Initial Import
[profile/ivi/clutter-toys.git] / attic / astro-desktop / applications / example / astro-example.c
1 /*
2  * Copyright (C) 2007 OpenedHand Limited
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  *
19  * Author: Neil Jagdish Patel <njp@o-hand.com>
20  */
21
22
23 #include "astro-example.h"
24
25 #include <libastro-desktop/astro-defines.h>
26 #include <libastro-desktop/astro-application.h>
27 #include <libastro-desktop/astro-window.h>
28
29 G_DEFINE_TYPE (AstroExample2, astro_example2, ASTRO_TYPE_APPLICATION);
30
31 #define ASTRO_EXAMPLE2_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj),\
32         ASTRO_TYPE_EXAMPLE2, AstroExample2Private))
33         
34 struct _AstroExample2Private
35 {
36   const gchar *title;
37   GdkPixbuf *icon;
38   ClutterActor *window;
39 };
40
41 /* Public Functions */
42
43 /* Private functions */
44 static const gchar *
45 get_title (AstroApplication *app)
46 {
47   g_return_val_if_fail (ASTRO_IS_EXAMPLE2 (app), NULL);
48
49   return ASTRO_EXAMPLE2 (app)->priv->title;
50 }
51
52 static void
53 set_title (AstroApplication *app, const gchar *title)
54 {
55   g_return_if_fail (ASTRO_IS_EXAMPLE2 (app));
56   g_return_if_fail (title);
57
58   ASTRO_EXAMPLE2 (app)->priv->title = g_strdup (title);
59 }
60
61 static GdkPixbuf *
62 get_icon (AstroApplication *app)
63 {
64   g_return_val_if_fail (ASTRO_IS_EXAMPLE2 (app), NULL);
65
66   return ASTRO_EXAMPLE2 (app)->priv->icon;
67 }
68
69 static void
70 set_icon (AstroApplication *app, GdkPixbuf *icon)
71 {
72   g_return_if_fail (ASTRO_IS_EXAMPLE2 (app));
73   g_return_if_fail (GDK_IS_PIXBUF (icon));
74
75   ASTRO_EXAMPLE2 (app)->priv->icon = icon;
76 }
77
78 static AstroWindow *
79 get_window (AstroApplication *app)
80 {
81   AstroExample2Private *priv;
82   ClutterColor color = { 0xff, 0xff, 0x22, 0x22 };
83   ClutterActor *window = NULL, *rect;
84
85   g_return_val_if_fail (ASTRO_IS_EXAMPLE2 (app), NULL);
86   priv = ASTRO_EXAMPLE2 (app)->priv;
87
88   if (CLUTTER_IS_ACTOR (priv->window))
89     window = priv->window;
90   else
91     {
92       window = astro_window_new ();
93       
94       rect = clutter_rectangle_new_with_color (&color);
95       clutter_container_add_actor (CLUTTER_CONTAINER (window), rect);
96       clutter_actor_set_size (rect, CSW (), CSH()-ASTRO_PANEL_HEIGHT());
97       clutter_actor_show (rect);
98     }
99
100   ASTRO_EXAMPLE2 (app)->priv->window = window;
101
102   return ASTRO_WINDOW (window);
103 }
104
105 static void
106 close (AstroApplication *app)
107 {
108   AstroExample2Private *priv;
109   
110   g_return_if_fail (ASTRO_IS_EXAMPLE2 (app));
111   priv = ASTRO_EXAMPLE2 (app)->priv;
112   
113   if (CLUTTER_IS_ACTOR (priv->window))
114     clutter_actor_destroy (priv->window);
115 }
116
117 /* GObject stuff */
118 static void
119 astro_example2_class_init (AstroExample2Class *klass)
120 {
121   GObjectClass        *gobject_class = G_OBJECT_CLASS (klass);
122   AstroApplicationClass *app_class = ASTRO_APPLICATION_CLASS (klass);
123
124   app_class->get_title = get_title;
125   app_class->set_title = set_title;
126   app_class->get_icon = get_icon;
127   app_class->set_icon = set_icon;
128   app_class->get_window = get_window;
129   app_class->close = close;
130
131   g_type_class_add_private (gobject_class, sizeof (AstroExample2Private));
132 }
133
134 static void
135 astro_example2_init (AstroExample2 *example2)
136 {
137   AstroExample2Private *priv;
138   priv = example2->priv = ASTRO_EXAMPLE2_GET_PRIVATE (example2);
139
140   priv->title = NULL;
141   priv->icon = NULL;
142   priv->window = NULL;
143 }
144
145 AstroApplication * 
146 astro_example2_new (const gchar *title, GdkPixbuf *icon)
147 {
148   AstroApplication *example2 =  g_object_new (ASTRO_TYPE_EXAMPLE2,
149                                                                                                NULL);
150
151   astro_application_set_title (example2, title);
152   astro_application_set_icon (example2, icon);
153
154   return example2;
155 }
156