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