ManageSieve: save manager window size (bug #2923)
authorCharles Lehner <cel@celehner.com>
Thu, 16 Jul 2015 01:47:45 +0000 (21:47 -0400)
committerCharles Lehner <cel@celehner.com>
Thu, 16 Jul 2015 02:19:38 +0000 (22:19 -0400)
src/plugins/managesieve/sieve_manager.c
src/plugins/managesieve/sieve_plugin.c
src/plugins/managesieve/sieve_prefs.c
src/plugins/managesieve/sieve_prefs.h

index d917eef..a97e2a9 100644 (file)
@@ -547,6 +547,14 @@ static gboolean manager_key_pressed(GtkWidget *widget, GdkEventKey *event,
        return FALSE;
 }
 
+static void size_allocate_cb(GtkWidget *widget, GtkAllocation *allocation)
+{
+       cm_return_if_fail(allocation != NULL);
+
+       sieve_config.manager_win_width = allocation->width;
+       sieve_config.manager_win_height = allocation->height;
+}
+
 static void got_session_error(SieveSession *session, const gchar *msg,
                SieveManagerPage *page)
 {
@@ -640,6 +648,8 @@ static SieveManagerPage *sieve_manager_page_new()
        SieveAccountConfig *config;
        PrefsAccount *default_account = NULL;
 
+       static GdkGeometry geometry;
+
        page = g_new0(SieveManagerPage, 1);
 
        /* Manage Window */
@@ -647,10 +657,24 @@ static SieveManagerPage *sieve_manager_page_new()
        window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "sievemanager");
        gtk_container_set_border_width (GTK_CONTAINER (window), 8);
        gtk_window_set_title (GTK_WINDOW (window), _("Manage Sieve Filters"));
-       gtk_widget_set_size_request (window, 480, 296);
        MANAGE_WINDOW_SIGNALS_CONNECT (window);
+
        g_signal_connect (G_OBJECT (window), "key_press_event",
                        G_CALLBACK (manager_key_pressed), page);
+       g_signal_connect (G_OBJECT(window), "size_allocate",
+                        G_CALLBACK (size_allocate_cb), NULL);
+
+       if (!geometry.min_height) {
+               geometry.min_width = 350;
+               geometry.min_height = 300;
+       }
+
+       gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
+                                     GDK_HINT_MIN_SIZE);
+       gtk_widget_set_size_request(window, sieve_config.manager_win_width,
+                       sieve_config.manager_win_height);
+       gtk_window_set_type_hint(GTK_WINDOW(window),
+                       GDK_WINDOW_TYPE_HINT_DIALOG);
 
        vbox = gtk_vbox_new (FALSE, 10);
        gtk_container_add (GTK_CONTAINER (window), vbox);
index 0ed9114..363a584 100644 (file)
@@ -82,16 +82,17 @@ gint plugin_init(gchar **error)
 gboolean plugin_done(void)
 {
        MainWindow *mainwin = mainwindow_get_mainwindow();
-       if (mainwin == NULL)
-               return FALSE;
-
-       MENUITEM_REMUI_MANAGER(mainwin->ui_manager, mainwin->action_group, "Tools/ManageSieveFilters", main_menu_id);
-       main_menu_id = 0;
 
        sieve_prefs_done();
        sieve_sessions_close();
 
+       if (mainwin)
+               MENUITEM_REMUI_MANAGER(mainwin->ui_manager,
+                               mainwin->action_group,
+                               "Tools/ManageSieveFilters", main_menu_id);
+
        debug_print("ManageSieve plugin unloaded\n");
+
        return TRUE;
 }
 
index 0bd3e41..f1ff729 100644 (file)
 #include "sieve_prefs.h"
 #include "managesieve.h"
 
+#define PREFS_BLOCK_NAME "ManageSieve"
+
+SieveConfig sieve_config;
+
+static PrefParam prefs[] = {
+        {"manager_win_width", "-1", &sieve_config.manager_win_width,
+               P_INT, NULL, NULL, NULL},
+        {"manager_win_height", "-1", &sieve_config.manager_win_height,
+               P_INT, NULL, NULL, NULL},
+        {0,0,0,0}
+};
+
 #define PACK_HBOX(hbox, vbox) \
 { \
        hbox = gtk_hbox_new (FALSE, 5); \
@@ -393,6 +405,9 @@ static gboolean sieve_prefs_account_can_close(PrefsPage *_page)
 
 void sieve_prefs_init()
 {
+       gchar *rcpath;
+
+       /* Account prefs */
        static gchar *path[3];
        path[0] = _("Plugins");
        path[1] = _("Sieve");
@@ -405,11 +420,41 @@ void sieve_prefs_init()
        account_page.page.can_close = sieve_prefs_account_can_close;
        account_page.page.weight = 30.0;
        prefs_account_register_page((PrefsPage *) &account_page);
+
+       /* Common prefs */
+       prefs_set_default(prefs);
+       rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
+       prefs_read_config(prefs, PREFS_BLOCK_NAME, rcpath, NULL);
+       g_free(rcpath);
 }
 
 void sieve_prefs_done(void)
 {
+       PrefFile *pref_file;
+       gchar *rc_file_path;
+
        prefs_account_unregister_page((PrefsPage *) &account_page);
+
+       rc_file_path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
+                                  COMMON_RC, NULL);
+       g_printf("rc_file: %s\n\n\n\n\n\n\n\n\n\n\n\n\n\n", rc_file_path);
+       pref_file = prefs_write_open(rc_file_path);
+       g_free(rc_file_path);
+
+       if (!pref_file || prefs_set_block_label(pref_file, PREFS_BLOCK_NAME) < 0)
+               return;
+
+       if (prefs_write_param(prefs, pref_file->fp) < 0) {
+               g_warning("failed to write ManageSieve Plugin configuration\n");
+               prefs_file_close_revert(pref_file);
+               return;
+       }
+
+       if (fprintf(pref_file->fp, "\n") < 0) {
+               FILE_OP_ERROR(rc_file_path, "fprintf");
+               prefs_file_close_revert(pref_file);
+       } else
+               prefs_file_close(pref_file);
 }
 
 struct SieveAccountConfig *sieve_prefs_account_get_config(
index c0c2417..c1d9f2d 100644 (file)
 #ifndef SIEVE_PREFS_H
 #define SIEVE_PREFS_H
 
+typedef struct SieveConfig SieveConfig;
 typedef struct SieveAccountConfig SieveAccountConfig;
 
 #include "prefs_account.h"
 #include "managesieve.h"
 
+struct SieveConfig
+{
+       gint            manager_win_width;
+       gint            manager_win_height;
+};
+
 struct SieveAccountConfig
 {
        gboolean        enable;
@@ -40,6 +47,8 @@ struct SieveAccountConfig
        gchar           *passwd;
 };
 
+extern SieveConfig sieve_config;
+
 void sieve_prefs_init(void);
 void sieve_prefs_done(void);
 struct SieveAccountConfig *sieve_prefs_account_get_config(