From 16d46a72a100196b4c93cfdc250db8ceee3b68c7 Mon Sep 17 00:00:00 2001 From: Jordan Lee Date: Fri, 1 Feb 2013 20:58:55 +0000 Subject: [PATCH] in the Qt and GTK+ clients, move the torrent count indicator from the statusbar to the filterbar --- gtk/filter.c | 51 +++++++++++++++++++++++++++++++++++++++++---- gtk/tr-window.c | 55 ++++++------------------------------------------- qt/filterbar.cc | 18 +++++++++++++++- qt/filterbar.h | 3 +++ qt/mainwin.cc | 33 +++++------------------------ qt/mainwin.h | 2 -- 6 files changed, 78 insertions(+), 84 deletions(-) diff --git a/gtk/filter.c b/gtk/filter.c index b59e17309..85b6b1ae3 100644 --- a/gtk/filter.c +++ b/gtk/filter.c @@ -791,6 +791,7 @@ struct filter_data GtkWidget * activity; GtkWidget * tracker; GtkWidget * entry; + GtkWidget * show_lb; GtkTreeModel * filter_model; int active_activity_type; int active_tracker_type; @@ -854,6 +855,47 @@ selection_changed_cb (GtkComboBox * combo, gpointer vdata) gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (data->filter_model)); } +/*** +**** +***/ + +static void +update_count_label (struct filter_data * data) +{ + char buf[512]; + GtkTreeModel * tmodel = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (data->filter_model)); + const int torrentCount = gtk_tree_model_iter_n_children (tmodel, NULL); + const int visibleCount = gtk_tree_model_iter_n_children (data->filter_model, NULL); + + /* set the text */ + if (visibleCount == torrentCount) + g_snprintf (buf, sizeof(buf), _("_Show:")); + else + g_snprintf (buf, sizeof(buf), _("_Show %'d:"), visibleCount); + gtk_label_set_markup_with_mnemonic (GTK_LABEL (data->show_lb), buf); +} + +static void +on_filter_model_row_inserted (GtkTreeModel * tree_model UNUSED, + GtkTreePath * path UNUSED, + GtkTreeIter * iter UNUSED, + gpointer data) +{ + update_count_label (data); +} + +static void +on_filter_model_row_deleted (GtkTreeModel * tree_model UNUSED, + GtkTreePath * path UNUSED, + gpointer data UNUSED) +{ + update_count_label (data); +} + +/*** +**** +***/ + GtkWidget * gtr_filter_bar_new (tr_session * session, GtkTreeModel * tmodel, GtkTreeModel ** filter_model) { @@ -864,7 +906,6 @@ gtr_filter_bar_new (tr_session * session, GtkTreeModel * tmodel, GtkTreeModel ** GtkWidget * activity; GtkWidget * tracker; GtkBox * h_box; - const char * str; struct filter_data * data; g_assert (DIRTY_KEY == 0); @@ -874,9 +915,12 @@ gtr_filter_bar_new (tr_session * session, GtkTreeModel * tmodel, GtkTreeModel ** TORRENT_MODEL_KEY = g_quark_from_static_string ("tr-filter-torrent-model-key"); data = g_new0 (struct filter_data, 1); + data->show_lb = gtk_label_new (NULL); data->activity = activity = activity_combo_box_new (tmodel); data->tracker = tracker = tracker_combo_box_new (tmodel); data->filter_model = gtk_tree_model_filter_new (tmodel, NULL); + g_signal_connect (data->filter_model, "row-deleted", G_CALLBACK(on_filter_model_row_deleted), data); + g_signal_connect (data->filter_model, "row-inserted", G_CALLBACK(on_filter_model_row_inserted), data); g_object_set (G_OBJECT (data->tracker), "width-request", 170, NULL); g_object_set_qdata (G_OBJECT (gtk_combo_box_get_model (GTK_COMBO_BOX (data->tracker))), SESSION_KEY, session); @@ -892,10 +936,8 @@ gtr_filter_bar_new (tr_session * session, GtkTreeModel * tmodel, GtkTreeModel ** h_box = GTK_BOX (h); /* add the activity combobox */ - str = _("_Show:"); w = activity; - l = gtk_label_new (NULL); - gtk_label_set_markup_with_mnemonic (GTK_LABEL (l), str); + l = data->show_lb; gtk_label_set_mnemonic_widget (GTK_LABEL (l), w); gtk_box_pack_start (h_box, l, FALSE, FALSE, 0); gtk_box_pack_start (h_box, w, TRUE, TRUE, 0); @@ -924,5 +966,6 @@ gtr_filter_bar_new (tr_session * session, GtkTreeModel * tmodel, GtkTreeModel ** selection_changed_cb (NULL, data); *filter_model = data->filter_model; + update_count_label (data); return h; } diff --git a/gtk/tr-window.c b/gtk/tr-window.c index dc98497e6..796779e2b 100644 --- a/gtk/tr-window.c +++ b/gtk/tr-window.c @@ -56,7 +56,6 @@ typedef struct GtkLabel * stats_lb; GtkLabel * freespace_lb; GtkWidget * freespace_icon; - GtkLabel * count_lb; GtkWidget * alt_speed_image; GtkWidget * alt_speed_button; GtkWidget * options_menu; @@ -716,25 +715,18 @@ gtr_window_new (GtkApplication * app, GtkUIManager * ui_mgr, TrCore * core) gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1); sibling = w; - /* torrent count */ - w = gtk_label_new ("N Torrents"); - p->count_lb = GTK_LABEL (w); - gtk_label_set_single_line_mode (p->count_lb, TRUE); + /* freespace */ + w = gtk_image_new_from_stock (GTK_STOCK_HARDDISK, GTK_ICON_SIZE_MENU); + p->freespace_icon = w; + g_object_set (G_OBJECT(w), "margin-left", GUI_PAD, NULL); gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1); sibling = w; - - /* freespace */ w = gtk_label_new (NULL); g_object_set (G_OBJECT(w), "margin-left", GUI_PAD_BIG*2, NULL); p->freespace_lb = GTK_LABEL (w); gtk_label_set_single_line_mode (p->freespace_lb, TRUE); gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1); sibling = w; - w = gtk_image_new_from_stock (GTK_STOCK_HARDDISK, GTK_ICON_SIZE_MENU); - p->freespace_icon = w; - g_object_set (G_OBJECT(w), "margin-left", GUI_PAD, NULL); - gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1); - sibling = w; /* spacer */ w = gtk_alignment_new (0.0f, 0.0f, 0.0f, 0.0f); @@ -829,42 +821,6 @@ gtr_window_new (GtkApplication * app, GtkUIManager * ui_mgr, TrCore * core) return self; } -static void -updateTorrentCount (PrivateData * p) -{ - bool visible = false; - - g_return_if_fail (p != NULL); - - if (p->core != NULL) - { - const int torrentCount = gtk_tree_model_iter_n_children (gtr_core_model (p->core), NULL); - const int visibleCount = gtk_tree_model_iter_n_children (p->filter_model, NULL); - - visible = torrentCount > 0; - - if (visible) - { - char countStr[512]; - - if (torrentCount != visibleCount) - g_snprintf (countStr, sizeof (countStr), - ngettext ("%1$'d of %2$'d Torrent", - "%1$'d of %2$'d Torrents", - torrentCount), - visibleCount, torrentCount); - else - g_snprintf (countStr, sizeof (countStr), - ngettext ("%'d Torrent", "%'d Torrents", torrentCount), - torrentCount); - - gtr_label_set_text (p->count_lb, countStr); - } - } - - gtk_widget_set_visible (GTK_WIDGET(p->count_lb), visible); -} - static void updateFreeSpace (PrivateData * p) { @@ -887,8 +843,10 @@ updateFreeSpace (PrivateData * p) { char * tip; char sizeStr[32]; + tr_strlsize (sizeStr, n, sizeof(sizeStr)); gtk_label_set_text (p->freespace_lb, sizeStr); + tip = tr_strdup_printf (_("Download folder \"%1$s\" has %2$s free"), downloadDir, sizeStr); gtk_widget_set_tooltip_text (w, tip); g_free (tip); @@ -989,7 +947,6 @@ gtr_window_refresh (GtkWindow * self) if (p && p->core && gtr_core_session (p->core)) { updateSpeeds (p); - updateTorrentCount (p); updateStats (p); updateFreeSpace (p); } diff --git a/qt/filterbar.cc b/qt/filterbar.cc index a3162cf79..f13c912f3 100644 --- a/qt/filterbar.cc +++ b/qt/filterbar.cc @@ -406,9 +406,10 @@ FilterBar :: FilterBar (Prefs& prefs, TorrentModel& torrents, TorrentFilter& fil QHBoxLayout * h = new QHBoxLayout (this); const int hmargin = qMax (int (HIG::PAD), style ()->pixelMetric (QStyle::PM_LayoutHorizontalSpacing)); + myCountLabel = new QLabel; h->setSpacing (0); h->setContentsMargins (2, 2, 2, 2); - h->addWidget (new QLabel (tr ("Show:"), this)); + h->addWidget (myCountLabel); h->addSpacing (hmargin); myActivityCombo = createActivityCombo (); @@ -437,6 +438,8 @@ FilterBar :: FilterBar (Prefs& prefs, TorrentModel& torrents, TorrentFilter& fil connect (&myPrefs, SIGNAL (changed (int)), this, SLOT (refreshPref (int))); connect (myActivityCombo, SIGNAL (currentIndexChanged (int)), this, SLOT (onActivityIndexChanged (int))); connect (myTrackerCombo, SIGNAL (currentIndexChanged (int)), this, SLOT (onTrackerIndexChanged (int))); + connect (&myFilter, SIGNAL (rowsInserted (const QModelIndex&,int,int)), this, SLOT (refreshCountLabel ())); + connect (&myFilter, SIGNAL (rowsRemoved (const QModelIndex&,int,int)), this, SLOT (refreshCountLabel ())); connect (&myTorrents, SIGNAL (modelReset ()), this, SLOT (onTorrentModelReset ())); connect (&myTorrents, SIGNAL (rowsInserted (const QModelIndex&,int,int)), this, SLOT (onTorrentModelRowsInserted (const QModelIndex&,int,int))); connect (&myTorrents, SIGNAL (rowsRemoved (const QModelIndex&,int,int)), this, SLOT (onTorrentModelRowsRemoved (const QModelIndex&,int,int))); @@ -445,6 +448,7 @@ FilterBar :: FilterBar (Prefs& prefs, TorrentModel& torrents, TorrentFilter& fil recountSoon (); refreshTrackers (); + refreshCountLabel (); myIsBootstrapping = false; // initialize our state @@ -578,3 +582,15 @@ FilterBar :: getCountString (int n) const { return QString ("%L1").arg (n); } + +void +FilterBar :: refreshCountLabel () +{ + const int visibleCount = myFilter.rowCount (); + const int torrentCount = visibleCount + myFilter.hiddenRowCount (); + + if (visibleCount == torrentCount) + myCountLabel->setText (tr("Show:")); + else + myCountLabel->setText (tr("Show %Ln:", 0, visibleCount)); +} diff --git a/qt/filterbar.h b/qt/filterbar.h index e027c3518..9d4127217 100644 --- a/qt/filterbar.h +++ b/qt/filterbar.h @@ -17,6 +17,7 @@ #include #include +class QLabel; class QLineEdit; class QPaintEvent; class QStandardItemModel; @@ -79,6 +80,7 @@ class FilterBar: public QWidget TorrentFilter& myFilter; QComboBox * myActivityCombo; QComboBox * myTrackerCombo; + QLabel * myCountLabel; QStandardItemModel * myTrackerModel; QTimer * myRecountTimer; bool myIsBootstrapping; @@ -87,6 +89,7 @@ class FilterBar: public QWidget private slots: void recount (); void refreshPref (int key); + void refreshCountLabel (); void onActivityIndexChanged (int index); void onTrackerIndexChanged (int index); void onTorrentModelReset (); diff --git a/qt/mainwin.cc b/qt/mainwin.cc index 92ad89802..7ea228a39 100644 --- a/qt/mainwin.cc +++ b/qt/mainwin.cc @@ -202,8 +202,6 @@ TrMainWindow :: TrMainWindow (Session& session, Prefs& prefs, TorrentModel& mode connect (ui.action_SelectAll, SIGNAL (triggered ()), ui.listView, SLOT (selectAll ())); connect (ui.action_DeselectAll, SIGNAL (triggered ()), ui.listView, SLOT (clearSelection ())); - connect (&myFilterModel, SIGNAL (rowsInserted (const QModelIndex&,int,int)), this, SLOT (refreshVisibleCount ())); - connect (&myFilterModel, SIGNAL (rowsRemoved (const QModelIndex&,int,int)), this, SLOT (refreshVisibleCount ())); connect (&myFilterModel, SIGNAL (rowsInserted (const QModelIndex&,int,int)), this, SLOT (refreshActionSensitivitySoon ())); connect (&myFilterModel, SIGNAL (rowsRemoved (const QModelIndex&,int,int)), this, SLOT (refreshActionSensitivitySoon ())); @@ -307,7 +305,6 @@ TrMainWindow :: TrMainWindow (Session& session, Prefs& prefs, TorrentModel& mode refreshStatusBar (); refreshFreeSpace (); refreshTitle (); - refreshVisibleCount (); } TrMainWindow :: ~TrMainWindow () @@ -328,7 +325,6 @@ void TrMainWindow :: onModelReset () { refreshTitle (); - refreshVisibleCount (); refreshActionSensitivitySoon (); refreshStatusBar (); refreshTrayIconSoon (); @@ -395,18 +391,13 @@ TrMainWindow :: createStatusBar () h->addStretch (1); - l = myVisibleCountLabel = new QLabel (this); + l = myFreeSpaceIconLabel = new QLabel (this); + l->setPixmap (getStockIcon ("drive-harddisk", QStyle::SP_DriveHDIcon).pixmap (smallIconSize)); h->addWidget (l); - - h->addSpacing (HIG::PAD_BIG); - l = myFreeSpaceTextLabel = new QLabel (this); const int minimumFreeSpaceWidth = l->fontMetrics ().width (Formatter::sizeToString (1024 * 1024)); l->setMinimumWidth (minimumFreeSpaceWidth); h->addWidget (l); - l = myFreeSpaceIconLabel = new QLabel (this); - l->setPixmap (getStockIcon ("drive-harddisk", QStyle::SP_DriveHDIcon).pixmap (smallIconSize)); - h->addWidget (l); h->addStretch (1); @@ -727,20 +718,6 @@ TrMainWindow :: refreshTitle () setWindowTitle (title); } -void -TrMainWindow :: refreshVisibleCount () -{ - const int visibleCount (myFilterModel.rowCount ()); - const int totalCount (visibleCount + myFilterModel.hiddenRowCount ()); - QString str; - if (visibleCount == totalCount) - str = tr ("%Ln Torrent (s)", 0, totalCount); - else - str = tr ("%L1 of %Ln Torrent (s)", 0, totalCount).arg (visibleCount); - myVisibleCountLabel->setText (str); - myVisibleCountLabel->setVisible (totalCount > 0); -} - void TrMainWindow :: refreshFreeSpace () { @@ -748,13 +725,13 @@ TrMainWindow :: refreshFreeSpace () if (bytes >= 0) { - const QString text = Formatter::sizeToString (bytes); + const QString sizeStr = Formatter::sizeToString (bytes); const QString tip = tr ("Download folder \"%1\" has %2 free") .arg (myPrefs.getString (Prefs::DOWNLOAD_DIR)) - .arg (text); + .arg (sizeStr); - myFreeSpaceTextLabel->setText (text); + myFreeSpaceTextLabel->setText (sizeStr); myFreeSpaceTextLabel->setToolTip (tip); myFreeSpaceIconLabel->setToolTip (tip); } diff --git a/qt/mainwin.h b/qt/mainwin.h index e06f890eb..681cbb99b 100644 --- a/qt/mainwin.h +++ b/qt/mainwin.h @@ -104,7 +104,6 @@ class TrMainWindow: public QMainWindow void showTotalTransfer (); void showSessionRatio (); void showSessionTransfer (); - void refreshVisibleCount (); void refreshFreeSpace (); void refreshTitle (); void refreshStatusBar (); @@ -155,7 +154,6 @@ class TrMainWindow: public QMainWindow QPushButton * myAltSpeedButton; QAction * myAltSpeedAction; QPushButton * myOptionsButton; - QLabel * myVisibleCountLabel; QPushButton * myStatsModeButton; QLabel * myStatsLabel; QLabel * myDownloadSpeedLabel;