aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/e_view_look.c179
-rw-r--r--src/e_view_look.h50
2 files changed, 229 insertions, 0 deletions
diff --git a/src/e_view_look.c b/src/e_view_look.c
new file mode 100644
index 000000000..45c3f138e
--- /dev/null
+++ b/src/e_view_look.c
@@ -0,0 +1,179 @@
+#include "e_view_look.h"
+#include "util.h"
+#include "view.h"
+#include "observer.h"
+#include "e_file.h"
+#include "e_dir.h"
+#include "view_layout.h"
+#include "e_view_machine.h"
+
+static void e_view_look_file_delete(E_View_Look *l, E_File *f);
+static void e_view_look_file_change(E_View_Look *l, E_File *f);
+static void e_view_look_cleanup(E_View_Look *l);
+static void e_view_look_objects_cleanup(E_View_Look_Objects *o);
+static void e_view_look_event_handler(E_Observer *obs, E_Observee *o, E_Event_Type event, void *data);
+
+
+E_View_Look *
+e_view_look_new(void)
+{
+ E_View_Look *l;
+ D_ENTER;
+
+ l = NEW(E_View_Look, 1);
+ ZERO(l, E_View_Look, 1);
+ e_observer_init(E_OBSERVER(l),
+ E_EVENT_FILE_ADD | E_EVENT_FILE_DELETE |
+ E_EVENT_FILE_CHANGE,
+ (E_Notify_Func) e_view_look_event_handler,
+ (E_Cleanup_Func) e_view_look_cleanup);
+
+ l->obj = NEW(E_View_Look_Objects, 1);
+ ZERO(l->obj, E_View_Look_Objects, 1);
+
+ l->obj->bg = NULL;
+ l->obj->icb = NULL;
+ l->obj->icb_bits = NULL;
+ l->obj->layout = NULL;
+ e_observee_init(E_OBSERVEE(l->obj), (E_Cleanup_Func) e_view_look_objects_cleanup);
+
+ e_view_machine_register_look(l);
+
+ D_RETURN_(l);
+}
+
+static void
+e_view_look_cleanup(E_View_Look *l)
+{
+ D_ENTER;
+ e_view_machine_unregister_look(l);
+ e_object_unref(E_OBJECT(l->obj));
+ e_object_cleanup(E_OBJECT(l));
+ D_RETURN;
+}
+
+static void
+e_view_look_objects_cleanup(E_View_Look_Objects *l)
+{
+ D_ENTER;
+ IF_FREE(l->bg);
+ IF_FREE(l->icb);
+ IF_FREE(l->icb_bits);
+ IF_FREE(l->layout);
+ e_object_cleanup(E_OBJECT(l));
+ D_RETURN;
+}
+
+static void
+e_view_look_event_handler(E_Observer *obs, E_Observee *o, E_Event_Type event, void *data)
+{
+ E_View_Look *l = (E_View_Look *) obs;
+ E_File *f = (E_File *) data;
+ D_ENTER;
+
+ if (event & E_EVENT_FILE_CHANGE || event & E_EVENT_FILE_ADD)
+ e_view_look_file_change(l, f);
+ else if (event & E_EVENT_FILE_DELETE)
+ e_view_look_file_delete(l, f);
+
+ D_RETURN;
+ UN(o);
+}
+
+
+void
+e_view_look_set_dir(E_View_Look *l, char *dir)
+{
+ E_Dir *d = NULL;
+ D_ENTER;
+
+ if (!(d = e_view_machine_dir_lookup(dir)))
+ {
+ D("Model for this dir doesn't exist, make a new one\n");
+ d = e_dir_new();
+ e_dir_set_dir(d, dir);
+ }
+ else
+ e_object_ref(E_OBJECT(d));
+
+ if (d)
+ {
+ l->dir = d;
+ e_observer_register_observee(E_OBSERVER(l), E_OBSERVEE(d));
+ }
+ else
+ {
+ D("Couldnt set dir for E_View_Look! Bad!\n");
+ }
+ D_RETURN;
+}
+
+
+/* React to file event */
+
+static void
+e_view_look_file_change(E_View_Look *l, E_File *f)
+{
+ char buf[PATH_MAX];
+ D_ENTER;
+ snprintf(buf, PATH_MAX, "%s/%s", l->dir->dir, f->file);
+ if (!strcmp(f->file, "background.db"))
+ {
+ IF_FREE(l->obj->bg);
+ l->obj->bg = strdup(buf);
+ e_observee_notify_observers(E_OBSERVEE(l->obj), E_EVENT_BG_CHANGED, f);
+ }
+ else if (!strcmp(f->file, "iconbar.db"))
+ {
+ IF_FREE(l->obj->icb);
+ l->obj->icb = strdup(buf);
+ e_observee_notify_observers(E_OBSERVEE(l->obj), E_EVENT_ICB_CHANGED, f);
+ }
+ else if (!strcmp(f->file, "iconbar.bits.db"))
+ {
+ IF_FREE(l->obj->icb_bits);
+ l->obj->icb_bits = strdup(buf);
+ e_observee_notify_observers(E_OBSERVEE(l->obj), E_EVENT_ICB_CHANGED, f);
+ }
+ else if (!strcmp(f->file, "layout.db"))
+ {
+ IF_FREE(l->obj->layout);
+ l->obj->layout = strdup(buf);
+ e_observee_notify_observers(E_OBSERVEE(l->obj), E_EVENT_LAYOUT_CHANGED, f);
+ }
+ D_RETURN;
+}
+
+static void
+e_view_look_file_delete(E_View_Look *l, E_File *f)
+{
+ D_ENTER;
+
+ if (!strcmp(f->file, "background.db"))
+ {
+ IF_FREE(l->obj->bg);
+ l->obj->bg = NULL;
+ e_observee_notify_observers(E_OBSERVEE(l->obj), E_EVENT_BG_CHANGED, f);
+ }
+ else if ( !strcmp(f->file, "iconbar.db"))
+ {
+ IF_FREE(l->obj->icb);
+ l->obj->icb = NULL;
+ e_observee_notify_observers(E_OBSERVEE(l->obj), E_EVENT_ICB_CHANGED, f);
+ }
+
+ else if (!strcmp(f->file, "iconbar.bits.db"))
+ {
+ IF_FREE(l->obj->icb_bits);
+ l->obj->icb_bits = NULL;
+ e_observee_notify_observers(E_OBSERVEE(l->obj), E_EVENT_ICB_CHANGED, f);
+ }
+ else if (!strcmp(f->file, "layout.db"))
+ {
+ IF_FREE(l->obj->layout);
+ l->obj->layout = NULL;
+ e_observee_notify_observers(E_OBSERVEE(l->obj), E_EVENT_LAYOUT_CHANGED, f);
+ }
+
+ D_RETURN;
+}
diff --git a/src/e_view_look.h b/src/e_view_look.h
new file mode 100644
index 000000000..aa4cf2da8
--- /dev/null
+++ b/src/e_view_look.h
@@ -0,0 +1,50 @@
+#ifndef E_VIEW_LOOK_H
+#define E_VIEW_LOOK_H
+#include "observer.h"
+#include "view_layout.h"
+#include "e_dir.h"
+#include <Evas.h>
+
+#ifndef E_VIEW_LOOK_TYPEDEF
+#define E_VIEW_LOOK_TYPEDEF
+typedef struct _E_View_Look E_View_Look;
+typedef struct _E_View_Look_Objects E_View_Look_Objects;
+#endif
+
+
+#ifndef E_DIR_TYPEDEF
+#define E_DIR_TYPEDEF
+typedef struct _E_Dir E_Dir;
+#endif
+#ifndef E_VIEW_LAYOUT_TYPEDEF
+#define E_VIEW_LAYOUT_TYPEDEF
+typedef struct _E_View_Layout E_View_Layout;
+typedef struct _E_View_Layout_Element E_View_Layout_Element;
+#endif
+
+struct _E_View_Look
+{
+ E_Observer o;
+
+ E_View_Look_Objects *obj;
+
+ /* The .e_layout dir to monitor */
+ E_Dir *dir;
+};
+
+struct _E_View_Look_Objects
+{
+ E_Observee o;
+
+ /* FIXME keep the bits/objects themselves here */
+
+ char *bg;
+ char *icb;
+ char *icb_bits;
+ char *layout;
+};
+
+E_View_Look *e_view_look_new(void);
+void e_view_look_set_dir(E_View_Look *l, char *dir);
+
+#endif