Only check for file association once (Win32)

Magnet link association (Win32)
This commit is contained in:
Christophe Dumez
2010-05-31 12:25:58 +00:00
parent 9c1bc13d6f
commit 48e6b46967
2 changed files with 883 additions and 853 deletions

View File

@@ -218,11 +218,13 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
qDebug("GUI Built"); qDebug("GUI Built");
#ifdef Q_WS_WIN #ifdef Q_WS_WIN
if(!Preferences::isFileAssocOk()) { if(!Preferences::neverCheckFileAssoc() && !Preferences::isFileAssocOk()) {
if(QMessageBox::question(0, tr("Torrent file association"), 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) { QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes) {
Preferences::setFileAssoc(); Preferences::setFileAssoc();
} else {
Preferences::setNeverCheckFileAssoc();
} }
} }
#endif #endif

View File

@@ -933,6 +933,16 @@ public:
return settings.value(QString::fromUtf8("Preferences/Win32/PythonPath"), "").toString(); 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() { static bool isFileAssocOk() {
QSettings settings("HKEY_CLASSES_ROOT", QSettings::NativeFormat); QSettings settings("HKEY_CLASSES_ROOT", QSettings::NativeFormat);
if(settings.value(".torrent/Default").toString() != "qBittorrent") { if(settings.value(".torrent/Default").toString() != "qBittorrent") {
@@ -947,11 +957,22 @@ public:
return false; return false;
QString assoc_exe = exe_reg.cap(1); QString assoc_exe = exe_reg.cap(1);
qDebug("exe: %s", qPrintable(assoc_exe)); qDebug("exe: %s", qPrintable(assoc_exe));
return (assoc_exe.compare(qApp->applicationFilePath().replace("/", "\\"), Qt::CaseInsensitive) == 0); 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() { static void setFileAssoc() {
QSettings settings("HKEY_CLASSES_ROOT", QSettings::NativeFormat); QSettings settings("HKEY_CLASSES_ROOT", QSettings::NativeFormat);
// .Torrent association
settings.setValue(".torrent/Default", "qBittorrent"); settings.setValue(".torrent/Default", "qBittorrent");
settings.setValue(".torrent/Content Type", "application/x-bittorrent"); settings.setValue(".torrent/Content Type", "application/x-bittorrent");
settings.setValue("qBittorrent/shell/Default", "open"); settings.setValue("qBittorrent/shell/Default", "open");
@@ -960,6 +981,13 @@ public:
settings.setValue("qBittorrent/Content Type/Default", "application/x-bittorrent"); settings.setValue("qBittorrent/Content Type/Default", "application/x-bittorrent");
const QString icon_str = "\""+qApp->applicationFilePath().replace("/", "\\")+"\",0"; const QString icon_str = "\""+qApp->applicationFilePath().replace("/", "\\")+"\",0";
settings.setValue("qBittorrent/DefaultIcon/Default", icon_str); 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 #endif