diff options
author | Moon <moon@140774ce-b5e7-0310-ab8b-a85725594a96> | 2008-06-06 19:10:13 +0000 |
---|---|---|
committer | Moon <moon@140774ce-b5e7-0310-ab8b-a85725594a96> | 2008-06-06 19:10:13 +0000 |
commit | 7f9eda78b1b4bdadf234587bbe908fc7d570b50c (patch) | |
tree | 76af4d4b07c33a4d9ff11043d14e40c6791a4da8 | |
parent | 6c9e28a988f4b94d6af89047862e3a50abc0a08e (diff) | |
download | gnunet-gtk-7f9eda78b1b4bdadf234587bbe908fc7d570b50c.tar.gz gnunet-gtk-7f9eda78b1b4bdadf234587bbe908fc7d570b50c.zip |
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)
-rw-r--r-- | configure.ac | 4 | ||||
-rw-r--r-- | src/plugins/fs/Makefile.am | 2 | ||||
-rw-r--r-- | src/plugins/fs/fs.h | 3 | ||||
-rw-r--r-- | src/plugins/fs/search.c | 81 |
4 files changed, 81 insertions, 9 deletions
diff --git a/configure.ac b/configure.ac index 982b73bd..b5ffcf17 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -60,6 +60,10 @@ else | |||
60 | AC_MSG_ERROR(Cannot find GTK: Is gtk-config in path?) | 60 | AC_MSG_ERROR(Cannot find GTK: Is gtk-config in path?) |
61 | fi | 61 | fi |
62 | 62 | ||
63 | # check for GIO (GLib >= 2.16) | ||
64 | PKG_CHECK_MODULES(GIO, gio-2.0, [AC_DEFINE(HAVE_GIO,1, GIO found | ||
65 | (optional))]) | ||
66 | |||
63 | 67 | ||
64 | CFLAGS="-Wall $CFLAGS" | 68 | CFLAGS="-Wall $CFLAGS" |
65 | # use '-fno-strict-aliasing', but only if the compiler can take it | 69 | # use '-fno-strict-aliasing', but only if the compiler can take it |
diff --git a/src/plugins/fs/Makefile.am b/src/plugins/fs/Makefile.am index 7d62fcc5..b00f8dcf 100644 --- a/src/plugins/fs/Makefile.am +++ b/src/plugins/fs/Makefile.am | |||
@@ -2,6 +2,7 @@ INCLUDES = \ | |||
2 | -I$(top_srcdir)/intl \ | 2 | -I$(top_srcdir)/intl \ |
3 | -I$(top_srcdir)/src/include \ | 3 | -I$(top_srcdir)/src/include \ |
4 | @GTK_CFLAGS@ \ | 4 | @GTK_CFLAGS@ \ |
5 | @GIO_CFLAGS@ \ | ||
5 | @GNUNETGTK_CFLAGS@ | 6 | @GNUNETGTK_CFLAGS@ |
6 | 7 | ||
7 | plugindir = $(libdir)/GNUnet | 8 | plugindir = $(libdir)/GNUnet |
@@ -25,6 +26,7 @@ libgnunetgtkmodule_fs_la_SOURCES = \ | |||
25 | libgnunetgtkmodule_fs_la_LIBADD = \ | 26 | libgnunetgtkmodule_fs_la_LIBADD = \ |
26 | $(top_builddir)/src/common/libgnunetgtk_common.la \ | 27 | $(top_builddir)/src/common/libgnunetgtk_common.la \ |
27 | @GTK_LIBS@ \ | 28 | @GTK_LIBS@ \ |
29 | @GIO_LIBS@ \ | ||
28 | @GNUNETGTK_LIBS@ \ | 30 | @GNUNETGTK_LIBS@ \ |
29 | $(INTLLIBS) \ | 31 | $(INTLLIBS) \ |
30 | -lgthread-2.0 \ | 32 | -lgthread-2.0 \ |
diff --git a/src/plugins/fs/fs.h b/src/plugins/fs/fs.h index 8af4ace4..8f5a2b13 100644 --- a/src/plugins/fs/fs.h +++ b/src/plugins/fs/fs.h | |||
@@ -52,6 +52,9 @@ enum | |||
52 | enum | 52 | enum |
53 | { | 53 | { |
54 | SEARCH_NAME = 0, | 54 | SEARCH_NAME = 0, |
55 | #ifdef HAVE_GIO | ||
56 | SEARCH_ICON, | ||
57 | #endif | ||
55 | SEARCH_SIZE, | 58 | SEARCH_SIZE, |
56 | SEARCH_HSIZE, | 59 | SEARCH_HSIZE, |
57 | SEARCH_MIME, | 60 | SEARCH_MIME, |
diff --git a/src/plugins/fs/search.c b/src/plugins/fs/search.c index f6a96470..11be760d 100644 --- a/src/plugins/fs/search.c +++ b/src/plugins/fs/search.c | |||
@@ -33,6 +33,9 @@ | |||
33 | #include <extractor.h> | 33 | #include <extractor.h> |
34 | #include <GNUnet/gnunet_util_crypto.h> | 34 | #include <GNUnet/gnunet_util_crypto.h> |
35 | #include <GNUnet/gnunet_namespace_lib.h> | 35 | #include <GNUnet/gnunet_namespace_lib.h> |
36 | #ifdef HAVE_GIO | ||
37 | #include <gio/gio.h> | ||
38 | #endif | ||
36 | 39 | ||
37 | 40 | ||
38 | /** | 41 | /** |
@@ -198,16 +201,23 @@ addEntryToSearchTree (SearchList * searchContext, | |||
198 | const GNUNET_ECRS_FileInfo * info, GtkTreeIter * iter) | 201 | const GNUNET_ECRS_FileInfo * info, GtkTreeIter * iter) |
199 | { | 202 | { |
200 | char *name; | 203 | char *name; |
204 | char *rawMime; | ||
201 | char *mime; | 205 | char *mime; |
202 | char *desc; | 206 | char *desc; |
203 | unsigned long long size; | 207 | unsigned long long size; |
204 | char *size_h; | 208 | char *size_h; |
205 | GdkPixbuf *pixbuf; | 209 | GdkPixbuf *pixbuf; |
206 | GdkPixbuf *rankbuf; | 210 | GdkPixbuf *rankbuf; |
211 | #ifdef HAVE_GIO | ||
212 | GdkPixbuf *icon = NULL; | ||
213 | GIcon *gicon = NULL; | ||
214 | const gchar **iconNames; | ||
215 | int i = 0; | ||
216 | #endif | ||
207 | enum GNUNET_URITRACK_STATE state; | 217 | enum GNUNET_URITRACK_STATE state; |
208 | 218 | ||
209 | state = GNUNET_URITRACK_get_state (ectx, cfg, info->uri); | 219 | state = GNUNET_URITRACK_get_state (ectx, cfg, info->uri); |
210 | mime = getMimeTypeFromMetaData (info->meta); | 220 | rawMime = getMimeTypeFromMetaData (info->meta); |
211 | desc = getDescriptionFromMetaData (info->meta); | 221 | desc = getDescriptionFromMetaData (info->meta); |
212 | name = getFileNameFromMetaData (info->meta); | 222 | name = getFileNameFromMetaData (info->meta); |
213 | size = GNUNET_ECRS_uri_test_chk (info->uri) | 223 | size = GNUNET_ECRS_uri_test_chk (info->uri) |
@@ -218,11 +228,41 @@ addEntryToSearchTree (SearchList * searchContext, | |||
218 | rankbuf = make_ranking_pixbuf (0, 0, 1, | 228 | rankbuf = make_ranking_pixbuf (0, 0, 1, |
219 | GNUNET_ECRS_uri_get_keyword_count_from_ksk | 229 | GNUNET_ECRS_uri_get_keyword_count_from_ksk |
220 | (searchContext->uri)); | 230 | (searchContext->uri)); |
221 | gtk_tree_store_set (searchContext->tree, iter, SEARCH_NAME, name, | 231 | #ifdef HAVE_GIO |
222 | SEARCH_SIZE, size, SEARCH_HSIZE, size_h, SEARCH_MIME, | 232 | if (0 == strcmp(rawMime, GNUNET_DIRECTORY_MIME)) |
223 | mime, SEARCH_DESC, desc, SEARCH_PIXBUF, pixbuf, | 233 | { |
224 | SEARCH_URI, GNUNET_ECRS_uri_duplicate (info->uri), | 234 | mime = GNUNET_strdup(_("Directory")); |
225 | SEARCH_META, | 235 | icon = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), |
236 | "folder", 16, 0, (GError **)NULL); | ||
237 | } | ||
238 | else | ||
239 | { | ||
240 | mime = g_content_type_get_description (rawMime); | ||
241 | gicon = g_content_type_get_icon (rawMime); | ||
242 | if (G_IS_THEMED_ICON (gicon)) | ||
243 | { | ||
244 | iconNames = (const gchar **)g_themed_icon_get_names | ||
245 | (G_THEMED_ICON (gicon)); | ||
246 | do { | ||
247 | icon = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), | ||
248 | iconNames[i], 16, 0, | ||
249 | (GError **)NULL); | ||
250 | i++; | ||
251 | } while ( (icon == NULL) && iconNames[i] ); | ||
252 | } | ||
253 | } | ||
254 | #else | ||
255 | mime = rawMime; | ||
256 | #endif | ||
257 | |||
258 | gtk_tree_store_set (searchContext->tree, iter, | ||
259 | #ifdef HAVE_GIO | ||
260 | SEARCH_ICON, icon, | ||
261 | #endif | ||
262 | SEARCH_NAME, name, SEARCH_SIZE, size, SEARCH_HSIZE, | ||
263 | size_h, SEARCH_MIME, mime, SEARCH_DESC, desc, | ||
264 | SEARCH_PIXBUF, pixbuf, SEARCH_URI, | ||
265 | GNUNET_ECRS_uri_duplicate (info->uri), SEARCH_META, | ||
226 | GNUNET_meta_data_duplicate (info->meta), | 266 | GNUNET_meta_data_duplicate (info->meta), |
227 | SEARCH_CELL_BG_COLOR, getColorCode (state), | 267 | SEARCH_CELL_BG_COLOR, getColorCode (state), |
228 | SEARCH_CELL_FG_COLOR, "black", SEARCH_INTERNAL, | 268 | SEARCH_CELL_FG_COLOR, "black", SEARCH_INTERNAL, |
@@ -233,10 +273,16 @@ addEntryToSearchTree (SearchList * searchContext, | |||
233 | g_object_unref (rankbuf); | 273 | g_object_unref (rankbuf); |
234 | if (pixbuf != NULL) | 274 | if (pixbuf != NULL) |
235 | g_object_unref (pixbuf); | 275 | g_object_unref (pixbuf); |
276 | #ifdef HAVE_GIO | ||
277 | if (gicon != NULL) | ||
278 | g_object_unref (gicon); | ||
279 | if (icon != NULL) | ||
280 | g_object_unref (icon); | ||
281 | #endif | ||
236 | GNUNET_free (size_h); | 282 | GNUNET_free (size_h); |
237 | GNUNET_free (name); | 283 | GNUNET_free (name); |
238 | GNUNET_free (desc); | 284 | GNUNET_free (desc); |
239 | GNUNET_free (mime); | 285 | GNUNET_free (rawMime); |
240 | } | 286 | } |
241 | 287 | ||
242 | /** | 288 | /** |
@@ -666,7 +712,10 @@ fs_search_started (struct GNUNET_FSUI_SearchList * fsui_list, | |||
666 | g_signal_connect_swapped (list->treeview, | 712 | g_signal_connect_swapped (list->treeview, |
667 | "button-press-event", | 713 | "button-press-event", |
668 | G_CALLBACK (search_click_handler), list); | 714 | G_CALLBACK (search_click_handler), list); |
669 | list->tree = gtk_tree_store_new (SEARCH_NUM, G_TYPE_STRING, /* name */ | 715 | list->tree = gtk_tree_store_new (SEARCH_NUM, G_TYPE_STRING, /* name */ |
716 | #ifdef HAVE_GIO | ||
717 | GDK_TYPE_PIXBUF, /* icon */ | ||
718 | #endif | ||
670 | G_TYPE_UINT64, /* size */ | 719 | G_TYPE_UINT64, /* size */ |
671 | G_TYPE_STRING, /* human-readable size */ | 720 | G_TYPE_STRING, /* human-readable size */ |
672 | G_TYPE_STRING, /* mime-type */ | 721 | G_TYPE_STRING, /* mime-type */ |
@@ -712,6 +761,20 @@ fs_search_started (struct GNUNET_FSUI_SearchList * fsui_list, | |||
712 | gtk_tree_view_column_set_sort_column_id (column, SEARCH_STATUS); | 761 | gtk_tree_view_column_set_sort_column_id (column, SEARCH_STATUS); |
713 | gtk_tree_view_column_set_min_width (column, 0); | 762 | gtk_tree_view_column_set_min_width (column, 0); |
714 | 763 | ||
764 | #ifdef HAVE_GIO | ||
765 | renderer = gtk_cell_renderer_pixbuf_new (); | ||
766 | col = gtk_tree_view_insert_column_with_attributes (list->treeview, | ||
767 | -1, | ||
768 | NULL, | ||
769 | renderer, | ||
770 | "pixbuf", | ||
771 | SEARCH_ICON, NULL); | ||
772 | column = gtk_tree_view_get_column (list->treeview, col - 1); | ||
773 | gtk_tree_view_column_set_resizable (column, TRUE); | ||
774 | gtk_tree_view_column_set_reorderable (column, FALSE); | ||
775 | gtk_tree_view_column_set_min_width (column, 20); | ||
776 | #endif | ||
777 | |||
715 | renderer = gtk_cell_renderer_text_new (); | 778 | renderer = gtk_cell_renderer_text_new (); |
716 | col = gtk_tree_view_insert_column_with_attributes (list->treeview, | 779 | col = gtk_tree_view_insert_column_with_attributes (list->treeview, |
717 | -1, | 780 | -1, |
@@ -745,7 +808,7 @@ fs_search_started (struct GNUNET_FSUI_SearchList * fsui_list, | |||
745 | renderer = gtk_cell_renderer_text_new (); | 808 | renderer = gtk_cell_renderer_text_new (); |
746 | col = gtk_tree_view_insert_column_with_attributes (list->treeview, | 809 | col = gtk_tree_view_insert_column_with_attributes (list->treeview, |
747 | -1, | 810 | -1, |
748 | _("Mime-type"), | 811 | _("Type"), |
749 | renderer, | 812 | renderer, |
750 | "text", SEARCH_MIME, | 813 | "text", SEARCH_MIME, |
751 | NULL); | 814 | NULL); |