From 5840fcede7178c80d137f589110d09ee20a99483 Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Fri, 26 Jan 2007 00:55:49 +0000 Subject: [PATCH] Do a custom error handling in for the 'Create New...' submenu. Thanks to David for adjusting KNewMenu :-) svn path=/trunk/playground/utils/dolphin/; revision=627220 --- src/CMakeLists.txt | 1 + src/dolphindirlister.cpp | 4 --- src/dolphindirlister.h | 2 +- src/dolphinmainwindow.cpp | 4 +-- src/dolphinmainwindow.h | 20 +++++++------- src/dolphinnewmenu.cpp | 50 +++++++++++++++++++++++++++++++++++ src/dolphinnewmenu.h | 55 +++++++++++++++++++++++++++++++++++++++ 7 files changed, 120 insertions(+), 16 deletions(-) create mode 100644 src/dolphinnewmenu.cpp create mode 100644 src/dolphinnewmenu.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 175f31f51..6a16c4901 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,6 +15,7 @@ set(dolphin_SRCS detailsviewsettingspage.cpp dolphinapplication.cpp dolphinmainwindow.cpp + dolphinnewmenu.cpp dolphinview.cpp dolphinstatusbar.cpp dolphindirlister.cpp diff --git a/src/dolphindirlister.cpp b/src/dolphindirlister.cpp index e1be8d8ba..8da962b18 100644 --- a/src/dolphindirlister.cpp +++ b/src/dolphindirlister.cpp @@ -21,9 +21,6 @@ #include "dolphindirlister.h" #include -// TODO: -#include - DolphinDirLister::DolphinDirLister() : KDirLister() { @@ -35,7 +32,6 @@ DolphinDirLister::~DolphinDirLister() void DolphinDirLister::handleError(KIO::Job* job) { - // TODO: some error texts should be adjusted manually emit errorMessage(job->errorString()); } diff --git a/src/dolphindirlister.h b/src/dolphindirlister.h index 6ee4dc600..98793727c 100644 --- a/src/dolphindirlister.h +++ b/src/dolphindirlister.h @@ -25,7 +25,7 @@ /** * @brief Extends the class KDirLister by emitting an error - * signal containing text. + * signal containing text. * * @author Peter Penz */ diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index eae9ca31a..e4fcc6a97 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -24,6 +24,7 @@ #include #include "dolphinapplication.h" +#include "dolphinnewmenu.h" #include "dolphinsettings.h" #include "dolphinsettingsdialog.h" #include "dolphinstatusbar.h" @@ -52,7 +53,6 @@ #include #include #include -#include #include #include #include @@ -937,7 +937,7 @@ void DolphinMainWindow::loadSettings() void DolphinMainWindow::setupActions() { // setup 'File' menu - m_newMenu = new KNewMenu(actionCollection(), this, "create_new"); + m_newMenu = new DolphinNewMenu(this); KMenu* menu = m_newMenu->menu(); menu->setTitle(i18n("Create New...")); menu->setIcon(SmallIcon("filenew")); diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index 6052ec5ba..2d11480a9 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -351,10 +351,6 @@ private: void connectViewSignals(int viewIndex); private: - KNewMenu* m_newMenu; - QSplitter* m_splitter; - DolphinView* m_activeView; - /** * DolphinMainWindowsupports only one or two views, which * are handled internally as primary and secondary view. @@ -364,17 +360,14 @@ private: PrimaryIdx = 0, SecondaryIdx = 1 }; - DolphinView* m_view[SecondaryIdx + 1]; - - /// remember pending undo operations until they are finished - QList m_undoOperations; /** * Implements a custom error handling for the undo manager. This * assures that all errors are shown in the status bar of Dolphin * instead as modal error dialog with an OK button. */ - class UndoUiInterface : public KonqUndoManager::UiInterface { + class UndoUiInterface : public KonqUndoManager::UiInterface + { public: UndoUiInterface(DolphinMainWindow* mainWin); virtual ~UndoUiInterface(); @@ -383,6 +376,15 @@ private: private: DolphinMainWindow* m_mainWin; }; + + KNewMenu* m_newMenu; + QSplitter* m_splitter; + DolphinView* m_activeView; + + DolphinView* m_view[SecondaryIdx + 1]; + + /// remember pending undo operations until they are finished + QList m_undoOperations; }; #endif // _DOLPHIN_H_ diff --git a/src/dolphinnewmenu.cpp b/src/dolphinnewmenu.cpp new file mode 100644 index 000000000..8592c30ad --- /dev/null +++ b/src/dolphinnewmenu.cpp @@ -0,0 +1,50 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * peter.penz@gmx.at * + * * + * 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., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "dolphinnewmenu.h" +#include "dolphinmainwindow.h" +#include "dolphinstatusbar.h" +#include "dolphinview.h" + +#include +#include + +DolphinNewMenu::DolphinNewMenu(DolphinMainWindow* mainWin) : + KNewMenu(mainWin->actionCollection(), mainWin, "create_new"), + m_mainWin(mainWin) +{ +} + +DolphinNewMenu::~DolphinNewMenu() +{ +} + +void DolphinNewMenu::slotResult(KJob* job) +{ + if (job->error()) { + DolphinStatusBar* statusBar = m_mainWin->activeView()->statusBar(); + statusBar->setMessage(job->errorString(), DolphinStatusBar::Error); + } + else { + KNewMenu::slotResult(job); + } +} + +#include "dolphinnewmenu.moc" diff --git a/src/dolphinnewmenu.h b/src/dolphinnewmenu.h new file mode 100644 index 000000000..cca7b8e37 --- /dev/null +++ b/src/dolphinnewmenu.h @@ -0,0 +1,55 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * peter.penz@gmx.at * + * * + * 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., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef DOLPHINNEWMENU_H +#define DOLPHINNEWMENU_H + +//class KActionCollection; // TODO: only required temporary because of + // missing forward declaration in knewmenu.h +#include + +class DolphinMainWindow; +class KJob; + +/** + * @brief Represents the 'Create New...' sub menu for the File menu + * and the context menu. + * + * The only difference to KNewMenu is the custom error handling. + * All errors are shown in the status bar of Dolphin + * instead as modal error dialog with an OK button. + */ +class DolphinNewMenu : public KNewMenu +{ +Q_OBJECT + +public: + DolphinNewMenu(DolphinMainWindow* mainWin); + virtual ~DolphinNewMenu(); + +protected slots: + /** @see KNewMenu::slotResult() */ + virtual void slotResult(KJob* job); + +private: + DolphinMainWindow* m_mainWin; +}; + +#endif -- 2.47.3