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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 m_fileGroupActions
.setAutoDelete(true);
91 // TODO: the following members are not used yet. See documentation
92 // of DolphinMainWindow::linkGroupActions() and DolphinMainWindow::linkToDeviceActions()
93 // in the header file for details.
94 //m_linkGroupActions.setAutoDelete(true);
95 //m_linkToDeviceActions.setAutoDelete(true);
98 DolphinMainWindow::~DolphinMainWindow()
101 * bye, bye managed window
103 DolphinApplication::app()->removeMainWindow( this );
106 void DolphinMainWindow::setActiveView(DolphinView
* view
)
108 assert((view
== m_view
[PrimaryIdx
]) || (view
== m_view
[SecondaryIdx
]));
109 if (m_activeView
== view
) {
120 setCaption(m_activeView
->url().fileName());
122 emit
activeViewChanged();
125 void DolphinMainWindow::dropUrls(const KUrl::List
& urls
,
126 const KUrl
& destination
)
128 int selectedIndex
= -1;
131 const ButtonState keyboardState = KApplication::keyboardMouseState();
132 const bool shiftPressed = (keyboardState & ShiftButton) > 0;
133 const bool controlPressed = (keyboardState & ControlButton) > 0;
137 if (shiftPressed && controlPressed) {
138 // shortcut for 'Linke Here' is used
141 else if (controlPressed) {
142 // shortcut for 'Copy Here' is used
145 else if (shiftPressed) {
146 // shortcut for 'Move Here' is used
150 // no shortcut is used, hence open a popup menu
153 popup
.insertItem(SmallIcon("goto"), i18n("&Move Here") + "\t" /* KDE4-TODO: + KKey::modFlagLabel(KKey::SHIFT)*/, 0);
154 popup
.insertItem(SmallIcon("editcopy"), i18n( "&Copy Here" ) /* KDE4-TODO + "\t" + KKey::modFlagLabel(KKey::CTRL)*/, 1);
155 popup
.insertItem(i18n("&Link Here") /* KDE4-TODO + "\t" + KKey::modFlagLabel((KKey::ModFlag)(KKey::CTRL|KKey::SHIFT)) */, 2);
156 popup
.insertSeparator();
157 popup
.insertItem(SmallIcon("stop"), i18n("Cancel"), 3);
158 popup
.setAccel(i18n("Escape"), 3);
160 /* KDE4-TODO: selectedIndex = popup.exec(QCursor::pos()); */
161 popup
.exec(QCursor::pos());
162 selectedIndex
= 0; // KD4-TODO: use QAction instead of switch below
163 // See libkonq/konq_operations.cc: KonqOperations::doDropFileCopy() (and doDrop, the main method)
166 if (selectedIndex
< 0) {
170 switch (selectedIndex
) {
172 // 'Move Here' has been selected
173 updateViewProperties(urls
);
174 moveUrls(urls
, destination
);
179 // 'Copy Here' has been selected
180 updateViewProperties(urls
);
181 copyUrls(urls
, destination
);
186 // 'Link Here' has been selected
187 KIO::Job
* job
= KIO::link(urls
, destination
);
188 addPendingUndoJob(job
, DolphinCommand::Link
, urls
, destination
);
193 // 'Cancel' has been selected
198 void DolphinMainWindow::refreshViews()
200 const bool split
= DolphinSettings::instance().generalSettings()->splitView();
201 const bool isPrimaryViewActive
= (m_activeView
== m_view
[PrimaryIdx
]);
203 for (int i
= PrimaryIdx
; i
<= SecondaryIdx
; ++i
) {
204 if (m_view
[i
] != 0) {
205 url
= m_view
[i
]->url();
207 // delete view instance...
209 m_view
[i
]->deleteLater();
213 if (split
|| (i
== PrimaryIdx
)) {
214 // ... and recreate it
215 ViewProperties
props(url
);
216 m_view
[i
] = new DolphinView(this,
220 props
.isShowHiddenFilesEnabled());
225 m_activeView
= isPrimaryViewActive
? m_view
[PrimaryIdx
] : m_view
[SecondaryIdx
];
226 assert(m_activeView
!= 0);
229 emit
activeViewChanged();
232 void DolphinMainWindow::slotHistoryChanged()
237 void DolphinMainWindow::slotUrlChanged(const KUrl
& url
)
241 setCaption(url
.fileName());
244 void DolphinMainWindow::slotUrlChangeRequest(const KUrl
& url
)
247 m_activeView
->setUrl(url
);
250 void DolphinMainWindow::slotViewModeChanged()
255 void DolphinMainWindow::slotShowHiddenFilesChanged()
257 KToggleAction
* showHiddenFilesAction
=
258 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
259 showHiddenFilesAction
->setChecked(m_activeView
->isShowHiddenFilesEnabled());
262 void DolphinMainWindow::slotShowFilterBarChanged()
264 KToggleAction
* showFilterBarAction
=
265 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
266 showFilterBarAction
->setChecked(m_activeView
->isFilterBarVisible());
269 void DolphinMainWindow::slotSortingChanged(DolphinView::Sorting sorting
)
273 case DolphinView::SortByName
:
274 action
= actionCollection()->action("by_name");
276 case DolphinView::SortBySize
:
277 action
= actionCollection()->action("by_size");
279 case DolphinView::SortByDate
:
280 action
= actionCollection()->action("by_date");
287 KToggleAction
* toggleAction
= static_cast<KToggleAction
*>(action
);
288 toggleAction
->setChecked(true);
292 void DolphinMainWindow::slotSortOrderChanged(Qt::SortOrder order
)
294 KToggleAction
* descending
= static_cast<KToggleAction
*>(actionCollection()->action("descending"));
295 const bool sortDescending
= (order
== Qt::Descending
);
296 descending
->setChecked(sortDescending
);
299 void DolphinMainWindow::slotSelectionChanged()
303 assert(m_view
[PrimaryIdx
] != 0);
304 int selectedUrlsCount
= m_view
[PrimaryIdx
]->selectedUrls().count();
305 if (m_view
[SecondaryIdx
] != 0) {
306 selectedUrlsCount
+= m_view
[SecondaryIdx
]->selectedUrls().count();
309 KAction
* compareFilesAction
= actionCollection()->action("compare_files");
310 compareFilesAction
->setEnabled(selectedUrlsCount
== 2);
312 m_activeView
->updateStatusBar();
314 emit
selectionChanged();
317 void DolphinMainWindow::slotRedo()
319 UndoManager::instance().redo(this);
322 void DolphinMainWindow::slotUndo()
324 UndoManager::instance().undo(this);
327 void DolphinMainWindow::slotNewMainWindow()
329 DolphinApplication::app()->createMainWindow()->show();
332 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
335 //KConfig* config = KGlobal::config();
336 //config->setGroup("General");
337 //config->writeEntry("First Run", false);
339 DolphinSettings
& settings
= DolphinSettings::instance();
340 GeneralSettings
* generalSettings
= settings
.generalSettings();
341 generalSettings
->setFirstRun(false);
345 KMainWindow::closeEvent(event
);
348 void DolphinMainWindow::saveProperties(KConfig
* config
)
350 config
->setGroup("Primary view");
351 config
->writeEntry("Url", m_view
[PrimaryIdx
]->url().url());
352 config
->writeEntry("Editable Url", m_view
[PrimaryIdx
]->isUrlEditable());
353 if (m_view
[SecondaryIdx
] != 0) {
354 config
->setGroup("Secondary view");
355 config
->writeEntry("Url", m_view
[SecondaryIdx
]->url().url());
356 config
->writeEntry("Editable Url", m_view
[SecondaryIdx
]->isUrlEditable());
360 void DolphinMainWindow::readProperties(KConfig
* config
)
362 config
->setGroup("Primary view");
363 m_view
[PrimaryIdx
]->setUrl(config
->readEntry("Url"));
364 m_view
[PrimaryIdx
]->setUrlEditable(config
->readBoolEntry("Editable Url"));
365 if (config
->hasGroup("Secondary view")) {
366 config
->setGroup("Secondary view");
367 if (m_view
[SecondaryIdx
] == 0) {
370 m_view
[SecondaryIdx
]->setUrl(config
->readEntry("Url"));
371 m_view
[SecondaryIdx
]->setUrlEditable(config
->readBoolEntry("Editable Url"));
373 else if (m_view
[SecondaryIdx
] != 0) {
378 void DolphinMainWindow::createFolder()
380 // Parts of the following code have been taken
381 // from the class KonqPopupMenu located in
382 // libqonq/konq_popupmenu.h of Konqueror.
383 // (Copyright (C) 2000 David Faure <faure@kde.org>,
384 // Copyright (C) 2001 Holger Freyther <freyther@yahoo.com>)
388 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
389 const KUrl
baseUrl(m_activeView
->url());
391 QString
name(i18n("New Folder"));
392 baseUrl
.path(KUrl::AddTrailingSlash
);
395 if (baseUrl
.isLocalFile() && QFileInfo(baseUrl
.path(KUrl::AddTrailingSlash
) + name
).exists()) {
396 name
= KIO::RenameDlg::suggestName(baseUrl
, i18n("New Folder"));
400 name
= KInputDialog::getText(i18n("New Folder"),
401 i18n("Enter folder name:" ),
407 // the user has pressed 'Cancel'
411 assert(!name
.isEmpty());
414 if ((name
[0] == '/') || (name
[0] == '~')) {
415 url
.setPath(KShell::tildeExpand(name
));
418 name
= KIO::encodeFileName(name
);
422 ok
= KIO::NetAccess::mkdir(url
, this);
424 // TODO: provide message type hint
426 statusBar
->setMessage(i18n("Created folder %1.",url
.path()),
427 DolphinStatusBar::OperationCompleted
);
429 DolphinCommand
command(DolphinCommand::CreateFolder
, KUrl::List(), url
);
430 UndoManager::instance().addCommand(command
);
433 // Creating of the folder has been failed. Check whether the creating
434 // has been failed because a folder with the same name exists...
435 if (KIO::NetAccess::exists(url
, true, this)) {
436 statusBar
->setMessage(i18n("A folder named %1 already exists.",url
.path()),
437 DolphinStatusBar::Error
);
440 statusBar
->setMessage(i18n("Creating of folder %1 failed.",url
.path()),
441 DolphinStatusBar::Error
);
447 void DolphinMainWindow::createFile()
449 // Parts of the following code have been taken
450 // from the class KonqPopupMenu located in
451 // libqonq/konq_popupmenu.h of Konqueror.
452 // (Copyright (C) 2000 David Faure <faure@kde.org>,
453 // Copyright (C) 2001 Holger Freyther <freyther@yahoo.com>)
457 // TODO: const Entry& entry = m_createFileTemplates[QString(sender->name())];
458 // should be enough. Anyway: the implemantation of [] does a linear search internally too.
459 KSortableList
<CreateFileEntry
, QString
>::ConstIterator it
= m_createFileTemplates
.begin();
460 KSortableList
<CreateFileEntry
, QString
>::ConstIterator end
= m_createFileTemplates
.end();
462 const QString
senderName(sender()->objectName());
464 CreateFileEntry entry
;
465 while (!found
&& (it
!= end
)) {
466 if ((*it
).index() == senderName
) {
467 entry
= (*it
).value();
475 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
476 if (!found
|| !QFile::exists(entry
.templatePath
)) {
477 statusBar
->setMessage(i18n("Could not create file."), DolphinStatusBar::Error
);
481 // Get the source path of the template which should be copied.
482 // The source path is part of the Url entry of the desktop file.
483 const int pos
= entry
.templatePath
.findRev('/');
484 QString
sourcePath(entry
.templatePath
.left(pos
+ 1));
485 sourcePath
+= KDesktopFile(entry
.templatePath
, true).readPathEntry("Url");
487 QString
name(i18n(entry
.name
.toAscii()));
488 // Most entry names end with "..." (e. g. "HTML File..."), which is ok for
489 // menus but no good choice for a new file name -> remove the dots...
490 name
.replace("...", QString::null
);
492 // add the file extension to the name
493 name
.append(sourcePath
.right(sourcePath
.length() - sourcePath
.findRev('.')));
495 // Check whether a file with the current name already exists. If yes suggest automatically
496 // a unique file name (e. g. "HTML File" will be replaced by "HTML File_1").
497 const KUrl
viewUrl(m_activeView
->url());
498 const bool fileExists
= viewUrl
.isLocalFile() &&
499 QFileInfo(viewUrl
.path(KUrl::AddTrailingSlash
) + KIO::encodeFileName(name
)).exists();
501 name
= KIO::RenameDlg::suggestName(viewUrl
, name
);
504 // let the user change the suggested file name
506 name
= KInputDialog::getText(entry
.name
,
512 // the user has pressed 'Cancel'
516 // before copying the template to the destination path check whether a file
517 // with the given name already exists
518 const QString
destPath(viewUrl
.pathOrUrl() + "/" + KIO::encodeFileName(name
));
519 const KUrl
destUrl(destPath
);
520 if (KIO::NetAccess::exists(destUrl
, false, this)) {
521 statusBar
->setMessage(i18n("A file named %1 already exists.",name
),
522 DolphinStatusBar::Error
);
526 // copy the template to the destination path
527 const KUrl
sourceUrl(sourcePath
);
528 KIO::CopyJob
* job
= KIO::copyAs(sourceUrl
, destUrl
);
529 job
->setDefaultPermissions(true);
530 if (KIO::NetAccess::synchronousRun(job
, this)) {
531 statusBar
->setMessage(i18n("Created file %1.",name
),
532 DolphinStatusBar::OperationCompleted
);
535 list
.append(sourceUrl
);
536 DolphinCommand
command(DolphinCommand::CreateFile
, list
, destUrl
);
537 UndoManager::instance().addCommand(command
);
541 statusBar
->setMessage(i18n("Creating of file %1 failed.",name
),
542 DolphinStatusBar::Error
);
546 void DolphinMainWindow::rename()
549 m_activeView
->renameSelectedItems();
552 void DolphinMainWindow::moveToTrash()
555 KUrl::List selectedUrls
= m_activeView
->selectedUrls();
556 KIO::Job
* job
= KIO::trash(selectedUrls
);
557 addPendingUndoJob(job
, DolphinCommand::Trash
, selectedUrls
, m_activeView
->url());
560 void DolphinMainWindow::deleteItems()
564 KUrl::List list
= m_activeView
->selectedUrls();
565 const uint itemCount
= list
.count();
566 assert(itemCount
>= 1);
570 text
= i18n("Do you really want to delete the %1 selected items?",itemCount
);
573 const KUrl
& url
= list
.first();
574 text
= i18n("Do you really want to delete '%1'?",url
.fileName());
577 const bool del
= KMessageBox::warningContinueCancel(this,
580 KGuiItem(i18n("Delete"), SmallIcon("editdelete"))
581 ) == KMessageBox::Continue
;
583 KIO::Job
* job
= KIO::del(list
);
584 connect(job
, SIGNAL(result(KJob
*)),
585 this, SLOT(slotHandleJobError(KJob
*)));
586 connect(job
, SIGNAL(result(KJob
*)),
587 this, SLOT(slotDeleteFileFinished(KJob
*)));
591 void DolphinMainWindow::properties()
593 const KFileItemList list
= m_activeView
->selectedItems();
594 new KPropertiesDialog(list
, this);
597 void DolphinMainWindow::quit()
602 void DolphinMainWindow::slotHandleJobError(KJob
* job
)
604 if (job
->error() != 0) {
605 m_activeView
->statusBar()->setMessage(job
->errorString(),
606 DolphinStatusBar::Error
);
610 void DolphinMainWindow::slotDeleteFileFinished(KJob
* job
)
612 if (job
->error() == 0) {
613 m_activeView
->statusBar()->setMessage(i18n("Delete operation completed."),
614 DolphinStatusBar::OperationCompleted
);
616 // TODO: In opposite to the 'Move to Trash' operation in the class KFileIconView
617 // no rearranging of the item position is done when a file has been deleted.
618 // This is bypassed by reloading the view, but it might be worth to investigate
619 // deeper for the root of this issue.
620 m_activeView
->reload();
624 void DolphinMainWindow::slotUndoAvailable(bool available
)
626 KAction
* undoAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Undo
));
627 if (undoAction
!= 0) {
628 undoAction
->setEnabled(available
);
632 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
634 KAction
* undoAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Undo
));
635 if (undoAction
!= 0) {
636 undoAction
->setText(text
);
640 void DolphinMainWindow::slotRedoAvailable(bool available
)
642 KAction
* redoAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Redo
));
643 if (redoAction
!= 0) {
644 redoAction
->setEnabled(available
);
648 void DolphinMainWindow::slotRedoTextChanged(const QString
& text
)
650 KAction
* redoAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Redo
));
651 if (redoAction
!= 0) {
652 redoAction
->setText(text
);
656 void DolphinMainWindow::cut()
658 // TODO: this boolean doesn't work between instances of dolphin or with konqueror or with other
659 // apps. The "application/x-kde-cutselection" mimetype should be used instead, see KonqMimeData
661 m_clipboardContainsCutData
= true;
662 /* KDE4-TODO: Q3DragObject* data = new KUrlDrag(m_activeView->selectedUrls(),
664 QApplication::clipboard()->setData(data);*/
667 void DolphinMainWindow::copy()
669 m_clipboardContainsCutData
= false;
671 Q3DragObject* data = new KUrlDrag(m_activeView->selectedUrls(),
673 QApplication::clipboard()->setData(data);*/
676 void DolphinMainWindow::paste()
678 /* KDE4-TODO: - see KonqOperations::doPaste
679 QClipboard* clipboard = QApplication::clipboard();
680 QMimeSource* data = clipboard->data();
681 if (!KUrlDrag::canDecode(data)) {
687 KUrl::List sourceUrls;
688 KUrlDrag::decode(data, sourceUrls);
690 // per default the pasting is done into the current Url of the view
691 KUrl destUrl(m_activeView->url());
693 // check whether the pasting should be done into a selected directory
694 KUrl::List selectedUrls = m_activeView->selectedUrls();
695 if (selectedUrls.count() == 1) {
696 const KFileItem fileItem(S_IFDIR,
698 selectedUrls.first(),
700 if (fileItem.isDir()) {
701 // only one item is selected which is a directory, hence paste
702 // into this directory
703 destUrl = selectedUrls.first();
708 updateViewProperties(sourceUrls);
709 if (m_clipboardContainsCutData) {
710 moveUrls(sourceUrls, destUrl);
711 m_clipboardContainsCutData = false;
715 copyUrls(sourceUrls, destUrl);
719 void DolphinMainWindow::updatePasteAction()
721 KAction
* pasteAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Paste
));
722 if (pasteAction
== 0) {
726 QString
text(i18n("Paste"));
727 QClipboard
* clipboard
= QApplication::clipboard();
728 QMimeSource
* data
= clipboard
->data();
730 if (KUrlDrag::canDecode(data)) {
731 pasteAction->setEnabled(true);
734 KUrlDrag::decode(data, urls);
735 const int count = urls.count();
737 pasteAction->setText(i18n("Paste 1 File"));
740 pasteAction->setText(i18n("Paste %1 Files").arg(count));
744 pasteAction
->setEnabled(false);
745 pasteAction
->setText(i18n("Paste"));
748 if (pasteAction
->isEnabled()) {
749 KUrl::List urls
= m_activeView
->selectedUrls();
750 const uint count
= urls
.count();
752 // pasting should not be allowed when more than one file
754 pasteAction
->setEnabled(false);
756 else if (count
== 1) {
757 // Only one file is selected. Pasting is only allowed if this
758 // file is a directory.
759 // TODO: this doesn't work with remote protocols; instead we need a
760 // m_activeView->selectedFileItems() to get the real KFileItems
761 const KFileItem
fileItem(S_IFDIR
,
765 pasteAction
->setEnabled(fileItem
.isDir());
770 void DolphinMainWindow::selectAll()
773 m_activeView
->selectAll();
776 void DolphinMainWindow::invertSelection()
779 m_activeView
->invertSelection();
781 void DolphinMainWindow::setIconsView()
783 m_activeView
->setMode(DolphinView::IconsView
);
786 void DolphinMainWindow::setDetailsView()
788 m_activeView
->setMode(DolphinView::DetailsView
);
791 void DolphinMainWindow::setPreviewsView()
793 m_activeView
->setMode(DolphinView::PreviewsView
);
796 void DolphinMainWindow::sortByName()
798 m_activeView
->setSorting(DolphinView::SortByName
);
801 void DolphinMainWindow::sortBySize()
803 m_activeView
->setSorting(DolphinView::SortBySize
);
806 void DolphinMainWindow::sortByDate()
808 m_activeView
->setSorting(DolphinView::SortByDate
);
811 void DolphinMainWindow::toggleSortOrder()
813 const Qt::SortOrder order
= (m_activeView
->sortOrder() == Qt::Ascending
) ?
816 m_activeView
->setSortOrder(order
);
819 void DolphinMainWindow::toggleSplitView()
821 if (m_view
[SecondaryIdx
] == 0) {
822 // create a secondary view
823 m_view
[SecondaryIdx
] = new DolphinView(this,
825 m_view
[PrimaryIdx
]->url(),
826 m_view
[PrimaryIdx
]->mode(),
827 m_view
[PrimaryIdx
]->isShowHiddenFilesEnabled());
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 m_view
[PrimaryIdx
]->deleteLater();
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::showHiddenFiles()
866 const KToggleAction
* showHiddenFilesAction
=
867 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
868 const bool show
= showHiddenFilesAction
->isChecked();
869 m_activeView
->setShowHiddenFilesEnabled(show
);
872 void DolphinMainWindow::showFilterBar()
874 const KToggleAction
* showFilterBarAction
=
875 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
876 const bool show
= showFilterBarAction
->isChecked();
877 m_activeView
->slotShowFilterBar(show
);
880 void DolphinMainWindow::zoomIn()
882 m_activeView
->zoomIn();
886 void DolphinMainWindow::zoomOut()
888 m_activeView
->zoomOut();
892 void DolphinMainWindow::toggleEditLocation()
896 KToggleAction
* action
= static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
898 bool editOrBrowse
= action
->isChecked();
899 // action->setChecked(action->setChecked);
900 m_activeView
->setUrlEditable(editOrBrowse
);
903 void DolphinMainWindow::editLocation()
905 KToggleAction
* action
= static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
906 action
->setChecked(true);
907 m_activeView
->setUrlEditable(true);
910 void DolphinMainWindow::adjustViewProperties()
913 ViewPropertiesDialog
dlg(m_activeView
);
917 void DolphinMainWindow::goBack()
920 m_activeView
->goBack();
923 void DolphinMainWindow::goForward()
926 m_activeView
->goForward();
929 void DolphinMainWindow::goUp()
932 m_activeView
->goUp();
935 void DolphinMainWindow::goHome()
938 m_activeView
->goHome();
941 void DolphinMainWindow::openTerminal()
943 QString
command("konsole --workdir \"");
944 command
.append(m_activeView
->url().path());
945 command
.append('\"');
947 KRun::runCommand(command
, "Konsole", "konsole");
950 void DolphinMainWindow::findFile()
952 KRun::run("kfind", m_activeView
->url());
955 void DolphinMainWindow::compareFiles()
957 // The method is only invoked if exactly 2 files have
958 // been selected. The selected files may be:
959 // - both in the primary view
960 // - both in the secondary view
961 // - one in the primary view and the other in the secondary
963 assert(m_view
[PrimaryIdx
] != 0);
967 KUrl::List urls
= m_view
[PrimaryIdx
]->selectedUrls();
969 switch (urls
.count()) {
971 assert(m_view
[SecondaryIdx
] != 0);
972 urls
= m_view
[SecondaryIdx
]->selectedUrls();
973 assert(urls
.count() == 2);
981 assert(m_view
[SecondaryIdx
] != 0);
982 urls
= m_view
[SecondaryIdx
]->selectedUrls();
983 assert(urls
.count() == 1);
995 // may not happen: compareFiles may only get invoked if 2
996 // files are selected
1001 QString
command("kompare -c \"");
1002 command
.append(urlA
.pathOrUrl());
1003 command
.append("\" \"");
1004 command
.append(urlB
.pathOrUrl());
1005 command
.append('\"');
1006 KRun::runCommand(command
, "Kompare", "kompare");
1010 void DolphinMainWindow::editSettings()
1012 // TODO: make a static method for opening the settings dialog
1013 DolphinSettingsDialog
dlg(this);
1017 void DolphinMainWindow::addUndoOperation(KJob
* job
)
1019 if (job
->error() != 0) {
1020 slotHandleJobError(job
);
1023 const int id
= job
->progressId();
1025 // set iterator to the executed command with the current id...
1026 Q3ValueList
<UndoInfo
>::Iterator it
= m_pendingUndoJobs
.begin();
1027 const Q3ValueList
<UndoInfo
>::Iterator end
= m_pendingUndoJobs
.end();
1029 while (!found
&& (it
!= end
)) {
1030 if ((*it
).id
== id
) {
1039 DolphinCommand command
= (*it
).command
;
1040 if (command
.type() == DolphinCommand::Trash
) {
1041 // To be able to perform an undo for the 'Move to Trash' operation
1042 // all source Urls must be updated with the trash Url. E. g. when moving
1043 // a file "test.txt" and a second file "test.txt" to the trash,
1044 // then the filenames in the trash are "0-test.txt" and "1-test.txt".
1045 QMap
<QString
, QString
> metaData
;
1046 KIO::Job
*kiojob
= qobject_cast
<KIO::Job
*>( job
);
1049 metaData
= kiojob
->metaData();
1051 KUrl::List newSourceUrls
;
1053 KUrl::List sourceUrls
= command
.source();
1054 KUrl::List::Iterator sourceIt
= sourceUrls
.begin();
1055 const KUrl::List::Iterator sourceEnd
= sourceUrls
.end();
1057 while (sourceIt
!= sourceEnd
) {
1058 QMap
<QString
, QString
>::ConstIterator metaIt
= metaData
.find("trashUrl-" + (*sourceIt
).path());
1059 if (metaIt
!= metaData
.end()) {
1060 newSourceUrls
.append(KUrl(metaIt
.data()));
1064 command
.setSource(newSourceUrls
);
1067 UndoManager::instance().addCommand(command
);
1068 m_pendingUndoJobs
.erase(it
);
1070 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
1071 switch (command
.type()) {
1072 case DolphinCommand::Copy
:
1073 statusBar
->setMessage(i18n("Copy operation completed."),
1074 DolphinStatusBar::OperationCompleted
);
1076 case DolphinCommand::Move
:
1077 statusBar
->setMessage(i18n("Move operation completed."),
1078 DolphinStatusBar::OperationCompleted
);
1080 case DolphinCommand::Trash
:
1081 statusBar
->setMessage(i18n("Move to trash operation completed."),
1082 DolphinStatusBar::OperationCompleted
);
1091 void DolphinMainWindow::init()
1093 // Check whether Dolphin runs the first time. If yes then
1094 // a proper default window size is given at the end of DolphinMainWindow::init().
1095 GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
1096 const bool firstRun
= generalSettings
->firstRun();
1098 setAcceptDrops(true);
1100 m_splitter
= new QSplitter(this);
1102 DolphinSettings
& settings
= DolphinSettings::instance();
1104 KBookmarkManager
* manager
= settings
.bookmarkManager();
1105 assert(manager
!= 0);
1106 KBookmarkGroup root
= manager
->root();
1107 if (root
.first().isNull()) {
1108 root
.addBookmark(manager
, i18n("Home"), settings
.generalSettings()->homeUrl(), "folder_home");
1109 root
.addBookmark(manager
, i18n("Storage Media"), KUrl("media:/"), "blockdevice");
1110 root
.addBookmark(manager
, i18n("Network"), KUrl("remote:/"), "network_local");
1111 root
.addBookmark(manager
, i18n("Root"), KUrl("/"), "folder_red");
1112 root
.addBookmark(manager
, i18n("Trash"), KUrl("trash:/"), "trashcan_full");
1117 const KUrl
& homeUrl
= root
.first().url();
1118 setCaption(homeUrl
.fileName());
1119 ViewProperties
props(homeUrl
);
1120 m_view
[PrimaryIdx
] = new DolphinView(this,
1124 props
.isShowHiddenFilesEnabled());
1126 m_activeView
= m_view
[PrimaryIdx
];
1128 setCentralWidget(m_splitter
);
1131 setupGUI(Keys
|Save
|Create
|ToolBar
);
1134 stateChanged("new_file");
1135 setAutoSaveSettings();
1137 QClipboard
* clipboard
= QApplication::clipboard();
1138 connect(clipboard
, SIGNAL(dataChanged()),
1139 this, SLOT(updatePasteAction()));
1140 updatePasteAction();
1143 setupCreateNewMenuActions();
1148 // assure a proper default size if Dolphin runs the first time
1153 void DolphinMainWindow::loadSettings()
1155 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
1157 KToggleAction
* splitAction
= static_cast<KToggleAction
*>(actionCollection()->action("split_view"));
1158 if (settings
->splitView()) {
1159 splitAction
->setChecked(true);
1163 updateViewActions();
1166 void DolphinMainWindow::setupActions()
1168 // setup 'File' menu
1169 KAction
*action
= new KAction(KIcon("window_new"), i18n( "New &Window" ), actionCollection(), "new_window" );
1170 connect(action
, SIGNAL(triggered()), this, SLOT(slotNewMainWindow()));
1172 KAction
* createFolder
= new KAction(i18n("Folder..."), actionCollection(), "create_folder");
1173 createFolder
->setIcon(KIcon("folder"));
1174 createFolder
->setShortcut(Qt::Key_N
);
1175 connect(createFolder
, SIGNAL(triggered()), this, SLOT(createFolder()));
1177 KAction
* rename
= new KAction(i18n("Rename"), actionCollection(), "rename");
1178 rename
->setShortcut(Qt::Key_F2
);
1179 connect(rename
, SIGNAL(triggered()), this, SLOT(rename()));
1181 KAction
* moveToTrash
= new KAction(i18n("Move to Trash"), actionCollection(), "move_to_trash");
1182 moveToTrash
->setIcon(KIcon("edittrash"));
1183 moveToTrash
->setShortcut(QKeySequence::Delete
);
1184 connect(moveToTrash
, SIGNAL(triggered()), this, SLOT(moveToTrash()));
1186 KAction
* deleteAction
= new KAction(i18n("Delete"), actionCollection(), "delete");
1187 deleteAction
->setShortcut(Qt::ALT
| Qt::Key_Delete
);
1188 deleteAction
->setIcon(KIcon("editdelete"));
1189 connect(deleteAction
, SIGNAL(triggered()), this, SLOT(deleteItems()));
1191 KAction
* properties
= new KAction(i18n("Propert&ies"), actionCollection(), "properties");
1192 properties
->setShortcut(Qt::Key_Alt
| Qt::Key_Return
);
1193 connect(properties
, SIGNAL(triggered()), this, SLOT(properties()));
1195 KStdAction::quit(this, SLOT(quit()), actionCollection());
1197 // setup 'Edit' menu
1198 UndoManager
& undoManager
= UndoManager::instance();
1199 KStdAction::undo(this,
1201 actionCollection());
1202 connect(&undoManager
, SIGNAL(undoAvailable(bool)),
1203 this, SLOT(slotUndoAvailable(bool)));
1204 connect(&undoManager
, SIGNAL(undoTextChanged(const QString
&)),
1205 this, SLOT(slotUndoTextChanged(const QString
&)));
1207 KStdAction::redo(this,
1209 actionCollection());
1210 connect(&undoManager
, SIGNAL(redoAvailable(bool)),
1211 this, SLOT(slotRedoAvailable(bool)));
1212 connect(&undoManager
, SIGNAL(redoTextChanged(const QString
&)),
1213 this, SLOT(slotRedoTextChanged(const QString
&)));
1215 KStdAction::cut(this, SLOT(cut()), actionCollection());
1216 KStdAction::copy(this, SLOT(copy()), actionCollection());
1217 KStdAction::paste(this, SLOT(paste()), actionCollection());
1219 KAction
* selectAll
= new KAction(i18n("Select All"), actionCollection(), "select_all");
1220 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1221 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1223 KAction
* invertSelection
= new KAction(i18n("Invert Selection"), actionCollection(), "invert_selection");
1224 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1225 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1227 // setup 'View' menu
1228 KStdAction::zoomIn(this,
1230 actionCollection());
1232 KStdAction::zoomOut(this,
1234 actionCollection());
1236 KToggleAction
* iconsView
= new KToggleAction(i18n("Icons"), actionCollection(), "icons");
1237 iconsView
->setShortcut(Qt::CTRL
| Qt::Key_1
);
1238 iconsView
->setIcon(KIcon("view_icon"));
1239 connect(iconsView
, SIGNAL(triggered()), this, SLOT(setIconsView()));
1241 KToggleAction
* detailsView
= new KToggleAction(i18n("Details"), actionCollection(), "details");
1242 detailsView
->setShortcut(Qt::CTRL
| Qt::Key_2
);
1243 detailsView
->setIcon(KIcon("view_text"));
1244 connect(detailsView
, SIGNAL(triggered()), this, SLOT(setDetailsView()));
1246 KToggleAction
* previewsView
= new KToggleAction(i18n("Previews"), actionCollection(), "previews");
1247 previewsView
->setShortcut(Qt::CTRL
| Qt::Key_3
);
1248 previewsView
->setIcon(KIcon("gvdirpart"));
1249 connect(previewsView
, SIGNAL(triggered()), this, SLOT(setPreviewsView()));
1251 QActionGroup
* viewModeGroup
= new QActionGroup(this);
1252 viewModeGroup
->addAction(iconsView
);
1253 viewModeGroup
->addAction(detailsView
);
1254 viewModeGroup
->addAction(previewsView
);
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
* showHiddenFiles
= new KToggleAction(i18n("Show Hidden Files"), actionCollection(), "show_hidden_files");
1274 //showHiddenFiles->setShortcut(Qt::ALT | Qt::Key_ KDE4-TODO: what Qt-Key represents '.'?
1275 connect(showHiddenFiles
, SIGNAL(triggered()), this, SLOT(showHiddenFiles()));
1277 KToggleAction
* split
= new KToggleAction(i18n("Split View"), actionCollection(), "split_view");
1278 split
->setShortcut(Qt::Key_F10
);
1279 split
->setIcon(KIcon("view_left_right"));
1280 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1282 KAction
* reload
= new KAction(i18n("Reload"), "F5", actionCollection(), "reload");
1283 reload
->setShortcut(Qt::Key_F5
);
1284 reload
->setIcon(KIcon("reload"));
1285 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1287 KAction
* stop
= new KAction(i18n("Stop"), actionCollection(), "stop");
1288 stop
->setIcon(KIcon("stop"));
1289 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1291 KToggleAction
* showFullLocation
= new KToggleAction(i18n("Show Full Location"), actionCollection(), "editable_location");
1292 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1293 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1295 KToggleAction
* editLocation
= new KToggleAction(i18n("Edit Location"), actionCollection(), "edit_location");
1296 editLocation
->setShortcut(Qt::Key_F6
);
1297 connect(editLocation
, SIGNAL(triggered()), this, SLOT(editLocation()));
1299 KAction
* adjustViewProps
= new KAction(i18n("Adjust View Properties..."), actionCollection(), "view_properties");
1300 connect(adjustViewProps
, SIGNAL(triggered()), this, SLOT(adjustViewProperties()));
1303 KStdAction::back(this, SLOT(goBack()), actionCollection());
1304 KStdAction::forward(this, SLOT(goForward()), actionCollection());
1305 KStdAction::up(this, SLOT(goUp()), actionCollection());
1306 KStdAction::home(this, SLOT(goHome()), actionCollection());
1308 // setup 'Tools' menu
1309 KAction
* openTerminal
= new KAction(i18n("Open Terminal"), actionCollection(), "open_terminal");
1310 openTerminal
->setShortcut(Qt::Key_F4
);
1311 openTerminal
->setIcon(KIcon("konsole"));
1312 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1314 KAction
* findFile
= new KAction(i18n("Find File..."), actionCollection(), "find_file");
1315 findFile
->setShortcut(Qt::Key_F
);
1316 findFile
->setIcon(KIcon("filefind"));
1317 connect(findFile
, SIGNAL(triggered()), this, SLOT(findFile()));
1319 KToggleAction
* showFilterBar
= new KToggleAction(i18n("Show Filter Bar"), actionCollection(), "show_filter_bar");
1320 showFilterBar
->setShortcut(Qt::Key_Slash
);
1321 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1323 KAction
* compareFiles
= new KAction(i18n("Compare Files"), actionCollection(), "compare_files");
1324 compareFiles
->setIcon(KIcon("kompare"));
1325 compareFiles
->setEnabled(false);
1326 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1328 // setup 'Settings' menu
1329 KStdAction::preferences(this, SLOT(editSettings()), actionCollection());
1332 void DolphinMainWindow::setupCreateNewMenuActions()
1334 // Parts of the following code have been taken
1335 // from the class KNewMenu located in
1336 // libqonq/knewmenu.h of Konqueror.
1337 // Copyright (C) 1998, 1999 David Faure <faure@kde.org>
1338 // 2003 Sven Leiber <s.leiber@web.de>
1340 QStringList files
= actionCollection()->instance()->dirs()->findAllResources("templates");
1341 for (QStringList::Iterator it
= files
.begin() ; it
!= files
.end(); ++it
) {
1342 if ((*it
)[0] != '.' ) {
1343 KSimpleConfig
config(*it
, true);
1344 config
.setDesktopGroup();
1346 // tricky solution to ensure that TextFile is at the beginning
1347 // because this filetype is the most used (according kde-core discussion)
1348 const QString
name(config
.readEntry("Name"));
1351 const QString
path(config
.readPathEntry("Url"));
1352 if (!path
.endsWith("emptydir")) {
1353 if (path
.endsWith("TextFile.txt")) {
1356 else if (!KDesktopFile::isDesktopFile(path
)) {
1359 else if (path
.endsWith("Url.desktop")){
1362 else if (path
.endsWith("Program.desktop")){
1369 const QString
icon(config
.readEntry("Icon"));
1370 const QString
comment(config
.readEntry("Comment"));
1371 const QString
type(config
.readEntry("Type"));
1373 const QString
filePath(*it
);
1376 if (type
== "Link") {
1377 CreateFileEntry entry
;
1380 entry
.comment
= comment
;
1381 entry
.templatePath
= filePath
;
1382 m_createFileTemplates
.insert(key
, entry
);
1387 m_createFileTemplates
.sort();
1389 unplugActionList("create_actions");
1390 KSortableList
<CreateFileEntry
, QString
>::ConstIterator it
= m_createFileTemplates
.begin();
1391 KSortableList
<CreateFileEntry
, QString
>::ConstIterator end
= m_createFileTemplates
.end();
1392 /* KDE4-TODO: don't port this code; use KNewMenu instead
1394 CreateFileEntry entry = (*it).value();
1395 KAction* action = new KAction(entry.name);
1396 action->setIcon(entry.icon);
1397 action->setName((*it).index());
1398 connect(action, SIGNAL(activated()),
1399 this, SLOT(createFile()));
1401 const QChar section = ((*it).index()[0]);
1405 m_fileGroupActions.append(action);
1411 // TODO: not used yet. See documentation of DolphinMainWindow::linkGroupActions()
1412 // and DolphinMainWindow::linkToDeviceActions() in the header file for details.
1413 //m_linkGroupActions.append(action);
1418 // TODO: not used yet. See documentation of DolphinMainWindow::linkGroupActions()
1419 // and DolphinMainWindow::linkToDeviceActions() in the header file for details.
1420 //m_linkToDeviceActions.append(action);
1429 plugActionList("create_file_group", m_fileGroupActions);
1430 //plugActionList("create_link_group", m_linkGroupActions);
1431 //plugActionList("link_to_device", m_linkToDeviceActions);*/
1434 void DolphinMainWindow::updateHistory()
1437 const Q3ValueList
<UrlNavigator::HistoryElem
> list
= m_activeView
->urlHistory(index
);
1439 KAction
* backAction
= actionCollection()->action("go_back");
1440 if (backAction
!= 0) {
1441 backAction
->setEnabled(index
< static_cast<int>(list
.count()) - 1);
1444 KAction
* forwardAction
= actionCollection()->action("go_forward");
1445 if (forwardAction
!= 0) {
1446 forwardAction
->setEnabled(index
> 0);
1450 void DolphinMainWindow::updateEditActions()
1452 const KFileItemList list
= m_activeView
->selectedItems();
1453 if (list
.isEmpty()) {
1454 stateChanged("has_no_selection");
1457 stateChanged("has_selection");
1459 KAction
* renameAction
= actionCollection()->action("rename");
1460 if (renameAction
!= 0) {
1461 renameAction
->setEnabled(list
.count() >= 1);
1464 bool enableMoveToTrash
= true;
1466 KFileItemList::const_iterator it
= list
.begin();
1467 const KFileItemList::const_iterator end
= list
.end();
1469 KFileItem
* item
= *it
;
1470 const KUrl
& url
= item
->url();
1471 // only enable the 'Move to Trash' action for local files
1472 if (!url
.isLocalFile()) {
1473 enableMoveToTrash
= false;
1478 KAction
* moveToTrashAction
= actionCollection()->action("move_to_trash");
1479 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1481 updatePasteAction();
1484 void DolphinMainWindow::updateViewActions()
1486 KAction
* zoomInAction
= actionCollection()->action(KStdAction::stdName(KStdAction::ZoomIn
));
1487 if (zoomInAction
!= 0) {
1488 zoomInAction
->setEnabled(m_activeView
->isZoomInPossible());
1491 KAction
* zoomOutAction
= actionCollection()->action(KStdAction::stdName(KStdAction::ZoomOut
));
1492 if (zoomOutAction
!= 0) {
1493 zoomOutAction
->setEnabled(m_activeView
->isZoomOutPossible());
1496 KAction
* action
= 0;
1497 switch (m_activeView
->mode()) {
1498 case DolphinView::IconsView
:
1499 action
= actionCollection()->action("icons");
1501 case DolphinView::DetailsView
:
1502 action
= actionCollection()->action("details");
1504 case DolphinView::PreviewsView
:
1505 action
= actionCollection()->action("previews");
1512 KToggleAction
* toggleAction
= static_cast<KToggleAction
*>(action
);
1513 toggleAction
->setChecked(true);
1516 slotSortingChanged(m_activeView
->sorting());
1517 slotSortOrderChanged(m_activeView
->sortOrder());
1519 KToggleAction
* showFilterBarAction
=
1520 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
1521 showFilterBarAction
->setChecked(m_activeView
->isFilterBarVisible());
1523 KToggleAction
* showHiddenFilesAction
=
1524 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
1525 showHiddenFilesAction
->setChecked(m_activeView
->isShowHiddenFilesEnabled());
1527 KToggleAction
* splitAction
= static_cast<KToggleAction
*>(actionCollection()->action("split_view"));
1528 splitAction
->setChecked(m_view
[SecondaryIdx
] != 0);
1531 void DolphinMainWindow::updateGoActions()
1533 KAction
* goUpAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Up
));
1534 const KUrl
& currentUrl
= m_activeView
->url();
1535 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1538 void DolphinMainWindow::updateViewProperties(const KUrl::List
& urls
)
1540 if (urls
.isEmpty()) {
1544 // Updating the view properties might take up to several seconds
1545 // when dragging several thousand Urls. Writing a KIO slave for this
1546 // use case is not worth the effort, but at least the main widget
1547 // must be disabled and a progress should be shown.
1548 ProgressIndicator
progressIndicator(this,
1549 i18n("Updating view properties..."),
1553 KUrl::List::ConstIterator end
= urls
.end();
1554 for(KUrl::List::ConstIterator it
= urls
.begin(); it
!= end
; ++it
) {
1555 progressIndicator
.execOperation();
1557 ViewProperties
props(*it
);
1562 void DolphinMainWindow::copyUrls(const KUrl::List
& source
, const KUrl
& dest
)
1564 KIO::Job
* job
= KIO::copy(source
, dest
);
1565 addPendingUndoJob(job
, DolphinCommand::Copy
, source
, dest
);
1568 void DolphinMainWindow::moveUrls(const KUrl::List
& source
, const KUrl
& dest
)
1570 KIO::Job
* job
= KIO::move(source
, dest
);
1571 addPendingUndoJob(job
, DolphinCommand::Move
, source
, dest
);
1574 void DolphinMainWindow::addPendingUndoJob(KIO::Job
* job
,
1575 DolphinCommand::Type commandType
,
1576 const KUrl::List
& source
,
1579 connect(job
, SIGNAL(result(KJob
*)),
1580 this, SLOT(addUndoOperation(KJob
*)));
1583 undoInfo
.id
= job
->progressId();
1584 undoInfo
.command
= DolphinCommand(commandType
, source
, dest
);
1585 m_pendingUndoJobs
.append(undoInfo
);
1588 void DolphinMainWindow::clearStatusBar()
1590 m_activeView
->statusBar()->clear();
1593 void DolphinMainWindow::setupDockWidgets()
1595 QDockWidget
*shortcutsDock
= new QDockWidget(i18n("Shortcuts"));
1596 shortcutsDock
->setObjectName("shortcutsDock");
1597 shortcutsDock
->setFeatures(QDockWidget::DockWidgetMovable
|QDockWidget::DockWidgetFloatable
);
1598 shortcutsDock
->setWidget(new BookmarksSidebarPage(this));
1599 addDockWidget(Qt::LeftDockWidgetArea
, shortcutsDock
);
1601 QDockWidget
*infoDock
= new QDockWidget(i18n("Information"));
1602 infoDock
->setObjectName("infoDock");
1603 infoDock
->setFeatures(QDockWidget::DockWidgetMovable
|QDockWidget::DockWidgetFloatable
);
1604 infoDock
->setWidget(new InfoSidebarPage(this));
1605 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1608 #include "dolphinmainwindow.moc"