song: use string.Template for expanding $tags.
[nephilim.git] / nephilim / nephilim_app.py
blobc56c6f0129a706c764427ca9fefa955152164fe7
2 # Copyright (C) 2009 Anton Khirnov <wyskas@gmail.com>
4 # Nephilim is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # Nephilim is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with Nephilim. If not, see <http://www.gnu.org/licenses/>.
18 from PyQt4 import QtGui, QtCore
20 from winMain import winMain
21 from common import ORGNAME, APPNAME, appIcon
22 from mpclient import MPClient
23 from settings_wg import SettingsWidget
24 from connect_wg import ConnectWidget
25 import plugins
26 import icons
28 class NephilimApp(QtGui.QApplication):
29 # public, constant
30 "main window object"
31 main_win = None
32 "MPD layer"
33 mpclient = None
34 "plugins interface"
35 plugins = None
36 "settings object"
37 settings = None
39 # private
40 "settings window"
41 __settings_win = None
42 "connection window"
43 __connect_win = None
45 def __init__(self, argv):
46 QtGui.QApplication.__init__(self, argv)
48 self.setApplicationName(APPNAME)
49 self.setOrganizationName(ORGNAME)
50 self.setWindowIcon(QtGui.QIcon(appIcon))
52 def exec_(self):
53 #init MPD layer
54 self.mpclient = MPClient()
56 #init settings
57 self.settings = QtCore.QSettings()
59 #init connection window
60 self.__connect_win = ConnectWidget()
62 #init main window
63 self.main_win = winMain(self.mpclient)
65 #init plugins
66 show_settings = False # are there new plugins?
67 self.plugins = plugins.Plugins(self.main_win, self.mpclient)
68 for plugin in self.plugins.plugins():
69 if self.settings.value(plugin.name + '/load') == None:
70 show_settings = True
71 if self.settings.value(plugin.name + '/load', QtCore.QVariant(True)).toBool():
72 self.plugins.load(plugin.name)
74 self.aboutToQuit.connect(self.__cleanup)
77 if show_settings:
78 self.show_settings_win()
79 self.main_win.restore_layout()
80 self.__connect_win.monitor()
82 QtGui.QApplication.exec_()
84 def __cleanup(self):
85 # unload all plugins
86 for plugin in self.plugins.loaded_plugins():
87 plugin.unload()
89 self.main_win.on_quit()
90 self.settings.sync()
92 def show_settings_win(self):
93 if not self.__settings_win:
94 self.__settings_win = SettingsWidget(self.mpclient, self.plugins)
96 self.__settings_win.show()
97 self.__settings_win.raise_()
99 def show_connect_win(self):
100 self.__connect_win.monitor()
102 def expand_tags(self, str):
103 ret = str
104 ret = ret.replace('${musicdir}', self.settings.value('MPD/music_dir').toString())
105 return ret