gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r4911 - in gnunet-gtk: . src/plugins/fs


From: gnunet
Subject: [GNUnet-SVN] r4911 - in gnunet-gtk: . src/plugins/fs
Date: Sun, 3 Jun 2007 15:18:22 -0600 (MDT)

Author: grothoff
Date: 2007-06-03 15:18:21 -0600 (Sun, 03 Jun 2007)
New Revision: 4911

Modified:
   gnunet-gtk/TODO
   gnunet-gtk/gnunet-gtk.glade
   gnunet-gtk/src/plugins/fs/fs.c
   gnunet-gtk/src/plugins/fs/helper.c
   gnunet-gtk/src/plugins/fs/namespace.c
Log:
implementing namespace update

Modified: gnunet-gtk/TODO
===================================================================
--- gnunet-gtk/TODO     2007-06-03 21:18:07 UTC (rev 4910)
+++ gnunet-gtk/TODO     2007-06-03 21:18:21 UTC (rev 4911)
@@ -15,8 +15,6 @@
   => currently, "infoMessage" opens a window that cannot be closed
      and that does not have a frame!!! [RC]
 - re-enable advanced/namespace menus  [RC]
-  + namespace addition  => untested
-  + namespace update    => FIX implementation!
   + namespace search    => FIX implementation (list namespaces!)
   + design and start use of short/nice namespace names/search URIs
 - re-enable advanced/collection menus

Modified: gnunet-gtk/gnunet-gtk.glade
===================================================================
--- gnunet-gtk/gnunet-gtk.glade 2007-06-03 21:18:07 UTC (rev 4910)
+++ gnunet-gtk/gnunet-gtk.glade 2007-06-03 21:18:21 UTC (rev 4911)
@@ -6557,7 +6557,7 @@
          </child>
 
          <child>
-           <widget class="GtkButton" id="button9">
+           <widget class="GtkButton" id="namespaceInsertOkButton">
              <property name="visible">True</property>
              <property name="tooltip" translatable="yes">Confirm the displayed 
meta-data and keywords and proceed with the publication.</property>
              <property name="can_default">True</property>
@@ -6805,6 +6805,7 @@
              <property name="add_tearoffs">False</property>
              <property name="has_frame">True</property>
              <property name="focus_on_click">True</property>
+             <signal name="changed" 
handler="on_updateIntervalComboEntry_changed_" object="namespaceInsertOkButton" 
last_modification_time="Sun, 03 Jun 2007 20:23:49 GMT"/>
            </widget>
            <packing>
              <property name="padding">0</property>
@@ -7327,7 +7328,7 @@
          </child>
 
          <child>
-           <widget class="GtkButton" id="okbutton1">
+           <widget class="GtkButton" id="namespaceUpdateOkButton">
              <property name="visible">True</property>
              <property name="can_default">True</property>
              <property name="can_focus">True</property>
@@ -7579,6 +7580,7 @@
                  <property name="add_tearoffs">False</property>
                  <property name="has_frame">True</property>
                  <property name="focus_on_click">True</property>
+                 <signal name="changed" 
handler="on_updateIntervalComboBoxEntry_changed" 
object="namespaceUpdateOkButton" last_modification_time="Sun, 03 Jun 2007 
21:07:44 GMT"/>
                </widget>
                <packing>
                  <property name="padding">0</property>

Modified: gnunet-gtk/src/plugins/fs/fs.c
===================================================================
--- gnunet-gtk/src/plugins/fs/fs.c      2007-06-03 21:18:07 UTC (rev 4910)
+++ gnunet-gtk/src/plugins/fs/fs.c      2007-06-03 21:18:21 UTC (rev 4911)
@@ -28,6 +28,7 @@
 #include <GNUnet/gnunet_collection_lib.h>
 #include <gdk/gdk.h>
 #include "fs.h"
+#include "meta.h"
 #include "download.h"
 #include "search.h"
 #include "upload.h"
@@ -63,7 +64,25 @@
 static unsigned int last_y;
 
 
+void on_updateIntervalComboEntry_changed_fs(GtkWidget * button,
+                                           GtkWidget * entryBox) {
+  const char * time;
+  TIME_T t;
+  GtkEntry * entry;
 
+  entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(entryBox)));
+  time = gtk_entry_get_text(entry);
+  if (OK != parseTimeInterval(time,
+                             &t)) {
+    gtk_widget_set_sensitive(button,
+                            FALSE);
+  } else {
+    gtk_widget_set_sensitive(button,
+                            TRUE);
+  }
+}
+
+
 /**
  * The selection of the download summary changed.
  * Update button status.

Modified: gnunet-gtk/src/plugins/fs/helper.c
===================================================================
--- gnunet-gtk/src/plugins/fs/helper.c  2007-06-03 21:18:07 UTC (rev 4910)
+++ gnunet-gtk/src/plugins/fs/helper.c  2007-06-03 21:18:21 UTC (rev 4911)
@@ -50,7 +50,7 @@
 
   while (t[pos] != '\0') {
     start = pos;
-    while ( (t[pos] != ' ') &&
+    while ( (isdigit(t[pos])) &&
            (t[pos] != '\0') )
       pos++;
     tmp = STRNDUP(&t[start],
@@ -87,6 +87,35 @@
                              strlen(_("days"))))
       ret += cronDAYS  * val;
     else
+    if (0 == strncasecmp(&t[start],
+                        _("minute"),
+                        strlen(_("minute"))))
+      ret += cronMINUTES * val;
+    else if (0 == strncasecmp(&t[start],
+                             _("second"),
+                             strlen(_("second"))))
+      ret += cronSECONDS * val;
+    else if (0 == strncasecmp(&t[start],
+                             _("hour"),
+                             strlen(_("hour"))))
+      ret += cronHOURS * val;
+    else if (0 == strncasecmp(&t[start],
+                             _("day"),
+                             strlen(_("day"))))
+      ret += cronDAYS  * val;
+    else if (0 == strncasecmp(&t[start],
+                        "m",
+                        strlen("m")))
+      ret += cronMINUTES * val;
+    else if (0 == strncasecmp(&t[start],
+                             "s",
+                             strlen("s")))
+      ret += cronSECONDS * val;
+    else if (0 == strncasecmp(&t[start],
+                             "h",
+                             strlen("h")))
+      ret += cronHOURS * val;
+    else
       return SYSERR; /* parse error */
     while ( t[pos] == ' ')
       pos++;

Modified: gnunet-gtk/src/plugins/fs/namespace.c
===================================================================
--- gnunet-gtk/src/plugins/fs/namespace.c       2007-06-03 21:18:07 UTC (rev 
4910)
+++ gnunet-gtk/src/plugins/fs/namespace.c       2007-06-03 21:18:21 UTC (rev 
4911)
@@ -88,10 +88,10 @@
         (TRUE == gtk_tree_selection_get_selected(ns,
                                                  NULL,
                                                  &iter)) ) {
-      
+      freq = NULL;
       gtk_tree_model_get(list->model,
                         &iter,
-                        IN_NAMESPACE_PUB_FREQ_STRING, &freq,
+                        IN_NAMESPACE_PUB_DATE_STRING, &freq,
                         -1);
       if ( (freq != NULL) &&
           (0 != strcmp(freq, _("never"))) )
@@ -147,7 +147,7 @@
                          GTK_TREE_MODEL(model));
   
gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(resultList)),
                              GTK_SELECTION_SINGLE);
-  g_signal_connect_data(content_selection,
+  g_signal_connect_data(gtk_tree_view_get_selection(GTK_TREE_VIEW(resultList)),
                        "changed",
                        G_CALLBACK(&on_namespaceContentSelectionChanged),
                        NULL,
@@ -380,6 +380,8 @@
     date = STRDUP(_("never"));
   else
     date = GN_CTIME(&nextPublicationTime);
+  if (date[strlen(date)-1] == '\n')
+    date[strlen(date)-1] = '\0';
 
   freq = updateIntervalToString(publicationFrequency);
   size_h = string_get_fancy_byte_size(size);
@@ -680,6 +682,7 @@
   GtkWidget * page;
   GtkWidget * notebook;
   GtkWidget * dialog;
+  GtkWidget * updateIntervalComboBox;
   HashCode512 nextId;
   IUC cls;
   gint num;
@@ -710,10 +713,19 @@
                                "namespaceInsertDialog");
   gtk_dialog_set_default_response(GTK_DIALOG(dialog),
                                  GTK_RESPONSE_OK);
+
+  updateIntervalComboBox = glade_xml_get_widget(metaXML,
+                                               "updateIntervalComboBoxEntry");
+  gtk_combo_box_set_active(GTK_COMBO_BOX(updateIntervalComboBox),
+                          0);
+
+
   if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
     if (OK != tryParseTimeInterval(metaXML,
                                   "updateIntervalComboBoxEntry",
                                   &cls.updateInterval)) {
+      /* this should be impossible - OK button is
+        deactivated while parse errors are there */
       gtk_widget_destroy(dialog);
       UNREF(metaXML);
       metaXML = NULL;
@@ -764,176 +776,172 @@
 
 
 /**
- * FIXME!!!
+ * User clicked on update; launch update dialog
+ * and perform namespace content update.
  */ 
 void on_namespaceUpdateButton_clicked_fs(GtkWidget * dummy1,
                                         GtkWidget * dummy2) {
-  const char * identifierName;
   NamespaceList * list;
-  GtkWidget * nameLine;
-  GtkWidget * dialog;
-  GtkWidget * spin;
-  GtkWidget * update;
   GtkTreeIter iter;
-  struct ECRS_MetaData * meta;
   HashCode512 nextId;
-  HashCode512 prevId;
+  HashCode512 lastId;
   GtkTreeSelection * selection;
   IUC cls;
   char * last;
   char * next;
   char * freq;
+  EncName nextnext;
+  GtkWidget * nextEntryLine;
+  GtkWidget * identifierLabel;
+  GtkWidget * updateIntervalComboBox;
+  GtkWidget * dialog;
+  GtkWidget * mdialog;
+  GtkWidget * notebook;
+  GtkWidget * page;
+  GtkTreeModel * model;
+  gint num;
+  const char * nn_str;
 
   DEBUG_BEGIN();
-
+  /* find out which namespace this is about */
+  notebook
+    = glade_xml_get_widget(getMainXML(),
+                          "localNamespacesNotebook");
+  num = gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
+  GE_ASSERT(ectx, num != -1);
+  page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook),
+                                  num); 
+  list = head;
+  while ( (list != NULL) &&
+         (list->namespacepage != page) )
+    list = list->next;
+  if (list == NULL) {
+    GE_BREAK(ectx, 0);
+    return;
+  }
+  cls.namespaceName = list->name;
+  
+  /* find out what we are updating */
+  selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(list->treeview));
+  if (TRUE != gtk_tree_selection_get_selected(selection,
+                                             NULL,
+                                             &iter)) {
+    GE_BREAK(ectx, 0);
+    return;
+  }
   gtk_tree_model_get(list->model,
                     &iter,
                     IN_NAMESPACE_LAST_STRING, &last,
                     IN_NAMESPACE_NEXT_STRING, &next,
                     IN_NAMESPACE_PUB_FREQ_STRING, &freq,
                     -1);
-  metaXML
-    = glade_xml_new(getGladeFileName(),
-                   "namespaceUpdateDialog",
-                   PACKAGE_NAME);
-  connectGladeWithPlugins(metaXML);
-
-
-
-  nameLine = glade_xml_get_widget(metaXML,
-                                 "identifierLabel");
-  gtk_label_set_text(GTK_LABEL(nameLine),
-                    next);
-  if (OK != enc2hash(next,
-                    &cls.thisId)) {
-    GE_BREAK(ectx, 0);
-    UNREF(metaXML);
-    metaXML = NULL;
-    if (last != NULL)
-      free(last);
-    if (next != NULL)
-      free(next);
-    if (freq != NULL)
-      free(freq);
+  if ( (last == NULL) ||
+       (next == NULL) ||
+       (freq == NULL) ) {
+    GE_BREAK(NULL, 0);
     return;
   }
-  if (OK == enc2hash(last,
-                    &prevId)) {
-    cls.lastId = &prevId;
-  } else {
-    GE_BREAK(ectx, 0); /* should not happen, try to continue */
-    cls.lastId = NULL;
-  }
-  nameLine = glade_xml_get_widget(metaXML,
-                                 "nextIdentifierEntry");
   if (OK != parseTimeInterval(freq,
                              &cls.updateInterval)) {
     GE_BREAK(ectx, 0);
     cls.updateInterval = ECRS_SBLOCK_UPDATE_SPORADIC;
   }
-  if (cls.updateInterval == ECRS_SBLOCK_UPDATE_SPORADIC) {
-    gtk_entry_set_text(GTK_ENTRY(nameLine),
-                      "");
-  } else {
-    EncName updateName;
 
-    if (OK != NS_computeNextId(ectx,
+  /* create update dialog */
+  metaXML
+    = glade_xml_new(getGladeFileName(),
+                   "namespaceUpdateDialog",
+                   PACKAGE_NAME);
+  connectGladeWithPlugins(metaXML);
+  dialog = glade_xml_get_widget(metaXML,
+                               "namespaceUpdateDialog");
+  gtk_dialog_set_default_response(GTK_DIALOG(dialog),
+                                 GTK_RESPONSE_OK);
+  identifierLabel = glade_xml_get_widget(metaXML,
+                                        "identifierLabel");
+  gtk_label_set_text(GTK_LABEL(identifierLabel),
+                    next);
+  enc2hash(last, &lastId);
+  cls.lastId = &lastId;
+  enc2hash(next, &cls.thisId);
+  
+  nextEntryLine = glade_xml_get_widget(metaXML,
+                                      "nextIdentifierEntry");
+  if ( (cls.updateInterval != ECRS_SBLOCK_UPDATE_SPORADIC) &&
+       (OK == NS_computeNextId(NULL,
                               cfg,
-                              list->name,
-                              &prevId,
+                              cls.namespaceName,
+                              &lastId,
                               &cls.thisId,
                               cls.updateInterval,
-                              &nextId)) {
-      GE_BREAK(ectx, 0);
-      UNREF(metaXML);
-      metaXML = NULL;
-      if (last != NULL)
-       free(last);
-      if (next != NULL)
-       free(next);
-      if (freq != NULL)
-       free(freq);
-      return;
-    }
+                              &nextId)) ) {
     hash2enc(&nextId,
-            &updateName);
-    gtk_entry_set_text(GTK_ENTRY(nameLine),
-                      (const char*) &updateName);
-    gtk_entry_set_editable(GTK_ENTRY(nameLine),
-                          FALSE);
+            &nextnext);
+    gtk_entry_set_text(GTK_ENTRY(nextEntryLine),
+                      (char*) &nextnext);
+    gtk_widget_set_sensitive(nextEntryLine,
+                            FALSE);
   }
+  /* set update interval in dialog to
+     the existing update interval */
+  updateIntervalComboBox = glade_xml_get_widget(metaXML,
+                                               
"namespaceUpdateIntervalComboBoxEntry");
+  model = gtk_combo_box_get_model(GTK_COMBO_BOX(updateIntervalComboBox));
+  gtk_list_store_insert(GTK_LIST_STORE(model),
+                       &iter,
+                       0);
+  gtk_list_store_set(GTK_LIST_STORE(model),
+                    &iter,
+                    0, freq,
+                    -1);
+  gtk_combo_box_set_active(GTK_COMBO_BOX(updateIntervalComboBox),
+                          0);
 
-  update = glade_xml_get_widget(metaXML,
-                               "namespaceUpdateIntervalComboBoxEntry");
-  gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(update))),
-                    freq);
-  createMetaDataListTreeView(metaXML,
-                            "namespaceUpdateMetaDataTreeView",
-                            "namespaceUpdatePreviewImage",
-                            meta);
-  createMetaTypeComboBox(metaXML,
-                        "namespaceUpdateMetaTypeComboBox");
-  dialog = glade_xml_get_widget(metaXML,
-                               "namespaceUpdateDialog");
-  gtk_dialog_set_default_response(GTK_DIALOG(dialog),
-                                 GTK_RESPONSE_OK);
-  if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
-    const char * error = NULL;
-    nameLine = glade_xml_get_widget(metaXML,
-                                   "nextIdentifierEntry");
-    if (OK != tryParseTimeInterval(metaXML,
-                                  "namespaceUpdateIntervalComboBoxEntry",
-                                  &cls.updateInterval)) {
-      error = _("Failed to parse given time interval!");
-      identifierName = ""; /* to make gcc happy */
-    } else {
-      identifierName = gtk_entry_get_text(GTK_ENTRY(nameLine));
-      if ( (cls.updateInterval != ECRS_SBLOCK_UPDATE_NONE) &&
-          ( (identifierName == NULL) ||
-            (strlen(identifierName) == 0)) ) {
-       error = _("You must specify an identifier for the next publication.");
-      }
-    }
-    if (error != NULL) {
-      gtk_widget_destroy(dialog);
-      UNREF(metaXML);
-      metaXML = NULL;
-      dialog = gtk_message_dialog_new
-       (NULL,
-        GTK_DIALOG_MODAL,
-        GTK_MESSAGE_ERROR,
-        GTK_BUTTONS_CLOSE,
-        error);
-      gtk_dialog_run(GTK_DIALOG(dialog));
-      gtk_widget_destroy(dialog);
-      FREENONNULL(last);
-      FREENONNULL(next);
-      FREENONNULL(freq);
-      return;
-    }
-    hash(identifierName,
-        strlen(identifierName),
-        &nextId);
-    cls.nextId = &nextId;
-    spin = glade_xml_get_widget(metaXML,
-                               "namespaceUpdateAnonymitySpinButton");
-    cls.anonymityLevel
-      = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin));
+  /* run update dialog */
+  if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK) 
+    goto CLEANUP;
+  gtk_widget_hide(dialog);
 
-    ggc_tree_selection_selected_foreach
-      (selection,
-       &addToNamespaceCB,
-       &cls);
+  /* get data from update dialog */
+  nn_str = gtk_entry_get_text(GTK_ENTRY(nextEntryLine));
+  if (nn_str == NULL)
+    nn_str = "";
+  hash(nn_str,
+       strlen(nn_str),
+       &nextId);
+  cls.nextId = &nextId;
+
+  if (OK != tryParseTimeInterval(metaXML,
+                                "namespaceUpdateIntervalComboBoxEntry",
+                                &cls.updateInterval)) {
+    /* This should be impossible since the
+       the OK button is deactivated while parse errors are present */
+    mdialog = gtk_message_dialog_new
+      (NULL,
+       GTK_DIALOG_MODAL,
+       GTK_MESSAGE_ERROR,
+       GTK_BUTTONS_CLOSE,
+       _("Failed to parse given time interval!"));
+    gtk_dialog_run(GTK_DIALOG(mdialog));
+    gtk_widget_destroy(mdialog);
+    goto CLEANUP;
   }
+  cls.anonymityLevel
+    = getSpinButtonValue(metaXML,
+                        "namespaceUpdateAnonymitySpinButton");
+
+  /* run actual update */
+  ggc_tree_selection_selected_foreach
+    (content_selection,
+     &addToNamespaceCB,
+     &cls);
+ CLEANUP:
   gtk_widget_destroy(dialog);
   UNREF(metaXML);
   metaXML = NULL;
-  if (last != NULL)
-    free(last);
-  if (next != NULL)
-    free(next);
-  if (freq != NULL)
-    free(freq);
+  free(last);
+  free(next);
+  free(freq);
   DEBUG_END();
 }
 





reply via email to

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