Playlist: highlight current song.
[nephilim.git] / nephilim / nephilim_app.py
blobda387a7181bff4196587ffb2c0d7e4acc3163942
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 main_window import MainWindow
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 ####
30 # those don't change while the program is running
31 """main window object"""
32 main_win = None
33 """"MPD layer"""
34 mpclient = None
35 """"plugins interface"""
36 plugins = None
37 """settings object"""
38 settings = None
40 #### PRIVATE ####
41 """settings window"""
42 _settings_win = None
43 """connection window"""
44 _connect_win = None
46 #### PUBLIC ####
47 def __init__(self, argv):
48 QtGui.QApplication.__init__(self, argv)
50 self.setApplicationName(APPNAME)
51 self.setOrganizationName(ORGNAME)
52 self.setWindowIcon(QtGui.QIcon(appIcon))
54 def __str__(self):
55 return APPNAME
57 def exec_(self):
58 #init MPD layer
59 self.mpclient = MPClient(self)
61 #init settings
62 self.settings = QtCore.QSettings(self)
64 #init connection window
65 self._connect_win = ConnectWidget()
67 #init main window
68 self.main_win = MainWindow(self.mpclient)
70 #init plugins
71 show_settings = False # are there new plugins?
72 self.plugins = plugins.Plugins(self.main_win, self.mpclient)
73 for plugin in self.plugins.plugins():
74 if self.settings.value(plugin.name + '/load') == None:
75 show_settings = True
76 if int(self.settings.value(plugin.name + '/load', 0)):
77 self.plugins.load(plugin.name)
79 self.aboutToQuit.connect(self._cleanup)
82 if show_settings:
83 self.show_settings_win()
84 self.main_win.restore_layout()
85 self._connect_win.monitor()
87 QtGui.QApplication.exec_()
90 def show_settings_win(self):
91 if not self._settings_win:
92 self._settings_win = SettingsWidget(self.mpclient, self.plugins)
94 self._settings_win.show()
95 self._settings_win.raise_()
97 def show_connect_win(self):
98 self._connect_win.monitor()
100 def expand_tags(self, str):
101 ret = str
102 ret = ret.replace('${musicdir}', self.settings.value('MPD/music_dir'))
103 return ret
105 #### PRIVATE ####
106 def _cleanup(self):
107 # unload all plugins
108 for plugin in self.plugins.loaded_plugins():
109 plugin.unload()
111 self.main_win.on_quit()
112 self.settings.sync()