Skip to content

Commit

Permalink
Merge pull request #39 from kalfa/home_widget
Browse files Browse the repository at this point in the history
Home panel's Widgets
  • Loading branch information
djdeath committed Apr 24, 2012
2 parents 6913772 + 1f86a72 commit 5a99ab9
Show file tree
Hide file tree
Showing 9 changed files with 238 additions and 121 deletions.
1 change: 1 addition & 0 deletions panels/home/data/Makefile.am
Expand Up @@ -8,6 +8,7 @@ service_DATA = $(service_in_files:.service.in=.service)
$(QUIET_GEN)sed -e "s|\@libexecdir\@|$(libexecdir)|" $< > $@

gsettings_SCHEMAS = \
org.dawati.shell.home.gschema.xml \
org.dawati.shell.home.plugin.gschema.xml \
$(NULL)

Expand Down
23 changes: 23 additions & 0 deletions panels/home/data/org.dawati.shell.home.gschema.xml
@@ -0,0 +1,23 @@
<schemalist>
<schema path="/org/dawati/shell/home/" id="org.dawati.shell.home">

<key name="widgets-list" type="as">
<default>[]</default>
<summary>List of widgets' object path</summary>
<description>The list of widgets' object path registered to the Panel.</description>
</key>

<key name="size" type="(uu)">
<default>(14, 7)</default>
<summary>The size of the panel's grid</summary>
<description>The width and height iof the panel's grid.</description>
</key>

<key name="background-image" type="s">
<default>'/usr/share/backgrounds/gnome/Aqua.jpg'</default>
<summary>Background image</summary>
<description>The file name for the panel's background image.</description>
</key>

</schema>
</schemalist>
13 changes: 13 additions & 0 deletions panels/home/data/org.dawati.shell.home.plugin.gschema.xml
@@ -1,5 +1,18 @@
<schemalist>
<schema id="org.dawati.shell.home.plugin">

<key name="column" type="i">
<default>-1</default>
<summary>Column position for the plugin</summary>
<description>The column on the grid where the plugin has been placed.</description>
</key>

<key name="row" type="i">
<default>-1</default>
<summary>Row position for the plugin</summary>
<description>The row on the grid where the plugin has been placed.</description>
</key>

<key name="module" type="s">
<default>''</default>
<summary>The plugin module providing this widget</summary>
Expand Down
43 changes: 23 additions & 20 deletions panels/home/plugins/example/example.js
Expand Up @@ -33,45 +33,48 @@ const Example = new Lang.Class({

init: function() {
print("Init");
print(this.settings_path);

this._settings = new Gio.Settings({
schema: 'org.dawati.shell.home.plugin.example',
path: this.settings_path,
});
},

get_widget: function() {
let stack = new Mx.Stack();
/* Init Widget actor */
this.widget = new Mx.Stack();

let bg = new Clutter.Texture({
// FIXME: hack to limit the size of the widget
width: 1,
height: 1,
});
let label = new Mx.Label({ text: "Example Plugin" });

this._settings.bind('picture', bg, 'filename', 0);
});
this._settings.bind('picture', bg, 'filename', 1);

stack.add_actor (bg);
stack.add_actor (label);
let label = new Mx.Label({text: "Example Plugin"});

return stack;
},
this.widget.add_actor(bg);
this.widget.add_actor(label);

get_configuration: function() {
let table = new Mx.Table();

/* Init Configuration actor */
this.configuration = new Mx.Table();
let label = new Mx.Label({ text: "Picture" });
let entry = new Mx.Entry();
this._settings.bind ("picture", entry, "text", 1);

this._settings.bind('picture', entry, 'text', 0);
this.configuration.insert_actor(label, 0, 0);
this.configuration.insert_actor(entry, 0, 1);
},

table.insert_actor(label, 0, 0);
table.insert_actor(entry, 0, 1);
get_widget: function() {
return this.widget;
},

print(this.settings_path);
get_configuration: function() {
return this.configuration;
},

return table;
deinit: function() {
this.widget.unref();
this.configuration.unref();
},
});

Expand Down
20 changes: 17 additions & 3 deletions panels/home/src/mnb-home-grid.c
Expand Up @@ -26,6 +26,8 @@
#include "mnb-home-grid.h"
#include "mnb-home-grid-child.h"
#include "mnb-home-grid-private.h"
#include "mnb-home-widget.h"
#include "utils.h"

#include <math.h>
#include <string.h>
Expand Down Expand Up @@ -699,6 +701,10 @@ stage_button_release_event_cb (ClutterActor *stage,
mnb_home_grid_remove_item_cells (self, priv->selection);
meta->col = priv->selection_col;
meta->row = priv->selection_row;
g_object_set (priv->selection,
"column", meta->col,
"row", meta->row,
NULL);
mnb_home_grid_insert_item_cells (self, priv->selection);

/* Animate selected actor to the final position */
Expand Down Expand Up @@ -773,6 +779,10 @@ mnb_home_grid_button_press_event (ClutterActor *self,
clutter_container_get_child_meta (CLUTTER_CONTAINER (self), child);
gfloat child_width, child_height;

/* be sure it's a MnbHomeWidget, it's a programming error if we obtain
* something else */
g_assert (MNB_IS_HOME_WIDGET (child));

priv->pointer_x = event->x;
priv->pointer_y = event->y;

Expand Down Expand Up @@ -1030,7 +1040,7 @@ mnb_home_grid_paint (ClutterActor *self)
}
}
}
else
else /* !edit_mode */
{
for (l = priv->children; l != NULL; l = g_list_next (l))
{
Expand Down Expand Up @@ -1370,6 +1380,8 @@ mnb_home_grid_set_edit_mode (MnbHomeGrid *self, gboolean value)
return;

priv->in_edit_mode = value;
g_object_notify (G_OBJECT (self), "edit-mode");

clutter_actor_queue_redraw (CLUTTER_ACTOR (self));
}

Expand Down Expand Up @@ -1416,7 +1428,7 @@ mnb_home_grid_insert_actor (MnbHomeGrid *self,
gfloat width, height;

g_return_if_fail (MNB_IS_HOME_GRID (self));
g_return_if_fail (CLUTTER_IS_ACTOR (actor));
g_return_if_fail (MNB_IS_HOME_WIDGET (actor));

priv = self->priv;

Expand All @@ -1435,6 +1447,8 @@ mnb_home_grid_insert_actor (MnbHomeGrid *self,
meta->height = ceilf (height / (UNIT_SIZE + priv->spacing));
mnb_home_grid_insert_item_cells (self, actor);

g_object_bind_property (self, "edit-mode", actor, "edit-mode", G_BINDING_DEFAULT);

clutter_actor_queue_relayout (CLUTTER_ACTOR (self));
}

Expand Down Expand Up @@ -1471,7 +1485,7 @@ mnb_home_grid_set_grid_size (MnbHomeGrid *self, guint cols, guint rows)
}

/**
* mnb_home_grid_set_grid_size:
* mnb_home_grid_get_grid_size:
* @grid: a #MnbHomeGrid
* @cols: (out): the number of columns
* @rows: (out): the number of rows
Expand Down
87 changes: 53 additions & 34 deletions panels/home/src/mnb-home-panel.c
Expand Up @@ -26,6 +26,11 @@

G_DEFINE_TYPE (MnbHomePanel, mnb_home_panel, MX_TYPE_WIDGET);

#define GSETTINGS_HOME_ID "org.dawati.shell.home"
#define GSETTINGS_HOME_PATH_PREFIX "/org/dawati/shell/home/"
#define GSETTINGS_HOME_BACKGROUND_KEY "background-image"
#define GSETTINGS_HOME_SIZE_KEY "size"

#define BUTTON_HOVER_TIMEOUT (750)
#define TAB_SWITCHING_TIMEOUT (400)
#define NB_TABS (5)
Expand All @@ -50,6 +55,9 @@ struct _MnbHomePanelPrivate
guint timeout_switch_tab;
gint workspace_dest;
MxButton *workspace_button;

GSettings *settings;
GList *widgets;
};

static void
Expand Down Expand Up @@ -246,7 +254,15 @@ mnb_home_panel_dispose (GObject *self)
{
MnbHomePanelPrivate *priv = MNB_HOME_PANEL (self)->priv;

g_object_unref (priv->panel_client);
g_clear_object (&priv->panel_client);
g_clear_object (&priv->background);
g_clear_object (&priv->grid);
g_clear_object (&priv->settings);
if (priv->widgets != NULL)
{
g_list_free_full (priv->widgets, g_object_unref);
priv->widgets = NULL;
}

G_OBJECT_CLASS (mnb_home_panel_parent_class)->dispose (self);
}
Expand Down Expand Up @@ -324,17 +340,24 @@ mnb_home_panel_init (MnbHomePanel *self)
{
MnbHomePanelPrivate *priv;
ClutterActor *edit, *item, *box;
ClutterColor *color;
GVariant *as;
GVariantIter iter;
guint col, row;
gchar *path;
gint i;
guint grid_width, grid_height;

self->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (self, MNB_TYPE_HOME_PANEL,
MnbHomePanelPrivate);

priv->settings = g_settings_new_with_path (GSETTINGS_HOME_ID,
GSETTINGS_HOME_PATH_PREFIX);

/* background */
/* FIXME: make this awesomer */
priv->background = mx_image_new ();
mx_image_set_from_file (MX_IMAGE (priv->background),
"/usr/share/backgrounds/gnome/Aqua.jpg", NULL);
g_settings_bind (priv->settings, GSETTINGS_HOME_BACKGROUND_KEY,
priv->background, "filename",
G_SETTINGS_BIND_GET);
clutter_actor_add_child (CLUTTER_ACTOR (self), priv->background);

priv->vbox = mx_box_layout_new_with_orientation (MX_ORIENTATION_VERTICAL);
Expand All @@ -354,7 +377,11 @@ mnb_home_panel_init (MnbHomePanel *self)
NULL);

priv->grid = mnb_home_grid_new ();
mnb_home_grid_set_grid_size (MNB_HOME_GRID (priv->grid), 40, 6); /* TODO: auto! */

g_settings_get (priv->settings, GSETTINGS_HOME_SIZE_KEY,
"(uu)", &grid_width, &grid_height);

mnb_home_grid_set_grid_size (MNB_HOME_GRID (priv->grid), grid_width, grid_height); /* TODO: auto! */
mx_bin_set_child (MX_BIN (priv->scrollview), priv->grid);

g_signal_connect (priv->grid, "drag-begin",
Expand Down Expand Up @@ -407,34 +434,26 @@ mnb_home_panel_init (MnbHomePanel *self)
G_CALLBACK (toggle_edit_mode),
self);

/* TODO: Demo, to remove when we have actual tiles */
color = clutter_color_new (0x0, 0, 0, 0xff);

/**/
clutter_color_from_string (color, "red");
item = clutter_rectangle_new_with_color (color);
clutter_actor_set_size (item, 64, 64);
mnb_home_grid_insert_actor (MNB_HOME_GRID (priv->grid), item, 0, 0);

/**/
clutter_color_from_string (color, "green");
item = clutter_rectangle_new_with_color (color);
clutter_actor_set_size (item, 64, 64);
mnb_home_grid_insert_actor (MNB_HOME_GRID (priv->grid), item, 3, 0);

/**/
clutter_color_from_string (color, "black");
item = clutter_rectangle_new_with_color (color);
clutter_actor_set_size (item, 50, 50);
mnb_home_grid_insert_actor (MNB_HOME_GRID (priv->grid), item, 3, 3);

/**/
clutter_color_from_string (color, "grey");
item = clutter_rectangle_new_with_color (color);
clutter_actor_set_size (item, 138, 138);
mnb_home_grid_insert_actor (MNB_HOME_GRID (priv->grid), item, 5, 3);

clutter_color_free (color);
/* Load all widgets added to the panel */
as = g_settings_get_value (priv->settings, "widgets-list");

g_variant_iter_init (&iter, as);
while (g_variant_iter_next (&iter, "s", &path))
{
item = mnb_home_widget_new (path);

g_object_get (item, "column", &col, "row", &row, NULL);
/* TODO: get the size of the widget from the object, which should have a
* resonable default */
clutter_actor_set_size (item, 138, 138);

mnb_home_grid_insert_actor (MNB_HOME_GRID (priv->grid), item, col, row);
priv->widgets = g_list_prepend (priv->widgets, item);

g_free (path);
}

g_variant_unref (as);

clutter_actor_show_all (CLUTTER_ACTOR (self));
}
Expand Down

0 comments on commit 5a99ab9

Please sign in to comment.