-/* modest-ui.c */
-
-/* insert (c)/licensing information) */
+/* Copyright (c) 2006, 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 <gtk/gtk.h>
+#include <glade/glade.h>
+#include <glib/gi18n.h>
+#include <string.h>
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /*HAVE_CONFIG_H*/
-#include "modest-main-window.h"
-#include "modest-edit-window.h"
+/* TODO: put in auto* */
+#include <tny-text-buffer-stream.h>
+#include <tny-msg-folder.h>
#include "../modest-ui.h"
#include "../modest-window-mgr.h"
#include "../modest-account-mgr.h"
+#include "../modest-account-mgr.h"
+#include "../modest-identity-mgr.h"
+
+#include "../modest-tny-account-store.h"
+#include "../widgets/modest-folder-view.h"
+#include "../widgets/modest-header-view.h"
+#include "../widgets/modest-msg-view.h"
+#include "../modest-tny-transport-actions.h"
+#include "../modest-tny-store-actions.h"
+#include "../modest-text-utils.h"
+#include "../modest-tny-msg-actions.h"
-/* include other impl specific header files */
+#include "../modest-editor-window.h"
+
+#include "modest-ui-glade.h"
+#include "modest-ui-wizard.h"
/* 'private'/'protected' functions */
static void modest_ui_class_init (ModestUIClass *klass);
static void modest_ui_init (ModestUI *obj);
static void modest_ui_finalize (GObject *obj);
+static void modest_ui_last_window_closed (GObject *obj, gpointer data);
-static void modest_ui_window_destroy (GtkWidget *win, gpointer data);
-static void modest_ui_last_window_closed (GObject *obj, gpointer data);
-
-
+gchar *on_password_requested (TnyAccountIface *, const gchar *, gboolean *);
/* list my signals */
enum {
LAST_SIGNAL
};
-
-typedef struct _ModestUIPrivate ModestUIPrivate;
-struct _ModestUIPrivate {
-
- ModestConf *modest_conf;
- ModestAccountMgr *modest_acc_mgr;
- ModestWindowMgr *modest_window_mgr;
-
- GtkWindow *main_window;
- GSList* *edit_window_list;
-
-};
-#define MODEST_UI_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
- MODEST_TYPE_UI, \
- ModestUIPrivate))
/* globals */
static GObjectClass *parent_class = NULL;
-/* uncomment the following if you have defined any signals */
-/* static guint signals[LAST_SIGNAL] = {0}; */
GType
modest_ui_get_type (void)
return my_type;
}
+
static void
modest_ui_class_init (ModestUIClass *klass)
{
g_type_class_add_private (gobject_class, sizeof(ModestUIPrivate));
- /* signal definitions go here, e.g.: */
-/* signals[MY_SIGNAL_1] = */
-/* g_signal_new ("my_signal_1",....); */
-/* signals[MY_SIGNAL_2] = */
-/* g_signal_new ("my_signal_2",....); */
-/* etc. */
}
+
static void
modest_ui_init (ModestUI *obj)
{
ModestUIPrivate *priv = MODEST_UI_GET_PRIVATE(obj);
priv->modest_acc_mgr = NULL;
+ priv->modest_id_mgr = NULL;
priv->modest_conf = NULL;
priv->modest_window_mgr = NULL;
-
+ priv->glade_xml = NULL;
+ priv->folder_view = NULL;
+ priv->header_view = NULL;
+ priv->message_view = NULL;
+ priv->current_folder = NULL;
}
+
static void
modest_ui_finalize (GObject *obj)
{
- ModestUIPrivate *priv = MODEST_UI_GET_PRIVATE(obj);
-
+ ModestUIPrivate *priv = MODEST_UI_GET_PRIVATE(obj);
+
if (priv->modest_acc_mgr)
g_object_unref (priv->modest_acc_mgr);
priv->modest_acc_mgr = NULL;
-
+
+ if (priv->modest_id_mgr)
+ g_object_unref (priv->modest_id_mgr);
+ priv->modest_id_mgr = NULL;
+
if (priv->modest_conf)
g_object_unref (priv->modest_conf);
priv->modest_conf = NULL;
-
+
if (priv->modest_window_mgr)
g_object_unref (priv->modest_window_mgr);
priv->modest_window_mgr = NULL;
}
-
-GObject*
+
+
+static void
+on_accounts_reloaded (ModestTnyAccountStore *account_store, gpointer user_data)
+{
+ ModestUIPrivate *priv = user_data;
+
+ g_return_if_fail (MODEST_IS_FOLDER_VIEW (priv->folder_view));
+ g_return_if_fail (MODEST_IS_HEADER_VIEW (priv->header_view));
+
+ modest_header_view_set_folder (MODEST_HEADER_VIEW(priv->header_view),
+ NULL);
+
+ modest_folder_view_update_model(MODEST_FOLDER_VIEW(priv->folder_view),
+ TNY_ACCOUNT_STORE_IFACE(account_store));
+}
+
+
+ModestUI*
modest_ui_new (ModestConf *modest_conf)
{
GObject *obj;
ModestUIPrivate *priv;
ModestAccountMgr *modest_acc_mgr;
+ ModestIdentityMgr *modest_id_mgr;
+ TnyAccountStoreIface *account_store_iface;
+ GSList *account_names_list, *cursor;
+ GSList *identities_list;
g_return_val_if_fail (modest_conf, NULL);
- obj = g_object_new(MODEST_TYPE_UI, NULL);
+ obj = g_object_new(MODEST_TYPE_UI, NULL);
priv = MODEST_UI_GET_PRIVATE(obj);
modest_acc_mgr = MODEST_ACCOUNT_MGR(modest_account_mgr_new (modest_conf));
g_warning ("could not create ModestAccountMgr instance");
g_object_unref (obj);
return NULL;
+ }
+
+ modest_id_mgr = MODEST_IDENTITY_MGR(modest_identity_mgr_new (modest_conf));
+ if (!modest_id_mgr) {
+ g_warning ("could not create ModestIdentityMgr instance");
+ g_object_unref (obj);
+ return NULL;
}
-
+
+ account_store_iface =
+ TNY_ACCOUNT_STORE_IFACE(modest_tny_account_store_new (modest_acc_mgr));
+ if (!account_store_iface) {
+ g_warning ("could not initialze ModestTnyAccountStore");
+ return NULL;
+ }
+
+ modest_tny_account_store_set_get_pass_func(MODEST_TNY_ACCOUNT_STORE(account_store_iface),
+ on_password_requested);
+
+ g_signal_connect (account_store_iface, "accounts_reloaded",
+ G_CALLBACK(on_accounts_reloaded), priv);
+
+ glade_init ();
+ priv->glade_xml = glade_xml_new (MODEST_GLADE, NULL, NULL);
+ if (!priv->glade_xml) {
+ g_warning ("failed to do glade stuff");
+ g_object_unref (obj);
+ return NULL;
+ }
+
+ /* FIXME: could be used, but doesn't work atm.
+ * glade_xml_signal_autoconnect(priv->glade_xml);
+ */
+
priv->modest_acc_mgr = modest_acc_mgr;
+ priv->modest_id_mgr = modest_id_mgr;
g_object_ref (priv->modest_conf = modest_conf);
+ priv->account_store = account_store_iface;
+
priv->modest_window_mgr = MODEST_WINDOW_MGR(modest_window_mgr_new());
g_signal_connect (priv->modest_window_mgr, "last_window_closed",
G_CALLBACK(modest_ui_last_window_closed),
NULL);
- return obj;
-}
-
-gboolean
-modest_ui_show_main_window (ModestUI *modest_ui)
-{
- GtkWidget *win;
- int height, width;
- ModestUIPrivate *priv;
-
- priv = MODEST_UI_GET_PRIVATE(modest_ui);
-
- height = modest_conf_get_int (priv->modest_conf,
- MODEST_CONF_MAIN_WINDOW_HEIGHT,NULL);
- width = modest_conf_get_int (priv->modest_conf,
- MODEST_CONF_MAIN_WINDOW_WIDTH,NULL);
+ account_names_list = modest_account_mgr_search_server_accounts(modest_acc_mgr,
+
+ NULL, MODEST_PROTO_TYPE_ANY, NULL, FALSE);
+ identities_list = modest_identity_mgr_identity_names(modest_id_mgr, NULL);
+ if (!(account_names_list != NULL || identities_list != NULL))
+ wizard_account_dialog(MODEST_UI(obj));
+
+ cursor = account_names_list;
+ while (cursor) {
+ g_free (cursor->data);
+ cursor = cursor->next;
+ }
+ g_slist_free(account_names_list);
- win = modest_main_window_new (priv->modest_conf,
- priv->modest_acc_mgr);
- if (!win) {
- g_warning ("could not create main window");
- return FALSE;
+
+ cursor = identities_list;
+ while (cursor) {
+ g_free (cursor->data);
+ cursor = cursor->next;
}
+ g_slist_free(identities_list);
- modest_window_mgr_register (priv->modest_window_mgr,
- G_OBJECT(win), MODEST_MAIN_WINDOW, 0);
-
- g_signal_connect (win, "destroy", G_CALLBACK(modest_ui_window_destroy),
- modest_ui);
-
- gtk_widget_set_usize (GTK_WIDGET(win), height, width);
- gtk_window_set_title (GTK_WINDOW(win), PACKAGE_STRING);
-
- gtk_widget_show (win);
- return TRUE;
+ return MODEST_UI(obj);
}
-gboolean
-modest_ui_show_edit_window (ModestUI *modest_ui, const gchar* to,
- const gchar* cc, const gchar* bcc,
- const gchar* subject, const gchar *body,
- const GSList* att)
+static void
+modest_ui_last_window_closed (GObject *obj, gpointer data)
{
- GtkWidget *win;
- ModestUIPrivate *priv;
-
- priv = MODEST_UI_GET_PRIVATE(modest_ui);
- int height = modest_conf_get_int (priv->modest_conf,
- MODEST_CONF_EDIT_WINDOW_HEIGHT,NULL);
- int width = modest_conf_get_int (priv->modest_conf,
- MODEST_CONF_EDIT_WINDOW_WIDTH,NULL);
-
- win = modest_edit_window_new (to, cc, bcc, subject, body, att);
- if (!win) {
- g_warning ("could not create edit window");
- return FALSE;
- }
-
- modest_window_mgr_register (priv->modest_window_mgr,
- G_OBJECT(win), MODEST_EDIT_WINDOW, 0);
+ /* FIXME: Other cleanups todo? Finalize Tinymail? */
+ gtk_main_quit ();
+}
- g_signal_connect (win, "destroy", G_CALLBACK(modest_ui_window_destroy),
- modest_ui);
- gtk_widget_set_usize (GTK_WIDGET(win), height, width);
- gtk_window_set_title (GTK_WINDOW(win),
- subject ? subject : "Untitled");
+gchar *
+on_password_requested (TnyAccountIface *account,
+ const gchar *prompt,
+ gboolean *cancel) {
+
+ GtkWidget *passdialog;
+ GtkWidget *vbox;
+ GtkWidget *infoscroll;
+ GtkWidget *infolabel;
+ GtkWidget *passentry;
+ GtkTextBuffer *infobuffer;
+ gchar *retval;
+ gint result;
+
+ passdialog = gtk_dialog_new_with_buttons(_("Password"),
+ NULL,
+ GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_STOCK_OK,
+ GTK_RESPONSE_ACCEPT,
+ GTK_STOCK_CANCEL,
+ GTK_RESPONSE_REJECT,
+ NULL);
+
+ vbox = gtk_vbox_new(FALSE, 0);
+
+ infobuffer = gtk_text_buffer_new (NULL);
+ gtk_text_buffer_set_text(infobuffer, prompt, -1);
+ infoscroll = gtk_scrolled_window_new(NULL, NULL);
+ infolabel = gtk_text_view_new_with_buffer(infobuffer);
+ gtk_container_add(GTK_CONTAINER(infoscroll), infolabel);
+ passentry = gtk_entry_new();
+ gtk_entry_set_visibility(GTK_ENTRY(passentry), FALSE);
+
+ gtk_box_pack_start(GTK_BOX(GTK_DIALOG(passdialog)->vbox), infoscroll, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(GTK_DIALOG(passdialog)->vbox), passentry, FALSE, FALSE, 0);
+ gtk_widget_show_all(passdialog);
+
+ result = gtk_dialog_run (GTK_DIALOG(passdialog));
+
+ switch (result) {
+ case GTK_RESPONSE_ACCEPT:
+ retval = g_strdup(gtk_entry_get_text(GTK_ENTRY(passentry)));
+ *cancel=FALSE;
+ break;
+ default:
+ retval = g_strdup("");;
+ *cancel=TRUE;
+ break;
+ }
- gtk_widget_show (win);
+ gtk_widget_hide(passdialog);
+ gtk_widget_destroy(passdialog);
+ while (gtk_events_pending()){
+ gtk_main_iteration();
+ }
- return TRUE;
+ return retval;
}
-static void
-modest_ui_window_destroy (GtkWidget *win, gpointer data)
+void
+on_account_selector_selection_changed (GtkWidget *widget, gpointer user_data)
{
- ModestUIPrivate *priv;
+ GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(widget));
+ GtkTreeIter iter;
- g_return_if_fail (data);
+ gchar *account_name;
- priv = MODEST_UI_GET_PRIVATE((ModestUI*)data);
- if (!modest_window_mgr_unregister (priv->modest_window_mgr, G_OBJECT(win)))
- g_warning ("modest window mgr: failed to unregister %p",
- G_OBJECT(win));
+ if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget), &iter)) {
+ gtk_tree_model_get(GTK_TREE_MODEL(model), &iter,
+ 0, &account_name, -1);
+ } else {
+ account_name="empty";
+ }
+
+ free(account_name);
}
-static void
-modest_ui_last_window_closed (GObject *obj, gpointer data)
-{
- gtk_main_quit ();
-}