Changeset 76
- Timestamp:
- 04/15/08 18:45:16
- Files:
-
- trunk/ChangeLog (modified) (1 diff)
- trunk/src/tmut-account-editor.c (modified) (7 diffs)
- trunk/src/tmut-account-editor.h (modified) (1 diff)
- trunk/src/tmut-account-manager.c (modified) (10 diffs)
- trunk/src/tmut-account-store.c (modified) (14 diffs)
- trunk/src/tmut-account-store.h (modified) (3 diffs)
- trunk/src/tmut-folder-selector.c (modified) (6 diffs)
- trunk/src/tmut-menu-view.c (modified) (7 diffs)
- trunk/src/tmut-msg-creator.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/ChangeLog
r75 r76 2 2 3 3 * Added the first signs of simple account management 4 * Implemented simple account management 5 * Implemented a new account store 4 6 5 7 2008-03-26 Philip Van Hoof <pvanhoof@gnome.org> trunk/src/tmut-account-editor.c
r75 r76 45 45 46 46 GtkWidget *name_entry, *hostname_entry, *enabled_checkbutton, 47 *proto_entry, *type_entry, *user_entry ;47 *proto_entry, *type_entry, *user_entry, *options_entry; 48 48 }; 49 49 … … 55 55 tmut_account_editor_get_enabled (TMutAccountEditor *self) 56 56 { 57 //TMutAccountEditorPriv *priv = TMUT_ACCOUNT_EDITOR_GET_PRIVATE (self);58 57 return TRUE; 59 //return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->enabled_checkbutton));60 58 } 61 59 … … 95 93 } 96 94 97 constgchar**95 gchar** 98 96 tmut_account_editor_get_options (TMutAccountEditor *self) 99 97 { 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); 101 101 } 102 102 … … 140 140 g_signal_emit (G_OBJECT (self), 141 141 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))); 142 143 return; 143 144 } … … 158 159 GtkWidget *ok_button, *cancel_button; 159 160 GtkWidget *hbox = gtk_hbox_new (FALSE, 0); 160 table = gtk_table_new ( 5, 2, FALSE);161 table = gtk_table_new (6, 2, FALSE); 161 162 162 163 gtk_widget_show (hbox); … … 207 208 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); 208 209 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 209 217 priv->name_entry = gtk_entry_new (); 210 218 gtk_widget_show (priv->name_entry); … … 234 242 gtk_widget_show (priv->type_entry); 235 243 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, 236 250 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 237 251 (GtkAttachOptions) (0), 0, 0); trunk/src/tmut-account-editor.h
r75 r76 63 63 const gchar* tmut_account_editor_get_account_type (TMutAccountEditor *self); 64 64 const gchar* tmut_account_editor_get_user (TMutAccountEditor *self); 65 constgchar** tmut_account_editor_get_options (TMutAccountEditor *self);65 gchar** tmut_account_editor_get_options (TMutAccountEditor *self); 66 66 TnyAccount *tmut_account_editor_get_account (TMutAccountEditor *self); 67 67 trunk/src/tmut-account-manager.c
r75 r76 41 41 GtkComboBox *accounts_combo; 42 42 TMutShellWindow *shell; 43 TnyAccount *account; 43 44 TnyAccountStore *account_store; 44 TnyAccount *account;45 gint account_created_signal, account_deleted_signal; 45 46 }; 46 47 … … 69 70 OnEditOrNewInfo *info = (OnEditOrNewInfo *) user_data; 70 71 TMutAccountManagerPriv *priv = TMUT_ACCOUNT_MANAGER_GET_PRIVATE (info->self); 72 gchar **options = tmut_account_editor_get_options (editor); 71 73 72 74 tmut_account_store_create_account (TMUT_ACCOUNT_STORE (priv->account_store), … … 77 79 tmut_account_editor_get_account_type (editor), 78 80 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); 80 85 } 81 86 … … 87 92 TMutAccountManagerPriv *priv = TMUT_ACCOUNT_MANAGER_GET_PRIVATE (info->self); 88 93 TnyAccount *account = tmut_account_editor_get_account (editor); 94 gchar **options = tmut_account_editor_get_options (editor); 89 95 90 96 tmut_account_store_edit_account (TMUT_ACCOUNT_STORE (priv->account_store), … … 94 100 tmut_account_editor_get_hostname (editor), 95 101 tmut_account_editor_get_proto (editor), 96 tmut_account_editor_get_account_type (editor),97 102 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); 99 107 100 108 g_object_unref (account); … … 156 164 g_object_unref (priv->account); 157 165 priv->account = NULL; 158 159 g_print ("Delete");160 166 161 167 return; … … 248 254 249 255 static void 256 on_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 264 static void 265 on_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 274 static void 275 disconnect_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 283 static void 250 284 tmut_account_manager_set_account_store (TnyAccountStoreView *self, TnyAccountStore *account_store) 251 285 { … … 259 293 260 294 if (priv->account_store) 261 g_object_unref (priv->account_store);295 disconnect_account_store (priv); 262 296 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); 263 302 264 303 TMUT_ACCOUNT_MANAGER_GET_CLASS (self)->create_menu (TMUT_ACCOUNT_MANAGER (self)); … … 275 314 GtkVBox *vbox = GTK_VBOX (self); 276 315 GtkCellRenderer *renderer; 277 GtkLabel *label = GTK_LABEL (gtk_label_new (" "));316 GtkLabel *label = GTK_LABEL (gtk_label_new ("Account manager")); 278 317 279 318 priv->account_store = NULL; 319 priv->account_created_signal = -1; 320 priv->account_deleted_signal = -1; 321 280 322 priv->account = NULL; 281 323 … … 308 350 309 351 if (priv->account_store) 310 g_object_unref (priv->account_store);352 disconnect_account_store (priv); 311 353 312 354 (*parent_class->finalize) (object); trunk/src/tmut-account-store.c
r75 r76 22 22 #endif 23 23 24 #include <string.h> 25 #include <glib.h> 26 #include <gtk/gtk.h> 24 27 #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> 27 48 28 49 static GObjectClass *parent_class = NULL; 29 50 51 typedef 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 58 static guint tmut_account_store_signals [TMUT_ACCOUNT_STORE_LAST_SIGNAL]; 59 30 60 typedef struct _TMutAccountStorePriv TMutAccountStorePriv; 31 61 32 62 struct _TMutAccountStorePriv 33 63 { 34 TnyAccountStore *decorated; 64 gchar *cache_dir; 65 TnySessionCamel *session; 66 TnyDevice *device; 67 guint notify; 68 GList *accounts; 35 69 }; 36 70 … … 39 73 40 74 41 void tmut_account_store_create_account (TMutAccountStore *self, 75 static gchar* 76 per_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 91 static void 92 per_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 104 static TnyAccount* 105 create_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 160 void 161 tmut_account_store_create_account (TMutAccountStore *self, 42 162 gboolean enabled, 43 163 const gchar *name, … … 46 166 const gchar *type, 47 167 const gchar *user, 168 const gchar *mech, 169 gint port, 48 170 const gchar **options) 49 171 { 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 235 void 236 tmut_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 56 259 } 57 260 … … 61 264 const gchar *hostname, 62 265 const gchar *proto, 63 const gchar *type,64 266 const gchar *user, 267 const gchar *mech, 268 gint port, 65 269 const gchar **options) 66 270 { 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 342 static void 343 kill_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 353 static void 354 load_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 69 430 70 431 static void … … 72 433 { 73 434 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; 75 457 } 76 458 … … 79 461 { 80 462 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; 82 466 } 83 467 … … 86 470 { 87 471 TMutAccountStorePriv *priv = TMUT_ACCOUNT_STORE_GET_PRIVATE (self); 88 return tny_account_store_get_device (priv->decorated);472 return g_object_ref (priv->device); 89 473 } 90 474 … … 93 477 { 94 478 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; 96 505 } 97 506 … … 100 509 { 101 510 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; 103 530 } 104 531 … … 109 536 TMutAccountStorePriv *priv = TMUT_ACCOUNT_STORE_GET_PRIVATE (object); 110 537 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); 113 544 114 545 parent_class->finalize (object); … … 121 552 TMutAccountStore *self = g_object_new (TMUT_TYPE_ACCOUNT_STORE, NULL); 122 553 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 ()); 124 556 return TNY_ACCOUNT_STORE (self); 125 557 } … … 129 561 { 130 562 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 132 569 return; 133 570 } … … 156 593 157 594 } 595 596 597 598 static void 599 tmut_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 158 636 159 637 GType … … 166 644 { 167 645 sizeof (TMutAccountStoreClass), 168 NULL, /* base_init */646 tmut_account_store_base_init, /* base_init */ 169 647 NULL, /* base_finalize */ 170 648 (GClassInitFunc) tmut_account_store_class_init, /* class_init */ trunk/src/tmut-account-store.h
r75 r76 43 43 { 44 44 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); 45 50 }; 46 51 … … 55 60 const gchar *type, 56 61 const gchar *user, 62 const gchar *mech, 63 gint port, 57 64 const gchar **options); 58 65 … … 64 71 const gchar *hostname, 65 72 const gchar *proto, 66 const gchar *type,67 73 const gchar *user, 74 const gchar *mech, 75 gint port, 68 76 const gchar **options); 69 77 trunk/src/tmut-folder-selector.c
r75 r76 27 27 #include "tmut-shell-window.h" 28 28 #include "tmut-shell-child.h" 29 #include "tmut-account-store.h" 29 30 30 31 #include <tny-gtk-folder-store-tree-model.h> … … 39 40 TMutShellWindow *shell; 40 41 TnyFolderStore *current; 42 TnyAccountStore *account_store; 43 gint account_created_signal, account_deleted_signal; 41 44 }; 42 45 … … 62 65 } 63 66 67 static void 68 disconnect_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 76 static void 77 on_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 85 static void 86 on_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 } 64 92 65 93 static void … … 75 103 model = tny_gtk_folder_store_tree_model_new (query); 76 104 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), 78 110 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); 79 116 80 117 gtk_tree_view_set_model (priv->folders_treeview, model); … … 137 174 GtkTreeSelection *select; 138 175 GtkWidget *sw; 176 177 priv->account_store = NULL; 178 priv->account_created_signal = -1; 179 priv->account_deleted_signal = -1; 139 180 140 181 priv->current = NULL; … … 172 213 tmut_folder_selector_finalize (GObject *object) 173 214 { 215 TMutFolderSelectorPriv *priv = TMUT_FOLDER_SELECTOR_GET_PRIVATE (object); 216 217 if (priv->account_store) 218 disconnect_account_store (priv); 174 219 175 220 (*parent_class->finalize) (object); trunk/src/tmut-menu-view.c
r75 r76 24 24 #include <glib/gi18n-lib.h> 25 25 26 #include "tmut-account-store.h" 26 27 #include "tmut-menu-view.h" 27 28 #include "tmut-folder-view.h" … … 45 46 TMutShellWindow *shell; 46 47 TnyAccountStore *account_store; 48 TnyAccount *active_account; 49 gint account_created_signal, account_deleted_signal; 47 50 }; 48 51 … … 606 609 gtk_tree_view_set_model (priv->folders_treeview, model); 607 610 611 if (priv->active_account) 612 g_object_unref (priv->active_account); 613 priv->active_account = g_object_ref (account); 614 608 615 g_object_unref (model); 609 616 … … 635 642 } 636 643 644 static void 645 on_account_created (TMutAccountStore *store, TnyAccount *account, TMutMenuView *self) 646 { 647 TMutMenuViewPriv *priv = TMUT_MENU_VIEW_GET_PRIVATE (self); 648
