mirror of
https://invent.kde.org/system/dolphin
synced 2024-08-22 01:40:02 +00:00
Dolphin is now a KUniqueApplication. A lot of thanks go to Oscar Blumberg, who submitted this patch.
svn path=/trunk/KDE/kdebase/apps/; revision=634862
This commit is contained in:
parent
fd43139134
commit
abf17941f7
|
@ -56,6 +56,12 @@ kde4_add_kcfg_files(dolphin_SRCS
|
|||
iconsmodesettings.kcfgc
|
||||
detailsmodesettings.kcfgc )
|
||||
|
||||
qt4_add_dbus_adaptor(dolphin_SRCS
|
||||
org.kde.dolphin.Application.xml
|
||||
dolphinapplication.h DolphinApplication)
|
||||
qt4_add_dbus_adaptor(dolphin_SRCS
|
||||
org.kde.dolphin.MainWindow.xml
|
||||
dolphinmainwindow.h DolphinMainWindow)
|
||||
kde4_add_executable(dolphin ${dolphin_SRCS})
|
||||
|
||||
target_link_libraries(dolphin ${KDE4_KDECORE_LIBS} ${KDE4_KDEPRINT_LIBS} konq )
|
||||
|
|
|
@ -21,8 +21,15 @@
|
|||
#include "dolphinapplication.h"
|
||||
#include "dolphinmainwindow.h"
|
||||
|
||||
DolphinApplication::DolphinApplication()
|
||||
#include <applicationadaptor.h>
|
||||
#include <kurl.h>
|
||||
#include <QDBusConnection>
|
||||
|
||||
DolphinApplication::DolphinApplication() :
|
||||
m_lastId(0)
|
||||
{
|
||||
new ApplicationAdaptor(this);
|
||||
QDBusConnection::sessionBus().registerObject("/dolphin/Application", this);
|
||||
}
|
||||
|
||||
DolphinApplication::~DolphinApplication()
|
||||
|
@ -40,13 +47,24 @@ DolphinApplication* DolphinApplication::app()
|
|||
|
||||
DolphinMainWindow* DolphinApplication::createMainWindow()
|
||||
{
|
||||
DolphinMainWindow* mainWindow = new DolphinMainWindow();
|
||||
DolphinMainWindow* mainWindow = new DolphinMainWindow(m_lastId);
|
||||
++m_lastId;
|
||||
mainWindow->init();
|
||||
|
||||
m_mainWindows.append(mainWindow);
|
||||
return mainWindow;
|
||||
}
|
||||
|
||||
int DolphinApplication::openWindow(const QString& url)
|
||||
{
|
||||
DolphinMainWindow* win = createMainWindow();
|
||||
if ((win->activeView() != 0) && !url.isEmpty()) {
|
||||
win->activeView()->setUrl(KUrl(url));
|
||||
}
|
||||
win->show();
|
||||
return win->getId();
|
||||
}
|
||||
|
||||
void DolphinApplication::removeMainWindow(DolphinMainWindow* mainWindow)
|
||||
{
|
||||
m_mainWindows.removeAll(mainWindow);
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#ifndef _DOLPHIN_APPLICATION_H
|
||||
#define _DOLPHIN_APPLICATION_H
|
||||
|
||||
#include <kapplication.h>
|
||||
#include <kuniqueapplication.h>
|
||||
|
||||
class DolphinMainWindow;
|
||||
|
||||
|
@ -32,9 +32,10 @@ class DolphinMainWindow;
|
|||
* we will delete on application exit.
|
||||
*/
|
||||
|
||||
class DolphinApplication : public KApplication
|
||||
class DolphinApplication : public KUniqueApplication
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.Application")
|
||||
friend class DolphinMainWindow;
|
||||
|
||||
public:
|
||||
|
@ -50,12 +51,16 @@ public:
|
|||
DolphinMainWindow* createMainWindow();
|
||||
void refreshMainWindows();
|
||||
|
||||
public slots:
|
||||
int openWindow(const QString& url);
|
||||
|
||||
protected:
|
||||
/** Called by the DolphinMainWindow to deregister. */
|
||||
void removeMainWindow(DolphinMainWindow* mainWindow);
|
||||
|
||||
private:
|
||||
QList<DolphinMainWindow*> m_mainWindows;
|
||||
int m_lastId;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "generalsettings.h"
|
||||
#include "viewpropertiesdialog.h"
|
||||
#include "viewproperties.h"
|
||||
#include "mainwindowadaptor.h"
|
||||
|
||||
#include <kaction.h>
|
||||
#include <kactioncollection.h>
|
||||
|
@ -70,16 +71,20 @@
|
|||
#include <QSplitter>
|
||||
#include <QDockWidget>
|
||||
|
||||
DolphinMainWindow::DolphinMainWindow() :
|
||||
DolphinMainWindow::DolphinMainWindow(int id) :
|
||||
KMainWindow(0),
|
||||
m_newMenu(0),
|
||||
m_splitter(0),
|
||||
m_activeView(0)
|
||||
m_activeView(0),
|
||||
m_id(id)
|
||||
{
|
||||
setObjectName("Dolphin");
|
||||
m_view[PrimaryIdx] = 0;
|
||||
m_view[SecondaryIdx] = 0;
|
||||
|
||||
new MainWindowAdaptor(this);
|
||||
QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id), this);
|
||||
|
||||
KonqUndoManager::incRef();
|
||||
|
||||
KonqUndoManager* undoManager = KonqUndoManager::self();
|
||||
|
@ -231,6 +236,13 @@ void DolphinMainWindow::refreshViews()
|
|||
emit activeViewChanged();
|
||||
}
|
||||
|
||||
void DolphinMainWindow::changeUrl(const QString& url)
|
||||
{
|
||||
if (activeView() != 0) {
|
||||
activeView()->setUrl(KUrl(url));
|
||||
}
|
||||
}
|
||||
|
||||
void DolphinMainWindow::slotViewModeChanged()
|
||||
{
|
||||
updateViewActions();
|
||||
|
|
|
@ -47,13 +47,14 @@ class DolphinApplication;
|
|||
* @short Main window for Dolphin.
|
||||
*
|
||||
* Handles the menus, toolbars and Dolphin views.
|
||||
*
|
||||
* @author Peter Penz <peter.penz@gmx.at>
|
||||
*/
|
||||
*/
|
||||
class DolphinMainWindow: public KMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
|
||||
Q_PROPERTY(int id READ getId SCRIPTABLE true)
|
||||
friend class DolphinApplication;
|
||||
|
||||
public:
|
||||
virtual ~DolphinMainWindow();
|
||||
|
||||
|
@ -97,6 +98,20 @@ public:
|
|||
*/
|
||||
KNewMenu* newMenu() const { return m_newMenu; }
|
||||
|
||||
public slots:
|
||||
/**
|
||||
* Returns the main windows ID, mainly used throught DBus.
|
||||
*/
|
||||
int getId() const { return m_id; }
|
||||
|
||||
/**
|
||||
* Changes the URL of the current active DolphinView to \a url.
|
||||
*/
|
||||
void changeUrl(const QString& url);
|
||||
|
||||
/** Stores all settings and quits Dolphin. */
|
||||
void quit();
|
||||
|
||||
signals:
|
||||
/**
|
||||
* Is send if the active view has been changed in
|
||||
|
@ -147,9 +162,6 @@ private slots:
|
|||
*/
|
||||
void properties();
|
||||
|
||||
/** Stores all settings and quits Dolphin. */
|
||||
void quit();
|
||||
|
||||
/**
|
||||
* Shows the error information of the job \a job
|
||||
* in the status bar.
|
||||
|
@ -338,7 +350,7 @@ private slots:
|
|||
void openNewMainWindow();
|
||||
|
||||
private:
|
||||
DolphinMainWindow();
|
||||
DolphinMainWindow(int id);
|
||||
void init();
|
||||
void loadSettings();
|
||||
|
||||
|
@ -392,6 +404,7 @@ private:
|
|||
KNewMenu* m_newMenu;
|
||||
QSplitter* m_splitter;
|
||||
DolphinView* m_activeView;
|
||||
int m_id;
|
||||
|
||||
DolphinView* m_view[SecondaryIdx + 1];
|
||||
|
||||
|
|
45
src/main.cpp
45
src/main.cpp
|
@ -24,6 +24,8 @@
|
|||
#include <kcmdlineargs.h>
|
||||
#include <klocale.h>
|
||||
#include <krun.h>
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusReply>
|
||||
|
||||
static KCmdLineOptions options[] =
|
||||
{
|
||||
|
@ -31,6 +33,18 @@ static KCmdLineOptions options[] =
|
|||
KCmdLineLastOption
|
||||
};
|
||||
|
||||
void openWindow(DolphinApplication* app, const QString& url = QString())
|
||||
{
|
||||
if (app != 0) {
|
||||
app->openWindow(url);
|
||||
return;
|
||||
}
|
||||
|
||||
static QDBusInterface dbusIface("org.kde.dolphin", "/dolphin/Application", "",
|
||||
QDBusConnection::connectToBus(QDBusConnection::SessionBus, "session_bus"));
|
||||
QDBusReply<int> reply = dbusIface.call("openWindow", url);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
KAboutData about("dolphin",
|
||||
|
@ -53,8 +67,10 @@ int main(int argc, char **argv)
|
|||
|
||||
KCmdLineArgs::init(argc, argv, &about);
|
||||
KCmdLineArgs::addCmdLineOptions(options);
|
||||
|
||||
DolphinApplication app;
|
||||
DolphinApplication *app = 0;
|
||||
if (DolphinApplication::start()) {
|
||||
app = new DolphinApplication();
|
||||
}
|
||||
|
||||
|
||||
#warning TODO, SessionManagement
|
||||
|
@ -68,18 +84,17 @@ int main(int argc, char **argv)
|
|||
} else {
|
||||
#endif
|
||||
|
||||
KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
|
||||
if (args->count() > 0) {
|
||||
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();
|
||||
KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
|
||||
if (args->count() > 0) {
|
||||
for (int i = 0; i < args->count(); ++i) {
|
||||
openWindow(app, args->arg(i));
|
||||
}
|
||||
args->clear();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
else {
|
||||
openWindow(app);
|
||||
}
|
||||
args->clear();
|
||||
if (app != 0) {
|
||||
return app->exec();
|
||||
}
|
||||
}
|
||||
|
|
9
src/org.kde.dolphin.Application.xml
Normal file
9
src/org.kde.dolphin.Application.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
|
||||
<node>
|
||||
<interface name="org.kde.dolphin.Application">
|
||||
<method name="openWindow">
|
||||
<arg type="i" direction="out"/>
|
||||
<arg name="url" type="s" direction="in"/>
|
||||
</method>
|
||||
</interface>
|
||||
</node>
|
13
src/org.kde.dolphin.MainWindow.xml
Normal file
13
src/org.kde.dolphin.MainWindow.xml
Normal file
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
|
||||
<node>
|
||||
<interface name="org.kde.dolphin.MainWindow">
|
||||
<method name="getId">
|
||||
<arg type="i" direction="out"/>
|
||||
</method>
|
||||
<method name="changeUrl">
|
||||
<arg name="url" type="s" direction="in"/>
|
||||
</method>
|
||||
<method name="quit">
|
||||
</method>
|
||||
</interface>
|
||||
</node>
|
Loading…
Reference in a new issue