Commit 67c6f94b authored by Linus Jahn's avatar Linus Jahn Committed by Jonah Brüchert

Add timer to screenshots to avoid rest of animations

parent 88f838d1
......@@ -80,47 +80,54 @@ void PhonePanel::toggleTorch()
void PhonePanel::takeScreenshot()
{
auto *interface = new org::kde::kwin::Screenshot(QStringLiteral("org.kde.KWin"), QStringLiteral("/Screenshot"), QDBusConnection::sessionBus(), this);
QDBusPendingReply<QString> reply = interface->screenshotFullscreen();
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, [=](QDBusPendingCallWatcher *watcher) {
QDBusPendingReply<QString> reply = *watcher;
if (reply.isError()) {
qWarning() << "Creating the screenshot failed:" << reply.error().name() << reply.error().message();
} else {
QString filePath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
if (filePath.isEmpty()) {
qWarning() << "Couldn't find a writable location for the screenshot! The screenshot is in /tmp.";
return;
}
// wait ~200 ms to wait for rest of animations
QTimer::singleShot(200, [=]() {
auto *interface = new org::kde::kwin::Screenshot(QStringLiteral("org.kde.KWin"), QStringLiteral("/Screenshot"), QDBusConnection::sessionBus(), this);
// screenshot fullscreen currently doesn't work on all devices -> we need to use screenshot area
// this won't work with multiple screens
QSize screenSize = QGuiApplication::primaryScreen()->size();
QDBusPendingReply<QString> reply = interface->screenshotArea(0, 0, screenSize.width(), screenSize.height());
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, [=](QDBusPendingCallWatcher *watcher) {
QDBusPendingReply<QString> reply = *watcher;
if (reply.isError()) {
qWarning() << "Creating the screenshot failed:" << reply.error().name() << reply.error().message();
} else {
QString filePath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
if (filePath.isEmpty()) {
qWarning() << "Couldn't find a writable location for the screenshot! The screenshot is in /tmp.";
return;
}
QDir picturesDir(filePath);
if (!picturesDir.mkpath(QStringLiteral("Screenshots"))) {
qWarning() << "Couldn't create folder at"
<< picturesDir.path() + QStringLiteral("/Screenshots")
<< "to take screenshot.";
return;
}
QDir picturesDir(filePath);
if (!picturesDir.mkpath(QStringLiteral("Screenshots"))) {
qWarning() << "Couldn't create folder at"
<< picturesDir.path() + QStringLiteral("/Screenshots")
<< "to take screenshot.";
return;
}
filePath += QStringLiteral("/Screenshots/Screenshot_%1.png")
.arg(QDateTime::currentDateTime().toString(QStringLiteral("yyyyMMdd_hhmmss")));
filePath += QStringLiteral("/Screenshots/Screenshot_%1.png")
.arg(QDateTime::currentDateTime().toString(QStringLiteral("yyyyMMdd_hhmmss")));
const QString currentPath = reply.argumentAt<0>();
QtConcurrent::run(QThreadPool::globalInstance(), [=]() {
QFile screenshotFile(currentPath);
if (!screenshotFile.rename(filePath)) {
qWarning() << "Couldn't move screenshot into Pictures folder:"
<< screenshotFile.errorString();
}
const QString currentPath = reply.argumentAt<0>();
QtConcurrent::run(QThreadPool::globalInstance(), [=]() {
QFile screenshotFile(currentPath);
if (!screenshotFile.rename(filePath)) {
qWarning() << "Couldn't move screenshot into Pictures folder:"
<< screenshotFile.errorString();
}
qDebug() << "Successfully saved screenshot at" << filePath;
});
}
qDebug() << "Successfully saved screenshot at" << filePath;
});
}
watcher->deleteLater();
interface->deleteLater();
watcher->deleteLater();
interface->deleteLater();
});
});
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment