2008-02-10 22:25:42 +00:00
|
|
|
/******************************************************************************
|
2008-02-26 21:08:51 +00:00
|
|
|
* $Id$
|
2008-02-10 22:25:42 +00:00
|
|
|
*
|
|
|
|
* Copyright (c) 2005-2008 Transmission authors and contributors
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#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>
|
2008-05-29 02:59:22 +00:00
|
|
|
#include <libtransmission/utils.h> /* tr_getRatio */
|
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"
|
2008-02-10 22:25:42 +00:00
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
enum
|
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
SUB_STATE_HIGH = ( 1 << 0 ),
|
|
|
|
SUB_STATE_NORMAL = ( 1 << 1 ),
|
|
|
|
SUB_STATE_LOW = ( 1 << 2 ),
|
|
|
|
SUB_STATE_PRIORITY_MASK =
|
|
|
|
( SUB_STATE_HIGH | SUB_STATE_NORMAL | SUB_STATE_LOW ),
|
|
|
|
SUB_STATE_DOWNLOAD = ( 1 << 4 ),
|
|
|
|
SUB_STATE_IGNORE = ( 1 << 5 ),
|
|
|
|
SUB_STATE_DOWNLOAD_MASK = ( SUB_STATE_DOWNLOAD | SUB_STATE_IGNORE )
|
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_KEY,
|
|
|
|
FC_INDEX,
|
|
|
|
FC_SIZE,
|
|
|
|
FC_HAVE,
|
|
|
|
FC_PRIORITY,
|
|
|
|
FC_ENABLED,
|
|
|
|
FC_IS_FILE,
|
|
|
|
FC_SUB_SIZE,
|
|
|
|
FC_SUB_HAVE,
|
|
|
|
FC_SUB_STATE,
|
|
|
|
N_FILE_COLS
|
2008-02-10 22:25:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
TrTorrent * gtor;
|
|
|
|
GtkWidget * top;
|
|
|
|
GtkWidget * view;
|
|
|
|
GtkTreeModel * model; /* same object as store, but recast */
|
|
|
|
GtkTreeStore * store; /* same object as model, but recast */
|
|
|
|
tr_file_stat * refresh_file_stat;
|
|
|
|
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
|
|
|
{
|
2008-05-29 02:59:22 +00:00
|
|
|
data->gtor = NULL;
|
|
|
|
|
2008-09-23 19:11: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
|
|
|
|
freeData( gpointer gdata )
|
2008-02-10 22:25:42 +00:00
|
|
|
{
|
2008-05-29 02:59:22 +00:00
|
|
|
FileData * data = gdata;
|
2008-09-23 19:11:04 +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
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2008-02-10 22:25:42 +00:00
|
|
|
static void
|
2009-03-02 23:31:01 +00:00
|
|
|
parsepath( GtkWidget * w,
|
|
|
|
const tr_torrent * tor,
|
|
|
|
GtkTreeStore * store,
|
|
|
|
GtkTreeIter * ret,
|
|
|
|
const char * path,
|
|
|
|
tr_file_index_t index,
|
|
|
|
uint64_t size )
|
2008-02-10 22:25:42 +00:00
|
|
|
{
|
|
|
|
GtkTreeModel * model;
|
2009-03-02 23:31:01 +00:00
|
|
|
GtkTreeIter * parent, start, iter;
|
|
|
|
char * file, * lower, * mykey;
|
2008-02-10 22:25:42 +00:00
|
|
|
int priority = 0;
|
|
|
|
gboolean enabled = TRUE;
|
2008-05-29 02:59:22 +00:00
|
|
|
gboolean is_file;
|
2009-03-02 23:31:01 +00:00
|
|
|
GdkPixbuf * icon;
|
|
|
|
const char * mime_type;
|
|
|
|
|
2008-02-10 22:25:42 +00:00
|
|
|
model = GTK_TREE_MODEL( store );
|
|
|
|
parent = NULL;
|
|
|
|
file = g_path_get_basename( path );
|
|
|
|
if( 0 != strcmp( file, path ) )
|
|
|
|
{
|
|
|
|
char * dir = g_path_get_dirname( path );
|
2009-03-02 23:31:01 +00:00
|
|
|
parsepath( w, tor, store, &start, dir, index, size );
|
2008-02-10 22:25:42 +00:00
|
|
|
parent = &start;
|
|
|
|
g_free( dir );
|
|
|
|
}
|
|
|
|
|
|
|
|
lower = g_utf8_casefold( file, -1 );
|
|
|
|
mykey = g_utf8_collate_key( lower, -1 );
|
|
|
|
if( gtk_tree_model_iter_children( model, &iter, parent ) ) do
|
2008-09-23 19:11:04 +00:00
|
|
|
{
|
|
|
|
gboolean stop;
|
|
|
|
char * modelkey;
|
|
|
|
gtk_tree_model_get( model, &iter, FC_KEY, &modelkey, -1 );
|
|
|
|
stop = ( modelkey != NULL ) && !strcmp( mykey, modelkey );
|
|
|
|
g_free ( modelkey );
|
|
|
|
if( stop ) goto done;
|
|
|
|
}
|
|
|
|
while( gtk_tree_model_iter_next( model, &iter ) );
|
2008-02-10 22:25:42 +00:00
|
|
|
|
|
|
|
gtk_tree_store_append( store, &iter, parent );
|
2008-09-23 19:11:04 +00:00
|
|
|
if( ( is_file = !ret ) )
|
2008-02-10 22:25:42 +00:00
|
|
|
{
|
2008-05-29 02:59:22 +00:00
|
|
|
priority = tr_torrentGetFilePriority( tor, index );
|
|
|
|
enabled = tr_torrentGetFileDL( tor, index );
|
2009-03-02 23:31:01 +00:00
|
|
|
mime_type = get_mime_type_from_filename( file );
|
2008-02-10 22:25:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
size = 0;
|
2009-03-02 23:31:01 +00:00
|
|
|
mime_type = DIRECTORY_MIME_TYPE;
|
2008-02-10 22:25:42 +00:00
|
|
|
}
|
|
|
|
|
2009-03-02 23:31:01 +00:00
|
|
|
icon = get_mime_type_icon( mime_type, GTK_ICON_SIZE_MENU, w );
|
|
|
|
|
2008-06-22 01:25:03 +00:00
|
|
|
#if 0
|
2008-02-10 22:25:42 +00:00
|
|
|
gtk_tree_store_set( store, &iter, FC_INDEX, index,
|
2009-03-02 23:31:01 +00:00
|
|
|
FC_LABEL, file,
|
|
|
|
FC_KEY, mykey,
|
|
|
|
FC_ICON, icon,
|
|
|
|
FC_PRIORITY, priority,
|
|
|
|
FC_ENABLED, enabled,
|
|
|
|
FC_IS_FILE, is_file,
|
|
|
|
FC_SIZE, size,
|
|
|
|
FC_HAVE, 0,
|
|
|
|
-1 );
|
2008-06-22 01:25:03 +00:00
|
|
|
#else
|
|
|
|
gtk_tree_store_set( store, &iter, FC_INDEX, index, -1 );
|
|
|
|
gtk_tree_store_set( store, &iter, FC_LABEL, file, -1 );
|
|
|
|
gtk_tree_store_set( store, &iter, FC_KEY, mykey, -1 );
|
2009-03-02 23:31:01 +00:00
|
|
|
gtk_tree_store_set( store, &iter, FC_ICON, icon, -1 );
|
2008-06-22 01:25:03 +00:00
|
|
|
gtk_tree_store_set( store, &iter, FC_PRIORITY, priority, -1 );
|
|
|
|
gtk_tree_store_set( store, &iter, FC_ENABLED, enabled, -1 );
|
|
|
|
gtk_tree_store_set( store, &iter, FC_IS_FILE, is_file, -1 );
|
|
|
|
gtk_tree_store_set( store, &iter, FC_SIZE, size, -1 );
|
|
|
|
gtk_tree_store_set( store, &iter, FC_HAVE, 0, -1 );
|
|
|
|
#endif
|
|
|
|
|
2009-03-02 23:31:01 +00:00
|
|
|
if( icon != NULL )
|
|
|
|
g_object_unref( icon );
|
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
done:
|
2008-02-10 22:25:42 +00:00
|
|
|
g_free( mykey );
|
|
|
|
g_free( lower );
|
|
|
|
g_free( file );
|
|
|
|
if( NULL != ret )
|
2008-09-23 19:11:04 +00:00
|
|
|
*ret = iter;
|
2008-02-10 22:25:42 +00:00
|
|
|
}
|
|
|
|
|
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 gboolean
|
2008-09-23 19:11:04 +00:00
|
|
|
refreshFilesForeach( GtkTreeModel * model,
|
2008-05-29 02:59:22 +00:00
|
|
|
GtkTreePath * path UNUSED,
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkTreeIter * iter,
|
|
|
|
gpointer gdata )
|
2008-05-29 02:59:22 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
FileData * data = gdata;
|
|
|
|
gboolean is_file;
|
2008-05-29 02:59:22 +00:00
|
|
|
unsigned int index;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
|
|
|
gtk_tree_model_get( model, iter, FC_IS_FILE, &is_file, FC_INDEX, &index,
|
|
|
|
-1 );
|
|
|
|
if( is_file )
|
|
|
|
{
|
2008-05-29 02:59:22 +00:00
|
|
|
GtkTreeStore * store = GTK_TREE_STORE( model );
|
2008-09-23 19:11:04 +00:00
|
|
|
tr_torrent * tor = tr_torrent_handle( data->gtor );
|
|
|
|
int download = tr_torrentGetFileDL( tor, index );
|
|
|
|
int priority = tr_torrentGetFilePriority( tor, index );
|
|
|
|
uint64_t have = data->refresh_file_stat[index].bytesCompleted;
|
2008-05-29 02:59:22 +00:00
|
|
|
gtk_tree_store_set( store, iter, FC_PRIORITY, priority,
|
2008-09-23 19:11:04 +00:00
|
|
|
FC_ENABLED, download,
|
|
|
|
FC_HAVE, have,
|
|
|
|
-1 );
|
2008-05-29 02:59:22 +00:00
|
|
|
}
|
|
|
|
return FALSE; /* keep walking */
|
2008-02-10 22:25:42 +00:00
|
|
|
}
|
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
static gboolean
|
2008-09-23 19:11:04 +00:00
|
|
|
resetSubForeach( GtkTreeModel * model,
|
|
|
|
GtkTreePath * path UNUSED,
|
|
|
|
GtkTreeIter * iter,
|
2008-05-29 02:59:22 +00:00
|
|
|
gpointer gdata UNUSED )
|
2008-02-10 22:25:42 +00:00
|
|
|
{
|
2008-05-29 03:15:33 +00:00
|
|
|
/* set the subs to the lowest values... */
|
2008-05-29 02:59:22 +00:00
|
|
|
gtk_tree_store_set( GTK_TREE_STORE( model ), iter,
|
|
|
|
FC_SUB_STATE, 0,
|
|
|
|
FC_SUB_SIZE, (uint64_t)0,
|
|
|
|
FC_SUB_HAVE, (uint64_t)0,
|
|
|
|
-1 );
|
|
|
|
return FALSE; /* keep walking */
|
|
|
|
}
|
2008-02-10 22:25:42 +00:00
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
static gboolean
|
2008-09-23 19:11:04 +00:00
|
|
|
addSubForeach( GtkTreeModel * model,
|
|
|
|
GtkTreePath * path UNUSED,
|
|
|
|
GtkTreeIter * iter,
|
2008-05-29 02:59:22 +00:00
|
|
|
gpointer gdata UNUSED )
|
|
|
|
{
|
|
|
|
uint64_t size;
|
|
|
|
uint64_t have;
|
2008-09-23 19:11:04 +00:00
|
|
|
int priority;
|
2008-05-29 02:59:22 +00:00
|
|
|
gboolean enabled;
|
|
|
|
gboolean is_file;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
gtk_tree_model_get( model, iter, FC_SIZE, &size,
|
2008-09-23 19:11:04 +00:00
|
|
|
FC_HAVE, &have,
|
|
|
|
FC_PRIORITY, &priority,
|
|
|
|
FC_ENABLED, &enabled,
|
|
|
|
FC_IS_FILE, &is_file,
|
|
|
|
-1 );
|
2008-05-29 02:59:22 +00:00
|
|
|
if( is_file )
|
2008-02-10 22:25:42 +00:00
|
|
|
{
|
2008-05-29 02:59:22 +00:00
|
|
|
GtkTreeIter child = *iter;
|
|
|
|
GtkTreeIter parent;
|
2008-09-23 19:11:04 +00:00
|
|
|
while( ( gtk_tree_model_iter_parent( model, &parent, &child ) ) )
|
2008-02-10 22:25:42 +00:00
|
|
|
{
|
2008-05-29 02:59:22 +00:00
|
|
|
uint64_t sub_size;
|
|
|
|
uint64_t sub_have;
|
2008-09-23 19:11:04 +00:00
|
|
|
int sub_state;
|
2008-05-29 02:59:22 +00:00
|
|
|
gtk_tree_model_get( model, &parent, FC_SUB_SIZE, &sub_size,
|
2008-09-23 19:11:04 +00:00
|
|
|
FC_SUB_HAVE, &sub_have,
|
|
|
|
FC_SUB_STATE, &sub_state,
|
|
|
|
-1 );
|
2008-05-29 02:59:22 +00:00
|
|
|
sub_have += have;
|
|
|
|
sub_size += size;
|
2008-09-23 19:11:04 +00:00
|
|
|
switch( priority )
|
|
|
|
{
|
|
|
|
case TR_PRI_HIGH:
|
|
|
|
sub_state |= SUB_STATE_HIGH; break;
|
|
|
|
|
|
|
|
case TR_PRI_NORMAL:
|
|
|
|
sub_state |= SUB_STATE_NORMAL; break;
|
|
|
|
|
|
|
|
case TR_PRI_LOW:
|
|
|
|
sub_state |= SUB_STATE_LOW; break;
|
2008-05-29 02:59:22 +00:00
|
|
|
}
|
|
|
|
sub_state |= ( enabled ? SUB_STATE_DOWNLOAD : SUB_STATE_IGNORE );
|
|
|
|
gtk_tree_store_set( GTK_TREE_STORE( model ), &parent,
|
|
|
|
FC_SUB_SIZE, sub_size,
|
|
|
|
FC_SUB_HAVE, sub_have,
|
|
|
|
FC_SUB_STATE, sub_state,
|
|
|
|
-1 );
|
|
|
|
child = parent;
|
2008-02-10 22:25:42 +00:00
|
|
|
}
|
2008-05-29 02:59:22 +00:00
|
|
|
}
|
|
|
|
return FALSE; /* keep walking */
|
|
|
|
}
|
2008-02-10 22:25:42 +00:00
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
static void
|
|
|
|
refresh( FileData * data )
|
|
|
|
{
|
|
|
|
tr_file_index_t fileCount;
|
2008-09-23 19:11:04 +00:00
|
|
|
tr_torrent * tor = tr_torrent_handle( data->gtor );
|
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
data->refresh_file_stat = tr_torrentFiles( tor, &fileCount );
|
2008-02-10 22:25:42 +00:00
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
gtk_tree_model_foreach( data->model, refreshFilesForeach, data );
|
|
|
|
gtk_tree_model_foreach( data->model, resetSubForeach, data );
|
|
|
|
gtk_tree_model_foreach( data->model, addSubForeach, data );
|
2008-02-10 22:25:42 +00:00
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
tr_torrentFilesFree( data->refresh_file_stat, fileCount );
|
|
|
|
data->refresh_file_stat = NULL;
|
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
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkTreeSelection * sel;
|
|
|
|
GArray * array;
|
2008-05-29 02:59:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static gboolean
|
2008-09-23 19:11:04 +00:00
|
|
|
getSelectedFilesForeach( GtkTreeModel * model,
|
2008-09-06 01:52:47 +00:00
|
|
|
GtkTreePath * path UNUSED,
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkTreeIter * iter,
|
|
|
|
gpointer gdata )
|
2008-05-29 02:59:22 +00:00
|
|
|
{
|
|
|
|
struct ActiveData * data = gdata;
|
2008-09-23 19:11:04 +00:00
|
|
|
unsigned int i;
|
|
|
|
gboolean is_file = FALSE;
|
|
|
|
gboolean is_active = FALSE;
|
2008-05-29 02:59:22 +00:00
|
|
|
|
|
|
|
/* active == if it's selected, or any ancestor is selected */
|
|
|
|
gtk_tree_model_get( model, iter, FC_IS_FILE, &is_file, FC_INDEX, &i, -1 );
|
2008-09-23 19:11:04 +00:00
|
|
|
if( is_file )
|
|
|
|
{
|
2008-05-29 02:59:22 +00:00
|
|
|
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;
|
2008-09-23 19:11:04 +00:00
|
|
|
while( !is_active
|
|
|
|
&& gtk_tree_model_iter_parent( model, &parent, &walk ) )
|
|
|
|
{
|
|
|
|
is_active = gtk_tree_selection_iter_is_selected( data->sel,
|
|
|
|
&parent );
|
2008-05-29 02:59:22 +00:00
|
|
|
walk = parent;
|
|
|
|
}
|
|
|
|
}
|
2008-03-22 18:10:59 +00:00
|
|
|
}
|
2008-02-10 22:25:42 +00:00
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
if( is_active )
|
|
|
|
g_array_append_val( data->array, i );
|
|
|
|
|
2008-05-29 03:15:33 +00:00
|
|
|
return FALSE; /* keep walking */
|
2008-02-10 22:25:42 +00:00
|
|
|
}
|
|
|
|
|
2008-09-06 01:52:47 +00:00
|
|
|
static void
|
2008-09-23 19:11:04 +00:00
|
|
|
getSelectedFilesAndDescendants( GtkTreeView * view,
|
|
|
|
GArray * indices )
|
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 );
|
2008-09-06 01:52:47 +00:00
|
|
|
data.array = indices;
|
2008-10-26 22:58:57 +00:00
|
|
|
gtk_tree_model_foreach( gtk_tree_view_get_model( view ),
|
|
|
|
getSelectedFilesForeach, &data );
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SubtreeForeachData
|
|
|
|
{
|
|
|
|
GArray * array;
|
|
|
|
GtkTreePath * path;
|
|
|
|
};
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
getSubtreeForeach( GtkTreeModel * model,
|
|
|
|
GtkTreePath * path,
|
|
|
|
GtkTreeIter * iter,
|
|
|
|
gpointer gdata )
|
|
|
|
{
|
|
|
|
struct SubtreeForeachData * data = gdata;
|
|
|
|
unsigned int i;
|
|
|
|
gboolean is_file = FALSE;
|
|
|
|
|
|
|
|
gtk_tree_model_get( model, iter,
|
|
|
|
FC_IS_FILE, &is_file,
|
|
|
|
FC_INDEX, &i, -1 );
|
|
|
|
if( is_file )
|
|
|
|
if( !gtk_tree_path_compare( path, data->path ) || gtk_tree_path_is_descendant( path, data->path ) )
|
|
|
|
g_array_append_val( data->array, i );
|
|
|
|
|
|
|
|
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*
|
2008-09-23 19:11:04 +00:00
|
|
|
getActiveFilesForPath( GtkTreeView * view,
|
|
|
|
GtkTreePath * path )
|
2008-02-15 18:20:56 +00:00
|
|
|
{
|
2008-09-05 21:01:00 +00:00
|
|
|
GtkTreeSelection * sel = gtk_tree_view_get_selection( view );
|
2008-10-26 22:58:57 +00:00
|
|
|
GArray * indices = g_array_new( FALSE, FALSE, sizeof( tr_file_index_t ) );
|
2008-09-05 21:01:00 +00:00
|
|
|
|
|
|
|
if( gtk_tree_selection_path_is_selected( sel, path ) )
|
|
|
|
{
|
|
|
|
/* clicked in a selected row... use the current selection */
|
2008-09-06 01:52:47 +00:00
|
|
|
getSelectedFilesAndDescendants( view, indices );
|
2008-09-05 21:01:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* clicked OUTSIDE of the selected row... just use the clicked row */
|
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
|
2008-09-23 19:11:04 +00:00
|
|
|
file_list_set_torrent( GtkWidget * w,
|
|
|
|
TrTorrent * gtor )
|
2008-02-10 22:25:42 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkTreeStore * store;
|
|
|
|
FileData * data;
|
2008-02-12 18:53:31 +00:00
|
|
|
|
|
|
|
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-03-02 23:31:01 +00:00
|
|
|
GDK_TYPE_PIXBUF, /* icon */
|
2008-02-10 22:25:42 +00:00
|
|
|
G_TYPE_STRING, /* label */
|
|
|
|
G_TYPE_INT, /* prog [0..100] */
|
|
|
|
G_TYPE_STRING, /* key */
|
2008-05-29 02:59:22 +00:00
|
|
|
G_TYPE_UINT, /* index */
|
2008-02-10 22:25:42 +00:00
|
|
|
G_TYPE_UINT64, /* size */
|
2008-05-29 02:59:22 +00:00
|
|
|
G_TYPE_UINT64, /* have */
|
|
|
|
G_TYPE_INT, /* priority */
|
|
|
|
G_TYPE_BOOLEAN, /* dl enabled */
|
|
|
|
G_TYPE_BOOLEAN, /* is file */
|
|
|
|
G_TYPE_UINT64, /* sub size */
|
|
|
|
G_TYPE_UINT64, /* sub have */
|
|
|
|
G_TYPE_INT ); /* sub state */
|
2008-02-12 18:53:31 +00:00
|
|
|
data->store = store;
|
|
|
|
data->model = GTK_TREE_MODEL( store );
|
|
|
|
data->gtor = gtor;
|
2008-02-10 22:25:42 +00:00
|
|
|
|
2008-02-12 18:53:31 +00:00
|
|
|
|
|
|
|
/* populate the model */
|
|
|
|
if( gtor )
|
2008-02-10 22:25:42 +00:00
|
|
|
{
|
2008-03-22 18:10:59 +00:00
|
|
|
tr_file_index_t i;
|
2008-02-12 18:53:31 +00:00
|
|
|
const tr_info * inf = tr_torrent_info( gtor );
|
2008-09-23 19:11:04 +00:00
|
|
|
tr_torrent * tor = tr_torrent_handle( gtor );
|
2008-02-12 18:53:31 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
for( i = 0; inf && i < inf->fileCount; ++i )
|
2008-02-12 18:53:31 +00:00
|
|
|
{
|
|
|
|
const char * path = inf->files[i].name;
|
2008-09-23 19:11:04 +00:00
|
|
|
const char * base =
|
|
|
|
g_path_is_absolute( path ) ? g_path_skip_root( path ) :
|
|
|
|
path;
|
2009-03-02 23:31:01 +00:00
|
|
|
parsepath( w, tor, store, NULL, base, i, inf->files[i].length );
|
2008-02-12 18:53:31 +00:00
|
|
|
}
|
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
refresh( data );
|
2008-02-12 18:53:31 +00:00
|
|
|
|
2008-12-22 05:39:03 +00:00
|
|
|
data->timeout_tag = gtr_timeout_add_seconds( 2, refreshModel, data );
|
2008-02-10 22:25:42 +00:00
|
|
|
}
|
2008-02-12 18:53:31 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_tree_view_set_model( GTK_TREE_VIEW( data->view ),
|
|
|
|
GTK_TREE_MODEL( store ) );
|
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
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2008-02-15 18:20:56 +00:00
|
|
|
static void
|
2008-05-29 02:59:22 +00:00
|
|
|
renderProgress( GtkTreeViewColumn * column UNUSED,
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkCellRenderer * renderer,
|
|
|
|
GtkTreeModel * model,
|
|
|
|
GtkTreeIter * iter,
|
|
|
|
gpointer data UNUSED )
|
2008-02-15 18:20:56 +00:00
|
|
|
{
|
2008-05-29 02:59:22 +00:00
|
|
|
gboolean is_file;
|
|
|
|
uint64_t size, have, subsize, subhave;
|
2008-09-23 19:11:04 +00:00
|
|
|
double progress;
|
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
gtk_tree_model_get( model, iter, FC_SIZE, &size,
|
2008-09-23 19:11:04 +00:00
|
|
|
FC_HAVE, &have,
|
|
|
|
FC_SUB_SIZE, &subsize,
|
|
|
|
FC_SUB_HAVE, &subhave,
|
|
|
|
FC_IS_FILE, &is_file,
|
|
|
|
-1 );
|
2008-05-29 02:59:22 +00:00
|
|
|
progress = is_file ? tr_getRatio( have, size )
|
2008-09-23 19:11:04 +00:00
|
|
|
: tr_getRatio( subhave, subsize );
|
|
|
|
g_object_set( renderer, "value", (int)( progress * 100 ), NULL );
|
2008-05-29 02:59:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
renderFilename( GtkTreeViewColumn * column UNUSED,
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkCellRenderer * renderer,
|
|
|
|
GtkTreeModel * model,
|
|
|
|
GtkTreeIter * iter,
|
|
|
|
gpointer data UNUSED )
|
2008-05-29 02:59:22 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
char * filename;
|
|
|
|
char * str;
|
|
|
|
int64_t size;
|
|
|
|
int64_t subsize;
|
2008-05-29 02:59:22 +00:00
|
|
|
gboolean is_file;
|
2008-09-23 19:11:04 +00:00
|
|
|
char buf[64];
|
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
gtk_tree_model_get( model, iter, FC_LABEL, &filename,
|
2008-09-23 19:11:04 +00:00
|
|
|
FC_SIZE, &size,
|
|
|
|
FC_SUB_SIZE, &subsize,
|
|
|
|
FC_IS_FILE, &is_file,
|
|
|
|
-1 );
|
2008-05-29 02:59:22 +00:00
|
|
|
tr_strlsize( buf, is_file ? size : subsize, sizeof( buf ) );
|
|
|
|
str = g_markup_printf_escaped( "<small>%s (%s)</small>",
|
|
|
|
filename, buf );
|
|
|
|
g_object_set( renderer, "markup", str, NULL );
|
|
|
|
g_free( str );
|
|
|
|
g_free( filename );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
renderDownload( GtkTreeViewColumn * column UNUSED,
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkCellRenderer * renderer,
|
|
|
|
GtkTreeModel * model,
|
|
|
|
GtkTreeIter * iter,
|
|
|
|
gpointer data UNUSED )
|
2008-05-29 02:59:22 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
int sub_state;
|
2008-05-29 02:59:22 +00:00
|
|
|
gboolean enabled;
|
2008-09-05 21:01:00 +00:00
|
|
|
gboolean active = FALSE;
|
|
|
|
gboolean inconsistent = FALSE;
|
2008-05-29 02:59:22 +00:00
|
|
|
gboolean is_file = FALSE;
|
|
|
|
|
|
|
|
gtk_tree_model_get( model, iter, FC_IS_FILE, &is_file,
|
2008-09-23 19:11:04 +00:00
|
|
|
FC_ENABLED, &enabled,
|
|
|
|
FC_SUB_STATE, &sub_state,
|
|
|
|
-1 );
|
2008-05-29 02:59:22 +00:00
|
|
|
if( is_file && enabled )
|
2008-09-05 21:01:00 +00:00
|
|
|
active = TRUE;
|
2008-05-29 02:59:22 +00:00
|
|
|
else if( is_file )
|
2008-09-05 21:01:00 +00:00
|
|
|
active = FALSE;
|
2008-09-23 19:11:04 +00:00
|
|
|
else switch( sub_state & SUB_STATE_DOWNLOAD_MASK )
|
|
|
|
{
|
|
|
|
case SUB_STATE_DOWNLOAD:
|
|
|
|
active = TRUE; break;
|
|
|
|
|
|
|
|
case SUB_STATE_IGNORE:
|
|
|
|
active = FALSE; break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
inconsistent = TRUE; break;
|
|
|
|
}
|
2008-05-29 02:59:22 +00:00
|
|
|
|
2008-09-05 21:01:00 +00:00
|
|
|
g_object_set( renderer, "inconsistent", inconsistent,
|
2008-09-23 19:11:04 +00:00
|
|
|
"active", active,
|
|
|
|
NULL );
|
2008-05-29 02:59:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
renderPriority( GtkTreeViewColumn * column UNUSED,
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkCellRenderer * renderer,
|
|
|
|
GtkTreeModel * model,
|
|
|
|
GtkTreeIter * iter,
|
|
|
|
gpointer data UNUSED )
|
2008-05-29 02:59:22 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
int priority;
|
|
|
|
int sub_state;
|
|
|
|
gboolean is_file = FALSE;
|
2008-05-29 02:59:22 +00:00
|
|
|
const char * text = "";
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
gtk_tree_model_get( model, iter, FC_IS_FILE, &is_file,
|
2008-09-23 19:11:04 +00:00
|
|
|
FC_PRIORITY, &priority,
|
|
|
|
FC_SUB_STATE, &sub_state,
|
|
|
|
-1 );
|
2008-05-29 02:59:22 +00:00
|
|
|
if( !is_file )
|
|
|
|
{
|
|
|
|
switch( sub_state & SUB_STATE_PRIORITY_MASK )
|
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
case SUB_STATE_HIGH:
|
|
|
|
priority = TR_PRI_HIGH; break;
|
|
|
|
|
|
|
|
case SUB_STATE_NORMAL:
|
|
|
|
priority = TR_PRI_NORMAL; break;
|
|
|
|
|
|
|
|
case SUB_STATE_LOW:
|
|
|
|
priority = TR_PRI_LOW; break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
priority = 666; break;
|
2008-05-29 02:59:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( priority )
|
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
case TR_PRI_HIGH:
|
|
|
|
text = _( "High" );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_PRI_NORMAL:
|
|
|
|
text = _( "Normal" );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_PRI_LOW:
|
|
|
|
text = _( "Low" );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
text = _( "Mixed" );
|
|
|
|
break;
|
2008-05-29 02:59:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_object_set( renderer, "text", text,
|
2008-09-23 19:11:04 +00:00
|
|
|
"xalign", (gfloat)0.5,
|
|
|
|
"yalign", (gfloat)0.5,
|
|
|
|
NULL );
|
2008-02-15 18:20:56 +00:00
|
|
|
}
|
|
|
|
|
2008-09-05 21:01:00 +00:00
|
|
|
static gboolean
|
2008-09-23 19:11:04 +00:00
|
|
|
onViewButtonPressed( GtkWidget * w,
|
2008-09-05 21:01:00 +00:00
|
|
|
GdkEventButton * event,
|
2008-09-06 01:52:47 +00:00
|
|
|
gpointer gdata )
|
2008-09-05 21:01:00 +00:00
|
|
|
{
|
2008-09-06 01:52:47 +00:00
|
|
|
FileData * data = gdata;
|
2008-09-23 19:11:04 +00:00
|
|
|
gboolean handled = FALSE;
|
2008-09-05 21:01:00 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
if( ( event->type == GDK_BUTTON_PRESS ) && ( event->button == 1 )
|
|
|
|
&& !( event->state & ( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) )
|
2008-09-05 21:01:00 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkTreeView * view = GTK_TREE_VIEW( w );
|
|
|
|
GtkTreePath * path;
|
2008-09-05 21:01:00 +00:00
|
|
|
GtkTreeViewColumn * column;
|
2008-09-23 19:11:04 +00:00
|
|
|
int cell_x;
|
|
|
|
int cell_y;
|
2008-09-06 01:52:47 +00:00
|
|
|
if( gtk_tree_view_get_path_at_pos( view, event->x, event->y,
|
2008-09-05 21:01:00 +00:00
|
|
|
&path, &column, &cell_x, &cell_y ) )
|
|
|
|
{
|
2008-12-03 15:32:42 +00:00
|
|
|
const char * column_title = gtk_tree_view_column_get_title( column );
|
|
|
|
const gboolean downloadColumn = !strcmp( column_title, _( "Download" ) );
|
|
|
|
const gboolean priorityColumn = !strcmp( column_title, _( "Priority" ) );
|
2008-09-06 01:52:47 +00:00
|
|
|
if( downloadColumn || priorityColumn )
|
2008-09-05 21:01:00 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
GArray * a = getActiveFilesForPath( view, path );
|
2008-09-06 01:52:47 +00:00
|
|
|
GtkTreeSelection * sel = gtk_tree_view_get_selection( view );
|
2008-09-23 19:11:04 +00:00
|
|
|
const gboolean isSelected =
|
|
|
|
gtk_tree_selection_path_is_selected( sel, path );
|
|
|
|
GtkTreeModel * model = gtk_tree_view_get_model( view );
|
|
|
|
GtkTreeIter iter;
|
2008-09-06 01:52:47 +00:00
|
|
|
|
|
|
|
gtk_tree_model_get_iter( model, &iter, path );
|
|
|
|
|
|
|
|
if( priorityColumn )
|
|
|
|
{
|
|
|
|
gboolean is_file;
|
2008-09-23 19:11:04 +00:00
|
|
|
int sub_state;
|
|
|
|
int priority;
|
2008-09-06 01:52:47 +00:00
|
|
|
|
|
|
|
/* get the `priority' state of the clicked row */
|
|
|
|
gtk_tree_model_get( model, &iter, FC_IS_FILE, &is_file,
|
2008-09-23 19:11:04 +00:00
|
|
|
FC_PRIORITY, &priority,
|
|
|
|
FC_SUB_STATE, &sub_state,
|
|
|
|
-1 );
|
2008-09-06 01:52:47 +00:00
|
|
|
|
|
|
|
/* twiddle it to the next state */
|
2008-09-23 19:11:04 +00:00
|
|
|
if( !is_file ) switch( sub_state &
|
|
|
|
SUB_STATE_PRIORITY_MASK )
|
|
|
|
{
|
|
|
|
case SUB_STATE_NORMAL:
|
|
|
|
priority = TR_PRI_HIGH; break;
|
|
|
|
|
|
|
|
case SUB_STATE_HIGH:
|
|
|
|
priority = TR_PRI_LOW; break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
priority = TR_PRI_NORMAL; break;
|
|
|
|
}
|
|
|
|
else switch( priority )
|
|
|
|
{
|
|
|
|
case TR_PRI_LOW:
|
|
|
|
priority = TR_PRI_NORMAL; break;
|
|
|
|
|
|
|
|
case TR_PRI_NORMAL:
|
|
|
|
priority = TR_PRI_HIGH; break;
|
|
|
|
|
|
|
|
case TR_PRI_HIGH:
|
|
|
|
priority = TR_PRI_LOW; break;
|
|
|
|
}
|
|
|
|
|
2008-09-06 01:52:47 +00:00
|
|
|
/* apply that new state to the active files */
|
2008-09-23 19:11:04 +00:00
|
|
|
tr_torrentSetFilePriorities( tr_torrent_handle( data->
|
|
|
|
gtor ),
|
2008-09-06 01:52:47 +00:00
|
|
|
(tr_file_index_t*)a->data,
|
|
|
|
(tr_file_index_t)a->len,
|
|
|
|
priority );
|
|
|
|
}
|
|
|
|
else if( downloadColumn )
|
|
|
|
{
|
|
|
|
gboolean is_file;
|
2008-09-23 19:11:04 +00:00
|
|
|
int sub_state;
|
2008-09-06 01:52:47 +00:00
|
|
|
gboolean enabled;
|
|
|
|
|
2008-09-08 15:17:18 +00:00
|
|
|
/* get the `enabled' state of the clicked row */
|
2008-09-06 01:52:47 +00:00
|
|
|
gtk_tree_model_get( model, &iter, FC_IS_FILE, &is_file,
|
2008-09-23 19:11:04 +00:00
|
|
|
FC_ENABLED, &enabled,
|
|
|
|
FC_SUB_STATE, &sub_state, -1 );
|
2008-09-06 01:52:47 +00:00
|
|
|
|
|
|
|
/* twiddle it to the next state */
|
|
|
|
if( is_file )
|
|
|
|
enabled = !enabled;
|
|
|
|
else
|
|
|
|
enabled = ( sub_state & SUB_STATE_IGNORE ) ? 1 : 0;
|
|
|
|
|
|
|
|
/* apply that new state to the active files */
|
2008-09-08 15:17:18 +00:00
|
|
|
tr_torrentSetFileDLs( tr_torrent_handle( data->gtor ),
|
|
|
|
(tr_file_index_t*)a->data,
|
|
|
|
(tr_file_index_t)a->len,
|
|
|
|
enabled );
|
2008-09-06 01:52:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
refresh( data );
|
2008-09-08 15:17:18 +00:00
|
|
|
|
|
|
|
/* the click was meant to change the priority or enabled state,
|
|
|
|
not to alter which rows were selected, so don't pass this
|
|
|
|
event on to the other handlers. */
|
2008-09-06 01:52:47 +00:00
|
|
|
handled = isSelected;
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
g_array_free( a, TRUE );
|
2008-09-05 21:01:00 +00:00
|
|
|
}
|
2008-09-06 01:52:47 +00:00
|
|
|
|
2008-09-05 21:01:00 +00:00
|
|
|
gtk_tree_path_free( path );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return handled;
|
|
|
|
}
|
|
|
|
|
2008-02-12 18:53:31 +00:00
|
|
|
GtkWidget *
|
|
|
|
file_list_new( TrTorrent * gtor )
|
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkWidget * ret;
|
|
|
|
GtkWidget * view, * scroll;
|
|
|
|
GtkCellRenderer * rend;
|
|
|
|
GtkTreeViewColumn * col;
|
|
|
|
GtkTreeSelection * sel;
|
|
|
|
FileData * data = g_new0( FileData, 1 );
|
2008-02-10 22:25:42 +00:00
|
|
|
|
|
|
|
/* create the view */
|
2008-02-12 18:53:31 +00:00
|
|
|
view = gtk_tree_view_new( );
|
2008-04-07 02:38:50 +00:00
|
|
|
gtk_tree_view_set_rules_hint( GTK_TREE_VIEW( 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 );
|
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
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
/* set up view */
|
|
|
|
sel = gtk_tree_view_get_selection( GTK_TREE_VIEW( view ) );
|
|
|
|
gtk_tree_selection_set_mode( sel, GTK_SELECTION_MULTIPLE );
|
|
|
|
gtk_tree_view_expand_all( GTK_TREE_VIEW( view ) );
|
|
|
|
gtk_tree_view_set_search_column( GTK_TREE_VIEW( view ), FC_LABEL );
|
|
|
|
|
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,
|
2008-12-03 15:32:42 +00:00
|
|
|
"title", _( "File" ),
|
2008-09-23 19:11:04 +00:00
|
|
|
NULL ) );
|
|
|
|
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( );
|
2008-02-10 22:25:42 +00:00
|
|
|
g_object_set( rend, "ellipsize", PANGO_ELLIPSIZE_END, NULL );
|
|
|
|
gtk_tree_view_column_pack_start( col, rend, TRUE );
|
2008-12-03 15:32:42 +00:00
|
|
|
gtk_tree_view_column_set_cell_data_func( col, rend, renderFilename, NULL, NULL );
|
2008-09-16 18:28:22 +00:00
|
|
|
gtk_tree_view_column_set_resizable( col, TRUE );
|
2008-02-10 22:25:42 +00:00
|
|
|
gtk_tree_view_append_column( GTK_TREE_VIEW( view ), col );
|
2008-05-29 02:59:22 +00:00
|
|
|
|
|
|
|
rend = gtk_cell_renderer_progress_new( );
|
2008-12-03 15:32:42 +00:00
|
|
|
col = gtk_tree_view_column_new_with_attributes( _( "Progress" ), rend, NULL );
|
2008-11-08 15:36:12 +00:00
|
|
|
gtk_tree_view_column_set_cell_data_func( col, rend, renderProgress, NULL, NULL );
|
|
|
|
gtk_tree_view_column_set_resizable( col, FALSE );
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_tree_view_append_column ( GTK_TREE_VIEW( view ), col );
|
2008-02-10 22:25:42 +00:00
|
|
|
|
2008-05-29 02:59:22 +00:00
|
|
|
/* add "enabled" column */
|
2008-09-05 21:01:00 +00:00
|
|
|
rend = gtk_cell_renderer_toggle_new( );
|
2008-12-03 15:32:42 +00:00
|
|
|
col = gtk_tree_view_column_new_with_attributes( _( "Download" ), rend, NULL );
|
2008-11-08 15:36:12 +00:00
|
|
|
gtk_tree_view_column_set_cell_data_func( col, rend, renderDownload, NULL, NULL );
|
|
|
|
gtk_tree_view_column_set_resizable( col, FALSE );
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_tree_view_append_column ( GTK_TREE_VIEW( view ), col );
|
2008-02-10 22:25:42 +00:00
|
|
|
|
|
|
|
/* add priority column */
|
2008-05-29 02:59:22 +00:00
|
|
|
rend = gtk_cell_renderer_text_new( );
|
2008-11-08 15:36:12 +00:00
|
|
|
col = gtk_tree_view_column_new_with_attributes( _( "Priority" ), rend, NULL );
|
|
|
|
gtk_tree_view_column_set_cell_data_func( col, rend, renderPriority, NULL, NULL );
|
|
|
|
gtk_tree_view_column_set_resizable( col, FALSE );
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_tree_view_append_column ( GTK_TREE_VIEW( 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 );
|
|
|
|
file_list_set_torrent( ret, gtor );
|
2008-02-10 22:25:42 +00:00
|
|
|
|
2008-02-12 18:53:31 +00:00
|
|
|
return ret;
|
2008-02-10 22:25:42 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|