Re: [Sugar-devel] [PATCH v4 sugar] Downgrading activities not allowed. (#2164)

2010-10-17 Thread Aleksey Lim
On Sun, Oct 17, 2010 at 01:55:00AM +0530, anub...@seeta.in wrote:
> Downgrading an activity is now made possible. When a .xo file of a version 
> older
> than the currently installed version is clicked, a downgrading option is made
> available, by popping up of a confirmation alert. Depending upton the choice
> selected you can downgrade the activity.

So we are in agreement to not use special window for downgrade alert
(we have at least one response from Garry), so downgarade alert
should be just regular alert(alert.py from sugar-toolkit)
in Journal window.

(and you didn't pass your patch though sugar-lint)

> v1 -> v2. Named according to the nomenclature suggested,inline function 
> used,signal emission condition revised,global variables removed.
> 
> v2 -> v3. Taking care of all calling of misc.resume.
> 
> v3 -> v4. Changes in the copyright of the new file
> 
> Signed-off-by: Anubhav Aggarwal  , Shanjit Singh Jajmann 
> 
> 
> ---
>  src/jarabe/journal/misc.py |   29 ++---
>  src/jarabe/journal/versionalert.py |  122 
> 
>  src/jarabe/model/bundleregistry.py |9 ++-
>  3 files changed, 148 insertions(+), 12 deletions(-)
>  create mode 100644 src/jarabe/journal/versionalert.py
> 
> diff --git a/src/jarabe/journal/misc.py b/src/jarabe/journal/misc.py
> index 32a2847..f060bb2 100644
> --- a/src/jarabe/journal/misc.py
> +++ b/src/jarabe/journal/misc.py
> @@ -30,12 +30,14 @@ from sugar.graphics.xocolor import XoColor
>  from sugar import mime
>  from sugar.bundle.activitybundle import ActivityBundle
>  from sugar.bundle.contentbundle import ContentBundle
> +from sugar.bundle.bundle import AlreadyInstalledException
>  from sugar import util
>  
>  from jarabe.view import launcher
>  from jarabe.model import bundleregistry, shell
>  from jarabe.journal.journalentrybundle import JournalEntryBundle
>  from jarabe.journal import model
> +from jarabe.journal.versionalert import VersionAlert
>  
>  def _get_icon_for_mime(mime_type):
>  generic_types = mime.get_all_generic_types()
> @@ -150,6 +152,7 @@ def get_activities(metadata):
>  
>  def resume(metadata, bundle_id=None):
>  registry = bundleregistry.get_registry()
> +version_downgrade = False
>  
>  if is_activity_bundle(metadata) and bundle_id is None:
>  
> @@ -159,19 +162,27 @@ def resume(metadata, bundle_id=None):
>  bundle = ActivityBundle(file_path)
>  if not registry.is_installed(bundle):
>  logging.debug('Installing activity bundle')
> -registry.install(bundle)
> +try:
> +registry.install(bundle)
> +except AlreadyInstalledException:
> +v_alert = VersionAlert()
> +v_alert.give_bundle(bundle)
> +version_downgrade= True
> +logging.debug('done')
> +
>  else:
>  logging.debug('Upgrading activity bundle')
>  registry.upgrade(bundle)
>  
> -logging.debug('activityfactory.creating bundle with id %r',
> -bundle.get_bundle_id())
> -installed_bundle = registry.get_bundle(bundle.get_bundle_id())
> -if installed_bundle:
> -launch(installed_bundle)
> -else:
> -logging.error('Bundle %r is not installed.',
> -  bundle.get_bundle_id())
> +if not version_downgrade:
> +logging.debug('activityfactory.creating bundle with id %r',
> +bundle.get_bundle_id())
> +installed_bundle = registry.get_bundle(bundle.get_bundle_id())
> +if installed_bundle:
> +launch(installed_bundle)
> +else:
> +logging.error('Bundle %r is not installed.',
> +  bundle.get_bundle_id())
>  
>  elif is_content_bundle(metadata) and bundle_id is None:
>  
> diff --git a/src/jarabe/journal/versionalert.py 
> b/src/jarabe/journal/versionalert.py
> new file mode 100644
> index 000..b0e30b0
> --- /dev/null
> +++ b/src/jarabe/journal/versionalert.py
> @@ -0,0 +1,122 @@
> +#Copyright (C) 2010 Software for Education, Entertainment and Training 
> Activities
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 2 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program; if not, write to the Free Software
> +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
> +
> +import gtk
> +from gettext im

Re: [Sugar-devel] [PATCH v4 sugar] Downgrading activities not allowed. (#2164)

2010-10-16 Thread Sascha Silbe
Excerpts from anubhav's message of Sat Oct 16 22:25:00 +0200 2010:

[src/jarabe/journal/versionalert.py: 147 lines skipped]

If we really need that much code just for asking the user for
confirmation then we're doing something wrong.

Sascha

--
http://sascha.silbe.org/
http://www.infra-silbe.de/


signature.asc
Description: PGP signature
___
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel


[Sugar-devel] [PATCH v4 sugar] Downgrading activities not allowed. (#2164)

2010-10-16 Thread anubhav
Downgrading an activity is now made possible. When a .xo file of a version older
than the currently installed version is clicked, a downgrading option is made
available, by popping up of a confirmation alert. Depending upton the choice
selected you can downgrade the activity.

v1 -> v2. Named according to the nomenclature suggested,inline function 
used,signal emission condition revised,global variables removed.

v2 -> v3. Taking care of all calling of misc.resume.

v3 -> v4. Changes in the copyright of the new file

Signed-off-by: Anubhav Aggarwal  , Shanjit Singh Jajmann 


---
 src/jarabe/journal/misc.py |   29 ++---
 src/jarabe/journal/versionalert.py |  122 
 src/jarabe/model/bundleregistry.py |9 ++-
 3 files changed, 148 insertions(+), 12 deletions(-)
 create mode 100644 src/jarabe/journal/versionalert.py

diff --git a/src/jarabe/journal/misc.py b/src/jarabe/journal/misc.py
index 32a2847..f060bb2 100644
--- a/src/jarabe/journal/misc.py
+++ b/src/jarabe/journal/misc.py
@@ -30,12 +30,14 @@ from sugar.graphics.xocolor import XoColor
 from sugar import mime
 from sugar.bundle.activitybundle import ActivityBundle
 from sugar.bundle.contentbundle import ContentBundle
+from sugar.bundle.bundle import AlreadyInstalledException
 from sugar import util
 
 from jarabe.view import launcher
 from jarabe.model import bundleregistry, shell
 from jarabe.journal.journalentrybundle import JournalEntryBundle
 from jarabe.journal import model
+from jarabe.journal.versionalert import VersionAlert
 
 def _get_icon_for_mime(mime_type):
 generic_types = mime.get_all_generic_types()
@@ -150,6 +152,7 @@ def get_activities(metadata):
 
 def resume(metadata, bundle_id=None):
 registry = bundleregistry.get_registry()
+version_downgrade = False
 
 if is_activity_bundle(metadata) and bundle_id is None:
 
@@ -159,19 +162,27 @@ def resume(metadata, bundle_id=None):
 bundle = ActivityBundle(file_path)
 if not registry.is_installed(bundle):
 logging.debug('Installing activity bundle')
-registry.install(bundle)
+try:
+registry.install(bundle)
+except AlreadyInstalledException:
+v_alert = VersionAlert()
+v_alert.give_bundle(bundle)
+version_downgrade= True
+logging.debug('done')
+
 else:
 logging.debug('Upgrading activity bundle')
 registry.upgrade(bundle)
 
-logging.debug('activityfactory.creating bundle with id %r',
-bundle.get_bundle_id())
-installed_bundle = registry.get_bundle(bundle.get_bundle_id())
-if installed_bundle:
-launch(installed_bundle)
-else:
-logging.error('Bundle %r is not installed.',
-  bundle.get_bundle_id())
+if not version_downgrade:
+logging.debug('activityfactory.creating bundle with id %r',
+bundle.get_bundle_id())
+installed_bundle = registry.get_bundle(bundle.get_bundle_id())
+if installed_bundle:
+launch(installed_bundle)
+else:
+logging.error('Bundle %r is not installed.',
+  bundle.get_bundle_id())
 
 elif is_content_bundle(metadata) and bundle_id is None:
 
diff --git a/src/jarabe/journal/versionalert.py 
b/src/jarabe/journal/versionalert.py
new file mode 100644
index 000..b0e30b0
--- /dev/null
+++ b/src/jarabe/journal/versionalert.py
@@ -0,0 +1,122 @@
+#Copyright (C) 2010 Software for Education, Entertainment and Training 
Activities
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+import gtk
+from gettext import gettext as _
+
+from sugar.graphics import style
+from jarabe.model import bundleregistry
+from sugar.activity import activityfactory
+import logging
+
+class VersionAlert(gtk.Window):
+
+def __init__(self):
+gtk.Window.__init__(self)
+
+self.set_border_width(style.LINE_WIDTH)
+offset = style.GRID_CELL_SIZE
+width = gtk.gdk.screen_width() - offset * 3
+height = gtk.gdk.screen_height() - offset * 8.5
+self.set_size_request(width, height)
+self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
+