2009-04-09 18:55:47 +00:00
|
|
|
/*
|
2014-01-19 01:09:44 +00:00
|
|
|
* This file Copyright (C) 2009-2014 Mnemosyne LLC
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
2014-12-21 23:49:39 +00:00
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
2009-05-31 19:33:48 +00:00
|
|
|
* $Id$
|
2009-04-09 18:55:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <cassert>
|
2013-08-24 17:53:45 +00:00
|
|
|
#include <climits> /* INT_MAX */
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QComboBox>
|
2009-10-06 00:27:26 +00:00
|
|
|
#include <QCoreApplication>
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QDoubleSpinBox>
|
2009-10-06 00:27:26 +00:00
|
|
|
#include <QFileIconProvider>
|
|
|
|
#include <QFileInfo>
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <QHBoxLayout>
|
2009-10-06 00:27:26 +00:00
|
|
|
#include <QIcon>
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <QLabel>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QList>
|
2009-10-06 00:27:26 +00:00
|
|
|
#include <QMessageBox>
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <QPushButton>
|
|
|
|
#include <QSpinBox>
|
|
|
|
#include <QStyle>
|
|
|
|
#include <QTabWidget>
|
|
|
|
#include <QTime>
|
|
|
|
#include <QTimeEdit>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
2013-02-09 04:05:03 +00:00
|
|
|
#include "freespace-label.h"
|
2010-07-03 01:10:36 +00:00
|
|
|
#include "formatter.h"
|
2009-04-09 18:55:47 +00:00
|
|
|
#include "hig.h"
|
|
|
|
#include "prefs.h"
|
|
|
|
#include "prefs-dialog.h"
|
|
|
|
#include "session.h"
|
2010-06-04 01:00:27 +00:00
|
|
|
#include "utils.h"
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
const char * PREF_KEY ("pref-key");
|
2009-04-09 18:55:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
PrefsDialog::checkBoxToggled (bool checked)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
const int key (sender ()->property (PREF_KEY).toInt ());
|
|
|
|
setPref (key, checked);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QCheckBox *
|
2014-12-12 23:05:10 +00:00
|
|
|
PrefsDialog::checkBoxNew (const QString& text, int key)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
QCheckBox * box = new QCheckBox (text);
|
|
|
|
box->setChecked (myPrefs.getBool (key));
|
|
|
|
box->setProperty (PREF_KEY, key);
|
|
|
|
connect (box, SIGNAL(toggled(bool)), this, SLOT(checkBoxToggled(bool)));
|
|
|
|
myWidgets.insert (key, box);
|
|
|
|
return box;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
PrefsDialog::enableBuddyWhenChecked (QCheckBox * box, QWidget * buddy)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
connect (box, SIGNAL(toggled(bool)), buddy, SLOT(setEnabled(bool)));
|
|
|
|
buddy->setEnabled (box->isChecked ());
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
PrefsDialog::spinBoxEditingFinished ()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
const QObject * spin = sender();
|
|
|
|
const int key = spin->property (PREF_KEY).toInt ();
|
|
|
|
const QDoubleSpinBox * d = qobject_cast<const QDoubleSpinBox*> (spin);
|
|
|
|
|
|
|
|
if (d)
|
|
|
|
setPref (key, d->value ());
|
|
|
|
else
|
|
|
|
setPref (key, qobject_cast<const QSpinBox*>(spin)->value ());
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QSpinBox *
|
2014-12-12 23:05:10 +00:00
|
|
|
PrefsDialog::spinBoxNew (int key, int low, int high, int step)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
QSpinBox * spin = new QSpinBox ();
|
|
|
|
spin->setRange (low, high);
|
|
|
|
spin->setSingleStep (step);
|
|
|
|
spin->setValue (myPrefs.getInt (key));
|
|
|
|
spin->setProperty (PREF_KEY, key);
|
|
|
|
connect (spin, SIGNAL(editingFinished()), this, SLOT(spinBoxEditingFinished()));
|
|
|
|
myWidgets.insert (key, spin);
|
|
|
|
return spin;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QDoubleSpinBox *
|
2014-12-12 23:05:10 +00:00
|
|
|
PrefsDialog::doubleSpinBoxNew (int key, double low, double high, double step, int decimals)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
QDoubleSpinBox * spin = new QDoubleSpinBox ();
|
|
|
|
spin->setRange (low, high);
|
|
|
|
spin->setSingleStep (step);
|
|
|
|
spin->setDecimals (decimals);
|
|
|
|
spin->setValue (myPrefs.getDouble (key));
|
|
|
|
spin->setProperty (PREF_KEY, key);
|
|
|
|
connect (spin, SIGNAL(editingFinished()), this, SLOT(spinBoxEditingFinished()));
|
|
|
|
myWidgets.insert (key, spin);
|
|
|
|
return spin;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-08-26 23:26:00 +00:00
|
|
|
PrefsDialog::timeEditingFinished()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2014-08-26 23:26:00 +00:00
|
|
|
auto e = qobject_cast<QTimeEdit*>(sender());
|
|
|
|
if (e != nullptr)
|
2010-12-04 00:19:52 +00:00
|
|
|
{
|
2014-08-26 23:26:00 +00:00
|
|
|
const int key {e->property(PREF_KEY).toInt()};
|
|
|
|
const QTime t {e->time()};
|
|
|
|
const int minutes_after_midnight {t.hour()*60 + t.minute()};
|
|
|
|
setPref(key, minutes_after_midnight);
|
2010-12-04 00:19:52 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2013-09-14 22:45:04 +00:00
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
QTimeEdit*
|
2014-08-26 23:26:00 +00:00
|
|
|
PrefsDialog::timeEditNew (int key)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2014-08-26 23:26:00 +00:00
|
|
|
const int minutes {myPrefs.getInt(key)};
|
|
|
|
auto e = new QTimeEdit{};
|
|
|
|
e->setDisplayFormat(QString::fromUtf8("hh:mm"));
|
|
|
|
e->setProperty(PREF_KEY, key);
|
|
|
|
e->setTime(QTime{minutes/60, minutes%60});
|
|
|
|
myWidgets.insert(key, e);
|
|
|
|
connect(e, SIGNAL(editingFinished()), this, SLOT(timeEditingFinished()));
|
2013-09-14 22:45:04 +00:00
|
|
|
return e;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
PrefsDialog::lineEditingFinished ()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
QLineEdit * e = qobject_cast<QLineEdit*>(sender());
|
|
|
|
if (e && e->isModified ())
|
2010-12-04 00:19:52 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
const int key (e->property (PREF_KEY).toInt ());
|
|
|
|
const QString text (e->text());
|
|
|
|
setPref (key, text);
|
2010-12-04 00:19:52 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2013-09-14 22:45:04 +00:00
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
QLineEdit*
|
2014-12-12 23:05:10 +00:00
|
|
|
PrefsDialog::lineEditNew (int key, int echoMode)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
QLineEdit * e = new QLineEdit (myPrefs.getString (key));
|
|
|
|
e->setProperty (PREF_KEY, key);
|
|
|
|
e->setEchoMode (QLineEdit::EchoMode (echoMode));
|
|
|
|
myWidgets.insert (key, e);
|
|
|
|
connect (e, SIGNAL(editingFinished()), this, SLOT(lineEditingFinished()));
|
|
|
|
return e;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
QWidget *
|
2014-12-12 23:05:10 +00:00
|
|
|
PrefsDialog::createRemoteTab (Session& session)
|
2013-09-14 22:45:04 +00:00
|
|
|
{
|
|
|
|
HIG * hig = new HIG (this);
|
|
|
|
hig->addSectionTitle (tr ("Remote Control"));
|
|
|
|
QWidget * w;
|
|
|
|
QHBoxLayout * h = new QHBoxLayout ();
|
|
|
|
QPushButton * b = new QPushButton (tr ("&Open web client"));
|
|
|
|
connect (b, SIGNAL(clicked()), &session, SLOT(launchWebInterface()));
|
|
|
|
h->addWidget (b, 0, Qt::AlignRight);
|
|
|
|
QWidget * l = checkBoxNew (tr ("Allow &remote access"), Prefs::RPC_ENABLED);
|
|
|
|
myUnsupportedWhenRemote << l;
|
|
|
|
hig->addRow (l, h, 0);
|
|
|
|
l = hig->addRow (tr ("HTTP &port:"), w = spinBoxNew (Prefs::RPC_PORT, 0, 65535, 1));
|
|
|
|
myWebWidgets << l << w;
|
|
|
|
hig->addWideControl (w = checkBoxNew (tr ("Use &authentication"), Prefs::RPC_AUTH_REQUIRED));
|
|
|
|
myWebWidgets << w;
|
|
|
|
l = hig->addRow (tr ("&Username:"), w = lineEditNew (Prefs::RPC_USERNAME));
|
|
|
|
myWebAuthWidgets << l << w;
|
|
|
|
l = hig->addRow (tr ("Pass&word:"), w = lineEditNew (Prefs::RPC_PASSWORD, QLineEdit::Password));
|
|
|
|
myWebAuthWidgets << l << w;
|
|
|
|
hig->addWideControl (w = checkBoxNew (tr ("Only allow these IP a&ddresses:"), Prefs::RPC_WHITELIST_ENABLED));
|
|
|
|
myWebWidgets << w;
|
|
|
|
l = hig->addRow (tr ("Addresses:"), w = lineEditNew (Prefs::RPC_WHITELIST));
|
|
|
|
myWebWhitelistWidgets << l << w;
|
|
|
|
myUnsupportedWhenRemote << myWebWidgets << myWebAuthWidgets << myWebWhitelistWidgets;
|
|
|
|
hig->finish ();
|
|
|
|
return hig;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
PrefsDialog::altSpeedDaysEdited (int i)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
const int value = qobject_cast<QComboBox*>(sender())->itemData(i).toInt();
|
|
|
|
setPref (Prefs::ALT_SPEED_LIMIT_TIME_DAY, value);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QWidget *
|
2014-12-12 23:05:10 +00:00
|
|
|
PrefsDialog::createSpeedTab ()
|
2013-09-14 22:45:04 +00:00
|
|
|
{
|
2014-12-22 03:06:09 +00:00
|
|
|
QWidget * l;
|
|
|
|
QSpinBox * r;
|
2013-09-14 22:45:04 +00:00
|
|
|
HIG * hig = new HIG (this);
|
|
|
|
hig->addSectionTitle (tr ("Speed Limits"));
|
|
|
|
const QString speed_K_str = Formatter::unitStr (Formatter::SPEED, Formatter::KB);
|
|
|
|
|
2014-12-22 03:06:09 +00:00
|
|
|
l = checkBoxNew (tr ("&Upload:"), Prefs::USPEED_ENABLED);
|
2013-09-14 22:45:04 +00:00
|
|
|
r = spinBoxNew (Prefs::USPEED, 0, INT_MAX, 5);
|
2014-12-22 03:06:09 +00:00
|
|
|
r->setSuffix (QString::fromLatin1 (" %1").arg (speed_K_str));
|
2013-09-14 22:45:04 +00:00
|
|
|
hig->addRow (l, r);
|
|
|
|
enableBuddyWhenChecked (qobject_cast<QCheckBox*>(l), r);
|
|
|
|
|
2014-12-22 03:06:09 +00:00
|
|
|
l = checkBoxNew (tr ("&Download:"), Prefs::DSPEED_ENABLED);
|
2013-09-14 22:45:04 +00:00
|
|
|
r = spinBoxNew (Prefs::DSPEED, 0, INT_MAX, 5);
|
2014-12-22 03:06:09 +00:00
|
|
|
r->setSuffix (QString::fromLatin1 (" %1").arg (speed_K_str));
|
2013-09-14 22:45:04 +00:00
|
|
|
hig->addRow (l, r);
|
|
|
|
enableBuddyWhenChecked (qobject_cast<QCheckBox*>(l), r);
|
|
|
|
|
|
|
|
hig->addSectionDivider ();
|
|
|
|
QHBoxLayout * h = new QHBoxLayout;
|
2014-12-12 23:05:10 +00:00
|
|
|
h->setSpacing (HIG::PAD);
|
2013-09-14 22:45:04 +00:00
|
|
|
QLabel * label = new QLabel;
|
|
|
|
label->setPixmap (QPixmap (QString::fromUtf8 (":/icons/alt-limit-off.png")));
|
|
|
|
label->setAlignment (Qt::AlignLeft|Qt::AlignVCenter);
|
|
|
|
h->addWidget (label);
|
|
|
|
label = new QLabel (tr ("Alternative Speed Limits"));
|
|
|
|
label->setStyleSheet (QString::fromUtf8 ("font: bold"));
|
|
|
|
label->setAlignment (Qt::AlignLeft|Qt::AlignVCenter);
|
|
|
|
h->addWidget (label);
|
|
|
|
hig->addSectionTitle (h);
|
|
|
|
|
|
|
|
QString s = tr ("<small>Override normal speed limits manually or at scheduled times</small>");
|
|
|
|
hig->addWideControl (new QLabel (s));
|
|
|
|
|
2014-12-22 03:06:09 +00:00
|
|
|
s = tr ("U&pload:");
|
2014-12-12 23:05:10 +00:00
|
|
|
r = spinBoxNew (Prefs::ALT_SPEED_LIMIT_UP, 0, INT_MAX, 5);
|
2014-12-22 03:06:09 +00:00
|
|
|
r->setSuffix (QString::fromLatin1 (" %1").arg (speed_K_str));
|
2013-09-14 22:45:04 +00:00
|
|
|
hig->addRow (s, r);
|
|
|
|
|
2014-12-22 03:06:09 +00:00
|
|
|
s = tr ("Do&wnload:");
|
2014-12-12 23:05:10 +00:00
|
|
|
r = spinBoxNew (Prefs::ALT_SPEED_LIMIT_DOWN, 0, INT_MAX, 5);
|
2014-12-22 03:06:09 +00:00
|
|
|
r->setSuffix (QString::fromLatin1 (" %1").arg (speed_K_str));
|
2013-09-14 22:45:04 +00:00
|
|
|
hig->addRow (s, r);
|
|
|
|
|
|
|
|
QCheckBox * c = checkBoxNew (tr ("&Scheduled times:"), Prefs::ALT_SPEED_LIMIT_TIME_ENABLED);
|
|
|
|
h = new QHBoxLayout ();
|
|
|
|
h->setSpacing (HIG::PAD);
|
2014-12-12 23:05:10 +00:00
|
|
|
QWidget * w = timeEditNew (Prefs::ALT_SPEED_LIMIT_TIME_BEGIN);
|
2013-09-14 22:45:04 +00:00
|
|
|
h->addWidget (w, 1);
|
|
|
|
mySchedWidgets << w;
|
|
|
|
QLabel * nd = new QLabel (tr("&to"));
|
|
|
|
h->addWidget (nd);
|
|
|
|
mySchedWidgets << nd;
|
2014-12-12 23:05:10 +00:00
|
|
|
w = timeEditNew (Prefs::ALT_SPEED_LIMIT_TIME_END);
|
2013-09-14 22:45:04 +00:00
|
|
|
nd->setBuddy (w);
|
|
|
|
h->addWidget (w, 1);
|
|
|
|
mySchedWidgets << w;
|
|
|
|
hig->addRow (c, h, 0);
|
|
|
|
|
|
|
|
s = tr ("&On days:");
|
|
|
|
QComboBox * box = new QComboBox;
|
|
|
|
const QIcon noIcon;
|
|
|
|
box->addItem (noIcon, tr ("Every Day"), QVariant (TR_SCHED_ALL));
|
|
|
|
box->addItem (noIcon, tr ("Weekdays"), QVariant (TR_SCHED_WEEKDAY));
|
|
|
|
box->addItem (noIcon, tr ("Weekends"), QVariant (TR_SCHED_WEEKEND));
|
|
|
|
box->addItem (noIcon, tr ("Sunday"), QVariant (TR_SCHED_SUN));
|
|
|
|
box->addItem (noIcon, tr ("Monday"), QVariant (TR_SCHED_MON));
|
|
|
|
box->addItem (noIcon, tr ("Tuesday"), QVariant (TR_SCHED_TUES));
|
|
|
|
box->addItem (noIcon, tr ("Wednesday"), QVariant (TR_SCHED_WED));
|
|
|
|
box->addItem (noIcon, tr ("Thursday"), QVariant (TR_SCHED_THURS));
|
|
|
|
box->addItem (noIcon, tr ("Friday"), QVariant (TR_SCHED_FRI));
|
|
|
|
box->addItem (noIcon, tr ("Saturday"), QVariant (TR_SCHED_SAT));
|
2014-12-12 23:05:10 +00:00
|
|
|
box->setCurrentIndex (box->findData (myPrefs.getInt (Prefs::ALT_SPEED_LIMIT_TIME_DAY)));
|
2013-09-14 22:45:04 +00:00
|
|
|
connect (box, SIGNAL(activated(int)), this, SLOT(altSpeedDaysEdited(int)));
|
|
|
|
w = hig->addRow (s, box);
|
|
|
|
mySchedWidgets << w << box;
|
|
|
|
|
|
|
|
hig->finish ();
|
|
|
|
return hig;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2010-08-02 03:07:42 +00:00
|
|
|
QWidget *
|
2014-12-12 23:05:10 +00:00
|
|
|
PrefsDialog::createDesktopTab ()
|
2010-08-02 03:07:42 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
HIG * hig = new HIG (this);
|
|
|
|
hig->addSectionTitle (tr ("Desktop"));
|
2010-08-02 03:07:42 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
hig->addWideControl (checkBoxNew (tr ("Show Transmission icon in the ¬ification area"), Prefs::SHOW_TRAY_ICON));
|
|
|
|
hig->addWideControl (checkBoxNew (tr ("Start &minimized in notification area"), Prefs::START_MINIMIZED));
|
2013-01-20 23:57:09 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
hig->addSectionDivider ();
|
|
|
|
hig->addSectionTitle (tr ("Notification"));
|
2013-01-20 23:57:09 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
hig->addWideControl (checkBoxNew (tr ("Show a notification when torrents are a&dded"), Prefs::SHOW_NOTIFICATION_ON_ADD));
|
|
|
|
hig->addWideControl (checkBoxNew (tr ("Show a notification when torrents &finish"), Prefs::SHOW_NOTIFICATION_ON_COMPLETE));
|
|
|
|
hig->addWideControl (checkBoxNew (tr ("Play a &sound when torrents finish"), Prefs::COMPLETE_SOUND_ENABLED));
|
2010-08-02 03:07:42 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
hig->finish ();
|
|
|
|
return hig;
|
2010-08-02 03:07:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
PrefsDialog::onPortTested (bool isOpen)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
myPortButton->setEnabled (true);
|
|
|
|
myWidgets[Prefs::PEER_PORT]->setEnabled (true);
|
|
|
|
myPortLabel->setText (isOpen ? tr ("Port is <b>open</b>")
|
|
|
|
: tr ("Port is <b>closed</b>"));
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
PrefsDialog::onPortTest ()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
myPortLabel->setText (tr ("Testing TCP Port..."));
|
|
|
|
myPortButton->setEnabled (false);
|
|
|
|
myWidgets[Prefs::PEER_PORT]->setEnabled (false);
|
|
|
|
mySession.portTest ();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QWidget *
|
2014-12-12 23:05:10 +00:00
|
|
|
PrefsDialog::createNetworkTab ()
|
2013-09-14 22:45:04 +00:00
|
|
|
{
|
|
|
|
HIG * hig = new HIG (this);
|
|
|
|
hig->addSectionTitle (tr ("Incoming Peers"));
|
|
|
|
|
|
|
|
QSpinBox * s = spinBoxNew (Prefs::PEER_PORT, 1, 65535, 1);
|
|
|
|
QHBoxLayout * h = new QHBoxLayout ();
|
|
|
|
QPushButton * b = myPortButton = new QPushButton (tr ("Te&st Port"));
|
|
|
|
QLabel * l = myPortLabel = new QLabel (tr ("Status unknown"));
|
|
|
|
h->addWidget (l);
|
2014-12-12 23:05:10 +00:00
|
|
|
h->addSpacing (HIG::PAD_BIG);
|
2013-09-14 22:45:04 +00:00
|
|
|
h->addWidget (b);
|
|
|
|
h->setStretchFactor (l, 1);
|
|
|
|
connect (b, SIGNAL(clicked(bool)), this, SLOT(onPortTest()));
|
|
|
|
connect (&mySession, SIGNAL(portTested(bool)), this, SLOT(onPortTested(bool)));
|
|
|
|
|
|
|
|
hig->addRow (tr ("&Port for incoming connections:"), s);
|
|
|
|
hig->addRow (QString(), h, 0);
|
2014-12-12 23:05:10 +00:00
|
|
|
hig->addWideControl (checkBoxNew (tr ("Pick a &random port every time Transmission is started"), Prefs::PEER_PORT_RANDOM_ON_START));
|
2013-09-14 22:45:04 +00:00
|
|
|
hig->addWideControl (checkBoxNew (tr ("Use UPnP or NAT-PMP port &forwarding from my router"), Prefs::PORT_FORWARDING));
|
|
|
|
|
|
|
|
hig->addSectionDivider ();
|
|
|
|
hig->addSectionTitle (tr ("Peer Limits"));
|
|
|
|
hig->addRow (tr ("Maximum peers per &torrent:"), spinBoxNew (Prefs::PEER_LIMIT_TORRENT, 1, FD_SETSIZE, 5));
|
|
|
|
hig->addRow (tr ("Maximum peers &overall:"), spinBoxNew (Prefs::PEER_LIMIT_GLOBAL, 1, FD_SETSIZE, 5));
|
|
|
|
|
|
|
|
hig->addSectionDivider ();
|
|
|
|
hig->addSectionTitle (tr ("Options"));
|
|
|
|
|
|
|
|
QWidget * w;
|
|
|
|
hig->addWideControl (w = checkBoxNew (tr ("Enable &uTP for peer connections"), Prefs::UTP_ENABLED));
|
|
|
|
w->setToolTip (tr ("uTP is a tool for reducing network congestion."));
|
|
|
|
hig->addWideControl (w = checkBoxNew (tr ("Use PE&X to find more peers"), Prefs::PEX_ENABLED));
|
|
|
|
w->setToolTip (tr ("PEX is a tool for exchanging peer lists with the peers you're connected to."));
|
|
|
|
hig->addWideControl (w = checkBoxNew (tr ("Use &DHT to find more peers"), Prefs::DHT_ENABLED));
|
|
|
|
w->setToolTip (tr ("DHT is a tool for finding peers without a tracker."));
|
|
|
|
hig->addWideControl (w = checkBoxNew (tr ("Use &Local Peer Discovery to find more peers"), Prefs::LPD_ENABLED));
|
|
|
|
w->setToolTip (tr ("LPD is a tool for finding peers on your local network."));
|
|
|
|
|
|
|
|
hig->finish ();
|
|
|
|
return hig;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
PrefsDialog::onBlocklistDialogDestroyed (QObject * o)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
Q_UNUSED (o);
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
myBlocklistDialog = 0;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
PrefsDialog::onUpdateBlocklistCancelled ()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
disconnect (&mySession, SIGNAL(blocklistUpdated(int)), this, SLOT(onBlocklistUpdated(int)));
|
|
|
|
myBlocklistDialog->deleteLater ();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
PrefsDialog::onBlocklistUpdated (int n)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2015-01-18 02:09:44 +00:00
|
|
|
myBlocklistDialog->setText (tr ("<b>Update succeeded!</b><p>Blocklist now has %Ln rule(s).", 0, n));
|
2013-09-14 22:45:04 +00:00
|
|
|
myBlocklistDialog->setTextFormat (Qt::RichText);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
PrefsDialog::onUpdateBlocklistClicked ()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
myBlocklistDialog = new QMessageBox (QMessageBox::Information,
|
|
|
|
QString(),
|
|
|
|
tr ("<b>Update Blocklist</b><p>Getting new blocklist..."),
|
|
|
|
QMessageBox::Close,
|
|
|
|
this);
|
|
|
|
connect (myBlocklistDialog, SIGNAL(rejected()), this, SLOT(onUpdateBlocklistCancelled()));
|
|
|
|
connect (&mySession, SIGNAL(blocklistUpdated(int)), this, SLOT(onBlocklistUpdated(int)));
|
|
|
|
myBlocklistDialog->show ();
|
|
|
|
mySession.updateBlocklist ();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2010-01-05 23:47:50 +00:00
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
PrefsDialog::encryptionEdited (int i)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
const int value (qobject_cast<QComboBox*>(sender())->itemData(i).toInt ());
|
|
|
|
setPref (Prefs::ENCRYPTION, value);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QWidget *
|
2014-12-12 23:05:10 +00:00
|
|
|
PrefsDialog::createPrivacyTab ()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
QWidget * w;
|
|
|
|
HIG * hig = new HIG (this);
|
2010-10-31 17:16:12 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
hig->addSectionTitle (tr ("Encryption"));
|
2013-01-16 21:42:03 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
QComboBox * box = new QComboBox ();
|
|
|
|
box->addItem (tr ("Allow encryption"), 0);
|
|
|
|
box->addItem (tr ("Prefer encryption"), 1);
|
|
|
|
box->addItem (tr ("Require encryption"), 2);
|
2014-12-12 23:05:10 +00:00
|
|
|
myWidgets.insert (Prefs::ENCRYPTION, box);
|
2013-09-14 22:45:04 +00:00
|
|
|
connect (box, SIGNAL(activated(int)), this, SLOT(encryptionEdited(int)));
|
2013-01-16 21:42:03 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
hig->addRow (tr ("&Encryption mode:"), box);
|
2013-01-16 21:42:03 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
hig->addSectionDivider ();
|
|
|
|
hig->addSectionTitle (tr ("Blocklist"));
|
2010-10-31 17:16:12 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
QWidget * l = checkBoxNew (tr("Enable &blocklist:"), Prefs::BLOCKLIST_ENABLED);
|
|
|
|
QWidget * e = lineEditNew (Prefs::BLOCKLIST_URL);
|
|
|
|
myBlockWidgets << e;
|
|
|
|
hig->addRow (l, e);
|
2010-10-31 17:16:12 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
l = myBlocklistLabel = new QLabel ();
|
|
|
|
myBlockWidgets << l;
|
|
|
|
w = new QPushButton (tr ("&Update"));
|
|
|
|
connect (w, SIGNAL(clicked(bool)), this, SLOT(onUpdateBlocklistClicked()));
|
|
|
|
myBlockWidgets << w;
|
|
|
|
QHBoxLayout * h = new QHBoxLayout ();
|
|
|
|
h->addWidget (l);
|
|
|
|
h->addStretch (1);
|
|
|
|
h->addWidget (w);
|
|
|
|
hig->addWideControl (h);
|
2010-10-31 17:16:12 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
l = checkBoxNew (tr ("Enable &automatic updates"), Prefs::BLOCKLIST_UPDATES_ENABLED);
|
|
|
|
myBlockWidgets << l;
|
|
|
|
hig->addWideControl (l);
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
hig->finish ();
|
|
|
|
updateBlocklistLabel ();
|
|
|
|
return hig;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2010-05-08 22:42:28 +00:00
|
|
|
void
|
2014-12-14 11:57:23 +00:00
|
|
|
PrefsDialog::onScriptClicked ()
|
2010-05-08 22:42:28 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
const QString title = tr ("Select \"Torrent Done\" Script");
|
|
|
|
const QString myPath = myPrefs.getString (Prefs::SCRIPT_TORRENT_DONE_FILENAME);
|
|
|
|
const QString path = Utils::remoteFileChooser (this, title, myPath, false, mySession.isServer());
|
2010-05-08 22:42:28 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
if (!path.isEmpty())
|
|
|
|
onLocationSelected (path, Prefs::SCRIPT_TORRENT_DONE_FILENAME);
|
2010-05-08 22:42:28 +00:00
|
|
|
}
|
|
|
|
|
2009-10-19 05:25:50 +00:00
|
|
|
void
|
2014-12-14 11:57:23 +00:00
|
|
|
PrefsDialog::onIncompleteClicked ()
|
2009-10-19 05:25:50 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
const QString title = tr ("Select Incomplete Directory");
|
|
|
|
const QString myPath = myPrefs.getString (Prefs::INCOMPLETE_DIR);
|
|
|
|
const QString path = Utils::remoteFileChooser (this, title, myPath, true, mySession.isServer());
|
2009-10-19 05:25:50 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
if (!path.isEmpty())
|
|
|
|
onLocationSelected (path, Prefs::INCOMPLETE_DIR);
|
2009-10-19 05:25:50 +00:00
|
|
|
}
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
void
|
2014-12-14 11:57:23 +00:00
|
|
|
PrefsDialog::onWatchClicked ()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
const QString title = tr ("Select Watch Directory");
|
|
|
|
const QString myPath = myPrefs.getString (Prefs::DIR_WATCH);
|
|
|
|
const QString path = Utils::remoteFileChooser (this, title, myPath, true, true);
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
if (!path.isEmpty())
|
|
|
|
onLocationSelected (path, Prefs::DIR_WATCH);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-14 11:57:23 +00:00
|
|
|
PrefsDialog::onDestinationClicked ()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
const QString title = tr ("Select Destination");
|
|
|
|
const QString myPath = myPrefs.getString (Prefs::DOWNLOAD_DIR);
|
|
|
|
const QString path = Utils::remoteFileChooser (this, title, myPath, true, mySession.isServer());
|
2010-06-04 01:00:27 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
if (!path.isEmpty())
|
|
|
|
onLocationSelected (path, Prefs::DOWNLOAD_DIR);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
PrefsDialog::onLocationSelected (const QString& path, int key)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
setPref (key, path);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2014-12-22 03:06:09 +00:00
|
|
|
void
|
|
|
|
PrefsDialog::onIdleLimitChanged ()
|
|
|
|
{
|
2015-01-12 06:18:52 +00:00
|
|
|
//: Spin box suffix, "Stop seeding if idle for: [ 5 minutes ]" (includes leading space after the number, if needed)
|
2014-12-22 03:06:09 +00:00
|
|
|
const QString unitsSuffix = tr (" minute(s)", 0, myIdleLimitSpin->value ());
|
|
|
|
if (myIdleLimitSpin->suffix () != unitsSuffix)
|
|
|
|
myIdleLimitSpin->setSuffix (unitsSuffix);
|
|
|
|
}
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
QWidget *
|
2014-12-12 23:05:10 +00:00
|
|
|
PrefsDialog::createSeedingTab ()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2014-12-12 23:05:10 +00:00
|
|
|
const int iconSize (style ()->pixelMetric (QStyle::PM_SmallIconSize));
|
2013-09-14 22:45:04 +00:00
|
|
|
const QFileIconProvider iconProvider;
|
|
|
|
const QIcon folderIcon = iconProvider.icon (QFileIconProvider::Folder);
|
|
|
|
const QPixmap folderPixmap = folderIcon.pixmap (iconSize);
|
|
|
|
const QIcon fileIcon = iconProvider.icon (QFileIconProvider::File);
|
|
|
|
const QPixmap filePixmap = fileIcon.pixmap (iconSize);
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
QWidget *l, *r;
|
|
|
|
HIG * hig = new HIG (this);
|
|
|
|
hig->addSectionTitle (tr ("Limits"));
|
2010-07-01 16:15:08 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
l = checkBoxNew (tr ("Stop seeding at &ratio:"), Prefs::RATIO_ENABLED);
|
|
|
|
r = doubleSpinBoxNew (Prefs::RATIO, 0, INT_MAX, 0.5, 2);
|
|
|
|
hig->addRow (l, r);
|
|
|
|
enableBuddyWhenChecked (qobject_cast<QCheckBox*>(l), r);
|
2009-10-20 14:01:15 +00:00
|
|
|
|
2014-12-22 03:06:09 +00:00
|
|
|
l = checkBoxNew (tr ("Stop seedi&ng if idle for:"), Prefs::IDLE_LIMIT_ENABLED);
|
|
|
|
r = myIdleLimitSpin = spinBoxNew (Prefs::IDLE_LIMIT, 1, INT_MAX, 5);
|
|
|
|
connect (r, SIGNAL (valueChanged (int)), this, SLOT (onIdleLimitChanged ()));
|
2013-09-14 22:45:04 +00:00
|
|
|
hig->addRow (l, r);
|
|
|
|
enableBuddyWhenChecked (qobject_cast<QCheckBox*>(l), r);
|
2014-12-22 03:06:09 +00:00
|
|
|
onIdleLimitChanged ();
|
2011-08-01 22:24:24 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
hig->finish ();
|
|
|
|
return hig;
|
2011-08-01 22:24:24 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 21:10:46 +00:00
|
|
|
void
|
|
|
|
PrefsDialog::onQueueStalledMinutesChanged ()
|
|
|
|
{
|
2015-01-12 06:18:52 +00:00
|
|
|
//: Spin box suffix, "Download is inactive if data sharing stopped: [ 5 minutes ago ]" (includes leading space after the number, if needed)
|
2015-01-11 21:10:46 +00:00
|
|
|
const QString unitsSuffix = tr (" minute(s) ago", 0, myQueueStalledMinutesSpin->value ());
|
|
|
|
if (myQueueStalledMinutesSpin->suffix () != unitsSuffix)
|
|
|
|
myQueueStalledMinutesSpin->setSuffix (unitsSuffix);
|
|
|
|
}
|
|
|
|
|
2011-08-01 22:24:24 +00:00
|
|
|
QWidget *
|
2014-12-12 23:05:10 +00:00
|
|
|
PrefsDialog::createDownloadingTab ()
|
2013-09-14 22:45:04 +00:00
|
|
|
{
|
2014-12-12 23:05:10 +00:00
|
|
|
const int iconSize (style ()->pixelMetric (QStyle::PM_SmallIconSize));
|
2013-09-14 22:45:04 +00:00
|
|
|
const QFileIconProvider iconProvider;
|
|
|
|
const QIcon folderIcon = iconProvider.icon (QFileIconProvider::Folder);
|
|
|
|
const QPixmap folderPixmap = folderIcon.pixmap (iconSize);
|
|
|
|
const QIcon fileIcon = iconProvider.icon (QFileIconProvider::File);
|
|
|
|
const QPixmap filePixmap = fileIcon.pixmap (iconSize);
|
|
|
|
|
|
|
|
QWidget * l;
|
|
|
|
QPushButton * b;
|
|
|
|
HIG * hig = new HIG (this);
|
|
|
|
hig->addSectionTitle (tr ("Adding"));
|
|
|
|
|
|
|
|
l = checkBoxNew (tr ("Automatically add .torrent files &from:"), Prefs::DIR_WATCH_ENABLED);
|
|
|
|
b = myWatchButton = new QPushButton;
|
|
|
|
b->setIcon (folderPixmap);
|
|
|
|
b->setStyleSheet (QString::fromUtf8 ("text-align: left; padding-left: 5; padding-right: 5"));
|
2014-12-14 11:57:23 +00:00
|
|
|
connect (b, SIGNAL(clicked(bool)), this, SLOT(onWatchClicked()));
|
2013-09-14 22:45:04 +00:00
|
|
|
hig->addRow (l, b);
|
|
|
|
enableBuddyWhenChecked (qobject_cast<QCheckBox*>(l), b);
|
|
|
|
|
|
|
|
hig->addWideControl (checkBoxNew (tr ("Show the Torrent Options &dialog"), Prefs::OPTIONS_PROMPT));
|
|
|
|
|
|
|
|
hig->addWideControl (checkBoxNew (tr ("&Start added torrents"), Prefs::START));
|
|
|
|
|
|
|
|
hig->addWideControl (checkBoxNew (tr ("Mo&ve the .torrent file to the trash"), Prefs::TRASH_ORIGINAL));
|
|
|
|
|
|
|
|
b = myDestinationButton = new QPushButton;
|
|
|
|
b->setIcon (folderPixmap);
|
|
|
|
b->setStyleSheet (QString::fromUtf8 ("text-align: left; padding-left: 5; padding-right: 5"));
|
2014-12-14 11:57:23 +00:00
|
|
|
connect (b, SIGNAL(clicked(bool)), this, SLOT(onDestinationClicked()));
|
2013-09-14 22:45:04 +00:00
|
|
|
hig->addRow (tr ("Save to &Location:"), b);
|
|
|
|
|
|
|
|
const QString downloadDir (myPrefs.getString(Prefs::DOWNLOAD_DIR));
|
2014-12-26 18:41:47 +00:00
|
|
|
l = myFreespaceLabel = new FreespaceLabel (this);
|
|
|
|
myFreespaceLabel->setSession (mySession);
|
|
|
|
myFreespaceLabel->setPath (downloadDir);
|
2013-09-14 22:45:04 +00:00
|
|
|
QHBoxLayout * h = new QHBoxLayout ();
|
|
|
|
h->addStretch (1);
|
|
|
|
h->addWidget (l);
|
|
|
|
hig->addWideControl (h);
|
|
|
|
|
|
|
|
hig->addSectionDivider ();
|
|
|
|
hig->addSectionTitle (tr ("Download Queue"));
|
2015-01-02 11:15:31 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
hig->addRow (tr ("Ma&ximum active downloads:"), spinBoxNew (Prefs::DOWNLOAD_QUEUE_SIZE, 1, INT_MAX, 1));
|
2015-01-11 21:10:46 +00:00
|
|
|
QSpinBox * sb = myQueueStalledMinutesSpin = spinBoxNew (Prefs::QUEUE_STALLED_MINUTES, 1, INT_MAX, 10);
|
|
|
|
connect (sb, SIGNAL (valueChanged (int)), this, SLOT (onQueueStalledMinutesChanged ()));
|
2015-01-18 02:09:44 +00:00
|
|
|
//: Please keep this phrase as short as possible, it's curently the longest and influences dialog width
|
2015-01-11 21:10:46 +00:00
|
|
|
hig->addRow (tr ("Download is i&nactive if data sharing stopped:"), sb);
|
|
|
|
onQueueStalledMinutesChanged ();
|
2011-08-01 22:24:24 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
hig->addSectionDivider ();
|
|
|
|
hig->addSectionTitle (tr ("Incomplete"));
|
2011-08-01 22:24:24 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
hig->addWideControl (checkBoxNew (tr ("Append \".&part\" to incomplete files' names"), Prefs::RENAME_PARTIAL_FILES));
|
2011-08-01 22:24:24 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
l = myIncompleteCheckbox = checkBoxNew (tr ("Keep &incomplete files in:"), Prefs::INCOMPLETE_DIR_ENABLED);
|
|
|
|
b = myIncompleteButton = new QPushButton;
|
|
|
|
b->setIcon (folderPixmap);
|
|
|
|
b->setStyleSheet (QString::fromUtf8 ("text-align: left; padding-left: 5; padding-right: 5"));
|
2014-12-14 11:57:23 +00:00
|
|
|
connect (b, SIGNAL(clicked(bool)), this, SLOT(onIncompleteClicked()));
|
2013-09-14 22:45:04 +00:00
|
|
|
hig->addRow (myIncompleteCheckbox, b);
|
|
|
|
enableBuddyWhenChecked (qobject_cast<QCheckBox*>(l), b);
|
2010-05-08 22:42:28 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
l = myTorrentDoneScriptCheckbox = checkBoxNew (tr ("Call scrip&t when torrent is completed:"), Prefs::SCRIPT_TORRENT_DONE_ENABLED);
|
|
|
|
b = myTorrentDoneScriptButton = new QPushButton;
|
|
|
|
b->setIcon (filePixmap);
|
|
|
|
b->setStyleSheet (QString::fromUtf8 ("text-align: left; padding-left: 5; padding-right: 5"));
|
2014-12-14 11:57:23 +00:00
|
|
|
connect (b, SIGNAL(clicked(bool)), this, SLOT(onScriptClicked()));
|
2013-09-14 22:45:04 +00:00
|
|
|
hig->addRow (myTorrentDoneScriptCheckbox, b);
|
|
|
|
enableBuddyWhenChecked (qobject_cast<QCheckBox*>(l), b);
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
hig->finish ();
|
|
|
|
return hig;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2014-12-12 23:05:10 +00:00
|
|
|
PrefsDialog::PrefsDialog (Session& session, Prefs& prefs, QWidget * parent):
|
2013-09-14 22:45:04 +00:00
|
|
|
QDialog (parent),
|
|
|
|
myIsServer (session.isServer ()),
|
|
|
|
mySession (session),
|
|
|
|
myPrefs (prefs),
|
|
|
|
myLayout (new QVBoxLayout (this))
|
|
|
|
{
|
|
|
|
setWindowTitle (tr ("Transmission Preferences"));
|
|
|
|
|
|
|
|
QTabWidget * t = new QTabWidget (this);
|
|
|
|
t->addTab (createSpeedTab (), tr ("Speed"));
|
|
|
|
t->addTab (createDownloadingTab (), tr ("Downloading"));
|
|
|
|
t->addTab (createSeedingTab (), tr ("Seeding"));
|
|
|
|
t->addTab (createPrivacyTab (), tr ("Privacy"));
|
|
|
|
t->addTab (createNetworkTab (), tr ("Network"));
|
|
|
|
t->addTab (createDesktopTab (), tr ("Desktop"));
|
|
|
|
t->addTab (createRemoteTab(session), tr ("Remote"));
|
|
|
|
myLayout->addWidget (t);
|
|
|
|
|
|
|
|
QDialogButtonBox * buttons = new QDialogButtonBox (QDialogButtonBox::Close, Qt::Horizontal, this);
|
|
|
|
connect (buttons, SIGNAL(rejected()), this, SLOT(close())); // "close" triggers rejected
|
|
|
|
myLayout->addWidget (buttons);
|
|
|
|
QWidget::setAttribute (Qt::WA_DeleteOnClose, true);
|
|
|
|
|
|
|
|
connect (&mySession, SIGNAL(sessionUpdated()), this, SLOT(sessionUpdated()));
|
|
|
|
|
|
|
|
QList<int> keys;
|
2014-12-12 23:05:10 +00:00
|
|
|
keys << Prefs::RPC_ENABLED
|
|
|
|
<< Prefs::ALT_SPEED_LIMIT_ENABLED
|
|
|
|
<< Prefs::ALT_SPEED_LIMIT_TIME_ENABLED
|
|
|
|
<< Prefs::ENCRYPTION
|
|
|
|
<< Prefs::BLOCKLIST_ENABLED
|
|
|
|
<< Prefs::DIR_WATCH
|
|
|
|
<< Prefs::DOWNLOAD_DIR
|
|
|
|
<< Prefs::INCOMPLETE_DIR
|
|
|
|
<< Prefs::INCOMPLETE_DIR_ENABLED
|
|
|
|
<< Prefs::SCRIPT_TORRENT_DONE_FILENAME;
|
2013-09-14 22:45:04 +00:00
|
|
|
foreach (int key, keys)
|
|
|
|
refreshPref (key);
|
|
|
|
|
|
|
|
// if it's a remote session, disable the preferences
|
|
|
|
// that don't work in remote sessions
|
|
|
|
if (!myIsServer)
|
|
|
|
{
|
|
|
|
foreach (QWidget * w, myUnsupportedWhenRemote)
|
|
|
|
{
|
|
|
|
w->setToolTip (tr ("Not supported by remote sessions"));
|
|
|
|
w->setEnabled (false);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-12 23:05:10 +00:00
|
|
|
PrefsDialog::~PrefsDialog ()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-08-02 16:30:24 +00:00
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
PrefsDialog::setPref (int key, const QVariant& v)
|
2010-08-02 16:30:24 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
myPrefs.set (key, v);
|
|
|
|
refreshPref (key);
|
2010-08-02 16:30:24 +00:00
|
|
|
}
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
PrefsDialog::sessionUpdated ()
|
2009-04-09 22:42:55 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
updateBlocklistLabel ();
|
2009-04-09 22:42:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
PrefsDialog::updateBlocklistLabel ()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
const int n = mySession.blocklistSize ();
|
2015-01-18 02:09:44 +00:00
|
|
|
myBlocklistLabel->setText (tr ("<i>Blocklist contains %Ln rule(s)</i>", 0, n));
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
PrefsDialog::refreshPref (int key)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
switch (key)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2014-12-12 23:05:10 +00:00
|
|
|
case Prefs::RPC_ENABLED:
|
|
|
|
case Prefs::RPC_WHITELIST_ENABLED:
|
|
|
|
case Prefs::RPC_AUTH_REQUIRED:
|
2013-09-14 22:45:04 +00:00
|
|
|
{
|
|
|
|
const bool enabled (myPrefs.getBool (Prefs::RPC_ENABLED));
|
|
|
|
const bool whitelist (myPrefs.getBool (Prefs::RPC_WHITELIST_ENABLED));
|
|
|
|
const bool auth (myPrefs.getBool (Prefs::RPC_AUTH_REQUIRED));
|
|
|
|
foreach (QWidget * w, myWebWhitelistWidgets)w->setEnabled (enabled && whitelist);
|
|
|
|
foreach (QWidget * w, myWebAuthWidgets)w->setEnabled (enabled && auth);
|
|
|
|
foreach (QWidget * w, myWebWidgets)w->setEnabled (enabled);
|
|
|
|
break;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2014-12-12 23:05:10 +00:00
|
|
|
case Prefs::ALT_SPEED_LIMIT_TIME_ENABLED:
|
2013-09-14 22:45:04 +00:00
|
|
|
{
|
|
|
|
const bool enabled = myPrefs.getBool (key);
|
|
|
|
foreach (QWidget * w, mySchedWidgets)w->setEnabled (enabled);
|
|
|
|
break;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2014-12-12 23:05:10 +00:00
|
|
|
case Prefs::BLOCKLIST_ENABLED:
|
2013-09-14 22:45:04 +00:00
|
|
|
{
|
|
|
|
const bool enabled = myPrefs.getBool (key);
|
|
|
|
foreach (QWidget * w, myBlockWidgets)w->setEnabled (enabled);
|
|
|
|
break;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2014-12-12 23:05:10 +00:00
|
|
|
case Prefs::DIR_WATCH:
|
2013-09-14 22:45:04 +00:00
|
|
|
myWatchButton->setText (QFileInfo(myPrefs.getString(Prefs::DIR_WATCH)).fileName());
|
|
|
|
break;
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2014-12-12 23:05:10 +00:00
|
|
|
case Prefs::SCRIPT_TORRENT_DONE_FILENAME:
|
2013-09-14 22:45:04 +00:00
|
|
|
{
|
|
|
|
const QString path (myPrefs.getString (key));
|
|
|
|
myTorrentDoneScriptButton->setText (QFileInfo(path).fileName());
|
|
|
|
break;
|
2011-01-19 20:33:43 +00:00
|
|
|
}
|
|
|
|
|
2014-12-12 23:05:10 +00:00
|
|
|
case Prefs::PEER_PORT:
|
2013-09-14 22:45:04 +00:00
|
|
|
myPortLabel->setText (tr ("Status unknown"));
|
|
|
|
myPortButton->setEnabled (true);
|
|
|
|
break;
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2014-12-12 23:05:10 +00:00
|
|
|
case Prefs::DOWNLOAD_DIR:
|
2013-09-14 22:45:04 +00:00
|
|
|
{
|
|
|
|
const QString path (myPrefs.getString (key));
|
|
|
|
myDestinationButton->setText (QFileInfo(path).fileName());
|
|
|
|
myFreespaceLabel->setPath (path);
|
|
|
|
break;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2014-12-12 23:05:10 +00:00
|
|
|
case Prefs::INCOMPLETE_DIR:
|
2013-09-14 22:45:04 +00:00
|
|
|
{
|
|
|
|
QString path (myPrefs.getString (key));
|
|
|
|
myIncompleteButton->setText (QFileInfo(path).fileName());
|
|
|
|
break;
|
2009-10-20 14:01:15 +00:00
|
|
|
}
|
|
|
|
|
2014-12-12 23:05:10 +00:00
|
|
|
case Prefs::INCOMPLETE_DIR_ENABLED:
|
2013-09-14 22:45:04 +00:00
|
|
|
{
|
|
|
|
const bool enabled = myPrefs.getBool (key);
|
|
|
|
myIncompleteButton->setEnabled (enabled);
|
|
|
|
break;
|
2009-10-20 14:01:15 +00:00
|
|
|
}
|
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
default:
|
|
|
|
break;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
key2widget_t::iterator it (myWidgets.find (key));
|
|
|
|
if (it != myWidgets.end ())
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
QWidget * w (it.value ());
|
|
|
|
QCheckBox * checkBox;
|
|
|
|
QSpinBox * spin;
|
|
|
|
QDoubleSpinBox * doubleSpin;
|
|
|
|
QTimeEdit * timeEdit;
|
|
|
|
QLineEdit * lineEdit;
|
|
|
|
|
|
|
|
if ((checkBox = qobject_cast<QCheckBox*>(w)))
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
checkBox->setChecked (myPrefs.getBool (key));
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2013-09-14 22:45:04 +00:00
|
|
|
else if ((spin = qobject_cast<QSpinBox*>(w)))
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
spin->setValue (myPrefs.getInt (key));
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2013-09-14 22:45:04 +00:00
|
|
|
else if ((doubleSpin = qobject_cast<QDoubleSpinBox*>(w)))
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
doubleSpin->setValue (myPrefs.getDouble (key));
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2013-09-14 22:45:04 +00:00
|
|
|
else if ((timeEdit = qobject_cast<QTimeEdit*>(w)))
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
const int minutes (myPrefs.getInt (key));
|
|
|
|
timeEdit->setTime (QTime().addSecs (minutes * 60));
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2013-09-14 22:45:04 +00:00
|
|
|
else if ((lineEdit = qobject_cast<QLineEdit*>(w)))
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
lineEdit->setText (myPrefs.getString (key));
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2013-09-14 22:45:04 +00:00
|
|
|
else if (key == Prefs::ENCRYPTION)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
QComboBox * comboBox (qobject_cast<QComboBox*> (w));
|
|
|
|
const int index = comboBox->findData (myPrefs.getInt (key));
|
|
|
|
comboBox->setCurrentIndex (index);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-12-12 23:05:10 +00:00
|
|
|
PrefsDialog::isAllowed (int key) const
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
Q_UNUSED (key);
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
return true;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|