1 | /*************************************************************************** |
2 | * Copyright (C) 2006-2011 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 "dolphin_generalsettings.h" |
24 | |
25 | #include <KCmdLineArgs> |
26 | #include <KDebug> |
27 | #include <KRun> |
28 | #include <KUrl> |
29 | |
30 | DolphinApplication::DolphinApplication() : |
31 | m_mainWindow(0) |
32 | { |
33 | KGlobal::locale()->insertCatalog("libkonq" ); // Needed for applications using libkonq |
34 | |
35 | m_mainWindow = new DolphinMainWindow(); |
36 | m_mainWindow->setAttribute(Qt::WA_DeleteOnClose); |
37 | |
38 | KCmdLineArgs* args = KCmdLineArgs::parsedArgs(); |
39 | |
40 | const int argsCount = args->count(); |
41 | |
42 | QList<KUrl> urls; |
43 | for (int i = 0; i < argsCount; ++i) { |
44 | const KUrl url = args->url(i); |
45 | if (url.isValid()) { |
46 | urls.append(url); |
47 | } |
48 | } |
49 | |
50 | bool resetSplitSettings = false; |
51 | if (args->isSet("split" ) && !GeneralSettings::splitView()) { |
52 | // Dolphin should be opened with a split view although this is not |
53 | // set in the GeneralSettings. Temporary adjust the setting until |
54 | // all passed URLs have been opened. |
55 | GeneralSettings::setSplitView(true); |
56 | resetSplitSettings = true; |
57 | |
58 | // We need 2 URLs to open Dolphin in split view mode |
59 | if (urls.isEmpty()) { // No URL given - Open home URL in all two views |
60 | urls.append(GeneralSettings::homeUrl()); |
61 | urls.append(GeneralSettings::homeUrl()); |
62 | } else if (urls.length() == 1) { // Only 1 URL given - Open given URL in all two views |
63 | urls.append(urls.at(0)); |
64 | } |
65 | } |
66 | |
67 | if (!urls.isEmpty()) { |
68 | if (args->isSet("select" )) { |
69 | m_mainWindow->openFiles(urls); |
70 | } else { |
71 | m_mainWindow->openDirectories(urls); |
72 | } |
73 | } else { |
74 | const KUrl homeUrl(GeneralSettings::homeUrl()); |
75 | m_mainWindow->openNewActivatedTab(homeUrl); |
76 | } |
77 | |
78 | if (resetSplitSettings) { |
79 | GeneralSettings::setSplitView(false); |
80 | } |
81 | |
82 | args->clear(); |
83 | |
84 | m_mainWindow->show(); |
85 | } |
86 | |
87 | DolphinApplication::~DolphinApplication() |
88 | { |
89 | } |
90 | |
91 | DolphinApplication* DolphinApplication::app() |
92 | { |
93 | return qobject_cast<DolphinApplication*>(qApp); |
94 | } |
95 | |
96 | void DolphinApplication::restoreSession() |
97 | { |
98 | const QString className = KXmlGuiWindow::classNameOfToplevel(1); |
99 | if (className == QLatin1String("DolphinMainWindow" )) { |
100 | m_mainWindow->restore(1); |
101 | } else { |
102 | kWarning() << "Unknown class " << className << " in session saved data!" ; |
103 | } |
104 | } |
105 | |
106 | #include "dolphinapplication.moc" |
107 | |