]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinapplication.cpp
468c7a0f799c18005af6979bd019401b1a3f2b52
[dolphin.git] / src / dolphinapplication.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz19@gmail.com> *
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 ***************************************************************************/
20
21 #include "dolphinapplication.h"
22 #include "dolphinmainwindow.h"
23 #include "dolphinviewcontainer.h"
24
25 #include <applicationadaptor.h>
26 #include <KCmdLineArgs>
27 #include <KUrl>
28 #include <QtDBus/QDBusConnection>
29
30 DolphinApplication::DolphinApplication() :
31 m_lastId(0)
32 {
33 new ApplicationAdaptor(this);
34 QDBusConnection::sessionBus().registerObject("/dolphin/Application", this);
35 }
36
37 DolphinApplication::~DolphinApplication()
38 {
39 // cleanup what ever is left from the MainWindows
40 while (!m_mainWindows.isEmpty()) {
41 delete m_mainWindows.takeFirst();
42 }
43 }
44
45 DolphinApplication* DolphinApplication::app()
46 {
47 return qobject_cast<DolphinApplication*>(qApp);
48 }
49
50 DolphinMainWindow* DolphinApplication::createMainWindow()
51 {
52 DolphinMainWindow* mainWindow = new DolphinMainWindow(m_lastId);
53 ++m_lastId;
54 mainWindow->init();
55
56 m_mainWindows.append(mainWindow);
57 return mainWindow;
58 }
59
60 void DolphinApplication::removeMainWindow(DolphinMainWindow* mainWindow)
61 {
62 m_mainWindows.removeAll(mainWindow);
63 }
64
65 void DolphinApplication::refreshMainWindows()
66 {
67 for (int i = 0; i < m_mainWindows.count(); ++i) {
68 m_mainWindows[i]->refreshViews();
69 }
70 }
71
72 int DolphinApplication::newInstance()
73 {
74 KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
75 static bool first = true;
76
77 const int argsCount = args->count();
78 if ((argsCount > 0) || !first || !isSessionRestored()) {
79 QList<KUrl> urls;
80 for (int i = 0; i < argsCount; ++i) {
81 urls.append(args->url(i));
82 }
83
84 DolphinMainWindow* win = createMainWindow();
85 if (urls.count() > 0) {
86 if (args->isSet("select")) {
87 win->openFiles(urls);
88 } else {
89 win->openDirectories(urls);
90 }
91 }
92 win->show();
93 }
94
95 first = false;
96 args->clear();
97 return 0;
98 }
99
100 int DolphinApplication::openWindow(const QString& urlString)
101 {
102 DolphinMainWindow* win = createMainWindow();
103 const KUrl url(urlString);
104 if (!url.isEmpty()) {
105 win->openDirectories(QList<KUrl>() << url);
106 }
107 win->show();
108 return win->getId();
109 }
110
111 #include "dolphinapplication.moc"