desktop swipe is done
[livewp] / applet / src / livewp-main.c
1 /* vim: set sw=4 ts=4 et: */
2 /*
3  * This file is part of Live Wallpaper (livewp)
4  * 
5  * Copyright (C) 2010 Vlad Vasiliev
6  * Copyright (C) 2010 Tanya Makova
7  *       for the code
8  * 
9  * This software is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1 of
12  * the License, or (at your option) any later version.
13  * 
14  * This software is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  * 
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this software; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22  * 02110-1301 USA
23 */
24 /*******************************************************************************/
25 #include "livewp-common.h"
26 #include "livewp-scene.h"
27 #include "livewp-settings.h"
28 #include "livewp-home-widget.h"
29 /*******************************************************************************/
30 #include <X11/extensions/Xrender.h>
31 #include <gdk/gdkx.h>
32
33 #include <X11/Xatom.h>
34
35 void 
36 btn_setting_clicked(HildonButton *btn, gpointer data)
37 {
38     Animation_WallpaperPrivate *priv = data;
39     // open settings dialog
40     fprintf(stderr, "btn setting clicked, %s\n", priv->theme);
41     lw_main_settings(priv, NULL);
42     fprintf(stderr, "btn setting clicked, %s\n", priv->theme);
43 }
44 /*******************************************************************************/
45 void
46 btn_power_clicked(HildonButton *btn, gpointer data)
47 {
48     const gchar *value; 
49     value = hildon_button_get_value(btn);
50     fprintf(stderr, "applet must be %s\n", value);
51     if (!strcmp(value, "stop"))
52         hildon_button_set_text(HILDON_BUTTON(btn), _("Start"), "start");
53     else 
54         hildon_button_set_text(HILDON_BUTTON(btn), _("Stop"), "stop");
55 }
56 /*******************************************************************************/
57 static void set_live_bg (Display *display, Window xwindow, int mode);
58 static 
59 void set_live_bg (Display *display, Window xwindow, int mode)
60 {
61         Atom atom;
62
63         atom = XInternAtom (display, "_HILDON_LIVE_DESKTOP_BACKGROUND", False);
64         fprintf (stderr, "XID: 0x%x\n", (unsigned)xwindow);
65
66         XChangeProperty (display,
67                        xwindow,
68                        atom,
69                        XA_INTEGER, 32, PropModeReplace,
70                        (unsigned char *) &mode, 1);
71 }
72 /*******************************************************************************/
73 void
74 view_changed (GConfClient *client, guint cnxn_id,
75                  GConfEntry *entry, Animation_WallpaperPrivate *priv)
76 {
77     GConfValue *value;
78     value = gconf_entry_get_value (entry);
79     if (value) {
80        if (priv->view == gconf_value_get_int (value))
81            priv->visible = TRUE;
82        else
83            priv->visible = FALSE;
84        if (priv->visible){
85            if (priv->long_timer == 0 ){
86                 priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, priv->desktop_plugin);
87                 run_long_timeout(priv->desktop_plugin);
88            }
89        }else{
90             if (priv->long_timer != 0 ){
91                 g_source_remove(priv->long_timer);
92                 priv->long_timer = 0;
93             }
94        }
95     gconf_value_free(value);
96     }
97 }
98 /*******************************************************************************/
99 void
100 quit_from_program (Animation_WallpaperPrivate *priv)
101 {
102      if (priv){
103              livewp_deinitialize_dbus(priv);
104              if (priv->long_timer){
105                     g_source_remove(priv->long_timer);
106                 priv->long_timer = 0;
107              }
108              if (priv->short_timer){
109                     g_source_remove(priv->short_timer);
110                     priv->short_timer = 0;
111              }
112              destroy_scene(priv->desktop_plugin);
113          if (priv->view_notify != 0)                                                                                                                                   
114             gconf_client_notify_remove (gconf_client_get_default (), priv->view_notify);
115      }
116      gtk_main_quit();;
117 }
118 /*******************************************************************************/
119 int
120 main(int argc, char *argv[])
121 {
122     GtkWidget *main_widget = NULL;
123     GtkWidget *window;
124     GtkWidget *btn_setting, *vbox, *btn_power;
125     gint result;
126     HildonProgram       *app;
127     int view = 1;
128
129      
130     if (argc == 2) 
131         view = atoi(argv[1]);
132     if (view < 1 || view > 4)
133         view = 1;
134
135     AWallpaperPlugin *desktop_plugin = g_new0 (AWallpaperPlugin, 1);
136     Animation_WallpaperPrivate *priv = g_new0 (Animation_WallpaperPrivate, 1);
137     desktop_plugin->priv = priv; 
138
139
140     /* Ininitializing */
141     hildon_gtk_init (&argc, &argv);
142     app = HILDON_PROGRAM (hildon_program_get_instance());
143     g_set_application_name (PACKAGE);
144  
145     priv->osso = osso_initialize("org.maemo.livewp", VERSION, TRUE, NULL);
146     if(!priv->osso){
147         fprintf(stderr,"osso_initialize failed\n");
148         return 1;
149     }
150
151 #ifdef ENABLE_NLS
152     setlocale(LC_ALL, "");
153     bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
154     bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
155     textdomain(GETTEXT_PACKAGE);
156 #endif
157 /* Create Main GUI */
158     main_widget = hildon_window_new ();
159     gtk_window_set_title(GTK_WINDOW(main_widget), PACKAGE);
160     
161     gtk_widget_show_all(GTK_WIDGET(main_widget));
162
163     priv->hash_scene_func = g_hash_table_new(g_str_hash, g_str_equal);
164     g_hash_table_insert(priv->hash_scene_func, g_strdup("Berlin"), (gpointer)&init_scene_Berlin);
165     g_hash_table_insert(priv->hash_scene_func, g_strdup("Modern"), (gpointer)&init_scene_Modern);
166     g_hash_table_insert(priv->hash_scene_func, g_strdup("Matrix"), (gpointer)&init_scene_Matrix);
167
168     priv->scene = NULL;
169     priv->window = main_widget;
170     priv->desktop_plugin = desktop_plugin;
171
172     priv->view = view;
173     /* Load config */
174     read_config(priv);
175     /* Initialize DBUS */
176     livewp_initialize_dbus(priv);
177     set_live_bg(GDK_WINDOW_XDISPLAY (main_widget->window), GDK_WINDOW_XID (main_widget->window), view);
178     if (current_active_view() == view) 
179         priv->visible = TRUE;
180     else 
181         priv->visible = FALSE;
182     
183     priv->view_notify = 0; 
184     fprintf(stderr,"VISIBLE %i %i\n",priv->visible, current_active_view());
185     gconf_client_add_dir(gconf_client_get_default (), "/apps/osso/hildon-desktop/views", GCONF_CLIENT_PRELOAD_NONE, NULL);
186     priv->view_notify = gconf_client_notify_add(gconf_client_get_default (),"/apps/osso/hildon-desktop/views/current",
187                                                 view_changed, priv, NULL, NULL);
188
189     init_scene_theme(desktop_plugin);
190         
191     priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
192
193     gtk_main();
194 }