Browse Source

Update Preferences class

Preferences class setters are guaranteed to accept string with both native and qt-style separators, getters are guaranteed to return string with qt-style separators
adaptive-webui-19844
Nick Tiskov 11 years ago
parent
commit
48250c7b76
  1. 78
      src/preferences/preferences.h
  2. 2
      src/qinisettings.h
  3. 10
      src/scannedfoldersmodel.cpp

78
src/preferences/preferences.h

@ -204,7 +204,7 @@ public: @@ -204,7 +204,7 @@ public:
void setStartup(bool b) {
QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat);
if (b) {
const QString bin_path = "\""+qApp->applicationFilePath().replace("/", "\\")+"\"";
const QString bin_path = "\""+qApp->applicationFilePath()+"\"";
settings.setValue("qBittorrent", bin_path);
}
else {
@ -217,12 +217,12 @@ public: @@ -217,12 +217,12 @@ public:
QString getSavePath() const {
QString save_path = value(QString::fromUtf8("Preferences/Downloads/SavePath")).toString();
if (!save_path.isEmpty())
return save_path;
return fsutils::fromNativePath(save_path);
return fsutils::QDesktopServicesDownloadLocation();
}
void setSavePath(const QString &save_path) {
setValue(QString::fromUtf8("Preferences/Downloads/SavePath"), save_path);
setValue(QString::fromUtf8("Preferences/Downloads/SavePath"), fsutils::fromNativePath(save_path));
}
bool isTempPathEnabled() const {
@ -235,11 +235,11 @@ public: @@ -235,11 +235,11 @@ public:
QString getTempPath() const {
const QString temp = QDir(getSavePath()).absoluteFilePath("temp");
return value(QString::fromUtf8("Preferences/Downloads/TempPath"), temp).toString();
return fsutils::fromNativePath(value(QString::fromUtf8("Preferences/Downloads/TempPath"), temp).toString());
}
void setTempPath(const QString &path) {
setValue(QString::fromUtf8("Preferences/Downloads/TempPath"), path);
setValue(QString::fromUtf8("Preferences/Downloads/TempPath"), fsutils::fromNativePath(path));
}
bool useIncompleteFilesExtension() const {
@ -259,11 +259,11 @@ public: @@ -259,11 +259,11 @@ public:
}
QString lastLocationPath() const {
return value(QString::fromUtf8("Preferences/Downloads/LastLocationPath"), QString()).toString();
return fsutils::fromNativePath(value(QString::fromUtf8("Preferences/Downloads/LastLocationPath"), QString()).toString());
}
void setLastLocationPath(const QString &path) {
setValue(QString::fromUtf8("Preferences/Downloads/LastLocationPath"), path);
setValue(QString::fromUtf8("Preferences/Downloads/LastLocationPath"), fsutils::fromNativePath(path));
}
bool preAllocateAllFiles() const {
@ -299,12 +299,26 @@ public: @@ -299,12 +299,26 @@ public:
}
QStringList getScanDirs() const {
return value(QString::fromUtf8("Preferences/Downloads/ScanDirs"), QStringList()).toStringList();
QStringList originalList = value(QString::fromUtf8("Preferences/Downloads/ScanDirs"), QStringList()).toStringList();
if (originalList.isEmpty())
return originalList;
QStringList newList;
foreach (const QString& s, originalList) {
newList << fsutils::fromNativePath(s);
}
return newList;
}
// This must be called somewhere with data from the model
void setScanDirs(const QStringList &dirs) {
setValue(QString::fromUtf8("Preferences/Downloads/ScanDirs"), dirs);
QStringList newList;
if (!dirs.isEmpty()) {
foreach (const QString& s, dirs) {
newList << fsutils::fromNativePath(s);
}
}
setValue(QString::fromUtf8("Preferences/Downloads/ScanDirs"), newList);
}
QList<bool> getDownloadInScanDirs() const {
@ -320,14 +334,11 @@ public: @@ -320,14 +334,11 @@ public:
}
QString getTorrentExportDir() const {
return value(QString::fromUtf8("Preferences/Downloads/TorrentExportDir"), QString()).toString();
return fsutils::fromNativePath(value(QString::fromUtf8("Preferences/Downloads/TorrentExportDir"), QString()).toString());
}
void setTorrentExportDir(QString path) {
path = path.trimmed();
if (path.isEmpty())
path = QString();
setValue(QString::fromUtf8("Preferences/Downloads/TorrentExportDir"), path);
setValue(QString::fromUtf8("Preferences/Downloads/TorrentExportDir"), fsutils::fromNativePath(path.trimmed()));
}
bool isFinishedTorrentExportEnabled() const {
@ -335,14 +346,11 @@ public: @@ -335,14 +346,11 @@ public:
}
QString getFinishedTorrentExportDir() const {
return value(QString::fromUtf8("Preferences/Downloads/FinishedTorrentExportDir"), QString()).toString();
return fsutils::fromNativePath(value(QString::fromUtf8("Preferences/Downloads/FinishedTorrentExportDir"), QString()).toString());
}
void setFinishedTorrentExportDir(QString path) {
path = path.trimmed();
if (path.isEmpty())
path = QString();
setValue(QString::fromUtf8("Preferences/Downloads/FinishedTorrentExportDir"), path);
setValue(QString::fromUtf8("Preferences/Downloads/FinishedTorrentExportDir"), fsutils::fromNativePath(path.trimmed()));
}
bool isMailNotificationEnabled() const {
@ -704,11 +712,11 @@ public: @@ -704,11 +712,11 @@ public:
}
QString getFilter() const {
return value(QString::fromUtf8("Preferences/IPFilter/File"), QString()).toString();
return fsutils::fromNativePath(value(QString::fromUtf8("Preferences/IPFilter/File"), QString()).toString());
}
void setFilter(const QString &path) {
setValue(QString::fromUtf8("Preferences/IPFilter/File"), path);
setValue(QString::fromUtf8("Preferences/IPFilter/File"), fsutils::fromNativePath(path));
}
void banIP(const QString &ip) {
@ -948,11 +956,11 @@ public: @@ -948,11 +956,11 @@ public:
}
void setAutoRunProgram(const QString &program) {
setValue("AutoRun/program", program);
setValue("AutoRun/program", fsutils::fromNativePath(program));
}
QString getAutoRunProgram() const {
return value("AutoRun/program", QString()).toString();
return fsutils::fromNativePath(value("AutoRun/program", QString()).toString());
}
bool shutdownWhenDownloadsComplete() const {
@ -1173,7 +1181,7 @@ public: @@ -1173,7 +1181,7 @@ public:
while(!versions.empty()) {
const QString version = versions.takeLast();
qDebug("Detected possible Python v%s location", qPrintable(version));
QString path = reg_python.value(version+"/InstallPath/Default", "").toString().replace("/", "\\");
QString path = reg_python.value(version+"/InstallPath/Default", "").toString();
if (!path.isEmpty() && QDir(path).exists("python.exe")) {
qDebug("Found python.exe at %s", qPrintable(path));
return path;
@ -1184,8 +1192,8 @@ public: @@ -1184,8 +1192,8 @@ public:
supported_versions << "32" << "31" << "30" << "27" << "26" << "25";
foreach (const QString &v, supported_versions) {
if (QFile::exists("C:/Python"+v+"/python.exe")) {
reg_python.setValue(v[0]+"."+v[1]+"/InstallPath/Default", QString("C:\\Python"+v));
return "C:\\Python"+v;
reg_python.setValue(v[0]+"."+v[1]+"/InstallPath/Default", QString("C:/Python"+v));
return "C:/Python"+v;
}
}
return QString::null;
@ -1206,17 +1214,17 @@ public: @@ -1206,17 +1214,17 @@ public:
return false;
}
qDebug("Checking shell command");
QString shell_command = settings.value("qBittorrent/shell/open/command/Default", "").toString();
QString shell_command = fsutils::toNativePath(settings.value("qBittorrent/shell/open/command/Default", "").toString());
qDebug("Shell command is: %s", qPrintable(shell_command));
QRegExp exe_reg("\"([^\"]+)\".*");
if (exe_reg.indexIn(shell_command) < 0)
return false;
QString assoc_exe = exe_reg.cap(1);
qDebug("exe: %s", qPrintable(assoc_exe));
if (assoc_exe.compare(qApp->applicationFilePath().replace("/", "\\"), Qt::CaseInsensitive) != 0)
if (assoc_exe.compare(fsutils::toNativePath(qApp->applicationFilePath()), Qt::CaseInsensitive) != 0)
return false;
// Icon
const QString icon_str = "\""+qApp->applicationFilePath().replace("/", "\\")+"\",1";
const QString icon_str = "\""+fsutils::toNativePath(qApp->applicationFilePath())+"\",1";
if (settings.value("qBittorrent/DefaultIcon/Default", icon_str).toString().compare(icon_str, Qt::CaseInsensitive) != 0)
return false;
@ -1228,12 +1236,12 @@ public: @@ -1228,12 +1236,12 @@ public:
// Check magnet link assoc
QRegExp exe_reg("\"([^\"]+)\".*");
QString shell_command = settings.value("Magnet/shell/open/command/Default", "").toString();
QString shell_command = fsutils::toNativePath(settings.value("Magnet/shell/open/command/Default", "").toString());
if (exe_reg.indexIn(shell_command) < 0)
return false;
QString assoc_exe = exe_reg.cap(1);
qDebug("exe: %s", qPrintable(assoc_exe));
if (assoc_exe.compare(qApp->applicationFilePath().replace("/", "\\"), Qt::CaseInsensitive) != 0)
if (assoc_exe.compare(fsutils::toNativePath(qApp->applicationFilePath()), Qt::CaseInsensitive) != 0)
return false;
return true;
}
@ -1243,8 +1251,8 @@ public: @@ -1243,8 +1251,8 @@ public:
// .Torrent association
if (set) {
const QString command_str = "\""+qApp->applicationFilePath().replace("/", "\\")+"\" \"%1\"";
const QString icon_str = "\""+qApp->applicationFilePath().replace("/", "\\")+"\",1";
const QString command_str = "\""+qApp->applicationFilePath()+"\" \"%1\"";
const QString icon_str = "\""+qApp->applicationFilePath()+"\",1";
settings.setValue(".torrent/Default", "qBittorrent");
settings.setValue(".torrent/Content Type", "application/x-bittorrent");
@ -1267,8 +1275,8 @@ public: @@ -1267,8 +1275,8 @@ public:
// Magnet association
if (set) {
const QString command_str = "\""+qApp->applicationFilePath().replace("/", "\\")+"\" \"%1\"";
const QString icon_str = "\""+qApp->applicationFilePath().replace("/", "\\")+"\",1";
const QString command_str = "\""+qApp->applicationFilePath()+"\" \"%1\"";
const QString icon_str = "\""+qApp->applicationFilePath()+"\",1";
settings.setValue("Magnet/Default", "Magnet URI");
settings.setValue("Magnet/Content Type", "application/x-magnet");

2
src/qinisettings.h

@ -63,7 +63,7 @@ public: @@ -63,7 +63,7 @@ public:
void setValue(const QString &key, const QVariant &val) {
QString key_tmp(key);
if (format() == QSettings::NativeFormat)
if (format() == QSettings::NativeFormat) // Using registry, don't touch replace here
key_tmp.replace("\\", "/");
QSettings::setValue(key_tmp, val);
}

10
src/scannedfoldersmodel.cpp

@ -82,12 +82,8 @@ QVariant ScanFoldersModel::data(const QModelIndex &index, int role) const { @@ -82,12 +82,8 @@ QVariant ScanFoldersModel::data(const QModelIndex &index, int role) const {
const PathData* pathData = m_pathList.at(index.row());
if (index.column() == PathColumn && role == Qt::DisplayRole) {
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
QString ret = pathData->path;
return ret.replace("/", "\\");
#else
return pathData->path;
#endif
return fsutils::toNativePath(pathData->path);
}
if (index.column() == DownloadAtTorrentColumn && role == Qt::CheckStateRole)
return pathData->downloadAtPath ? Qt::Checked : Qt::Unchecked;
@ -181,7 +177,7 @@ bool ScanFoldersModel::downloadInTorrentFolder(const QString &filePath) const { @@ -181,7 +177,7 @@ bool ScanFoldersModel::downloadInTorrentFolder(const QString &filePath) const {
int ScanFoldersModel::findPathData(const QString &path) const {
for (int i = 0; i < m_pathList.count(); ++i) {
const PathData* pathData = m_pathList.at(i);
if (pathData->path == path)
if (pathData->path == fsutils::fromNativePath(path))
return i;
}

Loading…
Cancel
Save