~ubuntu-branches/ubuntu/natty/exaile/natty

« back to all changes in this revision

Viewing changes to xl/plugins/gui.py

  • Committer: Bazaar Package Importer
  • Author(s): Nick Ellery
  • Date: 2008-11-04 18:33:00 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20081104183300-e4t9seztl35bdb24
Tags: 0.2.14-0ubuntu1
* New upstream release (LP: #280287)
* debian/control:
  - tighten dependency on python-gtk2 to (>= 2.10)
  - added python-sexy to recommends to add a clear button to filters
  - added python-gnome2-extras to recommends for lyrics, better tray icon,
    etc.

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
        self.parent = parent
48
48
        self.update = update
49
49
        self.manager = manager
 
50
        self.lists = dict()
 
51
        self.models = dict()
 
52
        self.author_labels = dict()
 
53
        self.descriptions = dict()
 
54
        self.version_labels = dict()
 
55
        self.name_labels = dict()
50
56
 
51
57
        self.xml = gtk.glade.XML('xl/plugins/plugins.glade',
52
58
            'PluginManagerDialog','exaile')
66
72
        self.configure_button.connect('clicked', self.configure_plugin)
67
73
        self.plugin_install_button = self.xml.get_widget('plugin_install_button')
68
74
        self.plugin_install_button.connect('clicked',
69
 
            self.install_plugin)
 
75
            lambda *e: self.install_plugin('avail'))
 
76
        self.plugin_update_button = self.xml.get_widget('plugin_update_button')
 
77
        self.plugin_update_button.connect('clicked',
 
78
            lambda *e: self.install_plugin('update'))
70
79
        self.xml.get_widget('plugin_uninstall_button').connect('clicked',
71
80
            self.uninstall_plugin)
72
81
 
103
112
        self.fetched = False
104
113
 
105
114
        if avail_url:
106
 
            self.setup_avail_tab()
 
115
            self.setup_tab('avail')
 
116
            self.setup_tab('update')
107
117
            self.avail_url = avail_url
108
 
            self.plugin_nb.connect('switch-page', self.check_fetch_avail)
 
118
            self.plugin_nb.connect('switch-page', lambda *e: self.check_fetch('avail'))
109
119
 
110
120
    def load_plugin_list(self):
111
121
        self.model.clear()
126
136
        for p in list:
127
137
            self.model.append(p)
128
138
 
129
 
    def install_plugin(self, *e):
 
139
    def install_plugin(self, type='avail'):
130
140
        """
131
141
            Installs the selected plugin
132
142
        """
133
143
        self.plugin_install_button.set_sensitive(False)
 
144
        self.plugin_update_button.set_sensitive(False)
134
145
        self.plugin_nb.set_sensitive(False)
135
 
        self.download_plugins()
 
146
        self.download_plugins(type)
136
147
 
137
 
    def done_installing(self, files):
 
148
    def done_installing(self, files, type='avail'):
138
149
        # now we remove all the installed plugins from the available list
139
150
        while True:
140
 
            iter = self.avail_model.get_iter_first()
 
151
            iter = self.models[type].get_iter_first()
141
152
            while True:
142
153
                if not iter: break
143
 
                file = self.avail_model.get_value(iter, 4)
 
154
                file = self.models[type].get_value(iter, 4)
144
155
                if file in files:
145
 
                    self.avail_model.remove(iter)
 
156
                    self.models[type].remove(iter)
146
157
                    break
147
 
                iter = self.avail_model.iter_next(iter)
 
158
                iter = self.models[type].iter_next(iter)
148
159
            if not iter: break
149
160
        self.plugin_install_button.set_sensitive(True)
 
161
        self.plugin_update_button.set_sensitive(True)
150
162
        self.load_plugin_list()
151
163
        self.plugin_nb.set_sensitive(True)
152
164
 
153
 
        self.avail_version_label.set_text('')
154
 
        self.avail_author_label.set_text('')
155
 
        self.avail_name_label.set_markup('<b>' + _('No Plugin Selected') +
 
165
        self.version_labels[type].set_text('')
 
166
        self.author_labels[type].set_text('')
 
167
        self.name_labels[type].set_markup('<b>' + _('No Plugin Selected') +
156
168
            '</b>')
157
 
        self.avail_description.get_buffer().set_text('')
 
169
        self.descriptions[type].get_buffer().set_text('')
158
170
 
159
171
    @common.threaded
160
 
    def download_plugins(self):
 
172
    def download_plugins(self, type='avail'):
161
173
        """
162
174
            Downloads the selected plugin
163
175
        """
164
176
        download_dir = xl.path.get_config('plugins')
165
177
        files = []
166
 
        iter = self.avail_model.get_iter_first()
 
178
        iter = self.models[type].get_iter_first()
167
179
        while True:
168
180
            if not iter: break
169
181
 
170
 
            checked = self.avail_model.get_value(iter, 5)
 
182
            checked = self.models[type].get_value(iter, 5)
171
183
            if checked:
172
 
                file = self.avail_model.get_value(iter, 4)
 
184
                file = self.models[type].get_value(iter, 4)
173
185
 
174
186
                try:
175
187
                    # if the directory does not exist, create it
209
221
                        enabled_plugins, False, avail_plugins)
210
222
                    files.append(file)
211
223
                except Exception, e:
212
 
                    self.model.set_value(iter, 5, False)
 
224
                    self.models[type].set_value(iter, 5, False)
213
225
                    gobject.idle_add(common.error, self.parent, _("%(plugin)s could "
214
226
                        "not be installed: %(exception)s") % 
215
227
                        {
217
229
                            'exception': e
218
230
                        })
219
231
                    xlmisc.log_exception()
220
 
            iter = self.avail_model.iter_next(iter)
221
 
 
222
 
        gobject.idle_add(self.done_installing, files)
223
 
 
224
 
    def check_fetch_avail(self, *e):
 
232
            iter = self.models[type].iter_next(iter)
 
233
 
 
234
        gobject.idle_add(self.done_installing, files, type)
 
235
 
 
236
    def check_fetch(self, type='avail'):
225
237
        """
226
238
            Checks to see if the available plugin list needs to be fetched
227
239
        """
228
240
        if self.plugin_nb.get_current_page() != 0 or self.fetched: return
229
241
        self.fetched = True
230
 
        self.avail_version_label.set_text('')
231
 
        self.avail_author_label.set_text('')
232
 
        self.avail_name_label.set_markup('<b>' + _('No Plugin Selected') + '</b>')
233
 
        self.avail_description.get_buffer().set_text(_("Fetching available"
 
242
        self.version_labels[type].set_text('')
 
243
        self.author_labels[type].set_text('')
 
244
        self.name_labels[type].set_markup('<b>' + _('No Plugin Selected') + '</b>')
 
245
        self.descriptions[type].get_buffer().set_text(_("Fetching available"
234
246
            " plugin list..."))
235
 
        self.avail_model.clear()
 
247
        self.models[type].clear()
236
248
        self.fetch_available_plugins(self.avail_url)
237
249
        xlmisc.log('Fetching available plugin list')
238
250
 
249
261
    def done_fetching(self, lines):
250
262
 
251
263
        plugin_list = []
 
264
        update_list = []
252
265
        check = False
253
266
        for line in lines:
254
267
            line = line.strip()
265
278
                    #this is a bit odd, to allow non-decimal versioning.
266
279
                    installed_ver = map(int, plugin.PLUGIN_VERSION.split('.'))
267
280
                    available_ver = map(int, version.split('.'))
 
281
            
 
282
                    found = True
268
283
 
269
 
                    if installed_ver >= available_ver:
270
 
                        found = True
 
284
                    # if there is an update available
 
285
                    if installed_ver < available_ver:
 
286
                        update_list.append([name, version, author,
 
287
                            description, file, False])
 
288
                        check = True
271
289
 
272
290
            if not found:
273
291
                plugin_list.append([name, version, author, description, file, False])
281
299
                return locale.strcoll(a[0].lower(), b[0].lower())
282
300
 
283
301
            plugin_list.sort(plugin_sort)
 
302
            update_list.sort(plugin_sort)
284
303
            for plugin in plugin_list:
285
 
                self.avail_model.append(plugin)
286
 
 
287
 
        self.avail_description.get_buffer().set_text(_("No plugin selected"))
288
 
        selection = self.avail_list.get_selection()
289
 
        selection.select_path(0)
290
 
        self.avail_row_selected(selection)
291
 
 
292
 
    def setup_avail_tab(self):
 
304
                self.models['avail'].append(plugin)
 
305
            for plugin in update_list:
 
306
                self.models['update'].append(plugin)
 
307
 
 
308
        for type in self.descriptions.keys():
 
309
            self.descriptions[type].get_buffer().set_text(_("No plugin selected"))
 
310
            selection = self.lists[type].get_selection()
 
311
            selection.select_path(0)
 
312
            self.t_row_selected(type, selection)
 
313
 
 
314
    def setup_tab(self, type='avail'):
293
315
        """
294
316
            Sets up the "plugins available" tab
295
317
        """
296
 
        self.avail_model = gtk.ListStore(str, str, str, str,
 
318
        self.models[type] = gtk.ListStore(str, str, str, str,
297
319
            str, bool)
298
 
        self.avail_list = self.xml.get_widget('avail_plugin_tree')
299
 
        self.avail_version_label = self.xml.get_widget('avail_version_label')
300
 
        self.avail_author_label = self.xml.get_widget('avail_author_label')
301
 
        self.avail_name_label = self.xml.get_widget('avail_name_label')
302
 
        self.avail_description = self.xml.get_widget('avail_description_view')
 
320
        self.lists[type] = self.xml.get_widget('%s_plugin_tree' % type)
 
321
        self.version_labels[type] = self.xml.get_widget('%s_version_label' %
 
322
            type)
 
323
        self.author_labels[type] = self.xml.get_widget('%s_author_label' %
 
324
            type)
 
325
        self.name_labels[type] = self.xml.get_widget('%s_name_label' % type)
 
326
        self.descriptions[type] = self.xml.get_widget('%s_description_view' %
 
327
            type)
303
328
 
304
329
        text = gtk.CellRendererText()
305
330
        col = gtk.TreeViewColumn(_('Plugin'))
308
333
        col.set_fixed_width(120)
309
334
        col.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
310
335
        col.set_attributes(text, text=0)
311
 
        self.avail_list.append_column(col)
 
336
        self.lists[type].append_column(col)
312
337
 
313
338
        text = gtk.CellRendererText()
314
339
        # TRANSLATORS: The column title for plugin versions
317
342
        col.set_expand(False)
318
343
        col.set_sizing(gtk.TREE_VIEW_COLUMN_AUTOSIZE)
319
344
        col.set_attributes(text, text=1)
320
 
        self.avail_list.append_column(col)
 
345
        self.lists[type].append_column(col)
321
346
 
322
347
        text = gtk.CellRendererToggle()
323
348
        text.set_property('activatable', True)
324
 
        text.connect('toggled', self.avail_toggle_cb, self.avail_model)
 
349
        text.connect('toggled', self.t_toggle_cb, self.models[type])
325
350
        # TRANSLATORS: The column title for the plugin installation statuses
326
351
        col = gtk.TreeViewColumn(_("Inst"), text)
327
352
        col.add_attribute(text, 'active', 5)
328
353
        col.set_expand(False)
329
354
        col.set_sizing(gtk.TREE_VIEW_COLUMN_AUTOSIZE)
330
 
        self.avail_list.append_column(col)
 
355
        self.lists[type].append_column(col)
331
356
 
332
 
        self.avail_list.set_model(self.avail_model)
333
 
        self.avail_description.get_buffer().set_text(_("Fetching available"
 
357
        self.lists[type].set_model(self.models[type])
 
358
        self.descriptions[type].get_buffer().set_text(_("Fetching available"
334
359
            " plugin list..."))
335
 
        selection = self.avail_list.get_selection()
336
 
        selection.connect('changed', self.avail_row_selected)
 
360
        selection = self.lists[type].get_selection()
 
361
        selection.connect('changed', lambda selection, type=type: 
 
362
            self.t_row_selected(type, selection))
337
363
 
338
 
    def avail_row_selected(self, selection):
 
364
    def t_row_selected(self, type, selection):
339
365
        """
340
366
            Called when a user selects a row in the avialable tab
341
367
        """
347
373
        author = model.get_value(iter, 2)
348
374
        description = model.get_value(iter, 3)
349
375
 
350
 
        self.avail_name_label.set_markup('<b>%s</b>' % common.escape_xml(name))
351
 
        self.avail_version_label.set_label(version)
352
 
        self.avail_author_label.set_label(author)
353
 
        self.avail_description.get_buffer().set_text(description)
 
376
        self.name_labels[type].set_markup('<b>%s</b>' % common.escape_xml(name))
 
377
        self.version_labels[type].set_label(version)
 
378
        self.author_labels[type].set_label(author)
 
379
        self.descriptions[type].get_buffer().set_text(description)
354
380
 
355
 
    def avail_toggle_cb(self, cell, path, model):
 
381
    def t_toggle_cb(self, cell, path, model):
356
382
        model[path][5] = not model[path][5]
357
383
 
358
384
    def toggle_cb(self, cell, path, model):