[evolution/wip/webkit2] Bug 761301 - Option to Create events, memos and tasks as Private by default



commit a5a90cf51ac4df822aeb088f64238da6afadd25d
Author: Milan Crha <mcrha redhat com>
Date:   Tue Feb 23 21:10:34 2016 +0100

    Bug 761301 - Option to Create events, memos and tasks as Private by default

 calendar/gui/e-cal-model.c                       |   38 ++++++++++++++++------
 calendar/gui/e-cal-ops.c                         |   18 ++++++++++
 calendar/gui/e-comp-editor-event.c               |   22 +++++++++---
 calendar/gui/e-comp-editor-property-parts.c      |   15 ++++++++-
 data/org.gnome.evolution.calendar.gschema.xml.in |    4 ++
 modules/calendar/e-calendar-preferences.c        |    6 +++
 modules/calendar/e-calendar-preferences.ui       |   33 ++++++++++++++++++-
 7 files changed, 118 insertions(+), 18 deletions(-)
---
diff --git a/calendar/gui/e-cal-model.c b/calendar/gui/e-cal-model.c
index ad1cdfd..19c649d 100644
--- a/calendar/gui/e-cal-model.c
+++ b/calendar/gui/e-cal-model.c
@@ -505,16 +505,16 @@ set_classification (ECalModelComponent *comp_data,
                        icalproperty_free (prop);
                }
        } else {
-         icalproperty_class ical_class;
-
-         if (!g_ascii_strcasecmp (value, "PUBLIC"))
-           ical_class = ICAL_CLASS_PUBLIC;
-         else if (!g_ascii_strcasecmp (value, "PRIVATE"))
-           ical_class = ICAL_CLASS_PRIVATE;
-         else if (!g_ascii_strcasecmp (value, "CONFIDENTIAL"))
-           ical_class = ICAL_CLASS_CONFIDENTIAL;
-         else
-           ical_class = ICAL_CLASS_NONE;
+               icalproperty_class ical_class;
+
+               if (!g_ascii_strcasecmp (value, "PUBLIC"))
+                       ical_class = ICAL_CLASS_PUBLIC;
+               else if (!g_ascii_strcasecmp (value, "PRIVATE"))
+                       ical_class = ICAL_CLASS_PRIVATE;
+               else if (!g_ascii_strcasecmp (value, "CONFIDENTIAL"))
+                       ical_class = ICAL_CLASS_CONFIDENTIAL;
+               else
+                       ical_class = ICAL_CLASS_NONE;
 
                if (!prop) {
                        prop = icalproperty_new_class (ical_class);
@@ -1385,6 +1385,7 @@ cal_model_create_component_from_values_thread (EAlertSinkThreadJobData *job_data
        ESource *source;
        EClient *client;
        ECalModelComponent *comp_data;
+       icalproperty *prop;
        const gchar *source_uid;
        gchar *display_name;
        GError *local_error = NULL;
@@ -1459,6 +1460,23 @@ cal_model_create_component_from_values_thread (EAlertSinkThreadJobData *job_data
                        model_class->fill_component_from_values (ccd->model, comp_data, ccd->values);
                }
 
+               prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_CLASS_PROPERTY);
+               if (!prop || icalproperty_get_class (prop) == ICAL_CLASS_NONE) {
+                       icalproperty_class ical_class = ICAL_CLASS_PUBLIC;
+                       GSettings *settings;
+
+                       settings = e_util_ref_settings ("org.gnome.evolution.calendar");
+                       if (g_settings_get_boolean (settings, "classify-private"))
+                               ical_class = ICAL_CLASS_PRIVATE;
+                       g_object_unref (settings);
+
+                       if (!prop) {
+                               prop = icalproperty_new_class (ical_class);
+                               icalcomponent_add_property (comp_data->icalcomp, prop);
+                       } else
+                               icalproperty_set_class (prop, ical_class);
+               }
+
                ccd->success = e_cal_client_create_object_sync (comp_data->client, comp_data->icalcomp, &uid, 
cancellable, error);
 
                g_free (uid);
diff --git a/calendar/gui/e-cal-ops.c b/calendar/gui/e-cal-ops.c
index a3f014c..8d497dd 100644
--- a/calendar/gui/e-cal-ops.c
+++ b/calendar/gui/e-cal-ops.c
@@ -171,6 +171,7 @@ e_cal_ops_create_component (ECalModel *model,
 {
        ECalDataModel *data_model;
        ESource *source;
+       icalproperty *prop;
        const gchar *description;
        const gchar *alert_ident;
        gchar *display_name;
@@ -210,6 +211,23 @@ e_cal_ops_create_component (ECalModel *model,
        bod->user_data = user_data;
        bod->user_data_free = user_data_free;
 
+       prop = icalcomponent_get_first_property (bod->icalcomp, ICAL_CLASS_PROPERTY);
+       if (!prop || icalproperty_get_class (prop) == ICAL_CLASS_NONE) {
+               icalproperty_class ical_class = ICAL_CLASS_PUBLIC;
+               GSettings *settings;
+
+               settings = e_util_ref_settings ("org.gnome.evolution.calendar");
+               if (g_settings_get_boolean (settings, "classify-private"))
+                       ical_class = ICAL_CLASS_PRIVATE;
+               g_object_unref (settings);
+
+               if (!prop) {
+                       prop = icalproperty_new_class (ical_class);
+                       icalcomponent_add_property (bod->icalcomp, prop);
+               } else
+                       icalproperty_set_class (prop, ical_class);
+       }
+
        display_name = e_util_get_source_full_name (e_cal_model_get_registry (model), source);
        cancellable = e_cal_data_model_submit_thread_job (data_model, description, alert_ident,
                display_name, cal_ops_create_component_thread,
diff --git a/calendar/gui/e-comp-editor-event.c b/calendar/gui/e-comp-editor-event.c
index db28281..2d161c2 100644
--- a/calendar/gui/e-comp-editor-event.c
+++ b/calendar/gui/e-comp-editor-event.c
@@ -230,6 +230,7 @@ ece_event_fill_widgets (ECompEditor *comp_editor,
        icaltimezone *zone = NULL;
        gboolean all_day_event = FALSE;
        GtkAction *action;
+       guint32 flags;
 
        g_return_if_fail (E_IS_COMP_EDITOR_EVENT (comp_editor));
        g_return_if_fail (component != NULL);
@@ -238,6 +239,7 @@ ece_event_fill_widgets (ECompEditor *comp_editor,
 
        event_editor = E_COMP_EDITOR_EVENT (comp_editor);
 
+       flags = e_comp_editor_get_flags (comp_editor);
        dtstart = icaltime_null_time ();
        dtend = icaltime_null_time ();
 
@@ -262,10 +264,8 @@ ece_event_fill_widgets (ECompEditor *comp_editor,
        }
 
        if (zone) {
-               ECompEditorEvent *event_editor;
                GtkWidget *edit_widget;
 
-               event_editor = E_COMP_EDITOR_EVENT (comp_editor);
                edit_widget = e_comp_editor_property_part_get_edit_widget (event_editor->priv->timezone);
 
                e_timezone_entry_set_timezone (E_TIMEZONE_ENTRY (edit_widget), zone);
@@ -287,8 +287,6 @@ ece_event_fill_widgets (ECompEditor *comp_editor,
        }
 
        if (icaltime_is_valid_time (dtend) && !icaltime_is_null_time (dtend)) {
-               ECompEditorEvent *event_editor;
-
                if (dtstart.is_date && dtend.is_date) {
                        all_day_event = TRUE;
                        if (icaltime_compare_date_only (dtend, dtstart) > 0) {
@@ -296,7 +294,6 @@ ece_event_fill_widgets (ECompEditor *comp_editor,
                        }
                }
 
-               event_editor = E_COMP_EDITOR_EVENT (comp_editor);
                e_comp_editor_property_part_datetime_set_value (
                        E_COMP_EDITOR_PROPERTY_PART_DATETIME (event_editor->priv->dtend), dtend);
        }
@@ -308,8 +305,21 @@ ece_event_fill_widgets (ECompEditor *comp_editor,
                action = e_comp_editor_get_action (comp_editor, "classify-private");
        else if (prop && icalproperty_get_class (prop) == ICAL_CLASS_CONFIDENTIAL)
                action = e_comp_editor_get_action (comp_editor, "classify-confidential");
-       else
+       else if (!(flags & E_COMP_EDITOR_FLAG_IS_NEW))
                action = e_comp_editor_get_action (comp_editor, "classify-public");
+       else {
+               GSettings *settings;
+
+               settings = e_util_ref_settings ("org.gnome.evolution.calendar");
+
+               if (g_settings_get_boolean (settings, "classify-private")) {
+                       action = e_comp_editor_get_action (comp_editor, "classify-private");
+               } else {
+                       action = e_comp_editor_get_action (comp_editor, "classify-public");
+               }
+
+               g_object_unref (settings);
+       }
 
        gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
 }
diff --git a/calendar/gui/e-comp-editor-property-parts.c b/calendar/gui/e-comp-editor-property-parts.c
index 51e62e8..91d805a 100644
--- a/calendar/gui/e-comp-editor-property-parts.c
+++ b/calendar/gui/e-comp-editor-property-parts.c
@@ -1134,18 +1134,31 @@ e_comp_editor_property_part_classification_new (void)
                { ICAL_CLASS_PRIVATE,      NC_("ECompEditor", "Private"),      FALSE, NULL },
                { ICAL_CLASS_CONFIDENTIAL, NC_("ECompEditor", "Confidential"), FALSE, NULL }
        };
+       GSettings *settings;
+       ECompEditorPropertyPart *part;
+       gboolean classify_private;
        gint ii, n_elems = G_N_ELEMENTS (map);
 
        for (ii = 0; ii < n_elems; ii++) {
                map[ii].description = g_dpgettext2 (GETTEXT_PACKAGE, "ECompEditor", map[ii].description);
        }
 
-       return e_comp_editor_property_part_picker_with_map_new (map, n_elems,
+       settings = e_util_ref_settings ("org.gnome.evolution.calendar");
+       classify_private = g_settings_get_boolean (settings, "classify-private");
+       g_object_unref (settings);
+
+       part = e_comp_editor_property_part_picker_with_map_new (map, n_elems,
                C_("ECompEditor", "C_lassification:"),
                ICAL_CLASS_PROPERTY,
                (ECompEditorPropertyPartPickerMapICalNewFunc) icalproperty_new_class,
                (ECompEditorPropertyPartPickerMapICalSetFunc) icalproperty_set_class,
                (ECompEditorPropertyPartPickerMapICalGetFunc) icalproperty_get_class);
+
+       e_comp_editor_property_part_picker_with_map_set_selected (
+               E_COMP_EDITOR_PROPERTY_PART_PICKER_WITH_MAP (part),
+               classify_private ? ICAL_CLASS_PRIVATE : ICAL_CLASS_PUBLIC);
+
+       return part;
 }
 
 /* ************************************************************************* */
diff --git a/data/org.gnome.evolution.calendar.gschema.xml.in 
b/data/org.gnome.evolution.calendar.gschema.xml.in
index 95f6304..8663b91 100644
--- a/data/org.gnome.evolution.calendar.gschema.xml.in
+++ b/data/org.gnome.evolution.calendar.gschema.xml.in
@@ -451,6 +451,10 @@
       <default>false</default>
       <_summary>Sunday is a work day</_summary>
     </key>
+    <key name="classify-private" type="b">
+      <default>false</default>
+      <_summary>Create events, memos and tasks as Private by default</_summary>
+    </key>
 
     <!-- The following keys are deprecated. -->
 
diff --git a/modules/calendar/e-calendar-preferences.c b/modules/calendar/e-calendar-preferences.c
index 9e1645d..63bc7c9 100644
--- a/modules/calendar/e-calendar-preferences.c
+++ b/modules/calendar/e-calendar-preferences.c
@@ -874,6 +874,12 @@ calendar_preferences_construct (ECalendarPreferences *prefs,
                widget, "sensitive",
                G_SETTINGS_BIND_GET);
 
+       widget = e_builder_get_widget (prefs->builder, "classify-private");
+       g_settings_bind (
+               settings, "classify-private",
+               widget, "active",
+               G_SETTINGS_BIND_DEFAULT);
+
        /* These settings control the "Birthdays & Anniversaries" backend. */
 
        eds_settings =
diff --git a/modules/calendar/e-calendar-preferences.ui b/modules/calendar/e-calendar-preferences.ui
index 2b17953..a2fe263 100644
--- a/modules/calendar/e-calendar-preferences.ui
+++ b/modules/calendar/e-calendar-preferences.ui
@@ -705,13 +705,44 @@
           </packing>
         </child>
         <child>
+          <object class="GtkLabel" id="misc-label1">
+            <property name="visible">True</property>
+            <property name="xalign">0</property>
+            <property name="label" translatable="yes">Miscellaneous</property>
+            <attributes>
+              <attribute name="weight" value="bold"/>
+            </attributes>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">6</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkCheckButton" id="classify-private">
+            <property name="label" translatable="yes">Create events, memos and tasks as _Private by 
default</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">False</property>
+            <property name="use_underline">True</property>
+            <property name="draw_indicator">True</property>
+            <property name="margin-left">12</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">7</property>
+          </packing>
+        </child>
+        <child>
           <object class="GtkLabel" id="general-space-label">
             <property name="visible">True</property>
           </object>
           <packing>
             <property name="expand">True</property>
             <property name="fill">True</property>
-            <property name="position">6</property>
+            <property name="position">8</property>
           </packing>
         </child>
       </object>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]