r3246 - in trunk/src/target/OM-2007.2/applications/openmoko-appearance: . src
chris at sita.openmoko.org
chris at sita.openmoko.org
Mon Oct 22 19:47:56 CEST 2007
Author: chris
Date: 2007-10-22 19:47:55 +0200 (Mon, 22 Oct 2007)
New Revision: 3246
Added:
trunk/src/target/OM-2007.2/applications/openmoko-appearance/src/appearance-background.c
trunk/src/target/OM-2007.2/applications/openmoko-appearance/src/appearance-background.h
Modified:
trunk/src/target/OM-2007.2/applications/openmoko-appearance/ChangeLog
trunk/src/target/OM-2007.2/applications/openmoko-appearance/src/Makefile.am
trunk/src/target/OM-2007.2/applications/openmoko-appearance/src/appearance-main.c
trunk/src/target/OM-2007.2/applications/openmoko-appearance/src/appearance.h
Log:
* src/Makefile.am:
* src/appearance-background.[ch]:
* src/appearance-main.c: (main):
* src/appearance.h:
Add background chooser
Modified: trunk/src/target/OM-2007.2/applications/openmoko-appearance/ChangeLog
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-appearance/ChangeLog 2007-10-22 17:41:18 UTC (rev 3245)
+++ trunk/src/target/OM-2007.2/applications/openmoko-appearance/ChangeLog 2007-10-22 17:47:55 UTC (rev 3246)
@@ -1,3 +1,11 @@
+2007-10-22 Chris Lord <chris at openedhand.com>
+
+ * src/Makefile.am:
+ * src/appearance-background.[ch]:
+ * src/appearance-main.c: (main):
+ * src/appearance.h:
+ Add background chooser
+
2007-10-22 Thomas Wood <thomas at openedhand.com>
* Makefile.am:
Modified: trunk/src/target/OM-2007.2/applications/openmoko-appearance/src/Makefile.am
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-appearance/src/Makefile.am 2007-10-22 17:41:18 UTC (rev 3245)
+++ trunk/src/target/OM-2007.2/applications/openmoko-appearance/src/Makefile.am 2007-10-22 17:47:55 UTC (rev 3246)
@@ -10,7 +10,9 @@
appearance.h \
appearance-main.c \
appearance-colors.c \
- appearance-colors.h
+ appearance-colors.h \
+ appearance-background.c \
+ appearance-background.h
openmoko_appearance_LDADD = @MOKOUI_LIBS@
Added: trunk/src/target/OM-2007.2/applications/openmoko-appearance/src/appearance-background.c
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-appearance/src/appearance-background.c 2007-10-22 17:41:18 UTC (rev 3245)
+++ trunk/src/target/OM-2007.2/applications/openmoko-appearance/src/appearance-background.c 2007-10-22 17:47:55 UTC (rev 3246)
@@ -0,0 +1,207 @@
+/*
+ * OpenMoko Appearance - Change various appearance related settings
+ *
+ * Copyright (C) 2007 by OpenMoko, Inc.
+ * Written by OpenedHand Ltd <info at openedhand.com>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "appearance-background.h"
+#include <gconf/gconf-client.h>
+
+static gboolean
+unselect_file_idle (GtkFileChooser *chooser)
+{
+ gtk_file_chooser_unselect_all (chooser);
+ return FALSE;
+}
+
+/* Following three functions taken from openmoko-today2 */
+static void
+wallpaper_notify (GConfClient *client, guint cnxn_id,
+ GConfEntry *entry, AppearanceData *data)
+{
+ gint width, height, pwidth, pheight;
+ GdkPixbuf *pixbuf, *pixbuf_scaled;
+ GConfValue *value;
+ const gchar *path = NULL;
+ gfloat scale;
+
+ if (!GTK_WIDGET_REALIZED (data->bg_ebox))
+ gtk_widget_realize (data->bg_ebox);
+
+ /* Return if the background is tiny, we'll get called again when it
+ * resizes anyway.
+ */
+ width = data->bg_ebox->allocation.width;
+ height = data->bg_ebox->allocation.height;
+ if ((width <= 0) || (height <= 0)) return;
+
+ value = gconf_entry_get_value (entry);
+ if (value) path = gconf_value_get_string (value);
+ if (!path || (!(pixbuf = gdk_pixbuf_new_from_file (path, NULL)))) {
+ /* We need to do this in an idle, otherwise there's some weird
+ * race condition where it won't work...
+ */
+ g_idle_add_full (G_PRIORITY_HIGH_IDLE, (GSourceFunc)
+ unselect_file_idle, data->bg_chooser, NULL);
+ if (data->wallpaper) {
+ g_object_unref (data->wallpaper);
+ data->wallpaper = NULL;
+ gtk_widget_queue_draw (data->bg_ebox);
+ }
+ return;
+ }
+
+ /* Select the file in the background chooser, if it isn't already */
+ gtk_file_chooser_set_filename (
+ GTK_FILE_CHOOSER (data->bg_chooser), path);
+
+ /* Create background pixmap */
+ if (data->wallpaper) g_object_unref (data->wallpaper);
+ data->wallpaper = gdk_pixmap_new (data->bg_ebox->window,
+ width, height, -1);
+
+ /* Scale and draw pixbuf */
+ pwidth = gdk_pixbuf_get_width (pixbuf);
+ pheight = gdk_pixbuf_get_height (pixbuf);
+ if (((gfloat)pwidth / (gfloat)pheight) >
+ ((gfloat)width / (gfloat)height))
+ scale = (gfloat)height/(gfloat)pheight;
+ else
+ scale = (gfloat)width/(gfloat)pwidth;
+ pwidth *= scale;
+ pheight *= scale;
+ pixbuf_scaled = gdk_pixbuf_scale_simple (pixbuf, pwidth, pheight,
+ GDK_INTERP_BILINEAR);
+ if (pixbuf_scaled) {
+ gdk_draw_pixbuf (data->wallpaper, NULL, pixbuf_scaled,
+ 0, 0, 0, 0, -1, -1, GDK_RGB_DITHER_MAX, 0, 0);
+ g_object_unref (pixbuf_scaled);
+ }
+ g_object_unref (pixbuf);
+
+ /* Redraw */
+ gtk_widget_queue_draw (data->bg_ebox);
+}
+
+static gboolean
+bg_expose_cb (GtkWidget *widget, GdkEventExpose *event, AppearanceData *data)
+{
+ if (data->wallpaper)
+ gdk_draw_drawable (widget->window, widget->style->black_gc,
+ data->wallpaper, 0, 0, 0, 0, -1, -1);
+
+ return FALSE;
+}
+
+static void
+bg_size_allocate_cb (GtkWidget *widget, GtkAllocation *allocation,
+ AppearanceData *data)
+{
+ static gint width = 0, height = 0;
+
+ /* Re-scale wallpaper */
+ if ((width != allocation->width) || (height != allocation->height)) {
+ width = allocation->width;
+ height = allocation->height;
+ gconf_client_notify (gconf_client_get_default (),
+ GCONF_POKY_INTERFACE_PREFIX GCONF_POKY_WALLPAPER);
+ }
+}
+
+static void
+bg_response_cb (GtkDialog *dialog, gint response, AppearanceData *data)
+{
+ gchar *file;
+
+ switch (response) {
+ case GTK_RESPONSE_NO :
+ gconf_client_unset (gconf_client_get_default (),
+ GCONF_POKY_INTERFACE_PREFIX GCONF_POKY_WALLPAPER,
+ NULL);
+ break;
+ case GTK_RESPONSE_ACCEPT :
+ file = gtk_file_chooser_get_filename (
+ GTK_FILE_CHOOSER (data->bg_chooser));
+ gconf_client_set_string (gconf_client_get_default (),
+ GCONF_POKY_INTERFACE_PREFIX GCONF_POKY_WALLPAPER,
+ file, NULL);
+ g_free (file);
+ break;
+ case GTK_RESPONSE_CANCEL :
+ default :
+ break;
+ }
+}
+
+GtkWidget *
+background_page_new (AppearanceData *data)
+{
+ GtkWidget *button, *align;
+
+ /* Create an event box so we can draw a background for the page */
+ data->bg_ebox = gtk_event_box_new ();
+
+ /* Tell GTK we want to paint on this widget */
+ gtk_widget_set_app_paintable (data->bg_ebox, TRUE);
+
+ /* Connect to the 'expose' event to know when we should draw */
+ g_signal_connect (data->bg_ebox, "expose-event",
+ G_CALLBACK (bg_expose_cb), data);
+
+ /* Connect to the 'size-allocate' event so we can resize the image to
+ * fit the background.
+ */
+ g_signal_connect (data->bg_ebox, "size-allocate",
+ G_CALLBACK (bg_size_allocate_cb), data);
+
+ /* Create a file-chooser dialog */
+ data->bg_chooser = gtk_file_chooser_dialog_new ("Choose an image",
+ GTK_WINDOW (data->window), GTK_FILE_CHOOSER_ACTION_OPEN,
+ "No image", GTK_RESPONSE_NO,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
+
+ /* Connect to the 'response' signal for the file chooser */
+ g_signal_connect (data->bg_chooser, "response",
+ G_CALLBACK (bg_response_cb), data);
+
+ /* Create a file-chooser button */
+ button = gtk_file_chooser_button_new_with_dialog (data->bg_chooser);
+
+ /* Create an alignment so we can squish the button to the bottom of
+ * the page, with padding
+ */
+ align = gtk_alignment_new (0.5, 1, 1, 0);
+ gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 12, 12, 12);
+
+ /* Pack widgets into the page/each other and show them */
+ gtk_container_add (GTK_CONTAINER (align), button);
+ gtk_container_add (GTK_CONTAINER (data->bg_ebox), align);
+ gtk_widget_show_all (data->bg_ebox);
+
+ /* Connect to GConf signals */
+ gconf_client_add_dir (gconf_client_get_default (),
+ GCONF_POKY_INTERFACE_PREFIX, GCONF_CLIENT_PRELOAD_NONE, NULL);
+ gconf_client_notify_add (gconf_client_get_default (),
+ GCONF_POKY_INTERFACE_PREFIX GCONF_POKY_WALLPAPER,
+ (GConfClientNotifyFunc)wallpaper_notify,
+ data, NULL, NULL);
+
+ return data->bg_ebox;
+}
Added: trunk/src/target/OM-2007.2/applications/openmoko-appearance/src/appearance-background.h
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-appearance/src/appearance-background.h 2007-10-22 17:41:18 UTC (rev 3245)
+++ trunk/src/target/OM-2007.2/applications/openmoko-appearance/src/appearance-background.h 2007-10-22 17:47:55 UTC (rev 3246)
@@ -0,0 +1,31 @@
+/*
+ * OpenMoko Appearance - Change various appearance related settings
+ *
+ * Copyright (C) 2007 by OpenMoko, Inc.
+ * Written by OpenedHand Ltd <info at openedhand.com>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef APPEARANCE_BACKGROUND_H
+#define APPEARANCE_BACKGROUND_H
+
+#include <gtk/gtk.h>
+#include "appearance.h"
+
+GtkWidget * background_page_new (AppearanceData *data);
+
+#endif /* APPEARANCE_BACKGROUND_H */
Modified: trunk/src/target/OM-2007.2/applications/openmoko-appearance/src/appearance-main.c
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-appearance/src/appearance-main.c 2007-10-22 17:41:18 UTC (rev 3245)
+++ trunk/src/target/OM-2007.2/applications/openmoko-appearance/src/appearance-main.c 2007-10-22 17:47:55 UTC (rev 3246)
@@ -21,14 +21,16 @@
*/
#include <gtk/gtk.h>
+#include <gconf/gconf-client.h>
#include "appearance.h"
#include "appearance-colors.h"
+#include "appearance-background.h"
int
main (int argc, char *argv[])
{
AppearanceData *data;
- GtkWidget *window, *notebook, *label, *colors_page, *background_page;
+ GtkWidget *notebook, *icon, *colors_page, *background_page;
/* initialise gtk+ */
gtk_init (&argc, &argv);
@@ -38,12 +40,12 @@
data = g_new0 (AppearanceData, 1);
/* create our main window */
- window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- gtk_window_set_title (GTK_WINDOW (window), "Appearance");
+ data->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title (GTK_WINDOW (data->window), "Appearance");
/* connect the "delete" event of the window to the main quit function
* this causes the program to quit (main loop to exit) when the window is
* closed */
- g_signal_connect (window, "delete-event", G_CALLBACK (gtk_main_quit), NULL);
+ g_signal_connect (data->window, "delete-event", G_CALLBACK (gtk_main_quit), NULL);
/* create a notebook and set the tab position to the bottom of the window */
notebook = gtk_notebook_new ();
@@ -52,28 +54,34 @@
/* Add the notebook to the window
* GtkWindow inherits from GtkContainer, so we can case it as a GtkContainer
* (here using the inbuilt macro) and then use it in gtk_container_* functions */
- gtk_container_add (GTK_CONTAINER (window), notebook);
+ gtk_container_add (GTK_CONTAINER (data->window), notebook);
/* create our "pages" */
colors_page = colors_page_new (data);
- background_page = gtk_label_new ("No background options yet");
+ background_page = background_page_new (data);
/* add the pages to the notebook */
/* colors page */
- label = gtk_label_new ("Colors");
- gtk_notebook_append_page (GTK_NOTEBOOK (notebook), colors_page, label);
+ icon = gtk_image_new_from_stock (GTK_STOCK_SELECT_COLOR, GTK_ICON_SIZE_LARGE_TOOLBAR);
+ gtk_notebook_append_page (GTK_NOTEBOOK (notebook), colors_page, icon);
/* OpenMoko style means we make the tabs as big as possible by setting
* tab-fill to true */
gtk_container_child_set (GTK_CONTAINER (notebook), colors_page, "tab-expand", TRUE, NULL);
/* background page */
- label = gtk_label_new ("Background");
- gtk_notebook_append_page (GTK_NOTEBOOK (notebook), background_page, label);
+ icon = gtk_image_new_from_stock (GTK_STOCK_ORIENTATION_PORTRAIT, GTK_ICON_SIZE_LARGE_TOOLBAR);
+ gtk_notebook_append_page (GTK_NOTEBOOK (notebook), background_page, icon);
gtk_container_child_set (GTK_CONTAINER (notebook), background_page, "tab-expand", TRUE, NULL);
/* display the window and all the widgets inside it */
- gtk_widget_show_all (window);
+ gtk_widget_show_all (data->window);
+ /* select the first notebook page */
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), 0);
+
+ gconf_client_notify (gconf_client_get_default (),
+ GCONF_POKY_INTERFACE_PREFIX GCONF_POKY_WALLPAPER);
+
/* start the main loop */
gtk_main ();
Modified: trunk/src/target/OM-2007.2/applications/openmoko-appearance/src/appearance.h
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-appearance/src/appearance.h 2007-10-22 17:41:18 UTC (rev 3245)
+++ trunk/src/target/OM-2007.2/applications/openmoko-appearance/src/appearance.h 2007-10-22 17:47:55 UTC (rev 3246)
@@ -23,12 +23,20 @@
#ifndef APPEARANCE_H
#define APPEARANCE_H
+#define GCONF_POKY_INTERFACE_PREFIX "/desktop/poky/interface"
+#define GCONF_POKY_WALLPAPER "/wallpaper"
+
typedef struct
{
+ GtkWidget *window;
+
/* colours page */
GtkWidget *colors_combo;
/* background page */
+ GtkWidget *bg_ebox;
+ GtkWidget *bg_chooser;
+ GdkPixmap *wallpaper;
} AppearanceData;
More information about the commitlog
mailing list