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.
1741 lines
53 KiB
1741 lines
53 KiB
15 years ago
|
/* This file is part of the KDE libraries
|
||
|
Copyright (C) 1999,2000 Stephan Kulow <coolo@kde.org>
|
||
|
1999,2000,2001,2002,2003 Carsten Pfeiffer <pfeiffer@kde.org>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library 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
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include <unistd.h>
|
||
|
|
||
14 years ago
|
#include <tqdir.h>
|
||
|
#include <tqapplication.h>
|
||
|
#include <tqdialog.h>
|
||
|
#include <tqlabel.h>
|
||
13 years ago
|
#include <tqlayout.h>
|
||
14 years ago
|
#include <tqpushbutton.h>
|
||
|
#include <tqpopupmenu.h>
|
||
|
#include <tqregexp.h>
|
||
|
#include <tqtimer.h>
|
||
|
#include <tqvbox.h>
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdeaction.h>
|
||
12 years ago
|
#include <tdeapplication.h>
|
||
15 years ago
|
#include <kdebug.h>
|
||
|
#include <kdialog.h>
|
||
|
#include <kdialogbase.h>
|
||
|
#include <kdirlister.h>
|
||
|
#include <kinputdialog.h>
|
||
12 years ago
|
#include <tdelocale.h>
|
||
|
#include <tdemessagebox.h>
|
||
12 years ago
|
#include <tdepopupmenu.h>
|
||
15 years ago
|
#include <kprogress.h>
|
||
|
#include <kstdaction.h>
|
||
12 years ago
|
#include <tdeio/job.h>
|
||
|
#include <tdeio/jobclasses.h>
|
||
|
#include <tdeio/netaccess.h>
|
||
|
#include <tdeio/previewjob.h>
|
||
|
#include <tdeio/renamedlg.h>
|
||
15 years ago
|
#include <kpropertiesdialog.h>
|
||
|
#include <kservicetypefactory.h>
|
||
12 years ago
|
#include <tdestdaccel.h>
|
||
15 years ago
|
#include <kde_file.h>
|
||
|
|
||
12 years ago
|
#include "config-tdefile.h"
|
||
15 years ago
|
#include "kcombiview.h"
|
||
12 years ago
|
#include "tdediroperator.h"
|
||
12 years ago
|
#include "tdefiledetailview.h"
|
||
|
#include "tdefileiconview.h"
|
||
|
#include "tdefilepreview.h"
|
||
|
#include "tdefileview.h"
|
||
|
#include "tdefileitem.h"
|
||
|
#include "tdefilemetapreview.h"
|
||
15 years ago
|
|
||
|
|
||
14 years ago
|
template class TQPtrStack<KURL>;
|
||
|
template class TQDict<KFileItem>;
|
||
15 years ago
|
|
||
|
|
||
|
class KDirOperator::KDirOperatorPrivate
|
||
|
{
|
||
|
public:
|
||
|
KDirOperatorPrivate() {
|
||
|
onlyDoubleClickSelectsFiles = false;
|
||
|
progressDelayTimer = 0L;
|
||
|
dirHighlighting = false;
|
||
|
config = 0L;
|
||
|
dropOptions = 0;
|
||
|
}
|
||
|
|
||
|
~KDirOperatorPrivate() {
|
||
|
delete progressDelayTimer;
|
||
|
}
|
||
|
|
||
|
bool dirHighlighting;
|
||
14 years ago
|
TQString lastURL; // used for highlighting a directory on cdUp
|
||
15 years ago
|
bool onlyDoubleClickSelectsFiles;
|
||
14 years ago
|
TQTimer *progressDelayTimer;
|
||
12 years ago
|
TDEActionSeparator *viewActionSeparator;
|
||
15 years ago
|
int dropOptions;
|
||
|
|
||
12 years ago
|
TDEConfig *config;
|
||
14 years ago
|
TQString configGroup;
|
||
15 years ago
|
};
|
||
|
|
||
|
KDirOperator::KDirOperator(const KURL& _url,
|
||
14 years ago
|
TQWidget *parent, const char* _name)
|
||
|
: TQWidget(parent, _name),
|
||
15 years ago
|
dir(0),
|
||
|
m_fileView(0),
|
||
|
progress(0)
|
||
|
{
|
||
|
myPreview = 0L;
|
||
|
myMode = KFile::File;
|
||
|
m_viewKind = KFile::Simple;
|
||
14 years ago
|
mySorting = static_cast<TQDir::SortSpec>(TQDir::Name | TQDir::DirsFirst);
|
||
15 years ago
|
d = new KDirOperatorPrivate;
|
||
|
|
||
|
if (_url.isEmpty()) { // no dir specified -> current dir
|
||
14 years ago
|
TQString strPath = TQDir::currentDirPath();
|
||
15 years ago
|
strPath.append('/');
|
||
|
currUrl = KURL();
|
||
13 years ago
|
currUrl.setProtocol(TQString::fromLatin1("file"));
|
||
15 years ago
|
currUrl.setPath(strPath);
|
||
|
}
|
||
|
else {
|
||
|
currUrl = _url;
|
||
|
if ( currUrl.protocol().isEmpty() )
|
||
13 years ago
|
currUrl.setProtocol(TQString::fromLatin1("file"));
|
||
15 years ago
|
|
||
|
currUrl.addPath("/"); // make sure we have a trailing slash!
|
||
|
}
|
||
|
|
||
|
setDirLister( new KDirLister( true ) );
|
||
|
|
||
14 years ago
|
connect(&myCompletion, TQT_SIGNAL(match(const TQString&)),
|
||
|
TQT_SLOT(slotCompletionMatch(const TQString&)));
|
||
15 years ago
|
|
||
|
progress = new KProgress(this, "progress");
|
||
|
progress->adjustSize();
|
||
|
progress->move(2, height() - progress->height() -2);
|
||
|
|
||
14 years ago
|
d->progressDelayTimer = new TQTimer( this, "progress delay timer" );
|
||
|
connect( d->progressDelayTimer, TQT_SIGNAL( timeout() ),
|
||
|
TQT_SLOT( slotShowProgress() ));
|
||
15 years ago
|
|
||
|
myCompleteListDirty = false;
|
||
|
|
||
|
backStack.setAutoDelete( true );
|
||
|
forwardStack.setAutoDelete( true );
|
||
|
|
||
|
// action stuff
|
||
|
setupActions();
|
||
|
setupMenu();
|
||
|
|
||
14 years ago
|
setFocusPolicy(TQ_WheelFocus);
|
||
15 years ago
|
}
|
||
|
|
||
|
KDirOperator::~KDirOperator()
|
||
|
{
|
||
|
resetCursor();
|
||
|
if ( m_fileView )
|
||
|
{
|
||
|
if ( d->config )
|
||
|
m_fileView->writeConfig( d->config, d->configGroup );
|
||
|
|
||
|
delete m_fileView;
|
||
|
m_fileView = 0L;
|
||
|
}
|
||
|
|
||
|
delete myPreview;
|
||
|
delete dir;
|
||
|
delete d;
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void KDirOperator::setSorting( TQDir::SortSpec spec )
|
||
15 years ago
|
{
|
||
|
if ( m_fileView )
|
||
|
m_fileView->setSorting( spec );
|
||
|
mySorting = spec;
|
||
|
updateSortActions();
|
||
|
}
|
||
|
|
||
|
void KDirOperator::resetCursor()
|
||
|
{
|
||
14 years ago
|
TQApplication::restoreOverrideCursor();
|
||
15 years ago
|
progress->hide();
|
||
|
}
|
||
|
|
||
|
void KDirOperator::insertViewDependentActions()
|
||
|
{
|
||
|
// If we have a new view actionCollection(), insert its actions
|
||
|
// into viewActionMenu.
|
||
|
|
||
|
if( !m_fileView )
|
||
|
return;
|
||
|
|
||
|
if ( (viewActionMenu->popupMenu()->count() == 0) || // Not yet initialized or...
|
||
|
(viewActionCollection != m_fileView->actionCollection()) ) // ...changed since.
|
||
|
{
|
||
|
if (viewActionCollection)
|
||
|
{
|
||
12 years ago
|
disconnect( viewActionCollection, TQT_SIGNAL( inserted( TDEAction * )),
|
||
|
this, TQT_SLOT( slotViewActionAdded( TDEAction * )));
|
||
|
disconnect( viewActionCollection, TQT_SIGNAL( removed( TDEAction * )),
|
||
|
this, TQT_SLOT( slotViewActionRemoved( TDEAction * )));
|
||
15 years ago
|
}
|
||
|
|
||
|
viewActionMenu->popupMenu()->clear();
|
||
|
// viewActionMenu->insert( shortAction );
|
||
|
// viewActionMenu->insert( detailedAction );
|
||
|
// viewActionMenu->insert( actionSeparator );
|
||
|
viewActionMenu->insert( myActionCollection->action( "short view" ) );
|
||
|
viewActionMenu->insert( myActionCollection->action( "detailed view" ) );
|
||
|
viewActionMenu->insert( actionSeparator );
|
||
|
viewActionMenu->insert( showHiddenAction );
|
||
|
// viewActionMenu->insert( myActionCollection->action( "single" ));
|
||
|
viewActionMenu->insert( separateDirsAction );
|
||
|
// Warning: adjust slotViewActionAdded() and slotViewActionRemoved()
|
||
|
// when you add/remove actions here!
|
||
|
|
||
|
viewActionCollection = m_fileView->actionCollection();
|
||
|
if (!viewActionCollection)
|
||
|
return;
|
||
|
|
||
|
if ( !viewActionCollection->isEmpty() )
|
||
|
{
|
||
|
viewActionMenu->insert( d->viewActionSeparator );
|
||
|
|
||
|
// first insert the normal actions, then the grouped ones
|
||
14 years ago
|
TQStringList groups = viewActionCollection->groups();
|
||
|
groups.prepend( TQString::null ); // actions without group
|
||
|
TQStringList::ConstIterator git = groups.begin();
|
||
12 years ago
|
TDEActionPtrList list;
|
||
|
TDEAction *sep = actionCollection()->action("separator");
|
||
15 years ago
|
for ( ; git != groups.end(); ++git )
|
||
|
{
|
||
|
if ( git != groups.begin() )
|
||
|
viewActionMenu->insert( sep );
|
||
|
|
||
|
list = viewActionCollection->actions( *git );
|
||
12 years ago
|
TDEActionPtrList::ConstIterator it = list.begin();
|
||
15 years ago
|
for ( ; it != list.end(); ++it )
|
||
|
viewActionMenu->insert( *it );
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
connect( viewActionCollection, TQT_SIGNAL( inserted( TDEAction * )),
|
||
|
TQT_SLOT( slotViewActionAdded( TDEAction * )));
|
||
|
connect( viewActionCollection, TQT_SIGNAL( removed( TDEAction * )),
|
||
|
TQT_SLOT( slotViewActionRemoved( TDEAction * )));
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
void KDirOperator::activatedMenu( const KFileItem *, const TQPoint& pos )
|
||
15 years ago
|
{
|
||
|
setupMenu();
|
||
|
updateSelectionDependentActions();
|
||
|
|
||
|
actionMenu->popup( pos );
|
||
|
}
|
||
|
|
||
|
void KDirOperator::updateSelectionDependentActions()
|
||
|
{
|
||
|
bool hasSelection = m_fileView && m_fileView->selectedItems() &&
|
||
|
!m_fileView->selectedItems()->isEmpty();
|
||
|
myActionCollection->action( "trash" )->setEnabled( hasSelection );
|
||
|
myActionCollection->action( "delete" )->setEnabled( hasSelection );
|
||
|
myActionCollection->action( "properties" )->setEnabled( hasSelection );
|
||
|
}
|
||
|
|
||
14 years ago
|
void KDirOperator::setPreviewWidget(const TQWidget *w)
|
||
15 years ago
|
{
|
||
|
if(w != 0L)
|
||
|
m_viewKind = (m_viewKind | KFile::PreviewContents);
|
||
|
else
|
||
|
m_viewKind = (m_viewKind & ~KFile::PreviewContents);
|
||
|
|
||
|
delete myPreview;
|
||
|
myPreview = w;
|
||
|
|
||
12 years ago
|
TDEToggleAction *preview = static_cast<TDEToggleAction*>(myActionCollection->action("preview"));
|
||
15 years ago
|
preview->setEnabled( w != 0L );
|
||
|
preview->setChecked( w != 0L );
|
||
|
setView( static_cast<KFile::FileView>(m_viewKind) );
|
||
|
}
|
||
|
|
||
|
int KDirOperator::numDirs() const
|
||
|
{
|
||
|
return m_fileView ? m_fileView->numDirs() : 0;
|
||
|
}
|
||
|
|
||
|
int KDirOperator::numFiles() const
|
||
|
{
|
||
|
return m_fileView ? m_fileView->numFiles() : 0;
|
||
|
}
|
||
|
|
||
|
void KDirOperator::slotDetailedView()
|
||
|
{
|
||
|
KFile::FileView view = static_cast<KFile::FileView>( (m_viewKind & ~KFile::Simple) | KFile::Detail );
|
||
|
setView( view );
|
||
|
}
|
||
|
|
||
|
void KDirOperator::slotSimpleView()
|
||
|
{
|
||
|
KFile::FileView view = static_cast<KFile::FileView>( (m_viewKind & ~KFile::Detail) | KFile::Simple );
|
||
|
setView( view );
|
||
|
}
|
||
|
|
||
|
void KDirOperator::slotToggleHidden( bool show )
|
||
|
{
|
||
|
dir->setShowingDotFiles( show );
|
||
|
updateDir();
|
||
|
if ( m_fileView )
|
||
|
m_fileView->listingCompleted();
|
||
|
}
|
||
|
|
||
|
void KDirOperator::slotSeparateDirs()
|
||
|
{
|
||
|
if (separateDirsAction->isChecked())
|
||
|
{
|
||
|
KFile::FileView view = static_cast<KFile::FileView>( m_viewKind | KFile::SeparateDirs );
|
||
|
setView( view );
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
KFile::FileView view = static_cast<KFile::FileView>( m_viewKind & ~KFile::SeparateDirs );
|
||
|
setView( view );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KDirOperator::slotDefaultPreview()
|
||
|
{
|
||
|
m_viewKind = m_viewKind | KFile::PreviewContents;
|
||
|
if ( !myPreview ) {
|
||
|
myPreview = new KFileMetaPreview( this );
|
||
12 years ago
|
(static_cast<TDEToggleAction*>( myActionCollection->action("preview") ))->setChecked(true);
|
||
15 years ago
|
}
|
||
|
|
||
|
setView( static_cast<KFile::FileView>(m_viewKind) );
|
||
|
}
|
||
|
|
||
|
void KDirOperator::slotSortByName()
|
||
|
{
|
||
14 years ago
|
int sorting = (m_fileView->sorting()) & ~TQDir::SortByMask;
|
||
|
m_fileView->setSorting( static_cast<TQDir::SortSpec>( sorting | TQDir::Name ));
|
||
15 years ago
|
mySorting = m_fileView->sorting();
|
||
|
caseInsensitiveAction->setEnabled( true );
|
||
|
}
|
||
|
|
||
|
void KDirOperator::slotSortBySize()
|
||
|
{
|
||
14 years ago
|
int sorting = (m_fileView->sorting()) & ~TQDir::SortByMask;
|
||
|
m_fileView->setSorting( static_cast<TQDir::SortSpec>( sorting | TQDir::Size ));
|
||
15 years ago
|
mySorting = m_fileView->sorting();
|
||
|
caseInsensitiveAction->setEnabled( false );
|
||
|
}
|
||
|
|
||
|
void KDirOperator::slotSortByDate()
|
||
|
{
|
||
14 years ago
|
int sorting = (m_fileView->sorting()) & ~TQDir::SortByMask;
|
||
|
m_fileView->setSorting( static_cast<TQDir::SortSpec>( sorting | TQDir::Time ));
|
||
15 years ago
|
mySorting = m_fileView->sorting();
|
||
|
caseInsensitiveAction->setEnabled( false );
|
||
|
}
|
||
|
|
||
|
void KDirOperator::slotSortReversed()
|
||
|
{
|
||
|
if ( m_fileView )
|
||
|
m_fileView->sortReversed();
|
||
|
}
|
||
|
|
||
|
void KDirOperator::slotToggleDirsFirst()
|
||
|
{
|
||
14 years ago
|
TQDir::SortSpec sorting = m_fileView->sorting();
|
||
15 years ago
|
if ( !KFile::isSortDirsFirst( sorting ) )
|
||
14 years ago
|
m_fileView->setSorting( static_cast<TQDir::SortSpec>( sorting | TQDir::DirsFirst ));
|
||
15 years ago
|
else
|
||
14 years ago
|
m_fileView->setSorting( static_cast<TQDir::SortSpec>( sorting & ~TQDir::DirsFirst));
|
||
15 years ago
|
mySorting = m_fileView->sorting();
|
||
|
}
|
||
|
|
||
|
void KDirOperator::slotToggleIgnoreCase()
|
||
|
{
|
||
14 years ago
|
TQDir::SortSpec sorting = m_fileView->sorting();
|
||
15 years ago
|
if ( !KFile::isSortCaseInsensitive( sorting ) )
|
||
14 years ago
|
m_fileView->setSorting( static_cast<TQDir::SortSpec>( sorting | TQDir::IgnoreCase ));
|
||
15 years ago
|
else
|
||
14 years ago
|
m_fileView->setSorting( static_cast<TQDir::SortSpec>( sorting & ~TQDir::IgnoreCase));
|
||
15 years ago
|
mySorting = m_fileView->sorting();
|
||
|
}
|
||
|
|
||
|
void KDirOperator::mkdir()
|
||
|
{
|
||
|
bool ok;
|
||
14 years ago
|
TQString where = url().pathOrURL();
|
||
|
TQString name = i18n( "New Folder" );
|
||
|
if ( url().isLocalFile() && TQFileInfo( url().path(+1) + name ).exists() )
|
||
12 years ago
|
name = TDEIO::RenameDlg::suggestName( url(), name );
|
||
15 years ago
|
|
||
14 years ago
|
TQString dir = KInputDialog::getText( i18n( "New Folder" ),
|
||
15 years ago
|
i18n( "Create new folder in:\n%1" ).arg( where ),
|
||
|
name, &ok, this);
|
||
|
if (ok)
|
||
12 years ago
|
mkdir( TDEIO::encodeFileName( dir ), true );
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
bool KDirOperator::mkdir( const TQString& directory, bool enterDirectory )
|
||
15 years ago
|
{
|
||
|
// Creates "directory", relative to the current directory (currUrl).
|
||
|
// The given path may contain any number directories, existant or not.
|
||
|
// They will all be created, if possible.
|
||
|
|
||
|
bool writeOk = false;
|
||
|
bool exists = false;
|
||
|
KURL url( currUrl );
|
||
|
|
||
14 years ago
|
TQStringList dirs = TQStringList::split( TQDir::separator(), directory );
|
||
|
TQStringList::ConstIterator it = dirs.begin();
|
||
15 years ago
|
|
||
|
for ( ; it != dirs.end(); ++it )
|
||
|
{
|
||
|
url.addPath( *it );
|
||
12 years ago
|
exists = TDEIO::NetAccess::exists( url, false, 0 );
|
||
|
writeOk = !exists && TDEIO::NetAccess::mkdir( url, topLevelWidget() );
|
||
15 years ago
|
}
|
||
|
|
||
|
if ( exists ) // url was already existant
|
||
|
{
|
||
|
KMessageBox::sorry(viewWidget(), i18n("A file or folder named %1 already exists.").arg(url.pathOrURL()));
|
||
|
enterDirectory = false;
|
||
|
}
|
||
|
else if ( !writeOk ) {
|
||
|
KMessageBox::sorry(viewWidget(), i18n("You do not have permission to "
|
||
|
"create that folder." ));
|
||
|
}
|
||
|
else if ( enterDirectory ) {
|
||
|
setURL( url, true );
|
||
|
}
|
||
|
|
||
|
return writeOk;
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEIO::DeleteJob * KDirOperator::del( const KFileItemList& items,
|
||
15 years ago
|
bool ask, bool showProgress )
|
||
|
{
|
||
|
return del( items, this, ask, showProgress );
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEIO::DeleteJob * KDirOperator::del( const KFileItemList& items,
|
||
14 years ago
|
TQWidget *parent,
|
||
15 years ago
|
bool ask, bool showProgress )
|
||
|
{
|
||
|
if ( items.isEmpty() ) {
|
||
|
KMessageBox::information( parent,
|
||
|
i18n("You did not select a file to delete."),
|
||
|
i18n("Nothing to Delete") );
|
||
|
return 0L;
|
||
|
}
|
||
|
|
||
|
KURL::List urls;
|
||
14 years ago
|
TQStringList files;
|
||
15 years ago
|
KFileItemListIterator it( items );
|
||
|
|
||
|
for ( ; it.current(); ++it ) {
|
||
|
KURL url = (*it)->url();
|
||
|
urls.append( url );
|
||
|
if ( url.isLocalFile() )
|
||
|
files.append( url.path() );
|
||
|
else
|
||
|
files.append( url.prettyURL() );
|
||
|
}
|
||
|
|
||
|
bool doIt = !ask;
|
||
|
if ( ask ) {
|
||
|
int ret;
|
||
|
if ( items.count() == 1 ) {
|
||
|
ret = KMessageBox::warningContinueCancel( parent,
|
||
|
i18n( "<qt>Do you really want to delete\n <b>'%1'</b>?</qt>" )
|
||
|
.arg( files.first() ),
|
||
|
i18n("Delete File"),
|
||
|
KStdGuiItem::del(), "AskForDelete" );
|
||
|
}
|
||
|
else
|
||
|
ret = KMessageBox::warningContinueCancelList( parent,
|
||
|
i18n("Do you really want to delete this item?", "Do you really want to delete these %n items?", items.count() ),
|
||
|
files,
|
||
|
i18n("Delete Files"),
|
||
|
KStdGuiItem::del(), "AskForDelete" );
|
||
|
doIt = (ret == KMessageBox::Continue);
|
||
|
}
|
||
|
|
||
|
if ( doIt ) {
|
||
12 years ago
|
TDEIO::DeleteJob *job = TDEIO::del( urls, false, showProgress );
|
||
13 years ago
|
job->setWindow (topLevelWidget());
|
||
15 years ago
|
job->setAutoErrorHandlingEnabled( true, parent );
|
||
|
return job;
|
||
|
}
|
||
|
|
||
|
return 0L;
|
||
|
}
|
||
|
|
||
|
void KDirOperator::deleteSelected()
|
||
|
{
|
||
|
if ( !m_fileView )
|
||
|
return;
|
||
|
|
||
|
const KFileItemList *list = m_fileView->selectedItems();
|
||
|
if ( list )
|
||
|
del( *list );
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEIO::CopyJob * KDirOperator::trash( const KFileItemList& items,
|
||
14 years ago
|
TQWidget *parent,
|
||
15 years ago
|
bool ask, bool showProgress )
|
||
|
{
|
||
|
if ( items.isEmpty() ) {
|
||
|
KMessageBox::information( parent,
|
||
|
i18n("You did not select a file to trash."),
|
||
|
i18n("Nothing to Trash") );
|
||
|
return 0L;
|
||
|
}
|
||
|
|
||
|
KURL::List urls;
|
||
14 years ago
|
TQStringList files;
|
||
15 years ago
|
KFileItemListIterator it( items );
|
||
|
|
||
|
for ( ; it.current(); ++it ) {
|
||
|
KURL url = (*it)->url();
|
||
|
urls.append( url );
|
||
|
if ( url.isLocalFile() )
|
||
|
files.append( url.path() );
|
||
|
else
|
||
|
files.append( url.prettyURL() );
|
||
|
}
|
||
|
|
||
|
bool doIt = !ask;
|
||
|
if ( ask ) {
|
||
|
int ret;
|
||
|
if ( items.count() == 1 ) {
|
||
|
ret = KMessageBox::warningContinueCancel( parent,
|
||
|
i18n( "<qt>Do you really want to trash\n <b>'%1'</b>?</qt>" )
|
||
|
.arg( files.first() ),
|
||
|
i18n("Trash File"),
|
||
|
KGuiItem(i18n("to trash", "&Trash"),"edittrash"), "AskForTrash" );
|
||
|
}
|
||
|
else
|
||
|
ret = KMessageBox::warningContinueCancelList( parent,
|
||
|
i18n("translators: not called for n == 1", "Do you really want to trash these %n items?", items.count() ),
|
||
|
files,
|
||
|
i18n("Trash Files"),
|
||
|
KGuiItem(i18n("to trash", "&Trash"),"edittrash"), "AskForTrash" );
|
||
|
doIt = (ret == KMessageBox::Continue);
|
||
|
}
|
||
|
|
||
|
if ( doIt ) {
|
||
12 years ago
|
TDEIO::CopyJob *job = TDEIO::trash( urls, showProgress );
|
||
13 years ago
|
job->setWindow (topLevelWidget());
|
||
15 years ago
|
job->setAutoErrorHandlingEnabled( true, parent );
|
||
|
return job;
|
||
|
}
|
||
|
|
||
|
return 0L;
|
||
|
}
|
||
|
|
||
12 years ago
|
void KDirOperator::trashSelected(TDEAction::ActivationReason reason, TQt::ButtonState state)
|
||
15 years ago
|
{
|
||
|
if ( !m_fileView )
|
||
|
return;
|
||
|
|
||
12 years ago
|
if ( reason == TDEAction::PopupMenuActivation && ( state & ShiftButton ) ) {
|
||
15 years ago
|
deleteSelected();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
const KFileItemList *list = m_fileView->selectedItems();
|
||
|
if ( list )
|
||
|
trash( *list, this );
|
||
|
}
|
||
|
|
||
|
void KDirOperator::close()
|
||
|
{
|
||
|
resetCursor();
|
||
|
pendingMimeTypes.clear();
|
||
|
myCompletion.clear();
|
||
|
myDirCompletion.clear();
|
||
|
myCompleteListDirty = true;
|
||
|
dir->stop();
|
||
|
}
|
||
|
|
||
14 years ago
|
void KDirOperator::checkPath(const TQString &, bool /*takeFiles*/) // SLOT
|
||
15 years ago
|
{
|
||
|
#if 0
|
||
|
// copy the argument in a temporary string
|
||
14 years ago
|
TQString text = _txt;
|
||
15 years ago
|
// it's unlikely to happen, that at the beginning are spaces, but
|
||
|
// for the end, it happens quite often, I guess.
|
||
|
text = text.stripWhiteSpace();
|
||
|
// if the argument is no URL (the check is quite fragil) and it's
|
||
|
// no absolute path, we add the current directory to get a correct url
|
||
13 years ago
|
if (text.find(':') < 0 && text[0] != '/')
|
||
15 years ago
|
text.insert(0, currUrl);
|
||
|
|
||
|
// in case we have a selection defined and someone patched the file-
|
||
|
// name, we check, if the end of the new name is changed.
|
||
|
if (!selection.isNull()) {
|
||
14 years ago
|
int position = text.findRev('/');
|
||
15 years ago
|
ASSERT(position >= 0); // we already inserted the current dir in case
|
||
14 years ago
|
TQString filename = text.mid(position + 1, text.length());
|
||
15 years ago
|
if (filename != selection)
|
||
14 years ago
|
selection = TQString::null;
|
||
15 years ago
|
}
|
||
|
|
||
|
KURL u(text); // I have to take care of entered URLs
|
||
|
bool filenameEntered = false;
|
||
|
|
||
|
if (u.isLocalFile()) {
|
||
|
// the empty path is kind of a hack
|
||
|
KFileItem i("", u.path());
|
||
|
if (i.isDir())
|
||
|
setURL(text, true);
|
||
|
else {
|
||
|
if (takeFiles)
|
||
|
if (acceptOnlyExisting && !i.isFile())
|
||
|
warning("you entered an invalid URL");
|
||
|
else
|
||
|
filenameEntered = true;
|
||
|
}
|
||
|
} else
|
||
|
setURL(text, true);
|
||
|
|
||
|
if (filenameEntered) {
|
||
|
filename_ = u.url();
|
||
|
emit fileSelected(filename_);
|
||
|
|
||
14 years ago
|
TQApplication::restoreOverrideCursor();
|
||
15 years ago
|
|
||
|
accept();
|
||
|
}
|
||
|
#endif
|
||
12 years ago
|
kdDebug(tdefile_area) << "TODO KDirOperator::checkPath()" << endl;
|
||
15 years ago
|
}
|
||
|
|
||
|
void KDirOperator::setURL(const KURL& _newurl, bool clearforward)
|
||
|
{
|
||
|
KURL newurl;
|
||
|
|
||
|
if ( !_newurl.isValid() )
|
||
14 years ago
|
newurl.setPath( TQDir::homeDirPath() );
|
||
15 years ago
|
else
|
||
|
newurl = _newurl;
|
||
|
|
||
14 years ago
|
TQString pathstr = newurl.path(+1);
|
||
15 years ago
|
newurl.setPath(pathstr);
|
||
|
|
||
|
// already set
|
||
|
if ( newurl.equals( currUrl, true ) )
|
||
|
return;
|
||
|
|
||
|
if ( !isReadable( newurl ) ) {
|
||
|
// maybe newurl is a file? check its parent directory
|
||
13 years ago
|
newurl.cd(TQString::fromLatin1(".."));
|
||
15 years ago
|
if ( !isReadable( newurl ) ) {
|
||
|
resetCursor();
|
||
|
KMessageBox::error(viewWidget(),
|
||
|
i18n("The specified folder does not exist "
|
||
|
"or was not readable."));
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (clearforward) {
|
||
|
// autodelete should remove this one
|
||
|
backStack.push(new KURL(currUrl));
|
||
|
forwardStack.clear();
|
||
|
}
|
||
|
|
||
|
d->lastURL = currUrl.url(-1);
|
||
|
currUrl = newurl;
|
||
|
|
||
|
pathChanged();
|
||
|
emit urlEntered(newurl);
|
||
|
|
||
|
// enable/disable actions
|
||
|
forwardAction->setEnabled( !forwardStack.isEmpty() );
|
||
|
backAction->setEnabled( !backStack.isEmpty() );
|
||
|
upAction->setEnabled( !isRoot() );
|
||
|
|
||
|
openURL( newurl );
|
||
|
}
|
||
|
|
||
|
void KDirOperator::updateDir()
|
||
|
{
|
||
|
dir->emitChanges();
|
||
|
if ( m_fileView )
|
||
|
m_fileView->listingCompleted();
|
||
|
}
|
||
|
|
||
|
void KDirOperator::rereadDir()
|
||
|
{
|
||
|
pathChanged();
|
||
|
openURL( currUrl, false, true );
|
||
|
}
|
||
|
|
||
|
|
||
|
bool KDirOperator::openURL( const KURL& url, bool keep, bool reload )
|
||
|
{
|
||
|
bool result = dir->openURL( url, keep, reload );
|
||
|
if ( !result ) // in that case, neither completed() nor canceled() will be emitted by KDL
|
||
|
slotCanceled();
|
||
|
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
// Protected
|
||
|
void KDirOperator::pathChanged()
|
||
|
{
|
||
|
if (!m_fileView)
|
||
|
return;
|
||
|
|
||
|
pendingMimeTypes.clear();
|
||
|
m_fileView->clear();
|
||
|
myCompletion.clear();
|
||
|
myDirCompletion.clear();
|
||
|
|
||
|
// it may be, that we weren't ready at this time
|
||
14 years ago
|
TQApplication::restoreOverrideCursor();
|
||
15 years ago
|
|
||
12 years ago
|
// when TDEIO::Job emits finished, the slot will restore the cursor
|
||
14 years ago
|
TQApplication::setOverrideCursor( tqwaitCursor );
|
||
15 years ago
|
|
||
|
if ( !isReadable( currUrl )) {
|
||
|
KMessageBox::error(viewWidget(),
|
||
|
i18n("The specified folder does not exist "
|
||
|
"or was not readable."));
|
||
|
if (backStack.isEmpty())
|
||
|
home();
|
||
|
else
|
||
|
back();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KDirOperator::slotRedirected( const KURL& newURL )
|
||
|
{
|
||
|
currUrl = newURL;
|
||
|
pendingMimeTypes.clear();
|
||
|
myCompletion.clear();
|
||
|
myDirCompletion.clear();
|
||
|
myCompleteListDirty = true;
|
||
|
emit urlEntered( newURL );
|
||
|
}
|
||
|
|
||
|
// Code pinched from kfm then hacked
|
||
|
void KDirOperator::back()
|
||
|
{
|
||
|
if ( backStack.isEmpty() )
|
||
|
return;
|
||
|
|
||
|
forwardStack.push( new KURL(currUrl) );
|
||
|
|
||
|
KURL *s = backStack.pop();
|
||
|
|
||
|
setURL(*s, false);
|
||
|
delete s;
|
||
|
}
|
||
|
|
||
|
// Code pinched from kfm then hacked
|
||
|
void KDirOperator::forward()
|
||
|
{
|
||
|
if ( forwardStack.isEmpty() )
|
||
|
return;
|
||
|
|
||
|
backStack.push(new KURL(currUrl));
|
||
|
|
||
|
KURL *s = forwardStack.pop();
|
||
|
setURL(*s, false);
|
||
|
delete s;
|
||
|
}
|
||
|
|
||
|
KURL KDirOperator::url() const
|
||
|
{
|
||
|
return currUrl;
|
||
|
}
|
||
|
|
||
|
void KDirOperator::cdUp()
|
||
|
{
|
||
|
KURL tmp(currUrl);
|
||
13 years ago
|
tmp.cd(TQString::fromLatin1(".."));
|
||
15 years ago
|
setURL(tmp, true);
|
||
|
}
|
||
|
|
||
|
void KDirOperator::home()
|
||
|
{
|
||
|
KURL u;
|
||
14 years ago
|
u.setPath( TQDir::homeDirPath() );
|
||
15 years ago
|
setURL(u, true);
|
||
|
}
|
||
|
|
||
|
void KDirOperator::clearFilter()
|
||
|
{
|
||
14 years ago
|
dir->setNameFilter( TQString::null );
|
||
15 years ago
|
dir->clearMimeFilter();
|
||
|
checkPreviewSupport();
|
||
|
}
|
||
|
|
||
14 years ago
|
void KDirOperator::setNameFilter(const TQString& filter)
|
||
15 years ago
|
{
|
||
|
dir->setNameFilter(filter);
|
||
|
checkPreviewSupport();
|
||
|
}
|
||
|
|
||
14 years ago
|
void KDirOperator::setMimeFilter( const TQStringList& mimetypes )
|
||
15 years ago
|
{
|
||
|
dir->setMimeFilter( mimetypes );
|
||
|
checkPreviewSupport();
|
||
|
}
|
||
|
|
||
|
bool KDirOperator::checkPreviewSupport()
|
||
|
{
|
||
12 years ago
|
TDEToggleAction *previewAction = static_cast<TDEToggleAction*>( myActionCollection->action( "preview" ));
|
||
15 years ago
|
|
||
|
bool hasPreviewSupport = false;
|
||
12 years ago
|
TDEConfig *kc = TDEGlobal::config();
|
||
|
TDEConfigGroupSaver cs( kc, ConfigGroup );
|
||
15 years ago
|
if ( kc->readBoolEntry( "Show Default Preview", true ) )
|
||
|
hasPreviewSupport = checkPreviewInternal();
|
||
|
|
||
|
previewAction->setEnabled( hasPreviewSupport );
|
||
|
return hasPreviewSupport;
|
||
|
}
|
||
|
|
||
|
bool KDirOperator::checkPreviewInternal() const
|
||
|
{
|
||
12 years ago
|
TQStringList supported = TDEIO::PreviewJob::supportedMimeTypes();
|
||
15 years ago
|
// no preview support for directories?
|
||
13 years ago
|
if ( dirOnlyMode() && supported.findIndex( "inode/directory" ) == -1 )
|
||
15 years ago
|
return false;
|
||
|
|
||
14 years ago
|
TQStringList mimeTypes = dir->mimeFilters();
|
||
|
TQStringList nameFilter = TQStringList::split( " ", dir->nameFilter() );
|
||
15 years ago
|
|
||
|
if ( mimeTypes.isEmpty() && nameFilter.isEmpty() && !supported.isEmpty() )
|
||
|
return true;
|
||
|
else {
|
||
14 years ago
|
TQRegExp r;
|
||
15 years ago
|
r.setWildcard( true ); // the "mimetype" can be "image/*"
|
||
|
|
||
|
if ( !mimeTypes.isEmpty() ) {
|
||
14 years ago
|
TQStringList::Iterator it = supported.begin();
|
||
15 years ago
|
|
||
|
for ( ; it != supported.end(); ++it ) {
|
||
|
r.setPattern( *it );
|
||
|
|
||
14 years ago
|
TQStringList result = mimeTypes.grep( r );
|
||
15 years ago
|
if ( !result.isEmpty() ) { // matches! -> we want previews
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if ( !nameFilter.isEmpty() ) {
|
||
14 years ago
|
// find the mimetypes of all the filter-patterns and
|
||
15 years ago
|
KServiceTypeFactory *fac = KServiceTypeFactory::self();
|
||
14 years ago
|
TQStringList::Iterator it1 = nameFilter.begin();
|
||
15 years ago
|
for ( ; it1 != nameFilter.end(); ++it1 ) {
|
||
|
if ( (*it1) == "*" ) {
|
||
|
return true;
|
||
|
}
|
||
|
|
||
14 years ago
|
KMimeType *mt = fac->findFromPattern( *it1 );
|
||
15 years ago
|
if ( !mt )
|
||
|
continue;
|
||
14 years ago
|
TQString mime = mt->name();
|
||
15 years ago
|
delete mt;
|
||
|
|
||
|
// the "mimetypes" we get from the PreviewJob can be "image/*"
|
||
|
// so we need to check in wildcard mode
|
||
14 years ago
|
TQStringList::Iterator it2 = supported.begin();
|
||
15 years ago
|
for ( ; it2 != supported.end(); ++it2 ) {
|
||
|
r.setPattern( *it2 );
|
||
|
if ( r.search( mime ) != -1 ) {
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
14 years ago
|
KFileView* KDirOperator::createView( TQWidget* parent, KFile::FileView view )
|
||
15 years ago
|
{
|
||
|
KFileView* new_view = 0L;
|
||
|
bool separateDirs = KFile::isSeparateDirs( view );
|
||
|
bool preview = ( KFile::isPreviewInfo(view) || KFile::isPreviewContents( view ) );
|
||
|
|
||
|
if ( separateDirs || preview ) {
|
||
|
KCombiView *combi = 0L;
|
||
|
if (separateDirs)
|
||
|
{
|
||
|
combi = new KCombiView( parent, "combi view" );
|
||
|
combi->setOnlyDoubleClickSelectsFiles(d->onlyDoubleClickSelectsFiles);
|
||
|
}
|
||
|
|
||
|
KFileView* v = 0L;
|
||
|
if ( KFile::isSimpleView( view ) )
|
||
|
v = createView( combi, KFile::Simple );
|
||
|
else
|
||
|
v = createView( combi, KFile::Detail );
|
||
|
|
||
|
v->setOnlyDoubleClickSelectsFiles(d->onlyDoubleClickSelectsFiles);
|
||
|
|
||
|
if (combi)
|
||
|
combi->setRight( v );
|
||
|
|
||
|
if (preview)
|
||
|
{
|
||
|
KFilePreview* pView = new KFilePreview( combi ? combi : v, parent, "preview" );
|
||
|
pView->setOnlyDoubleClickSelectsFiles(d->onlyDoubleClickSelectsFiles);
|
||
|
new_view = pView;
|
||
|
}
|
||
|
else
|
||
|
new_view = combi;
|
||
|
}
|
||
|
else if ( KFile::isDetailView( view ) && !preview ) {
|
||
|
new_view = new KFileDetailView( parent, "detail view");
|
||
|
new_view->setViewName( i18n("Detailed View") );
|
||
|
}
|
||
|
else /* if ( KFile::isSimpleView( view ) && !preview ) */ {
|
||
|
KFileIconView *iconView = new KFileIconView( parent, "simple view");
|
||
|
new_view = iconView;
|
||
|
new_view->setViewName( i18n("Short View") );
|
||
|
}
|
||
|
|
||
|
new_view->widget()->setAcceptDrops(acceptDrops());
|
||
|
return new_view;
|
||
|
}
|
||
|
|
||
|
void KDirOperator::setAcceptDrops(bool b)
|
||
|
{
|
||
|
if (m_fileView)
|
||
|
m_fileView->widget()->setAcceptDrops(b);
|
||
14 years ago
|
TQWidget::setAcceptDrops(b);
|
||
15 years ago
|
}
|
||
|
|
||
|
void KDirOperator::setDropOptions(int options)
|
||
|
{
|
||
|
d->dropOptions = options;
|
||
|
if (m_fileView)
|
||
|
m_fileView->setDropOptions(options);
|
||
|
}
|
||
|
|
||
|
void KDirOperator::setView( KFile::FileView view )
|
||
|
{
|
||
|
bool separateDirs = KFile::isSeparateDirs( view );
|
||
|
bool preview=( KFile::isPreviewInfo(view) || KFile::isPreviewContents( view ) );
|
||
|
|
||
|
if (view == KFile::Default) {
|
||
|
if ( KFile::isDetailView( (KFile::FileView) defaultView ) )
|
||
|
view = KFile::Detail;
|
||
|
else
|
||
|
view = KFile::Simple;
|
||
|
|
||
|
separateDirs = KFile::isSeparateDirs( static_cast<KFile::FileView>(defaultView) );
|
||
|
preview = ( KFile::isPreviewInfo( static_cast<KFile::FileView>(defaultView) ) ||
|
||
|
KFile::isPreviewContents( static_cast<KFile::FileView>(defaultView) ) )
|
||
|
&& myActionCollection->action("preview")->isEnabled();
|
||
|
|
||
|
if ( preview ) { // instantiates KFileMetaPreview and calls setView()
|
||
|
m_viewKind = defaultView;
|
||
|
slotDefaultPreview();
|
||
|
return;
|
||
|
}
|
||
|
else if ( !separateDirs )
|
||
|
separateDirsAction->setChecked(true);
|
||
|
}
|
||
|
|
||
|
// if we don't have any files, we can't separate dirs from files :)
|
||
|
if ( (mode() & KFile::File) == 0 &&
|
||
|
(mode() & KFile::Files) == 0 ) {
|
||
|
separateDirs = false;
|
||
|
separateDirsAction->setEnabled( false );
|
||
|
}
|
||
|
|
||
|
m_viewKind = static_cast<int>(view) | (separateDirs ? KFile::SeparateDirs : 0);
|
||
|
view = static_cast<KFile::FileView>(m_viewKind);
|
||
|
|
||
|
KFileView *new_view = createView( this, view );
|
||
|
if ( preview ) {
|
||
|
// we keep the preview-_widget_ around, but not the KFilePreview.
|
||
|
// KFilePreview::setPreviewWidget handles the reparenting for us
|
||
|
static_cast<KFilePreview*>(new_view)->setPreviewWidget(myPreview, url());
|
||
|
}
|
||
|
|
||
|
setView( new_view );
|
||
|
}
|
||
|
|
||
|
|
||
|
void KDirOperator::connectView(KFileView *view)
|
||
|
{
|
||
|
// TODO: do a real timer and restart it after that
|
||
|
pendingMimeTypes.clear();
|
||
|
bool listDir = true;
|
||
|
|
||
|
if ( dirOnlyMode() )
|
||
|
view->setViewMode(KFileView::Directories);
|
||
|
else
|
||
|
view->setViewMode(KFileView::All);
|
||
|
|
||
|
if ( myMode & KFile::Files )
|
||
|
view->setSelectionMode( KFile::Extended );
|
||
|
else
|
||
|
view->setSelectionMode( KFile::Single );
|
||
|
|
||
|
if (m_fileView)
|
||
|
{
|
||
|
if ( d->config ) // save and restore the views' configuration
|
||
|
{
|
||
|
m_fileView->writeConfig( d->config, d->configGroup );
|
||
|
view->readConfig( d->config, d->configGroup );
|
||
|
}
|
||
|
|
||
|
// transfer the state from old view to new view
|
||
|
view->clear();
|
||
|
view->addItemList( *m_fileView->items() );
|
||
|
listDir = false;
|
||
|
|
||
|
if ( m_fileView->widget()->hasFocus() )
|
||
|
view->widget()->setFocus();
|
||
|
|
||
|
KFileItem *oldCurrentItem = m_fileView->currentFileItem();
|
||
|
if ( oldCurrentItem ) {
|
||
|
view->setCurrentItem( oldCurrentItem );
|
||
|
view->setSelected( oldCurrentItem, false );
|
||
|
view->ensureItemVisible( oldCurrentItem );
|
||
|
}
|
||
|
|
||
|
const KFileItemList *oldSelected = m_fileView->selectedItems();
|
||
|
if ( !oldSelected->isEmpty() ) {
|
||
|
KFileItemListIterator it( *oldSelected );
|
||
|
for ( ; it.current(); ++it )
|
||
|
view->setSelected( it.current(), true );
|
||
|
}
|
||
|
|
||
|
m_fileView->widget()->hide();
|
||
|
delete m_fileView;
|
||
|
}
|
||
|
|
||
|
else
|
||
|
{
|
||
|
if ( d->config )
|
||
|
view->readConfig( d->config, d->configGroup );
|
||
|
}
|
||
|
|
||
|
m_fileView = view;
|
||
|
m_fileView->setDropOptions(d->dropOptions);
|
||
|
viewActionCollection = 0L;
|
||
|
KFileViewSignaler *sig = view->signaler();
|
||
|
|
||
14 years ago
|
connect(sig, TQT_SIGNAL( activatedMenu(const KFileItem *, const TQPoint& ) ),
|
||
|
this, TQT_SLOT( activatedMenu(const KFileItem *, const TQPoint& )));
|
||
|
connect(sig, TQT_SIGNAL( dirActivated(const KFileItem *) ),
|
||
|
this, TQT_SLOT( selectDir(const KFileItem*) ) );
|
||
|
connect(sig, TQT_SIGNAL( fileSelected(const KFileItem *) ),
|
||
|
this, TQT_SLOT( selectFile(const KFileItem*) ) );
|
||
|
connect(sig, TQT_SIGNAL( fileHighlighted(const KFileItem *) ),
|
||
|
this, TQT_SLOT( highlightFile(const KFileItem*) ));
|
||
|
connect(sig, TQT_SIGNAL( sortingChanged( TQDir::SortSpec ) ),
|
||
|
this, TQT_SLOT( slotViewSortingChanged( TQDir::SortSpec )));
|
||
|
connect(sig, TQT_SIGNAL( dropped(const KFileItem *, TQDropEvent*, const KURL::List&) ),
|
||
|
this, TQT_SIGNAL( dropped(const KFileItem *, TQDropEvent*, const KURL::List&)) );
|
||
15 years ago
|
|
||
|
if ( reverseAction->isChecked() != m_fileView->isReversed() )
|
||
|
slotSortReversed();
|
||
|
|
||
|
updateViewActions();
|
||
|
m_fileView->widget()->resize(size());
|
||
|
m_fileView->widget()->show();
|
||
|
|
||
|
if ( listDir ) {
|
||
14 years ago
|
TQApplication::setOverrideCursor( tqwaitCursor );
|
||
15 years ago
|
openURL( currUrl );
|
||
|
}
|
||
|
else
|
||
|
view->listingCompleted();
|
||
|
}
|
||
|
|
||
|
KFile::Mode KDirOperator::mode() const
|
||
|
{
|
||
|
return myMode;
|
||
|
}
|
||
|
|
||
|
void KDirOperator::setMode(KFile::Mode m)
|
||
|
{
|
||
|
if (myMode == m)
|
||
|
return;
|
||
|
|
||
|
myMode = m;
|
||
|
|
||
|
dir->setDirOnlyMode( dirOnlyMode() );
|
||
|
|
||
|
// reset the view with the different mode
|
||
|
setView( static_cast<KFile::FileView>(m_viewKind) );
|
||
|
}
|
||
|
|
||
|
void KDirOperator::setView(KFileView *view)
|
||
|
{
|
||
|
if ( view == m_fileView ) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
setFocusProxy(view->widget());
|
||
|
view->setSorting( mySorting );
|
||
|
view->setOnlyDoubleClickSelectsFiles( d->onlyDoubleClickSelectsFiles );
|
||
|
connectView(view); // also deletes the old view
|
||
|
|
||
|
emit viewChanged( view );
|
||
|
}
|
||
|
|
||
|
void KDirOperator::setDirLister( KDirLister *lister )
|
||
|
{
|
||
|
if ( lister == dir ) // sanity check
|
||
|
return;
|
||
|
|
||
|
delete dir;
|
||
|
dir = lister;
|
||
|
|
||
|
dir->setAutoUpdate( true );
|
||
|
|
||
13 years ago
|
TQWidget* mainWidget = topLevelWidget();
|
||
15 years ago
|
dir->setMainWindow (mainWidget);
|
||
12 years ago
|
kdDebug (tdefile_area) << "mainWidget=" << mainWidget << endl;
|
||
15 years ago
|
|
||
14 years ago
|
connect( dir, TQT_SIGNAL( percent( int )),
|
||
|
TQT_SLOT( slotProgress( int ) ));
|
||
|
connect( dir, TQT_SIGNAL(started( const KURL& )), TQT_SLOT(slotStarted()));
|
||
|
connect( dir, TQT_SIGNAL(newItems(const KFileItemList &)),
|
||
|
TQT_SLOT(insertNewFiles(const KFileItemList &)));
|
||
|
connect( dir, TQT_SIGNAL(completed()), TQT_SLOT(slotIOFinished()));
|
||
|
connect( dir, TQT_SIGNAL(canceled()), TQT_SLOT(slotCanceled()));
|
||
|
connect( dir, TQT_SIGNAL(deleteItem(KFileItem *)),
|
||
|
TQT_SLOT(itemDeleted(KFileItem *)));
|
||
|
connect( dir, TQT_SIGNAL(redirection( const KURL& )),
|
||
|
TQT_SLOT( slotRedirected( const KURL& )));
|
||
|
connect( dir, TQT_SIGNAL( clear() ), TQT_SLOT( slotClearView() ));
|
||
|
connect( dir, TQT_SIGNAL( refreshItems( const KFileItemList& ) ),
|
||
|
TQT_SLOT( slotRefreshItems( const KFileItemList& ) ) );
|
||
15 years ago
|
}
|
||
|
|
||
|
void KDirOperator::insertNewFiles(const KFileItemList &newone)
|
||
|
{
|
||
|
if ( newone.isEmpty() || !m_fileView )
|
||
|
return;
|
||
|
|
||
|
myCompleteListDirty = true;
|
||
|
m_fileView->addItemList( newone );
|
||
|
emit updateInformation(m_fileView->numDirs(), m_fileView->numFiles());
|
||
|
|
||
|
KFileItem *item;
|
||
|
KFileItemListIterator it( newone );
|
||
|
|
||
|
while ( (item = it.current()) ) {
|
||
|
// highlight the dir we come from, if possible
|
||
|
if ( d->dirHighlighting && item->isDir() &&
|
||
|
item->url().url(-1) == d->lastURL ) {
|
||
|
m_fileView->setCurrentItem( item );
|
||
|
m_fileView->ensureItemVisible( item );
|
||
|
}
|
||
|
|
||
|
++it;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQTimer::singleShot(200, this, TQT_SLOT(resetCursor()));
|
||
15 years ago
|
}
|
||
|
|
||
|
void KDirOperator::selectDir(const KFileItem *item)
|
||
|
{
|
||
|
setURL(item->url(), true);
|
||
|
}
|
||
|
|
||
|
void KDirOperator::itemDeleted(KFileItem *item)
|
||
|
{
|
||
|
pendingMimeTypes.removeRef( item );
|
||
|
if ( m_fileView )
|
||
|
{
|
||
|
m_fileView->removeItem( static_cast<KFileItem *>( item ));
|
||
|
emit updateInformation(m_fileView->numDirs(), m_fileView->numFiles());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KDirOperator::selectFile(const KFileItem *item)
|
||
|
{
|
||
14 years ago
|
TQApplication::restoreOverrideCursor();
|
||
15 years ago
|
|
||
|
emit fileSelected( item );
|
||
|
}
|
||
|
|
||
14 years ago
|
void KDirOperator::setCurrentItem( const TQString& filename )
|
||
15 years ago
|
{
|
||
|
if ( m_fileView ) {
|
||
|
const KFileItem *item = 0L;
|
||
|
|
||
|
if ( !filename.isNull() )
|
||
14 years ago
|
item = static_cast<KFileItem *>(dir->findByName( filename ));
|
||
15 years ago
|
|
||
|
m_fileView->clearSelection();
|
||
|
if ( item ) {
|
||
|
m_fileView->setCurrentItem( item );
|
||
|
m_fileView->setSelected( item, true );
|
||
|
m_fileView->ensureItemVisible( item );
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString KDirOperator::makeCompletion(const TQString& string)
|
||
15 years ago
|
{
|
||
|
if ( string.isEmpty() ) {
|
||
|
m_fileView->clearSelection();
|
||
14 years ago
|
return TQString::null;
|
||
15 years ago
|
}
|
||
|
|
||
|
prepareCompletionObjects();
|
||
|
return myCompletion.makeCompletion( string );
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString KDirOperator::makeDirCompletion(const TQString& string)
|
||
15 years ago
|
{
|
||
|
if ( string.isEmpty() ) {
|
||
|
m_fileView->clearSelection();
|
||
14 years ago
|
return TQString::null;
|
||
15 years ago
|
}
|
||
|
|
||
|
prepareCompletionObjects();
|
||
|
return myDirCompletion.makeCompletion( string );
|
||
|
}
|
||
|
|
||
|
void KDirOperator::prepareCompletionObjects()
|
||
|
{
|
||
|
if ( !m_fileView )
|
||
|
return;
|
||
|
|
||
|
if ( myCompleteListDirty ) { // create the list of all possible completions
|
||
|
KFileItemListIterator it( *(m_fileView->items()) );
|
||
|
for( ; it.current(); ++it ) {
|
||
|
KFileItem *item = it.current();
|
||
|
|
||
|
myCompletion.addItem( item->name() );
|
||
|
if ( item->isDir() )
|
||
|
myDirCompletion.addItem( item->name() );
|
||
|
}
|
||
|
myCompleteListDirty = false;
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
void KDirOperator::slotCompletionMatch(const TQString& match)
|
||
15 years ago
|
{
|
||
|
setCurrentItem( match );
|
||
|
emit completion( match );
|
||
|
}
|
||
|
|
||
|
void KDirOperator::setupActions()
|
||
|
{
|
||
12 years ago
|
myActionCollection = new TDEActionCollection( topLevelWidget(), TQT_TQOBJECT(this), "KDirOperator::myActionCollection" );
|
||
15 years ago
|
|
||
12 years ago
|
actionMenu = new TDEActionMenu( i18n("Menu"), myActionCollection, "popupMenu" );
|
||
14 years ago
|
upAction = KStdAction::up( TQT_TQOBJECT(this), TQT_SLOT( cdUp() ), myActionCollection, "up" );
|
||
15 years ago
|
upAction->setText( i18n("Parent Folder") );
|
||
14 years ago
|
backAction = KStdAction::back( TQT_TQOBJECT(this), TQT_SLOT( back() ), myActionCollection, "back" );
|
||
|
forwardAction = KStdAction::forward( TQT_TQOBJECT(this), TQT_SLOT(forward()), myActionCollection, "forward" );
|
||
|
homeAction = KStdAction::home( TQT_TQOBJECT(this), TQT_SLOT( home() ), myActionCollection, "home" );
|
||
15 years ago
|
homeAction->setText(i18n("Home Folder"));
|
||
14 years ago
|
reloadAction = KStdAction::redisplay( TQT_TQOBJECT(this), TQT_SLOT(rereadDir()), myActionCollection, "reload" );
|
||
12 years ago
|
actionSeparator = new TDEActionSeparator( myActionCollection, "separator" );
|
||
|
d->viewActionSeparator = new TDEActionSeparator( myActionCollection,
|
||
15 years ago
|
"viewActionSeparator" );
|
||
12 years ago
|
mkdirAction = new TDEAction( i18n("New Folder..."), 0,
|
||
14 years ago
|
TQT_TQOBJECT(this), TQT_SLOT( mkdir() ), myActionCollection, "mkdir" );
|
||
12 years ago
|
TDEAction* trash = new TDEAction( i18n( "Move to Trash" ), "edittrash", Key_Delete, myActionCollection, "trash" );
|
||
|
connect( trash, TQT_SIGNAL( activated( TDEAction::ActivationReason, TQt::ButtonState ) ),
|
||
|
this, TQT_SLOT( trashSelected( TDEAction::ActivationReason, TQt::ButtonState ) ) );
|
||
|
new TDEAction( i18n( "Delete" ), "editdelete", SHIFT+Key_Delete, TQT_TQOBJECT(this),
|
||
14 years ago
|
TQT_SLOT( deleteSelected() ), myActionCollection, "delete" );
|
||
13 years ago
|
mkdirAction->setIcon( TQString::fromLatin1("folder_new") );
|
||
15 years ago
|
reloadAction->setText( i18n("Reload") );
|
||
12 years ago
|
reloadAction->setShortcut( TDEStdAccel::shortcut( TDEStdAccel::Reload ));
|
||
15 years ago
|
|
||
|
|
||
|
// the sort menu actions
|
||
12 years ago
|
sortActionMenu = new TDEActionMenu( i18n("Sorting"), myActionCollection, "sorting menu");
|
||
|
byNameAction = new TDERadioAction( i18n("By Name"), 0,
|
||
14 years ago
|
TQT_TQOBJECT(this), TQT_SLOT( slotSortByName() ),
|
||
15 years ago
|
myActionCollection, "by name" );
|
||
12 years ago
|
byDateAction = new TDERadioAction( i18n("By Date"), 0,
|
||
14 years ago
|
TQT_TQOBJECT(this), TQT_SLOT( slotSortByDate() ),
|
||
15 years ago
|
myActionCollection, "by date" );
|
||
12 years ago
|
bySizeAction = new TDERadioAction( i18n("By Size"), 0,
|
||
14 years ago
|
TQT_TQOBJECT(this), TQT_SLOT( slotSortBySize() ),
|
||
15 years ago
|
myActionCollection, "by size" );
|
||
12 years ago
|
reverseAction = new TDEToggleAction( i18n("Reverse"), 0,
|
||
14 years ago
|
TQT_TQOBJECT(this), TQT_SLOT( slotSortReversed() ),
|
||
15 years ago
|
myActionCollection, "reversed" );
|
||
|
|
||
13 years ago
|
TQString sortGroup = TQString::fromLatin1("sort");
|
||
15 years ago
|
byNameAction->setExclusiveGroup( sortGroup );
|
||
|
byDateAction->setExclusiveGroup( sortGroup );
|
||
|
bySizeAction->setExclusiveGroup( sortGroup );
|
||
|
|
||
|
|
||
12 years ago
|
dirsFirstAction = new TDEToggleAction( i18n("Folders First"), 0,
|
||
15 years ago
|
myActionCollection, "dirs first");
|
||
12 years ago
|
caseInsensitiveAction = new TDEToggleAction(i18n("Case Insensitive"), 0,
|
||
15 years ago
|
myActionCollection, "case insensitive" );
|
||
|
|
||
14 years ago
|
connect( dirsFirstAction, TQT_SIGNAL( toggled( bool ) ),
|
||
|
TQT_SLOT( slotToggleDirsFirst() ));
|
||
|
connect( caseInsensitiveAction, TQT_SIGNAL( toggled( bool ) ),
|
||
|
TQT_SLOT( slotToggleIgnoreCase() ));
|
||
15 years ago
|
|
||
|
|
||
|
|
||
|
// the view menu actions
|
||
12 years ago
|
viewActionMenu = new TDEActionMenu( i18n("&View"), myActionCollection, "view menu" );
|
||
14 years ago
|
connect( viewActionMenu->popupMenu(), TQT_SIGNAL( aboutToShow() ),
|
||
|
TQT_SLOT( insertViewDependentActions() ));
|
||
15 years ago
|
|
||
12 years ago
|
shortAction = new TDERadioAction( i18n("Short View"), "view_multicolumn",
|
||
|
TDEShortcut(), myActionCollection, "short view" );
|
||
|
detailedAction = new TDERadioAction( i18n("Detailed View"), "view_detailed",
|
||
|
TDEShortcut(), myActionCollection, "detailed view" );
|
||
15 years ago
|
|
||
12 years ago
|
showHiddenAction = new TDEToggleAction( i18n("Show Hidden Files"), TDEShortcut(),
|
||
15 years ago
|
myActionCollection, "show hidden" );
|
||
|
// showHiddenAction->setCheckedState( i18n("Hide Hidden Files") );
|
||
12 years ago
|
separateDirsAction = new TDEToggleAction( i18n("Separate Folders"), TDEShortcut(),
|
||
14 years ago
|
TQT_TQOBJECT(this),
|
||
14 years ago
|
TQT_SLOT(slotSeparateDirs()),
|
||
15 years ago
|
myActionCollection, "separate dirs" );
|
||
12 years ago
|
TDEToggleAction *previewAction = new TDEToggleAction(i18n("Show Preview"),
|
||
|
"thumbnail", TDEShortcut(),
|
||
15 years ago
|
myActionCollection,
|
||
|
"preview" );
|
||
|
previewAction->setCheckedState(i18n("Hide Preview"));
|
||
14 years ago
|
connect( previewAction, TQT_SIGNAL( toggled( bool )),
|
||
|
TQT_SLOT( togglePreview( bool )));
|
||
15 years ago
|
|
||
|
|
||
13 years ago
|
TQString viewGroup = TQString::fromLatin1("view");
|
||
15 years ago
|
shortAction->setExclusiveGroup( viewGroup );
|
||
|
detailedAction->setExclusiveGroup( viewGroup );
|
||
|
|
||
14 years ago
|
connect( shortAction, TQT_SIGNAL( activated() ),
|
||
|
TQT_SLOT( slotSimpleView() ));
|
||
|
connect( detailedAction, TQT_SIGNAL( activated() ),
|
||
|
TQT_SLOT( slotDetailedView() ));
|
||
|
connect( showHiddenAction, TQT_SIGNAL( toggled( bool ) ),
|
||
|
TQT_SLOT( slotToggleHidden( bool ) ));
|
||
15 years ago
|
|
||
12 years ago
|
new TDEAction( i18n("Properties"), TDEShortcut(ALT+Key_Return), TQT_TQOBJECT(this),
|
||
14 years ago
|
TQT_SLOT(slotProperties()), myActionCollection, "properties" );
|
||
15 years ago
|
}
|
||
|
|
||
|
void KDirOperator::setupMenu()
|
||
|
{
|
||
|
setupMenu(AllActions);
|
||
|
}
|
||
|
|
||
|
void KDirOperator::setupMenu(int whichActions)
|
||
|
{
|
||
|
// first fill the submenus (sort and view)
|
||
|
sortActionMenu->popupMenu()->clear();
|
||
|
sortActionMenu->insert( byNameAction );
|
||
|
sortActionMenu->insert( byDateAction );
|
||
|
sortActionMenu->insert( bySizeAction );
|
||
|
sortActionMenu->insert( actionSeparator );
|
||
|
sortActionMenu->insert( reverseAction );
|
||
|
sortActionMenu->insert( dirsFirstAction );
|
||
|
sortActionMenu->insert( caseInsensitiveAction );
|
||
|
|
||
|
// now plug everything into the popupmenu
|
||
|
actionMenu->popupMenu()->clear();
|
||
|
if (whichActions & NavActions)
|
||
|
{
|
||
|
actionMenu->insert( upAction );
|
||
|
actionMenu->insert( backAction );
|
||
|
actionMenu->insert( forwardAction );
|
||
|
actionMenu->insert( homeAction );
|
||
|
actionMenu->insert( actionSeparator );
|
||
|
}
|
||
|
|
||
|
if (whichActions & FileActions)
|
||
|
{
|
||
|
actionMenu->insert( mkdirAction );
|
||
12 years ago
|
if (currUrl.isLocalFile() && !(TDEApplication::keyboardMouseState() & TQt::ShiftButton))
|
||
15 years ago
|
actionMenu->insert( myActionCollection->action( "trash" ) );
|
||
12 years ago
|
TDEConfig *globalconfig = TDEGlobal::config();
|
||
|
TDEConfigGroupSaver cs( globalconfig, TQString::fromLatin1("KDE") );
|
||
12 years ago
|
if (!currUrl.isLocalFile() || (TDEApplication::keyboardMouseState() & TQt::ShiftButton) ||
|
||
15 years ago
|
globalconfig->readBoolEntry("ShowDeleteCommand", false))
|
||
|
actionMenu->insert( myActionCollection->action( "delete" ) );
|
||
|
actionMenu->insert( actionSeparator );
|
||
|
}
|
||
|
|
||
|
if (whichActions & SortActions)
|
||
|
{
|
||
|
actionMenu->insert( sortActionMenu );
|
||
|
actionMenu->insert( actionSeparator );
|
||
|
}
|
||
|
|
||
|
if (whichActions & ViewActions)
|
||
|
{
|
||
|
actionMenu->insert( viewActionMenu );
|
||
|
actionMenu->insert( actionSeparator );
|
||
|
}
|
||
|
|
||
|
if (whichActions & FileActions)
|
||
|
{
|
||
|
actionMenu->insert( myActionCollection->action( "properties" ) );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KDirOperator::updateSortActions()
|
||
|
{
|
||
|
if ( KFile::isSortByName( mySorting ) )
|
||
|
byNameAction->setChecked( true );
|
||
|
else if ( KFile::isSortByDate( mySorting ) )
|
||
|
byDateAction->setChecked( true );
|
||
|
else if ( KFile::isSortBySize( mySorting ) )
|
||
|
bySizeAction->setChecked( true );
|
||
|
|
||
|
dirsFirstAction->setChecked( KFile::isSortDirsFirst( mySorting ) );
|
||
|
caseInsensitiveAction->setChecked( KFile::isSortCaseInsensitive(mySorting) );
|
||
|
caseInsensitiveAction->setEnabled( KFile::isSortByName( mySorting ) );
|
||
|
|
||
|
if ( m_fileView )
|
||
|
reverseAction->setChecked( m_fileView->isReversed() );
|
||
|
}
|
||
|
|
||
|
void KDirOperator::updateViewActions()
|
||
|
{
|
||
|
KFile::FileView fv = static_cast<KFile::FileView>( m_viewKind );
|
||
|
|
||
|
separateDirsAction->setChecked( KFile::isSeparateDirs( fv ) &&
|
||
|
separateDirsAction->isEnabled() );
|
||
|
|
||
|
shortAction->setChecked( KFile::isSimpleView( fv ));
|
||
|
detailedAction->setChecked( KFile::isDetailView( fv ));
|
||
|
}
|
||
|
|
||
12 years ago
|
void KDirOperator::readConfig( TDEConfig *kc, const TQString& group )
|
||
15 years ago
|
{
|
||
|
if ( !kc )
|
||
|
return;
|
||
14 years ago
|
TQString oldGroup = kc->group();
|
||
15 years ago
|
if ( !group.isEmpty() )
|
||
|
kc->setGroup( group );
|
||
|
|
||
|
defaultView = 0;
|
||
|
int sorting = 0;
|
||
|
|
||
13 years ago
|
TQString viewStyle = kc->readEntry( TQString::fromLatin1("View Style"),
|
||
|
TQString::fromLatin1("Simple") );
|
||
|
if ( viewStyle == TQString::fromLatin1("Detail") )
|
||
15 years ago
|
defaultView |= KFile::Detail;
|
||
|
else
|
||
|
defaultView |= KFile::Simple;
|
||
13 years ago
|
if ( kc->readBoolEntry( TQString::fromLatin1("Separate Directories"),
|
||
15 years ago
|
DefaultMixDirsAndFiles ) )
|
||
|
defaultView |= KFile::SeparateDirs;
|
||
13 years ago
|
if ( kc->readBoolEntry(TQString::fromLatin1("Show Preview"), false))
|
||
15 years ago
|
defaultView |= KFile::PreviewContents;
|
||
|
|
||
13 years ago
|
if ( kc->readBoolEntry( TQString::fromLatin1("Sort case insensitively"),
|
||
15 years ago
|
DefaultCaseInsensitive ) )
|
||
14 years ago
|
sorting |= TQDir::IgnoreCase;
|
||
13 years ago
|
if ( kc->readBoolEntry( TQString::fromLatin1("Sort directories first"),
|
||
15 years ago
|
DefaultDirsFirst ) )
|
||
14 years ago
|
sorting |= TQDir::DirsFirst;
|
||
15 years ago
|
|
||
|
|
||
13 years ago
|
TQString name = TQString::fromLatin1("Name");
|
||
|
TQString sortBy = kc->readEntry( TQString::fromLatin1("Sort by"), name );
|
||
15 years ago
|
if ( sortBy == name )
|
||
14 years ago
|
sorting |= TQDir::Name;
|
||
13 years ago
|
else if ( sortBy == TQString::fromLatin1("Size") )
|
||
14 years ago
|
sorting |= TQDir::Size;
|
||
13 years ago
|
else if ( sortBy == TQString::fromLatin1("Date") )
|
||
14 years ago
|
sorting |= TQDir::Time;
|
||
15 years ago
|
|
||
14 years ago
|
mySorting = static_cast<TQDir::SortSpec>( sorting );
|
||
15 years ago
|
setSorting( mySorting );
|
||
|
|
||
|
|
||
13 years ago
|
if ( kc->readBoolEntry( TQString::fromLatin1("Show hidden files"),
|
||
15 years ago
|
DefaultShowHidden ) ) {
|
||
|
showHiddenAction->setChecked( true );
|
||
|
dir->setShowingDotFiles( true );
|
||
|
}
|
||
13 years ago
|
if ( kc->readBoolEntry( TQString::fromLatin1("Sort reversed"),
|
||
15 years ago
|
DefaultSortReversed ) )
|
||
|
reverseAction->setChecked( true );
|
||
|
|
||
|
kc->setGroup( oldGroup );
|
||
|
}
|
||
|
|
||
12 years ago
|
void KDirOperator::writeConfig( TDEConfig *kc, const TQString& group )
|
||
15 years ago
|
{
|
||
|
if ( !kc )
|
||
|
return;
|
||
|
|
||
14 years ago
|
const TQString oldGroup = kc->group();
|
||
15 years ago
|
|
||
|
if ( !group.isEmpty() )
|
||
|
kc->setGroup( group );
|
||
|
|
||
13 years ago
|
TQString sortBy = TQString::fromLatin1("Name");
|
||
15 years ago
|
if ( KFile::isSortBySize( mySorting ) )
|
||
13 years ago
|
sortBy = TQString::fromLatin1("Size");
|
||
15 years ago
|
else if ( KFile::isSortByDate( mySorting ) )
|
||
13 years ago
|
sortBy = TQString::fromLatin1("Date");
|
||
|
kc->writeEntry( TQString::fromLatin1("Sort by"), sortBy );
|
||
15 years ago
|
|
||
13 years ago
|
kc->writeEntry( TQString::fromLatin1("Sort reversed"),
|
||
15 years ago
|
reverseAction->isChecked() );
|
||
13 years ago
|
kc->writeEntry( TQString::fromLatin1("Sort case insensitively"),
|
||
15 years ago
|
caseInsensitiveAction->isChecked() );
|
||
13 years ago
|
kc->writeEntry( TQString::fromLatin1("Sort directories first"),
|
||
15 years ago
|
dirsFirstAction->isChecked() );
|
||
|
|
||
|
// don't save the separate dirs or preview when an application specific
|
||
|
// preview is in use.
|
||
|
bool appSpecificPreview = false;
|
||
|
if ( myPreview ) {
|
||
14 years ago
|
TQWidget *preview = const_cast<TQWidget*>( myPreview ); // grmbl
|
||
15 years ago
|
KFileMetaPreview *tmp = dynamic_cast<KFileMetaPreview*>( preview );
|
||
|
appSpecificPreview = (tmp == 0L);
|
||
|
}
|
||
|
|
||
|
if ( !appSpecificPreview ) {
|
||
|
if ( separateDirsAction->isEnabled() )
|
||
13 years ago
|
kc->writeEntry( TQString::fromLatin1("Separate Directories"),
|
||
15 years ago
|
separateDirsAction->isChecked() );
|
||
|
|
||
12 years ago
|
TDEToggleAction *previewAction = static_cast<TDEToggleAction*>(myActionCollection->action("preview"));
|
||
15 years ago
|
if ( previewAction->isEnabled() ) {
|
||
|
bool hasPreview = previewAction->isChecked();
|
||
13 years ago
|
kc->writeEntry( TQString::fromLatin1("Show Preview"), hasPreview );
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
13 years ago
|
kc->writeEntry( TQString::fromLatin1("Show hidden files"),
|
||
15 years ago
|
showHiddenAction->isChecked() );
|
||
|
|
||
|
KFile::FileView fv = static_cast<KFile::FileView>( m_viewKind );
|
||
14 years ago
|
TQString style;
|
||
15 years ago
|
if ( KFile::isDetailView( fv ) )
|
||
13 years ago
|
style = TQString::fromLatin1("Detail");
|
||
15 years ago
|
else if ( KFile::isSimpleView( fv ) )
|
||
13 years ago
|
style = TQString::fromLatin1("Simple");
|
||
|
kc->writeEntry( TQString::fromLatin1("View Style"), style );
|
||
15 years ago
|
|
||
|
kc->setGroup( oldGroup );
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void KDirOperator::resizeEvent( TQResizeEvent * )
|
||
15 years ago
|
{
|
||
|
if (m_fileView)
|
||
|
m_fileView->widget()->resize( size() );
|
||
|
|
||
13 years ago
|
if ( TQT_BASE_OBJECT(progress->parent()) == TQT_BASE_OBJECT(this) ) // might be reparented into a statusbar
|
||
15 years ago
|
progress->move(2, height() - progress->height() -2);
|
||
|
}
|
||
|
|
||
|
void KDirOperator::setOnlyDoubleClickSelectsFiles( bool enable )
|
||
|
{
|
||
|
d->onlyDoubleClickSelectsFiles = enable;
|
||
|
if ( m_fileView )
|
||
|
m_fileView->setOnlyDoubleClickSelectsFiles( enable );
|
||
|
}
|
||
|
|
||
|
bool KDirOperator::onlyDoubleClickSelectsFiles() const
|
||
|
{
|
||
|
return d->onlyDoubleClickSelectsFiles;
|
||
|
}
|
||
|
|
||
|
void KDirOperator::slotStarted()
|
||
|
{
|
||
|
progress->setProgress( 0 );
|
||
|
// delay showing the progressbar for one second
|
||
|
d->progressDelayTimer->start( 1000, true );
|
||
|
}
|
||
|
|
||
|
void KDirOperator::slotShowProgress()
|
||
|
{
|
||
|
progress->raise();
|
||
|
progress->show();
|
||
14 years ago
|
TQApplication::flushX();
|
||
15 years ago
|
}
|
||
|
|
||
|
void KDirOperator::slotProgress( int percent )
|
||
|
{
|
||
|
progress->setProgress( percent );
|
||
|
// we have to redraw this as fast as possible
|
||
|
if ( progress->isVisible() )
|
||
14 years ago
|
TQApplication::flushX();
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
|
void KDirOperator::slotIOFinished()
|
||
|
{
|
||
|
d->progressDelayTimer->stop();
|
||
|
slotProgress( 100 );
|
||
|
progress->hide();
|
||
|
emit finishedLoading();
|
||
|
resetCursor();
|
||
|
|
||
|
if ( m_fileView )
|
||
|
m_fileView->listingCompleted();
|
||
|
}
|
||
|
|
||
|
void KDirOperator::slotCanceled()
|
||
|
{
|
||
|
emit finishedLoading();
|
||
|
resetCursor();
|
||
|
|
||
|
if ( m_fileView )
|
||
|
m_fileView->listingCompleted();
|
||
|
}
|
||
|
|
||
|
KProgress * KDirOperator::progressBar() const
|
||
|
{
|
||
|
return progress;
|
||
|
}
|
||
|
|
||
|
void KDirOperator::clearHistory()
|
||
|
{
|
||
|
backStack.clear();
|
||
|
backAction->setEnabled( false );
|
||
|
forwardStack.clear();
|
||
|
forwardAction->setEnabled( false );
|
||
|
}
|
||
|
|
||
12 years ago
|
void KDirOperator::slotViewActionAdded( TDEAction *action )
|
||
15 years ago
|
{
|
||
|
if ( viewActionMenu->popupMenu()->count() == 5 ) // need to add a separator
|
||
|
viewActionMenu->insert( d->viewActionSeparator );
|
||
|
|
||
|
viewActionMenu->insert( action );
|
||
|
}
|
||
|
|
||
12 years ago
|
void KDirOperator::slotViewActionRemoved( TDEAction *action )
|
||
15 years ago
|
{
|
||
|
viewActionMenu->remove( action );
|
||
|
|
||
|
if ( viewActionMenu->popupMenu()->count() == 6 ) // remove the separator
|
||
|
viewActionMenu->remove( d->viewActionSeparator );
|
||
|
}
|
||
|
|
||
14 years ago
|
void KDirOperator::slotViewSortingChanged( TQDir::SortSpec sort )
|
||
15 years ago
|
{
|
||
|
mySorting = sort;
|
||
|
updateSortActions();
|
||
|
}
|
||
|
|
||
|
void KDirOperator::setEnableDirHighlighting( bool enable )
|
||
|
{
|
||
|
d->dirHighlighting = enable;
|
||
|
}
|
||
|
|
||
|
bool KDirOperator::dirHighlighting() const
|
||
|
{
|
||
|
return d->dirHighlighting;
|
||
|
}
|
||
|
|
||
|
void KDirOperator::slotProperties()
|
||
|
{
|
||
|
if ( m_fileView ) {
|
||
|
const KFileItemList *list = m_fileView->selectedItems();
|
||
|
if ( !list->isEmpty() )
|
||
|
(void) new KPropertiesDialog( *list, this, "props dlg", true);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KDirOperator::slotClearView()
|
||
|
{
|
||
|
if ( m_fileView )
|
||
|
m_fileView->clearView();
|
||
|
}
|
||
|
|
||
|
// ### temporary code
|
||
|
#include <dirent.h>
|
||
|
bool KDirOperator::isReadable( const KURL& url )
|
||
|
{
|
||
|
if ( !url.isLocalFile() )
|
||
|
return true; // what else can we say?
|
||
|
|
||
|
KDE_struct_stat buf;
|
||
14 years ago
|
TQString ts = url.path(+1);
|
||
|
bool readable = ( KDE_stat( TQFile::encodeName( ts ), &buf) == 0 );
|
||
15 years ago
|
if (readable) { // further checks
|
||
|
DIR *test;
|
||
14 years ago
|
test = opendir( TQFile::encodeName( ts )); // we do it just to test here
|
||
15 years ago
|
readable = (test != 0);
|
||
|
if (test)
|
||
|
closedir(test);
|
||
|
}
|
||
|
return readable;
|
||
|
}
|
||
|
|
||
|
void KDirOperator::togglePreview( bool on )
|
||
|
{
|
||
|
if ( on )
|
||
|
slotDefaultPreview();
|
||
|
else
|
||
|
setView( (KFile::FileView) (m_viewKind & ~(KFile::PreviewContents|KFile::PreviewInfo)) );
|
||
|
}
|
||
|
|
||
|
void KDirOperator::slotRefreshItems( const KFileItemList& items )
|
||
|
{
|
||
|
if ( !m_fileView )
|
||
|
return;
|
||
|
|
||
|
KFileItemListIterator it( items );
|
||
|
for ( ; it.current(); ++it )
|
||
|
m_fileView->updateView( it.current() );
|
||
|
}
|
||
|
|
||
12 years ago
|
void KDirOperator::setViewConfig( TDEConfig *config, const TQString& group )
|
||
15 years ago
|
{
|
||
|
d->config = config;
|
||
|
d->configGroup = group;
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEConfig * KDirOperator::viewConfig()
|
||
15 years ago
|
{
|
||
|
return d->config;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString KDirOperator::viewConfigGroup() const
|
||
15 years ago
|
{
|
||
|
return d->configGroup;
|
||
|
}
|
||
|
|
||
|
void KDirOperator::virtual_hook( int, void* )
|
||
|
{ /*BASE::virtual_hook( id, data );*/ }
|
||
|
|
||
12 years ago
|
#include "tdediroperator.moc"
|