Tons of fixes/tweaks/changes in general
[jamaendo] / jamaui / refresh.py
1 #!/usr/bin/env python
2 #
3 # This file is part of Jamaendo.
4 # Copyright (c) 2010 Kristoffer Gronlund
5 #
6 # Jamaendo is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # Jamaendo is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with Jamaendo.  If not, see <http://www.gnu.org/licenses/>.
18 #
19 # Player code heavily based on http://thpinfo.com/2008/panucci/:
20 #  A resuming media player for Podcasts and Audiobooks
21 #  Copyright (c) 2008-05-26 Thomas Perl <thpinfo.com>
22 #  (based on http://pygstdocs.berlios.de/pygst-tutorial/seeking.html)
23 #
24
25 class RefreshDialog(object):
26     def __init__(self):
27         self.notebook = gtk.Notebook()
28         info = gtk.VBox()
29         info.pack_start(gtk.Label("Downloading complete DB from jamendo.com."), True, False)
30         info.pack_start(gtk.Label("This will download approximately 8 MB."), True, False)
31         self.force = hildon.GtkToggleButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
32         self.force.set_label("Force refresh")
33
34         info.pack_start(self.force, True, False)
35         self.notebook.append_page(info)
36
37         pcont = gtk.VBox()
38         self.progress = gtk.ProgressBar()
39         pcont.pack_start(self.progress, True, False)
40         self.notebook.append_page(pcont,
41                                   gtk.Label("Updating Database"))
42         self.progress.set_fraction(0)
43         self.progress.set_orientation(gtk.PROGRESS_LEFT_TO_RIGHT)
44         self.progress.set_text("Downloading...")
45
46         self.notebook.append_page(gtk.Label("Database refreshed."))
47
48         self.dialog = hildon.WizardDialog(None, "Refresh", self.notebook)
49         self.notebook.connect("switch-page", self.on_switch)
50         self.dialog.set_forward_page_func(self.forward_func)
51
52         self.refresher = None
53
54     def on_complete(self, status):
55         hildon.hildon_gtk_window_set_progress_indicator(self.dialog, 0)
56         if status:
57             self.progress.set_fraction(1)
58             self.progress.set_text("DB up to date.")
59         else:
60             self.progress.set_fraction(0)
61             self.progress.set_text("Download failed.")
62
63     def on_progress(self, percent):
64         if percent < 100:
65             self.progress.set_text("Downloading...")
66         self.progress.set_fraction(percent/100.0)
67
68     def on_switch(self, notebook, page, num):
69         if num == 1:
70             hildon.hildon_gtk_window_set_progress_indicator(self.dialog, 1)
71             refresh_dump(self.on_complete, self.on_progress, force=self.force.get_active())
72         elif self.refresher:
73             # cancel download
74             pass
75         return True
76
77     def forward_func(self, notebook, current, userdata):
78         #page = notebook.get_nth_page(current)
79         if current == 0:
80             return True
81         else:
82             return False
83
84     def show_all(self):
85         self.dialog.show_all()
86
87     def run(self):
88         self.dialog.run()
89
90     def hide(self):
91         self.dialog.hide()