]>
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/renamedlg.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 int selectedIndex
= -1;
122 const ButtonState keyboardState = KApplication::keyboardMouseState();
123 const bool shiftPressed = (keyboardState & ShiftButton) > 0;
124 const bool controlPressed = (keyboardState & ControlButton) > 0;
128 if (shiftPressed && controlPressed) {
129 // shortcut for 'Linke Here' is used
132 else if (controlPressed) {
133 // shortcut for 'Copy Here' is used
136 else if (shiftPressed) {
137 // shortcut for 'Move Here' is used
141 // no shortcut is used, hence open a popup menu
144 popup
.insertItem(SmallIcon("goto"), i18n("&Move Here") + "\t" /* KDE4-TODO: + KKey::modFlagLabel(KKey::SHIFT)*/, 0);
145 popup
.insertItem(SmallIcon("editcopy"), i18n( "&Copy Here" ) /* KDE4-TODO + "\t" + KKey::modFlagLabel(KKey::CTRL)*/, 1);
146 popup
.insertItem(i18n("&Link Here") /* KDE4-TODO + "\t" + KKey::modFlagLabel((KKey::ModFlag)(KKey::CTRL|KKey::SHIFT)) */, 2);
147 popup
.insertSeparator();
148 popup
.insertItem(SmallIcon("stop"), i18n("Cancel"), 3);
149 popup
.setAccel(i18n("Escape"), 3);
151 /* KDE4-TODO: selectedIndex = popup.exec(QCursor::pos()); */
152 popup
.exec(QCursor::pos());
153 selectedIndex
= 0; // KD4-TODO: use QAction instead of switch below
154 // See libkonq/konq_operations.cc: KonqOperations::doDropFileCopy() (and doDrop, the main method)
157 if (selectedIndex
< 0) {
161 switch (selectedIndex
) {
163 // 'Move Here' has been selected
164 updateViewProperties(urls
);
165 moveUrls(urls
, destination
);
170 // 'Copy Here' has been selected
171 updateViewProperties(urls
);
172 copyUrls(urls
, destination
);
177 // 'Link Here' has been selected
178 KIO::Job
* job
= KIO::link(urls
, destination
);
179 addPendingUndoJob(job
, DolphinCommand::Link
, urls
, destination
);
184 // 'Cancel' has been selected
189 void DolphinMainWindow::refreshViews()
191 const bool split
= DolphinSettings::instance().generalSettings()->splitView();
192 const bool isPrimaryViewActive
= (m_activeView
== m_view
[PrimaryIdx
]);
194 for (int i
= PrimaryIdx
; i
<= SecondaryIdx
; ++i
) {
195 if (m_view
[i
] != 0) {
196 url
= m_view
[i
]->url();
198 // delete view instance...
200 m_view
[i
]->deleteLater();
204 if (split
|| (i
== PrimaryIdx
)) {
205 // ... and recreate it
206 ViewProperties
props(url
);
207 m_view
[i
] = new DolphinView(this,
211 props
.showHiddenFiles());
212 connectViewSignals(i
);
217 m_activeView
= isPrimaryViewActive
? m_view
[PrimaryIdx
] : m_view
[SecondaryIdx
];
218 assert(m_activeView
!= 0);
221 emit
activeViewChanged();
224 void DolphinMainWindow::slotViewModeChanged()
229 void DolphinMainWindow::slotShowHiddenFilesChanged()
231 KToggleAction
* showHiddenFilesAction
=
232 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
233 showHiddenFilesAction
->setChecked(m_activeView
->showHiddenFiles());
236 void DolphinMainWindow::slotSortingChanged(DolphinView::Sorting sorting
)
240 case DolphinView::SortByName
:
241 action
= actionCollection()->action("by_name");
243 case DolphinView::SortBySize
:
244 action
= actionCollection()->action("by_size");
246 case DolphinView::SortByDate
:
247 action
= actionCollection()->action("by_date");
254 KToggleAction
* toggleAction
= static_cast<KToggleAction
*>(action
);
255 toggleAction
->setChecked(true);
259 void DolphinMainWindow::slotSortOrderChanged(Qt::SortOrder order
)
261 KToggleAction
* descending
= static_cast<KToggleAction
*>(actionCollection()->action("descending"));
262 const bool sortDescending
= (order
== Qt::Descending
);
263 descending
->setChecked(sortDescending
);
266 void DolphinMainWindow::slotSelectionChanged()
270 assert(m_view
[PrimaryIdx
] != 0);
271 int selectedUrlsCount
= m_view
[PrimaryIdx
]->selectedUrls().count();
272 if (m_view
[SecondaryIdx
] != 0) {
273 selectedUrlsCount
+= m_view
[SecondaryIdx
]->selectedUrls().count();
276 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
277 compareFilesAction
->setEnabled(selectedUrlsCount
== 2);
279 m_activeView
->updateStatusBar();
281 emit
selectionChanged();
284 void DolphinMainWindow::slotHistoryChanged()
289 void DolphinMainWindow::slotUrlChanged(const KUrl
& url
)
293 setCaption(url
.fileName());
296 void DolphinMainWindow::updateFilterBarAction(bool show
)
298 KToggleAction
* showFilterBarAction
=
299 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
300 showFilterBarAction
->setChecked(show
);
303 void DolphinMainWindow::redo()
305 UndoManager::instance().redo(this);
308 void DolphinMainWindow::undo()
310 UndoManager::instance().undo(this);
313 void DolphinMainWindow::openNewMainWindow()
315 DolphinApplication::app()->createMainWindow()->show();
318 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
321 //KConfig* config = KGlobal::config();
322 //config->setGroup("General");
323 //config->writeEntry("First Run", false);
325 DolphinSettings
& settings
= DolphinSettings::instance();
326 GeneralSettings
* generalSettings
= settings
.generalSettings();
327 generalSettings
->setFirstRun(false);
331 KMainWindow::closeEvent(event
);
334 void DolphinMainWindow::saveProperties(KConfig
* config
)
336 config
->setGroup("Primary view");
337 config
->writeEntry("Url", m_view
[PrimaryIdx
]->url().url());
338 config
->writeEntry("Editable Url", m_view
[PrimaryIdx
]->isUrlEditable());
339 if (m_view
[SecondaryIdx
] != 0) {
340 config
->setGroup("Secondary view");
341 config
->writeEntry("Url", m_view
[SecondaryIdx
]->url().url());
342 config
->writeEntry("Editable Url", m_view
[SecondaryIdx
]->isUrlEditable());
346 void DolphinMainWindow::readProperties(KConfig
* config
)
348 config
->setGroup("Primary view");
349 m_view
[PrimaryIdx
]->setUrl(config
->readEntry("Url"));
350 m_view
[PrimaryIdx
]->setUrlEditable(config
->readEntry("Editable Url", false));
351 if (config
->hasGroup("Secondary view")) {
352 config
->setGroup("Secondary view");
353 if (m_view
[SecondaryIdx
] == 0) {
356 m_view
[SecondaryIdx
]->setUrl(config
->readEntry("Url"));
357 m_view
[SecondaryIdx
]->setUrlEditable(config
->readEntry("Editable Url", false));
359 else if (m_view
[SecondaryIdx
] != 0) {
364 void DolphinMainWindow::createFolder()
366 // Parts of the following code have been taken
367 // from the class KonqPopupMenu located in
368 // libqonq/konq_popupmenu.h of Konqueror.
369 // (Copyright (C) 2000 David Faure <faure@kde.org>,
370 // Copyright (C) 2001 Holger Freyther <freyther@yahoo.com>)
374 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
375 const KUrl
baseUrl(m_activeView
->url());
377 QString
name(i18n("New Folder"));
378 baseUrl
.path(KUrl::AddTrailingSlash
);
381 if (baseUrl
.isLocalFile() && QFileInfo(baseUrl
.path(KUrl::AddTrailingSlash
) + name
).exists()) {
382 name
= KIO::RenameDlg::suggestName(baseUrl
, i18n("New Folder"));
386 name
= KInputDialog::getText(i18n("New Folder"),
387 i18n("Enter folder name:" ),
393 // the user has pressed 'Cancel'
397 assert(!name
.isEmpty());
400 if ((name
[0] == '/') || (name
[0] == '~')) {
401 url
.setPath(KShell::tildeExpand(name
));
404 name
= KIO::encodeFileName(name
);
408 ok
= KIO::NetAccess::mkdir(url
, this);
410 // TODO: provide message type hint
412 statusBar
->setMessage(i18n("Created folder %1.",url
.path()),
413 DolphinStatusBar::OperationCompleted
);
415 DolphinCommand
command(DolphinCommand::CreateFolder
, KUrl::List(), url
);
416 UndoManager::instance().addCommand(command
);
419 // Creating of the folder has been failed. Check whether the creating
420 // has been failed because a folder with the same name exists...
421 if (KIO::NetAccess::exists(url
, true, this)) {
422 statusBar
->setMessage(i18n("A folder named %1 already exists.",url
.path()),
423 DolphinStatusBar::Error
);
426 statusBar
->setMessage(i18n("Creating of folder %1 failed.",url
.path()),
427 DolphinStatusBar::Error
);
433 void DolphinMainWindow::createFile()
435 // Parts of the following code have been taken
436 // from the class KonqPopupMenu located in
437 // libqonq/konq_popupmenu.h of Konqueror.
438 // (Copyright (C) 2000 David Faure <faure@kde.org>,
439 // Copyright (C) 2001 Holger Freyther <freyther@yahoo.com>)
443 // TODO: const Entry& entry = m_createFileTemplates[QString(sender->name())];
444 // should be enough. Anyway: the implemantation of [] does a linear search internally too.
445 KSortableList
<CreateFileEntry
, QString
>::ConstIterator it
= m_createFileTemplates
.begin();
446 KSortableList
<CreateFileEntry
, QString
>::ConstIterator end
= m_createFileTemplates
.end();
448 const QString
senderName(sender()->objectName());
450 CreateFileEntry entry
;
451 while (!found
&& (it
!= end
)) {
452 if ((*it
).key() == senderName
) {
453 entry
= (*it
).value();
461 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
462 if (!found
|| !QFile::exists(entry
.templatePath
)) {
463 statusBar
->setMessage(i18n("Could not create file."), DolphinStatusBar::Error
);
467 // Get the source path of the template which should be copied.
468 // The source path is part of the Url entry of the desktop file.
469 const int pos
= entry
.templatePath
.lastIndexOf('/');
470 QString
sourcePath(entry
.templatePath
.left(pos
+ 1));
471 sourcePath
+= KDesktopFile(entry
.templatePath
, true).readPathEntry("Url");
473 QString
name(i18n(entry
.name
.toAscii()));
474 // Most entry names end with "..." (e. g. "HTML File..."), which is ok for
475 // menus but no good choice for a new file name -> remove the dots...
476 name
.replace("...", QString::null
);
478 // add the file extension to the name
479 name
.append(sourcePath
.right(sourcePath
.length() - sourcePath
.lastIndexOf('.')));
481 // Check whether a file with the current name already exists. If yes suggest automatically
482 // a unique file name (e. g. "HTML File" will be replaced by "HTML File_1").
483 const KUrl
viewUrl(m_activeView
->url());
484 const bool fileExists
= viewUrl
.isLocalFile() &&
485 QFileInfo(viewUrl
.path(KUrl::AddTrailingSlash
) + KIO::encodeFileName(name
)).exists();
487 name
= KIO::RenameDlg::suggestName(viewUrl
, name
);
490 // let the user change the suggested file name
492 name
= KInputDialog::getText(entry
.name
,
498 // the user has pressed 'Cancel'
502 // before copying the template to the destination path check whether a file
503 // with the given name already exists
504 const QString
destPath(viewUrl
.pathOrUrl() + "/" + KIO::encodeFileName(name
));
505 const KUrl
destUrl(destPath
);
506 if (KIO::NetAccess::exists(destUrl
, false, this)) {
507 statusBar
->setMessage(i18n("A file named %1 already exists.",name
),
508 DolphinStatusBar::Error
);
512 // copy the template to the destination path
513 const KUrl
sourceUrl(sourcePath
);
514 KIO::CopyJob
* job
= KIO::copyAs(sourceUrl
, destUrl
);
515 job
->setDefaultPermissions(true);
516 if (KIO::NetAccess::synchronousRun(job
, this)) {
517 statusBar
->setMessage(i18n("Created file %1.",name
),
518 DolphinStatusBar::OperationCompleted
);
521 list
.append(sourceUrl
);
522 DolphinCommand
command(DolphinCommand::CreateFile
, list
, destUrl
);
523 UndoManager::instance().addCommand(command
);
527 statusBar
->setMessage(i18n("Creating of file %1 failed.",name
),
528 DolphinStatusBar::Error
);
532 void DolphinMainWindow::rename()
535 m_activeView
->renameSelectedItems();
538 void DolphinMainWindow::moveToTrash()
541 KUrl::List selectedUrls
= m_activeView
->selectedUrls();
542 KIO::Job
* job
= KIO::trash(selectedUrls
);
543 addPendingUndoJob(job
, DolphinCommand::Trash
, selectedUrls
, m_activeView
->url());
546 void DolphinMainWindow::deleteItems()
550 KUrl::List list
= m_activeView
->selectedUrls();
551 const uint itemCount
= list
.count();
552 assert(itemCount
>= 1);
556 text
= i18n("Do you really want to delete the %1 selected items?",itemCount
);
559 const KUrl
& url
= list
.first();
560 text
= i18n("Do you really want to delete '%1'?",url
.fileName());
563 const bool del
= KMessageBox::warningContinueCancel(this,
566 KGuiItem(i18n("Delete"), KIcon("editdelete"))
567 ) == KMessageBox::Continue
;
569 KIO::Job
* job
= KIO::del(list
);
570 connect(job
, SIGNAL(result(KJob
*)),
571 this, SLOT(slotHandleJobError(KJob
*)));
572 connect(job
, SIGNAL(result(KJob
*)),
573 this, SLOT(slotDeleteFileFinished(KJob
*)));
577 void DolphinMainWindow::properties()
579 const KFileItemList list
= m_activeView
->selectedItems();
580 new KPropertiesDialog(list
, this);
583 void DolphinMainWindow::quit()
588 void DolphinMainWindow::slotHandleJobError(KJob
* job
)
590 if (job
->error() != 0) {
591 m_activeView
->statusBar()->setMessage(job
->errorString(),
592 DolphinStatusBar::Error
);
596 void DolphinMainWindow::slotDeleteFileFinished(KJob
* job
)
598 if (job
->error() == 0) {
599 m_activeView
->statusBar()->setMessage(i18n("Delete operation completed."),
600 DolphinStatusBar::OperationCompleted
);
602 // TODO: In opposite to the 'Move to Trash' operation in the class KFileIconView
603 // no rearranging of the item position is done when a file has been deleted.
604 // This is bypassed by reloading the view, but it might be worth to investigate
605 // deeper for the root of this issue.
606 m_activeView
->reload();
610 void DolphinMainWindow::slotUndoAvailable(bool available
)
612 QAction
* undoAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::Undo
));
613 if (undoAction
!= 0) {
614 undoAction
->setEnabled(available
);
618 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
620 QAction
* undoAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::Undo
));
621 if (undoAction
!= 0) {
622 undoAction
->setText(text
);
626 void DolphinMainWindow::slotRedoAvailable(bool available
)
628 QAction
* redoAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::Redo
));
629 if (redoAction
!= 0) {
630 redoAction
->setEnabled(available
);
634 void DolphinMainWindow::slotRedoTextChanged(const QString
& text
)
636 QAction
* redoAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::Redo
));
637 if (redoAction
!= 0) {
638 redoAction
->setText(text
);
642 void DolphinMainWindow::cut()
644 QMimeData
* mimeData
= new QMimeData();
645 const KUrl::List kdeUrls
= m_activeView
->selectedUrls();
646 const KUrl::List mostLocalUrls
;
647 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, true);
648 QApplication::clipboard()->setMimeData(mimeData
);
651 void DolphinMainWindow::copy()
653 QMimeData
* mimeData
= new QMimeData();
654 const KUrl::List kdeUrls
= m_activeView
->selectedUrls();
655 const KUrl::List mostLocalUrls
;
656 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, false);
658 QApplication::clipboard()->setMimeData(mimeData
);
661 void DolphinMainWindow::paste()
663 QClipboard
* clipboard
= QApplication::clipboard();
664 const QMimeData
* mimeData
= clipboard
->mimeData();
668 const KUrl::List sourceUrls
= KUrl::List::fromMimeData(mimeData
);
670 // per default the pasting is done into the current Url of the view
671 KUrl
destUrl(m_activeView
->url());
673 // check whether the pasting should be done into a selected directory
674 KUrl::List selectedUrls
= m_activeView
->selectedUrls();
675 if (selectedUrls
.count() == 1) {
676 const KFileItem
fileItem(S_IFDIR
,
678 selectedUrls
.first(),
680 if (fileItem
.isDir()) {
681 // only one item is selected which is a directory, hence paste
682 // into this directory
683 destUrl
= selectedUrls
.first();
687 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
688 moveUrls(sourceUrls
, destUrl
);
692 copyUrls(sourceUrls
, destUrl
);
696 void DolphinMainWindow::updatePasteAction()
698 QAction
* pasteAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::Paste
));
699 if (pasteAction
== 0) {
703 QString
text(i18n("Paste"));
704 QClipboard
* clipboard
= QApplication::clipboard();
705 const QMimeData
* mimeData
= clipboard
->mimeData();
707 KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
708 if (!urls
.isEmpty()) {
709 pasteAction
->setEnabled(true);
711 const int count
= urls
.count();
713 pasteAction
->setText(i18n("Paste 1 File"));
716 pasteAction
->setText(i18n("Paste %1 Files").arg(count
));
720 pasteAction
->setEnabled(false);
721 pasteAction
->setText(i18n("Paste"));
724 if (pasteAction
->isEnabled()) {
725 KUrl::List urls
= m_activeView
->selectedUrls();
726 const uint count
= urls
.count();
728 // pasting should not be allowed when more than one file
730 pasteAction
->setEnabled(false);
732 else if (count
== 1) {
733 // Only one file is selected. Pasting is only allowed if this
734 // file is a directory.
735 // TODO: this doesn't work with remote protocols; instead we need a
736 // m_activeView->selectedFileItems() to get the real KFileItems
737 const KFileItem
fileItem(S_IFDIR
,
741 pasteAction
->setEnabled(fileItem
.isDir());
746 void DolphinMainWindow::selectAll()
749 m_activeView
->selectAll();
752 void DolphinMainWindow::invertSelection()
755 m_activeView
->invertSelection();
757 void DolphinMainWindow::setIconsView()
759 m_activeView
->setMode(DolphinView::IconsView
);
762 void DolphinMainWindow::setDetailsView()
764 m_activeView
->setMode(DolphinView::DetailsView
);
767 void DolphinMainWindow::sortByName()
769 m_activeView
->setSorting(DolphinView::SortByName
);
772 void DolphinMainWindow::sortBySize()
774 m_activeView
->setSorting(DolphinView::SortBySize
);
777 void DolphinMainWindow::sortByDate()
779 m_activeView
->setSorting(DolphinView::SortByDate
);
782 void DolphinMainWindow::toggleSortOrder()
784 const Qt::SortOrder order
= (m_activeView
->sortOrder() == Qt::Ascending
) ?
787 m_activeView
->setSortOrder(order
);
790 void DolphinMainWindow::toggleSplitView()
792 if (m_view
[SecondaryIdx
] == 0) {
793 const int newWidth
= (m_view
[PrimaryIdx
]->width() - m_splitter
->handleWidth()) / 2;
794 // create a secondary view
795 m_view
[SecondaryIdx
] = new DolphinView(this,
797 m_view
[PrimaryIdx
]->url(),
798 m_view
[PrimaryIdx
]->mode(),
799 m_view
[PrimaryIdx
]->showHiddenFiles());
800 connectViewSignals(SecondaryIdx
);
801 m_splitter
->addWidget(m_view
[SecondaryIdx
]);
802 m_splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
803 m_view
[SecondaryIdx
]->show();
806 // remove secondary view
807 if (m_activeView
== m_view
[PrimaryIdx
]) {
808 m_view
[SecondaryIdx
]->close();
809 m_view
[SecondaryIdx
]->deleteLater();
810 m_view
[SecondaryIdx
] = 0;
811 setActiveView(m_view
[PrimaryIdx
]);
814 // The secondary view is active, hence from the users point of view
815 // the content of the secondary view should be moved to the primary view.
816 // From an implementation point of view it is more efficient to close
817 // the primary view and exchange the internal pointers afterwards.
818 m_view
[PrimaryIdx
]->close();
819 delete m_view
[PrimaryIdx
];
820 m_view
[PrimaryIdx
] = m_view
[SecondaryIdx
];
821 m_view
[SecondaryIdx
] = 0;
822 setActiveView(m_view
[PrimaryIdx
]);
827 void DolphinMainWindow::reloadView()
830 m_activeView
->reload();
833 void DolphinMainWindow::stopLoading()
837 void DolphinMainWindow::togglePreview()
841 const KToggleAction
* showPreviewAction
=
842 static_cast<KToggleAction
*>(actionCollection()->action("show_preview"));
843 const bool show
= showPreviewAction
->isChecked();
844 m_activeView
->setShowPreview(show
);
847 void DolphinMainWindow::toggleShowHiddenFiles()
851 const KToggleAction
* showHiddenFilesAction
=
852 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
853 const bool show
= showHiddenFilesAction
->isChecked();
854 m_activeView
->setShowHiddenFiles(show
);
857 void DolphinMainWindow::showFilterBar()
859 const KToggleAction
* showFilterBarAction
=
860 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
861 const bool show
= showFilterBarAction
->isChecked();
862 m_activeView
->slotShowFilterBar(show
);
865 void DolphinMainWindow::zoomIn()
867 m_activeView
->zoomIn();
871 void DolphinMainWindow::zoomOut()
873 m_activeView
->zoomOut();
877 void DolphinMainWindow::toggleEditLocation()
881 KToggleAction
* action
= static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
883 bool editOrBrowse
= action
->isChecked();
884 // action->setChecked(action->setChecked);
885 m_activeView
->setUrlEditable(editOrBrowse
);
888 void DolphinMainWindow::editLocation()
890 KToggleAction
* action
= static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
891 action
->setChecked(true);
892 m_activeView
->setUrlEditable(true);
895 void DolphinMainWindow::adjustViewProperties()
898 ViewPropertiesDialog
dlg(m_activeView
);
902 void DolphinMainWindow::goBack()
905 m_activeView
->goBack();
908 void DolphinMainWindow::goForward()
911 m_activeView
->goForward();
914 void DolphinMainWindow::goUp()
917 m_activeView
->goUp();
920 void DolphinMainWindow::goHome()
923 m_activeView
->goHome();
926 void DolphinMainWindow::openTerminal()
928 QString
command("konsole --workdir \"");
929 command
.append(m_activeView
->url().path());
930 command
.append('\"');
932 KRun::runCommand(command
, "Konsole", "konsole");
935 void DolphinMainWindow::findFile()
937 KRun::run("kfind", m_activeView
->url());
940 void DolphinMainWindow::compareFiles()
942 // The method is only invoked if exactly 2 files have
943 // been selected. The selected files may be:
944 // - both in the primary view
945 // - both in the secondary view
946 // - one in the primary view and the other in the secondary
948 assert(m_view
[PrimaryIdx
] != 0);
952 KUrl::List urls
= m_view
[PrimaryIdx
]->selectedUrls();
954 switch (urls
.count()) {
956 assert(m_view
[SecondaryIdx
] != 0);
957 urls
= m_view
[SecondaryIdx
]->selectedUrls();
958 assert(urls
.count() == 2);
966 assert(m_view
[SecondaryIdx
] != 0);
967 urls
= m_view
[SecondaryIdx
]->selectedUrls();
968 assert(urls
.count() == 1);
980 // may not happen: compareFiles may only get invoked if 2
981 // files are selected
986 QString
command("kompare -c \"");
987 command
.append(urlA
.pathOrUrl());
988 command
.append("\" \"");
989 command
.append(urlB
.pathOrUrl());
990 command
.append('\"');
991 KRun::runCommand(command
, "Kompare", "kompare");
995 void DolphinMainWindow::editSettings()
997 // TODO: make a static method for opening the settings dialog
998 DolphinSettingsDialog
dlg(this);
1002 void DolphinMainWindow::addUndoOperation(KJob
* job
)
1004 if (job
->error() != 0) {
1005 slotHandleJobError(job
);
1008 const int id
= job
->progressId();
1010 // set iterator to the executed command with the current id...
1011 Q3ValueList
<UndoInfo
>::Iterator it
= m_pendingUndoJobs
.begin();
1012 const Q3ValueList
<UndoInfo
>::Iterator end
= m_pendingUndoJobs
.end();
1014 while (!found
&& (it
!= end
)) {
1015 if ((*it
).id
== id
) {
1024 DolphinCommand command
= (*it
).command
;
1025 if (command
.type() == DolphinCommand::Trash
) {
1026 // To be able to perform an undo for the 'Move to Trash' operation
1027 // all source Urls must be updated with the trash Url. E. g. when moving
1028 // a file "test.txt" and a second file "test.txt" to the trash,
1029 // then the filenames in the trash are "0-test.txt" and "1-test.txt".
1030 QMap
<QString
, QString
> metaData
;
1031 KIO::Job
*kiojob
= qobject_cast
<KIO::Job
*>( job
);
1034 metaData
= kiojob
->metaData();
1036 KUrl::List newSourceUrls
;
1038 KUrl::List sourceUrls
= command
.source();
1039 KUrl::List::Iterator sourceIt
= sourceUrls
.begin();
1040 const KUrl::List::Iterator sourceEnd
= sourceUrls
.end();
1042 while (sourceIt
!= sourceEnd
) {
1043 QMap
<QString
, QString
>::ConstIterator metaIt
= metaData
.find("trashUrl-" + (*sourceIt
).path());
1044 if (metaIt
!= metaData
.end()) {
1045 newSourceUrls
.append(KUrl(metaIt
.value()));
1049 command
.setSource(newSourceUrls
);
1052 UndoManager::instance().addCommand(command
);
1053 m_pendingUndoJobs
.erase(it
);
1055 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
1056 switch (command
.type()) {
1057 case DolphinCommand::Copy
:
1058 statusBar
->setMessage(i18n("Copy operation completed."),
1059 DolphinStatusBar::OperationCompleted
);
1061 case DolphinCommand::Move
:
1062 statusBar
->setMessage(i18n("Move operation completed."),
1063 DolphinStatusBar::OperationCompleted
);
1065 case DolphinCommand::Trash
:
1066 statusBar
->setMessage(i18n("Move to trash operation completed."),
1067 DolphinStatusBar::OperationCompleted
);
1076 void DolphinMainWindow::init()
1078 // Check whether Dolphin runs the first time. If yes then
1079 // a proper default window size is given at the end of DolphinMainWindow::init().
1080 GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
1081 const bool firstRun
= generalSettings
->firstRun();
1083 setAcceptDrops(true);
1085 m_splitter
= new QSplitter(this);
1087 DolphinSettings
& settings
= DolphinSettings::instance();
1089 KBookmarkManager
* manager
= settings
.bookmarkManager();
1090 assert(manager
!= 0);
1091 KBookmarkGroup root
= manager
->root();
1092 if (root
.first().isNull()) {
1093 root
.addBookmark(manager
, i18n("Home"), settings
.generalSettings()->homeUrl(), "folder_home");
1094 root
.addBookmark(manager
, i18n("Storage Media"), KUrl("media:/"), "blockdevice");
1095 root
.addBookmark(manager
, i18n("Network"), KUrl("remote:/"), "network_local");
1096 root
.addBookmark(manager
, i18n("Root"), KUrl("/"), "folder_red");
1097 root
.addBookmark(manager
, i18n("Trash"), KUrl("trash:/"), "trashcan_full");
1102 const KUrl
& homeUrl
= root
.first().url();
1103 setCaption(homeUrl
.fileName());
1104 ViewProperties
props(homeUrl
);
1105 m_view
[PrimaryIdx
] = new DolphinView(this,
1109 props
.showHiddenFiles());
1110 connectViewSignals(PrimaryIdx
);
1111 m_view
[PrimaryIdx
]->show();
1113 m_activeView
= m_view
[PrimaryIdx
];
1115 setCentralWidget(m_splitter
);
1118 setupGUI(Keys
|Save
|Create
|ToolBar
);
1121 stateChanged("new_file");
1122 setAutoSaveSettings();
1124 QClipboard
* clipboard
= QApplication::clipboard();
1125 connect(clipboard
, SIGNAL(dataChanged()),
1126 this, SLOT(updatePasteAction()));
1127 updatePasteAction();
1130 setupCreateNewMenuActions();
1135 // assure a proper default size if Dolphin runs the first time
1140 void DolphinMainWindow::loadSettings()
1142 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
1144 KToggleAction
* splitAction
= static_cast<KToggleAction
*>(actionCollection()->action("split_view"));
1145 if (settings
->splitView()) {
1146 splitAction
->setChecked(true);
1150 updateViewActions();
1153 void DolphinMainWindow::setupActions()
1155 // setup 'File' menu
1156 KAction
*action
= new KAction(KIcon("window_new"), i18n( "New &Window" ), actionCollection(), "new_window" );
1157 connect(action
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1159 KAction
* createFolder
= new KAction(i18n("Folder..."), actionCollection(), "create_folder");
1160 createFolder
->setIcon(KIcon("folder"));
1161 createFolder
->setShortcut(Qt::Key_N
);
1162 connect(createFolder
, SIGNAL(triggered()), this, SLOT(createFolder()));
1164 KAction
* rename
= new KAction(i18n("Rename"), actionCollection(), "rename");
1165 rename
->setShortcut(Qt::Key_F2
);
1166 connect(rename
, SIGNAL(triggered()), this, SLOT(rename()));
1168 KAction
* moveToTrash
= new KAction(i18n("Move to Trash"), actionCollection(), "move_to_trash");
1169 moveToTrash
->setIcon(KIcon("edittrash"));
1170 moveToTrash
->setShortcut(QKeySequence::Delete
);
1171 connect(moveToTrash
, SIGNAL(triggered()), this, SLOT(moveToTrash()));
1173 KAction
* deleteAction
= new KAction(i18n("Delete"), actionCollection(), "delete");
1174 deleteAction
->setShortcut(Qt::ALT
| Qt::Key_Delete
);
1175 deleteAction
->setIcon(KIcon("editdelete"));
1176 connect(deleteAction
, SIGNAL(triggered()), this, SLOT(deleteItems()));
1178 KAction
* properties
= new KAction(i18n("Propert&ies"), actionCollection(), "properties");
1179 properties
->setShortcut(Qt::Key_Alt
| Qt::Key_Return
);
1180 connect(properties
, SIGNAL(triggered()), this, SLOT(properties()));
1182 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1184 // setup 'Edit' menu
1185 UndoManager
& undoManager
= UndoManager::instance();
1186 KStandardAction::undo(this,
1188 actionCollection());
1189 connect(&undoManager
, SIGNAL(undoAvailable(bool)),
1190 this, SLOT(slotUndoAvailable(bool)));
1191 connect(&undoManager
, SIGNAL(undoTextChanged(const QString
&)),
1192 this, SLOT(slotUndoTextChanged(const QString
&)));
1194 KStandardAction::redo(this,
1196 actionCollection());
1197 connect(&undoManager
, SIGNAL(redoAvailable(bool)),
1198 this, SLOT(slotRedoAvailable(bool)));
1199 connect(&undoManager
, SIGNAL(redoTextChanged(const QString
&)),
1200 this, SLOT(slotRedoTextChanged(const QString
&)));
1202 KStandardAction::cut(this, SLOT(cut()), actionCollection());
1203 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1204 KStandardAction::paste(this, SLOT(paste()), actionCollection());
1206 KAction
* selectAll
= new KAction(i18n("Select All"), actionCollection(), "select_all");
1207 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1208 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1210 KAction
* invertSelection
= new KAction(i18n("Invert Selection"), actionCollection(), "invert_selection");
1211 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1212 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1214 // setup 'View' menu
1215 KStandardAction::zoomIn(this,
1217 actionCollection());
1219 KStandardAction::zoomOut(this,
1221 actionCollection());
1223 KToggleAction
* iconsView
= new KToggleAction(i18n("Icons"), actionCollection(), "icons");
1224 iconsView
->setShortcut(Qt::CTRL
| Qt::Key_1
);
1225 iconsView
->setIcon(KIcon("view_icon"));
1226 connect(iconsView
, SIGNAL(triggered()), this, SLOT(setIconsView()));
1228 KToggleAction
* detailsView
= new KToggleAction(i18n("Details"), actionCollection(), "details");
1229 detailsView
->setShortcut(Qt::CTRL
| Qt::Key_2
);
1230 detailsView
->setIcon(KIcon("view_text"));
1231 connect(detailsView
, SIGNAL(triggered()), this, SLOT(setDetailsView()));
1233 QActionGroup
* viewModeGroup
= new QActionGroup(this);
1234 viewModeGroup
->addAction(iconsView
);
1235 viewModeGroup
->addAction(detailsView
);
1237 KToggleAction
* sortByName
= new KToggleAction(i18n("By Name"), actionCollection(), "by_name");
1238 connect(sortByName
, SIGNAL(triggered()), this, SLOT(sortByName()));
1240 KToggleAction
* sortBySize
= new KToggleAction(i18n("By Size"), actionCollection(), "by_size");
1241 connect(sortBySize
, SIGNAL(triggered()), this, SLOT(sortBySize()));
1243 KToggleAction
* sortByDate
= new KToggleAction(i18n("By Date"), actionCollection(), "by_date");
1244 connect(sortByDate
, SIGNAL(triggered()), this, SLOT(sortByDate()));
1246 QActionGroup
* sortGroup
= new QActionGroup(this);
1247 sortGroup
->addAction(sortByName
);
1248 sortGroup
->addAction(sortBySize
);
1249 sortGroup
->addAction(sortByDate
);
1251 KToggleAction
* sortDescending
= new KToggleAction(i18n("Descending"), actionCollection(), "descending");
1252 connect(sortDescending
, SIGNAL(triggered()), this, SLOT(toggleSortOrder()));
1254 KToggleAction
* showPreview
= new KToggleAction(i18n("Show Preview"), actionCollection(), "show_preview");
1255 connect(showPreview
, SIGNAL(triggered()), this, SLOT(togglePreview()));
1257 KToggleAction
* showHiddenFiles
= new KToggleAction(i18n("Show Hidden Files"), actionCollection(), "show_hidden_files");
1258 //showHiddenFiles->setShortcut(Qt::ALT | Qt::Key_ KDE4-TODO: what Qt-Key represents '.'?
1259 connect(showHiddenFiles
, SIGNAL(triggered()), this, SLOT(toggleShowHiddenFiles()));
1261 KToggleAction
* split
= new KToggleAction(i18n("Split View"), actionCollection(), "split_view");
1262 split
->setShortcut(Qt::Key_F10
);
1263 split
->setIcon(KIcon("view_left_right"));
1264 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1266 KAction
* reload
= new KAction(actionCollection(), "reload");
1267 reload
->setText(i18n("Reload"));
1268 reload
->setShortcut(Qt::Key_F5
);
1269 reload
->setIcon(KIcon("reload"));
1270 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1272 KAction
* stop
= new KAction(i18n("Stop"), actionCollection(), "stop");
1273 stop
->setIcon(KIcon("stop"));
1274 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1276 KToggleAction
* showFullLocation
= new KToggleAction(i18n("Show Full Location"), actionCollection(), "editable_location");
1277 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1278 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1280 KToggleAction
* editLocation
= new KToggleAction(i18n("Edit Location"), actionCollection(), "edit_location");
1281 editLocation
->setShortcut(Qt::Key_F6
);
1282 connect(editLocation
, SIGNAL(triggered()), this, SLOT(editLocation()));
1284 KAction
* adjustViewProps
= new KAction(i18n("Adjust View Properties..."), actionCollection(), "view_properties");
1285 connect(adjustViewProps
, SIGNAL(triggered()), this, SLOT(adjustViewProperties()));
1288 KStandardAction::back(this, SLOT(goBack()), actionCollection());
1289 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1290 KStandardAction::up(this, SLOT(goUp()), actionCollection());
1291 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1293 // setup 'Tools' menu
1294 KAction
* openTerminal
= new KAction(i18n("Open Terminal"), actionCollection(), "open_terminal");
1295 openTerminal
->setShortcut(Qt::Key_F4
);
1296 openTerminal
->setIcon(KIcon("konsole"));
1297 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1299 KAction
* findFile
= new KAction(i18n("Find File..."), actionCollection(), "find_file");
1300 findFile
->setShortcut(Qt::Key_F
);
1301 findFile
->setIcon(KIcon("filefind"));
1302 connect(findFile
, SIGNAL(triggered()), this, SLOT(findFile()));
1304 KToggleAction
* showFilterBar
= new KToggleAction(i18n("Show Filter Bar"), actionCollection(), "show_filter_bar");
1305 showFilterBar
->setShortcut(Qt::Key_Slash
);
1306 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1308 KAction
* compareFiles
= new KAction(i18n("Compare Files"), actionCollection(), "compare_files");
1309 compareFiles
->setIcon(KIcon("kompare"));
1310 compareFiles
->setEnabled(false);
1311 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1313 // setup 'Settings' menu
1314 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1317 void DolphinMainWindow::setupDockWidgets()
1319 QDockWidget
*shortcutsDock
= new QDockWidget(i18n("Shortcuts"));
1321 shortcutsDock
->setObjectName("shortcutsDock");
1322 shortcutsDock
->setWidget(new BookmarksSidebarPage(this));
1324 shortcutsDock
->toggleViewAction()->setObjectName("show_shortcuts_pane");
1325 shortcutsDock
->toggleViewAction()->setText(i18n("Show Shortcuts Panel"));
1326 actionCollection()->insert(shortcutsDock
->toggleViewAction());
1328 addDockWidget(Qt::LeftDockWidgetArea
, shortcutsDock
);
1330 QDockWidget
*infoDock
= new QDockWidget(i18n("Information"));
1332 infoDock
->setObjectName("infoDock");
1333 infoDock
->setWidget(new InfoSidebarPage(this));
1335 infoDock
->toggleViewAction()->setObjectName("show_info_pane");
1336 infoDock
->toggleViewAction()->setText(i18n("Show Information Panel"));
1337 actionCollection()->insert(infoDock
->toggleViewAction());
1339 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1342 void DolphinMainWindow::setupCreateNewMenuActions()
1344 // Parts of the following code have been taken
1345 // from the class KNewMenu located in
1346 // libqonq/knewmenu.h of Konqueror.
1347 // Copyright (C) 1998, 1999 David Faure <faure@kde.org>
1348 // 2003 Sven Leiber <s.leiber@web.de>
1350 QStringList files
= actionCollection()->instance()->dirs()->findAllResources("templates");
1351 for (QStringList::Iterator it
= files
.begin() ; it
!= files
.end(); ++it
) {
1352 if ((*it
)[0] != '.' ) {
1353 KSimpleConfig
config(*it
, true);
1354 config
.setDesktopGroup();
1356 // tricky solution to ensure that TextFile is at the beginning
1357 // because this filetype is the most used (according kde-core discussion)
1358 const QString
name(config
.readEntry("Name"));
1361 const QString
path(config
.readPathEntry("Url"));
1362 if (!path
.endsWith("emptydir")) {
1363 if (path
.endsWith("TextFile.txt")) {
1366 else if (!KDesktopFile::isDesktopFile(path
)) {
1369 else if (path
.endsWith("Url.desktop")){
1372 else if (path
.endsWith("Program.desktop")){
1379 const QString
icon(config
.readEntry("Icon"));
1380 const QString
comment(config
.readEntry("Comment"));
1381 const QString
type(config
.readEntry("Type"));
1383 const QString
filePath(*it
);
1386 if (type
== "Link") {
1387 CreateFileEntry entry
;
1390 entry
.comment
= comment
;
1391 entry
.templatePath
= filePath
;
1392 m_createFileTemplates
.insert(key
, entry
);
1397 m_createFileTemplates
.sort();
1399 unplugActionList("create_actions");
1400 KSortableList
<CreateFileEntry
, QString
>::ConstIterator it
= m_createFileTemplates
.begin();
1401 KSortableList
<CreateFileEntry
, QString
>::ConstIterator end
= m_createFileTemplates
.end();
1402 /* KDE4-TODO: don't port this code; use KNewMenu instead
1404 CreateFileEntry entry = (*it).value();
1405 KAction* action = new KAction(entry.name);
1406 action->setIcon(entry.icon);
1407 action->setName((*it).index());
1408 connect(action, SIGNAL(activated()),
1409 this, SLOT(createFile()));
1411 const QChar section = ((*it).index()[0]);
1415 m_fileGroupActions.append(action);
1421 // TODO: not used yet. See documentation of DolphinMainWindow::linkGroupActions()
1422 // and DolphinMainWindow::linkToDeviceActions() in the header file for details.
1423 //m_linkGroupActions.append(action);
1428 // TODO: not used yet. See documentation of DolphinMainWindow::linkGroupActions()
1429 // and DolphinMainWindow::linkToDeviceActions() in the header file for details.
1430 //m_linkToDeviceActions.append(action);
1439 plugActionList("create_file_group", m_fileGroupActions);
1440 //plugActionList("create_link_group", m_linkGroupActions);
1441 //plugActionList("link_to_device", m_linkToDeviceActions);*/
1444 void DolphinMainWindow::updateHistory()
1447 const Q3ValueList
<UrlNavigator::HistoryElem
> list
= m_activeView
->urlHistory(index
);
1449 QAction
* backAction
= actionCollection()->action("go_back");
1450 if (backAction
!= 0) {
1451 backAction
->setEnabled(index
< static_cast<int>(list
.count()) - 1);
1454 QAction
* forwardAction
= actionCollection()->action("go_forward");
1455 if (forwardAction
!= 0) {
1456 forwardAction
->setEnabled(index
> 0);
1460 void DolphinMainWindow::updateEditActions()
1462 const KFileItemList list
= m_activeView
->selectedItems();
1463 if (list
.isEmpty()) {
1464 stateChanged("has_no_selection");
1467 stateChanged("has_selection");
1469 QAction
* renameAction
= actionCollection()->action("rename");
1470 if (renameAction
!= 0) {
1471 renameAction
->setEnabled(list
.count() >= 1);
1474 bool enableMoveToTrash
= true;
1476 KFileItemList::const_iterator it
= list
.begin();
1477 const KFileItemList::const_iterator end
= list
.end();
1479 KFileItem
* item
= *it
;
1480 const KUrl
& url
= item
->url();
1481 // only enable the 'Move to Trash' action for local files
1482 if (!url
.isLocalFile()) {
1483 enableMoveToTrash
= false;
1488 QAction
* moveToTrashAction
= actionCollection()->action("move_to_trash");
1489 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1491 updatePasteAction();
1494 void DolphinMainWindow::updateViewActions()
1496 QAction
* zoomInAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::ZoomIn
));
1497 if (zoomInAction
!= 0) {
1498 zoomInAction
->setEnabled(m_activeView
->isZoomInPossible());
1501 QAction
* zoomOutAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::ZoomOut
));
1502 if (zoomOutAction
!= 0) {
1503 zoomOutAction
->setEnabled(m_activeView
->isZoomOutPossible());
1506 QAction
* action
= 0;
1507 switch (m_activeView
->mode()) {
1508 case DolphinView::IconsView
:
1509 action
= actionCollection()->action("icons");
1511 case DolphinView::DetailsView
:
1512 action
= actionCollection()->action("details");
1514 //case DolphinView::PreviewsView:
1515 // action = actionCollection()->action("previews");
1522 KToggleAction
* toggleAction
= static_cast<KToggleAction
*>(action
);
1523 toggleAction
->setChecked(true);
1526 slotSortingChanged(m_activeView
->sorting());
1527 slotSortOrderChanged(m_activeView
->sortOrder());
1529 KToggleAction
* showFilterBarAction
=
1530 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
1531 showFilterBarAction
->setChecked(m_activeView
->isFilterBarVisible());
1533 KToggleAction
* showHiddenFilesAction
=
1534 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
1535 showHiddenFilesAction
->setChecked(m_activeView
->showHiddenFiles());
1537 KToggleAction
* splitAction
= static_cast<KToggleAction
*>(actionCollection()->action("split_view"));
1538 splitAction
->setChecked(m_view
[SecondaryIdx
] != 0);
1541 void DolphinMainWindow::updateGoActions()
1543 QAction
* goUpAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::Up
));
1544 const KUrl
& currentUrl
= m_activeView
->url();
1545 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1548 void DolphinMainWindow::updateViewProperties(const KUrl::List
& urls
)
1550 if (urls
.isEmpty()) {
1554 // Updating the view properties might take up to several seconds
1555 // when dragging several thousand Urls. Writing a KIO slave for this
1556 // use case is not worth the effort, but at least the main widget
1557 // must be disabled and a progress should be shown.
1558 ProgressIndicator
progressIndicator(this,
1559 i18n("Updating view properties..."),
1563 KUrl::List::ConstIterator end
= urls
.end();
1564 for(KUrl::List::ConstIterator it
= urls
.begin(); it
!= end
; ++it
) {
1565 progressIndicator
.execOperation();
1567 ViewProperties
props(*it
);
1572 void DolphinMainWindow::copyUrls(const KUrl::List
& source
, const KUrl
& dest
)
1574 KIO::Job
* job
= KIO::copy(source
, dest
);
1575 addPendingUndoJob(job
, DolphinCommand::Copy
, source
, dest
);
1578 void DolphinMainWindow::moveUrls(const KUrl::List
& source
, const KUrl
& dest
)
1580 KIO::Job
* job
= KIO::move(source
, dest
);
1581 addPendingUndoJob(job
, DolphinCommand::Move
, source
, dest
);
1584 void DolphinMainWindow::addPendingUndoJob(KIO::Job
* job
,
1585 DolphinCommand::Type commandType
,
1586 const KUrl::List
& source
,
1589 connect(job
, SIGNAL(result(KJob
*)),
1590 this, SLOT(addUndoOperation(KJob
*)));
1593 undoInfo
.id
= job
->progressId();
1594 undoInfo
.command
= DolphinCommand(commandType
, source
, dest
);
1595 m_pendingUndoJobs
.append(undoInfo
);
1598 void DolphinMainWindow::clearStatusBar()
1600 m_activeView
->statusBar()->clear();
1603 void DolphinMainWindow::connectViewSignals(int viewIndex
)
1605 DolphinView
* view
= m_view
[viewIndex
];
1606 connect(view
, SIGNAL(modeChanged()),
1607 this, SLOT(slotViewModeChanged()));
1608 connect(view
, SIGNAL(showHiddenFilesChanged()),
1609 this, SLOT(slotShowHiddenFilesChanged()));
1610 connect(view
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
1611 this, SLOT(slotSortingChanged(DolphinView::Sorting
)));
1612 connect(view
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
1613 this, SLOT(slotSortOrderChanged(Qt::SortOrder
)));
1614 connect(view
, SIGNAL(selectionChanged()),
1615 this, SLOT(slotSelectionChanged()));
1616 connect(view
, SIGNAL(showFilterBarChanged(bool)),
1617 this, SLOT(updateFilterBarAction(bool)));
1619 const UrlNavigator
* navigator
= view
->urlNavigator();
1620 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1621 this, SLOT(slotUrlChanged(const KUrl
&)));
1622 connect(navigator
, SIGNAL(historyChanged()),
1623 this, SLOT(slotHistoryChanged()));
1627 #include "dolphinmainwindow.moc"