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