source: trunk/gtk/tr-prefs.c @ 13796

Last change on this file since 13796 was 13796, checked in by jordan, 8 years ago

re-sync the GTK+ and Qt clients' prefs dialogs.

  • Property svn:keywords set to Date Rev Author Id
File size: 43.6 KB
Line 
1/*
2 * This file Copyright (C) Mnemosyne LLC
3 *
4 * This file is licensed by the GPL version 2. Works owned by the
5 * Transmission project are granted a special exemption to clause 2 (b)
6 * so that the bulk of its code can remain under the MIT license.
7 * This exemption does not extend to derived works not owned by
8 * the Transmission project.
9 *
10 * $Id: tr-prefs.c 13796 2013-01-16 21:42:03Z jordan $
11 */
12
13#include <ctype.h> /* isspace */
14#include <limits.h> /* USHRT_MAX */
15#include <string.h> /* strcmp () */
16#include <unistd.h>
17#include <glib/gi18n.h>
18#include <gtk/gtk.h>
19#include <libtransmission/transmission.h>
20#include <libtransmission/utils.h>
21#include <libtransmission/version.h>
22#include "conf.h"
23#include "hig.h"
24#include "tr-core.h"
25#include "tr-prefs.h"
26#include "util.h"
27
28/**
29***
30**/
31
32#define PREF_KEY "pref-key"
33
34static void
35response_cb (GtkDialog *     dialog,
36             int             response,
37             gpointer unused UNUSED)
38{
39    if (response == GTK_RESPONSE_HELP)
40    {
41        char * uri = g_strconcat (gtr_get_help_uri (), "/html/preferences.html", NULL);
42        gtr_open_uri (uri);
43        g_free (uri);
44    }
45
46    if (response == GTK_RESPONSE_CLOSE)
47        gtk_widget_destroy (GTK_WIDGET (dialog));
48}
49
50static void
51toggled_cb (GtkToggleButton * w,
52            gpointer          core)
53{
54    const tr_quark key = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (w), PREF_KEY));
55    const gboolean flag = gtk_toggle_button_get_active (w);
56
57    gtr_core_set_pref_bool (TR_CORE (core), key, flag);
58}
59
60static GtkWidget*
61new_check_button (const char      * mnemonic,
62                  const tr_quark    key,
63                  gpointer          core)
64{
65    GtkWidget * w = gtk_check_button_new_with_mnemonic (mnemonic);
66    g_object_set_data (G_OBJECT(w), PREF_KEY, GINT_TO_POINTER(key));
67    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w),
68                                 gtr_pref_flag_get (key));
69    g_signal_connect (w, "toggled", G_CALLBACK (toggled_cb), core);
70    return w;
71}
72
73#define IDLE_DATA "idle-data"
74
75struct spin_idle_data
76{
77    gpointer    core;
78    GTimer *    last_change;
79    gboolean    isDouble;
80};
81
82static void
83spin_idle_data_free (gpointer gdata)
84{
85    struct spin_idle_data * data = gdata;
86
87    g_timer_destroy (data->last_change);
88    g_free (data);
89}
90
91static gboolean
92spun_cb_idle (gpointer spin)
93{
94    gboolean keep_waiting = TRUE;
95    GObject * o = G_OBJECT (spin);
96    struct spin_idle_data * data = g_object_get_data (o, IDLE_DATA);
97
98    /* has the user stopped making changes? */
99    if (g_timer_elapsed (data->last_change, NULL) > 0.33f)
100    {
101        /* update the core */
102        const tr_quark key = GPOINTER_TO_INT (g_object_get_data (o, PREF_KEY));
103
104        if (data->isDouble)
105        {
106            const double value = gtk_spin_button_get_value (GTK_SPIN_BUTTON (spin));
107            gtr_core_set_pref_double (TR_CORE (data->core), key, value);
108        }
109        else
110        {
111            const int value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spin));
112            gtr_core_set_pref_int (TR_CORE (data->core), key, value);
113        }
114
115        /* cleanup */
116        g_object_set_data (o, IDLE_DATA, NULL);
117        keep_waiting = FALSE;
118        g_object_unref (G_OBJECT (o));
119    }
120
121    return keep_waiting;
122}
123
124static void
125spun_cb (GtkSpinButton * w, gpointer core, gboolean isDouble)
126{
127    /* user may be spinning through many values, so let's hold off
128       for a moment to keep from flooding the core with changes */
129    GObject * o = G_OBJECT (w);
130    struct spin_idle_data * data = g_object_get_data (o, IDLE_DATA);
131
132    if (data == NULL)
133    {
134        data = g_new (struct spin_idle_data, 1);
135        data->core = core;
136        data->last_change = g_timer_new ();
137        data->isDouble = isDouble;
138        g_object_set_data_full (o, IDLE_DATA, data, spin_idle_data_free);
139        g_object_ref (G_OBJECT (o));
140        gdk_threads_add_timeout_seconds (1, spun_cb_idle, w);
141    }
142    g_timer_start (data->last_change);
143}
144
145static void
146spun_cb_int (GtkSpinButton * w, gpointer core)
147{
148    spun_cb (w, core, FALSE);
149}
150
151static void
152spun_cb_double (GtkSpinButton * w, gpointer core)
153{
154    spun_cb (w, core, TRUE);
155}
156
157static GtkWidget*
158new_spin_button (const tr_quark  key,
159                 gpointer        core,
160                 int             low,
161                 int             high,
162                 int             step)
163{
164    GtkWidget * w = gtk_spin_button_new_with_range (low, high, step);
165    g_object_set_data (G_OBJECT(w), PREF_KEY, GINT_TO_POINTER(key));
166    gtk_spin_button_set_digits (GTK_SPIN_BUTTON (w), 0);
167    gtk_spin_button_set_value (GTK_SPIN_BUTTON (w), gtr_pref_int_get (key));
168    g_signal_connect (w, "value-changed", G_CALLBACK (spun_cb_int), core);
169    return w;
170}
171
172static GtkWidget*
173new_spin_button_double (const tr_quark  key,
174                        gpointer        core,
175                        double          low,
176                        double          high,
177                        double          step)
178{
179    GtkWidget * w = gtk_spin_button_new_with_range (low, high, step);
180    g_object_set_data (G_OBJECT(w), PREF_KEY, GINT_TO_POINTER(key));
181    gtk_spin_button_set_digits (GTK_SPIN_BUTTON (w), 2);
182    gtk_spin_button_set_value (GTK_SPIN_BUTTON (w), gtr_pref_double_get (key));
183    g_signal_connect (w, "value-changed", G_CALLBACK (spun_cb_double), core);
184    return w;
185}
186
187static void
188entry_changed_cb (GtkEntry * w, gpointer core)
189{
190  const tr_quark key = GPOINTER_TO_INT (g_object_get_data (G_OBJECT(w), PREF_KEY));
191  const char * value = gtk_entry_get_text (w);
192
193  gtr_core_set_pref (TR_CORE(core), key, value);
194}
195
196static GtkWidget*
197new_entry (const tr_quark  key,
198           gpointer        core)
199{
200  GtkWidget * w = gtk_entry_new ();
201  const char * value = gtr_pref_string_get (key);
202
203  if (value)
204    gtk_entry_set_text (GTK_ENTRY (w), value);
205
206  g_object_set_data (G_OBJECT (w), PREF_KEY, GINT_TO_POINTER(key));
207  g_signal_connect (w, "changed", G_CALLBACK (entry_changed_cb), core);
208  return w;
209}
210
211static void
212chosen_cb (GtkFileChooser * w, gpointer core)
213{
214  const tr_quark key = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (w), PREF_KEY));
215  char * value = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (w));
216  gtr_core_set_pref (TR_CORE (core), key, value);
217  g_free (value);
218}
219
220static GtkWidget*
221new_path_chooser_button (const tr_quark key, gpointer core)
222{
223  GtkWidget *  w = gtk_file_chooser_button_new (NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
224  const char * path = gtr_pref_string_get (key);
225  g_object_set_data (G_OBJECT (w), PREF_KEY, GINT_TO_POINTER(key));
226  g_signal_connect (w, "selection-changed", G_CALLBACK (chosen_cb), core);
227
228  if (path != NULL)
229    gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (w), path);
230
231  return w;
232}
233
234static GtkWidget*
235new_file_chooser_button (const tr_quark key, gpointer core)
236{
237  GtkWidget *  w = gtk_file_chooser_button_new (NULL, GTK_FILE_CHOOSER_ACTION_OPEN);
238  const char * path = gtr_pref_string_get (key);
239  g_object_set_data (G_OBJECT(w), PREF_KEY, GINT_TO_POINTER(key));
240  if (path != NULL)
241    gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (w), path);
242  g_signal_connect (w, "selection-changed", G_CALLBACK (chosen_cb), core);
243  return w;
244}
245
246static void
247target_cb (GtkWidget * tb, gpointer target)
248{
249  const gboolean b = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (tb));
250
251  gtk_widget_set_sensitive (GTK_WIDGET (target), b);
252}
253
254/****
255*****  Download Tab
256****/
257
258static GtkWidget*
259downloadingPage (GObject * core)
260{
261  GtkWidget * t;
262  GtkWidget * w;
263  GtkWidget * l;
264  const char * s;
265  guint row = 0;
266
267  t = hig_workarea_create ();
268  hig_workarea_add_section_title (t, &row, C_("Gerund", "Adding"));
269
270    s = _("Automatically add .torrent files _from:");
271    l = new_check_button (s, TR_KEY_watch_dir_enabled, core);
272    w = new_path_chooser_button (TR_KEY_watch_dir, core);
273    gtk_widget_set_sensitive (GTK_WIDGET (w), gtr_pref_flag_get (TR_KEY_watch_dir_enabled));
274    g_signal_connect (l, "toggled", G_CALLBACK (target_cb), w);
275    hig_workarea_add_row_w (t, &row, l, w, NULL);
276
277    s = _("Show the Torrent Options _dialog");
278    w = new_check_button (s, TR_KEY_show_options_window, core);
279    hig_workarea_add_wide_control (t, &row, w);
280
281    s = _("_Start added torrents");
282    w = new_check_button (s, TR_KEY_start_added_torrents, core);
283    hig_workarea_add_wide_control (t, &row, w);
284
285    s = _("Mo_ve .torrent file to the trash");
286    w = new_check_button (s, TR_KEY_trash_original_torrent_files, core);
287    hig_workarea_add_wide_control (t, &row, w);
288
289    w = new_path_chooser_button (TR_KEY_download_dir, core);
290    hig_workarea_add_row (t, &row, _("Save to _Location:"), w, NULL);
291
292  hig_workarea_add_section_divider (t, &row);
293  hig_workarea_add_section_title (t, &row, _("Download Queue"));
294
295    s = _("Ma_ximum active downloads:");
296    w = new_spin_button (TR_KEY_download_queue_size, core, 0, INT_MAX, 1);
297    hig_workarea_add_row (t, &row, s, w, NULL);
298
299    s = _("Downloads sharing data in the last _N minutes are active:");
300    w = new_spin_button (TR_KEY_queue_stalled_minutes, core, 1, INT_MAX, 15);
301    hig_workarea_add_row (t, &row, s, w, NULL);
302
303  hig_workarea_add_section_divider (t, &row);
304  hig_workarea_add_section_title (t, &row, _("Incomplete"));
305
306    s = _("Append \"._part\" to incomplete files' names");
307    w = new_check_button (s, TR_KEY_rename_partial_files, core);
308    hig_workarea_add_wide_control (t, &row, w);
309
310    s = _("Keep _incomplete torrents in:");
311    l = new_check_button (s, TR_KEY_incomplete_dir_enabled, core);
312    w = new_path_chooser_button (TR_KEY_incomplete_dir, core);
313    gtk_widget_set_sensitive (GTK_WIDGET (w), gtr_pref_flag_get (TR_KEY_incomplete_dir_enabled));
314    g_signal_connect (l, "toggled", G_CALLBACK (target_cb), w);
315    hig_workarea_add_row_w (t, &row, l, w, NULL);
316
317    s = _("Call scrip_t when torrent is completed:");
318    l = new_check_button (s, TR_KEY_script_torrent_done_enabled, core);
319    w = new_file_chooser_button (TR_KEY_script_torrent_done_filename, core);
320    gtk_widget_set_sensitive (GTK_WIDGET (w), gtr_pref_flag_get (TR_KEY_script_torrent_done_enabled));
321    g_signal_connect (l, "toggled", G_CALLBACK (target_cb), w);
322    hig_workarea_add_row_w (t, &row, l, w, NULL);
323
324  return t;
325}
326
327/****
328*****  Torrent Tab
329****/
330
331static GtkWidget*
332seedingPage (GObject * core)
333{
334  GtkWidget * t;
335  GtkWidget * w;
336  GtkWidget * w2;
337  const char * s;
338  guint row = 0;
339
340  t = hig_workarea_create ();
341  hig_workarea_add_section_title (t, &row, _("Limits"));
342
343    s = _("Stop seeding at _ratio:");
344    w = new_check_button (s, TR_KEY_ratio_limit_enabled, core);
345    w2 = new_spin_button_double (TR_KEY_ratio_limit, core, 0, 1000, .05);
346    gtk_widget_set_sensitive (GTK_WIDGET (w2), gtr_pref_flag_get (TR_KEY_ratio_limit_enabled));
347    g_signal_connect (w, "toggled", G_CALLBACK (target_cb), w2);
348    hig_workarea_add_row_w (t, &row, w, w2, NULL);
349
350    s = _("Stop seeding if idle for _N minutes:");
351    w = new_check_button (s, TR_KEY_idle_seeding_limit_enabled, core);
352    w2 = new_spin_button (TR_KEY_idle_seeding_limit, core, 1, 9999, 5);
353    gtk_widget_set_sensitive (GTK_WIDGET (w2), gtr_pref_flag_get (TR_KEY_idle_seeding_limit_enabled));
354    g_signal_connect (w, "toggled", G_CALLBACK (target_cb), w2);
355    hig_workarea_add_row_w (t, &row, w, w2, NULL);
356
357  return t;
358}
359
360/****
361*****  Desktop Tab
362****/
363
364static GtkWidget*
365desktopPage (GObject * core)
366{
367    GtkWidget * t;
368    GtkWidget * w;
369    const char * s;
370    guint row = 0;
371
372    t = hig_workarea_create ();
373    hig_workarea_add_section_title (t, &row, _("Desktop"));
374
375    s = _("_Inhibit hibernation when torrents are active");
376    w = new_check_button (s, TR_KEY_inhibit_desktop_hibernation, core);
377    hig_workarea_add_wide_control (t, &row, w);
378
379    s = _("Show Transmission icon in the _notification area");
380    w = new_check_button (s, TR_KEY_show_notification_area_icon, core);
381    hig_workarea_add_wide_control (t, &row, w);
382
383    hig_workarea_add_section_divider (t, &row);
384    hig_workarea_add_section_title (t, &row, _("Notification"));
385
386    s = _("Show a notification when torrents are a_dded");
387    w = new_check_button (s, TR_KEY_torrent_added_notification_enabled, core);
388    hig_workarea_add_wide_control (t, &row, w);
389
390    s = _("Show a notification when torrents _finish");
391    w = new_check_button (s, TR_KEY_torrent_complete_notification_enabled, core);
392    hig_workarea_add_wide_control (t, &row, w);
393
394    s = _("Play a _sound when torrents finish");
395    w = new_check_button (s, TR_KEY_torrent_complete_sound_enabled, core);
396    hig_workarea_add_wide_control (t, &row, w);
397
398    return t;
399}
400
401/****
402*****  Peer Tab
403****/
404
405struct blocklist_data
406{
407    gulong      updateBlocklistTag;
408    GtkWidget * updateBlocklistButton;
409    GtkWidget * updateBlocklistDialog;
410    GtkWidget * label;
411    GtkWidget * check;
412    TrCore    * core;
413};
414
415static void
416updateBlocklistText (GtkWidget * w, TrCore * core)
417{
418    char buf1[512];
419    char buf2[512];
420    const int n = tr_blocklistGetRuleCount (gtr_core_session (core));
421    g_snprintf (buf1, sizeof (buf1),
422                ngettext ("Blocklist contains %'d rule",
423                          "Blocklist contains %'d rules", n), n);
424    g_snprintf (buf2, sizeof (buf2), "<i>%s</i>", buf1);
425    gtk_label_set_markup (GTK_LABEL (w), buf2);
426}
427
428/* prefs dialog is being destroyed, so stop listening to blocklist updates */
429static void
430privacyPageDestroyed (gpointer gdata, GObject * dead UNUSED)
431{
432    struct blocklist_data * data = gdata;
433    if (data->updateBlocklistTag > 0)
434        g_signal_handler_disconnect (data->core, data->updateBlocklistTag);
435    g_free (data);
436}
437
438/* user hit "close" in the blocklist-update dialog */
439static void
440onBlocklistUpdateResponse (GtkDialog * dialog, gint response UNUSED, gpointer gdata)
441{
442    struct blocklist_data * data = gdata;
443    gtk_widget_destroy (GTK_WIDGET (dialog));
444    gtk_widget_set_sensitive (data->updateBlocklistButton, TRUE);
445    data->updateBlocklistDialog = NULL;
446    g_signal_handler_disconnect (data->core, data->updateBlocklistTag);
447}
448
449/* core says the blocklist was updated */
450static void
451onBlocklistUpdated (TrCore * core, int n, gpointer gdata)
452{
453    const bool success = n >= 0;
454    const int count = n >=0 ? n : tr_blocklistGetRuleCount (gtr_core_session (core));
455    const char * s = ngettext ("Blocklist has %'d rule.", "Blocklist has %'d rules.", count);
456    struct blocklist_data * data = gdata;
457    GtkMessageDialog * d = GTK_MESSAGE_DIALOG (data->updateBlocklistDialog);
458    gtk_widget_set_sensitive (data->updateBlocklistButton, TRUE);
459    gtk_message_dialog_set_markup (d, success ? _("<b>Update succeeded!</b>") : _("<b>Unable to update.</b>"));
460    gtk_message_dialog_format_secondary_text (d, s, count);
461    updateBlocklistText (data->label, core);
462}
463
464/* user pushed a button to update the blocklist */
465static void
466onBlocklistUpdate (GtkButton * w, gpointer gdata)
467{
468    GtkWidget * d;
469    struct blocklist_data * data = gdata;
470    d = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (w))),
471                                GTK_DIALOG_DESTROY_WITH_PARENT,
472                                GTK_MESSAGE_INFO,
473                                GTK_BUTTONS_CLOSE,
474                                "%s", _("Update Blocklist"));
475    gtk_widget_set_sensitive (data->updateBlocklistButton, FALSE);
476    gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (d), "%s", _("Getting new blocklist
"));
477    data->updateBlocklistDialog = d;
478    g_signal_connect (d, "response", G_CALLBACK (onBlocklistUpdateResponse), data);
479    gtk_widget_show (d);
480    gtr_core_blocklist_update (data->core);
481    data->updateBlocklistTag = g_signal_connect (data->core, "blocklist-updated", G_CALLBACK (onBlocklistUpdated), data);
482}
483
484static void
485on_blocklist_url_changed (GtkEditable * e, gpointer gbutton)
486{
487  gchar * url = gtk_editable_get_chars (e, 0, -1);
488  const gboolean err = tr_urlParse (url, -1, NULL, NULL, NULL, NULL);
489  gtk_widget_set_sensitive (GTK_WIDGET (gbutton), !err);
490  g_free (url);
491}
492
493static void
494onIntComboChanged (GtkComboBox * combo_box, gpointer core)
495{
496  const int val = gtr_combo_box_get_active_enum (combo_box);
497  const tr_quark key = GPOINTER_TO_INT (g_object_get_data (G_OBJECT(combo_box), PREF_KEY));
498  gtr_core_set_pref_int (TR_CORE (core), key, val);
499}
500
501static GtkWidget*
502new_encryption_combo (GObject * core, const tr_quark key)
503{
504  GtkWidget * w = gtr_combo_box_new_enum (_("Allow encryption"),   TR_CLEAR_PREFERRED,
505                                          _("Prefer encryption"),  TR_ENCRYPTION_PREFERRED,
506                                          _("Require encryption"), TR_ENCRYPTION_REQUIRED,
507                                          NULL);
508  gtr_combo_box_set_active_enum (GTK_COMBO_BOX (w), gtr_pref_int_get (key));
509  g_object_set_data (G_OBJECT (w), PREF_KEY, GINT_TO_POINTER(key));
510  g_signal_connect (w, "changed", G_CALLBACK (onIntComboChanged), core);
511  return w;
512}
513
514static GtkWidget*
515privacyPage (GObject * core)
516{
517  const char * s;
518  GtkWidget * t;
519  GtkWidget * w;
520  GtkWidget * b;
521  GtkWidget * h;
522  GtkWidget * e;
523  struct blocklist_data * data;
524  guint row = 0;
525
526  data = g_new0 (struct blocklist_data, 1);
527  data->core = TR_CORE (core);
528
529  t = hig_workarea_create ();
530  hig_workarea_add_section_title (t, &row, _("Privacy"));
531
532    s = _("_Encryption mode:");
533    w = new_encryption_combo (core, TR_KEY_encryption);
534    hig_workarea_add_row (t, &row, s, w, NULL);
535
536  hig_workarea_add_section_divider (t, &row);
537  hig_workarea_add_section_title (t, &row, _("Blocklist"));
538
539    b = new_check_button (_("Enable _blocklist:"), TR_KEY_blocklist_enabled, core);
540    e = new_entry (TR_KEY_blocklist_url, core);
541    gtk_widget_set_size_request (e, 300, -1);
542    hig_workarea_add_row_w (t, &row, b, e, NULL);
543    data->check = b;
544    g_signal_connect (b, "toggled", G_CALLBACK (target_cb), e);
545    target_cb (b, e);
546
547    w = gtk_label_new ("");
548    gtk_misc_set_alignment (GTK_MISC (w), 0.0f, 0.5f);
549    updateBlocklistText (w, TR_CORE (core));
550    data->label = w;
551    h = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, GUI_PAD_BIG);
552    gtk_box_pack_start (GTK_BOX (h), w, TRUE, TRUE, 0);
553    b = data->updateBlocklistButton = gtk_button_new_with_mnemonic (_("_Update"));
554    g_object_set_data (G_OBJECT (b), "session", gtr_core_session (TR_CORE (core)));
555    g_signal_connect (b, "clicked", G_CALLBACK (onBlocklistUpdate), data);
556    g_signal_connect (data->check, "toggled", G_CALLBACK (target_cb), b); target_cb (data->check, b);
557    gtk_box_pack_start (GTK_BOX (h), b, FALSE, FALSE, 0);
558    g_signal_connect (data->check, "toggled", G_CALLBACK (target_cb), w); target_cb (data->check, w);
559    hig_workarea_add_wide_control (t, &row, h);
560    g_signal_connect (e, "changed", G_CALLBACK (on_blocklist_url_changed), data->updateBlocklistButton);
561    on_blocklist_url_changed (GTK_EDITABLE (e), data->updateBlocklistButton);
562
563    s = _("Enable _automatic updates");
564    w = new_check_button (s, TR_KEY_blocklist_updates_enabled, core);
565    hig_workarea_add_wide_control (t, &row, w);
566    g_signal_connect (data->check, "toggled", G_CALLBACK (target_cb), w); target_cb (data->check, w);
567
568  g_object_weak_ref (G_OBJECT (t), privacyPageDestroyed, data);
569  return t;
570}
571
572/****
573*****  Remote Tab
574****/
575
576enum
577{
578    COL_ADDRESS,
579    N_COLS
580};
581
582static GtkTreeModel*
583whitelist_tree_model_new (const char * whitelist)
584{
585    int            i;
586    char **        rules;
587    GtkListStore * store = gtk_list_store_new (N_COLS,
588                                               G_TYPE_STRING,
589                                               G_TYPE_STRING);
590
591    rules = g_strsplit (whitelist, ",", 0);
592
593    for (i = 0; rules && rules[i]; ++i)
594    {
595        GtkTreeIter iter;
596        const char * s = rules[i];
597        while (isspace (*s)) ++s;
598        gtk_list_store_append (store, &iter);
599        gtk_list_store_set (store, &iter, COL_ADDRESS, s, -1);
600    }
601
602    g_strfreev (rules);
603    return GTK_TREE_MODEL (store);
604}
605
606struct remote_page
607{
608    TrCore *           core;
609    GtkTreeView *      view;
610    GtkListStore *     store;
611    GtkWidget *        remove_button;
612    GSList *           widgets;
613    GSList *           auth_widgets;
614    GSList *           whitelist_widgets;
615    GtkToggleButton *  rpc_tb;
616    GtkToggleButton *  auth_tb;
617    GtkToggleButton *  whitelist_tb;
618};
619
620static void
621refreshWhitelist (struct remote_page * page)
622{
623    GtkTreeIter iter;
624    GString * gstr = g_string_new (NULL);
625    GtkTreeModel * model = GTK_TREE_MODEL (page->store);
626
627    if (gtk_tree_model_iter_nth_child (model, &iter, NULL, 0)) do
628    {
629        char * address;
630        gtk_tree_model_get (model, &iter, COL_ADDRESS, &address, -1);
631        g_string_append (gstr, address);
632        g_string_append (gstr, ",");
633        g_free (address);
634    }
635    while (gtk_tree_model_iter_next (model, &iter));
636
637    g_string_truncate (gstr, gstr->len - 1); /* remove the trailing comma */
638
639    gtr_core_set_pref (page->core, TR_KEY_rpc_whitelist, gstr->str);
640
641    g_string_free (gstr, TRUE);
642}
643
644static void
645onAddressEdited (GtkCellRendererText  * r UNUSED,
646                 gchar *                  path_string,
647                 gchar *                  address,
648                 gpointer                 gpage)
649{
650    GtkTreeIter          iter;
651    struct remote_page * page = gpage;
652    GtkTreeModel *       model = GTK_TREE_MODEL (page->store);
653    GtkTreePath *        path = gtk_tree_path_new_from_string (path_string);
654
655    if (gtk_tree_model_get_iter (model, &iter, path))
656        gtk_list_store_set (page->store, &iter, COL_ADDRESS, address, -1);
657
658    gtk_tree_path_free (path);
659    refreshWhitelist (page);
660}
661
662static void
663onAddWhitelistClicked (GtkButton * b UNUSED,
664                 gpointer      gpage)
665{
666    GtkTreeIter          iter;
667    GtkTreePath *        path;
668    struct remote_page * page = gpage;
669
670    gtk_list_store_append (page->store, &iter);
671    gtk_list_store_set (page->store, &iter,
672                        COL_ADDRESS,  "0.0.0.0",
673                        -1);
674
675    path = gtk_tree_model_get_path (GTK_TREE_MODEL (page->store), &iter);
676    gtk_tree_view_set_cursor (
677        page->view, path,
678        gtk_tree_view_get_column (page->view, COL_ADDRESS),
679        TRUE);
680    gtk_tree_path_free (path);
681}
682
683static void
684onRemoveWhitelistClicked (GtkButton * b UNUSED,
685                    gpointer      gpage)
686{
687    struct remote_page * page = gpage;
688    GtkTreeSelection *   sel = gtk_tree_view_get_selection (page->view);
689    GtkTreeIter          iter;
690
691    if (gtk_tree_selection_get_selected (sel, NULL, &iter))
692    {
693        gtk_list_store_remove (page->store, &iter);
694        refreshWhitelist (page);
695    }
696}
697
698static void
699refreshRPCSensitivity (struct remote_page * page)
700{
701    GSList *           l;
702    const int          rpc_active = gtk_toggle_button_get_active (
703        page->rpc_tb);
704    const int          auth_active = gtk_toggle_button_get_active (
705        page->auth_tb);
706    const int          whitelist_active = gtk_toggle_button_get_active (
707        page->whitelist_tb);
708    GtkTreeSelection * sel = gtk_tree_view_get_selection (page->view);
709    const int          have_addr =
710        gtk_tree_selection_get_selected (sel, NULL,
711                                         NULL);
712    const int          n_rules = gtk_tree_model_iter_n_children (
713        GTK_TREE_MODEL (page->store), NULL);
714
715    for (l = page->widgets; l != NULL; l = l->next)
716        gtk_widget_set_sensitive (GTK_WIDGET (l->data), rpc_active);
717
718    for (l = page->auth_widgets; l != NULL; l = l->next)
719        gtk_widget_set_sensitive (GTK_WIDGET (
720                                      l->data), rpc_active && auth_active);
721
722    for (l = page->whitelist_widgets; l != NULL; l = l->next)
723        gtk_widget_set_sensitive (GTK_WIDGET (l->data),
724                                  rpc_active && whitelist_active);
725
726    gtk_widget_set_sensitive (page->remove_button,
727                              rpc_active && have_addr && n_rules > 1);
728}
729
730static void
731onRPCToggled (GtkToggleButton * tb UNUSED,
732              gpointer             page)
733{
734    refreshRPCSensitivity (page);
735}
736
737static void
738onWhitelistSelectionChanged (GtkTreeSelection * sel UNUSED,
739                       gpointer               page)
740{
741    refreshRPCSensitivity (page);
742}
743
744static void
745onLaunchClutchCB (GtkButton * w UNUSED, gpointer data UNUSED)
746{
747  char * uri;
748  const int port = gtr_pref_int_get (TR_KEY_rpc_port);
749
750  uri = g_strdup_printf ("http://localhost:%d/", port);
751  gtr_open_uri (uri);
752  g_free (uri);
753}
754
755static void
756remotePageFree (gpointer gpage)
757{
758    struct remote_page * page = gpage;
759
760    g_slist_free (page->widgets);
761    g_slist_free (page->auth_widgets);
762    g_slist_free (page->whitelist_widgets);
763    g_free (page);
764}
765
766static GtkWidget*
767remotePage (GObject * core)
768{
769    GtkWidget * t;
770    GtkWidget * w;
771    GtkWidget * h;
772    const char * s;
773    guint row = 0;
774    struct remote_page * page = g_new0 (struct remote_page, 1);
775
776    page->core = TR_CORE (core);
777
778    t = hig_workarea_create ();
779    g_object_set_data_full (G_OBJECT (t), "page", page, remotePageFree);
780
781    hig_workarea_add_section_title (t, &row, _("Remote Control"));
782
783    /* "enabled" checkbutton */
784    s = _("Allow _remote access");
785    w = new_check_button (s, TR_KEY_rpc_enabled, core);
786    page->rpc_tb = GTK_TOGGLE_BUTTON (w);
787    g_signal_connect (w, "clicked", G_CALLBACK (onRPCToggled), page);
788    h = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, GUI_PAD_BIG);
789    gtk_box_pack_start (GTK_BOX (h), w, TRUE, TRUE, 0);
790    w = gtk_button_new_with_mnemonic (_("_Open web client"));
791    page->widgets = g_slist_prepend (page->widgets, w);
792    g_signal_connect (w, "clicked", G_CALLBACK (onLaunchClutchCB), NULL);
793    gtk_box_pack_start (GTK_BOX (h), w, FALSE, FALSE, 0);
794    hig_workarea_add_wide_control (t, &row, h);
795
796    /* port */
797    w = new_spin_button (TR_KEY_rpc_port, core, 0, USHRT_MAX, 1);
798    page->widgets = g_slist_prepend (page->widgets, w);
799    w = hig_workarea_add_row (t, &row, _("HTTP _port:"), w, NULL);
800    page->widgets = g_slist_prepend (page->widgets, w);
801
802    /* require authentication */
803    s = _("Use _authentication");
804    w = new_check_button (s, TR_KEY_rpc_authentication_required, core);
805    hig_workarea_add_wide_control (t, &row, w);
806    page->auth_tb = GTK_TOGGLE_BUTTON (w);
807    page->widgets = g_slist_prepend (page->widgets, w);
808    g_signal_connect (w, "clicked", G_CALLBACK (onRPCToggled), page);
809
810    /* username */
811    s = _("_Username:");
812    w = new_entry (TR_KEY_rpc_username, core);
813    page->auth_widgets = g_slist_prepend (page->auth_widgets, w);
814    w = hig_workarea_add_row (t, &row, s, w, NULL);
815    page->auth_widgets = g_slist_prepend (page->auth_widgets, w);
816
817    /* password */
818    s = _("Pass_word:");
819    w = new_entry (TR_KEY_rpc_password, core);
820    gtk_entry_set_visibility (GTK_ENTRY (w), FALSE);
821    page->auth_widgets = g_slist_prepend (page->auth_widgets, w);
822    w = hig_workarea_add_row (t, &row, s, w, NULL);
823    page->auth_widgets = g_slist_prepend (page->auth_widgets, w);
824
825    /* require authentication */
826    s = _("Only allow these IP a_ddresses:");
827    w = new_check_button (s, TR_KEY_rpc_whitelist_enabled, core);
828    hig_workarea_add_wide_control (t, &row, w);
829    page->whitelist_tb = GTK_TOGGLE_BUTTON (w);
830    page->widgets = g_slist_prepend (page->widgets, w);
831    g_signal_connect (w, "clicked", G_CALLBACK (onRPCToggled), page);
832
833    /* access control list */
834    {
835        const char *        val = gtr_pref_string_get (TR_KEY_rpc_whitelist);
836        GtkTreeModel *      m = whitelist_tree_model_new (val);
837        GtkTreeViewColumn * c;
838        GtkCellRenderer *   r;
839        GtkTreeSelection *  sel;
840        GtkTreeView *       v;
841        GtkWidget *         w;
842        GtkWidget *         h;
843
844        page->store = GTK_LIST_STORE (m);
845        w = gtk_tree_view_new_with_model (m);
846        g_signal_connect (w, "button-release-event",
847                          G_CALLBACK (on_tree_view_button_released), NULL);
848
849        page->whitelist_widgets = g_slist_prepend (page->whitelist_widgets, w);
850        v = page->view = GTK_TREE_VIEW (w);
851        gtk_widget_set_tooltip_text (w, _("IP addresses may use wildcards, such as 192.168.*.*"));
852        sel = gtk_tree_view_get_selection (v);
853        g_signal_connect (sel, "changed",
854                          G_CALLBACK (onWhitelistSelectionChanged), page);
855        g_object_unref (G_OBJECT (m));
856        gtk_tree_view_set_headers_visible (v, TRUE);
857        w = gtk_frame_new (NULL);
858        gtk_frame_set_shadow_type (GTK_FRAME (w), GTK_SHADOW_IN);
859        gtk_container_add (GTK_CONTAINER (w), GTK_WIDGET (v));
860
861        /* ip address column */
862        r = gtk_cell_renderer_text_new ();
863        g_signal_connect (r, "edited",
864                          G_CALLBACK (onAddressEdited), page);
865        g_object_set (G_OBJECT (r), "editable", TRUE, NULL);
866        c = gtk_tree_view_column_new_with_attributes (NULL, r,
867                                                      "text", COL_ADDRESS,
868                                                      NULL);
869        gtk_tree_view_column_set_expand (c, TRUE);
870        gtk_tree_view_append_column (v, c);
871        gtk_tree_view_set_headers_visible (v, FALSE);
872
873        s = _("Addresses:");
874        w = hig_workarea_add_row (t, &row, s, w, NULL);
875        gtk_misc_set_alignment (GTK_MISC (w), 0.0f, 0.0f);
876        gtk_misc_set_padding (GTK_MISC (w), 0, GUI_PAD);
877        page->whitelist_widgets = g_slist_prepend (page->whitelist_widgets, w);
878
879        h = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, GUI_PAD);
880        w = gtk_button_new_from_stock (GTK_STOCK_REMOVE);
881        g_signal_connect (w, "clicked", G_CALLBACK (
882                              onRemoveWhitelistClicked), page);
883        page->remove_button = w;
884        onWhitelistSelectionChanged (sel, page);
885        gtk_box_pack_start (GTK_BOX (h), w, TRUE, TRUE, 0);
886        w = gtk_button_new_from_stock (GTK_STOCK_ADD);
887        page->whitelist_widgets = g_slist_prepend (page->whitelist_widgets, w);
888        g_signal_connect (w, "clicked", G_CALLBACK (onAddWhitelistClicked), page);
889        gtk_box_pack_start (GTK_BOX (h), w, TRUE, TRUE, 0);
890        w = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
891        gtk_box_pack_start (GTK_BOX (w), gtk_alignment_new (0, 0, 0, 0),
892                            TRUE, TRUE, 0);
893        gtk_box_pack_start (GTK_BOX (w), h, FALSE, FALSE, 0);
894        hig_workarea_add_wide_control (t, &row, w);
895    }
896
897    refreshRPCSensitivity (page);
898    return t;
899}
900
901/****
902*****  Bandwidth Tab
903****/
904
905struct BandwidthPage
906{
907  TrCore *  core;
908  GSList *  sched_widgets;
909};
910
911static void
912refreshSchedSensitivity (struct BandwidthPage * p)
913{
914  GSList * l;
915  const gboolean sched_enabled = gtr_pref_flag_get (TR_KEY_alt_speed_time_enabled);
916
917  for (l=p->sched_widgets; l!=NULL; l=l->next)
918    gtk_widget_set_sensitive (GTK_WIDGET (l->data), sched_enabled);
919}
920
921static void
922onSchedToggled (GtkToggleButton * tb UNUSED,
923                gpointer             user_data)
924{
925    refreshSchedSensitivity (user_data);
926}
927
928static void
929onTimeComboChanged (GtkComboBox * w, gpointer core)
930{
931  GtkTreeIter iter;
932
933  if (gtk_combo_box_get_active_iter (w, &iter))
934    {
935      int val = 0;
936      const tr_quark key = GPOINTER_TO_INT (g_object_get_data (G_OBJECT(w), PREF_KEY));
937      gtk_tree_model_get (gtk_combo_box_get_model(w), &iter, 0, &val, -1);
938      gtr_core_set_pref_int (TR_CORE(core), key, val);
939    }
940}
941
942static GtkWidget*
943new_time_combo (GObject * core, const tr_quark key)
944{
945  int val;
946  int i;
947  GtkWidget * w;
948  GtkCellRenderer * r;
949  GtkListStore * store;
950
951  /* build a store at 15 minute intervals */
952  store = gtk_list_store_new (2, G_TYPE_INT, G_TYPE_STRING);
953  for (i=0; i<60*24; i+=15)
954    {
955      char buf[128];
956      GtkTreeIter iter;
957      struct tm   tm;
958      tm.tm_hour = i / 60;
959      tm.tm_min = i % 60;
960      tm.tm_sec = 0;
961      strftime (buf, sizeof (buf), "%H:%M", &tm);
962      gtk_list_store_append (store, &iter);
963      gtk_list_store_set (store, &iter, 0, i, 1, buf, -1);
964    }
965
966  /* build the widget */
967  w = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
968  gtk_combo_box_set_wrap_width (GTK_COMBO_BOX (w), 4);
969  r = gtk_cell_renderer_text_new ();
970  gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (w), r, TRUE);
971  gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (w), r, "text", 1, NULL);
972  g_object_set_data (G_OBJECT(w), PREF_KEY, GINT_TO_POINTER(key));
973  val = gtr_pref_int_get (key);
974  gtk_combo_box_set_active (GTK_COMBO_BOX (w), val / (15));
975  g_signal_connect (w, "changed", G_CALLBACK (onTimeComboChanged), core);
976
977  /* cleanup */
978  g_object_unref (G_OBJECT (store));
979  return w;
980}
981
982static GtkWidget*
983new_week_combo (GObject * core, const tr_quark key)
984{
985  GtkWidget * w = gtr_combo_box_new_enum (_("Every Day"), TR_SCHED_ALL,
986                                          _("Weekdays"),  TR_SCHED_WEEKDAY,
987                                          _("Weekends"),  TR_SCHED_WEEKEND,
988                                          _("Sunday"),    TR_SCHED_SUN,
989                                          _("Monday"),    TR_SCHED_MON,
990                                          _("Tuesday"),   TR_SCHED_TUES,
991                                          _("Wednesday"), TR_SCHED_WED,
992                                          _("Thursday"),  TR_SCHED_THURS,
993                                          _("Friday"),    TR_SCHED_FRI,
994                                          _("Saturday"),  TR_SCHED_SAT,
995                                          NULL);
996  gtr_combo_box_set_active_enum (GTK_COMBO_BOX (w), gtr_pref_int_get (key));
997  g_object_set_data (G_OBJECT(w), PREF_KEY, GINT_TO_POINTER(key));
998  g_signal_connect (w, "changed", G_CALLBACK (onIntComboChanged), core);
999  return w;
1000}
1001
1002static void
1003speedPageFree (gpointer gpage)
1004{
1005    struct BandwidthPage * page = gpage;
1006
1007    g_slist_free (page->sched_widgets);
1008    g_free (page);
1009}
1010
1011static GtkWidget*
1012speedPage (GObject * core)
1013{
1014    const char * s;
1015    GtkWidget * t;
1016    GtkWidget * l;
1017    GtkWidget * w, * w2, * h;
1018    char buf[512];
1019    guint row = 0;
1020    struct BandwidthPage * page = tr_new0 (struct BandwidthPage, 1);
1021
1022    page->core = TR_CORE (core);
1023
1024    t = hig_workarea_create ();
1025    hig_workarea_add_section_title (t, &row, _("Speed Limits"));
1026
1027        g_snprintf (buf, sizeof (buf), _("_Upload (%s):"), _ (speed_K_str));
1028        w = new_check_button (buf, TR_KEY_speed_limit_up_enabled, core);
1029        w2 = new_spin_button (TR_KEY_speed_limit_up, core, 0, INT_MAX, 5);
1030        gtk_widget_set_sensitive (GTK_WIDGET (w2), gtr_pref_flag_get (TR_KEY_speed_limit_up_enabled));
1031        g_signal_connect (w, "toggled", G_CALLBACK (target_cb), w2);
1032        hig_workarea_add_row_w (t, &row, w, w2, NULL);
1033
1034        g_snprintf (buf, sizeof (buf), _("_Download (%s):"), _ (speed_K_str));
1035        w = new_check_button (buf, TR_KEY_speed_limit_down_enabled, core);
1036        w2 = new_spin_button (TR_KEY_speed_limit_down, core, 0, INT_MAX, 5);
1037        gtk_widget_set_sensitive (GTK_WIDGET (w2), gtr_pref_flag_get (TR_KEY_speed_limit_down_enabled));
1038        g_signal_connect (w, "toggled", G_CALLBACK (target_cb), w2);
1039        hig_workarea_add_row_w (t, &row, w, w2, NULL);
1040
1041    hig_workarea_add_section_divider (t, &row);
1042    h = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, GUI_PAD);
1043    g_snprintf (buf, sizeof (buf), "<b>%s</b>", _("Alternative Speed Limits"));
1044    w = gtk_label_new (buf);
1045    gtk_misc_set_alignment (GTK_MISC (w), 0.0f, 0.5f);
1046    gtk_label_set_use_markup (GTK_LABEL (w), TRUE);
1047    gtk_box_pack_start (GTK_BOX (h), w, FALSE, FALSE, 0);
1048    w = gtk_image_new_from_stock ("alt-speed-on", -1);
1049    gtk_box_pack_start (GTK_BOX (h), w, FALSE, FALSE, 0);
1050    hig_workarea_add_section_title_widget (t, &row, h);
1051
1052        s = _("Override normal speed limits manually or at scheduled times");
1053        g_snprintf (buf, sizeof (buf), "<small>%s</small>", s);
1054        w = gtk_label_new (buf);
1055        gtk_label_set_use_markup (GTK_LABEL (w), TRUE);
1056        gtk_misc_set_alignment (GTK_MISC (w), 0.0f, 0.5f);
1057        hig_workarea_add_wide_control (t, &row, w);
1058
1059        g_snprintf (buf, sizeof (buf), _("U_pload (%s):"), _ (speed_K_str));
1060        w = new_spin_button (TR_KEY_alt_speed_up, core, 0, INT_MAX, 5);
1061        hig_workarea_add_row (t, &row, buf, w, NULL);
1062
1063        g_snprintf (buf, sizeof (buf), _("Do_wnload (%s):"), _ (speed_K_str));
1064        w = new_spin_button (TR_KEY_alt_speed_down, core, 0, INT_MAX, 5);
1065        hig_workarea_add_row (t, &row, buf, w, NULL);
1066
1067        s = _("_Scheduled times:");
1068        h = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
1069        w2 = new_time_combo (core, TR_KEY_alt_speed_time_begin);
1070        page->sched_widgets = g_slist_prepend (page->sched_widgets, w2);
1071        gtk_box_pack_start (GTK_BOX (h), w2, TRUE, TRUE, 0);
1072        w2 = l = gtk_label_new_with_mnemonic (_(" _to "));
1073        page->sched_widgets = g_slist_prepend (page->sched_widgets, w2);
1074        gtk_box_pack_start (GTK_BOX (h), w2, FALSE, FALSE, 0);
1075        w2 = new_time_combo (core, TR_KEY_alt_speed_time_end);
1076        gtk_label_set_mnemonic_widget (GTK_LABEL (l), w2);
1077        page->sched_widgets = g_slist_prepend (page->sched_widgets, w2);
1078        gtk_box_pack_start (GTK_BOX (h), w2, TRUE, TRUE, 0);
1079        w = new_check_button (s, TR_KEY_alt_speed_time_enabled, core);
1080        g_signal_connect (w, "toggled", G_CALLBACK (onSchedToggled), page);
1081        hig_workarea_add_row_w (t, &row, w, h, NULL);
1082
1083        s = _("_On days:");
1084        w = new_week_combo (core, TR_KEY_alt_speed_time_day);
1085        page->sched_widgets = g_slist_prepend (page->sched_widgets, w);
1086        w = hig_workarea_add_row (t, &row, s, w, NULL);
1087        page->sched_widgets = g_slist_prepend (page->sched_widgets, w);
1088
1089    g_object_set_data_full (G_OBJECT (t), "page", page, speedPageFree);
1090
1091    refreshSchedSensitivity (page);
1092    return t;
1093}
1094
1095/****
1096*****  Network Tab
1097****/
1098
1099struct network_page_data
1100{
1101    TrCore     * core;
1102    GtkWidget  * portLabel;
1103    GtkWidget  * portButton;
1104    GtkWidget  * portSpin;
1105    gulong       portTag;
1106    gulong       prefsTag;
1107};
1108
1109static void
1110onCorePrefsChanged (TrCore * core UNUSED, const tr_quark key, gpointer gdata)
1111{
1112  if (key == TR_KEY_peer_port)
1113    {
1114      struct network_page_data * data = gdata;
1115      gtr_label_set_text (GTK_LABEL (data->portLabel), _("Status unknown"));
1116      gtk_widget_set_sensitive (data->portButton, TRUE);
1117      gtk_widget_set_sensitive (data->portSpin, TRUE);
1118    }
1119}
1120
1121static void
1122networkPageDestroyed (gpointer gdata, GObject * dead UNUSED)
1123{
1124  struct network_page_data * data = gdata;
1125
1126  if (data->prefsTag > 0)
1127    g_signal_handler_disconnect (data->core, data->prefsTag);
1128  if (data->portTag > 0)
1129    g_signal_handler_disconnect (data->core, data->portTag);
1130
1131  g_free (data);
1132}
1133
1134static void
1135onPortTested (TrCore * core UNUSED, gboolean isOpen, gpointer vdata)
1136{
1137  struct network_page_data * data = vdata;
1138  const char * markup = isOpen ? _("Port is <b>open</b>") : _("Port is <b>closed</b>");
1139
1140  //gdk_threads_enter ();
1141  gtk_label_set_markup (GTK_LABEL (data->portLabel), markup);
1142  gtk_widget_set_sensitive (data->portButton, TRUE);
1143  gtk_widget_set_sensitive (data->portSpin, TRUE);
1144  //gdk_threads_leave ();
1145}
1146
1147static void
1148onPortTest (GtkButton * button UNUSED, gpointer vdata)
1149{
1150  struct network_page_data * data = vdata;
1151  gtk_widget_set_sensitive (data->portButton, FALSE);
1152  gtk_widget_set_sensitive (data->portSpin, FALSE);
1153  gtk_label_set_markup (GTK_LABEL (data->portLabel), _("<i>Testing TCP port
</i>"));
1154  if (!data->portTag)
1155    data->portTag = g_signal_connect (data->core, "port-tested", G_CALLBACK (onPortTested), data);
1156  gtr_core_port_test (data->core);
1157}
1158
1159static GtkWidget*
1160networkPage (GObject * core)
1161{
1162  GtkWidget * t;
1163  GtkWidget * w;
1164  GtkWidget * h;
1165  GtkWidget * l;
1166  const char * s;
1167  struct network_page_data * data;
1168  guint row = 0;
1169
1170  /* register to stop listening to core prefs changes when the page is destroyed */
1171  data = g_new0 (struct network_page_data, 1);
1172  data->core = TR_CORE (core);
1173
1174  /* build the page */
1175  t = hig_workarea_create ();
1176  hig_workarea_add_section_title (t, &row, _("Listening Port"));
1177
1178  s = _("_Port used for incoming connections:");
1179  w = data->portSpin = new_spin_button (TR_KEY_peer_port, core, 1, USHRT_MAX, 1);
1180  hig_workarea_add_row (t, &row, s, w, NULL);
1181
1182  h = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, GUI_PAD_BIG);
1183  l = data->portLabel = gtk_label_new (_("Status unknown"));
1184  gtk_misc_set_alignment (GTK_MISC (l), 0.0f, 0.5f);
1185  gtk_box_pack_start (GTK_BOX (h), l, TRUE, TRUE, 0);
1186  w = data->portButton = gtk_button_new_with_mnemonic (_("Te_st Port"));
1187  gtk_box_pack_end (GTK_BOX (h), w, FALSE, FALSE, 0);
1188  g_signal_connect (w, "clicked", G_CALLBACK (onPortTest), data);
1189  hig_workarea_add_row (t, &row, NULL, h, NULL);
1190  data->prefsTag = g_signal_connect (TR_CORE (core), "prefs-changed", G_CALLBACK (onCorePrefsChanged), data);
1191  g_object_weak_ref (G_OBJECT (t), networkPageDestroyed, data);
1192
1193  s = _("Pick a _random port every time Transmission is started");
1194  w = new_check_button (s, TR_KEY_peer_port_random_on_start, core);
1195  hig_workarea_add_wide_control (t, &row, w);
1196
1197  s = _("Use UPnP or NAT-PMP port _forwarding from my router");
1198  w = new_check_button (s, TR_KEY_port_forwarding_enabled, core);
1199  hig_workarea_add_wide_control (t, &row, w);
1200
1201  hig_workarea_add_section_divider (t, &row);
1202  hig_workarea_add_section_title (t, &row, _("Peer Limits"));
1203
1204  w = new_spin_button (TR_KEY_peer_limit_per_torrent, core, 1, FD_SETSIZE, 5);
1205  hig_workarea_add_row (t, &row, _("Maximum peers per _torrent:"), w, NULL);
1206  w = new_spin_button (TR_KEY_peer_limit_global, core, 1, FD_SETSIZE, 5);
1207  hig_workarea_add_row (t, &row, _("Maximum peers _overall:"), w, NULL);
1208
1209  hig_workarea_add_section_divider (t, &row);
1210  hig_workarea_add_section_title (t, &row, _("Options"));
1211
1212#ifdef WITH_UTP
1213  s = _("Enable _uTP for peer communication");
1214  w = new_check_button (s, TR_KEY_utp_enabled, core);
1215  s = _("uTP is a tool for reducing network congestion.");
1216  gtk_widget_set_tooltip_text (w, s);
1217  hig_workarea_add_wide_control (t, &row, w);
1218#endif
1219
1220  s = _("Use PE_X to find more peers");
1221  w = new_check_button (s, TR_KEY_pex_enabled, core);
1222  s = _("PEX is a tool for exchanging peer lists with the peers you're connected to.");
1223  gtk_widget_set_tooltip_text (w, s);
1224  hig_workarea_add_wide_control (t, &row, w);
1225
1226  s = _("Use _DHT to find more peers");
1227  w = new_check_button (s, TR_KEY_dht_enabled, core);
1228  s = _("DHT is a tool for finding peers without a tracker.");
1229  gtk_widget_set_tooltip_text (w, s);
1230  hig_workarea_add_wide_control (t, &row, w);
1231
1232  s = _("Use _Local Peer Discovery to find more peers");
1233  w = new_check_button (s, TR_KEY_lpd_enabled, core);
1234  s = _("LPD is a tool for finding peers on your local network.");
1235  gtk_widget_set_tooltip_text (w, s);
1236  hig_workarea_add_wide_control (t, &row, w);
1237
1238  return t;
1239}
1240
1241/****
1242*****
1243****/
1244
1245GtkWidget *
1246gtr_prefs_dialog_new (GtkWindow * parent, GObject * core)
1247{
1248  GtkWidget * d;
1249  GtkWidget * n;
1250
1251  d = gtk_dialog_new_with_buttons (_("Transmission Preferences"),
1252                                   parent,
1253                                   GTK_DIALOG_DESTROY_WITH_PARENT,
1254                                   GTK_STOCK_HELP, GTK_RESPONSE_HELP,
1255                                   GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
1256                                   NULL);
1257  gtk_window_set_role (GTK_WINDOW (d), "transmission-preferences-dialog");
1258  gtk_container_set_border_width (GTK_CONTAINER (d), GUI_PAD);
1259
1260  n = gtk_notebook_new ();
1261  gtk_container_set_border_width (GTK_CONTAINER (n), GUI_PAD);
1262
1263  gtk_notebook_append_page (GTK_NOTEBOOK (n), speedPage (core),
1264                            gtk_label_new (_("Speed")));
1265  gtk_notebook_append_page (GTK_NOTEBOOK (n), downloadingPage (core),
1266                            gtk_label_new (C_("Gerund", "Downloading")));
1267  gtk_notebook_append_page (GTK_NOTEBOOK (n), seedingPage (core),
1268                            gtk_label_new (C_("Gerund", "Seeding")));
1269  gtk_notebook_append_page (GTK_NOTEBOOK (n), privacyPage (core),
1270                            gtk_label_new (_("Privacy")));
1271  gtk_notebook_append_page (GTK_NOTEBOOK (n), networkPage (core),
1272                            gtk_label_new (_("Network")));
1273  gtk_notebook_append_page (GTK_NOTEBOOK (n), desktopPage (core),
1274                            gtk_label_new (_("Desktop")));
1275  gtk_notebook_append_page (GTK_NOTEBOOK (n), remotePage (core),
1276                            gtk_label_new (_("Remote")));
1277
1278  g_signal_connect (d, "response", G_CALLBACK (response_cb), core);
1279  gtr_dialog_set_content (GTK_DIALOG (d), n);
1280  return d;
1281}
1282
Note: See TracBrowser for help on using the repository browser.