Preference Panel Handlers



Hi all,

I've been working on adding a slideshow interval option to the preferences panel. Overall I was pretty impressed with how easy it was to implement it --- I'm quite impressed by the overall architecture.

for the record I'm using the source code for f-spot 0.1.11 and the mono 1.1.13.4 snapshot.

I've run into a bit of strangeness - Once I had the slideshow interval preference implemented and apparently working, I noticed that the second time I opened the preferences panel and tried to move the slider, I got a native code crash in the gtk range code. After debugging a bit, I found that the problem was that things were getting kinda cyclic: I had implemented my slide similar to the metadata checkbox - I had a handler method that was called when the value changed, and it then set the preference to the current value. However then the OnPreferencesChanged method triggered, causing LoadPreference to try to read the value from the Preference and set it in the widget.

What I ended up doing is kinda cludgy - I created a local bool data member called "loadingPrefs", and set it in the ctor for the dialogue when we are calling LoadPreferences, and unset it immediately afterwards. In the LoadPreferences to code to handle the slideshow interval, I only actually do something if loadingPrefs is set --- so when the dialogue is originally opened, the slider gets set to the correct value, but LoadPreferences calls triggered by OnPreferecnesChanged don't do anything.

THis isn't a very satisfying solution, though. Is the 'OnPreferencesChanged' trigger to update the widgets really necessary? It looks to me like the only way to change the preferences is by manipulating the widgets on the preferences panel, so it doesn't seem necessary to then turn around and reset the widgets to the value you just took from the widget... Is there any way to modify the preferences aside from directly manipulating the widgets?

Any other suggestions how to deal with the problem?

For completeness, I've attached the patch I've created so far, and I'll include the crash messages I'm seeing if I remove the test against loadingsPrefs in the LoadPreferences code for the slideshow interval:

In the terminal I started f-spot from, I see:
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================

Stacktrace:

in (wrapper managed-to-native) Gtk.Range:gtk_range_set_value (intptr,double) <0x4> in (wrapper managed-to-native) Gtk.Range:gtk_range_set_value (intptr,double) <0xffffffe0>
in Gtk.Range:set_Value (double) <0x20>
in FSpot.PreferenceDialog:LoadPreference (string) <0x262>
in FSpot.PreferenceDialog:OnPreferencesChanged (object,GConf.NotifyEventArgs) <0x1c> in (wrapper delegate-invoke) System.MulticastDelegate:invoke_void_object_NotifyEventArgs (object,GConf.NotifyEventArgs) <0x29> in (wrapper delegate-invoke) System.MulticastDelegate:invoke_void_object_NotifyEventArgs (object,GConf.NotifyEventArgs) <0x86>
in FSpot.Preferences:OnSettingChanged (object,GConf.NotifyEventArgs) <0x1e>
in (wrapper delegate-invoke) System.MulticastDelegate:invoke_void_object_NotifyEventArgs (object,GConf.NotifyEventArgs) <0xfffffe29>
in GConf.NotifyWrapper:NotifyCB (intptr,uint,intptr,intptr) <0x131>
in (wrapper native-to-managed) GConf.NotifyWrapper:NotifyCB (intptr,uint,intptr,intptr) <0xae0d0e6c>
in (wrapper managed-to-native) Gtk.Application:gtk_main () <0x4>
in (wrapper managed-to-native) Gtk.Application:gtk_main () <0xffffffe7>
in Gtk.Application:Run () <0x7>
in Gnome.Program:Run () <0x7>
in FSpot.Driver:Main (string[]) <0x692>
in (wrapper runtime-invoke) System.Object:runtime_invoke_void_string[] (object,intptr,intptr,intptr) <0x50d07169>

Native stacktrace:

        f-spot(mono_handle_native_sigsegv+0x81) [0x8143f81]
        f-spot [0x81146cb]
        [0xffffe440]
        [0xb5b54075]
        [0xb5b54021]
        [0xb5c3a6eb]
        [0xb5b5694d]
        [0xb5b5689a]
        [0xb5b56882]
        [0xb5b568df]
        [0xb5b568aa]
        [0xb5b56682]
        [0x85bb353]
        /usr/lib/libgconf-2.so.4 [0xb668c17d]
        /usr/lib/libgconf-2.so.4(gconf_listeners_notify+0x101) [0xb667c954]
        /usr/lib/libgconf-2.so.4 [0xb668c23d]
        /usr/lib/libgconf-2.so.4 [0xb668c429]
        /usr/lib/libglib-2.0.so.0 [0xb7edd750]
/usr/lib/libglib-2.0.so.0(g_main_context_dispatch+0x1dc) [0xb7edb4ee]
        /usr/lib/libglib-2.0.so.0 [0xb7ede4f6]
        /usr/lib/libglib-2.0.so.0(g_main_loop_run+0x1a1) [0xb7ede7e3]
        /usr/lib/libgtk-x11-2.0.so.0(gtk_main+0xb4) [0xb6adee65]
        [0xb5c789e1]
        [0xb5c789a0]
        [0xb5c78980]
        [0xb738b7d3]
        [0xb738a823]
        f-spot(mono_runtime_exec_main+0x52) [0x8091962]
        f-spot(mono_runtime_run_main+0x12f) [0x809458f]
        f-spot(mono_main+0xf26) [0x805d836]
        /lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xd2) [0xb7d47ec2]
        f-spot [0x805c3b1]


In the bug-buddy window that appears, the stack trace is:
Backtrace was generated from '/usr/bin/f-spot'

Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1".
[Thread debugging using libthread_db enabled]
[New Thread -1210897504 (LWP 28397)]
[New Thread -1243980880 (LWP 28403)]
[New Thread -1242928208 (LWP 28402)]
[New Thread -1221030992 (LWP 28399)]
[New Thread -1220949072 (LWP 28398)]
0xffffe410 in ?? ()
#0  0xffffe410 in ?? ()
#1  0xbfe645b4 in ?? ()
#2  0x00000000 in ?? ()
#3  0xbfe64510 in ?? ()
#4 0xb7e994cb in __waitpid_nocancel () from /lib/tls/i686/cmov/libpthread.so.0 #5 0xb6ee5508 in libgnomeui_module_info_get () from /usr/lib/libgnomeui-2.so.0
#6  <signal handler called>
#7  0xffffe410 in ?? ()
#8  0xbfe648ac in ?? ()
#9  0x00000006 in ?? ()
#10 0x00006eed in ?? ()
#11 0xb7d5b9d1 in raise () from /lib/tls/i686/cmov/libc.so.6
#12 0xb7d5d2e9 in abort () from /lib/tls/i686/cmov/libc.so.6
#13 0x08143faf in mono_handle_native_sigsegv (ctx=0xbfe64ec0)
    at mini-exceptions.c:1034
#14 0x081146cb in sigsegv_signal_handler (_dummy=11, info=0xbfe64e40,
    context=0xbfe64ec0) at mini.c:9974
#15 <signal handler called>
#16 0xb6b0f7fc in gtk_range_set_value () from /usr/lib/libgtk-x11-2.0.so.0
#17 0xb5b54075 in ?? ()
#18 0x08745d20 in ?? ()
#19 0x00000000 in ?? ()
#20 0x40140000 in ?? ()
#21 0x0013ac10 in ?? ()
#22 0x002955a0 in ?? ()
#23 0xbfe655c4 in ?? ()
#24 0x081cb878 in ?? ()
#25 0x08780530 in ?? ()
#26 0x002d30f0 in ?? ()
#27 0x08745d20 in ?? ()
#28 0x0013ac10 in ?? ()
#29 0xbfe65210 in ?? ()
#30 0xb5b54044 in ?? ()
#31 0xbfe65228 in ?? ()
#32 0xb5b54021 in ?? ()
#33 0x08745d20 in ?? ()
#34 0x00000000 in ?? ()
#35 0x40140000 in ?? ()
#36 0x002955a0 in ?? ()
#37 0xbfe65288 in ?? ()
#38 0xb5c3a6eb in ?? ()
#39 0x000ec438 in ?? ()
#40 0x00000000 in ?? ()
#41 0x40140000 in ?? ()
#42 0xbfe652b0 in ?? ()
#43 0x08379c80 in ?? ()
#44 0x002d30f0 in ?? ()
#45 0x00000000 in ?? ()
#46 0x00000000 in ?? ()
#47 0xbfe65270 in ?? ()
#48 0x00000000 in ?? ()
#49 0x40140000 in ?? ()
#50 0x00000000 in ?? ()
#51 0x00000000 in ?? ()
#52 0x00000000 in ?? ()
#53 0x002bb578 in ?? ()
#54 0xbfe65284 in ?? ()
#55 0xb5b56905 in ?? ()
#56 0x000f7e58 in ?? ()
#57 0x002955a0 in ?? ()
#58 0x00154690 in ?? ()
#59 0x002955a0 in ?? ()
#60 0x002bb5a0 in ?? ()
#61 0xbfe652a0 in ?? ()
#62 0xb5b5694d in ?? ()
#63 0x00154690 in ?? ()
#64 0x002955a0 in ?? ()
#65 0x002acfa8 in ?? ()
#66 0x00154690 in ?? ()
#67 0xbfe652bc in ?? ()
#68 0xb5b5689a in ?? ()
#69 0x00154690 in ?? ()
#70 0x000fa2a0 in ?? ()
#71 0x000fa260 in ?? ()
#72 0x002bb5a0 in ?? ()
#73 0x002bb5c8 in ?? ()
#74 0xbfe652d8 in ?? ()
#75 0xb5b56882 in ?? ()
#76 0x002bb5a0 in ?? ()
#77 0x000fa2a0 in ?? ()
#78 0x000fa260 in ?? ()
#79 0x00000000 in ?? ()
#80 0x000c5a78 in ?? ()
#81 0xbfe652ec in ?? ()
#82 0xb5b568df in ?? ()
#83 0x002bb5c8 in ?? ()
#84 0x000fa2a0 in ?? ()
#85 0x000fa260 in ?? ()
#86 0xbfe65304 in ?? ()
#87 0xb5b568aa in ?? ()
#88 0x000fa2a0 in ?? ()
#89 0x000fa260 in ?? ()
#90 0x000fa290 in ?? ()
#91 0x000fa2a0 in ?? ()
#92 0xbfe6533c in ?? ()
#93 0xb5b56682 in ?? ()
#94 0x000c5a78 in ?? ()
#95 0x000fa2a0 in ?? ()
#96 0x000fa260 in ?? ()
#97 0x000fa260 in ?? ()
#98 0x0013acd0 in ?? ()
#99 0x002955a0 in ?? ()
#100 0x000fa2a0 in ?? ()
#101 0x087ecc80 in ?? ()
#102 0x000c5a78 in ?? ()
#103 0x0830bdd8 in ?? ()
#104 0x00094dd0 in ?? ()
#105 0xb66963e8 in ?? () from /usr/lib/libgconf-2.so.4
#106 0xbfe65364 in ?? ()
#107 0x085bb353 in ?? ()
#108 0x00094dd0 in ?? ()
#109 0x0830bdd8 in ?? ()
#110 0xf7000007 in ?? ()
#111 0x08779ee0 in ?? ()
#112 0x00000000 in ?? ()
#113 0x00f33180 in ?? ()
#114 0x08749a50 in ?? ()
#115 0xbfe65400 in ?? ()
#116 0xbfe65394 in ?? ()
#117 0xb668c17d in gconf_client_change_set_from_current ()
   from /usr/lib/libgconf-2.so.4

Thanks,

Warren


diff -ur clean/f-spot-0.1.11/src/f-spot.glade f-spot-0.1.11/src/f-spot.glade
--- clean/f-spot-0.1.11/src/f-spot.glade	2006-02-25 03:54:05.000000000 -0500
+++ f-spot-0.1.11/src/f-spot.glade	2006-03-31 19:01:57.000000000 -0500
@@ -12099,6 +12099,126 @@
 	  </child>
 
 	  <child>
+	    <widget class="GtkFrame" id="frame47">
+	      <property name="visible">True</property>
+	      <property name="label_xalign">0</property>
+	      <property name="label_yalign">0.5</property>
+	      <property name="shadow_type">GTK_SHADOW_NONE</property>
+
+	      <child>
+		<widget class="GtkAlignment" id="alignment63">
+		  <property name="visible">True</property>
+		  <property name="xalign">0.5</property>
+		  <property name="yalign">0.5</property>
+		  <property name="xscale">1</property>
+		  <property name="yscale">1</property>
+		  <property name="top_padding">0</property>
+		  <property name="bottom_padding">0</property>
+		  <property name="left_padding">12</property>
+		  <property name="right_padding">0</property>
+
+		  <child>
+		    <widget class="GtkVBox" id="vbox83">
+		      <property name="visible">True</property>
+		      <property name="homogeneous">False</property>
+		      <property name="spacing">6</property>
+
+		      <child>
+			<widget class="GtkHBox" id="hbox85">
+			  <property name="visible">True</property>
+			  <property name="homogeneous">False</property>
+			  <property name="spacing">12</property>
+
+			  <child>
+			    <widget class="GtkHScale" id="slideshow_interval">
+			      <property name="visible">True</property>
+			      <property name="can_focus">True</property>
+			      <property name="draw_value">True</property>
+			      <property name="value_pos">GTK_POS_BOTTOM</property>
+			      <property name="digits">1</property>
+			      <property name="update_policy">GTK_UPDATE_CONTINUOUS</property>
+			      <property name="inverted">False</property>
+			      <property name="adjustment">2 0.5 30 0 0 0</property>
+			      <signal name="value_changed" handler="HandleSlideshowInterval" last_modification_time="Fri, 31 Mar 2006 13:23:13 GMT"/>
+			    </widget>
+			    <packing>
+			      <property name="padding">0</property>
+			      <property name="expand">True</property>
+			      <property name="fill">True</property>
+			    </packing>
+			  </child>
+
+			  <child>
+			    <widget class="GtkLabel" id="label214">
+			      <property name="visible">True</property>
+			      <property name="label" translatable="yes">Delay Between Images</property>
+			      <property name="use_underline">False</property>
+			      <property name="use_markup">False</property>
+			      <property name="justify">GTK_JUSTIFY_LEFT</property>
+			      <property name="wrap">False</property>
+			      <property name="selectable">False</property>
+			      <property name="xalign">0.5</property>
+			      <property name="yalign">0.5</property>
+			      <property name="xpad">0</property>
+			      <property name="ypad">0</property>
+			      <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+			      <property name="width_chars">-1</property>
+			      <property name="single_line_mode">False</property>
+			      <property name="angle">0</property>
+			    </widget>
+			    <packing>
+			      <property name="padding">0</property>
+			      <property name="expand">False</property>
+			      <property name="fill">False</property>
+			    </packing>
+			  </child>
+			</widget>
+			<packing>
+			  <property name="padding">0</property>
+			  <property name="expand">False</property>
+			  <property name="fill">False</property>
+			</packing>
+		      </child>
+
+		      <child>
+			<placeholder/>
+		      </child>
+		    </widget>
+		  </child>
+		</widget>
+	      </child>
+
+	      <child>
+		<widget class="GtkLabel" id="label212">
+		  <property name="visible">True</property>
+		  <property name="label" translatable="yes">&lt;b&gt;Slideshow&lt;/b&gt;</property>
+		  <property name="use_underline">False</property>
+		  <property name="use_markup">True</property>
+		  <property name="justify">GTK_JUSTIFY_LEFT</property>
+		  <property name="wrap">False</property>
+		  <property name="selectable">False</property>
+		  <property name="xalign">0.5</property>
+		  <property name="yalign">0.5</property>
+		  <property name="xpad">0</property>
+		  <property name="ypad">0</property>
+		  <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+		  <property name="width_chars">-1</property>
+		  <property name="single_line_mode">False</property>
+		  <property name="angle">0</property>
+		</widget>
+		<packing>
+		  <property name="type">label_item</property>
+		</packing>
+	      </child>
+	    </widget>
+	    <packing>
+	      <property name="padding">0</property>
+	      <property name="expand">True</property>
+	      <property name="fill">True</property>
+	    </packing>
+	  </child>
+
+	  <child>
 	    <widget class="GtkFrame" id="frame46">
 	      <property name="visible">True</property>
 	      <property name="label_xalign">0</property>
diff -ur clean/f-spot-0.1.11/src/PreferenceDialog.cs f-spot-0.1.11/src/PreferenceDialog.cs
--- clean/f-spot-0.1.11/src/PreferenceDialog.cs	2006-02-20 18:38:14.000000000 -0500
+++ f-spot-0.1.11/src/PreferenceDialog.cs	2006-03-31 20:49:42.000000000 -0500
@@ -29,16 +29,21 @@
 		[Glade.Widget] private ComboBox destination_combo;
 		[Glade.Widget] private OptionMenu tag_option;
 		[Glade.Widget] private Button set_saver_button;
+		[Glade.Widget] private HScale slideshow_interval;
 		private static PreferenceDialog prefs = null;
 		int screensaver_tag;
+		bool loadingPrefs;
 		private const string SaverCommand = "f-spot-screensaver";
 
 		public PreferenceDialog () : base ("main_preferences")
 		{
+			loadingPrefs = true;
 			LoadPreference (Preferences.METADATA_EMBED_IN_IMAGE);
 			LoadPreference (Preferences.SCREENSAVER_TAG);
 			LoadPreference (Preferences.GNOME_SCREENSAVER_THEME);
-
+			LoadPreference (Preferences.SLIDESHOW_INTERVAL);
+			loadingPrefs = false;
+			
 			Gtk.CellRendererText name_cell = new Gtk.CellRendererText ();
 			Gtk.CellRendererText desc_cell = new Gtk.CellRendererText ();
 			
@@ -103,6 +108,11 @@
 			LoadPreference (args.Key);
 		}
 
+		void HandleSlideshowInterval (object sender, System.EventArgs args)
+		{
+			Preferences.Set (Preferences.SLIDESHOW_INTERVAL, slideshow_interval.Value);
+		}
+		
 		void MetadataToggled (object sender, System.EventArgs args)
 		{
 			Preferences.Set (Preferences.METADATA_EMBED_IN_IMAGE, metadata_check.Active);
@@ -135,7 +145,18 @@
 				string [] names = (string []) val;
 				set_saver_button.Sensitive = (names.Length != 1 || names [0] != SaverCommand);
 				break;
+			case Preferences.SLIDESHOW_INTERVAL:
+				double interval = 2;
+				if (val != null) {
+					interval = (double) val;
+				}
+				if (loadingPrefs) {
+					slideshow_interval.Value = interval;
+				}
+				break;
+								
 			}
+			
 		}
 
 		void HandleClose (object sender, EventArgs args)
diff -ur clean/f-spot-0.1.11/src/Preferences.cs f-spot-0.1.11/src/Preferences.cs
--- clean/f-spot-0.1.11/src/Preferences.cs	2006-02-20 12:46:48.000000000 -0500
+++ f-spot-0.1.11/src/Preferences.cs	2006-03-31 19:08:11.000000000 -0500
@@ -73,6 +73,8 @@
 
 		public const string SCREENSAVER_TAG = "/apps/f-spot/screensaver/tag_id";
 
+		public const string SLIDESHOW_INTERVAL = "/apps/f-spot/slideshow/interval";
+
 		public const string METADATA_EMBED_IN_IMAGE = "/apps/f-spot/metadata/embed_in_image";
 
 		public const string GNOME_SCREENSAVER_THEME = "/apps/gnome-screensaver/themes";
diff -ur clean/f-spot-0.1.11/src/SlideView.cs f-spot-0.1.11/src/SlideView.cs
--- clean/f-spot-0.1.11/src/SlideView.cs	2006-03-31 20:46:38.000000000 -0500
+++ f-spot-0.1.11/src/SlideView.cs	2006-03-31 19:28:30.000000000 -0500
@@ -303,7 +303,7 @@
 			
 			black = false;
 			transition_interval = 75;
-			flip_interval = 2000;
+			flip_interval = FlipIntervalPref;
 		}
 		
 		private bool PreloadNextImage (int idx)
@@ -574,6 +574,18 @@
 				
 			}
 		}
+		
+		private uint FlipIntervalPref {
+			get {
+				object val = Preferences.Get(Preferences.SLIDESHOW_INTERVAL);
+				double interval = 2;
+				if (val != null) {
+					interval = (double) val;
+				}
+				System.Console.WriteLine("setting interval to:" + interval);
+				return (uint) interval * 1000;				
+			}
+		}
 
 		private void ClearTweens () {
 			for (int i = 0; i < tweens.Length; i++) {


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