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";
147 ProfileManager *ProfileManager::mInstance = NULL;
151 if (mInstance == NULL)
169 ProfileManager::ProfileManager()
171 QString defaultProfile = this->getDefaultProfileUid();
172 defaultProfile = this->getGenericSettings()->value(
"profile", defaultProfile).toString();
179 ProfileManager::~ProfileManager()
184 QString ProfileManager::getDefaultProfileUid()
186 QStringList installed = this->getInstalledProfiles();
187 if (installed.contains(
"Laboratory"))
191 else if (!installed.isEmpty())
193 return installed.front();
208 QString filename = this->getCustomPath() +
"/generic_settings.ini";
209 return QSettingsPtr(
new QSettings(filename, QSettings::IniFormat));
212 QStringList ProfileManager::getInstalledProfiles()
215 QStringList profiles;
216 for (
int i=0; i< configPaths.size(); ++i)
217 profiles << getProfilesInFolder(configPaths[i]+
"/profiles");
220 QStringList ProfileManager::getCustomProfiles()
222 QStringList profiles;
223 profiles << getProfilesInFolder(this->getCustomPath());
227 QString ProfileManager::getCustomPath()
232 QStringList ProfileManager::getProfilesInFolder(QString folder)
235 return dir.entryList(QStringList(), QDir::Dirs | QDir::NoDotAndDotDot);
240 QStringList profiles = this->getInstalledProfiles();
241 profiles << getProfilesInFolder(this->getCustomPath());
242 profiles.removeDuplicates();
246 void ProfileManager::newProfile(QString uid)
248 QString path = this->getPathForCustom(uid);
254 this->profilesChanged();
257 void ProfileManager::copyProfile(QString base, QString uid)
259 QString newPath = this->getPathForCustom(uid);
262 CX_LOG_WARNING() <<
"Failed to copy profile " << base <<
" to " << newPath;
264 this->profilesChanged();
272 QString ProfileManager::getPathForInstalled(QString uid)
275 QStringList profiles;
276 for (
int i=0; i< configPaths.size(); ++i)
278 QFileInfo info(configPaths[i]+
"/profiles/"+uid);
280 return info.canonicalFilePath();
285 QString ProfileManager::getPathForCustom(QString uid)
287 return this->getCustomPath() +
"/" + uid;
292 if (mActive && mActive->getUid()==uid)
295 if (!this->getCustomProfiles().contains(uid))
297 this->createCustomProfile(uid);
302 mActive.reset(
new Profile(this->getPathForCustom(uid), mSettings));
303 this->getGenericSettings()->setValue(
"profile", mActive->getUid());
311 void ProfileManager::createCustomProfile(QString uid)
313 if (this->getInstalledProfiles().contains(uid))
315 QString path = this->getPathForInstalled(uid);
316 this->copyProfile(path, uid);
322 this->copyProfile(mActive->getPath(), uid);
324 else if (!this->getInstalledProfiles().isEmpty())
326 QString base = this->getInstalledProfiles().front();
327 QString basePath = this->getPathForInstalled(base);
328 this->copyProfile(basePath, uid);
332 this->newProfile(uid);
337 void ProfileManager::profilesChanged()
QStringList getApplicationToolConfigPaths()
cxResource_EXPORT ProfilePtr profile()
bool copyRecursively(const QString &srcFilePath, const QString &tgtFilePath)
void activeProfileChanged()
ProfilePtr activeProfile()
QString getSettingsPath()
boost::shared_ptr< class Settings > SettingsPtr
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
static QStringList getRootConfigPaths()
QStringList getProfiles()
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()
boost::shared_ptr< class Profile > ProfilePtr
Helper class for xml files used to store ssc/cx data.