gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r19555 - gnunet-gtk/src/fs


From: gnunet
Subject: [GNUnet-SVN] r19555 - gnunet-gtk/src/fs
Date: Tue, 31 Jan 2012 00:23:28 +0100

Author: grothoff
Date: 2012-01-31 00:23:28 +0100 (Tue, 31 Jan 2012)
New Revision: 19555

Modified:
   gnunet-gtk/src/fs/gnunet-fs-gtk-main_window_file_publish.c
Log:
-adapting publishing code to new dirscanner API

Modified: gnunet-gtk/src/fs/gnunet-fs-gtk-main_window_file_publish.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk-main_window_file_publish.c  2012-01-30 
22:10:33 UTC (rev 19554)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk-main_window_file_publish.c  2012-01-30 
23:23:28 UTC (rev 19555)
@@ -69,26 +69,12 @@
   struct AddDirClientContext *prev;
   struct AddDirClientContext *next;
 
-  /**
-   * GNUNET_YES if the user asked to cancel the processing.
-   * If so, wrap up as fast as possible and close the progress dialog.
-   */
-  int cancelling;
-
-  /**
-   * GNUNET_YES if there was something during the scan that might
-   * need user's attention. Prevents the dialog from closing, unless
-   * the process was cancelled.
-   */
-  int keep;
-
   struct GNUNET_FS_ProcessMetadataContext *pmc;
 
   struct MainPublishingDialogContext *ctx;
   struct GNUNET_FS_DirScanner *ds;
 
   struct GNUNET_FS_ShareTreeItem *directory_scan_result;
-  struct GNUNET_FS_ShareTreeItem *directory_scan_intermediary_result;
 
   struct GNUNET_FS_BlockOptions directory_scan_bo;
   int directory_scan_do_index;
@@ -96,7 +82,6 @@
   GtkBuilder *progress_dialog_builder;
   GtkWidget *progress_dialog;
   GtkProgressBar *progress_dialog_bar;
-  GtkButton *progress_dialog_ok;
   GtkButton *progress_dialog_cancel;
   GtkTextView *progress_dialog_textview;
   GtkTextBuffer *progress_dialog_textbuffer;
@@ -817,18 +802,28 @@
   GNUNET_free (item->filename);
 }
 
-void
+
+static void
 add_item (struct AddDirClientContext *adcc, GtkTreeStore *ts,
-  struct GNUNET_FS_ShareTreeItem *item, GtkTreeIter *parent, GtkTreeIter 
*sibling,
-  GtkTreeIter *item_iter)
+         struct GNUNET_FS_ShareTreeItem *item, 
+         GtkTreeIter *parent, 
+         GtkTreeIter *sibling,
+         GtkTreeIter *item_iter)
 {
   char *file_size_fancy;
   struct GNUNET_FS_FileInformation *fi;
   GtkTreeRowReference *row_reference;
   GtkTreePath *path;
+  struct stat sbuf;
+  
+  if (0 != stat (item->filename,
+                &sbuf))
+  {
+    GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "stat", item->filename);
+    return;
+  }
 
   gtk_tree_store_insert_after (ts, item_iter, parent, sibling);
-
   path = gtk_tree_model_get_path (GTK_TREE_MODEL (ts), item_iter);
   row_reference = gtk_tree_row_reference_new (GTK_TREE_MODEL (ts), path);
   gtk_tree_path_free (path);
@@ -836,7 +831,7 @@
   if (item->is_directory)
   {
     GNUNET_CONTAINER_meta_data_delete (item->meta,
-        EXTRACTOR_METATYPE_MIMETYPE, NULL, 0);
+                                      EXTRACTOR_METATYPE_MIMETYPE, NULL, 0);
     GNUNET_FS_meta_data_make_directory (item->meta);
     GNUNET_FS_uri_ksk_add_keyword (item->ksk_uri, GNUNET_FS_DIRECTORY_MIME,
         GNUNET_NO);
@@ -856,7 +851,8 @@
   if (item->is_directory)
     file_size_fancy = GNUNET_strdup (MARKER_DIR_FILE_SIZE);
   else
-    file_size_fancy = GNUNET_STRINGS_byte_size_fancy (item->file_size);
+    file_size_fancy = GNUNET_STRINGS_byte_size_fancy (sbuf.st_size);
+  
   gtk_tree_store_set (ts, item_iter, 0, file_size_fancy,
       1, (gboolean) adcc->directory_scan_do_index,
       2, item->short_filename,
@@ -870,21 +866,23 @@
   GNUNET_free (item->filename);
 }
 
+
 /* Used to avoid recursion */
+// FIXME: we should probably use recursion instead ;-).
 struct AddShareItemsStack
 {
   struct AddShareItemsStack *parent;
   GtkTreeIter last_added;
 };
 
+
 /**
  * Traverse the share tree and add it to the tree store
- * Set "discard" to GNUNET_YES to force the tree to be destroyed
- * without processing (it is destroyed either way).
+ *
  */
-void
+static void
 add_share_items_to_treestore (struct AddDirClientContext *adcc,
-    struct GNUNET_FS_ShareTreeItem *toplevel, int discard)
+                             struct GNUNET_FS_ShareTreeItem *toplevel)
 {
   struct MainPublishingDialogContext *ctx = adcc->ctx;
   GtkTreeStore *ts = GTK_TREE_STORE (ctx->file_info_treemodel);
@@ -893,33 +891,22 @@
   struct GNUNET_FS_ShareTreeItem *item, *next;
   struct AddShareItemsStack *stack;
 
-  if (!discard)
-  {
-    stack = GNUNET_malloc (sizeof (struct AddShareItemsStack));
-    parent_iter = NULL;
-    sibling_iter = NULL;
-  }
+  stack = GNUNET_malloc (sizeof (struct AddShareItemsStack));
+  parent_iter = NULL;
+  sibling_iter = NULL;  
   for (item = toplevel; item != NULL; item = next)
   {
-    if (!discard)
-    {
-      add_item (adcc, ts, item, parent_iter, sibling_iter, &stack->last_added);
-      sibling_iter = &stack->last_added;
-    }
-    else
-      discard_item (item);
+    add_item (adcc, ts, item, parent_iter, sibling_iter, &stack->last_added);
+    sibling_iter = &stack->last_added;
     if (item->is_directory)
     {
       if (item->children_head != NULL)
       {
-        if (!discard)
-        {
-          struct AddShareItemsStack *child = GNUNET_malloc (sizeof (struct 
AddShareItemsStack));
-          child->parent = stack;
-          sibling_iter = NULL;
-          parent_iter = &stack->last_added;
-          stack = child;
-        }
+       struct AddShareItemsStack *child = GNUNET_malloc (sizeof (struct 
AddShareItemsStack));
+       child->parent = stack;
+       sibling_iter = NULL;
+       parent_iter = &stack->last_added;
+       stack = child;      
         next = item->children_head;
         continue;
       }
@@ -929,118 +916,62 @@
       if (item->parent != NULL)
       {
         next = item->parent;
-        if (!discard)
-        {
-          struct AddShareItemsStack *child;
-          sibling_iter = &stack->parent->last_added;
-          parent_iter = stack->parent->parent != NULL ? 
&stack->parent->parent->last_added : NULL;
-          child = stack;
-          stack = stack->parent;
-          GNUNET_free (child);
-        }
-        GNUNET_free (item);
+       struct AddShareItemsStack *child;
+       sibling_iter = &stack->parent->last_added;
+       parent_iter = stack->parent->parent != NULL ? 
&stack->parent->parent->last_added : NULL;
+       child = stack;
+       stack = stack->parent;
         item = next;
       }
       else
         break;
     }
-    GNUNET_free (item);
   }
-  if (!discard)
-    GNUNET_free (stack);
+  GNUNET_free (stack);
 }
 
+
 static void
 close_scan (struct AddDirClientContext *adcc)
 {
   gtk_widget_destroy (adcc->progress_dialog);
   g_object_unref (G_OBJECT (adcc->progress_dialog_builder));  
   GNUNET_CONTAINER_DLL_remove (adcc->ctx->adddir_head,
-      adcc->ctx->adddir_tail, adcc);
+                              adcc->ctx->adddir_tail, 
+                              adcc);
   update_selectivity (adcc->ctx);
   GNUNET_free (adcc);
 }
 
-static void
-complete_scan (struct AddDirClientContext *adcc)
-{
-  /* Pressing OK shouldn't work until we have the results */
-  if (adcc->directory_scan_result != NULL)
-  {
-    add_share_items_to_treestore (adcc, adcc->directory_scan_result,
-        adcc->cancelling ? GNUNET_YES : GNUNET_NO);
-    adcc->directory_scan_result = NULL;
-    update_selectivity (adcc->ctx);
-    close_scan (adcc);
-  }
-}
 
-static int
-cancel_scan (struct AddDirClientContext *adcc)
+void
+GNUNET_FS_GTK_progress_dialog_cancel_button_clicked_cb (GtkButton *button,
+                                                       void *cls)
 {
-  int result = GNUNET_YES;
-  /* User wants to cancel */
-  adcc->cancelling = GNUNET_YES;
+  struct AddDirClientContext *adcc = cls;
+
   if (adcc->ds != NULL)
   {
     /* Still scanning - signal the scanner to finish */
     GNUNET_FS_directory_scan_abort (adcc->ds);
-    result = GNUNET_NO;
+    adcc->ds = NULL;
   }
-  if (adcc->directory_scan_result != NULL)
-  {
-    /* Not scanning anymore - discard the results of the scan and close */
-    add_share_items_to_treestore (adcc, adcc->directory_scan_result, 
GNUNET_YES);
-    adcc->directory_scan_result = NULL;
-    close_scan (adcc);
-    result = GNUNET_YES;
-  }
-  return result;
+  close_scan (adcc);
 }
 
-void
-GNUNET_FS_GTK_progress_dialog_ok_button_clicked_cb (GtkButton *button,
-    struct AddDirClientContext *adcc)
-{
-  complete_scan (adcc);
-}
 
-void
-GNUNET_FS_GTK_progress_dialog_cancel_button_clicked_cb (GtkButton *button,
-    struct AddDirClientContext *adcc)
-{
-  cancel_scan (adcc);
-}
-
 gboolean
 GNUNET_FS_GTK_progress_dialog_delete_event_cb (GtkWidget *widget,
-    GdkEvent * event, struct AddDirClientContext *adcc)
+                                              GdkEvent * event,
+                                              void *cls)
 {
   /* Don't allow GTK to kill the window, until the scan is finished */
-  return cancel_scan (adcc) == GNUNET_NO;
+  return GNUNET_NO;
 }
 
-static void
-directory_trim_complete (void *cls,
-    const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  struct AddDirClientContext *adcc = cls;
-  adcc->directory_scan_result = adcc->directory_scan_intermediary_result;
-  if (adcc->cancelling)
-  {
-    cancel_scan (adcc);
-  }
-  else
-  {
-    gtk_widget_set_sensitive (GTK_WIDGET (adcc->progress_dialog_ok), TRUE);
-    gtk_widget_set_visible (GTK_WIDGET (adcc->progress_dialog_bar), FALSE);
-    if (!adcc->keep)
-      complete_scan (adcc);
-  }
-}
 
 static void
-directory_scan_cb (void *cls, struct GNUNET_FS_DirScanner *ds,
+directory_scan_cb (void *cls, 
                   const char *filename, int is_directory,
                   enum GNUNET_FS_DirScannerProgressUpdateReason reason)
 {
@@ -1050,69 +981,62 @@
   gtk_progress_bar_pulse (adcc->progress_dialog_bar);
   switch (reason)
   {
-    case GNUNET_FS_DIRSCANNER_FILE_START:
-      if (filename != NULL)
-      {
-        if (is_directory)
-          GNUNET_asprintf (&s, _("Scanning directory `%s'.\n"), filename);
-        else
-          GNUNET_asprintf (&s, _("Scanning file `%s'.\n"), filename);
-        insert_progress_dialog_text (adcc, s);
-        GNUNET_free (s);
-      }
-      break;
-    case GNUNET_FS_DIRSCANNER_DOES_NOT_EXIST:
-      if (filename != NULL)
-      {
-        GNUNET_asprintf (&s,
-            _("Failed to scan `%s', because it does not exist.\n"),
-            filename);
-        adcc->keep = 1;
-        insert_progress_dialog_text (adcc, s);
-        GNUNET_free (s);
-      }
-      break;
-    case GNUNET_FS_DIRSCANNER_INTERNAL_ERROR:
-      if (filename != NULL)
-      {
-        GNUNET_asprintf (&s,
-            _("Scanner was about to scan `%s', but is now stopping.\n"),
-            filename);
-        insert_progress_dialog_text (adcc, s);
-        GNUNET_free (s);
-      }
+  case GNUNET_FS_DIRSCANNER_FILE_START:
+    if (filename != NULL)
+    {
+      if (is_directory)
+       GNUNET_asprintf (&s, _("Scanning directory `%s'.\n"), filename);
       else
-        insert_progress_dialog_text (adcc, _("Scanner is stopping.\n"));
-      break;
-    case GNUNET_FS_DIRSCANNER_FINISHED:
-      insert_progress_dialog_text (adcc, _("Scanner has finished.\n"));
-      break;
-    case GNUNET_FS_DIRSCANNER_ALL_COUNTED:
-      // FIXME...
-      break;
-    case GNUNET_FS_DIRSCANNER_SUBTREE_COUNTED:
-      // FIXME...
-      break;
-    case GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED:
-      // FIXME...
-      GNUNET_asprintf (&s,_("Got unknown scanner update with filename 
`%s'.\n"),
-          filename);
+       GNUNET_asprintf (&s, _("Scanning file `%s'.\n"), filename);
       insert_progress_dialog_text (adcc, s);
       GNUNET_free (s);
-      adcc->directory_scan_intermediary_result = 
GNUNET_FS_directory_scan_get_result (ds);
-      GNUNET_FS_share_tree_trim (adcc->directory_scan_intermediary_result);
-      // FIXME...
-      directory_trim_complete (adcc, NULL);      
-      adcc->ds = NULL;
-      adcc->keep = 1;
-      break;
+    }
+    break;
+  case GNUNET_FS_DIRSCANNER_FILE_IGNORED:
+    if (filename != NULL)
+    {
+      GNUNET_asprintf (&s,
+                      _("Failed to scan `%s', because it does not exist.\n"),
+                      filename);
+      insert_progress_dialog_text (adcc, s);
+      GNUNET_free (s);
+    }
+    break;
+  case GNUNET_FS_DIRSCANNER_ALL_COUNTED:
+    // FIXME...
+    break;
+  case GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED:
+    // FIXME...
+    break;
+  case GNUNET_FS_DIRSCANNER_INTERNAL_ERROR:
+    insert_progress_dialog_text (adcc, _("Operation failed (press cancel)\n"));
+    GNUNET_FS_directory_scan_abort (adcc->ds);
+    adcc->ds = NULL;
+    break;
+  case GNUNET_FS_DIRSCANNER_FINISHED:
+    insert_progress_dialog_text (adcc, _("Scanner has finished.\n"));
+    adcc->directory_scan_result = GNUNET_FS_directory_scan_get_result 
(adcc->ds);
+    adcc->ds = NULL;
+    GNUNET_FS_share_tree_trim (adcc->directory_scan_result);
+    add_share_items_to_treestore (adcc, 
+                                 adcc->directory_scan_result);
+    GNUNET_FS_share_tree_free (adcc->directory_scan_result);
+    adcc->directory_scan_result = NULL;
+    update_selectivity (adcc->ctx);
+    close_scan (adcc);
+    break;
+  default:
+    GNUNET_break (0);
+    break;
   }
 }
 
 
-void
-scan_file_or_directory (struct MainPublishingDialogContext *ctx, gchar 
*filename,
-    struct GNUNET_FS_BlockOptions *bo, int do_index)
+static void
+scan_file_or_directory (struct MainPublishingDialogContext *ctx, 
+                       gchar *filename,
+                       struct GNUNET_FS_BlockOptions *bo, 
+                       int do_index)
 {
   struct AddDirClientContext *adcc;
   GtkTextIter iter;
@@ -1133,9 +1057,6 @@
   adcc->progress_dialog_bar = GTK_PROGRESS_BAR (gtk_builder_get_object (
       adcc->progress_dialog_builder,
       "GNUNET_FS_GTK_progress_dialog_progressbar"));
-  adcc->progress_dialog_ok = GTK_BUTTON (gtk_builder_get_object (
-      adcc->progress_dialog_builder,
-      "GNUNET_FS_GTK_progress_dialog_ok_button"));
   adcc->progress_dialog_cancel = GTK_BUTTON (gtk_builder_get_object (
       adcc->progress_dialog_builder,
       "GNUNET_FS_GTK_progress_dialog_cancel_button"));
@@ -1145,8 +1066,6 @@
   adcc->progress_dialog_textbuffer = GTK_TEXT_BUFFER (
       gtk_builder_get_object (adcc->progress_dialog_builder,
       "GNUNET_FS_GTK_progress_dialog_textbuffer"));
-  gtk_widget_set_sensitive (GTK_WIDGET (adcc->progress_dialog_ok), FALSE);
-
   gtk_text_buffer_get_end_iter (adcc->progress_dialog_textbuffer,
       &iter);
   adcc->progress_dialog_textmark = gtk_text_buffer_create_mark (
@@ -1159,6 +1078,7 @@
   update_selectivity (ctx);
 }
 
+
 void
 GNUNET_GTK_publish_directory_dialog_response_cb (GtkDialog * dialog,
                                                  gint response_id,




reply via email to

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