Changeset View
Changeset View
Standalone View
Standalone View
src/Main.cpp
Context not available. | |||||
18 | */ | 18 | */ | ||
---|---|---|---|---|---|
19 | 19 | | |||
20 | #include "Config.h" | 20 | #include "Config.h" | ||
21 | #include "SpectacleCommon.h" | ||||
21 | #include "SpectacleCore.h" | 22 | #include "SpectacleCore.h" | ||
22 | #include "SpectacleDBusAdapter.h" | 23 | #include "SpectacleDBusAdapter.h" | ||
23 | 24 | | |||
25 | #include <QApplication> | ||||
26 | #include <QCommandLineParser> | ||||
27 | #include <QDBusConnection> | ||||
28 | | ||||
24 | #include <KAboutData> | 29 | #include <KAboutData> | ||
25 | #include <KDBusService> | 30 | #include <KDBusService> | ||
26 | #include <KLocalizedString> | 31 | #include <KLocalizedString> | ||
27 | 32 | | |||
28 | #include <QCommandLineParser> | | |||
29 | #include <QDBusConnection> | | |||
30 | | ||||
31 | int main(int argc, char **argv) | 33 | int main(int argc, char **argv) | ||
32 | { | 34 | { | ||
33 | // set up the application | 35 | // set up the application | ||
34 | 36 | | |||
35 | QApplication app(argc, argv); | 37 | QApplication lApp(argc, argv); | ||
36 | 38 | | |||
37 | app.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, true); | 39 | lApp.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, true); | ||
38 | app.setAttribute(Qt::AA_UseHighDpiPixmaps, true); | 40 | lApp.setAttribute(Qt::AA_UseHighDpiPixmaps, true); | ||
39 | 41 | | |||
40 | KLocalizedString::setApplicationDomain("spectacle"); | 42 | KLocalizedString::setApplicationDomain("spectacle"); | ||
41 | 43 | | |||
Context not available. | |||||
48 | aboutData.addAuthor(QStringLiteral("Boudhayan Gupta"), QString(), QStringLiteral("bgupta@kde.org")); | 50 | aboutData.addAuthor(QStringLiteral("Boudhayan Gupta"), QString(), QStringLiteral("bgupta@kde.org")); | ||
49 | aboutData.setTranslator(i18nc("NAME OF TRANSLATORS", "Your names"), i18nc("EMAIL OF TRANSLATORS", "Your emails")); | 51 | aboutData.setTranslator(i18nc("NAME OF TRANSLATORS", "Your names"), i18nc("EMAIL OF TRANSLATORS", "Your emails")); | ||
50 | KAboutData::setApplicationData(aboutData); | 52 | KAboutData::setApplicationData(aboutData); | ||
51 | app.setWindowIcon(QIcon::fromTheme(QStringLiteral("spectacle"))); | 53 | lApp.setWindowIcon(QIcon::fromTheme(QStringLiteral("spectacle"))); | ||
52 | 54 | | |||
53 | // set up the command line options parser | 55 | // set up the command line options parser | ||
54 | 56 | | |||
55 | QCommandLineParser parser; | 57 | QCommandLineParser lCmdLineParser; | ||
56 | aboutData.setupCommandLine(&parser); | 58 | aboutData.setupCommandLine(&lCmdLineParser); | ||
57 | 59 | | |||
58 | parser.addOptions({ | 60 | lCmdLineParser.addOptions({ | ||
59 | {{QStringLiteral("f"), QStringLiteral("fullscreen")}, i18n("Capture the entire desktop (default)")}, | 61 | {{QStringLiteral("f"), QStringLiteral("fullscreen")}, i18n("Capture the entire desktop (default)")}, | ||
60 | {{QStringLiteral("m"), QStringLiteral("current")}, i18n("Capture the current monitor")}, | 62 | {{QStringLiteral("m"), QStringLiteral("current")}, i18n("Capture the current monitor")}, | ||
61 | {{QStringLiteral("a"), QStringLiteral("activewindow")}, i18n("Capture the active window")}, | 63 | {{QStringLiteral("a"), QStringLiteral("activewindow")}, i18n("Capture the active window")}, | ||
Context not available. | |||||
72 | {{QStringLiteral("w"), QStringLiteral("onclick")}, i18n("Wait for a click before taking screenshot. Invalidates delay")} | 74 | {{QStringLiteral("w"), QStringLiteral("onclick")}, i18n("Wait for a click before taking screenshot. Invalidates delay")} | ||
73 | }); | 75 | }); | ||
74 | 76 | | |||
75 | parser.process(app); | 77 | lCmdLineParser.process(lApp); | ||
76 | aboutData.processCommandLine(&parser); | 78 | aboutData.processCommandLine(&lCmdLineParser); | ||
77 | 79 | | |||
78 | // extract the capture mode | 80 | // extract the capture mode | ||
79 | 81 | | |||
80 | ImageGrabber::GrabMode grabMode = ImageGrabber::FullScreen; | 82 | Spectacle::CaptureMode lCaptureMode = Spectacle::CaptureMode::AllScreens; | ||
81 | if (parser.isSet(QStringLiteral("current"))) { | 83 | if (lCmdLineParser.isSet(QStringLiteral("current"))) { | ||
82 | grabMode = ImageGrabber::CurrentScreen; | 84 | lCaptureMode = Spectacle::CaptureMode::CurrentScreen; | ||
83 | } else if (parser.isSet(QStringLiteral("activewindow"))) { | 85 | } else if (lCmdLineParser.isSet(QStringLiteral("activewindow"))) { | ||
84 | grabMode = ImageGrabber::ActiveWindow; | 86 | lCaptureMode = Spectacle::CaptureMode::ActiveWindow; | ||
85 | } else if (parser.isSet(QStringLiteral("region"))) { | 87 | } else if (lCmdLineParser.isSet(QStringLiteral("region"))) { | ||
86 | grabMode = ImageGrabber::RectangularRegion; | 88 | lCaptureMode = Spectacle::CaptureMode::RectangularRegion; | ||
87 | } else if (parser.isSet(QStringLiteral("windowundercursor"))) { | 89 | } else if (lCmdLineParser.isSet(QStringLiteral("windowundercursor"))) { | ||
88 | grabMode = ImageGrabber::TransientWithParent; | 90 | lCaptureMode = Spectacle::CaptureMode::TransientWithParent; | ||
89 | } else if (parser.isSet(QStringLiteral("transientonly"))) { | 91 | } else if (lCmdLineParser.isSet(QStringLiteral("transientonly"))) { | ||
90 | grabMode = ImageGrabber::WindowUnderCursor; | 92 | lCaptureMode = Spectacle::CaptureMode::WindowUnderCursor; | ||
91 | } | 93 | } | ||
92 | 94 | | |||
93 | // are we running in background or dbus mode? | 95 | // are we running in background or dbus mode? | ||
94 | 96 | | |||
95 | SpectacleCore::StartMode startMode = SpectacleCore::GuiMode; | 97 | SpectacleCore::StartMode lStartMode = SpectacleCore::StartMode::Gui; | ||
96 | bool notify = true; | 98 | bool lNotify = true; | ||
97 | bool copyToClipboard = false; | 99 | bool lCopyToClipboard = false; | ||
98 | qint64 delayMsec = 0; | 100 | qint64 lDelayMsec = 0; | ||
99 | QString fileName = QString(); | 101 | QString lFileName = QString(); | ||
100 | 102 | | |||
101 | if (parser.isSet(QStringLiteral("background"))) { | 103 | if (lCmdLineParser.isSet(QStringLiteral("background"))) { | ||
102 | startMode = SpectacleCore::BackgroundMode; | 104 | lStartMode = SpectacleCore::StartMode::Background; | ||
103 | } else if (parser.isSet(QStringLiteral("dbus"))) { | 105 | } else if (lCmdLineParser.isSet(QStringLiteral("dbus"))) { | ||
104 | startMode = SpectacleCore::DBusMode; | 106 | lStartMode = SpectacleCore::StartMode::DBus; | ||
105 | } | 107 | } | ||
106 | 108 | | |||
107 | switch (startMode) { | 109 | switch(lStartMode) { | ||
108 | case SpectacleCore::BackgroundMode: | 110 | case SpectacleCore::StartMode::Background: | ||
109 | if (parser.isSet(QStringLiteral("nonotify"))) { | 111 | if (lCmdLineParser.isSet(QStringLiteral("nonotify"))) { | ||
110 | notify = false; | 112 | lNotify = false; | ||
111 | } | 113 | } | ||
112 | 114 | | |||
113 | if (parser.isSet(QStringLiteral("output"))) { | 115 | if (lCmdLineParser.isSet(QStringLiteral("output"))) { | ||
114 | fileName = parser.value(QStringLiteral("output")); | 116 | lFileName = lCmdLineParser.value(QStringLiteral("output")); | ||
115 | } | 117 | } | ||
116 | 118 | | |||
117 | if (parser.isSet(QStringLiteral("delay"))) { | 119 | if (lCmdLineParser.isSet(QStringLiteral("delay"))) { | ||
118 | bool ok = false; | 120 | bool lParseOk = false; | ||
119 | qint64 delayValue = parser.value(QStringLiteral("delay")).toLongLong(&ok); | 121 | qint64 lDelayValue = lCmdLineParser.value(QStringLiteral("delay")).toLongLong(&lParseOk); | ||
120 | if (ok) { | 122 | if (lParseOk) { | ||
121 | delayMsec = delayValue; | 123 | lDelayMsec = lDelayValue; | ||
122 | } | 124 | } | ||
123 | } | 125 | } | ||
124 | 126 | | |||
125 | if (parser.isSet(QStringLiteral("onclick"))) { | 127 | if (lCmdLineParser.isSet(QStringLiteral("onclick"))) { | ||
126 | delayMsec = -1; | 128 | lDelayMsec = -1; | ||
127 | } | 129 | } | ||
128 | 130 | | |||
129 | if (parser.isSet(QStringLiteral("clipboard"))) { | 131 | if (lCmdLineParser.isSet(QStringLiteral("clipboard"))) { | ||
130 | copyToClipboard = true; | 132 | lCopyToClipboard = true; | ||
131 | } | 133 | } | ||
132 | 134 | | |||
133 | app.setQuitOnLastWindowClosed(false); | 135 | lApp.setQuitOnLastWindowClosed(false); | ||
134 | break; | 136 | break; | ||
135 | 137 | case SpectacleCore::StartMode::DBus: | |||
136 | case SpectacleCore::DBusMode: | 138 | lApp.setQuitOnLastWindowClosed(false); | ||
137 | app.setQuitOnLastWindowClosed(false); | | |||
138 | break; | 139 | break; | ||
139 | case SpectacleCore::GuiMode: | 140 | case SpectacleCore::StartMode::Gui: | ||
140 | default: | | |||
141 | break; | 141 | break; | ||
142 | } | 142 | } | ||
143 | 143 | | |||
144 | // release the kraken | 144 | // release the kraken | ||
145 | 145 | | |||
146 | SpectacleCore core(startMode, grabMode, fileName, delayMsec, notify, copyToClipboard); | 146 | SpectacleCore lCore(lStartMode, lCaptureMode, lFileName, lDelayMsec, lNotify, lCopyToClipboard); | ||
147 | QObject::connect(&core, &SpectacleCore::allDone, qApp, &QApplication::quit); | 147 | QObject::connect(&lCore, &SpectacleCore::allDone, qApp, &QApplication::quit); | ||
148 | 148 | | |||
149 | // create the dbus connections | 149 | // create the dbus connections | ||
150 | 150 | | |||
151 | new KDBusService(KDBusService::Multiple, &core); | 151 | new KDBusService(KDBusService::Multiple, &lCore); | ||
152 | 152 | SpectacleDBusAdapter *lDBusAdapter = new SpectacleDBusAdapter(&lCore); | |||
153 | SpectacleDBusAdapter *dbusAdapter = new SpectacleDBusAdapter(&core); | 153 | QObject::connect(&lCore, &SpectacleCore::grabFailed, lDBusAdapter, &SpectacleDBusAdapter::ScreenshotFailed); | ||
154 | QObject::connect(&core, &SpectacleCore::grabFailed, dbusAdapter, &SpectacleDBusAdapter::ScreenshotFailed); | | |||
155 | QObject::connect(ExportManager::instance(), &ExportManager::imageSaved, [&](const QUrl &savedAt) { | 154 | QObject::connect(ExportManager::instance(), &ExportManager::imageSaved, [&](const QUrl &savedAt) { | ||
156 | emit dbusAdapter->ScreenshotTaken(savedAt.toLocalFile()); | 155 | emit lDBusAdapter->ScreenshotTaken(savedAt.toLocalFile()); | ||
157 | }); | 156 | }); | ||
158 | 157 | QDBusConnection::sessionBus().registerObject(QStringLiteral("/"), &lCore); | |||
159 | QDBusConnection::sessionBus().registerObject(QStringLiteral("/"), &core); | | |||
160 | QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.Spectacle")); | 158 | QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.Spectacle")); | ||
161 | 159 | | |||
162 | // fire it up | 160 | // fire it up | ||
163 | 161 | | |||
164 | return app.exec(); | 162 | return lApp.exec(); | ||
165 | } | 163 | } | ||
Context not available. |