[Xfce4-commits] [xfce/xfce4-settings] 06/18: display: Verify unique profile names

noreply at xfce.org noreply at xfce.org
Thu Apr 4 23:03:04 CEST 2019


This is an automated email from the git hooks/post-receive script.

o   c   h   o   s   i       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository xfce/xfce4-settings.

commit 2dfa5611cc8b440b83248c7fafe708e2c0fc18e2
Author: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>
Date:   Fri Mar 29 23:19:37 2019 +0100

    display: Verify unique profile names
---
 common/display-profiles.c                     |  30 +++++++
 common/display-profiles.h                     |   5 +-
 dialogs/display-settings/display-dialog.glade | 125 ++++++++++++++++++++++++++
 dialogs/display-settings/main.c               |  65 +++++---------
 4 files changed, 183 insertions(+), 42 deletions(-)

diff --git a/common/display-profiles.c b/common/display-profiles.c
index da8bbcf..f5ba676 100644
--- a/common/display-profiles.c
+++ b/common/display-profiles.c
@@ -39,6 +39,36 @@ get_size (gchar **i) {
     return num;
 }
 
+gboolean
+display_settings_profile_name_exists (XfconfChannel *channel, const gchar *new_profile_name)
+{
+    GHashTable *properties;
+    GList *channel_contents, *current;
+
+    properties = xfconf_channel_get_properties (channel, NULL);
+    channel_contents = g_hash_table_get_keys (properties);
+
+    /* get all profiles */
+    current = g_list_first (channel_contents);
+    while (current)
+    {
+        gchar **current_elements = g_strsplit (current->data, "/", -1);
+
+        if (get_size (current_elements) != 2)
+        {
+            g_strfreev (current_elements);
+            current = g_list_next (current);
+            continue;
+        }
+
+        if (g_strcmp0 (new_profile_name, xfconf_channel_get_string (channel, current->data, NULL)) == 0)
+            return FALSE;
+
+        current = g_list_next (current);
+    }
+    return TRUE;
+}
+
 GList*
 display_settings_get_profiles (XfceRandr *xfce_randr, XfconfChannel *channel)
 {
diff --git a/common/display-profiles.h b/common/display-profiles.h
index f56f32e..0299964 100644
--- a/common/display-profiles.h
+++ b/common/display-profiles.h
@@ -22,4 +22,7 @@
 #include "xfce-randr.h"
 
 
-GList* display_settings_get_profiles (XfceRandr *xfce_randr, XfconfChannel *channel);
+gboolean display_settings_profile_name_exists   (XfconfChannel *channel,
+                                                 const gchar   *new_profile_name);
+GList*   display_settings_get_profiles          (XfceRandr     *xfce_randr,
+                                                 XfconfChannel *channel);
diff --git a/dialogs/display-settings/display-dialog.glade b/dialogs/display-settings/display-dialog.glade
index 719164c..da5ccdc 100644
--- a/dialogs/display-settings/display-dialog.glade
+++ b/dialogs/display-settings/display-dialog.glade
@@ -872,4 +872,129 @@
       <action-widget response="0">button-close</action-widget>
     </action-widgets>
   </object>
+  <object class="GtkPopover" id="popover-create-profile">
+    <property name="can_focus">False</property>
+    <property name="relative_to">button-profile-create</property>
+    <child>
+      <object class="GtkGrid">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="margin_left">12</property>
+        <property name="margin_right">12</property>
+        <property name="margin_top">12</property>
+        <property name="margin_bottom">24</property>
+        <property name="row_spacing">6</property>
+        <property name="column_spacing">6</property>
+        <child>
+          <object class="GtkLabel">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="label" translatable="yes"><b>Profile Name</b></property>
+            <property name="use_markup">True</property>
+            <property name="xalign">0</property>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkInfoBar" id="profile-exists">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="message_type">error</property>
+            <child internal-child="action_area">
+              <object class="GtkButtonBox">
+                <property name="can_focus">False</property>
+                <property name="spacing">6</property>
+                <property name="layout_style">end</property>
+                <child>
+                  <placeholder/>
+                </child>
+                <child>
+                  <placeholder/>
+                </child>
+                <child>
+                  <placeholder/>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child internal-child="content_area">
+              <object class="GtkBox">
+                <property name="can_focus">False</property>
+                <property name="spacing">16</property>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="can_focus">False</property>
+                    <property name="label" translatable="yes">A profile of this name already exists.</property>
+                  </object>
+                  <packing>
+                    <property name="expand">True</property>
+                    <property name="fill">True</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <placeholder/>
+                </child>
+                <child>
+                  <placeholder/>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">0</property>
+            <property name="width">2</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkEntry" id="entry-profile-create">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="hexpand">True</property>
+            <property name="activates_default">True</property>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">2</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkButton" id="button-profile-create-cb">
+            <property name="label" translatable="yes">Create</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="can_default">True</property>
+            <property name="has_default">True</property>
+            <property name="receives_default">True</property>
+            <style>
+              <class name="suggested-action"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left_attach">1</property>
+            <property name="top_attach">2</property>
+          </packing>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+      </object>
+    </child>
+  </object>
 </interface>
diff --git a/dialogs/display-settings/main.c b/dialogs/display-settings/main.c
index d78e49d..fb97281 100644
--- a/dialogs/display-settings/main.c
+++ b/dialogs/display-settings/main.c
@@ -159,9 +159,6 @@ GList *current_outputs = NULL;
 GtkWidget *randr_outputs_combobox = NULL;
 GtkWidget *apply_button = NULL;
 
-/* New Profile entry */
-GtkWidget *profile_create_entry;
-
 static void display_settings_minimal_only_display1_toggled   (GtkToggleButton *button,
                                                               GtkBuilder      *builder);
 
@@ -1578,8 +1575,19 @@ display_settings_profile_create_cb (GtkWidget *widget, GtkBuilder *builder)
 {
     const gchar *profile_name;
     GtkWidget *popover;
+    GObject *infobar, *entry;
+
+    entry = gtk_builder_get_object (builder, "entry-profile-create");
+    profile_name = gtk_entry_get_text (GTK_ENTRY (entry));
+
+    /* check if the profile name is already taken */
+    if (!display_settings_profile_name_exists (display_channel, profile_name))
+    {
+        infobar = gtk_builder_get_object (builder, "profile-exists");
+        gtk_widget_show_all (GTK_WIDGET (infobar));
+        return;
+    }
 
-    profile_name = gtk_entry_get_text (GTK_ENTRY (profile_create_entry));
     if (profile_name)
     {
         guint i = 0;
@@ -1607,45 +1615,20 @@ display_settings_profile_create_cb (GtkWidget *widget, GtkBuilder *builder)
 static void
 display_settings_profile_create (GtkWidget *widget, GtkBuilder *builder)
 {
-    GtkWidget *popover, *grid, *label, *button;
-    GtkStyleContext *context;
-    const char *str, *format;
-    char *markup;
+    GObject *popover, *entry, *button, *infobar;
 
     /* Create a popover dialog for saving a new profile */
-    popover = gtk_popover_new (widget);
-    gtk_popover_set_modal (GTK_POPOVER (popover), TRUE);
-
-    label = gtk_label_new (NULL);
-    str = _("Profile Name");
-    format = "<b>\%s</b>";
-    markup = g_markup_printf_escaped (format, str);
-    gtk_label_set_markup (GTK_LABEL (label), markup);
-    gtk_label_set_xalign (GTK_LABEL (label), 0.0);
-    g_free (markup);
-    profile_create_entry = gtk_entry_new ();
-    gtk_entry_set_activates_default (GTK_ENTRY (profile_create_entry), TRUE);
-    button = gtk_button_new_with_label (_("Create"));
-    context = gtk_widget_get_style_context (button);
-    gtk_style_context_add_class (context, "suggested-action");
-    gtk_widget_set_can_default (button, TRUE);
-
-    grid = gtk_grid_new ();
-    gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 2, 1);
-    gtk_grid_attach (GTK_GRID (grid), profile_create_entry, 0, 1, 1, 1);
-    gtk_grid_attach (GTK_GRID (grid), button, 1, 1, 1, 1);
-    gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
-    gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
-    gtk_widget_set_margin_start (grid, 12);
-    gtk_widget_set_margin_end (grid, 12);
-    gtk_widget_set_margin_top (grid, 12);
-    gtk_widget_set_margin_bottom (grid, 24);
-    gtk_container_add (GTK_CONTAINER (popover), grid);
-    gtk_widget_show_all (popover);
-    gtk_widget_grab_focus (GTK_WIDGET (profile_create_entry));
-    gtk_widget_grab_default (button);
-
-    g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (display_settings_profile_create_cb), builder);
+    popover = gtk_builder_get_object (builder, "popover-create-profile");
+    entry = gtk_builder_get_object (builder, "entry-profile-create");
+    button = gtk_builder_get_object (builder, "button-profile-create-cb");
+    infobar = gtk_builder_get_object (builder, "profile-exists");
+
+    gtk_widget_show (GTK_WIDGET (popover));
+    gtk_widget_hide (GTK_WIDGET (infobar));
+    gtk_widget_grab_focus (GTK_WIDGET (entry));
+    gtk_widget_grab_default (GTK_WIDGET (button));
+
+    g_signal_connect (button, "clicked", G_CALLBACK (display_settings_profile_create_cb), builder);
 }
 
 static void

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list