]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
SVN_SILENT unused (showed up in lxr)
[dolphin.git] / 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> *
5 * *
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. *
10 * *
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. *
15 * *
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 ***************************************************************************/
21
22 #include <config-kmetadata.h>
23 #include "dolphinmainwindow.h"
24
25 #include "bookmarkssidebarpage.h"
26 #include "dolphinapplication.h"
27 #include "dolphinnewmenu.h"
28 #include "dolphinsettings.h"
29 #include "dolphinsettingsdialog.h"
30 #include "dolphinstatusbar.h"
31 #include "infosidebarpage.h"
32 #include "metadataloader.h"
33 #include "mainwindowadaptor.h"
34 #include "treeviewsidebarpage.h"
35 #include "urlnavigator.h"
36 #include "viewpropertiesdialog.h"
37 #include "viewproperties.h"
38
39 #include "dolphin_generalsettings.h"
40
41 #include <kaction.h>
42 #include <kactioncollection.h>
43 #include <kbookmarkmanager.h>
44 #include <kconfig.h>
45 #include <kdesktopfile.h>
46 #include <kdeversion.h>
47 #include <kfiledialog.h>
48 #include <kglobal.h>
49 #include <kicon.h>
50 #include <kiconloader.h>
51 #include <kio/netaccess.h>
52 #include <kio/deletejob.h>
53 #include <kio/renamedialog.h>
54 #include <kinputdialog.h>
55 #include <klocale.h>
56 #include <kmenu.h>
57 #include <kmessagebox.h>
58 #include <konqmimedata.h>
59 #include <konq_operations.h>
60 #include <kpropertiesdialog.h>
61 #include <kprotocolinfo.h>
62 #include <ktoggleaction.h>
63 #include <krun.h>
64 #include <kshell.h>
65 #include <kstandarddirs.h>
66 #include <kstatusbar.h>
67 #include <kstandardaction.h>
68 #include <kurl.h>
69
70 #include <QCloseEvent>
71 #include <QClipboard>
72 #include <QSplitter>
73 #include <QDockWidget>
74
75 DolphinMainWindow::DolphinMainWindow(int id) :
76 KMainWindow(0),
77 m_newMenu(0),
78 m_splitter(0),
79 m_activeView(0),
80 m_id(id)
81 {
82 setObjectName("Dolphin");
83 m_view[PrimaryIdx] = 0;
84 m_view[SecondaryIdx] = 0;
85
86 new MainWindowAdaptor(this);
87 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id), this);
88
89 KonqUndoManager::incRef();
90
91 KonqUndoManager* undoManager = KonqUndoManager::self();
92 undoManager->setUiInterface(new UndoUiInterface(this));
93
94 connect(undoManager, SIGNAL(undoAvailable(bool)),
95 this, SLOT(slotUndoAvailable(bool)));
96 connect(undoManager, SIGNAL(undoTextChanged(const QString&)),
97 this, SLOT(slotUndoTextChanged(const QString&)));
98 }
99
100 DolphinMainWindow::~DolphinMainWindow()
101 {
102 KonqUndoManager::decRef();
103 DolphinApplication::app()->removeMainWindow(this);
104 }
105
106 void DolphinMainWindow::setActiveView(DolphinView* view)
107 {
108 Q_ASSERT((view == m_view[PrimaryIdx]) || (view == m_view[SecondaryIdx]));
109 if (m_activeView == view) {
110 return;
111 }
112
113 m_activeView = view;
114
115 updateHistory();
116 updateEditActions();
117 updateViewActions();
118 updateGoActions();
119
120 setCaption(m_activeView->url().fileName());
121
122 emit activeViewChanged();
123 }
124
125 void DolphinMainWindow::dropUrls(const KUrl::List& urls,
126 const KUrl& destination)
127 {
128 Qt::DropAction action = Qt::CopyAction;
129
130 Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
131 const bool shiftPressed = modifier & Qt::ShiftModifier;
132 const bool controlPressed = modifier & Qt::ControlModifier;
133 if (shiftPressed && controlPressed) {
134 // shortcut for 'Link Here' is used
135 action = Qt::LinkAction;
136 }
137 else if (shiftPressed) {
138 // shortcut for 'Move Here' is used
139 action = Qt::MoveAction;
140 }
141 else if (controlPressed) {
142 // shortcut for 'Copy Here' is used
143 action = Qt::CopyAction;
144 }
145 else {
146 // open a context menu which offers the following actions:
147 // - Move Here
148 // - Copy Here
149 // - Link Here
150 // - Cancel
151
152 KMenu popup(this);
153
154 QString seq = QKeySequence(Qt::ShiftModifier).toString();
155 seq.chop(1); // chop superfluous '+'
156 QAction* moveAction = popup.addAction(KIcon("goto-page"),
157 i18n("&Move Here") + '\t' + seq);
158
159 seq = QKeySequence(Qt::ControlModifier).toString();
160 seq.chop(1);
161 QAction* copyAction = popup.addAction(KIcon("edit-copy"),
162 i18n("&Copy Here") + '\t' + seq);
163
164 seq = QKeySequence(Qt::ControlModifier + Qt::ShiftModifier).toString();
165 seq.chop(1);
166 QAction* linkAction = popup.addAction(KIcon("www"),
167 i18n("&Link Here") + '\t' + seq);
168
169 popup.addSeparator();
170 popup.addAction(KIcon("process-stop"), i18n("Cancel"));
171
172 QAction* activatedAction = popup.exec(QCursor::pos());
173 if (activatedAction == moveAction) {
174 action = Qt::MoveAction;
175 }
176 else if (activatedAction == copyAction) {
177 action = Qt::CopyAction;
178 }
179 else if (activatedAction == linkAction) {
180 action = Qt::LinkAction;
181 }
182 else {
183 return;
184 }
185 }
186
187 switch (action) {
188 case Qt::MoveAction:
189 moveUrls(urls, destination);
190 break;
191
192 case Qt::CopyAction:
193 copyUrls(urls, destination);
194 break;
195
196 case Qt::LinkAction:
197 linkUrls(urls, destination);
198 break;
199
200 default:
201 break;
202 }
203 }
204
205 void DolphinMainWindow::rename(const KUrl& oldUrl, const KUrl& newUrl)
206 {
207 KonqOperations::rename(this, oldUrl, newUrl);
208 m_undoCommandTypes.append(KonqUndoManager::RENAME);
209 }
210
211 void DolphinMainWindow::refreshViews()
212 {
213 const bool split = DolphinSettings::instance().generalSettings()->splitView();
214 const bool isPrimaryViewActive = (m_activeView == m_view[PrimaryIdx]);
215 KUrl url;
216 for (int i = PrimaryIdx; i <= SecondaryIdx; ++i) {
217 if (m_view[i] != 0) {
218 url = m_view[i]->url();
219
220 // delete view instance...
221 m_view[i]->close();
222 m_view[i]->deleteLater();
223 m_view[i] = 0;
224 }
225
226 if (split || (i == PrimaryIdx)) {
227 // ... and recreate it
228 ViewProperties props(url);
229 m_view[i] = new DolphinView(this,
230 m_splitter,
231 url,
232 props.viewMode(),
233 props.showHiddenFiles());
234 connectViewSignals(i);
235 m_view[i]->show();
236 }
237 }
238
239 m_activeView = isPrimaryViewActive ? m_view[PrimaryIdx] : m_view[SecondaryIdx];
240 Q_ASSERT(m_activeView != 0);
241
242 updateViewActions();
243 emit activeViewChanged();
244 }
245
246 void DolphinMainWindow::changeUrl(const QString& url)
247 {
248 if (activeView() != 0) {
249 activeView()->setUrl(KUrl(url));
250 }
251 }
252
253 void DolphinMainWindow::slotViewModeChanged()
254 {
255 updateViewActions();
256 }
257
258 void DolphinMainWindow::slotShowPreviewChanged()
259 {
260 // It is not enough to update the 'Show Preview' action, also
261 // the 'Zoom In' and 'Zoom Out' actions must be adapted.
262 updateViewActions();
263 }
264
265 void DolphinMainWindow::slotShowHiddenFilesChanged()
266 {
267 KToggleAction* showHiddenFilesAction =
268 static_cast<KToggleAction*>(actionCollection()->action("show_hidden_files"));
269 showHiddenFilesAction->setChecked(m_activeView->showHiddenFiles());
270 }
271
272 void DolphinMainWindow::slotSortingChanged(DolphinView::Sorting sorting)
273 {
274 QAction* action = 0;
275 switch (sorting) {
276 case DolphinView::SortByName:
277 action = actionCollection()->action("by_name");
278 break;
279 case DolphinView::SortBySize:
280 action = actionCollection()->action("by_size");
281 break;
282 case DolphinView::SortByDate:
283 action = actionCollection()->action("by_date");
284 break;
285 case DolphinView::SortByPermissions:
286 action = actionCollection()->action("by_permissions");
287 break;
288 case DolphinView::SortByOwner:
289 action = actionCollection()->action("by_owner");
290 break;
291 case DolphinView::SortByGroup:
292 action = actionCollection()->action("by_group");
293 break;
294 default:
295 break;
296 }
297
298 if (action != 0) {
299 KToggleAction* toggleAction = static_cast<KToggleAction*>(action);
300 toggleAction->setChecked(true);
301 }
302 }
303
304 void DolphinMainWindow::slotSortOrderChanged(Qt::SortOrder order)
305 {
306 KToggleAction* descending = static_cast<KToggleAction*>(actionCollection()->action("descending"));
307 const bool sortDescending = (order == Qt::Descending);
308 descending->setChecked(sortDescending);
309 }
310
311 void DolphinMainWindow::slotAdditionalInfoChanged(KFileItemDelegate::AdditionalInformation info)
312 {
313 QAction* action = 0;
314 switch (info) {
315 case KFileItemDelegate::FriendlyMimeType:
316 action = actionCollection()->action("show_mime_info");
317 break;
318 case KFileItemDelegate::Size:
319 action = actionCollection()->action("show_size_info");
320 break;
321 case KFileItemDelegate::ModificationTime:
322 action = actionCollection()->action("show_date_info");
323 break;
324 case KFileItemDelegate::NoInformation:
325 default:
326 action = actionCollection()->action("clear_info");
327 break;
328 }
329
330 if (action != 0) {
331 KToggleAction* toggleAction = static_cast<KToggleAction*>(action);
332 toggleAction->setChecked(true);
333
334 QActionGroup* group = toggleAction->actionGroup();
335 Q_ASSERT(group != 0);
336 group->setEnabled(m_activeView->mode() == DolphinView::IconsView);
337 }
338 }
339
340 void DolphinMainWindow::slotSelectionChanged()
341 {
342 updateEditActions();
343
344 Q_ASSERT(m_view[PrimaryIdx] != 0);
345 int selectedUrlsCount = m_view[PrimaryIdx]->selectedUrls().count();
346 if (m_view[SecondaryIdx] != 0) {
347 selectedUrlsCount += m_view[SecondaryIdx]->selectedUrls().count();
348 }
349
350 QAction* compareFilesAction = actionCollection()->action("compare_files");
351 compareFilesAction->setEnabled(selectedUrlsCount == 2);
352
353 m_activeView->updateStatusBar();
354
355 emit selectionChanged();
356 }
357
358 void DolphinMainWindow::slotHistoryChanged()
359 {
360 updateHistory();
361 }
362
363 void DolphinMainWindow::slotUrlChanged(const KUrl& url)
364 {
365 updateEditActions();
366 updateViewActions();
367 updateGoActions();
368 setCaption(url.fileName());
369 }
370
371 void DolphinMainWindow::updateFilterBarAction(bool show)
372 {
373 KToggleAction* showFilterBarAction =
374 static_cast<KToggleAction*>(actionCollection()->action("show_filter_bar"));
375 showFilterBarAction->setChecked(show);
376 }
377
378 void DolphinMainWindow::openNewMainWindow()
379 {
380 DolphinApplication::app()->createMainWindow()->show();
381 }
382
383 void DolphinMainWindow::closeEvent(QCloseEvent* event)
384 {
385 DolphinSettings& settings = DolphinSettings::instance();
386 GeneralSettings* generalSettings = settings.generalSettings();
387 generalSettings->setFirstRun(false);
388
389 settings.save();
390
391 // TODO: I assume there will be a generic way in KDE 4 to store the docks
392 // of the main window. In the meantime they are stored manually:
393 QString filename = KStandardDirs::locateLocal("data", KGlobal::mainComponent().componentName());
394 filename.append("/panels_layout");
395 QFile file(filename);
396 if (file.open(QIODevice::WriteOnly)) {
397 QByteArray data = saveState();
398 file.write(data);
399 file.close();
400 }
401
402 KMainWindow::closeEvent(event);
403 }
404
405 void DolphinMainWindow::saveProperties(KConfig* config)
406 {
407 KConfigGroup primaryView = config->group("Primary view");
408 primaryView.writeEntry("Url", m_view[PrimaryIdx]->url().url());
409 primaryView.writeEntry("Editable Url", m_view[PrimaryIdx]->isUrlEditable());
410 if (m_view[SecondaryIdx] != 0) {
411 KConfigGroup secondaryView = config->group("Secondary view");
412 secondaryView.writeEntry("Url", m_view[SecondaryIdx]->url().url());
413 secondaryView.writeEntry("Editable Url", m_view[SecondaryIdx]->isUrlEditable());
414 }
415 }
416
417 void DolphinMainWindow::readProperties(KConfig* config)
418 {
419 const KConfigGroup primaryView = config->group("Primary view");
420 m_view[PrimaryIdx]->setUrl(primaryView.readEntry("Url"));
421 m_view[PrimaryIdx]->setUrlEditable(primaryView.readEntry("Editable Url", false));
422 if (config->hasGroup("Secondary view")) {
423 const KConfigGroup secondaryView = config->group("Secondary view");
424 if (m_view[SecondaryIdx] == 0) {
425 toggleSplitView();
426 }
427 m_view[SecondaryIdx]->setUrl(secondaryView.readEntry("Url"));
428 m_view[SecondaryIdx]->setUrlEditable(secondaryView.readEntry("Editable Url", false));
429 }
430 else if (m_view[SecondaryIdx] != 0) {
431 toggleSplitView();
432 }
433 }
434
435 void DolphinMainWindow::updateNewMenu()
436 {
437 m_newMenu->slotCheckUpToDate();
438 m_newMenu->setPopupFiles(activeView()->url());
439 }
440
441 void DolphinMainWindow::rename()
442 {
443 clearStatusBar();
444 m_activeView->renameSelectedItems();
445 }
446
447 void DolphinMainWindow::moveToTrash()
448 {
449 clearStatusBar();
450 const KUrl::List selectedUrls = m_activeView->selectedUrls();
451 KonqOperations::del(this, KonqOperations::TRASH, selectedUrls);
452 m_undoCommandTypes.append(KonqUndoManager::TRASH);
453 }
454
455 void DolphinMainWindow::deleteItems()
456 {
457 clearStatusBar();
458
459 KUrl::List list = m_activeView->selectedUrls();
460 const uint itemCount = list.count();
461 Q_ASSERT(itemCount >= 1);
462
463 QString text;
464 if (itemCount > 1) {
465 text = i18n("Do you really want to delete the %1 selected items?",itemCount);
466 }
467 else {
468 const KUrl& url = list.first();
469 text = i18n("Do you really want to delete '%1'?",url.fileName());
470 }
471
472 const bool del = KMessageBox::warningContinueCancel(this,
473 text,
474 QString(),
475 KGuiItem(i18n("Delete"), KIcon("edit-delete"))
476 ) == KMessageBox::Continue;
477 if (del) {
478 KIO::Job* job = KIO::del(list);
479 connect(job, SIGNAL(result(KJob*)),
480 this, SLOT(slotHandleJobError(KJob*)));
481 connect(job, SIGNAL(result(KJob*)),
482 this, SLOT(slotDeleteFileFinished(KJob*)));
483 }
484 }
485
486 void DolphinMainWindow::properties()
487 {
488 const KFileItemList list = m_activeView->selectedItems();
489 new KPropertiesDialog(list, this);
490 }
491
492 void DolphinMainWindow::quit()
493 {
494 close();
495 }
496
497 void DolphinMainWindow::slotHandleJobError(KJob* job)
498 {
499 if (job->error() != 0) {
500 DolphinStatusBar* statusBar = m_activeView->statusBar();
501 statusBar->setMessage(job->errorString(),
502 DolphinStatusBar::Error);
503 }
504 }
505
506 void DolphinMainWindow::slotDeleteFileFinished(KJob* job)
507 {
508 if (job->error() == 0) {
509 DolphinStatusBar* statusBar = m_activeView->statusBar();
510 statusBar->setMessage(i18n("Delete operation completed."),
511 DolphinStatusBar::OperationCompleted);
512 }
513 }
514
515 void DolphinMainWindow::slotUndoAvailable(bool available)
516 {
517 QAction* undoAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::Undo));
518 if (undoAction != 0) {
519 undoAction->setEnabled(available);
520 }
521
522 if (available && (m_undoCommandTypes.count() > 0)) {
523 const KonqUndoManager::CommandType command = m_undoCommandTypes.takeFirst();
524 DolphinStatusBar* statusBar = m_activeView->statusBar();
525 switch (command) {
526 case KonqUndoManager::COPY:
527 statusBar->setMessage(i18n("Copy operation completed."),
528 DolphinStatusBar::OperationCompleted);
529 break;
530 case KonqUndoManager::MOVE:
531 statusBar->setMessage(i18n("Move operation completed."),
532 DolphinStatusBar::OperationCompleted);
533 break;
534 case KonqUndoManager::LINK:
535 statusBar->setMessage(i18n("Link operation completed."),
536 DolphinStatusBar::OperationCompleted);
537 break;
538 case KonqUndoManager::TRASH:
539 statusBar->setMessage(i18n("Move to trash operation completed."),
540 DolphinStatusBar::OperationCompleted);
541 break;
542 case KonqUndoManager::RENAME:
543 statusBar->setMessage(i18n("Renaming operation completed."),
544 DolphinStatusBar::OperationCompleted);
545 break;
546
547 case KonqUndoManager::MKDIR:
548 statusBar->setMessage(i18n("Created directory."),
549 DolphinStatusBar::OperationCompleted);
550 break;
551
552 default:
553 break;
554 }
555
556 }
557 }
558
559 void DolphinMainWindow::slotUndoTextChanged(const QString& text)
560 {
561 QAction* undoAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::Undo));
562 if (undoAction != 0) {
563 undoAction->setText(text);
564 }
565 }
566
567 void DolphinMainWindow::undo()
568 {
569 clearStatusBar();
570 KonqUndoManager::self()->undo();
571 }
572
573 void DolphinMainWindow::cut()
574 {
575 QClipboard* clipboard = QApplication::clipboard();
576 const QMimeData* currentMimeData = clipboard->mimeData();
577 const bool hadCutSelection = KonqMimeData::decodeIsCutSelection(currentMimeData);
578
579 QMimeData* mimeData = new QMimeData();
580 const KUrl::List kdeUrls = m_activeView->selectedUrls();
581 const KUrl::List mostLocalUrls;
582 KonqMimeData::populateMimeData(mimeData, kdeUrls, mostLocalUrls, true);
583 QApplication::clipboard()->setMimeData(mimeData);
584
585 if (hadCutSelection) {
586 // If an old cut selection has been applied, the view must
587 // be reloaded to get the original icons of the items without an
588 // applied item effect.
589 m_view[PrimaryIdx]->reload();
590 if (m_view[SecondaryIdx] != 0) {
591 m_view[SecondaryIdx]->reload();
592 }
593 }
594 else {
595 // apply an item effect for the icons of all cut items
596 m_view[PrimaryIdx]->updateCutItems();
597 if (m_view[SecondaryIdx] != 0) {
598 m_view[SecondaryIdx]->updateCutItems();
599 }
600 }
601 }
602
603 void DolphinMainWindow::copy()
604 {
605 QMimeData* mimeData = new QMimeData();
606 const KUrl::List kdeUrls = m_activeView->selectedUrls();
607 const KUrl::List mostLocalUrls;
608 KonqMimeData::populateMimeData(mimeData, kdeUrls, mostLocalUrls, false);
609
610 QApplication::clipboard()->setMimeData(mimeData);
611 }
612
613 void DolphinMainWindow::paste()
614 {
615 QClipboard* clipboard = QApplication::clipboard();
616 const QMimeData* mimeData = clipboard->mimeData();
617
618 clearStatusBar();
619
620 const KUrl::List sourceUrls = KUrl::List::fromMimeData(mimeData);
621
622 // per default the pasting is done into the current Url of the view
623 KUrl destUrl(m_activeView->url());
624
625 // check whether the pasting should be done into a selected directory
626 KUrl::List selectedUrls = m_activeView->selectedUrls();
627 if (selectedUrls.count() == 1) {
628 const KFileItem fileItem(S_IFDIR,
629 KFileItem::Unknown,
630 selectedUrls.first(),
631 true);
632 if (fileItem.isDir()) {
633 // only one item is selected which is a directory, hence paste
634 // into this directory
635 destUrl = selectedUrls.first();
636 }
637 }
638
639 if (KonqMimeData::decodeIsCutSelection(mimeData)) {
640 moveUrls(sourceUrls, destUrl);
641 clipboard->clear();
642 }
643 else {
644 copyUrls(sourceUrls, destUrl);
645 }
646 }
647
648 void DolphinMainWindow::updatePasteAction()
649 {
650 QAction* pasteAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::Paste));
651 if (pasteAction == 0) {
652 return;
653 }
654
655 QString text(i18n("Paste"));
656 QClipboard* clipboard = QApplication::clipboard();
657 const QMimeData* mimeData = clipboard->mimeData();
658
659 KUrl::List urls = KUrl::List::fromMimeData(mimeData);
660 if (!urls.isEmpty()) {
661 pasteAction->setEnabled(true);
662
663 pasteAction->setText(i18np("Paste One File", "Paste %1 Files", urls.count()));
664 }
665 else {
666 pasteAction->setEnabled(false);
667 pasteAction->setText(i18n("Paste"));
668 }
669
670 if (pasteAction->isEnabled()) {
671 KUrl::List urls = m_activeView->selectedUrls();
672 const uint count = urls.count();
673 if (count > 1) {
674 // pasting should not be allowed when more than one file
675 // is selected
676 pasteAction->setEnabled(false);
677 }
678 else if (count == 1) {
679 // Only one file is selected. Pasting is only allowed if this
680 // file is a directory.
681 // TODO: this doesn't work with remote protocols; instead we need a
682 // m_activeView->selectedFileItems() to get the real KFileItems
683 const KFileItem fileItem(S_IFDIR,
684 KFileItem::Unknown,
685 urls.first(),
686 true);
687 pasteAction->setEnabled(fileItem.isDir());
688 }
689 }
690 }
691
692 void DolphinMainWindow::selectAll()
693 {
694 clearStatusBar();
695 m_activeView->selectAll();
696 }
697
698 void DolphinMainWindow::invertSelection()
699 {
700 clearStatusBar();
701 m_activeView->invertSelection();
702 }
703 void DolphinMainWindow::setIconsView()
704 {
705 m_activeView->setMode(DolphinView::IconsView);
706 }
707
708 void DolphinMainWindow::setDetailsView()
709 {
710 m_activeView->setMode(DolphinView::DetailsView);
711 }
712
713 void DolphinMainWindow::sortByName()
714 {
715 m_activeView->setSorting(DolphinView::SortByName);
716 }
717
718 void DolphinMainWindow::sortBySize()
719 {
720 m_activeView->setSorting(DolphinView::SortBySize);
721 }
722
723 void DolphinMainWindow::sortByDate()
724 {
725 m_activeView->setSorting(DolphinView::SortByDate);
726 }
727
728 void DolphinMainWindow::sortByPermissions()
729 {
730 m_activeView->setSorting(DolphinView::SortByPermissions);
731 }
732
733 void DolphinMainWindow::sortByOwner()
734 {
735 m_activeView->setSorting(DolphinView::SortByOwner);
736 }
737
738 void DolphinMainWindow::sortByGroup()
739 {
740 m_activeView->setSorting(DolphinView::SortByGroup);
741 }
742
743 void DolphinMainWindow::toggleSortOrder()
744 {
745 const Qt::SortOrder order = (m_activeView->sortOrder() == Qt::Ascending) ?
746 Qt::Descending :
747 Qt::Ascending;
748 m_activeView->setSortOrder(order);
749 }
750
751 void DolphinMainWindow::clearInfo()
752 {
753 m_activeView->setAdditionalInfo(KFileItemDelegate::NoInformation);
754 }
755
756 void DolphinMainWindow::showMimeInfo()
757 {
758 clearStatusBar();
759 m_activeView->setAdditionalInfo(KFileItemDelegate::FriendlyMimeType);
760 }
761
762 void DolphinMainWindow::showSizeInfo()
763 {
764 clearStatusBar();
765 m_activeView->setAdditionalInfo(KFileItemDelegate::Size);
766 }
767
768 void DolphinMainWindow::showDateInfo()
769 {
770 clearStatusBar();
771 m_activeView->setAdditionalInfo(KFileItemDelegate::ModificationTime);
772 }
773
774 void DolphinMainWindow::toggleSplitView()
775 {
776 if (m_view[SecondaryIdx] == 0) {
777 const int newWidth = (m_view[PrimaryIdx]->width() - m_splitter->handleWidth()) / 2;
778 // create a secondary view
779 m_view[SecondaryIdx] = new DolphinView(this,
780 0,
781 m_view[PrimaryIdx]->url(),
782 m_view[PrimaryIdx]->mode(),
783 m_view[PrimaryIdx]->showHiddenFiles());
784 connectViewSignals(SecondaryIdx);
785 m_splitter->addWidget(m_view[SecondaryIdx]);
786 m_splitter->setSizes(QList<int>() << newWidth << newWidth);
787 m_view[SecondaryIdx]->show();
788 }
789 else {
790 // remove secondary view
791 if (m_activeView == m_view[PrimaryIdx]) {
792 m_view[SecondaryIdx]->close();
793 m_view[SecondaryIdx]->deleteLater();
794 m_view[SecondaryIdx] = 0;
795 setActiveView(m_view[PrimaryIdx]);
796 }
797 else {
798 // The secondary view is active, hence from the users point of view
799 // the content of the secondary view should be moved to the primary view.
800 // From an implementation point of view it is more efficient to close
801 // the primary view and exchange the internal pointers afterwards.
802 m_view[PrimaryIdx]->close();
803 delete m_view[PrimaryIdx];
804 m_view[PrimaryIdx] = m_view[SecondaryIdx];
805 m_view[SecondaryIdx] = 0;
806 setActiveView(m_view[PrimaryIdx]);
807 }
808 }
809 emit activeViewChanged();
810 }
811
812 void DolphinMainWindow::reloadView()
813 {
814 clearStatusBar();
815 m_activeView->reload();
816 }
817
818 void DolphinMainWindow::stopLoading()
819 {
820 }
821
822 void DolphinMainWindow::togglePreview()
823 {
824 clearStatusBar();
825
826 const KToggleAction* showPreviewAction =
827 static_cast<KToggleAction*>(actionCollection()->action("show_preview"));
828 const bool show = showPreviewAction->isChecked();
829 m_activeView->setShowPreview(show);
830 }
831
832 void DolphinMainWindow::toggleShowHiddenFiles()
833 {
834 clearStatusBar();
835
836 const KToggleAction* showHiddenFilesAction =
837 static_cast<KToggleAction*>(actionCollection()->action("show_hidden_files"));
838 const bool show = showHiddenFilesAction->isChecked();
839 m_activeView->setShowHiddenFiles(show);
840 }
841
842 void DolphinMainWindow::showFilterBar()
843 {
844 const KToggleAction* showFilterBarAction =
845 static_cast<KToggleAction*>(actionCollection()->action("show_filter_bar"));
846 const bool show = showFilterBarAction->isChecked();
847 m_activeView->showFilterBar(show);
848 }
849
850 void DolphinMainWindow::zoomIn()
851 {
852 m_activeView->zoomIn();
853 updateViewActions();
854 }
855
856 void DolphinMainWindow::zoomOut()
857 {
858 m_activeView->zoomOut();
859 updateViewActions();
860 }
861
862 void DolphinMainWindow::toggleEditLocation()
863 {
864 clearStatusBar();
865
866 KToggleAction* action = static_cast<KToggleAction*>(actionCollection()->action("editable_location"));
867
868 bool editOrBrowse = action->isChecked();
869 m_activeView->setUrlEditable(editOrBrowse);
870 }
871
872 void DolphinMainWindow::editLocation()
873 {
874 m_activeView->setUrlEditable(true);
875 }
876
877 void DolphinMainWindow::adjustViewProperties()
878 {
879 clearStatusBar();
880 ViewPropertiesDialog dlg(m_activeView);
881 dlg.exec();
882 }
883
884 void DolphinMainWindow::goBack()
885 {
886 clearStatusBar();
887 m_activeView->goBack();
888 }
889
890 void DolphinMainWindow::goForward()
891 {
892 clearStatusBar();
893 m_activeView->goForward();
894 }
895
896 void DolphinMainWindow::goUp()
897 {
898 clearStatusBar();
899 m_activeView->goUp();
900 }
901
902 void DolphinMainWindow::goHome()
903 {
904 clearStatusBar();
905 m_activeView->goHome();
906 }
907
908 void DolphinMainWindow::openTerminal()
909 {
910 QString command("konsole --workdir \"");
911 command.append(m_activeView->url().path());
912 command.append('\"');
913
914 KRun::runCommand(command, "Konsole", "konsole");
915 }
916
917 void DolphinMainWindow::findFile()
918 {
919 KRun::run("kfind", m_activeView->url());
920 }
921
922 void DolphinMainWindow::compareFiles()
923 {
924 // The method is only invoked if exactly 2 files have
925 // been selected. The selected files may be:
926 // - both in the primary view
927 // - both in the secondary view
928 // - one in the primary view and the other in the secondary
929 // view
930 Q_ASSERT(m_view[PrimaryIdx] != 0);
931
932 KUrl urlA;
933 KUrl urlB;
934 KUrl::List urls = m_view[PrimaryIdx]->selectedUrls();
935
936 switch (urls.count()) {
937 case 0: {
938 Q_ASSERT(m_view[SecondaryIdx] != 0);
939 urls = m_view[SecondaryIdx]->selectedUrls();
940 Q_ASSERT(urls.count() == 2);
941 urlA = urls[0];
942 urlB = urls[1];
943 break;
944 }
945
946 case 1: {
947 urlA = urls[0];
948 Q_ASSERT(m_view[SecondaryIdx] != 0);
949 urls = m_view[SecondaryIdx]->selectedUrls();
950 Q_ASSERT(urls.count() == 1);
951 urlB = urls[0];
952 break;
953 }
954
955 case 2: {
956 urlA = urls[0];
957 urlB = urls[1];
958 break;
959 }
960
961 default: {
962 // may not happen: compareFiles may only get invoked if 2
963 // files are selected
964 Q_ASSERT(false);
965 }
966 }
967
968 QString command("kompare -c \"");
969 command.append(urlA.pathOrUrl());
970 command.append("\" \"");
971 command.append(urlB.pathOrUrl());
972 command.append('\"');
973 KRun::runCommand(command, "Kompare", "kompare");
974
975 }
976
977 void DolphinMainWindow::editSettings()
978 {
979 // TODO: make a static method for opening the settings dialog
980 DolphinSettingsDialog dlg(this);
981 dlg.exec();
982 }
983
984 void DolphinMainWindow::init()
985 {
986 // Check whether Dolphin runs the first time. If yes then
987 // a proper default window size is given at the end of DolphinMainWindow::init().
988 GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings();
989 const bool firstRun = generalSettings->firstRun();
990 if (firstRun) {
991 generalSettings->setViewPropsTimestamp(QDateTime::currentDateTime());
992 }
993
994 setAcceptDrops(true);
995
996 m_splitter = new QSplitter(this);
997
998 DolphinSettings& settings = DolphinSettings::instance();
999
1000 KBookmarkManager* manager = settings.bookmarkManager();
1001 Q_ASSERT(manager != 0);
1002 KBookmarkGroup root = manager->root();
1003 if (root.first().isNull()) {
1004 root.addBookmark(manager, i18n("Home"), settings.generalSettings()->homeUrl(), "folder-home");
1005 root.addBookmark(manager, i18n("Storage Media"), KUrl("media:/"), "hdd-mount");
1006 root.addBookmark(manager, i18n("Network"), KUrl("remote:/"), "network-local");
1007 root.addBookmark(manager, i18n("Root"), KUrl("/"), "folder-red");
1008 root.addBookmark(manager, i18n("Trash"), KUrl("trash:/"), "user-trash");
1009 }
1010
1011 setupActions();
1012
1013 const KUrl& homeUrl = settings.generalSettings()->homeUrl();
1014 setCaption(homeUrl.fileName());
1015 ViewProperties props(homeUrl);
1016 m_view[PrimaryIdx] = new DolphinView(this,
1017 m_splitter,
1018 homeUrl,
1019 props.viewMode(),
1020 props.showHiddenFiles());
1021 connectViewSignals(PrimaryIdx);
1022 m_view[PrimaryIdx]->show();
1023
1024 m_activeView = m_view[PrimaryIdx];
1025
1026 setCentralWidget(m_splitter);
1027 setupDockWidgets();
1028
1029 setupGUI(Keys|Save|Create|ToolBar);
1030 createGUI();
1031
1032 stateChanged("new_file");
1033 setAutoSaveSettings();
1034
1035 QClipboard* clipboard = QApplication::clipboard();
1036 connect(clipboard, SIGNAL(dataChanged()),
1037 this, SLOT(updatePasteAction()));
1038 updatePasteAction();
1039 updateGoActions();
1040
1041 loadSettings();
1042
1043 if (firstRun) {
1044 // assure a proper default size if Dolphin runs the first time
1045 resize(640, 480);
1046 }
1047 #ifdef HAVE_KMETADATA
1048 if (!DolphinApplication::app()->metadataLoader()->storageUp())
1049 activeView()->statusBar()->setMessage(i18n("Failed to contact Nepomuk service, annotation and tagging are disabled."), DolphinStatusBar::Error);
1050 #endif
1051 }
1052
1053 void DolphinMainWindow::loadSettings()
1054 {
1055 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
1056
1057 KToggleAction* splitAction = static_cast<KToggleAction*>(actionCollection()->action("split_view"));
1058 if (settings->splitView()) {
1059 splitAction->setChecked(true);
1060 toggleSplitView();
1061 }
1062
1063 updateViewActions();
1064
1065 // TODO: I assume there will be a generic way in KDE 4 to restore the docks
1066 // of the main window. In the meantime they are restored manually (see also
1067 // DolphinMainWindow::closeEvent() for more details):
1068 QString filename = KStandardDirs::locateLocal("data", KGlobal::mainComponent().componentName()); filename.append("/panels_layout");
1069 QFile file(filename);
1070 if (file.open(QIODevice::ReadOnly)) {
1071 QByteArray data = file.readAll();
1072 restoreState(data);
1073 file.close();
1074 }
1075 }
1076
1077 void DolphinMainWindow::setupActions()
1078 {
1079 // setup 'File' menu
1080 m_newMenu = new DolphinNewMenu(this);
1081 KMenu* menu = m_newMenu->menu();
1082 menu->setTitle(i18n("Create New..."));
1083 menu->setIcon(SmallIcon("document-new"));
1084 connect(menu, SIGNAL(aboutToShow()),
1085 this, SLOT(updateNewMenu()));
1086
1087 QAction* newWindow = actionCollection()->addAction("new_window");
1088 newWindow->setIcon(KIcon("window-new"));
1089 newWindow->setText(i18n("New &Window"));
1090 newWindow->setShortcut(Qt::CTRL | Qt::Key_N);
1091 connect(newWindow, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1092
1093 QAction* rename = actionCollection()->addAction("rename");
1094 rename->setText(i18n("Rename"));
1095 rename->setShortcut(Qt::Key_F2);
1096 connect(rename, SIGNAL(triggered()), this, SLOT(rename()));
1097
1098 QAction* moveToTrash = actionCollection()->addAction("move_to_trash");
1099 moveToTrash->setText(i18n("Move to Trash"));
1100 moveToTrash->setIcon(KIcon("edit-trash"));
1101 moveToTrash->setShortcut(QKeySequence::Delete);
1102 connect(moveToTrash, SIGNAL(triggered()), this, SLOT(moveToTrash()));
1103
1104 QAction* deleteAction = actionCollection()->addAction("delete");
1105 deleteAction->setText(i18n("Delete"));
1106 deleteAction->setShortcut(Qt::SHIFT | Qt::Key_Delete);
1107 deleteAction->setIcon(KIcon("edit-delete"));
1108 connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItems()));
1109
1110 QAction* properties = actionCollection()->addAction("properties");
1111 properties->setText(i18n("Properties"));
1112 properties->setShortcut(Qt::ALT | Qt::Key_Return);
1113 connect(properties, SIGNAL(triggered()), this, SLOT(properties()));
1114
1115 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1116
1117 // setup 'Edit' menu
1118 KStandardAction::undo(this,
1119 SLOT(undo()),
1120 actionCollection());
1121
1122 KStandardAction::cut(this, SLOT(cut()), actionCollection());
1123 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1124 KStandardAction::paste(this, SLOT(paste()), actionCollection());
1125
1126 QAction* selectAll = actionCollection()->addAction("select_all");
1127 selectAll->setText(i18n("Select All"));
1128 selectAll->setShortcut(Qt::CTRL + Qt::Key_A);
1129 connect(selectAll, SIGNAL(triggered()), this, SLOT(selectAll()));
1130
1131 QAction* invertSelection = actionCollection()->addAction("invert_selection");
1132 invertSelection->setText(i18n("Invert Selection"));
1133 invertSelection->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_A);
1134 connect(invertSelection, SIGNAL(triggered()), this, SLOT(invertSelection()));
1135
1136 // setup 'View' menu
1137 KStandardAction::zoomIn(this,
1138 SLOT(zoomIn()),
1139 actionCollection());
1140
1141 KStandardAction::zoomOut(this,
1142 SLOT(zoomOut()),
1143 actionCollection());
1144
1145 KToggleAction* iconsView = actionCollection()->add<KToggleAction>("icons");
1146 iconsView->setText(i18n("Icons"));
1147 iconsView->setShortcut(Qt::CTRL | Qt::Key_1);
1148 iconsView->setIcon(KIcon("view-icon"));
1149 connect(iconsView, SIGNAL(triggered()), this, SLOT(setIconsView()));
1150
1151 KToggleAction* detailsView = actionCollection()->add<KToggleAction>("details");
1152 detailsView->setText(i18n("Details"));
1153 detailsView->setShortcut(Qt::CTRL | Qt::Key_2);
1154 detailsView->setIcon(KIcon("fileview-text"));
1155 connect(detailsView, SIGNAL(triggered()), this, SLOT(setDetailsView()));
1156
1157 QActionGroup* viewModeGroup = new QActionGroup(this);
1158 viewModeGroup->addAction(iconsView);
1159 viewModeGroup->addAction(detailsView);
1160
1161 KToggleAction* sortByName = actionCollection()->add<KToggleAction>("by_name");
1162 sortByName->setText(i18n("By Name"));
1163 connect(sortByName, SIGNAL(triggered()), this, SLOT(sortByName()));
1164
1165 KToggleAction* sortBySize = actionCollection()->add<KToggleAction>("by_size");
1166 sortBySize->setText(i18n("By Size"));
1167 connect(sortBySize, SIGNAL(triggered()), this, SLOT(sortBySize()));
1168
1169 KToggleAction* sortByDate = actionCollection()->add<KToggleAction>("by_date");
1170 sortByDate->setText(i18n("By Date"));
1171 connect(sortByDate, SIGNAL(triggered()), this, SLOT(sortByDate()));
1172
1173 KToggleAction* sortByPermissions = actionCollection()->add<KToggleAction>("by_permissions");
1174 sortByPermissions->setText(i18n("By Permissions"));
1175 connect(sortByPermissions, SIGNAL(triggered()), this, SLOT(sortByPermissions()));
1176
1177 KToggleAction* sortByOwner = actionCollection()->add<KToggleAction>("by_owner");
1178 sortByOwner->setText(i18n("By Owner"));
1179 connect(sortByOwner, SIGNAL(triggered()), this, SLOT(sortByOwner()));
1180
1181 KToggleAction* sortByGroup = actionCollection()->add<KToggleAction>("by_group");
1182 sortByGroup->setText(i18n("By Group"));
1183 connect(sortByGroup, SIGNAL(triggered()), this, SLOT(sortByGroup()));
1184
1185 QActionGroup* sortGroup = new QActionGroup(this);
1186 sortGroup->addAction(sortByName);
1187 sortGroup->addAction(sortBySize);
1188 sortGroup->addAction(sortByDate);
1189 sortGroup->addAction(sortByPermissions);
1190 sortGroup->addAction(sortByOwner);
1191 sortGroup->addAction(sortByGroup);
1192
1193 KToggleAction* sortDescending = actionCollection()->add<KToggleAction>("descending");
1194 sortDescending->setText(i18n("Descending"));
1195 connect(sortDescending, SIGNAL(triggered()), this, SLOT(toggleSortOrder()));
1196
1197 KToggleAction* clearInfo = actionCollection()->add<KToggleAction>("clear_info");
1198 clearInfo->setText(i18n("No Information"));
1199 connect(clearInfo, SIGNAL(triggered()), this, SLOT(clearInfo()));
1200
1201 KToggleAction* showMimeInfo = actionCollection()->add<KToggleAction>("show_mime_info");
1202 showMimeInfo->setText(i18n("Type"));
1203 connect(showMimeInfo, SIGNAL(triggered()), this, SLOT(showMimeInfo()));
1204
1205 KToggleAction* showSizeInfo = actionCollection()->add<KToggleAction>("show_size_info");
1206 showSizeInfo->setText(i18n("Size"));
1207 connect(showSizeInfo, SIGNAL(triggered()), this, SLOT(showSizeInfo()));
1208
1209 KToggleAction* showDateInfo = actionCollection()->add<KToggleAction>("show_date_info");
1210 showDateInfo->setText(i18n("Date"));
1211 connect(showDateInfo, SIGNAL(triggered()), this, SLOT(showDateInfo()));
1212
1213 QActionGroup* infoGroup = new QActionGroup(this);
1214 infoGroup->addAction(clearInfo);
1215 infoGroup->addAction(showMimeInfo);
1216 infoGroup->addAction(showSizeInfo);
1217 infoGroup->addAction(showDateInfo);
1218
1219 KToggleAction* showPreview = actionCollection()->add<KToggleAction>("show_preview");
1220 showPreview->setText(i18n("Preview"));
1221 showPreview->setIcon(KIcon("thumbnail-show"));
1222 connect(showPreview, SIGNAL(triggered()), this, SLOT(togglePreview()));
1223
1224 KToggleAction* showHiddenFiles = actionCollection()->add<KToggleAction>("show_hidden_files");
1225 showHiddenFiles->setText(i18n("Show Hidden Files"));
1226 showHiddenFiles->setShortcut(Qt::ALT | Qt::Key_Period);
1227 connect(showHiddenFiles, SIGNAL(triggered()), this, SLOT(toggleShowHiddenFiles()));
1228
1229 KToggleAction* split = actionCollection()->add<KToggleAction>("split_view");
1230 split->setText(i18n("Split"));
1231 split->setShortcut(Qt::Key_F10);
1232 split->setIcon(KIcon("view-left-right"));
1233 connect(split, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1234
1235 QAction* reload = actionCollection()->addAction("reload");
1236 reload->setText(i18n("Reload"));
1237 reload->setShortcut(Qt::Key_F5);
1238 reload->setIcon(KIcon("view-refresh"));
1239 connect(reload, SIGNAL(triggered()), this, SLOT(reloadView()));
1240
1241 QAction* stop = actionCollection()->addAction("stop");
1242 stop->setText(i18n("Stop"));
1243 stop->setIcon(KIcon("process-stop"));
1244 connect(stop, SIGNAL(triggered()), this, SLOT(stopLoading()));
1245
1246 // TODO: the URL navigator must emit a signal if the editable state has been
1247 // changed, so that the corresponding showFullLocation action is updated. Also
1248 // the naming "Show full Location" is currently confusing...
1249 KToggleAction* showFullLocation = actionCollection()->add<KToggleAction>("editable_location");
1250 showFullLocation->setText(i18n("Show Full Location"));
1251 showFullLocation->setShortcut(Qt::CTRL | Qt::Key_L);
1252 connect(showFullLocation, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1253
1254 QAction* editLocation = actionCollection()->addAction("edit_location");
1255 editLocation->setText(i18n("Edit Location"));
1256 editLocation->setShortcut(Qt::Key_F6);
1257 connect(editLocation, SIGNAL(triggered()), this, SLOT(editLocation()));
1258
1259 QAction* adjustViewProps = actionCollection()->addAction("view_properties");
1260 adjustViewProps->setText(i18n("Adjust View Properties..."));
1261 connect(adjustViewProps, SIGNAL(triggered()), this, SLOT(adjustViewProperties()));
1262
1263 // setup 'Go' menu
1264 KStandardAction::back(this, SLOT(goBack()), actionCollection());
1265 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1266 KStandardAction::up(this, SLOT(goUp()), actionCollection());
1267 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1268
1269 // setup 'Tools' menu
1270 QAction* openTerminal = actionCollection()->addAction("open_terminal");
1271 openTerminal->setText(i18n("Open Terminal"));
1272 openTerminal->setShortcut(Qt::Key_F4);
1273 openTerminal->setIcon(KIcon("konsole"));
1274 connect(openTerminal, SIGNAL(triggered()), this, SLOT(openTerminal()));
1275
1276 QAction* findFile = actionCollection()->addAction("find_file");
1277 findFile->setText(i18n("Find File..."));
1278 findFile->setShortcut(Qt::Key_F);
1279 findFile->setIcon(KIcon("file-find"));
1280 connect(findFile, SIGNAL(triggered()), this, SLOT(findFile()));
1281
1282 KToggleAction* showFilterBar = actionCollection()->add<KToggleAction>("show_filter_bar");
1283 showFilterBar->setText(i18n("Show Filter Bar"));
1284 showFilterBar->setShortcut(Qt::Key_Slash);
1285 connect(showFilterBar, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1286
1287 QAction* compareFiles = actionCollection()->addAction("compare_files");
1288 compareFiles->setText(i18n("Compare Files"));
1289 compareFiles->setIcon(KIcon("kompare"));
1290 compareFiles->setEnabled(false);
1291 connect(compareFiles, SIGNAL(triggered()), this, SLOT(compareFiles()));
1292
1293 // setup 'Settings' menu
1294 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1295 }
1296
1297 void DolphinMainWindow::setupDockWidgets()
1298 {
1299 // TODO: there's a lot copy/paste code here. Provide a generic approach
1300 // after the dock concept has been finalized.
1301
1302 // setup "Bookmarks"
1303 QDockWidget* shortcutsDock = new QDockWidget(i18n("Bookmarks"));
1304 shortcutsDock->setObjectName("bookmarksDock");
1305 shortcutsDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1306 shortcutsDock->setWidget(new BookmarksSidebarPage(this));
1307
1308 shortcutsDock->toggleViewAction()->setText(i18n("Show Bookmarks Panel"));
1309 actionCollection()->addAction("show_bookmarks_panel", shortcutsDock->toggleViewAction());
1310
1311 addDockWidget(Qt::LeftDockWidgetArea, shortcutsDock);
1312
1313 // setup "Information"
1314 QDockWidget* infoDock = new QDockWidget(i18n("Information"));
1315 infoDock->setObjectName("infoDock");
1316 infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1317 infoDock->setWidget(new InfoSidebarPage(this));
1318
1319 infoDock->toggleViewAction()->setText(i18n("Show Information Panel"));
1320 actionCollection()->addAction("show_info_panel", infoDock->toggleViewAction());
1321
1322 addDockWidget(Qt::RightDockWidgetArea, infoDock);
1323
1324 // setup "Tree View"
1325 QDockWidget* treeViewDock = new QDockWidget(i18n("Folders")); // TODO: naming?
1326 treeViewDock->setObjectName("treeViewDock");
1327 treeViewDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1328 treeViewDock->setWidget(new TreeViewSidebarPage(this));
1329
1330 treeViewDock->toggleViewAction()->setText(i18n("Show Folders Panel"));
1331 actionCollection()->addAction("show_folders_panel", treeViewDock->toggleViewAction());
1332
1333 addDockWidget(Qt::LeftDockWidgetArea, treeViewDock);
1334
1335 const bool firstRun = DolphinSettings::instance().generalSettings()->firstRun();
1336 if (firstRun) {
1337 infoDock->hide();
1338 treeViewDock->hide();
1339 }
1340 }
1341
1342 void DolphinMainWindow::updateHistory()
1343 {
1344 int index = 0;
1345 const QLinkedList<UrlNavigator::HistoryElem> list = m_activeView->urlHistory(index);
1346
1347 QAction* backAction = actionCollection()->action("go_back");
1348 if (backAction != 0) {
1349 backAction->setEnabled(index < static_cast<int>(list.count()) - 1);
1350 }
1351
1352 QAction* forwardAction = actionCollection()->action("go_forward");
1353 if (forwardAction != 0) {
1354 forwardAction->setEnabled(index > 0);
1355 }
1356 }
1357
1358 void DolphinMainWindow::updateEditActions()
1359 {
1360 const KFileItemList list = m_activeView->selectedItems();
1361 if (list.isEmpty()) {
1362 stateChanged("has_no_selection");
1363 }
1364 else {
1365 stateChanged("has_selection");
1366
1367 QAction* renameAction = actionCollection()->action("rename");
1368 if (renameAction != 0) {
1369 renameAction->setEnabled(list.count() >= 1);
1370 }
1371
1372 bool enableMoveToTrash = true;
1373
1374 KFileItemList::const_iterator it = list.begin();
1375 const KFileItemList::const_iterator end = list.end();
1376 while (it != end) {
1377 KFileItem* item = *it;
1378 const KUrl& url = item->url();
1379 // only enable the 'Move to Trash' action for local files
1380 if (!url.isLocalFile()) {
1381 enableMoveToTrash = false;
1382 }
1383 ++it;
1384 }
1385
1386 QAction* moveToTrashAction = actionCollection()->action("move_to_trash");
1387 moveToTrashAction->setEnabled(enableMoveToTrash);
1388 }
1389 updatePasteAction();
1390 }
1391
1392 void DolphinMainWindow::updateViewActions()
1393 {
1394 QAction* zoomInAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::ZoomIn));
1395 if (zoomInAction != 0) {
1396 zoomInAction->setEnabled(m_activeView->isZoomInPossible());
1397 }
1398
1399 QAction* zoomOutAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::ZoomOut));
1400 if (zoomOutAction != 0) {
1401 zoomOutAction->setEnabled(m_activeView->isZoomOutPossible());
1402 }
1403
1404 QAction* action = 0;
1405 switch (m_activeView->mode()) {
1406 case DolphinView::IconsView:
1407 action = actionCollection()->action("icons");
1408 break;
1409 case DolphinView::DetailsView:
1410 action = actionCollection()->action("details");
1411 break;
1412 default:
1413 break;
1414 }
1415
1416 if (action != 0) {
1417 KToggleAction* toggleAction = static_cast<KToggleAction*>(action);
1418 toggleAction->setChecked(true);
1419 }
1420
1421 slotSortingChanged(m_activeView->sorting());
1422 slotSortOrderChanged(m_activeView->sortOrder());
1423 slotAdditionalInfoChanged(m_activeView->additionalInfo());
1424
1425 KToggleAction* showFilterBarAction =
1426 static_cast<KToggleAction*>(actionCollection()->action("show_filter_bar"));
1427 showFilterBarAction->setChecked(m_activeView->isFilterBarVisible());
1428
1429 KToggleAction* showPreviewAction =
1430 static_cast<KToggleAction*>(actionCollection()->action("show_preview"));
1431 showPreviewAction->setChecked(m_activeView->showPreview());
1432
1433 KToggleAction* showHiddenFilesAction =
1434 static_cast<KToggleAction*>(actionCollection()->action("show_hidden_files"));
1435 showHiddenFilesAction->setChecked(m_activeView->showHiddenFiles());
1436
1437 KToggleAction* splitAction = static_cast<KToggleAction*>(actionCollection()->action("split_view"));
1438 splitAction->setChecked(m_view[SecondaryIdx] != 0);
1439
1440 KToggleAction* editableLocactionAction =
1441 static_cast<KToggleAction*>(actionCollection()->action("editable_location"));
1442 editableLocactionAction->setChecked(m_activeView->isUrlEditable());
1443 }
1444
1445 void DolphinMainWindow::updateGoActions()
1446 {
1447 QAction* goUpAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::Up));
1448 const KUrl& currentUrl = m_activeView->url();
1449 goUpAction->setEnabled(currentUrl.upUrl() != currentUrl);
1450 }
1451
1452 void DolphinMainWindow::copyUrls(const KUrl::List& source, const KUrl& dest)
1453 {
1454 KonqOperations::copy(this, KonqOperations::COPY, source, dest);
1455 m_undoCommandTypes.append(KonqUndoManager::COPY);
1456 }
1457
1458 void DolphinMainWindow::moveUrls(const KUrl::List& source, const KUrl& dest)
1459 {
1460 KonqOperations::copy(this, KonqOperations::MOVE, source, dest);
1461 m_undoCommandTypes.append(KonqUndoManager::MOVE);
1462 }
1463
1464 void DolphinMainWindow::linkUrls(const KUrl::List& source, const KUrl& dest)
1465 {
1466 KonqOperations::copy(this, KonqOperations::LINK, source, dest);
1467 m_undoCommandTypes.append(KonqUndoManager::LINK);
1468 }
1469
1470 void DolphinMainWindow::clearStatusBar()
1471 {
1472 m_activeView->statusBar()->clear();
1473 }
1474
1475 void DolphinMainWindow::connectViewSignals(int viewIndex)
1476 {
1477 DolphinView* view = m_view[viewIndex];
1478 connect(view, SIGNAL(modeChanged()),
1479 this, SLOT(slotViewModeChanged()));
1480 connect(view, SIGNAL(showPreviewChanged()),
1481 this, SLOT(slotShowPreviewChanged()));
1482 connect(view, SIGNAL(showHiddenFilesChanged()),
1483 this, SLOT(slotShowHiddenFilesChanged()));
1484 connect(view, SIGNAL(sortingChanged(DolphinView::Sorting)),
1485 this, SLOT(slotSortingChanged(DolphinView::Sorting)));
1486 connect(view, SIGNAL(sortOrderChanged(Qt::SortOrder)),
1487 this, SLOT(slotSortOrderChanged(Qt::SortOrder)));
1488 connect(view, SIGNAL(additionalInfoChanged(KFileItemDelegate::AdditionalInformation)),
1489 this, SLOT(slotAdditionalInfoChanged(KFileItemDelegate::AdditionalInformation)));
1490 connect(view, SIGNAL(selectionChanged()),
1491 this, SLOT(slotSelectionChanged()));
1492 connect(view, SIGNAL(showFilterBarChanged(bool)),
1493 this, SLOT(updateFilterBarAction(bool)));
1494
1495 const UrlNavigator* navigator = view->urlNavigator();
1496 connect(navigator, SIGNAL(urlChanged(const KUrl&)),
1497 this, SLOT(slotUrlChanged(const KUrl&)));
1498 connect(navigator, SIGNAL(historyChanged()),
1499 this, SLOT(slotHistoryChanged()));
1500
1501 }
1502
1503 DolphinMainWindow::UndoUiInterface::UndoUiInterface(DolphinMainWindow* mainWin) :
1504 KonqUndoManager::UiInterface(mainWin),
1505 m_mainWin(mainWin)
1506 {
1507 Q_ASSERT(m_mainWin != 0);
1508 }
1509
1510 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1511 {
1512 }
1513
1514 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job)
1515 {
1516 DolphinStatusBar* statusBar = m_mainWin->activeView()->statusBar();
1517 statusBar->setMessage(job->errorString(), DolphinStatusBar::Error);
1518 }
1519
1520 #include "dolphinmainwindow.moc"