/* * This file is part of Maemo Examples * * Copyright (C) 2005 Nokia Corporation. * * * This software is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * */ #include #include #include #include #include #define GCONF_KEY "/apps/example_prefs/title" /* Application UI data struct */ typedef struct _AppData AppData; struct _AppData { HildonProgram *program; HildonWindow *window; }; void commit_entry_data_callback(GtkWidget* entry) { GConfClient* client; HildonProgram *program; gchar* str; str = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1); client = g_object_get_data(G_OBJECT (entry), "client"); gconf_client_set_string(client, GCONF_KEY, str, NULL ); program = g_object_get_data (G_OBJECT (entry), "program"); if (str != NULL && *str != '\0') g_set_application_name(str); g_free(str); return ; } int main(int argc, char *argv[]) { /* Announce vars */ HildonProgram *program; HildonWindow *window; GtkWidget *entry, *label, *hbox; GConfClient *client; /* Initialize GTK. */ gtk_init(&argc, &argv); /* Get the default client */ client = gconf_client_get_default(); /*Add GConf node if absent*/ gconf_client_add_dir (client, "/apps/example_prefs", GCONF_CLIENT_PRELOAD_NONE, NULL); /* Read title */ gchar *title = gconf_client_get_string(client, GCONF_KEY, NULL); /* Create the hildon program and setup the title */ program = HILDON_PROGRAM(hildon_program_get_instance()); if (title != NULL) { g_set_application_name(title); } /* Create HildonWindow and set it to HildonProgram */ window = HILDON_WINDOW(hildon_window_new()); hildon_program_add_window(program, window); /* Create buttons and add it to main view */ hbox = gtk_hbox_new(FALSE, 5); label = gtk_label_new ("Change window title: "); entry = gtk_entry_new(); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); gtk_box_pack_end (GTK_BOX (hbox), entry, FALSE, FALSE, 0); g_object_set_data (G_OBJECT (entry), "client", client); g_object_set_data (G_OBJECT (entry), "program", program); g_signal_connect(G_OBJECT(entry), "focus_out_event", G_CALLBACK(commit_entry_data_callback), client); g_signal_connect(G_OBJECT(entry), "activate", G_CALLBACK(commit_entry_data_callback), client); if (title) { gtk_entry_set_text (GTK_ENTRY (entry), title); } g_free (title); gtk_widget_set_sensitive (entry, gconf_client_key_is_writable (client,GCONF_KEY, NULL)); gtk_container_add (GTK_CONTAINER (window), hbox); /* Connect signal to X in the upper corner */ g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(gtk_main_quit), NULL); /* Begin the main application */ gtk_widget_show_all(GTK_WIDGET(window)); gtk_main(); /* Exit */ g_object_unref (G_OBJECT (client)); return 0; }