root/branches/gajim_0.7.1/src/check_for_new_version.py

Revision 1369, 2.9 kB (checked in by nk, 4 years ago)

it's better like that. after 0.7 I hopefully will pass the socket to main()

Line 
1##      common/check_for_new_version.py
2##
3## Gajim Team:
4## - Yann Le Boulanger <asterix@lagaule.org>
5## - Vincent Hanquez <tab@snarc.org>
6## - Nikos Kouremenos <kourem@gmail.com>
7##
8##      Copyright (C) 2003-2005 Gajim Team
9##
10## This program is free software; you can redistribute it and/or modify
11## it under the terms of the GNU General Public License as published
12## by the Free Software Foundation; version 2 only.
13##
14## This program is distributed in the hope that it will be useful,
15## but WITHOUT ANY WARRANTY; without even the implied warranty of
16## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17## GNU General Public License for more details.
18##
19
20import gtk
21import gtk.glade
22
23from common import gajim
24from common import i18n
25
26_ = i18n._
27APP = i18n.APP
28gtk.glade.bindtextdomain(APP, i18n.DIR)
29gtk.glade.textdomain(APP)
30
31GTKGUI_GLADE='gtkgui.glade'
32
33class Check_for_new_version_dialog:
34        def __init__(self, plugin):
35                self.plugin = plugin
36                try:
37                        self.check_for_new_version()
38                except:
39                        pass
40
41        def parse_glade(self):
42                xml = gtk.glade.XML(GTKGUI_GLADE, 'new_version_available_dialog', APP)
43                self.window = xml.get_widget('new_version_available_dialog')
44                self.information_label = xml.get_widget('information_label')
45                self.changes_textview = xml.get_widget('changes_textview')
46                xml.signal_autoconnect(self)
47
48        def on_new_version_available_dialog_delete_event(self, widget, event):
49                self.window.destroy()
50
51        def on_open_download_page_button_clicked(self, widget):
52                url = 'http://www.gajim.org/downloads.php?lang='
53                self.plugin.launch_browser_mailer('url', url)
54                self.window.destroy()
55
56        def check_for_new_version(self):
57                '''parse online Changelog to find out last version
58                and the changes for that latest version'''
59                import urllib2
60                import socket
61                dto = socket.getdefaulttimeout()
62                socket.setdefaulttimeout(5)
63
64                url = 'http://trac.gajim.org/file/trunk/Changelog?rev=latest&format=txt'
65                changelog = urllib2.urlopen(url)
66
67                socket.setdefaulttimeout(dto)
68
69                # format is 'Gajim version (date)'
70                first_line = changelog.readline()
71                finish_version = first_line.find(' ', 6) # start search after 'Gajim'
72                latest_version = first_line[6:finish_version]
73                if latest_version > gajim.version:
74                        start_date = finish_version + 2 # one space and one (
75                        date = first_line[start_date:-2] # remove the last ) and \n
76                        info = 'Gajim ' + latest_version + ' was released in ' + date + '!'
77                        changes = ''
78                        while True:
79                                line = changelog.readline().lstrip()
80                                if line.startswith('Gajim'):
81                                        break
82                                else:
83                                        if line != '\n' or line !='': # line has some content
84                                                if not line.startswith('*'):
85                                                        # the is not a new *real* line
86                                                        # but a continuation from previous line.
87                                                        # So remove \n from previous 'line' beforing adding it
88                                                        changes = changes[:-1]
89
90                                                changes += line
91                       
92                        self.parse_glade()
93                        self.information_label.set_text(info)
94                        buf = self.changes_textview.get_buffer()
95                        buf.set_text(changes)
96                        self.window.show_all()
Note: See TracBrowser for help on using the browser.