switch to new-style PyQt4 signals.
[nephilim.git] / nephilim / nephilim_app.py
blob3e9b1975ff132e060d81ba7cb3974438d4b8d382
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
27 class NephilimApp(QtGui.QApplication):
28 # public, constant
29 "main window object"
30 main_win = None
31 "MPD layer"
32 mpclient = None
33 "plugins interface"
34 plugins = None
35 "settings object"
36 settings = None
38 # private
39 "settings window"
40 __settings_win = None
41 "connection window"
42 __connect_win = None
44 def __init__(self, argv):
45 QtGui.QApplication.__init__(self, argv)
47 self.setApplicationName(APPNAME)
48 self.setOrganizationName(ORGNAME)
49 self.setWindowIcon(QtGui.QIcon(appIcon))
51 def exec_(self):
52 #init MPD layer
53 self.mpclient = MPClient()
55 #init settings
56 self.settings = QtCore.QSettings()
58 #init connection window
59 self.__connect_win = ConnectWidget()
61 #init main window
62 self.main_win = winMain(self.mpclient)
64 #init plugins
65 show_settings = False # are there new plugins?
66 self.plugins = plugins.Plugins(self.main_win, self.mpclient)
67 for plugin in self.plugins.plugins():
68 if self.settings.value(plugin.name + '/load') == None:
69 show_settings = True
70 if self.settings.value(plugin.name + '/load', QtCore.QVariant(True)).toBool():
71 self.plugins.load(plugin.name)
73 self.aboutToQuit.connect(self.__cleanup)
76 if show_settings:
77 self.show_settings_win()
78 self.main_win.restore_layout()
79 self.__connect_win.monitor()
81 QtGui.QApplication.exec_()
83 def __cleanup(self):
84 # unload all plugins
85 for plugin in self.plugins.loaded_plugins():
86 plugin.unload()
88 self.main_win.on_quit()
89 self.settings.sync()
91 def show_settings_win(self):
92 if not self.__settings_win:
93 self.__settings_win = SettingsWidget(self.mpclient, self.plugins)
95 self.__settings_win.destroyed.connect(self.__del_settings_win)
96 self.__settings_win.show()
97 self.__settings_win.raise_()
98 def show_connect_win(self):
99 self.__connect_win.monitor()
101 def __del_settings_win(self):
102 self.__settings_win = None
104 def expand_tags(self, str):
105 ret = str
106 ret = ret.replace('$musicdir', self.settings.value('MPD/music_dir').toString())
107 return ret