diary r98 - in trunk: . data src src/links



Author: pwithnall
Date: Sun Oct 26 22:35:16 2008
New Revision: 98
URL: http://svn.gnome.org/viewvc/diary?rev=98&view=rev

Log:
2008-10-26  Philip Withnall  <philip tecnocode co uk>

	* configure.ac:
	* data/Makefile.am:
	* data/almanah.schemas.in:
	* src/main-window.c (almanah_main_window_dispose),
	(almanah_main_window_new), (save_window_state),
	(restore_window_state), (mw_delete_event_cb): Save the window
	dimensions and position upon exiting, and restore them when 
starting
	the program. Promotes the dependency on GConf to be mandatory 
(was
	previously dependent on compiling with encryption support).
	* src/links/file.c (file_view): Fix a compilation error about
	mismatched pointer types.



Modified:
   trunk/ChangeLog
   trunk/configure.ac
   trunk/data/Makefile.am
   trunk/data/almanah.schemas.in
   trunk/src/links/file.c
   trunk/src/main-window.c

Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac	(original)
+++ trunk/configure.ac	Sun Oct 26 22:35:16 2008
@@ -68,7 +68,7 @@
 AM_PROG_LIBTOOL
 AM_GCONF_SOURCE_2
 
-PKG_CHECK_MODULES(STANDARD, glib-2.0 gtk+-2.0 >= 2.12 gmodule-2.0 gio-2.0 sqlite3 cairo)
+PKG_CHECK_MODULES(STANDARD, glib-2.0 gtk+-2.0 >= 2.12 gmodule-2.0 gio-2.0 sqlite3 cairo gconf-2.0)
 AC_SUBST(STANDARD_CFLAGS)
 AC_SUBST(STANDARD_LIBS)
 
@@ -79,7 +79,7 @@
 fi
 
 if test $encryption = "true"; then
-	PKG_CHECK_MODULES(ENCRYPTION, cryptui-0.0 gconf-2.0)
+	PKG_CHECK_MODULES(ENCRYPTION, cryptui-0.0)
 
 	dnl Check for GPGME, which doesn't provide a pkgconfig file
 	dnl This code courtesy of seahorse

Modified: trunk/data/Makefile.am
==============================================================================
--- trunk/data/Makefile.am	(original)
+++ trunk/data/Makefile.am	Sun Oct 26 22:35:16 2008
@@ -46,7 +46,6 @@
 
 install-data-local:
 if GCONF_SCHEMAS_INSTALL
-if ENCRYPTION
 	@GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) gconftool-2 \
 		--makefile-install-rule $(schemas_DATA) || \
 		(echo ;\
@@ -55,7 +54,6 @@
 		echo "*****************************************************";)
 	@true
 endif
-endif
 
 ###############################################################################
 # General

Modified: trunk/data/almanah.schemas.in
==============================================================================
--- trunk/data/almanah.schemas.in	(original)
+++ trunk/data/almanah.schemas.in	Sun Oct 26 22:35:16 2008
@@ -8,7 +8,62 @@
 			<default></default>
 			<locale name="C">
 				<short>Database encryption key ID</short>
-		        	<long>The ID of the key to use to encrypt and decrypt the database, if Almanah has been built with encryption support. Leave blank to disable database encryption.</long>
+				<long>The ID of the key to use to encrypt and decrypt the database, if Almanah has been built with encryption support. Leave blank to disable database encryption.</long>
+			</locale>
+		</schema>
+		<schema>
+			<key>/schemas/apps/almanah/state/main_window_maximized</key>
+			<applyto>/apps/almanah/state/main_window_maximized</applyto>
+			<owner>almanah</owner>
+			<type>bool</type>
+			<default>false</default>
+			<locale name="C">
+				<short>Main window maximization</short>
+				<long>Whether the main window should start maximized.</long>
+			</locale>
+		</schema>
+		<schema>
+			<key>/schemas/apps/almanah/state/main_window_width</key>
+			<applyto>/apps/almanah/state/main_window_width</applyto>
+			<owner>almanah</owner>
+			<type>int</type>
+			<default>700</default>
+			<locale name="C">
+				<short>Main window width</short>
+				<long>The width of the main window.</long>
+			</locale>
+		</schema>
+		<schema>
+			<key>/schemas/apps/almanah/state/main_window_height</key>
+			<applyto>/apps/almanah/state/main_window_height</applyto>
+			<owner>almanah</owner>
+			<type>int</type>
+			<default>500</default>
+			<locale name="C">
+				<short>Main window height</short>
+				<long>The height of the main window.</long>
+			</locale>
+		</schema>
+		<schema>
+			<key>/schemas/apps/almanah/state/main_window_x_position</key>
+			<applyto>/apps/almanah/state/main_window_x_position</applyto>
+			<owner>almanah</owner>
+			<type>int</type>
+			<default>100</default>
+			<locale name="C">
+				<short>Main window X position</short>
+				<long>The X position of the main window.</long>
+			</locale>
+		</schema>
+		<schema>
+			<key>/schemas/apps/almanah/state/main_window_y_position</key>
+			<applyto>/apps/almanah/state/main_window_y_position</applyto>
+			<owner>almanah</owner>
+			<type>int</type>
+			<default>100</default>
+			<locale name="C">
+				<short>Main window Y position</short>
+				<long>The Y position of the main window.</long>
 			</locale>
 		</schema>
 	</schemalist>

Modified: trunk/src/links/file.c
==============================================================================
--- trunk/src/links/file.c	(original)
+++ trunk/src/links/file.c	Sun Oct 26 22:35:16 2008
@@ -78,7 +78,7 @@
 		GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW (almanah->main_window),
 							    GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
 							    _("Error opening file"));
-		gtk_message_dialog_format_secondary_text (GTK_DIALOG (dialog), "%s", error->message);
+		gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
 		gtk_dialog_run (GTK_DIALOG (dialog));
 		gtk_widget_destroy (dialog);
 

Modified: trunk/src/main-window.c
==============================================================================
--- trunk/src/main-window.c	(original)
+++ trunk/src/main-window.c	Sun Oct 26 22:35:16 2008
@@ -35,6 +35,8 @@
 
 static void almanah_main_window_init (AlmanahMainWindow *self);
 static void almanah_main_window_dispose (GObject *object);
+static void save_window_state (AlmanahMainWindow *self);
+static void restore_window_state (AlmanahMainWindow *self);
 static gboolean mw_delete_event_cb (GtkWindow *window, gpointer user_data);
 static void mw_entry_buffer_cursor_position_cb (GObject *object, GParamSpec *pspec, AlmanahMainWindow *main_window);
 static void mw_entry_buffer_insert_text_cb (GtkTextBuffer *text_buffer, GtkTextIter *start, gchar *text, gint len, AlmanahMainWindow *main_window);
@@ -101,7 +103,6 @@
 {
 	AlmanahMainWindowPrivate *priv = ALMANAH_MAIN_WINDOW (object)->priv;
 
-	/* TODO: Free UI objects? */
 	if (priv->current_entry != NULL) {
 		g_object_unref (priv->current_entry);
 		priv->current_entry = NULL;
@@ -233,10 +234,75 @@
 
 	g_object_unref (builder);
 
+	restore_window_state (main_window);
+
 	return main_window;
 }
 
 static void
+save_window_state (AlmanahMainWindow *self)
+{
+	GdkWindow *window;
+	GdkWindowState state;
+	gint width, height, x, y;
+
+	window = gtk_widget_get_window (GTK_WIDGET (self));
+	state = gdk_window_get_state (window);
+	gconf_client_set_bool (almanah->gconf_client, "/apps/almanah/state/main_window_maximized", state & GDK_WINDOW_STATE_MAXIMIZED ? TRUE : FALSE, NULL);
+
+	/* If we're maximised, don't bother saving size/position */
+	if (state & GDK_WINDOW_STATE_MAXIMIZED)
+		return;
+
+	/* Save the window dimensions */
+	gtk_window_get_size (GTK_WINDOW (self), &width, &height);
+
+	gconf_client_set_int (almanah->gconf_client, "/apps/almanah/state/main_window_width", width, NULL);
+	gconf_client_set_int (almanah->gconf_client, "/apps/almanah/state/main_window_height", height, NULL);
+
+	/* Save the window position */
+	gtk_window_get_position (GTK_WINDOW (self), &x, &y);
+
+	gconf_client_set_int (almanah->gconf_client, "/apps/almanah/state/main_window_x_position", x, NULL);
+	gconf_client_set_int (almanah->gconf_client, "/apps/almanah/state/main_window_y_position", y, NULL);
+}
+
+static void
+restore_window_state (AlmanahMainWindow *self)
+{
+	gint width, height, x, y;
+
+	width = gconf_client_get_int (almanah->gconf_client, "/apps/almanah/state/main_window_width", NULL);
+	height = gconf_client_get_int (almanah->gconf_client, "/apps/almanah/state/main_window_height", NULL);
+	x = gconf_client_get_int (almanah->gconf_client, "/apps/almanah/state/main_window_x_position", NULL);
+	y = gconf_client_get_int (almanah->gconf_client, "/apps/almanah/state/main_window_y_position", NULL);
+
+	/* Make sure the dimensions and position are sane */
+	if (width > 1 && height > 1) {
+		GdkScreen *screen;
+		gint max_width, max_height;
+
+		screen = gtk_widget_get_screen (GTK_WIDGET (self));
+		max_width = gdk_screen_get_width (screen);
+		max_height = gdk_screen_get_height (screen);
+
+		width = CLAMP (width, 0, max_width);
+		height = CLAMP (height, 0, max_height);
+
+		x = CLAMP (x, 0, max_width - width);
+		y = CLAMP (y, 0, max_height - height);
+
+		gtk_window_set_default_size (GTK_WINDOW (self), width, height);
+	}
+
+	gtk_window_move (GTK_WINDOW (self), x, y);
+
+	/* Maximised? */
+	if (gconf_client_get_bool (almanah->gconf_client, "/apps/almanah/state/main_window_maximized", NULL) == TRUE)
+		gtk_window_maximize (GTK_WINDOW (self));
+}
+
+static void
 save_current_entry (AlmanahMainWindow *self)
 {
 	gboolean entry_exists, entry_is_empty;
@@ -537,6 +603,7 @@
 mw_delete_event_cb (GtkWindow *window, gpointer user_data)
 {
 	save_current_entry (ALMANAH_MAIN_WINDOW (window));
+	save_window_state (ALMANAH_MAIN_WINDOW (window));
 	almanah_quit ();
 
 	return TRUE;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]