- Updated configure file to check for libcommoncpp2 instead of libcurl

- Used downloadThread in search plugin update instead of libcurl (no more gui freeze by the same occasion)
- Still need to handle download from urls errors and use fallback url in search plugin update (before beta2)
This commit is contained in:
Christophe Dumez 2007-07-20 17:11:02 +00:00
commit 2fd0de082c
13 changed files with 145 additions and 204 deletions

View file

@ -128,11 +128,6 @@ class misc : public QObject{
return true;
}
// Function called by curl to write the data to the file
static int my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream){
return fwrite(buffer, size, nmemb, (FILE*)stream);
}
static QString findFileInDir(const QString& dir_path, const QString& fileName){
QDir dir(dir_path);
if(dir.exists(fileName)){

View file

@ -37,7 +37,6 @@
#include <QFile>
#include <QImage>
#include <QList>
#include <curl/curl.h>
#include <QTemporaryFile>
#include <QSettings>
#include <QDomDocument>

View file

@ -27,12 +27,12 @@
#include <QSystemTrayIcon>
#include <QTemporaryFile>
#include <QSystemTrayIcon>
#include <curl/curl.h>
#include <iostream>
#include "SearchListDelegate.h"
#include "searchEngine.h"
#include "bittorrent.h"
#include "downloadThread.h"
#define SEARCH_NAME 0
#define SEARCH_SIZE 1
@ -46,6 +46,8 @@ SearchEngine::SearchEngine(bittorrent *BTSession, QSystemTrayIcon *myTrayIcon, b
setupUi(this);
this->BTSession = BTSession;
this->myTrayIcon = myTrayIcon;
downloader = new downloadThread(this);
connect(downloader, SIGNAL(downloadFinished(const QString&, const QString&)), this, SLOT(novaUpdateDownloaded(const QString&, const QString&)));
// Set Search results list model
SearchListModel = new QStandardItemModel(0,5);
SearchListModel->setHeaderData(SEARCH_NAME, Qt::Horizontal, tr("Name", "i.e: file name"));
@ -110,6 +112,7 @@ SearchEngine::~SearchEngine(){
delete searchCompleter;
delete SearchListModel;
delete SearchDelegate;
delete downloader;
}
// Set the color of a row in data model
@ -428,98 +431,45 @@ void SearchEngine::updateNova() const{
}
}
// Download nova.py from qbittorrent.org
// Check if our nova.py is outdated and
// ask user for action.
void SearchEngine::on_update_nova_button_clicked(){
CURL *curl;
QString filePath;
qDebug("Checking for search plugin updates on qbittorrent.org");
// XXX: Trick to get a unique filename
QTemporaryFile *tmpfile = new QTemporaryFile;
if (tmpfile->open()) {
filePath = tmpfile->fileName();
}
delete tmpfile;
FILE *file = fopen((const char*)filePath.toUtf8(), "w");
if(!file){
std::cerr << "Error: could not open temporary file...\n";
}
// Initilization required by libcurl
curl = curl_easy_init();
if(!curl){
std::cerr << "Error: Failed to init curl...\n";
fclose(file);
return;
}
// Set url to download
curl_easy_setopt(curl, CURLOPT_URL, "http://www.dchris.eu/nova/nova.zip");
// Define our callback to get called when there's data to be written
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, misc::my_fwrite);
// Set destination file
curl_easy_setopt(curl, CURLOPT_WRITEDATA, file);
// Some SSL mambo jambo
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
// Perform Download
curl_easy_perform(curl); /* ignores error */
// Cleanup
curl_easy_cleanup(curl);
// Close tmp file
fclose(file);
qDebug("Version on qbittorrent.org: %.2f", getNovaVersion(filePath));
void SearchEngine::novaUpdateDownloaded(const QString&, const QString& filePath){
float version_on_server = getNovaVersion(filePath);
if(version_on_server == 0.0){
//First server is down, try the mirror
QFile::remove(filePath);
FILE *file = fopen((const char*)filePath.toUtf8(), "w");
if(!file){
std::cerr << "Error: could not open temporary file...\n";
}
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, "http://hydr0g3n.free.fr/nova/nova.py");
// Define our callback to get called when there's data to be written
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, misc::my_fwrite);
// Set destination file
curl_easy_setopt(curl, CURLOPT_WRITEDATA, file);
// Some SSL mambo jambo
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
// Perform Download
curl_easy_perform(curl); /* ignores error */
// Cleanup
curl_easy_cleanup(curl);
// Close tmp file
fclose(file);
version_on_server = getNovaVersion(filePath);
}
qDebug("Version on qbittorrent.org: %.2f", version_on_server);
if(version_on_server > getNovaVersion(misc::qBittorrentPath()+"nova.py")){
if(QMessageBox::question(this,
tr("Search plugin update -- qBittorrent"),
tr("Search plugin can be updated, do you want to update it?\n\nChangelog:\n")+getNovaChangelog(filePath),
tr("&Yes"), tr("&No"),
QString(), 0, 1)){
return;
}else{
qDebug("Updating search plugin from qbittorrent.org");
QFile::remove(misc::qBittorrentPath()+"nova.py");
QFile::copy(filePath, misc::qBittorrentPath()+"nova.py");
QFile::Permissions perm=QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner | QFile::ReadUser | QFile::WriteUser | QFile::ExeUser | QFile::ReadGroup | QFile::ReadGroup;
QFile(misc::qBittorrentPath()+"nova.py").setPermissions(perm);
}
tr("Search plugin update -- qBittorrent"),
tr("Search plugin can be updated, do you want to update it?\n\nChangelog:\n")+getNovaChangelog(filePath),
tr("&Yes"), tr("&No"),
QString(), 0, 1)){
return;
}else{
qDebug("Updating search plugin from qbittorrent.org");
QFile::remove(misc::qBittorrentPath()+"nova.py");
QFile::copy(filePath, misc::qBittorrentPath()+"nova.py");
QFile::Permissions perm=QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner | QFile::ReadUser | QFile::WriteUser | QFile::ExeUser | QFile::ReadGroup | QFile::ReadGroup;
QFile(misc::qBittorrentPath()+"nova.py").setPermissions(perm);
}
}else{
if(version_on_server == 0.0){
QMessageBox::information(this, tr("Search plugin update")+" -- "+tr("qBittorrent"),
tr("Sorry, update server is temporarily unavailable."));
}else{
QMessageBox::information(this, tr("Search plugin update -- qBittorrent"),
tr("Your search plugin is already up to date."));
tr("Your search plugin is already up to date."));
}
}
// Delete tmp file
QFile::remove(filePath);
}
// Download nova.py from qbittorrent.org
// Check if our nova.py is outdated and
// ask user for action.
void SearchEngine::on_update_nova_button_clicked(){
qDebug("Checking for search plugin updates on qbittorrent.org");
downloader->downloadUrl("http://www.dchris.eu/nova/nova.zip");
//TODO: make use of fallback url: "http://hydr0g3n.free.fr/nova/nova.py"
}
// Slot called when search is Finished
// Search can be finished for 3 reasons :
// Error | Stopped by user | Finished normally

View file

@ -31,6 +31,7 @@ class QStandardItemModel;
class SearchListDelegate;
class bittorrent;
class QSystemTrayIcon;
class downloadThread;
class SearchEngine : public QWidget, public Ui::search_engine{
Q_OBJECT
@ -50,6 +51,7 @@ class SearchEngine : public QWidget, public Ui::search_engine{
bittorrent *BTSession;
QSystemTrayIcon *myTrayIcon;
bool systrayIntegration;
downloadThread *downloader;
public:
SearchEngine(bittorrent *BTSession, QSystemTrayIcon *myTrayIcon, bool systrayIntegration);
@ -80,6 +82,7 @@ class SearchEngine : public QWidget, public Ui::search_engine{
void sortSearchList(int index);
void sortSearchListInt(int index, Qt::SortOrder sortOrder);
void sortSearchListString(int index, Qt::SortOrder sortOrder);
void novaUpdateDownloaded(const QString& url, const QString& path);
};
#endif

View file

@ -2,9 +2,6 @@
LANG_PATH = lang
ICONS_PATH = Icons
LIBS += -lccext2
LIBS += -lccgnu2
#Set the following variable to 1 to enable debug
DEBUG_MODE = 1
@ -30,7 +27,7 @@ contains(DEBUG_MODE, 0){
QMAKE_CXXFLAGS_RELEASE += -fwrapv
QMAKE_CXXFLAGS_DEBUG += -fwrapv
#LIBS += -lcurl -lupnp
CONFIG += link_pkgconfig
PKGCONFIG += libtorrent
QT += network xml
@ -78,7 +75,7 @@ contains(DEBUG_MODE, 0){
# Windows
win32 {
DEFINES += NO_UPNP
LIBS += -lcurl -ltorrent
LIBS += -ltorrent -lccext2 -lccgnu2
}
RESOURCES = icons.qrc \