Changeset 505

Show
Ignore:
Timestamp:
06/13/06 23:33:42
Author:
pvanhoof
Message:

Support for offline mode

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libtinymail-camel/tny-account-priv.h

    r485 r505  
    4343}; 
    4444 
    45 const CamelService*  _tny_account_get_service    (TnyAccount *self); 
    46 const gchar*         _tny_account_get_url_string (TnyAccount *self); 
     45const CamelService* _tny_account_get_service (TnyAccount *self); 
     46const gchar* _tny_account_get_url_string (TnyAccount *self); 
     47void _tny_account_set_online_status (TnyAccount *self, gboolean offline); 
    4748 
    48 void _tny_account_start_camel_operation          (TnyAccountIface *self, CamelOperationStatusFunc func, gpointer user_data, const gchar *what); 
    49 void _tny_account_stop_camel_operation           (TnyAccountIface *self); 
     49void _tny_account_start_camel_operation (TnyAccountIface *self, CamelOperationStatusFunc func, gpointer user_data, const gchar *what); 
     50void _tny_account_stop_camel_operation (TnyAccountIface *self); 
    5051 
    5152#define TNY_ACCOUNT_GET_PRIVATE(o)      \ 
  • trunk/libtinymail-camel/tny-account.c

    r486 r505  
    3636#include <camel/camel-session.h> 
    3737#include <camel/camel-store.h> 
     38#include <camel/camel-offline-folder.h> 
     39#include <camel/camel-offline-store.h> 
     40#include <camel/camel-disco-folder.h> 
     41#include <camel/camel-disco-store.h> 
    3842 
    3943#include <sys/stat.h> 
     
    470474{ 
    471475        g_object_unref (G_OBJECT (data)); 
     476} 
     477 
     478void  
     479_tny_account_set_online_status (TnyAccount *self, gboolean offline) 
     480{ 
     481        TnyAccountPriv *priv = TNY_ACCOUNT_GET_PRIVATE (self); 
     482 
     483        if (!priv->service) 
     484                return; 
     485 
     486 
     487        if (offline) 
     488                camel_service_cancel_connect (priv->service); 
     489 
     490        if (CAMEL_IS_DISCO_STORE (priv->service)) { 
     491                if (!offline) { 
     492                        camel_disco_store_set_status (CAMEL_DISCO_STORE (priv->service), 
     493                                                      CAMEL_DISCO_STORE_ONLINE, priv->ex); 
     494                        return; 
     495                } else if (camel_disco_store_can_work_offline (CAMEL_DISCO_STORE (priv->service))) { 
     496 
     497                        camel_disco_store_set_status (CAMEL_DISCO_STORE (priv->service), 
     498                                                      CAMEL_DISCO_STORE_OFFLINE, 
     499                                                      priv->ex); 
     500                        return; 
     501                } 
     502        } else if (CAMEL_IS_OFFLINE_STORE (priv->service)) { 
     503 
     504                if (!offline) { 
     505 
     506                        camel_offline_store_set_network_state (CAMEL_OFFLINE_STORE (priv->service), 
     507                                                               CAMEL_OFFLINE_STORE_NETWORK_AVAIL, 
     508                                                               priv->ex); 
     509                        return; 
     510                } else { 
     511                        camel_offline_store_set_network_state (CAMEL_OFFLINE_STORE (priv->service), 
     512                                                               CAMEL_OFFLINE_STORE_NETWORK_UNAVAIL, 
     513                                                               priv->ex); 
     514                        return; 
     515                } 
     516        } 
     517 
     518        if (offline) 
     519                camel_service_disconnect (CAMEL_SERVICE (priv->service), 
     520                                          TRUE, priv->ex); 
    472521} 
    473522 
  • trunk/libtinymail-camel/tny-session-camel.c

    r502 r505  
    438438tny_session_camel_init (TnySessionCamel *instance) 
    439439{ 
     440        /* Avoid the first question in connection_changed */ 
     441        instance->prev_constat = TRUE; 
    440442        instance->device = NULL; 
    441443} 
     
    445447{ 
    446448        TnySessionCamel *self = user_data; 
    447  
     449         
    448450        camel_session_set_online ((CamelSession *) self, online);  
     451 
     452        if (self->account_store) 
     453        { 
     454                GList *copy; 
     455 
     456                copy = (GList*) tny_account_store_iface_get_store_accounts (self->account_store);; 
     457         
     458                while (G_LIKELY (copy)) 
     459                { 
     460                        TnyStoreAccountIface *account = copy->data; 
     461 
     462                        _tny_account_set_online_status (account, !online); 
     463 
     464                        copy = g_list_next (copy); 
     465                } 
     466        } 
     467 
     468 
     469        self->prev_constat = online; 
    449470 
    450471        return; 
  • trunk/libtinymail-camel/tny-session-camel.h

    r487 r505  
    3939        gpointer device; 
    4040        gpointer account_store; 
    41         gboolean interactive
     41        gboolean interactive, prev_constat
    4242        guint connchanged_signal; 
    4343}; 
  • trunk/libtinymail-camel/tny-store-account.c

    r503 r505  
    6767} 
    6868 
     69 
     70static void 
     71walk_folders_uncache_em (TnyStoreAccountIface *self, TnyListIface *folders) 
     72{ 
     73  if (folders && tny_list_iface_length (folders) > 0) 
     74  { 
     75        TnyIteratorIface *iterator = tny_list_iface_create_iterator (folders); 
     76        gboolean next = TRUE; 
     77 
     78        while (next) 
     79        { 
     80                TnyMsgFolderIface *folder = tny_iterator_iface_current (iterator); 
     81                TnyListIface *more_folders = (TnyListIface*)tny_msg_folder_iface_get_folders (folder); 
     82 
     83                tny_msg_folder_iface_uncache (folder); 
     84 
     85                if (tny_list_iface_length (more_folders) > 0) 
     86                        walk_folders_uncache_em (self, more_folders); 
     87 
     88                next = tny_iterator_iface_has_next (iterator); 
     89 
     90                if (next) 
     91                        tny_iterator_iface_next (iterator); 
     92        } 
     93 
     94        g_object_unref (G_OBJECT (iterator)); 
     95  } 
     96} 
     97 
    6998static void  
    7099tny_store_account_reconnect (TnyAccount *self) 
    71100{ 
    72101        TnyAccountPriv *priv = TNY_ACCOUNT_GET_PRIVATE (self); 
     102        TnyStoreAccountPriv *spriv = TNY_STORE_ACCOUNT_GET_PRIVATE (self); 
     103 
     104        if (spriv->folders) 
     105                walk_folders_uncache_em (TNY_STORE_ACCOUNT_IFACE (self), spriv->folders); 
     106 
     107        if (spriv->ufolders) 
     108                walk_folders_uncache_em (TNY_STORE_ACCOUNT_IFACE (self), spriv->ufolders); 
    73109 
    74110        if (G_LIKELY (priv->session) && G_UNLIKELY (priv->proto) &&  
     
    125161                if (G_UNLIKELY (priv->service)) 
    126162                        camel_object_unref (CAMEL_OBJECT (priv->service)); 
    127          
    128                 priv->service = camel_session_get_service  
     163 
     164                priv->service = camel_session_get_service 
    129165                        (CAMEL_SESSION (priv->session), priv->url_string,  
    130166                        priv->type, priv->ex); 
     
    136172        { 
    137173                /* un officially supported provider */ 
    138                 priv->service = camel_session_get_service  
     174 
     175                priv->service = camel_session_get_service 
    139176                        (CAMEL_SESSION (priv->session), priv->url_string,  
    140177                        priv->type, priv->ex); 
     178 
    141179                if (priv->service == NULL) 
    142180                        report_error (priv); 
     
    151189        { 
    152190                priv->connected = FALSE; 
    153                 camel_service_connect (priv->service, priv->ex); 
    154  
    155                 if (camel_exception_is_set (priv->ex)) 
     191 
     192                if (!camel_service_connect (priv->service, priv->ex)) 
    156193                { 
    157194                        g_warning (_("Not connected with %s: %s\n"), priv->url_string, 
    158195                                   camel_exception_get_description (priv->ex)); 
    159196                        camel_exception_clear (priv->ex); 
    160                         camel_service_cancel_connect (priv->service); 
    161                         camel_service_disconnect (priv->service, FALSE, priv->ex); 
     197                        /* camel_service_cancel_connect (priv->service); 
     198                        camel_service_disconnect (priv->service, FALSE, priv->ex); */ 
    162199                } else { 
    163200                        priv->connected = TRUE; 
    164201                } 
    165                  
    166                 camel_session_set_online (CAMEL_SESSION (priv->session), priv->connected); 
    167202        } 
    168203 
  • trunk/libtinymail-gnome-desktop/tny-account-store.c

    r487 r505  
    748748 
    749749        priv->device = tny_platform_factory_iface_new_device (platfact); 
     750        //tny_device_iface_force_online (priv->device); 
    750751        priv->session = tny_session_camel_new (TNY_ACCOUNT_STORE_IFACE (self)); 
    751752 
  • trunk/libtinymail-gnome-desktop/tny-device-priv.h

    r259 r505  
    2727        libnm_glib_ctx *nm_ctx; 
    2828        guint callback_id; 
     29        gboolean forced, fset; 
    2930}; 
    3031 
  • trunk/libtinymail-gnome-desktop/tny-device.c

    r487 r505  
    2929#include "tny-device-priv.h" 
    3030 
    31 static void 
    32 tny_device_on_online (TnyDeviceIface *self) 
    33 
    34         g_signal_emit (self, tny_device_iface_signals [TNY_DEVICE_IFACE_CONNECTION_CHANGED], 0, TRUE); 
    35  
    36         return; 
    37 
    38  
    39 static void 
    40 tny_device_on_offline (TnyDeviceIface *self) 
    41 
    42         g_signal_emit (self, tny_device_iface_signals [TNY_DEVICE_IFACE_CONNECTION_CHANGED], 0, FALSE); 
    43  
    44         return; 
    45 
    46  
    47 static gboolean 
    48 tny_device_is_online (TnyDeviceIface *self) 
    49 
    50         TnyDevicePriv *priv = TNY_DEVICE_GET_PRIVATE (self); 
    51  
    52         libnm_glib_state state = libnm_glib_get_network_state (priv->nm_ctx); 
    53         gboolean retval; 
    54  
    55         switch (state) 
    56         { 
    57                 case LIBNM_NO_NETWORK_CONNECTION: 
    58                 retval = FALSE; 
    59                 break; 
    60  
    61                 case LIBNM_NO_DBUS: 
    62                 case LIBNM_NO_NETWORKMANAGER: 
    63                 case LIBNM_INVALID_CONTEXT: 
    64                 g_print (_("Invalid network manager installation. Going to assume Online status\n")); 
    65                 case LIBNM_ACTIVE_NETWORK_CONNECTION: 
    66                 default: 
    67                 retval = TRUE; 
    68                 break; 
    69         } 
    70  
    71         return retval; 
    72 
     31static void tny_device_on_online (TnyDeviceIface *self); 
     32static void tny_device_on_offline (TnyDeviceIface *self); 
     33static gboolean tny_device_is_online (TnyDeviceIface *self); 
     34 
    7335 
    7436static void  
     
    8547} 
    8648 
     49static void  
     50tny_device_reset (TnyDeviceIface *self) 
     51{ 
     52        TnyDevicePriv *priv = TNY_DEVICE_GET_PRIVATE (self); 
     53 
     54        priv->fset = FALSE; 
     55        priv->forced = FALSE; 
     56 
     57        nm_callback (priv->nm_ctx, self); 
     58} 
     59 
     60static void  
     61tny_device_force_online (TnyDeviceIface *self) 
     62{ 
     63        TnyDevicePriv *priv = TNY_DEVICE_GET_PRIVATE (self); 
     64 
     65        priv->fset = TRUE; 
     66        priv->forced = TRUE; 
     67 
     68        nm_callback (priv->nm_ctx, self); 
     69 
     70        return; 
     71} 
     72 
     73 
     74static void 
     75tny_device_force_offline (TnyDeviceIface *self) 
     76{ 
     77        TnyDevicePriv *priv = TNY_DEVICE_GET_PRIVATE (self); 
     78 
     79        priv->fset = TRUE; 
     80        priv->forced = FALSE; 
     81 
     82        nm_callback (priv->nm_ctx, self); 
     83 
     84        return; 
     85} 
     86 
     87static void 
     88tny_device_on_online (TnyDeviceIface *self) 
     89{ 
     90        g_signal_emit (self, tny_device_iface_signals [TNY_DEVICE_IFACE_CONNECTION_CHANGED], 0, TRUE); 
     91 
     92        return; 
     93} 
     94 
     95static void 
     96tny_device_on_offline (TnyDeviceIface *self) 
     97{ 
     98        g_signal_emit (self, tny_device_iface_signals [TNY_DEVICE_IFACE_CONNECTION_CHANGED], 0, FALSE); 
     99 
     100        return; 
     101} 
     102 
     103static gboolean 
     104tny_device_is_online (TnyDeviceIface *self) 
     105{ 
     106        TnyDevicePriv *priv = TNY_DEVICE_GET_PRIVATE (self); 
     107        gboolean retval = priv->forced; 
     108 
     109        if (!priv->fset) 
     110        { 
     111                libnm_glib_state state = libnm_glib_get_network_state (priv->nm_ctx); 
     112                 
     113                switch (state) 
     114                { 
     115                        case LIBNM_NO_NETWORK_CONNECTION: 
     116                        retval = FALSE; 
     117                        break; 
     118 
     119                        case LIBNM_NO_DBUS: 
     120                        case LIBNM_NO_NETWORKMANAGER: 
     121                        case LIBNM_INVALID_CONTEXT: 
     122                        g_print (_("Invalid network manager installation. Going to assume Online status\n")); 
     123                        case LIBNM_ACTIVE_NETWORK_CONNECTION: 
     124                        default: 
     125                        retval = TRUE; 
     126                        break; 
     127                } 
     128        } 
     129 
     130        return retval; 
     131} 
     132 
     133 
    87134static void 
    88135tny_device_instance_init (GTypeInstance *instance, gpointer g_class) 
     
    91138        TnyDevicePriv *priv = TNY_DEVICE_GET_PRIVATE (self); 
    92139 
     140        priv->fset = FALSE; 
     141        priv->forced = FALSE; 
    93142        priv->nm_ctx = libnm_glib_init (); 
    94143        priv->callback_id = libnm_glib_register_callback  
     
    136185 
    137186        klass->is_online_func = tny_device_is_online; 
     187        klass->reset_func = tny_device_reset; 
     188        klass->force_offline_func = tny_device_force_offline; 
     189        klass->force_online_func = tny_device_force_online; 
    138190 
    139191        return; 
  • trunk/libtinymail/tny-device-iface.c

    r487 r505  
    3232guint *tny_device_iface_signals = NULL; 
    3333 
     34 
     35/** 
     36 * tny_device_iface_reset: 
     37 * @self: a #TnyDeviceIface object 
     38 *  
     39 * Reset status 
     40 **/ 
     41void  
     42tny_device_iface_reset (TnyDeviceIface *self) 
     43{ 
     44        TNY_DEVICE_IFACE_GET_CLASS (self)->reset_func (self); 
     45        return; 
     46} 
     47 
     48/** 
     49 * tny_device_iface_force_offline: 
     50 * @self: a #TnyDeviceIface object 
     51 *  
     52 * Force offline status 
     53 **/ 
     54void  
     55tny_device_iface_force_online (TnyDeviceIface *self) 
     56{ 
     57        TNY_DEVICE_IFACE_GET_CLASS (self)->force_online_func (self); 
     58        return; 
     59} 
     60 
     61/** 
     62 * tny_device_iface_force_online: 
     63 * @self: a #TnyDeviceIface object 
     64 *  
     65 * Force online status 
     66 **/ 
     67void 
     68tny_device_iface_force_offline (TnyDeviceIface *self) 
     69{ 
     70        TNY_DEVICE_IFACE_GET_CLASS (self)->force_offline_func (self); 
     71        return; 
     72} 
    3473 
    3574/** 
  • trunk/libtinymail/tny-device-iface.h

    r487 r505  
    4848        GTypeInterface parent; 
    4949 
    50         gboolean (*is_online_func)  (TnyDeviceIface *self); 
     50        gboolean (*is_online_func) (TnyDeviceIface *self); 
     51 
     52        void (*force_online_func) (TnyDeviceIface *self); 
     53        void (*force_offline_func) (TnyDeviceIface *self); 
     54        void (*reset_func) (TnyDeviceIface *self); 
    5155 
    5256        /* Signals */ 
    53         void (*connection_changed) (TnyDeviceIface *self, gboolean online); 
     57        void (*connection_changed) (TnyDeviceIface *self, gboolean online); 
    5458 
    5559}; 
     
    5862 
    5963gboolean tny_device_iface_is_online (TnyDeviceIface *self); 
     64void tny_device_iface_force_online (TnyDeviceIface *self); 
     65void tny_device_iface_force_offline (TnyDeviceIface *self); 
    6066 
    6167G_END_DECLS 
  • trunk/tinymail/tny-summary-window.c

    r501 r505  
    5353#include <tny-account-store-view-iface.h> 
    5454 
     55 
     56#define GO_ONLINE_TXT _("Go online") 
     57#define GO_OFFLINE_TXT _("Go offline") 
     58 
    5559static GObjectClass *parent_class = NULL; 
    5660 
     
    6468        TnyMsgViewIface *msg_view; 
    6569        guint accounts_reloaded_signal; 
    66         GtkWidget *status, *progress
     70        GtkWidget *status, *progress, *online_button
    6771        guint status_id; 
    6872        gulong mailbox_select_sid; 
    6973        GtkTreeSelection *mailbox_select; 
    7074        GtkTreeIter last_mailbox_correct_select; 
    71         guint connchanged_signal
     75        guint connchanged_signal, online_button_signal
    7276        TnyMsgFolderIface *last_folder; 
    7377}; 
     
    96100} 
    97101 
     102static GtkTreeModel *empty_model; 
     103 
    98104static void  
    99105reload_accounts (TnySummaryWindowPriv *priv) 
    100106{ 
    101         static GtkTreeModel *empty_model; 
    102  
    103107        TnyAccountStoreIface *account_store = priv->account_store; 
    104108        GtkTreeModel *sortable, *mailbox_model = GTK_TREE_MODEL (tny_account_tree_model_new ()); 
     
    108112                empty_model = GTK_TREE_MODEL (gtk_list_store_new  
    109113                        (1, G_TYPE_STRING)); 
    110  
    111114        /* Clear the header_view by giving it an empty model */ 
    112115        set_header_view_model (GTK_TREE_VIEW (priv->header_view), empty_model); 
     
    141144{ 
    142145        TnySummaryWindowPriv *priv = user_data; 
    143  
     146         
    144147        reload_accounts (priv); 
    145148         
     
    147150} 
    148151 
     152static void  
     153online_button_toggled (GtkToggleButton *togglebutton, gpointer user_data) 
     154{ 
     155        TnySummaryWindowIface *self = user_data; 
     156        TnySummaryWindowPriv *priv = TNY_SUMMARY_WINDOW_GET_PRIVATE (self); 
     157 
     158        if (priv->account_store) 
     159        { 
     160                const TnyDeviceIface *device = tny_account_store_iface_get_device (priv->account_store); 
     161 
     162                if (gtk_toggle_button_get_active (togglebutton)) 
     163                        tny_device_iface_force_online (device); 
     164                else 
     165                        tny_device_iface_force_offline (device); 
     166        } 
     167} 
     168 
    149169static void 
    150170connection_changed (TnyDeviceIface *device, gboolean online, gpointer user_data) 
    151171{ 
    152172        TnySummaryWindowIface *self = user_data; 
     173        TnySummaryWindowPriv *priv = TNY_SUMMARY_WINDOW_GET_PRIVATE (self); 
    153174 
    154175        if (online) 
     176        { 
     177                gtk_button_set_label  (GTK_BUTTON (priv->online_button), GO_OFFLINE_TXT); 
     178                g_signal_handler_block (G_OBJECT (priv->online_button), priv->online_button_signal); 
     179                gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->online_button), TRUE); 
     180                g_signal_handler_unblock (G_OBJECT (priv->online_button), priv->online_button_signal); 
     181 
    155182                gtk_window_set_title (GTK_WINDOW (self), _("Tinymail - online")); 
    156         else 
     183        } else { 
     184 
     185                gtk_button_set_label  (GTK_BUTTON (priv->online_button), GO_ONLINE_TXT); 
     186                g_signal_handler_block (G_OBJECT (priv->online_button), priv->online_button_signal); 
     187                gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->online_button), FALSE); 
     188                g_signal_handler_unblock (G_OBJECT (priv->online_button), priv->online_button_signal); 
     189 
    157190                gtk_window_set_title (GTK_WINDOW (self), _("Tinymail - offline")); 
     191        } 
    158192 
    159193        return; 
     
    297331                                else  
    298332                                { 
    299                                         GtkTreeModel *rmodel = model; 
    300                                         if (GTK_IS_TREE_MODEL_SORT (model)) 
    301                                                 rmodel = gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (model)); 
    302                                         tny_list_iface_remove (TNY_LIST_IFACE (rmodel), header); 
     333                                        /* Loading the message failed (service unavailable  
     334                                           or message deleted by an external device) */ 
    303335                                } 
    304336 
     
    528560        GtkWidget *vbox; 
    529561         
    530  
    531562        /* TODO: Persist application UI status (of the panes) */ 
     563 
     564        priv->online_button = gtk_toggle_button_new (); 
     565 
     566        priv->online_button_signal = g_signal_connect (G_OBJECT (priv->online_button), "toggled",  
     567                G_CALLBACK (online_button_toggled), self); 
    532568        priv->last_folder = NULL; 
    533569        platfact = TNY_PLATFORM_FACTORY_IFACE  
     
    542578 
    543579        gtk_box_pack_start (GTK_BOX (priv->status), priv->progress, FALSE, FALSE, 0); 
     580        gtk_box_pack_start (GTK_BOX (priv->status), priv->online_button, FALSE, FALSE, 0); 
     581 
     582        gtk_widget_show (priv->online_button); 
    544583        gtk_widget_show (priv->status); 
    545584        gtk_widget_show (vbox);