Changeset 1783

Show
Ignore:
Timestamp:
04/13/07 01:14:48
Author:
pvanhoof
Message:

Introduction of the TnyPasswordGetter interface

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ChangeLog

    r1782 r1783  
    22 
    33        * Added skeleton for ACAP support 
     4        * Major modifications to the 'getting of passwords' 
     5        * Introduction of the TnyPasswordGetter interface 
    46 
    57        * This was a major API change 
  • trunk/Makefile.am

    r1782 r1783  
    55 
    66if BUILD_GNOME 
     7SUBDIRS += libtinymailui-gnome-keyring 
    78SUBDIRS += libtinymail-gnomevfs  
    89endif 
  • trunk/bindings/python/Makefile.am

    r1683 r1783  
    115115        $(top_srcdir)/libtinymail/tny-folder-store-observer.h \ 
    116116        $(top_srcdir)/libtinymail/tny-folder-store-change.h \ 
    117         $(top_srcdir)/libtinymail/tny-folder-stats.h 
     117        $(top_srcdir)/libtinymail/tny-folder-stats.h \ 
     118        $(top_srcdir)/libtinymail/tny-password-getter.h 
    118119 
    119120tinymail.defs: $(tinymail_h_files) tinymail.defs.extra $(top_srcdir)/bindings/python/filter.py  
  • trunk/bindings/python/tinymail.override

    r1683 r1783  
    3535#include <tny-folder-store-change.h> 
    3636#include <tny-folder-stats.h> 
     37#include <tny-password-getter.h> 
     38 
    3739 
    3840#define NO_IMPORT_PYGOBJECT 
  • trunk/configure.ac

    r1782 r1783  
    402402libtinymailui-mozembed/Makefile 
    403403libtinymailui-mozembed/libtinymailui-mozembed.pc 
     404libtinymailui-gnome-keyring/Makefile 
    404405libtinymail-gnomevfs/Makefile 
    405406libtinymail-gnomevfs/libtinymail-gnomevfs.pc 
  • trunk/libtinymail-acap

    • Property svn:ignore set to Makefile.in libtinymail-acap-1.0.pc config.h .deps Makefile .libs .svnignore stamp-h3 libtinymail-acap.pc
  • trunk/libtinymail-acap/tny-acap-account-store.c

    r1782 r1783  
    114114        add_account_remote (self, TNY_ACCOUNT (account), "transport"); 
    115115 
    116         tny_account_store_add_store_account (priv->real, account); 
     116        tny_account_store_add_transport_account (priv->real, account); 
    117117 
    118118        return; 
  • trunk/libtinymail-gnome-desktop/Makefile.am

    r1014 r1783  
    1414 
    1515if BUILD_GNOME 
    16 INCLUDES += -DGNOME 
     16INCLUDES += -I$(top_srcdir)/libtinymailui-gnome-keyring -DGNOME 
    1717endif 
    1818 
     
    2121libtinymail_gnome_desktop_1_0_headers = \ 
    2222        tny-gnome-account-store.h \ 
    23         tny-gnome-password-dialog.h \ 
    2423        tny-gnome-device.h \ 
    2524        tny-gnome-platform-factory.h 
     
    3029        tny-gnome-device-priv.h \ 
    3130        tny-gnome-device.c \ 
    32         tny-gnome-password-dialog.c \ 
    3331        tny-gnome-platform-factory.c 
    3432 
     
    4240libtinymail_gnome_desktop_1_0_la_LDFLAGS = -export-dynamic \ 
    4341        -version-info $(LT_VERSION_INFO) $(LIBTOOL_EXPORT_OPTIONS) 
     42 
     43if BUILD_GNOME 
     44libtinymail_gnome_desktop_1_0_la_LIBADD += $(top_builddir)/libtinymailui-gnome-keyring/libtinymailui-gnome-keyring.a 
     45endif 
    4446 
    4547if BUILD_MOZEMBED 
  • trunk/libtinymail-gnome-desktop/tny-gnome-account-store.c

    r1713 r1783  
    2929 
    3030#include <tny-platform-factory.h> 
     31#include <tny-password-getter.h> 
    3132#include <tny-gnome-platform-factory.h> 
    3233#include <tny-account-store.h> 
    3334#include <tny-gnome-account-store.h> 
    34 #include <tny-gnome-password-dialog.h> 
    3535#include <tny-account.h> 
    3636#include <tny-store-account.h> 
     
    4949#include <tny-gtk-lockable.h> 
    5050 
    51 #ifdef GNOME 
    52 #include <libgnomeui/gnome-password-dialog.h> 
    53 #include <gnome-keyring.h> 
    54 #endif 
    5551 
    5652/* "GConf vs. libtinymail-camel" account-store implementation */ 
     
    7470 
    7571 
    76 #ifdef GNOME 
    7772static gchar*  
    7873per_account_get_pass_func (TnyAccount *account, const gchar *prompt, gboolean *cancel) 
    7974{ 
    80         gchar *retval = NULL; 
    81         GList *list; 
    82         GnomeKeyringResult keyringret; 
    83         gchar *keyring; 
    84  
    85         gnome_keyring_get_default_keyring_sync (&keyring); 
    86  
    87         keyringret = gnome_keyring_find_network_password_sync ( 
    88                 tny_account_get_user (account), 
    89                 "Mail", tny_account_get_hostname (account), 
    90                 "password", tny_account_get_proto (account),  
    91                 "PLAIN", 0, &list); 
    92  
    93         if (keyringret != GNOME_KEYRING_RESULT_OK) 
    94         { 
    95                 gboolean canc = FALSE; 
    96  
    97                 GnomePasswordDialog *dialog = GNOME_PASSWORD_DIALOG  
    98                                 (gnome_password_dialog_new 
    99                                         (_("Enter password"), prompt, 
    100                                         tny_account_get_user (account),  
    101                                         NULL, TRUE)); 
    102  
    103                 gnome_password_dialog_set_domain (dialog, "Mail"); 
    104                 gnome_password_dialog_set_remember (dialog,  
    105                         GNOME_PASSWORD_DIALOG_REMEMBER_FOREVER); 
    106                 gnome_password_dialog_set_readonly_username (dialog, TRUE); 
    107                 gnome_password_dialog_set_username (dialog,  
    108                         tny_account_get_user (account)); 
    109  
    110                 gnome_password_dialog_set_show_username (dialog, FALSE); 
    111                 gnome_password_dialog_set_show_remember (dialog,  
    112                         gnome_keyring_is_available ()); 
    113                 gnome_password_dialog_set_show_domain (dialog, FALSE); 
    114                 gnome_password_dialog_set_show_userpass_buttons (dialog, FALSE); 
    115  
    116                 canc = gnome_password_dialog_run_and_block (dialog); 
    117  
    118                 if (canc) 
    119                 { 
    120                         guint32 item_id; 
    121                         GnomePasswordDialogRemember r; 
    122  
    123                         retval = gnome_password_dialog_get_password (dialog); 
    124  
    125                         r = gnome_password_dialog_get_remember (dialog); 
    126  
    127                         if (r == GNOME_PASSWORD_DIALOG_REMEMBER_FOREVER) 
    128                         { 
    129                                 gnome_keyring_set_network_password_sync (keyring, 
    130                                         tny_account_get_user (account), 
    131                                         "Mail", tny_account_get_hostname (account), 
    132                                         "password", tny_account_get_proto (account),  
    133                                         "PLAIN", 0, retval, &item_id); 
    134                         } 
    135                 } else retval = NULL; 
    136  
    137                 *cancel = (!canc); 
    138  
    139                 /* this causes warnings, but should be done afaik */ 
    140                 gtk_object_destroy (GTK_OBJECT (dialog)); 
    141  
    142                 while (gtk_events_pending ()) 
    143                         gtk_main_iteration (); 
    144  
    145         } else { 
    146  
    147                 GnomeKeyringNetworkPasswordData *pwd_data; 
    148                 pwd_data = list->data; 
    149                 retval = g_strdup (pwd_data->password); 
    150  
    151                 *cancel = FALSE; 
    152  
    153                 gnome_keyring_network_password_list_free (list); 
    154         } 
     75        TnyPlatformFactory *platfact = tny_gnome_platform_factory_get_instance (); 
     76        TnyPasswordGetter *pwdgetter; 
     77        gchar *retval; 
     78 
     79        pwdgetter = tny_platform_factory_new_password_getter (platfact); 
     80        retval = (gchar*) tny_password_getter_get_password (pwdgetter, account, prompt, cancel); 
     81        g_object_unref (G_OBJECT (pwdgetter)); 
    15582 
    15683        return retval; 
    15784} 
    15885 
     86 
    15987static void 
    16088per_account_forget_pass_func (TnyAccount *account) 
    16189{ 
    162         GList *list=NULL; 
    163         GnomeKeyringResult keyringret; 
    164         gchar *keyring; 
    165         GnomeKeyringNetworkPasswordData *pwd_data; 
    166  
    167         gnome_keyring_get_default_keyring_sync (&keyring); 
    168  
    169         keyringret = gnome_keyring_find_network_password_sync ( 
    170                 tny_account_get_user (account), 
    171                 "Mail", tny_account_get_hostname (account), 
    172                 "password", tny_account_get_proto (account),  
    173                 "PLAIN", 0, &list); 
    174  
    175         if (keyringret == GNOME_KEYRING_RESULT_OK) 
    176         { 
    177                 pwd_data = list->data; 
    178                 gnome_keyring_item_delete_sync (keyring, pwd_data->item_id); 
    179                 gnome_keyring_network_password_list_free (list); 
    180         } 
    181         return; 
    182 
    183  
    184 #else  
    185  
    186 static GHashTable *passwords; 
    187  
    188 static gchar*  
    189 per_account_get_pass_func (TnyAccount *account, const gchar *prompt, gboolean *cancel) 
    190 
    191         gchar *retval = NULL; 
    192         const gchar *accountid; 
    193  
    194         accountid = tny_account_get_id (account); 
    195  
    196         if (G_UNLIKELY (!passwords)) 
    197                 passwords = g_hash_table_new (g_str_hash, g_str_equal); 
    198  
    199         retval = g_hash_table_lookup (passwords, accountid); 
    200  
    201         if (G_UNLIKELY (!retval)) 
    202         { 
    203                 GtkDialog *dialog = GTK_DIALOG (tny_gnome_password_dialog_new ()); 
    204          
    205                 tny_gnome_password_dialog_set_prompt (TNY_GNOME_PASSWORD_DIALOG (dialog), prompt); 
    206  
    207                 if (G_LIKELY (gtk_dialog_run (dialog) == GTK_RESPONSE_OK)) 
    208                 { 
    209                         const gchar *pwd = tny_gnome_password_dialog_get_password  
    210                                 (TNY_GNOME_PASSWORD_DIALOG (dialog)); 
    211          
    212                         retval = g_strdup (pwd); 
    213  
    214                         mlock (retval, strlen (retval)); 
    215  
    216                         g_hash_table_insert (passwords, g_strdup (accountid),  
    217                                 retval); 
    218  
    219                         *cancel = FALSE; 
    220  
    221                 } else { 
    222  
    223                         *cancel = TRUE; 
    224  
    225                 } 
    226  
    227                 gtk_widget_destroy (GTK_WIDGET (dialog)); 
    228  
    229                 while (gtk_events_pending ()) 
    230                         gtk_main_iteration (); 
    231         } else { 
    232                 *cancel = FALSE; 
    233         } 
    234  
    235         return retval; 
    236 
    237  
    238  
    239 static void 
    240 per_account_forget_pass_func (TnyAccount *account) 
    241 
    242         if (G_LIKELY (passwords)) 
    243         { 
    244                 const gchar *accountid = tny_account_get_id (account); 
    245  
    246                 gchar *pwd = g_hash_table_lookup (passwords, accountid); 
    247  
    248                 if (G_LIKELY (pwd)) 
    249                 { 
    250                         memset (pwd, 0, strlen (pwd)); 
    251                         /* g_free (pwd); uhm, crashed once */ 
    252                         g_hash_table_remove (passwords, accountid); 
    253                 } 
    254  
    255         } 
    256  
    257         return; 
    258 
    259  
    260 #endif 
     90        TnyPlatformFactory *platfact = tny_gnome_platform_factory_get_instance (); 
     91        TnyPasswordGetter *pwdgetter; 
     92 
     93        pwdgetter = tny_platform_factory_new_password_getter (platfact); 
     94        tny_password_getter_forget_password (pwdgetter, account); 
     95        g_object_unref (G_OBJECT (pwdgetter)); 
     96 
     97        return; 
     98
    26199 
    262100static gboolean 
     
    697535        TnyGnomeAccountStore *self = g_object_new (TNY_TYPE_GNOME_ACCOUNT_STORE, NULL); 
    698536        TnyGnomeAccountStorePriv *priv = TNY_GNOME_ACCOUNT_STORE_GET_PRIVATE (self); 
     537 
    699538        priv->session = tny_session_camel_new (TNY_ACCOUNT_STORE (self)); 
    700  
    701539        tny_session_camel_set_ui_locker (priv->session, tny_gtk_lockable_new ()); 
    702540 
  • trunk/libtinymail-gnome-desktop/tny-gnome-platform-factory.c

    r1736 r1783  
    3232#endif 
    3333 
     34#ifdef GNOME 
     35#include <tny-gnome-keyring-password-getter.h> 
     36#else 
     37#include <tny-gtk-password-dialog.h> 
     38#endif 
     39 
    3440static GObjectClass *parent_class = NULL; 
    3541 
     
    6571{ 
    6672        return tny_gnome_device_new (); 
     73} 
     74 
     75 
     76static TnyPasswordGetter* 
     77tny_gnome_platform_factory_new_password_getter (TnyPlatformFactory *self) 
     78{ 
     79#ifdef GNOME 
     80        return tny_gnome_keyring_password_getter_new (); 
     81#else 
     82        return tny_gtk_password_dialog_new (); 
     83#endif 
    6784} 
    6885 
     
    115132        klass->new_msg_func = tny_gnome_platform_factory_new_msg; 
    116133        klass->new_mime_part_func = tny_gnome_platform_factory_new_mime_part; 
     134        klass->new_password_getter_func = tny_gnome_platform_factory_new_password_getter; 
    117135 
    118136        return; 
  • trunk/libtinymail-gpe/Makefile.am

    r1014 r1783  
    1414libtinymail_gpe_1_0_headers = \ 
    1515        tny-gpe-account-store.h \ 
    16         tny-gpe-password-dialog.h \ 
    1716        tny-gpe-device.h \ 
    1817        tny-gpe-platform-factory.h 
     
    2322        tny-gpe-device-priv.h \ 
    2423        tny-gpe-device.c \ 
    25         tny-gpe-password-dialog.c \ 
    2624        tny-gpe-platform-factory.c 
    2725 
  • trunk/libtinymail-gpe/tny-gpe-account-store.c

    r1713 r1783  
    2929 
    3030#include <tny-platform-factory.h> 
     31#include <tny-password-getter.h> 
    3132#include <tny-gpe-platform-factory.h> 
    3233#include <tny-account-store.h> 
     
    6768 
    6869 
    69 static GHashTable *passwords; 
    70  
    7170static gchar*  
    7271per_account_get_pass_func (TnyAccount *account, const gchar *prompt, gboolean *cancel) 
    7372{ 
    74         gchar *retval = NULL; 
    75         const gchar *accountid = tny_account_get_id (account); 
    76  
    77         if (G_UNLIKELY (!passwords)) 
    78                 passwords = g_hash_table_new (g_str_hash, g_str_equal); 
    79  
    80         retval = g_hash_table_lookup (passwords, accountid); 
    81  
    82         if (G_UNLIKELY (!retval)) 
    83         { 
    84                 GtkDialog *dialog = tny_gpe_password_dialog_new (); 
    85          
    86                 tny_gpe_password_dialog_set_prompt (TNY_GPE_PASSWORD_DIALOG (dialog), prompt); 
    87  
    88                 if (G_LIKELY (gtk_dialog_run (dialog) == GTK_RESPONSE_OK)) 
    89                 { 
    90                         const gchar *pwd = tny_gpe_password_dialog_get_password  
    91                                 (TNY_GPE_PASSWORD_DIALOG (dialog)); 
    92          
    93                         retval = g_strdup (pwd); 
    94  
    95                         mlock (retval, strlen (retval)); 
    96  
    97                         g_hash_table_insert (passwords, g_strdup (accountid),  
    98                                 retval); 
    99  
    100                         *cancel = FALSE; 
    101  
    102                 } else { 
    103  
    104                         *cancel = TRUE; 
    105  
    106                 } 
    107  
    108                 gtk_widget_destroy (GTK_WIDGET (dialog)); 
    109  
    110                 while (gtk_events_pending ()) 
    111                         gtk_main_iteration (); 
    112         } else { 
    113                 *cancel = FALSE; 
    114         } 
     73        TnyPlatformFactory *platfact = tny_gpe_platform_factory_get_instance (); 
     74        TnyPasswordGetter *pwdgetter; 
     75        gchar *retval; 
     76 
     77        pwdgetter = tny_platform_factory_new_password_getter (platfact); 
     78        retval = (gchar*) tny_password_getter_get_password (pwdgetter, account, prompt, cancel); 
     79        g_object_unref (G_OBJECT (pwdgetter)); 
    11580 
    11681        return retval; 
    11782} 
    11883 
     84 
    11985static void 
    12086per_account_forget_pass_func (TnyAccount *account) 
    12187{ 
    122         TnyGetPassFunc func; 
    123         if (G_LIKELY (passwords)) 
    124         { 
    125                 const gchar *accountid = tny_account_get_id (account); 
    126  
    127                 gchar *pwd = g_hash_table_lookup (passwords, accountid); 
    128  
    129                 if (G_LIKELY (pwd)) 
    130                 { 
    131                         memset (pwd, 0, strlen (pwd)); 
    132                         /* g_free (pwd); uhm, crashed once */ 
    133                         g_hash_table_remove (passwords, accountid); 
    134                 } 
    135  
    136         } 
     88        TnyPlatformFactory *platfact = tny_gpe_platform_factory_get_instance (); 
     89        TnyPasswordGetter *pwdgetter; 
     90 
     91        pwdgetter = tny_platform_factory_new_password_getter (platfact); 
     92        tny_password_getter_forget_password (pwdgetter, account); 
     93        g_object_unref (G_OBJECT (pwdgetter)); 
    13794 
    13895        return; 
  • trunk/libtinymail-gpe/tny-gpe-platform-factory.c

    r1700 r1783  
    2323#include <tny-gpe-device.h> 
    2424#include <tny-gtk-msg-view.h> 
     25#include <tny-gtk-password-dialog.h> 
    2526#include <tny-camel-mime-part.h> 
    2627#include <tny-camel-msg.h> 
     
    6869} 
    6970 
     71static TnyPasswordGetter* 
     72tny_gpe_platform_factory_new_password_getter (TnyPlatformFactory *self) 
     73{ 
     74        return tny_gtk_password_dialog_new (); 
     75} 
     76 
    7077/** 
    7178 * tny_gpe_platform_factory_get_instance: 
     
    102109        klass->new_msg_func = tny_gpe_platform_factory_new_msg; 
    103110        klass->new_mime_part_func = tny_gpe_platform_factory_new_mime_part; 
     111        klass->new_password_getter_func = tny_gpe_platform_factory_new_password_getter; 
    104112 
    105113        return; 
  • trunk/libtinymail-maemo/Makefile.am

    r1508 r1783  
    1515libtinymail_maemo_1_0_headers = \ 
    1616        tny-maemo-account-store.h \ 
    17         tny-maemo-password-dialog.h \ 
    1817        tny-maemo-device.h \ 
    1918        tny-maemo-platform-factory.h 
     
    2322        tny-maemo-account-store.c \ 
    2423        tny-maemo-device.c \ 
    25         tny-maemo-password-dialog.c \ 
    2624        tny-maemo-platform-factory.c 
    2725 
  • trunk/libtinymail-maemo/tny-maemo-account-store.c

    r1713 r1783  
    3030 
    3131#include <tny-platform-factory.h> 
     32#include <tny-password-getter.h> 
    3233#include <tny-maemo-platform-factory.h> 
     34 
    3335#include <tny-account-store.h> 
    3436#include <tny-maemo-account-store.h> 
     
    6769 
    6870 
    69 static GHashTable *passwords; 
    70  
    7171static gchar*  
    7272per_account_get_pass_func (TnyAccount *account, const gchar *prompt, gboolean *cancel) 
    7373{ 
    74         gchar *retval = NULL; 
    75         const gchar *accountid = tny_account_get_id (account); 
    76  
    77         if (G_UNLIKELY (!passwords)) 
    78                 passwords = g_hash_table_new (g_str_hash, g_str_equal); 
    79  
    80         retval = g_hash_table_lookup (passwords, accountid); 
    81  
    82         if (G_UNLIKELY (!retval)) 
    83         { 
    84                 GtkDialog *dialog = GTK_DIALOG (tny_maemo_password_dialog_new ()); 
    85          
    86                 tny_maemo_password_dialog_set_prompt (TNY_MAEMO_PASSWORD_DIALOG (dialog), prompt); 
    87  
    88                 if (G_LIKELY (gtk_dialog_run (dialog) == GTK_RESPONSE_OK)) 
    89                 { 
    90                         const gchar *pwd = tny_maemo_password_dialog_get_password  
    91                                 (TNY_MAEMO_PASSWORD_DIALOG (dialog)); 
    92          
    93                         retval = g_strdup (pwd); 
    94  
    95                         mlock (retval, strlen (retval)); 
    96  
    97                         g_hash_table_insert (passwords, g_strdup (accountid),  
    98                                 retval); 
    99  
    100                         *cancel = FALSE; 
    101  
    102                 } else { 
    103  
    104                         *cancel = TRUE; 
    105  
    106                 } 
    107  
    108                 gtk_widget_destroy (GTK_WIDGET (dialog)); 
    109  
    110                 while (gtk_events_pending ()) 
    111                         gtk_main_iteration (); 
    112         } else { 
    113                 *cancel = FALSE; 
    114         } 
     74        TnyPlatformFactory *platfact = tny_maemo_platform_factory_get_instance (); 
     75        TnyPasswordGetter *pwdgetter; 
     76        gchar *retval; 
     77 
     78        pwdgetter = tny_platform_factory_new_password_getter (platfact); 
     79        retval = (gchar*) tny_password_getter_get_password (pwdgetter, account, prompt, cancel); 
     80        g_object_unref (G_OBJECT (pwdgetter)); 
    11581 
    11682        return retval; 
    11783} 
    11884 
     85 
    11986static void 
    12087per_account_forget_pass_func (TnyAccount *account) 
    12188{ 
    122         TnyGetPassFunc func; 
    123  
    124         if (G_LIKELY (passwords)) 
    125         { 
    126                 const gchar *accountid = tny_account_get_id (account); 
    127  
    128                 gchar *pwd = g_hash_table_lookup (passwords, accountid); 
    129  
    130                 if (G_LIKELY (pwd)) 
    131                 { 
    132                         memset (pwd, 0, strlen (pwd)); 
    133                         /* g_free (pwd); uhm, crashed once ?! */ 
    134                         g_hash_table_remove (passwords, accountid); 
    135                 } 
    136  
    137         } 
     89        TnyPlatformFactory *platfact = tny_maemo_platform_factory_get_instance (); 
     90        TnyPasswordGetter *pwdgetter; 
     91 
     92        pwdgetter = tny_platform_factory_new_password_getter (platfact); 
     93        tny_password_getter_forget_password (pwdgetter, account); 
     94        g_object_unref (G_OBJECT (pwdgetter)); 
    13895 
    13996        return; 
  • trunk/libtinymail-maemo/tny-maemo-platform-factory.c

    r1700 r1783  
    2424#include <tny-maemo-device.h> 
    2525#include <tny-gtk-msg-view.h> 
     26#include <tny-gtk-password-dialog.h> 
    2627#include <tny-camel-mime-part.h> 
    2728#include <tny-camel-msg.h> 
     
    4950} 
    5051 
     52static TnyPasswordGetter* 
     53tny_maemo_platform_factory_new_password_getter (TnyPlatformFactory *self) 
     54{ 
     55        return tny_gtk_password_dialog_new (); 
     56} 
    5157 
    5258static TnyAccountStore* 
     
    104110        klass->new_msg_func = tny_maemo_platform_factory_new_msg; 
    105111        klass->new_mime_part_func = tny_maemo_platform_factory_new_mime_part; 
     112        klass->new_password_getter_func = tny_maemo_platform_factory_new_password_getter; 
    106113 
    107114        return; 
  • trunk/libtinymail-olpc/Makefile.am

    r1014 r1783  
    1414libtinymail_olpc_1_0_headers = \ 
    1515        tny-olpc-account-store.h \ 
    16         tny-olpc-password-dialog.h \ 
    1716        tny-olpc-device.h \ 
    1817        tny-olpc-platform-factory.h 
     
    2322        tny-olpc-device-priv.h \ 
    2423        tny-olpc-device.c \ 
    25         tny-olpc-password-dialog.c \ 
    2624        tny-olpc-platform-factory.c 
    2725 
  • trunk/libtinymail-olpc/tny-olpc-account-store.c

    r1754 r1783  
    2828 
    2929#include <tny-platform-factory.h> 
     30#include <tny-password-getter.h> 
    3031#include <tny-olpc-platform-factory.h> 
    3132 
    3233#include <tny-account-store.h> 
    3334#include <tny-olpc-account-store.h> 
    34 #include <tny-olpc-password-dialog.h> 
    3535#include <tny-account.h> 
    3636#include <tny-store-account.h> 
     
    6565 
    6666 
    67 static GHashTable *passwords; 
    6867 
    6968static gchar*  
    7069per_account_get_pass_func (TnyAccount *account, const gchar *prompt, gboolean *cancel) 
    7170{ 
    72         gchar *retval = NULL; 
    73         const gchar *accountid = tny_account_get_id (account); 
    74  
    75         if (G_UNLIKELY (!passwords)) 
    76                 passwords = g_hash_table_new (g_str_hash, g_str_equal); 
    77  
    78         retval = g_hash_table_lookup (passwords, accountid); 
    79  
    80         if (G_UNLIKELY (!retval)) 
    81         { 
    82                 GtkDialog *dialog = GTK_DIALOG (tny_olpc_password_dialog_new ()); 
    83          
    84                 tny_olpc_password_dialog_set_prompt (TNY_OLPC_PASSWORD_DIALOG (dialog), prompt); 
    85  
    86                 if (G_LIKELY (gtk_dialog_run (dialog) == GTK_RESPONSE_OK)) 
    87                 { 
    88                         const gchar *pwd = tny_olpc_password_dialog_get_password  
    89                                 (TNY_OLPC_PASSWORD_DIALOG (dialog)); 
    90          
    91                         retval = g_strdup (pwd); 
    92  
    93                         mlock (retval, strlen (retval)); 
    94  
    95                         g_hash_table_insert (passwords, g_strdup (accountid),  
    96                                 retval); 
    97  
    98                         *cancel = FALSE; 
    99  
    100                 } else { 
    101  
    102                         *cancel = TRUE; 
    103  
    104                 } 
    105  
    106                 gtk_widget_destroy (GTK_WIDGET (dialog)); 
    107  
    108                 while (gtk_events_pending ()) 
    109                         gtk_main_iteration (); 
    110         } else { 
    111                 *cancel = FALSE; 
    112         } 
     71        TnyPlatformFactory *platfact = tny_olpc_platform_factory_get_instance (); 
     72        TnyPasswordGetter *pwdgetter; 
     73        gchar *retval; 
     74 
     75        pwdgetter = tny_platform_factory_new_password_getter (platfact); 
     76        retval = (gchar*) tny_password_getter_get_password (pwdgetter, account, prompt, cancel); 
     77        g_object_unref (G_OBJECT (pwdgetter)); 
    11378 
    11479        return retval; 
    11580} 
    11681 
     82 
    11783static void 
    11884per_account_forget_pass_func (TnyAccount *account) 
    11985{ 
    120         TnyGetPassFunc func; 
    121         if (G_LIKELY (passwords)) 
    122         { 
    123                 const gchar *accountid = tny_account_get_id (account); 
    124  
    125                 gchar *pwd = g_hash_table_lookup (passwords, accountid); 
    126  
    127                 if (G_LIKELY (pwd)) 
    128                 { 
    129                         memset (pwd, 0, strlen (pwd)); 
    130                         /* g_free (pwd); uhm, crashed once */ 
    131                         g_hash_table_remove (passwords, accountid); 
    132                 } 
    133  
    134         } 
     86        TnyPlatformFactory *platfact = tny_olpc_platform_factory_get_instance (); 
     87        TnyPasswordGetter *pwdgetter; 
     88 
     89        pwdgetter = tny_platform_factory_new_password_getter (platfact); 
     90        tny_password_getter_forget_password (pwdgetter, account); 
     91        g_object_unref (G_OBJECT (pwdgetter)); 
    13592 
    13693        return; 
  • trunk/libtinymail-olpc/tny-olpc-platform-factory.c

    r1700 r1783  
    2020 
    2121#include <tny-olpc-platform-factory.h> 
    22  
    2322#include <tny-olpc-account-store.h> 
    2423#include <tny-olpc-device.h> 
    2524#include <tny-gtk-msg-view.h> 
     25#include <tny-gtk-password-dialog.h> 
    2626#include <tny-camel-mime-part.h> 
    2727#include <tny-camel-msg.h> 
     
    6868} 
    6969 
     70static TnyPasswordGetter* 
     71tny_olpc_platform_factory_new_password_getter (TnyPlatformFactory *self) 
     72{ 
     73        return tny_gtk_password_dialog_new (); 
     74} 
     75 
    7076/** 
    7177 * tny_olpc_platform_factory_get_instance: 
     
    104110        klass->new_msg_func = tny_olpc_platform_factory_new_msg; 
    105111        klass->new_mime_part_func = tny_olpc_platform_factory_new_mime_part; 
     112        klass->new_password_getter_func = tny_olpc_platform_factory_new_password_getter; 
    106113 
    107114        return; 
  • trunk/libtinymail/Makefile.am

    r1683 r1783  
    3333        tny-msg-remove-strategy.h \ 
    3434        tny-msg-receive-strategy.h \ 
    35         tny-send-queue.h 
     35        tny-send-queue.h \ 
     36        tny-password-getter.h 
    3637 
    3738libtinymail_1_0_la_SOURCES = \ 
     
    6869        tny-msg-remove-strategy.c \ 
    6970        tny-msg-receive-strategy.c \ 
    70         tny-send-queue.c 
     71        tny-send-queue.c \ 
     72        tny-password-getter.c 
    7173 
    7274libtinymail_1_0_la_LIBADD = $(LIBTINYMAIL_LIBS) 
  • trunk/libtinymail/tny-shared.h

    r1719 r1783  
    102102typedef struct _TnyFolderStatsClass TnyFolderStatsClass; 
    103103typedef enum _TnyFolderCaps TnyFolderCaps; 
     104typedef struct _TnyPasswordGetter TnyPasswordGetter; 
     105typedef struct _TnyPasswordGetterIface TnyPasswordGetterIface; 
    104106 
    105107G_END_DECLS 
  • trunk/libtinymailui-gtk/Makefile.am

    r1398 r1783  
    2222        tny-gtk-attach-list-model.h \ 
    2323        tny-gtk-text-buffer-stream.h \ 
    24         tny-gtk-header-view.h 
     24        tny-gtk-header-view.h \ 
     25        tny-gtk-password-dialog.h 
    2526 
    2627libtinymailui_gtk_1_0_la_SOURCES = \ 
     
    4647        tny-gtk-account-list-model-iterator-priv.h \ 
    4748        tny-gtk-text-buffer-stream.c \ 
    48         tny-gtk-header-view.c 
     49        tny-gtk-header-view.c \ 
     50        tny-gtk-password-dialog.c 
    4951 
    5052libtinymailui_gtk_1_0_la_LIBADD = \ 
  • trunk/libtinymailui-gtk/tny-gtk-password-dialog.c

    r1782 r1783  
    11/* tinymail - Tiny Mail 
    2  * Copyright (C) 2006-2007 Philip Van Hoof <pvanhoof@gnome.org> 
     2 * Copyright (C) 2006-2007 Philip Van Hoof <pvanhoof@gtk.org> 
    33 * 
    44 * This library is free software; you can redistribute it and/or 
     
    2020/* TODO: Refactory this type to libtinymailui-gtk */ 
    2121#include <config.h> 
     22#include <string.h> 
     23 
    2224#include <glib/gi18n-lib.h> 
    2325 
    2426#include <gtk/gtk.h> 
    25 #include <tny-gnome-password-dialog.h> 
     27#include <tny-gtk-password-dialog.h> 
     28 
     29#include <tny-account.h> 
    2630 
    2731static GObjectClass *parent_class = NULL; 
    2832 
    29 typedef struct _TnyGnomePasswordDialogPriv TnyGnomePasswordDialogPriv; 
    30  
    31 struct _TnyGnomePasswordDialogPriv 
     33typedef struct _TnyGtkPasswordDialogPriv TnyGtkPasswordDialogPriv; 
     34 
     35struct _TnyGtkPasswordDialogPriv 
    3236{ 
    3337        GtkEntry *pwd_entry; 
     
    3539}; 
    3640 
    37 #define TNY_GNOME_PASSWORD_DIALOG_GET_PRIVATE(o)        \ 
    38         (G_TYPE_INSTANCE_GET_PRIVATE ((o), TNY_TYPE_GNOME_PASSWORD_DIALOG, TnyGnomePasswordDialogPriv)) 
    39  
     41#define TNY_GTK_PASSWORD_DIALOG_GET_PRIVATE(o)  \ 
     42        (G_TYPE_INSTANCE_GET_PRIVATE ((o), TNY_TYPE_GTK_PASSWORD_DIALOG, TnyGtkPasswordDialogPriv)) 
     43 
     44static GHashTable *passwords = NULL; 
     45 
     46 
     47 
     48static const gchar* 
     49tny_gtk_password_dialog_get_password (TnyPasswordGetter *self, TnyAccount *account, const gchar *prompt, gboolean *cancel) 
     50
     51        TnyGtkPasswordDialogPriv *priv = TNY_GTK_PASSWORD_DIALOG_GET_PRIVATE (self); 
     52