r3474 - in trunk/src/target/OM-2007.2/applications/openmoko-messages2: . src

chris at sita.openmoko.org chris at sita.openmoko.org
Thu Nov 22 13:25:33 CET 2007


Author: chris
Date: 2007-11-22 13:25:31 +0100 (Thu, 22 Nov 2007)
New Revision: 3474

Added:
   trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-compose.c
   trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-compose.h
   trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-utils.c
   trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-utils.h
Modified:
   trunk/src/target/OM-2007.2/applications/openmoko-messages2/ChangeLog
   trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/Makefile.am
   trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-contacts.c
   trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-contacts.h
   trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-main.c
   trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-notes.c
   trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms.h
Log:
        * src/Makefile.am:
        Add new files sms-compose.[ch] and sms-utils.[ch]

        * src/sms-compose.c: (page_shown), (page_hidden),
        (notify_visible_cb), (visibility_notify_event_cb), (unmap_cb),
        (send_clicked_cb), (sms_compose_page_new):
        * src/sms-compose.h:
        Separate message sending in its own page, not enough room to do inline

        * src/sms-contacts.c: (contacts_store), (sms_contacts_page_new):
        * src/sms-contacts.h:
        Move parts to sms-utils.[ch], lookup icon size instead of using fixed
        for the missing photo image

        * src/sms-main.c: (new_clicked_cb), (main):
        Add callback for new button to switch to sending page, new button is a
        button instead of a toggle-button

        * src/sms-notes.c: (note_changed_cb), (page_shown), (page_hidden),
        (sms_notes_data_func), (sms_notes_page_new):
        Move SMS sending to separate page, move get_selected_contact function to
        sms-utils.[ch], swap alignment of sent/received messages

        * src/sms-utils.c: (sms_get_selected_contact),
        (contact_photo_size), (sms_contact_load_photo):
        * src/sms-utils.h:
        New utility functions collected from other files

        * src/sms.h:
        New variables for sending page


Modified: trunk/src/target/OM-2007.2/applications/openmoko-messages2/ChangeLog
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-messages2/ChangeLog	2007-11-22 10:22:27 UTC (rev 3473)
+++ trunk/src/target/OM-2007.2/applications/openmoko-messages2/ChangeLog	2007-11-22 12:25:31 UTC (rev 3474)
@@ -1,3 +1,36 @@
+2007-11-22  Chris Lord  <chris at openedhand.com>
+
+	* src/Makefile.am:
+	Add new files sms-compose.[ch] and sms-utils.[ch]
+
+	* src/sms-compose.c: (page_shown), (page_hidden),
+	(notify_visible_cb), (visibility_notify_event_cb), (unmap_cb),
+	(send_clicked_cb), (sms_compose_page_new):
+	* src/sms-compose.h:
+	Separate message sending in its own page, not enough room to do inline
+
+	* src/sms-contacts.c: (contacts_store), (sms_contacts_page_new):
+	* src/sms-contacts.h:
+	Move parts to sms-utils.[ch], lookup icon size instead of using fixed
+	for the missing photo image
+
+	* src/sms-main.c: (new_clicked_cb), (main):
+	Add callback for new button to switch to sending page, new button is a
+	button instead of a toggle-button
+
+	* src/sms-notes.c: (note_changed_cb), (page_shown), (page_hidden),
+	(sms_notes_data_func), (sms_notes_page_new):
+	Move SMS sending to separate page, move get_selected_contact function to
+	sms-utils.[ch], swap alignment of sent/received messages
+
+	* src/sms-utils.c: (sms_get_selected_contact),
+	(contact_photo_size), (sms_contact_load_photo):
+	* src/sms-utils.h:
+	New utility functions collected from other files
+
+	* src/sms.h:
+	New variables for sending page
+
 2007-11-21  Chris Lord  <chris at openedhand.com>
 
 	* src/sms-contacts.c: (sms_contacts_load_photo),

Modified: trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/Makefile.am
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/Makefile.am	2007-11-22 10:22:27 UTC (rev 3473)
+++ trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/Makefile.am	2007-11-22 12:25:31 UTC (rev 3474)
@@ -10,5 +10,9 @@
 	sms-contacts.c \
 	sms-contacts.h \
 	sms-notes.c \
-	sms-notes.h
+	sms-notes.h \
+	sms-compose.c \
+	sms-compose.h \
+	sms-utils.c \
+	sms-utils.h
 

Added: trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-compose.c
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-compose.c	2007-11-22 10:22:27 UTC (rev 3473)
+++ trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-compose.c	2007-11-22 12:25:31 UTC (rev 3474)
@@ -0,0 +1,247 @@
+/*
+ *  openmoko-messages -- OpenMoko SMS Application
+ *
+ *  Authored by Chris Lord <chris at openedhand.com>
+ *
+ *  Copyright (C) 2007 OpenMoko Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser Public License as published by
+ *  the Free Software Foundation; version 2 of the license.
+ *
+ *  This program 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 Public License for more details.
+ *
+ *  Current Version: $Rev$ ($Date$) [$Author$]
+ */
+
+#include "sms-compose.h"
+#include "sms-utils.h"
+#include <moko-stock.h>
+
+static gboolean hidden = TRUE;
+
+static void
+page_shown (SmsData *data)
+{
+	GtkTreeModel *model;
+	EContact *contact;
+	GdkPixbuf *photo;
+	gchar *string;
+	gint i;
+	
+	gboolean set = FALSE;
+	
+	if (!data->sms_proxy)
+		gtk_widget_set_sensitive (GTK_WIDGET (data->new_button), FALSE);
+	gtk_tool_button_set_stock_id (GTK_TOOL_BUTTON (data->new_button),
+		MOKO_STOCK_MAIL_SEND);
+	gtk_widget_grab_focus (data->sms_textview);
+
+	/* Empty numbers combo */
+	model = gtk_combo_box_get_model (GTK_COMBO_BOX (data->number_combo));
+	while (gtk_tree_model_iter_n_children (model, NULL))
+		gtk_combo_box_remove_text (GTK_COMBO_BOX (
+			data->number_combo), 0);
+
+	if (!(contact = sms_get_selected_contact (data))) {
+		gtk_image_set_from_icon_name (GTK_IMAGE (data->contact_image),
+			"stock_person", GTK_ICON_SIZE_DIALOG);
+		gtk_label_set_markup (GTK_LABEL (data->contact_label),
+			"<big>Unknown</big>");
+		return;
+	}
+	
+	/* Fill contact photo */
+	photo = sms_contact_load_photo (contact);
+	if (photo) {
+		gtk_image_set_from_pixbuf (GTK_IMAGE (
+			data->contact_image), photo);
+		g_object_unref (photo);
+	} else {
+		gtk_image_set_from_icon_name (GTK_IMAGE (data->contact_image),
+			"stock_person", GTK_ICON_SIZE_DIALOG);
+	}
+	
+	/* Fill contact label */
+	string = g_strconcat ("<big>", e_contact_get_const (
+		contact, E_CONTACT_FULL_NAME), "</big>", NULL);
+	gtk_label_set_markup (GTK_LABEL (data->contact_label), string);
+	g_free (string);
+	
+	/* Fill number combo */
+	for (i = E_CONTACT_FIRST_PHONE_ID; i <= E_CONTACT_LAST_PHONE_ID; i++) {
+		const gchar *number = e_contact_get_const (
+			contact, (EContactField)i);
+
+		if (!number) continue;
+		
+		if (((i == E_CONTACT_PHONE_MOBILE) ||
+		     (i == E_CONTACT_PHONE_PRIMARY)) && (!set)) {
+			gtk_entry_set_text (GTK_ENTRY (GTK_BIN (
+				data->number_combo)->child), number);
+			set = TRUE;
+		}
+		gtk_combo_box_append_text (GTK_COMBO_BOX (data->number_combo),
+			number);
+	}
+	if (!set) {
+		gtk_entry_set_text (GTK_ENTRY (GTK_BIN (
+			data->number_combo)->child),
+			gtk_combo_box_get_active_text (
+				GTK_COMBO_BOX (data->number_combo)));
+	}
+	
+	g_object_unref (contact);
+}
+
+static void
+page_hidden (SmsData *data)
+{
+	gtk_widget_set_sensitive (GTK_WIDGET (data->new_button), TRUE);
+	gtk_tool_button_set_stock_id (GTK_TOOL_BUTTON (data->new_button),
+		MOKO_STOCK_SMS_NEW);
+}
+
+static void
+notify_visible_cb (GObject *gobject, GParamSpec *arg1, SmsData *data)
+{
+	if ((!hidden) && (!GTK_WIDGET_VISIBLE (gobject))) {
+		hidden = TRUE;
+		page_hidden (data);
+	}
+}
+
+static gboolean
+visibility_notify_event_cb (GtkWidget *widget, GdkEventVisibility *event,
+			    SmsData *data)
+{
+	if (((event->state == GDK_VISIBILITY_PARTIAL) ||
+	     (event->state == GDK_VISIBILITY_UNOBSCURED)) && (hidden)) {
+		hidden = FALSE;
+		page_shown (data);
+	}/* else if ((event->state == GDK_VISIBILITY_FULLY_OBSCURED) &&
+		   (!hidden)) {
+		hidden = TRUE;
+	}*/
+	
+	return FALSE;
+}
+
+static void
+unmap_cb (GtkWidget *widget, SmsData *data)
+{
+	if (!hidden) {
+		hidden = TRUE;
+		page_hidden (data);
+	}
+}
+
+static void
+send_clicked_cb (GtkButton *button, SmsData *data)
+{
+	GtkTextIter start, end;
+	GtkTextBuffer *buffer;
+	const gchar *number;
+	EContact *contact;
+	gchar *message;
+	
+	if (hidden) return;
+	
+	/* TODO: Spawn an error dialog or something */
+	if (!(contact = sms_get_selected_contact (data))) return;
+	
+	gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
+		data->new_button), FALSE);
+
+	number = gtk_entry_get_text (GTK_ENTRY (
+		GTK_BIN (data->number_combo)->child));
+	
+	if (number && (number[0] != '\0')) {
+		GError *error = NULL;
+		buffer = gtk_text_view_get_buffer (
+			GTK_TEXT_VIEW (data->sms_textview));
+		gtk_text_buffer_get_start_iter (buffer, &start);
+		gtk_text_buffer_get_end_iter (buffer, &end);
+		message = gtk_text_buffer_get_text (
+			buffer, &start, &end, FALSE);
+		
+		if (message[0] != '\0') {
+			g_debug ("Sending message '%s' to %s", message, number);
+			if (!dbus_g_proxy_call (data->sms_proxy, "Send", &error,
+			     G_TYPE_STRING, number, G_TYPE_STRING, message,
+			     G_TYPE_INVALID, G_TYPE_STRING, NULL,
+			     G_TYPE_INVALID)) {
+				g_warning ("Error sending message: %s",
+					error->message);
+				g_error_free (error);
+			}
+		} else {
+			/* TODO: Error dialog for empty message */
+		}
+		
+		g_free (message);
+	} else {
+		/* TODO: Error dialog for empty number */
+	}
+	
+	g_object_unref (contact);
+
+	gtk_notebook_set_current_page (
+		GTK_NOTEBOOK (data->notebook), SMS_PAGE_NOTES);
+}
+
+GtkWidget *
+sms_compose_page_new (SmsData *data)
+{
+	GtkWidget *vbox, *frame, *contact_table;
+	
+	/* Connect to new/send button clicked */
+	g_signal_connect (data->new_button, "clicked",
+		G_CALLBACK (send_clicked_cb), data);
+	
+	/* Create contact info display/number entry */
+	contact_table = gtk_table_new (2, 2, FALSE);
+	gtk_table_set_col_spacings (GTK_TABLE (contact_table), 6);
+	gtk_table_set_row_spacings (GTK_TABLE (contact_table), 6);
+	gtk_container_set_border_width (GTK_CONTAINER (contact_table), 6);
+	data->contact_image = gtk_image_new ();
+	data->contact_label = gtk_label_new (NULL);
+	gtk_label_set_use_markup (GTK_LABEL (data->contact_label), TRUE);
+	gtk_misc_set_alignment (GTK_MISC (data->contact_label), 0, 0.5);
+	data->number_combo = gtk_combo_box_entry_new_text ();
+	gtk_table_attach (GTK_TABLE (contact_table), data->contact_image,
+		0, 1, 0, 2, GTK_FILL, GTK_FILL, 0, 0);
+	gtk_table_attach (GTK_TABLE (contact_table), data->contact_label,
+		1, 2, 0, 1, GTK_EXPAND | GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
+	gtk_table_attach (GTK_TABLE (contact_table), data->number_combo,
+		1, 2, 1, 2, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
+	
+	/* Create sms entry bits */
+	data->sms_textview = gtk_text_view_new ();
+	gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (data->sms_textview),
+		GTK_WRAP_WORD_CHAR);
+	frame = gtk_frame_new (NULL);
+	gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
+	gtk_container_add (GTK_CONTAINER (frame), data->sms_textview);
+	
+	/* Pack widgets */
+	vbox = gtk_vbox_new (FALSE, 0);
+	gtk_box_pack_start (GTK_BOX (vbox), contact_table, FALSE, TRUE, 0);
+	gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);
+
+	/* Add events for detecting whether the page has been hidden/shown */
+	gtk_widget_add_events (data->sms_textview, GDK_VISIBILITY_NOTIFY_MASK);
+	g_signal_connect (data->sms_textview, "visibility-notify-event",
+		G_CALLBACK (visibility_notify_event_cb), data);
+	g_signal_connect (data->sms_textview, "notify::visible",
+		G_CALLBACK (notify_visible_cb), data);
+	g_signal_connect (vbox, "unmap",
+		G_CALLBACK (unmap_cb), data);
+
+	gtk_widget_show_all (vbox);
+	
+	return vbox;
+}

Added: trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-compose.h
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-compose.h	2007-11-22 10:22:27 UTC (rev 3473)
+++ trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-compose.h	2007-11-22 12:25:31 UTC (rev 3474)
@@ -0,0 +1,27 @@
+/*
+ *  openmoko-messages -- OpenMoko SMS Application
+ *
+ *  Authored by Chris Lord <chris at openedhand.com>
+ *
+ *  Copyright (C) 2007 OpenMoko Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser Public License as published by
+ *  the Free Software Foundation; version 2 of the license.
+ *
+ *  This program 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 Public License for more details.
+ *
+ *  Current Version: $Rev$ ($Date$) [$Author$]
+ */
+
+#ifndef SMS_COMPOSE_H
+#define SMS_COMPOSE_H
+
+#include "sms.h"
+
+GtkWidget *sms_compose_page_new (SmsData *data);
+
+#endif /* SMS_COMPOSE_H */

Modified: trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-contacts.c
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-contacts.c	2007-11-22 10:22:27 UTC (rev 3473)
+++ trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-contacts.c	2007-11-22 12:25:31 UTC (rev 3474)
@@ -25,66 +25,6 @@
 #  include <config.h>
 #endif
 
-/* Following two functions taken from pimlico Contacts */
-static void
-contact_photo_size (GdkPixbufLoader * loader, gint width, gint height,
-		    gpointer user_data)
-{
-	/* Max height of GTK_ICON_SIZE_DIALOG */
-	gint iconwidth, iconheight;
-	gtk_icon_size_lookup (GTK_ICON_SIZE_DIALOG, &iconwidth, &iconheight);
-	
-	gdk_pixbuf_loader_set_size (loader,
-				    width / ((gdouble) height /
-					     iconheight), iconheight);
-}
-
-GdkPixbuf *
-sms_contacts_load_photo (EContact *contact)
-{
-	EContactPhoto *photo;
-	GdkPixbuf *pixbuf = NULL;
-	
-	/* Retrieve contact picture and resize */
-	photo = e_contact_get (contact, E_CONTACT_PHOTO);
-	if (photo) {
-		GdkPixbufLoader *loader = gdk_pixbuf_loader_new ();
-		if (loader) {
-			g_signal_connect (G_OBJECT (loader),
-					  "size-prepared",
-					  G_CALLBACK (contact_photo_size),
-					  NULL);
-#if HAVE_PHOTO_TYPE
-			switch (photo->type) {
-			case E_CONTACT_PHOTO_TYPE_INLINED :
-				gdk_pixbuf_loader_write (loader,
-					photo->data.inlined.data,
-					photo->data.inlined.length, NULL);
-				break;
-			case E_CONTACT_PHOTO_TYPE_URI :
-			default :
-				g_warning ("Cannot handle URI photos yet");
-				g_object_unref (loader);
-				loader = NULL;
-				break;
-			}
-#else
-			gdk_pixbuf_loader_write (loader, (const guchar *)
-				photo->data, photo->length, NULL);
-#endif
-			if (loader) {
-				gdk_pixbuf_loader_close (loader, NULL);
-				pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
-				if (pixbuf) g_object_ref (pixbuf);
-				g_object_unref (loader);
-			}
-		}
-		e_contact_photo_free (photo);
-	}
-	
-	return pixbuf;
-}
-
 static const gchar *clear_numbers_uid;
 
 static void
@@ -113,7 +53,7 @@
 {
 	gint i;
 	
-	GdkPixbuf *photo = sms_contacts_load_photo (contact);
+	GdkPixbuf *photo = sms_contact_load_photo (contact);
 
 	gtk_list_store_set ((GtkListStore *)data->contacts_store, iter,
 		COL_UID, e_contact_get_const (contact, E_CONTACT_UID),
@@ -252,7 +192,7 @@
 	GtkCellRenderer *renderer;
 	EBookQuery *tel_query;
 	EBookView *view;
-	gint i;
+	gint i, width;
 
 	GError *error = NULL;
 	
@@ -295,8 +235,9 @@
 	}
 	
 	/* Get icon to use when no contact photo exists */
+	gtk_icon_size_lookup (GTK_ICON_SIZE_DIALOG, &width, NULL);
 	data->no_photo = gtk_icon_theme_load_icon (
-		gtk_icon_theme_get_default (), "stock_person", 48, 0, NULL);
+		gtk_icon_theme_get_default (), "stock_person", width, 0, NULL);
 
 	/* Create contacts model */
 	data->contacts_store = (GtkTreeModel *)gtk_list_store_new (COL_LAST,

Modified: trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-contacts.h
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-contacts.h	2007-11-22 10:22:27 UTC (rev 3473)
+++ trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-contacts.h	2007-11-22 12:25:31 UTC (rev 3474)
@@ -31,7 +31,6 @@
 };
 
 GtkWidget *sms_contacts_page_new (SmsData *data);
-GdkPixbuf *sms_contacts_load_photo (EContact *contact);
 
 #endif
 

Modified: trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-main.c
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-main.c	2007-11-22 10:22:27 UTC (rev 3473)
+++ trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-main.c	2007-11-22 12:25:31 UTC (rev 3474)
@@ -20,6 +20,8 @@
 #include "sms.h"
 #include "sms-contacts.h"
 #include "sms-notes.h"
+#include "sms-compose.h"
+#include <moko-stock.h>
 
 static void
 notebook_add_page_with_icon (GtkWidget *notebook, GtkWidget *child,
@@ -38,6 +40,13 @@
 		"tab-expand", TRUE, NULL);
 }
 
+static void
+new_clicked_cb (GtkToolButton *button, SmsData *data)
+{
+	gtk_notebook_set_current_page (
+		GTK_NOTEBOOK (data->notebook), SMS_PAGE_COMPOSE);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -47,6 +56,7 @@
 	GError *error = NULL;
 	
 	gtk_init (&argc, &argv);
+	moko_stock_register ();
 	
 	/* Get SMS dbus proxy */
 	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
@@ -69,25 +79,27 @@
 	toolbar = gtk_toolbar_new ();
 	
 	/* New button */
-	data.new_button = gtk_toggle_tool_button_new_from_stock (GTK_STOCK_NEW);
+	data.new_button = gtk_tool_button_new_from_stock (MOKO_STOCK_SMS_NEW);
 	gtk_tool_item_set_expand (data.new_button, TRUE);
 	gtk_toolbar_insert (GTK_TOOLBAR (toolbar), data.new_button, 0);
-	gtk_toolbar_insert (GTK_TOOLBAR (toolbar),
-		gtk_separator_tool_item_new (), 1);
+	/*gtk_toolbar_insert (GTK_TOOLBAR (toolbar),
+		gtk_separator_tool_item_new (), 1);*/
+	g_signal_connect (data.new_button, "clicked",
+		G_CALLBACK (new_clicked_cb), &data);
 	
 	/* Delete all button */
 	data.delete_all_button = gtk_tool_button_new_from_stock (
 		GTK_STOCK_MISSING_IMAGE);
 	gtk_tool_item_set_expand (data.delete_all_button, TRUE);
-	gtk_toolbar_insert (GTK_TOOLBAR (toolbar), data.delete_all_button, 2);
-	gtk_toolbar_insert (GTK_TOOLBAR (toolbar),
-		gtk_separator_tool_item_new (), 3);
+	gtk_toolbar_insert (GTK_TOOLBAR (toolbar), data.delete_all_button, 1);
+	/*gtk_toolbar_insert (GTK_TOOLBAR (toolbar),
+		gtk_separator_tool_item_new (), 3);*/
 	
 	/* Delete button */
 	data.delete_button = gtk_tool_button_new_from_stock (
 		GTK_STOCK_DELETE);
 	gtk_tool_item_set_expand (data.delete_button, TRUE);
-	gtk_toolbar_insert (GTK_TOOLBAR (toolbar), data.delete_button, 4);
+	gtk_toolbar_insert (GTK_TOOLBAR (toolbar), data.delete_button, 2);
 	
 	/* Create notebook */
 	data.notebook = gtk_notebook_new ();
@@ -97,10 +109,14 @@
 	notebook_add_page_with_icon (data.notebook,
 		sms_contacts_page_new (&data), GTK_STOCK_INDEX, 6);
 
-	/* Add message view/send page */
+	/* Add message view page */
 	notebook_add_page_with_icon (data.notebook,
-		sms_notes_page_new (&data), GTK_STOCK_EDIT, 6);
+		sms_notes_page_new (&data), GTK_STOCK_FILE, 6);
 
+	/* Add message compose page */
+	notebook_add_page_with_icon (data.notebook,
+		sms_compose_page_new (&data), GTK_STOCK_EDIT, 6);
+	
 	/* Pack and show */
 	vbox = gtk_vbox_new (FALSE, 0);
 	gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, TRUE, 0);

Modified: trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-notes.c
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-notes.c	2007-11-22 10:22:27 UTC (rev 3473)
+++ trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-notes.c	2007-11-22 12:25:31 UTC (rev 3474)
@@ -18,7 +18,7 @@
  */
 
 #include "sms-notes.h"
-#include "sms-contacts.h"
+#include "sms-utils.h"
 #include <libjana-ecal/jana-ecal.h>
 #include <libmokoui2/moko-finger-scroll.h>
 #include <libmokoui2/moko-search-bar.h>
@@ -29,34 +29,6 @@
 static gboolean hidden = TRUE;
 static gboolean open = FALSE;
 
-static EContact *
-get_selected_contact (SmsData *data)
-{
-	GtkTreeSelection *selection;
-	GtkTreeModel *model;
-	EContact *contact;
-	GtkTreeIter iter;
-	
-	GError *error = NULL;
-	
-	selection = gtk_tree_view_get_selection (
-		GTK_TREE_VIEW (data->contacts_treeview));
-	
-	if (!gtk_tree_selection_get_selected (selection, &model, &iter))
-		return NULL;
-	gtk_tree_model_get (model, &iter, COL_UID, &data->author_uid,
-		COL_ICON, &data->author_icon, -1);
-	
-	if (!e_book_get_contact (data->ebook,
-	     data->author_uid, &contact, &error)) {
-		g_warning ("Error retrieving contact: %s", error->message);
-		g_error_free (error);
-		contact = NULL;
-	}
-	
-	return contact;
-}
-
 static void
 note_changed_cb (JanaStoreView *store_view, GList *components, SmsData *data)
 {
@@ -88,7 +60,7 @@
 			/* TODO: Unknown contact, probably */
 		} else {
 			data->recipient_icon =
-				sms_contacts_load_photo (contact);
+				sms_contact_load_photo (contact);
 			if ((!data->recipient_icon) && (data->no_photo))
 				data->recipient_icon =
 					g_object_ref (data->no_photo);
@@ -115,7 +87,7 @@
 	
 	if (!open) return;
 	
-	if (!(contact = get_selected_contact (data))) return;
+	if (!(contact = sms_get_selected_contact (data))) return;
 	
 	store_view = jana_store_get_view (data->notes);
 	for (i = E_CONTACT_FIRST_PHONE_ID; i <= E_CONTACT_LAST_PHONE_ID; i++) {
@@ -149,8 +121,6 @@
 {
 	jana_gtk_note_store_set_view (JANA_GTK_NOTE_STORE (
 		data->note_store), NULL);
-	gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
-		data->new_button), FALSE);
 	if (data->author_uid) {
 		g_free (data->author_uid);
 		data->author_uid = NULL;
@@ -203,72 +173,6 @@
 	}
 }
 
-static void
-new_toggled_cb (GtkToggleToolButton *button, SmsData *data)
-{
-	gboolean active = gtk_toggle_tool_button_get_active (button);
-
-	g_object_set (data->sms_hbox, "visible", active, NULL);
-	if (active) {
-		gtk_notebook_set_current_page (GTK_NOTEBOOK (
-			data->notebook), SMS_PAGE_NOTES);
-		gtk_widget_grab_focus (data->sms_textview);
-	}
-}
-
-static void
-send_clicked_cb (GtkButton *button, SmsData *data)
-{
-	GtkTextIter start, end;
-	GtkTextBuffer *buffer;
-	const gchar *number;
-	EContact *contact;
-	gchar *message;
-	
-	/* TODO: Spawn an error dialog or something */
-	if (!(contact = get_selected_contact (data))) return;
-	
-	gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
-		data->new_button), FALSE);
-
-	/* Try getting mobile and primary number first, before looping through 
-	 * all numbers.
-	 */
-	number = NULL;
-	if (!(number = e_contact_get_const (contact, E_CONTACT_PHONE_MOBILE)) &&
-	    !(number = e_contact_get_const (contact, E_CONTACT_PHONE_PRIMARY))){
-		gint i;
-		for (i = E_CONTACT_FIRST_PHONE_ID;
-		     i <= E_CONTACT_LAST_PHONE_ID; i++) {
-			number = e_contact_get_const (
-				contact, (EContactField)i);
-			if (number) break;
-		}
-	}
-	
-	if (number) {
-		GError *error = NULL;
-		buffer = gtk_text_view_get_buffer (
-			GTK_TEXT_VIEW (data->sms_textview));
-		gtk_text_buffer_get_start_iter (buffer, &start);
-		gtk_text_buffer_get_end_iter (buffer, &end);
-		message = gtk_text_buffer_get_text (
-			buffer, &start, &end, FALSE);
-		
-		g_debug ("Sending message '%s' to %s", message, number);
-		if (!dbus_g_proxy_call (data->sms_proxy, "Send", &error,
-			G_TYPE_STRING, number, G_TYPE_STRING, message,
-			G_TYPE_INVALID, G_TYPE_STRING, NULL, G_TYPE_INVALID)) {
-			g_warning ("Error sending message: %s", error->message);
-			g_error_free (error);
-		}
-		
-		g_free (message);
-	}
-	
-	g_object_unref (contact);
-}
-
 static void sms_notes_data_func (GtkTreeViewColumn *tree_column,
 				 GtkCellRenderer *cell,
 				 GtkTreeModel *model,
@@ -278,7 +182,6 @@
 	gchar *author, *recipient, *body;
 	JanaTime *created, *modified;
 	gboolean outgoing;
-	gint i;
 	
 	gtk_tree_model_get (model, iter,
 		JANA_GTK_NOTE_STORE_COL_AUTHOR, &author,
@@ -301,7 +204,7 @@
 		"created", created,
 		"modified", modified,
 		"justify", outgoing ?
-		      GTK_JUSTIFY_LEFT : GTK_JUSTIFY_RIGHT,
+		      GTK_JUSTIFY_RIGHT : GTK_JUSTIFY_LEFT,
 		"icon", outgoing ?
 		      data->author_icon : data->recipient_icon,
 		NULL);
@@ -323,8 +226,7 @@
 GtkWidget *
 sms_notes_page_new (SmsData *data)
 {
-	GtkWidget *treeview, *scroll, *vbox, *searchbar,
-		*sms_vbox, *frame, *label, *button;
+	GtkWidget *treeview, *scroll, *vbox, *searchbar;
 	GtkCellRenderer *renderer;
 	GHashTable *colours_hash;
 	
@@ -361,36 +263,6 @@
 	searchbar = moko_search_bar_new_with_combo (
 		GTK_COMBO_BOX (data->notes_combo));
 	
-	/* Create text entry bits */
-	data->sms_textview = gtk_text_view_new ();
-	gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (data->sms_textview),
-		GTK_WRAP_WORD_CHAR);
-	frame = gtk_frame_new (NULL);
-	gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
-	gtk_container_add (GTK_CONTAINER (frame), data->sms_textview);
-	
-	label = gtk_label_new (NULL);
-	gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
-	gtk_label_set_markup (GTK_LABEL (label),
-		"<small>0\n  /\n     160</small>");
-	
-	button = gtk_button_new_with_label ("Send");
-	g_signal_connect (button, "clicked",
-		G_CALLBACK (send_clicked_cb), data);
-	if (!data->sms_proxy) gtk_widget_set_sensitive (button, FALSE);
-	
-	sms_vbox = gtk_vbox_new (FALSE, 6);
-	gtk_box_pack_start (GTK_BOX (sms_vbox), label, FALSE, TRUE, 0);
-	gtk_box_pack_end (GTK_BOX (sms_vbox), button, TRUE, TRUE, 0);
-
-	data->sms_hbox = gtk_hbox_new (FALSE, 6);
-	gtk_box_pack_start (GTK_BOX (data->sms_hbox), frame, TRUE, TRUE, 0);
-	gtk_box_pack_end (GTK_BOX (data->sms_hbox), sms_vbox, FALSE, TRUE, 0);
-
-	gtk_widget_show_all (data->sms_hbox);
-	gtk_widget_set_no_show_all (data->sms_hbox, TRUE);
-	gtk_widget_hide (data->sms_hbox);
-	
 	/* Pack widgets */
 	scroll = moko_finger_scroll_new ();
 	gtk_container_add (GTK_CONTAINER (scroll), treeview);
@@ -398,7 +270,6 @@
 	vbox = gtk_vbox_new (FALSE, 0);
 	gtk_box_pack_start (GTK_BOX (vbox), searchbar, FALSE, TRUE, 0);
 	gtk_box_pack_start (GTK_BOX (vbox), scroll, TRUE, TRUE, 0);
-	gtk_box_pack_end (GTK_BOX (vbox), data->sms_hbox, FALSE, TRUE, 0);
 	gtk_widget_show_all (vbox);
 	
 	/* Add events for detecting whether the page has been hidden/shown */
@@ -410,10 +281,6 @@
 	g_signal_connect (vbox, "unmap",
 		G_CALLBACK (unmap_cb), data);
 	
-	/* Connect to new button toggle */
-	g_signal_connect (data->new_button, "toggled",
-		G_CALLBACK (new_toggled_cb), data);
-	
 	jana_store_open (data->notes);
 
 	return vbox;

Added: trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-utils.c
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-utils.c	2007-11-22 10:22:27 UTC (rev 3473)
+++ trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-utils.c	2007-11-22 12:25:31 UTC (rev 3474)
@@ -0,0 +1,112 @@
+/*
+ *  openmoko-messages -- OpenMoko SMS Application
+ *
+ *  Authored by Chris Lord <chris at openedhand.com>
+ *
+ *  Copyright (C) 2007 OpenMoko Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser Public License as published by
+ *  the Free Software Foundation; version 2 of the license.
+ *
+ *  This program 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 Public License for more details.
+ *
+ *  Current Version: $Rev$ ($Date$) [$Author$]
+ */
+
+#include "sms-contacts.h"
+#include "sms-utils.h"
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+EContact *
+sms_get_selected_contact (SmsData *data)
+{
+	GtkTreeSelection *selection;
+	GtkTreeModel *model;
+	EContact *contact;
+	GtkTreeIter iter;
+	
+	GError *error = NULL;
+	
+	selection = gtk_tree_view_get_selection (
+		GTK_TREE_VIEW (data->contacts_treeview));
+	
+	if (!gtk_tree_selection_get_selected (selection, &model, &iter))
+		return NULL;
+	gtk_tree_model_get (model, &iter, COL_UID, &data->author_uid,
+		COL_ICON, &data->author_icon, -1);
+	
+	if (!e_book_get_contact (data->ebook,
+	     data->author_uid, &contact, &error)) {
+		g_warning ("Error retrieving contact: %s", error->message);
+		g_error_free (error);
+		contact = NULL;
+	}
+	
+	return contact;
+}
+
+/* Following two functions taken from pimlico Contacts and modified slightly */
+static void
+contact_photo_size (GdkPixbufLoader * loader, gint width, gint height,
+		    gpointer user_data)
+{
+	/* Max height of GTK_ICON_SIZE_DIALOG */
+	gint iconwidth, iconheight;
+	gtk_icon_size_lookup (GTK_ICON_SIZE_DIALOG, &iconwidth, &iconheight);
+	
+	gdk_pixbuf_loader_set_size (loader,
+				    width / ((gdouble) height /
+					     iconheight), iconheight);
+}
+
+GdkPixbuf *
+sms_contact_load_photo (EContact *contact)
+{
+	EContactPhoto *photo;
+	GdkPixbuf *pixbuf = NULL;
+	
+	/* Retrieve contact picture and resize */
+	photo = e_contact_get (contact, E_CONTACT_PHOTO);
+	if (photo) {
+		GdkPixbufLoader *loader = gdk_pixbuf_loader_new ();
+		if (loader) {
+			g_signal_connect (G_OBJECT (loader),
+					  "size-prepared",
+					  G_CALLBACK (contact_photo_size),
+					  NULL);
+#if HAVE_PHOTO_TYPE
+			switch (photo->type) {
+			case E_CONTACT_PHOTO_TYPE_INLINED :
+				gdk_pixbuf_loader_write (loader,
+					photo->data.inlined.data,
+					photo->data.inlined.length, NULL);
+				break;
+			case E_CONTACT_PHOTO_TYPE_URI :
+			default :
+				g_warning ("Cannot handle URI photos yet");
+				g_object_unref (loader);
+				loader = NULL;
+				break;
+			}
+#else
+			gdk_pixbuf_loader_write (loader, (const guchar *)
+				photo->data, photo->length, NULL);
+#endif
+			if (loader) {
+				gdk_pixbuf_loader_close (loader, NULL);
+				pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
+				if (pixbuf) g_object_ref (pixbuf);
+				g_object_unref (loader);
+			}
+		}
+		e_contact_photo_free (photo);
+	}
+	
+	return pixbuf;
+}

Added: trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-utils.h
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-utils.h	2007-11-22 10:22:27 UTC (rev 3473)
+++ trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms-utils.h	2007-11-22 12:25:31 UTC (rev 3474)
@@ -0,0 +1,28 @@
+/*
+ *  openmoko-messages -- OpenMoko SMS Application
+ *
+ *  Authored by Chris Lord <chris at openedhand.com>
+ *
+ *  Copyright (C) 2007 OpenMoko Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser Public License as published by
+ *  the Free Software Foundation; version 2 of the license.
+ *
+ *  This program 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 Public License for more details.
+ *
+ *  Current Version: $Rev$ ($Date$) [$Author$]
+ */
+
+#ifndef SMS_UTILS_H
+#define SMS_UTILS_H
+
+#include "sms.h"
+
+EContact *sms_get_selected_contact (SmsData *data);
+GdkPixbuf *sms_contact_load_photo (EContact *contact);
+
+#endif /* SMS_UTILS_H */

Modified: trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms.h
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms.h	2007-11-22 10:22:27 UTC (rev 3473)
+++ trunk/src/target/OM-2007.2/applications/openmoko-messages2/src/sms.h	2007-11-22 12:25:31 UTC (rev 3474)
@@ -46,8 +46,6 @@
 	GtkToolItem *delete_button;
 
 	GtkWidget *notes_combo;
-	GtkWidget *sms_hbox;
-	GtkWidget *sms_textview;
 	GdkPixbuf *author_icon;
 	GdkPixbuf *recipient_icon;
 	gchar *recipient_number;
@@ -57,6 +55,12 @@
 	GtkWidget *contacts_combo;
 	GdkPixbuf *no_photo;
 	
+	GtkWidget *sms_textview;
+	GtkWidget *length_label;
+	GtkWidget *contact_image;
+	GtkWidget *contact_label;
+	GtkWidget *number_combo;
+
 	gulong delete_all_handler;
 	gulong delete_handler;
 	
@@ -66,6 +70,7 @@
 typedef enum {
 	SMS_PAGE_CONTACTS,
 	SMS_PAGE_NOTES,
+	SMS_PAGE_COMPOSE,
 } SmsPage;
 
 #endif /* _SMS_H */





More information about the commitlog mailing list