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->getGenericSettingsFromInstaller()->value(
"profile", profileUid).toString();
191 profileUid = this->getGenericSettings()->value(
"profile", profileUid).toString();
195 this->setActiveProfile(profileUid);
198 ProfileManager::~ProfileManager()
203 QString ProfileManager::getDefaultProfileUid(QString defaultProfile)
205 QStringList installed = this->getInstalledProfiles();
206 if (installed.contains(defaultProfile))
208 return defaultProfile;
210 else if (!installed.isEmpty())
212 return installed.front();
227 QString filename = this->getCustomPath() +
"/generic_settings.ini";
228 return QSettingsPtr(
new QSettings(filename, QSettings::IniFormat));
231 QSettingsPtr ProfileManager::getGenericSettingsFromInstaller()
234 QString filename = configPath +
"/profiles/generic_settings.ini";
235 return QSettingsPtr(
new QSettings(filename, QSettings::IniFormat));
238 QStringList ProfileManager::getInstalledProfiles()
241 QStringList profiles;
242 for (
int i=0; i< configPaths.size(); ++i)
243 profiles << getProfilesInFolder(configPaths[i]+
"/profiles");
246 QStringList ProfileManager::getCustomProfiles()
248 QStringList profiles;
249 profiles << getProfilesInFolder(this->getCustomPath());
253 QString ProfileManager::getCustomPath()
258 QStringList ProfileManager::getProfilesInFolder(QString folder)
261 return dir.entryList(QStringList(), QDir::Dirs | QDir::NoDotAndDotDot);
266 QStringList profiles = this->getInstalledProfiles();
267 profiles << getProfilesInFolder(this->getCustomPath());
268 profiles.removeDuplicates();
272 void ProfileManager::newProfile(QString uid)
274 QString path = this->getPathForCustom(uid);
280 this->profilesChanged();
283 void ProfileManager::copyProfile(QString base, QString uid)
285 QString newPath = this->getPathForCustom(uid);
288 CX_LOG_WARNING() <<
"Failed to copy profile " << base <<
" to " << newPath;
290 this->profilesChanged();
298 QString ProfileManager::getPathForInstalled(QString uid)
301 QStringList profiles;
302 for (
int i=0; i< configPaths.size(); ++i)
304 QFileInfo info(configPaths[i]+
"/profiles/"+uid);
306 return info.canonicalFilePath();
311 QString ProfileManager::getPathForCustom(QString uid)
313 return this->getCustomPath() +
"/" + uid;
318 if (mActive && mActive->getUid()==uid)
321 if (!this->getCustomProfiles().contains(uid))
323 this->createCustomProfile(uid);
328 mActive.reset(
new Profile(this->getPathForCustom(uid), mSettings));
329 this->getGenericSettings()->setValue(
"profile", mActive->getUid());
331 emit activeProfileChanged();
335 void ProfileManager::createCustomProfile(QString uid)
337 if (this->getInstalledProfiles().contains(uid))
339 QString path = this->getPathForInstalled(uid);
340 this->copyProfile(path, uid);
346 this->copyProfile(mActive->getPath(), uid);
348 else if (!this->getInstalledProfiles().isEmpty())
350 QString base = this->getInstalledProfiles().front();
351 QString basePath = this->getPathForInstalled(base);
352 this->copyProfile(basePath, uid);
356 this->newProfile(uid);
361 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
QString getSessionRootFolder() const
Helper class for xml files used to store ssc/cx data.
QString getPatientTemplatePath()
Namespace for all CustusX production code.