enum
{
- /* 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
+ /* 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
};
enum
{
- FC_ICON,
- FC_LABEL,
- FC_LABEL_ESC,
- FC_PROG,
- FC_INDEX,
- FC_SIZE,
- FC_SIZE_STR,
- FC_HAVE,
- FC_PRIORITY,
- FC_ENABLED,
- N_FILE_COLS
+ FC_ICON,
+ FC_LABEL,
+ FC_LABEL_ESC,
+ FC_PROG,
+ FC_INDEX,
+ FC_SIZE,
+ FC_SIZE_STR,
+ FC_HAVE,
+ FC_PRIORITY,
+ FC_ENABLED,
+ N_FILE_COLS
};
typedef struct
{
- TrCore * core;
- GtkWidget * top;
- GtkWidget * view;
- GtkTreeModel * model; /* same object as store, but recast */
- GtkTreeStore * store; /* same object as model, but recast */
- int torrentId;
- guint timeout_tag;
+ TrCore * core;
+ GtkWidget * top;
+ GtkWidget * view;
+ GtkTreeModel * model; /* same object as store, but recast */
+ GtkTreeStore * store; /* same object as model, but recast */
+ int torrentId;
+ guint timeout_tag;
}
FileData;
static void
clearData (FileData * data)
{
- data->torrentId = -1;
+ data->torrentId = -1;
- if (data->timeout_tag) {
- g_source_remove (data->timeout_tag);
- data->timeout_tag = 0;
+ if (data->timeout_tag)
+ {
+ g_source_remove (data->timeout_tag);
+ data->timeout_tag = 0;
}
}
static void
freeData (gpointer data)
{
- clearData (data);
- g_free (data);
+ clearData (data);
+ g_free (data);
}
/***
struct RefreshData
{
- int sort_column_id;
- gboolean resort_needed;
+ int sort_column_id;
+ gboolean resort_needed;
- tr_file_stat * refresh_file_stat;
- tr_torrent * tor;
+ tr_file_stat * refresh_file_stat;
+ tr_torrent * tor;
- FileData * file_data;
+ FileData * file_data;
};
static gboolean
GtkTreeIter * iter,
gpointer gdata)
{
- struct RefreshData * refresh_data = gdata;
- FileData * data = refresh_data->file_data;
- unsigned int index;
- uint64_t size;
- uint64_t old_have;
- int old_prog;
- int old_priority;
- int old_enabled;
- const gboolean is_file = !gtk_tree_model_iter_has_child (model, iter);
-
- gtk_tree_model_get (model, iter, FC_ENABLED, &old_enabled,
- FC_PRIORITY, &old_priority,
- FC_INDEX, &index,
- FC_HAVE, &old_have,
- FC_SIZE, &size,
- FC_PROG, &old_prog,
- -1);
-
- if (is_file)
+ struct RefreshData * refresh_data = gdata;
+ FileData * data = refresh_data->file_data;
+ unsigned int index;
+ uint64_t size;
+ uint64_t old_have;
+ int old_prog;
+ int old_priority;
+ int old_enabled;
+ const gboolean is_file = !gtk_tree_model_iter_has_child (model, iter);
+
+ gtk_tree_model_get (model, iter, FC_ENABLED, &old_enabled,
+ FC_PRIORITY, &old_priority,
+ FC_INDEX, &index,
+ FC_HAVE, &old_have,
+ FC_SIZE, &size,
+ FC_PROG, &old_prog,
+ -1);
+
+ if (is_file)
{
- tr_torrent * tor = refresh_data->tor;
- const tr_info * inf = tr_torrentInfo (tor);
- const int enabled = !inf->files[index].dnd;
- const int priority = inf->files[index].priority;
- const uint64_t have = refresh_data->refresh_file_stat[index].bytesCompleted;
- const int prog = size ? (int)((100.0*have)/size) : 1;
-
- if ((priority!=old_priority) || (enabled!=old_enabled) || (have!=old_have) || (prog!=old_prog))
+ tr_torrent * tor = refresh_data->tor;
+ const tr_info * inf = tr_torrentInfo (tor);
+ const int enabled = !inf->files[index].dnd;
+ const int priority = inf->files[index].priority;
+ const uint64_t have = refresh_data->refresh_file_stat[index].bytesCompleted;
+ const int prog = size ? (int)((100.0*have)/size) : 1;
+
+ if ((priority!=old_priority) || (enabled!=old_enabled) || (have!=old_have) || (prog!=old_prog))
{
- /* Changing a value in the sort column can trigger a resort
- * which breaks this foreach () call. (See #3529)
- * As a workaround: if that's about to happen, temporarily disable
- * sorting until we finish walking the tree. */
- if (!refresh_data->resort_needed)
+ /* Changing a value in the sort column can trigger a resort
+ * which breaks this foreach () call. (See #3529)
+ * 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 =
+ 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);
+ 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);
}
}
- gtk_tree_store_set (data->store, iter, FC_PRIORITY, priority,
- FC_ENABLED, enabled,
- FC_HAVE, have,
- FC_PROG, prog,
- -1);
+ gtk_tree_store_set (data->store, iter, FC_PRIORITY, priority,
+ FC_ENABLED, enabled,
+ FC_HAVE, have,
+ FC_PROG, prog,
+ -1);
}
}
- else
+ else
{
- GtkTreeIter child;
- uint64_t sub_size = 0;
- uint64_t have = 0;
- int prog;
- int enabled = NOT_SET;
- int priority = NOT_SET;
+ GtkTreeIter child;
+ uint64_t sub_size = 0;
+ uint64_t have = 0;
+ int prog;
+ int enabled = NOT_SET;
+ int priority = NOT_SET;
- /* since gtk_tree_model_foreach () is depth-first, we can
- * get the `sub' info by walking the immediate children */
+ /* 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
+ if (gtk_tree_model_iter_children (model, &child, iter)) do
{
- int child_enabled;
- int child_priority;
- int64_t child_have, child_size;
+ int child_enabled;
+ int child_priority;
+ int64_t child_have, child_size;
- gtk_tree_model_get (model, &child, FC_SIZE, &child_size,
- FC_HAVE, &child_have,
- FC_PRIORITY, &child_priority,
- FC_ENABLED, &child_enabled,
- -1);
+ gtk_tree_model_get (model, &child, FC_SIZE, &child_size,
+ FC_HAVE, &child_have,
+ FC_PRIORITY, &child_priority,
+ FC_ENABLED, &child_enabled,
+ -1);
- if ((child_enabled != FALSE) && (child_enabled != NOT_SET))
+ if ((child_enabled != FALSE) && (child_enabled != NOT_SET))
{
sub_size += child_size;
have += child_have;
}
- if (enabled == NOT_SET)
- enabled = child_enabled;
- else if (enabled != child_enabled)
- enabled = MIXED;
+ 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;
+ if (priority == NOT_SET)
+ priority = child_priority;
+ else if (priority != child_priority)
+ priority = MIXED;
}
- while (gtk_tree_model_iter_next (model, &child));
+ while (gtk_tree_model_iter_next (model, &child));
- prog = sub_size ? (int)((100.0*have)/sub_size) : 1;
+ prog = sub_size ? (int)((100.0*have)/sub_size) : 1;
- if ((size!=sub_size) || (have!=old_have)
+ if ((size!=sub_size) || (have!=old_have)
|| (priority!=old_priority)
|| (enabled!=old_enabled)
|| (prog!=old_prog))
{
- char size_str[64];
- tr_strlsize (size_str, sub_size, sizeof size_str);
- gtk_tree_store_set (data->store, iter, FC_SIZE, sub_size,
- FC_SIZE_STR, size_str,
- FC_HAVE, have,
- FC_PRIORITY, priority,
- FC_ENABLED, enabled,
- FC_PROG, prog,
- -1);
+ char size_str[64];
+ tr_strlsize (size_str, sub_size, sizeof size_str);
+ gtk_tree_store_set (data->store, iter, FC_SIZE, sub_size,
+ FC_SIZE_STR, size_str,
+ FC_HAVE, have,
+ FC_PRIORITY, priority,
+ FC_ENABLED, enabled,
+ FC_PROG, prog,
+ -1);
}
}
- return FALSE; /* keep walking */
+ return FALSE; /* keep walking */
}
static void
GtkTreeModelForeachFunc func,
gpointer data)
{
- 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);
+ 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);
}
static void
GtkTreeModelForeachFunc func,
gpointer data)
{
- GtkTreeIter iter;
- if (gtk_tree_model_iter_nth_child (model, &iter, NULL, 0)) do
- gtr_tree_model_foreach_postorder_subtree (model, &iter, func, data);
- while (gtk_tree_model_iter_next (model, &iter));
+ GtkTreeIter iter;
+ if (gtk_tree_model_iter_nth_child (model, &iter, NULL, 0)) do
+ gtr_tree_model_foreach_postorder_subtree (model, &iter, func, data);
+ while (gtk_tree_model_iter_next (model, &iter));
}
static void
refresh (FileData * data)
{
- tr_torrent * tor = gtr_core_find_torrent (data->core, data->torrentId);
+ tr_torrent * tor = gtr_core_find_torrent (data->core, data->torrentId);
- if (tor == NULL)
+ if (tor == NULL)
{
- gtr_file_list_clear (data->top);
+ gtr_file_list_clear (data->top);
}
- else
+ else
{
- GtkSortType order;
- int sort_column_id;
- tr_file_index_t fileCount;
- struct RefreshData refresh_data;
- GtkTreeSortable * sortable = GTK_TREE_SORTABLE (data->model);
- gtk_tree_sortable_get_sort_column_id (sortable, &sort_column_id, &order);
+ GtkSortType order;
+ int sort_column_id;
+ tr_file_index_t fileCount;
+ 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);
- refresh_data.tor = tor;
- refresh_data.file_data = data;
+ refresh_data.sort_column_id = sort_column_id;
+ refresh_data.resort_needed = FALSE;
+ refresh_data.refresh_file_stat = tr_torrentFiles (tor, &fileCount);
+ refresh_data.tor = tor;
+ refresh_data.file_data = data;
- gtr_tree_model_foreach_postorder (data->model, refreshFilesForeach, &refresh_data);
+ gtr_tree_model_foreach_postorder (data->model, refreshFilesForeach, &refresh_data);
- if (refresh_data.resort_needed)
- gtk_tree_sortable_set_sort_column_id (sortable, sort_column_id, order);
+ if (refresh_data.resort_needed)
+ gtk_tree_sortable_set_sort_column_id (sortable, sort_column_id, order);
- tr_torrentFilesFree (refresh_data.refresh_file_stat, fileCount);
+ tr_torrentFilesFree (refresh_data.refresh_file_stat, fileCount);
}
}
static gboolean
refreshModel (gpointer file_data)
{
- refresh (file_data);
+ refresh (file_data);
- return G_SOURCE_CONTINUE;
+ return G_SOURCE_CONTINUE;
}
/***
struct ActiveData
{
- GtkTreeSelection * sel;
- GArray * array;
+ GtkTreeSelection * sel;
+ GArray * array;
};
static gboolean
GtkTreeIter * iter,
gpointer gdata)
{
- const gboolean is_file = !gtk_tree_model_iter_has_child (model, iter);
+ const gboolean is_file = !gtk_tree_model_iter_has_child (model, iter);
- if (is_file)
+ if (is_file)
{
- struct ActiveData * data = gdata;
-
- /* active means: if it's selected or any ancestor is selected */
+ struct ActiveData * data = gdata;
- gboolean is_active = gtk_tree_selection_iter_is_selected (data->sel, iter);
+ /* active means: if it's selected or any ancestor is selected */
+ gboolean is_active = gtk_tree_selection_iter_is_selected (data->sel, iter);
- if (!is_active)
+ if (!is_active)
{
- GtkTreeIter walk = *iter;
- GtkTreeIter parent;
- while (!is_active && gtk_tree_model_iter_parent (model, &parent, &walk))
+ GtkTreeIter walk = *iter;
+ GtkTreeIter parent;
+ while (!is_active && gtk_tree_model_iter_parent (model, &parent, &walk))
{
- is_active = gtk_tree_selection_iter_is_selected (data->sel, &parent);
- walk = parent;
+ is_active = gtk_tree_selection_iter_is_selected (data->sel, &parent);
+ walk = parent;
}
}
- if (is_active)
+ if (is_active)
{
- unsigned int i;
- gtk_tree_model_get (model, iter, FC_INDEX, &i, -1);
- g_array_append_val (data->array, i);
+ unsigned int i;
+ gtk_tree_model_get (model, iter, FC_INDEX, &i, -1);
+ g_array_append_val (data->array, i);
}
}
- return FALSE; /* keep walking */
+ return FALSE; /* keep walking */
}
static GArray*
getSelectedFilesAndDescendants (GtkTreeView * view)
{
- struct ActiveData data;
+ struct ActiveData data;
- data.sel = gtk_tree_view_get_selection (view);
- data.array = g_array_new (FALSE, FALSE, sizeof (tr_file_index_t));
- gtk_tree_model_foreach (gtk_tree_view_get_model (view),
- getSelectedFilesForeach, &data);
- return data.array;
+ data.sel = gtk_tree_view_get_selection (view);
+ data.array = g_array_new (FALSE, FALSE, sizeof (tr_file_index_t));
+ gtk_tree_model_foreach (gtk_tree_view_get_model (view),
+ getSelectedFilesForeach, &data);
+ return data.array;
}
struct SubtreeForeachData
{
- GArray * array;
- GtkTreePath * path;
+ GArray * array;
+ GtkTreePath * path;
};
static gboolean
GtkTreeIter * iter,
gpointer gdata)
{
- const gboolean is_file = !gtk_tree_model_iter_has_child (model, iter);
+ const gboolean is_file = !gtk_tree_model_iter_has_child (model, iter);
- if (is_file)
+ if (is_file)
{
- struct SubtreeForeachData * data = gdata;
+ struct SubtreeForeachData * data = gdata;
- if (!gtk_tree_path_compare (path, data->path) || gtk_tree_path_is_descendant (path, data->path))
+ if (!gtk_tree_path_compare (path, data->path) || gtk_tree_path_is_descendant (path, data->path))
{
- unsigned int i;
- gtk_tree_model_get (model, iter, FC_INDEX, &i, -1);
- g_array_append_val (data->array, i);
+ unsigned int i;
+ gtk_tree_model_get (model, iter, FC_INDEX, &i, -1);
+ g_array_append_val (data->array, i);
}
}
- return FALSE; /* keep walking */
+ 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);
+ struct SubtreeForeachData tmp;
+ tmp.array = indices;
+ tmp.path = path;
+ gtk_tree_model_foreach (gtk_tree_view_get_model (view), getSubtreeForeach, &tmp);
}
/* if `path' is a selected row, all selected rows are returned.
static GArray*
getActiveFilesForPath (GtkTreeView * view, GtkTreePath * path)
{
- GArray * indices;
- GtkTreeSelection * sel = gtk_tree_view_get_selection (view);
+ GArray * indices;
+ GtkTreeSelection * sel = gtk_tree_view_get_selection (view);
- if (gtk_tree_selection_path_is_selected (sel, path))
+ if (gtk_tree_selection_path_is_selected (sel, path))
{
- /* clicked in a selected row... use the current selection */
- indices = getSelectedFilesAndDescendants (view);
+ /* clicked in a selected row... use the current selection */
+ indices = getSelectedFilesAndDescendants (view);
}
- else
+ else
{
- /* clicked OUTSIDE of the selected row... just use the clicked row */
- indices = g_array_new (FALSE, FALSE, sizeof (tr_file_index_t));
- getSubtree (view, path, indices);
+ /* clicked OUTSIDE of the selected row... just use the clicked row */
+ indices = g_array_new (FALSE, FALSE, sizeof (tr_file_index_t));
+ getSubtree (view, path, indices);
}
- return indices;
+ return indices;
}
/***
void
gtr_file_list_clear (GtkWidget * w)
{
- gtr_file_list_set_torrent (w, -1);
+ gtr_file_list_set_torrent (w, -1);
}
struct build_data
{
- GtkWidget * w;
- tr_torrent * tor;
- GtkTreeIter * iter;
- GtkTreeStore * store;
+ GtkWidget * w;
+ tr_torrent * tor;
+ GtkTreeIter * iter;
+ GtkTreeStore * store;
};
struct row_struct
{
- uint64_t length;
- char * name;
- int index;
+ uint64_t length;
+ char * name;
+ int index;
};
static void
buildTree (GNode * node, gpointer gdata)
{
- char size_str[64];
- GtkTreeIter child_iter;
- struct build_data * build = gdata;
- struct row_struct *child_data = node->data;
- const gboolean isLeaf = node->children == NULL;
-
- 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);
- 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;
- char * name_esc = g_markup_escape_text (child_data->name, -1);
-
- tr_strlsize (size_str, child_data->length, sizeof size_str);
-
- 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_LABEL_ESC, name_esc,
- FC_SIZE, child_data->length,
- FC_SIZE_STR, size_str,
- FC_ICON, icon,
- FC_PRIORITY, priority,
- FC_ENABLED, enabled,
- -1);
-
- if (!isLeaf)
+ char size_str[64];
+ GtkTreeIter child_iter;
+ struct build_data * build = gdata;
+ struct row_struct *child_data = node->data;
+ const gboolean isLeaf = node->children == NULL;
+
+ 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);
+ 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;
+ char * name_esc = g_markup_escape_text (child_data->name, -1);
+
+ tr_strlsize (size_str, child_data->length, sizeof size_str);
+
+ 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_LABEL_ESC, name_esc,
+ FC_SIZE, child_data->length,
+ FC_SIZE_STR, size_str,
+ FC_ICON, icon,
+ FC_PRIORITY, priority,
+ FC_ENABLED, enabled,
+ -1);
+
+ if (!isLeaf)
{
- struct build_data b = *build;
- b.iter = &child_iter;
- g_node_children_foreach (node, G_TRAVERSE_ALL, buildTree, &b);
+ struct build_data b = *build;
+ b.iter = &child_iter;
+ g_node_children_foreach (node, G_TRAVERSE_ALL, buildTree, &b);
}
- g_free (name_esc);
- g_object_unref (icon);
+ g_free (name_esc);
+ g_object_unref (icon);
- /* we're done with this node */
- g_free (child_data->name);
- g_free (child_data);
+ /* 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) && !g_strcmp0 (child_data->name, name))
- break;
- child = child->next;
+ GNode * child = parent->children;
+
+ while (child)
+ {
+ const struct row_struct * child_data = child->data;
+ if ((*child_data->name == *name) && !g_strcmp0 (child_data->name, name))
+ break;
+ child = child->next;
}
- return child;
+
+ return child;
}
void
gtr_file_list_set_torrent (GtkWidget * w, int torrentId)
{
- GtkTreeStore * store;
- FileData * data = g_object_get_data (G_OBJECT (w), "file-data");
-
- /* unset the old fields */
- clearData (data);
-
- /* instantiate the model */
- store = gtk_tree_store_new (N_FILE_COLS,
- GDK_TYPE_PIXBUF, /* icon */
- G_TYPE_STRING, /* label */
- G_TYPE_STRING, /* label esc */
- G_TYPE_INT, /* prog [0..100] */
- G_TYPE_UINT, /* index */
- G_TYPE_UINT64, /* size */
- G_TYPE_STRING, /* size str */
- G_TYPE_UINT64, /* have */
- G_TYPE_INT, /* priority */
- G_TYPE_INT); /* dl enabled */
-
- data->store = store;
- data->model = GTK_TREE_MODEL (store);
- data->torrentId = torrentId;
-
- /* populate the model */
- if (torrentId > 0)
+ GtkTreeStore * store;
+ FileData * data = g_object_get_data (G_OBJECT (w), "file-data");
+
+ /* unset the old fields */
+ clearData (data);
+
+ /* instantiate the model */
+ store = gtk_tree_store_new (N_FILE_COLS,
+ GDK_TYPE_PIXBUF, /* icon */
+ G_TYPE_STRING, /* label */
+ G_TYPE_STRING, /* label esc */
+ G_TYPE_INT, /* prog [0..100] */
+ G_TYPE_UINT, /* index */
+ G_TYPE_UINT64, /* size */
+ G_TYPE_STRING, /* size str */
+ G_TYPE_UINT64, /* have */
+ G_TYPE_INT, /* priority */
+ G_TYPE_INT); /* dl enabled */
+
+ data->store = store;
+ data->model = GTK_TREE_MODEL (store);
+ data->torrentId = torrentId;
+
+ /* populate the model */
+ if (torrentId > 0)
{
- tr_torrent * tor = gtr_core_find_torrent (data->core, torrentId);
- if (tor != NULL)
+ tr_torrent * tor = gtr_core_find_torrent (data->core, torrentId);
+ if (tor != NULL)
{
- tr_file_index_t i;
- const tr_info * inf = tr_torrentInfo (tor);
- 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);
- root_data->name = g_strdup (tr_torrentName (tor));
- 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);
+ tr_file_index_t i;
+ const tr_info * inf = tr_torrentInfo (tor);
+ 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);
+ root_data->name = g_strdup (tr_torrentName (tor));
+ 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;
+ parent = node;
}
- g_strfreev (tokens);
+ g_strfreev (tokens);
}
- /* 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);
- g_free (root_data->name);
- g_free (root_data);
+ /* 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);
+ g_free (root_data->name);
+ g_free (root_data);
}
- refresh (data);
- data->timeout_tag = gdk_threads_add_timeout_seconds (SECONDARY_WINDOW_REFRESH_INTERVAL_SECONDS, refreshModel, data);
+ refresh (data);
+ data->timeout_tag = gdk_threads_add_timeout_seconds (SECONDARY_WINDOW_REFRESH_INTERVAL_SECONDS, refreshModel, data);
}
- gtk_tree_view_set_model (GTK_TREE_VIEW (data->view), data->model);
- gtk_tree_view_expand_all (GTK_TREE_VIEW (data->view));
- g_object_unref (data->model);
+ gtk_tree_view_set_model (GTK_TREE_VIEW (data->view), data->model);
+ gtk_tree_view_expand_all (GTK_TREE_VIEW (data->view));
+ g_object_unref (data->model);
}
/***
GtkTreeIter * iter,
gpointer data UNUSED)
{
- gboolean enabled;
- gtk_tree_model_get (model, iter, FC_ENABLED, &enabled, -1);
- g_object_set (renderer, "inconsistent", (enabled==MIXED),
- "active", (enabled==TRUE),
- NULL);
+ gboolean enabled;
+ gtk_tree_model_get (model, iter, FC_ENABLED, &enabled, -1);
+ g_object_set (renderer, "inconsistent", (enabled==MIXED),
+ "active", (enabled==TRUE),
+ NULL);
}
static void
GtkTreeIter * iter,
gpointer data UNUSED)
{
- int priority;
- const char * text;
- gtk_tree_model_get (model, iter, FC_PRIORITY, &priority, -1);
- switch (priority) {
- 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;
+ int priority;
+ const char * text;
+ gtk_tree_model_get (model, iter, FC_PRIORITY, &priority, -1);
+ switch (priority)
+ {
+ 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;
}
- g_object_set (renderer, "text", text, NULL);
+ g_object_set (renderer, "text", text, NULL);
}
/* build a filename from tr_torrentGetCurrentDir () + the model's FC_LABELs */
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;
+ 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;
- tr_torrent * tor = gtr_core_find_torrent (data->core, data->torrentId);
+ gboolean handled = FALSE;
+ FileData * data = gdata;
+ tr_torrent * tor = gtr_core_find_torrent (data->core, data->torrentId);
- if (tor != NULL)
+ if (tor != NULL)
{
- GtkTreeIter iter;
- GtkTreeModel * model = gtk_tree_view_get_model (view);
+ GtkTreeIter iter;
+ GtkTreeModel * model = gtk_tree_view_get_model (view);
- if (gtk_tree_model_get_iter (model, &iter, path))
+ 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);
+ 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
+ /* 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;
+ char * tmp = g_path_get_dirname (filename);
+ g_free (filename);
+ filename = tmp;
}
- while (filename && *filename && !g_file_test (filename, G_FILE_TEST_EXISTS));
+ while (filename && *filename && !g_file_test (filename, G_FILE_TEST_EXISTS));
- if ((handled = filename && *filename))
- gtr_open_file (filename);
+ if ((handled = filename && *filename))
+ gtr_open_file (filename);
}
}
- return handled;
+ return handled;
}
static gboolean
GtkTreePath * path,
FileData * data)
{
- int cid;
- tr_torrent * tor;
- gboolean handled = FALSE;
+ int cid;
+ tr_torrent * tor;
+ gboolean handled = FALSE;
- if (!col || !path)
- return FALSE;
+ if (!col || !path)
+ return FALSE;
- cid = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (col), TR_COLUMN_ID_KEY));
- tor = gtr_core_find_torrent (data->core, data->torrentId);
- if ((tor != NULL) && ((cid == FC_PRIORITY) || (cid == FC_ENABLED)))
+ cid = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (col), TR_COLUMN_ID_KEY));
+ tor = gtr_core_find_torrent (data->core, data->torrentId);
+ if ((tor != NULL) && ((cid == FC_PRIORITY) || (cid == FC_ENABLED)))
{
- GtkTreeIter iter;
- GArray * indices = getActiveFilesForPath (view, path);
- GtkTreeModel * model = data->model;
+ GtkTreeIter iter;
+ GArray * indices = getActiveFilesForPath (view, path);
+ GtkTreeModel * model = data->model;
- gtk_tree_model_get_iter (model, &iter, path);
+ gtk_tree_model_get_iter (model, &iter, path);
- if (cid == FC_PRIORITY)
+ 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;
+ 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_torrentSetFilePriorities (tor,
(tr_file_index_t *) indices->data,
(tr_file_index_t) indices->len,
priority);
}
- else
+ else
{
- int enabled;
- gtk_tree_model_get (model, &iter, FC_ENABLED, &enabled, -1);
- enabled = !enabled;
+ int enabled;
+ gtk_tree_model_get (model, &iter, FC_ENABLED, &enabled, -1);
+ enabled = !enabled;
- tr_torrentSetFileDLs (tor,
+ tr_torrentSetFileDLs (tor,
(tr_file_index_t *) indices->data,
(tr_file_index_t) indices->len,
- enabled);
+ enabled);
}
- refresh (data);
- g_array_free (indices, TRUE);
- handled = TRUE;
+ refresh (data);
+ g_array_free (indices, TRUE);
+ handled = TRUE;
}
- return handled;
+ return handled;
}
/**
GtkTreeViewColumn ** col,
GtkTreePath ** path)
{
- GtkTreeSelection * sel;
+ GtkTreeSelection * sel;
- if (gtk_tree_view_get_path_at_pos (treeview,
- event->x, event->y,
- path, col, NULL, NULL))
+ 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))
+ 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);
+ gtk_tree_selection_unselect_all (sel);
+ gtk_tree_selection_select_path (sel, *path);
}
- return TRUE;
+ return TRUE;
}
- return FALSE;
+ return FALSE;
}
static gboolean
onViewButtonPressed (GtkWidget * w, GdkEventButton * event, gpointer gdata)
{
- GtkTreeViewColumn * col;
- GtkTreePath * path = NULL;
- gboolean handled = FALSE;
- GtkTreeView * treeview = GTK_TREE_VIEW (w);
- FileData * data = gdata;
-
- if ((event->type == GDK_BUTTON_PRESS)
- && (event->button == 1)
- && ! (event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK))
- && getAndSelectEventPath (treeview, event, &col, &path))
+ GtkTreeViewColumn * col;
+ GtkTreePath * path = NULL;
+ gboolean handled = FALSE;
+ GtkTreeView * treeview = GTK_TREE_VIEW (w);
+ FileData * data = gdata;
+
+ 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);
+ handled = onViewPathToggled (treeview, col, path, data);
- if (path != NULL)
- gtk_tree_path_free (path);
+ if (path != NULL)
+ gtk_tree_path_free (path);
}
- return handled;
+ return handled;
}
struct rename_data
GtkWidget *
gtr_file_list_new (TrCore * core, int torrentId)
{
- int size;
- int width;
- GtkWidget * ret;
- GtkWidget * view;
- GtkWidget * scroll;
- GtkCellRenderer * rend;
- GtkTreeSelection * sel;
- GtkTreeViewColumn * col;
- GtkTreeView * tree_view;
- const char * title;
- PangoLayout * pango_layout;
- PangoContext * pango_context;
- PangoFontDescription * pango_font_description;
- FileData * data = g_new0 (FileData, 1);
-
- data->core = core;
-
- /* create the view */
- view = gtk_tree_view_new ();
- tree_view = GTK_TREE_VIEW (view);
- gtk_tree_view_set_rules_hint (tree_view, TRUE);
- gtk_container_set_border_width (GTK_CONTAINER (view), GUI_PAD_BIG);
- g_signal_connect (view, "button-press-event",
- G_CALLBACK (onViewButtonPressed), data);
- g_signal_connect (view, "row_activated",
- G_CALLBACK (onRowActivated), data);
- g_signal_connect (view, "button-release-event",
- G_CALLBACK (on_tree_view_button_released), NULL);
-
-
- 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));
-
- /* set up view */
- sel = gtk_tree_view_get_selection (tree_view);
- gtk_tree_selection_set_mode (sel, GTK_SELECTION_MULTIPLE);
- gtk_tree_view_expand_all (tree_view);
- gtk_tree_view_set_search_column (tree_view, FC_LABEL);
-
- /* add file column */
- col = GTK_TREE_VIEW_COLUMN (g_object_new (GTK_TYPE_TREE_VIEW_COLUMN,
- "expand", TRUE,
- "title", _("Name"),
- NULL));
- gtk_tree_view_column_set_resizable (col, TRUE);
- rend = gtk_cell_renderer_pixbuf_new ();
- gtk_tree_view_column_pack_start (col, rend, FALSE);
- gtk_tree_view_column_add_attribute (col, rend, "pixbuf", FC_ICON);
- /* add text renderer */
- rend = gtk_cell_renderer_text_new ();
- g_object_set (rend, "editable", TRUE, NULL);
- g_object_set (rend, "ellipsize", PANGO_ELLIPSIZE_END, "font-desc", pango_font_description, NULL);
- g_signal_connect (rend, "edited", (GCallback)cell_edited_callback, data);
- gtk_tree_view_column_pack_start (col, rend, TRUE);
- gtk_tree_view_column_set_attributes (col, rend, "text", FC_LABEL, NULL);
- gtk_tree_view_column_set_sort_column_id (col, FC_LABEL);
- gtk_tree_view_append_column (tree_view, col);
-
- /* 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);
-
- /* add "progress" column */
- title = _("Have");
- pango_layout = gtk_widget_create_pango_layout (view, title);
- pango_layout_get_pixel_size (pango_layout, &width, NULL);
- width += 30; /* room for the sort indicator */
- g_object_unref (G_OBJECT (pango_layout));
- rend = gtk_cell_renderer_progress_new ();
- 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);
- gtk_tree_view_column_set_sort_column_id (col, FC_PROG);
- gtk_tree_view_append_column (tree_view, col);
-
- /* add "enabled" column */
- title = _("Download");
- pango_layout = gtk_widget_create_pango_layout (view, title);
- pango_layout_get_pixel_size (pango_layout, &width, NULL);
- width += 30; /* room for the sort indicator */
- g_object_unref (G_OBJECT (pango_layout));
- rend = gtk_cell_renderer_toggle_new ();
- col = gtk_tree_view_column_new_with_attributes (title, rend, NULL);
- g_object_set_data (G_OBJECT (col), TR_COLUMN_ID_KEY,
- GINT_TO_POINTER (FC_ENABLED));
- gtk_tree_view_column_set_fixed_width (col, width);
- gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_FIXED);
- gtk_tree_view_column_set_cell_data_func (col, rend, renderDownload, NULL, NULL);
- gtk_tree_view_column_set_sort_column_id (col, FC_ENABLED);
- gtk_tree_view_append_column (tree_view, col);
-
- /* add priority column */
- title = _("Priority");
- pango_layout = gtk_widget_create_pango_layout (view, title);
- pango_layout_get_pixel_size (pango_layout, &width, NULL);
- width += 30; /* room for the sort indicator */
- g_object_unref (G_OBJECT (pango_layout));
- rend = gtk_cell_renderer_text_new ();
- g_object_set (rend, "xalign", (gfloat)0.5, "yalign", (gfloat)0.5, NULL);
- col = gtk_tree_view_column_new_with_attributes (title, rend, NULL);
- g_object_set_data (G_OBJECT (col), TR_COLUMN_ID_KEY,
- GINT_TO_POINTER (FC_PRIORITY));
- gtk_tree_view_column_set_fixed_width (col, width);
- gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_FIXED);
- gtk_tree_view_column_set_sort_column_id (col, FC_PRIORITY);
- gtk_tree_view_column_set_cell_data_func (col, rend, renderPriority, NULL, NULL);
- gtk_tree_view_append_column (tree_view, col);
-
- /* add tooltip to tree */
- gtk_tree_view_set_tooltip_column (tree_view, FC_LABEL_ESC);
-
- /* 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),
- GTK_POLICY_AUTOMATIC,
- GTK_POLICY_AUTOMATIC);
- gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll),
- GTK_SHADOW_IN);
- gtk_container_add (GTK_CONTAINER (scroll), view);
- gtk_widget_set_size_request (scroll, -1, 200);
-
- ret = scroll;
- data->view = view;
- data->top = scroll;
- g_object_set_data_full (G_OBJECT (ret), "file-data", data, freeData);
- gtr_file_list_set_torrent (ret, torrentId);
-
- pango_font_description_free (pango_font_description);
- return ret;
+ int size;
+ int width;
+ GtkWidget * ret;
+ GtkWidget * view;
+ GtkWidget * scroll;
+ GtkCellRenderer * rend;
+ GtkTreeSelection * sel;
+ GtkTreeViewColumn * col;
+ GtkTreeView * tree_view;
+ const char * title;
+ PangoLayout * pango_layout;
+ PangoContext * pango_context;
+ PangoFontDescription * pango_font_description;
+ FileData * data = g_new0 (FileData, 1);
+
+ data->core = core;
+
+ /* create the view */
+ view = gtk_tree_view_new ();
+ tree_view = GTK_TREE_VIEW (view);
+ gtk_tree_view_set_rules_hint (tree_view, TRUE);
+ gtk_container_set_border_width (GTK_CONTAINER (view), GUI_PAD_BIG);
+ g_signal_connect (view, "button-press-event",
+ G_CALLBACK (onViewButtonPressed), data);
+ g_signal_connect (view, "row_activated",
+ G_CALLBACK (onRowActivated), data);
+ g_signal_connect (view, "button-release-event",
+ G_CALLBACK (on_tree_view_button_released), NULL);
+
+
+ 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));
+
+ /* set up view */
+ sel = gtk_tree_view_get_selection (tree_view);
+ gtk_tree_selection_set_mode (sel, GTK_SELECTION_MULTIPLE);
+ gtk_tree_view_expand_all (tree_view);
+ gtk_tree_view_set_search_column (tree_view, FC_LABEL);
+
+ /* add file column */
+ col = GTK_TREE_VIEW_COLUMN (g_object_new (GTK_TYPE_TREE_VIEW_COLUMN,
+ "expand", TRUE,
+ "title", _("Name"),
+ NULL));
+ gtk_tree_view_column_set_resizable (col, TRUE);
+ rend = gtk_cell_renderer_pixbuf_new ();
+ gtk_tree_view_column_pack_start (col, rend, FALSE);
+ gtk_tree_view_column_add_attribute (col, rend, "pixbuf", FC_ICON);
+ /* add text renderer */
+ rend = gtk_cell_renderer_text_new ();
+ g_object_set (rend, "editable", TRUE, NULL);
+ g_object_set (rend, "ellipsize", PANGO_ELLIPSIZE_END, "font-desc", pango_font_description, NULL);
+ g_signal_connect (rend, "edited", (GCallback)cell_edited_callback, data);
+ gtk_tree_view_column_pack_start (col, rend, TRUE);
+ gtk_tree_view_column_set_attributes (col, rend, "text", FC_LABEL, NULL);
+ gtk_tree_view_column_set_sort_column_id (col, FC_LABEL);
+ gtk_tree_view_append_column (tree_view, col);
+
+ /* 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);
+
+ /* add "progress" column */
+ title = _("Have");
+ pango_layout = gtk_widget_create_pango_layout (view, title);
+ pango_layout_get_pixel_size (pango_layout, &width, NULL);
+ width += 30; /* room for the sort indicator */
+ g_object_unref (G_OBJECT (pango_layout));
+ rend = gtk_cell_renderer_progress_new ();
+ 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);
+ gtk_tree_view_column_set_sort_column_id (col, FC_PROG);
+ gtk_tree_view_append_column (tree_view, col);
+
+ /* add "enabled" column */
+ title = _("Download");
+ pango_layout = gtk_widget_create_pango_layout (view, title);
+ pango_layout_get_pixel_size (pango_layout, &width, NULL);
+ width += 30; /* room for the sort indicator */
+ g_object_unref (G_OBJECT (pango_layout));
+ rend = gtk_cell_renderer_toggle_new ();
+ col = gtk_tree_view_column_new_with_attributes (title, rend, NULL);
+ g_object_set_data (G_OBJECT (col), TR_COLUMN_ID_KEY,
+ GINT_TO_POINTER (FC_ENABLED));
+ gtk_tree_view_column_set_fixed_width (col, width);
+ gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_FIXED);
+ gtk_tree_view_column_set_cell_data_func (col, rend, renderDownload, NULL, NULL);
+ gtk_tree_view_column_set_sort_column_id (col, FC_ENABLED);
+ gtk_tree_view_append_column (tree_view, col);
+
+ /* add priority column */
+ title = _("Priority");
+ pango_layout = gtk_widget_create_pango_layout (view, title);
+ pango_layout_get_pixel_size (pango_layout, &width, NULL);
+ width += 30; /* room for the sort indicator */
+ g_object_unref (G_OBJECT (pango_layout));
+ rend = gtk_cell_renderer_text_new ();
+ g_object_set (rend, "xalign", (gfloat)0.5, "yalign", (gfloat)0.5, NULL);
+ col = gtk_tree_view_column_new_with_attributes (title, rend, NULL);
+ g_object_set_data (G_OBJECT (col), TR_COLUMN_ID_KEY,
+ GINT_TO_POINTER (FC_PRIORITY));
+ gtk_tree_view_column_set_fixed_width (col, width);
+ gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_FIXED);
+ gtk_tree_view_column_set_sort_column_id (col, FC_PRIORITY);
+ gtk_tree_view_column_set_cell_data_func (col, rend, renderPriority, NULL, NULL);
+ gtk_tree_view_append_column (tree_view, col);
+
+ /* add tooltip to tree */
+ gtk_tree_view_set_tooltip_column (tree_view, FC_LABEL_ESC);
+
+ /* 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),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll),
+ GTK_SHADOW_IN);
+ gtk_container_add (GTK_CONTAINER (scroll), view);
+ gtk_widget_set_size_request (scroll, -1, 200);
+
+ ret = scroll;
+ data->view = view;
+ data->top = scroll;
+ g_object_set_data_full (G_OBJECT (ret), "file-data", data, freeData);
+ gtr_file_list_set_torrent (ret, torrentId);
+
+ pango_font_description_free (pango_font_description);
+ return ret;
}
static GSList*
get_recent_destinations (void)
{
- int i;
- GSList * list = NULL;
+ int i;
+ GSList * list = NULL;
- for (i=0; i<N_RECENT; ++i)
+ for (i=0; i<N_RECENT; ++i)
{
- char key[64];
- const char * val;
- g_snprintf (key, sizeof (key), "recent-download-dir-%d", i+1);
- if ((val = gtr_pref_string_get (tr_quark_new(key,-1))))
- list = g_slist_append (list, (void*)val);
+ char key[64];
+ const char * val;
+ g_snprintf (key, sizeof (key), "recent-download-dir-%d", i+1);
+ if ((val = gtr_pref_string_get (tr_quark_new(key,-1))))
+ list = g_slist_append (list, (void*)val);
}
- return list;
+
+ return list;
}
static void
save_recent_destination (TrCore * core, const char * dir)
{
- int i;
- GSList * l;
- GSList * list = get_recent_destinations ();
-
- if (dir == NULL)
- return;
-
- /* if it was already in the list, remove it */
- if ((l = g_slist_find_custom (list, dir, (GCompareFunc)g_strcmp0)))
- list = g_slist_delete_link (list, l);
-
- /* add it to the front of the list */
- list = g_slist_prepend (list, (void*)dir);
-
- /* make local copies of the strings that aren't
- * invalidated by gtr_pref_string_set () */
- for (l=list; l; l=l->next)
- l->data = g_strdup (l->data);
-
- /* save the first N_RECENT directories */
- for (l=list, i=0; l && (i<N_RECENT); ++i, l=l->next) {
- char key[64];
- g_snprintf (key, sizeof (key), "recent-download-dir-%d", i + 1);
- gtr_pref_string_set (tr_quark_new(key,-1), l->data);
+ int i;
+ GSList * l;
+ GSList * list = get_recent_destinations ();
+
+ if (dir == NULL)
+ return;
+
+ /* if it was already in the list, remove it */
+ if ((l = g_slist_find_custom (list, dir, (GCompareFunc)g_strcmp0)))
+ list = g_slist_delete_link (list, l);
+
+ /* add it to the front of the list */
+ list = g_slist_prepend (list, (void*)dir);
+
+ /* make local copies of the strings that aren't
+ * invalidated by gtr_pref_string_set () */
+ for (l=list; l; l=l->next)
+ l->data = g_strdup (l->data);
+
+ /* save the first N_RECENT directories */
+ for (l=list, i=0; l && (i<N_RECENT); ++i, l=l->next)
+ {
+ char key[64];
+ g_snprintf (key, sizeof (key), "recent-download-dir-%d", i + 1);
+ gtr_pref_string_set (tr_quark_new(key,-1), l->data);
}
- gtr_pref_save (gtr_core_session (core));
+ gtr_pref_save (gtr_core_session (core));
- /* cleanup */
- g_slist_foreach (list, (GFunc)g_free, NULL);
- g_slist_free (list);
+ /* cleanup */
+ g_slist_foreach (list, (GFunc)g_free, NULL);
+ g_slist_free (list);
}
/****
struct OpenData
{
- TrCore * core;
- GtkWidget * file_list;
- GtkWidget * run_check;
- GtkWidget * trash_check;
- GtkWidget * priority_combo;
- GtkWidget * freespace_label;
- char * filename;
- char * downloadDir;
- tr_torrent * tor;
- tr_ctor * ctor;
+ TrCore * core;
+ GtkWidget * file_list;
+ GtkWidget * run_check;
+ GtkWidget * trash_check;
+ GtkWidget * priority_combo;
+ GtkWidget * freespace_label;
+ char * filename;
+ char * downloadDir;
+ tr_torrent * tor;
+ tr_ctor * ctor;
};
static void
removeOldTorrent (struct OpenData * o)
{
- if (o->tor)
+ if (o->tor)
{
- gtr_file_list_clear (o->file_list);
- tr_torrentRemove (o->tor, FALSE, NULL);
- o->tor = NULL;
+ gtr_file_list_clear (o->file_list);
+ tr_torrentRemove (o->tor, FALSE, NULL);
+ o->tor = NULL;
}
}
gint response,
gpointer gdata)
{
- struct OpenData * o = gdata;
+ struct OpenData * o = gdata;
- if (o->tor)
+ if (o->tor)
{
- if (response != GTK_RESPONSE_ACCEPT)
+ if (response != GTK_RESPONSE_ACCEPT)
{
- removeOldTorrent (o);
+ removeOldTorrent (o);
}
- else
+ else
{
- tr_torrentSetPriority (o->tor, gtr_priority_combo_get_value (GTK_COMBO_BOX (o->priority_combo)));
+ tr_torrentSetPriority (o->tor, gtr_priority_combo_get_value (GTK_COMBO_BOX (o->priority_combo)));
- if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (o->run_check)))
- tr_torrentStart (o->tor);
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (o->run_check)))
+ tr_torrentStart (o->tor);
- gtr_core_add_torrent (o->core, o->tor, FALSE);
+ gtr_core_add_torrent (o->core, o->tor, FALSE);
- if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (o->trash_check)))
- gtr_file_trash_or_remove (o->filename);
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (o->trash_check)))
+ gtr_file_trash_or_remove (o->filename);
- save_recent_destination (o->core, o->downloadDir);
+ save_recent_destination (o->core, o->downloadDir);
}
}
- tr_ctorFree (o->ctor);
- g_free (o->filename);
- g_free (o->downloadDir);
- g_free (o);
- gtk_widget_destroy (GTK_WIDGET (dialog));
+ tr_ctorFree (o->ctor);
+ g_free (o->filename);
+ g_free (o->downloadDir);
+ g_free (o);
+ gtk_widget_destroy (GTK_WIDGET (dialog));
}
static void
updateTorrent (struct OpenData * o)
{
- const gboolean isLocalFile = tr_ctorGetSourceFile (o->ctor) != NULL;
- gtk_widget_set_sensitive (o->trash_check, isLocalFile);
+ const gboolean isLocalFile = tr_ctorGetSourceFile (o->ctor) != NULL;
+ gtk_widget_set_sensitive (o->trash_check, isLocalFile);
- if (!o->tor)
+ if (!o->tor)
{
- gtr_file_list_clear (o->file_list);
- gtk_widget_set_sensitive (o->file_list, FALSE);
+ gtr_file_list_clear (o->file_list);
+ gtk_widget_set_sensitive (o->file_list, FALSE);
}
- else
+ else
{
- tr_torrentSetDownloadDir (o->tor, o->downloadDir);
- gtk_widget_set_sensitive (o->file_list, tr_torrentHasMetadata (o->tor));
- gtr_file_list_set_torrent (o->file_list, tr_torrentId (o->tor));
- tr_torrentVerify (o->tor, NULL, NULL);
+ tr_torrentSetDownloadDir (o->tor, o->downloadDir);
+ gtk_widget_set_sensitive (o->file_list, tr_torrentHasMetadata (o->tor));
+ gtr_file_list_set_torrent (o->file_list, tr_torrentId (o->tor));
+ tr_torrentVerify (o->tor, NULL, NULL);
}
}
static void
sourceChanged (GtkFileChooserButton * b, gpointer gdata)
{
- struct OpenData * o = gdata;
- char * filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (b));
+ struct OpenData * o = gdata;
+ char * filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (b));
- /* maybe instantiate a torrent */
- if (filename || !o->tor)
+ /* maybe instantiate a torrent */
+ if (filename || !o->tor)
{
- int err = 0;
- int new_file = 0;
- int duplicate_id = 0;
- tr_torrent * torrent;
+ int err = 0;
+ int new_file = 0;
+ int duplicate_id = 0;
+ tr_torrent * torrent;
- if (filename && (!o->filename || !tr_is_same_file (filename, o->filename)))
+ if (filename && (!o->filename || !tr_is_same_file (filename, o->filename)))
{
- g_free (o->filename);
- o->filename = g_strdup (filename);
- tr_ctorSetMetainfoFromFile (o->ctor, o->filename);
- new_file = 1;
+ g_free (o->filename);
+ o->filename = g_strdup (filename);
+ tr_ctorSetMetainfoFromFile (o->ctor, o->filename);
+ new_file = 1;
}
- tr_ctorSetDownloadDir (o->ctor, TR_FORCE, o->downloadDir);
- tr_ctorSetPaused (o->ctor, TR_FORCE, TRUE);
- tr_ctorSetDeleteSource (o->ctor, FALSE);
+ tr_ctorSetDownloadDir (o->ctor, TR_FORCE, o->downloadDir);
+ tr_ctorSetPaused (o->ctor, TR_FORCE, TRUE);
+ tr_ctorSetDeleteSource (o->ctor, FALSE);
- if ((torrent = tr_torrentNew (o->ctor, &err, &duplicate_id)))
+ if ((torrent = tr_torrentNew (o->ctor, &err, &duplicate_id)))
{
- removeOldTorrent (o);
- o->tor = torrent;
+ removeOldTorrent (o);
+ o->tor = torrent;
}
- else if (new_file)
+ else if (new_file)
{
- tr_torrent * tor;
+ tr_torrent * tor;
- if (duplicate_id)
- tor = gtr_core_find_torrent (o->core, duplicate_id);
- else
- tor = NULL;
+ if (duplicate_id)
+ tor = gtr_core_find_torrent (o->core, duplicate_id);
+ else
+ tor = NULL;
- gtr_add_torrent_error_dialog (GTK_WIDGET (b), err, tor, o->filename);
+ gtr_add_torrent_error_dialog (GTK_WIDGET (b), err, tor, o->filename);
}
- updateTorrent (o);
+ updateTorrent (o);
}
- g_free (filename);
+ g_free (filename);
}
static void
downloadDirChanged (GtkFileChooserButton * b, gpointer gdata)
{
- struct OpenData * data = gdata;
- char * fname = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (b));
+ struct OpenData * data = gdata;
+ char * fname = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (b));
- if (fname && (!data->downloadDir || !tr_is_same_file (fname, data->downloadDir)))
+ if (fname && (!data->downloadDir || !tr_is_same_file (fname, data->downloadDir)))
{
- g_free (data->downloadDir);
- data->downloadDir = g_strdup (fname);
- updateTorrent (data);
+ g_free (data->downloadDir);
+ data->downloadDir = g_strdup (fname);
+ updateTorrent (data);
- gtr_freespace_label_set_dir (data->freespace_label, data->downloadDir);
+ gtr_freespace_label_set_dir (data->freespace_label, data->downloadDir);
}
- g_free (fname);
+ g_free (fname);
}
static void
addTorrentFilters (GtkFileChooser * chooser)
{
- GtkFileFilter * filter;
+ GtkFileFilter * filter;
- filter = gtk_file_filter_new ();
- gtk_file_filter_set_name (filter, _("Torrent files"));
- gtk_file_filter_add_pattern (filter, "*.torrent");
- gtk_file_chooser_add_filter (chooser, filter);
+ filter = gtk_file_filter_new ();
+ gtk_file_filter_set_name (filter, _("Torrent files"));
+ gtk_file_filter_add_pattern (filter, "*.torrent");
+ gtk_file_chooser_add_filter (chooser, filter);
- filter = gtk_file_filter_new ();
- gtk_file_filter_set_name (filter, _("All files"));
- gtk_file_filter_add_pattern (filter, "*");
- gtk_file_chooser_add_filter (chooser, filter);
+ filter = gtk_file_filter_new ();
+ gtk_file_filter_set_name (filter, _("All files"));
+ gtk_file_filter_add_pattern (filter, "*");
+ gtk_file_chooser_add_filter (chooser, filter);
}
/****
GtkWidget*
gtr_torrent_options_dialog_new (GtkWindow * parent, TrCore * core, tr_ctor * ctor)
{
- const char * str;
- GtkWidget * w;
- GtkWidget * d;
- GtkGrid * grid;
- int row;
- GtkWidget * l;
- GtkWidget * source_chooser;
- struct OpenData * data;
- bool flag;
- GSList * list;
- GSList * walk;
-
- /* make the dialog */
- d = gtk_dialog_new_with_buttons (_("Torrent Options"), parent,
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
- NULL);
- gtk_dialog_set_default_response (GTK_DIALOG (d),
- GTK_RESPONSE_ACCEPT);
- gtk_dialog_set_alternative_button_order (GTK_DIALOG (d),
- GTK_RESPONSE_ACCEPT,
- GTK_RESPONSE_CANCEL,
- -1);
-
- if (tr_ctorGetDownloadDir (ctor, TR_FORCE, &str))
- g_assert_not_reached ();
- g_assert (str);
-
- data = g_new0 (struct OpenData, 1);
- data->core = core;
- data->ctor = ctor;
- data->filename = g_strdup (tr_ctorGetSourceFile (ctor));
- data->downloadDir = g_strdup (str);
- data->file_list = gtr_file_list_new (core, 0);
- str = _("Mo_ve .torrent file to the trash");
- data->trash_check = gtk_check_button_new_with_mnemonic (str);
- str = _("_Start when added");
- data->run_check = gtk_check_button_new_with_mnemonic (str);
-
- w = data->priority_combo = gtr_priority_combo_new ();
- gtr_priority_combo_set_value (GTK_COMBO_BOX (w), TR_PRI_NORMAL);
-
- g_signal_connect (G_OBJECT (d), "response",
- G_CALLBACK (addResponseCB), data);
-
- row = 0;
- grid = GTK_GRID (gtk_grid_new ());
- gtk_container_set_border_width (GTK_CONTAINER (grid), GUI_PAD_BIG);
- gtk_grid_set_row_spacing (grid, GUI_PAD);
- gtk_grid_set_column_spacing (grid, GUI_PAD_BIG);
-
- // "torrent file" row
- l = gtk_label_new_with_mnemonic (_("_Torrent file:"));
- gtk_misc_set_alignment (GTK_MISC (l), 0.0f, 0.5f);
- gtk_grid_attach (grid, l, 0, row, 1, 1);
- w = gtk_file_chooser_button_new (_("Select Source File"),
- GTK_FILE_CHOOSER_ACTION_OPEN);
- source_chooser = w;
- gtk_widget_set_hexpand (w, TRUE);
- gtk_grid_attach_next_to (grid, w, l, GTK_POS_RIGHT, 1, 1);
- gtk_label_set_mnemonic_widget (GTK_LABEL (l), w);
- addTorrentFilters (GTK_FILE_CHOOSER (w));
- g_signal_connect (w, "selection-changed",
- G_CALLBACK (sourceChanged), data);
-
- // "destination folder" row
- row++;
- l = gtk_label_new_with_mnemonic (_("_Destination folder:"));
- gtk_misc_set_alignment (GTK_MISC (l), 0.0f, 0.5f);
- gtk_grid_attach (grid, l, 0, row, 1, 1);
- w = gtk_file_chooser_button_new (_("Select Destination Folder"),
- GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
- if (!gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (w),
- data->downloadDir))
- g_warning ("couldn't select '%s'", data->downloadDir);
- list = get_recent_destinations ();
- for (walk = list; walk; walk = walk->next)
- gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (w), walk->data, NULL);
- g_slist_free (list);
- gtk_grid_attach_next_to (grid, w, l, GTK_POS_RIGHT, 1, 1);
- gtk_label_set_mnemonic_widget (GTK_LABEL (l), w);
- g_signal_connect (w, "selection-changed",
- G_CALLBACK (downloadDirChanged), data);
-
- row++;
- l = data->freespace_label = gtr_freespace_label_new (core, data->downloadDir);
- gtk_widget_set_margin_bottom (l, GUI_PAD_BIG);
- gtk_misc_set_alignment (GTK_MISC (l), 1.0f, 0.5f);
- gtk_grid_attach (grid, l, 0, row, 2, 1);
-
-
- // file list row
- row++;
- w = data->file_list;
- gtk_widget_set_vexpand (w, TRUE);
- gtk_widget_set_size_request (w, 466u, 300u);
- gtk_grid_attach (grid, w, 0, row, 2, 1);
-
- // torrent priority row
- row++;
- l = gtk_label_new_with_mnemonic (_("Torrent _priority:"));
- gtk_misc_set_alignment (GTK_MISC (l), 0.0f, 0.5f);
- gtk_grid_attach (grid, l, 0, row, 1, 1);
- w = data->priority_combo;
- gtk_label_set_mnemonic_widget (GTK_LABEL (l), w);
- gtk_grid_attach_next_to (grid, w, l, GTK_POS_RIGHT, 1, 1);
-
- // torrent priority row
- row++;
- w = data->run_check;
- if (tr_ctorGetPaused (ctor, TR_FORCE, &flag))
- g_assert_not_reached ();
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), !flag);
- gtk_grid_attach (grid, w, 0, row, 2, 1);
-
- // "trash .torrent file" row
- row++;
- w = data->trash_check;
- if (tr_ctorGetDeleteSource (ctor, &flag))
- g_assert_not_reached ();
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), flag);
- gtk_grid_attach (grid, w, 0, row, 2, 1);
-
- /* trigger sourceChanged, either directly or indirectly,
- * so that it creates the tor/gtor objects */
- w = source_chooser;
- if (data->filename)
- gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (w), data->filename);
- else
- sourceChanged (GTK_FILE_CHOOSER_BUTTON (w), data);
-
- gtr_dialog_set_content (GTK_DIALOG (d), GTK_WIDGET (grid));
- w = gtk_dialog_get_widget_for_response (GTK_DIALOG (d), GTK_RESPONSE_ACCEPT);
- gtk_widget_grab_focus (w);
- return d;
+ const char * str;
+ GtkWidget * w;
+ GtkWidget * d;
+ GtkGrid * grid;
+ int row;
+ GtkWidget * l;
+ GtkWidget * source_chooser;
+ struct OpenData * data;
+ bool flag;
+ GSList * list;
+ GSList * walk;
+
+ /* make the dialog */
+ d = gtk_dialog_new_with_buttons (_("Torrent Options"), parent,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ NULL);
+ gtk_dialog_set_default_response (GTK_DIALOG (d),
+ GTK_RESPONSE_ACCEPT);
+ gtk_dialog_set_alternative_button_order (GTK_DIALOG (d),
+ GTK_RESPONSE_ACCEPT,
+ GTK_RESPONSE_CANCEL,
+ -1);
+
+ if (tr_ctorGetDownloadDir (ctor, TR_FORCE, &str))
+ g_assert_not_reached ();
+ g_assert (str);
+
+ data = g_new0 (struct OpenData, 1);
+ data->core = core;
+ data->ctor = ctor;
+ data->filename = g_strdup (tr_ctorGetSourceFile (ctor));
+ data->downloadDir = g_strdup (str);
+ data->file_list = gtr_file_list_new (core, 0);
+ str = _("Mo_ve .torrent file to the trash");
+ data->trash_check = gtk_check_button_new_with_mnemonic (str);
+ str = _("_Start when added");
+ data->run_check = gtk_check_button_new_with_mnemonic (str);
+
+ w = data->priority_combo = gtr_priority_combo_new ();
+ gtr_priority_combo_set_value (GTK_COMBO_BOX (w), TR_PRI_NORMAL);
+
+ g_signal_connect (G_OBJECT (d), "response",
+ G_CALLBACK (addResponseCB), data);
+
+ row = 0;
+ grid = GTK_GRID (gtk_grid_new ());
+ gtk_container_set_border_width (GTK_CONTAINER (grid), GUI_PAD_BIG);
+ gtk_grid_set_row_spacing (grid, GUI_PAD);
+ gtk_grid_set_column_spacing (grid, GUI_PAD_BIG);
+
+ /* "torrent file" row */
+ l = gtk_label_new_with_mnemonic (_("_Torrent file:"));
+ gtk_misc_set_alignment (GTK_MISC (l), 0.0f, 0.5f);
+ gtk_grid_attach (grid, l, 0, row, 1, 1);
+ w = gtk_file_chooser_button_new (_("Select Source File"),
+ GTK_FILE_CHOOSER_ACTION_OPEN);
+ source_chooser = w;
+ gtk_widget_set_hexpand (w, TRUE);
+ gtk_grid_attach_next_to (grid, w, l, GTK_POS_RIGHT, 1, 1);
+ gtk_label_set_mnemonic_widget (GTK_LABEL (l), w);
+ addTorrentFilters (GTK_FILE_CHOOSER (w));
+ g_signal_connect (w, "selection-changed",
+ G_CALLBACK (sourceChanged), data);
+
+ /* "destination folder" row */
+ row++;
+ l = gtk_label_new_with_mnemonic (_("_Destination folder:"));
+ gtk_misc_set_alignment (GTK_MISC (l), 0.0f, 0.5f);
+ gtk_grid_attach (grid, l, 0, row, 1, 1);
+ w = gtk_file_chooser_button_new (_("Select Destination Folder"),
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
+ if (!gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (w),
+ data->downloadDir))
+ g_warning ("couldn't select '%s'", data->downloadDir);
+ list = get_recent_destinations ();
+ for (walk = list; walk; walk = walk->next)
+ gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (w), walk->data, NULL);
+ g_slist_free (list);
+ gtk_grid_attach_next_to (grid, w, l, GTK_POS_RIGHT, 1, 1);
+ gtk_label_set_mnemonic_widget (GTK_LABEL (l), w);
+ g_signal_connect (w, "selection-changed",
+ G_CALLBACK (downloadDirChanged), data);
+
+ row++;
+ l = data->freespace_label = gtr_freespace_label_new (core, data->downloadDir);
+ gtk_widget_set_margin_bottom (l, GUI_PAD_BIG);
+ gtk_misc_set_alignment (GTK_MISC (l), 1.0f, 0.5f);
+ gtk_grid_attach (grid, l, 0, row, 2, 1);
+
+
+ /* file list row */
+ row++;
+ w = data->file_list;
+ gtk_widget_set_vexpand (w, TRUE);
+ gtk_widget_set_size_request (w, 466u, 300u);
+ gtk_grid_attach (grid, w, 0, row, 2, 1);
+
+ /* torrent priority row */
+ row++;
+ l = gtk_label_new_with_mnemonic (_("Torrent _priority:"));
+ gtk_misc_set_alignment (GTK_MISC (l), 0.0f, 0.5f);
+ gtk_grid_attach (grid, l, 0, row, 1, 1);
+ w = data->priority_combo;
+ gtk_label_set_mnemonic_widget (GTK_LABEL (l), w);
+ gtk_grid_attach_next_to (grid, w, l, GTK_POS_RIGHT, 1, 1);
+
+ /* torrent priority row */
+ row++;
+ w = data->run_check;
+ if (tr_ctorGetPaused (ctor, TR_FORCE, &flag))
+ g_assert_not_reached ();
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), !flag);
+ gtk_grid_attach (grid, w, 0, row, 2, 1);
+
+ /* "trash .torrent file" row */
+ row++;
+ w = data->trash_check;
+ if (tr_ctorGetDeleteSource (ctor, &flag))
+ g_assert_not_reached ();
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), flag);
+ gtk_grid_attach (grid, w, 0, row, 2, 1);
+
+ /* trigger sourceChanged, either directly or indirectly,
+ * so that it creates the tor/gtor objects */
+ w = source_chooser;
+ if (data->filename)
+ gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (w), data->filename);
+ else
+ sourceChanged (GTK_FILE_CHOOSER_BUTTON (w), data);
+
+ gtr_dialog_set_content (GTK_DIALOG (d), GTK_WIDGET (grid));
+ w = gtk_dialog_get_widget_for_response (GTK_DIALOG (d), GTK_RESPONSE_ACCEPT);
+ gtk_widget_grab_focus (w);
+ return d;
}
/****
static void
onOpenDialogResponse (GtkDialog * dialog, int response, gpointer core)
{
- char * folder;
+ char * folder;
- /* remember this folder the next time we use this dialog */
- folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog));
- gtr_pref_string_set (TR_KEY_open_dialog_dir, folder);
- g_free (folder);
+ /* remember this folder the next time we use this dialog */
+ folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog));
+ gtr_pref_string_set (TR_KEY_open_dialog_dir, folder);
+ g_free (folder);
- if (response == GTK_RESPONSE_ACCEPT)
+ if (response == GTK_RESPONSE_ACCEPT)
{
- GtkFileChooser * chooser = GTK_FILE_CHOOSER (dialog);
- GtkWidget * w = gtk_file_chooser_get_extra_widget (chooser);
- GtkToggleButton * tb = GTK_TOGGLE_BUTTON (w);
- const gboolean do_start = gtr_pref_flag_get (TR_KEY_start_added_torrents);
- const gboolean do_prompt = gtk_toggle_button_get_active (tb);
- const gboolean do_notify = FALSE;
- GSList * files = gtk_file_chooser_get_files (chooser);
-
- gtr_core_add_files (core, files, do_start, do_prompt, do_notify);
- g_slist_foreach (files, (GFunc)g_object_unref, NULL);
- g_slist_free (files);
+ GtkFileChooser * chooser = GTK_FILE_CHOOSER (dialog);
+ GtkWidget * w = gtk_file_chooser_get_extra_widget (chooser);
+ GtkToggleButton * tb = GTK_TOGGLE_BUTTON (w);
+ const gboolean do_start = gtr_pref_flag_get (TR_KEY_start_added_torrents);
+ const gboolean do_prompt = gtk_toggle_button_get_active (tb);
+ const gboolean do_notify = FALSE;
+ GSList * files = gtk_file_chooser_get_files (chooser);
+
+ gtr_core_add_files (core, files, do_start, do_prompt, do_notify);
+ g_slist_foreach (files, (GFunc)g_object_unref, NULL);
+ g_slist_free (files);
}
- gtk_widget_destroy (GTK_WIDGET (dialog));
+ gtk_widget_destroy (GTK_WIDGET (dialog));
}
GtkWidget*
gtr_torrent_open_from_file_dialog_new (GtkWindow * parent, TrCore * core)
{
- GtkWidget * w;
- GtkWidget * c;
- const char * folder;
-
- w = gtk_file_chooser_dialog_new (_("Open a Torrent"), parent,
- GTK_FILE_CHOOSER_ACTION_OPEN,
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
- NULL);
- gtk_dialog_set_alternative_button_order (GTK_DIALOG (w),
- GTK_RESPONSE_ACCEPT,
- GTK_RESPONSE_CANCEL,
- -1);
- gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (w), TRUE);
- addTorrentFilters (GTK_FILE_CHOOSER (w));
- g_signal_connect (w, "response", G_CALLBACK (onOpenDialogResponse), core);
-
- if ((folder = gtr_pref_string_get (TR_KEY_open_dialog_dir)))
- gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (w), folder);
-
- c = gtk_check_button_new_with_mnemonic (_("Show _options dialog"));
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (c),
- gtr_pref_flag_get (TR_KEY_show_options_window));
- gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (w), c);
- gtk_widget_show (c);
-
- return w;
+ GtkWidget * w;
+ GtkWidget * c;
+ const char * folder;
+
+ w = gtk_file_chooser_dialog_new (_("Open a Torrent"), parent,
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ NULL);
+ gtk_dialog_set_alternative_button_order (GTK_DIALOG (w),
+ GTK_RESPONSE_ACCEPT,
+ GTK_RESPONSE_CANCEL,
+ -1);
+ gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (w), TRUE);
+ addTorrentFilters (GTK_FILE_CHOOSER (w));
+ g_signal_connect (w, "response", G_CALLBACK (onOpenDialogResponse), core);
+
+ if ((folder = gtr_pref_string_get (TR_KEY_open_dialog_dir)))
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (w), folder);
+
+ c = gtk_check_button_new_with_mnemonic (_("Show _options dialog"));
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (c),
+ gtr_pref_flag_get (TR_KEY_show_options_window));
+ gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (w), c);
+ gtk_widget_show (c);
+
+ return w;
}
/***
static void
onOpenURLResponse (GtkDialog * dialog, int response, gpointer user_data)
{
- bool handled = false;
+ bool handled = false;
- if (response == GTK_RESPONSE_ACCEPT)
+ if (response == GTK_RESPONSE_ACCEPT)
{
- GtkWidget * e = GTK_WIDGET (g_object_get_data (G_OBJECT (dialog), "url-entry"));
- char * url = g_strdup (gtk_entry_get_text (GTK_ENTRY (e)));
- g_strstrip (url);
-
- if (url) {
- handled = gtr_core_add_from_url (user_data, url);
- if (!handled)
- gtr_unrecognized_url_dialog (GTK_WIDGET (dialog), url);
- g_free (url);
+ GtkWidget * e = GTK_WIDGET (g_object_get_data (G_OBJECT (dialog), "url-entry"));
+ char * url = g_strdup (gtk_entry_get_text (GTK_ENTRY (e)));
+ g_strstrip (url);
+
+ if (url)
+ {
+ handled = gtr_core_add_from_url (user_data, url);
+ if (!handled)
+ gtr_unrecognized_url_dialog (GTK_WIDGET (dialog), url);
+ g_free (url);
}
}
- else if (response == GTK_RESPONSE_CANCEL)
+ else if (response == GTK_RESPONSE_CANCEL)
{
- handled = TRUE;
+ handled = TRUE;
}
- if (handled)
- gtk_widget_destroy (GTK_WIDGET (dialog));
+ if (handled)
+ gtk_widget_destroy (GTK_WIDGET (dialog));
}
GtkWidget*
gtr_torrent_open_from_url_dialog_new (GtkWindow * parent, TrCore * core)
{
- guint row;
- GtkWidget * e;
- GtkWidget * t;
- GtkWidget * w;
-
- w = gtk_dialog_new_with_buttons (_("Open URL"), parent,
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
- NULL);
- gtk_dialog_set_alternative_button_order (GTK_DIALOG (w),
- GTK_RESPONSE_ACCEPT,
- GTK_RESPONSE_CANCEL,
- -1);
- g_signal_connect (w, "response", G_CALLBACK (onOpenURLResponse), core);
-
- row = 0;
- t = hig_workarea_create ();
- hig_workarea_add_section_title (t, &row, _("Open torrent from URL"));
- e = gtk_entry_new ();
- gtk_widget_set_size_request (e, 400, -1);
- gtr_paste_clipboard_url_into_entry (e);
- g_object_set_data (G_OBJECT (w), "url-entry", e);
- hig_workarea_add_row (t, &row, _("_URL"), e, NULL);
-
- gtr_dialog_set_content (GTK_DIALOG (w), t);
-
- if (gtk_entry_get_text_length (GTK_ENTRY (e)) == 0)
- gtk_widget_grab_focus (e);
- else
- gtk_widget_grab_focus (gtk_dialog_get_widget_for_response (GTK_DIALOG (w), GTK_RESPONSE_ACCEPT));
-
- return w;
+ guint row;
+ GtkWidget * e;
+ GtkWidget * t;
+ GtkWidget * w;
+
+ w = gtk_dialog_new_with_buttons (_("Open URL"), parent,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ NULL);
+ gtk_dialog_set_alternative_button_order (GTK_DIALOG (w),
+ GTK_RESPONSE_ACCEPT,
+ GTK_RESPONSE_CANCEL,
+ -1);
+ g_signal_connect (w, "response", G_CALLBACK (onOpenURLResponse), core);
+
+ row = 0;
+ t = hig_workarea_create ();
+ hig_workarea_add_section_title (t, &row, _("Open torrent from URL"));
+ e = gtk_entry_new ();
+ gtk_widget_set_size_request (e, 400, -1);
+ gtr_paste_clipboard_url_into_entry (e);
+ g_object_set_data (G_OBJECT (w), "url-entry", e);
+ hig_workarea_add_row (t, &row, _("_URL"), e, NULL);
+
+ gtr_dialog_set_content (GTK_DIALOG (w), t);
+
+ if (gtk_entry_get_text_length (GTK_ENTRY (e)) == 0)
+ gtk_widget_grab_focus (e);
+ else
+ gtk_widget_grab_focus (gtk_dialog_get_widget_for_response (GTK_DIALOG (w), GTK_RESPONSE_ACCEPT));
+
+ return w;
}