Improve screenshot path handling (#1815)
* Make --path work correctly with relative paths Relative paths are taken relative to the working directory of the calling command, not relative to the daemon's working directory. * Allow file paths in --path and refactor * Remove some redundancy These actions are already performed in the respective functions in FlameshotDBusAdapter. * Tweak --path error checker a bit more * Rework FileNameHandler and update references The class now has a much simpler interface. - Screenshot paths are now universally determined by the function properScreenshotPath - Some unreferenced methods have been removed - The documentation of properScreenshotPath documents the changes well. * Add crude tests for --path Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix failing build on Windows Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Add a test for invalid path Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Make tests clearer Thanks to @mmahmoudian for his review and contribution. Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix bug in properScreenshotPath Auto-numeration did not work when the screenshot was automatically saved when copied to clipboard. Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fall back to default pictures location Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Revert "Remove some redundancy" This was not redundancy. I had actually introduced a bug with this. This reverts commit 011ef737564892e494518443e6b80ccf3d286ae1. * Change default path only on interactive save Previously, the default save path was changed every time a screenshot was saved. Now, that only happens when it gets saved from the GUI. Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Change --path help text Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Allow other image formats Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>
This commit is contained in:
19
src/main.cpp
19
src/main.cpp
@@ -148,7 +148,7 @@ int main(int argc, char* argv[])
|
||||
// Options
|
||||
CommandOption pathOption(
|
||||
{ "p", "path" },
|
||||
QObject::tr("Path where the capture will be saved"),
|
||||
QObject::tr("Existing directory or new file to save to"),
|
||||
QStringLiteral("path"));
|
||||
CommandOption clipboardOption(
|
||||
{ "c", "clipboard" }, QObject::tr("Save the capture to the clipboard"));
|
||||
@@ -213,14 +213,17 @@ int main(int argc, char* argv[])
|
||||
};
|
||||
|
||||
const QString pathErr =
|
||||
QObject::tr("Invalid path, it must be a real path in the system");
|
||||
QObject::tr("Invalid path, must be an existing directory or a new file "
|
||||
"in an existing directory");
|
||||
auto pathChecker = [pathErr](const QString& pathValue) -> bool {
|
||||
bool res = QDir(pathValue).exists();
|
||||
if (!res) {
|
||||
QFileInfo fileInfo(pathValue);
|
||||
if (fileInfo.isDir() || fileInfo.dir().exists()) {
|
||||
return true;
|
||||
} else {
|
||||
SystemNotification().sendMessage(
|
||||
QObject::tr(pathErr.toLatin1().data()));
|
||||
return false;
|
||||
}
|
||||
return res;
|
||||
};
|
||||
|
||||
const QString booleanErr =
|
||||
@@ -290,7 +293,7 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
sessionBus.call(m);
|
||||
} else if (parser.isSet(guiArgument)) { // GUI
|
||||
QString pathValue = parser.value(pathOption);
|
||||
QString pathValue = QDir(parser.value(pathOption)).absolutePath();
|
||||
int delay = parser.value(delayOption).toInt();
|
||||
bool toClipboard = parser.isSet(clipboardOption);
|
||||
bool isRaw = parser.isSet(rawImageOption);
|
||||
@@ -321,7 +324,7 @@ int main(int argc, char* argv[])
|
||||
return waitAfterConnecting(delay, app);
|
||||
}
|
||||
} else if (parser.isSet(fullArgument)) { // FULL
|
||||
QString pathValue = parser.value(pathOption);
|
||||
QString pathValue = QDir(parser.value(pathOption)).absolutePath();
|
||||
int delay = parser.value(delayOption).toInt();
|
||||
bool toClipboard = parser.isSet(clipboardOption);
|
||||
bool isRaw = parser.isSet(rawImageOption);
|
||||
@@ -376,7 +379,7 @@ int main(int argc, char* argv[])
|
||||
QString numberStr = parser.value(screenNumberOption);
|
||||
int number =
|
||||
numberStr.startsWith(QLatin1String("-")) ? -1 : numberStr.toInt();
|
||||
QString pathValue = parser.value(pathOption);
|
||||
QString pathValue = QDir(parser.value(pathOption)).absolutePath();
|
||||
int delay = parser.value(delayOption).toInt();
|
||||
bool toClipboard = parser.isSet(clipboardOption);
|
||||
bool isRaw = parser.isSet(rawImageOption);
|
||||
|
||||
Reference in New Issue
Block a user