Skip to content

Commit

Permalink
[fingerterm] Don't copy anymore layouts to user config directory on s…
Browse files Browse the repository at this point in the history
…tartup.
  • Loading branch information
dcaliste committed Jun 21, 2017
1 parent 5250432 commit 02f08ca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
11 changes: 11 additions & 0 deletions keyloader.cpp
Expand Up @@ -49,6 +49,8 @@ bool KeyLoader::loadLayout(QString layout)
}
else { // load from file
QFile f(iUtil->configPath() + "/" + layout + ".layout");
if (!f.exists()) // fallback to installation directory
f.setFileName(QStringLiteral(DEPLOYMENT_PATH) + "/data/" + layout + ".layout");
ret = loadLayoutInternal(f);
}

Expand Down Expand Up @@ -197,6 +199,15 @@ const QStringList KeyLoader::availableLayouts()
ret << s.left(s.lastIndexOf('.'));
}

// Add also layouts from installation path.
QDir dataDir(QStringLiteral(DEPLOYMENT_PATH) + "/data");
results = dataDir.entryList(filter, QDir::Files|QDir::Readable, QDir::Name);
foreach(QString s, results) {
QString layout = s.left(s.lastIndexOf('.'));
if (!ret.contains(layout))
ret << layout;
}

return ret;
}

Expand Down
16 changes: 0 additions & 16 deletions main.cpp
Expand Up @@ -40,8 +40,6 @@ extern "C" {
#include "version.h"
#include "keyloader.h"

static void copyFilesFromPath(QString from, QString to);

int main(int argc, char *argv[])
{
QString settings_path(QDir::homePath() + "/.config/FingerTerm");
Expand Down Expand Up @@ -131,9 +129,6 @@ int main(int argc, char *argv[])

QString startupErrorMsg;

// copy the default config files to the config dir if they don't already exist
copyFilesFromPath(QStringLiteral(DEPLOYMENT_PATH) + QDir::separator() + QStringLiteral("data"), util.configPath());

KeyLoader keyLoader;
keyLoader.setUtil(&util);
bool ret = keyLoader.loadLayout(util.keyboardLayout());
Expand Down Expand Up @@ -179,14 +174,3 @@ int main(int argc, char *argv[])

return app.exec();
}

static void copyFilesFromPath(QString from, QString to)
{
QDir fromDir(from);
QDir toDir(to);

// Copy files from fromDir to toDir, but don't overwrite existing ones
foreach (const QString &filename, fromDir.entryList(QDir::Files)) {
QFile::copy(fromDir.filePath(filename), toDir.filePath(filename));
}
}

0 comments on commit 02f08ca

Please sign in to comment.