]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinapplication.cpp
Restore the "Edit->Selection" menu from Konqueror 3 for file
[dolphin.git] / 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> *
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.h>
27 #include <kurl.h>
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.count() != 0) {
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 switch (args->count()) {
78 case 0:
79 if( !first || !isSessionRestored()) {
80 openWindow(KUrl());
81 }
82 break;
83
84 case 1:
85 openWindow(args->url(0));
86 break;
87
88 case 2:
89 openSplitWindow(args->url(0),args->url(1));
90 break;
91
92 default:
93 for (int i = 0; i < args->count(); ++i) {
94 openWindow(args->url(i));
95 }
96 }
97
98 first = false;
99 args->clear();
100 return 0;
101 }
102
103 int DolphinApplication::openWindow(const KUrl& url)
104 {
105 DolphinMainWindow* win = createMainWindow();
106 if ((win->activeViewContainer() != 0) && url.isValid()) {
107 win->activeViewContainer()->setUrl(url);
108 }
109 win->show();
110 return win->getId();
111 }
112
113 int DolphinApplication::openSplitWindow(const KUrl& leftUrl, const KUrl& rightUrl)
114 {
115 DolphinMainWindow* win = createMainWindow();
116 if ((win->activeViewContainer() != 0) && leftUrl.isValid()) {
117 win->activeViewContainer()->setUrl(leftUrl);
118 }
119 win->toggleSplitView();
120 if ((win->activeViewContainer() != 0) && rightUrl.isValid()){
121 win->activeViewContainer()->setUrl(rightUrl);
122 }
123 win->show();
124 return win->getId();
125 }
126
127
128 #include "dolphinapplication.moc"