Changeset 2339

Show
Ignore:
Timestamp:
07/02/07 11:48:09
Author:
murrayc
Message:

2007-07-02 Murray Cumming <murrayc@murrayc.com>

        • libtinymail-maemo/tny-maemo-conic-device.c:

(tny_maemo_conic_device_connect): When using scratchbox, show an OK/Cancel dialog
and write a fake connection name to the text file, to simulate what libconic does on
the device.
(on_dummy_connection_check): Interpret 'none' in the text file as meaning no connection.
This leaves an empty file as defaulting to a meaning of connection debugid0.
(tny_maemo_conic_device_get_current_iap_id): Return NULL if the iap is 'none', when in
scratchbox.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ChangeLog

    r2337 r2339  
     12007-07-02  Murray Cumming  <murrayc@murrayc.com> 
     2 
     3        * libtinymail-maemo/tny-maemo-conic-device.c: 
     4        (tny_maemo_conic_device_connect): When using scratchbox, show an OK/Cancel dialog 
     5        and write a fake connection name to the text file, to simulate what libconic does on  
     6        the device. 
     7        (on_dummy_connection_check): Interpret 'none' in the text file as meaning no connection. 
     8        This leaves an empty file as defaulting to a meaning of connection debugid0. 
     9        (tny_maemo_conic_device_get_current_iap_id): Return NULL if the iap is 'none', when in  
     10        scratchbox. 
     11 
    1122007-07-02  Philip Van Hoof  <pvanhoof@gnome.org> 
    213 
  • trunk/libtinymail-maemo/tny-maemo-conic-device.c

    r2329 r2339  
    3030#include <stdio.h> /* for printf */ 
    3131 
     32#ifdef MAEMO_CONIC_DUMMY  
     33#include <gtk/gtkmessagedialog.h> 
     34#endif 
     35 
    3236#ifdef MAEMO_CONIC_DUMMY 
    3337/* #include "coniciap-private.h" 
     
    4852 
    4953#define MAEMO_CONIC_DUMMY_IAP_ID_FILENAME "maemo_conic_dummy_id" 
     54#define MAEMO_CONIC_DUMMY_IAP_ID_NONE "none" 
    5055static gboolean on_dummy_connection_check (gpointer user_data); 
    5156#endif /* MAEMO_CONIC_DUMMY */ 
     
    170175} 
    171176 
     177#ifdef MAEMO_CONIC_DUMMY 
     178 
     179static gchar* 
     180get_dummy_filename () 
     181{ 
     182        gchar *filename = g_build_filename ( 
     183                g_get_home_dir (),  
     184                MAEMO_CONIC_DUMMY_IAP_ID_FILENAME, 
     185                NULL); 
     186        return filename; 
     187} 
     188 
     189static gboolean dummy_con_ic_connection_connect_by_id (TnyMaemoConicDevice *self, const gchar* iap_id) 
     190{ 
     191        /* Show a dialog, because libconic would show a dialog here, 
     192         * and give the user a chance to refuse a new connection, because libconic would allow that too. 
     193         * This allows us to see roughly similar behaviour in scratchbox as on the device. */ 
     194        GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new( NULL, GTK_DIALOG_MODAL, 
     195                        GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL,  
     196                        "TnyMaemoConicDevice fake scratchbox implementation:\nThe application requested a connection. Make a fake connection?")); 
     197        const int response = gtk_dialog_run (dialog); 
     198        gtk_widget_hide (GTK_WIDGET (dialog)); 
     199        gtk_widget_destroy (GTK_WIDGET (dialog)); 
     200         
     201        if (response == GTK_RESPONSE_OK) { 
     202                /* Make a connection, by setting a name in our dummy text file, 
     203                 * which will be read later: */ 
     204                gchar *filename = get_dummy_filename (); 
     205                 
     206                gchar *contents = 0; 
     207                GError* error = 0; 
     208                g_file_set_contents (filename, "debug id0", -1, &error); 
     209                if(error) { 
     210                        printf("%s: error from g_file_set_contents(): %s\n", __FUNCTION__, error->message); 
     211                        g_error_free (error); 
     212                        error = NULL; 
     213                } 
     214                 
     215                g_free (filename); 
     216                 
     217                return TRUE; 
     218        } 
     219        else 
     220                return FALSE; 
     221} 
     222 
     223#endif /* MAEMO_CONIC_DUMMY */ 
     224         
    172225/** 
    173226 * tny_maemo_conic_device_connect: 
     
    186239tny_maemo_conic_device_connect (TnyMaemoConicDevice *self, const gchar* iap_id) 
    187240{ 
     241        #ifdef MAEMO_CONIC_DUMMY  
     242        return dummy_con_ic_connection_connect_by_id (self, iap_id); 
     243        #endif /* MAEMO_CONIC_DUMMY */ 
     244         
    188245        TnyMaemoConicDevicePriv *priv; 
    189246 
     
    299356                on_dummy_connection_check (self); 
    300357        } 
     358         
     359        /* Handle the special "none" text: */ 
     360        if (priv->iap && (strcmp (priv->iap, MAEMO_CONIC_DUMMY_IAP_ID_NONE) == 0)) 
     361                return NULL; 
    301362        #endif 
    302363         
     
    483544 
    484545#ifdef MAEMO_CONIC_DUMMY 
     546 
    485547static gboolean on_dummy_connection_check (gpointer user_data) 
    486548{ 
     
    490552        /* Check whether the enviroment variable has changed,  
    491553         * so we can fake a connection change: */ 
    492         gchar *filename = g_build_filename ( 
    493                 g_get_home_dir (),  
    494                 MAEMO_CONIC_DUMMY_IAP_ID_FILENAME, 
    495                 NULL); 
     554        gchar *filename = get_dummy_filename (); 
    496555                 
    497556        gchar *contents = 0; 
     
    513572 
    514573        if (!(priv->iap) || (strcmp (contents, priv->iap) != 0)) { 
     574                if (priv->iap) { 
     575                        g_free (priv->iap); 
     576                        priv->iap = NULL; 
     577                } 
     578                         
     579                /* We store even the special "none" text, so we can detect changes. */ 
    515580                priv->iap = g_strdup (contents); 
    516581                 
    517                 printf ("DEBUG: TnyMaemoConicDevice: %s:\n  Dummy connection changing to %s\n", __FUNCTION__, priv->iap); 
    518                 g_signal_emit (self, tny_device_signals [TNY_DEVICE_CONNECTION_CHANGED], 
     582                if (strcmp (priv->iap, MAEMO_CONIC_DUMMY_IAP_ID_NONE) == 0) {            
     583                        printf ("DEBUG: TnyMaemoConicDevice: %s:\n  Dummy connection changing to no connection.\n", __FUNCTION__); 
     584                        g_signal_emit (self, tny_device_signals [TNY_DEVICE_CONNECTION_CHANGED], 
     585                               0, FALSE); 
     586                } else { 
     587                        printf ("DEBUG: TnyMaemoConicDevice: %s:\n  Dummy connection changing to '%s\n", __FUNCTION__, priv->iap); 
     588                        g_signal_emit (self, tny_device_signals [TNY_DEVICE_CONNECTION_CHANGED], 
    519589                       0, TRUE); 
     590                } 
    520591        } 
    521592