[Goodies-commits] r3249 - ristretto/trunk/src
Stephan Arts
stephan at xfce.org
Tue Sep 25 19:57:19 CEST 2007
Author: stephan
Date: 2007-09-25 17:57:19 +0000 (Tue, 25 Sep 2007)
New Revision: 3249
Modified:
ristretto/trunk/src/main.c
ristretto/trunk/src/main_window.c
ristretto/trunk/src/main_window.h
Log:
Re-implement some settings-management
Modified: ristretto/trunk/src/main.c
===================================================================
--- ristretto/trunk/src/main.c 2007-09-25 17:23:54 UTC (rev 3248)
+++ ristretto/trunk/src/main.c 2007-09-25 17:57:19 UTC (rev 3249)
@@ -27,11 +27,17 @@
#include "main_window.h"
static ThunarVfsMimeDatabase *mime_dbase = NULL;
-static GtkIconTheme *icon_theme = NULL;
-static GtkRecentManager *recent_manager;
static XfceRc *xfce_rc;
+static gint window_save_geometry_timer_id = 0;
+static gboolean
+rstto_window_save_geometry_timer (gpointer user_data);
+static void
+rstto_window_save_geometry_timer_destroy(gpointer user_data);
+static gboolean
+cb_rstto_main_window_configure_event (GtkWidget *widget, GdkEventConfigure *event);
+
int main(int argc, char **argv)
{
@@ -47,23 +53,97 @@
thunar_vfs_init();
mime_dbase = thunar_vfs_mime_database_get_default();
- icon_theme = gtk_icon_theme_get_default();
gtk_window_set_default_icon_name("ristretto");
- recent_manager = gtk_recent_manager_get_default();
xfce_rc = xfce_rc_config_open(XFCE_RESOURCE_CONFIG, "ristretto/ristrettorc", FALSE);
+
+ const gchar *thumbnail_viewer_orientation = xfce_rc_read_entry(xfce_rc, "ThumbnailViewerOrientation", "horizontal");
+ gboolean show_thumbnail_viewer = xfce_rc_read_bool_entry(xfce_rc, "ShowThumbnailViewer", TRUE);
+ gboolean show_toolbar = xfce_rc_read_bool_entry(xfce_rc, "ShowToolBar", TRUE);
+ gint window_width = xfce_rc_read_int_entry(xfce_rc, "LastWindowWidth", 400);
+ gint window_height = xfce_rc_read_int_entry(xfce_rc, "LastWindowHeight", 300);
+ //gint slideshow_timeout = xfce_rc_read_int_entry(xfce_rc, "SlideShowTimeout", 5000);
GtkWidget *window = rstto_main_window_new();
g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
+ g_signal_connect(G_OBJECT(window), "configure-event", G_CALLBACK(cb_rstto_main_window_configure_event), NULL);
+ if (!strcmp(thumbnail_viewer_orientation, "vertical"))
+ {
+ rstto_main_window_set_thumbnail_viewer_orientation(RSTTO_MAIN_WINDOW(window), GTK_ORIENTATION_VERTICAL);
+ }
+ else
+ {
+ rstto_main_window_set_thumbnail_viewer_orientation(RSTTO_MAIN_WINDOW(window), GTK_ORIENTATION_HORIZONTAL);
+ }
+
+ gtk_window_set_default_size(GTK_WINDOW(window), window_width, window_height);
gtk_widget_show_all(window);
- rstto_main_window_set_thumbnail_viewer_visibility(RSTTO_MAIN_WINDOW(window), TRUE);
+ rstto_main_window_set_show_thumbnail_viewer(RSTTO_MAIN_WINDOW(window), show_thumbnail_viewer);
+ rstto_main_window_set_show_toolbar(RSTTO_MAIN_WINDOW(window), show_toolbar);
+
gtk_main();
xfce_rc_flush(xfce_rc);
xfce_rc_close(xfce_rc);
return 0;
}
+
+static gboolean
+rstto_window_save_geometry_timer (gpointer user_data)
+{
+ GtkWindow *window = GTK_WINDOW(user_data);
+ gint width = 0;
+ gint height = 0;
+ /* check if the window is still visible */
+ if (GTK_WIDGET_VISIBLE (window))
+ {
+ /* determine the current state of the window */
+ gint state = gdk_window_get_state (GTK_WIDGET (window)->window);
+
+ /* don't save geometry for maximized or fullscreen windows */
+ if ((state & (GDK_WINDOW_STATE_MAXIMIZED | GDK_WINDOW_STATE_FULLSCREEN)) == 0)
+ {
+ /* determine the current width/height of the window... */
+ gtk_window_get_size (GTK_WINDOW (window), &width, &height);
+
+ /* ...and remember them as default for new windows */
+ xfce_rc_write_int_entry (xfce_rc, "LastWindowWidth", width);
+ xfce_rc_write_int_entry (xfce_rc, "LastWindowHeight", height);
+ }
+ }
+ return FALSE;
+}
+
+static void
+rstto_window_save_geometry_timer_destroy(gpointer user_data)
+{
+ window_save_geometry_timer_id = 0;
+}
+
+static gboolean
+cb_rstto_main_window_configure_event (GtkWidget *widget, GdkEventConfigure *event)
+{
+ /* shamelessly copied from thunar, written by benny */
+ /* check if we have a new dimension here */
+ if (widget->allocation.width != event->width || widget->allocation.height != event->height)
+ {
+ /* drop any previous timer source */
+ if (window_save_geometry_timer_id > 0)
+ g_source_remove (window_save_geometry_timer_id);
+
+ /* check if we should schedule another save timer */
+ if (GTK_WIDGET_VISIBLE (widget))
+ {
+ /* save the geometry one second after the last configure event */
+ window_save_geometry_timer_id = g_timeout_add_full (G_PRIORITY_LOW, 1000, rstto_window_save_geometry_timer,
+ widget, rstto_window_save_geometry_timer_destroy);
+ }
+ }
+
+ /* let Gtk+ handle the configure event */
+ return FALSE;
+}
Modified: ristretto/trunk/src/main_window.c
===================================================================
--- ristretto/trunk/src/main_window.c 2007-09-25 17:23:54 UTC (rev 3248)
+++ ristretto/trunk/src/main_window.c 2007-09-25 17:57:19 UTC (rev 3249)
@@ -577,39 +577,66 @@
}
void
-rstto_main_window_set_thumbnail_viewer_visibility (RsttoMainWindow *window, gboolean visibility)
+rstto_main_window_set_show_thumbnail_viewer(RsttoMainWindow *window, gboolean visibility)
{
window->priv->settings.thumbnail_viewer_visibility = visibility;
if (visibility == TRUE)
{
- gtk_widget_show(window->priv->thumbnail_viewer);
+ switch(rstto_thumbnail_viewer_get_orientation(RSTTO_THUMBNAIL_VIEWER(window->priv->thumbnail_viewer)))
+ {
+ case GTK_ORIENTATION_HORIZONTAL:
+ gtk_check_menu_item_set_active(
+ GTK_CHECK_MENU_ITEM(window->priv->menus.view.show_thumbnail_viewer.menu_item_thumbnail_viewer_horizontal),
+ TRUE);
+ break;
+ case GTK_ORIENTATION_VERTICAL:
+ gtk_check_menu_item_set_active(
+ GTK_CHECK_MENU_ITEM(window->priv->menus.view.show_thumbnail_viewer.menu_item_thumbnail_viewer_vertical),
+ TRUE);
+ break;
+ }
+
}
else
{
- gtk_widget_hide(window->priv->thumbnail_viewer);
+ gtk_check_menu_item_set_active(
+ GTK_CHECK_MENU_ITEM(window->priv->menus.view.show_thumbnail_viewer.menu_item_thumbnail_viewer_hide),
+ TRUE);
}
}
+void
+rstto_main_window_set_show_toolbar (RsttoMainWindow *window, gboolean visibility)
+{
+ window->priv->settings.toolbar_visibility = visibility;
+ gtk_check_menu_item_set_active(
+ GTK_CHECK_MENU_ITEM(window->priv->menus.view.menu_item_show_toolbar),
+ visibility);
+}
+
/* CALLBACK FUNCTIONS */
static void
cb_rstto_main_window_thumbnail_viewer_horizontal(GtkWidget *widget, RsttoMainWindow *window)
{
- rstto_main_window_set_thumbnail_viewer_visibility(window, TRUE);
+ window->priv->settings.thumbnail_viewer_visibility = TRUE;
+ gtk_widget_show(window->priv->thumbnail_viewer);
rstto_main_window_set_thumbnail_viewer_orientation(window, GTK_ORIENTATION_HORIZONTAL);
}
static void
cb_rstto_main_window_thumbnail_viewer_vertical(GtkWidget *widget, RsttoMainWindow *window)
{
- rstto_main_window_set_thumbnail_viewer_visibility(window, TRUE);
+ window->priv->settings.thumbnail_viewer_visibility = TRUE;
+ gtk_widget_show(window->priv->thumbnail_viewer);
rstto_main_window_set_thumbnail_viewer_orientation(window, GTK_ORIENTATION_VERTICAL);
}
static void
cb_rstto_main_window_thumbnail_viewer_hide(GtkWidget *widget, RsttoMainWindow *window)
{
- rstto_main_window_set_thumbnail_viewer_visibility(window, FALSE);
+ window->priv->settings.thumbnail_viewer_visibility = FALSE;
+ gtk_widget_hide(window->priv->thumbnail_viewer);
}
static void
@@ -686,7 +713,7 @@
rstto_navigator_jump_back(rstto_window->priv->navigator);
break;
case GDK_t:
- rstto_main_window_set_thumbnail_viewer_visibility(RSTTO_MAIN_WINDOW(window),
+ rstto_main_window_set_show_thumbnail_viewer(RSTTO_MAIN_WINDOW(window),
!(RSTTO_MAIN_WINDOW(window)->priv->settings.thumbnail_viewer_visibility));
break;
}
Modified: ristretto/trunk/src/main_window.h
===================================================================
--- ristretto/trunk/src/main_window.h 2007-09-25 17:23:54 UTC (rev 3248)
+++ ristretto/trunk/src/main_window.h 2007-09-25 17:57:19 UTC (rev 3249)
@@ -63,7 +63,9 @@
void
rstto_main_window_set_thumbnail_viewer_orientation(RsttoMainWindow *window, GtkOrientation orientation);
void
-rstto_main_window_set_thumbnail_viewer_visibility (RsttoMainWindow *window, gboolean visibility);
+rstto_main_window_set_show_thumbnail_viewer (RsttoMainWindow *window, gboolean visibility);
+void
+rstto_main_window_set_show_toolbar (RsttoMainWindow *window, gboolean visibility);
G_END_DECLS
More information about the Goodies-commits
mailing list