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