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