// 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 <hildon-home-plugin/hildon-home-plugin-interface.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);
-
- void background() {}
- void foreground() {}
- 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);
-
- if (applet != NULL) {
- if (applet->doInit(state_data, state_size)) {
- *widget = applet->getWidget();
- } else {
- delete applet;
- applet = NULL;
- }
- }
-
- return (void*)applet;
-}
-
-void hildon_home_applet_lib_deinitialize(void *applet_data) {
- SimpleLauncherApplet *applet = (SimpleLauncherApplet *)applet_data;
-
- delete applet;
-}
-
-void hildon_home_applet_lib_background(void *applet_data) {
- ((SimpleLauncherApplet *)applet_data)->background();
-}
-
-void hildon_home_applet_lib_foreground (void *applet_data) {
- ((SimpleLauncherApplet *)applet_data)->foreground();
-}
-
-GtkWidget *hildon_home_applet_lib_settings(void *applet_data, GtkWindow *parent) {
- return ((SimpleLauncherApplet *)applet_data)->settings(parent);
-}
-
-int hildon_home_applet_lib_save_state (void *applet_data, void **state_data, int *state_size) {
- return ((SimpleLauncherApplet *)applet_data)->saveState(state_data, state_size);
-}
-
// SimpleLauncherApplet implementation
char *SimpleLauncherApplet::ourDirs[] = {
NULL
};
-// 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", true), myIconSize(base, "icon_size", 48) {
+SimpleLauncherApplet::SimpleLauncherApplet(const std::string& base) : myContext(NULL), myWidget(NULL), myParent(NULL), myValidItems(0), myTransparent(GConfKey(base), "transparent", false), myIconSize(GConfKey(base), "icon_size", 48) {
}
-bool SimpleLauncherApplet::doInit(void *state_data, int *state_size) {
+bool SimpleLauncherApplet::doInit() {
if ((myContext = osso_initialize(SL_APPLET_DBUS_NAME, SL_APPLET_VERSION, FALSE, NULL)) == NULL) {
g_debug("sla-applet: failed to initialize the osso layer");
return false;
SimpleLauncherApplet::~SimpleLauncherApplet() {
myItems.clear();
-
+#if 0
+ // This does not seem to be necessary
if (myWidget != NULL) {
gtk_widget_destroy(myWidget);
myWidget = NULL;
}
-
+#endif
if (myContext != NULL) {
osso_deinitialize(myContext);
myContext = NULL;
}
}
-// FIXME: this probably should be done somehow differently
-static char *configFileName="/home/user/.slarc";
+// {{{ Configuration file managment
+static const gchar *getConfigFileName() {
+ static gchar *configFileName = NULL;
+
+ if (configFileName == NULL) {
+ configFileName = g_build_filename(g_get_home_dir(), ".slarc", NULL);
+ }
+
+ return configFileName;
+}
void SimpleLauncherApplet::loadConfig() {
- std::ifstream config(configFileName);
+ std::ifstream config(getConfigFileName());
if (config) {
char *buffer = new char [1024];
addItem(myItems, buffer, (p != NULL && (*p == '1' || *p == 'y' || *p == 'Y')));
}
- delete buffer;
+ delete [] buffer;
}
}
void SimpleLauncherApplet::saveConfig() {
// TODO: make saving config an atomic operation
- std::ofstream config(configFileName);
+ std::ofstream config(getConfigFileName());
if (config) {
for (size_t i = 0 ; i < myItems.size() ; ++i) {
}
}
+// }}}
+
void SimpleLauncherApplet::updateItems(LauncherItems& items) {
for (int i = 0 ; ourDirs[i] != NULL ; ++i) {
processDirectory(items, ourDirs[i]);
GtkSizeGroup *group = gtk_size_group_new(GTK_SIZE_GROUP_BOTH);
- int button_no = 0;
+ myValidItems = 0;
for (size_t i = 0 ; i < myItems.size() ; ++i) {
LauncherItem *item = myItems[i];
gtk_box_pack_start(GTK_BOX(myWidget), GTK_WIDGET(button), false, false, 0);
- ++button_no;
+ ++myValidItems;
}
}
g_object_unref(G_OBJECT(group));
- int totalSize = myIconSize.value();
-
- if (button_no == 0) {
- gtk_widget_set_size_request(myWidget, totalSize, totalSize);
- } else {
- gtk_widget_set_size_request(myWidget, button_no*totalSize, totalSize);
- }
+ gtk_widget_set_size_request(myWidget, getWidth(), getHeight());
gtk_widget_show_all(myWidget);
}
}
}
-int SimpleLauncherApplet::saveState(void **state_data, int *state_size) {
- if (state_data != NULL) {
- *state_data = NULL;
- }
-
- if (state_size != NULL) {
- *state_size = 0;
- }
-
- return 1;
-}
-
GtkWidget *SimpleLauncherApplet::settings(GtkWindow *parent) {
myParent = parent; // FIXME: Ugly piece of code :(
; // FIXME: do I want to do anything in here?
}
- newItems.clear();
+ // newItems.clear(); // TODO: do I really need it?
+}
+
+int SimpleLauncherApplet::getWidth() const {
+ if (myValidItems) {
+ return myIconSize.value() * myValidItems;
+ } else {
+ return myIconSize.value();
+ }
+}
+
+int SimpleLauncherApplet::getHeight() const {
+ return myIconSize.value();
+}
+
+void SimpleLauncherApplet::getBackgroundColour(double& red, double& green, double& blue, double alpha) const {
+ // white :)
+ red = 1.0; green = 1.0; blue = 1.0;
+
+ alpha = myTransparent.value() ? 0.0 : 1.0;
}
-// vim:ts=2:sw=2:et
+// vim:ts=2:sw=2:et:foldmethod=marker