gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r24916 - in gnunet-gtk: contrib src/fs
Date: Mon, 12 Nov 2012 16:57:32 +0100

Author: LRN
Date: 2012-11-12 16:57:32 +0100 (Mon, 12 Nov 2012)
New Revision: 24916

Modified:
   gnunet-gtk/contrib/gnunet_fs_gtk_main_window.glade
   gnunet-gtk/src/fs/gnunet-fs-gtk.c
   gnunet-gtk/src/fs/gnunet-fs-gtk.h
   gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c
   gnunet-gtk/src/fs/gnunet-fs-gtk_main-window-search.c
Log:
Lots of stuff

1) A couple of docfixes
2) More widgets in main window context
3) Main window context is easily gettable from a static variable

(2) and (3) fix a crash where widgets are being fetched via "ml" pointer
when it's already freed. Main window context lives longer.

4) New download panel
This takes most of the new code. Specifically, it gets its own filename
suggestion routine.

5) Fix for step-by-step manual directory trees' download (sets de->pde for
such cases; without that children can't be properly linked to parents for
things like cleanup)

Modified: gnunet-gtk/contrib/gnunet_fs_gtk_main_window.glade
===================================================================
--- gnunet-gtk/contrib/gnunet_fs_gtk_main_window.glade  2012-11-12 15:57:27 UTC 
(rev 24915)
+++ gnunet-gtk/contrib/gnunet_fs_gtk_main_window.glade  2012-11-12 15:57:32 UTC 
(rev 24916)
@@ -710,11 +710,217 @@
             <property name="visible">True</property>
             <property name="can_focus">True</property>
             <child>
-              <object class="GtkNotebook" id="GNUNET_GTK_main_window_notebook">
+              <object class="GtkVBox" id="GNUNET_GTK_main_window_left_vbox">
                 <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="scrollable">True</property>
-                <signal name="switch-page" 
handler="GNUNET_GTK_main_window_notebook_switch_page_cb" after="yes" 
swapped="no"/>
+                <property name="can_focus">False</property>
+                <child>
+                  <object class="GtkNotebook" 
id="GNUNET_GTK_main_window_notebook">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="scrollable">True</property>
+                    <signal name="switch-page" 
handler="GNUNET_GTK_main_window_notebook_switch_page_cb" after="yes" 
swapped="no"/>
+                  </object>
+                  <packing>
+                    <property name="expand">True</property>
+                    <property name="fill">True</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkVBox" 
id="GNUNET_GTK_search_frame_download_vbox">
+                    <property name="visible">False</property>
+                    <property name="can_focus">False</property>
+                    <child>
+                      <object class="GtkHBox" 
id="GNUNET_GTK_search_frame_download_into_hbox">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="spacing">4</property>
+                        <child>
+                          <object class="GtkLabel" 
id="GNUNET_GTK_search_frame_download_location_label">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="xalign">1</property>
+                            <property 
name="yalign">0.43999999761581421</property>
+                            <property name="label" translatable="yes">Download 
into:</property>
+                            <property name="single_line_mode">True</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">False</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkFileChooserButton" 
id="GNUNET_GTK_search_frame_download_location_chooser">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="action">select-folder</property>
+                            <property name="title" translatable="yes">Select a 
directory to download into</property>
+                          </object>
+                          <packing>
+                            <property name="expand">True</property>
+                            <property name="fill">True</property>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkHBox" 
id="GNUNET_GTK_search_frame_download_filename_hbox">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="spacing">4</property>
+                        <child>
+                          <object class="GtkLabel" 
id="GNUNET_GTK_search_frame_download_filename_label">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="xalign">1</property>
+                            <property 
name="yalign">0.43999999761581421</property>
+                            <property name="label" translatable="yes">Download 
as:</property>
+                            <property name="single_line_mode">True</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">False</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkEntry" 
id="GNUNET_GTK_search_frame_download_filename_entry">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="invisible_char">●</property>
+                            <property name="invisible_char_set">True</property>
+                            <property 
name="primary_icon_activatable">False</property>
+                            <property 
name="secondary_icon_activatable">False</property>
+                            <property 
name="primary_icon_sensitive">True</property>
+                            <property 
name="secondary_icon_sensitive">True</property>
+                          </object>
+                          <packing>
+                            <property name="expand">True</property>
+                            <property name="fill">True</property>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkHBox" 
id="GNUNET_GTK_search_frame_download_misc_hbox">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="spacing">4</property>
+                        <child>
+                          <object class="GtkLabel" 
id="GNUNET_GTK_search_frame_download_anonymity_label">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="xalign">1</property>
+                            <property name="label" 
translatable="yes">Anonymity:</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">False</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkAlignment" 
id="main_window_download_anonymity_combobox_alignment">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="yscale">0</property>
+                            <child>
+                              <object class="GtkComboBox" 
id="main_window_download_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="main_window_download_anonymity_combobox_renderer"/>
+                                  <attributes>
+                                    <attribute name="foreground">2</attribute>
+                                    <attribute name="text">0</attribute>
+                                  </attributes>
+                                </child>
+                                <child>
+                                  <object class="GtkCellRendererText" 
id="main_window_download_anonymity_combobox_renerer_level"/>
+                                  <attributes>
+                                    <attribute name="text">1</attribute>
+                                  </attributes>
+                                </child>
+                              </object>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">False</property>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkCheckButton" 
id="GNUNET_GTK_search_frame_download_recursive_checkbox">
+                            <property name="label" 
translatable="yes">Recursive</property>
+                            <property 
name="use_action_appearance">False</property>
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">False</property>
+                            <property name="draw_indicator">True</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">False</property>
+                            <property name="pack_type">end</property>
+                            <property name="position">2</property>
+                          </packing>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">2</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkHBox" 
id="GNUNET_GTK_search_frame_download_download_hbox">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <child>
+                          <object class="GtkButton" 
id="GNUNET_GTK_search_frame_download_download_button">
+                            <property name="label" 
translatable="yes">Download!</property>
+                            <property 
name="use_action_appearance">False</property>
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">True</property>
+                            <signal name="clicked" 
handler="GNUNET_GTK_search_frame_download_download_button_clicked_cb" 
swapped="no"/>
+                          </object>
+                          <packing>
+                            <property name="expand">True</property>
+                            <property name="fill">True</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">3</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
               </object>
               <packing>
                 <property name="resize">True</property>
@@ -942,6 +1148,13 @@
     <property name="can_focus">False</property>
     <property name="stock">gtk-open</property>
   </object>
+  <object class="GtkSizeGroup" 
id="GNUNET_GTK_download_frame_labels_size_group">
+    <widgets>
+      <widget name="GNUNET_GTK_search_frame_download_location_label"/>
+      <widget name="GNUNET_GTK_search_frame_download_anonymity_label"/>
+      <widget name="GNUNET_GTK_search_frame_download_filename_label"/>
+    </widgets>
+  </object>
   <object class="GtkSizeGroup" id="enties_and_comboboxes_sizegroup">
     <property name="mode">vertical</property>
     <widgets>
@@ -971,6 +1184,4 @@
     <property name="can_focus">False</property>
     <property name="stock">gtk-go-up</property>
   </object>
-  <object class="GtkSizeGroup" id="sizegroup4"/>
-  <object class="GtkSizeGroup" id="sizegroup5"/>
 </interface>

Modified: gnunet-gtk/src/fs/gnunet-fs-gtk.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk.c   2012-11-12 15:57:27 UTC (rev 24915)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk.c   2012-11-12 15:57:32 UTC (rev 24916)
@@ -58,12 +58,23 @@
  */
 static struct GNUNET_FS_Handle *fs;
 
+/**
+ * Context for main window.
+ */
+static struct GNUNET_GTK_MainWindowContext main_context;
 
+
 #if HAVE_LIBUNIQUE
 static UniqueApp *unique_app;
 #endif
 
+struct GNUNET_GTK_MainWindowContext *
+GNUNET_FS_GTK_get_main_context ()
+{
+  return &main_context;
+}
 
+
 /**
  * Return handle for file-sharing operations.
  *
@@ -373,7 +384,6 @@
   unsigned long long window_width;
   unsigned long long window_height;
   int maximized;
-  static struct GNUNET_GTK_MainWindowContext main_context;
 
   ml = cls;
   /* setup main context */
@@ -398,6 +408,15 @@
   main_context.md_treeview = GTK_TREE_VIEW 
(GNUNET_FS_GTK_get_main_window_object 
("GNUNET_GTK_main_window_metadata_treeview"));
   main_context.ns_callback_registered = GNUNET_NO;
 
+  main_context.download_location_chooser = GTK_FILE_CHOOSER 
(GNUNET_FS_GTK_get_main_window_object 
("GNUNET_GTK_search_frame_download_location_chooser"));
+  main_context.download_name_entry = GTK_ENTRY 
(GNUNET_FS_GTK_get_main_window_object 
("GNUNET_GTK_search_frame_download_filename_entry"));
+  main_context.download_anonymity_combo = GTK_COMBO_BOX 
(GNUNET_FS_GTK_get_main_window_object 
("main_window_download_anonymity_combobox"));
+  main_context.download_recursive_checkbutton = GTK_CHECK_BUTTON 
(GNUNET_FS_GTK_get_main_window_object 
("GNUNET_GTK_search_frame_download_recursive_checkbox"));
+  main_context.download_download_button = GTK_BUTTON 
(GNUNET_FS_GTK_get_main_window_object 
("GNUNET_GTK_search_frame_download_download_hbox"));
+  main_context.download_panel = GTK_VBOX (GNUNET_FS_GTK_get_main_window_object 
("GNUNET_GTK_search_frame_download_vbox"));
+
+  main_context.notebook = GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object 
("GNUNET_GTK_main_window_notebook"));
+
   GNUNET_GTK_set_icon_search_path ();
   GNUNET_GTK_setup_nls ();
 

Modified: gnunet-gtk/src/fs/gnunet-fs-gtk.h
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk.h   2012-11-12 15:57:27 UTC (rev 24915)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk.h   2012-11-12 15:57:32 UTC (rev 24916)
@@ -58,6 +58,15 @@
   int ns_callback_registered;
   GtkWindow *ns_manager;
   gulong ns_manager_delete_handler_id;
+
+  GtkFileChooser *download_location_chooser;
+  GtkEntry *download_name_entry;
+  GtkComboBox *download_anonymity_combo;
+  GtkCheckButton *download_recursive_checkbutton;
+  GtkButton *download_download_button;
+  GtkVBox *download_panel;
+
+  GtkNotebook *notebook;
 };
 
 
@@ -168,7 +177,13 @@
     GNUNET_GTK_FS_MAIN_WINDOW_SEARCH_MIME_MC_FREEDOM = 4,
   };
 
+/**
+ * Get main context.
+ */
+struct GNUNET_GTK_MainWindowContext *
+GNUNET_FS_GTK_get_main_context ();
 
+
 /**
  * Get our configuration.
  */

Modified: gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c     2012-11-12 15:57:27 UTC 
(rev 24915)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c     2012-11-12 15:57:32 UTC 
(rev 24916)
@@ -256,6 +256,11 @@
 static struct PublishTab *publish_tab;
 
 /**
+ * Special tab we use to store publishing operations.
+ */
+static struct SearchTab *current_search_tab = NULL;
+
+/**
  * Animation to display while publishing.
  */
 static struct GNUNET_FS_AnimationContext *animation_publishing;
@@ -296,7 +301,13 @@
 static struct GNUNET_FS_AnimationContext *animation_error;
 
 
+struct SearchTab *
+GNUNET_FS_GTK_get_current_search_tab ()
+{
+  return current_search_tab;
+}
 
+
 /* ***************** Search event handling ****************** */
 
 
@@ -323,16 +334,10 @@
 static void
 clear_metadata_display ()
 {
-  GtkImage *image;
-  GtkListStore *ms;
+  struct GNUNET_GTK_MainWindowContext *mctx = GNUNET_FS_GTK_get_main_context 
();
 
-  image =
-      GTK_IMAGE (GNUNET_FS_GTK_get_main_window_object
-                 ("GNUNET_GTK_main_window_preview_image"));
-  gtk_image_clear (image);
-  ms = GTK_LIST_STORE (GNUNET_FS_GTK_get_main_window_object
-                       ("GNUNET_GTK_meta_data_list_store"));
-  gtk_list_store_clear (ms);
+  gtk_image_clear (mctx->preview_image);
+  gtk_list_store_clear (mctx->md_liststore);
 }
 
 
@@ -494,7 +499,206 @@
   return NULL;
 }
 
+/*
+ *
+ * finished_chain - non-NULL for top-level call (for the item we're about to 
download), NULL otherwise
+ *   function sets it to GNUNET_YES if the item we're about to download was, 
in fact, already downloaded once, and thus we provide a name for it,
+ *   returning a finished relative filename that might only need .gnd appended 
to it, nothing else.
+ * root_directory - top-level download directory to use. Set to the directory 
into which root of the tree (grand-*-parent item) was downloaded.
+ *   If there's no already-downloaded grand-*-parents, set to default download 
directory (thus it will anways be filled on return).
+ * relative_directory - name of the directory in which we're about to download 
a file, relative to the root_directory. Whether it includes name of the file 
itself, depends on finished_chain.
+ * anonymity - anonymity level of one of the *parents. Initialize to -1. If 
none were downloaded, remains -1.
+ * Returned strings should be freed with GNUNET_free() if not NULL.
+ */
+void
+build_relative_name (GtkTreeModel *tm,
+                                  GtkTreeIter *iter,
+                                   int *finished_chain,
+                                   gchar **root_directory,
+                                   gchar **relative_directory,
+                                  int *anonymity)
+{
+  char *filename;
+  int downloaded_anonymity;
+  char *parent_filename;
+  GtkTreeIter parent;
 
+  gtk_tree_model_get (tm, iter,
+      SEARCH_TAB_MC_DOWNLOADED_FILENAME, &filename, 
+      SEARCH_TAB_MC_DOWNLOADED_ANONYMITY, &downloaded_anonymity, -1);
+
+  if (!gtk_tree_model_iter_parent (tm, &parent, iter))
+  {
+    /* Ok, we're at the top item.
+     * bottom == GNUNET_YES is a corner case when we only have one
+     * item (top and bottom at the same time), and it was already
+     * downloaded once (has SEARCH_TAB_MC_DOWNLOADED_FILENAME set) and
+     * cleaned up afterwards (downloadable again).
+     */
+    if (filename == NULL)
+    {
+      /* Top-level item is not downloaded yet
+       * (i.e. we only have one item, it's toplevel, and we're
+       * about to start downloading it).
+       * Use default download directory.
+       */
+      char buf[FILENAME_MAX];
+      char *tmp;
+      tmp = get_default_download_directory (buf, sizeof (buf));
+      /* If no download directory is known, try working directory */
+      if (NULL == tmp)
+        tmp = g_strdup (getcwd (buf, sizeof (buf)));
+      *root_directory = g_strdup  (tmp);
+    }
+    else
+    {
+      char *dot_gnd;
+      /* Toplevel item is a .gnd file, get its directory,
+       * and use it as download root (for now).
+       */
+      *root_directory = g_path_get_dirname (filename);
+      *relative_directory = g_path_get_basename (filename);
+      dot_gnd = strrchr (*relative_directory, '.');
+      if (NULL != dot_gnd && strcmp (dot_gnd, ".gnd") == 0)
+        *dot_gnd = '\0';
+      if (finished_chain)
+        *finished_chain = GNUNET_YES;
+    }
+  }
+  else
+  {
+    build_relative_name (tm, &parent, NULL, root_directory, 
relative_directory, anonymity);
+    /* We now know the root directory parent stems from,
+     * and parent's name (without .gnd) relative to the root directory.
+     * Now we need to check that root + reldir = directory
+     * where current item resides (that is, it was not saved in a different 
directory).
+     */
+    if (NULL != filename)
+    {
+      gchar *our_dirname = g_path_get_dirname (filename);
+      gchar *our_expected_dirname = g_build_filename (*root_directory, 
*relative_directory, NULL);
+      gchar *bname = g_path_get_basename (filename);
+      int chain_ok;
+      char *dot_gnd;
+#if WINDOWS
+      /* Kind of stricmp() for utf-8 */
+      gchar *tmp = g_utf8_casefold (our_dirname, -1);
+      gchar *tmpd = g_utf8_casefold (our_expected_dirname, -1);
+      chain_ok = 0 == g_utf8_collate (tmp, tmpd);
+      g_free (tmp);
+      g_free (tmpd);
+#else
+      chain_ok = 0 == g_utf8_collate (our_dirname, our_expected_dirname);
+#endif
+      dot_gnd = strrchr (bname, '.');
+      if (NULL != dot_gnd && strcmp (dot_gnd, ".gnd") == 0)
+        *dot_gnd = '\0';
+      if (!chain_ok)
+      {
+        /* User decided to download one of the directories into
+         * a different place - respect that decision, pick that
+         * place as the new root directory, and re-start relative name from 
here.
+         */
+        g_free (*root_directory);
+        *root_directory = g_strdup (our_dirname);
+        g_free (*relative_directory);
+        *relative_directory = g_strdup (bname);
+      }
+      else
+      {
+        /* Continue the chain from the same root directory */
+        gchar *new_relative_directory = g_build_filename (*relative_directory, 
bname, NULL);
+        g_free (*relative_directory);
+        *relative_directory = new_relative_directory;
+      }
+      if (finished_chain)
+        *finished_chain = GNUNET_YES;
+      g_free (our_dirname);
+      g_free (our_expected_dirname);
+      g_free (bname);
+    }
+  }
+
+  if ((downloaded_anonymity != -1) && (*anonymity == -1))
+    *anonymity = downloaded_anonymity;
+  g_free (filename);
+}
+
+static char *
+get_suggested_filename_anonymity2 (GtkTreeModel *tm,
+                                  GtkTreeIter *iter, 
+                                   char **download_directory,
+                                  int *anonymity)
+{
+  char *result;
+  char *downloaddir;
+  char *relname;
+  char *filename;
+  char *tmp;
+  int downloaded_anonymity;
+  struct GNUNET_CONTAINER_MetaData *meta;
+  GtkTreeIter parent;
+  char *dot;
+  size_t tmplen;
+  int finished_chain;
+
+  downloaddir = NULL;
+  relname = NULL;
+  finished_chain = GNUNET_NO;
+  build_relative_name (tm, iter, &finished_chain, &downloaddir, &relname, 
&downloaded_anonymity);
+  
+  gtk_tree_model_get (tm, iter, SEARCH_TAB_MC_METADATA, &meta, -1);
+
+  filename = GNUNET_FS_meta_data_suggest_filename (meta);
+  /* Don't trust metadata */
+  tmp = (char *) GNUNET_STRINGS_get_short_name (filename);
+
+  /* Really don't trust metadata */
+  if (NULL != tmp)
+  {
+    tmplen = strlen (tmp);
+    if ((1 == tmplen && '.' == tmp[0]) || (2 <= tmplen && '.' == tmp[0] && '.' 
== tmp[1]))
+      tmp = NULL;
+    else if ((1 == tmplen && ('/' == tmp[0] || '\\' == tmp[0])) || 0 == tmplen)
+      tmp = NULL;
+  }
+  if (NULL != tmp)
+  {
+    /* now, if we have a directory, replace trailing '/' with ".gnd" */
+    if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (meta))
+    {
+      if ((tmp[tmplen-1] == '/') || (tmp[tmplen-1] == '\\'))
+        tmp[tmplen-1] = '\0';
+      if (relname)
+      {
+        if (finished_chain)
+          GNUNET_asprintf (&result, "%s%s", relname, GNUNET_FS_DIRECTORY_EXT);
+        else
+          GNUNET_asprintf (&result, "%s%s%s%s", relname, DIR_SEPARATOR_STR, 
tmp, GNUNET_FS_DIRECTORY_EXT);
+      }
+      else
+        GNUNET_asprintf (&result, "%s%s", tmp, GNUNET_FS_DIRECTORY_EXT);
+    }
+    else
+    {
+      if (relname)
+      {
+        if (finished_chain)
+          result = GNUNET_strdup (relname);
+        else
+          GNUNET_asprintf (&result, "%s%s%s", relname, DIR_SEPARATOR_STR, tmp);
+      }
+      else
+        result = GNUNET_strdup (tmp);
+    }
+  }
+  *download_directory = GNUNET_strdup (downloaddir);
+  GNUNET_free (filename);
+  g_free (downloaddir);
+  g_free (relname);
+  return result;
+}
+
 /**
  * This function is called when the user double-clicks on a search
  * result.  Begins the download, if necessary by opening the "save as"
@@ -742,8 +946,94 @@
   gtk_tree_path_free (path);
 }
 
+void
+start_download2 ()
+{
+  struct GNUNET_GTK_MainWindowContext *mctx = GNUNET_FS_GTK_get_main_context 
();
+  struct SearchTab *st = GNUNET_FS_GTK_get_current_search_tab ();
+  struct GNUNET_CONTAINER_MetaData *meta;
+  GtkTreeView *tv;
+  GtkTreeSelection *sel;
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+  GtkTreeIter parent_iter;
+  struct SearchResult *sr;
+  struct GNUNET_FS_Uri *uri;
+  GtkTreePath *path;
+  const gchar *filename;
+  gchar *downloaddir;
+  struct DownloadEntry *de;
+  guint anonymity;
+  
+  gboolean recursive;
 
+  tv = GTK_TREE_VIEW (gtk_builder_get_object (st->builder, 
"_search_result_frame"));
+  sel = gtk_tree_view_get_selection (tv);
+  if (!gtk_tree_selection_get_selected (sel, &model, &iter))
+    return;
+
+  meta = NULL;
+
+  gtk_tree_model_get (model, &iter,
+                      SEARCH_TAB_MC_METADATA, &meta,
+                      SEARCH_TAB_MC_URI, &uri,
+                      SEARCH_TAB_MC_SEARCH_RESULT, &sr,
+                      -1);
+
+  if (!((NULL == sr->download) && (NULL != uri) &&
+      ((GNUNET_FS_uri_test_chk (uri) || GNUNET_FS_uri_test_loc (uri)))))
+    return;
+
+  path = gtk_tree_model_get_path (model, &iter);
+  recursive = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON 
(mctx->download_recursive_checkbutton));
+  filename = gtk_entry_get_text (mctx->download_name_entry);
+  downloaddir = gtk_file_chooser_get_filename 
(mctx->download_location_chooser);
+
+  de = GNUNET_malloc (sizeof (struct DownloadEntry));
+
+  if (gtk_tree_model_iter_parent (model, &parent_iter, &iter))
+  {
+    struct SearchResult *psr = NULL;
+    gtk_tree_model_get (model, &parent_iter,
+                      SEARCH_TAB_MC_SEARCH_RESULT, &psr,
+                      -1);
+    if (psr)
+      de->pde = psr->download;
+  }
+  /* else pde remains zero */
+
+  de->uri = GNUNET_FS_uri_dup (uri);
+  GNUNET_asprintf (&de->filename, "%s%s%s", downloaddir, DIR_SEPARATOR_STR, 
filename);
+  de->sr = sr;
+  sr->download = de;
+  if (GNUNET_GTK_get_selected_anonymity_combo_level 
(mctx->download_anonymity_combo, &anonymity))
+    de->anonymity = anonymity;
+  else
+    de->anonymity = 1;
+  de->is_recursive = recursive;
+  de->is_directory = GNUNET_FS_meta_data_test_for_directory (meta);
+
+  GNUNET_FS_GTK_download_context_start_download (de);
+
+  gtk_tree_path_free (path);
+  g_free (downloaddir);
+}
+
 /**
+ * User clicked on "Download!" button at the download options panel.
+ *
+ * @param button the "Download!" button
+ * @param user_data the main window context
+ */
+void
+GNUNET_GTK_search_frame_download_download_button_clicked_cb (
+    GtkButton *button, gpointer user_data)
+{
+  start_download2 ();
+}
+
+
+/**
  * "Download" was selected in the current search context menu.
  * 
  * @param item the 'download' menu item
@@ -1049,7 +1339,7 @@
 static void
 close_search_tab (struct SearchTab *tab)
 {
-  GtkNotebook *notebook;
+  struct GNUNET_GTK_MainWindowContext *mctx = GNUNET_FS_GTK_get_main_context 
();
   int index;
   int i;
 
@@ -1061,14 +1351,11 @@
     return;
   }
   clear_metadata_display ();
-  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))
+  for (i = gtk_notebook_get_n_pages (mctx->notebook) - 1; i >= 0; i--)
+    if (tab->frame == gtk_notebook_get_nth_page (mctx->notebook, i))
       index = i;
-  gtk_notebook_remove_page (notebook, index);
+  gtk_notebook_remove_page (mctx->notebook, index);
   g_object_unref (tab->builder);
   GNUNET_free (tab->query_txt);
   GNUNET_CONTAINER_DLL_remove (search_tab_head, search_tab_tail, tab);
@@ -1298,6 +1585,9 @@
   {
     GNUNET_break (0);
     gtk_tree_path_free (path);
+    g_free (filename);
+    g_free (downloaded_filename);
+    g_free (status_colour);
     return;
   }
   gtk_tree_path_free (path);
@@ -1447,43 +1737,80 @@
                                              gpointer user_data)
 {
   struct SearchTab *tab = user_data;
-  GtkImage *image;
-  GtkListStore *ms;
   GtkTreeSelection *sel;
   GtkTreeModel *model;
   GtkTreeIter iter;
   struct GNUNET_CONTAINER_MetaData *meta;
   GdkPixbuf *pixbuf;
+  struct SearchResult *sr;
+  struct GNUNET_FS_Uri *uri;
+  gchar *filename;
+  struct GNUNET_GTK_MainWindowContext *mctx = GNUNET_FS_GTK_get_main_context 
();
 
   GNUNET_assert (tab->query_txt != NULL);
-  image =
-      GTK_IMAGE (GNUNET_FS_GTK_get_main_window_object
-                 ("GNUNET_GTK_main_window_preview_image"));
-  ms = GTK_LIST_STORE (GNUNET_FS_GTK_get_main_window_object
-                       ("GNUNET_GTK_meta_data_list_store"));
   sel = gtk_tree_view_get_selection (tv);
-  gtk_list_store_clear (ms);
+  gtk_list_store_clear (mctx->md_liststore);
+  sel = gtk_tree_view_get_selection (tv);
   if (! gtk_tree_selection_get_selected (sel, &model, &iter))
   {
     /* nothing selected, clear preview */
-    gtk_image_clear (image);
+    gtk_image_clear (mctx->preview_image);
+    gtk_widget_hide (GTK_WIDGET (mctx->download_panel));
     return;
   }
   meta = NULL;
   pixbuf = NULL;
+
   gtk_tree_model_get (model, &iter,
                       SEARCH_TAB_MC_METADATA, &meta,
                       SEARCH_TAB_MC_PREVIEW, &pixbuf,
+                      SEARCH_TAB_MC_URI, &uri,
+                      SEARCH_TAB_MC_SEARCH_RESULT, &sr,
                       -1);
+
+  if ((NULL == sr->download) && (NULL != uri) &&
+      ((GNUNET_FS_uri_test_chk (uri) || GNUNET_FS_uri_test_loc (uri))))
+  {
+    char *download_directory;
+    char *filename;
+    int anonymity;
+    int is_directory;
+
+    /* Calculate suggested filename */
+    anonymity = -1;
+    download_directory = NULL;
+    filename = get_suggested_filename_anonymity2 (model, &iter,
+        &download_directory, &anonymity);
+
+    is_directory = GNUNET_FS_meta_data_test_for_directory (meta);
+    gtk_widget_set_sensitive (GTK_WIDGET 
(mctx->download_recursive_checkbutton), is_directory);
+
+    /* TODO: make this configurable */
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON 
(mctx->download_recursive_checkbutton), is_directory);
+
+    /* TODO: make this configurable */
+    GNUNET_GTK_select_anonymity_combo_level (mctx->download_anonymity_combo, 
anonymity >= 0 ? anonymity : 1);
+
+    gtk_entry_set_text (mctx->download_name_entry, filename != NULL ? filename 
: NULL);
+    gtk_file_chooser_set_current_folder (mctx->download_location_chooser, 
download_directory);
+    /*gtk_file_chooser_set_current_name (mctx->download_location_chooser, 
download_directory);*/
+    
+    gtk_widget_show_all (GTK_WIDGET (mctx->download_panel));
+    GNUNET_free (filename);
+    GNUNET_free (download_directory);
+  }
+  else
+    gtk_widget_hide (GTK_WIDGET (mctx->download_panel));
+
   if (NULL != pixbuf)
   {
-    gtk_image_set_from_pixbuf (image, pixbuf);
+    gtk_image_set_from_pixbuf (mctx->preview_image, pixbuf);
     g_object_unref (G_OBJECT (pixbuf));
   }
   if (NULL != meta)  
     GNUNET_CONTAINER_meta_data_iterate (meta,
                                         
&GNUNET_FS_GTK_add_meta_data_to_list_store,
-                                        ms);
+                                        mctx->md_liststore);
 }
 
 
@@ -1492,43 +1819,36 @@
  * metadata views.
  *
  * @param dummy widget emitting the event, unused
- * @param data master Gtk builder, unused
+ * @param data main window context
  */
 void
 GNUNET_GTK_main_window_notebook_switch_page_cb (GtkWidget * dummy,
                                                 gpointer data)
 {
-  GtkNotebook *notebook;
   gint page;
   GtkWidget *w;
   struct SearchTab *tab;
-  GtkImage *image;
-  GtkListStore *ms;
   GtkTreeView *tv;
+  struct GNUNET_GTK_MainWindowContext *mctx = GNUNET_FS_GTK_get_main_context 
();
 
-  notebook =
-      GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object
-                    ("GNUNET_GTK_main_window_notebook"));
-  page = gtk_notebook_get_current_page (notebook);
-  w = gtk_notebook_get_nth_page (notebook, page);
+  page = gtk_notebook_get_current_page (mctx->notebook);
+  w = gtk_notebook_get_nth_page (mctx->notebook, page);
+  current_search_tab = NULL;
   for (tab = search_tab_head; NULL != tab; tab = tab->next)
   {
     if (tab->frame != w)
       continue;
+    current_search_tab = tab;
     tv = GTK_TREE_VIEW (gtk_builder_get_object
                        (tab->builder, "_search_result_frame"));
     GNUNET_FS_GTK_search_treeview_cursor_changed (tv, tab);
     return;
   }
+  gtk_widget_hide (GTK_WIDGET (mctx->download_panel));
   /* active tab is not a search tab (likely the 'publish' tab), 
      clear meta data and preview widgets */
-  image =
-      GTK_IMAGE (GNUNET_FS_GTK_get_main_window_object
-                 ("GNUNET_GTK_main_window_preview_image"));
-  gtk_image_clear (image);
-  ms = GTK_LIST_STORE (GNUNET_FS_GTK_get_main_window_object
-                       ("GNUNET_GTK_meta_data_list_store"));
-  gtk_list_store_clear (ms);
+  gtk_image_clear (mctx->preview_image);
+  gtk_list_store_clear (mctx->md_liststore);
 }
 
 
@@ -1752,9 +2072,9 @@
   char *mime;
   GdkPixbuf *pixbuf;
   guint percent_avail;
-  GtkNotebook *notebook;
   gint page;
   int desc_is_a_dup;
+  struct GNUNET_GTK_MainWindowContext *mctx = GNUNET_FS_GTK_get_main_context 
();
 
   if (sr == NULL)
   {
@@ -1800,11 +2120,8 @@
   GNUNET_free (desc);
   GNUNET_free_non_null (mime);
 
-  notebook =
-      GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object
-                    ("GNUNET_GTK_main_window_notebook"));
-  page = gtk_notebook_get_current_page (notebook);
-  if (gtk_notebook_get_nth_page (notebook, page) == sr->tab->frame)
+  page = gtk_notebook_get_current_page (mctx->notebook);
+  if (gtk_notebook_get_nth_page (mctx->notebook, page) == sr->tab->frame)
   {
     tv = GTK_TREE_VIEW (gtk_builder_get_object
                         (sr->tab->builder, "_search_result_frame"));
@@ -2006,11 +2323,11 @@
                  const struct GNUNET_FS_Uri *query)
 {
   struct SearchTab *tab;
-  GtkNotebook *notebook;
   GtkWindow *sf;
   GtkTreeViewColumn *anim_col;
   GtkTreeView *tv;
   gint pages;
+  struct GNUNET_GTK_MainWindowContext *mctx = GNUNET_FS_GTK_get_main_context 
();
 
   if (NULL == animation_downloading)
   {
@@ -2081,13 +2398,10 @@
   update_search_label (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->tab_label, pages - 1);
-  gtk_notebook_set_current_page (notebook, pages - 1);
-  gtk_widget_show (GTK_WIDGET (notebook));
+  pages = gtk_notebook_get_n_pages (mctx->notebook);
+  gtk_notebook_insert_page (mctx->notebook, tab->frame, tab->tab_label, pages 
- 1);
+  gtk_notebook_set_current_page (mctx->notebook, pages - 1);
+  gtk_widget_show (GTK_WIDGET (mctx->notebook));
   return tab;
 }
 
@@ -2149,7 +2463,7 @@
 GNUNET_GTK_add_to_uri_tab (const struct GNUNET_CONTAINER_MetaData *meta,
                            const struct GNUNET_FS_Uri *uri)
 {
-  GtkNotebook *notebook;
+  struct GNUNET_GTK_MainWindowContext *mctx = GNUNET_FS_GTK_get_main_context 
();
   gint page;
 
   if (NULL == uri_tab)
@@ -2159,13 +2473,10 @@
     gtk_widget_set_visible (uri_tab->pause_button, FALSE);
   }
   /* make 'uri_tab' the current page */
-  notebook =
-    GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object
-                 ("GNUNET_GTK_main_window_notebook"));
-  for (page = 0; page < gtk_notebook_get_n_pages (notebook); page++)
-    if (uri_tab->frame == gtk_notebook_get_nth_page (notebook, page))
+  for (page = 0; page < gtk_notebook_get_n_pages (mctx->notebook); page++)
+    if (uri_tab->frame == gtk_notebook_get_nth_page (mctx->notebook, page))
     {
-      gtk_notebook_set_current_page (notebook, page);
+      gtk_notebook_set_current_page (mctx->notebook, page);
       break;
     }
   return GNUNET_GTK_add_search_result (uri_tab, NULL, uri, meta, NULL, 0);
@@ -2648,7 +2959,7 @@
                       SEARCH_TAB_MC_STATUS_COLOUR, "blue",
                       SEARCH_TAB_MC_SEARCH_RESULT, de->sr, 
                       SEARCH_TAB_MC_COMPLETED, (guint64) completed,
-                      SEARCH_TAB_MC_FILENAME, de->filename,
+                      SEARCH_TAB_MC_DOWNLOADED_FILENAME, de->filename,
                       SEARCH_TAB_MC_DOWNLOADED_ANONYMITY, de->anonymity,
                      SEARCH_TAB_MC_STATUS_ICON,
                      GNUNET_GTK_animation_context_get_pixbuf 
(animation_download_stalled),
@@ -2797,23 +3108,20 @@
 static void
 delete_publish_tab ()
 {
-  GtkNotebook *notebook;
   struct PublishTab *pt;
   int index;
   int i;
+  struct GNUNET_GTK_MainWindowContext *mctx = GNUNET_FS_GTK_get_main_context 
();
  
   if (NULL == publish_tab)
     return;
   pt = publish_tab;
   publish_tab = NULL;
-  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 (pt->frame == gtk_notebook_get_nth_page (notebook, i))
+  for (i = gtk_notebook_get_n_pages (mctx->notebook) - 1; i >= 0; i--)
+    if (pt->frame == gtk_notebook_get_nth_page (mctx->notebook, i))
       index = i;
-  gtk_notebook_remove_page (notebook, index);
+  gtk_notebook_remove_page (mctx->notebook, index);
 
   /* fully destroy tab */
   g_object_unref (pt->builder);
@@ -2912,10 +3220,10 @@
   GtkTreePath *path;
   GtkWindow *df;
   GtkWidget *tab_label;
-  GtkNotebook *notebook;
   char *size_fancy;
   GtkTreeView *tv;
   GtkTreeViewColumn *anim_col;
+  struct GNUNET_GTK_MainWindowContext *mctx = GNUNET_FS_GTK_get_main_context 
();
   
   if (NULL == publish_tab)
   {
@@ -2948,12 +3256,9 @@
                                                                  anim_col);
 
     /* make visible */
-    notebook =
-      GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object
-                   ("GNUNET_GTK_main_window_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);
+    gtk_notebook_insert_page (mctx->notebook, publish_tab->frame, tab_label, 
0);
+    gtk_widget_show (GTK_WIDGET (mctx->notebook));
+    gtk_notebook_set_current_page (mctx->notebook, 0);
     publish_tab->ts =
       GTK_TREE_STORE (gtk_builder_get_object
                      (publish_tab->builder, "_publish_frame_tree_store"));

Modified: gnunet-gtk/src/fs/gnunet-fs-gtk_main-window-search.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_main-window-search.c        2012-11-12 
15:57:27 UTC (rev 24915)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_main-window-search.c        2012-11-12 
15:57:32 UTC (rev 24916)
@@ -31,7 +31,7 @@
 /**
  * Start a search.
  *
- * @param builder the main dialog builder
+ * @param builder the main window context
  */
 static void
 start_search (struct GNUNET_GTK_MainWindowContext *main_ctx)
@@ -149,7 +149,7 @@
  * User clicked on the 'search' button in the main window.
  *
  * @param button the search button
- * @param user_data the main dialog builder
+ * @param user_data the main window context builder
  */
 void
 main_window_search_button_clicked_cb (GtkButton * button, 
@@ -159,14 +159,13 @@
   start_search (main_ctx);
 }
 
-
 /**
  * User pushed a key (possibly ENTER) in the search entry widget.
  * Start the search if it was ENTER.
  *
  * @param widget the entry widget
  * @param event the key stroke
- * @param user_data the builder of the main window
+ * @param user_data the main window context
  * @return FALSE if this was not ENTER, TRUE if it was
  */
 gboolean




reply via email to

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