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 <konq_undo.h>
58 #include <kpropertiesdialog.h>
59 #include <kprotocolinfo.h>
60 #include <ktoggleaction.h>
63 #include <kstandarddirs.h>
64 #include <kstatusbar.h>
65 #include <kstandardaction.h>
68 #include <QCloseEvent>
71 #include <QDockWidget>
73 DolphinMainWindow::DolphinMainWindow() :
79 setObjectName("Dolphin");
80 m_view
[PrimaryIdx
] = 0;
81 m_view
[SecondaryIdx
] = 0;
83 KonqUndoManager::incRef();
85 connect(KonqUndoManager::self(), SIGNAL(undoAvailable(bool)),
86 this, SLOT(slotUndoAvailable(bool)));
87 connect(KonqUndoManager::self(), SIGNAL(undoTextChanged(const QString
&)),
88 this, SLOT(slotUndoTextChanged(const QString
&)));
91 DolphinMainWindow::~DolphinMainWindow()
93 KonqUndoManager::decRef();
94 DolphinApplication::app()->removeMainWindow(this);
97 void DolphinMainWindow::setActiveView(DolphinView
* view
)
99 assert((view
== m_view
[PrimaryIdx
]) || (view
== m_view
[SecondaryIdx
]));
100 if (m_activeView
== view
) {
111 setCaption(m_activeView
->url().fileName());
113 emit
activeViewChanged();
116 void DolphinMainWindow::dropUrls(const KUrl::List
& urls
,
117 const KUrl
& destination
)
119 Qt::DropAction action
= Qt::CopyAction
;
121 Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
122 const bool shiftPressed
= modifier
& Qt::ShiftModifier
;
123 const bool controlPressed
= modifier
& Qt::ControlModifier
;
124 if (shiftPressed
&& controlPressed
) {
125 // shortcut for 'Link Here' is used
126 action
= Qt::LinkAction
;
128 else if (shiftPressed
) {
129 // shortcut for 'Move Here' is used
130 action
= Qt::MoveAction
;
132 else if (controlPressed
) {
133 // shortcut for 'Copy Here' is used
134 action
= Qt::CopyAction
;
137 // open a context menu which offers the following actions:
145 QString seq
= QKeySequence(Qt::ShiftModifier
).toString();
146 seq
.chop(1); // chop superfluous '+'
147 QAction
* moveAction
= popup
.addAction(KIcon("goto"),
148 i18n("&Move Here") + "\t" + seq
);
150 seq
= QKeySequence(Qt::ControlModifier
).toString();
152 QAction
* copyAction
= popup
.addAction(KIcon("editcopy"),
153 i18n("&Copy Here") + "\t" + seq
);
155 seq
= QKeySequence(Qt::ControlModifier
+ Qt::ShiftModifier
).toString();
157 QAction
* linkAction
= popup
.addAction(KIcon("www"),
158 i18n("&Link Here") + "\t" + seq
);
160 popup
.addSeparator();
161 popup
.addAction(KIcon("stop"), i18n("Cancel"));
163 QAction
* activatedAction
= popup
.exec(QCursor::pos());
164 if (activatedAction
== moveAction
) {
165 action
= Qt::MoveAction
;
167 else if (activatedAction
== copyAction
) {
168 action
= Qt::CopyAction
;
170 else if (activatedAction
== linkAction
) {
171 action
= Qt::LinkAction
;
177 moveUrls(urls
, destination
);
181 copyUrls(urls
, destination
);
185 KonqOperations::copy(this, KonqOperations::LINK
, urls
, destination
);
186 m_undoOperations
.append(KonqOperations::LINK
);
194 void DolphinMainWindow::refreshViews()
196 const bool split
= DolphinSettings::instance().generalSettings()->splitView();
197 const bool isPrimaryViewActive
= (m_activeView
== m_view
[PrimaryIdx
]);
199 for (int i
= PrimaryIdx
; i
<= SecondaryIdx
; ++i
) {
200 if (m_view
[i
] != 0) {
201 url
= m_view
[i
]->url();
203 // delete view instance...
205 m_view
[i
]->deleteLater();
209 if (split
|| (i
== PrimaryIdx
)) {
210 // ... and recreate it
211 ViewProperties
props(url
);
212 m_view
[i
] = new DolphinView(this,
216 props
.showHiddenFiles());
217 connectViewSignals(i
);
222 m_activeView
= isPrimaryViewActive
? m_view
[PrimaryIdx
] : m_view
[SecondaryIdx
];
223 assert(m_activeView
!= 0);
226 emit
activeViewChanged();
229 void DolphinMainWindow::slotViewModeChanged()
234 void DolphinMainWindow::slotShowHiddenFilesChanged()
236 KToggleAction
* showHiddenFilesAction
=
237 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
238 showHiddenFilesAction
->setChecked(m_activeView
->showHiddenFiles());
241 void DolphinMainWindow::slotSortingChanged(DolphinView::Sorting sorting
)
245 case DolphinView::SortByName
:
246 action
= actionCollection()->action("by_name");
248 case DolphinView::SortBySize
:
249 action
= actionCollection()->action("by_size");
251 case DolphinView::SortByDate
:
252 action
= actionCollection()->action("by_date");
259 KToggleAction
* toggleAction
= static_cast<KToggleAction
*>(action
);
260 toggleAction
->setChecked(true);
264 void DolphinMainWindow::slotSortOrderChanged(Qt::SortOrder order
)
266 KToggleAction
* descending
= static_cast<KToggleAction
*>(actionCollection()->action("descending"));
267 const bool sortDescending
= (order
== Qt::Descending
);
268 descending
->setChecked(sortDescending
);
271 void DolphinMainWindow::slotSelectionChanged()
275 assert(m_view
[PrimaryIdx
] != 0);
276 int selectedUrlsCount
= m_view
[PrimaryIdx
]->selectedUrls().count();
277 if (m_view
[SecondaryIdx
] != 0) {
278 selectedUrlsCount
+= m_view
[SecondaryIdx
]->selectedUrls().count();
281 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
282 compareFilesAction
->setEnabled(selectedUrlsCount
== 2);
284 m_activeView
->updateStatusBar();
286 emit
selectionChanged();
289 void DolphinMainWindow::slotHistoryChanged()
294 void DolphinMainWindow::slotUrlChanged(const KUrl
& url
)
298 setCaption(url
.fileName());
301 void DolphinMainWindow::updateFilterBarAction(bool show
)
303 KToggleAction
* showFilterBarAction
=
304 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
305 showFilterBarAction
->setChecked(show
);
308 void DolphinMainWindow::openNewMainWindow()
310 DolphinApplication::app()->createMainWindow()->show();
313 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
315 DolphinSettings
& settings
= DolphinSettings::instance();
316 GeneralSettings
* generalSettings
= settings
.generalSettings();
317 generalSettings
->setFirstRun(false);
321 // TODO: I assume there will be a generic way in KDE 4 to store the docks
322 // of the main window. In the meantime they are stored manually:
323 QString filename
= KStandardDirs::locateLocal("data", KGlobal::instance()->instanceName());
324 filename
.append("/panels_layout");
325 QFile
file(filename
);
326 if (file
.open(QIODevice::WriteOnly
)) {
327 QByteArray data
= saveState();
332 KMainWindow::closeEvent(event
);
335 void DolphinMainWindow::saveProperties(KConfig
* config
)
337 config
->setGroup("Primary view");
338 config
->writeEntry("Url", m_view
[PrimaryIdx
]->url().url());
339 config
->writeEntry("Editable Url", m_view
[PrimaryIdx
]->isUrlEditable());
340 if (m_view
[SecondaryIdx
] != 0) {
341 config
->setGroup("Secondary view");
342 config
->writeEntry("Url", m_view
[SecondaryIdx
]->url().url());
343 config
->writeEntry("Editable Url", m_view
[SecondaryIdx
]->isUrlEditable());
347 void DolphinMainWindow::readProperties(KConfig
* config
)
349 config
->setGroup("Primary view");
350 m_view
[PrimaryIdx
]->setUrl(config
->readEntry("Url"));
351 m_view
[PrimaryIdx
]->setUrlEditable(config
->readEntry("Editable Url", false));
352 if (config
->hasGroup("Secondary view")) {
353 config
->setGroup("Secondary view");
354 if (m_view
[SecondaryIdx
] == 0) {
357 m_view
[SecondaryIdx
]->setUrl(config
->readEntry("Url"));
358 m_view
[SecondaryIdx
]->setUrlEditable(config
->readEntry("Editable Url", false));
360 else if (m_view
[SecondaryIdx
] != 0) {
365 void DolphinMainWindow::updateNewMenu()
367 m_newMenu
->slotCheckUpToDate();
368 m_newMenu
->setPopupFiles(activeView()->url());
371 void DolphinMainWindow::rename()
374 m_activeView
->renameSelectedItems();
377 void DolphinMainWindow::moveToTrash()
380 const KUrl::List selectedUrls
= m_activeView
->selectedUrls();
381 KonqOperations::del(this, KonqOperations::TRASH
, selectedUrls
);
382 m_undoOperations
.append(KonqOperations::TRASH
);
385 void DolphinMainWindow::deleteItems()
389 KUrl::List list
= m_activeView
->selectedUrls();
390 const uint itemCount
= list
.count();
391 assert(itemCount
>= 1);
395 text
= i18n("Do you really want to delete the %1 selected items?",itemCount
);
398 const KUrl
& url
= list
.first();
399 text
= i18n("Do you really want to delete '%1'?",url
.fileName());
402 const bool del
= KMessageBox::warningContinueCancel(this,
405 KGuiItem(i18n("Delete"), KIcon("editdelete"))
406 ) == KMessageBox::Continue
;
408 KIO::Job
* job
= KIO::del(list
);
409 connect(job
, SIGNAL(result(KJob
*)),
410 this, SLOT(slotHandleJobError(KJob
*)));
411 connect(job
, SIGNAL(result(KJob
*)),
412 this, SLOT(slotDeleteFileFinished(KJob
*)));
416 void DolphinMainWindow::properties()
418 const KFileItemList list
= m_activeView
->selectedItems();
419 new KPropertiesDialog(list
, this);
422 void DolphinMainWindow::quit()
427 void DolphinMainWindow::slotHandleJobError(KJob
* job
)
429 if (job
->error() != 0) {
430 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
431 statusBar
->setMessage(job
->errorString(),
432 DolphinStatusBar::Error
);
436 void DolphinMainWindow::slotDeleteFileFinished(KJob
* job
)
438 if (job
->error() == 0) {
439 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
440 statusBar
->setMessage(i18n("Delete operation completed."),
441 DolphinStatusBar::OperationCompleted
);
445 void DolphinMainWindow::slotUndoAvailable(bool available
)
447 QAction
* undoAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::Undo
));
448 if (undoAction
!= 0) {
449 undoAction
->setEnabled(available
);
452 if (available
&& (m_undoOperations
.count() > 0)) {
453 const KonqOperations::Operation op
= m_undoOperations
.takeFirst();
454 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
456 case KonqOperations::COPY
:
457 statusBar
->setMessage(i18n("Copy operation completed."),
458 DolphinStatusBar::OperationCompleted
);
460 case KonqOperations::MOVE
:
461 statusBar
->setMessage(i18n("Move operation completed."),
462 DolphinStatusBar::OperationCompleted
);
464 case KonqOperations::LINK
:
465 statusBar
->setMessage(i18n("Link operation completed."),
466 DolphinStatusBar::OperationCompleted
);
468 case KonqOperations::TRASH
:
469 statusBar
->setMessage(i18n("Move to trash operation completed."),
470 DolphinStatusBar::OperationCompleted
);
479 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
481 QAction
* undoAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::Undo
));
482 if (undoAction
!= 0) {
483 undoAction
->setText(text
);
487 void DolphinMainWindow::cut()
489 QMimeData
* mimeData
= new QMimeData();
490 const KUrl::List kdeUrls
= m_activeView
->selectedUrls();
491 const KUrl::List mostLocalUrls
;
492 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, true);
493 QApplication::clipboard()->setMimeData(mimeData
);
496 void DolphinMainWindow::copy()
498 QMimeData
* mimeData
= new QMimeData();
499 const KUrl::List kdeUrls
= m_activeView
->selectedUrls();
500 const KUrl::List mostLocalUrls
;
501 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, false);
503 QApplication::clipboard()->setMimeData(mimeData
);
506 void DolphinMainWindow::paste()
508 QClipboard
* clipboard
= QApplication::clipboard();
509 const QMimeData
* mimeData
= clipboard
->mimeData();
513 const KUrl::List sourceUrls
= KUrl::List::fromMimeData(mimeData
);
515 // per default the pasting is done into the current Url of the view
516 KUrl
destUrl(m_activeView
->url());
518 // check whether the pasting should be done into a selected directory
519 KUrl::List selectedUrls
= m_activeView
->selectedUrls();
520 if (selectedUrls
.count() == 1) {
521 const KFileItem
fileItem(S_IFDIR
,
523 selectedUrls
.first(),
525 if (fileItem
.isDir()) {
526 // only one item is selected which is a directory, hence paste
527 // into this directory
528 destUrl
= selectedUrls
.first();
532 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
533 moveUrls(sourceUrls
, destUrl
);
537 copyUrls(sourceUrls
, destUrl
);
541 void DolphinMainWindow::updatePasteAction()
543 QAction
* pasteAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::Paste
));
544 if (pasteAction
== 0) {
548 QString
text(i18n("Paste"));
549 QClipboard
* clipboard
= QApplication::clipboard();
550 const QMimeData
* mimeData
= clipboard
->mimeData();
552 KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
553 if (!urls
.isEmpty()) {
554 pasteAction
->setEnabled(true);
556 const int count
= urls
.count();
558 pasteAction
->setText(i18n("Paste 1 File"));
561 pasteAction
->setText(i18n("Paste %1 Files").arg(count
));
565 pasteAction
->setEnabled(false);
566 pasteAction
->setText(i18n("Paste"));
569 if (pasteAction
->isEnabled()) {
570 KUrl::List urls
= m_activeView
->selectedUrls();
571 const uint count
= urls
.count();
573 // pasting should not be allowed when more than one file
575 pasteAction
->setEnabled(false);
577 else if (count
== 1) {
578 // Only one file is selected. Pasting is only allowed if this
579 // file is a directory.
580 // TODO: this doesn't work with remote protocols; instead we need a
581 // m_activeView->selectedFileItems() to get the real KFileItems
582 const KFileItem
fileItem(S_IFDIR
,
586 pasteAction
->setEnabled(fileItem
.isDir());
591 void DolphinMainWindow::selectAll()
594 m_activeView
->selectAll();
597 void DolphinMainWindow::invertSelection()
600 m_activeView
->invertSelection();
602 void DolphinMainWindow::setIconsView()
604 m_activeView
->setMode(DolphinView::IconsView
);
607 void DolphinMainWindow::setDetailsView()
609 m_activeView
->setMode(DolphinView::DetailsView
);
612 void DolphinMainWindow::sortByName()
614 m_activeView
->setSorting(DolphinView::SortByName
);
617 void DolphinMainWindow::sortBySize()
619 m_activeView
->setSorting(DolphinView::SortBySize
);
622 void DolphinMainWindow::sortByDate()
624 m_activeView
->setSorting(DolphinView::SortByDate
);
627 void DolphinMainWindow::toggleSortOrder()
629 const Qt::SortOrder order
= (m_activeView
->sortOrder() == Qt::Ascending
) ?
632 m_activeView
->setSortOrder(order
);
635 void DolphinMainWindow::toggleSplitView()
637 if (m_view
[SecondaryIdx
] == 0) {
638 const int newWidth
= (m_view
[PrimaryIdx
]->width() - m_splitter
->handleWidth()) / 2;
639 // create a secondary view
640 m_view
[SecondaryIdx
] = new DolphinView(this,
642 m_view
[PrimaryIdx
]->url(),
643 m_view
[PrimaryIdx
]->mode(),
644 m_view
[PrimaryIdx
]->showHiddenFiles());
645 connectViewSignals(SecondaryIdx
);
646 m_splitter
->addWidget(m_view
[SecondaryIdx
]);
647 m_splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
648 m_view
[SecondaryIdx
]->show();
651 // remove secondary view
652 if (m_activeView
== m_view
[PrimaryIdx
]) {
653 m_view
[SecondaryIdx
]->close();
654 m_view
[SecondaryIdx
]->deleteLater();
655 m_view
[SecondaryIdx
] = 0;
656 setActiveView(m_view
[PrimaryIdx
]);
659 // The secondary view is active, hence from the users point of view
660 // the content of the secondary view should be moved to the primary view.
661 // From an implementation point of view it is more efficient to close
662 // the primary view and exchange the internal pointers afterwards.
663 m_view
[PrimaryIdx
]->close();
664 delete m_view
[PrimaryIdx
];
665 m_view
[PrimaryIdx
] = m_view
[SecondaryIdx
];
666 m_view
[SecondaryIdx
] = 0;
667 setActiveView(m_view
[PrimaryIdx
]);
672 void DolphinMainWindow::reloadView()
675 m_activeView
->reload();
678 void DolphinMainWindow::stopLoading()
682 void DolphinMainWindow::togglePreview()
686 const KToggleAction
* showPreviewAction
=
687 static_cast<KToggleAction
*>(actionCollection()->action("show_preview"));
688 const bool show
= showPreviewAction
->isChecked();
689 m_activeView
->setShowPreview(show
);
692 void DolphinMainWindow::toggleShowHiddenFiles()
696 const KToggleAction
* showHiddenFilesAction
=
697 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
698 const bool show
= showHiddenFilesAction
->isChecked();
699 m_activeView
->setShowHiddenFiles(show
);
702 void DolphinMainWindow::showFilterBar()
704 const KToggleAction
* showFilterBarAction
=
705 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
706 const bool show
= showFilterBarAction
->isChecked();
707 m_activeView
->showFilterBar(show
);
710 void DolphinMainWindow::zoomIn()
712 m_activeView
->zoomIn();
716 void DolphinMainWindow::zoomOut()
718 m_activeView
->zoomOut();
722 void DolphinMainWindow::toggleEditLocation()
726 KToggleAction
* action
= static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
728 bool editOrBrowse
= action
->isChecked();
729 m_activeView
->setUrlEditable(editOrBrowse
);
732 void DolphinMainWindow::editLocation()
734 KToggleAction
* action
= static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
735 action
->setChecked(true);
736 m_activeView
->setUrlEditable(true);
739 void DolphinMainWindow::adjustViewProperties()
742 ViewPropertiesDialog
dlg(m_activeView
);
746 void DolphinMainWindow::goBack()
749 m_activeView
->goBack();
752 void DolphinMainWindow::goForward()
755 m_activeView
->goForward();
758 void DolphinMainWindow::goUp()
761 m_activeView
->goUp();
764 void DolphinMainWindow::goHome()
767 m_activeView
->goHome();
770 void DolphinMainWindow::openTerminal()
772 QString
command("konsole --workdir \"");
773 command
.append(m_activeView
->url().path());
774 command
.append('\"');
776 KRun::runCommand(command
, "Konsole", "konsole");
779 void DolphinMainWindow::findFile()
781 KRun::run("kfind", m_activeView
->url());
784 void DolphinMainWindow::compareFiles()
786 // The method is only invoked if exactly 2 files have
787 // been selected. The selected files may be:
788 // - both in the primary view
789 // - both in the secondary view
790 // - one in the primary view and the other in the secondary
792 assert(m_view
[PrimaryIdx
] != 0);
796 KUrl::List urls
= m_view
[PrimaryIdx
]->selectedUrls();
798 switch (urls
.count()) {
800 assert(m_view
[SecondaryIdx
] != 0);
801 urls
= m_view
[SecondaryIdx
]->selectedUrls();
802 assert(urls
.count() == 2);
810 assert(m_view
[SecondaryIdx
] != 0);
811 urls
= m_view
[SecondaryIdx
]->selectedUrls();
812 assert(urls
.count() == 1);
824 // may not happen: compareFiles may only get invoked if 2
825 // files are selected
830 QString
command("kompare -c \"");
831 command
.append(urlA
.pathOrUrl());
832 command
.append("\" \"");
833 command
.append(urlB
.pathOrUrl());
834 command
.append('\"');
835 KRun::runCommand(command
, "Kompare", "kompare");
839 void DolphinMainWindow::editSettings()
841 // TODO: make a static method for opening the settings dialog
842 DolphinSettingsDialog
dlg(this);
846 void DolphinMainWindow::init()
848 // Check whether Dolphin runs the first time. If yes then
849 // a proper default window size is given at the end of DolphinMainWindow::init().
850 GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
851 const bool firstRun
= generalSettings
->firstRun();
853 setAcceptDrops(true);
855 m_splitter
= new QSplitter(this);
857 DolphinSettings
& settings
= DolphinSettings::instance();
859 KBookmarkManager
* manager
= settings
.bookmarkManager();
860 assert(manager
!= 0);
861 KBookmarkGroup root
= manager
->root();
862 if (root
.first().isNull()) {
863 root
.addBookmark(manager
, i18n("Home"), settings
.generalSettings()->homeUrl(), "folder_home");
864 root
.addBookmark(manager
, i18n("Storage Media"), KUrl("media:/"), "blockdevice");
865 root
.addBookmark(manager
, i18n("Network"), KUrl("remote:/"), "network_local");
866 root
.addBookmark(manager
, i18n("Root"), KUrl("/"), "folder_red");
867 root
.addBookmark(manager
, i18n("Trash"), KUrl("trash:/"), "trashcan_full");
872 const KUrl
& homeUrl
= root
.first().url();
873 setCaption(homeUrl
.fileName());
874 ViewProperties
props(homeUrl
);
875 m_view
[PrimaryIdx
] = new DolphinView(this,
879 props
.showHiddenFiles());
880 connectViewSignals(PrimaryIdx
);
881 m_view
[PrimaryIdx
]->show();
883 m_activeView
= m_view
[PrimaryIdx
];
885 setCentralWidget(m_splitter
);
888 setupGUI(Keys
|Save
|Create
|ToolBar
);
891 stateChanged("new_file");
892 setAutoSaveSettings();
894 QClipboard
* clipboard
= QApplication::clipboard();
895 connect(clipboard
, SIGNAL(dataChanged()),
896 this, SLOT(updatePasteAction()));
903 // assure a proper default size if Dolphin runs the first time
908 void DolphinMainWindow::loadSettings()
910 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
912 KToggleAction
* splitAction
= static_cast<KToggleAction
*>(actionCollection()->action("split_view"));
913 if (settings
->splitView()) {
914 splitAction
->setChecked(true);
920 // TODO: I assume there will be a generic way in KDE 4 to restore the docks
921 // of the main window. In the meantime they are restored manually (see also
922 // DolphinMainWindow::closeEvent() for more details):
923 QString filename
= KStandardDirs::locateLocal("data", KGlobal::instance()->instanceName());
924 filename
.append("/panels_layout");
925 QFile
file(filename
);
926 if (file
.open(QIODevice::ReadOnly
)) {
927 QByteArray data
= file
.readAll();
933 void DolphinMainWindow::setupActions()
936 m_newMenu
= new KNewMenu(actionCollection(), this, "create_new");
937 KMenu
* menu
= m_newMenu
->menu();
938 menu
->setTitle(i18n("Create New..."));
939 menu
->setIcon(SmallIcon("filenew"));
940 connect(menu
, SIGNAL(aboutToShow()),
941 this, SLOT(updateNewMenu()));
943 QAction
* action
= actionCollection()->addAction("new_window");
944 action
->setIcon(KIcon("window_new"));
945 action
->setText(i18n("New &Window"));
946 connect(action
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
948 QAction
* rename
= actionCollection()->addAction("rename");
949 rename
->setText(i18n("Rename"));
950 rename
->setShortcut(Qt::Key_F2
);
951 connect(rename
, SIGNAL(triggered()), this, SLOT(rename()));
953 QAction
* moveToTrash
= actionCollection()->addAction("move_to_trash");
954 moveToTrash
->setText(i18n("Move to Trash"));
955 moveToTrash
->setIcon(KIcon("edittrash"));
956 moveToTrash
->setShortcut(QKeySequence::Delete
);
957 connect(moveToTrash
, SIGNAL(triggered()), this, SLOT(moveToTrash()));
959 QAction
* deleteAction
= actionCollection()->addAction("delete");
960 deleteAction
->setText(i18n("Delete"));
961 deleteAction
->setShortcut(Qt::ALT
| Qt::Key_Delete
);
962 deleteAction
->setIcon(KIcon("editdelete"));
963 connect(deleteAction
, SIGNAL(triggered()), this, SLOT(deleteItems()));
965 QAction
* properties
= actionCollection()->addAction("properties");
966 properties
->setText(i18n("Propert&ies"));
967 properties
->setShortcut(Qt::Key_Alt
| Qt::Key_Return
);
968 connect(properties
, SIGNAL(triggered()), this, SLOT(properties()));
970 KStandardAction::quit(this, SLOT(quit()), actionCollection());
973 KStandardAction::undo(KonqUndoManager::self(),
977 KStandardAction::cut(this, SLOT(cut()), actionCollection());
978 KStandardAction::copy(this, SLOT(copy()), actionCollection());
979 KStandardAction::paste(this, SLOT(paste()), actionCollection());
981 QAction
* selectAll
= actionCollection()->addAction("select_all");
982 selectAll
->setText(i18n("Select All"));
983 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
984 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
986 QAction
* invertSelection
= actionCollection()->addAction("invert_selection");
987 invertSelection
->setText(i18n("Invert Selection"));
988 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
989 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
992 KStandardAction::zoomIn(this,
996 KStandardAction::zoomOut(this,
1000 KToggleAction
* iconsView
= actionCollection()->add
<KToggleAction
>("icons");
1001 iconsView
->setText(i18n("Icons"));
1002 iconsView
->setShortcut(Qt::CTRL
| Qt::Key_1
);
1003 iconsView
->setIcon(KIcon("view_icon"));
1004 connect(iconsView
, SIGNAL(triggered()), this, SLOT(setIconsView()));
1006 KToggleAction
* detailsView
= actionCollection()->add
<KToggleAction
>("details");
1007 detailsView
->setText(i18n("Details"));
1008 detailsView
->setShortcut(Qt::CTRL
| Qt::Key_2
);
1009 detailsView
->setIcon(KIcon("view_text"));
1010 connect(detailsView
, SIGNAL(triggered()), this, SLOT(setDetailsView()));
1012 QActionGroup
* viewModeGroup
= new QActionGroup(this);
1013 viewModeGroup
->addAction(iconsView
);
1014 viewModeGroup
->addAction(detailsView
);
1016 KToggleAction
* sortByName
= actionCollection()->add
<KToggleAction
>("by_name");
1017 sortByName
->setText(i18n("By Name"));
1018 connect(sortByName
, SIGNAL(triggered()), this, SLOT(sortByName()));
1020 KToggleAction
* sortBySize
= actionCollection()->add
<KToggleAction
>("by_size");
1021 sortBySize
->setText(i18n("By Size"));
1022 connect(sortBySize
, SIGNAL(triggered()), this, SLOT(sortBySize()));
1024 KToggleAction
* sortByDate
= actionCollection()->add
<KToggleAction
>("by_date");
1025 sortByDate
->setText(i18n("By Date"));
1026 connect(sortByDate
, SIGNAL(triggered()), this, SLOT(sortByDate()));
1028 QActionGroup
* sortGroup
= new QActionGroup(this);
1029 sortGroup
->addAction(sortByName
);
1030 sortGroup
->addAction(sortBySize
);
1031 sortGroup
->addAction(sortByDate
);
1033 KToggleAction
* sortDescending
= actionCollection()->add
<KToggleAction
>("descending");
1034 sortDescending
->setText(i18n("Descending"));
1035 connect(sortDescending
, SIGNAL(triggered()), this, SLOT(toggleSortOrder()));
1037 KToggleAction
* showPreview
= actionCollection()->add
<KToggleAction
>("show_preview");
1038 showPreview
->setText(i18n("Show Preview"));
1039 connect(showPreview
, SIGNAL(triggered()), this, SLOT(togglePreview()));
1041 KToggleAction
* showHiddenFiles
= actionCollection()->add
<KToggleAction
>("show_hidden_files");
1042 showHiddenFiles
->setText(i18n("Show Hidden Files"));
1043 //showHiddenFiles->setShortcut(Qt::ALT | Qt::Key_ KDE4-TODO: what Qt-Key represents '.'?
1044 connect(showHiddenFiles
, SIGNAL(triggered()), this, SLOT(toggleShowHiddenFiles()));
1046 KToggleAction
* split
= actionCollection()->add
<KToggleAction
>("split_view");
1047 split
->setText(i18n("Split View"));
1048 split
->setShortcut(Qt::Key_F10
);
1049 split
->setIcon(KIcon("view_left_right"));
1050 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1052 QAction
* reload
= actionCollection()->addAction("reload");
1053 reload
->setText(i18n("Reload"));
1054 reload
->setShortcut(Qt::Key_F5
);
1055 reload
->setIcon(KIcon("reload"));
1056 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1058 QAction
* stop
= actionCollection()->addAction("stop");
1059 stop
->setText(i18n("Stop"));
1060 stop
->setIcon(KIcon("stop"));
1061 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1063 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1064 showFullLocation
->setText(i18n("Show Full Location"));
1065 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1066 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1068 KToggleAction
* editLocation
= actionCollection()->add
<KToggleAction
>("edit_location");
1069 editLocation
->setText(i18n("Edit Location"));
1070 editLocation
->setShortcut(Qt::Key_F6
);
1071 connect(editLocation
, SIGNAL(triggered()), this, SLOT(editLocation()));
1073 QAction
* adjustViewProps
= actionCollection()->addAction("view_properties");
1074 adjustViewProps
->setText(i18n("Adjust View Properties..."));
1075 connect(adjustViewProps
, SIGNAL(triggered()), this, SLOT(adjustViewProperties()));
1078 KStandardAction::back(this, SLOT(goBack()), actionCollection());
1079 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1080 KStandardAction::up(this, SLOT(goUp()), actionCollection());
1081 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1083 // setup 'Tools' menu
1084 QAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1085 openTerminal
->setText(i18n("Open Terminal"));
1086 openTerminal
->setShortcut(Qt::Key_F4
);
1087 openTerminal
->setIcon(KIcon("konsole"));
1088 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1090 QAction
* findFile
= actionCollection()->addAction("find_file");
1091 findFile
->setText(i18n("Find File..."));
1092 findFile
->setShortcut(Qt::Key_F
);
1093 findFile
->setIcon(KIcon("filefind"));
1094 connect(findFile
, SIGNAL(triggered()), this, SLOT(findFile()));
1096 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
1097 showFilterBar
->setText(i18n("Show Filter Bar"));
1098 showFilterBar
->setShortcut(Qt::Key_Slash
);
1099 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1101 QAction
* compareFiles
= actionCollection()->addAction("compare_files");
1102 compareFiles
->setText(i18n("Compare Files"));
1103 compareFiles
->setIcon(KIcon("kompare"));
1104 compareFiles
->setEnabled(false);
1105 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1107 // setup 'Settings' menu
1108 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1111 void DolphinMainWindow::setupDockWidgets()
1113 QDockWidget
* shortcutsDock
= new QDockWidget(i18n("Bookmarks"));
1114 shortcutsDock
->setObjectName("bookmarksDock");
1115 shortcutsDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1116 shortcutsDock
->setWidget(new BookmarksSidebarPage(this));
1118 shortcutsDock
->toggleViewAction()->setText(i18n("Show Bookmarks Panel"));
1119 actionCollection()->addAction("show_bookmarks_panel", shortcutsDock
->toggleViewAction());
1121 addDockWidget(Qt::LeftDockWidgetArea
, shortcutsDock
);
1123 QDockWidget
* infoDock
= new QDockWidget(i18n("Information"));
1124 infoDock
->setObjectName("infoDock");
1125 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1126 infoDock
->setWidget(new InfoSidebarPage(this));
1128 infoDock
->toggleViewAction()->setText(i18n("Show Information Panel"));
1129 actionCollection()->addAction("show_info_panel", infoDock
->toggleViewAction());
1131 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1134 void DolphinMainWindow::updateHistory()
1137 const QLinkedList
<UrlNavigator::HistoryElem
> list
= m_activeView
->urlHistory(index
);
1139 QAction
* backAction
= actionCollection()->action("go_back");
1140 if (backAction
!= 0) {
1141 backAction
->setEnabled(index
< static_cast<int>(list
.count()) - 1);
1144 QAction
* forwardAction
= actionCollection()->action("go_forward");
1145 if (forwardAction
!= 0) {
1146 forwardAction
->setEnabled(index
> 0);
1150 void DolphinMainWindow::updateEditActions()
1152 const KFileItemList list
= m_activeView
->selectedItems();
1153 if (list
.isEmpty()) {
1154 stateChanged("has_no_selection");
1157 stateChanged("has_selection");
1159 QAction
* renameAction
= actionCollection()->action("rename");
1160 if (renameAction
!= 0) {
1161 renameAction
->setEnabled(list
.count() >= 1);
1164 bool enableMoveToTrash
= true;
1166 KFileItemList::const_iterator it
= list
.begin();
1167 const KFileItemList::const_iterator end
= list
.end();
1169 KFileItem
* item
= *it
;
1170 const KUrl
& url
= item
->url();
1171 // only enable the 'Move to Trash' action for local files
1172 if (!url
.isLocalFile()) {
1173 enableMoveToTrash
= false;
1178 QAction
* moveToTrashAction
= actionCollection()->action("move_to_trash");
1179 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1181 updatePasteAction();
1184 void DolphinMainWindow::updateViewActions()
1186 QAction
* zoomInAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::ZoomIn
));
1187 if (zoomInAction
!= 0) {
1188 zoomInAction
->setEnabled(m_activeView
->isZoomInPossible());
1191 QAction
* zoomOutAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::ZoomOut
));
1192 if (zoomOutAction
!= 0) {
1193 zoomOutAction
->setEnabled(m_activeView
->isZoomOutPossible());
1196 QAction
* action
= 0;
1197 switch (m_activeView
->mode()) {
1198 case DolphinView::IconsView
:
1199 action
= actionCollection()->action("icons");
1201 case DolphinView::DetailsView
:
1202 action
= actionCollection()->action("details");
1209 KToggleAction
* toggleAction
= static_cast<KToggleAction
*>(action
);
1210 toggleAction
->setChecked(true);
1213 slotSortingChanged(m_activeView
->sorting());
1214 slotSortOrderChanged(m_activeView
->sortOrder());
1216 KToggleAction
* showFilterBarAction
=
1217 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
1218 showFilterBarAction
->setChecked(m_activeView
->isFilterBarVisible());
1220 KToggleAction
* showHiddenFilesAction
=
1221 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
1222 showHiddenFilesAction
->setChecked(m_activeView
->showHiddenFiles());
1224 KToggleAction
* splitAction
= static_cast<KToggleAction
*>(actionCollection()->action("split_view"));
1225 splitAction
->setChecked(m_view
[SecondaryIdx
] != 0);
1228 void DolphinMainWindow::updateGoActions()
1230 QAction
* goUpAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::Up
));
1231 const KUrl
& currentUrl
= m_activeView
->url();
1232 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1235 void DolphinMainWindow::copyUrls(const KUrl::List
& source
, const KUrl
& dest
)
1237 KonqOperations::copy(this, KonqOperations::COPY
, source
, dest
);
1238 m_undoOperations
.append(KonqOperations::COPY
);
1241 void DolphinMainWindow::moveUrls(const KUrl::List
& source
, const KUrl
& dest
)
1243 KonqOperations::copy(this, KonqOperations::MOVE
, source
, dest
);
1244 m_undoOperations
.append(KonqOperations::MOVE
);
1247 void DolphinMainWindow::clearStatusBar()
1249 m_activeView
->statusBar()->clear();
1252 void DolphinMainWindow::connectViewSignals(int viewIndex
)
1254 DolphinView
* view
= m_view
[viewIndex
];
1255 connect(view
, SIGNAL(modeChanged()),
1256 this, SLOT(slotViewModeChanged()));
1257 connect(view
, SIGNAL(showHiddenFilesChanged()),
1258 this, SLOT(slotShowHiddenFilesChanged()));
1259 connect(view
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
1260 this, SLOT(slotSortingChanged(DolphinView::Sorting
)));
1261 connect(view
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
1262 this, SLOT(slotSortOrderChanged(Qt::SortOrder
)));
1263 connect(view
, SIGNAL(selectionChanged()),
1264 this, SLOT(slotSelectionChanged()));
1265 connect(view
, SIGNAL(showFilterBarChanged(bool)),
1266 this, SLOT(updateFilterBarAction(bool)));
1268 const UrlNavigator
* navigator
= view
->urlNavigator();
1269 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1270 this, SLOT(slotUrlChanged(const KUrl
&)));
1271 connect(navigator
, SIGNAL(historyChanged()),
1272 this, SLOT(slotHistoryChanged()));
1276 #include "dolphinmainwindow.moc"