- Fix indentation

This commit is contained in:
Christophe Dumez 2009-11-04 15:07:50 +00:00
commit 92dd4c8c5b

View file

@ -241,10 +241,10 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
connect(scrapeTimer, SIGNAL(timeout()), this, SLOT(scrapeTrackers())); connect(scrapeTimer, SIGNAL(timeout()), this, SLOT(scrapeTrackers()));
scrapeTimer->start(20000); scrapeTimer->start(20000);
qDebug("GUI Built"); qDebug("GUI Built");
} }
// Destructor // Destructor
GUI::~GUI() { GUI::~GUI() {
qDebug("GUI destruction"); qDebug("GUI destruction");
hide(); hide();
// Do this as soon as possible // Do this as soon as possible
@ -294,9 +294,9 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
qDebug("4"); qDebug("4");
delete BTSession; delete BTSession;
qDebug("5"); qDebug("5");
} }
void GUI::displayRSSTab(bool enable) { void GUI::displayRSSTab(bool enable) {
if(enable) { if(enable) {
// RSS tab // RSS tab
if(rssWidget == 0) { if(rssWidget == 0) {
@ -310,9 +310,9 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
rssWidget = 0; rssWidget = 0;
} }
} }
} }
void GUI::scrapeTrackers() { void GUI::scrapeTrackers() {
std::vector<torrent_handle> torrents = BTSession->getTorrents(); std::vector<torrent_handle> torrents = BTSession->getTorrents();
std::vector<torrent_handle>::iterator torrentIT; std::vector<torrent_handle>::iterator torrentIT;
for(torrentIT = torrents.begin(); torrentIT != torrents.end(); torrentIT++) { for(torrentIT = torrents.begin(); torrentIT != torrents.end(); torrentIT++) {
@ -320,9 +320,9 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
if(!h.is_valid()) continue; if(!h.is_valid()) continue;
h.scrape_tracker(); h.scrape_tracker();
} }
} }
void GUI::updateRatio() { void GUI::updateRatio() {
// Update ratio info // Update ratio info
float ratio = 1.; float ratio = 1.;
session_status sessionStatus = BTSession->getSessionStatus(); session_status sessionStatus = BTSession->getSessionStatus();
@ -339,30 +339,30 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
ratioLbl->setText(tr("Ratio: %1").arg(QString(QByteArray::number(ratio, 'f', 1)))); ratioLbl->setText(tr("Ratio: %1").arg(QString(QByteArray::number(ratio, 'f', 1))));
// Update DHT nodes // Update DHT nodes
DHTLbl->setText(tr("DHT: %1 nodes").arg(QString::number(sessionStatus.dht_nodes))); DHTLbl->setText(tr("DHT: %1 nodes").arg(QString::number(sessionStatus.dht_nodes)));
} }
void GUI::on_actionWebsite_triggered() const { void GUI::on_actionWebsite_triggered() const {
QDesktopServices::openUrl(QUrl(QString::fromUtf8("http://www.qbittorrent.org"))); QDesktopServices::openUrl(QUrl(QString::fromUtf8("http://www.qbittorrent.org")));
} }
void GUI::on_actionDocumentation_triggered() const { void GUI::on_actionDocumentation_triggered() const {
QDesktopServices::openUrl(QUrl(QString::fromUtf8("http://wiki.qbittorrent.org"))); QDesktopServices::openUrl(QUrl(QString::fromUtf8("http://wiki.qbittorrent.org")));
} }
void GUI::on_actionBugReport_triggered() const { void GUI::on_actionBugReport_triggered() const {
QDesktopServices::openUrl(QUrl(QString::fromUtf8("http://bugs.qbittorrent.org"))); QDesktopServices::openUrl(QUrl(QString::fromUtf8("http://bugs.qbittorrent.org")));
} }
void GUI::writeSettings() { void GUI::writeSettings() {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
settings.beginGroup(QString::fromUtf8("MainWindow")); settings.beginGroup(QString::fromUtf8("MainWindow"));
settings.setValue(QString::fromUtf8("size"), size()); settings.setValue(QString::fromUtf8("size"), size());
settings.setValue(QString::fromUtf8("pos"), pos()); settings.setValue(QString::fromUtf8("pos"), pos());
settings.endGroup(); settings.endGroup();
} }
// called when a torrent has finished // called when a torrent has finished
void GUI::finishedTorrent(QTorrentHandle& h) const { void GUI::finishedTorrent(QTorrentHandle& h) const {
qDebug("In GUI, a torrent has finished"); qDebug("In GUI, a torrent has finished");
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
bool show_msg = true; bool show_msg = true;
@ -379,33 +379,33 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
if(show_msg && systrayIntegration && useNotificationBalloons) { if(show_msg && systrayIntegration && useNotificationBalloons) {
myTrayIcon->showMessage(tr("Download finished"), tr("%1 has finished downloading.", "e.g: xxx.avi has finished downloading.").arg(fileName), QSystemTrayIcon::Information, TIME_TRAY_BALLOON); myTrayIcon->showMessage(tr("Download finished"), tr("%1 has finished downloading.", "e.g: xxx.avi has finished downloading.").arg(fileName), QSystemTrayIcon::Information, TIME_TRAY_BALLOON);
} }
} }
void GUI::addedTorrent(QTorrentHandle& h) const { void GUI::addedTorrent(QTorrentHandle& h) const {
if(h.is_seed()) { if(h.is_seed()) {
finishedTorrentTab->addTorrent(h.hash()); finishedTorrentTab->addTorrent(h.hash());
} else { } else {
downloadingTorrentTab->addTorrent(h.hash()); downloadingTorrentTab->addTorrent(h.hash());
} }
} }
void GUI::pausedTorrent(QTorrentHandle& h) const { void GUI::pausedTorrent(QTorrentHandle& h) const {
if(h.is_seed()) { if(h.is_seed()) {
finishedTorrentTab->pauseTorrent(h.hash()); finishedTorrentTab->pauseTorrent(h.hash());
} else { } else {
downloadingTorrentTab->pauseTorrent(h.hash()); downloadingTorrentTab->pauseTorrent(h.hash());
} }
} }
void GUI::resumedTorrent(QTorrentHandle& h) const { void GUI::resumedTorrent(QTorrentHandle& h) const {
if(h.is_seed()) { if(h.is_seed()) {
finishedTorrentTab->updateTorrent(h); finishedTorrentTab->updateTorrent(h);
} else { } else {
downloadingTorrentTab->updateTorrent(h); downloadingTorrentTab->updateTorrent(h);
} }
} }
void GUI::checkedTorrent(QTorrentHandle& h) const { void GUI::checkedTorrent(QTorrentHandle& h) const {
if(h.is_seed()) { if(h.is_seed()) {
// Move torrent to finished tab // Move torrent to finished tab
downloadingTorrentTab->deleteTorrent(h.hash()); downloadingTorrentTab->deleteTorrent(h.hash());
@ -418,10 +418,10 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
downloadingTorrentTab->addTorrent(h.hash()); downloadingTorrentTab->addTorrent(h.hash());
} }
} }
} }
// Notification when disk is full // Notification when disk is full
void GUI::fullDiskError(QTorrentHandle& h, QString msg) const { void GUI::fullDiskError(QTorrentHandle& h, QString msg) const {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
bool useNotificationBalloons = settings.value(QString::fromUtf8("Preferences/General/NotificationBaloons"), true).toBool(); bool useNotificationBalloons = settings.value(QString::fromUtf8("Preferences/General/NotificationBaloons"), true).toBool();
if(systrayIntegration && useNotificationBalloons) { if(systrayIntegration && useNotificationBalloons) {
@ -432,9 +432,9 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
qDebug("Full disk error, pausing torrent %s", hash.toLocal8Bit().data()); qDebug("Full disk error, pausing torrent %s", hash.toLocal8Bit().data());
setPaused(h); setPaused(h);
BTSession->addConsoleMessage(tr("An error occured (full disk?), '%1' paused.", "e.g: An error occured (full disk?), 'xxx.avi' paused.").arg(h.name())); BTSession->addConsoleMessage(tr("An error occured (full disk?), '%1' paused.", "e.g: An error occured (full disk?), 'xxx.avi' paused.").arg(h.name()));
} }
void GUI::setPaused(QTorrentHandle &h) const { void GUI::setPaused(QTorrentHandle &h) const {
if(!h.is_paused()) { if(!h.is_paused()) {
// FIXME in v1.6.0: Add Error state and stop using pause for this // FIXME in v1.6.0: Add Error state and stop using pause for this
h.pause(); h.pause();
@ -447,9 +447,9 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
}else{ }else{
downloadingTorrentTab->pauseTorrent(h.hash()); downloadingTorrentTab->pauseTorrent(h.hash());
} }
} }
void GUI::createKeyboardShortcuts() { void GUI::createKeyboardShortcuts() {
actionCreate_torrent->setShortcut(QKeySequence(QString::fromUtf8("Ctrl+N"))); actionCreate_torrent->setShortcut(QKeySequence(QString::fromUtf8("Ctrl+N")));
actionOpen->setShortcut(QKeySequence(QString::fromUtf8("Ctrl+O"))); actionOpen->setShortcut(QKeySequence(QString::fromUtf8("Ctrl+O")));
actionExit->setShortcut(QKeySequence(QString::fromUtf8("Ctrl+Q"))); actionExit->setShortcut(QKeySequence(QString::fromUtf8("Ctrl+Q")));
@ -473,36 +473,36 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
actionPause_All->setShortcut(QKeySequence(QString::fromUtf8("Ctrl+Shift+P"))); actionPause_All->setShortcut(QKeySequence(QString::fromUtf8("Ctrl+Shift+P")));
actionDecreasePriority->setShortcut(QKeySequence(QString::fromUtf8("Ctrl+-"))); actionDecreasePriority->setShortcut(QKeySequence(QString::fromUtf8("Ctrl+-")));
actionIncreasePriority->setShortcut(QKeySequence(QString::fromUtf8("Ctrl++"))); actionIncreasePriority->setShortcut(QKeySequence(QString::fromUtf8("Ctrl++")));
} }
// Keyboard shortcuts slots // Keyboard shortcuts slots
void GUI::displayDownTab() const { void GUI::displayDownTab() const {
tabs->setCurrentIndex(0); tabs->setCurrentIndex(0);
} }
void GUI::displayUpTab() const { void GUI::displayUpTab() const {
tabs->setCurrentIndex(1); tabs->setCurrentIndex(1);
} }
void GUI::displaySearchTab() const { void GUI::displaySearchTab() const {
tabs->setCurrentIndex(2); tabs->setCurrentIndex(2);
} }
void GUI::displayRSSTab() const { void GUI::displayRSSTab() const {
tabs->setCurrentIndex(3); tabs->setCurrentIndex(3);
} }
// End of keyboard shortcuts slots // End of keyboard shortcuts slots
void GUI::readSettings() { void GUI::readSettings() {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
settings.beginGroup(QString::fromUtf8("MainWindow")); settings.beginGroup(QString::fromUtf8("MainWindow"));
resize(settings.value(QString::fromUtf8("size"), size()).toSize()); resize(settings.value(QString::fromUtf8("size"), size()).toSize());
move(settings.value(QString::fromUtf8("pos"), screenCenter()).toPoint()); move(settings.value(QString::fromUtf8("pos"), screenCenter()).toPoint());
settings.endGroup(); settings.endGroup();
} }
void GUI::balloonClicked() { void GUI::balloonClicked() {
if(isHidden()) { if(isHidden()) {
show(); show();
if(isMinimized()) { if(isMinimized()) {
@ -511,15 +511,15 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
raise(); raise();
activateWindow(); activateWindow();
} }
} }
void GUI::acceptConnection() { void GUI::acceptConnection() {
clientConnection = localServer->nextPendingConnection(); clientConnection = localServer->nextPendingConnection();
connect(clientConnection, SIGNAL(disconnected()), this, SLOT(readParamsOnSocket())); connect(clientConnection, SIGNAL(disconnected()), this, SLOT(readParamsOnSocket()));
qDebug("accepted connection from another instance"); qDebug("accepted connection from another instance");
} }
void GUI::readParamsOnSocket() { void GUI::readParamsOnSocket() {
if(clientConnection) { if(clientConnection) {
QByteArray params = clientConnection->readAll(); QByteArray params = clientConnection->readAll();
if(!params.isEmpty()) { if(!params.isEmpty()) {
@ -527,28 +527,28 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
qDebug("Received parameters from another instance"); qDebug("Received parameters from another instance");
} }
} }
} }
void GUI::handleDownloadFromUrlFailure(QString url, QString reason) const{ void GUI::handleDownloadFromUrlFailure(QString url, QString reason) const{
// Display a message box // Display a message box
QMessageBox::critical(0, tr("Url download error"), tr("Couldn't download file at url: %1, reason: %2.").arg(url).arg(reason)); QMessageBox::critical(0, tr("Url download error"), tr("Couldn't download file at url: %1, reason: %2.").arg(url).arg(reason));
} }
void GUI::on_actionSet_global_upload_limit_triggered() { void GUI::on_actionSet_global_upload_limit_triggered() {
qDebug("actionSet_global_upload_limit_triggered"); qDebug("actionSet_global_upload_limit_triggered");
new BandwidthAllocationDialog(this, true, BTSession, QStringList()); new BandwidthAllocationDialog(this, true, BTSession, QStringList());
} }
void GUI::on_actionShow_console_triggered() { void GUI::on_actionShow_console_triggered() {
new consoleDlg(this, BTSession); new consoleDlg(this, BTSession);
} }
void GUI::on_actionSet_global_download_limit_triggered() { void GUI::on_actionSet_global_download_limit_triggered() {
qDebug("actionSet_global_download_limit_triggered"); qDebug("actionSet_global_download_limit_triggered");
new BandwidthAllocationDialog(this, false, BTSession, QStringList()); new BandwidthAllocationDialog(this, false, BTSession, QStringList());
} }
void GUI::on_actionPreview_file_triggered() { void GUI::on_actionPreview_file_triggered() {
QString hash; QString hash;
switch(tabs->currentIndex()){ switch(tabs->currentIndex()){
case 0: case 0:
@ -562,9 +562,9 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
} }
QTorrentHandle h = BTSession->getTorrentHandle(hash); QTorrentHandle h = BTSession->getTorrentHandle(hash);
new previewSelect(this, h); new previewSelect(this, h);
} }
void GUI::openDestinationFolder() const { void GUI::openDestinationFolder() const {
QStringList hashes; QStringList hashes;
switch(tabs->currentIndex()){ switch(tabs->currentIndex()){
case 0: case 0:
@ -585,9 +585,9 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
QDesktopServices::openUrl(QString("file://")+savePath); QDesktopServices::openUrl(QString("file://")+savePath);
} }
} }
} }
void GUI::copyMagnetURI() const { void GUI::copyMagnetURI() const {
QStringList hashes; QStringList hashes;
switch(tabs->currentIndex()){ switch(tabs->currentIndex()){
case 0: case 0:
@ -607,9 +607,9 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
} }
} }
qApp->clipboard()->setText(magnet_uris.join("\n")); qApp->clipboard()->setText(magnet_uris.join("\n"));
} }
void GUI::goBuyPage() const { void GUI::goBuyPage() const {
QStringList hashes; QStringList hashes;
switch(tabs->currentIndex()){ switch(tabs->currentIndex()){
case 0: case 0:
@ -626,31 +626,31 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
QTorrentHandle h = BTSession->getTorrentHandle(hash); QTorrentHandle h = BTSession->getTorrentHandle(hash);
QDesktopServices::openUrl("http://match.sharemonkey.com/?info_hash="+hash+"&n="+h.name()+"&cid=33"); QDesktopServices::openUrl("http://match.sharemonkey.com/?info_hash="+hash+"&n="+h.name()+"&cid=33");
} }
} }
// Necessary if we want to close the window // Necessary if we want to close the window
// in one time if "close to systray" is enabled // in one time if "close to systray" is enabled
void GUI::on_actionExit_triggered() { void GUI::on_actionExit_triggered() {
force_exit = true; force_exit = true;
close(); close();
} }
void GUI::previewFile(QString filePath) { void GUI::previewFile(QString filePath) {
QDesktopServices::openUrl(QString("file://")+filePath); QDesktopServices::openUrl(QString("file://")+filePath);
} }
int GUI::getCurrentTabIndex() const{ int GUI::getCurrentTabIndex() const{
if(isMinimized() || isHidden()) if(isMinimized() || isHidden())
return -1; return -1;
return tabs->currentIndex(); return tabs->currentIndex();
} }
void GUI::setTabText(int index, QString text) const { void GUI::setTabText(int index, QString text) const {
tabs->setTabText(index, text); tabs->setTabText(index, text);
} }
// Toggle Main window visibility // Toggle Main window visibility
void GUI::toggleVisibility(QSystemTrayIcon::ActivationReason e) { void GUI::toggleVisibility(QSystemTrayIcon::ActivationReason e) {
if(e == QSystemTrayIcon::Trigger || e == QSystemTrayIcon::DoubleClick) { if(e == QSystemTrayIcon::Trigger || e == QSystemTrayIcon::DoubleClick) {
if(isHidden()) { if(isHidden()) {
show(); show();
@ -667,10 +667,10 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
hide(); hide();
} }
} }
} }
// Center window // Center window
QPoint GUI::screenCenter() const{ QPoint GUI::screenCenter() const{
int scrn = 0; int scrn = 0;
QWidget *w = this->topLevelWidget(); QWidget *w = this->topLevelWidget();
@ -683,22 +683,22 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
QRect desk(QApplication::desktop()->availableGeometry(scrn)); QRect desk(QApplication::desktop()->availableGeometry(scrn));
return QPoint((desk.width() - this->frameGeometry().width()) / 2, (desk.height() - this->frameGeometry().height()) / 2); return QPoint((desk.width() - this->frameGeometry().width()) / 2, (desk.height() - this->frameGeometry().height()) / 2);
} }
// Display About Dialog // Display About Dialog
void GUI::on_actionAbout_triggered() { void GUI::on_actionAbout_triggered() {
//About dialog //About dialog
new about(this); new about(this);
} }
void GUI::showEvent(QShowEvent *e) { void GUI::showEvent(QShowEvent *e) {
qDebug("** Show Event **"); qDebug("** Show Event **");
updateLists(true); updateLists(true);
e->accept(); e->accept();
} }
// Called when we close the program // Called when we close the program
void GUI::closeEvent(QCloseEvent *e) { void GUI::closeEvent(QCloseEvent *e) {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
bool goToSystrayOnExit = settings.value(QString::fromUtf8("Preferences/General/CloseToTray"), false).toBool(); bool goToSystrayOnExit = settings.value(QString::fromUtf8("Preferences/General/CloseToTray"), false).toBool();
@ -734,16 +734,16 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
// Accept exit // Accept exit
e->accept(); e->accept();
qApp->exit(); qApp->exit();
} }
// Display window to create a torrent // Display window to create a torrent
void GUI::on_actionCreate_torrent_triggered() { void GUI::on_actionCreate_torrent_triggered() {
createtorrent *ct = new createtorrent(this); createtorrent *ct = new createtorrent(this);
connect(ct, SIGNAL(torrent_to_seed(QString)), this, SLOT(addTorrent(QString))); connect(ct, SIGNAL(torrent_to_seed(QString)), this, SLOT(addTorrent(QString)));
} }
bool GUI::event(QEvent * e) { bool GUI::event(QEvent * e) {
if(e->type() == QEvent::WindowStateChange) { if(e->type() == QEvent::WindowStateChange) {
//Now check to see if the window is minimised //Now check to see if the window is minimised
if(isMinimized()) { if(isMinimized()) {
@ -755,10 +755,10 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
} }
} }
return QMainWindow::event(e); return QMainWindow::event(e);
} }
// Action executed when a file is dropped // Action executed when a file is dropped
void GUI::dropEvent(QDropEvent *event) { void GUI::dropEvent(QDropEvent *event) {
event->acceptProposedAction(); event->acceptProposedAction();
QStringList files; QStringList files;
if(event->mimeData()->hasUrls()) { if(event->mimeData()->hasUrls()) {
@ -793,27 +793,27 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
BTSession->addTorrent(file); BTSession->addTorrent(file);
} }
} }
} }
// Decode if we accept drag 'n drop or not // Decode if we accept drag 'n drop or not
void GUI::dragEnterEvent(QDragEnterEvent *event) { void GUI::dragEnterEvent(QDragEnterEvent *event) {
foreach(const QString &mime, event->mimeData()->formats()){ foreach(const QString &mime, event->mimeData()->formats()){
qDebug("mimeData: %s", mime.toLocal8Bit().data()); qDebug("mimeData: %s", mime.toLocal8Bit().data());
} }
if (event->mimeData()->hasFormat(QString::fromUtf8("text/plain")) || event->mimeData()->hasFormat(QString::fromUtf8("text/uri-list"))) { if (event->mimeData()->hasFormat(QString::fromUtf8("text/plain")) || event->mimeData()->hasFormat(QString::fromUtf8("text/uri-list"))) {
event->acceptProposedAction(); event->acceptProposedAction();
} }
} }
/***************************************************** /*****************************************************
* * * *
* Torrent * * Torrent *
* * * *
*****************************************************/ *****************************************************/
// Display a dialog to allow user to add // Display a dialog to allow user to add
// torrents to download list // torrents to download list
void GUI::on_actionOpen_triggered() { void GUI::on_actionOpen_triggered() {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
// Open File Open Dialog // Open File Open Dialog
// Note: it is possible to select more than one file // Note: it is possible to select more than one file
@ -836,10 +836,10 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
top_dir.removeLast(); top_dir.removeLast();
settings.setValue(QString::fromUtf8("MainWindowLastDir"), top_dir.join(QDir::separator())); settings.setValue(QString::fromUtf8("MainWindowLastDir"), top_dir.join(QDir::separator()));
} }
} }
// delete from download list AND from hard drive // delete from download list AND from hard drive
void GUI::on_actionDelete_Permanently_triggered() { void GUI::on_actionDelete_Permanently_triggered() {
QStringList hashes; QStringList hashes;
bool inDownloadList = true; bool inDownloadList = true;
switch(tabs->currentIndex()){ switch(tabs->currentIndex()){
@ -879,16 +879,16 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
// Remove the torrent // Remove the torrent
BTSession->deleteTorrent(hash, true); BTSession->deleteTorrent(hash, true);
} }
} }
void GUI::deleteTorrent(QString hash) { void GUI::deleteTorrent(QString hash) {
// Delete item from list // Delete item from list
downloadingTorrentTab->deleteTorrent(hash); downloadingTorrentTab->deleteTorrent(hash);
finishedTorrentTab->deleteTorrent(hash); finishedTorrentTab->deleteTorrent(hash);
} }
// delete selected items in the list // delete selected items in the list
void GUI::on_actionDelete_triggered() { void GUI::on_actionDelete_triggered() {
QStringList hashes; QStringList hashes;
bool inDownloadList = true; bool inDownloadList = true;
switch(tabs->currentIndex()){ switch(tabs->currentIndex()){
@ -931,13 +931,13 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
// Remove the torrent // Remove the torrent
BTSession->deleteTorrent(hash, false); BTSession->deleteTorrent(hash, false);
} }
} }
// As program parameters, we can get paths or urls. // As program parameters, we can get paths or urls.
// This function parse the parameters and call // This function parse the parameters and call
// the right addTorrent function, considering // the right addTorrent function, considering
// the parameter type. // the parameter type.
void GUI::processParams(const QStringList& params) { void GUI::processParams(const QStringList& params) {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
bool useTorrentAdditionDialog = settings.value(QString::fromUtf8("Preferences/Downloads/AdditionDialog"), true).toBool(); bool useTorrentAdditionDialog = settings.value(QString::fromUtf8("Preferences/Downloads/AdditionDialog"), true).toBool();
foreach(QString param, params) { foreach(QString param, params) {
@ -959,13 +959,13 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
} }
} }
} }
} }
void GUI::addTorrent(QString path) { void GUI::addTorrent(QString path) {
BTSession->addTorrent(path); BTSession->addTorrent(path);
} }
void GUI::processDownloadedFiles(QString path, QString url) { void GUI::processDownloadedFiles(QString path, QString url) {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
bool useTorrentAdditionDialog = settings.value(QString::fromUtf8("Preferences/Downloads/AdditionDialog"), true).toBool(); bool useTorrentAdditionDialog = settings.value(QString::fromUtf8("Preferences/Downloads/AdditionDialog"), true).toBool();
if(useTorrentAdditionDialog) { if(useTorrentAdditionDialog) {
@ -974,10 +974,10 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
}else{ }else{
BTSession->addTorrent(path, false, url); BTSession->addTorrent(path, false, url);
} }
} }
// Set BT session configuration // Set BT session configuration
void GUI::configureSession(bool deleteOptions) { void GUI::configureSession(bool deleteOptions) {
qDebug("Configuring session"); qDebug("Configuring session");
// General // General
bool new_displaySpeedInTitle = options->speedInTitleBar(); bool new_displaySpeedInTitle = options->speedInTitleBar();
@ -1245,20 +1245,20 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
options->deleteLater(); options->deleteLater();
} }
qDebug("Session configured"); qDebug("Session configured");
} }
void GUI::updateUnfinishedTorrentNumber(unsigned int nb) { void GUI::updateUnfinishedTorrentNumber(unsigned int nb) {
unsigned int paused = BTSession->getUnfinishedPausedTorrentsNb(); unsigned int paused = BTSession->getUnfinishedPausedTorrentsNb();
tabs->setTabText(0, tr("Downloads") +QString::fromUtf8(" (")+misc::toQString(nb-paused)+"/"+misc::toQString(nb)+QString::fromUtf8(")")); tabs->setTabText(0, tr("Downloads") +QString::fromUtf8(" (")+misc::toQString(nb-paused)+"/"+misc::toQString(nb)+QString::fromUtf8(")"));
} }
void GUI::updateFinishedTorrentNumber(unsigned int nb) { void GUI::updateFinishedTorrentNumber(unsigned int nb) {
unsigned int paused = BTSession->getFinishedPausedTorrentsNb(); unsigned int paused = BTSession->getFinishedPausedTorrentsNb();
tabs->setTabText(1, tr("Finished") +QString::fromUtf8(" (")+misc::toQString(nb-paused)+"/"+misc::toQString(nb)+QString::fromUtf8(")")); tabs->setTabText(1, tr("Finished") +QString::fromUtf8(" (")+misc::toQString(nb-paused)+"/"+misc::toQString(nb)+QString::fromUtf8(")"));
} }
// Allow to change action on double-click // Allow to change action on double-click
void GUI::torrentDoubleClicked(QString hash, bool finished) { void GUI::torrentDoubleClicked(QString hash, bool finished) {
int action; int action;
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
QTorrentHandle h = BTSession->getTorrentHandle(hash); QTorrentHandle h = BTSession->getTorrentHandle(hash);
@ -1287,10 +1287,10 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
} }
break; break;
} }
} }
// Toggle paused state of selected torrent // Toggle paused state of selected torrent
void GUI::togglePausedState(QString hash) { void GUI::togglePausedState(QString hash) {
if(tabs->currentIndex() > 1) return; if(tabs->currentIndex() > 1) return;
bool inDownloadList = true; bool inDownloadList = true;
if(tabs->currentIndex() == 1) if(tabs->currentIndex() == 1)
@ -1313,10 +1313,10 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
updateFinishedTorrentNumber(finishedTorrentTab->getNbTorrentsInList()); updateFinishedTorrentNumber(finishedTorrentTab->getNbTorrentsInList());
} }
} }
} }
// Pause All Downloads in DL list // Pause All Downloads in DL list
void GUI::on_actionPause_All_triggered() { void GUI::on_actionPause_All_triggered() {
bool change = false; bool change = false;
std::vector<torrent_handle> torrents = BTSession->getTorrents(); std::vector<torrent_handle> torrents = BTSession->getTorrents();
std::vector<torrent_handle>::iterator torrentIT; std::vector<torrent_handle>::iterator torrentIT;
@ -1331,9 +1331,9 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
updateUnfinishedTorrentNumber(downloadingTorrentTab->getNbTorrentsInList()); updateUnfinishedTorrentNumber(downloadingTorrentTab->getNbTorrentsInList());
updateFinishedTorrentNumber(finishedTorrentTab->getNbTorrentsInList()); updateFinishedTorrentNumber(finishedTorrentTab->getNbTorrentsInList());
} }
} }
void GUI::on_actionIncreasePriority_triggered() { void GUI::on_actionIncreasePriority_triggered() {
if(tabs->currentIndex() != 0) if(tabs->currentIndex() != 0)
return; return;
QStringList hashes = downloadingTorrentTab->getSelectedTorrents(); QStringList hashes = downloadingTorrentTab->getSelectedTorrents();
@ -1341,19 +1341,19 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
BTSession->increaseDlTorrentPriority(hash); BTSession->increaseDlTorrentPriority(hash);
} }
updateLists(); updateLists();
} }
void GUI::on_actionDecreasePriority_triggered() { void GUI::on_actionDecreasePriority_triggered() {
Q_ASSERT(tabs->currentIndex() == 0); Q_ASSERT(tabs->currentIndex() == 0);
QStringList hashes = downloadingTorrentTab->getSelectedTorrents(); QStringList hashes = downloadingTorrentTab->getSelectedTorrents();
foreach(const QString &hash, hashes) { foreach(const QString &hash, hashes) {
BTSession->decreaseDlTorrentPriority(hash); BTSession->decreaseDlTorrentPriority(hash);
} }
updateLists(); updateLists();
} }
// pause selected items in the list // pause selected items in the list
void GUI::on_actionPause_triggered() { void GUI::on_actionPause_triggered() {
bool inDownloadList = true; bool inDownloadList = true;
if(tabs->currentIndex() > 1) return; if(tabs->currentIndex() > 1) return;
if(tabs->currentIndex() == 1) if(tabs->currentIndex() == 1)
@ -1377,10 +1377,10 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
} }
} }
} }
} }
// Resume All Downloads in DL list // Resume All Downloads in DL list
void GUI::on_actionStart_All_triggered() { void GUI::on_actionStart_All_triggered() {
bool change = false; bool change = false;
std::vector<torrent_handle> torrents = BTSession->getTorrents(); std::vector<torrent_handle> torrents = BTSession->getTorrents();
std::vector<torrent_handle>::iterator torrentIT; std::vector<torrent_handle>::iterator torrentIT;
@ -1395,10 +1395,10 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
updateUnfinishedTorrentNumber(downloadingTorrentTab->getNbTorrentsInList()); updateUnfinishedTorrentNumber(downloadingTorrentTab->getNbTorrentsInList());
updateFinishedTorrentNumber(finishedTorrentTab->getNbTorrentsInList()); updateFinishedTorrentNumber(finishedTorrentTab->getNbTorrentsInList());
} }
} }
// start selected items in the list // start selected items in the list
void GUI::on_actionStart_triggered() { void GUI::on_actionStart_triggered() {
bool inDownloadList = true; bool inDownloadList = true;
if(tabs->currentIndex() > 1) return; if(tabs->currentIndex() > 1) return;
if(tabs->currentIndex() == 1) if(tabs->currentIndex() == 1)
@ -1421,17 +1421,17 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
} }
} }
} }
} }
void GUI::addUnauthenticatedTracker(QPair<QTorrentHandle,QString> tracker) { void GUI::addUnauthenticatedTracker(QPair<QTorrentHandle,QString> tracker) {
// Trackers whose authentication was cancelled // Trackers whose authentication was cancelled
if(unauthenticated_trackers.indexOf(tracker) < 0) { if(unauthenticated_trackers.indexOf(tracker) < 0) {
unauthenticated_trackers << tracker; unauthenticated_trackers << tracker;
} }
} }
// display properties of selected items // display properties of selected items
void GUI::on_actionTorrent_Properties_triggered() { void GUI::on_actionTorrent_Properties_triggered() {
if(tabs->currentIndex() > 1) return; if(tabs->currentIndex() > 1) return;
switch(tabs->currentIndex()){ switch(tabs->currentIndex()){
case 1: // DL List case 1: // DL List
@ -1440,9 +1440,9 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
default: default:
downloadingTorrentTab->propertiesSelection(); downloadingTorrentTab->propertiesSelection();
} }
} }
void GUI::updateLists(bool force) { void GUI::updateLists(bool force) {
if(isVisible() || force) { if(isVisible() || force) {
// update global informations // update global informations
dlSpeedLbl->setText(tr("DL: %1 KiB/s").arg(QString(QByteArray::number(BTSession->getPayloadDownloadRate()/1024., 'f', 1)))); dlSpeedLbl->setText(tr("DL: %1 KiB/s").arg(QString(QByteArray::number(BTSession->getPayloadDownloadRate()/1024., 'f', 1))));
@ -1474,18 +1474,18 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
QString up_rate = QByteArray::number(BTSession->getSessionStatus().payload_upload_rate/1024, 'f', 1); QString up_rate = QByteArray::number(BTSession->getSessionStatus().payload_upload_rate/1024, 'f', 1);
setWindowTitle(tr("qBittorrent %1 (DL: %2KiB/s, UP: %3KiB/s)", "%1 is qBittorrent version").arg(QString::fromUtf8(VERSION)).arg(dl_rate).arg(up_rate)); setWindowTitle(tr("qBittorrent %1 (DL: %2KiB/s, UP: %3KiB/s)", "%1 is qBittorrent version").arg(QString::fromUtf8(VERSION)).arg(dl_rate).arg(up_rate));
} }
} }
// Called when a tracker requires authentication // Called when a tracker requires authentication
void GUI::trackerAuthenticationRequired(QTorrentHandle& h) { void GUI::trackerAuthenticationRequired(QTorrentHandle& h) {
if(unauthenticated_trackers.indexOf(QPair<QTorrentHandle,QString>(h, h.current_tracker())) < 0) { if(unauthenticated_trackers.indexOf(QPair<QTorrentHandle,QString>(h, h.current_tracker())) < 0) {
// Tracker login // Tracker login
new trackerLogin(this, h); new trackerLogin(this, h);
} }
} }
// Check connection status and display right icon // Check connection status and display right icon
void GUI::checkConnectionStatus() { void GUI::checkConnectionStatus() {
// qDebug("Checking connection status"); // qDebug("Checking connection status");
// Update Ratio // Update Ratio
updateRatio(); updateRatio();
@ -1518,15 +1518,15 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
connecStatusLblIcon->setPixmap(QPixmap(QString::fromUtf8(":/Icons/skin/firewalled.png"))); connecStatusLblIcon->setPixmap(QPixmap(QString::fromUtf8(":/Icons/skin/firewalled.png")));
connecStatusLblIcon->setToolTip(QString::fromUtf8("<b>")+tr("Connection status:")+QString::fromUtf8("</b><br>")+QString::fromUtf8("<i>")+tr("No direct connections. This may indicate network configuration problems.")+QString::fromUtf8("</i>")); connecStatusLblIcon->setToolTip(QString::fromUtf8("<b>")+tr("Connection status:")+QString::fromUtf8("</b><br>")+QString::fromUtf8("<i>")+tr("No direct connections. This may indicate network configuration problems.")+QString::fromUtf8("</i>"));
} }
} }
/***************************************************** /*****************************************************
* * * *
* Utils * * Utils *
* * * *
*****************************************************/ *****************************************************/
void GUI::downloadFromURLList(const QStringList& url_list) { void GUI::downloadFromURLList(const QStringList& url_list) {
foreach(const QString url, url_list) { foreach(const QString url, url_list) {
if(url.startsWith("magnet:", Qt::CaseInsensitive)) { if(url.startsWith("magnet:", Qt::CaseInsensitive)) {
BTSession->addMagnetUri(url); BTSession->addMagnetUri(url);
@ -1534,15 +1534,15 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
BTSession->downloadFromUrl(url); BTSession->downloadFromUrl(url);
} }
} }
} }
/***************************************************** /*****************************************************
* * * *
* Options * * Options *
* * * *
*****************************************************/ *****************************************************/
void GUI::createSystrayDelayed() { void GUI::createSystrayDelayed() {
static int timeout = 10; static int timeout = 10;
if(QSystemTrayIcon::isSystemTrayAvailable()) { if(QSystemTrayIcon::isSystemTrayAvailable()) {
// Ok, systray integration is now supported // Ok, systray integration is now supported
@ -1561,9 +1561,9 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
delete systrayCreator; delete systrayCreator;
} }
} }
} }
void GUI::createTrayIcon() { void GUI::createTrayIcon() {
// Tray icon // Tray icon
#ifdef Q_WS_WIN #ifdef Q_WS_WIN
myTrayIcon = new QSystemTrayIcon(QIcon(QString::fromUtf8(":/Icons/skin/qbittorrent16.png")), this); myTrayIcon = new QSystemTrayIcon(QIcon(QString::fromUtf8(":/Icons/skin/qbittorrent16.png")), this);
@ -1588,17 +1588,17 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
// End of Icon Menu // End of Icon Menu
connect(myTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(toggleVisibility(QSystemTrayIcon::ActivationReason))); connect(myTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(toggleVisibility(QSystemTrayIcon::ActivationReason)));
myTrayIcon->show(); myTrayIcon->show();
} }
// Display Program Options // Display Program Options
void GUI::on_actionOptions_triggered() { void GUI::on_actionOptions_triggered() {
options = new options_imp(this); options = new options_imp(this);
connect(options, SIGNAL(status_changed(bool)), this, SLOT(OptionsSaved(bool))); connect(options, SIGNAL(status_changed(bool)), this, SLOT(OptionsSaved(bool)));
options->show(); options->show();
} }
// Is executed each time options are saved // Is executed each time options are saved
void GUI::OptionsSaved(bool deleteOptions) { void GUI::OptionsSaved(bool deleteOptions) {
BTSession->addConsoleMessage(tr("Options were saved successfully.")); BTSession->addConsoleMessage(tr("Options were saved successfully."));
bool newSystrayIntegration = options->systrayIntegration(); bool newSystrayIntegration = options->systrayIntegration();
if(newSystrayIntegration != systrayIntegration) { if(newSystrayIntegration != systrayIntegration) {
@ -1623,9 +1623,9 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
} }
// Update session // Update session
configureSession(deleteOptions); configureSession(deleteOptions);
} }
bool GUI::initWebUi(QString username, QString password, int port) { bool GUI::initWebUi(QString username, QString password, int port) {
if(httpServer) if(httpServer)
httpServer->close(); httpServer->close();
else else
@ -1637,18 +1637,18 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
else else
QMessageBox::critical(this, "Web User Interface Error", "Unable to initialize HTTP Server on port " + misc::toQString(port)); QMessageBox::critical(this, "Web User Interface Error", "Unable to initialize HTTP Server on port " + misc::toQString(port));
return success; return success;
} }
/***************************************************** /*****************************************************
* * * *
* HTTP Downloader * * HTTP Downloader *
* * * *
*****************************************************/ *****************************************************/
// Display an input dialog to prompt user for // Display an input dialog to prompt user for
// an url // an url
void GUI::on_actionDownload_from_URL_triggered() { void GUI::on_actionDownload_from_URL_triggered() {
downloadFromURL *downloadFromURLDialog = new downloadFromURL(this); downloadFromURL *downloadFromURLDialog = new downloadFromURL(this);
connect(downloadFromURLDialog, SIGNAL(urlsReadyToBeDownloaded(const QStringList&)), BTSession, SLOT(downloadFromURLList(const QStringList&))); connect(downloadFromURLDialog, SIGNAL(urlsReadyToBeDownloaded(const QStringList&)), BTSession, SLOT(downloadFromURLList(const QStringList&)));
} }