2008-06-09 [colin] 3.4.0cvs85
authorColin Leroy <colin@colino.net>
Mon, 9 Jun 2008 16:49:02 +0000 (16:49 +0000)
committerColin Leroy <colin@colino.net>
Mon, 9 Jun 2008 16:49:02 +0000 (16:49 +0000)
* src/main.c
Integrate AWN information bubble if dbus is
available
* src/folder.c
Fix crash when calling scan_required() on
folder classes that don't implement them
* src/common/session.c
Fix a little typo

ChangeLog
PATCHSETS
configure.ac
src/common/session.c
src/folder.c
src/main.c

index 64c75fe..b1bc6d6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2008-06-09 [colin]     3.4.0cvs85
+
+       * src/main.c
+               Integrate AWN information bubble if dbus is
+               available
+       * src/folder.c
+               Fix crash when calling scan_required() on 
+               folder classes that don't implement them
+       * src/common/session.c
+               Fix a little typo
+
 2008-06-09 [colin]     3.4.0cvs84
 
        * src/main.c
index c5b6ec9..dfa4f54 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.94.2.179 -r 1.94.2.180 src/messageview.c;  ) > 3.4.0cvs82.patchset
 ( cvs diff -u -r 1.60.2.44 -r 1.60.2.45 src/filtering.c;  ) > 3.4.0cvs83.patchset
 ( cvs diff -u -r 1.115.2.196 -r 1.115.2.197 src/main.c;  ) > 3.4.0cvs84.patchset
+( cvs diff -u -r 1.115.2.197 -r 1.115.2.198 src/main.c;  cvs diff -u -r 1.213.2.182 -r 1.213.2.183 src/folder.c;  cvs diff -u -r 1.23.2.16 -r 1.23.2.17 src/common/session.c;  ) > 3.4.0cvs85.patchset
index 07ea96f..4ad930d 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=4
 MICRO_VERSION=0
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=84
+EXTRA_VERSION=85
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index 5bc0098..8391ba0 100644 (file)
@@ -348,7 +348,7 @@ gint session_start_tls(Session *session)
        if (!ssl_init_socket_with_method(session->sock, SSL_METHOD_TLSv1)) {
                g_warning("couldn't start TLS session.\n");
                if (nb_mode)
-                       sock_set_nonblocking_mode(session->sock, TRUE);
+                       sock_set_nonblocking_mode(session->sock, session->nonblocking);
                return -1;
        }
 
index 68d8b3f..94275ef 100644 (file)
@@ -2587,7 +2587,10 @@ void folder_item_write_cache(FolderItem *item)
                return;
 
        last_mtime = item->mtime;
-       need_scan = item->folder->klass->scan_required(item->folder, item);
+       if (item->folder->klass->scan_required)
+               need_scan = item->folder->klass->scan_required(item->folder, item);
+       else
+               need_scan = TRUE;
 
        id = folder_item_get_identifier(item);
        debug_print("Save cache for folder %s\n", id);
index 8885ad2..2bc773e 100644 (file)
@@ -57,8 +57,10 @@ GCRY_THREAD_OPTION_PTHREAD_IMPL;
 # include <gdk/gdkx.h>
 #endif
 
-#ifdef HAVE_NETWORKMANAGER_SUPPORT
+#ifdef HAVE_DBUS_GLIB
 #include <dbus/dbus-glib.h>
+#endif
+#ifdef HAVE_NETWORKMANAGER_SUPPORT
 #include <NetworkManager.h>
 #endif
 
@@ -109,6 +111,7 @@ GCRY_THREAD_OPTION_PTHREAD_IMPL;
 #include "news_gtk.h"
 #include "matcher.h"
 #include "tags.h"
+#include "hooks.h"
 
 #ifdef HAVE_LIBETPAN
 #include "imap-thread.h"
@@ -162,6 +165,10 @@ static GnomeVFSVolumeMonitor *volmon;
 static gboolean went_offline_nm;
 #endif
 
+#ifdef HAVE_DBUS_GLIB
+static DBusGProxy *awn_proxy = NULL;
+#endif
+
 gchar *prog_version;
 gchar *argv0;
 
@@ -916,16 +923,118 @@ static void main_dump_features_list(gboolean show_debug_only)
 #endif
 }
 
+#ifdef HAVE_DBUS_GLIB
+static guint dbus_item_hook_id = -1;
+static guint dbus_folder_hook_id = -1;
+
+static void uninstall_dbus_status_handler(void)
+{
+       if(awn_proxy)
+               g_object_unref(awn_proxy);
+       awn_proxy = NULL;
+       if (dbus_item_hook_id != -1)
+               hooks_unregister_hook(FOLDER_ITEM_UPDATE_HOOKLIST, dbus_item_hook_id);
+       if (dbus_folder_hook_id != -1)
+               hooks_unregister_hook(FOLDER_UPDATE_HOOKLIST, dbus_folder_hook_id);
+}
+
+static void dbus_update(FolderItem *removed_item)
+{
+       guint new, unread, unreadmarked, marked, total;
+       guint replied, forwarded, locked, ignored, watched;
+       gchar *buf;
+       GError *error = NULL;
+
+       folder_count_total_msgs(&new, &unread, &unreadmarked, &marked, &total,
+                               &replied, &forwarded, &locked, &ignored,
+                               &watched);
+       if (removed_item) {
+               total -= removed_item->total_msgs;
+               new -= removed_item->new_msgs;
+               unread -= removed_item->unread_msgs;
+       }
+
+       if (new > 0) {
+               buf = g_strdup_printf("%d", new);
+               dbus_g_proxy_call(awn_proxy, "SetInfoByName", &error,
+                       G_TYPE_STRING, "claws-mail",
+                       G_TYPE_STRING, buf,
+                       G_TYPE_INVALID, G_TYPE_INVALID);
+               g_free(buf);
+               
+       } else {
+               dbus_g_proxy_call(awn_proxy, "UnsetInfoByName", &error, G_TYPE_STRING,
+                       "claws-mail", G_TYPE_INVALID, G_TYPE_INVALID);
+       }
+       if (error) {
+               debug_print(error->message);
+               g_error_free(error);
+       }
+}
+
+static gboolean dbus_status_update_folder_hook(gpointer source, gpointer data)
+{
+       FolderUpdateData *hookdata;
+       hookdata = source;
+       if (hookdata->update_flags & FOLDER_REMOVE_FOLDERITEM)
+               dbus_update(hookdata->item);
+       else
+               dbus_update(NULL);
+
+       return FALSE;
+}
+
+static gboolean dbus_status_update_item_hook(gpointer source, gpointer data)
+{
+       dbus_update(NULL);
+
+       return FALSE;
+}
+
+static void install_dbus_status_handler(void)
+{
+       GError *tmp_error = NULL;
+       DBusGConnection *connection = dbus_g_bus_get(DBUS_BUS_SESSION, &tmp_error);
+       
+       if(!connection) {
+               /* If calling code doesn't do error checking, at least print some debug */
+               debug_print("Failed to open connection to session bus: %s\n",
+                                tmp_error->message);
+               g_error_free(tmp_error);
+               return;
+       }
+       awn_proxy = dbus_g_proxy_new_for_name(connection,
+                       "com.google.code.Awn",
+                       "/com/google/code/Awn",
+                       "com.google.code.Awn");
+       dbus_item_hook_id = hooks_register_hook (FOLDER_ITEM_UPDATE_HOOKLIST, dbus_status_update_item_hook, NULL);
+       if (dbus_item_hook_id == -1) {
+               g_warning(_("Failed to register folder item update hook"));
+               uninstall_dbus_status_handler();
+               return;
+       }
+
+       dbus_folder_hook_id = hooks_register_hook (FOLDER_UPDATE_HOOKLIST, dbus_status_update_folder_hook, NULL);
+       if (dbus_folder_hook_id == -1) {
+               g_warning(_("Failed to register folder update hook"));
+               uninstall_dbus_status_handler();
+               return;
+       }
+}
+#endif
+
 int main(int argc, char *argv[])
 {
 #ifdef MAEMO
        osso_context_t *osso_context;
        osso_return_t result;
 #endif
-#ifdef HAVE_NETWORKMANAGER_SUPPORT
+#ifdef HAVE_DBUS_GLIB
        DBusGConnection *connection;
-  GError *error;
-  DBusGProxy *proxy;
+       GError *error;
+#endif
+#ifdef HAVE_NETWORKMANAGER_SUPPORT
+       DBusGProxy *nm_proxy;
 #endif
        gchar *userrc;
        MainWindow *mainwin;
@@ -1005,23 +1114,30 @@ int main(int argc, char *argv[])
 
 #ifdef HAVE_NETWORKMANAGER_SUPPORT
        went_offline_nm = FALSE;
+       nm_proxy = NULL;
+#endif
+#ifdef HAVE_DBUS_GLIB
        error = NULL;
-       proxy = NULL;
-  connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
+       connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
 
-  if(!connection) {
+       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);
+#ifdef HAVE_NETWORKMANAGER_SUPPORT
+               nm_proxy = dbus_g_proxy_new_for_name(connection,
+                       "org.freedesktop.NetworkManager",
+                       "/org/freedesktop/NetworkManager",
+                       "org.freedesktop.NetworkManager");
+               if (nm_proxy) {
+                       dbus_g_proxy_add_signal(nm_proxy, "StateChange", G_TYPE_UINT, G_TYPE_INVALID);
+                       dbus_g_proxy_connect_signal(nm_proxy, "StateChange",
+                               G_CALLBACK(networkmanager_state_change_cb),
+                               NULL,NULL);
+               }
+#endif
+               install_dbus_status_handler();
        }
 #endif
 
@@ -1210,7 +1326,7 @@ int main(int argc, char *argv[])
        mainwin = main_window_create();
 
 #ifdef HAVE_NETWORKMANAGER_SUPPORT
-               networkmanager_state_change_cb(proxy,NULL,mainwin);
+       networkmanager_state_change_cb(nm_proxy,NULL,mainwin);
 #endif
 
 #ifdef MAEMO
@@ -1516,8 +1632,11 @@ int main(int argc, char *argv[])
        osso_deinitialize(osso_context);
 #endif
 #ifdef HAVE_NETWORKMANAGER_SUPPORT
-       if(proxy)
-               g_object_unref(proxy);
+       if(nm_proxy)
+               g_object_unref(nm_proxy);
+#endif
+#ifdef HAVE_DBUS_GLIB
+       uninstall_dbus_status_handler();
        if(connection)
                dbus_g_connection_unref(connection);
 #endif
@@ -1778,7 +1897,7 @@ static void parse_cmd_opt(int argc, char *argv[])
                        cmd.target = argv[i+1];
                } else if (i == 1 && argc == 2) {
                        /* only one parameter. Do something intelligent about it */
-                       if (strstr(argv[i], "@") && !strstr(argv[i], "://")) {
+                       if ((strstr(argv[i], "@")||!strncmp(argv[i], "mailto:", 7)) && !strstr(argv[i], "://")) {
                                const gchar *p = argv[i];
 
                                cmd.compose = TRUE;
@@ -2407,7 +2526,7 @@ gboolean networkmanager_is_online(GError **error)
 {
        DBusGConnection *connection;
        DBusGProxy *proxy;
-       GError *tmp_error;
+       GError *tmp_error = NULL;
        gboolean retVal;
        guint32 state;