@ -34,8 +34,8 @@
# include "base/utils/fs.h"
# include "base/utils/fs.h"
# include "base/utils/misc.h"
# include "base/utils/misc.h"
# include "ico.h"
# include "ico.h"
# include "searchengine .h"
# include "searchwidget .h"
# include "pluginsource.h"
# include "pluginsourcedlg .h"
# include "guiiconprovider.h"
# include "guiiconprovider.h"
# include "autoexpandabledialog.h"
# include "autoexpandabledialog.h"
# include <QProcess>
# include <QProcess>
@ -53,7 +53,7 @@
enum EngineColumns { ENGINE_NAME , ENGINE_VERSION , ENGINE_URL , ENGINE_STATE , ENGINE_ID } ;
enum EngineColumns { ENGINE_NAME , ENGINE_VERSION , ENGINE_URL , ENGINE_STATE , ENGINE_ID } ;
engineSelectDlg : : e ngineSelectDlg( QWidget * parent , SupportedEngines * supported_engines )
EngineSelectDlg : : E ngineSelectDlg( QWidget * parent , SupportedEngines * supported_engines )
: QDialog ( parent )
: QDialog ( parent )
, supported_engines ( supported_engines )
, supported_engines ( supported_engines )
, m_updateUrl ( QString ( " https://raw.github.com/qbittorrent/qBittorrent/master/src/searchengine/ " ) + ( Utils : : Misc : : pythonVersion ( ) > = 3 ? " nova3 " : " nova " ) + " /engines/ " )
, m_updateUrl ( QString ( " https://raw.github.com/qbittorrent/qBittorrent/master/src/searchengine/ " ) + ( Utils : : Misc : : pythonVersion ( ) > = 3 ? " nova3 " : " nova " ) + " /engines/ " )
@ -82,13 +82,13 @@ engineSelectDlg::engineSelectDlg(QWidget *parent, SupportedEngines *supported_en
show ( ) ;
show ( ) ;
}
}
e ngineSelectDlg: : ~ e ngineSelectDlg( ) {
E ngineSelectDlg: : ~ E ngineSelectDlg( ) {
qDebug ( " Destroying engineSelectDlg " ) ;
qDebug ( " Destroying engineSelectDlg " ) ;
emit enginesChanged ( ) ;
emit enginesChanged ( ) ;
qDebug ( " Engine plugins dialog destroyed " ) ;
qDebug ( " Engine plugins dialog destroyed " ) ;
}
}
void e ngineSelectDlg: : dropEvent ( QDropEvent * event ) {
void E ngineSelectDlg: : dropEvent ( QDropEvent * event ) {
event - > acceptProposedAction ( ) ;
event - > acceptProposedAction ( ) ;
QStringList files ;
QStringList files ;
if ( event - > mimeData ( ) - > hasUrls ( ) ) {
if ( event - > mimeData ( ) - > hasUrls ( ) ) {
@ -123,7 +123,7 @@ void engineSelectDlg::dropEvent(QDropEvent *event) {
}
}
// Decode if we accept drag 'n drop or not
// Decode if we accept drag 'n drop or not
void e ngineSelectDlg: : dragEnterEvent ( QDragEnterEvent * event ) {
void E ngineSelectDlg: : dragEnterEvent ( QDragEnterEvent * event ) {
QString mime ;
QString mime ;
foreach ( mime , event - > mimeData ( ) - > formats ( ) ) {
foreach ( mime , event - > mimeData ( ) - > formats ( ) ) {
qDebug ( " mimeData: %s " , qPrintable ( mime ) ) ;
qDebug ( " mimeData: %s " , qPrintable ( mime ) ) ;
@ -133,13 +133,13 @@ void engineSelectDlg::dragEnterEvent(QDragEnterEvent *event) {
}
}
}
}
void e ngineSelectDlg: : on_updateButton_clicked ( ) {
void E ngineSelectDlg: : on_updateButton_clicked ( ) {
// Download version file from update server on sourceforge
// Download version file from update server on sourceforge
setCursor ( QCursor ( Qt : : WaitCursor ) ) ;
setCursor ( QCursor ( Qt : : WaitCursor ) ) ;
downloadFromUrl ( m_updateUrl + " versions.txt " ) ;
downloadFromUrl ( m_updateUrl + " versions.txt " ) ;
}
}
void e ngineSelectDlg: : toggleEngineState ( QTreeWidgetItem * item , int ) {
void E ngineSelectDlg: : toggleEngineState ( QTreeWidgetItem * item , int ) {
SupportedEngine * engine = supported_engines - > value ( item - > text ( ENGINE_ID ) ) ;
SupportedEngine * engine = supported_engines - > value ( item - > text ( ENGINE_ID ) ) ;
engine - > setEnabled ( ! engine - > isEnabled ( ) ) ;
engine - > setEnabled ( ! engine - > isEnabled ( ) ) ;
if ( engine - > isEnabled ( ) ) {
if ( engine - > isEnabled ( ) ) {
@ -151,7 +151,7 @@ void engineSelectDlg::toggleEngineState(QTreeWidgetItem *item, int) {
}
}
}
}
void e ngineSelectDlg: : displayContextMenu ( const QPoint & ) {
void E ngineSelectDlg: : displayContextMenu ( const QPoint & ) {
QMenu myContextMenu ( this ) ;
QMenu myContextMenu ( this ) ;
// Enable/disable pause/start action given the DL state
// Enable/disable pause/start action given the DL state
QList < QTreeWidgetItem * > items = pluginsTree - > selectedItems ( ) ;
QList < QTreeWidgetItem * > items = pluginsTree - > selectedItems ( ) ;
@ -164,11 +164,11 @@ void engineSelectDlg::displayContextMenu(const QPoint&) {
myContextMenu . exec ( QCursor : : pos ( ) ) ;
myContextMenu . exec ( QCursor : : pos ( ) ) ;
}
}
void e ngineSelectDlg: : on_closeButton_clicked ( ) {
void E ngineSelectDlg: : on_closeButton_clicked ( ) {
close ( ) ;
close ( ) ;
}
}
void e ngineSelectDlg: : on_actionUninstall_triggered ( ) {
void E ngineSelectDlg: : on_actionUninstall_triggered ( ) {
QList < QTreeWidgetItem * > items = pluginsTree - > selectedItems ( ) ;
QList < QTreeWidgetItem * > items = pluginsTree - > selectedItems ( ) ;
QTreeWidgetItem * item ;
QTreeWidgetItem * item ;
bool error = false ;
bool error = false ;
@ -205,7 +205,7 @@ void engineSelectDlg::on_actionUninstall_triggered() {
QMessageBox : : information ( 0 , tr ( " Uninstall success " ) , tr ( " All selected plugins were uninstalled successfully " ) ) ;
QMessageBox : : information ( 0 , tr ( " Uninstall success " ) , tr ( " All selected plugins were uninstalled successfully " ) ) ;
}
}
void e ngineSelectDlg: : enableSelection ( bool enable ) {
void E ngineSelectDlg: : enableSelection ( bool enable ) {
QList < QTreeWidgetItem * > items = pluginsTree - > selectedItems ( ) ;
QList < QTreeWidgetItem * > items = pluginsTree - > selectedItems ( ) ;
QTreeWidgetItem * item ;
QTreeWidgetItem * item ;
foreach ( item , items ) {
foreach ( item , items ) {
@ -224,14 +224,14 @@ void engineSelectDlg::enableSelection(bool enable) {
}
}
// Set the color of a row in data model
// Set the color of a row in data model
void e ngineSelectDlg: : setRowColor ( int row , QString color ) {
void E ngineSelectDlg: : setRowColor ( int row , QString color ) {
QTreeWidgetItem * item = pluginsTree - > topLevelItem ( row ) ;
QTreeWidgetItem * item = pluginsTree - > topLevelItem ( row ) ;
for ( int i = 0 ; i < pluginsTree - > columnCount ( ) ; + + i ) {
for ( int i = 0 ; i < pluginsTree - > columnCount ( ) ; + + i ) {
item - > setData ( i , Qt : : ForegroundRole , QVariant ( QColor ( color ) ) ) ;
item - > setData ( i , Qt : : ForegroundRole , QVariant ( QColor ( color ) ) ) ;
}
}
}
}
QList < QTreeWidgetItem * > e ngineSelectDlg: : findItemsWithUrl ( QString url ) {
QList < QTreeWidgetItem * > E ngineSelectDlg: : findItemsWithUrl ( QString url ) {
QList < QTreeWidgetItem * > res ;
QList < QTreeWidgetItem * > res ;
for ( int i = 0 ; i < pluginsTree - > topLevelItemCount ( ) ; + + i ) {
for ( int i = 0 ; i < pluginsTree - > topLevelItemCount ( ) ; + + i ) {
QTreeWidgetItem * item = pluginsTree - > topLevelItem ( i ) ;
QTreeWidgetItem * item = pluginsTree - > topLevelItem ( i ) ;
@ -241,7 +241,7 @@ QList<QTreeWidgetItem*> engineSelectDlg::findItemsWithUrl(QString url) {
return res ;
return res ;
}
}
QTreeWidgetItem * e ngineSelectDlg: : findItemWithID ( QString id ) {
QTreeWidgetItem * E ngineSelectDlg: : findItemWithID ( QString id ) {
QList < QTreeWidgetItem * > res ;
QList < QTreeWidgetItem * > res ;
for ( int i = 0 ; i < pluginsTree - > topLevelItemCount ( ) ; + + i ) {
for ( int i = 0 ; i < pluginsTree - > topLevelItemCount ( ) ; + + i ) {
QTreeWidgetItem * item = pluginsTree - > topLevelItem ( i ) ;
QTreeWidgetItem * item = pluginsTree - > topLevelItem ( i ) ;
@ -251,15 +251,15 @@ QTreeWidgetItem* engineSelectDlg::findItemWithID(QString id) {
return 0 ;
return 0 ;
}
}
bool e ngineSelectDlg: : isUpdateNeeded ( QString plugin_name , qreal new_version ) const {
bool E ngineSelectDlg: : isUpdateNeeded ( QString plugin_name , qreal new_version ) const {
qreal old_version = SearchEngine : : getPluginVersion ( Utils : : Fs : : searchEngineLocation ( ) + " /engines/ " + plugin_name + " .py " ) ;
qreal old_version = SearchWidget : : getPluginVersion ( Utils : : Fs : : searchEngineLocation ( ) + " /engines/ " + plugin_name + " .py " ) ;
qDebug ( " IsUpdate needed? tobeinstalled: %.2f, alreadyinstalled: %.2f " , new_version , old_version ) ;
qDebug ( " IsUpdate needed? tobeinstalled: %.2f, alreadyinstalled: %.2f " , new_version , old_version ) ;
return ( new_version > old_version ) ;
return ( new_version > old_version ) ;
}
}
void e ngineSelectDlg: : installPlugin ( QString path , QString plugin_name ) {
void E ngineSelectDlg: : installPlugin ( QString path , QString plugin_name ) {
qDebug ( " Asked to install plugin at %s " , qPrintable ( path ) ) ;
qDebug ( " Asked to install plugin at %s " , qPrintable ( path ) ) ;
qreal new_version = SearchEngine : : getPluginVersion ( path ) ;
qreal new_version = SearchWidget : : getPluginVersion ( path ) ;
if ( new_version = = 0.0 ) {
if ( new_version = = 0.0 ) {
QMessageBox : : warning ( this , tr ( " Invalid plugin " ) , tr ( " The search engine plugin is invalid, please contact the author. " ) ) ;
QMessageBox : : warning ( this , tr ( " Invalid plugin " ) , tr ( " The search engine plugin is invalid, please contact the author. " ) ) ;
return ;
return ;
@ -304,7 +304,7 @@ void engineSelectDlg::installPlugin(QString path, QString plugin_name) {
// Install was successful, remove backup and update plugin version
// Install was successful, remove backup and update plugin version
if ( update ) {
if ( update ) {
Utils : : Fs : : forceRemove ( dest_path + " .bak " ) ;
Utils : : Fs : : forceRemove ( dest_path + " .bak " ) ;
qreal version = SearchEngine : : getPluginVersion ( Utils : : Fs : : searchEngineLocation ( ) + " /engines/ " + plugin_name + " .py " ) ;
qreal version = SearchWidget : : getPluginVersion ( Utils : : Fs : : searchEngineLocation ( ) + " /engines/ " + plugin_name + " .py " ) ;
QTreeWidgetItem * item = findItemWithID ( plugin_name ) ;
QTreeWidgetItem * item = findItemWithID ( plugin_name ) ;
item - > setText ( ENGINE_VERSION , QString : : number ( version , ' f ' , 2 ) ) ;
item - > setText ( ENGINE_VERSION , QString : : number ( version , ' f ' , 2 ) ) ;
QMessageBox : : information ( this , tr ( " Search plugin install " ) , tr ( " '%1' search engine plugin was successfully updated. " , " %1 is the name of the search engine " ) . arg ( plugin_name ) ) ;
QMessageBox : : information ( this , tr ( " Search plugin install " ) , tr ( " '%1' search engine plugin was successfully updated. " , " %1 is the name of the search engine " ) . arg ( plugin_name ) ) ;
@ -315,7 +315,7 @@ void engineSelectDlg::installPlugin(QString path, QString plugin_name) {
}
}
}
}
void e ngineSelectDlg: : loadSupportedSearchEngines ( ) {
void E ngineSelectDlg: : loadSupportedSearchEngines ( ) {
// Some clean up first
// Some clean up first
pluginsTree - > clear ( ) ;
pluginsTree - > clear ( ) ;
foreach ( QString name , supported_engines - > keys ( ) ) {
foreach ( QString name , supported_engines - > keys ( ) ) {
@ -323,7 +323,7 @@ void engineSelectDlg::loadSupportedSearchEngines() {
}
}
}
}
void e ngineSelectDlg: : addNewEngine ( QString engine_name ) {
void E ngineSelectDlg: : addNewEngine ( QString engine_name ) {
QTreeWidgetItem * item = new QTreeWidgetItem ( pluginsTree ) ;
QTreeWidgetItem * item = new QTreeWidgetItem ( pluginsTree ) ;
SupportedEngine * engine = supported_engines - > value ( engine_name ) ;
SupportedEngine * engine = supported_engines - > value ( engine_name ) ;
item - > setText ( ENGINE_NAME , engine - > getFullName ( ) ) ;
item - > setText ( ENGINE_NAME , engine - > getFullName ( ) ) ;
@ -351,17 +351,17 @@ void engineSelectDlg::addNewEngine(QString engine_name) {
}
}
}
}
// Load version
// Load version
qreal version = SearchEngine : : getPluginVersion ( Utils : : Fs : : searchEngineLocation ( ) + " /engines/ " + engine - > getName ( ) + " .py " ) ;
qreal version = SearchWidget : : getPluginVersion ( Utils : : Fs : : searchEngineLocation ( ) + " /engines/ " + engine - > getName ( ) + " .py " ) ;
item - > setText ( ENGINE_VERSION , QString : : number ( version , ' f ' , 2 ) ) ;
item - > setText ( ENGINE_VERSION , QString : : number ( version , ' f ' , 2 ) ) ;
}
}
void e ngineSelectDlg: : on_installButton_clicked ( ) {
void E ngineSelectDlg: : on_installButton_clicked ( ) {
p luginSourceDlg * dlg = new p luginSourceDlg( this ) ;
P luginSourceDlg * dlg = new P luginSourceDlg( this ) ;
connect ( dlg , SIGNAL ( askForLocalFile ( ) ) , this , SLOT ( askForLocalPlugin ( ) ) ) ;
connect ( dlg , SIGNAL ( askForLocalFile ( ) ) , this , SLOT ( askForLocalPlugin ( ) ) ) ;
connect ( dlg , SIGNAL ( askForUrl ( ) ) , this , SLOT ( askForPluginUrl ( ) ) ) ;
connect ( dlg , SIGNAL ( askForUrl ( ) ) , this , SLOT ( askForPluginUrl ( ) ) ) ;
}
}
void e ngineSelectDlg: : askForPluginUrl ( ) {
void E ngineSelectDlg: : askForPluginUrl ( ) {
bool ok ( false ) ;
bool ok ( false ) ;
QString clipTxt = qApp - > clipboard ( ) - > text ( ) ;
QString clipTxt = qApp - > clipboard ( ) - > text ( ) ;
QString defaultUrl = " http:// " ;
QString defaultUrl = " http:// " ;
@ -391,7 +391,7 @@ void engineSelectDlg::askForPluginUrl() {
downloadFromUrl ( url ) ;
downloadFromUrl ( url ) ;
}
}
void e ngineSelectDlg: : askForLocalPlugin ( ) {
void E ngineSelectDlg: : askForLocalPlugin ( ) {
QStringList pathsList = QFileDialog : : getOpenFileNames ( 0 ,
QStringList pathsList = QFileDialog : : getOpenFileNames ( 0 ,
tr ( " Select search plugins " ) , QDir : : homePath ( ) ,
tr ( " Select search plugins " ) , QDir : : homePath ( ) ,
tr ( " qBittorrent search plugin " ) + QString : : fromUtf8 ( " (*.py) " ) ) ;
tr ( " qBittorrent search plugin " ) + QString : : fromUtf8 ( " (*.py) " ) ) ;
@ -404,7 +404,7 @@ void engineSelectDlg::askForLocalPlugin() {
}
}
}
}
bool e ngineSelectDlg: : parseVersionsFile ( QString versions_file ) {
bool E ngineSelectDlg: : parseVersionsFile ( QString versions_file ) {
qDebug ( " Checking if update is needed " ) ;
qDebug ( " Checking if update is needed " ) ;
bool file_correct = false ;
bool file_correct = false ;
QFile versions ( versions_file ) ;
QFile versions ( versions_file ) ;
@ -450,14 +450,14 @@ bool engineSelectDlg::parseVersionsFile(QString versions_file) {
return file_correct ;
return file_correct ;
}
}
void e ngineSelectDlg: : downloadFromUrl ( const QString & url )
void E ngineSelectDlg: : downloadFromUrl ( const QString & url )
{
{
Net : : DownloadHandler * handler = Net : : DownloadManager : : instance ( ) - > downloadUrl ( url , true ) ;
Net : : DownloadHandler * handler = Net : : DownloadManager : : instance ( ) - > downloadUrl ( url , true ) ;
connect ( handler , SIGNAL ( downloadFinished ( QString , QString ) ) , this , SLOT ( processDownloadedFile ( QString , QString ) ) ) ;
connect ( handler , SIGNAL ( downloadFinished ( QString , QString ) ) , this , SLOT ( processDownloadedFile ( QString , QString ) ) ) ;
connect ( handler , SIGNAL ( downloadFailed ( QString , QString ) ) , this , SLOT ( handleDownloadFailure ( QString , QString ) ) ) ;
connect ( handler , SIGNAL ( downloadFailed ( QString , QString ) ) , this , SLOT ( handleDownloadFailure ( QString , QString ) ) ) ;
}
}
void e ngineSelectDlg: : processDownloadedFile ( const QString & url , QString filePath ) {
void E ngineSelectDlg: : processDownloadedFile ( const QString & url , QString filePath ) {
filePath = Utils : : Fs : : fromNativePath ( filePath ) ;
filePath = Utils : : Fs : : fromNativePath ( filePath ) ;
setCursor ( QCursor ( Qt : : ArrowCursor ) ) ;
setCursor ( QCursor ( Qt : : ArrowCursor ) ) ;
qDebug ( " engineSelectDlg received %s " , qPrintable ( url ) ) ;
qDebug ( " engineSelectDlg received %s " , qPrintable ( url ) ) ;
@ -500,7 +500,7 @@ void engineSelectDlg::processDownloadedFile(const QString &url, QString filePath
}
}
}
}
void e ngineSelectDlg: : handleDownloadFailure ( const QString & url , const QString & reason ) {
void E ngineSelectDlg: : handleDownloadFailure ( const QString & url , const QString & reason ) {
setCursor ( QCursor ( Qt : : ArrowCursor ) ) ;
setCursor ( QCursor ( Qt : : ArrowCursor ) ) ;
if ( url . endsWith ( " favicon.ico " , Qt : : CaseInsensitive ) ) {
if ( url . endsWith ( " favicon.ico " , Qt : : CaseInsensitive ) ) {
qDebug ( " Could not download favicon: %s, reason: %s " , qPrintable ( url ) , qPrintable ( reason ) ) ;
qDebug ( " Could not download favicon: %s, reason: %s " , qPrintable ( url ) , qPrintable ( reason ) ) ;