]>
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>
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>
54 #include <konqmimedata.h>
56 #include <qclipboard.h>
57 #include <q3dragobject.h>
59 #include <Q3ValueList>
60 #include <QCloseEvent>
62 #include <QDockWidget>
64 #include "urlnavigator.h"
65 #include "viewpropertiesdialog.h"
66 #include "viewproperties.h"
67 #include "dolphinsettings.h"
68 #include "dolphinsettingsdialog.h"
69 #include "dolphinstatusbar.h"
70 #include "dolphinapplication.h"
71 #include "undomanager.h"
72 #include "progressindicator.h"
73 #include "dolphinsettings.h"
74 #include "bookmarkssidebarpage.h"
75 #include "infosidebarpage.h"
76 #include "generalsettings.h"
77 #include "dolphinapplication.h"
80 DolphinMainWindow::DolphinMainWindow() :
85 setObjectName("Dolphin");
86 m_view
[PrimaryIdx
] = 0;
87 m_view
[SecondaryIdx
] = 0;
90 DolphinMainWindow::~DolphinMainWindow()
92 qDeleteAll(m_fileGroupActions
);
93 m_fileGroupActions
.clear();
95 DolphinApplication::app()->removeMainWindow(this);
98 void DolphinMainWindow::setActiveView(DolphinView
* view
)
100 assert((view
== m_view
[PrimaryIdx
]) || (view
== m_view
[SecondaryIdx
]));
101 if (m_activeView
== view
) {
112 setCaption(m_activeView
->url().fileName());
114 emit
activeViewChanged();
117 void DolphinMainWindow::dropUrls(const KUrl::List
& urls
,
118 const KUrl
& destination
)
120 int selectedIndex
= -1;
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 popup
.insertItem(SmallIcon("goto"), i18n("&Move Here") + "\t" /* KDE4-TODO: + KKey::modFlagLabel(KKey::SHIFT)*/, 0);
146 popup
.insertItem(SmallIcon("editcopy"), i18n( "&Copy Here" ) /* KDE4-TODO + "\t" + KKey::modFlagLabel(KKey::CTRL)*/, 1);
147 popup
.insertItem(i18n("&Link Here") /* KDE4-TODO + "\t" + KKey::modFlagLabel((KKey::ModFlag)(KKey::CTRL|KKey::SHIFT)) */, 2);
148 popup
.insertSeparator();
149 popup
.insertItem(SmallIcon("stop"), i18n("Cancel"), 3);
150 popup
.setAccel(i18n("Escape"), 3);
152 /* KDE4-TODO: selectedIndex = popup.exec(QCursor::pos()); */
153 popup
.exec(QCursor::pos());
154 selectedIndex
= 0; // KD4-TODO: use QAction instead of switch below
155 // See libkonq/konq_operations.cc: KonqOperations::doDropFileCopy() (and doDrop, the main method)
158 if (selectedIndex
< 0) {
162 switch (selectedIndex
) {
164 // 'Move Here' has been selected
165 updateViewProperties(urls
);
166 moveUrls(urls
, destination
);
171 // 'Copy Here' has been selected
172 updateViewProperties(urls
);
173 copyUrls(urls
, destination
);
178 // 'Link Here' has been selected
179 KIO::Job
* job
= KIO::link(urls
, destination
);
180 addPendingUndoJob(job
, DolphinCommand::Link
, urls
, destination
);
185 // 'Cancel' has been selected
190 void DolphinMainWindow::refreshViews()
192 const bool split
= DolphinSettings::instance().generalSettings()->splitView();
193 const bool isPrimaryViewActive
= (m_activeView
== m_view
[PrimaryIdx
]);
195 for (int i
= PrimaryIdx
; i
<= SecondaryIdx
; ++i
) {
196 if (m_view
[i
] != 0) {
197 url
= m_view
[i
]->url();
199 // delete view instance...
201 m_view
[i
]->deleteLater();
205 if (split
|| (i
== PrimaryIdx
)) {
206 // ... and recreate it
207 ViewProperties
props(url
);
208 m_view
[i
] = new DolphinView(this,
212 props
.showHiddenFiles());
213 connectViewSignals(i
);
218 m_activeView
= isPrimaryViewActive
? m_view
[PrimaryIdx
] : m_view
[SecondaryIdx
];
219 assert(m_activeView
!= 0);
222 emit
activeViewChanged();
225 void DolphinMainWindow::slotViewModeChanged()
230 void DolphinMainWindow::slotShowHiddenFilesChanged()
232 KToggleAction
* showHiddenFilesAction
=
233 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
234 showHiddenFilesAction
->setChecked(m_activeView
->showHiddenFiles());
237 void DolphinMainWindow::slotSortingChanged(DolphinView::Sorting sorting
)
241 case DolphinView::SortByName
:
242 action
= actionCollection()->action("by_name");
244 case DolphinView::SortBySize
:
245 action
= actionCollection()->action("by_size");
247 case DolphinView::SortByDate
:
248 action
= actionCollection()->action("by_date");
255 KToggleAction
* toggleAction
= static_cast<KToggleAction
*>(action
);
256 toggleAction
->setChecked(true);
260 void DolphinMainWindow::slotSortOrderChanged(Qt::SortOrder order
)
262 KToggleAction
* descending
= static_cast<KToggleAction
*>(actionCollection()->action("descending"));
263 const bool sortDescending
= (order
== Qt::Descending
);
264 descending
->setChecked(sortDescending
);
267 void DolphinMainWindow::slotSelectionChanged()
271 assert(m_view
[PrimaryIdx
] != 0);
272 int selectedUrlsCount
= m_view
[PrimaryIdx
]->selectedUrls().count();
273 if (m_view
[SecondaryIdx
] != 0) {
274 selectedUrlsCount
+= m_view
[SecondaryIdx
]->selectedUrls().count();
277 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
278 compareFilesAction
->setEnabled(selectedUrlsCount
== 2);
280 m_activeView
->updateStatusBar();
282 emit
selectionChanged();
285 void DolphinMainWindow::slotHistoryChanged()
290 void DolphinMainWindow::slotUrlChanged(const KUrl
& url
)
294 setCaption(url
.fileName());
297 void DolphinMainWindow::updateFilterBarAction(bool show
)
299 KToggleAction
* showFilterBarAction
=
300 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
301 showFilterBarAction
->setChecked(show
);
304 void DolphinMainWindow::redo()
306 UndoManager::instance().redo(this);
309 void DolphinMainWindow::undo()
311 UndoManager::instance().undo(this);
314 void DolphinMainWindow::openNewMainWindow()
316 DolphinApplication::app()->createMainWindow()->show();
319 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
322 //KConfig* config = KGlobal::config();
323 //config->setGroup("General");
324 //config->writeEntry("First Run", false);
326 DolphinSettings
& settings
= DolphinSettings::instance();
327 GeneralSettings
* generalSettings
= settings
.generalSettings();
328 generalSettings
->setFirstRun(false);
332 KMainWindow::closeEvent(event
);
335 void DolphinMainWindow::saveProperties(KConfig
* config
)
337 config
->setGroup("Primary view");
338 config
->writeEntry("Url", m_view
[PrimaryIdx
]->url().url());
339 config
->writeEntry("Editable Url", m_view
[PrimaryIdx
]->isUrlEditable());
340 if (m_view
[SecondaryIdx
] != 0) {
341 config
->setGroup("Secondary view");
342 config
->writeEntry("Url", m_view
[SecondaryIdx
]->url().url());
343 config
->writeEntry("Editable Url", m_view
[SecondaryIdx
]->isUrlEditable());
347 void DolphinMainWindow::readProperties(KConfig
* config
)
349 config
->setGroup("Primary view");
350 m_view
[PrimaryIdx
]->setUrl(config
->readEntry("Url"));
351 m_view
[PrimaryIdx
]->setUrlEditable(config
->readEntry("Editable Url", false));
352 if (config
->hasGroup("Secondary view")) {
353 config
->setGroup("Secondary view");
354 if (m_view
[SecondaryIdx
] == 0) {
357 m_view
[SecondaryIdx
]->setUrl(config
->readEntry("Url"));
358 m_view
[SecondaryIdx
]->setUrlEditable(config
->readEntry("Editable Url", false));
360 else if (m_view
[SecondaryIdx
] != 0) {
365 void DolphinMainWindow::createFolder()
367 // Parts of the following code have been taken
368 // from the class KonqPopupMenu located in
369 // libqonq/konq_popupmenu.h of Konqueror.
370 // (Copyright (C) 2000 David Faure <faure@kde.org>,
371 // Copyright (C) 2001 Holger Freyther <freyther@yahoo.com>)
375 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
376 const KUrl
baseUrl(m_activeView
->url());
378 QString
name(i18n("New Folder"));
379 baseUrl
.path(KUrl::AddTrailingSlash
);
382 if (baseUrl
.isLocalFile() && QFileInfo(baseUrl
.path(KUrl::AddTrailingSlash
) + name
).exists()) {
383 name
= KIO::RenameDlg::suggestName(baseUrl
, i18n("New Folder"));
387 name
= KInputDialog::getText(i18n("New Folder"),
388 i18n("Enter folder name:" ),
394 // the user has pressed 'Cancel'
398 assert(!name
.isEmpty());
401 if ((name
[0] == '/') || (name
[0] == '~')) {
402 url
.setPath(KShell::tildeExpand(name
));
405 name
= KIO::encodeFileName(name
);
409 ok
= KIO::NetAccess::mkdir(url
, this);
411 // TODO: provide message type hint
413 statusBar
->setMessage(i18n("Created folder %1.",url
.path()),
414 DolphinStatusBar::OperationCompleted
);
416 DolphinCommand
command(DolphinCommand::CreateFolder
, KUrl::List(), url
);
417 UndoManager::instance().addCommand(command
);
420 // Creating of the folder has been failed. Check whether the creating
421 // has been failed because a folder with the same name exists...
422 if (KIO::NetAccess::exists(url
, true, this)) {
423 statusBar
->setMessage(i18n("A folder named %1 already exists.",url
.path()),
424 DolphinStatusBar::Error
);
427 statusBar
->setMessage(i18n("Creating of folder %1 failed.",url
.path()),
428 DolphinStatusBar::Error
);
434 void DolphinMainWindow::createFile()
436 // Parts of the following code have been taken
437 // from the class KonqPopupMenu located in
438 // libqonq/konq_popupmenu.h of Konqueror.
439 // (Copyright (C) 2000 David Faure <faure@kde.org>,
440 // Copyright (C) 2001 Holger Freyther <freyther@yahoo.com>)
444 // TODO: const Entry& entry = m_createFileTemplates[QString(sender->name())];
445 // should be enough. Anyway: the implemantation of [] does a linear search internally too.
446 KSortableList
<CreateFileEntry
, QString
>::ConstIterator it
= m_createFileTemplates
.begin();
447 KSortableList
<CreateFileEntry
, QString
>::ConstIterator end
= m_createFileTemplates
.end();
449 const QString
senderName(sender()->objectName());
451 CreateFileEntry entry
;
452 while (!found
&& (it
!= end
)) {
453 if ((*it
).key() == senderName
) {
454 entry
= (*it
).value();
462 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
463 if (!found
|| !QFile::exists(entry
.templatePath
)) {
464 statusBar
->setMessage(i18n("Could not create file."), DolphinStatusBar::Error
);
468 // Get the source path of the template which should be copied.
469 // The source path is part of the Url entry of the desktop file.
470 const int pos
= entry
.templatePath
.lastIndexOf('/');
471 QString
sourcePath(entry
.templatePath
.left(pos
+ 1));
472 sourcePath
+= KDesktopFile(entry
.templatePath
, true).readPathEntry("Url");
474 QString
name(i18n(entry
.name
.toAscii()));
475 // Most entry names end with "..." (e. g. "HTML File..."), which is ok for
476 // menus but no good choice for a new file name -> remove the dots...
477 name
.replace("...", QString::null
);
479 // add the file extension to the name
480 name
.append(sourcePath
.right(sourcePath
.length() - sourcePath
.lastIndexOf('.')));
482 // Check whether a file with the current name already exists. If yes suggest automatically
483 // a unique file name (e. g. "HTML File" will be replaced by "HTML File_1").
484 const KUrl
viewUrl(m_activeView
->url());
485 const bool fileExists
= viewUrl
.isLocalFile() &&
486 QFileInfo(viewUrl
.path(KUrl::AddTrailingSlash
) + KIO::encodeFileName(name
)).exists();
488 name
= KIO::RenameDlg::suggestName(viewUrl
, name
);
491 // let the user change the suggested file name
493 name
= KInputDialog::getText(entry
.name
,
499 // the user has pressed 'Cancel'
503 // before copying the template to the destination path check whether a file
504 // with the given name already exists
505 const QString
destPath(viewUrl
.pathOrUrl() + "/" + KIO::encodeFileName(name
));
506 const KUrl
destUrl(destPath
);
507 if (KIO::NetAccess::exists(destUrl
, false, this)) {
508 statusBar
->setMessage(i18n("A file named %1 already exists.",name
),
509 DolphinStatusBar::Error
);
513 // copy the template to the destination path
514 const KUrl
sourceUrl(sourcePath
);
515 KIO::CopyJob
* job
= KIO::copyAs(sourceUrl
, destUrl
);
516 job
->setDefaultPermissions(true);
517 if (KIO::NetAccess::synchronousRun(job
, this)) {
518 statusBar
->setMessage(i18n("Created file %1.",name
),
519 DolphinStatusBar::OperationCompleted
);
522 list
.append(sourceUrl
);
523 DolphinCommand
command(DolphinCommand::CreateFile
, list
, destUrl
);
524 UndoManager::instance().addCommand(command
);
528 statusBar
->setMessage(i18n("Creating of file %1 failed.",name
),
529 DolphinStatusBar::Error
);
533 void DolphinMainWindow::rename()
536 m_activeView
->renameSelectedItems();
539 void DolphinMainWindow::moveToTrash()
542 KUrl::List selectedUrls
= m_activeView
->selectedUrls();
543 KIO::Job
* job
= KIO::trash(selectedUrls
);
544 addPendingUndoJob(job
, DolphinCommand::Trash
, selectedUrls
, m_activeView
->url());
547 void DolphinMainWindow::deleteItems()
551 KUrl::List list
= m_activeView
->selectedUrls();
552 const uint itemCount
= list
.count();
553 assert(itemCount
>= 1);
557 text
= i18n("Do you really want to delete the %1 selected items?",itemCount
);
560 const KUrl
& url
= list
.first();
561 text
= i18n("Do you really want to delete '%1'?",url
.fileName());
564 const bool del
= KMessageBox::warningContinueCancel(this,
567 KGuiItem(i18n("Delete"), SmallIcon("editdelete"))
568 ) == KMessageBox::Continue
;
570 KIO::Job
* job
= KIO::del(list
);
571 connect(job
, SIGNAL(result(KJob
*)),
572 this, SLOT(slotHandleJobError(KJob
*)));
573 connect(job
, SIGNAL(result(KJob
*)),
574 this, SLOT(slotDeleteFileFinished(KJob
*)));
578 void DolphinMainWindow::properties()
580 const KFileItemList list
= m_activeView
->selectedItems();
581 new KPropertiesDialog(list
, this);
584 void DolphinMainWindow::quit()
589 void DolphinMainWindow::slotHandleJobError(KJob
* job
)
591 if (job
->error() != 0) {
592 m_activeView
->statusBar()->setMessage(job
->errorString(),
593 DolphinStatusBar::Error
);
597 void DolphinMainWindow::slotDeleteFileFinished(KJob
* job
)
599 if (job
->error() == 0) {
600 m_activeView
->statusBar()->setMessage(i18n("Delete operation completed."),
601 DolphinStatusBar::OperationCompleted
);
603 // TODO: In opposite to the 'Move to Trash' operation in the class KFileIconView
604 // no rearranging of the item position is done when a file has been deleted.
605 // This is bypassed by reloading the view, but it might be worth to investigate
606 // deeper for the root of this issue.
607 m_activeView
->reload();
611 void DolphinMainWindow::slotUndoAvailable(bool available
)
613 QAction
* undoAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Undo
));
614 if (undoAction
!= 0) {
615 undoAction
->setEnabled(available
);
619 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
621 QAction
* undoAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Undo
));
622 if (undoAction
!= 0) {
623 undoAction
->setText(text
);
627 void DolphinMainWindow::slotRedoAvailable(bool available
)
629 QAction
* redoAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Redo
));
630 if (redoAction
!= 0) {
631 redoAction
->setEnabled(available
);
635 void DolphinMainWindow::slotRedoTextChanged(const QString
& text
)
637 QAction
* redoAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Redo
));
638 if (redoAction
!= 0) {
639 redoAction
->setText(text
);
643 void DolphinMainWindow::cut()
645 QMimeData
* mimeData
= new QMimeData();
646 const KUrl::List kdeUrls
= m_activeView
->selectedUrls();
647 const KUrl::List mostLocalUrls
;
648 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, true);
649 QApplication::clipboard()->setMimeData(mimeData
);
652 void DolphinMainWindow::copy()
654 QMimeData
* mimeData
= new QMimeData();
655 const KUrl::List kdeUrls
= m_activeView
->selectedUrls();
656 const KUrl::List mostLocalUrls
;
657 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, false);
659 QApplication::clipboard()->setMimeData(mimeData
);
662 void DolphinMainWindow::paste()
664 QClipboard
* clipboard
= QApplication::clipboard();
665 const QMimeData
* mimeData
= clipboard
->mimeData();
669 const KUrl::List sourceUrls
= KUrl::List::fromMimeData(mimeData
);
671 // per default the pasting is done into the current Url of the view
672 KUrl
destUrl(m_activeView
->url());
674 // check whether the pasting should be done into a selected directory
675 KUrl::List selectedUrls
= m_activeView
->selectedUrls();
676 if (selectedUrls
.count() == 1) {
677 const KFileItem
fileItem(S_IFDIR
,
679 selectedUrls
.first(),
681 if (fileItem
.isDir()) {
682 // only one item is selected which is a directory, hence paste
683 // into this directory
684 destUrl
= selectedUrls
.first();
688 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
689 moveUrls(sourceUrls
, destUrl
);
693 copyUrls(sourceUrls
, destUrl
);
697 void DolphinMainWindow::updatePasteAction()
699 QAction
* pasteAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Paste
));
700 if (pasteAction
== 0) {
704 QString
text(i18n("Paste"));
705 QClipboard
* clipboard
= QApplication::clipboard();
706 const QMimeData
* mimeData
= clipboard
->mimeData();
708 KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
709 if (!urls
.isEmpty()) {
710 pasteAction
->setEnabled(true);
712 const int count
= urls
.count();
714 pasteAction
->setText(i18n("Paste 1 File"));
717 pasteAction
->setText(i18n("Paste %1 Files").arg(count
));
721 pasteAction
->setEnabled(false);
722 pasteAction
->setText(i18n("Paste"));
725 if (pasteAction
->isEnabled()) {
726 KUrl::List urls
= m_activeView
->selectedUrls();
727 const uint count
= urls
.count();
729 // pasting should not be allowed when more than one file
731 pasteAction
->setEnabled(false);
733 else if (count
== 1) {
734 // Only one file is selected. Pasting is only allowed if this
735 // file is a directory.
736 // TODO: this doesn't work with remote protocols; instead we need a
737 // m_activeView->selectedFileItems() to get the real KFileItems
738 const KFileItem
fileItem(S_IFDIR
,
742 pasteAction
->setEnabled(fileItem
.isDir());
747 void DolphinMainWindow::selectAll()
750 m_activeView
->selectAll();
753 void DolphinMainWindow::invertSelection()
756 m_activeView
->invertSelection();
758 void DolphinMainWindow::setIconsView()
760 m_activeView
->setMode(DolphinView::IconsView
);
763 void DolphinMainWindow::setDetailsView()
765 m_activeView
->setMode(DolphinView::DetailsView
);
768 void DolphinMainWindow::sortByName()
770 m_activeView
->setSorting(DolphinView::SortByName
);
773 void DolphinMainWindow::sortBySize()
775 m_activeView
->setSorting(DolphinView::SortBySize
);
778 void DolphinMainWindow::sortByDate()
780 m_activeView
->setSorting(DolphinView::SortByDate
);
783 void DolphinMainWindow::toggleSortOrder()
785 const Qt::SortOrder order
= (m_activeView
->sortOrder() == Qt::Ascending
) ?
788 m_activeView
->setSortOrder(order
);
791 void DolphinMainWindow::toggleSplitView()
793 if (m_view
[SecondaryIdx
] == 0) {
794 const int newWidth
= (m_view
[PrimaryIdx
]->width() - m_splitter
->handleWidth()) / 2;
795 // create a secondary view
796 m_view
[SecondaryIdx
] = new DolphinView(this,
798 m_view
[PrimaryIdx
]->url(),
799 m_view
[PrimaryIdx
]->mode(),
800 m_view
[PrimaryIdx
]->showHiddenFiles());
801 connectViewSignals(SecondaryIdx
);
802 m_splitter
->addWidget(m_view
[SecondaryIdx
]);
803 m_splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
804 m_view
[SecondaryIdx
]->show();
807 // remove secondary view
808 if (m_activeView
== m_view
[PrimaryIdx
]) {
809 m_view
[SecondaryIdx
]->close();
810 m_view
[SecondaryIdx
]->deleteLater();
811 m_view
[SecondaryIdx
] = 0;
812 setActiveView(m_view
[PrimaryIdx
]);
815 // The secondary view is active, hence from the users point of view
816 // the content of the secondary view should be moved to the primary view.
817 // From an implementation point of view it is more efficient to close
818 // the primary view and exchange the internal pointers afterwards.
819 m_view
[PrimaryIdx
]->close();
820 delete m_view
[PrimaryIdx
];
821 m_view
[PrimaryIdx
] = m_view
[SecondaryIdx
];
822 m_view
[SecondaryIdx
] = 0;
823 setActiveView(m_view
[PrimaryIdx
]);
828 void DolphinMainWindow::reloadView()
831 m_activeView
->reload();
834 void DolphinMainWindow::stopLoading()
838 void DolphinMainWindow::togglePreview()
842 void DolphinMainWindow::toggleShowHiddenFiles()
846 const KToggleAction
* showHiddenFilesAction
=
847 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
848 const bool show
= showHiddenFilesAction
->isChecked();
849 m_activeView
->setShowHiddenFiles(show
);
852 void DolphinMainWindow::showFilterBar()
854 const KToggleAction
* showFilterBarAction
=
855 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
856 const bool show
= showFilterBarAction
->isChecked();
857 m_activeView
->slotShowFilterBar(show
);
860 void DolphinMainWindow::zoomIn()
862 m_activeView
->zoomIn();
866 void DolphinMainWindow::zoomOut()
868 m_activeView
->zoomOut();
872 void DolphinMainWindow::toggleEditLocation()
876 KToggleAction
* action
= static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
878 bool editOrBrowse
= action
->isChecked();
879 // action->setChecked(action->setChecked);
880 m_activeView
->setUrlEditable(editOrBrowse
);
883 void DolphinMainWindow::editLocation()
885 KToggleAction
* action
= static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
886 action
->setChecked(true);
887 m_activeView
->setUrlEditable(true);
890 void DolphinMainWindow::adjustViewProperties()
893 ViewPropertiesDialog
dlg(m_activeView
);
897 void DolphinMainWindow::goBack()
900 m_activeView
->goBack();
903 void DolphinMainWindow::goForward()
906 m_activeView
->goForward();
909 void DolphinMainWindow::goUp()
912 m_activeView
->goUp();
915 void DolphinMainWindow::goHome()
918 m_activeView
->goHome();
921 void DolphinMainWindow::openTerminal()
923 QString
command("konsole --workdir \"");
924 command
.append(m_activeView
->url().path());
925 command
.append('\"');
927 KRun::runCommand(command
, "Konsole", "konsole");
930 void DolphinMainWindow::findFile()
932 KRun::run("kfind", m_activeView
->url());
935 void DolphinMainWindow::compareFiles()
937 // The method is only invoked if exactly 2 files have
938 // been selected. The selected files may be:
939 // - both in the primary view
940 // - both in the secondary view
941 // - one in the primary view and the other in the secondary
943 assert(m_view
[PrimaryIdx
] != 0);
947 KUrl::List urls
= m_view
[PrimaryIdx
]->selectedUrls();
949 switch (urls
.count()) {
951 assert(m_view
[SecondaryIdx
] != 0);
952 urls
= m_view
[SecondaryIdx
]->selectedUrls();
953 assert(urls
.count() == 2);
961 assert(m_view
[SecondaryIdx
] != 0);
962 urls
= m_view
[SecondaryIdx
]->selectedUrls();
963 assert(urls
.count() == 1);
975 // may not happen: compareFiles may only get invoked if 2
976 // files are selected
981 QString
command("kompare -c \"");
982 command
.append(urlA
.pathOrUrl());
983 command
.append("\" \"");
984 command
.append(urlB
.pathOrUrl());
985 command
.append('\"');
986 KRun::runCommand(command
, "Kompare", "kompare");
990 void DolphinMainWindow::editSettings()
992 // TODO: make a static method for opening the settings dialog
993 DolphinSettingsDialog
dlg(this);
997 void DolphinMainWindow::addUndoOperation(KJob
* job
)
999 if (job
->error() != 0) {
1000 slotHandleJobError(job
);
1003 const int id
= job
->progressId();
1005 // set iterator to the executed command with the current id...
1006 Q3ValueList
<UndoInfo
>::Iterator it
= m_pendingUndoJobs
.begin();
1007 const Q3ValueList
<UndoInfo
>::Iterator end
= m_pendingUndoJobs
.end();
1009 while (!found
&& (it
!= end
)) {
1010 if ((*it
).id
== id
) {
1019 DolphinCommand command
= (*it
).command
;
1020 if (command
.type() == DolphinCommand::Trash
) {
1021 // To be able to perform an undo for the 'Move to Trash' operation
1022 // all source Urls must be updated with the trash Url. E. g. when moving
1023 // a file "test.txt" and a second file "test.txt" to the trash,
1024 // then the filenames in the trash are "0-test.txt" and "1-test.txt".
1025 QMap
<QString
, QString
> metaData
;
1026 KIO::Job
*kiojob
= qobject_cast
<KIO::Job
*>( job
);
1029 metaData
= kiojob
->metaData();
1031 KUrl::List newSourceUrls
;
1033 KUrl::List sourceUrls
= command
.source();
1034 KUrl::List::Iterator sourceIt
= sourceUrls
.begin();
1035 const KUrl::List::Iterator sourceEnd
= sourceUrls
.end();
1037 while (sourceIt
!= sourceEnd
) {
1038 QMap
<QString
, QString
>::ConstIterator metaIt
= metaData
.find("trashUrl-" + (*sourceIt
).path());
1039 if (metaIt
!= metaData
.end()) {
1040 newSourceUrls
.append(KUrl(metaIt
.value()));
1044 command
.setSource(newSourceUrls
);
1047 UndoManager::instance().addCommand(command
);
1048 m_pendingUndoJobs
.erase(it
);
1050 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
1051 switch (command
.type()) {
1052 case DolphinCommand::Copy
:
1053 statusBar
->setMessage(i18n("Copy operation completed."),
1054 DolphinStatusBar::OperationCompleted
);
1056 case DolphinCommand::Move
:
1057 statusBar
->setMessage(i18n("Move operation completed."),
1058 DolphinStatusBar::OperationCompleted
);
1060 case DolphinCommand::Trash
:
1061 statusBar
->setMessage(i18n("Move to trash operation completed."),
1062 DolphinStatusBar::OperationCompleted
);
1071 void DolphinMainWindow::init()
1073 // Check whether Dolphin runs the first time. If yes then
1074 // a proper default window size is given at the end of DolphinMainWindow::init().
1075 GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
1076 const bool firstRun
= generalSettings
->firstRun();
1078 setAcceptDrops(true);
1080 m_splitter
= new QSplitter(this);
1082 DolphinSettings
& settings
= DolphinSettings::instance();
1084 KBookmarkManager
* manager
= settings
.bookmarkManager();
1085 assert(manager
!= 0);
1086 KBookmarkGroup root
= manager
->root();
1087 if (root
.first().isNull()) {
1088 root
.addBookmark(manager
, i18n("Home"), settings
.generalSettings()->homeUrl(), "folder_home");
1089 root
.addBookmark(manager
, i18n("Storage Media"), KUrl("media:/"), "blockdevice");
1090 root
.addBookmark(manager
, i18n("Network"), KUrl("remote:/"), "network_local");
1091 root
.addBookmark(manager
, i18n("Root"), KUrl("/"), "folder_red");
1092 root
.addBookmark(manager
, i18n("Trash"), KUrl("trash:/"), "trashcan_full");
1097 const KUrl
& homeUrl
= root
.first().url();
1098 setCaption(homeUrl
.fileName());
1099 ViewProperties
props(homeUrl
);
1100 m_view
[PrimaryIdx
] = new DolphinView(this,
1104 props
.showHiddenFiles());
1105 connectViewSignals(PrimaryIdx
);
1106 m_view
[PrimaryIdx
]->show();
1108 m_activeView
= m_view
[PrimaryIdx
];
1110 setCentralWidget(m_splitter
);
1113 setupGUI(Keys
|Save
|Create
|ToolBar
);
1116 stateChanged("new_file");
1117 setAutoSaveSettings();
1119 QClipboard
* clipboard
= QApplication::clipboard();
1120 connect(clipboard
, SIGNAL(dataChanged()),
1121 this, SLOT(updatePasteAction()));
1122 updatePasteAction();
1125 setupCreateNewMenuActions();
1130 // assure a proper default size if Dolphin runs the first time
1135 void DolphinMainWindow::loadSettings()
1137 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
1139 KToggleAction
* splitAction
= static_cast<KToggleAction
*>(actionCollection()->action("split_view"));
1140 if (settings
->splitView()) {
1141 splitAction
->setChecked(true);
1145 updateViewActions();
1148 void DolphinMainWindow::setupActions()
1150 // setup 'File' menu
1151 KAction
*action
= new KAction(KIcon("window_new"), i18n( "New &Window" ), actionCollection(), "new_window" );
1152 connect(action
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1154 KAction
* createFolder
= new KAction(i18n("Folder..."), actionCollection(), "create_folder");
1155 createFolder
->setIcon(KIcon("folder"));
1156 createFolder
->setShortcut(Qt::Key_N
);
1157 connect(createFolder
, SIGNAL(triggered()), this, SLOT(createFolder()));
1159 KAction
* rename
= new KAction(i18n("Rename"), actionCollection(), "rename");
1160 rename
->setShortcut(Qt::Key_F2
);
1161 connect(rename
, SIGNAL(triggered()), this, SLOT(rename()));
1163 KAction
* moveToTrash
= new KAction(i18n("Move to Trash"), actionCollection(), "move_to_trash");
1164 moveToTrash
->setIcon(KIcon("edittrash"));
1165 moveToTrash
->setShortcut(QKeySequence::Delete
);
1166 connect(moveToTrash
, SIGNAL(triggered()), this, SLOT(moveToTrash()));
1168 KAction
* deleteAction
= new KAction(i18n("Delete"), actionCollection(), "delete");
1169 deleteAction
->setShortcut(Qt::ALT
| Qt::Key_Delete
);
1170 deleteAction
->setIcon(KIcon("editdelete"));
1171 connect(deleteAction
, SIGNAL(triggered()), this, SLOT(deleteItems()));
1173 KAction
* properties
= new KAction(i18n("Propert&ies"), actionCollection(), "properties");
1174 properties
->setShortcut(Qt::Key_Alt
| Qt::Key_Return
);
1175 connect(properties
, SIGNAL(triggered()), this, SLOT(properties()));
1177 KStdAction::quit(this, SLOT(quit()), actionCollection());
1179 // setup 'Edit' menu
1180 UndoManager
& undoManager
= UndoManager::instance();
1181 KStdAction::undo(this,
1183 actionCollection());
1184 connect(&undoManager
, SIGNAL(undoAvailable(bool)),
1185 this, SLOT(slotUndoAvailable(bool)));
1186 connect(&undoManager
, SIGNAL(undoTextChanged(const QString
&)),
1187 this, SLOT(slotUndoTextChanged(const QString
&)));
1189 KStdAction::redo(this,
1191 actionCollection());
1192 connect(&undoManager
, SIGNAL(redoAvailable(bool)),
1193 this, SLOT(slotRedoAvailable(bool)));
1194 connect(&undoManager
, SIGNAL(redoTextChanged(const QString
&)),
1195 this, SLOT(slotRedoTextChanged(const QString
&)));
1197 KStdAction::cut(this, SLOT(cut()), actionCollection());
1198 KStdAction::copy(this, SLOT(copy()), actionCollection());
1199 KStdAction::paste(this, SLOT(paste()), actionCollection());
1201 KAction
* selectAll
= new KAction(i18n("Select All"), actionCollection(), "select_all");
1202 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1203 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1205 KAction
* invertSelection
= new KAction(i18n("Invert Selection"), actionCollection(), "invert_selection");
1206 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1207 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1209 // setup 'View' menu
1210 KStdAction::zoomIn(this,
1212 actionCollection());
1214 KStdAction::zoomOut(this,
1216 actionCollection());
1218 KToggleAction
* iconsView
= new KToggleAction(i18n("Icons"), actionCollection(), "icons");
1219 iconsView
->setShortcut(Qt::CTRL
| Qt::Key_1
);
1220 iconsView
->setIcon(KIcon("view_icon"));
1221 connect(iconsView
, SIGNAL(triggered()), this, SLOT(setIconsView()));
1223 KToggleAction
* detailsView
= new KToggleAction(i18n("Details"), actionCollection(), "details");
1224 detailsView
->setShortcut(Qt::CTRL
| Qt::Key_2
);
1225 detailsView
->setIcon(KIcon("view_text"));
1226 connect(detailsView
, SIGNAL(triggered()), this, SLOT(setDetailsView()));
1228 QActionGroup
* viewModeGroup
= new QActionGroup(this);
1229 viewModeGroup
->addAction(iconsView
);
1230 viewModeGroup
->addAction(detailsView
);
1232 KToggleAction
* sortByName
= new KToggleAction(i18n("By Name"), actionCollection(), "by_name");
1233 connect(sortByName
, SIGNAL(triggered()), this, SLOT(sortByName()));
1235 KToggleAction
* sortBySize
= new KToggleAction(i18n("By Size"), actionCollection(), "by_size");
1236 connect(sortBySize
, SIGNAL(triggered()), this, SLOT(sortBySize()));
1238 KToggleAction
* sortByDate
= new KToggleAction(i18n("By Date"), actionCollection(), "by_date");
1239 connect(sortByDate
, SIGNAL(triggered()), this, SLOT(sortByDate()));
1241 QActionGroup
* sortGroup
= new QActionGroup(this);
1242 sortGroup
->addAction(sortByName
);
1243 sortGroup
->addAction(sortBySize
);
1244 sortGroup
->addAction(sortByDate
);
1246 KToggleAction
* sortDescending
= new KToggleAction(i18n("Descending"), actionCollection(), "descending");
1247 connect(sortDescending
, SIGNAL(triggered()), this, SLOT(toggleSortOrder()));
1249 KToggleAction
* showPreview
= new KToggleAction(i18n("Show Preview"), actionCollection(), "show_preview");
1250 connect(showPreview
, SIGNAL(triggered()), this, SLOT(togglePreview()));
1252 KToggleAction
* showHiddenFiles
= new KToggleAction(i18n("Show Hidden Files"), actionCollection(), "show_hidden_files");
1253 //showHiddenFiles->setShortcut(Qt::ALT | Qt::Key_ KDE4-TODO: what Qt-Key represents '.'?
1254 connect(showHiddenFiles
, SIGNAL(triggered()), this, SLOT(toggleShowHiddenFiles()));
1256 KToggleAction
* split
= new KToggleAction(i18n("Split View"), actionCollection(), "split_view");
1257 split
->setShortcut(Qt::Key_F10
);
1258 split
->setIcon(KIcon("view_left_right"));
1259 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1261 KAction
* reload
= new KAction(i18n("Reload"), "F5", actionCollection(), "reload");
1262 reload
->setShortcut(Qt::Key_F5
);
1263 reload
->setIcon(KIcon("reload"));
1264 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1266 KAction
* stop
= new KAction(i18n("Stop"), actionCollection(), "stop");
1267 stop
->setIcon(KIcon("stop"));
1268 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1270 KToggleAction
* showFullLocation
= new KToggleAction(i18n("Show Full Location"), actionCollection(), "editable_location");
1271 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1272 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1274 KToggleAction
* editLocation
= new KToggleAction(i18n("Edit Location"), actionCollection(), "edit_location");
1275 editLocation
->setShortcut(Qt::Key_F6
);
1276 connect(editLocation
, SIGNAL(triggered()), this, SLOT(editLocation()));
1278 KAction
* adjustViewProps
= new KAction(i18n("Adjust View Properties..."), actionCollection(), "view_properties");
1279 connect(adjustViewProps
, SIGNAL(triggered()), this, SLOT(adjustViewProperties()));
1282 KStdAction::back(this, SLOT(goBack()), actionCollection());
1283 KStdAction::forward(this, SLOT(goForward()), actionCollection());
1284 KStdAction::up(this, SLOT(goUp()), actionCollection());
1285 KStdAction::home(this, SLOT(goHome()), actionCollection());
1287 // setup 'Tools' menu
1288 KAction
* openTerminal
= new KAction(i18n("Open Terminal"), actionCollection(), "open_terminal");
1289 openTerminal
->setShortcut(Qt::Key_F4
);
1290 openTerminal
->setIcon(KIcon("konsole"));
1291 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1293 KAction
* findFile
= new KAction(i18n("Find File..."), actionCollection(), "find_file");
1294 findFile
->setShortcut(Qt::Key_F
);
1295 findFile
->setIcon(KIcon("filefind"));
1296 connect(findFile
, SIGNAL(triggered()), this, SLOT(findFile()));
1298 KToggleAction
* showFilterBar
= new KToggleAction(i18n("Show Filter Bar"), actionCollection(), "show_filter_bar");
1299 showFilterBar
->setShortcut(Qt::Key_Slash
);
1300 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1302 KAction
* compareFiles
= new KAction(i18n("Compare Files"), actionCollection(), "compare_files");
1303 compareFiles
->setIcon(KIcon("kompare"));
1304 compareFiles
->setEnabled(false);
1305 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1307 // setup 'Settings' menu
1308 KStdAction::preferences(this, SLOT(editSettings()), actionCollection());
1311 void DolphinMainWindow::setupDockWidgets()
1313 QDockWidget
*shortcutsDock
= new QDockWidget(i18n("Shortcuts"));
1315 shortcutsDock
->setObjectName("shortcutsDock");
1316 shortcutsDock
->setWidget(new BookmarksSidebarPage(this));
1318 shortcutsDock
->toggleViewAction()->setObjectName("show_shortcuts_pane");
1319 shortcutsDock
->toggleViewAction()->setText(i18n("Show Shortcuts Panel"));
1320 actionCollection()->insert(shortcutsDock
->toggleViewAction());
1322 addDockWidget(Qt::LeftDockWidgetArea
, shortcutsDock
);
1324 QDockWidget
*infoDock
= new QDockWidget(i18n("Information"));
1326 infoDock
->setObjectName("infoDock");
1327 infoDock
->setWidget(new InfoSidebarPage(this));
1329 infoDock
->toggleViewAction()->setObjectName("show_info_pane");
1330 infoDock
->toggleViewAction()->setText(i18n("Show Information Panel"));
1331 actionCollection()->insert(infoDock
->toggleViewAction());
1333 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1336 void DolphinMainWindow::setupCreateNewMenuActions()
1338 // Parts of the following code have been taken
1339 // from the class KNewMenu located in
1340 // libqonq/knewmenu.h of Konqueror.
1341 // Copyright (C) 1998, 1999 David Faure <faure@kde.org>
1342 // 2003 Sven Leiber <s.leiber@web.de>
1344 QStringList files
= actionCollection()->instance()->dirs()->findAllResources("templates");
1345 for (QStringList::Iterator it
= files
.begin() ; it
!= files
.end(); ++it
) {
1346 if ((*it
)[0] != '.' ) {
1347 KSimpleConfig
config(*it
, true);
1348 config
.setDesktopGroup();
1350 // tricky solution to ensure that TextFile is at the beginning
1351 // because this filetype is the most used (according kde-core discussion)
1352 const QString
name(config
.readEntry("Name"));
1355 const QString
path(config
.readPathEntry("Url"));
1356 if (!path
.endsWith("emptydir")) {
1357 if (path
.endsWith("TextFile.txt")) {
1360 else if (!KDesktopFile::isDesktopFile(path
)) {
1363 else if (path
.endsWith("Url.desktop")){
1366 else if (path
.endsWith("Program.desktop")){
1373 const QString
icon(config
.readEntry("Icon"));
1374 const QString
comment(config
.readEntry("Comment"));
1375 const QString
type(config
.readEntry("Type"));
1377 const QString
filePath(*it
);
1380 if (type
== "Link") {
1381 CreateFileEntry entry
;
1384 entry
.comment
= comment
;
1385 entry
.templatePath
= filePath
;
1386 m_createFileTemplates
.insert(key
, entry
);
1391 m_createFileTemplates
.sort();
1393 unplugActionList("create_actions");
1394 KSortableList
<CreateFileEntry
, QString
>::ConstIterator it
= m_createFileTemplates
.begin();
1395 KSortableList
<CreateFileEntry
, QString
>::ConstIterator end
= m_createFileTemplates
.end();
1396 /* KDE4-TODO: don't port this code; use KNewMenu instead
1398 CreateFileEntry entry = (*it).value();
1399 KAction* action = new KAction(entry.name);
1400 action->setIcon(entry.icon);
1401 action->setName((*it).index());
1402 connect(action, SIGNAL(activated()),
1403 this, SLOT(createFile()));
1405 const QChar section = ((*it).index()[0]);
1409 m_fileGroupActions.append(action);
1415 // TODO: not used yet. See documentation of DolphinMainWindow::linkGroupActions()
1416 // and DolphinMainWindow::linkToDeviceActions() in the header file for details.
1417 //m_linkGroupActions.append(action);
1422 // TODO: not used yet. See documentation of DolphinMainWindow::linkGroupActions()
1423 // and DolphinMainWindow::linkToDeviceActions() in the header file for details.
1424 //m_linkToDeviceActions.append(action);
1433 plugActionList("create_file_group", m_fileGroupActions);
1434 //plugActionList("create_link_group", m_linkGroupActions);
1435 //plugActionList("link_to_device", m_linkToDeviceActions);*/
1438 void DolphinMainWindow::updateHistory()
1441 const Q3ValueList
<UrlNavigator::HistoryElem
> list
= m_activeView
->urlHistory(index
);
1443 QAction
* backAction
= actionCollection()->action("go_back");
1444 if (backAction
!= 0) {
1445 backAction
->setEnabled(index
< static_cast<int>(list
.count()) - 1);
1448 QAction
* forwardAction
= actionCollection()->action("go_forward");
1449 if (forwardAction
!= 0) {
1450 forwardAction
->setEnabled(index
> 0);
1454 void DolphinMainWindow::updateEditActions()
1456 const KFileItemList list
= m_activeView
->selectedItems();
1457 if (list
.isEmpty()) {
1458 stateChanged("has_no_selection");
1461 stateChanged("has_selection");
1463 QAction
* renameAction
= actionCollection()->action("rename");
1464 if (renameAction
!= 0) {
1465 renameAction
->setEnabled(list
.count() >= 1);
1468 bool enableMoveToTrash
= true;
1470 KFileItemList::const_iterator it
= list
.begin();
1471 const KFileItemList::const_iterator end
= list
.end();
1473 KFileItem
* item
= *it
;
1474 const KUrl
& url
= item
->url();
1475 // only enable the 'Move to Trash' action for local files
1476 if (!url
.isLocalFile()) {
1477 enableMoveToTrash
= false;
1482 QAction
* moveToTrashAction
= actionCollection()->action("move_to_trash");
1483 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1485 updatePasteAction();
1488 void DolphinMainWindow::updateViewActions()
1490 QAction
* zoomInAction
= actionCollection()->action(KStdAction::stdName(KStdAction::ZoomIn
));
1491 if (zoomInAction
!= 0) {
1492 zoomInAction
->setEnabled(m_activeView
->isZoomInPossible());
1495 QAction
* zoomOutAction
= actionCollection()->action(KStdAction::stdName(KStdAction::ZoomOut
));
1496 if (zoomOutAction
!= 0) {
1497 zoomOutAction
->setEnabled(m_activeView
->isZoomOutPossible());
1500 QAction
* action
= 0;
1501 switch (m_activeView
->mode()) {
1502 case DolphinView::IconsView
:
1503 action
= actionCollection()->action("icons");
1505 case DolphinView::DetailsView
:
1506 action
= actionCollection()->action("details");
1508 //case DolphinView::PreviewsView:
1509 // action = actionCollection()->action("previews");
1516 KToggleAction
* toggleAction
= static_cast<KToggleAction
*>(action
);
1517 toggleAction
->setChecked(true);
1520 slotSortingChanged(m_activeView
->sorting());
1521 slotSortOrderChanged(m_activeView
->sortOrder());
1523 KToggleAction
* showFilterBarAction
=
1524 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
1525 showFilterBarAction
->setChecked(m_activeView
->isFilterBarVisible());
1527 KToggleAction
* showHiddenFilesAction
=
1528 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
1529 showHiddenFilesAction
->setChecked(m_activeView
->showHiddenFiles());
1531 KToggleAction
* splitAction
= static_cast<KToggleAction
*>(actionCollection()->action("split_view"));
1532 splitAction
->setChecked(m_view
[SecondaryIdx
] != 0);
1535 void DolphinMainWindow::updateGoActions()
1537 QAction
* goUpAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Up
));
1538 const KUrl
& currentUrl
= m_activeView
->url();
1539 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1542 void DolphinMainWindow::updateViewProperties(const KUrl::List
& urls
)
1544 if (urls
.isEmpty()) {
1548 // Updating the view properties might take up to several seconds
1549 // when dragging several thousand Urls. Writing a KIO slave for this
1550 // use case is not worth the effort, but at least the main widget
1551 // must be disabled and a progress should be shown.
1552 ProgressIndicator
progressIndicator(this,
1553 i18n("Updating view properties..."),
1557 KUrl::List::ConstIterator end
= urls
.end();
1558 for(KUrl::List::ConstIterator it
= urls
.begin(); it
!= end
; ++it
) {
1559 progressIndicator
.execOperation();
1561 ViewProperties
props(*it
);
1566 void DolphinMainWindow::copyUrls(const KUrl::List
& source
, const KUrl
& dest
)
1568 KIO::Job
* job
= KIO::copy(source
, dest
);
1569 addPendingUndoJob(job
, DolphinCommand::Copy
, source
, dest
);
1572 void DolphinMainWindow::moveUrls(const KUrl::List
& source
, const KUrl
& dest
)
1574 KIO::Job
* job
= KIO::move(source
, dest
);
1575 addPendingUndoJob(job
, DolphinCommand::Move
, source
, dest
);
1578 void DolphinMainWindow::addPendingUndoJob(KIO::Job
* job
,
1579 DolphinCommand::Type commandType
,
1580 const KUrl::List
& source
,
1583 connect(job
, SIGNAL(result(KJob
*)),
1584 this, SLOT(addUndoOperation(KJob
*)));
1587 undoInfo
.id
= job
->progressId();
1588 undoInfo
.command
= DolphinCommand(commandType
, source
, dest
);
1589 m_pendingUndoJobs
.append(undoInfo
);
1592 void DolphinMainWindow::clearStatusBar()
1594 m_activeView
->statusBar()->clear();
1597 void DolphinMainWindow::connectViewSignals(int viewIndex
)
1599 DolphinView
* view
= m_view
[viewIndex
];
1600 connect(view
, SIGNAL(modeChanged()),
1601 this, SLOT(slotViewModeChanged()));
1602 connect(view
, SIGNAL(showHiddenFilesChanged()),
1603 this, SLOT(slotShowHiddenFilesChanged()));
1604 connect(view
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
1605 this, SLOT(slotSortingChanged(DolphinView::Sorting
)));
1606 connect(view
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
1607 this, SLOT(slotSortOrderChanged(Qt::SortOrder
)));
1608 connect(view
, SIGNAL(selectionChanged()),
1609 this, SLOT(slotSelectionChanged()));
1610 connect(view
, SIGNAL(showFilterBarChanged(bool)),
1611 this, SLOT(updateFilterBarAction(bool)));
1613 const UrlNavigator
* navigator
= view
->urlNavigator();
1614 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1615 this, SLOT(slotUrlChanged(const KUrl
&)));
1616 connect(navigator
, SIGNAL(historyChanged()),
1617 this, SLOT(slotHistoryChanged()));
1621 #include "dolphinmainwindow.moc"