]>
cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinapplication.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2006 by Holger 'zecke' Freyther <freyther@kde.org> *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
21 #include "dolphinapplication.h"
22 #include "dolphinmainwindow.h"
23 #include "dolphinviewcontainer.h"
25 #include <applicationadaptor.h>
26 #include <kcmdlineargs.h>
28 #include <QtDBus/QDBusConnection>
30 DolphinApplication::DolphinApplication() :
33 new ApplicationAdaptor(this);
34 QDBusConnection::sessionBus().registerObject("/dolphin/Application", this);
37 DolphinApplication::~DolphinApplication()
39 // cleanup what ever is left from the MainWindows
40 while (m_mainWindows
.count() != 0) {
41 delete m_mainWindows
.takeFirst();
45 DolphinApplication
* DolphinApplication::app()
47 return qobject_cast
<DolphinApplication
*>(qApp
);
50 DolphinMainWindow
* DolphinApplication::createMainWindow()
52 DolphinMainWindow
* mainWindow
= new DolphinMainWindow(m_lastId
);
56 m_mainWindows
.append(mainWindow
);
60 void DolphinApplication::removeMainWindow(DolphinMainWindow
* mainWindow
)
62 m_mainWindows
.removeAll(mainWindow
);
65 void DolphinApplication::refreshMainWindows()
67 for (int i
= 0; i
< m_mainWindows
.count(); ++i
) {
68 m_mainWindows
[i
]->refreshViews();
72 int DolphinApplication::newInstance()
74 KCmdLineArgs
* args
= KCmdLineArgs::parsedArgs();
75 static bool first
= true;
77 switch (args
->count()) {
79 if( !first
|| !isSessionRestored()) {
85 openWindow(args
->url(0));
89 openSplitWindow(args
->url(0),args
->url(1));
93 for (int i
= 0; i
< args
->count(); ++i
) {
94 openWindow(args
->url(i
));
103 int DolphinApplication::openWindow(const KUrl
& url
)
105 DolphinMainWindow
* win
= createMainWindow();
106 if ((win
->activeViewContainer() != 0) && url
.isValid()) {
107 win
->activeViewContainer()->setUrl(url
);
113 int DolphinApplication::openSplitWindow(const KUrl
& leftUrl
, const KUrl
& rightUrl
)
115 DolphinMainWindow
* win
= createMainWindow();
116 if ((win
->activeViewContainer() != 0) && leftUrl
.isValid()) {
117 win
->activeViewContainer()->setUrl(leftUrl
);
119 win
->toggleSplitView();
120 if ((win
->activeViewContainer() != 0) && rightUrl
.isValid()){
121 win
->activeViewContainer()->setUrl(rightUrl
);
128 #include "dolphinapplication.moc"