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