Changeset 1911

Show
Ignore:
Timestamp:
05/08/07 11:41:03
Author:
murrayc
Message:

2007-05-08 Murray Cumming <murrayc@murrayc.com

        • libtinymail/tny-account-store.c:
        • libtinymail/tny-account-store.h: Change the alert_func vfunc to

provide a GError instead of a human-readable error string.
(tny_account_store_alert): The documentation for this vfunc invoker seems to
refer to the vfunc (as is also normal in GTK+), so document how the GError
should be used and point out that the application should translate the
message and show an appropriate dialog.
This does not seem to require the definition of a new GError domain -
the existing one seems suitable.

        • libtinymail-acap/tny-acap-account-store.c:

(tny_acap_account_store_alert):

        • libtinymail-camel/tny-camel-account.c:

(tny_camel_account_set_online_default):

        • libtinymail-camel/tny-session-camel.c:

(tny_session_camel_alert_user), (foreach_account_set_connectivity):

        • libtinymail-gnome-desktop/tny-gnome-account-store.c:

(tny_gnome_account_store_alert):

        • libtinymail-gpe/tny-gpe-account-store.c:

(tny_gpe_account_store_alert):

        • libtinymail-maemo/tny-maemo-account-store.c:

(tny_maemo_account_store_alert):

        • libtinymail-olpc/tny-olpc-account-store.c:

(tny_olpc_account_store_alert):

        • tests/shared/account-store.c: (tny_test_account_store_alert):

Use the GError instead of the message string.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ChangeLog

    r1906 r1911  
     12007-05-08  Murray Cumming  <murrayc@murrayc.com 
     2 
     3        * libtinymail/tny-account-store.c: 
     4        * libtinymail/tny-account-store.h: Change the alert_func vfunc to  
     5        provide a GError instead of a human-readable error string. 
     6        (tny_account_store_alert): The documentation for this vfunc invoker seems to  
     7        refer to the vfunc (as is also normal in GTK+), so document how the GError  
     8        should be used and point out that the application should translate the  
     9        message and show an appropriate dialog. 
     10        This does not seem to require the definition of a new GError domain -  
     11        the existing one seems suitable. 
     12         
     13        * libtinymail-acap/tny-acap-account-store.c: 
     14        (tny_acap_account_store_alert): 
     15        * libtinymail-camel/tny-camel-account.c: 
     16        (tny_camel_account_set_online_default): 
     17        * libtinymail-camel/tny-session-camel.c: 
     18        (tny_session_camel_alert_user), (foreach_account_set_connectivity): 
     19        * libtinymail-gnome-desktop/tny-gnome-account-store.c: 
     20        (tny_gnome_account_store_alert): 
     21        * libtinymail-gpe/tny-gpe-account-store.c: 
     22        (tny_gpe_account_store_alert): 
     23        * libtinymail-maemo/tny-maemo-account-store.c: 
     24        (tny_maemo_account_store_alert): 
     25        * libtinymail-olpc/tny-olpc-account-store.c: 
     26        (tny_olpc_account_store_alert): 
     27        * tests/shared/account-store.c: (tny_test_account_store_alert): 
     28        Use the GError instead of the message string. 
     29 
    1302007-05-08  Philip Van Hoof  <pvanhoof@gnome.org> 
    231 
  • trunk/libtinymail-acap/tny-acap-account-store.c

    r1855 r1911  
    4848 
    4949static gboolean 
    50 tny_acap_account_store_alert (TnyAccountStore *self, TnyAlertType type, const gchar *prompt
    51 { 
    52         TnyAcapAccountStorePriv *priv = TNY_ACAP_ACCOUNT_STORE_GET_PRIVATE (self); 
    53         return tny_account_store_alert (priv->real, type, prompt); 
     50tny_acap_account_store_alert (TnyAccountStore *self, TnyAlertType type, const GError *error
     51{ 
     52        TnyAcapAccountStorePriv *priv = TNY_ACAP_ACCOUNT_STORE_GET_PRIVATE (self); 
     53        return tny_account_store_alert (priv->real, type, error); 
    5454} 
    5555 
  • trunk/libtinymail-camel/tny-camel-account.c

    r1886 r1911  
    840840tny_camel_account_set_online_default (TnyCamelAccount *self, gboolean online, GError **err) 
    841841{ 
     842        /* Note that the human-readable GError:message strings here are only for debugging. 
     843         * They should never be shown to the user. The application should make its own  
     844         * decisions about how to show these errors in the UI, and should make sure that  
     845         * they are translated in the user's locale. 
     846         */ 
     847 
    842848        TnyCamelAccountPriv *priv = TNY_CAMEL_ACCOUNT_GET_PRIVATE (self); 
    843849        CamelException ex = CAMEL_EXCEPTION_INITIALISER; 
  • trunk/libtinymail-camel/tny-session-camel.c

    r1866 r1911  
    170170 
    171171static gboolean 
    172 tny_session_camel_alert_user (CamelSession *session, CamelSessionAlertType type, const char *prompt, gboolean cancel) 
     172tny_session_camel_alert_user (CamelSession *session, CamelSessionAlertType type, const GError *error, gboolean cancel) 
    173173{ 
    174174        TnySessionCamel *self = (TnySessionCamel *)session; 
     
    199199                retval = tny_account_store_alert ( 
    200200                        (TnyAccountStore*) self->priv->account_store,  
    201                         tnytype, (const gchar *) prompt); 
     201                        tnytype, error); 
    202202                tny_lockable_unlock (self->priv->ui_lock); 
    203203        } 
     
    415415                if (err != NULL)  
    416416                { 
    417                         tny_session_camel_alert_user (session, CAMEL_SESSION_ALERT_ERROR, err->message, FALSE); 
     417                        tny_session_camel_alert_user (session, CAMEL_SESSION_ALERT_ERROR, err, FALSE); 
    418418                        g_error_free (err); 
    419419                } 
  • trunk/libtinymail-gnome-desktop/tny-gnome-account-store.c

    r1866 r1911  
    100100 
    101101static gboolean 
    102 tny_gnome_account_store_alert (TnyAccountStore *self, TnyAlertType type, const gchar *prompt
     102tny_gnome_account_store_alert (TnyAccountStore *self, TnyAlertType type, const GError *error
    103103{ 
    104104        GtkMessageType gtktype; 
  • trunk/libtinymail-gpe/tny-gpe-account-store.c

    r1855 r1911  
    9898 
    9999static gboolean 
    100 tny_gpe_account_store_alert (TnyAccountStore *self, TnyAlertType type, const gchar *prompt
     100tny_gpe_account_store_alert (TnyAccountStore *self, TnyAlertType type, const GError *error
    101101{ 
    102102        GtkMessageType gtktype; 
  • trunk/libtinymail-maemo/tny-maemo-account-store.c

    r1861 r1911  
    3434 
    3535#include <tny-account-store.h> 
     36#include <tny-error.h> 
    3637#include <tny-maemo-account-store.h> 
    3738#include <tny-account.h> 
     
    9899 
    99100static gboolean 
    100 tny_maemo_account_store_alert (TnyAccountStore *self, TnyAlertType type, const gchar *prompt
     101tny_maemo_account_store_alert (TnyAccountStore *self, TnyAlertType type, const GError *error
    101102{ 
    102103        GtkMessageType gtktype; 
    103         gboolean retval = FALSE; 
    104104        GtkWidget *dialog; 
    105105 
     
    118118        } 
    119119 
     120        const gchar *prompt = NULL; 
     121        switch (error->code) 
     122        { 
     123                /* Currently, this seems to be the only possible error. 
     124                 * It originates from _tny_camel_account_try_connect(),  
     125                 * and maybe from similar functions. 
     126                 * The error->message text originates from  
     127                 * camel-imap-store.c:imap_auth_loop(). 
     128                 */ 
     129                case TNY_ACCOUNT_ERROR_TRY_CONNECT: 
     130                        /* Use a Logical ID: */ 
     131                        prompt = _("Account not yet fully configured"); 
     132                        break; 
     133                default: 
     134                        g_warning ("%s: Unhandled GError code.", __FUNCTION__); 
     135                        prompt = NULL; 
     136                break; 
     137        } 
     138         
     139        if (!prompt) 
     140                return FALSE; 
     141                 
     142        /* TODO: Show more appropriate explicitly named buttons in the dialog, 
     143         * and just show one button if there is no choice to be made. */ 
     144        gboolean retval = FALSE; 
    120145        dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, 
    121146                                  gtktype, GTK_BUTTONS_YES_NO, prompt); 
  • trunk/libtinymail-olpc/tny-olpc-account-store.c

    r1855 r1911  
    9696 
    9797static gboolean 
    98 tny_olpc_account_store_alert (TnyAccountStore *self, TnyAlertType type, const gchar *prompt
     98tny_olpc_account_store_alert (TnyAccountStore *self, TnyAlertType type, const GError *error
    9999{ 
    100100        GtkMessageType gtktype; 
  • trunk/libtinymail/tny-account-store.c

    r1866 r1911  
    8181 * @self: a #TnyAccountStore object 
    8282 * @type: the message type (severity) 
    83  * @prompt: the prompt 
    84  * 
    85  * This jump-to-the-ui method implements showing a message dialog with @prompt 
    86  * as prompt and @type as message type. It will return TRUE if the reply was  
     83 * @error: A GError, of domain TNY_ACCOUNT_ERROR, which should be used to determine what to show to the user. 
     84 * 
     85 * This jump-to-the-ui method implements showing a message dialog appropriate for the @error 
     86 * and @type as message type. It will return TRUE if the reply was  
    8787 * affirmative or FALSE if not. 
    8888 * 
    8989 * Implementors: when implementing a platform-specific library, you must 
    90  * implement this method. For example in Gtk+ by using the #GtkDialog API. The 
    91  * implementation will for example be used to ask the user about accepting SSL 
     90 * implement this method. For example in GTK+ by using the #GtkDialog API. The 
     91 * implementation will, for example, be used to ask the user about accepting SSL 
    9292 * certificates. The two possible answers that must be supported are  
    93  * "Yes" and "No" which must result in a TRUE or a FALSE return value. 
    94  * 
    95  * Example implementation for Gtk+: 
     93 * "Yes" and "No" which must result in a TRUE or a FALSE return value, though  
     94 * your implementation should attempt to use explicit button names such as  
     95 * "Accept Certificate" and "Reject Certificate". Likewise, the dialog should be  
     96 * arranged according the the user interface guidelines of your target platform. 
     97 * 
     98 * Example implementation for GTK+: 
    9699 * <informalexample><programlisting> 
    97100 * static gboolean 
    98  * tny_gnome_account_store_alert (TnyAccountStore *self, TnyAlertType type, const gchar *prompt
     101 * tny_gnome_account_store_alert (TnyAccountStore *self, TnyAlertType type, const GError *error
    99102 * { 
    100103 *     GtkMessageType gtktype; 
    101  *     gboolean retval = FALSE; 
    102104 *     GtkWidget *dialog; 
    103105 *     switch (type) 
     
    114116 *         break; 
    115117 *     } 
     118 * 
     119 *     const gchar *prompt = NULL; 
     120 *     switch (error->code) 
     121 *     { 
     122 *         case TNY_ACCOUNT_ERROR_TRY_CONNECT: 
     123 *             prompt = _("Account not yet fully configured"); 
     124 *             break; 
     125 *         default: 
     126 *             g_warning ("%s: Unhandled GError code.", __FUNCTION__); 
     127 *             prompt = NULL; 
     128 *             break; 
     129 *      } 
     130 *       
     131 *      if (!prompt) 
     132 *              return FALSE; 
     133 * 
     134 *     gboolean retval = FALSE; 
    116135 *     dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, 
    117136 *            gtktype, GTK_BUTTONS_YES_NO, prompt); 
     
    127146 **/ 
    128147gboolean  
    129 tny_account_store_alert (TnyAccountStore *self, TnyAlertType type, const gchar *prompt
     148tny_account_store_alert (TnyAccountStore *self, TnyAlertType type, const GError *error
    130149{ 
    131150        gboolean retval; 
     
    138157#endif 
    139158 
    140         retval = TNY_ACCOUNT_STORE_GET_IFACE (self)->alert_func (self, type, prompt); 
     159        retval = TNY_ACCOUNT_STORE_GET_IFACE (self)->alert_func (self, type, error); 
    141160 
    142161#ifdef DBC /* ensure */ 
  • trunk/libtinymail/tny-account-store.h

    r1855 r1911  
    7979        const gchar* (*get_cache_dir_func) (TnyAccountStore *self); 
    8080        TnyDevice* (*get_device_func) (TnyAccountStore *self); 
    81         gboolean (*alert_func) (TnyAccountStore *self, TnyAlertType type, const gchar *prompt); 
     81        gboolean (*alert_func) (TnyAccountStore *self, TnyAlertType type, const GError *error); 
    8282        TnyAccount* (*find_account_func) (TnyAccountStore *self, const gchar *url_string); 
    8383}; 
     
    9090const gchar*  tny_account_store_get_cache_dir (TnyAccountStore *self); 
    9191TnyDevice* tny_account_store_get_device (TnyAccountStore *self); 
    92 gboolean tny_account_store_alert (TnyAccountStore *self, TnyAlertType type, const gchar *prompt); 
     92gboolean tny_account_store_alert (TnyAccountStore *self, TnyAlertType type, const GError *error); 
    9393TnyAccount* tny_account_store_find_account (TnyAccountStore *self, const gchar *url_string); 
    9494 
  • trunk/tests/shared/account-store.c

    r1857 r1911  
    6666 
    6767static gboolean 
    68 tny_test_account_store_alert (TnyAccountStore *self, TnyAlertType type, const gchar *prompt
     68tny_test_account_store_alert (TnyAccountStore *self, TnyAlertType type, const GError *error
    6969{ 
    7070        return TRUE;