gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r2644 - in gnunet-gtk/src: common include plugins/fs


From: grothoff
Subject: [GNUnet-SVN] r2644 - in gnunet-gtk/src: common include plugins/fs
Date: Sun, 23 Apr 2006 04:47:33 -0700 (PDT)

Author: grothoff
Date: 2006-04-23 04:47:30 -0700 (Sun, 23 Apr 2006)
New Revision: 2644

Modified:
   gnunet-gtk/src/common/helper.c
   gnunet-gtk/src/include/gnunetgtk_common.h
   gnunet-gtk/src/plugins/fs/search.c
Log:
working on mantis 1046

Modified: gnunet-gtk/src/common/helper.c
===================================================================
--- gnunet-gtk/src/common/helper.c      2006-04-23 11:12:44 UTC (rev 2643)
+++ gnunet-gtk/src/common/helper.c      2006-04-23 11:47:30 UTC (rev 2644)
@@ -502,10 +502,8 @@
  *
  */
 void gnunetgtk_notify(const char *message, int type) {
-
-  GtkWidget * root;
-  
 #ifdef WITH_LIBNOTIFY
+  GtkWidget * root; 
   NotifyNotification *libnotify;
   NotifyUrgency libnotify_urgency = NOTIFY_URGENCY_NORMAL;
   long libnotify_expire_timeout = NOTIFY_EXPIRES_DEFAULT;
@@ -537,7 +535,37 @@
     notify_uninit();
   }
 #endif
+}
 
+/**
+ * Validate that a string is a Utf-8 string.
+ * If validation fails, msg is freed and a valid
+ * Utf-8 string is returned.
+ */
+char * validate_utf8(char * msg) {
+  const gchar * end;
+  char * ret;
+  gsize send;
+
+  end = NULL;
+  if (TRUE == g_utf8_validate(msg,
+                             -1,
+                             &end)) 
+    return msg;
+  /* hope that it is ISO8859-1 */
+  ret = g_convert_with_fallback(msg,
+                               -1,
+                               "UTF-8",
+                               "ISO8859-1",
+                               ".",
+                               NULL,
+                               &send,
+                               NULL);
+  FREE(msg);
+  msg = STRDUP(ret);
+  g_free(ret);
+  return msg;
 }
 
+
 /* end of helper.c */

Modified: gnunet-gtk/src/include/gnunetgtk_common.h
===================================================================
--- gnunet-gtk/src/include/gnunetgtk_common.h   2006-04-23 11:12:44 UTC (rev 
2643)
+++ gnunet-gtk/src/include/gnunetgtk_common.h   2006-04-23 11:47:30 UTC (rev 
2644)
@@ -92,9 +92,14 @@
 
 /**
  * Sends a message to libnotify
- *
- *
  */
 void gnunetgtk_notify(const char * message, int type);
 
+/**
+ * Validate that a string is a Utf-8 string.
+ * If validation fails, msg is freed and a valid
+ * Utf-8 string is returned.
+ */
+char * validate_utf8(char * msg);
+
 #endif

Modified: gnunet-gtk/src/plugins/fs/search.c
===================================================================
--- gnunet-gtk/src/plugins/fs/search.c  2006-04-23 11:12:44 UTC (rev 2643)
+++ gnunet-gtk/src/plugins/fs/search.c  2006-04-23 11:47:30 UTC (rev 2644)
@@ -75,6 +75,7 @@
                              EXTRACTOR_MIMETYPE);
   if (mime == NULL)
     mime = STRDUP(_("unknown"));
+  mime = validate_utf8(mime);
   desc = ECRS_getFirstFromMetaData(meta,
                                   EXTRACTOR_DESCRIPTION,
                                   EXTRACTOR_GENRE,
@@ -87,6 +88,7 @@
                                   -1);
   if (desc == NULL)
     desc = STRDUP("");
+  desc = validate_utf8(desc);
   name = ECRS_getFirstFromMetaData(meta,
                                   EXTRACTOR_FILENAME,
                                   EXTRACTOR_TITLE,
@@ -100,11 +102,12 @@
   if (name == NULL)
     name = STRDUP(_("no name given"));
   else {
-    char *dotdot;
+    char * dotdot;
     
     while (NULL != (dotdot = strstr(name, "..")))
       dotdot[0] = dotdot[1] = '_';
   }
+  name = validate_utf8(name);
     
   if (ECRS_isFileUri(uri)) {
     size = ECRS_fileSize(uri);
@@ -447,46 +450,50 @@
   return NULL;
 }
 
-void on_closeSearchButton_clicked(GtkWidget * searchPage,
-                                 GtkWidget * closeButton) {
+static void freeSearchModel(GtkTreeModel * model,
+                           GtkTreeIter * parent) {
+  struct ECRS_URI * u;
+  struct ECRS_MetaData * m;
+  GtkTreeIter iter;
+
+  if (gtk_tree_model_iter_children(model,
+                                  &iter,
+                                  parent)) {
+    do {
+      gtk_tree_model_get(model,
+                        &iter,
+                        SEARCH_URI, &u,
+                        SEARCH_META, &m,
+                        -1);
+      gtk_tree_store_set(GTK_TREE_STORE(model),
+                        &iter,
+                        SEARCH_URI, NULL,
+                        SEARCH_META, NULL,
+                        -1);
+      if (u != NULL)
+       ECRS_freeUri(u);
+      if (m != NULL)
+       ECRS_freeMetaData(m);
+      freeSearchModel(model, &iter);
+    } while (gtk_tree_model_iter_next(model,
+                                     &iter));
+  }  
+}
+
+static void closeSearchPage(SearchList * list) {
   GtkWidget * notebook;
   int index;
   int i;
-  struct ECRS_URI * uri;
-  SearchList * list;
-  SearchList * prev;
   GtkTreeIter iter;
   struct ECRS_URI * euri;
 
-  list = head;
-  prev = NULL;
-  while (list != NULL) {
-    if (list->searchpage == searchPage)
-      break;
-    prev = list;
-    list = list->next;
-  }
-
-  if (list == NULL)
-       return;
-
-  uri = list->uri;
-
-  run_with_save_calls(&stopSearch,
-                     uri);
-  if (prev == NULL)
-    head = list->next;
-  else
-    prev->next = list->next;
-  FREE(list);
-
   notebook
     = glade_xml_get_widget(getMainXML(),
                           "downloadNotebook");
   index = -1;
   for (i=gtk_notebook_get_n_pages(GTK_NOTEBOOK(notebook))-1;i>=0;i--)
-    if (searchPage == gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook),
-                                               i))
+    if (list->searchpage == gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook),
+                                                     i))
       index = i;
 
   if (index != -1) {
@@ -495,11 +502,14 @@
   } else {
     BREAK();
   }
+  freeSearchModel(list->model, NULL);
+  list->model = NULL;
 
   if (! gtk_tree_model_get_iter_first(GTK_TREE_MODEL(summary),
                                      &iter)) {
     BREAK();
-    ECRS_freeUri(uri);
+    ECRS_freeUri(list->uri);
+    list->uri = NULL;
     return;
   }
   do { 
@@ -508,19 +518,47 @@
                       SER_SUM_URI, &euri,
                       -1);
     if (ECRS_equalsUri(euri,
-                      uri)) {
+                      list->uri)) {
       gtk_list_store_remove(GTK_LIST_STORE(summary),
                            &iter);
       ECRS_freeUri(euri);
-      ECRS_freeUri(uri);
+      ECRS_freeUri(list->uri);
+      list->uri = NULL;
       return;
     }
   } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(summary),
                                    &iter));
-  ECRS_freeUri(uri);
+  ECRS_freeUri(list->uri);
+  list->uri = NULL;
   BREAK();
 }
 
+void on_closeSearchButton_clicked(GtkWidget * searchPage,
+                                 GtkWidget * closeButton) {
+  SearchList * list;
+  SearchList * prev;
+
+  list = head;
+  prev = NULL;
+  while (list != NULL) {
+    if (list->searchpage == searchPage)
+      break;
+    prev = list;
+    list = list->next;
+  }
+  if (list == NULL)
+    return;
+  if (prev == NULL)
+    head = list->next;
+  else
+    prev->next = list->next;
+
+  run_with_save_calls(&stopSearch,
+                     list->uri);
+  closeSearchPage(list);
+  FREE(list);
+}
+
 static GtkWidget * makeResultFrame(GtkWidget ** treeview,
                                   GtkWidget ** anonSpin) {
   GtkWidget * window;
@@ -962,7 +1000,6 @@
   return OK;
 }
 
-
 void fs_search_start() {
   GtkWidget * searchCB;
   GtkListStore * model;
@@ -1023,36 +1060,6 @@
                    NULL);
 }
 
-static void freeSearchModel(GtkTreeModel * model,
-                           GtkTreeIter * parent) {
-  struct ECRS_URI * u;
-  struct ECRS_MetaData * m;
-  GtkTreeIter iter;
-
-  if (gtk_tree_model_iter_children(model,
-                                  &iter,
-                                  parent)) {
-    do {
-      gtk_tree_model_get(model,
-                        &iter,
-                        SEARCH_URI, &u,
-                        SEARCH_META, &m,
-                        -1);
-      gtk_tree_store_set(GTK_TREE_STORE(model),
-                        &iter,
-                        SEARCH_URI, NULL,
-                        SEARCH_META, NULL,
-                        -1);
-      if (u != NULL)
-       ECRS_freeUri(u);
-      if (m != NULL)
-       ECRS_freeMetaData(m);
-      freeSearchModel(model, &iter);
-    } while (gtk_tree_model_iter_next(model,
-                                     &iter));
-  }  
-}
-
 void fs_search_stop() {
   SearchList * list;
   GtkTreeIter iter;
@@ -1064,8 +1071,8 @@
   while (head != NULL) {
     list = head;
     head = head->next;
-    ECRS_freeUri(list->uri);
     freeSearchModel(list->model, NULL);
+    closeSearchPage(list);
     FREE(list);
   }
 





reply via email to

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