Ignore:
Timestamp:
Jan 27, 2013, 11:05:47 PM (8 years ago)
Author:
jordan
Message:

synchronize the Qt and GTK+ client's statusbars, including the new freespace indicator. Make the up/down speed ordering consistent between statusbar and torrent list.

File:
1 edited

Legend:

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

    r13822 r13891  
    5555    GtkLabel           * dl_lb;
    5656    GtkLabel           * stats_lb;
    57     GtkLabel           * gutter_lb;
     57    GtkLabel           * freespace_lb;
     58    GtkWidget          * freespace_icon;
     59    GtkLabel           * count_lb;
    5860    GtkWidget          * alt_speed_image;
    5961    GtkWidget          * alt_speed_button;
     
    608610  const char     * pch, * style;
    609611  PrivateData    * p;
     612  GtkWidget      * sibling = NULL;
    610613  GtkWidget      * ul_lb, * dl_lb;
    611614  GtkWidget      * mainmenu, *toolbar, *filter, *list, *status;
    612   GtkWidget      * vbox, *w, *self, *h, *hbox, *menu;
     615  GtkWidget      * vbox, *w, *self, *menu;
     616  GtkWidget      * grid_w;
    613617  GtkWindow      * win;
    614618  GtkCssProvider * css_provider;
    615619  GSList         * l;
     620  GtkGrid        * grid;
    616621
    617622  p = g_new0 (PrivateData, 1);
     
    658663
    659664  /* filter */
    660   h = filter = p->filter = gtr_filter_bar_new (gtr_core_session (core),
     665  w = filter = p->filter = gtr_filter_bar_new (gtr_core_session (core),
    661666                                               gtr_core_model (core),
    662667                                               &p->filter_model);
    663   gtk_container_set_border_width (GTK_CONTAINER (h), GUI_PAD_SMALL);
     668  gtk_container_set_border_width (GTK_CONTAINER (w), GUI_PAD_SMALL);
    664669
    665670  /* status menu */
     
    679684    }
    680685
    681   /* status */
    682   h = status = p->status = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, GUI_PAD_BIG);
    683   gtk_container_set_border_width (GTK_CONTAINER (h), GUI_PAD_SMALL);
    684 
     686  /**
     687  *** Statusbar
     688  **/
     689
     690  grid_w = status = p->status = gtk_grid_new ();
     691  grid = GTK_GRID (grid_w);
     692  gtk_container_set_border_width (GTK_CONTAINER (grid), GUI_PAD_SMALL);
     693
     694  /* gear */
    685695  w = gtk_button_new ();
    686696  gtk_container_add (GTK_CONTAINER (w), gtk_image_new_from_stock ("utilities", -1));
    687697  gtk_widget_set_tooltip_text (w, _("Options"));
    688   gtk_box_pack_start (GTK_BOX (h), w, 0, 0, 0);
     698  gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
    689699  gtk_button_set_relief (GTK_BUTTON (w), GTK_RELIEF_NONE);
    690700  p->options_menu = createOptionsMenu (p);
    691701  g_signal_connect (w, "clicked", G_CALLBACK (onOptionsClicked), p);
    692 
     702  sibling = w;
     703
     704  /* turtle */
    693705  p->alt_speed_image = gtk_image_new ();
    694706  w = p->alt_speed_button = gtk_toggle_button_new ();
     
    696708  gtk_button_set_relief (GTK_BUTTON (w), GTK_RELIEF_NONE);
    697709  g_signal_connect (w, "toggled", G_CALLBACK (alt_speed_toggled_cb), p);
    698   gtk_box_pack_start (GTK_BOX (h), w, 0, 0, 0);
    699 
     710  gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
     711  sibling = w;
     712
     713  /* spacer */
     714  w = gtk_alignment_new (0.0f, 0.0f, 0.0f, 0.0f);
     715  gtk_widget_set_hexpand (w, TRUE);
     716  gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
     717  sibling = w;
     718
     719  /* torrent count */
    700720  w = gtk_label_new ("N Torrents");
    701   p->gutter_lb = GTK_LABEL (w);
    702   gtk_label_set_single_line_mode (p->gutter_lb, TRUE);
    703   gtk_box_pack_start (GTK_BOX (h), w, 1, 1, GUI_PAD);
    704 
    705   hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, GUI_PAD);
    706     w = gtk_alignment_new (0.0f, 0.0f, 0.0f, 0.0f);
    707     gtk_widget_set_size_request (w, GUI_PAD, 0u);
    708     gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
    709     w = ul_lb = gtk_label_new (NULL);
    710     p->ul_lb = GTK_LABEL (w);
    711     gtk_label_set_single_line_mode (p->ul_lb, TRUE);
    712     gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
    713     w = gtk_image_new_from_stock (GTK_STOCK_GO_UP, GTK_ICON_SIZE_MENU);
    714     gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
    715   gtk_box_pack_end (GTK_BOX (h), hbox, FALSE, FALSE, 0);
    716 
    717   hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, GUI_PAD);
    718     w = gtk_alignment_new (0.0f, 0.0f, 0.0f, 0.0f);
    719     gtk_widget_set_size_request (w, GUI_PAD, 0u);
    720     gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
    721     w = dl_lb = gtk_label_new (NULL);
    722     p->dl_lb = GTK_LABEL (w);
    723     gtk_label_set_single_line_mode (p->dl_lb, TRUE);
    724     gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
    725     w = gtk_image_new_from_stock (GTK_STOCK_GO_DOWN, GTK_ICON_SIZE_MENU);
    726     gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
    727   gtk_box_pack_end (GTK_BOX (h), hbox, FALSE, FALSE, 0);
    728 
    729   hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, GUI_PAD);
    730     w = gtk_button_new ();
    731     gtk_widget_set_tooltip_text (w, _("Statistics"));
    732     gtk_container_add (GTK_CONTAINER (w), gtk_image_new_from_stock ("ratio", -1));
    733     gtk_button_set_relief (GTK_BUTTON (w), GTK_RELIEF_NONE);
    734     g_signal_connect (w, "clicked", G_CALLBACK (onYinYangReleased), p);
    735     gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
    736     w = gtk_label_new (NULL);
    737     p->stats_lb = GTK_LABEL (w);
    738     gtk_label_set_single_line_mode (p->stats_lb, TRUE);
    739     gtk_box_pack_end (GTK_BOX (hbox), w, FALSE, FALSE, 0);
    740   gtk_box_pack_end (GTK_BOX (h), hbox, FALSE, FALSE, 0);
    741 
     721  p->count_lb = GTK_LABEL (w);
     722  gtk_label_set_single_line_mode (p->count_lb, TRUE);
     723  gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
     724  sibling = w;
     725
     726  /* freespace */
     727  w = gtk_label_new (NULL);
     728  g_object_set (G_OBJECT(w), "margin-left", GUI_PAD_BIG*2, NULL);
     729  p->freespace_lb = GTK_LABEL (w);
     730  gtk_label_set_single_line_mode (p->freespace_lb, TRUE);
     731  gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
     732  sibling = w;
     733  w = gtk_image_new_from_stock (GTK_STOCK_HARDDISK, GTK_ICON_SIZE_MENU);
     734  p->freespace_icon = w;
     735  g_object_set (G_OBJECT(w), "margin-left", GUI_PAD, NULL);
     736  gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
     737  sibling = w;
     738
     739  /* spacer */
     740  w = gtk_alignment_new (0.0f, 0.0f, 0.0f, 0.0f);
     741  gtk_widget_set_hexpand (w, TRUE);
     742  gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
     743  sibling = w;
     744
     745  /* ratio */
     746  w = gtk_label_new (NULL);
     747  p->stats_lb = GTK_LABEL (w);
     748  gtk_label_set_single_line_mode (p->stats_lb, TRUE);
     749  gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
     750  sibling = w;
     751  w = gtk_button_new ();
     752  gtk_widget_set_tooltip_text (w, _("Statistics"));
     753  gtk_container_add (GTK_CONTAINER (w), gtk_image_new_from_stock ("ratio", -1));
     754  gtk_button_set_relief (GTK_BUTTON (w), GTK_RELIEF_NONE);
     755  g_signal_connect (w, "clicked", G_CALLBACK (onYinYangReleased), p);
     756  gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
     757  sibling = w;
     758
     759  /* upload */
     760  w = ul_lb = gtk_label_new (NULL);
     761  p->ul_lb = GTK_LABEL (w);
     762  gtk_label_set_single_line_mode (p->ul_lb, TRUE);
     763  gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
     764  sibling = w;
     765  w = gtk_image_new_from_stock (GTK_STOCK_GO_UP, GTK_ICON_SIZE_MENU);
     766  g_object_set (G_OBJECT(w), "margin-left", GUI_PAD, NULL);
     767  gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
     768  sibling = w;
     769
     770  /* download */
     771  w = dl_lb = gtk_label_new (NULL);
     772  p->dl_lb = GTK_LABEL (w);
     773  gtk_label_set_single_line_mode (p->dl_lb, TRUE);
     774  gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
     775  sibling = w;
     776  w = gtk_image_new_from_stock (GTK_STOCK_GO_DOWN, GTK_ICON_SIZE_MENU);
     777  g_object_set (G_OBJECT(w), "margin-left", GUI_PAD, NULL);
     778  gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
     779  sibling = w;
    742780
    743781  /* workarea */
     
    793831updateTorrentCount (PrivateData * p)
    794832{
    795   if (p && p->core)
    796     {
    797       char buf[512];
     833  bool visible = false;
     834
     835  g_return_if_fail (p != NULL);
     836
     837  if (p->core != NULL)
     838    {
    798839      const int torrentCount = gtk_tree_model_iter_n_children (gtr_core_model (p->core), NULL);
    799840      const int visibleCount = gtk_tree_model_iter_n_children (p->filter_model, NULL);
    800841
    801       if (!torrentCount)
    802         *buf = '\0';
    803       else if (torrentCount != visibleCount)
    804         g_snprintf (buf, sizeof (buf),
    805                     ngettext ("%1$'d of %2$'d Torrent",
    806                               "%1$'d of %2$'d Torrents",
    807                               torrentCount),
    808                     visibleCount, torrentCount);
    809       else
    810         g_snprintf (buf, sizeof (buf),
    811                     ngettext ("%'d Torrent", "%'d Torrents", torrentCount),
    812                     torrentCount);
    813 
    814       gtr_label_set_text (p->gutter_lb, buf);
    815     }
     842      visible = torrentCount > 0;
     843
     844      if (visible)
     845        {
     846          char countStr[512];
     847
     848          if (torrentCount != visibleCount)
     849            g_snprintf (countStr, sizeof (countStr),
     850                        ngettext ("%1$'d of %2$'d Torrent",
     851                                  "%1$'d of %2$'d Torrents",
     852                                  torrentCount),
     853                        visibleCount, torrentCount);
     854          else
     855            g_snprintf (countStr, sizeof (countStr),
     856                        ngettext ("%'d Torrent", "%'d Torrents", torrentCount),
     857                        torrentCount);
     858
     859          gtr_label_set_text (p->count_lb, countStr);
     860        }
     861    }
     862
     863  gtk_widget_set_visible (GTK_WIDGET(p->count_lb), visible);
     864}
     865
     866static void
     867updateFreeSpace (PrivateData * p)
     868{
     869  GtkWidget * w;
     870  bool visible = false;
     871
     872  g_return_if_fail (p != NULL);
     873
     874  w = GTK_WIDGET (p->freespace_lb);
     875
     876  if (p->core != NULL)
     877    {
     878      tr_session * session = gtr_core_session (p->core);
     879      const int64_t n = tr_sessionGetDownloadDirFreeSpace (session);
     880      const char * downloadDir = tr_sessionGetDownloadDir (session);
     881
     882      visible = n >= 0;
     883
     884      if (visible)
     885        {
     886          char * tip;
     887          char sizeStr[32];
     888          tr_strlsize (sizeStr, n, sizeof(sizeStr));
     889          gtk_label_set_text (p->freespace_lb, sizeStr);
     890          tip = tr_strdup_printf (_("Download folder \"%1$s\" has %2$s free"), downloadDir, sizeStr);
     891          gtk_widget_set_tooltip_text (w, tip);
     892          g_free (tip);
     893        }
     894    }
     895
     896  gtk_widget_set_visible (w, visible);
     897  gtk_widget_set_visible (p->freespace_icon, visible);
    816898}
    817899
     
    908990      updateTorrentCount (p);
    909991      updateStats (p);
     992      updateFreeSpace (p);
    910993    }
    911994}
Note: See TracChangeset for help on using the changeset viewer.