⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gemfilechooser.c.svn-base

📁 一款Linux手机上应用的文件管理器 系统要求就安装Gtk+2.0
💻 SVN-BASE
📖 第 1 页 / 共 3 页
字号:
/*	libgemwidget - Gtk+ Embedded Widget library * *	Authors: YE Nan <nan.ye@orange-ftgourp.com>  *	         CHEN YaJing <chenyajing1226@gmail.com> *	This software and associated documentation files (the "Software")  *	are copyright (C) 2005 LiPS Linux Phone Standards Forum [FranceTelecom]  *	All Rights Reserved.  * *	A copyright license is hereby granted for redistribution and use of  *	the Software in source and binary forms, with or without modification,  *	provided that the following conditions are met:  *	- Redistributions of source code must retain the above copyright notice,  *	this copyright license and the following disclaimer.  *  - Redistributions in binary form must reproduce the above copyright  * 	notice, this copyright license and the following disclaimer in the  *	documentation and/or other materials provided with the distribution.  *	- Neither the name of LiPS  nor the names of its Members may be used  *	to endorse or promote products derived from the Software without  *	specific prior written permission.  * *	A patent license for any Necessary Claims owned by Members of LiPS Forum  *	to make, have made, use, import, offer to sell, lease and sell or otherwise  *	distribute any implementation compliant with the any specification adopted  *	by the LiPS Forumcan be obtained from the respective Members on reasonable  *	and non-discriminatory terms and conditions and under reciprocity, as  *	regulated in more detail in the Internal Policy of the LiPS Forum.  * *	THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER, ITS MEMBERS AND CONTRIBUTORS  *	"AS IS", AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,  *	THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE  *	AND NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER,  *	ITS MEMBERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,  *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,  *	PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;  *	OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,  *	WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)  *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE  *	POSSIBILITY OF SUCH DAMAGE.  */#include <libintl.h>#include <ctype.h>#include <string.h>#include <time.h>#include <glib.h>#include <gtk/gtk.h>#include <gdk/gdkkeysyms.h>#include <gtkautoscrolledwindow.h>#include "gemfilechooser.h"#include "gemresource.h"#include "gemenv.h"#include <gdk-pixbuf/gdk-pixbuf.h>#ifndef DBGING#define DBGING  1#define DBG(x...) do { if(DBGING) { \                                   g_print("%s(%d):", __FUNCTION__, __LINE__); \                                   g_print(x);    \                                   g_print("\n"); \                              } \                              }while(0)#endif#define _(x) gettext(x)static gchar *prefix =  PREFIX ;extern gchar *virtual_root =  VIRTUAL_ROOT;static gchar * gem_resource_path = NULL;static GHashTable *loaded_icons;static GnomeVFSMonitorHandle *dir_monitor = NULL;static gboolean refresh_scheduled = FALSE;static void free_a_hash_table_entry(gpointer key, gpointer value, gpointer user_data);static voidfree_a_hash_table_entry(gpointer key, gpointer value, gpointer user_data){  g_free(key);  gdk_pixbuf_unref((GdkPixbuf *)value);  return;}//gchar *sdcard_path =   SD_PATH;typedef	enum {	GEM_FC_COL_CHECK,	GEM_FC_COL_PIC,	GEM_FC_COL_NAME,	GEM_FC_COL_IS_FOLDER,	GEM_FC_COL_VFS_FILE_INFO,	GEM_FC_COL_CHECK_BOX,	GEM_FC_NUMS_COLS,} GemFileChooserCols;/* GObject, GtkObject methods */static void gem_file_chooser_class_init			(GemFileChooserClass	*klass);static void gem_file_chooser_init						(GemFileChooser				*window);static void	gem_file_chooser_dispose				(GObject							*object);static void	gem_file_chooser_finalize				(GObject							*object);static gchar *find_mime_icon(GnomeVFSFileInfo*,gchar *);static gchar *find_icon_path (gchar *);static GdkPixbuf *get_pixbuf (const gchar* );/* Default signal handlers */static void gem_file_chooser_file_selected	(GemFileChooser				*filechooser);static GemTreeView * parent_class = NULL;static gchar * find_mime_icon( GnomeVFSFileInfo * vfs_file_info , gchar *absolute_path){  gchar *mime_icon = NULL;  gchar *path= g_strdup(absolute_path);  if (vfs_file_info->type == GNOME_VFS_FILE_TYPE_DIRECTORY)  {       mime_icon = g_strdup_printf ("%s/%s/%s",gem_resource_path,"pixmaps", "folder.png");  }  else     if( vfs_file_info->type == GNOME_VFS_FILE_TYPE_REGULAR||vfs_file_info->type == GNOME_VFS_FILE_TYPE_UNKNOWN )    {        vfs_file_info->mime_type = gnome_vfs_get_mime_type (path);      if (vfs_file_info->mime_type)      {         mime_icon = find_icon_path (vfs_file_info->mime_type);      }      else      {          mime_icon = g_strdup_printf ("%s/%s/%s",gem_resource_path,"pximaps","file.png");      }     }  g_free(path);  return mime_icon;}static gchar *find_icon_path (gchar *mime_type){  struct stat s;  gchar *mime_icon;  gchar *mime_path, *p;  mime_icon = g_strdup(gnome_vfs_mime_get_icon(mime_type));  if (mime_icon)  {    if (mime_icon[0] == '/')    {      if (stat (mime_icon, &s) == 0)         return mime_icon;    }    mime_path = g_strdup_printf ("%s/%s/%s",gem_resource_path,"pixmaps",mime_icon);    g_free(mime_icon);        if (stat (mime_path, &s) == 0)      return mime_path;    g_free(mime_path);    mime_path = g_strdup_printf ("%s/%s/%s",gem_resource_path, "pixmaps",mime_icon);    if (stat (mime_path, &s) == 0)      return mime_path;  }  //not find in the mime database ,mime_icon should be mime_type  mime_icon = g_strdup (mime_type);     while ((p = strchr(mime_icon, '/')) != NULL)    *p = '-';  mime_path = g_strdup_printf ("%s/%s/gnome-%s.png",gem_resource_path,"pixmaps",mime_icon);  if (stat (mime_path, &s) == 0)  {    g_free(mime_icon);    return mime_path;  }    g_free(mime_path);  mime_path = g_strdup_printf ("%s/%s/gnome-%s.png",gem_resource_path , "pixmaps",mime_icon);  if (stat (mime_path, &s) == 0)  {    g_free(mime_icon);    return mime_path;  }  g_free(mime_icon);  g_free(mime_path);  return g_strdup_printf ("%s/%s/file.png",gem_resource_path,"pixmaps");}static GdkPixbuf *get_pixbuf (const gchar * filename){  GdkPixbuf *pixbuf=NULL;  pixbuf = g_hash_table_lookup (loaded_icons, (gconstpointer) filename);  if (pixbuf)  {    g_free((gchar *)filename);    return pixbuf;  }  else  {    pixbuf = gdk_pixbuf_new_from_file (filename, NULL);    g_hash_table_insert (loaded_icons, (gpointer) filename,  (gpointer) pixbuf);    return pixbuf;  }}enum {  FILE_SELECTED,  LAST_SIGNAL};static guint file_chooser_signals[LAST_SIGNAL];GTypegem_file_chooser_get_type (void){	static GType file_chooser_type = 0;  if (!file_chooser_type)	{		static const GTypeInfo file_chooser_info =		{			sizeof (GemFileChooserClass),			NULL,		/* base_init */			NULL,		/* base_finalize */			(GClassInitFunc) gem_file_chooser_class_init,			NULL,		/* class_finalize */			NULL,		/* class_data */			sizeof (GemFileChooser),			0,			/* n_preallocs */			(GInstanceInitFunc) gem_file_chooser_init,		};		file_chooser_type = g_type_register_static(GEM_TYPE_TREE_VIEW,																						  "GemFileChooser",																						  &file_chooser_info,																						  0);	}	return file_chooser_type;}static voidgem_file_chooser_class_init (GemFileChooserClass * klass){  GObjectClass	*object_class;  object_class = G_OBJECT_CLASS(klass);  parent_class = g_type_class_peek_parent(klass);  object_class->dispose		= gem_file_chooser_dispose;  object_class->finalize	= gem_file_chooser_finalize;	klass->file_selected = gem_file_chooser_file_selected;	/* Action signals */  file_chooser_signals[FILE_SELECTED] = 	g_signal_new("file_selected",							 G_OBJECT_CLASS_TYPE(klass),							 G_SIGNAL_RUN_LAST,							 G_STRUCT_OFFSET(GemFileChooserClass, file_selected),							 NULL, NULL,							 gtk_marshal_VOID__VOID,							 G_TYPE_NONE,							 0);	return;}static voidgem_file_chooser_dispose (GObject *object){ 	(*G_OBJECT_CLASS(parent_class)->dispose)(object); 	return;}static voidgem_file_chooser_finalize (GObject *object){	GemFileChooser * filechooser = GEM_FILE_CHOOSER(object);	g_print("%s(): entering\n", __FUNCTION__);	g_free(filechooser->current_path);  (*G_OBJECT_CLASS(parent_class)->finalize)(object);  g_hash_table_foreach(loaded_icons,free_a_hash_table_entry,NULL);  g_hash_table_destroy ( loaded_icons );  return;}static voidgem_file_chooser_file_info_print (GtkFileInfo		*info){	struct tm loacl_time;	time_t time;		if (info == NULL)	{		return;	}	time = (time_t)gtk_file_info_get_modification_time(info);	localtime_r(&time, &loacl_time);		g_print("%s():Info 0x%08x\n",					__FUNCTION__,					(guint32)info);	g_print("%s():|- Display Name  : %s\n",					__FUNCTION__,					gtk_file_info_get_display_name(info));	g_print("%s():|- Display Key   : %s\n",					__FUNCTION__,					gtk_file_info_get_display_key(info));	g_print("%s():|- Folder        : %s\n",					__FUNCTION__,					(gtk_file_info_get_is_folder(info) ? "TRUE" : "FALSE"));	g_print("%s():|- Hidden        : %s\n",					__FUNCTION__,					(gtk_file_info_get_is_hidden(info) ? "TRUE" : "FALSE"));	g_print("%s():|- MIME Type     : %s\n",					__FUNCTION__,					gtk_file_info_get_mime_type(info));	g_print("%s():|- Modified Time : %04d/%02d/%02d %02d:%02d:%02d\n",					__FUNCTION__,					loacl_time.tm_year + 1900,					loacl_time.tm_mon + 1,					loacl_time.tm_mday,					loacl_time.tm_hour,					loacl_time.tm_min,					loacl_time.tm_sec);	g_print("%s():`- Size          : %lld\n",					__FUNCTION__,					gtk_file_info_get_size(info));						g_print("\n");	return;}static gint gemgem_file_chooser_sort_func (GtkTreeModel 		*model,															 GtkTreeIter			*a,															 GtkTreeIter			*b,															 gpointer					 user_data){	gint ret = 0;	gchar * str1 = NULL;	gchar * str2 = NULL;	gboolean is_folder1 = FALSE;	gboolean is_folder2 = FALSE;		gtk_tree_model_get(model,										 a,										 GEM_FC_COL_NAME,										 &str1,										 GEM_FC_COL_IS_FOLDER,										 &is_folder1,										 -1);	gtk_tree_model_get(model,										 b,										 GEM_FC_COL_NAME,										 &str2,										 GEM_FC_COL_IS_FOLDER,										 &is_folder2,										 -1);		if (str1 == NULL && str2 == NULL)	{		ret = 0;	}	else if (str1 == NULL || str2 == NULL)	{		ret = (str1 == NULL) ? -1 : 1;	}	else	{    gboolean str1_is_sel_all=!strcmp(str1,"Select All");    gboolean str2_is_sel_all=!strcmp(str2,"Select All");    if(str1_is_sel_all&&str2_is_sel_all)      ret = 0;    if(str1_is_sel_all||str2_is_sel_all)    {      ret =  (str1_is_sel_all) ? -1 : 1;    }    if (is_folder1 != is_folder2)		{			ret = (is_folder1 > is_folder2) ? -1 : 1;		}		else		{			ret = g_utf8_collate(str1, str2);		}	}		g_free(str1);	g_free(str2);		return ret;}static voidgem_file_chooser_file_selected (GemFileChooser	*filechooser){	return;}static void mark_toggled_cb(GtkCellRendererToggle *celltoggle,gchar *pathstr,gpointer userdata){  GtkTreeIter iter;  GtkTreeModel *model = NULL;  gboolean active;  GtkTreePath *path = NULL;  GemFileChooser * filechooser = GEM_FILE_CHOOSER(userdata);    if(gem_file_chooser_get_selectable==FALSE)  {   DBG("_____________________________________________Error BUG");   return;  }  model = gem_tree_view_get_model(GEM_TREE_VIEW(GEM_FILE_CHOOSER(filechooser)));	path = gtk_tree_path_new_from_string (pathstr);    if (!gtk_tree_model_get_iter (model, &iter, path))	{	  g_print ("%s(): bad path %s\n", __FUNCTION__, pathstr);	  return;	}  if (model)  {        /*first check if select all has been choosen*/         gtk_tree_model_get ( GTK_TREE_MODEL (model),                         &iter,                         GEM_FC_COL_CHECK_BOX,                         &active,                         -1);    active = !active;    gtk_list_store_set ( GTK_LIST_STORE (model),&iter,                         GEM_FC_COL_CHECK_BOX, active,                          GEM_FC_COL_CHECK, active,                          -1);    gtk_cell_renderer_toggle_set_active((GtkCellRendererToggle *)celltoggle,active);    #if 1    {      GtkTreePath *root = NULL;      root = gtk_tree_path_new_first ();      if (!gtk_tree_path_compare (path, root))      {        if(active)          gem_file_chooser_select_all(filechooser);        else          gem_file_chooser_unselect_all(filechooser);      }       gtk_tree_path_free(root);    }      #endif                      }  return ;}#if 1static gem_file_chooser_tree_view_row_activated (GtkTreeView				 	*treeview,																					GtkTreePath					*path,																					GtkTreeViewColumn		*col,																					gpointer						 user_data){	GemFileChooser * filechooser = GEM_FILE_CHOOSER(user_data);	GtkTreeModel * model = NULL;	GtkTreeIter iter;  GnomeVFSFileInfo *vfs_file_info; /*= gnome_vfs_file_info_new ();*/  gboolean selectable=gem_file_chooser_get_selectable(filechooser);  if(selectable)    return;  model = gem_tree_view_get_model(GEM_TREE_VIEW(filechooser));		if (model && gtk_tree_model_get_iter(model,																			 &iter,																			 path))	{		//GtkFilePath * filepath = NULL;		GError * error = NULL;		gchar * name = NULL;		gboolean is_folder = FALSE;		gtk_tree_model_get(model,											 &iter,											 GEM_FC_COL_NAME,											 &name,											 GEM_FC_COL_IS_FOLDER,											 &is_folder,											 GEM_FC_COL_VFS_FILE_INFO,                       &vfs_file_info,											 -1);		g_print("%s(): %-20s [%s]\n",						__FUNCTION__,						name ? name : "null",						(is_folder ? "FOLER" : "FILE"));		if (name == NULL)			return;		if(name == "My Collections")      return;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -