Commit caef0da6 authored by Holger Freyther's avatar Holger Freyther
Browse files

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
parent de8273df
......@@ -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
......
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
......@@ -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);
......
......@@ -36,12 +36,11 @@
#include <klocale.h>
#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&)));
......
......@@ -41,7 +41,7 @@ class BookmarksSidebarPage : public SidebarPage
Q_OBJECT
public:
BookmarksSidebarPage(QWidget* parent);
BookmarksSidebarPage(DolphinMainWindow *mainWindow, QWidget* parent);
virtual ~BookmarksSidebarPage();
protected:
......
/***************************************************************************
* Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
* Copyright (C) 2006 by Holger 'zecke' Freyther <freyther@kde.org> *
* *
* 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<DolphinApplication*>(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"
/***************************************************************************
* Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
* Copyright (C) 2006 by Holger 'zecke' Freyther <freyther@kde.org> *
* *
* 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 <kapplication.h>
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<DolphinMainWindow*> m_mainWindows;
};
#endif
......@@ -40,7 +40,7 @@
#include <kmenu.h>
#include <kstdaction.h>
#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<KAction> fileGrouptIt(dolphin.fileGroupActions());
Q3PtrListIterator<KAction> fileGrouptIt(dolphin->fileGroupActions());
while ((action = fileGrouptIt.current()) != 0) {
action->plug(createNewMenu);
++fileGrouptIt;
......@@ -104,14 +104,14 @@ void DolphinContextMenu::openViewportContextMenu()
//
//createNewMenu->insertSeparator();
//
//QPtrListIterator<KAction> linkGroupIt(dolphin.linkGroupActions());
//QPtrListIterator<KAction> linkGroupIt(dolphin->linkGroupActions());
//while ((action = linkGroupIt.current()) != 0) {
// action->plug(createNewMenu);
// ++linkGroupIt;
//}
//
//KMenu* linkToDeviceMenu = new KMenu();
//QPtrListIterator<KAction> linkToDeviceIt(dolphin.linkToDeviceActions());
//QPtrListIterator<KAction> 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);
......
......@@ -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"
......@@ -19,8 +19,8 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef _DOLPHIN_H_
#define _DOLPHIN_H_
#ifndef _DOLPHIN_MAINWINDOW_H_
#define _DOLPHIN_MAINWINDOW_H_
#ifdef HAVE_CONFIG_H
#include <config.h>
......@@ -49,6 +49,7 @@ class QSplitter;
class KAction;
class UrlNavigator;
class Sidebar;
class DolphinApplication;
/**
* @short Main window for Dolphin.
......@@ -57,18 +58,12 @@ class Sidebar;
*
* @author Peter Penz <peter.penz@gmx.at>
*/
class Dolphin : public KMainWindow
class DolphinMainWindow: public KMainWindow
{
Q_OBJECT
friend class DolphinApplication;
public:
/**
* Returns the instance for the Dolphin main window.
*/
// KXMLGUIClient::instance() already in use :-(
static Dolphin& mainWin();
virtual ~Dolphin();
virtual ~DolphinMainWindow();
/**
* Activates the given view, which means that
......@@ -80,7 +75,7 @@ public:
/**
* Returns the currently active view. See
* Dolphin::setActiveView() for more details.
* DolphinMainWindow::setActiveView() for more details.
*/
DolphinView* activeView() const { return m_activeView; }
......@@ -378,7 +373,7 @@ private slots:
void closeSidebar();
private:
Dolphin();
DolphinMainWindow();
void init();
void loadSettings();
......@@ -404,7 +399,7 @@ private:
DolphinView* m_activeView;
/**
* Dolphin supports only one or two views, which
* DolphinMainWindowsupports only one or two views, which
* are handled internally as primary and secondary view.
*/
enum ViewIndex
......@@ -423,8 +418,8 @@ private:
* 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
* @see DolphinMainWindow::addPendingUndoJob
* @see DolphinMainWindow::addUndoOperation
*/
struct UndoInfo
{
......@@ -446,8 +441,8 @@ private:
Q3PtrList<KAction> m_fileGroupActions;
KSortableList<CreateFileEntry,QString> m_createFileTemplates;
// TODO: not used yet. See documentation of Dolphin::linkGroupActions()
// and Dolphin::linkToDeviceActions() in for details.
// TODO: not used yet. See documentation of DolphinMainWindow::linkGroupActions()
// and DolphinMainWindow::linkToDeviceActions() in for details.
//QPtrList<KAction> m_linkGroupActions;
//QPtrList<KAction> m_linkToDeviceActions;
};
......
......@@ -30,13 +30,14 @@
#include <klocale.h>
#include <kstandarddirs.h>
#include "dolphin.h"
#include "generalsettings.h"
#include "iconsmodesettings.h"
#include "previewsmodesettings.h"
#include "detailsmodesettings.h"
#include "sidebarsettings.h"
#include <Q3IconView>
DolphinSettings& DolphinSettings::instance()
{
static DolphinSettings* instance = 0;
......
......@@ -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 <QFrame>
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"
......@@ -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;
......
......@@ -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()),