Changeset 13927


Ignore:
Timestamp:
Feb 1, 2013, 8:58:55 PM (8 years ago)
Author:
jordan
Message:

in the Qt and GTK+ clients, move the torrent count indicator from the statusbar to the filterbar

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/filter.c

    r13732 r13927  
    792792  GtkWidget * tracker;
    793793  GtkWidget * entry;
     794  GtkWidget * show_lb;
    794795  GtkTreeModel * filter_model;
    795796  int active_activity_type;
     
    855856}
    856857
     858/***
     859****
     860***/
     861
     862static void
     863update_count_label (struct filter_data * data)
     864{
     865  char buf[512];
     866  GtkTreeModel * tmodel = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (data->filter_model));
     867  const int torrentCount = gtk_tree_model_iter_n_children (tmodel, NULL);
     868  const int visibleCount = gtk_tree_model_iter_n_children (data->filter_model, NULL);
     869
     870  /* set the text */
     871  if (visibleCount == torrentCount)
     872    g_snprintf (buf, sizeof(buf), _("_Show:"));
     873  else
     874    g_snprintf (buf, sizeof(buf), _("_Show %'d:"), visibleCount);
     875  gtk_label_set_markup_with_mnemonic (GTK_LABEL (data->show_lb), buf);
     876}
     877
     878static void
     879on_filter_model_row_inserted (GtkTreeModel * tree_model UNUSED,
     880                              GtkTreePath  * path       UNUSED,
     881                              GtkTreeIter  * iter       UNUSED,
     882                              gpointer       data)
     883{
     884  update_count_label (data);
     885}
     886
     887static void
     888on_filter_model_row_deleted (GtkTreeModel * tree_model UNUSED,
     889                             GtkTreePath  * path       UNUSED,
     890                             gpointer       data       UNUSED)
     891{
     892  update_count_label (data);
     893}
     894
     895/***
     896****
     897***/
     898
    857899GtkWidget *
    858900gtr_filter_bar_new (tr_session * session, GtkTreeModel * tmodel, GtkTreeModel ** filter_model)
     
    865907  GtkWidget * tracker;
    866908  GtkBox * h_box;
    867   const char * str;
    868909  struct filter_data * data;
    869910
     
    875916
    876917  data = g_new0 (struct filter_data, 1);
     918  data->show_lb = gtk_label_new (NULL);
    877919  data->activity = activity = activity_combo_box_new (tmodel);
    878920  data->tracker = tracker = tracker_combo_box_new (tmodel);
    879921  data->filter_model = gtk_tree_model_filter_new (tmodel, NULL);
     922  g_signal_connect (data->filter_model, "row-deleted", G_CALLBACK(on_filter_model_row_deleted), data);
     923  g_signal_connect (data->filter_model, "row-inserted", G_CALLBACK(on_filter_model_row_inserted), data);
    880924
    881925  g_object_set (G_OBJECT (data->tracker), "width-request", 170, NULL);
     
    893937
    894938  /* add the activity combobox */
    895   str = _("_Show:");
    896939  w = activity;
    897   l = gtk_label_new (NULL);
    898   gtk_label_set_markup_with_mnemonic (GTK_LABEL (l), str);
     940  l = data->show_lb;
    899941  gtk_label_set_mnemonic_widget (GTK_LABEL (l), w);
    900942  gtk_box_pack_start (h_box, l, FALSE, FALSE, 0);
     
    925967
    926968  *filter_model = data->filter_model;
     969  update_count_label (data);
    927970  return h;
    928971}
  • trunk/gtk/tr-window.c

    r13897 r13927  
    5757    GtkLabel           * freespace_lb;
    5858    GtkWidget          * freespace_icon;
    59     GtkLabel           * count_lb;
    6059    GtkWidget          * alt_speed_image;
    6160    GtkWidget          * alt_speed_button;
     
    717716  sibling = w;
    718717
    719   /* torrent count */
    720   w = gtk_label_new ("N Torrents");
    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 
    726718  /* freespace */
     719  w = gtk_image_new_from_stock (GTK_STOCK_HARDDISK, GTK_ICON_SIZE_MENU);
     720  p->freespace_icon = w;
     721  g_object_set (G_OBJECT(w), "margin-left", GUI_PAD, NULL);
     722  gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
     723  sibling = w;
    727724  w = gtk_label_new (NULL);
    728725  g_object_set (G_OBJECT(w), "margin-left", GUI_PAD_BIG*2, NULL);
    729726  p->freespace_lb = GTK_LABEL (w);
    730727  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);
    736728  gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
    737729  sibling = w;
     
    831823
    832824static void
    833 updateTorrentCount (PrivateData * p)
    834 {
    835   bool visible = false;
    836 
    837   g_return_if_fail (p != NULL);
    838 
    839   if (p->core != NULL)
    840     {
    841       const int torrentCount = gtk_tree_model_iter_n_children (gtr_core_model (p->core), NULL);
    842       const int visibleCount = gtk_tree_model_iter_n_children (p->filter_model, NULL);
    843 
    844       visible = torrentCount > 0;
    845 
    846       if (visible)
    847         {
    848           char countStr[512];
    849 
    850           if (torrentCount != visibleCount)
    851             g_snprintf (countStr, sizeof (countStr),
    852                         ngettext ("%1$'d of %2$'d Torrent",
    853                                   "%1$'d of %2$'d Torrents",
    854                                   torrentCount),
    855                         visibleCount, torrentCount);
    856           else
    857             g_snprintf (countStr, sizeof (countStr),
    858                         ngettext ("%'d Torrent", "%'d Torrents", torrentCount),
    859                         torrentCount);
    860 
    861           gtr_label_set_text (p->count_lb, countStr);
    862         }
    863     }
    864 
    865   gtk_widget_set_visible (GTK_WIDGET(p->count_lb), visible);
    866 }
    867 
    868 static void
    869825updateFreeSpace (PrivateData * p)
    870826{
     
    888844          char * tip;
    889845          char sizeStr[32];
     846
    890847          tr_strlsize (sizeStr, n, sizeof(sizeStr));
    891848          gtk_label_set_text (p->freespace_lb, sizeStr);
     849
    892850          tip = tr_strdup_printf (_("Download folder \"%1$s\" has %2$s free"), downloadDir, sizeStr);
    893851          gtk_widget_set_tooltip_text (w, tip);
     
    990948    {
    991949      updateSpeeds (p);
    992       updateTorrentCount (p);
    993950      updateStats (p);
    994951      updateFreeSpace (p);
  • trunk/qt/filterbar.cc

    r13869 r13927  
    407407  const int hmargin = qMax (int (HIG::PAD), style ()->pixelMetric (QStyle::PM_LayoutHorizontalSpacing));
    408408
     409  myCountLabel = new QLabel;
    409410  h->setSpacing (0);
    410411  h->setContentsMargins (2, 2, 2, 2);
    411   h->addWidget (new QLabel (tr ("Show:"), this));
     412  h->addWidget (myCountLabel);
    412413  h->addSpacing (hmargin);
    413414
     
    438439  connect (myActivityCombo, SIGNAL (currentIndexChanged (int)), this, SLOT (onActivityIndexChanged (int)));
    439440  connect (myTrackerCombo, SIGNAL (currentIndexChanged (int)), this, SLOT (onTrackerIndexChanged (int)));
     441  connect (&myFilter, SIGNAL (rowsInserted (const QModelIndex&,int,int)), this, SLOT (refreshCountLabel ()));
     442  connect (&myFilter, SIGNAL (rowsRemoved (const QModelIndex&,int,int)), this, SLOT (refreshCountLabel ()));
    440443  connect (&myTorrents, SIGNAL (modelReset ()), this, SLOT (onTorrentModelReset ()));
    441444  connect (&myTorrents, SIGNAL (rowsInserted (const QModelIndex&,int,int)), this, SLOT (onTorrentModelRowsInserted (const QModelIndex&,int,int)));
     
    446449  recountSoon ();
    447450  refreshTrackers ();
     451  refreshCountLabel ();
    448452  myIsBootstrapping = false;
    449453
     
    579583  return QString ("%L1").arg (n);
    580584}
     585
     586void
     587FilterBar :: refreshCountLabel ()
     588{
     589  const int visibleCount = myFilter.rowCount ();
     590  const int torrentCount = visibleCount + myFilter.hiddenRowCount ();
     591
     592  if (visibleCount == torrentCount)
     593    myCountLabel->setText (tr("Show:"));
     594  else
     595    myCountLabel->setText (tr("Show %Ln:", 0, visibleCount));
     596}
  • trunk/qt/filterbar.h

    r13869 r13927  
    1818#include <QWidget>
    1919
     20class QLabel;
    2021class QLineEdit;
    2122class QPaintEvent;
     
    8081    QComboBox * myActivityCombo;
    8182    QComboBox * myTrackerCombo;
     83    QLabel * myCountLabel;
    8284    QStandardItemModel * myTrackerModel;
    8385    QTimer * myRecountTimer;
     
    8890    void recount ();
    8991    void refreshPref (int key);
     92    void refreshCountLabel ();
    9093    void onActivityIndexChanged (int index);
    9194    void onTrackerIndexChanged (int index);
  • trunk/qt/mainwin.cc

    r13897 r13927  
    203203  connect (ui.action_DeselectAll, SIGNAL (triggered ()), ui.listView, SLOT (clearSelection ()));
    204204
    205   connect (&myFilterModel, SIGNAL (rowsInserted (const QModelIndex&,int,int)), this, SLOT (refreshVisibleCount ()));
    206   connect (&myFilterModel, SIGNAL (rowsRemoved (const QModelIndex&,int,int)), this, SLOT (refreshVisibleCount ()));
    207205  connect (&myFilterModel, SIGNAL (rowsInserted (const QModelIndex&,int,int)), this, SLOT (refreshActionSensitivitySoon ()));
    208206  connect (&myFilterModel, SIGNAL (rowsRemoved (const QModelIndex&,int,int)), this, SLOT (refreshActionSensitivitySoon ()));
     
    308306  refreshFreeSpace ();
    309307  refreshTitle ();
    310   refreshVisibleCount ();
    311308}
    312309
     
    329326{
    330327  refreshTitle ();
    331   refreshVisibleCount ();
    332328  refreshActionSensitivitySoon ();
    333329  refreshStatusBar ();
     
    396392  h->addStretch (1);
    397393
    398     l = myVisibleCountLabel = new QLabel (this);
     394    l = myFreeSpaceIconLabel = new QLabel (this);
     395    l->setPixmap (getStockIcon ("drive-harddisk", QStyle::SP_DriveHDIcon).pixmap (smallIconSize));
    399396    h->addWidget (l);
    400 
    401   h->addSpacing (HIG::PAD_BIG);
    402 
    403397    l = myFreeSpaceTextLabel = new QLabel (this);
    404398    const int minimumFreeSpaceWidth = l->fontMetrics ().width (Formatter::sizeToString (1024 * 1024));
    405399    l->setMinimumWidth (minimumFreeSpaceWidth);
    406     h->addWidget (l);
    407     l = myFreeSpaceIconLabel = new QLabel (this);
    408     l->setPixmap (getStockIcon ("drive-harddisk", QStyle::SP_DriveHDIcon).pixmap (smallIconSize));
    409400    h->addWidget (l);
    410401
     
    729720
    730721void
    731 TrMainWindow :: refreshVisibleCount ()
    732 {
    733   const int visibleCount (myFilterModel.rowCount ());
    734   const int totalCount (visibleCount + myFilterModel.hiddenRowCount ());
    735   QString str;
    736   if (visibleCount == totalCount)
    737     str = tr ("%Ln Torrent (s)", 0, totalCount);
    738   else
    739     str = tr ("%L1 of %Ln Torrent (s)", 0, totalCount).arg (visibleCount);
    740   myVisibleCountLabel->setText (str);
    741   myVisibleCountLabel->setVisible (totalCount > 0);
    742 }
    743 
    744 void
    745722TrMainWindow :: refreshFreeSpace ()
    746723{
     
    749726  if (bytes >= 0)
    750727    {
    751       const QString text = Formatter::sizeToString (bytes);
     728      const QString sizeStr = Formatter::sizeToString (bytes);
    752729
    753730      const QString tip = tr ("Download folder \"%1\" has %2 free")
    754731        .arg (myPrefs.getString (Prefs::DOWNLOAD_DIR))
    755         .arg (text);
    756 
    757       myFreeSpaceTextLabel->setText (text);
     732        .arg (sizeStr);
     733
     734      myFreeSpaceTextLabel->setText (sizeStr);
    758735      myFreeSpaceTextLabel->setToolTip (tip);
    759736      myFreeSpaceIconLabel->setToolTip (tip);
  • trunk/qt/mainwin.h

    r13886 r13927  
    105105    void showSessionRatio ();
    106106    void showSessionTransfer ();
    107     void refreshVisibleCount ();
    108107    void refreshFreeSpace ();
    109108    void refreshTitle ();
     
    156155    QAction * myAltSpeedAction;
    157156    QPushButton * myOptionsButton;
    158     QLabel * myVisibleCountLabel;
    159157    QPushButton * myStatsModeButton;
    160158    QLabel * myStatsLabel;
Note: See TracChangeset for help on using the changeset viewer.