1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-22 20:44:15 +00:00

Merge Win32 changes

This commit is contained in:
Christophe Dumez 2010-05-31 12:48:00 +00:00
parent c1a72f075d
commit 4fd10bc5f5
2 changed files with 50 additions and 20 deletions

View File

@ -219,11 +219,13 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
qDebug("GUI Built");
#ifdef Q_WS_WIN
if(!Preferences::isFileAssocOk()) {
if(!Preferences::neverCheckFileAssoc() && !Preferences::isFileAssocOk()) {
if(QMessageBox::question(0, tr("Torrent file association"),
tr("qBittorrent is not the default application to open torrent files.\nDo you want to associate qBittorrent to torrent files?"),
tr("qBittorrent is not the default application to open torrent files or Magnet links.\nDo you want to associate qBittorrent to torrent files and Magnet links?"),
QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes) {
Preferences::setFileAssoc();
} else {
Preferences::setNeverCheckFileAssoc();
}
}
#endif

View File

@ -991,34 +991,55 @@ public:
#ifdef Q_WS_WIN
static void setPythonPath(QString path) {
QSettings settings("qBittorrent", "qBittorrent");
settings.setValue(QString::fromUtf8("Preferences/Win32/PythonPath"), path);
QSettings settings("qBittorrent", "qBittorrent");
settings.setValue(QString::fromUtf8("Preferences/Win32/PythonPath"), path);
}
static QString getPythonPath() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Win32/PythonPath"), "").toString();
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Win32/PythonPath"), "").toString();
}
static bool neverCheckFileAssoc() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Win32/NeverCheckFileAssocation"), false).toBool();
}
static void setNeverCheckFileAssoc(bool check=true) {
QSettings settings("qBittorrent", "qBittorrent");
settings.setValue(QString::fromUtf8("Preferences/Win32/NeverCheckFileAssocation"), check);
}
static bool isFileAssocOk() {
QSettings settings("HKEY_CLASSES_ROOT", QSettings::NativeFormat);
if(settings.value(".torrent/Default").toString() != "qBittorrent") {
qDebug(".torrent != qBittorrent");
return false;
}
qDebug("Checking shell command");
QString shell_command = 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));
return (assoc_exe.compare(qApp->applicationFilePath().replace("/", "\\"), Qt::CaseInsensitive) == 0);
QSettings settings("HKEY_CLASSES_ROOT", QSettings::NativeFormat);
if(settings.value(".torrent/Default").toString() != "qBittorrent") {
qDebug(".torrent != qBittorrent");
return false;
}
qDebug("Checking shell command");
QString shell_command = 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)
return false;
// Check magnet link assoc
shell_command = settings.value("Magnet/shell/open/command/Default", "").toString();
if(exe_reg.indexIn(shell_command) < 0)
return false;
assoc_exe = exe_reg.cap(1);
qDebug("exe: %s", qPrintable(assoc_exe));
if(assoc_exe.compare(qApp->applicationFilePath().replace("/", "\\"), Qt::CaseInsensitive) != 0)
return false;
return true;
}
static void setFileAssoc() {
QSettings settings("HKEY_CLASSES_ROOT", QSettings::NativeFormat);
// .Torrent association
settings.setValue(".torrent/Default", "qBittorrent");
settings.setValue(".torrent/Content Type", "application/x-bittorrent");
settings.setValue("qBittorrent/shell/Default", "open");
@ -1027,6 +1048,13 @@ public:
settings.setValue("qBittorrent/Content Type/Default", "application/x-bittorrent");
const QString icon_str = "\""+qApp->applicationFilePath().replace("/", "\\")+"\",0";
settings.setValue("qBittorrent/DefaultIcon/Default", icon_str);
// Magnet association
settings.setValue("Magnet/Default", "Magnet URI");
settings.setValue("Magnet/Content Type", "application/x-magnet");
settings.setValue("Magnet/URL Protocol", "");
settings.setValue("Magnet/DefaultIcon/Default", icon_str);
settings.setValue("Magnet/shell/Default", "open");
settings.setValue("Magnet/shell/open/command/Default", command_str);
}
#endif