Commit 460cbadc authored by Daniel Molkentin's avatar Daniel Molkentin
Browse files

Refactor: add userResourcePath() accessor to ICore.

Access to the users private resource path (derived from the
settings path) has been used in quite some places, so it's
worth moving it to the core interface centrally.

Reviewed-By: Thorbjorn Lindeijer
parent 071400d6
......@@ -175,6 +175,22 @@ QString CoreImpl::resourcePath() const
return QDir::cleanPath(QCoreApplication::applicationDirPath() + QLatin1String(SHARE_PATH));
}
QString CoreImpl::userResourcePath() const
{
// Create qtcreator dir if it doesn't yet exist
const QString configDir = QFileInfo(settings(QSettings::UserScope)->fileName()).path();
const QString urp = configDir + "/qtcreator";
QFileInfo fi(urp + QLatin1Char('/'));
if (!fi.exists()) {
QDir dir;
if (!dir.mkpath(urp))
qWarning() << "could not create" << url;
}
return urp;
}
IContext *CoreImpl::currentContextObject() const
{
return m_mainwindow->currentContextObject();
......
......@@ -74,6 +74,7 @@ public:
QPrinter *printer() const;
QString resourcePath() const;
QString userResourcePath() const;
IContext *currentContextObject() const;
......
......@@ -94,11 +94,7 @@ HelpManager* HelpManager::instance()
QString HelpManager::collectionFilePath()
{
const QFileInfo fi(Core::ICore::instance()->settings()->fileName());
const QDir directory(fi.absolutePath() + QLatin1String("/qtcreator"));
if (!directory.exists())
directory.mkpath(directory.absolutePath());
return QDir::cleanPath(directory.absolutePath() + QLatin1String("/helpcollection.qhc"));
return QDir::cleanPath(Core::ICore::instance()->userResourcePath() + QLatin1String("/helpcollection.qhc"));
}
void HelpManager::registerDocumentation(const QStringList &files)
......
......@@ -233,6 +233,16 @@
the place, since e.g. on Mac the resources are part of the application bundle.
*/
/*!
\fn QString ICore::userResourcePath() const
\brief Returns the absolute path in the users directory that is used for
resources like project templates.
Use this method for finding the place for resources that the user may
write to, e.g. to allow for custom palettes or templates.
*/
/*!
\fn QMainWindow *ICore::mainWindow() const
\brief Returns the main application window.
......
......@@ -105,6 +105,7 @@ public:
virtual QPrinter *printer() const = 0;
virtual QString resourcePath() const = 0;
virtual QString userResourcePath() const = 0;
virtual QMainWindow *mainWindow() const = 0;
virtual QStatusBar *statusBar() const = 0;
......
......@@ -985,7 +985,7 @@ QStringList SessionManager::sessions() const
QString SessionManager::sessionNameToFileName(const QString &session)
{
return QFileInfo(m_core->settings()->fileName()).path() + "/qtcreator/" + session + ".qws";
return m_core->userResourcePath() + '/' + session + ".qws";
}
void SessionManager::createAndLoadNewDefaultSession()
......
......@@ -143,8 +143,8 @@ using namespace TextEditor::Internal;
static QString customStylesPath()
{
QString path = QFileInfo(Core::ICore::instance()->settings()->fileName()).path();
path.append(QLatin1String("/qtcreator/styles/"));
QString path = Core::ICore::instance()->userResourcePath();
path.append(QLatin1String("/styles/"));
return path;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment