[gnome-panel/wip-geiger-dialog: 2/2] properties-dialog: align with add-to-window



commit 6dfffa40772184b3e7ed6544d74d6c5483d6db5b
Author: Sebastian Geiger <sbastig gmx net>
Date:   Sat Apr 18 16:02:06 2020 +0200

    properties-dialog: align with add-to-window
    
    Applets are grouped by pack_type and sorted by pack_index, the also
    have a remove button and its possible to access the about and help
    menus of each applet.

 gnome-panel/Makefile.am             |   2 +
 gnome-panel/gp-applet-list-row.c    | 426 ++++++++++++++++++++++++++++++++++++
 gnome-panel/gp-applet-list-row.h    |  43 ++++
 gnome-panel/gp-properties-dialog.c  | 207 +++++++++++++-----
 gnome-panel/gp-properties-dialog.ui |  72 +++++-
 libgnome-panel/gp-applet-info.c     |  18 ++
 libgnome-panel/gp-applet-info.h     |   6 +
 7 files changed, 722 insertions(+), 52 deletions(-)
---
diff --git a/gnome-panel/Makefile.am b/gnome-panel/Makefile.am
index cab705909..ab0d67027 100644
--- a/gnome-panel/Makefile.am
+++ b/gnome-panel/Makefile.am
@@ -11,6 +11,8 @@ bin_PROGRAMS = \
 panel_sources =                        \
        gp-add-applet-window.c \
        gp-add-applet-window.h \
+       gp-applet-list-row.c \
+       gp-applet-list-row.h \
        gp-applet-manager.c \
        gp-applet-manager.h \
        gp-applet-row.c \
diff --git a/gnome-panel/gp-applet-list-row.c b/gnome-panel/gp-applet-list-row.c
new file mode 100644
index 000000000..893f67c24
--- /dev/null
+++ b/gnome-panel/gp-applet-list-row.c
@@ -0,0 +1,426 @@
+/*
+ * Copyright (C) 2020 Alberts Muktupāvels
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include "gp-applet-list-row.h"
+
+#include <glib/gi18n.h>
+
+#include "panel-applets-manager.h"
+#include "panel-layout.h"
+#include "panel-lockdown.h"
+
+struct _GpAppletListRow
+{
+    GtkListBoxRow  parent;
+
+    GpModule      *module;
+    char          *applet_id;
+
+    AppletInfo    *info;
+
+    char          *iid;
+
+    GtkWidget     *event_box;
+
+    GtkWidget     *about_dialog;
+};
+
+enum
+{
+    PROP_0,
+
+    PROP_MODULE,
+    PROP_APPLET_ID,
+    PROP_APPLET_INFO,
+
+    LAST_PROP
+};
+
+static GParamSpec *row_properties[LAST_PROP] = { NULL };
+
+G_DEFINE_TYPE (GpAppletListRow, gp_applet_list_row, GTK_TYPE_LIST_BOX_ROW)
+
+static void
+help_cb (GtkMenuItem     *menuitem,
+         GpAppletListRow *self)
+{
+  gp_module_show_help (self->module, NULL, self->applet_id, NULL);
+}
+
+static void
+about_cb (GtkMenuItem     *menuitem,
+          GpAppletListRow *self)
+{
+  if (self->about_dialog != NULL)
+    {
+      gtk_window_present (GTK_WINDOW (self->about_dialog));
+      return;
+    }
+
+  self->about_dialog = gp_module_create_about_dialog (self->module,
+                                                      NULL,
+                                                      self->applet_id);
+
+  if (self->about_dialog == NULL)
+    return;
+
+  g_object_add_weak_pointer (G_OBJECT (self->about_dialog),
+                             (gpointer *) &self->about_dialog);
+
+  gtk_window_present (GTK_WINDOW (self->about_dialog));
+}
+
+static void
+setup_view_more_button (GpAppletListRow *self,
+                        GtkWidget       *button,
+                        GpAppletInfo    *info)
+{
+  GtkWidget *image;
+  GtkWidget *menu;
+  gboolean sensitive;
+  GtkWidget *item;
+
+  image = gtk_image_new_from_icon_name ("view-more-symbolic",
+                                        GTK_ICON_SIZE_MENU);
+
+  gtk_button_set_image (GTK_BUTTON (button), image);
+  gtk_image_set_pixel_size (GTK_IMAGE (image), 16);
+
+  menu = gtk_menu_new ();
+  sensitive = FALSE;
+
+  gtk_menu_button_set_popup (GTK_MENU_BUTTON (button), menu);
+  gtk_widget_set_halign (menu, GTK_ALIGN_END);
+
+  if (info->help_uri && info->help_uri[0] != '\0')
+    {
+      sensitive = TRUE;
+      item = gtk_menu_item_new_with_label (_("Help"));
+      gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+      gtk_widget_show (item);
+
+      g_signal_connect (item, "activate", G_CALLBACK (help_cb), self);
+    }
+
+  if (info->about_dialog_func != NULL)
+    {
+      sensitive = TRUE;
+      item = gtk_menu_item_new_with_label (_("About"));
+      gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+      gtk_widget_show (item);
+
+      g_signal_connect (item, "activate", G_CALLBACK (about_cb), self);
+    }
+
+  gtk_widget_set_sensitive (button, sensitive);
+}
+
+static void
+drag_data_get_cb (GtkWidget        *widget,
+                  GdkDragContext   *context,
+                  GtkSelectionData *data,
+                  guint             info,
+                  guint             time,
+                  GpAppletListRow  *self)
+{
+  gtk_selection_data_set (data,
+                          gtk_selection_data_get_target (data),
+                          8,
+                          (const guchar *) self->iid,
+                          strlen (self->iid));
+}
+
+static void
+setup_drag_source (GpAppletListRow *self)
+{
+  GpAppletInfo *info;
+  GdkModifierType modifiers;
+  GdkDragAction actions;
+  GtkTargetList *target_list;
+  GdkAtom target;
+
+  info = gp_module_get_applet_info (self->module, self->applet_id, NULL);
+
+  modifiers = GDK_BUTTON1_MASK | GDK_BUTTON2_MASK;
+  actions = GDK_ACTION_COPY;
+
+  gtk_drag_source_set (self->event_box, modifiers, NULL, 0, actions);
+  gtk_drag_source_set_icon_name (self->event_box, info->icon_name);
+
+  target_list = gtk_target_list_new (NULL, 0);
+
+  target = gdk_atom_intern_static_string ("application/x-panel-applet-iid");
+  gtk_target_list_add (target_list, target, 0, 0);
+
+  gtk_drag_source_set_target_list (self->event_box, target_list);
+  gtk_target_list_unref (target_list);
+
+  g_signal_connect (self->event_box,
+                    "drag-data-get",
+                    G_CALLBACK (drag_data_get_cb),
+                    self);
+}
+
+static void
+lockdown_changed_cb (PanelLockdown *lockdown,
+                     gpointer       user_data)
+{
+  GpAppletListRow *self;
+
+  self = GP_APPLET_LIST_ROW (user_data);
+
+  if (!panel_layout_is_writable () ||
+      panel_lockdown_get_panels_locked_down_s () ||
+      panel_applets_manager_is_applet_disabled (self->iid, NULL))
+    {
+      gtk_widget_set_sensitive (GTK_WIDGET (self), FALSE);
+      gtk_drag_source_unset (self->event_box);
+      return;
+    }
+
+  gtk_widget_set_sensitive (GTK_WIDGET (self), TRUE);
+  setup_drag_source (self);
+}
+
+static void
+remove_clicked_cb (GtkButton       *button,
+                   GpAppletListRow *self)
+{
+  GtkListBoxRow *row;
+
+  row = GTK_LIST_BOX_ROW (self);
+
+  GTK_LIST_BOX_ROW_GET_CLASS (row)->activate (row);
+}
+
+static void
+setup_row (GpAppletListRow *self)
+{
+  GpAppletInfo *info;
+  GtkWidget *hbox;
+  GtkWidget *icon_image;
+  GtkWidget *vbox;
+  GtkWidget *remove_button;
+  GtkWidget *menu_button;
+  GtkWidget *title_label;
+  GtkWidget *description_label;
+
+  char * name;
+
+  info = gp_module_get_applet_info (self->module, self->applet_id, NULL);
+  g_assert (info != NULL);
+
+  self->iid = g_strdup_printf ("%s::%s",
+                               gp_module_get_id (self->module),
+                               self->applet_id);
+
+  self->event_box = gtk_event_box_new ();
+  gtk_container_add (GTK_CONTAINER (self), self->event_box);
+  gtk_widget_show (self->event_box);
+
+  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
+  gtk_container_add (GTK_CONTAINER (self->event_box), hbox);
+  gtk_widget_show (hbox);
+
+  g_object_set (hbox,
+                "margin-start", 6,
+                "margin-end", 6,
+                NULL);
+
+  icon_image = gtk_image_new_from_icon_name (info->icon_name, GTK_ICON_SIZE_DND);
+  gtk_image_set_pixel_size (GTK_IMAGE (icon_image), 32);
+  gtk_box_pack_start (GTK_BOX (hbox), icon_image, FALSE, FALSE, 0);
+  gtk_widget_show (icon_image);
+
+  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+  gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
+  gtk_widget_show (vbox);
+
+  remove_button = gtk_button_new_with_label (_("Remove"));
+  gtk_box_pack_start (GTK_BOX (hbox), remove_button, FALSE, FALSE, 0);
+  gtk_widget_set_valign (remove_button, GTK_ALIGN_CENTER);
+  gtk_widget_show (remove_button);
+
+  g_signal_connect (remove_button, "clicked", G_CALLBACK (remove_clicked_cb), self);
+
+  menu_button = gtk_menu_button_new ();
+  gtk_box_pack_end (GTK_BOX (hbox), menu_button, FALSE, FALSE, 0);
+  gtk_widget_set_valign (menu_button, GTK_ALIGN_CENTER);
+  setup_view_more_button (self, menu_button, info);
+  gtk_widget_show (menu_button);
+
+  title_label = gtk_label_new (NULL);
+  name = g_strdup_printf ("<b>%s</b>", info->name);
+  gtk_label_set_markup (GTK_LABEL (title_label), name);
+  g_free (name);
+
+  gtk_box_pack_start (GTK_BOX (vbox), title_label, FALSE, FALSE, 0);
+  gtk_label_set_xalign (GTK_LABEL (title_label), 0);
+  gtk_widget_show (title_label);
+
+  description_label = gtk_label_new (info->description);
+  gtk_box_pack_start (GTK_BOX (vbox), description_label, FALSE, FALSE, 0);
+  gtk_label_set_max_width_chars (GTK_LABEL (description_label), 20);
+  gtk_label_set_line_wrap (GTK_LABEL (description_label), TRUE);
+  gtk_label_set_xalign (GTK_LABEL (description_label), 0);
+  gtk_widget_show (description_label);
+
+  panel_lockdown_on_notify (panel_lockdown_get (),
+                            NULL,
+                            G_OBJECT (self),
+                            lockdown_changed_cb,
+                            self);
+
+  lockdown_changed_cb (panel_lockdown_get (), self);
+}
+
+static void
+gp_applet_list_row_constructed (GObject *object)
+{
+  G_OBJECT_CLASS (gp_applet_list_row_parent_class)->constructed (object);
+  setup_row (GP_APPLET_LIST_ROW (object));
+}
+
+static void
+gp_applet_list_row_dispose (GObject *object)
+{
+  GpAppletListRow *self;
+
+  self = GP_APPLET_LIST_ROW (object);
+
+  g_clear_object (&self->module);
+
+  g_clear_pointer (&self->about_dialog, gtk_widget_destroy);
+
+  G_OBJECT_CLASS (gp_applet_list_row_parent_class)->dispose (object);
+}
+
+static void
+gp_applet_list_row_finalize (GObject *object)
+{
+  GpAppletListRow *self;
+
+  self = GP_APPLET_LIST_ROW (object);
+
+  g_clear_pointer (&self->applet_id, g_free);
+
+  G_OBJECT_CLASS (gp_applet_list_row_parent_class)->finalize (object);
+}
+
+static void
+gp_applet_list_row_set_property (GObject      *object,
+                                 guint         property_id,
+                                 const GValue *value,
+                                 GParamSpec   *pspec)
+{
+  GpAppletListRow *self;
+
+  self = GP_APPLET_LIST_ROW (object);
+
+  switch (property_id)
+    {
+      case PROP_MODULE:
+        g_assert (self->module == NULL);
+        self->module = g_value_dup_object (value);
+        break;
+
+      case PROP_APPLET_ID:
+        g_assert (self->applet_id == NULL);
+        self->applet_id = g_value_dup_string (value);
+        break;
+
+      case PROP_APPLET_INFO:
+        g_assert (self->info == NULL);
+        self->info = g_value_get_pointer (value);
+        break;
+
+      default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+}
+
+static void
+install_properties (GObjectClass *object_class)
+{
+  row_properties[PROP_MODULE] =
+      g_param_spec_object ("module",
+                           "module",
+                           "module",
+                           GP_TYPE_MODULE,
+                           G_PARAM_WRITABLE |
+                           G_PARAM_CONSTRUCT_ONLY |
+                           G_PARAM_STATIC_STRINGS);
+
+  row_properties[PROP_APPLET_ID] =
+      g_param_spec_string ("applet-id",
+                           "applet-id",
+                           "applet-id",
+                           NULL,
+                           G_PARAM_WRITABLE |
+                           G_PARAM_CONSTRUCT_ONLY |
+                           G_PARAM_STATIC_STRINGS);
+
+  row_properties[PROP_APPLET_INFO] =
+      g_param_spec_pointer("applet-info",
+                           "applet-info",
+                           "applet-info",
+                           G_PARAM_WRITABLE |
+                           G_PARAM_CONSTRUCT_ONLY |
+                           G_PARAM_STATIC_STRINGS);
+
+  g_object_class_install_properties (object_class, LAST_PROP, row_properties);
+}
+
+static void
+gp_applet_list_row_class_init (GpAppletListRowClass *self_class)
+{
+  GObjectClass *object_class;
+
+  object_class = G_OBJECT_CLASS (self_class);
+
+  object_class->constructed = gp_applet_list_row_constructed;
+  object_class->dispose = gp_applet_list_row_dispose;
+  object_class->finalize = gp_applet_list_row_finalize;
+  object_class->set_property = gp_applet_list_row_set_property;
+
+  install_properties (object_class);
+}
+
+static void
+gp_applet_list_row_init (GpAppletListRow *self)
+{
+}
+
+GtkWidget *
+gp_applet_list_row_new (GpModule   *module,
+                        const char *applet_id,
+                        AppletInfo *info)
+{
+  return g_object_new (GP_TYPE_APPLET_LIST_ROW,
+                       "module", module,
+                       "applet-id", applet_id,
+                       "applet-info", info,
+                       NULL);
+}
+
+AppletInfo *
+gp_applet_list_row_get_applet_info (GpAppletListRow *self)
+{
+  return self->info;
+}
diff --git a/gnome-panel/gp-applet-list-row.h b/gnome-panel/gp-applet-list-row.h
new file mode 100644
index 000000000..27c4f5b32
--- /dev/null
+++ b/gnome-panel/gp-applet-list-row.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2020 Alberts Muktupāvels
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GP_APPLET_ROW_H
+#define GP_APPLET_ROW_H
+
+#include "libgnome-panel/gp-applet-info-private.h"
+#include "libgnome-panel/gp-module-private.h"
+
+#include "applet.h"
+
+G_BEGIN_DECLS
+
+#define GP_TYPE_APPLET_LIST_ROW (gp_applet_list_row_get_type ())
+G_DECLARE_FINAL_TYPE (GpAppletListRow, gp_applet_list_row, GP, APPLET_LIST_ROW, GtkListBoxRow)
+
+GtkWidget    *gp_applet_list_row_new             (GpModule    *module,
+                                                  const char  *applet_id,
+                                                  AppletInfo  *info);
+
+GpAppletInfo *gp_applet_list_row_get_info        (GpAppletListRow *self);
+
+const char   *gp_applet_list_row_get_iid         (GpAppletListRow *self);
+
+AppletInfo   *gp_applet_list_row_get_applet_info (GpAppletListRow *self);
+
+G_END_DECLS
+
+#endif
diff --git a/gnome-panel/gp-properties-dialog.c b/gnome-panel/gp-properties-dialog.c
index c1ce06a4c..dea92a993 100644
--- a/gnome-panel/gp-properties-dialog.c
+++ b/gnome-panel/gp-properties-dialog.c
@@ -18,11 +18,13 @@
 #include "config.h"
 
 #include <glib/gi18n.h>
+#include <libgnome-panel/gp-applet-info.h>
 
 #include "gp-properties-dialog.h"
 #include "panel-schemas.h"
-#include "applet.h"
 #include "panel-applets-manager.h"
+#include "gp-applet-list-row.h"
+#include "panel-layout.h"
 
 struct _GpPropertiesDialog
 {
@@ -60,6 +62,9 @@ struct _GpPropertiesDialog
   GtkWidget *fg_color;
 
   GtkWidget *applet_box;
+  GtkWidget *applet_box_left;
+  GtkWidget *applet_box_center;
+  GtkWidget *applet_box_right;
 };
 
 enum
@@ -311,99 +316,196 @@ setup_theme_bindings (GpPropertiesDialog *dialog)
 }
 
 static char *
-get_applet_iid (AppletInfo *applet) {
-  return g_settings_get_string (applet->settings, PANEL_OBJECT_IID_KEY);
+get_applet_iid (AppletInfo *info)
+{
+  return g_settings_get_string (info->settings, PANEL_OBJECT_IID_KEY);
 }
 
-static GtkWidget *
-create_applet_entry (GpPropertiesDialog *dialog, AppletInfo *info)
+static char *
+get_applet_id (AppletInfo *info)
 {
-  PanelAppletInfo *panel_applet_info;
+  return g_strrstr (get_applet_iid(info), "::") + 2;
+}
 
-  GtkWidget *name_label;
-  GtkWidget *description_label;
-  GtkWidget *entry;
-  GtkWidget *entryDetails;
-  GtkWidget *image;
+static PanelObjectPackType
+get_applet_pack_type (AppletInfo *info)
+{
+  return g_settings_get_enum (info->settings, PANEL_OBJECT_PACK_TYPE_KEY);
+}
 
-  const char *name;
-  const char *description;
-  const char *icon_name;
+static int
+get_applet_pack_index (AppletInfo *info)
+{
+  return g_settings_get_int (info->settings, PANEL_OBJECT_PACK_INDEX_KEY);
+}
 
-  GIcon *icon;
+static GpModule *
+get_module_from_id (GpModuleManager *manager,
+                    char            *iid)
+{
+  const gchar *applet_id;
+  gchar *module_id;
+  GpModule *module;
 
-  panel_applet_info = panel_applets_manager_get_applet_info (get_applet_iid (info));
+  applet_id = g_strrstr (iid, "::");
 
-  if (!panel_applet_info)
-    {
-      g_debug ("No panel applet info for id: %s", info->id);
-      return NULL;
-    }
+  if (!applet_id)
+    return FALSE;
+
+  module_id = g_strndup (iid, strlen (iid) - strlen (applet_id));
+
+  module = gp_module_manager_get_module (manager, module_id);
+  g_free (module_id);
+
+  return module;
+}
 
-  entry = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
-  entryDetails = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
+static void
+insert_applet_entry (GpPropertiesDialog *dialog,
+                     AppletInfo         *info,
+                     GtkWidget          *applet_entry)
+{
+  PanelObjectPackType pack_type;
+  int pack_index;
 
-  name = panel_applet_info_get_name (panel_applet_info);
-  name_label = gtk_label_new (NULL);
-  gtk_label_set_markup(GTK_LABEL (name_label), g_strdup_printf ("<b>Applet Name: %s</b>", name));
-  gtk_widget_set_halign (name_label, GTK_ALIGN_START);
+  pack_type = get_applet_pack_type (info);
+  pack_index = get_applet_pack_index (info);
 
-  description = panel_applet_info_get_description (panel_applet_info);
-  description_label = gtk_label_new (g_strdup_printf ("Applet Description: %s", description));
-  gtk_widget_set_halign (description_label, GTK_ALIGN_START);
+  g_object_set_data (G_OBJECT (applet_entry), "pack-index", GINT_TO_POINTER (pack_index));
 
-  icon_name = panel_applet_info_get_icon (panel_applet_info);
+  if (pack_type == PANEL_OBJECT_PACK_START)
+    {
+      gtk_container_add (GTK_CONTAINER (dialog->applet_box_left), applet_entry);
+    }
 
-  if (icon_name)
+  if (pack_type == PANEL_OBJECT_PACK_CENTER)
     {
-      icon = g_themed_icon_new (icon_name);
-      image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_DIALOG);
+      gtk_container_add (GTK_CONTAINER (dialog->applet_box_center), applet_entry);
     }
 
-  gtk_container_add (GTK_CONTAINER (entryDetails), name_label);
-  gtk_container_add (GTK_CONTAINER (entryDetails), description_label);
+  if (pack_type == PANEL_OBJECT_PACK_END)
+    {
+      gtk_container_add (GTK_CONTAINER (dialog->applet_box_right), applet_entry);
+    }
+}
 
-  gtk_container_add (GTK_CONTAINER (entry), image);
-  gtk_container_add (GTK_CONTAINER (entry), entryDetails);
+static gint
+applet_sort_func (GtkListBoxRow *row1,
+                  GtkListBoxRow *row2,
+                  gpointer       user_data)
+{
+  gpointer index_1;
+  gpointer index_2;
 
-  return entry;
+  index_1 = g_object_get_data (G_OBJECT (row1), "pack-index");
+  index_2 = g_object_get_data (G_OBJECT (row2), "pack-index");
+
+  return GPOINTER_TO_INT (index_1) - GPOINTER_TO_INT (index_2);
+}
+
+static gint
+applet_sort_func_reverse (GtkListBoxRow *row1,
+                          GtkListBoxRow *row2,
+                          gpointer       user_data)
+{
+  gpointer index_1;
+  gpointer index_2;
+
+  index_1 = g_object_get_data (G_OBJECT (row1), "pack-index");
+  index_2 = g_object_get_data (G_OBJECT (row2), "pack-index");
+
+  return GPOINTER_TO_INT (index_2) - GPOINTER_TO_INT (index_1);
 }
 
 static void
-setup_applet_box (GpPropertiesDialog  *dialog)
+row_activated_cb (GtkListBox         *box,
+                  GtkListBoxRow      *row,
+                  GpPropertiesDialog *self)
 {
-  GSList * applets;
-  GSList * item;
+  AppletInfo *info;
 
-  applets = panel_applet_list_applets ();
+  info = gp_applet_list_row_get_applet_info (GP_APPLET_LIST_ROW (row));
+
+  gtk_container_remove (GTK_CONTAINER (box), GTK_WIDGET (row));
+
+  panel_layout_delete_object (panel_applet_get_id (info));
+}
+
+static void
+setup_applet_box_structure (GpPropertiesDialog *dialog)
+{
+  gtk_list_box_set_sort_func (GTK_LIST_BOX (dialog->applet_box_left), applet_sort_func, NULL, NULL);
+  gtk_list_box_set_sort_func (GTK_LIST_BOX (dialog->applet_box_center), applet_sort_func, NULL, NULL);
+  gtk_list_box_set_sort_func (GTK_LIST_BOX (dialog->applet_box_right), applet_sort_func_reverse, NULL, NULL);
+
+  gtk_list_box_set_activate_on_single_click(GTK_LIST_BOX (dialog->applet_box_left), FALSE);
+  gtk_list_box_set_activate_on_single_click(GTK_LIST_BOX (dialog->applet_box_center), FALSE);
+  gtk_list_box_set_activate_on_single_click(GTK_LIST_BOX (dialog->applet_box_right), FALSE);
+
+  g_signal_connect (dialog->applet_box_left,
+                    "row-activated",
+                    G_CALLBACK (row_activated_cb),
+                    dialog);
+
+  g_signal_connect (dialog->applet_box_center,
+                    "row-activated",
+                    G_CALLBACK (row_activated_cb),
+                    dialog);
+
+  g_signal_connect (dialog->applet_box_right,
+                    "row-activated",
+                    G_CALLBACK (row_activated_cb),
+                    dialog);
+}
+
+static void
+setup_applet_box_add_applets (GpPropertiesDialog *dialog,
+                              GSList             *applets)
+{
+  GSList *iter;
+  GpModuleManager *manager;
+  GpModule *module;
 
-  for (item = applets; item; item = item->next)
+  manager = panel_applets_maanger_get_module_manager();
+
+  for (iter = applets; iter; iter = iter->next)
     {
       AppletInfo *info;
       GtkWidget *applet_entry;
 
       const char * applet_toplevel_id;
+      const char * applet_id;
 
-      info = item->data;
+      info = iter->data;
 
       applet_toplevel_id = panel_applet_get_toplevel_id (info);
 
       if (g_strcmp0 (applet_toplevel_id, dialog->toplevel_id) != 0)
         continue;
 
-      applet_entry = create_applet_entry (dialog, info);
+      module = get_module_from_id (manager, get_applet_iid (info));
+      applet_id = get_applet_id (info);
 
-      if (!applet_entry)
-        {
-          continue;
-        }
+      applet_entry = gp_applet_list_row_new (module, applet_id, info);
 
-      gtk_container_add (GTK_CONTAINER (dialog->applet_box), applet_entry);
+      insert_applet_entry (dialog, info, applet_entry);
     }
 
   gtk_widget_show_all(dialog->applet_box);
 }
 
+static void
+setup_applet_box (GpPropertiesDialog  *dialog)
+{
+  GSList * applets;
+
+  setup_applet_box_structure (dialog);
+
+  applets = panel_applet_list_applets ();
+
+  setup_applet_box_add_applets (dialog, applets);
+}
+
 static gboolean
 all_keys_writable (GSettings    *settings,
                    const gchar **keys)
@@ -599,6 +701,9 @@ bind_template (GtkWidgetClass *widget_class)
   gtk_widget_class_bind_template_child (widget_class, GpPropertiesDialog, fg_color);
 
   gtk_widget_class_bind_template_child (widget_class, GpPropertiesDialog, applet_box);
+  gtk_widget_class_bind_template_child (widget_class, GpPropertiesDialog, applet_box_left);
+  gtk_widget_class_bind_template_child (widget_class, GpPropertiesDialog, applet_box_center);
+  gtk_widget_class_bind_template_child (widget_class, GpPropertiesDialog, applet_box_right);
 }
 
 static void
diff --git a/gnome-panel/gp-properties-dialog.ui b/gnome-panel/gp-properties-dialog.ui
index 53200c220..c63543cc8 100644
--- a/gnome-panel/gp-properties-dialog.ui
+++ b/gnome-panel/gp-properties-dialog.ui
@@ -615,9 +615,79 @@
           </packing>
         </child>
         <child>
-          <object class="GtkListBox" id="applet_box">
+          <object class="GtkBox" id="applet_box">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
+            <property name="orientation">vertical</property>
+            <child>
+              <object class="GtkLabel">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Left</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkListBox" id="applet_box_left">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Center</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkListBox" id="applet_box_center">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">3</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Right</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">4</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkListBox" id="applet_box_right">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">5</property>
+              </packing>
+            </child>
           </object>
           <packing>
             <property name="position">2</property>
diff --git a/libgnome-panel/gp-applet-info.c b/libgnome-panel/gp-applet-info.c
index 5e0376452..9ae4dc1e5 100644
--- a/libgnome-panel/gp-applet-info.c
+++ b/libgnome-panel/gp-applet-info.c
@@ -156,3 +156,21 @@ gp_applet_info_free (GpAppletInfo *info)
 
   g_free (info);
 }
+
+const char *
+gp_applet_info_get_name (GpAppletInfo *info)
+{
+  return info->name;
+}
+
+const char *
+gp_applet_info_get_description (GpAppletInfo *info)
+{
+  return info->description;
+}
+
+const char *
+gp_applet_info_get_icon_name (GpAppletInfo *info)
+{
+  return info->icon_name;
+}
diff --git a/libgnome-panel/gp-applet-info.h b/libgnome-panel/gp-applet-info.h
index 266ee860d..10a11b9cd 100644
--- a/libgnome-panel/gp-applet-info.h
+++ b/libgnome-panel/gp-applet-info.h
@@ -102,6 +102,12 @@ void          gp_applet_info_set_backends             (GpAppletInfo
 void          gp_applet_info_set_is_disabled          (GpAppletInfo             *info,
                                                        GpIsDisabledFunc          func);
 
+const char *  gp_applet_info_get_name                 (GpAppletInfo             *info);
+
+const char *  gp_applet_info_get_description          (GpAppletInfo             *info);
+
+const char *  gp_applet_info_get_icon_name            (GpAppletInfo             *info);
+
 G_END_DECLS
 
 #endif


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