* all:
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Fri, 9 Feb 2007 13:18:24 +0000 (13:18 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Fri, 9 Feb 2007 13:18:24 +0000 (13:18 +0000)
  - add 'active_account' parameter + accessor functions to modest-window
  - add 'set_active_id' to modest_combo_box
  - add account parameter to msg-edit and msg-view
  - remove _set_msg from edit-msg

pmo-trunk-r807

src/widgets/modest-combo-box.c
src/widgets/modest-combo-box.h
src/widgets/modest-msg-edit-window.h
src/widgets/modest-msg-view-window.h
src/widgets/modest-msg-view.c
src/widgets/modest-window-priv.h
src/widgets/modest-window.c
src/widgets/modest-window.h

index bfe58f5..6020686 100644 (file)
@@ -52,8 +52,8 @@ enum {
 
 typedef struct _ModestComboBoxPrivate ModestComboBoxPrivate;
 struct _ModestComboBoxPrivate {
-       /* my private members go here, eg. */
-       /* gboolean frobnicate_mode; */
+       GEqualFunc id_equal_func;
+       
 };
 #define MODEST_COMBO_BOX_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
                                               MODEST_TYPE_COMBO_BOX, \
@@ -125,7 +125,7 @@ modest_combo_box_finalize (GObject *obj)
 }
 
 static GtkTreeModel*
-get_model (const GSList *pairs)
+get_model (const ModestPairList *pairs)
 {
        GtkTreeIter iter;
        GtkListStore *store;
@@ -149,16 +149,19 @@ get_model (const GSList *pairs)
 
 
 GtkWidget*
-modest_combo_box_new (const GSList *pairs)
+modest_combo_box_new (const ModestPairList *pairs, GEqualFunc id_equal_func)
 {
        GtkTreeModel *model;
        GtkCellRenderer *renderer;
        GObject *obj;
+       ModestComboBoxPrivate *priv;
 
+       g_return_val_if_fail (pairs,         NULL);
+       
        obj  = G_OBJECT(g_object_new(MODEST_TYPE_COMBO_BOX, NULL));
-               
+       priv = MODEST_COMBO_BOX_GET_PRIVATE(obj);
+       
        model = get_model (pairs);
-
        if (model) {
                gtk_combo_box_set_model (GTK_COMBO_BOX(obj), model);
                g_object_unref (model);
@@ -173,6 +176,12 @@ modest_combo_box_new (const GSList *pairs)
        }
 
        gtk_combo_box_set_active (GTK_COMBO_BOX(obj), 0);
+
+       if (id_equal_func)
+               priv->id_equal_func = id_equal_func;
+       else
+               priv->id_equal_func = g_direct_equal; /* compare the ptr values */
+       
        return GTK_WIDGET(obj);
 }
 
@@ -182,7 +191,6 @@ static void
 get_active (ModestComboBox *self, GValue *val, gint column)
 {
        GtkTreeIter iter;
-       
        g_return_if_fail (self);
 
        if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX(self), &iter)) {
@@ -196,10 +204,11 @@ get_active (ModestComboBox *self, GValue *val, gint column)
 gpointer
 modest_combo_box_get_active_id (ModestComboBox *self)
 {
-       g_return_val_if_fail (self, NULL);
        GValue val = {0,};
        gpointer retval;
 
+       g_return_val_if_fail (self, NULL);
+       
        /* Do not unset the GValue */
        get_active (self, &val, COLUMN_ID);
        retval = g_value_peek_pointer (&val);
@@ -207,16 +216,49 @@ modest_combo_box_get_active_id (ModestComboBox *self)
        return retval;
 }
 
-gpointer
+
+void
+modest_combo_box_set_active_id (ModestComboBox *self, gpointer id)
+{
+       GtkTreeModel *model;
+       GtkTreeIter iter;
+       ModestComboBoxPrivate *priv;
+       gboolean found;
+       
+       g_return_if_fail (self);
+
+       priv = MODEST_COMBO_BOX_GET_PRIVATE(self);
+       
+       model = gtk_combo_box_get_model (GTK_COMBO_BOX(self));
+       if (!gtk_tree_model_get_iter_first (model, &iter))
+               return; /* empty list */
+
+       do {
+               gpointer row_id;
+               gtk_tree_model_get (model, &iter, COLUMN_ID, &row_id, -1);
+               if ((priv->id_equal_func)(id, row_id) == 0) {
+                       gtk_combo_box_set_active_iter (GTK_COMBO_BOX(self), &iter);
+                       found = TRUE;
+               }
+       } while (!found && gtk_tree_model_iter_next (model, &iter));
+
+       if (!found)
+               g_printerr ("modest: could not set the active id\n"); 
+}
+
+
+
+const gchar*
 modest_combo_box_get_active_display_name (ModestComboBox *self)
 {
-       g_return_val_if_fail (self, NULL);
        GValue val = {0,};
        gpointer retval;
 
+       g_return_val_if_fail (self, NULL);
+
        /* Do not unset the GValue */
        get_active (self, &val, COLUMN_DISPLAY_NAME);
        retval = g_value_peek_pointer (&val);
 
-       return retval;
+       return (gchar*) retval;
 }
index 9ce1349..aedea9e 100644 (file)
@@ -63,26 +63,41 @@ GType        modest_combo_box_get_type    (void) G_GNUC_CONST;
 
 /**
  * modest_combo_box_new
- * @hash: a ptr to a GSList; each element should be a ptr to
- * a ModestPair 
+ * @pairs: a #ModestPairList; each element should be a ptr to a #ModestPair 
+ * @cmp_id_func: a GEqualFunc to compare the ids (= the first elements of the pairs)
+ * For example, if the ids are strings, you can use g_str_equal.
  *
+ * (If you provide NULL for this parameter, the id ptr address will be compared)
+ * 
  * create a new modest combo box
  * 
  * Returns: a new GtkComboBox instance, or NULL in case of failure
  */
-GtkWidget*   modest_combo_box_new         (const GSList *hash);
+GtkWidget*   modest_combo_box_new         (const ModestPairList* pairs,
+                                          GEqualFunc id_equal_func);
 
 /**
  * modest_combo_box_get_active_id
  * @self: a valid ModestComboBox instance 
  * 
- * get the id for the currently active lemma, or NULL if there's nothing chosen
+ * get the id for the currently active item, or NULL if there's nothing chosen
+ * (ie., the id is the first element of the pair)
  * 
  * Returns: the id or NULL if there's nothing chosen.
  */
 gpointer   modest_combo_box_get_active_id  (ModestComboBox *self);
 
 /**
+ * modest_combo_box_set_active_id
+ * @self: a valid ModestComboBox instance
+ * @id: the id to make active
+ * 
+ * set the active item
+ * 
+ */
+void       modest_combo_box_set_active_id (ModestComboBox *self, gpointer id);
+
+/**
  * modest_combo_box_get_active_display_name
  * @self: a valid ModestComboBox instance 
  * 
@@ -91,7 +106,7 @@ gpointer   modest_combo_box_get_active_id  (ModestComboBox *self);
  * 
  * Returns: the display name or NULL if there's nothing chosen.
  */
-gpointer   modest_combo_box_get_active_display_name  (ModestComboBox *self);
+const gchar* modest_combo_box_get_active_display_name  (ModestComboBox *self);
 
 G_END_DECLS
 
index b657e9e..575d493 100644 (file)
@@ -61,12 +61,11 @@ typedef enum  {
        MODEST_EDIT_TYPE_NEW,
        MODEST_EDIT_TYPE_REPLY,
        MODEST_EDIT_TYPE_FORWARD,
-       MODEST_EDIT_TYPE_VIEW,
        
        MODEST_EDIT_TYPE_NUM
 } ModestEditType;
 
-typedef struct _MsgData {
+typedef struct  {
        gchar *from, *to, *cc, *bcc, *subject, *body;
 } MsgData;
 
@@ -83,23 +82,14 @@ GType        modest_msg_edit_window_get_type    (void) G_GNUC_CONST;
 
 /**
  * modest_msg_edit_window_new:
+ * #msg: a #TnyMsg instance
+ * #account_name: the account this message applies to
  * 
  * instantiates a new #ModestMsgEditWindow widget
  *
  * Returns: a new #ModestMsgEditWindow, or NULL in case of error
  */
-ModestWindow*   modest_msg_edit_window_new         (ModestEditType type);
-
-
-/**
- * modest_msg_edit_window_set_msg:
- * @self: a #ModestMsgEditWindow
- * @msg: a #TnyMsg
- * 
- * shows the message @msg in a #ModestMsgEditWindow
- **/
-void         modest_msg_edit_window_set_msg     (ModestMsgEditWindow *self, 
-                                                TnyMsg *msg);
+ModestWindow*   modest_msg_edit_window_new         (TnyMsg *msg, const gchar *account_name);
 
 
 /**
index 2dbe818..249cb31 100644 (file)
@@ -66,12 +66,15 @@ GType        modest_msg_view_window_get_type    (void) G_GNUC_CONST;
 
 /**
  * modest_msg_view_window_new:
+ * @msg: an #TnyMsg instance
+ * @account: the account name 
  * 
- * instantiates a new #ModestMsgViewWindow widget
+ * instantiates a new #ModestMsgViewWindow widget. The account name is used to
+ * set the proper account when choosing reply/forward from the msg view window
  *
  * Returns: a new #ModestMsgViewWindow, or NULL in case of error
  */
-ModestWindow*   modest_msg_view_window_new         (TnyMsg *msg);
+ModestWindow*   modest_msg_view_window_new         (TnyMsg *msg, const gchar *account);
 
 G_END_DECLS
 
index ff47e61..bc42516 100644 (file)
@@ -380,7 +380,6 @@ attachments_as_html (ModestMsgView *self, TnyMsg *msg)
 }
 
 
-
 static gchar*
 get_header_info (TnyMsg *msg, gboolean outgoing)
 {
index 59f1b48..5d10b75 100644 (file)
@@ -41,6 +41,8 @@ struct _ModestWindowPrivate {
        GtkUIManager         *ui_manager;
        GtkWidget            *toolbar;
        GtkWidget            *menubar;
+
+       gchar                *active_account;
 };
 
 #define MODEST_WINDOW_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
index 6132053..e3b30be 100644 (file)
@@ -96,9 +96,11 @@ modest_window_init (ModestWindow *obj)
 
        priv = MODEST_WINDOW_GET_PRIVATE(obj);
 
-       priv->ui_manager    = NULL;
-       priv->toolbar       = NULL;
-       priv->menubar       = NULL;
+       priv->ui_manager     = NULL;
+       priv->toolbar        = NULL;
+       priv->menubar        = NULL;
+
+       priv->active_account = NULL;
 }
 
 static void
@@ -113,5 +115,32 @@ modest_window_finalize (GObject *obj)
                priv->ui_manager = NULL;
        }
 
+       g_free (priv->active_account);
+       
        G_OBJECT_CLASS(parent_class)->finalize (obj);
 }
+
+
+
+const gchar*
+modest_window_get_active_account (ModestWindow *self)
+{
+       g_return_val_if_fail (self, NULL);
+
+       return MODEST_WINDOW_GET_PRIVATE(self)->active_account;
+}
+
+void
+modest_window_set_active_account (ModestWindow *self, const gchar *active_account)
+{
+       ModestWindowPrivate *priv;      
+
+       priv = MODEST_WINDOW_GET_PRIVATE(self);
+
+       if (active_account == priv->active_account)
+               return;
+       else {
+               g_free (priv->active_account);
+               priv->active_account = g_strdup (active_account);
+       }
+}
index ada4a82..cc55fa9 100644 (file)
@@ -72,9 +72,39 @@ struct _ModestWindowClass {
        ModestWindowParentClass parent_class;
 };
 
-/* member functions */
+/**
+ * modest_window_get_type:
+ *
+ * get the #GType for #ModestWindow
+ * 
+ * Returns: the type
+ */    
 GType        modest_window_get_type    (void) G_GNUC_CONST;
 
+
+/**
+ * modest_window_get_active_account:
+ * @self: a modest window instance
+ * 
+ * get the name of the active account
+ * 
+ * Returns: the active account name as a constant string
+ */    
+const gchar* modest_window_get_active_account (ModestWindow *self);
+
+
+
+/**
+ * modest_window_set_active_account:
+ * @self: a modest window instance
+ * @active_account: a new active account name for this window
+ * 
+ * set the active account for this window
+ * 
+ */    
+void modest_window_set_active_account (ModestWindow *self, const gchar *active_account);
+
+
 G_END_DECLS
 
 #endif /* __MODEST_WINDOW_H__ */