Changeset 76

Show
Ignore:
Timestamp:
04/15/08 18:45:16
Author:
pvanhoof
Message:
        • Implemented simple account management
        • Implemented a new account store
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ChangeLog

    r75 r76  
    22 
    33        * Added the first signs of simple account management 
     4        * Implemented simple account management 
     5        * Implemented a new account store 
    46 
    572008-03-26  Philip Van Hoof  <pvanhoof@gnome.org> 
  • trunk/src/tmut-account-editor.c

    r75 r76  
    4545 
    4646        GtkWidget *name_entry, *hostname_entry, *enabled_checkbutton, 
    47                   *proto_entry, *type_entry, *user_entry
     47                  *proto_entry, *type_entry, *user_entry, *options_entry
    4848}; 
    4949 
     
    5555tmut_account_editor_get_enabled (TMutAccountEditor *self) 
    5656{ 
    57         //TMutAccountEditorPriv *priv = TMUT_ACCOUNT_EDITOR_GET_PRIVATE (self); 
    5857        return TRUE; 
    59         //return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->enabled_checkbutton)); 
    6058} 
    6159 
     
    9593} 
    9694 
    97 const gchar**  
     95gchar**  
    9896tmut_account_editor_get_options (TMutAccountEditor *self) 
    9997{ 
    100         return NULL; 
     98        TMutAccountEditorPriv *priv = TMUT_ACCOUNT_EDITOR_GET_PRIVATE (self); 
     99        const gchar *str = gtk_entry_get_text (GTK_ENTRY (priv->options_entry)); 
     100        return g_strsplit (str?str:"", ",", -1); 
    101101} 
    102102 
     
    140140        g_signal_emit (G_OBJECT (self),  
    141141                tmut_account_editor_signals [TMUT_ACCOUNT_EDITOR_OK_CLICKED], 0); 
     142        tmut_shell_window_back (tmut_shell_child_get_window (TMUT_SHELL_CHILD (user_data))); 
    142143        return; 
    143144} 
     
    158159        GtkWidget *ok_button, *cancel_button; 
    159160        GtkWidget *hbox = gtk_hbox_new (FALSE, 0); 
    160         table = gtk_table_new (5, 2, FALSE); 
     161        table = gtk_table_new (6, 2, FALSE); 
    161162 
    162163        gtk_widget_show (hbox); 
     
    207208        gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); 
    208209 
     210        label = gtk_label_new (_("Options")); 
     211        gtk_widget_show (label); 
     212        gtk_table_attach (GTK_TABLE (table), label, 0, 1, 5, 6, 
     213        (GtkAttachOptions) (GTK_FILL), 
     214        (GtkAttachOptions) (0), 0, 0); 
     215        gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); 
     216 
    209217        priv->name_entry = gtk_entry_new (); 
    210218        gtk_widget_show (priv->name_entry); 
     
    234242        gtk_widget_show (priv->type_entry); 
    235243        gtk_table_attach (GTK_TABLE (table), priv->type_entry, 1, 2, 4, 5, 
     244                (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 
     245                (GtkAttachOptions) (0), 0, 0); 
     246 
     247        priv->options_entry = gtk_entry_new (); 
     248        gtk_widget_show (priv->options_entry); 
     249        gtk_table_attach (GTK_TABLE (table), priv->options_entry, 1, 2, 5, 6, 
    236250                (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 
    237251                (GtkAttachOptions) (0), 0, 0); 
  • trunk/src/tmut-account-editor.h

    r75 r76  
    6363const gchar* tmut_account_editor_get_account_type (TMutAccountEditor *self);  
    6464const gchar* tmut_account_editor_get_user (TMutAccountEditor *self); 
    65 const gchar** tmut_account_editor_get_options (TMutAccountEditor *self); 
     65gchar** tmut_account_editor_get_options (TMutAccountEditor *self); 
    6666TnyAccount *tmut_account_editor_get_account (TMutAccountEditor *self); 
    6767 
  • trunk/src/tmut-account-manager.c

    r75 r76  
    4141        GtkComboBox *accounts_combo; 
    4242        TMutShellWindow *shell; 
     43        TnyAccount *account; 
    4344        TnyAccountStore *account_store; 
    44         TnyAccount *account
     45        gint account_created_signal, account_deleted_signal
    4546}; 
    4647 
     
    6970        OnEditOrNewInfo *info = (OnEditOrNewInfo *) user_data; 
    7071        TMutAccountManagerPriv *priv = TMUT_ACCOUNT_MANAGER_GET_PRIVATE (info->self); 
     72        gchar **options = tmut_account_editor_get_options (editor); 
    7173 
    7274        tmut_account_store_create_account (TMUT_ACCOUNT_STORE (priv->account_store),  
     
    7779                tmut_account_editor_get_account_type (editor),  
    7880                tmut_account_editor_get_user (editor),  
    79                 tmut_account_editor_get_options (editor)); 
     81                NULL, -1, 
     82                (const char **) options); 
     83 
     84        g_strfreev (options); 
    8085} 
    8186 
     
    8792        TMutAccountManagerPriv *priv = TMUT_ACCOUNT_MANAGER_GET_PRIVATE (info->self); 
    8893        TnyAccount *account = tmut_account_editor_get_account (editor); 
     94        gchar **options = tmut_account_editor_get_options (editor); 
    8995 
    9096        tmut_account_store_edit_account (TMUT_ACCOUNT_STORE (priv->account_store),  
     
    94100                tmut_account_editor_get_hostname (editor),  
    95101                tmut_account_editor_get_proto (editor),  
    96                 tmut_account_editor_get_account_type (editor),  
    97102                tmut_account_editor_get_user (editor),  
    98                 tmut_account_editor_get_options (editor)); 
     103                NULL, -1, 
     104                (const char **) options); 
     105 
     106        g_strfreev (options); 
    99107 
    100108        g_object_unref (account); 
     
    156164        g_object_unref (priv->account); 
    157165        priv->account = NULL; 
    158  
    159         g_print ("Delete"); 
    160166 
    161167        return; 
     
    248254 
    249255static void 
     256on_account_created (TMutAccountStore *store, TnyAccount *account, TMutAccountManager *self) 
     257{ 
     258        TMutAccountManagerPriv *priv = TMUT_ACCOUNT_MANAGER_GET_PRIVATE (self); 
     259        TnyList *model = TNY_LIST (gtk_combo_box_get_model (priv->accounts_combo)); 
     260        tny_list_prepend (model, (GObject *) account); 
     261} 
     262 
     263 
     264static void 
     265on_account_deleted (TMutAccountStore *store, TnyAccount *account, TMutAccountManager *self) 
     266{ 
     267        TMutAccountManagerPriv *priv = TMUT_ACCOUNT_MANAGER_GET_PRIVATE (self); 
     268        gtk_combo_box_set_active (priv->accounts_combo, -1); 
     269        TnyList *model = TNY_LIST (gtk_combo_box_get_model (priv->accounts_combo)); 
     270        tny_list_remove (model, (GObject *) account); 
     271} 
     272 
     273 
     274static void 
     275disconnect_account_store (TMutAccountManagerPriv *priv) 
     276{ 
     277        g_signal_handler_disconnect (priv->account_store, priv->account_created_signal); 
     278        g_signal_handler_disconnect (priv->account_store, priv->account_deleted_signal); 
     279        g_object_unref (priv->account_store); 
     280        priv->account_store = NULL; 
     281} 
     282 
     283static void 
    250284tmut_account_manager_set_account_store (TnyAccountStoreView *self, TnyAccountStore *account_store) 
    251285{ 
     
    259293 
    260294        if (priv->account_store) 
    261                 g_object_unref (priv->account_store); 
     295                disconnect_account_store (priv); 
    262296        priv->account_store = TNY_ACCOUNT_STORE (g_object_ref (account_store)); 
     297 
     298        priv->account_created_signal = g_signal_connect (G_OBJECT (priv->account_store), "account_created", 
     299                G_CALLBACK (on_account_created), self); 
     300        priv->account_deleted_signal = g_signal_connect (G_OBJECT (priv->account_store), "account_deleted", 
     301                G_CALLBACK (on_account_deleted), self); 
    263302 
    264303        TMUT_ACCOUNT_MANAGER_GET_CLASS (self)->create_menu (TMUT_ACCOUNT_MANAGER (self)); 
     
    275314        GtkVBox *vbox = GTK_VBOX (self); 
    276315        GtkCellRenderer *renderer; 
    277         GtkLabel *label = GTK_LABEL (gtk_label_new ("")); 
     316        GtkLabel *label = GTK_LABEL (gtk_label_new ("Account manager")); 
    278317 
    279318        priv->account_store = NULL; 
     319        priv->account_created_signal = -1; 
     320        priv->account_deleted_signal = -1; 
     321 
    280322        priv->account = NULL; 
    281323 
     
    308350 
    309351        if (priv->account_store) 
    310                 g_object_unref (priv->account_store); 
     352                disconnect_account_store (priv); 
    311353 
    312354        (*parent_class->finalize) (object); 
  • trunk/src/tmut-account-store.c

    r75 r76  
    2222#endif 
    2323 
     24#include <string.h> 
     25#include <glib.h> 
     26#include <gtk/gtk.h> 
    2427#include <glib/gi18n-lib.h> 
    25  
    26 #include <tmut-account-store.h> 
     28#include <glib/gstdio.h> 
     29#include <errno.h> 
     30#include <stdlib.h> 
     31 
     32#include "tmut-account-store.h" 
     33#include "tmut-platform-factory.h" 
     34 
     35#include <tny-gtk-lockable.h> 
     36#include <tny-platform-factory.h> 
     37#include <tny-password-getter.h> 
     38#include <tny-account-store.h> 
     39#include <tny-account.h> 
     40#include <tny-store-account.h> 
     41#include <tny-transport-account.h> 
     42#include <tny-device.h> 
     43 
     44#include <tny-camel-account.h> 
     45#include <tny-camel-store-account.h> 
     46#include <tny-camel-transport-account.h> 
     47#include <tny-session-camel.h> 
    2748 
    2849static GObjectClass *parent_class = NULL; 
    2950 
     51typedef enum { 
     52        TMUT_ACCOUNT_STORE_ACCOUNT_DELETED, 
     53        TMUT_ACCOUNT_STORE_ACCOUNT_CREATED, 
     54        TMUT_ACCOUNT_STORE_ACCOUNT_EDITED, 
     55        TMUT_ACCOUNT_STORE_LAST_SIGNAL 
     56} TMutAccountStoreSignal; 
     57 
     58static guint tmut_account_store_signals [TMUT_ACCOUNT_STORE_LAST_SIGNAL]; 
     59 
    3060typedef struct _TMutAccountStorePriv TMutAccountStorePriv; 
    3161 
    3262struct _TMutAccountStorePriv 
    3363{ 
    34         TnyAccountStore *decorated; 
     64        gchar *cache_dir; 
     65        TnySessionCamel *session; 
     66        TnyDevice *device; 
     67        guint notify; 
     68        GList *accounts; 
    3569}; 
    3670 
     
    3973 
    4074 
    41 void tmut_account_store_create_account (TMutAccountStore *self,  
     75static gchar*  
     76per_account_get_pass(TnyAccount *account, const gchar *prompt, gboolean *cancel) 
     77
     78        TnyPlatformFactory *platfact = tmut_platform_factory_get_instance (); 
     79        TnyPasswordGetter *pwdgetter; 
     80        gchar *retval; 
     81 
     82        pwdgetter = tny_platform_factory_new_password_getter (platfact); 
     83        retval = (gchar*) tny_password_getter_get_password (pwdgetter,  
     84                tny_account_get_id (account), prompt, cancel); 
     85        g_object_unref (pwdgetter); 
     86 
     87        return retval; 
     88
     89 
     90 
     91static void 
     92per_account_forget_pass(TnyAccount *account) 
     93
     94        TnyPlatformFactory *platfact = tmut_platform_factory_get_instance (); 
     95        TnyPasswordGetter *pwdgetter; 
     96 
     97        pwdgetter = tny_platform_factory_new_password_getter (platfact); 
     98        tny_password_getter_forget_password (pwdgetter, tny_account_get_id (account)); 
     99        g_object_unref (pwdgetter); 
     100 
     101        return; 
     102
     103 
     104static TnyAccount* 
     105create_account_instance (TMutAccountStorePriv *priv, const gchar *type, const gchar *proto, const gchar *mech, const gchar *name, gchar **options, const gchar *user, const gchar *hostname, gint port, const gchar *url_string, const gchar *fullfilen) 
     106
     107        TnyAccount *account = NULL; 
     108 
     109        if (!g_ascii_strncasecmp (proto, "smtp", 4)) 
     110                account = TNY_ACCOUNT (tny_camel_transport_account_new ()); 
     111        else if (!g_ascii_strncasecmp (proto, "imap", 4)) 
     112                account = TNY_ACCOUNT (tny_camel_imap_store_account_new ()); 
     113        else if (!g_ascii_strncasecmp (proto, "nntp", 4)) 
     114                account = TNY_ACCOUNT (tny_camel_nntp_store_account_new ()); 
     115        else if (!g_ascii_strncasecmp (proto, "pop", 3)) 
     116                account = TNY_ACCOUNT (tny_camel_pop_store_account_new ()); 
     117        else    /* Unknown, create a generic one? */ 
     118                account = TNY_ACCOUNT (tny_camel_store_account_new ()); 
     119 
     120        if (account) { 
     121                gint i; 
     122 
     123                tny_camel_account_set_session (TNY_CAMEL_ACCOUNT (account), priv->session); 
     124                tny_account_set_proto (account, proto); 
     125 
     126                if (name) 
     127                        tny_account_set_name (account, name); 
     128                if (mech) 
     129                        tny_account_set_secure_auth_mech (account, mech); 
     130 
     131                if (options) { 
     132                        gint i = 0; 
     133                        while (options[i] != NULL) { 
     134                                tny_camel_account_add_option (TNY_CAMEL_ACCOUNT (account), options[i]); 
     135                                i++; 
     136                        } 
     137                } 
     138 
     139                if (!g_ascii_strncasecmp (proto, "pop", 3) ||  
     140                    !g_ascii_strncasecmp (proto, "imap", 4)) { 
     141                        tny_account_set_user (account, user); 
     142                        tny_account_set_hostname (account, hostname); 
     143                        if (port != -1) 
     144                                tny_account_set_port (account, port); 
     145                } else 
     146                        tny_account_set_url_string (account, url_string); 
     147 
     148                tny_account_set_id (account, fullfilen); 
     149 
     150                tny_account_set_forget_pass_func (TNY_ACCOUNT (account), 
     151                        per_account_forget_pass); 
     152                tny_account_set_pass_func (TNY_ACCOUNT (account), 
     153                        per_account_get_pass); 
     154 
     155        } 
     156 
     157        return account; 
     158
     159 
     160void  
     161tmut_account_store_create_account (TMutAccountStore *self,  
    42162                gboolean enabled, 
    43163                const gchar *name,  
     
    46166                const gchar *type, 
    47167                const gchar *user, 
     168                const gchar *mech, 
     169                gint port, 
    48170                const gchar **options) 
    49171{ 
    50         g_print ("Create\n"); 
    51 
    52  
    53 void tmut_account_store_delete_account (TMutAccountStore *self, TnyAccount *account) 
    54 
    55         g_print ("Delete\n"); 
     172        TMutAccountStorePriv *priv = TMUT_ACCOUNT_STORE_GET_PRIVATE (self); 
     173        GList *found; 
     174        TnyAccount *account = NULL; 
     175        FILE *file; 
     176        GKeyFile *keyfile = g_key_file_new (); 
     177 
     178        gchar *filen = g_build_filename (g_get_home_dir(),  
     179                ".tmut", "accounts", name, NULL); 
     180 
     181        gchar *dirn = g_build_filename (g_get_home_dir(),  
     182                ".tmut", "accounts", NULL); 
     183 
     184        if (!g_file_test (dirn, G_FILE_TEST_EXISTS)) 
     185                g_mkdir_with_parents (dirn, S_IRUSR | S_IWUSR | S_IXUSR); 
     186 
     187        g_free (dirn); 
     188 
     189        if (g_file_test (filen, G_FILE_TEST_EXISTS)) { 
     190                g_warning ("%s already existed\n", filen); 
     191                g_unlink (filen); 
     192        } 
     193 
     194        g_key_file_set_value (keyfile, "tmut", "proto", proto); 
     195        g_key_file_set_value (keyfile, "tmut", "name", name); 
     196        g_key_file_set_value (keyfile, "tmut", "hostname", hostname); 
     197        g_key_file_set_value (keyfile, "tmut", "user", user); 
     198        g_key_file_set_value (keyfile, "tmut", "type", type); 
     199 
     200 
     201        if (options) { 
     202                gint options_len = 0; 
     203                while (options[options_len] != NULL) 
     204                        options_len++; 
     205                g_key_file_set_string_list (keyfile, "tmut", "options",  
     206                        options, options_len); 
     207        } 
     208 
     209        /* todo: port and mech */ 
     210 
     211        file = fopen (filen, "w"); 
     212 
     213        if (file) { 
     214                gsize len; 
     215                char *str = g_key_file_to_data (keyfile, &len, NULL); 
     216                fputs (str, file); 
     217                fclose (file); 
     218        } 
     219 
     220        account = create_account_instance (priv, type, proto, mech, name,  
     221                (gchar **) options, user, hostname, port, NULL, filen); 
     222 
     223        if (account) { 
     224                priv->accounts = g_list_prepend (priv->accounts, account); 
     225                g_signal_emit (self,  
     226                        tmut_account_store_signals [TMUT_ACCOUNT_STORE_ACCOUNT_CREATED],  
     227                        0, account); 
     228        } 
     229 
     230        g_key_file_free (keyfile); 
     231        g_free (filen); 
     232 
     233
     234 
     235void  
     236tmut_account_store_delete_account (TMutAccountStore *self, TnyAccount *account) 
     237
     238        TMutAccountStorePriv *priv = TMUT_ACCOUNT_STORE_GET_PRIVATE (self); 
     239        const gchar *filen = tny_account_get_id (account); 
     240        GList *found; 
     241        TnyAccount *found_account = NULL; 
     242 
     243        if (g_file_test (filen, G_FILE_TEST_EXISTS)) 
     244                g_unlink (filen); 
     245 
     246        found = g_list_find (priv->accounts, account); 
     247        if (found) { 
     248                found_account = found->data; 
     249                priv->accounts = g_list_delete_link (priv->accounts, found); 
     250        } 
     251 
     252        if (found_account) { 
     253                g_signal_emit (self,  
     254                        tmut_account_store_signals [TMUT_ACCOUNT_STORE_ACCOUNT_DELETED],  
     255                        0, found_account); 
     256                g_object_unref (found_account); 
     257        } 
     258 
    56259} 
    57260 
     
    61264                const gchar *hostname,  
    62265                const gchar *proto, 
    63                 const gchar *type, 
    64266                const gchar *user, 
     267                const gchar *mech, 
     268                gint port, 
    65269                const gchar **options) 
    66270{ 
    67         g_print ("Edit\n"); 
    68 
     271        TMutAccountStorePriv *priv = TMUT_ACCOUNT_STORE_GET_PRIVATE (self); 
     272        GList *found = g_list_find (priv->accounts, account); 
     273 
     274        if (found) { 
     275                TnyAccount *account = found->data; 
     276                const gchar *filen = tny_account_get_id (account); 
     277                FILE *file; 
     278                GKeyFile *keyfile = g_key_file_new (); 
     279 
     280                g_key_file_load_from_file (keyfile, filen, G_KEY_FILE_NONE, NULL); 
     281 
     282                if (name) { 
     283                        tny_account_set_name (account, name); 
     284                        g_key_file_set_value (keyfile, "tmut", "name", name); 
     285                } 
     286 
     287                if (hostname) { 
     288                        tny_account_set_hostname (account, hostname); 
     289                        g_key_file_set_value (keyfile, "tmut", "hostname", hostname); 
     290                } 
     291 
     292                if (proto) { 
     293                        tny_account_set_proto (account, proto); 
     294                        g_key_file_set_value (keyfile, "tmut", "proto", proto); 
     295                } 
     296 
     297                if (user) { 
     298                        tny_account_set_user (account, user); 
     299                        g_key_file_set_value (keyfile, "tmut", "user", user); 
     300                } 
     301 
     302                if (port != -1) { 
     303                        tny_account_set_port (account, port); 
     304                        g_key_file_set_integer (keyfile, "tmut", "port", port); 
     305                } 
     306 
     307                if (mech) { 
     308                        tny_account_set_secure_auth_mech (account, mech); 
     309                        g_key_file_set_value (keyfile, "tmut", "mech", mech); 
     310                } 
     311 
     312                if (options) { 
     313                        /* todo: sync account instance's options with new ones */ 
     314                        gint options_len = 0; 
     315                        while (options[options_len] != NULL) 
     316                                options_len++; 
     317                        g_key_file_set_string_list (keyfile, "tmut", "options",  
     318                                options, options_len); 
     319                } 
     320 
     321                file = fopen (filen, "w"); 
     322 
     323                if (file) { 
     324                        gsize len; 
     325                        char *str = g_key_file_to_data (keyfile, &len, NULL); 
     326                        fputs (str, file); 
     327                        fclose (file); 
     328                } 
     329 
     330                if (account) { 
     331                        g_signal_emit (self,  
     332                                tmut_account_store_signals [TMUT_ACCOUNT_STORE_ACCOUNT_EDITED],  
     333                                0, account); 
     334                } 
     335 
     336                g_key_file_free (keyfile); 
     337                g_list_free (found); 
     338        } 
     339
     340 
     341 
     342static void 
     343kill_stored_accounts (TMutAccountStorePriv *priv) 
     344
     345        if (priv->accounts) { 
     346                g_list_foreach (priv->accounts, (GFunc) g_object_unref, NULL); 
     347                g_list_free (priv->accounts); 
     348                priv->accounts = NULL; 
     349        } 
     350
     351 
     352 
     353static void 
     354load_accounts (TnyAccountStore *self) 
     355
     356        TMutAccountStorePriv *priv = TMUT_ACCOUNT_STORE_GET_PRIVATE (self); 
     357 
     358        const gchar *filen; 
     359        gchar *configd; 
     360        GDir *dir; 
     361 
     362        configd = g_build_path (G_DIR_SEPARATOR_S, g_get_home_dir(),  
     363                ".tmut", "accounts", NULL); 
     364        dir = g_dir_open (configd, 0, NULL); 
     365        g_free (configd); 
     366 
     367        if (!dir) 
     368                return; 
     369 
     370        for (filen = g_dir_read_name (dir); filen; filen = g_dir_read_name (dir)) { 
     371                GError *port_err = NULL; 
     372                GKeyFile *keyfile; 
     373                gchar *proto, *type, *user, *hostname, *url_string; 
     374                gchar *name, *mech, **options; 
     375                gsize options_len; 
     376                TnyAccount *account = NULL;  
     377                gint port = 0; 
     378                gchar *fullfilen = g_build_filename (g_get_home_dir(),  
     379                        ".tmut", "accounts", filen, NULL); 
     380 
     381                keyfile = g_key_file_new (); 
     382 
     383                if (!g_key_file_load_from_file (keyfile, fullfilen, G_KEY_FILE_NONE, NULL)) { 
     384                        g_free (fullfilen); 
     385                        continue; 
     386                } 
     387 
     388                if (g_key_file_get_boolean (keyfile, "tmut", "disabled", NULL)) { 
     389                        g_free (fullfilen); 
     390                        continue; 
     391                } 
     392 
     393                type = g_key_file_get_value (keyfile, "tmut", "type", NULL); 
     394                proto = g_key_file_get_value (keyfile, "tmut", "proto", NULL); 
     395                mech = g_key_file_get_value (keyfile, "tmut", "mech", NULL); 
     396                name = g_key_file_get_value (keyfile, "tmut", "name", NULL); 
     397                options = g_key_file_get_string_list (keyfile, "tmut",  
     398                        "options", &options_len, NULL); 
     399                user = g_key_file_get_value (keyfile, "tmut", "user", NULL); 
     400                hostname = g_key_file_get_value (keyfile, "tmut", "hostname", NULL); 
     401                url_string = g_key_file_get_value (keyfile, "tmut", "url_string", NULL); 
     402                port = g_key_file_get_integer (keyfile, "tmut", "port", &port_err); 
     403 
     404                if (port_err) { 
     405                        port = -1; 
     406                        g_error_free (port_err); 
     407                } 
     408 
     409                account = create_account_instance (priv, type, proto, mech, name, options, user, hostname, port, url_string, fullfilen); 
     410 
     411                if (account) 
     412                        priv->accounts = g_list_prepend (priv->accounts, account); 
     413 
     414                g_free (type); 
     415                if (options) 
     416                        g_strfreev (options); 
     417                g_free (url_string);  
     418                g_free (hostname);  
     419                g_free (user); 
     420                g_free (proto); 
     421                g_free (mech); 
     422 
     423                g_key_file_free (keyfile); 
     424        } 
     425        g_dir_close (dir); 
     426 
     427        tny_session_camel_set_initialized (priv->session); 
     428
     429 
    69430 
    70431static void 
     
    72433{ 
    73434        TMutAccountStorePriv *priv = TMUT_ACCOUNT_STORE_GET_PRIVATE (self); 
    74         tny_account_store_get_accounts (priv->decorated, list, types); 
     435 
     436        g_assert (TNY_IS_LIST (list)); 
     437 
     438        if (!priv->accounts) 
     439                load_accounts (self); 
     440 
     441        if (priv->accounts) { 
     442                GList *copy = priv->accounts; 
     443                while (copy) { 
     444                        TnyAccount *account = copy->data; 
     445                        if (types == TNY_ACCOUNT_STORE_BOTH || types == TNY_ACCOUNT_STORE_STORE_ACCOUNTS) { 
     446                                if (TNY_IS_STORE_ACCOUNT (account)) 
     447                                        tny_list_prepend (list, (GObject*) account); 
     448                        } else if (types == TNY_ACCOUNT_STORE_BOTH || types == TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS) { 
     449                                if (TNY_IS_TRANSPORT_ACCOUNT (account)) 
     450                                        tny_list_prepend (list, (GObject*) account); 
     451                        } 
     452                        copy = g_list_next (copy); 
     453                } 
     454        } 
     455 
     456        return; 
    75457} 
    76458 
     
    79461{ 
    80462        TMutAccountStorePriv *priv = TMUT_ACCOUNT_STORE_GET_PRIVATE (self); 
    81         return tny_account_store_get_cache_dir (priv->decorated); 
     463        if (!priv->cache_dir) 
     464                priv->cache_dir = g_build_path (G_DIR_SEPARATOR_S, g_get_home_dir(), ".tmut", NULL); 
     465        return priv->cache_dir; 
    82466} 
    83467 
     
    86470{ 
    87471        TMutAccountStorePriv *priv = TMUT_ACCOUNT_STORE_GET_PRIVATE (self); 
    88         return tny_account_store_get_device (priv->decorated); 
     472        return g_object_ref (priv->device); 
    89473} 
    90474 
     
    93477{ 
    94478        TMutAccountStorePriv *priv = TMUT_ACCOUNT_STORE_GET_PRIVATE (self); 
    95         return tny_account_store_alert (priv->decorated, account, type, question, error); 
     479        GtkMessageType gtktype; 
     480        gboolean retval = FALSE; 
     481        GtkWidget *dialog; 
     482 
     483        switch (type) { 
     484                case TNY_ALERT_TYPE_INFO: 
     485                gtktype = GTK_MESSAGE_INFO; 
     486                break; 
     487                case TNY_ALERT_TYPE_WARNING: 
     488                gtktype = GTK_MESSAGE_WARNING; 
     489                break; 
     490                case TNY_ALERT_TYPE_ERROR: 
     491                default: 
     492                gtktype = GTK_MESSAGE_ERROR; 
     493                break; 
     494        } 
     495 
     496        dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, 
     497                        gtktype, GTK_BUTTONS_YES_NO, error->message); 
     498 
     499        if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_YES) 
     500                retval = TRUE; 
     501 
     502        gtk_widget_destroy (dialog); 
     503 
     504        return retval; 
    96505} 
    97506 
     
    100509{ 
    101510        TMutAccountStorePriv *priv = TMUT_ACCOUNT_STORE_GET_PRIVATE (self); 
    102         return tny_account_store_find_account (priv->decorated, url_string); 
     511        TnyAccount *found = NULL; 
     512 
     513        if (!priv->accounts) 
     514                load_accounts (self); 
     515 
     516        if (priv->accounts) { 
     517                GList *copy = priv->accounts; 
     518                while (copy) { 
     519                        TnyAccount *account = copy->data; 
     520 
     521                        if (tny_account_matches_url_string (account, url_string)) { 
     522                                found = TNY_ACCOUNT (g_object_ref (G_OBJECT (account))); 
     523                                break; 
     524                        } 
     525                        copy = g_list_next (copy); 
     526                } 
     527        } 
     528 
     529        return found; 
    103530} 
    104531 
     
    109536        TMutAccountStorePriv *priv = TMUT_ACCOUNT_STORE_GET_PRIVATE (object); 
    110537 
    111         if (priv->decorated) 
    112                 g_object_unref (priv->decorated); 
     538        kill_stored_accounts (priv); 
     539 
     540        if (priv->cache_dir) 
     541                g_free (priv->cache_dir); 
     542 
     543        g_object_unref (priv->device); 
    113544 
    114545        parent_class->finalize (object); 
     
    121552        TMutAccountStore *self = g_object_new (TMUT_TYPE_ACCOUNT_STORE, NULL); 
    122553        TMutAccountStorePriv *priv = TMUT_ACCOUNT_STORE_GET_PRIVATE (self); 
    123         priv->decorated = TNY_ACCOUNT_STORE (g_object_ref (decorated)); 
     554        priv->session = tny_session_camel_new (TNY_ACCOUNT_STORE (self)); 
     555        tny_session_camel_set_ui_locker (priv->session, tny_gtk_lockable_new ()); 
    124556        return TNY_ACCOUNT_STORE (self); 
    125557} 
     
    129561{ 
    130562        TMutAccountStorePriv *priv = TMUT_ACCOUNT_STORE_GET_PRIVATE (instance); 
    131         priv->decorated = NULL; 
     563        TnyPlatformFactory *platfact = tmut_platform_factory_get_instance (); 
     564 
     565        priv->cache_dir = NULL; 
     566        priv->accounts = NULL; 
     567        priv->device = tny_platform_factory_new_device (platfact); 
     568 
    132569        return; 
    133570} 
     
    156593 
    157594} 
     595 
     596 
     597 
     598static void 
     599tmut_account_store_base_init (gpointer g_class) 
     600{ 
     601        static gboolean tmut_account_store_initialized = FALSE; 
     602 
     603        if (!tmut_account_store_initialized)  
     604        { 
     605                tmut_account_store_signals[TMUT_ACCOUNT_STORE_ACCOUNT_DELETED] = 
     606                   g_signal_new ("account_deleted", 
     607                        TMUT_TYPE_ACCOUNT_STORE, 
     608                        G_SIGNAL_RUN_FIRST, 
     609                        G_STRUCT_OFFSET (TMutAccountStoreClass, account_deleted), 
     610                        NULL, NULL, 
     611                        g_cclosure_marshal_VOID__OBJECT,  
     612                        G_TYPE_NONE, 1, TNY_TYPE_ACCOUNT); 
     613 
     614                tmut_account_store_signals[TMUT_ACCOUNT_STORE_ACCOUNT_EDITED] = 
     615                   g_signal_new ("account_edited", 
     616                        TMUT_TYPE_ACCOUNT_STORE, 
     617                        G_SIGNAL_RUN_FIRST, 
     618                        G_STRUCT_OFFSET (TMutAccountStoreClass, account_edited), 
     619                        NULL, NULL, 
     620                        g_cclosure_marshal_VOID__OBJECT,  
     621                        G_TYPE_NONE, 1, TNY_TYPE_ACCOUNT); 
     622 
     623                tmut_account_store_signals[TMUT_ACCOUNT_STORE_ACCOUNT_CREATED] = 
     624                   g_signal_new ("account_created", 
     625                        TMUT_TYPE_ACCOUNT_STORE, 
     626                        G_SIGNAL_RUN_FIRST, 
     627                        G_STRUCT_OFFSET (TMutAccountStoreClass, account_created), 
     628                        NULL, NULL, 
     629                        g_cclosure_marshal_VOID__OBJECT,  
     630                        G_TYPE_NONE, 1, TNY_TYPE_ACCOUNT); 
     631 
     632                tmut_account_store_initialized = TRUE; 
     633        } 
     634} 
     635 
    158636 
    159637GType 
     
    166644                { 
    167645                        sizeof (TMutAccountStoreClass), 
    168                         NULL,   /* base_init */ 
     646                        tmut_account_store_base_init,   /* base_init */ 
    169647                        NULL,   /* base_finalize */ 
    170648                        (GClassInitFunc) tmut_account_store_class_init,   /* class_init */ 
  • trunk/src/tmut-account-store.h

    r75 r76  
    4343{ 
    4444        GObjectClass parent; 
     45 
     46        /* Signals */ 
     47        void (*account_deleted) (TMutAccountStore *self, TnyAccount *account); 
     48        void (*account_created) (TMutAccountStore *self, TnyAccount *account); 
     49        void (*account_edited) (TMutAccountStore *self, TnyAccount *account); 
    4550}; 
    4651 
     
    5560                const gchar *type, 
    5661                const gchar *user, 
     62                const gchar *mech, 
     63                gint port, 
    5764                const gchar **options); 
    5865 
     
    6471                const gchar *hostname,  
    6572                const gchar *proto, 
    66                 const gchar *type, 
    6773                const gchar *user, 
     74                const gchar *mech, 
     75                gint port, 
    6876                const gchar **options); 
    6977 
  • trunk/src/tmut-folder-selector.c

    r75 r76  
    2727#include "tmut-shell-window.h" 
    2828#include "tmut-shell-child.h" 
     29#include "tmut-account-store.h" 
    2930 
    3031#include <tny-gtk-folder-store-tree-model.h> 
     
    3940        TMutShellWindow *shell; 
    4041        TnyFolderStore *current; 
     42        TnyAccountStore *account_store; 
     43        gint account_created_signal, account_deleted_signal; 
    4144}; 
    4245 
     
    6265} 
    6366 
     67static void 
     68disconnect_account_store (TMutFolderSelectorPriv *priv) 
     69{ 
     70        g_signal_handler_disconnect (priv->account_store, priv->account_created_signal); 
     71        g_signal_handler_disconnect (priv->account_store, priv->account_deleted_signal); 
     72        g_object_unref (priv->account_store); 
     73        priv->account_store = NULL; 
     74} 
     75 
     76static void 
     77on_account_created (TMutAccountStore *store, TnyAccount *account, TMutFolderSelector *self) 
     78{ 
     79        TMutFolderSelectorPriv *priv = TMUT_FOLDER_SELECTOR_GET_PRIVATE (self); 
     80        TnyList *model = TNY_LIST (gtk_tree_view_get_model (priv->folders_treeview)); 
     81        tny_list_prepend (model, (GObject *) account); 
     82} 
     83 
     84 
     85static void 
     86on_account_deleted (TMutAccountStore *store, TnyAccount *account, TMutFolderSelector *self) 
     87{ 
     88        TMutFolderSelectorPriv *priv = TMUT_FOLDER_SELECTOR_GET_PRIVATE (self); 
     89        TnyList *model = TNY_LIST (gtk_tree_view_get_model (priv->folders_treeview)); 
     90        tny_list_remove (model, (GObject *) account); 
     91} 
    6492 
    6593static void 
     
    75103        model = tny_gtk_folder_store_tree_model_new (query); 
    76104 
    77         tny_account_store_get_accounts (account_store, TNY_LIST (model), 
     105        if (priv->account_store) 
     106                disconnect_account_store (priv); 
     107        priv->account_store = TNY_ACCOUNT_STORE (g_object_ref (account_store)); 
     108 
     109        tny_account_store_get_accounts (priv->account_store, TNY_LIST (model), 
    78110                TNY_ACCOUNT_STORE_STORE_ACCOUNTS); 
     111 
     112        priv->account_created_signal = g_signal_connect (G_OBJECT (priv->account_store), "account_created", 
     113                G_CALLBACK (on_account_created), self); 
     114        priv->account_deleted_signal = g_signal_connect (G_OBJECT (priv->account_store), "account_deleted", 
     115                G_CALLBACK (on_account_deleted), self); 
    79116 
    80117        gtk_tree_view_set_model (priv->folders_treeview, model); 
     
    137174        GtkTreeSelection *select; 
    138175        GtkWidget *sw; 
     176 
     177        priv->account_store = NULL; 
     178        priv->account_created_signal = -1; 
     179        priv->account_deleted_signal = -1; 
    139180 
    140181        priv->current = NULL; 
     
    172213tmut_folder_selector_finalize (GObject *object) 
    173214{ 
     215        TMutFolderSelectorPriv *priv = TMUT_FOLDER_SELECTOR_GET_PRIVATE (object); 
     216 
     217        if (priv->account_store) 
     218                disconnect_account_store (priv); 
    174219 
    175220        (*parent_class->finalize) (object); 
  • trunk/src/tmut-menu-view.c

    r75 r76  
    2424#include <glib/gi18n-lib.h> 
    2525 
     26#include "tmut-account-store.h" 
    2627#include "tmut-menu-view.h" 
    2728#include "tmut-folder-view.h" 
     
    4546        TMutShellWindow *shell; 
    4647        TnyAccountStore *account_store; 
     48        TnyAccount *active_account; 
     49        gint account_created_signal, account_deleted_signal; 
    4750}; 
    4851 
     
    606609        gtk_tree_view_set_model (priv->folders_treeview, model); 
    607610 
     611        if (priv->active_account) 
     612                g_object_unref (priv->active_account); 
     613        priv->active_account = g_object_ref (account); 
     614 
    608615        g_object_unref (model); 
    609616 
     
    635642} 
    636643 
     644static void 
     645on_account_created (TMutAccountStore *store, TnyAccount *account, TMutMenuView *self) 
     646{ 
     647        TMutMenuViewPriv *priv = TMUT_MENU_VIEW_GET_PRIVATE (self); 
     648