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