libkonq Library API Documentation

konq_dirpart.cc

00001 /* This file is part of the KDE projects
00002    Copyright (C) 2000 David Faure <faure@kde.org>
00003 
00004    This program is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     General Public License for more details.
00013 
00014    You should have received a copy of the GNU General Public License
00015    along with this program; see the file COPYING.  If not, write to
00016    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017    Boston, MA 02111-1307, USA.
00018 */
00019 
00020 #include "konq_dirpart.h"
00021 #include "konq_bgnddlg.h"
00022 #include "konq_propsview.h"
00023 #include "konq_settings.h"
00024 
00025 #include <kapplication.h>
00026 #include <kaction.h>
00027 #include <kdatastream.h>
00028 #include <kdebug.h>
00029 #include <kdirlister.h>
00030 #include <kiconloader.h>
00031 #include <klocale.h>
00032 #include <kmessagebox.h>
00033 #include <konq_drag.h>
00034 #include <kparts/browserextension.h>
00035 #include <kurldrag.h>
00036 #include <kuserprofile.h>
00037 #include <kurifilter.h>
00038 #include <kglobalsettings.h>
00039 #include <kdesktopfile.h>
00040 
00041 #include <qapplication.h>
00042 #include <qclipboard.h>
00043 #include <qfile.h>
00044 #include <assert.h>
00045 #include <qvaluevector.h>
00046 
00047 class KonqDirPart::KonqDirPartPrivate
00048 {
00049 public:
00050     KonqDirPartPrivate() : dirLister( 0 ) {}
00051     QStringList mimeFilters;
00052     KToggleAction *aEnormousIcons;
00053     KToggleAction *aSmallMediumIcons;
00054     QValueVector<int> iconSize;
00055 
00056     KDirLister* dirLister;
00057     bool dirSizeDirty;
00058 
00059     void findAvailableIconSizes(void);
00060     int findNearestIconSize(int size);
00061     int nearestIconSizeError(int size);
00062 };
00063 
00064 void KonqDirPart::KonqDirPartPrivate::findAvailableIconSizes(void)
00065 {
00066     KIconTheme *root = KGlobal::instance()->iconLoader()->theme();
00067     iconSize.resize(1);
00068     if (root) {
00069     QValueList<int> avSizes = root->querySizes(KIcon::Desktop);
00070         kdDebug(1203) << "The icon theme handles the sizes:" << avSizes << endl;
00071     qHeapSort(avSizes);
00072     int oldSize = -1;
00073     if (avSizes.count() < 10) {
00074         // Fixed or threshold type icons
00075         QValueListConstIterator<int> i;
00076         for (i = avSizes.begin(); i != avSizes.end(); i++) {
00077         // Skip duplicated values (sanity check)
00078         if (*i != oldSize) iconSize.append(*i);
00079         oldSize = *i;
00080         }
00081     } else {
00082         // Scalable icons.
00083         const int progression[] = {16, 22, 32, 48, 64, 96, 128, 192, 256};
00084 
00085         QValueListConstIterator<int> j = avSizes.begin();
00086         for (uint i = 0; i < 9; i++) {
00087         while (j++ != avSizes.end()) {
00088             if (*j >= progression[i]) {
00089             iconSize.append(*j);
00090             kdDebug(1203) << "appending " << *j << " size." << endl;
00091             break;
00092             }
00093         }
00094         }
00095     }
00096     } else {
00097     iconSize.append(KIcon::SizeSmall); // 16
00098     iconSize.append(KIcon::SizeMedium); // 32
00099     iconSize.append(KIcon::SizeLarge); // 48
00100     iconSize.append(KIcon::SizeHuge); // 64
00101     }
00102     kdDebug(1203) << "Using " << iconSize.count() << " icon sizes." << endl;
00103 }
00104 
00105 int KonqDirPart::KonqDirPartPrivate::findNearestIconSize(int preferred)
00106 {
00107     int s1 = iconSize[1];
00108     if (preferred == 0) return KGlobal::iconLoader()->currentSize(KIcon::Desktop);
00109     if (preferred <= s1) return s1;
00110     for (uint i = 2; i <= iconSize.count(); i++) {
00111         if (preferred <= iconSize[i]) {
00112         if (preferred - s1 <  iconSize[i] - preferred) return s1;
00113         else return iconSize[i];
00114     } else {
00115         s1 = iconSize[i];
00116     }
00117     }
00118     return s1;
00119 }
00120 
00121 int KonqDirPart::KonqDirPartPrivate::nearestIconSizeError(int size)
00122 {
00123     return QABS(size - findNearestIconSize(size));
00124 }
00125 
00126 KonqDirPart::KonqDirPart( QObject *parent, const char *name )
00127             :KParts::ReadOnlyPart( parent, name ),
00128     m_pProps( 0L ),
00129     m_findPart( 0L )
00130 {
00131     d = new KonqDirPartPrivate;
00132     resetCount();
00133     //m_bMultipleItemsSelected = false;
00134 
00135     connect( QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(slotClipboardDataChanged()) );
00136 
00137     actionCollection()->setHighlightingEnabled( true );
00138 
00139     m_paIncIconSize = new KAction( i18n( "Enlarge Icons" ), "viewmag+", 0, this, SLOT( slotIncIconSize() ), actionCollection(), "incIconSize" );
00140     m_paDecIconSize = new KAction( i18n( "Shrink Icons" ), "viewmag-", 0, this, SLOT( slotDecIconSize() ), actionCollection(), "decIconSize" );
00141 
00142     m_paDefaultIcons = new KRadioAction( i18n( "&Default Size" ), 0, actionCollection(), "modedefault" );
00143     d->aEnormousIcons = new KRadioAction( i18n( "&Huge" ), 0,
00144         actionCollection(), "modeenormous" );
00145     m_paHugeIcons = new KRadioAction( i18n( "&Very Large" ), 0, actionCollection(), "modehuge" );
00146     m_paLargeIcons = new KRadioAction( i18n( "&Large" ), 0, actionCollection(), "modelarge" );
00147     m_paMediumIcons = new KRadioAction( i18n( "&Medium" ), 0, actionCollection(), "modemedium" );
00148     d->aSmallMediumIcons = new KRadioAction( i18n( "&Small" ), 0,
00149         actionCollection(), "modesmallmedium" );
00150     m_paSmallIcons = new KRadioAction( i18n( "&Tiny" ), 0, actionCollection(), "modesmall" );
00151 
00152     m_paDefaultIcons->setExclusiveGroup( "ViewMode" );
00153     d->aEnormousIcons->setExclusiveGroup( "ViewMode" );
00154     m_paHugeIcons->setExclusiveGroup( "ViewMode" );
00155     m_paLargeIcons->setExclusiveGroup( "ViewMode" );
00156     m_paMediumIcons->setExclusiveGroup( "ViewMode" );
00157     d->aSmallMediumIcons->setExclusiveGroup( "ViewMode" );
00158     m_paSmallIcons->setExclusiveGroup( "ViewMode" );
00159 
00160     connect( m_paDefaultIcons, SIGNAL( toggled( bool ) ), this, SLOT( slotIconSizeToggled( bool ) ) );
00161     connect( d->aEnormousIcons, SIGNAL( toggled( bool ) ),
00162         this, SLOT( slotIconSizeToggled( bool ) ) );
00163     connect( m_paHugeIcons, SIGNAL( toggled( bool ) ), this, SLOT( slotIconSizeToggled( bool ) ) );
00164     connect( m_paLargeIcons, SIGNAL( toggled( bool ) ), this, SLOT( slotIconSizeToggled( bool ) ) );
00165     connect( m_paMediumIcons, SIGNAL( toggled( bool ) ), this, SLOT( slotIconSizeToggled( bool ) ) );
00166     connect( d->aSmallMediumIcons, SIGNAL( toggled( bool ) ),
00167         this, SLOT( slotIconSizeToggled( bool ) ) );
00168     connect( m_paSmallIcons, SIGNAL( toggled( bool ) ), this, SLOT( slotIconSizeToggled( bool ) ) );
00169 
00170     connect( kapp, SIGNAL(iconChanged(int)), SLOT(slotIconChanged(int)) );
00171 #if 0
00172     // Extract 6 icon sizes from the icon theme.
00173     // Use 16,22,32,48,64,128 as default.
00174     // Use these also if the icon theme is scalable.
00175     int i;
00176     d->iconSize[0] = 0; // Default value
00177     d->iconSize[1] = KIcon::SizeSmall; // 16
00178     d->iconSize[2] = KIcon::SizeSmallMedium; // 22
00179     d->iconSize[3] = KIcon::SizeMedium; // 32
00180     d->iconSize[4] = KIcon::SizeLarge; // 48
00181     d->iconSize[5] = KIcon::SizeHuge; // 64
00182     d->iconSize[6] = KIcon::SizeEnormous; // 128
00183     d->iconSize[7] = 192;
00184     d->iconSize[8] = 256;
00185     KIconTheme *root = KGlobal::instance()->iconLoader()->theme();
00186     if (root)
00187     {
00188       QValueList<int> avSizes = root->querySizes(KIcon::Desktop);
00189       kdDebug(1203) << "the icon theme handles the following sizes:" << avSizes << endl;
00190       if (avSizes.count() < 10) {
00191     // Use the icon sizes supplied by the theme.
00192     // If avSizes contains more than 10 entries, assume a scalable
00193     // icon theme.
00194     QValueList<int>::Iterator it;
00195     for (i=1, it=avSizes.begin(); (it!=avSizes.end()) && (i<7); it++, i++)
00196     {
00197       d->iconSize[i] = *it;
00198       kdDebug(1203) << "m_iIconSize[" << i << "] = " << *it << endl;
00199     }
00200     // Generate missing sizes
00201     for (; i < 7; i++) {
00202       d->iconSize[i] = d->iconSize[i - 1] + d->iconSize[i - 1] / 2 ;
00203       kdDebug(1203) << "m_iIconSize[" << i << "] = " << d->iconSize[i] << endl;
00204     }
00205       }
00206     }
00207 #else
00208     d->iconSize.reserve(10);
00209     d->iconSize.append(0); // Default value
00210     adjustIconSizes();
00211 #endif
00212 
00213     // Remove in KDE4 ...
00214     // These are here in the event subclasses access them.
00215     m_iIconSize[1] = KIcon::SizeSmall;
00216     m_iIconSize[2] = KIcon::SizeMedium;
00217     m_iIconSize[3] = KIcon::SizeLarge;
00218     m_iIconSize[4] = KIcon::SizeHuge;
00219     // ... up to here
00220 
00221     KAction *a = new KAction( i18n( "Configure Background..." ), "background", 0, this, SLOT( slotBackgroundSettings() ),
00222                               actionCollection(), "bgsettings" );
00223 
00224     a->setToolTip( i18n( "Allows choosing of background settings for this view" ) );
00225 }
00226 
00227 KonqDirPart::~KonqDirPart()
00228 {
00229     // Close the find part with us
00230     delete m_findPart;
00231     delete d;
00232 }
00233 
00234 void KonqDirPart::adjustIconSizes()
00235 {
00236     d->findAvailableIconSizes();
00237     m_paSmallIcons->setEnabled(d->findNearestIconSize(16) < 20);
00238     d->aSmallMediumIcons->setEnabled(d->nearestIconSizeError(22) < 2);
00239     m_paMediumIcons->setEnabled(d->nearestIconSizeError(32) < 6);
00240     m_paLargeIcons->setEnabled(d->nearestIconSizeError(48) < 8);
00241     m_paHugeIcons->setEnabled(d->nearestIconSizeError(64) < 12);
00242     d->aEnormousIcons->setEnabled(d->findNearestIconSize(128) > 110);
00243 
00244     if (m_pProps) {
00245     int size = m_pProps->iconSize();
00246     int nearSize = d->findNearestIconSize(size);
00247 
00248     if (size != nearSize) {
00249         m_pProps->setIconSize(nearSize);
00250     }
00251     newIconSize(nearSize);
00252     }
00253 }
00254 
00255 void KonqDirPart::setMimeFilter (const QStringList& mime)
00256 {
00257     QString u = url().url();
00258 
00259     if ( u.isEmpty () )
00260         return;
00261 
00262     if ( mime.isEmpty() )
00263         d->mimeFilters.clear();
00264     else
00265         d->mimeFilters = mime;
00266 }
00267 
00268 QStringList KonqDirPart::mimeFilter() const
00269 {
00270     return d->mimeFilters;
00271 }
00272 
00273 QScrollView * KonqDirPart::scrollWidget()
00274 {
00275     return static_cast<QScrollView *>(widget());
00276 }
00277 
00278 void KonqDirPart::slotBackgroundSettings()
00279 {
00280     QColor bgndColor = m_pProps->bgColor( widget() );
00281     QColor defaultColor = KGlobalSettings::baseColor();
00282     KonqBgndDialog dlg( widget(), m_pProps->bgPixmapFile(), bgndColor, defaultColor );
00283     if ( dlg.exec() == KonqBgndDialog::Accepted )
00284     {
00285         if ( dlg.color().isValid() )
00286         {
00287             m_pProps->setBgColor( dlg.color() );
00288         m_pProps->setBgPixmapFile( "" );
00289     }
00290         else
00291     {
00292             m_pProps->setBgColor( defaultColor );
00293         m_pProps->setBgPixmapFile( dlg.pixmapFile() );
00294         }
00295         m_pProps->applyColors( scrollWidget()->viewport() );
00296         scrollWidget()->viewport()->repaint();
00297     }
00298 }
00299 
00300 void KonqDirPart::lmbClicked( KFileItem * fileItem )
00301 {
00302     bool is_local = fileItem->isLocalFile();
00303      
00304      if ( fileItem->mimetype() == "application/x-desktop" )
00305      {
00306          KDesktopFile df( fileItem->url().path(), true );
00307          if ( df.readType() == "Link" )
00308          {
00309              KURL lu( df.readURL() );
00310              if ( is_local )
00311              {
00312                  fileItem = new KFileItem( KURL( df.readURL() ), "inode/directory", S_IFDIR );
00313              }
00314          }
00315      }
00316 
00317     KURL url = fileItem->url();
00318     if ( !fileItem->isReadable() )
00319     {
00320         // No permissions or local file that doesn't exist - need to find out which
00321         if ( ( !fileItem->isLocalFile() ) || QFile::exists( url.path() ) )
00322         {
00323             KMessageBox::error( widget(), i18n("<p>You do not have enough permissions to read <b>%1</b></p>").arg(url.prettyURL()) );
00324             return;
00325         }
00326         KMessageBox::error( widget(), i18n("<p><b>%1</b> does not seem to exist anymore</p>").arg(url.prettyURL()) );
00327         return;
00328     }
00329 
00330     KParts::URLArgs args;
00331      
00332     fileItem->determineMimeType();
00333      if ( fileItem->isMimeTypeKnown() )
00334          args.serviceType = fileItem->mimetype();
00335      args.trustedSource = true;
00336 
00337     if ( fileItem->isLink() && is_local ) // see KFileItem::run
00338         url = KURL( url, KURL::encode_string( fileItem->linkDest() ) );
00339 
00340     if (KonqFMSettings::settings()->alwaysNewWin() && fileItem->isDir()) {
00341         //args.frameName = "_blank"; // open new window
00342         // We tried the other option, passing the path as framename so that
00343         // an existing window for that dir is reused (like MSWindows does when
00344         // the similar option is activated and the sidebar is hidden (!)).
00345         // But this requires some work, including changing the framename
00346         // when navigating, etc. Not very much requested yet, in addition.
00347         KParts::WindowArgs wargs;
00348         KParts::ReadOnlyPart* dummy;
00349         emit m_extension->createNewWindow( url, args, wargs, dummy );
00350     }
00351     else
00352     {
00353         if (!fileItem->isDir())
00354         {
00355             url = fileItem->mostLocalURL(is_local);
00356         }
00357         kdDebug() << "emit m_extension->openURLRequest( " << url.url() << "," << args.serviceType << ")" << endl;
00358         emit m_extension->openURLRequest( url, args );
00359     }
00360 }
00361 
00362 void KonqDirPart::mmbClicked( KFileItem * fileItem )
00363 {
00364     if ( fileItem )
00365     {
00366         // Optimisation to avoid KRun to call kfmclient that then tells us
00367         // to open a window :-)
00368         KService::Ptr offer = KServiceTypeProfile::preferredService(fileItem->mimetype(), "Application");
00369         //if (offer) kdDebug(1203) << "KonqDirPart::mmbClicked: got service " << offer->desktopEntryName() << endl;
00370         if ( offer && offer->desktopEntryName().startsWith("kfmclient") )
00371         {
00372             KParts::URLArgs args;
00373             args.serviceType = fileItem->mimetype();
00374             emit m_extension->createNewWindow( fileItem->url(), args );
00375         }
00376         else
00377             fileItem->run();
00378     }
00379     else
00380     {
00381         m_extension->pasteRequest();
00382     }
00383 }
00384 
00385 void KonqDirPart::saveState( QDataStream& stream )
00386 {
00387     stream << m_nameFilter;
00388 }
00389 
00390 void KonqDirPart::restoreState( QDataStream& stream )
00391 {
00392     stream >> m_nameFilter;
00393 }
00394 
00395 void KonqDirPart::saveFindState( QDataStream& stream )
00396 {
00397     // assert only doable in KDE4.
00398     //assert( m_findPart ); // test done by caller.
00399     if ( !m_findPart )
00400         return;
00401 
00402     // When we have a find part, our own URL wasn't saved (see KonqDirPartBrowserExtension)
00403     // So let's do it here
00404     stream << m_url;
00405 
00406     KParts::BrowserExtension* ext = KParts::BrowserExtension::childObject( m_findPart );
00407     if( !ext )
00408         return;
00409 
00410     ext->saveState( stream );
00411 }
00412 
00413 void KonqDirPart::restoreFindState( QDataStream& stream )
00414 {
00415     // Restore our own URL
00416     stream >> m_url;
00417 
00418     emit findOpen( this );
00419 
00420     KParts::BrowserExtension* ext = KParts::BrowserExtension::childObject( m_findPart );
00421     slotClear();
00422 
00423     if( !ext )
00424         return;
00425 
00426     ext->restoreState( stream );
00427 }
00428 
00429 void KonqDirPart::slotClipboardDataChanged()
00430 {
00431     // This is very related to KDIconView::slotClipboardDataChanged
00432 
00433     KURL::List lst;
00434     QMimeSource *data = QApplication::clipboard()->data();
00435     if ( data->provides( "application/x-kde-cutselection" ) && data->provides( "text/uri-list" ) )
00436         if ( KonqDrag::decodeIsCutSelection( data ) )
00437             (void) KURLDrag::decode( data, lst );
00438 
00439     disableIcons( lst );
00440 
00441     updatePasteAction();
00442 }
00443 
00444 void KonqDirPart::updatePasteAction()
00445 {
00446     QMimeSource *data = QApplication::clipboard()->data();
00447     bool paste = ( data->format() != 0 );
00448 
00449     emit m_extension->enableAction( "paste", paste ); // TODO : if only one url, check that it's a dir
00450 }
00451 
00452 void KonqDirPart::newItems( const KFileItemList & entries )
00453 {
00454     d->dirSizeDirty = true;
00455     if ( m_findPart )
00456         emitTotalCount();
00457 
00458     emit itemsAdded( entries );
00459 }
00460 
00461 void KonqDirPart::deleteItem( KFileItem * fileItem )
00462 {
00463     d->dirSizeDirty = true;
00464     emit itemRemoved( fileItem );
00465 }
00466 
00467 void KonqDirPart::emitTotalCount()
00468 {
00469     if ( !d->dirLister || d->dirLister->url().isEmpty() )
00470         return;
00471     if ( d->dirSizeDirty ) {
00472         m_lDirSize = 0;
00473         m_lFileCount = 0;
00474         m_lDirCount = 0;
00475         KFileItemList entries = d->dirLister->items();
00476         for (KFileItemListIterator it(entries); it.current(); ++it)
00477         {
00478             if ( !it.current()->isDir() )
00479             {
00480                 if (!it.current()->isLink()) // symlinks don't contribute to the size
00481                     m_lDirSize += it.current()->size();
00482                 m_lFileCount++;
00483             }
00484             else
00485                 m_lDirCount++;
00486         }
00487         d->dirSizeDirty = false;
00488     }
00489 
00490     QString summary =
00491         KIO::itemsSummaryString(m_lFileCount + m_lDirCount,
00492                                 m_lFileCount,
00493                                 m_lDirCount,
00494                                 m_lDirSize,
00495                                 true);
00496     bool bShowsResult = false;
00497     if (m_findPart)
00498     {
00499         QVariant prop = m_findPart->property( "showsResult" );
00500         bShowsResult = prop.isValid() && prop.toBool();
00501     }
00502     //kdDebug(1203) << "KonqDirPart::emitTotalCount bShowsResult=" << bShowsResult << endl;
00503     emit setStatusBarText( bShowsResult ? i18n("Search result: %1").arg(summary) : summary );
00504 }
00505 
00506 void KonqDirPart::emitCounts( const KFileItemList & lst )
00507 {
00508     if ( lst.count() == 1 )
00509         emit setStatusBarText( ((KFileItemList)lst).first()->getStatusBarInfo() );
00510     else
00511     {
00512         long long fileSizeSum = 0;
00513         uint fileCount = 0;
00514         uint dirCount = 0;
00515 
00516         for ( KFileItemListIterator it( lst ); it.current(); ++it )
00517         {
00518             if ( it.current()->isDir() )
00519                 dirCount++;
00520             else
00521             {
00522                 if ( !it.current()->isLink() ) // ignore symlinks
00523                     fileSizeSum += it.current()->size();
00524                 fileCount++;
00525             }
00526         }
00527 
00528         emit setStatusBarText( KIO::itemsSummaryString( fileCount + dirCount,
00529                                                         fileCount, dirCount,
00530                                                         fileSizeSum, true ) );
00531     }
00532 }
00533 
00534 void KonqDirPart::emitCounts( const KFileItemList & lst, bool selectionChanged )
00535 {
00536     if ( lst.count() == 0 )
00537         emitTotalCount();
00538     else
00539         emitCounts( lst );
00540 
00541     // Yes, the caller could do that too :)
00542     // But this bool could also be used to cache the QString for the last
00543     // selection, as long as selectionChanged is false.
00544     // Not sure it's worth it though.
00545     // MiB: no, I don't think it's worth it. Especially regarding the
00546     //      loss of readability of the code. Thus, this will be removed in
00547     //      KDE 4.0.
00548     if ( selectionChanged )
00549         emit m_extension->selectionInfo( lst );
00550 }
00551 
00552 void KonqDirPart::emitMouseOver( const KFileItem* item )
00553 {
00554     emit m_extension->mouseOverInfo( item );
00555 }
00556 
00557 void KonqDirPart::slotIconSizeToggled( bool toggleOn )
00558 {
00559     //kdDebug(1203) << "KonqDirPart::slotIconSizeToggled" << endl;
00560 
00561     // This slot is called when an iconsize action is checked or by calling
00562     // action->setChecked(false) (previously true). So we must filter out
00563     // the 'untoggled' case to prevent odd results here (repaints/loops!)
00564     if ( !toggleOn )
00565         return;
00566 
00567     if ( m_paDefaultIcons->isChecked() )
00568         setIconSize(0);
00569     else if ( d->aEnormousIcons->isChecked() )
00570         setIconSize(d->findNearestIconSize(KIcon::SizeEnormous));
00571     else if ( m_paHugeIcons->isChecked() )
00572         setIconSize(d->findNearestIconSize(KIcon::SizeHuge));
00573     else if ( m_paLargeIcons->isChecked() )
00574         setIconSize(d->findNearestIconSize(KIcon::SizeLarge));
00575     else if ( m_paMediumIcons->isChecked() )
00576         setIconSize(d->findNearestIconSize(KIcon::SizeMedium));
00577     else if ( d->aSmallMediumIcons->isChecked() )
00578         setIconSize(d->findNearestIconSize(KIcon::SizeSmallMedium));
00579     else if ( m_paSmallIcons->isChecked() )
00580         setIconSize(d->findNearestIconSize(KIcon::SizeSmall));
00581 }
00582 
00583 void KonqDirPart::slotIncIconSize()
00584 {
00585     int s = m_pProps->iconSize();
00586     s = s ? s : KGlobal::iconLoader()->currentSize( KIcon::Desktop );
00587     uint sizeIndex = 0;
00588     for ( uint idx = 1; idx < d->iconSize.count() ; ++idx )
00589         if (s == d->iconSize[idx]) {
00590             sizeIndex = idx;
00591         break;
00592     }
00593     if ( sizeIndex > 0 && sizeIndex < d->iconSize.count() - 1 )
00594     {
00595         setIconSize( d->iconSize[sizeIndex + 1] );
00596     }
00597 }
00598 
00599 void KonqDirPart::slotDecIconSize()
00600 {
00601     int s = m_pProps->iconSize();
00602     s = s ? s : KGlobal::iconLoader()->currentSize( KIcon::Desktop );
00603     uint sizeIndex = 0;
00604     for ( uint idx = 1; idx < d->iconSize.count() ; ++idx )
00605         if (s == d->iconSize[idx]) {
00606             sizeIndex = idx;
00607         break;
00608     }
00609     if ( sizeIndex > 1 )
00610     {
00611         setIconSize( d->iconSize[sizeIndex - 1] );
00612     }
00613 }
00614 
00615 // Only updates Actions, a GUI update is done in the views by reimplementing this
00616 void KonqDirPart::newIconSize( int size /*0=default, or 16,32,48....*/ )
00617 {
00618     int realSize = (size==0) ? KGlobal::iconLoader()->currentSize( KIcon::Desktop ) : size;
00619     m_paDecIconSize->setEnabled(realSize > d->iconSize[1]);
00620     m_paIncIconSize->setEnabled(realSize < d->iconSize.back());
00621 
00622     m_paDefaultIcons->setChecked(size == 0);
00623     d->aEnormousIcons->setChecked(size == d->findNearestIconSize(KIcon::SizeEnormous));
00624     m_paHugeIcons->setChecked(size == d->findNearestIconSize(KIcon::SizeHuge));
00625     m_paLargeIcons->setChecked(size == d->findNearestIconSize(KIcon::SizeLarge));
00626     m_paMediumIcons->setChecked(size == d->findNearestIconSize(KIcon::SizeMedium));
00627     d->aSmallMediumIcons->setChecked(size == d->findNearestIconSize(KIcon::SizeSmallMedium));
00628     m_paSmallIcons->setChecked(size == d->findNearestIconSize(KIcon::SizeSmall));
00629 }
00630 
00631 // Stores the new icon size and updates the GUI
00632 void KonqDirPart::setIconSize( int size )
00633 {
00634     //kdDebug(1203) << "KonqDirPart::setIconSize " << size << " -> updating props and GUI" << endl;
00635     m_pProps->setIconSize( size );
00636     newIconSize( size );
00637 }
00638 
00639 bool KonqDirPart::closeURL()
00640 {
00641     // Tell all the childern objects to clean themselves up for dinner :)
00642     return doCloseURL();
00643 }
00644 
00645 bool KonqDirPart::openURL(const KURL& url)
00646 {
00647     if ( m_findPart )
00648     {
00649         kdDebug(1203) << "KonqDirPart::openURL -> emit findClosed " << this << endl;
00650         delete m_findPart;
00651         m_findPart = 0L;
00652         emit findClosed( this );
00653     }
00654 
00655     m_url = url;
00656     emit aboutToOpenURL ();
00657 
00658     return doOpenURL(url);
00659 }
00660 
00661 void KonqDirPart::setFindPart( KParts::ReadOnlyPart * part )
00662 {
00663     assert(part);
00664     m_findPart = part;
00665     connect( m_findPart, SIGNAL( started() ),
00666              this, SLOT( slotStarted() ) );
00667     connect( m_findPart, SIGNAL( started() ),
00668              this, SLOT( slotStartAnimationSearching() ) );
00669     connect( m_findPart, SIGNAL( clear() ),
00670              this, SLOT( slotClear() ) );
00671     connect( m_findPart, SIGNAL( newItems( const KFileItemList & ) ),
00672              this, SLOT( slotNewItems( const KFileItemList & ) ) );
00673     connect( m_findPart, SIGNAL( finished() ), // can't name it completed, it conflicts with a KROP signal
00674              this, SLOT( slotCompleted() ) );
00675     connect( m_findPart, SIGNAL( finished() ),
00676              this, SLOT( slotStopAnimationSearching() ) );
00677     connect( m_findPart, SIGNAL( canceled() ),
00678              this, SLOT( slotCanceled() ) );
00679     connect( m_findPart, SIGNAL( canceled() ),
00680              this, SLOT( slotStopAnimationSearching() ) );
00681 
00682     connect( m_findPart, SIGNAL( findClosed() ),
00683              this, SLOT( slotFindClosed() ) );
00684 
00685     emit findOpened( this );
00686 
00687     // set the initial URL in the find part
00688     m_findPart->openURL( url() );
00689 }
00690 
00691 void KonqDirPart::slotFindClosed()
00692 {
00693     kdDebug(1203) << "KonqDirPart::slotFindClosed -> emit findClosed " << this << endl;
00694     delete m_findPart;
00695     m_findPart = 0L;
00696     emit findClosed( this );
00697     // reload where we were before
00698     openURL( url() );
00699 }
00700 
00701 void KonqDirPart::slotIconChanged( int group )
00702 {
00703     if (group != KIcon::Desktop) return;
00704     adjustIconSizes();
00705 }
00706 
00707 void KonqDirPart::slotStartAnimationSearching()
00708 {
00709   started(0);
00710 }
00711 
00712 void KonqDirPart::slotStopAnimationSearching()
00713 {
00714   completed();
00715 }
00716 
00717 void KonqDirPartBrowserExtension::saveState( QDataStream &stream )
00718 {
00719     m_dirPart->saveState( stream );
00720     bool hasFindPart = m_dirPart->findPart();
00721     stream << hasFindPart;
00722     assert( ! ( hasFindPart && m_dirPart->className() == "KFindPart" ) );
00723     if ( !hasFindPart )
00724         KParts::BrowserExtension::saveState( stream );
00725     else {
00726         m_dirPart->saveFindState( stream );
00727     }
00728 }
00729 
00730 void KonqDirPartBrowserExtension::restoreState( QDataStream &stream )
00731 {
00732     m_dirPart->restoreState( stream );
00733     bool hasFindPart;
00734     stream >> hasFindPart;
00735     assert( ! ( hasFindPart && m_dirPart->className() == "KFindPart" ) );
00736     if ( !hasFindPart )
00737         // This calls openURL, that's why we don't want to call it in case of a find part
00738         KParts::BrowserExtension::restoreState( stream );
00739     else {
00740         m_dirPart->restoreFindState( stream );
00741     }
00742 }
00743 
00744 
00745 void KonqDirPart::resetCount()
00746 {
00747     m_lDirSize = 0;
00748     m_lFileCount = 0;
00749     m_lDirCount = 0;
00750     d->dirSizeDirty = true;
00751 }
00752 
00753 void KonqDirPart::setDirLister( KDirLister* lister )
00754 {
00755     d->dirLister = lister;
00756 }
00757 
00758 #include "konq_dirpart.moc"
KDE Logo
This file is part of the documentation for libkonq Library Version 3.4.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jun 14 19:05:21 2006 by doxygen 1.4.4 written by Dimitri van Heesch, © 1997-2003