2015-08-27 14:25:14 +03:00
/*
* Bittorrent Client using Qt and libtorrent .
* Copyright ( C ) 2015 Vladimir Golovnev < glassez @ yandex . ru >
* Copyright ( C ) 2006 Christophe Dumez < chris @ qbittorrent . org >
*
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version 2
* of the License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
*
* In addition , as a special exception , the copyright holders give permission to
* link this program with the OpenSSL project ' s " OpenSSL " library ( or with
* modified versions of it that use the same license as the " OpenSSL " library ) ,
* and distribute the linked executables . You must obey the GNU General Public
* License in all respects for all of the code used other than " OpenSSL " . If you
* modify file ( s ) , you may extend this exception to your version of the file ( s ) ,
* but you are not obligated to do so . If you do not wish to do so , delete this
* exception statement from your version .
*/
2018-06-14 12:54:23 +03:00
# include "pluginselectdialog.h"
2017-04-11 15:35:10 +03:00
2017-12-03 10:32:58 +03:00
# include <QClipboard>
# include <QDropEvent>
# include <QFileDialog>
2015-08-27 14:25:14 +03:00
# include <QHeaderView>
2017-12-03 10:32:58 +03:00
# include <QImageReader>
2015-08-27 14:25:14 +03:00
# include <QMenu>
# include <QMessageBox>
# include <QMimeData>
# include <QTableView>
2018-11-18 21:40:37 +03:00
# include "base/global.h"
2017-12-03 10:32:58 +03:00
# include "base/net/downloadmanager.h"
2015-09-24 10:33:02 +03:00
# include "base/utils/fs.h"
2018-05-31 12:19:07 +03:00
# include "autoexpandabledialog.h"
2018-06-14 12:54:23 +03:00
# include "pluginsourcedialog.h"
2017-12-03 10:32:58 +03:00
# include "searchwidget.h"
2018-06-14 12:54:23 +03:00
# include "ui_pluginselectdialog.h"
2019-07-16 07:01:33 +03:00
# include "uithememanager.h"
2017-12-03 10:32:58 +03:00
# include "utils.h"
2015-09-24 10:33:02 +03:00
enum PluginColumns
{
PLUGIN_NAME ,
PLUGIN_VERSION ,
PLUGIN_URL ,
PLUGIN_STATE ,
PLUGIN_ID
} ;
2015-08-27 14:25:14 +03:00
2018-06-14 12:54:23 +03:00
PluginSelectDialog : : PluginSelectDialog ( SearchPluginManager * pluginManager , QWidget * parent )
2015-08-27 14:25:14 +03:00
: QDialog ( parent )
2018-06-14 12:54:23 +03:00
, m_ui ( new Ui : : PluginSelectDialog ( ) )
2015-08-27 14:25:14 +03:00
, m_pluginManager ( pluginManager )
, m_asyncOps ( 0 )
2017-06-14 01:23:08 +03:00
, m_pendingUpdates ( 0 )
2015-08-27 14:25:14 +03:00
{
2017-04-11 15:35:10 +03:00
m_ui - > setupUi ( this ) ;
2015-09-24 10:33:02 +03:00
setAttribute ( Qt : : WA_DeleteOnClose ) ;
// This hack fixes reordering of first column with Qt5.
// https://github.com/qtproject/qtbase/commit/e0fc088c0c8bc61dbcaf5928b24986cd61a22777
QTableView unused ;
2017-04-11 15:35:10 +03:00
unused . setVerticalHeader ( m_ui - > pluginsTree - > header ( ) ) ;
m_ui - > pluginsTree - > header ( ) - > setParent ( m_ui - > pluginsTree ) ;
2015-09-24 10:33:02 +03:00
unused . setVerticalHeader ( new QHeaderView ( Qt : : Horizontal ) ) ;
2017-01-19 15:10:09 +03:00
2017-04-11 15:35:10 +03:00
m_ui - > pluginsTree - > setRootIsDecorated ( false ) ;
m_ui - > pluginsTree - > hideColumn ( PLUGIN_ID ) ;
2017-10-03 16:57:09 +03:00
m_ui - > pluginsTree - > header ( ) - > setSortIndicator ( 0 , Qt : : AscendingOrder ) ;
2015-09-24 10:33:02 +03:00
2019-07-16 07:01:33 +03:00
m_ui - > actionUninstall - > setIcon ( UIThemeManager : : instance ( ) - > getIcon ( " list-remove " ) ) ;
2015-09-24 10:33:02 +03:00
2018-06-14 12:54:23 +03:00
connect ( m_ui - > actionEnable , & QAction : : toggled , this , & PluginSelectDialog : : enableSelection ) ;
connect ( m_ui - > pluginsTree , & QTreeWidget : : customContextMenuRequested , this , & PluginSelectDialog : : displayContextMenu ) ;
connect ( m_ui - > pluginsTree , & QTreeWidget : : itemDoubleClicked , this , & PluginSelectDialog : : togglePluginState ) ;
2015-09-24 10:33:02 +03:00
loadSupportedSearchPlugins ( ) ;
2018-06-14 12:54:23 +03:00
connect ( m_pluginManager , & SearchPluginManager : : pluginInstalled , this , & PluginSelectDialog : : pluginInstalled ) ;
connect ( m_pluginManager , & SearchPluginManager : : pluginInstallationFailed , this , & PluginSelectDialog : : pluginInstallationFailed ) ;
connect ( m_pluginManager , & SearchPluginManager : : pluginUpdated , this , & PluginSelectDialog : : pluginUpdated ) ;
connect ( m_pluginManager , & SearchPluginManager : : pluginUpdateFailed , this , & PluginSelectDialog : : pluginUpdateFailed ) ;
connect ( m_pluginManager , & SearchPluginManager : : checkForUpdatesFinished , this , & PluginSelectDialog : : checkForUpdatesFinished ) ;
connect ( m_pluginManager , & SearchPluginManager : : checkForUpdatesFailed , this , & PluginSelectDialog : : checkForUpdatesFailed ) ;
2015-09-24 10:33:02 +03:00
2017-12-03 10:32:58 +03:00
Utils : : Gui : : resize ( this ) ;
2015-09-24 10:33:02 +03:00
show ( ) ;
2015-08-27 14:25:14 +03:00
}
2018-06-14 12:54:23 +03:00
PluginSelectDialog : : ~ PluginSelectDialog ( )
2015-09-24 10:33:02 +03:00
{
2017-04-11 15:35:10 +03:00
delete m_ui ;
2015-08-27 14:25:14 +03:00
}
2018-06-14 12:54:23 +03:00
void PluginSelectDialog : : dropEvent ( QDropEvent * event )
2015-09-24 10:33:02 +03:00
{
event - > acceptProposedAction ( ) ;
QStringList files ;
if ( event - > mimeData ( ) - > hasUrls ( ) ) {
2018-11-27 23:15:04 +03:00
for ( const QUrl & url : asConst ( event - > mimeData ( ) - > urls ( ) ) ) {
2015-09-24 10:33:02 +03:00
if ( ! url . isEmpty ( ) ) {
if ( url . scheme ( ) . compare ( " file " , Qt : : CaseInsensitive ) = = 0 )
files < < url . toLocalFile ( ) ;
else
files < < url . toString ( ) ;
}
}
}
else {
files = event - > mimeData ( ) - > text ( ) . split ( QLatin1String ( " \n " ) ) ;
2015-08-27 14:25:14 +03:00
}
2015-09-24 10:33:02 +03:00
if ( files . isEmpty ( ) ) return ;
2015-08-27 14:25:14 +03:00
2018-11-27 23:15:04 +03:00
for ( const QString & file : asConst ( files ) ) {
2017-08-13 13:56:03 +03:00
qDebug ( " dropped %s " , qUtf8Printable ( file ) ) ;
2015-09-24 10:33:02 +03:00
startAsyncOp ( ) ;
m_pluginManager - > installPlugin ( file ) ;
}
2015-08-27 14:25:14 +03:00
}
// Decode if we accept drag 'n drop or not
2018-06-14 12:54:23 +03:00
void PluginSelectDialog : : dragEnterEvent ( QDragEnterEvent * event )
2015-09-24 10:33:02 +03:00
{
2018-11-27 23:15:04 +03:00
for ( const QString & mime : asConst ( event - > mimeData ( ) - > formats ( ) ) ) {
2017-08-13 13:56:03 +03:00
qDebug ( " mimeData: %s " , qUtf8Printable ( mime ) ) ;
2015-09-24 10:33:02 +03:00
}
if ( event - > mimeData ( ) - > hasFormat ( QLatin1String ( " text/plain " ) ) | | event - > mimeData ( ) - > hasFormat ( QLatin1String ( " text/uri-list " ) ) ) {
event - > acceptProposedAction ( ) ;
}
2015-08-27 14:25:14 +03:00
}
2018-06-14 12:54:23 +03:00
void PluginSelectDialog : : on_updateButton_clicked ( )
2015-09-24 10:33:02 +03:00
{
startAsyncOp ( ) ;
m_pluginManager - > checkForUpdates ( ) ;
2015-08-27 14:25:14 +03:00
}
2018-06-14 12:54:23 +03:00
void PluginSelectDialog : : togglePluginState ( QTreeWidgetItem * item , int )
2015-09-24 10:33:02 +03:00
{
PluginInfo * plugin = m_pluginManager - > pluginInfo ( item - > text ( PLUGIN_ID ) ) ;
m_pluginManager - > enablePlugin ( plugin - > name , ! plugin - > enabled ) ;
if ( plugin - > enabled ) {
item - > setText ( PLUGIN_STATE , tr ( " Yes " ) ) ;
2017-04-11 15:35:10 +03:00
setRowColor ( m_ui - > pluginsTree - > indexOfTopLevelItem ( item ) , " green " ) ;
2015-09-24 10:33:02 +03:00
}
else {
item - > setText ( PLUGIN_STATE , tr ( " No " ) ) ;
2017-04-11 15:35:10 +03:00
setRowColor ( m_ui - > pluginsTree - > indexOfTopLevelItem ( item ) , " red " ) ;
2015-09-24 10:33:02 +03:00
}
2015-08-27 14:25:14 +03:00
}
2019-06-03 10:10:19 +03:00
void PluginSelectDialog : : displayContextMenu ( const QPoint & )
2015-09-24 10:33:02 +03:00
{
// Enable/disable pause/start action given the DL state
2019-06-03 10:10:19 +03:00
const QList < QTreeWidgetItem * > items = m_ui - > pluginsTree - > selectedItems ( ) ;
2015-09-24 10:33:02 +03:00
if ( items . isEmpty ( ) ) return ;
2019-06-03 10:10:19 +03:00
QMenu * myContextMenu = new QMenu ( this ) ;
myContextMenu - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
const QString firstID = items . first ( ) - > text ( PLUGIN_ID ) ;
2018-06-14 14:46:50 +03:00
m_ui - > actionEnable - > setChecked ( m_pluginManager - > pluginInfo ( firstID ) - > enabled ) ;
2019-06-03 10:10:19 +03:00
myContextMenu - > addAction ( m_ui - > actionEnable ) ;
myContextMenu - > addSeparator ( ) ;
myContextMenu - > addAction ( m_ui - > actionUninstall ) ;
myContextMenu - > popup ( QCursor : : pos ( ) ) ;
2015-08-27 14:25:14 +03:00
}
2018-06-14 12:54:23 +03:00
void PluginSelectDialog : : on_closeButton_clicked ( )
2015-09-24 10:33:02 +03:00
{
close ( ) ;
2015-08-27 14:25:14 +03:00
}
2018-06-14 12:54:23 +03:00
void PluginSelectDialog : : on_actionUninstall_triggered ( )
2015-09-24 10:33:02 +03:00
{
bool error = false ;
2018-11-27 23:15:04 +03:00
for ( QTreeWidgetItem * item : asConst ( m_ui - > pluginsTree - > selectedItems ( ) ) ) {
2017-04-11 15:35:10 +03:00
int index = m_ui - > pluginsTree - > indexOfTopLevelItem ( item ) ;
2015-09-24 10:33:02 +03:00
Q_ASSERT ( index ! = - 1 ) ;
QString id = item - > text ( PLUGIN_ID ) ;
if ( m_pluginManager - > uninstallPlugin ( id ) ) {
delete item ;
}
else {
error = true ;
// Disable it instead
m_pluginManager - > enablePlugin ( id , false ) ;
item - > setText ( PLUGIN_STATE , tr ( " No " ) ) ;
setRowColor ( index , " red " ) ;
}
2015-08-27 14:25:14 +03:00
}
2015-09-24 10:33:02 +03:00
if ( error )
2015-11-11 06:19:16 +03:00
QMessageBox : : warning ( this , tr ( " Uninstall warning " ) , tr ( " Some plugins could not be uninstalled because they are included in qBittorrent. Only the ones you added yourself can be uninstalled. \n Those plugins were disabled. " ) ) ;
2015-09-24 10:33:02 +03:00
else
2015-11-11 06:19:16 +03:00
QMessageBox : : information ( this , tr ( " Uninstall success " ) , tr ( " All selected plugins were uninstalled successfully " ) ) ;
2015-08-27 14:25:14 +03:00
}
2018-06-14 12:54:23 +03:00
void PluginSelectDialog : : enableSelection ( bool enable )
2015-09-24 10:33:02 +03:00
{
2018-11-27 23:15:04 +03:00
for ( QTreeWidgetItem * item : asConst ( m_ui - > pluginsTree - > selectedItems ( ) ) ) {
2017-04-11 15:35:10 +03:00
int index = m_ui - > pluginsTree - > indexOfTopLevelItem ( item ) ;
2015-09-24 10:33:02 +03:00
Q_ASSERT ( index ! = - 1 ) ;
QString id = item - > text ( PLUGIN_ID ) ;
m_pluginManager - > enablePlugin ( id , enable ) ;
if ( enable ) {
item - > setText ( PLUGIN_STATE , tr ( " Yes " ) ) ;
setRowColor ( index , " green " ) ;
}
else {
item - > setText ( PLUGIN_STATE , tr ( " No " ) ) ;
setRowColor ( index , " red " ) ;
}
2015-08-27 14:25:14 +03:00
}
}
// Set the color of a row in data model
2019-02-12 03:45:30 +03:00
void PluginSelectDialog : : setRowColor ( const int row , const QString & color )
2015-09-24 10:33:02 +03:00
{
2017-04-11 15:35:10 +03:00
QTreeWidgetItem * item = m_ui - > pluginsTree - > topLevelItem ( row ) ;
for ( int i = 0 ; i < m_ui - > pluginsTree - > columnCount ( ) ; + + i ) {
2015-09-24 10:33:02 +03:00
item - > setData ( i , Qt : : ForegroundRole , QVariant ( QColor ( color ) ) ) ;
}
2015-08-27 14:25:14 +03:00
}
2019-02-12 03:45:30 +03:00
QList < QTreeWidgetItem * > PluginSelectDialog : : findItemsWithUrl ( const QString & url )
2015-09-24 10:33:02 +03:00
{
QList < QTreeWidgetItem * > res ;
2017-04-11 15:35:10 +03:00
for ( int i = 0 ; i < m_ui - > pluginsTree - > topLevelItemCount ( ) ; + + i ) {
QTreeWidgetItem * item = m_ui - > pluginsTree - > topLevelItem ( i ) ;
2015-09-24 10:33:02 +03:00
if ( url . startsWith ( item - > text ( PLUGIN_URL ) , Qt : : CaseInsensitive ) )
res < < item ;
}
return res ;
2015-08-27 14:25:14 +03:00
}
2019-02-12 03:45:30 +03:00
QTreeWidgetItem * PluginSelectDialog : : findItemWithID ( const QString & id )
2015-09-24 10:33:02 +03:00
{
2017-04-11 15:35:10 +03:00
for ( int i = 0 ; i < m_ui - > pluginsTree - > topLevelItemCount ( ) ; + + i ) {
QTreeWidgetItem * item = m_ui - > pluginsTree - > topLevelItem ( i ) ;
2015-09-24 10:33:02 +03:00
if ( id = = item - > text ( PLUGIN_ID ) )
return item ;
}
2018-09-07 14:12:38 +03:00
return nullptr ;
2015-08-27 14:25:14 +03:00
}
2018-06-14 12:54:23 +03:00
void PluginSelectDialog : : loadSupportedSearchPlugins ( )
2015-09-24 10:33:02 +03:00
{
// Some clean up first
2017-04-11 15:35:10 +03:00
m_ui - > pluginsTree - > clear ( ) ;
2018-11-27 23:15:04 +03:00
for ( const QString & name : asConst ( m_pluginManager - > allPlugins ( ) ) )
2015-09-24 10:33:02 +03:00
addNewPlugin ( name ) ;
2015-08-27 14:25:14 +03:00
}
2019-02-12 03:45:30 +03:00
void PluginSelectDialog : : addNewPlugin ( const QString & pluginName )
2015-09-24 10:33:02 +03:00
{
2019-02-13 18:12:02 +03:00
auto * item = new QTreeWidgetItem ( m_ui - > pluginsTree ) ;
2015-09-24 10:33:02 +03:00
PluginInfo * plugin = m_pluginManager - > pluginInfo ( pluginName ) ;
item - > setText ( PLUGIN_NAME , plugin - > fullName ) ;
item - > setText ( PLUGIN_URL , plugin - > url ) ;
item - > setText ( PLUGIN_ID , plugin - > name ) ;
if ( plugin - > enabled ) {
item - > setText ( PLUGIN_STATE , tr ( " Yes " ) ) ;
2017-04-11 15:35:10 +03:00
setRowColor ( m_ui - > pluginsTree - > indexOfTopLevelItem ( item ) , " green " ) ;
2015-09-24 10:33:02 +03:00
}
else {
item - > setText ( PLUGIN_STATE , tr ( " No " ) ) ;
2017-04-11 15:35:10 +03:00
setRowColor ( m_ui - > pluginsTree - > indexOfTopLevelItem ( item ) , " red " ) ;
2015-09-24 10:33:02 +03:00
}
// Handle icon
if ( QFile : : exists ( plugin - > iconPath ) ) {
// Good, we already have the icon
item - > setData ( PLUGIN_NAME , Qt : : DecorationRole , QVariant ( QIcon ( plugin - > iconPath ) ) ) ;
}
else {
// Icon is missing, we must download it
2017-06-14 01:59:57 +03:00
using namespace Net ;
2019-03-03 12:43:42 +03:00
DownloadManager : : instance ( ) - > download (
DownloadRequest ( plugin - > url + " /favicon.ico " ) . saveToFile ( true )
, this , & PluginSelectDialog : : iconDownloadFinished ) ;
2015-09-24 10:33:02 +03:00
}
2016-05-14 17:46:40 +03:00
item - > setText ( PLUGIN_VERSION , plugin - > version ) ;
2015-08-27 14:25:14 +03:00
}
2018-06-14 12:54:23 +03:00
void PluginSelectDialog : : startAsyncOp ( )
2015-08-27 14:25:14 +03:00
{
+ + m_asyncOps ;
if ( m_asyncOps = = 1 )
setCursor ( QCursor ( Qt : : WaitCursor ) ) ;
}
2018-06-14 12:54:23 +03:00
void PluginSelectDialog : : finishAsyncOp ( )
2015-08-27 14:25:14 +03:00
{
- - m_asyncOps ;
if ( m_asyncOps = = 0 )
setCursor ( QCursor ( Qt : : ArrowCursor ) ) ;
}
2018-06-14 12:54:23 +03:00
void PluginSelectDialog : : finishPluginUpdate ( )
2017-06-14 01:23:08 +03:00
{
- - m_pendingUpdates ;
2018-06-14 14:46:50 +03:00
if ( ( m_pendingUpdates = = 0 ) & & ! m_updatedPlugins . isEmpty ( ) ) {
2017-06-14 01:23:08 +03:00
m_updatedPlugins . sort ( Qt : : CaseInsensitive ) ;
QMessageBox : : information ( this , tr ( " Search plugin update " ) , tr ( " Plugins installed or updated: %1 " ) . arg ( m_updatedPlugins . join ( " , " ) ) ) ;
m_updatedPlugins . clear ( ) ;
}
}
2018-06-14 12:54:23 +03:00
void PluginSelectDialog : : on_installButton_clicked ( )
2015-09-24 10:33:02 +03:00
{
2019-02-13 18:12:02 +03:00
auto * dlg = new PluginSourceDialog ( this ) ;
2018-06-14 12:54:23 +03:00
connect ( dlg , & PluginSourceDialog : : askForLocalFile , this , & PluginSelectDialog : : askForLocalPlugin ) ;
connect ( dlg , & PluginSourceDialog : : askForUrl , this , & PluginSelectDialog : : askForPluginUrl ) ;
2015-08-27 14:25:14 +03:00
}
2018-06-14 12:54:23 +03:00
void PluginSelectDialog : : askForPluginUrl ( )
2015-09-24 10:33:02 +03:00
{
bool ok = false ;
QString clipTxt = qApp - > clipboard ( ) - > text ( ) ;
QString defaultUrl = " http:// " ;
2018-12-29 15:38:51 +03:00
if ( Net : : DownloadManager : : hasSupportedScheme ( clipTxt ) & & clipTxt . endsWith ( " .py " ) )
2015-09-24 10:33:02 +03:00
defaultUrl = clipTxt ;
QString url = AutoExpandableDialog : : getText (
this , tr ( " New search engine plugin URL " ) ,
tr ( " URL: " ) , QLineEdit : : Normal , defaultUrl , & ok
) ;
while ( ok & & ! url . isEmpty ( ) & & ! url . endsWith ( " .py " ) ) {
QMessageBox : : warning ( this , tr ( " Invalid link " ) , tr ( " The link doesn't seem to point to a search engine plugin. " ) ) ;
url = AutoExpandableDialog : : getText (
this , tr ( " New search engine plugin URL " ) ,
tr ( " URL: " ) , QLineEdit : : Normal , url , & ok
) ;
2015-08-27 14:25:14 +03:00
}
2015-09-24 10:33:02 +03:00
if ( ok & & ! url . isEmpty ( ) ) {
startAsyncOp ( ) ;
m_pluginManager - > installPlugin ( url ) ;
}
2015-08-27 14:25:14 +03:00
}
2018-06-14 12:54:23 +03:00
void PluginSelectDialog : : askForLocalPlugin ( )
2015-09-24 10:33:02 +03:00
{
2018-11-18 21:40:37 +03:00
const QStringList pathsList = QFileDialog : : getOpenFileNames (
2018-09-07 14:12:38 +03:00
nullptr , tr ( " Select search plugins " ) , QDir : : homePath ( ) ,
2015-09-24 10:33:02 +03:00
tr ( " qBittorrent search plugin " ) + QLatin1String ( " (*.py) " )
) ;
2018-11-18 21:40:37 +03:00
for ( const QString & path : pathsList ) {
2015-09-24 10:33:02 +03:00
startAsyncOp ( ) ;
m_pluginManager - > installPlugin ( path ) ;
}
2015-08-27 14:25:14 +03:00
}
2019-03-01 10:38:16 +03:00
void PluginSelectDialog : : iconDownloadFinished ( const Net : : DownloadResult & result )
2015-09-24 10:33:02 +03:00
{
2019-03-01 10:38:16 +03:00
if ( result . status ! = Net : : DownloadStatus : : Success ) {
qDebug ( " Could not download favicon: %s, reason: %s " , qUtf8Printable ( result . url ) , qUtf8Printable ( result . errorString ) ) ;
return ;
}
2019-06-16 20:14:15 +03:00
const QString filePath = Utils : : Fs : : toUniformPath ( result . filePath ) ;
2015-09-24 10:33:02 +03:00
// Icon downloaded
2017-06-13 18:45:22 +03:00
QIcon icon ( filePath ) ;
// Detect a non-decodable icon
QList < QSize > sizes = icon . availableSizes ( ) ;
bool invalid = ( sizes . isEmpty ( ) | | icon . pixmap ( sizes . first ( ) ) . isNull ( ) ) ;
if ( ! invalid ) {
2019-03-01 10:38:16 +03:00
for ( QTreeWidgetItem * item : asConst ( findItemsWithUrl ( result . url ) ) ) {
2015-09-24 10:33:02 +03:00
QString id = item - > text ( PLUGIN_ID ) ;
PluginInfo * plugin = m_pluginManager - > pluginInfo ( id ) ;
if ( ! plugin ) continue ;
2017-06-13 18:45:22 +03:00
QString iconPath = QString ( " %1/%2.%3 " )
2018-03-06 18:49:12 +03:00
. arg ( SearchPluginManager : : pluginsLocation ( )
, id
2019-03-01 10:38:16 +03:00
, result . url . endsWith ( " .ico " , Qt : : CaseInsensitive ) ? " ico " : " png " ) ;
2017-06-13 17:55:48 +03:00
if ( QFile : : copy ( filePath , iconPath ) ) {
2017-06-13 18:45:22 +03:00
// This 2nd check is necessary. Some favicons (eg from piratebay)
// decode fine without an ext, but fail to do so when appending the ext
// from the url. Probably a Qt bug.
QIcon iconWithExt ( iconPath ) ;
QList < QSize > sizesExt = iconWithExt . availableSizes ( ) ;
bool invalidExt = ( sizesExt . isEmpty ( ) | | iconWithExt . pixmap ( sizesExt . first ( ) ) . isNull ( ) ) ;
if ( invalidExt ) {
Utils : : Fs : : forceRemove ( iconPath ) ;
continue ;
}
item - > setData ( PLUGIN_NAME , Qt : : DecorationRole , iconWithExt ) ;
2017-06-13 17:55:48 +03:00
m_pluginManager - > updateIconPath ( plugin ) ;
}
2015-09-24 10:33:02 +03:00
}
2015-08-27 14:25:14 +03:00
}
2015-09-24 10:33:02 +03:00
// Delete tmp file
Utils : : Fs : : forceRemove ( filePath ) ;
2015-08-27 14:25:14 +03:00
}
2018-06-14 12:54:23 +03:00
void PluginSelectDialog : : checkForUpdatesFinished ( const QHash < QString , PluginVersion > & updateInfo )
2015-08-27 14:25:14 +03:00
{
finishAsyncOp ( ) ;
if ( updateInfo . isEmpty ( ) ) {
QMessageBox : : information ( this , tr ( " Search plugin update " ) , tr ( " All your plugins are already up to date. " ) ) ;
return ;
}
2018-03-06 17:50:10 +03:00
for ( auto i = updateInfo . cbegin ( ) ; i ! = updateInfo . cend ( ) ; + + i ) {
2015-08-27 14:25:14 +03:00
startAsyncOp ( ) ;
2018-05-30 20:06:28 +03:00
+ + m_pendingUpdates ;
2018-03-06 17:50:10 +03:00
m_pluginManager - > updatePlugin ( i . key ( ) ) ;
2015-08-27 14:25:14 +03:00
}
}
2018-06-14 12:54:23 +03:00
void PluginSelectDialog : : checkForUpdatesFailed ( const QString & reason )
2015-08-27 14:25:14 +03:00
{
finishAsyncOp ( ) ;
QMessageBox : : warning ( this , tr ( " Search plugin update " ) , tr ( " Sorry, couldn't check for plugin updates. %1 " ) . arg ( reason ) ) ;
}
2018-06-14 12:54:23 +03:00
void PluginSelectDialog : : pluginInstalled ( const QString & name )
2015-08-27 14:25:14 +03:00
{
addNewPlugin ( name ) ;
finishAsyncOp ( ) ;
2017-06-14 01:23:08 +03:00
m_updatedPlugins . append ( name ) ;
finishPluginUpdate ( ) ;
2015-08-27 14:25:14 +03:00
}
2018-06-14 12:54:23 +03:00
void PluginSelectDialog : : pluginInstallationFailed ( const QString & name , const QString & reason )
2015-08-27 14:25:14 +03:00
{
finishAsyncOp ( ) ;
2018-03-06 18:49:12 +03:00
QMessageBox : : information ( this , tr ( " Search plugin install " )
, tr ( " Couldn't install \" %1 \" search engine plugin. %2 " ) . arg ( name , reason ) ) ;
2017-06-14 01:23:08 +03:00
finishPluginUpdate ( ) ;
2015-08-27 14:25:14 +03:00
}
2018-06-14 12:54:23 +03:00
void PluginSelectDialog : : pluginUpdated ( const QString & name )
2015-08-27 14:25:14 +03:00
{
finishAsyncOp ( ) ;
2016-05-14 17:46:40 +03:00
PluginVersion version = m_pluginManager - > pluginInfo ( name ) - > version ;
2015-08-27 14:25:14 +03:00
QTreeWidgetItem * item = findItemWithID ( name ) ;
2016-05-14 17:46:40 +03:00
item - > setText ( PLUGIN_VERSION , version ) ;
2017-06-14 01:23:08 +03:00
m_updatedPlugins . append ( name ) ;
finishPluginUpdate ( ) ;
2015-08-27 14:25:14 +03:00
}
2018-06-14 12:54:23 +03:00
void PluginSelectDialog : : pluginUpdateFailed ( const QString & name , const QString & reason )
2015-08-27 14:25:14 +03:00
{
finishAsyncOp ( ) ;
2018-03-06 18:49:12 +03:00
QMessageBox : : information ( this , tr ( " Search plugin update " )
, tr ( " Couldn't update \" %1 \" search engine plugin. %2 " ) . arg ( name , reason ) ) ;
2017-06-14 01:23:08 +03:00
finishPluginUpdate ( ) ;
2015-08-27 14:25:14 +03:00
}