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