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";
148 QString Profile::getDefaultSessionRootFolder()
const 151 path << QDir::homePath() <<
"Patients" << this->
getName();
152 return path.join(
"/");
158 this->getDefaultSessionRootFolder()).toString();
161 if (!QDir().exists(folder))
163 if(QDir().mkpath(folder))
164 report(
"Made a new patient folder: " + folder);
190 if (mInstance == NULL)
208 ProfileManager::ProfileManager(QString defaultProfile)
210 QString profileUid = this->getDefaultProfileUid(defaultProfile);
211 profileUid = this->getGenericSettings()->value(
"profile", profileUid).toString();
215 this->setActiveProfile(profileUid);
218 ProfileManager::~ProfileManager()
223 QString ProfileManager::getDefaultProfileUid(QString defaultProfile)
225 QStringList installed = this->getInstalledProfiles();
226 if (installed.contains(defaultProfile))
228 return defaultProfile;
230 else if (!installed.isEmpty())
232 return installed.front();
247 QString filename = this->getCustomPath() +
"/generic_settings.ini";
248 return QSettingsPtr(
new QSettings(filename, QSettings::IniFormat));
251 QStringList ProfileManager::getInstalledProfiles()
254 QStringList profiles;
255 for (
int i=0; i< configPaths.size(); ++i)
256 profiles << getProfilesInFolder(configPaths[i]+
"/profiles");
259 QStringList ProfileManager::getCustomProfiles()
261 QStringList profiles;
262 profiles << getProfilesInFolder(this->getCustomPath());
266 QString ProfileManager::getCustomPath()
271 QStringList ProfileManager::getProfilesInFolder(QString folder)
274 return dir.entryList(QStringList(), QDir::Dirs | QDir::NoDotAndDotDot);
279 QStringList profiles = this->getInstalledProfiles();
280 profiles << getProfilesInFolder(this->getCustomPath());
281 profiles.removeDuplicates();
285 void ProfileManager::newProfile(QString uid)
287 QString path = this->getPathForCustom(uid);
293 this->profilesChanged();
296 void ProfileManager::copyProfile(QString base, QString uid)
298 QString newPath = this->getPathForCustom(uid);
301 CX_LOG_WARNING() <<
"Failed to copy profile " << base <<
" to " << newPath;
303 this->profilesChanged();
311 QString ProfileManager::getPathForInstalled(QString uid)
314 QStringList profiles;
315 for (
int i=0; i< configPaths.size(); ++i)
317 QFileInfo info(configPaths[i]+
"/profiles/"+uid);
319 return info.canonicalFilePath();
324 QString ProfileManager::getPathForCustom(QString uid)
326 return this->getCustomPath() +
"/" + uid;
331 if (mActive && mActive->getUid()==uid)
334 if (!this->getCustomProfiles().contains(uid))
336 this->createCustomProfile(uid);
341 mActive.reset(
new Profile(this->getPathForCustom(uid), mSettings));
342 this->getGenericSettings()->setValue(
"profile", mActive->getUid());
344 emit activeProfileChanged();
348 void ProfileManager::createCustomProfile(QString uid)
350 if (this->getInstalledProfiles().
contains(uid))
352 QString path = this->getPathForInstalled(uid);
353 this->copyProfile(path, uid);
359 this->copyProfile(mActive->getPath(), uid);
361 else if (!this->getInstalledProfiles().isEmpty())
363 QString base = this->getInstalledProfiles().front();
364 QString basePath = this->getPathForInstalled(base);
365 this->copyProfile(basePath, uid);
369 this->newProfile(uid);
374 void ProfileManager::profilesChanged()
QStringList getApplicationToolConfigPaths()
cxResource_EXPORT ProfilePtr profile()
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)
bool copyRecursively(QString sourceDir, QString destinationDir, bool overWriteDirectory)
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()
static QString getRootConfigPath()
return path to root config folder. May be replaced with getExistingConfigPath()
void save()
save entire document.
QString getSettingsPath()
void setSessionRootFolder(QString path)
boost::shared_ptr< class Profile > ProfilePtr
bool contains(std::string const &s, std::string const &infix)
QString getSessionRootFolder() const
Helper class for xml files used to store ssc/cx data.
QString getPatientTemplatePath()
Namespace for all CustusX production code.