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