Fix bug in text edit dialog (no response)
[gpodder.git] / src / gpodder / __init__.py
bloba3c65dfbfce425400acb1c0406a58503f6b652d4
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.5'
22 __date__ = '2010-04-20'
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
44 try:
45 import mygpoclient
46 except ImportError:
47 print """
48 Error: Module "mygpoclient" not found. Please install "python-mygpoclient"
49 or download it from http://thpinfo.com/2010/mygpoclient/
50 """
51 sys.exit(1)
52 del mygpoclient
54 # The User-Agent string for downloads
55 user_agent = 'gPodder/%s (+%s)' % (__version__, __url__)
57 # Are we running in GUI, Maemo or console mode?
58 class UI(object):
59 def __init__(self):
60 self.desktop = False
61 self.diablo = False
62 self.fremantle = False
64 @property
65 def maemo(self):
66 return self.diablo or self.fremantle
68 ui = UI()
70 # D-Bus specific interface names
71 dbus_bus_name = 'org.gpodder'
72 dbus_gui_object_path = '/gui'
73 dbus_podcasts_object_path = '/podcasts'
74 dbus_interface = 'org.gpodder.interface'
75 dbus_podcasts = 'org.gpodder.podcasts'
77 # Set "win32" to True if we are on Windows
78 win32 = (platform.system() == 'Windows')
80 # i18n setup (will result in "gettext" to be available)
81 # Use _ = gpodder.gettext in modules to enable string translations
82 textdomain = 'gpodder'
83 locale_dir = gettext.bindtextdomain(textdomain)
84 t = gettext.translation(textdomain, locale_dir, fallback=True)
85 gettext = t.ugettext
86 ngettext = t.ungettext
87 if win32:
88 # Workaround for bug 650
89 from gtk.glade import bindtextdomain
90 bindtextdomain(textdomain, locale_dir)
91 del bindtextdomain
92 del t
94 # Set up textdomain for gtk.Builder (this accesses the C library functions)
95 if hasattr(locale, 'bindtextdomain'):
96 locale.bindtextdomain(textdomain, locale_dir)
97 else:
98 # On Win32, the locale module does not have bindtextdomain. We use a
99 # small module that provides similar functionality here (from doc/dev/).
100 try:
101 import gtkbuilderi18n
102 gtkbuilderi18n.bindtextdomain(textdomain, locale_dir)
103 except ImportError, ioe:
104 pass
106 del locale_dir
108 # Set up socket timeouts to fix bug 174
109 SOCKET_TIMEOUT = 60
110 import socket
111 socket.setdefaulttimeout(SOCKET_TIMEOUT)
112 del socket
113 del SOCKET_TIMEOUT
115 # Variables reserved for GUI-specific use (will be set accordingly)
116 ui_folders = []
117 credits_file = None
118 icon_file = None
119 images_folder = None
121 # Episode states used in the database
122 STATE_NORMAL, STATE_DOWNLOADED, STATE_DELETED = range(3)
124 # Default locations for configuration and data files
125 default_home = os.path.expanduser(os.path.join('~', '.config', 'gpodder'))
126 home = os.environ.get('GPODDER_HOME', None)
127 if home is None:
128 home = default_home
129 else:
130 print >>sys.stderr, 'Using', home, 'to store data (GPODDER_HOME is set)'
131 subscription_file = os.path.join(home, 'channels.opml')
132 config_file = os.path.join(home, 'gpodder.conf')
133 database_file = os.path.join(home, 'database.sqlite')
135 # Plugins to load by default
136 DEFAULT_PLUGINS = ['gpodder.soundcloud']
138 def load_plugins():
139 """Load (non-essential) plugin modules
141 This loads a default set of plugins, but you can use
142 the environment variable "GPODDER_PLUGINS" to modify
143 the list of plugins."""
144 global DEFAULT_PLUGINS
145 PLUGINS = os.environ.get('GPODDER_PLUGINS', None)
146 if PLUGINS is None:
147 PLUGINS = DEFAULT_PLUGINS
148 else:
149 PLUGINS = PLUGINS.split()
150 import imp
151 for plugin in PLUGINS:
152 try:
153 __import__(plugin)
154 print >>sys.stderr, 'Plugin loaded:', plugin
155 except Exception, e:
156 print >>sys.stderr, 'Cannot load plugin: %s (%s)' % (plugin, e)