38 #include <QApplication>
70 mSettings->resetFile(this->getSettingsFile());
81 return mSettings.get();
84 QString Profile::getSettingsFile()
97 return QFileInfo(mPath).fileName();
107 return QStringList() << this->
getPath() +
"/tool/";
114 QFileInfo info(path);
115 if (info.absolutePath() != expectedPath)
116 CX_LOG_WARNING() <<
"Set ref to file " << path <<
", should be in folder " << expectedPath;
125 if (filename.isEmpty())
127 return path +
"/" + filename;
132 return this->
getPath() +
"/settings";
143 QString Profile::getDefaultSessionRootFolder()
const
146 path << QDir::homePath() <<
"Patients" << this->
getName();
147 return path.join(
"/");
153 this->getDefaultSessionRootFolder()).toString();
156 if (!QDir().exists(folder))
158 if(QDir().mkpath(folder))
159 report(
"Made a new patient folder: " + folder);
181 ProfileManager *ProfileManager::mInstance = NULL;
185 if (mInstance == NULL)
203 ProfileManager::ProfileManager(QString defaultProfile)
205 QString profileUid = this->getDefaultProfileUid(defaultProfile);
206 profileUid = this->getGenericSettings()->value(
"profile", profileUid).toString();
213 ProfileManager::~ProfileManager()
218 QString ProfileManager::getDefaultProfileUid(QString defaultProfile)
220 QStringList installed = this->getInstalledProfiles();
221 if (installed.contains(defaultProfile))
223 return defaultProfile;
225 else if (!installed.isEmpty())
227 return installed.front();
242 QString filename = this->getCustomPath() +
"/generic_settings.ini";
243 return QSettingsPtr(
new QSettings(filename, QSettings::IniFormat));
246 QStringList ProfileManager::getInstalledProfiles()
249 QStringList profiles;
250 for (
int i=0; i< configPaths.size(); ++i)
251 profiles << getProfilesInFolder(configPaths[i]+
"/profiles");
254 QStringList ProfileManager::getCustomProfiles()
256 QStringList profiles;
257 profiles << getProfilesInFolder(this->getCustomPath());
261 QString ProfileManager::getCustomPath()
266 QStringList ProfileManager::getProfilesInFolder(QString folder)
269 return dir.entryList(QStringList(), QDir::Dirs | QDir::NoDotAndDotDot);
274 QStringList profiles = this->getInstalledProfiles();
275 profiles << getProfilesInFolder(this->getCustomPath());
276 profiles.removeDuplicates();
280 void ProfileManager::newProfile(QString uid)
282 QString path = this->getPathForCustom(uid);
288 this->profilesChanged();
291 void ProfileManager::copyProfile(QString base, QString uid)
293 QString newPath = this->getPathForCustom(uid);
296 CX_LOG_WARNING() <<
"Failed to copy profile " << base <<
" to " << newPath;
298 this->profilesChanged();
306 QString ProfileManager::getPathForInstalled(QString uid)
309 QStringList profiles;
310 for (
int i=0; i< configPaths.size(); ++i)
312 QFileInfo info(configPaths[i]+
"/profiles/"+uid);
314 return info.canonicalFilePath();
319 QString ProfileManager::getPathForCustom(QString uid)
321 return this->getCustomPath() +
"/" + uid;
326 if (mActive && mActive->getUid()==uid)
329 if (!this->getCustomProfiles().contains(uid))
331 this->createCustomProfile(uid);
336 mActive.reset(
new Profile(this->getPathForCustom(uid), mSettings));
337 this->getGenericSettings()->setValue(
"profile", mActive->getUid());
343 void ProfileManager::createCustomProfile(QString uid)
345 if (this->getInstalledProfiles().contains(uid))
347 QString path = this->getPathForInstalled(uid);
348 this->copyProfile(path, uid);
354 this->copyProfile(mActive->getPath(), uid);
356 else if (!this->getInstalledProfiles().isEmpty())
358 QString base = this->getInstalledProfiles().front();
359 QString basePath = this->getPathForInstalled(base);
360 this->copyProfile(basePath, uid);
364 this->newProfile(uid);
369 void ProfileManager::profilesChanged()
QStringList getApplicationToolConfigPaths()
cxResource_EXPORT ProfilePtr profile()
bool copyRecursively(const QString &srcFilePath, const QString &tgtFilePath)
void activeProfileChanged()
ProfilePtr activeProfile()
Settings * getSettings() const
QString getSettingsPath()
boost::shared_ptr< class Settings > SettingsPtr
static ProfileManager * getInstance(QString defaultProfile=QString("Laboratory"))
returns the only instance of this class
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
static QStringList getRootConfigPaths()
QStringList getProfiles()
void setValueIfNotDefault(const QString &key, const QVariant &value, const QVariant &defaultValue)
void setToolConfigFilePath(QString path)
void setActiveProfile(QString uid)
void setValue(const QString &key, const QVariant &value)
Profile(QString path, SettingsPtr settings)
Customized interface for setting values in QSettings.
void reportWarning(QString msg)
boost::shared_ptr< class QSettings > QSettingsPtr
XmlOptionFile getXmlSettings()
internal use
Settings * settings()
Shortcut for accessing the settings instance.
static QString getPersistentWritablePath()
Path to location usable for persistent and temporary storage of config. Do not use directly...
QString getToolConfigFilePath()
QStringList getAllRootConfigPaths()
void save()
save entire document.
QString getSettingsPath()
void setSessionRootFolder(QString path)
boost::shared_ptr< class Profile > ProfilePtr
QString getSessionRootFolder() const
Helper class for xml files used to store ssc/cx data.