2009-02-06 [colin] 3.7.0cvs54
[claws.git] / src / mainwindow.c
index f6243841fb2a0d66c45dd5db0ec5e231f217d7ae..43733dc8840eda95003e096746008be6508b6a92 100644 (file)
@@ -1,6 +1,6 @@
 /*
    Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
-   Copyright (C) 1999-2008 Hiroyuki Yamamoto and the Claws Mail team
+   Copyright (C) 1999-2009 Hiroyuki Yamamoto and the Claws Mail team
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -81,6 +81,9 @@
 #include "imap.h"
 #include "socket.h"
 #include "printing.h"
+#ifdef G_OS_WIN32
+#include "w32lib.h"
+#endif
 
 #define AC_LABEL_WIDTH 240
 
@@ -187,6 +190,8 @@ static void view_source_cb          (GtkAction      *action,
 
 static void show_all_header_cb         (GtkAction      *action,
                                  gpointer       data);
+static void toggle_fullscreen_cb       (GtkAction      *action,
+                                 gpointer       data);
 
 static void hide_quotes_cb(GtkAction   *action,
                                  gpointer       data);
@@ -340,7 +345,7 @@ static void prefs_post_processing_open_cb (GtkAction        *action,
 
 static void prefs_filtering_open_cb    (GtkAction      *action,
                                  gpointer       data);
-#if (defined(USE_OPENSSL) || defined (USE_GNUTLS))
+#ifdef USE_GNUTLS
 static void ssl_manager_open_cb        (GtkAction      *action,
                                  gpointer       data);
 #endif
@@ -371,6 +376,11 @@ static void manual_faq_open_cb      (GtkAction     *action,
 static void legend_open_cb      (GtkAction     *action,
                                  gpointer       data);
 
+#ifdef G_OS_WIN32
+static void set_default_client_cb (GtkAction   *action,
+                                 gpointer       data);
+#endif
+
 static void scan_tree_func      (Folder        *folder,
                                  FolderItem    *item,
                                  gpointer       data);
@@ -619,7 +629,7 @@ static GtkActionEntry mainwin_entries[] =
        {"Message/CancelNews",                  NULL, N_("Cancel a news message"), NULL, NULL, G_CALLBACK(cancel_cb) },
        /*{"Message/---",                       NULL, "---" },*/
        
-       {"Message/Mark",                        NULL, "_Mark" },
+       {"Message/Mark",                        NULL, N_("_Mark") },
        {"Message/Mark/Mark",                   NULL, N_("_Mark"), "<shift>asterisk", NULL, G_CALLBACK(mark_cb) },
        {"Message/Mark/Unmark",                 NULL, N_("_Unmark"), "U", NULL, G_CALLBACK(unmark_cb) },
        {"Message/Mark/---",                    NULL, "---", NULL, NULL, NULL },
@@ -687,7 +697,7 @@ static GtkActionEntry mainwin_entries[] =
        /* {"Tools/---",                        NULL, "---", NULL, NULL, NULL }, */
 
        {"Tools/Execute",                       NULL, N_("E_xecute"), "X", NULL, G_CALLBACK(execute_summary_cb) }, 
-#if (defined(USE_OPENSSL) || defined (USE_GNUTLS))
+#ifdef USE_GNUTLS
        /* {"Tools/---",                        NULL, "---", NULL, NULL, NULL }, */
        {"Tools/SSLCertificates",               NULL, N_("SSL cer_tificates"), NULL, NULL, G_CALLBACK(ssl_manager_open_cb) }, 
 #endif
@@ -721,6 +731,9 @@ static GtkActionEntry mainwin_entries[] =
        {"Help/Manual",                         NULL, N_("_Manual"), NULL, NULL, G_CALLBACK(manual_open_cb) }, 
        {"Help/FAQ",                            NULL, N_("_Online User-contributed FAQ"), NULL, NULL, G_CALLBACK(manual_faq_open_cb) }, 
        {"Help/IconLegend",                     NULL, N_("Icon _Legend"), NULL, NULL, G_CALLBACK(legend_open_cb) }, 
+#ifdef G_OS_WIN32
+       {"Help/SetDefault",                     NULL, N_("Set as default client"), NULL, NULL, G_CALLBACK(set_default_client_cb) }, 
+#endif
        {"Help/---",                            NULL, "---" }, 
        {"Help/About",                          NULL, N_("_About"), NULL, NULL, G_CALLBACK(about_cb) }, 
 };
@@ -734,6 +747,9 @@ static GtkToggleActionEntry mainwin_toggle_entries[] = {
        {"View/ShowHide/ColumnHeaders",         NULL, N_("Column headers"), NULL, NULL, G_CALLBACK(toggle_col_headers_cb) }, /* toggle */
        {"View/ThreadView",                     NULL, N_("Th_read view"), "<control>T", NULL, G_CALLBACK(thread_cb) }, /* toggle */
        {"View/HideReadMessages",               NULL, N_("_Hide read messages"), NULL, NULL, G_CALLBACK(hide_read_messages) }, /* toggle */
+#ifndef MAEMO
+       {"View/FullScreen",                     NULL, N_("_Fullscreen"), "F11", NULL, G_CALLBACK(toggle_fullscreen_cb) }, /* toggle */
+#endif
        {"View/AllHeaders",                     NULL, N_("Show all _headers"), "<control>H", NULL, G_CALLBACK(show_all_header_cb) }, /* toggle */
        {"View/Quotes/FoldAll",                 NULL, N_("_Fold all"), "<control><shift>Q", NULL, G_CALLBACK(hide_quotes_cb) }, /* 1 toggle */
        {"View/Quotes/Fold2",                   NULL, N_("Fold from level _2"), NULL, NULL, G_CALLBACK(hide_quotes_cb) }, /* 2 toggle */
@@ -1038,6 +1054,33 @@ static void mainwindow_tags_menu_item_activate_cb(GtkWidget *widget,
        summary_set_tag(mainwin->summaryview, id, NULL);
 }
 
+void mainwin_accel_changed_cb (GtkAccelGroup *accelgroup, guint keyval, GdkModifierType modifier,
+                                 GClosure *closure, GtkMenuItem *item)
+{
+       GList *closures = gtk_widget_list_accel_closures(GTK_WIDGET(item));
+       GList *cur;
+       for (cur = closures; cur; cur = cur->next) {
+               if (closure == cur->data) {
+                       GtkLabel *label = g_object_get_data(G_OBJECT(item), "accel_label");
+                       gchar *new_accel;
+                       
+                       if (keyval == GDK_BackSpace) {
+                               const gchar *accel_path;
+#if GTK_CHECK_VERSION(2,14,0)
+                               accel_path = gtk_menu_item_get_accel_path(item);
+#else
+                               accel_path = GTK_MENU_ITEM(item)->accel_path;
+#endif
+                               keyval = 0; modifier = 0;
+                               gtk_accel_map_change_entry (accel_path, keyval, modifier, TRUE);
+                       }
+                       new_accel = gtk_accelerator_get_label(keyval, modifier);
+                       gtk_label_set_text(label, new_accel);
+                       g_free(new_accel);
+               }
+       }
+}
+
 static void mainwindow_colorlabel_menu_create(MainWindow *mainwin, gboolean refresh)
 {
        GtkWidget *label_menuitem;
@@ -1089,11 +1132,15 @@ static void mainwindow_colorlabel_menu_create(MainWindow *mainwin, gboolean refr
                g_object_set_data(G_OBJECT(item), "mainwin",
                                  mainwin);
                gtk_widget_show(item);
-               accel_path = g_strdup_printf("<ClawsColorLabels>/%d", i);
+               accel_path = g_strdup_printf("<ClawsColorLabels>/%d", i+1);
                gtk_menu_item_set_accel_path(GTK_MENU_ITEM(item), accel_path);
                if (i < 9)
                        gtk_accel_map_add_entry(accel_path, GDK_1+i, GDK_CONTROL_MASK);
                g_free(accel_path);
+               g_signal_connect (gtk_ui_manager_get_accel_group(mainwin->ui_manager), 
+                       "accel-changed", G_CALLBACK (mainwin_accel_changed_cb), item);
+
+
        }
        gtk_widget_show(menu);
        gtk_menu_item_set_submenu(GTK_MENU_ITEM(label_menuitem), menu);
@@ -1265,9 +1312,13 @@ static gboolean mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
 
        switch (event->keyval) {
        case GDK_Q:             /* Quit */
+#ifndef MAEMO
                BREAK_ON_MODIFIER_KEY();
 
-               app_exit_cb(NULL, mainwin);
+               if (gtk_window_is_active(GTK_WINDOW(mainwin->window))) {
+                       app_exit_cb(NULL, mainwin);
+               }
+#endif
                return FALSE;
        case GDK_space:
                BREAK_ON_MODIFIER_KEY();
@@ -1283,18 +1334,6 @@ static gboolean mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
                        }
                }
                break;
-#ifndef MAEMO
-        case GDK_F11:
-                if (mainwin->fullscreen) {
-                    gtk_window_unfullscreen(GTK_WINDOW(mainwin->window));
-                    mainwin->fullscreen = FALSE;
-                }
-                else {
-                    gtk_window_fullscreen(GTK_WINDOW(mainwin->window));
-                    mainwin->fullscreen = TRUE;
-                }
-                break;
-#endif
 
 #ifdef MAEMO
        case GDK_F6:
@@ -1619,6 +1658,9 @@ MainWindow *main_window_create()
        MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/SetColumns", "Messagelist", "View/SetColumns/Messagelist", GTK_UI_MANAGER_MENUITEM)
        MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "Separator1", "View/---", GTK_UI_MANAGER_SEPARATOR)
 
+#ifndef MAEMO
+       MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "FullScreen", "View/FullScreen", GTK_UI_MANAGER_MENUITEM)
+#endif
 #ifndef GENERIC_UMPC
        MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "Layout", "View/Layout", GTK_UI_MANAGER_MENU)
        MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Layout", "Standard", "View/Layout/Standard", GTK_UI_MANAGER_MENUITEM)
@@ -1862,7 +1904,7 @@ MainWindow *main_window_create()
        MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "Separator5", "Tools/---", GTK_UI_MANAGER_SEPARATOR)
 
        MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "Execute", "Tools/Execute", GTK_UI_MANAGER_MENUITEM)
-#if (defined(USE_OPENSSL) || defined (USE_GNUTLS))
+#ifdef USE_GNUTLS
        MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "Separator6", "Tools/---", GTK_UI_MANAGER_SEPARATOR)
        MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "SSLCertificates", "Tools/SSLCertificates", GTK_UI_MANAGER_MENUITEM)
 #endif
@@ -1898,7 +1940,11 @@ MainWindow *main_window_create()
        MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Help", "Manual", "Help/Manual", GTK_UI_MANAGER_MENUITEM)
        MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Help", "FAQ", "Help/FAQ", GTK_UI_MANAGER_MENUITEM)
        MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Help", "IconLegend", "Help/IconLegend", GTK_UI_MANAGER_MENUITEM)
+#ifdef G_OS_WIN32
        MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Help", "Separator1", "Help/---", GTK_UI_MANAGER_SEPARATOR)
+       MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Help", "SetDefault", "Help/SetDefault", GTK_UI_MANAGER_MENUITEM)
+#endif
+       MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Help", "Separator2", "Help/---", GTK_UI_MANAGER_SEPARATOR)
        MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Help", "About", "Help/About", GTK_UI_MANAGER_MENUITEM)
 
 
@@ -1912,7 +1958,6 @@ MainWindow *main_window_create()
        hildon_window_set_menu(HILDON_WINDOW(window), GTK_MENU(menubar));
 #endif
 
-
        if (prefs_common.toolbar_detachable) {
                handlebox = gtk_handle_box_new();
                gtk_widget_show(handlebox);
@@ -2028,7 +2073,7 @@ MainWindow *main_window_create()
 #endif
        /* create views */
        mainwin->folderview  = folderview  = folderview_create();
-       mainwin->summaryview = summaryview = summary_create();
+       mainwin->summaryview = summaryview = summary_create(mainwin);
        mainwin->messageview = messageview = messageview_create(mainwin);
 
        /* init log instances data before creating log views */
@@ -2201,8 +2246,6 @@ MainWindow *main_window_create()
 
        ADD_MENU_ACCEL_GROUP_TO_WINDOW(summaryview->popupmenu, mainwin->window);
        
-/* FIXME       menu_connect_identical_items(); */
-
 #ifndef GENERIC_UMPC
        gtk_window_iconify(GTK_WINDOW(mainwin->window));
 #endif
@@ -2225,7 +2268,7 @@ MainWindow *main_window_create()
        folderview_init(folderview);
        summary_init(summaryview);
        messageview_init(messageview);
-#if (defined(USE_OPENSSL) || defined (USE_GNUTLS))
+#ifdef USE_GNUTLS
        sslcertwindow_register_hook();
 #endif
        mainwin->lock_count = 0;
@@ -2250,8 +2293,13 @@ MainWindow *main_window_create()
 #ifdef MAEMO
        main_window_install_maemo_hooks(mainwin);
 #endif
-        mainwin->fullscreen = FALSE;
-
+#ifndef MAEMO
+       if (prefs_common.mainwin_fullscreen) {
+               cm_toggle_menu_set_active_full(mainwin->ui_manager, 
+                       "Menu/View/FullScreen",
+                       TRUE);
+       }
+#endif
        return mainwin;
 }
 
@@ -2349,6 +2397,8 @@ static gboolean reflect_prefs_timeout_cb(gpointer data)
                        compose_reflect_prefs_pixmap_theme();
                        folderview_reflect_prefs_pixmap_theme(mainwin->folderview);
                        summary_reflect_prefs_pixmap_theme(mainwin->summaryview);
+                       foldersel_reflect_prefs_pixmap_theme();
+                       addressbook_reflect_prefs_pixmap_theme();
 #ifndef GENERIC_UMPC
                        pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_ONLINE);
                        gtk_container_remove(GTK_CONTAINER(mainwin->online_switch), 
@@ -2403,6 +2453,10 @@ void main_window_reflect_prefs_custom_colors(MainWindow *mainwin)
 
        /* clear items. get item pointers. */
        for (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
+               g_signal_handlers_disconnect_matched
+                        (gtk_ui_manager_get_accel_group(mainwin->ui_manager), 
+                        G_SIGNAL_MATCH_DATA|G_SIGNAL_MATCH_FUNC,
+                        0, 0, NULL, mainwin_accel_changed_cb, cur->data);
                gtk_menu_item_set_submenu(GTK_MENU_ITEM(cur->data), NULL);
        }
        mainwindow_colorlabel_menu_create(mainwin, TRUE);
@@ -2829,11 +2883,11 @@ void main_window_get_size(MainWindow *mainwin)
 
        allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
        
-       if (mainwin->fullscreen) {
+       if (prefs_common.mainwin_fullscreen) {
                debug_print("mainwin in full screen state. "
                            "Keeping original settings\n");
        }
-       if (allocation->width > 1 && allocation->height > 1 && !mainwin->fullscreen) {
+       if (allocation->width > 1 && allocation->height > 1 && !prefs_common.mainwin_fullscreen) {
                prefs_common.summaryview_width = allocation->width;
 
                if (messageview_is_visible(mainwin->messageview))
@@ -2844,7 +2898,7 @@ void main_window_get_size(MainWindow *mainwin)
 
        allocation = &mainwin->window->allocation;
        if (allocation->width > 1 && allocation->height > 1 &&
-           !prefs_common.mainwin_maximised && !mainwin->fullscreen) {
+           !prefs_common.mainwin_maximised && !prefs_common.mainwin_fullscreen) {
                prefs_common.mainview_height = allocation->height;
                prefs_common.mainwin_width   = allocation->width;
                prefs_common.mainwin_height  = allocation->height;
@@ -2852,14 +2906,14 @@ void main_window_get_size(MainWindow *mainwin)
 
        allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
        if (allocation->width > 1 && allocation->height > 1 &&
-           !mainwin->fullscreen) {
+           !prefs_common.mainwin_fullscreen) {
                prefs_common.folderview_width  = allocation->width;
                prefs_common.folderview_height = allocation->height;
        }
 
        allocation = &(GTK_WIDGET_PTR(mainwin->messageview)->allocation);
        if (allocation->width > 1 && allocation->height > 1 &&
-           !mainwin->fullscreen) {
+           !prefs_common.mainwin_fullscreen) {
                prefs_common.msgview_width = allocation->width;
                prefs_common.msgview_height = allocation->height;
        }
@@ -2879,7 +2933,7 @@ void main_window_get_position(MainWindow *mainwin)
 {
        gint x, y;
 
-       if (prefs_common.mainwin_maximised || mainwin->fullscreen)
+       if (prefs_common.mainwin_maximised || prefs_common.mainwin_fullscreen)
                return;
 
        gtkut_widget_get_uposition(mainwin->window, &x, &y);
@@ -3459,10 +3513,19 @@ static void get_url_part (const gchar **buffer, gchar *url_decoded, gint maxlen)
 static void mailing_list_compose (GtkWidget *w, gpointer *data)
 {
        const gchar *mailto;
+       PrefsAccount *account = NULL;
+       FolderItem   *folder_item = NULL;
 
        mailto = gtk_label_get_text(GTK_LABEL (gtk_bin_get_child(GTK_BIN((w)))));
+       if (mainwindow_get_mainwindow()) {
+               folder_item = mainwindow_get_mainwindow()->summaryview->folder_item;
+               if (folder_item && folder_item->prefs && folder_item->prefs->enable_default_account)
+                       account = account_find_from_id(folder_item->prefs->default_account);
+               if (folder_item && !account)
+                       account = account_find_from_item(folder_item);
+       }
        if (mailto)
-               compose_new(NULL, mailto+7, NULL);
+               compose_new_with_folderitem(account, folder_item, mailto+7);
 }
  
  static void mailing_list_open_uri (GtkWidget *w, gpointer *data)
@@ -4134,7 +4197,7 @@ static void online_switch_clicked (GtkButton *btn, gpointer data)
        MainWindow *mainwin;
        gboolean have_connectivity;
 
-#ifdef HAVE_NETWORKMANAGER
+#ifdef HAVE_NETWORKMANAGER_SUPPORT
        have_connectivity = networkmanager_is_online(NULL); 
 #else
        have_connectivity = TRUE;
@@ -4160,7 +4223,8 @@ static void online_switch_clicked (GtkButton *btn, gpointer data)
                if(have_connectivity)
                        mainwindow_check_synchronise(mainwin, TRUE);
                prefs_common.work_offline = TRUE;
-               imap_disconnect_all();
+               if(have_connectivity)
+                       imap_disconnect_all();
                hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);
        } else {
                /*go online */
@@ -4253,6 +4317,20 @@ static void show_all_header_cb(GtkAction *action, gpointer data)
                                     gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
 }
 
+static void toggle_fullscreen_cb(GtkAction *action, gpointer data)
+{
+       MainWindow *mainwin = (MainWindow *)data;
+       if (mainwin->menu_lock_count) return;
+       if (!gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
+               gtk_window_unfullscreen(GTK_WINDOW(mainwin->window));
+               prefs_common.mainwin_fullscreen = FALSE;
+       }
+       else {
+               prefs_common.mainwin_fullscreen = TRUE;
+               gtk_window_fullscreen(GTK_WINDOW(mainwin->window));
+       }
+}
+
 static void hide_quotes_cb(GtkAction *action, gpointer data)
 {
        MainWindow *mainwin = (MainWindow *)data;
@@ -4777,7 +4855,7 @@ static void prefs_tags_open_cb(GtkAction *action, gpointer data)
        GSList * list = summary_get_selected_msg_list(mainwin->summaryview);
        tag_apply_open(list);
 }
-#if (defined(USE_OPENSSL) || defined (USE_GNUTLS))
+#ifdef USE_GNUTLS
 static void ssl_manager_open_cb(GtkAction *action, gpointer data)
 {
        MainWindow *mainwin = (MainWindow *)data;
@@ -4861,6 +4939,78 @@ static void legend_open_cb(GtkAction *action, gpointer data)
        legend_show();
 }
 
+#ifdef G_OS_WIN32
+static void set_default_client_cb(GtkAction *action, gpointer data)
+{
+       char exename[MAX_PATH];
+       gchar *binary_icon = NULL;
+       gchar *binary_compose = NULL;
+       gchar *binary_run = NULL;
+       int r = 0;
+       if ( !GetModuleFileNameA (0, exename, sizeof (exename)) ) {
+               alertpanel_error(_("Can not register as default client: impossible to get executable path."));
+               return;
+       }
+       binary_icon = g_strconcat(exename, ",0", NULL);
+       binary_compose = g_strconcat(exename, " --compose %1", NULL);
+       binary_run = g_strconcat(exename, NULL);
+
+       /* Try to set the Mail Start menu item to Claws. It may fail if we're not root; we don't care */
+       r = write_w32_registry_string("HKLM", "Software\\Clients\\Mail", 
+                       "", "Claws Mail");
+       
+       r = write_w32_registry_string("HKCU", "Software\\Clients\\Mail\\Claws Mail", 
+                               "", "Claws Mail");
+       if (!r)
+               r = write_w32_registry_string("HKCU", "Software\\Clients\\Mail\\Claws Mail", 
+                               "DLLPath", "");
+       if (!r)
+               r = write_w32_registry_string("HKCU", "Software\\Clients\\Mail\\Claws Mail\\Protocols\\mailto", 
+                               "", "URL:MailTo-Protocol");
+       if (!r)
+               r = write_w32_registry_string("HKCU", "Software\\Clients\\Mail\\Claws Mail\\Protocols\\mailto", 
+                               "URL Protocol", "");
+       if (!r)
+               r = write_w32_registry_dword ("HKCU", "Software\\Clients\\Mail\\Claws Mail\\Protocols\\mailto", 
+                               "EditFlags", 2);
+       if (!r)
+               r = write_w32_registry_string("HKCU", "Software\\Clients\\Mail\\Claws Mail\\Protocols\\mailto\\DefaultIcon", 
+                               "", binary_icon);
+       if (!r)
+               r = write_w32_registry_string("HKCU", "Software\\Clients\\Mail\\Claws Mail\\Protocols\\mailto\\shell\\open\\command", 
+                               "", binary_compose);
+       if (!r)
+               r = write_w32_registry_string("HKCU", "Software\\Clients\\Mail\\Claws Mail\\shell\\open\\command", 
+                               "", binary_run);
+       
+       if (!r)
+               r = write_w32_registry_string("HKCU", "Software\\Classes\\mailto", 
+                               "", "URL:MailTo-Protocol");
+       if (!r)
+               r = write_w32_registry_string("HKCU", "Software\\Classes\\mailto", 
+                               "URL Protocol", "");
+       if (!r)
+               r = write_w32_registry_dword ("HKCU", "Software\\Classes\\mailto", 
+                               "EditFlags", 2);
+       if (!r)
+               r = write_w32_registry_string("HKCU", "Software\\Classes\\mailto\\DefaultIcon", 
+                               "", binary_icon);
+       if (!r)
+               r = write_w32_registry_string("HKCU", "Software\\Classes\\mailto\\shell\\open\\command", 
+                               "", binary_compose);
+       
+       if (!r) {
+               SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)"Software\\Clients\\Mail");
+               alertpanel_notice(_("Claws Mail has been registered as default client."));
+       } else {
+               alertpanel_error(_("Can not register as default client: impossible to write to the registry."));
+       }
+       g_free(binary_icon);
+       g_free(binary_compose);
+       g_free(binary_run);
+}
+#endif
+
 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
 {
        MainWindow *mainwin = (MainWindow *)data;