Fix typo: D-Bus bus name of gPodder (bug 772)
[gpodder.git] / src / gpodder / __init__.py
bloba795a3c1acd6e793d727bc49dbe2c44fe4e59f90
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/>.
20 __author__ = 'Thomas Perl <thp@gpodder.org>'
21 __version__ = '2.1'
22 __date__ = '2009-12-12'
23 __copyright__ = '© 2005-2010 Thomas Perl and the gPodder Team'
24 __licence__ = 'GNU General Public License, version 3 or later'
25 __url__ = 'http://gpodder.org/'
27 import os
28 import sys
29 import platform
30 import gettext
31 import locale
33 # Check if real hard dependencies are available
34 try:
35 import feedparser
36 except ImportError:
37 print """
38 Error: Module "feedparser" not found. Please install "python-feedparser".
39 The feedparser module can be downloaded from www.feedparser.org.
40 """
41 sys.exit(1)
42 del feedparser
45 # The User-Agent string for downloads
46 user_agent = 'gPodder/%s (+%s)' % (__version__, __url__)
48 # Are we running in GUI, Maemo or console mode?
49 class UI(object):
50 def __init__(self):
51 self.desktop = False
52 self.diablo = False
53 self.fremantle = False
55 @property
56 def maemo(self):
57 return self.diablo or self.fremantle
59 ui = UI()
61 # D-Bus specific interface names
62 dbus_bus_name = 'org.gpodder'
63 dbus_gui_object_path = '/gui'
64 dbus_podcasts_object_path = '/podcasts'
65 dbus_interface = 'org.gpodder.interface'
66 dbus_podcasts = 'org.gpodder.podcasts'
68 # Set "win32" to True if we are on Windows
69 win32 = (platform.system() == 'Windows')
71 # i18n setup (will result in "gettext" to be available)
72 # Use _ = gpodder.gettext in modules to enable string translations
73 textdomain = 'gpodder'
74 locale_dir = gettext.bindtextdomain(textdomain)
75 t = gettext.translation(textdomain, locale_dir, fallback=True)
76 gettext = t.ugettext
77 ngettext = t.ungettext
78 if win32:
79 # Workaround for bug 650
80 from gtk.glade import bindtextdomain
81 bindtextdomain(textdomain, locale_dir)
82 del bindtextdomain
83 del t
85 # Set up textdomain for gtk.Builder (this accesses the C library functions)
86 if hasattr(locale, 'bindtextdomain'):
87 locale.bindtextdomain(textdomain, locale_dir)
88 else:
89 # On Win32, the locale module does not have bindtextdomain. We use a
90 # small module that provides similar functionality here (from doc/dev/).
91 try:
92 import gtkbuilderi18n
93 gtkbuilderi18n.bindtextdomain(textdomain, locale_dir)
94 except ImportError, ioe:
95 pass
97 del locale_dir
99 # Set up socket timeouts to fix bug 174
100 SOCKET_TIMEOUT = 60
101 import socket
102 socket.setdefaulttimeout(SOCKET_TIMEOUT)
103 del socket
104 del SOCKET_TIMEOUT
106 # Variables reserved for GUI-specific use (will be set accordingly)
107 ui_folders = []
108 credits_file = None
109 icon_file = None
111 # Episode states used in the database
112 STATE_NORMAL, STATE_DOWNLOADED, STATE_DELETED = range(3)
114 # Default locations for configuration and data files
115 default_home = os.path.expanduser(os.path.join('~', '.config', 'gpodder'))
116 home = os.environ.get('GPODDER_HOME', None)
117 if home is None:
118 home = default_home
119 else:
120 print >>sys.stderr, 'Using', home, 'to store data (GPODDER_HOME is set)'
121 subscription_file = os.path.join(home, 'channels.opml')
122 config_file = os.path.join(home, 'gpodder.conf')
123 database_file = os.path.join(home, 'database.sqlite')
125 # Plugins to load by default
126 DEFAULT_PLUGINS = ['gpodder.soundcloud']
128 def load_plugins():
129 """Load (non-essential) plugin modules
131 This loads a default set of plugins, but you can use
132 the environment variable "GPODDER_PLUGINS" to modify
133 the list of plugins."""
134 global DEFAULT_PLUGINS
135 PLUGINS = os.environ.get('GPODDER_PLUGINS', None)
136 if PLUGINS is None:
137 PLUGINS = DEFAULT_PLUGINS
138 else:
139 PLUGINS = PLUGINS.split()
140 import imp
141 for plugin in PLUGINS:
142 try:
143 __import__(plugin)
144 print >>sys.stderr, 'Plugin loaded:', plugin
145 except Exception, e:
146 print >>sys.stderr, 'Cannot load plugin: %s (%s)' % (plugin, e)