1 # -*- coding: utf-8 -*-
3 # gPodder - A media aggregator and podcast client
4 # Copyright (c) 2005-2010 Thomas Perl and the gPodder Team
6 # gPodder 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.
11 # gPodder 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.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
28 from gpodder
.gtkui
.widgets
import SpinningProgressIndicator
30 class ProgressIndicator(object):
31 # Delayed time until window is shown (for short operations)
34 # Time between GUI updates after window creation
37 def __init__(self
, title
, subtitle
=None, cancellable
=False, parent
=None):
39 self
.subtitle
= subtitle
40 self
.cancellable
= cancellable
43 self
.progressbar
= None
45 self
._initial
_message
= None
46 self
._initial
_progress
= None
47 self
._progress
_set
= False
48 self
.source_id
= gobject
.timeout_add(self
.DELAY
, self
._create
_progress
)
50 def _on_delete_event(self
, window
, event
):
52 self
.dialog
.response(gtk
.RESPONSE_CANCEL
)
55 def _create_progress(self
):
56 if gpodder
.ui
.fremantle
:
57 self
.dialog
= gtk
.Dialog(self
.title
, self
.parent
, 0, \
58 (gtk
.STOCK_CANCEL
, gtk
.RESPONSE_CANCEL
))
60 hildon
.hildon_gtk_window_set_progress_indicator(self
.dialog
, True)
62 self
.dialog
= gtk
.MessageDialog(self
.parent
, \
63 0, 0, gtk
.BUTTONS_CANCEL
, self
.subtitle
or self
.title
)
64 self
.dialog
.label
.set_selectable(False)
65 self
.dialog
.connect('delete-event', self
._on
_delete
_event
)
66 self
.dialog
.set_title(self
.title
)
67 self
.dialog
.set_deletable(self
.cancellable
)
69 self
.dialog
.set_response_sensitive(gtk
.RESPONSE_CANCEL
, \
72 self
.progressbar
= gtk
.ProgressBar()
73 self
.progressbar
.set_ellipsize(pango
.ELLIPSIZE_END
)
75 # If the window is shown after the first update, set the progress
76 # info so that when the window appears, data is there already
77 if self
._initial
_progress
is not None:
78 self
.progressbar
.set_fraction(self
._initial
_progress
)
79 if self
._initial
_message
is not None:
80 self
.progressbar
.set_text(self
._initial
_message
)
82 self
.dialog
.vbox
.add(self
.progressbar
)
83 if not gpodder
.ui
.fremantle
:
84 self
.indicator
= SpinningProgressIndicator()
85 self
.dialog
.set_image(self
.indicator
)
86 self
.dialog
.show_all()
88 gobject
.source_remove(self
.source_id
)
89 self
.source_id
= gobject
.timeout_add(self
.INTERVAL
, self
._update
_gui
)
92 def _update_gui(self
):
94 self
.indicator
.step_animation()
95 if not self
._progress
_set
and self
.progressbar
:
96 self
.progressbar
.pulse()
99 def on_message(self
, message
):
101 self
.progressbar
.set_text(message
)
103 self
._initial
_message
= message
105 def on_progress(self
, progress
):
106 self
._progress
_set
= True
108 self
.progressbar
.set_fraction(progress
)
110 self
._initial
_progress
= progress
112 def on_finished(self
):
113 if self
.dialog
is not None:
114 self
.dialog
.destroy()
115 gobject
.source_remove(self
.source_id
)