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