2008-01-14 [holger] 3.2.0cvs40
authorHolger Berndt <hb@claws-mail.org>
Mon, 14 Jan 2008 09:14:07 +0000 (09:14 +0000)
committerHolger Berndt <hb@claws-mail.org>
Mon, 14 Jan 2008 09:14:07 +0000 (09:14 +0000)
* configure.ac
Add tests for dbus, dbus glib bindings,
and NetworkManager. All is optional. Add new
--(en|dis)able-networkmanager-support switch.
* src/Makefile.am
* src/imap.c
* src/inc.c
* src/main.c
* src/main.h
* src/mainwindow.c
* src/gtk/about.c
Add optional NetworkManager support, so Claws Mail
can try to do the right thing when the network connection
status changes. NetworkManager support is active by
default if above requirements were met.

ChangeLog
PATCHSETS
configure.ac
src/Makefile.am
src/gtk/about.c
src/imap.c
src/inc.c
src/main.c
src/main.h
src/mainwindow.c

index 2f5c863e8c4507ee5886b971e2a54bab2b66c8ac..7529100dfda377f948efb126a2352b1f681637b1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2008-01-14 [holger]    3.2.0cvs40
+
+       * configure.ac
+               Add tests for dbus, dbus glib bindings,
+               and NetworkManager. All is optional. Add new
+               --(en|dis)able-networkmanager-support switch.
+       * src/Makefile.am
+       * src/imap.c
+       * src/inc.c
+       * src/main.c
+       * src/main.h
+       * src/mainwindow.c
+       * src/gtk/about.c
+               Add optional NetworkManager support, so Claws Mail
+               can try to do the right thing when the network connection
+               status changes. NetworkManager support is active by
+               default if above requirements were met.
+
 2008-01-12 [colin]     3.2.0cvs39
 
        * src/summaryview.c
index 961a2e302ebc6b7872f72910ab537f25c9e36bcc..64d9e1284552780ec021504688561890204532fa 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.16.2.33 -r 1.16.2.34 src/prefs_display_header.c;  ) > 3.2.0cvs37.patchset
 ( cvs diff -u -r 1.155.2.81 -r 1.155.2.82 src/Makefile.am;  cvs diff -u -r 1.25.2.50 -r 1.25.2.51 src/stock_pixmap.c;  cvs diff -u -r 1.18.2.32 -r 1.18.2.33 src/stock_pixmap.h;  diff -u /dev/null src/pixmaps/tray_newmail.offline.xpm;  diff -u /dev/null src/pixmaps/tray_newmail.xpm;  diff -u /dev/null src/pixmaps/tray_newmarkedmail.offline.xpm;  diff -u /dev/null src/pixmaps/tray_newmarkedmail.xpm;  diff -u /dev/null src/pixmaps/tray_nomail.offline.xpm;  diff -u /dev/null src/pixmaps/tray_nomail.xpm;  diff -u /dev/null src/pixmaps/tray_unreadmail.offline.xpm;  diff -u /dev/null src/pixmaps/tray_unreadmail.xpm;  diff -u /dev/null src/pixmaps/tray_unreadmarkedmail.offline.xpm;  diff -u /dev/null src/pixmaps/tray_unreadmarkedmail.xpm;  cvs diff -u -r 1.4.2.10 -r 1.4.2.11 src/plugins/trayicon/Makefile.am;  cvs diff -u -r -1.1.2.1 -r -1.1.2.2 src/plugins/trayicon/newmail.offline.xpm;  cvs diff -u -r -1.1 -r -1.2 src/plugins/trayicon/newmail.xpm;  cvs diff -u -r -1.1.2.1 -r -1.1.2.2 src/plugins/trayicon/newmarkedmail.offline.xpm;  cvs diff -u -r -1.1.2.1 -r -1.1.2.2 src/plugins/trayicon/newmarkedmail.xpm;  cvs diff -u -r -1.1.2.1 -r -1.1.2.2 src/plugins/trayicon/nomail.offline.xpm;  cvs diff -u -r -1.1 -r -1.2 src/plugins/trayicon/nomail.xpm;  cvs diff -u -r 1.14.2.59 -r 1.14.2.60 src/plugins/trayicon/trayicon.c;  cvs diff -u -r -1.1.2.1 -r -1.1.2.2 src/plugins/trayicon/unreadmail.offline.xpm;  cvs diff -u -r -1.1 -r -1.2 src/plugins/trayicon/unreadmail.xpm;  cvs diff -u -r -1.1.2.1 -r -1.1.2.2 src/plugins/trayicon/unreadmarkedmail.offline.xpm;  cvs diff -u -r -1.1.2.1 -r -1.1.2.2 src/plugins/trayicon/unreadmarkedmail.xpm;  ) > 3.2.0cvs38.patchset
 ( cvs diff -u -r 1.395.2.348 -r 1.395.2.349 src/summaryview.c;  ) > 3.2.0cvs39.patchset
+( cvs diff -u -r 1.654.2.3235 -r 1.654.2.3236 configure.ac;  cvs diff -u -r 1.155.2.82 -r 1.155.2.83 src/Makefile.am;  cvs diff -u -r 1.179.2.207 -r 1.179.2.208 src/imap.c;  cvs diff -u -r 1.149.2.85 -r 1.149.2.86 src/inc.c;  cvs diff -u -r 1.115.2.180 -r 1.115.2.181 src/main.c;  cvs diff -u -r 1.7.2.15 -r 1.7.2.16 src/main.h;  cvs diff -u -r 1.274.2.228 -r 1.274.2.229 src/mainwindow.c;  cvs diff -u -r 1.4.2.57 -r 1.4.2.58 src/gtk/about.c;  ) > 3.2.0cvs40.patchset
index 0830ab70352eb09ad0961cdf7199d4d6c679f8d6..25e0fcb7cc714d741c0e9b63ec0deec543b2b4d5 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=2
 MICRO_VERSION=0
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=39
+EXTRA_VERSION=40
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
@@ -698,6 +698,44 @@ if test "x$enable_startup_notification" = "xyes"; then
        AC_SUBST(STARTUP_NOTIFICATION_LIBS)
 fi
 
+dnl #######################################################################
+dnl # Check for D-Bus support
+dnl #######################################################################
+PKG_CHECK_MODULES(DBUS, [dbus-1 >= 0.60, dbus-glib-1 >= 0.60],
+[
+       AC_DEFINE(HAVE_DBUS_GLIB, 1, [Define if glib bindings of D-Bus are available])
+       enable_dbus_glib=yes
+],
+[
+       echo "D-Bus requirements not met. D-Bus support not activated."
+       enable_dbus_glib=no
+])
+AC_SUBST(DBUS_CFLAGS)
+AC_SUBST(DBUS_LIBS)
+
+dnl #######################################################################
+dnl # Check for NetworkManager support
+dnl #######################################################################
+if test x"$enable_dbus_glib" = xyes; then
+       AC_ARG_ENABLE(networkmanager-support, [  --disable-networkmanager-support  disable NetworkManager support],,enable_networkmanager_support=yes)
+       if test x"$enable_networkmanager_support" = xyes; then
+               PKG_CHECK_MODULES(NETWORKMANAGER_SUPPORT, NetworkManager >= 0.6.2,
+               [
+                       AC_DEFINE(HAVE_NETWORKMANAGER_SUPPORT, 1, [Define if NetworkManager support is to be included.])
+                       echo "Building with NetworkManager support"
+                       enable_networkmanager_support=yes
+               ],
+               [
+                       echo "NetworkManager not found."
+                       enable_networkmanager_support=no
+               ])
+               AC_SUBST(NETWORKMANAGER_SUPPORT_CFLAGS)
+       fi
+else
+       echo "NetworkManager support deactivated as D-Bus requirements were not met."
+       enable_networkmanager_support=no
+fi
+
 dnl *************************
 dnl ** section for plugins **
 dnl *************************
@@ -1014,6 +1052,7 @@ echo "Crash dialog      : $ac_cv_enable_crash_dialog"
 echo "Libgnomeprint     : $ac_cv_enable_gnomeprint"
 echo "GTK+ print support: $ac_cv_have_gtk210"
 echo "LibSM             : $ac_cv_enable_libsm"
+echo "NetworkManager    : $enable_networkmanager_support"
 echo "Manual            : $ac_cv_enable_manual"
 echo "Plugins           : $PLUGINS"
 echo "Maemo  build      : $ac_cv_enable_maemo"
index 8e10b580f29c3215e2d2cc51a7f36be38537e779..6a79e355793084e4c71a5ad97fe0c2a3539c9676 100644 (file)
@@ -503,7 +503,8 @@ claws_mail_LDADD = \
        $(STARTUP_NOTIFICATION_LIBS) \
        $(LIBETPAN_LIBS) \
        $(MAEMO_LIBS) \
-       $(CONIC_LIBS)
+       $(CONIC_LIBS) \
+       $(DBUS_LIBS)
 
 pixmapdir=$(datadir)/icons/hicolor/48x48/apps
 
@@ -524,8 +525,10 @@ AM_CPPFLAGS = \
        $(LIBETPAN_CPPFLAGS) \
        $(STARTUP_NOTIFICATION_CFLAGS) \
        $(MAEMO_CFLAGS) \
-       $(CONIC_CFLAGS)
-        
+       $(CONIC_CFLAGS) \
+       $(DBUS_CFLAGS) \
+  $(NETWORKMANAGER_SUPPORT_CFLAGS)
+
 #no-unused-function is there because of bison stuff
 #no-deprecated-declarations because of gpgme_data_rewind, which we have
 #to call inside gpgme due to our lack of LARGEFILE support
index 3c87462b6471ee8f8e53b3d632a75d8739753593..80358336962a33925220fdb2acc4b9c3108ac609 100644 (file)
@@ -523,6 +523,16 @@ static GtkWidget *about_create_child_page_features(void)
        gtk_text_buffer_insert(buffer, &iter, 
                (gchar *)Q_("libSM|adds support for session handling\n"), -1);
 
+#if HAVE_NETWORKMANAGER_SUPPORT
+       gtk_text_buffer_insert_pixbuf(buffer, &iter, active_pixbuf);
+#else
+       gtk_text_buffer_insert_pixbuf(buffer, &iter, inactive_pixbuf);
+#endif
+       gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, (" NetworkManager "), -1,
+                                                "bold", NULL);
+       gtk_text_buffer_insert(buffer, &iter,
+               (gchar *)Q_("NetworkManager|adds support for network connection changes\n"), -1);
+
 #if USE_OPENSSL
        gtk_text_buffer_insert_pixbuf(buffer, &iter, active_pixbuf);
 #else
index ff1e5823e927c20b0524a2b23d1d16f32d387c2d..7c7fdbde09537724c6c2250e941fe001ba6b73ac 100644 (file)
@@ -70,6 +70,7 @@
 #include "imap-thread.h"
 #include "account.h"
 #include "tags.h"
+#include "main.h"
 
 typedef struct _IMAPFolder     IMAPFolder;
 typedef struct _IMAPSession    IMAPSession;
@@ -5169,7 +5170,25 @@ void imap_folder_ref(Folder *folder)
 void imap_disconnect_all(void)
 {
        GList *list;
-       imap_main_set_timeout(1);
+       gboolean short_timeout;
+#ifdef HAVE_NETWORKMANAGER_SUPPORT
+       GError *error;
+#endif
+
+#ifdef HAVE_NETWORKMANAGER_SUPPORT
+       error = NULL;
+       short_timeout = !networkmanager_is_online(&error);
+       if(error) {
+               short_timeout = TRUE;
+               g_error_free(error);
+       }
+#else
+       short_timeout = TRUE;
+#endif
+
+       if(short_timeout)
+               imap_main_set_timeout(1);
+
        for (list = account_get_list(); list != NULL; list = list->next) {
                PrefsAccount *account = list->data;
                if (account->protocol == A_IMAP4) {
@@ -5183,7 +5202,9 @@ void imap_disconnect_all(void)
                        }
                }
        }
-       imap_main_set_timeout(prefs_common.io_timeout_secs);
+
+       if(short_timeout)
+               imap_main_set_timeout(prefs_common.io_timeout_secs);
 }
 
 void imap_folder_unref(Folder *folder)
index c87976a4a13ba4f90a5ef0b5cbadad916d5433ce..e03cc0ab45e1ebd08ac02c1a6e8b2ab85cbaf763 100644 (file)
--- a/src/inc.c
+++ b/src/inc.c
@@ -1547,6 +1547,12 @@ gboolean inc_offline_should_override(gboolean force_ask, const gchar *msg)
        int length = 10; /* minutes */
        gint answer = G_ALERTDEFAULT;
 
+#ifdef HAVE_NETWORKMANAGER_SUPPORT
+       /* If no network connection is available, override is not possible */
+       if(!networkmanager_is_online(NULL))
+               return FALSE;
+#endif
+
 #if (defined(MAEMO) && defined(CONIC))
        if (prefs_common.work_offline) {
                if (force_ask && !maemo_warned_offline) {
index 319b0f1c585b9b61df1b45b1dc19a596d77bf401..c00301145372595c4e344f4f07a548e193f3aed3 100644 (file)
 # include <gdk/gdkx.h>
 #endif
 
+#ifdef HAVE_NETWORKMANAGER_SUPPORT
+#include <dbus/dbus-glib.h>
+#include <NetworkManager.h>
+#endif
+
 #include "claws.h"
 #include "main.h"
 #include "mainwindow.h"
@@ -145,6 +150,11 @@ struct _AppData {
 static GnomeVFSVolumeMonitor *volmon;
 #endif
 
+#ifdef HAVE_NETWORKMANAGER_SUPPORT
+/* Went offline due to NetworkManager */
+static gboolean went_offline_nm;
+#endif
+
 gchar *prog_version;
 gchar *argv0;
 
@@ -205,6 +215,11 @@ static void quit_signal_handler         (int sig);
 static void install_basic_sighandlers   (void);
 static void exit_claws                 (MainWindow *mainwin);
 
+#ifdef HAVE_NETWORKMANAGER_SUPPORT
+static void networkmanager_state_change_cb(DBusGProxy *proxy, gchar *dev,
+                                                                                                                                                                        gpointer data);
+#endif
+
 #define MAKE_DIR_IF_NOT_EXIST(dir) \
 { \
        if (!is_dir_exist(dir)) { \
@@ -804,6 +819,11 @@ int main(int argc, char *argv[])
 #ifdef MAEMO
        osso_context_t *osso_context;
        osso_return_t result;
+#endif
+#ifdef HAVE_NETWORKMANAGER_SUPPORT
+       DBusGConnection *connection;
+  GError *error;
+  DBusGProxy *proxy;
 #endif
        gchar *userrc;
        MainWindow *mainwin;
@@ -862,6 +882,9 @@ int main(int argc, char *argv[])
 #if HAVE_LIBSM
        debug_print(" libsm\n");
 #endif
+#if HAVE_NETWORKMANAGER_SUPPORT
+       debug_print(" NetworkManager\n");
+#endif
 #if USE_OPENSSL
        debug_print(" openssl\n");
 #endif
@@ -914,6 +937,29 @@ int main(int argc, char *argv[])
        gtk_set_locale();
        gtk_init(&argc, &argv);
 
+#ifdef HAVE_NETWORKMANAGER_SUPPORT
+       went_offline_nm = FALSE;
+       error = NULL;
+       proxy = NULL;
+  connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
+
+  if(!connection) {
+               debug_print("Failed to open connection to system bus: %s\n", error->message);
+               g_error_free(error);
+       }
+       else {
+               proxy = dbus_g_proxy_new_for_name(connection,
+                                                                                                                                                       "org.freedesktop.NetworkManager",
+                                                                                                                                                       "/org/freedesktop/NetworkManager",
+                                                                                                                                                       "org.freedesktop.NetworkManager");
+               dbus_g_proxy_add_signal(proxy,"StateChange", G_TYPE_UINT, G_TYPE_INVALID);
+               dbus_g_proxy_connect_signal(proxy, "StateChange",
+                                                                                                                               G_CALLBACK(networkmanager_state_change_cb),
+                                                                                                                               NULL,NULL);
+       }
+#endif
+
+
 #ifdef MAEMO
        osso_context = osso_initialize(OSSO_SERVICE, "2.8.1", TRUE, NULL);
        if (osso_context == NULL) {
@@ -1105,6 +1151,11 @@ int main(int argc, char *argv[])
        news_gtk_init();
 
        mainwin = main_window_create();
+
+#ifdef HAVE_NETWORKMANAGER_SUPPORT
+               networkmanager_state_change_cb(proxy,NULL,mainwin);
+#endif
+
 #ifdef MAEMO
        AppData *appdata;
        appdata = g_new0(AppData, 1);
@@ -1146,6 +1197,7 @@ int main(int argc, char *argv[])
                                        mainwin);
 #endif
 
+
        prefs_account_init();
        account_read_config_all();
 
@@ -1342,6 +1394,7 @@ int main(int argc, char *argv[])
 #ifdef HAVE_LIBSM
        sc_session_manager_connect(mainwin);
 #endif
+
        folder_item_update_thaw();
        gtk_clist_thaw(GTK_CLIST(mainwin->folderview->ctree));
        main_window_cursor_normal(mainwin);
@@ -1399,9 +1452,15 @@ int main(int argc, char *argv[])
 
        gtk_main();
 
-       #ifdef MAEMO
+#ifdef MAEMO
        osso_deinitialize(osso_context);
 #endif
+#ifdef HAVE_NETWORKMANAGER_SUPPORT
+       if(proxy)
+               g_object_unref(proxy);
+       if(connection)
+               dbus_g_connection_unref(connection);
+#endif
 #ifdef G_OS_WIN32
        win32_close_log();
 #endif
@@ -1437,6 +1496,11 @@ static void exit_claws(MainWindow *mainwin)
                main_window_empty_trash(mainwin, prefs_common.ask_on_clean);
        }
 
+#ifdef HAVE_NETWORKMANAGER_SUPPORT
+       if (prefs_common.work_offline && went_offline_nm)
+               prefs_common.work_offline = FALSE;
+#endif
+
        /* save prefs for opened folder */
        if(mainwin->folderview->opened) {
                FolderItem *item;
@@ -2166,3 +2230,93 @@ osso_context_t *get_osso_context(void)
        return static_osso_context;
 }
 #endif
+
+
+#ifdef HAVE_NETWORKMANAGER_SUPPORT
+static void networkmanager_state_change_cb(DBusGProxy *proxy, gchar *dev,
+                                                                                                                                                                        gpointer data)
+{
+       MainWindow *mainWin;
+
+       mainWin = NULL;
+       if(static_mainwindow)
+               mainWin = static_mainwindow;
+       else if(data)
+               mainWin = (MainWindow*)data;
+       
+       if(mainWin) {
+               GError *error;
+               gboolean online;
+
+               error = NULL;           
+               online = networkmanager_is_online(&error);
+               if(!error) {
+                       if(online && went_offline_nm) {
+                               went_offline_nm = FALSE;
+                               main_window_toggle_work_offline(mainWin, FALSE, FALSE);
+                               debug_print("NetworkManager: Went online\n");
+                       }
+                       else if(!online) {
+                               went_offline_nm = TRUE;
+                               main_window_toggle_work_offline(mainWin, TRUE, FALSE);
+                               debug_print("NetworkManager: Went offline\n");
+                       }
+               }
+               else {
+                       debug_print("Failed to get online information from NetworkManager: %s\n",
+                                                        error->message);
+                       g_error_free(error);
+               }
+       }
+       else
+               debug_print("NetworkManager: Cannot change connection state because "
+                                                "main window does not exist\n");
+}
+
+/* Returns true (and sets error appropriately, if given) in case of error */
+gboolean networkmanager_is_online(GError **error)
+{
+       DBusGConnection *connection;
+  DBusGProxy *proxy;
+       GError *tmp_error;
+       gboolean retVal;
+       guint32 state;
+
+       tmp_error = NULL;
+       proxy = NULL;
+  connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &tmp_error);
+
+  if(!connection) {
+               /* If calling code doesn't do error checking, at least print some debug */
+               if((error == NULL) || (*error == NULL))
+                       debug_print("Failed to open connection to system bus: %s\n",
+                                                        tmp_error->message);
+               g_propagate_error(error, tmp_error);
+               return TRUE;
+       }
+
+       proxy = dbus_g_proxy_new_for_name(connection,
+                                                                                                                                               "org.freedesktop.NetworkManager",
+                                                                                                                                               "/org/freedesktop/NetworkManager",
+                                                                                                                                               "org.freedesktop.NetworkManager");
+
+       retVal = dbus_g_proxy_call(proxy,"state",&tmp_error,G_TYPE_INVALID,
+                                                                                                                G_TYPE_UINT,&state,G_TYPE_INVALID);
+
+       if(proxy)
+               g_object_unref(proxy);
+       if(connection)
+               dbus_g_connection_unref(connection);
+
+       if(!retVal) {
+               /* If calling code doesn't do error checking, at least print some debug */
+               if((error == NULL) || (*error == NULL))
+                       debug_print("Failed to get state info from NetworkManager: %s\n",
+                                                        tmp_error->message);
+               g_propagate_error(error, tmp_error);
+               return TRUE;
+       }
+
+       return (state == NM_STATE_CONNECTED);
+}
+#endif
index c0909ca6577e829e8f403bc94a1ae3cfa05d9615..4e9526e19d84032bd167fa7ad4d5f641b1e26912 100644 (file)
@@ -46,4 +46,8 @@ gchar *claws_get_socket_name(void);
 void main_set_show_at_startup(gboolean show);
 gboolean claws_crashed(void);
 
+#ifdef HAVE_NETWORKMANAGER_SUPPORT
+gboolean networkmanager_is_online(GError **error);
+#endif
+
 #endif /* __MAIN_H__ */
index cdb7a3622023998fa3af0f24852279bba6ce419d..c82f733035567784f6c3c284fd3542c7abc0ae38 100644 (file)
@@ -3744,6 +3744,13 @@ static void online_switch_clicked (GtkButton *btn, gpointer data)
        MainWindow *mainwin;
        GtkItemFactory *ifactory;
        GtkCheckMenuItem *menuitem;
+       gboolean have_connectivity;
+
+#ifdef HAVE_NETWORKMANAGER
+       have_connectivity = networkmanager_is_online(NULL); 
+#else
+       have_connectivity = TRUE;
+#endif
 
        mainwin = (MainWindow *) data;
        
@@ -3764,7 +3771,9 @@ static void online_switch_clicked (GtkButton *btn, gpointer data)
                /* go offline */
                if (prefs_common.work_offline)
                        return;
-               mainwindow_check_synchronise(mainwin, TRUE);
+
+               if(have_connectivity)
+                       mainwindow_check_synchronise(mainwin, TRUE);
                prefs_common.work_offline = TRUE;
                imap_disconnect_all();
                hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);