# # Copyright (C) 2009 Anton Khirnov # # 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 . # 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 int(self.settings.value(plugin.name + '/load', 0)): 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')) return ret