2010-03-14 05:13:02 +00:00
|
|
|
/*
|
2014-01-19 01:09:44 +00:00
|
|
|
* This file Copyright (C) 2012-2014 Mnemosyne LLC
|
2010-03-14 05:13:02 +00:00
|
|
|
*
|
2014-01-21 03:10:30 +00:00
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
2010-03-14 05:13:02 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-04-21 07:40:57 +00:00
|
|
|
#include <stdlib.h> /* qsort() */
|
2011-03-16 18:04:23 +00:00
|
|
|
|
2010-03-14 05:13:02 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
|
|
|
|
#include <libtransmission/transmission.h>
|
|
|
|
#include <libtransmission/utils.h>
|
|
|
|
|
2017-04-21 07:40:57 +00:00
|
|
|
#include "favicon.h" /* gtr_get_favicon() */
|
2010-03-14 05:13:02 +00:00
|
|
|
#include "filter.h"
|
|
|
|
#include "hig.h" /* GUI_PAD */
|
2011-03-03 01:59:25 +00:00
|
|
|
#include "tr-core.h" /* MC_TORRENT */
|
2017-04-21 07:40:57 +00:00
|
|
|
#include "util.h" /* gtr_get_host_from_url() */
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2011-04-05 15:59:41 +00:00
|
|
|
static GQuark DIRTY_KEY = 0;
|
|
|
|
static GQuark SESSION_KEY = 0;
|
|
|
|
static GQuark TEXT_KEY = 0;
|
|
|
|
static GQuark TORRENT_MODEL_KEY = 0;
|
2010-03-14 05:13:02 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
2013-01-01 19:45:00 +00:00
|
|
|
**** TRACKERS
|
2010-03-14 05:13:02 +00:00
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
TRACKER_FILTER_TYPE_ALL,
|
|
|
|
TRACKER_FILTER_TYPE_HOST,
|
|
|
|
TRACKER_FILTER_TYPE_SEPARATOR,
|
2010-03-14 05:13:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
TRACKER_FILTER_COL_NAME, /* human-readable name; ie, Legaltorrents */
|
|
|
|
TRACKER_FILTER_COL_COUNT, /* how many matches there are */
|
|
|
|
TRACKER_FILTER_COL_TYPE,
|
|
|
|
TRACKER_FILTER_COL_HOST, /* pattern-matching text; ie, legaltorrents.com */
|
|
|
|
TRACKER_FILTER_COL_PIXBUF,
|
|
|
|
TRACKER_FILTER_N_COLS
|
2010-03-14 05:13:02 +00:00
|
|
|
};
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static int pstrcmp(void const* a, void const* b)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2017-04-21 07:40:57 +00:00
|
|
|
return g_strcmp0(*(char const* const*)a, *(char const* const*)b);
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2010-03-15 14:35:43 +00:00
|
|
|
/* human-readable name; ie, Legaltorrents */
|
2017-04-20 16:02:19 +00:00
|
|
|
static char* get_name_from_host(char const* host)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
char* name;
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* dot = strrchr(host, '.');
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (tr_addressIsIP(host))
|
|
|
|
{
|
|
|
|
name = g_strdup(host);
|
|
|
|
}
|
2017-04-30 16:25:26 +00:00
|
|
|
else if (dot != NULL)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
name = g_strndup(host, dot - host);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
name = g_strdup(host);
|
|
|
|
}
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
*name = g_ascii_toupper(*name);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return name;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void tracker_model_update_count(GtkTreeStore* store, GtkTreeIter* iter, int n)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
int count;
|
|
|
|
GtkTreeModel* model = GTK_TREE_MODEL(store);
|
|
|
|
gtk_tree_model_get(model, iter, TRACKER_FILTER_COL_COUNT, &count, -1);
|
|
|
|
|
|
|
|
if (n != count)
|
|
|
|
{
|
|
|
|
gtk_tree_store_set(store, iter, TRACKER_FILTER_COL_COUNT, n, -1);
|
|
|
|
}
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void favicon_ready_cb(gpointer pixbuf, gpointer vreference)
|
2010-03-15 02:53:31 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkTreeIter iter;
|
2021-09-25 10:47:09 +00:00
|
|
|
auto* reference = static_cast<GtkTreeRowReference*>(vreference);
|
2010-03-15 02:53:31 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (pixbuf != NULL)
|
2010-03-15 02:53:31 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkTreePath* path = gtk_tree_row_reference_get_path(reference);
|
|
|
|
GtkTreeModel* model = gtk_tree_row_reference_get_model(reference);
|
2010-03-15 02:53:31 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (gtk_tree_model_get_iter(model, &iter, path))
|
|
|
|
{
|
|
|
|
gtk_tree_store_set(GTK_TREE_STORE(model), &iter, TRACKER_FILTER_COL_PIXBUF, pixbuf, -1);
|
|
|
|
}
|
2010-03-15 02:53:31 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_tree_path_free(path);
|
2010-03-15 02:53:31 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
g_object_unref(pixbuf);
|
2010-03-15 02:53:31 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_tree_row_reference_free(reference);
|
2010-03-15 02:53:31 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static gboolean tracker_filter_model_update(gpointer gstore)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GObject* o = G_OBJECT(gstore);
|
|
|
|
g_object_steal_qdata(o, DIRTY_KEY);
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* Walk through all the torrents, tallying how many matches there are
|
|
|
|
* for the various categories. Also make a sorted list of all tracker
|
|
|
|
* hosts s.t. we can merge it with the existing list */
|
2020-11-04 00:59:19 +00:00
|
|
|
int num_torrents = 0;
|
|
|
|
GPtrArray* hosts = g_ptr_array_new();
|
|
|
|
GStringChunk* strings = g_string_chunk_new(4096);
|
|
|
|
GHashTable* hosts_hash = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
|
|
|
|
GtkTreeModel* tmodel = GTK_TREE_MODEL(g_object_get_qdata(o, TORRENT_MODEL_KEY));
|
|
|
|
GtkTreeIter iter;
|
2017-04-19 12:04:45 +00:00
|
|
|
if (gtk_tree_model_iter_nth_child(tmodel, &iter, NULL, 0))
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
do
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2020-11-04 00:59:19 +00:00
|
|
|
tr_torrent const* tor;
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_tree_model_get(tmodel, &iter, MC_TORRENT, &tor, -1);
|
2020-11-04 00:59:19 +00:00
|
|
|
tr_info const* const inf = tr_torrentInfo(tor);
|
|
|
|
|
|
|
|
int keyCount = 0;
|
|
|
|
char** const keys = g_new(char*, inf->trackerCount);
|
2011-04-04 16:54:09 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (unsigned int i = 0; i < inf->trackerCount; ++i)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2020-11-04 00:59:19 +00:00
|
|
|
char name[1024];
|
|
|
|
gtr_get_host_from_url(name, sizeof(name), inf->trackers[i].announce);
|
|
|
|
char* const key = g_string_chunk_insert_const(strings, name);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-09-25 10:47:09 +00:00
|
|
|
auto* count = static_cast<int*>(g_hash_table_lookup(hosts_hash, key));
|
2017-04-19 12:04:45 +00:00
|
|
|
if (count == NULL)
|
|
|
|
{
|
|
|
|
count = tr_new0(int, 1);
|
|
|
|
g_hash_table_insert(hosts_hash, key, count);
|
|
|
|
g_ptr_array_add(hosts, key);
|
|
|
|
}
|
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
for (int k = 0; !found && k < keyCount; ++k)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2017-05-13 22:38:31 +00:00
|
|
|
found = g_strcmp0(keys[k], key) == 0;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
if (!found)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
keys[keyCount++] = key;
|
|
|
|
}
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 0; i < keyCount; ++i)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-09-25 10:47:09 +00:00
|
|
|
auto* incrementme = static_cast<int*>(g_hash_table_lookup(hosts_hash, keys[i]));
|
2017-04-19 12:04:45 +00:00
|
|
|
++*incrementme;
|
|
|
|
}
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
g_free(keys);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2020-11-04 00:59:19 +00:00
|
|
|
++num_torrents;
|
2021-08-15 09:41:48 +00:00
|
|
|
} while (gtk_tree_model_iter_next(tmodel, &iter));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
qsort(hosts->pdata, hosts->len, sizeof(char*), pstrcmp);
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2020-11-04 00:59:19 +00:00
|
|
|
// update the "all" count
|
|
|
|
GtkTreeStore* store = GTK_TREE_STORE(gstore);
|
|
|
|
GtkTreeModel* model = GTK_TREE_MODEL(gstore);
|
2017-04-19 12:04:45 +00:00
|
|
|
if (gtk_tree_model_iter_children(model, &iter, NULL))
|
|
|
|
{
|
2020-11-04 00:59:19 +00:00
|
|
|
tracker_model_update_count(store, &iter, num_torrents);
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2020-11-04 00:59:19 +00:00
|
|
|
int store_pos = 2; // offset past the "All" and the separator
|
|
|
|
guint i = 0;
|
|
|
|
for (;;)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2020-11-04 00:59:19 +00:00
|
|
|
// are we done yet?
|
|
|
|
gboolean const new_hosts_done = i >= hosts->len;
|
2017-04-20 16:02:19 +00:00
|
|
|
gboolean const old_hosts_done = !gtk_tree_model_iter_nth_child(model, &iter, NULL, store_pos);
|
2017-04-19 12:04:45 +00:00
|
|
|
if (new_hosts_done && old_hosts_done)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2020-11-04 00:59:19 +00:00
|
|
|
// decide what to do
|
|
|
|
gboolean remove_row = FALSE;
|
|
|
|
gboolean insert_row = FALSE;
|
2017-04-19 12:04:45 +00:00
|
|
|
if (new_hosts_done)
|
2013-01-01 18:43:41 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
remove_row = TRUE;
|
2013-01-01 18:43:41 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else if (old_hosts_done)
|
2013-01-01 18:43:41 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
insert_row = TRUE;
|
2013-01-01 18:43:41 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2013-01-01 18:43:41 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
char* host;
|
2017-04-21 07:40:57 +00:00
|
|
|
gtk_tree_model_get(model, &iter, TRACKER_FILTER_COL_HOST, &host, -1);
|
2021-09-25 10:47:09 +00:00
|
|
|
int const cmp = g_strcmp0(host, static_cast<char const*>(hosts->pdata[i]));
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (cmp < 0)
|
|
|
|
{
|
|
|
|
remove_row = TRUE;
|
|
|
|
}
|
|
|
|
else if (cmp > 0)
|
|
|
|
{
|
|
|
|
insert_row = TRUE;
|
|
|
|
}
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
g_free(host);
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2020-11-04 00:59:19 +00:00
|
|
|
// do something
|
2017-04-19 12:04:45 +00:00
|
|
|
if (remove_row)
|
2013-01-01 18:43:41 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_tree_store_remove(store, &iter);
|
2013-01-01 18:43:41 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else if (insert_row)
|
2013-01-01 18:43:41 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkTreeIter add;
|
|
|
|
GtkTreePath* path;
|
|
|
|
GtkTreeRowReference* reference;
|
2021-09-25 10:47:09 +00:00
|
|
|
auto* session = static_cast<tr_session*>(g_object_get_qdata(G_OBJECT(store), SESSION_KEY));
|
|
|
|
auto const* host = static_cast<char const*>(hosts->pdata[i]);
|
2017-04-19 12:04:45 +00:00
|
|
|
char* name = get_name_from_host(host);
|
2017-04-21 07:40:57 +00:00
|
|
|
int const count = *(int*)g_hash_table_lookup(hosts_hash, host);
|
2021-08-15 09:41:48 +00:00
|
|
|
gtk_tree_store_insert_with_values(
|
|
|
|
store,
|
|
|
|
&add,
|
|
|
|
NULL,
|
|
|
|
store_pos,
|
|
|
|
TR_ARG_TUPLE(TRACKER_FILTER_COL_HOST, host),
|
|
|
|
TR_ARG_TUPLE(TRACKER_FILTER_COL_NAME, name),
|
|
|
|
TR_ARG_TUPLE(TRACKER_FILTER_COL_COUNT, count),
|
|
|
|
TR_ARG_TUPLE(TRACKER_FILTER_COL_TYPE, TRACKER_FILTER_TYPE_HOST),
|
2017-04-19 12:04:45 +00:00
|
|
|
-1);
|
|
|
|
path = gtk_tree_model_get_path(model, &add);
|
|
|
|
reference = gtk_tree_row_reference_new(model, path);
|
|
|
|
gtr_get_favicon(session, host, favicon_ready_cb, reference);
|
|
|
|
gtk_tree_path_free(path);
|
|
|
|
g_free(name);
|
|
|
|
++store_pos;
|
|
|
|
++i;
|
2013-01-01 18:43:41 +00:00
|
|
|
}
|
2020-11-04 00:59:19 +00:00
|
|
|
else // update row
|
2013-01-01 18:43:41 +00:00
|
|
|
{
|
2021-09-25 10:47:09 +00:00
|
|
|
auto const* const host = static_cast<char const*>(hosts->pdata[i]);
|
2017-04-21 07:40:57 +00:00
|
|
|
int const count = *(int*)g_hash_table_lookup(hosts_hash, host);
|
2017-04-19 12:04:45 +00:00
|
|
|
tracker_model_update_count(store, &iter, count);
|
|
|
|
++store_pos;
|
|
|
|
++i;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
}
|
2010-03-17 17:07:40 +00:00
|
|
|
|
2020-11-04 00:59:19 +00:00
|
|
|
// cleanup
|
2017-04-19 12:04:45 +00:00
|
|
|
g_ptr_array_free(hosts, TRUE);
|
|
|
|
g_hash_table_unref(hosts_hash);
|
|
|
|
g_string_chunk_free(strings);
|
|
|
|
return G_SOURCE_REMOVE;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static GtkTreeModel* tracker_filter_model_new(GtkTreeModel* tmodel)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
GtkTreeStore* store = gtk_tree_store_new(
|
|
|
|
TRACKER_FILTER_N_COLS,
|
2017-04-21 07:40:57 +00:00
|
|
|
G_TYPE_STRING,
|
|
|
|
G_TYPE_INT,
|
|
|
|
G_TYPE_INT,
|
|
|
|
G_TYPE_STRING,
|
|
|
|
GDK_TYPE_PIXBUF);
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
gtk_tree_store_insert_with_values(
|
|
|
|
store,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
-1,
|
|
|
|
TR_ARG_TUPLE(TRACKER_FILTER_COL_NAME, _("All")),
|
|
|
|
TR_ARG_TUPLE(TRACKER_FILTER_COL_TYPE, TRACKER_FILTER_TYPE_ALL),
|
2017-04-19 12:04:45 +00:00
|
|
|
-1);
|
2021-08-15 09:41:48 +00:00
|
|
|
gtk_tree_store_insert_with_values(
|
|
|
|
store,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
-1,
|
|
|
|
TR_ARG_TUPLE(TRACKER_FILTER_COL_TYPE, TRACKER_FILTER_TYPE_SEPARATOR),
|
2017-04-19 12:04:45 +00:00
|
|
|
-1);
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
g_object_set_qdata(G_OBJECT(store), TORRENT_MODEL_KEY, tmodel);
|
|
|
|
tracker_filter_model_update(store);
|
|
|
|
return GTK_TREE_MODEL(store);
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2020-08-18 10:36:10 +00:00
|
|
|
static gboolean is_it_a_separator(GtkTreeModel* m, GtkTreeIter* iter, gpointer data)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2020-08-18 10:36:10 +00:00
|
|
|
TR_UNUSED(data);
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
int type;
|
|
|
|
gtk_tree_model_get(m, iter, TRACKER_FILTER_COL_TYPE, &type, -1);
|
|
|
|
return type == TRACKER_FILTER_TYPE_SEPARATOR;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void tracker_model_update_idle(gpointer tracker_model)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GObject* o = G_OBJECT(tracker_model);
|
2017-04-20 16:02:19 +00:00
|
|
|
gboolean const pending = g_object_get_qdata(o, DIRTY_KEY) != NULL;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (!pending)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GSourceFunc func = tracker_filter_model_update;
|
|
|
|
g_object_set_qdata(o, DIRTY_KEY, GINT_TO_POINTER(1));
|
|
|
|
gdk_threads_add_idle(func, tracker_model);
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-18 17:31:06 +00:00
|
|
|
static void torrent_model_row_changed(GtkTreeModel* tmodel, GtkTreePath* path, GtkTreeIter* iter, gpointer tracker_model)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2020-08-18 10:36:10 +00:00
|
|
|
TR_UNUSED(tmodel);
|
|
|
|
TR_UNUSED(path);
|
|
|
|
TR_UNUSED(iter);
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tracker_model_update_idle(tracker_model);
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2020-08-18 10:36:10 +00:00
|
|
|
static void torrent_model_row_deleted_cb(GtkTreeModel* tmodel, GtkTreePath* path, gpointer tracker_model)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2020-08-18 10:36:10 +00:00
|
|
|
TR_UNUSED(tmodel);
|
|
|
|
TR_UNUSED(path);
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tracker_model_update_idle(tracker_model);
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
static void render_pixbuf_func(
|
|
|
|
GtkCellLayout* cell_layout,
|
|
|
|
GtkCellRenderer* cell_renderer,
|
|
|
|
GtkTreeModel* tree_model,
|
|
|
|
GtkTreeIter* iter,
|
|
|
|
gpointer data)
|
2010-03-15 02:53:31 +00:00
|
|
|
{
|
2020-08-18 10:36:10 +00:00
|
|
|
TR_UNUSED(cell_layout);
|
|
|
|
TR_UNUSED(data);
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
int type;
|
|
|
|
int width;
|
2010-03-16 00:45:12 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_tree_model_get(tree_model, iter, TRACKER_FILTER_COL_TYPE, &type, -1);
|
|
|
|
width = (type == TRACKER_FILTER_TYPE_HOST) ? 20 : 0;
|
|
|
|
g_object_set(cell_renderer, "width", width, NULL);
|
2010-03-15 02:53:31 +00:00
|
|
|
}
|
2010-03-16 00:45:12 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
static void render_number_func(
|
|
|
|
GtkCellLayout* cell_layout,
|
|
|
|
GtkCellRenderer* cell_renderer,
|
|
|
|
GtkTreeModel* tree_model,
|
|
|
|
GtkTreeIter* iter,
|
|
|
|
gpointer data)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2020-08-18 10:36:10 +00:00
|
|
|
TR_UNUSED(cell_layout);
|
|
|
|
TR_UNUSED(data);
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
int count;
|
|
|
|
char buf[32];
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_tree_model_get(tree_model, iter, TRACKER_FILTER_COL_COUNT, &count, -1);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (count >= 0)
|
|
|
|
{
|
|
|
|
g_snprintf(buf, sizeof(buf), "%'d", count);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*buf = '\0';
|
|
|
|
}
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
g_object_set(cell_renderer, "text", buf, NULL);
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static GtkCellRenderer* number_renderer_new(void)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkCellRenderer* r = gtk_cell_renderer_text_new();
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
g_object_set(
|
|
|
|
G_OBJECT(r),
|
|
|
|
TR_ARG_TUPLE("alignment", PANGO_ALIGN_RIGHT),
|
|
|
|
TR_ARG_TUPLE("weight", PANGO_WEIGHT_ULTRALIGHT),
|
|
|
|
TR_ARG_TUPLE("xalign", 1.0),
|
|
|
|
TR_ARG_TUPLE("xpad", GUI_PAD),
|
2017-04-19 12:04:45 +00:00
|
|
|
NULL);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return r;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void disconnect_cat_model_callbacks(gpointer tmodel, GObject* cat_model)
|
2011-03-25 17:42:47 +00:00
|
|
|
{
|
2021-09-25 10:47:09 +00:00
|
|
|
g_signal_handlers_disconnect_by_func(tmodel, reinterpret_cast<gpointer>(torrent_model_row_changed), cat_model);
|
|
|
|
g_signal_handlers_disconnect_by_func(tmodel, reinterpret_cast<gpointer>(torrent_model_row_deleted_cb), cat_model);
|
2011-03-25 17:42:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static GtkWidget* tracker_combo_box_new(GtkTreeModel* tmodel)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkWidget* c;
|
|
|
|
GtkCellRenderer* r;
|
|
|
|
GtkTreeModel* cat_model;
|
|
|
|
GtkCellLayout* c_cell_layout;
|
|
|
|
GtkComboBox* c_combo_box;
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* create the tracker combobox */
|
|
|
|
cat_model = tracker_filter_model_new(tmodel);
|
|
|
|
c = gtk_combo_box_new_with_model(cat_model);
|
|
|
|
c_combo_box = GTK_COMBO_BOX(c);
|
|
|
|
c_cell_layout = GTK_CELL_LAYOUT(c);
|
|
|
|
gtk_combo_box_set_row_separator_func(c_combo_box, is_it_a_separator, NULL, NULL);
|
|
|
|
gtk_combo_box_set_active(c_combo_box, 0);
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
r = gtk_cell_renderer_pixbuf_new();
|
|
|
|
gtk_cell_layout_pack_start(c_cell_layout, r, FALSE);
|
|
|
|
gtk_cell_layout_set_cell_data_func(c_cell_layout, r, render_pixbuf_func, NULL, NULL);
|
|
|
|
gtk_cell_layout_set_attributes(c_cell_layout, r, "pixbuf", TRACKER_FILTER_COL_PIXBUF, NULL);
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
r = gtk_cell_renderer_text_new();
|
|
|
|
gtk_cell_layout_pack_start(c_cell_layout, r, FALSE);
|
|
|
|
gtk_cell_layout_set_attributes(c_cell_layout, r, "text", TRACKER_FILTER_COL_NAME, NULL);
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
r = number_renderer_new();
|
|
|
|
gtk_cell_layout_pack_end(c_cell_layout, r, TRUE);
|
|
|
|
gtk_cell_layout_set_cell_data_func(c_cell_layout, r, render_number_func, NULL, NULL);
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
g_object_weak_ref(G_OBJECT(cat_model), disconnect_cat_model_callbacks, tmodel);
|
|
|
|
g_signal_connect(tmodel, "row-changed", G_CALLBACK(torrent_model_row_changed), cat_model);
|
|
|
|
g_signal_connect(tmodel, "row-inserted", G_CALLBACK(torrent_model_row_changed), cat_model);
|
|
|
|
g_signal_connect(tmodel, "row-deleted", G_CALLBACK(torrent_model_row_deleted_cb), cat_model);
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return c;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2020-11-05 22:46:21 +00:00
|
|
|
static gboolean test_tracker(tr_torrent const* tor, int active_tracker_type, char const* host)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
gboolean matches = TRUE;
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (active_tracker_type == TRACKER_FILTER_TYPE_HOST)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
char tmp[1024];
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_info const* const inf = tr_torrentInfo(tor);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
matches = FALSE;
|
|
|
|
|
|
|
|
for (unsigned int i = 0; !matches && i < inf->trackerCount; ++i)
|
2013-01-01 18:43:41 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
gtr_get_host_from_url(tmp, sizeof(tmp), inf->trackers[i].announce);
|
2017-05-13 22:38:31 +00:00
|
|
|
matches = g_strcmp0(tmp, host) == 0;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-01 19:45:00 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return matches;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
2010-03-27 02:52:10 +00:00
|
|
|
**** ACTIVITY
|
2010-03-14 05:13:02 +00:00
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
ACTIVITY_FILTER_ALL,
|
|
|
|
ACTIVITY_FILTER_DOWNLOADING,
|
|
|
|
ACTIVITY_FILTER_SEEDING,
|
|
|
|
ACTIVITY_FILTER_ACTIVE,
|
|
|
|
ACTIVITY_FILTER_PAUSED,
|
|
|
|
ACTIVITY_FILTER_FINISHED,
|
|
|
|
ACTIVITY_FILTER_VERIFYING,
|
|
|
|
ACTIVITY_FILTER_ERROR,
|
|
|
|
ACTIVITY_FILTER_SEPARATOR
|
2010-03-14 05:13:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
ACTIVITY_FILTER_COL_NAME,
|
|
|
|
ACTIVITY_FILTER_COL_COUNT,
|
|
|
|
ACTIVITY_FILTER_COL_TYPE,
|
2020-07-27 17:49:45 +00:00
|
|
|
ACTIVITY_FILTER_COL_ICON_NAME,
|
2017-04-19 12:04:45 +00:00
|
|
|
ACTIVITY_FILTER_N_COLS
|
2010-03-14 05:13:02 +00:00
|
|
|
};
|
|
|
|
|
2020-08-18 10:36:10 +00:00
|
|
|
static gboolean activity_is_it_a_separator(GtkTreeModel* m, GtkTreeIter* i, gpointer d)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2020-08-18 10:36:10 +00:00
|
|
|
TR_UNUSED(d);
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
int type;
|
|
|
|
gtk_tree_model_get(m, i, ACTIVITY_FILTER_COL_TYPE, &type, -1);
|
|
|
|
return type == ACTIVITY_FILTER_SEPARATOR;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static gboolean test_torrent_activity(tr_torrent* tor, int type)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_stat const* st = tr_torrentStatCached(tor);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
switch (type)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
case ACTIVITY_FILTER_DOWNLOADING:
|
2017-04-30 16:25:26 +00:00
|
|
|
return st->activity == TR_STATUS_DOWNLOAD || st->activity == TR_STATUS_DOWNLOAD_WAIT;
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case ACTIVITY_FILTER_SEEDING:
|
2017-04-30 16:25:26 +00:00
|
|
|
return st->activity == TR_STATUS_SEED || st->activity == TR_STATUS_SEED_WAIT;
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case ACTIVITY_FILTER_ACTIVE:
|
2017-04-30 16:25:26 +00:00
|
|
|
return st->peersSendingToUs > 0 || st->peersGettingFromUs > 0 || st->webseedsSendingToUs > 0 ||
|
2019-02-10 11:05:16 +00:00
|
|
|
st->activity == TR_STATUS_CHECK;
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case ACTIVITY_FILTER_PAUSED:
|
2013-01-01 18:43:41 +00:00
|
|
|
return st->activity == TR_STATUS_STOPPED;
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case ACTIVITY_FILTER_FINISHED:
|
2013-01-01 18:43:41 +00:00
|
|
|
return st->finished == TRUE;
|
2010-08-01 17:43:35 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case ACTIVITY_FILTER_VERIFYING:
|
2017-04-30 16:25:26 +00:00
|
|
|
return st->activity == TR_STATUS_CHECK || st->activity == TR_STATUS_CHECK_WAIT;
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case ACTIVITY_FILTER_ERROR:
|
2013-01-01 18:43:41 +00:00
|
|
|
return st->error != 0;
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
default: /* ACTIVITY_FILTER_ALL */
|
2013-01-01 18:43:41 +00:00
|
|
|
return TRUE;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void status_model_update_count(GtkListStore* store, GtkTreeIter* iter, int n)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
int count;
|
|
|
|
GtkTreeModel* model = GTK_TREE_MODEL(store);
|
|
|
|
gtk_tree_model_get(model, iter, ACTIVITY_FILTER_COL_COUNT, &count, -1);
|
|
|
|
|
|
|
|
if (n != count)
|
|
|
|
{
|
|
|
|
gtk_list_store_set(store, iter, ACTIVITY_FILTER_COL_COUNT, n, -1);
|
|
|
|
}
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static gboolean activity_filter_model_update(gpointer gstore)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
GObject* o = G_OBJECT(gstore);
|
|
|
|
GtkListStore* store = GTK_LIST_STORE(gstore);
|
|
|
|
GtkTreeModel* model = GTK_TREE_MODEL(store);
|
|
|
|
GtkTreeModel* tmodel = GTK_TREE_MODEL(g_object_get_qdata(o, TORRENT_MODEL_KEY));
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
g_object_steal_qdata(o, DIRTY_KEY);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (gtk_tree_model_iter_nth_child(model, &iter, NULL, 0))
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
int hits;
|
|
|
|
int type;
|
|
|
|
GtkTreeIter torrent_iter;
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_tree_model_get(model, &iter, ACTIVITY_FILTER_COL_TYPE, &type, -1);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
hits = 0;
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (gtk_tree_model_iter_nth_child(tmodel, &torrent_iter, NULL, 0))
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
tr_torrent* tor;
|
|
|
|
gtk_tree_model_get(tmodel, &torrent_iter, MC_TORRENT, &tor, -1);
|
|
|
|
|
|
|
|
if (test_torrent_activity(tor, type))
|
|
|
|
{
|
|
|
|
++hits;
|
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
} while (gtk_tree_model_iter_next(tmodel, &torrent_iter));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
status_model_update_count(store, &iter, hits);
|
2021-08-15 09:41:48 +00:00
|
|
|
} while (gtk_tree_model_iter_next(model, &iter));
|
2013-01-01 18:43:41 +00:00
|
|
|
}
|
2013-02-02 23:01:33 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return G_SOURCE_REMOVE;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static GtkTreeModel* activity_filter_model_new(GtkTreeModel* tmodel)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
int type;
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* context;
|
|
|
|
char const* name;
|
2020-07-27 17:49:45 +00:00
|
|
|
char const* icon_name;
|
2021-08-15 09:41:48 +00:00
|
|
|
} types[] = {
|
2017-04-19 12:04:45 +00:00
|
|
|
{ ACTIVITY_FILTER_ALL, NULL, N_("All"), NULL },
|
|
|
|
{ ACTIVITY_FILTER_SEPARATOR, NULL, NULL, NULL },
|
2020-07-27 17:49:45 +00:00
|
|
|
{ ACTIVITY_FILTER_ACTIVE, NULL, N_("Active"), "system-run" },
|
|
|
|
{ ACTIVITY_FILTER_DOWNLOADING, "Verb", NC_("Verb", "Downloading"), "network-receive" },
|
|
|
|
{ ACTIVITY_FILTER_SEEDING, "Verb", NC_("Verb", "Seeding"), "network-transmit" },
|
|
|
|
{ ACTIVITY_FILTER_PAUSED, NULL, N_("Paused"), "media-playback-pause" },
|
|
|
|
{ ACTIVITY_FILTER_FINISHED, NULL, N_("Finished"), "media-playback-stop" },
|
|
|
|
{ ACTIVITY_FILTER_VERIFYING, "Verb", NC_("Verb", "Verifying"), "view-refresh" },
|
2021-08-15 09:41:48 +00:00
|
|
|
{ ACTIVITY_FILTER_ERROR, NULL, N_("Error"), "dialog-error" },
|
2017-04-19 12:04:45 +00:00
|
|
|
};
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
GtkListStore* store = gtk_list_store_new(ACTIVITY_FILTER_N_COLS, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (size_t i = 0; i < G_N_ELEMENTS(types); ++i)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2017-05-01 15:47:49 +00:00
|
|
|
char const* name = types[i].context != NULL ? g_dpgettext2(NULL, types[i].context, types[i].name) : _(types[i].name);
|
2021-08-15 09:41:48 +00:00
|
|
|
gtk_list_store_insert_with_values(
|
|
|
|
store,
|
|
|
|
NULL,
|
|
|
|
-1,
|
|
|
|
TR_ARG_TUPLE(ACTIVITY_FILTER_COL_NAME, name),
|
|
|
|
TR_ARG_TUPLE(ACTIVITY_FILTER_COL_TYPE, types[i].type),
|
|
|
|
TR_ARG_TUPLE(ACTIVITY_FILTER_COL_ICON_NAME, types[i].icon_name),
|
2017-04-19 12:04:45 +00:00
|
|
|
-1);
|
2012-04-13 14:49:34 +00:00
|
|
|
}
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
g_object_set_qdata(G_OBJECT(store), TORRENT_MODEL_KEY, tmodel);
|
|
|
|
activity_filter_model_update(store);
|
|
|
|
return GTK_TREE_MODEL(store);
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
static void render_activity_pixbuf_func(
|
|
|
|
GtkCellLayout* cell_layout,
|
|
|
|
GtkCellRenderer* cell_renderer,
|
|
|
|
GtkTreeModel* tree_model,
|
|
|
|
GtkTreeIter* iter,
|
|
|
|
gpointer data)
|
2010-05-18 14:14:17 +00:00
|
|
|
{
|
2020-08-18 10:36:10 +00:00
|
|
|
TR_UNUSED(cell_layout);
|
|
|
|
TR_UNUSED(data);
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
int type;
|
|
|
|
int width;
|
|
|
|
int ypad;
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_tree_model_get(tree_model, iter, ACTIVITY_FILTER_COL_TYPE, &type, -1);
|
|
|
|
width = type == ACTIVITY_FILTER_ALL ? 0 : 20;
|
|
|
|
ypad = type == ACTIVITY_FILTER_ALL ? 0 : 2;
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
g_object_set(cell_renderer, "width", width, "ypad", ypad, NULL);
|
2010-05-18 14:14:17 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void activity_model_update_idle(gpointer activity_model)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GObject* o = G_OBJECT(activity_model);
|
2017-04-20 16:02:19 +00:00
|
|
|
gboolean const pending = g_object_get_qdata(o, DIRTY_KEY) != NULL;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (!pending)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GSourceFunc func = activity_filter_model_update;
|
|
|
|
g_object_set_qdata(o, DIRTY_KEY, GINT_TO_POINTER(1));
|
|
|
|
gdk_threads_add_idle(func, activity_model);
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
static void activity_torrent_model_row_changed(
|
|
|
|
GtkTreeModel const* tmodel,
|
|
|
|
GtkTreePath const* path,
|
|
|
|
GtkTreeIter const* iter,
|
2017-04-19 12:04:45 +00:00
|
|
|
gpointer activity_model)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2020-08-18 10:36:10 +00:00
|
|
|
TR_UNUSED(tmodel);
|
|
|
|
TR_UNUSED(path);
|
|
|
|
TR_UNUSED(iter);
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
activity_model_update_idle(activity_model);
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2020-11-09 03:31:02 +00:00
|
|
|
static void activity_torrent_model_row_deleted_cb(GtkTreeModel const* tmodel, GtkTreePath const* path, gpointer activity_model)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2020-08-18 10:36:10 +00:00
|
|
|
TR_UNUSED(tmodel);
|
|
|
|
TR_UNUSED(path);
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
activity_model_update_idle(activity_model);
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void disconnect_activity_model_callbacks(gpointer tmodel, GObject* cat_model)
|
2011-03-25 17:42:47 +00:00
|
|
|
{
|
2021-09-25 10:47:09 +00:00
|
|
|
g_signal_handlers_disconnect_by_func(tmodel, reinterpret_cast<gpointer>(activity_torrent_model_row_changed), cat_model);
|
|
|
|
g_signal_handlers_disconnect_by_func(tmodel, reinterpret_cast<gpointer>(activity_torrent_model_row_deleted_cb), cat_model);
|
2011-03-25 17:42:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static GtkWidget* activity_combo_box_new(GtkTreeModel* tmodel)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkWidget* c;
|
|
|
|
GtkCellRenderer* r;
|
|
|
|
GtkTreeModel* activity_model;
|
|
|
|
GtkComboBox* c_combo_box;
|
|
|
|
GtkCellLayout* c_cell_layout;
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
activity_model = activity_filter_model_new(tmodel);
|
|
|
|
c = gtk_combo_box_new_with_model(activity_model);
|
|
|
|
c_combo_box = GTK_COMBO_BOX(c);
|
|
|
|
c_cell_layout = GTK_CELL_LAYOUT(c);
|
|
|
|
gtk_combo_box_set_row_separator_func(c_combo_box, activity_is_it_a_separator, NULL, NULL);
|
|
|
|
gtk_combo_box_set_active(c_combo_box, 0);
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
r = gtk_cell_renderer_pixbuf_new();
|
|
|
|
gtk_cell_layout_pack_start(c_cell_layout, r, FALSE);
|
2021-08-15 09:41:48 +00:00
|
|
|
gtk_cell_layout_set_attributes(c_cell_layout, r, TR_ARG_TUPLE("icon-name", ACTIVITY_FILTER_COL_ICON_NAME), NULL);
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_cell_layout_set_cell_data_func(c_cell_layout, r, render_activity_pixbuf_func, NULL, NULL);
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
r = gtk_cell_renderer_text_new();
|
|
|
|
gtk_cell_layout_pack_start(c_cell_layout, r, TRUE);
|
2021-08-15 09:41:48 +00:00
|
|
|
gtk_cell_layout_set_attributes(c_cell_layout, r, TR_ARG_TUPLE("text", ACTIVITY_FILTER_COL_NAME), NULL);
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
r = number_renderer_new();
|
|
|
|
gtk_cell_layout_pack_end(c_cell_layout, r, TRUE);
|
|
|
|
gtk_cell_layout_set_cell_data_func(c_cell_layout, r, render_number_func, NULL, NULL);
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
g_object_weak_ref(G_OBJECT(activity_model), disconnect_activity_model_callbacks, tmodel);
|
|
|
|
g_signal_connect(tmodel, "row-changed", G_CALLBACK(activity_torrent_model_row_changed), activity_model);
|
|
|
|
g_signal_connect(tmodel, "row-inserted", G_CALLBACK(activity_torrent_model_row_changed), activity_model);
|
|
|
|
g_signal_connect(tmodel, "row-deleted", G_CALLBACK(activity_torrent_model_row_deleted_cb), activity_model);
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return c;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/****
|
|
|
|
*****
|
|
|
|
***** ENTRY FIELD
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static gboolean testText(tr_torrent const* tor, char const* key)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
gboolean ret = FALSE;
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2019-07-13 08:52:44 +00:00
|
|
|
if (tr_str_is_empty(key))
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
ret = TRUE;
|
2010-08-06 15:03:25 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2010-08-06 15:03:25 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_info const* inf = tr_torrentInfo(tor);
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* test the torrent name... */
|
2020-11-09 03:31:02 +00:00
|
|
|
char* pch = g_utf8_casefold(tr_torrentName(tor), -1);
|
|
|
|
ret = key == NULL || strstr(pch, key) != NULL;
|
|
|
|
g_free(pch);
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* test the files... */
|
2017-05-13 22:38:31 +00:00
|
|
|
for (tr_file_index_t i = 0; i < inf->fileCount && !ret; ++i)
|
2010-08-06 15:03:25 +00:00
|
|
|
{
|
2020-11-09 03:31:02 +00:00
|
|
|
pch = g_utf8_casefold(inf->files[i].name, -1);
|
2017-05-01 15:47:49 +00:00
|
|
|
ret = key == NULL || strstr(pch, key) != NULL;
|
2017-04-19 12:04:45 +00:00
|
|
|
g_free(pch);
|
2010-08-06 15:03:25 +00:00
|
|
|
}
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return ret;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void entry_clear(GtkEntry* e)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_entry_set_text(e, "");
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void filter_entry_changed(GtkEditable* e, gpointer filter_model)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
char* pch;
|
|
|
|
char* folded;
|
2010-03-17 17:07:40 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
pch = gtk_editable_get_chars(e, 0, -1);
|
|
|
|
folded = g_utf8_casefold(pch, -1);
|
|
|
|
g_strstrip(folded);
|
2021-09-25 10:47:09 +00:00
|
|
|
g_object_set_qdata_full(static_cast<GObject*>(filter_model), TEXT_KEY, folded, g_free);
|
2017-04-19 12:04:45 +00:00
|
|
|
g_free(pch);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_tree_model_filter_refilter(GTK_TREE_MODEL_FILTER(filter_model));
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****
|
|
|
|
******
|
|
|
|
******
|
|
|
|
******
|
|
|
|
*****/
|
|
|
|
|
|
|
|
struct filter_data
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkWidget* activity;
|
|
|
|
GtkWidget* tracker;
|
|
|
|
GtkWidget* entry;
|
|
|
|
GtkWidget* show_lb;
|
|
|
|
GtkTreeModel* filter_model;
|
|
|
|
int active_activity_type;
|
|
|
|
int active_tracker_type;
|
|
|
|
char* active_tracker_host;
|
2010-03-14 05:13:02 +00:00
|
|
|
};
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static gboolean is_row_visible(GtkTreeModel* model, GtkTreeIter* iter, gpointer vdata)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* text;
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_torrent* tor;
|
2021-09-25 10:47:09 +00:00
|
|
|
auto* data = static_cast<filter_data*>(vdata);
|
2017-04-19 12:04:45 +00:00
|
|
|
GObject* o = G_OBJECT(data->filter_model);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_tree_model_get(model, iter, MC_TORRENT, &tor, -1);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
text = (char const*)g_object_get_qdata(o, TEXT_KEY);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
return tor != NULL && test_tracker(tor, data->active_tracker_type, data->active_tracker_host) &&
|
2019-02-10 11:05:16 +00:00
|
|
|
test_torrent_activity(tor, data->active_activity_type) && testText(tor, text);
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void selection_changed_cb(GtkComboBox* combo, gpointer vdata)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
int type;
|
|
|
|
char* host;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeModel* model;
|
2021-09-25 10:47:09 +00:00
|
|
|
auto* data = static_cast<filter_data*>(vdata);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* set data->active_activity_type from the activity combobox */
|
|
|
|
combo = GTK_COMBO_BOX(data->activity);
|
|
|
|
model = gtk_combo_box_get_model(combo);
|
|
|
|
|
|
|
|
if (gtk_combo_box_get_active_iter(combo, &iter))
|
|
|
|
{
|
|
|
|
gtk_tree_model_get(model, &iter, ACTIVITY_FILTER_COL_TYPE, &type, -1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
type = ACTIVITY_FILTER_ALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->active_activity_type = type;
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* set the active tracker type & host from the tracker combobox */
|
|
|
|
combo = GTK_COMBO_BOX(data->tracker);
|
|
|
|
model = gtk_combo_box_get_model(combo);
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (gtk_combo_box_get_active_iter(combo, &iter))
|
2013-01-01 18:43:41 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
gtk_tree_model_get(
|
|
|
|
model,
|
|
|
|
&iter,
|
|
|
|
TR_ARG_TUPLE(TRACKER_FILTER_COL_TYPE, &type),
|
|
|
|
TR_ARG_TUPLE(TRACKER_FILTER_COL_HOST, &host),
|
2017-04-19 12:04:45 +00:00
|
|
|
-1);
|
2013-01-01 18:43:41 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2013-01-01 18:43:41 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
type = TRACKER_FILTER_TYPE_ALL;
|
|
|
|
host = NULL;
|
2011-04-13 22:04:31 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
g_free(data->active_tracker_host);
|
|
|
|
data->active_tracker_host = host;
|
|
|
|
data->active_tracker_type = type;
|
|
|
|
|
|
|
|
/* refilter */
|
|
|
|
gtk_tree_model_filter_refilter(GTK_TREE_MODEL_FILTER(data->filter_model));
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2013-02-01 20:58:55 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static gboolean update_count_label(gpointer gdata)
|
|
|
|
{
|
|
|
|
char buf[512];
|
|
|
|
int visibleCount;
|
|
|
|
int trackerCount;
|
|
|
|
int activityCount;
|
|
|
|
GtkTreeModel* model;
|
|
|
|
GtkComboBox* combo;
|
|
|
|
GtkTreeIter iter;
|
2021-09-25 10:47:09 +00:00
|
|
|
auto* data = static_cast<filter_data*>(gdata);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* get the visible count */
|
|
|
|
visibleCount = gtk_tree_model_iter_n_children(data->filter_model, NULL);
|
|
|
|
|
|
|
|
/* get the tracker count */
|
|
|
|
combo = GTK_COMBO_BOX(data->tracker);
|
|
|
|
model = gtk_combo_box_get_model(combo);
|
|
|
|
|
|
|
|
if (gtk_combo_box_get_active_iter(combo, &iter))
|
|
|
|
{
|
|
|
|
gtk_tree_model_get(model, &iter, TRACKER_FILTER_COL_COUNT, &trackerCount, -1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
trackerCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the activity count */
|
|
|
|
combo = GTK_COMBO_BOX(data->activity);
|
|
|
|
model = gtk_combo_box_get_model(combo);
|
|
|
|
|
|
|
|
if (gtk_combo_box_get_active_iter(combo, &iter))
|
|
|
|
{
|
|
|
|
gtk_tree_model_get(model, &iter, ACTIVITY_FILTER_COL_COUNT, &activityCount, -1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
activityCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set the text */
|
|
|
|
if (visibleCount == MIN(activityCount, trackerCount))
|
|
|
|
{
|
|
|
|
g_snprintf(buf, sizeof(buf), _("_Show:"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_snprintf(buf, sizeof(buf), _("_Show %'d of:"), visibleCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_label_set_markup_with_mnemonic(GTK_LABEL(data->show_lb), buf);
|
|
|
|
|
|
|
|
g_object_steal_qdata(G_OBJECT(data->show_lb), DIRTY_KEY);
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void update_count_label_idle(struct filter_data* data)
|
|
|
|
{
|
|
|
|
GObject* o = G_OBJECT(data->show_lb);
|
2017-04-20 16:02:19 +00:00
|
|
|
gboolean const pending = g_object_get_qdata(o, DIRTY_KEY) != NULL;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (!pending)
|
|
|
|
{
|
|
|
|
g_object_set_qdata(o, DIRTY_KEY, GINT_TO_POINTER(1));
|
|
|
|
gdk_threads_add_idle(update_count_label, data);
|
2013-02-02 23:01:33 +00:00
|
|
|
}
|
2013-02-01 20:58:55 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
static void on_filter_model_row_inserted(
|
|
|
|
GtkTreeModel const* tree_model,
|
|
|
|
GtkTreePath const* path,
|
|
|
|
GtkTreeIter const* iter,
|
2020-11-09 03:31:02 +00:00
|
|
|
gpointer data)
|
2013-02-01 20:58:55 +00:00
|
|
|
{
|
2020-08-18 10:36:10 +00:00
|
|
|
TR_UNUSED(tree_model);
|
|
|
|
TR_UNUSED(path);
|
|
|
|
TR_UNUSED(iter);
|
|
|
|
|
2021-09-25 10:47:09 +00:00
|
|
|
update_count_label_idle(static_cast<filter_data*>(data));
|
2013-02-01 20:58:55 +00:00
|
|
|
}
|
|
|
|
|
2020-11-09 03:31:02 +00:00
|
|
|
static void on_filter_model_row_deleted(GtkTreeModel const* tree_model, GtkTreePath const* path, gpointer data)
|
2013-02-01 20:58:55 +00:00
|
|
|
{
|
2020-08-18 10:36:10 +00:00
|
|
|
TR_UNUSED(tree_model);
|
|
|
|
TR_UNUSED(path);
|
|
|
|
|
2021-09-25 10:47:09 +00:00
|
|
|
update_count_label_idle(static_cast<filter_data*>(data));
|
2013-02-01 20:58:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkWidget* gtr_filter_bar_new(tr_session* session, GtkTreeModel* tmodel, GtkTreeModel** filter_model)
|
|
|
|
{
|
|
|
|
GtkWidget* l;
|
|
|
|
GtkWidget* w;
|
|
|
|
GtkWidget* h;
|
|
|
|
GtkWidget* s;
|
|
|
|
GtkWidget* activity;
|
|
|
|
GtkWidget* tracker;
|
|
|
|
GtkBox* h_box;
|
|
|
|
struct filter_data* data;
|
|
|
|
|
|
|
|
g_assert(DIRTY_KEY == 0);
|
|
|
|
TEXT_KEY = g_quark_from_static_string("tr-filter-text-key");
|
|
|
|
DIRTY_KEY = g_quark_from_static_string("tr-filter-dirty-key");
|
|
|
|
SESSION_KEY = g_quark_from_static_string("tr-session-key");
|
|
|
|
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);
|
|
|
|
|
|
|
|
gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(data->filter_model), is_row_visible, data, g_free);
|
|
|
|
|
|
|
|
g_signal_connect(data->tracker, "changed", G_CALLBACK(selection_changed_cb), data);
|
|
|
|
g_signal_connect(data->activity, "changed", G_CALLBACK(selection_changed_cb), data);
|
|
|
|
|
|
|
|
h = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, GUI_PAD_SMALL);
|
|
|
|
h_box = GTK_BOX(h);
|
|
|
|
|
|
|
|
/* add the activity combobox */
|
|
|
|
w = activity;
|
|
|
|
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);
|
2019-11-06 19:09:27 +00:00
|
|
|
#if GTK_CHECK_VERSION(3, 12, 0)
|
|
|
|
gtk_widget_set_margin_end(w, GUI_PAD);
|
|
|
|
#else
|
|
|
|
gtk_widget_set_margin_right(w, GUI_PAD);
|
|
|
|
#endif
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* add the tracker combobox */
|
|
|
|
w = tracker;
|
|
|
|
gtk_box_pack_start(h_box, w, TRUE, TRUE, 0);
|
2019-11-06 19:09:27 +00:00
|
|
|
#if GTK_CHECK_VERSION(3, 12, 0)
|
|
|
|
gtk_widget_set_margin_end(w, GUI_PAD);
|
|
|
|
#else
|
|
|
|
gtk_widget_set_margin_right(w, GUI_PAD);
|
|
|
|
#endif
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* add the entry field */
|
|
|
|
s = gtk_entry_new();
|
2020-07-27 17:49:45 +00:00
|
|
|
gtk_entry_set_icon_from_icon_name(GTK_ENTRY(s), GTK_ENTRY_ICON_SECONDARY, "edit-clear");
|
2017-04-19 12:04:45 +00:00
|
|
|
g_signal_connect(s, "icon-release", G_CALLBACK(entry_clear), NULL);
|
|
|
|
gtk_box_pack_start(h_box, s, TRUE, TRUE, 0);
|
|
|
|
|
|
|
|
g_signal_connect(s, "changed", G_CALLBACK(filter_entry_changed), data->filter_model);
|
|
|
|
selection_changed_cb(NULL, data);
|
|
|
|
|
|
|
|
*filter_model = data->filter_model;
|
|
|
|
update_count_label(data);
|
|
|
|
return h;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|