2010-03-14 05:13:02 +00:00
|
|
|
/*
|
2011-01-19 13:48:47 +00:00
|
|
|
* This file Copyright (C) Mnemosyne LLC
|
2010-03-14 05:13:02 +00:00
|
|
|
*
|
2010-12-27 19:18:17 +00:00
|
|
|
* This file is licensed by the GPL version 2. Works owned by the
|
2012-12-05 17:29:46 +00:00
|
|
|
* Transmission project are granted a special exemption to clause 2 (b)
|
2010-03-14 05:13:02 +00:00
|
|
|
* so that the bulk of its code can remain under the MIT license.
|
|
|
|
* This exemption does not extend to derived works not owned by
|
|
|
|
* the Transmission project.
|
|
|
|
*
|
2010-03-16 00:45:12 +00:00
|
|
|
* $Id$
|
2010-03-14 05:13:02 +00:00
|
|
|
*/
|
|
|
|
|
2012-12-05 17:29:46 +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>
|
|
|
|
|
2012-12-05 17:29:46 +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 */
|
2012-12-05 17:29:46 +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
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
**** CATEGORIES
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
CAT_FILTER_TYPE_ALL,
|
|
|
|
CAT_FILTER_TYPE_PRIVATE,
|
|
|
|
CAT_FILTER_TYPE_PUBLIC,
|
|
|
|
CAT_FILTER_TYPE_HOST,
|
|
|
|
CAT_FILTER_TYPE_PARENT,
|
|
|
|
CAT_FILTER_TYPE_PRI_HIGH,
|
|
|
|
CAT_FILTER_TYPE_PRI_NORMAL,
|
|
|
|
CAT_FILTER_TYPE_PRI_LOW,
|
|
|
|
CAT_FILTER_TYPE_TAG,
|
|
|
|
CAT_FILTER_TYPE_SEPARATOR,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
CAT_FILTER_COL_NAME, /* human-readable name; ie, Legaltorrents */
|
|
|
|
CAT_FILTER_COL_COUNT, /* how many matches there are */
|
|
|
|
CAT_FILTER_COL_TYPE,
|
|
|
|
CAT_FILTER_COL_HOST, /* pattern-matching text; ie, legaltorrents.com */
|
2010-03-15 02:53:31 +00:00
|
|
|
CAT_FILTER_COL_PIXBUF,
|
2010-03-14 05:13:02 +00:00
|
|
|
CAT_FILTER_N_COLS
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
2012-12-05 17:29:46 +00:00
|
|
|
pstrcmp (const void * a, const void * b)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
return strcmp (* (const char**)a, * (const char**)b);
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2010-03-15 14:35:43 +00:00
|
|
|
/* human-readable name; ie, Legaltorrents */
|
2010-03-14 05:13:02 +00:00
|
|
|
static char*
|
2012-12-05 17:29:46 +00:00
|
|
|
get_name_from_host (const char * host)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
|
|
|
char * name;
|
2012-12-05 17:29:46 +00:00
|
|
|
const char * dot = strrchr (host, '.');
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (tr_addressIsIP (host))
|
|
|
|
name = g_strdup (host);
|
|
|
|
else if (dot)
|
|
|
|
name = g_strndup (host, dot - host);
|
2011-02-01 01:38:58 +00:00
|
|
|
else
|
2012-12-05 17:29:46 +00:00
|
|
|
name = g_strdup (host);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
*name = g_ascii_toupper (*name);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-12-05 17:29:46 +00:00
|
|
|
category_model_update_count (GtkTreeStore * store, GtkTreeIter * iter, int n)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
|
|
|
int count;
|
2012-12-05 17:29:46 +00:00
|
|
|
GtkTreeModel * model = GTK_TREE_MODEL (store);
|
|
|
|
gtk_tree_model_get (model, iter, CAT_FILTER_COL_COUNT, &count, -1);
|
|
|
|
if (n != count)
|
|
|
|
gtk_tree_store_set (store, iter, CAT_FILTER_COL_COUNT, n, -1);
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2010-03-15 02:53:31 +00:00
|
|
|
static void
|
2012-12-05 17:29:46 +00:00
|
|
|
favicon_ready_cb (gpointer pixbuf, gpointer vreference)
|
2010-03-15 02:53:31 +00:00
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeRowReference * reference = vreference;
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (pixbuf != NULL)
|
2010-03-15 02:53:31 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +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
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (gtk_tree_model_get_iter (model, &iter, path))
|
|
|
|
gtk_tree_store_set (GTK_TREE_STORE (model), &iter,
|
2010-03-15 14:35:43 +00:00
|
|
|
CAT_FILTER_COL_PIXBUF, pixbuf,
|
2012-12-05 17:29:46 +00:00
|
|
|
-1);
|
2010-03-15 02:53:31 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
gtk_tree_path_free (path);
|
2010-03-15 02:53:31 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
g_object_unref (pixbuf);
|
2010-03-15 02:53:31 +00:00
|
|
|
}
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
gtk_tree_row_reference_free (reference);
|
2010-03-15 02:53:31 +00:00
|
|
|
}
|
|
|
|
|
2010-03-14 05:13:02 +00:00
|
|
|
static gboolean
|
2012-12-05 17:29:46 +00:00
|
|
|
category_filter_model_update (GtkTreeStore * store)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
|
|
|
int i, n;
|
|
|
|
int low = 0;
|
|
|
|
int all = 0;
|
|
|
|
int high = 0;
|
|
|
|
int public = 0;
|
|
|
|
int normal = 0;
|
|
|
|
int private = 0;
|
|
|
|
int store_pos;
|
2010-03-16 00:45:12 +00:00
|
|
|
GtkTreeIter top;
|
2010-03-14 05:13:02 +00:00
|
|
|
GtkTreeIter iter;
|
2012-12-05 17:29:46 +00:00
|
|
|
GtkTreeModel * model = GTK_TREE_MODEL (store);
|
|
|
|
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);
|
|
|
|
GObject * o = G_OBJECT (store);
|
|
|
|
GtkTreeModel * tmodel = GTK_TREE_MODEL (g_object_get_qdata (o, TORRENT_MODEL_KEY));
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
g_object_steal_qdata (o, DIRTY_KEY);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2010-12-27 19:18:17 +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
|
2010-03-14 05:13:02 +00:00
|
|
|
* hosts s.t. we can merge it with the existing list */
|
2012-12-05 17:29:46 +00:00
|
|
|
if (gtk_tree_model_iter_nth_child (tmodel, &iter, NULL, 0)) do
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
|
|
|
tr_torrent * tor;
|
|
|
|
const tr_info * inf;
|
|
|
|
int keyCount;
|
|
|
|
char ** keys;
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
gtk_tree_model_get (tmodel, &iter, MC_TORRENT, &tor, -1);
|
|
|
|
inf = tr_torrentInfo (tor);
|
2010-03-14 05:13:02 +00:00
|
|
|
keyCount = 0;
|
2012-12-05 17:29:46 +00:00
|
|
|
keys = g_new (char*, inf->trackerCount);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
for (i=0, n=inf->trackerCount; i<n; ++i)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
|
|
|
int k;
|
2011-04-04 16:54:09 +00:00
|
|
|
int * count;
|
2011-04-28 23:13:14 +00:00
|
|
|
char buf[1024];
|
|
|
|
char * key;
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
gtr_get_host_from_url (buf, sizeof (buf), inf->trackers[i].announce);
|
|
|
|
key = g_string_chunk_insert_const (strings, buf);
|
2011-04-04 16:54:09 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
count = g_hash_table_lookup (hosts_hash, key);
|
|
|
|
if (count == NULL)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
count = tr_new0 (int, 1);
|
|
|
|
g_hash_table_insert (hosts_hash, key, count);
|
|
|
|
g_ptr_array_add (hosts, key);
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
for (k=0; k<keyCount; ++k)
|
|
|
|
if (!strcmp (keys[k], key))
|
2010-03-14 05:13:02 +00:00
|
|
|
break;
|
2012-12-05 17:29:46 +00:00
|
|
|
if (k==keyCount)
|
2011-04-28 23:13:14 +00:00
|
|
|
keys[keyCount++] = key;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
for (i=0; i<keyCount; ++i)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
int * incrementme = g_hash_table_lookup (hosts_hash, keys[i]);
|
2010-03-14 05:13:02 +00:00
|
|
|
++*incrementme;
|
|
|
|
}
|
2012-12-05 17:29:46 +00:00
|
|
|
g_free (keys);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
|
|
|
++all;
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (inf->isPrivate)
|
2010-03-14 05:13:02 +00:00
|
|
|
++private;
|
|
|
|
else
|
|
|
|
++public;
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
switch (tr_torrentGetPriority (tor))
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
|
|
|
case TR_PRI_HIGH: ++high; break;
|
|
|
|
case TR_PRI_LOW: ++low; break;
|
|
|
|
default: ++normal; break;
|
|
|
|
}
|
|
|
|
}
|
2012-12-05 17:29:46 +00:00
|
|
|
while (gtk_tree_model_iter_next (tmodel, &iter));
|
|
|
|
qsort (hosts->pdata, hosts->len, sizeof (char*), pstrcmp);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
|
|
|
/* update the "all" count */
|
2012-12-05 17:29:46 +00:00
|
|
|
gtk_tree_model_iter_children (model, &top, NULL);
|
|
|
|
category_model_update_count (store, &top, all);
|
2010-03-16 00:45:12 +00:00
|
|
|
|
|
|
|
/* skip separator */
|
2012-12-05 17:29:46 +00:00
|
|
|
gtk_tree_model_iter_next (model, &top);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
|
|
|
/* update the "hosts" subtree */
|
2012-12-05 17:29:46 +00:00
|
|
|
gtk_tree_model_iter_next (model, &top);
|
|
|
|
for (i=store_pos=0, n=hosts->len ; ;)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
|
|
|
const gboolean new_hosts_done = i >= n;
|
2012-12-05 17:29:46 +00:00
|
|
|
const gboolean old_hosts_done = !gtk_tree_model_iter_nth_child (model, &iter, &top, store_pos);
|
2010-03-14 05:13:02 +00:00
|
|
|
gboolean remove_row = FALSE;
|
|
|
|
gboolean insert_row = FALSE;
|
|
|
|
|
|
|
|
/* are we done yet? */
|
2012-12-05 17:29:46 +00:00
|
|
|
if (new_hosts_done && old_hosts_done)
|
2010-03-14 05:13:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* decide what to do */
|
2012-12-05 17:29:46 +00:00
|
|
|
if (new_hosts_done)
|
2010-03-14 05:13:02 +00:00
|
|
|
remove_row = TRUE;
|
2012-12-05 17:29:46 +00:00
|
|
|
else if (old_hosts_done)
|
2010-03-14 05:13:02 +00:00
|
|
|
insert_row = TRUE;
|
2010-03-16 00:45:12 +00:00
|
|
|
else {
|
2010-03-14 05:13:02 +00:00
|
|
|
int cmp;
|
|
|
|
char * host;
|
2012-12-05 17:29:46 +00:00
|
|
|
gtk_tree_model_get (model, &iter, CAT_FILTER_COL_HOST, &host, -1);
|
|
|
|
cmp = strcmp (host, hosts->pdata[i]);
|
|
|
|
if (cmp < 0)
|
2010-03-14 05:13:02 +00:00
|
|
|
remove_row = TRUE;
|
2012-12-05 17:29:46 +00:00
|
|
|
else if (cmp > 0)
|
2010-03-14 05:13:02 +00:00
|
|
|
insert_row = TRUE;
|
2012-12-05 17:29:46 +00:00
|
|
|
g_free (host);
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* do something */
|
2012-12-05 17:29:46 +00:00
|
|
|
if (remove_row) {
|
|
|
|
/* g_message ("removing row and incrementing i"); */
|
|
|
|
gtk_tree_store_remove (store, &iter);
|
|
|
|
} else if (insert_row) {
|
2010-03-16 00:45:12 +00:00
|
|
|
GtkTreeIter add;
|
2010-03-15 02:53:31 +00:00
|
|
|
GtkTreePath * path;
|
|
|
|
GtkTreeRowReference * reference;
|
2012-12-05 17:29:46 +00:00
|
|
|
tr_session * session = g_object_get_qdata (G_OBJECT (store), SESSION_KEY);
|
2010-03-14 05:13:02 +00:00
|
|
|
const char * host = hosts->pdata[i];
|
2012-12-05 17:29:46 +00:00
|
|
|
char * name = get_name_from_host (host);
|
|
|
|
const int count = * (int*)g_hash_table_lookup (hosts_hash, host);
|
|
|
|
gtk_tree_store_insert_with_values (store, &add, &top, store_pos,
|
2010-03-14 05:13:02 +00:00
|
|
|
CAT_FILTER_COL_HOST, host,
|
|
|
|
CAT_FILTER_COL_NAME, name,
|
|
|
|
CAT_FILTER_COL_COUNT, count,
|
|
|
|
CAT_FILTER_COL_TYPE, CAT_FILTER_TYPE_HOST,
|
2012-12-05 17:29:46 +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);
|
2010-03-14 05:13:02 +00:00
|
|
|
++store_pos;
|
|
|
|
++i;
|
|
|
|
} else { /* update row */
|
|
|
|
const char * host = hosts->pdata[i];
|
2012-12-05 17:29:46 +00:00
|
|
|
const int count = * (int*)g_hash_table_lookup (hosts_hash, host);
|
|
|
|
category_model_update_count (store, &iter, count);
|
2010-03-14 05:13:02 +00:00
|
|
|
++store_pos;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
2010-03-17 17:07:40 +00:00
|
|
|
|
2010-05-16 15:51:01 +00:00
|
|
|
/* update the "public" subtree */
|
2012-12-05 17:29:46 +00:00
|
|
|
gtk_tree_model_iter_next (model, &top);
|
|
|
|
gtk_tree_model_iter_children (model, &iter, &top);
|
|
|
|
category_model_update_count (store, &iter, public);
|
|
|
|
gtk_tree_model_iter_next (model, &iter);
|
|
|
|
category_model_update_count (store, &iter, private);
|
2010-05-16 15:51:01 +00:00
|
|
|
|
|
|
|
/* update the "priority" subtree */
|
2012-12-05 17:29:46 +00:00
|
|
|
gtk_tree_model_iter_next (model, &top);
|
|
|
|
gtk_tree_model_iter_children (model, &iter, &top);
|
|
|
|
category_model_update_count (store, &iter, high);
|
|
|
|
gtk_tree_model_iter_next (model, &iter);
|
|
|
|
category_model_update_count (store, &iter, normal);
|
|
|
|
gtk_tree_model_iter_next (model, &iter);
|
|
|
|
category_model_update_count (store, &iter, low);
|
2010-05-16 15:51:01 +00:00
|
|
|
|
2010-03-14 05:13:02 +00:00
|
|
|
/* cleanup */
|
2012-12-05 17:29:46 +00:00
|
|
|
g_ptr_array_free (hosts, TRUE);
|
|
|
|
g_hash_table_unref (hosts_hash);
|
|
|
|
g_string_chunk_free (strings);
|
2010-03-14 05:13:02 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkTreeModel *
|
2012-12-05 17:29:46 +00:00
|
|
|
category_filter_model_new (GtkTreeModel * tmodel)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
const int invisible_number = -1; /* doesn't get rendered */
|
2012-12-05 17:29:46 +00:00
|
|
|
GtkTreeStore * store = gtk_tree_store_new (CAT_FILTER_N_COLS,
|
2010-03-16 00:45:12 +00:00
|
|
|
G_TYPE_STRING,
|
|
|
|
G_TYPE_INT,
|
|
|
|
G_TYPE_INT,
|
|
|
|
G_TYPE_STRING,
|
2012-12-05 17:29:46 +00:00
|
|
|
GDK_TYPE_PIXBUF);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
gtk_tree_store_insert_with_values (store, NULL, NULL, -1,
|
|
|
|
CAT_FILTER_COL_NAME, _("All"),
|
2010-03-14 05:13:02 +00:00
|
|
|
CAT_FILTER_COL_TYPE, CAT_FILTER_TYPE_ALL,
|
2012-12-05 17:29:46 +00:00
|
|
|
-1);
|
|
|
|
gtk_tree_store_insert_with_values (store, NULL, NULL, -1,
|
2010-03-14 05:13:02 +00:00
|
|
|
CAT_FILTER_COL_TYPE, CAT_FILTER_TYPE_SEPARATOR,
|
2012-12-05 17:29:46 +00:00
|
|
|
-1);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
gtk_tree_store_insert_with_values (store, &iter, NULL, -1,
|
|
|
|
CAT_FILTER_COL_NAME, _("Trackers"),
|
2010-05-16 15:51:01 +00:00
|
|
|
CAT_FILTER_COL_COUNT, invisible_number,
|
|
|
|
CAT_FILTER_COL_TYPE, CAT_FILTER_TYPE_PARENT,
|
2012-12-05 17:29:46 +00:00
|
|
|
-1);
|
2010-05-16 15:51:01 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
gtk_tree_store_insert_with_values (store, &iter, NULL, -1,
|
|
|
|
CAT_FILTER_COL_NAME, _("Privacy"),
|
2010-03-14 05:13:02 +00:00
|
|
|
CAT_FILTER_COL_COUNT, invisible_number,
|
|
|
|
CAT_FILTER_COL_TYPE, CAT_FILTER_TYPE_PARENT,
|
2012-12-05 17:29:46 +00:00
|
|
|
-1);
|
|
|
|
gtk_tree_store_insert_with_values (store, NULL, &iter, -1,
|
|
|
|
CAT_FILTER_COL_NAME, _("Public"),
|
2010-03-14 05:13:02 +00:00
|
|
|
CAT_FILTER_COL_TYPE, CAT_FILTER_TYPE_PUBLIC,
|
2012-12-05 17:29:46 +00:00
|
|
|
-1);
|
|
|
|
gtk_tree_store_insert_with_values (store, NULL, &iter, -1,
|
|
|
|
CAT_FILTER_COL_NAME, _("Private"),
|
2010-03-14 05:13:02 +00:00
|
|
|
CAT_FILTER_COL_TYPE, CAT_FILTER_TYPE_PRIVATE,
|
2012-12-05 17:29:46 +00:00
|
|
|
-1);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
gtk_tree_store_insert_with_values (store, &iter, NULL, -1,
|
|
|
|
CAT_FILTER_COL_NAME, _("Priority"),
|
2010-03-14 05:13:02 +00:00
|
|
|
CAT_FILTER_COL_COUNT, invisible_number,
|
|
|
|
CAT_FILTER_COL_TYPE, CAT_FILTER_TYPE_PARENT,
|
2012-12-05 17:29:46 +00:00
|
|
|
-1);
|
|
|
|
gtk_tree_store_insert_with_values (store, NULL, &iter, -1,
|
|
|
|
CAT_FILTER_COL_NAME, _("High"),
|
2010-03-14 05:13:02 +00:00
|
|
|
CAT_FILTER_COL_TYPE, CAT_FILTER_TYPE_PRI_HIGH,
|
2012-12-05 17:29:46 +00:00
|
|
|
-1);
|
|
|
|
gtk_tree_store_insert_with_values (store, NULL, &iter, -1,
|
|
|
|
CAT_FILTER_COL_NAME, _("Normal"),
|
2010-03-14 05:13:02 +00:00
|
|
|
CAT_FILTER_COL_TYPE, CAT_FILTER_TYPE_PRI_NORMAL,
|
2012-12-05 17:29:46 +00:00
|
|
|
-1);
|
|
|
|
gtk_tree_store_insert_with_values (store, NULL, &iter, -1,
|
|
|
|
CAT_FILTER_COL_NAME, _("Low"),
|
2010-03-14 05:13:02 +00:00
|
|
|
CAT_FILTER_COL_TYPE, CAT_FILTER_TYPE_PRI_LOW,
|
2012-12-05 17:29:46 +00:00
|
|
|
-1);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
g_object_set_qdata (G_OBJECT (store), TORRENT_MODEL_KEY, tmodel);
|
|
|
|
category_filter_model_update (store);
|
|
|
|
return GTK_TREE_MODEL (store);
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-12-05 17:29:46 +00:00
|
|
|
is_it_a_separator (GtkTreeModel * m, GtkTreeIter * iter, gpointer data UNUSED)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
|
|
|
int type;
|
2012-12-05 17:29:46 +00:00
|
|
|
gtk_tree_model_get (m, iter, CAT_FILTER_COL_TYPE, &type, -1);
|
2010-03-14 05:13:02 +00:00
|
|
|
return type == CAT_FILTER_TYPE_SEPARATOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-12-05 17:29:46 +00:00
|
|
|
category_model_update_idle (gpointer category_model)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
GObject * o = G_OBJECT (category_model);
|
|
|
|
const gboolean pending = g_object_get_qdata (o, DIRTY_KEY) != NULL;
|
|
|
|
if (!pending)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
|
|
|
GSourceFunc func = (GSourceFunc) category_filter_model_update;
|
2012-12-05 17:29:46 +00:00
|
|
|
g_object_set_qdata (o, DIRTY_KEY, GINT_TO_POINTER (1));
|
|
|
|
gdk_threads_add_idle (func, category_model);
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-12-05 17:29:46 +00:00
|
|
|
torrent_model_row_changed (GtkTreeModel * tmodel UNUSED,
|
2010-03-14 05:13:02 +00:00
|
|
|
GtkTreePath * path UNUSED,
|
|
|
|
GtkTreeIter * iter UNUSED,
|
2012-12-05 17:29:46 +00:00
|
|
|
gpointer category_model)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
category_model_update_idle (category_model);
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-12-05 17:29:46 +00:00
|
|
|
torrent_model_row_deleted_cb (GtkTreeModel * tmodel UNUSED,
|
2010-03-14 05:13:02 +00:00
|
|
|
GtkTreePath * path UNUSED,
|
2012-12-05 17:29:46 +00:00
|
|
|
gpointer category_model)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
category_model_update_idle (category_model);
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2010-03-15 02:53:31 +00:00
|
|
|
static void
|
2012-12-05 17:29:46 +00:00
|
|
|
render_pixbuf_func (GtkCellLayout * cell_layout UNUSED,
|
2010-03-15 02:53:31 +00:00
|
|
|
GtkCellRenderer * cell_renderer,
|
|
|
|
GtkTreeModel * tree_model,
|
|
|
|
GtkTreeIter * iter,
|
2012-12-05 17:29:46 +00:00
|
|
|
gpointer data UNUSED)
|
2010-03-15 02:53:31 +00:00
|
|
|
{
|
|
|
|
int type;
|
2010-03-16 00:45:12 +00:00
|
|
|
int width = 0;
|
2012-12-05 17:29:46 +00:00
|
|
|
const gboolean leaf = !gtk_tree_model_iter_has_child (tree_model, iter);
|
2010-03-16 00:45:12 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
gtk_tree_model_get (tree_model, iter, CAT_FILTER_COL_TYPE, &type, -1);
|
|
|
|
if (type == CAT_FILTER_TYPE_HOST)
|
2010-03-16 00:45:12 +00:00
|
|
|
width = 20;
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
g_object_set (cell_renderer, "width", width,
|
2010-03-16 00:45:12 +00:00
|
|
|
"sensitive", leaf,
|
2012-12-05 17:29:46 +00:00
|
|
|
NULL);
|
2010-03-16 00:45:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-12-05 17:29:46 +00:00
|
|
|
is_capital_sensitive (GtkCellLayout * cell_layout UNUSED,
|
2010-03-16 00:45:12 +00:00
|
|
|
GtkCellRenderer * cell_renderer,
|
|
|
|
GtkTreeModel * tree_model,
|
|
|
|
GtkTreeIter * iter,
|
2012-12-05 17:29:46 +00:00
|
|
|
gpointer data UNUSED)
|
2010-03-16 00:45:12 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
const gboolean leaf = !gtk_tree_model_iter_has_child (tree_model, iter);
|
2010-03-16 00:45:12 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
g_object_set (cell_renderer, "sensitive", leaf,
|
|
|
|
NULL);
|
2010-03-15 02:53:31 +00:00
|
|
|
}
|
2010-03-16 00:45:12 +00:00
|
|
|
|
2010-03-14 05:13:02 +00:00
|
|
|
static void
|
2012-12-05 17:29:46 +00:00
|
|
|
render_number_func (GtkCellLayout * cell_layout UNUSED,
|
2010-03-15 14:35:43 +00:00
|
|
|
GtkCellRenderer * cell_renderer,
|
|
|
|
GtkTreeModel * tree_model,
|
|
|
|
GtkTreeIter * iter,
|
2012-12-05 17:29:46 +00:00
|
|
|
gpointer data UNUSED)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
|
|
|
int count;
|
2010-03-16 00:45:12 +00:00
|
|
|
char buf[32];
|
2012-12-05 17:29:46 +00:00
|
|
|
const gboolean leaf = !gtk_tree_model_iter_has_child (tree_model, iter);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
gtk_tree_model_get (tree_model, iter, CAT_FILTER_COL_COUNT, &count, -1);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (count >= 0)
|
|
|
|
g_snprintf (buf, sizeof (buf), "%'d", count);
|
2010-03-14 05:13:02 +00:00
|
|
|
else
|
|
|
|
*buf = '\0';
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
g_object_set (cell_renderer, "text", buf,
|
2010-03-16 00:45:12 +00:00
|
|
|
"sensitive", leaf,
|
2012-12-05 17:29:46 +00:00
|
|
|
NULL);
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GtkCellRenderer *
|
2012-12-05 17:29:46 +00:00
|
|
|
number_renderer_new (void)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
GtkCellRenderer * r = gtk_cell_renderer_text_new ();
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
g_object_set (G_OBJECT (r), "alignment", PANGO_ALIGN_RIGHT,
|
2010-03-14 05:13:02 +00:00
|
|
|
"weight", PANGO_WEIGHT_ULTRALIGHT,
|
|
|
|
"xalign", 1.0,
|
|
|
|
"xpad", GUI_PAD,
|
2012-12-05 17:29:46 +00:00
|
|
|
NULL);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2011-03-25 17:42:47 +00:00
|
|
|
static void
|
2012-12-05 17:29:46 +00:00
|
|
|
disconnect_cat_model_callbacks (gpointer tmodel, GObject * cat_model)
|
2011-03-25 17:42:47 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (tmodel, torrent_model_row_changed, cat_model);
|
|
|
|
g_signal_handlers_disconnect_by_func (tmodel, torrent_model_row_deleted_cb, cat_model);
|
2011-03-25 17:42:47 +00:00
|
|
|
}
|
|
|
|
|
2010-03-14 05:13:02 +00:00
|
|
|
static GtkWidget *
|
2012-12-05 17:29:46 +00:00
|
|
|
category_combo_box_new (GtkTreeModel * tmodel)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
|
|
|
GtkWidget * c;
|
|
|
|
GtkCellRenderer * r;
|
2010-03-16 00:45:12 +00:00
|
|
|
GtkTreeModel * cat_model;
|
2012-12-13 03:00:57 +00:00
|
|
|
GtkCellLayout * c_cell_layout;
|
|
|
|
GtkComboBox * c_combo_box;
|
2010-03-14 05:13:02 +00:00
|
|
|
|
|
|
|
/* create the category combobox */
|
2012-12-05 17:29:46 +00:00
|
|
|
cat_model = category_filter_model_new (tmodel);
|
|
|
|
c = gtk_combo_box_new_with_model (cat_model);
|
2012-12-13 03:00:57 +00:00
|
|
|
c_combo_box = GTK_COMBO_BOX (c);
|
|
|
|
c_cell_layout = GTK_CELL_LAYOUT (c);
|
2012-12-05 17:29:46 +00:00
|
|
|
g_object_unref (cat_model);
|
2012-12-13 03:00:57 +00:00
|
|
|
gtk_combo_box_set_row_separator_func (c_combo_box,
|
2012-12-05 17:29:46 +00:00
|
|
|
is_it_a_separator, NULL, NULL);
|
2012-12-13 03:00:57 +00:00
|
|
|
gtk_combo_box_set_active (c_combo_box, 0);
|
2012-12-05 17:29:46 +00:00
|
|
|
|
|
|
|
r = gtk_cell_renderer_pixbuf_new ();
|
2012-12-13 03:00:57 +00:00
|
|
|
gtk_cell_layout_pack_start (c_cell_layout, r, FALSE);
|
|
|
|
gtk_cell_layout_set_cell_data_func (c_cell_layout, r,
|
2012-12-05 17:29:46 +00:00
|
|
|
render_pixbuf_func, NULL, NULL);
|
2012-12-13 03:00:57 +00:00
|
|
|
gtk_cell_layout_set_attributes (c_cell_layout, r,
|
2010-03-15 02:53:31 +00:00
|
|
|
"pixbuf", CAT_FILTER_COL_PIXBUF,
|
2012-12-05 17:29:46 +00:00
|
|
|
NULL);
|
2010-03-17 17:07:40 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
r = gtk_cell_renderer_text_new ();
|
2012-12-13 03:00:57 +00:00
|
|
|
gtk_cell_layout_pack_start (c_cell_layout, r, FALSE);
|
|
|
|
gtk_cell_layout_set_attributes (c_cell_layout, r,
|
2010-03-14 05:13:02 +00:00
|
|
|
"text", CAT_FILTER_COL_NAME,
|
2012-12-05 17:29:46 +00:00
|
|
|
NULL);
|
2012-12-13 03:00:57 +00:00
|
|
|
gtk_cell_layout_set_cell_data_func (c_cell_layout, r,
|
2010-03-16 00:45:12 +00:00
|
|
|
is_capital_sensitive,
|
|
|
|
NULL, NULL);
|
|
|
|
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
r = number_renderer_new ();
|
2012-12-13 03:00:57 +00:00
|
|
|
gtk_cell_layout_pack_end (c_cell_layout, r, TRUE);
|
|
|
|
gtk_cell_layout_set_cell_data_func (c_cell_layout, r,
|
2012-12-05 17:29:46 +00:00
|
|
|
render_number_func, NULL, NULL);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2012-12-05 17:29:46 +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);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-12-05 17:29:46 +00:00
|
|
|
test_category (tr_torrent * tor, int active_category_type, const char * host)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
const tr_info * const inf = tr_torrentInfo (tor);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
switch (active_category_type)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
|
|
|
case CAT_FILTER_TYPE_ALL:
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case CAT_FILTER_TYPE_PRIVATE:
|
|
|
|
return inf->isPrivate;
|
|
|
|
|
|
|
|
case CAT_FILTER_TYPE_PUBLIC:
|
|
|
|
return !inf->isPrivate;
|
|
|
|
|
|
|
|
case CAT_FILTER_TYPE_PRI_HIGH:
|
2012-12-05 17:29:46 +00:00
|
|
|
return tr_torrentGetPriority (tor) == TR_PRI_HIGH;
|
2010-03-14 05:13:02 +00:00
|
|
|
|
|
|
|
case CAT_FILTER_TYPE_PRI_NORMAL:
|
2012-12-05 17:29:46 +00:00
|
|
|
return tr_torrentGetPriority (tor) == TR_PRI_NORMAL;
|
2010-03-14 05:13:02 +00:00
|
|
|
|
|
|
|
case CAT_FILTER_TYPE_PRI_LOW:
|
2012-12-05 17:29:46 +00:00
|
|
|
return tr_torrentGetPriority (tor) == TR_PRI_LOW;
|
2010-03-14 05:13:02 +00:00
|
|
|
|
|
|
|
case CAT_FILTER_TYPE_HOST: {
|
|
|
|
int i;
|
2011-04-04 16:54:09 +00:00
|
|
|
char tmp[1024];
|
2012-12-05 17:29:46 +00:00
|
|
|
for (i=0; i<inf->trackerCount; ++i) {
|
|
|
|
gtr_get_host_from_url (tmp, sizeof (tmp), inf->trackers[i].announce);
|
|
|
|
if (!strcmp (tmp, host))
|
2010-03-14 05:13:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return i < inf->trackerCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CAT_FILTER_TYPE_TAG:
|
2010-03-14 15:05:32 +00:00
|
|
|
/* FIXME */
|
|
|
|
return TRUE;
|
|
|
|
|
2010-03-14 05:13:02 +00:00
|
|
|
default:
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
2010-03-27 02:52:10 +00:00
|
|
|
**** ACTIVITY
|
2010-03-14 05:13:02 +00:00
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2010-03-27 02:52:10 +00:00
|
|
|
ACTIVITY_FILTER_ALL,
|
|
|
|
ACTIVITY_FILTER_DOWNLOADING,
|
|
|
|
ACTIVITY_FILTER_SEEDING,
|
|
|
|
ACTIVITY_FILTER_ACTIVE,
|
|
|
|
ACTIVITY_FILTER_PAUSED,
|
2010-08-01 17:43:35 +00:00
|
|
|
ACTIVITY_FILTER_FINISHED,
|
2010-03-27 02:52:10 +00:00
|
|
|
ACTIVITY_FILTER_VERIFYING,
|
|
|
|
ACTIVITY_FILTER_ERROR,
|
|
|
|
ACTIVITY_FILTER_SEPARATOR
|
2010-03-14 05:13:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2010-03-27 02:52:10 +00:00
|
|
|
ACTIVITY_FILTER_COL_NAME,
|
|
|
|
ACTIVITY_FILTER_COL_COUNT,
|
|
|
|
ACTIVITY_FILTER_COL_TYPE,
|
2010-05-18 14:14:17 +00:00
|
|
|
ACTIVITY_FILTER_COL_STOCK_ID,
|
2010-03-27 02:52:10 +00:00
|
|
|
ACTIVITY_FILTER_N_COLS
|
2010-03-14 05:13:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static gboolean
|
2012-12-05 17:29:46 +00:00
|
|
|
activity_is_it_a_separator (GtkTreeModel * m, GtkTreeIter * i, gpointer d UNUSED)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
|
|
|
int type;
|
2012-12-05 17:29:46 +00:00
|
|
|
gtk_tree_model_get (m, i, ACTIVITY_FILTER_COL_TYPE, &type, -1);
|
2010-03-27 02:52:10 +00:00
|
|
|
return type == ACTIVITY_FILTER_SEPARATOR;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-12-05 17:29:46 +00:00
|
|
|
test_torrent_activity (tr_torrent * tor, int type)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
const tr_stat * st = tr_torrentStatCached (tor);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
switch (type)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2010-03-27 02:52:10 +00:00
|
|
|
case ACTIVITY_FILTER_DOWNLOADING:
|
2012-12-05 17:29:46 +00:00
|
|
|
return (st->activity == TR_STATUS_DOWNLOAD)
|
|
|
|
|| (st->activity == TR_STATUS_DOWNLOAD_WAIT);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2010-03-27 02:52:10 +00:00
|
|
|
case ACTIVITY_FILTER_SEEDING:
|
2012-12-05 17:29:46 +00:00
|
|
|
return (st->activity == TR_STATUS_SEED)
|
|
|
|
|| (st->activity == TR_STATUS_SEED_WAIT);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2010-03-27 02:52:10 +00:00
|
|
|
case ACTIVITY_FILTER_ACTIVE:
|
2012-12-05 17:29:46 +00:00
|
|
|
return (st->peersSendingToUs > 0)
|
|
|
|
|| (st->peersGettingFromUs > 0)
|
|
|
|
|| (st->webseedsSendingToUs > 0)
|
|
|
|
|| (st->activity == TR_STATUS_CHECK);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2010-03-27 02:52:10 +00:00
|
|
|
case ACTIVITY_FILTER_PAUSED:
|
2010-03-14 05:13:02 +00:00
|
|
|
return st->activity == TR_STATUS_STOPPED;
|
|
|
|
|
2010-08-01 17:43:35 +00:00
|
|
|
case ACTIVITY_FILTER_FINISHED:
|
|
|
|
return st->finished == TRUE;
|
|
|
|
|
2010-03-27 02:52:10 +00:00
|
|
|
case ACTIVITY_FILTER_VERIFYING:
|
2012-12-05 17:29:46 +00:00
|
|
|
return (st->activity == TR_STATUS_CHECK)
|
|
|
|
|| (st->activity == TR_STATUS_CHECK_WAIT);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2010-03-27 02:52:10 +00:00
|
|
|
case ACTIVITY_FILTER_ERROR:
|
2010-03-14 05:13:02 +00:00
|
|
|
return st->error != 0;
|
|
|
|
|
2010-03-27 02:52:10 +00:00
|
|
|
default: /* ACTIVITY_FILTER_ALL */
|
2010-03-14 05:13:02 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-12-05 17:29:46 +00:00
|
|
|
status_model_update_count (GtkListStore * store, GtkTreeIter * iter, int n)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
|
|
|
int count;
|
2012-12-05 17:29:46 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-12-05 17:29:46 +00:00
|
|
|
activity_filter_model_update (GtkListStore * store)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
2012-12-05 17:29:46 +00:00
|
|
|
GtkTreeModel * model = GTK_TREE_MODEL (store);
|
|
|
|
GObject * o = G_OBJECT (store);
|
|
|
|
GtkTreeModel * tmodel = GTK_TREE_MODEL (g_object_get_qdata (o, TORRENT_MODEL_KEY));
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
g_object_steal_qdata (o, DIRTY_KEY);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (gtk_tree_model_iter_nth_child (model, &iter, NULL, 0)) do
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
|
|
|
int hits;
|
|
|
|
int type;
|
|
|
|
GtkTreeIter torrent_iter;
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
gtk_tree_model_get (model, &iter, ACTIVITY_FILTER_COL_TYPE, &type, -1);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
|
|
|
hits = 0;
|
2012-12-05 17:29:46 +00:00
|
|
|
if (gtk_tree_model_iter_nth_child (tmodel, &torrent_iter, NULL, 0)) do {
|
2010-03-14 05:13:02 +00:00
|
|
|
tr_torrent * tor;
|
2012-12-05 17:29:46 +00:00
|
|
|
gtk_tree_model_get (tmodel, &torrent_iter, MC_TORRENT, &tor, -1);
|
|
|
|
if (test_torrent_activity (tor, type))
|
2010-03-14 05:13:02 +00:00
|
|
|
++hits;
|
2012-12-05 17:29:46 +00:00
|
|
|
} while (gtk_tree_model_iter_next (tmodel, &torrent_iter));
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
status_model_update_count (store, &iter, hits);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
} while (gtk_tree_model_iter_next (model, &iter));
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GtkTreeModel *
|
2012-12-05 17:29:46 +00:00
|
|
|
activity_filter_model_new (GtkTreeModel * tmodel)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
|
|
|
int i, n;
|
|
|
|
struct {
|
|
|
|
int type;
|
2012-04-13 14:49:34 +00:00
|
|
|
const char * context;
|
2010-03-14 05:13:02 +00:00
|
|
|
const char * name;
|
2010-05-18 14:14:17 +00:00
|
|
|
const char * stock_id;
|
2010-03-14 05:13:02 +00:00
|
|
|
} types[] = {
|
2012-12-05 17:29:46 +00:00
|
|
|
{ ACTIVITY_FILTER_ALL, NULL, N_("All"), NULL },
|
2012-04-13 14:49:34 +00:00
|
|
|
{ ACTIVITY_FILTER_SEPARATOR, NULL, NULL, NULL },
|
2012-12-05 17:29:46 +00:00
|
|
|
{ ACTIVITY_FILTER_ACTIVE, NULL, N_("Active"), GTK_STOCK_EXECUTE },
|
|
|
|
{ ACTIVITY_FILTER_DOWNLOADING, "Verb", NC_("Verb", "Downloading"), GTK_STOCK_GO_DOWN },
|
|
|
|
{ ACTIVITY_FILTER_SEEDING, "Verb", NC_("Verb", "Seeding"), GTK_STOCK_GO_UP },
|
|
|
|
{ ACTIVITY_FILTER_PAUSED, NULL, N_("Paused"), GTK_STOCK_MEDIA_PAUSE },
|
|
|
|
{ ACTIVITY_FILTER_FINISHED, NULL, N_("Finished"), NULL },
|
|
|
|
{ ACTIVITY_FILTER_VERIFYING, "Verb", NC_("Verb", "Verifying"), GTK_STOCK_REFRESH },
|
|
|
|
{ ACTIVITY_FILTER_ERROR, NULL, N_("Error"), GTK_STOCK_DIALOG_ERROR }
|
2010-03-14 05:13:02 +00:00
|
|
|
};
|
2012-12-05 17:29:46 +00:00
|
|
|
GtkListStore * store = gtk_list_store_new (ACTIVITY_FILTER_N_COLS,
|
2010-05-18 14:14:17 +00:00
|
|
|
G_TYPE_STRING,
|
|
|
|
G_TYPE_INT,
|
|
|
|
G_TYPE_INT,
|
2012-12-05 17:29:46 +00:00
|
|
|
G_TYPE_STRING);
|
|
|
|
for (i=0, n=G_N_ELEMENTS (types); i<n; ++i) {
|
|
|
|
const char * name = types[i].context ? g_dpgettext2 (NULL, types[i].context, types[i].name)
|
|
|
|
: _ (types[i].name);
|
|
|
|
gtk_list_store_insert_with_values (store, NULL, -1,
|
2012-04-13 14:49:34 +00:00
|
|
|
ACTIVITY_FILTER_COL_NAME, name,
|
2010-03-27 02:52:10 +00:00
|
|
|
ACTIVITY_FILTER_COL_TYPE, types[i].type,
|
2010-05-18 14:14:17 +00:00
|
|
|
ACTIVITY_FILTER_COL_STOCK_ID, types[i].stock_id,
|
2012-12-05 17:29:46 +00:00
|
|
|
-1);
|
2012-04-13 14:49:34 +00:00
|
|
|
}
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2012-12-05 17:29:46 +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
|
|
|
}
|
|
|
|
|
2010-05-18 14:14:17 +00:00
|
|
|
static void
|
2012-12-05 17:29:46 +00:00
|
|
|
render_activity_pixbuf_func (GtkCellLayout * cell_layout UNUSED,
|
2010-05-18 14:14:17 +00:00
|
|
|
GtkCellRenderer * cell_renderer,
|
|
|
|
GtkTreeModel * tree_model,
|
|
|
|
GtkTreeIter * iter,
|
2012-12-05 17:29:46 +00:00
|
|
|
gpointer data UNUSED)
|
2010-05-18 14:14:17 +00:00
|
|
|
{
|
|
|
|
int type;
|
|
|
|
int width;
|
|
|
|
int ypad;
|
2012-12-05 17:29:46 +00:00
|
|
|
const gboolean leaf = !gtk_tree_model_iter_has_child (tree_model, iter);
|
2010-05-18 14:14:17 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
gtk_tree_model_get (tree_model, iter, ACTIVITY_FILTER_COL_TYPE, &type, -1);
|
2010-05-18 14:14:17 +00:00
|
|
|
width = type == ACTIVITY_FILTER_ALL ? 0 : 20;
|
2010-05-20 16:37:59 +00:00
|
|
|
ypad = type == ACTIVITY_FILTER_ALL ? 0 : 2;
|
2010-05-18 14:14:17 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
g_object_set (cell_renderer, "width", width,
|
2010-05-18 14:14:17 +00:00
|
|
|
"sensitive", leaf,
|
|
|
|
"ypad", ypad,
|
2012-12-05 17:29:46 +00:00
|
|
|
NULL);
|
2010-05-18 14:14:17 +00:00
|
|
|
}
|
|
|
|
|
2010-03-14 05:13:02 +00:00
|
|
|
static void
|
2012-12-05 17:29:46 +00:00
|
|
|
activity_model_update_idle (gpointer activity_model)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
GObject * o = G_OBJECT (activity_model);
|
|
|
|
const gboolean pending = g_object_get_qdata (o, DIRTY_KEY) != NULL;
|
|
|
|
if (!pending)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2010-03-27 02:52:10 +00:00
|
|
|
GSourceFunc func = (GSourceFunc) activity_filter_model_update;
|
2012-12-05 17:29:46 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-12-05 17:29:46 +00:00
|
|
|
activity_torrent_model_row_changed (GtkTreeModel * tmodel UNUSED,
|
2010-03-27 02:52:10 +00:00
|
|
|
GtkTreePath * path UNUSED,
|
|
|
|
GtkTreeIter * iter UNUSED,
|
2012-12-05 17:29:46 +00:00
|
|
|
gpointer activity_model)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
activity_model_update_idle (activity_model);
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-12-05 17:29:46 +00:00
|
|
|
activity_torrent_model_row_deleted_cb (GtkTreeModel * tmodel UNUSED,
|
2010-03-27 02:52:10 +00:00
|
|
|
GtkTreePath * path UNUSED,
|
2012-12-05 17:29:46 +00:00
|
|
|
gpointer activity_model)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
activity_model_update_idle (activity_model);
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2011-03-25 17:42:47 +00:00
|
|
|
static void
|
2012-12-05 17:29:46 +00:00
|
|
|
disconnect_activity_model_callbacks (gpointer tmodel, GObject * cat_model)
|
2011-03-25 17:42:47 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (tmodel, activity_torrent_model_row_changed, cat_model);
|
|
|
|
g_signal_handlers_disconnect_by_func (tmodel, activity_torrent_model_row_deleted_cb, cat_model);
|
2011-03-25 17:42:47 +00:00
|
|
|
}
|
|
|
|
|
2010-03-14 05:13:02 +00:00
|
|
|
static GtkWidget *
|
2012-12-05 17:29:46 +00:00
|
|
|
activity_combo_box_new (GtkTreeModel * tmodel)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
|
|
|
GtkWidget * c;
|
|
|
|
GtkCellRenderer * r;
|
2010-03-27 02:52:10 +00:00
|
|
|
GtkTreeModel * activity_model;
|
2012-12-13 03:00:57 +00:00
|
|
|
GtkComboBox * c_combo_box;
|
|
|
|
GtkCellLayout * c_cell_layout;
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
activity_model = activity_filter_model_new (tmodel);
|
|
|
|
c = gtk_combo_box_new_with_model (activity_model);
|
2012-12-13 03:00:57 +00:00
|
|
|
c_combo_box = GTK_COMBO_BOX (c);
|
|
|
|
c_cell_layout = GTK_CELL_LAYOUT (c);
|
2012-12-05 17:29:46 +00:00
|
|
|
g_object_unref (activity_model);
|
2012-12-13 03:00:57 +00:00
|
|
|
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);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
r = gtk_cell_renderer_pixbuf_new ();
|
2012-12-13 03:00:57 +00:00
|
|
|
gtk_cell_layout_pack_start (c_cell_layout, r, FALSE);
|
|
|
|
gtk_cell_layout_set_attributes (c_cell_layout, r,
|
2010-05-18 14:14:17 +00:00
|
|
|
"stock-id", ACTIVITY_FILTER_COL_STOCK_ID,
|
2012-12-05 17:29:46 +00:00
|
|
|
NULL);
|
2012-12-13 03:00:57 +00:00
|
|
|
gtk_cell_layout_set_cell_data_func (c_cell_layout, r,
|
2012-12-05 17:29:46 +00:00
|
|
|
render_activity_pixbuf_func, NULL, NULL);
|
2010-05-18 14:14:17 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
r = gtk_cell_renderer_text_new ();
|
2012-12-13 03:00:57 +00:00
|
|
|
gtk_cell_layout_pack_start (c_cell_layout, r, TRUE);
|
|
|
|
gtk_cell_layout_set_attributes (c_cell_layout, r,
|
2010-03-27 02:52:10 +00:00
|
|
|
"text", ACTIVITY_FILTER_COL_NAME,
|
2012-12-05 17:29:46 +00:00
|
|
|
NULL);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
r = number_renderer_new ();
|
2012-12-13 03:00:57 +00:00
|
|
|
gtk_cell_layout_pack_end (c_cell_layout, r, TRUE);
|
|
|
|
gtk_cell_layout_set_cell_data_func (c_cell_layout, r,
|
2012-12-05 17:29:46 +00:00
|
|
|
render_number_func, NULL, NULL);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2012-12-05 17:29:46 +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);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****
|
|
|
|
*****
|
|
|
|
***** ENTRY FIELD
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
|
|
|
static gboolean
|
2012-12-05 17:29:46 +00:00
|
|
|
testText (const tr_torrent * tor, const char * key)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2010-08-06 06:54:42 +00:00
|
|
|
gboolean ret = FALSE;
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (!key || !*key)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2010-08-06 15:03:25 +00:00
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tr_file_index_t i;
|
2012-12-05 17:29:46 +00:00
|
|
|
const tr_info * inf = tr_torrentInfo (tor);
|
2010-08-06 15:03:25 +00:00
|
|
|
|
2011-09-14 17:22:54 +00:00
|
|
|
/* test the torrent name... */
|
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
char * pch = g_utf8_casefold (tr_torrentName (tor), -1);
|
|
|
|
ret = !key || strstr (pch, key) != NULL;
|
|
|
|
g_free (pch);
|
2011-09-14 17:22:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* test the files... */
|
2012-12-05 17:29:46 +00:00
|
|
|
for (i=0; i<inf->fileCount && !ret; ++i)
|
2010-08-06 15:03:25 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
char * pch = g_utf8_casefold (inf->files[i].name, -1);
|
|
|
|
ret = !key || strstr (pch, key) != NULL;
|
|
|
|
g_free (pch);
|
2010-08-06 15:03:25 +00:00
|
|
|
}
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-12-05 17:29:46 +00:00
|
|
|
entry_clear (GtkEntry * e)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
gtk_entry_set_text (e, "");
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-12-05 17:29:46 +00:00
|
|
|
filter_entry_changed (GtkEditable * e, gpointer filter_model)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
|
|
|
char * pch;
|
|
|
|
char * folded;
|
2010-03-17 17:07:40 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
pch = gtk_editable_get_chars (e, 0, -1);
|
|
|
|
folded = g_utf8_casefold (pch, -1);
|
|
|
|
g_strstrip (folded);
|
|
|
|
g_object_set_qdata_full (filter_model, TEXT_KEY, folded, g_free);
|
|
|
|
g_free (pch);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (filter_model));
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****
|
|
|
|
******
|
|
|
|
******
|
|
|
|
******
|
|
|
|
*****/
|
|
|
|
|
|
|
|
struct filter_data
|
|
|
|
{
|
2010-03-27 02:52:10 +00:00
|
|
|
GtkWidget * activity;
|
2010-03-14 05:13:02 +00:00
|
|
|
GtkWidget * category;
|
|
|
|
GtkWidget * entry;
|
|
|
|
GtkTreeModel * filter_model;
|
2011-04-13 22:04:31 +00:00
|
|
|
int active_activity_type;
|
|
|
|
int active_category_type;
|
|
|
|
char * active_category_host;
|
2010-03-14 05:13:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static gboolean
|
2012-12-05 17:29:46 +00:00
|
|
|
is_row_visible (GtkTreeModel * model, GtkTreeIter * iter, gpointer vdata)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
|
|
|
const char * text;
|
|
|
|
tr_torrent * tor;
|
|
|
|
struct filter_data * data = vdata;
|
2012-12-05 17:29:46 +00:00
|
|
|
GObject * o = G_OBJECT (data->filter_model);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
gtk_tree_model_get (model, iter, MC_TORRENT, &tor, -1);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
text = (const char*) g_object_get_qdata (o, TEXT_KEY);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
return (tor != NULL) && test_category (tor, data->active_category_type, data->active_category_host)
|
|
|
|
&& test_torrent_activity (tor, data->active_activity_type)
|
|
|
|
&& testText (tor, text);
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-12-05 17:29:46 +00:00
|
|
|
selection_changed_cb (GtkComboBox * combo, gpointer vdata)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2011-04-13 22:04:31 +00:00
|
|
|
int type;
|
|
|
|
char * host;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeModel * model;
|
2010-03-14 05:13:02 +00:00
|
|
|
struct filter_data * data = vdata;
|
2011-04-13 22:04:31 +00:00
|
|
|
|
|
|
|
/* set data->active_activity_type from the activity combobox */
|
2012-12-05 17:29:46 +00:00
|
|
|
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);
|
2011-04-13 22:04:31 +00:00
|
|
|
else
|
|
|
|
type = ACTIVITY_FILTER_ALL;
|
|
|
|
data->active_activity_type = type;
|
|
|
|
|
|
|
|
/* set the active category type & host from the category combobox */
|
2012-12-05 17:29:46 +00:00
|
|
|
combo = GTK_COMBO_BOX (data->category);
|
|
|
|
model = gtk_combo_box_get_model (combo);
|
|
|
|
if (gtk_combo_box_get_active_iter (combo, &iter)) {
|
|
|
|
gtk_tree_model_get (model, &iter, CAT_FILTER_COL_TYPE, &type,
|
2011-04-13 22:04:31 +00:00
|
|
|
CAT_FILTER_COL_HOST, &host,
|
2012-12-05 17:29:46 +00:00
|
|
|
-1);
|
2011-04-13 22:04:31 +00:00
|
|
|
} else {
|
|
|
|
type = CAT_FILTER_TYPE_ALL;
|
|
|
|
host = NULL;
|
|
|
|
}
|
2012-12-05 17:29:46 +00:00
|
|
|
g_free (data->active_category_host);
|
2011-04-13 22:04:31 +00:00
|
|
|
data->active_category_host = host;
|
|
|
|
data->active_category_type = type;
|
|
|
|
|
|
|
|
/* refilter */
|
2012-12-05 17:29:46 +00:00
|
|
|
gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (data->filter_model));
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
2012-12-05 17:29:46 +00:00
|
|
|
gtr_filter_bar_new (tr_session * session, GtkTreeModel * tmodel, GtkTreeModel ** filter_model)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
|
|
|
GtkWidget * l;
|
|
|
|
GtkWidget * w;
|
|
|
|
GtkWidget * h;
|
|
|
|
GtkWidget * s;
|
2010-03-27 02:52:10 +00:00
|
|
|
GtkWidget * activity;
|
2010-03-14 05:13:02 +00:00
|
|
|
GtkWidget * category;
|
2012-12-13 03:00:57 +00:00
|
|
|
GtkBox * h_box;
|
2010-03-14 05:13:02 +00:00
|
|
|
const char * str;
|
|
|
|
struct filter_data * data;
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
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");
|
2011-04-05 15:59:41 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
data = g_new0 (struct filter_data, 1);
|
|
|
|
data->activity = activity = activity_combo_box_new (tmodel);
|
|
|
|
data->category = category = category_combo_box_new (tmodel);
|
|
|
|
data->filter_model = gtk_tree_model_filter_new (tmodel, NULL);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
g_object_set (G_OBJECT (data->category), "width-request", 170, NULL);
|
|
|
|
g_object_set_qdata (G_OBJECT (gtk_combo_box_get_model (GTK_COMBO_BOX (data->category))), SESSION_KEY, session);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
gtk_tree_model_filter_set_visible_func (
|
|
|
|
GTK_TREE_MODEL_FILTER (data->filter_model),
|
|
|
|
is_row_visible, data, g_free);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
g_signal_connect (data->category, "changed", G_CALLBACK (selection_changed_cb), data);
|
|
|
|
g_signal_connect (data->activity, "changed", G_CALLBACK (selection_changed_cb), data);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
h = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, GUI_PAD_SMALL);
|
2012-12-13 03:00:57 +00:00
|
|
|
h_box = GTK_BOX (h);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2010-05-16 15:51:01 +00:00
|
|
|
/* add the activity combobox */
|
2012-12-05 17:29:46 +00:00
|
|
|
str = _("_Show:");
|
2010-05-16 15:51:01 +00:00
|
|
|
w = activity;
|
2012-12-05 17:29:46 +00:00
|
|
|
l = gtk_label_new (NULL);
|
|
|
|
gtk_label_set_markup_with_mnemonic (GTK_LABEL (l), str);
|
|
|
|
gtk_label_set_mnemonic_widget (GTK_LABEL (l), w);
|
2012-12-13 03:00:57 +00:00
|
|
|
gtk_box_pack_start (h_box, l, FALSE, FALSE, 0);
|
|
|
|
gtk_box_pack_start (h_box, w, TRUE, TRUE, 0);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
|
|
|
/* add a spacer */
|
2012-12-05 17:29:46 +00:00
|
|
|
w = gtk_alignment_new (0.0f, 0.0f, 0.0f, 0.0f);
|
|
|
|
gtk_widget_set_size_request (w, 0u, GUI_PAD_BIG);
|
2012-12-13 03:00:57 +00:00
|
|
|
gtk_box_pack_start (h_box, w, FALSE, FALSE, 0);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2010-05-16 15:51:01 +00:00
|
|
|
/* add the category combobox */
|
|
|
|
w = category;
|
2012-12-13 03:00:57 +00:00
|
|
|
gtk_box_pack_start (h_box, w, TRUE, TRUE, 0);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
|
|
|
/* add a spacer */
|
2012-12-05 17:29:46 +00:00
|
|
|
w = gtk_alignment_new (0.0f, 0.0f, 0.0f, 0.0f);
|
|
|
|
gtk_widget_set_size_request (w, 0u, GUI_PAD_BIG);
|
2012-12-13 03:00:57 +00:00
|
|
|
gtk_box_pack_start (h_box, w, FALSE, FALSE, 0);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
|
|
|
/* add the entry field */
|
2012-12-05 17:29:46 +00:00
|
|
|
s = gtk_entry_new ();
|
|
|
|
gtk_entry_set_icon_from_stock (GTK_ENTRY (s), GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CLEAR);
|
|
|
|
g_signal_connect (s, "icon-release", G_CALLBACK (entry_clear), NULL);
|
2012-12-13 03:00:57 +00:00
|
|
|
gtk_box_pack_start (h_box, s, TRUE, TRUE, 0);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
g_signal_connect (s, "changed", G_CALLBACK (filter_entry_changed), data->filter_model);
|
|
|
|
selection_changed_cb (NULL, data);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
|
|
|
*filter_model = data->filter_model;
|
|
|
|
return h;
|
|
|
|
}
|