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