]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
KDE 4.1 requires Qt4.4 -> remove the #ifdefs...
[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 // select the whole text of the combo box editor
504 QLineEdit* lineEdit = navigator->editor()->lineEdit();
505 const QString text = lineEdit->text();
506 lineEdit->setSelection(0, text.length());
507 }
508
509 void DolphinMainWindow::adjustViewProperties()
510 {
511 clearStatusBar();
512 ViewPropertiesDialog dlg(m_activeViewContainer->view());
513 dlg.exec();
514 }
515
516 void DolphinMainWindow::goBack()
517 {
518 clearStatusBar();
519 m_activeViewContainer->urlNavigator()->goBack();
520 }
521
522 void DolphinMainWindow::goForward()
523 {
524 clearStatusBar();
525 m_activeViewContainer->urlNavigator()->goForward();
526 }
527
528 void DolphinMainWindow::goUp()
529 {
530 clearStatusBar();
531 m_activeViewContainer->urlNavigator()->goUp();
532 }
533
534 void DolphinMainWindow::goHome()
535 {
536 clearStatusBar();
537 m_activeViewContainer->urlNavigator()->goHome();
538 }
539
540 void DolphinMainWindow::findFile()
541 {
542 KRun::run("kfind", m_activeViewContainer->url(), this);
543 }
544
545 void DolphinMainWindow::compareFiles()
546 {
547 // The method is only invoked if exactly 2 files have
548 // been selected. The selected files may be:
549 // - both in the primary view
550 // - both in the secondary view
551 // - one in the primary view and the other in the secondary
552 // view
553 Q_ASSERT(m_viewContainer[PrimaryView] != 0);
554
555 KUrl urlA;
556 KUrl urlB;
557 KUrl::List urls = m_viewContainer[PrimaryView]->view()->selectedUrls();
558
559 switch (urls.count()) {
560 case 0: {
561 Q_ASSERT(m_viewContainer[SecondaryView] != 0);
562 urls = m_viewContainer[SecondaryView]->view()->selectedUrls();
563 Q_ASSERT(urls.count() == 2);
564 urlA = urls[0];
565 urlB = urls[1];
566 break;
567 }
568
569 case 1: {
570 urlA = urls[0];
571 Q_ASSERT(m_viewContainer[SecondaryView] != 0);
572 urls = m_viewContainer[SecondaryView]->view()->selectedUrls();
573 Q_ASSERT(urls.count() == 1);
574 urlB = urls[0];
575 break;
576 }
577
578 case 2: {
579 urlA = urls[0];
580 urlB = urls[1];
581 break;
582 }
583
584 default: {
585 // may not happen: compareFiles may only get invoked if 2
586 // files are selected
587 Q_ASSERT(false);
588 }
589 }
590
591 QString command("kompare -c \"");
592 command.append(urlA.pathOrUrl());
593 command.append("\" \"");
594 command.append(urlB.pathOrUrl());
595 command.append('\"');
596 KRun::runCommand(command, "Kompare", "kompare", this);
597
598 }
599
600 void DolphinMainWindow::toggleShowMenuBar()
601 {
602 const bool visible = menuBar()->isVisible();
603 menuBar()->setVisible(!visible);
604 }
605
606 void DolphinMainWindow::editSettings()
607 {
608 DolphinSettingsDialog dialog(this);
609 dialog.exec();
610 }
611
612 void DolphinMainWindow::init()
613 {
614 DolphinSettings& settings = DolphinSettings::instance();
615
616 // Check whether Dolphin runs the first time. If yes then
617 // a proper default window size is given at the end of DolphinMainWindow::init().
618 GeneralSettings* generalSettings = settings.generalSettings();
619 const bool firstRun = generalSettings->firstRun();
620 if (firstRun) {
621 generalSettings->setViewPropsTimestamp(QDateTime::currentDateTime());
622 }
623
624 setAcceptDrops(true);
625
626 m_splitter = new QSplitter(this);
627
628 setupActions();
629
630 const KUrl& homeUrl = generalSettings->homeUrl();
631 setCaption(homeUrl.fileName());
632 m_actionHandler = new DolphinViewActionHandler(actionCollection(), this);
633 connect(m_actionHandler, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
634 ViewProperties props(homeUrl);
635 m_viewContainer[PrimaryView] = new DolphinViewContainer(this,
636 m_splitter,
637 homeUrl);
638
639 m_activeViewContainer = m_viewContainer[PrimaryView];
640 connectViewSignals(PrimaryView);
641 DolphinView* view = m_viewContainer[PrimaryView]->view();
642 view->reload();
643 m_viewContainer[PrimaryView]->show();
644 m_actionHandler->setCurrentView(view);
645
646 setCentralWidget(m_splitter);
647 setupDockWidgets();
648
649 setupGUI(Keys | Save | Create | ToolBar);
650 createGUI();
651
652 stateChanged("new_file");
653 setAutoSaveSettings();
654
655 QClipboard* clipboard = QApplication::clipboard();
656 connect(clipboard, SIGNAL(dataChanged()),
657 this, SLOT(updatePasteAction()));
658 updatePasteAction();
659 updateGoActions();
660
661 if (generalSettings->splitView()) {
662 toggleSplitView();
663 }
664 updateViewActions();
665
666 if (firstRun) {
667 // assure a proper default size if Dolphin runs the first time
668 resize(700, 500);
669 }
670
671 emit urlChanged(homeUrl);
672 }
673
674 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContainer)
675 {
676 Q_ASSERT(viewContainer != 0);
677 Q_ASSERT((viewContainer == m_viewContainer[PrimaryView]) || (viewContainer == m_viewContainer[SecondaryView]));
678 if (m_activeViewContainer == viewContainer) {
679 return;
680 }
681
682 m_activeViewContainer->setActive(false);
683 m_activeViewContainer = viewContainer;
684 m_activeViewContainer->setActive(true);
685
686 updateHistory();
687 updateEditActions();
688 updateViewActions();
689 updateGoActions();
690
691 const KUrl& url = m_activeViewContainer->url();
692 setCaption(url.fileName());
693
694 m_actionHandler->setCurrentView(viewContainer->view());
695
696 emit activeViewChanged(); // TODO unused; remove?
697 emit urlChanged(url);
698 }
699
700 void DolphinMainWindow::setupActions()
701 {
702 // setup 'File' menu
703 m_newMenu = new DolphinNewMenu(this);
704 KMenu* menu = m_newMenu->menu();
705 menu->setTitle(i18nc("@title:menu", "Create New"));
706 menu->setIcon(KIcon("document-new"));
707 connect(menu, SIGNAL(aboutToShow()),
708 this, SLOT(updateNewMenu()));
709
710 KAction* newWindow = actionCollection()->addAction("new_window");
711 newWindow->setIcon(KIcon("window-new"));
712 newWindow->setText(i18nc("@action:inmenu File", "New &Window"));
713 newWindow->setShortcut(Qt::CTRL | Qt::Key_N);
714 connect(newWindow, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
715
716 KAction* properties = actionCollection()->addAction("properties");
717 properties->setText(i18nc("@action:inmenu File", "Properties"));
718 properties->setShortcut(Qt::ALT | Qt::Key_Return);
719 connect(properties, SIGNAL(triggered()), this, SLOT(properties()));
720
721 KStandardAction::quit(this, SLOT(quit()), actionCollection());
722
723 // setup 'Edit' menu
724 KStandardAction::undo(this,
725 SLOT(undo()),
726 actionCollection());
727
728 // need to remove shift+del from cut action, else the shortcut for deletejob
729 // doesn't work
730 KAction* cut = KStandardAction::cut(this, SLOT(cut()), actionCollection());
731 KShortcut cutShortcut = cut->shortcut();
732 cutShortcut.remove(Qt::SHIFT + Qt::Key_Delete, KShortcut::KeepEmpty);
733 cut->setShortcut(cutShortcut);
734 KStandardAction::copy(this, SLOT(copy()), actionCollection());
735 KStandardAction::paste(this, SLOT(paste()), actionCollection());
736
737 KAction* selectAll = actionCollection()->addAction("select_all");
738 selectAll->setText(i18nc("@action:inmenu Edit", "Select All"));
739 selectAll->setShortcut(Qt::CTRL + Qt::Key_A);
740 connect(selectAll, SIGNAL(triggered()), this, SLOT(selectAll()));
741
742 KAction* invertSelection = actionCollection()->addAction("invert_selection");
743 invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
744 invertSelection->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_A);
745 connect(invertSelection, SIGNAL(triggered()), this, SLOT(invertSelection()));
746
747 // setup 'View' menu
748 // (note that most of it is set up in DolphinViewActionHandler)
749
750 KAction* split = actionCollection()->addAction("split_view");
751 split->setShortcut(Qt::Key_F3);
752 updateSplitAction();
753 connect(split, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
754
755 KAction* reload = actionCollection()->addAction("reload");
756 reload->setText(i18nc("@action:inmenu View", "Reload"));
757 reload->setShortcut(Qt::Key_F5);
758 reload->setIcon(KIcon("view-refresh"));
759 connect(reload, SIGNAL(triggered()), this, SLOT(reloadView()));
760
761 KAction* stop = actionCollection()->addAction("stop");
762 stop->setText(i18nc("@action:inmenu View", "Stop"));
763 stop->setIcon(KIcon("process-stop"));
764 connect(stop, SIGNAL(triggered()), this, SLOT(stopLoading()));
765
766 // TODO: the naming "Show full Location" is currently confusing...
767 KToggleAction* showFullLocation = actionCollection()->add<KToggleAction>("editable_location");
768 showFullLocation->setText(i18nc("@action:inmenu Navigation Bar", "Show Full Location"));
769 showFullLocation->setShortcut(Qt::CTRL | Qt::Key_L);
770 connect(showFullLocation, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
771
772 KAction* editLocation = actionCollection()->addAction("edit_location");
773 editLocation->setText(i18nc("@action:inmenu Navigation Bar", "Edit Location"));
774 editLocation->setShortcut(Qt::Key_F6);
775 connect(editLocation, SIGNAL(triggered()), this, SLOT(editLocation()));
776
777 KAction* adjustViewProps = actionCollection()->addAction("view_properties");
778 adjustViewProps->setText(i18nc("@action:inmenu View", "Adjust View Properties..."));
779 connect(adjustViewProps, SIGNAL(triggered()), this, SLOT(adjustViewProperties()));
780
781 // setup 'Go' menu
782 KAction* backAction = KStandardAction::back(this, SLOT(goBack()), actionCollection());
783 KShortcut backShortcut = backAction->shortcut();
784 backShortcut.setAlternate(Qt::Key_Backspace);
785 backAction->setShortcut(backShortcut);
786
787 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
788 KStandardAction::up(this, SLOT(goUp()), actionCollection());
789 KStandardAction::home(this, SLOT(goHome()), actionCollection());
790
791 // setup 'Tools' menu
792 QAction* findFile = actionCollection()->addAction("find_file");
793 findFile->setText(i18nc("@action:inmenu Tools", "Find File..."));
794 findFile->setShortcut(Qt::CTRL | Qt::Key_F);
795 findFile->setIcon(KIcon("edit-find"));
796 connect(findFile, SIGNAL(triggered()), this, SLOT(findFile()));
797
798 KToggleAction* showFilterBar = actionCollection()->add<KToggleAction>("show_filter_bar");
799 showFilterBar->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
800 showFilterBar->setShortcut(Qt::CTRL | Qt::Key_I);
801 connect(showFilterBar, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
802
803 KAction* compareFiles = actionCollection()->addAction("compare_files");
804 compareFiles->setText(i18nc("@action:inmenu Tools", "Compare Files"));
805 compareFiles->setIcon(KIcon("kompare"));
806 compareFiles->setEnabled(false);
807 connect(compareFiles, SIGNAL(triggered()), this, SLOT(compareFiles()));
808
809 // setup 'Settings' menu
810 m_showMenuBar = KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
811 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
812 }
813
814 void DolphinMainWindow::setupDockWidgets()
815 {
816 // setup "Information"
817 QDockWidget* infoDock = new QDockWidget(i18nc("@title:window", "Information"));
818 infoDock->setObjectName("infoDock");
819 infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
820 SidebarPage* infoWidget = new InfoSidebarPage(infoDock);
821 infoDock->setWidget(infoWidget);
822
823 infoDock->toggleViewAction()->setText(i18nc("@title:window", "Information"));
824 infoDock->toggleViewAction()->setShortcut(Qt::Key_F11);
825 actionCollection()->addAction("show_info_panel", infoDock->toggleViewAction());
826
827 addDockWidget(Qt::RightDockWidgetArea, infoDock);
828 connect(this, SIGNAL(urlChanged(KUrl)),
829 infoWidget, SLOT(setUrl(KUrl)));
830 connect(this, SIGNAL(selectionChanged(KFileItemList)),
831 infoWidget, SLOT(setSelection(KFileItemList)));
832 connect(this, SIGNAL(requestItemInfo(KFileItem)),
833 infoWidget, SLOT(requestDelayedItemInfo(KFileItem)));
834
835 // setup "Tree View"
836 QDockWidget* treeViewDock = new QDockWidget(i18nc("@title:window", "Folders"));
837 treeViewDock->setObjectName("treeViewDock");
838 treeViewDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
839 TreeViewSidebarPage* treeWidget = new TreeViewSidebarPage(treeViewDock);
840 treeViewDock->setWidget(treeWidget);
841
842 treeViewDock->toggleViewAction()->setText(i18nc("@title:window", "Folders"));
843 treeViewDock->toggleViewAction()->setShortcut(Qt::Key_F7);
844 actionCollection()->addAction("show_folders_panel", treeViewDock->toggleViewAction());
845
846 addDockWidget(Qt::LeftDockWidgetArea, treeViewDock);
847 connect(this, SIGNAL(urlChanged(KUrl)),
848 treeWidget, SLOT(setUrl(KUrl)));
849 connect(treeWidget, SIGNAL(changeUrl(KUrl)),
850 this, SLOT(changeUrl(KUrl)));
851 connect(treeWidget, SIGNAL(changeSelection(KFileItemList)),
852 this, SLOT(changeSelection(KFileItemList)));
853 connect(treeWidget, SIGNAL(urlsDropped(KUrl::List, KUrl)),
854 this, SLOT(dropUrls(KUrl::List, KUrl)));
855
856 // setup "Terminal"
857 QDockWidget* terminalDock = new QDockWidget(i18nc("@title:window", "Terminal"));
858 terminalDock->setObjectName("terminalDock");
859 terminalDock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
860 SidebarPage* terminalWidget = new TerminalSidebarPage(terminalDock);
861 terminalDock->setWidget(terminalWidget);
862
863 connect(terminalWidget, SIGNAL(hideTerminalSidebarPage()), terminalDock, SLOT(hide()));
864
865 terminalDock->toggleViewAction()->setText(i18nc("@title:window", "Terminal"));
866 terminalDock->toggleViewAction()->setShortcut(Qt::Key_F4);
867 actionCollection()->addAction("show_terminal_panel", terminalDock->toggleViewAction());
868
869 addDockWidget(Qt::BottomDockWidgetArea, terminalDock);
870 connect(this, SIGNAL(urlChanged(KUrl)),
871 terminalWidget, SLOT(setUrl(KUrl)));
872
873 const bool firstRun = DolphinSettings::instance().generalSettings()->firstRun();
874 if (firstRun) {
875 infoDock->hide();
876 treeViewDock->hide();
877 terminalDock->hide();
878 }
879
880 QDockWidget* placesDock = new QDockWidget(i18nc("@title:window", "Places"));
881 placesDock->setObjectName("placesDock");
882 placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
883
884 DolphinFilePlacesView* placesView = new DolphinFilePlacesView(placesDock);
885 placesDock->setWidget(placesView);
886 placesView->setModel(DolphinSettings::instance().placesModel());
887 placesView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
888
889 placesDock->toggleViewAction()->setText(i18nc("@title:window", "Places"));
890 placesDock->toggleViewAction()->setShortcut(Qt::Key_F9);
891 actionCollection()->addAction("show_places_panel", placesDock->toggleViewAction());
892
893 addDockWidget(Qt::LeftDockWidgetArea, placesDock);
894 connect(placesView, SIGNAL(urlChanged(KUrl)),
895 this, SLOT(changeUrl(KUrl)));
896 connect(this, SIGNAL(urlChanged(KUrl)),
897 placesView, SLOT(setUrl(KUrl)));
898 }
899
900 void DolphinMainWindow::updateHistory()
901 {
902 const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
903 const int index = urlNavigator->historyIndex();
904
905 QAction* backAction = actionCollection()->action("go_back");
906 if (backAction != 0) {
907 backAction->setEnabled(index < urlNavigator->historySize() - 1);
908 }
909
910 QAction* forwardAction = actionCollection()->action("go_forward");
911 if (forwardAction != 0) {
912 forwardAction->setEnabled(index > 0);
913 }
914 }
915
916 void DolphinMainWindow::updateEditActions()
917 {
918 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
919 if (list.isEmpty()) {
920 stateChanged("has_no_selection");
921 } else {
922 stateChanged("has_selection");
923
924 QAction* renameAction = actionCollection()->action("rename");
925 if (renameAction != 0) {
926 renameAction->setEnabled(true);
927 }
928
929 bool enableMoveToTrash = true;
930
931 KFileItemList::const_iterator it = list.begin();
932 const KFileItemList::const_iterator end = list.end();
933 while (it != end) {
934 const KUrl& url = (*it).url();
935 // only enable the 'Move to Trash' action for local files
936 if (!url.isLocalFile()) {
937 enableMoveToTrash = false;
938 }
939 ++it;
940 }
941
942 QAction* moveToTrashAction = actionCollection()->action("move_to_trash");
943 moveToTrashAction->setEnabled(enableMoveToTrash);
944 }
945 updatePasteAction();
946 }
947
948 void DolphinMainWindow::updateViewActions()
949 {
950 m_actionHandler->updateViewActions();
951
952 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
953 showFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible());
954
955 updateSplitAction();
956
957 QAction* editableLocactionAction = actionCollection()->action("editable_location");
958 const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
959 editableLocactionAction->setChecked(urlNavigator->isUrlEditable());
960 }
961
962 void DolphinMainWindow::updateGoActions()
963 {
964 QAction* goUpAction = actionCollection()->action(KStandardAction::name(KStandardAction::Up));
965 const KUrl& currentUrl = m_activeViewContainer->url();
966 goUpAction->setEnabled(currentUrl.upUrl() != currentUrl);
967 }
968
969 void DolphinMainWindow::clearStatusBar()
970 {
971 m_activeViewContainer->statusBar()->clear();
972 }
973
974 void DolphinMainWindow::connectViewSignals(int viewIndex)
975 {
976 DolphinViewContainer* container = m_viewContainer[viewIndex];
977 connect(container, SIGNAL(showFilterBarChanged(bool)),
978 this, SLOT(updateFilterBarAction(bool)));
979
980 DolphinView* view = container->view();
981 connect(view, SIGNAL(selectionChanged(KFileItemList)),
982 this, SLOT(slotSelectionChanged(KFileItemList)));
983 connect(view, SIGNAL(requestItemInfo(KFileItem)),
984 this, SLOT(slotRequestItemInfo(KFileItem)));
985 connect(view, SIGNAL(activated()),
986 this, SLOT(toggleActiveView()));
987 connect(view, SIGNAL(doingOperation(KonqFileUndoManager::CommandType)),
988 this, SLOT(slotDoingOperation(KonqFileUndoManager::CommandType)));
989
990 const KUrlNavigator* navigator = container->urlNavigator();
991 connect(navigator, SIGNAL(urlChanged(const KUrl&)),
992 this, SLOT(changeUrl(const KUrl&)));
993 connect(navigator, SIGNAL(historyChanged()),
994 this, SLOT(slotHistoryChanged()));
995 connect(navigator, SIGNAL(editableStateChanged(bool)),
996 this, SLOT(slotEditableStateChanged(bool)));
997 }
998
999 void DolphinMainWindow::updateSplitAction()
1000 {
1001 QAction* splitAction = actionCollection()->action("split_view");
1002 if (m_viewContainer[SecondaryView] != 0) {
1003 if (m_activeViewContainer == m_viewContainer[PrimaryView]) {
1004 splitAction->setText(i18nc("@action:intoolbar Close right view", "Close"));
1005 splitAction->setIcon(KIcon("view-right-close"));
1006 } else {
1007 splitAction->setText(i18nc("@action:intoolbar Close left view", "Close"));
1008 splitAction->setIcon(KIcon("view-left-close"));
1009 }
1010 } else {
1011 splitAction->setText(i18nc("@action:intoolbar Split view", "Split"));
1012 splitAction->setIcon(KIcon("view-right-new"));
1013 }
1014 }
1015
1016 DolphinMainWindow::UndoUiInterface::UndoUiInterface(DolphinMainWindow* mainWin) :
1017 KonqFileUndoManager::UiInterface(mainWin),
1018 m_mainWin(mainWin)
1019 {
1020 Q_ASSERT(m_mainWin != 0);
1021 }
1022
1023 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1024 {
1025 }
1026
1027 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job)
1028 {
1029 DolphinStatusBar* statusBar = m_mainWin->activeViewContainer()->statusBar();
1030 statusBar->setMessage(job->errorString(), DolphinStatusBar::Error);
1031 }
1032
1033 #include "dolphinmainwindow.moc"