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