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

📄 enabler.c

📁 linux手机上的phonebook代码
💻 C
字号:
/*	contact - LiPS Address Book Application * *	Authors: YE Nan <nan.ye@orange-ftgroup.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 <stdio.h>#include <stdlib.h>#include <string.h>#include <uuid/uuid.h>#include <gtk/gtk.h>#include <glib.h>#include <addressbook.h>#include <abcontact.h>#include <uicompcnteditview.h>#include <uicompcntlistview.h>#include "enabler.h"#include "threads.h"#define		ENABLER_SPEC_VER		1static ab_sid_t sessions[NUM_SESSIONS];static guint32	indexes[NUM_SESSIONS] = {	0,	/* Local Flash Address Book */	1,	/* SIM Card Address Book */	2,	/* Network Address Book */}; gbooleanab_enabler_initialize (void){	gint i;		for (i = 0; i < NUM_SESSIONS; i++)	{		ab_err_t error = AB_ERROR_NONE;				error = ab_open_session(indexes[i],														&sessions[i],														ENABLER_SPEC_VER);		if (error != AB_ERROR_NONE)		{			g_print("%s(): open session failure. index = %d, error = %d\n",							__FUNCTION__,							indexes[i],							error);			sessions[i] = AB_ID_INVALID;		}	}		return TRUE;}voidab_enabler_finalize (void){	gint i;		for (i = 0; i < NUM_SESSIONS; i++)	{		if (sessions[i] != AB_ID_INVALID)		{			ab_close_session(sessions[i]);		}	}		return;	}inline ab_sid_tab_enabler_get_session (ABSessionEnum sess){	return sessions[sess];}gbooleanab_enabler_ui_comp_cnt_list_view_find (UICompCntListView			*cntview,																			 ab_uid_t								 uidcomp,																			 GtkTreeIter						*iter){	GtkTreeModel * model = NULL;	model = gem_tree_view_get_model(GEM_TREE_VIEW(cntview));	if (model)	{		if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model),																			iter))		{			gboolean res = TRUE;			//			g_print("%s() entering\n", __FUNCTION__);			while (res)			{				ab_uid_t uid = AB_ID_INVALID;				gboolean compare_res = FALSE;								gtk_tree_model_get(GTK_TREE_MODEL(model),													 iter,													 UI_COMP_CNT_LV_UID,													 &uid,													 -1);													 				if (uidcomp == uid)				{					return TRUE;				}								res = gtk_tree_model_iter_next(GTK_TREE_MODEL(model),																			 iter);			}		}	}		return FALSE;}void ab_enabler_ui_comp_cnt_list_view_add (UICompCntListView			*cntview,																			const ab_contact_t		*contact){	return ab_enabler_ui_comp_cnt_list_view_update(cntview,																								 contact,																								 NULL);}voidab_enabler_ui_comp_cnt_list_view_update (UICompCntListView		*cntview,																				 const ab_contact_t		*contact,																				 GtkTreeIter					*iter){	GtkTreeModel * model = NULL;	model = gem_tree_view_get_model(GEM_TREE_VIEW(cntview));	if (model)	{		ab_uid_t uid = AB_ID_INVALID;		gchar * name = NULL;		GdkPixbuf * pixbuf = NULL;				ab_contact_get_uid(contact, &uid);		ab_contact_get_full_name(contact, &name);				if (TRUE)		{			gchar * picpath = NULL;						picpath = g_build_filename(gem_env_get_resource_path(),																 "pixmaps",																 "sample02.png",																 NULL);//			g_print("%s(): path = %s\n", __FUNCTION__, picpath);			gem_resource_load_pic(picpath,														GEM_PIC_NORMAL);			pixbuf = gem_resource_find_pic(picpath,																		 GEM_PIC_NORMAL);				g_free(picpath);		}		if (iter)		{			gtk_list_store_set(GTK_LIST_STORE(model), 												 iter,												 UI_COMP_CNT_LV_UID,												 uid,												 UI_COMP_CNT_LV_NAME,												 name,												 UI_COMP_CNT_LV_PIC,												 pixbuf,												 UI_COMP_CNT_LV_STORAGE,												 STORAGE_LOCAL,												 -1);		}		else		{			GtkTreeIter iter_new;						gtk_list_store_append(GTK_LIST_STORE(model),														&iter_new);			gtk_list_store_set(GTK_LIST_STORE(model),												 &iter_new,												 UI_COMP_CNT_LV_UID,												 uid,												 UI_COMP_CNT_LV_NAME,												 name,												 UI_COMP_CNT_LV_PIC,												 pixbuf,												 UI_COMP_CNT_LV_STORAGE,												 STORAGE_LOCAL,												 -1);		}				g_free(name);		//		g_object_unref(model);	}		return;}gpointerab_enabler_cnt_list_view_load_contacts_thread (gpointer arg){	ab_thread_t	*thread = (ab_thread_t *)arg;	UICompCntListView *cntview = UI_COMP_CNT_LIST_VIEW(thread->user_data);	GemNotification *notifier = GEM_NOTIFICATION(thread->notifier);	ab_contact_t **contacts = NULL;	gint i;	gint count;			ab_get_contacts(AB_ENABLER_SESS_LOCAL,									NULL,									&contacts);		g_print("%s(): contacts = 0x%08x\n",					__FUNCTION__,					contacts);	ab_thread_print(thread);	if (contacts)	{		for (i = 0, count = 0; contacts[i] != NULL; i++)		{			count++;					}				for (i = 0; contacts[i] != NULL; i++)		{/*			g_print("%s(): i = %d\n",							__FUNCTION__,							i);//			ab_contact_print(contacts[i]);*/ 			ab_enabler_ui_comp_cnt_list_view_add(cntview,  																				 contacts[i]);       if (i % 10 == 0)      {  			gdk_threads_enter();	      ui_comp_cnt_list_view_update(cntview);	        gdk_threads_leave();  	  	gem_notification_set_progross_fraction(notifier,	  																					 ((gdouble)i / count));      }		}	}		ab_free_contacts(AB_ENABLER_SESS_LOCAL,									 contacts);	return NULL;	}/*************************     qzh Jan 31    ****************************/ab_contact_t *ab_enabler_cnt_parse_from_edit_view (GemHashView *view){  ab_sid_t sid;  ab_contact_t *contact = NULL;  gint i;  sid = sessions[0];  ab_create_contact (sid, &contact);	for (i = 0; i < NUM_CNT_VIEW_ITEMS; i++)  {    const gchar *value = gem_hash_view_get_value (view,i);//              g_print("%s(): value = [%s]\n", __FUNCTION__, value ? value : "null");    if (value && strlen (value) > 0)    {//                      g_print("%s(): set value\n", __FUNCTION__);      ab_contact_set_string_field (contact, i + 2, (gconstpointer) value);    }#if 1    else    {      ab_contact_set_string_field (contact, i + 2, "");    }#endif  }	if (TRUE)  {    gchar *uidstr = NULL;    uidstr = (gchar *)gem_hash_view_get_value (view, AB_IV_UID);    if (uidstr)    {      ab_uid_t uid;			uuid_parse(uidstr,uid);			      ab_contact_set_string_field (contact, CNT_UID, uid);    }  }  ab_contact_print (contact);  return contact;}/*************************     qzh Jan 31    ****************************//*vi:ts=2:nowrap:ai:expandtab */

⌨️ 快捷键说明

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