Changeset View
Changeset View
Standalone View
Standalone View
src/SpectacleCore.cpp
Show All 36 Lines | |||||
37 | #include <QDebug> | 37 | #include <QDebug> | ||
38 | #include <QDir> | 38 | #include <QDir> | ||
39 | #include <QDrag> | 39 | #include <QDrag> | ||
40 | #include <QMimeData> | 40 | #include <QMimeData> | ||
41 | #include <QProcess> | 41 | #include <QProcess> | ||
42 | #include <QTimer> | 42 | #include <QTimer> | ||
43 | 43 | | |||
44 | SpectacleCore::SpectacleCore(StartMode startMode, ImageGrabber::GrabMode grabMode, QString &saveFileName, | 44 | SpectacleCore::SpectacleCore(StartMode startMode, ImageGrabber::GrabMode grabMode, QString &saveFileName, | ||
45 | qint64 delayMsec, bool notifyOnGrab, QObject *parent) : | 45 | qint64 delayMsec, bool notifyOnGrab, bool copyToClipboard, QObject *parent) : | ||
46 | QObject(parent), | 46 | QObject(parent), | ||
47 | mExportManager(ExportManager::instance()), | 47 | mExportManager(ExportManager::instance()), | ||
48 | mStartMode(startMode), | 48 | mStartMode(startMode), | ||
49 | mNotify(notifyOnGrab), | 49 | mNotify(notifyOnGrab), | ||
50 | mImageGrabber(nullptr), | 50 | mImageGrabber(nullptr), | ||
51 | mMainWindow(nullptr), | 51 | mMainWindow(nullptr), | ||
52 | isGuiInited(false) | 52 | isGuiInited(false), | ||
53 | copyToClipboard(copyToClipboard) | ||||
53 | { | 54 | { | ||
54 | KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("spectaclerc")); | 55 | KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("spectaclerc")); | ||
55 | KConfigGroup guiConfig(config, "GuiConfig"); | 56 | KConfigGroup guiConfig(config, "GuiConfig"); | ||
56 | 57 | | |||
57 | if (!(saveFileName.isEmpty() || saveFileName.isNull())) { | 58 | if (!(saveFileName.isEmpty() || saveFileName.isNull())) { | ||
58 | if (QDir::isRelativePath(saveFileName)) { | 59 | if (QDir::isRelativePath(saveFileName)) { | ||
59 | saveFileName = QDir::current().absoluteFilePath(saveFileName); | 60 | saveFileName = QDir::current().absoluteFilePath(saveFileName); | ||
60 | } | 61 | } | ||
▲ Show 20 Lines • Show All 148 Lines • ▼ Show 20 Line(s) | 208 | { | |||
209 | mExportManager->updatePixmapTimestamp(); | 210 | mExportManager->updatePixmapTimestamp(); | ||
210 | 211 | | |||
211 | switch (mStartMode) { | 212 | switch (mStartMode) { | ||
212 | case BackgroundMode: | 213 | case BackgroundMode: | ||
213 | case DBusMode: | 214 | case DBusMode: | ||
214 | default: | 215 | default: | ||
215 | { | 216 | { | ||
216 | if (mNotify) { | 217 | if (mNotify) { | ||
217 | connect(mExportManager, &ExportManager::imageSaved, this, &SpectacleCore::doNotify); | 218 | connect(mExportManager, &ExportManager::imageSaved, this, &SpectacleCore::doNotify); | ||
davidre: It get's called through this connection. | |||||
218 | } | 219 | } | ||
219 | 220 | | |||
221 | if (copyToClipboard) { | ||||
222 | mExportManager->doCopyToClipboard(mNotify); | ||||
223 | } else { | ||||
220 | QUrl savePath = (mStartMode == BackgroundMode && mFileNameUrl.isValid() && mFileNameUrl.isLocalFile()) ? | 224 | QUrl savePath = (mStartMode == BackgroundMode && mFileNameUrl.isValid() && mFileNameUrl.isLocalFile()) ? | ||
221 | mFileNameUrl : QUrl(); | 225 | mFileNameUrl : QUrl(); | ||
222 | mExportManager->doSave(savePath); | 226 | mExportManager->doSave(savePath); | ||
227 | } | ||||
223 | 228 | | |||
224 | // if we notify, we emit allDone only if the user either dismissed the notification or pressed | 229 | // if we notify, we emit allDone only if the user either dismissed the notification or pressed | ||
225 | // the "Open" button, otherwise the app closes before it can react to it. | 230 | // the "Open" button, otherwise the app closes before it can react to it. | ||
226 | if (!mNotify) { | 231 | if (!mNotify) { | ||
227 | emit allDone(); | 232 | emit allDone(); | ||
228 | } | 233 | } | ||
229 | } | 234 | } | ||
230 | break; | 235 | break; | ||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | 276 | case ImageGrabber::GrabMode::RectangularRegion: | |||
273 | break; | 278 | break; | ||
274 | case ImageGrabber::GrabMode::InvalidChoice: | 279 | case ImageGrabber::GrabMode::InvalidChoice: | ||
275 | default: | 280 | default: | ||
276 | break; | 281 | break; | ||
277 | } | 282 | } | ||
278 | 283 | | |||
279 | const QString &path = savedAt.adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash).path(); | 284 | const QString &path = savedAt.adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash).path(); | ||
280 | 285 | | |||
281 | // a speaking message is prettier than a URL, special case for the default pictures location | 286 | // a speaking message is prettier than a URL, special case for copy to clipboard and the default pictures location | ||
282 | if (path == QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)) { | 287 | if (copyToClipboard) { | ||
288 | notify->setText(i18n("A screenshot was saved to your clipboard.")); | ||||
289 | } else if (path == QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)) { | ||||
283 | notify->setText(i18nc("Placeholder is filename", "A screenshot was saved as '%1' to your Pictures folder.", savedAt.fileName())); | 290 | notify->setText(i18nc("Placeholder is filename", "A screenshot was saved as '%1' to your Pictures folder.", savedAt.fileName())); | ||
284 | } else { | 291 | } else { | ||
285 | notify->setText(i18n("A screenshot was saved as '%1' to '%2'.", savedAt.fileName(), path)); | 292 | notify->setText(i18n("A screenshot was saved as '%1' to '%2'.", savedAt.fileName(), path)); | ||
286 | } | 293 | } | ||
287 | 294 | | |||
295 | if (!copyToClipboard) { | ||||
288 | notify->setActions({i18nc("Open the screenshot we just saved", "Open")}); | 296 | notify->setActions({i18nc("Open the screenshot we just saved", "Open")}); | ||
289 | notify->setUrls({savedAt}); | 297 | notify->setUrls({savedAt}); | ||
298 | } | ||||
290 | 299 | | |||
291 | connect(notify, &KNotification::action1Activated, this, [this, savedAt] { | 300 | connect(notify, &KNotification::action1Activated, this, [this, savedAt] { | ||
292 | new KRun(savedAt, nullptr); | 301 | new KRun(savedAt, nullptr); | ||
293 | QTimer::singleShot(250, this, &SpectacleCore::allDone); | 302 | QTimer::singleShot(250, this, &SpectacleCore::allDone); | ||
294 | }); | 303 | }); | ||
295 | connect(notify, &QObject::destroyed, this, &SpectacleCore::allDone); | 304 | connect(notify, &QObject::destroyed, this, &SpectacleCore::allDone); | ||
296 | 305 | | |||
297 | notify->sendEvent(); | 306 | notify->sendEvent(); | ||
Show All 40 Lines |
It get's called through this connection.