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 "dolphinapplication.h"
27 #include "dolphinsettings.h"
28 #include "dolphinsettingsdialog.h"
29 #include "dolphinstatusbar.h"
30 #include "dolphinapplication.h"
31 #include "urlnavigator.h"
32 #include "dolphinsettings.h"
33 #include "bookmarkssidebarpage.h"
34 #include "infosidebarpage.h"
35 #include "generalsettings.h"
36 #include "viewpropertiesdialog.h"
37 #include "viewproperties.h"
40 #include <kactioncollection.h>
41 #include <kbookmarkmanager.h>
43 #include <kdesktopfile.h>
44 #include <kdeversion.h>
45 #include <kfiledialog.h>
48 #include <kiconloader.h>
49 #include <kio/netaccess.h>
50 #include <kio/renamedialog.h>
51 #include <kinputdialog.h>
54 #include <kmessagebox.h>
56 #include <konqmimedata.h>
57 #include <kpropertiesdialog.h>
58 #include <kprotocolinfo.h>
59 #include <ktoggleaction.h>
62 #include <kstandarddirs.h>
63 #include <kstatusbar.h>
64 #include <kstandardaction.h>
67 #include <QCloseEvent>
70 #include <QDockWidget>
72 DolphinMainWindow::DolphinMainWindow() :
78 setObjectName("Dolphin");
79 m_view
[PrimaryIdx
] = 0;
80 m_view
[SecondaryIdx
] = 0;
82 KonqUndoManager::incRef();
84 KonqUndoManager
* undoManager
= KonqUndoManager::self();
85 undoManager
->setUiInterface(new UndoUiInterface(this));
87 connect(undoManager
, SIGNAL(undoAvailable(bool)),
88 this, SLOT(slotUndoAvailable(bool)));
89 connect(undoManager
, SIGNAL(undoTextChanged(const QString
&)),
90 this, SLOT(slotUndoTextChanged(const QString
&)));
93 DolphinMainWindow::~DolphinMainWindow()
95 KonqUndoManager::decRef();
96 DolphinApplication::app()->removeMainWindow(this);
99 void DolphinMainWindow::setActiveView(DolphinView
* view
)
101 assert((view
== m_view
[PrimaryIdx
]) || (view
== m_view
[SecondaryIdx
]));
102 if (m_activeView
== view
) {
113 setCaption(m_activeView
->url().fileName());
115 emit
activeViewChanged();
118 void DolphinMainWindow::dropUrls(const KUrl::List
& urls
,
119 const KUrl
& destination
)
121 Qt::DropAction action
= Qt::CopyAction
;
123 Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
124 const bool shiftPressed
= modifier
& Qt::ShiftModifier
;
125 const bool controlPressed
= modifier
& Qt::ControlModifier
;
126 if (shiftPressed
&& controlPressed
) {
127 // shortcut for 'Link Here' is used
128 action
= Qt::LinkAction
;
130 else if (shiftPressed
) {
131 // shortcut for 'Move Here' is used
132 action
= Qt::MoveAction
;
134 else if (controlPressed
) {
135 // shortcut for 'Copy Here' is used
136 action
= Qt::CopyAction
;
139 // open a context menu which offers the following actions:
147 QString seq
= QKeySequence(Qt::ShiftModifier
).toString();
148 seq
.chop(1); // chop superfluous '+'
149 QAction
* moveAction
= popup
.addAction(KIcon("goto"),
150 i18n("&Move Here") + "\t" + seq
);
152 seq
= QKeySequence(Qt::ControlModifier
).toString();
154 QAction
* copyAction
= popup
.addAction(KIcon("editcopy"),
155 i18n("&Copy Here") + "\t" + seq
);
157 seq
= QKeySequence(Qt::ControlModifier
+ Qt::ShiftModifier
).toString();
159 QAction
* linkAction
= popup
.addAction(KIcon("www"),
160 i18n("&Link Here") + "\t" + seq
);
162 popup
.addSeparator();
163 popup
.addAction(KIcon("stop"), i18n("Cancel"));
165 QAction
* activatedAction
= popup
.exec(QCursor::pos());
166 if (activatedAction
== moveAction
) {
167 action
= Qt::MoveAction
;
169 else if (activatedAction
== copyAction
) {
170 action
= Qt::CopyAction
;
172 else if (activatedAction
== linkAction
) {
173 action
= Qt::LinkAction
;
179 moveUrls(urls
, destination
);
183 copyUrls(urls
, destination
);
187 linkUrls(urls
, destination
);
195 void DolphinMainWindow::refreshViews()
197 const bool split
= DolphinSettings::instance().generalSettings()->splitView();
198 const bool isPrimaryViewActive
= (m_activeView
== m_view
[PrimaryIdx
]);
200 for (int i
= PrimaryIdx
; i
<= SecondaryIdx
; ++i
) {
201 if (m_view
[i
] != 0) {
202 url
= m_view
[i
]->url();
204 // delete view instance...
206 m_view
[i
]->deleteLater();
210 if (split
|| (i
== PrimaryIdx
)) {
211 // ... and recreate it
212 ViewProperties
props(url
);
213 m_view
[i
] = new DolphinView(this,
217 props
.showHiddenFiles());
218 connectViewSignals(i
);
223 m_activeView
= isPrimaryViewActive
? m_view
[PrimaryIdx
] : m_view
[SecondaryIdx
];
224 assert(m_activeView
!= 0);
227 emit
activeViewChanged();
230 void DolphinMainWindow::slotViewModeChanged()
235 void DolphinMainWindow::slotShowHiddenFilesChanged()
237 KToggleAction
* showHiddenFilesAction
=
238 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
239 showHiddenFilesAction
->setChecked(m_activeView
->showHiddenFiles());
242 void DolphinMainWindow::slotSortingChanged(DolphinView::Sorting sorting
)
246 case DolphinView::SortByName
:
247 action
= actionCollection()->action("by_name");
249 case DolphinView::SortBySize
:
250 action
= actionCollection()->action("by_size");
252 case DolphinView::SortByDate
:
253 action
= actionCollection()->action("by_date");
260 KToggleAction
* toggleAction
= static_cast<KToggleAction
*>(action
);
261 toggleAction
->setChecked(true);
265 void DolphinMainWindow::slotSortOrderChanged(Qt::SortOrder order
)
267 KToggleAction
* descending
= static_cast<KToggleAction
*>(actionCollection()->action("descending"));
268 const bool sortDescending
= (order
== Qt::Descending
);
269 descending
->setChecked(sortDescending
);
272 void DolphinMainWindow::slotSelectionChanged()
276 assert(m_view
[PrimaryIdx
] != 0);
277 int selectedUrlsCount
= m_view
[PrimaryIdx
]->selectedUrls().count();
278 if (m_view
[SecondaryIdx
] != 0) {
279 selectedUrlsCount
+= m_view
[SecondaryIdx
]->selectedUrls().count();
282 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
283 compareFilesAction
->setEnabled(selectedUrlsCount
== 2);
285 m_activeView
->updateStatusBar();
287 emit
selectionChanged();
290 void DolphinMainWindow::slotHistoryChanged()
295 void DolphinMainWindow::slotUrlChanged(const KUrl
& url
)
299 setCaption(url
.fileName());
302 void DolphinMainWindow::updateFilterBarAction(bool show
)
304 KToggleAction
* showFilterBarAction
=
305 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
306 showFilterBarAction
->setChecked(show
);
309 void DolphinMainWindow::openNewMainWindow()
311 DolphinApplication::app()->createMainWindow()->show();
314 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
316 DolphinSettings
& settings
= DolphinSettings::instance();
317 GeneralSettings
* generalSettings
= settings
.generalSettings();
318 generalSettings
->setFirstRun(false);
322 // TODO: I assume there will be a generic way in KDE 4 to store the docks
323 // of the main window. In the meantime they are stored manually:
324 QString filename
= KStandardDirs::locateLocal("data", KGlobal::instance()->instanceName());
325 filename
.append("/panels_layout");
326 QFile
file(filename
);
327 if (file
.open(QIODevice::WriteOnly
)) {
328 QByteArray data
= saveState();
333 KMainWindow::closeEvent(event
);
336 void DolphinMainWindow::saveProperties(KConfig
* config
)
338 config
->setGroup("Primary view");
339 config
->writeEntry("Url", m_view
[PrimaryIdx
]->url().url());
340 config
->writeEntry("Editable Url", m_view
[PrimaryIdx
]->isUrlEditable());
341 if (m_view
[SecondaryIdx
] != 0) {
342 config
->setGroup("Secondary view");
343 config
->writeEntry("Url", m_view
[SecondaryIdx
]->url().url());
344 config
->writeEntry("Editable Url", m_view
[SecondaryIdx
]->isUrlEditable());
348 void DolphinMainWindow::readProperties(KConfig
* config
)
350 config
->setGroup("Primary view");
351 m_view
[PrimaryIdx
]->setUrl(config
->readEntry("Url"));
352 m_view
[PrimaryIdx
]->setUrlEditable(config
->readEntry("Editable Url", false));
353 if (config
->hasGroup("Secondary view")) {
354 config
->setGroup("Secondary view");
355 if (m_view
[SecondaryIdx
] == 0) {
358 m_view
[SecondaryIdx
]->setUrl(config
->readEntry("Url"));
359 m_view
[SecondaryIdx
]->setUrlEditable(config
->readEntry("Editable Url", false));
361 else if (m_view
[SecondaryIdx
] != 0) {
366 void DolphinMainWindow::updateNewMenu()
368 m_newMenu
->slotCheckUpToDate();
369 m_newMenu
->setPopupFiles(activeView()->url());
372 void DolphinMainWindow::rename()
375 m_activeView
->renameSelectedItems();
378 void DolphinMainWindow::moveToTrash()
381 const KUrl::List selectedUrls
= m_activeView
->selectedUrls();
382 KonqOperations::del(this, KonqOperations::TRASH
, selectedUrls
);
383 m_undoOperations
.append(KonqOperations::TRASH
);
386 void DolphinMainWindow::deleteItems()
390 KUrl::List list
= m_activeView
->selectedUrls();
391 const uint itemCount
= list
.count();
392 assert(itemCount
>= 1);
396 text
= i18n("Do you really want to delete the %1 selected items?",itemCount
);
399 const KUrl
& url
= list
.first();
400 text
= i18n("Do you really want to delete '%1'?",url
.fileName());
403 const bool del
= KMessageBox::warningContinueCancel(this,
406 KGuiItem(i18n("Delete"), KIcon("editdelete"))
407 ) == KMessageBox::Continue
;
409 KIO::Job
* job
= KIO::del(list
);
410 connect(job
, SIGNAL(result(KJob
*)),
411 this, SLOT(slotHandleJobError(KJob
*)));
412 connect(job
, SIGNAL(result(KJob
*)),
413 this, SLOT(slotDeleteFileFinished(KJob
*)));
417 void DolphinMainWindow::properties()
419 const KFileItemList list
= m_activeView
->selectedItems();
420 new KPropertiesDialog(list
, this);
423 void DolphinMainWindow::quit()
428 void DolphinMainWindow::slotHandleJobError(KJob
* job
)
430 if (job
->error() != 0) {
431 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
432 statusBar
->setMessage(job
->errorString(),
433 DolphinStatusBar::Error
);
437 void DolphinMainWindow::slotDeleteFileFinished(KJob
* job
)
439 if (job
->error() == 0) {
440 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
441 statusBar
->setMessage(i18n("Delete operation completed."),
442 DolphinStatusBar::OperationCompleted
);
446 void DolphinMainWindow::slotUndoAvailable(bool available
)
448 QAction
* undoAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::Undo
));
449 if (undoAction
!= 0) {
450 undoAction
->setEnabled(available
);
453 if (available
&& (m_undoOperations
.count() > 0)) {
454 const KonqOperations::Operation op
= m_undoOperations
.takeFirst();
455 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
457 case KonqOperations::COPY
:
458 statusBar
->setMessage(i18n("Copy operation completed."),
459 DolphinStatusBar::OperationCompleted
);
461 case KonqOperations::MOVE
:
462 statusBar
->setMessage(i18n("Move operation completed."),
463 DolphinStatusBar::OperationCompleted
);
465 case KonqOperations::LINK
:
466 statusBar
->setMessage(i18n("Link operation completed."),
467 DolphinStatusBar::OperationCompleted
);
469 case KonqOperations::TRASH
:
470 statusBar
->setMessage(i18n("Move to trash operation completed."),
471 DolphinStatusBar::OperationCompleted
);
480 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
482 QAction
* undoAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::Undo
));
483 if (undoAction
!= 0) {
484 undoAction
->setText(text
);
488 void DolphinMainWindow::cut()
490 QMimeData
* mimeData
= new QMimeData();
491 const KUrl::List kdeUrls
= m_activeView
->selectedUrls();
492 const KUrl::List mostLocalUrls
;
493 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, true);
494 QApplication::clipboard()->setMimeData(mimeData
);
497 void DolphinMainWindow::copy()
499 QMimeData
* mimeData
= new QMimeData();
500 const KUrl::List kdeUrls
= m_activeView
->selectedUrls();
501 const KUrl::List mostLocalUrls
;
502 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, false);
504 QApplication::clipboard()->setMimeData(mimeData
);
507 void DolphinMainWindow::paste()
509 QClipboard
* clipboard
= QApplication::clipboard();
510 const QMimeData
* mimeData
= clipboard
->mimeData();
514 const KUrl::List sourceUrls
= KUrl::List::fromMimeData(mimeData
);
516 // per default the pasting is done into the current Url of the view
517 KUrl
destUrl(m_activeView
->url());
519 // check whether the pasting should be done into a selected directory
520 KUrl::List selectedUrls
= m_activeView
->selectedUrls();
521 if (selectedUrls
.count() == 1) {
522 const KFileItem
fileItem(S_IFDIR
,
524 selectedUrls
.first(),
526 if (fileItem
.isDir()) {
527 // only one item is selected which is a directory, hence paste
528 // into this directory
529 destUrl
= selectedUrls
.first();
533 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
534 moveUrls(sourceUrls
, destUrl
);
538 copyUrls(sourceUrls
, destUrl
);
542 void DolphinMainWindow::updatePasteAction()
544 QAction
* pasteAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::Paste
));
545 if (pasteAction
== 0) {
549 QString
text(i18n("Paste"));
550 QClipboard
* clipboard
= QApplication::clipboard();
551 const QMimeData
* mimeData
= clipboard
->mimeData();
553 KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
554 if (!urls
.isEmpty()) {
555 pasteAction
->setEnabled(true);
557 const int count
= urls
.count();
559 pasteAction
->setText(i18n("Paste 1 File"));
562 pasteAction
->setText(i18n("Paste %1 Files").arg(count
));
566 pasteAction
->setEnabled(false);
567 pasteAction
->setText(i18n("Paste"));
570 if (pasteAction
->isEnabled()) {
571 KUrl::List urls
= m_activeView
->selectedUrls();
572 const uint count
= urls
.count();
574 // pasting should not be allowed when more than one file
576 pasteAction
->setEnabled(false);
578 else if (count
== 1) {
579 // Only one file is selected. Pasting is only allowed if this
580 // file is a directory.
581 // TODO: this doesn't work with remote protocols; instead we need a
582 // m_activeView->selectedFileItems() to get the real KFileItems
583 const KFileItem
fileItem(S_IFDIR
,
587 pasteAction
->setEnabled(fileItem
.isDir());
592 void DolphinMainWindow::selectAll()
595 m_activeView
->selectAll();
598 void DolphinMainWindow::invertSelection()
601 m_activeView
->invertSelection();
603 void DolphinMainWindow::setIconsView()
605 m_activeView
->setMode(DolphinView::IconsView
);
608 void DolphinMainWindow::setDetailsView()
610 m_activeView
->setMode(DolphinView::DetailsView
);
613 void DolphinMainWindow::sortByName()
615 m_activeView
->setSorting(DolphinView::SortByName
);
618 void DolphinMainWindow::sortBySize()
620 m_activeView
->setSorting(DolphinView::SortBySize
);
623 void DolphinMainWindow::sortByDate()
625 m_activeView
->setSorting(DolphinView::SortByDate
);
628 void DolphinMainWindow::toggleSortOrder()
630 const Qt::SortOrder order
= (m_activeView
->sortOrder() == Qt::Ascending
) ?
633 m_activeView
->setSortOrder(order
);
636 void DolphinMainWindow::toggleSplitView()
638 if (m_view
[SecondaryIdx
] == 0) {
639 const int newWidth
= (m_view
[PrimaryIdx
]->width() - m_splitter
->handleWidth()) / 2;
640 // create a secondary view
641 m_view
[SecondaryIdx
] = new DolphinView(this,
643 m_view
[PrimaryIdx
]->url(),
644 m_view
[PrimaryIdx
]->mode(),
645 m_view
[PrimaryIdx
]->showHiddenFiles());
646 connectViewSignals(SecondaryIdx
);
647 m_splitter
->addWidget(m_view
[SecondaryIdx
]);
648 m_splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
649 m_view
[SecondaryIdx
]->show();
652 // remove secondary view
653 if (m_activeView
== m_view
[PrimaryIdx
]) {
654 m_view
[SecondaryIdx
]->close();
655 m_view
[SecondaryIdx
]->deleteLater();
656 m_view
[SecondaryIdx
] = 0;
657 setActiveView(m_view
[PrimaryIdx
]);
660 // The secondary view is active, hence from the users point of view
661 // the content of the secondary view should be moved to the primary view.
662 // From an implementation point of view it is more efficient to close
663 // the primary view and exchange the internal pointers afterwards.
664 m_view
[PrimaryIdx
]->close();
665 delete m_view
[PrimaryIdx
];
666 m_view
[PrimaryIdx
] = m_view
[SecondaryIdx
];
667 m_view
[SecondaryIdx
] = 0;
668 setActiveView(m_view
[PrimaryIdx
]);
673 void DolphinMainWindow::reloadView()
676 m_activeView
->reload();
679 void DolphinMainWindow::stopLoading()
683 void DolphinMainWindow::togglePreview()
687 const KToggleAction
* showPreviewAction
=
688 static_cast<KToggleAction
*>(actionCollection()->action("show_preview"));
689 const bool show
= showPreviewAction
->isChecked();
690 m_activeView
->setShowPreview(show
);
693 void DolphinMainWindow::toggleShowHiddenFiles()
697 const KToggleAction
* showHiddenFilesAction
=
698 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
699 const bool show
= showHiddenFilesAction
->isChecked();
700 m_activeView
->setShowHiddenFiles(show
);
703 void DolphinMainWindow::showFilterBar()
705 const KToggleAction
* showFilterBarAction
=
706 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
707 const bool show
= showFilterBarAction
->isChecked();
708 m_activeView
->showFilterBar(show
);
711 void DolphinMainWindow::zoomIn()
713 m_activeView
->zoomIn();
717 void DolphinMainWindow::zoomOut()
719 m_activeView
->zoomOut();
723 void DolphinMainWindow::toggleEditLocation()
727 KToggleAction
* action
= static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
729 bool editOrBrowse
= action
->isChecked();
730 m_activeView
->setUrlEditable(editOrBrowse
);
733 void DolphinMainWindow::editLocation()
735 KToggleAction
* action
= static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
736 action
->setChecked(true);
737 m_activeView
->setUrlEditable(true);
740 void DolphinMainWindow::adjustViewProperties()
743 ViewPropertiesDialog
dlg(m_activeView
);
747 void DolphinMainWindow::goBack()
750 m_activeView
->goBack();
753 void DolphinMainWindow::goForward()
756 m_activeView
->goForward();
759 void DolphinMainWindow::goUp()
762 m_activeView
->goUp();
765 void DolphinMainWindow::goHome()
768 m_activeView
->goHome();
771 void DolphinMainWindow::openTerminal()
773 QString
command("konsole --workdir \"");
774 command
.append(m_activeView
->url().path());
775 command
.append('\"');
777 KRun::runCommand(command
, "Konsole", "konsole");
780 void DolphinMainWindow::findFile()
782 KRun::run("kfind", m_activeView
->url());
785 void DolphinMainWindow::compareFiles()
787 // The method is only invoked if exactly 2 files have
788 // been selected. The selected files may be:
789 // - both in the primary view
790 // - both in the secondary view
791 // - one in the primary view and the other in the secondary
793 assert(m_view
[PrimaryIdx
] != 0);
797 KUrl::List urls
= m_view
[PrimaryIdx
]->selectedUrls();
799 switch (urls
.count()) {
801 assert(m_view
[SecondaryIdx
] != 0);
802 urls
= m_view
[SecondaryIdx
]->selectedUrls();
803 assert(urls
.count() == 2);
811 assert(m_view
[SecondaryIdx
] != 0);
812 urls
= m_view
[SecondaryIdx
]->selectedUrls();
813 assert(urls
.count() == 1);
825 // may not happen: compareFiles may only get invoked if 2
826 // files are selected
831 QString
command("kompare -c \"");
832 command
.append(urlA
.pathOrUrl());
833 command
.append("\" \"");
834 command
.append(urlB
.pathOrUrl());
835 command
.append('\"');
836 KRun::runCommand(command
, "Kompare", "kompare");
840 void DolphinMainWindow::editSettings()
842 // TODO: make a static method for opening the settings dialog
843 DolphinSettingsDialog
dlg(this);
847 void DolphinMainWindow::init()
849 // Check whether Dolphin runs the first time. If yes then
850 // a proper default window size is given at the end of DolphinMainWindow::init().
851 GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
852 const bool firstRun
= generalSettings
->firstRun();
854 setAcceptDrops(true);
856 m_splitter
= new QSplitter(this);
858 DolphinSettings
& settings
= DolphinSettings::instance();
860 KBookmarkManager
* manager
= settings
.bookmarkManager();
861 assert(manager
!= 0);
862 KBookmarkGroup root
= manager
->root();
863 if (root
.first().isNull()) {
864 root
.addBookmark(manager
, i18n("Home"), settings
.generalSettings()->homeUrl(), "folder_home");
865 root
.addBookmark(manager
, i18n("Storage Media"), KUrl("media:/"), "blockdevice");
866 root
.addBookmark(manager
, i18n("Network"), KUrl("remote:/"), "network_local");
867 root
.addBookmark(manager
, i18n("Root"), KUrl("/"), "folder_red");
868 root
.addBookmark(manager
, i18n("Trash"), KUrl("trash:/"), "trashcan_full");
873 const KUrl
& homeUrl
= root
.first().url();
874 setCaption(homeUrl
.fileName());
875 ViewProperties
props(homeUrl
);
876 m_view
[PrimaryIdx
] = new DolphinView(this,
880 props
.showHiddenFiles());
881 connectViewSignals(PrimaryIdx
);
882 m_view
[PrimaryIdx
]->show();
884 m_activeView
= m_view
[PrimaryIdx
];
886 setCentralWidget(m_splitter
);
889 setupGUI(Keys
|Save
|Create
|ToolBar
);
892 stateChanged("new_file");
893 setAutoSaveSettings();
895 QClipboard
* clipboard
= QApplication::clipboard();
896 connect(clipboard
, SIGNAL(dataChanged()),
897 this, SLOT(updatePasteAction()));
904 // assure a proper default size if Dolphin runs the first time
909 void DolphinMainWindow::loadSettings()
911 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
913 KToggleAction
* splitAction
= static_cast<KToggleAction
*>(actionCollection()->action("split_view"));
914 if (settings
->splitView()) {
915 splitAction
->setChecked(true);
921 // TODO: I assume there will be a generic way in KDE 4 to restore the docks
922 // of the main window. In the meantime they are restored manually (see also
923 // DolphinMainWindow::closeEvent() for more details):
924 QString filename
= KStandardDirs::locateLocal("data", KGlobal::instance()->instanceName());
925 filename
.append("/panels_layout");
926 QFile
file(filename
);
927 if (file
.open(QIODevice::ReadOnly
)) {
928 QByteArray data
= file
.readAll();
934 void DolphinMainWindow::setupActions()
937 m_newMenu
= new KNewMenu(actionCollection(), this, "create_new");
938 KMenu
* menu
= m_newMenu
->menu();
939 menu
->setTitle(i18n("Create New..."));
940 menu
->setIcon(SmallIcon("filenew"));
941 connect(menu
, SIGNAL(aboutToShow()),
942 this, SLOT(updateNewMenu()));
944 QAction
* action
= actionCollection()->addAction("new_window");
945 action
->setIcon(KIcon("window_new"));
946 action
->setText(i18n("New &Window"));
947 connect(action
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
949 QAction
* rename
= actionCollection()->addAction("rename");
950 rename
->setText(i18n("Rename"));
951 rename
->setShortcut(Qt::Key_F2
);
952 connect(rename
, SIGNAL(triggered()), this, SLOT(rename()));
954 QAction
* moveToTrash
= actionCollection()->addAction("move_to_trash");
955 moveToTrash
->setText(i18n("Move to Trash"));
956 moveToTrash
->setIcon(KIcon("edittrash"));
957 moveToTrash
->setShortcut(QKeySequence::Delete
);
958 connect(moveToTrash
, SIGNAL(triggered()), this, SLOT(moveToTrash()));
960 QAction
* deleteAction
= actionCollection()->addAction("delete");
961 deleteAction
->setText(i18n("Delete"));
962 deleteAction
->setShortcut(Qt::ALT
| Qt::Key_Delete
);
963 deleteAction
->setIcon(KIcon("editdelete"));
964 connect(deleteAction
, SIGNAL(triggered()), this, SLOT(deleteItems()));
966 QAction
* properties
= actionCollection()->addAction("properties");
967 properties
->setText(i18n("Propert&ies"));
968 properties
->setShortcut(Qt::Key_Alt
| Qt::Key_Return
);
969 connect(properties
, SIGNAL(triggered()), this, SLOT(properties()));
971 KStandardAction::quit(this, SLOT(quit()), actionCollection());
974 KStandardAction::undo(KonqUndoManager::self(),
978 KStandardAction::cut(this, SLOT(cut()), actionCollection());
979 KStandardAction::copy(this, SLOT(copy()), actionCollection());
980 KStandardAction::paste(this, SLOT(paste()), actionCollection());
982 QAction
* selectAll
= actionCollection()->addAction("select_all");
983 selectAll
->setText(i18n("Select All"));
984 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
985 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
987 QAction
* invertSelection
= actionCollection()->addAction("invert_selection");
988 invertSelection
->setText(i18n("Invert Selection"));
989 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
990 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
993 KStandardAction::zoomIn(this,
997 KStandardAction::zoomOut(this,
1001 KToggleAction
* iconsView
= actionCollection()->add
<KToggleAction
>("icons");
1002 iconsView
->setText(i18n("Icons"));
1003 iconsView
->setShortcut(Qt::CTRL
| Qt::Key_1
);
1004 iconsView
->setIcon(KIcon("view_icon"));
1005 connect(iconsView
, SIGNAL(triggered()), this, SLOT(setIconsView()));
1007 KToggleAction
* detailsView
= actionCollection()->add
<KToggleAction
>("details");
1008 detailsView
->setText(i18n("Details"));
1009 detailsView
->setShortcut(Qt::CTRL
| Qt::Key_2
);
1010 detailsView
->setIcon(KIcon("view_text"));
1011 connect(detailsView
, SIGNAL(triggered()), this, SLOT(setDetailsView()));
1013 QActionGroup
* viewModeGroup
= new QActionGroup(this);
1014 viewModeGroup
->addAction(iconsView
);
1015 viewModeGroup
->addAction(detailsView
);
1017 KToggleAction
* sortByName
= actionCollection()->add
<KToggleAction
>("by_name");
1018 sortByName
->setText(i18n("By Name"));
1019 connect(sortByName
, SIGNAL(triggered()), this, SLOT(sortByName()));
1021 KToggleAction
* sortBySize
= actionCollection()->add
<KToggleAction
>("by_size");
1022 sortBySize
->setText(i18n("By Size"));
1023 connect(sortBySize
, SIGNAL(triggered()), this, SLOT(sortBySize()));
1025 KToggleAction
* sortByDate
= actionCollection()->add
<KToggleAction
>("by_date");
1026 sortByDate
->setText(i18n("By Date"));
1027 connect(sortByDate
, SIGNAL(triggered()), this, SLOT(sortByDate()));
1029 QActionGroup
* sortGroup
= new QActionGroup(this);
1030 sortGroup
->addAction(sortByName
);
1031 sortGroup
->addAction(sortBySize
);
1032 sortGroup
->addAction(sortByDate
);
1034 KToggleAction
* sortDescending
= actionCollection()->add
<KToggleAction
>("descending");
1035 sortDescending
->setText(i18n("Descending"));
1036 connect(sortDescending
, SIGNAL(triggered()), this, SLOT(toggleSortOrder()));
1038 KToggleAction
* showPreview
= actionCollection()->add
<KToggleAction
>("show_preview");
1039 showPreview
->setText(i18n("Show Preview"));
1040 connect(showPreview
, SIGNAL(triggered()), this, SLOT(togglePreview()));
1042 KToggleAction
* showHiddenFiles
= actionCollection()->add
<KToggleAction
>("show_hidden_files");
1043 showHiddenFiles
->setText(i18n("Show Hidden Files"));
1044 //showHiddenFiles->setShortcut(Qt::ALT | Qt::Key_ KDE4-TODO: what Qt-Key represents '.'?
1045 connect(showHiddenFiles
, SIGNAL(triggered()), this, SLOT(toggleShowHiddenFiles()));
1047 KToggleAction
* split
= actionCollection()->add
<KToggleAction
>("split_view");
1048 split
->setText(i18n("Split View"));
1049 split
->setShortcut(Qt::Key_F10
);
1050 split
->setIcon(KIcon("view_left_right"));
1051 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1053 QAction
* reload
= actionCollection()->addAction("reload");
1054 reload
->setText(i18n("Reload"));
1055 reload
->setShortcut(Qt::Key_F5
);
1056 reload
->setIcon(KIcon("reload"));
1057 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1059 QAction
* stop
= actionCollection()->addAction("stop");
1060 stop
->setText(i18n("Stop"));
1061 stop
->setIcon(KIcon("stop"));
1062 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1064 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1065 showFullLocation
->setText(i18n("Show Full Location"));
1066 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1067 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1069 KToggleAction
* editLocation
= actionCollection()->add
<KToggleAction
>("edit_location");
1070 editLocation
->setText(i18n("Edit Location"));
1071 editLocation
->setShortcut(Qt::Key_F6
);
1072 connect(editLocation
, SIGNAL(triggered()), this, SLOT(editLocation()));
1074 QAction
* adjustViewProps
= actionCollection()->addAction("view_properties");
1075 adjustViewProps
->setText(i18n("Adjust View Properties..."));
1076 connect(adjustViewProps
, SIGNAL(triggered()), this, SLOT(adjustViewProperties()));
1079 KStandardAction::back(this, SLOT(goBack()), actionCollection());
1080 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1081 KStandardAction::up(this, SLOT(goUp()), actionCollection());
1082 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1084 // setup 'Tools' menu
1085 QAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1086 openTerminal
->setText(i18n("Open Terminal"));
1087 openTerminal
->setShortcut(Qt::Key_F4
);
1088 openTerminal
->setIcon(KIcon("konsole"));
1089 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1091 QAction
* findFile
= actionCollection()->addAction("find_file");
1092 findFile
->setText(i18n("Find File..."));
1093 findFile
->setShortcut(Qt::Key_F
);
1094 findFile
->setIcon(KIcon("filefind"));
1095 connect(findFile
, SIGNAL(triggered()), this, SLOT(findFile()));
1097 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
1098 showFilterBar
->setText(i18n("Show Filter Bar"));
1099 showFilterBar
->setShortcut(Qt::Key_Slash
);
1100 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1102 QAction
* compareFiles
= actionCollection()->addAction("compare_files");
1103 compareFiles
->setText(i18n("Compare Files"));
1104 compareFiles
->setIcon(KIcon("kompare"));
1105 compareFiles
->setEnabled(false);
1106 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1108 // setup 'Settings' menu
1109 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1112 void DolphinMainWindow::setupDockWidgets()
1114 QDockWidget
* shortcutsDock
= new QDockWidget(i18n("Bookmarks"));
1115 shortcutsDock
->setObjectName("bookmarksDock");
1116 shortcutsDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1117 shortcutsDock
->setWidget(new BookmarksSidebarPage(this));
1119 shortcutsDock
->toggleViewAction()->setText(i18n("Show Bookmarks Panel"));
1120 actionCollection()->addAction("show_bookmarks_panel", shortcutsDock
->toggleViewAction());
1122 addDockWidget(Qt::LeftDockWidgetArea
, shortcutsDock
);
1124 QDockWidget
* infoDock
= new QDockWidget(i18n("Information"));
1125 infoDock
->setObjectName("infoDock");
1126 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1127 infoDock
->setWidget(new InfoSidebarPage(this));
1129 infoDock
->toggleViewAction()->setText(i18n("Show Information Panel"));
1130 actionCollection()->addAction("show_info_panel", infoDock
->toggleViewAction());
1132 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1135 void DolphinMainWindow::updateHistory()
1138 const QLinkedList
<UrlNavigator::HistoryElem
> list
= m_activeView
->urlHistory(index
);
1140 QAction
* backAction
= actionCollection()->action("go_back");
1141 if (backAction
!= 0) {
1142 backAction
->setEnabled(index
< static_cast<int>(list
.count()) - 1);
1145 QAction
* forwardAction
= actionCollection()->action("go_forward");
1146 if (forwardAction
!= 0) {
1147 forwardAction
->setEnabled(index
> 0);
1151 void DolphinMainWindow::updateEditActions()
1153 const KFileItemList list
= m_activeView
->selectedItems();
1154 if (list
.isEmpty()) {
1155 stateChanged("has_no_selection");
1158 stateChanged("has_selection");
1160 QAction
* renameAction
= actionCollection()->action("rename");
1161 if (renameAction
!= 0) {
1162 renameAction
->setEnabled(list
.count() >= 1);
1165 bool enableMoveToTrash
= true;
1167 KFileItemList::const_iterator it
= list
.begin();
1168 const KFileItemList::const_iterator end
= list
.end();
1170 KFileItem
* item
= *it
;
1171 const KUrl
& url
= item
->url();
1172 // only enable the 'Move to Trash' action for local files
1173 if (!url
.isLocalFile()) {
1174 enableMoveToTrash
= false;
1179 QAction
* moveToTrashAction
= actionCollection()->action("move_to_trash");
1180 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1182 updatePasteAction();
1185 void DolphinMainWindow::updateViewActions()
1187 QAction
* zoomInAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::ZoomIn
));
1188 if (zoomInAction
!= 0) {
1189 zoomInAction
->setEnabled(m_activeView
->isZoomInPossible());
1192 QAction
* zoomOutAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::ZoomOut
));
1193 if (zoomOutAction
!= 0) {
1194 zoomOutAction
->setEnabled(m_activeView
->isZoomOutPossible());
1197 QAction
* action
= 0;
1198 switch (m_activeView
->mode()) {
1199 case DolphinView::IconsView
:
1200 action
= actionCollection()->action("icons");
1202 case DolphinView::DetailsView
:
1203 action
= actionCollection()->action("details");
1210 KToggleAction
* toggleAction
= static_cast<KToggleAction
*>(action
);
1211 toggleAction
->setChecked(true);
1214 slotSortingChanged(m_activeView
->sorting());
1215 slotSortOrderChanged(m_activeView
->sortOrder());
1217 KToggleAction
* showFilterBarAction
=
1218 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
1219 showFilterBarAction
->setChecked(m_activeView
->isFilterBarVisible());
1221 KToggleAction
* showHiddenFilesAction
=
1222 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
1223 showHiddenFilesAction
->setChecked(m_activeView
->showHiddenFiles());
1225 KToggleAction
* splitAction
= static_cast<KToggleAction
*>(actionCollection()->action("split_view"));
1226 splitAction
->setChecked(m_view
[SecondaryIdx
] != 0);
1229 void DolphinMainWindow::updateGoActions()
1231 QAction
* goUpAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::Up
));
1232 const KUrl
& currentUrl
= m_activeView
->url();
1233 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1236 void DolphinMainWindow::copyUrls(const KUrl::List
& source
, const KUrl
& dest
)
1238 KonqOperations::copy(this, KonqOperations::COPY
, source
, dest
);
1239 m_undoOperations
.append(KonqOperations::COPY
);
1242 void DolphinMainWindow::moveUrls(const KUrl::List
& source
, const KUrl
& dest
)
1244 KonqOperations::copy(this, KonqOperations::MOVE
, source
, dest
);
1245 m_undoOperations
.append(KonqOperations::MOVE
);
1248 void DolphinMainWindow::linkUrls(const KUrl::List
& source
, const KUrl
& dest
)
1250 KonqOperations::copy(this, KonqOperations::LINK
, source
, dest
);
1251 m_undoOperations
.append(KonqOperations::LINK
);
1254 void DolphinMainWindow::clearStatusBar()
1256 m_activeView
->statusBar()->clear();
1259 void DolphinMainWindow::connectViewSignals(int viewIndex
)
1261 DolphinView
* view
= m_view
[viewIndex
];
1262 connect(view
, SIGNAL(modeChanged()),
1263 this, SLOT(slotViewModeChanged()));
1264 connect(view
, SIGNAL(showHiddenFilesChanged()),
1265 this, SLOT(slotShowHiddenFilesChanged()));
1266 connect(view
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
1267 this, SLOT(slotSortingChanged(DolphinView::Sorting
)));
1268 connect(view
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
1269 this, SLOT(slotSortOrderChanged(Qt::SortOrder
)));
1270 connect(view
, SIGNAL(selectionChanged()),
1271 this, SLOT(slotSelectionChanged()));
1272 connect(view
, SIGNAL(showFilterBarChanged(bool)),
1273 this, SLOT(updateFilterBarAction(bool)));
1275 const UrlNavigator
* navigator
= view
->urlNavigator();
1276 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1277 this, SLOT(slotUrlChanged(const KUrl
&)));
1278 connect(navigator
, SIGNAL(historyChanged()),
1279 this, SLOT(slotHistoryChanged()));
1283 DolphinMainWindow::UndoUiInterface::UndoUiInterface(DolphinMainWindow
* mainWin
) :
1286 assert(m_mainWin
!= 0);
1289 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1293 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1295 DolphinStatusBar
* statusBar
= m_mainWin
->activeView()->statusBar();
1296 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1299 bool DolphinMainWindow::UndoUiInterface::copiedFileWasModified(const KUrl
& src
,
1304 // The following code has been taken from libkonq/konq_undo.cc
1305 // Copyright (C) 2000 Simon Hausmann <hausmann@kde.org>
1306 // Copyright (C) 2006 David Faure <faure@kde.org>
1307 const QDateTime destDt
= QDateTime::fromTime_t(destTime
);
1308 const QString timeStr
= KGlobal::locale()->formatDateTime(destDt
, true /* short */);
1309 return KMessageBox::warningContinueCancel(
1311 i18n( "The file %1 was copied from %2, but since then it has apparently been modified at %3.\n"
1312 "Undoing the copy will delete the file, and all modifications will be lost.\n"
1313 "Are you sure you want to delete %4?", dest
.pathOrUrl(), src
.pathOrUrl(), timeStr
, dest
.pathOrUrl()),
1314 i18n( "Undo File Copy Confirmation" ),
1315 KStandardGuiItem::cont(),
1317 KMessageBox::Notify
| KMessageBox::Dangerous
) == KMessageBox::Continue
;
1320 #include "dolphinmainwindow.moc"