]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinapplication.cpp
Fix issue that dragging pictures/videos to Google-Search/YouTube fails
[dolphin.git] / src / dolphinapplication.cpp
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 m_mainWindow = new DolphinMainWindow();
34 m_mainWindow->setAttribute(Qt::WA_DeleteOnClose);
35 m_mainWindow->show();
36
37 KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
38
39 bool resetSplitSettings = false;
40 if (args->isSet("split") && !GeneralSettings::splitView()) {
41 // Dolphin should be opened with a split view although this is not
42 // set in the GeneralSettings. Temporary adjust the setting until
43 // all passed URLs have been opened.
44 GeneralSettings::setSplitView(true);
45 resetSplitSettings = true;
46 }
47
48 const int argsCount = args->count();
49 if (argsCount > 0) {
50 QList<KUrl> urls;
51 for (int i = 0; i < argsCount; ++i) {
52 const KUrl url = args->url(i);
53 if (url.isValid()) {
54 urls.append(url);
55 }
56 }
57
58 if (!urls.isEmpty()) {
59 if (args->isSet("select")) {
60 m_mainWindow->openFiles(urls);
61 } else {
62 m_mainWindow->openDirectories(urls);
63 }
64 }
65 }
66 args->clear();
67
68 if (resetSplitSettings) {
69 GeneralSettings::setSplitView(false);
70 }
71 }
72
73 DolphinApplication::~DolphinApplication()
74 {
75 }
76
77 DolphinApplication* DolphinApplication::app()
78 {
79 return qobject_cast<DolphinApplication*>(qApp);
80 }
81
82 void DolphinApplication::restoreSession()
83 {
84 const QString className = KXmlGuiWindow::classNameOfToplevel(1);
85 if (className == QLatin1String("DolphinMainWindow")) {
86 m_mainWindow->restore(1);
87 } else {
88 kWarning() << "Unknown class " << className << " in session saved data!";
89 }
90 }
91
92 #include "dolphinapplication.moc"