From: Roman Moravcik Date: Fri, 15 Oct 2010 10:26:31 +0000 (+0200) Subject: Added portrait mode support. X-Git-Tag: v0.2-1~5 X-Git-Url: http://vcs.maemo.org/git/?p=birthday;a=commitdiff_plain;h=71ad08280ca7f9f8111914fa50fe7a9cff4053fc Added portrait mode support. --- diff --git a/src/birthday.c b/src/birthday.c index bca95a7..36a4797 100644 --- a/src/birthday.c +++ b/src/birthday.c @@ -38,6 +38,11 @@ #include #include +#include +#include + +#define MCE_MATCH_RULE "type='signal',interface='" MCE_SIGNAL_IF "',member='" MCE_DEVICE_ORIENTATION_SIG "'" + #define _HL(str) dgettext("hildon-libs",str) enum @@ -57,6 +62,8 @@ struct _BirthdayData { GtkWidget *view; GtkWidget *search; + GtkTreeViewColumn *display_column; + GtkWidget *tree_view; GtkTreeModel *sorted; GtkTreeModel *filter; @@ -67,6 +74,54 @@ struct _BirthdayData { guint n_contacts; }; +static void set_portrait_mode (BirthdayData *priv, gboolean enable); + +static gboolean +is_portrait_mode (osso_context_t *osso_context) +{ + osso_rpc_t ret; + gboolean result = FALSE; + + if (osso_rpc_run_system (osso_context, MCE_SERVICE, MCE_REQUEST_PATH, + MCE_REQUEST_IF, MCE_DEVICE_ORIENTATION_GET, + &ret, DBUS_TYPE_INVALID) == OSSO_OK) { + + if (strcmp (ret.value.s, MCE_ORIENTATION_PORTRAIT) == 0) { + result = TRUE; + } + osso_rpc_free_val (&ret); + } else { + g_critical ("ERROR: Call do DBus failed\n"); + } + return result; +} + +static DBusHandlerResult +dbus_handle_mce_message (DBusConnection *connection, + DBusMessage *message, + gpointer data) +{ + DBusMessageIter iter; + const gchar *orientation = NULL; + BirthdayData *priv; + + g_return_val_if_fail (data, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); + priv = (BirthdayData *) data; + + if (dbus_message_is_signal (message, MCE_SIGNAL_IF, MCE_DEVICE_ORIENTATION_SIG)) { + if (dbus_message_iter_init (message, &iter)) { + dbus_message_iter_get_basic(&iter, &orientation); + if (orientation) { + if (!strcmp (orientation, MCE_ORIENTATION_PORTRAIT)) + set_portrait_mode (priv, TRUE); + else + set_portrait_mode (priv, FALSE); + } + } + } + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; +} + static gboolean birthday_filered_view_visible_func (GtkTreeModel *model, GtkTreeIter *iter, @@ -347,6 +402,23 @@ get_text_color_by_name (const gchar *name) return gdk_color_to_string (&color); } +static void +set_portrait_mode (BirthdayData *priv, + gboolean enable) +{ + g_return_if_fail (priv); + + if (enable) { + gtk_tree_view_column_set_fixed_width (priv->display_column, 389); + hildon_gtk_window_set_portrait_flags (GTK_WINDOW (priv->window), + HILDON_PORTRAIT_MODE_REQUEST); + } else { + gtk_tree_view_column_set_fixed_width (priv->display_column, 709); + hildon_gtk_window_set_portrait_flags (GTK_WINDOW (priv->window), + ~HILDON_PORTRAIT_MODE_REQUEST); + } +} + static GtkListStore * create_bday_liststore (BirthdayData *priv, GList *contacts) { @@ -641,8 +713,8 @@ create_main_window (BirthdayData *priv, GtkListStore *store) "markup", COLUMN_DISPLAY, NULL); g_object_set (G_OBJECT (renderer), "xpad", 10, NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (priv->tree_view), column); + priv->display_column = column; /* avatar column */ column = gtk_tree_view_column_new (); @@ -673,6 +745,10 @@ create_main_window (BirthdayData *priv, GtkListStore *store) gtk_widget_show (GTK_WIDGET (priv->label)); gtk_widget_hide (GTK_WIDGET (priv->view)); } + + /* enable portrait mode support */ + hildon_gtk_window_set_portrait_flags (GTK_WINDOW (priv->window), + HILDON_PORTRAIT_MODE_SUPPORT); } static GList * @@ -748,6 +824,17 @@ int main (int argc, char **argv) /* create main widow */ create_main_window (data, store); + /* get the system dbus connection */ + DBusConnection *dbus_connection = osso_get_sys_dbus_connection (osso_context); + + /* add the callback, which should be called, once the device is rotated */ + dbus_bus_add_match (dbus_connection, MCE_MATCH_RULE, NULL); + dbus_connection_add_filter (dbus_connection, dbus_handle_mce_message, data, NULL); + + /* check if device is not already in portrait orientation */ + if (is_portrait_mode (osso_context)) + set_portrait_mode (data, TRUE); + gtk_main (); exit: