From: Sergio Villar Senin Date: Tue, 10 Apr 2007 11:02:55 +0000 (+0000) Subject: * Added ModestWindowMgr object X-Git-Tag: git_migration_finished~3923 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=7b9c42bc690092373ab9e35d4848fc85635dd100 * Added ModestWindowMgr object * Added ModestWindowMgr singleton stuff * Added homogeneous toolbar items to the main window pmo-trunk-r1529 --- diff --git a/src/maemo/modest-main-window.c b/src/maemo/modest-main-window.c index 4dd2d27..1d621fb 100644 --- a/src/maemo/modest-main-window.c +++ b/src/maemo/modest-main-window.c @@ -277,6 +277,14 @@ on_delete_event (GtkWidget *widget, GdkEvent *event, ModestMainWindow *self) return FALSE; } +static void +set_homogeneous (GtkWidget *widget, + gpointer data) +{ + gtk_tool_item_set_expand (GTK_TOOL_ITEM (widget), TRUE); + gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (widget), TRUE); +} + static GtkWidget* get_toolbar (ModestMainWindow *self) { @@ -292,6 +300,9 @@ get_toolbar (ModestMainWindow *self) menu = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolbarReplyContextMenu"); gtk_widget_tap_and_hold_setup (GTK_WIDGET (reply_button), menu, NULL, 0); + /* Set homogeneous toolbar */ + gtk_container_foreach (GTK_CONTAINER (toolbar), set_homogeneous, NULL); + return toolbar; } diff --git a/src/modest-runtime.c b/src/modest-runtime.c index de3fa1f..b231072 100644 --- a/src/modest-runtime.c +++ b/src/modest-runtime.c @@ -260,9 +260,6 @@ modest_runtime_get_platform_factory (void) return modest_singletons_get_platform_factory (_singletons); } - - - ModestTnySendQueue* modest_runtime_get_send_queue (TnyTransportAccount *account) { @@ -285,8 +282,12 @@ modest_runtime_get_send_queue (TnyTransportAccount *account) return MODEST_TNY_SEND_QUEUE(send_queue); } - - +ModestWindowMgr * +modest_runtime_get_window_mgr (void) +{ + g_return_val_if_fail (_singletons, NULL); + return modest_singletons_get_window_mgr (_singletons); +} /* http://primates.ximian.com/~federico/news-2006-04.html#memory-debugging-infrastructure*/ ModestRuntimeDebugFlags diff --git a/src/modest-runtime.h b/src/modest-runtime.h index 099a02f..eade560 100644 --- a/src/modest-runtime.h +++ b/src/modest-runtime.h @@ -39,6 +39,7 @@ #include #include #include +#include "widgets/modest-window-mgr.h" G_BEGIN_DECLS @@ -196,6 +197,14 @@ ModestMailOperationQueue* modest_runtime_get_mail_operation_queue (void); ModestTnySendQueue* modest_runtime_get_send_queue (TnyTransportAccount *account); +/** + * modest_runtime_get_window_mgr: + * + * get the #ModestWindowMgr singleton instance + * + * Returns: the #ModestWindowMgr singleton. This should NOT be unref'd. + **/ +ModestWindowMgr* modest_runtime_get_window_mgr (void); /** * modest_runtime_verify_object_death diff --git a/src/modest-singletons.c b/src/modest-singletons.c index 396a4b3..a8cd130 100644 --- a/src/modest-singletons.c +++ b/src/modest-singletons.c @@ -44,6 +44,7 @@ struct _ModestSingletonsPrivate { ModestMailOperationQueue *mail_op_queue; TnyPlatformFactory *platform_fact; TnyDevice *device; + ModestWindowMgr *window_mgr; }; #define MODEST_SINGLETONS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ MODEST_TYPE_SINGLETONS, \ @@ -100,6 +101,7 @@ modest_singletons_init (ModestSingletons *obj) priv->mail_op_queue = NULL; priv->platform_fact = NULL; priv->device = NULL; + priv->window_mgr = NULL; priv->conf = modest_conf_new (); if (!priv->conf) { @@ -141,7 +143,13 @@ modest_singletons_init (ModestSingletons *obj) if (!priv->mail_op_queue) { g_printerr ("modest: cannot create modest mail operation queue instance\n"); return; - } + } + + priv->window_mgr = modest_window_mgr_new (); + if (!priv->window_mgr) { + g_printerr ("modest: cannot create modest window manager instance\n"); + return; + } } static void @@ -265,3 +273,10 @@ modest_singletons_get_platform_factory (ModestSingletons *self) g_return_val_if_fail (self, NULL); return MODEST_SINGLETONS_GET_PRIVATE(self)->platform_fact; } + +ModestWindowMgr* +modest_singletons_get_window_mgr (ModestSingletons *self) +{ + g_return_val_if_fail (self, NULL); + return MODEST_SINGLETONS_GET_PRIVATE(self)->window_mgr; +} diff --git a/src/modest-singletons.h b/src/modest-singletons.h index b6f0448..2e5d1fa 100644 --- a/src/modest-singletons.h +++ b/src/modest-singletons.h @@ -39,6 +39,7 @@ #include #include #include +#include "widgets/modest-window-mgr.h" G_BEGIN_DECLS @@ -175,7 +176,16 @@ TnyDevice* modest_singletons_get_device (ModestSingletons **/ ModestMailOperationQueue* modest_singletons_get_mail_operation_queue (ModestSingletons *self); - +/** + * modest_singletons_get_window_mgr: + * @self: + * + * Gets the #ModestWindowMgr singleton instance. Don't use this + * function directly, use the modest-runtime function instead. + * + * Return value: the singleton instance of #ModestWindowMgr + **/ +ModestWindowMgr* modest_singletons_get_window_mgr (ModestSingletons *self); G_END_DECLS diff --git a/src/widgets/Makefile.am b/src/widgets/Makefile.am index cb0ff4e..ff67a8b 100644 --- a/src/widgets/Makefile.am +++ b/src/widgets/Makefile.am @@ -46,7 +46,9 @@ libmodest_widgets_la_SOURCES= \ modest-tny-stream-gtkhtml.c \ modest-tny-stream-gtkhtml.h \ modest-window.c \ - modest-window.h + modest-window.h \ + modest-window-mgr.h \ + modest-window-mgr.c LDADD = \ $(MODEST_GSTUFF_LIBS) \ diff --git a/src/widgets/modest-window-mgr.c b/src/widgets/modest-window-mgr.c new file mode 100644 index 0000000..1e40676 --- /dev/null +++ b/src/widgets/modest-window-mgr.c @@ -0,0 +1,181 @@ +/* Copyright (c) 2006,2007 Nokia Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Nokia Corporation nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "modest-window-mgr.h" +/* include other impl specific header files */ + +/* 'private'/'protected' functions */ +static void modest_window_mgr_class_init (ModestWindowMgrClass *klass); +static void modest_window_mgr_init (ModestWindowMgr *obj); +static void modest_window_mgr_finalize (GObject *obj); +/* list my signals */ +enum { + /* MY_SIGNAL_1, */ + /* MY_SIGNAL_2, */ + LAST_SIGNAL +}; + +typedef struct _ModestWindowMgrPrivate ModestWindowMgrPrivate; +struct _ModestWindowMgrPrivate { + GList *window_list; +}; +#define MODEST_WINDOW_MGR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ + MODEST_TYPE_WINDOW_MGR, \ + ModestWindowMgrPrivate)) +/* globals */ +static GObjectClass *parent_class = NULL; + +/* uncomment the following if you have defined any signals */ +/* static guint signals[LAST_SIGNAL] = {0}; */ + +GType +modest_window_mgr_get_type (void) +{ + static GType my_type = 0; + if (!my_type) { + static const GTypeInfo my_info = { + sizeof(ModestWindowMgrClass), + NULL, /* base init */ + NULL, /* base finalize */ + (GClassInitFunc) modest_window_mgr_class_init, + NULL, /* class finalize */ + NULL, /* class data */ + sizeof(ModestWindowMgr), + 1, /* n_preallocs */ + (GInstanceInitFunc) modest_window_mgr_init, + NULL + }; + my_type = g_type_register_static (G_TYPE_OBJECT, + "ModestWindowMgr", + &my_info, 0); + } + return my_type; +} + +static void +modest_window_mgr_class_init (ModestWindowMgrClass *klass) +{ + GObjectClass *gobject_class; + gobject_class = (GObjectClass*) klass; + + parent_class = g_type_class_peek_parent (klass); + gobject_class->finalize = modest_window_mgr_finalize; + + g_type_class_add_private (gobject_class, sizeof(ModestWindowMgrPrivate)); +} + +static void +modest_window_mgr_init (ModestWindowMgr *obj) +{ + ModestWindowMgrPrivate *priv = MODEST_WINDOW_MGR_GET_PRIVATE(obj); + + priv->window_list = NULL; +} + +static void +modest_window_mgr_finalize (GObject *obj) +{ + ModestWindowMgrPrivate *priv = MODEST_WINDOW_MGR_GET_PRIVATE(obj); + + if (priv->window_list) { + GList *iter = priv->window_list; + /* unregister pending windows */ + while (iter) { + modest_window_mgr_unregister_window (MODEST_WINDOW_MGR (obj), + MODEST_WINDOW (iter->data)); + iter = g_list_next (iter); + } + g_list_free (priv->window_list); + priv->window_list = NULL; + } + + G_OBJECT_CLASS(parent_class)->finalize (obj); +} + +ModestWindowMgr* +modest_window_mgr_new (void) +{ + return MODEST_WINDOW_MGR(g_object_new(MODEST_TYPE_WINDOW_MGR, NULL)); +} + +void +modest_window_mgr_register_window (ModestWindowMgr *self, + ModestWindow *window) +{ + GList *win; + ModestWindowMgrPrivate *priv; + + g_return_if_fail (MODEST_IS_WINDOW_MGR (self)); + g_return_if_fail (MODEST_IS_WINDOW (window)); + + priv = MODEST_WINDOW_MGR_GET_PRIVATE (self); + + win = g_list_find (priv->window_list, window); + if (win) { + g_warning ("Trying to register an already registered window"); + return; + } + + /* Add to list. Keep a reference to the window */ + g_object_ref (window); + priv->window_list = g_list_prepend (priv->window_list, window); +} + +void +modest_window_mgr_unregister_window (ModestWindowMgr *self, + ModestWindow *window) +{ + GList *win; + ModestWindowMgrPrivate *priv; + + g_return_if_fail (MODEST_IS_WINDOW_MGR (self)); + g_return_if_fail (MODEST_IS_WINDOW (window)); + + priv = MODEST_WINDOW_MGR_GET_PRIVATE (self); + + win = g_list_find (priv->window_list, window); + if (!win) { + g_warning ("Trying to unregister a window that has not being registered yet"); + return; + } + + /* Remove from list. Remove the reference to the window */ + g_object_unref (win->data); + priv->window_list = g_list_remove_link (priv->window_list, win); +} + +ModestWindow * +modest_window_mgr_find_window_for_msgid (ModestWindowMgr *self, + gchar *msgid, + GType modest_window_type) +{ + /* TODO */ + + return NULL; +} diff --git a/src/widgets/modest-window-mgr.h b/src/widgets/modest-window-mgr.h new file mode 100644 index 0000000..1453d86 --- /dev/null +++ b/src/widgets/modest-window-mgr.h @@ -0,0 +1,108 @@ +/* Copyright (c) 2006,2007 Nokia Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Nokia Corporation nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __MODEST_WINDOW_MGR_H__ +#define __MODEST_WINDOW_MGR_H__ + +#include +#include "widgets/modest-window.h" + +G_BEGIN_DECLS + +/* convenience macros */ +#define MODEST_TYPE_WINDOW_MGR (modest_window_mgr_get_type()) +#define MODEST_WINDOW_MGR(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),MODEST_TYPE_WINDOW_MGR,ModestWindowMgr)) +#define MODEST_WINDOW_MGR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),MODEST_TYPE_WINDOW_MGR,GObject)) +#define MODEST_IS_WINDOW_MGR(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),MODEST_TYPE_WINDOW_MGR)) +#define MODEST_IS_WINDOW_MGR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),MODEST_TYPE_WINDOW_MGR)) +#define MODEST_WINDOW_MGR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),MODEST_TYPE_WINDOW_MGR,ModestWindowMgrClass)) + +typedef struct _ModestWindowMgr ModestWindowMgr; +typedef struct _ModestWindowMgrClass ModestWindowMgrClass; + +struct _ModestWindowMgr { + GObject parent; + /* insert public members, if any */ +}; + +struct _ModestWindowMgrClass { + GObjectClass parent_class; + /* insert signal callback declarations, eg. */ + /* void (* my_event) (ModestWindowMgr* obj); */ +}; + +/* member functions */ +GType modest_window_mgr_get_type (void) G_GNUC_CONST; + +/* typical parameter-less _new function */ +ModestWindowMgr* modest_window_mgr_new (void); + + +/** + * modest_window_mgr_register_window: + * @self: the #ModestWindowMgr + * @window: a #ModestWindow + * + * Registers a new window in the window manager. The window manager + * will keep a reference. + **/ +void modest_window_mgr_register_window (ModestWindowMgr *self, + ModestWindow *window); + +/** + * modest_window_mgr_unregister_window: + * @self: the #ModestWindowMgr + * @window: a #ModestWindow + * + * Unegisters a given window from the window manager. The window + * manager will free its reference to it. + **/ +void modest_window_mgr_unregister_window (ModestWindowMgr *self, + ModestWindow *window); + + +/** + * modest_window_mgr_find_window_for_msgid: + * @self: the #ModestWindowMgr + * @msgid: the message id + * @modest_window_type: the type of the #ModestWindow we're looking for + * + * Looks for a window of a given type that have a relationship with + * the message specified by the message id passed as argument + * + * Return value: the #ModestWindow if found, else NULL + **/ +ModestWindow* modest_window_mgr_find_window_for_msgid (ModestWindowMgr *self, + gchar *msgid, + GType modest_window_type); + +G_END_DECLS + +#endif /* __MODEST_WINDOW_MGR_H__ */ +