]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
Use a QLinkedList instead of Q3PtrList
[dolphin.git] / src / dolphinmainwindow.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2006 by Stefan Monov <logixoul@gmail.com> *
4 * Copyright (C) 2006 by Cvetoslav Ludmiloff <ludmiloff@gmail.com> *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
21
22 #include "dolphinmainwindow.h"
23
24 #include <assert.h>
25
26 #include <kactioncollection.h>
27 #include <ktoggleaction.h>
28 #include <kbookmarkmanager.h>
29 #include <kglobal.h>
30 #include <kpropertiesdialog.h>
31 #include <kicon.h>
32 #include <kiconloader.h>
33 #include <kdeversion.h>
34 #include <kstatusbar.h>
35 #include <kio/netaccess.h>
36 #include <kfiledialog.h>
37 #include <kconfig.h>
38 #include <kurl.h>
39 #include <kstdaccel.h>
40 #include <kaction.h>
41 #include <kstdaction.h>
42 #include <kmenu.h>
43 #include <kio/renamedlg.h>
44 #include <kinputdialog.h>
45 #include <kshell.h>
46 #include <kdesktopfile.h>
47 #include <kstandarddirs.h>
48 #include <kprotocolinfo.h>
49 #include <kmessagebox.h>
50 #include <kservice.h>
51 #include <kstandarddirs.h>
52 #include <krun.h>
53 #include <klocale.h>
54
55 #include <qclipboard.h>
56 #include <q3dragobject.h>
57 //Added by qt3to4:
58 #include <Q3ValueList>
59 #include <QCloseEvent>
60 #include <QSplitter>
61 #include <QDockWidget>
62
63 #include "urlnavigator.h"
64 #include "viewpropertiesdialog.h"
65 #include "viewproperties.h"
66 #include "dolphinsettings.h"
67 #include "dolphinsettingsdialog.h"
68 #include "dolphinstatusbar.h"
69 #include "dolphinapplication.h"
70 #include "undomanager.h"
71 #include "progressindicator.h"
72 #include "dolphinsettings.h"
73 #include "bookmarkssidebarpage.h"
74 #include "infosidebarpage.h"
75 #include "generalsettings.h"
76 #include "dolphinapplication.h"
77
78
79 DolphinMainWindow::DolphinMainWindow() :
80 KMainWindow(0),
81 m_splitter(0),
82 m_activeView(0),
83 m_clipboardContainsCutData(false)
84 {
85 setObjectName("Dolphin");
86 m_view[PrimaryIdx] = 0;
87 m_view[SecondaryIdx] = 0;
88
89 // TODO: the following members are not used yet. See documentation
90 // of DolphinMainWindow::linkGroupActions() and DolphinMainWindow::linkToDeviceActions()
91 // in the header file for details.
92 }
93
94 DolphinMainWindow::~DolphinMainWindow()
95 {
96 qDeleteAll(m_fileGroupActions);
97 //qDeleteAll(m_linkToDeviceActions);
98 //qDeleteAll(m_linkGroupActions);
99 m_fileGroupActions.clear();
100 //m_linkGroupActions.clear();
101 //m_linkToDeviceActions.clear();
102
103 /*
104 * bye, bye managed window
105 */
106 DolphinApplication::app()->removeMainWindow( this );
107 }
108
109 void DolphinMainWindow::setActiveView(DolphinView* view)
110 {
111 assert((view == m_view[PrimaryIdx]) || (view == m_view[SecondaryIdx]));
112 if (m_activeView == view) {
113 return;
114 }
115
116 m_activeView = view;
117
118 updateHistory();
119 updateEditActions();
120 updateViewActions();
121 updateGoActions();
122
123 setCaption(m_activeView->url().fileName());
124
125 emit activeViewChanged();
126 }
127
128 void DolphinMainWindow::dropUrls(const KUrl::List& urls,
129 const KUrl& destination)
130 {
131 int selectedIndex = -1;
132
133 /* KDE4-TODO
134 const ButtonState keyboardState = KApplication::keyboardMouseState();
135 const bool shiftPressed = (keyboardState & ShiftButton) > 0;
136 const bool controlPressed = (keyboardState & ControlButton) > 0;
137
138
139
140 if (shiftPressed && controlPressed) {
141 // shortcut for 'Linke Here' is used
142 selectedIndex = 2;
143 }
144 else if (controlPressed) {
145 // shortcut for 'Copy Here' is used
146 selectedIndex = 1;
147 }
148 else if (shiftPressed) {
149 // shortcut for 'Move Here' is used
150 selectedIndex = 0;
151 }
152 else*/ {
153 // no shortcut is used, hence open a popup menu
154 KMenu popup(this);
155
156 popup.insertItem(SmallIcon("goto"), i18n("&Move Here") + "\t" /* KDE4-TODO: + KKey::modFlagLabel(KKey::SHIFT)*/, 0);
157 popup.insertItem(SmallIcon("editcopy"), i18n( "&Copy Here" ) /* KDE4-TODO + "\t" + KKey::modFlagLabel(KKey::CTRL)*/, 1);
158 popup.insertItem(i18n("&Link Here") /* KDE4-TODO + "\t" + KKey::modFlagLabel((KKey::ModFlag)(KKey::CTRL|KKey::SHIFT)) */, 2);
159 popup.insertSeparator();
160 popup.insertItem(SmallIcon("stop"), i18n("Cancel"), 3);
161 popup.setAccel(i18n("Escape"), 3);
162
163 /* KDE4-TODO: selectedIndex = popup.exec(QCursor::pos()); */
164 popup.exec(QCursor::pos());
165 selectedIndex = 0; // KD4-TODO: use QAction instead of switch below
166 // See libkonq/konq_operations.cc: KonqOperations::doDropFileCopy() (and doDrop, the main method)
167 }
168
169 if (selectedIndex < 0) {
170 return;
171 }
172
173 switch (selectedIndex) {
174 case 0: {
175 // 'Move Here' has been selected
176 updateViewProperties(urls);
177 moveUrls(urls, destination);
178 break;
179 }
180
181 case 1: {
182 // 'Copy Here' has been selected
183 updateViewProperties(urls);
184 copyUrls(urls, destination);
185 break;
186 }
187
188 case 2: {
189 // 'Link Here' has been selected
190 KIO::Job* job = KIO::link(urls, destination);
191 addPendingUndoJob(job, DolphinCommand::Link, urls, destination);
192 break;
193 }
194
195 default:
196 // 'Cancel' has been selected
197 break;
198 }
199 }
200
201 void DolphinMainWindow::refreshViews()
202 {
203 const bool split = DolphinSettings::instance().generalSettings()->splitView();
204 const bool isPrimaryViewActive = (m_activeView == m_view[PrimaryIdx]);
205 KUrl url;
206 for (int i = PrimaryIdx; i <= SecondaryIdx; ++i) {
207 if (m_view[i] != 0) {
208 url = m_view[i]->url();
209
210 // delete view instance...
211 m_view[i]->close();
212 m_view[i]->deleteLater();
213 m_view[i] = 0;
214 }
215
216 if (split || (i == PrimaryIdx)) {
217 // ... and recreate it
218 ViewProperties props(url);
219 m_view[i] = new DolphinView(this,
220 m_splitter,
221 url,
222 props.viewMode(),
223 props.isShowHiddenFilesEnabled());
224 connectViewSignals(i);
225 m_view[i]->show();
226 }
227 }
228
229 m_activeView = isPrimaryViewActive ? m_view[PrimaryIdx] : m_view[SecondaryIdx];
230 assert(m_activeView != 0);
231
232 updateViewActions();
233 emit activeViewChanged();
234 }
235
236 void DolphinMainWindow::slotViewModeChanged()
237 {
238 updateViewActions();
239 }
240
241 void DolphinMainWindow::slotShowHiddenFilesChanged()
242 {
243 KToggleAction* showHiddenFilesAction =
244 static_cast<KToggleAction*>(actionCollection()->action("show_hidden_files"));
245 showHiddenFilesAction->setChecked(m_activeView->isShowHiddenFilesEnabled());
246 }
247
248 void DolphinMainWindow::slotSortingChanged(DolphinView::Sorting sorting)
249 {
250 QAction* action = 0;
251 switch (sorting) {
252 case DolphinView::SortByName:
253 action = actionCollection()->action("by_name");
254 break;
255 case DolphinView::SortBySize:
256 action = actionCollection()->action("by_size");
257 break;
258 case DolphinView::SortByDate:
259 action = actionCollection()->action("by_date");
260 break;
261 default:
262 break;
263 }
264
265 if (action != 0) {
266 KToggleAction* toggleAction = static_cast<KToggleAction*>(action);
267 toggleAction->setChecked(true);
268 }
269 }
270
271 void DolphinMainWindow::slotSortOrderChanged(Qt::SortOrder order)
272 {
273 KToggleAction* descending = static_cast<KToggleAction*>(actionCollection()->action("descending"));
274 const bool sortDescending = (order == Qt::Descending);
275 descending->setChecked(sortDescending);
276 }
277
278 void DolphinMainWindow::slotSelectionChanged()
279 {
280 updateEditActions();
281
282 assert(m_view[PrimaryIdx] != 0);
283 int selectedUrlsCount = m_view[PrimaryIdx]->selectedUrls().count();
284 if (m_view[SecondaryIdx] != 0) {
285 selectedUrlsCount += m_view[SecondaryIdx]->selectedUrls().count();
286 }
287
288 QAction* compareFilesAction = actionCollection()->action("compare_files");
289 compareFilesAction->setEnabled(selectedUrlsCount == 2);
290
291 m_activeView->updateStatusBar();
292
293 emit selectionChanged();
294 }
295
296 void DolphinMainWindow::slotHistoryChanged()
297 {
298 updateHistory();
299 }
300
301 void DolphinMainWindow::slotUrlChanged(const KUrl& url)
302 {
303 updateEditActions();
304 updateGoActions();
305 setCaption(url.fileName());
306 }
307
308 void DolphinMainWindow::updateFilterBarAction(bool show)
309 {
310 KToggleAction* showFilterBarAction =
311 static_cast<KToggleAction*>(actionCollection()->action("show_filter_bar"));
312 showFilterBarAction->setChecked(show);
313 }
314
315 void DolphinMainWindow::redo()
316 {
317 UndoManager::instance().redo(this);
318 }
319
320 void DolphinMainWindow::undo()
321 {
322 UndoManager::instance().undo(this);
323 }
324
325 void DolphinMainWindow::openNewMainWindow()
326 {
327 DolphinApplication::app()->createMainWindow()->show();
328 }
329
330 void DolphinMainWindow::closeEvent(QCloseEvent* event)
331 {
332 // KDE4-TODO
333 //KConfig* config = KGlobal::config();
334 //config->setGroup("General");
335 //config->writeEntry("First Run", false);
336
337 DolphinSettings& settings = DolphinSettings::instance();
338 GeneralSettings* generalSettings = settings.generalSettings();
339 generalSettings->setFirstRun(false);
340
341 settings.save();
342
343 KMainWindow::closeEvent(event);
344 }
345
346 void DolphinMainWindow::saveProperties(KConfig* config)
347 {
348 config->setGroup("Primary view");
349 config->writeEntry("Url", m_view[PrimaryIdx]->url().url());
350 config->writeEntry("Editable Url", m_view[PrimaryIdx]->isUrlEditable());
351 if (m_view[SecondaryIdx] != 0) {
352 config->setGroup("Secondary view");
353 config->writeEntry("Url", m_view[SecondaryIdx]->url().url());
354 config->writeEntry("Editable Url", m_view[SecondaryIdx]->isUrlEditable());
355 }
356 }
357
358 void DolphinMainWindow::readProperties(KConfig* config)
359 {
360 config->setGroup("Primary view");
361 m_view[PrimaryIdx]->setUrl(config->readEntry("Url"));
362 m_view[PrimaryIdx]->setUrlEditable(config->readEntry("Editable Url", false));
363 if (config->hasGroup("Secondary view")) {
364 config->setGroup("Secondary view");
365 if (m_view[SecondaryIdx] == 0) {
366 toggleSplitView();
367 }
368 m_view[SecondaryIdx]->setUrl(config->readEntry("Url"));
369 m_view[SecondaryIdx]->setUrlEditable(config->readEntry("Editable Url", false));
370 }
371 else if (m_view[SecondaryIdx] != 0) {
372 toggleSplitView();
373 }
374 }
375
376 void DolphinMainWindow::createFolder()
377 {
378 // Parts of the following code have been taken
379 // from the class KonqPopupMenu located in
380 // libqonq/konq_popupmenu.h of Konqueror.
381 // (Copyright (C) 2000 David Faure <faure@kde.org>,
382 // Copyright (C) 2001 Holger Freyther <freyther@yahoo.com>)
383
384 clearStatusBar();
385
386 DolphinStatusBar* statusBar = m_activeView->statusBar();
387 const KUrl baseUrl(m_activeView->url());
388
389 QString name(i18n("New Folder"));
390 baseUrl.path(KUrl::AddTrailingSlash);
391
392
393 if (baseUrl.isLocalFile() && QFileInfo(baseUrl.path(KUrl::AddTrailingSlash) + name).exists()) {
394 name = KIO::RenameDlg::suggestName(baseUrl, i18n("New Folder"));
395 }
396
397 bool ok = false;
398 name = KInputDialog::getText(i18n("New Folder"),
399 i18n("Enter folder name:" ),
400 name,
401 &ok,
402 this);
403
404 if (!ok) {
405 // the user has pressed 'Cancel'
406 return;
407 }
408
409 assert(!name.isEmpty());
410
411 KUrl url;
412 if ((name[0] == '/') || (name[0] == '~')) {
413 url.setPath(KShell::tildeExpand(name));
414 }
415 else {
416 name = KIO::encodeFileName(name);
417 url = baseUrl;
418 url.addPath(name);
419 }
420 ok = KIO::NetAccess::mkdir(url, this);
421
422 // TODO: provide message type hint
423 if (ok) {
424 statusBar->setMessage(i18n("Created folder %1.",url.path()),
425 DolphinStatusBar::OperationCompleted);
426
427 DolphinCommand command(DolphinCommand::CreateFolder, KUrl::List(), url);
428 UndoManager::instance().addCommand(command);
429 }
430 else {
431 // Creating of the folder has been failed. Check whether the creating
432 // has been failed because a folder with the same name exists...
433 if (KIO::NetAccess::exists(url, true, this)) {
434 statusBar->setMessage(i18n("A folder named %1 already exists.",url.path()),
435 DolphinStatusBar::Error);
436 }
437 else {
438 statusBar->setMessage(i18n("Creating of folder %1 failed.",url.path()),
439 DolphinStatusBar::Error);
440 }
441
442 }
443 }
444
445 void DolphinMainWindow::createFile()
446 {
447 // Parts of the following code have been taken
448 // from the class KonqPopupMenu located in
449 // libqonq/konq_popupmenu.h of Konqueror.
450 // (Copyright (C) 2000 David Faure <faure@kde.org>,
451 // Copyright (C) 2001 Holger Freyther <freyther@yahoo.com>)
452
453 clearStatusBar();
454
455 // TODO: const Entry& entry = m_createFileTemplates[QString(sender->name())];
456 // should be enough. Anyway: the implemantation of [] does a linear search internally too.
457 KSortableList<CreateFileEntry, QString>::ConstIterator it = m_createFileTemplates.begin();
458 KSortableList<CreateFileEntry, QString>::ConstIterator end = m_createFileTemplates.end();
459
460 const QString senderName(sender()->objectName());
461 bool found = false;
462 CreateFileEntry entry;
463 while (!found && (it != end)) {
464 if ((*it).key() == senderName) {
465 entry = (*it).value();
466 found = true;
467 }
468 else {
469 ++it;
470 }
471 }
472
473 DolphinStatusBar* statusBar = m_activeView->statusBar();
474 if (!found || !QFile::exists(entry.templatePath)) {
475 statusBar->setMessage(i18n("Could not create file."), DolphinStatusBar::Error);
476 return;
477 }
478
479 // Get the source path of the template which should be copied.
480 // The source path is part of the Url entry of the desktop file.
481 const int pos = entry.templatePath.lastIndexOf('/');
482 QString sourcePath(entry.templatePath.left(pos + 1));
483 sourcePath += KDesktopFile(entry.templatePath, true).readPathEntry("Url");
484
485 QString name(i18n(entry.name.toAscii()));
486 // Most entry names end with "..." (e. g. "HTML File..."), which is ok for
487 // menus but no good choice for a new file name -> remove the dots...
488 name.replace("...", QString::null);
489
490 // add the file extension to the name
491 name.append(sourcePath.right(sourcePath.length() - sourcePath.lastIndexOf('.')));
492
493 // Check whether a file with the current name already exists. If yes suggest automatically
494 // a unique file name (e. g. "HTML File" will be replaced by "HTML File_1").
495 const KUrl viewUrl(m_activeView->url());
496 const bool fileExists = viewUrl.isLocalFile() &&
497 QFileInfo(viewUrl.path(KUrl::AddTrailingSlash) + KIO::encodeFileName(name)).exists();
498 if (fileExists) {
499 name = KIO::RenameDlg::suggestName(viewUrl, name);
500 }
501
502 // let the user change the suggested file name
503 bool ok = false;
504 name = KInputDialog::getText(entry.name,
505 entry.comment,
506 name,
507 &ok,
508 this);
509 if (!ok) {
510 // the user has pressed 'Cancel'
511 return;
512 }
513
514 // before copying the template to the destination path check whether a file
515 // with the given name already exists
516 const QString destPath(viewUrl.pathOrUrl() + "/" + KIO::encodeFileName(name));
517 const KUrl destUrl(destPath);
518 if (KIO::NetAccess::exists(destUrl, false, this)) {
519 statusBar->setMessage(i18n("A file named %1 already exists.",name),
520 DolphinStatusBar::Error);
521 return;
522 }
523
524 // copy the template to the destination path
525 const KUrl sourceUrl(sourcePath);
526 KIO::CopyJob* job = KIO::copyAs(sourceUrl, destUrl);
527 job->setDefaultPermissions(true);
528 if (KIO::NetAccess::synchronousRun(job, this)) {
529 statusBar->setMessage(i18n("Created file %1.",name),
530 DolphinStatusBar::OperationCompleted);
531
532 KUrl::List list;
533 list.append(sourceUrl);
534 DolphinCommand command(DolphinCommand::CreateFile, list, destUrl);
535 UndoManager::instance().addCommand(command);
536
537 }
538 else {
539 statusBar->setMessage(i18n("Creating of file %1 failed.",name),
540 DolphinStatusBar::Error);
541 }
542 }
543
544 void DolphinMainWindow::rename()
545 {
546 clearStatusBar();
547 m_activeView->renameSelectedItems();
548 }
549
550 void DolphinMainWindow::moveToTrash()
551 {
552 clearStatusBar();
553 KUrl::List selectedUrls = m_activeView->selectedUrls();
554 KIO::Job* job = KIO::trash(selectedUrls);
555 addPendingUndoJob(job, DolphinCommand::Trash, selectedUrls, m_activeView->url());
556 }
557
558 void DolphinMainWindow::deleteItems()
559 {
560 clearStatusBar();
561
562 KUrl::List list = m_activeView->selectedUrls();
563 const uint itemCount = list.count();
564 assert(itemCount >= 1);
565
566 QString text;
567 if (itemCount > 1) {
568 text = i18n("Do you really want to delete the %1 selected items?",itemCount);
569 }
570 else {
571 const KUrl& url = list.first();
572 text = i18n("Do you really want to delete '%1'?",url.fileName());
573 }
574
575 const bool del = KMessageBox::warningContinueCancel(this,
576 text,
577 QString::null,
578 KGuiItem(i18n("Delete"), SmallIcon("editdelete"))
579 ) == KMessageBox::Continue;
580 if (del) {
581 KIO::Job* job = KIO::del(list);
582 connect(job, SIGNAL(result(KJob*)),
583 this, SLOT(slotHandleJobError(KJob*)));
584 connect(job, SIGNAL(result(KJob*)),
585 this, SLOT(slotDeleteFileFinished(KJob*)));
586 }
587 }
588
589 void DolphinMainWindow::properties()
590 {
591 const KFileItemList list = m_activeView->selectedItems();
592 new KPropertiesDialog(list, this);
593 }
594
595 void DolphinMainWindow::quit()
596 {
597 close();
598 }
599
600 void DolphinMainWindow::slotHandleJobError(KJob* job)
601 {
602 if (job->error() != 0) {
603 m_activeView->statusBar()->setMessage(job->errorString(),
604 DolphinStatusBar::Error);
605 }
606 }
607
608 void DolphinMainWindow::slotDeleteFileFinished(KJob* job)
609 {
610 if (job->error() == 0) {
611 m_activeView->statusBar()->setMessage(i18n("Delete operation completed."),
612 DolphinStatusBar::OperationCompleted);
613
614 // TODO: In opposite to the 'Move to Trash' operation in the class KFileIconView
615 // no rearranging of the item position is done when a file has been deleted.
616 // This is bypassed by reloading the view, but it might be worth to investigate
617 // deeper for the root of this issue.
618 m_activeView->reload();
619 }
620 }
621
622 void DolphinMainWindow::slotUndoAvailable(bool available)
623 {
624 QAction* undoAction = actionCollection()->action(KStdAction::stdName(KStdAction::Undo));
625 if (undoAction != 0) {
626 undoAction->setEnabled(available);
627 }
628 }
629
630 void DolphinMainWindow::slotUndoTextChanged(const QString& text)
631 {
632 QAction* undoAction = actionCollection()->action(KStdAction::stdName(KStdAction::Undo));
633 if (undoAction != 0) {
634 undoAction->setText(text);
635 }
636 }
637
638 void DolphinMainWindow::slotRedoAvailable(bool available)
639 {
640 QAction* redoAction = actionCollection()->action(KStdAction::stdName(KStdAction::Redo));
641 if (redoAction != 0) {
642 redoAction->setEnabled(available);
643 }
644 }
645
646 void DolphinMainWindow::slotRedoTextChanged(const QString& text)
647 {
648 QAction* redoAction = actionCollection()->action(KStdAction::stdName(KStdAction::Redo));
649 if (redoAction != 0) {
650 redoAction->setText(text);
651 }
652 }
653
654 void DolphinMainWindow::cut()
655 {
656 // TODO: this boolean doesn't work between instances of dolphin or with konqueror or with other
657 // apps. The "application/x-kde-cutselection" mimetype should be used instead, see KonqMimeData
658 // in libkonq
659 m_clipboardContainsCutData = true;
660 /* KDE4-TODO: Q3DragObject* data = new KUrlDrag(m_activeView->selectedUrls(),
661 widget());
662 QApplication::clipboard()->setData(data);*/
663 }
664
665 void DolphinMainWindow::copy()
666 {
667 m_clipboardContainsCutData = false;
668 /* KDE4-TODO:
669 Q3DragObject* data = new KUrlDrag(m_activeView->selectedUrls(),
670 widget());
671 QApplication::clipboard()->setData(data);*/
672 }
673
674 void DolphinMainWindow::paste()
675 {
676 /* KDE4-TODO: - see KonqOperations::doPaste
677 QClipboard* clipboard = QApplication::clipboard();
678 QMimeSource* data = clipboard->data();
679 if (!KUrlDrag::canDecode(data)) {
680 return;
681 }
682
683 clearStatusBar();
684
685 KUrl::List sourceUrls;
686 KUrlDrag::decode(data, sourceUrls);
687
688 // per default the pasting is done into the current Url of the view
689 KUrl destUrl(m_activeView->url());
690
691 // check whether the pasting should be done into a selected directory
692 KUrl::List selectedUrls = m_activeView->selectedUrls();
693 if (selectedUrls.count() == 1) {
694 const KFileItem fileItem(S_IFDIR,
695 KFileItem::Unknown,
696 selectedUrls.first(),
697 true);
698 if (fileItem.isDir()) {
699 // only one item is selected which is a directory, hence paste
700 // into this directory
701 destUrl = selectedUrls.first();
702 }
703 }
704
705
706 updateViewProperties(sourceUrls);
707 if (m_clipboardContainsCutData) {
708 moveUrls(sourceUrls, destUrl);
709 m_clipboardContainsCutData = false;
710 clipboard->clear();
711 }
712 else {
713 copyUrls(sourceUrls, destUrl);
714 }*/
715 }
716
717 void DolphinMainWindow::updatePasteAction()
718 {
719 QAction* pasteAction = actionCollection()->action(KStdAction::stdName(KStdAction::Paste));
720 if (pasteAction == 0) {
721 return;
722 }
723
724 QString text(i18n("Paste"));
725 QClipboard* clipboard = QApplication::clipboard();
726 const QMimeData* data = clipboard->mimeData();
727 /* KDE4-TODO:
728 if (KUrlDrag::canDecode(data)) {
729 pasteAction->setEnabled(true);
730
731 KUrl::List urls;
732 KUrlDrag::decode(data, urls);
733 const int count = urls.count();
734 if (count == 1) {
735 pasteAction->setText(i18n("Paste 1 File"));
736 }
737 else {
738 pasteAction->setText(i18n("Paste %1 Files").arg(count));
739 }
740 }
741 else {*/
742 pasteAction->setEnabled(false);
743 pasteAction->setText(i18n("Paste"));
744 //}
745
746 if (pasteAction->isEnabled()) {
747 KUrl::List urls = m_activeView->selectedUrls();
748 const uint count = urls.count();
749 if (count > 1) {
750 // pasting should not be allowed when more than one file
751 // is selected
752 pasteAction->setEnabled(false);
753 }
754 else if (count == 1) {
755 // Only one file is selected. Pasting is only allowed if this
756 // file is a directory.
757 // TODO: this doesn't work with remote protocols; instead we need a
758 // m_activeView->selectedFileItems() to get the real KFileItems
759 const KFileItem fileItem(S_IFDIR,
760 KFileItem::Unknown,
761 urls.first(),
762 true);
763 pasteAction->setEnabled(fileItem.isDir());
764 }
765 }
766 }
767
768 void DolphinMainWindow::selectAll()
769 {
770 clearStatusBar();
771 m_activeView->selectAll();
772 }
773
774 void DolphinMainWindow::invertSelection()
775 {
776 clearStatusBar();
777 m_activeView->invertSelection();
778 }
779 void DolphinMainWindow::setIconsView()
780 {
781 m_activeView->setMode(DolphinView::IconsView);
782 }
783
784 void DolphinMainWindow::setDetailsView()
785 {
786 m_activeView->setMode(DolphinView::DetailsView);
787 }
788
789 void DolphinMainWindow::setPreviewsView()
790 {
791 m_activeView->setMode(DolphinView::PreviewsView);
792 }
793
794 void DolphinMainWindow::sortByName()
795 {
796 m_activeView->setSorting(DolphinView::SortByName);
797 }
798
799 void DolphinMainWindow::sortBySize()
800 {
801 m_activeView->setSorting(DolphinView::SortBySize);
802 }
803
804 void DolphinMainWindow::sortByDate()
805 {
806 m_activeView->setSorting(DolphinView::SortByDate);
807 }
808
809 void DolphinMainWindow::toggleSortOrder()
810 {
811 const Qt::SortOrder order = (m_activeView->sortOrder() == Qt::Ascending) ?
812 Qt::Descending :
813 Qt::Ascending;
814 m_activeView->setSortOrder(order);
815 }
816
817 void DolphinMainWindow::toggleSplitView()
818 {
819 if (m_view[SecondaryIdx] == 0) {
820 const int newWidth = (m_view[PrimaryIdx]->width() - m_splitter->handleWidth()) / 2;
821 // create a secondary view
822 m_view[SecondaryIdx] = new DolphinView(this,
823 0,
824 m_view[PrimaryIdx]->url(),
825 m_view[PrimaryIdx]->mode(),
826 m_view[PrimaryIdx]->isShowHiddenFilesEnabled());
827 connectViewSignals(SecondaryIdx);
828 m_splitter->addWidget(m_view[SecondaryIdx]);
829 m_splitter->setSizes(QList<int>() << newWidth << newWidth);
830 m_view[SecondaryIdx]->show();
831 }
832 else {
833 // remove secondary view
834 if (m_activeView == m_view[PrimaryIdx]) {
835 m_view[SecondaryIdx]->close();
836 m_view[SecondaryIdx]->deleteLater();
837 m_view[SecondaryIdx] = 0;
838 setActiveView(m_view[PrimaryIdx]);
839 }
840 else {
841 // The secondary view is active, hence from the users point of view
842 // the content of the secondary view should be moved to the primary view.
843 // From an implementation point of view it is more efficient to close
844 // the primary view and exchange the internal pointers afterwards.
845 m_view[PrimaryIdx]->close();
846 delete m_view[PrimaryIdx];
847 m_view[PrimaryIdx] = m_view[SecondaryIdx];
848 m_view[SecondaryIdx] = 0;
849 setActiveView(m_view[PrimaryIdx]);
850 }
851 }
852 }
853
854 void DolphinMainWindow::reloadView()
855 {
856 clearStatusBar();
857 m_activeView->reload();
858 }
859
860 void DolphinMainWindow::stopLoading()
861 {
862 }
863
864 void DolphinMainWindow::showHiddenFiles()
865 {
866 clearStatusBar();
867
868 const KToggleAction* showHiddenFilesAction =
869 static_cast<KToggleAction*>(actionCollection()->action("show_hidden_files"));
870 const bool show = showHiddenFilesAction->isChecked();
871 m_activeView->setShowHiddenFilesEnabled(show);
872 }
873
874 void DolphinMainWindow::showFilterBar()
875 {
876 const KToggleAction* showFilterBarAction =
877 static_cast<KToggleAction*>(actionCollection()->action("show_filter_bar"));
878 const bool show = showFilterBarAction->isChecked();
879 m_activeView->slotShowFilterBar(show);
880 }
881
882 void DolphinMainWindow::zoomIn()
883 {
884 m_activeView->zoomIn();
885 updateViewActions();
886 }
887
888 void DolphinMainWindow::zoomOut()
889 {
890 m_activeView->zoomOut();
891 updateViewActions();
892 }
893
894 void DolphinMainWindow::toggleEditLocation()
895 {
896 clearStatusBar();
897
898 KToggleAction* action = static_cast<KToggleAction*>(actionCollection()->action("editable_location"));
899
900 bool editOrBrowse = action->isChecked();
901 // action->setChecked(action->setChecked);
902 m_activeView->setUrlEditable(editOrBrowse);
903 }
904
905 void DolphinMainWindow::editLocation()
906 {
907 KToggleAction* action = static_cast<KToggleAction*>(actionCollection()->action("editable_location"));
908 action->setChecked(true);
909 m_activeView->setUrlEditable(true);
910 }
911
912 void DolphinMainWindow::adjustViewProperties()
913 {
914 clearStatusBar();
915 ViewPropertiesDialog dlg(m_activeView);
916 dlg.exec();
917 }
918
919 void DolphinMainWindow::goBack()
920 {
921 clearStatusBar();
922 m_activeView->goBack();
923 }
924
925 void DolphinMainWindow::goForward()
926 {
927 clearStatusBar();
928 m_activeView->goForward();
929 }
930
931 void DolphinMainWindow::goUp()
932 {
933 clearStatusBar();
934 m_activeView->goUp();
935 }
936
937 void DolphinMainWindow::goHome()
938 {
939 clearStatusBar();
940 m_activeView->goHome();
941 }
942
943 void DolphinMainWindow::openTerminal()
944 {
945 QString command("konsole --workdir \"");
946 command.append(m_activeView->url().path());
947 command.append('\"');
948
949 KRun::runCommand(command, "Konsole", "konsole");
950 }
951
952 void DolphinMainWindow::findFile()
953 {
954 KRun::run("kfind", m_activeView->url());
955 }
956
957 void DolphinMainWindow::compareFiles()
958 {
959 // The method is only invoked if exactly 2 files have
960 // been selected. The selected files may be:
961 // - both in the primary view
962 // - both in the secondary view
963 // - one in the primary view and the other in the secondary
964 // view
965 assert(m_view[PrimaryIdx] != 0);
966
967 KUrl urlA;
968 KUrl urlB;
969 KUrl::List urls = m_view[PrimaryIdx]->selectedUrls();
970
971 switch (urls.count()) {
972 case 0: {
973 assert(m_view[SecondaryIdx] != 0);
974 urls = m_view[SecondaryIdx]->selectedUrls();
975 assert(urls.count() == 2);
976 urlA = urls[0];
977 urlB = urls[1];
978 break;
979 }
980
981 case 1: {
982 urlA = urls[0];
983 assert(m_view[SecondaryIdx] != 0);
984 urls = m_view[SecondaryIdx]->selectedUrls();
985 assert(urls.count() == 1);
986 urlB = urls[0];
987 break;
988 }
989
990 case 2: {
991 urlA = urls[0];
992 urlB = urls[1];
993 break;
994 }
995
996 default: {
997 // may not happen: compareFiles may only get invoked if 2
998 // files are selected
999 assert(false);
1000 }
1001 }
1002
1003 QString command("kompare -c \"");
1004 command.append(urlA.pathOrUrl());
1005 command.append("\" \"");
1006 command.append(urlB.pathOrUrl());
1007 command.append('\"');
1008 KRun::runCommand(command, "Kompare", "kompare");
1009
1010 }
1011
1012 void DolphinMainWindow::editSettings()
1013 {
1014 // TODO: make a static method for opening the settings dialog
1015 DolphinSettingsDialog dlg(this);
1016 dlg.exec();
1017 }
1018
1019 void DolphinMainWindow::addUndoOperation(KJob* job)
1020 {
1021 if (job->error() != 0) {
1022 slotHandleJobError(job);
1023 }
1024 else {
1025 const int id = job->progressId();
1026
1027 // set iterator to the executed command with the current id...
1028 Q3ValueList<UndoInfo>::Iterator it = m_pendingUndoJobs.begin();
1029 const Q3ValueList<UndoInfo>::Iterator end = m_pendingUndoJobs.end();
1030 bool found = false;
1031 while (!found && (it != end)) {
1032 if ((*it).id == id) {
1033 found = true;
1034 }
1035 else {
1036 ++it;
1037 }
1038 }
1039
1040 if (found) {
1041 DolphinCommand command = (*it).command;
1042 if (command.type() == DolphinCommand::Trash) {
1043 // To be able to perform an undo for the 'Move to Trash' operation
1044 // all source Urls must be updated with the trash Url. E. g. when moving
1045 // a file "test.txt" and a second file "test.txt" to the trash,
1046 // then the filenames in the trash are "0-test.txt" and "1-test.txt".
1047 QMap<QString, QString> metaData;
1048 KIO::Job *kiojob = qobject_cast<KIO::Job*>( job );
1049 if ( kiojob )
1050 {
1051 metaData = kiojob->metaData();
1052 }
1053 KUrl::List newSourceUrls;
1054
1055 KUrl::List sourceUrls = command.source();
1056 KUrl::List::Iterator sourceIt = sourceUrls.begin();
1057 const KUrl::List::Iterator sourceEnd = sourceUrls.end();
1058
1059 while (sourceIt != sourceEnd) {
1060 QMap<QString, QString>::ConstIterator metaIt = metaData.find("trashUrl-" + (*sourceIt).path());
1061 if (metaIt != metaData.end()) {
1062 newSourceUrls.append(KUrl(metaIt.value()));
1063 }
1064 ++sourceIt;
1065 }
1066 command.setSource(newSourceUrls);
1067 }
1068
1069 UndoManager::instance().addCommand(command);
1070 m_pendingUndoJobs.erase(it);
1071
1072 DolphinStatusBar* statusBar = m_activeView->statusBar();
1073 switch (command.type()) {
1074 case DolphinCommand::Copy:
1075 statusBar->setMessage(i18n("Copy operation completed."),
1076 DolphinStatusBar::OperationCompleted);
1077 break;
1078 case DolphinCommand::Move:
1079 statusBar->setMessage(i18n("Move operation completed."),
1080 DolphinStatusBar::OperationCompleted);
1081 break;
1082 case DolphinCommand::Trash:
1083 statusBar->setMessage(i18n("Move to trash operation completed."),
1084 DolphinStatusBar::OperationCompleted);
1085 break;
1086 default:
1087 break;
1088 }
1089 }
1090 }
1091 }
1092
1093 void DolphinMainWindow::init()
1094 {
1095 // Check whether Dolphin runs the first time. If yes then
1096 // a proper default window size is given at the end of DolphinMainWindow::init().
1097 GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings();
1098 const bool firstRun = generalSettings->firstRun();
1099
1100 setAcceptDrops(true);
1101
1102 m_splitter = new QSplitter(this);
1103
1104 DolphinSettings& settings = DolphinSettings::instance();
1105
1106 KBookmarkManager* manager = settings.bookmarkManager();
1107 assert(manager != 0);
1108 KBookmarkGroup root = manager->root();
1109 if (root.first().isNull()) {
1110 root.addBookmark(manager, i18n("Home"), settings.generalSettings()->homeUrl(), "folder_home");
1111 root.addBookmark(manager, i18n("Storage Media"), KUrl("media:/"), "blockdevice");
1112 root.addBookmark(manager, i18n("Network"), KUrl("remote:/"), "network_local");
1113 root.addBookmark(manager, i18n("Root"), KUrl("/"), "folder_red");
1114 root.addBookmark(manager, i18n("Trash"), KUrl("trash:/"), "trashcan_full");
1115 }
1116
1117 setupActions();
1118
1119 const KUrl& homeUrl = root.first().url();
1120 setCaption(homeUrl.fileName());
1121 ViewProperties props(homeUrl);
1122 m_view[PrimaryIdx] = new DolphinView(this,
1123 m_splitter,
1124 homeUrl,
1125 props.viewMode(),
1126 props.isShowHiddenFilesEnabled());
1127 connectViewSignals(PrimaryIdx);
1128 m_view[PrimaryIdx]->show();
1129
1130 m_activeView = m_view[PrimaryIdx];
1131
1132 setCentralWidget(m_splitter);
1133 setupDockWidgets();
1134
1135 setupGUI(Keys|Save|Create|ToolBar);
1136 createGUI();
1137
1138 stateChanged("new_file");
1139 setAutoSaveSettings();
1140
1141 QClipboard* clipboard = QApplication::clipboard();
1142 connect(clipboard, SIGNAL(dataChanged()),
1143 this, SLOT(updatePasteAction()));
1144 updatePasteAction();
1145 updateGoActions();
1146
1147 setupCreateNewMenuActions();
1148
1149 loadSettings();
1150
1151 if (firstRun) {
1152 // assure a proper default size if Dolphin runs the first time
1153 resize(640, 480);
1154 }
1155 }
1156
1157 void DolphinMainWindow::loadSettings()
1158 {
1159 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
1160
1161 KToggleAction* splitAction = static_cast<KToggleAction*>(actionCollection()->action("split_view"));
1162 if (settings->splitView()) {
1163 splitAction->setChecked(true);
1164 toggleSplitView();
1165 }
1166
1167 updateViewActions();
1168 }
1169
1170 void DolphinMainWindow::setupActions()
1171 {
1172 // setup 'File' menu
1173 KAction *action = new KAction(KIcon("window_new"), i18n( "New &Window" ), actionCollection(), "new_window" );
1174 connect(action, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1175
1176 KAction* createFolder = new KAction(i18n("Folder..."), actionCollection(), "create_folder");
1177 createFolder->setIcon(KIcon("folder"));
1178 createFolder->setShortcut(Qt::Key_N);
1179 connect(createFolder, SIGNAL(triggered()), this, SLOT(createFolder()));
1180
1181 KAction* rename = new KAction(i18n("Rename"), actionCollection(), "rename");
1182 rename->setShortcut(Qt::Key_F2);
1183 connect(rename, SIGNAL(triggered()), this, SLOT(rename()));
1184
1185 KAction* moveToTrash = new KAction(i18n("Move to Trash"), actionCollection(), "move_to_trash");
1186 moveToTrash->setIcon(KIcon("edittrash"));
1187 moveToTrash->setShortcut(QKeySequence::Delete);
1188 connect(moveToTrash, SIGNAL(triggered()), this, SLOT(moveToTrash()));
1189
1190 KAction* deleteAction = new KAction(i18n("Delete"), actionCollection(), "delete");
1191 deleteAction->setShortcut(Qt::ALT | Qt::Key_Delete);
1192 deleteAction->setIcon(KIcon("editdelete"));
1193 connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItems()));
1194
1195 KAction* properties = new KAction(i18n("Propert&ies"), actionCollection(), "properties");
1196 properties->setShortcut(Qt::Key_Alt | Qt::Key_Return);
1197 connect(properties, SIGNAL(triggered()), this, SLOT(properties()));
1198
1199 KStdAction::quit(this, SLOT(quit()), actionCollection());
1200
1201 // setup 'Edit' menu
1202 UndoManager& undoManager = UndoManager::instance();
1203 KStdAction::undo(this,
1204 SLOT(undo()),
1205 actionCollection());
1206 connect(&undoManager, SIGNAL(undoAvailable(bool)),
1207 this, SLOT(slotUndoAvailable(bool)));
1208 connect(&undoManager, SIGNAL(undoTextChanged(const QString&)),
1209 this, SLOT(slotUndoTextChanged(const QString&)));
1210
1211 KStdAction::redo(this,
1212 SLOT(redo()),
1213 actionCollection());
1214 connect(&undoManager, SIGNAL(redoAvailable(bool)),
1215 this, SLOT(slotRedoAvailable(bool)));
1216 connect(&undoManager, SIGNAL(redoTextChanged(const QString&)),
1217 this, SLOT(slotRedoTextChanged(const QString&)));
1218
1219 KStdAction::cut(this, SLOT(cut()), actionCollection());
1220 KStdAction::copy(this, SLOT(copy()), actionCollection());
1221 KStdAction::paste(this, SLOT(paste()), actionCollection());
1222
1223 KAction* selectAll = new KAction(i18n("Select All"), actionCollection(), "select_all");
1224 selectAll->setShortcut(Qt::CTRL + Qt::Key_A);
1225 connect(selectAll, SIGNAL(triggered()), this, SLOT(selectAll()));
1226
1227 KAction* invertSelection = new KAction(i18n("Invert Selection"), actionCollection(), "invert_selection");
1228 invertSelection->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_A);
1229 connect(invertSelection, SIGNAL(triggered()), this, SLOT(invertSelection()));
1230
1231 // setup 'View' menu
1232 KStdAction::zoomIn(this,
1233 SLOT(zoomIn()),
1234 actionCollection());
1235
1236 KStdAction::zoomOut(this,
1237 SLOT(zoomOut()),
1238 actionCollection());
1239
1240 KToggleAction* iconsView = new KToggleAction(i18n("Icons"), actionCollection(), "icons");
1241 iconsView->setShortcut(Qt::CTRL | Qt::Key_1);
1242 iconsView->setIcon(KIcon("view_icon"));
1243 connect(iconsView, SIGNAL(triggered()), this, SLOT(setIconsView()));
1244
1245 KToggleAction* detailsView = new KToggleAction(i18n("Details"), actionCollection(), "details");
1246 detailsView->setShortcut(Qt::CTRL | Qt::Key_2);
1247 detailsView->setIcon(KIcon("view_text"));
1248 connect(detailsView, SIGNAL(triggered()), this, SLOT(setDetailsView()));
1249
1250 KToggleAction* previewsView = new KToggleAction(i18n("Previews"), actionCollection(), "previews");
1251 previewsView->setShortcut(Qt::CTRL | Qt::Key_3);
1252 previewsView->setIcon(KIcon("gvdirpart"));
1253 connect(previewsView, SIGNAL(triggered()), this, SLOT(setPreviewsView()));
1254
1255 QActionGroup* viewModeGroup = new QActionGroup(this);
1256 viewModeGroup->addAction(iconsView);
1257 viewModeGroup->addAction(detailsView);
1258 viewModeGroup->addAction(previewsView);
1259
1260 KToggleAction* sortByName = new KToggleAction(i18n("By Name"), actionCollection(), "by_name");
1261 connect(sortByName, SIGNAL(triggered()), this, SLOT(sortByName()));
1262
1263 KToggleAction* sortBySize = new KToggleAction(i18n("By Size"), actionCollection(), "by_size");
1264 connect(sortBySize, SIGNAL(triggered()), this, SLOT(sortBySize()));
1265
1266 KToggleAction* sortByDate = new KToggleAction(i18n("By Date"), actionCollection(), "by_date");
1267 connect(sortByDate, SIGNAL(triggered()), this, SLOT(sortByDate()));
1268
1269 QActionGroup* sortGroup = new QActionGroup(this);
1270 sortGroup->addAction(sortByName);
1271 sortGroup->addAction(sortBySize);
1272 sortGroup->addAction(sortByDate);
1273
1274 KToggleAction* sortDescending = new KToggleAction(i18n("Descending"), actionCollection(), "descending");
1275 connect(sortDescending, SIGNAL(triggered()), this, SLOT(toggleSortOrder()));
1276
1277 KToggleAction* showHiddenFiles = new KToggleAction(i18n("Show Hidden Files"), actionCollection(), "show_hidden_files");
1278 //showHiddenFiles->setShortcut(Qt::ALT | Qt::Key_ KDE4-TODO: what Qt-Key represents '.'?
1279 connect(showHiddenFiles, SIGNAL(triggered()), this, SLOT(showHiddenFiles()));
1280
1281 KToggleAction* split = new KToggleAction(i18n("Split View"), actionCollection(), "split_view");
1282 split->setShortcut(Qt::Key_F10);
1283 split->setIcon(KIcon("view_left_right"));
1284 connect(split, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1285
1286 KAction* reload = new KAction(i18n("Reload"), "F5", actionCollection(), "reload");
1287 reload->setShortcut(Qt::Key_F5);
1288 reload->setIcon(KIcon("reload"));
1289 connect(reload, SIGNAL(triggered()), this, SLOT(reloadView()));
1290
1291 KAction* stop = new KAction(i18n("Stop"), actionCollection(), "stop");
1292 stop->setIcon(KIcon("stop"));
1293 connect(stop, SIGNAL(triggered()), this, SLOT(stopLoading()));
1294
1295 KToggleAction* showFullLocation = new KToggleAction(i18n("Show Full Location"), actionCollection(), "editable_location");
1296 showFullLocation->setShortcut(Qt::CTRL | Qt::Key_L);
1297 connect(showFullLocation, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1298
1299 KToggleAction* editLocation = new KToggleAction(i18n("Edit Location"), actionCollection(), "edit_location");
1300 editLocation->setShortcut(Qt::Key_F6);
1301 connect(editLocation, SIGNAL(triggered()), this, SLOT(editLocation()));
1302
1303 KAction* adjustViewProps = new KAction(i18n("Adjust View Properties..."), actionCollection(), "view_properties");
1304 connect(adjustViewProps, SIGNAL(triggered()), this, SLOT(adjustViewProperties()));
1305
1306 // setup 'Go' menu
1307 KStdAction::back(this, SLOT(goBack()), actionCollection());
1308 KStdAction::forward(this, SLOT(goForward()), actionCollection());
1309 KStdAction::up(this, SLOT(goUp()), actionCollection());
1310 KStdAction::home(this, SLOT(goHome()), actionCollection());
1311
1312 // setup 'Tools' menu
1313 KAction* openTerminal = new KAction(i18n("Open Terminal"), actionCollection(), "open_terminal");
1314 openTerminal->setShortcut(Qt::Key_F4);
1315 openTerminal->setIcon(KIcon("konsole"));
1316 connect(openTerminal, SIGNAL(triggered()), this, SLOT(openTerminal()));
1317
1318 KAction* findFile = new KAction(i18n("Find File..."), actionCollection(), "find_file");
1319 findFile->setShortcut(Qt::Key_F);
1320 findFile->setIcon(KIcon("filefind"));
1321 connect(findFile, SIGNAL(triggered()), this, SLOT(findFile()));
1322
1323 KToggleAction* showFilterBar = new KToggleAction(i18n("Show Filter Bar"), actionCollection(), "show_filter_bar");
1324 showFilterBar->setShortcut(Qt::Key_Slash);
1325 connect(showFilterBar, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1326
1327 KAction* compareFiles = new KAction(i18n("Compare Files"), actionCollection(), "compare_files");
1328 compareFiles->setIcon(KIcon("kompare"));
1329 compareFiles->setEnabled(false);
1330 connect(compareFiles, SIGNAL(triggered()), this, SLOT(compareFiles()));
1331
1332 // setup 'Settings' menu
1333 KStdAction::preferences(this, SLOT(editSettings()), actionCollection());
1334 }
1335
1336 void DolphinMainWindow::setupDockWidgets()
1337 {
1338 QDockWidget *shortcutsDock = new QDockWidget(i18n("Shortcuts"));
1339
1340 shortcutsDock->setObjectName("shortcutsDock");
1341 shortcutsDock->setWidget(new BookmarksSidebarPage(this));
1342
1343 shortcutsDock->toggleViewAction()->setObjectName("show_shortcuts_pane");
1344 shortcutsDock->toggleViewAction()->setText(i18n("Show Shortcuts Panel"));
1345 actionCollection()->insert(shortcutsDock->toggleViewAction());
1346
1347 addDockWidget(Qt::LeftDockWidgetArea, shortcutsDock);
1348
1349 QDockWidget *infoDock = new QDockWidget(i18n("Information"));
1350
1351 infoDock->setObjectName("infoDock");
1352 infoDock->setWidget(new InfoSidebarPage(this));
1353
1354 infoDock->toggleViewAction()->setObjectName("show_info_pane");
1355 infoDock->toggleViewAction()->setText(i18n("Show Information Panel"));
1356 actionCollection()->insert(infoDock->toggleViewAction());
1357
1358 addDockWidget(Qt::RightDockWidgetArea, infoDock);
1359 }
1360
1361 void DolphinMainWindow::setupCreateNewMenuActions()
1362 {
1363 // Parts of the following code have been taken
1364 // from the class KNewMenu located in
1365 // libqonq/knewmenu.h of Konqueror.
1366 // Copyright (C) 1998, 1999 David Faure <faure@kde.org>
1367 // 2003 Sven Leiber <s.leiber@web.de>
1368
1369 QStringList files = actionCollection()->instance()->dirs()->findAllResources("templates");
1370 for (QStringList::Iterator it = files.begin() ; it != files.end(); ++it) {
1371 if ((*it)[0] != '.' ) {
1372 KSimpleConfig config(*it, true);
1373 config.setDesktopGroup();
1374
1375 // tricky solution to ensure that TextFile is at the beginning
1376 // because this filetype is the most used (according kde-core discussion)
1377 const QString name(config.readEntry("Name"));
1378 QString key(name);
1379
1380 const QString path(config.readPathEntry("Url"));
1381 if (!path.endsWith("emptydir")) {
1382 if (path.endsWith("TextFile.txt")) {
1383 key = "1" + key;
1384 }
1385 else if (!KDesktopFile::isDesktopFile(path)) {
1386 key = "2" + key;
1387 }
1388 else if (path.endsWith("Url.desktop")){
1389 key = "3" + key;
1390 }
1391 else if (path.endsWith("Program.desktop")){
1392 key = "4" + key;
1393 }
1394 else {
1395 key = "5";
1396 }
1397
1398 const QString icon(config.readEntry("Icon"));
1399 const QString comment(config.readEntry("Comment"));
1400 const QString type(config.readEntry("Type"));
1401
1402 const QString filePath(*it);
1403
1404
1405 if (type == "Link") {
1406 CreateFileEntry entry;
1407 entry.name = name;
1408 entry.icon = icon;
1409 entry.comment = comment;
1410 entry.templatePath = filePath;
1411 m_createFileTemplates.insert(key, entry);
1412 }
1413 }
1414 }
1415 }
1416 m_createFileTemplates.sort();
1417
1418 unplugActionList("create_actions");
1419 KSortableList<CreateFileEntry, QString>::ConstIterator it = m_createFileTemplates.begin();
1420 KSortableList<CreateFileEntry, QString>::ConstIterator end = m_createFileTemplates.end();
1421 /* KDE4-TODO: don't port this code; use KNewMenu instead
1422 while (it != end) {
1423 CreateFileEntry entry = (*it).value();
1424 KAction* action = new KAction(entry.name);
1425 action->setIcon(entry.icon);
1426 action->setName((*it).index());
1427 connect(action, SIGNAL(activated()),
1428 this, SLOT(createFile()));
1429
1430 const QChar section = ((*it).index()[0]);
1431 switch (section) {
1432 case '1':
1433 case '2': {
1434 m_fileGroupActions.append(action);
1435 break;
1436 }
1437
1438 case '3':
1439 case '4': {
1440 // TODO: not used yet. See documentation of DolphinMainWindow::linkGroupActions()
1441 // and DolphinMainWindow::linkToDeviceActions() in the header file for details.
1442 //m_linkGroupActions.append(action);
1443 break;
1444 }
1445
1446 case '5': {
1447 // TODO: not used yet. See documentation of DolphinMainWindow::linkGroupActions()
1448 // and DolphinMainWindow::linkToDeviceActions() in the header file for details.
1449 //m_linkToDeviceActions.append(action);
1450 break;
1451 }
1452 default:
1453 break;
1454 }
1455 ++it;
1456 }
1457
1458 plugActionList("create_file_group", m_fileGroupActions);
1459 //plugActionList("create_link_group", m_linkGroupActions);
1460 //plugActionList("link_to_device", m_linkToDeviceActions);*/
1461 }
1462
1463 void DolphinMainWindow::updateHistory()
1464 {
1465 int index = 0;
1466 const Q3ValueList<UrlNavigator::HistoryElem> list = m_activeView->urlHistory(index);
1467
1468 QAction* backAction = actionCollection()->action("go_back");
1469 if (backAction != 0) {
1470 backAction->setEnabled(index < static_cast<int>(list.count()) - 1);
1471 }
1472
1473 QAction* forwardAction = actionCollection()->action("go_forward");
1474 if (forwardAction != 0) {
1475 forwardAction->setEnabled(index > 0);
1476 }
1477 }
1478
1479 void DolphinMainWindow::updateEditActions()
1480 {
1481 const KFileItemList list = m_activeView->selectedItems();
1482 if (list.isEmpty()) {
1483 stateChanged("has_no_selection");
1484 }
1485 else {
1486 stateChanged("has_selection");
1487
1488 QAction* renameAction = actionCollection()->action("rename");
1489 if (renameAction != 0) {
1490 renameAction->setEnabled(list.count() >= 1);
1491 }
1492
1493 bool enableMoveToTrash = true;
1494
1495 KFileItemList::const_iterator it = list.begin();
1496 const KFileItemList::const_iterator end = list.end();
1497 while (it != end) {
1498 KFileItem* item = *it;
1499 const KUrl& url = item->url();
1500 // only enable the 'Move to Trash' action for local files
1501 if (!url.isLocalFile()) {
1502 enableMoveToTrash = false;
1503 }
1504 ++it;
1505 }
1506
1507 QAction* moveToTrashAction = actionCollection()->action("move_to_trash");
1508 moveToTrashAction->setEnabled(enableMoveToTrash);
1509 }
1510 updatePasteAction();
1511 }
1512
1513 void DolphinMainWindow::updateViewActions()
1514 {
1515 QAction* zoomInAction = actionCollection()->action(KStdAction::stdName(KStdAction::ZoomIn));
1516 if (zoomInAction != 0) {
1517 zoomInAction->setEnabled(m_activeView->isZoomInPossible());
1518 }
1519
1520 QAction* zoomOutAction = actionCollection()->action(KStdAction::stdName(KStdAction::ZoomOut));
1521 if (zoomOutAction != 0) {
1522 zoomOutAction->setEnabled(m_activeView->isZoomOutPossible());
1523 }
1524
1525 QAction* action = 0;
1526 switch (m_activeView->mode()) {
1527 case DolphinView::IconsView:
1528 action = actionCollection()->action("icons");
1529 break;
1530 case DolphinView::DetailsView:
1531 action = actionCollection()->action("details");
1532 break;
1533 case DolphinView::PreviewsView:
1534 action = actionCollection()->action("previews");
1535 break;
1536 default:
1537 break;
1538 }
1539
1540 if (action != 0) {
1541 KToggleAction* toggleAction = static_cast<KToggleAction*>(action);
1542 toggleAction->setChecked(true);
1543 }
1544
1545 slotSortingChanged(m_activeView->sorting());
1546 slotSortOrderChanged(m_activeView->sortOrder());
1547
1548 KToggleAction* showFilterBarAction =
1549 static_cast<KToggleAction*>(actionCollection()->action("show_filter_bar"));
1550 showFilterBarAction->setChecked(m_activeView->isFilterBarVisible());
1551
1552 KToggleAction* showHiddenFilesAction =
1553 static_cast<KToggleAction*>(actionCollection()->action("show_hidden_files"));
1554 showHiddenFilesAction->setChecked(m_activeView->isShowHiddenFilesEnabled());
1555
1556 KToggleAction* splitAction = static_cast<KToggleAction*>(actionCollection()->action("split_view"));
1557 splitAction->setChecked(m_view[SecondaryIdx] != 0);
1558 }
1559
1560 void DolphinMainWindow::updateGoActions()
1561 {
1562 QAction* goUpAction = actionCollection()->action(KStdAction::stdName(KStdAction::Up));
1563 const KUrl& currentUrl = m_activeView->url();
1564 goUpAction->setEnabled(currentUrl.upUrl() != currentUrl);
1565 }
1566
1567 void DolphinMainWindow::updateViewProperties(const KUrl::List& urls)
1568 {
1569 if (urls.isEmpty()) {
1570 return;
1571 }
1572
1573 // Updating the view properties might take up to several seconds
1574 // when dragging several thousand Urls. Writing a KIO slave for this
1575 // use case is not worth the effort, but at least the main widget
1576 // must be disabled and a progress should be shown.
1577 ProgressIndicator progressIndicator(this,
1578 i18n("Updating view properties..."),
1579 QString::null,
1580 urls.count());
1581
1582 KUrl::List::ConstIterator end = urls.end();
1583 for(KUrl::List::ConstIterator it = urls.begin(); it != end; ++it) {
1584 progressIndicator.execOperation();
1585
1586 ViewProperties props(*it);
1587 props.save();
1588 }
1589 }
1590
1591 void DolphinMainWindow::copyUrls(const KUrl::List& source, const KUrl& dest)
1592 {
1593 KIO::Job* job = KIO::copy(source, dest);
1594 addPendingUndoJob(job, DolphinCommand::Copy, source, dest);
1595 }
1596
1597 void DolphinMainWindow::moveUrls(const KUrl::List& source, const KUrl& dest)
1598 {
1599 KIO::Job* job = KIO::move(source, dest);
1600 addPendingUndoJob(job, DolphinCommand::Move, source, dest);
1601 }
1602
1603 void DolphinMainWindow::addPendingUndoJob(KIO::Job* job,
1604 DolphinCommand::Type commandType,
1605 const KUrl::List& source,
1606 const KUrl& dest)
1607 {
1608 connect(job, SIGNAL(result(KJob*)),
1609 this, SLOT(addUndoOperation(KJob*)));
1610
1611 UndoInfo undoInfo;
1612 undoInfo.id = job->progressId();
1613 undoInfo.command = DolphinCommand(commandType, source, dest);
1614 m_pendingUndoJobs.append(undoInfo);
1615 }
1616
1617 void DolphinMainWindow::clearStatusBar()
1618 {
1619 m_activeView->statusBar()->clear();
1620 }
1621
1622 void DolphinMainWindow::connectViewSignals(int viewIndex)
1623 {
1624 DolphinView* view = m_view[viewIndex];
1625 connect(view, SIGNAL(modeChanged()),
1626 this, SLOT(slotViewModeChanged()));
1627 connect(view, SIGNAL(showHiddenFilesChanged()),
1628 this, SLOT(slotShowHiddenFilesChanged()));
1629 connect(view, SIGNAL(sortingChanged(DolphinView::Sorting)),
1630 this, SLOT(slotSortingChanged(DolphinView::Sorting)));
1631 connect(view, SIGNAL(sortOrderChanged(Qt::SortOrder)),
1632 this, SLOT(slotSortOrderChanged(Qt::SortOrder)));
1633 connect(view, SIGNAL(selectionChanged()),
1634 this, SLOT(slotSelectionChanged()));
1635 connect(view, SIGNAL(showFilterBarChanged(bool)),
1636 this, SLOT(updateFilterBarAction(bool)));
1637
1638 const UrlNavigator* navigator = view->urlNavigator();
1639 connect(navigator, SIGNAL(urlChanged(const KUrl&)),
1640 this, SLOT(slotUrlChanged(const KUrl&)));
1641 connect(navigator, SIGNAL(historyChanged()),
1642 this, SLOT(slotHistoryChanged()));
1643
1644 }
1645
1646 #include "dolphinmainwindow.moc"