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

This commit is contained in:
Jordan Lee 2013-02-01 20:58:55 +00:00
parent 70289d9629
commit 16d46a72a1
6 changed files with 78 additions and 84 deletions

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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));
}

View File

@ -17,6 +17,7 @@
#include <QItemDelegate>
#include <QWidget>
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 ();

View File

@ -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);
}

View File

@ -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;