[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r18887 - in gnunet-gtk: contrib src/fs
From: |
gnunet |
Subject: |
[GNUnet-SVN] r18887 - in gnunet-gtk: contrib src/fs |
Date: |
Sun, 1 Jan 2012 21:09:25 +0100 |
Author: grothoff
Date: 2012-01-01 21:09:25 +0100 (Sun, 01 Jan 2012)
New Revision: 18887
Modified:
gnunet-gtk/contrib/gnunet_fs_gtk_search_tab.glade
gnunet-gtk/src/fs/gnunet-fs-gtk-download.h
gnunet-gtk/src/fs/gnunet-fs-gtk-event_handler.c
Log:
-LRN: Completed column, delayed updates
Modified: gnunet-gtk/contrib/gnunet_fs_gtk_search_tab.glade
===================================================================
--- gnunet-gtk/contrib/gnunet_fs_gtk_search_tab.glade 2012-01-01 20:02:23 UTC
(rev 18886)
+++ gnunet-gtk/contrib/gnunet_fs_gtk_search_tab.glade 2012-01-01 20:09:25 UTC
(rev 18887)
@@ -32,6 +32,8 @@
<column type="guint"/>
<!-- column-name availability_rank -->
<column type="gint"/>
+ <!-- column-name completed -->
+ <column type="guint64"/>
</columns>
</object>
<object class="GtkWindow" id="_search_result_frame_window">
@@ -56,11 +58,11 @@
<property name="can_focus">True</property>
<property
name="model">GNUNET_GTK_file_sharing_result_tree_store</property>
<property name="reorderable">True</property>
+ <property name="search_column">6</property>
<property name="enable_grid_lines">horizontal</property>
<property name="enable_tree_lines">True</property>
<child>
<object class="GtkTreeViewColumn"
id="search_result_description_column">
- <property name="resizable">True</property>
<property name="sizing">autosize</property>
<property name="title"
translatable="yes">Description</property>
<property name="expand">True</property>
@@ -112,6 +114,22 @@
</object>
</child>
<child>
+ <object class="GtkTreeViewColumn"
id="search_result_completed_column">
+ <property name="sizing">autosize</property>
+ <property name="title" translatable="yes">Completed
(bytes)</property>
+ <property name="reorderable">True</property>
+ <property name="sort_indicator">True</property>
+ <property name="sort_column_id">14</property>
+ <child>
+ <object class="GtkCellRendererText"
id="search_result_completed_renderer"/>
+ <attributes>
+ <attribute name="cell-background">8</attribute>
+ <attribute name="text">14</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
+ <child>
<object class="GtkTreeViewColumn" id="search_result_size_column">
<property name="sizing">autosize</property>
<property name="title" translatable="yes">Size</property>
@@ -130,6 +148,7 @@
</child>
<child>
<object class="GtkTreeViewColumn"
id="search_result_progress_column">
+ <property name="sizing">autosize</property>
<property name="title" translatable="yes">Progress</property>
<property name="clickable">True</property>
<property name="reorderable">True</property>
@@ -151,7 +170,6 @@
<property name="title">#</property>
<property name="reorderable">True</property>
<property name="sort_indicator">True</property>
- <property name="sort_order">descending</property>
<property name="sort_column_id">11</property>
<child>
<object class="GtkCellRendererText"
id="search_result_applicability_renderer"/>
Modified: gnunet-gtk/src/fs/gnunet-fs-gtk-download.h
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk-download.h 2012-01-01 20:02:23 UTC (rev
18886)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk-download.h 2012-01-01 20:09:25 UTC (rev
18887)
@@ -73,6 +73,12 @@
* Desired (default) anonymity level.
*/
int anonymity;
+
+ /**
+ * Tab where this download is currently on display.
+ * (this is the same as sr->tab, but sr is opaque here).
+ */
+ struct SearchTab *tab;
};
Modified: gnunet-gtk/src/fs/gnunet-fs-gtk-event_handler.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk-event_handler.c 2012-01-01 20:02:23 UTC
(rev 18886)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk-event_handler.c 2012-01-01 20:09:25 UTC
(rev 18887)
@@ -105,10 +105,36 @@
};
+struct StartDownloadContext
+{
+ struct SearchTab *tab;
+ gboolean recursive;
+};
static struct PublishTab *publish_tab;
+struct UpdateSearchItem
+{
+ struct UpdateSearchItem *prev;
+ struct UpdateSearchItem *next;
+ struct DownloadEntry *de;
+ uint64_t size;
+ uint64_t completed;
+ void *block_data;
+ uint64_t offset;
+ uint64_t block_size;
+ unsigned int depth;
+};
+GNUNET_SCHEDULER_TaskIdentifier update_progress_task =
GNUNET_SCHEDULER_NO_TASK;
+
+
+static void
+closure_notify_free (gpointer data, GClosure *closure)
+{
+ GNUNET_free (data);
+}
+
static struct DownloadEntry *
change_download_colour (struct DownloadEntry *de, const char *colour)
{
@@ -167,23 +193,26 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping download DE=%p, %s\n", de,
is_suspend ? "temporarily" : "permanently");
path = gtk_tree_row_reference_get_path (de->rr);
tm = gtk_tree_row_reference_get_model (de->rr);
- if (TRUE != gtk_tree_model_get_iter (tm, &iter, path))
- GNUNET_break (0);
- else
+ if (path != NULL)
{
- gtk_tree_model_get (tm, &iter, 9, &search_result, -1);
- /*Always fails on downloads started by Download URI */
- /*GNUNET_assert (search_result->download == de); */
- search_result->download = NULL;
- if (NULL == search_result->result)
+ if (TRUE != gtk_tree_model_get_iter (tm, &iter, path))
+ GNUNET_break (0);
+ else
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing it from the tree\n");
- (void) gtk_tree_store_remove (GTK_TREE_STORE (tm), &iter);
+ gtk_tree_model_get (tm, &iter, 9, &search_result, -1);
+ /*Always fails on downloads started by Download URI */
+ /*GNUNET_assert (search_result->download == de); */
+ search_result->download = NULL;
+ if (NULL == search_result->result)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing it from the tree\n");
+ (void) gtk_tree_store_remove (GTK_TREE_STORE (tm), &iter);
+ }
+ else
+ change_download_colour (de, "white");
}
- else
- change_download_colour (de, "white");
+ gtk_tree_path_free (path);
}
- gtk_tree_path_free (path);
gtk_tree_row_reference_free (de->rr);
GNUNET_FS_uri_destroy (de->uri);
GNUNET_CONTAINER_meta_data_destroy (de->meta);
@@ -282,48 +311,120 @@
}
+static void
+mark_download_progress_delayed (struct DownloadEntry *de, uint64_t size,
+ uint64_t completed, const void *block_data,
+ uint64_t offset, uint64_t block_size, unsigned int depth)
+{
+ GtkTreeIter iter;
+ GtkTreePath *path;
+
+ do
+ {
+ path = gtk_tree_row_reference_get_path (de->rr);
+ if (TRUE != gtk_tree_model_get_iter (GTK_TREE_MODEL (de->ts), &iter, path))
+ {
+ GNUNET_break (0);
+ gtk_tree_path_free (path);
+ break;
+ }
+ gtk_tree_path_free (path);
+ gtk_tree_store_set (de->ts, &iter, 4,
+ (guint) ((size >
+ 0) ? (100 * completed /
+ size) : 100) /* progress */ ,
+ 14, completed, -1);
+ if ((depth == 0) && (block_size > 0) &&
+ (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (de->meta)))
+ {
+ struct AddDirectoryEntryContext ade;
+ ade.de = de;
+ ade.prr = de->rr;
+ ade.check_duplicates = GNUNET_NO;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "It is a directory, list its
contents\n");
+ if (GNUNET_SYSERR ==
+ GNUNET_FS_directory_list_contents ((size_t) block_size, block_data,
+ offset, &add_directory_entry,
&ade))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Metadata wrongly claims that this is a GNUnet
directory!\n"));
+ }
+ }
+ } while (0);
+}
+
+
+void
+GNUNET_FS_GTK_update_download_progress (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct SearchTab *st;
+ GtkTreeStore *ts;
+ struct UpdateSearchItem *usi_head;
+ struct UpdateSearchItem *usi_tail;
+ struct UpdateSearchItem *usi;
+ struct UpdateSearchItem *next;
+
+ update_progress_task = GNUNET_SCHEDULER_NO_TASK;
+ for (st = search_tab_head; st; st = st->next)
+ {
+ ts = st->ts;
+ usi_head = g_object_get_data (G_OBJECT (ts), "usi_head");
+ usi_tail = g_object_get_data (G_OBJECT (ts), "usi_tail");
+ for (usi = usi_head; NULL != usi; usi = next)
+ {
+ next = usi->next;
+ mark_download_progress_delayed (usi->de, usi->size,
+ usi->completed, usi->block_data, usi->offset, usi->block_size,
+ usi->depth);
+ GNUNET_CONTAINER_DLL_remove (usi_head, usi_tail, usi);
+ GNUNET_free_non_null (usi->block_data);
+ GNUNET_free (usi);
+ }
+ g_object_set_data (G_OBJECT (ts), "usi_head", usi_head);
+ g_object_set_data (G_OBJECT (ts), "usi_tail", usi_tail);
+ }
+ if (!(tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+ update_progress_task = GNUNET_SCHEDULER_add_delayed (
+ GNUNET_TIME_UNIT_SECONDS,
+ GNUNET_FS_GTK_update_download_progress, NULL);
+}
+
+
static struct DownloadEntry *
mark_download_progress (struct DownloadEntry *de, uint64_t size,
uint64_t completed, const void *block_data,
uint64_t offset, uint64_t block_size,
unsigned int depth)
{
- struct AddDirectoryEntryContext ade;
- GtkTreeIter iter;
- GtkTreePath *path;
+ struct UpdateSearchItem *usi_head;
+ struct UpdateSearchItem *usi_tail;
+ struct UpdateSearchItem *usi_new;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Marking download progress for DE=%p, %llu/%llu, address@hidden
depth=%u\n",
de, completed, size, block_size, offset, depth);
- path = gtk_tree_row_reference_get_path (de->rr);
- if (TRUE != gtk_tree_model_get_iter (GTK_TREE_MODEL (de->ts), &iter, path))
- {
- GNUNET_break (0);
- gtk_tree_path_free (path);
- return de;
- }
- gtk_tree_path_free (path);
- gtk_tree_store_set (de->ts, &iter, 4,
- (guint) ((size >
- 0) ? (100 * completed /
- size) : 100) /* progress */ ,
- -1);
- if ((depth == 0) && (block_size > 0) &&
- (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (de->meta)))
- {
- ade.de = de;
- ade.prr = de->rr;
- ade.check_duplicates = GNUNET_NO;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "It is a directory, list its
contents\n");
- if (GNUNET_SYSERR ==
- GNUNET_FS_directory_list_contents ((size_t) block_size, block_data,
- offset, &add_directory_entry, &ade))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _
- ("Metadata wrongly claims that this is a GNUnet
directory!\n"));
- }
- }
+
+ usi_head = g_object_get_data (G_OBJECT (de->ts), "usi_head");
+ usi_tail = g_object_get_data (G_OBJECT (de->ts), "usi_tail");
+ usi_new = GNUNET_malloc (sizeof (struct UpdateSearchItem));
+ usi_new->de = de;
+ usi_new->size = size;
+ usi_new->completed = completed;
+ usi_new->block_data = GNUNET_malloc (block_size);
+ memcpy (usi_new->block_data, block_data, block_size);
+ usi_new->offset = offset;
+ usi_new->block_size = block_size;
+ usi_new->depth = depth;
+ GNUNET_CONTAINER_DLL_insert_tail (usi_head, usi_tail, usi_new);
+ g_object_set_data (G_OBJECT (de->ts), "usi_head", usi_head);
+ g_object_set_data (G_OBJECT (de->ts), "usi_tail", usi_tail);
+
+ if (update_progress_task == GNUNET_SCHEDULER_NO_TASK)
+ update_progress_task = GNUNET_SCHEDULER_add_delayed (
+ GNUNET_TIME_UNIT_SECONDS,
+ GNUNET_FS_GTK_update_download_progress, NULL);
return de;
}
@@ -425,7 +526,7 @@
GtkTreePath *path;
struct GNUNET_CONTAINER_MetaData *meta;
struct GNUNET_FS_Uri *uri;
- guint64 filesize;
+ guint64 filesize, completed;
GdkPixbuf *preview;
guint percent_progress;
guint percent_availability;
@@ -447,7 +548,8 @@
&percent_availability, 6, &filename, 7,
&uri_as_string, 8, &status_colour, 9, &search_result,
10, &mimetype, 11, &applicability_rank, 12,
- &availability_certainty, 13, &availability_rank, -1);
+ &availability_certainty, 13, &availability_rank, 14,
+ &completed, -1);
gtk_tree_store_insert_with_values (GTK_TREE_STORE (dst_model),
&dst_child,
dst_iter, G_MAXINT, 0, meta, 1, uri,
2,
filesize, 3, preview, 4,
@@ -457,7 +559,7 @@
search_result, 10, mimetype, 11,
applicability_rank, 12,
availability_certainty, 13,
- availability_rank, -1);
+ availability_rank, 14, completed, -1);
g_free (filename);
g_free (uri_as_string);
g_free (status_colour);
@@ -644,6 +746,7 @@
6, filename /* filename/description */ ,
8, "blue" /* status colour: pending */ ,
-1);
+ gtk_tree_store_set (de->ts, &iter, 14, completed, -1);
return de;
}
@@ -654,9 +757,10 @@
*/
static void
start_download (GtkTreeView * tree_view, GtkTreePath * path,
- GtkTreeViewColumn * column, gboolean recursive, gpointer
user_data)
+ GtkTreeViewColumn * column, gpointer user_data)
{
- struct SearchTab *tab = user_data;
+ struct StartDownloadContext *sdc = user_data;
+ struct SearchTab *tab = sdc->tab;
GtkTreeModel *tm;
GtkTreeIter iter;
struct GNUNET_FS_Uri *uri;
@@ -671,13 +775,14 @@
char *filename;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting a %sdownload\n", recursive ? "recursive " : "");
+ "Starting a %sdownload\n", sdc->recursive ? "recursive " : "");
GNUNET_assert (tab != NULL);
tm = gtk_tree_view_get_model (tree_view);
if (TRUE != gtk_tree_model_get_iter (tm, &iter, path))
{
GNUNET_break (0);
+ GNUNET_free (sdc);
return;
}
gtk_tree_model_get (tm, &iter, 0, &meta, 1, &uri, 9, &sr, 10, &mime, -1);
@@ -685,6 +790,7 @@
{
/* can only download chk/loc URIs, ignore */
g_free (mime);
+ GNUNET_free (sdc);
return;
}
@@ -737,7 +843,8 @@
dlc->rr = gtk_tree_row_reference_new (tm, path);
dlc->sr = sr->result;
dlc->anonymity = -1;
- dlc->is_recursive = recursive;
+ dlc->is_recursive = sdc->recursive;
+ dlc->tab = tab;
GNUNET_FS_GTK_open_download_as_dialog (dlc);
g_free (mime);
}
@@ -762,6 +869,7 @@
{
GtkTreePath *path;
GtkTreeView *tv;
+ struct StartDownloadContext sdc;
if (current_context_row_reference == NULL)
{
@@ -774,7 +882,9 @@
tv = GTK_TREE_VIEW (gtk_builder_get_object
(current_context_search_tab->builder,
"_search_result_frame"));
- start_download (tv, path, NULL, FALSE, current_context_search_tab);
+ sdc.tab = current_context_search_tab;
+ sdc.recursive = FALSE;
+ start_download (tv, path, NULL, &sdc);
gtk_tree_path_free (path);
current_context_search_tab = NULL;
}
@@ -787,6 +897,7 @@
{
GtkTreePath *path;
GtkTreeView *tv;
+ struct StartDownloadContext sdc;
if (current_context_row_reference == NULL)
{
@@ -799,7 +910,9 @@
tv = GTK_TREE_VIEW (gtk_builder_get_object
(current_context_search_tab->builder,
"_search_result_frame"));
- start_download (tv, path, NULL, TRUE, current_context_search_tab);
+ sdc.tab = current_context_search_tab;
+ sdc.recursive = TRUE;
+ start_download (tv, path, NULL, &sdc);
gtk_tree_path_free (path);
current_context_search_tab = NULL;
}
@@ -1240,6 +1353,7 @@
GtkNotebook *notebook;
GtkWindow *sf;
gint pages;
+ struct StartDownloadContext *sdc;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Setting up a search for %p\n", sc);
@@ -1314,8 +1428,12 @@
/* add signal handlers */
tv = GTK_TREE_VIEW (gtk_builder_get_object
(tab->builder, "_search_result_frame"));
- g_signal_connect (G_OBJECT (tv), "row-activated", G_CALLBACK
(start_download),
- tab);
+ sdc = GNUNET_malloc (sizeof (struct StartDownloadContext));
+ sdc->tab = tab;
+ sdc->recursive = FALSE;
+ g_signal_connect_data (G_OBJECT (tv), "row-activated",
+ G_CALLBACK (start_download), sdc,
+ &closure_notify_free, 0);
g_signal_connect (G_OBJECT (tv), "cursor-changed",
G_CALLBACK (update_meta_data_views), tab);
g_signal_connect (G_OBJECT (tv), "button_press_event",
@@ -1499,7 +1617,8 @@
7, uris, 8, status_colour, 9, sr, 10,
mime,
11, applicability_rank, 12,
0 /* avail-cert */ ,
- 13, 0 /* avail-rank */ ,
+ 13, 0, /* avail-rank */
+ 14, (guint64) 0, /* completed */
-1);
if (tab != NULL)
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r18887 - in gnunet-gtk: contrib src/fs,
gnunet <=