Browse Source

- BUGFIX: the function that set the rows color doesn't handle hidden columns anymore

- BUGFIX: improved search engine plugin manager code and fixed bugs
adaptive-webui-19844
Christophe Dumez 17 years ago
parent
commit
24dced2411
  1. 2
      TODO
  2. 3
      src/FinishedTorrents.cpp
  3. 2
      src/downloadingTorrents.cpp
  4. 7
      src/engineSelect.ui
  5. 110
      src/engineSelectDlg.cpp
  6. 8
      src/engineSelectDlg.h

2
TODO

@ -103,4 +103,6 @@ beta6->beta7 changelog:
- BUGFIX: Fixed log context menu position - BUGFIX: Fixed log context menu position
- BUGFIX: Made pause/resume all function affect both (dl/up) tabs when window is hidden - BUGFIX: Made pause/resume all function affect both (dl/up) tabs when window is hidden
- BUGFIX: Fixed torrent create (can only one file or one folder) - BUGFIX: Fixed torrent create (can only one file or one folder)
- BUGFIX: the function that set the rows color doesn't handle hidden columns anymore
- BUGFIX: improved search engine plugin manager code and fixed bugs
- COSMETIC: Improved some icons - COSMETIC: Improved some icons

3
src/FinishedTorrents.cpp

@ -122,7 +122,8 @@ void FinishedTorrents::torrentAdded(QString, QTorrentHandle& h, bool) {
// Set the color of a row in data model // Set the color of a row in data model
void FinishedTorrents::setRowColor(int row, QString color){ void FinishedTorrents::setRowColor(int row, QString color){
for(int i=0; i<finishedListModel->columnCount(); ++i){ unsigned int nbColumns = finishedListModel->columnCount()-1;
for(unsigned int i=0; i<nbColumns; ++i){
finishedListModel->setData(finishedListModel->index(row, i), QVariant(QColor(color)), Qt::ForegroundRole); finishedListModel->setData(finishedListModel->index(row, i), QVariant(QColor(color)), Qt::ForegroundRole);
} }
} }

2
src/downloadingTorrents.cpp

@ -664,7 +664,7 @@ void DownloadingTorrents::portListeningFailure() {
// Set the color of a row in data model // Set the color of a row in data model
void DownloadingTorrents::setRowColor(int row, QString color) { void DownloadingTorrents::setRowColor(int row, QString color) {
unsigned int nbColumns = DLListModel->columnCount(); unsigned int nbColumns = DLListModel->columnCount()-1;
for(unsigned int i=0; i<nbColumns; ++i) { for(unsigned int i=0; i<nbColumns; ++i) {
DLListModel->setData(DLListModel->index(row, i), QVariant(QColor(color)), Qt::ForegroundRole); DLListModel->setData(DLListModel->index(row, i), QVariant(QColor(color)), Qt::ForegroundRole);
} }

7
src/engineSelect.ui

@ -5,7 +5,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>527</width> <width>541</width>
<height>254</height> <height>254</height>
</rect> </rect>
</property> </property>
@ -59,6 +59,11 @@
<string>Enabled</string> <string>Enabled</string>
</property> </property>
</column> </column>
<column>
<property name="text" >
<string/>
</property>
</column>
</widget> </widget>
</item> </item>
<item> <item>

110
src/engineSelectDlg.cpp

@ -38,12 +38,14 @@
#define ENGINE_NAME 0 #define ENGINE_NAME 0
#define ENGINE_URL 1 #define ENGINE_URL 1
#define ENGINE_STATE 2 #define ENGINE_STATE 2
#define ENGINE_ID 3
engineSelectDlg::engineSelectDlg(QWidget *parent) : QDialog(parent) { engineSelectDlg::engineSelectDlg(QWidget *parent) : QDialog(parent) {
setupUi(this); setupUi(this);
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
pluginsTree->header()->resizeSection(0, 170); pluginsTree->header()->resizeSection(0, 170);
pluginsTree->header()->resizeSection(1, 220); pluginsTree->header()->resizeSection(1, 220);
pluginsTree->hideColumn(ENGINE_ID);
actionEnable->setIcon(QIcon(QString::fromUtf8(":/Icons/button_ok.png"))); actionEnable->setIcon(QIcon(QString::fromUtf8(":/Icons/button_ok.png")));
actionDisable->setIcon(QIcon(QString::fromUtf8(":/Icons/button_cancel.png"))); actionDisable->setIcon(QIcon(QString::fromUtf8(":/Icons/button_cancel.png")));
actionUninstall->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/remove.png"))); actionUninstall->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/remove.png")));
@ -53,15 +55,13 @@ engineSelectDlg::engineSelectDlg(QWidget *parent) : QDialog(parent) {
downloader = new downloadThread(this); downloader = new downloadThread(this);
connect(downloader, SIGNAL(downloadFinished(QString, QString)), this, SLOT(processDownloadedFile(QString, QString))); connect(downloader, SIGNAL(downloadFinished(QString, QString)), this, SLOT(processDownloadedFile(QString, QString)));
connect(downloader, SIGNAL(downloadFailure(QString, QString)), this, SLOT(handleDownloadFailure(QString, QString))); connect(downloader, SIGNAL(downloadFailure(QString, QString)), this, SLOT(handleDownloadFailure(QString, QString)));
loadSettings(); loadSupportedSearchEngines(true);
loadSupportedSearchEngines();
connect(pluginsTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(toggleEngineState(QTreeWidgetItem*, int))); connect(pluginsTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(toggleEngineState(QTreeWidgetItem*, int)));
show(); show();
} }
engineSelectDlg::~engineSelectDlg() { engineSelectDlg::~engineSelectDlg() {
qDebug("Destroying engineSelectDlg"); qDebug("Destroying engineSelectDlg");
saveSettings();
emit enginesChanged(); emit enginesChanged();
qDebug("Before deleting downloader"); qDebug("Before deleting downloader");
delete downloader; delete downloader;
@ -95,16 +95,17 @@ void engineSelectDlg::dragEnterEvent(QDragEnterEvent *event) {
} }
} }
void engineSelectDlg::loadSettings() {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
known_engines = settings.value(QString::fromUtf8("SearchEngines/knownEngines"), QStringList()).toStringList();
known_enginesEnabled = settings.value(QString::fromUtf8("SearchEngines/knownEnginesEnabled"), QList<QVariant>()).toList();
}
void engineSelectDlg::saveSettings() { void engineSelectDlg::saveSettings() {
QStringList known_engines;
QVariantList known_enginesEnabled;
QString engine;
foreach(engine, installed_engines) {
known_engines << engine;
known_enginesEnabled << QVariant(installed_engines.value(engine, true));
}
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
settings.setValue(QString::fromUtf8("SearchEngines/knownEngines"), installed_engines); settings.setValue(QString::fromUtf8("SearchEngines/knownEngines"), known_engines);
settings.setValue(QString::fromUtf8("SearchEngines/knownEnginesEnabled"), enginesEnabled); settings.setValue(QString::fromUtf8("SearchEngines/knownEnginesEnabled"), known_enginesEnabled);
} }
void engineSelectDlg::on_updateButton_clicked() { void engineSelectDlg::on_updateButton_clicked() {
@ -114,9 +115,9 @@ void engineSelectDlg::on_updateButton_clicked() {
void engineSelectDlg::toggleEngineState(QTreeWidgetItem *item, int) { void engineSelectDlg::toggleEngineState(QTreeWidgetItem *item, int) {
int index = pluginsTree->indexOfTopLevelItem(item); int index = pluginsTree->indexOfTopLevelItem(item);
Q_ASSERT(index != -1); QString id = item->text(ENGINE_ID);
bool new_val = !enginesEnabled.at(index).toBool(); bool new_val = !installed_engines.value(id, true);
enginesEnabled.replace(index, QVariant(new_val)); installed_engines[id] = new_val;
QString enabledTxt; QString enabledTxt;
if(new_val){ if(new_val){
enabledTxt = tr("True"); enabledTxt = tr("True");
@ -136,13 +137,12 @@ void engineSelectDlg::displayContextMenu(const QPoint& pos) {
bool has_enable = false, has_disable = false; bool has_enable = false, has_disable = false;
QTreeWidgetItem *item; QTreeWidgetItem *item;
foreach(item, items) { foreach(item, items) {
int index = pluginsTree->indexOfTopLevelItem(item); QString id = item->text(ENGINE_ID);
Q_ASSERT(index != -1); if(installed_engines.value(id, true) and !has_disable) {
if(enginesEnabled.at(index).toBool() and !has_disable) {
myContextMenu.addAction(actionDisable); myContextMenu.addAction(actionDisable);
has_disable = true; has_disable = true;
} }
if(!enginesEnabled.at(index).toBool() and !has_enable) { if(!installed_engines.value(id, true) and !has_enable) {
myContextMenu.addAction(actionEnable); myContextMenu.addAction(actionEnable);
has_enable = true; has_enable = true;
} }
@ -165,33 +165,31 @@ void engineSelectDlg::on_actionUninstall_triggered() {
foreach(item, items) { foreach(item, items) {
int index = pluginsTree->indexOfTopLevelItem(item); int index = pluginsTree->indexOfTopLevelItem(item);
Q_ASSERT(index != -1); Q_ASSERT(index != -1);
QString name = installed_engines.at(index); QString id = item->text(ENGINE_ID);
if(QFile::exists(":/search_engine/engines/"+name+".py")) { if(QFile::exists(":/search_engine/engines/"+id+".py")) {
error = true; error = true;
// Disable it instead // Disable it instead
enginesEnabled.replace(index, QVariant(false)); installed_engines.insert(id, false);
item->setText(ENGINE_STATE, tr("False")); item->setText(ENGINE_STATE, tr("False"));
setRowColor(index, "red"); setRowColor(index, "red");
continue; continue;
}else { }else {
// Proceed with uninstall // Proceed with uninstall
// remove it from hard drive // remove it from hard drive
QFile::remove(misc::qBittorrentPath()+"search_engine"+QDir::separator()+"engines"+QDir::separator()+name+".py"); QDir enginesFolder(misc::qBittorrentPath()+"search_engine"+QDir::separator()+"engines");
if(QFile::exists(misc::qBittorrentPath()+"search_engine"+QDir::separator()+"engines"+QDir::separator()+name+".png")) { QStringList filters;
QFile::remove(misc::qBittorrentPath()+"search_engine"+QDir::separator()+"engines"+QDir::separator()+name+".png"); filters << id+".*";
} QStringList files = enginesFolder.entryList(filters, QDir::Files, QDir::Unsorted);
if(QFile::exists(misc::qBittorrentPath()+"search_engine"+QDir::separator()+"engines"+QDir::separator()+name+".pyc")) { QString file;
QFile::remove(misc::qBittorrentPath()+"search_engine"+QDir::separator()+"engines"+QDir::separator()+name+".pyc"); foreach(file, files) {
enginesFolder.remove(file);
} }
// Remove it from lists // Remove it from lists
installed_engines.removeAt(index); installed_engines.remove(id);
enginesEnabled.removeAt(index); delete item;
pluginsTree->takeTopLevelItem(index);
change = true; change = true;
} }
} }
if(change)
saveSettings();
if(error) if(error)
QMessageBox::warning(0, tr("Uninstall warning"), tr("Some plugins could not be uninstalled because they are included in qBittorrent.\n Only the ones you added yourself can be uninstalled.\nHowever, those plugins were disabled.")); QMessageBox::warning(0, tr("Uninstall warning"), tr("Some plugins could not be uninstalled because they are included in qBittorrent.\n Only the ones you added yourself can be uninstalled.\nHowever, those plugins were disabled."));
else else
@ -204,7 +202,8 @@ void engineSelectDlg::enableSelection() {
foreach(item, items) { foreach(item, items) {
int index = pluginsTree->indexOfTopLevelItem(item); int index = pluginsTree->indexOfTopLevelItem(item);
Q_ASSERT(index != -1); Q_ASSERT(index != -1);
enginesEnabled.replace(index, QVariant(true)); QString id = item->text(ENGINE_ID);
installed_engines.insert(id, true);
item->setText(ENGINE_STATE, tr("True")); item->setText(ENGINE_STATE, tr("True"));
setRowColor(index, "green"); setRowColor(index, "green");
} }
@ -216,7 +215,8 @@ void engineSelectDlg::disableSelection() {
foreach(item, items) { foreach(item, items) {
int index = pluginsTree->indexOfTopLevelItem(item); int index = pluginsTree->indexOfTopLevelItem(item);
Q_ASSERT(index != -1); Q_ASSERT(index != -1);
enginesEnabled.replace(index, QVariant(false)); QString id = item->text(ENGINE_ID);
installed_engines.insert(id, false);
item->setText(ENGINE_STATE, tr("False")); item->setText(ENGINE_STATE, tr("False"));
setRowColor(index, "red"); setRowColor(index, "red");
} }
@ -225,7 +225,7 @@ void engineSelectDlg::disableSelection() {
// Set the color of a row in data model // Set the color of a row in data model
void engineSelectDlg::setRowColor(int row, QString color){ void engineSelectDlg::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()-1; ++i){
item->setData(i, Qt::ForegroundRole, QVariant(QColor(color))); item->setData(i, Qt::ForegroundRole, QVariant(QColor(color)));
} }
} }
@ -243,11 +243,23 @@ bool engineSelectDlg::checkInstalled(QString plugin_name) const {
return plugins_list.contains(plugin_name.toUtf8()); return plugins_list.contains(plugin_name.toUtf8());
} }
void engineSelectDlg::loadSupportedSearchEngines() { void engineSelectDlg::loadSupportedSearchEngines(bool first) {
// Some clean up first // Some clean up first
pluginsTree->clear(); pluginsTree->clear();
QHash<QString, bool> old_engines;
if(first) {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
QStringList known_engines = settings.value(QString::fromUtf8("SearchEngines/knownEngines"), QStringList()).toStringList();
QVariantList enabled = settings.value(QString::fromUtf8("SearchEngines/knownEnginesEnabled"), QList<QVariant>()).toList();
Q_ASSERT(known_engines.size() == enabled.size());
unsigned int nbKnownEngines = known_engines.size();
for(unsigned int i=0; i<nbKnownEngines; ++i) {
old_engines[known_engines.at(i)] = enabled.at(i).toBool();
}
} else {
old_engines = installed_engines;
}
installed_engines.clear(); installed_engines.clear();
enginesEnabled.clear();
QStringList params; QStringList params;
// Ask nova core for the supported search engines // Ask nova core for the supported search engines
QProcess nova; QProcess nova;
@ -259,14 +271,11 @@ void engineSelectDlg::loadSupportedSearchEngines() {
result = result.replace("\n", ""); result = result.replace("\n", "");
qDebug("read: %s", result.data()); qDebug("read: %s", result.data());
QByteArray e; QByteArray e;
QStringList supported_engines_ids;
foreach(e, result.split(',')) { foreach(e, result.split(',')) {
QString en = QString(e); QString en = QString(e);
installed_engines << en; supported_engines_ids << en;
int index = known_engines.indexOf(en); installed_engines[en] = old_engines.value(en, true);
if(index == -1)
enginesEnabled << true;
else
enginesEnabled << known_enginesEnabled.at(index).toBool();
} }
params.clear(); params.clear();
params << "--supported_engines_infos"; params << "--supported_engines_infos";
@ -278,19 +287,21 @@ void engineSelectDlg::loadSupportedSearchEngines() {
qDebug("read: %s", result.data()); qDebug("read: %s", result.data());
unsigned int i = 0; unsigned int i = 0;
foreach(e, result.split(',')) { foreach(e, result.split(',')) {
QString id = supported_engines_ids.at(i);
QString nameUrlCouple(e); QString nameUrlCouple(e);
QStringList line = nameUrlCouple.split('|'); QStringList line = nameUrlCouple.split('|');
if(line.size() != 2) continue; if(line.size() != 2) continue;
// Download favicon // Download favicon
QString enabledTxt; QString enabledTxt;
if(enginesEnabled.at(i).toBool()){ if(installed_engines.value(id, true)) {
enabledTxt = tr("True"); enabledTxt = tr("True");
}else{ } else {
enabledTxt = tr("False"); enabledTxt = tr("False");
} }
line << enabledTxt; line << enabledTxt;
line << id;
QTreeWidgetItem *item = new QTreeWidgetItem(pluginsTree, line); QTreeWidgetItem *item = new QTreeWidgetItem(pluginsTree, line);
QString iconPath = misc::qBittorrentPath()+"search_engine"+QDir::separator()+"engines"+QDir::separator()+installed_engines.at(i)+".png"; QString iconPath = misc::qBittorrentPath()+"search_engine"+QDir::separator()+"engines"+QDir::separator()+id+".png";
if(QFile::exists(iconPath)) { if(QFile::exists(iconPath)) {
// Good, we already have the icon // Good, we already have the icon
item->setData(ENGINE_NAME, Qt::DecorationRole, QVariant(QIcon(iconPath))); item->setData(ENGINE_NAME, Qt::DecorationRole, QVariant(QIcon(iconPath)));
@ -298,7 +309,7 @@ void engineSelectDlg::loadSupportedSearchEngines() {
// Icon is missing, we must download it // Icon is missing, we must download it
downloader->downloadUrl(line.at(1)+"/favicon.ico"); downloader->downloadUrl(line.at(1)+"/favicon.ico");
} }
if(enginesEnabled.at(i).toBool()) if(installed_engines.value(id, true))
setRowColor(i, "green"); setRowColor(i, "green");
else else
setRowColor(i, "red"); setRowColor(i, "red");
@ -451,9 +462,8 @@ void engineSelectDlg::processDownloadedFile(QString url, QString filePath) {
QList<QTreeWidgetItem*> items = findItemsWithUrl(url); QList<QTreeWidgetItem*> items = findItemsWithUrl(url);
QTreeWidgetItem *item; QTreeWidgetItem *item;
foreach(item, items){ foreach(item, items){
int index = pluginsTree->indexOfTopLevelItem(item); QString id = item->text(ENGINE_ID);
Q_ASSERT(index != -1); QString iconPath = misc::qBittorrentPath()+"search_engine"+QDir::separator()+"engines"+QDir::separator()+id+".png";
QString iconPath = misc::qBittorrentPath()+"search_engine"+QDir::separator()+"engines"+QDir::separator()+installed_engines.at(index)+".png";
QFile::copy(filePath, iconPath); QFile::copy(filePath, iconPath);
item->setData(ENGINE_NAME, Qt::DecorationRole, QVariant(QIcon(iconPath))); item->setData(ENGINE_NAME, Qt::DecorationRole, QVariant(QIcon(iconPath)));
} }

8
src/engineSelectDlg.h

@ -32,10 +32,7 @@ class engineSelectDlg : public QDialog, public Ui::engineSelect{
private: private:
// Search related // Search related
QStringList installed_engines; QHash<QString, bool> installed_engines;
QVariantList enginesEnabled;
QStringList known_engines;
QVariantList known_enginesEnabled;
downloadThread *downloader; downloadThread *downloader;
public: public:
@ -52,10 +49,9 @@ class engineSelectDlg : public QDialog, public Ui::engineSelect{
void enginesChanged(); void enginesChanged();
protected slots: protected slots:
void loadSettings();
void saveSettings(); void saveSettings();
void on_closeButton_clicked(); void on_closeButton_clicked();
void loadSupportedSearchEngines(); void loadSupportedSearchEngines(bool first=false);
void toggleEngineState(QTreeWidgetItem*, int); void toggleEngineState(QTreeWidgetItem*, int);
void setRowColor(int row, QString color); void setRowColor(int row, QString color);
void processDownloadedFile(QString url, QString filePath); void processDownloadedFile(QString url, QString filePath);

Loading…
Cancel
Save