[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r19601 - in gnunet-gtk: contrib src/fs
From: |
gnunet |
Subject: |
[GNUnet-SVN] r19601 - in gnunet-gtk: contrib src/fs |
Date: |
Wed, 1 Feb 2012 17:35:15 +0100 |
Author: grothoff
Date: 2012-02-01 17:35:15 +0100 (Wed, 01 Feb 2012)
New Revision: 19601
Modified:
gnunet-gtk/contrib/gnunet_fs_gtk_publish_tab.glade
gnunet-gtk/src/fs/gnunet-fs-gtk-event_handler.c
Log:
-more publish handling cleanup
Modified: gnunet-gtk/contrib/gnunet_fs_gtk_publish_tab.glade
===================================================================
--- gnunet-gtk/contrib/gnunet_fs_gtk_publish_tab.glade 2012-02-01 16:00:39 UTC
(rev 19600)
+++ gnunet-gtk/contrib/gnunet_fs_gtk_publish_tab.glade 2012-02-01 16:35:15 UTC
(rev 19601)
@@ -1,70 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="2.20"/>
- <!-- interface-naming-policy project-wide -->
+ <object class="GtkTreeStore" id="_publish_frame_tree_store">
+ <columns>
+ <!-- column-name filename -->
+ <column type="gchararray"/>
+ <!-- column-name filesize -->
+ <column type="gchararray"/>
+ <!-- column-name bgcolour -->
+ <column type="gchararray"/>
+ <!-- column-name progress -->
+ <column type="guint"/>
+ <!-- column-name ent -->
+ <column type="gpointer"/>
+ <!-- column-name result_string -->
+ <column type="gchararray"/>
+ </columns>
+ </object>
<object class="GtkWindow" id="_publish_frame_window">
+ <property name="can_focus">False</property>
<property name="title">You should never see this</property>
-
- <child>
- <object class="GtkScrolledWindow"
id="_publish_frame_scrolled_window">
- <property name="height_request">100</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="hscrollbar_policy">automatic</property>
- <property name="vscrollbar_policy">automatic</property>
-
<child>
- <object class="GtkTreeView" id="_publish_frame">
+ <object class="GtkScrolledWindow" id="_publish_frame_scrolled_window">
+ <property name="height_request">100</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="model">_publish_frame_tree_store</property>
- <property name="reorderable">True</property>
- <property name="enable_tree_lines">True</property>
<child>
- <object class="GtkTreeViewColumn" id="filename">
- <property name="sizing">autosize</property>
- <property name="title" translatable="yes">Filename</property>
- <property name="expand">True</property>
+ <object class="GtkTreeView" id="_publish_frame">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="model">_publish_frame_tree_store</property>
+ <property name="reorderable">True</property>
+ <property name="enable_tree_lines">True</property>
+ <child internal-child="selection">
+ <object class="GtkTreeSelection" id="treeview-selection1"/>
+ </child>
<child>
- <object class="GtkCellRendererProgress" id="filename_renderer"/>
- <attributes>
- <attribute name="cell-background">2</attribute>
- <attribute name="text">0</attribute>
- <attribute name="value">3</attribute>
- </attributes>
+ <object class="GtkTreeViewColumn" id="filename">
+ <property name="sizing">autosize</property>
+ <property name="title" translatable="yes">Filename</property>
+ <property name="expand">True</property>
+ <child>
+ <object class="GtkCellRendererProgress"
id="filename_renderer"/>
+ <attributes>
+ <attribute name="cell-background">2</attribute>
+ <attribute name="text">0</attribute>
+ <attribute name="value">3</attribute>
+ </attributes>
+ </child>
+ </object>
</child>
- </object>
- </child>
- <child>
- <object class="GtkTreeViewColumn" id="filesize">
- <property name="sizing">autosize</property>
- <property name="title" translatable="yes">Size</property>
<child>
- <object class="GtkCellRendererText" id="size_renderer"/>
- <attributes>
- <attribute name="background">2</attribute>
- <attribute name="text">1</attribute>
- </attributes>
+ <object class="GtkTreeViewColumn" id="filesize">
+ <property name="sizing">autosize</property>
+ <property name="title" translatable="yes">Size</property>
+ <child>
+ <object class="GtkCellRendererText" id="size_renderer"/>
+ <attributes>
+ <attribute name="background">2</attribute>
+ <attribute name="text">1</attribute>
+ </attributes>
+ </child>
+ </object>
</child>
</object>
</child>
</object>
</child>
</object>
- </child>
- </object>
<object class="GtkWindow" id="_publish_label_window">
+ <property name="can_focus">False</property>
<child>
<object class="GtkHBox" id="_publish_label_hbox">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="border_width">5</property>
<child>
<object class="GtkLabel" id="_publish_label_window_label">
<property name="height_request">30</property>
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="label" translatable="yes">Publishing</property>
</object>
<packing>
+ <property name="expand">True</property>
<property name="fill">False</property>
<property name="padding">5</property>
<property name="position">0</property>
@@ -72,6 +91,7 @@
</child>
<child>
<object class="GtkButton" id="_publish_label_close_button">
+ <property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
@@ -80,6 +100,7 @@
<child>
<object class="GtkImage" id="close_icon_stock_image">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="stock">gtk-close</property>
<property name="icon-size">2</property>
</object>
@@ -94,18 +115,4 @@
</object>
</child>
</object>
- <object class="GtkTreeStore" id="_publish_frame_tree_store">
- <columns>
- <!-- column-name filename -->
- <column type="gchararray"/>
- <!-- column-name filesize -->
- <column type="gchararray"/>
- <!-- column-name bgcolour -->
- <column type="gchararray"/>
- <!-- column-name progress -->
- <column type="guint"/>
- <!-- column-name ent -->
- <column type="gpointer"/>
- </columns>
- </object>
</interface>
Modified: gnunet-gtk/src/fs/gnunet-fs-gtk-event_handler.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk-event_handler.c 2012-02-01 16:00:39 UTC
(rev 19600)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk-event_handler.c 2012-02-01 16:35:15 UTC
(rev 19601)
@@ -1061,7 +1061,7 @@
* We received a search error message from the FS library.
* Present it to the user in an appropriate form.
*
- * @param tab search tab affected by the error message
+ * @param tab search tab affected by the error
* @param emsg the error message
*/
static void
@@ -2155,23 +2155,27 @@
}
-static struct PublishEntry *
+/**
+ * We got an event that some publishing operation is progressing.
+ * Update the tree model accordingly.
+ *
+ * @param pe publish entry that is progressing
+ * @param size overall size of the file or directory
+ * @param completed number of bytes we have completed
+ */
+static void
mark_publish_progress (struct PublishEntry *pe, uint64_t size,
uint64_t completed)
{
GtkTreeIter iter;
GtkTreePath *path;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Marking publicaation progress for PE=%p, %llu/%llu\n",
- pe, completed, size);
path = gtk_tree_row_reference_get_path (pe->rr);
- if (TRUE !=
- gtk_tree_model_get_iter (GTK_TREE_MODEL (pe->tab->ts), &iter, path))
+ if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (pe->tab->ts), &iter, path))
{
GNUNET_break (0);
gtk_tree_path_free (path);
- return pe;
+ return;
}
gtk_tree_path_free (path);
gtk_tree_store_set (pe->tab->ts, &iter, 3,
@@ -2179,98 +2183,114 @@
0) ? (100 * completed /
size) : 100) /* progress */ ,
-1);
- return pe;
}
/**
- * Close a publish tab and free associated state.
+ * FS-API notified us that we're done with some publish operation.
+ * Update the view accordingly.
+ *
+ * @param pe publish operation that has finished
+ * @param uri resulting URI
*/
static void
handle_publish_completed (struct PublishEntry *pe,
const struct GNUNET_FS_Uri *uri)
{
+ GtkTreeIter iter;
+ GtkTreePath *path;
+ char *uris;
+
+ path = gtk_tree_row_reference_get_path (pe->rr);
+ if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (pe->tab->ts), &iter, path))
+ {
+ GNUNET_break (0);
+ gtk_tree_path_free (path);
+ return;
+ }
+ gtk_tree_path_free (path);
pe->uri = GNUNET_FS_uri_dup (uri);
+ uris = GNUNET_FS_uri_to_string (uri);
+ gtk_tree_store_set (pe->tab->ts, &iter,
+ 5, uris,
+ -1);
+ GNUNET_free (uris);
change_publish_color (pe, "green");
}
-
/**
- * Handle error.
+ * We received a publish error message from the FS library.
+ * Present it to the user in an appropriate form.
+ *
+ * @param pe publishing operation affected by the error
+ * @param emsg the error message
*/
static void
-handle_publish_error (struct PublishEntry *ent,
+handle_publish_error (struct PublishEntry *pe,
const char *emsg)
{
- GNUNET_break (0);
- change_publish_color (ent, "red");
+ GtkTreeIter iter;
+ GtkTreePath *path;
+
+ path = gtk_tree_row_reference_get_path (pe->rr);
+ if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (pe->tab->ts), &iter, path))
+ {
+ GNUNET_break (0);
+ gtk_tree_path_free (path);
+ return;
+ }
+ gtk_tree_path_free (path);
+ gtk_tree_store_set (pe->tab->ts, &iter,
+ 5, emsg,
+ -1);
+ change_publish_color (pe, "red");
}
/**
- * Close free an entry in the publish tab and free associated state.
+ * A publishing operation was stopped (in FS API). Free an entry in
+ * the publish tab and its associated state.
+ *
+ * @param pe publishing operation that was stopped
*/
static void
-handle_publish_stop (struct PublishEntry *ent)
+handle_publish_stop (struct PublishEntry *pe)
{
GtkTreeIter iter;
GtkTreePath *path;
- GtkTreeModel *tm;
- if (ent == NULL)
+ path = gtk_tree_row_reference_get_path (pe->rr);
+ /* This is a child of a directory, and we've had that directory
+ free'd already */
+ if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (pe->tab->ts), &iter, path))
{
GNUNET_break (0);
return;
}
- if (NULL != ent->pc)
+ (void) gtk_tree_store_remove (pe->tab->ts, &iter);
+ gtk_tree_path_free (path);
+ gtk_tree_row_reference_free (pe->rr);
+ if (pe->uri != NULL)
{
- /* get piter from parent */
- path = gtk_tree_row_reference_get_path (ent->rr);
- tm = gtk_tree_row_reference_get_model (ent->rr);
- /* This is a child of a directory, and we've had that directory
- * freed already
- */
- if (path != NULL)
- {
- if (TRUE != gtk_tree_model_get_iter (tm, &iter, path))
- GNUNET_break (0);
- else
- (void) gtk_tree_store_remove (GTK_TREE_STORE (tm), &iter);
- gtk_tree_path_free (path);
- }
+ GNUNET_FS_uri_destroy (pe->uri);
+ pe->uri = NULL;
}
- gtk_tree_row_reference_free (ent->rr);
- if (ent->uri != NULL)
- {
- GNUNET_FS_uri_destroy (ent->uri);
- ent->uri = NULL;
- }
- GNUNET_free (ent);
+ GNUNET_free (pe);
}
-
-
-
-
-
-
-
-
-
-
-
-
-
/**
+ * The user clicked on the "close" button of the publishing tab.
* Tell FS to stop all active publish operations. Then close the tab.
+ *
+ * @param button the stop button
+ * @param user_data the 'struct PublishTab' that is being closed
*/
static void
stop_publishing (GtkButton * button, gpointer user_data)
{
struct PublishTab *tab = user_data;
- struct GNUNET_FS_PublishContext *pc;
struct PublishEntry *ent;
GtkTreeIter iter;
GtkTreeModel *tm;
@@ -2279,20 +2299,20 @@
int i;
GNUNET_assert (tab == publish_tab);
+ /* stop all active operations */
tm = GTK_TREE_MODEL (publish_tab->ts);
- if (TRUE == gtk_tree_model_iter_children (tm, &iter, NULL))
+ if (gtk_tree_model_iter_children (tm, &iter, NULL))
{
do
{
gtk_tree_model_get (tm, &iter, 4, &ent, -1);
- if (NULL != (pc = ent->pc))
- {
- ent->pc = NULL;
- GNUNET_FS_publish_stop (pc);
- }
+ GNUNET_FS_publish_stop (ent->pc);
+ ent->pc = NULL;
}
while (TRUE == gtk_tree_model_iter_next (tm, &iter));
}
+
+ /* remove tab from notebook */
notebook =
GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object
("GNUNET_GTK_main_window_notebook"));
@@ -2301,12 +2321,24 @@
if (publish_tab->frame == gtk_notebook_get_nth_page (notebook, i))
index = i;
gtk_notebook_remove_page (notebook, index);
+
+ /* fully destroy tab */
g_object_unref (publish_tab->builder);
GNUNET_free (publish_tab);
publish_tab = NULL;
}
+/**
+ * The user started a publishing operation. Add it to the publishing
+ * tab. If needed, create the publishing tab.
+ *
+ * @param pc the FS-API's publishing context for the operation
+ * @param fn the name of the file (or directory) that is being published
+ * @param fsize size of the file
+ * @param parent parent of this publishing operation (for recursive
operations), NULL for top-level operations
+ * @return the publishing entry that will represent this operation
+ */
static struct PublishEntry *
setup_publish (struct GNUNET_FS_PublishContext *pc, const char *fn,
uint64_t fsize, struct PublishEntry *parent)
@@ -2321,57 +2353,52 @@
GtkWidget *close_button;
GtkNotebook *notebook;
char *size_fancy;
+
+ if (NULL == publish_tab)
+ {
+ /* create new tab */
+ publish_tab = GNUNET_malloc (sizeof (struct PublishTab));
+ publish_tab->builder =
+ GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_publish_tab.glade",
+ publish_tab);
+ df = GTK_WINDOW (gtk_builder_get_object
+ (publish_tab->builder, "_publish_frame_window"));
+ publish_tab->frame = gtk_bin_get_child (GTK_BIN (df));
+ g_object_ref (publish_tab->frame);
+ gtk_container_remove (GTK_CONTAINER (df), publish_tab->frame);
+ gtk_widget_destroy (GTK_WIDGET (df));
+
+ /* load tab_label */
+ df = GTK_WINDOW (gtk_builder_get_object
+ (publish_tab->builder, "_publish_label_window"));
+ tab_label = gtk_bin_get_child (GTK_BIN (df));
+ g_object_ref (tab_label);
+ gtk_container_remove (GTK_CONTAINER (df), tab_label);
+ gtk_widget_destroy (GTK_WIDGET (df));
+
+ /* FIXME: connect these signals using GLADE!!! */
+ /* get refs to widgets */
+ close_button =
+ GTK_WIDGET (gtk_builder_get_object
+ (publish_tab->builder, "_publish_label_close_button"));
+ g_signal_connect (G_OBJECT (close_button), "clicked",
+ G_CALLBACK (stop_publishing), publish_tab);
+ /* make visible */
+ notebook =
+ GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object
+ ("GNUNET_GTK_main_window_notebook"));
+ gtk_notebook_insert_page (notebook, publish_tab->frame, tab_label, 0);
+ gtk_widget_show (GTK_WIDGET (notebook));
+ gtk_notebook_set_current_page (notebook, 0);
+ publish_tab->ts =
+ GTK_TREE_STORE (gtk_builder_get_object
+ (publish_tab->builder, "_publish_frame_tree_store"));
+ }
+ /* decide where to insert in the tab */
if (NULL == parent)
{
- if (NULL == publish_tab)
- {
- /* create new tab */
- publish_tab = GNUNET_malloc (sizeof (struct PublishTab));
- publish_tab->builder =
- GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_publish_tab.glade",
- publish_tab);
- df = GTK_WINDOW (gtk_builder_get_object
- (publish_tab->builder, "_publish_frame_window"));
- publish_tab->frame = gtk_bin_get_child (GTK_BIN (df));
- g_object_ref (publish_tab->frame);
- gtk_container_remove (GTK_CONTAINER (df), publish_tab->frame);
- gtk_widget_destroy (GTK_WIDGET (df));
-
- /* load tab_label */
- df = GTK_WINDOW (gtk_builder_get_object
- (publish_tab->builder, "_publish_label_window"));
- tab_label = gtk_bin_get_child (GTK_BIN (df));
- g_object_ref (tab_label);
- gtk_container_remove (GTK_CONTAINER (df), tab_label);
- gtk_widget_destroy (GTK_WIDGET (df));
-
- /* FIXME: connect these signals using GLADE!!! */
- /* get refs to widgets */
- close_button =
- GTK_WIDGET (gtk_builder_get_object
- (publish_tab->builder, "_publish_label_close_button"));
- g_signal_connect (G_OBJECT (close_button), "clicked",
- G_CALLBACK (stop_publishing), publish_tab);
- /* FIXME: we don't actually need the closure anymore,
- * so we could have glade connect the above signal... */
- /* make visible */
- notebook =
- GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object
- ("GNUNET_GTK_main_window_notebook"));
- gtk_notebook_insert_page (notebook, publish_tab->frame, tab_label, 0);
- gtk_widget_show (GTK_WIDGET (notebook));
- gtk_notebook_set_current_page (notebook, 0);
- publish_tab->ts =
- GTK_TREE_STORE (gtk_builder_get_object
- (publish_tab->builder, "_publish_frame_tree_store"));
- pitrptr = NULL;
- }
- else
- {
- /* use existing TAB, but create fresh entry */
- pitrptr = NULL;
- }
+ pitrptr = NULL;
}
else
{
@@ -2386,28 +2413,30 @@
}
pitrptr = &piter;
}
- size_fancy = GNUNET_STRINGS_byte_size_fancy (fsize);
+
+ /* create entry and perform insertion */
ent = GNUNET_malloc (sizeof (struct PublishEntry));
ent->is_top = (parent == NULL) ? GNUNET_YES : GNUNET_NO;
ent->tab = publish_tab;
+ ent->pc = pc;
+ size_fancy = GNUNET_STRINGS_byte_size_fancy (fsize);
gtk_tree_store_insert_with_values (publish_tab->ts, &iter, pitrptr, G_MAXINT,
0, fn, 1, size_fancy, 2, "white", 3,
(guint) 0 /* progress */ ,
4, ent, -1);
+ GNUNET_free (size_fancy);
path = gtk_tree_model_get_path (GTK_TREE_MODEL (publish_tab->ts), &iter);
- GNUNET_assert (NULL != path);
ent->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (publish_tab->ts),
path);
gtk_tree_path_free (path);
- ent->pc = pc;
- GNUNET_free (size_fancy);
return ent;
}
-
/* ***************** Master event handler ****************** */
+
+
/**
* Notification of FS to a client about the progress of an
* operation. Callbacks of this type will be used for uploads,
@@ -2455,9 +2484,10 @@
handle_publish_stop (info->value.publish.cctx);
return NULL;
case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
- return mark_publish_progress (info->value.publish.cctx,
- info->value.publish.size,
- info->value.publish.completed);
+ mark_publish_progress (info->value.publish.cctx,
+ info->value.publish.size,
+ info->value.publish.completed);
+ return info->value.publish.cctx;
case GNUNET_FS_STATUS_PUBLISH_ERROR:
handle_publish_error (info->value.publish.cctx,
info->value.publish.specifics.error.message);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r19601 - in gnunet-gtk: contrib src/fs,
gnunet <=