mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-23 04:54:18 +00:00
Fixes to sledgehammer's merge request.
This commit is contained in:
parent
6c52dbd477
commit
fe6df6176d
@ -185,11 +185,13 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Downloads
|
// Downloads
|
||||||
QString getSavePath() {
|
QString getSavePath() const {
|
||||||
#ifdef Q_WS_WIN
|
#if defined(Q_WS_WIN)
|
||||||
|
// TODO: Use IKnownFolderManager to get path of FOLDERID_Downloads
|
||||||
|
// instead of hardcoding "Downloads"
|
||||||
return value(QString::fromUtf8("Preferences/Downloads/SavePath"),
|
return value(QString::fromUtf8("Preferences/Downloads/SavePath"),
|
||||||
QDir(QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation)).absoluteFilePath("Downloads")).toString();
|
QDir(QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation)).absoluteFilePath("Downloads")).toString();
|
||||||
#else defined(Q_OS_LINUX)
|
#elif defined(Q_WS_X11)
|
||||||
QString save_path = value(QString::fromUtf8("Preferences/Downloads/SavePath")).toString();
|
QString save_path = value(QString::fromUtf8("Preferences/Downloads/SavePath")).toString();
|
||||||
if (!save_path.isEmpty())
|
if (!save_path.isEmpty())
|
||||||
return save_path;
|
return save_path;
|
||||||
@ -199,34 +201,37 @@ public:
|
|||||||
if (config_path.isEmpty())
|
if (config_path.isEmpty())
|
||||||
config_path = QDir::home().absoluteFilePath(".config");
|
config_path = QDir::home().absoluteFilePath(".config");
|
||||||
|
|
||||||
if (QFile::exists(conf + "/user-dirs.dirs")) {
|
QString user_dirs_file = config_path + "/user-dirs.dirs";
|
||||||
QSettings settings(conf + "/user-dirs.dirs", QSettings::IniFormat);
|
if (QFile::exists(user_dirs_file)) {
|
||||||
|
QSettings settings(user_dirs_file, QSettings::IniFormat);
|
||||||
QString xdg_download_dir = settings.value("XDG_DOWNLOAD_DIR").toString();
|
QString xdg_download_dir = settings.value("XDG_DOWNLOAD_DIR").toString();
|
||||||
if (!xdg_download_dir.isEmpty()) {
|
if (!xdg_download_dir.isEmpty()) {
|
||||||
// Resolve environment variables
|
// Resolve environment variables
|
||||||
QRegExp envar("$([a-ZA-Z_]+)");
|
QRegExp envar("\\$([a-ZA-Z_]+)");
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
while ((pos = envar.indexIn(xdg_download_dir, pos)) != -1) {
|
while ((pos = envar.indexIn(xdg_download_dir, pos)) != -1) {
|
||||||
QString variable = envar.cap(1);
|
QString variable = envar.cap(1);
|
||||||
QString replacement = QString::fromLocal8Bit(getenv(variable.toLocal8Bit()));
|
QString replacement = QString::fromLocal8Bit(getenv(variable.toLocal8Bit()));
|
||||||
|
qDebug() << Q_FUNC_INFO << "Replacing " << envar.cap(0) << "by" << replacement;
|
||||||
if (!replacement.isEmpty())
|
if (!replacement.isEmpty())
|
||||||
xdg_download_dir.replace("$"+variable, replacement);
|
xdg_download_dir.replace(envar.cap(0), replacement);
|
||||||
}
|
}
|
||||||
save_path = xdg_download_dir;
|
save_path = xdg_download_dir;
|
||||||
|
qDebug() << Q_FUNC_INFO << "SUCCESS: Using XDG path for downloads: " << save_path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback
|
// Fallback
|
||||||
if (save_path.isEmpty() || !QFile::exists(save_path))
|
if (save_path.isEmpty() || !QFile::exists(save_path)) {
|
||||||
save_path = QDir::home().absoluteFilePath("/Downloads");
|
save_path = QDir::home().absoluteFilePath("Downloads");
|
||||||
|
qDebug() << Q_FUNC_INFO << "using" << save_path << "as fallback since the XDG detection did not work";
|
||||||
// Save it
|
}
|
||||||
setSavePath(save_path);
|
|
||||||
|
|
||||||
return save_path;
|
return save_path;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
return value(QString::fromUtf8("Preferences/Downloads/SavePath"), QDir::home().absoluteFilePath("qBT_dir")).toString();
|
// TODO: On MAC OS X there is probably a way to detect the Downloads folder path
|
||||||
|
return value(QString::fromUtf8("Preferences/Downloads/SavePath"), QDir::home().absoluteFilePath("Downloads")).toString();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user