2008-05-17 17:23:37 +04:00
|
|
|
/*
|
2009-04-05 22:48:45 +04:00
|
|
|
* Bittorrent Client using Qt4 and libtorrent.
|
|
|
|
* Copyright (C) 2006 Ishan Arora and Christophe Dumez
|
2008-05-17 17:23:37 +04:00
|
|
|
*
|
2009-04-05 22:48:45 +04:00
|
|
|
* 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.
|
2008-05-17 17:23:37 +04:00
|
|
|
*
|
2009-04-05 22:48:45 +04:00
|
|
|
* 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.
|
2008-05-17 17:23:37 +04:00
|
|
|
*
|
2009-04-05 22:48:45 +04:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Contact : chris@qbittorrent.org
|
2008-05-17 17:23:37 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2010-06-07 12:32:41 +04:00
|
|
|
#include <libtorrent/version.hpp>
|
2008-05-17 17:23:37 +04:00
|
|
|
#include "eventmanager.h"
|
2008-08-08 17:17:26 +04:00
|
|
|
#include "bittorrent.h"
|
2010-03-18 22:25:16 +03:00
|
|
|
#include "scannedfoldersmodel.h"
|
2009-11-23 13:37:55 +03:00
|
|
|
#include "misc.h"
|
2009-11-26 11:10:23 +03:00
|
|
|
#include "preferences.h"
|
2010-01-03 01:20:37 +03:00
|
|
|
//#include "proplistdelegate.h"
|
2009-11-24 11:53:14 +03:00
|
|
|
#include "torrentpersistentdata.h"
|
2008-05-17 17:23:37 +04:00
|
|
|
#include <QDebug>
|
2010-09-25 16:42:19 +04:00
|
|
|
#include <QTranslator>
|
2008-05-17 17:23:37 +04:00
|
|
|
|
2009-11-20 11:01:59 +03:00
|
|
|
EventManager::EventManager(QObject *parent, Bittorrent *BTSession)
|
* Replace priority combo boxes by check boxes in Web UI as in Regular UI
* Prepare http server and preferences classes to add new settings to Web UI
* Tabified Program preferences in Web UI since there will be a lot of settings soon
* Started to add new settings to Web UI (PeX, LSD, Encryption, save path, temp path, scan dir, preallocateall, queueing, listen_port, upnp, nat-pmp, language, ip filter) -> Proxy is missing
* Added a command line parameter to change the web ui port
* Fix PeerGuardian .p2b binary filter support
2009-12-28 22:39:47 +03:00
|
|
|
: QObject(parent), BTSession(BTSession)
|
2008-05-17 17:23:37 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-12-25 17:33:37 +03:00
|
|
|
QList<QVariantMap> EventManager::getEventList() const {
|
2009-11-19 21:28:30 +03:00
|
|
|
return event_list.values();
|
2008-05-17 17:23:37 +04:00
|
|
|
}
|
|
|
|
|
2009-11-24 14:14:02 +03:00
|
|
|
QList<QVariantMap> EventManager::getPropTrackersInfo(QString hash) const {
|
|
|
|
QList<QVariantMap> trackersInfo;
|
|
|
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
|
|
|
if(h.is_valid()) {
|
|
|
|
QHash<QString, TrackerInfos> trackers_data = BTSession->getTrackersInfo(hash);
|
|
|
|
std::vector<announce_entry> vect_trackers = h.trackers();
|
|
|
|
std::vector<announce_entry>::iterator it;
|
|
|
|
for(it = vect_trackers.begin(); it != vect_trackers.end(); it++) {
|
|
|
|
QVariantMap tracker;
|
|
|
|
QString tracker_url = misc::toQString(it->url);
|
|
|
|
tracker["url"] = tracker_url;
|
|
|
|
TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url));
|
|
|
|
QString error_message = data.last_message.trimmed();
|
2010-06-07 12:32:41 +04:00
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14
|
2009-11-24 14:14:02 +03:00
|
|
|
if(it->verified) {
|
|
|
|
tracker["status"] = tr("Working");
|
|
|
|
} else {
|
|
|
|
if(it->updating && it->fails == 0) {
|
|
|
|
tracker["status"] = tr("Updating...");
|
|
|
|
} else {
|
|
|
|
if(it->fails > 0) {
|
|
|
|
tracker["status"] = tr("Not working");
|
|
|
|
} else {
|
|
|
|
tracker["status"] = tr("Not contacted yet");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if(data.verified) {
|
|
|
|
tracker["status"] = tr("Working");
|
|
|
|
} else {
|
|
|
|
if(data.fail_count > 0)
|
|
|
|
tracker["status"] = tr("Not working");
|
|
|
|
else
|
|
|
|
tracker["status"] = tr("Not contacted yet");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
tracker["num_peers"] = QString::number(trackers_data.value(tracker_url, TrackerInfos(tracker_url)).num_peers);
|
|
|
|
tracker["msg"] = error_message;
|
|
|
|
trackersInfo << tracker;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return trackersInfo;
|
|
|
|
}
|
|
|
|
|
2009-11-24 16:10:17 +03:00
|
|
|
QList<QVariantMap> EventManager::getPropFilesInfo(QString hash) const {
|
|
|
|
QList<QVariantMap> files;
|
|
|
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
2009-12-05 17:24:45 +03:00
|
|
|
if(!h.is_valid() || !h.has_metadata()) return files;
|
2009-11-24 16:10:17 +03:00
|
|
|
std::vector<int> priorities = h.file_priorities();
|
2009-11-24 22:47:23 +03:00
|
|
|
std::vector<size_type> fp;
|
2009-11-24 16:10:17 +03:00
|
|
|
h.file_progress(fp);
|
|
|
|
torrent_info t = h.get_torrent_info();
|
|
|
|
torrent_info::file_iterator fi;
|
|
|
|
int i=0;
|
|
|
|
for(fi=t.begin_files(); fi != t.end_files(); fi++) {
|
|
|
|
QVariantMap file;
|
2010-06-07 17:41:32 +04:00
|
|
|
QString path = QDir::cleanPath(misc::toQStringU(fi->path.string()));
|
2010-01-15 01:53:59 +03:00
|
|
|
QString name = path.split('/').last();
|
|
|
|
file["name"] = name;
|
2009-11-24 16:10:17 +03:00
|
|
|
file["size"] = misc::friendlyUnit((double)fi->size);
|
2009-11-29 17:34:39 +03:00
|
|
|
if(fi->size > 0)
|
|
|
|
file["progress"] = fp[i]/(double)fi->size;
|
|
|
|
else
|
|
|
|
file["progress"] = 1.; // Empty file...
|
2009-11-24 18:38:47 +03:00
|
|
|
file["priority"] = priorities[i];
|
2010-05-24 23:37:56 +04:00
|
|
|
if(i == 0)
|
|
|
|
file["is_seed"] = h.is_seed();
|
2009-11-24 16:10:17 +03:00
|
|
|
files << file;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
return files;
|
|
|
|
}
|
|
|
|
|
* Replace priority combo boxes by check boxes in Web UI as in Regular UI
* Prepare http server and preferences classes to add new settings to Web UI
* Tabified Program preferences in Web UI since there will be a lot of settings soon
* Started to add new settings to Web UI (PeX, LSD, Encryption, save path, temp path, scan dir, preallocateall, queueing, listen_port, upnp, nat-pmp, language, ip filter) -> Proxy is missing
* Added a command line parameter to change the web ui port
* Fix PeerGuardian .p2b binary filter support
2009-12-28 22:39:47 +03:00
|
|
|
void EventManager::setGlobalPreferences(QVariantMap m) const {
|
|
|
|
// UI
|
2010-09-25 16:42:19 +04:00
|
|
|
if(m.contains("locale")) {
|
|
|
|
QString locale = m["locale"].toString();
|
|
|
|
if(Preferences::getLocale() != locale) {
|
|
|
|
QTranslator *translator = new QTranslator;
|
|
|
|
if(translator->load(QString::fromUtf8(":/lang/qbittorrent_") + locale)){
|
|
|
|
qDebug("%s locale recognized, using translation.", qPrintable(locale));
|
|
|
|
}else{
|
|
|
|
qDebug("%s locale unrecognized, using default (en_GB).", qPrintable(locale));
|
|
|
|
}
|
|
|
|
qApp->installTranslator(translator);
|
|
|
|
}
|
|
|
|
|
|
|
|
Preferences::setLocale(locale);
|
|
|
|
}
|
* Replace priority combo boxes by check boxes in Web UI as in Regular UI
* Prepare http server and preferences classes to add new settings to Web UI
* Tabified Program preferences in Web UI since there will be a lot of settings soon
* Started to add new settings to Web UI (PeX, LSD, Encryption, save path, temp path, scan dir, preallocateall, queueing, listen_port, upnp, nat-pmp, language, ip filter) -> Proxy is missing
* Added a command line parameter to change the web ui port
* Fix PeerGuardian .p2b binary filter support
2009-12-28 22:39:47 +03:00
|
|
|
// Downloads
|
|
|
|
if(m.contains("save_path"))
|
|
|
|
Preferences::setSavePath(m["save_path"].toString());
|
|
|
|
if(m.contains("temp_path_enabled"))
|
|
|
|
Preferences::setTempPathEnabled(m["temp_path_enabled"].toBool());
|
|
|
|
if(m.contains("temp_path"))
|
|
|
|
Preferences::setTempPath(m["temp_path"].toString());
|
2010-03-22 21:50:04 +03:00
|
|
|
if(m.contains("scan_dirs") && m.contains("download_in_scan_dirs")) {
|
2010-06-05 22:59:05 +04:00
|
|
|
QVariantList download_at_path_tmp = m["download_in_scan_dirs"].toList();
|
|
|
|
QList<bool> download_at_path;
|
|
|
|
foreach(QVariant var, download_at_path_tmp) {
|
|
|
|
download_at_path << var.toBool();
|
|
|
|
}
|
2010-03-18 22:25:16 +03:00
|
|
|
QStringList old_folders = Preferences::getScanDirs();
|
|
|
|
QStringList new_folders = m["scan_dirs"].toStringList();
|
2010-03-22 21:50:04 +03:00
|
|
|
if(download_at_path.size() == new_folders.size()) {
|
2010-03-22 21:58:30 +03:00
|
|
|
Preferences::setScanDirs(new_folders);
|
|
|
|
Preferences::setDownloadInScanDirs(download_at_path);
|
2010-03-22 21:50:04 +03:00
|
|
|
foreach(const QString &old_folder, old_folders) {
|
|
|
|
// Update deleted folders
|
|
|
|
if(!new_folders.contains(old_folder)) {
|
|
|
|
BTSession->getScanFoldersModel()->removePath(old_folder);
|
|
|
|
}
|
2010-03-18 22:25:16 +03:00
|
|
|
}
|
2010-03-22 21:50:04 +03:00
|
|
|
int i = 0;
|
|
|
|
foreach(const QString &new_folder, new_folders) {
|
2010-06-29 12:44:56 +04:00
|
|
|
qDebug("New watched folder: %s", qPrintable(new_folder));
|
2010-03-22 21:50:04 +03:00
|
|
|
// Update new folders
|
|
|
|
if(!old_folders.contains(new_folder)) {
|
2010-06-05 22:59:05 +04:00
|
|
|
BTSession->getScanFoldersModel()->addPath(new_folder, download_at_path.at(i));
|
2010-03-22 21:50:04 +03:00
|
|
|
}
|
|
|
|
++i;
|
2010-03-18 22:25:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-01-31 16:47:57 +03:00
|
|
|
if(m.contains("export_dir"))
|
|
|
|
Preferences::setExportDir(m["export_dir"].toString());
|
2010-08-19 23:10:46 +04:00
|
|
|
if(m.contains("mail_notification_enabled"))
|
|
|
|
Preferences::setMailNotificationEnabled(m["mail_notification_enabled"].toBool());
|
|
|
|
if(m.contains("mail_notification_email"))
|
|
|
|
Preferences::setMailNotificationEmail(m["mail_notification_email"].toString());
|
|
|
|
if(m.contains("mail_notification_smtp"))
|
|
|
|
Preferences::setMailNotificationSMTP(m["mail_notification_smtp"].toString());
|
2010-08-20 18:02:40 +04:00
|
|
|
if(m.contains("autorun_enabled"))
|
|
|
|
Preferences::setAutoRunEnabled(m["autorun_enabled"].toBool());
|
|
|
|
if(m.contains("autorun_program"))
|
|
|
|
Preferences::setAutoRunProgram(m["autorun_program"].toString());
|
* Replace priority combo boxes by check boxes in Web UI as in Regular UI
* Prepare http server and preferences classes to add new settings to Web UI
* Tabified Program preferences in Web UI since there will be a lot of settings soon
* Started to add new settings to Web UI (PeX, LSD, Encryption, save path, temp path, scan dir, preallocateall, queueing, listen_port, upnp, nat-pmp, language, ip filter) -> Proxy is missing
* Added a command line parameter to change the web ui port
* Fix PeerGuardian .p2b binary filter support
2009-12-28 22:39:47 +03:00
|
|
|
if(m.contains("preallocate_all"))
|
|
|
|
Preferences::preAllocateAllFiles(m["preallocate_all"].toBool());
|
|
|
|
if(m.contains("queueing_enabled"))
|
|
|
|
Preferences::setQueueingSystemEnabled(m["queueing_enabled"].toBool());
|
|
|
|
if(m.contains("max_active_downloads"))
|
|
|
|
Preferences::setMaxActiveDownloads(m["max_active_downloads"].toInt());
|
|
|
|
if(m.contains("max_active_torrents"))
|
|
|
|
Preferences::setMaxActiveTorrents(m["max_active_torrents"].toInt());
|
|
|
|
if(m.contains("max_active_uploads"))
|
|
|
|
Preferences::setMaxActiveUploads(m["max_active_uploads"].toInt());
|
2010-06-07 12:32:41 +04:00
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14
|
* Replace priority combo boxes by check boxes in Web UI as in Regular UI
* Prepare http server and preferences classes to add new settings to Web UI
* Tabified Program preferences in Web UI since there will be a lot of settings soon
* Started to add new settings to Web UI (PeX, LSD, Encryption, save path, temp path, scan dir, preallocateall, queueing, listen_port, upnp, nat-pmp, language, ip filter) -> Proxy is missing
* Added a command line parameter to change the web ui port
* Fix PeerGuardian .p2b binary filter support
2009-12-28 22:39:47 +03:00
|
|
|
if(m.contains("incomplete_files_ext"))
|
|
|
|
Preferences::useIncompleteFilesExtension(m["incomplete_files_ext"].toBool());
|
|
|
|
#endif
|
|
|
|
// Connection
|
|
|
|
if(m.contains("listen_port"))
|
|
|
|
Preferences::setSessionPort(m["listen_port"].toInt());
|
|
|
|
if(m.contains("upnp"))
|
|
|
|
Preferences::setUPnPEnabled(m["upnp"].toBool());
|
|
|
|
if(m.contains("natpmp"))
|
|
|
|
Preferences::setNATPMPEnabled(m["natpmp"].toBool());
|
|
|
|
if(m.contains("dl_limit"))
|
|
|
|
Preferences::setGlobalDownloadLimit(m["dl_limit"].toInt());
|
|
|
|
if(m.contains("up_limit"))
|
|
|
|
Preferences::setGlobalUploadLimit(m["up_limit"].toInt());
|
|
|
|
if(m.contains("max_connec"))
|
|
|
|
Preferences::setMaxConnecs(m["max_connec"].toInt());
|
|
|
|
if(m.contains("max_connec_per_torrent"))
|
|
|
|
Preferences::setMaxConnecsPerTorrent(m["max_connec_per_torrent"].toInt());
|
|
|
|
if(m.contains("max_uploads_per_torrent"))
|
|
|
|
Preferences::setMaxUploadsPerTorrent(m["max_uploads_per_torrent"].toInt());
|
|
|
|
// Bittorrent
|
|
|
|
if(m.contains("dht"))
|
|
|
|
Preferences::setDHTEnabled(m["dht"].toBool());
|
2010-03-22 23:34:12 +03:00
|
|
|
if(m.contains("dhtSameAsBT"))
|
|
|
|
Preferences::setDHTPortSameAsBT(m["dhtSameAsBT"].toBool());
|
|
|
|
if(m.contains("dht_port"))
|
|
|
|
Preferences::setDHTPort(m["dht_port"].toInt());
|
* Replace priority combo boxes by check boxes in Web UI as in Regular UI
* Prepare http server and preferences classes to add new settings to Web UI
* Tabified Program preferences in Web UI since there will be a lot of settings soon
* Started to add new settings to Web UI (PeX, LSD, Encryption, save path, temp path, scan dir, preallocateall, queueing, listen_port, upnp, nat-pmp, language, ip filter) -> Proxy is missing
* Added a command line parameter to change the web ui port
* Fix PeerGuardian .p2b binary filter support
2009-12-28 22:39:47 +03:00
|
|
|
if(m.contains("pex"))
|
|
|
|
Preferences::setPeXEnabled(m["pex"].toBool());
|
|
|
|
qDebug("Pex support: %d", (int)m["pex"].toBool());
|
|
|
|
if(m.contains("lsd"))
|
|
|
|
Preferences::setLSDEnabled(m["lsd"].toBool());
|
|
|
|
if(m.contains("encryption"))
|
|
|
|
Preferences::setEncryptionSetting(m["encryption"].toInt());
|
|
|
|
// Proxy
|
|
|
|
if(m.contains("proxy_type"))
|
2009-12-30 13:53:58 +03:00
|
|
|
Preferences::setPeerProxyType(m["proxy_type"].toInt());
|
* Replace priority combo boxes by check boxes in Web UI as in Regular UI
* Prepare http server and preferences classes to add new settings to Web UI
* Tabified Program preferences in Web UI since there will be a lot of settings soon
* Started to add new settings to Web UI (PeX, LSD, Encryption, save path, temp path, scan dir, preallocateall, queueing, listen_port, upnp, nat-pmp, language, ip filter) -> Proxy is missing
* Added a command line parameter to change the web ui port
* Fix PeerGuardian .p2b binary filter support
2009-12-28 22:39:47 +03:00
|
|
|
if(m.contains("proxy_ip"))
|
2009-12-30 13:53:58 +03:00
|
|
|
Preferences::setPeerProxyIp(m["proxy_ip"].toString());
|
* Replace priority combo boxes by check boxes in Web UI as in Regular UI
* Prepare http server and preferences classes to add new settings to Web UI
* Tabified Program preferences in Web UI since there will be a lot of settings soon
* Started to add new settings to Web UI (PeX, LSD, Encryption, save path, temp path, scan dir, preallocateall, queueing, listen_port, upnp, nat-pmp, language, ip filter) -> Proxy is missing
* Added a command line parameter to change the web ui port
* Fix PeerGuardian .p2b binary filter support
2009-12-28 22:39:47 +03:00
|
|
|
if(m.contains("proxy_port"))
|
2009-12-30 13:53:58 +03:00
|
|
|
Preferences::setPeerProxyPort(m["proxy_port"].toUInt());
|
* Replace priority combo boxes by check boxes in Web UI as in Regular UI
* Prepare http server and preferences classes to add new settings to Web UI
* Tabified Program preferences in Web UI since there will be a lot of settings soon
* Started to add new settings to Web UI (PeX, LSD, Encryption, save path, temp path, scan dir, preallocateall, queueing, listen_port, upnp, nat-pmp, language, ip filter) -> Proxy is missing
* Added a command line parameter to change the web ui port
* Fix PeerGuardian .p2b binary filter support
2009-12-28 22:39:47 +03:00
|
|
|
if(m.contains("proxy_auth_enabled"))
|
2009-12-30 13:53:58 +03:00
|
|
|
Preferences::setPeerProxyAuthEnabled(m["proxy_auth_enabled"].toBool());
|
* Replace priority combo boxes by check boxes in Web UI as in Regular UI
* Prepare http server and preferences classes to add new settings to Web UI
* Tabified Program preferences in Web UI since there will be a lot of settings soon
* Started to add new settings to Web UI (PeX, LSD, Encryption, save path, temp path, scan dir, preallocateall, queueing, listen_port, upnp, nat-pmp, language, ip filter) -> Proxy is missing
* Added a command line parameter to change the web ui port
* Fix PeerGuardian .p2b binary filter support
2009-12-28 22:39:47 +03:00
|
|
|
if(m.contains("proxy_username"))
|
2009-12-30 13:53:58 +03:00
|
|
|
Preferences::setPeerProxyUsername(m["proxy_username"].toString());
|
* Replace priority combo boxes by check boxes in Web UI as in Regular UI
* Prepare http server and preferences classes to add new settings to Web UI
* Tabified Program preferences in Web UI since there will be a lot of settings soon
* Started to add new settings to Web UI (PeX, LSD, Encryption, save path, temp path, scan dir, preallocateall, queueing, listen_port, upnp, nat-pmp, language, ip filter) -> Proxy is missing
* Added a command line parameter to change the web ui port
* Fix PeerGuardian .p2b binary filter support
2009-12-28 22:39:47 +03:00
|
|
|
if(m.contains("proxy_password"))
|
2009-12-30 13:53:58 +03:00
|
|
|
Preferences::setPeerProxyPassword(m["proxy_password"].toString());
|
|
|
|
if(m.contains("http_proxy_type"))
|
|
|
|
Preferences::setHTTPProxyType(m["http_proxy_type"].toInt());
|
|
|
|
if(m.contains("http_proxy_ip"))
|
|
|
|
Preferences::setHTTPProxyIp(m["http_proxy_ip"].toString());
|
|
|
|
if(m.contains("http_proxy_port"))
|
|
|
|
Preferences::setHTTPProxyPort(m["http_proxy_port"].toUInt());
|
|
|
|
if(m.contains("http_proxy_auth_enabled"))
|
|
|
|
Preferences::setHTTPProxyAuthEnabled(m["http_proxy_auth_enabled"].toBool());
|
|
|
|
if(m.contains("http_proxy_username"))
|
2009-12-30 18:07:51 +03:00
|
|
|
Preferences::setHTTPProxyUsername(m["http_proxy_username"].toString());
|
2009-12-30 13:53:58 +03:00
|
|
|
if(m.contains("http_proxy_password"))
|
2009-12-30 18:07:51 +03:00
|
|
|
Preferences::setHTTPProxyPassword(m["http_proxy_password"].toString());
|
* Replace priority combo boxes by check boxes in Web UI as in Regular UI
* Prepare http server and preferences classes to add new settings to Web UI
* Tabified Program preferences in Web UI since there will be a lot of settings soon
* Started to add new settings to Web UI (PeX, LSD, Encryption, save path, temp path, scan dir, preallocateall, queueing, listen_port, upnp, nat-pmp, language, ip filter) -> Proxy is missing
* Added a command line parameter to change the web ui port
* Fix PeerGuardian .p2b binary filter support
2009-12-28 22:39:47 +03:00
|
|
|
// IP Filter
|
|
|
|
if(m.contains("ip_filter_enabled"))
|
|
|
|
Preferences::setFilteringEnabled(m["ip_filter_enabled"].toBool());
|
|
|
|
if(m.contains("ip_filter_path"))
|
|
|
|
Preferences::setFilter(m["ip_filter_path"].toString());
|
|
|
|
// Web UI
|
|
|
|
if(m.contains("web_ui_port"))
|
|
|
|
Preferences::setWebUiPort(m["web_ui_port"].toUInt());
|
|
|
|
if(m.contains("web_ui_username"))
|
|
|
|
Preferences::setWebUiUsername(m["web_ui_username"].toString());
|
|
|
|
if(m.contains("web_ui_password"))
|
|
|
|
Preferences::setWebUiPassword(m["web_ui_password"].toString());
|
|
|
|
// Reload preferences
|
|
|
|
BTSession->configureSession();
|
|
|
|
}
|
|
|
|
|
2009-11-26 11:10:23 +03:00
|
|
|
QVariantMap EventManager::getGlobalPreferences() const {
|
|
|
|
QVariantMap data;
|
* Replace priority combo boxes by check boxes in Web UI as in Regular UI
* Prepare http server and preferences classes to add new settings to Web UI
* Tabified Program preferences in Web UI since there will be a lot of settings soon
* Started to add new settings to Web UI (PeX, LSD, Encryption, save path, temp path, scan dir, preallocateall, queueing, listen_port, upnp, nat-pmp, language, ip filter) -> Proxy is missing
* Added a command line parameter to change the web ui port
* Fix PeerGuardian .p2b binary filter support
2009-12-28 22:39:47 +03:00
|
|
|
// UI
|
|
|
|
data["locale"] = Preferences::getLocale();
|
|
|
|
// Downloads
|
|
|
|
data["save_path"] = Preferences::getSavePath();
|
|
|
|
data["temp_path_enabled"] = Preferences::isTempPathEnabled();
|
|
|
|
data["temp_path"] = Preferences::getTempPath();
|
2010-02-28 20:24:35 +03:00
|
|
|
data["scan_dirs"] = Preferences::getScanDirs();
|
2010-06-05 22:59:05 +04:00
|
|
|
QVariantList var_list;
|
|
|
|
foreach(bool b, Preferences::getDownloadInScanDirs()) {
|
|
|
|
var_list << b;
|
|
|
|
}
|
|
|
|
data["download_in_scan_dirs"] = var_list;
|
2010-01-31 16:47:57 +03:00
|
|
|
data["export_dir_enabled"] = Preferences::isTorrentExportEnabled();
|
|
|
|
data["export_dir"] = Preferences::getExportDir();
|
2010-08-19 23:10:46 +04:00
|
|
|
data["mail_notification_enabled"] = Preferences::isMailNotificationEnabled();
|
|
|
|
data["mail_notification_email"] = Preferences::getMailNotificationEmail();
|
|
|
|
data["mail_notification_smtp"] = Preferences::getMailNotificationSMTP();
|
2010-08-20 18:02:40 +04:00
|
|
|
data["autorun_enabled"] = Preferences::isAutoRunEnabled();
|
|
|
|
data["autorun_program"] = Preferences::getAutoRunProgram();
|
* Replace priority combo boxes by check boxes in Web UI as in Regular UI
* Prepare http server and preferences classes to add new settings to Web UI
* Tabified Program preferences in Web UI since there will be a lot of settings soon
* Started to add new settings to Web UI (PeX, LSD, Encryption, save path, temp path, scan dir, preallocateall, queueing, listen_port, upnp, nat-pmp, language, ip filter) -> Proxy is missing
* Added a command line parameter to change the web ui port
* Fix PeerGuardian .p2b binary filter support
2009-12-28 22:39:47 +03:00
|
|
|
data["preallocate_all"] = Preferences::preAllocateAllFiles();
|
|
|
|
data["queueing_enabled"] = Preferences::isQueueingSystemEnabled();
|
|
|
|
data["max_active_downloads"] = Preferences::getMaxActiveDownloads();
|
|
|
|
data["max_active_torrents"] = Preferences::getMaxActiveTorrents();
|
|
|
|
data["max_active_uploads"] = Preferences::getMaxActiveUploads();
|
2010-06-07 12:32:41 +04:00
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14
|
* Replace priority combo boxes by check boxes in Web UI as in Regular UI
* Prepare http server and preferences classes to add new settings to Web UI
* Tabified Program preferences in Web UI since there will be a lot of settings soon
* Started to add new settings to Web UI (PeX, LSD, Encryption, save path, temp path, scan dir, preallocateall, queueing, listen_port, upnp, nat-pmp, language, ip filter) -> Proxy is missing
* Added a command line parameter to change the web ui port
* Fix PeerGuardian .p2b binary filter support
2009-12-28 22:39:47 +03:00
|
|
|
data["incomplete_files_ext"] = Preferences::useIncompleteFilesExtension();
|
|
|
|
#endif
|
|
|
|
// Connection
|
|
|
|
data["listen_port"] = Preferences::getSessionPort();
|
|
|
|
data["upnp"] = Preferences::isUPnPEnabled();
|
|
|
|
data["natpmp"] = Preferences::isNATPMPEnabled();
|
2009-11-26 11:10:23 +03:00
|
|
|
data["dl_limit"] = Preferences::getGlobalDownloadLimit();
|
|
|
|
data["up_limit"] = Preferences::getGlobalUploadLimit();
|
|
|
|
data["max_connec"] = Preferences::getMaxConnecs();
|
|
|
|
data["max_connec_per_torrent"] = Preferences::getMaxConnecsPerTorrent();
|
|
|
|
data["max_uploads_per_torrent"] = Preferences::getMaxUploadsPerTorrent();
|
* Replace priority combo boxes by check boxes in Web UI as in Regular UI
* Prepare http server and preferences classes to add new settings to Web UI
* Tabified Program preferences in Web UI since there will be a lot of settings soon
* Started to add new settings to Web UI (PeX, LSD, Encryption, save path, temp path, scan dir, preallocateall, queueing, listen_port, upnp, nat-pmp, language, ip filter) -> Proxy is missing
* Added a command line parameter to change the web ui port
* Fix PeerGuardian .p2b binary filter support
2009-12-28 22:39:47 +03:00
|
|
|
// Bittorrent
|
|
|
|
data["dht"] = Preferences::isDHTEnabled();
|
2010-03-22 23:34:12 +03:00
|
|
|
data["dhtSameAsBT"] = Preferences::isDHTPortSameAsBT();
|
|
|
|
data["dht_port"] = Preferences::getDHTPort();
|
* Replace priority combo boxes by check boxes in Web UI as in Regular UI
* Prepare http server and preferences classes to add new settings to Web UI
* Tabified Program preferences in Web UI since there will be a lot of settings soon
* Started to add new settings to Web UI (PeX, LSD, Encryption, save path, temp path, scan dir, preallocateall, queueing, listen_port, upnp, nat-pmp, language, ip filter) -> Proxy is missing
* Added a command line parameter to change the web ui port
* Fix PeerGuardian .p2b binary filter support
2009-12-28 22:39:47 +03:00
|
|
|
data["pex"] = Preferences::isPeXEnabled();
|
|
|
|
data["lsd"] = Preferences::isLSDEnabled();
|
|
|
|
data["encryption"] = Preferences::getEncryptionSetting();
|
|
|
|
// Proxy
|
2009-12-30 13:53:58 +03:00
|
|
|
data["proxy_type"] = Preferences::getPeerProxyType();
|
|
|
|
data["proxy_ip"] = Preferences::getPeerProxyIp();
|
|
|
|
data["proxy_port"] = Preferences::getPeerProxyPort();
|
|
|
|
data["proxy_auth_enabled"] = Preferences::isPeerProxyAuthEnabled();
|
|
|
|
data["proxy_username"] = Preferences::getPeerProxyUsername();
|
|
|
|
data["proxy_password"] = Preferences::getPeerProxyPassword();
|
|
|
|
data["http_proxy_type"] = Preferences::getHTTPProxyType();
|
|
|
|
data["http_proxy_ip"] = Preferences::getHTTPProxyIp();
|
|
|
|
data["http_proxy_port"] = Preferences::getHTTPProxyPort();
|
|
|
|
data["http_proxy_auth_enabled"] = Preferences::isHTTPProxyAuthEnabled();
|
|
|
|
data["http_proxy_username"] = Preferences::getHTTPProxyUsername();
|
|
|
|
data["http_proxy_password"] = Preferences::getHTTPProxyPassword();
|
* Replace priority combo boxes by check boxes in Web UI as in Regular UI
* Prepare http server and preferences classes to add new settings to Web UI
* Tabified Program preferences in Web UI since there will be a lot of settings soon
* Started to add new settings to Web UI (PeX, LSD, Encryption, save path, temp path, scan dir, preallocateall, queueing, listen_port, upnp, nat-pmp, language, ip filter) -> Proxy is missing
* Added a command line parameter to change the web ui port
* Fix PeerGuardian .p2b binary filter support
2009-12-28 22:39:47 +03:00
|
|
|
// IP Filter
|
|
|
|
data["ip_filter_enabled"] = Preferences::isFilteringEnabled();
|
|
|
|
data["ip_filter_path"] = Preferences::getFilter();
|
|
|
|
// Web UI
|
|
|
|
data["web_ui_port"] = Preferences::getWebUiPort();
|
|
|
|
data["web_ui_username"] = Preferences::getWebUiUsername();
|
|
|
|
data["web_ui_password"] = Preferences::getWebUiPassword();
|
2009-11-26 11:10:23 +03:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2009-11-24 11:53:14 +03:00
|
|
|
QVariantMap EventManager::getPropGeneralInfo(QString hash) const {
|
|
|
|
QVariantMap data;
|
|
|
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
2009-12-05 17:24:45 +03:00
|
|
|
if(h.is_valid() && h.has_metadata()) {
|
2009-11-24 11:53:14 +03:00
|
|
|
// Save path
|
2010-02-14 18:30:10 +03:00
|
|
|
QString p = TorrentPersistentData::getSavePath(hash);
|
|
|
|
if(p.isEmpty()) p = h.save_path();
|
|
|
|
data["save_path"] = p;
|
2009-11-24 11:53:14 +03:00
|
|
|
// Creation date
|
|
|
|
data["creation_date"] = h.creation_date();
|
|
|
|
// Comment
|
|
|
|
data["comment"] = h.comment();
|
2010-03-07 00:11:47 +03:00
|
|
|
data["total_wasted"] = QVariant(misc::friendlyUnit(h.total_failed_bytes()+h.total_redundant_bytes()));
|
|
|
|
data["total_uploaded"] = QVariant(misc::friendlyUnit(h.all_time_upload()) + " ("+misc::friendlyUnit(h.total_payload_upload())+" "+tr("this session")+")");
|
|
|
|
data["total_downloaded"] = QVariant(misc::friendlyUnit(h.all_time_download()) + " ("+misc::friendlyUnit(h.total_payload_download())+" "+tr("this session")+")");
|
2009-11-24 11:53:14 +03:00
|
|
|
if(h.upload_limit() <= 0)
|
|
|
|
data["up_limit"] = QString::fromUtf8("∞");
|
|
|
|
else
|
2010-03-07 00:11:47 +03:00
|
|
|
data["up_limit"] = QVariant(misc::friendlyUnit(h.upload_limit())+tr("/s", "/second (i.e. per second)"));
|
2009-11-24 11:53:14 +03:00
|
|
|
if(h.download_limit() <= 0)
|
|
|
|
data["dl_limit"] = QString::fromUtf8("∞");
|
|
|
|
else
|
2010-03-07 00:11:47 +03:00
|
|
|
data["dl_limit"] = QVariant(misc::friendlyUnit(h.download_limit())+tr("/s", "/second (i.e. per second)"));
|
2009-11-24 11:53:14 +03:00
|
|
|
QString elapsed_txt = misc::userFriendlyDuration(h.active_time());
|
|
|
|
if(h.is_seed()) {
|
|
|
|
elapsed_txt += " ("+tr("Seeded for %1", "e.g. Seeded for 3m10s").arg(misc::userFriendlyDuration(h.seeding_time()))+")";
|
|
|
|
}
|
|
|
|
data["time_elapsed"] = elapsed_txt;
|
2010-03-07 00:11:47 +03:00
|
|
|
data["nb_connections"] = QVariant(QString::number(h.num_connections())+" ("+tr("%1 max", "e.g. 10 max").arg(QString::number(h.connections_limit()))+")");
|
2009-11-24 11:53:14 +03:00
|
|
|
// Update ratio info
|
2009-12-01 00:30:14 +03:00
|
|
|
double ratio = BTSession->getRealRatio(h.hash());
|
* Replace priority combo boxes by check boxes in Web UI as in Regular UI
* Prepare http server and preferences classes to add new settings to Web UI
* Tabified Program preferences in Web UI since there will be a lot of settings soon
* Started to add new settings to Web UI (PeX, LSD, Encryption, save path, temp path, scan dir, preallocateall, queueing, listen_port, upnp, nat-pmp, language, ip filter) -> Proxy is missing
* Added a command line parameter to change the web ui port
* Fix PeerGuardian .p2b binary filter support
2009-12-28 22:39:47 +03:00
|
|
|
if(ratio > 100.)
|
|
|
|
data["share_ratio"] = QString::fromUtf8("∞");
|
|
|
|
else
|
|
|
|
data["share_ratio"] = QString(QByteArray::number(ratio, 'f', 1));
|
2009-11-24 11:53:14 +03:00
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2008-09-07 15:31:29 +04:00
|
|
|
void EventManager::addedTorrent(QTorrentHandle& h)
|
2008-05-17 17:23:37 +04:00
|
|
|
{
|
2009-11-19 21:28:30 +03:00
|
|
|
modifiedTorrent(h);
|
2008-12-25 16:48:23 +03:00
|
|
|
}
|
2008-09-27 23:55:56 +04:00
|
|
|
|
2008-09-28 15:30:24 +04:00
|
|
|
void EventManager::deletedTorrent(QString hash)
|
|
|
|
{
|
2009-11-19 21:28:30 +03:00
|
|
|
event_list.remove(hash);
|
2008-09-27 23:55:56 +04:00
|
|
|
}
|
|
|
|
|
2008-09-28 15:30:24 +04:00
|
|
|
void EventManager::modifiedTorrent(QTorrentHandle h)
|
|
|
|
{
|
2009-11-19 21:28:30 +03:00
|
|
|
QString hash = h.hash();
|
|
|
|
QVariantMap event;
|
2009-11-23 13:37:55 +03:00
|
|
|
event["eta"] = QVariant(QString::fromUtf8("∞"));
|
2009-11-19 21:28:30 +03:00
|
|
|
if(h.is_paused()) {
|
2010-05-24 18:19:25 +04:00
|
|
|
if(h.has_error()) {
|
|
|
|
event["state"] = QVariant("error");
|
|
|
|
} else {
|
|
|
|
if(h.is_seed())
|
|
|
|
event["state"] = QVariant("pausedUP");
|
|
|
|
else
|
|
|
|
event["state"] = QVariant("pausedDL");
|
|
|
|
}
|
2009-11-19 21:28:30 +03:00
|
|
|
} else {
|
|
|
|
if(BTSession->isQueueingEnabled() && h.is_queued()) {
|
2009-11-23 12:16:32 +03:00
|
|
|
if(h.is_seed())
|
|
|
|
event["state"] = QVariant("queuedUP");
|
|
|
|
else
|
|
|
|
event["state"] = QVariant("queuedDL");
|
2008-11-02 14:43:20 +03:00
|
|
|
} else {
|
2009-11-19 21:28:30 +03:00
|
|
|
switch(h.state())
|
|
|
|
{
|
2009-11-23 12:16:32 +03:00
|
|
|
case torrent_status::finished:
|
|
|
|
case torrent_status::seeding:
|
2009-11-23 13:37:55 +03:00
|
|
|
if(h.upload_payload_rate() > 0) {
|
2009-12-01 00:30:14 +03:00
|
|
|
event["state"] = QVariant("uploading");
|
2009-11-23 13:37:55 +03:00
|
|
|
} else {
|
2009-11-23 12:16:32 +03:00
|
|
|
event["state"] = QVariant("stalledUP");
|
2009-11-23 13:37:55 +03:00
|
|
|
}
|
2009-11-19 21:28:30 +03:00
|
|
|
break;
|
2009-11-23 12:16:32 +03:00
|
|
|
case torrent_status::allocating:
|
2009-11-19 21:28:30 +03:00
|
|
|
case torrent_status::checking_files:
|
|
|
|
case torrent_status::queued_for_checking:
|
|
|
|
case torrent_status::checking_resume_data:
|
2009-11-23 13:37:55 +03:00
|
|
|
if(h.is_seed()) {
|
2009-11-23 12:16:32 +03:00
|
|
|
event["state"] = QVariant("checkingUP");
|
2009-11-23 13:37:55 +03:00
|
|
|
} else {
|
2009-11-23 12:16:32 +03:00
|
|
|
event["state"] = QVariant("checkingDL");
|
2009-11-23 13:37:55 +03:00
|
|
|
}
|
2009-11-19 21:28:30 +03:00
|
|
|
break;
|
2009-11-23 12:16:32 +03:00
|
|
|
case torrent_status::downloading:
|
|
|
|
case torrent_status::downloading_metadata:
|
2009-11-19 21:28:30 +03:00
|
|
|
if(h.download_payload_rate() > 0)
|
|
|
|
event["state"] = QVariant("downloading");
|
|
|
|
else
|
2009-11-23 12:16:32 +03:00
|
|
|
event["state"] = QVariant("stalledDL");
|
2009-11-23 13:37:55 +03:00
|
|
|
event["eta"] = misc::userFriendlyDuration(BTSession->getETA(hash));
|
2009-11-19 21:28:30 +03:00
|
|
|
break;
|
2008-11-02 14:43:20 +03:00
|
|
|
default:
|
2009-11-19 21:28:30 +03:00
|
|
|
qDebug("No status, should not happen!!! status is %d", h.state());
|
|
|
|
event["state"] = QVariant();
|
|
|
|
}
|
2008-11-02 14:43:20 +03:00
|
|
|
}
|
2009-11-19 21:28:30 +03:00
|
|
|
}
|
|
|
|
event["name"] = QVariant(h.name());
|
2009-11-23 13:37:55 +03:00
|
|
|
event["size"] = QVariant(misc::friendlyUnit(h.actual_size()));
|
2009-12-29 23:09:46 +03:00
|
|
|
event["progress"] = QVariant((double)h.progress());
|
2009-11-23 13:37:55 +03:00
|
|
|
event["dlspeed"] = QVariant(tr("%1/s", "e.g. 120 KiB/s").arg(misc::friendlyUnit(h.download_payload_rate())));
|
2009-11-23 12:16:32 +03:00
|
|
|
if(BTSession->isQueueingEnabled()) {
|
2009-11-23 16:35:46 +03:00
|
|
|
if(h.queue_position() >= 0)
|
|
|
|
event["priority"] = QVariant(QString::number(h.queue_position()));
|
|
|
|
else
|
|
|
|
event["priority"] = "*";
|
2009-11-23 12:16:32 +03:00
|
|
|
} else {
|
2009-11-23 16:35:46 +03:00
|
|
|
event["priority"] = "*";
|
2009-11-19 21:28:30 +03:00
|
|
|
}
|
2009-11-23 13:37:55 +03:00
|
|
|
event["upspeed"] = QVariant(tr("%1/s", "e.g. 120 KiB/s").arg(misc::friendlyUnit(h.upload_payload_rate())));
|
|
|
|
QString seeds = QString::number(h.num_seeds());
|
|
|
|
if(h.num_complete() > 0)
|
|
|
|
seeds += " ("+QString::number(h.num_complete())+")";
|
|
|
|
event["num_seeds"] = QVariant(seeds);
|
|
|
|
QString leechs = QString::number(h.num_peers()-h.num_seeds());
|
|
|
|
if(h.num_incomplete() > 0)
|
|
|
|
leechs += " ("+QString::number(h.num_incomplete())+")";
|
|
|
|
event["num_leechs"] = QVariant(leechs);
|
2009-11-19 21:28:30 +03:00
|
|
|
event["seed"] = QVariant(h.is_seed());
|
2009-11-27 18:59:49 +03:00
|
|
|
double ratio = BTSession->getRealRatio(hash);
|
|
|
|
if(ratio > 100.)
|
2009-12-01 00:30:14 +03:00
|
|
|
event["ratio"] = QString::fromUtf8("∞");
|
2009-11-27 18:59:49 +03:00
|
|
|
else
|
|
|
|
event["ratio"] = QVariant(QString::number(ratio, 'f', 1));
|
2009-11-19 21:28:30 +03:00
|
|
|
event["hash"] = QVariant(hash);
|
|
|
|
event_list[hash] = event;
|
2008-05-17 17:23:37 +04:00
|
|
|
}
|