gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r11824 - gnunet gnunet-gtk/src


From: gnunet
Subject: [GNUnet-SVN] r11824 - gnunet gnunet-gtk/src
Date: Sun, 20 Jun 2010 13:38:40 +0200

Author: grothoff
Date: 2010-06-20 13:38:40 +0200 (Sun, 20 Jun 2010)
New Revision: 11824

Modified:
   gnunet-gtk/src/fs_event_handler.c
   gnunet/TODO
Log:
publish start, progress, complete handling

Modified: gnunet/TODO
===================================================================
--- gnunet/TODO 2010-06-20 11:32:18 UTC (rev 11823)
+++ gnunet/TODO 2010-06-20 11:38:40 UTC (rev 11824)
@@ -18,9 +18,6 @@
     [On W32, we need to select after calling socket before doing connect etc.]
 * GNUNET-GTK:
   - handle publish events
-    + start 
-    + progress
-    + completed
     + stopped
     + suspend
   - directory support:

Modified: gnunet-gtk/src/fs_event_handler.c
===================================================================
--- gnunet-gtk/src/fs_event_handler.c   2010-06-20 11:32:18 UTC (rev 11823)
+++ gnunet-gtk/src/fs_event_handler.c   2010-06-20 11:38:40 UTC (rev 11824)
@@ -56,12 +56,23 @@
 {
   struct PublishTab *next;
   struct PublishTab *prev;
+  GtkBuilder *builder;
   struct GNUNET_FS_PublishContext *pc;
-  GtkBuilder *builder;
+  GtkTreeStore *ts;
 };
 
-//static struct PublishTab *p
 
+struct PublishEntry
+{
+  struct GNUNET_FS_PublishContext *pc;
+  struct PublishTab *tab;
+  GtkTreeRowReference *rr;
+};
+
+static struct PublishTab *publish_tab_head;
+
+static struct PublishTab *publish_tab_tail;
+
 struct SearchResult 
 {
   GtkTreeRowReference *rr;
@@ -107,6 +118,29 @@
 }
 
 
+static struct PublishEntry *
+change_publish_colour (struct PublishEntry *pe,
+                      const char *colour)
+{
+  GtkTreeIter iter;
+  GtkTreePath *path;
+  
+  path = gtk_tree_row_reference_get_path (pe->rr);
+  if (TRUE != gtk_tree_model_get_iter (GTK_TREE_MODEL (pe->tab->ts), 
+                                      &iter, path))
+    {
+      GNUNET_break (0);
+      gtk_tree_path_free (path);
+      return pe;
+    }
+  gtk_tree_path_free (path);
+  gtk_tree_store_set (pe->tab->ts, &iter,
+                     2, colour,
+                     -1);
+  return pe;
+}
+
+
 static void 
 stop_download (struct DownloadEntry *de,
               int is_suspend)
@@ -145,6 +179,30 @@
 }
 
 
+static struct PublishEntry *
+mark_publish_progress (struct PublishEntry *pe,
+                       uint64_t size,
+                       uint64_t completed)
+{
+  GtkTreeIter iter;
+  GtkTreePath *path;
+  
+  path = gtk_tree_row_reference_get_path (pe->rr);
+  if (TRUE != gtk_tree_model_get_iter (GTK_TREE_MODEL (pe->tab->ts), 
+                                      &iter, path))
+    {
+      GNUNET_break (0);
+      gtk_tree_path_free (path);
+      return pe;
+    }
+  gtk_tree_path_free (path);
+  gtk_tree_store_set (pe->tab->ts, &iter,
+                     3, (guint) ((size > 0) ? (100 * completed / size) : 100) 
/* progress */,
+                     -1);
+  return pe;
+}
+
+
 /**
  * Setup a new download entry.
  *
@@ -802,6 +860,122 @@
 
 
 /**
+ * Tell FS to stop publishing.
+ */
+static void
+stop_publishing (GtkButton *button,
+                gpointer user_data)
+{
+  struct PublishTab *tab = user_data;
+  if (tab->pc != NULL)
+    {
+      GNUNET_FS_publish_stop (tab->pc);
+      tab->pc = NULL;
+    }
+}
+
+
+static struct PublishEntry *
+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;
+  GtkTreeIter piter;
+  GtkTreePath *path;
+  GtkWindow *df;
+  GtkWidget *tab_label;
+  GtkLabel *fn_label;
+  GtkWidget *close_button;
+  GtkWidget *frame;
+  GtkNotebook *notebook;
+  gint pages;
+  char *size_fancy;
+
+  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 ("publish_tab.glade");
+      df = GTK_WINDOW (gtk_builder_get_object (tab->builder,
+                                              "_search_result_frame_window"));
+      frame = gtk_bin_get_child (GTK_BIN (df));
+      gtk_widget_ref (frame);
+      gtk_container_remove (GTK_CONTAINER (df), 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));
+      gtk_widget_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_GTK_get_main_window_object 
("GNUNET_GTK_main_window_notebook"));
+      pages = gtk_notebook_get_n_pages (notebook);
+      gtk_notebook_insert_page (notebook, 
+                               frame,
+                               tab_label,
+                               pages - 1);
+      gtk_widget_show (GTK_WIDGET (notebook));
+      tab->ts = GTK_TREE_STORE (gtk_builder_get_object (tab->builder,
+                                                       
"_publish_tree_store")); 
+      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))
+       {
+         GNUNET_break (0);
+         return NULL;
+       }
+      pitrptr = &piter;
+    }
+  size_fancy = GNUNET_STRINGS_byte_size_fancy (fsize);
+  gtk_tree_store_insert_with_values (tab->ts,
+                                    &iter,
+                                    pitrptr,
+                                    G_MAXINT,
+                                    0, fn,
+                                    1, size_fancy,
+                                    2, "white",
+                                    3, (guint) 0 /* progress */,
+                                    -1);
+  GNUNET_free (size_fancy);
+  ent = GNUNET_malloc (sizeof (struct PublishEntry));
+  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);
+  gtk_tree_path_free (path);
+  ent->pc = pc;
+  return ent;
+}
+
+
+/**
  * Notification of FS to a client about the progress of an 
  * operation.  Callbacks of this type will be used for uploads,
  * downloads and searches.  Some of the arguments depend a bit 
@@ -823,7 +997,10 @@
   switch (info->status)
     {
     case GNUNET_FS_STATUS_PUBLISH_START: 
-      GNUNET_break (0); 
+      return setup_publish (info->value.publish.pc,
+                           info->value.publish.filename,
+                           info->value.publish.size,
+                           info->value.publish.pctx);
       break;
     case GNUNET_FS_STATUS_PUBLISH_RESUME:
       GNUNET_break (0); 
@@ -832,14 +1009,15 @@
       GNUNET_break (0); 
       break;
     case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
-      GNUNET_break (0); 
-      break;
+      return mark_publish_progress (info->value.publish.cctx,
+                                   info->value.publish.size,
+                                   info->value.publish.completed);
     case GNUNET_FS_STATUS_PUBLISH_ERROR: 
       GNUNET_break (0); 
       break;
     case GNUNET_FS_STATUS_PUBLISH_COMPLETED: 
-      GNUNET_break (0); 
-      break;
+      return change_publish_colour (info->value.publish.cctx,
+                                   "green");
     case GNUNET_FS_STATUS_PUBLISH_STOPPED: 
       GNUNET_break (0); 
       break;




reply via email to

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