#include <libebook/e-book.h>
#include <libosso-abook/osso-abook.h>
+#include <mce/dbus-names.h>
+#include <mce/mode-names.h>
+
+#define MCE_MATCH_RULE "type='signal',interface='" MCE_SIGNAL_IF "',member='" MCE_DEVICE_ORIENTATION_SIG "'"
+
#define _HL(str) dgettext("hildon-libs",str)
enum
COLUMN_DISPLAY,
COLUMN_FULLNAME,
COLUMN_NEXT_BIRTHDAY,
+ COLUMN_ABOOK_CONTACT,
NUM_COLS
};
GtkWidget *view;
GtkWidget *search;
+ GtkTreeViewColumn *display_column;
+
GtkWidget *tree_view;
GtkTreeModel *sorted;
GtkTreeModel *filter;
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,
return TRUE;
}
- ascii_searched_name = g_ascii_strdown (priv->searched_name, strlen (priv->searched_name));
+ ascii_searched_name = g_utf8_strdown (priv->searched_name, strlen (priv->searched_name));
gtk_tree_model_get (model, iter, COLUMN_FULLNAME, &fullname, -1);
if (fullname) {
- ascii_fullname = g_ascii_strdown (fullname, strlen (fullname));
+ ascii_fullname = g_utf8_strdown (fullname, strlen (fullname));
g_free (fullname);
}
on_search_entry_changed (GtkEditable *editable,
gpointer data)
{
+ GtkTreeSelection *selection;
BirthdayData *priv;
g_return_if_fail (data);
g_free (priv->searched_name);
priv->searched_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (editable)));
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view));
+
+ /* ugly hack, set back mode to selection none to not generate "changed"
+ signal during re-filtering */
+ gtk_tree_selection_set_mode (selection, GTK_SELECTION_NONE);
+
/* refilter tree view */
gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter));
/* ugly, but working way how to scroll to the first row */
gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->tree_view),
gtk_tree_path_new_from_string ("0"), NULL, FALSE, 0, 0);
+
+ /* ugly hack, set back mode to single selection */
+ gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
+
+ /* unselect selected rows */
+ gtk_tree_selection_unselect_all (selection);
}
static void
on_search_close_clicked (GtkButton *button,
gpointer data)
{
+ GtkTreeSelection *selection;
BirthdayData *priv;
g_return_if_fail (data);
priv = (BirthdayData *) data;
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view));
+
+ /* ugly hack, set back mode to selection none to not generate "changed"
+ signal during re-filtering */
+ gtk_tree_selection_set_mode (selection, GTK_SELECTION_NONE);
+
/* hide search bar */
gtk_widget_hide (priv->search);
/* ugly, but working way how to scroll to the first row */
gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->tree_view),
gtk_tree_path_new_from_string ("0"), NULL, FALSE, 0, 0);
+
+ /* ugly hack, set back mode to single selection */
+ gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
+
+ /* unselect selected rows */
+ gtk_tree_selection_unselect_all (selection);
}
return FALSE;
}
+static void
+on_selection_changed (GtkTreeSelection *selection,
+ gpointer data)
+{
+ BirthdayData *priv;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ GtkWidget *entry;
+
+ g_return_if_fail (data);
+ priv = (BirthdayData *) data;
+
+ if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
+ OssoABookContact *abook_contact = NULL;
+
+ /* unselect selected rows */
+ gtk_tree_selection_unselect_all (selection);
+
+ gtk_tree_model_get (model, &iter, COLUMN_ABOOK_CONTACT, &abook_contact, -1);
+
+ if (abook_contact) {
+ GtkWidget *starter, *dialog;
+ OssoABookContactDetailStore *store;
+ OssoABookContactAction actions[9] = {OSSO_ABOOK_CONTACT_ACTION_TEL,
+ OSSO_ABOOK_CONTACT_ACTION_SMS,
+ OSSO_ABOOK_CONTACT_ACTION_CHATTO,
+ OSSO_ABOOK_CONTACT_ACTION_VOIPTO,
+ OSSO_ABOOK_CONTACT_ACTION_VOIPTO_AUDIO,
+ OSSO_ABOOK_CONTACT_ACTION_VOIPTO_VIDEO,
+ OSSO_ABOOK_CONTACT_ACTION_MAILTO,
+ OSSO_ABOOK_CONTACT_ACTION_CREATE_ACCOUNT,
+ OSSO_ABOOK_CONTACT_ACTION_BIND};
+
+ store = osso_abook_contact_detail_store_new (abook_contact,
+ OSSO_ABOOK_CONTACT_DETAIL_EMAIL |
+ OSSO_ABOOK_CONTACT_DETAIL_PHONE |
+ OSSO_ABOOK_CONTACT_DETAIL_IM_VOICE |
+ OSSO_ABOOK_CONTACT_DETAIL_IM_VIDEO |
+ OSSO_ABOOK_CONTACT_DETAIL_IM_CHAT |
+ OSSO_ABOOK_CONTACT_DETAIL_OTHERS |
+ OSSO_ABOOK_CONTACT_DETAIL_SMS);
+
+ starter = osso_abook_touch_contact_starter_new_with_store (store,
+ (OssoABookContactAction *) &actions,
+ sizeof (actions));
+
+ dialog = osso_abook_touch_contact_starter_dialog_new (GTK_WINDOW (priv->window),
+ OSSO_ABOOK_TOUCH_CONTACT_STARTER (starter));
+ gtk_widget_show_all (dialog);
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ }
+ }
+
+ /* grab focus to search entry */
+ entry = g_object_get_data (G_OBJECT (priv->search), "entry");
+ gtk_widget_grab_focus (GTK_WIDGET (entry));
+
+}
+
static unsigned int
-calc_age (EContactDate *bdate)
+calc_age (EContactDate *bdate, time_t current_date)
{
+ struct tm *current_date_tm;
struct tm bday_tm;
- struct tm *age_tm;
- time_t t_age;
int age = 0;
+ current_date_tm = gmtime (¤t_date);
+
bday_tm.tm_sec = 0;
bday_tm.tm_min = 0;
bday_tm.tm_hour = 0;
bday_tm.tm_mday = bdate->day;
bday_tm.tm_mon = bdate->month - 1;
- bday_tm.tm_year = bdate->year - 1900;
+ bday_tm.tm_year = current_date_tm->tm_year;
+ bday_tm.tm_isdst = current_date_tm->tm_isdst;
- t_age = time (NULL) - mktime (&bday_tm);
- age_tm = gmtime (&t_age);
- age = age_tm->tm_year - 70;
+ if (mktime (&bday_tm) > current_date) {
+ age = (current_date_tm->tm_year + 1900) - bdate->year - 1;
+ } else {
+ age = (current_date_tm->tm_year + 1900) - bdate->year;
+ }
if (age < 0)
age = 0;
}
static unsigned int
-calc_next_bday (EContactDate *bdate)
+calc_next_bday (EContactDate *bdate, time_t current_date)
{
struct tm current_bday_tm, next_bday_tm;
struct tm *current_date_tm;
- time_t t_current_date, t_current_bday, t_next_bday;
+ time_t current_bday, next_bday;
- t_current_date = time (NULL);
- current_date_tm = localtime (&t_current_date);
+ current_date_tm = gmtime (¤t_date);
current_bday_tm.tm_sec = 0;
current_bday_tm.tm_min = 0;
current_bday_tm.tm_mday = bdate->day;
current_bday_tm.tm_mon = bdate->month - 1;
current_bday_tm.tm_year = current_date_tm->tm_year;
- t_current_bday = mktime (¤t_bday_tm);
+ current_bday_tm.tm_isdst = current_date_tm->tm_isdst;
+ current_bday = mktime (¤t_bday_tm);
- if (t_current_date > t_current_bday) {
+ if (current_date > current_bday) {
next_bday_tm.tm_sec = 0;
next_bday_tm.tm_min = 0;
next_bday_tm.tm_hour = 0;
next_bday_tm.tm_mday = bdate->day;
next_bday_tm.tm_mon = bdate->month - 1;
next_bday_tm.tm_year = current_date_tm->tm_year + 1;
- t_next_bday = mktime (&next_bday_tm);
+ next_bday_tm.tm_isdst = current_date_tm->tm_isdst;
+ next_bday = mktime (&next_bday_tm);
} else {
- t_next_bday = t_current_bday;
+ next_bday = current_bday;
}
- return (t_next_bday - t_current_date) / 86400;
+ return (next_bday - current_date) / 86400;
}
static gchar *
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)
{
gchar *text_font = NULL;
gchar *text_color = NULL;
guint n_contacts = 0;
+ time_t current_date;
+ struct tm *current_date_tm;
g_return_val_if_fail (priv, NULL);
text_font = get_text_font_by_name ("SmallSystemFont");
text_color = get_text_color_by_name ("SecondaryTextColor");
+ current_date = time (NULL);
+
+ /* set hour, minute, second to 0 */
+ current_date_tm = gmtime (¤t_date);
+ current_date_tm->tm_sec = 0;
+ current_date_tm->tm_min = 0;
+ current_date_tm->tm_hour = 0;
+ current_date = mktime (current_date_tm);
+
store = gtk_list_store_new(NUM_COLS,
GDK_TYPE_PIXBUF, /* COLUMN_AVATAR */
G_TYPE_STRING, /* COLUMN_DISPLAY */
G_TYPE_STRING, /* COLUMN_FULLNAME */
- G_TYPE_INT); /* COLUMN_NEXT_BIRTHDAY */
+ G_TYPE_INT, /* COLUMN_NEXT_BIRTHDAY */
+ G_TYPE_POINTER); /* COLUMN_ABOOK_CONTACT */
for (contact = contacts; contact != NULL; contact = contact->next) {
+
EContactDate *bdate = NULL;
bdate = e_contact_get (E_CONTACT (contact->data), E_CONTACT_BIRTH_DATE);
if (bdate) {
- EContactPhoto *photo = NULL;
GError *error = NULL;
GdkPixbuf *avatar = NULL;
- gchar *fullname = NULL;
+ const gchar *fullname = NULL;
guint age = 0, next_birthday = 0;
gchar *display_column = NULL;
gchar *next_birthday_text = NULL;
struct tm birthday_tm;
gchar birthday_text[11];
- photo = e_contact_get (E_CONTACT (contact->data), E_CONTACT_PHOTO);
- if (photo) {
- if (photo->type == E_CONTACT_PHOTO_TYPE_INLINED) {
- GdkPixbufLoader *loader;
-
- loader = gdk_pixbuf_loader_new ();
- if (gdk_pixbuf_loader_write (loader, (guchar *) photo->data.inlined.data, photo->data.inlined.length, NULL))
- avatar = gdk_pixbuf_loader_get_pixbuf (loader);
-
- } else {
- gchar *avatar_filename = NULL;
-
- avatar_filename = g_filename_from_uri (photo->data.uri, NULL, NULL);
- if (avatar_filename) {
- avatar = gdk_pixbuf_new_from_file (avatar_filename, &error);
- g_free (avatar_filename);
- }
- }
-
- if (avatar) {
- gint height = gdk_pixbuf_get_height (avatar);
- if (height != 48) {
- gint new_height = 48;
- gint new_width = new_height * gdk_pixbuf_get_width (avatar) / height;
- avatar = gdk_pixbuf_scale_simple (avatar, new_width, new_height, GDK_INTERP_BILINEAR);
- }
- }
- e_contact_photo_free (photo);
- photo = NULL;
- } else {
+ avatar = osso_abook_avatar_get_image_rounded (OSSO_ABOOK_AVATAR (contact->data), 48, 48, TRUE, 4, NULL);
+ if (!avatar) {
avatar = gdk_pixbuf_new_from_file ("/usr/share/icons/hicolor/48x48/hildon/general_default_avatar.png", &error);
}
- fullname = e_contact_get (E_CONTACT (contact->data), E_CONTACT_FULL_NAME);
- if (!fullname) {
- fullname = e_contact_get (E_CONTACT (contact->data), E_CONTACT_GIVEN_NAME);
- if (!fullname) {
- fullname = e_contact_get (E_CONTACT (contact->data), E_CONTACT_FAMILY_NAME);
- if (!fullname) {
- fullname = e_contact_get (E_CONTACT (contact->data), E_CONTACT_NICKNAME);
- if (!fullname) {
- fullname = e_contact_get (E_CONTACT (contact->data), E_CONTACT_ORG);
- }
- }
- }
- }
+ fullname = osso_abook_contact_get_display_name (OSSO_ABOOK_CONTACT (contact->data));
birthday_tm.tm_sec = 0;
birthday_tm.tm_min = 0;
birthday_tm.tm_year = bdate->year - 1900;
strftime (birthday_text, 11, _HL("wdgt_va_date"), &birthday_tm);
- age = calc_age(bdate);
- next_birthday = calc_next_bday(bdate);
- next_birthday_text = g_strdup_printf(ngettext ("next birthday in %d day", "next birthday in %d days", next_birthday), next_birthday);
- display_column = g_strdup_printf("%s <span font_desc=\"%s\" foreground=\"%s\"><sup>(%d)</sup>\n%s, %s</span>",
+ age = calc_age(bdate, current_date);
+ next_birthday = calc_next_bday(bdate, current_date);
+
+ if (next_birthday == 0)
+ next_birthday_text = g_strdup_printf (_("has birthday today"));
+ else
+ next_birthday_text = g_strdup_printf (ngettext ("will have birthday tomorrow",
+ "will have birthday in %d days", next_birthday),
+ next_birthday);
+
+ display_column = g_strdup_printf ("%s <span font_desc=\"%s\" foreground=\"%s\"><sup>(%d)</sup>\n%s, %s</span>",
fullname, text_font, text_color, age, birthday_text, next_birthday_text);
gtk_list_store_append (store, &iter);
COLUMN_DISPLAY, display_column,
COLUMN_FULLNAME, fullname,
COLUMN_NEXT_BIRTHDAY, next_birthday,
+ COLUMN_ABOOK_CONTACT, contact->data,
-1);
n_contacts++;
g_free (display_column);
display_column = NULL;
- if (fullname)
- g_free (fullname);
- fullname = NULL;
-
if (next_birthday_text)
g_free (next_birthday_text);
next_birthday_text = NULL;
create_main_window (BirthdayData *priv, GtkListStore *store)
{
HildonProgram *program = NULL;
- GtkWidget *main_vbox, *alignment, *pannable, *tree_view;
+ GtkWidget *main_vbox, *alignment, *pannable;
GtkTreeModel *filter;
GtkTreeViewColumn *column;
GtkCellRenderer *renderer;
+ GtkTreeSelection *selection;
g_return_if_fail (priv);
priv->filter = GTK_TREE_MODEL (filter);
/* tree view */
- priv->tree_view = hildon_gtk_tree_view_new_with_model (HILDON_UI_MODE_NORMAL, filter);
+ priv->tree_view = hildon_gtk_tree_view_new_with_model (HILDON_UI_MODE_EDIT, filter);
gtk_container_add (GTK_CONTAINER (pannable), priv->tree_view);
/* display column */
"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 ();
create_search_bar(priv);
gtk_box_pack_end (GTK_BOX (main_vbox), priv->search, FALSE, FALSE, 0);
- /* window signals */
- g_signal_connect (G_OBJECT (priv->window), "destroy", G_CALLBACK (gtk_main_quit), NULL);
- g_signal_connect (G_OBJECT (priv->window), "key-press-event", G_CALLBACK (on_key_press_event), priv);
-
gtk_widget_show_all (GTK_WIDGET (priv->window));
gtk_widget_hide (GTK_WIDGET (priv->search));
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);
+
+ /* tree view signals */
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view));
+ gtk_tree_selection_unselect_all (selection);
+ g_signal_connect (selection, "changed", G_CALLBACK (on_selection_changed), priv);
+
+ /* window signals */
+ g_signal_connect (G_OBJECT (priv->window), "destroy", G_CALLBACK (gtk_main_quit), NULL);
+ g_signal_connect (G_OBJECT (priv->window), "key-press-event", G_CALLBACK (on_key_press_event), priv);
}
static GList *
-get_all_contacts (EBook *ebook)
+get_all_contacts (void)
{
GError *error = NULL;
- EBookQuery *query;
+ OssoABookAggregator *aggregator;
GList *contacts;
- ebook = e_book_new_system_addressbook (&error);
- if (!ebook) {
- g_warning ("Error opening system address book: %s", error->message);
+ aggregator = OSSO_ABOOK_AGGREGATOR (osso_abook_aggregator_get_default (&error));
+ if (!aggregator) {
+ g_warning ("Error creating default abook aggregator: %s", error->message);
g_error_free (error);
return NULL;
}
- if (!e_book_open (ebook, TRUE, &error)) {
- g_warning ("Error opening system address book: %s", error->message);
+ osso_abook_waitable_run (OSSO_ABOOK_WAITABLE (aggregator), g_main_context_default(), &error);
+ if (error) {
+ g_warning ("Error wating for abook: %s", error->message);
g_error_free (error);
return NULL;
}
- query = e_book_query_any_field_contains ("");
-
- if (!e_book_get_contacts (ebook, query, &contacts, &error)) {
- g_warning ("Error getting contacts: %s", error->message);
- g_error_free (error);
- return NULL;
- }
+ contacts = osso_abook_aggregator_list_master_contacts (aggregator);
return contacts;
}
{
BirthdayData *data;
osso_context_t *osso_context;
- EBook *ebook;
- GtkWidget *window;
GtkListStore *store;
GList *contacts;
goto exit;
}
- contacts = get_all_contacts (ebook);
+ contacts = get_all_contacts ();
store = create_bday_liststore (data, contacts);
/* 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: