~ubuntu-branches/ubuntu/quantal/rhythmbox-ampache/quantal

« back to all changes in this revision

Viewing changes to ampache/__init__.py

  • Committer: Bazaar Package Importer
  • Author(s): Charlie Smotherman
  • Date: 2011-01-12 17:12:50 UTC
  • Revision ID: james.westby@ubuntu.com-20110112171250-wo8fx5u5hvilaumb
Tags: upstream-0.11.1
ImportĀ upstreamĀ versionĀ 0.11.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- Mode: python; coding: utf-8; tab-width: 8; indent-tabs-mode: t; -*-
 
2
 
 
3
import rhythmdb, rb
 
4
import gobject
 
5
import gtk
 
6
 
 
7
from AmpacheConfig import AmpacheConfig
 
8
from AmpacheConfigDialog import AmpacheConfigDialog
 
9
from AmpacheBrowser import AmpacheBrowser
 
10
 
 
11
ui_str = """
 
12
<ui>
 
13
  <menubar name="MenuBar">
 
14
    <menu name="ToolsMenu" action="Tools">
 
15
      <placeholder name="ToolsOps_5">
 
16
        <menuitem name="Re-fetch Ampache Library" action="RefetchAmpache"/>
 
17
      </placeholder>
 
18
    </menu>
 
19
  </menubar>
 
20
</ui>
 
21
"""
 
22
 
 
23
class AmpacheEntryType(rhythmdb.EntryType):
 
24
        def __init__(self):
 
25
                rhythmdb.EntryType.__init__(self, name='AmpacheEntryType')
 
26
 
 
27
class Ampache(rb.Plugin):
 
28
        def __init__(self):
 
29
                self.config = AmpacheConfig()
 
30
 
 
31
                rb.Plugin.__init__(self)
 
32
 
 
33
        def activate(self, shell):
 
34
                self.db = shell.props.db
 
35
 
 
36
                self.entry_type = AmpacheEntryType()
 
37
                self.entry_type.can_sync_metadata = True
 
38
                self.entry_type.sync_metadata = None
 
39
                self.entry_type.category = rhythmdb.ENTRY_STREAM
 
40
 
 
41
                group = rb.rb_source_group_get_by_name(self.config.get("group"))
 
42
                if not group:
 
43
                        group = rb.rb_source_group_register (
 
44
                                "ampache",
 
45
                                self.config.get("group"),
 
46
                                rb.SOURCE_GROUP_CATEGORY_FIXED,
 
47
                        )
 
48
 
 
49
 
 
50
                self.source = gobject.new (
 
51
                        AmpacheBrowser,
 
52
                        entry_type=self.entry_type,
 
53
                        source_group=group,
 
54
                        name=self.config.get("name"),
 
55
                        shell=shell,
 
56
                )
 
57
 
 
58
                self.config.set("icon_filename", self.find_file(self.config.get("icon")))
 
59
                self.source.activate(self.config)
 
60
 
 
61
                shell.register_entry_type_for_source(self.source, self.entry_type)
 
62
                shell.append_source(self.source, None)
 
63
 
 
64
                ui_manager = shell.get_ui_manager()
 
65
                action = gtk.Action('RefetchAmpache', 
 
66
                                    _('_Re-fetch Ampache Library'), 
 
67
                                    _('Update the local ampache library'), "")
 
68
                action.connect ('activate', self.refetch_ampache, shell)
 
69
                action_group = gtk.ActionGroup ('RefetchAmpacheGroup')
 
70
                action_group.add_action(action)
 
71
                ui_manager.insert_action_group(action_group, -1)
 
72
                self.uid = ui_manager.add_ui_from_string(ui_str)
 
73
                ui_manager.ensure_update()
 
74
 
 
75
        def deactivate(self, shell):
 
76
                self.db.entry_delete_by_type(self.entry_type)
 
77
                self.db.commit()
 
78
                del self.db
 
79
                self.db = None
 
80
 
 
81
                self.entry_type = None
 
82
 
 
83
                self.source.delete_thyself()
 
84
                del self.source
 
85
                self.source = None
 
86
 
 
87
                # clean up the UI
 
88
                ui_manager = shell.get_ui_manager()
 
89
                ui_manager.remove_ui(self.uid)
 
90
 
 
91
        def create_configure_dialog(self):
 
92
                glade_file = self.find_file("ampache-prefs.glade")
 
93
 
 
94
                if glade_file:
 
95
                        dialog = AmpacheConfigDialog(glade_file, self.config).get_dialog()
 
96
 
 
97
                if dialog:
 
98
                        return dialog
 
99
                else:
 
100
                        print "couldn't create configure dialog"
 
101
                        return None
 
102
 
 
103
        def refetch_ampache(self, widget, shell):
 
104
                self.source.download_db()