From 2c27f952e20c314b2221053ecb45054603fd5971 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sun, 2 Sep 2007 09:01:22 +0000 Subject: [PATCH] - FEATURE: Allow to drag'n drop plugin to list for install/update - Added some debug --- TODO | 2 +- src/GUI.cpp | 4 ++ src/engineSelect.ui | 3 + src/engineSelectDlg.cpp | 133 +++++++++++++++++++++++++--------------- src/engineSelectDlg.h | 4 ++ 5 files changed, 97 insertions(+), 49 deletions(-) diff --git a/TODO b/TODO index 6f987095f..026fccd97 100644 --- a/TODO +++ b/TODO @@ -49,7 +49,6 @@ - valgrind --tool=memcheck --leak-check=full src/qbittorrent (Looks ok) - 128m 29m 16m S 4.8 2.9 0:02.28 qbittorrent * beta 7 - - Allow to drag'n drop plugins - read icon meta in xhtml pages when favicon.ico can't be downloaded? - Translations update (IN PROGRESS) - Wait for some bug fixes in libtorrent : @@ -78,6 +77,7 @@ LANGUAGES UPDATED: beta6->beta7 changelog: - FEATURE: Made search engine plugin install more reliable +- FEATURE: Allow to drag'n drop plugin to list for install/update - BUGFIX: Updated man page / README / INSTALL - BUGFIX: Paused torrents could be displayed as connected for a sec after checking - BUGFIX: 'Unknown' is now displayed in search results columns where value is -1 diff --git a/src/GUI.cpp b/src/GUI.cpp index 5fa5882e1..423e5cb86 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -553,6 +553,10 @@ void GUI::dropEvent(QDropEvent *event) { // Decode if we accept drag 'n drop or not void GUI::dragEnterEvent(QDragEnterEvent *event) { + QString mime; + foreach(mime, event->mimeData()->formats()){ + qDebug("mimeData: %s", mime.toUtf8().data()); + } if (event->mimeData()->hasFormat(QString::fromUtf8("text/plain"))) { event->acceptProposedAction(); } diff --git a/src/engineSelect.ui b/src/engineSelect.ui index efbd36668..00af11ce1 100644 --- a/src/engineSelect.ui +++ b/src/engineSelect.ui @@ -9,6 +9,9 @@ 254 + + true + Search plugins diff --git a/src/engineSelectDlg.cpp b/src/engineSelectDlg.cpp index 128d88aef..f49da5436 100644 --- a/src/engineSelectDlg.cpp +++ b/src/engineSelectDlg.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #ifdef HAVE_MAGICK #include @@ -67,6 +68,33 @@ engineSelectDlg::~engineSelectDlg() { qDebug("Engine plugins dialog destroyed"); } +void engineSelectDlg::dropEvent(QDropEvent *event) { + event->acceptProposedAction(); + QStringList files=event->mimeData()->text().split(QString::fromUtf8("\n")); + QString file; + foreach(file, files) { + qDebug("dropped %s", file.toUtf8().data()); + file = file.replace("file://", ""); + if(file.startsWith("http://") || file.startsWith("https://") || file.startsWith("ftp://")) { + downloader->downloadUrl(file); + continue; + } + if(file.endsWith(".py")) + installPlugin(file); + } +} + +// Decode if we accept drag 'n drop or not +void engineSelectDlg::dragEnterEvent(QDragEnterEvent *event) { + QString mime; + foreach(mime, event->mimeData()->formats()){ + qDebug("mimeData: %s", mime.toUtf8().data()); + } + if (event->mimeData()->hasFormat(QString::fromUtf8("text/plain"))) { + event->acceptProposedAction(); + } +} + void engineSelectDlg::loadSettings() { QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); known_engines = settings.value(QString::fromUtf8("SearchEngines/knownEngines"), QStringList()).toStringList(); @@ -293,61 +321,65 @@ bool engineSelectDlg::isUpdateNeeded(QString plugin_name, float new_version) con return (new_version > old_version); } -void engineSelectDlg::on_installButton_clicked() { - QStringList pathsList = QFileDialog::getOpenFileNames(0, - tr("Select search plugins"), QDir::homePath(), - tr("qBittorrent search plugins")+QString::fromUtf8(" (*.py)")); - QString path; - foreach(path, pathsList) { - if(!path.endsWith(".py")) continue; - float new_version = misc::getPluginVersion(path); - QString plugin_name = path.split(QDir::separator()).last(); - plugin_name.replace(".py", ""); - if(!isUpdateNeeded(plugin_name, new_version)) { - QMessageBox::information(this, tr("Search plugin install")+" -- "+tr("qBittorrent"), tr("A more recent version of %1 search engine plugin is already installed.", "%1 is the name of the search engine").arg(plugin_name.toUtf8().data())); - continue; - } +void engineSelectDlg::installPlugin(QString path) { + if(!path.endsWith(".py")) return; + float new_version = misc::getPluginVersion(path); + QString plugin_name = path.split(QDir::separator()).last(); + plugin_name.replace(".py", ""); + if(!isUpdateNeeded(plugin_name, new_version)) { + QMessageBox::information(this, tr("Search plugin install")+" -- "+tr("qBittorrent"), tr("A more recent version of %1 search engine plugin is already installed.", "%1 is the name of the search engine").arg(plugin_name.toUtf8().data())); + return; + } // Process with install - QString dest_path = misc::qBittorrentPath()+"search_engine"+QDir::separator()+"engines"+QDir::separator()+plugin_name+".py"; - bool update = false; - if(QFile::exists(dest_path)) { + QString dest_path = misc::qBittorrentPath()+"search_engine"+QDir::separator()+"engines"+QDir::separator()+plugin_name+".py"; + bool update = false; + if(QFile::exists(dest_path)) { // Backup in case install fails - QFile::copy(dest_path, dest_path+".bak"); - QFile::remove(dest_path); - update = true; - } + QFile::copy(dest_path, dest_path+".bak"); + QFile::remove(dest_path); + update = true; + } // Copy the plugin - QFile::copy(path, dest_path); + QFile::copy(path, dest_path); // Check if this was correctly installed - if(!checkInstalled(plugin_name)) { - if(update) { + if(!checkInstalled(plugin_name)) { + if(update) { // Remove broken file - QFile::remove(dest_path); + QFile::remove(dest_path); // restore backup - QFile::copy(dest_path+".bak", dest_path); - QFile::remove(dest_path+".bak"); - QMessageBox::warning(this, tr("Search plugin install")+" -- "+tr("qBittorrent"), tr("%1 search engine plugin could not be updated, keeping old version.", "%1 is the name of the search engine").arg(plugin_name.toUtf8().data())); - return; - } else { + QFile::copy(dest_path+".bak", dest_path); + QFile::remove(dest_path+".bak"); + QMessageBox::warning(this, tr("Search plugin install")+" -- "+tr("qBittorrent"), tr("%1 search engine plugin could not be updated, keeping old version.", "%1 is the name of the search engine").arg(plugin_name.toUtf8().data())); + return; + } else { // Remove broken file - QFile::remove(dest_path); - QMessageBox::warning(this, tr("Search plugin install")+" -- "+tr("qBittorrent"), tr("%1 search engine plugin could not be installed.", "%1 is the name of the search engine").arg(plugin_name.toUtf8().data())); - return; - } + QFile::remove(dest_path); + QMessageBox::warning(this, tr("Search plugin install")+" -- "+tr("qBittorrent"), tr("%1 search engine plugin could not be installed.", "%1 is the name of the search engine").arg(plugin_name.toUtf8().data())); + return; } + } // Install was successful, remove backup - if(update) { - QFile::remove(dest_path+".bak"); - } + if(update) { + QFile::remove(dest_path+".bak"); + } // Refresh plugin list - loadSupportedSearchEngines(); - if(update) { - QMessageBox::information(this, tr("Search plugin install")+" -- "+tr("qBittorrent"), tr("%1 search engine plugin was successfully updated.", "%1 is the name of the search engine").arg(plugin_name.toUtf8().data())); - continue; - } else { - QMessageBox::information(this, tr("Search plugin install")+" -- "+tr("qBittorrent"), tr("%1 search engine plugin was successfully installed.", "%1 is the name of the search engine").arg(plugin_name.toUtf8().data())); - continue; - } + loadSupportedSearchEngines(); + if(update) { + QMessageBox::information(this, tr("Search plugin install")+" -- "+tr("qBittorrent"), tr("%1 search engine plugin was successfully updated.", "%1 is the name of the search engine").arg(plugin_name.toUtf8().data())); + return; + } else { + QMessageBox::information(this, tr("Search plugin install")+" -- "+tr("qBittorrent"), tr("%1 search engine plugin was successfully installed.", "%1 is the name of the search engine").arg(plugin_name.toUtf8().data())); + return; + } +} + +void engineSelectDlg::on_installButton_clicked() { + QStringList pathsList = QFileDialog::getOpenFileNames(0, + tr("Select search plugins"), QDir::homePath(), + tr("qBittorrent search plugins")+QString::fromUtf8(" (*.py)")); + QString path; + foreach(path, pathsList) { + installPlugin(path); } } @@ -397,6 +429,7 @@ bool engineSelectDlg::parseVersionsFile(QString versions_file, QString updateSer } void engineSelectDlg::processDownloadedFile(QString url, QString filePath) { + qDebug("engineSelectDlg received %s", url.toUtf8().data()); if(url.endsWith("favicon.ico")){ // Icon downloaded QImage fileIcon; @@ -442,10 +475,11 @@ void engineSelectDlg::processDownloadedFile(QString url, QString filePath) { return; } } - if(url.endsWith(".zip")) { + if(url.endsWith(".zip") || url.endsWith(".py")) { // a plugin update has been downloaded QString plugin_name = url.split('/').last(); plugin_name.replace(".zip", ""); + plugin_name.replace(".py", ""); QString dest_path = misc::qBittorrentPath()+"search_engine"+QDir::separator()+"engines"+QDir::separator()+plugin_name+".py"; bool new_plugin = false; if(QFile::exists(dest_path)) { @@ -460,8 +494,10 @@ void engineSelectDlg::processDownloadedFile(QString url, QString filePath) { if(new_plugin) { // if it is new, refresh the list of plugins loadSupportedSearchEngines(); + QMessageBox::information(this, tr("Search plugin install")+" -- "+tr("qBittorrent"), tr("%1 search engine plugin was successfully installed.", "%1 is the name of the search engine").arg(plugin_name.toUtf8().data())); + } else { + QMessageBox::information(this, tr("Search plugin update")+" -- "+tr("qBittorrent"), tr("%1 search plugin was successfully updated.", "%1 is the name of the search engine").arg(plugin_name.toUtf8().data())); } - QMessageBox::information(this, tr("Search plugin update")+" -- "+tr("qBittorrent"), tr("%1 search plugin was successfully updated.", "%1 is the name of the search engine").arg(plugin_name.toUtf8().data())); } } @@ -480,10 +516,11 @@ void engineSelectDlg::handleDownloadFailure(QString url, QString reason) { QMessageBox::warning(this, tr("Search plugin update")+" -- "+tr("qBittorrent"), tr("Sorry, update server is temporarily unavailable.")); return; } - if(url.endsWith(".zip")) { + if(url.endsWith(".zip") || url.endsWith(".py")) { // a plugin update download has been failed QString plugin_name = url.split('/').last(); plugin_name.replace(".zip", ""); + plugin_name.replace(".py", ""); QMessageBox::warning(this, tr("Search plugin update")+" -- "+tr("qBittorrent"), tr("Sorry, %1 search plugin update failed.", "%1 is the name of the search engine").arg(plugin_name.toUtf8().data())); } } diff --git a/src/engineSelectDlg.h b/src/engineSelectDlg.h index dc55297a5..6bf506414 100644 --- a/src/engineSelectDlg.h +++ b/src/engineSelectDlg.h @@ -25,6 +25,7 @@ #include "ui_engineSelect.h" class downloadThread; +class QDropEvent; class engineSelectDlg : public QDialog, public Ui::engineSelect{ Q_OBJECT @@ -65,6 +66,9 @@ class engineSelectDlg : public QDialog, public Ui::engineSelect{ void on_actionUninstall_triggered(); void on_updateButton_clicked(); void on_installButton_clicked(); + void dropEvent(QDropEvent *event); + void dragEnterEvent(QDragEnterEvent *event); + void installPlugin(QString plugin_path); }; #endif