You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
762 lines
24 KiB
762 lines
24 KiB
15 years ago
|
/* This file is part of the KDE projects
|
||
|
Copyright (C) 2000 David Faure <faure@kde.org>
|
||
|
|
||
|
This program is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This program is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU General Public License
|
||
|
along with this program; see the file COPYING. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include "konq_dirpart.h"
|
||
|
#include "konq_bgnddlg.h"
|
||
|
#include "konq_propsview.h"
|
||
|
#include "konq_settings.h"
|
||
|
|
||
12 years ago
|
#include <tdeio/paste.h>
|
||
12 years ago
|
#include <tdeapplication.h>
|
||
12 years ago
|
#include <tdeaction.h>
|
||
15 years ago
|
#include <kdatastream.h>
|
||
|
#include <kdebug.h>
|
||
|
#include <kdirlister.h>
|
||
|
#include <kiconloader.h>
|
||
12 years ago
|
#include <tdelocale.h>
|
||
|
#include <tdemessagebox.h>
|
||
15 years ago
|
#include <konq_drag.h>
|
||
12 years ago
|
#include <tdeparts/browserextension.h>
|
||
15 years ago
|
#include <kurldrag.h>
|
||
|
#include <kuserprofile.h>
|
||
|
#include <kurifilter.h>
|
||
12 years ago
|
#include <tdeglobalsettings.h>
|
||
15 years ago
|
|
||
15 years ago
|
#include <tqapplication.h>
|
||
13 years ago
|
#include <tqclipboard.h>
|
||
15 years ago
|
#include <tqfile.h>
|
||
|
#include <tqguardedptr.h>
|
||
15 years ago
|
#include <assert.h>
|
||
15 years ago
|
#include <tqvaluevector.h>
|
||
15 years ago
|
|
||
|
class KonqDirPart::KonqDirPartPrivate
|
||
|
{
|
||
|
public:
|
||
|
KonqDirPartPrivate() : dirLister( 0 ) {}
|
||
15 years ago
|
TQStringList mimeFilters;
|
||
12 years ago
|
TDEToggleAction *aEnormousIcons;
|
||
|
TDEToggleAction *aSmallMediumIcons;
|
||
15 years ago
|
TQValueVector<int> iconSize;
|
||
15 years ago
|
|
||
|
KDirLister* dirLister;
|
||
|
bool dirSizeDirty;
|
||
|
|
||
|
void findAvailableIconSizes(void);
|
||
|
int findNearestIconSize(int size);
|
||
|
int nearestIconSizeError(int size);
|
||
|
};
|
||
|
|
||
|
void KonqDirPart::KonqDirPartPrivate::findAvailableIconSizes(void)
|
||
|
{
|
||
12 years ago
|
TDEIconTheme *root = TDEGlobal::instance()->iconLoader()->theme();
|
||
15 years ago
|
iconSize.resize(1);
|
||
|
if (root) {
|
||
12 years ago
|
TQValueList<int> avSizes = root->querySizes(TDEIcon::Desktop);
|
||
15 years ago
|
kdDebug(1203) << "The icon theme handles the sizes:" << avSizes << endl;
|
||
|
qHeapSort(avSizes);
|
||
|
int oldSize = -1;
|
||
|
if (avSizes.count() < 10) {
|
||
|
// Fixed or threshold type icons
|
||
15 years ago
|
TQValueListConstIterator<int> i;
|
||
15 years ago
|
for (i = avSizes.begin(); i != avSizes.end(); i++) {
|
||
|
// Skip duplicated values (sanity check)
|
||
|
if (*i != oldSize) iconSize.append(*i);
|
||
|
oldSize = *i;
|
||
|
}
|
||
|
} else {
|
||
|
// Scalable icons.
|
||
|
const int progression[] = {16, 22, 32, 48, 64, 96, 128, 192, 256};
|
||
|
|
||
15 years ago
|
TQValueListConstIterator<int> j = avSizes.begin();
|
||
15 years ago
|
for (uint i = 0; i < 9; i++) {
|
||
|
while (j++ != avSizes.end()) {
|
||
|
if (*j >= progression[i]) {
|
||
|
iconSize.append(*j);
|
||
|
kdDebug(1203) << "appending " << *j << " size." << endl;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
} else {
|
||
12 years ago
|
iconSize.append(TDEIcon::SizeSmall); // 16
|
||
|
iconSize.append(TDEIcon::SizeMedium); // 32
|
||
|
iconSize.append(TDEIcon::SizeLarge); // 48
|
||
|
iconSize.append(TDEIcon::SizeHuge); // 64
|
||
15 years ago
|
}
|
||
|
kdDebug(1203) << "Using " << iconSize.count() << " icon sizes." << endl;
|
||
|
}
|
||
|
|
||
|
int KonqDirPart::KonqDirPartPrivate::findNearestIconSize(int preferred)
|
||
|
{
|
||
|
int s1 = iconSize[1];
|
||
12 years ago
|
if (preferred == 0) return TDEGlobal::iconLoader()->currentSize(TDEIcon::Desktop);
|
||
15 years ago
|
if (preferred <= s1) return s1;
|
||
|
for (uint i = 2; i <= iconSize.count(); i++) {
|
||
|
if (preferred <= iconSize[i]) {
|
||
|
if (preferred - s1 < iconSize[i] - preferred) return s1;
|
||
|
else return iconSize[i];
|
||
|
} else {
|
||
|
s1 = iconSize[i];
|
||
|
}
|
||
|
}
|
||
|
return s1;
|
||
|
}
|
||
|
|
||
|
int KonqDirPart::KonqDirPartPrivate::nearestIconSizeError(int size)
|
||
|
{
|
||
|
return QABS(size - findNearestIconSize(size));
|
||
|
}
|
||
|
|
||
15 years ago
|
KonqDirPart::KonqDirPart( TQObject *parent, const char *name )
|
||
15 years ago
|
:KParts::ReadOnlyPart( parent, name ),
|
||
|
m_pProps( 0L ),
|
||
|
m_findPart( 0L )
|
||
|
{
|
||
|
d = new KonqDirPartPrivate;
|
||
|
resetCount();
|
||
|
//m_bMultipleItemsSelected = false;
|
||
|
|
||
13 years ago
|
connect( TQApplication::clipboard(), TQT_SIGNAL(dataChanged()), this, TQT_SLOT(slotClipboardDataChanged()) );
|
||
15 years ago
|
|
||
|
actionCollection()->setHighlightingEnabled( true );
|
||
|
|
||
10 years ago
|
m_paIncIconSize = new TDEAction( i18n( "Enlarge Icons" ), "zoom-in", 0, this, TQT_SLOT( slotIncIconSize() ), actionCollection(), "incIconSize" );
|
||
|
m_paDecIconSize = new TDEAction( i18n( "Shrink Icons" ), "zoom-out", 0, this, TQT_SLOT( slotDecIconSize() ), actionCollection(), "decIconSize" );
|
||
15 years ago
|
|
||
12 years ago
|
m_paDefaultIcons = new TDERadioAction( i18n( "&Default Size" ), 0, actionCollection(), "modedefault" );
|
||
|
d->aEnormousIcons = new TDERadioAction( i18n( "&Huge" ), 0,
|
||
15 years ago
|
actionCollection(), "modeenormous" );
|
||
12 years ago
|
m_paHugeIcons = new TDERadioAction( i18n( "&Very Large" ), 0, actionCollection(), "modehuge" );
|
||
|
m_paLargeIcons = new TDERadioAction( i18n( "&Large" ), 0, actionCollection(), "modelarge" );
|
||
|
m_paMediumIcons = new TDERadioAction( i18n( "&Medium" ), 0, actionCollection(), "modemedium" );
|
||
|
d->aSmallMediumIcons = new TDERadioAction( i18n( "&Small" ), 0,
|
||
15 years ago
|
actionCollection(), "modesmallmedium" );
|
||
12 years ago
|
m_paSmallIcons = new TDERadioAction( i18n( "&Tiny" ), 0, actionCollection(), "modesmall" );
|
||
15 years ago
|
|
||
|
m_paDefaultIcons->setExclusiveGroup( "ViewMode" );
|
||
|
d->aEnormousIcons->setExclusiveGroup( "ViewMode" );
|
||
|
m_paHugeIcons->setExclusiveGroup( "ViewMode" );
|
||
|
m_paLargeIcons->setExclusiveGroup( "ViewMode" );
|
||
|
m_paMediumIcons->setExclusiveGroup( "ViewMode" );
|
||
|
d->aSmallMediumIcons->setExclusiveGroup( "ViewMode" );
|
||
|
m_paSmallIcons->setExclusiveGroup( "ViewMode" );
|
||
|
|
||
15 years ago
|
connect( m_paDefaultIcons, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotIconSizeToggled( bool ) ) );
|
||
|
connect( d->aEnormousIcons, TQT_SIGNAL( toggled( bool ) ),
|
||
|
this, TQT_SLOT( slotIconSizeToggled( bool ) ) );
|
||
|
connect( m_paHugeIcons, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotIconSizeToggled( bool ) ) );
|
||
|
connect( m_paLargeIcons, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotIconSizeToggled( bool ) ) );
|
||
|
connect( m_paMediumIcons, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotIconSizeToggled( bool ) ) );
|
||
|
connect( d->aSmallMediumIcons, TQT_SIGNAL( toggled( bool ) ),
|
||
|
this, TQT_SLOT( slotIconSizeToggled( bool ) ) );
|
||
|
connect( m_paSmallIcons, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotIconSizeToggled( bool ) ) );
|
||
|
|
||
|
connect( kapp, TQT_SIGNAL(iconChanged(int)), TQT_SLOT(slotIconChanged(int)) );
|
||
15 years ago
|
#if 0
|
||
|
// Extract 6 icon sizes from the icon theme.
|
||
|
// Use 16,22,32,48,64,128 as default.
|
||
|
// Use these also if the icon theme is scalable.
|
||
|
int i;
|
||
|
d->iconSize[0] = 0; // Default value
|
||
12 years ago
|
d->iconSize[1] = TDEIcon::SizeSmall; // 16
|
||
|
d->iconSize[2] = TDEIcon::SizeSmallMedium; // 22
|
||
|
d->iconSize[3] = TDEIcon::SizeMedium; // 32
|
||
|
d->iconSize[4] = TDEIcon::SizeLarge; // 48
|
||
|
d->iconSize[5] = TDEIcon::SizeHuge; // 64
|
||
|
d->iconSize[6] = TDEIcon::SizeEnormous; // 128
|
||
15 years ago
|
d->iconSize[7] = 192;
|
||
|
d->iconSize[8] = 256;
|
||
12 years ago
|
TDEIconTheme *root = TDEGlobal::instance()->iconLoader()->theme();
|
||
15 years ago
|
if (root)
|
||
|
{
|
||
12 years ago
|
TQValueList<int> avSizes = root->querySizes(TDEIcon::Desktop);
|
||
15 years ago
|
kdDebug(1203) << "the icon theme handles the following sizes:" << avSizes << endl;
|
||
|
if (avSizes.count() < 10) {
|
||
|
// Use the icon sizes supplied by the theme.
|
||
14 years ago
|
// If avSizes contains more than 10 entries, assume a scalable
|
||
15 years ago
|
// icon theme.
|
||
15 years ago
|
TQValueList<int>::Iterator it;
|
||
15 years ago
|
for (i=1, it=avSizes.begin(); (it!=avSizes.end()) && (i<7); it++, i++)
|
||
|
{
|
||
|
d->iconSize[i] = *it;
|
||
|
kdDebug(1203) << "m_iIconSize[" << i << "] = " << *it << endl;
|
||
|
}
|
||
|
// Generate missing sizes
|
||
|
for (; i < 7; i++) {
|
||
|
d->iconSize[i] = d->iconSize[i - 1] + d->iconSize[i - 1] / 2 ;
|
||
|
kdDebug(1203) << "m_iIconSize[" << i << "] = " << d->iconSize[i] << endl;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
#else
|
||
|
d->iconSize.reserve(10);
|
||
|
d->iconSize.append(0); // Default value
|
||
|
adjustIconSizes();
|
||
|
#endif
|
||
|
|
||
|
// Remove in KDE4 ...
|
||
|
// These are here in the event subclasses access them.
|
||
12 years ago
|
m_iIconSize[1] = TDEIcon::SizeSmall;
|
||
|
m_iIconSize[2] = TDEIcon::SizeMedium;
|
||
|
m_iIconSize[3] = TDEIcon::SizeLarge;
|
||
|
m_iIconSize[4] = TDEIcon::SizeHuge;
|
||
15 years ago
|
// ... up to here
|
||
|
|
||
12 years ago
|
TDEAction *a = new TDEAction( i18n( "Configure Background..." ), "background", 0, this, TQT_SLOT( slotBackgroundSettings() ),
|
||
15 years ago
|
actionCollection(), "bgsettings" );
|
||
|
|
||
|
a->setToolTip( i18n( "Allows choosing of background settings for this view" ) );
|
||
|
}
|
||
|
|
||
|
KonqDirPart::~KonqDirPart()
|
||
|
{
|
||
|
// Close the find part with us
|
||
|
delete m_findPart;
|
||
|
delete d;
|
||
|
d = 0;
|
||
|
}
|
||
|
|
||
|
void KonqDirPart::adjustIconSizes()
|
||
|
{
|
||
|
d->findAvailableIconSizes();
|
||
|
m_paSmallIcons->setEnabled(d->findNearestIconSize(16) < 20);
|
||
|
d->aSmallMediumIcons->setEnabled(d->nearestIconSizeError(22) < 2);
|
||
|
m_paMediumIcons->setEnabled(d->nearestIconSizeError(32) < 6);
|
||
|
m_paLargeIcons->setEnabled(d->nearestIconSizeError(48) < 8);
|
||
|
m_paHugeIcons->setEnabled(d->nearestIconSizeError(64) < 12);
|
||
|
d->aEnormousIcons->setEnabled(d->findNearestIconSize(128) > 110);
|
||
|
|
||
|
if (m_pProps) {
|
||
|
int size = m_pProps->iconSize();
|
||
|
int nearSize = d->findNearestIconSize(size);
|
||
|
|
||
|
if (size != nearSize) {
|
||
|
m_pProps->setIconSize(nearSize);
|
||
|
}
|
||
|
newIconSize(nearSize);
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void KonqDirPart::setMimeFilter (const TQStringList& mime)
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString u = url().url();
|
||
15 years ago
|
|
||
|
if ( u.isEmpty () )
|
||
|
return;
|
||
|
|
||
|
if ( mime.isEmpty() )
|
||
|
d->mimeFilters.clear();
|
||
|
else
|
||
|
d->mimeFilters = mime;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQStringList KonqDirPart::mimeFilter() const
|
||
15 years ago
|
{
|
||
|
return d->mimeFilters;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQScrollView * KonqDirPart::scrollWidget()
|
||
15 years ago
|
{
|
||
15 years ago
|
return static_cast<TQScrollView *>(widget());
|
||
15 years ago
|
}
|
||
|
|
||
|
void KonqDirPart::slotBackgroundSettings()
|
||
|
{
|
||
15 years ago
|
TQColor bgndColor = m_pProps->bgColor( widget() );
|
||
12 years ago
|
TQColor defaultColor = TDEGlobalSettings::baseColor();
|
||
15 years ago
|
// dlg must be created on the heap as widget() can get deleted while dlg.exec(),
|
||
|
// trying to delete dlg as its child then (#124210) - Frank Osterfeld
|
||
15 years ago
|
TQGuardedPtr<KonqBgndDialog> dlg = new KonqBgndDialog( widget(),
|
||
15 years ago
|
m_pProps->bgPixmapFile(),
|
||
|
bgndColor,
|
||
|
defaultColor );
|
||
|
|
||
|
if ( dlg->exec() == KonqBgndDialog::Accepted )
|
||
|
{
|
||
|
if ( dlg->color().isValid() )
|
||
|
{
|
||
|
m_pProps->setBgColor( dlg->color() );
|
||
|
m_pProps->setBgPixmapFile( "" );
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
m_pProps->setBgColor( defaultColor );
|
||
|
m_pProps->setBgPixmapFile( dlg->pixmapFile() );
|
||
|
}
|
||
|
m_pProps->applyColors( scrollWidget()->viewport() );
|
||
13 years ago
|
scrollWidget()->viewport()->repaint();
|
||
15 years ago
|
}
|
||
|
|
||
|
delete dlg;
|
||
|
}
|
||
|
|
||
|
void KonqDirPart::lmbClicked( KFileItem * fileItem )
|
||
|
{
|
||
|
KURL url = fileItem->url();
|
||
|
if ( !fileItem->isReadable() )
|
||
|
{
|
||
|
// No permissions or local file that doesn't exist - need to find out which
|
||
15 years ago
|
if ( ( !fileItem->isLocalFile() ) || TQFile::exists( url.path() ) )
|
||
15 years ago
|
{
|
||
|
KMessageBox::error( widget(), i18n("<p>You do not have enough permissions to read <b>%1</b></p>").arg(url.prettyURL()) );
|
||
|
return;
|
||
|
}
|
||
|
KMessageBox::error( widget(), i18n("<p><b>%1</b> does not seem to exist anymore</p>").arg(url.prettyURL()) );
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
KParts::URLArgs args;
|
||
|
fileItem->determineMimeType();
|
||
|
if ( fileItem->isMimeTypeKnown() )
|
||
|
args.serviceType = fileItem->mimetype();
|
||
|
args.trustedSource = true;
|
||
|
|
||
|
if (KonqFMSettings::settings()->alwaysNewWin() && fileItem->isDir()) {
|
||
|
//args.frameName = "_blank"; // open new window
|
||
|
// We tried the other option, passing the path as framename so that
|
||
|
// an existing window for that dir is reused (like MSWindows does when
|
||
|
// the similar option is activated and the sidebar is hidden (!)).
|
||
|
// But this requires some work, including changing the framename
|
||
|
// when navigating, etc. Not very much requested yet, in addition.
|
||
|
KParts::WindowArgs wargs;
|
||
|
KParts::ReadOnlyPart* dummy;
|
||
|
emit m_extension->createNewWindow( url, args, wargs, dummy );
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
kdDebug() << "emit m_extension->openURLRequest( " << url.url() << "," << args.serviceType << ")" << endl;
|
||
|
emit m_extension->openURLRequest( url, args );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KonqDirPart::mmbClicked( KFileItem * fileItem )
|
||
|
{
|
||
|
if ( fileItem )
|
||
|
{
|
||
|
// Optimisation to avoid KRun to call kfmclient that then tells us
|
||
|
// to open a window :-)
|
||
|
KService::Ptr offer = KServiceTypeProfile::preferredService(fileItem->mimetype(), "Application");
|
||
|
//if (offer) kdDebug(1203) << "KonqDirPart::mmbClicked: got service " << offer->desktopEntryName() << endl;
|
||
|
if ( offer && offer->desktopEntryName().startsWith("kfmclient") )
|
||
|
{
|
||
|
KParts::URLArgs args;
|
||
|
args.serviceType = fileItem->mimetype();
|
||
|
emit m_extension->createNewWindow( fileItem->url(), args );
|
||
|
}
|
||
|
else
|
||
|
fileItem->run();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
m_extension->pasteRequest();
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void KonqDirPart::saveState( TQDataStream& stream )
|
||
15 years ago
|
{
|
||
|
stream << m_nameFilter;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KonqDirPart::restoreState( TQDataStream& stream )
|
||
15 years ago
|
{
|
||
|
stream >> m_nameFilter;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KonqDirPart::saveFindState( TQDataStream& stream )
|
||
15 years ago
|
{
|
||
|
// assert only doable in KDE4.
|
||
|
//assert( m_findPart ); // test done by caller.
|
||
|
if ( !m_findPart )
|
||
|
return;
|
||
|
|
||
|
// When we have a find part, our own URL wasn't saved (see KonqDirPartBrowserExtension)
|
||
|
// So let's do it here
|
||
|
stream << m_url;
|
||
|
|
||
|
KParts::BrowserExtension* ext = KParts::BrowserExtension::childObject( m_findPart );
|
||
|
if( !ext )
|
||
|
return;
|
||
|
|
||
|
ext->saveState( stream );
|
||
|
}
|
||
|
|
||
15 years ago
|
void KonqDirPart::restoreFindState( TQDataStream& stream )
|
||
15 years ago
|
{
|
||
|
// Restore our own URL
|
||
|
stream >> m_url;
|
||
|
|
||
|
emit findOpen( this );
|
||
|
|
||
|
KParts::BrowserExtension* ext = KParts::BrowserExtension::childObject( m_findPart );
|
||
|
slotClear();
|
||
|
|
||
|
if( !ext )
|
||
|
return;
|
||
|
|
||
|
ext->restoreState( stream );
|
||
|
}
|
||
|
|
||
|
void KonqDirPart::slotClipboardDataChanged()
|
||
|
{
|
||
|
// This is very related to KDIconView::slotClipboardDataChanged
|
||
|
|
||
|
KURL::List lst;
|
||
13 years ago
|
TQMimeSource *data = TQApplication::clipboard()->data();
|
||
10 years ago
|
if ( data->provides( "application/x-tde-cutselection" ) && data->provides( "text/uri-list" ) ) {
|
||
|
if ( KonqDrag::decodeIsCutSelection( data ) ) {
|
||
15 years ago
|
(void) KURLDrag::decode( data, lst );
|
||
10 years ago
|
}
|
||
|
}
|
||
15 years ago
|
|
||
|
disableIcons( lst );
|
||
|
|
||
|
updatePasteAction();
|
||
|
}
|
||
|
|
||
|
void KonqDirPart::updatePasteAction() // KDE4: merge into method above
|
||
|
{
|
||
12 years ago
|
TQString actionText = TDEIO::pasteActionText();
|
||
15 years ago
|
bool paste = !actionText.isEmpty();
|
||
10 years ago
|
if ( paste ) {
|
||
15 years ago
|
emit m_extension->setActionText( "paste", actionText );
|
||
10 years ago
|
}
|
||
15 years ago
|
emit m_extension->enableAction( "paste", paste );
|
||
|
}
|
||
|
|
||
10 years ago
|
void KonqDirPart::newItems(const KFileItemList &entries)
|
||
15 years ago
|
{
|
||
|
d->dirSizeDirty = true;
|
||
12 years ago
|
if ( m_findPart ) {
|
||
15 years ago
|
emitTotalCount();
|
||
12 years ago
|
}
|
||
15 years ago
|
|
||
10 years ago
|
emit itemsAdded(entries);
|
||
15 years ago
|
}
|
||
|
|
||
10 years ago
|
void KonqDirPart::deleteItem(KFileItem * fileItem)
|
||
15 years ago
|
{
|
||
|
d->dirSizeDirty = true;
|
||
10 years ago
|
emit itemRemoved(fileItem);
|
||
|
}
|
||
|
|
||
|
void KonqDirPart::refreshItems(const KFileItemList &entries)
|
||
|
{
|
||
|
emit itemsRefresh(entries);
|
||
15 years ago
|
}
|
||
|
|
||
|
void KonqDirPart::emitTotalCount()
|
||
|
{
|
||
12 years ago
|
if ( !d->dirLister || d->dirLister->url().isEmpty() ) {
|
||
15 years ago
|
return;
|
||
12 years ago
|
}
|
||
15 years ago
|
if ( d->dirSizeDirty ) {
|
||
|
m_lDirSize = 0;
|
||
|
m_lFileCount = 0;
|
||
|
m_lDirCount = 0;
|
||
|
KFileItemList entries = d->dirLister->items();
|
||
|
for (KFileItemListIterator it(entries); it.current(); ++it)
|
||
|
{
|
||
|
if ( !it.current()->isDir() )
|
||
|
{
|
||
12 years ago
|
if (!it.current()->isLink()) { // symlinks don't contribute to the size
|
||
15 years ago
|
m_lDirSize += it.current()->size();
|
||
12 years ago
|
}
|
||
15 years ago
|
m_lFileCount++;
|
||
|
}
|
||
12 years ago
|
else {
|
||
15 years ago
|
m_lDirCount++;
|
||
12 years ago
|
}
|
||
15 years ago
|
}
|
||
|
d->dirSizeDirty = false;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString summary =
|
||
12 years ago
|
TDEIO::itemsSummaryString(m_lFileCount + m_lDirCount,
|
||
15 years ago
|
m_lFileCount,
|
||
|
m_lDirCount,
|
||
|
m_lDirSize,
|
||
|
true);
|
||
|
bool bShowsResult = false;
|
||
|
if (m_findPart)
|
||
|
{
|
||
15 years ago
|
TQVariant prop = m_findPart->property( "showsResult" );
|
||
15 years ago
|
bShowsResult = prop.isValid() && prop.toBool();
|
||
|
}
|
||
|
//kdDebug(1203) << "KonqDirPart::emitTotalCount bShowsResult=" << bShowsResult << endl;
|
||
|
emit setStatusBarText( bShowsResult ? i18n("Search result: %1").arg(summary) : summary );
|
||
|
}
|
||
|
|
||
|
void KonqDirPart::emitCounts( const KFileItemList & lst )
|
||
|
{
|
||
|
if ( lst.count() == 1 )
|
||
|
emit setStatusBarText( ((KFileItemList)lst).first()->getStatusBarInfo() );
|
||
|
else
|
||
|
{
|
||
|
long long fileSizeSum = 0;
|
||
|
uint fileCount = 0;
|
||
|
uint dirCount = 0;
|
||
|
|
||
|
for ( KFileItemListIterator it( lst ); it.current(); ++it )
|
||
|
{
|
||
|
if ( it.current()->isDir() )
|
||
|
dirCount++;
|
||
|
else
|
||
|
{
|
||
|
if ( !it.current()->isLink() ) // ignore symlinks
|
||
|
fileSizeSum += it.current()->size();
|
||
|
fileCount++;
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
emit setStatusBarText( TDEIO::itemsSummaryString( fileCount + dirCount,
|
||
15 years ago
|
fileCount, dirCount,
|
||
|
fileSizeSum, true ) );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KonqDirPart::emitCounts( const KFileItemList & lst, bool selectionChanged )
|
||
|
{
|
||
12 years ago
|
if ( lst.count() == 0 ) {
|
||
15 years ago
|
emitTotalCount();
|
||
12 years ago
|
}
|
||
|
else {
|
||
15 years ago
|
emitCounts( lst );
|
||
12 years ago
|
}
|
||
15 years ago
|
|
||
|
// Yes, the caller could do that too :)
|
||
15 years ago
|
// But this bool could also be used to cache the TQString for the last
|
||
15 years ago
|
// selection, as long as selectionChanged is false.
|
||
|
// Not sure it's worth it though.
|
||
|
// MiB: no, I don't think it's worth it. Especially regarding the
|
||
|
// loss of readability of the code. Thus, this will be removed in
|
||
|
// KDE 4.0.
|
||
12 years ago
|
if ( selectionChanged ) {
|
||
15 years ago
|
emit m_extension->selectionInfo( lst );
|
||
12 years ago
|
}
|
||
15 years ago
|
}
|
||
|
|
||
|
void KonqDirPart::emitMouseOver( const KFileItem* item )
|
||
|
{
|
||
|
emit m_extension->mouseOverInfo( item );
|
||
|
}
|
||
|
|
||
|
void KonqDirPart::slotIconSizeToggled( bool toggleOn )
|
||
|
{
|
||
|
//kdDebug(1203) << "KonqDirPart::slotIconSizeToggled" << endl;
|
||
|
|
||
|
// This slot is called when an iconsize action is checked or by calling
|
||
|
// action->setChecked(false) (previously true). So we must filter out
|
||
14 years ago
|
// the 'untoggled' case to prevent odd results here (repaints/loops!)
|
||
15 years ago
|
if ( !toggleOn )
|
||
|
return;
|
||
|
|
||
|
if ( m_paDefaultIcons->isChecked() )
|
||
|
setIconSize(0);
|
||
|
else if ( d->aEnormousIcons->isChecked() )
|
||
12 years ago
|
setIconSize(d->findNearestIconSize(TDEIcon::SizeEnormous));
|
||
15 years ago
|
else if ( m_paHugeIcons->isChecked() )
|
||
12 years ago
|
setIconSize(d->findNearestIconSize(TDEIcon::SizeHuge));
|
||
15 years ago
|
else if ( m_paLargeIcons->isChecked() )
|
||
12 years ago
|
setIconSize(d->findNearestIconSize(TDEIcon::SizeLarge));
|
||
15 years ago
|
else if ( m_paMediumIcons->isChecked() )
|
||
12 years ago
|
setIconSize(d->findNearestIconSize(TDEIcon::SizeMedium));
|
||
15 years ago
|
else if ( d->aSmallMediumIcons->isChecked() )
|
||
12 years ago
|
setIconSize(d->findNearestIconSize(TDEIcon::SizeSmallMedium));
|
||
15 years ago
|
else if ( m_paSmallIcons->isChecked() )
|
||
12 years ago
|
setIconSize(d->findNearestIconSize(TDEIcon::SizeSmall));
|
||
15 years ago
|
}
|
||
|
|
||
|
void KonqDirPart::slotIncIconSize()
|
||
|
{
|
||
|
int s = m_pProps->iconSize();
|
||
12 years ago
|
s = s ? s : TDEGlobal::iconLoader()->currentSize( TDEIcon::Desktop );
|
||
15 years ago
|
uint sizeIndex = 0;
|
||
|
for ( uint idx = 1; idx < d->iconSize.count() ; ++idx )
|
||
|
if (s == d->iconSize[idx]) {
|
||
|
sizeIndex = idx;
|
||
|
break;
|
||
|
}
|
||
|
if ( sizeIndex > 0 && sizeIndex < d->iconSize.count() - 1 )
|
||
|
{
|
||
|
setIconSize( d->iconSize[sizeIndex + 1] );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KonqDirPart::slotDecIconSize()
|
||
|
{
|
||
|
int s = m_pProps->iconSize();
|
||
12 years ago
|
s = s ? s : TDEGlobal::iconLoader()->currentSize( TDEIcon::Desktop );
|
||
15 years ago
|
uint sizeIndex = 0;
|
||
|
for ( uint idx = 1; idx < d->iconSize.count() ; ++idx )
|
||
|
if (s == d->iconSize[idx]) {
|
||
|
sizeIndex = idx;
|
||
|
break;
|
||
|
}
|
||
|
if ( sizeIndex > 1 )
|
||
|
{
|
||
|
setIconSize( d->iconSize[sizeIndex - 1] );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Only updates Actions, a GUI update is done in the views by reimplementing this
|
||
|
void KonqDirPart::newIconSize( int size /*0=default, or 16,32,48....*/ )
|
||
|
{
|
||
12 years ago
|
int realSize = (size==0) ? TDEGlobal::iconLoader()->currentSize( TDEIcon::Desktop ) : size;
|
||
15 years ago
|
m_paDecIconSize->setEnabled(realSize > d->iconSize[1]);
|
||
|
m_paIncIconSize->setEnabled(realSize < d->iconSize.back());
|
||
|
|
||
|
m_paDefaultIcons->setChecked(size == 0);
|
||
12 years ago
|
d->aEnormousIcons->setChecked(size == d->findNearestIconSize(TDEIcon::SizeEnormous));
|
||
|
m_paHugeIcons->setChecked(size == d->findNearestIconSize(TDEIcon::SizeHuge));
|
||
|
m_paLargeIcons->setChecked(size == d->findNearestIconSize(TDEIcon::SizeLarge));
|
||
|
m_paMediumIcons->setChecked(size == d->findNearestIconSize(TDEIcon::SizeMedium));
|
||
|
d->aSmallMediumIcons->setChecked(size == d->findNearestIconSize(TDEIcon::SizeSmallMedium));
|
||
|
m_paSmallIcons->setChecked(size == d->findNearestIconSize(TDEIcon::SizeSmall));
|
||
15 years ago
|
}
|
||
|
|
||
|
// Stores the new icon size and updates the GUI
|
||
|
void KonqDirPart::setIconSize( int size )
|
||
|
{
|
||
|
//kdDebug(1203) << "KonqDirPart::setIconSize " << size << " -> updating props and GUI" << endl;
|
||
|
m_pProps->setIconSize( size );
|
||
|
newIconSize( size );
|
||
|
}
|
||
|
|
||
|
bool KonqDirPart::closeURL()
|
||
|
{
|
||
|
// Tell all the childern objects to clean themselves up for dinner :)
|
||
|
return doCloseURL();
|
||
|
}
|
||
|
|
||
|
bool KonqDirPart::openURL(const KURL& url)
|
||
|
{
|
||
|
if ( m_findPart )
|
||
|
{
|
||
|
kdDebug(1203) << "KonqDirPart::openURL -> emit findClosed " << this << endl;
|
||
|
delete m_findPart;
|
||
|
m_findPart = 0L;
|
||
|
emit findClosed( this );
|
||
|
}
|
||
|
|
||
|
m_url = url;
|
||
|
emit aboutToOpenURL ();
|
||
|
|
||
|
return doOpenURL(url);
|
||
|
}
|
||
|
|
||
|
void KonqDirPart::setFindPart( KParts::ReadOnlyPart * part )
|
||
|
{
|
||
|
assert(part);
|
||
|
m_findPart = part;
|
||
15 years ago
|
connect( m_findPart, TQT_SIGNAL( started() ),
|
||
|
this, TQT_SLOT( slotStarted() ) );
|
||
|
connect( m_findPart, TQT_SIGNAL( started() ),
|
||
|
this, TQT_SLOT( slotStartAnimationSearching() ) );
|
||
|
connect( m_findPart, TQT_SIGNAL( clear() ),
|
||
|
this, TQT_SLOT( slotClear() ) );
|
||
|
connect( m_findPart, TQT_SIGNAL( newItems( const KFileItemList & ) ),
|
||
|
this, TQT_SLOT( slotNewItems( const KFileItemList & ) ) );
|
||
|
connect( m_findPart, TQT_SIGNAL( finished() ), // can't name it completed, it conflicts with a KROP signal
|
||
|
this, TQT_SLOT( slotCompleted() ) );
|
||
|
connect( m_findPart, TQT_SIGNAL( finished() ),
|
||
|
this, TQT_SLOT( slotStopAnimationSearching() ) );
|
||
|
connect( m_findPart, TQT_SIGNAL( canceled() ),
|
||
|
this, TQT_SLOT( slotCanceled() ) );
|
||
|
connect( m_findPart, TQT_SIGNAL( canceled() ),
|
||
|
this, TQT_SLOT( slotStopAnimationSearching() ) );
|
||
|
|
||
|
connect( m_findPart, TQT_SIGNAL( findClosed() ),
|
||
|
this, TQT_SLOT( slotFindClosed() ) );
|
||
15 years ago
|
|
||
|
emit findOpened( this );
|
||
|
|
||
|
// set the initial URL in the find part
|
||
|
m_findPart->openURL( url() );
|
||
|
}
|
||
|
|
||
|
void KonqDirPart::slotFindClosed()
|
||
|
{
|
||
|
kdDebug(1203) << "KonqDirPart::slotFindClosed -> emit findClosed " << this << endl;
|
||
|
delete m_findPart;
|
||
|
m_findPart = 0L;
|
||
|
emit findClosed( this );
|
||
|
// reload where we were before
|
||
|
openURL( url() );
|
||
|
}
|
||
|
|
||
|
void KonqDirPart::slotIconChanged( int group )
|
||
|
{
|
||
12 years ago
|
if (group != TDEIcon::Desktop) return;
|
||
15 years ago
|
adjustIconSizes();
|
||
|
}
|
||
|
|
||
|
void KonqDirPart::slotStartAnimationSearching()
|
||
|
{
|
||
|
started(0);
|
||
|
}
|
||
|
|
||
|
void KonqDirPart::slotStopAnimationSearching()
|
||
|
{
|
||
|
completed();
|
||
|
}
|
||
|
|
||
15 years ago
|
void KonqDirPartBrowserExtension::saveState( TQDataStream &stream )
|
||
15 years ago
|
{
|
||
|
m_dirPart->saveState( stream );
|
||
|
bool hasFindPart = m_dirPart->findPart();
|
||
|
stream << hasFindPart;
|
||
|
assert( ! ( hasFindPart && !strcmp(m_dirPart->className(), "KFindPart") ) );
|
||
|
if ( !hasFindPart )
|
||
|
KParts::BrowserExtension::saveState( stream );
|
||
|
else {
|
||
|
m_dirPart->saveFindState( stream );
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void KonqDirPartBrowserExtension::restoreState( TQDataStream &stream )
|
||
15 years ago
|
{
|
||
|
m_dirPart->restoreState( stream );
|
||
|
bool hasFindPart;
|
||
|
stream >> hasFindPart;
|
||
|
assert( ! ( hasFindPart && !strcmp(m_dirPart->className(), "KFindPart") ) );
|
||
|
if ( !hasFindPart )
|
||
|
// This calls openURL, that's why we don't want to call it in case of a find part
|
||
|
KParts::BrowserExtension::restoreState( stream );
|
||
|
else {
|
||
|
m_dirPart->restoreFindState( stream );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
void KonqDirPart::resetCount()
|
||
|
{
|
||
|
m_lDirSize = 0;
|
||
|
m_lFileCount = 0;
|
||
|
m_lDirCount = 0;
|
||
|
d->dirSizeDirty = true;
|
||
|
}
|
||
|
|
||
|
void KonqDirPart::setDirLister( KDirLister* lister )
|
||
|
{
|
||
|
d->dirLister = lister;
|
||
|
}
|
||
|
|
||
|
#include "konq_dirpart.moc"
|