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>
62 #include "urlnavigator.h"
63 #include "viewpropertiesdialog.h"
64 #include "viewproperties.h"
65 #include "dolphinsettings.h"
66 #include "dolphinsettingsdialog.h"
67 #include "dolphinstatusbar.h"
68 #include "dolphinapplication.h"
69 #include "undomanager.h"
70 #include "progressindicator.h"
71 #include "dolphinsettings.h"
73 #include "sidebarsettings.h"
74 #include "generalsettings.h"
75 #include "dolphinapplication.h"
78 DolphinMainWindow::DolphinMainWindow() :
79 KMainWindow(0, "Dolphin"),
83 m_clipboardContainsCutData(false)
85 m_view
[PrimaryIdx
] = 0;
86 m_view
[SecondaryIdx
] = 0;
88 m_fileGroupActions
.setAutoDelete(true);
90 // TODO: the following members are not used yet. See documentation
91 // of DolphinMainWindow::linkGroupActions() and DolphinMainWindow::linkToDeviceActions()
92 // in the header file for details.
93 //m_linkGroupActions.setAutoDelete(true);
94 //m_linkToDeviceActions.setAutoDelete(true);
97 DolphinMainWindow::~DolphinMainWindow()
100 * bye, bye managed window
102 DolphinApplication::app()->removeMainWindow( this );
105 void DolphinMainWindow::setActiveView(DolphinView
* view
)
107 assert((view
== m_view
[PrimaryIdx
]) || (view
== m_view
[SecondaryIdx
]));
108 if (m_activeView
== view
) {
119 setCaption(m_activeView
->url().fileName());
121 emit
activeViewChanged();
124 void DolphinMainWindow::dropUrls(const KUrl::List
& urls
,
125 const KUrl
& destination
)
127 int selectedIndex
= -1;
130 const ButtonState keyboardState = KApplication::keyboardMouseState();
131 const bool shiftPressed = (keyboardState & ShiftButton) > 0;
132 const bool controlPressed = (keyboardState & ControlButton) > 0;
136 if (shiftPressed && controlPressed) {
137 // shortcut for 'Linke Here' is used
140 else if (controlPressed) {
141 // shortcut for 'Copy Here' is used
144 else if (shiftPressed) {
145 // shortcut for 'Move Here' is used
149 // no shortcut is used, hence open a popup menu
152 popup
.insertItem(SmallIcon("goto"), i18n("&Move Here") + "\t" /* KDE4-TODO: + KKey::modFlagLabel(KKey::SHIFT)*/, 0);
153 popup
.insertItem(SmallIcon("editcopy"), i18n( "&Copy Here" ) /* KDE4-TODO + "\t" + KKey::modFlagLabel(KKey::CTRL)*/, 1);
154 popup
.insertItem(i18n("&Link Here") /* KDE4-TODO + "\t" + KKey::modFlagLabel((KKey::ModFlag)(KKey::CTRL|KKey::SHIFT)) */, 2);
155 popup
.insertSeparator();
156 popup
.insertItem(SmallIcon("stop"), i18n("Cancel"), 3);
157 popup
.setAccel(i18n("Escape"), 3);
159 /* KDE4-TODO: selectedIndex = popup.exec(QCursor::pos()); */
160 popup
.exec(QCursor::pos());
161 selectedIndex
= 0; // KD4-TODO: use QAction instead of switch below
162 // See libkonq/konq_operations.cc: KonqOperations::doDropFileCopy() (and doDrop, the main method)
165 if (selectedIndex
< 0) {
169 switch (selectedIndex
) {
171 // 'Move Here' has been selected
172 updateViewProperties(urls
);
173 moveUrls(urls
, destination
);
178 // 'Copy Here' has been selected
179 updateViewProperties(urls
);
180 copyUrls(urls
, destination
);
185 // 'Link Here' has been selected
186 KIO::Job
* job
= KIO::link(urls
, destination
);
187 addPendingUndoJob(job
, DolphinCommand::Link
, urls
, destination
);
192 // 'Cancel' has been selected
197 void DolphinMainWindow::refreshViews()
199 const bool split
= DolphinSettings::instance().generalSettings()->splitView();
200 const bool isPrimaryViewActive
= (m_activeView
== m_view
[PrimaryIdx
]);
202 for (int i
= PrimaryIdx
; i
<= SecondaryIdx
; ++i
) {
203 if (m_view
[i
] != 0) {
204 url
= m_view
[i
]->url();
206 // delete view instance...
208 m_view
[i
]->deleteLater();
212 if (split
|| (i
== PrimaryIdx
)) {
213 // ... and recreate it
214 ViewProperties
props(url
);
215 m_view
[i
] = new DolphinView(this,
219 props
.isShowHiddenFilesEnabled());
224 m_activeView
= isPrimaryViewActive
? m_view
[PrimaryIdx
] : m_view
[SecondaryIdx
];
225 assert(m_activeView
!= 0);
228 emit
activeViewChanged();
231 void DolphinMainWindow::slotHistoryChanged()
236 void DolphinMainWindow::slotUrlChanged(const KUrl
& url
)
240 setCaption(url
.fileName());
243 void DolphinMainWindow::slotUrlChangeRequest(const KUrl
& url
)
246 m_activeView
->setUrl(url
);
249 void DolphinMainWindow::slotViewModeChanged()
254 void DolphinMainWindow::slotShowHiddenFilesChanged()
256 KToggleAction
* showHiddenFilesAction
=
257 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
258 showHiddenFilesAction
->setChecked(m_activeView
->isShowHiddenFilesEnabled());
261 void DolphinMainWindow::slotShowFilterBarChanged()
263 KToggleAction
* showFilterBarAction
=
264 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
265 showFilterBarAction
->setChecked(m_activeView
->isFilterBarVisible());
268 void DolphinMainWindow::slotSortingChanged(DolphinView::Sorting sorting
)
272 case DolphinView::SortByName
:
273 action
= actionCollection()->action("by_name");
275 case DolphinView::SortBySize
:
276 action
= actionCollection()->action("by_size");
278 case DolphinView::SortByDate
:
279 action
= actionCollection()->action("by_date");
286 KToggleAction
* toggleAction
= static_cast<KToggleAction
*>(action
);
287 toggleAction
->setChecked(true);
291 void DolphinMainWindow::slotSortOrderChanged(Qt::SortOrder order
)
293 KToggleAction
* descending
= static_cast<KToggleAction
*>(actionCollection()->action("descending"));
294 const bool sortDescending
= (order
== Qt::Descending
);
295 descending
->setChecked(sortDescending
);
298 void DolphinMainWindow::slotSelectionChanged()
302 assert(m_view
[PrimaryIdx
] != 0);
303 int selectedUrlsCount
= m_view
[PrimaryIdx
]->selectedUrls().count();
304 if (m_view
[SecondaryIdx
] != 0) {
305 selectedUrlsCount
+= m_view
[SecondaryIdx
]->selectedUrls().count();
308 KAction
* compareFilesAction
= actionCollection()->action("compare_files");
309 compareFilesAction
->setEnabled(selectedUrlsCount
== 2);
311 m_activeView
->updateStatusBar();
313 emit
selectionChanged();
316 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
319 //KConfig* config = KGlobal::config();
320 //config->setGroup("General");
321 //config->writeEntry("First Run", false);
323 DolphinSettings
& settings
= DolphinSettings::instance();
324 GeneralSettings
* generalSettings
= settings
.generalSettings();
325 generalSettings
->setFirstRun(false);
327 SidebarSettings
* sidebarSettings
= settings
.sidebarSettings();
328 const bool isSidebarVisible
= (m_sidebar
!= 0);
329 sidebarSettings
->setVisible(isSidebarVisible
);
330 if (isSidebarVisible
) {
331 sidebarSettings
->setWidth(m_sidebar
->width());
336 KMainWindow::closeEvent(event
);
339 void DolphinMainWindow::saveProperties(KConfig
* config
)
341 config
->setGroup("Primary view");
342 config
->writeEntry("Url", m_view
[PrimaryIdx
]->url().url());
343 config
->writeEntry("Editable Url", m_view
[PrimaryIdx
]->isUrlEditable());
344 if (m_view
[SecondaryIdx
] != 0) {
345 config
->setGroup("Secondary view");
346 config
->writeEntry("Url", m_view
[SecondaryIdx
]->url().url());
347 config
->writeEntry("Editable Url", m_view
[SecondaryIdx
]->isUrlEditable());
351 void DolphinMainWindow::readProperties(KConfig
* config
)
353 config
->setGroup("Primary view");
354 m_view
[PrimaryIdx
]->setUrl(config
->readEntry("Url"));
355 m_view
[PrimaryIdx
]->setUrlEditable(config
->readBoolEntry("Editable Url"));
356 if (config
->hasGroup("Secondary view")) {
357 config
->setGroup("Secondary view");
358 if (m_view
[SecondaryIdx
] == 0) {
361 m_view
[SecondaryIdx
]->setUrl(config
->readEntry("Url"));
362 m_view
[SecondaryIdx
]->setUrlEditable(config
->readBoolEntry("Editable Url"));
364 else if (m_view
[SecondaryIdx
] != 0) {
369 void DolphinMainWindow::createFolder()
371 // Parts of the following code have been taken
372 // from the class KonqPopupMenu located in
373 // libqonq/konq_popupmenu.h of Konqueror.
374 // (Copyright (C) 2000 David Faure <faure@kde.org>,
375 // Copyright (C) 2001 Holger Freyther <freyther@yahoo.com>)
379 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
380 const KUrl
baseUrl(m_activeView
->url());
382 QString
name(i18n("New Folder"));
383 baseUrl
.path(KUrl::AddTrailingSlash
);
386 if (baseUrl
.isLocalFile() && QFileInfo(baseUrl
.path(KUrl::AddTrailingSlash
) + name
).exists()) {
387 name
= KIO::RenameDlg::suggestName(baseUrl
, i18n("New Folder"));
391 name
= KInputDialog::getText(i18n("New Folder"),
392 i18n("Enter folder name:" ),
398 // the user has pressed 'Cancel'
402 assert(!name
.isEmpty());
405 if ((name
[0] == '/') || (name
[0] == '~')) {
406 url
.setPath(KShell::tildeExpand(name
));
409 name
= KIO::encodeFileName(name
);
413 ok
= KIO::NetAccess::mkdir(url
, this);
415 // TODO: provide message type hint
417 statusBar
->setMessage(i18n("Created folder %1.",url
.path()),
418 DolphinStatusBar::OperationCompleted
);
420 DolphinCommand
command(DolphinCommand::CreateFolder
, KUrl::List(), url
, this);
421 UndoManager::instance().addCommand(command
);
424 // Creating of the folder has been failed. Check whether the creating
425 // has been failed because a folder with the same name exists...
426 if (KIO::NetAccess::exists(url
, true, this)) {
427 statusBar
->setMessage(i18n("A folder named %1 already exists.",url
.path()),
428 DolphinStatusBar::Error
);
431 statusBar
->setMessage(i18n("Creating of folder %1 failed.",url
.path()),
432 DolphinStatusBar::Error
);
438 void DolphinMainWindow::createFile()
440 // Parts of the following code have been taken
441 // from the class KonqPopupMenu located in
442 // libqonq/konq_popupmenu.h of Konqueror.
443 // (Copyright (C) 2000 David Faure <faure@kde.org>,
444 // Copyright (C) 2001 Holger Freyther <freyther@yahoo.com>)
448 // TODO: const Entry& entry = m_createFileTemplates[QString(sender->name())];
449 // should be enough. Anyway: the implemantation of [] does a linear search internally too.
450 KSortableList
<CreateFileEntry
, QString
>::ConstIterator it
= m_createFileTemplates
.begin();
451 KSortableList
<CreateFileEntry
, QString
>::ConstIterator end
= m_createFileTemplates
.end();
453 const QString
senderName(sender()->name());
455 CreateFileEntry entry
;
456 while (!found
&& (it
!= end
)) {
457 if ((*it
).index() == senderName
) {
458 entry
= (*it
).value();
466 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
467 if (!found
|| !QFile::exists(entry
.templatePath
)) {
468 statusBar
->setMessage(i18n("Could not create file."), DolphinStatusBar::Error
);
472 // Get the source path of the template which should be copied.
473 // The source path is part of the Url entry of the desktop file.
474 const int pos
= entry
.templatePath
.findRev('/');
475 QString
sourcePath(entry
.templatePath
.left(pos
+ 1));
476 sourcePath
+= KDesktopFile(entry
.templatePath
, true).readPathEntry("Url");
478 QString
name(i18n(entry
.name
.ascii()));
479 // Most entry names end with "..." (e. g. "HTML File..."), which is ok for
480 // menus but no good choice for a new file name -> remove the dots...
481 name
.replace("...", QString::null
);
483 // add the file extension to the name
484 name
.append(sourcePath
.right(sourcePath
.length() - sourcePath
.findRev('.')));
486 // Check whether a file with the current name already exists. If yes suggest automatically
487 // a unique file name (e. g. "HTML File" will be replaced by "HTML File_1").
488 const KUrl
viewUrl(m_activeView
->url());
489 const bool fileExists
= viewUrl
.isLocalFile() &&
490 QFileInfo(viewUrl
.path(KUrl::AddTrailingSlash
) + KIO::encodeFileName(name
)).exists();
492 name
= KIO::RenameDlg::suggestName(viewUrl
, name
);
495 // let the user change the suggested file name
497 name
= KInputDialog::getText(entry
.name
,
503 // the user has pressed 'Cancel'
507 // before copying the template to the destination path check whether a file
508 // with the given name already exists
509 const QString
destPath(viewUrl
.pathOrUrl() + "/" + KIO::encodeFileName(name
));
510 const KUrl
destUrl(destPath
);
511 if (KIO::NetAccess::exists(destUrl
, false, this)) {
512 statusBar
->setMessage(i18n("A file named %1 already exists.",name
),
513 DolphinStatusBar::Error
);
517 // copy the template to the destination path
518 const KUrl
sourceUrl(sourcePath
);
519 KIO::CopyJob
* job
= KIO::copyAs(sourceUrl
, destUrl
);
520 job
->setDefaultPermissions(true);
521 if (KIO::NetAccess::synchronousRun(job
, this)) {
522 statusBar
->setMessage(i18n("Created file %1.",name
),
523 DolphinStatusBar::OperationCompleted
);
526 list
.append(sourceUrl
);
527 DolphinCommand
command(DolphinCommand::CreateFile
, list
, destUrl
, this);
528 UndoManager::instance().addCommand(command
);
532 statusBar
->setMessage(i18n("Creating of file %1 failed.",name
),
533 DolphinStatusBar::Error
);
537 void DolphinMainWindow::rename()
540 m_activeView
->renameSelectedItems();
543 void DolphinMainWindow::moveToTrash()
546 KUrl::List selectedUrls
= m_activeView
->selectedUrls();
547 KIO::Job
* job
= KIO::trash(selectedUrls
);
548 addPendingUndoJob(job
, DolphinCommand::Trash
, selectedUrls
, m_activeView
->url());
551 void DolphinMainWindow::deleteItems()
555 KUrl::List list
= m_activeView
->selectedUrls();
556 const uint itemCount
= list
.count();
557 assert(itemCount
>= 1);
561 text
= i18n("Do you really want to delete the %1 selected items?",itemCount
);
564 const KUrl
& url
= list
.first();
565 text
= i18n("Do you really want to delete '%1'?",url
.fileName());
568 const bool del
= KMessageBox::warningContinueCancel(this,
571 KGuiItem(i18n("Delete"), SmallIcon("editdelete"))
572 ) == KMessageBox::Continue
;
574 KIO::Job
* job
= KIO::del(list
);
575 connect(job
, SIGNAL(result(KJob
*)),
576 this, SLOT(slotHandleJobError(KJob
*)));
577 connect(job
, SIGNAL(result(KJob
*)),
578 this, SLOT(slotDeleteFileFinished(KJob
*)));
582 void DolphinMainWindow::properties()
584 const KFileItemList
* sourceList
= m_activeView
->selectedItems();
585 if (sourceList
== 0) {
590 KFileItemList::const_iterator it
= sourceList
->begin();
591 const KFileItemList::const_iterator end
= sourceList
->end();
598 new KPropertiesDialog(list
, this);
601 void DolphinMainWindow::quit()
606 void DolphinMainWindow::slotHandleJobError(KJob
* job
)
608 if (job
->error() != 0) {
609 m_activeView
->statusBar()->setMessage(job
->errorString(),
610 DolphinStatusBar::Error
);
614 void DolphinMainWindow::slotDeleteFileFinished(KJob
* job
)
616 if (job
->error() == 0) {
617 m_activeView
->statusBar()->setMessage(i18n("Delete operation completed."),
618 DolphinStatusBar::OperationCompleted
);
620 // TODO: In opposite to the 'Move to Trash' operation in the class KFileIconView
621 // no rearranging of the item position is done when a file has been deleted.
622 // This is bypassed by reloading the view, but it might be worth to investigate
623 // deeper for the root of this issue.
624 m_activeView
->reload();
628 void DolphinMainWindow::slotUndoAvailable(bool available
)
630 KAction
* undoAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Undo
));
631 if (undoAction
!= 0) {
632 undoAction
->setEnabled(available
);
636 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
638 KAction
* undoAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Undo
));
639 if (undoAction
!= 0) {
640 undoAction
->setText(text
);
644 void DolphinMainWindow::slotRedoAvailable(bool available
)
646 KAction
* redoAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Redo
));
647 if (redoAction
!= 0) {
648 redoAction
->setEnabled(available
);
652 void DolphinMainWindow::slotRedoTextChanged(const QString
& text
)
654 KAction
* redoAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Redo
));
655 if (redoAction
!= 0) {
656 redoAction
->setText(text
);
660 void DolphinMainWindow::cut()
662 // TODO: this boolean doesn't work between instances of dolphin or with konqueror or with other
663 // apps. The "application/x-kde-cutselection" mimetype should be used instead, see KonqMimeData
665 m_clipboardContainsCutData
= true;
666 /* KDE4-TODO: Q3DragObject* data = new KUrlDrag(m_activeView->selectedUrls(),
668 QApplication::clipboard()->setData(data);*/
671 void DolphinMainWindow::copy()
673 m_clipboardContainsCutData
= false;
675 Q3DragObject* data = new KUrlDrag(m_activeView->selectedUrls(),
677 QApplication::clipboard()->setData(data);*/
680 void DolphinMainWindow::paste()
682 /* KDE4-TODO: - see KonqOperations::doPaste
683 QClipboard* clipboard = QApplication::clipboard();
684 QMimeSource* data = clipboard->data();
685 if (!KUrlDrag::canDecode(data)) {
691 KUrl::List sourceUrls;
692 KUrlDrag::decode(data, sourceUrls);
694 // per default the pasting is done into the current Url of the view
695 KUrl destUrl(m_activeView->url());
697 // check whether the pasting should be done into a selected directory
698 KUrl::List selectedUrls = m_activeView->selectedUrls();
699 if (selectedUrls.count() == 1) {
700 const KFileItem fileItem(S_IFDIR,
702 selectedUrls.first(),
704 if (fileItem.isDir()) {
705 // only one item is selected which is a directory, hence paste
706 // into this directory
707 destUrl = selectedUrls.first();
712 updateViewProperties(sourceUrls);
713 if (m_clipboardContainsCutData) {
714 moveUrls(sourceUrls, destUrl);
715 m_clipboardContainsCutData = false;
719 copyUrls(sourceUrls, destUrl);
723 void DolphinMainWindow::updatePasteAction()
725 KAction
* pasteAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Paste
));
726 if (pasteAction
== 0) {
730 QString
text(i18n("Paste"));
731 QClipboard
* clipboard
= QApplication::clipboard();
732 QMimeSource
* data
= clipboard
->data();
734 if (KUrlDrag::canDecode(data)) {
735 pasteAction->setEnabled(true);
738 KUrlDrag::decode(data, urls);
739 const int count = urls.count();
741 pasteAction->setText(i18n("Paste 1 File"));
744 pasteAction->setText(i18n("Paste %1 Files").arg(count));
748 pasteAction
->setEnabled(false);
749 pasteAction
->setText(i18n("Paste"));
752 if (pasteAction
->isEnabled()) {
753 KUrl::List urls
= m_activeView
->selectedUrls();
754 const uint count
= urls
.count();
756 // pasting should not be allowed when more than one file
758 pasteAction
->setEnabled(false);
760 else if (count
== 1) {
761 // Only one file is selected. Pasting is only allowed if this
762 // file is a directory.
763 // TODO: this doesn't work with remote protocols; instead we need a
764 // m_activeView->selectedFileItems() to get the real KFileItems
765 const KFileItem
fileItem(S_IFDIR
,
769 pasteAction
->setEnabled(fileItem
.isDir());
774 void DolphinMainWindow::selectAll()
777 m_activeView
->selectAll();
780 void DolphinMainWindow::invertSelection()
783 m_activeView
->invertSelection();
785 void DolphinMainWindow::setIconsView()
787 m_activeView
->setMode(DolphinView::IconsView
);
790 void DolphinMainWindow::setDetailsView()
792 m_activeView
->setMode(DolphinView::DetailsView
);
795 void DolphinMainWindow::setPreviewsView()
797 m_activeView
->setMode(DolphinView::PreviewsView
);
800 void DolphinMainWindow::sortByName()
802 m_activeView
->setSorting(DolphinView::SortByName
);
805 void DolphinMainWindow::sortBySize()
807 m_activeView
->setSorting(DolphinView::SortBySize
);
810 void DolphinMainWindow::sortByDate()
812 m_activeView
->setSorting(DolphinView::SortByDate
);
815 void DolphinMainWindow::toggleSortOrder()
817 const Qt::SortOrder order
= (m_activeView
->sortOrder() == Qt::Ascending
) ?
820 m_activeView
->setSortOrder(order
);
823 void DolphinMainWindow::toggleSplitView()
825 if (m_view
[SecondaryIdx
] == 0) {
826 // create a secondary view
827 m_view
[SecondaryIdx
] = new DolphinView(this,
829 m_view
[PrimaryIdx
]->url(),
830 m_view
[PrimaryIdx
]->mode(),
831 m_view
[PrimaryIdx
]->isShowHiddenFilesEnabled());
832 m_view
[SecondaryIdx
]->show();
835 // remove secondary view
836 if (m_activeView
== m_view
[PrimaryIdx
]) {
837 m_view
[SecondaryIdx
]->close();
838 m_view
[SecondaryIdx
]->deleteLater();
839 m_view
[SecondaryIdx
] = 0;
840 setActiveView(m_view
[PrimaryIdx
]);
843 // The secondary view is active, hence from the users point of view
844 // the content of the secondary view should be moved to the primary view.
845 // From an implementation point of view it is more efficient to close
846 // the primary view and exchange the internal pointers afterwards.
847 m_view
[PrimaryIdx
]->close();
848 m_view
[PrimaryIdx
]->deleteLater();
849 m_view
[PrimaryIdx
] = m_view
[SecondaryIdx
];
850 m_view
[SecondaryIdx
] = 0;
851 setActiveView(m_view
[PrimaryIdx
]);
856 void DolphinMainWindow::reloadView()
859 m_activeView
->reload();
862 void DolphinMainWindow::stopLoading()
866 void DolphinMainWindow::showHiddenFiles()
870 const KToggleAction
* showHiddenFilesAction
=
871 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
872 const bool show
= showHiddenFilesAction
->isChecked();
873 m_activeView
->setShowHiddenFilesEnabled(show
);
876 void DolphinMainWindow::showFilterBar()
878 const KToggleAction
* showFilterBarAction
=
879 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
880 const bool show
= showFilterBarAction
->isChecked();
881 m_activeView
->slotShowFilterBar(show
);
884 void DolphinMainWindow::zoomIn()
886 m_activeView
->zoomIn();
890 void DolphinMainWindow::zoomOut()
892 m_activeView
->zoomOut();
896 void DolphinMainWindow::toggleEditLocation()
900 KToggleAction
* action
= static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
902 bool editOrBrowse
= action
->isChecked();
903 // action->setChecked(action->setChecked);
904 m_activeView
->setUrlEditable(editOrBrowse
);
907 void DolphinMainWindow::editLocation()
909 KToggleAction
* action
= static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
910 action
->setChecked(true);
911 m_activeView
->setUrlEditable(true);
914 void DolphinMainWindow::adjustViewProperties()
917 ViewPropertiesDialog
dlg(m_activeView
);
921 void DolphinMainWindow::goBack()
924 m_activeView
->goBack();
927 void DolphinMainWindow::goForward()
930 m_activeView
->goForward();
933 void DolphinMainWindow::goUp()
936 m_activeView
->goUp();
939 void DolphinMainWindow::goHome()
942 m_activeView
->goHome();
945 void DolphinMainWindow::openTerminal()
947 QString
command("konsole --workdir \"");
948 command
.append(m_activeView
->url().path());
949 command
.append('\"');
951 KRun::runCommand(command
, "Konsole", "konsole");
954 void DolphinMainWindow::findFile()
956 KRun::run("kfind", m_activeView
->url());
959 void DolphinMainWindow::compareFiles()
961 // The method is only invoked if exactly 2 files have
962 // been selected. The selected files may be:
963 // - both in the primary view
964 // - both in the secondary view
965 // - one in the primary view and the other in the secondary
967 assert(m_view
[PrimaryIdx
] != 0);
971 KUrl::List urls
= m_view
[PrimaryIdx
]->selectedUrls();
973 switch (urls
.count()) {
975 assert(m_view
[SecondaryIdx
] != 0);
976 urls
= m_view
[SecondaryIdx
]->selectedUrls();
977 assert(urls
.count() == 2);
985 assert(m_view
[SecondaryIdx
] != 0);
986 urls
= m_view
[SecondaryIdx
]->selectedUrls();
987 assert(urls
.count() == 1);
999 // may not happen: compareFiles may only get invoked if 2
1000 // files are selected
1005 QString
command("kompare -c \"");
1006 command
.append(urlA
.pathOrUrl());
1007 command
.append("\" \"");
1008 command
.append(urlB
.pathOrUrl());
1009 command
.append('\"');
1010 KRun::runCommand(command
, "Kompare", "kompare");
1014 void DolphinMainWindow::editSettings()
1016 // TODO: make a static method for opening the settings dialog
1017 DolphinSettingsDialog
dlg(this);
1021 void DolphinMainWindow::addUndoOperation(KJob
* job
)
1023 if (job
->error() != 0) {
1024 slotHandleJobError(job
);
1027 const int id
= job
->progressId();
1029 // set iterator to the executed command with the current id...
1030 Q3ValueList
<UndoInfo
>::Iterator it
= m_pendingUndoJobs
.begin();
1031 const Q3ValueList
<UndoInfo
>::Iterator end
= m_pendingUndoJobs
.end();
1033 while (!found
&& (it
!= end
)) {
1034 if ((*it
).id
== id
) {
1043 DolphinCommand command
= (*it
).command
;
1044 if (command
.type() == DolphinCommand::Trash
) {
1045 // To be able to perform an undo for the 'Move to Trash' operation
1046 // all source Urls must be updated with the trash Url. E. g. when moving
1047 // a file "test.txt" and a second file "test.txt" to the trash,
1048 // then the filenames in the trash are "0-test.txt" and "1-test.txt".
1049 QMap
<QString
, QString
> metaData
;
1050 KIO::Job
*kiojob
= qobject_cast
<KIO::Job
*>( job
);
1053 metaData
= kiojob
->metaData();
1055 KUrl::List newSourceUrls
;
1057 KUrl::List sourceUrls
= command
.source();
1058 KUrl::List::Iterator sourceIt
= sourceUrls
.begin();
1059 const KUrl::List::Iterator sourceEnd
= sourceUrls
.end();
1061 while (sourceIt
!= sourceEnd
) {
1062 QMap
<QString
, QString
>::ConstIterator metaIt
= metaData
.find("trashUrl-" + (*sourceIt
).path());
1063 if (metaIt
!= metaData
.end()) {
1064 newSourceUrls
.append(KUrl(metaIt
.data()));
1068 command
.setSource(newSourceUrls
);
1071 UndoManager::instance().addCommand(command
);
1072 m_pendingUndoJobs
.erase(it
);
1074 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
1075 switch (command
.type()) {
1076 case DolphinCommand::Copy
:
1077 statusBar
->setMessage(i18n("Copy operation completed."),
1078 DolphinStatusBar::OperationCompleted
);
1080 case DolphinCommand::Move
:
1081 statusBar
->setMessage(i18n("Move operation completed."),
1082 DolphinStatusBar::OperationCompleted
);
1084 case DolphinCommand::Trash
:
1085 statusBar
->setMessage(i18n("Move to trash operation completed."),
1086 DolphinStatusBar::OperationCompleted
);
1095 void DolphinMainWindow::toggleSidebar()
1097 if (m_sidebar
== 0) {
1104 KToggleAction
* sidebarAction
= static_cast<KToggleAction
*>(actionCollection()->action("sidebar"));
1105 sidebarAction
->setChecked(m_sidebar
!= 0);
1108 void DolphinMainWindow::closeSidebar()
1110 if (m_sidebar
== 0) {
1111 // the sidebar has already been closed
1115 // store width of sidebar and remember that the sidebar has been closed
1116 SidebarSettings
* settings
= DolphinSettings::instance().sidebarSettings();
1117 settings
->setVisible(false);
1118 settings
->setWidth(m_sidebar
->width());
1120 m_sidebar
->deleteLater();
1125 void DolphinMainWindow::init()
1127 // Check whether Dolphin runs the first time. If yes then
1128 // a proper default window size is given at the end of DolphinMainWindow::init().
1129 GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
1130 const bool firstRun
= generalSettings
->firstRun();
1132 setAcceptDrops(true);
1134 m_splitter
= new QSplitter(this);
1136 DolphinSettings
& settings
= DolphinSettings::instance();
1138 KBookmarkManager
* manager
= settings
.bookmarkManager();
1139 assert(manager
!= 0);
1140 KBookmarkGroup root
= manager
->root();
1141 if (root
.first().isNull()) {
1142 root
.addBookmark(manager
, i18n("Home"), settings
.generalSettings()->homeUrl(), "folder_home");
1143 root
.addBookmark(manager
, i18n("Storage Media"), KUrl("media:/"), "blockdevice");
1144 root
.addBookmark(manager
, i18n("Network"), KUrl("remote:/"), "network_local");
1145 root
.addBookmark(manager
, i18n("Root"), KUrl("/"), "folder_red");
1146 root
.addBookmark(manager
, i18n("Trash"), KUrl("trash:/"), "trashcan_full");
1150 setupGUI(Keys
|Save
|Create
|ToolBar
);
1152 const KUrl
& homeUrl
= root
.first().url();
1153 setCaption(homeUrl
.fileName());
1154 ViewProperties
props(homeUrl
);
1155 m_view
[PrimaryIdx
] = new DolphinView(this,
1159 props
.isShowHiddenFilesEnabled());
1161 m_activeView
= m_view
[PrimaryIdx
];
1163 setCentralWidget(m_splitter
);
1166 SidebarSettings
* sidebarSettings
= settings
.sidebarSettings();
1167 assert(sidebarSettings
!= 0);
1168 if (sidebarSettings
->visible()) {
1174 stateChanged("new_file");
1175 setAutoSaveSettings();
1177 QClipboard
* clipboard
= QApplication::clipboard();
1178 connect(clipboard
, SIGNAL(dataChanged()),
1179 this, SLOT(updatePasteAction()));
1180 updatePasteAction();
1183 setupCreateNewMenuActions();
1188 // assure a proper default size if Dolphin runs the first time
1193 void DolphinMainWindow::loadSettings()
1195 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
1197 KToggleAction
* splitAction
= static_cast<KToggleAction
*>(actionCollection()->action("split_view"));
1198 if (settings
->splitView()) {
1199 splitAction
->setChecked(true);
1203 updateViewActions();
1206 void DolphinMainWindow::setupActions()
1208 // setup 'File' menu
1209 KAction
* createFolder
= new KAction(i18n("Folder..."), actionCollection(), "create_folder");
1210 createFolder
->setIcon(KIcon("folder"));
1211 createFolder
->setShortcut(Qt::Key_N
);
1212 connect(createFolder
, SIGNAL(triggered()), this, SLOT(createFolder()));
1214 KAction
* rename
= new KAction(i18n("Rename"), actionCollection(), "rename");
1215 rename
->setShortcut(Qt::Key_F2
);
1216 connect(rename
, SIGNAL(triggered()), this, SLOT(rename()));
1218 KAction
* moveToTrash
= new KAction(i18n("Move to Trash"), actionCollection(), "move_to_trash");
1219 moveToTrash
->setIcon(KIcon("edittrash"));
1220 moveToTrash
->setShortcut(QKeySequence::Delete
);
1221 connect(moveToTrash
, SIGNAL(triggered()), this, SLOT(moveToTrash()));
1223 KAction
* deleteAction
= new KAction(i18n("Delete"), actionCollection(), "delete");
1224 deleteAction
->setShortcut(Qt::ALT
| Qt::Key_Delete
);
1225 deleteAction
->setIcon(KIcon("editdelete"));
1226 connect(deleteAction
, SIGNAL(triggered()), this, SLOT(deleteItems()));
1228 KAction
* properties
= new KAction(i18n("Propert&ies"), actionCollection(), "properties");
1229 properties
->setShortcut(Qt::Key_Alt
| Qt::Key_Return
);
1230 connect(properties
, SIGNAL(triggered()), this, SLOT(properties()));
1232 KStdAction::quit(this, SLOT(quit()), actionCollection());
1234 // setup 'Edit' menu
1235 UndoManager
& undoManager
= UndoManager::instance();
1236 KStdAction::undo(&undoManager
,
1238 actionCollection());
1239 connect(&undoManager
, SIGNAL(undoAvailable(bool)),
1240 this, SLOT(slotUndoAvailable(bool)));
1241 connect(&undoManager
, SIGNAL(undoTextChanged(const QString
&)),
1242 this, SLOT(slotUndoTextChanged(const QString
&)));
1244 KStdAction::redo(&undoManager
,
1246 actionCollection());
1247 connect(&undoManager
, SIGNAL(redoAvailable(bool)),
1248 this, SLOT(slotRedoAvailable(bool)));
1249 connect(&undoManager
, SIGNAL(redoTextChanged(const QString
&)),
1250 this, SLOT(slotRedoTextChanged(const QString
&)));
1252 KStdAction::cut(this, SLOT(cut()), actionCollection());
1253 KStdAction::copy(this, SLOT(copy()), actionCollection());
1254 KStdAction::paste(this, SLOT(paste()), actionCollection());
1256 KAction
* selectAll
= new KAction(i18n("Select All"), actionCollection(), "select_all");
1257 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1258 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1260 KAction
* invertSelection
= new KAction(i18n("Invert Selection"), actionCollection(), "invert_selection");
1261 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1262 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1264 // setup 'View' menu
1265 KStdAction::zoomIn(this,
1267 actionCollection());
1269 KStdAction::zoomOut(this,
1271 actionCollection());
1273 KToggleAction
* iconsView
= new KToggleAction(i18n("Icons"), actionCollection(), "icons");
1274 iconsView
->setShortcut(Qt::CTRL
| Qt::Key_1
);
1275 iconsView
->setIcon(KIcon("view_icon"));
1276 connect(iconsView
, SIGNAL(triggered()), this, SLOT(setIconsView()));
1278 KToggleAction
* detailsView
= new KToggleAction(i18n("Details"), actionCollection(), "details");
1279 detailsView
->setShortcut(Qt::CTRL
| Qt::Key_2
);
1280 detailsView
->setIcon(KIcon("view_text"));
1281 connect(detailsView
, SIGNAL(triggered()), this, SLOT(setDetailsView()));
1283 KToggleAction
* previewsView
= new KToggleAction(i18n("Previews"), actionCollection(), "previews");
1284 previewsView
->setShortcut(Qt::CTRL
| Qt::Key_3
);
1285 previewsView
->setIcon(KIcon("gvdirpart"));
1286 connect(previewsView
, SIGNAL(triggered()), this, SLOT(setPreviewsView()));
1288 QActionGroup
* viewModeGroup
= new QActionGroup(this);
1289 viewModeGroup
->addAction(iconsView
);
1290 viewModeGroup
->addAction(detailsView
);
1291 viewModeGroup
->addAction(previewsView
);
1293 KToggleAction
* sortByName
= new KToggleAction(i18n("By Name"), actionCollection(), "by_name");
1294 connect(sortByName
, SIGNAL(triggered()), this, SLOT(sortByName()));
1296 KToggleAction
* sortBySize
= new KToggleAction(i18n("By Size"), actionCollection(), "by_size");
1297 connect(sortBySize
, SIGNAL(triggered()), this, SLOT(sortBySize()));
1299 KToggleAction
* sortByDate
= new KToggleAction(i18n("By Date"), actionCollection(), "by_date");
1300 connect(sortByDate
, SIGNAL(triggered()), this, SLOT(sortByDate()));
1302 QActionGroup
* sortGroup
= new QActionGroup(this);
1303 sortGroup
->addAction(sortByName
);
1304 sortGroup
->addAction(sortBySize
);
1305 sortGroup
->addAction(sortByDate
);
1307 KToggleAction
* sortDescending
= new KToggleAction(i18n("Descending"), actionCollection(), "descending");
1308 connect(sortDescending
, SIGNAL(triggered()), this, SLOT(toggleSortOrder()));
1310 KToggleAction
* showHiddenFiles
= new KToggleAction(i18n("Show Hidden Files"), actionCollection(), "show_hidden_files");
1311 //showHiddenFiles->setShortcut(Qt::ALT | Qt::Key_ KDE4-TODO: what Qt-Key represents '.'?
1312 connect(showHiddenFiles
, SIGNAL(triggered()), this, SLOT(showHiddenFiles()));
1314 KToggleAction
* split
= new KToggleAction(i18n("Split View"), actionCollection(), "split_view");
1315 split
->setShortcut(Qt::Key_F10
);
1316 split
->setIcon(KIcon("view_left_right"));
1317 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1319 KAction
* reload
= new KAction(i18n("Reload"), "F5", actionCollection(), "reload");
1320 reload
->setShortcut(Qt::Key_F5
);
1321 reload
->setIcon(KIcon("reload"));
1322 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1324 KAction
* stop
= new KAction(i18n("Stop"), actionCollection(), "stop");
1325 stop
->setIcon(KIcon("stop"));
1326 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1328 KToggleAction
* showFullLocation
= new KToggleAction(i18n("Show Full Location"), actionCollection(), "editable_location");
1329 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1330 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1332 KToggleAction
* editLocation
= new KToggleAction(i18n("Edit Location"), actionCollection(), "edit_location");
1333 editLocation
->setShortcut(Qt::Key_F6
);
1334 connect(editLocation
, SIGNAL(triggered()), this, SLOT(editLocation()));
1336 KToggleAction
* sidebar
= new KToggleAction(i18n("Sidebar"), actionCollection(), "sidebar");
1337 sidebar
->setShortcut(Qt::Key_F9
);
1338 connect(sidebar
, SIGNAL(triggered()), this, SLOT(toggleSidebar()));
1340 KAction
* adjustViewProps
= new KAction(i18n("Adjust View Properties..."), actionCollection(), "view_properties");
1341 connect(adjustViewProps
, SIGNAL(triggered()), this, SLOT(adjustViewProperties()));
1344 KStdAction::back(this, SLOT(goBack()), actionCollection());
1345 KStdAction::forward(this, SLOT(goForward()), actionCollection());
1346 KStdAction::up(this, SLOT(goUp()), actionCollection());
1347 KStdAction::home(this, SLOT(goHome()), actionCollection());
1349 // setup 'Tools' menu
1350 KAction
* openTerminal
= new KAction(i18n("Open Terminal"), actionCollection(), "open_terminal");
1351 openTerminal
->setShortcut(Qt::Key_F4
);
1352 openTerminal
->setIcon(KIcon("konsole"));
1353 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1355 KAction
* findFile
= new KAction(i18n("Find File..."), actionCollection(), "find_file");
1356 findFile
->setShortcut(Qt::Key_F
);
1357 findFile
->setIcon(KIcon("filefind"));
1358 connect(findFile
, SIGNAL(triggered()), this, SLOT(findFile()));
1360 KToggleAction
* showFilterBar
= new KToggleAction(i18n("Show Filter Bar"), actionCollection(), "show_filter_bar");
1361 showFilterBar
->setShortcut(Qt::Key_Slash
);
1362 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1364 KAction
* compareFiles
= new KAction(i18n("Compare Files"), actionCollection(), "compare_files");
1365 compareFiles
->setIcon(KIcon("kompare"));
1366 compareFiles
->setEnabled(false);
1367 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1369 // setup 'Settings' menu
1370 KStdAction::preferences(this, SLOT(editSettings()), actionCollection());
1373 void DolphinMainWindow::setupCreateNewMenuActions()
1375 // Parts of the following code have been taken
1376 // from the class KNewMenu located in
1377 // libqonq/knewmenu.h of Konqueror.
1378 // Copyright (C) 1998, 1999 David Faure <faure@kde.org>
1379 // 2003 Sven Leiber <s.leiber@web.de>
1381 QStringList files
= actionCollection()->instance()->dirs()->findAllResources("templates");
1382 for (QStringList::Iterator it
= files
.begin() ; it
!= files
.end(); ++it
) {
1383 if ((*it
)[0] != '.' ) {
1384 KSimpleConfig
config(*it
, true);
1385 config
.setDesktopGroup();
1387 // tricky solution to ensure that TextFile is at the beginning
1388 // because this filetype is the most used (according kde-core discussion)
1389 const QString
name(config
.readEntry("Name"));
1392 const QString
path(config
.readPathEntry("Url"));
1393 if (!path
.endsWith("emptydir")) {
1394 if (path
.endsWith("TextFile.txt")) {
1397 else if (!KDesktopFile::isDesktopFile(path
)) {
1400 else if (path
.endsWith("Url.desktop")){
1403 else if (path
.endsWith("Program.desktop")){
1410 const QString
icon(config
.readEntry("Icon"));
1411 const QString
comment(config
.readEntry("Comment"));
1412 const QString
type(config
.readEntry("Type"));
1414 const QString
filePath(*it
);
1417 if (type
== "Link") {
1418 CreateFileEntry entry
;
1421 entry
.comment
= comment
;
1422 entry
.templatePath
= filePath
;
1423 m_createFileTemplates
.insert(key
, entry
);
1428 m_createFileTemplates
.sort();
1430 unplugActionList("create_actions");
1431 KSortableList
<CreateFileEntry
, QString
>::ConstIterator it
= m_createFileTemplates
.begin();
1432 KSortableList
<CreateFileEntry
, QString
>::ConstIterator end
= m_createFileTemplates
.end();
1433 /* KDE4-TODO: don't port this code; use KNewMenu instead
1435 CreateFileEntry entry = (*it).value();
1436 KAction* action = new KAction(entry.name);
1437 action->setIcon(entry.icon);
1438 action->setName((*it).index());
1439 connect(action, SIGNAL(activated()),
1440 this, SLOT(createFile()));
1442 const QChar section = ((*it).index()[0]);
1446 m_fileGroupActions.append(action);
1452 // TODO: not used yet. See documentation of DolphinMainWindow::linkGroupActions()
1453 // and DolphinMainWindow::linkToDeviceActions() in the header file for details.
1454 //m_linkGroupActions.append(action);
1459 // TODO: not used yet. See documentation of DolphinMainWindow::linkGroupActions()
1460 // and DolphinMainWindow::linkToDeviceActions() in the header file for details.
1461 //m_linkToDeviceActions.append(action);
1470 plugActionList("create_file_group", m_fileGroupActions);
1471 //plugActionList("create_link_group", m_linkGroupActions);
1472 //plugActionList("link_to_device", m_linkToDeviceActions);*/
1475 void DolphinMainWindow::updateHistory()
1478 const Q3ValueList
<UrlNavigator::HistoryElem
> list
= m_activeView
->urlHistory(index
);
1480 KAction
* backAction
= actionCollection()->action("go_back");
1481 if (backAction
!= 0) {
1482 backAction
->setEnabled(index
< static_cast<int>(list
.count()) - 1);
1485 KAction
* forwardAction
= actionCollection()->action("go_forward");
1486 if (forwardAction
!= 0) {
1487 forwardAction
->setEnabled(index
> 0);
1491 void DolphinMainWindow::updateEditActions()
1493 const KFileItemList
* list
= m_activeView
->selectedItems();
1494 if ((list
== 0) || (*list
).isEmpty()) {
1495 stateChanged("has_no_selection");
1498 stateChanged("has_selection");
1500 KAction
* renameAction
= actionCollection()->action("rename");
1501 if (renameAction
!= 0) {
1502 renameAction
->setEnabled(list
->count() >= 1);
1505 bool enableMoveToTrash
= true;
1507 KFileItemList::const_iterator it
= list
->begin();
1508 const KFileItemList::const_iterator end
= list
->end();
1510 KFileItem
* item
= *it
;
1511 const KUrl
& url
= item
->url();
1512 // only enable the 'Move to Trash' action for local files
1513 if (!url
.isLocalFile()) {
1514 enableMoveToTrash
= false;
1519 KAction
* moveToTrashAction
= actionCollection()->action("move_to_trash");
1520 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1522 updatePasteAction();
1525 void DolphinMainWindow::updateViewActions()
1527 KAction
* zoomInAction
= actionCollection()->action(KStdAction::stdName(KStdAction::ZoomIn
));
1528 if (zoomInAction
!= 0) {
1529 zoomInAction
->setEnabled(m_activeView
->isZoomInPossible());
1532 KAction
* zoomOutAction
= actionCollection()->action(KStdAction::stdName(KStdAction::ZoomOut
));
1533 if (zoomOutAction
!= 0) {
1534 zoomOutAction
->setEnabled(m_activeView
->isZoomOutPossible());
1537 KAction
* action
= 0;
1538 switch (m_activeView
->mode()) {
1539 case DolphinView::IconsView
:
1540 action
= actionCollection()->action("icons");
1542 case DolphinView::DetailsView
:
1543 action
= actionCollection()->action("details");
1545 case DolphinView::PreviewsView
:
1546 action
= actionCollection()->action("previews");
1553 KToggleAction
* toggleAction
= static_cast<KToggleAction
*>(action
);
1554 toggleAction
->setChecked(true);
1557 slotSortingChanged(m_activeView
->sorting());
1558 slotSortOrderChanged(m_activeView
->sortOrder());
1560 KToggleAction
* showFilterBarAction
=
1561 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
1562 showFilterBarAction
->setChecked(m_activeView
->isFilterBarVisible());
1564 KToggleAction
* showHiddenFilesAction
=
1565 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
1566 showHiddenFilesAction
->setChecked(m_activeView
->isShowHiddenFilesEnabled());
1568 KToggleAction
* splitAction
= static_cast<KToggleAction
*>(actionCollection()->action("split_view"));
1569 splitAction
->setChecked(m_view
[SecondaryIdx
] != 0);
1571 KToggleAction
* sidebarAction
= static_cast<KToggleAction
*>(actionCollection()->action("sidebar"));
1572 sidebarAction
->setChecked(m_sidebar
!= 0);
1575 void DolphinMainWindow::updateGoActions()
1577 KAction
* goUpAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Up
));
1578 const KUrl
& currentUrl
= m_activeView
->url();
1579 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1582 void DolphinMainWindow::updateViewProperties(const KUrl::List
& urls
)
1584 if (urls
.isEmpty()) {
1588 // Updating the view properties might take up to several seconds
1589 // when dragging several thousand Urls. Writing a KIO slave for this
1590 // use case is not worth the effort, but at least the main widget
1591 // must be disabled and a progress should be shown.
1592 ProgressIndicator
progressIndicator(this,
1593 i18n("Updating view properties..."),
1597 KUrl::List::ConstIterator end
= urls
.end();
1598 for(KUrl::List::ConstIterator it
= urls
.begin(); it
!= end
; ++it
) {
1599 progressIndicator
.execOperation();
1601 ViewProperties
props(*it
);
1606 void DolphinMainWindow::copyUrls(const KUrl::List
& source
, const KUrl
& dest
)
1608 KIO::Job
* job
= KIO::copy(source
, dest
);
1609 addPendingUndoJob(job
, DolphinCommand::Copy
, source
, dest
);
1612 void DolphinMainWindow::moveUrls(const KUrl::List
& source
, const KUrl
& dest
)
1614 KIO::Job
* job
= KIO::move(source
, dest
);
1615 addPendingUndoJob(job
, DolphinCommand::Move
, source
, dest
);
1618 void DolphinMainWindow::addPendingUndoJob(KIO::Job
* job
,
1619 DolphinCommand::Type commandType
,
1620 const KUrl::List
& source
,
1623 connect(job
, SIGNAL(result(KJob
*)),
1624 this, SLOT(addUndoOperation(KJob
*)));
1627 undoInfo
.id
= job
->progressId();
1628 undoInfo
.command
= DolphinCommand(commandType
, source
, dest
, this);
1629 m_pendingUndoJobs
.append(undoInfo
);
1632 void DolphinMainWindow::clearStatusBar()
1634 m_activeView
->statusBar()->clear();
1637 void DolphinMainWindow::openSidebar()
1639 if (m_sidebar
!= 0) {
1640 // the sidebar is already open
1644 m_sidebar
= new Sidebar(this, m_splitter
);
1647 connect(m_sidebar
, SIGNAL(urlChanged(const KUrl
&)),
1648 this, SLOT(slotUrlChangeRequest(const KUrl
&)));
1649 m_splitter
->setCollapsible(m_sidebar
, false);
1650 m_splitter
->setResizeMode(m_sidebar
, QSplitter::KeepSize
);
1651 m_splitter
->moveToFirst(m_sidebar
);
1653 SidebarSettings
* settings
= DolphinSettings::instance().sidebarSettings();
1654 settings
->setVisible(true);
1657 #include "dolphinmainwindow.moc"