1 | /* |
---|
2 | * This file Copyright (C) Mnemosyne LLC |
---|
3 | * |
---|
4 | * This program is free software; you can redistribute it and/or modify |
---|
5 | * it under the terms of the GNU General Public License version 2 |
---|
6 | * as published by the Free Software Foundation. |
---|
7 | * |
---|
8 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
9 | * |
---|
10 | * $Id: prefs-dialog.cc 13796 2013-01-16 21:42:03Z jordan $ |
---|
11 | */ |
---|
12 | |
---|
13 | #include <cassert> |
---|
14 | #include <iostream> |
---|
15 | |
---|
16 | #include <QCheckBox> |
---|
17 | #include <QComboBox> |
---|
18 | #include <QCoreApplication> |
---|
19 | #include <QDialogButtonBox> |
---|
20 | #include <QDoubleSpinBox> |
---|
21 | #include <QFileIconProvider> |
---|
22 | #include <QFileInfo> |
---|
23 | #include <QHBoxLayout> |
---|
24 | #include <QHttp> |
---|
25 | #include <QIcon> |
---|
26 | #include <QLabel> |
---|
27 | #include <QLineEdit> |
---|
28 | #include <QList> |
---|
29 | #include <QMessageBox> |
---|
30 | #include <QPushButton> |
---|
31 | #include <QSpinBox> |
---|
32 | #include <QStyle> |
---|
33 | #include <QTabWidget> |
---|
34 | #include <QTime> |
---|
35 | #include <QTimeEdit> |
---|
36 | #include <QTimer> |
---|
37 | #include <QVBoxLayout> |
---|
38 | |
---|
39 | #include "formatter.h" |
---|
40 | #include "hig.h" |
---|
41 | #include "prefs.h" |
---|
42 | #include "prefs-dialog.h" |
---|
43 | #include "session.h" |
---|
44 | #include "utils.h" |
---|
45 | |
---|
46 | /*** |
---|
47 | **** |
---|
48 | ***/ |
---|
49 | |
---|
50 | namespace |
---|
51 | { |
---|
52 | const char * PREF_KEY( "pref-key" ); |
---|
53 | }; |
---|
54 | |
---|
55 | void |
---|
56 | PrefsDialog :: checkBoxToggled( bool checked ) |
---|
57 | { |
---|
58 | const int key( sender( )->property( PREF_KEY ).toInt( ) ); |
---|
59 | setPref( key, checked ); |
---|
60 | } |
---|
61 | |
---|
62 | QCheckBox * |
---|
63 | PrefsDialog :: checkBoxNew( const QString& text, int key ) |
---|
64 | { |
---|
65 | QCheckBox * box = new QCheckBox( text ); |
---|
66 | box->setChecked( myPrefs.getBool( key ) ); |
---|
67 | box->setProperty( PREF_KEY, key ); |
---|
68 | connect( box, SIGNAL(toggled(bool)), this, SLOT(checkBoxToggled(bool))); |
---|
69 | myWidgets.insert( key, box ); |
---|
70 | return box; |
---|
71 | } |
---|
72 | |
---|
73 | void |
---|
74 | PrefsDialog :: enableBuddyWhenChecked( QCheckBox * box, QWidget * buddy ) |
---|
75 | { |
---|
76 | connect( box, SIGNAL(toggled(bool)), buddy, SLOT(setEnabled(bool)) ); |
---|
77 | buddy->setEnabled( box->isChecked( ) ); |
---|
78 | } |
---|
79 | |
---|
80 | void |
---|
81 | PrefsDialog :: spinBoxEditingFinished() |
---|
82 | { |
---|
83 | const QObject * spin = sender(); |
---|
84 | const int key = spin->property( PREF_KEY ).toInt( ); |
---|
85 | const QDoubleSpinBox * d = qobject_cast<const QDoubleSpinBox*>( spin ); |
---|
86 | if( d ) |
---|
87 | setPref( key, d->value( ) ); |
---|
88 | else |
---|
89 | setPref( key, qobject_cast<const QSpinBox*>(spin)->value( ) ); |
---|
90 | } |
---|
91 | |
---|
92 | QSpinBox * |
---|
93 | PrefsDialog :: spinBoxNew( int key, int low, int high, int step ) |
---|
94 | { |
---|
95 | QSpinBox * spin = new QSpinBox( ); |
---|
96 | spin->setRange( low, high ); |
---|
97 | spin->setSingleStep( step ); |
---|
98 | spin->setValue( myPrefs.getInt( key ) ); |
---|
99 | spin->setProperty( PREF_KEY, key ); |
---|
100 | connect( spin, SIGNAL(editingFinished()), this, SLOT(spinBoxEditingFinished())); |
---|
101 | myWidgets.insert( key, spin ); |
---|
102 | return spin; |
---|
103 | } |
---|
104 | |
---|
105 | QDoubleSpinBox * |
---|
106 | PrefsDialog :: doubleSpinBoxNew( int key, double low, double high, double step, int decimals ) |
---|
107 | { |
---|
108 | QDoubleSpinBox * spin = new QDoubleSpinBox( ); |
---|
109 | spin->setRange( low, high ); |
---|
110 | spin->setSingleStep( step ); |
---|
111 | spin->setDecimals( decimals ); |
---|
112 | spin->setValue( myPrefs.getDouble( key ) ); |
---|
113 | spin->setProperty( PREF_KEY, key ); |
---|
114 | connect( spin, SIGNAL(editingFinished()), this, SLOT(spinBoxEditingFinished())); |
---|
115 | myWidgets.insert( key, spin ); |
---|
116 | return spin; |
---|
117 | } |
---|
118 | |
---|
119 | void |
---|
120 | PrefsDialog :: timeEditingFinished( ) |
---|
121 | { |
---|
122 | QTimeEdit * e = qobject_cast<QTimeEdit*>(sender()); |
---|
123 | if( e ) |
---|
124 | { |
---|
125 | const int key( e->property( PREF_KEY ).toInt( ) ); |
---|
126 | const QTime time( e->time( ) ); |
---|
127 | const int seconds( QTime().secsTo( time ) ); |
---|
128 | std::cerr << "setPref to " << (seconds/60) << " minutes" << std::endl; |
---|
129 | setPref( key, seconds / 60 ); |
---|
130 | } |
---|
131 | } |
---|
132 | QTimeEdit* |
---|
133 | PrefsDialog :: timeEditNew( int key ) |
---|
134 | { |
---|
135 | const int minutes( myPrefs.getInt( key ) ); |
---|
136 | QTimeEdit * e = new QTimeEdit( ); |
---|
137 | e->setDisplayFormat( QString::fromAscii( "hh:mm" ) ); |
---|
138 | e->setProperty( PREF_KEY, key ); |
---|
139 | e->setTime( QTime().addSecs( minutes * 60 ) ); |
---|
140 | myWidgets.insert( key, e ); |
---|
141 | connect( e, SIGNAL(editingFinished()), this, SLOT(timeEditingFinished()) ); |
---|
142 | return e; |
---|
143 | } |
---|
144 | |
---|
145 | void |
---|
146 | PrefsDialog :: lineEditingFinished( ) |
---|
147 | { |
---|
148 | QLineEdit * e = qobject_cast<QLineEdit*>(sender()); |
---|
149 | if( e && e->isModified( ) ) |
---|
150 | { |
---|
151 | const int key( e->property( PREF_KEY ).toInt( ) ); |
---|
152 | const QString text( e->text() ); |
---|
153 | setPref( key, text ); |
---|
154 | } |
---|
155 | } |
---|
156 | QLineEdit* |
---|
157 | PrefsDialog :: lineEditNew( int key, int echoMode ) |
---|
158 | { |
---|
159 | QLineEdit * e = new QLineEdit( myPrefs.getString( key ) ); |
---|
160 | e->setProperty( PREF_KEY, key ); |
---|
161 | e->setEchoMode( QLineEdit::EchoMode( echoMode ) ); |
---|
162 | myWidgets.insert( key, e ); |
---|
163 | connect( e, SIGNAL(editingFinished()), this, SLOT(lineEditingFinished()) ); |
---|
164 | return e; |
---|
165 | } |
---|
166 | |
---|
167 | /*** |
---|
168 | **** |
---|
169 | ***/ |
---|
170 | |
---|
171 | QWidget * |
---|
172 | PrefsDialog :: createRemoteTab( Session& session ) |
---|
173 | { |
---|
174 | HIG * hig = new HIG( this ); |
---|
175 | hig->addSectionTitle( tr( "Remote Control" ) ); |
---|
176 | QWidget * w; |
---|
177 | QHBoxLayout * h = new QHBoxLayout( ); |
---|
178 | QPushButton * b = new QPushButton( tr( "&Open web client" ) ); |
---|
179 | connect( b, SIGNAL(clicked()), &session, SLOT(launchWebInterface()) ); |
---|
180 | h->addWidget( b, 0, Qt::AlignRight ); |
---|
181 | QWidget * l = checkBoxNew( tr( "Allow &remote access" ), Prefs::RPC_ENABLED ); |
---|
182 | myUnsupportedWhenRemote << l; |
---|
183 | hig->addRow( l, h, 0 ); |
---|
184 | l = hig->addRow( tr( "HTTP &port:" ), w = spinBoxNew( Prefs::RPC_PORT, 0, 65535, 1 ) ); |
---|
185 | myWebWidgets << l << w; |
---|
186 | hig->addWideControl( w = checkBoxNew( tr( "Use &authentication" ), Prefs::RPC_AUTH_REQUIRED ) ); |
---|
187 | myWebWidgets << w; |
---|
188 | l = hig->addRow( tr( "&Username:" ), w = lineEditNew( Prefs::RPC_USERNAME ) ); |
---|
189 | myWebAuthWidgets << l << w; |
---|
190 | l = hig->addRow( tr( "Pass&word:" ), w = lineEditNew( Prefs::RPC_PASSWORD, QLineEdit::Password ) ); |
---|
191 | myWebAuthWidgets << l << w; |
---|
192 | hig->addWideControl( w = checkBoxNew( tr( "Only allow these IP a&ddresses:" ), Prefs::RPC_WHITELIST_ENABLED ) ); |
---|
193 | myWebWidgets << w; |
---|
194 | l = hig->addRow( tr( "Addresses:" ), w = lineEditNew( Prefs::RPC_WHITELIST ) ); |
---|
195 | myWebWhitelistWidgets << l << w; |
---|
196 | myUnsupportedWhenRemote << myWebWidgets << myWebAuthWidgets << myWebWhitelistWidgets; |
---|
197 | hig->finish( ); |
---|
198 | return hig; |
---|
199 | } |
---|
200 | |
---|
201 | /*** |
---|
202 | **** |
---|
203 | ***/ |
---|
204 | |
---|
205 | void |
---|
206 | PrefsDialog :: altSpeedDaysEdited( int i ) |
---|
207 | { |
---|
208 | const int value = qobject_cast<QComboBox*>(sender())->itemData(i).toInt(); |
---|
209 | setPref( Prefs::ALT_SPEED_LIMIT_TIME_DAY, value ); |
---|
210 | } |
---|
211 | |
---|
212 | |
---|
213 | QWidget * |
---|
214 | PrefsDialog :: createSpeedTab( ) |
---|
215 | { |
---|
216 | QWidget *l, *r; |
---|
217 | HIG * hig = new HIG( this ); |
---|
218 | hig->addSectionTitle( tr( "Speed Limits" ) ); |
---|
219 | const QString speed_K_str = Formatter::unitStr( Formatter::SPEED, Formatter::KB ); |
---|
220 | |
---|
221 | l = checkBoxNew( tr( "&Upload (%1):" ).arg( speed_K_str ), Prefs::USPEED_ENABLED ); |
---|
222 | r = spinBoxNew( Prefs::USPEED, 0, INT_MAX, 5 ); |
---|
223 | hig->addRow( l, r ); |
---|
224 | enableBuddyWhenChecked( qobject_cast<QCheckBox*>(l), r ); |
---|
225 | |
---|
226 | l = checkBoxNew( tr( "&Download (%1):" ).arg( speed_K_str ), Prefs::DSPEED_ENABLED ); |
---|
227 | r = spinBoxNew( Prefs::DSPEED, 0, INT_MAX, 5 ); |
---|
228 | hig->addRow( l, r ); |
---|
229 | enableBuddyWhenChecked( qobject_cast<QCheckBox*>(l), r ); |
---|
230 | |
---|
231 | hig->addSectionDivider( ); |
---|
232 | QHBoxLayout * h = new QHBoxLayout; |
---|
233 | h->setSpacing( HIG :: PAD ); |
---|
234 | QLabel * label = new QLabel; |
---|
235 | label->setPixmap( QPixmap( QString::fromAscii( ":/icons/alt-limit-off.png" ) ) ); |
---|
236 | label->setAlignment( Qt::AlignLeft|Qt::AlignVCenter ); |
---|
237 | h->addWidget( label ); |
---|
238 | label = new QLabel( tr( "Alternative Speed Limits" ) ); |
---|
239 | label->setStyleSheet( QString::fromAscii( "font: bold" ) ); |
---|
240 | label->setAlignment( Qt::AlignLeft|Qt::AlignVCenter ); |
---|
241 | h->addWidget( label ); |
---|
242 | hig->addSectionTitle( h ); |
---|
243 | |
---|
244 | QString s = tr( "<small>Override normal speed limits manually or at scheduled times</small>" ); |
---|
245 | hig->addWideControl( new QLabel( s ) ); |
---|
246 | |
---|
247 | s = tr( "U&pload (%1):" ).arg( speed_K_str ); |
---|
248 | r = spinBoxNew( Prefs :: ALT_SPEED_LIMIT_UP, 0, INT_MAX, 5 ); |
---|
249 | hig->addRow( s, r ); |
---|
250 | |
---|
251 | s = tr( "Do&wnload (%1):" ).arg( speed_K_str ); |
---|
252 | r = spinBoxNew( Prefs :: ALT_SPEED_LIMIT_DOWN, 0, INT_MAX, 5 ); |
---|
253 | hig->addRow( s, r ); |
---|
254 | |
---|
255 | QCheckBox * c = checkBoxNew( tr( "&Scheduled times:" ), Prefs::ALT_SPEED_LIMIT_TIME_ENABLED ); |
---|
256 | h = new QHBoxLayout( ); |
---|
257 | h->setSpacing( HIG::PAD ); |
---|
258 | QWidget * w = timeEditNew( Prefs :: ALT_SPEED_LIMIT_TIME_BEGIN ); |
---|
259 | h->addWidget( w, 1 ); |
---|
260 | mySchedWidgets << w; |
---|
261 | QLabel * nd = new QLabel( tr("&to") ); |
---|
262 | h->addWidget( nd ); |
---|
263 | mySchedWidgets << nd; |
---|
264 | w = timeEditNew( Prefs :: ALT_SPEED_LIMIT_TIME_END ); |
---|
265 | nd->setBuddy( w ); |
---|
266 | h->addWidget( w, 1 ); |
---|
267 | mySchedWidgets << w; |
---|
268 | hig->addRow( c, h, 0 ); |
---|
269 | |
---|
270 | s = tr( "&On days:" ); |
---|
271 | QComboBox * box = new QComboBox; |
---|
272 | const QIcon noIcon; |
---|
273 | box->addItem( noIcon, tr( "Every Day" ), QVariant( TR_SCHED_ALL ) ); |
---|
274 | box->addItem( noIcon, tr( "Weekdays" ), QVariant( TR_SCHED_WEEKDAY ) ); |
---|
275 | box->addItem( noIcon, tr( "Weekends" ), QVariant( TR_SCHED_WEEKEND ) ); |
---|
276 | box->addItem( noIcon, tr( "Sunday" ), QVariant( TR_SCHED_SUN ) ); |
---|
277 | box->addItem( noIcon, tr( "Monday" ), QVariant( TR_SCHED_MON ) ); |
---|
278 | box->addItem( noIcon, tr( "Tuesday" ), QVariant( TR_SCHED_TUES ) ); |
---|
279 | box->addItem( noIcon, tr( "Wednesday" ), QVariant( TR_SCHED_WED ) ); |
---|
280 | box->addItem( noIcon, tr( "Thursday" ), QVariant( TR_SCHED_THURS ) ); |
---|
281 | box->addItem( noIcon, tr( "Friday" ), QVariant( TR_SCHED_FRI ) ); |
---|
282 | box->addItem( noIcon, tr( "Saturday" ), QVariant( TR_SCHED_SAT ) ); |
---|
283 | box->setCurrentIndex( box->findData( myPrefs.getInt( Prefs :: ALT_SPEED_LIMIT_TIME_DAY ) ) ); |
---|
284 | connect( box, SIGNAL(activated(int)), this, SLOT(altSpeedDaysEdited(int)) ); |
---|
285 | w = hig->addRow( s, box ); |
---|
286 | mySchedWidgets << w << box; |
---|
287 | |
---|
288 | hig->finish( ); |
---|
289 | return hig; |
---|
290 | } |
---|
291 | |
---|
292 | /*** |
---|
293 | **** |
---|
294 | ***/ |
---|
295 | |
---|
296 | QWidget * |
---|
297 | PrefsDialog :: createDesktopTab( ) |
---|
298 | { |
---|
299 | HIG * hig = new HIG( this ); |
---|
300 | hig->addSectionTitle( tr( "Desktop" ) ); |
---|
301 | |
---|
302 | hig->addWideControl( checkBoxNew( tr( "Show Transmission icon in the ¬ification area" ), Prefs::SHOW_TRAY_ICON ) ); |
---|
303 | hig->addWideControl( checkBoxNew( tr( "Start &minimized in notification area" ), Prefs::START_MINIMIZED ) ); |
---|
304 | hig->addWideControl( checkBoxNew( tr( "Show &popup notifications" ), Prefs::SHOW_DESKTOP_NOTIFICATION ) ); |
---|
305 | |
---|
306 | hig->finish( ); |
---|
307 | return hig; |
---|
308 | } |
---|
309 | |
---|
310 | /*** |
---|
311 | **** |
---|
312 | ***/ |
---|
313 | |
---|
314 | void |
---|
315 | PrefsDialog :: onPortTested( bool isOpen ) |
---|
316 | { |
---|
317 | myPortButton->setEnabled( true ); |
---|
318 | myWidgets[Prefs::PEER_PORT]->setEnabled( true ); |
---|
319 | myPortLabel->setText( isOpen ? tr( "Port is <b>open</b>" ) |
---|
320 | : tr( "Port is <b>closed</b>" ) ); |
---|
321 | } |
---|
322 | |
---|
323 | void |
---|
324 | PrefsDialog :: onPortTest( ) |
---|
325 | { |
---|
326 | myPortLabel->setText( tr( "Testing TCP Port..." ) ); |
---|
327 | myPortButton->setEnabled( false ); |
---|
328 | myWidgets[Prefs::PEER_PORT]->setEnabled( false ); |
---|
329 | mySession.portTest( ); |
---|
330 | } |
---|
331 | |
---|
332 | QWidget * |
---|
333 | PrefsDialog :: createNetworkTab( ) |
---|
334 | { |
---|
335 | HIG * hig = new HIG( this ); |
---|
336 | hig->addSectionTitle( tr( "Incoming Peers" ) ); |
---|
337 | |
---|
338 | QSpinBox * s = spinBoxNew( Prefs::PEER_PORT, 1, 65535, 1 ); |
---|
339 | QHBoxLayout * h = new QHBoxLayout( ); |
---|
340 | QPushButton * b = myPortButton = new QPushButton( tr( "Te&st Port" ) ); |
---|
341 | QLabel * l = myPortLabel = new QLabel( tr( "Status unknown" ) ); |
---|
342 | h->addWidget( l ); |
---|
343 | h->addSpacing( HIG :: PAD_BIG ); |
---|
344 | h->addWidget( b ); |
---|
345 | h->setStretchFactor( l, 1 ); |
---|
346 | connect( b, SIGNAL(clicked(bool)), this, SLOT(onPortTest())); |
---|
347 | connect( &mySession, SIGNAL(portTested(bool)), this, SLOT(onPortTested(bool))); |
---|
348 | |
---|
349 | hig->addRow( tr( "&Port for incoming connections:" ), s ); |
---|
350 | hig->addRow( QString(), h, 0 ); |
---|
351 | hig->addWideControl( checkBoxNew( tr( "Pick a &random port every time Transmission is started" ), Prefs :: PEER_PORT_RANDOM_ON_START ) ); |
---|
352 | hig->addWideControl( checkBoxNew( tr( "Use UPnP or NAT-PMP port &forwarding from my router" ), Prefs::PORT_FORWARDING ) ); |
---|
353 | |
---|
354 | hig->addSectionDivider( ); |
---|
355 | hig->addSectionTitle( tr( "Peer Limits" ) ); |
---|
356 | hig->addRow( tr( "Maximum peers per &torrent:" ), spinBoxNew( Prefs::PEER_LIMIT_TORRENT, 1, FD_SETSIZE, 5 ) ); |
---|
357 | hig->addRow( tr( "Maximum peers &overall:" ), spinBoxNew( Prefs::PEER_LIMIT_GLOBAL, 1, FD_SETSIZE, 5 ) ); |
---|
358 | |
---|
359 | hig->addSectionDivider( ); |
---|
360 | hig->addSectionTitle( tr( "Options" ) ); |
---|
361 | |
---|
362 | QWidget * w; |
---|
363 | hig->addWideControl( w = checkBoxNew( tr( "Enable &uTP for peer connections" ), Prefs::UTP_ENABLED ) ); |
---|
364 | w->setToolTip( tr( "uTP is a tool for reducing network congestion." ) ); |
---|
365 | hig->addWideControl( w = checkBoxNew( tr( "Use PE&X to find more peers" ), Prefs::PEX_ENABLED ) ); |
---|
366 | w->setToolTip( tr( "PEX is a tool for exchanging peer lists with the peers you're connected to." ) ); |
---|
367 | hig->addWideControl( w = checkBoxNew( tr( "Use &DHT to find more peers" ), Prefs::DHT_ENABLED ) ); |
---|
368 | w->setToolTip( tr( "DHT is a tool for finding peers without a tracker." ) ); |
---|
369 | hig->addWideControl( w = checkBoxNew( tr( "Use &Local Peer Discovery to find more peers" ), Prefs::LPD_ENABLED ) ); |
---|
370 | w->setToolTip( tr( "LPD is a tool for finding peers on your local network." ) ); |
---|
371 | |
---|
372 | hig->finish( ); |
---|
373 | return hig; |
---|
374 | } |
---|
375 | |
---|
376 | /*** |
---|
377 | **** |
---|
378 | ***/ |
---|
379 | |
---|
380 | void |
---|
381 | PrefsDialog :: onBlocklistDialogDestroyed( QObject * o ) |
---|
382 | { |
---|
383 | Q_UNUSED( o ); |
---|
384 | |
---|
385 | myBlocklistDialog = 0; |
---|
386 | } |
---|
387 | |
---|
388 | void |
---|
389 | PrefsDialog :: onUpdateBlocklistCancelled( ) |
---|
390 | { |
---|
391 | disconnect( &mySession, SIGNAL(blocklistUpdated(int)), this, SLOT(onBlocklistUpdated(int))) ; |
---|
392 | myBlocklistDialog->deleteLater( ); |
---|
393 | } |
---|
394 | |
---|
395 | void |
---|
396 | PrefsDialog :: onBlocklistUpdated( int n ) |
---|
397 | { |
---|
398 | myBlocklistDialog->setText( tr( "<b>Update succeeded!</b><p>Blocklist now has %Ln rules.", 0, n ) ); |
---|
399 | myBlocklistDialog->setTextFormat( Qt::RichText ); |
---|
400 | } |
---|
401 | |
---|
402 | void |
---|
403 | PrefsDialog :: onUpdateBlocklistClicked( ) |
---|
404 | { |
---|
405 | myBlocklistDialog = new QMessageBox( QMessageBox::Information, |
---|
406 | QString(), |
---|
407 | tr( "<b>Update Blocklist</b><p>Getting new blocklist..." ), |
---|
408 | QMessageBox::Close, |
---|
409 | this ); |
---|
410 | connect( myBlocklistDialog, SIGNAL(rejected()), this, SLOT(onUpdateBlocklistCancelled()) ); |
---|
411 | connect( &mySession, SIGNAL(blocklistUpdated(int)), this, SLOT(onBlocklistUpdated(int))) ; |
---|
412 | myBlocklistDialog->show( ); |
---|
413 | mySession.updateBlocklist( ); |
---|
414 | } |
---|
415 | |
---|
416 | void |
---|
417 | PrefsDialog :: encryptionEdited( int i ) |
---|
418 | { |
---|
419 | const int value( qobject_cast<QComboBox*>(sender())->itemData(i).toInt( ) ); |
---|
420 | setPref( Prefs::ENCRYPTION, value ); |
---|
421 | } |
---|
422 | |
---|
423 | QWidget * |
---|
424 | PrefsDialog :: createPrivacyTab( ) |
---|
425 | { |
---|
426 | QWidget * w; |
---|
427 | HIG * hig = new HIG( this ); |
---|
428 | |
---|
429 | hig->addSectionTitle( tr( "Encryption" ) ); |
---|
430 | |
---|
431 | QComboBox * box = new QComboBox( ); |
---|
432 | box->addItem( tr( "Allow encryption" ), 0 ); |
---|
433 | box->addItem( tr( "Prefer encryption" ), 1 ); |
---|
434 | box->addItem( tr( "Require encryption" ), 2 ); |
---|
435 | myWidgets.insert( Prefs :: ENCRYPTION, box ); |
---|
436 | connect( box, SIGNAL(activated(int)), this, SLOT(encryptionEdited(int))); |
---|
437 | |
---|
438 | hig->addRow( tr( "&Encryption mode:" ), box ); |
---|
439 | |
---|
440 | hig->addSectionDivider( ); |
---|
441 | hig->addSectionTitle( tr( "Blocklist" ) ); |
---|
442 | |
---|
443 | QWidget * l = checkBoxNew( tr("Enable &blocklist:"), Prefs::BLOCKLIST_ENABLED ); |
---|
444 | QWidget * e = lineEditNew( Prefs::BLOCKLIST_URL ); |
---|
445 | myBlockWidgets << e; |
---|
446 | hig->addRow( l, e ); |
---|
447 | |
---|
448 | l = myBlocklistLabel = new QLabel( ); |
---|
449 | myBlockWidgets << l; |
---|
450 | w = new QPushButton( tr( "&Update" ) ); |
---|
451 | connect( w, SIGNAL(clicked(bool)), this, SLOT(onUpdateBlocklistClicked())); |
---|
452 | myBlockWidgets << w; |
---|
453 | QHBoxLayout * h = new QHBoxLayout( ); |
---|
454 | h->addWidget( l ); |
---|
455 | h->addStretch( 1 ); |
---|
456 | h->addWidget( w ); |
---|
457 | hig->addWideControl( h ); |
---|
458 | |
---|
459 | l = checkBoxNew( tr( "Enable &automatic updates" ), Prefs::BLOCKLIST_UPDATES_ENABLED ); |
---|
460 | myBlockWidgets << l; |
---|
461 | hig->addWideControl( l ); |
---|
462 | |
---|
463 | hig->finish( ); |
---|
464 | updateBlocklistLabel( ); |
---|
465 | return hig; |
---|
466 | } |
---|
467 | |
---|
468 | /*** |
---|
469 | **** |
---|
470 | ***/ |
---|
471 | |
---|
472 | void |
---|
473 | PrefsDialog :: onScriptClicked( void ) |
---|
474 | { |
---|
475 | const QString title = tr( "Select \"Torrent Done\" Script" ); |
---|
476 | const QString myPath = myPrefs.getString( Prefs::SCRIPT_TORRENT_DONE_FILENAME ); |
---|
477 | const QString path = Utils::remoteFileChooser( this, title, myPath, false, mySession.isServer() ); |
---|
478 | |
---|
479 | if( !path.isEmpty() ) |
---|
480 | onLocationSelected( path, Prefs::SCRIPT_TORRENT_DONE_FILENAME ); |
---|
481 | } |
---|
482 | |
---|
483 | void |
---|
484 | PrefsDialog :: onIncompleteClicked( void ) |
---|
485 | { |
---|
486 | const QString title = tr( "Select Incomplete Directory" ); |
---|
487 | const QString myPath = myPrefs.getString( Prefs::INCOMPLETE_DIR ); |
---|
488 | const QString path = Utils::remoteFileChooser( this, title, myPath, true, mySession.isServer() ); |
---|
489 | |
---|
490 | if( !path.isEmpty() ) |
---|
491 | onLocationSelected( path, Prefs::INCOMPLETE_DIR ); |
---|
492 | } |
---|
493 | |
---|
494 | void |
---|
495 | PrefsDialog :: onWatchClicked( void ) |
---|
496 | { |
---|
497 | const QString title = tr( "Select Watch Directory" ); |
---|
498 | const QString myPath = myPrefs.getString( Prefs::DIR_WATCH ); |
---|
499 | const QString path = Utils::remoteFileChooser( this, title, myPath, true, true ); |
---|
500 | |
---|
501 | if( !path.isEmpty() ) |
---|
502 | onLocationSelected( path, Prefs::DIR_WATCH ); |
---|
503 | } |
---|
504 | |
---|
505 | void |
---|
506 | PrefsDialog :: onDestinationClicked( void ) |
---|
507 | { |
---|
508 | const QString title = tr( "Select Destination" ); |
---|
509 | const QString myPath = myPrefs.getString( Prefs::DOWNLOAD_DIR ); |
---|
510 | const QString path = Utils::remoteFileChooser( this, title, myPath, true, mySession.isServer() ); |
---|
511 | |
---|
512 | if( !path.isEmpty() ) |
---|
513 | onLocationSelected( path, Prefs::DOWNLOAD_DIR ); |
---|
514 | } |
---|
515 | |
---|
516 | void |
---|
517 | PrefsDialog :: onLocationSelected( const QString& path, int key ) |
---|
518 | { |
---|
519 | setPref( key, path ); |
---|
520 | } |
---|
521 | |
---|
522 | QWidget * |
---|
523 | PrefsDialog :: createSeedingTab( ) |
---|
524 | { |
---|
525 | const int iconSize( style( )->pixelMetric( QStyle :: PM_SmallIconSize ) ); |
---|
526 | const QFileIconProvider iconProvider; |
---|
527 | const QIcon folderIcon = iconProvider.icon( QFileIconProvider::Folder ); |
---|
528 | const QPixmap folderPixmap = folderIcon.pixmap( iconSize ); |
---|
529 | const QIcon fileIcon = iconProvider.icon( QFileIconProvider::File ); |
---|
530 | const QPixmap filePixmap = fileIcon.pixmap( iconSize ); |
---|
531 | |
---|
532 | QWidget *l, *r; |
---|
533 | HIG * hig = new HIG( this ); |
---|
534 | hig->addSectionTitle( tr( "Limits" ) ); |
---|
535 | |
---|
536 | l = checkBoxNew( tr( "Stop seeding at &ratio:" ), Prefs::RATIO_ENABLED ); |
---|
537 | r = doubleSpinBoxNew( Prefs::RATIO, 0, INT_MAX, 0.5, 2 ); |
---|
538 | hig->addRow( l, r ); |
---|
539 | enableBuddyWhenChecked( qobject_cast<QCheckBox*>(l), r ); |
---|
540 | |
---|
541 | l = checkBoxNew( tr( "Stop seeding if idle for &N minutes:" ), Prefs::IDLE_LIMIT_ENABLED ); |
---|
542 | r = spinBoxNew( Prefs::IDLE_LIMIT, 1, INT_MAX, 5 ); |
---|
543 | hig->addRow( l, r ); |
---|
544 | enableBuddyWhenChecked( qobject_cast<QCheckBox*>(l), r ); |
---|
545 | |
---|
546 | hig->finish( ); |
---|
547 | return hig; |
---|
548 | } |
---|
549 | |
---|
550 | QWidget * |
---|
551 | PrefsDialog :: createDownloadingTab( ) |
---|
552 | { |
---|
553 | const int iconSize( style( )->pixelMetric( QStyle :: PM_SmallIconSize ) ); |
---|
554 | const QFileIconProvider iconProvider; |
---|
555 | const QIcon folderIcon = iconProvider.icon( QFileIconProvider::Folder ); |
---|
556 | const QPixmap folderPixmap = folderIcon.pixmap( iconSize ); |
---|
557 | const QIcon fileIcon = iconProvider.icon( QFileIconProvider::File ); |
---|
558 | const QPixmap filePixmap = fileIcon.pixmap( iconSize ); |
---|
559 | |
---|
560 | QWidget * l; |
---|
561 | QPushButton * b; |
---|
562 | HIG * hig = new HIG( this ); |
---|
563 | hig->addSectionTitle( tr( "Adding" ) ); |
---|
564 | |
---|
565 | l = checkBoxNew( tr( "Automatically add .torrent files &from:" ), Prefs::DIR_WATCH_ENABLED ); |
---|
566 | b = myWatchButton = new QPushButton; |
---|
567 | b->setIcon( folderPixmap ); |
---|
568 | b->setStyleSheet( QString::fromAscii( "text-align: left; padding-left: 5; padding-right: 5" ) ); |
---|
569 | connect( b, SIGNAL(clicked(bool)), this, SLOT(onWatchClicked(void)) ); |
---|
570 | hig->addRow( l, b ); |
---|
571 | enableBuddyWhenChecked( qobject_cast<QCheckBox*>(l), b ); |
---|
572 | |
---|
573 | hig->addWideControl( checkBoxNew( tr( "Show the Torrent Options &dialog" ), Prefs::OPTIONS_PROMPT ) ); |
---|
574 | |
---|
575 | hig->addWideControl( checkBoxNew( tr( "&Start added torrents" ), Prefs::START ) ); |
---|
576 | |
---|
577 | hig->addWideControl( checkBoxNew( tr( "Mo&ve the .torrent file to the trash" ), Prefs::TRASH_ORIGINAL ) ); |
---|
578 | |
---|
579 | b = myDestinationButton = new QPushButton; |
---|
580 | b->setIcon( folderPixmap ); |
---|
581 | b->setStyleSheet( QString::fromAscii( "text-align: left; padding-left: 5; padding-right: 5" ) ); |
---|
582 | connect( b, SIGNAL(clicked(bool)), this, SLOT(onDestinationClicked(void)) ); |
---|
583 | hig->addRow( tr( "Save to &Location:" ), b ); |
---|
584 | |
---|
585 | hig->addSectionDivider( ); |
---|
586 | hig->addSectionTitle( tr( "Download Queue" ) ); |
---|
587 | |
---|
588 | hig->addRow( tr( "Ma&ximum active downloads:" ), spinBoxNew( Prefs::DOWNLOAD_QUEUE_SIZE, 1, INT_MAX, 1 ) ); |
---|
589 | hig->addRow( tr( "Downloads sharing data in the last &N minutes are active:" ), spinBoxNew( Prefs::QUEUE_STALLED_MINUTES, 1, INT_MAX, 10 ) ); |
---|
590 | |
---|
591 | hig->addSectionDivider( ); |
---|
592 | hig->addSectionTitle( tr( "Incomplete" ) ); |
---|
593 | |
---|
594 | hig->addWideControl( checkBoxNew( tr( "Append \".&part\" to incomplete files' names" ), Prefs::RENAME_PARTIAL_FILES ) ); |
---|
595 | |
---|
596 | l = myIncompleteCheckbox = checkBoxNew( tr( "Keep &incomplete files in:" ), Prefs::INCOMPLETE_DIR_ENABLED ); |
---|
597 | b = myIncompleteButton = new QPushButton; |
---|
598 | b->setIcon( folderPixmap ); |
---|
599 | b->setStyleSheet( QString::fromAscii( "text-align: left; padding-left: 5; padding-right: 5" ) ); |
---|
600 | connect( b, SIGNAL(clicked(bool)), this, SLOT(onIncompleteClicked(void)) ); |
---|
601 | hig->addRow( myIncompleteCheckbox, b ); |
---|
602 | enableBuddyWhenChecked( qobject_cast<QCheckBox*>(l), b ); |
---|
603 | |
---|
604 | l = myTorrentDoneScriptCheckbox = checkBoxNew( tr( "Call scrip&t when torrent is completed:" ), Prefs::SCRIPT_TORRENT_DONE_ENABLED ); |
---|
605 | b = myTorrentDoneScriptButton = new QPushButton; |
---|
606 | b->setIcon( filePixmap ); |
---|
607 | b->setStyleSheet( QString::fromAscii( "text-align: left; padding-left: 5; padding-right: 5" ) ); |
---|
608 | connect( b, SIGNAL(clicked(bool)), this, SLOT(onScriptClicked(void)) ); |
---|
609 | hig->addRow( myTorrentDoneScriptCheckbox, b ); |
---|
610 | enableBuddyWhenChecked( qobject_cast<QCheckBox*>(l), b ); |
---|
611 | |
---|
612 | hig->finish( ); |
---|
613 | return hig; |
---|
614 | } |
---|
615 | |
---|
616 | /*** |
---|
617 | **** |
---|
618 | ***/ |
---|
619 | |
---|
620 | PrefsDialog :: PrefsDialog( Session& session, Prefs& prefs, QWidget * parent ): |
---|
621 | QDialog( parent ), |
---|
622 | myIsServer( session.isServer( ) ), |
---|
623 | mySession( session ), |
---|
624 | myPrefs( prefs ), |
---|
625 | myLayout( new QVBoxLayout( this ) ) |
---|
626 | { |
---|
627 | setWindowTitle( tr( "Transmission Preferences" ) ); |
---|
628 | |
---|
629 | QTabWidget * t = new QTabWidget( this ); |
---|
630 | t->addTab( createSpeedTab( ), tr( "Speed" ) ); |
---|
631 | t->addTab( createDownloadingTab( ), tr( "Downloading" ) ); |
---|
632 | t->addTab( createSeedingTab( ), tr( "Seeding" ) ); |
---|
633 | t->addTab( createPrivacyTab( ), tr( "Privacy" ) ); |
---|
634 | t->addTab( createNetworkTab( ), tr( "Network" ) ); |
---|
635 | t->addTab( createDesktopTab( ), tr( "Desktop" ) ); |
---|
636 | t->addTab( createRemoteTab(session), tr( "Remote" ) ); |
---|
637 | myLayout->addWidget( t ); |
---|
638 | |
---|
639 | QDialogButtonBox * buttons = new QDialogButtonBox( QDialogButtonBox::Close, Qt::Horizontal, this ); |
---|
640 | connect( buttons, SIGNAL(rejected()), this, SLOT(close()) ); // "close" triggers rejected |
---|
641 | myLayout->addWidget( buttons ); |
---|
642 | QWidget::setAttribute( Qt::WA_DeleteOnClose, true ); |
---|
643 | |
---|
644 | connect( &mySession, SIGNAL(sessionUpdated()), this, SLOT(sessionUpdated())); |
---|
645 | |
---|
646 | QList<int> keys; |
---|
647 | keys << Prefs :: RPC_ENABLED |
---|
648 | << Prefs :: ALT_SPEED_LIMIT_ENABLED |
---|
649 | << Prefs :: ALT_SPEED_LIMIT_TIME_ENABLED |
---|
650 | << Prefs :: ENCRYPTION |
---|
651 | << Prefs :: BLOCKLIST_ENABLED |
---|
652 | << Prefs :: DIR_WATCH |
---|
653 | << Prefs :: DOWNLOAD_DIR |
---|
654 | << Prefs :: INCOMPLETE_DIR |
---|
655 | << Prefs :: INCOMPLETE_DIR_ENABLED |
---|
656 | << Prefs :: SCRIPT_TORRENT_DONE_FILENAME; |
---|
657 | foreach( int key, keys ) |
---|
658 | refreshPref( key ); |
---|
659 | |
---|
660 | // if it's a remote session, disable the preferences |
---|
661 | // that don't work in remote sessions |
---|
662 | if( !myIsServer ) { |
---|
663 | foreach( QWidget * w, myUnsupportedWhenRemote ) { |
---|
664 | w->setToolTip( tr( "Not supported by remote sessions" ) ); |
---|
665 | w->setEnabled( false ); |
---|
666 | } |
---|
667 | } |
---|
668 | } |
---|
669 | |
---|
670 | PrefsDialog :: ~PrefsDialog( ) |
---|
671 | { |
---|
672 | } |
---|
673 | |
---|
674 | void |
---|
675 | PrefsDialog :: setPref( int key, const QVariant& v ) |
---|
676 | { |
---|
677 | myPrefs.set( key, v ); |
---|
678 | refreshPref( key ); |
---|
679 | } |
---|
680 | |
---|
681 | /*** |
---|
682 | **** |
---|
683 | ***/ |
---|
684 | |
---|
685 | void |
---|
686 | PrefsDialog :: sessionUpdated( ) |
---|
687 | { |
---|
688 | updateBlocklistLabel( ); |
---|
689 | } |
---|
690 | |
---|
691 | void |
---|
692 | PrefsDialog :: updateBlocklistLabel( ) |
---|
693 | { |
---|
694 | const int n = mySession.blocklistSize( ); |
---|
695 | myBlocklistLabel->setText( tr( "<i>Blocklist contains %Ln rules</i>", 0, n ) ); |
---|
696 | } |
---|
697 | |
---|
698 | void |
---|
699 | PrefsDialog :: refreshPref( int key ) |
---|
700 | { |
---|
701 | switch( key ) |
---|
702 | { |
---|
703 | case Prefs :: RPC_ENABLED: |
---|
704 | case Prefs :: RPC_WHITELIST_ENABLED: |
---|
705 | case Prefs :: RPC_AUTH_REQUIRED: { |
---|
706 | const bool enabled( myPrefs.getBool( Prefs::RPC_ENABLED ) ); |
---|
707 | const bool whitelist( myPrefs.getBool( Prefs::RPC_WHITELIST_ENABLED ) ); |
---|
708 | const bool auth( myPrefs.getBool( Prefs::RPC_AUTH_REQUIRED ) ); |
---|
709 | foreach( QWidget * w, myWebWhitelistWidgets ) w->setEnabled( enabled && whitelist ); |
---|
710 | foreach( QWidget * w, myWebAuthWidgets ) w->setEnabled( enabled && auth ); |
---|
711 | foreach( QWidget * w, myWebWidgets ) w->setEnabled( enabled ); |
---|
712 | break; |
---|
713 | } |
---|
714 | |
---|
715 | case Prefs :: ALT_SPEED_LIMIT_TIME_ENABLED: { |
---|
716 | const bool enabled = myPrefs.getBool( key ); |
---|
717 | foreach( QWidget * w, mySchedWidgets ) w->setEnabled( enabled ); |
---|
718 | break; |
---|
719 | } |
---|
720 | |
---|
721 | case Prefs :: BLOCKLIST_ENABLED: { |
---|
722 | const bool enabled = myPrefs.getBool( key ); |
---|
723 | foreach( QWidget * w, myBlockWidgets ) w->setEnabled( enabled ); |
---|
724 | break; |
---|
725 | } |
---|
726 | |
---|
727 | case Prefs :: DIR_WATCH: |
---|
728 | myWatchButton->setText( QFileInfo(myPrefs.getString(Prefs::DIR_WATCH)).fileName() ); |
---|
729 | break; |
---|
730 | |
---|
731 | case Prefs :: SCRIPT_TORRENT_DONE_FILENAME: { |
---|
732 | const QString path( myPrefs.getString( key ) ); |
---|
733 | myTorrentDoneScriptButton->setText( QFileInfo(path).fileName() ); |
---|
734 | break; |
---|
735 | } |
---|
736 | |
---|
737 | case Prefs :: PEER_PORT: |
---|
738 | myPortLabel->setText( tr( "Status unknown" ) ); |
---|
739 | myPortButton->setEnabled( true ); |
---|
740 | break; |
---|
741 | |
---|
742 | case Prefs :: DOWNLOAD_DIR: { |
---|
743 | QString path( myPrefs.getString( key ) ); |
---|
744 | myDestinationButton->setText( QFileInfo(path).fileName() ); |
---|
745 | break; |
---|
746 | } |
---|
747 | |
---|
748 | case Prefs :: INCOMPLETE_DIR: { |
---|
749 | QString path( myPrefs.getString( key ) ); |
---|
750 | myIncompleteButton->setText( QFileInfo(path).fileName() ); |
---|
751 | break; |
---|
752 | } |
---|
753 | |
---|
754 | case Prefs :: INCOMPLETE_DIR_ENABLED: { |
---|
755 | const bool enabled = myPrefs.getBool( key ); |
---|
756 | myIncompleteButton->setEnabled( enabled ); |
---|
757 | break; |
---|
758 | } |
---|
759 | |
---|
760 | default: |
---|
761 | break; |
---|
762 | } |
---|
763 | |
---|
764 | key2widget_t::iterator it( myWidgets.find( key ) ); |
---|
765 | if( it != myWidgets.end( ) ) |
---|
766 | { |
---|
767 | QWidget * w( it.value( ) ); |
---|
768 | QCheckBox * checkBox; |
---|
769 | QSpinBox * spin; |
---|
770 | QDoubleSpinBox * doubleSpin; |
---|
771 | QTimeEdit * timeEdit; |
---|
772 | QLineEdit * lineEdit; |
---|
773 | |
---|
774 | if(( checkBox = qobject_cast<QCheckBox*>(w))) |
---|
775 | { |
---|
776 | checkBox->setChecked( myPrefs.getBool( key ) ); |
---|
777 | } |
---|
778 | else if(( spin = qobject_cast<QSpinBox*>(w))) |
---|
779 | { |
---|
780 | spin->setValue( myPrefs.getInt( key ) ); |
---|
781 | } |
---|
782 | else if(( doubleSpin = qobject_cast<QDoubleSpinBox*>(w))) |
---|
783 | { |
---|
784 | doubleSpin->setValue( myPrefs.getDouble( key ) ); |
---|
785 | } |
---|
786 | else if(( timeEdit = qobject_cast<QTimeEdit*>(w))) |
---|
787 | { |
---|
788 | const int minutes( myPrefs.getInt( key ) ); |
---|
789 | timeEdit->setTime( QTime().addSecs( minutes * 60 ) ); |
---|
790 | } |
---|
791 | else if(( lineEdit = qobject_cast<QLineEdit*>(w))) |
---|
792 | { |
---|
793 | lineEdit->setText( myPrefs.getString( key ) ); |
---|
794 | } |
---|
795 | else if( key == Prefs::ENCRYPTION ) |
---|
796 | { |
---|
797 | QComboBox * comboBox( qobject_cast<QComboBox*>( w ) ); |
---|
798 | const int index = comboBox->findData( myPrefs.getInt( key ) ); |
---|
799 | comboBox->setCurrentIndex( index ); |
---|
800 | } |
---|
801 | } |
---|
802 | } |
---|
803 | |
---|
804 | bool |
---|
805 | PrefsDialog :: isAllowed( int key ) const |
---|
806 | { |
---|
807 | Q_UNUSED( key ); |
---|
808 | |
---|
809 | return true; |
---|
810 | } |
---|