[Xfce4-commits] <squeeze:master> Fixed mime info and mime icons

Peter de Ridder noreply at xfce.org
Sun Aug 21 13:58:01 CEST 2011


Updating branch refs/heads/master
         to 26947daaf4219756f73b97b3cc7c74adead5981e (commit)
       from 72da5b00a24a60603191f5aba057a80b97527a8c (commit)

commit 26947daaf4219756f73b97b3cc7c74adead5981e
Author: Peter de Ridder <peter at xfce.org>
Date:   Sun Aug 21 13:55:46 2011 +0200

    Fixed mime info and mime icons

 libsqueeze/archive-iter.c    |   31 +++++++++++++++----------------
 libsqueeze/archive.c         |    6 +-----
 libsqueeze/libsqueeze-view.h |    2 +-
 src/archive_store.c          |   26 +++++++++-----------------
 src/notebook.c               |    2 +-
 5 files changed, 27 insertions(+), 40 deletions(-)

diff --git a/libsqueeze/archive-iter.c b/libsqueeze/archive-iter.c
index b5f36bd..1022c47 100644
--- a/libsqueeze/archive-iter.c
+++ b/libsqueeze/archive-iter.c
@@ -51,7 +51,7 @@ lsq_archive_entry_save_free(const LSQArchive *, LSQArchiveEntry *);
 inline static const gchar *
 lsq_archive_entry_get_filename(const LSQArchiveEntry *);
 inline static const gchar *
-lsq_archive_entry_get_mimetype(const LSQArchiveEntry *);
+lsq_archive_entry_get_contenttype(const LSQArchiveEntry *);
 
 inline static guint
 lsq_archive_entry_n_children(const LSQArchiveEntry *);
@@ -395,13 +395,14 @@ lsq_archive_iter_get_real_parent(LSQArchiveIter *iter)
 gboolean
 lsq_archive_iter_is_directory(const LSQArchiveIter *iter)
 {
+	const gchar *contenttype;
 #ifdef debug
 	g_return_val_if_fail(iter, FALSE);
 #endif
-	const gchar *mime = lsq_archive_entry_get_mimetype(iter->entry);
-	if(!mime)
+	contenttype = lsq_archive_entry_get_contenttype(iter->entry);
+	if(!contenttype)
 		return FALSE;
-	if(!strcmp(mime, LSQ_MIME_DIRECTORY))
+	if(!strcmp(contenttype, LSQ_MIME_DIRECTORY))
 		return TRUE;
 	return FALSE;
 }
@@ -591,12 +592,12 @@ lsq_archive_iter_get_filename(const LSQArchiveIter *iter)
 }
 
 const gchar*
-lsq_archive_iter_get_mime(const LSQArchiveIter *iter)
+lsq_archive_iter_get_contenttype(const LSQArchiveIter *iter)
 {
 #ifdef DEBUG
 	g_return_val_if_fail(iter, FALSE);
 #endif
-	return lsq_archive_entry_get_mimetype(iter->entry);
+	return lsq_archive_entry_get_contenttype(iter->entry);
 }
 
 gboolean
@@ -892,23 +893,21 @@ lsq_archive_entry_new(const gchar *filename)
 	if(pos)
 	{
 		entry->filename = g_strndup(filename, (gsize)(pos - filename));
-		/*entry->mime_info = thunar_vfs_mime_database_get_info(lsq_mime_database, LSQ_MIME_DIRECTORY);*/
+		entry->content_type = g_strdup(LSQ_MIME_DIRECTORY);
 	}
 	else
 	{
 		entry->filename = g_strdup(filename);
-        /*
 		if(g_utf8_validate (filename, -1, NULL))
 		{
-			entry->mime_info = thunar_vfs_mime_database_get_info_for_name(lsq_mime_database, entry->filename);
+			entry->content_type = g_content_type_guess(entry->filename, NULL, 0, NULL);
 		}
 		else
 		{
 			gchar *utf8_file = g_convert(filename, -1, "UTF-8", "WINDOWS-1252", NULL, NULL, NULL);
-			entry->mime_info = thunar_vfs_mime_database_get_info_for_name(lsq_mime_database, utf8_file);
+			entry->content_type = g_content_type_guess(utf8_file, NULL, 0, NULL);
 			g_free(utf8_file);
 		}
-        */
 	}
 
 	return entry;
@@ -1011,7 +1010,7 @@ lsq_archive_entry_free(const LSQArchive *archive, LSQArchiveEntry *entry)
 	/* free the properties */
 	lsq_archive_entry_props_free(archive, entry);
 
-	/* free the mime info */
+	/* free the content type */
 	if(entry->content_type)
     {
         g_free (entry->content_type);
@@ -1030,7 +1029,7 @@ lsq_archive_entry_get_filename(const LSQArchiveEntry *entry)
 }
 
 inline static const gchar *
-lsq_archive_entry_get_mimetype(const LSQArchiveEntry *entry)
+lsq_archive_entry_get_contenttype(const LSQArchiveEntry *entry)
 {
 	return entry->content_type;
 }
@@ -1196,9 +1195,9 @@ static LSQArchiveEntry *
 lsq_archive_entry_add_child(LSQArchiveEntry *parent, const gchar *filename)
 {
 	LSQArchiveEntry *child = lsq_archive_entry_new(filename);
-	const gchar *mime = lsq_archive_entry_get_mimetype(parent);
+	const gchar *contenttype = lsq_archive_entry_get_contenttype(parent);
 
-	if(!mime || strcmp(mime, LSQ_MIME_DIRECTORY))
+	if(!contenttype || strcmp(contenttype, LSQ_MIME_DIRECTORY))
 	{
         /*
 		if(parent->content_type)
@@ -1299,7 +1298,7 @@ lsq_archive_entry_get_prop_str(const LSQArchive *archive, const LSQArchiveEntry
 			retval = lsq_archive_entry_get_filename(entry);
 			break;
 		case LSQ_ARCHIVE_PROP_MIME_TYPE:
-			retval = lsq_archive_entry_get_mimetype(entry);
+			retval = lsq_archive_entry_get_contenttype(entry);
 			break;
 		default:
 			props_iter = entry->props;
diff --git a/libsqueeze/archive.c b/libsqueeze/archive.c
index b591ecd..3e584c0 100644
--- a/libsqueeze/archive.c
+++ b/libsqueeze/archive.c
@@ -41,10 +41,6 @@
 #define LSQ_ENTRY_CHILD_BUFFER_SIZE 500
 #endif
 
-#ifndef LSQ_MIME_DIRECTORY
-#define LSQ_MIME_DIRECTORY "inode/directory"
-#endif
-
 static void
 lsq_archive_class_init(LSQArchiveClass *archive_class);
 
@@ -150,7 +146,6 @@ lsq_archive_finalize(GObject *object)
  * lsq_archive_new:
  *
  * @path: path to archive
- * @mime: mime-type (or NULL)
  *
  * Return value: LSQArchive object
  *
@@ -181,6 +176,7 @@ lsq_archive_new (GFile *file)
 	{
 	  content_type = g_file_info_get_attribute_string (file_info, "standard::content-type");
 	  archive->priv->content_type = g_strdup (content_type); 
+	  g_object_unref(file_info);
 	}
 #ifdef DEBUG
 	g_debug("mime: %s\n", archive->priv->content_type);
diff --git a/libsqueeze/libsqueeze-view.h b/libsqueeze/libsqueeze-view.h
index ee6a972..d8fef13 100644
--- a/libsqueeze/libsqueeze-view.h
+++ b/libsqueeze/libsqueeze-view.h
@@ -30,7 +30,7 @@ LSQArchiveIter	 *lsq_archive_iter_get_parent(LSQArchiveIter *);
 
 gboolean			lsq_archive_iter_get_prop_value(const LSQArchiveIter *iter, guint n, GValue *value);
 const gchar		*lsq_archive_iter_get_filename(const LSQArchiveIter *);
-const gchar		*lsq_archive_iter_get_mime(const LSQArchiveIter *);
+const gchar		*lsq_archive_iter_get_contenttype(const LSQArchiveIter *);
 gchar			  *lsq_archive_iter_get_path(const LSQArchiveIter *archive);
 
 LSQArchiveIter	 *lsq_archive_get_iter(LSQArchive *archive, const gchar *path);
diff --git a/src/archive_store.c b/src/archive_store.c
index bf162da..9aecb71 100644
--- a/src/archive_store.c
+++ b/src/archive_store.c
@@ -124,7 +124,7 @@ sq_archive_insertionsort(SQArchiveStore *store, gint left, gint right);
 static void
 sq_archive_store_sort(SQArchiveStore *store);
 
-static const gchar *
+static GIcon *
 sq_archive_store_get_icon_name_for_iter(SQArchiveStore *store, LSQArchiveIter *iter);
 
 static void
@@ -411,8 +411,9 @@ sq_archive_store_get_column_type(GtkTreeModel *tree_model, gint index_)
 	switch(index_)
 	{
 		case SQ_ARCHIVE_STORE_EXTRA_PROP_PATH:
-		case SQ_ARCHIVE_STORE_EXTRA_PROP_ICON:
 			return G_TYPE_STRING; 
+		case SQ_ARCHIVE_STORE_EXTRA_PROP_ICON:
+			return G_TYPE_ICON; 
 		default:
 			return lsq_archive_get_entry_property_type(archive, index_ - SQ_ARCHIVE_STORE_EXTRA_PROP_COUNT);
 	}
@@ -536,10 +537,10 @@ sq_archive_store_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, gint co
 				lsq_archive_iter_unref(parent);
 			break;
 			case SQ_ARCHIVE_STORE_EXTRA_PROP_ICON:
-				g_value_init(value, G_TYPE_STRING);
+				g_value_init(value, G_TYPE_ICON);
 
 				if(store->props._show_icons)
-					g_value_set_string(value, sq_archive_store_get_icon_name_for_iter(store, entry));
+					g_value_take_object(value, sq_archive_store_get_icon_name_for_iter(store, entry));
 			break;
 			case LSQ_ARCHIVE_PROP_FILENAME + SQ_ARCHIVE_STORE_EXTRA_PROP_COUNT:
 				if(store->props._show_full_path)
@@ -565,9 +566,9 @@ sq_archive_store_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, gint co
 		switch(column)
 		{
 			case SQ_ARCHIVE_STORE_EXTRA_PROP_ICON:
-				g_value_init(value, G_TYPE_STRING);
+				g_value_init(value, G_TYPE_ICON);
 				if(store->props._show_icons)
-					g_value_set_string(value, GTK_STOCK_GO_UP);
+					g_value_take_object(value, g_themed_icon_new(GTK_STOCK_GO_UP));
 			break;
 			case LSQ_ARCHIVE_PROP_FILENAME + SQ_ARCHIVE_STORE_EXTRA_PROP_COUNT:
 				g_value_init(value, G_TYPE_STRING);
@@ -1003,19 +1004,10 @@ sq_archive_insertionsort(SQArchiveStore *store, gint left, gint right)
 	}
 }
 
-static const gchar *
+static GIcon *
 sq_archive_store_get_icon_name_for_iter(SQArchiveStore *store, LSQArchiveIter *iter)
 {
-    /*
-	ThunarVfsMimeInfo *mime_info = thunar_vfs_mime_database_get_info(mimedb, lsq_archive_iter_get_mime(iter));
-	const gchar *icon_name = thunar_vfs_mime_info_lookup_icon_name(mime_info, store->icon_theme);
-	if(icon_name && !gtk_icon_theme_has_icon(store->icon_theme, icon_name))
-		icon_name = NULL;
-	thunar_vfs_mime_info_unref(mime_info);
-	g_object_unref(mimedb);
-	return icon_name;
-    */
-    return NULL;
+	return g_content_type_get_icon(lsq_archive_iter_get_contenttype(iter));
 }
 
 GtkTreeModel *
diff --git a/src/notebook.c b/src/notebook.c
index 05ba718..97effba 100644
--- a/src/notebook.c
+++ b/src/notebook.c
@@ -710,7 +710,7 @@ sq_notebook_treeview_reset_columns(LSQArchive *archive, GtkTreeView *treeview)
 	renderer = gtk_cell_renderer_pixbuf_new();
 	g_object_set(G_OBJECT(renderer), "stock-size", GTK_ICON_SIZE_SMALL_TOOLBAR, NULL);
 	gtk_tree_view_column_pack_start(column, renderer, FALSE);
-	gtk_tree_view_column_set_attributes(column, renderer, "icon-name", SQ_ARCHIVE_STORE_EXTRA_PROP_ICON, NULL);
+	gtk_tree_view_column_set_attributes(column, renderer, "gicon", SQ_ARCHIVE_STORE_EXTRA_PROP_ICON, NULL);
 
 	renderer = gtk_cell_renderer_text_new();
 	gtk_tree_view_column_pack_start(column, renderer, TRUE);


More information about the Xfce4-commits mailing list