1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2006 by Stefan Monov <logixoul@gmail.com> *
4 * Copyright (C) 2006 by Cvetoslav Ludmiloff <ludmiloff@gmail.com> *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
22 #include "dolphinmainwindow.h"
26 #include <kactioncollection.h>
27 #include <ktoggleaction.h>
28 #include <kbookmarkmanager.h>
30 #include <kpropertiesdialog.h>
32 #include <kiconloader.h>
33 #include <kdeversion.h>
34 #include <kstatusbar.h>
35 #include <kio/netaccess.h>
36 #include <kfiledialog.h>
39 #include <kstdaccel.h>
41 #include <kstdaction.h>
43 #include <kio/renamedlg.h>
44 #include <kinputdialog.h>
46 #include <kdesktopfile.h>
47 #include <kstandarddirs.h>
48 #include <kprotocolinfo.h>
49 #include <kmessagebox.h>
51 #include <kstandarddirs.h>
55 #include <qclipboard.h>
56 #include <q3dragobject.h>
58 #include <Q3ValueList>
59 #include <QCloseEvent>
61 #include <QDockWidget>
63 #include "urlnavigator.h"
64 #include "viewpropertiesdialog.h"
65 #include "viewproperties.h"
66 #include "dolphinsettings.h"
67 #include "dolphinsettingsdialog.h"
68 #include "dolphinstatusbar.h"
69 #include "dolphinapplication.h"
70 #include "undomanager.h"
71 #include "progressindicator.h"
72 #include "dolphinsettings.h"
73 #include "bookmarkssidebarpage.h"
74 #include "infosidebarpage.h"
75 #include "generalsettings.h"
76 #include "dolphinapplication.h"
79 DolphinMainWindow::DolphinMainWindow() :
83 m_clipboardContainsCutData(false)
85 setObjectName("Dolphin");
86 m_view
[PrimaryIdx
] = 0;
87 m_view
[SecondaryIdx
] = 0;
89 // TODO: the following members are not used yet. See documentation
90 // of DolphinMainWindow::linkGroupActions() and DolphinMainWindow::linkToDeviceActions()
91 // in the header file for details.
94 DolphinMainWindow::~DolphinMainWindow()
96 qDeleteAll(m_fileGroupActions
);
97 //qDeleteAll(m_linkToDeviceActions);
98 //qDeleteAll(m_linkGroupActions);
99 m_fileGroupActions
.clear();
100 //m_linkGroupActions.clear();
101 //m_linkToDeviceActions.clear();
104 * bye, bye managed window
106 DolphinApplication::app()->removeMainWindow( this );
109 void DolphinMainWindow::setActiveView(DolphinView
* view
)
111 assert((view
== m_view
[PrimaryIdx
]) || (view
== m_view
[SecondaryIdx
]));
112 if (m_activeView
== view
) {
123 setCaption(m_activeView
->url().fileName());
125 emit
activeViewChanged();
128 void DolphinMainWindow::dropUrls(const KUrl::List
& urls
,
129 const KUrl
& destination
)
131 int selectedIndex
= -1;
134 const ButtonState keyboardState = KApplication::keyboardMouseState();
135 const bool shiftPressed = (keyboardState & ShiftButton) > 0;
136 const bool controlPressed = (keyboardState & ControlButton) > 0;
140 if (shiftPressed && controlPressed) {
141 // shortcut for 'Linke Here' is used
144 else if (controlPressed) {
145 // shortcut for 'Copy Here' is used
148 else if (shiftPressed) {
149 // shortcut for 'Move Here' is used
153 // no shortcut is used, hence open a popup menu
156 popup
.insertItem(SmallIcon("goto"), i18n("&Move Here") + "\t" /* KDE4-TODO: + KKey::modFlagLabel(KKey::SHIFT)*/, 0);
157 popup
.insertItem(SmallIcon("editcopy"), i18n( "&Copy Here" ) /* KDE4-TODO + "\t" + KKey::modFlagLabel(KKey::CTRL)*/, 1);
158 popup
.insertItem(i18n("&Link Here") /* KDE4-TODO + "\t" + KKey::modFlagLabel((KKey::ModFlag)(KKey::CTRL|KKey::SHIFT)) */, 2);
159 popup
.insertSeparator();
160 popup
.insertItem(SmallIcon("stop"), i18n("Cancel"), 3);
161 popup
.setAccel(i18n("Escape"), 3);
163 /* KDE4-TODO: selectedIndex = popup.exec(QCursor::pos()); */
164 popup
.exec(QCursor::pos());
165 selectedIndex
= 0; // KD4-TODO: use QAction instead of switch below
166 // See libkonq/konq_operations.cc: KonqOperations::doDropFileCopy() (and doDrop, the main method)
169 if (selectedIndex
< 0) {
173 switch (selectedIndex
) {
175 // 'Move Here' has been selected
176 updateViewProperties(urls
);
177 moveUrls(urls
, destination
);
182 // 'Copy Here' has been selected
183 updateViewProperties(urls
);
184 copyUrls(urls
, destination
);
189 // 'Link Here' has been selected
190 KIO::Job
* job
= KIO::link(urls
, destination
);
191 addPendingUndoJob(job
, DolphinCommand::Link
, urls
, destination
);
196 // 'Cancel' has been selected
201 void DolphinMainWindow::refreshViews()
203 const bool split
= DolphinSettings::instance().generalSettings()->splitView();
204 const bool isPrimaryViewActive
= (m_activeView
== m_view
[PrimaryIdx
]);
206 for (int i
= PrimaryIdx
; i
<= SecondaryIdx
; ++i
) {
207 if (m_view
[i
] != 0) {
208 url
= m_view
[i
]->url();
210 // delete view instance...
212 m_view
[i
]->deleteLater();
216 if (split
|| (i
== PrimaryIdx
)) {
217 // ... and recreate it
218 ViewProperties
props(url
);
219 m_view
[i
] = new DolphinView(this,
223 props
.showHiddenFiles());
224 connectViewSignals(i
);
229 m_activeView
= isPrimaryViewActive
? m_view
[PrimaryIdx
] : m_view
[SecondaryIdx
];
230 assert(m_activeView
!= 0);
233 emit
activeViewChanged();
236 void DolphinMainWindow::slotViewModeChanged()
241 void DolphinMainWindow::slotShowHiddenFilesChanged()
243 KToggleAction
* showHiddenFilesAction
=
244 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
245 showHiddenFilesAction
->setChecked(m_activeView
->showHiddenFiles());
248 void DolphinMainWindow::slotSortingChanged(DolphinView::Sorting sorting
)
252 case DolphinView::SortByName
:
253 action
= actionCollection()->action("by_name");
255 case DolphinView::SortBySize
:
256 action
= actionCollection()->action("by_size");
258 case DolphinView::SortByDate
:
259 action
= actionCollection()->action("by_date");
266 KToggleAction
* toggleAction
= static_cast<KToggleAction
*>(action
);
267 toggleAction
->setChecked(true);
271 void DolphinMainWindow::slotSortOrderChanged(Qt::SortOrder order
)
273 KToggleAction
* descending
= static_cast<KToggleAction
*>(actionCollection()->action("descending"));
274 const bool sortDescending
= (order
== Qt::Descending
);
275 descending
->setChecked(sortDescending
);
278 void DolphinMainWindow::slotSelectionChanged()
282 assert(m_view
[PrimaryIdx
] != 0);
283 int selectedUrlsCount
= m_view
[PrimaryIdx
]->selectedUrls().count();
284 if (m_view
[SecondaryIdx
] != 0) {
285 selectedUrlsCount
+= m_view
[SecondaryIdx
]->selectedUrls().count();
288 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
289 compareFilesAction
->setEnabled(selectedUrlsCount
== 2);
291 m_activeView
->updateStatusBar();
293 emit
selectionChanged();
296 void DolphinMainWindow::slotHistoryChanged()
301 void DolphinMainWindow::slotUrlChanged(const KUrl
& url
)
305 setCaption(url
.fileName());
308 void DolphinMainWindow::updateFilterBarAction(bool show
)
310 KToggleAction
* showFilterBarAction
=
311 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
312 showFilterBarAction
->setChecked(show
);
315 void DolphinMainWindow::redo()
317 UndoManager::instance().redo(this);
320 void DolphinMainWindow::undo()
322 UndoManager::instance().undo(this);
325 void DolphinMainWindow::openNewMainWindow()
327 DolphinApplication::app()->createMainWindow()->show();
330 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
333 //KConfig* config = KGlobal::config();
334 //config->setGroup("General");
335 //config->writeEntry("First Run", false);
337 DolphinSettings
& settings
= DolphinSettings::instance();
338 GeneralSettings
* generalSettings
= settings
.generalSettings();
339 generalSettings
->setFirstRun(false);
343 KMainWindow::closeEvent(event
);
346 void DolphinMainWindow::saveProperties(KConfig
* config
)
348 config
->setGroup("Primary view");
349 config
->writeEntry("Url", m_view
[PrimaryIdx
]->url().url());
350 config
->writeEntry("Editable Url", m_view
[PrimaryIdx
]->isUrlEditable());
351 if (m_view
[SecondaryIdx
] != 0) {
352 config
->setGroup("Secondary view");
353 config
->writeEntry("Url", m_view
[SecondaryIdx
]->url().url());
354 config
->writeEntry("Editable Url", m_view
[SecondaryIdx
]->isUrlEditable());
358 void DolphinMainWindow::readProperties(KConfig
* config
)
360 config
->setGroup("Primary view");
361 m_view
[PrimaryIdx
]->setUrl(config
->readEntry("Url"));
362 m_view
[PrimaryIdx
]->setUrlEditable(config
->readEntry("Editable Url", false));
363 if (config
->hasGroup("Secondary view")) {
364 config
->setGroup("Secondary view");
365 if (m_view
[SecondaryIdx
] == 0) {
368 m_view
[SecondaryIdx
]->setUrl(config
->readEntry("Url"));
369 m_view
[SecondaryIdx
]->setUrlEditable(config
->readEntry("Editable Url", false));
371 else if (m_view
[SecondaryIdx
] != 0) {
376 void DolphinMainWindow::createFolder()
378 // Parts of the following code have been taken
379 // from the class KonqPopupMenu located in
380 // libqonq/konq_popupmenu.h of Konqueror.
381 // (Copyright (C) 2000 David Faure <faure@kde.org>,
382 // Copyright (C) 2001 Holger Freyther <freyther@yahoo.com>)
386 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
387 const KUrl
baseUrl(m_activeView
->url());
389 QString
name(i18n("New Folder"));
390 baseUrl
.path(KUrl::AddTrailingSlash
);
393 if (baseUrl
.isLocalFile() && QFileInfo(baseUrl
.path(KUrl::AddTrailingSlash
) + name
).exists()) {
394 name
= KIO::RenameDlg::suggestName(baseUrl
, i18n("New Folder"));
398 name
= KInputDialog::getText(i18n("New Folder"),
399 i18n("Enter folder name:" ),
405 // the user has pressed 'Cancel'
409 assert(!name
.isEmpty());
412 if ((name
[0] == '/') || (name
[0] == '~')) {
413 url
.setPath(KShell::tildeExpand(name
));
416 name
= KIO::encodeFileName(name
);
420 ok
= KIO::NetAccess::mkdir(url
, this);
422 // TODO: provide message type hint
424 statusBar
->setMessage(i18n("Created folder %1.",url
.path()),
425 DolphinStatusBar::OperationCompleted
);
427 DolphinCommand
command(DolphinCommand::CreateFolder
, KUrl::List(), url
);
428 UndoManager::instance().addCommand(command
);
431 // Creating of the folder has been failed. Check whether the creating
432 // has been failed because a folder with the same name exists...
433 if (KIO::NetAccess::exists(url
, true, this)) {
434 statusBar
->setMessage(i18n("A folder named %1 already exists.",url
.path()),
435 DolphinStatusBar::Error
);
438 statusBar
->setMessage(i18n("Creating of folder %1 failed.",url
.path()),
439 DolphinStatusBar::Error
);
445 void DolphinMainWindow::createFile()
447 // Parts of the following code have been taken
448 // from the class KonqPopupMenu located in
449 // libqonq/konq_popupmenu.h of Konqueror.
450 // (Copyright (C) 2000 David Faure <faure@kde.org>,
451 // Copyright (C) 2001 Holger Freyther <freyther@yahoo.com>)
455 // TODO: const Entry& entry = m_createFileTemplates[QString(sender->name())];
456 // should be enough. Anyway: the implemantation of [] does a linear search internally too.
457 KSortableList
<CreateFileEntry
, QString
>::ConstIterator it
= m_createFileTemplates
.begin();
458 KSortableList
<CreateFileEntry
, QString
>::ConstIterator end
= m_createFileTemplates
.end();
460 const QString
senderName(sender()->objectName());
462 CreateFileEntry entry
;
463 while (!found
&& (it
!= end
)) {
464 if ((*it
).key() == senderName
) {
465 entry
= (*it
).value();
473 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
474 if (!found
|| !QFile::exists(entry
.templatePath
)) {
475 statusBar
->setMessage(i18n("Could not create file."), DolphinStatusBar::Error
);
479 // Get the source path of the template which should be copied.
480 // The source path is part of the Url entry of the desktop file.
481 const int pos
= entry
.templatePath
.lastIndexOf('/');
482 QString
sourcePath(entry
.templatePath
.left(pos
+ 1));
483 sourcePath
+= KDesktopFile(entry
.templatePath
, true).readPathEntry("Url");
485 QString
name(i18n(entry
.name
.toAscii()));
486 // Most entry names end with "..." (e. g. "HTML File..."), which is ok for
487 // menus but no good choice for a new file name -> remove the dots...
488 name
.replace("...", QString::null
);
490 // add the file extension to the name
491 name
.append(sourcePath
.right(sourcePath
.length() - sourcePath
.lastIndexOf('.')));
493 // Check whether a file with the current name already exists. If yes suggest automatically
494 // a unique file name (e. g. "HTML File" will be replaced by "HTML File_1").
495 const KUrl
viewUrl(m_activeView
->url());
496 const bool fileExists
= viewUrl
.isLocalFile() &&
497 QFileInfo(viewUrl
.path(KUrl::AddTrailingSlash
) + KIO::encodeFileName(name
)).exists();
499 name
= KIO::RenameDlg::suggestName(viewUrl
, name
);
502 // let the user change the suggested file name
504 name
= KInputDialog::getText(entry
.name
,
510 // the user has pressed 'Cancel'
514 // before copying the template to the destination path check whether a file
515 // with the given name already exists
516 const QString
destPath(viewUrl
.pathOrUrl() + "/" + KIO::encodeFileName(name
));
517 const KUrl
destUrl(destPath
);
518 if (KIO::NetAccess::exists(destUrl
, false, this)) {
519 statusBar
->setMessage(i18n("A file named %1 already exists.",name
),
520 DolphinStatusBar::Error
);
524 // copy the template to the destination path
525 const KUrl
sourceUrl(sourcePath
);
526 KIO::CopyJob
* job
= KIO::copyAs(sourceUrl
, destUrl
);
527 job
->setDefaultPermissions(true);
528 if (KIO::NetAccess::synchronousRun(job
, this)) {
529 statusBar
->setMessage(i18n("Created file %1.",name
),
530 DolphinStatusBar::OperationCompleted
);
533 list
.append(sourceUrl
);
534 DolphinCommand
command(DolphinCommand::CreateFile
, list
, destUrl
);
535 UndoManager::instance().addCommand(command
);
539 statusBar
->setMessage(i18n("Creating of file %1 failed.",name
),
540 DolphinStatusBar::Error
);
544 void DolphinMainWindow::rename()
547 m_activeView
->renameSelectedItems();
550 void DolphinMainWindow::moveToTrash()
553 KUrl::List selectedUrls
= m_activeView
->selectedUrls();
554 KIO::Job
* job
= KIO::trash(selectedUrls
);
555 addPendingUndoJob(job
, DolphinCommand::Trash
, selectedUrls
, m_activeView
->url());
558 void DolphinMainWindow::deleteItems()
562 KUrl::List list
= m_activeView
->selectedUrls();
563 const uint itemCount
= list
.count();
564 assert(itemCount
>= 1);
568 text
= i18n("Do you really want to delete the %1 selected items?",itemCount
);
571 const KUrl
& url
= list
.first();
572 text
= i18n("Do you really want to delete '%1'?",url
.fileName());
575 const bool del
= KMessageBox::warningContinueCancel(this,
578 KGuiItem(i18n("Delete"), SmallIcon("editdelete"))
579 ) == KMessageBox::Continue
;
581 KIO::Job
* job
= KIO::del(list
);
582 connect(job
, SIGNAL(result(KJob
*)),
583 this, SLOT(slotHandleJobError(KJob
*)));
584 connect(job
, SIGNAL(result(KJob
*)),
585 this, SLOT(slotDeleteFileFinished(KJob
*)));
589 void DolphinMainWindow::properties()
591 const KFileItemList list
= m_activeView
->selectedItems();
592 new KPropertiesDialog(list
, this);
595 void DolphinMainWindow::quit()
600 void DolphinMainWindow::slotHandleJobError(KJob
* job
)
602 if (job
->error() != 0) {
603 m_activeView
->statusBar()->setMessage(job
->errorString(),
604 DolphinStatusBar::Error
);
608 void DolphinMainWindow::slotDeleteFileFinished(KJob
* job
)
610 if (job
->error() == 0) {
611 m_activeView
->statusBar()->setMessage(i18n("Delete operation completed."),
612 DolphinStatusBar::OperationCompleted
);
614 // TODO: In opposite to the 'Move to Trash' operation in the class KFileIconView
615 // no rearranging of the item position is done when a file has been deleted.
616 // This is bypassed by reloading the view, but it might be worth to investigate
617 // deeper for the root of this issue.
618 m_activeView
->reload();
622 void DolphinMainWindow::slotUndoAvailable(bool available
)
624 QAction
* undoAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Undo
));
625 if (undoAction
!= 0) {
626 undoAction
->setEnabled(available
);
630 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
632 QAction
* undoAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Undo
));
633 if (undoAction
!= 0) {
634 undoAction
->setText(text
);
638 void DolphinMainWindow::slotRedoAvailable(bool available
)
640 QAction
* redoAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Redo
));
641 if (redoAction
!= 0) {
642 redoAction
->setEnabled(available
);
646 void DolphinMainWindow::slotRedoTextChanged(const QString
& text
)
648 QAction
* redoAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Redo
));
649 if (redoAction
!= 0) {
650 redoAction
->setText(text
);
654 void DolphinMainWindow::cut()
656 // TODO: this boolean doesn't work between instances of dolphin or with konqueror or with other
657 // apps. The "application/x-kde-cutselection" mimetype should be used instead, see KonqMimeData
659 m_clipboardContainsCutData
= true;
661 QMimeData
* mimeData
= new QMimeData();
662 const KUrl::List selectedUrls
= m_activeView
->selectedUrls();
663 selectedUrls
.populateMimeData(mimeData
);
665 QApplication::clipboard()->setMimeData(mimeData
);
668 void DolphinMainWindow::copy()
670 m_clipboardContainsCutData
= false;
672 QMimeData
* mimeData
= new QMimeData();
673 const KUrl::List selectedUrls
= m_activeView
->selectedUrls();
674 selectedUrls
.populateMimeData(mimeData
);
676 QApplication::clipboard()->setMimeData(mimeData
);
679 void DolphinMainWindow::paste()
681 QClipboard
* clipboard
= QApplication::clipboard();
682 const QMimeData
* mimeData
= clipboard
->mimeData();
686 const KUrl::List sourceUrls
= KUrl::List::fromMimeData(mimeData
);
688 // per default the pasting is done into the current Url of the view
689 KUrl
destUrl(m_activeView
->url());
691 // check whether the pasting should be done into a selected directory
692 KUrl::List selectedUrls
= m_activeView
->selectedUrls();
693 if (selectedUrls
.count() == 1) {
694 const KFileItem
fileItem(S_IFDIR
,
696 selectedUrls
.first(),
698 if (fileItem
.isDir()) {
699 // only one item is selected which is a directory, hence paste
700 // into this directory
701 destUrl
= selectedUrls
.first();
705 // TODO #1: use libkonq commands (see doPaste() implementation
706 // KIO::Job* job = KIO::pasteClipboard(destUrl, this, false);
708 // TODO #2: this boolean doesn't work between instances of dolphin or with konqueror or with other
709 // apps. The "application/x-kde-cutselection" mimetype should be used instead, see KonqMimeData
711 if (m_clipboardContainsCutData
) {
712 moveUrls(sourceUrls
, destUrl
);
713 m_clipboardContainsCutData
= false;
717 copyUrls(sourceUrls
, destUrl
);
721 void DolphinMainWindow::updatePasteAction()
723 QAction
* pasteAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Paste
));
724 if (pasteAction
== 0) {
728 QString
text(i18n("Paste"));
729 QClipboard
* clipboard
= QApplication::clipboard();
730 const QMimeData
* mimeData
= clipboard
->mimeData();
732 KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
733 if (!urls
.isEmpty()) {
734 pasteAction
->setEnabled(true);
736 const int count
= urls
.count();
738 pasteAction
->setText(i18n("Paste 1 File"));
741 pasteAction
->setText(i18n("Paste %1 Files").arg(count
));
745 pasteAction
->setEnabled(false);
746 pasteAction
->setText(i18n("Paste"));
749 if (pasteAction
->isEnabled()) {
750 KUrl::List urls
= m_activeView
->selectedUrls();
751 const uint count
= urls
.count();
753 // pasting should not be allowed when more than one file
755 pasteAction
->setEnabled(false);
757 else if (count
== 1) {
758 // Only one file is selected. Pasting is only allowed if this
759 // file is a directory.
760 // TODO: this doesn't work with remote protocols; instead we need a
761 // m_activeView->selectedFileItems() to get the real KFileItems
762 const KFileItem
fileItem(S_IFDIR
,
766 pasteAction
->setEnabled(fileItem
.isDir());
771 void DolphinMainWindow::selectAll()
774 m_activeView
->selectAll();
777 void DolphinMainWindow::invertSelection()
780 m_activeView
->invertSelection();
782 void DolphinMainWindow::setIconsView()
784 m_activeView
->setMode(DolphinView::IconsView
);
787 void DolphinMainWindow::setDetailsView()
789 m_activeView
->setMode(DolphinView::DetailsView
);
792 void DolphinMainWindow::sortByName()
794 m_activeView
->setSorting(DolphinView::SortByName
);
797 void DolphinMainWindow::sortBySize()
799 m_activeView
->setSorting(DolphinView::SortBySize
);
802 void DolphinMainWindow::sortByDate()
804 m_activeView
->setSorting(DolphinView::SortByDate
);
807 void DolphinMainWindow::toggleSortOrder()
809 const Qt::SortOrder order
= (m_activeView
->sortOrder() == Qt::Ascending
) ?
812 m_activeView
->setSortOrder(order
);
815 void DolphinMainWindow::toggleSplitView()
817 if (m_view
[SecondaryIdx
] == 0) {
818 const int newWidth
= (m_view
[PrimaryIdx
]->width() - m_splitter
->handleWidth()) / 2;
819 // create a secondary view
820 m_view
[SecondaryIdx
] = new DolphinView(this,
822 m_view
[PrimaryIdx
]->url(),
823 m_view
[PrimaryIdx
]->mode(),
824 m_view
[PrimaryIdx
]->showHiddenFiles());
825 connectViewSignals(SecondaryIdx
);
826 m_splitter
->addWidget(m_view
[SecondaryIdx
]);
827 m_splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
828 m_view
[SecondaryIdx
]->show();
831 // remove secondary view
832 if (m_activeView
== m_view
[PrimaryIdx
]) {
833 m_view
[SecondaryIdx
]->close();
834 m_view
[SecondaryIdx
]->deleteLater();
835 m_view
[SecondaryIdx
] = 0;
836 setActiveView(m_view
[PrimaryIdx
]);
839 // The secondary view is active, hence from the users point of view
840 // the content of the secondary view should be moved to the primary view.
841 // From an implementation point of view it is more efficient to close
842 // the primary view and exchange the internal pointers afterwards.
843 m_view
[PrimaryIdx
]->close();
844 delete m_view
[PrimaryIdx
];
845 m_view
[PrimaryIdx
] = m_view
[SecondaryIdx
];
846 m_view
[SecondaryIdx
] = 0;
847 setActiveView(m_view
[PrimaryIdx
]);
852 void DolphinMainWindow::reloadView()
855 m_activeView
->reload();
858 void DolphinMainWindow::stopLoading()
862 void DolphinMainWindow::togglePreview()
866 void DolphinMainWindow::toggleShowHiddenFiles()
870 const KToggleAction
* showHiddenFilesAction
=
871 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
872 const bool show
= showHiddenFilesAction
->isChecked();
873 m_activeView
->setShowHiddenFiles(show
);
876 void DolphinMainWindow::showFilterBar()
878 const KToggleAction
* showFilterBarAction
=
879 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
880 const bool show
= showFilterBarAction
->isChecked();
881 m_activeView
->slotShowFilterBar(show
);
884 void DolphinMainWindow::zoomIn()
886 m_activeView
->zoomIn();
890 void DolphinMainWindow::zoomOut()
892 m_activeView
->zoomOut();
896 void DolphinMainWindow::toggleEditLocation()
900 KToggleAction
* action
= static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
902 bool editOrBrowse
= action
->isChecked();
903 // action->setChecked(action->setChecked);
904 m_activeView
->setUrlEditable(editOrBrowse
);
907 void DolphinMainWindow::editLocation()
909 KToggleAction
* action
= static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
910 action
->setChecked(true);
911 m_activeView
->setUrlEditable(true);
914 void DolphinMainWindow::adjustViewProperties()
917 ViewPropertiesDialog
dlg(m_activeView
);
921 void DolphinMainWindow::goBack()
924 m_activeView
->goBack();
927 void DolphinMainWindow::goForward()
930 m_activeView
->goForward();
933 void DolphinMainWindow::goUp()
936 m_activeView
->goUp();
939 void DolphinMainWindow::goHome()
942 m_activeView
->goHome();
945 void DolphinMainWindow::openTerminal()
947 QString
command("konsole --workdir \"");
948 command
.append(m_activeView
->url().path());
949 command
.append('\"');
951 KRun::runCommand(command
, "Konsole", "konsole");
954 void DolphinMainWindow::findFile()
956 KRun::run("kfind", m_activeView
->url());
959 void DolphinMainWindow::compareFiles()
961 // The method is only invoked if exactly 2 files have
962 // been selected. The selected files may be:
963 // - both in the primary view
964 // - both in the secondary view
965 // - one in the primary view and the other in the secondary
967 assert(m_view
[PrimaryIdx
] != 0);
971 KUrl::List urls
= m_view
[PrimaryIdx
]->selectedUrls();
973 switch (urls
.count()) {
975 assert(m_view
[SecondaryIdx
] != 0);
976 urls
= m_view
[SecondaryIdx
]->selectedUrls();
977 assert(urls
.count() == 2);
985 assert(m_view
[SecondaryIdx
] != 0);
986 urls
= m_view
[SecondaryIdx
]->selectedUrls();
987 assert(urls
.count() == 1);
999 // may not happen: compareFiles may only get invoked if 2
1000 // files are selected
1005 QString
command("kompare -c \"");
1006 command
.append(urlA
.pathOrUrl());
1007 command
.append("\" \"");
1008 command
.append(urlB
.pathOrUrl());
1009 command
.append('\"');
1010 KRun::runCommand(command
, "Kompare", "kompare");
1014 void DolphinMainWindow::editSettings()
1016 // TODO: make a static method for opening the settings dialog
1017 DolphinSettingsDialog
dlg(this);
1021 void DolphinMainWindow::addUndoOperation(KJob
* job
)
1023 if (job
->error() != 0) {
1024 slotHandleJobError(job
);
1027 const int id
= job
->progressId();
1029 // set iterator to the executed command with the current id...
1030 Q3ValueList
<UndoInfo
>::Iterator it
= m_pendingUndoJobs
.begin();
1031 const Q3ValueList
<UndoInfo
>::Iterator end
= m_pendingUndoJobs
.end();
1033 while (!found
&& (it
!= end
)) {
1034 if ((*it
).id
== id
) {
1043 DolphinCommand command
= (*it
).command
;
1044 if (command
.type() == DolphinCommand::Trash
) {
1045 // To be able to perform an undo for the 'Move to Trash' operation
1046 // all source Urls must be updated with the trash Url. E. g. when moving
1047 // a file "test.txt" and a second file "test.txt" to the trash,
1048 // then the filenames in the trash are "0-test.txt" and "1-test.txt".
1049 QMap
<QString
, QString
> metaData
;
1050 KIO::Job
*kiojob
= qobject_cast
<KIO::Job
*>( job
);
1053 metaData
= kiojob
->metaData();
1055 KUrl::List newSourceUrls
;
1057 KUrl::List sourceUrls
= command
.source();
1058 KUrl::List::Iterator sourceIt
= sourceUrls
.begin();
1059 const KUrl::List::Iterator sourceEnd
= sourceUrls
.end();
1061 while (sourceIt
!= sourceEnd
) {
1062 QMap
<QString
, QString
>::ConstIterator metaIt
= metaData
.find("trashUrl-" + (*sourceIt
).path());
1063 if (metaIt
!= metaData
.end()) {
1064 newSourceUrls
.append(KUrl(metaIt
.value()));
1068 command
.setSource(newSourceUrls
);
1071 UndoManager::instance().addCommand(command
);
1072 m_pendingUndoJobs
.erase(it
);
1074 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
1075 switch (command
.type()) {
1076 case DolphinCommand::Copy
:
1077 statusBar
->setMessage(i18n("Copy operation completed."),
1078 DolphinStatusBar::OperationCompleted
);
1080 case DolphinCommand::Move
:
1081 statusBar
->setMessage(i18n("Move operation completed."),
1082 DolphinStatusBar::OperationCompleted
);
1084 case DolphinCommand::Trash
:
1085 statusBar
->setMessage(i18n("Move to trash operation completed."),
1086 DolphinStatusBar::OperationCompleted
);
1095 void DolphinMainWindow::init()
1097 // Check whether Dolphin runs the first time. If yes then
1098 // a proper default window size is given at the end of DolphinMainWindow::init().
1099 GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
1100 const bool firstRun
= generalSettings
->firstRun();
1102 setAcceptDrops(true);
1104 m_splitter
= new QSplitter(this);
1106 DolphinSettings
& settings
= DolphinSettings::instance();
1108 KBookmarkManager
* manager
= settings
.bookmarkManager();
1109 assert(manager
!= 0);
1110 KBookmarkGroup root
= manager
->root();
1111 if (root
.first().isNull()) {
1112 root
.addBookmark(manager
, i18n("Home"), settings
.generalSettings()->homeUrl(), "folder_home");
1113 root
.addBookmark(manager
, i18n("Storage Media"), KUrl("media:/"), "blockdevice");
1114 root
.addBookmark(manager
, i18n("Network"), KUrl("remote:/"), "network_local");
1115 root
.addBookmark(manager
, i18n("Root"), KUrl("/"), "folder_red");
1116 root
.addBookmark(manager
, i18n("Trash"), KUrl("trash:/"), "trashcan_full");
1121 const KUrl
& homeUrl
= root
.first().url();
1122 setCaption(homeUrl
.fileName());
1123 ViewProperties
props(homeUrl
);
1124 m_view
[PrimaryIdx
] = new DolphinView(this,
1128 props
.showHiddenFiles());
1129 connectViewSignals(PrimaryIdx
);
1130 m_view
[PrimaryIdx
]->show();
1132 m_activeView
= m_view
[PrimaryIdx
];
1134 setCentralWidget(m_splitter
);
1137 setupGUI(Keys
|Save
|Create
|ToolBar
);
1140 stateChanged("new_file");
1141 setAutoSaveSettings();
1143 QClipboard
* clipboard
= QApplication::clipboard();
1144 connect(clipboard
, SIGNAL(dataChanged()),
1145 this, SLOT(updatePasteAction()));
1146 updatePasteAction();
1149 setupCreateNewMenuActions();
1154 // assure a proper default size if Dolphin runs the first time
1159 void DolphinMainWindow::loadSettings()
1161 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
1163 KToggleAction
* splitAction
= static_cast<KToggleAction
*>(actionCollection()->action("split_view"));
1164 if (settings
->splitView()) {
1165 splitAction
->setChecked(true);
1169 updateViewActions();
1172 void DolphinMainWindow::setupActions()
1174 // setup 'File' menu
1175 KAction
*action
= new KAction(KIcon("window_new"), i18n( "New &Window" ), actionCollection(), "new_window" );
1176 connect(action
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1178 KAction
* createFolder
= new KAction(i18n("Folder..."), actionCollection(), "create_folder");
1179 createFolder
->setIcon(KIcon("folder"));
1180 createFolder
->setShortcut(Qt::Key_N
);
1181 connect(createFolder
, SIGNAL(triggered()), this, SLOT(createFolder()));
1183 KAction
* rename
= new KAction(i18n("Rename"), actionCollection(), "rename");
1184 rename
->setShortcut(Qt::Key_F2
);
1185 connect(rename
, SIGNAL(triggered()), this, SLOT(rename()));
1187 KAction
* moveToTrash
= new KAction(i18n("Move to Trash"), actionCollection(), "move_to_trash");
1188 moveToTrash
->setIcon(KIcon("edittrash"));
1189 moveToTrash
->setShortcut(QKeySequence::Delete
);
1190 connect(moveToTrash
, SIGNAL(triggered()), this, SLOT(moveToTrash()));
1192 KAction
* deleteAction
= new KAction(i18n("Delete"), actionCollection(), "delete");
1193 deleteAction
->setShortcut(Qt::ALT
| Qt::Key_Delete
);
1194 deleteAction
->setIcon(KIcon("editdelete"));
1195 connect(deleteAction
, SIGNAL(triggered()), this, SLOT(deleteItems()));
1197 KAction
* properties
= new KAction(i18n("Propert&ies"), actionCollection(), "properties");
1198 properties
->setShortcut(Qt::Key_Alt
| Qt::Key_Return
);
1199 connect(properties
, SIGNAL(triggered()), this, SLOT(properties()));
1201 KStdAction::quit(this, SLOT(quit()), actionCollection());
1203 // setup 'Edit' menu
1204 UndoManager
& undoManager
= UndoManager::instance();
1205 KStdAction::undo(this,
1207 actionCollection());
1208 connect(&undoManager
, SIGNAL(undoAvailable(bool)),
1209 this, SLOT(slotUndoAvailable(bool)));
1210 connect(&undoManager
, SIGNAL(undoTextChanged(const QString
&)),
1211 this, SLOT(slotUndoTextChanged(const QString
&)));
1213 KStdAction::redo(this,
1215 actionCollection());
1216 connect(&undoManager
, SIGNAL(redoAvailable(bool)),
1217 this, SLOT(slotRedoAvailable(bool)));
1218 connect(&undoManager
, SIGNAL(redoTextChanged(const QString
&)),
1219 this, SLOT(slotRedoTextChanged(const QString
&)));
1221 KStdAction::cut(this, SLOT(cut()), actionCollection());
1222 KStdAction::copy(this, SLOT(copy()), actionCollection());
1223 KStdAction::paste(this, SLOT(paste()), actionCollection());
1225 KAction
* selectAll
= new KAction(i18n("Select All"), actionCollection(), "select_all");
1226 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1227 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1229 KAction
* invertSelection
= new KAction(i18n("Invert Selection"), actionCollection(), "invert_selection");
1230 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1231 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1233 // setup 'View' menu
1234 KStdAction::zoomIn(this,
1236 actionCollection());
1238 KStdAction::zoomOut(this,
1240 actionCollection());
1242 KToggleAction
* iconsView
= new KToggleAction(i18n("Icons"), actionCollection(), "icons");
1243 iconsView
->setShortcut(Qt::CTRL
| Qt::Key_1
);
1244 iconsView
->setIcon(KIcon("view_icon"));
1245 connect(iconsView
, SIGNAL(triggered()), this, SLOT(setIconsView()));
1247 KToggleAction
* detailsView
= new KToggleAction(i18n("Details"), actionCollection(), "details");
1248 detailsView
->setShortcut(Qt::CTRL
| Qt::Key_2
);
1249 detailsView
->setIcon(KIcon("view_text"));
1250 connect(detailsView
, SIGNAL(triggered()), this, SLOT(setDetailsView()));
1252 QActionGroup
* viewModeGroup
= new QActionGroup(this);
1253 viewModeGroup
->addAction(iconsView
);
1254 viewModeGroup
->addAction(detailsView
);
1256 KToggleAction
* sortByName
= new KToggleAction(i18n("By Name"), actionCollection(), "by_name");
1257 connect(sortByName
, SIGNAL(triggered()), this, SLOT(sortByName()));
1259 KToggleAction
* sortBySize
= new KToggleAction(i18n("By Size"), actionCollection(), "by_size");
1260 connect(sortBySize
, SIGNAL(triggered()), this, SLOT(sortBySize()));
1262 KToggleAction
* sortByDate
= new KToggleAction(i18n("By Date"), actionCollection(), "by_date");
1263 connect(sortByDate
, SIGNAL(triggered()), this, SLOT(sortByDate()));
1265 QActionGroup
* sortGroup
= new QActionGroup(this);
1266 sortGroup
->addAction(sortByName
);
1267 sortGroup
->addAction(sortBySize
);
1268 sortGroup
->addAction(sortByDate
);
1270 KToggleAction
* sortDescending
= new KToggleAction(i18n("Descending"), actionCollection(), "descending");
1271 connect(sortDescending
, SIGNAL(triggered()), this, SLOT(toggleSortOrder()));
1273 KToggleAction
* showPreview
= new KToggleAction(i18n("Show Preview"), actionCollection(), "show_preview");
1274 connect(showPreview
, SIGNAL(triggered()), this, SLOT(togglePreview()));
1276 KToggleAction
* showHiddenFiles
= new KToggleAction(i18n("Show Hidden Files"), actionCollection(), "show_hidden_files");
1277 //showHiddenFiles->setShortcut(Qt::ALT | Qt::Key_ KDE4-TODO: what Qt-Key represents '.'?
1278 connect(showHiddenFiles
, SIGNAL(triggered()), this, SLOT(toggleShowHiddenFiles()));
1280 KToggleAction
* split
= new KToggleAction(i18n("Split View"), actionCollection(), "split_view");
1281 split
->setShortcut(Qt::Key_F10
);
1282 split
->setIcon(KIcon("view_left_right"));
1283 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1285 KAction
* reload
= new KAction(i18n("Reload"), "F5", actionCollection(), "reload");
1286 reload
->setShortcut(Qt::Key_F5
);
1287 reload
->setIcon(KIcon("reload"));
1288 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1290 KAction
* stop
= new KAction(i18n("Stop"), actionCollection(), "stop");
1291 stop
->setIcon(KIcon("stop"));
1292 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1294 KToggleAction
* showFullLocation
= new KToggleAction(i18n("Show Full Location"), actionCollection(), "editable_location");
1295 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1296 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1298 KToggleAction
* editLocation
= new KToggleAction(i18n("Edit Location"), actionCollection(), "edit_location");
1299 editLocation
->setShortcut(Qt::Key_F6
);
1300 connect(editLocation
, SIGNAL(triggered()), this, SLOT(editLocation()));
1302 KAction
* adjustViewProps
= new KAction(i18n("Adjust View Properties..."), actionCollection(), "view_properties");
1303 connect(adjustViewProps
, SIGNAL(triggered()), this, SLOT(adjustViewProperties()));
1306 KStdAction::back(this, SLOT(goBack()), actionCollection());
1307 KStdAction::forward(this, SLOT(goForward()), actionCollection());
1308 KStdAction::up(this, SLOT(goUp()), actionCollection());
1309 KStdAction::home(this, SLOT(goHome()), actionCollection());
1311 // setup 'Tools' menu
1312 KAction
* openTerminal
= new KAction(i18n("Open Terminal"), actionCollection(), "open_terminal");
1313 openTerminal
->setShortcut(Qt::Key_F4
);
1314 openTerminal
->setIcon(KIcon("konsole"));
1315 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1317 KAction
* findFile
= new KAction(i18n("Find File..."), actionCollection(), "find_file");
1318 findFile
->setShortcut(Qt::Key_F
);
1319 findFile
->setIcon(KIcon("filefind"));
1320 connect(findFile
, SIGNAL(triggered()), this, SLOT(findFile()));
1322 KToggleAction
* showFilterBar
= new KToggleAction(i18n("Show Filter Bar"), actionCollection(), "show_filter_bar");
1323 showFilterBar
->setShortcut(Qt::Key_Slash
);
1324 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1326 KAction
* compareFiles
= new KAction(i18n("Compare Files"), actionCollection(), "compare_files");
1327 compareFiles
->setIcon(KIcon("kompare"));
1328 compareFiles
->setEnabled(false);
1329 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1331 // setup 'Settings' menu
1332 KStdAction::preferences(this, SLOT(editSettings()), actionCollection());
1335 void DolphinMainWindow::setupDockWidgets()
1337 QDockWidget
*shortcutsDock
= new QDockWidget(i18n("Shortcuts"));
1339 shortcutsDock
->setObjectName("shortcutsDock");
1340 shortcutsDock
->setWidget(new BookmarksSidebarPage(this));
1342 shortcutsDock
->toggleViewAction()->setObjectName("show_shortcuts_pane");
1343 shortcutsDock
->toggleViewAction()->setText(i18n("Show Shortcuts Panel"));
1344 actionCollection()->insert(shortcutsDock
->toggleViewAction());
1346 addDockWidget(Qt::LeftDockWidgetArea
, shortcutsDock
);
1348 QDockWidget
*infoDock
= new QDockWidget(i18n("Information"));
1350 infoDock
->setObjectName("infoDock");
1351 infoDock
->setWidget(new InfoSidebarPage(this));
1353 infoDock
->toggleViewAction()->setObjectName("show_info_pane");
1354 infoDock
->toggleViewAction()->setText(i18n("Show Information Panel"));
1355 actionCollection()->insert(infoDock
->toggleViewAction());
1357 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1360 void DolphinMainWindow::setupCreateNewMenuActions()
1362 // Parts of the following code have been taken
1363 // from the class KNewMenu located in
1364 // libqonq/knewmenu.h of Konqueror.
1365 // Copyright (C) 1998, 1999 David Faure <faure@kde.org>
1366 // 2003 Sven Leiber <s.leiber@web.de>
1368 QStringList files
= actionCollection()->instance()->dirs()->findAllResources("templates");
1369 for (QStringList::Iterator it
= files
.begin() ; it
!= files
.end(); ++it
) {
1370 if ((*it
)[0] != '.' ) {
1371 KSimpleConfig
config(*it
, true);
1372 config
.setDesktopGroup();
1374 // tricky solution to ensure that TextFile is at the beginning
1375 // because this filetype is the most used (according kde-core discussion)
1376 const QString
name(config
.readEntry("Name"));
1379 const QString
path(config
.readPathEntry("Url"));
1380 if (!path
.endsWith("emptydir")) {
1381 if (path
.endsWith("TextFile.txt")) {
1384 else if (!KDesktopFile::isDesktopFile(path
)) {
1387 else if (path
.endsWith("Url.desktop")){
1390 else if (path
.endsWith("Program.desktop")){
1397 const QString
icon(config
.readEntry("Icon"));
1398 const QString
comment(config
.readEntry("Comment"));
1399 const QString
type(config
.readEntry("Type"));
1401 const QString
filePath(*it
);
1404 if (type
== "Link") {
1405 CreateFileEntry entry
;
1408 entry
.comment
= comment
;
1409 entry
.templatePath
= filePath
;
1410 m_createFileTemplates
.insert(key
, entry
);
1415 m_createFileTemplates
.sort();
1417 unplugActionList("create_actions");
1418 KSortableList
<CreateFileEntry
, QString
>::ConstIterator it
= m_createFileTemplates
.begin();
1419 KSortableList
<CreateFileEntry
, QString
>::ConstIterator end
= m_createFileTemplates
.end();
1420 /* KDE4-TODO: don't port this code; use KNewMenu instead
1422 CreateFileEntry entry = (*it).value();
1423 KAction* action = new KAction(entry.name);
1424 action->setIcon(entry.icon);
1425 action->setName((*it).index());
1426 connect(action, SIGNAL(activated()),
1427 this, SLOT(createFile()));
1429 const QChar section = ((*it).index()[0]);
1433 m_fileGroupActions.append(action);
1439 // TODO: not used yet. See documentation of DolphinMainWindow::linkGroupActions()
1440 // and DolphinMainWindow::linkToDeviceActions() in the header file for details.
1441 //m_linkGroupActions.append(action);
1446 // TODO: not used yet. See documentation of DolphinMainWindow::linkGroupActions()
1447 // and DolphinMainWindow::linkToDeviceActions() in the header file for details.
1448 //m_linkToDeviceActions.append(action);
1457 plugActionList("create_file_group", m_fileGroupActions);
1458 //plugActionList("create_link_group", m_linkGroupActions);
1459 //plugActionList("link_to_device", m_linkToDeviceActions);*/
1462 void DolphinMainWindow::updateHistory()
1465 const Q3ValueList
<UrlNavigator::HistoryElem
> list
= m_activeView
->urlHistory(index
);
1467 QAction
* backAction
= actionCollection()->action("go_back");
1468 if (backAction
!= 0) {
1469 backAction
->setEnabled(index
< static_cast<int>(list
.count()) - 1);
1472 QAction
* forwardAction
= actionCollection()->action("go_forward");
1473 if (forwardAction
!= 0) {
1474 forwardAction
->setEnabled(index
> 0);
1478 void DolphinMainWindow::updateEditActions()
1480 const KFileItemList list
= m_activeView
->selectedItems();
1481 if (list
.isEmpty()) {
1482 stateChanged("has_no_selection");
1485 stateChanged("has_selection");
1487 QAction
* renameAction
= actionCollection()->action("rename");
1488 if (renameAction
!= 0) {
1489 renameAction
->setEnabled(list
.count() >= 1);
1492 bool enableMoveToTrash
= true;
1494 KFileItemList::const_iterator it
= list
.begin();
1495 const KFileItemList::const_iterator end
= list
.end();
1497 KFileItem
* item
= *it
;
1498 const KUrl
& url
= item
->url();
1499 // only enable the 'Move to Trash' action for local files
1500 if (!url
.isLocalFile()) {
1501 enableMoveToTrash
= false;
1506 QAction
* moveToTrashAction
= actionCollection()->action("move_to_trash");
1507 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1509 updatePasteAction();
1512 void DolphinMainWindow::updateViewActions()
1514 QAction
* zoomInAction
= actionCollection()->action(KStdAction::stdName(KStdAction::ZoomIn
));
1515 if (zoomInAction
!= 0) {
1516 zoomInAction
->setEnabled(m_activeView
->isZoomInPossible());
1519 QAction
* zoomOutAction
= actionCollection()->action(KStdAction::stdName(KStdAction::ZoomOut
));
1520 if (zoomOutAction
!= 0) {
1521 zoomOutAction
->setEnabled(m_activeView
->isZoomOutPossible());
1524 QAction
* action
= 0;
1525 switch (m_activeView
->mode()) {
1526 case DolphinView::IconsView
:
1527 action
= actionCollection()->action("icons");
1529 case DolphinView::DetailsView
:
1530 action
= actionCollection()->action("details");
1532 //case DolphinView::PreviewsView:
1533 // action = actionCollection()->action("previews");
1540 KToggleAction
* toggleAction
= static_cast<KToggleAction
*>(action
);
1541 toggleAction
->setChecked(true);
1544 slotSortingChanged(m_activeView
->sorting());
1545 slotSortOrderChanged(m_activeView
->sortOrder());
1547 KToggleAction
* showFilterBarAction
=
1548 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
1549 showFilterBarAction
->setChecked(m_activeView
->isFilterBarVisible());
1551 KToggleAction
* showHiddenFilesAction
=
1552 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
1553 showHiddenFilesAction
->setChecked(m_activeView
->showHiddenFiles());
1555 KToggleAction
* splitAction
= static_cast<KToggleAction
*>(actionCollection()->action("split_view"));
1556 splitAction
->setChecked(m_view
[SecondaryIdx
] != 0);
1559 void DolphinMainWindow::updateGoActions()
1561 QAction
* goUpAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Up
));
1562 const KUrl
& currentUrl
= m_activeView
->url();
1563 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1566 void DolphinMainWindow::updateViewProperties(const KUrl::List
& urls
)
1568 if (urls
.isEmpty()) {
1572 // Updating the view properties might take up to several seconds
1573 // when dragging several thousand Urls. Writing a KIO slave for this
1574 // use case is not worth the effort, but at least the main widget
1575 // must be disabled and a progress should be shown.
1576 ProgressIndicator
progressIndicator(this,
1577 i18n("Updating view properties..."),
1581 KUrl::List::ConstIterator end
= urls
.end();
1582 for(KUrl::List::ConstIterator it
= urls
.begin(); it
!= end
; ++it
) {
1583 progressIndicator
.execOperation();
1585 ViewProperties
props(*it
);
1590 void DolphinMainWindow::copyUrls(const KUrl::List
& source
, const KUrl
& dest
)
1592 KIO::Job
* job
= KIO::copy(source
, dest
);
1593 addPendingUndoJob(job
, DolphinCommand::Copy
, source
, dest
);
1596 void DolphinMainWindow::moveUrls(const KUrl::List
& source
, const KUrl
& dest
)
1598 KIO::Job
* job
= KIO::move(source
, dest
);
1599 addPendingUndoJob(job
, DolphinCommand::Move
, source
, dest
);
1602 void DolphinMainWindow::addPendingUndoJob(KIO::Job
* job
,
1603 DolphinCommand::Type commandType
,
1604 const KUrl::List
& source
,
1607 connect(job
, SIGNAL(result(KJob
*)),
1608 this, SLOT(addUndoOperation(KJob
*)));
1611 undoInfo
.id
= job
->progressId();
1612 undoInfo
.command
= DolphinCommand(commandType
, source
, dest
);
1613 m_pendingUndoJobs
.append(undoInfo
);
1616 void DolphinMainWindow::clearStatusBar()
1618 m_activeView
->statusBar()->clear();
1621 void DolphinMainWindow::connectViewSignals(int viewIndex
)
1623 DolphinView
* view
= m_view
[viewIndex
];
1624 connect(view
, SIGNAL(modeChanged()),
1625 this, SLOT(slotViewModeChanged()));
1626 connect(view
, SIGNAL(showHiddenFilesChanged()),
1627 this, SLOT(slotShowHiddenFilesChanged()));
1628 connect(view
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
1629 this, SLOT(slotSortingChanged(DolphinView::Sorting
)));
1630 connect(view
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
1631 this, SLOT(slotSortOrderChanged(Qt::SortOrder
)));
1632 connect(view
, SIGNAL(selectionChanged()),
1633 this, SLOT(slotSelectionChanged()));
1634 connect(view
, SIGNAL(showFilterBarChanged(bool)),
1635 this, SLOT(updateFilterBarAction(bool)));
1637 const UrlNavigator
* navigator
= view
->urlNavigator();
1638 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1639 this, SLOT(slotUrlChanged(const KUrl
&)));
1640 connect(navigator
, SIGNAL(historyChanged()),
1641 this, SLOT(slotHistoryChanged()));
1645 #include "dolphinmainwindow.moc"