Changeset View
Changeset View
Standalone View
Standalone View
src/kgrapheditormain.cpp
Show All 10 Lines | 1 | /* This file is part of KGraphViewer. | |||
---|---|---|---|---|---|
11 | General Public License for more details. | 11 | General Public License for more details. | ||
12 | 12 | | |||
13 | You should have received a copy of the GNU General Public License | 13 | You should have received a copy of the GNU General Public License | ||
14 | along with this program; if not, write to the Free Software | 14 | along with this program; if not, write to the Free Software | ||
15 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | 15 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
16 | 02110-1301, USA | 16 | 02110-1301, USA | ||
17 | */ | 17 | */ | ||
18 | 18 | | |||
19 | | ||||
20 | #include "kgrapheditor.h" | 19 | #include "kgrapheditor.h" | ||
21 | #include "kgrapheditor_debug.h" | 20 | #include "kgrapheditor_debug.h" | ||
22 | 21 | | |||
23 | #include <QApplication> | 22 | #include <QApplication> | ||
24 | #include <kaboutdata.h> | | |||
25 | #include <QCommandLineParser> | | |||
26 | #include <QMessageBox> | | |||
27 | #include <QDebug> | | |||
28 | #include <iostream> | | |||
29 | #include <QDir> | | |||
30 | #include <QByteArray> | 23 | #include <QByteArray> | ||
31 | #include <QDBusInterface> | 24 | #include <QCommandLineParser> | ||
32 | #include <QDBusConnection> | 25 | #include <QDBusConnection> | ||
33 | #include <QDBusConnectionInterface> | 26 | #include <QDBusConnectionInterface> | ||
27 | #include <QDBusInterface> | ||||
34 | #include <QDBusReply> | 28 | #include <QDBusReply> | ||
29 | #include <QDebug> | ||||
30 | #include <QDir> | ||||
31 | #include <QMessageBox> | ||||
32 | #include <iostream> | ||||
33 | #include <kaboutdata.h> | ||||
35 | 34 | | |||
36 | #include <klocalizedstring.h> | | |||
37 | #include <KAboutData> | | |||
38 | #include "kgrapheditoradaptor.h" | | |||
39 | #include "config-kgraphviewer.h" | 35 | #include "config-kgraphviewer.h" | ||
36 | #include "kgrapheditoradaptor.h" | ||||
37 | #include <KAboutData> | ||||
38 | #include <klocalizedstring.h> | ||||
40 | 39 | | |||
41 | int main(int argc, char **argv) | 40 | int main(int argc, char **argv) { | ||
42 | { | | |||
43 | QApplication app(argc, argv); | 41 | QApplication app(argc, argv); | ||
44 | 42 | | |||
45 | KLocalizedString::setApplicationDomain("kgraphviewer"); | 43 | KLocalizedString::setApplicationDomain("kgraphviewer"); | ||
46 | 44 | | |||
47 | KAboutData about(QStringLiteral("kgrapheditor"), | 45 | KAboutData about( | ||
48 | i18n("KGraphEditor"), | 46 | QStringLiteral("kgrapheditor"), i18n("KGraphEditor"), | ||
49 | KGRAPHVIEWER_VERSION_STRING, | 47 | KGRAPHVIEWER_VERSION_STRING, i18n("A Graphviz DOT graph editor by KDE"), | ||
50 | i18n("A Graphviz DOT graph editor by KDE"), | 48 | KAboutLicense::GPL, i18n("(C) 2005-2010 Gaël de Chalendar")); | ||
51 | KAboutLicense::GPL, | | |||
52 | i18n("(C) 2005-2010 Gaël de Chalendar")); | | |||
53 | 49 | | |||
54 | app.setOrganizationDomain(QStringLiteral("kde.org")); | 50 | app.setOrganizationDomain(QStringLiteral("kde.org")); | ||
55 | app.setOrganizationName(QStringLiteral("KDE")); | 51 | app.setOrganizationName(QStringLiteral("KDE")); | ||
56 | 52 | | |||
57 | KAboutData::setApplicationData(about); | 53 | KAboutData::setApplicationData(about); | ||
58 | 54 | | |||
59 | app.setWindowIcon(QIcon::fromTheme("kgraphviewer", app.windowIcon())); | 55 | app.setWindowIcon(QIcon::fromTheme("kgraphviewer", app.windowIcon())); | ||
60 | 56 | | |||
61 | QCommandLineParser options; | 57 | QCommandLineParser options; | ||
62 | options.addHelpOption(); | 58 | options.addHelpOption(); | ||
63 | options.addVersionOption(); | 59 | options.addVersionOption(); | ||
64 | options.addPositionalArgument(QStringLiteral("url"), i18n("Path or URL to scan"), i18n("[url]")); | 60 | options.addPositionalArgument(QStringLiteral("url"), | ||
61 | i18n("Path or URL to scan"), i18n("[url]")); | ||||
65 | about.setupCommandLine(&options); | 62 | about.setupCommandLine(&options); | ||
66 | options.process(app); | 63 | options.process(app); | ||
67 | about.processCommandLine(&options); | 64 | about.processCommandLine(&options); | ||
68 | 65 | | |||
69 | // see if we are starting with session management | 66 | // see if we are starting with session management | ||
70 | if (app.isSessionRestored()) | 67 | if (app.isSessionRestored()) { | ||
71 | { | | |||
72 | RESTORE(KGraphEditor); | 68 | RESTORE(KGraphEditor); | ||
73 | } | 69 | } else { | ||
74 | else | | |||
75 | { | | |||
76 | // no session.. just start up normally | 70 | // no session.. just start up normally | ||
77 | QStringList args = options.positionalArguments(); | 71 | QStringList args = options.positionalArguments(); | ||
78 | 72 | | |||
79 | KGraphEditor *widget = nullptr; | 73 | KGraphEditor *widget = nullptr; | ||
80 | if ( args.count() == 0 ) | 74 | if (args.count() == 0) { | ||
81 | { | | |||
82 | widget = new KGraphEditor; | 75 | widget = new KGraphEditor; | ||
83 | new KgrapheditorAdaptor(widget); | 76 | new KgrapheditorAdaptor(widget); | ||
84 | QDBusConnection::sessionBus().registerObject("/KGraphEditor", widget); | 77 | QDBusConnection::sessionBus().registerObject("/KGraphEditor", | ||
78 | widget); | ||||
85 | widget->show(); | 79 | widget->show(); | ||
86 | } | 80 | } else { | ||
87 | else | 81 | QDBusReply<bool> reply = | ||
88 | { | 82 | QDBusConnection::sessionBus().interface()->isServiceRegistered( | ||
89 | QDBusReply<bool> reply = QDBusConnection::sessionBus().interface()->isServiceRegistered( "org.kde.kgrapheditor" ); | 83 | "org.kde.kgrapheditor"); | ||
90 | 84 | | |||
91 | bool instanceExists = reply.value(); | 85 | bool instanceExists = reply.value(); | ||
92 | 86 | | |||
93 | for (int i = 0; i < args.count(); i++ ) | 87 | for (int i = 0; i < args.count(); i++) { | ||
94 | { | 88 | if (instanceExists && | ||
95 | if (instanceExists | 89 | (QMessageBox::question( | ||
96 | && (QMessageBox::question(nullptr, | 90 | nullptr, | ||
97 | i18n("A KGraphEditor window is already open, do you want to open the file in it?"), | 91 | i18n("A KGraphEditor window is already open, do you " | ||
92 | "want to " | ||||
93 | "open the file in it?"), | ||||
98 | i18n("Opening in new window confirmation"), | 94 | i18n("Opening in new window confirmation"), | ||
99 | "openInNewWindowMode" ) == QMessageBox::Yes) ) | 95 | "openInNewWindowMode") == QMessageBox::Yes)) { | ||
100 | { | | |||
101 | QByteArray tosenddata; | 96 | QByteArray tosenddata; | ||
102 | QDataStream arg(&tosenddata, QIODevice::WriteOnly); | 97 | QDataStream arg(&tosenddata, QIODevice::WriteOnly); | ||
103 | QString strarg = args[i]; | 98 | QString strarg = args[i]; | ||
104 | QUrl url = QUrl::fromUserInput(strarg, QDir::currentPath(), QUrl::AssumeLocalFile); | 99 | QUrl url = QUrl::fromUserInput(strarg, QDir::currentPath(), | ||
100 | QUrl::AssumeLocalFile); | ||||
105 | arg << url; | 101 | arg << url; | ||
106 | QDBusInterface iface("org.kde.kgrapheditor", "/KGraphEditor", "", QDBusConnection::sessionBus()); | 102 | QDBusInterface iface("org.kde.kgrapheditor", | ||
107 | if (iface.isValid()) | 103 | "/KGraphEditor", "", | ||
108 | { | 104 | QDBusConnection::sessionBus()); | ||
109 | QDBusReply<void> reply = iface.call("openUrl", url.url(QUrl::PreferLocalFile)); | 105 | if (iface.isValid()) { | ||
110 | if (reply.isValid()) | 106 | QDBusReply<void> reply = iface.call( | ||
111 | { | 107 | "openUrl", url.url(QUrl::PreferLocalFile)); | ||
112 | qCDebug(KGRAPHEDITOR_LOG) << "Reply was valid" << endl; | 108 | if (reply.isValid()) { | ||
109 | qCDebug(KGRAPHEDITOR_LOG) | ||||
110 | << "Reply was valid" << endl; | ||||
113 | return 0; | 111 | return 0; | ||
114 | } | 112 | } | ||
115 | 113 | | |||
116 | qCWarning(KGRAPHEDITOR_LOG) << "Call failed: " << reply.error().message() << endl; | 114 | qCWarning(KGRAPHEDITOR_LOG) | ||
115 | << "Call failed: " << reply.error().message() | ||||
116 | << endl; | ||||
117 | return 1; | 117 | return 1; | ||
118 | } | 118 | } | ||
119 | qCWarning(KGRAPHEDITOR_LOG) << "Invalid interface" << endl; | 119 | qCWarning(KGRAPHEDITOR_LOG) << "Invalid interface" << endl; | ||
120 | exit(0); | 120 | exit(0); | ||
121 | } | 121 | } else { | ||
122 | else | | |||
123 | { | | |||
124 | widget = new KGraphEditor; | 122 | widget = new KGraphEditor; | ||
125 | new KgrapheditorAdaptor(widget); | 123 | new KgrapheditorAdaptor(widget); | ||
126 | QDBusConnection::sessionBus().registerObject("/KGraphEditor", widget); | 124 | QDBusConnection::sessionBus().registerObject( | ||
125 | "/KGraphEditor", widget); | ||||
127 | widget->show(); | 126 | widget->show(); | ||
128 | widget->openUrl(QUrl::fromUserInput(args[0], QDir::currentPath(), QUrl::AssumeLocalFile)); | 127 | widget->openUrl(QUrl::fromUserInput( | ||
128 | args[0], QDir::currentPath(), QUrl::AssumeLocalFile)); | ||||
129 | } | 129 | } | ||
130 | } | 130 | } | ||
131 | } | 131 | } | ||
132 | if (widget) | 132 | if (widget) { | ||
133 | { | | |||
134 | widget->reloadPreviousFiles(); | 133 | widget->reloadPreviousFiles(); | ||
135 | } | 134 | } | ||
136 | | ||||
137 | } | 135 | } | ||
138 | return app.exec(); | 136 | return app.exec(); | ||
139 | } | 137 | } |