Yasumichi Akahoshi
yasum****@users*****
2005年 4月 11日 (月) 22:41:32 JST
Index: cxplorer/src/cxp-right-pane.c diff -u cxplorer/src/cxp-right-pane.c:1.26 cxplorer/src/cxp-right-pane.c:1.27 --- cxplorer/src/cxp-right-pane.c:1.26 Sat Apr 9 02:48:16 2005 +++ cxplorer/src/cxp-right-pane.c Mon Apr 11 22:41:32 2005 @@ -5,13 +5,15 @@ #endif #include <glib/gi18n.h> +#include <errno.h> +#include <fcntl.h> +#include <magic.h> #include <stdio.h> #include <string.h> #include <sys/types.h> #include <sys/stat.h> -#include <fcntl.h> +#include <time.h> #include <unistd.h> -#include <errno.h> #include "cxp-right-pane.h" /* If you use Pimpls, include the private structure @@ -30,6 +32,8 @@ gchar *preview_dir; gchar *preview_text; gchar *preview_binary; + magic_t normal_cookie; + magic_t mime_cookie; CxpHandler *handler; } CxpRightPanePrivate; @@ -94,7 +98,7 @@ static void cxp_right_pane_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec); -static GtkWidget *cxp_right_pane_file_list_new (void); +static GtkWidget *cxp_right_pane_file_list_new (CxpRightPane *self); static void cxp_right_pane_on_cursor_changed (GtkTreeView * treeview, gpointer user_data); static void cxp_right_pane_on_row_activated (GtkTreeView * treeview, @@ -207,12 +211,17 @@ GtkWidget *scrolled_window; PangoFontDescription *font_desc; + priv->normal_cookie = magic_open (MAGIC_NONE); + magic_load (priv->normal_cookie, NULL); + priv->mime_cookie = magic_open (MAGIC_MIME); + magic_load (priv->mime_cookie, NULL); + gtk_paned_set_position (GTK_PANED (self), 250); scrolled_window = gtk_scrolled_window_new (NULL, NULL); gtk_paned_pack1 (GTK_PANED (self), scrolled_window, TRUE, FALSE); gtk_widget_show (scrolled_window); - priv->file_list = cxp_right_pane_file_list_new (); + priv->file_list = cxp_right_pane_file_list_new (self); gtk_container_add (GTK_CONTAINER (scrolled_window), priv->file_list); gtk_widget_show (priv->file_list); @@ -263,6 +272,9 @@ * reference. */ g_object_unref (priv->handler); + magic_close (priv->normal_cookie); + magic_close (priv->mime_cookie); + /* Chain up to the parent class */ G_OBJECT_CLASS (parent_class)->dispose (obj); @@ -326,7 +338,7 @@ } } -static GtkWidget *cxp_right_pane_file_list_new (void) +static GtkWidget *cxp_right_pane_file_list_new (CxpRightPane *self) { GtkWidget *file_list; GtkListStore *store; @@ -357,12 +369,12 @@ gtk_tree_view_column_pack_start (column, renderer, FALSE); gtk_tree_view_column_set_cell_data_func (column, renderer, cxp_right_pane_draw_icon, - NULL, NULL); + self, NULL); renderer = gtk_cell_renderer_text_new (); gtk_tree_view_column_pack_start (column, renderer, FALSE); gtk_tree_view_column_set_cell_data_func (column, renderer, cxp_right_pane_draw_file_name, - NULL, NULL); + self, NULL); /* 2nd column */ renderer = gtk_cell_renderer_text_new (); @@ -383,7 +395,7 @@ gtk_tree_view_append_column (GTK_TREE_VIEW (file_list), column); gtk_tree_view_column_set_cell_data_func (column, renderer, cxp_right_pane_draw_file_type, - NULL, NULL); + self, NULL); /* 4th column */ renderer = gtk_cell_renderer_text_new (); @@ -556,19 +568,15 @@ GtkTreeModel * tree_model, GtkTreeIter * iter, gpointer data) { - magic_t cookie; + CxpRightPanePrivate *priv = CXP_RIGHT_PANE_GET_PRIVATE(data); gchar *fullpath; gchar *filetype; - cookie = magic_open (MAGIC_NONE); - magic_load (cookie, NULL); - gtk_tree_model_get (tree_model, iter, COL_FILE_PATH, &fullpath, COL_TERMINATOR); - filetype = g_strdup (magic_file (cookie, fullpath)); + filetype = g_strdup (magic_file (priv->normal_cookie, fullpath)); g_object_set (cell, "text", filetype, NULL); - magic_close (cookie); } /** @@ -686,7 +694,6 @@ { CxpRightPanePrivate *priv = CXP_RIGHT_PANE_GET_PRIVATE(self); gchar *cmd; - magic_t cookie; gchar *filetype; gchar *standard_output; gchar *stdout_utf8; @@ -699,9 +706,7 @@ } else { - cookie = magic_open (MAGIC_NONE); - magic_load (cookie, NULL); - filetype = g_strdup (magic_file (cookie, filename)); + filetype = g_strdup (magic_file (priv->normal_cookie, filename)); if (g_strrstr (filetype, "text") != NULL) { cmd = g_strdup_printf ("%s '%s'", @@ -710,7 +715,6 @@ } else if (strstr (filetype, "fifo") != NULL) { - magic_close(cookie); return; } else @@ -719,7 +723,6 @@ priv->preview_binary, filename); } - magic_close (cookie); } g_spawn_command_line_sync (cmd, &standard_output, NULL, &exit_status, NULL); Index: cxplorer/src/cxp-right-pane.h diff -u cxplorer/src/cxp-right-pane.h:1.10 cxplorer/src/cxp-right-pane.h:1.11 --- cxplorer/src/cxp-right-pane.h:1.10 Fri Apr 8 01:53:09 2005 +++ cxplorer/src/cxp-right-pane.h Mon Apr 11 22:41:32 2005 @@ -21,11 +21,6 @@ * Potentially, include other headers on which this header depends. */ #include <cxp.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> -#include <magic.h> -#include <time.h> #define CXP_TYPE_RIGHT_PANE (cxp_right_pane_get_type ()) #define CXP_RIGHT_PANE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CXP_TYPE_RIGHT_PANE, CxpRightPane)) Index: cxplorer/src/cxplorer-window.c diff -u cxplorer/src/cxplorer-window.c:1.25 cxplorer/src/cxplorer-window.c:1.26 --- cxplorer/src/cxplorer-window.c:1.25 Sun Apr 10 23:53:32 2005 +++ cxplorer/src/cxplorer-window.c Mon Apr 11 22:41:32 2005 @@ -29,6 +29,9 @@ #include <cxp.h> #include <glib/gi18n.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> #include <errno.h> #include "cxp-dir-view.h" #include "cxp-right-pane.h"