📄 abookcategoryview.c
字号:
/* addressbook - Address book *abookcategoryview.c - * *Authors: YE Nan <nan.ye@orange-ftgroup.com> * ZHAO Liangjing <liangjing.zhao@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 <libintl.h>#include <gtk/gtk.h>#include <gdk/gdkkeysyms.h>#include "abookcategoryview.h"#include "abookenv.h"#include "abookpicture.h"#define _(x) gettext(x)static void abook_category_view_class_init (ABookCategoryViewClass *klass);static void abook_category_view_init (ABookCategoryView *view);static void abook_category_view_destroy (GtkObject *object);static GtkAutoScrolledWindowClass *parent_class = NULL;GTypeabook_category_view_get_type (void){ static GType view_type = 0; if (!view_type) { static const GTypeInfo view_info = { sizeof (ABookCategoryViewClass), NULL, /* base_init */ NULL, /* base_finalize */ (GClassInitFunc) abook_category_view_class_init, NULL, /* class_finalize */ NULL, /* class_data */ sizeof (ABookCategoryView), 0, /* n_preallocs */ (GInstanceInitFunc) abook_category_view_init, NULL, }; view_type = g_type_register_static (GTK_TYPE_AUTO_SCROLLED_WINDOW, "ABookCategoryView", &view_info, 0); } return view_type;}static voidabook_category_view_class_init (ABookCategoryViewClass *klass){ GtkObjectClass *object_class; object_class = (GtkObjectClass *) klass; parent_class = g_type_class_peek_parent (klass); object_class->destroy = abook_category_view_destroy; return;}static voidabook_category_view_destroy (GtkObject *object){ ABookCategoryView *view = ABOOK_CATEGORY_VIEW (object); if (view->uuid) { g_free (view->uuid); view->uuid = NULL; } (*GTK_OBJECT_CLASS (parent_class)->destroy) (object); return;}static gbooleanentry_focus_in_cb (GtkWidget *widget, GdkEventFocus *event, ABookCategoryView *view){ gtk_entry_set_has_frame (GTK_ENTRY (widget), TRUE); gtk_editable_select_region (GTK_EDITABLE (widget), 0, 0); gtk_editable_set_position (GTK_EDITABLE (widget), -1); return FALSE;}static gbooleanentry_focus_out_cb (GtkWidget *widget, GdkEventFocus *event, ABookCategoryView *view){ gtk_entry_set_has_frame (GTK_ENTRY (widget), FALSE); gtk_editable_select_region (GTK_EDITABLE (widget), 0, 0); if (widget == view->entries[CAT_VIEW_PICTURE]) { GdkPixbuf *pixbuf = NULL; gchar *picpath = NULL; picpath = g_build_filename (abook_env_get_picpath (), gtk_entry_get_text (GTK_ENTRY (widget)), NULL); g_print ("%s(): path = %s\n", __FUNCTION__, picpath); abook_pictures_load (picpath, PIC_LARGE); pixbuf = abook_pictures_find (picpath, PIC_LARGE); gtk_image_set_from_pixbuf (GTK_IMAGE (view->image), pixbuf);// g_object_unref(pixbuf); g_free (picpath); } return FALSE;}static voidabook_category_view_show_cb (GtkWidget *widget, gpointer user_data){ ABookCategoryView *view = ABOOK_CATEGORY_VIEW (widget);/* if (view->editable && view->entries[CAT_VIEW_PICTURE]) { gtk_widget_grab_focus(view->entries[CAT_VIEW_PICTURE]); } else if (view->labels[CAT_VIEW_NAME]) { gtk_widget_grab_focus(view->labels[CAT_VIEW_NAME]); }*/ if (view->editable) { gtk_widget_grab_focus (view->entries[view->focused_item]); } else { gtk_widget_grab_focus (view->labels[view->focused_item]); } return;}static voidabook_category_view_hide_cb (GtkWidget *widget, gpointer user_data){ ABookCategoryView *view = ABOOK_CATEGORY_VIEW (widget); gint i; g_print ("%s(): entering\n", __FUNCTION__); for (i = 0; i < NUM_CAT_VIEW_ITEMS; i++) { gtk_entry_set_text (GTK_ENTRY (view->entries[i]), ""); } gtk_image_set_from_file (GTK_IMAGE (view->image), NULL); abook_category_view_set_uid (view, NULL); return;}static voidabook_category_view_init (ABookCategoryView *view){ gint i; GtkWidget *vbox = NULL; vbox = gtk_vbox_new (FALSE, 0); for (i = 0; i < NUM_CAT_VIEW_ITEMS; i++) { view->entries[i] = gtk_entry_new ();#if 1 gtk_widget_set_size_request (view->entries[i], 100, -1); gtk_entry_set_has_frame (GTK_ENTRY (view->entries[i]), FALSE); g_signal_connect (G_OBJECT (view->entries[i]), "focus-in-event", G_CALLBACK (entry_focus_in_cb), (gpointer) view); g_signal_connect (G_OBJECT (view->entries[i]), "focus-out-event", G_CALLBACK (entry_focus_out_cb), (gpointer) view);#endif } for (i = CAT_VIEW_NAME; i < NUM_CAT_VIEW_ITEMS; i++) { view->labels[i] = gtk_label_new (NULL);// GTK_WIDGET_SET_FLAGS(buddy_labels[i], GTK_CAN_FOCUS); } gtk_label_set_markup (GTK_LABEL (view->labels[CAT_VIEW_NAME]), "<span color=\"Blue\">Name</span>"); gtk_label_set_markup (GTK_LABEL (view->labels[CAT_VIEW_PICTURE]), "<span color=\"Blue\">Picure</span>"); gtk_label_set_markup (GTK_LABEL (view->labels[CAT_VIEW_RINGTONE]), "<span color=\"Blue\">Ringtone</span>"); view->image = gtk_image_new (); gtk_widget_set_size_request (view->image, 64, 64); if (TRUE) { GtkWidget *grpbox = NULL; GtkWidget *sep = NULL; grpbox = gtk_hbox_new (FALSE, 0); gtk_widget_set_size_request (grpbox, -1, 70); if (TRUE) { GtkWidget *subbox = NULL; gtk_widget_set_size_request (view->labels[CAT_VIEW_NAME], -1, 40); gtk_misc_set_alignment (GTK_MISC (view->labels[CAT_VIEW_NAME]), 0, 0); subbox = gtk_vbox_new (FALSE, 0); gtk_box_pack_start (GTK_BOX (subbox), view->labels[CAT_VIEW_NAME], FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (subbox), view->entries[CAT_VIEW_NAME], FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (grpbox), subbox, FALSE, FALSE, 20); } gtk_box_pack_end (GTK_BOX (grpbox), view->image, FALSE, FALSE, 5); gtk_box_pack_start (GTK_BOX (vbox), grpbox, FALSE, FALSE, 10); sep = gtk_hseparator_new (); gtk_box_pack_start (GTK_BOX (vbox), sep, 0, TRUE, 0); } for (i = CAT_VIEW_PICTURE; i < NUM_CAT_VIEW_ITEMS; i++) { GtkWidget *grpbox = NULL; grpbox = gtk_vbox_new (FALSE, 5); gtk_widget_set_size_request (grpbox, -1, 60); gtk_misc_set_alignment (GTK_MISC (view->labels[i]), 0, 0); gtk_box_pack_start (GTK_BOX (grpbox), view->labels[i], FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (grpbox), view->entries[i], FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), grpbox, FALSE, FALSE, 10); } gtk_auto_scrolled_window_add_with_viewport (GTK_AUTO_SCROLLED_WINDOW (view), vbox); if (TRUE) { GtkWidget *viewport = NULL; GdkColor white_bg = { 0, 0xFFFF, 0xFFFF, 0xFFFF }; viewport = gtk_auto_scrolled_window_get_viewport (GTK_AUTO_SCROLLED_WINDOW (view)); if (viewport) { gtk_widget_modify_bg (GTK_WIDGET (viewport), GTK_STATE_NORMAL, &white_bg); } } g_signal_connect (G_OBJECT (view), "show", G_CALLBACK (abook_category_view_show_cb), NULL); g_signal_connect (G_OBJECT (view), "hide", G_CALLBACK (abook_category_view_hide_cb), NULL); view->uuid = NULL; view->editable = TRUE; view->status = FALSE; return;}GtkWidget *abook_category_view_new (void){ return gtk_widget_new (ABOOK_TYPE_CATEGORY_VIEW, NULL);}G_CONST_RETURN gchar *abook_category_view_get_item_value (const ABookCategoryView *view, ABookCategoryViewItems item){ GtkWidget *entry = view->entries[item]; return gtk_entry_get_text (GTK_ENTRY (entry));}voidabook_category_view_set_item_value (ABookCategoryView *view, ABookCategoryViewItems item, const gchar *value){ GtkWidget *entry = view->entries[item]; if (value == NULL) { return; } gtk_entry_set_text (GTK_ENTRY (entry), value); if (item == CAT_VIEW_PICTURE) { GdkPixbuf *pixbuf = NULL; gchar *picpath = NULL; picpath = g_build_filename (abook_env_get_picpath (), value, NULL); g_print ("%s(): path = %s\n", __FUNCTION__, picpath); abook_pictures_load (picpath, PIC_LARGE); pixbuf = abook_pictures_find (picpath, PIC_LARGE); gtk_image_set_from_pixbuf (GTK_IMAGE (view->image), pixbuf);// g_object_unref(pixbuf); g_free (picpath); } return;}voidabook_category_view_set_uid (ABookCategoryView *view, const gchar *uidstr){ if (view->uuid) { g_free (view->uuid); view->uuid = NULL; } if (uidstr) { view->uuid = g_strdup (uidstr); } return;}G_CONST_RETURN gchar *abook_category_view_get_uid (ABookCategoryView *view){ return view->uuid;}voidabook_category_view_set_editable (ABookCategoryView *view, gboolean editable){ gint i; if (view->editable == editable) { return; } view->editable = editable; if (editable) { for (i = 0; i < NUM_CAT_VIEW_ITEMS; i++) { GTK_WIDGET_UNSET_FLAGS (view->labels[i], GTK_CAN_FOCUS); GTK_WIDGET_SET_FLAGS (view->entries[i], GTK_CAN_FOCUS); gtk_editable_set_editable (GTK_EDITABLE (view->entries[i]), editable); } } else { for (i = 0; i < NUM_CAT_VIEW_ITEMS; i++) { GTK_WIDGET_SET_FLAGS (view->labels[i], GTK_CAN_FOCUS); GTK_WIDGET_UNSET_FLAGS (view->entries[i], GTK_CAN_FOCUS); gtk_editable_set_editable (GTK_EDITABLE (view->entries[i]), editable); } } return;}gbooleanabook_category_view_get_editable (ABookCategoryView *view){ return view->editable;}voidabook_category_view_set_focus_item (ABookCategoryView *view, ABookCategoryViewItems item){ view->focused_item = item; return;}/* vi:ts=2:nowrap:ai:expandtab*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -