24 #include <tqapplication.h>
28 #include <tqpushbutton.h>
29 #include <tqpopupmenu.h>
34 #include <tdeaction.h>
35 #include <tdeapplication.h>
38 #include <kdialogbase.h>
39 #include <kdirlister.h>
40 #include <kinputdialog.h>
41 #include <tdelocale.h>
42 #include <tdemessagebox.h>
43 #include <tdepopupmenu.h>
44 #include <kprogress.h>
45 #include <kstdaction.h>
46 #include <tdeio/job.h>
47 #include <tdeio/jobclasses.h>
48 #include <tdeio/netaccess.h>
49 #include <tdeio/previewjob.h>
50 #include <tdeio/renamedlg.h>
51 #include <kpropertiesdialog.h>
52 #include <kservicetypefactory.h>
53 #include <tdestdaccel.h>
56 #include "config-tdefile.h"
57 #include "kcombiview.h"
58 #include "tdediroperator.h"
59 #include "tdefiledetailview.h"
60 #include "tdefileiconview.h"
61 #include "tdefilepreview.h"
62 #include "tdefileview.h"
63 #include "tdefileitem.h"
64 #include "tdefilemetapreview.h"
67 template class TQPtrStack<KURL>;
68 template class TQDict<KFileItem>;
71 class KDirOperator::KDirOperatorPrivate
74 KDirOperatorPrivate() {
75 onlyDoubleClickSelectsFiles =
false;
76 progressDelayTimer = 0L;
77 dirHighlighting =
false;
82 ~KDirOperatorPrivate() {
83 delete progressDelayTimer;
88 bool onlyDoubleClickSelectsFiles;
89 TQTimer *progressDelayTimer;
90 TDEActionSeparator *viewActionSeparator;
98 TQWidget *parent,
const char* _name)
99 : TQWidget(parent, _name),
105 myMode = KFile::File;
106 m_viewKind = KFile::Simple;
107 mySorting =
static_cast<TQDir::SortSpec
>(TQDir::Name | TQDir::DirsFirst);
108 d =
new KDirOperatorPrivate;
110 if (_url.isEmpty()) {
111 TQString strPath = TQDir::currentDirPath();
114 currUrl.setProtocol(TQString::fromLatin1(
"file"));
115 currUrl.setPath(strPath);
119 if ( currUrl.protocol().isEmpty() )
120 currUrl.setProtocol(TQString::fromLatin1(
"file"));
122 currUrl.addPath(
"/");
127 connect(&myCompletion, TQ_SIGNAL(match(
const TQString&)),
130 progress =
new KProgress(
this,
"progress");
131 progress->adjustSize();
132 progress->move(2, height() - progress->height() -2);
134 d->progressDelayTimer =
new TQTimer(
this,
"progress delay timer" );
135 connect( d->progressDelayTimer, TQ_SIGNAL( timeout() ),
136 TQ_SLOT( slotShowProgress() ));
138 myCompleteListDirty =
false;
140 backStack.setAutoDelete(
true );
141 forwardStack.setAutoDelete(
true );
147 setFocusPolicy(TQWidget::WheelFocus);
149 installEventFilter(
this);
158 m_fileView->writeConfig( d->config, d->configGroup );
180 TQApplication::restoreOverrideCursor();
184 void KDirOperator::insertViewDependentActions()
192 if ( (viewActionMenu->popupMenu()->count() == 0) ||
195 if (viewActionCollection)
197 disconnect( viewActionCollection, TQ_SIGNAL( inserted( TDEAction * )),
198 this, TQ_SLOT( slotViewActionAdded( TDEAction * )));
199 disconnect( viewActionCollection, TQ_SIGNAL( removed( TDEAction * )),
200 this, TQ_SLOT( slotViewActionRemoved( TDEAction * )));
203 viewActionMenu->popupMenu()->clear();
207 viewActionMenu->insert( myActionCollection->action(
"short view" ) );
208 viewActionMenu->insert( myActionCollection->action(
"detailed view" ) );
209 viewActionMenu->insert( actionSeparator );
210 viewActionMenu->insert( showHiddenAction );
212 viewActionMenu->insert( separateDirsAction );
217 if (!viewActionCollection)
220 if ( !viewActionCollection->isEmpty() )
222 viewActionMenu->insert( d->viewActionSeparator );
225 TQStringList groups = viewActionCollection->groups();
226 groups.prepend( TQString::null );
227 TQStringList::ConstIterator git = groups.begin();
228 TDEActionPtrList list;
230 for ( ; git != groups.end(); ++git )
232 if ( git != groups.begin() )
233 viewActionMenu->insert( sep );
235 list = viewActionCollection->actions( *git );
236 TDEActionPtrList::ConstIterator it = list.begin();
237 for ( ; it != list.end(); ++it )
238 viewActionMenu->insert( *it );
242 connect( viewActionCollection, TQ_SIGNAL( inserted( TDEAction * )),
243 TQ_SLOT( slotViewActionAdded( TDEAction * )));
244 connect( viewActionCollection, TQ_SIGNAL( removed( TDEAction * )),
245 TQ_SLOT( slotViewActionRemoved( TDEAction * )));
254 actionMenu->popup( pos );
259 bool hasSelection = m_fileView && m_fileView->
selectedItems() &&
261 myActionCollection->action(
"trash" )->setEnabled( hasSelection );
262 myActionCollection->action(
"delete" )->setEnabled( hasSelection );
263 myActionCollection->action(
"properties" )->setEnabled( hasSelection );
269 m_viewKind = (m_viewKind | KFile::PreviewContents);
271 m_viewKind = (m_viewKind & ~
KFile::PreviewContents);
276 TDEToggleAction *preview =
static_cast<TDEToggleAction*
>(myActionCollection->action(
"preview"));
277 preview->setEnabled( w != 0L );
278 preview->setChecked( w != 0L );
279 setView(
static_cast<KFile::FileView
>(m_viewKind) );
284 return m_fileView ? m_fileView->
numDirs() : 0;
289 return m_fileView ? m_fileView->
numFiles() : 0;
292 void KDirOperator::slotDetailedView()
294 KFile::FileView
view =
static_cast<KFile::FileView
>( (m_viewKind & ~
KFile::Simple) | KFile::Detail );
298 void KDirOperator::slotSimpleView()
300 KFile::FileView
view =
static_cast<KFile::FileView
>( (m_viewKind & ~
KFile::Detail) | KFile::Simple );
304 void KDirOperator::slotToggleHidden(
bool show )
306 dir->setShowingDotFiles( show );
312 void KDirOperator::slotSeparateDirs()
314 if (separateDirsAction->isChecked())
316 KFile::FileView
view =
static_cast<KFile::FileView
>( m_viewKind | KFile::SeparateDirs );
321 KFile::FileView
view =
static_cast<KFile::FileView
>( m_viewKind & ~
KFile::SeparateDirs );
326 void KDirOperator::slotDefaultPreview()
328 m_viewKind = m_viewKind | KFile::PreviewContents;
330 myPreview =
new KFileMetaPreview(
this );
331 (
static_cast<TDEToggleAction*
>( myActionCollection->action(
"preview") ))->setChecked(
true);
334 setView(
static_cast<KFile::FileView
>(m_viewKind) );
337 void KDirOperator::slotSortByName()
341 mySorting = m_fileView->
sorting();
342 caseInsensitiveAction->setEnabled(
true );
345 void KDirOperator::slotSortBySize()
349 mySorting = m_fileView->
sorting();
350 caseInsensitiveAction->setEnabled(
false );
353 void KDirOperator::slotSortByDate()
357 mySorting = m_fileView->
sorting();
358 caseInsensitiveAction->setEnabled(
false );
361 void KDirOperator::slotSortReversed()
364 m_fileView->sortReversed();
367 void KDirOperator::slotToggleDirsFirst()
370 if ( !KFile::isSortDirsFirst(
sorting ) )
371 m_fileView->
setSorting(
static_cast<TQDir::SortSpec
>(
sorting | TQDir::DirsFirst ));
373 m_fileView->
setSorting(
static_cast<TQDir::SortSpec
>(
sorting & ~TQDir::DirsFirst));
374 mySorting = m_fileView->
sorting();
377 void KDirOperator::slotToggleIgnoreCase()
380 if ( !KFile::isSortCaseInsensitive(
sorting ) )
381 m_fileView->
setSorting(
static_cast<TQDir::SortSpec
>(
sorting | TQDir::IgnoreCase ));
383 m_fileView->
setSorting(
static_cast<TQDir::SortSpec
>(
sorting & ~TQDir::IgnoreCase));
384 mySorting = m_fileView->
sorting();
390 TQString where =
url().pathOrURL();
391 TQString name = i18n(
"New Folder" );
392 if (
url().isLocalFile() && TQFileInfo(
url().path(+1) + name ).exists() )
393 name = TDEIO::RenameDlg::suggestName(
url(), name );
395 TQString dir = KInputDialog::getText( i18n(
"New Folder" ),
396 i18n(
"Create new folder in:\n%1" ).arg( where ),
399 mkdir( TDEIO::encodeFileName( dir ),
true );
408 bool writeOk =
false;
412 TQStringList dirs = TQStringList::split( TQDir::separator(), directory );
413 TQStringList::ConstIterator it = dirs.begin();
415 for ( ; it != dirs.end(); ++it )
418 exists = TDEIO::NetAccess::exists(
url,
false, 0 );
419 writeOk = !exists && TDEIO::NetAccess::mkdir(
url, topLevelWidget() );
424 KMessageBox::sorry(
viewWidget(), i18n(
"A file or folder named %1 already exists.").arg(
url.pathOrURL()));
425 enterDirectory =
false;
427 else if ( !writeOk ) {
428 KMessageBox::sorry(
viewWidget(), i18n(
"You do not have permission to "
429 "create that folder." ));
431 else if ( enterDirectory ) {
439 bool ask,
bool showProgress )
441 return del( items,
this, ask, showProgress );
446 bool ask,
bool showProgress )
448 if ( items.isEmpty() ) {
449 KMessageBox::information( parent,
450 i18n(
"You did not select a file to delete."),
451 i18n(
"Nothing to Delete") );
457 KFileItemListIterator it( items );
459 for ( ; it.current(); ++it ) {
460 KURL
url = (*it)->url();
462 if (
url.isLocalFile() )
463 files.append(
url.path() );
465 files.append(
url.prettyURL() );
471 if ( items.count() == 1 ) {
472 ret = KMessageBox::warningContinueCancel( parent,
473 i18n(
"<qt>Do you really want to delete\n <b>'%1'</b>?</qt>" )
474 .arg( files.first() ),
476 KStdGuiItem::del(),
"AskForDelete" );
479 ret = KMessageBox::warningContinueCancelList( parent,
480 i18n(
"Do you really want to delete this item?",
"Do you really want to delete these %n items?", items.count() ),
482 i18n(
"Delete Files"),
483 KStdGuiItem::del(),
"AskForDelete" );
484 doIt = (ret == KMessageBox::Continue);
488 TDEIO::DeleteJob *job = TDEIO::del( urls,
false, showProgress );
489 job->setWindow (topLevelWidget());
490 job->setAutoErrorHandlingEnabled(
true, parent );
509 bool ask,
bool showProgress )
511 if ( items.isEmpty() ) {
512 KMessageBox::information( parent,
513 i18n(
"You did not select a file to trash."),
514 i18n(
"Nothing to Trash") );
520 KFileItemListIterator it( items );
522 for ( ; it.current(); ++it ) {
523 KURL
url = (*it)->url();
525 if (
url.isLocalFile() )
526 files.append(
url.path() );
528 files.append(
url.prettyURL() );
534 if ( items.count() == 1 ) {
535 ret = KMessageBox::warningContinueCancel( parent,
536 i18n(
"<qt>Do you really want to trash\n <b>'%1'</b>?</qt>" )
537 .arg( files.first() ),
539 KGuiItem(i18n(
"to trash",
"&Trash"),
"edittrash"),
"AskForTrash" );
542 ret = KMessageBox::warningContinueCancelList( parent,
543 i18n(
"translators: not called for n == 1",
"Do you really want to trash these %n items?", items.count() ),
546 KGuiItem(i18n(
"to trash",
"&Trash"),
"edittrash"),
"AskForTrash" );
547 doIt = (ret == KMessageBox::Continue);
551 TDEIO::CopyJob *job = TDEIO::trash( urls, showProgress );
552 job->setWindow (topLevelWidget());
553 job->setAutoErrorHandlingEnabled(
true, parent );
565 if ( reason == TDEAction::PopupMenuActivation && ( state & ShiftButton ) ) {
572 trash( *list,
this );
578 pendingMimeTypes.clear();
579 myCompletion.clear();
580 myDirCompletion.clear();
581 myCompleteListDirty =
true;
585 void KDirOperator::checkPath(
const TQString &,
bool )
589 TQString text = _txt;
592 text = text.stripWhiteSpace();
595 if (text.find(
':') < 0 && text[0] !=
'/')
596 text.insert(0, currUrl);
600 if (!selection.isNull()) {
601 int position = text.findRev(
'/');
602 ASSERT(position >= 0);
603 TQString filename = text.mid(position + 1, text.length());
604 if (filename != selection)
605 selection = TQString::null;
609 bool filenameEntered =
false;
611 if (u.isLocalFile()) {
613 KFileItem i(
"", u.path());
618 if (acceptOnlyExisting && !i.isFile())
619 warning(
"you entered an invalid URL");
621 filenameEntered =
true;
626 if (filenameEntered) {
628 emit fileSelected(filename_);
630 TQApplication::restoreOverrideCursor();
635 kdDebug(tdefile_area) <<
"TODO KDirOperator::checkPath()" << endl;
642 if ( !_newurl.isValid() )
643 newurl.setPath( TQDir::homeDirPath() );
647 TQString pathstr = newurl.path(+1);
648 newurl.setPath(pathstr);
651 if ( newurl.equals( currUrl,
true ) )
654 if ( !isReadable( newurl ) ) {
656 newurl.cd(TQString::fromLatin1(
".."));
657 if ( !isReadable( newurl ) ) {
660 i18n(
"The specified folder does not exist "
661 "or was not readable."));
668 backStack.push(
new KURL(currUrl));
669 forwardStack.clear();
672 d->lastURL = currUrl.url(-1);
676 emit urlEntered(newurl);
679 forwardAction->setEnabled( !forwardStack.isEmpty() );
680 backAction->setEnabled( !backStack.isEmpty() );
681 upAction->setEnabled( !
isRoot() );
696 openURL( currUrl,
false,
true );
700 bool KDirOperator::openURL(
const KURL& url,
bool keep,
bool reload )
702 bool result = dir->openURL(
url, keep, reload );
715 pendingMimeTypes.clear();
717 myCompletion.clear();
718 myDirCompletion.clear();
721 TQApplication::restoreOverrideCursor();
724 TQApplication::setOverrideCursor( TQt::waitCursor );
726 if ( !isReadable( currUrl )) {
728 i18n(
"The specified folder does not exist "
729 "or was not readable."));
730 if (backStack.isEmpty())
737 void KDirOperator::slotRedirected(
const KURL& newURL )
740 pendingMimeTypes.clear();
741 myCompletion.clear();
742 myDirCompletion.clear();
743 myCompleteListDirty =
true;
744 emit urlEntered( newURL );
750 if ( backStack.isEmpty() )
753 forwardStack.push(
new KURL(currUrl) );
755 KURL *s = backStack.pop();
764 if ( forwardStack.isEmpty() )
767 backStack.push(
new KURL(currUrl));
769 KURL *s = forwardStack.pop();
782 tmp.cd(TQString::fromLatin1(
".."));
789 u.setPath( TQDir::homeDirPath() );
795 dir->setNameFilter( TQString::null );
796 dir->clearMimeFilter();
802 dir->setNameFilter(filter);
808 dir->setMimeFilter( mimetypes );
814 TDEToggleAction *previewAction =
static_cast<TDEToggleAction*
>( myActionCollection->action(
"preview" ));
816 bool hasPreviewSupport =
false;
817 TDEConfig *kc = TDEGlobal::config();
818 TDEConfigGroupSaver cs( kc, ConfigGroup );
819 if ( kc->readBoolEntry(
"Show Default Preview",
true ) )
820 hasPreviewSupport = checkPreviewInternal();
822 previewAction->setEnabled( hasPreviewSupport );
823 return hasPreviewSupport;
826 bool KDirOperator::checkPreviewInternal()
const
828 TQStringList supported = TDEIO::PreviewJob::supportedMimeTypes();
830 if (
dirOnlyMode() && supported.findIndex(
"inode/directory" ) == -1 )
833 TQStringList mimeTypes = dir->mimeFilters();
834 TQStringList
nameFilter = TQStringList::split(
" ", dir->nameFilter() );
836 if ( mimeTypes.isEmpty() &&
nameFilter.isEmpty() && !supported.isEmpty() )
840 r.setWildcard(
true );
842 if ( !mimeTypes.isEmpty() ) {
843 TQStringList::Iterator it = supported.begin();
845 for ( ; it != supported.end(); ++it ) {
848 TQStringList result = mimeTypes.grep( r );
849 if ( !result.isEmpty() ) {
857 KServiceTypeFactory *fac = KServiceTypeFactory::self();
858 TQStringList::Iterator it1 =
nameFilter.begin();
860 if ( (*it1) ==
"*" ) {
864 KMimeType *mt = fac->findFromPattern( *it1 );
867 TQString mime = mt->name();
872 TQStringList::Iterator it2 = supported.begin();
873 for ( ; it2 != supported.end(); ++it2 ) {
874 r.setPattern( *it2 );
875 if ( r.search( mime ) != -1 ) {
889 bool separateDirs = KFile::isSeparateDirs(
view );
892 if ( separateDirs || preview ) {
896 combi =
new KCombiView( parent,
"combi view" );
901 if ( KFile::isSimpleView(
view ) )
920 else if ( KFile::isDetailView(
view ) && !preview ) {
930 new_view->
widget()->setAcceptDrops(acceptDrops());
937 m_fileView->
widget()->setAcceptDrops(b);
938 TQWidget::setAcceptDrops(b);
943 d->dropOptions = options;
950 bool separateDirs = KFile::isSeparateDirs(
view );
953 if (
view == KFile::Default) {
954 if ( KFile::isDetailView( (KFile::FileView) defaultView ) )
955 view = KFile::Detail;
957 view = KFile::Simple;
959 separateDirs = KFile::isSeparateDirs(
static_cast<KFile::FileView
>(defaultView) );
961 KFile::isPreviewContents(
static_cast<KFile::FileView
>(defaultView) ) )
962 && myActionCollection->action(
"preview")->isEnabled();
965 m_viewKind = defaultView;
966 slotDefaultPreview();
969 else if ( !separateDirs )
970 separateDirsAction->setChecked(
true);
974 if ( (
mode() & KFile::File) == 0 &&
975 (
mode() & KFile::Files) == 0 ) {
976 separateDirs =
false;
977 separateDirsAction->setEnabled(
false );
980 m_viewKind =
static_cast<int>(
view) | (separateDirs ? KFile::SeparateDirs : 0);
981 view =
static_cast<KFile::FileView
>(m_viewKind);
994 void KDirOperator::connectView(
KFileView *view)
997 pendingMimeTypes.clear();
1001 view->setViewMode(KFileView::Directories);
1003 view->setViewMode(KFileView::All);
1005 if ( myMode & KFile::Files )
1006 view->setSelectionMode( KFile::Extended );
1008 view->setSelectionMode( KFile::Single );
1014 m_fileView->writeConfig( d->config, d->configGroup );
1015 view->readConfig( d->config, d->configGroup );
1023 if ( m_fileView->
widget()->hasFocus() )
1027 if ( oldCurrentItem ) {
1033 const KFileItemList *oldSelected = m_fileView->
selectedItems();
1034 if ( !oldSelected->isEmpty() ) {
1035 KFileItemListIterator it( *oldSelected );
1036 for ( ; it.current(); ++it )
1040 m_fileView->
widget()->hide();
1047 view->readConfig( d->config, d->configGroup );
1051 m_fileView->
widget()->installEventFilter(
this);
1052 if (m_fileView->
widget()->inherits(
"TQScrollView"))
1054 (
static_cast<TQScrollView *
>(m_fileView->
widget()))->viewport()->installEventFilter(
this);
1057 viewActionCollection = 0L;
1060 connect(sig, TQ_SIGNAL(
activatedMenu(
const KFileItem *,
const TQPoint& ) ),
1061 this, TQ_SLOT(
activatedMenu(
const KFileItem *,
const TQPoint& )));
1062 connect(sig, TQ_SIGNAL( dirActivated(
const KFileItem *) ),
1063 this, TQ_SLOT(
selectDir(
const KFileItem*) ) );
1064 connect(sig, TQ_SIGNAL( fileSelected(
const KFileItem *) ),
1065 this, TQ_SLOT(
selectFile(
const KFileItem*) ) );
1068 connect(sig, TQ_SIGNAL( sortingChanged( TQDir::SortSpec ) ),
1069 this, TQ_SLOT( slotViewSortingChanged( TQDir::SortSpec )));
1070 connect(sig, TQ_SIGNAL(
dropped(
const KFileItem *, TQDropEvent*,
const KURL::List&) ),
1071 this, TQ_SIGNAL(
dropped(
const KFileItem *, TQDropEvent*,
const KURL::List&)) );
1073 if ( reverseAction->isChecked() != m_fileView->
isReversed() )
1077 m_fileView->
widget()->resize(size());
1078 m_fileView->
widget()->show();
1081 TQApplication::setOverrideCursor( TQt::waitCursor );
1103 setView(
static_cast<KFile::FileView
>(m_viewKind) );
1108 if (
view == m_fileView ) {
1122 if ( lister == dir )
1128 dir->setAutoUpdate(
true );
1130 TQWidget* mainWidget = topLevelWidget();
1131 dir->setMainWindow (mainWidget);
1132 kdDebug (tdefile_area) <<
"mainWidget=" << mainWidget << endl;
1134 connect( dir, TQ_SIGNAL( percent(
int )),
1135 TQ_SLOT( slotProgress(
int ) ));
1136 connect( dir, TQ_SIGNAL(started(
const KURL& )), TQ_SLOT(slotStarted()));
1137 connect( dir, TQ_SIGNAL(newItems(
const KFileItemList &)),
1139 connect( dir, TQ_SIGNAL(completed()), TQ_SLOT(slotIOFinished()));
1140 connect( dir, TQ_SIGNAL(canceled()), TQ_SLOT(slotCanceled()));
1141 connect( dir, TQ_SIGNAL(deleteItem(KFileItem *)),
1143 connect( dir, TQ_SIGNAL(redirection(
const KURL& )),
1144 TQ_SLOT( slotRedirected(
const KURL& )));
1145 connect( dir, TQ_SIGNAL( clear() ), TQ_SLOT( slotClearView() ));
1146 connect( dir, TQ_SIGNAL( refreshItems(
const KFileItemList& ) ),
1147 TQ_SLOT( slotRefreshItems(
const KFileItemList& ) ) );
1152 if ( newone.isEmpty() || !m_fileView )
1155 myCompleteListDirty =
true;
1157 emit updateInformation(m_fileView->
numDirs(), m_fileView->
numFiles());
1160 KFileItemListIterator it( newone );
1162 while ( (item = it.current()) ) {
1164 if ( d->dirHighlighting && item->isDir() &&
1165 item->url().url(-1) == d->lastURL ) {
1173 TQTimer::singleShot(200,
this, TQ_SLOT(
resetCursor()));
1178 setURL(item->url(),
true);
1183 pendingMimeTypes.removeRef( item );
1186 m_fileView->
removeItem(
static_cast<KFileItem *
>( item ));
1187 emit updateInformation(m_fileView->
numDirs(), m_fileView->
numFiles());
1193 TQApplication::restoreOverrideCursor();
1195 emit fileSelected( item );
1201 const KFileItem *item = 0L;
1203 if ( !filename.isNull() )
1204 item =
static_cast<KFileItem *
>(dir->findByName( filename ));
1217 if (
string.isEmpty() ) {
1219 return TQString::null;
1223 return myCompletion.makeCompletion(
string );
1228 if (
string.isEmpty() ) {
1230 return TQString::null;
1234 return myDirCompletion.makeCompletion(
string );
1242 if ( myCompleteListDirty ) {
1243 KFileItemListIterator it( *(m_fileView->
items()) );
1244 for( ; it.current(); ++it ) {
1245 KFileItem *item = it.current();
1247 myCompletion.addItem( item->name() );
1248 if ( item->isDir() )
1249 myDirCompletion.addItem( item->name() );
1251 myCompleteListDirty =
false;
1258 emit completion( match );
1263 myActionCollection =
new TDEActionCollection( topLevelWidget(),
this,
"KDirOperator::myActionCollection" );
1265 actionMenu =
new TDEActionMenu( i18n(
"Menu"), myActionCollection,
"popupMenu" );
1266 upAction = KStdAction::up(
this, TQ_SLOT(
cdUp() ), myActionCollection,
"up" );
1267 upAction->setText( i18n(
"Parent Folder") );
1268 backAction = KStdAction::back(
this, TQ_SLOT(
back() ), myActionCollection,
"back" );
1269 forwardAction = KStdAction::forward(
this, TQ_SLOT(
forward()), myActionCollection,
"forward" );
1270 homeAction = KStdAction::home(
this, TQ_SLOT(
home() ), myActionCollection,
"home" );
1271 homeAction->setText(i18n(
"Home Folder"));
1272 reloadAction = KStdAction::redisplay(
this, TQ_SLOT(
rereadDir()), myActionCollection,
"reload" );
1273 actionSeparator =
new TDEActionSeparator( myActionCollection,
"separator" );
1274 d->viewActionSeparator =
new TDEActionSeparator( myActionCollection,
1275 "viewActionSeparator" );
1276 mkdirAction =
new TDEAction( i18n(
"New Folder..."), 0,
1277 this, TQ_SLOT(
mkdir() ), myActionCollection,
"mkdir" );
1278 TDEAction*
trash =
new TDEAction( i18n(
"Move to Trash" ),
"edittrash", Key_Delete, myActionCollection,
"trash" );
1279 connect(
trash, TQ_SIGNAL( activated( TDEAction::ActivationReason, TQt::ButtonState ) ),
1280 this, TQ_SLOT(
trashSelected( TDEAction::ActivationReason, TQt::ButtonState ) ) );
1281 new TDEAction( i18n(
"Delete" ),
"edit-delete", SHIFT+Key_Delete,
this,
1283 mkdirAction->setIcon( TQString::fromLatin1(
"folder-new") );
1284 reloadAction->setText( i18n(
"Reload") );
1285 reloadAction->setShortcut( TDEStdAccel::shortcut( TDEStdAccel::Reload ));
1289 sortActionMenu =
new TDEActionMenu( i18n(
"Sorting"), myActionCollection,
"sorting menu");
1290 byNameAction =
new TDERadioAction( i18n(
"By Name"), 0,
1291 this, TQ_SLOT( slotSortByName() ),
1292 myActionCollection,
"by name" );
1293 byDateAction =
new TDERadioAction( i18n(
"By Date"), 0,
1294 this, TQ_SLOT( slotSortByDate() ),
1295 myActionCollection,
"by date" );
1296 bySizeAction =
new TDERadioAction( i18n(
"By Size"), 0,
1297 this, TQ_SLOT( slotSortBySize() ),
1298 myActionCollection,
"by size" );
1299 reverseAction =
new TDEToggleAction( i18n(
"Reverse"), 0,
1300 this, TQ_SLOT( slotSortReversed() ),
1301 myActionCollection,
"reversed" );
1303 TQString sortGroup = TQString::fromLatin1(
"sort");
1304 byNameAction->setExclusiveGroup( sortGroup );
1305 byDateAction->setExclusiveGroup( sortGroup );
1306 bySizeAction->setExclusiveGroup( sortGroup );
1309 dirsFirstAction =
new TDEToggleAction( i18n(
"Folders First"), 0,
1310 myActionCollection,
"dirs first");
1311 caseInsensitiveAction =
new TDEToggleAction(i18n(
"Case Insensitive"), 0,
1312 myActionCollection,
"case insensitive" );
1314 connect( dirsFirstAction, TQ_SIGNAL( toggled(
bool ) ),
1315 TQ_SLOT( slotToggleDirsFirst() ));
1316 connect( caseInsensitiveAction, TQ_SIGNAL( toggled(
bool ) ),
1317 TQ_SLOT( slotToggleIgnoreCase() ));
1322 viewActionMenu =
new TDEActionMenu( i18n(
"&View"), myActionCollection,
"view menu" );
1323 connect( viewActionMenu->popupMenu(), TQ_SIGNAL( aboutToShow() ),
1324 TQ_SLOT( insertViewDependentActions() ));
1326 shortAction =
new TDERadioAction( i18n(
"Short View"),
"view_multicolumn",
1327 TDEShortcut(), myActionCollection,
"short view" );
1328 detailedAction =
new TDERadioAction( i18n(
"Detailed View"),
"view_detailed",
1329 TDEShortcut(), myActionCollection,
"detailed view" );
1331 showHiddenAction =
new TDEToggleAction( i18n(
"Show Hidden Files"), TDEShortcut(),
1332 myActionCollection,
"show hidden" );
1334 separateDirsAction =
new TDEToggleAction( i18n(
"Separate Folders"), TDEShortcut(),
1336 TQ_SLOT(slotSeparateDirs()),
1337 myActionCollection,
"separate dirs" );
1338 TDEToggleAction *previewAction =
new TDEToggleAction(i18n(
"Show Preview"),
1339 "thumbnail", TDEShortcut(),
1342 previewAction->setCheckedState(i18n(
"Hide Preview"));
1343 connect( previewAction, TQ_SIGNAL( toggled(
bool )),
1344 TQ_SLOT( togglePreview(
bool )));
1347 TQString viewGroup = TQString::fromLatin1(
"view");
1348 shortAction->setExclusiveGroup( viewGroup );
1349 detailedAction->setExclusiveGroup( viewGroup );
1351 connect( shortAction, TQ_SIGNAL( activated() ),
1352 TQ_SLOT( slotSimpleView() ));
1353 connect( detailedAction, TQ_SIGNAL( activated() ),
1354 TQ_SLOT( slotDetailedView() ));
1355 connect( showHiddenAction, TQ_SIGNAL( toggled(
bool ) ),
1356 TQ_SLOT( slotToggleHidden(
bool ) ));
1358 new TDEAction( i18n(
"Properties"), TDEShortcut(ALT+Key_Return),
this,
1359 TQ_SLOT(slotProperties()), myActionCollection,
"properties" );
1370 sortActionMenu->popupMenu()->clear();
1371 sortActionMenu->insert( byNameAction );
1372 sortActionMenu->insert( byDateAction );
1373 sortActionMenu->insert( bySizeAction );
1374 sortActionMenu->insert( actionSeparator );
1375 sortActionMenu->insert( reverseAction );
1376 sortActionMenu->insert( dirsFirstAction );
1377 sortActionMenu->insert( caseInsensitiveAction );
1380 actionMenu->popupMenu()->clear();
1381 if (whichActions & NavActions)
1383 actionMenu->insert( upAction );
1384 actionMenu->insert( backAction );
1385 actionMenu->insert( forwardAction );
1386 actionMenu->insert( homeAction );
1387 actionMenu->insert( actionSeparator );
1390 if (whichActions & FileActions)
1392 actionMenu->insert( mkdirAction );
1393 if (currUrl.isLocalFile() && !(TDEApplication::keyboardMouseState() & TQt::ShiftButton))
1394 actionMenu->insert( myActionCollection->action(
"trash" ) );
1395 TDEConfig *globalconfig = TDEGlobal::config();
1396 TDEConfigGroupSaver cs( globalconfig, TQString::fromLatin1(
"KDE") );
1397 if (!currUrl.isLocalFile() || (TDEApplication::keyboardMouseState() & TQt::ShiftButton) ||
1398 globalconfig->readBoolEntry(
"ShowDeleteCommand",
false))
1399 actionMenu->insert( myActionCollection->action(
"delete" ) );
1400 actionMenu->insert( actionSeparator );
1403 if (whichActions & SortActions)
1405 actionMenu->insert( sortActionMenu );
1406 actionMenu->insert( actionSeparator );
1409 if (whichActions & ViewActions)
1411 actionMenu->insert( viewActionMenu );
1412 actionMenu->insert( actionSeparator );
1415 if (whichActions & FileActions)
1417 actionMenu->insert( myActionCollection->action(
"properties" ) );
1423 if ( KFile::isSortByName( mySorting ) )
1424 byNameAction->setChecked(
true );
1425 else if ( KFile::isSortByDate( mySorting ) )
1426 byDateAction->setChecked(
true );
1427 else if ( KFile::isSortBySize( mySorting ) )
1428 bySizeAction->setChecked(
true );
1430 dirsFirstAction->setChecked( KFile::isSortDirsFirst( mySorting ) );
1431 caseInsensitiveAction->setChecked( KFile::isSortCaseInsensitive(mySorting) );
1432 caseInsensitiveAction->setEnabled( KFile::isSortByName( mySorting ) );
1435 reverseAction->setChecked( m_fileView->
isReversed() );
1440 KFile::FileView fv =
static_cast<KFile::FileView
>( m_viewKind );
1442 separateDirsAction->setChecked( KFile::isSeparateDirs( fv ) &&
1443 separateDirsAction->isEnabled() );
1445 shortAction->setChecked( KFile::isSimpleView( fv ));
1446 detailedAction->setChecked( KFile::isDetailView( fv ));
1453 TQString oldGroup = kc->group();
1454 if ( !group.isEmpty() )
1455 kc->setGroup( group );
1460 TQString viewStyle = kc->readEntry( TQString::fromLatin1(
"View Style"),
1461 TQString::fromLatin1(
"Simple") );
1462 if ( viewStyle == TQString::fromLatin1(
"Detail") )
1463 defaultView |= KFile::Detail;
1465 defaultView |= KFile::Simple;
1466 if ( kc->readBoolEntry( TQString::fromLatin1(
"Separate Directories"),
1467 DefaultMixDirsAndFiles ) )
1468 defaultView |= KFile::SeparateDirs;
1469 if ( kc->readBoolEntry(TQString::fromLatin1(
"Show Preview"),
false))
1470 defaultView |= KFile::PreviewContents;
1472 if ( kc->readBoolEntry( TQString::fromLatin1(
"Sort case insensitively"),
1473 DefaultCaseInsensitive ) )
1475 if ( kc->readBoolEntry( TQString::fromLatin1(
"Sort directories first"),
1476 DefaultDirsFirst ) )
1480 TQString name = TQString::fromLatin1(
"Name");
1481 TQString sortBy = kc->readEntry( TQString::fromLatin1(
"Sort by"), name );
1482 if ( sortBy == name )
1484 else if ( sortBy == TQString::fromLatin1(
"Size") )
1486 else if ( sortBy == TQString::fromLatin1(
"Date") )
1489 mySorting =
static_cast<TQDir::SortSpec
>(
sorting );
1493 if ( kc->readBoolEntry( TQString::fromLatin1(
"Show hidden files"),
1494 DefaultShowHidden ) ) {
1495 showHiddenAction->setChecked(
true );
1496 dir->setShowingDotFiles(
true );
1498 if ( kc->readBoolEntry( TQString::fromLatin1(
"Sort reversed"),
1499 DefaultSortReversed ) )
1500 reverseAction->setChecked(
true );
1502 kc->setGroup( oldGroup );
1510 const TQString oldGroup = kc->group();
1512 if ( !group.isEmpty() )
1513 kc->setGroup( group );
1515 TQString sortBy = TQString::fromLatin1(
"Name");
1516 if ( KFile::isSortBySize( mySorting ) )
1517 sortBy = TQString::fromLatin1(
"Size");
1518 else if ( KFile::isSortByDate( mySorting ) )
1519 sortBy = TQString::fromLatin1(
"Date");
1520 kc->writeEntry( TQString::fromLatin1(
"Sort by"), sortBy );
1522 kc->writeEntry( TQString::fromLatin1(
"Sort reversed"),
1523 reverseAction->isChecked() );
1524 kc->writeEntry( TQString::fromLatin1(
"Sort case insensitively"),
1525 caseInsensitiveAction->isChecked() );
1526 kc->writeEntry( TQString::fromLatin1(
"Sort directories first"),
1527 dirsFirstAction->isChecked() );
1531 bool appSpecificPreview =
false;
1533 TQWidget *preview =
const_cast<TQWidget*
>( myPreview );
1534 KFileMetaPreview *tmp =
dynamic_cast<KFileMetaPreview*
>( preview );
1535 appSpecificPreview = (tmp == 0L);
1538 if ( !appSpecificPreview ) {
1539 if ( separateDirsAction->isEnabled() )
1540 kc->writeEntry( TQString::fromLatin1(
"Separate Directories"),
1541 separateDirsAction->isChecked() );
1543 TDEToggleAction *previewAction =
static_cast<TDEToggleAction*
>(myActionCollection->action(
"preview"));
1544 if ( previewAction->isEnabled() ) {
1545 bool hasPreview = previewAction->isChecked();
1546 kc->writeEntry( TQString::fromLatin1(
"Show Preview"), hasPreview );
1550 kc->writeEntry( TQString::fromLatin1(
"Show hidden files"),
1551 showHiddenAction->isChecked() );
1553 KFile::FileView fv =
static_cast<KFile::FileView
>( m_viewKind );
1555 if ( KFile::isDetailView( fv ) )
1556 style = TQString::fromLatin1(
"Detail");
1557 else if ( KFile::isSimpleView( fv ) )
1558 style = TQString::fromLatin1(
"Simple");
1559 kc->writeEntry( TQString::fromLatin1(
"View Style"), style );
1561 kc->setGroup( oldGroup );
1565 void KDirOperator::resizeEvent( TQResizeEvent * )
1568 m_fileView->
widget()->resize( size() );
1570 if ( progress->parent() ==
this )
1571 progress->move(2, height() - progress->height() -2);
1576 d->onlyDoubleClickSelectsFiles = enable;
1583 return d->onlyDoubleClickSelectsFiles;
1586 void KDirOperator::slotStarted()
1588 progress->setProgress( 0 );
1590 d->progressDelayTimer->start( 1000,
true );
1593 void KDirOperator::slotShowProgress()
1597 TQApplication::flushX();
1600 void KDirOperator::slotProgress(
int percent )
1602 progress->setProgress( percent );
1604 if ( progress->isVisible() )
1605 TQApplication::flushX();
1609 void KDirOperator::slotIOFinished()
1611 d->progressDelayTimer->stop();
1612 slotProgress( 100 );
1614 emit finishedLoading();
1621 void KDirOperator::slotCanceled()
1623 emit finishedLoading();
1638 backAction->setEnabled(
false );
1639 forwardStack.clear();
1640 forwardAction->setEnabled(
false );
1643 void KDirOperator::slotViewActionAdded( TDEAction *action )
1645 if ( viewActionMenu->popupMenu()->count() == 5 )
1646 viewActionMenu->insert( d->viewActionSeparator );
1648 viewActionMenu->insert( action );
1651 void KDirOperator::slotViewActionRemoved( TDEAction *action )
1653 viewActionMenu->remove( action );
1655 if ( viewActionMenu->popupMenu()->count() == 6 )
1656 viewActionMenu->remove( d->viewActionSeparator );
1659 void KDirOperator::slotViewSortingChanged( TQDir::SortSpec sort )
1667 d->dirHighlighting = enable;
1672 return d->dirHighlighting;
1675 void KDirOperator::slotProperties()
1679 if ( !list->isEmpty() )
1684 void KDirOperator::slotClearView()
1692 bool KDirOperator::isReadable(
const KURL& url )
1694 if ( !
url.isLocalFile() )
1697 KDE_struct_stat buf;
1698 TQString ts =
url.path(+1);
1699 bool readable = ( KDE_stat( TQFile::encodeName( ts ), &buf) == 0 );
1702 test = opendir( TQFile::encodeName( ts ));
1703 readable = (test != 0);
1710 void KDirOperator::togglePreview(
bool on )
1713 slotDefaultPreview();
1715 setView( (KFile::FileView) (m_viewKind & ~(KFile::PreviewContents|KFile::PreviewInfo)) );
1718 void KDirOperator::slotRefreshItems(
const KFileItemList& items )
1723 KFileItemListIterator it( items );
1724 for ( ; it.current(); ++it )
1731 d->configGroup = group;
1741 return d->configGroup;
1744 bool KDirOperator::eventFilter(TQObject *obj, TQEvent *ev)
1746 if (ev->type() == TQEvent::MouseButtonRelease)
1748 TQMouseEvent *mouseEv =
static_cast<TQMouseEvent *
>(ev);
1749 switch (mouseEv->button())
1751 case TQMouseEvent::HistoryBackButton:
1754 case TQMouseEvent::HistoryForwardButton:
1762 void KDirOperator::virtual_hook(
int,
void* )
1765 #include "tdediroperator.moc"