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;
43 #define MODEST_DIMMING_RULE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
44 MODEST_TYPE_DIMMING_RULE, \
45 ModestDimmingRulePrivate))
48 static GObjectClass *parent_class = NULL;
51 modest_dimming_rule_get_type (void)
53 static GType my_type = 0;
55 static const GTypeInfo my_info = {
56 sizeof(ModestDimmingRuleClass),
58 NULL, /* base finalize */
59 (GClassInitFunc) modest_dimming_rule_class_init,
60 NULL, /* class finalize */
61 NULL, /* class data */
62 sizeof(ModestDimmingRule),
64 (GInstanceInitFunc) modest_dimming_rule_init,
67 my_type = g_type_register_static (G_TYPE_OBJECT,
75 modest_dimming_rule_class_init (ModestDimmingRuleClass *klass)
77 GObjectClass *gobject_class;
78 gobject_class = (GObjectClass*) klass;
80 parent_class = g_type_class_peek_parent (klass);
81 gobject_class->finalize = modest_dimming_rule_finalize;
83 g_type_class_add_private (gobject_class, sizeof(ModestDimmingRulePrivate));
87 modest_dimming_rule_init (ModestDimmingRule *obj)
89 ModestDimmingRulePrivate *priv;
91 priv = MODEST_DIMMING_RULE_GET_PRIVATE(obj);
93 priv->dimming_rule = NULL;
94 priv->action_path = NULL;
98 modest_dimming_rule_finalize (GObject *obj)
100 ModestDimmingRulePrivate *priv;
102 priv = MODEST_DIMMING_RULE_GET_PRIVATE(obj);
104 if (priv->action_path != NULL)
105 g_free(priv->action_path);
107 G_OBJECT_CLASS(parent_class)->finalize (obj);
112 modest_dimming_rule_new(ModestWindow *win,
113 ModestDimmingCallback dimming_rule,
114 const gchar *action_path)
116 ModestDimmingRule *obj;
117 ModestDimmingRulePrivate *priv;
119 g_return_val_if_fail (MODEST_IS_WINDOW (win), NULL);
120 g_return_val_if_fail (dimming_rule != NULL, NULL);
121 g_return_val_if_fail (action_path != NULL, NULL);
123 obj = MODEST_DIMMING_RULE(g_object_new(MODEST_TYPE_DIMMING_RULE, NULL));
125 priv = MODEST_DIMMING_RULE_GET_PRIVATE(obj);
127 priv->dimming_rule = dimming_rule;
128 priv->action_path = g_strdup(action_path);
135 modest_dimming_rule_process (ModestDimmingRule *self)
138 ModestDimmingRulePrivate *priv = NULL;
139 GtkAction *action = NULL;
140 gboolean dimmed = FALSE;
142 priv = MODEST_DIMMING_RULE_GET_PRIVATE(self);
143 g_return_if_fail (priv->win != NULL);
144 g_return_if_fail (priv->dimming_rule != NULL);
145 g_return_if_fail (priv->action_path != NULL);
147 /* process dimming rule */
148 dimmed = priv->dimming_rule (priv->win, NULL);
150 /* Update dimming status */
151 action = modest_window_get_action (priv->win, priv->action_path);
152 g_return_if_fail (action != NULL);
153 gtk_action_set_sensitive (action, !dimmed);