--- a/PluginTimeTracker.py Sat Oct 20 20:01:33 2012 +0200 +++ b/PluginTimeTracker.py Sat Oct 20 21:52:00 2012 +0200 @@ -9,10 +9,12 @@ import os -from PyQt4.QtCore import QObject, QTranslator +from PyQt4.QtCore import QObject, QTranslator, QCoreApplication from E5Gui.E5Application import e5App +import Preferences + from TimeTracker.TimeTracker import TimeTracker # Start-Of-Header @@ -31,8 +33,48 @@ # End-Of-Header error = "" + +timeTrackerPluginObject = None +def createTimeTrackerPage(configDlg): + """ + Module function to create the Time Tracker configuration page. + + @return reference to the configuration page + """ + global timeTrackerPluginObject + from TimeTracker.ConfigurationPage.TimeTrackerPage import TimeTrackerPage + page = TimeTrackerPage(timeTrackerPluginObject) + return page + + +def getConfigData(): + """ + Module function returning data as required by the configuration dialog. + + @return dictionary containing the relevant data + """ + if e5App().getObject("UserInterface").versionIsNewer('5.2.99', '20121012'): + return { + "timeTrackerPage": \ + [QCoreApplication.translate("TimeTrackerPlugin", "Time Tracker"), + os.path.join("TimeTracker", "icons", + "clock.png"), + createTimeTrackerPage, None, None], + } + else: + return {} + + +def prepareUninstall(): + """ + Module function to prepare for an uninstallation. + """ + tracker = TimeTrackerPlugin(None) + tracker.prepareUninstall() + + class TimeTrackerPlugin(QObject): """ Class implementing the Eric assistant plugin. @@ -47,6 +89,12 @@ self.__ui = ui self.__initialize() + self.__defaults = { + "MinimumDuration": 2, + "AutoSave": False, + "AllowDuplicates": False, + } + self.__translator = None self.__loadTranslator() @@ -87,6 +135,9 @@ if not self.__checkVersions(): return None, False + global timeTrackerPluginObject + timeTrackerPluginObject = self + self.__object = TimeTracker(self, self.__ui) ## self.__object.initActions() e5App().registerPluginObject("TimeTracker", self.__object) @@ -133,3 +184,38 @@ print("Warning: translation file '{0}' could not be loaded."\ .format(translation)) print("Using default.") + + def getPreferences(self, key): + """ + Public method to retrieve the various settings. + + @param key the key of the value to get + @param prefClass preferences class used as the storage area + @return the requested setting + """ + if key in ["MinimumDuration"]: + return int(Preferences.Prefs.settings.value("TimeTracker/" + key, + self.__defaults[key])) + elif key in ["AutoSave", "AllowDuplicates"]: + return Preferences.toBool( + Preferences.Prefs.settings.value("TimeTracker/" + key, + self.__defaults[key])) + else: + return Preferences.Prefs.settings.value("TimeTracker/" + key, + self.__defaults[key]) + + def setPreferences(self, key, value): + """ + Public method to store the various settings. + + @param key the key of the setting to be set (string) + @param value the value to be set + @param prefClass preferences class used as the storage area + """ + Preferences.Prefs.settings.setValue("TimeTracker/" + key, value) + + def prepareUninstall(self): + """ + Public method to prepare for an uninstallation. + """ + Preferences.Prefs.settings.remove("TimeTracker")