Author: colossus
Date: 2007-08-01 11:30:41 +0000 (Wed, 01 Aug 2007)
New Revision: 25947
Removed:
xarchiver/trunk/src/xdgmime/.deps/
Modified:
xarchiver/trunk/src/archive.c
xarchiver/trunk/src/mime.c
xarchiver/trunk/src/mime.h
xarchiver/trunk/src/window.c
xarchiver/trunk/src/xdgmime/xdgmime.c
xarchiver/trunk/src/xdgmime/xdgmime.h
xarchiver/trunk/src/xdgmime/xdgmimealias.c
xarchiver/trunk/src/xdgmime/xdgmimecache.c
xarchiver/trunk/src/xdgmime/xdgmimeglob.c
xarchiver/trunk/src/xdgmime/xdgmimemagic.c
xarchiver/trunk/src/zip.c
Log:
An icon corresponding to the filename mimetype is now shown next to it.
Deleted .deps dir in src/xdgmime
Updated XDG files.
Modified: xarchiver/trunk/src/archive.c
===================================================================
--- xarchiver/trunk/src/archive.c 2007-07-31 21:31:59 UTC (rev 25946)
+++ xarchiver/trunk/src/archive.c 2007-08-01 11:30:41 UTC (rev 25947)
@@ -544,8 +544,7 @@
current_column = entry->columns;
gtk_list_store_append (archive->liststore, &iter);
- GdkPixbuf *pixbuf = xa_get_stock_mime_icon(entry->filename);
- gtk_list_store_set
(archive->liststore,&iter,0,pixbuf,1,entry->filename,-1);
+ gtk_list_store_set
(archive->liststore,&iter,0,xa_get_stock_mime_icon(entry->filename),1,entry->filename,-1);
for (i = 0; i < archive->nc; i++)
{
Modified: xarchiver/trunk/src/mime.c
===================================================================
--- xarchiver/trunk/src/mime.c 2007-07-31 21:31:59 UTC (rev 25946)
+++ xarchiver/trunk/src/mime.c 2007-08-01 11:30:41 UTC (rev 25947)
@@ -18,26 +18,40 @@
*/
#include "mime.h"
+#include <string.h>
-//
-//gboolean gtk_icon_theme_has_icon
-
-GdkPixbuf *xa_get_stock_mime_icon(gchar *filename)
+const char *xa_get_stock_mime_icon(gchar *filename)
{
const char *mime;
- GdkPixbuf *pixbuf = NULL;
- const char *icon_name = "GTK_STOCK_FILE";
+ const char *icon_name = "binary";
mime = xdg_mime_get_mime_type_from_file_name(filename);
- g_print ("%s\n",mime);
+ g_print ("%s\t%s\n",filename,mime);
if (strncmp(mime,"image/",6) == 0)
icon_name = "image";
else if (strcmp(mime,"text/html") == 0)
icon_name = "html";
- else if (strcmp(mime,"application/octet-stream") == 0)
- icon_name = "folder";
-
- pixbuf = gtk_icon_theme_load_icon
(gtk_icon_theme_get_default(),icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR, 0, NULL);
- return pixbuf;
+ else if (strncmp(mime,"text/",5) == 0)
+ icon_name = "txt";
+ else if (strcmp(mime,"application/rtf") == 0 ||
strcmp(mime,"application/pdf") == 0 || strcmp(mime,"application/msword") == 0)
+ icon_name = "document";
+ else if (strcmp(mime,"audio/mpeg") == 0 || strcmp(mime,"audio/midi") ==
0 )
+ icon_name = "sound";
+ else if (strcmp(mime,"application/vnd.ms-excel") == 0)
+ icon_name = "gnome-mime-application-vnd.ms-excel";
+ else if (strcmp(mime,"application/zip") == 0 ||
strcmp(mime,"application/x-rar") == 0 || strcmp(mime,"application/x-tar") == 0
+ || strcmp(mime,"application/x-7z-compressed") == 0)
+ icon_name = "package";
+ else if (strcmp(mime,"application/x-shockwave-flash") == 0 ||
strcmp(mime,"video/mpeg") == 0 || strcmp(mime,"video/quicktime") == 0
+ || strcmp(mime,"video/x-msvideo") == 0)
+ icon_name = "video";
+ else if (strcmp(mime,"application/x-cd-image") == 0)
+ icon_name = "application-x-cd-image";
+ else if (strcmp(mime,"application/x-php") == 0)
+ icon_name = "gnome-mime-application-x-php";
+ else if (strcmp(mime,"application/x-perl") == 0 || strcmp
(mime,"application/x-csh") == 0 || strcmp (mime,"application/x-shellscript") ==
0)
+ icon_name = "gnome-mime-application-x-perl";
+
+ return icon_name;
}
Modified: xarchiver/trunk/src/mime.h
===================================================================
--- xarchiver/trunk/src/mime.h 2007-07-31 21:31:59 UTC (rev 25946)
+++ xarchiver/trunk/src/mime.h 2007-08-01 11:30:41 UTC (rev 25947)
@@ -23,5 +23,5 @@
#include "xdgmime/xdgmime.h"
#include <gtk/gtk.h>
-GdkPixbuf *xa_get_stock_mime_icon(gchar *filename);
+const char *xa_get_stock_mime_icon(gchar *filename);
#endif
Modified: xarchiver/trunk/src/window.c
===================================================================
--- xarchiver/trunk/src/window.c 2007-07-31 21:31:59 UTC (rev 25946)
+++ xarchiver/trunk/src/window.c 2007-08-01 11:30:41 UTC (rev 25947)
@@ -1164,8 +1164,9 @@
/* First column: icon + text */
column = gtk_tree_view_column_new();
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, "pixbuf",0,NULL);
+ gtk_tree_view_column_set_attributes(column, renderer,
"icon-name",0,NULL);
renderer = gtk_cell_renderer_text_new ();
gtk_tree_view_column_pack_start(column, renderer, TRUE);
Modified: xarchiver/trunk/src/xdgmime/xdgmime.c
===================================================================
--- xarchiver/trunk/src/xdgmime/xdgmime.c 2007-07-31 21:31:59 UTC (rev
25946)
+++ xarchiver/trunk/src/xdgmime/xdgmime.c 2007-08-01 11:30:41 UTC (rev
25947)
@@ -60,7 +60,7 @@
XdgMimeCache **_caches = NULL;
static int n_caches = 0;
-const char *xdg_mime_type_unknown = "application/octet-stream";
+const char xdg_mime_type_unknown[] = "application/octet-stream";
enum
@@ -281,7 +281,8 @@
* FIXME: This doesn't protect against permission changes.
*/
static int
-xdg_check_file (const char *file_path)
+xdg_check_file (const char *file_path,
+ int *exists)
{
struct stat st;
@@ -290,6 +291,9 @@
{
XdgDirTimeList *list;
+ if (exists)
+ *exists = TRUE;
+
for (list = dir_time_list; list; list = list->next)
{
if (! strcmp (list->directory_name, file_path) &&
@@ -306,6 +310,9 @@
return TRUE;
}
+ if (exists)
+ *exists = FALSE;
+
return FALSE;
}
@@ -313,26 +320,30 @@
xdg_check_dir (const char *directory,
int *invalid_dir_list)
{
- int invalid;
+ int invalid, exists;
char *file_name;
assert (directory != NULL);
- /* Check the globs file */
- file_name = malloc (strlen (directory) + strlen ("/mime/globs") + 1);
- strcpy (file_name, directory); strcat (file_name, "/mime/globs");
- invalid = xdg_check_file (file_name);
+ /* Check the mime.cache file */
+ file_name = malloc (strlen (directory) + strlen ("/mime/mime.cache") + 1);
+ strcpy (file_name, directory); strcat (file_name, "/mime/mime.cache");
+ invalid = xdg_check_file (file_name, &exists);
free (file_name);
if (invalid)
{
*invalid_dir_list = TRUE;
return TRUE;
}
+ else if (exists)
+ {
+ return FALSE;
+ }
- /* Check the magic file */
- file_name = malloc (strlen (directory) + strlen ("/mime/magic") + 1);
- strcpy (file_name, directory); strcat (file_name, "/mime/magic");
- invalid = xdg_check_file (file_name);
+ /* Check the globs file */
+ file_name = malloc (strlen (directory) + strlen ("/mime/globs") + 1);
+ strcpy (file_name, directory); strcat (file_name, "/mime/globs");
+ invalid = xdg_check_file (file_name, NULL);
free (file_name);
if (invalid)
{
@@ -340,10 +351,10 @@
return TRUE;
}
- /* Check the mime.cache file */
- file_name = malloc (strlen (directory) + strlen ("/mime/mime.cache") + 1);
- strcpy (file_name, directory); strcat (file_name, "/mime/mime.cache");
- invalid = xdg_check_file (file_name);
+ /* Check the magic file */
+ file_name = malloc (strlen (directory) + strlen ("/mime/magic") + 1);
+ strcpy (file_name, directory); strcat (file_name, "/mime/magic");
+ invalid = xdg_check_file (file_name, NULL);
free (file_name);
if (invalid)
{
@@ -528,15 +539,15 @@
const char *
xdg_mime_get_mime_type_from_file_name (const char *file_name)
{
- const char *mime_types[2];
+ const char *mime_type;
xdg_mime_init ();
if (_caches)
return _xdg_mime_cache_get_mime_type_from_file_name (file_name);
- if (_xdg_glob_hash_lookup_file_name (global_hash, file_name, mime_types, 2)
== 1)
- return mime_types[0];
+ if (_xdg_glob_hash_lookup_file_name (global_hash, file_name, &mime_type, 1))
+ return mime_type;
else
return XDG_MIME_TYPE_UNKNOWN;
}
@@ -584,6 +595,17 @@
parent_list = NULL;
}
+ if (_caches)
+ {
+ int i;
+
+ for (i = 0; i < n_caches; i++)
+ _xdg_mime_cache_unref (_caches[i]);
+ free (_caches);
+ _caches = NULL;
+ n_caches = 0;
+ }
+
for (list = callback_list; list; list = list->next)
(list->callback) (list->data);
@@ -601,7 +623,7 @@
return _xdg_mime_magic_get_buffer_extents (global_magic);
}
-static const char *
+const char *
_xdg_mime_unalias_mime_type (const char *mime_type)
{
const char *lookup;
@@ -663,7 +685,7 @@
return 0;
}
-#if 0
+#if 1
static int
xdg_mime_is_super_type (const char *mime)
{
@@ -696,7 +718,7 @@
if (strcmp (umime, ubase) == 0)
return 1;
-#if 0
+#if 1
/* Handle supertypes */
if (xdg_mime_is_super_type (ubase) &&
xdg_mime_media_type_equal (umime, ubase))
Modified: xarchiver/trunk/src/xdgmime/xdgmime.h
===================================================================
--- xarchiver/trunk/src/xdgmime/xdgmime.h 2007-07-31 21:31:59 UTC (rev
25946)
+++ xarchiver/trunk/src/xdgmime/xdgmime.h 2007-08-01 11:30:41 UTC (rev
25947)
@@ -59,12 +59,13 @@
#define xdg_mime_unalias_mime_type XDG_ENTRY(unalias_mime_type)
#define xdg_mime_get_max_buffer_extents XDG_ENTRY(get_max_buffer_extents)
#define xdg_mime_shutdown XDG_ENTRY(shutdown)
+#define xdg_mime_dump XDG_ENTRY(dump)
#define xdg_mime_register_reload_callback
XDG_ENTRY(register_reload_callback)
#define xdg_mime_remove_callback XDG_ENTRY(remove_callback)
#define xdg_mime_type_unknown XDG_ENTRY(type_unknown)
#endif
-extern const char *xdg_mime_type_unknown;
+extern const char xdg_mime_type_unknown[];
#define XDG_MIME_TYPE_UNKNOWN xdg_mime_type_unknown
const char *xdg_mime_get_mime_type_for_data (const void *data,
@@ -95,14 +96,16 @@
XdgMimeDestroy destroy);
void xdg_mime_remove_callback (int
callback_id);
- /* Private versions of functions that don't call xdg_mime_init () */
+ /* Private versions of functions that don't call xdg_mime_init () */
int _xdg_mime_mime_type_equal (const char *mime_a,
const char *mime_b);
+int _xdg_mime_media_type_equal (const char *mime_a,
+ const char *mime_b);
int _xdg_mime_mime_type_subclass (const char *mime,
const char *base);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
-
#endif /* __XDG_MIME_H__ */
Modified: xarchiver/trunk/src/xdgmime/xdgmimealias.c
===================================================================
--- xarchiver/trunk/src/xdgmime/xdgmimealias.c 2007-07-31 21:31:59 UTC (rev
25946)
+++ xarchiver/trunk/src/xdgmime/xdgmimealias.c 2007-08-01 11:30:41 UTC (rev
25947)
@@ -105,7 +105,7 @@
if (list->n_aliases > 0)
{
key.alias = (char *)alias;
- key.mime_type = 0;
+ key.mime_type = NULL;
entry = bsearch (&key, list->aliases, list->n_aliases,
sizeof (XdgAlias), alias_entry_cmp);
Modified: xarchiver/trunk/src/xdgmime/xdgmimecache.c
===================================================================
--- xarchiver/trunk/src/xdgmime/xdgmimecache.c 2007-07-31 21:31:59 UTC (rev
25946)
+++ xarchiver/trunk/src/xdgmime/xdgmimecache.c 2007-08-01 11:30:41 UTC (rev
25947)
@@ -123,7 +123,7 @@
if (fstat (fd, &st) < 0 || st.st_size < 4)
goto done;
- buffer = (char *) mmap (NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
+ buffer = (char *) mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
if (buffer == MAP_FAILED)
goto done;
@@ -163,7 +163,7 @@
xdg_uint32_t data_offset = GET_UINT32 (cache->buffer, offset + 16);
xdg_uint32_t mask_offset = GET_UINT32 (cache->buffer, offset + 20);
- unsigned int i, j;
+ int i, j;
for (i = range_start; i <= range_start + range_length; i++)
{
@@ -212,7 +212,7 @@
xdg_uint32_t n_children = GET_UINT32 (cache->buffer, offset + 24);
xdg_uint32_t child_offset = GET_UINT32 (cache->buffer, offset + 28);
- unsigned int i;
+ int i;
if (cache_magic_matchlet_compare_to_data (cache, offset, data, len))
{
@@ -242,7 +242,7 @@
xdg_uint32_t n_matchlets = GET_UINT32 (cache->buffer, offset + 8);
xdg_uint32_t matchlet_offset = GET_UINT32 (cache->buffer, offset + 12);
- unsigned int i;
+ int i;
for (i = 0; i < n_matchlets; i++)
{
@@ -270,8 +270,7 @@
xdg_uint32_t n_entries;
xdg_uint32_t offset;
- unsigned int j;
- int n;
+ int j, n;
*prio = 0;
@@ -395,8 +394,7 @@
const char *mime_type;
const char *ptr;
- int i, n;
- unsigned int j;
+ int i, j, n;
n = 0;
for (i = 0; _caches[i]; i++)
@@ -440,8 +438,7 @@
xdg_uint32_t n_children;
xdg_uint32_t child_offset;
- int min, max, mid, n;
- unsigned int i;
+ int min, max, mid, n, i;
character = _xdg_utf8_to_ucs4 (suffix);
if (ignore_case)
@@ -466,7 +463,8 @@
{
mimetype_offset = GET_UINT32 (cache->buffer, offset + 16 * mid +
4);
n = 0;
- mime_types[n++] = cache->buffer + mimetype_offset;
+ if (mimetype_offset)
+ mime_types[n++] = cache->buffer + mimetype_offset;
n_children = GET_UINT32 (cache->buffer, offset + 16 * mid + 8);
child_offset = GET_UINT32 (cache->buffer, offset + 16 * mid + 12);
@@ -532,9 +530,8 @@
static void
find_stopchars (char *stopchars)
{
- int i, k, l;
- unsigned int j;
-
+ int i, j, k, l;
+
k = 0;
for (i = 0; _caches[i]; i++)
{
@@ -551,15 +548,8 @@
if (match_char < 128)
{
for (l = 0; l < k; l++)
- {
- xdg_uint32_t character;
-
- character = stopchars[l];
-
- if (character == match_char)
- break;
- }
-
+ if (stopchars[l] == match_char)
+ break;
if (l == k)
{
stopchars[k] = (char) match_char;
@@ -748,10 +738,10 @@
const char *
_xdg_mime_cache_get_mime_type_from_file_name (const char *file_name)
{
- const char *mime_types[2];
+ const char *mime_type;
- if (cache_glob_lookup_file_name (file_name, mime_types, 2) == 1)
- return mime_types[0];
+ if (cache_glob_lookup_file_name (file_name, &mime_type, 1))
+ return mime_type;
else
return XDG_MIME_TYPE_UNKNOWN;
}
@@ -779,9 +769,8 @@
{
const char *umime, *ubase;
- int i, min, max, med, cmp;
- unsigned int j;
-
+ int i, j, min, max, med, cmp;
+
umime = _xdg_mime_cache_unalias_mime_type (mime);
ubase = _xdg_mime_cache_unalias_mime_type (base);
@@ -862,11 +851,12 @@
char **
_xdg_mime_cache_list_mime_parents (const char *mime)
{
- int i, p;
- unsigned int j;
+ int i, j, k, p;
char *all_parents[128]; /* we'll stop at 128 */
char **result;
+ mime = xdg_mime_unalias_mime_type (mime);
+
p = 0;
for (i = 0; _caches[i]; i++)
{
@@ -877,16 +867,20 @@
for (j = 0; j < n_entries; j++)
{
- xdg_uint32_t mimetype_offset = GET_UINT32 (cache->buffer, list_offset
+ 4 + 8 * i);
- xdg_uint32_t parents_offset = GET_UINT32 (cache->buffer, list_offset
+ 4 + 8 * i + 4);
-
+ xdg_uint32_t mimetype_offset = GET_UINT32 (cache->buffer, list_offset
+ 4 + 8 * j);
+ xdg_uint32_t parents_offset = GET_UINT32 (cache->buffer, list_offset
+ 4 + 8 * j + 4);
+
if (strcmp (cache->buffer + mimetype_offset, mime) == 0)
{
+ xdg_uint32_t parent_mime_offset;
xdg_uint32_t n_parents = GET_UINT32 (cache->buffer,
parents_offset);
-
- for (j = 0; j < n_parents; j++)
- all_parents[p++] = cache->buffer + parents_offset + 4 + 4 * j;
+ for (k = 0; k < n_parents && p < 127; k++)
+ {
+ parent_mime_offset = GET_UINT32 (cache->buffer,
parents_offset + 4 + 4 * k);
+ all_parents[p++] = cache->buffer + parent_mime_offset;
+ }
+
break;
}
}
Modified: xarchiver/trunk/src/xdgmime/xdgmimeglob.c
===================================================================
--- xarchiver/trunk/src/xdgmime/xdgmimeglob.c 2007-07-31 21:31:59 UTC (rev
25946)
+++ xarchiver/trunk/src/xdgmime/xdgmimeglob.c 2007-08-01 11:30:41 UTC (rev
25947)
@@ -308,12 +308,12 @@
if (*file_name == '\000')
{
n = 0;
- if (node->mime_type)
+ if (node->mime_type)
mime_types[n++] = node->mime_type;
node = node->child;
while (n < n_mime_types && node && node->character == 0)
{
- if (node->mime_type)
+ if (node->mime_type)
mime_types[n++] = node->mime_type;
node = node->next;
}
Modified: xarchiver/trunk/src/xdgmime/xdgmimemagic.c
===================================================================
--- xarchiver/trunk/src/xdgmime/xdgmimemagic.c 2007-07-31 21:31:59 UTC (rev
25946)
+++ xarchiver/trunk/src/xdgmime/xdgmimemagic.c 2007-08-01 11:30:41 UTC (rev
25947)
@@ -47,7 +47,9 @@
#define TRUE (!FALSE)
#endif
-extern int errno;
+#if !defined getc_unlocked && !defined HAVE_GETC_UNLOCKED
+# define getc_unlocked(fp) getc (fp)
+#endif
typedef struct XdgMimeMagicMatch XdgMimeMagicMatch;
typedef struct XdgMimeMagicMatchlet XdgMimeMagicMatchlet;
@@ -315,7 +317,7 @@
int c;
int end_of_file;
int indent = 0;
- unsigned int bytes_read;
+ int bytes_read;
assert (magic_file != NULL);
@@ -454,21 +456,17 @@
if (c == '+')
{
- int range_length;
-
- range_length = _xdg_mime_magic_read_a_number (magic_file, &end_of_file);
+ matchlet->range_length = _xdg_mime_magic_read_a_number (magic_file,
&end_of_file);
if (end_of_file)
{
_xdg_mime_magic_matchlet_free (matchlet);
return XDG_MIME_MAGIC_EOF;
}
- if (range_length == -1)
+ if (matchlet->range_length == -1)
{
_xdg_mime_magic_matchlet_free (matchlet);
return XDG_MIME_MAGIC_ERROR;
}
- /* now we are sure that range_length is positive */
- matchlet->range_length = (unsigned int) range_length;
c = getc_unlocked (magic_file);
}
@@ -478,9 +476,7 @@
/* We clean up the matchlet, byte swapping if needed */
if (matchlet->word_size > 1)
{
-#if LITTLE_ENDIAN
- unsigned int i;
-#endif
+ int i;
if (matchlet->value_length % matchlet->word_size != 0)
{
_xdg_mime_magic_matchlet_free (matchlet);
@@ -525,7 +521,7 @@
const void *data,
size_t len)
{
- unsigned int i, j;
+ int i, j;
for (i = matchlet->offset; i < matchlet->offset + matchlet->range_length;
i++)
{
int valid_matchlet = TRUE;
@@ -666,28 +662,15 @@
XdgMimeMagicMatch *match;
const char *mime_type;
int n;
- int priority;
- int had_match;
mime_type = NULL;
- priority = 0;
- had_match = 0;
for (match = mime_magic->match_list; match; match = match->next)
{
if (_xdg_mime_magic_match_compare_to_data (match, data, len))
{
- if (!had_match || match->priority > priority ||
- (mime_type != NULL && _xdg_mime_mime_type_subclass
(match->mime_type, mime_type)))
- {
- mime_type = match->mime_type;
- priority = match->priority;
- }
- else if (had_match && match->priority == priority)
- /* multiple unrelated patterns with the same priority matched,
- * so we can't tell what type this is. */
- mime_type = NULL;
-
- had_match = 1;
+ if ((mime_type == NULL) || (_xdg_mime_mime_type_subclass
(match->mime_type, mime_type))) {
+ mime_type = match->mime_type;
+ }
}
else
{
Modified: xarchiver/trunk/src/zip.c
===================================================================
--- xarchiver/trunk/src/zip.c 2007-07-31 21:31:59 UTC (rev 25946)
+++ xarchiver/trunk/src/zip.c 2007-08-01 11:30:41 UTC (rev 25947)
@@ -43,7 +43,7 @@
if (archive->child_pid == 0)
return;
- GType types[] =
{GDK_TYPE_PIXBUF,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_UINT64,G_TYPE_UINT64,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING};
+ GType types[] =
{G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_UINT64,G_TYPE_UINT64,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING};
archive->column_types = g_malloc0(sizeof(types));
for (i = 0; i < 10; i++)
archive->column_types[i] = types[i];
_______________________________________________
Xfce4-commits mailing list
[email protected]
http://foo-projects.org/mailman/listinfo/xfce4-commits