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