#endif /*HAVE_CONFIG_H*/
#include <glib/gi18n.h>
+#include <string.h>
#include "modest-ui-priv.h"
#include "modest-ui.h"
#include "modest-ui-actions.h"
#include "modest-icon-names.h"
#include "modest-tny-platform-factory.h"
#include "modest-account-view-window.h"
+#include "modest-account-mgr-helpers.h"
#include "modest-main-window.h"
+#include "modest-mail-operation.h"
#include <modest-widget-memory.h>
#include <tny-error.h>
#include <tny-simple-list.h>
+#include <tny-msg-view.h>
#define MODEST_UI_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
MODEST_TYPE_UI, \
static GObjectClass *parent_class = NULL;
/* '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 register_stock_icons ();
-static void connect_signals (ModestUI *self);
-/* static GtkUIManager *create_ui_manager (); */
-
-static void reply_forward_func (gpointer data, gpointer user_data);
-static void read_msg_func (gpointer data, gpointer user_data);
-static void get_msg_cb (TnyFolder *folder,
- TnyMsg *msg,
- GError **err,
- gpointer user_data);
-
-static void reply_forward (GtkWidget *widget,
- ReplyForwardAction action,
- ModestMainWindow *main_window);
-
-static void _modest_ui_actions_on_password_requested (ModestTnyAccountStore *account_store,
- const gchar* account_name,
- gchar **password,
- gboolean *cancel,
- gboolean *remember,
- ModestMainWindow *main_window);
+static void modest_ui_class_init (ModestUIClass *klass);
+static void modest_ui_init (ModestUI *obj);
+static void modest_ui_finalize (GObject *obj);
+
+static void register_stock_icons ();
+static void connect_signals (ModestUI *self);
+
+static void reply_forward_func (gpointer data,
+ gpointer user_data);
+static void read_msg_func (gpointer data,
+ gpointer user_data);
+static void get_msg_cb (TnyFolder *folder,
+ TnyMsg *msg,
+ GError **err,
+ gpointer user_data);
+
+static void reply_forward (GtkWidget *widget,
+ ReplyForwardAction action,
+ ModestMainWindow *main_window);
+
+static gchar* ask_for_folder_name (GtkWindow *parent_window,
+ const gchar *title);
GType
modest_ui_get_type (void)
static void
modest_ui_finalize (GObject *obj)
{
-
ModestUIPrivate *priv = MODEST_UI_GET_PRIVATE(obj);
if (priv->widget_factory) {
g_object_unref (G_OBJECT(priv->ui_manager));
priv->ui_manager = NULL;
}
-
+
G_OBJECT_CLASS(parent_class)->finalize (obj);
}
{ MODEST_STOCK_DELETE, "delete", 0, 0, NULL },
{ MODEST_STOCK_NEXT, "next", 0, 0, NULL },
{ MODEST_STOCK_PREV, "prev", 0, 0, NULL },
- { MODEST_STOCK_STOP, "stop", 0, 0, NULL }
+/* { MODEST_STOCK_STOP, "stop", 0, 0, NULL } */
};
static gchar *items_names [] = {
MODEST_TOOLBAR_ICON_DELETE,
MODEST_TOOLBAR_ICON_NEXT,
MODEST_TOOLBAR_ICON_PREV,
- MODEST_TOOLBAR_ICON_STOP
+/* MODEST_TOOLBAR_ICON_STOP */
};
registered = TRUE;
/* folder view */
g_signal_connect (G_OBJECT(folder_view), "folder_selection_changed",
G_CALLBACK(_modest_ui_actions_on_folder_selection_changed),
- priv->main_window);
-/* g_signal_connect (G_OBJECT(folder_view), "key-press-event", */
-/* G_CALLBACK(on_folder_key_press_event), priv->widget_factory); */
-
+ priv->main_window);
/* header view */
g_signal_connect (G_OBJECT(header_view), "status_update",
G_CALLBACK(_modest_ui_actions_on_header_status_update),
g_signal_connect (G_OBJECT(header_view), "item_not_found",
G_CALLBACK(_modest_ui_actions_on_item_not_found),
priv->main_window);
-
-
/* msg preview */
g_signal_connect (G_OBJECT(msg_view), "link_clicked",
G_CALLBACK(_modest_ui_actions_on_msg_link_clicked),
G_CALLBACK(_modest_ui_actions_on_online_toggle_toggled),
priv->main_window);
- /* account store */
- g_signal_connect (G_OBJECT (priv->account_store),
- "password_requested",
- G_CALLBACK(_modest_ui_actions_on_password_requested),
- priv->main_window);
-
/* Destroy window */
g_signal_connect (G_OBJECT(priv->main_window),
"destroy",
/* ***************************************************************** */
/* M O D E S T U I A C T I O N S */
/* ***************************************************************** */
-void
+void
_modest_ui_actions_on_about (GtkWidget *widget,
ModestMainWindow *main_window)
{
TnyIterator *iter;
GtkTreeModel *model;
- widget_factory = modest_main_window_get_widget_factory (main_window);
+ widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (main_window));
header_view = modest_widget_factory_get_header_view (widget_factory);
header_list = modest_header_view_get_selected_headers (header_view);
g_object_unref (G_OBJECT(widget_factory));
GtkWidget *account_win;
ModestWidgetFactory *widget_factory;
- widget_factory = modest_main_window_get_widget_factory (main_window);
+ widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (main_window));
account_win = modest_account_view_window_new (widget_factory);
g_object_unref (G_OBJECT(widget_factory));
ModestWidgetFactory *widget_factory;
TnyAccountStore *account_store;
- widget_factory = modest_main_window_get_widget_factory (main_window);
- account_store = modest_main_window_get_account_store (main_window);
+ widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (main_window));
+ account_store = modest_window_get_account_store (MODEST_WINDOW (main_window));
msg_win = modest_edit_msg_window_new (widget_factory,
account_store,
MODEST_EDIT_TYPE_NEW);
g_object_unref (G_OBJECT (widget_factory));
g_object_unref (G_OBJECT (account_store));
- gtk_widget_show (GTK_WIDGET (msg_win));
+ gtk_widget_show_all (GTK_WIDGET (msg_win));
}
static void
TnyAccountStore *account_store;
GetMsgAsyncHelper *helper;
ReplyForwardHelper *rf_helper;
- GtkWindow *msg_win;
+ ModestWindow *msg_win;
ModestEditType edit_type;
msg = TNY_MSG (data);
rf_helper->from,
rf_helper->reply_forward_type,
MODEST_MAIL_OPERATION_REPLY_MODE_SENDER);
+ break;
case ACTION_REPLY_TO_ALL:
new_msg =
modest_mail_operation_create_reply_mail (msg, rf_helper->from, rf_helper->reply_forward_type,
modest_mail_operation_create_forward_mail (msg, rf_helper->from, rf_helper->reply_forward_type);
edit_type = MODEST_EDIT_TYPE_FORWARD;
break;
+ default:
+ g_return_if_reached ();
}
- /* Set from */
- new_header = tny_msg_get_header (new_msg);
- tny_header_set_from (new_header, rf_helper->from);
- g_object_unref (G_OBJECT (new_header));
+ if (!new_msg) {
+ g_warning ("Unable to create a message");
+ goto cleanup;
+ }
+
+/* /\* Set from *\/ */
+/* new_header = tny_msg_get_header (new_msg); */
+/* tny_header_set_from (new_header, rf_helper->from); */
+/* g_object_unref (G_OBJECT (new_header)); */
/* Show edit window */
- widget_factory = modest_main_window_get_widget_factory (helper->main_window);
- account_store = modest_main_window_get_account_store (helper->main_window);
+ widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (helper->main_window));
+ account_store = modest_window_get_account_store (MODEST_WINDOW (helper->main_window));
msg_win = modest_edit_msg_window_new (widget_factory,
account_store,
MODEST_EDIT_TYPE_NEW);
g_object_unref (G_OBJECT (widget_factory));
g_object_unref (G_OBJECT (account_store));
+
modest_edit_msg_window_set_msg (MODEST_EDIT_MSG_WINDOW (msg_win),
new_msg);
- gtk_widget_show (GTK_WIDGET (msg_win));
+ gtk_widget_show_all (GTK_WIDGET (msg_win));
/* Clean */
g_object_unref (G_OBJECT (new_msg));
+
+ cleanup:
g_free (rf_helper->from);
g_slice_free (ReplyForwardHelper, rf_helper);
}
ModestMainWindow *main_window)
{
ModestHeaderView *header_view;
+ ModestAccountMgr *account_mgr;
ModestWidgetFactory *widget_factory;
TnyList *header_list;
guint reply_forward_type;
- ModestConf *conf;
+ ModestConf *conf;
+ ModestAccountData *default_account_data;
TnyPlatformFactory *plat_factory;
TnyHeader *header;
TnyFolder *folder;
- gchar *from, *key;
+ gchar *from, *key, *default_account_name;
GetMsgAsyncHelper *helper;
ReplyForwardHelper *rf_helper;
g_free (key);
/* Get the list of headers */
- widget_factory = modest_main_window_get_widget_factory (main_window);
+ widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (main_window));
header_view = modest_widget_factory_get_header_view (widget_factory);
header_list = modest_header_view_get_selected_headers (header_view);
g_object_unref (G_OBJECT(widget_factory));
same folder and that we reply all of them from the
same account. In fact the interface currently only
allows single selection */
-
- /* TODO: get the from string from account */
- from = g_strdup ("Invalid");
+ account_mgr = modest_tny_platform_factory_get_account_mgr_instance
+ (MODEST_TNY_PLATFORM_FACTORY(plat_factory));
+ default_account_name = modest_account_mgr_get_default_account (account_mgr);
+ default_account_data =
+ modest_account_mgr_get_account_data (account_mgr,
+ (const gchar*) default_account_name);
+ from = g_strdup (default_account_data->email);
+ modest_account_mgr_free_account_data (account_mgr, default_account_data);
+ g_free (default_account_name);
/* Fill helpers */
rf_helper = g_slice_new0 (ReplyForwardHelper);
ModestHeaderView *header_view;
ModestWidgetFactory *widget_factory;
- widget_factory = modest_main_window_get_widget_factory (main_window);
+ widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (main_window));
header_view = modest_widget_factory_get_header_view (widget_factory);
g_object_unref (G_OBJECT(widget_factory));
modest_header_view_select_next (header_view);
}
+void
+_modest_ui_actions_toggle_view (GtkWidget *widget,
+ ModestMainWindow *main_window)
+{
+ ModestHeaderView *header_view;
+ ModestWidgetFactory *widget_factory;
+ ModestConf *conf;
+ TnyPlatformFactory *plat_factory;
+
+ /* Get ModestConf */
+ plat_factory = modest_tny_platform_factory_get_instance ();
+ conf = modest_tny_platform_factory_get_conf_instance
+ (MODEST_TNY_PLATFORM_FACTORY(plat_factory));
+ widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (main_window));
+ header_view = modest_widget_factory_get_header_view (widget_factory);
+ g_object_unref (G_OBJECT(widget_factory));
+
+ /* what is saved/restored is depending on the style; thus; we save with
+ * old style, then update the style, and restore for this new style*/
+ modest_widget_memory_save (conf, G_OBJECT(header_view), "header-view");
+
+ if (modest_header_view_get_style (header_view) == MODEST_HEADER_VIEW_STYLE_DETAILS)
+ modest_header_view_set_style (header_view, MODEST_HEADER_VIEW_STYLE_TWOLINES);
+ else
+ modest_header_view_set_style (header_view, MODEST_HEADER_VIEW_STYLE_DETAILS);
+
+ modest_widget_memory_restore (conf, G_OBJECT(header_view), "header-view");
+}
+
+
/*
* Marks a message as read and passes it to the msg preview widget
g_object_unref (G_OBJECT (header));
/* Set message on msg view */
- widget_factory = modest_main_window_get_widget_factory (helper->main_window);
+ widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (helper->main_window));
msg_view = modest_widget_factory_get_msg_preview (widget_factory);
g_object_unref (G_OBJECT(widget_factory));
modest_msg_view_set_message (msg_view, msg);
ModestHeaderView *header_view;
ModestWidgetFactory *widget_factory;
- widget_factory = modest_main_window_get_widget_factory (helper->main_window);
+ widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (helper->main_window));
header_view = modest_widget_factory_get_header_view (widget_factory);
g_object_unref (G_OBJECT (widget_factory));
- _modest_ui_actions_on_item_not_found (header_view,
- MODEST_ITEM_TYPE_MESSAGE,
+ _modest_ui_actions_on_item_not_found (header_view,
+ MODEST_ITEM_TYPE_MESSAGE,
helper->main_window);
return;
}
GetMsgAsyncHelper *helper;
TnyList *list;
- if (!header)
+ /* when there's no header, clear the msgview */
+ if (!header) {
+ ModestMsgView *msg_view;
+ ModestWidgetFactory *widget_factory;
+ widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (main_window));
+ msg_view = modest_widget_factory_get_msg_preview (widget_factory);
+ modest_msg_view_set_message (msg_view, NULL);
return;
+ }
folder = tny_header_get_folder (TNY_HEADER(header));
helper->func = read_msg_func;
tny_folder_get_msg_async (TNY_FOLDER(folder),
- header,
- get_msg_cb,
+ header, get_msg_cb,
helper);
/* Frees */
ModestHeaderView *header_view;
ModestWidgetFactory *widget_factory;
- widget_factory = modest_main_window_get_widget_factory (main_window);
+ widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (main_window));
folder_info_label =
GTK_LABEL (modest_widget_factory_get_folder_info_label (widget_factory));
modest_widget_memory_save (conf, G_OBJECT (header_view),
"header-view");
gtk_window_set_title (GTK_WINDOW(main_window), "Modest");
+ modest_header_view_set_folder (header_view, NULL);
} else { /* the folder was selected */
- guint num, unread;
- gchar *title;
- num = tny_folder_get_all_count (folder);
- unread = tny_folder_get_unread_count (folder);
-
- title = g_strdup_printf ("Modest: %s",
- tny_folder_get_name (folder));
-
- gtk_window_set_title (GTK_WINDOW(main_window), title);
- g_free (title);
+ if (folder) { /* folder may be NULL */
+ guint num, unread;
+ gchar *title;
- txt = g_strdup_printf (_("%d %s, %d unread"),
- num, num==1 ? _("item") : _("items"), unread);
- gtk_label_set_label (GTK_LABEL(folder_info_label), txt);
- g_free (txt);
+ num = tny_folder_get_all_count (folder);
+ unread = tny_folder_get_unread_count (folder);
+
+ title = g_strdup_printf ("Modest: %s",
+ tny_folder_get_name (folder));
+ gtk_window_set_title (GTK_WINDOW(main_window), title);
+ g_free (title);
+
+ txt = g_strdup_printf (_("%d %s, %d unread"),
+ num, num==1 ? _("item") : _("items"), unread);
+ gtk_label_set_label (GTK_LABEL(folder_info_label), txt);
+ g_free (txt);
+ }
modest_header_view_set_folder (header_view, folder);
modest_widget_memory_restore (conf, G_OBJECT(header_view),
"header-view");
}
}
-void
-_modest_ui_actions_on_password_requested (ModestTnyAccountStore *account_store,
- const gchar* account_name,
- gchar **password,
- gboolean *cancel,
- gboolean *remember,
- ModestMainWindow *main_window)
-{
- gchar *txt;
- GtkWidget *dialog, *entry, *remember_pass_check;
-
- dialog = gtk_dialog_new_with_buttons (_("Password requested"),
- GTK_WINDOW (main_window),
- GTK_DIALOG_MODAL,
- GTK_STOCK_CANCEL,
- GTK_RESPONSE_REJECT,
- GTK_STOCK_OK,
- GTK_RESPONSE_ACCEPT,
- NULL);
-
- txt = g_strdup_printf (_("Please enter your password for %s"), account_name);
- gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt),
- FALSE, FALSE, 0);
- g_free (txt);
-
- entry = gtk_entry_new_with_max_length (40);
- gtk_entry_set_visibility (GTK_ENTRY(entry), FALSE);
- gtk_entry_set_invisible_char (GTK_ENTRY(entry), 0x2022); /* bullet unichar */
-
- gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry,
- TRUE, FALSE, 0);
-
- remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
- gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
- TRUE, FALSE, 0);
-
- gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
-
- if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
- *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry)));
- *cancel = FALSE;
- } else {
- *password = NULL;
- *cancel = TRUE;
- }
-
- if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
- *remember = TRUE;
- else
- *remember = FALSE;
-
- gtk_widget_destroy (dialog);
-
- while (gtk_events_pending ())
- gtk_main_iteration ();
-}
/****************************************************/
/*
guint msg_id;
} StatusRemoveData;
+
+static gboolean
+progress_bar_clean (GtkWidget *bar)
+{
+ if (GTK_IS_PROGRESS_BAR(bar)) {
+ gtk_progress_bar_set_text (GTK_PROGRESS_BAR(bar), "");
+ gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(bar), 1.0);
+ }
+ return FALSE;
+}
+
static gboolean
-on_statusbar_remove_msg (StatusRemoveData *data)
+statusbar_clean (GtkWidget *bar)
{
- /* we need to test types, as this callback maybe called after the
- * widgets have been destroyed
- */
- if (GTK_IS_STATUSBAR(data->status_bar))
- gtk_statusbar_remove (GTK_STATUSBAR(data->status_bar),
- 0, data->msg_id);
- if (GTK_IS_PROGRESS_BAR(data->progress_bar))
- gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(data->progress_bar),
- 1.0);
- g_free (data);
+ if (GTK_IS_STATUSBAR(bar))
+ gtk_statusbar_push (GTK_STATUSBAR(bar), 0, "");
return FALSE;
}
+
static void
statusbar_push (ModestWidgetFactory *factory, guint context_id, const gchar *msg)
{
- guint id;
- StatusRemoveData *data;
GtkWidget *status_bar, *progress_bar;
if (!msg)
progress_bar = modest_widget_factory_get_progress_bar (factory);
status_bar = modest_widget_factory_get_status_bar (factory);
-
- id = gtk_statusbar_push (GTK_STATUSBAR(status_bar), 0, msg);
- data = g_new (StatusRemoveData, 1);
- data->status_bar = status_bar;
- data->progress_bar = progress_bar;
- data->msg_id = id;
+ gtk_widget_show (GTK_WIDGET(status_bar));
+ gtk_widget_show (GTK_WIDGET(progress_bar));
+
+ gtk_statusbar_push (GTK_STATUSBAR(status_bar), 0, msg);
- g_timeout_add (1500, (GSourceFunc)on_statusbar_remove_msg, data);
+ g_timeout_add (1500, (GSourceFunc)statusbar_clean, status_bar);
+ g_timeout_add (3000, (GSourceFunc)progress_bar_clean, progress_bar);
}
/****************************************************************************/
ModestHeaderView *header_view;
ModestWidgetFactory *widget_factory;
- widget_factory = modest_main_window_get_widget_factory (main_window);
+ widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (main_window));
header_view = modest_widget_factory_get_header_view (widget_factory);
online_toggle = modest_widget_factory_get_online_toggle (widget_factory);
factory = modest_tny_platform_factory_get_instance ();
account_store = tny_platform_factory_new_account_store (factory);
device = tny_account_store_get_device (account_store);
-
- gdk_threads_enter ();
+
+ if (g_main_depth > 0)
+ gdk_threads_enter ();
online = tny_device_is_online (device);
if (online) {
}
}
gtk_widget_destroy (dialog);
- gdk_threads_leave ();
+ if (g_main_depth > 0)
+ gdk_threads_leave ();
}
+
+
void
_modest_ui_actions_on_header_status_update (ModestHeaderView *header_view,
const gchar *msg,
{
GtkWidget *progress_bar;
ModestWidgetFactory *widget_factory;
-
- widget_factory = modest_main_window_get_widget_factory (main_window);
+ char* txt;
+
+ widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (main_window));
progress_bar = modest_widget_factory_get_progress_bar (widget_factory);
if (total != 0)
else
gtk_progress_bar_pulse (GTK_PROGRESS_BAR(progress_bar));
+ txt = g_strdup_printf (_("Downloading %d of %d"), num, total);
+ gtk_progress_bar_set_text (GTK_PROGRESS_BAR(progress_bar), txt);
+ g_free (txt);
+
statusbar_push (widget_factory, 0, msg);
-
+
/* Free */
g_object_unref (G_OBJECT (widget_factory));
}
+
void
_modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview,
const gchar* link,
{
ModestWidgetFactory *widget_factory;
- widget_factory = modest_main_window_get_widget_factory (main_window);
+ widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (main_window));
statusbar_push (widget_factory, 0, link);
g_object_unref (G_OBJECT (widget_factory));
ModestWidgetFactory *widget_factory;
msg = g_strdup_printf (_("Opening %s..."), link);
- widget_factory = modest_main_window_get_widget_factory (main_window);
+ widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (main_window));
statusbar_push (widget_factory, 0, msg);
g_object_unref (G_OBJECT (widget_factory));
ModestWidgetFactory *widget_factory;
msg = g_strdup_printf (_("Opening attachment %d..."), index);
- widget_factory = modest_main_window_get_widget_factory (main_window);
+ widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (main_window));
statusbar_push (widget_factory, 0, msg);
g_free (msg);
TnyAccountStore *account_store;
accounts = TNY_LIST(tny_simple_list_new ());
- account_store = modest_edit_msg_window_get_account_store (edit_window);
+ account_store = modest_window_get_account_store (MODEST_WINDOW (edit_window));
tny_account_store_get_accounts (account_store, accounts,
TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS);
g_object_unref (G_OBJECT (account_store));
/* save_settings (edit_window) */
gtk_widget_destroy (GTK_WIDGET (edit_window));
}
+
+/*
+ * Shows a dialog with an entry that asks for some text. The returned
+ * value must be freed by the caller. The dialog window title will be
+ * set to @title.
+ */
+static gchar *
+ask_for_folder_name (GtkWindow *parent_window,
+ const gchar *title)
+{
+ GtkWidget *dialog, *entry;
+ gchar *folder_name = NULL;
+
+ /* Ask for folder name */
+ dialog = gtk_dialog_new_with_buttons (_("New Folder Name"),
+ parent_window,
+ GTK_DIALOG_MODAL,
+ GTK_STOCK_CANCEL,
+ GTK_RESPONSE_REJECT,
+ GTK_STOCK_OK,
+ GTK_RESPONSE_ACCEPT,
+ NULL);
+ gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
+ gtk_label_new(title),
+ FALSE, FALSE, 0);
+
+ entry = gtk_entry_new_with_max_length (40);
+ gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
+ entry,
+ TRUE, FALSE, 0);
+
+ gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
+
+ if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
+ folder_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
+
+ gtk_widget_destroy (dialog);
+
+ return folder_name;
+}
+
+void
+_modest_ui_actions_on_new_folder (GtkWidget *widget,
+ ModestMainWindow *main_window)
+{
+ TnyFolder *parent_folder;
+ ModestFolderView *folder_view;
+ ModestWidgetFactory *widget_factory;
+
+ widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (main_window));
+ folder_view = modest_widget_factory_get_folder_view (widget_factory);
+ parent_folder = modest_folder_view_get_selected (folder_view);
+
+ if (parent_folder) {
+ gchar *folder_name;
+
+ folder_name = ask_for_folder_name (GTK_WINDOW (main_window),
+ _("Please enter a name for the new folder"));
+
+ if (folder_name != NULL && strlen (folder_name) > 0) {
+ TnyFolder *new_folder;
+ ModestMailOperation *mail_op;
+
+ mail_op = modest_mail_operation_new ();
+ new_folder = modest_mail_operation_create_folder (mail_op,
+ TNY_FOLDER_STORE (parent_folder),
+ (const gchar *) folder_name);
+ if (new_folder) {
+ /* Do anything more? The model
+ is automatically updated */
+ g_object_unref (new_folder);
+ }
+ g_object_unref (mail_op);
+ }
+ g_object_unref (parent_folder);
+ }
+ g_object_unref (G_OBJECT (widget_factory));
+}
+
+void
+_modest_ui_actions_on_rename_folder (GtkWidget *widget,
+ ModestMainWindow *main_window)
+{
+ TnyFolder *folder;
+ ModestFolderView *folder_view;
+ ModestWidgetFactory *widget_factory;
+
+ widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (main_window));
+ folder_view = modest_widget_factory_get_folder_view (widget_factory);
+ folder = modest_folder_view_get_selected (folder_view);
+
+ if (folder) {
+ gchar *folder_name;
+
+ folder_name = ask_for_folder_name (GTK_WINDOW (main_window),
+ _("Please enter a new name for the folder"));
+
+ if (folder_name != NULL && strlen (folder_name) > 0) {
+ ModestMailOperation *mail_op;
+
+ mail_op = modest_mail_operation_new ();
+ modest_mail_operation_rename_folder (mail_op,
+ folder,
+ (const gchar *) folder_name);
+ g_object_unref (mail_op);
+ }
+ g_object_unref (folder);
+ }
+ g_object_unref (G_OBJECT (widget_factory));
+}
+
+static void
+delete_folder (ModestMainWindow *main_window,
+ gboolean move_to_trash)
+{
+ TnyFolder *folder;
+ ModestFolderView *folder_view;
+ ModestWidgetFactory *widget_factory;
+ ModestMailOperation *mail_op;
+
+ widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (main_window));
+ folder_view = modest_widget_factory_get_folder_view (widget_factory);
+ folder = modest_folder_view_get_selected (folder_view);
+
+ mail_op = modest_mail_operation_new ();
+ modest_mail_operation_remove_folder (mail_op, folder, move_to_trash);
+ g_object_unref (mail_op);
+}
+
+void
+_modest_ui_actions_on_delete_folder (GtkWidget *widget,
+ ModestMainWindow *main_window)
+{
+ delete_folder (main_window, FALSE);
+}
+
+void
+_modest_ui_actions_on_move_to_trash_folder (GtkWidget *widget,
+ ModestMainWindow *main_window)
+{
+ delete_folder (main_window, TRUE);
+}