[maemo-commits] [maemo-commits] r10326 - projects/haf/trunk/libosso/src
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Fri Mar 2 15:45:41 EET 2007
- Previous message: [maemo-commits] r10325 - projects/haf/trunk/gconf2/debian
- Next message: [maemo-commits] r10328 - projects/haf/trunk/libosso/src
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: schulhof Date: 2007-03-02 15:45:40 +0200 (Fri, 02 Mar 2007) New Revision: 10326 Added: projects/haf/trunk/libosso/src/osso-locale.c projects/haf/trunk/libosso/src/osso-locale.h Modified: projects/haf/trunk/libosso/src/Makefile.am projects/haf/trunk/libosso/src/Makefile.in projects/haf/trunk/libosso/src/libosso.h Log: Added locale set/change notification support. Modified: projects/haf/trunk/libosso/src/Makefile.am =================================================================== --- projects/haf/trunk/libosso/src/Makefile.am 2007-03-02 13:43:08 UTC (rev 10325) +++ projects/haf/trunk/libosso/src/Makefile.am 2007-03-02 13:45:40 UTC (rev 10326) @@ -36,6 +36,8 @@ osso-log.c \ osso-time.c \ osso-time.h \ + osso-locale.c \ + osso-locale.h \ osso-application-init.c \ osso-mem.h \ osso-mem.c \ Modified: projects/haf/trunk/libosso/src/Makefile.in =================================================================== --- projects/haf/trunk/libosso/src/Makefile.in 2007-03-02 13:43:08 UTC (rev 10325) +++ projects/haf/trunk/libosso/src/Makefile.in 2007-03-02 13:45:40 UTC (rev 10326) @@ -58,7 +58,7 @@ osso-application-top.lo osso-application-autosave.lo \ osso-hw.lo osso-mime.lo osso-system-note.lo osso-rpc.lo \ osso-statusbar.lo osso-cp-plugin.lo osso-log.lo osso-time.lo \ - osso-application-init.lo osso-mem.lo + osso-locale.lo osso-application-init.lo osso-mem.lo libosso_la_OBJECTS = $(am_libosso_la_OBJECTS) DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/depcomp @@ -68,6 +68,7 @@ @AMDEP_TRUE@ ./$(DEPDIR)/osso-application-top.Plo \ @AMDEP_TRUE@ ./$(DEPDIR)/osso-cp-plugin.Plo \ @AMDEP_TRUE@ ./$(DEPDIR)/osso-hw.Plo ./$(DEPDIR)/osso-init.Plo \ + at AMDEP_TRUE@ ./$(DEPDIR)/osso-locale.Plo \ @AMDEP_TRUE@ ./$(DEPDIR)/osso-log.Plo ./$(DEPDIR)/osso-mem.Plo \ @AMDEP_TRUE@ ./$(DEPDIR)/osso-mime.Plo ./$(DEPDIR)/osso-rpc.Plo \ @AMDEP_TRUE@ ./$(DEPDIR)/osso-state.Plo \ @@ -241,6 +242,8 @@ osso-log.c \ osso-time.c \ osso-time.h \ + osso-locale.c \ + osso-locale.h \ osso-application-init.c \ osso-mem.h \ osso-mem.c \ @@ -321,6 +324,7 @@ @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/osso-cp-plugin.Plo at am__quote@ @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/osso-hw.Plo at am__quote@ @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/osso-init.Plo at am__quote@ + at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/osso-locale.Plo at am__quote@ @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/osso-log.Plo at am__quote@ @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/osso-mem.Plo at am__quote@ @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/osso-mime.Plo at am__quote@ Modified: projects/haf/trunk/libosso/src/libosso.h =================================================================== --- projects/haf/trunk/libosso/src/libosso.h 2007-03-02 13:43:08 UTC (rev 10325) +++ projects/haf/trunk/libosso/src/libosso.h 2007-03-02 13:45:40 UTC (rev 10326) @@ -841,6 +841,68 @@ /* @}*/ /** + * \defgroup Locale Locale + */ +/* @{*/ + +/** + * This is the type for the locale change notification callback function. + * @param new_locale The new locale (e.g. "en_GB") + * @param data An application specific data pointer. + * + * <h2>Example</h2> + * This is an example implementation of the locale change callback + * function. It correctly passes the received locale value to gettext + * and updates the labels for all the text widgets in the application. + * @code +static void locale_changed_cb (char *new_locale, gpointer user_data) +{ + GtkWidget *my_label = GTK_WIDGET (user_data); + + g_setenv ("LANG", new_locale, TRUE); + setlocale (LC_ALL, ""); + setlocale (LC_MESSAGES, new_locale); + setlocale (LC_TIME, new_locale); + + // Here you re-set the text labels for all your widgets. In this example + // only one widget is passed into the callback via user_data. + + gtk_label_set_text (GTK_LABEL (my_label), _("Label Text")); + + // The label's text will now be rendered in the new language +} + * @endcode + */ +typedef void(osso_locale_change_cb_f)(char *new_locale, gpointer data); + +/** + * This function registers a callback that is called whenever the locale is + * changed. + * @param osso The library context as returned by #osso_initialize. + * @param cb Function that is called when the system locale is changed. + * @param data Arbitrary application-specific pointer that will be passed + * to the callback and ignored by Libosso. + * @return #OSSO_OK if all goes well, #OSSO_ERROR if an error occurred, or + * #OSSO_INVALID if some parameter is invalid. + */ +osso_return_t osso_locale_change_set_notification_cb(osso_context_t *osso, + osso_locale_change_cb_f *cb, + gpointer data); + +/** + * This function issues a notification over the D-Bus system bus indicating + * a change of locale. To receive such a notification, install a callback + * function with #osso_locale_change_set_notification_cb. + * + * @param osso The library context as returned by #osso_initialize. + * @param new_locale The new locale (e.g. "en_GB"). Must not be NULL. + * @return #OSSO_OK if all goes well, #OSSO_ERROR if an error occurred, or + * #OSSO_INVALID if new_locale is NULL or the osso context is invalid. + */ +osso_return_t osso_locale_set(osso_context_t *osso, char *new_locale); + +/* @}*/ +/** * \defgroup Sysnotes System notification */ /* @{*/ Added: projects/haf/trunk/libosso/src/osso-locale.c =================================================================== --- projects/haf/trunk/libosso/src/osso-locale.c 2007-03-02 13:43:08 UTC (rev 10325) +++ projects/haf/trunk/libosso/src/osso-locale.c 2007-03-02 13:45:40 UTC (rev 10326) @@ -0,0 +1,142 @@ +/** + * @file osso-locale.c + * This file implements notifications about locale modifications + * + * This file is part of libosso + * + * Copyright (C) 2005 Nokia Corporation. All rights reserved. + * + * Contact: Kimmo Hämäläinen <kimmo.hamalainen at nokia.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include <osso-locale.h> + +#define MATCH_RULE \ + "type='signal',interface='com.nokia.LocaleChangeNotification',"\ + "member='locale_changed'" + +static void _locale_change_handler(osso_context_t *osso, + DBusMessage *msg, + _osso_callback_data_t *ot, + muali_bus_type dbus_type); + + +/************************************************************************/ +osso_return_t osso_locale_change_set_notification_cb(osso_context_t *osso, + osso_locale_change_cb_f *cb, + gpointer data) +{ + _osso_callback_data_t *ot; + DBusError error; + + if (osso == NULL || cb == NULL) { + ULOG_ERR_F("invalid arguments"); + return OSSO_INVALID; + } + if (osso->sys_conn == NULL) { + ULOG_ERR_F("no D-Bus system bus connection"); + return OSSO_INVALID; + } + + ot = calloc(1, sizeof(_osso_callback_data_t)); + if (ot == NULL) { + ULOG_ERR_F("calloc failed"); + return OSSO_ERROR; + } + + dbus_error_init(&error); + dbus_bus_add_match(osso->sys_conn, MATCH_RULE, &error); + if (dbus_error_is_set(&error)) { + ULOG_ERR_F("dbus_bus_add_match() failed: %s", error.message); + dbus_error_free(&error); + return OSSO_ERROR; + } + + ot->user_cb = cb; + ot->user_data = data; + ot->data = LOCALE_CHANGED_SIG_NAME; + + _msg_handler_set_cb_f_free_data(osso, + NULL, + LOCALE_CHANGED_PATH, + LOCALE_CHANGED_INTERFACE, + _locale_change_handler, ot, FALSE); + return OSSO_OK; +} + +/************************************************************************/ +osso_return_t osso_locale_set(osso_context_t *osso, char *new_locale) +{ + DBusMessage* m = NULL; + dbus_bool_t ret = FALSE; + + if (NULL == new_locale || osso == NULL + || osso->sys_conn == NULL) { + ULOG_ERR_F("invalid arguments"); + return OSSO_INVALID; + } + + /* send a signal about the locale change */ + m = dbus_message_new_signal(LOCALE_CHANGED_PATH, LOCALE_CHANGED_INTERFACE, LOCALE_CHANGED_SIG_NAME); + if (m == NULL) { + ULOG_ERR_F("dbus_message_new_signal failed"); + return OSSO_ERROR; + } + + ret = dbus_message_append_args(m, DBUS_TYPE_STRING, &new_locale, + DBUS_TYPE_INVALID); + if (!ret) { + ULOG_ERR_F("couldn't append argument"); + dbus_message_unref(m); + return OSSO_ERROR; + } + + ret = dbus_connection_send(osso->sys_conn, m, NULL); + if (!ret) { + ULOG_ERR_F("dbus_connection_send failed"); + dbus_message_unref(m); + return OSSO_ERROR; + } + dbus_message_unref(m); + + return OSSO_OK; +} + +/************************************************************************/ +static void _locale_change_handler(osso_context_t *osso, + DBusMessage *msg, + _osso_callback_data_t *ot, + muali_bus_type dbus_type) +{ + if (dbus_message_is_signal(msg, LOCALE_CHANGED_INTERFACE, (char*)ot->data)) { + osso_locale_change_cb_f *handler = ot->user_cb; + char *new_locale = NULL ; + DBusMessageIter iter ; + + if(!dbus_message_iter_init(msg, &iter)) { + ULOG_ERR_F("Message has no arguments"); + return; + } + if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING) { + dbus_message_iter_get_basic(&iter, &new_locale); + } + + ULOG_DEBUG_F("arguments = '%s'", NULL == new_locale ? "<NULL>" : new_locale); + + (*handler)(new_locale, ot->user_data); + } +} Added: projects/haf/trunk/libosso/src/osso-locale.h =================================================================== --- projects/haf/trunk/libosso/src/osso-locale.h 2007-03-02 13:43:08 UTC (rev 10325) +++ projects/haf/trunk/libosso/src/osso-locale.h 2007-03-02 13:45:40 UTC (rev 10326) @@ -0,0 +1,37 @@ +/** + * @file osso-locale.h + * This file includes the definitions needed by osso-locale + * + * This file is part of libosso + * + * Copyright (C) 2005 Nokia Corporation. All rights reserved. + * + * Contact: Kimmo Hämäläinen <kimmo.hamalainen at nokia.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef OSSO_LOCALE_H +#define OSSO_LOCALE_H + +#include <libosso.h> +#include "osso-internal.h" +#include "osso-log.h" + +#define LOCALE_CHANGED_INTERFACE "com.nokia.LocaleChangeNotification" +#define LOCALE_CHANGED_PATH "/" +#define LOCALE_CHANGED_SIG_NAME "locale_changed" + +#endif
- Previous message: [maemo-commits] r10325 - projects/haf/trunk/gconf2/debian
- Next message: [maemo-commits] r10328 - projects/haf/trunk/libosso/src
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]