gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r7059 - in gnunet-gtk: . src/plugins/fs
Date: Fri, 6 Jun 2008 13:10:13 -0600 (MDT)

Author: moon
Date: 2008-06-06 13:10:13 -0600 (Fri, 06 Jun 2008)
New Revision: 7059

Modified:
   gnunet-gtk/configure.ac
   gnunet-gtk/src/plugins/fs/Makefile.am
   gnunet-gtk/src/plugins/fs/fs.h
   gnunet-gtk/src/plugins/fs/search.c
Log:
translate MIME types into human-readable descriptions
add a column with 16x16 icons corresponding to the MIME type
(using GIO, enabled only when GLib >= 2.16)



Modified: gnunet-gtk/configure.ac
===================================================================
--- gnunet-gtk/configure.ac     2008-06-05 22:49:47 UTC (rev 7058)
+++ gnunet-gtk/configure.ac     2008-06-06 19:10:13 UTC (rev 7059)
@@ -60,7 +60,11 @@
  AC_MSG_ERROR(Cannot find GTK: Is gtk-config in path?)
 fi
 
+# check for GIO (GLib >= 2.16)
+PKG_CHECK_MODULES(GIO, gio-2.0, [AC_DEFINE(HAVE_GIO,1, GIO found 
+(optional))])
 
+
 CFLAGS="-Wall $CFLAGS"
 # use '-fno-strict-aliasing', but only if the compiler can take it
 if gcc -fno-strict-aliasing -S -o /dev/null -xc /dev/null >/dev/null 2>&1;

Modified: gnunet-gtk/src/plugins/fs/Makefile.am
===================================================================
--- gnunet-gtk/src/plugins/fs/Makefile.am       2008-06-05 22:49:47 UTC (rev 
7058)
+++ gnunet-gtk/src/plugins/fs/Makefile.am       2008-06-06 19:10:13 UTC (rev 
7059)
@@ -2,6 +2,7 @@
   -I$(top_srcdir)/intl \
   -I$(top_srcdir)/src/include \
   @GTK_CFLAGS@ \
+  @GIO_CFLAGS@ \
   @GNUNETGTK_CFLAGS@
 
 plugindir = $(libdir)/GNUnet
@@ -25,6 +26,7 @@
 libgnunetgtkmodule_fs_la_LIBADD = \
   $(top_builddir)/src/common/libgnunetgtk_common.la \
   @GTK_LIBS@ \
+  @GIO_LIBS@  \
   @GNUNETGTK_LIBS@ \
   $(INTLLIBS) \
   -lgthread-2.0 \

Modified: gnunet-gtk/src/plugins/fs/fs.h
===================================================================
--- gnunet-gtk/src/plugins/fs/fs.h      2008-06-05 22:49:47 UTC (rev 7058)
+++ gnunet-gtk/src/plugins/fs/fs.h      2008-06-06 19:10:13 UTC (rev 7059)
@@ -52,6 +52,9 @@
 enum
 {
   SEARCH_NAME = 0,
+#ifdef HAVE_GIO
+  SEARCH_ICON,
+#endif
   SEARCH_SIZE,
   SEARCH_HSIZE,
   SEARCH_MIME,

Modified: gnunet-gtk/src/plugins/fs/search.c
===================================================================
--- gnunet-gtk/src/plugins/fs/search.c  2008-06-05 22:49:47 UTC (rev 7058)
+++ gnunet-gtk/src/plugins/fs/search.c  2008-06-06 19:10:13 UTC (rev 7059)
@@ -33,6 +33,9 @@
 #include <extractor.h>
 #include <GNUnet/gnunet_util_crypto.h>
 #include <GNUnet/gnunet_namespace_lib.h>
+#ifdef HAVE_GIO
+#include <gio/gio.h>
+#endif
 
 
 /**
@@ -198,16 +201,23 @@
                       const GNUNET_ECRS_FileInfo * info, GtkTreeIter * iter)
 {
   char *name;
+  char *rawMime;
   char *mime;
   char *desc;
   unsigned long long size;
   char *size_h;
   GdkPixbuf *pixbuf;
   GdkPixbuf *rankbuf;
+#ifdef HAVE_GIO
+  GdkPixbuf *icon = NULL;
+  GIcon *gicon = NULL;
+  const gchar **iconNames;
+  int i = 0;
+#endif
   enum GNUNET_URITRACK_STATE state;
 
   state = GNUNET_URITRACK_get_state (ectx, cfg, info->uri);
-  mime = getMimeTypeFromMetaData (info->meta);
+  rawMime = getMimeTypeFromMetaData (info->meta);
   desc = getDescriptionFromMetaData (info->meta);
   name = getFileNameFromMetaData (info->meta);
   size = GNUNET_ECRS_uri_test_chk (info->uri)
@@ -218,11 +228,41 @@
   rankbuf = make_ranking_pixbuf (0, 0, 1,
                                  GNUNET_ECRS_uri_get_keyword_count_from_ksk
                                  (searchContext->uri));
-  gtk_tree_store_set (searchContext->tree, iter, SEARCH_NAME, name,
-                      SEARCH_SIZE, size, SEARCH_HSIZE, size_h, SEARCH_MIME,
-                      mime, SEARCH_DESC, desc, SEARCH_PIXBUF, pixbuf,
-                      SEARCH_URI, GNUNET_ECRS_uri_duplicate (info->uri),
-                      SEARCH_META,
+#ifdef HAVE_GIO
+  if (0 == strcmp(rawMime, GNUNET_DIRECTORY_MIME))
+  {
+    mime = GNUNET_strdup(_("Directory"));
+    icon = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
+                                     "folder", 16, 0, (GError **)NULL);
+  }
+  else
+  {
+    mime = g_content_type_get_description (rawMime);
+    gicon = g_content_type_get_icon (rawMime);
+    if (G_IS_THEMED_ICON (gicon))
+      {
+        iconNames = (const gchar **)g_themed_icon_get_names
+                                           (G_THEMED_ICON (gicon));
+        do {
+            icon = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
+                                             iconNames[i], 16, 0,
+                                             (GError **)NULL);
+            i++;
+          } while ( (icon == NULL) && iconNames[i] );
+      }
+  }
+#else
+  mime = rawMime;
+#endif
+
+  gtk_tree_store_set (searchContext->tree, iter,
+#ifdef HAVE_GIO
+                      SEARCH_ICON, icon,
+#endif
+                      SEARCH_NAME, name, SEARCH_SIZE, size, SEARCH_HSIZE,
+                      size_h, SEARCH_MIME, mime, SEARCH_DESC, desc,
+                      SEARCH_PIXBUF, pixbuf, SEARCH_URI,
+                      GNUNET_ECRS_uri_duplicate (info->uri), SEARCH_META,
                       GNUNET_meta_data_duplicate (info->meta),
                       SEARCH_CELL_BG_COLOR, getColorCode (state),
                       SEARCH_CELL_FG_COLOR, "black", SEARCH_INTERNAL,
@@ -233,10 +273,16 @@
   g_object_unref (rankbuf);
   if (pixbuf != NULL)
     g_object_unref (pixbuf);
+#ifdef HAVE_GIO
+  if (gicon != NULL)
+    g_object_unref (gicon);
+  if (icon != NULL)
+    g_object_unref (icon);
+#endif
   GNUNET_free (size_h);
   GNUNET_free (name);
   GNUNET_free (desc);
-  GNUNET_free (mime);
+  GNUNET_free (rawMime);
 }
 
 /**
@@ -666,7 +712,10 @@
   g_signal_connect_swapped (list->treeview,
                             "button-press-event",
                             G_CALLBACK (search_click_handler), list);
-  list->tree = gtk_tree_store_new (SEARCH_NUM, G_TYPE_STRING,   /* name */
+  list->tree = gtk_tree_store_new (SEARCH_NUM, G_TYPE_STRING,  /* name */
+#ifdef HAVE_GIO
+                                   GDK_TYPE_PIXBUF,    /* icon */
+#endif
                                    G_TYPE_UINT64,       /* size */
                                    G_TYPE_STRING,       /* human-readable size 
*/
                                    G_TYPE_STRING,       /* mime-type */
@@ -712,6 +761,20 @@
   gtk_tree_view_column_set_sort_column_id (column, SEARCH_STATUS);
   gtk_tree_view_column_set_min_width (column, 0);
 
+#ifdef HAVE_GIO
+  renderer = gtk_cell_renderer_pixbuf_new ();
+  col = gtk_tree_view_insert_column_with_attributes (list->treeview,
+                                                     -1,
+                                                     NULL,
+                                                     renderer,
+                                                     "pixbuf",
+                                                     SEARCH_ICON, NULL);
+  column = gtk_tree_view_get_column (list->treeview, col - 1);
+  gtk_tree_view_column_set_resizable (column, TRUE);
+  gtk_tree_view_column_set_reorderable (column, FALSE);
+  gtk_tree_view_column_set_min_width (column, 20);
+#endif
+
   renderer = gtk_cell_renderer_text_new ();
   col = gtk_tree_view_insert_column_with_attributes (list->treeview,
                                                      -1,
@@ -745,7 +808,7 @@
   renderer = gtk_cell_renderer_text_new ();
   col = gtk_tree_view_insert_column_with_attributes (list->treeview,
                                                      -1,
-                                                     _("Mime-type"),
+                                                     _("Type"),
                                                      renderer,
                                                      "text", SEARCH_MIME,
                                                      NULL);





reply via email to

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