[pitivi/ges] Add a version checker



commit 20ad0a2c13d2d5c776a17fca9dc2f6545b68e81b
Author: Paul Lange <palango gmx de>
Date:   Thu Apr 26 15:18:14 2012 -0500

    Add a version checker
    
    Load version information from the PiTiVi website and check for updates.
    If a new release is available, it will be shown in the welcome dialog
    and the about dialog.
    
    Fixes bug #596864

 data/ui/startupwizard.ui        |  195 +++++++++++++++++++++------------------
 docs/release                    |    1 +
 pitivi/application.py           |   37 +++++++-
 pitivi/configure.py.in          |    1 +
 pitivi/dialogs/startupwizard.py |   33 +++++++-
 pitivi/mainwindow.py            |   19 ++++-
 6 files changed, 193 insertions(+), 93 deletions(-)
---
diff --git a/data/ui/startupwizard.ui b/data/ui/startupwizard.ui
index 3a654f0..5092883 100644
--- a/data/ui/startupwizard.ui
+++ b/data/ui/startupwizard.ui
@@ -8,7 +8,6 @@
   </object>
   <object class="GtkWindow" id="window1">
     <property name="can_focus">False</property>
-    <property name="border_width">10</property>
     <property name="title" translatable="yes">Welcome</property>
     <property name="resizable">False</property>
     <property name="modal">True</property>
@@ -18,21 +17,52 @@
     <signal name="key-press-event" handler="_keyPressCb" swapped="no"/>
     <signal name="delete-event" handler="_deleteCb" swapped="no"/>
     <child>
-      <object class="GtkHBox" id="hbox2">
+      <object class="GtkVBox" id="topvbox">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
-        <property name="spacing">12</property>
         <child>
-          <object class="GtkVBox" id="vbox1">
+          <object class="GtkHBox" id="hbox2">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="spacing">6</property>
+            <property name="border_width">10</property>
+            <property name="spacing">12</property>
             <child>
-              <object class="GtkLabel" id="label1">
+              <object class="GtkVBox" id="vbox2">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="xalign">0</property>
-                <property name="label" translatable="yes">Double-click a project below to load it:</property>
+                <property name="spacing">6</property>
+                <child>
+                  <object class="GtkLabel" id="label1">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="xalign">0</property>
+                    <property name="label" translatable="yes">Double-click a project below to load it:</property>
+                  </object>
+                  <packing>
+                    <property name="expand">True</property>
+                    <property name="fill">True</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkRecentChooserWidget" id="recentchooser2">
+                    <property name="width_request">300</property>
+                    <property name="height_request">215</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="orientation">vertical</property>
+                    <property name="limit">7</property>
+                    <property name="show_not_found">False</property>
+                    <property name="show_tips">True</property>
+                    <property name="sort_type">mru</property>
+                    <signal name="item-activated" handler="_loadCb" swapped="no"/>
+                  </object>
+                  <packing>
+                    <property name="expand">True</property>
+                    <property name="fill">True</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
               </object>
               <packing>
                 <property name="expand">True</property>
@@ -41,16 +71,73 @@
               </packing>
             </child>
             <child>
-              <object class="GtkRecentChooserWidget" id="recentchooser2">
-                <property name="width_request">300</property>
-                <property name="height_request">215</property>
+              <object class="GtkVButtonBox" id="vbuttonbox2">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="limit">7</property>
-                <property name="show_not_found">False</property>
-                <property name="show_tips">True</property>
-                <property name="sort_type">mru</property>
-                <signal name="item-activated" handler="_loadCb" swapped="no"/>
+                <property name="spacing">6</property>
+                <property name="layout_style">start</property>
+                <child>
+                  <object class="GtkButton" id="button1">
+                    <property name="label">gtk-new</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <property name="use_action_appearance">False</property>
+                    <property name="use_stock">True</property>
+                    <signal name="clicked" handler="_newProjectCb" swapped="no"/>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkButton" id="button7">
+                    <property name="label">gtk-help</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <property name="use_action_appearance">False</property>
+                    <property name="use_stock">True</property>
+                    <signal name="clicked" handler="_userManualCb" swapped="no"/>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkButton" id="button8">
+                    <property name="label" translatable="yes">Browse projects...</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <property name="use_action_appearance">False</property>
+                    <signal name="clicked" handler="_onBrowseButtonClickedCb" swapped="no"/>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">2</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkButton" id="missing_deps_button">
+                    <property name="label" translatable="yes">Missing dependencies...</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <property name="use_action_appearance">False</property>
+                    <signal name="clicked" handler="_onMissingDepsButtonClickedCb" swapped="no"/>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">3</property>
+                  </packing>
+                </child>
               </object>
               <packing>
                 <property name="expand">True</property>
@@ -62,84 +149,12 @@
           <packing>
             <property name="expand">True</property>
             <property name="fill">True</property>
+            <property name="pack_type">end</property>
             <property name="position">0</property>
           </packing>
         </child>
         <child>
-          <object class="GtkVButtonBox" id="vbuttonbox2">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="spacing">6</property>
-            <property name="layout_style">start</property>
-            <child>
-              <object class="GtkButton" id="button1">
-                <property name="label">gtk-new</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_action_appearance">False</property>
-                <property name="use_stock">True</property>
-                <signal name="clicked" handler="_newProjectCb" swapped="no"/>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkButton" id="button7">
-                <property name="label">gtk-help</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_action_appearance">False</property>
-                <property name="use_stock">True</property>
-                <signal name="clicked" handler="_userManualCb" swapped="no"/>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkButton" id="button8">
-                <property name="label" translatable="yes">Browse projects...</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_action_appearance">False</property>
-                <property name="image">image2</property>
-                <signal name="clicked" handler="_onBrowseButtonClickedCb" swapped="no"/>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">2</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkButton" id="missing_deps_button">
-                <property name="label" translatable="yes">Missing dependencies...</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_action_appearance">False</property>
-                <signal name="clicked" handler="_onMissingDepsButtonClickedCb" swapped="no"/>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">3</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">True</property>
-            <property name="fill">True</property>
-            <property name="position">1</property>
-          </packing>
+          <placeholder/>
         </child>
       </object>
     </child>
diff --git a/docs/release b/docs/release
index 28ecc6d..8c7bf8c 100644
--- a/docs/release
+++ b/docs/release
@@ -28,6 +28,7 @@ Preparing:
      * Re-autogen
      * Make sure pre-requisites are still valid
      * Update the following files:
+      * pitivi.org/versions.txt: add new release as current
       * ChangeLog (see the instructions in the previous section)
       * RELEASE. To get the list of contributors,
         * 'git shortlog -s -n RELEASE-<previoustag>..'
diff --git a/pitivi/application.py b/pitivi/application.py
index 998c805..57d6955 100644
--- a/pitivi/application.py
+++ b/pitivi/application.py
@@ -30,6 +30,7 @@ import os
 import sys
 import urllib
 import ges
+import gio
 
 from gettext import gettext as _
 from optparse import OptionParser
@@ -38,7 +39,7 @@ import pitivi.instance as instance
 
 from pitivi.check import initial_checks
 from pitivi.effects import EffectsHandler
-from pitivi.configure import APPNAME
+from pitivi.configure import APPNAME, pitivi_version, RELEASES_URL
 from pitivi.settings import GlobalSettings
 from pitivi.utils.threads import ThreadMaster
 from pitivi.mainwindow import PitiviMainWindow
@@ -96,6 +97,7 @@ class Pitivi(Loggable, Signallable):
         "closing-project": ["project"],
         "project-closed": ["project"],
         "missing-uri": ["formatter", "uri"],
+        "version-info-received": ["versions"],
         "shutdown": None}
 
     def __init__(self):
@@ -139,6 +141,9 @@ class Pitivi(Loggable, Signallable):
         self.projectLogObserver = ProjectLogObserver(self.action_log)
         self.medialibrary_log_observer = MediaLibraryLogObserver(self.action_log)
 
+        self.version_information = {}
+        self._checkVersion()
+
     def shutdown(self):
         """
         Close PiTiVi.
@@ -204,6 +209,36 @@ class Pitivi(Loggable, Signallable):
         self.current = None
         self.emit("project-closed", project)
 
+    # check if for version information online
+    def _checkVersion(self):
+        giofile = gio.File(uri=RELEASES_URL)
+        self.info("Requesting version information")
+        if giofile.query_exists(None):
+            giofile.load_contents_async(self._versionInfoReceivedCb, None, None)
+
+    def _versionInfoReceivedCb(self, giofile, result, data):
+        try:
+            # split data in lines
+            raw = giofile.load_contents_finish(result)[0].split("\n")
+            # split line at '=' if not empty or comment
+            data = [element.split("=") for element in raw
+                    if element and not element.startswith("#")]
+
+            # search newest version and status
+            status = "UNSUPPORTED"
+            for version, version_status in data:
+                if pitivi_version == version:
+                    status = version_status
+                if version_status.upper() == "CURRENT":
+                    current_version = version
+
+            self.info("Version information received")
+            self.version_information["current"] = current_version
+            self.version_information["status"] = status
+            self.emit("version-info-received", self.version_information)
+        except:
+            self.warning("Version information could not be read")
+
 
 class InteractivePitivi(Pitivi):
     """
diff --git a/pitivi/configure.py.in b/pitivi/configure.py.in
index 46f420e..ca5cb57 100644
--- a/pitivi/configure.py.in
+++ b/pitivi/configure.py.in
@@ -39,6 +39,7 @@ PKGDATADIR = '@DATADIR@/@PACKAGE@'
 pitivi_version = '@VERSION@'
 APPNAME = '@PACKAGE_NAME@'
 APPURL = 'http://www.pitivi.org/'
+RELEASES_URL = 'http://pitivi.org/releases.txt'
 PYGTK_REQ = '@PYGTK_REQ@'
 GTK_REQ = '@GTK_REQ@'
 PYGST_REQ = '@PYGST_REQ@'
diff --git a/pitivi/dialogs/startupwizard.py b/pitivi/dialogs/startupwizard.py
index 55ede5a..a468e4d 100644
--- a/pitivi/dialogs/startupwizard.py
+++ b/pitivi/dialogs/startupwizard.py
@@ -24,10 +24,11 @@ import gtk
 
 from gettext import gettext as _
 
-from pitivi.configure import get_ui_dir
+from pitivi.configure import get_ui_dir, APPURL
 from pitivi.dialogs.depsmanager import DepsManager
 from pitivi.check import soft_deps
 from pitivi.utils.misc import show_user_manual
+from pitivi.settings import GlobalSettings
 
 from urllib import unquote
 
@@ -69,6 +70,14 @@ class StartUpWizard(object):
         self.app.projectManager.connect("new-project-loading",
                 self._projectLoadingCb)
 
+        vbox = self.builder.get_object("topvbox")
+        self.infobar = gtk.InfoBar()
+        vbox.pack_start(self.infobar)
+        if self.app.version_information:
+            self._appVersionInfoReceivedCb(None, self.app.version_information)
+        else:
+            self.app.connect("version-info-received", self._appVersionInfoReceivedCb)
+
     def _newProjectCb(self, unused_button):
         """Handle a click on the New (Project) button."""
         self.app.projectManager.newBlankProject()
@@ -132,3 +141,25 @@ class StartUpWizard(object):
     def _projectLoadingCb(self, unused_project_manager, unused_project):
         """Handle the start of a project load operation."""
         self.hide()
+
+    def _appVersionInfoReceivedCb(self, pitivi, version):
+        # current version, don't show message
+        if version["status"].upper() == "CURRENT":
+            return
+
+        # new current version, reset counter
+        if self.app.settings.lastCurrentVersion != version["current"]:
+            self.app.settings.lastCurrentVersion = version["current"]
+            self.app.settings.displayCounter = 0
+
+        # current version info already showed 5 times, don't show again
+        if self.app.settings.displayCounter >= 5:
+            return
+
+        # increment counter, create infobar and show info
+        self.app.settings.displayCounter = self.app.settings.displayCounter + 1
+        text = _("PiTiVi %s is available." % version["current"])
+        label = gtk.Label(text)
+        self.infobar.get_content_area().add(label)
+        self.infobar.set_message_type(gtk.MESSAGE_INFO)
+        self.infobar.show_all()
diff --git a/pitivi/mainwindow.py b/pitivi/mainwindow.py
index d5d6901..13e2c1d 100644
--- a/pitivi/mainwindow.py
+++ b/pitivi/mainwindow.py
@@ -119,6 +119,15 @@ GlobalSettings.addConfigOption('effectVPanedPosition',
     section='effect-configuration',
     key='effect-vpaned-position',
     type_=int)
+GlobalSettings.addConfigSection("version")
+GlobalSettings.addConfigOption('displayCounter',
+    section='version',
+    key='info-displayed-counter',
+    default=0)
+GlobalSettings.addConfigOption('lastCurrentVersion',
+    section='version',
+    key='last-current-version',
+    default='')
 
 
 #FIXME Hacky, reimplement when avalaible in GES
@@ -625,7 +634,15 @@ class PitiviMainWindow(gtk.Window, Loggable):
         ges_version_str = "GES %i.%i.%i.%i" % (ges.version())
         gst_version_str = "GStreamer %i.%i.%i.%i" % (gst.version())
         pygst_version_str = "PyGST %i.%i.%i.%i" % (gst.get_pygst_version())
-        abt.set_comments("%s\n%s\n%s" % (ges_version_str, pygst_version_str, gst_version_str))
+        if self.app.version_information and \
+           self.app.version_information["status"] != "CURRENT":
+            version_str = _("PiTiVi %s is available." %
+                (self.app.version_information["current"]))
+
+            abt.set_comments("%s\n%s\n%s\n\n%s" %
+                (ges_version_str, pygst_version_str, gst_version_str, version_str))
+        else:
+            abt.set_comments("%s\n%s\n%s" % (ges_version_str, pygst_version_str, gst_version_str))
         authors = ["Edward Hervey <bilboed bilboed com>",
                    "Alessandro Decina <alessandro decina collabora co uk>",
                    "Brandon Lewis <brandon_lewis berkeley edu> (UI)",



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