17 #include <QApplication>
49 mSettings->resetFile(this->getSettingsFile());
60 return mSettings.get();
63 QString Profile::getSettingsFile()
76 return QFileInfo(mPath).fileName();
86 return QStringList() << this->
getPath() +
"/tool/";
94 if (info.absolutePath() != expectedPath)
95 CX_LOG_WARNING() <<
"Set ref to file " << path <<
", should be in folder " << expectedPath;
104 if (filename.isEmpty())
106 return path +
"/" + filename;
111 return this->
getPath() +
"/settings";
127 QString Profile::getDefaultSessionRootFolder()
const
130 path << QDir::homePath() <<
"Patients" << this->
getName();
131 return path.join(
"/");
137 this->getDefaultSessionRootFolder()).toString();
140 if (!QDir().exists(folder))
142 if(QDir().mkpath(folder))
143 report(
"Made a new patient folder: " + folder);
165 ProfileManager *ProfileManager::mInstance = NULL;
169 if (mInstance == NULL)
187 ProfileManager::ProfileManager(QString defaultProfile)
189 QString profileUid = this->getDefaultProfileUid(defaultProfile);
190 profileUid = this->getGenericSettingsFromInstaller()->value(
"profile", profileUid).toString();
191 profileUid = this->getGenericSettings()->value(
"profile", profileUid).toString();
198 ProfileManager::~ProfileManager()
203 QString ProfileManager::getDefaultProfileUid(QString defaultProfile)
205 QStringList installed = this->getInstalledProfiles();
206 if (installed.contains(defaultProfile))
208 return defaultProfile;
210 else if (!installed.isEmpty())
212 return installed.front();
227 QString filename = this->getCustomPath() +
"/generic_settings.ini";
228 return QSettingsPtr(
new QSettings(filename, QSettings::IniFormat));
231 QSettingsPtr ProfileManager::getGenericSettingsFromInstaller()
234 QString filename = configPath +
"/profiles/generic_settings.ini";
235 return QSettingsPtr(
new QSettings(filename, QSettings::IniFormat));
238 QStringList ProfileManager::getInstalledProfiles()
241 QStringList profiles;
242 for (
int i=0; i< configPaths.size(); ++i)
243 profiles << getProfilesInFolder(configPaths[i]+
"/profiles");
246 QStringList ProfileManager::getCustomProfiles()
248 QStringList profiles;
249 profiles << getProfilesInFolder(this->getCustomPath());
253 QString ProfileManager::getCustomPath()
258 QStringList ProfileManager::getProfilesInFolder(QString folder)
261 return dir.entryList(QStringList(), QDir::Dirs | QDir::NoDotAndDotDot);
266 QStringList profiles = this->getInstalledProfiles();
267 profiles << getProfilesInFolder(this->getCustomPath());
268 profiles.removeDuplicates();
272 void ProfileManager::newProfile(QString uid)
274 QString path = this->getPathForCustom(uid);
280 this->profilesChanged();
283 void ProfileManager::copyProfile(QString base, QString uid)
285 QString newPath = this->getPathForCustom(uid);
288 CX_LOG_WARNING() <<
"Failed to copy profile " << base <<
" to " << newPath;
290 this->profilesChanged();
298 QString ProfileManager::getPathForInstalled(QString uid)
301 QStringList profiles;
302 for (
int i=0; i< configPaths.size(); ++i)
304 QFileInfo info(configPaths[i]+
"/profiles/"+uid);
306 return info.canonicalFilePath();
311 QString ProfileManager::getPathForCustom(QString uid)
313 return this->getCustomPath() +
"/" + uid;
318 if (mActive && mActive->getUid()==uid)
321 if (!this->getCustomProfiles().contains(uid))
323 this->createCustomProfile(uid);
328 mActive.reset(
new Profile(this->getPathForCustom(uid), mSettings));
329 this->getGenericSettings()->setValue(
"profile", mActive->getUid());
335 void ProfileManager::createCustomProfile(QString uid)
337 if (this->getInstalledProfiles().contains(uid))
339 QString path = this->getPathForInstalled(uid);
340 this->copyProfile(path, uid);
346 this->copyProfile(mActive->getPath(), uid);
348 else if (!this->getInstalledProfiles().isEmpty())
350 QString base = this->getInstalledProfiles().front();
351 QString basePath = this->getPathForInstalled(base);
352 this->copyProfile(basePath, uid);
356 this->newProfile(uid);
361 void ProfileManager::profilesChanged()