[gnome-applets/wip/segeiger/task-list-and-title: 2/2] window-picker: Remove task-list.c



commit b3b3723e7eb577135740228a1b70f12134b83f7c
Author: Sebastian Geiger <sbastig gmx net>
Date:   Tue Jul 14 20:52:24 2015 +0200

    window-picker: Remove task-list.c
    
    The code in task-list.c was mostly unneeded boilerplate code. The code to handle
    newly opened windows and list initialization was moved to the WpApplet class, the code to handle
    closed windows was moved to the TaskItem class.

 windowpicker/src/Makefile.am  |    2 -
 windowpicker/src/task-item.c  |   11 +++-
 windowpicker/src/task-item.h  |    1 +
 windowpicker/src/task-list.c  |  156 -----------------------------------------
 windowpicker/src/task-list.h  |   62 ----------------
 windowpicker/src/task-title.c |    1 -
 windowpicker/src/wp-applet.c  |   50 ++++++++++++-
 7 files changed, 57 insertions(+), 226 deletions(-)
---
diff --git a/windowpicker/src/Makefile.am b/windowpicker/src/Makefile.am
index ca1979a..5e4668a 100644
--- a/windowpicker/src/Makefile.am
+++ b/windowpicker/src/Makefile.am
@@ -35,8 +35,6 @@ libwindow_picker_applet_la_SOURCES = \
        wp-preferences-dialog.h \
        task-item.c \
        task-item.h \
-       task-list.c \
-       task-list.h \
        task-title.c \
        task-title.h \
        wp-resources.c \
diff --git a/windowpicker/src/task-item.c b/windowpicker/src/task-item.c
index 126467a..f11ecf1 100644
--- a/windowpicker/src/task-item.c
+++ b/windowpicker/src/task-item.c
@@ -19,7 +19,6 @@
  */
 
 #include "task-item.h"
-#include "task-list.h"
 
 #include <math.h>
 #include <glib/gi18n.h>
@@ -114,6 +113,16 @@ static void update_hints (TaskItem *item) {
     );
 }
 
+void task_item_destroy (TaskItem *item)
+{
+    GtkWidget *tasks = wp_applet_get_tasks (item->priv->windowPickerApplet);
+    gtk_container_remove (
+            GTK_CONTAINER (tasks),
+            GTK_WIDGET (item)
+    );
+    gtk_widget_destroy (GTK_WIDGET (item));
+}
+
 static gboolean on_task_item_button_released (
     GtkWidget      *widget,
     GdkEventButton *event,
diff --git a/windowpicker/src/task-item.h b/windowpicker/src/task-item.h
index dcb9a0e..13fa3de 100644
--- a/windowpicker/src/task-item.h
+++ b/windowpicker/src/task-item.h
@@ -50,5 +50,6 @@ struct _TaskItemClass {
 
 GType task_item_get_type (void) G_GNUC_CONST;
 GtkWidget * task_item_new (WpApplet *windowPickerApplet, WnckWindow *window);
+void task_item_destroy (TaskItem *item);
 
 #endif /* _TASK_ITEM_H_ */
diff --git a/windowpicker/src/task-title.c b/windowpicker/src/task-title.c
index e8e0eba..fd54b61 100644
--- a/windowpicker/src/task-title.c
+++ b/windowpicker/src/task-title.c
@@ -27,7 +27,6 @@
 #include <glib/gi18n-lib.h>
 
 #include "task-title.h"
-#include "task-list.h"
 
 struct _TaskTitlePrivate {
     WnckScreen *screen;
diff --git a/windowpicker/src/wp-applet.c b/windowpicker/src/wp-applet.c
index 927b441..f80a5cd 100644
--- a/windowpicker/src/wp-applet.c
+++ b/windowpicker/src/wp-applet.c
@@ -31,10 +31,10 @@
 #include <string.h>
 
 #include "task-title.h"
-#include "task-list.h"
 #include "wp-about-dialog.h"
 #include "wp-applet.h"
 #include "wp-preferences-dialog.h"
+#include "task-item.h"
 
 #define SETTINGS_SCHEMA "org.gnome.gnome-applets.window-picker-applet"
 #define GRESOURCE "/org/gnome/gnome-applets/window-picker/"
@@ -74,6 +74,30 @@ static GParamSpec *properties[LAST_PROP] = { NULL };
 
 G_DEFINE_TYPE (WpApplet, wp_applet, PANEL_TYPE_APPLET)
 
+static void wp_applet_open_window (WnckScreen *screen,
+                                   WnckWindow *window,
+                                   WpApplet *applet)
+{
+    g_return_if_fail (applet->tasks != NULL);
+    WnckWindowType type = wnck_window_get_window_type (window);
+    if (type == WNCK_WINDOW_DESKTOP
+        || type == WNCK_WINDOW_DOCK
+        || type == WNCK_WINDOW_SPLASHSCREEN
+        || type == WNCK_WINDOW_MENU)
+    {
+        return;
+    }
+
+    GtkWidget *item = task_item_new (applet, window);
+
+    if (item) {
+        //we add items dynamically to the end of the list
+        gtk_container_add(GTK_CONTAINER(applet->tasks), item);
+        g_signal_connect (TASK_ITEM(item), "task-item-closed",
+                          G_CALLBACK(task_item_destroy), NULL);
+    }
+}
+
 static void
 wp_about_dialog_response_cb (GtkDialog *dialog,
                              gint       response_id,
@@ -188,10 +212,19 @@ wp_applet_load (PanelApplet *panel_applet)
   applet->container = gtk_box_new (orientation, 10);
   gtk_container_add (GTK_CONTAINER (applet), applet->container);
 
-  applet->tasks = task_list_new (applet);
+  applet->tasks = gtk_box_new (orientation, 0);
   gtk_box_pack_start (GTK_BOX (applet->container), applet->tasks,
                       FALSE, FALSE, 0);
 
+  g_signal_connect (wnck_screen_get_default (), "window-opened",
+                    G_CALLBACK (wp_applet_open_window), applet);
+
+  GList *windows = wnck_screen_get_windows (wnck_screen_get_default ());
+  while (windows != NULL) {
+      wp_applet_open_window (wnck_screen_get_default (), windows->data, applet);
+      windows = windows->next;
+  }
+
   applet->title = task_title_new (applet);
   gtk_box_pack_start (GTK_BOX (applet->container), applet->title,
                       FALSE, FALSE, 0);
@@ -242,6 +275,8 @@ wp_applet_dispose (GObject *object)
 
   applet = WP_APPLET (object);
 
+  g_signal_handlers_disconnect_by_func (wnck_screen_get_default (), wp_applet_open_window, applet);
+
   g_clear_object (&applet->settings);
 
   if (applet->about_dialog != NULL)
@@ -366,8 +401,15 @@ wp_applet_change_orient (PanelApplet       *panel_applet,
   applet = WP_APPLET (panel_applet);
   orientation = panel_applet_get_gtk_orientation (panel_applet);
 
-  gtk_orientable_set_orientation (GTK_ORIENTABLE (applet->container),
-                                  orientation);
+  if (applet->container) {
+      gtk_orientable_set_orientation (GTK_ORIENTABLE (applet->container),
+                                      orientation);
+  }
+
+  if (applet->tasks) {
+      gtk_orientable_set_orientation (GTK_ORIENTABLE (applet->tasks),
+                                      orientation);
+  }
 
   gtk_widget_queue_resize (GTK_WIDGET (applet));
 }


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