gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r29115 - in gnunet-gtk: contrib src/fs src/identity src/inc


From: gnunet
Subject: [GNUnet-SVN] r29115 - in gnunet-gtk: contrib src/fs src/identity src/include src/lib
Date: Sun, 8 Sep 2013 20:02:18 +0200

Author: grothoff
Date: 2013-09-08 20:02:18 +0200 (Sun, 08 Sep 2013)
New Revision: 29115

Added:
   gnunet-gtk/src/lib/misc.c
Modified:
   gnunet-gtk/contrib/gnunet_identity_gtk_advertise_dialog.glade
   gnunet-gtk/src/fs/gnunet-fs-gtk.h
   gnunet-gtk/src/fs/gnunet-fs-gtk_anonymity-widgets.c
   gnunet-gtk/src/fs/gnunet-fs-gtk_anonymity-widgets.h
   gnunet-gtk/src/fs/gnunet-fs-gtk_common.c
   gnunet-gtk/src/fs/gnunet-fs-gtk_common.h
   gnunet-gtk/src/fs/gnunet-fs-gtk_publish-dialog.c
   gnunet-gtk/src/fs/gnunet-fs-gtk_publish-edit-dialog.c
   gnunet-gtk/src/identity/gnunet-identity-gtk_advertise.c
   gnunet-gtk/src/include/gnunet_gtk.h
   gnunet-gtk/src/lib/Makefile.am
Log:
implementing #3023, moving some functions from fs to lib as they are also 
needed in identity

Modified: gnunet-gtk/contrib/gnunet_identity_gtk_advertise_dialog.glade
===================================================================
--- gnunet-gtk/contrib/gnunet_identity_gtk_advertise_dialog.glade       
2013-09-08 17:41:42 UTC (rev 29114)
+++ gnunet-gtk/contrib/gnunet_identity_gtk_advertise_dialog.glade       
2013-09-08 18:02:18 UTC (rev 29115)
@@ -2,17 +2,6 @@
 <interface>
   <requires lib="gtk+" version="2.20"/>
   <!-- interface-naming-policy project-wide -->
-  <object class="GtkAdjustment" 
id="GNUNET_GTK_identity_advertise_keywords_hadj">
-    <property name="upper">100</property>
-    <property name="step_increment">1</property>
-    <property name="page_increment">10</property>
-  </object>
-  <object class="GtkListStore" 
id="GNUNET_GTK_identity_advertise_keywords_liststore">
-    <columns>
-      <!-- column-name Keyword -->
-      <column type="gchararray"/>
-    </columns>
-  </object>
   <object class="GtkDialog" id="GNUNET_GTK_identity_advertise_dialog">
     <property name="can_focus">False</property>
     <property name="border_width">5</property>
@@ -355,6 +344,7 @@
                           <object class="GtkComboBox" 
id="GNUNET_GTK_identity_advertise_anonymity_combobox">
                             <property name="visible">True</property>
                             <property name="can_focus">False</property>
+                            <property 
name="model">anonymity_level_liststore</property>
                             <property name="active">1</property>
                             <child>
                               <object class="GtkCellRendererText" 
id="GNUNET_GTK_identity_advertise_anonymity_combobox_renderer"/>
@@ -560,6 +550,17 @@
       <action-widget 
response="-6">GNUNET_GTK_identity_advertise_cancel_button</action-widget>
     </action-widgets>
   </object>
+  <object class="GtkAdjustment" 
id="GNUNET_GTK_identity_advertise_keywords_hadj">
+    <property name="upper">100</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
+  </object>
+  <object class="GtkListStore" 
id="GNUNET_GTK_identity_advertise_keywords_liststore">
+    <columns>
+      <!-- column-name Keyword -->
+      <column type="gchararray"/>
+    </columns>
+  </object>
   <object class="GtkAdjustment" 
id="GNUNET_GTK_identity_advertise_keywords_vadj">
     <property name="upper">100</property>
     <property name="step_increment">1</property>
@@ -585,14 +586,6 @@
     <property name="step_increment">1</property>
     <property name="page_increment">10</property>
   </object>
-  <object class="GtkListStore" 
id="GNUNET_GTK_identity_metadata_types_liststore">
-    <columns>
-      <!-- column-name type_as_string -->
-      <column type="gchararray"/>
-      <!-- column-name type_as_enum -->
-      <column type="guint"/>
-    </columns>
-  </object>
   <object class="GtkAdjustment" id="expiration_year_adjustment">
     <property name="upper">9999</property>
     <property name="step_increment">1</property>
@@ -608,4 +601,39 @@
     <property name="step_increment">1</property>
     <property name="page_increment">10</property>
   </object>
+  <object class="GtkListStore" 
id="GNUNET_GTK_identity_metadata_types_liststore">
+    <columns>
+      <!-- column-name type_as_string -->
+      <column type="gchararray"/>
+      <!-- column-name type_as_enum -->
+      <column type="guint"/>
+    </columns>
+  </object>
+  <object class="GtkListStore" id="anonymity_level_liststore">
+    <columns>
+      <!-- column-name Name -->
+      <column type="gchararray"/>
+      <!-- column-name Level -->
+      <column type="guint"/>
+      <!-- column-name Color -->
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0" translatable="yes">None</col>
+        <col id="1">0</col>
+        <col id="2" translatable="yes">#AAAA00000000</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Normal</col>
+        <col id="1">1</col>
+        <col id="2" translatable="yes">#000000000000</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Paranoid</col>
+        <col id="1">10</col>
+        <col id="2" translatable="yes">#0000AAAA0000</col>
+      </row>
+    </data>
+  </object>
 </interface>

Modified: gnunet-gtk/src/fs/gnunet-fs-gtk.h
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk.h   2013-09-08 17:41:42 UTC (rev 29114)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk.h   2013-09-08 18:02:18 UTC (rev 29115)
@@ -225,28 +225,6 @@
 
 
 /**
- * Columns in the anonymity level model.
- */
-enum GNUNET_GTK_FS_MAIN_WINDOW_AnonymityLevelModelColumns
-  {
-    /**
-     * A gchararray.
-     */
-    GNUNET_GTK_FS_MAIN_WINDOW_ANONYMITY_LEVEL_MC_NAME = 0,
-
-    /**
-     * A guint.
-     */
-    GNUNET_GTK_FS_MAIN_WINDOW_ANONYMITY_LEVEL_MC_LEVEL = 1,
-    
-    /**
-     * A gchararray.
-     */
-    GNUNET_GTK_FS_MAIN_WINDOW_ANONYMITY_LEVEL_MC_COLOR = 2,
-  };
-
-
-/**
  * Columns in the search mime model.
  */
 enum GNUNET_GTK_FS_MAIN_WINDOW_SearchMimeModelColumns
@@ -350,6 +328,7 @@
 gboolean
 GNUNET_GTK_get_selected_anonymity_combo_level (GtkComboBox *combo, guint 
*p_level);
 
+
 /**
  * Set the selected anonymity level.
  * For dialogue initialization.
@@ -375,8 +354,6 @@
 gboolean
 GNUNET_GTK_select_anonymity_combo_level (GtkComboBox *combo, guint sel_level);
 
-void
-GNUNET_GTK_main_window_refresh_ns_list (struct GNUNET_GTK_MainWindowContext 
*main_ctx);
 
 #endif
 /* end of gnunet-fs-gtk.h */

Modified: gnunet-gtk/src/fs/gnunet-fs-gtk_anonymity-widgets.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_anonymity-widgets.c 2013-09-08 17:41:42 UTC 
(rev 29114)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_anonymity-widgets.c 2013-09-08 18:02:18 UTC 
(rev 29115)
@@ -75,56 +75,6 @@
 
 
 /**
- * Obtain the numeric anonymity level selected by a GtkComboBox.
- *
- * @param builder builder for looking up widgets
- * @param combo_name name of the GtkComboBox with the anonymity selection
- * @param p_level where to store the anonymity level
- * @return TRUE on success, FALSE on failure
- */
-gboolean
-GNUNET_GTK_get_selected_anonymity_level (GtkBuilder * builder,
-                                         gchar * combo_name, guint * p_level)
-{
-  GtkComboBox *combo;
-
-  combo = GTK_COMBO_BOX (gtk_builder_get_object (builder, combo_name));
-  if (!combo)
-    return FALSE;
-  return GNUNET_GTK_get_selected_anonymity_combo_level (combo, p_level);
-}
-
-
-/**
- * Obtain the numeric anonymity level selected by a GtkComboBox.
- *
- * @param combo the GtkComboBox with the anonymity selection
- * @param p_level where to store the anonymity level
- * @return TRUE on success, FALSE on failure
- */
-gboolean
-GNUNET_GTK_get_selected_anonymity_combo_level (GtkComboBox *combo, guint 
*p_level)
-{
-  GtkTreeIter iter;
-  GtkTreeModel *model;
-  guint level;
-
-  if (! gtk_combo_box_get_active_iter (combo, &iter))
-    return FALSE;
-  model = gtk_combo_box_get_model (combo);
-  if (!model)
-    return FALSE;
-  gtk_tree_model_get (model, &iter,
-                      GNUNET_GTK_FS_MAIN_WINDOW_ANONYMITY_LEVEL_MC_LEVEL,
-                      &level,
-                      -1);
-  if (p_level)
-    *p_level = level;
-  return TRUE;
-}
-
-
-/**
  * Set the anonymity level displayed by a combo box.
  *
  * @param builder the builder of the combo box
@@ -167,7 +117,7 @@
   do
   {
     gtk_tree_model_get (model, &iter,
-                        GNUNET_GTK_FS_MAIN_WINDOW_ANONYMITY_LEVEL_MC_LEVEL,
+                        GNUNET_GTK_ANONYMITY_LEVEL_MC_LEVEL,
                         &level,
                         -1);
     if (level == sel_level)

Modified: gnunet-gtk/src/fs/gnunet-fs-gtk_anonymity-widgets.h
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_anonymity-widgets.h 2013-09-08 17:41:42 UTC 
(rev 29114)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_anonymity-widgets.h 2013-09-08 18:02:18 UTC 
(rev 29115)
@@ -30,30 +30,6 @@
 
 
 /**
- * Obtain the numeric anonymity level selected by a GtkComboBox.
- *
- * @param builder builder for looking up widgets
- * @param combo_name name of the GtkComboBox with the anonymity selection
- * @param p_level where to store the anonymity level
- * @return TRUE on success, FALSE on failure
- */
-gboolean
-GNUNET_GTK_get_selected_anonymity_level (GtkBuilder * builder,
-                                         gchar * combo_name, guint * p_level);
-
-
-/**
- * Obtain the numeric anonymity level selected by a GtkComboBox.
- *
- * @param combo the GtkComboBox with the anonymity selection
- * @param p_level where to store the anonymity level
- * @return TRUE on success, FALSE on failure
- */
-gboolean
-GNUNET_GTK_get_selected_anonymity_combo_level (GtkComboBox *combo, guint 
*p_level);
-
-
-/**
  * Set the anonymity level displayed by a combo box.
  *
  * @param builder the builder of the combo box

Modified: gnunet-gtk/src/fs/gnunet-fs-gtk_common.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_common.c    2013-09-08 17:41:42 UTC (rev 
29114)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_common.c    2013-09-08 18:02:18 UTC (rev 
29115)
@@ -123,49 +123,6 @@
 
 
 /**
- * Convert the year from the spin button to an expiration
- * time (on midnight, January 1st of that year).
- *
- * @param spin button with an expiration year
- * @return expiration time in the usual GNUnet format
- */
-struct GNUNET_TIME_Absolute
-GNUNET_FS_GTK_get_expiration_time (GtkSpinButton * spin)
-{
-  struct GNUNET_TIME_Absolute ret;
-  int year;
-
-  year = gtk_spin_button_get_value_as_int (spin);
-  GNUNET_assert (year >= 0);
-  ret = GNUNET_FS_year_to_time ((unsigned int) year);
-  GNUNET_break (GNUNET_TIME_absolute_get ().abs_value_us < ret.abs_value_us);
-  return ret;
-}
-
-
-/**
- * Initialize the 'expiration_year_adjustment' of the given
- * builder to have a lower range of current-year+1 and a
- * default of current-year+2.
- *
- * @param builder builder object for which we should manipulate
- * the adjustment
- */
-void
-GNUNET_FS_GTK_setup_expiration_year_adjustment (GtkBuilder * builder)
-{
-  GtkAdjustment *aj;
-  unsigned int year;
-
-  year = GNUNET_FS_get_current_year ();
-  aj = GTK_ADJUSTMENT (gtk_builder_get_object
-                       (builder, "expiration_year_adjustment"));
-  gtk_adjustment_set_value (aj, year + 2);
-  gtk_adjustment_set_lower (aj, year + 1);
-}
-
-
-/**
  * Obtain pixbuf from thumbnail data in meta data.
  *
  * @param meta input meta data

Modified: gnunet-gtk/src/fs/gnunet-fs-gtk_common.h
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_common.h    2013-09-08 17:41:42 UTC (rev 
29114)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_common.h    2013-09-08 18:02:18 UTC (rev 
29115)
@@ -43,30 +43,6 @@
 
 
 /**
- * Initialize the 'expiration_year_adjustment' of the given
- * builder to have a lower range of current-year+1 and a
- * default of current-year+2.
- * FIXME-STYLE: odd API...
- *
- * @param builder builder object for which we should manipulate
- * the adjustment
- */
-void
-GNUNET_FS_GTK_setup_expiration_year_adjustment (GtkBuilder * builder);
-
-
-/**
- * Convert the year from the spin button to an expiration
- * time (on midnight, January 1st of that year).
- *
- * @param spin button with the year
- * @return time converted from the spin button
- */
-struct GNUNET_TIME_Absolute
-GNUNET_FS_GTK_get_expiration_time (GtkSpinButton * spin);
-
-
-/**
  * mmap the given file and run the #GNUNET_FS_directory_list_contents
  * function on it.
  *

Modified: gnunet-gtk/src/fs/gnunet-fs-gtk_publish-dialog.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_publish-dialog.c    2013-09-08 17:41:42 UTC 
(rev 29114)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_publish-dialog.c    2013-09-08 18:02:18 UTC 
(rev 29115)
@@ -1673,7 +1673,7 @@
       sb = GTK_SPIN_BUTTON (gtk_builder_get_object
                            (ctx->open_directory_builder,
                             
"GNUNET_GTK_publish_directory_dialog_expiration_year_spin_button"));
-      bo.expiration_time = GNUNET_FS_GTK_get_expiration_time (sb);
+      bo.expiration_time = GNUNET_GTK_get_expiration_time (sb);
     }
     do_index =
         gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
@@ -1728,7 +1728,7 @@
       sb = GTK_SPIN_BUTTON (gtk_builder_get_object
                            (ctx->open_file_builder,
                             
"GNUNET_GTK_publish_file_dialog_expiration_year_spin_button"));      
-      bo.expiration_time = GNUNET_FS_GTK_get_expiration_time (sb);
+      bo.expiration_time = GNUNET_GTK_get_expiration_time (sb);
     }
     bo.replication_level =
       gtk_spin_button_get_value (GTK_SPIN_BUTTON
@@ -1766,7 +1766,7 @@
   struct MainPublishingDialogContext *ctx = user_data;
 
   ctx->open_file_builder = GNUNET_GTK_get_new_builder 
("gnunet_fs_gtk_publish_file_dialog.glade", ctx);
-  GNUNET_FS_GTK_setup_expiration_year_adjustment (ctx->open_file_builder);
+  GNUNET_GTK_setup_expiration_year_adjustment (ctx->open_file_builder);
 
   /* FIXME-FEATURE: Use some kind of adjustable defaults instead of 1000, 0 
and TRUE */
   gtk_spin_button_set_value (GTK_SPIN_BUTTON (gtk_builder_get_object 
(ctx->open_file_builder,
@@ -1813,7 +1813,7 @@
   struct MainPublishingDialogContext *ctx = user_data;
 
   ctx->open_directory_builder = GNUNET_GTK_get_new_builder 
("gnunet_fs_gtk_publish_directory_dialog.glade", ctx);
-  GNUNET_FS_GTK_setup_expiration_year_adjustment (ctx->open_directory_builder);
+  GNUNET_GTK_setup_expiration_year_adjustment (ctx->open_directory_builder);
 
   /* FIXME-FEATURE: Use some kind of adjustable defaults instead of 1000, 0 
and TRUE */
   gtk_spin_button_set_value (GTK_SPIN_BUTTON (gtk_builder_get_object 
(ctx->open_directory_builder,

Modified: gnunet-gtk/src/fs/gnunet-fs-gtk_publish-edit-dialog.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_publish-edit-dialog.c       2013-09-08 
17:41:42 UTC (rev 29114)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_publish-edit-dialog.c       2013-09-08 
18:02:18 UTC (rev 29115)
@@ -1334,7 +1334,7 @@
   /* Basic initialization of widgets models and visibility */
   gtk_combo_box_set_model (ctx->anonymity_combo, 
                           GNUNET_FS_GTK_get_anonymity_level_list_store ());
-  GNUNET_FS_GTK_setup_expiration_year_adjustment (ctx->builder);
+  GNUNET_GTK_setup_expiration_year_adjustment (ctx->builder);
 
   pubtypes_combo =
       GTK_COMBO_BOX (gtk_builder_get_object

Modified: gnunet-gtk/src/identity/gnunet-identity-gtk_advertise.c
===================================================================
--- gnunet-gtk/src/identity/gnunet-identity-gtk_advertise.c     2013-09-08 
17:41:42 UTC (rev 29114)
+++ gnunet-gtk/src/identity/gnunet-identity-gtk_advertise.c     2013-09-08 
18:02:18 UTC (rev 29115)
@@ -287,6 +287,7 @@
   struct GNUNET_FS_BlockOptions bo;
   struct GNUNET_CRYPTO_EccPublicKey pk;
   struct PublishContext *pc;
+  guint anonymity;
 
   if (GTK_RESPONSE_OK != response_id)
     goto cleanup;  
@@ -332,10 +333,28 @@
     while (gtk_tree_model_iter_next (GTK_TREE_MODEL (ac->metadata), &iter));
   }
 
-  bo.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS; /* FIXME: allow user to 
specify */
-  bo.anonymity_level = 1; /* FIXME: allow user to specify */
-  bo.content_priority = 1000; /* FIXME: allow user to specify */
-  bo.replication_level = 5;
+  bo.expiration_time = GNUNET_GTK_get_expiration_time
+    (GTK_SPIN_BUTTON 
+     (gtk_builder_get_object 
+      (ac->builder,
+       "GNUNET_GTK_identity_advertise_expiration_year_spin_button")));
+  anonymity = 1;
+  GNUNET_break (GNUNET_GTK_get_selected_anonymity_level (ac->builder,
+                                                        
"GNUNET_GTK_identity_advertise_anonymity_combobox",
+                                                        &anonymity));
+  bo.anonymity_level = anonymity;
+  bo.content_priority
+    = (unsigned int) gtk_spin_buttion_get_value
+    (GTK_SPIN_BUTTON 
+     (gtk_builder_get_object 
+      (ac->builder,
+       "GNUNET_GTK_identity_advertise_priority_spin_button")));
+  bo.replication_level
+    = (unsigned int) gtk_spin_buttion_get_value
+    (GTK_SPIN_BUTTON 
+     (gtk_builder_get_object 
+      (ac->builder,
+       "GNUNET_GTK_identity_advertise_replication_spin_button")));
   GNUNET_CRYPTO_ecc_key_get_public (&ac->priv,
                                    &pk);
   uri = GNUNET_FS_uri_sks_create (&pk,
@@ -624,6 +643,7 @@
     GNUNET_free (ac);
     return;
   }
+  GNUNET_GTK_setup_expiration_year_adjustment (ac->builder);
   ac->dialog = GTK_WIDGET (gtk_builder_get_object
                           (ac->builder, 
"GNUNET_GTK_identity_advertise_dialog"));
   ac->keywords = GTK_LIST_STORE (gtk_builder_get_object

Modified: gnunet-gtk/src/include/gnunet_gtk.h
===================================================================
--- gnunet-gtk/src/include/gnunet_gtk.h 2013-09-08 17:41:42 UTC (rev 29114)
+++ gnunet-gtk/src/include/gnunet_gtk.h 2013-09-08 18:02:18 UTC (rev 29115)
@@ -345,5 +345,78 @@
 GNUNET_GTK_animation_tree_view_unregister (struct 
GNUNET_FS_AnimationTreeViewHandle *atv);
 
 
+/* ********************* generic helpers ******************* */
+
+
+/**
+ * Columns in the anonymity level model.
+ */
+enum GNUNET_GTK_FS_MAIN_WINDOW_AnonymityLevelModelColumns
+  {
+    /**
+     * A gchararray.
+     */
+    GNUNET_GTK_ANONYMITY_LEVEL_MC_NAME = 0,
+
+    /**
+     * A guint.
+     */
+    GNUNET_GTK_ANONYMITY_LEVEL_MC_LEVEL = 1,
+    
+    /**
+     * A gchararray.
+     */
+    GNUNET_GTK_ANONYMITY_LEVEL_MC_COLOR = 2
+  };
+
+
+/**
+ * Convert the year from the spin button to an expiration
+ * time (on midnight, January 1st of that year).
+ *
+ * @param spin button with the year
+ * @return time converted from the spin button
+ */
+struct GNUNET_TIME_Absolute
+GNUNET_GTK_get_expiration_time (GtkSpinButton * spin);
+
+
+/**
+ * Initialize the 'expiration_year_adjustment' of the given
+ * builder to have a lower range of current-year+1 and a
+ * default of current-year+2.
+ * FIXME-STYLE: odd API...
+ *
+ * @param builder builder object for which we should manipulate
+ * the adjustment
+ */
+void
+GNUNET_GTK_setup_expiration_year_adjustment (GtkBuilder * builder);
+
+
+/**
+ * Obtain the numeric anonymity level selected by a GtkComboBox.
+ *
+ * @param builder builder for looking up widgets
+ * @param combo_name name of the GtkComboBox with the anonymity selection
+ * @param p_level where to store the anonymity level
+ * @return TRUE on success, FALSE on failure
+ */
+gboolean
+GNUNET_GTK_get_selected_anonymity_level (GtkBuilder * builder,
+                                         gchar * combo_name, guint * p_level);
+
+
+/**
+ * Obtain the numeric anonymity level selected by a GtkComboBox.
+ *
+ * @param combo the GtkComboBox with the anonymity selection
+ * @param p_level where to store the anonymity level
+ * @return TRUE on success, FALSE on failure
+ */
+gboolean
+GNUNET_GTK_get_selected_anonymity_combo_level (GtkComboBox *combo, guint 
*p_level);
+
+
 #endif
 /* end of gnunet_gtk.h */

Modified: gnunet-gtk/src/lib/Makefile.am
===================================================================
--- gnunet-gtk/src/lib/Makefile.am      2013-09-08 17:41:42 UTC (rev 29114)
+++ gnunet-gtk/src/lib/Makefile.am      2013-09-08 18:02:18 UTC (rev 29115)
@@ -16,6 +16,7 @@
   animations.c \
   eventloop.c \
   glade.c \
+  misc.c \
   nls.c \
   os_installation.c \
   trayicon.c 

Added: gnunet-gtk/src/lib/misc.c
===================================================================
--- gnunet-gtk/src/lib/misc.c                           (rev 0)
+++ gnunet-gtk/src/lib/misc.c   2013-09-08 18:02:18 UTC (rev 29115)
@@ -0,0 +1,122 @@
+/*
+     This file is part of GNUnet.
+     (C) 2011, 2013 Christian Grothoff (and other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file src/lib/misc.c
+ * @brief misc functions 
+ * @author Christian Grothoff
+ */
+#include "gnunet_gtk.h"
+
+
+/**
+ * Initialize the 'expiration_year_adjustment' of the given
+ * builder to have a lower range of current-year+1 and a
+ * default of current-year+2.
+ *
+ * @param builder builder object for which we should manipulate
+ * the adjustment
+ */
+void
+GNUNET_GTK_setup_expiration_year_adjustment (GtkBuilder * builder)
+{
+  GtkAdjustment *aj;
+  unsigned int year;
+
+  year = GNUNET_FS_get_current_year ();
+  aj = GTK_ADJUSTMENT (gtk_builder_get_object
+                       (builder, "expiration_year_adjustment"));
+  gtk_adjustment_set_value (aj, year + 2);
+  gtk_adjustment_set_lower (aj, year + 1);
+}
+
+
+/**
+ * Convert the year from the spin button to an expiration
+ * time (on midnight, January 1st of that year).
+ *
+ * @param spin button with an expiration year
+ * @return expiration time in the usual GNUnet format
+ */
+struct GNUNET_TIME_Absolute
+GNUNET_GTK_get_expiration_time (GtkSpinButton * spin)
+{
+  struct GNUNET_TIME_Absolute ret;
+  int year;
+
+  year = gtk_spin_button_get_value_as_int (spin);
+  GNUNET_assert (year >= 0);
+  ret = GNUNET_FS_year_to_time ((unsigned int) year);
+  GNUNET_break (GNUNET_TIME_absolute_get ().abs_value_us < ret.abs_value_us);
+  return ret;
+}
+
+
+/**
+ * Obtain the numeric anonymity level selected by a GtkComboBox.
+ *
+ * @param builder builder for looking up widgets
+ * @param combo_name name of the GtkComboBox with the anonymity selection
+ * @param p_level where to store the anonymity level
+ * @return TRUE on success, FALSE on failure
+ */
+gboolean
+GNUNET_GTK_get_selected_anonymity_level (GtkBuilder * builder,
+                                         gchar * combo_name, guint * p_level)
+{
+  GtkComboBox *combo;
+
+  combo = GTK_COMBO_BOX (gtk_builder_get_object (builder, combo_name));
+  if (!combo)
+    return FALSE;
+  return GNUNET_GTK_get_selected_anonymity_combo_level (combo, p_level);
+}
+
+
+/**
+ * Obtain the numeric anonymity level selected by a GtkComboBox.
+ *
+ * @param combo the GtkComboBox with the anonymity selection
+ * @param p_level where to store the anonymity level
+ * @return TRUE on success, FALSE on failure
+ */
+gboolean
+GNUNET_GTK_get_selected_anonymity_combo_level (GtkComboBox *combo, guint 
*p_level)
+{
+  GtkTreeIter iter;
+  GtkTreeModel *model;
+  guint level;
+
+  if (! gtk_combo_box_get_active_iter (combo, &iter))
+    return FALSE;
+  model = gtk_combo_box_get_model (combo);
+  if (!model)
+    return FALSE;
+  gtk_tree_model_get (model, &iter,
+                      GNUNET_GTK_ANONYMITY_LEVEL_MC_LEVEL,
+                      &level,
+                      -1);
+  if (p_level)
+    *p_level = level;
+  return TRUE;
+}
+
+
+/* end of misc.c */




reply via email to

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