2d08955318e3cbadd421fa908da95ab07c6cbb74
[jamaendo] / jamaui / refresh.py
1 class RefreshDialog(object):
2     def __init__(self):
3         self.notebook = gtk.Notebook()
4         info = gtk.VBox()
5         info.pack_start(gtk.Label("Downloading complete DB from jamendo.com."), True, False)
6         info.pack_start(gtk.Label("This will download approximately 8 MB."), True, False)
7         self.force = hildon.GtkToggleButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
8         self.force.set_label("Force refresh")
9
10         info.pack_start(self.force, True, False)
11         self.notebook.append_page(info)
12
13         pcont = gtk.VBox()
14         self.progress = gtk.ProgressBar()
15         pcont.pack_start(self.progress, True, False)
16         self.notebook.append_page(pcont,
17                                   gtk.Label("Updating Database"))
18         self.progress.set_fraction(0)
19         self.progress.set_orientation(gtk.PROGRESS_LEFT_TO_RIGHT)
20         self.progress.set_text("Downloading...")
21
22         self.notebook.append_page(gtk.Label("Database refreshed."))
23
24         self.dialog = hildon.WizardDialog(None, "Refresh", self.notebook)
25         self.notebook.connect("switch-page", self.on_switch)
26         self.dialog.set_forward_page_func(self.forward_func)
27
28         self.refresher = None
29
30     def on_complete(self, status):
31         hildon.hildon_gtk_window_set_progress_indicator(self.dialog, 0)
32         if status:
33             self.progress.set_fraction(1)
34             self.progress.set_text("DB up to date.")
35         else:
36             self.progress.set_fraction(0)
37             self.progress.set_text("Download failed.")
38
39     def on_progress(self, percent):
40         if percent < 100:
41             self.progress.set_text("Downloading...")
42         self.progress.set_fraction(percent/100.0)
43
44     def on_switch(self, notebook, page, num):
45         if num == 1:
46             hildon.hildon_gtk_window_set_progress_indicator(self.dialog, 1)
47             refresh_dump(self.on_complete, self.on_progress, force=self.force.get_active())
48         elif self.refresher:
49             # cancel download
50             pass
51         return True
52
53     def forward_func(self, notebook, current, userdata):
54         #page = notebook.get_nth_page(current)
55         if current == 0:
56             return True
57         else:
58             return False
59
60     def show_all(self):
61         self.dialog.show_all()
62
63     def run(self):
64         self.dialog.run()
65
66     def hide(self):
67         self.dialog.hide()