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