aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--shell/e-shell-shortcut.c208
-rw-r--r--shell/e-shell-view.c76
-rw-r--r--shell/e-shell.c38
-rw-r--r--shell/e-shell.h5
-rw-r--r--shell/e-shortcut.c347
-rw-r--r--shell/e-shortcut.h79
6 files changed, 551 insertions, 202 deletions
diff --git a/shell/e-shell-shortcut.c b/shell/e-shell-shortcut.c
index 6e6aaf8260..a04171bdd2 100644
--- a/shell/e-shell-shortcut.c
+++ b/shell/e-shell-shortcut.c
@@ -17,28 +17,80 @@
#define LARGE_ICONS 2
static void
-set_large_icons (GtkMenu *menu, EShellView *eshell_view)
+set_large_icons (GtkMenuItem *menu_item, EShellView *eshell_view)
{
+ EShortcutGroup *sg = gtk_object_get_data (GTK_OBJECT (menu_item), "shortcut_group");
+
+ g_assert (sg != NULL);
+ e_shortcut_group_set_view_type (sg, E_ICON_BAR_LARGE_ICONS);
}
static void
-set_small_icons (GtkMenu *menu, EShellView *eshell_view)
+set_small_icons (GtkMenu *menu_item, EShellView *eshell_view)
{
+ EShortcutGroup *sg = gtk_object_get_data (GTK_OBJECT (menu_item), "shortcut_group");
+
+ g_assert (sg != NULL);
+ e_shortcut_group_set_view_type (sg, E_ICON_BAR_SMALL_ICONS);
}
static void
add_group (GtkMenu *menu, EShellView *eshell_view)
{
+ int group_num;
+ GtkWidget *entry;
+
+ group_num = e_shortcut_bar_model_add_group (eshell_view->eshell->shortcut_bar);
+
+ /*
+ * FIXME: Figure out why this does not quite work
+ */
+ entry = gtk_entry_new ();
+ gtk_widget_show (entry);
+
+ e_group_bar_set_group_button_label (
+ E_GROUP_BAR (eshell_view->shortcut_bar),
+ group_num,
+ entry);
}
static void
-remove_group (GtkMenu *menu, EShellView *eshell_view)
+remove_group (GtkMenuItem *menu_item, EShellView *eshell_view)
{
+ EShortcutGroup *sg = gtk_object_get_data (GTK_OBJECT (menu_item), "shortcut_group");
+
+ g_assert (sg != NULL);
+
+ e_shortcut_bar_model_remove_group (eshell_view->eshell->shortcut_bar, sg);
}
static void
-rename_group (GtkMenu *menu, EShellView *eshell_view)
+do_rename (GtkEntry *entry, EShortcutGroup *sg)
{
+ e_shortcut_group_rename (sg, gtk_entry_get_text (entry));
+}
+
+static void
+rename_group (GtkMenuItem *menu_item, EShellView *eshell_view)
+{
+ EShortcutGroup *sg = gtk_object_get_data (GTK_OBJECT (menu_item), "shortcut_group");
+ GtkWidget *entry;
+ int item;
+
+ g_assert (sg != NULL);
+
+ item = e_group_num_from_group_ptr (eshell_view->eshell->shortcut_bar, sg);
+ e_shortcut_group_rename (sg, "Dum de da");
+
+ return;
+
+ entry = gtk_entry_new ();
+ gtk_widget_show (entry);
+ gtk_widget_grab_focus (entry);
+
+ gtk_signal_connect (GTK_OBJECT (entry), "activate", GTK_SIGNAL_FUNC (do_rename), sg);
+
+ e_group_bar_set_group_button_label (E_GROUP_BAR (eshell_view->shortcut_bar), item, entry);
}
static void
@@ -72,19 +124,24 @@ shortcut_bar_show_standard_popup (EShellView *eshell_view, GdkEvent *event, ESho
menu = gtk_menu_new ();
for (i = 0; i < ELEMENTS (shortcut_menu); i++){
+ gboolean disable = FALSE;
+
if (shortcut_menu [i].flags & SMALL_ICONS)
- if (!shortcut_group->small_icons)
- continue;
+ if (shortcut_group->type != E_ICON_BAR_SMALL_ICONS)
+ disable = TRUE;
if (shortcut_menu [i].flags & LARGE_ICONS)
- if (shortcut_group->small_icons)
- continue;
+ if (shortcut_group->type != E_ICON_BAR_LARGE_ICONS)
+ disable = TRUE;
if (shortcut_menu [i].label == NULL){
menuitem = gtk_menu_item_new ();
gtk_widget_set_sensitive (menuitem, FALSE);
} else
menuitem = gtk_menu_item_new_with_label (_(shortcut_menu [i].label));
+
+ if (disable)
+ gtk_widget_set_sensitive (menuitem, FALSE);
gtk_widget_show (menuitem);
gtk_menu_append (GTK_MENU (menu), menuitem);
@@ -98,48 +155,141 @@ shortcut_bar_show_standard_popup (EShellView *eshell_view, GdkEvent *event, ESho
}
gtk_signal_connect (GTK_OBJECT (menu), "deactivate",
- GTK_SIGNAL_FUNC (gtk_object_destroy), NULL);
-
+ GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
+
gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
event->button.button, event->button.time);
+
+ gtk_main ();
+
+ gtk_object_destroy (GTK_OBJECT (menu));
}
static void
-shortcut_bar_show_context_popup (EShellView *eshell_view, GdkEvent *event, EShortcutGroup *shortcut_group)
+shortcut_open (GtkMenuItem *menuitem, EShellView *eshell_view)
{
- printf ("Context popup\n");
}
-static EShortcut *
-shortcut_from_pos (EShellView *eshell_view, int group_num, int item_num, EShortcutGroup **group_result)
+static void
+shortcut_open_new_window (GtkMenuItem *menuitem, EShellView *eshell_view)
{
- EShell *eshell = eshell_view->eshell;
- EShortcutGroup *group;
- EShortcut *shortcut;
+}
+
+static void
+shortcut_remove (GtkMenuItem *menuitem, EShellView *eshell_view)
+{
+}
+
+static void
+shortcut_rename (GtkMenuItem *menuitem, EShellView *eshell_view)
+{
+ printf ("Implement: %s %s\n", __FILE__, __FUNCTION__);
+}
+
+static void
+shortcut_properties (GtkMenuItem *menuitem, EShellView *eshell_view)
+{
+ printf ("Implement: %s %s\n", __FILE__, __FUNCTION__);
+}
+
+#define NOT_IMPLEMENTED 1
+static struct {
+ char *label;
+ char *stock_id;
+ int flags;
+ GtkSignalFunc callback;
+} context_shortcut_menu [] = {
+ { N_("Open Folder"), GNOME_STOCK_MENU_OPEN, 0, GTK_SIGNAL_FUNC (shortcut_open) },
+ { N_("Open in New Window"), NULL, 0, GTK_SIGNAL_FUNC (shortcut_open_new_window) },
+ { N_("Advanced Find"), NULL, NOT_IMPLEMENTED, NULL },
+ { NULL, },
+ { N_("Remove From Shortcut Bar"), NULL, 0, GTK_SIGNAL_FUNC (shortcut_remove) },
+ { N_("Rename Shortcut"), NULL, 0, GTK_SIGNAL_FUNC (shortcut_rename) },
+ { NULL, },
+ { N_("Properties"), NULL, 0, GTK_SIGNAL_FUNC (shortcut_properties) },
+};
- if (item_num == -1)
- return NULL;
+static void
+shortcut_bar_show_context_popup (EShellView *eshell_view, GdkEvent *event, EShortcutGroup *shortcut_group)
+{
+ GtkWidget *menu, *menuitem;
+ int i;
+ gboolean disable;
- g_assert (group_num < eshell->shortcut_groups->len);
- group = g_array_index (eshell->shortcut_groups, EShortcutGroup *, group_num);
+ menu = gtk_menu_new ();
+
+ for (i = 0; i < ELEMENTS (context_shortcut_menu); i++){
+ disable = FALSE;
+
+ if (context_shortcut_menu [i].flags & NOT_IMPLEMENTED)
+ disable = TRUE;
+
+ if (context_shortcut_menu [i].label == NULL){
+ menuitem = gtk_menu_item_new ();
+ gtk_widget_set_sensitive (menuitem, FALSE);
+ } else {
+ GtkWidget *label;
+
+ if (context_shortcut_menu [i].stock_id){
+ GtkWidget *stock;
+
+ menuitem = gtk_pixmap_menu_item_new ();
+ stock = gnome_stock_pixmap_widget (
+ menu,
+ context_shortcut_menu [i].stock_id);
+ if (stock){
+ gtk_widget_show (stock);
+ gtk_pixmap_menu_item_set_pixmap (
+ GTK_PIXMAP_MENU_ITEM (menuitem), stock);
+ }
+ } else
+ menuitem = gtk_menu_item_new ();
+
+ label = gtk_label_new (_(context_shortcut_menu [i].label));
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ gtk_widget_show (label);
+ gtk_container_add (GTK_CONTAINER (menuitem), label);
+ }
+
+ if (disable)
+ gtk_widget_set_sensitive (menuitem, FALSE);
+
+ gtk_widget_show (menuitem);
+ gtk_menu_append (GTK_MENU (menu), menuitem);
- g_assert (item_num < group->shortcuts->len);
- shortcut = g_array_index (group->shortcuts, EShortcut *, item_num);
+ gtk_signal_connect (
+ GTK_OBJECT (menuitem), "activate",
+ context_shortcut_menu [i].callback, eshell_view);
+ gtk_object_set_data (
+ GTK_OBJECT (menuitem), "shortcut_group",
+ shortcut_group);
+ }
- *group_result = group;
+ gtk_signal_connect (GTK_OBJECT (menu), "deactivate",
+ GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
+
+ gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
+ event->button.button, event->button.time);
+
+ gtk_main ();
- return shortcut;
+ gtk_object_destroy (GTK_OBJECT (menu));
}
void
-shortcut_bar_item_selected (EShortcutBar *shortcut_bar,
+shortcut_bar_item_selected (EShortcutBar *e_shortcut_bar,
GdkEvent *event, gint group_num, gint item_num,
EShellView *eshell_view)
{
EShortcut *shortcut;
EShortcutGroup *shortcut_group;
-
- shortcut = shortcut_from_pos (eshell_view, group_num, item_num, &shortcut_group);
+ EShortcutBarModel *shortcut_bar = eshell_view->eshell->shortcut_bar;
+
+ shortcut_group = e_shortcut_group_from_pos (shortcut_bar, group_num);
+ if (shortcut_group == NULL)
+ return;
+
+ shortcut = e_shortcut_from_pos (shortcut_group, item_num);
if (group_num == -1)
return;
@@ -153,7 +303,7 @@ shortcut_bar_item_selected (EShortcutBar *shortcut_bar,
eshell_view, event, shortcut_group);
else
shortcut_bar_show_context_popup (
- eshell_view, event, shortcut);
+ eshell_view, event, shortcut_group);
}
}
diff --git a/shell/e-shell-view.c b/shell/e-shell-view.c
index 34438e4556..300a996959 100644
--- a/shell/e-shell-view.c
+++ b/shell/e-shell-view.c
@@ -48,89 +48,21 @@ e_shell_view_setup (EShellView *eshell_view)
static void
e_shell_view_setup_shortcut_display (EShellView *eshell_view)
{
- gtk_widget_push_visual (gdk_rgb_get_visual ());
- gtk_widget_push_colormap (gdk_rgb_get_cmap ());
-
+ eshell_view->shortcut_bar = e_shortcut_bar_view_new (eshell_view->eshell->shortcut_bar);
+
eshell_view->shortcut_hpaned = gtk_hpaned_new ();
gtk_widget_show (eshell_view->shortcut_hpaned);
-
- eshell_view->shortcut_bar = e_shortcut_bar_new ();
gtk_paned_set_position (GTK_PANED (eshell_view->shortcut_hpaned), 100);
gtk_paned_pack1 (GTK_PANED (eshell_view->shortcut_hpaned),
eshell_view->shortcut_bar, FALSE, TRUE);
gtk_widget_show (eshell_view->shortcut_bar);
- gtk_widget_pop_visual ();
- gtk_widget_pop_colormap ();
-
gnome_app_set_contents (GNOME_APP (eshell_view), eshell_view->shortcut_hpaned);
gtk_signal_connect (
GTK_OBJECT (eshell_view->shortcut_bar), "item_selected",
GTK_SIGNAL_FUNC (shortcut_bar_item_selected), eshell_view);
-
-}
-
-static void
-e_shell_view_load_group (EShell *eshell, EShellView *eshell_view, EShortcutGroup *esg)
-{
- EShortcutBar *bar = E_SHORTCUT_BAR (eshell_view->shortcut_bar);
- int group_num, i;
- const int items = esg->shortcuts->len;
-
- group_num = e_shortcut_bar_add_group (bar, esg->title);
- if (esg->small_icons)
- e_shortcut_bar_set_view_type (bar, group_num, E_ICON_BAR_SMALL_ICONS);
-
- for (i = 0; i < items; i++){
- EShortcut *shortcut = E_SHORTCUT (g_array_index (esg->shortcuts, EShortcut *, i));
- EFolder *folder = shortcut->efolder;
- char *type = NULL;
-
- switch (folder->type){
- case E_FOLDER_MAIL:
- type = "folder:";
- break;
-
- case E_FOLDER_CONTACTS:
- type = "contacts:";
- break;
-
- case E_FOLDER_CALENDAR:
- type = "calendar:";
- break;
-
- case E_FOLDER_TASKS:
- type = "todo:";
- break;
-
- case E_FOLDER_OTHER:
- type = "file:";
- break;
-
- default:
- g_assert_not_reached ();
- }
-
- e_shortcut_bar_add_item (bar, group_num, type, folder->name);
- }
-}
-
-static void
-e_shell_view_load_shortcut_bar (EShellView *eshell_view)
-{
- EShell *eshell = eshell_view->eshell;
- const int groups = eshell->shortcut_groups->len;
- int i;
-
- for (i = 0; i < groups; i++){
- EShortcutGroup *esg;
-
- esg = g_array_index (eshell->shortcut_groups, EShortcutGroup *, i);
-
- e_shell_view_load_group (eshell, eshell_view, esg);
- }
}
GtkWidget *
@@ -146,14 +78,14 @@ e_shell_view_new (EShell *eshell, gboolean show_shortcut_bar)
e_shell_view_setup (eshell_view);
e_shell_view_setup_menus (eshell_view);
+ e_shell_register_view (eshell, eshell_view);
+
if (show_shortcut_bar){
e_shell_view_setup_shortcut_display (eshell_view);
- e_shell_view_load_shortcut_bar (eshell_view);
} else {
g_error ("Non-shortcut bar code not written yet");
}
- e_shell_register_view (eshell, eshell_view);
eshell_view->shortcut_displayed = show_shortcut_bar;
diff --git a/shell/e-shell.c b/shell/e-shell.c
index 4382dc7ed9..9be32ba3c1 100644
--- a/shell/e-shell.c
+++ b/shell/e-shell.c
@@ -153,28 +153,13 @@ es_destroy_default_folders (EShell *eshell)
}
static void
-es_destroy_shortcuts (EShell *eshell)
-{
- const int len = eshell->shortcut_groups->len;
- int i;
-
- for (i = 0; i < len; i++){
- EShortcutGroup *g = g_array_index (eshell->shortcut_groups, EShortcutGroup *, i);
-
- gtk_object_unref (GTK_OBJECT (g));
- }
-
- g_array_free (eshell->shortcut_groups, TRUE);
-}
-
-static void
e_shell_destroy (GtkObject *object)
{
EShell *eshell = E_SHELL (object);
- es_destroy_shortcuts (eshell);
-
+ gtk_object_unref (GTK_OBJECT (eshell->shortcut_bar));
es_destroy_default_folders (eshell);
+
GTK_OBJECT_CLASS (e_shell_parent_class)->destroy (object);
}
@@ -190,7 +175,6 @@ e_shell_class_init (GtkObjectClass *object_class)
static void
e_shell_destroy_views (EShell *eshell)
{
- GSList *l;
/*
* Notice that eshell->views is updated by the various views
@@ -294,17 +278,13 @@ setup_secondary_shortcuts (EShell *eshell)
static void
e_shell_setup_default_shortcuts (EShell *eshell)
{
- GArray *esg;
- EShortcutGroup *g;
-
- esg = g_array_new (FALSE, FALSE, sizeof (EShortcutGroup *));
-
- g = setup_main_shortcuts (eshell);
- g_array_append_val (esg, g);
- g = setup_secondary_shortcuts (eshell);
- g_array_append_val (esg, g);
-
- eshell->shortcut_groups = esg;
+ eshell->shortcut_bar = e_shortcut_bar_model_new ();
+ e_shortcut_bar_model_append (
+ eshell->shortcut_bar,
+ setup_main_shortcuts (eshell));
+ e_shortcut_bar_model_append (
+ eshell->shortcut_bar,
+ setup_secondary_shortcuts (eshell));
}
static void
diff --git a/shell/e-shell.h b/shell/e-shell.h
index 213f6deb14..b2778f0444 100644
--- a/shell/e-shell.h
+++ b/shell/e-shell.h
@@ -31,10 +31,7 @@ struct _EShell {
EFolder *contacts;
} default_folders;
- /*
- * An array of EShortcutGroups
- */
- GArray *shortcut_groups;
+ EShortcutBarModel *shortcut_bar;
};
typedef struct {
diff --git a/shell/e-shortcut.c b/shell/e-shortcut.c
index ec83bc3854..767f9e4067 100644
--- a/shell/e-shortcut.c
+++ b/shell/e-shortcut.c
@@ -9,22 +9,26 @@
*/
#include <config.h>
#include <gtk/gtksignal.h>
+#include <gtk/gtkmisc.h>
+#include <libgnome/libgnome.h>
#include "e-util/e-util.h"
#include "e-shortcut.h"
+#include "shortcut-bar/e-shortcut-bar.h"
+#include "shortcut-bar/e-clipped-label.h"
#define SHORTCUT_PARENT_TYPE gtk_object_get_type ()
+#define SHORTCUT_BAR_MODEL_PARENT_TYPE gtk_object_get_type ()
#define SHORTCUT_GROUP_PARENT_TYPE gtk_object_get_type ()
static GtkObjectClass *shortcut_parent_class;
static GtkObjectClass *shortcut_group_parent_class;
+static GtkObjectClass *shortcut_bar_model_parent_class;
enum {
STRUCTURE_CHANGED,
LAST_SIGNAL
};
-static unsigned int sg_signals [LAST_SIGNAL] = { 0, };
-
static void
es_destroy (GtkObject *object)
{
@@ -58,49 +62,16 @@ esg_destroy (GtkObject *object)
}
g_array_free (efg->shortcuts, TRUE);
+ efg->model = NULL;
shortcut_group_parent_class->destroy (object);
}
-typedef void (*MyGtkSignal_NONE__INT_INT_INT) (GtkObject * object,
- int arg1,
- int arg2,
- int arg3,
- gpointer user_data);
-static void
-mygtk_marshal_NONE__INT_INT_INT (GtkObject * object,
- GtkSignalFunc func,
- gpointer func_data,
- GtkArg * args)
-{
- MyGtkSignal_NONE__INT_INT_INT rfunc;
- rfunc = (MyGtkSignal_NONE__INT_INT_INT) func;
-
- (*rfunc) (object,
- GTK_VALUE_INT (args[0]),
- GTK_VALUE_INT (args[1]),
- GTK_VALUE_INT (args[2]),
- func_data);
-}
-
static void
e_shortcut_group_class_init (GtkObjectClass *object_class)
{
object_class->destroy = esg_destroy;
shortcut_parent_class = gtk_type_class (SHORTCUT_GROUP_PARENT_TYPE);
-
- sg_signals [STRUCTURE_CHANGED] =
- gtk_signal_new ("structure_changed",
- GTK_RUN_LAST,
- object_class->type,
- GTK_SIGNAL_OFFSET (EShortcutGroupClass, structure_changed),
- mygtk_marshal_NONE__INT_INT_INT,
- GTK_TYPE_NONE,
- 3,
- GTK_TYPE_ENUM, GTK_TYPE_INT, GTK_TYPE_INT);
- gtk_object_class_add_signals (
- object_class, sg_signals, LAST_SIGNAL);
-
}
static void
@@ -108,12 +79,11 @@ e_shortcut_group_init (GtkObject *object)
{
EShortcutGroup *esg = E_SHORTCUT_GROUP (object);
+ GTK_OBJECT_UNSET_FLAGS (GTK_OBJECT (object), GTK_FLOATING);
+
esg->shortcuts = g_array_new (FALSE, FALSE, sizeof (EShortcut *));
}
-E_MAKE_TYPE (e_shortcut, "EShortcut", EShortcut, e_shortcut_class_init, NULL, SHORTCUT_PARENT_TYPE);
-E_MAKE_TYPE (e_shortcut_group, "EShortcutGroup", EShortcutGroup, e_shortcut_group_class_init, e_shortcut_group_init, SHORTCUT_GROUP_PARENT_TYPE);
-
EShortcut *
e_shortcut_new (EFolder *efolder)
{
@@ -126,21 +96,15 @@ e_shortcut_new (EFolder *efolder)
}
EShortcutGroup *
-e_shortcut_group_new (const char *title, gboolean small_icons)
+e_shortcut_group_new (const char *title, EIconBarViewType type)
{
EShortcutGroup *shortcut_group = gtk_type_new (e_shortcut_group_get_type ());
shortcut_group->title = g_strdup (title);
- shortcut_group->small_icons = small_icons;
+ shortcut_group->type = type;
return shortcut_group;
}
-static void
-es_emit (EShortcutGroup *sg, EShortcutGroupChange change, int arg1, int arg2)
-{
- gtk_signal_emit (GTK_OBJECT (sg), sg_signals [STRUCTURE_CHANGED], change, arg1, arg2);
-}
-
void
e_shortcut_group_append (EShortcutGroup *sg, EShortcut *shortcut)
{
@@ -150,9 +114,11 @@ e_shortcut_group_append (EShortcutGroup *sg, EShortcut *shortcut)
g_return_if_fail (E_IS_SHORTCUT (shortcut));
gtk_object_ref (GTK_OBJECT (shortcut));
+ gtk_object_sink (GTK_OBJECT (shortcut));
+
g_array_append_val (sg->shortcuts, shortcut);
- es_emit (sg, E_SHORTCUT_GROUP_ITEM_ADDED, sg->shortcuts->len-1, 0);
+ /* FIXME: Broadcast change */
}
void
@@ -172,7 +138,7 @@ e_shortcut_group_remove (EShortcutGroup *sg, EShortcut *shortcut)
if (es == shortcut){
g_array_remove_index (sg->shortcuts, i);
- es_emit (sg, E_SHORTCUT_GROUP_ITEM_REMOVED, i, 0);
+ /* FIXME: Broadcast change */
return;
}
}
@@ -200,5 +166,286 @@ e_shortcut_group_move (EShortcutGroup *sg, int from, int to)
g_array_index (sg->shortcuts, EShortcut *, to);
g_array_index (sg->shortcuts, EShortcut *, to) = t;
- es_emit (sg, E_SHORTCUT_GROUP_ITEM_MOVED, from, to);
+ /* FIXME: Broadcast change */
+}
+
+void
+e_shortcut_group_rename (EShortcutGroup *sg, const char *text)
+{
+ GSList *l;
+ int id;
+
+ g_return_if_fail (sg != NULL);
+ g_return_if_fail (E_IS_SHORTCUT_GROUP (sg));
+
+ id = e_group_num_from_group_ptr (sg->model, sg);
+ for (l = sg->model->views; l; l = l->next){
+ EShortcutBar *shortcut_bar = l->data;
+ GtkWidget *label;
+
+ label = e_clipped_label_new (text);
+
+ gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);
+ gtk_widget_show (label);
+
+ e_group_bar_set_group_button_label (
+ E_GROUP_BAR (shortcut_bar), id, label);
+ }
+}
+
+static void
+esb_destroy (GtkObject *object)
+{
+ EShortcutBarModel *esb = E_SHORTCUT_BAR_MODEL (object);
+ const int count = esb->groups->len;
+ int i;
+
+ for (i = 0; i < count; i++){
+ EShortcutGroup *esg = g_array_index (esb->groups, EShortcutGroup *, i);
+
+ gtk_object_destroy (GTK_OBJECT (esg));
+ }
+
+ g_array_free (esb->groups, TRUE);
+ shortcut_bar_model_parent_class->destroy (object);
+}
+
+static void
+e_shortcut_bar_model_class_init (GtkObjectClass *object_class)
+{
+ object_class->destroy = esb_destroy;
+ shortcut_bar_model_parent_class = gtk_type_class (SHORTCUT_BAR_MODEL_PARENT_TYPE);
+}
+
+static void
+e_shortcut_bar_model_init (GtkObject *object)
+{
+ EShortcutBarModel *esb = E_SHORTCUT_BAR_MODEL (object);
+
+ /* The shortcut bar model is self owned */
+ GTK_OBJECT_UNSET_FLAGS (object, GTK_FLOATING);
+
+ esb->groups = g_array_new (FALSE, FALSE, sizeof (EShortcutGroup *));
+}
+
+EShortcutBarModel *
+e_shortcut_bar_model_new (void)
+{
+ EShortcutBarModel *bm;
+
+ bm = gtk_type_new (e_shortcut_bar_model_get_type ());
+
+ return bm;
+}
+
+void
+e_shortcut_bar_model_append (EShortcutBarModel *bm, EShortcutGroup *sg)
+{
+ g_return_if_fail (bm != NULL);
+ g_return_if_fail (sg != NULL);
+ g_return_if_fail (E_IS_SHORTCUT_BAR_MODEL (bm));
+ g_return_if_fail (E_IS_SHORTCUT_GROUP (sg));
+
+ gtk_object_ref (GTK_OBJECT (sg));
+ gtk_object_sink (GTK_OBJECT (sg));
+
+ sg->model = bm;
+
+ g_array_append_val (bm->groups, sg);
+}
+
+EShortcutGroup *
+e_shortcut_group_from_pos (EShortcutBarModel *bm, int group_num)
+{
+ EShortcutGroup *group;
+
+ if (group_num == -1)
+ return NULL;
+
+ group = g_array_index (bm->groups, EShortcutGroup *, group_num);
+ return group;
+}
+
+EShortcut *
+e_shortcut_from_pos (EShortcutGroup *group, int item_num)
+{
+ EShortcut *shortcut;
+
+ g_return_val_if_fail (group != NULL, NULL);
+ g_return_val_if_fail (E_IS_SHORTCUT_GROUP (group), NULL);
+
+ if (item_num == -1)
+ return NULL;
+
+ g_return_val_if_fail (item_num < group->shortcuts->len, NULL);
+
+ shortcut = g_array_index (group->shortcuts, EShortcut *, item_num);
+ return shortcut;
+}
+
+static void
+populate_group (EShortcutBarModel *bm, EShortcutGroup *esg, EShortcutBar *shortcut_bar)
+{
+ int group_num, i;
+ const int items = esg->shortcuts->len;
+
+ group_num = e_shortcut_bar_add_group (shortcut_bar, esg->title);
+ e_shortcut_bar_set_view_type (shortcut_bar, group_num, esg->type);
+
+ for (i = 0; i < items; i++){
+ EShortcut *shortcut = E_SHORTCUT (g_array_index (esg->shortcuts, EShortcut *, i));
+ EFolder *folder = shortcut->efolder;
+ char *type = NULL;
+
+ switch (folder->type){
+ case E_FOLDER_MAIL:
+ type = "folder:";
+ break;
+
+ case E_FOLDER_CONTACTS:
+ type = "contacts:";
+ break;
+
+ case E_FOLDER_CALENDAR:
+ type = "calendar:";
+ break;
+
+ case E_FOLDER_TASKS:
+ type = "todo:";
+ break;
+
+ case E_FOLDER_OTHER:
+ type = "file:";
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+
+ e_shortcut_bar_add_item (shortcut_bar, group_num, type, folder->name);
+ }
+}
+
+static void
+populate_from_model (EShortcutBarModel *bm, EShortcutBar *shortcut_bar)
+{
+ const int groups = bm->groups->len;
+ int i;
+
+ for (i = 0; i < groups; i++){
+ EShortcutGroup *esg;
+
+ esg = g_array_index (bm->groups, EShortcutGroup *, i);
+
+ populate_group (bm, esg, shortcut_bar);
+ }
+
+}
+
+static void
+view_destroyed (EShortcutBar *shortcut_bar, EShortcutBarModel *bm)
+{
+ bm->views = g_slist_remove (bm->views, shortcut_bar);
+}
+
+GtkWidget *
+e_shortcut_bar_view_new (EShortcutBarModel *bm)
+{
+ GtkWidget *shortcut_bar;
+
+ gtk_widget_push_visual (gdk_rgb_get_visual ());
+ gtk_widget_push_colormap (gdk_rgb_get_cmap ());
+
+ shortcut_bar = e_shortcut_bar_new ();
+
+ gtk_widget_pop_visual ();
+ gtk_widget_pop_colormap ();
+
+ populate_from_model (bm, E_SHORTCUT_BAR (shortcut_bar));
+
+ bm->views = g_slist_prepend (bm->views, shortcut_bar);
+ gtk_signal_connect (GTK_OBJECT (shortcut_bar), "destroy", GTK_SIGNAL_FUNC (view_destroyed), bm);
+
+ return shortcut_bar;
+}
+
+int
+e_group_num_from_group_ptr (EShortcutBarModel *bm, EShortcutGroup *group)
+{
+ const int n = bm->groups->len;
+ int i;
+
+ for (i = 0; i < n; i++)
+ if (g_array_index (bm->groups, EShortcutGroup *, i) == group)
+ return i;
+ return -1;
+}
+
+/*
+ * Sets the view mode in all the views
+ */
+void
+e_shortcut_group_set_view_type (EShortcutGroup *group, EIconBarViewType type)
+{
+ GSList *l;
+ int group_num;
+
+ g_return_if_fail (group != NULL);
+ g_return_if_fail (E_IS_SHORTCUT_GROUP (group));
+
+ group_num = e_group_num_from_group_ptr (group->model, group);
+
+ g_assert (group_num != -1);
+
+ group->type = type;
+
+ for (l = group->model->views; l ; l = l->next){
+ EShortcutBar *shortcut_bar = l->data;
+
+ e_shortcut_bar_set_view_type (shortcut_bar, group_num, type);
+ }
+}
+
+gint
+e_shortcut_bar_model_add_group (EShortcutBarModel *model)
+{
+ int id = -1;
+ GSList *l = NULL;
+
+ g_return_val_if_fail (model != NULL, -1);
+ g_return_val_if_fail (E_IS_SHORTCUT_BAR_MODEL (model), -1);
+
+ for (l = model->views; l; l = l->next){
+ EShortcutBar *shortcut_bar = l->data;
+
+ id = e_shortcut_bar_add_group (shortcut_bar, _("New group"));
+ }
+
+ return id;
+}
+
+void
+e_shortcut_bar_model_remove_group (EShortcutBarModel *model, EShortcutGroup *sg)
+{
+ GSList *l = NULL;
+ int group_num;
+
+ g_return_if_fail (model != NULL);
+ g_return_if_fail (E_IS_SHORTCUT_BAR_MODEL (model));
+ g_return_if_fail (sg != NULL);
+ g_return_if_fail (E_IS_SHORTCUT_GROUP (sg));
+
+ group_num = e_group_num_from_group_ptr (model, sg);
+
+ for (l = model->views; l; l = l->next){
+ EShortcutBar *shortcut_bar = l->data;
+
+ e_shortcut_bar_remove_group (shortcut_bar, group_num);
+ }
+
}
+
+E_MAKE_TYPE (e_shortcut, "EShortcut", EShortcut, e_shortcut_class_init, NULL, SHORTCUT_PARENT_TYPE);
+E_MAKE_TYPE (e_shortcut_group, "EShortcutGroup", EShortcutGroup, e_shortcut_group_class_init, e_shortcut_group_init, SHORTCUT_GROUP_PARENT_TYPE);
+E_MAKE_TYPE (e_shortcut_bar_model, "EShortcutBarModel", EShortcutBarModel, e_shortcut_bar_model_class_init, e_shortcut_bar_model_init, SHORTCUT_BAR_MODEL_PARENT_TYPE);
+
diff --git a/shell/e-shortcut.h b/shell/e-shortcut.h
index 1087fb0847..e7dde69124 100644
--- a/shell/e-shortcut.h
+++ b/shell/e-shortcut.h
@@ -3,6 +3,11 @@
#include <gtk/gtkobject.h>
#include "e-folder.h"
+#include "shortcut-bar/e-icon-bar.h"
+
+typedef struct _EShortcut EShortcut;
+typedef struct _EShortcutGroup EShortcutGroup;
+typedef struct _EShortcutBarModel EShortcutBarModel;
#define E_SHORTCUT_TYPE (e_shortcut_get_type ())
#define E_SHORTCUT(o) (GTK_CHECK_CAST ((o), E_SHORTCUT_TYPE, EShortcut))
@@ -10,10 +15,10 @@
#define E_IS_SHORTCUT(o) (GTK_CHECK_TYPE ((o), E_SHORTCUT_TYPE))
#define E_IS_SHORTCUT_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_SHORTCUT_TYPE))
-typedef struct {
+struct _EShortcut {
GtkObject object;
EFolder *efolder;
-} EShortcut;
+};
typedef struct {
GtkObjectClass parent_class;
@@ -25,35 +30,73 @@ typedef struct {
#define E_IS_SHORTCUT_GROUP(o) (GTK_CHECK_TYPE ((o), E_SHORTCUT_GROUP_TYPE))
#define E_IS_SHORTCUT_GROUP_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_SHORTCUT_GROUP_TYPE))
-typedef struct {
- GtkObject object;
- char *group_name;
- GArray *shortcuts;
- char *title;
- gboolean small_icons;
-} EShortcutGroup;
-
-typedef enum {
- E_SHORTCUT_GROUP_ITEM_ADDED,
- E_SHORTCUT_GROUP_ITEM_REMOVED,
- E_SHORTCUT_GROUP_ITEM_MOVED,
-} EShortcutGroupChange;
+struct _EShortcutGroup {
+ GtkObject object;
+ EShortcutBarModel *model;
+ char *group_name;
+ GArray *shortcuts;
+ char *title;
+ EIconBarViewType type;
+};
typedef struct {
GtkObjectClass parent_class;
-
- void (*structure_changed) (EShortcutGroup *, EShortcutGroupChange change, int arg1, int arg2);
} EShortcutGroupClass;
GtkType e_shortcut_get_type (void);
EShortcut *e_shortcut_new (EFolder *efolder);
GtkType e_shortcut_group_get_type (void);
-EShortcutGroup *e_shortcut_group_new (const char *name, gboolean small_icons);
+EShortcutGroup *e_shortcut_group_new (const char *name, EIconBarViewType type);
void e_shortcut_group_append (EShortcutGroup *sg, EShortcut *shortcut);
void e_shortcut_group_destroy (EShortcutGroup *sg);
void e_shortcut_group_remove (EShortcutGroup *sg, EShortcut *shortcut);
void e_shortcut_group_move (EShortcutGroup *sg, int from, int to);
+void e_shortcut_group_set_view_type (EShortcutGroup *sg, EIconBarViewType type);
+void e_shortcut_group_rename (EShortcutGroup *sg, const char *text);
+
+#define E_SHORTCUT_BAR_MODEL_TYPE (e_shortcut_bar_model_get_type ())
+#define E_SHORTCUT_BAR_MODEL(o) (GTK_CHECK_CAST ((o), E_SHORTCUT_BAR_MODEL_TYPE, EShortcutBarModel))
+#define E_SHORTCUT_BAR_MODEL_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_SHORTCUT_BAR_MODEL_TYPE, EShortcutBarMNodelClass))
+#define E_IS_SHORTCUT_BAR_MODEL(o) (GTK_CHECK_TYPE ((o), E_SHORTCUT_BAR_MODEL_TYPE))
+#define E_IS_SHORTCUT_BAR_MODEL_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_SHORTCUT_BAR_MODEL_TYPE))
+
+struct _EShortcutBarModel {
+ GtkObject object;
+ GArray *groups;
+ GSList *views;
+};
+
+typedef struct {
+ GtkObjectClass object_class;
+} EShortcutBarModelClass;
+
+GtkType e_shortcut_bar_model_get_type (void);
+EShortcutBarModel *e_shortcut_bar_model_new (void);
+void e_shortcut_bar_model_append (EShortcutBarModel *shortcut_bar,
+ EShortcutGroup *group);
+int e_shortcut_bar_model_add_group (EShortcutBarModel *shortcut_bar);
+void e_shortcut_bar_model_remove_group
+ (EShortcutBarModel *model,
+ EShortcutGroup *sg);
+
+/* Ugly api name */
+int e_group_num_from_group_ptr (EShortcutBarModel *bm,
+ EShortcutGroup *group);
+
+/*
+ * Produces a new view of the Shortcut Bar model
+ */
+GtkWidget *e_shortcut_bar_view_new (EShortcutBarModel *bm);
+
+/*
+ * Locating objects
+ */
+EShortcutGroup *e_shortcut_group_from_pos (EShortcutBarModel *bm,
+ int group_num);
+EShortcut *e_shortcut_from_pos (EShortcutGroup *group,
+ int item_num);
#endif
+