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

fewer redundant gobject dynamic casts

File:
1 edited

Legend:

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

    r13625 r13656  
    5252    GtkWidget *           status;
    5353    GtkWidget *           status_menu;
    54     GtkWidget *           ul_lb;
    55     GtkWidget *           dl_lb;
    56     GtkWidget *           stats_lb;
    57     GtkWidget *           gutter_lb;
     54    GtkLabel *           ul_lb;
     55    GtkLabel *           dl_lb;
     56    GtkLabel *           stats_lb;
     57    GtkLabel *           gutter_lb;
    5858    GtkWidget *           alt_speed_image;
    5959    GtkWidget *           alt_speed_button;
     
    413413    int i, n;
    414414    GtkWidget *w, *m;
     415    GtkMenuShell * menu_shell;
    415416    const int speeds_KBps[] = { 5, 10, 20, 30, 40, 50, 75, 100, 150, 200, 250, 500, 750 };
    416417
    417418    m = gtk_menu_new ();
     419    menu_shell = GTK_MENU_SHELL (m);
    418420
    419421    w = gtk_radio_menu_item_new_with_label (NULL, _("Unlimited"));
     
    422424    g_object_set_data (G_OBJECT (w), ENABLED_KEY, GINT_TO_POINTER (FALSE));
    423425    g_signal_connect (w, "toggled", G_CALLBACK (onSpeedToggled), p);
    424     gtk_menu_shell_append (GTK_MENU_SHELL (m), w);
     426    gtk_menu_shell_append (menu_shell, w);
    425427
    426428    w = gtk_radio_menu_item_new_with_label_from_widget (GTK_RADIO_MENU_ITEM (w), "");
     
    429431    g_object_set_data (G_OBJECT (w), ENABLED_KEY, GINT_TO_POINTER (TRUE));
    430432    g_signal_connect (w, "toggled", G_CALLBACK (onSpeedToggled), p);
    431     gtk_menu_shell_append (GTK_MENU_SHELL (m), w);
     433    gtk_menu_shell_append (menu_shell, w);
    432434
    433435    w = gtk_separator_menu_item_new ();
    434     gtk_menu_shell_append (GTK_MENU_SHELL (m), w);
     436    gtk_menu_shell_append (menu_shell, w);
    435437
    436438    for (i=0, n=G_N_ELEMENTS (speeds_KBps); i<n; ++i)
     
    442444        g_object_set_data (G_OBJECT (w), SPEED_KEY, GINT_TO_POINTER (speeds_KBps[i]));
    443445        g_signal_connect (w, "activate", G_CALLBACK (onSpeedSet), p);
    444         gtk_menu_shell_append (GTK_MENU_SHELL (m), w);
     446        gtk_menu_shell_append (menu_shell, w);
    445447    }
    446448
     
    480482{
    481483    int i, n;
    482     GtkWidget *m, *w;
     484    GtkWidget *m, *w;
     485    GtkMenuShell * menu_shell;
    483486
    484487    m = gtk_menu_new ();
     488    menu_shell = GTK_MENU_SHELL (m);
    485489
    486490    w = gtk_radio_menu_item_new_with_label (NULL, _("Seed Forever"));
     
    488492    g_object_set_data (G_OBJECT (w), ENABLED_KEY, GINT_TO_POINTER (FALSE));
    489493    g_signal_connect (w, "toggled", G_CALLBACK (onRatioToggled), p);
    490     gtk_menu_shell_append (GTK_MENU_SHELL (m), w);
     494    gtk_menu_shell_append (menu_shell, w);
    491495
    492496    w = gtk_radio_menu_item_new_with_label_from_widget (GTK_RADIO_MENU_ITEM (w), "");
     
    494498    g_object_set_data (G_OBJECT (w), ENABLED_KEY, GINT_TO_POINTER (TRUE));
    495499    g_signal_connect (w, "toggled", G_CALLBACK (onRatioToggled), p);
    496     gtk_menu_shell_append (GTK_MENU_SHELL (m), w);
     500    gtk_menu_shell_append (menu_shell, w);
    497501
    498502    w = gtk_separator_menu_item_new ();
    499     gtk_menu_shell_append (GTK_MENU_SHELL (m), w);
     503    gtk_menu_shell_append (menu_shell, w);
    500504
    501505    for (i=0, n=G_N_ELEMENTS (stockRatios); i<n; ++i)
     
    506510        g_object_set_data (G_OBJECT (w), RATIO_KEY, GINT_TO_POINTER (i));
    507511        g_signal_connect (w, "activate", G_CALLBACK (onRatioSet), p);
    508         gtk_menu_shell_append (GTK_MENU_SHELL (m), w);
     512        gtk_menu_shell_append (menu_shell, w);
    509513    }
    510514
     
    521525    GtkWidget * m;
    522526    GtkWidget * top = gtk_menu_new ();
     527    GtkMenuShell * menu_shell = GTK_MENU_SHELL (top);
    523528
    524529    m = gtk_menu_item_new_with_label (_("Limit Download Speed"));
    525530    gtk_menu_item_set_submenu (GTK_MENU_ITEM (m), createSpeedMenu (p, TR_DOWN));
    526     gtk_menu_shell_append (GTK_MENU_SHELL (top), m);
     531    gtk_menu_shell_append (menu_shell, m);
    527532
    528533    m = gtk_menu_item_new_with_label (_("Limit Upload Speed"));
    529534    gtk_menu_item_set_submenu (GTK_MENU_ITEM (m), createSpeedMenu (p, TR_UP));
    530     gtk_menu_shell_append (GTK_MENU_SHELL (top), m);
     535    gtk_menu_shell_append (menu_shell, m);
    531536
    532537    m = gtk_separator_menu_item_new ();
    533     gtk_menu_shell_append (GTK_MENU_SHELL (top), m);
     538    gtk_menu_shell_append (menu_shell, m);
    534539
    535540    m = gtk_menu_item_new_with_label (_("Stop Seeding at Ratio"));
    536541    gtk_menu_item_set_submenu (GTK_MENU_ITEM (m), createRatioMenu (p));
    537     gtk_menu_shell_append (GTK_MENU_SHELL (top), m);
     542    gtk_menu_shell_append (menu_shell, m);
    538543
    539544    gtk_widget_show_all (top);
     
    586591    const char  * pch;
    587592    PrivateData * p;
     593    GtkWidget   * ul_lb, * dl_lb;
    588594    GtkWidget   * mainmenu, *toolbar, *filter, *list, *status;
    589595    GtkWidget   * vbox, *w, *self, *h, *hbox, *menu;
     
    669675        gtk_box_pack_start (GTK_BOX (h), w, 0, 0, 0);
    670676
    671         w = p->gutter_lb = gtk_label_new ("N Torrents");
    672         gtk_label_set_single_line_mode (GTK_LABEL (w), TRUE);
     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);
    673680        gtk_box_pack_start (GTK_BOX (h), w, 1, 1, GUI_PAD);
    674681
     
    677684            gtk_widget_set_size_request (w, GUI_PAD, 0u);
    678685            gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
    679             w = p->ul_lb = gtk_label_new (NULL);
    680             gtk_label_set_single_line_mode (GTK_LABEL (w), TRUE);
     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);
    681689            gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
    682690            w = gtk_image_new_from_stock (GTK_STOCK_GO_UP, GTK_ICON_SIZE_MENU);
     
    688696            gtk_widget_set_size_request (w, GUI_PAD, 0u);
    689697            gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
    690             w = p->dl_lb = gtk_label_new (NULL);
    691             gtk_label_set_single_line_mode (GTK_LABEL (w), TRUE);
     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);
    692701            gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
    693702            w = gtk_image_new_from_stock (GTK_STOCK_GO_DOWN, GTK_ICON_SIZE_MENU);
     
    702711            g_signal_connect (w, "clicked", G_CALLBACK (onYinYangReleased), p);
    703712            gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
    704             w = p->stats_lb = gtk_label_new (NULL);
    705             gtk_label_set_single_line_mode (GTK_LABEL (w), TRUE);
     713            w = gtk_label_new (NULL);
     714            p->stats_lb = GTK_LABEL (w);
     715            gtk_label_set_single_line_mode (p->stats_lb, TRUE);
    706716            gtk_box_pack_end (GTK_BOX (hbox), w, FALSE, FALSE, 0);
    707717        gtk_box_pack_end (GTK_BOX (h), hbox, FALSE, FALSE, 0);
     
    728738        int w=0, h=0;
    729739        PangoLayout * pango_layout;
    730         pango_layout = gtk_widget_create_pango_layout (p->ul_lb, "999.99 kB/s");
     740        pango_layout = gtk_widget_create_pango_layout (ul_lb, "999.99 kB/s");
    731741        pango_layout_get_pixel_size (pango_layout, &w, &h);
    732         gtk_widget_set_size_request (p->ul_lb, w, h);
    733         gtk_widget_set_size_request (p->dl_lb, w, h);
    734         gtk_misc_set_alignment (GTK_MISC (p->ul_lb), 1.0, 0.5);
    735         gtk_misc_set_alignment (GTK_MISC (p->dl_lb), 1.0, 0.5);
     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);
    736746        g_object_unref (G_OBJECT (pango_layout));
    737747    }
     
    759769updateTorrentCount (PrivateData * p)
    760770{
    761     if (p && p->core)
    762     {
    763         char      buf[512];
    764         const int torrentCount = gtk_tree_model_iter_n_children (gtr_core_model (p->core), NULL);
    765         const int visibleCount = gtk_tree_model_iter_n_children (p->filter_model, NULL);
    766 
    767         if (!torrentCount)
    768             *buf = '\0';
    769         else if (torrentCount != visibleCount)
    770             g_snprintf (buf, sizeof (buf),
    771                         ngettext ("%1$'d of %2$'d Torrent",
    772                                   "%1$'d of %2$'d Torrents",
    773                                   torrentCount),
    774                         visibleCount, torrentCount);
    775         else
    776             g_snprintf (buf, sizeof (buf),
    777                         ngettext ("%'d Torrent", "%'d Torrents", torrentCount),
    778                         torrentCount);
    779         gtr_label_set_text (GTK_LABEL (p->gutter_lb), buf);
     771  if (p && p->core)
     772    {
     773      char buf[512];
     774      const int torrentCount = gtk_tree_model_iter_n_children (gtr_core_model (p->core), NULL);
     775      const int visibleCount = gtk_tree_model_iter_n_children (p->filter_model, NULL);
     776
     777      if (!torrentCount)
     778        *buf = '\0';
     779      else if (torrentCount != visibleCount)
     780        g_snprintf (buf, sizeof (buf),
     781                    ngettext ("%1$'d of %2$'d Torrent",
     782                              "%1$'d of %2$'d Torrents",
     783                              torrentCount),
     784                    visibleCount, torrentCount);
     785      else
     786        g_snprintf (buf, sizeof (buf),
     787                    ngettext ("%'d Torrent", "%'d Torrents", torrentCount),
     788                    torrentCount);
     789
     790      gtr_label_set_text (p->gutter_lb, buf);
    780791    }
    781792}
     
    825836        g_snprintf (buf, sizeof (buf), _("Ratio: %s"), ratio);
    826837    }
    827     gtr_label_set_text (GTK_LABEL (p->stats_lb), buf);
     838    gtr_label_set_text (p->stats_lb, buf);
    828839}
    829840
     
    852863
    853864        tr_formatter_speed_KBps (buf, down, sizeof (buf));
    854         gtr_label_set_text (GTK_LABEL (p->dl_lb), buf);
     865        gtr_label_set_text (p->dl_lb, buf);
    855866
    856867        tr_formatter_speed_KBps (buf, up, sizeof (buf));
    857         gtr_label_set_text (GTK_LABEL (p->ul_lb), buf);
     868        gtr_label_set_text (p->ul_lb, buf);
    858869    }
    859870}
Note: See TracChangeset for help on using the changeset viewer.