gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r16937 - in gnunet-gtk: contrib src/fs


From: gnunet
Subject: [GNUnet-SVN] r16937 - in gnunet-gtk: contrib src/fs
Date: Sun, 18 Sep 2011 15:47:35 +0200

Author: grothoff
Date: 2011-09-18 15:47:35 +0200 (Sun, 18 Sep 2011)
New Revision: 16937

Modified:
   gnunet-gtk/contrib/gnunet_fs_gtk_publish_tab.glade
   gnunet-gtk/src/fs/gnunet-fs-gtk-event_handler.c
Log:
moving all publish operations into a single publishing tab

Modified: gnunet-gtk/contrib/gnunet_fs_gtk_publish_tab.glade
===================================================================
--- gnunet-gtk/contrib/gnunet_fs_gtk_publish_tab.glade  2011-09-18 13:07:28 UTC 
(rev 16936)
+++ gnunet-gtk/contrib/gnunet_fs_gtk_publish_tab.glade  2011-09-18 13:47:35 UTC 
(rev 16937)
@@ -62,7 +62,7 @@
           <object class="GtkLabel" id="_publish_label_window_label">
             <property name="height_request">30</property>
             <property name="visible">True</property>
-            <property name="label" translatable="yes">filename</property>
+            <property name="label" translatable="yes">Publishing</property>
           </object>
           <packing>
             <property name="fill">False</property>
@@ -104,6 +104,8 @@
       <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     2011-09-18 13:07:28 UTC 
(rev 16936)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk-event_handler.c     2011-09-18 13:47:35 UTC 
(rev 16937)
@@ -34,25 +34,20 @@
 
 struct PublishTab
 {
+
   /**
-   * This is a doubly-linked list.
+   * Frame for the tab.
    */
-  struct PublishTab *next;
+  GtkWidget *frame;
 
   /**
-   * This is a doubly-linked list.
+   * Associated builder.
    */
-  struct PublishTab *prev;
-
-  GtkWidget *frame;
-
   GtkBuilder *builder;
 
   /**
-   * Associated (top-level) FS publish operation.
+   * Associated tree store.
    */
-  struct GNUNET_FS_PublishContext *pc;
-
   GtkTreeStore *ts;
 };
 
@@ -109,11 +104,9 @@
 
 
 
-static struct PublishTab *publish_tab_head;
+static struct PublishTab *publish_tab;
 
-static struct PublishTab *publish_tab_tail;
 
-
 static struct DownloadEntry *
 change_download_colour (struct DownloadEntry *de, const char *colour)
 {
@@ -923,42 +916,38 @@
 
 
 /**
- * Close a publish tab and free associated state.
+ * Close free an entry in the publish tab and free associated state.
  */
 static void
-close_publish_tab (struct PublishEntry *ent)
+handle_publish_stop (struct PublishEntry *ent)
 {
-  struct PublishTab *tab;
-  GtkNotebook *notebook;
-  int index;
-  int i;
+  GtkTreeIter iter;
+  GtkTreePath *path;
+  GtkTreeModel *tm;
 
   if (ent == NULL)
   {
     GNUNET_break (0);
     return;
   }
-  gtk_tree_row_reference_free (ent->rr);
-  if (GNUNET_YES != ent->is_top)
+  if (NULL != ent->pc)
   {
-    GNUNET_free (ent);
-    return;
+     /* get piter from parent */
+    path = gtk_tree_row_reference_get_path (ent->rr);
+    tm = gtk_tree_row_reference_get_model (ent->rr);
+    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);
   }
-  tab = ent->tab;
+  gtk_tree_row_reference_free (ent->rr);
   if (ent->uri != NULL)
+  {
     GNUNET_FS_uri_destroy (ent->uri);
+    ent->uri = NULL;
+  }
   GNUNET_free (ent);
-  notebook =
-      GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object
-                    ("GNUNET_GTK_main_window_notebook"));
-  index = -1;
-  for (i = gtk_notebook_get_n_pages (notebook) - 1; i >= 0; i--)
-    if (tab->frame == gtk_notebook_get_nth_page (notebook, i))
-      index = i;
-  gtk_notebook_remove_page (notebook, index);
-  g_object_unref (tab->builder);
-  GNUNET_CONTAINER_DLL_remove (publish_tab_head, publish_tab_tail, tab);
-  GNUNET_free (tab);
 }
 
 
@@ -1517,19 +1506,46 @@
 
 
 /**
- * Tell FS to stop publishing.
+ * Tell FS to stop all active publish operations.  Then close the tab.
  */
 static void
 stop_publishing (GtkButton * button, gpointer user_data)
 {
   struct PublishTab *tab = user_data;
   struct GNUNET_FS_PublishContext *pc;
-
-  if (NULL != (pc = tab->pc))
+  struct PublishEntry *ent;
+  GtkTreeIter iter;
+  GtkTreeModel *tm;
+  GtkNotebook *notebook;
+  int index;
+  int i;
+ 
+  GNUNET_assert (tab == publish_tab);
+  tm = GTK_TREE_MODEL (publish_tab->ts);
+  if (TRUE == gtk_tree_model_iter_children (tm, &iter, NULL))
   {
-    tab->pc = NULL;
-    GNUNET_FS_publish_stop (pc);
+    do
+    {
+      gtk_tree_model_get (tm, &iter, 4, &ent, -1);
+      if (NULL != (pc = ent->pc))
+       {
+         ent->pc = NULL;
+         GNUNET_FS_publish_stop (pc);
+       }
+    }
+    while (TRUE == gtk_tree_model_iter_next (tm, &iter));
   }
+  notebook =
+    GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object
+                 ("GNUNET_GTK_main_window_notebook"));
+  index = -1;
+  for (i = gtk_notebook_get_n_pages (notebook) - 1; i >= 0; i--)
+    if (publish_tab->frame == gtk_notebook_get_nth_page (notebook, i))
+      index = i;
+  gtk_notebook_remove_page (notebook, index);
+  g_object_unref (publish_tab->builder);
+  GNUNET_free (publish_tab);
+  publish_tab = NULL;
 }
 
 
@@ -1537,7 +1553,6 @@
 setup_publish (struct GNUNET_FS_PublishContext *pc, const char *fn,
                uint64_t fsize, struct PublishEntry *parent)
 {
-  struct PublishTab *tab;
   struct PublishEntry *ent;
   GtkTreeIter *pitrptr;
   GtkTreeIter iter;
@@ -1545,7 +1560,6 @@
   GtkTreePath *path;
   GtkWindow *df;
   GtkWidget *tab_label;
-  GtkLabel *fn_label;
   GtkWidget *close_button;
   GtkNotebook *notebook;
   gint pages;
@@ -1553,56 +1567,60 @@
 
   if (NULL == parent)
   {
-    /* create new tab */
-    tab = GNUNET_malloc (sizeof (struct PublishTab));
-    tab->pc = pc;
-    GNUNET_CONTAINER_DLL_insert (publish_tab_head, publish_tab_tail, tab);
-    tab->builder =
-        GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_publish_tab.glade");
-    df = GTK_WINDOW (gtk_builder_get_object
-                     (tab->builder, "_publish_frame_window"));
-    tab->frame = gtk_bin_get_child (GTK_BIN (df));
-    g_object_ref (tab->frame);
-    gtk_container_remove (GTK_CONTAINER (df), tab->frame);
-    gtk_widget_destroy (GTK_WIDGET (df));
-
-    /* load tab_label */
-    df = GTK_WINDOW (gtk_builder_get_object
-                     (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));
-
-    /* get refs to widgets */
-    fn_label =
-        GTK_LABEL (gtk_builder_get_object
-                   (tab->builder, "_publish_label_window_label"));
-    gtk_label_set_text (fn_label, fn);
-    close_button =
-        GTK_WIDGET (gtk_builder_get_object
-                    (tab->builder, "_publish_label_close_button"));
-    g_signal_connect (G_OBJECT (close_button), "clicked",
-                      G_CALLBACK (stop_publishing), tab);
-    /* make visible */
-    notebook =
-        GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object
-                      ("GNUNET_GTK_main_window_notebook"));
-    pages = gtk_notebook_get_n_pages (notebook);
-    gtk_notebook_insert_page (notebook, tab->frame, tab_label, pages - 1);
-    gtk_widget_show (GTK_WIDGET (notebook));
-    tab->ts =
-        GTK_TREE_STORE (gtk_builder_get_object
-                        (tab->builder, "_publish_frame_tree_store"));
-    pitrptr = NULL;
+    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");
+      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));
+      
+      /* 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"));
+      pages = gtk_notebook_get_n_pages (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;
+    }
   }
   else
   {
     /* create new iter from parent */
-    tab = parent->tab;
     path = gtk_tree_row_reference_get_path (parent->rr);
     if (TRUE !=
-        gtk_tree_model_get_iter (GTK_TREE_MODEL (tab->ts), &piter, path))
+        gtk_tree_model_get_iter (GTK_TREE_MODEL (publish_tab->ts), &piter, 
path))
     {
       GNUNET_break (0);
       return NULL;
@@ -1610,18 +1628,20 @@
     pitrptr = &piter;
   }
   size_fancy = GNUNET_STRINGS_byte_size_fancy (fsize);
-  gtk_tree_store_insert_with_values (tab->ts, &iter, pitrptr, G_MAXINT, 0, fn,
+  ent = GNUNET_malloc (sizeof (struct PublishEntry));
+  ent->is_top = (parent == NULL) ? GNUNET_YES : GNUNET_NO;
+  ent->tab = publish_tab;
+  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);
-  ent = GNUNET_malloc (sizeof (struct PublishEntry));
-  ent->is_top = (parent == NULL) ? GNUNET_YES : GNUNET_NO;
-  ent->tab = tab;
-  path = gtk_tree_model_get_path (GTK_TREE_MODEL (tab->ts), &iter);
-  ent->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (tab->ts), path);
+  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;
 }
 
@@ -1673,7 +1693,7 @@
     }
     return ret;
   case GNUNET_FS_STATUS_PUBLISH_SUSPEND:
-    close_publish_tab (info->value.publish.cctx);
+    handle_publish_stop (info->value.publish.cctx);
     return NULL;
   case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
     return mark_publish_progress (info->value.publish.cctx,
@@ -1687,7 +1707,7 @@
                                      info->value.publish.specifics.completed.
                                      chk_uri);
   case GNUNET_FS_STATUS_PUBLISH_STOPPED:
-    close_publish_tab (info->value.publish.cctx);
+    handle_publish_stop (info->value.publish.cctx);
     return NULL;
   case GNUNET_FS_STATUS_DOWNLOAD_START:
     return setup_download (info->value.download.cctx, 
info->value.download.pctx,




reply via email to

[Prev in Thread] Current Thread [Next in Thread]