move plugins enable/disable code from winMain to plugins
[nephilim.git] / nephilim / nephilim_app.py
blob269cc9e67a36ee26eeced07f38bca07e057416cb
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 misc import ORGNAME, APPNAME, appIcon
22 from mpclient import MPClient
23 from settings_wg import SettingsWidget
24 import plugins
26 class NephilimApp(QtGui.QApplication):
27 # public, constant
28 "main window object"
29 main_win = None
30 "MPD layer"
31 mpclient = None
32 "plugins interface"
33 plugins = None
34 "settings object"
35 settings = None
37 # private
38 "settings window"
39 __settings_win = None
41 def __init__(self, argv):
42 QtGui.QApplication.__init__(self, argv)
44 self.setApplicationName(APPNAME)
45 self.setOrganizationName(ORGNAME)
46 self.setWindowIcon(QtGui.QIcon(appIcon))
48 def exec_(self):
49 #init MPD layer
50 self.mpclient = MPClient()
52 #init settings
53 self.settings = QtCore.QSettings()
55 #init main window
56 self.main_win = winMain()
58 #init plugins
59 show_settings = False # are there new plugins?
60 self.plugins = plugins.Plugins(self.main_win, self.mpclient)
61 for plugin in self.plugins.plugins():
62 if self.settings.value(plugin.name() + '/load') == None:
63 show_settings = True
64 if self.settings.value(plugin.name() + '/load', QtCore.QVariant(True)).toBool():
65 self.plugins.load(plugin.name())
67 self.connect(self, QtCore.SIGNAL('aboutToQuit()'), self.__cleanup)
69 if show_settings:
70 self.show_settings_win()
71 self.main_win.restore_layout()
72 QtGui.QApplication.exec_()
74 def __cleanup(self):
75 # unload all plugins
76 for plugin in self.plugins.loaded_plugins():
77 plugin.unload()
79 self.main_win.on_quit()
80 self.settings.sync()
82 def show_settings_win(self):
83 if not self.__settings_win:
84 self.__settings_win = SettingsWidget(self.mpclient, self.plugins)
86 self.connect(self.__settings_win, QtCore.SIGNAL('destroyed()'), self.__del_settings_win)
87 self.__settings_win.show()
88 self.__settings_win.raise_()
90 def __del_settings_win(self):
91 self.__settings_win = None
93 def expand_tags(self, str):
94 ret = str
95 ret = ret.replace('$musicdir', self.settings.value('MPD/music_dir').toString())
96 return ret