From f31a541925033c2ef5e27b85c099d47791b50121 Mon Sep 17 00:00:00 2001 From: Holger Freyther Date: Wed, 29 Nov 2006 00:02:19 +0000 Subject: Make it (almost) possible to have more than one Dolphin KMainWindow Create a DolphinApplication, holding DolphinMainWindows and update the code to use the DolphinView to get the MainWindow, or get a ptr to the MainWindow directly. Or if all windows are effected go through the DolphinApplication to update every mainwindow. The UndowManager and ProgressIndicator have a rather strange relationship and will need some more attention but as UndoManager will be killed anyway I have skipped this. More cleanup, debugging and thinking is needed. svn path=/trunk/playground/utils/dolphin/; revision=608945 --- src/CMakeLists.txt | 3 +- src/THOUGHTS.zecke | 36 + src/bookmarkselector.cpp | 6 +- src/bookmarkssidebarpage.cpp | 13 +- src/bookmarkssidebarpage.h | 2 +- src/dolphin.cpp | 1655 ---------------------------------------- src/dolphin.h | 456 ------------ src/dolphinapplication.cpp | 64 ++ src/dolphinapplication.h | 64 ++ src/dolphincontextmenu.cpp | 38 +- src/dolphiniconsview.cpp | 7 +- src/dolphinmainwindow.cpp | 1657 +++++++++++++++++++++++++++++++++++++++++ src/dolphinmainwindow.h | 451 +++++++++++ src/dolphinsettings.cpp | 3 +- src/dolphinsettingsdialog.cpp | 12 +- src/dolphinsettingsdialog.h | 4 +- src/dolphinview.cpp | 57 +- src/dolphinview.h | 22 +- src/filterbar.cpp | 11 +- src/filterbar.h | 4 +- src/generalsettingspage.cpp | 7 +- src/generalsettingspage.h | 4 +- src/infosidebarpage.cpp | 18 +- src/infosidebarpage.h | 2 +- src/main.cpp | 25 +- src/progressindicator.cpp | 19 +- src/progressindicator.h | 7 +- src/sidebar.cpp | 7 +- src/sidebar.h | 4 +- src/sidebarpage.cpp | 13 +- src/sidebarpage.h | 9 +- src/undomanager.cpp | 29 +- src/undomanager.h | 6 +- src/urlbutton.cpp | 4 +- src/urlnavigator.cpp | 4 +- src/urlnavigator.h | 2 +- src/urlnavigatorbutton.cpp | 6 +- 37 files changed, 2481 insertions(+), 2250 deletions(-) create mode 100644 src/THOUGHTS.zecke delete mode 100644 src/dolphin.cpp delete mode 100644 src/dolphin.h create mode 100644 src/dolphinapplication.cpp create mode 100644 src/dolphinapplication.h create mode 100644 src/dolphinmainwindow.cpp create mode 100644 src/dolphinmainwindow.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c701e14a7..7ea5426bb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -9,7 +9,8 @@ include_directories( ${KDE4_INCLUDE_DIR} ${QT_INCLUDES} ) set(dolphin_SRCS main.cpp - dolphin.cpp + dolphinapplication.cpp + dolphinmainwindow.cpp dolphinview.cpp urlnavigator.cpp urlnavigatorbutton.cpp diff --git a/src/THOUGHTS.zecke b/src/THOUGHTS.zecke new file mode 100644 index 000000000..3b9f383fc --- /dev/null +++ b/src/THOUGHTS.zecke @@ -0,0 +1,36 @@ +Zecke's Implementation Thoughts + + +Task: Kill the Dolphin Singleton +Reasoning: Have more than one Dolphin TLW +Approach: + 1. Create DolphinApplication to hold all TLW's. + 2. Make dolphin.h dolphomainwindow.h + 3. Change the Views to have a DolphinMainWindow + parameter + +Reasoning: + I find it more natural that the DolphinApplication + holds and controls the list of managed MainWindows and + will control the life time of them, specially deleting + them on exit. + The downside is that DolphinApplication and DolphinMainWindow + need to work together but this is managable + + Making DolphinView::mainWindow() public. Most users of the + current Dolphin::mainView have a pointer to the current view + already. We could pass a second pointer for the mainwindow each + time but the same can be achieved by using the appropriate + DolphinView::mainWindow. + Another approach would be to ask the DolphinView to execute + actions on the MainWindow like it is done with declareViewActive + in DolphinView. I'm not entirely sure which one wins but currently + using mainWindow() does not show any negative impact. + + 2 times Dolphin::mainWin was used to check if the view is current. + this can be made a method of of the view + + 1 time we want the viewChanged signal of our mainwindow to update, + the UrlNavigator could connect a signal to a signal to allow this + + 12 times this was used to access the actionCollection diff --git a/src/bookmarkselector.cpp b/src/bookmarkselector.cpp index 73e063fda..7b489b8fa 100644 --- a/src/bookmarkselector.cpp +++ b/src/bookmarkselector.cpp @@ -31,7 +31,7 @@ #include "bookmarkselector.h" #include "dolphinsettings.h" #include "dolphinview.h" -#include "dolphin.h" +#include "dolphinmainwindow.h" #include "urlnavigator.h" BookmarkSelector::BookmarkSelector(UrlNavigator* parent) : @@ -134,9 +134,9 @@ void BookmarkSelector::paintEvent(QPaintEvent* event) // dimm the colors if the parent view does not have the focus const DolphinView* parentView = urlNavigator()->dolphinView(); - const Dolphin& dolphin = Dolphin::mainWin(); + const DolphinMainWindow* dolphin = parentView->mainWindow(); - const bool isActive = (dolphin.activeView() == parentView); + const bool isActive = (dolphin->activeView() == parentView); if (!isActive) { QColor dimmColor(colorGroup().background()); foregroundColor = mixColors(foregroundColor, dimmColor); diff --git a/src/bookmarkssidebarpage.cpp b/src/bookmarkssidebarpage.cpp index b3861aa2f..7eced5a01 100644 --- a/src/bookmarkssidebarpage.cpp +++ b/src/bookmarkssidebarpage.cpp @@ -36,12 +36,11 @@ #include #include "dolphinsettings.h" -#include "dolphin.h" -#include "dolphinview.h" +#include "dolphinmainwindow.h" #include "editbookmarkdialog.h" -BookmarksSidebarPage::BookmarksSidebarPage(QWidget* parent) : - SidebarPage(parent) +BookmarksSidebarPage::BookmarksSidebarPage(DolphinMainWindow* mainWindow, QWidget* parent) : + SidebarPage(mainWindow, parent) { Q3VBoxLayout* layout = new Q3VBoxLayout(this); m_bookmarksList = new BookmarksListBox(this); @@ -98,7 +97,7 @@ void BookmarksSidebarPage::slotMouseButtonClicked(int button, Q3ListBoxItem* ite const int index = m_bookmarksList->index(item); KBookmark bookmark = DolphinSettings::instance().bookmark(index); - Dolphin::mainWin().activeView()->setUrl(bookmark.url()); + mainWindow()->activeView()->setUrl(bookmark.url()); } void BookmarksSidebarPage::slotContextMenuRequested(Q3ListBoxItem* item, @@ -187,7 +186,7 @@ void BookmarksSidebarPage::slotContextMenuRequested(Q3ListBoxItem* item, delete popup; popup = 0; - DolphinView* view = Dolphin::mainWin().activeView(); + DolphinView* view = mainWindow()->activeView(); adjustSelection(view->url()); } @@ -241,7 +240,7 @@ void BookmarksSidebarPage::slotUrlChanged(const KUrl& url) void BookmarksSidebarPage::connectToActiveView() { - DolphinView* view = Dolphin::mainWin().activeView(); + DolphinView* view = mainWindow()->activeView(); adjustSelection(view->url()); connect(view, SIGNAL(signalUrlChanged(const KUrl&)), this, SLOT(slotUrlChanged(const KUrl&))); diff --git a/src/bookmarkssidebarpage.h b/src/bookmarkssidebarpage.h index 37a500987..953755399 100644 --- a/src/bookmarkssidebarpage.h +++ b/src/bookmarkssidebarpage.h @@ -41,7 +41,7 @@ class BookmarksSidebarPage : public SidebarPage Q_OBJECT public: - BookmarksSidebarPage(QWidget* parent); + BookmarksSidebarPage(DolphinMainWindow *mainWindow, QWidget* parent); virtual ~BookmarksSidebarPage(); protected: diff --git a/src/dolphin.cpp b/src/dolphin.cpp deleted file mode 100644 index db4f46889..000000000 --- a/src/dolphin.cpp +++ /dev/null @@ -1,1655 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * Copyright (C) 2006 by Stefan Monov * - * Copyright (C) 2006 by Cvetoslav Ludmiloff * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "dolphin.h" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -//Added by qt3to4: -#include -#include -#include - -#include "urlnavigator.h" -#include "viewpropertiesdialog.h" -#include "viewproperties.h" -#include "dolphinsettings.h" -#include "dolphinsettingsdialog.h" -#include "dolphinstatusbar.h" -#include "undomanager.h" -#include "progressindicator.h" -#include "dolphinsettings.h" -#include "sidebar.h" -#include "sidebarsettings.h" -#include "generalsettings.h" - -Dolphin& Dolphin::mainWin() -{ - static Dolphin* instance = 0; - if (instance == 0) { - instance = new Dolphin(); - instance->init(); - } - return *instance; -} - -Dolphin::~Dolphin() -{ -} - -void Dolphin::setActiveView(DolphinView* view) -{ - assert((view == m_view[PrimaryIdx]) || (view == m_view[SecondaryIdx])); - if (m_activeView == view) { - return; - } - - m_activeView = view; - - updateHistory(); - updateEditActions(); - updateViewActions(); - updateGoActions(); - - setCaption(m_activeView->url().fileName()); - - emit activeViewChanged(); -} - -void Dolphin::dropUrls(const KUrl::List& urls, - const KUrl& destination) -{ - int selectedIndex = -1; - - /* KDE4-TODO - const ButtonState keyboardState = KApplication::keyboardMouseState(); - const bool shiftPressed = (keyboardState & ShiftButton) > 0; - const bool controlPressed = (keyboardState & ControlButton) > 0; - - - - if (shiftPressed && controlPressed) { - // shortcut for 'Linke Here' is used - selectedIndex = 2; - } - else if (controlPressed) { - // shortcut for 'Copy Here' is used - selectedIndex = 1; - } - else if (shiftPressed) { - // shortcut for 'Move Here' is used - selectedIndex = 0; - } - else*/ { - // no shortcut is used, hence open a popup menu - KMenu popup(this); - - popup.insertItem(SmallIcon("goto"), i18n("&Move Here") + "\t" /* KDE4-TODO: + KKey::modFlagLabel(KKey::SHIFT)*/, 0); - popup.insertItem(SmallIcon("editcopy"), i18n( "&Copy Here" ) /* KDE4-TODO + "\t" + KKey::modFlagLabel(KKey::CTRL)*/, 1); - popup.insertItem(i18n("&Link Here") /* KDE4-TODO + "\t" + KKey::modFlagLabel((KKey::ModFlag)(KKey::CTRL|KKey::SHIFT)) */, 2); - popup.insertSeparator(); - popup.insertItem(SmallIcon("stop"), i18n("Cancel"), 3); - popup.setAccel(i18n("Escape"), 3); - - /* KDE4-TODO: selectedIndex = popup.exec(QCursor::pos()); */ - popup.exec(QCursor::pos()); - selectedIndex = 0; // KD4-TODO: use QAction instead of switch below - // See libkonq/konq_operations.cc: KonqOperations::doDropFileCopy() (and doDrop, the main method) - } - - if (selectedIndex < 0) { - return; - } - - switch (selectedIndex) { - case 0: { - // 'Move Here' has been selected - updateViewProperties(urls); - moveUrls(urls, destination); - break; - } - - case 1: { - // 'Copy Here' has been selected - updateViewProperties(urls); - copyUrls(urls, destination); - break; - } - - case 2: { - // 'Link Here' has been selected - KIO::Job* job = KIO::link(urls, destination); - addPendingUndoJob(job, DolphinCommand::Link, urls, destination); - break; - } - - default: - // 'Cancel' has been selected - break; - } -} - -void Dolphin::refreshViews() -{ - const bool split = DolphinSettings::instance().generalSettings()->splitView(); - const bool isPrimaryViewActive = (m_activeView == m_view[PrimaryIdx]); - KUrl url; - for (int i = PrimaryIdx; i <= SecondaryIdx; ++i) { - if (m_view[i] != 0) { - url = m_view[i]->url(); - - // delete view instance... - m_view[i]->close(); - m_view[i]->deleteLater(); - m_view[i] = 0; - } - - if (split || (i == PrimaryIdx)) { - // ... and recreate it - ViewProperties props(url); - m_view[i] = new DolphinView(m_splitter, - url, - props.viewMode(), - props.isShowHiddenFilesEnabled()); - m_view[i]->show(); - } - } - - m_activeView = isPrimaryViewActive ? m_view[PrimaryIdx] : m_view[SecondaryIdx]; - assert(m_activeView != 0); - - updateViewActions(); - emit activeViewChanged(); -} - -void Dolphin::slotHistoryChanged() -{ - updateHistory(); -} - -void Dolphin::slotUrlChanged(const KUrl& url) -{ - updateEditActions(); - updateGoActions(); - setCaption(url.fileName()); -} - -void Dolphin::slotUrlChangeRequest(const KUrl& url) -{ - clearStatusBar(); - m_activeView->setUrl(url); -} - -void Dolphin::slotViewModeChanged() -{ - updateViewActions(); -} - -void Dolphin::slotShowHiddenFilesChanged() -{ - KToggleAction* showHiddenFilesAction = - static_cast(actionCollection()->action("show_hidden_files")); - showHiddenFilesAction->setChecked(m_activeView->isShowHiddenFilesEnabled()); -} - -void Dolphin::slotShowFilterBarChanged() -{ - KToggleAction* showFilterBarAction = - static_cast(actionCollection()->action("show_filter_bar")); - showFilterBarAction->setChecked(m_activeView->isFilterBarVisible()); -} - -void Dolphin::slotSortingChanged(DolphinView::Sorting sorting) -{ - KAction* action = 0; - switch (sorting) { - case DolphinView::SortByName: - action = actionCollection()->action("by_name"); - break; - case DolphinView::SortBySize: - action = actionCollection()->action("by_size"); - break; - case DolphinView::SortByDate: - action = actionCollection()->action("by_date"); - break; - default: - break; - } - - if (action != 0) { - KToggleAction* toggleAction = static_cast(action); - toggleAction->setChecked(true); - } -} - -void Dolphin::slotSortOrderChanged(Qt::SortOrder order) -{ - KToggleAction* descending = static_cast(actionCollection()->action("descending")); - const bool sortDescending = (order == Qt::Descending); - descending->setChecked(sortDescending); -} - -void Dolphin::slotSelectionChanged() -{ - updateEditActions(); - - assert(m_view[PrimaryIdx] != 0); - int selectedUrlsCount = m_view[PrimaryIdx]->selectedUrls().count(); - if (m_view[SecondaryIdx] != 0) { - selectedUrlsCount += m_view[SecondaryIdx]->selectedUrls().count(); - } - - KAction* compareFilesAction = actionCollection()->action("compare_files"); - compareFilesAction->setEnabled(selectedUrlsCount == 2); - - m_activeView->updateStatusBar(); - - emit selectionChanged(); -} - -void Dolphin::closeEvent(QCloseEvent* event) -{ - // KDE4-TODO - //KConfig* config = KGlobal::config(); - //config->setGroup("General"); - //config->writeEntry("First Run", false); - - DolphinSettings& settings = DolphinSettings::instance(); - GeneralSettings* generalSettings = settings.generalSettings(); - generalSettings->setFirstRun(false); - - SidebarSettings* sidebarSettings = settings.sidebarSettings(); - const bool isSidebarVisible = (m_sidebar != 0); - sidebarSettings->setVisible(isSidebarVisible); - if (isSidebarVisible) { - sidebarSettings->setWidth(m_sidebar->width()); - } - - settings.save(); - - KMainWindow::closeEvent(event); -} - -void Dolphin::saveProperties(KConfig* config) -{ - config->setGroup("Primary view"); - config->writeEntry("Url", m_view[PrimaryIdx]->url().url()); - config->writeEntry("Editable Url", m_view[PrimaryIdx]->isUrlEditable()); - if (m_view[SecondaryIdx] != 0) { - config->setGroup("Secondary view"); - config->writeEntry("Url", m_view[SecondaryIdx]->url().url()); - config->writeEntry("Editable Url", m_view[SecondaryIdx]->isUrlEditable()); - } -} - -void Dolphin::readProperties(KConfig* config) -{ - config->setGroup("Primary view"); - m_view[PrimaryIdx]->setUrl(config->readEntry("Url")); - m_view[PrimaryIdx]->setUrlEditable(config->readBoolEntry("Editable Url")); - if (config->hasGroup("Secondary view")) { - config->setGroup("Secondary view"); - if (m_view[SecondaryIdx] == 0) { - toggleSplitView(); - } - m_view[SecondaryIdx]->setUrl(config->readEntry("Url")); - m_view[SecondaryIdx]->setUrlEditable(config->readBoolEntry("Editable Url")); - } - else if (m_view[SecondaryIdx] != 0) { - toggleSplitView(); - } -} - -void Dolphin::createFolder() -{ - // Parts of the following code have been taken - // from the class KonqPopupMenu located in - // libqonq/konq_popupmenu.h of Konqueror. - // (Copyright (C) 2000 David Faure , - // Copyright (C) 2001 Holger Freyther ) - - clearStatusBar(); - - DolphinStatusBar* statusBar = m_activeView->statusBar(); - const KUrl baseUrl(m_activeView->url()); - - QString name(i18n("New Folder")); - baseUrl.path(KUrl::AddTrailingSlash); - - - if (baseUrl.isLocalFile() && QFileInfo(baseUrl.path(KUrl::AddTrailingSlash) + name).exists()) { - name = KIO::RenameDlg::suggestName(baseUrl, i18n("New Folder")); - } - - bool ok = false; - name = KInputDialog::getText(i18n("New Folder"), - i18n("Enter folder name:" ), - name, - &ok, - this); - - if (!ok) { - // the user has pressed 'Cancel' - return; - } - - assert(!name.isEmpty()); - - KUrl url; - if ((name[0] == '/') || (name[0] == '~')) { - url.setPath(KShell::tildeExpand(name)); - } - else { - name = KIO::encodeFileName(name); - url = baseUrl; - url.addPath(name); - } - ok = KIO::NetAccess::mkdir(url, this); - - // TODO: provide message type hint - if (ok) { - statusBar->setMessage(i18n("Created folder %1.",url.path()), - DolphinStatusBar::OperationCompleted); - - DolphinCommand command(DolphinCommand::CreateFolder, KUrl::List(), url); - UndoManager::instance().addCommand(command); - } - else { - // Creating of the folder has been failed. Check whether the creating - // has been failed because a folder with the same name exists... - if (KIO::NetAccess::exists(url, true, this)) { - statusBar->setMessage(i18n("A folder named %1 already exists.",url.path()), - DolphinStatusBar::Error); - } - else { - statusBar->setMessage(i18n("Creating of folder %1 failed.",url.path()), - DolphinStatusBar::Error); - } - - } -} - -void Dolphin::createFile() -{ - // Parts of the following code have been taken - // from the class KonqPopupMenu located in - // libqonq/konq_popupmenu.h of Konqueror. - // (Copyright (C) 2000 David Faure , - // Copyright (C) 2001 Holger Freyther ) - - clearStatusBar(); - - // TODO: const Entry& entry = m_createFileTemplates[QString(sender->name())]; - // should be enough. Anyway: the implemantation of [] does a linear search internally too. - KSortableList::ConstIterator it = m_createFileTemplates.begin(); - KSortableList::ConstIterator end = m_createFileTemplates.end(); - - const QString senderName(sender()->name()); - bool found = false; - CreateFileEntry entry; - while (!found && (it != end)) { - if ((*it).index() == senderName) { - entry = (*it).value(); - found = true; - } - else { - ++it; - } - } - - DolphinStatusBar* statusBar = m_activeView->statusBar(); - if (!found || !QFile::exists(entry.templatePath)) { - statusBar->setMessage(i18n("Could not create file."), DolphinStatusBar::Error); - return; - } - - // Get the source path of the template which should be copied. - // The source path is part of the Url entry of the desktop file. - const int pos = entry.templatePath.findRev('/'); - QString sourcePath(entry.templatePath.left(pos + 1)); - sourcePath += KDesktopFile(entry.templatePath, true).readPathEntry("Url"); - - QString name(i18n(entry.name.ascii())); - // Most entry names end with "..." (e. g. "HTML File..."), which is ok for - // menus but no good choice for a new file name -> remove the dots... - name.replace("...", QString::null); - - // add the file extension to the name - name.append(sourcePath.right(sourcePath.length() - sourcePath.findRev('.'))); - - // Check whether a file with the current name already exists. If yes suggest automatically - // a unique file name (e. g. "HTML File" will be replaced by "HTML File_1"). - const KUrl viewUrl(m_activeView->url()); - const bool fileExists = viewUrl.isLocalFile() && - QFileInfo(viewUrl.path(KUrl::AddTrailingSlash) + KIO::encodeFileName(name)).exists(); - if (fileExists) { - name = KIO::RenameDlg::suggestName(viewUrl, name); - } - - // let the user change the suggested file name - bool ok = false; - name = KInputDialog::getText(entry.name, - entry.comment, - name, - &ok, - this); - if (!ok) { - // the user has pressed 'Cancel' - return; - } - - // before copying the template to the destination path check whether a file - // with the given name already exists - const QString destPath(viewUrl.pathOrUrl() + "/" + KIO::encodeFileName(name)); - const KUrl destUrl(destPath); - if (KIO::NetAccess::exists(destUrl, false, this)) { - statusBar->setMessage(i18n("A file named %1 already exists.",name), - DolphinStatusBar::Error); - return; - } - - // copy the template to the destination path - const KUrl sourceUrl(sourcePath); - KIO::CopyJob* job = KIO::copyAs(sourceUrl, destUrl); - job->setDefaultPermissions(true); - if (KIO::NetAccess::synchronousRun(job, this)) { - statusBar->setMessage(i18n("Created file %1.",name), - DolphinStatusBar::OperationCompleted); - - KUrl::List list; - list.append(sourceUrl); - DolphinCommand command(DolphinCommand::CreateFile, list, destUrl); - UndoManager::instance().addCommand(command); - - } - else { - statusBar->setMessage(i18n("Creating of file %1 failed.",name), - DolphinStatusBar::Error); - } -} - -void Dolphin::rename() -{ - clearStatusBar(); - m_activeView->renameSelectedItems(); -} - -void Dolphin::moveToTrash() -{ - clearStatusBar(); - KUrl::List selectedUrls = m_activeView->selectedUrls(); - KIO::Job* job = KIO::trash(selectedUrls); - addPendingUndoJob(job, DolphinCommand::Trash, selectedUrls, m_activeView->url()); -} - -void Dolphin::deleteItems() -{ - clearStatusBar(); - - KUrl::List list = m_activeView->selectedUrls(); - const uint itemCount = list.count(); - assert(itemCount >= 1); - - QString text; - if (itemCount > 1) { - text = i18n("Do you really want to delete the %1 selected items?",itemCount); - } - else { - const KUrl& url = list.first(); - text = i18n("Do you really want to delete '%1'?",url.fileName()); - } - - const bool del = KMessageBox::warningContinueCancel(this, - text, - QString::null, - KGuiItem(i18n("Delete"), SmallIcon("editdelete")) - ) == KMessageBox::Continue; - if (del) { - KIO::Job* job = KIO::del(list); - connect(job, SIGNAL(result(KJob*)), - this, SLOT(slotHandleJobError(KJob*))); - connect(job, SIGNAL(result(KJob*)), - this, SLOT(slotDeleteFileFinished(KJob*))); - } -} - -void Dolphin::properties() -{ - const KFileItemList* sourceList = m_activeView->selectedItems(); - if (sourceList == 0) { - return; - } - - KFileItemList list; - KFileItemList::const_iterator it = sourceList->begin(); - const KFileItemList::const_iterator end = sourceList->end(); - KFileItem* item = 0; - while (it != end) { - list.append(item); - ++it; - } - - new KPropertiesDialog(list, this); -} - -void Dolphin::quit() -{ - close(); -} - -void Dolphin::slotHandleJobError(KJob* job) -{ - if (job->error() != 0) { - m_activeView->statusBar()->setMessage(job->errorString(), - DolphinStatusBar::Error); - } -} - -void Dolphin::slotDeleteFileFinished(KJob* job) -{ - if (job->error() == 0) { - m_activeView->statusBar()->setMessage(i18n("Delete operation completed."), - DolphinStatusBar::OperationCompleted); - - // TODO: In opposite to the 'Move to Trash' operation in the class KFileIconView - // no rearranging of the item position is done when a file has been deleted. - // This is bypassed by reloading the view, but it might be worth to investigate - // deeper for the root of this issue. - m_activeView->reload(); - } -} - -void Dolphin::slotUndoAvailable(bool available) -{ - KAction* undoAction = actionCollection()->action(KStdAction::stdName(KStdAction::Undo)); - if (undoAction != 0) { - undoAction->setEnabled(available); - } -} - -void Dolphin::slotUndoTextChanged(const QString& text) -{ - KAction* undoAction = actionCollection()->action(KStdAction::stdName(KStdAction::Undo)); - if (undoAction != 0) { - undoAction->setText(text); - } -} - -void Dolphin::slotRedoAvailable(bool available) -{ - KAction* redoAction = actionCollection()->action(KStdAction::stdName(KStdAction::Redo)); - if (redoAction != 0) { - redoAction->setEnabled(available); - } -} - -void Dolphin::slotRedoTextChanged(const QString& text) -{ - KAction* redoAction = actionCollection()->action(KStdAction::stdName(KStdAction::Redo)); - if (redoAction != 0) { - redoAction->setText(text); - } -} - -void Dolphin::cut() -{ - // TODO: this boolean doesn't work between instances of dolphin or with konqueror or with other - // apps. The "application/x-kde-cutselection" mimetype should be used instead, see KonqMimeData - // in libkonq - m_clipboardContainsCutData = true; - /* KDE4-TODO: Q3DragObject* data = new KUrlDrag(m_activeView->selectedUrls(), - widget()); - QApplication::clipboard()->setData(data);*/ -} - -void Dolphin::copy() -{ - m_clipboardContainsCutData = false; - /* KDE4-TODO: - Q3DragObject* data = new KUrlDrag(m_activeView->selectedUrls(), - widget()); - QApplication::clipboard()->setData(data);*/ -} - -void Dolphin::paste() -{ - /* KDE4-TODO: - see KonqOperations::doPaste - QClipboard* clipboard = QApplication::clipboard(); - QMimeSource* data = clipboard->data(); - if (!KUrlDrag::canDecode(data)) { - return; - } - - clearStatusBar(); - - KUrl::List sourceUrls; - KUrlDrag::decode(data, sourceUrls); - - // per default the pasting is done into the current Url of the view - KUrl destUrl(m_activeView->url()); - - // check whether the pasting should be done into a selected directory - KUrl::List selectedUrls = m_activeView->selectedUrls(); - if (selectedUrls.count() == 1) { - const KFileItem fileItem(S_IFDIR, - KFileItem::Unknown, - selectedUrls.first(), - true); - if (fileItem.isDir()) { - // only one item is selected which is a directory, hence paste - // into this directory - destUrl = selectedUrls.first(); - } - } - - - updateViewProperties(sourceUrls); - if (m_clipboardContainsCutData) { - moveUrls(sourceUrls, destUrl); - m_clipboardContainsCutData = false; - clipboard->clear(); - } - else { - copyUrls(sourceUrls, destUrl); - }*/ -} - -void Dolphin::updatePasteAction() -{ - KAction* pasteAction = actionCollection()->action(KStdAction::stdName(KStdAction::Paste)); - if (pasteAction == 0) { - return; - } - - QString text(i18n("Paste")); - QClipboard* clipboard = QApplication::clipboard(); - QMimeSource* data = clipboard->data(); - /* KDE4-TODO: - if (KUrlDrag::canDecode(data)) { - pasteAction->setEnabled(true); - - KUrl::List urls; - KUrlDrag::decode(data, urls); - const int count = urls.count(); - if (count == 1) { - pasteAction->setText(i18n("Paste 1 File")); - } - else { - pasteAction->setText(i18n("Paste %1 Files").arg(count)); - } - } - else {*/ - pasteAction->setEnabled(false); - pasteAction->setText(i18n("Paste")); - //} - - if (pasteAction->isEnabled()) { - KUrl::List urls = m_activeView->selectedUrls(); - const uint count = urls.count(); - if (count > 1) { - // pasting should not be allowed when more than one file - // is selected - pasteAction->setEnabled(false); - } - else if (count == 1) { - // Only one file is selected. Pasting is only allowed if this - // file is a directory. - // TODO: this doesn't work with remote protocols; instead we need a - // m_activeView->selectedFileItems() to get the real KFileItems - const KFileItem fileItem(S_IFDIR, - KFileItem::Unknown, - urls.first(), - true); - pasteAction->setEnabled(fileItem.isDir()); - } - } -} - -void Dolphin::selectAll() -{ - clearStatusBar(); - m_activeView->selectAll(); -} - -void Dolphin::invertSelection() -{ - clearStatusBar(); - m_activeView->invertSelection(); -} -void Dolphin::setIconsView() -{ - m_activeView->setMode(DolphinView::IconsView); -} - -void Dolphin::setDetailsView() -{ - m_activeView->setMode(DolphinView::DetailsView); -} - -void Dolphin::setPreviewsView() -{ - m_activeView->setMode(DolphinView::PreviewsView); -} - -void Dolphin::sortByName() -{ - m_activeView->setSorting(DolphinView::SortByName); -} - -void Dolphin::sortBySize() -{ - m_activeView->setSorting(DolphinView::SortBySize); -} - -void Dolphin::sortByDate() -{ - m_activeView->setSorting(DolphinView::SortByDate); -} - -void Dolphin::toggleSortOrder() -{ - const Qt::SortOrder order = (m_activeView->sortOrder() == Qt::Ascending) ? - Qt::Descending : - Qt::Ascending; - m_activeView->setSortOrder(order); -} - -void Dolphin::toggleSplitView() -{ - if (m_view[SecondaryIdx] == 0) { - // create a secondary view - m_view[SecondaryIdx] = new DolphinView(m_splitter, - m_view[PrimaryIdx]->url(), - m_view[PrimaryIdx]->mode(), - m_view[PrimaryIdx]->isShowHiddenFilesEnabled()); - m_view[SecondaryIdx]->show(); - } - else { - // remove secondary view - if (m_activeView == m_view[PrimaryIdx]) { - m_view[SecondaryIdx]->close(); - m_view[SecondaryIdx]->deleteLater(); - m_view[SecondaryIdx] = 0; - setActiveView(m_view[PrimaryIdx]); - } - else { - // The secondary view is active, hence from the users point of view - // the content of the secondary view should be moved to the primary view. - // From an implementation point of view it is more efficient to close - // the primary view and exchange the internal pointers afterwards. - m_view[PrimaryIdx]->close(); - m_view[PrimaryIdx]->deleteLater(); - m_view[PrimaryIdx] = m_view[SecondaryIdx]; - m_view[SecondaryIdx] = 0; - setActiveView(m_view[PrimaryIdx]); - } - } -} - -void Dolphin::reloadView() -{ - clearStatusBar(); - m_activeView->reload(); -} - -void Dolphin::stopLoading() -{ -} - -void Dolphin::showHiddenFiles() -{ - clearStatusBar(); - - const KToggleAction* showHiddenFilesAction = - static_cast(actionCollection()->action("show_hidden_files")); - const bool show = showHiddenFilesAction->isChecked(); - m_activeView->setShowHiddenFilesEnabled(show); -} - -void Dolphin::showFilterBar() -{ - const KToggleAction* showFilterBarAction = - static_cast(actionCollection()->action("show_filter_bar")); - const bool show = showFilterBarAction->isChecked(); - m_activeView->slotShowFilterBar(show); -} - -void Dolphin::zoomIn() -{ - m_activeView->zoomIn(); - updateViewActions(); -} - -void Dolphin::zoomOut() -{ - m_activeView->zoomOut(); - updateViewActions(); -} - -void Dolphin::toggleEditLocation() -{ - clearStatusBar(); - - KToggleAction* action = static_cast(actionCollection()->action("editable_location")); - - bool editOrBrowse = action->isChecked(); -// action->setChecked(action->setChecked); - m_activeView->setUrlEditable(editOrBrowse); -} - -void Dolphin::editLocation() -{ - KToggleAction* action = static_cast(actionCollection()->action("editable_location")); - action->setChecked(true); - m_activeView->setUrlEditable(true); -} - -void Dolphin::adjustViewProperties() -{ - clearStatusBar(); - ViewPropertiesDialog dlg(m_activeView); - dlg.exec(); -} - -void Dolphin::goBack() -{ - clearStatusBar(); - m_activeView->goBack(); -} - -void Dolphin::goForward() -{ - clearStatusBar(); - m_activeView->goForward(); -} - -void Dolphin::goUp() -{ - clearStatusBar(); - m_activeView->goUp(); -} - -void Dolphin::goHome() -{ - clearStatusBar(); - m_activeView->goHome(); -} - -void Dolphin::openTerminal() -{ - QString command("konsole --workdir \""); - command.append(m_activeView->url().path()); - command.append('\"'); - - KRun::runCommand(command, "Konsole", "konsole"); -} - -void Dolphin::findFile() -{ - KRun::run("kfind", m_activeView->url()); -} - -void Dolphin::compareFiles() -{ - // The method is only invoked if exactly 2 files have - // been selected. The selected files may be: - // - both in the primary view - // - both in the secondary view - // - one in the primary view and the other in the secondary - // view - assert(m_view[PrimaryIdx] != 0); - - KUrl urlA; - KUrl urlB; - KUrl::List urls = m_view[PrimaryIdx]->selectedUrls(); - - switch (urls.count()) { - case 0: { - assert(m_view[SecondaryIdx] != 0); - urls = m_view[SecondaryIdx]->selectedUrls(); - assert(urls.count() == 2); - urlA = urls[0]; - urlB = urls[1]; - break; - } - - case 1: { - urlA = urls[0]; - assert(m_view[SecondaryIdx] != 0); - urls = m_view[SecondaryIdx]->selectedUrls(); - assert(urls.count() == 1); - urlB = urls[0]; - break; - } - - case 2: { - urlA = urls[0]; - urlB = urls[1]; - break; - } - - default: { - // may not happen: compareFiles may only get invoked if 2 - // files are selected - assert(false); - } - } - - QString command("kompare -c \""); - command.append(urlA.pathOrUrl()); - command.append("\" \""); - command.append(urlB.pathOrUrl()); - command.append('\"'); - KRun::runCommand(command, "Kompare", "kompare"); - -} - -void Dolphin::editSettings() -{ - // TODO: make a static method for opening the settings dialog - DolphinSettingsDialog dlg; - dlg.exec(); -} - -void Dolphin::addUndoOperation(KJob* job) -{ - if (job->error() != 0) { - slotHandleJobError(job); - } - else { - const int id = job->progressId(); - - // set iterator to the executed command with the current id... - Q3ValueList::Iterator it = m_pendingUndoJobs.begin(); - const Q3ValueList::Iterator end = m_pendingUndoJobs.end(); - bool found = false; - while (!found && (it != end)) { - if ((*it).id == id) { - found = true; - } - else { - ++it; - } - } - - if (found) { - DolphinCommand command = (*it).command; - if (command.type() == DolphinCommand::Trash) { - // To be able to perform an undo for the 'Move to Trash' operation - // all source Urls must be updated with the trash Url. E. g. when moving - // a file "test.txt" and a second file "test.txt" to the trash, - // then the filenames in the trash are "0-test.txt" and "1-test.txt". - QMap metaData; - KIO::Job *kiojob = qobject_cast( job ); - if ( kiojob ) - { - metaData = kiojob->metaData(); - } - KUrl::List newSourceUrls; - - KUrl::List sourceUrls = command.source(); - KUrl::List::Iterator sourceIt = sourceUrls.begin(); - const KUrl::List::Iterator sourceEnd = sourceUrls.end(); - - while (sourceIt != sourceEnd) { - QMap::ConstIterator metaIt = metaData.find("trashUrl-" + (*sourceIt).path()); - if (metaIt != metaData.end()) { - newSourceUrls.append(KUrl(metaIt.data())); - } - ++sourceIt; - } - command.setSource(newSourceUrls); - } - - UndoManager::instance().addCommand(command); - m_pendingUndoJobs.erase(it); - - DolphinStatusBar* statusBar = m_activeView->statusBar(); - switch (command.type()) { - case DolphinCommand::Copy: - statusBar->setMessage(i18n("Copy operation completed."), - DolphinStatusBar::OperationCompleted); - break; - case DolphinCommand::Move: - statusBar->setMessage(i18n("Move operation completed."), - DolphinStatusBar::OperationCompleted); - break; - case DolphinCommand::Trash: - statusBar->setMessage(i18n("Move to trash operation completed."), - DolphinStatusBar::OperationCompleted); - break; - default: - break; - } - } - } -} - -void Dolphin::toggleSidebar() -{ - if (m_sidebar == 0) { - openSidebar(); - } - else { - closeSidebar(); - } - - KToggleAction* sidebarAction = static_cast(actionCollection()->action("sidebar")); - sidebarAction->setChecked(m_sidebar != 0); -} - -void Dolphin::closeSidebar() -{ - if (m_sidebar == 0) { - // the sidebar has already been closed - return; - } - - // store width of sidebar and remember that the sidebar has been closed - SidebarSettings* settings = DolphinSettings::instance().sidebarSettings(); - settings->setVisible(false); - settings->setWidth(m_sidebar->width()); - - m_sidebar->deleteLater(); - m_sidebar = 0; -} - -Dolphin::Dolphin() : - KMainWindow(0, "Dolphin"), - m_splitter(0), - m_sidebar(0), - m_activeView(0), - m_clipboardContainsCutData(false) -{ - m_view[PrimaryIdx] = 0; - m_view[SecondaryIdx] = 0; - - m_fileGroupActions.setAutoDelete(true); - - // TODO: the following members are not used yet. See documentation - // of Dolphin::linkGroupActions() and Dolphin::linkToDeviceActions() - // in the header file for details. - //m_linkGroupActions.setAutoDelete(true); - //m_linkToDeviceActions.setAutoDelete(true); -} - -void Dolphin::init() -{ - // Check whether Dolphin runs the first time. If yes then - // a proper default window size is given at the end of Dolphin::init(). - GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings(); - const bool firstRun = generalSettings->firstRun(); - - setAcceptDrops(true); - - m_splitter = new QSplitter(this); - - DolphinSettings& settings = DolphinSettings::instance(); - - KBookmarkManager* manager = settings.bookmarkManager(); - assert(manager != 0); - KBookmarkGroup root = manager->root(); - if (root.first().isNull()) { - root.addBookmark(manager, i18n("Home"), settings.generalSettings()->homeUrl(), "folder_home"); - root.addBookmark(manager, i18n("Storage Media"), KUrl("media:/"), "blockdevice"); - root.addBookmark(manager, i18n("Network"), KUrl("remote:/"), "network_local"); - root.addBookmark(manager, i18n("Root"), KUrl("/"), "folder_red"); - root.addBookmark(manager, i18n("Trash"), KUrl("trash:/"), "trashcan_full"); - } - - setupActions(); - setupGUI(Keys|Save|Create|ToolBar); - - const KUrl& homeUrl = root.first().url(); - setCaption(homeUrl.fileName()); - ViewProperties props(homeUrl); - m_view[PrimaryIdx] = new DolphinView(m_splitter, - homeUrl, - props.viewMode(), - props.isShowHiddenFilesEnabled()); - - m_activeView = m_view[PrimaryIdx]; - - setCentralWidget(m_splitter); - - // open sidebar - SidebarSettings* sidebarSettings = settings.sidebarSettings(); - assert(sidebarSettings != 0); - if (sidebarSettings->visible()) { - openSidebar(); - } - - createGUI(); - - stateChanged("new_file"); - setAutoSaveSettings(); - - QClipboard* clipboard = QApplication::clipboard(); - connect(clipboard, SIGNAL(dataChanged()), - this, SLOT(updatePasteAction())); - updatePasteAction(); - updateGoActions(); - - setupCreateNewMenuActions(); - - loadSettings(); - - if (firstRun) { - // assure a proper default size if Dolphin runs the first time - resize(640, 480); - } -} - -void Dolphin::loadSettings() -{ - GeneralSettings* settings = DolphinSettings::instance().generalSettings(); - - KToggleAction* splitAction = static_cast(actionCollection()->action("split_view")); - if (settings->splitView()) { - splitAction->setChecked(true); - toggleSplitView(); - } - - updateViewActions(); -} - -void Dolphin::setupActions() -{ - // setup 'File' menu - KAction* createFolder = new KAction(i18n("Folder..."), actionCollection(), "create_folder"); - createFolder->setIcon(KIcon("folder")); - createFolder->setShortcut(Qt::Key_N); - connect(createFolder, SIGNAL(triggered()), this, SLOT(createFolder())); - - KAction* rename = new KAction(i18n("Rename"), actionCollection(), "rename"); - rename->setShortcut(Qt::Key_F2); - connect(rename, SIGNAL(triggered()), this, SLOT(rename())); - - KAction* moveToTrash = new KAction(i18n("Move to Trash"), actionCollection(), "move_to_trash"); - moveToTrash->setIcon(KIcon("edittrash")); - moveToTrash->setShortcut(QKeySequence::Delete); - connect(moveToTrash, SIGNAL(triggered()), this, SLOT(moveToTrash())); - - KAction* deleteAction = new KAction(i18n("Delete"), actionCollection(), "delete"); - deleteAction->setShortcut(Qt::ALT | Qt::Key_Delete); - deleteAction->setIcon(KIcon("editdelete")); - connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItems())); - - KAction* properties = new KAction(i18n("Propert&ies"), actionCollection(), "properties"); - properties->setShortcut(Qt::Key_Alt | Qt::Key_Return); - connect(properties, SIGNAL(triggered()), this, SLOT(properties())); - - KStdAction::quit(this, SLOT(quit()), actionCollection()); - - // setup 'Edit' menu - UndoManager& undoManager = UndoManager::instance(); - KStdAction::undo(&undoManager, - SLOT(undo()), - actionCollection()); - connect(&undoManager, SIGNAL(undoAvailable(bool)), - this, SLOT(slotUndoAvailable(bool))); - connect(&undoManager, SIGNAL(undoTextChanged(const QString&)), - this, SLOT(slotUndoTextChanged(const QString&))); - - KStdAction::redo(&undoManager, - SLOT(redo()), - actionCollection()); - connect(&undoManager, SIGNAL(redoAvailable(bool)), - this, SLOT(slotRedoAvailable(bool))); - connect(&undoManager, SIGNAL(redoTextChanged(const QString&)), - this, SLOT(slotRedoTextChanged(const QString&))); - - KStdAction::cut(this, SLOT(cut()), actionCollection()); - KStdAction::copy(this, SLOT(copy()), actionCollection()); - KStdAction::paste(this, SLOT(paste()), actionCollection()); - - KAction* selectAll = new KAction(i18n("Select All"), actionCollection(), "select_all"); - selectAll->setShortcut(Qt::CTRL + Qt::Key_A); - connect(selectAll, SIGNAL(triggered()), this, SLOT(selectAll())); - - KAction* invertSelection = new KAction(i18n("Invert Selection"), actionCollection(), "invert_selection"); - invertSelection->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_A); - connect(invertSelection, SIGNAL(triggered()), this, SLOT(invertSelection())); - - // setup 'View' menu - KStdAction::zoomIn(this, - SLOT(zoomIn()), - actionCollection()); - - KStdAction::zoomOut(this, - SLOT(zoomOut()), - actionCollection()); - - KToggleAction* iconsView = new KToggleAction(i18n("Icons"), actionCollection(), "icons"); - iconsView->setShortcut(Qt::CTRL | Qt::Key_1); - iconsView->setIcon(KIcon("view_icon")); - connect(iconsView, SIGNAL(triggered()), this, SLOT(setIconsView())); - - KToggleAction* detailsView = new KToggleAction(i18n("Details"), actionCollection(), "details"); - detailsView->setShortcut(Qt::CTRL | Qt::Key_2); - detailsView->setIcon(KIcon("view_text")); - connect(detailsView, SIGNAL(triggered()), this, SLOT(setDetailsView())); - - KToggleAction* previewsView = new KToggleAction(i18n("Previews"), actionCollection(), "previews"); - previewsView->setShortcut(Qt::CTRL | Qt::Key_3); - previewsView->setIcon(KIcon("gvdirpart")); - connect(previewsView, SIGNAL(triggered()), this, SLOT(setPreviewsView())); - - QActionGroup* viewModeGroup = new QActionGroup(this); - viewModeGroup->addAction(iconsView); - viewModeGroup->addAction(detailsView); - viewModeGroup->addAction(previewsView); - - KToggleAction* sortByName = new KToggleAction(i18n("By Name"), actionCollection(), "by_name"); - connect(sortByName, SIGNAL(triggered()), this, SLOT(sortByName())); - - KToggleAction* sortBySize = new KToggleAction(i18n("By Size"), actionCollection(), "by_size"); - connect(sortBySize, SIGNAL(triggered()), this, SLOT(sortBySize())); - - KToggleAction* sortByDate = new KToggleAction(i18n("By Date"), actionCollection(), "by_date"); - connect(sortByDate, SIGNAL(triggered()), this, SLOT(sortByDate())); - - QActionGroup* sortGroup = new QActionGroup(this); - sortGroup->addAction(sortByName); - sortGroup->addAction(sortBySize); - sortGroup->addAction(sortByDate); - - KToggleAction* sortDescending = new KToggleAction(i18n("Descending"), actionCollection(), "descending"); - connect(sortDescending, SIGNAL(triggered()), this, SLOT(toggleSortOrder())); - - KToggleAction* showHiddenFiles = new KToggleAction(i18n("Show Hidden Files"), actionCollection(), "show_hidden_files"); - //showHiddenFiles->setShortcut(Qt::ALT | Qt::Key_ KDE4-TODO: what Qt-Key represents '.'? - connect(showHiddenFiles, SIGNAL(triggered()), this, SLOT(showHiddenFiles())); - - KToggleAction* split = new KToggleAction(i18n("Split View"), actionCollection(), "split_view"); - split->setShortcut(Qt::Key_F10); - split->setIcon(KIcon("view_left_right")); - connect(split, SIGNAL(triggered()), this, SLOT(toggleSplitView())); - - KAction* reload = new KAction(i18n("Reload"), "F5", actionCollection(), "reload"); - reload->setShortcut(Qt::Key_F5); - reload->setIcon(KIcon("reload")); - connect(reload, SIGNAL(triggered()), this, SLOT(reloadView())); - - KAction* stop = new KAction(i18n("Stop"), actionCollection(), "stop"); - stop->setIcon(KIcon("stop")); - connect(stop, SIGNAL(triggered()), this, SLOT(stopLoading())); - - KToggleAction* showFullLocation = new KToggleAction(i18n("Show Full Location"), actionCollection(), "editable_location"); - showFullLocation->setShortcut(Qt::CTRL | Qt::Key_L); - connect(showFullLocation, SIGNAL(triggered()), this, SLOT(toggleEditLocation())); - - KToggleAction* editLocation = new KToggleAction(i18n("Edit Location"), actionCollection(), "edit_location"); - editLocation->setShortcut(Qt::Key_F6); - connect(editLocation, SIGNAL(triggered()), this, SLOT(editLocation())); - - KToggleAction* sidebar = new KToggleAction(i18n("Sidebar"), actionCollection(), "sidebar"); - sidebar->setShortcut(Qt::Key_F9); - connect(sidebar, SIGNAL(triggered()), this, SLOT(toggleSidebar())); - - KAction* adjustViewProps = new KAction(i18n("Adjust View Properties..."), actionCollection(), "view_properties"); - connect(adjustViewProps, SIGNAL(triggered()), this, SLOT(adjustViewProperties())); - - // setup 'Go' menu - KStdAction::back(this, SLOT(goBack()), actionCollection()); - KStdAction::forward(this, SLOT(goForward()), actionCollection()); - KStdAction::up(this, SLOT(goUp()), actionCollection()); - KStdAction::home(this, SLOT(goHome()), actionCollection()); - - // setup 'Tools' menu - KAction* openTerminal = new KAction(i18n("Open Terminal"), actionCollection(), "open_terminal"); - openTerminal->setShortcut(Qt::Key_F4); - openTerminal->setIcon(KIcon("konsole")); - connect(openTerminal, SIGNAL(triggered()), this, SLOT(openTerminal())); - - KAction* findFile = new KAction(i18n("Find File..."), actionCollection(), "find_file"); - findFile->setShortcut(Qt::Key_F); - findFile->setIcon(KIcon("filefind")); - connect(findFile, SIGNAL(triggered()), this, SLOT(findFile())); - - KToggleAction* showFilterBar = new KToggleAction(i18n("Show Filter Bar"), actionCollection(), "show_filter_bar"); - showFilterBar->setShortcut(Qt::Key_Slash); - connect(showFilterBar, SIGNAL(triggered()), this, SLOT(showFilterBar())); - - KAction* compareFiles = new KAction(i18n("Compare Files"), actionCollection(), "compare_files"); - compareFiles->setIcon(KIcon("kompare")); - compareFiles->setEnabled(false); - connect(compareFiles, SIGNAL(triggered()), this, SLOT(compareFiles())); - - // setup 'Settings' menu - KStdAction::preferences(this, SLOT(editSettings()), actionCollection()); -} - -void Dolphin::setupCreateNewMenuActions() -{ - // Parts of the following code have been taken - // from the class KNewMenu located in - // libqonq/knewmenu.h of Konqueror. - // Copyright (C) 1998, 1999 David Faure - // 2003 Sven Leiber - - QStringList files = actionCollection()->instance()->dirs()->findAllResources("templates"); - for (QStringList::Iterator it = files.begin() ; it != files.end(); ++it) { - if ((*it)[0] != '.' ) { - KSimpleConfig config(*it, true); - config.setDesktopGroup(); - - // tricky solution to ensure that TextFile is at the beginning - // because this filetype is the most used (according kde-core discussion) - const QString name(config.readEntry("Name")); - QString key(name); - - const QString path(config.readPathEntry("Url")); - if (!path.endsWith("emptydir")) { - if (path.endsWith("TextFile.txt")) { - key = "1" + key; - } - else if (!KDesktopFile::isDesktopFile(path)) { - key = "2" + key; - } - else if (path.endsWith("Url.desktop")){ - key = "3" + key; - } - else if (path.endsWith("Program.desktop")){ - key = "4" + key; - } - else { - key = "5"; - } - - const QString icon(config.readEntry("Icon")); - const QString comment(config.readEntry("Comment")); - const QString type(config.readEntry("Type")); - - const QString filePath(*it); - - - if (type == "Link") { - CreateFileEntry entry; - entry.name = name; - entry.icon = icon; - entry.comment = comment; - entry.templatePath = filePath; - m_createFileTemplates.insert(key, entry); - } - } - } - } - m_createFileTemplates.sort(); - - unplugActionList("create_actions"); - KSortableList::ConstIterator it = m_createFileTemplates.begin(); - KSortableList::ConstIterator end = m_createFileTemplates.end(); - /* KDE4-TODO: don't port this code; use KNewMenu instead - while (it != end) { - CreateFileEntry entry = (*it).value(); - KAction* action = new KAction(entry.name); - action->setIcon(entry.icon); - action->setName((*it).index()); - connect(action, SIGNAL(activated()), - this, SLOT(createFile())); - - const QChar section = ((*it).index()[0]); - switch (section) { - case '1': - case '2': { - m_fileGroupActions.append(action); - break; - } - - case '3': - case '4': { - // TODO: not used yet. See documentation of Dolphin::linkGroupActions() - // and Dolphin::linkToDeviceActions() in the header file for details. - //m_linkGroupActions.append(action); - break; - } - - case '5': { - // TODO: not used yet. See documentation of Dolphin::linkGroupActions() - // and Dolphin::linkToDeviceActions() in the header file for details. - //m_linkToDeviceActions.append(action); - break; - } - default: - break; - } - ++it; - } - - plugActionList("create_file_group", m_fileGroupActions); - //plugActionList("create_link_group", m_linkGroupActions); - //plugActionList("link_to_device", m_linkToDeviceActions);*/ -} - -void Dolphin::updateHistory() -{ - int index = 0; - const Q3ValueList list = m_activeView->urlHistory(index); - - KAction* backAction = actionCollection()->action("go_back"); - if (backAction != 0) { - backAction->setEnabled(index < static_cast(list.count()) - 1); - } - - KAction* forwardAction = actionCollection()->action("go_forward"); - if (forwardAction != 0) { - forwardAction->setEnabled(index > 0); - } -} - -void Dolphin::updateEditActions() -{ - const KFileItemList* list = m_activeView->selectedItems(); - if ((list == 0) || (*list).isEmpty()) { - stateChanged("has_no_selection"); - } - else { - stateChanged("has_selection"); - - KAction* renameAction = actionCollection()->action("rename"); - if (renameAction != 0) { - renameAction->setEnabled(list->count() >= 1); - } - - bool enableMoveToTrash = true; - - KFileItemList::const_iterator it = list->begin(); - const KFileItemList::const_iterator end = list->end(); - while (it != end) { - KFileItem* item = *it; - const KUrl& url = item->url(); - // only enable the 'Move to Trash' action for local files - if (!url.isLocalFile()) { - enableMoveToTrash = false; - } - ++it; - } - - KAction* moveToTrashAction = actionCollection()->action("move_to_trash"); - moveToTrashAction->setEnabled(enableMoveToTrash); - } - updatePasteAction(); -} - -void Dolphin::updateViewActions() -{ - KAction* zoomInAction = actionCollection()->action(KStdAction::stdName(KStdAction::ZoomIn)); - if (zoomInAction != 0) { - zoomInAction->setEnabled(m_activeView->isZoomInPossible()); - } - - KAction* zoomOutAction = actionCollection()->action(KStdAction::stdName(KStdAction::ZoomOut)); - if (zoomOutAction != 0) { - zoomOutAction->setEnabled(m_activeView->isZoomOutPossible()); - } - - KAction* action = 0; - switch (m_activeView->mode()) { - case DolphinView::IconsView: - action = actionCollection()->action("icons"); - break; - case DolphinView::DetailsView: - action = actionCollection()->action("details"); - break; - case DolphinView::PreviewsView: - action = actionCollection()->action("previews"); - break; - default: - break; - } - - if (action != 0) { - KToggleAction* toggleAction = static_cast(action); - toggleAction->setChecked(true); - } - - slotSortingChanged(m_activeView->sorting()); - slotSortOrderChanged(m_activeView->sortOrder()); - - KToggleAction* showFilterBarAction = - static_cast(actionCollection()->action("show_filter_bar")); - showFilterBarAction->setChecked(m_activeView->isFilterBarVisible()); - - KToggleAction* showHiddenFilesAction = - static_cast(actionCollection()->action("show_hidden_files")); - showHiddenFilesAction->setChecked(m_activeView->isShowHiddenFilesEnabled()); - - KToggleAction* splitAction = static_cast(actionCollection()->action("split_view")); - splitAction->setChecked(m_view[SecondaryIdx] != 0); - - KToggleAction* sidebarAction = static_cast(actionCollection()->action("sidebar")); - sidebarAction->setChecked(m_sidebar != 0); -} - -void Dolphin::updateGoActions() -{ - KAction* goUpAction = actionCollection()->action(KStdAction::stdName(KStdAction::Up)); - const KUrl& currentUrl = m_activeView->url(); - goUpAction->setEnabled(currentUrl.upUrl() != currentUrl); -} - -void Dolphin::updateViewProperties(const KUrl::List& urls) -{ - if (urls.isEmpty()) { - return; - } - - // Updating the view properties might take up to several seconds - // when dragging several thousand Urls. Writing a KIO slave for this - // use case is not worth the effort, but at least the main widget - // must be disabled and a progress should be shown. - ProgressIndicator progressIndicator(i18n("Updating view properties..."), - QString::null, - urls.count()); - - KUrl::List::ConstIterator end = urls.end(); - for(KUrl::List::ConstIterator it = urls.begin(); it != end; ++it) { - progressIndicator.execOperation(); - - ViewProperties props(*it); - props.save(); - } -} - -void Dolphin::copyUrls(const KUrl::List& source, const KUrl& dest) -{ - KIO::Job* job = KIO::copy(source, dest); - addPendingUndoJob(job, DolphinCommand::Copy, source, dest); -} - -void Dolphin::moveUrls(const KUrl::List& source, const KUrl& dest) -{ - KIO::Job* job = KIO::move(source, dest); - addPendingUndoJob(job, DolphinCommand::Move, source, dest); -} - -void Dolphin::addPendingUndoJob(KIO::Job* job, - DolphinCommand::Type commandType, - const KUrl::List& source, - const KUrl& dest) -{ - connect(job, SIGNAL(result(KJob*)), - this, SLOT(addUndoOperation(KJob*))); - - UndoInfo undoInfo; - undoInfo.id = job->progressId(); - undoInfo.command = DolphinCommand(commandType, source, dest); - m_pendingUndoJobs.append(undoInfo); -} - -void Dolphin::clearStatusBar() -{ - m_activeView->statusBar()->clear(); -} - -void Dolphin::openSidebar() -{ - if (m_sidebar != 0) { - // the sidebar is already open - return; - } - - m_sidebar = new Sidebar(m_splitter); - m_sidebar->show(); - - connect(m_sidebar, SIGNAL(urlChanged(const KUrl&)), - this, SLOT(slotUrlChangeRequest(const KUrl&))); - m_splitter->setCollapsible(m_sidebar, false); - m_splitter->setResizeMode(m_sidebar, QSplitter::KeepSize); - m_splitter->moveToFirst(m_sidebar); - - SidebarSettings* settings = DolphinSettings::instance().sidebarSettings(); - settings->setVisible(true); -} - -#include "dolphin.moc" diff --git a/src/dolphin.h b/src/dolphin.h deleted file mode 100644 index 0013b4de8..000000000 --- a/src/dolphin.h +++ /dev/null @@ -1,456 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * Copyright (C) 2006 by Stefan Monov * - * Copyright (C) 2006 by Cvetoslav Ludmiloff * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef _DOLPHIN_H_ -#define _DOLPHIN_H_ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include -//Added by qt3to4: -#include -#include -#include - -#include "dolphinview.h" -#include "undomanager.h" - -class KPrinter; -class KUrl; -class QLineEdit; -class KFileIconView; -class KHBox; -class Q3IconViewItem; -class QSplitter; -class KAction; -class UrlNavigator; -class Sidebar; - -/** - * @short Main window for Dolphin. - * - * Handles the menus, toolbars and Dolphin views. - * - * @author Peter Penz -*/ -class Dolphin : public KMainWindow -{ - Q_OBJECT - -public: - /** - * Returns the instance for the Dolphin main window. - */ - // KXMLGUIClient::instance() already in use :-( - static Dolphin& mainWin(); - - virtual ~Dolphin(); - - /** - * Activates the given view, which means that - * all menu actions are applied to this view. When - * having a split view setup the nonactive view - * is usually shown in darker colors. - */ - void setActiveView(DolphinView* view); - - /** - * Returns the currently active view. See - * Dolphin::setActiveView() for more details. - */ - DolphinView* activeView() const { return m_activeView; } - - /** - * Handles the dropping of Urls to the given - * destination. A context menu with the options - * 'Move Here', 'Copy Here', 'Link Here' and - * 'Cancel' is offered to the user. - * @param urls List of Urls which have been - * dropped. - * @param destination Destination Url, where the - * list or Urls should be moved, - * copied or linked to. - */ - void dropUrls(const KUrl::List& urls, - const KUrl& destination); - - /** - * Returns 'true', if the clipboard contains data - * which has been cutted by the Cut action (Ctrl + X). - */ - bool clipboardContainsCutData() const { return m_clipboardContainsCutData; } - - /** - * Returns the list of actions which are part of the file group - * of the 'Create New...' sub menu. Usually the list contains actions - * for creating folders, text files, HTML files etc. - */ - const Q3PtrList& fileGroupActions() const { return m_fileGroupActions; } - //const QPtrList& linkGroupActions() const { return m_linkGroupActions; } - //const QPtrList& linkToDeviceActions() const { return m_linkToDeviceActions; } - - /** - * Refreshs the views of the main window by recreating them dependent from - * the given Dolphin settings. - */ - void refreshViews(); - -signals: - /** - * Is send if the active view has been changed in - * the split view mode. - */ - void activeViewChanged(); - - /** - * Is send if the selection of the currently active view has - * been changed. - */ - void selectionChanged(); - -public slots: - /** - * Updates the state of the 'Back' and 'Forward' menu - * actions corresponding the the current history. - */ - void slotHistoryChanged(); - - /** - * Updates the caption of the main window and the state - * of all menu actions which depend from a changed Url. - */ - void slotUrlChanged(const KUrl& url); - - /** - * Go to the given Url. - */ - void slotUrlChangeRequest(const KUrl& url); - - /** Updates the state of all 'View' menu actions. */ - void slotViewModeChanged(); - - /** Updates the state of the 'Show hidden files' menu action. */ - void slotShowHiddenFilesChanged(); - - /** Updates the state of the 'Show filter bar' menu action. */ - void slotShowFilterBarChanged(); - - /** Updates the state of the 'Sort by' actions. */ - void slotSortingChanged(DolphinView::Sorting sorting); - - /** Updates the state of the 'Sort Ascending/Descending' action. */ - void slotSortOrderChanged(Qt::SortOrder order); - - /** Updates the state of the 'Edit' menu actions. */ - void slotSelectionChanged(); - -protected: - /** @see QMainWindow::closeEvent */ - virtual void closeEvent(QCloseEvent* event); - - /** - * This method is called when it is time for the app to save its - * properties for session management purposes. - */ - void saveProperties(KConfig*); - - /** - * This method is called when this app is restored. The KConfig - * object points to the session management config file that was saved - * with @ref saveProperties - */ - void readProperties(KConfig*); - -private slots: - /** Opens an input dialog for creating a new folder. */ - void createFolder(); - - /** Creates a file with the MIME type given by the sender. */ - void createFile(); - - /** Renames the selected item of the active view. */ - void rename(); - - /** Moves the selected items of the active view to the trash. */ - void moveToTrash(); - - /** Deletes the selected items of the active view. */ - void deleteItems(); - - /** - * Opens the properties window for the selected items of the - * active view. The properties windows shows informations - * like name, size and permissions. - */ - void properties(); - - /** Stores all settings and quits Dolphin. */ - void quit(); - - /** - * Shows the error information of the job \a job - * in the status bar. - */ - void slotHandleJobError(KJob* job); - - /** - * Indicates in the status bar that the delete operation - * of the job \a job has been finished. - */ - void slotDeleteFileFinished(KJob* job); - - /** - * Updates the state of the 'Undo' menu action dependent - * from the parameter \a available. - */ - void slotUndoAvailable(bool available); - - /** Sets the text of the 'Undo' menu action to \a text. */ - void slotUndoTextChanged(const QString& text); - - /** - * Updates the state of the 'Redo' menu action dependent - * from the parameter \a available. - */ - void slotRedoAvailable(bool available); - - /** Sets the text of the 'Redo' menu action to \a text. */ - void slotRedoTextChanged(const QString& text); - - /** - * Copies all selected items to the clipboard and marks - * the items as cutted. - */ - void cut(); - - /** Copies all selected items to the clipboard. */ - void copy(); - - /** Pastes the clipboard data to the active view. */ - void paste(); - - /** - * Updates the text of the paste action dependent from - * the number of items which are in the clipboard. - */ - void updatePasteAction(); - - /** Selects all items from the active view. */ - void selectAll(); - - /** - * Inverts the selection of all items of the active view: - * Selected items get nonselected and nonselected items get - * selected. - */ - void invertSelection(); - - /** The current active view is switched to the icons mode. */ - void setIconsView(); - - /** The current active view is switched to the details mode. */ - void setDetailsView(); - - /** The current active view is switched to the previews mode. */ - void setPreviewsView(); - - /** The sorting of the current view should be done by the name. */ - void sortByName(); - - /** The sorting of the current view should be done by the size. */ - void sortBySize(); - - /** The sorting of the current view should be done by the date. */ - void sortByDate(); - - /** Switches between an ascending and descending sorting order. */ - void toggleSortOrder(); - - /** - * Switches between one and two views: - * If one view is visible, it will get split into two views. - * If already two views are visible, the nonactivated view gets closed. - */ - void toggleSplitView(); - - /** Reloads the current active view. */ - void reloadView(); - - /** Stops the loading process for the current active view. */ - void stopLoading(); - - /** - * Switches between showing and hiding of hidden marked files dependent - * from the current state of the 'Show Hidden Files' menu toggle action. - */ - void showHiddenFiles(); - - /** - * Switches between showing and hiding of the filter bar dependent - * from the current state of the 'Show Filter Bar' menu toggle action. - */ - void showFilterBar(); - - /** Increases the size of the current set view mode. */ - void zoomIn(); - - /** Decreases the size of the current set view mode. */ - void zoomOut(); - - /** - * Toggles between edit and brose mode of the navigation bar. - */ - void toggleEditLocation(); - - /** - * Switches to the edit mode of the navigation bar. If the edit mode is - * already active, it is assured that the navigation bar get focused. - */ - void editLocation(); - - /** - * Opens the view properties dialog, which allows to modify the properties - * of the currently active view. - */ - void adjustViewProperties(); - - /** Goes back on step of the Url history. */ - void goBack(); - - /** Goes forward one step of the Url history. */ - void goForward(); - - /** Goes up one hierarchy of the current Url. */ - void goUp(); - - /** Goes to the home Url. */ - void goHome(); - - /** Opens a terminal for the current shown directory. */ - void openTerminal(); - - /** Opens KFind for the current shown directory. */ - void findFile(); - - /** Opens Kompare for 2 selected files. */ - void compareFiles(); - - /** Opens the settings dialog for Dolphin. */ - void editSettings(); - - /** - * Adds the undo operation given by \a job - * to the UndoManager. - */ - void addUndoOperation(KJob* job); - - - void toggleSidebar(); - - /** - * Stores the current sidebar width and closes - * the sidebar. - */ - void closeSidebar(); - -private: - Dolphin(); - void init(); - void loadSettings(); - - void setupAccel(); - void setupActions(); - void setupCreateNewMenuActions(); - void updateHistory(); - void updateEditActions(); - void updateViewActions(); - void updateGoActions(); - void updateViewProperties(const KUrl::List& urls); - void copyUrls(const KUrl::List& source, const KUrl& dest); - void moveUrls(const KUrl::List& source, const KUrl& dest); - void addPendingUndoJob(KIO::Job* job, - DolphinCommand::Type commandType, - const KUrl::List& source, - const KUrl& dest); - void clearStatusBar(); - void openSidebar(); - - QSplitter* m_splitter; - Sidebar* m_sidebar; - DolphinView* m_activeView; - - /** - * Dolphin supports only one or two views, which - * are handled internally as primary and secondary view. - */ - enum ViewIndex - { - PrimaryIdx = 0, - SecondaryIdx = 1 - }; - DolphinView* m_view[SecondaryIdx + 1]; - - /// If set to true, the clipboard contains data which should be cutted after pasting. - bool m_clipboardContainsCutData; - - /** - * Asynchronous operations like 'Move' and 'Copy' may only be added as undo - * operation after they have been finished successfully. When an asynchronous - * operation is started, it is added to a pending undo jobs list in the meantime. - * As soon as the job has been finished, the operation is added to the undo mangager. - * @see UndoManager - * @see Dolphin::addPendingUndoJob - * @see Dolphin::addUndoOperation - */ - struct UndoInfo - { - int id; - DolphinCommand command; - }; - Q3ValueList m_pendingUndoJobs; - - /** Contains meta information for creating files. */ - struct CreateFileEntry - { - QString name; - QString filePath; - QString templatePath; - QString icon; - QString comment; - }; - - Q3PtrList m_fileGroupActions; - KSortableList m_createFileTemplates; - - // TODO: not used yet. See documentation of Dolphin::linkGroupActions() - // and Dolphin::linkToDeviceActions() in for details. - //QPtrList m_linkGroupActions; - //QPtrList m_linkToDeviceActions; -}; - -#endif // _DOLPHIN_H_ - diff --git a/src/dolphinapplication.cpp b/src/dolphinapplication.cpp new file mode 100644 index 000000000..a27a4cb27 --- /dev/null +++ b/src/dolphinapplication.cpp @@ -0,0 +1,64 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * Copyright (C) 2006 by Holger 'zecke' Freyther * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "dolphinapplication.h" +#include "dolphinmainwindow.h" + +DolphinApplication::DolphinApplication() +{ +} + +/* + * cleanup what ever is left from the MainWindows + */ +DolphinApplication::~DolphinApplication() +{ + while( m_mainWindows.count() != 0 ) + delete m_mainWindows.takeFirst(); +} + +DolphinApplication* DolphinApplication::app() +{ + return qobject_cast(qApp); +} + +DolphinMainWindow* DolphinApplication::createMainWindow() +{ + DolphinMainWindow* mainwindow = new DolphinMainWindow; + mainwindow->init(); + + m_mainWindows.append( mainwindow ); + return mainwindow; +} + +void DolphinApplication::removeMainWindow( DolphinMainWindow *mainwindow ) +{ + m_mainWindows.remove( mainwindow ); +} + +void DolphinApplication::refreshMainWindows() +{ + for( int i = 0; i < m_mainWindows.count(); ++i ) { + m_mainWindows[i]->refreshViews(); + } +} + +#include "dolphinapplication.moc" + diff --git a/src/dolphinapplication.h b/src/dolphinapplication.h new file mode 100644 index 000000000..a8474bd36 --- /dev/null +++ b/src/dolphinapplication.h @@ -0,0 +1,64 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * Copyright (C) 2006 by Holger 'zecke' Freyther * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + + +#ifndef _DOLPHIN_APPLICATION_H +#define _DOLPHIN_APPLICATION_H + +#include + +class DolphinMainWindow; + +/** + * + * DolphinApplication will hold application wide data which + * can be accessed. + * At first this will hold a list of DolphinMainWindows which + * we will delete on application exit. + */ + +class DolphinApplication : public KApplication { + Q_OBJECT + friend class DolphinMainWindow; +public: + DolphinApplication(); + ~DolphinApplication(); + + static DolphinApplication* app(); + + /** + * Construct a new mainwindow which is owned + * by the application. + */ + DolphinMainWindow* createMainWindow(); + void refreshMainWindows(); + +protected: + /** + * called by the MainWindow to deregister + */ + void removeMainWindow( DolphinMainWindow* ); + +private: + QList m_mainWindows; +}; + + +#endif diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp index d53aa3f17..1da2443db 100644 --- a/src/dolphincontextmenu.cpp +++ b/src/dolphincontextmenu.cpp @@ -40,7 +40,7 @@ #include #include -#include "dolphin.h" +#include "dolphinmainwindow.h" #include "dolphinview.h" #include "editbookmarkdialog.h" #include "dolphinsettings.h" @@ -79,12 +79,12 @@ void DolphinContextMenu::openViewportContextMenu() assert(m_fileInfo == 0); KMenu* popup = new KMenu(m_dolphinView); - Dolphin& dolphin = Dolphin::mainWin(); + DolphinMainWindow *dolphin = m_dolphinView->mainWindow(); // setup 'Create New' menu KMenu* createNewMenu = new KMenu(); - KAction* createFolderAction = dolphin.actionCollection()->action("create_folder"); + KAction* createFolderAction = dolphin->actionCollection()->action("create_folder"); if (createFolderAction != 0) { createFolderAction->plug(createNewMenu); } @@ -93,7 +93,7 @@ void DolphinContextMenu::openViewportContextMenu() KAction* action = 0; - Q3PtrListIterator fileGrouptIt(dolphin.fileGroupActions()); + Q3PtrListIterator fileGrouptIt(dolphin->fileGroupActions()); while ((action = fileGrouptIt.current()) != 0) { action->plug(createNewMenu); ++fileGrouptIt; @@ -104,14 +104,14 @@ void DolphinContextMenu::openViewportContextMenu() // //createNewMenu->insertSeparator(); // - //QPtrListIterator linkGroupIt(dolphin.linkGroupActions()); + //QPtrListIterator linkGroupIt(dolphin->linkGroupActions()); //while ((action = linkGroupIt.current()) != 0) { // action->plug(createNewMenu); // ++linkGroupIt; //} // //KMenu* linkToDeviceMenu = new KMenu(); - //QPtrListIterator linkToDeviceIt(dolphin.linkToDeviceActions()); + //QPtrListIterator linkToDeviceIt(dolphin->linkToDeviceActions()); //while ((action = linkToDeviceIt.current()) != 0) { // action->plug(linkToDeviceMenu); // ++linkToDeviceIt; @@ -122,19 +122,19 @@ void DolphinContextMenu::openViewportContextMenu() popup->insertItem(SmallIcon("filenew"), i18n("Create New"), createNewMenu); popup->insertSeparator(); - KAction* pasteAction = dolphin.actionCollection()->action(KStdAction::stdName(KStdAction::Paste)); + KAction* pasteAction = dolphin->actionCollection()->action(KStdAction::stdName(KStdAction::Paste)); pasteAction->plug(popup); // setup 'View Mode' menu KMenu* viewModeMenu = new KMenu(); - KAction* iconsMode = dolphin.actionCollection()->action("icons"); + KAction* iconsMode = dolphin->actionCollection()->action("icons"); iconsMode->plug(viewModeMenu); - KAction* detailsMode = dolphin.actionCollection()->action("details"); + KAction* detailsMode = dolphin->actionCollection()->action("details"); detailsMode->plug(viewModeMenu); - KAction* previewsMode = dolphin.actionCollection()->action("previews"); + KAction* previewsMode = dolphin->actionCollection()->action("previews"); previewsMode->plug(viewModeMenu); popup->insertItem(i18n("View Mode"), viewModeMenu); @@ -147,10 +147,10 @@ void DolphinContextMenu::openViewportContextMenu() QAction *activatedAction = popup->exec(m_pos); if (activatedAction == propertiesAction) { - new KPropertiesDialog(dolphin.activeView()->url()); + new KPropertiesDialog(dolphin->activeView()->url()); } else if (activatedAction == bookmarkAction) { - const KUrl& url = dolphin.activeView()->url(); + const KUrl& url = dolphin->activeView()->url(); KBookmark bookmark = EditBookmarkDialog::getBookmark(i18n("Add folder as bookmark"), url.fileName(), url, @@ -176,14 +176,14 @@ void DolphinContextMenu::openItemContextMenu() assert(m_fileInfo != 0); KMenu* popup = new KMenu(m_dolphinView); - Dolphin& dolphin = Dolphin::mainWin(); + DolphinMainWindow* dolphin = m_dolphinView->mainWindow(); const KUrl::List urls = m_dolphinView->selectedUrls(); // insert 'Cut', 'Copy' and 'Paste' const KStdAction::StdAction actionNames[] = { KStdAction::Cut, KStdAction::Copy, KStdAction::Paste }; const int count = sizeof(actionNames) / sizeof(KStdAction::StdAction); for (int i = 0; i < count; ++i) { - KAction* action = dolphin.actionCollection()->action(KStdAction::stdName(actionNames[i])); + KAction* action = dolphin->actionCollection()->action(KStdAction::stdName(actionNames[i])); if (action != 0) { action->plug(popup); } @@ -191,17 +191,17 @@ void DolphinContextMenu::openItemContextMenu() popup->insertSeparator(); // insert 'Rename' - KAction* renameAction = dolphin.actionCollection()->action("rename"); + KAction* renameAction = dolphin->actionCollection()->action("rename"); renameAction->plug(popup); // insert 'Move to Trash' for local Urls, otherwise insert 'Delete' - const KUrl& url = dolphin.activeView()->url(); + const KUrl& url = dolphin->activeView()->url(); if (url.isLocalFile()) { - KAction* moveToTrashAction = dolphin.actionCollection()->action("move_to_trash"); + KAction* moveToTrashAction = dolphin->actionCollection()->action("move_to_trash"); moveToTrashAction->plug(popup); } else { - KAction* deleteAction = dolphin.actionCollection()->action("delete"); + KAction* deleteAction = dolphin->actionCollection()->action("delete"); deleteAction->plug(popup); } @@ -225,7 +225,7 @@ void DolphinContextMenu::openItemContextMenu() // insert 'Properties...' entry popup->insertSeparator(); - KAction* propertiesAction = dolphin.actionCollection()->action("properties"); + KAction* propertiesAction = dolphin->actionCollection()->action("properties"); propertiesAction->plug(popup); QAction *activatedAction = popup->exec(m_pos); diff --git a/src/dolphiniconsview.cpp b/src/dolphiniconsview.cpp index 7cbe3297d..9372ae9e0 100644 --- a/src/dolphiniconsview.cpp +++ b/src/dolphiniconsview.cpp @@ -20,11 +20,10 @@ #include "dolphiniconsview.h" #include "dolphinview.h" -#include "dolphin.h" DolphinIconsView::DolphinIconsView(DolphinView* parent) : - QListView(parent) - , m_parentView( parent ) + QListView(parent), + m_parentView( parent ) { setResizeMode( QListView::Adjust ); } @@ -36,7 +35,7 @@ DolphinIconsView::~DolphinIconsView() void DolphinIconsView::mouseReleaseEvent(QMouseEvent *e) { QListView::mouseReleaseEvent(e); - Dolphin::mainWin().setActiveView(m_parentView); + m_parentView->declareViewActive(); } #include "dolphiniconsview.moc" diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp new file mode 100644 index 000000000..0d4667db7 --- /dev/null +++ b/src/dolphinmainwindow.cpp @@ -0,0 +1,1657 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * Copyright (C) 2006 by Stefan Monov * + * Copyright (C) 2006 by Cvetoslav Ludmiloff * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "dolphinmainwindow.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +//Added by qt3to4: +#include +#include +#include + +#include "urlnavigator.h" +#include "viewpropertiesdialog.h" +#include "viewproperties.h" +#include "dolphinsettings.h" +#include "dolphinsettingsdialog.h" +#include "dolphinstatusbar.h" +#include "dolphinapplication.h" +#include "undomanager.h" +#include "progressindicator.h" +#include "dolphinsettings.h" +#include "sidebar.h" +#include "sidebarsettings.h" +#include "generalsettings.h" +#include "dolphinapplication.h" + + +DolphinMainWindow::DolphinMainWindow() : + KMainWindow(0, "Dolphin"), + m_splitter(0), + m_sidebar(0), + m_activeView(0), + m_clipboardContainsCutData(false) +{ + m_view[PrimaryIdx] = 0; + m_view[SecondaryIdx] = 0; + + m_fileGroupActions.setAutoDelete(true); + + // TODO: the following members are not used yet. See documentation + // of DolphinMainWindow::linkGroupActions() and DolphinMainWindow::linkToDeviceActions() + // in the header file for details. + //m_linkGroupActions.setAutoDelete(true); + //m_linkToDeviceActions.setAutoDelete(true); +} + +DolphinMainWindow::~DolphinMainWindow() +{ + /* + * bye, bye managed window + */ + DolphinApplication::app()->removeMainWindow( this ); +} + +void DolphinMainWindow::setActiveView(DolphinView* view) +{ + assert((view == m_view[PrimaryIdx]) || (view == m_view[SecondaryIdx])); + if (m_activeView == view) { + return; + } + + m_activeView = view; + + updateHistory(); + updateEditActions(); + updateViewActions(); + updateGoActions(); + + setCaption(m_activeView->url().fileName()); + + emit activeViewChanged(); +} + +void DolphinMainWindow::dropUrls(const KUrl::List& urls, + const KUrl& destination) +{ + int selectedIndex = -1; + + /* KDE4-TODO + const ButtonState keyboardState = KApplication::keyboardMouseState(); + const bool shiftPressed = (keyboardState & ShiftButton) > 0; + const bool controlPressed = (keyboardState & ControlButton) > 0; + + + + if (shiftPressed && controlPressed) { + // shortcut for 'Linke Here' is used + selectedIndex = 2; + } + else if (controlPressed) { + // shortcut for 'Copy Here' is used + selectedIndex = 1; + } + else if (shiftPressed) { + // shortcut for 'Move Here' is used + selectedIndex = 0; + } + else*/ { + // no shortcut is used, hence open a popup menu + KMenu popup(this); + + popup.insertItem(SmallIcon("goto"), i18n("&Move Here") + "\t" /* KDE4-TODO: + KKey::modFlagLabel(KKey::SHIFT)*/, 0); + popup.insertItem(SmallIcon("editcopy"), i18n( "&Copy Here" ) /* KDE4-TODO + "\t" + KKey::modFlagLabel(KKey::CTRL)*/, 1); + popup.insertItem(i18n("&Link Here") /* KDE4-TODO + "\t" + KKey::modFlagLabel((KKey::ModFlag)(KKey::CTRL|KKey::SHIFT)) */, 2); + popup.insertSeparator(); + popup.insertItem(SmallIcon("stop"), i18n("Cancel"), 3); + popup.setAccel(i18n("Escape"), 3); + + /* KDE4-TODO: selectedIndex = popup.exec(QCursor::pos()); */ + popup.exec(QCursor::pos()); + selectedIndex = 0; // KD4-TODO: use QAction instead of switch below + // See libkonq/konq_operations.cc: KonqOperations::doDropFileCopy() (and doDrop, the main method) + } + + if (selectedIndex < 0) { + return; + } + + switch (selectedIndex) { + case 0: { + // 'Move Here' has been selected + updateViewProperties(urls); + moveUrls(urls, destination); + break; + } + + case 1: { + // 'Copy Here' has been selected + updateViewProperties(urls); + copyUrls(urls, destination); + break; + } + + case 2: { + // 'Link Here' has been selected + KIO::Job* job = KIO::link(urls, destination); + addPendingUndoJob(job, DolphinCommand::Link, urls, destination); + break; + } + + default: + // 'Cancel' has been selected + break; + } +} + +void DolphinMainWindow::refreshViews() +{ + const bool split = DolphinSettings::instance().generalSettings()->splitView(); + const bool isPrimaryViewActive = (m_activeView == m_view[PrimaryIdx]); + KUrl url; + for (int i = PrimaryIdx; i <= SecondaryIdx; ++i) { + if (m_view[i] != 0) { + url = m_view[i]->url(); + + // delete view instance... + m_view[i]->close(); + m_view[i]->deleteLater(); + m_view[i] = 0; + } + + if (split || (i == PrimaryIdx)) { + // ... and recreate it + ViewProperties props(url); + m_view[i] = new DolphinView(this, + m_splitter, + url, + props.viewMode(), + props.isShowHiddenFilesEnabled()); + m_view[i]->show(); + } + } + + m_activeView = isPrimaryViewActive ? m_view[PrimaryIdx] : m_view[SecondaryIdx]; + assert(m_activeView != 0); + + updateViewActions(); + emit activeViewChanged(); +} + +void DolphinMainWindow::slotHistoryChanged() +{ + updateHistory(); +} + +void DolphinMainWindow::slotUrlChanged(const KUrl& url) +{ + updateEditActions(); + updateGoActions(); + setCaption(url.fileName()); +} + +void DolphinMainWindow::slotUrlChangeRequest(const KUrl& url) +{ + clearStatusBar(); + m_activeView->setUrl(url); +} + +void DolphinMainWindow::slotViewModeChanged() +{ + updateViewActions(); +} + +void DolphinMainWindow::slotShowHiddenFilesChanged() +{ + KToggleAction* showHiddenFilesAction = + static_cast(actionCollection()->action("show_hidden_files")); + showHiddenFilesAction->setChecked(m_activeView->isShowHiddenFilesEnabled()); +} + +void DolphinMainWindow::slotShowFilterBarChanged() +{ + KToggleAction* showFilterBarAction = + static_cast(actionCollection()->action("show_filter_bar")); + showFilterBarAction->setChecked(m_activeView->isFilterBarVisible()); +} + +void DolphinMainWindow::slotSortingChanged(DolphinView::Sorting sorting) +{ + KAction* action = 0; + switch (sorting) { + case DolphinView::SortByName: + action = actionCollection()->action("by_name"); + break; + case DolphinView::SortBySize: + action = actionCollection()->action("by_size"); + break; + case DolphinView::SortByDate: + action = actionCollection()->action("by_date"); + break; + default: + break; + } + + if (action != 0) { + KToggleAction* toggleAction = static_cast(action); + toggleAction->setChecked(true); + } +} + +void DolphinMainWindow::slotSortOrderChanged(Qt::SortOrder order) +{ + KToggleAction* descending = static_cast(actionCollection()->action("descending")); + const bool sortDescending = (order == Qt::Descending); + descending->setChecked(sortDescending); +} + +void DolphinMainWindow::slotSelectionChanged() +{ + updateEditActions(); + + assert(m_view[PrimaryIdx] != 0); + int selectedUrlsCount = m_view[PrimaryIdx]->selectedUrls().count(); + if (m_view[SecondaryIdx] != 0) { + selectedUrlsCount += m_view[SecondaryIdx]->selectedUrls().count(); + } + + KAction* compareFilesAction = actionCollection()->action("compare_files"); + compareFilesAction->setEnabled(selectedUrlsCount == 2); + + m_activeView->updateStatusBar(); + + emit selectionChanged(); +} + +void DolphinMainWindow::closeEvent(QCloseEvent* event) +{ + // KDE4-TODO + //KConfig* config = KGlobal::config(); + //config->setGroup("General"); + //config->writeEntry("First Run", false); + + DolphinSettings& settings = DolphinSettings::instance(); + GeneralSettings* generalSettings = settings.generalSettings(); + generalSettings->setFirstRun(false); + + SidebarSettings* sidebarSettings = settings.sidebarSettings(); + const bool isSidebarVisible = (m_sidebar != 0); + sidebarSettings->setVisible(isSidebarVisible); + if (isSidebarVisible) { + sidebarSettings->setWidth(m_sidebar->width()); + } + + settings.save(); + + KMainWindow::closeEvent(event); +} + +void DolphinMainWindow::saveProperties(KConfig* config) +{ + config->setGroup("Primary view"); + config->writeEntry("Url", m_view[PrimaryIdx]->url().url()); + config->writeEntry("Editable Url", m_view[PrimaryIdx]->isUrlEditable()); + if (m_view[SecondaryIdx] != 0) { + config->setGroup("Secondary view"); + config->writeEntry("Url", m_view[SecondaryIdx]->url().url()); + config->writeEntry("Editable Url", m_view[SecondaryIdx]->isUrlEditable()); + } +} + +void DolphinMainWindow::readProperties(KConfig* config) +{ + config->setGroup("Primary view"); + m_view[PrimaryIdx]->setUrl(config->readEntry("Url")); + m_view[PrimaryIdx]->setUrlEditable(config->readBoolEntry("Editable Url")); + if (config->hasGroup("Secondary view")) { + config->setGroup("Secondary view"); + if (m_view[SecondaryIdx] == 0) { + toggleSplitView(); + } + m_view[SecondaryIdx]->setUrl(config->readEntry("Url")); + m_view[SecondaryIdx]->setUrlEditable(config->readBoolEntry("Editable Url")); + } + else if (m_view[SecondaryIdx] != 0) { + toggleSplitView(); + } +} + +void DolphinMainWindow::createFolder() +{ + // Parts of the following code have been taken + // from the class KonqPopupMenu located in + // libqonq/konq_popupmenu.h of Konqueror. + // (Copyright (C) 2000 David Faure , + // Copyright (C) 2001 Holger Freyther ) + + clearStatusBar(); + + DolphinStatusBar* statusBar = m_activeView->statusBar(); + const KUrl baseUrl(m_activeView->url()); + + QString name(i18n("New Folder")); + baseUrl.path(KUrl::AddTrailingSlash); + + + if (baseUrl.isLocalFile() && QFileInfo(baseUrl.path(KUrl::AddTrailingSlash) + name).exists()) { + name = KIO::RenameDlg::suggestName(baseUrl, i18n("New Folder")); + } + + bool ok = false; + name = KInputDialog::getText(i18n("New Folder"), + i18n("Enter folder name:" ), + name, + &ok, + this); + + if (!ok) { + // the user has pressed 'Cancel' + return; + } + + assert(!name.isEmpty()); + + KUrl url; + if ((name[0] == '/') || (name[0] == '~')) { + url.setPath(KShell::tildeExpand(name)); + } + else { + name = KIO::encodeFileName(name); + url = baseUrl; + url.addPath(name); + } + ok = KIO::NetAccess::mkdir(url, this); + + // TODO: provide message type hint + if (ok) { + statusBar->setMessage(i18n("Created folder %1.",url.path()), + DolphinStatusBar::OperationCompleted); + + DolphinCommand command(DolphinCommand::CreateFolder, KUrl::List(), url, this); + UndoManager::instance().addCommand(command); + } + else { + // Creating of the folder has been failed. Check whether the creating + // has been failed because a folder with the same name exists... + if (KIO::NetAccess::exists(url, true, this)) { + statusBar->setMessage(i18n("A folder named %1 already exists.",url.path()), + DolphinStatusBar::Error); + } + else { + statusBar->setMessage(i18n("Creating of folder %1 failed.",url.path()), + DolphinStatusBar::Error); + } + + } +} + +void DolphinMainWindow::createFile() +{ + // Parts of the following code have been taken + // from the class KonqPopupMenu located in + // libqonq/konq_popupmenu.h of Konqueror. + // (Copyright (C) 2000 David Faure , + // Copyright (C) 2001 Holger Freyther ) + + clearStatusBar(); + + // TODO: const Entry& entry = m_createFileTemplates[QString(sender->name())]; + // should be enough. Anyway: the implemantation of [] does a linear search internally too. + KSortableList::ConstIterator it = m_createFileTemplates.begin(); + KSortableList::ConstIterator end = m_createFileTemplates.end(); + + const QString senderName(sender()->name()); + bool found = false; + CreateFileEntry entry; + while (!found && (it != end)) { + if ((*it).index() == senderName) { + entry = (*it).value(); + found = true; + } + else { + ++it; + } + } + + DolphinStatusBar* statusBar = m_activeView->statusBar(); + if (!found || !QFile::exists(entry.templatePath)) { + statusBar->setMessage(i18n("Could not create file."), DolphinStatusBar::Error); + return; + } + + // Get the source path of the template which should be copied. + // The source path is part of the Url entry of the desktop file. + const int pos = entry.templatePath.findRev('/'); + QString sourcePath(entry.templatePath.left(pos + 1)); + sourcePath += KDesktopFile(entry.templatePath, true).readPathEntry("Url"); + + QString name(i18n(entry.name.ascii())); + // Most entry names end with "..." (e. g. "HTML File..."), which is ok for + // menus but no good choice for a new file name -> remove the dots... + name.replace("...", QString::null); + + // add the file extension to the name + name.append(sourcePath.right(sourcePath.length() - sourcePath.findRev('.'))); + + // Check whether a file with the current name already exists. If yes suggest automatically + // a unique file name (e. g. "HTML File" will be replaced by "HTML File_1"). + const KUrl viewUrl(m_activeView->url()); + const bool fileExists = viewUrl.isLocalFile() && + QFileInfo(viewUrl.path(KUrl::AddTrailingSlash) + KIO::encodeFileName(name)).exists(); + if (fileExists) { + name = KIO::RenameDlg::suggestName(viewUrl, name); + } + + // let the user change the suggested file name + bool ok = false; + name = KInputDialog::getText(entry.name, + entry.comment, + name, + &ok, + this); + if (!ok) { + // the user has pressed 'Cancel' + return; + } + + // before copying the template to the destination path check whether a file + // with the given name already exists + const QString destPath(viewUrl.pathOrUrl() + "/" + KIO::encodeFileName(name)); + const KUrl destUrl(destPath); + if (KIO::NetAccess::exists(destUrl, false, this)) { + statusBar->setMessage(i18n("A file named %1 already exists.",name), + DolphinStatusBar::Error); + return; + } + + // copy the template to the destination path + const KUrl sourceUrl(sourcePath); + KIO::CopyJob* job = KIO::copyAs(sourceUrl, destUrl); + job->setDefaultPermissions(true); + if (KIO::NetAccess::synchronousRun(job, this)) { + statusBar->setMessage(i18n("Created file %1.",name), + DolphinStatusBar::OperationCompleted); + + KUrl::List list; + list.append(sourceUrl); + DolphinCommand command(DolphinCommand::CreateFile, list, destUrl, this); + UndoManager::instance().addCommand(command); + + } + else { + statusBar->setMessage(i18n("Creating of file %1 failed.",name), + DolphinStatusBar::Error); + } +} + +void DolphinMainWindow::rename() +{ + clearStatusBar(); + m_activeView->renameSelectedItems(); +} + +void DolphinMainWindow::moveToTrash() +{ + clearStatusBar(); + KUrl::List selectedUrls = m_activeView->selectedUrls(); + KIO::Job* job = KIO::trash(selectedUrls); + addPendingUndoJob(job, DolphinCommand::Trash, selectedUrls, m_activeView->url()); +} + +void DolphinMainWindow::deleteItems() +{ + clearStatusBar(); + + KUrl::List list = m_activeView->selectedUrls(); + const uint itemCount = list.count(); + assert(itemCount >= 1); + + QString text; + if (itemCount > 1) { + text = i18n("Do you really want to delete the %1 selected items?",itemCount); + } + else { + const KUrl& url = list.first(); + text = i18n("Do you really want to delete '%1'?",url.fileName()); + } + + const bool del = KMessageBox::warningContinueCancel(this, + text, + QString::null, + KGuiItem(i18n("Delete"), SmallIcon("editdelete")) + ) == KMessageBox::Continue; + if (del) { + KIO::Job* job = KIO::del(list); + connect(job, SIGNAL(result(KJob*)), + this, SLOT(slotHandleJobError(KJob*))); + connect(job, SIGNAL(result(KJob*)), + this, SLOT(slotDeleteFileFinished(KJob*))); + } +} + +void DolphinMainWindow::properties() +{ + const KFileItemList* sourceList = m_activeView->selectedItems(); + if (sourceList == 0) { + return; + } + + KFileItemList list; + KFileItemList::const_iterator it = sourceList->begin(); + const KFileItemList::const_iterator end = sourceList->end(); + KFileItem* item = 0; + while (it != end) { + list.append(item); + ++it; + } + + new KPropertiesDialog(list, this); +} + +void DolphinMainWindow::quit() +{ + close(); +} + +void DolphinMainWindow::slotHandleJobError(KJob* job) +{ + if (job->error() != 0) { + m_activeView->statusBar()->setMessage(job->errorString(), + DolphinStatusBar::Error); + } +} + +void DolphinMainWindow::slotDeleteFileFinished(KJob* job) +{ + if (job->error() == 0) { + m_activeView->statusBar()->setMessage(i18n("Delete operation completed."), + DolphinStatusBar::OperationCompleted); + + // TODO: In opposite to the 'Move to Trash' operation in the class KFileIconView + // no rearranging of the item position is done when a file has been deleted. + // This is bypassed by reloading the view, but it might be worth to investigate + // deeper for the root of this issue. + m_activeView->reload(); + } +} + +void DolphinMainWindow::slotUndoAvailable(bool available) +{ + KAction* undoAction = actionCollection()->action(KStdAction::stdName(KStdAction::Undo)); + if (undoAction != 0) { + undoAction->setEnabled(available); + } +} + +void DolphinMainWindow::slotUndoTextChanged(const QString& text) +{ + KAction* undoAction = actionCollection()->action(KStdAction::stdName(KStdAction::Undo)); + if (undoAction != 0) { + undoAction->setText(text); + } +} + +void DolphinMainWindow::slotRedoAvailable(bool available) +{ + KAction* redoAction = actionCollection()->action(KStdAction::stdName(KStdAction::Redo)); + if (redoAction != 0) { + redoAction->setEnabled(available); + } +} + +void DolphinMainWindow::slotRedoTextChanged(const QString& text) +{ + KAction* redoAction = actionCollection()->action(KStdAction::stdName(KStdAction::Redo)); + if (redoAction != 0) { + redoAction->setText(text); + } +} + +void DolphinMainWindow::cut() +{ + // TODO: this boolean doesn't work between instances of dolphin or with konqueror or with other + // apps. The "application/x-kde-cutselection" mimetype should be used instead, see KonqMimeData + // in libkonq + m_clipboardContainsCutData = true; + /* KDE4-TODO: Q3DragObject* data = new KUrlDrag(m_activeView->selectedUrls(), + widget()); + QApplication::clipboard()->setData(data);*/ +} + +void DolphinMainWindow::copy() +{ + m_clipboardContainsCutData = false; + /* KDE4-TODO: + Q3DragObject* data = new KUrlDrag(m_activeView->selectedUrls(), + widget()); + QApplication::clipboard()->setData(data);*/ +} + +void DolphinMainWindow::paste() +{ + /* KDE4-TODO: - see KonqOperations::doPaste + QClipboard* clipboard = QApplication::clipboard(); + QMimeSource* data = clipboard->data(); + if (!KUrlDrag::canDecode(data)) { + return; + } + + clearStatusBar(); + + KUrl::List sourceUrls; + KUrlDrag::decode(data, sourceUrls); + + // per default the pasting is done into the current Url of the view + KUrl destUrl(m_activeView->url()); + + // check whether the pasting should be done into a selected directory + KUrl::List selectedUrls = m_activeView->selectedUrls(); + if (selectedUrls.count() == 1) { + const KFileItem fileItem(S_IFDIR, + KFileItem::Unknown, + selectedUrls.first(), + true); + if (fileItem.isDir()) { + // only one item is selected which is a directory, hence paste + // into this directory + destUrl = selectedUrls.first(); + } + } + + + updateViewProperties(sourceUrls); + if (m_clipboardContainsCutData) { + moveUrls(sourceUrls, destUrl); + m_clipboardContainsCutData = false; + clipboard->clear(); + } + else { + copyUrls(sourceUrls, destUrl); + }*/ +} + +void DolphinMainWindow::updatePasteAction() +{ + KAction* pasteAction = actionCollection()->action(KStdAction::stdName(KStdAction::Paste)); + if (pasteAction == 0) { + return; + } + + QString text(i18n("Paste")); + QClipboard* clipboard = QApplication::clipboard(); + QMimeSource* data = clipboard->data(); + /* KDE4-TODO: + if (KUrlDrag::canDecode(data)) { + pasteAction->setEnabled(true); + + KUrl::List urls; + KUrlDrag::decode(data, urls); + const int count = urls.count(); + if (count == 1) { + pasteAction->setText(i18n("Paste 1 File")); + } + else { + pasteAction->setText(i18n("Paste %1 Files").arg(count)); + } + } + else {*/ + pasteAction->setEnabled(false); + pasteAction->setText(i18n("Paste")); + //} + + if (pasteAction->isEnabled()) { + KUrl::List urls = m_activeView->selectedUrls(); + const uint count = urls.count(); + if (count > 1) { + // pasting should not be allowed when more than one file + // is selected + pasteAction->setEnabled(false); + } + else if (count == 1) { + // Only one file is selected. Pasting is only allowed if this + // file is a directory. + // TODO: this doesn't work with remote protocols; instead we need a + // m_activeView->selectedFileItems() to get the real KFileItems + const KFileItem fileItem(S_IFDIR, + KFileItem::Unknown, + urls.first(), + true); + pasteAction->setEnabled(fileItem.isDir()); + } + } +} + +void DolphinMainWindow::selectAll() +{ + clearStatusBar(); + m_activeView->selectAll(); +} + +void DolphinMainWindow::invertSelection() +{ + clearStatusBar(); + m_activeView->invertSelection(); +} +void DolphinMainWindow::setIconsView() +{ + m_activeView->setMode(DolphinView::IconsView); +} + +void DolphinMainWindow::setDetailsView() +{ + m_activeView->setMode(DolphinView::DetailsView); +} + +void DolphinMainWindow::setPreviewsView() +{ + m_activeView->setMode(DolphinView::PreviewsView); +} + +void DolphinMainWindow::sortByName() +{ + m_activeView->setSorting(DolphinView::SortByName); +} + +void DolphinMainWindow::sortBySize() +{ + m_activeView->setSorting(DolphinView::SortBySize); +} + +void DolphinMainWindow::sortByDate() +{ + m_activeView->setSorting(DolphinView::SortByDate); +} + +void DolphinMainWindow::toggleSortOrder() +{ + const Qt::SortOrder order = (m_activeView->sortOrder() == Qt::Ascending) ? + Qt::Descending : + Qt::Ascending; + m_activeView->setSortOrder(order); +} + +void DolphinMainWindow::toggleSplitView() +{ + if (m_view[SecondaryIdx] == 0) { + // create a secondary view + m_view[SecondaryIdx] = new DolphinView(this, + m_splitter, + m_view[PrimaryIdx]->url(), + m_view[PrimaryIdx]->mode(), + m_view[PrimaryIdx]->isShowHiddenFilesEnabled()); + m_view[SecondaryIdx]->show(); + } + else { + // remove secondary view + if (m_activeView == m_view[PrimaryIdx]) { + m_view[SecondaryIdx]->close(); + m_view[SecondaryIdx]->deleteLater(); + m_view[SecondaryIdx] = 0; + setActiveView(m_view[PrimaryIdx]); + } + else { + // The secondary view is active, hence from the users point of view + // the content of the secondary view should be moved to the primary view. + // From an implementation point of view it is more efficient to close + // the primary view and exchange the internal pointers afterwards. + m_view[PrimaryIdx]->close(); + m_view[PrimaryIdx]->deleteLater(); + m_view[PrimaryIdx] = m_view[SecondaryIdx]; + m_view[SecondaryIdx] = 0; + setActiveView(m_view[PrimaryIdx]); + } + } +} + +void DolphinMainWindow::reloadView() +{ + clearStatusBar(); + m_activeView->reload(); +} + +void DolphinMainWindow::stopLoading() +{ +} + +void DolphinMainWindow::showHiddenFiles() +{ + clearStatusBar(); + + const KToggleAction* showHiddenFilesAction = + static_cast(actionCollection()->action("show_hidden_files")); + const bool show = showHiddenFilesAction->isChecked(); + m_activeView->setShowHiddenFilesEnabled(show); +} + +void DolphinMainWindow::showFilterBar() +{ + const KToggleAction* showFilterBarAction = + static_cast(actionCollection()->action("show_filter_bar")); + const bool show = showFilterBarAction->isChecked(); + m_activeView->slotShowFilterBar(show); +} + +void DolphinMainWindow::zoomIn() +{ + m_activeView->zoomIn(); + updateViewActions(); +} + +void DolphinMainWindow::zoomOut() +{ + m_activeView->zoomOut(); + updateViewActions(); +} + +void DolphinMainWindow::toggleEditLocation() +{ + clearStatusBar(); + + KToggleAction* action = static_cast(actionCollection()->action("editable_location")); + + bool editOrBrowse = action->isChecked(); +// action->setChecked(action->setChecked); + m_activeView->setUrlEditable(editOrBrowse); +} + +void DolphinMainWindow::editLocation() +{ + KToggleAction* action = static_cast(actionCollection()->action("editable_location")); + action->setChecked(true); + m_activeView->setUrlEditable(true); +} + +void DolphinMainWindow::adjustViewProperties() +{ + clearStatusBar(); + ViewPropertiesDialog dlg(m_activeView); + dlg.exec(); +} + +void DolphinMainWindow::goBack() +{ + clearStatusBar(); + m_activeView->goBack(); +} + +void DolphinMainWindow::goForward() +{ + clearStatusBar(); + m_activeView->goForward(); +} + +void DolphinMainWindow::goUp() +{ + clearStatusBar(); + m_activeView->goUp(); +} + +void DolphinMainWindow::goHome() +{ + clearStatusBar(); + m_activeView->goHome(); +} + +void DolphinMainWindow::openTerminal() +{ + QString command("konsole --workdir \""); + command.append(m_activeView->url().path()); + command.append('\"'); + + KRun::runCommand(command, "Konsole", "konsole"); +} + +void DolphinMainWindow::findFile() +{ + KRun::run("kfind", m_activeView->url()); +} + +void DolphinMainWindow::compareFiles() +{ + // The method is only invoked if exactly 2 files have + // been selected. The selected files may be: + // - both in the primary view + // - both in the secondary view + // - one in the primary view and the other in the secondary + // view + assert(m_view[PrimaryIdx] != 0); + + KUrl urlA; + KUrl urlB; + KUrl::List urls = m_view[PrimaryIdx]->selectedUrls(); + + switch (urls.count()) { + case 0: { + assert(m_view[SecondaryIdx] != 0); + urls = m_view[SecondaryIdx]->selectedUrls(); + assert(urls.count() == 2); + urlA = urls[0]; + urlB = urls[1]; + break; + } + + case 1: { + urlA = urls[0]; + assert(m_view[SecondaryIdx] != 0); + urls = m_view[SecondaryIdx]->selectedUrls(); + assert(urls.count() == 1); + urlB = urls[0]; + break; + } + + case 2: { + urlA = urls[0]; + urlB = urls[1]; + break; + } + + default: { + // may not happen: compareFiles may only get invoked if 2 + // files are selected + assert(false); + } + } + + QString command("kompare -c \""); + command.append(urlA.pathOrUrl()); + command.append("\" \""); + command.append(urlB.pathOrUrl()); + command.append('\"'); + KRun::runCommand(command, "Kompare", "kompare"); + +} + +void DolphinMainWindow::editSettings() +{ + // TODO: make a static method for opening the settings dialog + DolphinSettingsDialog dlg(this); + dlg.exec(); +} + +void DolphinMainWindow::addUndoOperation(KJob* job) +{ + if (job->error() != 0) { + slotHandleJobError(job); + } + else { + const int id = job->progressId(); + + // set iterator to the executed command with the current id... + Q3ValueList::Iterator it = m_pendingUndoJobs.begin(); + const Q3ValueList::Iterator end = m_pendingUndoJobs.end(); + bool found = false; + while (!found && (it != end)) { + if ((*it).id == id) { + found = true; + } + else { + ++it; + } + } + + if (found) { + DolphinCommand command = (*it).command; + if (command.type() == DolphinCommand::Trash) { + // To be able to perform an undo for the 'Move to Trash' operation + // all source Urls must be updated with the trash Url. E. g. when moving + // a file "test.txt" and a second file "test.txt" to the trash, + // then the filenames in the trash are "0-test.txt" and "1-test.txt". + QMap metaData; + KIO::Job *kiojob = qobject_cast( job ); + if ( kiojob ) + { + metaData = kiojob->metaData(); + } + KUrl::List newSourceUrls; + + KUrl::List sourceUrls = command.source(); + KUrl::List::Iterator sourceIt = sourceUrls.begin(); + const KUrl::List::Iterator sourceEnd = sourceUrls.end(); + + while (sourceIt != sourceEnd) { + QMap::ConstIterator metaIt = metaData.find("trashUrl-" + (*sourceIt).path()); + if (metaIt != metaData.end()) { + newSourceUrls.append(KUrl(metaIt.data())); + } + ++sourceIt; + } + command.setSource(newSourceUrls); + } + + UndoManager::instance().addCommand(command); + m_pendingUndoJobs.erase(it); + + DolphinStatusBar* statusBar = m_activeView->statusBar(); + switch (command.type()) { + case DolphinCommand::Copy: + statusBar->setMessage(i18n("Copy operation completed."), + DolphinStatusBar::OperationCompleted); + break; + case DolphinCommand::Move: + statusBar->setMessage(i18n("Move operation completed."), + DolphinStatusBar::OperationCompleted); + break; + case DolphinCommand::Trash: + statusBar->setMessage(i18n("Move to trash operation completed."), + DolphinStatusBar::OperationCompleted); + break; + default: + break; + } + } + } +} + +void DolphinMainWindow::toggleSidebar() +{ + if (m_sidebar == 0) { + openSidebar(); + } + else { + closeSidebar(); + } + + KToggleAction* sidebarAction = static_cast(actionCollection()->action("sidebar")); + sidebarAction->setChecked(m_sidebar != 0); +} + +void DolphinMainWindow::closeSidebar() +{ + if (m_sidebar == 0) { + // the sidebar has already been closed + return; + } + + // store width of sidebar and remember that the sidebar has been closed + SidebarSettings* settings = DolphinSettings::instance().sidebarSettings(); + settings->setVisible(false); + settings->setWidth(m_sidebar->width()); + + m_sidebar->deleteLater(); + m_sidebar = 0; +} + + +void DolphinMainWindow::init() +{ + // Check whether Dolphin runs the first time. If yes then + // a proper default window size is given at the end of DolphinMainWindow::init(). + GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings(); + const bool firstRun = generalSettings->firstRun(); + + setAcceptDrops(true); + + m_splitter = new QSplitter(this); + + DolphinSettings& settings = DolphinSettings::instance(); + + KBookmarkManager* manager = settings.bookmarkManager(); + assert(manager != 0); + KBookmarkGroup root = manager->root(); + if (root.first().isNull()) { + root.addBookmark(manager, i18n("Home"), settings.generalSettings()->homeUrl(), "folder_home"); + root.addBookmark(manager, i18n("Storage Media"), KUrl("media:/"), "blockdevice"); + root.addBookmark(manager, i18n("Network"), KUrl("remote:/"), "network_local"); + root.addBookmark(manager, i18n("Root"), KUrl("/"), "folder_red"); + root.addBookmark(manager, i18n("Trash"), KUrl("trash:/"), "trashcan_full"); + } + + setupActions(); + setupGUI(Keys|Save|Create|ToolBar); + + const KUrl& homeUrl = root.first().url(); + setCaption(homeUrl.fileName()); + ViewProperties props(homeUrl); + m_view[PrimaryIdx] = new DolphinView(this, + m_splitter, + homeUrl, + props.viewMode(), + props.isShowHiddenFilesEnabled()); + + m_activeView = m_view[PrimaryIdx]; + + setCentralWidget(m_splitter); + + // open sidebar + SidebarSettings* sidebarSettings = settings.sidebarSettings(); + assert(sidebarSettings != 0); + if (sidebarSettings->visible()) { + openSidebar(); + } + + createGUI(); + + stateChanged("new_file"); + setAutoSaveSettings(); + + QClipboard* clipboard = QApplication::clipboard(); + connect(clipboard, SIGNAL(dataChanged()), + this, SLOT(updatePasteAction())); + updatePasteAction(); + updateGoActions(); + + setupCreateNewMenuActions(); + + loadSettings(); + + if (firstRun) { + // assure a proper default size if Dolphin runs the first time + resize(640, 480); + } +} + +void DolphinMainWindow::loadSettings() +{ + GeneralSettings* settings = DolphinSettings::instance().generalSettings(); + + KToggleAction* splitAction = static_cast(actionCollection()->action("split_view")); + if (settings->splitView()) { + splitAction->setChecked(true); + toggleSplitView(); + } + + updateViewActions(); +} + +void DolphinMainWindow::setupActions() +{ + // setup 'File' menu + KAction* createFolder = new KAction(i18n("Folder..."), actionCollection(), "create_folder"); + createFolder->setIcon(KIcon("folder")); + createFolder->setShortcut(Qt::Key_N); + connect(createFolder, SIGNAL(triggered()), this, SLOT(createFolder())); + + KAction* rename = new KAction(i18n("Rename"), actionCollection(), "rename"); + rename->setShortcut(Qt::Key_F2); + connect(rename, SIGNAL(triggered()), this, SLOT(rename())); + + KAction* moveToTrash = new KAction(i18n("Move to Trash"), actionCollection(), "move_to_trash"); + moveToTrash->setIcon(KIcon("edittrash")); + moveToTrash->setShortcut(QKeySequence::Delete); + connect(moveToTrash, SIGNAL(triggered()), this, SLOT(moveToTrash())); + + KAction* deleteAction = new KAction(i18n("Delete"), actionCollection(), "delete"); + deleteAction->setShortcut(Qt::ALT | Qt::Key_Delete); + deleteAction->setIcon(KIcon("editdelete")); + connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItems())); + + KAction* properties = new KAction(i18n("Propert&ies"), actionCollection(), "properties"); + properties->setShortcut(Qt::Key_Alt | Qt::Key_Return); + connect(properties, SIGNAL(triggered()), this, SLOT(properties())); + + KStdAction::quit(this, SLOT(quit()), actionCollection()); + + // setup 'Edit' menu + UndoManager& undoManager = UndoManager::instance(); + KStdAction::undo(&undoManager, + SLOT(undo()), + actionCollection()); + connect(&undoManager, SIGNAL(undoAvailable(bool)), + this, SLOT(slotUndoAvailable(bool))); + connect(&undoManager, SIGNAL(undoTextChanged(const QString&)), + this, SLOT(slotUndoTextChanged(const QString&))); + + KStdAction::redo(&undoManager, + SLOT(redo()), + actionCollection()); + connect(&undoManager, SIGNAL(redoAvailable(bool)), + this, SLOT(slotRedoAvailable(bool))); + connect(&undoManager, SIGNAL(redoTextChanged(const QString&)), + this, SLOT(slotRedoTextChanged(const QString&))); + + KStdAction::cut(this, SLOT(cut()), actionCollection()); + KStdAction::copy(this, SLOT(copy()), actionCollection()); + KStdAction::paste(this, SLOT(paste()), actionCollection()); + + KAction* selectAll = new KAction(i18n("Select All"), actionCollection(), "select_all"); + selectAll->setShortcut(Qt::CTRL + Qt::Key_A); + connect(selectAll, SIGNAL(triggered()), this, SLOT(selectAll())); + + KAction* invertSelection = new KAction(i18n("Invert Selection"), actionCollection(), "invert_selection"); + invertSelection->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_A); + connect(invertSelection, SIGNAL(triggered()), this, SLOT(invertSelection())); + + // setup 'View' menu + KStdAction::zoomIn(this, + SLOT(zoomIn()), + actionCollection()); + + KStdAction::zoomOut(this, + SLOT(zoomOut()), + actionCollection()); + + KToggleAction* iconsView = new KToggleAction(i18n("Icons"), actionCollection(), "icons"); + iconsView->setShortcut(Qt::CTRL | Qt::Key_1); + iconsView->setIcon(KIcon("view_icon")); + connect(iconsView, SIGNAL(triggered()), this, SLOT(setIconsView())); + + KToggleAction* detailsView = new KToggleAction(i18n("Details"), actionCollection(), "details"); + detailsView->setShortcut(Qt::CTRL | Qt::Key_2); + detailsView->setIcon(KIcon("view_text")); + connect(detailsView, SIGNAL(triggered()), this, SLOT(setDetailsView())); + + KToggleAction* previewsView = new KToggleAction(i18n("Previews"), actionCollection(), "previews"); + previewsView->setShortcut(Qt::CTRL | Qt::Key_3); + previewsView->setIcon(KIcon("gvdirpart")); + connect(previewsView, SIGNAL(triggered()), this, SLOT(setPreviewsView())); + + QActionGroup* viewModeGroup = new QActionGroup(this); + viewModeGroup->addAction(iconsView); + viewModeGroup->addAction(detailsView); + viewModeGroup->addAction(previewsView); + + KToggleAction* sortByName = new KToggleAction(i18n("By Name"), actionCollection(), "by_name"); + connect(sortByName, SIGNAL(triggered()), this, SLOT(sortByName())); + + KToggleAction* sortBySize = new KToggleAction(i18n("By Size"), actionCollection(), "by_size"); + connect(sortBySize, SIGNAL(triggered()), this, SLOT(sortBySize())); + + KToggleAction* sortByDate = new KToggleAction(i18n("By Date"), actionCollection(), "by_date"); + connect(sortByDate, SIGNAL(triggered()), this, SLOT(sortByDate())); + + QActionGroup* sortGroup = new QActionGroup(this); + sortGroup->addAction(sortByName); + sortGroup->addAction(sortBySize); + sortGroup->addAction(sortByDate); + + KToggleAction* sortDescending = new KToggleAction(i18n("Descending"), actionCollection(), "descending"); + connect(sortDescending, SIGNAL(triggered()), this, SLOT(toggleSortOrder())); + + KToggleAction* showHiddenFiles = new KToggleAction(i18n("Show Hidden Files"), actionCollection(), "show_hidden_files"); + //showHiddenFiles->setShortcut(Qt::ALT | Qt::Key_ KDE4-TODO: what Qt-Key represents '.'? + connect(showHiddenFiles, SIGNAL(triggered()), this, SLOT(showHiddenFiles())); + + KToggleAction* split = new KToggleAction(i18n("Split View"), actionCollection(), "split_view"); + split->setShortcut(Qt::Key_F10); + split->setIcon(KIcon("view_left_right")); + connect(split, SIGNAL(triggered()), this, SLOT(toggleSplitView())); + + KAction* reload = new KAction(i18n("Reload"), "F5", actionCollection(), "reload"); + reload->setShortcut(Qt::Key_F5); + reload->setIcon(KIcon("reload")); + connect(reload, SIGNAL(triggered()), this, SLOT(reloadView())); + + KAction* stop = new KAction(i18n("Stop"), actionCollection(), "stop"); + stop->setIcon(KIcon("stop")); + connect(stop, SIGNAL(triggered()), this, SLOT(stopLoading())); + + KToggleAction* showFullLocation = new KToggleAction(i18n("Show Full Location"), actionCollection(), "editable_location"); + showFullLocation->setShortcut(Qt::CTRL | Qt::Key_L); + connect(showFullLocation, SIGNAL(triggered()), this, SLOT(toggleEditLocation())); + + KToggleAction* editLocation = new KToggleAction(i18n("Edit Location"), actionCollection(), "edit_location"); + editLocation->setShortcut(Qt::Key_F6); + connect(editLocation, SIGNAL(triggered()), this, SLOT(editLocation())); + + KToggleAction* sidebar = new KToggleAction(i18n("Sidebar"), actionCollection(), "sidebar"); + sidebar->setShortcut(Qt::Key_F9); + connect(sidebar, SIGNAL(triggered()), this, SLOT(toggleSidebar())); + + KAction* adjustViewProps = new KAction(i18n("Adjust View Properties..."), actionCollection(), "view_properties"); + connect(adjustViewProps, SIGNAL(triggered()), this, SLOT(adjustViewProperties())); + + // setup 'Go' menu + KStdAction::back(this, SLOT(goBack()), actionCollection()); + KStdAction::forward(this, SLOT(goForward()), actionCollection()); + KStdAction::up(this, SLOT(goUp()), actionCollection()); + KStdAction::home(this, SLOT(goHome()), actionCollection()); + + // setup 'Tools' menu + KAction* openTerminal = new KAction(i18n("Open Terminal"), actionCollection(), "open_terminal"); + openTerminal->setShortcut(Qt::Key_F4); + openTerminal->setIcon(KIcon("konsole")); + connect(openTerminal, SIGNAL(triggered()), this, SLOT(openTerminal())); + + KAction* findFile = new KAction(i18n("Find File..."), actionCollection(), "find_file"); + findFile->setShortcut(Qt::Key_F); + findFile->setIcon(KIcon("filefind")); + connect(findFile, SIGNAL(triggered()), this, SLOT(findFile())); + + KToggleAction* showFilterBar = new KToggleAction(i18n("Show Filter Bar"), actionCollection(), "show_filter_bar"); + showFilterBar->setShortcut(Qt::Key_Slash); + connect(showFilterBar, SIGNAL(triggered()), this, SLOT(showFilterBar())); + + KAction* compareFiles = new KAction(i18n("Compare Files"), actionCollection(), "compare_files"); + compareFiles->setIcon(KIcon("kompare")); + compareFiles->setEnabled(false); + connect(compareFiles, SIGNAL(triggered()), this, SLOT(compareFiles())); + + // setup 'Settings' menu + KStdAction::preferences(this, SLOT(editSettings()), actionCollection()); +} + +void DolphinMainWindow::setupCreateNewMenuActions() +{ + // Parts of the following code have been taken + // from the class KNewMenu located in + // libqonq/knewmenu.h of Konqueror. + // Copyright (C) 1998, 1999 David Faure + // 2003 Sven Leiber + + QStringList files = actionCollection()->instance()->dirs()->findAllResources("templates"); + for (QStringList::Iterator it = files.begin() ; it != files.end(); ++it) { + if ((*it)[0] != '.' ) { + KSimpleConfig config(*it, true); + config.setDesktopGroup(); + + // tricky solution to ensure that TextFile is at the beginning + // because this filetype is the most used (according kde-core discussion) + const QString name(config.readEntry("Name")); + QString key(name); + + const QString path(config.readPathEntry("Url")); + if (!path.endsWith("emptydir")) { + if (path.endsWith("TextFile.txt")) { + key = "1" + key; + } + else if (!KDesktopFile::isDesktopFile(path)) { + key = "2" + key; + } + else if (path.endsWith("Url.desktop")){ + key = "3" + key; + } + else if (path.endsWith("Program.desktop")){ + key = "4" + key; + } + else { + key = "5"; + } + + const QString icon(config.readEntry("Icon")); + const QString comment(config.readEntry("Comment")); + const QString type(config.readEntry("Type")); + + const QString filePath(*it); + + + if (type == "Link") { + CreateFileEntry entry; + entry.name = name; + entry.icon = icon; + entry.comment = comment; + entry.templatePath = filePath; + m_createFileTemplates.insert(key, entry); + } + } + } + } + m_createFileTemplates.sort(); + + unplugActionList("create_actions"); + KSortableList::ConstIterator it = m_createFileTemplates.begin(); + KSortableList::ConstIterator end = m_createFileTemplates.end(); + /* KDE4-TODO: don't port this code; use KNewMenu instead + while (it != end) { + CreateFileEntry entry = (*it).value(); + KAction* action = new KAction(entry.name); + action->setIcon(entry.icon); + action->setName((*it).index()); + connect(action, SIGNAL(activated()), + this, SLOT(createFile())); + + const QChar section = ((*it).index()[0]); + switch (section) { + case '1': + case '2': { + m_fileGroupActions.append(action); + break; + } + + case '3': + case '4': { + // TODO: not used yet. See documentation of DolphinMainWindow::linkGroupActions() + // and DolphinMainWindow::linkToDeviceActions() in the header file for details. + //m_linkGroupActions.append(action); + break; + } + + case '5': { + // TODO: not used yet. See documentation of DolphinMainWindow::linkGroupActions() + // and DolphinMainWindow::linkToDeviceActions() in the header file for details. + //m_linkToDeviceActions.append(action); + break; + } + default: + break; + } + ++it; + } + + plugActionList("create_file_group", m_fileGroupActions); + //plugActionList("create_link_group", m_linkGroupActions); + //plugActionList("link_to_device", m_linkToDeviceActions);*/ +} + +void DolphinMainWindow::updateHistory() +{ + int index = 0; + const Q3ValueList list = m_activeView->urlHistory(index); + + KAction* backAction = actionCollection()->action("go_back"); + if (backAction != 0) { + backAction->setEnabled(index < static_cast(list.count()) - 1); + } + + KAction* forwardAction = actionCollection()->action("go_forward"); + if (forwardAction != 0) { + forwardAction->setEnabled(index > 0); + } +} + +void DolphinMainWindow::updateEditActions() +{ + const KFileItemList* list = m_activeView->selectedItems(); + if ((list == 0) || (*list).isEmpty()) { + stateChanged("has_no_selection"); + } + else { + stateChanged("has_selection"); + + KAction* renameAction = actionCollection()->action("rename"); + if (renameAction != 0) { + renameAction->setEnabled(list->count() >= 1); + } + + bool enableMoveToTrash = true; + + KFileItemList::const_iterator it = list->begin(); + const KFileItemList::const_iterator end = list->end(); + while (it != end) { + KFileItem* item = *it; + const KUrl& url = item->url(); + // only enable the 'Move to Trash' action for local files + if (!url.isLocalFile()) { + enableMoveToTrash = false; + } + ++it; + } + + KAction* moveToTrashAction = actionCollection()->action("move_to_trash"); + moveToTrashAction->setEnabled(enableMoveToTrash); + } + updatePasteAction(); +} + +void DolphinMainWindow::updateViewActions() +{ + KAction* zoomInAction = actionCollection()->action(KStdAction::stdName(KStdAction::ZoomIn)); + if (zoomInAction != 0) { + zoomInAction->setEnabled(m_activeView->isZoomInPossible()); + } + + KAction* zoomOutAction = actionCollection()->action(KStdAction::stdName(KStdAction::ZoomOut)); + if (zoomOutAction != 0) { + zoomOutAction->setEnabled(m_activeView->isZoomOutPossible()); + } + + KAction* action = 0; + switch (m_activeView->mode()) { + case DolphinView::IconsView: + action = actionCollection()->action("icons"); + break; + case DolphinView::DetailsView: + action = actionCollection()->action("details"); + break; + case DolphinView::PreviewsView: + action = actionCollection()->action("previews"); + break; + default: + break; + } + + if (action != 0) { + KToggleAction* toggleAction = static_cast(action); + toggleAction->setChecked(true); + } + + slotSortingChanged(m_activeView->sorting()); + slotSortOrderChanged(m_activeView->sortOrder()); + + KToggleAction* showFilterBarAction = + static_cast(actionCollection()->action("show_filter_bar")); + showFilterBarAction->setChecked(m_activeView->isFilterBarVisible()); + + KToggleAction* showHiddenFilesAction = + static_cast(actionCollection()->action("show_hidden_files")); + showHiddenFilesAction->setChecked(m_activeView->isShowHiddenFilesEnabled()); + + KToggleAction* splitAction = static_cast(actionCollection()->action("split_view")); + splitAction->setChecked(m_view[SecondaryIdx] != 0); + + KToggleAction* sidebarAction = static_cast(actionCollection()->action("sidebar")); + sidebarAction->setChecked(m_sidebar != 0); +} + +void DolphinMainWindow::updateGoActions() +{ + KAction* goUpAction = actionCollection()->action(KStdAction::stdName(KStdAction::Up)); + const KUrl& currentUrl = m_activeView->url(); + goUpAction->setEnabled(currentUrl.upUrl() != currentUrl); +} + +void DolphinMainWindow::updateViewProperties(const KUrl::List& urls) +{ + if (urls.isEmpty()) { + return; + } + + // Updating the view properties might take up to several seconds + // when dragging several thousand Urls. Writing a KIO slave for this + // use case is not worth the effort, but at least the main widget + // must be disabled and a progress should be shown. + ProgressIndicator progressIndicator(this, + i18n("Updating view properties..."), + QString::null, + urls.count()); + + KUrl::List::ConstIterator end = urls.end(); + for(KUrl::List::ConstIterator it = urls.begin(); it != end; ++it) { + progressIndicator.execOperation(); + + ViewProperties props(*it); + props.save(); + } +} + +void DolphinMainWindow::copyUrls(const KUrl::List& source, const KUrl& dest) +{ + KIO::Job* job = KIO::copy(source, dest); + addPendingUndoJob(job, DolphinCommand::Copy, source, dest); +} + +void DolphinMainWindow::moveUrls(const KUrl::List& source, const KUrl& dest) +{ + KIO::Job* job = KIO::move(source, dest); + addPendingUndoJob(job, DolphinCommand::Move, source, dest); +} + +void DolphinMainWindow::addPendingUndoJob(KIO::Job* job, + DolphinCommand::Type commandType, + const KUrl::List& source, + const KUrl& dest) +{ + connect(job, SIGNAL(result(KJob*)), + this, SLOT(addUndoOperation(KJob*))); + + UndoInfo undoInfo; + undoInfo.id = job->progressId(); + undoInfo.command = DolphinCommand(commandType, source, dest, this); + m_pendingUndoJobs.append(undoInfo); +} + +void DolphinMainWindow::clearStatusBar() +{ + m_activeView->statusBar()->clear(); +} + +void DolphinMainWindow::openSidebar() +{ + if (m_sidebar != 0) { + // the sidebar is already open + return; + } + + m_sidebar = new Sidebar(this, m_splitter); + m_sidebar->show(); + + connect(m_sidebar, SIGNAL(urlChanged(const KUrl&)), + this, SLOT(slotUrlChangeRequest(const KUrl&))); + m_splitter->setCollapsible(m_sidebar, false); + m_splitter->setResizeMode(m_sidebar, QSplitter::KeepSize); + m_splitter->moveToFirst(m_sidebar); + + SidebarSettings* settings = DolphinSettings::instance().sidebarSettings(); + settings->setVisible(true); +} + +#include "dolphinmainwindow.moc" diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h new file mode 100644 index 000000000..6e9f75b7f --- /dev/null +++ b/src/dolphinmainwindow.h @@ -0,0 +1,451 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * Copyright (C) 2006 by Stefan Monov * + * Copyright (C) 2006 by Cvetoslav Ludmiloff * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef _DOLPHIN_MAINWINDOW_H_ +#define _DOLPHIN_MAINWINDOW_H_ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +//Added by qt3to4: +#include +#include +#include + +#include "dolphinview.h" +#include "undomanager.h" + +class KPrinter; +class KUrl; +class QLineEdit; +class KFileIconView; +class KHBox; +class Q3IconViewItem; +class QSplitter; +class KAction; +class UrlNavigator; +class Sidebar; +class DolphinApplication; + +/** + * @short Main window for Dolphin. + * + * Handles the menus, toolbars and Dolphin views. + * + * @author Peter Penz +*/ +class DolphinMainWindow: public KMainWindow +{ + Q_OBJECT + friend class DolphinApplication; +public: + virtual ~DolphinMainWindow(); + + /** + * Activates the given view, which means that + * all menu actions are applied to this view. When + * having a split view setup the nonactive view + * is usually shown in darker colors. + */ + void setActiveView(DolphinView* view); + + /** + * Returns the currently active view. See + * DolphinMainWindow::setActiveView() for more details. + */ + DolphinView* activeView() const { return m_activeView; } + + /** + * Handles the dropping of Urls to the given + * destination. A context menu with the options + * 'Move Here', 'Copy Here', 'Link Here' and + * 'Cancel' is offered to the user. + * @param urls List of Urls which have been + * dropped. + * @param destination Destination Url, where the + * list or Urls should be moved, + * copied or linked to. + */ + void dropUrls(const KUrl::List& urls, + const KUrl& destination); + + /** + * Returns 'true', if the clipboard contains data + * which has been cutted by the Cut action (Ctrl + X). + */ + bool clipboardContainsCutData() const { return m_clipboardContainsCutData; } + + /** + * Returns the list of actions which are part of the file group + * of the 'Create New...' sub menu. Usually the list contains actions + * for creating folders, text files, HTML files etc. + */ + const Q3PtrList& fileGroupActions() const { return m_fileGroupActions; } + //const QPtrList& linkGroupActions() const { return m_linkGroupActions; } + //const QPtrList& linkToDeviceActions() const { return m_linkToDeviceActions; } + + /** + * Refreshs the views of the main window by recreating them dependent from + * the given Dolphin settings. + */ + void refreshViews(); + +signals: + /** + * Is send if the active view has been changed in + * the split view mode. + */ + void activeViewChanged(); + + /** + * Is send if the selection of the currently active view has + * been changed. + */ + void selectionChanged(); + +public slots: + /** + * Updates the state of the 'Back' and 'Forward' menu + * actions corresponding the the current history. + */ + void slotHistoryChanged(); + + /** + * Updates the caption of the main window and the state + * of all menu actions which depend from a changed Url. + */ + void slotUrlChanged(const KUrl& url); + + /** + * Go to the given Url. + */ + void slotUrlChangeRequest(const KUrl& url); + + /** Updates the state of all 'View' menu actions. */ + void slotViewModeChanged(); + + /** Updates the state of the 'Show hidden files' menu action. */ + void slotShowHiddenFilesChanged(); + + /** Updates the state of the 'Show filter bar' menu action. */ + void slotShowFilterBarChanged(); + + /** Updates the state of the 'Sort by' actions. */ + void slotSortingChanged(DolphinView::Sorting sorting); + + /** Updates the state of the 'Sort Ascending/Descending' action. */ + void slotSortOrderChanged(Qt::SortOrder order); + + /** Updates the state of the 'Edit' menu actions. */ + void slotSelectionChanged(); + +protected: + /** @see QMainWindow::closeEvent */ + virtual void closeEvent(QCloseEvent* event); + + /** + * This method is called when it is time for the app to save its + * properties for session management purposes. + */ + void saveProperties(KConfig*); + + /** + * This method is called when this app is restored. The KConfig + * object points to the session management config file that was saved + * with @ref saveProperties + */ + void readProperties(KConfig*); + +private slots: + /** Opens an input dialog for creating a new folder. */ + void createFolder(); + + /** Creates a file with the MIME type given by the sender. */ + void createFile(); + + /** Renames the selected item of the active view. */ + void rename(); + + /** Moves the selected items of the active view to the trash. */ + void moveToTrash(); + + /** Deletes the selected items of the active view. */ + void deleteItems(); + + /** + * Opens the properties window for the selected items of the + * active view. The properties windows shows informations + * like name, size and permissions. + */ + void properties(); + + /** Stores all settings and quits Dolphin. */ + void quit(); + + /** + * Shows the error information of the job \a job + * in the status bar. + */ + void slotHandleJobError(KJob* job); + + /** + * Indicates in the status bar that the delete operation + * of the job \a job has been finished. + */ + void slotDeleteFileFinished(KJob* job); + + /** + * Updates the state of the 'Undo' menu action dependent + * from the parameter \a available. + */ + void slotUndoAvailable(bool available); + + /** Sets the text of the 'Undo' menu action to \a text. */ + void slotUndoTextChanged(const QString& text); + + /** + * Updates the state of the 'Redo' menu action dependent + * from the parameter \a available. + */ + void slotRedoAvailable(bool available); + + /** Sets the text of the 'Redo' menu action to \a text. */ + void slotRedoTextChanged(const QString& text); + + /** + * Copies all selected items to the clipboard and marks + * the items as cutted. + */ + void cut(); + + /** Copies all selected items to the clipboard. */ + void copy(); + + /** Pastes the clipboard data to the active view. */ + void paste(); + + /** + * Updates the text of the paste action dependent from + * the number of items which are in the clipboard. + */ + void updatePasteAction(); + + /** Selects all items from the active view. */ + void selectAll(); + + /** + * Inverts the selection of all items of the active view: + * Selected items get nonselected and nonselected items get + * selected. + */ + void invertSelection(); + + /** The current active view is switched to the icons mode. */ + void setIconsView(); + + /** The current active view is switched to the details mode. */ + void setDetailsView(); + + /** The current active view is switched to the previews mode. */ + void setPreviewsView(); + + /** The sorting of the current view should be done by the name. */ + void sortByName(); + + /** The sorting of the current view should be done by the size. */ + void sortBySize(); + + /** The sorting of the current view should be done by the date. */ + void sortByDate(); + + /** Switches between an ascending and descending sorting order. */ + void toggleSortOrder(); + + /** + * Switches between one and two views: + * If one view is visible, it will get split into two views. + * If already two views are visible, the nonactivated view gets closed. + */ + void toggleSplitView(); + + /** Reloads the current active view. */ + void reloadView(); + + /** Stops the loading process for the current active view. */ + void stopLoading(); + + /** + * Switches between showing and hiding of hidden marked files dependent + * from the current state of the 'Show Hidden Files' menu toggle action. + */ + void showHiddenFiles(); + + /** + * Switches between showing and hiding of the filter bar dependent + * from the current state of the 'Show Filter Bar' menu toggle action. + */ + void showFilterBar(); + + /** Increases the size of the current set view mode. */ + void zoomIn(); + + /** Decreases the size of the current set view mode. */ + void zoomOut(); + + /** + * Toggles between edit and brose mode of the navigation bar. + */ + void toggleEditLocation(); + + /** + * Switches to the edit mode of the navigation bar. If the edit mode is + * already active, it is assured that the navigation bar get focused. + */ + void editLocation(); + + /** + * Opens the view properties dialog, which allows to modify the properties + * of the currently active view. + */ + void adjustViewProperties(); + + /** Goes back on step of the Url history. */ + void goBack(); + + /** Goes forward one step of the Url history. */ + void goForward(); + + /** Goes up one hierarchy of the current Url. */ + void goUp(); + + /** Goes to the home Url. */ + void goHome(); + + /** Opens a terminal for the current shown directory. */ + void openTerminal(); + + /** Opens KFind for the current shown directory. */ + void findFile(); + + /** Opens Kompare for 2 selected files. */ + void compareFiles(); + + /** Opens the settings dialog for Dolphin. */ + void editSettings(); + + /** + * Adds the undo operation given by \a job + * to the UndoManager. + */ + void addUndoOperation(KJob* job); + + + void toggleSidebar(); + + /** + * Stores the current sidebar width and closes + * the sidebar. + */ + void closeSidebar(); + +private: + DolphinMainWindow(); + void init(); + void loadSettings(); + + void setupAccel(); + void setupActions(); + void setupCreateNewMenuActions(); + void updateHistory(); + void updateEditActions(); + void updateViewActions(); + void updateGoActions(); + void updateViewProperties(const KUrl::List& urls); + void copyUrls(const KUrl::List& source, const KUrl& dest); + void moveUrls(const KUrl::List& source, const KUrl& dest); + void addPendingUndoJob(KIO::Job* job, + DolphinCommand::Type commandType, + const KUrl::List& source, + const KUrl& dest); + void clearStatusBar(); + void openSidebar(); + + QSplitter* m_splitter; + Sidebar* m_sidebar; + DolphinView* m_activeView; + + /** + * DolphinMainWindowsupports only one or two views, which + * are handled internally as primary and secondary view. + */ + enum ViewIndex + { + PrimaryIdx = 0, + SecondaryIdx = 1 + }; + DolphinView* m_view[SecondaryIdx + 1]; + + /// If set to true, the clipboard contains data which should be cutted after pasting. + bool m_clipboardContainsCutData; + + /** + * Asynchronous operations like 'Move' and 'Copy' may only be added as undo + * operation after they have been finished successfully. When an asynchronous + * operation is started, it is added to a pending undo jobs list in the meantime. + * As soon as the job has been finished, the operation is added to the undo mangager. + * @see UndoManager + * @see DolphinMainWindow::addPendingUndoJob + * @see DolphinMainWindow::addUndoOperation + */ + struct UndoInfo + { + int id; + DolphinCommand command; + }; + Q3ValueList m_pendingUndoJobs; + + /** Contains meta information for creating files. */ + struct CreateFileEntry + { + QString name; + QString filePath; + QString templatePath; + QString icon; + QString comment; + }; + + Q3PtrList m_fileGroupActions; + KSortableList m_createFileTemplates; + + // TODO: not used yet. See documentation of DolphinMainWindow::linkGroupActions() + // and DolphinMainWindow::linkToDeviceActions() in for details. + //QPtrList m_linkGroupActions; + //QPtrList m_linkToDeviceActions; +}; + +#endif // _DOLPHIN_H_ + diff --git a/src/dolphinsettings.cpp b/src/dolphinsettings.cpp index ccb9442d2..f197d36f0 100644 --- a/src/dolphinsettings.cpp +++ b/src/dolphinsettings.cpp @@ -30,13 +30,14 @@ #include #include -#include "dolphin.h" #include "generalsettings.h" #include "iconsmodesettings.h" #include "previewsmodesettings.h" #include "detailsmodesettings.h" #include "sidebarsettings.h" +#include + DolphinSettings& DolphinSettings::instance() { static DolphinSettings* instance = 0; diff --git a/src/dolphinsettingsdialog.cpp b/src/dolphinsettingsdialog.cpp index e3561af48..9cfee7d4e 100644 --- a/src/dolphinsettingsdialog.cpp +++ b/src/dolphinsettingsdialog.cpp @@ -24,19 +24,21 @@ #include "generalsettingspage.h" #include "viewsettingspage.h" #include "bookmarkssettingspage.h" -#include "dolphin.h" +#include "dolphinapplication.h" +#include "dolphinmainwindow.h" //Added by qt3to4: #include -DolphinSettingsDialog::DolphinSettingsDialog() : - KPageDialog() +DolphinSettingsDialog::DolphinSettingsDialog(DolphinMainWindow* mainWindow) : + KPageDialog(), + m_mainWindow(mainWindow) { setFaceType( List); setCaption(i18n("Dolphin Preferences")); setButtons(Ok|Apply|Cancel); setDefaultButton(Ok); - m_generalSettingsPage = new GeneralSettingsPage(this); + m_generalSettingsPage = new GeneralSettingsPage(mainWindow, this); KPageWidgetItem* generalSettingsFrame = addPage(m_generalSettingsPage, i18n("General")); generalSettingsFrame->setIcon(KIcon("exec")); @@ -66,7 +68,7 @@ void DolphinSettingsDialog::applySettings() m_generalSettingsPage->applySettings(); m_viewSettingsPage->applySettings(); m_bookmarksSettingsPage->applySettings(); - Dolphin::mainWin().refreshViews(); + DolphinApplication::app()->refreshMainWindows(); } #include "dolphinsettingsdialog.moc" diff --git a/src/dolphinsettingsdialog.h b/src/dolphinsettingsdialog.h index f3e8da5c3..23072188e 100644 --- a/src/dolphinsettingsdialog.h +++ b/src/dolphinsettingsdialog.h @@ -25,6 +25,7 @@ class GeneralSettingsPage; class ViewSettingsPage; class BookmarksSettingsPage; +class DolphinMainWindow; /** * @brief Settings dialog for Dolphin. @@ -38,13 +39,14 @@ class DolphinSettingsDialog : public KPageDialog { Q_OBJECT public: - DolphinSettingsDialog(); + DolphinSettingsDialog(DolphinMainWindow* mainWindow); virtual ~DolphinSettingsDialog(); protected slots: virtual void slotButtonClicked(int button); private: + DolphinMainWindow* m_mainWindow; GeneralSettingsPage* m_generalSettingsPage; ViewSettingsPage* m_viewSettingsPage; BookmarksSettingsPage* m_bookmarksSettingsPage; diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index abc27167d..7dbebeab5 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -38,7 +38,7 @@ #include "urlnavigator.h" #include "dolphinstatusbar.h" -#include "dolphin.h" +#include "dolphinmainwindow.h" #include "dolphindirlister.h" #include "viewproperties.h" #include "dolphindetailsview.h" @@ -50,11 +50,13 @@ #include "filterbar.h" -DolphinView::DolphinView(QWidget *parent, +DolphinView::DolphinView(DolphinMainWindow *mainWindow, + QWidget *parent, const KUrl& url, Mode mode, bool showHiddenFiles) : QWidget(parent), + m_mainWindow(mainWindow), m_refreshing(false), m_showProgress(false), m_mode(mode), @@ -67,24 +69,22 @@ DolphinView::DolphinView(QWidget *parent, setFocusPolicy(Qt::StrongFocus); m_topLayout = new Q3VBoxLayout(this); - Dolphin& dolphin = Dolphin::mainWin(); - connect(this, SIGNAL(signalModeChanged()), - &dolphin, SLOT(slotViewModeChanged())); + mainWindow, SLOT(slotViewModeChanged())); connect(this, SIGNAL(signalShowHiddenFilesChanged()), - &dolphin, SLOT(slotShowHiddenFilesChanged())); + mainWindow, SLOT(slotShowHiddenFilesChanged())); connect(this, SIGNAL(signalSortingChanged(DolphinView::Sorting)), - &dolphin, SLOT(slotSortingChanged(DolphinView::Sorting))); + mainWindow, SLOT(slotSortingChanged(DolphinView::Sorting))); connect(this, SIGNAL(signalSortOrderChanged(Qt::SortOrder)), - &dolphin, SLOT(slotSortOrderChanged(Qt::SortOrder))); + mainWindow, SLOT(slotSortOrderChanged(Qt::SortOrder))); m_urlNavigator = new UrlNavigator(url, this); connect(m_urlNavigator, SIGNAL(urlChanged(const KUrl&)), this, SLOT(slotUrlChanged(const KUrl&))); connect(m_urlNavigator, SIGNAL(urlChanged(const KUrl&)), - &dolphin, SLOT(slotUrlChanged(const KUrl&))); + mainWindow, SLOT(slotUrlChanged(const KUrl&))); connect(m_urlNavigator, SIGNAL(historyChanged()), - &dolphin, SLOT(slotHistoryChanged())); + mainWindow, SLOT(slotHistoryChanged())); m_statusBar = new DolphinStatusBar(this); @@ -119,7 +119,7 @@ DolphinView::DolphinView(QWidget *parent, m_iconSize = K3Icon::SizeMedium; - m_filterBar = new FilterBar(this); + m_filterBar = new FilterBar(mainWindow, this); m_filterBar->hide(); connect(m_filterBar, SIGNAL(signalFilterChanged(const QString&)), this, SLOT(slotChangeNameFilter(const QString&))); @@ -150,12 +150,12 @@ const KUrl& DolphinView::url() const void DolphinView::requestActivation() { - Dolphin::mainWin().setActiveView(this); + mainWindow()->setActiveView(this); } bool DolphinView::isActive() const { - return (Dolphin::mainWin().activeView() == this); + return (mainWindow()->activeView() == this); } void DolphinView::setMode(Mode mode) @@ -221,7 +221,7 @@ void DolphinView::renameSelectedItems() return; } - DolphinView* view = Dolphin::mainWin().activeView(); + DolphinView* view = mainWindow()->activeView(); const QString& newName = dialog.newName(); if (newName.isEmpty()) { view->statusBar()->setMessage(i18n("The new item name is invalid."), @@ -235,7 +235,8 @@ void DolphinView::renameSelectedItems() const int urlsCount = urls.count(); ProgressIndicator* progressIndicator = - new ProgressIndicator(i18n("Renaming items..."), + new ProgressIndicator(mainWindow(), + i18n("Renaming items..."), i18n("Renaming finished."), urlsCount); @@ -262,7 +263,7 @@ void DolphinView::renameSelectedItems() else if (KIO::NetAccess::file_move(source, dest)) { // TODO: From the users point of view he executed one 'rename n files' operation, // but internally we store it as n 'rename 1 file' operations for the undo mechanism. - DolphinCommand command(DolphinCommand::Rename, source, dest); + DolphinCommand command(DolphinCommand::Rename, source, dest, mainWindow()); undoMan.addCommand(command); } } @@ -530,7 +531,7 @@ void DolphinView::rename(const KUrl& source, const QString& newName) const bool destExists = KIO::NetAccess::exists(dest, false, - Dolphin::mainWin().activeView()); + mainWindow()->activeView()); if (destExists) { // the destination already exists, hence ask the user // how to proceed... @@ -568,7 +569,7 @@ void DolphinView::rename(const KUrl& source, const QString& newName) m_statusBar->setMessage(i18n("Renamed file '%1' to '%2'.",source.fileName(), dest.fileName()), DolphinStatusBar::OperationCompleted); - DolphinCommand command(DolphinCommand::Rename, source, dest); + DolphinCommand command(DolphinCommand::Rename, source, dest, mainWindow()); UndoManager::instance().addCommand(command); } else { @@ -601,13 +602,18 @@ void DolphinView::slotUrlListDropped(QDropEvent* /* event */, } } - Dolphin::mainWin().dropUrls(urls, destination); + mainWindow()->dropUrls(urls, destination); } void DolphinView::mouseReleaseEvent(QMouseEvent* event) { QWidget::mouseReleaseEvent(event); - Dolphin::mainWin().setActiveView(this); + mainWindow()->setActiveView(this); +} + +DolphinMainWindow* DolphinView::mainWindow() const +{ + return m_mainWindow; } void DolphinView::slotUrlChanged(const KUrl& url) @@ -628,7 +634,7 @@ void DolphinView::slotUrlChanged(const KUrl& url) // created. The application does not care whether a view is represented by a // different instance, hence inform the application that the selection might have // changed so that it can update it's actions. - Dolphin::mainWin().slotSelectionChanged(); + mainWindow()->slotSelectionChanged(); emit signalUrlChanged(url); } @@ -644,7 +650,7 @@ void DolphinView::triggerIconsViewItem(Q3IconViewItem* item) // Updating the Url must be done outside the scope of this slot, // as iconview items will get deleted. QTimer::singleShot(0, this, SLOT(updateUrl())); - Dolphin::mainWin().setActiveView(this); + mainWindow()->setActiveView(this); } } @@ -795,7 +801,7 @@ void DolphinView::slotErrorMessage(const QString& msg) void DolphinView::slotGrabActivation() { - Dolphin::mainWin().setActiveView(this); + mainWindow()->setActiveView(this); } void DolphinView::slotContentsMoving(int x, int y) @@ -969,6 +975,11 @@ void DolphinView::slotShowFilterBar(bool show) } } +void DolphinView::declareViewActive() +{ + mainWindow()->setActiveView( this ); +} + void DolphinView::slotChangeNameFilter(const QString& nameFilter) { // The name filter of KDirLister does a 'hard' filtering, which diff --git a/src/dolphinview.h b/src/dolphinview.h index 5c7fb5c2c..69b0022d8 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -46,7 +46,7 @@ class Q3IconViewItem; class Q3ListViewItem; class Q3VBoxLayout; //class KFileView; -class Dolphin; +class DolphinMainWindow; class DolphinDirLister; class DolphinStatusBar; class DolphinIconsView; @@ -115,7 +115,8 @@ public: MaxSortEnum = SortByDate }; - DolphinView(QWidget* parent, + DolphinView(DolphinMainWindow* mainwindow, + QWidget *parent, const KUrl& url, Mode mode = IconsView, bool showHiddenFiles = false); @@ -326,6 +327,12 @@ public: */ bool isFilterBarVisible(); + /** + * Return the DolphinMainWindow this View belongs to. It is guranteed + * that we have one. + */ + DolphinMainWindow* mainWindow() const ; + public slots: void reload(); void slotUrlListDropped(QDropEvent* event, @@ -337,6 +344,11 @@ public slots: */ void slotShowFilterBar(bool show); + /** + * Declare this View as the activeview of the mainWindow() + */ + void declareViewActive(); + signals: /** Is emitted if Url of the view has been changed to \a url. */ void signalUrlChanged(const KUrl& url); @@ -367,8 +379,8 @@ signals: /** * Is emitted whenever the selection has been changed. The current selection can - * be retrieved by Dolphin::mainWin().activeView()->selectedItems() or by - * Dolphin::mainWin().activeView()->selectedUrls(). + * be retrieved by mainWindow()->activeView()->selectedItems() or by + * mainWindow()->activeView()->selectedUrls(). */ void signalSelectionChanged(); @@ -381,6 +393,7 @@ protected: /** @see QWidget::mouseReleaseEvent */ virtual void mouseReleaseEvent(QMouseEvent* event); + private slots: void slotUrlChanged(const KUrl& kurl); void triggerIconsViewItem(Q3IconViewItem *item); @@ -440,6 +453,7 @@ private: */ void applyModeToView(); + DolphinMainWindow *m_mainWindow; bool m_refreshing; bool m_showProgress; Mode m_mode; diff --git a/src/filterbar.cpp b/src/filterbar.cpp index 0982a61c7..f05d0d77d 100644 --- a/src/filterbar.cpp +++ b/src/filterbar.cpp @@ -29,10 +29,11 @@ #include #include -#include "dolphin.h" +#include "dolphinmainwindow.h" -FilterBar::FilterBar(QWidget *parent, const char *name) : - QWidget(parent, name) +FilterBar::FilterBar(DolphinMainWindow* mainWindow, QWidget *parent, const char *name) : + QWidget(parent, name), + m_mainWindow(mainWindow) { const int gap = 3; @@ -62,7 +63,7 @@ FilterBar::FilterBar(QWidget *parent, const char *name) : this, SIGNAL(signalFilterChanged(const QString&))); connect(m_close, SIGNAL(clicked()), this, SLOT(hide())); connect(m_close, SIGNAL(clicked()), - &Dolphin::mainWin(), SLOT(slotShowFilterBarChanged())); + mainWindow, SLOT(slotShowFilterBarChanged())); } FilterBar::~FilterBar() @@ -89,7 +90,7 @@ void FilterBar::keyReleaseEvent(QKeyEvent* event) QWidget::keyReleaseEvent(event); if ((event->key() == Qt::Key_Escape)) { hide(); - Dolphin::mainWin().slotShowFilterBarChanged(); + m_mainWindow->slotShowFilterBarChanged(); } } diff --git a/src/filterbar.h b/src/filterbar.h index 3f5c3cbfd..ef8bd52b7 100644 --- a/src/filterbar.h +++ b/src/filterbar.h @@ -25,6 +25,7 @@ class QLabel; class QToolButton; class KLineEdit; +class DolphinMainWindow; /** * @brief Provides an input field for filtering the currently shown items. @@ -36,7 +37,7 @@ class FilterBar : public QWidget Q_OBJECT public: - FilterBar(QWidget *parent = 0, const char *name = 0); + FilterBar(DolphinMainWindow* mainWindow, QWidget *parent = 0, const char *name = 0); virtual ~FilterBar(); signals: @@ -52,6 +53,7 @@ protected: virtual void keyReleaseEvent(QKeyEvent* event); private: + DolphinMainWindow *m_mainWindow; QLabel* m_filter; KLineEdit* m_filterInput; QToolButton* m_close; diff --git a/src/generalsettingspage.cpp b/src/generalsettingspage.cpp index d7b72aa6a..d858906cb 100644 --- a/src/generalsettingspage.cpp +++ b/src/generalsettingspage.cpp @@ -38,12 +38,13 @@ #include #include "dolphinsettings.h" -#include "dolphin.h" +#include "dolphinmainwindow.h" #include "dolphinview.h" #include "generalsettings.h" -GeneralSettingsPage::GeneralSettingsPage(QWidget* parent) : +GeneralSettingsPage::GeneralSettingsPage(DolphinMainWindow* mainWin,QWidget* parent) : SettingsPageBase(parent), + m_mainWindow(mainWin), m_homeUrl(0), m_startSplit(0), m_startEditable(0) @@ -158,7 +159,7 @@ void GeneralSettingsPage::selectHomeUrl() void GeneralSettingsPage::useCurrentLocation() { - const DolphinView* view = Dolphin::mainWin().activeView(); + const DolphinView* view = m_mainWindow->activeView(); m_homeUrl->setText(view->url().prettyUrl()); } diff --git a/src/generalsettingspage.h b/src/generalsettingspage.h index 246b150ed..f5e952b2f 100644 --- a/src/generalsettingspage.h +++ b/src/generalsettingspage.h @@ -24,6 +24,7 @@ class QLineEdit; class QRadioButton; class QCheckBox; +class DolphinMainWindow; /** * @brief Page for the 'General' settings of the Dolphin settings dialog. @@ -38,7 +39,7 @@ class GeneralSettingsPage : public SettingsPageBase Q_OBJECT public: - GeneralSettingsPage(QWidget* parent); + GeneralSettingsPage(DolphinMainWindow* mainWindow, QWidget* parent); virtual ~GeneralSettingsPage(); @@ -51,6 +52,7 @@ private slots: void useDefaulLocation(); private: + DolphinMainWindow *m_mainWindow; QLineEdit* m_homeUrl; QRadioButton* m_iconsView; QRadioButton* m_detailsView; diff --git a/src/infosidebarpage.cpp b/src/infosidebarpage.cpp index bf3d5f4fc..296be528b 100644 --- a/src/infosidebarpage.cpp +++ b/src/infosidebarpage.cpp @@ -47,12 +47,12 @@ #include #include -#include "dolphin.h" +#include "dolphinmainwindow.h" #include "pixmapviewer.h" #include "dolphinsettings.h" -InfoSidebarPage::InfoSidebarPage(QWidget* parent) : - SidebarPage(parent), +InfoSidebarPage::InfoSidebarPage(DolphinMainWindow* mainWindow, QWidget* parent) : + SidebarPage(mainWindow, parent), m_multipleSelection(false), m_pendingPreview(false), m_timer(0), @@ -111,7 +111,7 @@ InfoSidebarPage::InfoSidebarPage(QWidget* parent) : layout->addWidget(m_actionBox); layout->addWidget(dummy); - connect(&Dolphin::mainWin(), SIGNAL(selectionChanged()), + connect(mainWindow, SIGNAL(selectionChanged()), this, SLOT(showItemInfo())); connectToActiveView(); @@ -153,7 +153,7 @@ void InfoSidebarPage::showItemInfo() m_multipleSelection = false; // show the preview... - DolphinView* view = Dolphin::mainWin().activeView(); + DolphinView* view = mainWindow()->activeView(); const KFileItemList* selectedItems = view->selectedItems(); if ((selectedItems != 0) && selectedItems->count() > 1) { m_multipleSelection = true; @@ -218,7 +218,7 @@ void InfoSidebarPage::gotPreview(const KFileItem* /* item */, void InfoSidebarPage::startService(int index) { - DolphinView* view = Dolphin::mainWin().activeView(); + DolphinView* view = mainWindow()->activeView(); if (view->hasSelection()) { KUrl::List selectedUrls = view->selectedUrls(); KDEDesktopMimeType::executeService(selectedUrls, m_actionsVector[index]); @@ -232,7 +232,7 @@ void InfoSidebarPage::connectToActiveView() { cancelRequest(); - DolphinView* view = Dolphin::mainWin().activeView(); + DolphinView* view = mainWindow()->activeView(); connect(view, SIGNAL(signalRequestItemInfo(const KUrl&)), this, SLOT(requestDelayedItemInfo(const KUrl&))); connect(view, SIGNAL(signalUrlChanged(const KUrl&)), @@ -279,7 +279,7 @@ void InfoSidebarPage::createMetaInfo() // The methods beginInfoLines(), addInfoLine() and endInfoLines() // take care of this. beginInfoLines(); - DolphinView* view = Dolphin::mainWin().activeView(); + DolphinView* view = mainWindow()->activeView(); if (!view->hasSelection()) { KFileItem fileItem(S_IFDIR, KFileItem::Unknown, m_shownUrl); fileItem.refresh(); @@ -430,7 +430,7 @@ void InfoSidebarPage::insertActions() // by the given Url 'url' is created and added to the list. KFileItem fileItem(S_IFDIR, KFileItem::Unknown, m_shownUrl); KFileItemList localList; - const KFileItemList* itemList = Dolphin::mainWin().activeView()->selectedItems(); + const KFileItemList* itemList = mainWindow()->activeView()->selectedItems(); if ((itemList == 0) || itemList->isEmpty()) { fileItem.refresh(); localList.append(&fileItem); diff --git a/src/infosidebarpage.h b/src/infosidebarpage.h index 8f2efcc73..edd43229e 100644 --- a/src/infosidebarpage.h +++ b/src/infosidebarpage.h @@ -59,7 +59,7 @@ class InfoSidebarPage : public SidebarPage Q_OBJECT public: - InfoSidebarPage(QWidget* parent); + InfoSidebarPage(DolphinMainWindow* mainWindow, QWidget* parent); virtual ~InfoSidebarPage(); protected: diff --git a/src/main.cpp b/src/main.cpp index eacff0cba..6d71bd720 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,7 +18,8 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include "dolphin.h" +#include "dolphinapplication.h" +#include "dolphinmainwindow.h" #include #include #include @@ -54,11 +55,11 @@ int main(int argc, char **argv) KCmdLineArgs::init(argc, argv, &about); KCmdLineArgs::addCmdLineOptions(options); - KApplication app; + DolphinApplication app; - Dolphin& mainWin = Dolphin::mainWin(); - mainWin.show(); +#warning TODO, SessionManagement +#if 0 if (false /* KDE4-TODO: app.isSessionRestored() */) { int n = 1; while (KMainWindow::canBeRestored(n)){ @@ -66,16 +67,20 @@ int main(int argc, char **argv) ++n; } } else { +#endif + KCmdLineArgs* args = KCmdLineArgs::parsedArgs(); if (args->count() > 0) { - mainWin.activeView()->setUrl(args->url(0)); - - for (int i = 1; i < args->count(); ++i) { - KRun::run("dolphin", args->url(i)); + for (int i = 0; i < args->count(); ++i) { + DolphinMainWindow *win = app.createMainWindow(); + win->activeView()->setUrl(args->url(i)); + win->show(); } + } else { + DolphinMainWindow* mainWin = app.createMainWindow(); + mainWin->show(); } args->clear(); - } - + return app.exec(); } diff --git a/src/progressindicator.cpp b/src/progressindicator.cpp index a09552c06..b42bc2ea5 100644 --- a/src/progressindicator.cpp +++ b/src/progressindicator.cpp @@ -19,19 +19,21 @@ ***************************************************************************/ #include "progressindicator.h" -#include "dolphin.h" +#include "dolphinmainwindow.h" #include "dolphinstatusbar.h" -ProgressIndicator::ProgressIndicator(const QString& progressText, +ProgressIndicator::ProgressIndicator(DolphinMainWindow* mainWindow, + const QString& progressText, const QString& finishedText, int operationsCount) - : m_showProgress(false), + : m_mainWindow(mainWindow), + m_showProgress(false), m_operationsCount(operationsCount), m_operationsIndex(0), m_startTime(QTime::currentTime()), m_finishedText(finishedText) { - DolphinStatusBar* statusBar = Dolphin::mainWin().activeView()->statusBar(); + DolphinStatusBar* statusBar = mainWindow->activeView()->statusBar(); statusBar->clear(); statusBar->setProgressText(progressText); statusBar->setProgress(0); @@ -40,13 +42,13 @@ ProgressIndicator::ProgressIndicator(const QString& progressText, ProgressIndicator::~ProgressIndicator() { - DolphinStatusBar* statusBar = Dolphin::mainWin().activeView()->statusBar(); + DolphinStatusBar* statusBar = m_mainWindow->activeView()->statusBar(); statusBar->setProgressText(QString::null); statusBar->setProgress(100); statusBar->setMessage(m_finishedText, DolphinStatusBar::OperationCompleted); if (m_showProgress) { - Dolphin::mainWin().setEnabled(true); + m_mainWindow->setEnabled(true); } } @@ -59,7 +61,7 @@ void ProgressIndicator::execOperation() if (elapsed > 500) { // the operations took already more than 500 milliseconds, // therefore show a progress indication - Dolphin::mainWin().setEnabled(false); + m_mainWindow->setEnabled(false); m_showProgress = true; } } @@ -69,8 +71,9 @@ void ProgressIndicator::execOperation() if (m_startTime.msecsTo(currentTime) > 100) { m_startTime = currentTime; - DolphinStatusBar* statusBar = Dolphin::mainWin().activeView()->statusBar(); + DolphinStatusBar* statusBar = m_mainWindow->activeView()->statusBar(); statusBar->setProgress((m_operationsIndex * 100) / m_operationsCount); +#warning "EVIL, DANGER, FIRE" kapp->processEvents(); statusBar->repaint(); } diff --git a/src/progressindicator.h b/src/progressindicator.h index cc5c64ad4..637ca10ec 100644 --- a/src/progressindicator.h +++ b/src/progressindicator.h @@ -22,6 +22,8 @@ #include +class DolphinMainWindow; + /** * Allows to show a progress of synchronous operations. Sample code: * \code @@ -46,12 +48,14 @@ class ProgressIndicator { public: /** + * @param mainWindow The mainwindow this statusbar should operate on * @param progressText Text for the progress bar (e. g. "Loading..."). * @param finishedText Text which is displayed after the operations have been finished * (e. g. "Loading finished."). * @param operationsCount Number of operations. */ - ProgressIndicator(const QString& progressText, + ProgressIndicator(DolphinMainWindow *mainWindow, + const QString& progressText, const QString& finishedText, int operationsCount); @@ -68,6 +72,7 @@ public: void execOperation(); private: + DolphinMainWindow *m_mainWindow; bool m_showProgress; int m_operationsCount; int m_operationsIndex; diff --git a/src/sidebar.cpp b/src/sidebar.cpp index d67f68180..26cfa0c46 100644 --- a/src/sidebar.cpp +++ b/src/sidebar.cpp @@ -30,8 +30,9 @@ #include "bookmarkssidebarpage.h" #include "infosidebarpage.h" -Sidebar::Sidebar(QWidget* parent) : +Sidebar::Sidebar(DolphinMainWindow* mainWindow, QWidget* parent) : QWidget(parent), + m_mainWindow(mainWindow), m_pagesSelector(0), m_page(0), m_layout(0) @@ -83,8 +84,8 @@ void Sidebar::createPage(int index) } switch (index) { - case 0: m_page = new InfoSidebarPage(this); break; - case 1: m_page = new BookmarksSidebarPage(this); break; + case 0: m_page = new InfoSidebarPage(m_mainWindow, this); break; + case 1: m_page = new BookmarksSidebarPage(m_mainWindow, this); break; default: break; } diff --git a/src/sidebar.h b/src/sidebar.h index 772d2d4f9..6c7abab34 100644 --- a/src/sidebar.h +++ b/src/sidebar.h @@ -28,6 +28,7 @@ class KUrl; class QComboBox; class Q3VBoxLayout; class SidebarPage; +class DolphinMainWindow; /** * @brief The sidebar allows to access bookmarks, history items and TODO... @@ -39,7 +40,7 @@ class Sidebar : public QWidget Q_OBJECT public: - Sidebar(QWidget* parent); + Sidebar(DolphinMainWindow* mainwindow, QWidget* parent); virtual ~Sidebar(); virtual QSize sizeHint() const; @@ -57,6 +58,7 @@ private slots: private: int indexForName(const QString& name) const; + DolphinMainWindow *m_mainWindow; QComboBox* m_pagesSelector; SidebarPage* m_page; QVBoxLayout* m_layout; diff --git a/src/sidebarpage.cpp b/src/sidebarpage.cpp index 0b633335b..5a57ad282 100644 --- a/src/sidebarpage.cpp +++ b/src/sidebarpage.cpp @@ -18,12 +18,13 @@ ***************************************************************************/ #include "sidebarpage.h" -#include "dolphin.h" +#include "dolphinmainwindow.h" -SidebarPage::SidebarPage(QWidget* parent) : - QWidget(parent) +SidebarPage::SidebarPage(DolphinMainWindow *mainWindow, QWidget* parent) : + QWidget(parent), + m_mainWindow(mainWindow) { - connect(&Dolphin::mainWin(), SIGNAL(activeViewChanged()), + connect(mainWindow, SIGNAL(activeViewChanged()), this, SLOT(activeViewChanged())); } @@ -35,4 +36,8 @@ void SidebarPage::activeViewChanged() { } +DolphinMainWindow* SidebarPage::mainWindow() const { + return m_mainWindow; +} + #include "sidebarpage.moc" diff --git a/src/sidebarpage.h b/src/sidebarpage.h index 50a7b598f..e97b0c9cf 100644 --- a/src/sidebarpage.h +++ b/src/sidebarpage.h @@ -23,6 +23,7 @@ #include +class DolphinMainWindow; class Sidebar; /** @@ -35,7 +36,7 @@ class SidebarPage : public QWidget Q_OBJECT public: - SidebarPage(QWidget* parent); + SidebarPage(DolphinMainWindow* mainwindow, QWidget* parent); virtual ~SidebarPage(); protected slots: @@ -44,6 +45,12 @@ protected slots: * The active view can be retrieved by Dolphin::mainWin().activeView(); */ virtual void activeViewChanged(); + +protected: + DolphinMainWindow* mainWindow() const; + +private: + DolphinMainWindow *m_mainWindow; }; #endif // _SIDEBARPAGE_H_ diff --git a/src/undomanager.cpp b/src/undomanager.cpp index 4e3ec054b..7d21896e1 100644 --- a/src/undomanager.cpp +++ b/src/undomanager.cpp @@ -24,13 +24,14 @@ #include #include -#include "dolphin.h" +#include "dolphinmainwindow.h" #include "dolphinstatusbar.h" #include "progressindicator.h" DolphinCommand::DolphinCommand() : m_type(Copy), - m_macroIndex(-1) + m_macroIndex(-1), + m_mainWindow(0) { // Implementation note: DolphinCommands are stored in a QValueList, whereas // QValueList requires a default constructor of the added class. @@ -43,11 +44,13 @@ DolphinCommand::DolphinCommand() : DolphinCommand::DolphinCommand(Type type, const KUrl::List& source, - const KUrl& dest) : + const KUrl& dest, + DolphinMainWindow* mainWindow) : m_type(type), m_macroIndex(-1), m_source(source), - m_dest(dest) + m_dest(dest), + m_mainWindow(mainWindow) { } @@ -60,6 +63,7 @@ DolphinCommand& DolphinCommand::operator = (const DolphinCommand& command) m_type = command.m_type; m_source = command.m_source; m_dest = command.m_dest; + m_mainWindow = command.m_mainWindow; return *this; } @@ -124,7 +128,7 @@ void UndoManager::undo() int macroCount = 1; calcStepsCount(macroCount, progressCount); - m_progressIndicator = new ProgressIndicator(i18n("Executing undo operation..."), + m_progressIndicator = new ProgressIndicator(0, i18n("Executing undo operation..."), i18n("Executed undo operation."), progressCount); @@ -201,7 +205,7 @@ void UndoManager::undo() case DolphinCommand::CreateFolder: case DolphinCommand::CreateFile: { - KIO::NetAccess::del(command.destination(), &Dolphin::mainWin()); + KIO::NetAccess::del(command.destination(), command.mainWindow() ); break; } } @@ -211,7 +215,7 @@ void UndoManager::undo() // information to the Dolphin statusbar. connect(job, SIGNAL(percent(KIO::Job*, unsigned long)), this, SLOT(slotPercent(KIO::Job*, unsigned long))); - KIO::NetAccess::synchronousRun(job, &Dolphin::mainWin()); + KIO::NetAccess::synchronousRun(job, command.mainWindow() ); } m_progressIndicator->execOperation(); @@ -237,7 +241,8 @@ void UndoManager::redo() int macroCount = 1; calcStepsCount(macroCount, progressCount); - m_progressIndicator = new ProgressIndicator(i18n("Executing redo operation..."), +#warning "TOUGH" + m_progressIndicator = new ProgressIndicator(0, i18n("Executing redo operation..."), i18n("Executed redo operation."), progressCount); @@ -254,8 +259,6 @@ void UndoManager::redo() emit undoAvailable(true); emit undoTextChanged(i18n("Undo: %1",commandText(command))); - Dolphin& dolphin = Dolphin::mainWin(); - KUrl::List sourceUrls = command.source(); KUrl::List::Iterator it = sourceUrls.begin(); const KUrl::List::Iterator end = sourceUrls.end(); @@ -286,7 +289,7 @@ void UndoManager::redo() const QString originalFileName((*it).fileName().section('-', 1)); KUrl originalSourceUrl(destUrl + "/" + originalFileName); KIO::Job* moveToTrashJob = KIO::trash(originalSourceUrl); - KIO::NetAccess::synchronousRun(moveToTrashJob, &dolphin); + KIO::NetAccess::synchronousRun(moveToTrashJob, command.mainWindow() ); ++it; m_progressIndicator->execOperation(); @@ -295,7 +298,7 @@ void UndoManager::redo() } case DolphinCommand::CreateFolder: { - KIO::NetAccess::mkdir(command.destination(), &dolphin); + KIO::NetAccess::mkdir(command.destination(), command.mainWindow()); break; } @@ -315,7 +318,7 @@ void UndoManager::redo() // information to the Dolphin statusbar. connect(job, SIGNAL(percent(KJob*, unsigned long)), this, SLOT(slotPercent(KJob*, unsigned long))); - KIO::NetAccess::synchronousRun(job, &dolphin); + KIO::NetAccess::synchronousRun(job, command.mainWindow()); } ++m_historyIndex; diff --git a/src/undomanager.h b/src/undomanager.h index ac2c2bb37..bf9a80c90 100644 --- a/src/undomanager.h +++ b/src/undomanager.h @@ -22,11 +22,13 @@ #define UNDOMANAGER_H #include +#include #include #include #include class ProgressIndicator; +class DolphinMainWindow; /** * @short Represents a file manager command which can be undone and redone. @@ -54,7 +56,7 @@ public: }; DolphinCommand(); - DolphinCommand(Type type, const KUrl::List& source, const KUrl& dest); + DolphinCommand(Type type, const KUrl::List& source, const KUrl& dest, DolphinMainWindow* mainWindow); ~DolphinCommand(); // non-virtual DolphinCommand& operator = (const DolphinCommand& command); @@ -62,12 +64,14 @@ public: void setSource(const KUrl::List source) { m_source = source; } const KUrl::List& source() const { return m_source; } const KUrl& destination() const { return m_dest; } + DolphinMainWindow* mainWindow() const { return m_mainWindow; } private: Type m_type; int m_macroIndex; KUrl::List m_source; KUrl m_dest; + QPointer m_mainWindow; friend class UndoManager; // allow to modify m_macroIndex }; diff --git a/src/urlbutton.cpp b/src/urlbutton.cpp index a4415707a..f2bf8ccda 100644 --- a/src/urlbutton.cpp +++ b/src/urlbutton.cpp @@ -29,7 +29,7 @@ #include #include "urlnavigator.h" -#include "dolphin.h" +#include "dolphinmainwindow.h" UrlButton::UrlButton(UrlNavigator* parent) @@ -42,7 +42,7 @@ UrlButton::UrlButton(UrlNavigator* parent) setMinimumHeight(parent->minimumHeight()); connect(this, SIGNAL(clicked()), parent, SLOT(slotRequestActivation())); - connect(&Dolphin::mainWin(), SIGNAL(activeViewChanged()), + connect(parent->dolphinView()->mainWindow(), SIGNAL(activeViewChanged()), this, SLOT(update())); } diff --git a/src/urlnavigator.cpp b/src/urlnavigator.cpp index ae2e06cbd..bc2c5914e 100644 --- a/src/urlnavigator.cpp +++ b/src/urlnavigator.cpp @@ -51,7 +51,7 @@ #include #include "bookmarkselector.h" -#include "dolphin.h" +#include "dolphinmainwindow.h" #include "dolphinsettings.h" #include "dolphinstatusbar.h" #include "dolphinview.h" @@ -470,7 +470,7 @@ void UrlNavigator::updateContent() QToolTip::remove(m_toggleButton); QString path(url().pathOrUrl()); - const KAction* action = Dolphin::mainWin().actionCollection()->action("editable_location"); + const KAction* action = dolphinView()->mainWindow()->actionCollection()->action("editable_location"); // TODO: registry of default shortcuts QString shortcut = action? action->shortcut().toString() : "Ctrl+L"; if (m_toggleButton->isChecked()) { diff --git a/src/urlnavigator.h b/src/urlnavigator.h index 0b25e136d..1ae1dc040 100644 --- a/src/urlnavigator.h +++ b/src/urlnavigator.h @@ -103,7 +103,7 @@ public: int m_contentsY; }; - UrlNavigator(const KUrl& url, DolphinView* dolphinView);; + UrlNavigator(const KUrl& url, DolphinView* dolphinView); virtual ~UrlNavigator(); /** diff --git a/src/urlnavigatorbutton.cpp b/src/urlnavigatorbutton.cpp index f9c5b407b..5e800c1a2 100644 --- a/src/urlnavigatorbutton.cpp +++ b/src/urlnavigatorbutton.cpp @@ -40,7 +40,7 @@ #include "urlnavigator.h" #include "dolphinview.h" -#include "dolphin.h" +#include "dolphinmainwindow.h" UrlNavigatorButton::UrlNavigatorButton(int index, UrlNavigator* parent) : UrlButton(parent), @@ -117,9 +117,9 @@ void UrlNavigatorButton::paintEvent(QPaintEvent* event) // dimm the colors if the parent view does not have the focus const DolphinView* parentView = urlNavigator()->dolphinView(); - const Dolphin& dolphin = Dolphin::mainWin(); + const DolphinMainWindow* dolphin = parentView->mainWindow(); - const bool isActive = (dolphin.activeView() == parentView); + const bool isActive = (dolphin->activeView() == parentView); if (!isActive) { QColor dimmColor(colorGroup().background()); foregroundColor = mixColors(foregroundColor, dimmColor); -- cgit v1.3