]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
SVN_SILENT: coding style fix (m_metadataWidget -> m_metaDataWidget)
[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 "dolphinmainwindow.h"
23 #include "dolphinviewactionhandler.h"
24 #include "dolphindropcontroller.h"
25
26 #include <config-nepomuk.h>
27
28 #include "dolphinapplication.h"
29 #include "dolphinfileplacesview.h"
30 #include "dolphinnewmenu.h"
31 #include "dolphinsettings.h"
32 #include "dolphinsettingsdialog.h"
33 #include "dolphinstatusbar.h"
34 #include "dolphinviewcontainer.h"
35 #include "infosidebarpage.h"
36 #include "metadatawidget.h"
37 #include "mainwindowadaptor.h"
38 #include "terminalsidebarpage.h"
39 #include "treeviewsidebarpage.h"
40 #include "viewpropertiesdialog.h"
41 #include "viewproperties.h"
42
43 #include "dolphin_generalsettings.h"
44 #include "dolphin_iconsmodesettings.h"
45
46 #include <kaction.h>
47 #include <kactioncollection.h>
48 #include <kconfig.h>
49 #include <kdesktopfile.h>
50 #include <kdeversion.h>
51 #include <kfiledialog.h>
52 #include <kfileplacesmodel.h>
53 #include <kglobal.h>
54 #include <kicon.h>
55 #include <kiconloader.h>
56 #include <kio/netaccess.h>
57 #include <kinputdialog.h>
58 #include <klocale.h>
59 #include <kmenu.h>
60 #include <kmenubar.h>
61 #include <kmessagebox.h>
62 #include <kurlnavigator.h>
63 #include <konqmimedata.h>
64 #include <kpropertiesdialog.h>
65 #include <kprotocolinfo.h>
66 #include <ktoggleaction.h>
67 #include <krun.h>
68 #include <kshell.h>
69 #include <kstandarddirs.h>
70 #include <kstatusbar.h>
71 #include <kstandardaction.h>
72 #include <kurl.h>
73 #include <kurlcombobox.h>
74
75 #include <QKeyEvent>
76 #include <QClipboard>
77 #include <QLineEdit>
78 #include <QSplitter>
79 #include <QDockWidget>
80
81 DolphinMainWindow::DolphinMainWindow(int id) :
82 KXmlGuiWindow(0),
83 m_newMenu(0),
84 m_showMenuBar(0),
85 m_splitter(0),
86 m_activeViewContainer(0),
87 m_id(id)
88 {
89 setObjectName("Dolphin");
90 m_viewContainer[PrimaryView] = 0;
91 m_viewContainer[SecondaryView] = 0;
92
93 new MainWindowAdaptor(this);
94 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id), this);
95
96 KonqFileUndoManager::incRef();
97
98 KonqFileUndoManager* undoManager = KonqFileUndoManager::self();
99 undoManager->setUiInterface(new UndoUiInterface(this));
100
101 connect(undoManager, SIGNAL(undoAvailable(bool)),
102 this, SLOT(slotUndoAvailable(bool)));
103 connect(undoManager, SIGNAL(undoTextChanged(const QString&)),
104 this, SLOT(slotUndoTextChanged(const QString&)));
105 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString&)),
106 this, SLOT(slotHandlePlacesError(const QString&)));
107 }
108
109 DolphinMainWindow::~DolphinMainWindow()
110 {
111 KonqFileUndoManager::decRef();
112 DolphinApplication::app()->removeMainWindow(this);
113 }
114
115 void DolphinMainWindow::toggleViews()
116 {
117 if (m_viewContainer[SecondaryView] == 0) {
118 return;
119 }
120
121 // move secondary view from the last position of the splitter
122 // to the first position
123 m_splitter->insertWidget(0, m_viewContainer[SecondaryView]);
124
125 DolphinViewContainer* container = m_viewContainer[PrimaryView];
126 m_viewContainer[PrimaryView] = m_viewContainer[SecondaryView];
127 m_viewContainer[SecondaryView] = container;
128 }
129
130 void DolphinMainWindow::slotDoingOperation(KonqFileUndoManager::CommandType commandType)
131 {
132 clearStatusBar();
133 m_undoCommandTypes.append(commandType);
134 }
135
136 void DolphinMainWindow::refreshViews()
137 {
138 Q_ASSERT(m_viewContainer[PrimaryView] != 0);
139
140 // remember the current active view, as because of
141 // the refreshing the active view might change to
142 // the secondary view
143 DolphinViewContainer* activeViewContainer = m_activeViewContainer;
144
145 m_viewContainer[PrimaryView]->view()->refresh();
146 if (m_viewContainer[SecondaryView] != 0) {
147 m_viewContainer[SecondaryView]->view()->refresh();
148 }
149
150 setActiveViewContainer(activeViewContainer);
151 }
152
153 void DolphinMainWindow::dropUrls(const KUrl::List& urls,
154 const KUrl& destination)
155 {
156 DolphinDropController dropController(this);
157 connect(&dropController, SIGNAL(doingOperation(KonqFileUndoManager::CommandType)),
158 this, SLOT(slotDoingOperation(KonqFileUndoManager::CommandType)));
159 dropController.dropUrls(urls, destination);
160 }
161
162 void DolphinMainWindow::changeUrl(const KUrl& url)
163 {
164 DolphinViewContainer* view = activeViewContainer();
165 if (view != 0) {
166 view->setUrl(url);
167 updateEditActions();
168 updateViewActions();
169 updateGoActions();
170 setCaption(url.fileName());
171 emit urlChanged(url);
172 }
173 }
174
175 void DolphinMainWindow::changeSelection(const KFileItemList& selection)
176 {
177 activeViewContainer()->view()->changeSelection(selection);
178 }
179
180 void DolphinMainWindow::slotEditableStateChanged(bool editable)
181 {
182 KToggleAction* editableLocationAction =
183 static_cast<KToggleAction*>(actionCollection()->action("editable_location"));
184 editableLocationAction->setChecked(editable);
185 }
186
187 void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection)
188 {
189 updateEditActions();
190
191 Q_ASSERT(m_viewContainer[PrimaryView] != 0);
192 int selectedUrlsCount = m_viewContainer[PrimaryView]->view()->selectedUrls().count();
193 if (m_viewContainer[SecondaryView] != 0) {
194 selectedUrlsCount += m_viewContainer[SecondaryView]->view()->selectedUrls().count();
195 }
196
197 QAction* compareFilesAction = actionCollection()->action("compare_files");
198 if (selectedUrlsCount == 2) {
199 const bool kompareInstalled = !KGlobal::dirs()->findExe("kompare").isEmpty();
200 compareFilesAction->setEnabled(selectedUrlsCount == 2 && kompareInstalled);
201 } else {
202 compareFilesAction->setEnabled(false);
203 }
204
205 m_activeViewContainer->updateStatusBar();
206
207 emit selectionChanged(selection);
208 }
209
210 void DolphinMainWindow::slotRequestItemInfo(const KFileItem& item)
211 {
212 emit requestItemInfo(item);
213 }
214
215 void DolphinMainWindow::slotHistoryChanged()
216 {
217 updateHistory();
218 }
219
220 void DolphinMainWindow::updateFilterBarAction(bool show)
221 {
222 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
223 showFilterBarAction->setChecked(show);
224 }
225
226 void DolphinMainWindow::openNewMainWindow()
227 {
228 DolphinApplication::app()->createMainWindow()->show();
229 }
230
231 void DolphinMainWindow::toggleActiveView()
232 {
233 if (m_viewContainer[SecondaryView] == 0) {
234 // only one view is available
235 return;
236 }
237
238 Q_ASSERT(m_activeViewContainer != 0);
239 Q_ASSERT(m_viewContainer[PrimaryView] != 0);
240
241 DolphinViewContainer* left = m_viewContainer[PrimaryView];
242 DolphinViewContainer* right = m_viewContainer[SecondaryView];
243 setActiveViewContainer(m_activeViewContainer == right ? left : right);
244 }
245
246 void DolphinMainWindow::closeEvent(QCloseEvent* event)
247 {
248 DolphinSettings& settings = DolphinSettings::instance();
249 GeneralSettings* generalSettings = settings.generalSettings();
250 generalSettings->setFirstRun(false);
251
252 settings.save();
253
254 KXmlGuiWindow::closeEvent(event);
255 }
256
257 void DolphinMainWindow::saveProperties(KConfigGroup& group)
258 {
259 DolphinViewContainer* cont = m_viewContainer[PrimaryView];
260 group.writeEntry("Primary Url", cont->url().url());
261 group.writeEntry("Primary Editable Url", cont->isUrlEditable());
262
263 cont = m_viewContainer[SecondaryView];
264 if (cont != 0) {
265 group.writeEntry("Secondary Url", cont->url().url());
266 group.writeEntry("Secondary Editable Url", cont->isUrlEditable());
267 }
268 }
269
270 void DolphinMainWindow::readProperties(const KConfigGroup& group)
271 {
272 DolphinViewContainer* cont = m_viewContainer[PrimaryView];
273
274 cont->setUrl(group.readEntry("Primary Url"));
275 bool editable = group.readEntry("Primary Editable Url", false);
276 cont->urlNavigator()->setUrlEditable(editable);
277
278 cont = m_viewContainer[SecondaryView];
279 const QString secondaryUrl = group.readEntry("Secondary Url");
280 if (!secondaryUrl.isEmpty()) {
281 if (cont == 0) {
282 // a secondary view should be shown, but no one is available
283 // currently -> create a new view
284 toggleSplitView();
285 cont = m_viewContainer[SecondaryView];
286 Q_ASSERT(cont != 0);
287 }
288
289 cont->setUrl(secondaryUrl);
290 bool editable = group.readEntry("Secondary Editable Url", false);
291 cont->urlNavigator()->setUrlEditable(editable);
292 } else if (cont != 0) {
293 // no secondary view should be shown, but the default setting shows
294 // one already -> close the view
295 toggleSplitView();
296 }
297 }
298
299 void DolphinMainWindow::updateNewMenu()
300 {
301 m_newMenu->slotCheckUpToDate();
302 m_newMenu->setPopupFiles(activeViewContainer()->url());
303 }
304
305 void DolphinMainWindow::properties()
306 {
307 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
308
309 KPropertiesDialog *dialog = new KPropertiesDialog(list, this);
310 dialog->setAttribute(Qt::WA_DeleteOnClose);
311 dialog->show();
312 dialog->raise();
313 dialog->activateWindow();
314 }
315
316 void DolphinMainWindow::quit()
317 {
318 close();
319 }
320
321 void DolphinMainWindow::slotHandlePlacesError(const QString &message)
322 {
323 if (!message.isEmpty()) {
324 DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
325 statusBar->setMessage(message, DolphinStatusBar::Error);
326 }
327 }
328
329 void DolphinMainWindow::slotUndoAvailable(bool available)
330 {
331 QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
332 if (undoAction != 0) {
333 undoAction->setEnabled(available);
334 }
335
336 if (available && (m_undoCommandTypes.count() > 0)) {
337 const KonqFileUndoManager::CommandType command = m_undoCommandTypes.takeFirst();
338 DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
339 switch (command) {
340 case KonqFileUndoManager::COPY:
341 statusBar->setMessage(i18nc("@info:status", "Copy operation completed."),
342 DolphinStatusBar::OperationCompleted);
343 break;
344 case KonqFileUndoManager::MOVE:
345 statusBar->setMessage(i18nc("@info:status", "Move operation completed."),
346 DolphinStatusBar::OperationCompleted);
347 break;
348 case KonqFileUndoManager::LINK:
349 statusBar->setMessage(i18nc("@info:status", "Link operation completed."),
350 DolphinStatusBar::OperationCompleted);
351 break;
352 case KonqFileUndoManager::TRASH:
353 statusBar->setMessage(i18nc("@info:status", "Move to trash operation completed."),
354 DolphinStatusBar::OperationCompleted);
355 break;
356 case KonqFileUndoManager::RENAME:
357 statusBar->setMessage(i18nc("@info:status", "Renaming operation completed."),
358 DolphinStatusBar::OperationCompleted);
359 break;
360
361 case KonqFileUndoManager::MKDIR:
362 statusBar->setMessage(i18nc("@info:status", "Created folder."),
363 DolphinStatusBar::OperationCompleted);
364 break;
365
366 default:
367 break;
368 }
369
370 }
371 }
372
373 void DolphinMainWindow::slotUndoTextChanged(const QString& text)
374 {
375 QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
376 if (undoAction != 0) {
377 undoAction->setText(text);
378 }
379 }
380
381 void DolphinMainWindow::undo()
382 {
383 clearStatusBar();
384 KonqFileUndoManager::self()->undo();
385 }
386
387 void DolphinMainWindow::cut()
388 {
389 m_activeViewContainer->view()->cutSelectedItems();
390 }
391
392 void DolphinMainWindow::copy()
393 {
394 m_activeViewContainer->view()->copySelectedItems();
395 }
396
397 void DolphinMainWindow::paste()
398 {
399 m_activeViewContainer->view()->paste();
400 }
401
402 void DolphinMainWindow::updatePasteAction()
403 {
404 QAction* pasteAction = actionCollection()->action(KStandardAction::name(KStandardAction::Paste));
405 if (pasteAction == 0) {
406 return;
407 }
408
409 QPair<bool, QString> pasteInfo = m_activeViewContainer->view()->pasteInfo();
410 pasteAction->setEnabled(pasteInfo.first);
411 pasteAction->setText(pasteInfo.second);
412 }
413
414 void DolphinMainWindow::selectAll()
415 {
416 clearStatusBar();
417
418 // if the URL navigator is editable and focused, select the whole
419 // URL instead of all items of the view
420
421 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
422 QLineEdit* lineEdit = urlNavigator->editor()->lineEdit();
423 const bool selectUrl = urlNavigator->isUrlEditable() &&
424 lineEdit->hasFocus();
425 if (selectUrl) {
426 lineEdit->selectAll();
427 } else {
428 m_activeViewContainer->view()->selectAll();
429 }
430 }
431
432 void DolphinMainWindow::invertSelection()
433 {
434 clearStatusBar();
435 m_activeViewContainer->view()->invertSelection();
436 }
437
438 void DolphinMainWindow::toggleSplitView()
439 {
440 if (m_viewContainer[SecondaryView] == 0) {
441 // create a secondary view
442 const int newWidth = (m_viewContainer[PrimaryView]->width() - m_splitter->handleWidth()) / 2;
443
444 const DolphinView* view = m_viewContainer[PrimaryView]->view();
445 m_viewContainer[SecondaryView] = new DolphinViewContainer(this, 0, view->rootUrl());
446 connectViewSignals(SecondaryView);
447 m_splitter->addWidget(m_viewContainer[SecondaryView]);
448 m_splitter->setSizes(QList<int>() << newWidth << newWidth);
449 m_viewContainer[SecondaryView]->view()->reload();
450 m_viewContainer[SecondaryView]->setActive(false);
451 m_viewContainer[SecondaryView]->show();
452 } else if (m_activeViewContainer == m_viewContainer[PrimaryView]) {
453 // remove secondary view
454 m_viewContainer[SecondaryView]->close();
455 m_viewContainer[SecondaryView]->deleteLater();
456 m_viewContainer[SecondaryView] = 0;
457 } else {
458 // The secondary view is active, hence from a users point of view
459 // the content of the secondary view should be moved to the primary view.
460 // From an implementation point of view it is more efficient to close
461 // the primary view and exchange the internal pointers afterwards.
462 m_viewContainer[PrimaryView]->close();
463 m_viewContainer[PrimaryView]->deleteLater();
464 m_viewContainer[PrimaryView] = m_viewContainer[SecondaryView];
465 m_viewContainer[SecondaryView] = 0;
466 }
467
468 setActiveViewContainer(m_viewContainer[PrimaryView]);
469 updateViewActions();
470 emit activeViewChanged(); // TODO unused; remove?
471 }
472
473 void DolphinMainWindow::reloadView()
474 {
475 clearStatusBar();
476 m_activeViewContainer->view()->reload();
477 }
478
479 void DolphinMainWindow::stopLoading()
480 {
481 }
482
483 void DolphinMainWindow::toggleFilterBarVisibility(bool show)
484 {
485 m_activeViewContainer->showFilterBar(show);
486 }
487
488 void DolphinMainWindow::toggleEditLocation()
489 {
490 clearStatusBar();
491
492 QAction* action = actionCollection()->action("editable_location");
493 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
494 urlNavigator->setUrlEditable(action->isChecked());
495 }
496
497 void DolphinMainWindow::editLocation()
498 {
499 KUrlNavigator* navigator = m_activeViewContainer->urlNavigator();
500 navigator->setUrlEditable(true);
501 navigator->setFocus();
502 }
503
504 void DolphinMainWindow::adjustViewProperties()
505 {
506 clearStatusBar();
507 ViewPropertiesDialog dlg(m_activeViewContainer->view());
508 dlg.exec();
509 }
510
511 void DolphinMainWindow::goBack()
512 {
513 clearStatusBar();
514 m_activeViewContainer->urlNavigator()->goBack();
515 }
516
517 void DolphinMainWindow::goForward()
518 {
519 clearStatusBar();
520 m_activeViewContainer->urlNavigator()->goForward();
521 }
522
523 void DolphinMainWindow::goUp()
524 {
525 clearStatusBar();
526 m_activeViewContainer->urlNavigator()->goUp();
527 }
528
529 void DolphinMainWindow::goHome()
530 {
531 clearStatusBar();
532 m_activeViewContainer->urlNavigator()->goHome();
533 }
534
535 void DolphinMainWindow::findFile()
536 {
537 KRun::run("kfind", m_activeViewContainer->url(), this);
538 }
539
540 void DolphinMainWindow::compareFiles()
541 {
542 // The method is only invoked if exactly 2 files have
543 // been selected. The selected files may be:
544 // - both in the primary view
545 // - both in the secondary view
546 // - one in the primary view and the other in the secondary
547 // view
548 Q_ASSERT(m_viewContainer[PrimaryView] != 0);
549
550 KUrl urlA;
551 KUrl urlB;
552 KUrl::List urls = m_viewContainer[PrimaryView]->view()->selectedUrls();
553
554 switch (urls.count()) {
555 case 0: {
556 Q_ASSERT(m_viewContainer[SecondaryView] != 0);
557 urls = m_viewContainer[SecondaryView]->view()->selectedUrls();
558 Q_ASSERT(urls.count() == 2);
559 urlA = urls[0];
560 urlB = urls[1];
561 break;
562 }
563
564 case 1: {
565 urlA = urls[0];
566 Q_ASSERT(m_viewContainer[SecondaryView] != 0);
567 urls = m_viewContainer[SecondaryView]->view()->selectedUrls();
568 Q_ASSERT(urls.count() == 1);
569 urlB = urls[0];
570 break;
571 }
572
573 case 2: {
574 urlA = urls[0];
575 urlB = urls[1];
576 break;
577 }
578
579 default: {
580 // may not happen: compareFiles may only get invoked if 2
581 // files are selected
582 Q_ASSERT(false);
583 }
584 }
585
586 QString command("kompare -c \"");
587 command.append(urlA.pathOrUrl());
588 command.append("\" \"");
589 command.append(urlB.pathOrUrl());
590 command.append('\"');
591 KRun::runCommand(command, "Kompare", "kompare", this);
592
593 }
594
595 void DolphinMainWindow::toggleShowMenuBar()
596 {
597 const bool visible = menuBar()->isVisible();
598 menuBar()->setVisible(!visible);
599 }
600
601 void DolphinMainWindow::editSettings()
602 {
603 DolphinSettingsDialog dialog(this);
604 dialog.exec();
605 }
606
607 void DolphinMainWindow::init()
608 {
609 DolphinSettings& settings = DolphinSettings::instance();
610
611 // Check whether Dolphin runs the first time. If yes then
612 // a proper default window size is given at the end of DolphinMainWindow::init().
613 GeneralSettings* generalSettings = settings.generalSettings();
614 const bool firstRun = generalSettings->firstRun();
615 if (firstRun) {
616 generalSettings->setViewPropsTimestamp(QDateTime::currentDateTime());
617 }
618
619 setAcceptDrops(true);
620
621 m_splitter = new QSplitter(this);
622
623 setupActions();
624
625 const KUrl& homeUrl = generalSettings->homeUrl();
626 setCaption(homeUrl.fileName());
627 m_actionHandler = new DolphinViewActionHandler(actionCollection(), this);
628 connect(m_actionHandler, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
629 ViewProperties props(homeUrl);
630 m_viewContainer[PrimaryView] = new DolphinViewContainer(this,
631 m_splitter,
632 homeUrl);
633
634 m_activeViewContainer = m_viewContainer[PrimaryView];
635 connectViewSignals(PrimaryView);
636 DolphinView* view = m_viewContainer[PrimaryView]->view();
637 view->reload();
638 m_viewContainer[PrimaryView]->show();
639 m_actionHandler->setCurrentView(view);
640
641 setCentralWidget(m_splitter);
642 setupDockWidgets();
643
644 setupGUI(Keys | Save | Create | ToolBar);
645 createGUI();
646
647 stateChanged("new_file");
648 setAutoSaveSettings();
649
650 QClipboard* clipboard = QApplication::clipboard();
651 connect(clipboard, SIGNAL(dataChanged()),
652 this, SLOT(updatePasteAction()));
653 updatePasteAction();
654 updateGoActions();
655
656 if (generalSettings->splitView()) {
657 toggleSplitView();
658 }
659 updateViewActions();
660
661 if (firstRun) {
662 // assure a proper default size if Dolphin runs the first time
663 resize(700, 500);
664 }
665
666 emit urlChanged(homeUrl);
667 }
668
669 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContainer)
670 {
671 Q_ASSERT(viewContainer != 0);
672 Q_ASSERT((viewContainer == m_viewContainer[PrimaryView]) || (viewContainer == m_viewContainer[SecondaryView]));
673 if (m_activeViewContainer == viewContainer) {
674 return;
675 }
676
677 m_activeViewContainer->setActive(false);
678 m_activeViewContainer = viewContainer;
679 m_activeViewContainer->setActive(true);
680
681 updateHistory();
682 updateEditActions();
683 updateViewActions();
684 updateGoActions();
685
686 const KUrl& url = m_activeViewContainer->url();
687 setCaption(url.fileName());
688
689 m_actionHandler->setCurrentView(viewContainer->view());
690
691 emit activeViewChanged(); // TODO unused; remove?
692 emit urlChanged(url);
693 }
694
695 void DolphinMainWindow::setupActions()
696 {
697 // setup 'File' menu
698 m_newMenu = new DolphinNewMenu(this);
699 KMenu* menu = m_newMenu->menu();
700 menu->setTitle(i18nc("@title:menu", "Create New"));
701 menu->setIcon(KIcon("document-new"));
702 connect(menu, SIGNAL(aboutToShow()),
703 this, SLOT(updateNewMenu()));
704
705 KAction* newWindow = actionCollection()->addAction("new_window");
706 newWindow->setIcon(KIcon("window-new"));
707 newWindow->setText(i18nc("@action:inmenu File", "New &Window"));
708 newWindow->setShortcut(Qt::CTRL | Qt::Key_N);
709 connect(newWindow, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
710
711 KAction* properties = actionCollection()->addAction("properties");
712 properties->setText(i18nc("@action:inmenu File", "Properties"));
713 properties->setShortcut(Qt::ALT | Qt::Key_Return);
714 connect(properties, SIGNAL(triggered()), this, SLOT(properties()));
715
716 KStandardAction::quit(this, SLOT(quit()), actionCollection());
717
718 // setup 'Edit' menu
719 KStandardAction::undo(this,
720 SLOT(undo()),
721 actionCollection());
722
723 // need to remove shift+del from cut action, else the shortcut for deletejob
724 // doesn't work
725 KAction* cut = KStandardAction::cut(this, SLOT(cut()), actionCollection());
726 KShortcut cutShortcut = cut->shortcut();
727 cutShortcut.remove(Qt::SHIFT + Qt::Key_Delete, KShortcut::KeepEmpty);
728 cut->setShortcut(cutShortcut);
729 KStandardAction::copy(this, SLOT(copy()), actionCollection());
730 KStandardAction::paste(this, SLOT(paste()), actionCollection());
731
732 KAction* selectAll = actionCollection()->addAction("select_all");
733 selectAll->setText(i18nc("@action:inmenu Edit", "Select All"));
734 selectAll->setShortcut(Qt::CTRL + Qt::Key_A);
735 connect(selectAll, SIGNAL(triggered()), this, SLOT(selectAll()));
736
737 KAction* invertSelection = actionCollection()->addAction("invert_selection");
738 invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
739 invertSelection->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_A);
740 connect(invertSelection, SIGNAL(triggered()), this, SLOT(invertSelection()));
741
742 // setup 'View' menu
743 // (note that most of it is set up in DolphinViewActionHandler)
744
745 KAction* split = actionCollection()->addAction("split_view");
746 split->setShortcut(Qt::Key_F3);
747 updateSplitAction();
748 connect(split, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
749
750 KAction* reload = actionCollection()->addAction("reload");
751 reload->setText(i18nc("@action:inmenu View", "Reload"));
752 reload->setShortcut(Qt::Key_F5);
753 reload->setIcon(KIcon("view-refresh"));
754 connect(reload, SIGNAL(triggered()), this, SLOT(reloadView()));
755
756 KAction* stop = actionCollection()->addAction("stop");
757 stop->setText(i18nc("@action:inmenu View", "Stop"));
758 stop->setIcon(KIcon("process-stop"));
759 connect(stop, SIGNAL(triggered()), this, SLOT(stopLoading()));
760
761 // TODO: the naming "Show full Location" is currently confusing...
762 KToggleAction* showFullLocation = actionCollection()->add<KToggleAction>("editable_location");
763 showFullLocation->setText(i18nc("@action:inmenu Navigation Bar", "Show Full Location"));
764 showFullLocation->setShortcut(Qt::CTRL | Qt::Key_L);
765 connect(showFullLocation, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
766
767 KAction* editLocation = actionCollection()->addAction("edit_location");
768 editLocation->setText(i18nc("@action:inmenu Navigation Bar", "Edit Location"));
769 editLocation->setShortcut(Qt::Key_F6);
770 connect(editLocation, SIGNAL(triggered()), this, SLOT(editLocation()));
771
772 KAction* adjustViewProps = actionCollection()->addAction("view_properties");
773 adjustViewProps->setText(i18nc("@action:inmenu View", "Adjust View Properties..."));
774 connect(adjustViewProps, SIGNAL(triggered()), this, SLOT(adjustViewProperties()));
775
776 // setup 'Go' menu
777 KAction* backAction = KStandardAction::back(this, SLOT(goBack()), actionCollection());
778 KShortcut backShortcut = backAction->shortcut();
779 backShortcut.setAlternate(Qt::Key_Backspace);
780 backAction->setShortcut(backShortcut);
781
782 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
783 KStandardAction::up(this, SLOT(goUp()), actionCollection());
784 KStandardAction::home(this, SLOT(goHome()), actionCollection());
785
786 // setup 'Tools' menu
787 QAction* findFile = actionCollection()->addAction("find_file");
788 findFile->setText(i18nc("@action:inmenu Tools", "Find File..."));
789 findFile->setShortcut(Qt::CTRL | Qt::Key_F);
790 findFile->setIcon(KIcon("edit-find"));
791 connect(findFile, SIGNAL(triggered()), this, SLOT(findFile()));
792
793 KToggleAction* showFilterBar = actionCollection()->add<KToggleAction>("show_filter_bar");
794 showFilterBar->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
795 showFilterBar->setShortcut(Qt::CTRL | Qt::Key_I);
796 connect(showFilterBar, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
797
798 KAction* compareFiles = actionCollection()->addAction("compare_files");
799 compareFiles->setText(i18nc("@action:inmenu Tools", "Compare Files"));
800 compareFiles->setIcon(KIcon("kompare"));
801 compareFiles->setEnabled(false);
802 connect(compareFiles, SIGNAL(triggered()), this, SLOT(compareFiles()));
803
804 // setup 'Settings' menu
805 m_showMenuBar = KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
806 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
807 }
808
809 void DolphinMainWindow::setupDockWidgets()
810 {
811 // setup "Information"
812 QDockWidget* infoDock = new QDockWidget(i18nc("@title:window", "Information"));
813 infoDock->setObjectName("infoDock");
814 infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
815 SidebarPage* infoWidget = new InfoSidebarPage(infoDock);
816 infoDock->setWidget(infoWidget);
817
818 infoDock->toggleViewAction()->setText(i18nc("@title:window", "Information"));
819 infoDock->toggleViewAction()->setShortcut(Qt::Key_F11);
820 actionCollection()->addAction("show_info_panel", infoDock->toggleViewAction());
821
822 addDockWidget(Qt::RightDockWidgetArea, infoDock);
823 connect(this, SIGNAL(urlChanged(KUrl)),
824 infoWidget, SLOT(setUrl(KUrl)));
825 connect(this, SIGNAL(selectionChanged(KFileItemList)),
826 infoWidget, SLOT(setSelection(KFileItemList)));
827 connect(this, SIGNAL(requestItemInfo(KFileItem)),
828 infoWidget, SLOT(requestDelayedItemInfo(KFileItem)));
829
830 // setup "Tree View"
831 QDockWidget* treeViewDock = new QDockWidget(i18nc("@title:window", "Folders"));
832 treeViewDock->setObjectName("treeViewDock");
833 treeViewDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
834 TreeViewSidebarPage* treeWidget = new TreeViewSidebarPage(treeViewDock);
835 treeViewDock->setWidget(treeWidget);
836
837 treeViewDock->toggleViewAction()->setText(i18nc("@title:window", "Folders"));
838 treeViewDock->toggleViewAction()->setShortcut(Qt::Key_F7);
839 actionCollection()->addAction("show_folders_panel", treeViewDock->toggleViewAction());
840
841 addDockWidget(Qt::LeftDockWidgetArea, treeViewDock);
842 connect(this, SIGNAL(urlChanged(KUrl)),
843 treeWidget, SLOT(setUrl(KUrl)));
844 connect(treeWidget, SIGNAL(changeUrl(KUrl)),
845 this, SLOT(changeUrl(KUrl)));
846 connect(treeWidget, SIGNAL(changeSelection(KFileItemList)),
847 this, SLOT(changeSelection(KFileItemList)));
848 connect(treeWidget, SIGNAL(urlsDropped(KUrl::List, KUrl)),
849 this, SLOT(dropUrls(KUrl::List, KUrl)));
850
851 // setup "Terminal"
852 QDockWidget* terminalDock = new QDockWidget(i18nc("@title:window", "Terminal"));
853 terminalDock->setObjectName("terminalDock");
854 terminalDock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
855 SidebarPage* terminalWidget = new TerminalSidebarPage(terminalDock);
856 terminalDock->setWidget(terminalWidget);
857
858 connect(terminalWidget, SIGNAL(hideTerminalSidebarPage()), terminalDock, SLOT(hide()));
859
860 terminalDock->toggleViewAction()->setText(i18nc("@title:window", "Terminal"));
861 terminalDock->toggleViewAction()->setShortcut(Qt::Key_F4);
862 actionCollection()->addAction("show_terminal_panel", terminalDock->toggleViewAction());
863
864 addDockWidget(Qt::BottomDockWidgetArea, terminalDock);
865 connect(this, SIGNAL(urlChanged(KUrl)),
866 terminalWidget, SLOT(setUrl(KUrl)));
867
868 const bool firstRun = DolphinSettings::instance().generalSettings()->firstRun();
869 if (firstRun) {
870 infoDock->hide();
871 treeViewDock->hide();
872 terminalDock->hide();
873 }
874
875 QDockWidget* placesDock = new QDockWidget(i18nc("@title:window", "Places"));
876 placesDock->setObjectName("placesDock");
877 placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
878
879 DolphinFilePlacesView* placesView = new DolphinFilePlacesView(placesDock);
880 placesDock->setWidget(placesView);
881 placesView->setModel(DolphinSettings::instance().placesModel());
882 placesView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
883
884 placesDock->toggleViewAction()->setText(i18nc("@title:window", "Places"));
885 placesDock->toggleViewAction()->setShortcut(Qt::Key_F9);
886 actionCollection()->addAction("show_places_panel", placesDock->toggleViewAction());
887
888 addDockWidget(Qt::LeftDockWidgetArea, placesDock);
889 connect(placesView, SIGNAL(urlChanged(KUrl)),
890 this, SLOT(changeUrl(KUrl)));
891 connect(this, SIGNAL(urlChanged(KUrl)),
892 placesView, SLOT(setUrl(KUrl)));
893 }
894
895 void DolphinMainWindow::updateHistory()
896 {
897 const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
898 const int index = urlNavigator->historyIndex();
899
900 QAction* backAction = actionCollection()->action("go_back");
901 if (backAction != 0) {
902 backAction->setEnabled(index < urlNavigator->historySize() - 1);
903 }
904
905 QAction* forwardAction = actionCollection()->action("go_forward");
906 if (forwardAction != 0) {
907 forwardAction->setEnabled(index > 0);
908 }
909 }
910
911 void DolphinMainWindow::updateEditActions()
912 {
913 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
914 if (list.isEmpty()) {
915 stateChanged("has_no_selection");
916 } else {
917 stateChanged("has_selection");
918
919 QAction* renameAction = actionCollection()->action("rename");
920 if (renameAction != 0) {
921 renameAction->setEnabled(true);
922 }
923
924 bool enableMoveToTrash = true;
925
926 KFileItemList::const_iterator it = list.begin();
927 const KFileItemList::const_iterator end = list.end();
928 while (it != end) {
929 const KUrl& url = (*it).url();
930 // only enable the 'Move to Trash' action for local files
931 if (!url.isLocalFile()) {
932 enableMoveToTrash = false;
933 }
934 ++it;
935 }
936
937 QAction* moveToTrashAction = actionCollection()->action("move_to_trash");
938 moveToTrashAction->setEnabled(enableMoveToTrash);
939 }
940 updatePasteAction();
941 }
942
943 void DolphinMainWindow::updateViewActions()
944 {
945 m_actionHandler->updateViewActions();
946
947 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
948 showFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible());
949
950 updateSplitAction();
951
952 QAction* editableLocactionAction = actionCollection()->action("editable_location");
953 const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
954 editableLocactionAction->setChecked(urlNavigator->isUrlEditable());
955 }
956
957 void DolphinMainWindow::updateGoActions()
958 {
959 QAction* goUpAction = actionCollection()->action(KStandardAction::name(KStandardAction::Up));
960 const KUrl& currentUrl = m_activeViewContainer->url();
961 goUpAction->setEnabled(currentUrl.upUrl() != currentUrl);
962 }
963
964 void DolphinMainWindow::clearStatusBar()
965 {
966 m_activeViewContainer->statusBar()->clear();
967 }
968
969 void DolphinMainWindow::connectViewSignals(int viewIndex)
970 {
971 DolphinViewContainer* container = m_viewContainer[viewIndex];
972 connect(container, SIGNAL(showFilterBarChanged(bool)),
973 this, SLOT(updateFilterBarAction(bool)));
974
975 DolphinView* view = container->view();
976 connect(view, SIGNAL(selectionChanged(KFileItemList)),
977 this, SLOT(slotSelectionChanged(KFileItemList)));
978 connect(view, SIGNAL(requestItemInfo(KFileItem)),
979 this, SLOT(slotRequestItemInfo(KFileItem)));
980 connect(view, SIGNAL(activated()),
981 this, SLOT(toggleActiveView()));
982 connect(view, SIGNAL(doingOperation(KonqFileUndoManager::CommandType)),
983 this, SLOT(slotDoingOperation(KonqFileUndoManager::CommandType)));
984
985 const KUrlNavigator* navigator = container->urlNavigator();
986 connect(navigator, SIGNAL(urlChanged(const KUrl&)),
987 this, SLOT(changeUrl(const KUrl&)));
988 connect(navigator, SIGNAL(historyChanged()),
989 this, SLOT(slotHistoryChanged()));
990 connect(navigator, SIGNAL(editableStateChanged(bool)),
991 this, SLOT(slotEditableStateChanged(bool)));
992 }
993
994 void DolphinMainWindow::updateSplitAction()
995 {
996 QAction* splitAction = actionCollection()->action("split_view");
997 if (m_viewContainer[SecondaryView] != 0) {
998 if (m_activeViewContainer == m_viewContainer[PrimaryView]) {
999 splitAction->setText(i18nc("@action:intoolbar Close right view", "Close"));
1000 splitAction->setIcon(KIcon("view-right-close"));
1001 } else {
1002 splitAction->setText(i18nc("@action:intoolbar Close left view", "Close"));
1003 splitAction->setIcon(KIcon("view-left-close"));
1004 }
1005 } else {
1006 splitAction->setText(i18nc("@action:intoolbar Split view", "Split"));
1007 splitAction->setIcon(KIcon("view-right-new"));
1008 }
1009 }
1010
1011 DolphinMainWindow::UndoUiInterface::UndoUiInterface(DolphinMainWindow* mainWin) :
1012 KonqFileUndoManager::UiInterface(mainWin),
1013 m_mainWin(mainWin)
1014 {
1015 Q_ASSERT(m_mainWin != 0);
1016 }
1017
1018 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1019 {
1020 }
1021
1022 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job)
1023 {
1024 DolphinStatusBar* statusBar = m_mainWin->activeViewContainer()->statusBar();
1025 statusBar->setMessage(job->errorString(), DolphinStatusBar::Error);
1026 }
1027
1028 #include "dolphinmainwindow.moc"