From: Roman Moravcik Date: Fri, 15 Oct 2010 13:11:05 +0000 (+0200) Subject: Added posibility to call or send SMS to selected contact. X-Git-Tag: v0.2-1~4 X-Git-Url: http://vcs.maemo.org/git/?p=birthday;a=commitdiff_plain;h=05b16825708be75389ab187149a7af3d83888c99 Added posibility to call or send SMS to selected contact. --- diff --git a/src/birthday.c b/src/birthday.c index 36a4797..52c472a 100644 --- a/src/birthday.c +++ b/src/birthday.c @@ -51,6 +51,7 @@ enum COLUMN_DISPLAY, COLUMN_FULLNAME, COLUMN_NEXT_BIRTHDAY, + COLUMN_ABOOK_CONTACT, NUM_COLS }; @@ -218,6 +219,7 @@ static void on_search_entry_changed (GtkEditable *editable, gpointer data) { + GtkTreeSelection *selection; BirthdayData *priv; g_return_if_fail (data); @@ -229,6 +231,12 @@ on_search_entry_changed (GtkEditable *editable, 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)); @@ -250,17 +258,30 @@ on_search_entry_changed (GtkEditable *editable, /* 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); @@ -281,6 +302,12 @@ on_search_close_clicked (GtkButton *button, /* 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); } @@ -315,6 +342,56 @@ on_key_press_event (GtkWidget *widget, return FALSE; } +static void +on_selection_changed (GtkTreeSelection *selection, + gpointer data) +{ + BirthdayData *priv; + GtkTreeModel *model; + GtkTreeIter iter; + + 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[7] = {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}; + + 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_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)); + } + } +} + static unsigned int calc_age (EContactDate *bdate, time_t current_date) { @@ -449,7 +526,8 @@ create_bday_liststore (BirthdayData *priv, GList *contacts) 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; @@ -465,6 +543,7 @@ create_bday_liststore (BirthdayData *priv, GList *contacts) gchar *next_birthday_text = NULL; struct tm birthday_tm; gchar birthday_text[11]; + OssoABookContact *abook_contact; photo = e_contact_get (E_CONTACT (contact->data), E_CONTACT_PHOTO); if (photo) { @@ -534,12 +613,15 @@ create_bday_liststore (BirthdayData *priv, GList *contacts) display_column = g_strdup_printf ("%s (%d)\n%s, %s", fullname, text_font, text_color, age, birthday_text, next_birthday_text); + abook_contact = osso_abook_contact_new_from_template (E_CONTACT (contact->data)); + gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, COLUMN_AVATAR, avatar, COLUMN_DISPLAY, display_column, COLUMN_FULLNAME, fullname, COLUMN_NEXT_BIRTHDAY, next_birthday, + COLUMN_ABOOK_CONTACT, abook_contact, -1); n_contacts++; @@ -644,6 +726,7 @@ create_main_window (BirthdayData *priv, GtkListStore *store) GtkTreeModel *filter; GtkTreeViewColumn *column; GtkCellRenderer *renderer; + GtkTreeSelection *selection; g_return_if_fail (priv); @@ -700,7 +783,7 @@ create_main_window (BirthdayData *priv, GtkListStore *store) 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 */ @@ -731,10 +814,6 @@ create_main_window (BirthdayData *priv, GtkListStore *store) 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)); @@ -749,6 +828,15 @@ create_main_window (BirthdayData *priv, GtkListStore *store) /* 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 *