Ticket #6014: sync_data.patch

File sync_data.patch, 3.5 kB (added by erikos, 7 years ago)

Sync the data when reboot/shutdown and suspend

  • lib/sugar/activity/activity.py

    diff --git a/lib/sugar/activity/activity.py b/lib/sugar/activity/activity.py
    index f6dbd37..0a3dd40 100644
    a b  
    675675        if self.canvas and self.canvas.window: 
    676676            self._preview.take_screenshot(self.canvas.window) 
    677677 
     678    def sync_data(self): 
     679        """Sync the activity data to the Journal. 
     680         
     681        This method is called when we shutdown, reboot or suspend the laptop. 
     682        """ 
     683        if self._jobject: 
     684            self.save() 
     685 
    678686    def save(self): 
    679687        """Request that the activity is saved to the Journal. 
    680688         
  • lib/sugar/activity/activityservice.py

    diff --git a/lib/sugar/activity/activityservice.py b/lib/sugar/activity/activityservice.py
    index c884fcb..82a63f0 100644
    a b  
    6868    def TakeScreenshot(self): 
    6969        self._activity.take_screenshot() 
    7070 
     71    @dbus.service.method(_ACTIVITY_INTERFACE) 
     72    def SyncData(self): 
     73        self._activity.sync_data() 
     74 
  • shell/model/homemodel.py

    diff --git a/shell/model/homemodel.py b/shell/model/homemodel.py
    index 44d5417..332d4df 100644
    a b  
    147147        self._active_activity = home_activity 
    148148        self.emit('active-activity-changed', self._active_activity) 
    149149 
     150    def sync_activity_data(self):         
     151        """Sync all the running activities to the datastore 
     152 
     153        This is used to not loose any date when we shutdown or  
     154        reboot the laptop.         
     155        """ 
     156        for act in self._activities: 
     157            if act.get_type() != 'org.laptop.JournalActivity': 
     158               if act: 
     159                   service = act.get_service() 
     160                   if service: 
     161                       service.SyncData()                 
     162 
    150163    def __iter__(self):  
    151164        return iter(self._activities) 
    152165         
  • shell/shellservice.py

    diff --git a/shell/shellservice.py b/shell/shellservice.py
    index 458f941..5cccc98 100644
    a b  
    6464        dbus.service.Object.__init__(self, bus_name, _DBUS_PATH) 
    6565 
    6666    @dbus.service.method(_DBUS_SHELL_IFACE, 
     67                         in_signature="", out_signature="") 
     68    def SyncActivityData(self): 
     69        self._home_model.sync_activity_data() 
     70 
     71    @dbus.service.method(_DBUS_SHELL_IFACE, 
    6772                         in_signature="s", out_signature="b") 
    6873    def ActivateActivity(self, activity_id): 
    6974        host = self._shell.get_activity(activity_id) 
  • shell/view/home/HomeBox.py

    diff --git a/shell/view/home/HomeBox.py b/shell/view/home/HomeBox.py
    index 8764887..069080c 100644
    a b  
    183183        model = self._shell.get_model() 
    184184        model.props.state = ShellModel.STATE_SHUTDOWN 
    185185 
     186        home_model = self._shell.get_model().get_home() 
     187        home_model.sync_activity_data() 
     188 
    186189        pm = self._get_power_manager() 
    187190 
    188191        hw_manager = hardwaremanager.get_manager() 
     
    197200        model = self._shell.get_model() 
    198201        model.props.state = ShellModel.STATE_SHUTDOWN 
    199202 
     203        home_model = self._shell.get_model().get_home() 
     204        home_model.sync_activity_data() 
     205 
    200206        pm = self._get_power_manager() 
    201207 
    202208        hw_manager = hardwaremanager.get_manager()