* main-window:
[modest] / src / maemo / modest-main-window.c
index f8b849d..bc4e78d 100644 (file)
@@ -33,6 +33,7 @@
 #include <gtk/gtktreeviewcolumn.h>
 #include <tny-account-store-view.h>
 #include <modest-runtime.h>
+#include <string.h>
 
 #include <widgets/modest-main-window.h>
 #include <widgets/modest-msg-edit-window.h>
@@ -44,6 +45,7 @@
 #include "modest-account-mgr.h"
 #include "modest-conf.h"
 
+#include "modest-maemo-utils.h"
 #include "modest-tny-platform-factory.h"
 #include "modest-tny-msg.h"
 #include "modest-mail-operation.h"
@@ -132,6 +134,37 @@ modest_main_window_class_init (ModestMainWindowClass *klass)
        g_type_class_add_private (gobject_class, sizeof(ModestMainWindowPrivate));
 }
 
+
+static void
+on_key_changed (ModestConf* conf, const gchar *key, ModestConfEvent event, ModestMainWindow *win)
+{
+       TnyAccount *account;
+       
+       if (!key || strcmp (key, MODEST_CONF_DEVICE_NAME) != 0)
+               return; /* wrong key */
+       
+       /* ok, the device name changed; thus, we have to update the
+        * local folder account name*/
+       account =
+               modest_tny_account_store_get_tny_account_by_account (modest_runtime_get_account_store(),
+                                                                    MODEST_LOCAL_FOLDERS_ACCOUNT_ID,
+                                                                    TNY_ACCOUNT_TYPE_STORE);
+       if (!account) {
+               g_printerr ("modest: could not get account\n");
+               return;
+       }
+
+       if (event == MODEST_CONF_EVENT_KEY_UNSET) 
+               tny_account_set_name (account, MODEST_LOCAL_FOLDERS_DEFAULT_DISPLAY_NAME);
+       else {
+               gchar *device_name = modest_conf_get_string (modest_runtime_get_conf(),
+                                                            MODEST_CONF_DEVICE_NAME, NULL);
+               tny_account_set_name (account, device_name);
+               g_free (device_name);
+       }
+       g_object_unref (G_OBJECT(account));     
+}
+
 static void
 modest_main_window_init (ModestMainWindow *obj)
 {
@@ -157,7 +190,6 @@ modest_main_window_finalize (GObject *obj)
        G_OBJECT_CLASS(parent_class)->finalize (obj);
 }
 
-
 GtkWidget*
 modest_main_window_get_child_widget (ModestMainWindow *self,
                                     ModestWidgetType widget_type)
@@ -177,7 +209,6 @@ modest_main_window_get_child_widget (ModestMainWindow *self,
        case MODEST_WIDGET_TYPE_FOLDER_VIEW:
                widget = (GtkWidget*)priv->folder_view; break;
        default:
-               g_return_val_if_reached (NULL);
                return NULL;
        }
 
@@ -287,9 +318,6 @@ get_toolbar (ModestMainWindow *self)
        
        /* Toolbar */
        toolbar       = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar");
-
-       gtk_progress_bar_set_text (GTK_PROGRESS_BAR(priv->progress_bar), "Connecting...");
-
        progress_box        = gtk_hbox_new (FALSE, HILDON_MARGIN_DEFAULT);
        progress_alignment  = gtk_alignment_new (0.5, 0.5, 1, 0);
        
@@ -308,7 +336,6 @@ get_toolbar (ModestMainWindow *self)
        gtk_toolbar_insert (GTK_TOOLBAR(toolbar), gtk_tool_button_new(stop_icon, NULL),
                            gtk_toolbar_get_n_items(GTK_TOOLBAR(toolbar)));
 
-
        gtk_widget_show_all (toolbar);
        return toolbar;
 }
@@ -325,24 +352,13 @@ connect_signals (ModestMainWindow *self)
 {      
        ModestWindowPrivate *parent_priv;
        ModestMainWindowPrivate *priv;
-       TnyDevice *device;
-       ModestTnyAccountStore *account_store;
        
        priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
        parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
-
-       account_store = modest_runtime_get_account_store ();
-       device        = tny_account_store_get_device(TNY_ACCOUNT_STORE(account_store));
        
        /* folder view */
        g_signal_connect (G_OBJECT(priv->folder_view), "folder_selection_changed",
                          G_CALLBACK(modest_ui_actions_on_folder_selection_changed), self);
-       g_signal_connect (G_OBJECT(priv->folder_view), "folder_moved",
-                         G_CALLBACK(modest_ui_actions_on_folder_moved), NULL);
-//     g_signal_connect (G_OBJECT(self->folder_view), "button-press-event",
-//                       G_CALLBACK (on_folder_view_button_press_event),self);
-//     g_signal_connect (self->folder_view,"popup-menu",
-//                       G_CALLBACK (on_folder_view_button_press_event),self);
 
        /* header view */
        g_signal_connect (G_OBJECT(priv->header_view), "status_update",
@@ -353,23 +369,35 @@ connect_signals (ModestMainWindow *self)
                          G_CALLBACK(modest_ui_actions_on_header_activated), self);
        g_signal_connect (G_OBJECT(priv->header_view), "item_not_found",
                          G_CALLBACK(modest_ui_actions_on_item_not_found), self);
-//     g_signal_connect (G_OBJECT(self->header_view), "button-press-event",
-//                       G_CALLBACK (on_header_view_button_press_event), self);
-//     g_signal_connect (G_OBJECT(self->header_view),"popup-menu",0
-//                       G_CALLBACK (on_header_view_button_press_event), self);
-
-       /* Account store */
-       g_signal_connect (G_OBJECT (modest_runtime_get_account_store()), "accounts_reloaded",
-                         G_CALLBACK (modest_ui_actions_on_accounts_reloaded), self);
-       
-       
+
        /* window */
        g_signal_connect (G_OBJECT(self), "destroy", G_CALLBACK(on_destroy), NULL);
        g_signal_connect (G_OBJECT(self), "delete-event", G_CALLBACK(on_delete_event), self);
+
+       
+       /* modest_maemo_utils_get_device_name will probably change
+        * MODEST_CONF_DEVICE_NAME. If that happens, we update the local folders
+        * account name in the callback
+        */
+       g_signal_connect (G_OBJECT(modest_runtime_get_conf()), "key_changed",
+                         G_CALLBACK(on_key_changed), self);
+
+       
+       g_signal_connect (G_OBJECT(self), "delete-event", G_CALLBACK(on_delete_event), self);
+
+
 }
 
 
+gboolean
+sync_accounts_cb (ModestMainWindow *win)
+{
+       modest_ui_actions_on_send_receive (NULL, MODEST_WINDOW(win));
+       return FALSE;
+}
+
 
+       
 ModestWindow*
 modest_main_window_new (void)
 {
@@ -399,7 +427,8 @@ modest_main_window_new (void)
        g_object_unref (action_group);
 
        /* Load the UI definition */
-       gtk_ui_manager_add_ui_from_file (parent_priv->ui_manager, MODEST_UIDIR "modest-main-window-ui.xml", &error);
+       gtk_ui_manager_add_ui_from_file (parent_priv->ui_manager,
+                                        MODEST_UIDIR "modest-main-window-ui.xml", &error);
        if (error != NULL) {
                g_warning ("Could not merge modest-ui.xml: %s", error->message);
                g_error_free (error);
@@ -425,8 +454,9 @@ modest_main_window_new (void)
        priv->folder_view = MODEST_FOLDER_VIEW(modest_folder_view_new (query));
        if (!priv->folder_view)
                g_printerr ("modest: cannot instantiate folder view\n");        
-       g_object_unref (G_OBJECT (query));
-       
+       g_object_unref (G_OBJECT (query));      
+       modest_maemo_utils_get_device_name ();
+
        /* header view */
        priv->header_view  =
                MODEST_HEADER_VIEW(modest_header_view_new (NULL, MODEST_HEADER_VIEW_STYLE_DETAILS));
@@ -436,7 +466,6 @@ modest_main_window_new (void)
        
        folder_win = wrapped_in_scrolled_window (GTK_WIDGET(priv->folder_view), FALSE);
        header_win = wrapped_in_scrolled_window (GTK_WIDGET(priv->header_view), FALSE);                    
-
        /* paned */
        priv->main_paned = gtk_hpaned_new ();
        gtk_paned_add1 (GTK_PANED(priv->main_paned), folder_win);
@@ -453,11 +482,11 @@ modest_main_window_new (void)
 
        gtk_window_set_title (GTK_WINDOW(self), _("Modest"));
        gtk_window_set_icon_from_file (GTK_WINDOW(self), MODEST_APP_ICON, NULL);
-       
        gtk_widget_show_all (main_vbox);
 
-       g_signal_connect (G_OBJECT(self), "delete-event",
-                         G_CALLBACK(on_delete_event), self);
+       /* should we hide the toolbar? */
+       if (!modest_conf_get_bool (modest_runtime_get_conf (), MODEST_CONF_SHOW_TOOLBAR, NULL))
+               gtk_widget_hide (parent_priv->toolbar);
 
        /* Connect signals */
        connect_signals (self);
@@ -465,5 +494,14 @@ modest_main_window_new (void)
        /* Set account store */
        tny_account_store_view_set_account_store (TNY_ACCOUNT_STORE_VIEW (priv->folder_view),
                                                  TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
+       g_idle_add ((GSourceFunc)sync_accounts_cb, self);
+       /* do send & receive when we are idle */
+       
        return MODEST_WINDOW(self);
 }
+
+
+
+
+
+