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);
169 if (mInstance == NULL)
187 ProfileManager::ProfileManager(QString defaultProfile)
189 QString profileUid = this->getDefaultProfileUid(defaultProfile);
190 profileUid = this->getGenericSettings()->value(
"profile", profileUid).toString();
194 this->setActiveProfile(profileUid);
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());
323 emit activeProfileChanged();
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()
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.