20 #include "konq_dirpart.h"
21 #include "konq_bgnddlg.h"
22 #include "konq_propsview.h"
23 #include "konq_settings.h"
25 #include <tdeio/paste.h>
26 #include <tdeapplication.h>
27 #include <tdeaction.h>
28 #include <kdatastream.h>
30 #include <kdirlister.h>
31 #include <kiconloader.h>
32 #include <tdelocale.h>
33 #include <tdemessagebox.h>
34 #include <konq_drag.h>
35 #include <tdeparts/browserextension.h>
37 #include <kuserprofile.h>
38 #include <kurifilter.h>
39 #include <tdeglobalsettings.h>
41 #include <tqapplication.h>
42 #include <tqclipboard.h>
44 #include <tqguardedptr.h>
46 #include <tqvaluevector.h>
48 class KonqDirPart::KonqDirPartPrivate
51 KonqDirPartPrivate() : dirLister( 0 ) {}
52 TQStringList mimeFilters;
53 TDEToggleAction *aEnormousIcons;
54 TDEToggleAction *aSmallMediumIcons;
55 TQValueVector<int> iconSize;
57 KDirLister* dirLister;
60 void findAvailableIconSizes(
void);
61 int findNearestIconSize(
int size);
62 int nearestIconSizeError(
int size);
65 void KonqDirPart::KonqDirPartPrivate::findAvailableIconSizes(
void)
67 TDEIconTheme *root = TDEGlobal::instance()->iconLoader()->theme();
70 TQValueList<int> avSizes = root->querySizes(TDEIcon::Desktop);
71 kdDebug(1203) <<
"The icon theme handles the sizes:" << avSizes << endl;
74 if (avSizes.count() < 10) {
76 TQValueListConstIterator<int> i;
77 for (i = avSizes.begin(); i != avSizes.end(); i++) {
79 if (*i != oldSize) iconSize.append(*i);
84 const int progression[] = {16, 22, 32, 48, 64, 96, 128, 192, 256};
86 TQValueListConstIterator<int> j = avSizes.begin();
87 for (uint i = 0; i < 9; i++) {
88 while (j++ != avSizes.end()) {
89 if (*j >= progression[i]) {
91 kdDebug(1203) <<
"appending " << *j <<
" size." << endl;
98 iconSize.append(TDEIcon::SizeSmall);
99 iconSize.append(TDEIcon::SizeMedium);
100 iconSize.append(TDEIcon::SizeLarge);
101 iconSize.append(TDEIcon::SizeHuge);
103 kdDebug(1203) <<
"Using " << iconSize.count() <<
" icon sizes." << endl;
106 int KonqDirPart::KonqDirPartPrivate::findNearestIconSize(
int preferred)
108 int s1 = iconSize[1];
109 if (preferred == 0)
return TDEGlobal::iconLoader()->currentSize(TDEIcon::Desktop);
110 if (preferred <= s1)
return s1;
111 for (uint i = 2; i <= iconSize.count(); i++) {
112 if (preferred <= iconSize[i]) {
113 if (preferred - s1 < iconSize[i] - preferred)
return s1;
114 else return iconSize[i];
122 int KonqDirPart::KonqDirPartPrivate::nearestIconSizeError(
int size)
124 return TQABS(size - findNearestIconSize(size));
127 KonqDirPart::KonqDirPart( TQObject *parent,
const char *name )
128 :KParts::ReadOnlyPart( parent, name ),
132 d =
new KonqDirPartPrivate;
136 connect( TQApplication::clipboard(), TQ_SIGNAL(dataChanged()),
this, TQ_SLOT(slotClipboardDataChanged()) );
138 actionCollection()->setHighlightingEnabled(
true );
140 m_paIncIconSize =
new TDEAction( i18n(
"Enlarge Icons" ),
"zoom-in", 0,
this, TQ_SLOT( slotIncIconSize() ), actionCollection(),
"incIconSize" );
141 m_paDecIconSize =
new TDEAction( i18n(
"Shrink Icons" ),
"zoom-out", 0,
this, TQ_SLOT( slotDecIconSize() ), actionCollection(),
"decIconSize" );
143 m_paDefaultIcons =
new TDERadioAction( i18n(
"&Default Size" ), 0, actionCollection(),
"modedefault" );
144 d->aEnormousIcons =
new TDERadioAction( i18n(
"&Huge" ), 0,
145 actionCollection(),
"modeenormous" );
146 m_paHugeIcons =
new TDERadioAction( i18n(
"&Very Large" ), 0, actionCollection(),
"modehuge" );
147 m_paLargeIcons =
new TDERadioAction( i18n(
"&Large" ), 0, actionCollection(),
"modelarge" );
148 m_paMediumIcons =
new TDERadioAction( i18n(
"&Medium" ), 0, actionCollection(),
"modemedium" );
149 d->aSmallMediumIcons =
new TDERadioAction( i18n(
"&Small" ), 0,
150 actionCollection(),
"modesmallmedium" );
151 m_paSmallIcons =
new TDERadioAction( i18n(
"&Tiny" ), 0, actionCollection(),
"modesmall" );
153 m_paDefaultIcons->setExclusiveGroup(
"ViewMode" );
154 d->aEnormousIcons->setExclusiveGroup(
"ViewMode" );
155 m_paHugeIcons->setExclusiveGroup(
"ViewMode" );
156 m_paLargeIcons->setExclusiveGroup(
"ViewMode" );
157 m_paMediumIcons->setExclusiveGroup(
"ViewMode" );
158 d->aSmallMediumIcons->setExclusiveGroup(
"ViewMode" );
159 m_paSmallIcons->setExclusiveGroup(
"ViewMode" );
161 connect( m_paDefaultIcons, TQ_SIGNAL( toggled(
bool ) ),
this, TQ_SLOT( slotIconSizeToggled(
bool ) ) );
162 connect( d->aEnormousIcons, TQ_SIGNAL( toggled(
bool ) ),
163 this, TQ_SLOT( slotIconSizeToggled(
bool ) ) );
164 connect( m_paHugeIcons, TQ_SIGNAL( toggled(
bool ) ),
this, TQ_SLOT( slotIconSizeToggled(
bool ) ) );
165 connect( m_paLargeIcons, TQ_SIGNAL( toggled(
bool ) ),
this, TQ_SLOT( slotIconSizeToggled(
bool ) ) );
166 connect( m_paMediumIcons, TQ_SIGNAL( toggled(
bool ) ),
this, TQ_SLOT( slotIconSizeToggled(
bool ) ) );
167 connect( d->aSmallMediumIcons, TQ_SIGNAL( toggled(
bool ) ),
168 this, TQ_SLOT( slotIconSizeToggled(
bool ) ) );
169 connect( m_paSmallIcons, TQ_SIGNAL( toggled(
bool ) ),
this, TQ_SLOT( slotIconSizeToggled(
bool ) ) );
171 connect( kapp, TQ_SIGNAL(iconChanged(
int)), TQ_SLOT(slotIconChanged(
int)) );
178 d->iconSize[1] = TDEIcon::SizeSmall;
179 d->iconSize[2] = TDEIcon::SizeSmallMedium;
180 d->iconSize[3] = TDEIcon::SizeMedium;
181 d->iconSize[4] = TDEIcon::SizeLarge;
182 d->iconSize[5] = TDEIcon::SizeHuge;
183 d->iconSize[6] = TDEIcon::SizeEnormous;
184 d->iconSize[7] = 192;
185 d->iconSize[8] = 256;
186 TDEIconTheme *root = TDEGlobal::instance()->iconLoader()->theme();
189 TQValueList<int> avSizes = root->querySizes(TDEIcon::Desktop);
190 kdDebug(1203) <<
"the icon theme handles the following sizes:" << avSizes << endl;
191 if (avSizes.count() < 10) {
195 TQValueList<int>::Iterator it;
196 for (i=1, it=avSizes.begin(); (it!=avSizes.end()) && (i<7); it++, i++)
198 d->iconSize[i] = *it;
199 kdDebug(1203) <<
"m_iIconSize[" << i <<
"] = " << *it << endl;
203 d->iconSize[i] = d->iconSize[i - 1] + d->iconSize[i - 1] / 2 ;
204 kdDebug(1203) <<
"m_iIconSize[" << i <<
"] = " << d->iconSize[i] << endl;
209 d->iconSize.reserve(10);
210 d->iconSize.append(0);
216 m_iIconSize[1] = TDEIcon::SizeSmall;
217 m_iIconSize[2] = TDEIcon::SizeMedium;
218 m_iIconSize[3] = TDEIcon::SizeLarge;
219 m_iIconSize[4] = TDEIcon::SizeHuge;
222 TDEAction *a =
new TDEAction( i18n(
"Configure Background..." ),
"background", 0,
this, TQ_SLOT( slotBackgroundSettings() ),
223 actionCollection(),
"bgsettings" );
225 a->setToolTip( i18n(
"Allows choosing of background settings for this view" ) );
228 KonqDirPart::~KonqDirPart()
236 void KonqDirPart::adjustIconSizes()
238 d->findAvailableIconSizes();
239 m_paSmallIcons->setEnabled(d->findNearestIconSize(16) < 20);
240 d->aSmallMediumIcons->setEnabled(d->nearestIconSizeError(22) < 2);
241 m_paMediumIcons->setEnabled(d->nearestIconSizeError(32) < 6);
242 m_paLargeIcons->setEnabled(d->nearestIconSizeError(48) < 8);
243 m_paHugeIcons->setEnabled(d->nearestIconSizeError(64) < 12);
244 d->aEnormousIcons->setEnabled(d->findNearestIconSize(128) > 110);
247 int size = m_pProps->iconSize();
248 int nearSize = d->findNearestIconSize(size);
250 if (size != nearSize) {
251 m_pProps->setIconSize(nearSize);
253 newIconSize(nearSize);
257 void KonqDirPart::setMimeFilter (
const TQStringList& mime)
259 TQString u = url().url();
264 if ( mime.isEmpty() )
265 d->mimeFilters.clear();
267 d->mimeFilters = mime;
270 TQStringList KonqDirPart::mimeFilter()
const
272 return d->mimeFilters;
275 TQScrollView * KonqDirPart::scrollWidget()
277 return static_cast<TQScrollView *
>(widget());
280 void KonqDirPart::slotBackgroundSettings()
282 TQColor bgndColor = m_pProps->bgColor( widget() );
283 TQColor defaultColor = TDEGlobalSettings::baseColor();
287 m_pProps->bgPixmapFile(),
291 if ( dlg->exec() == KonqBgndDialog::Accepted )
293 if ( dlg->color().isValid() )
295 m_pProps->setBgColor( dlg->color() );
296 m_pProps->setBgPixmapFile(
"" );
300 m_pProps->setBgColor( defaultColor );
301 m_pProps->setBgPixmapFile( dlg->pixmapFile() );
303 m_pProps->applyColors( scrollWidget()->viewport() );
304 scrollWidget()->viewport()->repaint();
310 void KonqDirPart::lmbClicked( KFileItem * fileItem )
312 KURL url = fileItem->url();
313 if ( !fileItem->isReadable() )
316 if ( ( !fileItem->isLocalFile() ) || TQFile::exists( url.path() ) )
318 KMessageBox::error( widget(), i18n(
"<p>You do not have enough permissions to read <b>%1</b></p>").arg(url.prettyURL()) );
321 KMessageBox::error( widget(), i18n(
"<p><b>%1</b> does not seem to exist anymore</p>").arg(url.prettyURL()) );
325 KParts::URLArgs args;
326 fileItem->determineMimeType();
327 if ( fileItem->isMimeTypeKnown() )
328 args.serviceType = fileItem->mimetype();
329 args.trustedSource =
true;
338 KParts::WindowArgs wargs;
339 KParts::ReadOnlyPart* dummy;
340 emit m_extension->createNewWindow( url, args, wargs, dummy );
344 kdDebug() <<
"emit m_extension->openURLRequest( " << url.url() <<
"," << args.serviceType <<
")" << endl;
345 emit m_extension->openURLRequest( url, args );
349 void KonqDirPart::mmbClicked( KFileItem * fileItem )
355 KService::Ptr offer = KServiceTypeProfile::preferredService(fileItem->mimetype(),
"Application");
357 if ( offer && offer->desktopEntryName().startsWith(
"kfmclient") )
359 KParts::URLArgs args;
360 args.serviceType = fileItem->mimetype();
361 emit m_extension->createNewWindow( fileItem->url(), args );
368 m_extension->pasteRequest();
372 void KonqDirPart::saveState( TQDataStream& stream )
374 stream << m_nameFilter;
377 void KonqDirPart::restoreState( TQDataStream& stream )
379 stream >> m_nameFilter;
382 void KonqDirPart::saveFindState( TQDataStream& stream )
393 KParts::BrowserExtension* ext = KParts::BrowserExtension::childObject( m_findPart );
397 ext->saveState( stream );
400 void KonqDirPart::restoreFindState( TQDataStream& stream )
405 emit findOpen(
this );
407 KParts::BrowserExtension* ext = KParts::BrowserExtension::childObject( m_findPart );
413 ext->restoreState( stream );
416 void KonqDirPart::slotClipboardDataChanged()
421 TQMimeSource *data = TQApplication::clipboard()->data();
422 if ( data->provides(
"application/x-tde-cutselection" ) && data->provides(
"text/uri-list" ) ) {
423 if ( KonqDrag::decodeIsCutSelection( data ) ) {
424 (void) KURLDrag::decode( data, lst );
433 void KonqDirPart::updatePasteAction()
435 TQString actionText = TDEIO::pasteActionText();
436 bool paste = !actionText.isEmpty();
438 emit m_extension->setActionText(
"paste", actionText );
440 emit m_extension->enableAction(
"paste", paste );
443 void KonqDirPart::newItems(
const KFileItemList &entries)
445 d->dirSizeDirty =
true;
450 emit itemsAdded(entries);
453 void KonqDirPart::deleteItem(KFileItem * fileItem)
455 d->dirSizeDirty =
true;
456 emit itemRemoved(fileItem);
459 void KonqDirPart::refreshItems(
const KFileItemList &entries)
461 emit itemsRefresh(entries);
464 void KonqDirPart::emitTotalCount()
466 if ( !d->dirLister || d->dirLister->url().isEmpty() ) {
469 if ( d->dirSizeDirty ) {
473 KFileItemList entries = d->dirLister->items();
474 for (KFileItemListIterator it(entries); it.current(); ++it)
476 if ( !it.current()->isDir() )
478 if (!it.current()->isLink()) {
479 m_lDirSize += it.current()->size();
487 d->dirSizeDirty =
false;
491 TDEIO::itemsSummaryString(m_lFileCount + m_lDirCount,
496 bool bShowsResult =
false;
499 TQVariant prop = m_findPart->property(
"showsResult" );
500 bShowsResult = prop.isValid() && prop.toBool();
503 emit setStatusBarText( bShowsResult ? i18n(
"Search result: %1").arg(summary) : summary );
506 void KonqDirPart::emitCounts(
const KFileItemList & lst )
508 if ( lst.count() == 1 )
509 emit setStatusBarText( ((KFileItemList)lst).first()->getStatusBarInfo() );
512 long long fileSizeSum = 0;
516 for ( KFileItemListIterator it( lst ); it.current(); ++it )
518 if ( it.current()->isDir() )
522 if ( !it.current()->isLink() )
523 fileSizeSum += it.current()->size();
528 emit setStatusBarText( TDEIO::itemsSummaryString( fileCount + dirCount,
530 fileSizeSum,
true ) );
534 void KonqDirPart::emitCounts(
const KFileItemList & lst,
bool selectionChanged )
536 if ( lst.count() == 0 ) {
550 if ( selectionChanged ) {
551 emit m_extension->selectionInfo( lst );
555 void KonqDirPart::emitMouseOver(
const KFileItem* item )
557 emit m_extension->mouseOverInfo( item );
560 void KonqDirPart::slotIconSizeToggled(
bool toggleOn )
570 if ( m_paDefaultIcons->isChecked() )
572 else if ( d->aEnormousIcons->isChecked() )
573 setIconSize(d->findNearestIconSize(TDEIcon::SizeEnormous));
574 else if ( m_paHugeIcons->isChecked() )
575 setIconSize(d->findNearestIconSize(TDEIcon::SizeHuge));
576 else if ( m_paLargeIcons->isChecked() )
577 setIconSize(d->findNearestIconSize(TDEIcon::SizeLarge));
578 else if ( m_paMediumIcons->isChecked() )
579 setIconSize(d->findNearestIconSize(TDEIcon::SizeMedium));
580 else if ( d->aSmallMediumIcons->isChecked() )
581 setIconSize(d->findNearestIconSize(TDEIcon::SizeSmallMedium));
582 else if ( m_paSmallIcons->isChecked() )
583 setIconSize(d->findNearestIconSize(TDEIcon::SizeSmall));
586 void KonqDirPart::slotIncIconSize()
588 int s = m_pProps->iconSize();
589 s = s ? s : TDEGlobal::iconLoader()->currentSize( TDEIcon::Desktop );
591 for ( uint idx = 1; idx < d->iconSize.count() ; ++idx )
592 if (s == d->iconSize[idx]) {
596 if ( sizeIndex > 0 && sizeIndex < d->iconSize.count() - 1 )
598 setIconSize( d->iconSize[sizeIndex + 1] );
602 void KonqDirPart::slotDecIconSize()
604 int s = m_pProps->iconSize();
605 s = s ? s : TDEGlobal::iconLoader()->currentSize( TDEIcon::Desktop );
607 for ( uint idx = 1; idx < d->iconSize.count() ; ++idx )
608 if (s == d->iconSize[idx]) {
614 setIconSize( d->iconSize[sizeIndex - 1] );
619 void KonqDirPart::newIconSize(
int size )
621 int realSize = (size==0) ? TDEGlobal::iconLoader()->currentSize( TDEIcon::Desktop ) : size;
622 m_paDecIconSize->setEnabled(realSize > d->iconSize[1]);
623 m_paIncIconSize->setEnabled(realSize < d->iconSize.back());
625 m_paDefaultIcons->setChecked(size == 0);
626 d->aEnormousIcons->setChecked(size == d->findNearestIconSize(TDEIcon::SizeEnormous));
627 m_paHugeIcons->setChecked(size == d->findNearestIconSize(TDEIcon::SizeHuge));
628 m_paLargeIcons->setChecked(size == d->findNearestIconSize(TDEIcon::SizeLarge));
629 m_paMediumIcons->setChecked(size == d->findNearestIconSize(TDEIcon::SizeMedium));
630 d->aSmallMediumIcons->setChecked(size == d->findNearestIconSize(TDEIcon::SizeSmallMedium));
631 m_paSmallIcons->setChecked(size == d->findNearestIconSize(TDEIcon::SizeSmall));
635 void KonqDirPart::setIconSize(
int size )
638 m_pProps->setIconSize( size );
642 bool KonqDirPart::closeURL()
648 bool KonqDirPart::openURL(
const KURL& url)
652 kdDebug(1203) <<
"KonqDirPart::openURL -> emit findClosed " <<
this << endl;
655 emit findClosed(
this );
659 emit aboutToOpenURL ();
661 return doOpenURL(url);
664 void KonqDirPart::setFindPart( KParts::ReadOnlyPart * part )
668 connect( m_findPart, TQ_SIGNAL( started() ),
669 this, TQ_SLOT( slotStarted() ) );
670 connect( m_findPart, TQ_SIGNAL( started() ),
671 this, TQ_SLOT( slotStartAnimationSearching() ) );
672 connect( m_findPart, TQ_SIGNAL( clear() ),
673 this, TQ_SLOT( slotClear() ) );
674 connect( m_findPart, TQ_SIGNAL( newItems(
const KFileItemList & ) ),
675 this, TQ_SLOT( slotNewItems(
const KFileItemList & ) ) );
676 connect( m_findPart, TQ_SIGNAL( finished() ),
677 this, TQ_SLOT( slotCompleted() ) );
678 connect( m_findPart, TQ_SIGNAL( finished() ),
679 this, TQ_SLOT( slotStopAnimationSearching() ) );
680 connect( m_findPart, TQ_SIGNAL( canceled() ),
681 this, TQ_SLOT( slotCanceled() ) );
682 connect( m_findPart, TQ_SIGNAL( canceled() ),
683 this, TQ_SLOT( slotStopAnimationSearching() ) );
685 connect( m_findPart, TQ_SIGNAL( findClosed() ),
686 this, TQ_SLOT( slotFindClosed() ) );
688 emit findOpened(
this );
691 m_findPart->openURL( url() );
694 void KonqDirPart::slotFindClosed()
696 kdDebug(1203) <<
"KonqDirPart::slotFindClosed -> emit findClosed " <<
this << endl;
699 emit findClosed(
this );
704 void KonqDirPart::slotIconChanged(
int group )
706 if (group != TDEIcon::Desktop)
return;
710 void KonqDirPart::slotStartAnimationSearching()
715 void KonqDirPart::slotStopAnimationSearching()
720 void KonqDirPartBrowserExtension::saveState( TQDataStream &stream )
722 m_dirPart->saveState( stream );
723 bool hasFindPart = m_dirPart->findPart();
724 stream << hasFindPart;
725 assert( ! ( hasFindPart && !strcmp(m_dirPart->className(),
"KFindPart") ) );
727 KParts::BrowserExtension::saveState( stream );
729 m_dirPart->saveFindState( stream );
733 void KonqDirPartBrowserExtension::restoreState( TQDataStream &stream )
735 m_dirPart->restoreState( stream );
737 stream >> hasFindPart;
738 assert( ! ( hasFindPart && !strcmp(m_dirPart->className(),
"KFindPart") ) );
741 KParts::BrowserExtension::restoreState( stream );
743 m_dirPart->restoreFindState( stream );
748 void KonqDirPart::resetCount()
753 d->dirSizeDirty =
true;
756 void KonqDirPart::setDirLister( KDirLister* lister )
758 d->dirLister = lister;
761 #include "konq_dirpart.moc"
Dialog for configuring the background Currently it defines and shows the pixmaps under the tiles reso...
static KonqFMSettings * settings()
The static instance of KonqFMSettings.