Changeset 13657


Ignore:
Timestamp:
Dec 13, 2012, 3:37:55 AM (9 years ago)
Author:
jordan
Message:

copyediting: indentation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/tr-window.c

    r13656 r13657  
    4242typedef struct
    4343{
    44     GtkWidget *          speedlimit_on_item[2];
    45     GtkWidget *          speedlimit_off_item[2];
    46     GtkWidget *          ratio_on_item;
    47     GtkWidget *          ratio_off_item;
    48     GtkWidget *          scroll;
    49     GtkWidget *          view;
    50     GtkWidget *          toolbar;
    51     GtkWidget *          filter;
    52     GtkWidget *          status;
    53     GtkWidget *          status_menu;
    54     GtkLabel  *          ul_lb;
    55     GtkLabel  *          dl_lb;
    56     GtkLabel  *          stats_lb;
    57     GtkLabel  *          gutter_lb;
    58     GtkWidget *          alt_speed_image;
    59     GtkWidget *          alt_speed_button;
    60     GtkWidget *          options_menu;
    61     GtkTreeSelection *    selection;
    62     GtkCellRenderer *    renderer;
    63     GtkTreeViewColumn column;
    64     GtkTreeModel *        filter_model;
    65     TrCore *              core;
    66     gulong                pref_handler_id;
     44    GtkWidget          * speedlimit_on_item[2];
     45    GtkWidget          * speedlimit_off_item[2];
     46    GtkWidget          * ratio_on_item;
     47    GtkWidget          * ratio_off_item;
     48    GtkWidget          * scroll;
     49    GtkWidget          * view;
     50    GtkWidget          * toolbar;
     51    GtkWidget          * filter;
     52    GtkWidget          * status;
     53    GtkWidget          * status_menu;
     54    GtkLabel           * ul_lb;
     55    GtkLabel           * dl_lb;
     56    GtkLabel           * stats_lb;
     57    GtkLabel           * gutter_lb;
     58    GtkWidget          * alt_speed_image;
     59    GtkWidget          * alt_speed_button;
     60    GtkWidget          * options_menu;
     61    GtkTreeSelection   * selection;
     62    GtkCellRenderer    * renderer;
     63    GtkTreeViewColumn  * column;
     64    GtkTreeModel       * filter_model;
     65    TrCore             * core;
     66    gulong               pref_handler_id;
    6767}
    6868PrivateData;
     
    7171get_private_data_key (void)
    7272{
    73     static GQuark q = 0;
    74     if (!q) q = g_quark_from_static_string ("private-data");
    75     return q;
     73  static GQuark q = 0;
     74
     75  if (!q)
     76    q = g_quark_from_static_string ("private-data");
     77
     78  return q;
    7679}
    7780
     
    7982get_private_data (GtkWindow * w)
    8083{
    81     return g_object_get_qdata (G_OBJECT (w), get_private_data_key ());
     84  return g_object_get_qdata (G_OBJECT (w), get_private_data_key ());
    8285}
    8386
     
    9093               GdkEventButton * event)
    9194{
    92     GtkWidget * menu = gtr_action_get_widget ("/main-window-popup");
    93 
    94     gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
     95  GtkWidget * menu = gtr_action_get_widget ("/main-window-popup");
     96
     97  gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
    9598                  (event ? event->button : 0),
    9699                  (event ? event->time : 0));
     
    103106                    gpointer            user_data UNUSED)
    104107{
    105     gtr_action_activate ("show-torrent-properties");
     108  gtr_action_activate ("show-torrent-properties");
    106109}
    107110
     
    128131makeview (PrivateData * p)
    129132{
    130     GtkWidget *        view;
    131     GtkTreeViewColumn * col;
    132     GtkTreeSelection * sel;
    133     GtkCellRenderer *  r;
    134     GtkTreeView * tree_view;
    135 
    136     view = gtk_tree_view_new ();
    137     tree_view = GTK_TREE_VIEW (view);
    138     gtk_tree_view_set_search_column (tree_view, MC_NAME_COLLATED);
    139     gtk_tree_view_set_search_equal_func (tree_view,
    140                                          tree_view_search_equal_func,
    141                                          NULL, NULL);
    142     gtk_tree_view_set_headers_visible (tree_view, FALSE);
    143     gtk_tree_view_set_fixed_height_mode (tree_view, TRUE);
    144 
    145     p->selection = gtk_tree_view_get_selection (tree_view);
    146 
    147     p->column = col = GTK_TREE_VIEW_COLUMN (g_object_new (GTK_TYPE_TREE_VIEW_COLUMN,
    148         "title", _("Torrent"),
    149         "resizable", TRUE,
    150         "sizing", GTK_TREE_VIEW_COLUMN_FIXED,
    151         NULL));
    152 
    153     p->renderer = r = torrent_cell_renderer_new ();
    154     gtk_tree_view_column_pack_start (col, r, FALSE);
    155     gtk_tree_view_column_add_attribute (col, r, "torrent", MC_TORRENT);
    156     gtk_tree_view_column_add_attribute (col, r, "piece-upload-speed", MC_SPEED_UP);
    157     gtk_tree_view_column_add_attribute (col, r, "piece-download-speed", MC_SPEED_DOWN);
    158 
    159     gtk_tree_view_append_column (tree_view, col);
    160     g_object_set (r, "xpad", GUI_PAD_SMALL, "ypad", GUI_PAD_SMALL, NULL);
    161 
    162     gtk_tree_view_set_rules_hint (tree_view, TRUE);
    163     sel = gtk_tree_view_get_selection (tree_view);
    164     gtk_tree_selection_set_mode (GTK_TREE_SELECTION (sel),
    165                                  GTK_SELECTION_MULTIPLE);
    166 
    167     g_signal_connect (view, "popup-menu",
    168                       G_CALLBACK (on_popup_menu), NULL);
    169     g_signal_connect (view, "button-press-event",
    170                       G_CALLBACK (on_tree_view_button_pressed),
     133  GtkWidget * view;
     134  GtkTreeViewColumn * col;
     135  GtkTreeSelection * sel;
     136  GtkCellRenderer * r;
     137  GtkTreeView * tree_view;
     138
     139  view = gtk_tree_view_new ();
     140  tree_view = GTK_TREE_VIEW (view);
     141  gtk_tree_view_set_search_column (tree_view, MC_NAME_COLLATED);
     142  gtk_tree_view_set_search_equal_func (tree_view,
     143                                       tree_view_search_equal_func,
     144                                       NULL, NULL);
     145  gtk_tree_view_set_headers_visible (tree_view, FALSE);
     146  gtk_tree_view_set_fixed_height_mode (tree_view, TRUE);
     147
     148  p->selection = gtk_tree_view_get_selection (tree_view);
     149
     150  p->column = col = GTK_TREE_VIEW_COLUMN (g_object_new (GTK_TYPE_TREE_VIEW_COLUMN,
     151    "title", _("Torrent"),
     152    "resizable", TRUE,
     153    "sizing", GTK_TREE_VIEW_COLUMN_FIXED,
     154    NULL));
     155
     156  p->renderer = r = torrent_cell_renderer_new ();
     157  gtk_tree_view_column_pack_start (col, r, FALSE);
     158  gtk_tree_view_column_add_attribute (col, r, "torrent", MC_TORRENT);
     159  gtk_tree_view_column_add_attribute (col, r, "piece-upload-speed", MC_SPEED_UP);
     160  gtk_tree_view_column_add_attribute (col, r, "piece-download-speed", MC_SPEED_DOWN);
     161
     162  gtk_tree_view_append_column (tree_view, col);
     163  g_object_set (r, "xpad", GUI_PAD_SMALL, "ypad", GUI_PAD_SMALL, NULL);
     164
     165  gtk_tree_view_set_rules_hint (tree_view, TRUE);
     166  sel = gtk_tree_view_get_selection (tree_view);
     167  gtk_tree_selection_set_mode (GTK_TREE_SELECTION (sel),
     168                               GTK_SELECTION_MULTIPLE);
     169
     170  g_signal_connect (view, "popup-menu",
     171                    G_CALLBACK (on_popup_menu), NULL);
     172  g_signal_connect (view, "button-press-event",
     173                    G_CALLBACK (on_tree_view_button_pressed),
    171174                    (void *) on_popup_menu);
    172     g_signal_connect (view, "button-release-event",
    173                       G_CALLBACK (on_tree_view_button_released), NULL);
    174     g_signal_connect (view, "row-activated",
    175                       G_CALLBACK (view_row_activated), NULL);
    176 
    177 
    178     gtk_tree_view_set_model (tree_view, p->filter_model);
    179     g_object_unref (p->filter_model);
    180 
    181     return view;
     175  g_signal_connect (view, "button-release-event",
     176                    G_CALLBACK (on_tree_view_button_released), NULL);
     177  g_signal_connect (view, "row-activated",
     178                    G_CALLBACK (view_row_activated), NULL);
     179
     180
     181  gtk_tree_view_set_model (tree_view, p->filter_model);
     182  g_object_unref (p->filter_model);
     183
     184  return view;
    182185}
    183186
     
    185188
    186189static void
    187 prefsChanged (TrCore * core UNUSED,
     190prefsChanged (TrCore     * core UNUSED,
    188191              const char *  key,
    189192              gpointer      wind)
    190193{
    191     PrivateData * p = get_private_data (GTK_WINDOW (wind));
    192 
    193     if (!strcmp (key, PREF_KEY_COMPACT_VIEW))
    194     {
    195         g_object_set (p->renderer, "compact", gtr_pref_flag_get (key), NULL);
    196         /* since the cell size has changed, we need gtktreeview to revalidate
    197          * its fixed-height mode values. Unfortunately there's not an API call
    198          * for that, but it *does* revalidate when it thinks the style's been tweaked */
    199         g_signal_emit_by_name (p->view, "style-updated", NULL, NULL);
    200     }
    201     else if (!strcmp (key, PREF_KEY_STATUSBAR))
    202     {
    203         const gboolean isEnabled = gtr_pref_flag_get (key);
    204         g_object_set (p->status, "visible", isEnabled, NULL);
    205     }
    206     else if (!strcmp (key, PREF_KEY_FILTERBAR))
    207     {
    208         const gboolean isEnabled = gtr_pref_flag_get (key);
    209         g_object_set (p->filter, "visible", isEnabled, NULL);
    210     }
    211     else if (!strcmp (key, PREF_KEY_TOOLBAR))
    212     {
    213         const gboolean isEnabled = gtr_pref_flag_get (key);
    214         g_object_set (p->toolbar, "visible", isEnabled, NULL);
    215     }
    216     else if (!strcmp (key, PREF_KEY_STATUSBAR_STATS))
    217     {
    218         gtr_window_refresh (wind);
    219     }
    220     else if (!strcmp (key, TR_PREFS_KEY_ALT_SPEED_ENABLED) ||
    221              !strcmp (key, TR_PREFS_KEY_ALT_SPEED_UP_KBps) ||
    222              !strcmp (key, TR_PREFS_KEY_ALT_SPEED_DOWN_KBps))
    223     {
    224         syncAltSpeedButton (p);
     194  PrivateData * p = get_private_data (GTK_WINDOW (wind));
     195
     196  if (!strcmp (key, PREF_KEY_COMPACT_VIEW))
     197    {
     198      g_object_set (p->renderer, "compact", gtr_pref_flag_get (key), NULL);
     199      /* since the cell size has changed, we need gtktreeview to revalidate
     200       * its fixed-height mode values. Unfortunately there's not an API call
     201       * for that, but it *does* revalidate when it thinks the style's been tweaked */
     202      g_signal_emit_by_name (p->view, "style-updated", NULL, NULL);
     203    }
     204  else if (!strcmp (key, PREF_KEY_STATUSBAR))
     205    {
     206      const gboolean isEnabled = gtr_pref_flag_get (key);
     207      g_object_set (p->status, "visible", isEnabled, NULL);
     208    }
     209  else if (!strcmp (key, PREF_KEY_FILTERBAR))
     210    {
     211      const gboolean isEnabled = gtr_pref_flag_get (key);
     212      g_object_set (p->filter, "visible", isEnabled, NULL);
     213    }
     214  else if (!strcmp (key, PREF_KEY_TOOLBAR))
     215    {
     216      const gboolean isEnabled = gtr_pref_flag_get (key);
     217      g_object_set (p->toolbar, "visible", isEnabled, NULL);
     218    }
     219  else if (!strcmp (key, PREF_KEY_STATUSBAR_STATS))
     220    {
     221      gtr_window_refresh (wind);
     222    }
     223  else if (!strcmp (key, TR_PREFS_KEY_ALT_SPEED_ENABLED) ||
     224           !strcmp (key, TR_PREFS_KEY_ALT_SPEED_UP_KBps) ||
     225           !strcmp (key, TR_PREFS_KEY_ALT_SPEED_DOWN_KBps))
     226    {
     227      syncAltSpeedButton (p);
    225228    }
    226229}
     
    229232privateFree (gpointer vprivate)
    230233{
    231     PrivateData * p = vprivate;
    232     g_signal_handler_disconnect (p->core, p->pref_handler_id);
    233     g_free (p);
     234  PrivateData * p = vprivate;
     235  g_signal_handler_disconnect (p->core, p->pref_handler_id);
     236  g_free (p);
    234237}
    235238
     
    237240onYinYangReleased (GtkWidget * w UNUSED, gpointer vprivate)
    238241{
    239     PrivateData * p = vprivate;
    240 
    241     gtk_menu_popup (GTK_MENU (p->status_menu),
    242                     NULL, NULL, NULL, NULL, 0,
    243                     gtk_get_current_event_time ());
     242  PrivateData * p = vprivate;
     243
     244  gtk_menu_popup (GTK_MENU (p->status_menu),
     245                  NULL, NULL, NULL, NULL, 0,
     246                  gtk_get_current_event_time ());
    244247}
    245248
     
    260263                        gpointer           vprivate)
    261264{
    262     if (gtk_check_menu_item_get_active (menu_item))
    263     {
    264         PrivateData * p = vprivate;
    265         const char *  val = g_object_get_data (G_OBJECT (
    266                                                    menu_item), STATS_MODE);
    267         gtr_core_set_pref (p->core, PREF_KEY_STATUSBAR_STATS, val);
     265  if (gtk_check_menu_item_get_active (menu_item))
     266    {
     267      PrivateData * p = vprivate;
     268      const char *  val = g_object_get_data (G_OBJECT (menu_item), STATS_MODE);
     269      gtr_core_set_pref (p->core, PREF_KEY_STATUSBAR_STATS, val);
    268270    }
    269271}
     
    272274syncAltSpeedButton (PrivateData * p)
    273275{
    274     char u[32];
    275     char d[32];
    276     char * str;
    277     const char * fmt;
    278     const gboolean b = gtr_pref_flag_get (TR_PREFS_KEY_ALT_SPEED_ENABLED);
    279     const char * stock = b ? "alt-speed-on" : "alt-speed-off";
    280     GtkWidget * w = p->alt_speed_button;
    281 
    282     tr_formatter_speed_KBps (u, gtr_pref_int_get (TR_PREFS_KEY_ALT_SPEED_UP_KBps), sizeof (u));
    283     tr_formatter_speed_KBps (d, gtr_pref_int_get (TR_PREFS_KEY_ALT_SPEED_DOWN_KBps), sizeof (d));
    284     fmt = b ? _("Click to disable Alternative Speed Limits\n (%1$s down, %2$s up)")
    285             : _("Click to enable Alternative Speed Limits\n (%1$s down, %2$s up)");
    286     str = g_strdup_printf (fmt, d, u);
    287 
    288     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), b);
    289     gtk_image_set_from_stock (GTK_IMAGE (p->alt_speed_image), stock, -1);
    290     gtk_button_set_alignment (GTK_BUTTON (w), 0.5, 0.5);
    291     gtk_widget_set_tooltip_text (w, str);
    292 
    293     g_free (str);
     276  char u[32];
     277  char d[32];
     278  char * str;
     279  const char * fmt;
     280  const gboolean b = gtr_pref_flag_get (TR_PREFS_KEY_ALT_SPEED_ENABLED);
     281  const char * stock = b ? "alt-speed-on" : "alt-speed-off";
     282  GtkWidget * w = p->alt_speed_button;
     283
     284  tr_formatter_speed_KBps (u, gtr_pref_int_get (TR_PREFS_KEY_ALT_SPEED_UP_KBps), sizeof (u));
     285  tr_formatter_speed_KBps (d, gtr_pref_int_get (TR_PREFS_KEY_ALT_SPEED_DOWN_KBps), sizeof (d));
     286  fmt = b ? _("Click to disable Alternative Speed Limits\n (%1$s down, %2$s up)")
     287          : _("Click to enable Alternative Speed Limits\n (%1$s down, %2$s up)");
     288  str = g_strdup_printf (fmt, d, u);
     289
     290  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), b);
     291  gtk_image_set_from_stock (GTK_IMAGE (p->alt_speed_image), stock, -1);
     292  gtk_button_set_alignment (GTK_BUTTON (w), 0.5, 0.5);
     293  gtk_widget_set_tooltip_text (w, str);
     294
     295  g_free (str);
    294296}
    295297
     
    297299alt_speed_toggled_cb (GtkToggleButton * button, gpointer vprivate)
    298300{
    299     PrivateData * p = vprivate;
    300     const gboolean b = gtk_toggle_button_get_active (button);
    301     gtr_core_set_pref_bool (p->core, TR_PREFS_KEY_ALT_SPEED_ENABLED,  b);
     301  PrivateData * p = vprivate;
     302  const gboolean b = gtk_toggle_button_get_active (button);
     303  gtr_core_set_pref_bool (p->core, TR_PREFS_KEY_ALT_SPEED_ENABLED,  b);
    302304}
    303305
     
    307309
    308310static void
    309 findMaxAnnounceTime (GtkTreeModel *      model,
     311findMaxAnnounceTime (GtkTreeModel * model,
    310312                     GtkTreePath  * path UNUSED,
    311                      GtkTreeIter *      iter,
    312                      gpointer            gmaxTime)
    313 {
    314     tr_torrent *    tor;
    315     const tr_stat * torStat;
    316     time_t *        maxTime = gmaxTime;
    317 
    318     gtk_tree_model_get (model, iter, MC_TORRENT, &tor, -1);
    319     torStat = tr_torrentStatCached (tor);
    320     *maxTime = MAX (*maxTime, torStat->manualAnnounceTime);
     313                     GtkTreeIter  * iter,
     314                     gpointer       gmaxTime)
     315{
     316  tr_torrent * tor;
     317  const tr_stat * torStat;
     318  time_t * maxTime = gmaxTime;
     319
     320  gtk_tree_model_get (model, iter, MC_TORRENT, &tor, -1);
     321  torStat = tr_torrentStatCached (tor);
     322  *maxTime = MAX (*maxTime, torStat->manualAnnounceTime);
    321323}
    322324
    323325static gboolean
    324 onAskTrackerQueryTooltip (GtkWidget *            widget UNUSED,
    325                           gint                   x UNUSED,
    326                           gint                   y UNUSED,
    327                           gboolean               keyboard_tip UNUSED,
    328                           GtkTooltip *           tooltip,
    329                           gpointer               gdata)
    330 {
    331     const time_t now = time (NULL);
    332     time_t       maxTime = 0;
    333     PrivateData * p = gdata;
    334 
    335     gtk_tree_selection_selected_foreach (p->selection,
    336                                          findMaxAnnounceTime,
    337                                          &maxTime);
    338     if (maxTime <= now)
    339     {
    340         return FALSE;
    341     }
    342     else
    343     {
    344         char      buf[512];
    345         char      timebuf[64];
    346         const int seconds = maxTime - now;
    347 
    348         tr_strltime (timebuf, seconds, sizeof (timebuf));
    349         g_snprintf (buf, sizeof (buf),
    350                     _("Tracker will allow requests in %s"), timebuf);
    351         gtk_tooltip_set_text (tooltip, buf);
    352         return TRUE;
    353     }
     326onAskTrackerQueryTooltip (GtkWidget   * widget UNUSED,
     327                          gint          x UNUSED,
     328                          gint          y UNUSED,
     329                          gboolean      keyboard_tip UNUSED,
     330                          GtkTooltip  * tooltip,
     331                          gpointer      gdata)
     332{
     333  gboolean handled;
     334  time_t maxTime = 0;
     335  PrivateData * p = gdata;
     336  const time_t now = time (NULL);
     337
     338  gtk_tree_selection_selected_foreach (p->selection,
     339                                       findMaxAnnounceTime,
     340                                       &maxTime);
     341  if (maxTime <= now)
     342    {
     343      handled = FALSE;
     344    }
     345  else
     346    {
     347      char buf[512];
     348      char timebuf[64];
     349      const int seconds = maxTime - now;
     350
     351      tr_strltime (timebuf, seconds, sizeof (timebuf));
     352      g_snprintf (buf, sizeof (buf),
     353                  _("Tracker will allow requests in %s"), timebuf);
     354      gtk_tooltip_set_text (tooltip, buf);
     355      handled = TRUE;
     356    }
     357
     358  return handled;
    354359}
    355360
     
    357362onAltSpeedToggledIdle (gpointer vp)
    358363{
    359     PrivateData * p = vp;
    360     gboolean b = tr_sessionUsesAltSpeed (gtr_core_session (p->core));
    361     gtr_core_set_pref_bool (p->core, TR_PREFS_KEY_ALT_SPEED_ENABLED, b);
    362 
    363     return FALSE;
     364  PrivateData * p = vp;
     365  gboolean b = tr_sessionUsesAltSpeed (gtr_core_session (p->core));
     366  gtr_core_set_pref_bool (p->core, TR_PREFS_KEY_ALT_SPEED_ENABLED, b);
     367
     368  return FALSE;
    364369}
    365370
     
    367372onAltSpeedToggled (tr_session * s UNUSED, bool isEnabled UNUSED, bool byUser UNUSED, void * p)
    368373{
    369     gdk_threads_add_idle (onAltSpeedToggledIdle, p);
     374  gdk_threads_add_idle (onAltSpeedToggledIdle, p);
    370375}
    371376
     
    381386onSpeedToggled (GtkCheckMenuItem * check, gpointer vp)
    382387{
    383     PrivateData * p = vp;
    384     GObject * o = G_OBJECT (check);
    385     gboolean isEnabled = g_object_get_data (o, ENABLED_KEY) != 0;
    386     tr_direction dir = GPOINTER_TO_INT (g_object_get_data (o, DIRECTION_KEY));
    387     const char * key = dir == TR_UP ? TR_PREFS_KEY_USPEED_ENABLED
    388                                     : TR_PREFS_KEY_DSPEED_ENABLED;
    389 
    390     if (gtk_check_menu_item_get_active (check))
    391         gtr_core_set_pref_bool (p->core, key, isEnabled);
     388  PrivateData * p = vp;
     389  GObject * o = G_OBJECT (check);
     390  gboolean isEnabled = g_object_get_data (o, ENABLED_KEY) != 0;
     391  tr_direction dir = GPOINTER_TO_INT (g_object_get_data (o, DIRECTION_KEY));
     392  const char * key = dir == TR_UP ? TR_PREFS_KEY_USPEED_ENABLED
     393                                  : TR_PREFS_KEY_DSPEED_ENABLED;
     394
     395  if (gtk_check_menu_item_get_active (check))
     396    gtr_core_set_pref_bool (p->core, key, isEnabled);
    392397}
    393398
     
    395400onSpeedSet (GtkCheckMenuItem * check, gpointer vp)
    396401{
    397     const char * key;
    398     PrivateData * p = vp;
    399     GObject * o = G_OBJECT (check);
    400     const int KBps = GPOINTER_TO_INT (g_object_get_data (o, SPEED_KEY));
    401     tr_direction dir = GPOINTER_TO_INT (g_object_get_data (o, DIRECTION_KEY));
    402 
    403     key = dir==TR_UP ? TR_PREFS_KEY_USPEED_KBps : TR_PREFS_KEY_DSPEED_KBps;
    404     gtr_core_set_pref_int (p->core, key, KBps);
    405 
    406     key = dir==TR_UP ? TR_PREFS_KEY_USPEED_ENABLED : TR_PREFS_KEY_DSPEED_ENABLED;
    407     gtr_core_set_pref_bool (p->core, key, TRUE);
     402  const char * key;
     403  PrivateData * p = vp;
     404  GObject * o = G_OBJECT (check);
     405  const int KBps = GPOINTER_TO_INT (g_object_get_data (o, SPEED_KEY));
     406  tr_direction dir = GPOINTER_TO_INT (g_object_get_data (o, DIRECTION_KEY));
     407
     408  key = dir==TR_UP ? TR_PREFS_KEY_USPEED_KBps : TR_PREFS_KEY_DSPEED_KBps;
     409  gtr_core_set_pref_int (p->core, key, KBps);
     410
     411  key = dir==TR_UP ? TR_PREFS_KEY_USPEED_ENABLED : TR_PREFS_KEY_DSPEED_ENABLED;
     412  gtr_core_set_pref_bool (p->core, key, TRUE);
    408413}
    409414
     
    411416createSpeedMenu (PrivateData * p, tr_direction dir)
    412417{
    413     int i, n;
    414     GtkWidget *w, *m;
    415     GtkMenuShell * menu_shell;
    416     const int speeds_KBps[] = { 5, 10, 20, 30, 40, 50, 75, 100, 150, 200, 250, 500, 750 };
    417 
    418     m = gtk_menu_new ();
    419     menu_shell = GTK_MENU_SHELL (m);
    420 
    421     w = gtk_radio_menu_item_new_with_label (NULL, _("Unlimited"));
    422     p->speedlimit_off_item[dir] = w;
    423     g_object_set_data (G_OBJECT (w), DIRECTION_KEY, GINT_TO_POINTER (dir));
    424     g_object_set_data (G_OBJECT (w), ENABLED_KEY, GINT_TO_POINTER (FALSE));
    425     g_signal_connect (w, "toggled", G_CALLBACK (onSpeedToggled), p);
    426     gtk_menu_shell_append (menu_shell, w);
    427 
    428     w = gtk_radio_menu_item_new_with_label_from_widget (GTK_RADIO_MENU_ITEM (w), "");
    429     p->speedlimit_on_item[dir] = w;
    430     g_object_set_data (G_OBJECT (w), DIRECTION_KEY, GINT_TO_POINTER (dir));
    431     g_object_set_data (G_OBJECT (w), ENABLED_KEY, GINT_TO_POINTER (TRUE));
    432     g_signal_connect (w, "toggled", G_CALLBACK (onSpeedToggled), p);
    433     gtk_menu_shell_append (menu_shell, w);
    434 
    435     w = gtk_separator_menu_item_new ();
    436     gtk_menu_shell_append (menu_shell, w);
    437 
    438     for (i=0, n=G_N_ELEMENTS (speeds_KBps); i<n; ++i)
    439     {
    440         char buf[128];
    441         tr_formatter_speed_KBps (buf, speeds_KBps[i], sizeof (buf));
    442         w = gtk_menu_item_new_with_label (buf);
    443         g_object_set_data (G_OBJECT (w), DIRECTION_KEY, GINT_TO_POINTER (dir));
    444         g_object_set_data (G_OBJECT (w), SPEED_KEY, GINT_TO_POINTER (speeds_KBps[i]));
    445         g_signal_connect (w, "activate", G_CALLBACK (onSpeedSet), p);
    446         gtk_menu_shell_append (menu_shell, w);
    447     }
    448 
    449     return m;
     418  int i, n;
     419  GObject * o;
     420  GtkWidget * w;
     421  GtkWidget * m;
     422  GtkMenuShell * menu_shell;
     423  const int speeds_KBps[] = { 5, 10, 20, 30, 40, 50, 75, 100, 150, 200, 250, 500, 750 };
     424
     425  m = gtk_menu_new ();
     426  menu_shell = GTK_MENU_SHELL (m);
     427
     428  w = gtk_radio_menu_item_new_with_label (NULL, _("Unlimited"));
     429  o = G_OBJECT (w);
     430  p->speedlimit_off_item[dir] = w;
     431  g_object_set_data (o, DIRECTION_KEY, GINT_TO_POINTER (dir));
     432  g_object_set_data (o, ENABLED_KEY, GINT_TO_POINTER (FALSE));
     433  g_signal_connect (w, "toggled", G_CALLBACK (onSpeedToggled), p);
     434  gtk_menu_shell_append (menu_shell, w);
     435
     436  w = gtk_radio_menu_item_new_with_label_from_widget (GTK_RADIO_MENU_ITEM (w), "");
     437  o = G_OBJECT (w);
     438  p->speedlimit_on_item[dir] = w;
     439  g_object_set_data (o, DIRECTION_KEY, GINT_TO_POINTER (dir));
     440  g_object_set_data (o, ENABLED_KEY, GINT_TO_POINTER (TRUE));
     441  g_signal_connect (w, "toggled", G_CALLBACK (onSpeedToggled), p);
     442  gtk_menu_shell_append (menu_shell, w);
     443
     444  w = gtk_separator_menu_item_new ();
     445  gtk_menu_shell_append (menu_shell, w);
     446
     447  for (i=0, n=G_N_ELEMENTS (speeds_KBps); i<n; ++i)
     448    {
     449      char buf[128];
     450      tr_formatter_speed_KBps (buf, speeds_KBps[i], sizeof (buf));
     451      w = gtk_menu_item_new_with_label (buf);
     452      o = G_OBJECT (w);
     453      g_object_set_data (o, DIRECTION_KEY, GINT_TO_POINTER (dir));
     454      g_object_set_data (o, SPEED_KEY, GINT_TO_POINTER (speeds_KBps[i]));
     455      g_signal_connect (w, "activate", G_CALLBACK (onSpeedSet), p);
     456      gtk_menu_shell_append (menu_shell, w);
     457    }
     458
     459  return m;
    450460}
    451461
     
    461471onRatioToggled (GtkCheckMenuItem * check, gpointer vp)
    462472{
    463     PrivateData * p = vp;
    464     if (gtk_check_menu_item_get_active (check))
    465     {
    466         gboolean f = g_object_get_data (G_OBJECT (check), ENABLED_KEY) != 0;
    467         gtr_core_set_pref_bool (p->core, TR_PREFS_KEY_RATIO_ENABLED, f);
     473  PrivateData * p = vp;
     474
     475  if (gtk_check_menu_item_get_active (check))
     476    {
     477      gboolean f = g_object_get_data (G_OBJECT (check), ENABLED_KEY) != 0;
     478      gtr_core_set_pref_bool (p->core, TR_PREFS_KEY_RATIO_ENABLED, f);
    468479    }
    469480}
     
    471482onRatioSet (GtkCheckMenuItem * check, gpointer vp)
    472483{
    473     PrivateData * p = vp;
    474     int i = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (check), RATIO_KEY));
    475     const double ratio = stockRatios[i];
    476     gtr_core_set_pref_double (p->core, TR_PREFS_KEY_RATIO, ratio);
    477     gtr_core_set_pref_bool (p->core, TR_PREFS_KEY_RATIO_ENABLED, TRUE);
     484  PrivateData * p = vp;
     485  int i = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (check), RATIO_KEY));
     486  const double ratio = stockRatios[i];
     487  gtr_core_set_pref_double (p->core, TR_PREFS_KEY_RATIO, ratio);
     488  gtr_core_set_pref_bool (p->core, TR_PREFS_KEY_RATIO_ENABLED, TRUE);
    478489}
    479490
     
    481492createRatioMenu (PrivateData * p)
    482493{
    483     int i, n;
    484     GtkWidget *m, *w;
    485     GtkMenuShell * menu_shell;
    486 
    487     m = gtk_menu_new ();
    488     menu_shell = GTK_MENU_SHELL (m);
    489 
    490     w = gtk_radio_menu_item_new_with_label (NULL, _("Seed Forever"));
    491     p->ratio_off_item = w;
    492     g_object_set_data (G_OBJECT (w), ENABLED_KEY, GINT_TO_POINTER (FALSE));
    493     g_signal_connect (w, "toggled", G_CALLBACK (onRatioToggled), p);
    494     gtk_menu_shell_append (menu_shell, w);
    495 
    496     w = gtk_radio_menu_item_new_with_label_from_widget (GTK_RADIO_MENU_ITEM (w), "");
    497     p->ratio_on_item = w;
    498     g_object_set_data (G_OBJECT (w), ENABLED_KEY, GINT_TO_POINTER (TRUE));
    499     g_signal_connect (w, "toggled", G_CALLBACK (onRatioToggled), p);
    500     gtk_menu_shell_append (menu_shell, w);
    501 
    502     w = gtk_separator_menu_item_new ();
    503     gtk_menu_shell_append (menu_shell, w);
    504 
    505     for (i=0, n=G_N_ELEMENTS (stockRatios); i<n; ++i)
    506     {
    507         char buf[128];
    508         tr_strlratio (buf, stockRatios[i], sizeof (buf));
    509         w = gtk_menu_item_new_with_label (buf);
    510         g_object_set_data (G_OBJECT (w), RATIO_KEY, GINT_TO_POINTER (i));
    511         g_signal_connect (w, "activate", G_CALLBACK (onRatioSet), p);
    512         gtk_menu_shell_append (menu_shell, w);
     494  int i, n;
     495  GtkWidget *m, *w;
     496  GtkMenuShell * menu_shell;
     497
     498  m = gtk_menu_new ();
     499  menu_shell = GTK_MENU_SHELL (m);
     500
     501  w = gtk_radio_menu_item_new_with_label (NULL, _("Seed Forever"));
     502  p->ratio_off_item = w;
     503  g_object_set_data (G_OBJECT (w), ENABLED_KEY, GINT_TO_POINTER (FALSE));
     504  g_signal_connect (w, "toggled", G_CALLBACK (onRatioToggled), p);
     505  gtk_menu_shell_append (menu_shell, w);
     506
     507  w = gtk_radio_menu_item_new_with_label_from_widget (GTK_RADIO_MENU_ITEM (w), "");
     508  p->ratio_on_item = w;
     509  g_object_set_data (G_OBJECT (w), ENABLED_KEY, GINT_TO_POINTER (TRUE));
     510  g_signal_connect (w, "toggled", G_CALLBACK (onRatioToggled), p);
     511  gtk_menu_shell_append (menu_shell, w);
     512
     513  w = gtk_separator_menu_item_new ();
     514  gtk_menu_shell_append (menu_shell, w);
     515
     516  for (i=0, n=G_N_ELEMENTS (stockRatios); i<n; ++i)
     517    {
     518      char buf[128];
     519      tr_strlratio (buf, stockRatios[i], sizeof (buf));
     520      w = gtk_menu_item_new_with_label (buf);
     521      g_object_set_data (G_OBJECT (w), RATIO_KEY, GINT_TO_POINTER (i));
     522      g_signal_connect (w, "activate", G_CALLBACK (onRatioSet), p);
     523      gtk_menu_shell_append (menu_shell, w);
    513524    }
    514525
     
    523534createOptionsMenu (PrivateData * p)
    524535{
    525     GtkWidget * m;
    526     GtkWidget * top = gtk_menu_new ();
    527     GtkMenuShell * menu_shell = GTK_MENU_SHELL (top);
    528 
    529     m = gtk_menu_item_new_with_label (_("Limit Download Speed"));
    530     gtk_menu_item_set_submenu (GTK_MENU_ITEM (m), createSpeedMenu (p, TR_DOWN));
    531     gtk_menu_shell_append (menu_shell, m);
    532 
    533     m = gtk_menu_item_new_with_label (_("Limit Upload Speed"));
    534     gtk_menu_item_set_submenu (GTK_MENU_ITEM (m), createSpeedMenu (p, TR_UP));
    535     gtk_menu_shell_append (menu_shell, m);
    536 
    537     m = gtk_separator_menu_item_new ();
    538     gtk_menu_shell_append (menu_shell, m);
    539 
    540     m = gtk_menu_item_new_with_label (_("Stop Seeding at Ratio"));
    541     gtk_menu_item_set_submenu (GTK_MENU_ITEM (m), createRatioMenu (p));
    542     gtk_menu_shell_append (menu_shell, m);
    543 
    544     gtk_widget_show_all (top);
    545     return top;
     536  GtkWidget * m;
     537  GtkWidget * top = gtk_menu_new ();
     538  GtkMenuShell * menu_shell = GTK_MENU_SHELL (top);
     539
     540  m = gtk_menu_item_new_with_label (_("Limit Download Speed"));
     541  gtk_menu_item_set_submenu (GTK_MENU_ITEM (m), createSpeedMenu (p, TR_DOWN));
     542  gtk_menu_shell_append (menu_shell, m);
     543
     544  m = gtk_menu_item_new_with_label (_("Limit Upload Speed"));
     545  gtk_menu_item_set_submenu (GTK_MENU_ITEM (m), createSpeedMenu (p, TR_UP));
     546  gtk_menu_shell_append (menu_shell, m);
     547
     548  m = gtk_separator_menu_item_new ();
     549  gtk_menu_shell_append (menu_shell, m);
     550
     551  m = gtk_menu_item_new_with_label (_("Stop Seeding at Ratio"));
     552  gtk_menu_item_set_submenu (GTK_MENU_ITEM (m), createRatioMenu (p));
     553  gtk_menu_shell_append (menu_shell, m);
     554
     555  gtk_widget_show_all (top);
     556  return top;
    546557}
    547558
     
    549560onOptionsClicked (GtkButton * button UNUSED, gpointer vp)
    550561{
    551     char buf1[512];
    552     char buf2[512];
    553     gboolean b;
    554     GtkWidget * w;
    555     PrivateData * p = vp;
    556 
    557     w = p->speedlimit_on_item[TR_DOWN];
    558     tr_formatter_speed_KBps (buf1, gtr_pref_int_get (TR_PREFS_KEY_DSPEED_KBps), sizeof (buf1));
    559     gtr_label_set_text (GTK_LABEL (gtk_bin_get_child (GTK_BIN (w))), buf1);
    560 
    561     b = gtr_pref_flag_get (TR_PREFS_KEY_DSPEED_ENABLED);
    562     w = b ? p->speedlimit_on_item[TR_DOWN] : p->speedlimit_off_item[TR_DOWN];
    563     gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w), TRUE);
    564 
    565     w = p->speedlimit_on_item[TR_UP];
    566     tr_formatter_speed_KBps (buf1, gtr_pref_int_get (TR_PREFS_KEY_USPEED_KBps), sizeof (buf1));
    567     gtr_label_set_text (GTK_LABEL (gtk_bin_get_child (GTK_BIN (w))), buf1);
    568 
    569     b = gtr_pref_flag_get (TR_PREFS_KEY_USPEED_ENABLED);
    570     w = b ? p->speedlimit_on_item[TR_UP] : p->speedlimit_off_item[TR_UP];
    571     gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w), TRUE);
    572 
    573     tr_strlratio (buf1, gtr_pref_double_get (TR_PREFS_KEY_RATIO), sizeof (buf1));
    574     g_snprintf (buf2, sizeof (buf2), _("Stop at Ratio (%s)"), buf1);
    575     gtr_label_set_text (GTK_LABEL (gtk_bin_get_child (GTK_BIN (p->ratio_on_item))), buf2);
    576 
    577     b = gtr_pref_flag_get (TR_PREFS_KEY_RATIO_ENABLED);
    578     gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (b ? p->ratio_on_item : p->ratio_off_item), TRUE);
    579 
    580     gtk_menu_popup (GTK_MENU (p->options_menu), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time ());
     562  char buf1[512];
     563  char buf2[512];
     564  gboolean b;
     565  GtkWidget * w;
     566  PrivateData * p = vp;
     567
     568  w = p->speedlimit_on_item[TR_DOWN];
     569  tr_formatter_speed_KBps (buf1, gtr_pref_int_get (TR_PREFS_KEY_DSPEED_KBps), sizeof (buf1));
     570  gtr_label_set_text (GTK_LABEL (gtk_bin_get_child (GTK_BIN (w))), buf1);
     571
     572  b = gtr_pref_flag_get (TR_PREFS_KEY_DSPEED_ENABLED);
     573  w = b ? p->speedlimit_on_item[TR_DOWN] : p->speedlimit_off_item[TR_DOWN];
     574  gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w), TRUE);
     575
     576  w = p->speedlimit_on_item[TR_UP];
     577  tr_formatter_speed_KBps (buf1, gtr_pref_int_get (TR_PREFS_KEY_USPEED_KBps), sizeof (buf1));
     578  gtr_label_set_text (GTK_LABEL (gtk_bin_get_child (GTK_BIN (w))), buf1);
     579
     580  b = gtr_pref_flag_get (TR_PREFS_KEY_USPEED_ENABLED);
     581  w = b ? p->speedlimit_on_item[TR_UP] : p->speedlimit_off_item[TR_UP];
     582  gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w), TRUE);
     583
     584  tr_strlratio (buf1, gtr_pref_double_get (TR_PREFS_KEY_RATIO), sizeof (buf1));
     585  g_snprintf (buf2, sizeof (buf2), _("Stop at Ratio (%s)"), buf1);
     586  gtr_label_set_text (GTK_LABEL (gtk_bin_get_child (GTK_BIN (p->ratio_on_item))), buf2);
     587
     588  b = gtr_pref_flag_get (TR_PREFS_KEY_RATIO_ENABLED);
     589  gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (b ? p->ratio_on_item : p->ratio_off_item), TRUE);
     590
     591  gtk_menu_popup (GTK_MENU (p->options_menu), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time ());
    581592}
    582593
     
    588599gtr_window_new (GtkApplication * app, GtkUIManager * ui_mgr, TrCore * core)
    589600{
    590     int           i, n;
    591     const char  * pch;
    592     PrivateData * p;
    593     GtkWidget   * ul_lb, * dl_lb;
    594     GtkWidget   * mainmenu, *toolbar, *filter, *list, *status;
    595     GtkWidget   * vbox, *w, *self, *h, *hbox, *menu;
    596     GtkWindow   * win;
    597     GSList      * l;
    598 
    599     p = g_new0 (PrivateData, 1);
    600 
    601     /* make the window */
    602     self = gtk_application_window_new (app);
    603     g_object_set_qdata_full (G_OBJECT (self), get_private_data_key (), p, privateFree);
    604     win = GTK_WINDOW (self);
    605     gtk_window_set_title (win, g_get_application_name ());
    606     gtk_window_set_role (win, "tr-main");
    607     gtk_window_set_default_size (win,
    608                                  gtr_pref_int_get (PREF_KEY_MAIN_WINDOW_WIDTH),
    609                                  gtr_pref_int_get (PREF_KEY_MAIN_WINDOW_HEIGHT));
    610     gtk_window_move (win, gtr_pref_int_get (PREF_KEY_MAIN_WINDOW_X),
    611                           gtr_pref_int_get (PREF_KEY_MAIN_WINDOW_Y));
    612     if (gtr_pref_flag_get (PREF_KEY_MAIN_WINDOW_IS_MAXIMIZED))
    613         gtk_window_maximize (win);
    614     gtk_window_add_accel_group (win, gtk_ui_manager_get_accel_group (ui_mgr));
    615 
    616     /* window's main container */
    617     vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
    618     gtk_container_add (GTK_CONTAINER (self), vbox);
    619 
    620     /* main menu */
    621     mainmenu = gtr_action_get_widget ("/main-window-menu");
    622     w = gtr_action_get_widget ("/main-window-menu/torrent-menu/torrent-reannounce");
    623     g_signal_connect (w, "query-tooltip", G_CALLBACK (onAskTrackerQueryTooltip), p);
    624 
    625     /* toolbar */
    626     toolbar = p->toolbar = gtr_action_get_widget ("/main-window-toolbar");
    627     gtk_style_context_add_class (gtk_widget_get_style_context (toolbar),
    628                                  GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
    629     gtr_action_set_important ("open-torrent-toolbar", TRUE);
    630     gtr_action_set_important ("show-torrent-properties", TRUE);
    631 
    632     /* filter */
    633     h = filter = p->filter = gtr_filter_bar_new (gtr_core_session (core),
    634                                                  gtr_core_model (core),
    635                                                  &p->filter_model);
    636     gtk_container_set_border_width (GTK_CONTAINER (h), GUI_PAD_SMALL);
    637 
    638     /* status menu */
    639     menu = p->status_menu = gtk_menu_new ();
    640     l = NULL;
    641     pch = gtr_pref_string_get (PREF_KEY_STATUSBAR_STATS);
    642     for (i = 0, n = G_N_ELEMENTS (stats_modes); i < n; ++i)
    643     {
    644         const char * val = stats_modes[i].val;
    645         w = gtk_radio_menu_item_new_with_label (l, _ (stats_modes[i].i18n));
    646         l = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (w));
    647         gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w),
    648                                        !strcmp (val, pch));
    649         g_object_set_data (G_OBJECT (
    650                                w), STATS_MODE,
    651                          (gpointer)stats_modes[i].val);
    652         g_signal_connect (w, "toggled", G_CALLBACK (
    653                               status_menu_toggled_cb), p);
    654         gtk_menu_shell_append (GTK_MENU_SHELL (menu), w);
    655         gtk_widget_show (w);
    656     }
    657 
    658     /* status */
    659     h = status = p->status = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, GUI_PAD_BIG);
    660     gtk_container_set_border_width (GTK_CONTAINER (h), GUI_PAD_SMALL);
    661 
    662         w = gtk_button_new ();
    663         gtk_container_add (GTK_CONTAINER (w), gtk_image_new_from_stock ("utilities", -1));
    664         gtk_widget_set_tooltip_text (w, _("Options"));
    665         gtk_box_pack_start (GTK_BOX (h), w, 0, 0, 0);
    666         gtk_button_set_relief (GTK_BUTTON (w), GTK_RELIEF_NONE);
    667         p->options_menu = createOptionsMenu (p);
    668         g_signal_connect (w, "clicked", G_CALLBACK (onOptionsClicked), p);
    669 
    670         p->alt_speed_image = gtk_image_new ();
    671         w = p->alt_speed_button = gtk_toggle_button_new ();
    672         gtk_button_set_image (GTK_BUTTON (w), p->alt_speed_image);
    673         gtk_button_set_relief (GTK_BUTTON (w), GTK_RELIEF_NONE);
    674         g_signal_connect (w, "toggled", G_CALLBACK (alt_speed_toggled_cb), p);
    675         gtk_box_pack_start (GTK_BOX (h), w, 0, 0, 0);
    676 
    677         w = gtk_label_new ("N Torrents");
    678         p->gutter_lb = GTK_LABEL (w);
    679         gtk_label_set_single_line_mode (p->gutter_lb, TRUE);
    680         gtk_box_pack_start (GTK_BOX (h), w, 1, 1, GUI_PAD);
    681 
    682         hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, GUI_PAD);
    683             w = gtk_alignment_new (0.0f, 0.0f, 0.0f, 0.0f);
    684             gtk_widget_set_size_request (w, GUI_PAD, 0u);
    685             gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
    686             w = ul_lb = gtk_label_new (NULL);
    687             p->ul_lb = GTK_LABEL (w);
    688             gtk_label_set_single_line_mode (p->ul_lb, TRUE);
    689             gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
    690             w = gtk_image_new_from_stock (GTK_STOCK_GO_UP, GTK_ICON_SIZE_MENU);
    691             gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
    692         gtk_box_pack_end (GTK_BOX (h), hbox, FALSE, FALSE, 0);
    693 
    694         hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, GUI_PAD);
    695             w = gtk_alignment_new (0.0f, 0.0f, 0.0f, 0.0f);
    696             gtk_widget_set_size_request (w, GUI_PAD, 0u);
    697             gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
    698             w = dl_lb = gtk_label_new (NULL);
    699             p->dl_lb = GTK_LABEL (w);
    700             gtk_label_set_single_line_mode (p->dl_lb, TRUE);
    701             gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
    702             w = gtk_image_new_from_stock (GTK_STOCK_GO_DOWN, GTK_ICON_SIZE_MENU);
    703             gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
    704         gtk_box_pack_end (GTK_BOX (h), hbox, FALSE, FALSE, 0);
    705 
    706         hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, GUI_PAD);
    707             w = gtk_button_new ();
    708             gtk_widget_set_tooltip_text (w, _("Statistics"));
    709             gtk_container_add (GTK_CONTAINER (w), gtk_image_new_from_stock ("ratio", -1));
    710             gtk_button_set_relief (GTK_BUTTON (w), GTK_RELIEF_NONE);
    711             g_signal_connect (w, "clicked", G_CALLBACK (onYinYangReleased), p);
    712             gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
    713             w = gtk_label_new (NULL);
    714             p->stats_lb = GTK_LABEL (w);
    715             gtk_label_set_single_line_mode (p->stats_lb, TRUE);
    716             gtk_box_pack_end (GTK_BOX (hbox), w, FALSE, FALSE, 0);
    717         gtk_box_pack_end (GTK_BOX (h), hbox, FALSE, FALSE, 0);
    718 
    719 
    720     /* workarea */
    721     p->view = makeview (p);
    722     w = list = p->scroll = gtk_scrolled_window_new (NULL, NULL);
    723     gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (w),
    724                                     GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
    725     gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (w),
    726                                          GTK_SHADOW_IN);
    727     gtk_container_add (GTK_CONTAINER (w), p->view);
    728 
    729     /* lay out the widgets */
    730     gtk_box_pack_start (GTK_BOX (vbox), mainmenu, FALSE, FALSE, 0);
    731     gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0);
    732     gtk_box_pack_start (GTK_BOX (vbox), filter, FALSE, FALSE, 0);
    733     gtk_box_pack_start (GTK_BOX (vbox), list, TRUE, TRUE, 0);
    734     gtk_box_pack_start (GTK_BOX (vbox), status, FALSE, FALSE, 0);
    735 
    736     {
    737         /* this is to determine the maximum width/height for the label */
    738         int w=0, h=0;
    739         PangoLayout * pango_layout;
    740         pango_layout = gtk_widget_create_pango_layout (ul_lb, "999.99 kB/s");
    741         pango_layout_get_pixel_size (pango_layout, &w, &h);
    742         gtk_widget_set_size_request (ul_lb, w, h);
    743         gtk_widget_set_size_request (dl_lb, w, h);
    744         gtk_misc_set_alignment (GTK_MISC (ul_lb), 1.0, 0.5);
    745         gtk_misc_set_alignment (GTK_MISC (dl_lb), 1.0, 0.5);
    746         g_object_unref (G_OBJECT (pango_layout));
    747     }
    748 
    749     /* show all but the window */
    750     gtk_widget_show_all (vbox);
    751 
    752     /* listen for prefs changes that affect the window */
    753     p->core = core;
    754     prefsChanged (core, PREF_KEY_COMPACT_VIEW, self);
    755     prefsChanged (core, PREF_KEY_FILTERBAR, self);
    756     prefsChanged (core, PREF_KEY_STATUSBAR, self);
    757     prefsChanged (core, PREF_KEY_STATUSBAR_STATS, self);
    758     prefsChanged (core, PREF_KEY_TOOLBAR, self);
    759     prefsChanged (core, TR_PREFS_KEY_ALT_SPEED_ENABLED, self);
    760     p->pref_handler_id = g_signal_connect (core, "prefs-changed",
    761                                            G_CALLBACK (prefsChanged), self);
    762 
    763     tr_sessionSetAltSpeedFunc (gtr_core_session (core), onAltSpeedToggled, p);
    764 
    765     return self;
     601  int           i, n;
     602  const char  * pch;
     603  PrivateData * p;
     604  GtkWidget   * ul_lb, * dl_lb;
     605  GtkWidget   * mainmenu, *toolbar, *filter, *list, *status;
     606  GtkWidget   * vbox, *w, *self, *h, *hbox, *menu;
     607  GtkWindow   * win;
     608  GSList      * l;
     609
     610  p = g_new0 (PrivateData, 1);
     611
     612  /* make the window */
     613  self = gtk_application_window_new (app);
     614  g_object_set_qdata_full (G_OBJECT (self), get_private_data_key (), p, privateFree);
     615  win = GTK_WINDOW (self);
     616  gtk_window_set_title (win, g_get_application_name ());
     617  gtk_window_set_role (win, "tr-main");
     618  gtk_window_set_default_size (win,
     619                               gtr_pref_int_get (PREF_KEY_MAIN_WINDOW_WIDTH),
     620                               gtr_pref_int_get (PREF_KEY_MAIN_WINDOW_HEIGHT));
     621  gtk_window_move (win, gtr_pref_int_get (PREF_KEY_MAIN_WINDOW_X),
     622                        gtr_pref_int_get (PREF_KEY_MAIN_WINDOW_Y));
     623  if (gtr_pref_flag_get (PREF_KEY_MAIN_WINDOW_IS_MAXIMIZED))
     624    gtk_window_maximize (win);
     625  gtk_window_add_accel_group (win, gtk_ui_manager_get_accel_group (ui_mgr));
     626
     627  /* window's main container */
     628  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
     629  gtk_container_add (GTK_CONTAINER (self), vbox);
     630
     631  /* main menu */
     632  mainmenu = gtr_action_get_widget ("/main-window-menu");
     633  w = gtr_action_get_widget ("/main-window-menu/torrent-menu/torrent-reannounce");
     634  g_signal_connect (w, "query-tooltip", G_CALLBACK (onAskTrackerQueryTooltip), p);
     635
     636  /* toolbar */
     637  toolbar = p->toolbar = gtr_action_get_widget ("/main-window-toolbar");
     638  gtk_style_context_add_class (gtk_widget_get_style_context (toolbar),
     639                               GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
     640  gtr_action_set_important ("open-torrent-toolbar", TRUE);
     641  gtr_action_set_important ("show-torrent-properties", TRUE);
     642
     643  /* filter */
     644  h = filter = p->filter = gtr_filter_bar_new (gtr_core_session (core),
     645                                               gtr_core_model (core),
     646                                               &p->filter_model);
     647  gtk_container_set_border_width (GTK_CONTAINER (h), GUI_PAD_SMALL);
     648
     649  /* status menu */
     650  menu = p->status_menu = gtk_menu_new ();
     651  l = NULL;
     652  pch = gtr_pref_string_get (PREF_KEY_STATUSBAR_STATS);
     653  for (i=0, n=G_N_ELEMENTS (stats_modes); i<n; ++i)
     654    {
     655      const char * val = stats_modes[i].val;
     656      w = gtk_radio_menu_item_new_with_label (l, _ (stats_modes[i].i18n));
     657      l = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (w));
     658      gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w), !strcmp (val, pch));
     659      g_object_set_data (G_OBJECT (w), STATS_MODE, (gpointer)stats_modes[i].val);
     660      g_signal_connect (w, "toggled", G_CALLBACK (status_menu_toggled_cb), p);
     661      gtk_menu_shell_append (GTK_MENU_SHELL (menu), w);
     662      gtk_widget_show (w);
     663    }
     664
     665  /* status */
     666  h = status = p->status = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, GUI_PAD_BIG);
     667  gtk_container_set_border_width (GTK_CONTAINER (h), GUI_PAD_SMALL);
     668
     669  w = gtk_button_new ();
     670  gtk_container_add (GTK_CONTAINER (w), gtk_image_new_from_stock ("utilities", -1));
     671  gtk_widget_set_tooltip_text (w, _("Options"));
     672  gtk_box_pack_start (GTK_BOX (h), w, 0, 0, 0);
     673  gtk_button_set_relief (GTK_BUTTON (w), GTK_RELIEF_NONE);
     674  p->options_menu = createOptionsMenu (p);
     675  g_signal_connect (w, "clicked", G_CALLBACK (onOptionsClicked), p);
     676
     677  p->alt_speed_image = gtk_image_new ();
     678  w = p->alt_speed_button = gtk_toggle_button_new ();
     679  gtk_button_set_image (GTK_BUTTON (w), p->alt_speed_image);
     680  gtk_button_set_relief (GTK_BUTTON (w), GTK_RELIEF_NONE);
     681  g_signal_connect (w, "toggled", G_CALLBACK (alt_speed_toggled_cb), p);
     682  gtk_box_pack_start (GTK_BOX (h), w, 0, 0, 0);
     683
     684  w = gtk_label_new ("N Torrents");
     685  p->gutter_lb = GTK_LABEL (w);
     686  gtk_label_set_single_line_mode (p->gutter_lb, TRUE);
     687  gtk_box_pack_start (GTK_BOX (h), w, 1, 1, GUI_PAD);
     688
     689  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, GUI_PAD);
     690    w = gtk_alignment_new (0.0f, 0.0f, 0.0f, 0.0f);
     691    gtk_widget_set_size_request (w, GUI_PAD, 0u);
     692    gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
     693    w = ul_lb = gtk_label_new (NULL);
     694    p->ul_lb = GTK_LABEL (w);
     695    gtk_label_set_single_line_mode (p->ul_lb, TRUE);
     696    gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
     697    w = gtk_image_new_from_stock (GTK_STOCK_GO_UP, GTK_ICON_SIZE_MENU);
     698    gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
     699  gtk_box_pack_end (GTK_BOX (h), hbox, FALSE, FALSE, 0);
     700
     701  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, GUI_PAD);
     702    w = gtk_alignment_new (0.0f, 0.0f, 0.0f, 0.0f);
     703    gtk_widget_set_size_request (w, GUI_PAD, 0u);
     704    gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
     705    w = dl_lb = gtk_label_new (NULL);
     706    p->dl_lb = GTK_LABEL (w);
     707    gtk_label_set_single_line_mode (p->dl_lb, TRUE);
     708    gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
     709    w = gtk_image_new_from_stock (GTK_STOCK_GO_DOWN, GTK_ICON_SIZE_MENU);
     710    gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
     711  gtk_box_pack_end (GTK_BOX (h), hbox, FALSE, FALSE, 0);
     712
     713  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, GUI_PAD);
     714    w = gtk_button_new ();
     715    gtk_widget_set_tooltip_text (w, _("Statistics"));
     716    gtk_container_add (GTK_CONTAINER (w), gtk_image_new_from_stock ("ratio", -1));
     717    gtk_button_set_relief (GTK_BUTTON (w), GTK_RELIEF_NONE);
     718    g_signal_connect (w, "clicked", G_CALLBACK (onYinYangReleased), p);
     719    gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
     720    w = gtk_label_new (NULL);
     721    p->stats_lb = GTK_LABEL (w);
     722    gtk_label_set_single_line_mode (p->stats_lb, TRUE);
     723    gtk_box_pack_end (GTK_BOX (hbox), w, FALSE, FALSE, 0);
     724  gtk_box_pack_end (GTK_BOX (h), hbox, FALSE, FALSE, 0);
     725
     726
     727  /* workarea */
     728  p->view = makeview (p);
     729  w = list = p->scroll = gtk_scrolled_window_new (NULL, NULL);
     730  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (w),
     731                                  GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
     732  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (w),
     733                                       GTK_SHADOW_IN);
     734  gtk_container_add (GTK_CONTAINER (w), p->view);
     735
     736  /* lay out the widgets */
     737  gtk_box_pack_start (GTK_BOX (vbox), mainmenu, FALSE, FALSE, 0);
     738  gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0);
     739  gtk_box_pack_start (GTK_BOX (vbox), filter, FALSE, FALSE, 0);
     740  gtk_box_pack_start (GTK_BOX (vbox), list, TRUE, TRUE, 0);
     741  gtk_box_pack_start (GTK_BOX (vbox), status, FALSE, FALSE, 0);
     742
     743  {
     744    /* this is to determine the maximum width/height for the label */
     745    int w=0, h=0;
     746    PangoLayout * pango_layout;
     747    pango_layout = gtk_widget_create_pango_layout (ul_lb, "999.99 kB/s");
     748    pango_layout_get_pixel_size (pango_layout, &w, &h);
     749    gtk_widget_set_size_request (ul_lb, w, h);
     750    gtk_widget_set_size_request (dl_lb, w, h);
     751    gtk_misc_set_alignment (GTK_MISC (ul_lb), 1.0, 0.5);
     752    gtk_misc_set_alignment (GTK_MISC (dl_lb), 1.0, 0.5);
     753    g_object_unref (G_OBJECT (pango_layout));
     754  }
     755
     756  /* show all but the window */
     757  gtk_widget_show_all (vbox);
     758
     759  /* listen for prefs changes that affect the window */
     760  p->core = core;
     761  prefsChanged (core, PREF_KEY_COMPACT_VIEW, self);
     762  prefsChanged (core, PREF_KEY_FILTERBAR, self);
     763  prefsChanged (core, PREF_KEY_STATUSBAR, self);
     764  prefsChanged (core, PREF_KEY_STATUSBAR_STATS, self);
     765  prefsChanged (core, PREF_KEY_TOOLBAR, self);
     766  prefsChanged (core, TR_PREFS_KEY_ALT_SPEED_ENABLED, self);
     767  p->pref_handler_id = g_signal_connect (core, "prefs-changed",
     768                                         G_CALLBACK (prefsChanged), self);
     769
     770  tr_sessionSetAltSpeedFunc (gtr_core_session (core), onAltSpeedToggled, p);
     771
     772  return self;
    766773}
    767774
     
    795802updateStats (PrivateData * p)
    796803{
    797     const char *            pch;
    798     char                    up[32], down[32], ratio[32], buf[512];
    799     struct tr_session_stats stats;
    800     tr_session *            session = gtr_core_session (p->core);
    801 
    802     /* update the stats */
    803     pch = gtr_pref_string_get (PREF_KEY_STATUSBAR_STATS);
    804     if (!strcmp (pch, "session-ratio"))
    805     {
    806         tr_sessionGetStats (session, &stats);
    807         tr_strlratio (ratio, stats.ratio, sizeof (ratio));
    808         g_snprintf (buf, sizeof (buf), _("Ratio: %s"), ratio);
    809     }
    810     else if (!strcmp (pch, "session-transfer"))
    811     {
    812         tr_sessionGetStats (session, &stats);
    813         tr_strlsize (up, stats.uploadedBytes, sizeof (up));
    814         tr_strlsize (down, stats.downloadedBytes, sizeof (down));
    815         /* Translators: "size|" is here for disambiguation. Please remove it from your translation.
    816            %1$s is the size of the data we've downloaded
    817            %2$s is the size of the data we've uploaded */
    818         g_snprintf (buf, sizeof (buf), Q_ (
    819                         "Down: %1$s, Up: %2$s"), down, up);
    820     }
    821     else if (!strcmp (pch, "total-transfer"))
    822     {
    823         tr_sessionGetCumulativeStats (session, &stats);
    824         tr_strlsize (up, stats.uploadedBytes, sizeof (up));
    825         tr_strlsize (down, stats.downloadedBytes, sizeof (down));
    826         /* Translators: "size|" is here for disambiguation. Please remove it from your translation.
    827            %1$s is the size of the data we've downloaded
    828            %2$s is the size of the data we've uploaded */
    829         g_snprintf (buf, sizeof (buf), Q_ (
    830                         "size|Down: %1$s, Up: %2$s"), down, up);
    831     }
    832     else     /* default is total-ratio */
    833     {
    834         tr_sessionGetCumulativeStats (session, &stats);
    835         tr_strlratio (ratio, stats.ratio, sizeof (ratio));
    836         g_snprintf (buf, sizeof (buf), _("Ratio: %s"), ratio);
    837     }
    838     gtr_label_set_text (p->stats_lb, buf);
     804  const char * pch;
     805  char up[32];
     806  char down[32];
     807  char ratio[32];
     808  char buf[512];
     809  struct tr_session_stats stats;
     810  tr_session * session = gtr_core_session (p->core);
     811
     812  /* update the stats */
     813  pch = gtr_pref_string_get (PREF_KEY_STATUSBAR_STATS);
     814  if (!strcmp (pch, "session-ratio"))
     815    {
     816      tr_sessionGetStats (session, &stats);
     817      tr_strlratio (ratio, stats.ratio, sizeof (ratio));
     818      g_snprintf (buf, sizeof (buf), _("Ratio: %s"), ratio);
     819    }
     820  else if (!strcmp (pch, "session-transfer"))
     821    {
     822      tr_sessionGetStats (session, &stats);
     823      tr_strlsize (up, stats.uploadedBytes, sizeof (up));
     824      tr_strlsize (down, stats.downloadedBytes, sizeof (down));
     825      /* Translators: "size|" is here for disambiguation. Please remove it from your translation.
     826         %1$s is the size of the data we've downloaded
     827         %2$s is the size of the data we've uploaded */
     828      g_snprintf (buf, sizeof (buf),
     829                  Q_("Down: %1$s, Up: %2$s"), down, up);
     830    }
     831  else if (!strcmp (pch, "total-transfer"))
     832    {
     833      tr_sessionGetCumulativeStats (session, &stats);
     834      tr_strlsize (up, stats.uploadedBytes, sizeof (up));
     835      tr_strlsize (down, stats.downloadedBytes, sizeof (down));
     836      /* Translators: "size|" is here for disambiguation. Please remove it from your translation.
     837         %1$s is the size of the data we've downloaded
     838         %2$s is the size of the data we've uploaded */
     839      g_snprintf (buf, sizeof (buf),
     840                  Q_( "size|Down: %1$s, Up: %2$s"), down, up);
     841    }
     842  else /* default is total-ratio */
     843    {
     844      tr_sessionGetCumulativeStats (session, &stats);
     845      tr_strlratio (ratio, stats.ratio, sizeof (ratio));
     846      g_snprintf (buf, sizeof (buf), _("Ratio: %s"), ratio);
     847    }
     848
     849  gtr_label_set_text (p->stats_lb, buf);
    839850}
    840851
     
    842853updateSpeeds (PrivateData * p)
    843854{
    844     tr_session * session = gtr_core_session (p->core);
    845 
    846     if (session != NULL)
    847     {
    848         char buf[128];
    849         double up=0, down=0;
    850         GtkTreeIter iter;
    851         GtkTreeModel * model = gtr_core_model (p->core);
    852 
    853         if (gtk_tree_model_iter_nth_child (model, &iter, NULL, 0)) do
     855  tr_session * session = gtr_core_session (p->core);
     856
     857  if (session != NULL)
     858    {
     859      char buf[128];
     860      double up=0, down=0;
     861      GtkTreeIter iter;
     862      GtkTreeModel * model = gtr_core_model (p->core);
     863
     864      if (gtk_tree_model_iter_nth_child (model, &iter, NULL, 0)) do
    854865        {
    855             double u, d;
    856             gtk_tree_model_get (model, &iter, MC_SPEED_UP, &u,
    857                                               MC_SPEED_DOWN, &d,
    858                                               -1);
    859             up += u;
    860             down += d;
     866          double u, d;
     867          gtk_tree_model_get (model, &iter, MC_SPEED_UP, &u,
     868                                            MC_SPEED_DOWN, &d,
     869                                            -1);
     870          up += u;
     871          down += d;
    861872        }
    862         while (gtk_tree_model_iter_next (model, &iter));
    863 
    864         tr_formatter_speed_KBps (buf, down, sizeof (buf));
    865         gtr_label_set_text (p->dl_lb, buf);
    866 
    867         tr_formatter_speed_KBps (buf, up, sizeof (buf));
    868         gtr_label_set_text (p->ul_lb, buf);
     873      while (gtk_tree_model_iter_next (model, &iter));
     874
     875      tr_formatter_speed_KBps (buf, down, sizeof (buf));
     876      gtr_label_set_text (p->dl_lb, buf);
     877
     878      tr_formatter_speed_KBps (buf, up, sizeof (buf));
     879      gtr_label_set_text (p->ul_lb, buf);
    869880    }
    870881}
     
    873884gtr_window_refresh (GtkWindow * self)
    874885{
    875     PrivateData * p = get_private_data (self);
    876 
    877     if (p && p->core && gtr_core_session (p->core))
    878     {
    879         updateSpeeds (p);
    880         updateTorrentCount (p);
    881         updateStats (p);
     886  PrivateData * p = get_private_data (self);
     887
     888  if (p && p->core && gtr_core_session (p->core))
     889    {
     890      updateSpeeds (p);
     891      updateTorrentCount (p);
     892      updateStats (p);
    882893    }
    883894}
     
    890901
    891902void
    892 gtr_window_set_busy (GtkWindow * w, gboolean isBusy)
    893 {
    894     if (w && gtk_widget_get_realized (GTK_WIDGET (w)))
    895     {
    896         GdkDisplay * display = gtk_widget_get_display (GTK_WIDGET (w));
    897         GdkCursor * cursor = isBusy ? gdk_cursor_new_for_display (display, GDK_WATCH) : NULL;
    898 
    899         gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (w)), cursor);
    900         gdk_display_flush (display);
    901 
    902         g_clear_object (&cursor);
    903     }
    904 }
     903gtr_window_set_busy (GtkWindow * win, gboolean isBusy)
     904{
     905  GtkWidget * w = GTK_WIDGET (win);
     906
     907  if (w && gtk_widget_get_realized (w))
     908    {
     909      GdkDisplay * display = gtk_widget_get_display (w);
     910      GdkCursor * cursor = isBusy ? gdk_cursor_new_for_display (display, GDK_WATCH) : NULL;
     911
     912      gdk_window_set_cursor (gtk_widget_get_window (w), cursor);
     913      gdk_display_flush (display);
     914
     915      g_clear_object (&cursor);
     916    }
     917}
Note: See TracChangeset for help on using the changeset viewer.