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