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->getGenericSettings()->value(
"profile", profileUid).toString();
197 ProfileManager::~ProfileManager()
202 QString ProfileManager::getDefaultProfileUid(QString defaultProfile)
204 QStringList installed = this->getInstalledProfiles();
205 if (installed.contains(defaultProfile))
207 return defaultProfile;
209 else if (!installed.isEmpty())
211 return installed.front();
226 QString filename = this->getCustomPath() +
"/generic_settings.ini";
227 return QSettingsPtr(
new QSettings(filename, QSettings::IniFormat));
230 QStringList ProfileManager::getInstalledProfiles()
233 QStringList profiles;
234 for (
int i=0; i< configPaths.size(); ++i)
235 profiles << getProfilesInFolder(configPaths[i]+
"/profiles");
238 QStringList ProfileManager::getCustomProfiles()
240 QStringList profiles;
241 profiles << getProfilesInFolder(this->getCustomPath());
245 QString ProfileManager::getCustomPath()
250 QStringList ProfileManager::getProfilesInFolder(QString folder)
253 return dir.entryList(QStringList(), QDir::Dirs | QDir::NoDotAndDotDot);
258 QStringList profiles = this->getInstalledProfiles();
259 profiles << getProfilesInFolder(this->getCustomPath());
260 profiles.removeDuplicates();
264 void ProfileManager::newProfile(QString uid)
266 QString path = this->getPathForCustom(uid);
272 this->profilesChanged();
275 void ProfileManager::copyProfile(QString base, QString uid)
277 QString newPath = this->getPathForCustom(uid);
280 CX_LOG_WARNING() <<
"Failed to copy profile " << base <<
" to " << newPath;
282 this->profilesChanged();
290 QString ProfileManager::getPathForInstalled(QString uid)
293 QStringList profiles;
294 for (
int i=0; i< configPaths.size(); ++i)
296 QFileInfo info(configPaths[i]+
"/profiles/"+uid);
298 return info.canonicalFilePath();
303 QString ProfileManager::getPathForCustom(QString uid)
305 return this->getCustomPath() +
"/" + uid;
310 if (mActive && mActive->getUid()==uid)
313 if (!this->getCustomProfiles().contains(uid))
315 this->createCustomProfile(uid);
320 mActive.reset(
new Profile(this->getPathForCustom(uid), mSettings));
321 this->getGenericSettings()->setValue(
"profile", mActive->getUid());
327 void ProfileManager::createCustomProfile(QString uid)
329 if (this->getInstalledProfiles().contains(uid))
331 QString path = this->getPathForInstalled(uid);
332 this->copyProfile(path, uid);
338 this->copyProfile(mActive->getPath(), uid);
340 else if (!this->getInstalledProfiles().isEmpty())
342 QString base = this->getInstalledProfiles().front();
343 QString basePath = this->getPathForInstalled(base);
344 this->copyProfile(basePath, uid);
348 this->newProfile(uid);
353 void ProfileManager::profilesChanged()