GtkWidget * activity;
GtkWidget * tracker;
GtkWidget * entry;
+ GtkWidget * show_lb;
GtkTreeModel * filter_model;
int active_activity_type;
int active_tracker_type;
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)
{
GtkWidget * activity;
GtkWidget * tracker;
GtkBox * h_box;
- const char * str;
struct filter_data * data;
g_assert (DIRTY_KEY == 0);
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);
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);
selection_changed_cb (NULL, data);
*filter_model = data->filter_model;
+ update_count_label (data);
return h;
}
GtkLabel * stats_lb;
GtkLabel * freespace_lb;
GtkWidget * freespace_icon;
- GtkLabel * count_lb;
GtkWidget * alt_speed_image;
GtkWidget * alt_speed_button;
GtkWidget * options_menu;
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);
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)
{
{
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);
if (p && p->core && gtr_core_session (p->core))
{
updateSpeeds (p);
- updateTorrentCount (p);
updateStats (p);
updateFreeSpace (p);
}
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 ();
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)));
recountSoon ();
refreshTrackers ();
+ refreshCountLabel ();
myIsBootstrapping = false;
// initialize our state
{
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));
+}
#include <QItemDelegate>
#include <QWidget>
+class QLabel;
class QLineEdit;
class QPaintEvent;
class QStandardItemModel;
TorrentFilter& myFilter;
QComboBox * myActivityCombo;
QComboBox * myTrackerCombo;
+ QLabel * myCountLabel;
QStandardItemModel * myTrackerModel;
QTimer * myRecountTimer;
bool myIsBootstrapping;
private slots:
void recount ();
void refreshPref (int key);
+ void refreshCountLabel ();
void onActivityIndexChanged (int index);
void onTrackerIndexChanged (int index);
void onTorrentModelReset ();
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 ()));
refreshStatusBar ();
refreshFreeSpace ();
refreshTitle ();
- refreshVisibleCount ();
}
TrMainWindow :: ~TrMainWindow ()
TrMainWindow :: onModelReset ()
{
refreshTitle ();
- refreshVisibleCount ();
refreshActionSensitivitySoon ();
refreshStatusBar ();
refreshTrayIconSoon ();
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);
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 ()
{
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);
}
void showTotalTransfer ();
void showSessionRatio ();
void showSessionTransfer ();
- void refreshVisibleCount ();
void refreshFreeSpace ();
void refreshTitle ();
void refreshStatusBar ();
QPushButton * myAltSpeedButton;
QAction * myAltSpeedAction;
QPushButton * myOptionsButton;
- QLabel * myVisibleCountLabel;
QPushButton * myStatsModeButton;
QLabel * myStatsLabel;
QLabel * myDownloadSpeedLabel;