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::slotRedo()
318 UndoManager::instance().redo(this);
321 void DolphinMainWindow::slotUndo()
323 UndoManager::instance().undo(this);
326 void DolphinMainWindow::slotNewMainWindow()
328 DolphinApplication::app()->createMainWindow()->show();
331 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
334 //KConfig* config = KGlobal::config();
335 //config->setGroup("General");
336 //config->writeEntry("First Run", false);
338 DolphinSettings
& settings
= DolphinSettings::instance();
339 GeneralSettings
* generalSettings
= settings
.generalSettings();
340 generalSettings
->setFirstRun(false);
342 SidebarSettings
* sidebarSettings
= settings
.sidebarSettings();
343 const bool isSidebarVisible
= (m_sidebar
!= 0);
344 sidebarSettings
->setVisible(isSidebarVisible
);
345 if (isSidebarVisible
) {
346 sidebarSettings
->setWidth(m_sidebar
->width());
351 KMainWindow::closeEvent(event
);
354 void DolphinMainWindow::saveProperties(KConfig
* config
)
356 config
->setGroup("Primary view");
357 config
->writeEntry("Url", m_view
[PrimaryIdx
]->url().url());
358 config
->writeEntry("Editable Url", m_view
[PrimaryIdx
]->isUrlEditable());
359 if (m_view
[SecondaryIdx
] != 0) {
360 config
->setGroup("Secondary view");
361 config
->writeEntry("Url", m_view
[SecondaryIdx
]->url().url());
362 config
->writeEntry("Editable Url", m_view
[SecondaryIdx
]->isUrlEditable());
366 void DolphinMainWindow::readProperties(KConfig
* config
)
368 config
->setGroup("Primary view");
369 m_view
[PrimaryIdx
]->setUrl(config
->readEntry("Url"));
370 m_view
[PrimaryIdx
]->setUrlEditable(config
->readBoolEntry("Editable Url"));
371 if (config
->hasGroup("Secondary view")) {
372 config
->setGroup("Secondary view");
373 if (m_view
[SecondaryIdx
] == 0) {
376 m_view
[SecondaryIdx
]->setUrl(config
->readEntry("Url"));
377 m_view
[SecondaryIdx
]->setUrlEditable(config
->readBoolEntry("Editable Url"));
379 else if (m_view
[SecondaryIdx
] != 0) {
384 void DolphinMainWindow::createFolder()
386 // Parts of the following code have been taken
387 // from the class KonqPopupMenu located in
388 // libqonq/konq_popupmenu.h of Konqueror.
389 // (Copyright (C) 2000 David Faure <faure@kde.org>,
390 // Copyright (C) 2001 Holger Freyther <freyther@yahoo.com>)
394 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
395 const KUrl
baseUrl(m_activeView
->url());
397 QString
name(i18n("New Folder"));
398 baseUrl
.path(KUrl::AddTrailingSlash
);
401 if (baseUrl
.isLocalFile() && QFileInfo(baseUrl
.path(KUrl::AddTrailingSlash
) + name
).exists()) {
402 name
= KIO::RenameDlg::suggestName(baseUrl
, i18n("New Folder"));
406 name
= KInputDialog::getText(i18n("New Folder"),
407 i18n("Enter folder name:" ),
413 // the user has pressed 'Cancel'
417 assert(!name
.isEmpty());
420 if ((name
[0] == '/') || (name
[0] == '~')) {
421 url
.setPath(KShell::tildeExpand(name
));
424 name
= KIO::encodeFileName(name
);
428 ok
= KIO::NetAccess::mkdir(url
, this);
430 // TODO: provide message type hint
432 statusBar
->setMessage(i18n("Created folder %1.",url
.path()),
433 DolphinStatusBar::OperationCompleted
);
435 DolphinCommand
command(DolphinCommand::CreateFolder
, KUrl::List(), url
);
436 UndoManager::instance().addCommand(command
);
439 // Creating of the folder has been failed. Check whether the creating
440 // has been failed because a folder with the same name exists...
441 if (KIO::NetAccess::exists(url
, true, this)) {
442 statusBar
->setMessage(i18n("A folder named %1 already exists.",url
.path()),
443 DolphinStatusBar::Error
);
446 statusBar
->setMessage(i18n("Creating of folder %1 failed.",url
.path()),
447 DolphinStatusBar::Error
);
453 void DolphinMainWindow::createFile()
455 // Parts of the following code have been taken
456 // from the class KonqPopupMenu located in
457 // libqonq/konq_popupmenu.h of Konqueror.
458 // (Copyright (C) 2000 David Faure <faure@kde.org>,
459 // Copyright (C) 2001 Holger Freyther <freyther@yahoo.com>)
463 // TODO: const Entry& entry = m_createFileTemplates[QString(sender->name())];
464 // should be enough. Anyway: the implemantation of [] does a linear search internally too.
465 KSortableList
<CreateFileEntry
, QString
>::ConstIterator it
= m_createFileTemplates
.begin();
466 KSortableList
<CreateFileEntry
, QString
>::ConstIterator end
= m_createFileTemplates
.end();
468 const QString
senderName(sender()->name());
470 CreateFileEntry entry
;
471 while (!found
&& (it
!= end
)) {
472 if ((*it
).index() == senderName
) {
473 entry
= (*it
).value();
481 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
482 if (!found
|| !QFile::exists(entry
.templatePath
)) {
483 statusBar
->setMessage(i18n("Could not create file."), DolphinStatusBar::Error
);
487 // Get the source path of the template which should be copied.
488 // The source path is part of the Url entry of the desktop file.
489 const int pos
= entry
.templatePath
.findRev('/');
490 QString
sourcePath(entry
.templatePath
.left(pos
+ 1));
491 sourcePath
+= KDesktopFile(entry
.templatePath
, true).readPathEntry("Url");
493 QString
name(i18n(entry
.name
.ascii()));
494 // Most entry names end with "..." (e. g. "HTML File..."), which is ok for
495 // menus but no good choice for a new file name -> remove the dots...
496 name
.replace("...", QString::null
);
498 // add the file extension to the name
499 name
.append(sourcePath
.right(sourcePath
.length() - sourcePath
.findRev('.')));
501 // Check whether a file with the current name already exists. If yes suggest automatically
502 // a unique file name (e. g. "HTML File" will be replaced by "HTML File_1").
503 const KUrl
viewUrl(m_activeView
->url());
504 const bool fileExists
= viewUrl
.isLocalFile() &&
505 QFileInfo(viewUrl
.path(KUrl::AddTrailingSlash
) + KIO::encodeFileName(name
)).exists();
507 name
= KIO::RenameDlg::suggestName(viewUrl
, name
);
510 // let the user change the suggested file name
512 name
= KInputDialog::getText(entry
.name
,
518 // the user has pressed 'Cancel'
522 // before copying the template to the destination path check whether a file
523 // with the given name already exists
524 const QString
destPath(viewUrl
.pathOrUrl() + "/" + KIO::encodeFileName(name
));
525 const KUrl
destUrl(destPath
);
526 if (KIO::NetAccess::exists(destUrl
, false, this)) {
527 statusBar
->setMessage(i18n("A file named %1 already exists.",name
),
528 DolphinStatusBar::Error
);
532 // copy the template to the destination path
533 const KUrl
sourceUrl(sourcePath
);
534 KIO::CopyJob
* job
= KIO::copyAs(sourceUrl
, destUrl
);
535 job
->setDefaultPermissions(true);
536 if (KIO::NetAccess::synchronousRun(job
, this)) {
537 statusBar
->setMessage(i18n("Created file %1.",name
),
538 DolphinStatusBar::OperationCompleted
);
541 list
.append(sourceUrl
);
542 DolphinCommand
command(DolphinCommand::CreateFile
, list
, destUrl
);
543 UndoManager::instance().addCommand(command
);
547 statusBar
->setMessage(i18n("Creating of file %1 failed.",name
),
548 DolphinStatusBar::Error
);
552 void DolphinMainWindow::rename()
555 m_activeView
->renameSelectedItems();
558 void DolphinMainWindow::moveToTrash()
561 KUrl::List selectedUrls
= m_activeView
->selectedUrls();
562 KIO::Job
* job
= KIO::trash(selectedUrls
);
563 addPendingUndoJob(job
, DolphinCommand::Trash
, selectedUrls
, m_activeView
->url());
566 void DolphinMainWindow::deleteItems()
570 KUrl::List list
= m_activeView
->selectedUrls();
571 const uint itemCount
= list
.count();
572 assert(itemCount
>= 1);
576 text
= i18n("Do you really want to delete the %1 selected items?",itemCount
);
579 const KUrl
& url
= list
.first();
580 text
= i18n("Do you really want to delete '%1'?",url
.fileName());
583 const bool del
= KMessageBox::warningContinueCancel(this,
586 KGuiItem(i18n("Delete"), SmallIcon("editdelete"))
587 ) == KMessageBox::Continue
;
589 KIO::Job
* job
= KIO::del(list
);
590 connect(job
, SIGNAL(result(KJob
*)),
591 this, SLOT(slotHandleJobError(KJob
*)));
592 connect(job
, SIGNAL(result(KJob
*)),
593 this, SLOT(slotDeleteFileFinished(KJob
*)));
597 void DolphinMainWindow::properties()
599 const KFileItemList
* sourceList
= m_activeView
->selectedItems();
600 if (sourceList
== 0) {
605 KFileItemList::const_iterator it
= sourceList
->begin();
606 const KFileItemList::const_iterator end
= sourceList
->end();
613 new KPropertiesDialog(list
, this);
616 void DolphinMainWindow::quit()
621 void DolphinMainWindow::slotHandleJobError(KJob
* job
)
623 if (job
->error() != 0) {
624 m_activeView
->statusBar()->setMessage(job
->errorString(),
625 DolphinStatusBar::Error
);
629 void DolphinMainWindow::slotDeleteFileFinished(KJob
* job
)
631 if (job
->error() == 0) {
632 m_activeView
->statusBar()->setMessage(i18n("Delete operation completed."),
633 DolphinStatusBar::OperationCompleted
);
635 // TODO: In opposite to the 'Move to Trash' operation in the class KFileIconView
636 // no rearranging of the item position is done when a file has been deleted.
637 // This is bypassed by reloading the view, but it might be worth to investigate
638 // deeper for the root of this issue.
639 m_activeView
->reload();
643 void DolphinMainWindow::slotUndoAvailable(bool available
)
645 KAction
* undoAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Undo
));
646 if (undoAction
!= 0) {
647 undoAction
->setEnabled(available
);
651 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
653 KAction
* undoAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Undo
));
654 if (undoAction
!= 0) {
655 undoAction
->setText(text
);
659 void DolphinMainWindow::slotRedoAvailable(bool available
)
661 KAction
* redoAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Redo
));
662 if (redoAction
!= 0) {
663 redoAction
->setEnabled(available
);
667 void DolphinMainWindow::slotRedoTextChanged(const QString
& text
)
669 KAction
* redoAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Redo
));
670 if (redoAction
!= 0) {
671 redoAction
->setText(text
);
675 void DolphinMainWindow::cut()
677 // TODO: this boolean doesn't work between instances of dolphin or with konqueror or with other
678 // apps. The "application/x-kde-cutselection" mimetype should be used instead, see KonqMimeData
680 m_clipboardContainsCutData
= true;
681 /* KDE4-TODO: Q3DragObject* data = new KUrlDrag(m_activeView->selectedUrls(),
683 QApplication::clipboard()->setData(data);*/
686 void DolphinMainWindow::copy()
688 m_clipboardContainsCutData
= false;
690 Q3DragObject* data = new KUrlDrag(m_activeView->selectedUrls(),
692 QApplication::clipboard()->setData(data);*/
695 void DolphinMainWindow::paste()
697 /* KDE4-TODO: - see KonqOperations::doPaste
698 QClipboard* clipboard = QApplication::clipboard();
699 QMimeSource* data = clipboard->data();
700 if (!KUrlDrag::canDecode(data)) {
706 KUrl::List sourceUrls;
707 KUrlDrag::decode(data, sourceUrls);
709 // per default the pasting is done into the current Url of the view
710 KUrl destUrl(m_activeView->url());
712 // check whether the pasting should be done into a selected directory
713 KUrl::List selectedUrls = m_activeView->selectedUrls();
714 if (selectedUrls.count() == 1) {
715 const KFileItem fileItem(S_IFDIR,
717 selectedUrls.first(),
719 if (fileItem.isDir()) {
720 // only one item is selected which is a directory, hence paste
721 // into this directory
722 destUrl = selectedUrls.first();
727 updateViewProperties(sourceUrls);
728 if (m_clipboardContainsCutData) {
729 moveUrls(sourceUrls, destUrl);
730 m_clipboardContainsCutData = false;
734 copyUrls(sourceUrls, destUrl);
738 void DolphinMainWindow::updatePasteAction()
740 KAction
* pasteAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Paste
));
741 if (pasteAction
== 0) {
745 QString
text(i18n("Paste"));
746 QClipboard
* clipboard
= QApplication::clipboard();
747 QMimeSource
* data
= clipboard
->data();
749 if (KUrlDrag::canDecode(data)) {
750 pasteAction->setEnabled(true);
753 KUrlDrag::decode(data, urls);
754 const int count = urls.count();
756 pasteAction->setText(i18n("Paste 1 File"));
759 pasteAction->setText(i18n("Paste %1 Files").arg(count));
763 pasteAction
->setEnabled(false);
764 pasteAction
->setText(i18n("Paste"));
767 if (pasteAction
->isEnabled()) {
768 KUrl::List urls
= m_activeView
->selectedUrls();
769 const uint count
= urls
.count();
771 // pasting should not be allowed when more than one file
773 pasteAction
->setEnabled(false);
775 else if (count
== 1) {
776 // Only one file is selected. Pasting is only allowed if this
777 // file is a directory.
778 // TODO: this doesn't work with remote protocols; instead we need a
779 // m_activeView->selectedFileItems() to get the real KFileItems
780 const KFileItem
fileItem(S_IFDIR
,
784 pasteAction
->setEnabled(fileItem
.isDir());
789 void DolphinMainWindow::selectAll()
792 m_activeView
->selectAll();
795 void DolphinMainWindow::invertSelection()
798 m_activeView
->invertSelection();
800 void DolphinMainWindow::setIconsView()
802 m_activeView
->setMode(DolphinView::IconsView
);
805 void DolphinMainWindow::setDetailsView()
807 m_activeView
->setMode(DolphinView::DetailsView
);
810 void DolphinMainWindow::setPreviewsView()
812 m_activeView
->setMode(DolphinView::PreviewsView
);
815 void DolphinMainWindow::sortByName()
817 m_activeView
->setSorting(DolphinView::SortByName
);
820 void DolphinMainWindow::sortBySize()
822 m_activeView
->setSorting(DolphinView::SortBySize
);
825 void DolphinMainWindow::sortByDate()
827 m_activeView
->setSorting(DolphinView::SortByDate
);
830 void DolphinMainWindow::toggleSortOrder()
832 const Qt::SortOrder order
= (m_activeView
->sortOrder() == Qt::Ascending
) ?
835 m_activeView
->setSortOrder(order
);
838 void DolphinMainWindow::toggleSplitView()
840 if (m_view
[SecondaryIdx
] == 0) {
841 // create a secondary view
842 m_view
[SecondaryIdx
] = new DolphinView(this,
844 m_view
[PrimaryIdx
]->url(),
845 m_view
[PrimaryIdx
]->mode(),
846 m_view
[PrimaryIdx
]->isShowHiddenFilesEnabled());
847 m_view
[SecondaryIdx
]->show();
850 // remove secondary view
851 if (m_activeView
== m_view
[PrimaryIdx
]) {
852 m_view
[SecondaryIdx
]->close();
853 m_view
[SecondaryIdx
]->deleteLater();
854 m_view
[SecondaryIdx
] = 0;
855 setActiveView(m_view
[PrimaryIdx
]);
858 // The secondary view is active, hence from the users point of view
859 // the content of the secondary view should be moved to the primary view.
860 // From an implementation point of view it is more efficient to close
861 // the primary view and exchange the internal pointers afterwards.
862 m_view
[PrimaryIdx
]->close();
863 m_view
[PrimaryIdx
]->deleteLater();
864 m_view
[PrimaryIdx
] = m_view
[SecondaryIdx
];
865 m_view
[SecondaryIdx
] = 0;
866 setActiveView(m_view
[PrimaryIdx
]);
871 void DolphinMainWindow::reloadView()
874 m_activeView
->reload();
877 void DolphinMainWindow::stopLoading()
881 void DolphinMainWindow::showHiddenFiles()
885 const KToggleAction
* showHiddenFilesAction
=
886 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
887 const bool show
= showHiddenFilesAction
->isChecked();
888 m_activeView
->setShowHiddenFilesEnabled(show
);
891 void DolphinMainWindow::showFilterBar()
893 const KToggleAction
* showFilterBarAction
=
894 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
895 const bool show
= showFilterBarAction
->isChecked();
896 m_activeView
->slotShowFilterBar(show
);
899 void DolphinMainWindow::zoomIn()
901 m_activeView
->zoomIn();
905 void DolphinMainWindow::zoomOut()
907 m_activeView
->zoomOut();
911 void DolphinMainWindow::toggleEditLocation()
915 KToggleAction
* action
= static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
917 bool editOrBrowse
= action
->isChecked();
918 // action->setChecked(action->setChecked);
919 m_activeView
->setUrlEditable(editOrBrowse
);
922 void DolphinMainWindow::editLocation()
924 KToggleAction
* action
= static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
925 action
->setChecked(true);
926 m_activeView
->setUrlEditable(true);
929 void DolphinMainWindow::adjustViewProperties()
932 ViewPropertiesDialog
dlg(m_activeView
);
936 void DolphinMainWindow::goBack()
939 m_activeView
->goBack();
942 void DolphinMainWindow::goForward()
945 m_activeView
->goForward();
948 void DolphinMainWindow::goUp()
951 m_activeView
->goUp();
954 void DolphinMainWindow::goHome()
957 m_activeView
->goHome();
960 void DolphinMainWindow::openTerminal()
962 QString
command("konsole --workdir \"");
963 command
.append(m_activeView
->url().path());
964 command
.append('\"');
966 KRun::runCommand(command
, "Konsole", "konsole");
969 void DolphinMainWindow::findFile()
971 KRun::run("kfind", m_activeView
->url());
974 void DolphinMainWindow::compareFiles()
976 // The method is only invoked if exactly 2 files have
977 // been selected. The selected files may be:
978 // - both in the primary view
979 // - both in the secondary view
980 // - one in the primary view and the other in the secondary
982 assert(m_view
[PrimaryIdx
] != 0);
986 KUrl::List urls
= m_view
[PrimaryIdx
]->selectedUrls();
988 switch (urls
.count()) {
990 assert(m_view
[SecondaryIdx
] != 0);
991 urls
= m_view
[SecondaryIdx
]->selectedUrls();
992 assert(urls
.count() == 2);
1000 assert(m_view
[SecondaryIdx
] != 0);
1001 urls
= m_view
[SecondaryIdx
]->selectedUrls();
1002 assert(urls
.count() == 1);
1014 // may not happen: compareFiles may only get invoked if 2
1015 // files are selected
1020 QString
command("kompare -c \"");
1021 command
.append(urlA
.pathOrUrl());
1022 command
.append("\" \"");
1023 command
.append(urlB
.pathOrUrl());
1024 command
.append('\"');
1025 KRun::runCommand(command
, "Kompare", "kompare");
1029 void DolphinMainWindow::editSettings()
1031 // TODO: make a static method for opening the settings dialog
1032 DolphinSettingsDialog
dlg(this);
1036 void DolphinMainWindow::addUndoOperation(KJob
* job
)
1038 if (job
->error() != 0) {
1039 slotHandleJobError(job
);
1042 const int id
= job
->progressId();
1044 // set iterator to the executed command with the current id...
1045 Q3ValueList
<UndoInfo
>::Iterator it
= m_pendingUndoJobs
.begin();
1046 const Q3ValueList
<UndoInfo
>::Iterator end
= m_pendingUndoJobs
.end();
1048 while (!found
&& (it
!= end
)) {
1049 if ((*it
).id
== id
) {
1058 DolphinCommand command
= (*it
).command
;
1059 if (command
.type() == DolphinCommand::Trash
) {
1060 // To be able to perform an undo for the 'Move to Trash' operation
1061 // all source Urls must be updated with the trash Url. E. g. when moving
1062 // a file "test.txt" and a second file "test.txt" to the trash,
1063 // then the filenames in the trash are "0-test.txt" and "1-test.txt".
1064 QMap
<QString
, QString
> metaData
;
1065 KIO::Job
*kiojob
= qobject_cast
<KIO::Job
*>( job
);
1068 metaData
= kiojob
->metaData();
1070 KUrl::List newSourceUrls
;
1072 KUrl::List sourceUrls
= command
.source();
1073 KUrl::List::Iterator sourceIt
= sourceUrls
.begin();
1074 const KUrl::List::Iterator sourceEnd
= sourceUrls
.end();
1076 while (sourceIt
!= sourceEnd
) {
1077 QMap
<QString
, QString
>::ConstIterator metaIt
= metaData
.find("trashUrl-" + (*sourceIt
).path());
1078 if (metaIt
!= metaData
.end()) {
1079 newSourceUrls
.append(KUrl(metaIt
.data()));
1083 command
.setSource(newSourceUrls
);
1086 UndoManager::instance().addCommand(command
);
1087 m_pendingUndoJobs
.erase(it
);
1089 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
1090 switch (command
.type()) {
1091 case DolphinCommand::Copy
:
1092 statusBar
->setMessage(i18n("Copy operation completed."),
1093 DolphinStatusBar::OperationCompleted
);
1095 case DolphinCommand::Move
:
1096 statusBar
->setMessage(i18n("Move operation completed."),
1097 DolphinStatusBar::OperationCompleted
);
1099 case DolphinCommand::Trash
:
1100 statusBar
->setMessage(i18n("Move to trash operation completed."),
1101 DolphinStatusBar::OperationCompleted
);
1110 void DolphinMainWindow::toggleSidebar()
1112 if (m_sidebar
== 0) {
1119 KToggleAction
* sidebarAction
= static_cast<KToggleAction
*>(actionCollection()->action("sidebar"));
1120 sidebarAction
->setChecked(m_sidebar
!= 0);
1123 void DolphinMainWindow::closeSidebar()
1125 if (m_sidebar
== 0) {
1126 // the sidebar has already been closed
1130 // store width of sidebar and remember that the sidebar has been closed
1131 SidebarSettings
* settings
= DolphinSettings::instance().sidebarSettings();
1132 settings
->setVisible(false);
1133 settings
->setWidth(m_sidebar
->width());
1135 m_sidebar
->deleteLater();
1140 void DolphinMainWindow::init()
1142 // Check whether Dolphin runs the first time. If yes then
1143 // a proper default window size is given at the end of DolphinMainWindow::init().
1144 GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
1145 const bool firstRun
= generalSettings
->firstRun();
1147 setAcceptDrops(true);
1149 m_splitter
= new QSplitter(this);
1151 DolphinSettings
& settings
= DolphinSettings::instance();
1153 KBookmarkManager
* manager
= settings
.bookmarkManager();
1154 assert(manager
!= 0);
1155 KBookmarkGroup root
= manager
->root();
1156 if (root
.first().isNull()) {
1157 root
.addBookmark(manager
, i18n("Home"), settings
.generalSettings()->homeUrl(), "folder_home");
1158 root
.addBookmark(manager
, i18n("Storage Media"), KUrl("media:/"), "blockdevice");
1159 root
.addBookmark(manager
, i18n("Network"), KUrl("remote:/"), "network_local");
1160 root
.addBookmark(manager
, i18n("Root"), KUrl("/"), "folder_red");
1161 root
.addBookmark(manager
, i18n("Trash"), KUrl("trash:/"), "trashcan_full");
1165 setupGUI(Keys
|Save
|Create
|ToolBar
);
1167 const KUrl
& homeUrl
= root
.first().url();
1168 setCaption(homeUrl
.fileName());
1169 ViewProperties
props(homeUrl
);
1170 m_view
[PrimaryIdx
] = new DolphinView(this,
1174 props
.isShowHiddenFilesEnabled());
1176 m_activeView
= m_view
[PrimaryIdx
];
1178 setCentralWidget(m_splitter
);
1181 SidebarSettings
* sidebarSettings
= settings
.sidebarSettings();
1182 assert(sidebarSettings
!= 0);
1183 if (sidebarSettings
->visible()) {
1189 stateChanged("new_file");
1190 setAutoSaveSettings();
1192 QClipboard
* clipboard
= QApplication::clipboard();
1193 connect(clipboard
, SIGNAL(dataChanged()),
1194 this, SLOT(updatePasteAction()));
1195 updatePasteAction();
1198 setupCreateNewMenuActions();
1203 // assure a proper default size if Dolphin runs the first time
1208 void DolphinMainWindow::loadSettings()
1210 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
1212 KToggleAction
* splitAction
= static_cast<KToggleAction
*>(actionCollection()->action("split_view"));
1213 if (settings
->splitView()) {
1214 splitAction
->setChecked(true);
1218 updateViewActions();
1221 void DolphinMainWindow::setupActions()
1223 // setup 'File' menu
1224 KAction
*action
= new KAction(KIcon("window_new"), i18n( "New &Window" ), actionCollection(), "new_window" );
1225 connect(action
, SIGNAL(triggered()), this, SLOT(slotNewMainWindow()));
1227 KAction
* createFolder
= new KAction(i18n("Folder..."), actionCollection(), "create_folder");
1228 createFolder
->setIcon(KIcon("folder"));
1229 createFolder
->setShortcut(Qt::Key_N
);
1230 connect(createFolder
, SIGNAL(triggered()), this, SLOT(createFolder()));
1232 KAction
* rename
= new KAction(i18n("Rename"), actionCollection(), "rename");
1233 rename
->setShortcut(Qt::Key_F2
);
1234 connect(rename
, SIGNAL(triggered()), this, SLOT(rename()));
1236 KAction
* moveToTrash
= new KAction(i18n("Move to Trash"), actionCollection(), "move_to_trash");
1237 moveToTrash
->setIcon(KIcon("edittrash"));
1238 moveToTrash
->setShortcut(QKeySequence::Delete
);
1239 connect(moveToTrash
, SIGNAL(triggered()), this, SLOT(moveToTrash()));
1241 KAction
* deleteAction
= new KAction(i18n("Delete"), actionCollection(), "delete");
1242 deleteAction
->setShortcut(Qt::ALT
| Qt::Key_Delete
);
1243 deleteAction
->setIcon(KIcon("editdelete"));
1244 connect(deleteAction
, SIGNAL(triggered()), this, SLOT(deleteItems()));
1246 KAction
* properties
= new KAction(i18n("Propert&ies"), actionCollection(), "properties");
1247 properties
->setShortcut(Qt::Key_Alt
| Qt::Key_Return
);
1248 connect(properties
, SIGNAL(triggered()), this, SLOT(properties()));
1250 KStdAction::quit(this, SLOT(quit()), actionCollection());
1252 // setup 'Edit' menu
1253 UndoManager
& undoManager
= UndoManager::instance();
1254 KStdAction::undo(this,
1256 actionCollection());
1257 connect(&undoManager
, SIGNAL(undoAvailable(bool)),
1258 this, SLOT(slotUndoAvailable(bool)));
1259 connect(&undoManager
, SIGNAL(undoTextChanged(const QString
&)),
1260 this, SLOT(slotUndoTextChanged(const QString
&)));
1262 KStdAction::redo(this,
1264 actionCollection());
1265 connect(&undoManager
, SIGNAL(redoAvailable(bool)),
1266 this, SLOT(slotRedoAvailable(bool)));
1267 connect(&undoManager
, SIGNAL(redoTextChanged(const QString
&)),
1268 this, SLOT(slotRedoTextChanged(const QString
&)));
1270 KStdAction::cut(this, SLOT(cut()), actionCollection());
1271 KStdAction::copy(this, SLOT(copy()), actionCollection());
1272 KStdAction::paste(this, SLOT(paste()), actionCollection());
1274 KAction
* selectAll
= new KAction(i18n("Select All"), actionCollection(), "select_all");
1275 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1276 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1278 KAction
* invertSelection
= new KAction(i18n("Invert Selection"), actionCollection(), "invert_selection");
1279 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1280 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1282 // setup 'View' menu
1283 KStdAction::zoomIn(this,
1285 actionCollection());
1287 KStdAction::zoomOut(this,
1289 actionCollection());
1291 KToggleAction
* iconsView
= new KToggleAction(i18n("Icons"), actionCollection(), "icons");
1292 iconsView
->setShortcut(Qt::CTRL
| Qt::Key_1
);
1293 iconsView
->setIcon(KIcon("view_icon"));
1294 connect(iconsView
, SIGNAL(triggered()), this, SLOT(setIconsView()));
1296 KToggleAction
* detailsView
= new KToggleAction(i18n("Details"), actionCollection(), "details");
1297 detailsView
->setShortcut(Qt::CTRL
| Qt::Key_2
);
1298 detailsView
->setIcon(KIcon("view_text"));
1299 connect(detailsView
, SIGNAL(triggered()), this, SLOT(setDetailsView()));
1301 KToggleAction
* previewsView
= new KToggleAction(i18n("Previews"), actionCollection(), "previews");
1302 previewsView
->setShortcut(Qt::CTRL
| Qt::Key_3
);
1303 previewsView
->setIcon(KIcon("gvdirpart"));
1304 connect(previewsView
, SIGNAL(triggered()), this, SLOT(setPreviewsView()));
1306 QActionGroup
* viewModeGroup
= new QActionGroup(this);
1307 viewModeGroup
->addAction(iconsView
);
1308 viewModeGroup
->addAction(detailsView
);
1309 viewModeGroup
->addAction(previewsView
);
1311 KToggleAction
* sortByName
= new KToggleAction(i18n("By Name"), actionCollection(), "by_name");
1312 connect(sortByName
, SIGNAL(triggered()), this, SLOT(sortByName()));
1314 KToggleAction
* sortBySize
= new KToggleAction(i18n("By Size"), actionCollection(), "by_size");
1315 connect(sortBySize
, SIGNAL(triggered()), this, SLOT(sortBySize()));
1317 KToggleAction
* sortByDate
= new KToggleAction(i18n("By Date"), actionCollection(), "by_date");
1318 connect(sortByDate
, SIGNAL(triggered()), this, SLOT(sortByDate()));
1320 QActionGroup
* sortGroup
= new QActionGroup(this);
1321 sortGroup
->addAction(sortByName
);
1322 sortGroup
->addAction(sortBySize
);
1323 sortGroup
->addAction(sortByDate
);
1325 KToggleAction
* sortDescending
= new KToggleAction(i18n("Descending"), actionCollection(), "descending");
1326 connect(sortDescending
, SIGNAL(triggered()), this, SLOT(toggleSortOrder()));
1328 KToggleAction
* showHiddenFiles
= new KToggleAction(i18n("Show Hidden Files"), actionCollection(), "show_hidden_files");
1329 //showHiddenFiles->setShortcut(Qt::ALT | Qt::Key_ KDE4-TODO: what Qt-Key represents '.'?
1330 connect(showHiddenFiles
, SIGNAL(triggered()), this, SLOT(showHiddenFiles()));
1332 KToggleAction
* split
= new KToggleAction(i18n("Split View"), actionCollection(), "split_view");
1333 split
->setShortcut(Qt::Key_F10
);
1334 split
->setIcon(KIcon("view_left_right"));
1335 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1337 KAction
* reload
= new KAction(i18n("Reload"), "F5", actionCollection(), "reload");
1338 reload
->setShortcut(Qt::Key_F5
);
1339 reload
->setIcon(KIcon("reload"));
1340 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1342 KAction
* stop
= new KAction(i18n("Stop"), actionCollection(), "stop");
1343 stop
->setIcon(KIcon("stop"));
1344 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1346 KToggleAction
* showFullLocation
= new KToggleAction(i18n("Show Full Location"), actionCollection(), "editable_location");
1347 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1348 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1350 KToggleAction
* editLocation
= new KToggleAction(i18n("Edit Location"), actionCollection(), "edit_location");
1351 editLocation
->setShortcut(Qt::Key_F6
);
1352 connect(editLocation
, SIGNAL(triggered()), this, SLOT(editLocation()));
1354 KToggleAction
* sidebar
= new KToggleAction(i18n("Sidebar"), actionCollection(), "sidebar");
1355 sidebar
->setShortcut(Qt::Key_F9
);
1356 connect(sidebar
, SIGNAL(triggered()), this, SLOT(toggleSidebar()));
1358 KAction
* adjustViewProps
= new KAction(i18n("Adjust View Properties..."), actionCollection(), "view_properties");
1359 connect(adjustViewProps
, SIGNAL(triggered()), this, SLOT(adjustViewProperties()));
1362 KStdAction::back(this, SLOT(goBack()), actionCollection());
1363 KStdAction::forward(this, SLOT(goForward()), actionCollection());
1364 KStdAction::up(this, SLOT(goUp()), actionCollection());
1365 KStdAction::home(this, SLOT(goHome()), actionCollection());
1367 // setup 'Tools' menu
1368 KAction
* openTerminal
= new KAction(i18n("Open Terminal"), actionCollection(), "open_terminal");
1369 openTerminal
->setShortcut(Qt::Key_F4
);
1370 openTerminal
->setIcon(KIcon("konsole"));
1371 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1373 KAction
* findFile
= new KAction(i18n("Find File..."), actionCollection(), "find_file");
1374 findFile
->setShortcut(Qt::Key_F
);
1375 findFile
->setIcon(KIcon("filefind"));
1376 connect(findFile
, SIGNAL(triggered()), this, SLOT(findFile()));
1378 KToggleAction
* showFilterBar
= new KToggleAction(i18n("Show Filter Bar"), actionCollection(), "show_filter_bar");
1379 showFilterBar
->setShortcut(Qt::Key_Slash
);
1380 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1382 KAction
* compareFiles
= new KAction(i18n("Compare Files"), actionCollection(), "compare_files");
1383 compareFiles
->setIcon(KIcon("kompare"));
1384 compareFiles
->setEnabled(false);
1385 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1387 // setup 'Settings' menu
1388 KStdAction::preferences(this, SLOT(editSettings()), actionCollection());
1391 void DolphinMainWindow::setupCreateNewMenuActions()
1393 // Parts of the following code have been taken
1394 // from the class KNewMenu located in
1395 // libqonq/knewmenu.h of Konqueror.
1396 // Copyright (C) 1998, 1999 David Faure <faure@kde.org>
1397 // 2003 Sven Leiber <s.leiber@web.de>
1399 QStringList files
= actionCollection()->instance()->dirs()->findAllResources("templates");
1400 for (QStringList::Iterator it
= files
.begin() ; it
!= files
.end(); ++it
) {
1401 if ((*it
)[0] != '.' ) {
1402 KSimpleConfig
config(*it
, true);
1403 config
.setDesktopGroup();
1405 // tricky solution to ensure that TextFile is at the beginning
1406 // because this filetype is the most used (according kde-core discussion)
1407 const QString
name(config
.readEntry("Name"));
1410 const QString
path(config
.readPathEntry("Url"));
1411 if (!path
.endsWith("emptydir")) {
1412 if (path
.endsWith("TextFile.txt")) {
1415 else if (!KDesktopFile::isDesktopFile(path
)) {
1418 else if (path
.endsWith("Url.desktop")){
1421 else if (path
.endsWith("Program.desktop")){
1428 const QString
icon(config
.readEntry("Icon"));
1429 const QString
comment(config
.readEntry("Comment"));
1430 const QString
type(config
.readEntry("Type"));
1432 const QString
filePath(*it
);
1435 if (type
== "Link") {
1436 CreateFileEntry entry
;
1439 entry
.comment
= comment
;
1440 entry
.templatePath
= filePath
;
1441 m_createFileTemplates
.insert(key
, entry
);
1446 m_createFileTemplates
.sort();
1448 unplugActionList("create_actions");
1449 KSortableList
<CreateFileEntry
, QString
>::ConstIterator it
= m_createFileTemplates
.begin();
1450 KSortableList
<CreateFileEntry
, QString
>::ConstIterator end
= m_createFileTemplates
.end();
1451 /* KDE4-TODO: don't port this code; use KNewMenu instead
1453 CreateFileEntry entry = (*it).value();
1454 KAction* action = new KAction(entry.name);
1455 action->setIcon(entry.icon);
1456 action->setName((*it).index());
1457 connect(action, SIGNAL(activated()),
1458 this, SLOT(createFile()));
1460 const QChar section = ((*it).index()[0]);
1464 m_fileGroupActions.append(action);
1470 // TODO: not used yet. See documentation of DolphinMainWindow::linkGroupActions()
1471 // and DolphinMainWindow::linkToDeviceActions() in the header file for details.
1472 //m_linkGroupActions.append(action);
1477 // TODO: not used yet. See documentation of DolphinMainWindow::linkGroupActions()
1478 // and DolphinMainWindow::linkToDeviceActions() in the header file for details.
1479 //m_linkToDeviceActions.append(action);
1488 plugActionList("create_file_group", m_fileGroupActions);
1489 //plugActionList("create_link_group", m_linkGroupActions);
1490 //plugActionList("link_to_device", m_linkToDeviceActions);*/
1493 void DolphinMainWindow::updateHistory()
1496 const Q3ValueList
<UrlNavigator::HistoryElem
> list
= m_activeView
->urlHistory(index
);
1498 KAction
* backAction
= actionCollection()->action("go_back");
1499 if (backAction
!= 0) {
1500 backAction
->setEnabled(index
< static_cast<int>(list
.count()) - 1);
1503 KAction
* forwardAction
= actionCollection()->action("go_forward");
1504 if (forwardAction
!= 0) {
1505 forwardAction
->setEnabled(index
> 0);
1509 void DolphinMainWindow::updateEditActions()
1511 const KFileItemList
* list
= m_activeView
->selectedItems();
1512 if ((list
== 0) || (*list
).isEmpty()) {
1513 stateChanged("has_no_selection");
1516 stateChanged("has_selection");
1518 KAction
* renameAction
= actionCollection()->action("rename");
1519 if (renameAction
!= 0) {
1520 renameAction
->setEnabled(list
->count() >= 1);
1523 bool enableMoveToTrash
= true;
1525 KFileItemList::const_iterator it
= list
->begin();
1526 const KFileItemList::const_iterator end
= list
->end();
1528 KFileItem
* item
= *it
;
1529 const KUrl
& url
= item
->url();
1530 // only enable the 'Move to Trash' action for local files
1531 if (!url
.isLocalFile()) {
1532 enableMoveToTrash
= false;
1537 KAction
* moveToTrashAction
= actionCollection()->action("move_to_trash");
1538 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1540 updatePasteAction();
1543 void DolphinMainWindow::updateViewActions()
1545 KAction
* zoomInAction
= actionCollection()->action(KStdAction::stdName(KStdAction::ZoomIn
));
1546 if (zoomInAction
!= 0) {
1547 zoomInAction
->setEnabled(m_activeView
->isZoomInPossible());
1550 KAction
* zoomOutAction
= actionCollection()->action(KStdAction::stdName(KStdAction::ZoomOut
));
1551 if (zoomOutAction
!= 0) {
1552 zoomOutAction
->setEnabled(m_activeView
->isZoomOutPossible());
1555 KAction
* action
= 0;
1556 switch (m_activeView
->mode()) {
1557 case DolphinView::IconsView
:
1558 action
= actionCollection()->action("icons");
1560 case DolphinView::DetailsView
:
1561 action
= actionCollection()->action("details");
1563 case DolphinView::PreviewsView
:
1564 action
= actionCollection()->action("previews");
1571 KToggleAction
* toggleAction
= static_cast<KToggleAction
*>(action
);
1572 toggleAction
->setChecked(true);
1575 slotSortingChanged(m_activeView
->sorting());
1576 slotSortOrderChanged(m_activeView
->sortOrder());
1578 KToggleAction
* showFilterBarAction
=
1579 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
1580 showFilterBarAction
->setChecked(m_activeView
->isFilterBarVisible());
1582 KToggleAction
* showHiddenFilesAction
=
1583 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
1584 showHiddenFilesAction
->setChecked(m_activeView
->isShowHiddenFilesEnabled());
1586 KToggleAction
* splitAction
= static_cast<KToggleAction
*>(actionCollection()->action("split_view"));
1587 splitAction
->setChecked(m_view
[SecondaryIdx
] != 0);
1589 KToggleAction
* sidebarAction
= static_cast<KToggleAction
*>(actionCollection()->action("sidebar"));
1590 sidebarAction
->setChecked(m_sidebar
!= 0);
1593 void DolphinMainWindow::updateGoActions()
1595 KAction
* goUpAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Up
));
1596 const KUrl
& currentUrl
= m_activeView
->url();
1597 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1600 void DolphinMainWindow::updateViewProperties(const KUrl::List
& urls
)
1602 if (urls
.isEmpty()) {
1606 // Updating the view properties might take up to several seconds
1607 // when dragging several thousand Urls. Writing a KIO slave for this
1608 // use case is not worth the effort, but at least the main widget
1609 // must be disabled and a progress should be shown.
1610 ProgressIndicator
progressIndicator(this,
1611 i18n("Updating view properties..."),
1615 KUrl::List::ConstIterator end
= urls
.end();
1616 for(KUrl::List::ConstIterator it
= urls
.begin(); it
!= end
; ++it
) {
1617 progressIndicator
.execOperation();
1619 ViewProperties
props(*it
);
1624 void DolphinMainWindow::copyUrls(const KUrl::List
& source
, const KUrl
& dest
)
1626 KIO::Job
* job
= KIO::copy(source
, dest
);
1627 addPendingUndoJob(job
, DolphinCommand::Copy
, source
, dest
);
1630 void DolphinMainWindow::moveUrls(const KUrl::List
& source
, const KUrl
& dest
)
1632 KIO::Job
* job
= KIO::move(source
, dest
);
1633 addPendingUndoJob(job
, DolphinCommand::Move
, source
, dest
);
1636 void DolphinMainWindow::addPendingUndoJob(KIO::Job
* job
,
1637 DolphinCommand::Type commandType
,
1638 const KUrl::List
& source
,
1641 connect(job
, SIGNAL(result(KJob
*)),
1642 this, SLOT(addUndoOperation(KJob
*)));
1645 undoInfo
.id
= job
->progressId();
1646 undoInfo
.command
= DolphinCommand(commandType
, source
, dest
);
1647 m_pendingUndoJobs
.append(undoInfo
);
1650 void DolphinMainWindow::clearStatusBar()
1652 m_activeView
->statusBar()->clear();
1655 void DolphinMainWindow::openSidebar()
1657 if (m_sidebar
!= 0) {
1658 // the sidebar is already open
1662 m_sidebar
= new Sidebar(this, m_splitter
);
1665 connect(m_sidebar
, SIGNAL(urlChanged(const KUrl
&)),
1666 this, SLOT(slotUrlChangeRequest(const KUrl
&)));
1667 m_splitter
->setCollapsible(m_sidebar
, false);
1668 m_splitter
->setResizeMode(m_sidebar
, QSplitter::KeepSize
);
1669 m_splitter
->moveToFirst(m_sidebar
);
1671 SidebarSettings
* settings
= DolphinSettings::instance().sidebarSettings();
1672 settings
->setVisible(true);
1675 #include "dolphinmainwindow.moc"