Commit a0d1bc36 authored by Michal Humpula's avatar Michal Humpula

migrate from KStandardDirs to QStandardPaths

parent 08284e5f
......@@ -27,7 +27,6 @@
#include "katepluginmanager.h"
#include "katerunninginstanceinfo.h"
#include <KStandardDirs>
#include <KLocale>
#include "katedebug.h"
#include <KDirWatch>
......@@ -79,7 +78,7 @@ KateSession::KateSession (KateSessionManager *manager, const QString &fileName)
void KateSession::init ()
{
// given file exists, use it to load some stuff ;)
if (!m_sessionFileRel.isEmpty() && KGlobal::dirs()->exists(sessionFile ()))
if (!m_sessionFileRel.isEmpty() && QFile::exists(sessionFile()))
{
KConfig config (sessionFile (), KConfig::SimpleConfig);
......@@ -89,7 +88,7 @@ void KateSession::init ()
return;
}
if (!m_sessionFileRel.isEmpty() && !KGlobal::dirs()->exists(sessionFile ()))
if (!m_sessionFileRel.isEmpty() && !QFile::exists(sessionFile()))
qCDebug(LOG_KATE) << "Warning, session file not found: " << m_sessionFileRel;
}
......@@ -122,7 +121,7 @@ bool KateSession::create (const QString &name, bool force)
m_sessionName = name;
QString oldSessionFileRel = m_sessionFileRel;
m_sessionFileRel = QUrl::toPercentEncoding(name, "", ".") + QString(".katesession");
if (KGlobal::dirs()->exists(sessionFile ()))
if ( QFile::exists(sessionFile()) )
{
m_sessionFileRel = oldSessionFileRel;
return false;
......@@ -148,7 +147,7 @@ bool KateSession::rename (const QString &name)
QString oldRel = m_sessionFileRel;
QString oldSessionFile = sessionFile();
m_sessionFileRel = QUrl::toPercentEncoding(name, "", ".") + QString(".katesession");
if (KGlobal::dirs()->exists(sessionFile ()))
if ( QFile::exists(sessionFile()) )
{
m_sessionFileRel = oldRel;
return false;
......@@ -214,13 +213,13 @@ void KateSession::makeAnonymous()
KateSessionManager::KateSessionManager (QObject *parent)
: QObject (parent)
, m_sessionsDir (KStandardDirs::locateLocal( "data", "kate/sessions"))
, m_sessionsDir (QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/kate/sessions")
, m_activeSession (new KateSession (this, QString()))
{
qCDebug(LOG_KATE) << "LOCAL SESSION DIR: " << m_sessionsDir;
// create dir if needed
KGlobal::dirs()->makeDir (m_sessionsDir);
QDir(m_sessionsDir).mkpath(".");
}
KateSessionManager::~KateSessionManager()
......
......@@ -38,7 +38,6 @@
#include "katedebug.h"
#include <KEncodingFileDialog>
#include <KIconLoader>
#include <KGlobal>
#include <KStringHandler>
#include <KLocale>
#include <KToolBar>
......@@ -47,7 +46,6 @@
#include <KConfig>
#include <KConfigGroup>
#include <kstandardaction.h>
#include <KStandardDirs>
#include <KGlobalSettings>
#include <kstandardshortcut.h>
......
......@@ -25,10 +25,8 @@
#include <kpluginfactory.h>
#include <kpluginloader.h>
#include <kstandarddirs.h>
#include <kglobal.h>
#include <qdir.h>
#include <QtCore/QDir>
namespace Kate
{
......@@ -130,7 +128,7 @@ namespace Kate
QString XMLGUIClient::xmlDataFile(const QString &componentName, const QString &filename)
{
const QString filter = "kate/plugins/" + componentName + '/' + filename;
const QStringList allFiles = KGlobal::dirs()->findAllResources("data", filter);
const QStringList allFiles = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, filter);
QString file;
QString doc;
if (!allFiles.isEmpty())
......@@ -140,7 +138,8 @@ namespace Kate
QString XMLGUIClient::localXmlDataFile(const QString &componentName, const QString &filename)
{
QString result = KStandardDirs::locateLocal( "data", "kate/plugins/" + componentName + QDir::separator() + filename);
QString result = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
result += "/kate/plugins/" + componentName + '/' + filename;
return result;
}
......
......@@ -27,9 +27,7 @@
#include <QtWidgets/QTextEdit>
// KDE
#include <KStandardDirs>
#include <KLocale>
#include <KGlobal>
#include <KIcon>
#include <klocalizedstring.h>
......@@ -43,7 +41,7 @@
KateScriptConsoleEngine::KateScriptConsoleEngine(KateView * view)
: m_view (view)
{
m_utilsUrl = KGlobal::dirs()->findResource("data", "katepart/script/commands/utils.js");
m_utilsUrl = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "katepart/script/commands/utils.js");
}
KateScriptConsoleEngine::~KateScriptConsoleEngine()
......
......@@ -25,6 +25,7 @@
#include <sys/stat.h>
#include <unistd.h>
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QStringList>
......@@ -32,10 +33,8 @@
#include <QUuid>
#include <klocalizedstring.h>
#include <kglobal.h>
#include <kconfig.h>
#include <kconfiggroup.h>
#include <kstandarddirs.h>
#include <kde_file.h>
#include "kateglobal.h"
......@@ -117,8 +116,18 @@ void KateScriptManager::collect(bool force)
* now, we search all kinds of known scripts
*/
foreach (const QString &type, QStringList () << "indentation" << "commands") {
// get a list of all .js files for the current type
const QStringList list = KGlobal::dirs()->findAllResources("data", "katepart/script/" + type + "/*.js", KStandardDirs::NoDuplicates);
// get a list of all unique .js files for the current type
const QString basedir = "katepart/script/" + type;
const QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, basedir, QStandardPaths::LocateDirectory);
QStringList list;
foreach (const QString& dir, dirs) {
const QStringList fileNames = QDir(dir).entryList(QStringList() << QStringLiteral("*.js"));
foreach (const QString& file, fileNames) {
list.append(dir + '/' + file);
}
}
// iterate through the files and read info out of cache or file
foreach(const QString &fileName, list) {
......
......@@ -14,7 +14,7 @@ Snippets and repositoryies get displayed as tree.
Snippets are grouped into repositories, which are saved as XML files to disk.
The XML format is the same as used in the snippets_tng plugin for Kate.
We look for available repository files via KStandardDirs in share/ktexteditor_snippets/{data,ghns}/.
We look for available repository files via QStandardPaths in share/ktexteditor_snippets/{data,ghns}/.
After importing, the repository and it's snippets and sup-repositories show
up in the snippet tree and the snippets can be inserted like normal code-completion items.
......
......@@ -31,11 +31,9 @@
#include <QAction>
#include <KIcon>
#include <KGlobal>
#include <QDomDocument>
#include <QDomElement>
#include <KStandardDirs>
#include <KMessageBox>
#include <KLocalizedString>
......@@ -74,8 +72,10 @@ SnippetRepository* SnippetRepository::createRepoFromName(const QString& name)
QString cleanName = name;
cleanName.replace('/', '-');
SnippetRepository* repo = new SnippetRepository(KGlobal::dirs()->locateLocal( "data",
"ktexteditor_snippets/data/" + cleanName + ".xml" ));
const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation,
"ktexteditor_snippets/data/" + cleanName + ".xml");
SnippetRepository* repo = new SnippetRepository(path);
repo->setText(name);
repo->setCheckState(Qt::Checked);
KUser user;
......@@ -218,14 +218,16 @@ void SnippetRepository::save()
}
//KMessageBox::information(0,doc.toString());
QFileInfo fi(m_file);
QString outname = KGlobal::dirs()->locateLocal( "data", "ktexteditor_snippets/data/" + fi.fileName() );
QString outname = QStandardPaths::locate(QStandardPaths::GenericDataLocation,
"ktexteditor_snippets/data/" + fi.fileName());
if ( m_file != outname) {
QFileInfo fiout(outname);
// if (fiout.exists()) {
// there could be cases that new new name clashes with a global file, but I guess it is not that often.
int i = 0;
while(QFile::exists(outname)) {
outname = KGlobal::dirs()->locateLocal( "data", "ktexteditor_snippets/data/"+QString("%1_").arg(i++)+fi.fileName());
outname = QStandardPaths::locate(QStandardPaths::GenericDataLocation,
"ktexteditor_snippets/data/"+QString("%1_").arg(i++)+fi.fileName());
}
KMessageBox::information(QApplication::activeWindow(),
i18n("You have edited a data file not located in your personal data directory; as such, a renamed clone of the original data file has been created within your personal data directory."));
......
......@@ -27,8 +27,7 @@
#include "snippetrepository.h"
#include "katepartdebug.h"
#include <KStandardDirs>
#include <KGlobal>
#include <QDir>
#include <ktexteditor/editor.h>
#include <ktexteditor/templateinterface2.h>
......@@ -40,12 +39,20 @@ SnippetStore::SnippetStore(KateSnippetGlobal* plugin)
{
m_self = this;
const QStringList list = KGlobal::dirs()->findAllResources("data",
"ktexteditor_snippets/data/*.xml", KStandardDirs::NoDuplicates)
<< KGlobal::dirs()->findAllResources("data",
"ktexteditor_snippets/ghns/*.xml", KStandardDirs::NoDuplicates);
QStringList files;
foreach(const QString& file, list ) {
const QStringList dirs =
QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "ktexteditor_snippets/data", QStandardPaths::LocateDirectory)
<< QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "ktexteditor_snippets/ghns", QStandardPaths::LocateDirectory);
foreach (const QString& dir, dirs) {
const QStringList fileNames = QDir(dir).entryList(QStringList() << QStringLiteral("*.xml"));
foreach (const QString& file, fileNames) {
files.append(dir + '/' + file);
}
}
foreach(const QString& file, files ) {
SnippetRepository* repo = new SnippetRepository(file);
appendRow(repo);
}
......
......@@ -27,8 +27,6 @@
#include <klocalizedstring.h>
#include "katepartdebug.h"
#include <kstandarddirs.h>
#include <kglobal.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kconfiggroup.h>
......@@ -36,6 +34,7 @@
#include <QtWidgets/QApplication>
#include <QtCore/QFile>
#include <QtCore/QDir>
// use this to turn on over verbose debug output...
#undef KSD_OVER_VERBOSE
......@@ -373,8 +372,15 @@ void KateSyntaxDocument::setupModeList (bool force)
}
// Let's get a list of all the xml files for hl
const QStringList list = KGlobal::dirs()->findAllResources("data","katepart/syntax/*.xml",
KStandardDirs::NoDuplicates);
QStringList list;
const QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "katepart/syntax", QStandardPaths::LocateDirectory);
foreach (const QString& dir, dirs) {
const QStringList fileNames = QDir(dir).entryList(QStringList() << QStringLiteral("*.xml"));
foreach (const QString& file, fileNames) {
list.append(dir + '/' + file);
}
}
// Let's iterate through the list and build the Mode List
for ( QStringList::ConstIterator it = list.begin(); it != list.end(); ++it )
......
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