Commit 2f885a51 authored by Marcus Comstedt's avatar Marcus Comstedt Committed by Simon Steinbeiss
Browse files

action buttons: Add button title options (Bug #8980)

Co-Author: Simon Steinbeiss <simon.steinbeiss@elfenbeinturm.at>
parent 46a74eee
Loading
Loading
Loading
Loading
Loading
+111 −14
Original line number Diff line number Diff line
@@ -39,6 +39,26 @@
      </row>
    </data>
  </object>
  <object class="GtkListStore" id="title-store">
    <columns>
      <!-- column-name title -->
      <column type="gchararray"/>
    </columns>
    <data>
      <row>
        <col id="0" translatable="yes">Full Name</col>
      </row>
      <row>
        <col id="0" translatable="yes">Username</col>
      </row>
      <row>
        <col id="0" translatable="yes">User ID</col>
      </row>
      <row>
        <col id="0" translatable="yes">Custom</col>
      </row>
    </data>
  </object>
  <object class="XfceTitledDialog" id="dialog">
    <property name="can_focus">False</property>
    <property name="title" translatable="yes">Action Buttons</property>
@@ -135,14 +155,88 @@
                      </packing>
                    </child>
                    <child>
                      <object class="GtkCheckButton" id="invert-orientation">
                        <property name="label" translatable="yes">Invert buttons _orientation</property>
                        <property name="use_action_appearance">False</property>
                      <object class="GtkLabel" id="label3">
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">False</property>
                        <property name="can_focus">False</property>
                        <property name="label" translatable="yes">Appeara_nce:</property>
                        <property name="use_underline">True</property>
                        <property name="draw_indicator">True</property>
                        <property name="xalign">0</property>
                      </object>
                      <packing>
                        <property name="left_attach">0</property>
                        <property name="top_attach">0</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkRevealer" id="revealer-title">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="reveal_child">True</property>
                        <child>
                          <object class="GtkGrid">
                            <property name="visible">True</property>
                            <property name="can_focus">False</property>
                            <property name="hexpand">True</property>
                            <property name="row_spacing">6</property>
                            <property name="column_spacing">12</property>
                            <child>
                              <object class="GtkLabel" id="label-title">
                                <property name="visible">True</property>
                                <property name="can_focus">False</property>
                                <property name="label" translatable="yes">Title:</property>
                                <property name="use_underline">True</property>
                                <property name="xalign">0</property>
                              </object>
                              <packing>
                                <property name="left_attach">0</property>
                                <property name="top_attach">0</property>
                              </packing>
                            </child>
                            <child>
                              <object class="GtkLabel" id="label-cust-title">
                                <property name="visible">True</property>
                                <property name="can_focus">False</property>
                                <property name="label" translatable="yes">Custo_m title:</property>
                                <property name="use_underline">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="GtkComboBox" id="combo-title">
                                <property name="visible">True</property>
                                <property name="can_focus">False</property>
                                <property name="hexpand">True</property>
                                <property name="model">title-store</property>
                                <child>
                                  <object class="GtkCellRendererText" id="cellrenderertext3"/>
                                  <attributes>
                                    <attribute name="text">0</attribute>
                                  </attributes>
                                </child>
                              </object>
                              <packing>
                                <property name="left_attach">1</property>
                                <property name="top_attach">0</property>
                              </packing>
                            </child>
                            <child>
                              <object class="GtkEntry" id="entry-cust-title">
                                <property name="visible">True</property>
                                <property name="can_focus">True</property>
                                <property name="hexpand">True</property>
                                <property name="invisible_char"></property>
                              </object>
                              <packing>
                                <property name="left_attach">1</property>
                                <property name="top_attach">1</property>
                              </packing>
                            </child>
                          </object>
                        </child>
                      </object>
                      <packing>
                        <property name="left_attach">0</property>
@@ -151,13 +245,12 @@
                      </packing>
                    </child>
                    <child>
                      <object class="GtkCheckButton" id="confirmation-dialog">
                        <property name="label" translatable="yes">_Show confirmation dialog</property>
                      <object class="GtkCheckButton" id="invert-orientation">
                        <property name="label" translatable="yes">Invert buttons _orientation</property>
                        <property name="use_action_appearance">False</property>
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">False</property>
                        <property name="tooltip_text" translatable="yes">Show a confirmation dialog with a 30 second timeout for some of the actions.</property>
                        <property name="use_underline">True</property>
                        <property name="draw_indicator">True</property>
                      </object>
@@ -168,16 +261,20 @@
                      </packing>
                    </child>
                    <child>
                      <object class="GtkLabel" id="label3">
                      <object class="GtkCheckButton" id="confirmation-dialog">
                        <property name="label" translatable="yes">_Show confirmation dialog</property>
                        <property name="use_action_appearance">False</property>
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="label" translatable="yes">Appeara_nce:</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">False</property>
                        <property name="tooltip_text" translatable="yes">Show a confirmation dialog with a 30 second timeout for some of the actions.</property>
                        <property name="use_underline">True</property>
                        <property name="xalign">0</property>
                        <property name="draw_indicator">True</property>
                      </object>
                      <packing>
                        <property name="left_attach">0</property>
                        <property name="top_attach">0</property>
                        <property name="top_attach">3</property>
                        <property name="width">2</property>
                      </packing>
                    </child>
                  </object>
+120 −10
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@



#define DEFAULT_TITLE    _("Session Menu")
#define DEFAULT_ICON_SIZE (16)
#define DEFAULT_TIMEOUT   (30)

@@ -71,11 +72,22 @@ typedef enum
}
AppearanceType;

typedef enum
{
  BUTTON_TITLE_TYPE_FULLNAME,
  BUTTON_TITLE_TYPE_USERNAME,
  BUTTON_TITLE_TYPE_USERID,
  BUTTON_TITLE_TYPE_CUSTOM
}
ButtonTitleType;

enum
{
  PROP_0,
  PROP_ITEMS,
  PROP_APPEARANCE,
  PROP_BUTTON_TITLE,
  PROP_CUSTOM_TITLE,
  PROP_INVERT_ORIENTATION,
  PROP_ASK_CONFIRMATION
};
@@ -98,6 +110,8 @@ struct _ActionsPlugin
  XfcePanelPlugin __parent__;

  AppearanceType  type;
  ButtonTitleType button_title;
  gchar          *custom_title;
  GPtrArray      *items;
  GtkWidget      *menu;
  guint           invert_orientation : 1;
@@ -272,6 +286,22 @@ actions_plugin_class_init (ActionsPluginClass *klass)
                                                      APPEARANCE_TYPE_MENU,
                                                      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

  g_object_class_install_property (gobject_class,
                                   PROP_BUTTON_TITLE,
                                   g_param_spec_uint ("button-title",
                                                      NULL, NULL,
                                                      BUTTON_TITLE_TYPE_FULLNAME,
                                                      BUTTON_TITLE_TYPE_CUSTOM,
                                                      BUTTON_TITLE_TYPE_FULLNAME,
                                                      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

  g_object_class_install_property (gobject_class,
                                   PROP_CUSTOM_TITLE,
                                   g_param_spec_string ("custom-title",
                                                        NULL, NULL,
                                                        DEFAULT_TITLE,
                                                        G_PARAM_READWRITE));

  g_object_class_install_property (gobject_class,
                                   PROP_INVERT_ORIENTATION,
                                   g_param_spec_boolean ("invert-orientation",
@@ -295,6 +325,7 @@ static void
actions_plugin_init (ActionsPlugin *plugin)
{
  plugin->type = APPEARANCE_TYPE_MENU;
  plugin->button_title = BUTTON_TITLE_TYPE_FULLNAME;
  plugin->invert_orientation = FALSE;
  plugin->ask_confirmation = TRUE;
}
@@ -330,6 +361,15 @@ actions_plugin_get_property (GObject *object,
      g_value_set_uint (value, plugin->type);
      break;

    case PROP_BUTTON_TITLE:
      g_value_set_uint (value, plugin->button_title);
      break;

    case PROP_CUSTOM_TITLE:
      g_value_set_string (value, plugin->custom_title == NULL ?
                          DEFAULT_TITLE : plugin->custom_title);
      break;

    case PROP_INVERT_ORIENTATION:
      g_value_set_boolean (value, plugin->invert_orientation);
      break;
@@ -369,6 +409,17 @@ actions_plugin_set_property (GObject *object,
      actions_plugin_pack (plugin);
      break;

    case PROP_BUTTON_TITLE:
      plugin->button_title = g_value_get_uint (value);
      actions_plugin_pack (plugin);
      break;

    case PROP_CUSTOM_TITLE:
      g_free (plugin->custom_title);
      plugin->custom_title = g_value_dup_string (value);
      actions_plugin_pack (plugin);
      break;

    case PROP_INVERT_ORIENTATION:
      plugin->invert_orientation = g_value_get_boolean (value);
      actions_plugin_pack (plugin);
@@ -394,6 +445,8 @@ actions_plugin_construct (XfcePanelPlugin *panel_plugin)
  {
    { "items", G_TYPE_PTR_ARRAY },
    { "appearance", G_TYPE_UINT },
    { "button-title", G_TYPE_UINT },
    { "custom-title", G_TYPE_STRING },
    { "invert-orientation", G_TYPE_BOOLEAN },
    { "ask-confirmation", G_TYPE_BOOLEAN },
    { NULL }
@@ -569,6 +622,20 @@ actions_plugin_lookup_entry (const gchar *name)



static void
actions_plugin_combo_title_changed_cb (GtkWidget *widget,
                                       gpointer   user_data)
{
  GtkBuilder *builder = GTK_BUILDER (user_data);

  gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (builder, "entry-cust-title")),
                            gtk_combo_box_get_active (GTK_COMBO_BOX (widget)) == 3);
  gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (builder, "label-cust-title")),
                            gtk_combo_box_get_active (GTK_COMBO_BOX (widget)) == 3);
}



static void
actions_plugin_configure_plugin (XfcePanelPlugin *panel_plugin)
{
@@ -611,6 +678,24 @@ actions_plugin_configure_plugin (XfcePanelPlugin *panel_plugin)
                          G_OBJECT (object), "sensitive",
                          G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL | G_BINDING_INVERT_BOOLEAN);

  object = gtk_builder_get_object (builder, "revealer-title");
  g_object_bind_property (G_OBJECT (plugin), "appearance",
                          object, "reveal-child",
                          G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);

  combo = gtk_builder_get_object (builder, "combo-title");
  g_object_bind_property (G_OBJECT (plugin), "button-title",
                          G_OBJECT (combo), "active",
                          G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);

  object = gtk_builder_get_object (builder, "entry-cust-title");
  g_object_bind_property (G_OBJECT (plugin), "custom-title",
                          G_OBJECT (object), "text",
                          G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);

  g_signal_connect (combo, "changed", G_CALLBACK (actions_plugin_combo_title_changed_cb), builder);
  actions_plugin_combo_title_changed_cb (GTK_WIDGET (object), builder);

  object = gtk_builder_get_object (builder, "confirmation-dialog");
  g_object_bind_property (G_OBJECT (plugin), "ask-confirmation",
                          G_OBJECT (object), "active",
@@ -1153,7 +1238,7 @@ actions_plugin_pack_idle (gpointer data)
  GtkWidget           *label;
  GtkWidget           *button;
  GtkWidget           *widget;
  const gchar         *username;
  const gchar         *button_title;
  GtkWidget           *child;
  GtkWidget           *box;
  guint                i;
@@ -1217,15 +1302,40 @@ actions_plugin_pack_idle (gpointer data)
    }
  else
    {
      switch (plugin->button_title)
        {
          case BUTTON_TITLE_TYPE_FULLNAME:
            /* get a decent username, not the glib defaults */
      username = g_get_real_name ();
      if (panel_str_is_empty (username)
          || strcmp (username, "Unknown") == 0)
            button_title = g_get_real_name ();
            if (panel_str_is_empty (button_title)
                || strcmp (button_title, "Unknown") == 0)
              {
                button_title = g_get_user_name ();
                if (panel_str_is_empty (button_title)
                    || strcmp (button_title, "username") == 0)
                  button_title = _("Little Mouse");
              }
            break;

          case BUTTON_TITLE_TYPE_USERNAME:
            button_title = g_get_user_name ();
            if (panel_str_is_empty (button_title))
              button_title = "username";
            break;

          case BUTTON_TITLE_TYPE_USERID:
            {
          username = g_get_user_name ();
          if (panel_str_is_empty (username)
              || strcmp (username, "somebody") == 0)
            username = _("John Doe");
              char buf[16];
              snprintf(buf, sizeof(buf), "%u", (unsigned)getuid());
              button_title = buf;
            }
            break;

          default:
          case BUTTON_TITLE_TYPE_CUSTOM:
            button_title = (plugin->custom_title == NULL?
                            DEFAULT_TITLE : plugin->custom_title);
            break;
        }

      button = xfce_arrow_button_new (GTK_ARROW_NONE);
@@ -1237,7 +1347,7 @@ actions_plugin_pack_idle (gpointer data)
          G_CALLBACK (actions_plugin_menu), plugin);
      gtk_widget_show (button);

      label = gtk_label_new (username);
      label = gtk_label_new (button_title);
      gtk_container_add (GTK_CONTAINER (button), label);
      mode = xfce_panel_plugin_get_mode (XFCE_PANEL_PLUGIN (plugin));
      gtk_label_set_angle (GTK_LABEL (label),