38 #include <QApplication>
65 mSettings->resetFile(this->getSettingsFile());
76 return mSettings.get();
79 QString Profile::getSettingsFile()
92 return QFileInfo(mPath).fileName();
102 return QStringList() << this->
getPath() +
"/tool/";
109 QFileInfo info(path);
110 if (info.absolutePath() != expectedPath)
111 CX_LOG_WARNING() <<
"Set ref to file " << path <<
", should be in folder " << expectedPath;
120 if (filename.isEmpty())
122 return path +
"/" + filename;
127 return this->
getPath() +
"/settings";
138 QString Profile::getDefaultSessionRootFolder()
const
141 path << QDir::homePath() <<
"Patients" << this->
getName();
142 return path.join(
"/");
148 this->getDefaultSessionRootFolder()).toString();
151 if (!QDir().exists(folder))
153 QDir().mkdir(folder);
154 report(
"Made a new patient folder: " + folder);
174 ProfileManager *ProfileManager::mInstance = NULL;
178 if (mInstance == NULL)
196 ProfileManager::ProfileManager()
198 QString defaultProfile = this->getDefaultProfileUid();
199 defaultProfile = this->getGenericSettings()->value(
"profile", defaultProfile).toString();
206 ProfileManager::~ProfileManager()
211 QString ProfileManager::getDefaultProfileUid()
213 QStringList installed = this->getInstalledProfiles();
214 if (installed.contains(
"Laboratory"))
218 else if (!installed.isEmpty())
220 return installed.front();
235 QString filename = this->getCustomPath() +
"/generic_settings.ini";
236 return QSettingsPtr(
new QSettings(filename, QSettings::IniFormat));
239 QStringList ProfileManager::getInstalledProfiles()
242 QStringList profiles;
243 for (
int i=0; i< configPaths.size(); ++i)
244 profiles << getProfilesInFolder(configPaths[i]+
"/profiles");
247 QStringList ProfileManager::getCustomProfiles()
249 QStringList profiles;
250 profiles << getProfilesInFolder(this->getCustomPath());
254 QString ProfileManager::getCustomPath()
259 QStringList ProfileManager::getProfilesInFolder(QString folder)
262 return dir.entryList(QStringList(), QDir::Dirs | QDir::NoDotAndDotDot);
267 QStringList profiles = this->getInstalledProfiles();
268 profiles << getProfilesInFolder(this->getCustomPath());
269 profiles.removeDuplicates();
273 void ProfileManager::newProfile(QString uid)
275 QString path = this->getPathForCustom(uid);
281 this->profilesChanged();
284 void ProfileManager::copyProfile(QString base, QString uid)
286 QString newPath = this->getPathForCustom(uid);
289 CX_LOG_WARNING() <<
"Failed to copy profile " << base <<
" to " << newPath;
291 this->profilesChanged();
299 QString ProfileManager::getPathForInstalled(QString uid)
302 QStringList profiles;
303 for (
int i=0; i< configPaths.size(); ++i)
305 QFileInfo info(configPaths[i]+
"/profiles/"+uid);
307 return info.canonicalFilePath();
312 QString ProfileManager::getPathForCustom(QString uid)
314 return this->getCustomPath() +
"/" + uid;
319 if (mActive && mActive->getUid()==uid)
322 if (!this->getCustomProfiles().contains(uid))
324 this->createCustomProfile(uid);
329 mActive.reset(
new Profile(this->getPathForCustom(uid), mSettings));
330 this->getGenericSettings()->setValue(
"profile", mActive->getUid());
336 void ProfileManager::createCustomProfile(QString uid)
338 if (this->getInstalledProfiles().contains(uid))
340 QString path = this->getPathForInstalled(uid);
341 this->copyProfile(path, uid);
347 this->copyProfile(mActive->getPath(), uid);
349 else if (!this->getInstalledProfiles().isEmpty())
351 QString base = this->getInstalledProfiles().front();
352 QString basePath = this->getPathForInstalled(base);
353 this->copyProfile(basePath, uid);
357 this->newProfile(uid);
362 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
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.
static ProfileManager * getInstance()
returns the only instance of this class
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()
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.