This is a manual merge of branch drop split view intro trunk.
[modest] / src / modest-dimming-rule.c
index 4b7f13b..61e40c6 100644 (file)
@@ -35,9 +35,11 @@ static void modest_dimming_rule_finalize   (GObject *obj);
 
 typedef struct _ModestDimmingRulePrivate ModestDimmingRulePrivate;
 struct _ModestDimmingRulePrivate {
+       ModestDimmingRulesGroup *group;
        ModestWindow *win;
        ModestDimmingCallback dimming_rule;
        gchar *action_path;
+       GtkWidget *widget;
        gchar *notification;
 };
 
@@ -90,9 +92,11 @@ modest_dimming_rule_init (ModestDimmingRule *obj)
        ModestDimmingRulePrivate *priv;
 
        priv = MODEST_DIMMING_RULE_GET_PRIVATE(obj);
+       priv->group= NULL;
        priv->win = NULL;
        priv->dimming_rule = NULL;
        priv->action_path = NULL;
+       priv->widget = NULL;
        priv->notification = NULL;
 }
 
@@ -103,6 +107,8 @@ modest_dimming_rule_finalize (GObject *obj)
 
        priv = MODEST_DIMMING_RULE_GET_PRIVATE(obj);
 
+       if (priv->group != NULL)
+               g_object_unref(priv->group);
        if (priv->action_path != NULL)
                g_free(priv->action_path);
        if (priv->notification != NULL)
@@ -134,6 +140,28 @@ modest_dimming_rule_new(ModestWindow *win,
        return obj;
 }
 
+ModestDimmingRule*
+modest_dimming_rule_new_from_widget (ModestWindow *win,
+                                    ModestDimmingCallback dimming_rule,
+                                    GtkWidget *widget)
+{
+       ModestDimmingRule *obj;
+       ModestDimmingRulePrivate *priv;
+               
+       g_return_val_if_fail (MODEST_IS_WINDOW (win), NULL);
+       g_return_val_if_fail (dimming_rule != NULL, NULL);
+       g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
+                             
+       obj = MODEST_DIMMING_RULE(g_object_new(MODEST_TYPE_DIMMING_RULE, NULL));
+
+       priv = MODEST_DIMMING_RULE_GET_PRIVATE(obj);
+       priv->win = win;
+       priv->dimming_rule = dimming_rule;
+       priv->widget = widget;
+
+       return obj;
+}
+
 
 void
 modest_dimming_rule_process (ModestDimmingRule *self)
@@ -146,15 +174,61 @@ modest_dimming_rule_process (ModestDimmingRule *self)
        priv = MODEST_DIMMING_RULE_GET_PRIVATE(self);
        g_return_if_fail (priv->win != NULL);
        g_return_if_fail (priv->dimming_rule != NULL);
-       g_return_if_fail (priv->action_path != NULL);
+       g_return_if_fail ((priv->action_path != NULL)|| GTK_IS_WIDGET (priv->widget));
 
        /* process dimming rule */
        dimmed = priv->dimming_rule (priv->win, self);
 
        /* Update dimming status */
-        action = modest_window_get_action (priv->win, priv->action_path);      
-       g_return_if_fail (action != NULL);
-       gtk_action_set_sensitive (action, !dimmed);
+       if (priv->action_path != NULL) {
+               action = modest_window_get_action (priv->win, priv->action_path);       
+               if (action != NULL)
+                       gtk_action_set_sensitive (action, !dimmed);
+               else
+                       g_printerr ("modest: action path '%s' has not associatd action\n", priv->action_path);
+       } else if (priv->widget != NULL) {
+#ifdef MODEST_TOOLKIT_HILDON2
+               if (GTK_IS_TOOL_ITEM (priv->widget)) {
+                       gtk_widget_set_sensitive (priv->widget, !dimmed);
+               } else {
+                       if (dimmed)
+                               gtk_widget_hide (priv->widget);
+                       else
+                               gtk_widget_show (priv->widget);
+               }
+#else
+               gtk_widget_set_sensitive (priv->widget, !dimmed);
+#endif
+       }
+}
+
+void
+modest_dimming_rule_set_group (ModestDimmingRule *rule,
+                              ModestDimmingRulesGroup *group)
+{
+       ModestDimmingRulePrivate *priv = NULL;
+
+       g_return_if_fail (MODEST_IS_DIMMING_RULE (rule));
+       g_return_if_fail (MODEST_IS_DIMMING_RULES_GROUP (group));
+       priv = MODEST_DIMMING_RULE_GET_PRIVATE(rule);
+
+       if (priv->group == group) 
+               return;
+       if (priv->group != NULL) 
+               g_object_unref (priv->group);
+       priv->group = g_object_ref (group);                     
+}      
+
+ModestDimmingRulesGroup *
+modest_dimming_rule_get_group (ModestDimmingRule *rule)
+{
+       ModestDimmingRulePrivate *priv = NULL;
+       
+       g_return_val_if_fail (MODEST_IS_DIMMING_RULE (rule), NULL);
+       priv = MODEST_DIMMING_RULE_GET_PRIVATE(rule);
+       g_return_val_if_fail (MODEST_IS_DIMMING_RULES_GROUP (priv->group), NULL);
+       
+       return g_object_ref(priv->group);
 }
 
 void
@@ -167,11 +241,14 @@ modest_dimming_rule_set_notification (ModestDimmingRule *rule,
        priv = MODEST_DIMMING_RULE_GET_PRIVATE(rule);
        
        /* Free previous notification */
-       if (priv->notification != NULL)
+       if (priv->notification != NULL) {
                g_free(priv->notification);
+               priv->notification = NULL;
+       }
 
        /* Set new notification message */
-       priv->notification = g_strdup(notification);
+       if (notification != NULL)
+               priv->notification = g_strdup(notification);
 }
 
 gchar *
@@ -184,3 +261,28 @@ modest_dimming_rule_get_notification (ModestDimmingRule *rule)
        
        return g_strdup(priv->notification);
 }
+
+GtkWidget *
+modest_dimming_rule_get_widget (ModestDimmingRule *rule)
+{
+       ModestDimmingRulePrivate *priv = NULL;
+
+       g_return_val_if_fail (MODEST_IS_DIMMING_RULE (rule), NULL);
+       priv = MODEST_DIMMING_RULE_GET_PRIVATE(rule);
+
+       if (priv->action_path != NULL)
+               return modest_window_get_action_widget (MODEST_WINDOW (priv->win), priv->action_path);
+       else
+               return priv->widget;
+}
+
+const gchar *
+modest_dimming_rule_get_action_path (ModestDimmingRule *rule)
+{
+       ModestDimmingRulePrivate *priv = NULL;
+
+       g_return_val_if_fail (MODEST_IS_DIMMING_RULE (rule), NULL);
+       priv = MODEST_DIMMING_RULE_GET_PRIVATE(rule);
+
+       return priv->action_path;
+}