1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "modest-dimming-rule.h"
32 static void modest_dimming_rule_class_init (ModestDimmingRuleClass *klass);
33 static void modest_dimming_rule_init (ModestDimmingRule *obj);
34 static void modest_dimming_rule_finalize (GObject *obj);
36 typedef struct _ModestDimmingRulePrivate ModestDimmingRulePrivate;
37 struct _ModestDimmingRulePrivate {
39 ModestDimmingCallback dimming_rule;
44 #define MODEST_DIMMING_RULE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
45 MODEST_TYPE_DIMMING_RULE, \
46 ModestDimmingRulePrivate))
49 static GObjectClass *parent_class = NULL;
52 modest_dimming_rule_get_type (void)
54 static GType my_type = 0;
56 static const GTypeInfo my_info = {
57 sizeof(ModestDimmingRuleClass),
59 NULL, /* base finalize */
60 (GClassInitFunc) modest_dimming_rule_class_init,
61 NULL, /* class finalize */
62 NULL, /* class data */
63 sizeof(ModestDimmingRule),
65 (GInstanceInitFunc) modest_dimming_rule_init,
68 my_type = g_type_register_static (G_TYPE_OBJECT,
76 modest_dimming_rule_class_init (ModestDimmingRuleClass *klass)
78 GObjectClass *gobject_class;
79 gobject_class = (GObjectClass*) klass;
81 parent_class = g_type_class_peek_parent (klass);
82 gobject_class->finalize = modest_dimming_rule_finalize;
84 g_type_class_add_private (gobject_class, sizeof(ModestDimmingRulePrivate));
88 modest_dimming_rule_init (ModestDimmingRule *obj)
90 ModestDimmingRulePrivate *priv;
92 priv = MODEST_DIMMING_RULE_GET_PRIVATE(obj);
94 priv->dimming_rule = NULL;
95 priv->action_path = NULL;
96 priv->notification = NULL;
100 modest_dimming_rule_finalize (GObject *obj)
102 ModestDimmingRulePrivate *priv;
104 priv = MODEST_DIMMING_RULE_GET_PRIVATE(obj);
106 if (priv->action_path != NULL)
107 g_free(priv->action_path);
108 if (priv->notification != NULL)
109 g_free(priv->notification);
111 G_OBJECT_CLASS(parent_class)->finalize (obj);
116 modest_dimming_rule_new(ModestWindow *win,
117 ModestDimmingCallback dimming_rule,
118 const gchar *action_path)
120 ModestDimmingRule *obj;
121 ModestDimmingRulePrivate *priv;
123 g_return_val_if_fail (MODEST_IS_WINDOW (win), NULL);
124 g_return_val_if_fail (dimming_rule != NULL, NULL);
125 g_return_val_if_fail (action_path != NULL, NULL);
127 obj = MODEST_DIMMING_RULE(g_object_new(MODEST_TYPE_DIMMING_RULE, NULL));
129 priv = MODEST_DIMMING_RULE_GET_PRIVATE(obj);
131 priv->dimming_rule = dimming_rule;
132 priv->action_path = g_strdup(action_path);
139 modest_dimming_rule_process (ModestDimmingRule *self)
142 ModestDimmingRulePrivate *priv = NULL;
143 GtkAction *action = NULL;
144 gboolean dimmed = FALSE;
146 priv = MODEST_DIMMING_RULE_GET_PRIVATE(self);
147 g_return_if_fail (priv->win != NULL);
148 g_return_if_fail (priv->dimming_rule != NULL);
149 g_return_if_fail (priv->action_path != NULL);
151 /* process dimming rule */
152 dimmed = priv->dimming_rule (priv->win, self);
154 /* Update dimming status */
155 action = modest_window_get_action (priv->win, priv->action_path);
156 g_return_if_fail (action != NULL);
157 gtk_action_set_sensitive (action, !dimmed);
161 modest_dimming_rule_set_notification (ModestDimmingRule *rule,
162 const gchar *notification)
164 ModestDimmingRulePrivate *priv = NULL;
166 g_return_if_fail (MODEST_IS_DIMMING_RULE (rule));
167 priv = MODEST_DIMMING_RULE_GET_PRIVATE(rule);
169 /* Free previous notification */
170 if (priv->notification != NULL)
171 g_free(priv->notification);
173 /* Set new notification message */
174 priv->notification = g_strdup(notification);
178 modest_dimming_rule_get_notification (ModestDimmingRule *rule)
180 ModestDimmingRulePrivate *priv = NULL;
182 g_return_val_if_fail (MODEST_IS_DIMMING_RULE (rule), NULL);
183 priv = MODEST_DIMMING_RULE_GET_PRIVATE(rule);
185 return g_strdup(priv->notification);