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