[pitivi] mainwindow: Make the version display more robust in the about window
- From: Mathieu Duponchelle <mathieudu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] mainwindow: Make the version display more robust in the about window
- Date: Fri, 28 Feb 2014 03:12:09 +0000 (UTC)
commit fe2d994aa412a4cd98a4b2d5dfb2a4b78c7ed142
Author: Alexandru Băluț <alexandru balut gmail com>
Date: Thu Jan 30 15:02:52 2014 +0100
mainwindow: Make the version display more robust in the about window
Also add a unittest for the latest version logic and
moved the Pitivi tests to test_application.py because
that's the module where the Pitivi class resides.
pitivi/application.py | 29 +++++++++++++----
pitivi/dialogs/startupwizard.py | 21 ++++++------
pitivi/mainwindow.py | 17 +++++-----
tests/Makefile.am | 3 +-
tests/test_application.py | 66 +++++++++++++++++++++++++++++++++++++++
tests/test_basic.py | 24 --------------
6 files changed, 109 insertions(+), 51 deletions(-)
---
diff --git a/pitivi/application.py b/pitivi/application.py
index 8518fdd..14242e0 100644
--- a/pitivi/application.py
+++ b/pitivi/application.py
@@ -128,7 +128,7 @@ class Pitivi(Loggable, Signallable):
#self.timelineLogObserver = TimelineLogObserver(self.action_log)
self.projectLogObserver = ProjectLogObserver(self.action_log)
- self.version_information = {}
+ self._version_information = {}
self._checkVersion()
def shutdown(self):
@@ -191,7 +191,7 @@ class Pitivi(Loggable, Signallable):
self.info("Requesting version information")
giofile.load_contents_async(None, self._versionInfoReceivedCb, None)
- def _versionInfoReceivedCb(self, giofile, result, data):
+ def _versionInfoReceivedCb(self, giofile, result, user_data):
try:
raw = giofile.load_contents_finish(result)[1]
raw = raw.split("\n")
@@ -201,21 +201,36 @@ class Pitivi(Loggable, Signallable):
# search newest version and status
status = "UNSUPPORTED"
+ current_version = None
for version, version_status in data:
if pitivi_version == version:
status = version_status
if version_status.upper() == "CURRENT":
+ # This is the latest.
current_version = version
self.info("Latest software version is %s", current_version)
if status is "UNSUPPORTED":
- self.warning("Using an outdated version of Pitivi (%s)" % pitivi_version)
+ self.warning("Using an outdated version of Pitivi (%s)", pitivi_version)
- self.version_information["current"] = current_version
- self.version_information["status"] = status
- self.emit("version-info-received", self.version_information)
+ self._version_information["current"] = current_version
+ self._version_information["status"] = status
+ self.emit("version-info-received", self._version_information)
except Exception, e:
- self.warning("Version info could not be read: %s" % e)
+ self.warning("Version info could not be read: %s", e)
+
+ def isLatest(self):
+ """
+ Whether the app's version is the latest as far as we know.
+ """
+ status = self._version_information.get("status")
+ return status is None or status.upper() == "CURRENT"
+
+ def getLatest(self):
+ """
+ Get the latest version of the app or None.
+ """
+ return self._version_information.get("current")
class InteractivePitivi(Pitivi):
diff --git a/pitivi/dialogs/startupwizard.py b/pitivi/dialogs/startupwizard.py
index 8f58c08..2691f34 100644
--- a/pitivi/dialogs/startupwizard.py
+++ b/pitivi/dialogs/startupwizard.py
@@ -86,8 +86,8 @@ class StartUpWizard(object):
vbox = self.builder.get_object("topvbox")
self.infobar = Gtk.InfoBar()
vbox.pack_start(self.infobar, True, True, 0)
- if self.app.version_information:
- self._appVersionInfoReceivedCb(None, self.app.version_information)
+ if self.app.getLatest():
+ self._appVersionInfoReceivedCb(self.app, None)
else:
self.app.connect("version-info-received", self._appVersionInfoReceivedCb)
@@ -152,24 +152,25 @@ class StartUpWizard(object):
"""Handle the start of a project load operation."""
self.hide()
- def _appVersionInfoReceivedCb(self, unused_pitivi, version):
+ def _appVersionInfoReceivedCb(self, app, unused_version_information):
"""Handle version info"""
- # current version, don't show message
- if version["status"].upper() == "CURRENT":
+ if app.isLatest():
+ # current version, don't show message
return
- # new current version, reset counter
- if self.app.settings.lastCurrentVersion != version["current"]:
- self.app.settings.lastCurrentVersion = version["current"]
+ latest_version = app.getLatest()
+ if self.app.settings.lastCurrentVersion != latest_version:
+ # new latest version, reset counter
+ self.app.settings.lastCurrentVersion = latest_version
self.app.settings.displayCounter = 0
- # current version info already showed 5 times, don't show again
if self.app.settings.displayCounter >= 5:
+ # current version info already showed 5 times, don't show again
return
# increment counter, create infobar and show info
self.app.settings.displayCounter = self.app.settings.displayCounter + 1
- text = _("Pitivi %s is available." % version["current"])
+ text = _("Pitivi %s is available." % latest_version)
label = Gtk.Label(label=text)
self.infobar.get_content_area().add(label)
self.infobar.set_message_type(Gtk.MessageType.INFO)
diff --git a/pitivi/mainwindow.py b/pitivi/mainwindow.py
index 8692e3f..74ccfaa 100644
--- a/pitivi/mainwindow.py
+++ b/pitivi/mainwindow.py
@@ -167,9 +167,7 @@ class PitiviMainWindow(Gtk.Window, Loggable):
Pitivi's main window.
@cvar app: The application object
- @type app: L{Application}
- @cvar project: The current project
- @type project: L{Project}
+ @type app: L{Pitivi}
"""
def __init__(self, instance, allow_full_screen=True):
""" initialize with the Pitivi object """
@@ -665,20 +663,21 @@ class PitiviMainWindow(Gtk.Window, Loggable):
abt.set_program_name(APPNAME)
abt.set_website(APPURL)
- _app_version_info = self.app.version_information
if in_devel():
version_str = _("Development version")
- elif _app_version_info and _app_version_info["status"] != "CURRENT":
+ elif not self.app.isLatest():
version_str = _("Version %(cur_ver)s — %(new_ver)s is available" %
{"cur_ver": pitivi_version,
- "new_ver": _app_version_info["current"]})
+ "new_ver": self.app.getLatest()})
else:
version_str = _("Version %s" % pitivi_version)
abt.set_version(version_str)
- ges_version_str = "GES %i.%i.%i.%i" % (GES.version())
- gst_version_str = "GStreamer %i.%i.%i.%i" % (Gst.version())
- abt.set_comments("\n%s\n%s" % (ges_version_str, gst_version_str))
+ comments = ["",
+ "GES %s" % ".".join(map(str, GES.version())),
+ "GStreamer %s" % ".".join(map(str, Gst.version()))]
+ abt.set_comments("\n".join(comments))
+
authors = [_("Current maintainers:"),
"Jean-François Fortin Tam <nekohayo gmail com>",
"Thibault Saunier <thibault saunier collabora com>",
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1a313dd..3b966ce 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -2,7 +2,8 @@
# Don't try to use wildcards to replace the list of tests below.
# http://www.gnu.org/software/automake/manual/automake.html#Wildcards
# Keep this list sorted!
-tests = test_basic.py \
+tests = \
+ test_application.py \
test_common.py \
test_log.py \
test_misc.py \
diff --git a/tests/test_application.py b/tests/test_application.py
new file mode 100644
index 0000000..cdbb9f8
--- /dev/null
+++ b/tests/test_application.py
@@ -0,0 +1,66 @@
+# -*- coding: utf-8 -*-
+# Pitivi video editor
+#
+# tests/test_application.py
+#
+# Copyright (c) 2014, Alex Băluț <alexandru balut gmail com>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser 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.
+
+from common import TestCase
+
+from pitivi import application
+from pitivi import configure
+
+
+class MockGioFile(object):
+ def load_contents_finish(self, result):
+ return (True, result)
+
+
+class TestPitivi(TestCase):
+
+ def testBasic(self):
+ app = application.Pitivi()
+ self.assertTrue(app.shutdown())
+
+ def testVersionInfo(self):
+ app = application.Pitivi()
+ self.assertTrue(app.isLatest())
+
+ app = application.Pitivi()
+ app._versionInfoReceivedCb(MockGioFile(), "invalid", None)
+ self.assertTrue(app.isLatest())
+
+ app = application.Pitivi()
+ app._versionInfoReceivedCb(MockGioFile(), "%s=CURRENT" % configure.pitivi_version, None)
+ self.assertTrue(app.isLatest())
+ self.assertEqual(configure.pitivi_version, app.getLatest())
+
+ app = application.Pitivi()
+ app._versionInfoReceivedCb(MockGioFile(), "%s=current\n0=supported" % configure.pitivi_version, None)
+ self.assertTrue(app.isLatest())
+ self.assertEqual(configure.pitivi_version, app.getLatest())
+
+ app = application.Pitivi()
+ app._versionInfoReceivedCb(MockGioFile(), "999.0=CURRENT", None)
+ self.assertFalse(app.isLatest())
+ self.assertEqual("999.0", app.getLatest())
+
+ app = application.Pitivi()
+ app._versionInfoReceivedCb(MockGioFile(), "999.0=CURRENT\n%s=SUPPORTED" % configure.pitivi_version,
None)
+ self.assertFalse(app.isLatest())
+ self.assertEqual("999.0", app.getLatest())
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]