]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
Rename the "Filter Panel" to "Search Panel"
[dolphin.git] / src / dolphinmainwindow.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz19@gmail.com> *
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
24 #include <config-nepomuk.h>
25
26 #include "dolphinapplication.h"
27 #include "dolphindockwidget.h"
28 #include "dolphincontextmenu.h"
29 #include "dolphinnewfilemenu.h"
30 #include "dolphinviewcontainer.h"
31 #include "mainwindowadaptor.h"
32 #ifdef HAVE_NEPOMUK
33 #include "panels/search/searchpanel.h"
34 #include <Nepomuk/ResourceManager>
35 #endif
36 #include "panels/folders/folderspanel.h"
37 #include "panels/places/placespanel.h"
38 #include "panels/information/informationpanel.h"
39 #include "search/dolphinsearchinformation.h"
40 #include "settings/dolphinsettings.h"
41 #include "settings/dolphinsettingsdialog.h"
42 #include "statusbar/dolphinstatusbar.h"
43 #include "views/dolphinviewactionhandler.h"
44 #include "views/dolphinremoteencoding.h"
45 #include "views/draganddrophelper.h"
46 #include "views/viewproperties.h"
47
48 #ifndef Q_OS_WIN
49 #include "panels/terminal/terminalpanel.h"
50 #endif
51
52 #include "dolphin_generalsettings.h"
53 #include "dolphin_iconsmodesettings.h"
54
55 #include <KAction>
56 #include <KActionCollection>
57 #include <KActionMenu>
58 #include <KConfig>
59 #include <KDesktopFile>
60 #include <kdeversion.h>
61 #include <kdualaction.h>
62 #include <KFileDialog>
63 #include <KFilePlacesModel>
64 #include <KGlobal>
65 #include <KLineEdit>
66 #include <ktoolbar.h>
67 #include <KIcon>
68 #include <KIconLoader>
69 #include <KIO/NetAccess>
70 #include <KInputDialog>
71 #include <KLocale>
72 #include <KProtocolManager>
73 #include <KMenu>
74 #include <KMenuBar>
75 #include <KMessageBox>
76 #include <KFileItemListProperties>
77 #include <konqmimedata.h>
78 #include <KProtocolInfo>
79 #include <KRun>
80 #include <KShell>
81 #include <KStandardDirs>
82 #include <kstatusbar.h>
83 #include <KStandardAction>
84 #include <ktabbar.h>
85 #include <KToggleAction>
86 #include <KUrlNavigator>
87 #include <KUrl>
88 #include <KUrlComboBox>
89 #include <KToolInvocation>
90
91 #include <QDBusMessage>
92 #include <QKeyEvent>
93 #include <QClipboard>
94 #include <QSplitter>
95 #include <kacceleratormanager.h>
96
97 /*
98 * Remembers the tab configuration if a tab has been closed.
99 * Each closed tab can be restored by the menu
100 * "Go -> Recently Closed Tabs".
101 */
102 struct ClosedTab
103 {
104 KUrl primaryUrl;
105 KUrl secondaryUrl;
106 bool isSplit;
107 };
108 Q_DECLARE_METATYPE(ClosedTab)
109
110 DolphinMainWindow::DolphinMainWindow(int id) :
111 KXmlGuiWindow(0),
112 m_newFileMenu(0),
113 m_showMenuBar(0),
114 m_tabBar(0),
115 m_activeViewContainer(0),
116 m_centralWidgetLayout(0),
117 m_id(id),
118 m_tabIndex(0),
119 m_viewTab(),
120 m_actionHandler(0),
121 m_remoteEncoding(0),
122 m_settingsDialog(0),
123 m_lastHandleUrlStatJob(0),
124 m_searchDockIsTemporaryVisible(false)
125 {
126 // Workaround for a X11-issue in combination with KModifierInfo
127 // (see DolphinContextMenu::initializeModifierKeyInfo() for
128 // more information):
129 DolphinContextMenu::initializeModifierKeyInfo();
130
131 setObjectName("Dolphin#");
132
133 m_viewTab.append(ViewTab());
134
135 new MainWindowAdaptor(this);
136 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id), this);
137
138 KIO::FileUndoManager* undoManager = KIO::FileUndoManager::self();
139 undoManager->setUiInterface(new UndoUiInterface());
140
141 connect(undoManager, SIGNAL(undoAvailable(bool)),
142 this, SLOT(slotUndoAvailable(bool)));
143 connect(undoManager, SIGNAL(undoTextChanged(const QString&)),
144 this, SLOT(slotUndoTextChanged(const QString&)));
145 connect(undoManager, SIGNAL(jobRecordingStarted(CommandType)),
146 this, SLOT(clearStatusBar()));
147 connect(undoManager, SIGNAL(jobRecordingFinished(CommandType)),
148 this, SLOT(showCommand(CommandType)));
149 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString&)),
150 this, SLOT(showErrorMessage(const QString&)));
151 connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(const QString&)),
152 this, SLOT(showErrorMessage(const QString&)));
153 }
154
155 DolphinMainWindow::~DolphinMainWindow()
156 {
157 DolphinApplication::app()->removeMainWindow(this);
158 }
159
160 void DolphinMainWindow::openDirectories(const QList<KUrl>& dirs)
161 {
162 if (dirs.isEmpty()) {
163 return;
164 }
165
166 if (dirs.count() == 1) {
167 m_activeViewContainer->setUrl(dirs.first());
168 return;
169 }
170
171 const int oldOpenTabsCount = m_viewTab.count();
172
173 const GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings();
174 const bool hasSplitView = generalSettings->splitView();
175
176 // Open each directory inside a new tab. If the "split view" option has been enabled,
177 // always show two directories within one tab.
178 QList<KUrl>::const_iterator it = dirs.begin();
179 while (it != dirs.end()) {
180 openNewTab(*it);
181 ++it;
182
183 if (hasSplitView && (it != dirs.end())) {
184 const int tabIndex = m_viewTab.count() - 1;
185 m_viewTab[tabIndex].secondaryView->setUrl(*it);
186 ++it;
187 }
188 }
189
190 // remove the previously opened tabs
191 for (int i = 0; i < oldOpenTabsCount; ++i) {
192 closeTab(0);
193 }
194 }
195
196 void DolphinMainWindow::openFiles(const QList<KUrl>& files)
197 {
198 if (files.isEmpty()) {
199 return;
200 }
201
202 // Get all distinct directories from 'files' and open a tab
203 // for each directory. If the "split view" option is enabled, two
204 // directories are shown inside one tab (see openDirectories()).
205 QList<KUrl> dirs;
206 foreach (const KUrl& url, files) {
207 const KUrl dir(url.directory());
208 if (!dirs.contains(dir)) {
209 dirs.append(dir);
210 }
211 }
212
213 openDirectories(dirs);
214
215 // Select the files. Although the files can be split between several
216 // tabs, there is no need to split 'files' accordingly, as
217 // the DolphinView will just ignore invalid selections.
218 const int tabCount = m_viewTab.count();
219 for (int i = 0; i < tabCount; ++i) {
220 m_viewTab[i].primaryView->view()->markUrlsAsSelected(files);
221 if (m_viewTab[i].secondaryView) {
222 m_viewTab[i].secondaryView->view()->markUrlsAsSelected(files);
223 }
224 }
225 }
226
227 void DolphinMainWindow::showCommand(CommandType command)
228 {
229 DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
230 switch (command) {
231 case KIO::FileUndoManager::Copy:
232 statusBar->setMessage(i18nc("@info:status", "Successfully copied."),
233 DolphinStatusBar::OperationCompleted);
234 break;
235 case KIO::FileUndoManager::Move:
236 statusBar->setMessage(i18nc("@info:status", "Successfully moved."),
237 DolphinStatusBar::OperationCompleted);
238 break;
239 case KIO::FileUndoManager::Link:
240 statusBar->setMessage(i18nc("@info:status", "Successfully linked."),
241 DolphinStatusBar::OperationCompleted);
242 break;
243 case KIO::FileUndoManager::Trash:
244 statusBar->setMessage(i18nc("@info:status", "Successfully moved to trash."),
245 DolphinStatusBar::OperationCompleted);
246 break;
247 case KIO::FileUndoManager::Rename:
248 statusBar->setMessage(i18nc("@info:status", "Successfully renamed."),
249 DolphinStatusBar::OperationCompleted);
250 break;
251
252 case KIO::FileUndoManager::Mkdir:
253 statusBar->setMessage(i18nc("@info:status", "Created folder."),
254 DolphinStatusBar::OperationCompleted);
255 break;
256
257 default:
258 break;
259 }
260 }
261
262 void DolphinMainWindow::refreshViews()
263 {
264 Q_ASSERT(m_viewTab[m_tabIndex].primaryView);
265
266 // remember the current active view, as because of
267 // the refreshing the active view might change to
268 // the secondary view
269 DolphinViewContainer* activeViewContainer = m_activeViewContainer;
270
271 const int tabCount = m_viewTab.count();
272 for (int i = 0; i < tabCount; ++i) {
273 m_viewTab[i].primaryView->refresh();
274 if (m_viewTab[i].secondaryView) {
275 m_viewTab[i].secondaryView->refresh();
276 }
277 }
278
279 setActiveViewContainer(activeViewContainer);
280
281 const GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings();
282 if (generalSettings->modifiedStartupSettings()) {
283 // The startup settings have been changed by the user (see bug #254947).
284 // Synchronize the split-view setting with the active view:
285 const bool splitView = generalSettings->splitView();
286 const ViewTab& activeTab = m_viewTab[m_tabIndex];
287 const bool toggle = ( splitView && !activeTab.secondaryView)
288 || (!splitView && activeTab.secondaryView);
289 if (toggle) {
290 toggleSplitView();
291 }
292 }
293 }
294
295 void DolphinMainWindow::pasteIntoFolder()
296 {
297 m_activeViewContainer->view()->pasteIntoFolder();
298 }
299
300 void DolphinMainWindow::changeUrl(const KUrl& url)
301 {
302 if (!KProtocolManager::supportsListing(url)) {
303 // The URL navigator only checks for validity, not
304 // if the URL can be listed. An error message is
305 // shown due to DolphinViewContainer::restoreView().
306 return;
307 }
308
309 DolphinViewContainer* view = activeViewContainer();
310 if (view) {
311 view->setUrl(url);
312 updateEditActions();
313 updateViewActions();
314 updateGoActions();
315 setUrlAsCaption(url);
316 if (m_viewTab.count() > 1) {
317 m_tabBar->setTabText(m_tabIndex, squeezedText(tabName(m_activeViewContainer->url())));
318 }
319 const QString iconName = KMimeType::iconNameForUrl(url);
320 m_tabBar->setTabIcon(m_tabIndex, KIcon(iconName));
321 emit urlChanged(url);
322 }
323 }
324
325 void DolphinMainWindow::slotEditableStateChanged(bool editable)
326 {
327 KToggleAction* editableLocationAction =
328 static_cast<KToggleAction*>(actionCollection()->action("editable_location"));
329 editableLocationAction->setChecked(editable);
330 }
331
332 void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection)
333 {
334 updateEditActions();
335
336 Q_ASSERT(m_viewTab[m_tabIndex].primaryView);
337 int selectedUrlsCount = m_viewTab[m_tabIndex].primaryView->view()->selectedItemsCount();
338 if (m_viewTab[m_tabIndex].secondaryView) {
339 selectedUrlsCount += m_viewTab[m_tabIndex].secondaryView->view()->selectedItemsCount();
340 }
341
342 QAction* compareFilesAction = actionCollection()->action("compare_files");
343 if (selectedUrlsCount == 2) {
344 compareFilesAction->setEnabled(isKompareInstalled());
345 } else {
346 compareFilesAction->setEnabled(false);
347 }
348
349 emit selectionChanged(selection);
350 }
351
352 void DolphinMainWindow::slotRequestItemInfo(const KFileItem& item)
353 {
354 emit requestItemInfo(item);
355 }
356
357 void DolphinMainWindow::updateHistory()
358 {
359 const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
360 const int index = urlNavigator->historyIndex();
361
362 QAction* backAction = actionCollection()->action("go_back");
363 backAction->setToolTip(i18nc("@info", "Go back"));
364 if (backAction) {
365 backAction->setEnabled(index < urlNavigator->historySize() - 1);
366 }
367
368 QAction* forwardAction = actionCollection()->action("go_forward");
369 forwardAction->setToolTip(i18nc("@info", "Go forward"));
370 if (forwardAction) {
371 forwardAction->setEnabled(index > 0);
372 }
373 }
374
375 void DolphinMainWindow::updateFilterBarAction(bool show)
376 {
377 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
378 showFilterBarAction->setChecked(show);
379 }
380
381 void DolphinMainWindow::openNewMainWindow()
382 {
383 DolphinApplication::app()->createMainWindow()->show();
384 }
385
386 void DolphinMainWindow::openNewTab()
387 {
388 const bool isUrlEditable = m_activeViewContainer->urlNavigator()->isUrlEditable();
389
390 openNewTab(m_activeViewContainer->url());
391 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
392
393 // The URL navigator of the new tab should have the same editable state
394 // as the current tab
395 KUrlNavigator* navigator = m_activeViewContainer->urlNavigator();
396 navigator->setUrlEditable(isUrlEditable);
397
398 if (isUrlEditable) {
399 // If a new tab is opened and the URL is editable, assure that
400 // the user can edit the URL without manually setting the focus
401 navigator->setFocus();
402 }
403 }
404
405 void DolphinMainWindow::openNewTab(const KUrl& url)
406 {
407 QWidget* focusWidget = QApplication::focusWidget();
408
409 if (m_viewTab.count() == 1) {
410 // Only one view is open currently and hence no tab is shown at
411 // all. Before creating a tab for 'url', provide a tab for the current URL.
412 const KUrl currentUrl = m_activeViewContainer->url();
413 m_tabBar->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl)),
414 squeezedText(tabName(currentUrl)));
415 m_tabBar->blockSignals(false);
416 }
417
418 m_tabBar->addTab(KIcon(KMimeType::iconNameForUrl(url)),
419 squeezedText(tabName(url)));
420
421 ViewTab viewTab;
422 viewTab.splitter = new QSplitter(this);
423 viewTab.splitter->setChildrenCollapsible(false);
424 viewTab.primaryView = new DolphinViewContainer(url, viewTab.splitter);
425 viewTab.primaryView->setActive(false);
426 connectViewSignals(viewTab.primaryView);
427
428 m_viewTab.append(viewTab);
429
430 actionCollection()->action("close_tab")->setEnabled(true);
431
432 // provide a split view, if the startup settings are set this way
433 const GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings();
434 if (generalSettings->splitView()) {
435 const int tabIndex = m_viewTab.count() - 1;
436 createSecondaryView(tabIndex);
437 m_viewTab[tabIndex].secondaryView->setActive(true);
438 m_viewTab[tabIndex].isPrimaryViewActive = false;
439 }
440
441 if (focusWidget) {
442 // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
443 // in background, assure that the previous focused widget gets the focus back.
444 focusWidget->setFocus();
445 }
446 }
447
448 void DolphinMainWindow::activateNextTab()
449 {
450 if ((m_viewTab.count() == 1) || (m_tabBar->count() < 2)) {
451 return;
452 }
453
454 const int tabIndex = (m_tabBar->currentIndex() + 1) % m_tabBar->count();
455 m_tabBar->setCurrentIndex(tabIndex);
456 }
457
458 void DolphinMainWindow::activatePrevTab()
459 {
460 if ((m_viewTab.count() == 1) || (m_tabBar->count() < 2)) {
461 return;
462 }
463
464 int tabIndex = m_tabBar->currentIndex() - 1;
465 if (tabIndex == -1) {
466 tabIndex = m_tabBar->count() - 1;
467 }
468 m_tabBar->setCurrentIndex(tabIndex);
469 }
470
471 void DolphinMainWindow::openInNewTab()
472 {
473 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
474 if (list.isEmpty()) {
475 openNewTab(m_activeViewContainer->url());
476 } else if ((list.count() == 1) && list[0].isDir()) {
477 openNewTab(list[0].url());
478 }
479 }
480
481 void DolphinMainWindow::openInNewWindow()
482 {
483 KUrl newWindowUrl;
484
485 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
486 if (list.isEmpty()) {
487 newWindowUrl = m_activeViewContainer->url();
488 } else if ((list.count() == 1) && list[0].isDir()) {
489 newWindowUrl = list[0].url();
490 }
491
492 if (!newWindowUrl.isEmpty()) {
493 DolphinMainWindow* window = DolphinApplication::app()->createMainWindow();
494 window->changeUrl(newWindowUrl);
495 window->show();
496 }
497 }
498
499 void DolphinMainWindow::toggleActiveView()
500 {
501 if (!m_viewTab[m_tabIndex].secondaryView) {
502 // only one view is available
503 return;
504 }
505
506 Q_ASSERT(m_activeViewContainer);
507 Q_ASSERT(m_viewTab[m_tabIndex].primaryView);
508
509 DolphinViewContainer* left = m_viewTab[m_tabIndex].primaryView;
510 DolphinViewContainer* right = m_viewTab[m_tabIndex].secondaryView;
511 setActiveViewContainer(m_activeViewContainer == right ? left : right);
512 }
513
514 void DolphinMainWindow::showEvent(QShowEvent* event)
515 {
516 KXmlGuiWindow::showEvent(event);
517 if (!event->spontaneous()) {
518 m_activeViewContainer->view()->setFocus();
519 }
520 }
521
522 void DolphinMainWindow::closeEvent(QCloseEvent* event)
523 {
524 DolphinSettings& settings = DolphinSettings::instance();
525 GeneralSettings* generalSettings = settings.generalSettings();
526
527 // Find out if Dolphin is closed directly by the user or
528 // by the session manager because the session is closed
529 bool closedByUser = true;
530 DolphinApplication *application = qobject_cast<DolphinApplication*>(qApp);
531 if (application && application->sessionSaving()) {
532 closedByUser = false;
533 }
534
535 if ((m_viewTab.count() > 1) && generalSettings->confirmClosingMultipleTabs() && closedByUser) {
536 // Ask the user if he really wants to quit and close all tabs.
537 // Open a confirmation dialog with 3 buttons:
538 // KDialog::Yes -> Quit
539 // KDialog::No -> Close only the current tab
540 // KDialog::Cancel -> do nothing
541 KDialog *dialog = new KDialog(this, Qt::Dialog);
542 dialog->setCaption(i18nc("@title:window", "Confirmation"));
543 dialog->setButtons(KDialog::Yes | KDialog::No | KDialog::Cancel);
544 dialog->setModal(true);
545 dialog->setButtonGuiItem(KDialog::Yes, KStandardGuiItem::quit());
546 dialog->setButtonGuiItem(KDialog::No, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
547 dialog->setButtonGuiItem(KDialog::Cancel, KStandardGuiItem::cancel());
548 dialog->setDefaultButton(KDialog::Yes);
549
550 bool doNotAskAgainCheckboxResult = false;
551
552 const int result = KMessageBox::createKMessageBox(dialog,
553 QMessageBox::Warning,
554 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
555 QStringList(),
556 i18n("Do not ask again"),
557 &doNotAskAgainCheckboxResult,
558 KMessageBox::Notify);
559
560 if (doNotAskAgainCheckboxResult) {
561 generalSettings->setConfirmClosingMultipleTabs(false);
562 }
563
564 switch (result) {
565 case KDialog::Yes:
566 // Quit
567 break;
568 case KDialog::No:
569 // Close only the current tab
570 closeTab();
571 default:
572 event->ignore();
573 return;
574 }
575 }
576
577 generalSettings->setFirstRun(false);
578
579 settings.save();
580
581 if (m_searchDockIsTemporaryVisible) {
582 QDockWidget* searchDock = findChild<QDockWidget*>("searchDock");
583 if (searchDock) {
584 searchDock->hide();
585 }
586 m_searchDockIsTemporaryVisible = false;
587 }
588
589 KXmlGuiWindow::closeEvent(event);
590 }
591
592 void DolphinMainWindow::saveProperties(KConfigGroup& group)
593 {
594 const int tabCount = m_viewTab.count();
595 group.writeEntry("Tab Count", tabCount);
596 group.writeEntry("Active Tab Index", m_tabBar->currentIndex());
597
598 for (int i = 0; i < tabCount; ++i) {
599 const DolphinViewContainer* cont = m_viewTab[i].primaryView;
600 group.writeEntry(tabProperty("Primary URL", i), cont->url().url());
601 group.writeEntry(tabProperty("Primary Editable", i),
602 cont->urlNavigator()->isUrlEditable());
603
604 cont = m_viewTab[i].secondaryView;
605 if (cont) {
606 group.writeEntry(tabProperty("Secondary URL", i), cont->url().url());
607 group.writeEntry(tabProperty("Secondary Editable", i),
608 cont->urlNavigator()->isUrlEditable());
609 }
610 }
611 }
612
613 void DolphinMainWindow::readProperties(const KConfigGroup& group)
614 {
615 const int tabCount = group.readEntry("Tab Count", 1);
616 for (int i = 0; i < tabCount; ++i) {
617 DolphinViewContainer* cont = m_viewTab[i].primaryView;
618
619 cont->setUrl(group.readEntry(tabProperty("Primary URL", i)));
620 const bool editable = group.readEntry(tabProperty("Primary Editable", i), false);
621 cont->urlNavigator()->setUrlEditable(editable);
622
623 cont = m_viewTab[i].secondaryView;
624 const QString secondaryUrl = group.readEntry(tabProperty("Secondary URL", i));
625 if (!secondaryUrl.isEmpty()) {
626 if (!cont) {
627 // a secondary view should be shown, but no one is available
628 // currently -> create a new view
629 toggleSplitView();
630 cont = m_viewTab[i].secondaryView;
631 Q_ASSERT(cont);
632 }
633
634 cont->setUrl(secondaryUrl);
635 const bool editable = group.readEntry(tabProperty("Secondary Editable", i), false);
636 cont->urlNavigator()->setUrlEditable(editable);
637 } else if (cont) {
638 // no secondary view should be shown, but the default setting shows
639 // one already -> close the view
640 toggleSplitView();
641 }
642
643 // openNewTab() needs to be called only tabCount - 1 times
644 if (i != tabCount - 1) {
645 openNewTab();
646 }
647 }
648
649 const int index = group.readEntry("Active Tab Index", 0);
650 m_tabBar->setCurrentIndex(index);
651 }
652
653 void DolphinMainWindow::updateNewMenu()
654 {
655 m_newFileMenu->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
656 m_newFileMenu->checkUpToDate();
657 m_newFileMenu->setPopupFiles(activeViewContainer()->url());
658 }
659
660 void DolphinMainWindow::createDirectory()
661 {
662 m_newFileMenu->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
663 m_newFileMenu->setPopupFiles(activeViewContainer()->url());
664 m_newFileMenu->createDirectory();
665 }
666
667 void DolphinMainWindow::quit()
668 {
669 close();
670 }
671
672 void DolphinMainWindow::showErrorMessage(const QString& message)
673 {
674 if (!message.isEmpty()) {
675 DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
676 statusBar->setMessage(message, DolphinStatusBar::Error);
677 }
678 }
679
680 void DolphinMainWindow::slotUndoAvailable(bool available)
681 {
682 QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
683 if (undoAction) {
684 undoAction->setEnabled(available);
685 }
686 }
687
688 void DolphinMainWindow::restoreClosedTab(QAction* action)
689 {
690 if (action->data().toBool()) {
691 // clear all actions except the "Empty Recently Closed Tabs"
692 // action and the separator
693 QList<QAction*> actions = m_recentTabsMenu->menu()->actions();
694 const int count = actions.size();
695 for (int i = 2; i < count; ++i) {
696 m_recentTabsMenu->menu()->removeAction(actions.at(i));
697 }
698 } else {
699 const ClosedTab closedTab = action->data().value<ClosedTab>();
700 openNewTab(closedTab.primaryUrl);
701 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
702
703 if (closedTab.isSplit) {
704 // create secondary view
705 toggleSplitView();
706 m_viewTab[m_tabIndex].secondaryView->setUrl(closedTab.secondaryUrl);
707 }
708
709 m_recentTabsMenu->removeAction(action);
710 }
711
712 if (m_recentTabsMenu->menu()->actions().count() == 2) {
713 m_recentTabsMenu->setEnabled(false);
714 }
715 }
716
717 void DolphinMainWindow::slotUndoTextChanged(const QString& text)
718 {
719 QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
720 if (undoAction) {
721 undoAction->setText(text);
722 }
723 }
724
725 void DolphinMainWindow::undo()
726 {
727 clearStatusBar();
728 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
729 KIO::FileUndoManager::self()->undo();
730 }
731
732 void DolphinMainWindow::cut()
733 {
734 m_activeViewContainer->view()->cutSelectedItems();
735 }
736
737 void DolphinMainWindow::copy()
738 {
739 m_activeViewContainer->view()->copySelectedItems();
740 }
741
742 void DolphinMainWindow::paste()
743 {
744 m_activeViewContainer->view()->paste();
745 }
746
747 void DolphinMainWindow::find()
748 {
749 m_activeViewContainer->setSearchModeEnabled(true);
750 }
751
752 void DolphinMainWindow::updatePasteAction()
753 {
754 QAction* pasteAction = actionCollection()->action(KStandardAction::name(KStandardAction::Paste));
755 QPair<bool, QString> pasteInfo = m_activeViewContainer->view()->pasteInfo();
756 pasteAction->setEnabled(pasteInfo.first);
757 pasteAction->setText(pasteInfo.second);
758 }
759
760 void DolphinMainWindow::selectAll()
761 {
762 clearStatusBar();
763
764 // if the URL navigator is editable and focused, select the whole
765 // URL instead of all items of the view
766
767 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
768 QLineEdit* lineEdit = urlNavigator->editor()->lineEdit(); // krazy:exclude=qclasses
769 const bool selectUrl = urlNavigator->isUrlEditable() &&
770 lineEdit->hasFocus();
771 if (selectUrl) {
772 lineEdit->selectAll();
773 } else {
774 m_activeViewContainer->view()->selectAll();
775 }
776 }
777
778 void DolphinMainWindow::invertSelection()
779 {
780 clearStatusBar();
781 m_activeViewContainer->view()->invertSelection();
782 }
783
784 void DolphinMainWindow::toggleSplitView()
785 {
786 if (!m_viewTab[m_tabIndex].secondaryView) {
787 createSecondaryView(m_tabIndex);
788 setActiveViewContainer(m_viewTab[m_tabIndex].secondaryView);
789 } else if (m_activeViewContainer == m_viewTab[m_tabIndex].secondaryView) {
790 // remove secondary view
791 m_viewTab[m_tabIndex].secondaryView->close();
792 m_viewTab[m_tabIndex].secondaryView->deleteLater();
793 m_viewTab[m_tabIndex].secondaryView = 0;
794
795 setActiveViewContainer(m_viewTab[m_tabIndex].primaryView);
796 } else {
797 // The primary view is active and should be closed. Hence from a users point of view
798 // the content of the secondary view should be moved to the primary view.
799 // From an implementation point of view it is more efficient to close
800 // the primary view and exchange the internal pointers afterwards.
801
802 m_viewTab[m_tabIndex].primaryView->close();
803 m_viewTab[m_tabIndex].primaryView->deleteLater();
804 m_viewTab[m_tabIndex].primaryView = m_viewTab[m_tabIndex].secondaryView;
805 m_viewTab[m_tabIndex].secondaryView = 0;
806
807 setActiveViewContainer(m_viewTab[m_tabIndex].primaryView);
808 }
809
810 updateViewActions();
811 }
812
813 void DolphinMainWindow::reloadView()
814 {
815 clearStatusBar();
816 m_activeViewContainer->view()->reload();
817 }
818
819 void DolphinMainWindow::stopLoading()
820 {
821 m_activeViewContainer->view()->stopLoading();
822 }
823
824 void DolphinMainWindow::enableStopAction()
825 {
826 actionCollection()->action("stop")->setEnabled(true);
827 }
828
829 void DolphinMainWindow::disableStopAction()
830 {
831 actionCollection()->action("stop")->setEnabled(false);
832 }
833
834 void DolphinMainWindow::showFilterBar()
835 {
836 m_activeViewContainer->setFilterBarVisible(true);
837 }
838
839 void DolphinMainWindow::toggleEditLocation()
840 {
841 clearStatusBar();
842
843 QAction* action = actionCollection()->action("editable_location");
844 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
845 urlNavigator->setUrlEditable(action->isChecked());
846 }
847
848 void DolphinMainWindow::replaceLocation()
849 {
850 KUrlNavigator* navigator = m_activeViewContainer->urlNavigator();
851 navigator->setUrlEditable(true);
852 navigator->setFocus();
853
854 // select the whole text of the combo box editor
855 QLineEdit* lineEdit = navigator->editor()->lineEdit(); // krazy:exclude=qclasses
856 lineEdit->selectAll();
857 }
858
859 void DolphinMainWindow::togglePanelLockState()
860 {
861 GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings();
862
863 const bool newLockState = !generalSettings->lockPanels();
864 foreach (QObject* child, children()) {
865 DolphinDockWidget* dock = qobject_cast<DolphinDockWidget*>(child);
866 if (dock) {
867 dock->setLocked(newLockState);
868 }
869 }
870
871 generalSettings->setLockPanels(newLockState);
872 }
873
874 void DolphinMainWindow::goBack()
875 {
876 clearStatusBar();
877
878 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
879 urlNavigator->goBack();
880
881 if (urlNavigator->locationState().isEmpty()) {
882 // An empty location state indicates a redirection URL,
883 // which must be skipped too
884 urlNavigator->goBack();
885 }
886 }
887
888 void DolphinMainWindow::goForward()
889 {
890 clearStatusBar();
891 m_activeViewContainer->urlNavigator()->goForward();
892 }
893
894 void DolphinMainWindow::goUp()
895 {
896 clearStatusBar();
897 m_activeViewContainer->urlNavigator()->goUp();
898 }
899
900 void DolphinMainWindow::goBack(Qt::MouseButtons buttons)
901 {
902 // The default case (left button pressed) is handled in goBack().
903 if (buttons == Qt::MidButton) {
904 KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator();
905 const int index = urlNavigator->historyIndex() + 1;
906 openNewTab(urlNavigator->locationUrl(index));
907 }
908 }
909
910 void DolphinMainWindow::goForward(Qt::MouseButtons buttons)
911 {
912 // The default case (left button pressed) is handled in goForward().
913 if (buttons == Qt::MidButton) {
914 KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator();
915 const int index = urlNavigator->historyIndex() - 1;
916 openNewTab(urlNavigator->locationUrl(index));
917 }
918 }
919
920 void DolphinMainWindow::goUp(Qt::MouseButtons buttons)
921 {
922 // The default case (left button pressed) is handled in goUp().
923 if (buttons == Qt::MidButton) {
924 openNewTab(activeViewContainer()->url().upUrl());
925 }
926 }
927
928 void DolphinMainWindow::goHome()
929 {
930 clearStatusBar();
931 m_activeViewContainer->urlNavigator()->goHome();
932 }
933
934 void DolphinMainWindow::compareFiles()
935 {
936 // The method is only invoked if exactly 2 files have
937 // been selected. The selected files may be:
938 // - both in the primary view
939 // - both in the secondary view
940 // - one in the primary view and the other in the secondary
941 // view
942 Q_ASSERT(m_viewTab[m_tabIndex].primaryView);
943
944 KUrl urlA;
945 KUrl urlB;
946
947 KFileItemList items = m_viewTab[m_tabIndex].primaryView->view()->selectedItems();
948
949 switch (items.count()) {
950 case 0: {
951 Q_ASSERT(m_viewTab[m_tabIndex].secondaryView);
952 items = m_viewTab[m_tabIndex].secondaryView->view()->selectedItems();
953 Q_ASSERT(items.count() == 2);
954 urlA = items[0].url();
955 urlB = items[1].url();
956 break;
957 }
958
959 case 1: {
960 urlA = items[0].url();
961 Q_ASSERT(m_viewTab[m_tabIndex].secondaryView);
962 items = m_viewTab[m_tabIndex].secondaryView->view()->selectedItems();
963 Q_ASSERT(items.count() == 1);
964 urlB = items[0].url();
965 break;
966 }
967
968 case 2: {
969 urlA = items[0].url();
970 urlB = items[1].url();
971 break;
972 }
973
974 default: {
975 // may not happen: compareFiles may only get invoked if 2
976 // files are selected
977 Q_ASSERT(false);
978 }
979 }
980
981 QString command("kompare -c \"");
982 command.append(urlA.pathOrUrl());
983 command.append("\" \"");
984 command.append(urlB.pathOrUrl());
985 command.append('\"');
986 KRun::runCommand(command, "Kompare", "kompare", this);
987 }
988
989 void DolphinMainWindow::toggleShowMenuBar()
990 {
991 const bool visible = menuBar()->isVisible();
992 menuBar()->setVisible(!visible);
993 }
994
995 void DolphinMainWindow::openTerminal()
996 {
997 QString dir(QDir::homePath());
998
999 // If the given directory is not local, it can still be the URL of an
1000 // ioslave using UDS_LOCAL_PATH which to be converted first.
1001 KUrl url = KIO::NetAccess::mostLocalUrl(m_activeViewContainer->url(), this);
1002
1003 //If the URL is local after the above conversion, set the directory.
1004 if (url.isLocalFile()) {
1005 dir = url.toLocalFile();
1006 }
1007
1008 KToolInvocation::invokeTerminal(QString(), dir);
1009 }
1010
1011 void DolphinMainWindow::editSettings()
1012 {
1013 if (!m_settingsDialog) {
1014 const KUrl url = activeViewContainer()->url();
1015 m_settingsDialog = new DolphinSettingsDialog(url, this);
1016 m_settingsDialog->setAttribute(Qt::WA_DeleteOnClose);
1017 m_settingsDialog->show();
1018 } else {
1019 m_settingsDialog->raise();
1020 }
1021 }
1022
1023 void DolphinMainWindow::setActiveTab(int index)
1024 {
1025 Q_ASSERT(index >= 0);
1026 Q_ASSERT(index < m_viewTab.count());
1027 if (index == m_tabIndex) {
1028 return;
1029 }
1030
1031 // hide current tab content
1032 ViewTab& hiddenTab = m_viewTab[m_tabIndex];
1033 hiddenTab.isPrimaryViewActive = hiddenTab.primaryView->isActive();
1034 hiddenTab.primaryView->setActive(false);
1035 if (hiddenTab.secondaryView) {
1036 hiddenTab.secondaryView->setActive(false);
1037 }
1038 QSplitter* splitter = m_viewTab[m_tabIndex].splitter;
1039 splitter->hide();
1040 m_centralWidgetLayout->removeWidget(splitter);
1041
1042 // show active tab content
1043 m_tabIndex = index;
1044
1045 ViewTab& viewTab = m_viewTab[index];
1046 m_centralWidgetLayout->addWidget(viewTab.splitter, 1);
1047 viewTab.primaryView->show();
1048 if (viewTab.secondaryView) {
1049 viewTab.secondaryView->show();
1050 }
1051 viewTab.splitter->show();
1052
1053 setActiveViewContainer(viewTab.isPrimaryViewActive ? viewTab.primaryView :
1054 viewTab.secondaryView);
1055 }
1056
1057 void DolphinMainWindow::closeTab()
1058 {
1059 closeTab(m_tabBar->currentIndex());
1060 }
1061
1062 void DolphinMainWindow::closeTab(int index)
1063 {
1064 Q_ASSERT(index >= 0);
1065 Q_ASSERT(index < m_viewTab.count());
1066 if (m_viewTab.count() == 1) {
1067 // the last tab may never get closed
1068 return;
1069 }
1070
1071 if (index == m_tabIndex) {
1072 // The tab that should be closed is the active tab. Activate the
1073 // previous tab before closing the tab.
1074 m_tabBar->setCurrentIndex((index > 0) ? index - 1 : 1);
1075 }
1076 rememberClosedTab(index);
1077
1078 // delete tab
1079 m_viewTab[index].primaryView->deleteLater();
1080 if (m_viewTab[index].secondaryView) {
1081 m_viewTab[index].secondaryView->deleteLater();
1082 }
1083 m_viewTab[index].splitter->deleteLater();
1084 m_viewTab.erase(m_viewTab.begin() + index);
1085
1086 m_tabBar->blockSignals(true);
1087 m_tabBar->removeTab(index);
1088
1089 if (m_tabIndex > index) {
1090 m_tabIndex--;
1091 Q_ASSERT(m_tabIndex >= 0);
1092 }
1093
1094 // if only one tab is left, also remove the tab entry so that
1095 // closing the last tab is not possible
1096 if (m_viewTab.count() == 1) {
1097 m_tabBar->removeTab(0);
1098 actionCollection()->action("close_tab")->setEnabled(false);
1099 } else {
1100 m_tabBar->blockSignals(false);
1101 }
1102 }
1103
1104 void DolphinMainWindow::openTabContextMenu(int index, const QPoint& pos)
1105 {
1106 KMenu menu(this);
1107
1108 QAction* newTabAction = menu.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1109 newTabAction->setShortcut(actionCollection()->action("new_tab")->shortcut());
1110
1111 QAction* detachTabAction = menu.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
1112
1113 QAction* closeOtherTabsAction = menu.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1114
1115 QAction* closeTabAction = menu.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1116 closeTabAction->setShortcut(actionCollection()->action("close_tab")->shortcut());
1117 QAction* selectedAction = menu.exec(pos);
1118 if (selectedAction == newTabAction) {
1119 const ViewTab& tab = m_viewTab[index];
1120 Q_ASSERT(tab.primaryView);
1121 const KUrl url = tab.secondaryView && tab.secondaryView->isActive() ?
1122 tab.secondaryView->url() : tab.primaryView->url();
1123 openNewTab(url);
1124 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
1125 } else if (selectedAction == detachTabAction) {
1126 const ViewTab& tab = m_viewTab[index];
1127 Q_ASSERT(tab.primaryView);
1128 const KUrl primaryUrl = tab.primaryView->url();
1129 DolphinMainWindow* window = DolphinApplication::app()->createMainWindow();
1130 window->changeUrl(primaryUrl);
1131
1132 if (tab.secondaryView) {
1133 const KUrl secondaryUrl = tab.secondaryView->url();
1134 if (!window->m_viewTab[0].secondaryView) {
1135 window->toggleSplitView();
1136 }
1137 window->m_viewTab[0].secondaryView->setUrl(secondaryUrl);
1138 if (tab.primaryView->isActive()) {
1139 window->m_viewTab[0].primaryView->setActive(true);
1140 } else {
1141 window->m_viewTab[0].secondaryView->setActive(true);
1142 }
1143 }
1144 window->show();
1145 closeTab(index);
1146 } else if (selectedAction == closeOtherTabsAction) {
1147 const int count = m_tabBar->count();
1148 for (int i = 0; i < index; ++i) {
1149 closeTab(0);
1150 }
1151 for (int i = index + 1; i < count; ++i) {
1152 closeTab(1);
1153 }
1154 } else if (selectedAction == closeTabAction) {
1155 closeTab(index);
1156 }
1157 }
1158
1159 void DolphinMainWindow::slotTabMoved(int from, int to)
1160 {
1161 m_viewTab.move(from, to);
1162 m_tabIndex = m_tabBar->currentIndex();
1163 }
1164
1165 void DolphinMainWindow::handlePlacesClick(const KUrl& url, Qt::MouseButtons buttons)
1166 {
1167 if (buttons & Qt::MidButton) {
1168 openNewTab(url);
1169 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
1170 } else {
1171 changeUrl(url);
1172 }
1173 }
1174
1175 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent* event, bool& canDecode)
1176 {
1177 canDecode = KUrl::List::canDecode(event->mimeData());
1178 }
1179
1180 void DolphinMainWindow::handleUrl(const KUrl& url)
1181 {
1182 delete m_lastHandleUrlStatJob;
1183 m_lastHandleUrlStatJob = 0;
1184
1185 if (url.isLocalFile() && QFileInfo(url.toLocalFile()).isDir()) {
1186 activeViewContainer()->setUrl(url);
1187 } else if (KProtocolManager::supportsListing(url)) {
1188 // stat the URL to see if it is a dir or not
1189 m_lastHandleUrlStatJob = KIO::stat(url, KIO::HideProgressInfo);
1190 connect(m_lastHandleUrlStatJob, SIGNAL(result(KJob*)),
1191 this, SLOT(slotHandleUrlStatFinished(KJob*)));
1192
1193 } else {
1194 new KRun(url, this);
1195 }
1196 }
1197
1198 void DolphinMainWindow::slotHandleUrlStatFinished(KJob* job)
1199 {
1200 m_lastHandleUrlStatJob = 0;
1201 const KIO::UDSEntry entry = static_cast<KIO::StatJob*>(job)->statResult();
1202 const KUrl url = static_cast<KIO::StatJob*>(job)->url();
1203 if (entry.isDir()) {
1204 activeViewContainer()->setUrl(url);
1205 } else {
1206 new KRun(url, this);
1207 }
1208 }
1209
1210 void DolphinMainWindow::tabDropEvent(int tab, QDropEvent* event)
1211 {
1212 const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
1213 if (!urls.isEmpty() && tab != -1) {
1214 const ViewTab& viewTab = m_viewTab[tab];
1215 const KUrl destPath = viewTab.isPrimaryViewActive ? viewTab.primaryView->url() : viewTab.secondaryView->url();
1216 DragAndDropHelper::instance().dropUrls(KFileItem(), destPath, event, m_tabBar);
1217 }
1218 }
1219
1220 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable)
1221 {
1222 newFileMenu()->setEnabled(isFolderWritable);
1223 }
1224
1225 void DolphinMainWindow::slotSearchModeChanged(bool enabled)
1226 {
1227 #ifdef HAVE_NEPOMUK
1228 const KUrl url = m_activeViewContainer->url();
1229 const DolphinSearchInformation& searchInfo = DolphinSearchInformation::instance();
1230 if (!searchInfo.isIndexingEnabled() || !searchInfo.isPathIndexed(url)) {
1231 return;
1232 }
1233
1234 QDockWidget* searchDock = findChild<QDockWidget*>("searchDock");
1235 if (!searchDock) {
1236 return;
1237 }
1238
1239 if (enabled) {
1240 if (!searchDock->isVisible()) {
1241 m_searchDockIsTemporaryVisible = true;
1242 }
1243 searchDock->show();
1244 } else {
1245 if (searchDock->isVisible() && m_searchDockIsTemporaryVisible) {
1246 searchDock->hide();
1247 }
1248 m_searchDockIsTemporaryVisible = false;
1249 }
1250 #else
1251 Q_UNUSED(enabled);
1252 #endif
1253 }
1254
1255 void DolphinMainWindow::openContextMenu(const KFileItem& item,
1256 const KUrl& url,
1257 const QList<QAction*>& customActions)
1258 {
1259 QPointer<DolphinContextMenu> contextMenu = new DolphinContextMenu(this, item, url);
1260 contextMenu->setCustomActions(customActions);
1261 const DolphinContextMenu::Command command = contextMenu->open();
1262
1263 switch (command) {
1264 case DolphinContextMenu::OpenParentFolderInNewWindow: {
1265 DolphinMainWindow* window = DolphinApplication::app()->createMainWindow();
1266 window->changeUrl(item.url().upUrl());
1267 window->show();
1268 break;
1269 }
1270
1271 case DolphinContextMenu::OpenParentFolderInNewTab:
1272 openNewTab(item.url().upUrl());
1273 break;
1274
1275 case DolphinContextMenu::None:
1276 default:
1277 break;
1278 }
1279
1280 delete contextMenu;
1281 }
1282
1283 void DolphinMainWindow::init()
1284 {
1285 DolphinSettings& settings = DolphinSettings::instance();
1286
1287 // Check whether Dolphin runs the first time. If yes then
1288 // a proper default window size is given at the end of DolphinMainWindow::init().
1289 GeneralSettings* generalSettings = settings.generalSettings();
1290 const bool firstRun = generalSettings->firstRun();
1291 if (firstRun) {
1292 generalSettings->setViewPropsTimestamp(QDateTime::currentDateTime());
1293 }
1294
1295 setAcceptDrops(true);
1296
1297 m_viewTab[m_tabIndex].splitter = new QSplitter(this);
1298 m_viewTab[m_tabIndex].splitter->setChildrenCollapsible(false);
1299
1300 setupActions();
1301
1302 const KUrl homeUrl(generalSettings->homeUrl());
1303 setUrlAsCaption(homeUrl);
1304 m_actionHandler = new DolphinViewActionHandler(actionCollection(), this);
1305 connect(m_actionHandler, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
1306 connect(m_actionHandler, SIGNAL(createDirectory()), SLOT(createDirectory()));
1307 ViewProperties props(homeUrl);
1308 m_viewTab[m_tabIndex].primaryView = new DolphinViewContainer(homeUrl,
1309 m_viewTab[m_tabIndex].splitter);
1310
1311 m_activeViewContainer = m_viewTab[m_tabIndex].primaryView;
1312 connectViewSignals(m_activeViewContainer);
1313 DolphinView* view = m_activeViewContainer->view();
1314 m_activeViewContainer->show();
1315 m_actionHandler->setCurrentView(view);
1316
1317 m_remoteEncoding = new DolphinRemoteEncoding(this, m_actionHandler);
1318 connect(this, SIGNAL(urlChanged(const KUrl&)),
1319 m_remoteEncoding, SLOT(slotAboutToOpenUrl()));
1320
1321 m_tabBar = new KTabBar(this);
1322 m_tabBar->setMovable(true);
1323 m_tabBar->setTabsClosable(true);
1324 connect(m_tabBar, SIGNAL(currentChanged(int)),
1325 this, SLOT(setActiveTab(int)));
1326 connect(m_tabBar, SIGNAL(tabCloseRequested(int)),
1327 this, SLOT(closeTab(int)));
1328 connect(m_tabBar, SIGNAL(contextMenu(int, const QPoint&)),
1329 this, SLOT(openTabContextMenu(int, const QPoint&)));
1330 connect(m_tabBar, SIGNAL(newTabRequest()),
1331 this, SLOT(openNewTab()));
1332 connect(m_tabBar, SIGNAL(testCanDecode(const QDragMoveEvent*, bool&)),
1333 this, SLOT(slotTestCanDecode(const QDragMoveEvent*, bool&)));
1334 connect(m_tabBar, SIGNAL(mouseMiddleClick(int)),
1335 this, SLOT(closeTab(int)));
1336 connect(m_tabBar, SIGNAL(tabMoved(int, int)),
1337 this, SLOT(slotTabMoved(int, int)));
1338 connect(m_tabBar, SIGNAL(receivedDropEvent(int, QDropEvent*)),
1339 this, SLOT(tabDropEvent(int, QDropEvent*)));
1340
1341 m_tabBar->blockSignals(true); // signals get unblocked after at least 2 tabs are open
1342
1343 QWidget* centralWidget = new QWidget(this);
1344 m_centralWidgetLayout = new QVBoxLayout(centralWidget);
1345 m_centralWidgetLayout->setSpacing(0);
1346 m_centralWidgetLayout->setMargin(0);
1347 m_centralWidgetLayout->addWidget(m_tabBar);
1348 m_centralWidgetLayout->addWidget(m_viewTab[m_tabIndex].splitter, 1);
1349
1350 setCentralWidget(centralWidget);
1351 setupDockWidgets();
1352 emit urlChanged(homeUrl);
1353
1354 setupGUI(Keys | Save | Create | ToolBar);
1355 stateChanged("new_file");
1356
1357 QClipboard* clipboard = QApplication::clipboard();
1358 connect(clipboard, SIGNAL(dataChanged()),
1359 this, SLOT(updatePasteAction()));
1360
1361 if (generalSettings->splitView()) {
1362 toggleSplitView();
1363 }
1364 updateEditActions();
1365 updateViewActions();
1366 updateGoActions();
1367
1368 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
1369 showFilterBarAction->setChecked(generalSettings->filterBar());
1370
1371 if (firstRun) {
1372 // assure a proper default size if Dolphin runs the first time
1373 resize(750, 500);
1374 }
1375
1376 m_showMenuBar->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
1377 }
1378
1379 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContainer)
1380 {
1381 Q_ASSERT(viewContainer);
1382 Q_ASSERT((viewContainer == m_viewTab[m_tabIndex].primaryView) ||
1383 (viewContainer == m_viewTab[m_tabIndex].secondaryView));
1384 if (m_activeViewContainer == viewContainer) {
1385 return;
1386 }
1387
1388 m_activeViewContainer->setActive(false);
1389 m_activeViewContainer = viewContainer;
1390
1391 // Activating the view container might trigger a recursive setActiveViewContainer() call
1392 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1393 // disconnect the activated() signal in this case:
1394 disconnect(m_activeViewContainer->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1395 m_activeViewContainer->setActive(true);
1396 connect(m_activeViewContainer->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1397
1398 m_actionHandler->setCurrentView(viewContainer->view());
1399
1400 updateHistory();
1401 updateEditActions();
1402 updateViewActions();
1403 updateGoActions();
1404
1405 const KUrl url = m_activeViewContainer->url();
1406 setUrlAsCaption(url);
1407 if (m_viewTab.count() > 1) {
1408 m_tabBar->setTabText(m_tabIndex, tabName(url));
1409 m_tabBar->setTabIcon(m_tabIndex, KIcon(KMimeType::iconNameForUrl(url)));
1410 }
1411
1412 emit urlChanged(url);
1413 }
1414
1415 void DolphinMainWindow::setupActions()
1416 {
1417 // setup 'File' menu
1418 m_newFileMenu = new DolphinNewFileMenu(this);
1419 KMenu* menu = m_newFileMenu->menu();
1420 menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1421 menu->setIcon(KIcon("document-new"));
1422 connect(menu, SIGNAL(aboutToShow()),
1423 this, SLOT(updateNewMenu()));
1424
1425 KAction* newWindow = actionCollection()->addAction("new_window");
1426 newWindow->setIcon(KIcon("window-new"));
1427 newWindow->setText(i18nc("@action:inmenu File", "New &Window"));
1428 newWindow->setShortcut(Qt::CTRL | Qt::Key_N);
1429 connect(newWindow, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1430
1431 KAction* newTab = actionCollection()->addAction("new_tab");
1432 newTab->setIcon(KIcon("tab-new"));
1433 newTab->setText(i18nc("@action:inmenu File", "New Tab"));
1434 newTab->setShortcut(KShortcut(Qt::CTRL | Qt::Key_T, Qt::CTRL | Qt::SHIFT | Qt::Key_N));
1435 connect(newTab, SIGNAL(triggered()), this, SLOT(openNewTab()));
1436
1437 KAction* closeTab = actionCollection()->addAction("close_tab");
1438 closeTab->setIcon(KIcon("tab-close"));
1439 closeTab->setText(i18nc("@action:inmenu File", "Close Tab"));
1440 closeTab->setShortcut(Qt::CTRL | Qt::Key_W);
1441 closeTab->setEnabled(false);
1442 connect(closeTab, SIGNAL(triggered()), this, SLOT(closeTab()));
1443
1444 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1445
1446 // setup 'Edit' menu
1447 KStandardAction::undo(this,
1448 SLOT(undo()),
1449 actionCollection());
1450
1451 // need to remove shift+del from cut action, else the shortcut for deletejob
1452 // doesn't work
1453 KAction* cut = KStandardAction::cut(this, SLOT(cut()), actionCollection());
1454 KShortcut cutShortcut = cut->shortcut();
1455 cutShortcut.remove(Qt::SHIFT | Qt::Key_Delete, KShortcut::KeepEmpty);
1456 cut->setShortcut(cutShortcut);
1457 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1458 KAction* paste = KStandardAction::paste(this, SLOT(paste()), actionCollection());
1459 // The text of the paste-action is modified dynamically by Dolphin
1460 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1461 // due to the long text, the text "Paste" is used:
1462 paste->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1463
1464 KStandardAction::find(this, SLOT(find()), actionCollection());
1465
1466 KAction* selectAll = actionCollection()->addAction("select_all");
1467 selectAll->setText(i18nc("@action:inmenu Edit", "Select All"));
1468 selectAll->setShortcut(Qt::CTRL | Qt::Key_A);
1469 connect(selectAll, SIGNAL(triggered()), this, SLOT(selectAll()));
1470
1471 KAction* invertSelection = actionCollection()->addAction("invert_selection");
1472 invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1473 invertSelection->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_A);
1474 connect(invertSelection, SIGNAL(triggered()), this, SLOT(invertSelection()));
1475
1476 // setup 'View' menu
1477 // (note that most of it is set up in DolphinViewActionHandler)
1478
1479 KAction* split = actionCollection()->addAction("split_view");
1480 split->setShortcut(Qt::Key_F3);
1481 updateSplitAction();
1482 connect(split, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1483
1484 KAction* reload = actionCollection()->addAction("reload");
1485 reload->setText(i18nc("@action:inmenu View", "Reload"));
1486 reload->setShortcut(Qt::Key_F5);
1487 reload->setIcon(KIcon("view-refresh"));
1488 connect(reload, SIGNAL(triggered()), this, SLOT(reloadView()));
1489
1490 KAction* stop = actionCollection()->addAction("stop");
1491 stop->setText(i18nc("@action:inmenu View", "Stop"));
1492 stop->setToolTip(i18nc("@info", "Stop loading"));
1493 stop->setIcon(KIcon("process-stop"));
1494 connect(stop, SIGNAL(triggered()), this, SLOT(stopLoading()));
1495
1496 KToggleAction* showFullLocation = actionCollection()->add<KToggleAction>("editable_location");
1497 showFullLocation->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1498 showFullLocation->setShortcut(Qt::CTRL | Qt::Key_L);
1499 connect(showFullLocation, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1500
1501 KAction* replaceLocation = actionCollection()->addAction("replace_location");
1502 replaceLocation->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1503 replaceLocation->setShortcut(Qt::Key_F6);
1504 connect(replaceLocation, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1505
1506 // setup 'Go' menu
1507 KAction* backAction = KStandardAction::back(this, SLOT(goBack()), actionCollection());
1508 connect(backAction, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)), this, SLOT(goBack(Qt::MouseButtons)));
1509 KShortcut backShortcut = backAction->shortcut();
1510 backShortcut.setAlternate(Qt::Key_Backspace);
1511 backAction->setShortcut(backShortcut);
1512
1513 m_recentTabsMenu = new KActionMenu(i18n("Recently Closed Tabs"), this);
1514 m_recentTabsMenu->setIcon(KIcon("edit-undo"));
1515 actionCollection()->addAction("closed_tabs", m_recentTabsMenu);
1516 connect(m_recentTabsMenu->menu(), SIGNAL(triggered(QAction *)),
1517 this, SLOT(restoreClosedTab(QAction *)));
1518
1519 QAction* action = new QAction("Empty Recently Closed Tabs", m_recentTabsMenu);
1520 action->setIcon(KIcon("edit-clear-list"));
1521 action->setData(QVariant::fromValue(true));
1522 m_recentTabsMenu->addAction(action);
1523 m_recentTabsMenu->addSeparator();
1524 m_recentTabsMenu->setEnabled(false);
1525
1526 KAction* forwardAction = KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1527 connect(forwardAction, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)), this, SLOT(goForward(Qt::MouseButtons)));
1528
1529 KAction* upAction = KStandardAction::up(this, SLOT(goUp()), actionCollection());
1530 connect(upAction, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)), this, SLOT(goUp(Qt::MouseButtons)));
1531
1532 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1533
1534 // setup 'Tools' menu
1535 KAction* showFilterBar = actionCollection()->addAction("show_filter_bar");
1536 showFilterBar->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1537 showFilterBar->setIcon(KIcon("view-filter"));
1538 showFilterBar->setShortcut(Qt::CTRL | Qt::Key_I);
1539 connect(showFilterBar, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1540
1541 KAction* compareFiles = actionCollection()->addAction("compare_files");
1542 compareFiles->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1543 compareFiles->setIcon(KIcon("kompare"));
1544 compareFiles->setEnabled(false);
1545 connect(compareFiles, SIGNAL(triggered()), this, SLOT(compareFiles()));
1546
1547 KAction* openTerminal = actionCollection()->addAction("open_terminal");
1548 openTerminal->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1549 openTerminal->setIcon(KIcon("utilities-terminal"));
1550 openTerminal->setShortcut(Qt::SHIFT | Qt::Key_F4);
1551 connect(openTerminal, SIGNAL(triggered()), this, SLOT(openTerminal()));
1552
1553 // setup 'Settings' menu
1554 m_showMenuBar = KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1555 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1556
1557 // not in menu actions
1558 QList<QKeySequence> nextTabKeys;
1559 nextTabKeys.append(KStandardShortcut::tabNext().primary());
1560 nextTabKeys.append(QKeySequence(Qt::CTRL | Qt::Key_Tab));
1561
1562 QList<QKeySequence> prevTabKeys;
1563 prevTabKeys.append(KStandardShortcut::tabPrev().primary());
1564 prevTabKeys.append(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_Tab));
1565
1566 KAction* activateNextTab = actionCollection()->addAction("activate_next_tab");
1567 activateNextTab->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1568 connect(activateNextTab, SIGNAL(triggered()), SLOT(activateNextTab()));
1569 activateNextTab->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys : nextTabKeys);
1570
1571 KAction* activatePrevTab = actionCollection()->addAction("activate_prev_tab");
1572 activatePrevTab->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1573 connect(activatePrevTab, SIGNAL(triggered()), SLOT(activatePrevTab()));
1574 activatePrevTab->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys : prevTabKeys);
1575
1576 // for context menu
1577 KAction* openInNewTab = actionCollection()->addAction("open_in_new_tab");
1578 openInNewTab->setText(i18nc("@action:inmenu", "Open in New Tab"));
1579 openInNewTab->setIcon(KIcon("tab-new"));
1580 connect(openInNewTab, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1581
1582 KAction* openInNewWindow = actionCollection()->addAction("open_in_new_window");
1583 openInNewWindow->setText(i18nc("@action:inmenu", "Open in New Window"));
1584 openInNewWindow->setIcon(KIcon("window-new"));
1585 connect(openInNewWindow, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1586 }
1587
1588 void DolphinMainWindow::setupDockWidgets()
1589 {
1590 const bool lock = DolphinSettings::instance().generalSettings()->lockPanels();
1591
1592 KDualAction* lockLayoutAction = actionCollection()->add<KDualAction>("lock_panels");
1593 lockLayoutAction->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1594 lockLayoutAction->setActiveIcon(KIcon("object-unlocked"));
1595 lockLayoutAction->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1596 lockLayoutAction->setInactiveIcon(KIcon("object-locked"));
1597 lockLayoutAction->setActive(lock);
1598 connect(lockLayoutAction, SIGNAL(triggered()), this, SLOT(togglePanelLockState()));
1599
1600 // Setup "Information"
1601 DolphinDockWidget* infoDock = new DolphinDockWidget(i18nc("@title:window", "Information"));
1602 infoDock->setLocked(lock);
1603 infoDock->setObjectName("infoDock");
1604 infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1605 Panel* infoPanel = new InformationPanel(infoDock);
1606 infoPanel->setCustomContextMenuActions(QList<QAction*>() << lockLayoutAction);
1607 connect(infoPanel, SIGNAL(urlActivated(KUrl)), this, SLOT(handleUrl(KUrl)));
1608 infoDock->setWidget(infoPanel);
1609
1610 QAction* infoAction = infoDock->toggleViewAction();
1611 infoAction->setIcon(KIcon("dialog-information"));
1612 infoAction->setShortcut(Qt::Key_F11);
1613 addActionCloneToCollection(infoAction, "show_information_panel");
1614
1615 addDockWidget(Qt::RightDockWidgetArea, infoDock);
1616 connect(this, SIGNAL(urlChanged(KUrl)),
1617 infoPanel, SLOT(setUrl(KUrl)));
1618 connect(this, SIGNAL(selectionChanged(KFileItemList)),
1619 infoPanel, SLOT(setSelection(KFileItemList)));
1620 connect(this, SIGNAL(requestItemInfo(KFileItem)),
1621 infoPanel, SLOT(requestDelayedItemInfo(KFileItem)));
1622
1623 // Setup "Folders"
1624 DolphinDockWidget* foldersDock = new DolphinDockWidget(i18nc("@title:window", "Folders"));
1625 foldersDock->setLocked(lock);
1626 foldersDock->setObjectName("foldersDock");
1627 foldersDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1628 FoldersPanel* foldersPanel = new FoldersPanel(foldersDock);
1629 foldersPanel->setCustomContextMenuActions(QList<QAction*>() << lockLayoutAction);
1630 foldersDock->setWidget(foldersPanel);
1631
1632 QAction* foldersAction = foldersDock->toggleViewAction();
1633 foldersAction->setShortcut(Qt::Key_F7);
1634 foldersAction->setIcon(KIcon("folder"));
1635 addActionCloneToCollection(foldersAction, "show_folders_panel");
1636
1637 addDockWidget(Qt::LeftDockWidgetArea, foldersDock);
1638 connect(this, SIGNAL(urlChanged(KUrl)),
1639 foldersPanel, SLOT(setUrl(KUrl)));
1640 connect(foldersPanel, SIGNAL(changeUrl(KUrl, Qt::MouseButtons)),
1641 this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
1642
1643 // Setup "Terminal"
1644 #ifndef Q_OS_WIN
1645 DolphinDockWidget* terminalDock = new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1646 terminalDock->setLocked(lock);
1647 terminalDock->setObjectName("terminalDock");
1648 terminalDock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
1649 Panel* terminalPanel = new TerminalPanel(terminalDock);
1650 terminalPanel->setCustomContextMenuActions(QList<QAction*>() << lockLayoutAction);
1651 terminalDock->setWidget(terminalPanel);
1652
1653 connect(terminalPanel, SIGNAL(hideTerminalPanel()), terminalDock, SLOT(hide()));
1654
1655 QAction* terminalAction = terminalDock->toggleViewAction();
1656 terminalAction->setShortcut(Qt::Key_F4);
1657 terminalAction->setIcon(KIcon("utilities-terminal"));
1658 addActionCloneToCollection(terminalAction, "show_terminal_panel");
1659
1660 addDockWidget(Qt::BottomDockWidgetArea, terminalDock);
1661 connect(this, SIGNAL(urlChanged(KUrl)),
1662 terminalPanel, SLOT(setUrl(KUrl)));
1663 #endif
1664
1665 // Setup "Search"
1666 #ifdef HAVE_NEPOMUK
1667 DolphinDockWidget* searchDock = new DolphinDockWidget(i18nc("@title:window", "Search"));
1668 searchDock->setLocked(lock);
1669 searchDock->setObjectName("searchDock");
1670 searchDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1671 Panel* searchPanel = new SearchPanel(searchDock);
1672 searchPanel->setCustomContextMenuActions(QList<QAction*>() << lockLayoutAction);
1673 connect(searchPanel, SIGNAL(urlActivated(KUrl)), this, SLOT(handleUrl(KUrl)));
1674 searchDock->setWidget(searchPanel);
1675
1676 QAction* searchAction = searchDock->toggleViewAction();
1677 searchAction->setShortcut(Qt::Key_F12);
1678 searchAction->setIcon(KIcon("system-search"));
1679 addActionCloneToCollection(searchAction, "show_search_panel");
1680 addDockWidget(Qt::RightDockWidgetArea, searchDock);
1681 connect(this, SIGNAL(urlChanged(KUrl)),
1682 searchPanel, SLOT(setUrl(KUrl)));
1683 #endif
1684
1685 const bool firstRun = DolphinSettings::instance().generalSettings()->firstRun();
1686 if (firstRun) {
1687 infoDock->hide();
1688 foldersDock->hide();
1689 #ifndef Q_OS_WIN
1690 terminalDock->hide();
1691 #endif
1692 #ifdef HAVE_NEPOMUK
1693 searchDock->hide();
1694 #endif
1695 }
1696
1697 // Setup "Places"
1698 DolphinDockWidget* placesDock = new DolphinDockWidget(i18nc("@title:window", "Places"));
1699 placesDock->setLocked(lock);
1700 placesDock->setObjectName("placesDock");
1701 placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1702
1703 PlacesPanel* placesPanel = new PlacesPanel(placesDock);
1704 QAction* separator = new QAction(placesPanel);
1705 separator->setSeparator(true);
1706 QList<QAction*> placesActions;
1707 placesActions.append(separator);
1708 placesActions.append(lockLayoutAction);
1709 placesPanel->addActions(placesActions);
1710 placesPanel->setModel(DolphinSettings::instance().placesModel());
1711 placesPanel->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1712 placesDock->setWidget(placesPanel);
1713
1714 QAction* placesAction = placesDock->toggleViewAction();
1715 placesAction->setShortcut(Qt::Key_F9);
1716 placesAction->setIcon(KIcon("bookmarks"));
1717 addActionCloneToCollection(placesAction, "show_places_panel");
1718
1719 addDockWidget(Qt::LeftDockWidgetArea, placesDock);
1720 connect(placesPanel, SIGNAL(urlChanged(KUrl, Qt::MouseButtons)),
1721 this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
1722 connect(this, SIGNAL(urlChanged(KUrl)),
1723 placesPanel, SLOT(setUrl(KUrl)));
1724
1725 // Add actions into the "Panels" menu
1726 KActionMenu* panelsMenu = new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1727 actionCollection()->addAction("panels", panelsMenu);
1728 panelsMenu->setDelayed(false);
1729 panelsMenu->addAction(placesAction);
1730 panelsMenu->addAction(infoAction);
1731 panelsMenu->addAction(foldersAction);
1732 #ifndef Q_OS_WIN
1733 panelsMenu->addAction(terminalAction);
1734 #endif
1735 #ifdef HAVE_NEPOMUK
1736 panelsMenu->addAction(searchAction);
1737 #endif
1738 panelsMenu->addSeparator();
1739 panelsMenu->addAction(lockLayoutAction);
1740 }
1741
1742 void DolphinMainWindow::updateEditActions()
1743 {
1744 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
1745 if (list.isEmpty()) {
1746 stateChanged("has_no_selection");
1747 } else {
1748 stateChanged("has_selection");
1749
1750 KActionCollection* col = actionCollection();
1751 QAction* renameAction = col->action("rename");
1752 QAction* moveToTrashAction = col->action("move_to_trash");
1753 QAction* deleteAction = col->action("delete");
1754 QAction* cutAction = col->action(KStandardAction::name(KStandardAction::Cut));
1755 QAction* deleteWithTrashShortcut = col->action("delete_shortcut"); // see DolphinViewActionHandler
1756
1757 KFileItemListProperties capabilities(list);
1758 const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving();
1759
1760 renameAction->setEnabled(capabilities.supportsMoving());
1761 moveToTrashAction->setEnabled(enableMoveToTrash);
1762 deleteAction->setEnabled(capabilities.supportsDeleting());
1763 deleteWithTrashShortcut->setEnabled(capabilities.supportsDeleting() && !enableMoveToTrash);
1764 cutAction->setEnabled(capabilities.supportsMoving());
1765 }
1766 updatePasteAction();
1767 }
1768
1769 void DolphinMainWindow::updateViewActions()
1770 {
1771 m_actionHandler->updateViewActions();
1772
1773 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
1774 showFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible());
1775
1776 updateSplitAction();
1777
1778 QAction* editableLocactionAction = actionCollection()->action("editable_location");
1779 const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
1780 editableLocactionAction->setChecked(urlNavigator->isUrlEditable());
1781 }
1782
1783 void DolphinMainWindow::updateGoActions()
1784 {
1785 QAction* goUpAction = actionCollection()->action(KStandardAction::name(KStandardAction::Up));
1786 const KUrl currentUrl = m_activeViewContainer->url();
1787 goUpAction->setEnabled(currentUrl.upUrl() != currentUrl);
1788 }
1789
1790 void DolphinMainWindow::rememberClosedTab(int index)
1791 {
1792 KMenu* tabsMenu = m_recentTabsMenu->menu();
1793
1794 const QString primaryPath = m_viewTab[index].primaryView->url().path();
1795 const QString iconName = KMimeType::iconNameForUrl(primaryPath);
1796
1797 QAction* action = new QAction(squeezedText(primaryPath), tabsMenu);
1798
1799 ClosedTab closedTab;
1800 closedTab.primaryUrl = m_viewTab[index].primaryView->url();
1801
1802 if (m_viewTab[index].secondaryView) {
1803 closedTab.secondaryUrl = m_viewTab[index].secondaryView->url();
1804 closedTab.isSplit = true;
1805 } else {
1806 closedTab.isSplit = false;
1807 }
1808
1809 action->setData(QVariant::fromValue(closedTab));
1810 action->setIcon(KIcon(iconName));
1811
1812 // add the closed tab menu entry after the separator and
1813 // "Empty Recently Closed Tabs" entry
1814 if (tabsMenu->actions().size() == 2) {
1815 tabsMenu->addAction(action);
1816 } else {
1817 tabsMenu->insertAction(tabsMenu->actions().at(2), action);
1818 }
1819
1820 // assure that only up to 8 closed tabs are shown in the menu
1821 if (tabsMenu->actions().size() > 8) {
1822 tabsMenu->removeAction(tabsMenu->actions().last());
1823 }
1824 actionCollection()->action("closed_tabs")->setEnabled(true);
1825 KAcceleratorManager::manage(tabsMenu);
1826 }
1827
1828 void DolphinMainWindow::clearStatusBar()
1829 {
1830 m_activeViewContainer->statusBar()->clear();
1831 }
1832
1833 void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container)
1834 {
1835 connect(container, SIGNAL(showFilterBarChanged(bool)),
1836 this, SLOT(updateFilterBarAction(bool)));
1837 connect(container, SIGNAL(writeStateChanged(bool)),
1838 this, SLOT(slotWriteStateChanged(bool)));
1839 connect(container, SIGNAL(searchModeChanged(bool)),
1840 this, SLOT(slotSearchModeChanged(bool)));
1841
1842 DolphinView* view = container->view();
1843 connect(view, SIGNAL(selectionChanged(KFileItemList)),
1844 this, SLOT(slotSelectionChanged(KFileItemList)));
1845 connect(view, SIGNAL(requestItemInfo(KFileItem)),
1846 this, SLOT(slotRequestItemInfo(KFileItem)));
1847 connect(view, SIGNAL(activated()),
1848 this, SLOT(toggleActiveView()));
1849 connect(view, SIGNAL(tabRequested(const KUrl&)),
1850 this, SLOT(openNewTab(const KUrl&)));
1851 connect(view, SIGNAL(requestContextMenu(KFileItem, const KUrl&, const QList<QAction*>&)),
1852 this, SLOT(openContextMenu(KFileItem, const KUrl&, const QList<QAction*>&)));
1853 connect(view, SIGNAL(startedPathLoading(KUrl)),
1854 this, SLOT(enableStopAction()));
1855 connect(view, SIGNAL(finishedPathLoading(KUrl)),
1856 this, SLOT(disableStopAction()));
1857
1858 const KUrlNavigator* navigator = container->urlNavigator();
1859 connect(navigator, SIGNAL(urlChanged(const KUrl&)),
1860 this, SLOT(changeUrl(const KUrl&)));
1861 connect(navigator, SIGNAL(historyChanged()),
1862 this, SLOT(updateHistory()));
1863 connect(navigator, SIGNAL(editableStateChanged(bool)),
1864 this, SLOT(slotEditableStateChanged(bool)));
1865 connect(navigator, SIGNAL(tabRequested(const KUrl&)),
1866 this, SLOT(openNewTab(KUrl)));
1867 }
1868
1869 void DolphinMainWindow::updateSplitAction()
1870 {
1871 QAction* splitAction = actionCollection()->action("split_view");
1872 if (m_viewTab[m_tabIndex].secondaryView) {
1873 if (m_activeViewContainer == m_viewTab[m_tabIndex].secondaryView) {
1874 splitAction->setText(i18nc("@action:intoolbar Close right view", "Close"));
1875 splitAction->setToolTip(i18nc("@info", "Close right view"));
1876 splitAction->setIcon(KIcon("view-right-close"));
1877 } else {
1878 splitAction->setText(i18nc("@action:intoolbar Close left view", "Close"));
1879 splitAction->setToolTip(i18nc("@info", "Close left view"));
1880 splitAction->setIcon(KIcon("view-left-close"));
1881 }
1882 } else {
1883 splitAction->setText(i18nc("@action:intoolbar Split view", "Split"));
1884 splitAction->setToolTip(i18nc("@info", "Split view"));
1885 splitAction->setIcon(KIcon("view-right-new"));
1886 }
1887 }
1888
1889 QString DolphinMainWindow::tabName(const KUrl& url) const
1890 {
1891 QString name;
1892 if (url.equals(KUrl("file:///"))) {
1893 name = '/';
1894 } else {
1895 name = url.fileName();
1896 if (name.isEmpty()) {
1897 name = url.protocol();
1898 } else {
1899 // Make sure that a '&' inside the directory name is displayed correctly
1900 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1901 name.replace('&', "&&");
1902 }
1903 }
1904 return name;
1905 }
1906
1907 bool DolphinMainWindow::isKompareInstalled() const
1908 {
1909 static bool initialized = false;
1910 static bool installed = false;
1911 if (!initialized) {
1912 // TODO: maybe replace this approach later by using a menu
1913 // plugin like kdiff3plugin.cpp
1914 installed = !KGlobal::dirs()->findExe("kompare").isEmpty();
1915 initialized = true;
1916 }
1917 return installed;
1918 }
1919
1920 void DolphinMainWindow::createSecondaryView(int tabIndex)
1921 {
1922 QSplitter* splitter = m_viewTab[tabIndex].splitter;
1923 const int newWidth = (m_viewTab[tabIndex].primaryView->width() - splitter->handleWidth()) / 2;
1924
1925 const DolphinView* view = m_viewTab[tabIndex].primaryView->view();
1926 m_viewTab[tabIndex].secondaryView = new DolphinViewContainer(view->rootUrl(), 0);
1927 splitter->addWidget(m_viewTab[tabIndex].secondaryView);
1928 splitter->setSizes(QList<int>() << newWidth << newWidth);
1929 connectViewSignals(m_viewTab[tabIndex].secondaryView);
1930 m_viewTab[tabIndex].secondaryView->setActive(false);
1931 m_viewTab[tabIndex].secondaryView->show();
1932 }
1933
1934 QString DolphinMainWindow::tabProperty(const QString& property, int tabIndex) const
1935 {
1936 return "Tab " + QString::number(tabIndex) + ' ' + property;
1937 }
1938
1939 void DolphinMainWindow::setUrlAsCaption(const KUrl& url)
1940 {
1941 QString caption;
1942 if (!url.isLocalFile()) {
1943 caption.append(url.protocol() + " - ");
1944 if (url.hasHost()) {
1945 caption.append(url.host() + " - ");
1946 }
1947 }
1948
1949 const QString fileName = url.fileName().isEmpty() ? "/" : url.fileName();
1950 caption.append(fileName);
1951
1952 setCaption(caption);
1953 }
1954
1955 QString DolphinMainWindow::squeezedText(const QString& text) const
1956 {
1957 const QFontMetrics fm = fontMetrics();
1958 return fm.elidedText(text, Qt::ElideMiddle, fm.maxWidth() * 10);
1959 }
1960
1961 void DolphinMainWindow::addActionCloneToCollection(QAction* action, const QString& actionName)
1962 {
1963 KAction* actionClone = actionCollection()->addAction(actionName);
1964 actionClone->setText(action->text());
1965 actionClone->setIcon(action->icon());
1966 connect(actionClone, SIGNAL(triggered()), action, SLOT(trigger()));
1967 }
1968
1969 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1970 KIO::FileUndoManager::UiInterface()
1971 {
1972 }
1973
1974 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1975 {
1976 }
1977
1978 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job)
1979 {
1980 DolphinMainWindow* mainWin= qobject_cast<DolphinMainWindow *>(parentWidget());
1981 if (mainWin) {
1982 DolphinStatusBar* statusBar = mainWin->activeViewContainer()->statusBar();
1983 statusBar->setMessage(job->errorString(), DolphinStatusBar::Error);
1984 } else {
1985 KIO::FileUndoManager::UiInterface::jobError(job);
1986 }
1987 }
1988
1989 #include "dolphinmainwindow.moc"