summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Woodward2010-01-12 17:55:14 -0500
committerJason Woodward2010-01-12 17:58:28 -0500
commit47081d412fb3fce0d013562df8d877f6f4ca20a3 (patch)
treef8e380498b8dffc867f7ca8f4b9938ea65a069e3
parent90f405f24fa1a10a035ed7de92295c907c43d3c6 (diff)
downloadgslapt-47081d412fb3fce0d013562df8d877f6f4ca20a3.tar.gz
save window state for next gslapt invocation
-rw-r--r--ChangeLog4
-rw-r--r--src/Makefile.am3
-rw-r--r--src/callbacks.c6
-rw-r--r--src/interface.c1
-rw-r--r--src/main.c28
-rw-r--r--src/settings.c131
-rw-r--r--src/settings.h19
7 files changed, 186 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index abf1d66..c7d3791 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,6 @@
-0.5.2b Jan 11, 2010
- * start the window maximized
+0.5.2b Jan 12, 2010
+ * save and restore window position and size between invocations
* free several package lists that were never freed
* updated handling of conflicts from command line package names
diff --git a/src/Makefile.am b/src/Makefile.am
index c027c4b..99dedc0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -11,7 +11,8 @@ gslapt_SOURCES = \
main.c \
support.c support.h \
interface.c interface.h \
- callbacks.c callbacks.h
+ callbacks.c callbacks.h \
+ settings.c settings.h
gslapt_LDADD = @PACKAGE_LIBS@ $(INTLLIBS)
diff --git a/src/callbacks.c b/src/callbacks.c
index 04c1fda..b2bb786 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -27,8 +27,10 @@
#include "callbacks.h"
#include "interface.h"
#include "support.h"
+#include "settings.h"
extern GtkWidget *gslapt;
+extern GslaptSettings *gslapt_settings;
extern slapt_rc_config *global_config;
extern struct slapt_pkg_list *all;
extern struct slapt_pkg_list *installed;
@@ -96,12 +98,14 @@ static gint convert_slapt_priority_to_gslapt_priority(SLAPT_PRIORITY_T p);
void on_gslapt_destroy (GtkObject *object, gpointer user_data)
{
-
slapt_free_transaction(trans);
slapt_free_pkg_list(all);
slapt_free_pkg_list(installed);
slapt_free_rc_config(global_config);
+ gslapt_write_rc(gslapt_settings);
+ gslapt_free_rc(gslapt_settings);
+
gtk_main_quit();
exit(0);
}
diff --git a/src/interface.c b/src/interface.c
index 523d465..f209d84 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -653,7 +653,6 @@ create_gslapt (void)
gtk_widget_set_name (gslapt, "gslapt");
gtk_window_set_title (GTK_WINDOW (gslapt), _("Gslapt"));
gtk_window_set_position (GTK_WINDOW (gslapt), GTK_WIN_POS_CENTER);
- gtk_window_set_default_size (GTK_WINDOW (gslapt), 640, 480);
gslapt_icon_pixbuf = create_pixbuf ("gslapt.png");
if (gslapt_icon_pixbuf)
{
diff --git a/src/main.c b/src/main.c
index 9c17e34..d97b139 100644
--- a/src/main.c
+++ b/src/main.c
@@ -24,6 +24,7 @@
#include "callbacks.h"
#include "interface.h"
#include "support.h"
+#include "settings.h"
slapt_rc_config *global_config; /* our config struct */
struct slapt_pkg_list *installed;
@@ -31,6 +32,16 @@ struct slapt_pkg_list *all;
GtkWidget *gslapt;
slapt_transaction_t *trans = NULL;
char rc_location[1024];
+GslaptSettings *gslapt_settings = NULL;
+
+static gboolean gslapt_resized(GtkWindow *window, GdkEvent *event, gpointer data)
+{
+ gslapt_settings->x = event->configure.x;
+ gslapt_settings->y = event->configure.y;
+ gslapt_settings->width = event->configure.width;
+ gslapt_settings->height = event->configure.height;
+ return FALSE;
+}
int main (int argc, char *argv[]) {
GtkStatusbar *bar;
@@ -174,7 +185,22 @@ int main (int argc, char *argv[]) {
gtk_widget_set_sensitive(lookup_widget(gslapt,"execute1"),FALSE);
gtk_widget_set_sensitive(lookup_widget(gslapt,"unmark_all1"),FALSE);
- gtk_window_maximize(GTK_WINDOW(gslapt));
+ gtk_widget_add_events(gslapt, GDK_CONFIGURE);
+ g_signal_connect(G_OBJECT(gslapt), "configure-event",
+ G_CALLBACK(gslapt_resized), NULL);
+
+ /* restore previous rc settings */
+ gslapt_settings = gslapt_read_rc();
+ if (gslapt_settings == NULL) {
+ gslapt_settings = gslapt_new_rc();
+ gtk_window_set_default_size (GTK_WINDOW (gslapt), 640, 480);
+ } else {
+ gtk_window_set_default_size(GTK_WINDOW(gslapt),
+ gslapt_settings->width, gslapt_settings->height);
+ gtk_window_move(GTK_WINDOW(gslapt),
+ gslapt_settings->x, gslapt_settings->y);
+ }
+
gtk_widget_show (gslapt);
if (do_upgrade == 1) {
diff --git a/src/settings.c b/src/settings.c
new file mode 100644
index 0000000..5199f3d
--- /dev/null
+++ b/src/settings.c
@@ -0,0 +1,131 @@
+#include "settings.h"
+
+
+char *gslapt_init_rc_dir (void)
+{
+ char *dir = g_build_path (G_DIR_SEPARATOR_S, g_get_user_config_dir (), PACKAGE, NULL);
+
+ if (g_file_test(dir, G_FILE_TEST_IS_DIR) == FALSE) {
+ if ( g_mkdir_with_parents(dir, 0755) !=0 ) {
+ g_free(dir);
+ return NULL;
+ }
+ }
+ return dir;
+}
+
+GslaptSettings *gslapt_new_rc (void)
+{
+ GslaptSettings *g = g_slice_new(GslaptSettings);
+ g->x = g->y = g->width = g->height = 0;
+
+ return g;
+}
+
+GslaptSettings *gslapt_read_rc (void)
+{
+ GslaptSettings *gslapt_settings = NULL;
+ char *dir = NULL, *file = NULL;
+
+ dir = gslapt_init_rc_dir();
+
+ if (dir == NULL)
+ return NULL;
+
+ file = g_build_path (G_DIR_SEPARATOR_S, dir, "rc", NULL);
+ free(dir);
+
+ if (file == NULL)
+ return NULL;
+
+
+ if (g_file_test(file, G_FILE_TEST_IS_REGULAR) == TRUE) {
+ GKeyFile *keyfile= NULL;
+ GKeyFileFlags flags = G_KEY_FILE_NONE;
+ GError *error = NULL;
+
+ keyfile = g_key_file_new();
+ if (keyfile == NULL)
+ goto GSLAPT_READ_CONFIG_END;
+
+ if (!g_key_file_load_from_file (keyfile, file, flags, &error)) {
+ if (error != NULL)
+ g_error_free(error);
+ if (keyfile != NULL)
+ g_key_file_free(keyfile);
+ goto GSLAPT_READ_CONFIG_END;
+ }
+
+ gslapt_settings = g_slice_new(GslaptSettings);
+ if (gslapt_settings == NULL) {
+ if (error != NULL)
+ g_error_free(error);
+ g_key_file_free(keyfile);
+ goto GSLAPT_READ_CONFIG_END;
+ }
+
+ gslapt_settings->x = g_key_file_get_integer (keyfile, "window", "x", NULL);
+ gslapt_settings->y = g_key_file_get_integer (keyfile, "window", "y", NULL);
+ gslapt_settings->width = g_key_file_get_integer (keyfile, "window", "width", NULL);
+ gslapt_settings->height = g_key_file_get_integer (keyfile, "window", "height", NULL);
+
+ g_key_file_free(keyfile);
+
+ }
+
+GSLAPT_READ_CONFIG_END:
+ free(file);
+
+ return gslapt_settings;
+}
+
+void gslapt_free_rc(GslaptSettings *gslapt_settings)
+{
+ g_slice_free(GslaptSettings,gslapt_settings);
+}
+
+int gslapt_write_rc(GslaptSettings *gslapt_settings)
+{
+ char *dir;
+ int rc = -1;
+
+ if (gslapt_settings == NULL)
+ return rc;
+
+ dir = gslapt_init_rc_dir();
+ if (dir != NULL) {
+ gsize length;
+ GKeyFile *keyfile= NULL;
+ gchar *rc_data = NULL;
+
+ keyfile = g_key_file_new();
+
+ g_key_file_set_integer (keyfile, "window", "x", gslapt_settings->x);
+ g_key_file_set_integer (keyfile, "window", "y", gslapt_settings->y);
+ g_key_file_set_integer (keyfile, "window", "width", gslapt_settings->width);
+ g_key_file_set_integer (keyfile, "window", "height", gslapt_settings->height);
+
+ rc_data = g_key_file_to_data(keyfile, &length, NULL);
+ if (length != 0) {
+ char *file = g_build_path (G_DIR_SEPARATOR_S, dir, "rc", NULL);
+ if (file != NULL) {
+ FILE *fh = fopen(file,"wb");
+ if (fh != NULL) {
+ fprintf(fh, "%s", rc_data);
+ rc = 0;
+ fclose(fh);
+ }
+ g_free(file);
+ }
+ }
+
+ if (rc_data != NULL)
+ g_free(rc_data);
+
+ g_key_file_free(keyfile);
+ g_free(dir);
+ }
+
+ return rc;
+}
+
diff --git a/src/settings.h b/src/settings.h
new file mode 100644
index 0000000..33c96a5
--- /dev/null
+++ b/src/settings.h
@@ -0,0 +1,19 @@
+#ifndef GSLAPT_SETTINGS_HEADER
+#define GSLAPT_SETTINGS_HEADER
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <glib.h>
+#include "config.h"
+
+typedef struct {
+ gint x; gint y; gint width; gint height;
+} GslaptSettings;
+
+char *gslapt_init_rc_dir (void);
+GslaptSettings *gslapt_new_rc (void);
+GslaptSettings *gslapt_read_rc (void);
+int gslapt_write_rc(GslaptSettings *gslapt_settings);
+void gslapt_free_rc(GslaptSettings *gslapt_settings);
+
+#endif