1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2006 by Stefan Monov <logixoul@gmail.com> *
4 * Copyright (C) 2006 by Cvetoslav Ludmiloff <ludmiloff@gmail.com> *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20 ***************************************************************************/
26 #include <kactioncollection.h>
27 #include <ktoggleaction.h>
28 #include <kbookmarkmanager.h>
30 #include <kpropertiesdialog.h>
32 #include <kiconloader.h>
33 #include <kdeversion.h>
34 #include <kstatusbar.h>
35 #include <kio/netaccess.h>
36 #include <kfiledialog.h>
39 #include <kstdaccel.h>
41 #include <kstdaction.h>
43 #include <kio/renamedlg.h>
44 #include <kinputdialog.h>
46 #include <kdesktopfile.h>
47 #include <kstandarddirs.h>
48 #include <kprotocolinfo.h>
49 #include <kmessagebox.h>
51 #include <kstandarddirs.h>
55 #include <qclipboard.h>
56 #include <q3dragobject.h>
58 #include <Q3ValueList>
59 #include <QCloseEvent>
62 #include "urlnavigator.h"
63 #include "viewpropertiesdialog.h"
64 #include "viewproperties.h"
65 #include "dolphinsettings.h"
66 #include "dolphinsettingsdialog.h"
67 #include "dolphinstatusbar.h"
68 #include "undomanager.h"
69 #include "progressindicator.h"
70 #include "dolphinsettings.h"
72 #include "sidebarsettings.h"
73 #include "generalsettings.h"
75 Dolphin
& Dolphin::mainWin()
77 static Dolphin
* instance
= 0;
79 instance
= new Dolphin();
89 void Dolphin::setActiveView(DolphinView
* view
)
91 assert((view
== m_view
[PrimaryIdx
]) || (view
== m_view
[SecondaryIdx
]));
92 if (m_activeView
== view
) {
103 setCaption(m_activeView
->url().fileName());
105 emit
activeViewChanged();
108 void Dolphin::dropUrls(const KUrl::List
& urls
,
109 const KUrl
& destination
)
111 int selectedIndex
= -1;
114 const ButtonState keyboardState = KApplication::keyboardMouseState();
115 const bool shiftPressed = (keyboardState & ShiftButton) > 0;
116 const bool controlPressed = (keyboardState & ControlButton) > 0;
120 if (shiftPressed && controlPressed) {
121 // shortcut for 'Linke Here' is used
124 else if (controlPressed) {
125 // shortcut for 'Copy Here' is used
128 else if (shiftPressed) {
129 // shortcut for 'Move Here' is used
133 // no shortcut is used, hence open a popup menu
136 popup
.insertItem(SmallIcon("goto"), i18n("&Move Here") + "\t" /* KDE4-TODO: + KKey::modFlagLabel(KKey::SHIFT)*/, 0);
137 popup
.insertItem(SmallIcon("editcopy"), i18n( "&Copy Here" ) /* KDE4-TODO + "\t" + KKey::modFlagLabel(KKey::CTRL)*/, 1);
138 popup
.insertItem(i18n("&Link Here") /* KDE4-TODO + "\t" + KKey::modFlagLabel((KKey::ModFlag)(KKey::CTRL|KKey::SHIFT)) */, 2);
139 popup
.insertSeparator();
140 popup
.insertItem(SmallIcon("stop"), i18n("Cancel"), 3);
141 popup
.setAccel(i18n("Escape"), 3);
143 /* KDE4-TODO: selectedIndex = popup.exec(QCursor::pos()); */
144 popup
.exec(QCursor::pos());
145 selectedIndex
= 0; // KD4-TODO: use QAction instead of switch below
148 if (selectedIndex
< 0) {
152 switch (selectedIndex
) {
154 // 'Move Here' has been selected
155 updateViewProperties(urls
);
156 moveUrls(urls
, destination
);
161 // 'Copy Here' has been selected
162 updateViewProperties(urls
);
163 copyUrls(urls
, destination
);
168 // 'Link Here' has been selected
169 KIO::Job
* job
= KIO::link(urls
, destination
);
170 addPendingUndoJob(job
, DolphinCommand::Link
, urls
, destination
);
175 // 'Cancel' has been selected
180 void Dolphin::refreshViews()
182 const bool split
= DolphinSettings::instance().generalSettings()->splitView();
183 const bool isPrimaryViewActive
= (m_activeView
== m_view
[PrimaryIdx
]);
185 for (int i
= PrimaryIdx
; i
<= SecondaryIdx
; ++i
) {
186 if (m_view
[i
] != 0) {
187 url
= m_view
[i
]->url();
189 // delete view instance...
191 m_view
[i
]->deleteLater();
195 if (split
|| (i
== PrimaryIdx
)) {
196 // ... and recreate it
197 ViewProperties
props(url
);
198 m_view
[i
] = new DolphinView(m_splitter
,
201 props
.isShowHiddenFilesEnabled());
206 m_activeView
= isPrimaryViewActive
? m_view
[PrimaryIdx
] : m_view
[SecondaryIdx
];
207 assert(m_activeView
!= 0);
210 emit
activeViewChanged();
213 void Dolphin::slotHistoryChanged()
218 void Dolphin::slotUrlChanged(const KUrl
& url
)
222 setCaption(url
.fileName());
225 void Dolphin::slotUrlChangeRequest(const KUrl
& url
)
228 m_activeView
->setUrl(url
);
231 void Dolphin::slotViewModeChanged()
236 void Dolphin::slotShowHiddenFilesChanged()
238 KToggleAction
* showHiddenFilesAction
=
239 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
240 showHiddenFilesAction
->setChecked(m_activeView
->isShowHiddenFilesEnabled());
243 void Dolphin::slotShowFilterBarChanged()
245 KToggleAction
* showFilterBarAction
=
246 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
247 showFilterBarAction
->setChecked(m_activeView
->isFilterBarVisible());
250 void Dolphin::slotSortingChanged(DolphinView::Sorting sorting
)
254 case DolphinView::SortByName
:
255 action
= actionCollection()->action("by_name");
257 case DolphinView::SortBySize
:
258 action
= actionCollection()->action("by_size");
260 case DolphinView::SortByDate
:
261 action
= actionCollection()->action("by_date");
268 KToggleAction
* toggleAction
= static_cast<KToggleAction
*>(action
);
269 toggleAction
->setChecked(true);
273 void Dolphin::slotSortOrderChanged(Qt::SortOrder order
)
275 KToggleAction
* descending
= static_cast<KToggleAction
*>(actionCollection()->action("descending"));
276 const bool sortDescending
= (order
== Qt::Descending
);
277 descending
->setChecked(sortDescending
);
280 void Dolphin::slotSelectionChanged()
284 assert(m_view
[PrimaryIdx
] != 0);
285 int selectedUrlsCount
= m_view
[PrimaryIdx
]->selectedUrls().count();
286 if (m_view
[SecondaryIdx
] != 0) {
287 selectedUrlsCount
+= m_view
[SecondaryIdx
]->selectedUrls().count();
290 KAction
* compareFilesAction
= actionCollection()->action("compare_files");
291 compareFilesAction
->setEnabled(selectedUrlsCount
== 2);
293 m_activeView
->updateStatusBar();
295 emit
selectionChanged();
298 void Dolphin::closeEvent(QCloseEvent
* event
)
301 //KConfig* config = KGlobal::config();
302 //config->setGroup("General");
303 //config->writeEntry("First Run", false);
305 DolphinSettings
& settings
= DolphinSettings::instance();
306 GeneralSettings
* generalSettings
= settings
.generalSettings();
307 generalSettings
->setFirstRun(false);
309 SidebarSettings
* sidebarSettings
= settings
.sidebarSettings();
310 const bool isSidebarVisible
= (m_sidebar
!= 0);
311 sidebarSettings
->setVisible(isSidebarVisible
);
312 if (isSidebarVisible
) {
313 sidebarSettings
->setWidth(m_sidebar
->width());
318 KMainWindow::closeEvent(event
);
321 void Dolphin::saveProperties(KConfig
* config
)
323 config
->setGroup("Primary view");
324 config
->writeEntry("Url", m_view
[PrimaryIdx
]->url().url());
325 config
->writeEntry("Editable Url", m_view
[PrimaryIdx
]->isUrlEditable());
326 if (m_view
[SecondaryIdx
] != 0) {
327 config
->setGroup("Secondary view");
328 config
->writeEntry("Url", m_view
[SecondaryIdx
]->url().url());
329 config
->writeEntry("Editable Url", m_view
[SecondaryIdx
]->isUrlEditable());
333 void Dolphin::readProperties(KConfig
* config
)
335 config
->setGroup("Primary view");
336 m_view
[PrimaryIdx
]->setUrl(config
->readEntry("Url"));
337 m_view
[PrimaryIdx
]->setUrlEditable(config
->readBoolEntry("Editable Url"));
338 if (config
->hasGroup("Secondary view")) {
339 config
->setGroup("Secondary view");
340 if (m_view
[SecondaryIdx
] == 0) {
343 m_view
[SecondaryIdx
]->setUrl(config
->readEntry("Url"));
344 m_view
[SecondaryIdx
]->setUrlEditable(config
->readBoolEntry("Editable Url"));
346 else if (m_view
[SecondaryIdx
] != 0) {
351 void Dolphin::createFolder()
353 // Parts of the following code have been taken
354 // from the class KonqPopupMenu located in
355 // libqonq/konq_popupmenu.h of Konqueror.
356 // (Copyright (C) 2000 David Faure <faure@kde.org>,
357 // Copyright (C) 2001 Holger Freyther <freyther@yahoo.com>)
361 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
362 const KUrl
baseUrl(m_activeView
->url());
364 QString
name(i18n("New Folder"));
365 baseUrl
.path(KUrl::AddTrailingSlash
);
368 if (baseUrl
.isLocalFile() && QFileInfo(baseUrl
.path(KUrl::AddTrailingSlash
) + name
).exists()) {
369 name
= KIO::RenameDlg::suggestName(baseUrl
, i18n("New Folder"));
373 name
= KInputDialog::getText(i18n("New Folder"),
374 i18n("Enter folder name:" ),
380 // the user has pressed 'Cancel'
384 assert(!name
.isEmpty());
387 if ((name
[0] == '/') || (name
[0] == '~')) {
388 url
.setPath(KShell::tildeExpand(name
));
391 name
= KIO::encodeFileName(name
);
395 ok
= KIO::NetAccess::mkdir(url
, this);
397 // TODO: provide message type hint
399 statusBar
->setMessage(i18n("Created folder %1.",url
.path()),
400 DolphinStatusBar::OperationCompleted
);
402 DolphinCommand
command(DolphinCommand::CreateFolder
, KUrl::List(), url
);
403 UndoManager::instance().addCommand(command
);
406 // Creating of the folder has been failed. Check whether the creating
407 // has been failed because a folder with the same name exists...
408 if (KIO::NetAccess::exists(url
, true, this)) {
409 statusBar
->setMessage(i18n("A folder named %1 already exists.",url
.path()),
410 DolphinStatusBar::Error
);
413 statusBar
->setMessage(i18n("Creating of folder %1 failed.",url
.path()),
414 DolphinStatusBar::Error
);
420 void Dolphin::createFile()
422 // Parts of the following code have been taken
423 // from the class KonqPopupMenu located in
424 // libqonq/konq_popupmenu.h of Konqueror.
425 // (Copyright (C) 2000 David Faure <faure@kde.org>,
426 // Copyright (C) 2001 Holger Freyther <freyther@yahoo.com>)
430 // TODO: const Entry& entry = m_createFileTemplates[QString(sender->name())];
431 // should be enough. Anyway: the implemantation of [] does a linear search internally too.
432 KSortableList
<CreateFileEntry
, QString
>::ConstIterator it
= m_createFileTemplates
.begin();
433 KSortableList
<CreateFileEntry
, QString
>::ConstIterator end
= m_createFileTemplates
.end();
435 const QString
senderName(sender()->name());
437 CreateFileEntry entry
;
438 while (!found
&& (it
!= end
)) {
439 if ((*it
).index() == senderName
) {
440 entry
= (*it
).value();
448 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
449 if (!found
|| !QFile::exists(entry
.templatePath
)) {
450 statusBar
->setMessage(i18n("Could not create file."), DolphinStatusBar::Error
);
454 // Get the source path of the template which should be copied.
455 // The source path is part of the Url entry of the desktop file.
456 const int pos
= entry
.templatePath
.findRev('/');
457 QString
sourcePath(entry
.templatePath
.left(pos
+ 1));
458 sourcePath
+= KDesktopFile(entry
.templatePath
, true).readPathEntry("Url");
460 QString
name(i18n(entry
.name
.ascii()));
461 // Most entry names end with "..." (e. g. "HTML File..."), which is ok for
462 // menus but no good choice for a new file name -> remove the dots...
463 name
.replace("...", QString::null
);
465 // add the file extension to the name
466 name
.append(sourcePath
.right(sourcePath
.length() - sourcePath
.findRev('.')));
468 // Check whether a file with the current name already exists. If yes suggest automatically
469 // a unique file name (e. g. "HTML File" will be replaced by "HTML File_1").
470 const KUrl
viewUrl(m_activeView
->url());
471 const bool fileExists
= viewUrl
.isLocalFile() &&
472 QFileInfo(viewUrl
.path(KUrl::AddTrailingSlash
) + KIO::encodeFileName(name
)).exists();
474 name
= KIO::RenameDlg::suggestName(viewUrl
, name
);
477 // let the user change the suggested file name
479 name
= KInputDialog::getText(entry
.name
,
485 // the user has pressed 'Cancel'
489 // before copying the template to the destination path check whether a file
490 // with the given name already exists
491 const QString
destPath(viewUrl
.pathOrUrl() + "/" + KIO::encodeFileName(name
));
492 const KUrl
destUrl(destPath
);
493 if (KIO::NetAccess::exists(destUrl
, false, this)) {
494 statusBar
->setMessage(i18n("A file named %1 already exists.",name
),
495 DolphinStatusBar::Error
);
499 // copy the template to the destination path
500 const KUrl
sourceUrl(sourcePath
);
501 KIO::CopyJob
* job
= KIO::copyAs(sourceUrl
, destUrl
);
502 job
->setDefaultPermissions(true);
503 if (KIO::NetAccess::synchronousRun(job
, this)) {
504 statusBar
->setMessage(i18n("Created file %1.",name
),
505 DolphinStatusBar::OperationCompleted
);
508 list
.append(sourceUrl
);
509 DolphinCommand
command(DolphinCommand::CreateFile
, list
, destUrl
);
510 UndoManager::instance().addCommand(command
);
514 statusBar
->setMessage(i18n("Creating of file %1 failed.",name
),
515 DolphinStatusBar::Error
);
519 void Dolphin::rename()
522 m_activeView
->renameSelectedItems();
525 void Dolphin::moveToTrash()
528 KUrl::List selectedUrls
= m_activeView
->selectedUrls();
529 KIO::Job
* job
= KIO::trash(selectedUrls
);
530 addPendingUndoJob(job
, DolphinCommand::Trash
, selectedUrls
, m_activeView
->url());
533 void Dolphin::deleteItems()
537 KUrl::List list
= m_activeView
->selectedUrls();
538 const uint itemCount
= list
.count();
539 assert(itemCount
>= 1);
543 text
= i18n("Do you really want to delete the %1 selected items?",itemCount
);
546 const KUrl
& url
= list
.first();
547 text
= i18n("Do you really want to delete '%1'?",url
.fileName());
550 const bool del
= KMessageBox::warningContinueCancel(this,
553 KGuiItem(i18n("Delete"), SmallIcon("editdelete"))
554 ) == KMessageBox::Continue
;
556 KIO::Job
* job
= KIO::del(list
);
557 connect(job
, SIGNAL(result(KIO::Job
*)),
558 this, SLOT(slotHandleJobError(KIO::Job
*)));
559 connect(job
, SIGNAL(result(KIO::Job
*)),
560 this, SLOT(slotDeleteFileFinished(KIO::Job
*)));
564 void Dolphin::properties()
566 const KFileItemList
* sourceList
= m_activeView
->selectedItems();
567 if (sourceList
== 0) {
572 KFileItemList::const_iterator it
= sourceList
->begin();
573 const KFileItemList::const_iterator end
= sourceList
->end();
580 new KPropertiesDialog(list
, this);
588 void Dolphin::slotHandleJobError(KIO::Job
* job
)
590 if (job
->error() != 0) {
591 m_activeView
->statusBar()->setMessage(job
->errorString(),
592 DolphinStatusBar::Error
);
596 void Dolphin::slotDeleteFileFinished(KIO::Job
* 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 Dolphin::slotUndoAvailable(bool available
)
612 KAction
* undoAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Undo
));
613 if (undoAction
!= 0) {
614 undoAction
->setEnabled(available
);
618 void Dolphin::slotUndoTextChanged(const QString
& text
)
620 KAction
* undoAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Undo
));
621 if (undoAction
!= 0) {
622 undoAction
->setText(text
);
626 void Dolphin::slotRedoAvailable(bool available
)
628 KAction
* redoAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Redo
));
629 if (redoAction
!= 0) {
630 redoAction
->setEnabled(available
);
634 void Dolphin::slotRedoTextChanged(const QString
& text
)
636 KAction
* redoAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Redo
));
637 if (redoAction
!= 0) {
638 redoAction
->setText(text
);
644 m_clipboardContainsCutData
= true;
645 /* KDE4-TODO: Q3DragObject* data = new KUrlDrag(m_activeView->selectedUrls(),
647 QApplication::clipboard()->setData(data);*/
652 m_clipboardContainsCutData
= false;
654 Q3DragObject* data = new KUrlDrag(m_activeView->selectedUrls(),
656 QApplication::clipboard()->setData(data);*/
659 void Dolphin::paste()
662 QClipboard* clipboard = QApplication::clipboard();
663 QMimeSource* data = clipboard->data();
664 if (!KUrlDrag::canDecode(data)) {
670 KUrl::List sourceUrls;
671 KUrlDrag::decode(data, sourceUrls);
673 // per default the pasting is done into the current Url of the view
674 KUrl destUrl(m_activeView->url());
676 // check whether the pasting should be done into a selected directory
677 KUrl::List selectedUrls = m_activeView->selectedUrls();
678 if (selectedUrls.count() == 1) {
679 const KFileItem fileItem(S_IFDIR,
681 selectedUrls.first(),
683 if (fileItem.isDir()) {
684 // only one item is selected which is a directory, hence paste
685 // into this directory
686 destUrl = selectedUrls.first();
691 updateViewProperties(sourceUrls);
692 if (m_clipboardContainsCutData) {
693 moveUrls(sourceUrls, destUrl);
694 m_clipboardContainsCutData = false;
698 copyUrls(sourceUrls, destUrl);
702 void Dolphin::updatePasteAction()
704 KAction
* pasteAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Paste
));
705 if (pasteAction
== 0) {
709 QString
text(i18n("Paste"));
710 QClipboard
* clipboard
= QApplication::clipboard();
711 QMimeSource
* data
= clipboard
->data();
713 if (KUrlDrag::canDecode(data)) {
714 pasteAction->setEnabled(true);
717 KUrlDrag::decode(data, urls);
718 const int count = urls.count();
720 pasteAction->setText(i18n("Paste 1 File"));
723 pasteAction->setText(i18n("Paste %1 Files").arg(count));
727 pasteAction
->setEnabled(false);
728 pasteAction
->setText(i18n("Paste"));
731 if (pasteAction
->isEnabled()) {
732 KUrl::List urls
= m_activeView
->selectedUrls();
733 const uint count
= urls
.count();
735 // pasting should not be allowed when more than one file
737 pasteAction
->setEnabled(false);
739 else if (count
== 1) {
740 // Only one file is selected. Pasting is only allowed if this
741 // file is a directory.
742 const KFileItem
fileItem(S_IFDIR
,
746 pasteAction
->setEnabled(fileItem
.isDir());
751 void Dolphin::selectAll()
754 m_activeView
->selectAll();
757 void Dolphin::invertSelection()
760 m_activeView
->invertSelection();
762 void Dolphin::setIconsView()
764 m_activeView
->setMode(DolphinView::IconsView
);
767 void Dolphin::setDetailsView()
769 m_activeView
->setMode(DolphinView::DetailsView
);
772 void Dolphin::setPreviewsView()
774 m_activeView
->setMode(DolphinView::PreviewsView
);
777 void Dolphin::sortByName()
779 m_activeView
->setSorting(DolphinView::SortByName
);
782 void Dolphin::sortBySize()
784 m_activeView
->setSorting(DolphinView::SortBySize
);
787 void Dolphin::sortByDate()
789 m_activeView
->setSorting(DolphinView::SortByDate
);
792 void Dolphin::toggleSortOrder()
794 const Qt::SortOrder order
= (m_activeView
->sortOrder() == Qt::Ascending
) ?
797 m_activeView
->setSortOrder(order
);
800 void Dolphin::toggleSplitView()
802 if (m_view
[SecondaryIdx
] == 0) {
803 // create a secondary view
804 m_view
[SecondaryIdx
] = new DolphinView(m_splitter
,
805 m_view
[PrimaryIdx
]->url(),
806 m_view
[PrimaryIdx
]->mode(),
807 m_view
[PrimaryIdx
]->isShowHiddenFilesEnabled());
808 m_view
[SecondaryIdx
]->show();
811 // remove secondary view
812 if (m_activeView
== m_view
[PrimaryIdx
]) {
813 m_view
[SecondaryIdx
]->close();
814 m_view
[SecondaryIdx
]->deleteLater();
815 m_view
[SecondaryIdx
] = 0;
816 setActiveView(m_view
[PrimaryIdx
]);
819 // The secondary view is active, hence from the users point of view
820 // the content of the secondary view should be moved to the primary view.
821 // From an implementation point of view it is more efficient to close
822 // the primary view and exchange the internal pointers afterwards.
823 m_view
[PrimaryIdx
]->close();
824 m_view
[PrimaryIdx
]->deleteLater();
825 m_view
[PrimaryIdx
] = m_view
[SecondaryIdx
];
826 m_view
[SecondaryIdx
] = 0;
827 setActiveView(m_view
[PrimaryIdx
]);
832 void Dolphin::reloadView()
835 m_activeView
->reload();
838 void Dolphin::stopLoading()
842 void Dolphin::showHiddenFiles()
846 const KToggleAction
* showHiddenFilesAction
=
847 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
848 const bool show
= showHiddenFilesAction
->isChecked();
849 m_activeView
->setShowHiddenFilesEnabled(show
);
852 void Dolphin::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 Dolphin::zoomIn()
862 m_activeView
->zoomIn();
866 void Dolphin::zoomOut()
868 m_activeView
->zoomOut();
872 void Dolphin::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 Dolphin::editLocation()
885 KToggleAction
* action
= static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
886 action
->setChecked(true);
887 m_activeView
->setUrlEditable(true);
890 void Dolphin::adjustViewProperties()
893 ViewPropertiesDialog
dlg(m_activeView
);
897 void Dolphin::goBack()
900 m_activeView
->goBack();
903 void Dolphin::goForward()
906 m_activeView
->goForward();
912 m_activeView
->goUp();
915 void Dolphin::goHome()
918 m_activeView
->goHome();
921 void Dolphin::openTerminal()
923 QString
command("konsole --workdir \"");
924 command
.append(m_activeView
->url().path());
925 command
.append('\"');
927 KRun::runCommand(command
, "Konsole", "konsole");
930 void Dolphin::findFile()
932 KRun::run("kfind", m_activeView
->url());
935 void Dolphin::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 Dolphin::editSettings()
992 // TODO: make a static method for opening the settings dialog
993 DolphinSettingsDialog dlg
;
997 void Dolphin::addUndoOperation(KIO::Job
* 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
= job
->metaData();
1026 KUrl::List newSourceUrls
;
1028 KUrl::List sourceUrls
= command
.source();
1029 KUrl::List::Iterator sourceIt
= sourceUrls
.begin();
1030 const KUrl::List::Iterator sourceEnd
= sourceUrls
.end();
1032 while (sourceIt
!= sourceEnd
) {
1033 QMap
<QString
, QString
>::ConstIterator metaIt
= metaData
.find("trashUrl-" + (*sourceIt
).path());
1034 if (metaIt
!= metaData
.end()) {
1035 newSourceUrls
.append(KUrl(metaIt
.data()));
1039 command
.setSource(newSourceUrls
);
1042 UndoManager::instance().addCommand(command
);
1043 m_pendingUndoJobs
.erase(it
);
1045 DolphinStatusBar
* statusBar
= m_activeView
->statusBar();
1046 switch (command
.type()) {
1047 case DolphinCommand::Copy
:
1048 statusBar
->setMessage(i18n("Copy operation completed."),
1049 DolphinStatusBar::OperationCompleted
);
1051 case DolphinCommand::Move
:
1052 statusBar
->setMessage(i18n("Move operation completed."),
1053 DolphinStatusBar::OperationCompleted
);
1055 case DolphinCommand::Trash
:
1056 statusBar
->setMessage(i18n("Move to trash operation completed."),
1057 DolphinStatusBar::OperationCompleted
);
1066 void Dolphin::toggleSidebar()
1068 if (m_sidebar
== 0) {
1075 KToggleAction
* sidebarAction
= static_cast<KToggleAction
*>(actionCollection()->action("sidebar"));
1076 sidebarAction
->setChecked(m_sidebar
!= 0);
1079 void Dolphin::closeSidebar()
1081 if (m_sidebar
== 0) {
1082 // the sidebar has already been closed
1086 // store width of sidebar and remember that the sidebar has been closed
1087 SidebarSettings
* settings
= DolphinSettings::instance().sidebarSettings();
1088 settings
->setVisible(false);
1089 settings
->setWidth(m_sidebar
->width());
1091 m_sidebar
->deleteLater();
1095 Dolphin::Dolphin() :
1096 KMainWindow(0, "Dolphin"),
1100 m_clipboardContainsCutData(false)
1102 m_view
[PrimaryIdx
] = 0;
1103 m_view
[SecondaryIdx
] = 0;
1105 m_fileGroupActions
.setAutoDelete(true);
1107 // TODO: the following members are not used yet. See documentation
1108 // of Dolphin::linkGroupActions() and Dolphin::linkToDeviceActions()
1109 // in the header file for details.
1110 //m_linkGroupActions.setAutoDelete(true);
1111 //m_linkToDeviceActions.setAutoDelete(true);
1114 void Dolphin::init()
1116 // Check whether Dolphin runs the first time. If yes then
1117 // a proper default window size is given at the end of Dolphin::init().
1118 GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
1119 const bool firstRun
= generalSettings
->firstRun();
1121 setAcceptDrops(true);
1123 m_splitter
= new QSplitter(this);
1125 DolphinSettings
& settings
= DolphinSettings::instance();
1127 KBookmarkManager
* manager
= settings
.bookmarkManager();
1128 assert(manager
!= 0);
1129 KBookmarkGroup root
= manager
->root();
1130 if (root
.first().isNull()) {
1131 root
.addBookmark(manager
, i18n("Home"), settings
.generalSettings()->homeUrl(), "folder_home");
1132 root
.addBookmark(manager
, i18n("Storage Media"), KUrl("media:/"), "blockdevice");
1133 root
.addBookmark(manager
, i18n("Network"), KUrl("remote:/"), "network_local");
1134 root
.addBookmark(manager
, i18n("Root"), KUrl("/"), "folder_red");
1135 root
.addBookmark(manager
, i18n("Trash"), KUrl("trash:/"), "trashcan_full");
1139 setupGUI(Keys
|Save
|Create
|ToolBar
);
1141 const KUrl
& homeUrl
= root
.first().url();
1142 setCaption(homeUrl
.fileName());
1143 ViewProperties
props(homeUrl
);
1144 m_view
[PrimaryIdx
] = new DolphinView(m_splitter
,
1147 props
.isShowHiddenFilesEnabled());
1149 m_activeView
= m_view
[PrimaryIdx
];
1151 setCentralWidget(m_splitter
);
1154 SidebarSettings
* sidebarSettings
= settings
.sidebarSettings();
1155 assert(sidebarSettings
!= 0);
1156 if (sidebarSettings
->visible()) {
1162 stateChanged("new_file");
1163 setAutoSaveSettings();
1165 QClipboard
* clipboard
= QApplication::clipboard();
1166 connect(clipboard
, SIGNAL(dataChanged()),
1167 this, SLOT(updatePasteAction()));
1168 updatePasteAction();
1171 setupCreateNewMenuActions();
1176 // assure a proper default size if Dolphin runs the first time
1181 void Dolphin::loadSettings()
1183 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
1185 KToggleAction
* splitAction
= static_cast<KToggleAction
*>(actionCollection()->action("split_view"));
1186 if (settings
->splitView()) {
1187 splitAction
->setChecked(true);
1191 updateViewActions();
1194 void Dolphin::setupActions()
1196 // setup 'File' menu
1197 KAction
* createFolder
= new KAction(i18n("Folder..."), actionCollection(), "create_folder");
1198 createFolder
->setIcon(KIcon("folder"));
1199 createFolder
->setShortcut(Qt::Key_N
);
1200 connect(createFolder
, SIGNAL(triggered()), this, SLOT(createFolder()));
1202 KAction
* rename
= new KAction(i18n("Rename"), actionCollection(), "rename");
1203 rename
->setShortcut(Qt::Key_F2
);
1204 connect(rename
, SIGNAL(triggered()), this, SLOT(rename()));
1206 KAction
* moveToTrash
= new KAction(i18n("Move to Trash"), actionCollection(), "move_to_trash");
1207 moveToTrash
->setIcon(KIcon("edittrash"));
1208 moveToTrash
->setShortcut(QKeySequence::Delete
);
1209 connect(moveToTrash
, SIGNAL(triggered()), this, SLOT(moveToTrash()));
1211 KAction
* deleteAction
= new KAction(i18n("Delete"), actionCollection(), "delete");
1212 deleteAction
->setShortcut(Qt::ALT
| Qt::Key_Delete
);
1213 deleteAction
->setIcon(KIcon("editdelete"));
1214 connect(deleteAction
, SIGNAL(triggered()), this, SLOT(deleteItems()));
1216 KAction
* properties
= new KAction(i18n("Propert&ies"), actionCollection(), "properties");
1217 properties
->setShortcut(Qt::Key_Alt
| Qt::Key_Return
);
1218 connect(properties
, SIGNAL(triggered()), this, SLOT(properties()));
1220 KStdAction::quit(this, SLOT(quit()), actionCollection());
1222 // setup 'Edit' menu
1223 UndoManager
& undoManager
= UndoManager::instance();
1224 KStdAction::undo(&undoManager
,
1226 actionCollection());
1227 connect(&undoManager
, SIGNAL(undoAvailable(bool)),
1228 this, SLOT(slotUndoAvailable(bool)));
1229 connect(&undoManager
, SIGNAL(undoTextChanged(const QString
&)),
1230 this, SLOT(slotUndoTextChanged(const QString
&)));
1232 KStdAction::redo(&undoManager
,
1234 actionCollection());
1235 connect(&undoManager
, SIGNAL(redoAvailable(bool)),
1236 this, SLOT(slotRedoAvailable(bool)));
1237 connect(&undoManager
, SIGNAL(redoTextChanged(const QString
&)),
1238 this, SLOT(slotRedoTextChanged(const QString
&)));
1240 KStdAction::cut(this, SLOT(cut()), actionCollection());
1241 KStdAction::copy(this, SLOT(copy()), actionCollection());
1242 KStdAction::paste(this, SLOT(paste()), actionCollection());
1244 KAction
* selectAll
= new KAction(i18n("Select All"), actionCollection(), "select_all");
1245 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1246 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1248 KAction
* invertSelection
= new KAction(i18n("Invert Selection"), actionCollection(), "invert_selection");
1249 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1250 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1252 // setup 'View' menu
1253 KStdAction::zoomIn(this,
1255 actionCollection());
1257 KStdAction::zoomOut(this,
1259 actionCollection());
1261 KToggleAction
* iconsView
= new KToggleAction(i18n("Icons"), actionCollection(), "icons");
1262 iconsView
->setShortcut(Qt::CTRL
| Qt::Key_1
);
1263 iconsView
->setIcon(KIcon("view_icon"));
1264 connect(iconsView
, SIGNAL(triggered()), this, SLOT(setIconsView()));
1266 KToggleAction
* detailsView
= new KToggleAction(i18n("Details"), actionCollection(), "details");
1267 detailsView
->setShortcut(Qt::CTRL
| Qt::Key_2
);
1268 detailsView
->setIcon(KIcon("view_text"));
1269 connect(detailsView
, SIGNAL(triggered()), this, SLOT(setIconsView()));
1271 KToggleAction
* previewsView
= new KToggleAction(i18n("Previews"), actionCollection(), "previews");
1272 previewsView
->setShortcut(Qt::CTRL
| Qt::Key_3
);
1273 previewsView
->setIcon(KIcon("gvdirpart"));
1274 connect(previewsView
, SIGNAL(triggered()), this, SLOT(setPreviewsView()));
1276 QActionGroup
* viewModeGroup
= new QActionGroup(this);
1277 viewModeGroup
->addAction(iconsView
);
1278 viewModeGroup
->addAction(detailsView
);
1279 viewModeGroup
->addAction(previewsView
);
1281 KToggleAction
* sortByName
= new KToggleAction(i18n("By Name"), actionCollection(), "by_name");
1282 connect(sortByName
, SIGNAL(triggered()), this, SLOT(sortByName()));
1284 KToggleAction
* sortBySize
= new KToggleAction(i18n("By Size"), actionCollection(), "by_size");
1285 connect(sortBySize
, SIGNAL(triggered()), this, SLOT(sortBySize()));
1287 KToggleAction
* sortByDate
= new KToggleAction(i18n("By Date"), actionCollection(), "by_date");
1288 connect(sortByDate
, SIGNAL(triggered()), this, SLOT(sortByDate()));
1290 QActionGroup
* sortGroup
= new QActionGroup(this);
1291 sortGroup
->addAction(sortByName
);
1292 sortGroup
->addAction(sortBySize
);
1293 sortGroup
->addAction(sortByDate
);
1295 KToggleAction
* sortDescending
= new KToggleAction(i18n("Descending"), actionCollection(), "descending");
1296 connect(sortDescending
, SIGNAL(triggered()), this, SLOT(toggleSortOrder()));
1298 KToggleAction
* showHiddenFiles
= new KToggleAction(i18n("Show Hidden Files"), actionCollection(), "show_hidden_files");
1299 //showHiddenFiles->setShortcut(Qt::ALT | Qt::Key_ KDE4-TODO: what Qt-Key represents '.'?
1300 connect(showHiddenFiles
, SIGNAL(triggered()), this, SLOT(showHiddenFiles()));
1302 KToggleAction
* split
= new KToggleAction(i18n("Split View"), actionCollection(), "split_view");
1303 split
->setShortcut(Qt::Key_F10
);
1304 split
->setIcon(KIcon("view_left_right"));
1305 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1307 KAction
* reload
= new KAction(i18n("Reload"), "F5", actionCollection(), "reload");
1308 reload
->setShortcut(Qt::Key_F5
);
1309 reload
->setIcon(KIcon("reload"));
1310 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1312 KAction
* stop
= new KAction(i18n("Stop"), actionCollection(), "stop");
1313 stop
->setIcon(KIcon("stop"));
1314 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1316 KToggleAction
* showFullLocation
= new KToggleAction(i18n("Show Full Location"), actionCollection(), "editable_location");
1317 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1318 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1320 KToggleAction
* editLocation
= new KToggleAction(i18n("Edit Location"), actionCollection(), "edit_location");
1321 editLocation
->setShortcut(Qt::Key_F6
);
1322 connect(editLocation
, SIGNAL(triggered()), this, SLOT(editLocation()));
1324 KToggleAction
* sidebar
= new KToggleAction(i18n("Sidebar"), actionCollection(), "sidebar");
1325 sidebar
->setShortcut(Qt::Key_F9
);
1326 connect(sidebar
, SIGNAL(triggered()), this, SLOT(toggleSidebar()));
1328 KAction
* adjustViewProps
= new KAction(i18n("Adjust View Properties..."), actionCollection(), "view_properties");
1329 connect(adjustViewProps
, SIGNAL(triggered()), this, SLOT(adjustViewProperties()));
1332 KStdAction::back(this, SLOT(goBack()), actionCollection());
1333 KStdAction::forward(this, SLOT(goForward()), actionCollection());
1334 KStdAction::up(this, SLOT(goUp()), actionCollection());
1335 KStdAction::home(this, SLOT(goHome()), actionCollection());
1337 // setup 'Tools' menu
1338 KAction
* openTerminal
= new KAction(i18n("Open Terminal"), actionCollection(), "open_terminal");
1339 openTerminal
->setShortcut(Qt::Key_F4
);
1340 openTerminal
->setIcon(KIcon("konsole"));
1341 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1343 KAction
* findFile
= new KAction(i18n("Find File..."), actionCollection(), "find_file");
1344 findFile
->setShortcut(Qt::Key_F
);
1345 findFile
->setIcon(KIcon("filefind"));
1346 connect(findFile
, SIGNAL(triggered()), this, SLOT(findFile()));
1348 KToggleAction
* showFilterBar
= new KToggleAction(i18n("Show Filter Bar"), actionCollection(), "show_filter_bar");
1349 showFilterBar
->setShortcut(Qt::Key_Slash
);
1350 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1352 KAction
* compareFiles
= new KAction(i18n("Compare Files"), actionCollection(), "compare_files");
1353 compareFiles
->setIcon(KIcon("kompare"));
1354 compareFiles
->setEnabled(false);
1355 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1357 // setup 'Settings' menu
1358 KStdAction::preferences(this, SLOT(editSettings()), actionCollection());
1361 void Dolphin::setupCreateNewMenuActions()
1363 // Parts of the following code have been taken
1364 // from the class KNewMenu located in
1365 // libqonq/knewmenu.h of Konqueror.
1366 // Copyright (C) 1998, 1999 David Faure <faure@kde.org>
1367 // 2003 Sven Leiber <s.leiber@web.de>
1369 QStringList files
= actionCollection()->instance()->dirs()->findAllResources("templates");
1370 for (QStringList::Iterator it
= files
.begin() ; it
!= files
.end(); ++it
) {
1371 if ((*it
)[0] != '.' ) {
1372 KSimpleConfig
config(*it
, true);
1373 config
.setDesktopGroup();
1375 // tricky solution to ensure that TextFile is at the beginning
1376 // because this filetype is the most used (according kde-core discussion)
1377 const QString
name(config
.readEntry("Name"));
1380 const QString
path(config
.readPathEntry("Url"));
1381 if (!path
.endsWith("emptydir")) {
1382 if (path
.endsWith("TextFile.txt")) {
1385 else if (!KDesktopFile::isDesktopFile(path
)) {
1388 else if (path
.endsWith("Url.desktop")){
1391 else if (path
.endsWith("Program.desktop")){
1398 const QString
icon(config
.readEntry("Icon"));
1399 const QString
comment(config
.readEntry("Comment"));
1400 const QString
type(config
.readEntry("Type"));
1402 const QString
filePath(*it
);
1405 if (type
== "Link") {
1406 CreateFileEntry entry
;
1409 entry
.comment
= comment
;
1410 entry
.templatePath
= filePath
;
1411 m_createFileTemplates
.insert(key
, entry
);
1416 m_createFileTemplates
.sort();
1418 unplugActionList("create_actions");
1419 KSortableList
<CreateFileEntry
, QString
>::ConstIterator it
= m_createFileTemplates
.begin();
1420 KSortableList
<CreateFileEntry
, QString
>::ConstIterator end
= m_createFileTemplates
.end();
1423 CreateFileEntry entry = (*it).value();
1424 KAction* action = new KAction(entry.name);
1425 action->setIcon(entry.icon);
1426 action->setName((*it).index());
1427 connect(action, SIGNAL(activated()),
1428 this, SLOT(createFile()));
1430 const QChar section = ((*it).index()[0]);
1434 m_fileGroupActions.append(action);
1440 // TODO: not used yet. See documentation of Dolphin::linkGroupActions()
1441 // and Dolphin::linkToDeviceActions() in the header file for details.
1442 //m_linkGroupActions.append(action);
1447 // TODO: not used yet. See documentation of Dolphin::linkGroupActions()
1448 // and Dolphin::linkToDeviceActions() in the header file for details.
1449 //m_linkToDeviceActions.append(action);
1458 plugActionList("create_file_group", m_fileGroupActions);
1459 //plugActionList("create_link_group", m_linkGroupActions);
1460 //plugActionList("link_to_device", m_linkToDeviceActions);*/
1463 void Dolphin::updateHistory()
1466 const Q3ValueList
<UrlNavigator::HistoryElem
> list
= m_activeView
->urlHistory(index
);
1468 KAction
* backAction
= actionCollection()->action("go_back");
1469 if (backAction
!= 0) {
1470 backAction
->setEnabled(index
< static_cast<int>(list
.count()) - 1);
1473 KAction
* forwardAction
= actionCollection()->action("go_forward");
1474 if (forwardAction
!= 0) {
1475 forwardAction
->setEnabled(index
> 0);
1479 void Dolphin::updateEditActions()
1481 const KFileItemList
* list
= m_activeView
->selectedItems();
1482 if ((list
== 0) || (*list
).isEmpty()) {
1483 stateChanged("has_no_selection");
1486 stateChanged("has_selection");
1488 KAction
* renameAction
= actionCollection()->action("rename");
1489 if (renameAction
!= 0) {
1490 renameAction
->setEnabled(list
->count() >= 1);
1493 bool enableMoveToTrash
= true;
1495 KFileItemList::const_iterator it
= list
->begin();
1496 const KFileItemList::const_iterator end
= list
->end();
1498 KFileItem
* item
= *it
;
1499 const KUrl
& url
= item
->url();
1500 // only enable the 'Move to Trash' action for local files
1501 if (!url
.isLocalFile()) {
1502 enableMoveToTrash
= false;
1507 KAction
* moveToTrashAction
= actionCollection()->action("move_to_trash");
1508 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1510 updatePasteAction();
1513 void Dolphin::updateViewActions()
1515 KAction
* zoomInAction
= actionCollection()->action(KStdAction::stdName(KStdAction::ZoomIn
));
1516 if (zoomInAction
!= 0) {
1517 zoomInAction
->setEnabled(m_activeView
->isZoomInPossible());
1520 KAction
* zoomOutAction
= actionCollection()->action(KStdAction::stdName(KStdAction::ZoomOut
));
1521 if (zoomOutAction
!= 0) {
1522 zoomOutAction
->setEnabled(m_activeView
->isZoomOutPossible());
1525 KAction
* action
= 0;
1526 switch (m_activeView
->mode()) {
1527 case DolphinView::IconsView
:
1528 action
= actionCollection()->action("icons");
1530 case DolphinView::DetailsView
:
1531 action
= actionCollection()->action("details");
1533 case DolphinView::PreviewsView
:
1534 action
= actionCollection()->action("previews");
1541 KToggleAction
* toggleAction
= static_cast<KToggleAction
*>(action
);
1542 toggleAction
->setChecked(true);
1545 slotSortingChanged(m_activeView
->sorting());
1546 slotSortOrderChanged(m_activeView
->sortOrder());
1548 KToggleAction
* showFilterBarAction
=
1549 static_cast<KToggleAction
*>(actionCollection()->action("show_filter_bar"));
1550 showFilterBarAction
->setChecked(m_activeView
->isFilterBarVisible());
1552 KToggleAction
* showHiddenFilesAction
=
1553 static_cast<KToggleAction
*>(actionCollection()->action("show_hidden_files"));
1554 showHiddenFilesAction
->setChecked(m_activeView
->isShowHiddenFilesEnabled());
1556 KToggleAction
* splitAction
= static_cast<KToggleAction
*>(actionCollection()->action("split_view"));
1557 splitAction
->setChecked(m_view
[SecondaryIdx
] != 0);
1559 KToggleAction
* sidebarAction
= static_cast<KToggleAction
*>(actionCollection()->action("sidebar"));
1560 sidebarAction
->setChecked(m_sidebar
!= 0);
1563 void Dolphin::updateGoActions()
1565 KAction
* goUpAction
= actionCollection()->action(KStdAction::stdName(KStdAction::Up
));
1566 const KUrl
& currentUrl
= m_activeView
->url();
1567 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1570 void Dolphin::updateViewProperties(const KUrl::List
& urls
)
1572 if (urls
.isEmpty()) {
1576 // Updating the view properties might take up to several seconds
1577 // when dragging several thousand Urls. Writing a KIO slave for this
1578 // use case is not worth the effort, but at least the main widget
1579 // must be disabled and a progress should be shown.
1580 ProgressIndicator
progressIndicator(i18n("Updating view properties..."),
1584 KUrl::List::ConstIterator end
= urls
.end();
1585 for(KUrl::List::ConstIterator it
= urls
.begin(); it
!= end
; ++it
) {
1586 progressIndicator
.execOperation();
1588 ViewProperties
props(*it
);
1593 void Dolphin::copyUrls(const KUrl::List
& source
, const KUrl
& dest
)
1595 KIO::Job
* job
= KIO::copy(source
, dest
);
1596 addPendingUndoJob(job
, DolphinCommand::Copy
, source
, dest
);
1599 void Dolphin::moveUrls(const KUrl::List
& source
, const KUrl
& dest
)
1601 KIO::Job
* job
= KIO::move(source
, dest
);
1602 addPendingUndoJob(job
, DolphinCommand::Move
, source
, dest
);
1605 void Dolphin::addPendingUndoJob(KIO::Job
* job
,
1606 DolphinCommand::Type commandType
,
1607 const KUrl::List
& source
,
1610 connect(job
, SIGNAL(result(KIO::Job
*)),
1611 this, SLOT(addUndoOperation(KIO::Job
*)));
1614 undoInfo
.id
= job
->progressId();
1615 undoInfo
.command
= DolphinCommand(commandType
, source
, dest
);
1616 m_pendingUndoJobs
.append(undoInfo
);
1619 void Dolphin::clearStatusBar()
1621 m_activeView
->statusBar()->clear();
1624 void Dolphin::openSidebar()
1626 if (m_sidebar
!= 0) {
1627 // the sidebar is already open
1631 m_sidebar
= new Sidebar(m_splitter
);
1634 connect(m_sidebar
, SIGNAL(urlChanged(const KUrl
&)),
1635 this, SLOT(slotUrlChangeRequest(const KUrl
&)));
1636 m_splitter
->setCollapsible(m_sidebar
, false);
1637 m_splitter
->setResizeMode(m_sidebar
, QSplitter::KeepSize
);
1638 m_splitter
->moveToFirst(m_sidebar
);
1640 SidebarSettings
* settings
= DolphinSettings::instance().sidebarSettings();
1641 settings
->setVisible(true);
1644 #include "dolphin.moc"