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