]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
Jippie: file previews are generated again! Thanks to Fredrik for giving me a hint...
[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 <config-kmetadata.h>
23 #include "dolphinmainwindow.h"
24
25 #include <assert.h>
26
27 #include "dolphinapplication.h"
28 #include "dolphinnewmenu.h"
29 #include "dolphinsettings.h"
30 #include "dolphinsettingsdialog.h"
31 #include "dolphinstatusbar.h"
32 #include "dolphinapplication.h"
33 #include "urlnavigator.h"
34 #include "dolphinsettings.h"
35 #include "bookmarkssidebarpage.h"
36 #include "infosidebarpage.h"
37 #include "dolphin_generalsettings.h"
38 #include "viewpropertiesdialog.h"
39 #include "viewproperties.h"
40 #include "metadataloader.h"
41 #include "mainwindowadaptor.h"
42
43 #include <kaction.h>
44 #include <kactioncollection.h>
45 #include <kbookmarkmanager.h>
46 #include <kconfig.h>
47 #include <kdesktopfile.h>
48 #include <kdeversion.h>
49 #include <kfiledialog.h>
50 #include <kglobal.h>
51 #include <kicon.h>
52 #include <kiconloader.h>
53 #include <kio/netaccess.h>
54 #include <kio/deletejob.h>
55 #include <kio/renamedialog.h>
56 #include <kinputdialog.h>
57 #include <klocale.h>
58 #include <kmenu.h>
59 #include <kmessagebox.h>
60 #include <konqmimedata.h>
61 #include <kpropertiesdialog.h>
62 #include <kprotocolinfo.h>
63 #include <ktoggleaction.h>
64 #include <krun.h>
65 #include <kshell.h>
66 #include <kstandarddirs.h>
67 #include <kstatusbar.h>
68 #include <kstandardaction.h>
69 #include <kurl.h>
70
71 #include <QCloseEvent>
72 #include <QClipboard>
73 #include <QSplitter>
74 #include <QDockWidget>
75
76 DolphinMainWindow::DolphinMainWindow(int id) :
77 KMainWindow(0),
78 m_newMenu(0),
79 m_splitter(0),
80 m_activeView(0),
81 m_id(id)
82 {
83 setObjectName("Dolphin");
84 m_view[PrimaryIdx] = 0;
85 m_view[SecondaryIdx] = 0;
86
87 new MainWindowAdaptor(this);
88 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id), this);
89
90 KonqUndoManager::incRef();
91
92 KonqUndoManager* undoManager = KonqUndoManager::self();
93 undoManager->setUiInterface(new UndoUiInterface(this));
94
95 connect(undoManager, SIGNAL(undoAvailable(bool)),
96 this, SLOT(slotUndoAvailable(bool)));
97 connect(undoManager, SIGNAL(undoTextChanged(const QString&)),
98 this, SLOT(slotUndoTextChanged(const QString&)));
99 }
100
101 DolphinMainWindow::~DolphinMainWindow()
102 {
103 KonqUndoManager::decRef();
104 DolphinApplication::app()->removeMainWindow(this);
105 }
106
107 void DolphinMainWindow::setActiveView(DolphinView* view)
108 {
109 assert((view == m_view[PrimaryIdx]) || (view == m_view[SecondaryIdx]));
110 if (m_activeView == view) {
111 return;
112 }
113
114 m_activeView = view;
115
116 updateHistory();
117 updateEditActions();
118 updateViewActions();
119 updateGoActions();
120
121 setCaption(m_activeView->url().fileName());
122
123 emit activeViewChanged();
124 }
125
126 void DolphinMainWindow::dropUrls(const KUrl::List& urls,
127 const KUrl& destination)
128 {
129 Qt::DropAction action = Qt::CopyAction;
130
131 Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
132 const bool shiftPressed = modifier & Qt::ShiftModifier;
133 const bool controlPressed = modifier & Qt::ControlModifier;
134 if (shiftPressed && controlPressed) {
135 // shortcut for 'Link Here' is used
136 action = Qt::LinkAction;
137 }
138 else if (shiftPressed) {
139 // shortcut for 'Move Here' is used
140 action = Qt::MoveAction;
141 }
142 else if (controlPressed) {
143 // shortcut for 'Copy Here' is used
144 action = Qt::CopyAction;
145 }
146 else {
147 // open a context menu which offers the following actions:
148 // - Move Here
149 // - Copy Here
150 // - Link Here
151 // - Cancel
152
153 KMenu popup(this);
154
155 QString seq = QKeySequence(Qt::ShiftModifier).toString();
156 seq.chop(1); // chop superfluous '+'
157 QAction* moveAction = popup.addAction(KIcon("goto"),
158 i18n("&Move Here") + '\t' + seq);
159
160 seq = QKeySequence(Qt::ControlModifier).toString();
161 seq.chop(1);
162 QAction* copyAction = popup.addAction(KIcon("editcopy"),
163 i18n("&Copy Here") + '\t' + seq);
164
165 seq = QKeySequence(Qt::ControlModifier + Qt::ShiftModifier).toString();
166 seq.chop(1);
167 QAction* linkAction = popup.addAction(KIcon("www"),
168 i18n("&Link Here") + '\t' + seq);
169
170 popup.addSeparator();
171 popup.addAction(KIcon("stop"), i18n("Cancel"));
172
173 QAction* activatedAction = popup.exec(QCursor::pos());
174 if (activatedAction == moveAction) {
175 action = Qt::MoveAction;
176 }
177 else if (activatedAction == copyAction) {
178 action = Qt::CopyAction;
179 }
180 else if (activatedAction == linkAction) {
181 action = Qt::LinkAction;
182 }
183 else {
184 return;
185 }
186 }
187
188 switch (action) {
189 case Qt::MoveAction:
190 moveUrls(urls, destination);
191 break;
192
193 case Qt::CopyAction:
194 copyUrls(urls, destination);
195 break;
196
197 case Qt::LinkAction:
198 linkUrls(urls, destination);
199 break;
200
201 default:
202 break;
203 }
204 }
205
206 void DolphinMainWindow::refreshViews()
207 {
208 const bool split = DolphinSettings::instance().generalSettings()->splitView();
209 const bool isPrimaryViewActive = (m_activeView == m_view[PrimaryIdx]);
210 KUrl url;
211 for (int i = PrimaryIdx; i <= SecondaryIdx; ++i) {
212 if (m_view[i] != 0) {
213 url = m_view[i]->url();
214
215 // delete view instance...
216 m_view[i]->close();
217 m_view[i]->deleteLater();
218 m_view[i] = 0;
219 }
220
221 if (split || (i == PrimaryIdx)) {
222 // ... and recreate it
223 ViewProperties props(url);
224 m_view[i] = new DolphinView(this,
225 m_splitter,
226 url,
227 props.viewMode(),
228 props.showHiddenFiles());
229 connectViewSignals(i);
230 m_view[i]->show();
231 }
232 }
233
234 m_activeView = isPrimaryViewActive ? m_view[PrimaryIdx] : m_view[SecondaryIdx];
235 assert(m_activeView != 0);
236
237 updateViewActions();
238 emit activeViewChanged();
239 }
240
241 void DolphinMainWindow::changeUrl(const QString& url)
242 {
243 if (activeView() != 0) {
244 activeView()->setUrl(KUrl(url));
245 }
246 }
247
248 void DolphinMainWindow::slotViewModeChanged()
249 {
250 updateViewActions();
251 }
252
253 void DolphinMainWindow::slowShowPreviewChanged()
254 {
255 KToggleAction* showPreviewAction =
256 static_cast<KToggleAction*>(actionCollection()->action("show_preview"));
257 showPreviewAction->setChecked(m_activeView->showPreview());
258 }
259
260 void DolphinMainWindow::slotShowHiddenFilesChanged()
261 {
262 KToggleAction* showHiddenFilesAction =
263 static_cast<KToggleAction*>(actionCollection()->action("show_hidden_files"));
264 showHiddenFilesAction->setChecked(m_activeView->showHiddenFiles());
265 }
266
267 void DolphinMainWindow::slotSortingChanged(DolphinView::Sorting sorting)
268 {
269 QAction* action = 0;
270 switch (sorting) {
271 case DolphinView::SortByName:
272 action = actionCollection()->action("by_name");
273 break;
274 case DolphinView::SortBySize:
275 action = actionCollection()->action("by_size");
276 break;
277 case DolphinView::SortByDate:
278 action = actionCollection()->action("by_date");
279 break;
280 case DolphinView::SortByPermissions:
281 action = actionCollection()->action("by_permissions");
282 break;
283 case DolphinView::SortByOwner:
284 action = actionCollection()->action("by_owner");
285 break;
286 case DolphinView::SortByGroup:
287 action = actionCollection()->action("by_group");
288 break;
289 default:
290 break;
291 }
292
293 if (action != 0) {
294 KToggleAction* toggleAction = static_cast<KToggleAction*>(action);
295 toggleAction->setChecked(true);
296 }
297 }
298
299 void DolphinMainWindow::slotSortOrderChanged(Qt::SortOrder order)
300 {
301 KToggleAction* descending = static_cast<KToggleAction*>(actionCollection()->action("descending"));
302 const bool sortDescending = (order == Qt::Descending);
303 descending->setChecked(sortDescending);
304 }
305
306 void DolphinMainWindow::slotSelectionChanged()
307 {
308 updateEditActions();
309
310 assert(m_view[PrimaryIdx] != 0);
311 int selectedUrlsCount = m_view[PrimaryIdx]->selectedUrls().count();
312 if (m_view[SecondaryIdx] != 0) {
313 selectedUrlsCount += m_view[SecondaryIdx]->selectedUrls().count();
314 }
315
316 QAction* compareFilesAction = actionCollection()->action("compare_files");
317 compareFilesAction->setEnabled(selectedUrlsCount == 2);
318
319 m_activeView->updateStatusBar();
320
321 emit selectionChanged();
322 }
323
324 void DolphinMainWindow::slotHistoryChanged()
325 {
326 updateHistory();
327 }
328
329 void DolphinMainWindow::slotUrlChanged(const KUrl& url)
330 {
331 updateEditActions();
332 updateGoActions();
333 setCaption(url.fileName());
334 }
335
336 void DolphinMainWindow::updateFilterBarAction(bool show)
337 {
338 KToggleAction* showFilterBarAction =
339 static_cast<KToggleAction*>(actionCollection()->action("show_filter_bar"));
340 showFilterBarAction->setChecked(show);
341 }
342
343 void DolphinMainWindow::openNewMainWindow()
344 {
345 DolphinApplication::app()->createMainWindow()->show();
346 }
347
348 void DolphinMainWindow::closeEvent(QCloseEvent* event)
349 {
350 DolphinSettings& settings = DolphinSettings::instance();
351 GeneralSettings* generalSettings = settings.generalSettings();
352 generalSettings->setFirstRun(false);
353
354 settings.save();
355
356 // TODO: I assume there will be a generic way in KDE 4 to store the docks
357 // of the main window. In the meantime they are stored manually:
358 QString filename = KStandardDirs::locateLocal("data", KGlobal::mainComponent().componentName());
359 filename.append("/panels_layout");
360 QFile file(filename);
361 if (file.open(QIODevice::WriteOnly)) {
362 QByteArray data = saveState();
363 file.write(data);
364 file.close();
365 }
366
367 KMainWindow::closeEvent(event);
368 }
369
370 void DolphinMainWindow::saveProperties(KConfig* config)
371 {
372 KConfigGroup primaryView = config->group("Primary view");
373 primaryView.writeEntry("Url", m_view[PrimaryIdx]->url().url());
374 primaryView.writeEntry("Editable Url", m_view[PrimaryIdx]->isUrlEditable());
375 if (m_view[SecondaryIdx] != 0) {
376 KConfigGroup secondaryView = config->group("Secondary view");
377 secondaryView.writeEntry("Url", m_view[SecondaryIdx]->url().url());
378 secondaryView.writeEntry("Editable Url", m_view[SecondaryIdx]->isUrlEditable());
379 }
380 }
381
382 void DolphinMainWindow::readProperties(KConfig* config)
383 {
384 const KConfigGroup primaryView = config->group("Primary view");
385 m_view[PrimaryIdx]->setUrl(primaryView.readEntry("Url"));
386 m_view[PrimaryIdx]->setUrlEditable(primaryView.readEntry("Editable Url", false));
387 if (config->hasGroup("Secondary view")) {
388 const KConfigGroup secondaryView = config->group("Secondary view");
389 if (m_view[SecondaryIdx] == 0) {
390 toggleSplitView();
391 }
392 m_view[SecondaryIdx]->setUrl(secondaryView.readEntry("Url"));
393 m_view[SecondaryIdx]->setUrlEditable(secondaryView.readEntry("Editable Url", false));
394 }
395 else if (m_view[SecondaryIdx] != 0) {
396 toggleSplitView();
397 }
398 }
399
400 void DolphinMainWindow::updateNewMenu()
401 {
402 m_newMenu->slotCheckUpToDate();
403 m_newMenu->setPopupFiles(activeView()->url());
404 }
405
406 void DolphinMainWindow::rename()
407 {
408 clearStatusBar();
409 m_activeView->renameSelectedItems();
410 }
411
412 void DolphinMainWindow::moveToTrash()
413 {
414 clearStatusBar();
415 const KUrl::List selectedUrls = m_activeView->selectedUrls();
416 KonqOperations::del(this, KonqOperations::TRASH, selectedUrls);
417 m_undoOperations.append(KonqOperations::TRASH);
418 }
419
420 void DolphinMainWindow::deleteItems()
421 {
422 clearStatusBar();
423
424 KUrl::List list = m_activeView->selectedUrls();
425 const uint itemCount = list.count();
426 assert(itemCount >= 1);
427
428 QString text;
429 if (itemCount > 1) {
430 text = i18n("Do you really want to delete the %1 selected items?",itemCount);
431 }
432 else {
433 const KUrl& url = list.first();
434 text = i18n("Do you really want to delete '%1'?",url.fileName());
435 }
436
437 const bool del = KMessageBox::warningContinueCancel(this,
438 text,
439 QString(),
440 KGuiItem(i18n("Delete"), KIcon("editdelete"))
441 ) == KMessageBox::Continue;
442 if (del) {
443 KIO::Job* job = KIO::del(list);
444 connect(job, SIGNAL(result(KJob*)),
445 this, SLOT(slotHandleJobError(KJob*)));
446 connect(job, SIGNAL(result(KJob*)),
447 this, SLOT(slotDeleteFileFinished(KJob*)));
448 }
449 }
450
451 void DolphinMainWindow::properties()
452 {
453 const KFileItemList list = m_activeView->selectedItems();
454 new KPropertiesDialog(list, this);
455 }
456
457 void DolphinMainWindow::quit()
458 {
459 close();
460 }
461
462 void DolphinMainWindow::slotHandleJobError(KJob* job)
463 {
464 if (job->error() != 0) {
465 DolphinStatusBar* statusBar = m_activeView->statusBar();
466 statusBar->setMessage(job->errorString(),
467 DolphinStatusBar::Error);
468 }
469 }
470
471 void DolphinMainWindow::slotDeleteFileFinished(KJob* job)
472 {
473 if (job->error() == 0) {
474 DolphinStatusBar* statusBar = m_activeView->statusBar();
475 statusBar->setMessage(i18n("Delete operation completed."),
476 DolphinStatusBar::OperationCompleted);
477 }
478 }
479
480 void DolphinMainWindow::slotUndoAvailable(bool available)
481 {
482 QAction* undoAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::Undo));
483 if (undoAction != 0) {
484 undoAction->setEnabled(available);
485 }
486
487 if (available && (m_undoOperations.count() > 0)) {
488 const KonqOperations::Operation op = m_undoOperations.takeFirst();
489 DolphinStatusBar* statusBar = m_activeView->statusBar();
490 switch (op) {
491 case KonqOperations::COPY:
492 statusBar->setMessage(i18n("Copy operation completed."),
493 DolphinStatusBar::OperationCompleted);
494 break;
495 case KonqOperations::MOVE:
496 statusBar->setMessage(i18n("Move operation completed."),
497 DolphinStatusBar::OperationCompleted);
498 break;
499 case KonqOperations::LINK:
500 statusBar->setMessage(i18n("Link operation completed."),
501 DolphinStatusBar::OperationCompleted);
502 break;
503 case KonqOperations::TRASH:
504 statusBar->setMessage(i18n("Move to trash operation completed."),
505 DolphinStatusBar::OperationCompleted);
506 break;
507 default:
508 break;
509 }
510
511 }
512 }
513
514 void DolphinMainWindow::slotUndoTextChanged(const QString& text)
515 {
516 QAction* undoAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::Undo));
517 if (undoAction != 0) {
518 undoAction->setText(text);
519 }
520 }
521
522 void DolphinMainWindow::undo()
523 {
524 clearStatusBar();
525 KonqUndoManager::self()->undo();
526 }
527
528 void DolphinMainWindow::cut()
529 {
530 QMimeData* mimeData = new QMimeData();
531 const KUrl::List kdeUrls = m_activeView->selectedUrls();
532 const KUrl::List mostLocalUrls;
533 KonqMimeData::populateMimeData(mimeData, kdeUrls, mostLocalUrls, true);
534 QApplication::clipboard()->setMimeData(mimeData);
535 }
536
537 void DolphinMainWindow::copy()
538 {
539 QMimeData* mimeData = new QMimeData();
540 const KUrl::List kdeUrls = m_activeView->selectedUrls();
541 const KUrl::List mostLocalUrls;
542 KonqMimeData::populateMimeData(mimeData, kdeUrls, mostLocalUrls, false);
543
544 QApplication::clipboard()->setMimeData(mimeData);
545 }
546
547 void DolphinMainWindow::paste()
548 {
549 QClipboard* clipboard = QApplication::clipboard();
550 const QMimeData* mimeData = clipboard->mimeData();
551
552 clearStatusBar();
553
554 const KUrl::List sourceUrls = KUrl::List::fromMimeData(mimeData);
555
556 // per default the pasting is done into the current Url of the view
557 KUrl destUrl(m_activeView->url());
558
559 // check whether the pasting should be done into a selected directory
560 KUrl::List selectedUrls = m_activeView->selectedUrls();
561 if (selectedUrls.count() == 1) {
562 const KFileItem fileItem(S_IFDIR,
563 KFileItem::Unknown,
564 selectedUrls.first(),
565 true);
566 if (fileItem.isDir()) {
567 // only one item is selected which is a directory, hence paste
568 // into this directory
569 destUrl = selectedUrls.first();
570 }
571 }
572
573 if (KonqMimeData::decodeIsCutSelection(mimeData)) {
574 moveUrls(sourceUrls, destUrl);
575 clipboard->clear();
576 }
577 else {
578 copyUrls(sourceUrls, destUrl);
579 }
580 }
581
582 void DolphinMainWindow::updatePasteAction()
583 {
584 QAction* pasteAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::Paste));
585 if (pasteAction == 0) {
586 return;
587 }
588
589 QString text(i18n("Paste"));
590 QClipboard* clipboard = QApplication::clipboard();
591 const QMimeData* mimeData = clipboard->mimeData();
592
593 KUrl::List urls = KUrl::List::fromMimeData(mimeData);
594 if (!urls.isEmpty()) {
595 pasteAction->setEnabled(true);
596
597 const int count = urls.count();
598 if (count == 1) {
599 pasteAction->setText(i18n("Paste 1 File"));
600 }
601 else {
602 pasteAction->setText(i18n("Paste %1 Files", count));
603 }
604 }
605 else {
606 pasteAction->setEnabled(false);
607 pasteAction->setText(i18n("Paste"));
608 }
609
610 if (pasteAction->isEnabled()) {
611 KUrl::List urls = m_activeView->selectedUrls();
612 const uint count = urls.count();
613 if (count > 1) {
614 // pasting should not be allowed when more than one file
615 // is selected
616 pasteAction->setEnabled(false);
617 }
618 else if (count == 1) {
619 // Only one file is selected. Pasting is only allowed if this
620 // file is a directory.
621 // TODO: this doesn't work with remote protocols; instead we need a
622 // m_activeView->selectedFileItems() to get the real KFileItems
623 const KFileItem fileItem(S_IFDIR,
624 KFileItem::Unknown,
625 urls.first(),
626 true);
627 pasteAction->setEnabled(fileItem.isDir());
628 }
629 }
630 }
631
632 void DolphinMainWindow::selectAll()
633 {
634 clearStatusBar();
635 m_activeView->selectAll();
636 }
637
638 void DolphinMainWindow::invertSelection()
639 {
640 clearStatusBar();
641 m_activeView->invertSelection();
642 }
643 void DolphinMainWindow::setIconsView()
644 {
645 m_activeView->setMode(DolphinView::IconsView);
646 }
647
648 void DolphinMainWindow::setDetailsView()
649 {
650 m_activeView->setMode(DolphinView::DetailsView);
651 }
652
653 void DolphinMainWindow::sortByName()
654 {
655 m_activeView->setSorting(DolphinView::SortByName);
656 }
657
658 void DolphinMainWindow::sortBySize()
659 {
660 m_activeView->setSorting(DolphinView::SortBySize);
661 }
662
663 void DolphinMainWindow::sortByDate()
664 {
665 m_activeView->setSorting(DolphinView::SortByDate);
666 }
667
668 void DolphinMainWindow::sortByPermissions()
669 {
670 m_activeView->setSorting(DolphinView::SortByPermissions);
671 }
672
673 void DolphinMainWindow::sortByOwner()
674 {
675 m_activeView->setSorting(DolphinView::SortByOwner);
676 }
677
678 void DolphinMainWindow::sortByGroup()
679 {
680 m_activeView->setSorting(DolphinView::SortByGroup);
681 }
682
683 void DolphinMainWindow::toggleSortOrder()
684 {
685 const Qt::SortOrder order = (m_activeView->sortOrder() == Qt::Ascending) ?
686 Qt::Descending :
687 Qt::Ascending;
688 m_activeView->setSortOrder(order);
689 }
690
691 void DolphinMainWindow::toggleSplitView()
692 {
693 if (m_view[SecondaryIdx] == 0) {
694 const int newWidth = (m_view[PrimaryIdx]->width() - m_splitter->handleWidth()) / 2;
695 // create a secondary view
696 m_view[SecondaryIdx] = new DolphinView(this,
697 0,
698 m_view[PrimaryIdx]->url(),
699 m_view[PrimaryIdx]->mode(),
700 m_view[PrimaryIdx]->showHiddenFiles());
701 connectViewSignals(SecondaryIdx);
702 m_splitter->addWidget(m_view[SecondaryIdx]);
703 m_splitter->setSizes(QList<int>() << newWidth << newWidth);
704 m_view[SecondaryIdx]->show();
705 }
706 else {
707 // remove secondary view
708 if (m_activeView == m_view[PrimaryIdx]) {
709 m_view[SecondaryIdx]->close();
710 m_view[SecondaryIdx]->deleteLater();
711 m_view[SecondaryIdx] = 0;
712 setActiveView(m_view[PrimaryIdx]);
713 }
714 else {
715 // The secondary view is active, hence from the users point of view
716 // the content of the secondary view should be moved to the primary view.
717 // From an implementation point of view it is more efficient to close
718 // the primary view and exchange the internal pointers afterwards.
719 m_view[PrimaryIdx]->close();
720 delete m_view[PrimaryIdx];
721 m_view[PrimaryIdx] = m_view[SecondaryIdx];
722 m_view[SecondaryIdx] = 0;
723 setActiveView(m_view[PrimaryIdx]);
724 }
725 }
726 emit activeViewChanged();
727 }
728
729 void DolphinMainWindow::reloadView()
730 {
731 clearStatusBar();
732 m_activeView->reload();
733 }
734
735 void DolphinMainWindow::stopLoading()
736 {
737 }
738
739 void DolphinMainWindow::togglePreview()
740 {
741 clearStatusBar();
742
743 const KToggleAction* showPreviewAction =
744 static_cast<KToggleAction*>(actionCollection()->action("show_preview"));
745 const bool show = showPreviewAction->isChecked();
746 m_activeView->setShowPreview(show);
747 }
748
749 void DolphinMainWindow::toggleShowHiddenFiles()
750 {
751 clearStatusBar();
752
753 const KToggleAction* showHiddenFilesAction =
754 static_cast<KToggleAction*>(actionCollection()->action("show_hidden_files"));
755 const bool show = showHiddenFilesAction->isChecked();
756 m_activeView->setShowHiddenFiles(show);
757 }
758
759 void DolphinMainWindow::showFilterBar()
760 {
761 const KToggleAction* showFilterBarAction =
762 static_cast<KToggleAction*>(actionCollection()->action("show_filter_bar"));
763 const bool show = showFilterBarAction->isChecked();
764 m_activeView->showFilterBar(show);
765 }
766
767 void DolphinMainWindow::zoomIn()
768 {
769 m_activeView->zoomIn();
770 updateViewActions();
771 }
772
773 void DolphinMainWindow::zoomOut()
774 {
775 m_activeView->zoomOut();
776 updateViewActions();
777 }
778
779 void DolphinMainWindow::toggleEditLocation()
780 {
781 clearStatusBar();
782
783 KToggleAction* action = static_cast<KToggleAction*>(actionCollection()->action("editable_location"));
784
785 bool editOrBrowse = action->isChecked();
786 m_activeView->setUrlEditable(editOrBrowse);
787 }
788
789 void DolphinMainWindow::editLocation()
790 {
791 m_activeView->setUrlEditable(true);
792 }
793
794 void DolphinMainWindow::adjustViewProperties()
795 {
796 clearStatusBar();
797 ViewPropertiesDialog dlg(m_activeView);
798 dlg.exec();
799 }
800
801 void DolphinMainWindow::goBack()
802 {
803 clearStatusBar();
804 m_activeView->goBack();
805 }
806
807 void DolphinMainWindow::goForward()
808 {
809 clearStatusBar();
810 m_activeView->goForward();
811 }
812
813 void DolphinMainWindow::goUp()
814 {
815 clearStatusBar();
816 m_activeView->goUp();
817 }
818
819 void DolphinMainWindow::goHome()
820 {
821 clearStatusBar();
822 m_activeView->goHome();
823 }
824
825 void DolphinMainWindow::openTerminal()
826 {
827 QString command("konsole --workdir \"");
828 command.append(m_activeView->url().path());
829 command.append('\"');
830
831 KRun::runCommand(command, "Konsole", "konsole");
832 }
833
834 void DolphinMainWindow::findFile()
835 {
836 KRun::run("kfind", m_activeView->url());
837 }
838
839 void DolphinMainWindow::compareFiles()
840 {
841 // The method is only invoked if exactly 2 files have
842 // been selected. The selected files may be:
843 // - both in the primary view
844 // - both in the secondary view
845 // - one in the primary view and the other in the secondary
846 // view
847 assert(m_view[PrimaryIdx] != 0);
848
849 KUrl urlA;
850 KUrl urlB;
851 KUrl::List urls = m_view[PrimaryIdx]->selectedUrls();
852
853 switch (urls.count()) {
854 case 0: {
855 assert(m_view[SecondaryIdx] != 0);
856 urls = m_view[SecondaryIdx]->selectedUrls();
857 assert(urls.count() == 2);
858 urlA = urls[0];
859 urlB = urls[1];
860 break;
861 }
862
863 case 1: {
864 urlA = urls[0];
865 assert(m_view[SecondaryIdx] != 0);
866 urls = m_view[SecondaryIdx]->selectedUrls();
867 assert(urls.count() == 1);
868 urlB = urls[0];
869 break;
870 }
871
872 case 2: {
873 urlA = urls[0];
874 urlB = urls[1];
875 break;
876 }
877
878 default: {
879 // may not happen: compareFiles may only get invoked if 2
880 // files are selected
881 assert(false);
882 }
883 }
884
885 QString command("kompare -c \"");
886 command.append(urlA.pathOrUrl());
887 command.append("\" \"");
888 command.append(urlB.pathOrUrl());
889 command.append('\"');
890 KRun::runCommand(command, "Kompare", "kompare");
891
892 }
893
894 void DolphinMainWindow::editSettings()
895 {
896 // TODO: make a static method for opening the settings dialog
897 DolphinSettingsDialog dlg(this);
898 dlg.exec();
899 }
900
901 void DolphinMainWindow::init()
902 {
903 // Check whether Dolphin runs the first time. If yes then
904 // a proper default window size is given at the end of DolphinMainWindow::init().
905 GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings();
906 const bool firstRun = generalSettings->firstRun();
907 if (firstRun) {
908 generalSettings->setViewPropsTimestamp(QDateTime::currentDateTime());
909 }
910
911 setAcceptDrops(true);
912
913 m_splitter = new QSplitter(this);
914
915 DolphinSettings& settings = DolphinSettings::instance();
916
917 KBookmarkManager* manager = settings.bookmarkManager();
918 assert(manager != 0);
919 KBookmarkGroup root = manager->root();
920 if (root.first().isNull()) {
921 root.addBookmark(manager, i18n("Home"), settings.generalSettings()->homeUrl(), "folder_home");
922 root.addBookmark(manager, i18n("Storage Media"), KUrl("media:/"), "blockdevice");
923 root.addBookmark(manager, i18n("Network"), KUrl("remote:/"), "network_local");
924 root.addBookmark(manager, i18n("Root"), KUrl("/"), "folder_red");
925 root.addBookmark(manager, i18n("Trash"), KUrl("trash:/"), "trashcan_full");
926 }
927
928 setupActions();
929
930 const KUrl& homeUrl = root.first().url();
931 setCaption(homeUrl.fileName());
932 ViewProperties props(homeUrl);
933 m_view[PrimaryIdx] = new DolphinView(this,
934 m_splitter,
935 homeUrl,
936 props.viewMode(),
937 props.showHiddenFiles());
938 connectViewSignals(PrimaryIdx);
939 m_view[PrimaryIdx]->show();
940
941 m_activeView = m_view[PrimaryIdx];
942
943 setCentralWidget(m_splitter);
944 setupDockWidgets();
945
946 setupGUI(Keys|Save|Create|ToolBar);
947 createGUI();
948
949 stateChanged("new_file");
950 setAutoSaveSettings();
951
952 QClipboard* clipboard = QApplication::clipboard();
953 connect(clipboard, SIGNAL(dataChanged()),
954 this, SLOT(updatePasteAction()));
955 updatePasteAction();
956 updateGoActions();
957
958 loadSettings();
959
960 if (firstRun) {
961 // assure a proper default size if Dolphin runs the first time
962 resize(640, 480);
963 }
964 #ifdef HAVE_KMETADATA
965 if (!DolphinApplication::app()->metadataLoader()->storageUp())
966 activeView()->statusBar()->setMessage(i18n("Failed to contact Nepomuk service, annotation and tagging are disabled."), DolphinStatusBar::Error);
967 #endif
968 }
969
970 void DolphinMainWindow::loadSettings()
971 {
972 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
973
974 KToggleAction* splitAction = static_cast<KToggleAction*>(actionCollection()->action("split_view"));
975 if (settings->splitView()) {
976 splitAction->setChecked(true);
977 toggleSplitView();
978 }
979
980 updateViewActions();
981
982 // TODO: I assume there will be a generic way in KDE 4 to restore the docks
983 // of the main window. In the meantime they are restored manually (see also
984 // DolphinMainWindow::closeEvent() for more details):
985 QString filename = KStandardDirs::locateLocal("data", KGlobal::mainComponent().componentName()); filename.append("/panels_layout");
986 QFile file(filename);
987 if (file.open(QIODevice::ReadOnly)) {
988 QByteArray data = file.readAll();
989 restoreState(data);
990 file.close();
991 }
992 }
993
994 void DolphinMainWindow::setupActions()
995 {
996 // setup 'File' menu
997 m_newMenu = new DolphinNewMenu(this);
998 KMenu* menu = m_newMenu->menu();
999 menu->setTitle(i18n("Create New..."));
1000 menu->setIcon(SmallIcon("filenew"));
1001 connect(menu, SIGNAL(aboutToShow()),
1002 this, SLOT(updateNewMenu()));
1003
1004 QAction* newWindow = actionCollection()->addAction("new_window");
1005 newWindow->setIcon(KIcon("window_new"));
1006 newWindow->setText(i18n("New &Window"));
1007 newWindow->setShortcut(Qt::CTRL | Qt::Key_N);
1008 connect(newWindow, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1009
1010 QAction* rename = actionCollection()->addAction("rename");
1011 rename->setText(i18n("Rename"));
1012 rename->setShortcut(Qt::Key_F2);
1013 connect(rename, SIGNAL(triggered()), this, SLOT(rename()));
1014
1015 QAction* moveToTrash = actionCollection()->addAction("move_to_trash");
1016 moveToTrash->setText(i18n("Move to Trash"));
1017 moveToTrash->setIcon(KIcon("edittrash"));
1018 moveToTrash->setShortcut(QKeySequence::Delete);
1019 connect(moveToTrash, SIGNAL(triggered()), this, SLOT(moveToTrash()));
1020
1021 QAction* deleteAction = actionCollection()->addAction("delete");
1022 deleteAction->setText(i18n("Delete"));
1023 deleteAction->setShortcut(Qt::SHIFT | Qt::Key_Delete);
1024 deleteAction->setIcon(KIcon("editdelete"));
1025 connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItems()));
1026
1027 QAction* properties = actionCollection()->addAction("properties");
1028 properties->setText(i18n("Properties"));
1029 properties->setShortcut(Qt::ALT | Qt::Key_Return);
1030 connect(properties, SIGNAL(triggered()), this, SLOT(properties()));
1031
1032 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1033
1034 // setup 'Edit' menu
1035 KStandardAction::undo(this,
1036 SLOT(undo()),
1037 actionCollection());
1038
1039 KStandardAction::cut(this, SLOT(cut()), actionCollection());
1040 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1041 KStandardAction::paste(this, SLOT(paste()), actionCollection());
1042
1043 QAction* selectAll = actionCollection()->addAction("select_all");
1044 selectAll->setText(i18n("Select All"));
1045 selectAll->setShortcut(Qt::CTRL + Qt::Key_A);
1046 connect(selectAll, SIGNAL(triggered()), this, SLOT(selectAll()));
1047
1048 QAction* invertSelection = actionCollection()->addAction("invert_selection");
1049 invertSelection->setText(i18n("Invert Selection"));
1050 invertSelection->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_A);
1051 connect(invertSelection, SIGNAL(triggered()), this, SLOT(invertSelection()));
1052
1053 // setup 'View' menu
1054 KStandardAction::zoomIn(this,
1055 SLOT(zoomIn()),
1056 actionCollection());
1057
1058 KStandardAction::zoomOut(this,
1059 SLOT(zoomOut()),
1060 actionCollection());
1061
1062 KToggleAction* iconsView = actionCollection()->add<KToggleAction>("icons");
1063 iconsView->setText(i18n("Icons"));
1064 iconsView->setShortcut(Qt::CTRL | Qt::Key_1);
1065 iconsView->setIcon(KIcon("view_icon"));
1066 connect(iconsView, SIGNAL(triggered()), this, SLOT(setIconsView()));
1067
1068 KToggleAction* detailsView = actionCollection()->add<KToggleAction>("details");
1069 detailsView->setText(i18n("Details"));
1070 detailsView->setShortcut(Qt::CTRL | Qt::Key_2);
1071 detailsView->setIcon(KIcon("view_text"));
1072 connect(detailsView, SIGNAL(triggered()), this, SLOT(setDetailsView()));
1073
1074 QActionGroup* viewModeGroup = new QActionGroup(this);
1075 viewModeGroup->addAction(iconsView);
1076 viewModeGroup->addAction(detailsView);
1077
1078 KToggleAction* sortByName = actionCollection()->add<KToggleAction>("by_name");
1079 sortByName->setText(i18n("By Name"));
1080 connect(sortByName, SIGNAL(triggered()), this, SLOT(sortByName()));
1081
1082 KToggleAction* sortBySize = actionCollection()->add<KToggleAction>("by_size");
1083 sortBySize->setText(i18n("By Size"));
1084 connect(sortBySize, SIGNAL(triggered()), this, SLOT(sortBySize()));
1085
1086 KToggleAction* sortByDate = actionCollection()->add<KToggleAction>("by_date");
1087 sortByDate->setText(i18n("By Date"));
1088 connect(sortByDate, SIGNAL(triggered()), this, SLOT(sortByDate()));
1089
1090 KToggleAction* sortByPermissions = actionCollection()->add<KToggleAction>("by_permissions");
1091 sortByPermissions->setText(i18n("By Permissions"));
1092 connect(sortByPermissions, SIGNAL(triggered()), this, SLOT(sortByPermissions()));
1093
1094 KToggleAction* sortByOwner = actionCollection()->add<KToggleAction>("by_owner");
1095 sortByOwner->setText(i18n("By Owner"));
1096 connect(sortByOwner, SIGNAL(triggered()), this, SLOT(sortByOwner()));
1097
1098 KToggleAction* sortByGroup = actionCollection()->add<KToggleAction>("by_group");
1099 sortByGroup->setText(i18n("By Group"));
1100 connect(sortByGroup, SIGNAL(triggered()), this, SLOT(sortByGroup()));
1101
1102 QActionGroup* sortGroup = new QActionGroup(this);
1103 sortGroup->addAction(sortByName);
1104 sortGroup->addAction(sortBySize);
1105 sortGroup->addAction(sortByDate);
1106 sortGroup->addAction(sortByPermissions);
1107 sortGroup->addAction(sortByOwner);
1108 sortGroup->addAction(sortByGroup);
1109
1110 KToggleAction* sortDescending = actionCollection()->add<KToggleAction>("descending");
1111 sortDescending->setText(i18n("Descending"));
1112 connect(sortDescending, SIGNAL(triggered()), this, SLOT(toggleSortOrder()));
1113
1114 KToggleAction* showPreview = actionCollection()->add<KToggleAction>("show_preview");
1115 showPreview->setText(i18n("Show Preview"));
1116 connect(showPreview, SIGNAL(triggered()), this, SLOT(togglePreview()));
1117
1118 KToggleAction* showHiddenFiles = actionCollection()->add<KToggleAction>("show_hidden_files");
1119 showHiddenFiles->setText(i18n("Show Hidden Files"));
1120 showHiddenFiles->setShortcut(Qt::ALT | Qt::Key_Period);
1121 connect(showHiddenFiles, SIGNAL(triggered()), this, SLOT(toggleShowHiddenFiles()));
1122
1123 KToggleAction* split = actionCollection()->add<KToggleAction>("split_view");
1124 split->setText(i18n("Split View"));
1125 split->setShortcut(Qt::Key_F10);
1126 split->setIcon(KIcon("view_left_right"));
1127 connect(split, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1128
1129 QAction* reload = actionCollection()->addAction("reload");
1130 reload->setText(i18n("Reload"));
1131 reload->setShortcut(Qt::Key_F5);
1132 reload->setIcon(KIcon("reload"));
1133 connect(reload, SIGNAL(triggered()), this, SLOT(reloadView()));
1134
1135 QAction* stop = actionCollection()->addAction("stop");
1136 stop->setText(i18n("Stop"));
1137 stop->setIcon(KIcon("stop"));
1138 connect(stop, SIGNAL(triggered()), this, SLOT(stopLoading()));
1139
1140 // TODO: the URL navigator must emit a signal if the editable state has been
1141 // changed, so that the corresponding showFullLocation action is updated. Also
1142 // the naming "Show full Location" is currently confusing...
1143 KToggleAction* showFullLocation = actionCollection()->add<KToggleAction>("editable_location");
1144 showFullLocation->setText(i18n("Show Full Location"));
1145 showFullLocation->setShortcut(Qt::CTRL | Qt::Key_L);
1146 connect(showFullLocation, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1147
1148 QAction* editLocation = actionCollection()->addAction("edit_location");
1149 editLocation->setText(i18n("Edit Location"));
1150 editLocation->setShortcut(Qt::Key_F6);
1151 connect(editLocation, SIGNAL(triggered()), this, SLOT(editLocation()));
1152
1153 QAction* adjustViewProps = actionCollection()->addAction("view_properties");
1154 adjustViewProps->setText(i18n("Adjust View Properties..."));
1155 connect(adjustViewProps, SIGNAL(triggered()), this, SLOT(adjustViewProperties()));
1156
1157 // setup 'Go' menu
1158 KStandardAction::back(this, SLOT(goBack()), actionCollection());
1159 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1160 KStandardAction::up(this, SLOT(goUp()), actionCollection());
1161 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1162
1163 // setup 'Tools' menu
1164 QAction* openTerminal = actionCollection()->addAction("open_terminal");
1165 openTerminal->setText(i18n("Open Terminal"));
1166 openTerminal->setShortcut(Qt::Key_F4);
1167 openTerminal->setIcon(KIcon("konsole"));
1168 connect(openTerminal, SIGNAL(triggered()), this, SLOT(openTerminal()));
1169
1170 QAction* findFile = actionCollection()->addAction("find_file");
1171 findFile->setText(i18n("Find File..."));
1172 findFile->setShortcut(Qt::Key_F);
1173 findFile->setIcon(KIcon("filefind"));
1174 connect(findFile, SIGNAL(triggered()), this, SLOT(findFile()));
1175
1176 KToggleAction* showFilterBar = actionCollection()->add<KToggleAction>("show_filter_bar");
1177 showFilterBar->setText(i18n("Show Filter Bar"));
1178 showFilterBar->setShortcut(Qt::Key_Slash);
1179 connect(showFilterBar, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1180
1181 QAction* compareFiles = actionCollection()->addAction("compare_files");
1182 compareFiles->setText(i18n("Compare Files"));
1183 compareFiles->setIcon(KIcon("kompare"));
1184 compareFiles->setEnabled(false);
1185 connect(compareFiles, SIGNAL(triggered()), this, SLOT(compareFiles()));
1186
1187 // setup 'Settings' menu
1188 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1189 }
1190
1191 void DolphinMainWindow::setupDockWidgets()
1192 {
1193 QDockWidget* shortcutsDock = new QDockWidget(i18n("Bookmarks"));
1194 shortcutsDock->setObjectName("bookmarksDock");
1195 shortcutsDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1196 shortcutsDock->setWidget(new BookmarksSidebarPage(this));
1197
1198 shortcutsDock->toggleViewAction()->setText(i18n("Show Bookmarks Panel"));
1199 actionCollection()->addAction("show_bookmarks_panel", shortcutsDock->toggleViewAction());
1200
1201 addDockWidget(Qt::LeftDockWidgetArea, shortcutsDock);
1202
1203 QDockWidget* infoDock = new QDockWidget(i18n("Information"));
1204 infoDock->setObjectName("infoDock");
1205 infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1206 infoDock->setWidget(new InfoSidebarPage(this));
1207
1208 infoDock->toggleViewAction()->setText(i18n("Show Information Panel"));
1209 actionCollection()->addAction("show_info_panel", infoDock->toggleViewAction());
1210
1211 addDockWidget(Qt::RightDockWidgetArea, infoDock);
1212 }
1213
1214 void DolphinMainWindow::updateHistory()
1215 {
1216 int index = 0;
1217 const QLinkedList<UrlNavigator::HistoryElem> list = m_activeView->urlHistory(index);
1218
1219 QAction* backAction = actionCollection()->action("go_back");
1220 if (backAction != 0) {
1221 backAction->setEnabled(index < static_cast<int>(list.count()) - 1);
1222 }
1223
1224 QAction* forwardAction = actionCollection()->action("go_forward");
1225 if (forwardAction != 0) {
1226 forwardAction->setEnabled(index > 0);
1227 }
1228 }
1229
1230 void DolphinMainWindow::updateEditActions()
1231 {
1232 const KFileItemList list = m_activeView->selectedItems();
1233 if (list.isEmpty()) {
1234 stateChanged("has_no_selection");
1235 }
1236 else {
1237 stateChanged("has_selection");
1238
1239 QAction* renameAction = actionCollection()->action("rename");
1240 if (renameAction != 0) {
1241 renameAction->setEnabled(list.count() >= 1);
1242 }
1243
1244 bool enableMoveToTrash = true;
1245
1246 KFileItemList::const_iterator it = list.begin();
1247 const KFileItemList::const_iterator end = list.end();
1248 while (it != end) {
1249 KFileItem* item = *it;
1250 const KUrl& url = item->url();
1251 // only enable the 'Move to Trash' action for local files
1252 if (!url.isLocalFile()) {
1253 enableMoveToTrash = false;
1254 }
1255 ++it;
1256 }
1257
1258 QAction* moveToTrashAction = actionCollection()->action("move_to_trash");
1259 moveToTrashAction->setEnabled(enableMoveToTrash);
1260 }
1261 updatePasteAction();
1262 }
1263
1264 void DolphinMainWindow::updateViewActions()
1265 {
1266 QAction* zoomInAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::ZoomIn));
1267 if (zoomInAction != 0) {
1268 zoomInAction->setEnabled(m_activeView->isZoomInPossible());
1269 }
1270
1271 QAction* zoomOutAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::ZoomOut));
1272 if (zoomOutAction != 0) {
1273 zoomOutAction->setEnabled(m_activeView->isZoomOutPossible());
1274 }
1275
1276 QAction* action = 0;
1277 switch (m_activeView->mode()) {
1278 case DolphinView::IconsView:
1279 action = actionCollection()->action("icons");
1280 break;
1281 case DolphinView::DetailsView:
1282 action = actionCollection()->action("details");
1283 break;
1284 default:
1285 break;
1286 }
1287
1288 if (action != 0) {
1289 KToggleAction* toggleAction = static_cast<KToggleAction*>(action);
1290 toggleAction->setChecked(true);
1291 }
1292
1293 slotSortingChanged(m_activeView->sorting());
1294 slotSortOrderChanged(m_activeView->sortOrder());
1295
1296 KToggleAction* showFilterBarAction =
1297 static_cast<KToggleAction*>(actionCollection()->action("show_filter_bar"));
1298 showFilterBarAction->setChecked(m_activeView->isFilterBarVisible());
1299
1300 KToggleAction* showPreviewAction =
1301 static_cast<KToggleAction*>(actionCollection()->action("show_preview"));
1302 showPreviewAction->setChecked(m_activeView->showPreview());
1303
1304 KToggleAction* showHiddenFilesAction =
1305 static_cast<KToggleAction*>(actionCollection()->action("show_hidden_files"));
1306 showHiddenFilesAction->setChecked(m_activeView->showHiddenFiles());
1307
1308 KToggleAction* splitAction = static_cast<KToggleAction*>(actionCollection()->action("split_view"));
1309 splitAction->setChecked(m_view[SecondaryIdx] != 0);
1310
1311 KToggleAction* editableLocactionAction =
1312 static_cast<KToggleAction*>(actionCollection()->action("editable_location"));
1313 editableLocactionAction->setChecked(m_activeView->isUrlEditable());
1314 }
1315
1316 void DolphinMainWindow::updateGoActions()
1317 {
1318 QAction* goUpAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::Up));
1319 const KUrl& currentUrl = m_activeView->url();
1320 goUpAction->setEnabled(currentUrl.upUrl() != currentUrl);
1321 }
1322
1323 void DolphinMainWindow::copyUrls(const KUrl::List& source, const KUrl& dest)
1324 {
1325 KonqOperations::copy(this, KonqOperations::COPY, source, dest);
1326 m_undoOperations.append(KonqOperations::COPY);
1327 }
1328
1329 void DolphinMainWindow::moveUrls(const KUrl::List& source, const KUrl& dest)
1330 {
1331 KonqOperations::copy(this, KonqOperations::MOVE, source, dest);
1332 m_undoOperations.append(KonqOperations::MOVE);
1333 }
1334
1335 void DolphinMainWindow::linkUrls(const KUrl::List& source, const KUrl& dest)
1336 {
1337 KonqOperations::copy(this, KonqOperations::LINK, source, dest);
1338 m_undoOperations.append(KonqOperations::LINK);
1339 }
1340
1341 void DolphinMainWindow::clearStatusBar()
1342 {
1343 m_activeView->statusBar()->clear();
1344 }
1345
1346 void DolphinMainWindow::connectViewSignals(int viewIndex)
1347 {
1348 DolphinView* view = m_view[viewIndex];
1349 connect(view, SIGNAL(modeChanged()),
1350 this, SLOT(slotViewModeChanged()));
1351 connect(view, SIGNAL(showPreviewChanged()),
1352 this, SLOT(slowShowPreviewChanged()));
1353 connect(view, SIGNAL(showHiddenFilesChanged()),
1354 this, SLOT(slotShowHiddenFilesChanged()));
1355 connect(view, SIGNAL(sortingChanged(DolphinView::Sorting)),
1356 this, SLOT(slotSortingChanged(DolphinView::Sorting)));
1357 connect(view, SIGNAL(sortOrderChanged(Qt::SortOrder)),
1358 this, SLOT(slotSortOrderChanged(Qt::SortOrder)));
1359 connect(view, SIGNAL(selectionChanged()),
1360 this, SLOT(slotSelectionChanged()));
1361 connect(view, SIGNAL(showFilterBarChanged(bool)),
1362 this, SLOT(updateFilterBarAction(bool)));
1363
1364 const UrlNavigator* navigator = view->urlNavigator();
1365 connect(navigator, SIGNAL(urlChanged(const KUrl&)),
1366 this, SLOT(slotUrlChanged(const KUrl&)));
1367 connect(navigator, SIGNAL(historyChanged()),
1368 this, SLOT(slotHistoryChanged()));
1369
1370 }
1371
1372 DolphinMainWindow::UndoUiInterface::UndoUiInterface(DolphinMainWindow* mainWin) :
1373 KonqUndoManager::UiInterface(mainWin),
1374 m_mainWin(mainWin)
1375 {
1376 assert(m_mainWin != 0);
1377 }
1378
1379 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1380 {
1381 }
1382
1383 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job)
1384 {
1385 DolphinStatusBar* statusBar = m_mainWin->activeView()->statusBar();
1386 statusBar->setMessage(job->errorString(), DolphinStatusBar::Error);
1387 }
1388
1389 #include "dolphinmainwindow.moc"