Migrate built-in "pager" plugin to new APIs.
authorAndriy Grytsenko <andrej@rep.kiev.ua>
Sat, 15 Feb 2014 15:04:16 +0000 (17:04 +0200)
committerAndriy Grytsenko <andrej@rep.kiev.ua>
Sat, 15 Feb 2014 15:04:16 +0000 (17:04 +0200)
src/configurator.c
src/plugin.c
src/plugins/pager.c

index 1482f7f..42ab9eb 100644 (file)
@@ -662,7 +662,6 @@ static void on_add_plugin( GtkButton* btn, GtkTreeView* _view )
 {
     GtkWidget* dlg, *parent_win, *scroll;
     GHashTable *classes;
-    GList *plugins;
     GtkTreeViewColumn* col;
     GtkCellRenderer* render;
     GtkTreeView* view;
@@ -674,7 +673,6 @@ static void on_add_plugin( GtkButton* btn, GtkTreeView* _view )
     Panel* p = (Panel*) g_object_get_data( G_OBJECT(_view), "panel" );
 
     classes = lxpanel_get_all_types();
-    plugins = gtk_container_get_children(GTK_CONTAINER(p->box));
 
     parent_win = gtk_widget_get_toplevel( GTK_WIDGET(_view) );
     dlg = gtk_dialog_new_with_buttons( _("Add plugin to panel"),
@@ -745,7 +743,6 @@ static void on_add_plugin( GtkButton* btn, GtkTreeView* _view )
                       G_CALLBACK(on_add_plugin_row_activated), (gpointer) dlg);
 
     g_object_set_data( G_OBJECT(dlg), "avail-plugins", view );
-    g_list_free(plugins);
 
     gtk_window_set_default_size( GTK_WINDOW(dlg), 320, 400 );
     gtk_widget_show_all( dlg );
index c95815c..1cb76f8 100644 (file)
@@ -134,7 +134,7 @@ static void init_plugin_class_list(void)
 #endif
 
 #ifdef STATIC_PAGER
-    REGISTER_STATIC_PLUGIN_CLASS(pager_plugin_class);
+    REGISTER_STATIC_MODULE(pager);
 #endif
 
 #ifdef STATIC_TRAY
index 2340f59..9addfd0 100644 (file)
 #endif
 #include <libwnck/libwnck.h>
 
-#include "panel.h"
-#include "misc.h"
-#include "private.h"
+#include "plugin.h"
 
-#include "dbg.h"
 
-typedef struct _pager {
-    Plugin* plugin;
-    GtkWidget *box;
-} pager;
-
-
-static int
-pager_constructor(Plugin *plug, char **fp)
+static void on_realize(GtkWidget *p, Panel *panel)
 {
-    pager *pg;
+    WnckPager *pager = WNCK_PAGER(gtk_bin_get_child(GTK_BIN(p)));
+    int rows, r;
+
+    /* set geometry */
+    wnck_pager_set_orientation(pager, panel_get_orientation(panel));
+    rows = panel_get_height(panel) / (panel_get_icon_size(panel) * 2) + 1; /* min */
+    r = (panel_get_height(panel) - 4) / panel_get_icon_size(panel); /* max */
+    /* g_debug("pager for height %d and icon size %d: %d to %d",panel_get_height(panel),panel_get_icon_size(panel),r,rows); */
+    rows = MAX(rows, r);
+    wnck_pager_set_n_rows(pager, rows);
+}
 
-    ENTER;
-    pg = g_new0(pager, 1);
-    g_return_val_if_fail(pg != NULL, 0);
-    plug->priv = pg;
-    pg->plugin = plug;
+static GtkWidget *pager_constructor(Panel *panel, config_setting_t *settings)
+{
+    GtkWidget *p, *w;
 
-    plug->pwid = gtk_event_box_new();
-    GTK_WIDGET_SET_FLAGS( plug->pwid, GTK_NO_WINDOW );
+    w = wnck_pager_new(NULL);
+    g_return_val_if_fail(w != NULL, 0);
+    p = gtk_event_box_new();
+    GTK_WIDGET_SET_FLAGS(p, GTK_NO_WINDOW);
 
-    pg->box = wnck_pager_new(NULL);
-    g_return_val_if_fail(pg->box != NULL, 0);
-    //set orientation
-    wnck_pager_set_orientation (WNCK_PAGER (pg->box),pg->plugin->panel->orientation);
-    wnck_pager_set_n_rows (WNCK_PAGER (pg->box), 1); //pager->rows);
-    wnck_pager_set_display_mode (WNCK_PAGER (pg->box),WNCK_PAGER_DISPLAY_CONTENT);
-    //pager->show_names ? WNCK_PAGER_DISPLAY_NAME : WNCK_PAGER_DISPLAY_CONTENT);
+    /* we cannot configure pager until it added into widgets hierarchy */
+    g_signal_connect(p, "realize", G_CALLBACK(on_realize), panel);
+    wnck_pager_set_display_mode(WNCK_PAGER(w), WNCK_PAGER_DISPLAY_CONTENT);
 
-    //gtk_container_set_border_width (GTK_CONTAINER (pg->box), 2);
-    gtk_widget_show(pg->box);
+    gtk_widget_show(w);
 
-    gtk_container_set_border_width (GTK_CONTAINER (plug->pwid), 1);
-    gtk_container_add(GTK_CONTAINER(plug->pwid), pg->box);
+    gtk_container_set_border_width(GTK_CONTAINER(p), 2);
+    gtk_container_add(GTK_CONTAINER(p), w);
 
-    RET(1);
+    return p;
 }
 
-static void
-pager_destructor(Plugin *p)
+static void pager_panel_configuration_changed(Panel *panel, GtkWidget *p)
 {
-    pager *pg = (pager *)p->priv;
-
-    ENTER;
-    gtk_widget_destroy(p->pwid);
-    g_free(pg);
-    RET();
+    on_realize(p, panel);
 }
 
-static void pager_panel_configuration_changed(Plugin * p)
-{
-    pager *pg = (pager *)p->priv;
-
-    wnck_pager_set_orientation (WNCK_PAGER (pg->box),pg->plugin->panel->orientation);
-    wnck_pager_set_n_rows (WNCK_PAGER (pg->box), pg->plugin->panel->height / 48 + 1);
-}
-
-PluginClass pager_plugin_class = {
-
-    PLUGINCLASS_VERSIONING,
-
-    .type = "pager",
+LXPanelPluginInit lxpanel_static_plugin_pager = {
     .name = N_("Desktop Pager"),
-    .version = "1.0",
     .description = N_("Simple pager plugin"),
 
-    .constructor = pager_constructor,
-    .destructor  = pager_destructor,
-    .config = NULL,
-    .save = NULL,
-    .panel_configuration_changed = pager_panel_configuration_changed
+    .new_instance = pager_constructor,
+    .reconfigure = pager_panel_configuration_changed
 };