Changeset View
Changeset View
Standalone View
Standalone View
src/main.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 "kgraphviewer.h" | 19 | #include "kgraphviewer.h" | ||
21 | #include "kgraphviewer_debug.h" | 20 | #include "kgraphviewer_debug.h" | ||
22 | 21 | | |||
22 | #include "config-kgraphviewer.h" | ||||
23 | #include "kgraphvieweradaptor.h" | ||||
24 | #include <KAboutData> | ||||
23 | #include <QApplication> | 25 | #include <QApplication> | ||
24 | #include <kaboutdata.h> | | |||
25 | #include <QCommandLineParser> | | |||
26 | #include <QMessageBox> | | |||
27 | #include <QDebug> | | |||
28 | #include <iostream> | | |||
29 | #include <QDir> | | |||
30 | #include <QByteArray> | 26 | #include <QByteArray> | ||
31 | #include <QDBusInterface> | 27 | #include <QCommandLineParser> | ||
32 | #include <QDBusConnection> | 28 | #include <QDBusConnection> | ||
33 | #include <QDBusConnectionInterface> | 29 | #include <QDBusConnectionInterface> | ||
30 | #include <QDBusInterface> | ||||
34 | #include <QDBusReply> | 31 | #include <QDBusReply> | ||
32 | #include <QDebug> | ||||
33 | #include <QDir> | ||||
34 | #include <QMessageBox> | ||||
35 | #include <iostream> | ||||
36 | #include <kaboutdata.h> | ||||
35 | #include <klocalizedstring.h> | 37 | #include <klocalizedstring.h> | ||
36 | #include <KAboutData> | | |||
37 | #include "kgraphvieweradaptor.h" | | |||
38 | #include "config-kgraphviewer.h" | | |||
39 | 38 | | |||
40 | int main(int argc, char **argv) | 39 | int main(int argc, char **argv) | ||
41 | { | 40 | { | ||
42 | QApplication app(argc, argv); | 41 | QApplication app(argc, argv); | ||
43 | 42 | | |||
44 | KLocalizedString::setApplicationDomain("kgraphviewer"); | 43 | KLocalizedString::setApplicationDomain("kgraphviewer"); | ||
45 | 44 | | |||
46 | KAboutData about(QStringLiteral("kgraphviewer"), | 45 | KAboutData about(QStringLiteral("kgraphviewer"), | ||
47 | i18n("KGraphViewer"), | 46 | i18n("KGraphViewer"), | ||
48 | KGRAPHVIEWER_VERSION_STRING, | 47 | KGRAPHVIEWER_VERSION_STRING, | ||
49 | i18n("A Graphviz DOT graph viewer"), | 48 | i18n("A Graphviz DOT graph viewer"), | ||
50 | KAboutLicense::GPL, | 49 | KAboutLicense::GPL, | ||
51 | i18n("(C) 2005-2010 Gaël de Chalendar"), | 50 | i18n("(C) 2005-2010 Gaël de Chalendar"), | ||
52 | QString(), | 51 | QString(), | ||
53 | QStringLiteral("https://www.kde.org/applications/graphics/kgraphviewer")); | 52 | QStringLiteral("https://www.kde.org/applications/graphics/kgraphviewer")); | ||
54 | about.addAuthor( i18n("Gaël de Chalendar"), i18n("Original Author and current maintainer"), "kleag@free.fr" ); | 53 | about.addAuthor(i18n("Gaël de Chalendar"), i18n("Original Author and current maintainer"), "kleag@free.fr"); | ||
55 | about.addAuthor( i18n("Reimar Döffinger"), i18n("Contributor"), "kde@reimardoeffinger.de" ); | 54 | about.addAuthor(i18n("Reimar Döffinger"), i18n("Contributor"), "kde@reimardoeffinger.de"); | ||
56 | about.addAuthor( i18n("Matthias Peinhardt"), i18n("Contributor"), "matthias.peinhardt@googlemail.com" ); | 55 | about.addAuthor(i18n("Matthias Peinhardt"), i18n("Contributor"), "matthias.peinhardt@googlemail.com"); | ||
57 | about.addAuthor( i18n("Sandro Andrade"), i18n("Contributor"), "sandro.andrade@gmail.com" ); | 56 | about.addAuthor(i18n("Sandro Andrade"), i18n("Contributor"), "sandro.andrade@gmail.com"); | ||
58 | about.addAuthor( i18n("Milian Wolff"), i18n("Contributor"), "mail@milianw.de" ); | 57 | about.addAuthor(i18n("Milian Wolff"), i18n("Contributor"), "mail@milianw.de"); | ||
59 | about.addAuthor( i18n("Martin Sandsmark"), i18n("Port to KF5"), "martin.sandsmark@kde.org" ); | 58 | about.addAuthor(i18n("Martin Sandsmark"), i18n("Port to KF5"), "martin.sandsmark@kde.org"); | ||
60 | 59 | | |||
61 | app.setOrganizationDomain(QStringLiteral("kde.org")); | 60 | app.setOrganizationDomain(QStringLiteral("kde.org")); | ||
62 | app.setOrganizationName(QStringLiteral("KDE")); | 61 | app.setOrganizationName(QStringLiteral("KDE")); | ||
63 | 62 | | |||
64 | KAboutData::setApplicationData(about); | 63 | KAboutData::setApplicationData(about); | ||
65 | 64 | | |||
66 | app.setWindowIcon(QIcon::fromTheme("kgraphviewer", app.windowIcon())); | 65 | app.setWindowIcon(QIcon::fromTheme("kgraphviewer", app.windowIcon())); | ||
67 | 66 | | |||
68 | QCommandLineParser options; | 67 | QCommandLineParser options; | ||
69 | options.addHelpOption(); | 68 | options.addHelpOption(); | ||
70 | options.addVersionOption(); | 69 | options.addVersionOption(); | ||
71 | options.addPositionalArgument(QStringLiteral("url"), i18n("Path or URL to scan"), i18n("[url]")); | 70 | options.addPositionalArgument(QStringLiteral("url"), i18n("Path or URL to scan"), i18n("[url]")); | ||
72 | about.setupCommandLine(&options); | 71 | about.setupCommandLine(&options); | ||
73 | options.process(app); | 72 | options.process(app); | ||
74 | about.processCommandLine(&options); | 73 | about.processCommandLine(&options); | ||
75 | 74 | | |||
76 | // see if we are starting with session management | 75 | // see if we are starting with session management | ||
77 | if (app.isSessionRestored()) | 76 | if (app.isSessionRestored()) { | ||
78 | { | | |||
79 | RESTORE(KGraphViewerWindow); | 77 | RESTORE(KGraphViewerWindow); | ||
80 | } | 78 | } else { | ||
81 | else | | |||
82 | { | | |||
83 | // no session.. just start up normally | 79 | // no session.. just start up normally | ||
84 | QStringList args = options.positionalArguments(); | 80 | QStringList args = options.positionalArguments(); | ||
85 | 81 | | |||
86 | KGraphViewerWindow *widget = nullptr; | 82 | KGraphViewerWindow *widget = nullptr; | ||
87 | if ( args.count() == 0 ) | 83 | if (args.count() == 0) { | ||
88 | { | | |||
89 | widget = new KGraphViewerWindow; | 84 | widget = new KGraphViewerWindow; | ||
90 | new KgraphviewerAdaptor(widget); | 85 | new KgraphviewerAdaptor(widget); | ||
91 | QDBusConnection::sessionBus().registerObject("/KGraphViewer", widget); | 86 | QDBusConnection::sessionBus().registerObject("/KGraphViewer", widget); | ||
92 | widget->show(); | 87 | widget->show(); | ||
93 | } | 88 | } else { | ||
94 | else | | |||
95 | { | | |||
96 | QDBusReply<bool> reply = QDBusConnection::sessionBus().interface()->isServiceRegistered( "org.kde.kgraphviewer" ); | 89 | QDBusReply<bool> reply = QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.kgraphviewer"); | ||
97 | 90 | | |||
98 | bool instanceExists = reply.value(); | 91 | bool instanceExists = reply.value(); | ||
99 | 92 | | |||
100 | for (int i = 0; i < args.count(); i++ ) | 93 | for (int i = 0; i < args.count(); i++) { | ||
101 | { | 94 | if (instanceExists && | ||
102 | if (instanceExists | 95 | (QMessageBox::question(nullptr, i18n("Opening in new window confirmation"), i18n("A KGraphViewer window is already open, where do you want to open this file in the existing window?")) == QMessageBox::Yes)) { | ||
103 | && (QMessageBox::question(nullptr, | | |||
104 | i18n("Opening in new window confirmation"), | | |||
105 | i18n("A KGraphViewer window is already open, where do you want to open this file in the existing window?")) | | |||
106 | == QMessageBox::Yes)) | | |||
107 | { | | |||
108 | QByteArray tosenddata; | 96 | QByteArray tosenddata; | ||
109 | QDataStream arg(&tosenddata, QIODevice::WriteOnly); | 97 | QDataStream arg(&tosenddata, QIODevice::WriteOnly); | ||
110 | QString strarg = args[i]; | 98 | QString strarg = args[i]; | ||
111 | QUrl url; | 99 | QUrl url; | ||
112 | if (strarg.left(1) == "/") | 100 | if (strarg.left(1) == "/") | ||
113 | url = QUrl::fromUserInput(strarg); | 101 | url = QUrl::fromUserInput(strarg); | ||
114 | else url = QUrl::fromLocalFile(QDir::currentPath() + '/' + strarg); | 102 | else | ||
103 | url = QUrl::fromLocalFile(QDir::currentPath() + '/' + strarg); | ||||
115 | arg << url; | 104 | arg << url; | ||
116 | QDBusInterface iface("org.kde.kgraphviewer", "/KGraphViewer", "", QDBusConnection::sessionBus()); | 105 | QDBusInterface iface("org.kde.kgraphviewer", "/KGraphViewer", "", QDBusConnection::sessionBus()); | ||
117 | if (iface.isValid()) | 106 | if (iface.isValid()) { | ||
118 | { | | |||
119 | QDBusReply<void> reply = iface.call("openUrl", url.url(QUrl::PreferLocalFile)); | 107 | QDBusReply<void> reply = iface.call("openUrl", url.url(QUrl::PreferLocalFile)); | ||
120 | if (reply.isValid()) | 108 | if (reply.isValid()) { | ||
121 | { | | |||
122 | qCWarning(KGRAPHVIEWER_LOG) << "Reply was valid"; | 109 | qCWarning(KGRAPHVIEWER_LOG) << "Reply was valid"; | ||
123 | return 0; | 110 | return 0; | ||
124 | } | 111 | } | ||
125 | 112 | | |||
126 | qCWarning(KGRAPHVIEWER_LOG) << "Call failed: " << reply.error().message() << endl; | 113 | qCWarning(KGRAPHVIEWER_LOG) << "Call failed: " << reply.error().message() << endl; | ||
127 | return 1; | 114 | return 1; | ||
128 | } | 115 | } | ||
129 | qCWarning(KGRAPHVIEWER_LOG) << "Invalid interface" << endl; | 116 | qCWarning(KGRAPHVIEWER_LOG) << "Invalid interface" << endl; | ||
130 | exit(0); | 117 | exit(0); | ||
131 | } | 118 | } else { | ||
132 | else | | |||
133 | { | | |||
134 | widget = new KGraphViewerWindow; | 119 | widget = new KGraphViewerWindow; | ||
135 | new KgraphviewerAdaptor(widget); | 120 | new KgraphviewerAdaptor(widget); | ||
136 | QDBusConnection::sessionBus().registerObject("/KGraphViewer", widget); | 121 | QDBusConnection::sessionBus().registerObject("/KGraphViewer", widget); | ||
137 | widget->show(); | 122 | widget->show(); | ||
138 | widget->openUrl( QUrl::fromUserInput(args[i])); | 123 | widget->openUrl(QUrl::fromUserInput(args[i])); | ||
139 | } | 124 | } | ||
140 | } | 125 | } | ||
141 | } | 126 | } | ||
142 | if (widget) | 127 | if (widget) { | ||
143 | { | | |||
144 | widget->reloadPreviousFiles(); | 128 | widget->reloadPreviousFiles(); | ||
145 | } | 129 | } | ||
146 | | ||||
147 | } | 130 | } | ||
148 | return app.exec(); | 131 | return app.exec(); | ||
149 | } | 132 | } |