* a bit of re-factoring
authormishas <mikhail.sobolev@gmail.com>
Thu, 17 Jan 2008 20:36:59 +0000 (20:36 +0000)
committermishas <mikhail.sobolev@gmail.com>
Thu, 17 Jan 2008 20:36:59 +0000 (20:36 +0000)
    * moved SimpleLauncherApplet class declaration into the header file
    * changed the constructor argument for SimpleLauncherApplet
 * finalized the code for wrapper
 * updated a few copyright years (for the files touched)

git-svn-id: file:///svnroot/simple-launcher/branches/new-items@258 3ba93dab-e023-0410-b42a-de7732cf370a

applet-wrapper.cc
simple-launcher.cc
simple-launcher.h

index 9ea7f11..2c673fe 100644 (file)
@@ -23,7 +23,7 @@
 #include "simple-launcher.h"
 
 struct _SLAWrapperPrivate {
-  void *applet;
+  SimpleLauncherApplet *applet;
   GdkPixmap *background_pixmap;
 };
 
@@ -33,15 +33,18 @@ struct _SLAWrapperPrivate {
   static gboolean sla_wrapper_expose(GtkWidget *widget, GdkEventExpose *event);
   static void sla_wrapper_size_allocate(GtkWidget *widget, GtkAllocation *alloc);
   static void sla_wrapper_size_request(GtkWidget *widget, GtkRequisition *requisition);
+  static void sla_wrapper_make_background(GtkWidget *widget, SLAWrapperPrivate *priv);
 
 HD_DEFINE_PLUGIN(SLAWrapper, sla_wrapper, HILDON_DESKTOP_TYPE_HOME_ITEM)
 
 static void sla_wrapper_init(SLAWrapper *self) {
   GdkColormap *colormap = NULL;
 
-  self->priv = G_TYPE_INSTANCE_GET_PRIVATE(self, SLA_TYPE_WRAPPER);
+  self->priv = G_TYPE_INSTANCE_GET_PRIVATE(self, SLA_TYPE_APPLET, SLAWrapperPrivate);
   self->priv->background_pixmap = NULL;
 
+  self->priv->applet = new SimpleLauncherApplet(SL_APPLET_GCONF_PATH);
+
   if ((colormap = gdk_screen_get_rgba_colormap(gdk_screen_get_default())) != NULL) {
     gtk_widget_set_colormap(GTK_WIDGET(self), colormap);
   }
@@ -64,35 +67,46 @@ static void sla_wrapper_class_init(SLAWrapperClass *klass) {
 }
 
 static void sla_wrapper_finalize(GObject *self) {
-  SLAWrapperPrivate *priv = SLA_WRAPPER(self)->priv;
+  SLAWrapperPrivate *priv = SLA_APPLET(self)->priv;
 
   if (priv->background_pixmap != NULL) {
     g_object_unref(priv->background_pixmap);
     priv->background_pixmap = NULL;
   }
-#if 0
-  free(priv->applet);
-#endif
+
+  if (priv->applet != NULL) {
+    delete priv->applet;
+  }
 }
 
-static gboolean sla_wrapper_expose(GtkWidget *widget, GdkEventExpose *event) {
-  if (GTK_WIDGET_DRAWABLE(widget)) {
-    cairo_t *cr;
+static void sla_wrapper_make_background(GtkWidget *widget, SLAWrapperPrivate *priv) {
+  if (priv->background_pixmap != NULL) {
+    g_object_unref(priv->background_pixmap);
+    priv->background_pixmap = NULL;
+  }
 
-    SLAWrapperPrivate *priv = SLA_WRAPPER(widget)->priv;
+  priv->background_pixmap = gdk_pixmap_new(widget->window, priv->applet->getWidth(), priv->applet->getHeight(), 32);
 
-    if (priv->background_pixmap == NULL) {
-      priv->background_pixmap = gdk_pixmap_new(widget->window, SOME_WIDTH, SOME_HEIGHT, 32);
+  cairo_t *cr = gdk_cairo_create(priv->background_pixmap);
+  double red, green, blue, alpha;
 
-      cr = gdk_cairo_create(priv->background_pixmap);
+  priv->applet->getBackgroundColour(red, green, blue, alpha);
 
-      cairo_set_source_rgba(cr, OUR_R, OUR_G, OUR_B, OUR_A);
-      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
-      cairo_paint(cr);
-      cairo_destroy(cr);
+  cairo_set_source_rgba(cr, red, green, blue, alpha);
+  cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
+  cairo_paint(cr);
+  cairo_destroy(cr);
+}
+
+static gboolean sla_wrapper_expose(GtkWidget *widget, GdkEventExpose *event) {
+  if (GTK_WIDGET_DRAWABLE(widget)) {
+    SLAWrapperPrivate *priv = SLA_APPLET(widget)->priv;
+
+    if (priv->background_pixmap == NULL) {
+      sla_wrapper_make_background(widget, priv);
     }
 
-    cr = gdk_cairo_create(widget->window);
+    cairo_t *cr = gdk_cairo_create(widget->window);
     gdk_cairo_set_source_pixmap(cr, priv->background_pixmap, 0, 0);
 
     cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
@@ -110,10 +124,12 @@ static void sla_wrapper_size_allocate(GtkWidget *widget, GtkAllocation *alloc) {
 }
 
 static void sla_wrapper_size_request(GtkWidget *widget, GtkRequisition *requisition) {
-#if 0
-  requisition->width = our_desired_width;
-  requisition->height = our_desired_height;
-#endif
+  if (GTK_WIDGET_DRAWABLE(widget)) {
+    SLAWrapperPrivate *priv = SLA_APPLET(widget)->priv;
+
+    requisition->width = priv->applet->getWidth();
+    requisition->height = priv->applet->getHeight();
+  }
 }
 
 // vim:ts=2:sw=2:et
index 0044068..6001d30 100644 (file)
@@ -1,6 +1,6 @@
 // This file is a part of Simple Launcher
 //
-// Copyright (C) 2006, 2007, Mikhail Sobolev
+// Copyright (C) 2006, 2007, 2008 Mikhail Sobolev <mss@mawhrin.net>
 //
 // Simple Launcher is free software; you can redistribute it and/or modify it
 // under the terms of the GNU General Public License version 2 as published by
 
 #include <gtk/gtk.h>
 
-#include <libosso.h>
-
-#include "launcher-item.h"
-#include "launchable-item.h"
-#include "settings-dialog.h"
-#include "gconf-wrapper.h"
+#include "simple-launcher.h"
 
 #define SL_APPLET_DBUS_NAME  "simple-launcher"
 #define SL_APPLET_VERSION    "0.0"
 
-#define SL_APPLET_GCONF_PATH  "/apps/simple-launcher"
-
-class SimpleLauncherApplet {
-public:
-  SimpleLauncherApplet(const GConfKey&);
- ~SimpleLauncherApplet();
-
-  bool doInit(void *state_data, int *state_size);
-
-  int saveState(void **state_data, int *state_size);
-  GtkWidget *settings(GtkWindow *parent);
-
-  GtkWidget *getWidget() { return myWidget; }
-
-private:
-  static void addItem(LauncherItems&, const std::string&, bool);
-
-  void loadConfig();
-  void saveConfig();
-
-  static void updateItems(LauncherItems&);
-  static void processDirectory(LauncherItems&, const std::string&);
-
-  bool initWidget();
-  void updateWidget();
-
-  void buttonPressed(GtkWidget *button, GdkEventButton *event);
-  void runDialog();
-
-  static void _button_pressed(GtkWidget *button, GdkEventButton *event, void *self);
-  static void _run_dialog(GtkMenuItem *, void *);
-
-private:
-  // GConfClientWrapper myClient;
-  // GConfKey myMainSettings;
-
-  osso_context_t *myContext;
-
-  GtkWidget *myWidget;
-  GtkWindow *myParent;
-
-  LauncherItems myItems;
-
-  GConfBooleanOption myTransparent;
-  // bool myShowInfobanner; // FIXME: to implement
-  GConfIntegerOption myIconSize;
-
-  static char *ourDirs[];
-};
-
 // Hildon home applet interface functions
 
 void *hildon_home_applet_lib_initialize(void *state_data, int *state_size, GtkWidget **widget) {
-  GConfKey baseKey(SL_APPLET_GCONF_PATH);
-
-  SimpleLauncherApplet *applet = new SimpleLauncherApplet(baseKey);
+  SimpleLauncherApplet *applet = new SimpleLauncherApplet(SL_APPLET_GCONF_PATH);
 
   if (applet != NULL) {
     if (applet->doInit(state_data, state_size)) {
@@ -124,7 +67,7 @@ char *SimpleLauncherApplet::ourDirs[] = {
 };
 
 // SimpleLauncherApplet::SimpleLauncherApplet() : myMainSettings(myClient.getKey(SL_APPLET_GCONF_PATH)), myContext(NULL), myWidget(NULL), myParent(NULL) {
-SimpleLauncherApplet::SimpleLauncherApplet(const GConfKey& base) : myContext(NULL), myWidget(NULL), myParent(NULL), myTransparent(base, "transparent", false), myIconSize(base, "icon_size", 48) {
+SimpleLauncherApplet::SimpleLauncherApplet(const std::string& base) : myContext(NULL), myWidget(NULL), myParent(NULL), myTransparent(GConfKey(base), "transparent", false), myIconSize(GConfKey(base), "icon_size", 48) {
 }
 
 bool SimpleLauncherApplet::doInit(void *state_data, int *state_size) {
index da7a66e..566d27e 100644 (file)
@@ -1,6 +1,6 @@
 // This file is a part of Simple Launcher
 //
-// Copyright (C) 2006, 2007, Mikhail Sobolev
+// Copyright (C) 2006, 2007, 2008 Mikhail Sobolev <mss@mawhrin.net>
 //
 // Simple Launcher is free software; you can redistribute it and/or modify it
 // under the terms of the GNU General Public License version 2 as published by
 #ifndef _SIMPLE_LAUNCHER_H_
 #define _SIMPLE_LAUNCHER_H_
 
+#include <libosso.h>
+
+#include "launcher-item.h"
+#include "launchable-item.h"
+#include "settings-dialog.h"
+#include "gconf-wrapper.h"
+
+#define SL_APPLET_GCONF_PATH  "/apps/simple-launcher"
+
+class SimpleLauncherApplet {
+public:
+  SimpleLauncherApplet(const std::string&);
+ ~SimpleLauncherApplet();
+
+  bool doInit(void *state_data, int *state_size);
+
+  int saveState(void **state_data, int *state_size);
+  GtkWidget *settings(GtkWindow *parent);
+
+  GtkWidget *getWidget() { return myWidget; }
+
+       int getWidth() const;
+       int getHeight() const;
+
+       void getBackgroundColour(double& red, double& green, double& blue, double alpha) const;
+
+private:
+  static void addItem(LauncherItems&, const std::string&, bool);
+
+  void loadConfig();
+  void saveConfig();
+
+  static void updateItems(LauncherItems&);
+  static void processDirectory(LauncherItems&, const std::string&);
+
+  bool initWidget();
+  void updateWidget();
+
+  void buttonPressed(GtkWidget *button, GdkEventButton *event);
+  void runDialog();
+
+  static void _button_pressed(GtkWidget *button, GdkEventButton *event, void *self);
+  static void _run_dialog(GtkMenuItem *, void *);
+
+private:
+  // GConfClientWrapper myClient;
+  // GConfKey myMainSettings;
+
+  osso_context_t *myContext;
+
+  GtkWidget *myWidget;
+  GtkWindow *myParent;
+
+  LauncherItems myItems;
+
+  GConfBooleanOption myTransparent;
+  // bool myShowInfobanner; // FIXME: to implement
+  GConfIntegerOption myIconSize;
+
+  static char *ourDirs[];
+};
+
 #endif