• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/tdefile
 

tdeio/tdefile

kurlbar.cpp

00001 /* This file is part of the KDE libraries
00002     Copyright (C) 2001,2002,2003 Carsten Pfeiffer <pfeiffer@kde.org>
00003 
00004     library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License as published by the Free Software Foundation, version 2.
00007 
00008     This library is distributed in the hope that it will be useful,
00009     but WITHOUT ANY WARRANTY; without even the implied warranty of
00010     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011     Library General Public License for more details.
00012 
00013     You should have received a copy of the GNU Library General Public License
00014     along with this library; see the file COPYING.LIB.  If not, write to
00015     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016     Boston, MA 02110-1301, USA.
00017 */
00018 
00019 #include <unistd.h>
00020 
00021 #include <tqapplication.h>
00022 #include <tqcheckbox.h>
00023 #include <tqdrawutil.h>
00024 #include <tqfontmetrics.h>
00025 #include <tqlabel.h>
00026 #include <tqgrid.h>
00027 #include <tqpainter.h>
00028 #include <tqpopupmenu.h>
00029 #include <tqstyle.h>
00030 #include <tqvbox.h>
00031 #include <tqwhatsthis.h>
00032 
00033 #include <tdeaboutdata.h>
00034 #include <tdeconfig.h>
00035 #include <kdebug.h>
00036 #include <tdeglobal.h>
00037 #include <kicondialog.h>
00038 #include <kiconloader.h>
00039 #include <kinstance.h>
00040 #include <klineedit.h>
00041 #include <tdelocale.h>
00042 #include <kmimetype.h>
00043 #include <kprotocolinfo.h>
00044 #include <kstringhandler.h>
00045 #include <kurldrag.h>
00046 #include <kurlrequester.h>
00047 #include <tdeio/global.h>
00048 #include <tdeio/netaccess.h>
00049 
00050 #include "kurlbar.h"
00051 
00056 class KURLBarToolTip : public TQToolTip
00057 {
00058 public:
00059     KURLBarToolTip( TQListBox *view ) : TQToolTip( view ), m_view( view ) {}
00060 
00061 protected:
00062     virtual void maybeTip( const TQPoint& point ) {
00063         TQListBoxItem *item = m_view->itemAt( point );
00064         if ( item ) {
00065             TQString text = static_cast<KURLBarItem*>( item )->toolTip();
00066             if ( !text.isEmpty() )
00067                 tip( m_view->itemRect( item ), text );
00068         }
00069     }
00070 
00071 private:
00072     TQListBox *m_view;
00073 };
00074 
00075 
00078 
00079 class KURLBarItem::KURLBarItemPrivate
00080 {
00081 public:
00082     KURLBarItemPrivate()
00083     {
00084         isPersistent = true;
00085     }
00086 
00087     bool isPersistent;
00088 };
00089 
00090 KURLBarItem::KURLBarItem( KURLBar *parent,
00091                           const KURL& url, bool persistent, const TQString& description,
00092                           const TQString& icon, TDEIcon::Group group )
00093     : TQListBoxPixmap( TDEIconLoader::unknown() /*, parent->listBox()*/ ),
00094       m_url( url ),
00095       m_pixmap( 0L ),
00096       m_parent( parent ),
00097       m_appLocal( false )
00098 {
00099     init( icon, group, description, persistent );
00100 }
00101 
00102 KURLBarItem::KURLBarItem( KURLBar *parent,
00103                           const KURL& url, const TQString& description,
00104                           const TQString& icon, TDEIcon::Group group )
00105     : TQListBoxPixmap( TDEIconLoader::unknown() /*, parent->listBox()*/ ),
00106       m_url( url ),
00107       m_pixmap( 0L ),
00108       m_parent( parent ),
00109       m_appLocal( false )
00110 {
00111     init( icon, group, description, true /*persistent*/ );
00112 }
00113 
00114 void KURLBarItem::init( const TQString& icon, TDEIcon::Group group,
00115                         const TQString& description, bool persistent )
00116 {
00117     d = new KURLBarItemPrivate;
00118     d->isPersistent = persistent;
00119 
00120     setCustomHighlighting( true );
00121     setIcon( icon, group );
00122     setDescription( description );
00123 }
00124 
00125 KURLBarItem::~KURLBarItem()
00126 {
00127     delete d;
00128 }
00129 
00130 void KURLBarItem::setURL( const KURL& url )
00131 {
00132     m_url = url;
00133     if ( m_description.isEmpty() )
00134         setText( url.fileName() );
00135 }
00136 
00137 void KURLBarItem::setIcon( const TQString& icon, TDEIcon::Group group )
00138 {
00139     m_icon  = icon;
00140     m_group = group;
00141 
00142     if ( icon.isEmpty() )
00143         m_pixmap = KMimeType::pixmapForURL( m_url, 0, group, iconSize() );
00144     else
00145         m_pixmap = TDEGlobal::iconLoader()->loadIcon( icon, group, iconSize(),
00146                                                     TDEIcon::DefaultState );
00147 }
00148 
00149 void KURLBarItem::setDescription( const TQString& desc )
00150 {
00151     m_description = desc;
00152     setText( desc.isEmpty() ? m_url.fileName() : desc );
00153 }
00154 
00155 void KURLBarItem::setApplicationLocal( bool local )
00156 {
00157     if ( !local && !isPersistent() )
00158     {
00159         kdWarning() << "KURLBar: dynamic (non-persistent) items can not be global." << endl;
00160         return;
00161     }
00162 
00163     m_appLocal = local;
00164 }
00165 
00166 void KURLBarItem::setToolTip( const TQString& tip )
00167 {
00168     m_toolTip = tip;
00169 }
00170 
00171 TQString KURLBarItem::toolTip() const
00172 {
00173     return m_toolTip.isEmpty() ? m_url.prettyURL() : m_toolTip;
00174 }
00175 
00176 int KURLBarItem::iconSize() const
00177 {
00178     return m_parent->iconSize();
00179 }
00180 
00181 void KURLBarItem::paint( TQPainter *p )
00182 {
00183     TQListBox *box = listBox();
00184     int w = width( box );
00185     static const int margin = KDialog::spacingHint();
00186 
00187     // draw sunken selection
00188     if ( isCurrent() || isSelected() ) {
00189         int h = height( box );
00190 
00191         TQBrush brush = box->colorGroup().brush( TQColorGroup::Highlight );
00192         p->fillRect( 0, 0, w, h, brush );
00193         TQPen pen = p->pen();
00194         TQPen oldPen = pen;
00195         pen.setColor( box->colorGroup().mid() );
00196         p->setPen( pen );
00197 
00198         p->drawPoint( 0, 0 );
00199         p->drawPoint( 0, h - 1 );
00200         p->drawPoint( w - 1, 0 );
00201         p->drawPoint( w - 1, h - 1 );
00202 
00203         p->setPen( oldPen );
00204     }
00205 
00206     if ( m_parent->iconSize() < TDEIcon::SizeMedium ) {
00207         // small icon -> draw icon next to text
00208 
00209         // ### mostly cut & paste of TQListBoxPixmap::paint() until Qt 3.1
00210         // (where it will properly use pixmap() instead of the internal pixmap)
00211         const TQPixmap *pm = pixmap();
00212         int yPos = TQMAX( 0, (height(box) - pm->height())/2 );
00213 
00214         p->drawPixmap( margin, yPos, *pm );
00215         if ( !text().isEmpty() ) {
00216             TQFontMetrics fm = p->fontMetrics();
00217             if ( pm->height() < fm.height() ) {
00218                 yPos = fm.ascent() + fm.leading()/2;
00219             }
00220             else {
00221                 yPos = height(box)/2 - fm.height()/2 + fm.ascent() - margin;
00222             }
00223 
00224             yPos += margin;
00225             int stringWidth = box->width() - pm->width() - 2 - (margin * 2);
00226             TQString visibleText = KStringHandler::rPixelSqueeze( text(), fm, stringWidth );
00227             int xPos = pm->width() + margin + 2;
00228 
00229             if ( isCurrent() || isSelected() ) {
00230                 p->setPen( box->colorGroup().highlight().dark(115) );
00231                 p->drawText( xPos + ( TQApplication::reverseLayout() ? -1 : 1),
00232                              yPos + 1, visibleText );
00233                 p->setPen( box->colorGroup().highlightedText() );
00234             }
00235 
00236             p->drawText( xPos, yPos, visibleText );
00237         }
00238         // end cut & paste (modulo pixmap centering)
00239     }
00240 
00241     else {
00242         // big icons -> draw text below icon
00243         int y = margin;
00244         const TQPixmap *pm = pixmap();
00245 
00246         if ( !pm->isNull() ) {
00247             int x = (w - pm->width()) / 2;
00248             x = TQMAX( x, margin );
00249             p->drawPixmap( x, y, *pm );
00250         }
00251 
00252         if ( !text().isEmpty() ) {
00253             TQFontMetrics fm = p->fontMetrics();
00254             y += pm->height() + fm.height() - fm.descent();
00255 
00256             int stringWidth = box->width() - (margin * 2);
00257             TQString visibleText = KStringHandler::rPixelSqueeze( text(), fm, stringWidth );
00258             int x = (w - fm.width( visibleText )) / 2;
00259             x = TQMAX( x, margin );
00260 
00261             if ( isCurrent() || isSelected() ) {
00262                 p->setPen( box->colorGroup().highlight().dark(115) );
00263                 p->drawText( x + ( TQApplication::reverseLayout() ? -1 : 1),
00264                              y + 1, visibleText );
00265                 p->setPen( box->colorGroup().highlightedText() );
00266             }
00267 
00268             p->drawText( x, y, visibleText );
00269         }
00270     }
00271 }
00272 
00273 TQSize KURLBarItem::sizeHint() const
00274 {
00275     int wmin = 0;
00276     int hmin = 0;
00277     const KURLBarListBox *lb =static_cast<const KURLBarListBox*>(listBox());
00278 
00279     if ( m_parent->iconSize() < TDEIcon::SizeMedium ) {
00280         wmin = TQListBoxPixmap::width( lb ) + KDialog::spacingHint() * 2;
00281         hmin = TQListBoxPixmap::height( lb ) + KDialog::spacingHint() * 2;
00282     }
00283     else {
00284         wmin = TQMAX(lb->fontMetrics().width(text()), pixmap()->width()) + KDialog::spacingHint() * 2;
00285         hmin = lb->fontMetrics().lineSpacing() + pixmap()->height() + KDialog::spacingHint() * 2;
00286     }
00287 
00288     if ( lb->isVertical() )
00289         wmin = TQMIN( wmin, lb->viewport()->sizeHint().width() );
00290     else
00291         hmin = TQMIN( hmin, lb->viewport()->sizeHint().height() );
00292 
00293     return TQSize( wmin, hmin );
00294 }
00295 
00296 int KURLBarItem::width( const TQListBox *lb ) const
00297 {
00298     if ( static_cast<const KURLBarListBox *>( lb )->isVertical() )
00299         return TQMAX( sizeHint().width(), lb->viewport()->width() );
00300     else
00301         return sizeHint().width();
00302 }
00303 
00304 int KURLBarItem::height( const TQListBox *lb ) const
00305 {
00306     if ( static_cast<const KURLBarListBox *>( lb )->isVertical() )
00307         return sizeHint().height();
00308     else
00309         return TQMAX( sizeHint().height(), lb->viewport()->height() );
00310 }
00311 
00312 bool KURLBarItem::isPersistent() const
00313 {
00314     return d->isPersistent;
00315 }
00316 
00319 
00320 class KURLBar::KURLBarPrivate
00321 {
00322 public:
00323     KURLBarPrivate()
00324     {
00325         currentURL.setPath( TQDir::homeDirPath() );
00326         defaultIconSize = 0;
00327     }
00328 
00329     int defaultIconSize;
00330     KURL currentURL;
00331 };
00332 
00333 
00334 KURLBar::KURLBar( bool useGlobalItems, TQWidget *parent, const char *name, WFlags f )
00335     : TQFrame( parent, name, f ),
00336       m_activeItem( 0L ),
00337       m_useGlobal( useGlobalItems ),
00338       m_isModified( false ),
00339       m_isImmutable( false ),
00340       m_listBox( 0L ),
00341       m_iconSize( TDEIcon::SizeMedium )
00342 {
00343     d = new KURLBarPrivate();
00344 
00345     setListBox( 0L );
00346     setSizePolicy( TQSizePolicy( isVertical() ?
00347                                 TQSizePolicy::Maximum :
00348                                 TQSizePolicy::Preferred,
00349                                 isVertical() ?
00350                                 TQSizePolicy::Preferred :
00351                                 TQSizePolicy::Maximum ));
00352     TQWhatsThis::add(this, i18n("<qt>The <b>Quick Access</b> panel provides easy access to commonly used file locations.<p>"
00353                                "Clicking on one of the shortcut entries will take you to that location.<p>"
00354                                "By right clicking on an entry you can add, edit and remove shortcuts.</qt>"));
00355 }
00356 
00357 KURLBar::~KURLBar()
00358 {
00359     delete d;
00360 }
00361 
00362 KURLBarItem * KURLBar::insertItem(const KURL& url, const TQString& description,
00363                                   bool applicationLocal,
00364                                   const TQString& icon, TDEIcon::Group group )
00365 {
00366     KURLBarItem *item = new KURLBarItem(this, url, description, icon, group);
00367     item->setApplicationLocal( applicationLocal );
00368     m_listBox->insertItem( item );
00369     return item;
00370 }
00371 
00372 KURLBarItem * KURLBar::insertDynamicItem(const KURL& url, const TQString& description,
00373                                          const TQString& icon, TDEIcon::Group group )
00374 {
00375     KURLBarItem *item = new KURLBarItem(this, url, false, description, icon, group);
00376     m_listBox->insertItem( item );
00377     return item;
00378 }
00379 
00380 void KURLBar::setOrientation( Qt::Orientation orient )
00381 {
00382     m_listBox->setOrientation( orient );
00383     setSizePolicy( TQSizePolicy( isVertical() ?
00384                                 TQSizePolicy::Maximum :
00385                                 TQSizePolicy::Preferred,
00386                                 isVertical() ?
00387                                 TQSizePolicy::Preferred :
00388                                 TQSizePolicy::Maximum ));
00389 }
00390 
00391 Qt::Orientation KURLBar::orientation() const
00392 {
00393     return m_listBox->orientation();
00394 }
00395 
00396 void KURLBar::setListBox( KURLBarListBox *view )
00397 {
00398     delete m_listBox;
00399 
00400     if ( !view ) {
00401         m_listBox = new KURLBarListBox( this, "urlbar listbox" );
00402         setOrientation( Qt::Vertical );
00403     }
00404     else {
00405         m_listBox = view;
00406         if ( m_listBox->parentWidget() != this )
00407             m_listBox->reparent( this, TQPoint(0,0) );
00408         m_listBox->resize( width(), height() );
00409     }
00410 
00411     m_listBox->setSelectionMode( TDEListBox::Single );
00412     paletteChange( palette() );
00413     m_listBox->setFocusPolicy( TQ_TabFocus );
00414 
00415     connect( m_listBox, TQT_SIGNAL( mouseButtonClicked( int, TQListBoxItem *, const TQPoint & ) ),
00416              TQT_SLOT( slotSelected( int, TQListBoxItem * )));
00417     connect( m_listBox, TQT_SIGNAL( dropped( TQDropEvent * )),
00418              this, TQT_SLOT( slotDropped( TQDropEvent * )));
00419     connect( m_listBox, TQT_SIGNAL( contextMenuRequested( TQListBoxItem *,
00420                                                       const TQPoint& )),
00421              TQT_SLOT( slotContextMenuRequested( TQListBoxItem *, const TQPoint& )));
00422     connect( m_listBox, TQT_SIGNAL( returnPressed( TQListBoxItem * ) ),
00423              TQT_SLOT( slotSelected( TQListBoxItem * ) ));
00424 }
00425 
00426 void KURLBar::setIconSize( int size )
00427 {
00428     if ( size == m_iconSize )
00429         return;
00430 
00431     m_iconSize = size;
00432 
00433     // reload the icons with the new size
00434     KURLBarItem *item = static_cast<KURLBarItem*>( m_listBox->firstItem() );
00435     while ( item ) {
00436         item->setIcon( item->icon(), item->iconGroup() );
00437         item = static_cast<KURLBarItem*>( item->next() );
00438     }
00439 
00440     resize( sizeHint() );
00441     updateGeometry();
00442 }
00443 
00444 void KURLBar::clear()
00445 {
00446     m_listBox->clear();
00447 }
00448 
00449 void KURLBar::resizeEvent( TQResizeEvent *e )
00450 {
00451     TQFrame::resizeEvent( e );
00452     m_listBox->resize( width(), height() );
00453 }
00454 
00455 void KURLBar::paletteChange( const TQPalette & )
00456 {
00457     TQPalette pal = palette();
00458     TQColor gray = pal.color( TQPalette::Normal, TQColorGroup::Background );
00459     TQColor selectedTextColor = pal.color( TQPalette::Normal, TQColorGroup::BrightText );
00460     TQColor foreground = pal.color( TQPalette::Normal, TQColorGroup::Foreground );
00461     pal.setColor( TQPalette::Normal,   TQColorGroup::Base, gray );
00462     pal.setColor( TQPalette::Normal,   TQColorGroup::HighlightedText, selectedTextColor );
00463     pal.setColor( TQPalette::Normal,   TQColorGroup::Text, foreground );
00464     pal.setColor( TQPalette::Inactive, TQColorGroup::Base, gray );
00465     pal.setColor( TQPalette::Inactive, TQColorGroup::HighlightedText, selectedTextColor );
00466     pal.setColor( TQPalette::Inactive, TQColorGroup::Text, foreground );
00467 
00468     setPalette( pal );
00469 }
00470 
00471 TQSize KURLBar::sizeHint() const
00472 {
00473     return m_listBox->sizeHint();
00474 
00475 #if 0
00476     // this code causes vertical and or horizontal scrollbars appearing
00477     // depending on the text, font, moonphase and earth rotation. Just using
00478     // m_listBox->sizeHint() fixes this (although the widget can then be
00479     // resized to a smaller size so that scrollbars appear).
00480     int w = 0;
00481     int h = 0;
00482     KURLBarItem *item;
00483     bool vertical = isVertical();
00484 
00485     for ( item = static_cast<KURLBarItem*>( m_listBox->firstItem() );
00486           item;
00487           item = static_cast<KURLBarItem*>( item->next() ) ) {
00488 
00489         TQSize sh = item->sizeHint();
00490 
00491         if ( vertical ) {
00492             w = TQMAX( w, sh.width() );
00493             h += sh.height();
00494         }
00495         else {
00496             w += sh.width();
00497             h = TQMAX( h, sh.height() );
00498         }
00499     }
00500 
00501 //     if ( vertical && m_listBox->verticalScrollBar()->isVisible() )
00502 //         w += m_listBox->verticalScrollBar()->width();
00503 //     else if ( !vertical && m_listBox->horizontalScrollBar()->isVisible() )
00504 //         h += m_listBox->horizontalScrollBar()->height();
00505 
00506     if ( w == 0 && h == 0 )
00507         return TQSize( 100, 200 );
00508     else
00509         return TQSize( 6 + w, h );
00510 #endif
00511 }
00512 
00513 TQSize KURLBar::minimumSizeHint() const
00514 {
00515     TQSize s = sizeHint(); // ###
00516     int w = s.width()  + m_listBox->verticalScrollBar()->width();
00517     int h = s.height() + m_listBox->horizontalScrollBar()->height();
00518     return TQSize( w, h );
00519 }
00520 
00521 void KURLBar::slotSelected( int button, TQListBoxItem *item )
00522 {
00523     if ( button != Qt::LeftButton )
00524         return;
00525 
00526     slotSelected( item );
00527 }
00528 
00529 void KURLBar::slotSelected( TQListBoxItem *item )
00530 {
00531     if ( item && item != m_activeItem )
00532         m_activeItem = static_cast<KURLBarItem*>( item );
00533 
00534     if ( m_activeItem ) {
00535         m_listBox->setCurrentItem( m_activeItem );
00536         emit activated( m_activeItem->url() );
00537     }
00538 }
00539 
00540 void KURLBar::setCurrentItem( const KURL& url )
00541 {
00542     d->currentURL = url;
00543 
00544     TQString u = url.url(-1);
00545 
00546     if ( m_activeItem && m_activeItem->url().url(-1) == u )
00547         return;
00548 
00549     bool hasURL = false;
00550     TQListBoxItem *item = m_listBox->firstItem();
00551     while ( item ) {
00552         if ( static_cast<KURLBarItem*>( item )->url().url(-1) == u ) {
00553             m_activeItem = static_cast<KURLBarItem*>( item );
00554             m_listBox->setCurrentItem( item );
00555             m_listBox->setSelected( item, true );
00556             hasURL = true;
00557             break;
00558         }
00559         item = item->next();
00560     }
00561 
00562     if ( !hasURL ) {
00563         m_activeItem = 0L;
00564         m_listBox->clearSelection();
00565     }
00566 }
00567 
00568 KURLBarItem * KURLBar::currentItem() const
00569 {
00570     TQListBoxItem *item = m_listBox->item( m_listBox->currentItem() );
00571     if ( item )
00572         return static_cast<KURLBarItem *>( item );
00573     return 0L;
00574 }
00575 
00576 KURL KURLBar::currentURL() const
00577 {
00578     KURLBarItem *item = currentItem();
00579     return item ? item->url() : KURL();
00580 }
00581 
00582 void KURLBar::readConfig( TDEConfig *appConfig, const TQString& itemGroup )
00583 {
00584     m_isImmutable = appConfig->groupIsImmutable( itemGroup );
00585     TDEConfigGroupSaver cs( appConfig, itemGroup );
00586     d->defaultIconSize = m_iconSize;
00587     m_iconSize = appConfig->readNumEntry( "Speedbar IconSize", m_iconSize );
00588 
00589     if ( m_useGlobal ) { // read global items
00590         TDEConfig *globalConfig = TDEGlobal::config();
00591         TDEConfigGroupSaver cs( globalConfig, (TQString)(itemGroup +" (Global)"));
00592         int num = globalConfig->readNumEntry( "Number of Entries" );
00593         for ( int i = 0; i < num; i++ ) {
00594             readItem( i, globalConfig, false );
00595         }
00596     }
00597 
00598     // read application local items
00599     int num = appConfig->readNumEntry( "Number of Entries" );
00600     for ( int i = 0; i < num; i++ ) {
00601         readItem( i, appConfig, true );
00602     }
00603 }
00604 
00605 void KURLBar::readItem( int i, TDEConfig *config, bool applicationLocal )
00606 {
00607     TQString number = TQString::number( i );
00608     KURL url = KURL::fromPathOrURL( config->readPathEntry( TQString("URL_") + number ));
00609     if ( !url.isValid() || !KProtocolInfo::isKnownProtocol( url ))
00610         return; // nothing we could do.
00611 
00612     TQString description = config->readEntry( TQString("Description_") + number ); 
00613 
00614     if (description.isEmpty() && url.protocol()=="beagle") {
00615         TDEIO::UDSEntry uds;
00616         const KURL kurl("beagle:?beagled-status");
00617         if (!TDEIO::NetAccess::stat(kurl, uds))
00618             return;
00619 
00620         description = i18n("Desktop Search");
00621     }
00622 
00623     insertItem( url,
00624                 description,
00625                 applicationLocal,
00626                 config->readEntry( TQString("Icon_") + number ),
00627                 static_cast<TDEIcon::Group>(
00628                     config->readNumEntry( TQString("IconGroup_") + number )) );
00629 }
00630 
00631 void KURLBar::writeConfig( TDEConfig *config, const TQString& itemGroup )
00632 {
00633     TDEConfigGroupSaver cs1( config, itemGroup );
00634     if(!config->hasDefault("Speedbar IconSize") && m_iconSize == d->defaultIconSize )
00635         config->revertToDefault("Speedbar IconSize");
00636     else
00637         config->writeEntry( "Speedbar IconSize", m_iconSize );
00638 
00639     if ( !m_isModified )
00640         return;
00641 
00642     int i = 0;
00643     int numLocal = 0;
00644     KURLBarItem *item = static_cast<KURLBarItem*>( m_listBox->firstItem() );
00645 
00646     while ( item )
00647     {
00648         if ( item->isPersistent() ) // we only save persistent items
00649         {
00650             if ( item->applicationLocal() )
00651             {
00652                 writeItem( item, numLocal, config, false );
00653                 numLocal++;
00654             }
00655 
00656             i++;
00657         }
00658         item = static_cast<KURLBarItem*>( item->next() );
00659     }
00660     config->writeEntry("Number of Entries", numLocal);
00661 
00662 
00663     // write the global entries to kdeglobals, if any
00664     bool haveGlobalEntries = (i > numLocal);
00665     if ( m_useGlobal && haveGlobalEntries ) {
00666         config->setGroup( itemGroup + " (Global)" );
00667 
00668         int numGlobals = 0;
00669         item = static_cast<KURLBarItem*>( m_listBox->firstItem() );
00670 
00671         while ( item )
00672         {
00673             if ( item->isPersistent() ) // we only save persistent items
00674             {
00675                 if ( !item->applicationLocal() )
00676                 {
00677                     writeItem( item, numGlobals, config, true );
00678                     numGlobals++;
00679                 }
00680             }
00681 
00682             item = static_cast<KURLBarItem*>( item->next() );
00683         }
00684         config->writeEntry("Number of Entries", numGlobals, true, true);
00685     }
00686 
00687     m_isModified = false;
00688 }
00689 
00690 void KURLBar::writeItem( KURLBarItem *item, int i, TDEConfig *config,
00691                          bool global )
00692 {
00693     if ( !item->isPersistent() )
00694         return;
00695 
00696     TQString Description = "Description_";
00697     TQString URL = "URL_";
00698     TQString Icon = "Icon_";
00699     TQString IconGroup = "IconGroup_";
00700 
00701     TQString number = TQString::number( i );
00702     config->writePathEntry( URL + number, item->url().prettyURL(), true, global );
00703 
00704     config->writeEntry( Description + number, item->description(),true,global);
00705     config->writeEntry( Icon + number, item->icon(), true, global );
00706     config->writeEntry( IconGroup + number, item->iconGroup(), true, global );
00707 }
00708 
00709 
00710 void KURLBar::slotDropped( TQDropEvent *e )
00711 {
00712     KURL::List urls;
00713     if ( KURLDrag::decode( e, urls ) ) {
00714         KURL url;
00715         TQString description;
00716         TQString icon;
00717         bool appLocal = false;
00718 
00719         KURL::List::Iterator it = urls.begin();
00720         for ( ; it != urls.end(); ++it ) {
00721             (void) insertItem( *it, description, appLocal, icon );
00722             m_isModified = true;
00723             updateGeometry();
00724         }
00725     }
00726 }
00727 
00728 void KURLBar::slotContextMenuRequested( TQListBoxItem *_item, const TQPoint& pos )
00729 {
00730     if (m_isImmutable)
00731         return;
00732 
00733     KURLBarItem *item = dynamic_cast<KURLBarItem*>( _item );
00734 
00735     static const int IconSize   = 10;
00736     static const int AddItem    = 20;
00737     static const int EditItem   = 30;
00738     static const int RemoveItem = 40;
00739 
00740     KURL lastURL = m_activeItem ? m_activeItem->url() : KURL();
00741 
00742     bool smallIcons = m_iconSize < TDEIcon::SizeMedium;
00743     TQPopupMenu *popup = new TQPopupMenu();
00744     popup->insertItem( smallIcons ?
00745                        i18n("&Large Icons") : i18n("&Small Icons"),
00746                        IconSize );
00747     popup->insertSeparator();
00748 
00749     if (item != 0L && item->isPersistent())
00750     {
00751         popup->insertItem(SmallIconSet("edit"), i18n("&Edit Entry..."), EditItem);
00752         popup->insertSeparator();
00753     }
00754 
00755     popup->insertItem(SmallIconSet("document-new"), i18n("&Add Entry..."), AddItem);
00756 
00757     if (item != 0L && item->isPersistent())
00758     {
00759         popup->insertItem( SmallIconSet("edit-delete"), i18n("&Remove Entry"),
00760                           RemoveItem );
00761     }
00762 
00763     int result = popup->exec( pos );
00764     switch ( result ) {
00765         case IconSize:
00766             setIconSize( smallIcons ? TDEIcon::SizeMedium : TDEIcon::SizeSmallMedium );
00767             m_listBox->triggerUpdate( true );
00768             break;
00769         case AddItem:
00770             addNewItem();
00771             break;
00772         case EditItem:
00773             editItem( static_cast<KURLBarItem *>( item ) );
00774             break;
00775         case RemoveItem:
00776             delete item;
00777             m_isModified = true;
00778             break;
00779         default: // abort
00780             break;
00781     }
00782 
00783     // reset current item
00784     m_activeItem = 0L;
00785     setCurrentItem( lastURL );
00786 }
00787 
00788 bool KURLBar::addNewItem()
00789 {
00790     KURLBarItem *item = new KURLBarItem( this, d->currentURL,
00791                                          i18n("Enter a description") );
00792     if ( editItem( item ) ) {
00793         m_listBox->insertItem( item );
00794         return true;
00795     }
00796 
00797     delete item;
00798     return false;
00799 }
00800 
00801 bool KURLBar::editItem( KURLBarItem *item )
00802 {
00803     if ( !item || !item->isPersistent() ) // should never happen tho
00804         return false;
00805 
00806     KURL url            = item->url();
00807     TQString description = item->description();
00808     TQString icon        = item->icon();
00809     bool appLocal       = item->applicationLocal();
00810 
00811     if ( KURLBarItemDialog::getInformation( m_useGlobal,
00812                                             url, description,
00813                                             icon, appLocal,
00814                                             m_iconSize, this ))
00815     {
00816         item->setURL( url );
00817         item->setDescription( description );
00818         item->setIcon( icon );
00819         item->setApplicationLocal( appLocal );
00820         m_listBox->triggerUpdate( true );
00821         m_isModified = true;
00822         updateGeometry();
00823         return true;
00824     }
00825 
00826     return false;
00827 }
00828 
00831 
00832 
00833 KURLBarListBox::KURLBarListBox( TQWidget *parent, const char *name )
00834     : TDEListBox( parent, name )
00835 {
00836     m_toolTip = new KURLBarToolTip( this );
00837     setAcceptDrops( true );
00838     viewport()->setAcceptDrops( true );
00839 }
00840 
00841 KURLBarListBox::~KURLBarListBox()
00842 {
00843     delete m_toolTip;
00844 }
00845 
00846 void KURLBarListBox::paintEvent( TQPaintEvent* )
00847 {
00848     TQPainter p(this);
00849     p.setPen( colorGroup().mid() );
00850     p.drawRect( 0, 0, width(), height() );
00851 }
00852 
00853 TQDragObject * KURLBarListBox::dragObject()
00854 {
00855     KURL::List urls;
00856     KURLBarItem *item = static_cast<KURLBarItem*>( firstItem() );
00857 
00858     while ( item ) {
00859         if ( item->isSelected() )
00860             urls.append( item->url() );
00861         item = static_cast<KURLBarItem*>( item->next() );
00862     }
00863 
00864     if ( !urls.isEmpty() ) // ### use custom drag-object with description etc.?
00865         return new KURLDrag( urls, this, "urlbar drag" );
00866 
00867     return 0L;
00868 }
00869 
00870 void KURLBarListBox::contentsDragEnterEvent( TQDragEnterEvent *e )
00871 {
00872     e->accept( KURLDrag::canDecode( e ));
00873 }
00874 
00875 void KURLBarListBox::contentsDropEvent( TQDropEvent *e )
00876 {
00877     emit dropped( e );
00878 }
00879 
00880 void KURLBarListBox::contextMenuEvent( TQContextMenuEvent *e )
00881 {
00882     if (e)
00883     {
00884         emit contextMenuRequested( itemAt( e->globalPos() ), e->globalPos() );
00885         e->consume(); // Consume the event to avoid multiple contextMenuEvent calls...
00886     }
00887 }
00888 
00889 void KURLBarListBox::setOrientation( Qt::Orientation orient )
00890 {
00891     if ( orient == Qt::Vertical ) {
00892         setColumnMode( 1 );
00893         setRowMode( Variable );
00894     }
00895     else {
00896         setRowMode( 1 );
00897         setColumnMode( Variable );
00898     }
00899 
00900     m_orientation = orient;
00901 }
00902 
00905 
00906 
00907 bool KURLBarItemDialog::getInformation( bool allowGlobal, KURL& url,
00908                                         TQString& description, TQString& icon,
00909                                         bool& appLocal, int iconSize,
00910                                         TQWidget *parent )
00911 {
00912     KURLBarItemDialog *dialog = new KURLBarItemDialog( allowGlobal, url,
00913                                                        description, icon,
00914                                                        appLocal,
00915                                                        iconSize, parent );
00916     if ( dialog->exec() == TQDialog::Accepted ) {
00917         // set the return parameters
00918         url         = dialog->url();
00919         description = dialog->description();
00920         icon        = dialog->icon();
00921         appLocal    = dialog->applicationLocal();
00922 
00923         delete dialog;
00924         return true;
00925     }
00926 
00927     delete dialog;
00928     return false;
00929 }
00930 
00931 KURLBarItemDialog::KURLBarItemDialog( bool allowGlobal, const KURL& url,
00932                                       const TQString& description,
00933                                       TQString icon, bool appLocal,
00934                                       int iconSize,
00935                                       TQWidget *parent, const char *name )
00936     : KDialogBase( parent, name, true,
00937                    i18n("Edit Quick Access Entry"), Ok | Cancel, Ok, true )
00938 {
00939     TQVBox *box = new TQVBox( this );
00940     TQString text = i18n("<qt><b>Please provide a description, URL and icon for this Quick Access entry.</b></br></qt>");
00941     TQLabel *label = new TQLabel( text, box );
00942     box->setSpacing( spacingHint() );
00943 
00944     TQGrid *grid = new TQGrid( 2, box );
00945     grid->setSpacing( spacingHint() );
00946 
00947     TQString whatsThisText = i18n("<qt>This is the text that will appear in the Quick Access panel.<p>"
00948                                  "The description should consist of one or two words "
00949                                  "that will help you remember what this entry refers to.</qt>");
00950     label = new TQLabel( i18n("&Description:"), grid );
00951     m_edit = new KLineEdit( grid, "description edit" );
00952     m_edit->setText( description.isEmpty() ? url.fileName() : description );
00953     label->setBuddy( m_edit );
00954     TQWhatsThis::add( label, whatsThisText );
00955     TQWhatsThis::add( m_edit, whatsThisText );
00956 
00957     whatsThisText = i18n("<qt>This is the location associated with the entry. Any valid URL may be used. For example:<p>"
00958                          "%1<br>http://www.trinitydesktop.org<p>"
00959                          "By clicking on the button next to the text edit box you can browse to an "
00960                          "appropriate URL.</qt>").arg(TQDir::homeDirPath());
00961     label = new TQLabel( i18n("&URL:"), grid );
00962     m_urlEdit = new KURLRequester( url.prettyURL(), grid );
00963     m_urlEdit->setMode( KFile::Directory );
00964     label->setBuddy( m_urlEdit );
00965     TQWhatsThis::add( label, whatsThisText );
00966     TQWhatsThis::add( m_urlEdit, whatsThisText );
00967 
00968     whatsThisText = i18n("<qt>This is the icon that will appear in the Quick Access panel.<p>"
00969                          "Click on the button to select a different icon.</qt>");
00970     label = new TQLabel( i18n("Choose an &icon:"), grid );
00971     m_iconButton = new TDEIconButton( grid, "icon button" );
00972     m_iconButton->setIconSize( iconSize );
00973     if ( icon.isEmpty() )
00974         icon = KMimeType::iconForURL( url );
00975     m_iconButton->setIcon( icon );
00976     label->setBuddy( m_iconButton );
00977     TQWhatsThis::add( label, whatsThisText );
00978     TQWhatsThis::add( m_iconButton, whatsThisText );
00979 
00980     if ( allowGlobal ) {
00981         TQString appName;
00982         if ( TDEGlobal::instance()->aboutData() )
00983             appName = TDEGlobal::instance()->aboutData()->programName();
00984         if ( appName.isEmpty() )
00985             appName = TQString::fromLatin1( TDEGlobal::instance()->instanceName() );
00986         m_appLocal = new TQCheckBox( i18n("&Only show when using this application (%1)").arg( appName ), box );
00987         m_appLocal->setChecked( appLocal );
00988         TQWhatsThis::add( m_appLocal,
00989                          i18n("<qt>Select this setting if you want this "
00990                               "entry to show only when using the current application (%1).<p>"
00991                               "If this setting is not selected, the entry will be available in all "
00992                               "applications.</qt>")
00993                               .arg(appName));
00994     }
00995     else
00996         m_appLocal = 0L;
00997     connect(m_urlEdit->lineEdit(),TQT_SIGNAL(textChanged ( const TQString & )),this,TQT_SLOT(urlChanged(const TQString & )));
00998     m_edit->setFocus();
00999     setMainWidget( box );
01000 }
01001 
01002 KURLBarItemDialog::~KURLBarItemDialog()
01003 {
01004 }
01005 
01006 void KURLBarItemDialog::urlChanged(const TQString & text )
01007 {
01008     enableButtonOK( !text.isEmpty() );
01009 }
01010 
01011 KURL KURLBarItemDialog::url() const
01012 {
01013     TQString text = m_urlEdit->url();
01014     KURL u;
01015     if ( text.at(0) == '/' )
01016         u.setPath( text );
01017     else
01018         u = text;
01019 
01020     return u;
01021 }
01022 
01023 TQString KURLBarItemDialog::description() const
01024 {
01025     return m_edit->text();
01026 }
01027 
01028 TQString KURLBarItemDialog::icon() const
01029 {
01030     return m_iconButton->icon();
01031 }
01032 
01033 bool KURLBarItemDialog::applicationLocal() const
01034 {
01035     if ( !m_appLocal )
01036         return true;
01037 
01038     return m_appLocal->isChecked();
01039 }
01040 
01041 void KURLBarItem::virtual_hook( int, void* )
01042 { /*BASE::virtual_hook( id, data );*/ }
01043 
01044 void KURLBar::virtual_hook( int, void* )
01045 { /*BASE::virtual_hook( id, data );*/ }
01046 
01047 void KURLBarListBox::virtual_hook( int id, void* data )
01048 { TDEListBox::virtual_hook( id, data ); }
01049 
01050 
01051 #include "kurlbar.moc"

tdeio/tdefile

Skip menu "tdeio/tdefile"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeio/tdefile

Skip menu "tdeio/tdefile"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdefile by doxygen 1.7.1
This website is maintained by Timothy Pearson.