| 975 | } |
| 976 | |
| 977 | void TOPPASBase::loadPreferences(String filename) |
| 978 | { |
| 979 | //compose default ini file path |
| 980 | String default_ini_file = String(QDir::homePath()) + "/.TOPPAS.ini"; |
| 981 | |
| 982 | if (filename.empty()) |
| 983 | { |
| 984 | filename = default_ini_file; |
| 985 | } |
| 986 | |
| 987 | //load preferences, if file exists |
| 988 | if (File::exists(filename)) |
| 989 | { |
| 990 | bool error = false; |
| 991 | Param tmp; |
| 992 | ParamXMLFile paramFile; |
| 993 | try // the file might be corrupt |
| 994 | { |
| 995 | paramFile.load(filename, tmp); |
| 996 | } |
| 997 | catch (...) |
| 998 | { |
| 999 | error = true; |
| 1000 | } |
| 1001 | |
| 1002 | //apply preferences if they are of the current TOPPAS version |
| 1003 | if (!error && tmp.exists("preferences:version") && tmp.getValue("preferences:version").toString() == VersionInfo::getVersion()) |
| 1004 | { |
| 1005 | try |
| 1006 | { |
| 1007 | setParameters(tmp); |
| 1008 | } |
| 1009 | catch (Exception::InvalidParameter& /*e*/) |
| 1010 | { |
| 1011 | error = true; |
| 1012 | } |
| 1013 | } |
| 1014 | else |
| 1015 | { |
| 1016 | error = true; |
| 1017 | } |
| 1018 | //set parameters to defaults when something is fishy with the parameters file |
| 1019 | if (error) |
| 1020 | { |
| 1021 | //reset parameters (they will be stored again when TOPPAS quits) |
| 1022 | setParameters(Param()); |
| 1023 | |
| 1024 | cerr << "The TOPPAS preferences files '" << filename << "' was ignored. It is no longer compatible with this TOPPAS version and will be replaced." << endl; |
| 1025 | } |
| 1026 | } |
| 1027 | else if (filename != default_ini_file) |
| 1028 | { |
| 1029 | cerr << "Unable to load INI File: '" << filename << "'" << endl; |
| 1030 | } |
| 1031 | param_.setValue("PreferencesFile", filename); |
| 1032 | |
| 1033 | // set the recent files |
| 1034 | recent_files_menu_.setFromParam(param_.copy("preferences:RecentFiles")); |