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