add more spacing
[personal-kdebase.git] / apps / dolphin / src / dolphinapplication.cpp
blobd9dc0728ef2feb893cd22b97b9e89dee4702cd5d
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2006 by Holger 'zecke' Freyther <freyther@kde.org> *
4 * *
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. *
9 * *
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. *
14 * *
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>
27 #include <kurl.h>
28 #include <QtDBus/QDBusConnection>
29 #include <QtCore/QDir>
31 DolphinApplication::DolphinApplication() :
32 m_lastId(0)
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);
54 ++m_lastId;
55 mainWindow->init();
57 m_mainWindows.append(mainWindow);
58 return 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()) {
80 case 0:
81 if( !first || !isSessionRestored()) {
82 openWindow(KUrl());
84 break;
86 case 1:
87 openWindow(args->url(0));
88 break;
90 case 2:
91 openSplitWindow(args->url(0),args->url(1));
92 break;
94 default:
95 for (int i = 0; i < args->count(); ++i) {
96 openWindow(args->url(i));
100 first = false;
101 args->clear();
102 return 0;
105 int DolphinApplication::openWindow(const KUrl& url)
107 DolphinMainWindow* win = createMainWindow();
108 if ((win->activeViewContainer() != 0) && url.isValid()) {
109 win->activeViewContainer()->setUrl(url);
111 win->show();
112 return win->getId();
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);
125 win->show();
126 return win->getId();
130 #include "dolphinapplication.moc"