From 9b6ea6ed9d97b617b4c9633068369c074b3173b8 Mon Sep 17 00:00:00 2001
From: Bernie Innocenti <bernie@codewiz.org>
Date: Tue, 18 May 2010 18:30:34 -0400
Subject: [sugar-toolkit] sl#1948: Race condition with name widget in the activity toolbar (0.88)
Organization: Sugar Labs Foundation
X-Subversion: sucks

The fix consists in updating the datastore metadata on "focus-out-event".
Previously, we were using the "change" event along with a 1s timeout, which
was likely to trigger while the user was still typing into the text
entry widget.

Signed-off-by: Bernie Innocenti <bernie@codewiz.org>
---
 src/sugar/activity/widgets.py |   23 ++++++++---------------
 1 files changed, 8 insertions(+), 15 deletions(-)
 
--- sugar-toolkit-0.88.1/src/sugar/activity/widgets.py.orig	2010-06-02 10:57:58.000000000 -0400
+++ sugar-toolkit-0.88.1/src/sugar/activity/widgets.py	2010-06-06 10:17:43.000000000 -0400
@@ -183,12 +183,11 @@ class TitleEntry(gtk.ToolItem):
     def __init__(self, activity, **kwargs):
         gtk.ToolItem.__init__(self)
         self.set_expand(False)
-        self._update_title_sid = None
 
         self.entry = gtk.Entry(**kwargs)
         self.entry.set_size_request(int(gtk.gdk.screen_width() / 3), -1)
         self.entry.set_text(activity.metadata['title'])
-        self.entry.connect('changed', self.__title_changed_cb, activity)
+        self.entry.connect('focus-out-event', self.__title_changed_cb, activity)
         self.entry.show()
         self.add(self.entry)
 
@@ -202,23 +201,16 @@ class TitleEntry(gtk.ToolItem):
         self.entry.set_text(jobject['title'])
 
     def __title_changed_cb(self, entry, activity):
-        if self._update_title_sid is not None:
-            gobject.source_remove(self._update_title_sid)
-        self._update_title_sid = gobject.timeout_add_seconds(
-                1, self.__update_title_cb, activity)
-
-    def __update_title_cb(self, activity):
         title = self.entry.get_text()
+        if title != self._activity.metadata['title']:
+            activity.metadata['title'] = title
+            activity.metadata['title_set_by_user'] = '1'
+            activity.save()
+
+            shared_activity = activity.get_shared_activity()
+            if shared_activity is not None:
+                shared_activity.props.name = title
 
-        activity.metadata['title'] = title
-        activity.metadata['title_set_by_user'] = '1'
-        activity.save()
-
-        shared_activity = activity.get_shared_activity()
-        if shared_activity is not None:
-            shared_activity.props.name = title
-
-        self._update_title_sid = None
         return False
 

-- 
1.7.0.1

