Browse Source

preferences: optimize XDG path detection code

adaptive-webui-19844
Christophe Dumez 13 years ago
parent
commit
928936046e
  1. 12
      src/preferences/preferences.h

12
src/preferences/preferences.h

@ -206,16 +206,8 @@ public: @@ -206,16 +206,8 @@ public:
QSettings settings(user_dirs_file, QSettings::IniFormat);
QString xdg_download_dir = settings.value("XDG_DOWNLOAD_DIR").toString();
if (!xdg_download_dir.isEmpty()) {
// Resolve environment variables
QRegExp envar("\\$([a-ZA-Z_]+)");
int pos = 0;
while ((pos = envar.indexIn(xdg_download_dir, pos)) != -1) {
QString variable = envar.cap(1);
QString replacement = QString::fromLocal8Bit(getenv(variable.toLocal8Bit()));
qDebug() << Q_FUNC_INFO << "Replacing " << envar.cap(0) << "by" << replacement;
if (!replacement.isEmpty())
xdg_download_dir.replace(envar.cap(0), replacement);
}
// Resolve $HOME environment variables
xdg_download_dir.replace("$HOME", QDir::homePath());
save_path = xdg_download_dir;
qDebug() << Q_FUNC_INFO << "SUCCESS: Using XDG path for downloads: " << save_path;
}

Loading…
Cancel
Save