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