2009-06-06 04:40:24 +00:00
|
|
|
/*
|
2011-01-19 13:48:47 +00:00
|
|
|
* This file Copyright (C) Mnemosyne LLC
|
2008-02-10 22:25:42 +00:00
|
|
|
*
|
2010-12-27 19:18:17 +00:00
|
|
|
* This file is licensed by the GPL version 2. Works owned by the
|
2009-06-06 04:40:24 +00:00
|
|
|
* Transmission project are granted a special exemption to clause 2(b)
|
|
|
|
* 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.
|
2008-02-10 22:25:42 +00:00
|
|
|
*
|
2009-06-06 04:40:24 +00:00
|
|
|
* $Id$
|
|
|
|
*/
|
2008-02-10 22:25:42 +00:00
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2008-08-21 14:57:59 +00:00
|
|
|
#include <string.h>
|
2008-02-10 22:25:42 +00:00
|
|
|
#include <glib/gi18n.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include <libtransmission/transmission.h>
|
2011-03-03 01:59:25 +00:00
|
|
|
#include <libtransmission/utils.h>
|
2008-02-10 22:25:42 +00:00
|
|
|
|
2008-02-12 18:53:31 +00:00
|
|
|
#include "file-list.h"
|
2008-02-10 22:25:42 +00:00
|
|
|
#include "hig.h"
|
2009-03-02 23:31:01 +00:00
|
|
|
#include "icons.h"
|
2010-02-01 04:54:10 +00:00
|
|
|
#include "tr-prefs.h"
|
2011-03-03 01:59:25 +00:00
|
|
|
#include "util.h"
|
2008-02-10 22:25:42 +00:00
|
|
|
|
2011-01-05 07:08:34 +00:00
|
|
|
#define TR_DOWNLOAD_KEY "tr-download-key"
|
|
|
|
#define TR_COLUMN_ID_KEY "tr-model-column-id-key"
|
|
|
|
#define TR_PRIORITY_KEY "tr-priority-key"
|
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
enum
|
|
|
|
{
|
2009-06-10 00:04:43 +00:00
|
|
|
/* these two fields could be any number at all so long as they're not
|
|
|
|
* TR_PRI_LOW, TR_PRI_NORMAL, TR_PRI_HIGH, TRUE, or FALSE */
|
|
|
|
NOT_SET = 1000,
|
|
|
|
MIXED = 1001
|
2008-05-29 02:59:22 +00:00
|
|
|
};
|
|
|
|
|
2008-02-10 22:25:42 +00:00
|
|
|
enum
|
|
|
|
{
|
2009-03-02 23:31:01 +00:00
|
|
|
FC_ICON,
|
2008-05-29 03:15:33 +00:00
|
|
|
FC_LABEL,
|
|
|
|
FC_PROG,
|
|
|
|
FC_INDEX,
|
|
|
|
FC_SIZE,
|
2011-01-06 17:21:55 +00:00
|
|
|
FC_SIZE_STR,
|
2008-05-29 03:15:33 +00:00
|
|
|
FC_HAVE,
|
|
|
|
FC_PRIORITY,
|
|
|
|
FC_ENABLED,
|
|
|
|
N_FILE_COLS
|
2008-02-10 22:25:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2009-06-06 14:09:43 +00:00
|
|
|
TrCore * core;
|
|
|
|
GtkWidget * top;
|
|
|
|
GtkWidget * view;
|
|
|
|
GtkTreeModel * model; /* same object as store, but recast */
|
|
|
|
GtkTreeStore * store; /* same object as model, but recast */
|
|
|
|
int torrentId;
|
2008-09-23 19:11:04 +00:00
|
|
|
guint timeout_tag;
|
2008-02-10 22:25:42 +00:00
|
|
|
}
|
|
|
|
FileData;
|
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
static void
|
|
|
|
clearData( FileData * data )
|
2008-02-10 22:25:42 +00:00
|
|
|
{
|
2009-04-24 01:37:04 +00:00
|
|
|
data->torrentId = -1;
|
2008-05-29 02:59:22 +00:00
|
|
|
|
2009-04-24 01:37:04 +00:00
|
|
|
if( data->timeout_tag ) {
|
2008-05-29 02:59:22 +00:00
|
|
|
g_source_remove( data->timeout_tag );
|
|
|
|
data->timeout_tag = 0;
|
2008-02-10 22:25:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
static void
|
2009-06-06 14:09:43 +00:00
|
|
|
freeData( gpointer data )
|
2008-02-10 22:25:42 +00:00
|
|
|
{
|
2008-05-29 02:59:22 +00:00
|
|
|
clearData( data );
|
|
|
|
g_free( data );
|
2008-02-10 22:25:42 +00:00
|
|
|
}
|
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2010-09-17 13:23:20 +00:00
|
|
|
struct RefreshData
|
|
|
|
{
|
|
|
|
int sort_column_id;
|
|
|
|
gboolean resort_needed;
|
|
|
|
|
|
|
|
tr_file_stat * refresh_file_stat;
|
|
|
|
tr_torrent * tor;
|
|
|
|
|
|
|
|
FileData * file_data;
|
|
|
|
};
|
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
static gboolean
|
2009-04-24 01:37:04 +00:00
|
|
|
refreshFilesForeach( GtkTreeModel * model,
|
|
|
|
GtkTreePath * path UNUSED,
|
|
|
|
GtkTreeIter * iter,
|
|
|
|
gpointer gdata )
|
2008-05-29 02:59:22 +00:00
|
|
|
{
|
2010-09-17 13:23:20 +00:00
|
|
|
struct RefreshData * refresh_data = gdata;
|
|
|
|
FileData * data = refresh_data->file_data;
|
2008-05-29 02:59:22 +00:00
|
|
|
unsigned int index;
|
2009-06-06 04:29:08 +00:00
|
|
|
uint64_t size;
|
|
|
|
uint64_t old_have;
|
|
|
|
int old_prog;
|
|
|
|
int old_priority;
|
2009-06-10 00:04:43 +00:00
|
|
|
int old_enabled;
|
2010-05-12 01:34:08 +00:00
|
|
|
const gboolean is_file = !gtk_tree_model_iter_has_child( model, iter );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2010-05-12 01:34:08 +00:00
|
|
|
gtk_tree_model_get( model, iter, FC_ENABLED, &old_enabled,
|
2009-06-06 04:29:08 +00:00
|
|
|
FC_PRIORITY, &old_priority,
|
2009-04-24 01:37:04 +00:00
|
|
|
FC_INDEX, &index,
|
2009-06-06 04:29:08 +00:00
|
|
|
FC_HAVE, &old_have,
|
|
|
|
FC_SIZE, &size,
|
|
|
|
FC_PROG, &old_prog,
|
2009-04-24 01:37:04 +00:00
|
|
|
-1 );
|
2009-06-06 14:09:43 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
if( is_file )
|
|
|
|
{
|
2010-09-17 13:23:20 +00:00
|
|
|
tr_torrent * tor = refresh_data->tor;
|
2010-02-11 14:45:03 +00:00
|
|
|
const tr_info * inf = tr_torrentInfo( tor );
|
|
|
|
const int enabled = !inf->files[index].dnd;
|
|
|
|
const int priority = inf->files[index].priority;
|
2010-09-17 13:23:20 +00:00
|
|
|
const uint64_t have = refresh_data->refresh_file_stat[index].bytesCompleted;
|
2010-01-31 18:02:02 +00:00
|
|
|
const int prog = size ? (int)((100.0*have)/size) : 1;
|
2009-06-06 04:29:08 +00:00
|
|
|
|
2009-06-10 00:04:43 +00:00
|
|
|
if( (priority!=old_priority) || (enabled!=old_enabled) || (have!=old_have) || (prog!=old_prog) )
|
2010-09-17 13:23:20 +00:00
|
|
|
{
|
|
|
|
/* Changing a value in the sort column can trigger a resort
|
2010-12-27 19:18:17 +00:00
|
|
|
* which breaks this foreach() call. (See #3529)
|
2010-09-17 13:23:20 +00:00
|
|
|
* As a workaround: if that's about to happen, temporarily disable
|
|
|
|
* sorting until we finish walking the tree. */
|
|
|
|
if( !refresh_data->resort_needed )
|
|
|
|
{
|
|
|
|
if(( refresh_data->resort_needed =
|
|
|
|
(( refresh_data->sort_column_id==FC_PRIORITY ) && ( priority!=old_priority )) ||
|
|
|
|
(( refresh_data->sort_column_id==FC_ENABLED ) && ( enabled!=old_enabled ))))
|
|
|
|
{
|
|
|
|
refresh_data->resort_needed = TRUE;
|
|
|
|
gtk_tree_sortable_set_sort_column_id( GTK_TREE_SORTABLE( data->model ),
|
|
|
|
GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID,
|
|
|
|
GTK_SORT_ASCENDING );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-06 04:29:08 +00:00
|
|
|
gtk_tree_store_set( data->store, iter, FC_PRIORITY, priority,
|
2009-06-10 00:04:43 +00:00
|
|
|
FC_ENABLED, enabled,
|
2009-06-06 04:29:08 +00:00
|
|
|
FC_HAVE, have,
|
2009-06-07 13:48:15 +00:00
|
|
|
FC_PROG, prog,
|
2009-06-06 04:29:08 +00:00
|
|
|
-1 );
|
2010-09-17 13:23:20 +00:00
|
|
|
}
|
2009-06-06 04:29:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkTreeIter child;
|
2009-06-10 00:04:43 +00:00
|
|
|
uint64_t sub_size = 0;
|
|
|
|
uint64_t have = 0;
|
2009-06-06 04:29:08 +00:00
|
|
|
int prog;
|
2009-06-10 00:04:43 +00:00
|
|
|
int enabled = NOT_SET;
|
|
|
|
int priority = NOT_SET;
|
2009-06-06 04:29:08 +00:00
|
|
|
|
|
|
|
/* since gtk_tree_model_foreach() is depth-first, we can
|
|
|
|
* get the `sub' info by walking the immediate children */
|
|
|
|
|
|
|
|
if( gtk_tree_model_iter_children( model, &child, iter ) ) do
|
|
|
|
{
|
2009-06-10 00:04:43 +00:00
|
|
|
int child_enabled;
|
|
|
|
int child_priority;
|
2009-06-06 04:29:08 +00:00
|
|
|
int64_t child_have, child_size;
|
2009-06-10 00:04:43 +00:00
|
|
|
|
|
|
|
gtk_tree_model_get( model, &child, FC_SIZE, &child_size,
|
|
|
|
FC_HAVE, &child_have,
|
|
|
|
FC_PRIORITY, &child_priority,
|
|
|
|
FC_ENABLED, &child_enabled,
|
2009-06-06 14:09:43 +00:00
|
|
|
-1 );
|
2009-06-10 00:04:43 +00:00
|
|
|
|
|
|
|
sub_size += child_size;
|
2009-06-06 04:29:08 +00:00
|
|
|
have += child_have;
|
2009-06-10 00:04:43 +00:00
|
|
|
|
|
|
|
if( enabled == NOT_SET )
|
|
|
|
enabled = child_enabled;
|
|
|
|
else if( enabled != child_enabled )
|
|
|
|
enabled = MIXED;
|
|
|
|
|
|
|
|
if( priority == NOT_SET )
|
|
|
|
priority = child_priority;
|
|
|
|
else if( priority != child_priority )
|
|
|
|
priority = MIXED;
|
2009-06-06 04:29:08 +00:00
|
|
|
}
|
|
|
|
while( gtk_tree_model_iter_next( model, &child ) );
|
|
|
|
|
2010-01-31 18:02:02 +00:00
|
|
|
prog = sub_size ? (int)((100.0*have)/sub_size) : 1;
|
2009-06-06 04:29:08 +00:00
|
|
|
|
2009-06-10 00:04:43 +00:00
|
|
|
if( (size!=sub_size) || (have!=old_have)
|
|
|
|
|| (priority!=old_priority)
|
|
|
|
|| (enabled!=old_enabled)
|
|
|
|
|| (prog!=old_prog) )
|
2011-01-06 17:21:55 +00:00
|
|
|
{
|
|
|
|
char size_str[64];
|
|
|
|
tr_strlsize( size_str, sub_size, sizeof size_str );
|
2009-06-10 00:04:43 +00:00
|
|
|
gtk_tree_store_set( data->store, iter, FC_SIZE, sub_size,
|
2011-01-06 17:21:55 +00:00
|
|
|
FC_SIZE_STR, size_str,
|
2009-06-10 00:04:43 +00:00
|
|
|
FC_HAVE, have,
|
|
|
|
FC_PRIORITY, priority,
|
|
|
|
FC_ENABLED, enabled,
|
2009-06-06 04:29:08 +00:00
|
|
|
FC_PROG, prog,
|
|
|
|
-1 );
|
2011-01-06 17:21:55 +00:00
|
|
|
}
|
2008-05-29 02:59:22 +00:00
|
|
|
}
|
2009-06-06 04:29:08 +00:00
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
return FALSE; /* keep walking */
|
2008-02-10 22:25:42 +00:00
|
|
|
}
|
|
|
|
|
2009-06-06 04:29:08 +00:00
|
|
|
static void
|
|
|
|
gtr_tree_model_foreach_postorder_subtree( GtkTreeModel * model,
|
|
|
|
GtkTreeIter * parent,
|
|
|
|
GtkTreeModelForeachFunc func,
|
|
|
|
gpointer data )
|
2008-02-10 22:25:42 +00:00
|
|
|
{
|
2009-06-06 04:29:08 +00:00
|
|
|
GtkTreeIter child;
|
|
|
|
if( gtk_tree_model_iter_children( model, &child, parent ) ) do
|
|
|
|
gtr_tree_model_foreach_postorder_subtree( model, &child, func, data );
|
|
|
|
while( gtk_tree_model_iter_next( model, &child ) );
|
|
|
|
if( parent )
|
|
|
|
func( model, NULL, parent, data );
|
2008-05-29 02:59:22 +00:00
|
|
|
}
|
2008-02-10 22:25:42 +00:00
|
|
|
|
2009-06-06 04:29:08 +00:00
|
|
|
static void
|
|
|
|
gtr_tree_model_foreach_postorder( GtkTreeModel * model,
|
|
|
|
GtkTreeModelForeachFunc func,
|
|
|
|
gpointer data )
|
2008-05-29 02:59:22 +00:00
|
|
|
{
|
2009-06-06 04:29:08 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
if( gtk_tree_model_get_iter_first( model, &iter ) ) do
|
|
|
|
gtr_tree_model_foreach_postorder_subtree( model, &iter, func, data );
|
|
|
|
while( gtk_tree_model_iter_next( model, &iter ) );
|
2008-05-29 02:59:22 +00:00
|
|
|
}
|
2008-02-10 22:25:42 +00:00
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
static void
|
|
|
|
refresh( FileData * data )
|
|
|
|
{
|
2011-03-03 01:59:25 +00:00
|
|
|
tr_torrent * tor = gtr_core_find_torrent( data->core, data->torrentId );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2009-04-24 01:37:04 +00:00
|
|
|
if( tor == NULL )
|
|
|
|
{
|
2010-12-22 06:25:30 +00:00
|
|
|
gtr_file_list_clear( data->top );
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-17 13:23:20 +00:00
|
|
|
GtkSortType order;
|
|
|
|
int sort_column_id;
|
2009-04-24 01:37:04 +00:00
|
|
|
tr_file_index_t fileCount;
|
2010-09-17 13:23:20 +00:00
|
|
|
struct RefreshData refresh_data;
|
|
|
|
GtkTreeSortable * sortable = GTK_TREE_SORTABLE( data->model );
|
|
|
|
gtk_tree_sortable_get_sort_column_id( sortable, &sort_column_id, &order );
|
|
|
|
|
|
|
|
refresh_data.sort_column_id = sort_column_id;
|
|
|
|
refresh_data.resort_needed = FALSE;
|
|
|
|
refresh_data.refresh_file_stat = tr_torrentFiles( tor, &fileCount );
|
2011-03-03 01:59:25 +00:00
|
|
|
refresh_data.tor = tor;
|
2010-09-17 13:23:20 +00:00
|
|
|
refresh_data.file_data = data;
|
|
|
|
|
|
|
|
gtr_tree_model_foreach_postorder( data->model, refreshFilesForeach, &refresh_data );
|
2008-02-10 22:25:42 +00:00
|
|
|
|
2010-09-17 13:23:20 +00:00
|
|
|
if( refresh_data.resort_needed )
|
|
|
|
gtk_tree_sortable_set_sort_column_id( sortable, sort_column_id, order );
|
2009-04-24 01:37:04 +00:00
|
|
|
|
2010-09-17 13:23:20 +00:00
|
|
|
tr_torrentFilesFree( refresh_data.refresh_file_stat, fileCount );
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
2008-02-10 22:25:42 +00:00
|
|
|
}
|
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
static gboolean
|
|
|
|
refreshModel( gpointer file_data )
|
2008-02-10 22:25:42 +00:00
|
|
|
{
|
2008-05-29 02:59:22 +00:00
|
|
|
refresh( file_data );
|
|
|
|
return TRUE;
|
2008-02-10 22:25:42 +00:00
|
|
|
}
|
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
struct ActiveData
|
2008-02-10 22:25:42 +00:00
|
|
|
{
|
2009-06-06 14:09:43 +00:00
|
|
|
GtkTreeSelection * sel;
|
|
|
|
GArray * array;
|
2008-05-29 02:59:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static gboolean
|
2009-06-06 14:09:43 +00:00
|
|
|
getSelectedFilesForeach( GtkTreeModel * model,
|
|
|
|
GtkTreePath * path UNUSED,
|
|
|
|
GtkTreeIter * iter,
|
|
|
|
gpointer gdata )
|
2008-05-29 02:59:22 +00:00
|
|
|
{
|
2010-05-12 01:34:08 +00:00
|
|
|
const gboolean is_file = !gtk_tree_model_iter_has_child( model, iter );
|
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
if( is_file )
|
|
|
|
{
|
2010-05-12 01:34:08 +00:00
|
|
|
struct ActiveData * data = gdata;
|
2010-12-12 16:43:19 +00:00
|
|
|
|
2010-05-12 01:34:08 +00:00
|
|
|
/* active means: if it's selected or any ancestor is selected */
|
|
|
|
|
|
|
|
gboolean is_active = gtk_tree_selection_iter_is_selected( data->sel, iter );
|
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
if( !is_active )
|
|
|
|
{
|
2008-05-29 02:59:22 +00:00
|
|
|
GtkTreeIter walk = *iter;
|
|
|
|
GtkTreeIter parent;
|
2009-06-06 14:09:43 +00:00
|
|
|
while( !is_active && gtk_tree_model_iter_parent( model, &parent, &walk ) )
|
2008-09-23 19:11:04 +00:00
|
|
|
{
|
2009-06-06 14:09:43 +00:00
|
|
|
is_active = gtk_tree_selection_iter_is_selected( data->sel, &parent );
|
2008-05-29 02:59:22 +00:00
|
|
|
walk = parent;
|
|
|
|
}
|
|
|
|
}
|
2008-02-10 22:25:42 +00:00
|
|
|
|
2010-05-12 01:34:08 +00:00
|
|
|
if( is_active )
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
gtk_tree_model_get( model, iter, FC_INDEX, &i, -1 );
|
|
|
|
g_array_append_val( data->array, i );
|
|
|
|
}
|
|
|
|
}
|
2008-05-29 02:59:22 +00:00
|
|
|
|
2008-05-29 03:15:33 +00:00
|
|
|
return FALSE; /* keep walking */
|
2008-02-10 22:25:42 +00:00
|
|
|
}
|
|
|
|
|
2011-01-05 07:08:34 +00:00
|
|
|
static GArray*
|
|
|
|
getSelectedFilesAndDescendants( GtkTreeView * view )
|
2008-02-10 22:25:42 +00:00
|
|
|
{
|
2008-05-29 02:59:22 +00:00
|
|
|
struct ActiveData data;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
data.sel = gtk_tree_view_get_selection( view );
|
2011-01-05 07:08:34 +00:00
|
|
|
data.array = g_array_new( FALSE, FALSE, sizeof( tr_file_index_t ) );
|
2008-10-26 22:58:57 +00:00
|
|
|
gtk_tree_model_foreach( gtk_tree_view_get_model( view ),
|
|
|
|
getSelectedFilesForeach, &data );
|
2011-01-05 07:08:34 +00:00
|
|
|
return data.array;
|
2008-10-26 22:58:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct SubtreeForeachData
|
|
|
|
{
|
2009-06-06 14:09:43 +00:00
|
|
|
GArray * array;
|
|
|
|
GtkTreePath * path;
|
2008-10-26 22:58:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
getSubtreeForeach( GtkTreeModel * model,
|
|
|
|
GtkTreePath * path,
|
|
|
|
GtkTreeIter * iter,
|
|
|
|
gpointer gdata )
|
|
|
|
{
|
2010-05-12 01:34:08 +00:00
|
|
|
const gboolean is_file = !gtk_tree_model_iter_has_child( model, iter );
|
2008-10-26 22:58:57 +00:00
|
|
|
|
|
|
|
if( is_file )
|
2010-05-12 01:34:08 +00:00
|
|
|
{
|
|
|
|
struct SubtreeForeachData * data = gdata;
|
|
|
|
|
2008-10-26 22:58:57 +00:00
|
|
|
if( !gtk_tree_path_compare( path, data->path ) || gtk_tree_path_is_descendant( path, data->path ) )
|
2010-05-12 01:34:08 +00:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
gtk_tree_model_get( model, iter, FC_INDEX, &i, -1 );
|
2008-10-26 22:58:57 +00:00
|
|
|
g_array_append_val( data->array, i );
|
2010-05-12 01:34:08 +00:00
|
|
|
}
|
|
|
|
}
|
2008-10-26 22:58:57 +00:00
|
|
|
|
|
|
|
return FALSE; /* keep walking */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
getSubtree( GtkTreeView * view, GtkTreePath * path, GArray * indices )
|
|
|
|
{
|
|
|
|
struct SubtreeForeachData tmp;
|
|
|
|
tmp.array = indices;
|
|
|
|
tmp.path = path;
|
|
|
|
gtk_tree_model_foreach( gtk_tree_view_get_model( view ), getSubtreeForeach, &tmp );
|
2008-02-10 22:25:42 +00:00
|
|
|
}
|
2008-09-05 21:01:00 +00:00
|
|
|
|
2008-09-06 01:52:47 +00:00
|
|
|
/* if `path' is a selected row, all selected rows are returned.
|
|
|
|
* otherwise, only the row indicated by `path' is returned.
|
|
|
|
* this is for toggling all the selected rows' states in a batch.
|
|
|
|
*/
|
|
|
|
static GArray*
|
2009-06-06 14:09:43 +00:00
|
|
|
getActiveFilesForPath( GtkTreeView * view, GtkTreePath * path )
|
2008-02-15 18:20:56 +00:00
|
|
|
{
|
2011-01-05 07:08:34 +00:00
|
|
|
GArray * indices;
|
2008-09-05 21:01:00 +00:00
|
|
|
GtkTreeSelection * sel = gtk_tree_view_get_selection( view );
|
|
|
|
|
|
|
|
if( gtk_tree_selection_path_is_selected( sel, path ) )
|
|
|
|
{
|
|
|
|
/* clicked in a selected row... use the current selection */
|
2011-01-05 07:08:34 +00:00
|
|
|
indices = getSelectedFilesAndDescendants( view );
|
2008-09-05 21:01:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* clicked OUTSIDE of the selected row... just use the clicked row */
|
2011-01-05 07:08:34 +00:00
|
|
|
indices = g_array_new( FALSE, FALSE, sizeof( tr_file_index_t ) );
|
2008-10-26 22:58:57 +00:00
|
|
|
getSubtree( view, path, indices );
|
2008-09-05 21:01:00 +00:00
|
|
|
}
|
|
|
|
|
2008-09-06 01:52:47 +00:00
|
|
|
return indices;
|
2008-02-15 18:20:56 +00:00
|
|
|
}
|
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2008-02-12 18:53:31 +00:00
|
|
|
void
|
2010-12-22 06:25:30 +00:00
|
|
|
gtr_file_list_clear( GtkWidget * w )
|
2008-02-10 22:25:42 +00:00
|
|
|
{
|
2010-12-22 06:25:30 +00:00
|
|
|
gtr_file_list_set_torrent( w, -1 );
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
2008-02-12 18:53:31 +00:00
|
|
|
|
2009-06-06 04:29:08 +00:00
|
|
|
struct build_data
|
|
|
|
{
|
2009-06-06 14:09:43 +00:00
|
|
|
GtkWidget * w;
|
|
|
|
tr_torrent * tor;
|
|
|
|
GtkTreeIter * iter;
|
2009-06-06 04:29:08 +00:00
|
|
|
GtkTreeStore * store;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct row_struct
|
|
|
|
{
|
2009-06-06 14:09:43 +00:00
|
|
|
uint64_t length;
|
|
|
|
char * name;
|
|
|
|
int index;
|
2009-06-06 04:29:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
buildTree( GNode * node, gpointer gdata )
|
|
|
|
{
|
2011-01-06 17:21:55 +00:00
|
|
|
char size_str[64];
|
2009-06-06 04:29:08 +00:00
|
|
|
GtkTreeIter child_iter;
|
|
|
|
struct build_data * build = gdata;
|
|
|
|
struct row_struct *child_data = node->data;
|
|
|
|
const gboolean isLeaf = node->children == NULL;
|
|
|
|
|
2010-12-21 19:20:58 +00:00
|
|
|
const char * mime_type = isLeaf ? gtr_get_mime_type_from_filename( child_data->name ) : DIRECTORY_MIME_TYPE;
|
|
|
|
GdkPixbuf * icon = gtr_get_mime_type_icon( mime_type, GTK_ICON_SIZE_MENU, build->w );
|
2010-02-11 14:55:00 +00:00
|
|
|
const tr_info * inf = tr_torrentInfo( build->tor );
|
|
|
|
const int priority = isLeaf ? inf->files[ child_data->index ].priority : 0;
|
|
|
|
const gboolean enabled = isLeaf ? !inf->files[ child_data->index ].dnd : TRUE;
|
2011-01-06 17:21:55 +00:00
|
|
|
|
|
|
|
tr_strlsize( size_str, child_data->length, sizeof size_str );
|
|
|
|
|
2009-06-06 04:29:08 +00:00
|
|
|
#if GTK_CHECK_VERSION(2,10,0)
|
|
|
|
gtk_tree_store_insert_with_values( build->store, &child_iter, build->iter, INT_MAX,
|
|
|
|
FC_INDEX, child_data->index,
|
|
|
|
FC_LABEL, child_data->name,
|
|
|
|
FC_SIZE, child_data->length,
|
2011-01-06 17:21:55 +00:00
|
|
|
FC_SIZE_STR, size_str,
|
2009-06-06 04:29:08 +00:00
|
|
|
FC_ICON, icon,
|
|
|
|
FC_PRIORITY, priority,
|
|
|
|
FC_ENABLED, enabled,
|
|
|
|
-1 );
|
|
|
|
#else
|
|
|
|
gtk_tree_store_append( build->store, &child_iter, build->iter );
|
|
|
|
gtk_tree_store_set( build->store, &child_iter,
|
|
|
|
FC_INDEX, child_data->index,
|
|
|
|
FC_LABEL, child_data->name,
|
|
|
|
FC_SIZE, child_data->length,
|
2011-01-06 17:21:55 +00:00
|
|
|
FC_SIZE_STR, size_str,
|
2009-06-06 04:29:08 +00:00
|
|
|
FC_ICON, icon,
|
|
|
|
FC_PRIORITY, priority,
|
|
|
|
FC_ENABLED, enabled,
|
|
|
|
-1 );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if( !isLeaf )
|
|
|
|
{
|
|
|
|
struct build_data b = *build;
|
|
|
|
b.iter = &child_iter;
|
|
|
|
g_node_children_foreach( node, G_TRAVERSE_ALL, buildTree, &b );
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref( icon );
|
2009-08-10 20:04:08 +00:00
|
|
|
|
2009-06-06 04:29:08 +00:00
|
|
|
/* we're done with this node */
|
|
|
|
g_free( child_data->name );
|
|
|
|
g_free( child_data );
|
|
|
|
}
|
|
|
|
|
|
|
|
static GNode*
|
|
|
|
find_child( GNode* parent, const char * name )
|
|
|
|
{
|
|
|
|
GNode * child = parent->children;
|
|
|
|
while( child ) {
|
|
|
|
const struct row_struct * child_data = child->data;
|
|
|
|
if( ( *child_data->name == *name ) && !strcmp( child_data->name, name ) )
|
|
|
|
break;
|
|
|
|
child = child->next;
|
|
|
|
}
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
|
2009-04-24 01:37:04 +00:00
|
|
|
void
|
2010-12-22 06:25:30 +00:00
|
|
|
gtr_file_list_set_torrent( GtkWidget * w, int torrentId )
|
2009-04-24 01:37:04 +00:00
|
|
|
{
|
|
|
|
GtkTreeStore * store;
|
|
|
|
FileData * data = g_object_get_data( G_OBJECT( w ), "file-data" );
|
2008-02-10 22:25:42 +00:00
|
|
|
|
2008-02-15 18:20:56 +00:00
|
|
|
/* unset the old fields */
|
|
|
|
clearData( data );
|
|
|
|
|
2008-02-12 18:53:31 +00:00
|
|
|
/* instantiate the model */
|
2008-02-10 22:25:42 +00:00
|
|
|
store = gtk_tree_store_new ( N_FILE_COLS,
|
2009-04-10 19:16:12 +00:00
|
|
|
GDK_TYPE_PIXBUF, /* icon */
|
2008-02-10 22:25:42 +00:00
|
|
|
G_TYPE_STRING, /* label */
|
|
|
|
G_TYPE_INT, /* prog [0..100] */
|
2008-05-29 02:59:22 +00:00
|
|
|
G_TYPE_UINT, /* index */
|
2008-02-10 22:25:42 +00:00
|
|
|
G_TYPE_UINT64, /* size */
|
2011-01-06 17:21:55 +00:00
|
|
|
G_TYPE_STRING, /* size str */
|
2008-05-29 02:59:22 +00:00
|
|
|
G_TYPE_UINT64, /* have */
|
|
|
|
G_TYPE_INT, /* priority */
|
2010-05-12 01:34:08 +00:00
|
|
|
G_TYPE_INT ); /* dl enabled */
|
2009-04-24 01:37:04 +00:00
|
|
|
|
2008-02-12 18:53:31 +00:00
|
|
|
data->store = store;
|
|
|
|
data->model = GTK_TREE_MODEL( store );
|
2009-04-24 01:37:04 +00:00
|
|
|
data->torrentId = torrentId;
|
2008-02-12 18:53:31 +00:00
|
|
|
|
|
|
|
/* populate the model */
|
2009-04-24 01:37:04 +00:00
|
|
|
if( torrentId > 0 )
|
2008-02-10 22:25:42 +00:00
|
|
|
{
|
2011-03-03 01:59:25 +00:00
|
|
|
tr_torrent * tor = gtr_core_find_torrent( data->core, torrentId );
|
2009-04-24 01:37:04 +00:00
|
|
|
if( tor != NULL )
|
2008-02-12 18:53:31 +00:00
|
|
|
{
|
2009-04-24 01:37:04 +00:00
|
|
|
tr_file_index_t i;
|
|
|
|
const tr_info * inf = tr_torrentInfo( tor );
|
2009-06-06 04:29:08 +00:00
|
|
|
struct row_struct * root_data;
|
|
|
|
GNode * root;
|
|
|
|
struct build_data build;
|
|
|
|
|
|
|
|
/* build a GNode tree of the files */
|
|
|
|
root_data = g_new0( struct row_struct, 1 );
|
2011-02-15 15:18:51 +00:00
|
|
|
root_data->name = g_strdup( tr_torrentName( tor ) );
|
2009-06-06 04:29:08 +00:00
|
|
|
root_data->index = -1;
|
|
|
|
root_data->length = 0;
|
|
|
|
root = g_node_new( root_data );
|
|
|
|
for( i=0; i<inf->fileCount; ++i ) {
|
|
|
|
int j;
|
|
|
|
GNode * parent = root;
|
|
|
|
const tr_file * file = &inf->files[i];
|
|
|
|
char ** tokens = g_strsplit( file->name, G_DIR_SEPARATOR_S, 0 );
|
|
|
|
for( j=0; tokens[j]; ++j ) {
|
|
|
|
const gboolean isLeaf = tokens[j+1] == NULL;
|
|
|
|
const char * name = tokens[j];
|
|
|
|
GNode * node = find_child( parent, name );
|
|
|
|
if( node == NULL ) {
|
|
|
|
struct row_struct * row = g_new( struct row_struct, 1 );
|
|
|
|
row->name = g_strdup( name );
|
|
|
|
row->index = isLeaf ? (int)i : -1;
|
|
|
|
row->length = isLeaf ? file->length : 0;
|
|
|
|
node = g_node_new( row );
|
|
|
|
g_node_append( parent, node );
|
|
|
|
}
|
|
|
|
parent = node;
|
|
|
|
}
|
|
|
|
g_strfreev( tokens );
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
2009-06-06 04:29:08 +00:00
|
|
|
|
|
|
|
/* now, add them to the model */
|
|
|
|
build.w = w;
|
|
|
|
build.tor = tor;
|
|
|
|
build.store = data->store;
|
|
|
|
build.iter = NULL;
|
|
|
|
g_node_children_foreach( root, G_TRAVERSE_ALL, buildTree, &build );
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
g_node_destroy( root );
|
2009-06-11 02:16:42 +00:00
|
|
|
g_free( root_data->name );
|
2009-06-06 04:29:08 +00:00
|
|
|
g_free( root_data );
|
2008-02-12 18:53:31 +00:00
|
|
|
}
|
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
refresh( data );
|
2010-02-01 04:54:10 +00:00
|
|
|
data->timeout_tag = gtr_timeout_add_seconds( SECONDARY_WINDOW_REFRESH_INTERVAL_SECONDS, refreshModel, data );
|
2008-02-10 22:25:42 +00:00
|
|
|
}
|
2008-02-12 18:53:31 +00:00
|
|
|
|
2009-06-06 14:09:43 +00:00
|
|
|
gtk_tree_view_set_model( GTK_TREE_VIEW( data->view ), data->model );
|
2008-02-12 18:53:31 +00:00
|
|
|
gtk_tree_view_expand_all( GTK_TREE_VIEW( data->view ) );
|
|
|
|
}
|
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
static void
|
|
|
|
renderDownload( GtkTreeViewColumn * column UNUSED,
|
2009-06-06 04:29:08 +00:00
|
|
|
GtkCellRenderer * renderer,
|
|
|
|
GtkTreeModel * model,
|
|
|
|
GtkTreeIter * iter,
|
2008-09-23 19:11:04 +00:00
|
|
|
gpointer data UNUSED )
|
2008-05-29 02:59:22 +00:00
|
|
|
{
|
|
|
|
gboolean enabled;
|
2009-06-10 00:04:43 +00:00
|
|
|
gtk_tree_model_get( model, iter, FC_ENABLED, &enabled, -1 );
|
|
|
|
g_object_set( renderer, "inconsistent", (enabled==MIXED),
|
|
|
|
"active", (enabled==TRUE),
|
2009-06-06 14:09:43 +00:00
|
|
|
NULL );
|
2008-05-29 02:59:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
renderPriority( GtkTreeViewColumn * column UNUSED,
|
2009-06-06 04:29:08 +00:00
|
|
|
GtkCellRenderer * renderer,
|
|
|
|
GtkTreeModel * model,
|
|
|
|
GtkTreeIter * iter,
|
2008-09-23 19:11:04 +00:00
|
|
|
gpointer data UNUSED )
|
2008-05-29 02:59:22 +00:00
|
|
|
{
|
2009-06-10 00:04:43 +00:00
|
|
|
int priority;
|
|
|
|
const char * text;
|
|
|
|
gtk_tree_model_get( model, iter, FC_PRIORITY, &priority, -1 );
|
2009-06-06 04:29:08 +00:00
|
|
|
switch( priority ) {
|
2009-06-10 00:04:43 +00:00
|
|
|
case TR_PRI_HIGH: text = _( "High" ); break;
|
2009-06-06 04:29:08 +00:00
|
|
|
case TR_PRI_NORMAL: text = _( "Normal" ); break;
|
2009-06-10 00:04:43 +00:00
|
|
|
case TR_PRI_LOW: text = _( "Low" ); break;
|
|
|
|
default: text = _( "Mixed" ); break;
|
2008-05-29 02:59:22 +00:00
|
|
|
}
|
2009-06-10 00:04:43 +00:00
|
|
|
g_object_set( renderer, "text", text, NULL );
|
2008-02-15 18:20:56 +00:00
|
|
|
}
|
|
|
|
|
2010-07-11 17:56:58 +00:00
|
|
|
/* build a filename from tr_torrentGetCurrentDir() + the model's FC_LABELs */
|
|
|
|
static char*
|
|
|
|
buildFilename( tr_torrent * tor, GtkTreeModel * model,
|
|
|
|
GtkTreePath * path, GtkTreeIter * iter )
|
|
|
|
{
|
|
|
|
char * ret;
|
|
|
|
GtkTreeIter child;
|
|
|
|
GtkTreeIter parent = *iter;
|
|
|
|
int n = gtk_tree_path_get_depth( path );
|
|
|
|
char ** tokens = g_new0( char*, n + 2 );
|
|
|
|
tokens[0] = g_strdup( tr_torrentGetCurrentDir( tor ) );
|
|
|
|
do {
|
|
|
|
child = parent;
|
|
|
|
gtk_tree_model_get( model, &child, FC_LABEL, &tokens[n--], -1 );
|
|
|
|
} while( gtk_tree_model_iter_parent( model, &parent, &child ) );
|
|
|
|
ret = g_build_filenamev( tokens );
|
|
|
|
g_strfreev( tokens );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
onRowActivated( GtkTreeView * view, GtkTreePath * path,
|
|
|
|
GtkTreeViewColumn * col UNUSED, gpointer gdata )
|
|
|
|
{
|
|
|
|
gboolean handled = FALSE;
|
|
|
|
FileData * data = gdata;
|
2011-03-03 01:59:25 +00:00
|
|
|
tr_torrent * tor = gtr_core_find_torrent( data->core, data->torrentId );
|
2010-07-11 17:56:58 +00:00
|
|
|
|
|
|
|
if( tor != NULL )
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeModel * model = gtk_tree_view_get_model( view );
|
|
|
|
|
|
|
|
if( gtk_tree_model_get_iter( model, &iter, path ) )
|
|
|
|
{
|
|
|
|
int prog;
|
|
|
|
char * filename = buildFilename( tor, model, path, &iter );
|
|
|
|
gtk_tree_model_get( model, &iter, FC_PROG, &prog, -1 );
|
|
|
|
|
|
|
|
/* if the file's not done, walk up the directory tree until we find
|
|
|
|
* an ancestor that exists, and open that instead */
|
|
|
|
if( filename && ( prog<100 || !g_file_test( filename, G_FILE_TEST_EXISTS ) ) ) do
|
|
|
|
{
|
|
|
|
char * tmp = g_path_get_dirname( filename );
|
|
|
|
g_free( filename );
|
|
|
|
filename = tmp;
|
|
|
|
}
|
|
|
|
while( filename && *filename && !g_file_test( filename, G_FILE_TEST_EXISTS ) );
|
|
|
|
|
|
|
|
if(( handled = filename && *filename ))
|
|
|
|
gtr_open_file( filename );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return handled;
|
|
|
|
}
|
|
|
|
|
2011-01-05 07:08:34 +00:00
|
|
|
static gboolean
|
|
|
|
onViewPathToggled( GtkTreeView * view,
|
|
|
|
GtkTreeViewColumn * col,
|
|
|
|
GtkTreePath * path,
|
|
|
|
FileData * data )
|
|
|
|
{
|
|
|
|
int cid;
|
|
|
|
tr_torrent * tor;
|
|
|
|
gboolean handled = FALSE;
|
2008-09-06 01:52:47 +00:00
|
|
|
|
2011-01-05 07:08:34 +00:00
|
|
|
if( !col || !path )
|
|
|
|
return FALSE;
|
2008-09-06 01:52:47 +00:00
|
|
|
|
2011-01-05 07:08:34 +00:00
|
|
|
cid = GPOINTER_TO_INT( g_object_get_data( G_OBJECT( col ), TR_COLUMN_ID_KEY ) );
|
2011-03-03 01:59:25 +00:00
|
|
|
tor = gtr_core_find_torrent( data->core, data->torrentId );
|
2011-01-05 07:08:34 +00:00
|
|
|
if( ( tor != NULL ) && ( ( cid == FC_PRIORITY ) || ( cid == FC_ENABLED ) ) )
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GArray * indices = getActiveFilesForPath( view, path );
|
|
|
|
GtkTreeModel * model = data->model;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2011-01-05 07:08:34 +00:00
|
|
|
gtk_tree_model_get_iter( model, &iter, path );
|
2008-09-06 01:52:47 +00:00
|
|
|
|
2011-01-05 07:08:34 +00:00
|
|
|
if( cid == FC_PRIORITY )
|
|
|
|
{
|
|
|
|
int priority;
|
|
|
|
gtk_tree_model_get( model, &iter, FC_PRIORITY, &priority, -1 );
|
|
|
|
switch( priority ) {
|
|
|
|
case TR_PRI_NORMAL: priority = TR_PRI_HIGH; break;
|
|
|
|
case TR_PRI_HIGH: priority = TR_PRI_LOW; break;
|
|
|
|
default: priority = TR_PRI_NORMAL; break;
|
|
|
|
}
|
|
|
|
tr_torrentSetFilePriorities( tor,
|
|
|
|
(tr_file_index_t *) indices->data,
|
|
|
|
(tr_file_index_t) indices->len,
|
|
|
|
priority );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int enabled;
|
|
|
|
gtk_tree_model_get( model, &iter, FC_ENABLED, &enabled, -1 );
|
|
|
|
enabled = !enabled;
|
|
|
|
|
|
|
|
tr_torrentSetFileDLs( tor,
|
|
|
|
(tr_file_index_t *) indices->data,
|
|
|
|
(tr_file_index_t) indices->len,
|
|
|
|
enabled );
|
|
|
|
}
|
|
|
|
|
|
|
|
refresh( data );
|
|
|
|
g_array_free( indices, TRUE );
|
|
|
|
handled = TRUE;
|
|
|
|
}
|
2008-09-06 01:52:47 +00:00
|
|
|
|
2011-01-05 07:08:34 +00:00
|
|
|
return handled;
|
|
|
|
}
|
2008-09-06 01:52:47 +00:00
|
|
|
|
2011-01-05 07:08:34 +00:00
|
|
|
/**
|
|
|
|
* @note 'col' and 'path' are assumed not to be NULL.
|
|
|
|
*/
|
|
|
|
static gboolean
|
|
|
|
getAndSelectEventPath( GtkTreeView * treeview,
|
|
|
|
GdkEventButton * event,
|
|
|
|
GtkTreeViewColumn ** col,
|
|
|
|
GtkTreePath ** path )
|
|
|
|
{
|
|
|
|
GtkTreeSelection * sel;
|
2008-09-06 01:52:47 +00:00
|
|
|
|
2011-01-05 07:08:34 +00:00
|
|
|
if( gtk_tree_view_get_path_at_pos( treeview,
|
|
|
|
event->x, event->y,
|
|
|
|
path, col, NULL, NULL ) )
|
|
|
|
{
|
|
|
|
sel = gtk_tree_view_get_selection( treeview );
|
|
|
|
if( !gtk_tree_selection_path_is_selected( sel, *path ) )
|
|
|
|
{
|
|
|
|
gtk_tree_selection_unselect_all( sel );
|
|
|
|
gtk_tree_selection_select_path( sel, *path );
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
2008-09-08 15:17:18 +00:00
|
|
|
|
2011-01-05 07:08:34 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2008-09-06 01:52:47 +00:00
|
|
|
|
2011-01-05 07:08:34 +00:00
|
|
|
static gboolean
|
|
|
|
onViewButtonPressed( GtkWidget * w, GdkEventButton * event, gpointer gdata )
|
|
|
|
{
|
2011-03-03 01:59:25 +00:00
|
|
|
tr_torrent * tor;
|
|
|
|
gboolean handled = FALSE;
|
|
|
|
FileData * data = gdata;
|
2008-09-06 01:52:47 +00:00
|
|
|
|
2011-03-03 01:59:25 +00:00
|
|
|
if(( tor = gtr_core_find_torrent( data->core, data->torrentId )))
|
2011-01-05 07:08:34 +00:00
|
|
|
{
|
2011-03-03 01:59:25 +00:00
|
|
|
GtkTreePath * path;
|
|
|
|
GtkTreeViewColumn * col;
|
|
|
|
GtkTreeView * treeview = GTK_TREE_VIEW( w );
|
|
|
|
|
|
|
|
if( event->type == GDK_BUTTON_PRESS && event->button == 1
|
|
|
|
&& !( event->state & ( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) )
|
|
|
|
&& getAndSelectEventPath( treeview, event, &col, &path ) )
|
|
|
|
handled = onViewPathToggled( treeview, col, path, data );
|
|
|
|
|
|
|
|
gtk_tree_path_free( path );
|
2011-01-05 07:08:34 +00:00
|
|
|
}
|
2008-09-05 21:01:00 +00:00
|
|
|
|
|
|
|
return handled;
|
|
|
|
}
|
|
|
|
|
2008-02-12 18:53:31 +00:00
|
|
|
GtkWidget *
|
2010-12-22 06:25:30 +00:00
|
|
|
gtr_file_list_new( TrCore * core, int torrentId )
|
2008-02-12 18:53:31 +00:00
|
|
|
{
|
2011-01-06 17:21:55 +00:00
|
|
|
int size;
|
2009-06-06 04:29:08 +00:00
|
|
|
int width;
|
2009-06-06 14:09:43 +00:00
|
|
|
GtkWidget * ret;
|
|
|
|
GtkWidget * view;
|
|
|
|
GtkWidget * scroll;
|
|
|
|
GtkCellRenderer * rend;
|
|
|
|
GtkTreeSelection * sel;
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkTreeViewColumn * col;
|
2009-06-06 14:09:43 +00:00
|
|
|
GtkTreeView * tree_view;
|
|
|
|
const char * title;
|
|
|
|
PangoLayout * pango_layout;
|
2011-01-06 17:21:55 +00:00
|
|
|
PangoContext * pango_context;
|
|
|
|
PangoFontDescription * pango_font_description;
|
2009-06-06 14:09:43 +00:00
|
|
|
FileData * data = g_new0( FileData, 1 );
|
2008-02-10 22:25:42 +00:00
|
|
|
|
2009-04-24 01:37:04 +00:00
|
|
|
data->core = core;
|
|
|
|
|
2008-02-10 22:25:42 +00:00
|
|
|
/* create the view */
|
2008-02-12 18:53:31 +00:00
|
|
|
view = gtk_tree_view_new( );
|
2009-06-06 14:09:43 +00:00
|
|
|
tree_view = GTK_TREE_VIEW( view );
|
|
|
|
gtk_tree_view_set_rules_hint( tree_view, TRUE );
|
2008-02-10 22:25:42 +00:00
|
|
|
gtk_container_set_border_width( GTK_CONTAINER( view ), GUI_PAD_BIG );
|
2008-09-23 19:11:04 +00:00
|
|
|
g_signal_connect( view, "button-press-event",
|
|
|
|
G_CALLBACK( onViewButtonPressed ), data );
|
2010-07-11 17:56:58 +00:00
|
|
|
g_signal_connect( view, "row_activated",
|
|
|
|
G_CALLBACK( onRowActivated ), data );
|
2008-09-27 18:01:31 +00:00
|
|
|
g_signal_connect( view, "button-release-event",
|
|
|
|
G_CALLBACK( on_tree_view_button_released ), NULL );
|
|
|
|
|
2008-02-10 22:25:42 +00:00
|
|
|
|
2011-01-06 17:21:55 +00:00
|
|
|
pango_context = gtk_widget_create_pango_context( view );
|
|
|
|
pango_font_description = pango_font_description_copy( pango_context_get_font_description( pango_context ) );
|
|
|
|
size = pango_font_description_get_size( pango_font_description );
|
|
|
|
pango_font_description_set_size( pango_font_description, size * 0.8 );
|
|
|
|
g_object_unref( G_OBJECT( pango_context ) );
|
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
/* set up view */
|
2009-06-06 14:09:43 +00:00
|
|
|
sel = gtk_tree_view_get_selection( tree_view );
|
2008-05-29 02:59:22 +00:00
|
|
|
gtk_tree_selection_set_mode( sel, GTK_SELECTION_MULTIPLE );
|
2009-06-06 14:09:43 +00:00
|
|
|
gtk_tree_view_expand_all( tree_view );
|
|
|
|
gtk_tree_view_set_search_column( tree_view, FC_LABEL );
|
2008-05-29 02:59:22 +00:00
|
|
|
|
2008-02-10 22:25:42 +00:00
|
|
|
/* add file column */
|
2008-09-23 19:11:04 +00:00
|
|
|
col = GTK_TREE_VIEW_COLUMN ( g_object_new ( GTK_TYPE_TREE_VIEW_COLUMN,
|
|
|
|
"expand", TRUE,
|
2011-01-06 17:21:55 +00:00
|
|
|
"title", _( "Name" ),
|
2008-09-23 19:11:04 +00:00
|
|
|
NULL ) );
|
2009-08-15 21:14:44 +00:00
|
|
|
gtk_tree_view_column_set_resizable( col, TRUE );
|
2008-09-23 19:11:04 +00:00
|
|
|
rend = gtk_cell_renderer_pixbuf_new( );
|
2008-02-10 22:25:42 +00:00
|
|
|
gtk_tree_view_column_pack_start( col, rend, FALSE );
|
2009-03-02 23:31:01 +00:00
|
|
|
gtk_tree_view_column_add_attribute( col, rend, "pixbuf", FC_ICON );
|
2008-02-10 22:25:42 +00:00
|
|
|
/* add text renderer */
|
2008-09-23 19:11:04 +00:00
|
|
|
rend = gtk_cell_renderer_text_new( );
|
2011-01-06 17:21:55 +00:00
|
|
|
g_object_set( rend, "ellipsize", PANGO_ELLIPSIZE_END, "font-desc", pango_font_description, NULL );
|
2008-02-10 22:25:42 +00:00
|
|
|
gtk_tree_view_column_pack_start( col, rend, TRUE );
|
2011-01-06 17:21:55 +00:00
|
|
|
gtk_tree_view_column_set_attributes( col, rend, "text", FC_LABEL, NULL );
|
2009-06-10 00:04:43 +00:00
|
|
|
gtk_tree_view_column_set_sort_column_id( col, FC_LABEL );
|
2009-06-06 14:09:43 +00:00
|
|
|
gtk_tree_view_append_column( tree_view, col );
|
2008-05-29 02:59:22 +00:00
|
|
|
|
2011-01-06 17:21:55 +00:00
|
|
|
/* add "size" column */
|
|
|
|
title = _( "Size" );
|
|
|
|
rend = gtk_cell_renderer_text_new( );
|
|
|
|
g_object_set( rend, "alignment", PANGO_ALIGN_RIGHT,
|
|
|
|
"font-desc", pango_font_description,
|
|
|
|
"xpad", GUI_PAD,
|
|
|
|
"xalign", 1.0f,
|
|
|
|
"yalign", 0.5f,
|
|
|
|
NULL );
|
|
|
|
col = gtk_tree_view_column_new_with_attributes( title, rend, NULL );
|
|
|
|
gtk_tree_view_column_set_sizing( col, GTK_TREE_VIEW_COLUMN_GROW_ONLY );
|
|
|
|
gtk_tree_view_column_set_sort_column_id( col, FC_SIZE );
|
|
|
|
gtk_tree_view_column_set_attributes( col, rend, "text", FC_SIZE_STR, NULL );
|
|
|
|
gtk_tree_view_append_column( tree_view, col );
|
|
|
|
|
2009-06-06 04:29:08 +00:00
|
|
|
/* add "progress" column */
|
2011-01-06 17:21:55 +00:00
|
|
|
title = _( "Have" );
|
2009-06-06 04:29:08 +00:00
|
|
|
pango_layout = gtk_widget_create_pango_layout( view, title );
|
|
|
|
pango_layout_get_pixel_size( pango_layout, &width, NULL );
|
2009-06-23 00:24:37 +00:00
|
|
|
width += 30; /* room for the sort indicator */
|
2009-06-06 04:29:08 +00:00
|
|
|
g_object_unref( G_OBJECT( pango_layout ) );
|
2008-05-29 02:59:22 +00:00
|
|
|
rend = gtk_cell_renderer_progress_new( );
|
2009-06-06 04:29:08 +00:00
|
|
|
col = gtk_tree_view_column_new_with_attributes( title, rend, "value", FC_PROG, NULL );
|
|
|
|
gtk_tree_view_column_set_fixed_width( col, width );
|
|
|
|
gtk_tree_view_column_set_sizing( col, GTK_TREE_VIEW_COLUMN_FIXED );
|
2009-06-10 00:04:43 +00:00
|
|
|
gtk_tree_view_column_set_sort_column_id( col, FC_PROG );
|
2009-06-23 00:24:37 +00:00
|
|
|
gtk_tree_view_append_column( tree_view, col );
|
2008-02-10 22:25:42 +00:00
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
/* add "enabled" column */
|
2009-06-06 04:29:08 +00:00
|
|
|
title = _( "Download" );
|
|
|
|
pango_layout = gtk_widget_create_pango_layout( view, title );
|
|
|
|
pango_layout_get_pixel_size( pango_layout, &width, NULL );
|
2009-06-23 00:24:37 +00:00
|
|
|
width += 30; /* room for the sort indicator */
|
2009-06-06 04:29:08 +00:00
|
|
|
g_object_unref( G_OBJECT( pango_layout ) );
|
2008-09-05 21:01:00 +00:00
|
|
|
rend = gtk_cell_renderer_toggle_new( );
|
2009-06-06 04:29:08 +00:00
|
|
|
col = gtk_tree_view_column_new_with_attributes( title, rend, NULL );
|
2011-01-05 07:08:34 +00:00
|
|
|
g_object_set_data( G_OBJECT( col ), TR_COLUMN_ID_KEY,
|
|
|
|
GINT_TO_POINTER( FC_ENABLED ) );
|
2009-06-06 04:29:08 +00:00
|
|
|
gtk_tree_view_column_set_fixed_width( col, width );
|
|
|
|
gtk_tree_view_column_set_sizing( col, GTK_TREE_VIEW_COLUMN_FIXED );
|
2008-11-08 15:36:12 +00:00
|
|
|
gtk_tree_view_column_set_cell_data_func( col, rend, renderDownload, NULL, NULL );
|
2009-06-10 00:04:43 +00:00
|
|
|
gtk_tree_view_column_set_sort_column_id( col, FC_ENABLED );
|
2009-06-23 00:24:37 +00:00
|
|
|
gtk_tree_view_append_column( tree_view, col );
|
2008-02-10 22:25:42 +00:00
|
|
|
|
|
|
|
/* add priority column */
|
2009-06-06 04:29:08 +00:00
|
|
|
title = _( "Priority" );
|
|
|
|
pango_layout = gtk_widget_create_pango_layout( view, title );
|
|
|
|
pango_layout_get_pixel_size( pango_layout, &width, NULL );
|
2009-06-23 00:24:37 +00:00
|
|
|
width += 30; /* room for the sort indicator */
|
2009-06-06 04:29:08 +00:00
|
|
|
g_object_unref( G_OBJECT( pango_layout ) );
|
2008-05-29 02:59:22 +00:00
|
|
|
rend = gtk_cell_renderer_text_new( );
|
2009-06-10 00:04:43 +00:00
|
|
|
g_object_set( rend, "xalign", (gfloat)0.5, "yalign", (gfloat)0.5, NULL );
|
2009-06-06 04:29:08 +00:00
|
|
|
col = gtk_tree_view_column_new_with_attributes( title, rend, NULL );
|
2011-01-05 07:08:34 +00:00
|
|
|
g_object_set_data( G_OBJECT( col ), TR_COLUMN_ID_KEY,
|
|
|
|
GINT_TO_POINTER( FC_PRIORITY ) );
|
2009-06-06 04:29:08 +00:00
|
|
|
gtk_tree_view_column_set_fixed_width( col, width );
|
|
|
|
gtk_tree_view_column_set_sizing( col, GTK_TREE_VIEW_COLUMN_FIXED );
|
2009-06-10 00:04:43 +00:00
|
|
|
gtk_tree_view_column_set_sort_column_id( col, FC_PRIORITY );
|
2008-11-08 15:36:12 +00:00
|
|
|
gtk_tree_view_column_set_cell_data_func( col, rend, renderPriority, NULL, NULL );
|
2009-06-23 00:24:37 +00:00
|
|
|
gtk_tree_view_append_column( tree_view, col );
|
2008-02-10 22:25:42 +00:00
|
|
|
|
|
|
|
/* create the scrolled window and stick the view in it */
|
|
|
|
scroll = gtk_scrolled_window_new( NULL, NULL );
|
|
|
|
gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scroll ),
|
2008-11-08 15:36:12 +00:00
|
|
|
GTK_POLICY_AUTOMATIC,
|
|
|
|
GTK_POLICY_AUTOMATIC );
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_scrolled_window_set_shadow_type ( GTK_SCROLLED_WINDOW( scroll ),
|
|
|
|
GTK_SHADOW_IN );
|
2008-02-10 22:25:42 +00:00
|
|
|
gtk_container_add( GTK_CONTAINER( scroll ), view );
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_widget_set_size_request ( scroll, -1, 200 );
|
2008-02-10 22:25:42 +00:00
|
|
|
|
2008-09-06 01:52:47 +00:00
|
|
|
ret = scroll;
|
2008-02-12 18:53:31 +00:00
|
|
|
data->view = view;
|
|
|
|
data->top = scroll;
|
|
|
|
g_object_set_data_full( G_OBJECT( ret ), "file-data", data, freeData );
|
2010-12-22 06:25:30 +00:00
|
|
|
gtr_file_list_set_torrent( ret, torrentId );
|
2008-02-10 22:25:42 +00:00
|
|
|
|
2011-02-01 17:42:50 +00:00
|
|
|
pango_font_description_free( pango_font_description );
|
2008-02-12 18:53:31 +00:00
|
|
|
return ret;
|
2008-02-10 22:25:42 +00:00
|
|
|
}
|