Changeset View
Changeset View
Standalone View
Standalone View
src/SpectacleCore.cpp
Show First 20 Lines • Show All 178 Lines • ▼ Show 20 Line(s) | |||||
179 | { | 179 | { | ||
180 | mExportManager->setPixmap(pixmap); | 180 | mExportManager->setPixmap(pixmap); | ||
181 | 181 | | |||
182 | switch (mStartMode) { | 182 | switch (mStartMode) { | ||
183 | case BackgroundMode: | 183 | case BackgroundMode: | ||
184 | case DBusMode: | 184 | case DBusMode: | ||
185 | { | 185 | { | ||
186 | if (mNotify) { | 186 | if (mNotify) { | ||
187 | connect(mExportManager, &ExportManager::imageSaved, this, &SpectacleCore::doNotify); | 187 | connect(mExportManager, &ExportManager::imageSaved, this, &SpectacleCore::doNotify, Qt::UniqueConnection); | ||
188 | } | 188 | } | ||
189 | 189 | | |||
190 | QUrl savePath = (mStartMode == BackgroundMode && mFileNameUrl.isValid() && mFileNameUrl.isLocalFile()) ? | 190 | QUrl savePath = (mStartMode == BackgroundMode && mFileNameUrl.isValid() && mFileNameUrl.isLocalFile()) ? | ||
191 | mFileNameUrl : QUrl(); | 191 | mFileNameUrl : QUrl(); | ||
192 | mExportManager->doSave(savePath); | 192 | mExportManager->doSave(savePath); | ||
193 | 193 | | |||
194 | // if we notify, we emit allDone only if the user either dismissed the notification or pressed | 194 | // if we notify, we emit allDone only if the user either dismissed the notification or pressed | ||
195 | // the "Open" button, otherwise the app closes before it can react to it. | 195 | // the "Open" button, otherwise the app closes before it can react to it. | ||
Show All 18 Lines | 211 | case DBusMode: | |||
214 | return; | 214 | return; | ||
215 | case GuiMode: | 215 | case GuiMode: | ||
216 | mMainWindow->show(); | 216 | mMainWindow->show(); | ||
217 | } | 217 | } | ||
218 | } | 218 | } | ||
219 | 219 | | |||
220 | void SpectacleCore::doNotify(const QUrl &savedAt) | 220 | void SpectacleCore::doNotify(const QUrl &savedAt) | ||
221 | { | 221 | { | ||
222 | KNotification *notify = new KNotification(QStringLiteral("newScreenshotSaved")); | 222 | static KNotification *notify = new KNotification(QStringLiteral("newScreenshotSaved"), | ||
223 | KNotification::CloseOnTimeout|KNotification::SkipGrouping); | ||||
224 | static bool notified = false; | ||||
223 | 225 | | |||
224 | switch(mImageGrabber->grabMode()) { | 226 | switch(mImageGrabber->grabMode()) { | ||
225 | case ImageGrabber::GrabMode::FullScreen: | 227 | case ImageGrabber::GrabMode::FullScreen: | ||
226 | notify->setTitle(i18nc("The entire screen area was captured, heading", "Full Screen Captured")); | 228 | notify->setTitle(i18nc("The entire screen area was captured, heading", "Full Screen Captured")); | ||
227 | break; | 229 | break; | ||
228 | case ImageGrabber::GrabMode::CurrentScreen: | 230 | case ImageGrabber::GrabMode::CurrentScreen: | ||
229 | notify->setTitle(i18nc("The current screen was captured, heading", "Current Screen Captured")); | 231 | notify->setTitle(i18nc("The current screen was captured, heading", "Current Screen Captured")); | ||
230 | break; | 232 | break; | ||
Show All 17 Lines | 249 | if (path == QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)) { | |||
248 | notify->setText(i18nc("Placeholder is filename", "A screenshot was saved as '%1' to your Pictures folder.", savedAt.fileName())); | 250 | notify->setText(i18nc("Placeholder is filename", "A screenshot was saved as '%1' to your Pictures folder.", savedAt.fileName())); | ||
249 | } else { | 251 | } else { | ||
250 | notify->setText(i18n("A screenshot was saved as '%1' to '%2'.", savedAt.fileName(), path)); | 252 | notify->setText(i18n("A screenshot was saved as '%1' to '%2'.", savedAt.fileName(), path)); | ||
251 | } | 253 | } | ||
252 | 254 | | |||
253 | notify->setActions({i18nc("Open the screenshot we just saved", "Open")}); | 255 | notify->setActions({i18nc("Open the screenshot we just saved", "Open")}); | ||
254 | notify->setUrls({savedAt}); | 256 | notify->setUrls({savedAt}); | ||
255 | 257 | | |||
256 | connect(notify, &KNotification::action1Activated, this, [this, savedAt] { | 258 | connect(notify, &KNotification::action1Activated, this, [this] { | ||
257 | new KRun(savedAt, nullptr); | 259 | connect(new KRun(mExportManager->lastSavePath(), nullptr), | ||
258 | QTimer::singleShot(250, this, &SpectacleCore::allDone); | 260 | &KRun::finished, this, &SpectacleCore::allDone); | ||
259 | }); | 261 | }); | ||
260 | connect(notify, &QObject::destroyed, this, &SpectacleCore::allDone); | | |||
261 | 262 | | |||
263 | if(notified) { | ||||
264 | notify->close(); | ||||
265 | } | ||||
266 | | ||||
267 | notified = true; | ||||
268 | | ||||
269 | connect(notify, &KNotification::closed, this, &SpectacleCore::allDone); | ||||
262 | notify->sendEvent(); | 270 | notify->sendEvent(); | ||
263 | } | 271 | } | ||
264 | 272 | | |||
265 | void SpectacleCore::doCopyPath(const QUrl &savedAt) | 273 | void SpectacleCore::doCopyPath(const QUrl &savedAt) | ||
266 | { | 274 | { | ||
267 | if (SpectacleConfig::instance()->copySaveLocationToClipboard()) { | 275 | if (SpectacleConfig::instance()->copySaveLocationToClipboard()) { | ||
268 | qApp->clipboard()->setText(savedAt.toLocalFile()); | 276 | qApp->clipboard()->setText(savedAt.toLocalFile()); | ||
269 | } | 277 | } | ||
Show All 33 Lines |