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>
29 #include <QtCore/QDir>
31 DolphinApplication::DolphinApplication() :
34 new ApplicationAdaptor(this);
35 QDBusConnection::sessionBus().registerObject("/dolphin/Application", this);
38 DolphinApplication::~DolphinApplication()
40 // cleanup what ever is left from the MainWindows
41 while (m_mainWindows
.count() != 0) {
42 delete m_mainWindows
.takeFirst();
46 DolphinApplication
* DolphinApplication::app()
48 return qobject_cast
<DolphinApplication
*>(qApp
);
51 DolphinMainWindow
* DolphinApplication::createMainWindow()
53 DolphinMainWindow
* mainWindow
= new DolphinMainWindow(m_lastId
);
57 m_mainWindows
.append(mainWindow
);
61 void DolphinApplication::removeMainWindow(DolphinMainWindow
* mainWindow
)
63 m_mainWindows
.removeAll(mainWindow
);
66 void DolphinApplication::refreshMainWindows()
68 for (int i
= 0; i
< m_mainWindows
.count(); ++i
) {
69 m_mainWindows
[i
]->refreshViews();
73 int DolphinApplication::newInstance()
75 KCmdLineArgs::setCwd(QDir::currentPath().toUtf8());
76 KCmdLineArgs
* args
= KCmdLineArgs::parsedArgs();
77 static bool first
= true;
79 switch (args
->count()) {
81 if( !first
|| !isSessionRestored()) {
87 openWindow(args
->url(0));
91 openSplitWindow(args
->url(0),args
->url(1));
95 for (int i
= 0; i
< args
->count(); ++i
) {
96 openWindow(args
->url(i
));
105 int DolphinApplication::openWindow(const KUrl
& url
)
107 DolphinMainWindow
* win
= createMainWindow();
108 if ((win
->activeViewContainer() != 0) && url
.isValid()) {
109 win
->activeViewContainer()->setUrl(url
);
115 int DolphinApplication::openSplitWindow(const KUrl
& leftUrl
, const KUrl
& rightUrl
)
117 DolphinMainWindow
* win
= createMainWindow();
118 if ((win
->activeViewContainer() != 0) && leftUrl
.isValid()) {
119 win
->activeViewContainer()->setUrl(leftUrl
);
121 win
->toggleSplitView();
122 if ((win
->activeViewContainer() != 0) && rightUrl
.isValid()){
123 win
->activeViewContainer()->setUrl(rightUrl
);
130 #include "dolphinapplication.moc"