]>
cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2006 by Stefan Monov <logixoul@gmail.com> *
4 * Copyright (C) 2006 by Cvetoslav Ludmiloff <ludmiloff@gmail.com> *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
22 #include "dolphinmainwindow.h"
26 #include <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>
40 #include <kstandardaction.h>
42 #include <kio/renamedialog.h>
43 #include <kinputdialog.h>
45 #include <kdesktopfile.h>
46 #include <kstandarddirs.h>
47 #include <kprotocolinfo.h>
48 #include <kmessagebox.h>
50 #include <kstandarddirs.h>
53 #include <konqmimedata.h>
55 #include <qclipboard.h>
56 #include <q3dragobject.h>
58 #include <Q3ValueList>
59 #include <QCloseEvent>
61 #include <QDockWidget>
63 #include "urlnavigator.h"
64 #include "viewpropertiesdialog.h"
65 #include "viewproperties.h"
66 #include "dolphinsettings.h"
67 #include "dolphinsettingsdialog.h"
68 #include "dolphinstatusbar.h"
69 #include "dolphinapplication.h"
70 #include "undomanager.h"
71 #include "progressindicator.h"
72 #include "dolphinsettings.h"
73 #include "bookmarkssidebarpage.h"
74 #include "infosidebarpage.h"
75 #include "generalsettings.h"
76 #include "dolphinapplication.h"
79 DolphinMainWindow::DolphinMainWindow() :
84 setObjectName("Dolphin");
85 m_view
[PrimaryIdx
] = 0;
86 m_view
[SecondaryIdx
] = 0;
89 DolphinMainWindow::~DolphinMainWindow()
91 qDeleteAll(m_fileGroupActions
);
92 m_fileGroupActions
.clear();
94 DolphinApplication::app()->removeMainWindow(this);
97 void DolphinMainWindow::setActiveView(DolphinView
* view
)
99 assert((view
== m_view
[PrimaryIdx
]) || (view
== m_view
[SecondaryIdx
]));
100 if (m_activeView
== view
) {
111 setCaption(m_activeView
->url().fileName());
113 emit
activeViewChanged();
116 void DolphinMainWindow::dropUrls(const KUrl::List
& urls
,
117 const KUrl
& destination
)
119 m_dropDestination
= destination
;
120 m_droppedUrls
= urls
;
123 const ButtonState keyboardState = KApplication::keyboardMouseState();
124 const bool shiftPressed = (keyboardState & ShiftButton) > 0;
125 const bool controlPressed = (keyboardState & ControlButton) > 0;
129 if (shiftPressed && controlPressed) {
130 // shortcut for 'Linke Here' is used
133 else if (controlPressed) {
134 // shortcut for 'Copy Here' is used
137 else if (shiftPressed) {
138 // shortcut for 'Move Here' is used
142 // no shortcut is used, hence open a popup menu
145 QAction
* moveAction
= popup
.addAction(SmallIcon("goto"), i18n("&Move Here"));
146 connect(moveAction
, SIGNAL(triggered()), this, SLOT(moveDroppedItems()));
148 QAction
* copyAction
= popup
.addAction(SmallIcon("editcopy"), i18n( "&Copy Here" ));
149 connect(copyAction
, SIGNAL(triggered()), this, SLOT(copyDroppedItems()));
151 QAction
* linkAction
= popup
.addAction(i18n("&Link Here"));
152 connect(linkAction
, SIGNAL(triggered()), this, SLOT(linkDroppedItems()));
154 QAction
* cancelAction
= popup
.addAction(SmallIcon("stop"), i18n("Cancel"));
155 popup
.insertSeparator(cancelAction
);
157 popup
.exec(QCursor::pos());
160 m_droppedUrls
.clear();
163 void DolphinMainWindow::refreshViews()
165 const bool split
= DolphinSettings::instance().generalSettings()->splitView();
166 const bool isPrimaryViewActive
= (m_activeView
== m_view
[PrimaryIdx
]);
168 for (int i
= PrimaryIdx
; i
<= SecondaryIdx
; ++i
) {
169 if (m_view
[i
] != 0) {
170 url
= m_view
[i
]->url();
172 // delete view instance...
174 m_view
[i
]->deleteLater();
178 if (split
|| (i
== PrimaryIdx
)) {
179 // ... and recreate it
180 ViewProperties
props(url
);
181 m_view
[i
] = new DolphinView(this,
185 props
.showHiddenFiles());
186 connectViewSignals(i
);
191 m_activeView
= isPrimaryViewActive
? m_view
[PrimaryIdx
] : m_view
[SecondaryIdx
];
192 assert(m_activeView
!= 0);
195 emit
activeViewChanged();
198 void DolphinMainWindow::slotViewModeChanged()
203 void DolphinMainWindow::slotShowHiddenFilesChanged()
205 KToggleAction
* showHiddenFilesAction
=
206 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
207 showHiddenFilesAction
->setChecked(m_activeView
->showHiddenFiles());
210 void DolphinMainWindow::slotSortingChanged(DolphinView::Sorting sorting
)
214 case DolphinView::SortByName
:
215 action
= actionCollection()->action("by_name");
217 case DolphinView::SortBySize
:
218 action
= actionCollection()->action("by_size");
220 case DolphinView::SortByDate
:
221 action
= actionCollection()->action("by_date");
228 KToggleAction
* toggleAction
= static_cast<KToggleAction
*>(action
);
229 toggleAction
->setChecked(true);
233 void DolphinMainWindow::slotSortOrderChanged(Qt::SortOrder order
)
235 KToggleAction
* descending
= static_cast<KToggleAction
*>(actionCollection()->action("descending"));
236 const bool sortDescending
= (order
== Qt::Descending
);
237 descending
->setChecked(sortDescending
);
240 void DolphinMainWindow::slotSelectionChanged()
244 assert(m_view
[PrimaryIdx
] != 0);
245 int selectedUrlsCount
= m_view
[PrimaryIdx
]->selectedUrls().count();
246 if (m_view
[SecondaryIdx
] != 0) {
247 selectedUrlsCount
+= m_view
[SecondaryIdx
]->selectedUrls().count();
250 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
251 compareFilesAction
->setEnabled(selectedUrlsCount
== 2);
253 m_activeView
->updateStatusBar();
255 emit
selectionChanged();
258 void DolphinMainWindow::slotHistoryChanged()
263 void DolphinMainWindow::slotUrlChanged(const KUrl
& url
)
267 setCaption(url
.fileName());
270 void DolphinMainWindow::updateFilterBarAction(bool show
)
272 KToggleAction
* showFilterBarAction
=
273 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
274 showFilterBarAction
->setChecked(show
);
277 void DolphinMainWindow::redo()
279 UndoManager::instance().redo(this);
282 void DolphinMainWindow::undo()
284 UndoManager::instance().undo(this);
287 void DolphinMainWindow::openNewMainWindow()
289 DolphinApplication::app()->createMainWindow()->show();
292 void DolphinMainWindow::moveDroppedItems()
294 moveUrls(m_droppedUrls
, m_dropDestination
);
297 void DolphinMainWindow::copyDroppedItems()
299 copyUrls(m_droppedUrls
, m_dropDestination
);
302 void DolphinMainWindow::linkDroppedItems()
304 KIO::Job
* job
= KIO::link(m_droppedUrls
, m_dropDestination
);
305 addPendingUndoJob(job
, DolphinCommand::Link
, m_droppedUrls
, m_dropDestination
);
308 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
310 DolphinSettings
& settings
= DolphinSettings::instance();
311 GeneralSettings
* generalSettings
= settings
.generalSettings();
312 generalSettings
->setFirstRun(false);
316 // TODO: I assume there will be a generic way in KDE 4 to store the docks
317 // of the main window. In the meantime they are stored manually:
318 QString filename
= KStandardDirs::locateLocal("data", KGlobal::instance()->instanceName());
319 filename
.append("/panels_layout");
320 QFile
file(filename
);
321 if (file
.open(QIODevice::WriteOnly
)) {
322 QByteArray data
= saveState();
327 KMainWindow::closeEvent(event
);
330 void DolphinMainWindow::saveProperties(KConfig
* config
)
332 config
->setGroup("Primary view");
333 config
->writeEntry("Url", m_view
[PrimaryIdx
]->url().url());
334 config
->writeEntry("Editable Url", m_view
[PrimaryIdx
]->isUrlEditable());
335 if (m_view
[SecondaryIdx
] != 0) {
336 config
->setGroup("Secondary view");
337 config
->writeEntry("Url", m_view
[SecondaryIdx
]->url().url());
338 config
->writeEntry("Editable Url", m_view
[SecondaryIdx
]->isUrlEditable());
342 void DolphinMainWindow::readProperties(KConfig
* config
)
344 config
->setGroup("Primary view");
345 m_view
[PrimaryIdx
]->setUrl(config
->readEntry("Url"));
346 m_view
[PrimaryIdx
]->setUrlEditable(config
->readEntry("Editable Url", false));
347 if (config
->hasGroup("Secondary view")) {
348 config
->setGroup("Secondary view");
349 if (m_view
[SecondaryIdx
] == 0) {
352 m_view
[SecondaryIdx
]->setUrl(config
->readEntry("Url"));
353 m_view
[SecondaryIdx
]->setUrlEditable(config
->readEntry("Editable Url", false));
355 else if (m_view
[SecondaryIdx
] != 0) {
360 void DolphinMainWindow::createFolder()
362 // Parts of the following code have been taken
363 // from the class KonqPopupMenu located in
364 // libqonq/konq_popupmenu.h of Konqueror.
365 // (Copyright (C) 2000 David Faure <faure@kde.org>,
366 // Copyright (C) 2001 Holger Freyther <freyther@yahoo.com>)
370 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
371 const KUrl
baseUrl(m_activeView
->url());
373 QString
name(i18n("New Folder"));
374 baseUrl
.path(KUrl::AddTrailingSlash
);
377 if (baseUrl
.isLocalFile() && QFileInfo(baseUrl
.path(KUrl::AddTrailingSlash
) + name
).exists()) {
378 name
= KIO::RenameDialog::suggestName(baseUrl
, i18n("New Folder"));
382 name
= KInputDialog::getText(i18n("New Folder"),
383 i18n("Enter folder name:" ),
389 // the user has pressed 'Cancel'
393 assert(!name
.isEmpty());
396 if ((name
[0] == '/') || (name
[0] == '~')) {
397 url
.setPath(KShell::tildeExpand(name
));
400 name
= KIO::encodeFileName(name
);
404 ok
= KIO::NetAccess::mkdir(url
, this);
406 // TODO: provide message type hint
408 statusBar
->setMessage(i18n("Created folder %1.",url
.path()),
409 DolphinStatusBar::OperationCompleted
);
411 DolphinCommand
command(DolphinCommand::CreateFolder
, KUrl::List(), url
);
412 UndoManager::instance().addCommand(command
);
415 // Creating of the folder has been failed. Check whether the creating
416 // has been failed because a folder with the same name exists...
417 if (KIO::NetAccess::exists(url
, true, this)) {
418 statusBar
->setMessage(i18n("A folder named %1 already exists.",url
.path()),
419 DolphinStatusBar::Error
);
422 statusBar
->setMessage(i18n("Creating of folder %1 failed.",url
.path()),
423 DolphinStatusBar::Error
);
429 void DolphinMainWindow::createFile()
431 // Parts of the following code have been taken
432 // from the class KonqPopupMenu located in
433 // libqonq/konq_popupmenu.h of Konqueror.
434 // (Copyright (C) 2000 David Faure <faure@kde.org>,
435 // Copyright (C) 2001 Holger Freyther <freyther@yahoo.com>)
439 // TODO: const Entry& entry = m_createFileTemplates[QString(sender->name())];
440 // should be enough. Anyway: the implementation of [] does a linear search internally too.
441 KSortableList
<CreateFileEntry
, QString
>::ConstIterator it
= m_createFileTemplates
.begin();
442 KSortableList
<CreateFileEntry
, QString
>::ConstIterator end
= m_createFileTemplates
.end();
444 const QString
senderName(sender()->objectName());
446 CreateFileEntry entry
;
447 while (!found
&& (it
!= end
)) {
448 if ((*it
).key() == senderName
) {
449 entry
= (*it
).value();
457 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
458 if (!found
|| !QFile::exists(entry
.templatePath
)) {
459 statusBar
->setMessage(i18n("Could not create file."), DolphinStatusBar::Error
);
463 // Get the source path of the template which should be copied.
464 // The source path is part of the Url entry of the desktop file.
465 const int pos
= entry
.templatePath
.lastIndexOf('/');
466 QString
sourcePath(entry
.templatePath
.left(pos
+ 1));
467 sourcePath
+= KDesktopFile(entry
.templatePath
, true).readPathEntry("Url");
469 QString
name(i18n(entry
.name
.toAscii()));
470 // Most entry names end with "..." (e. g. "HTML File..."), which is ok for
471 // menus but no good choice for a new file name -> remove the dots...
472 name
.replace("...", QString::null
);
474 // add the file extension to the name
475 name
.append(sourcePath
.right(sourcePath
.length() - sourcePath
.lastIndexOf('.')));
477 // Check whether a file with the current name already exists. If yes suggest automatically
478 // a unique file name (e. g. "HTML File" will be replaced by "HTML File_1").
479 const KUrl
viewUrl(m_activeView
->url());
480 const bool fileExists
= viewUrl
.isLocalFile() &&
481 QFileInfo(viewUrl
.path(KUrl::AddTrailingSlash
) + KIO::encodeFileName(name
)).exists();
483 name
= KIO::RenameDialog::suggestName(viewUrl
, name
);
486 // let the user change the suggested file name
488 name
= KInputDialog::getText(entry
.name
,
494 // the user has pressed 'Cancel'
498 // before copying the template to the destination path check whether a file
499 // with the given name already exists
500 const QString
destPath(viewUrl
.pathOrUrl() + "/" + KIO::encodeFileName(name
));
501 const KUrl
destUrl(destPath
);
502 if (KIO::NetAccess::exists(destUrl
, false, this)) {
503 statusBar
->setMessage(i18n("A file named %1 already exists.",name
),
504 DolphinStatusBar::Error
);
508 // copy the template to the destination path
509 const KUrl
sourceUrl(sourcePath
);
510 KIO::CopyJob
* job
= KIO::copyAs(sourceUrl
, destUrl
);
511 job
->setDefaultPermissions(true);
512 if (KIO::NetAccess::synchronousRun(job
, this)) {
513 statusBar
->setMessage(i18n("Created file %1.",name
),
514 DolphinStatusBar::OperationCompleted
);
517 list
.append(sourceUrl
);
518 DolphinCommand
command(DolphinCommand::CreateFile
, list
, destUrl
);
519 UndoManager::instance().addCommand(command
);
523 statusBar
->setMessage(i18n("Creating of file %1 failed.",name
),
524 DolphinStatusBar::Error
);
528 void DolphinMainWindow::rename()
531 m_activeView
->renameSelectedItems();
534 void DolphinMainWindow::moveToTrash()
537 KUrl::List selectedUrls
= m_activeView
->selectedUrls();
538 KIO::Job
* job
= KIO::trash(selectedUrls
);
539 addPendingUndoJob(job
, DolphinCommand::Trash
, selectedUrls
, m_activeView
->url());
542 void DolphinMainWindow::deleteItems()
546 KUrl::List list
= m_activeView
->selectedUrls();
547 const uint itemCount
= list
.count();
548 assert(itemCount
>= 1);
552 text
= i18n("Do you really want to delete the %1 selected items?",itemCount
);
555 const KUrl
& url
= list
.first();
556 text
= i18n("Do you really want to delete '%1'?",url
.fileName());
559 const bool del
= KMessageBox::warningContinueCancel(this,
562 KGuiItem(i18n("Delete"), KIcon("editdelete"))
563 ) == KMessageBox::Continue
;
565 KIO::Job
* job
= KIO::del(list
);
566 connect(job
, SIGNAL(result(KJob
*)),
567 this, SLOT(slotHandleJobError(KJob
*)));
568 connect(job
, SIGNAL(result(KJob
*)),
569 this, SLOT(slotDeleteFileFinished(KJob
*)));
573 void DolphinMainWindow::properties()
575 const KFileItemList list
= m_activeView
->selectedItems();
576 new KPropertiesDialog(list
, this);
579 void DolphinMainWindow::quit()
584 void DolphinMainWindow::slotHandleJobError(KJob
* job
)
586 if (job
->error() != 0) {
587 m_activeView
->statusBar()->setMessage(job
->errorString(),
588 DolphinStatusBar::Error
);
592 void DolphinMainWindow::slotDeleteFileFinished(KJob
* job
)
594 if (job
->error() == 0) {
595 m_activeView
->statusBar()->setMessage(i18n("Delete operation completed."),
596 DolphinStatusBar::OperationCompleted
);
598 // TODO: In opposite to the 'Move to Trash' operation in the class KFileIconView
599 // no rearranging of the item position is done when a file has been deleted.
600 // This is bypassed by reloading the view, but it might be worth to investigate
601 // deeper for the root of this issue.
602 m_activeView
->reload();
606 void DolphinMainWindow::slotUndoAvailable(bool available
)
608 QAction
* undoAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::Undo
));
609 if (undoAction
!= 0) {
610 undoAction
->setEnabled(available
);
614 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
616 QAction
* undoAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::Undo
));
617 if (undoAction
!= 0) {
618 undoAction
->setText(text
);
622 void DolphinMainWindow::slotRedoAvailable(bool available
)
624 QAction
* redoAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::Redo
));
625 if (redoAction
!= 0) {
626 redoAction
->setEnabled(available
);
630 void DolphinMainWindow::slotRedoTextChanged(const QString
& text
)
632 QAction
* redoAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::Redo
));
633 if (redoAction
!= 0) {
634 redoAction
->setText(text
);
638 void DolphinMainWindow::cut()
640 QMimeData
* mimeData
= new QMimeData();
641 const KUrl::List kdeUrls
= m_activeView
->selectedUrls();
642 const KUrl::List mostLocalUrls
;
643 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, true);
644 QApplication::clipboard()->setMimeData(mimeData
);
647 void DolphinMainWindow::copy()
649 QMimeData
* mimeData
= new QMimeData();
650 const KUrl::List kdeUrls
= m_activeView
->selectedUrls();
651 const KUrl::List mostLocalUrls
;
652 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, false);
654 QApplication::clipboard()->setMimeData(mimeData
);
657 void DolphinMainWindow::paste()
659 QClipboard
* clipboard
= QApplication::clipboard();
660 const QMimeData
* mimeData
= clipboard
->mimeData();
664 const KUrl::List sourceUrls
= KUrl::List::fromMimeData(mimeData
);
666 // per default the pasting is done into the current Url of the view
667 KUrl
destUrl(m_activeView
->url());
669 // check whether the pasting should be done into a selected directory
670 KUrl::List selectedUrls
= m_activeView
->selectedUrls();
671 if (selectedUrls
.count() == 1) {
672 const KFileItem
fileItem(S_IFDIR
,
674 selectedUrls
.first(),
676 if (fileItem
.isDir()) {
677 // only one item is selected which is a directory, hence paste
678 // into this directory
679 destUrl
= selectedUrls
.first();
683 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
684 moveUrls(sourceUrls
, destUrl
);
688 copyUrls(sourceUrls
, destUrl
);
692 void DolphinMainWindow::updatePasteAction()
694 QAction
* pasteAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::Paste
));
695 if (pasteAction
== 0) {
699 QString
text(i18n("Paste"));
700 QClipboard
* clipboard
= QApplication::clipboard();
701 const QMimeData
* mimeData
= clipboard
->mimeData();
703 KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
704 if (!urls
.isEmpty()) {
705 pasteAction
->setEnabled(true);
707 const int count
= urls
.count();
709 pasteAction
->setText(i18n("Paste 1 File"));
712 pasteAction
->setText(i18n("Paste %1 Files").arg(count
));
716 pasteAction
->setEnabled(false);
717 pasteAction
->setText(i18n("Paste"));
720 if (pasteAction
->isEnabled()) {
721 KUrl::List urls
= m_activeView
->selectedUrls();
722 const uint count
= urls
.count();
724 // pasting should not be allowed when more than one file
726 pasteAction
->setEnabled(false);
728 else if (count
== 1) {
729 // Only one file is selected. Pasting is only allowed if this
730 // file is a directory.
731 // TODO: this doesn't work with remote protocols; instead we need a
732 // m_activeView->selectedFileItems() to get the real KFileItems
733 const KFileItem
fileItem(S_IFDIR
,
737 pasteAction
->setEnabled(fileItem
.isDir());
742 void DolphinMainWindow::selectAll()
745 m_activeView
->selectAll();
748 void DolphinMainWindow::invertSelection()
751 m_activeView
->invertSelection();
753 void DolphinMainWindow::setIconsView()
755 m_activeView
->setMode(DolphinView::IconsView
);
758 void DolphinMainWindow::setDetailsView()
760 m_activeView
->setMode(DolphinView::DetailsView
);
763 void DolphinMainWindow::sortByName()
765 m_activeView
->setSorting(DolphinView::SortByName
);
768 void DolphinMainWindow::sortBySize()
770 m_activeView
->setSorting(DolphinView::SortBySize
);
773 void DolphinMainWindow::sortByDate()
775 m_activeView
->setSorting(DolphinView::SortByDate
);
778 void DolphinMainWindow::toggleSortOrder()
780 const Qt::SortOrder order
= (m_activeView
->sortOrder() == Qt::Ascending
) ?
783 m_activeView
->setSortOrder(order
);
786 void DolphinMainWindow::toggleSplitView()
788 if (m_view
[SecondaryIdx
] == 0) {
789 const int newWidth
= (m_view
[PrimaryIdx
]->width() - m_splitter
->handleWidth()) / 2;
790 // create a secondary view
791 m_view
[SecondaryIdx
] = new DolphinView(this,
793 m_view
[PrimaryIdx
]->url(),
794 m_view
[PrimaryIdx
]->mode(),
795 m_view
[PrimaryIdx
]->showHiddenFiles());
796 connectViewSignals(SecondaryIdx
);
797 m_splitter
->addWidget(m_view
[SecondaryIdx
]);
798 m_splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
799 m_view
[SecondaryIdx
]->show();
802 // remove secondary view
803 if (m_activeView
== m_view
[PrimaryIdx
]) {
804 m_view
[SecondaryIdx
]->close();
805 m_view
[SecondaryIdx
]->deleteLater();
806 m_view
[SecondaryIdx
] = 0;
807 setActiveView(m_view
[PrimaryIdx
]);
810 // The secondary view is active, hence from the users point of view
811 // the content of the secondary view should be moved to the primary view.
812 // From an implementation point of view it is more efficient to close
813 // the primary view and exchange the internal pointers afterwards.
814 m_view
[PrimaryIdx
]->close();
815 delete m_view
[PrimaryIdx
];
816 m_view
[PrimaryIdx
] = m_view
[SecondaryIdx
];
817 m_view
[SecondaryIdx
] = 0;
818 setActiveView(m_view
[PrimaryIdx
]);
823 void DolphinMainWindow::reloadView()
826 m_activeView
->reload();
829 void DolphinMainWindow::stopLoading()
833 void DolphinMainWindow::togglePreview()
837 const KToggleAction
* showPreviewAction
=
838 static_cast<KToggleAction
*>(actionCollection()->action("show_preview"));
839 const bool show
= showPreviewAction
->isChecked();
840 m_activeView
->setShowPreview(show
);
843 void DolphinMainWindow::toggleShowHiddenFiles()
847 const KToggleAction
* showHiddenFilesAction
=
848 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
849 const bool show
= showHiddenFilesAction
->isChecked();
850 m_activeView
->setShowHiddenFiles(show
);
853 void DolphinMainWindow::showFilterBar()
855 const KToggleAction
* showFilterBarAction
=
856 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
857 const bool show
= showFilterBarAction
->isChecked();
858 m_activeView
->slotShowFilterBar(show
);
861 void DolphinMainWindow::zoomIn()
863 m_activeView
->zoomIn();
867 void DolphinMainWindow::zoomOut()
869 m_activeView
->zoomOut();
873 void DolphinMainWindow::toggleEditLocation()
877 KToggleAction
* action
= static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
879 bool editOrBrowse
= action
->isChecked();
880 // action->setChecked(action->setChecked);
881 m_activeView
->setUrlEditable(editOrBrowse
);
884 void DolphinMainWindow::editLocation()
886 KToggleAction
* action
= static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
887 action
->setChecked(true);
888 m_activeView
->setUrlEditable(true);
891 void DolphinMainWindow::adjustViewProperties()
894 ViewPropertiesDialog
dlg(m_activeView
);
898 void DolphinMainWindow::goBack()
901 m_activeView
->goBack();
904 void DolphinMainWindow::goForward()
907 m_activeView
->goForward();
910 void DolphinMainWindow::goUp()
913 m_activeView
->goUp();
916 void DolphinMainWindow::goHome()
919 m_activeView
->goHome();
922 void DolphinMainWindow::openTerminal()
924 QString
command("konsole --workdir \"");
925 command
.append(m_activeView
->url().path());
926 command
.append('\"');
928 KRun::runCommand(command
, "Konsole", "konsole");
931 void DolphinMainWindow::findFile()
933 KRun::run("kfind", m_activeView
->url());
936 void DolphinMainWindow::compareFiles()
938 // The method is only invoked if exactly 2 files have
939 // been selected. The selected files may be:
940 // - both in the primary view
941 // - both in the secondary view
942 // - one in the primary view and the other in the secondary
944 assert(m_view
[PrimaryIdx
] != 0);
948 KUrl::List urls
= m_view
[PrimaryIdx
]->selectedUrls();
950 switch (urls
.count()) {
952 assert(m_view
[SecondaryIdx
] != 0);
953 urls
= m_view
[SecondaryIdx
]->selectedUrls();
954 assert(urls
.count() == 2);
962 assert(m_view
[SecondaryIdx
] != 0);
963 urls
= m_view
[SecondaryIdx
]->selectedUrls();
964 assert(urls
.count() == 1);
976 // may not happen: compareFiles may only get invoked if 2
977 // files are selected
982 QString
command("kompare -c \"");
983 command
.append(urlA
.pathOrUrl());
984 command
.append("\" \"");
985 command
.append(urlB
.pathOrUrl());
986 command
.append('\"');
987 KRun::runCommand(command
, "Kompare", "kompare");
991 void DolphinMainWindow::editSettings()
993 // TODO: make a static method for opening the settings dialog
994 DolphinSettingsDialog
dlg(this);
998 void DolphinMainWindow::addUndoOperation(KJob
* job
)
1000 if (job
->error() != 0) {
1001 slotHandleJobError(job
);
1004 const int id
= job
->progressId();
1006 // set iterator to the executed command with the current id...
1007 Q3ValueList
<UndoInfo
>::Iterator it
= m_pendingUndoJobs
.begin();
1008 const Q3ValueList
<UndoInfo
>::Iterator end
= m_pendingUndoJobs
.end();
1010 while (!found
&& (it
!= end
)) {
1011 if ((*it
).id
== id
) {
1020 DolphinCommand command
= (*it
).command
;
1021 if (command
.type() == DolphinCommand::Trash
) {
1022 // To be able to perform an undo for the 'Move to Trash' operation
1023 // all source Urls must be updated with the trash Url. E. g. when moving
1024 // a file "test.txt" and a second file "test.txt" to the trash,
1025 // then the filenames in the trash are "0-test.txt" and "1-test.txt".
1026 QMap
<QString
, QString
> metaData
;
1027 KIO::Job
*kiojob
= qobject_cast
<KIO::Job
*>( job
);
1030 metaData
= kiojob
->metaData();
1032 KUrl::List newSourceUrls
;
1034 KUrl::List sourceUrls
= command
.source();
1035 KUrl::List::Iterator sourceIt
= sourceUrls
.begin();
1036 const KUrl::List::Iterator sourceEnd
= sourceUrls
.end();
1038 while (sourceIt
!= sourceEnd
) {
1039 QMap
<QString
, QString
>::ConstIterator metaIt
= metaData
.find("trashUrl-" + (*sourceIt
).path());
1040 if (metaIt
!= metaData
.end()) {
1041 newSourceUrls
.append(KUrl(metaIt
.value()));
1045 command
.setSource(newSourceUrls
);
1048 UndoManager::instance().addCommand(command
);
1049 m_pendingUndoJobs
.erase(it
);
1051 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
1052 switch (command
.type()) {
1053 case DolphinCommand::Copy
:
1054 statusBar
->setMessage(i18n("Copy operation completed."),
1055 DolphinStatusBar::OperationCompleted
);
1057 case DolphinCommand::Move
:
1058 statusBar
->setMessage(i18n("Move operation completed."),
1059 DolphinStatusBar::OperationCompleted
);
1061 case DolphinCommand::Trash
:
1062 statusBar
->setMessage(i18n("Move to trash operation completed."),
1063 DolphinStatusBar::OperationCompleted
);
1072 void DolphinMainWindow::init()
1074 // Check whether Dolphin runs the first time. If yes then
1075 // a proper default window size is given at the end of DolphinMainWindow::init().
1076 GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
1077 const bool firstRun
= generalSettings
->firstRun();
1079 setAcceptDrops(true);
1081 m_splitter
= new QSplitter(this);
1083 DolphinSettings
& settings
= DolphinSettings::instance();
1085 KBookmarkManager
* manager
= settings
.bookmarkManager();
1086 assert(manager
!= 0);
1087 KBookmarkGroup root
= manager
->root();
1088 if (root
.first().isNull()) {
1089 root
.addBookmark(manager
, i18n("Home"), settings
.generalSettings()->homeUrl(), "folder_home");
1090 root
.addBookmark(manager
, i18n("Storage Media"), KUrl("media:/"), "blockdevice");
1091 root
.addBookmark(manager
, i18n("Network"), KUrl("remote:/"), "network_local");
1092 root
.addBookmark(manager
, i18n("Root"), KUrl("/"), "folder_red");
1093 root
.addBookmark(manager
, i18n("Trash"), KUrl("trash:/"), "trashcan_full");
1098 const KUrl
& homeUrl
= root
.first().url();
1099 setCaption(homeUrl
.fileName());
1100 ViewProperties
props(homeUrl
);
1101 m_view
[PrimaryIdx
] = new DolphinView(this,
1105 props
.showHiddenFiles());
1106 connectViewSignals(PrimaryIdx
);
1107 m_view
[PrimaryIdx
]->show();
1109 m_activeView
= m_view
[PrimaryIdx
];
1111 setCentralWidget(m_splitter
);
1114 setupGUI(Keys
|Save
|Create
|ToolBar
);
1117 stateChanged("new_file");
1118 setAutoSaveSettings();
1120 QClipboard
* clipboard
= QApplication::clipboard();
1121 connect(clipboard
, SIGNAL(dataChanged()),
1122 this, SLOT(updatePasteAction()));
1123 updatePasteAction();
1126 setupCreateNewMenuActions();
1131 // assure a proper default size if Dolphin runs the first time
1136 void DolphinMainWindow::loadSettings()
1138 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
1140 KToggleAction
* splitAction
= static_cast<KToggleAction
*>(actionCollection()->action("split_view"));
1141 if (settings
->splitView()) {
1142 splitAction
->setChecked(true);
1146 updateViewActions();
1148 // TODO: I assume there will be a generic way in KDE 4 to restore the docks
1149 // of the main window. In the meantime they are restored manually (see also
1150 // DolphinMainWindow::closeEvent() for more details):
1151 QString filename
= KStandardDirs::locateLocal("data", KGlobal::instance()->instanceName());
1152 filename
.append("/panels_layout");
1153 QFile
file(filename
);
1154 if (file
.open(QIODevice::ReadOnly
)) {
1155 QByteArray data
= file
.readAll();
1161 void DolphinMainWindow::setupActions()
1163 // setup 'File' menu
1164 QAction
*action
= actionCollection()->addAction("new_window");
1165 action
->setIcon(KIcon("window_new"));
1166 action
->setText(i18n("New &Window"));
1167 connect(action
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1169 QAction
* createFolder
= actionCollection()->addAction("create_folder");
1170 createFolder
->setText(i18n("Folder..."));
1171 createFolder
->setIcon(KIcon("folder"));
1172 createFolder
->setShortcut(Qt::Key_N
);
1173 connect(createFolder
, SIGNAL(triggered()), this, SLOT(createFolder()));
1175 QAction
* rename
= actionCollection()->addAction("rename");
1176 rename
->setText(i18n("Rename"));
1177 rename
->setShortcut(Qt::Key_F2
);
1178 connect(rename
, SIGNAL(triggered()), this, SLOT(rename()));
1180 QAction
* moveToTrash
= actionCollection()->addAction("move_to_trash");
1181 moveToTrash
->setText(i18n("Move to Trash"));
1182 moveToTrash
->setIcon(KIcon("edittrash"));
1183 moveToTrash
->setShortcut(QKeySequence::Delete
);
1184 connect(moveToTrash
, SIGNAL(triggered()), this, SLOT(moveToTrash()));
1186 QAction
* deleteAction
= actionCollection()->addAction("delete");
1187 deleteAction
->setText(i18n("Delete"));
1188 deleteAction
->setShortcut(Qt::ALT
| Qt::Key_Delete
);
1189 deleteAction
->setIcon(KIcon("editdelete"));
1190 connect(deleteAction
, SIGNAL(triggered()), this, SLOT(deleteItems()));
1192 QAction
* properties
= actionCollection()->addAction("properties");
1193 properties
->setText(i18n("Propert&ies"));
1194 properties
->setShortcut(Qt::Key_Alt
| Qt::Key_Return
);
1195 connect(properties
, SIGNAL(triggered()), this, SLOT(properties()));
1197 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1199 // setup 'Edit' menu
1200 UndoManager
& undoManager
= UndoManager::instance();
1201 KStandardAction::undo(this,
1203 actionCollection());
1204 connect(&undoManager
, SIGNAL(undoAvailable(bool)),
1205 this, SLOT(slotUndoAvailable(bool)));
1206 connect(&undoManager
, SIGNAL(undoTextChanged(const QString
&)),
1207 this, SLOT(slotUndoTextChanged(const QString
&)));
1209 KStandardAction::redo(this,
1211 actionCollection());
1212 connect(&undoManager
, SIGNAL(redoAvailable(bool)),
1213 this, SLOT(slotRedoAvailable(bool)));
1214 connect(&undoManager
, SIGNAL(redoTextChanged(const QString
&)),
1215 this, SLOT(slotRedoTextChanged(const QString
&)));
1217 KStandardAction::cut(this, SLOT(cut()), actionCollection());
1218 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1219 KStandardAction::paste(this, SLOT(paste()), actionCollection());
1221 QAction
* selectAll
= actionCollection()->addAction("select_all");
1222 selectAll
->setText(i18n("Select All"));
1223 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1224 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1226 QAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1227 invertSelection
->setText(i18n("Invert Selection"));
1228 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1229 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1231 // setup 'View' menu
1232 KStandardAction::zoomIn(this,
1234 actionCollection());
1236 KStandardAction::zoomOut(this,
1238 actionCollection());
1240 KToggleAction
* iconsView
= actionCollection()->add
<KToggleAction
>("icons");
1241 iconsView
->setText(i18n("Icons"));
1242 iconsView
->setShortcut(Qt::CTRL
| Qt::Key_1
);
1243 iconsView
->setIcon(KIcon("view_icon"));
1244 connect(iconsView
, SIGNAL(triggered()), this, SLOT(setIconsView()));
1246 KToggleAction
* detailsView
= actionCollection()->add
<KToggleAction
>("details");
1247 detailsView
->setText(i18n("Details"));
1248 detailsView
->setShortcut(Qt::CTRL
| Qt::Key_2
);
1249 detailsView
->setIcon(KIcon("view_text"));
1250 connect(detailsView
, SIGNAL(triggered()), this, SLOT(setDetailsView()));
1252 QActionGroup
* viewModeGroup
= new QActionGroup(this);
1253 viewModeGroup
->addAction(iconsView
);
1254 viewModeGroup
->addAction(detailsView
);
1256 KToggleAction
* sortByName
= actionCollection()->add
<KToggleAction
>("by_name");
1257 sortByName
->setText(i18n("By Name"));
1258 connect(sortByName
, SIGNAL(triggered()), this, SLOT(sortByName()));
1260 KToggleAction
* sortBySize
= actionCollection()->add
<KToggleAction
>("by_size");
1261 sortBySize
->setText(i18n("By Size"));
1262 connect(sortBySize
, SIGNAL(triggered()), this, SLOT(sortBySize()));
1264 KToggleAction
* sortByDate
= actionCollection()->add
<KToggleAction
>("by_date");
1265 sortByDate
->setText(i18n("By Date"));
1266 connect(sortByDate
, SIGNAL(triggered()), this, SLOT(sortByDate()));
1268 QActionGroup
* sortGroup
= new QActionGroup(this);
1269 sortGroup
->addAction(sortByName
);
1270 sortGroup
->addAction(sortBySize
);
1271 sortGroup
->addAction(sortByDate
);
1273 KToggleAction
* sortDescending
= actionCollection()->add
<KToggleAction
>("descending");
1274 sortDescending
->setText(i18n("Descending"));
1275 connect(sortDescending
, SIGNAL(triggered()), this, SLOT(toggleSortOrder()));
1277 KToggleAction
* showPreview
= actionCollection()->add
<KToggleAction
>("show_preview");
1278 showPreview
->setText(i18n("Show Preview"));
1279 connect(showPreview
, SIGNAL(triggered()), this, SLOT(togglePreview()));
1281 KToggleAction
* showHiddenFiles
= actionCollection()->add
<KToggleAction
>("show_hidden_files");
1282 showHiddenFiles
->setText(i18n("Show Hidden Files"));
1283 //showHiddenFiles->setShortcut(Qt::ALT | Qt::Key_ KDE4-TODO: what Qt-Key represents '.'?
1284 connect(showHiddenFiles
, SIGNAL(triggered()), this, SLOT(toggleShowHiddenFiles()));
1286 KToggleAction
* split
= actionCollection()->add
<KToggleAction
>("split_view");
1287 split
->setText(i18n("Split View"));
1288 split
->setShortcut(Qt::Key_F10
);
1289 split
->setIcon(KIcon("view_left_right"));
1290 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1292 QAction
* reload
= actionCollection()->addAction("reload");
1293 reload
->setText(i18n("Reload"));
1294 reload
->setShortcut(Qt::Key_F5
);
1295 reload
->setIcon(KIcon("reload"));
1296 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1298 QAction
* stop
= actionCollection()->addAction("stop");
1299 stop
->setText(i18n("Stop"));
1300 stop
->setIcon(KIcon("stop"));
1301 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1303 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1304 showFullLocation
->setText(i18n("Show Full Location"));
1305 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1306 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1308 KToggleAction
* editLocation
= actionCollection()->add
<KToggleAction
>("edit_location");
1309 editLocation
->setText(i18n("Edit Location"));
1310 editLocation
->setShortcut(Qt::Key_F6
);
1311 connect(editLocation
, SIGNAL(triggered()), this, SLOT(editLocation()));
1313 QAction
* adjustViewProps
= actionCollection()->addAction("view_properties");
1314 adjustViewProps
->setText(i18n("Adjust View Properties..."));
1315 connect(adjustViewProps
, SIGNAL(triggered()), this, SLOT(adjustViewProperties()));
1318 KStandardAction::back(this, SLOT(goBack()), actionCollection());
1319 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1320 KStandardAction::up(this, SLOT(goUp()), actionCollection());
1321 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1323 // setup 'Tools' menu
1324 QAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1325 openTerminal
->setText(i18n("Open Terminal"));
1326 openTerminal
->setShortcut(Qt::Key_F4
);
1327 openTerminal
->setIcon(KIcon("konsole"));
1328 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1330 QAction
* findFile
= actionCollection()->addAction("find_file");
1331 findFile
->setText(i18n("Find File..."));
1332 findFile
->setShortcut(Qt::Key_F
);
1333 findFile
->setIcon(KIcon("filefind"));
1334 connect(findFile
, SIGNAL(triggered()), this, SLOT(findFile()));
1336 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
1337 showFilterBar
->setText(i18n("Show Filter Bar"));
1338 showFilterBar
->setShortcut(Qt::Key_Slash
);
1339 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1341 QAction
* compareFiles
= actionCollection()->addAction("compare_files");
1342 compareFiles
->setText(i18n("Compare Files"));
1343 compareFiles
->setIcon(KIcon("kompare"));
1344 compareFiles
->setEnabled(false);
1345 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1347 // setup 'Settings' menu
1348 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1351 void DolphinMainWindow::setupDockWidgets()
1353 QDockWidget
* shortcutsDock
= new QDockWidget(i18n("Bookmarks"));
1354 shortcutsDock
->setObjectName("bookmarksDock");
1355 shortcutsDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1356 shortcutsDock
->setWidget(new BookmarksSidebarPage(this));
1358 shortcutsDock
->toggleViewAction()->setText(i18n("Show Bookmarks Panel"));
1359 actionCollection()->addAction("show_bookmarks_panel", shortcutsDock
->toggleViewAction());
1361 addDockWidget(Qt::LeftDockWidgetArea
, shortcutsDock
);
1363 QDockWidget
* infoDock
= new QDockWidget(i18n("Information"));
1364 infoDock
->setObjectName("infoDock");
1365 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1366 infoDock
->setWidget(new InfoSidebarPage(this));
1368 infoDock
->toggleViewAction()->setText(i18n("Show Information Panel"));
1369 actionCollection()->addAction("show_info_panel", infoDock
->toggleViewAction());
1371 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1374 void DolphinMainWindow::setupCreateNewMenuActions()
1376 // Parts of the following code have been taken
1377 // from the class KNewMenu located in
1378 // libqonq/knewmenu.h of Konqueror.
1379 // Copyright (C) 1998, 1999 David Faure <faure@kde.org>
1380 // 2003 Sven Leiber <s.leiber@web.de>
1382 QStringList files
= actionCollection()->instance()->dirs()->findAllResources("templates");
1383 for (QStringList::Iterator it
= files
.begin() ; it
!= files
.end(); ++it
) {
1384 if ((*it
)[0] != '.' ) {
1385 KSimpleConfig
config(*it
, true);
1386 config
.setDesktopGroup();
1388 // tricky solution to ensure that TextFile is at the beginning
1389 // because this filetype is the most used (according kde-core discussion)
1390 const QString
name(config
.readEntry("Name"));
1393 const QString
path(config
.readPathEntry("Url"));
1394 if (!path
.endsWith("emptydir")) {
1395 if (path
.endsWith("TextFile.txt")) {
1398 else if (!KDesktopFile::isDesktopFile(path
)) {
1401 else if (path
.endsWith("Url.desktop")){
1404 else if (path
.endsWith("Program.desktop")){
1411 const QString
icon(config
.readEntry("Icon"));
1412 const QString
comment(config
.readEntry("Comment"));
1413 const QString
type(config
.readEntry("Type"));
1415 const QString
filePath(*it
);
1418 if (type
== "Link") {
1419 CreateFileEntry entry
;
1422 entry
.comment
= comment
;
1423 entry
.templatePath
= filePath
;
1424 m_createFileTemplates
.insert(key
, entry
);
1429 m_createFileTemplates
.sort();
1431 unplugActionList("create_actions");
1432 KSortableList
<CreateFileEntry
, QString
>::ConstIterator it
= m_createFileTemplates
.begin();
1433 KSortableList
<CreateFileEntry
, QString
>::ConstIterator end
= m_createFileTemplates
.end();
1434 /* KDE4-TODO: don't port this code; use KNewMenu instead
1436 CreateFileEntry entry = (*it).value();
1437 KAction* action = new KAction(entry.name);
1438 action->setIcon(entry.icon);
1439 action->setName((*it).index());
1440 connect(action, SIGNAL(activated()),
1441 this, SLOT(createFile()));
1443 const QChar section = ((*it).index()[0]);
1447 m_fileGroupActions.append(action);
1453 // TODO: not used yet. See documentation of DolphinMainWindow::linkGroupActions()
1454 // and DolphinMainWindow::linkToDeviceActions() in the header file for details.
1455 //m_linkGroupActions.append(action);
1460 // TODO: not used yet. See documentation of DolphinMainWindow::linkGroupActions()
1461 // and DolphinMainWindow::linkToDeviceActions() in the header file for details.
1462 //m_linkToDeviceActions.append(action);
1471 plugActionList("create_file_group", m_fileGroupActions);
1472 //plugActionList("create_link_group", m_linkGroupActions);
1473 //plugActionList("link_to_device", m_linkToDeviceActions);*/
1476 void DolphinMainWindow::updateHistory()
1479 const Q3ValueList
<UrlNavigator::HistoryElem
> list
= m_activeView
->urlHistory(index
);
1481 QAction
* backAction
= actionCollection()->action("go_back");
1482 if (backAction
!= 0) {
1483 backAction
->setEnabled(index
< static_cast<int>(list
.count()) - 1);
1486 QAction
* forwardAction
= actionCollection()->action("go_forward");
1487 if (forwardAction
!= 0) {
1488 forwardAction
->setEnabled(index
> 0);
1492 void DolphinMainWindow::updateEditActions()
1494 const KFileItemList list
= m_activeView
->selectedItems();
1495 if (list
.isEmpty()) {
1496 stateChanged("has_no_selection");
1499 stateChanged("has_selection");
1501 QAction
* renameAction
= actionCollection()->action("rename");
1502 if (renameAction
!= 0) {
1503 renameAction
->setEnabled(list
.count() >= 1);
1506 bool enableMoveToTrash
= true;
1508 KFileItemList::const_iterator it
= list
.begin();
1509 const KFileItemList::const_iterator end
= list
.end();
1511 KFileItem
* item
= *it
;
1512 const KUrl
& url
= item
->url();
1513 // only enable the 'Move to Trash' action for local files
1514 if (!url
.isLocalFile()) {
1515 enableMoveToTrash
= false;
1520 QAction
* moveToTrashAction
= actionCollection()->action("move_to_trash");
1521 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1523 updatePasteAction();
1526 void DolphinMainWindow::updateViewActions()
1528 QAction
* zoomInAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::ZoomIn
));
1529 if (zoomInAction
!= 0) {
1530 zoomInAction
->setEnabled(m_activeView
->isZoomInPossible());
1533 QAction
* zoomOutAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::ZoomOut
));
1534 if (zoomOutAction
!= 0) {
1535 zoomOutAction
->setEnabled(m_activeView
->isZoomOutPossible());
1538 QAction
* action
= 0;
1539 switch (m_activeView
->mode()) {
1540 case DolphinView::IconsView
:
1541 action
= actionCollection()->action("icons");
1543 case DolphinView::DetailsView
:
1544 action
= actionCollection()->action("details");
1546 //case DolphinView::PreviewsView:
1547 // action = actionCollection()->action("previews");
1554 KToggleAction
* toggleAction
= static_cast<KToggleAction
*>(action
);
1555 toggleAction
->setChecked(true);
1558 slotSortingChanged(m_activeView
->sorting());
1559 slotSortOrderChanged(m_activeView
->sortOrder());
1561 KToggleAction
* showFilterBarAction
=
1562 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
1563 showFilterBarAction
->setChecked(m_activeView
->isFilterBarVisible());
1565 KToggleAction
* showHiddenFilesAction
=
1566 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
1567 showHiddenFilesAction
->setChecked(m_activeView
->showHiddenFiles());
1569 KToggleAction
* splitAction
= static_cast<KToggleAction
*>(actionCollection()->action("split_view"));
1570 splitAction
->setChecked(m_view
[SecondaryIdx
] != 0);
1573 void DolphinMainWindow::updateGoActions()
1575 QAction
* goUpAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::Up
));
1576 const KUrl
& currentUrl
= m_activeView
->url();
1577 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1580 void DolphinMainWindow::copyUrls(const KUrl::List
& source
, const KUrl
& dest
)
1582 KIO::Job
* job
= KIO::copy(source
, dest
);
1583 addPendingUndoJob(job
, DolphinCommand::Copy
, source
, dest
);
1586 void DolphinMainWindow::moveUrls(const KUrl::List
& source
, const KUrl
& dest
)
1588 KIO::Job
* job
= KIO::move(source
, dest
);
1589 addPendingUndoJob(job
, DolphinCommand::Move
, source
, dest
);
1592 void DolphinMainWindow::addPendingUndoJob(KIO::Job
* job
,
1593 DolphinCommand::Type commandType
,
1594 const KUrl::List
& source
,
1597 connect(job
, SIGNAL(result(KJob
*)),
1598 this, SLOT(addUndoOperation(KJob
*)));
1601 undoInfo
.id
= job
->progressId();
1602 undoInfo
.command
= DolphinCommand(commandType
, source
, dest
);
1603 m_pendingUndoJobs
.append(undoInfo
);
1606 void DolphinMainWindow::clearStatusBar()
1608 m_activeView
->statusBar()->clear();
1611 void DolphinMainWindow::connectViewSignals(int viewIndex
)
1613 DolphinView
* view
= m_view
[viewIndex
];
1614 connect(view
, SIGNAL(modeChanged()),
1615 this, SLOT(slotViewModeChanged()));
1616 connect(view
, SIGNAL(showHiddenFilesChanged()),
1617 this, SLOT(slotShowHiddenFilesChanged()));
1618 connect(view
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
1619 this, SLOT(slotSortingChanged(DolphinView::Sorting
)));
1620 connect(view
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
1621 this, SLOT(slotSortOrderChanged(Qt::SortOrder
)));
1622 connect(view
, SIGNAL(selectionChanged()),
1623 this, SLOT(slotSelectionChanged()));
1624 connect(view
, SIGNAL(showFilterBarChanged(bool)),
1625 this, SLOT(updateFilterBarAction(bool)));
1627 const UrlNavigator
* navigator
= view
->urlNavigator();
1628 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1629 this, SLOT(slotUrlChanged(const KUrl
&)));
1630 connect(navigator
, SIGNAL(historyChanged()),
1631 this, SLOT(slotHistoryChanged()));
1635 #include "dolphinmainwindow.moc"