Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'noresources' into 'master'
[fingerterm] Install QML files, icons and data under /usr/share/fingerterm instead of using resources.

See merge request !22
  • Loading branch information
pvuorela committed Jun 21, 2017
2 parents e28ec34 + 02f08ca commit 1d0fc67
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 59 deletions.
29 changes: 27 additions & 2 deletions fingerterm.pro
Expand Up @@ -15,6 +15,8 @@ isEmpty(DEFAULT_FONT) {
DEFAULT_FONT = monospace
}

DEPLOYMENT_PATH = /usr/share/$$TARGET
DEFINES += DEPLOYMENT_PATH=\\\"$$DEPLOYMENT_PATH\\\"
DEFINES += DEFAULT_FONTFAMILY=\\\"$$DEFAULT_FONT\\\"

TEMPLATE = app
Expand All @@ -40,8 +42,7 @@ SOURCES += \
util.cpp \
keyloader.cpp

OTHER_FILES += \
qml/Main.qml \
qml.files = qml/Main.qml \
qml/Keyboard.qml \
qml/Key.qml \
qml/Lineview.qml \
Expand All @@ -51,10 +52,34 @@ OTHER_FILES += \
qml/UrlWindow.qml \
qml/LayoutWindow.qml \
qml/PopupWindow.qml
qml.path = $$DEPLOYMENT_PATH
INSTALLS += qml

RESOURCES += \
resources.qrc

icons.files = icons/backspace.png \
icons/down.png \
icons/enter.png \
icons/left.png \
icons/menu.png \
icons/right.png \
icons/scroll-indicator.png \
icons/shift.png \
icons/tab.png \
icons/up.png
icons.path = $$DEPLOYMENT_PATH/icons
INSTALLS += icons

userdata.files = data/menu.xml \
data/english.layout \
data/finnish.layout \
data/french.layout \
data/german.layout \
data/qwertz.layout
userdata.path = $$DEPLOYMENT_PATH/data
INSTALLS += userdata

target.path = /usr/bin
INSTALLS += target

Expand Down
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
29 changes: 2 additions & 27 deletions main.cpp
Expand Up @@ -40,8 +40,6 @@ extern "C" {
#include "version.h"
#include "keyloader.h"

static void copyFileFromResources(QString from, QString to);

int main(int argc, char *argv[])
{
QString settings_path(QDir::homePath() + "/.config/FingerTerm");
Expand Down Expand Up @@ -131,14 +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
copyFileFromResources(":/data/menu.xml", util.configPath()+"/menu.xml");
copyFileFromResources(":/data/english.layout", util.configPath()+"/english.layout");
copyFileFromResources(":/data/finnish.layout", util.configPath()+"/finnish.layout");
copyFileFromResources(":/data/french.layout", util.configPath()+"/french.layout");
copyFileFromResources(":/data/german.layout", util.configPath()+"/german.layout");
copyFileFromResources(":/data/qwertz.layout", util.configPath()+"/qwertz.layout");

KeyLoader keyLoader;
keyLoader.setUtil(&util);
bool ret = keyLoader.loadLayout(util.keyboardLayout());
Expand All @@ -164,7 +154,8 @@ int main(int argc, char *argv[])
QObject::connect(view.engine(),SIGNAL(quit()),&app,SLOT(quit()));

view.setResizeMode(QQuickView::SizeRootObjectToView);
view.setSource(QUrl("qrc:/qml/Main.qml"));
view.engine()->addImportPath(QStringLiteral(DEPLOYMENT_PATH));
view.setSource(QUrl::fromLocalFile(QStringLiteral(DEPLOYMENT_PATH) + QDir::separator() + QStringLiteral("Main.qml")));

QObject *root = view.rootObject();
if(!root)
Expand All @@ -183,19 +174,3 @@ int main(int argc, char *argv[])

return app.exec();
}

static void copyFileFromResources(QString from, QString to)
{
// copy a file from resources to the config dir if it does not exist there
QFileInfo toFile(to);
if(!toFile.exists()) {
QFile newToFile(toFile.absoluteFilePath());
QResource res(from);
if (newToFile.open(QIODevice::WriteOnly)) {
newToFile.write( reinterpret_cast<const char*>(res.data()) );
newToFile.close();
} else {
qWarning() << "Failed to copy default config from resources to" << toFile.filePath();
}
}
}
2 changes: 1 addition & 1 deletion qml/Key.qml
Expand Up @@ -48,7 +48,7 @@ Rectangle {
id: keyImage
anchors.centerIn: parent
opacity: key.labelOpacity
source: { if(key.label.length>1 && key.label.charAt(0)==':') return "qrc:/icons/"+key.label.substring(1)+".png"; else return ""; }
source: { if(key.label.length>1 && key.label.charAt(0)==':') return "icons/"+key.label.substring(1)+".png"; else return ""; }
scale: window.pixelRatio
}

Expand Down
4 changes: 2 additions & 2 deletions qml/Main.qml
Expand Up @@ -184,14 +184,14 @@ Item {
id: menuImg

anchors.centerIn: parent
source: "qrc:/icons/menu.png"
source: "icons/menu.png"
scale: window.pixelRatio
}
}

Image {
// terminal buffer scroll indicator
source: "qrc:/icons/scroll-indicator.png"
source: "icons/scroll-indicator.png"
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
visible: textrender.showBufferScrollIndicator
Expand Down
25 changes: 0 additions & 25 deletions resources.qrc
@@ -1,30 +1,5 @@
<RCC>
<qresource prefix="/">
<file>qml/Main.qml</file>
<file>qml/Key.qml</file>
<file>qml/Keyboard.qml</file>
<file>qml/Lineview.qml</file>
<file>qml/Button.qml</file>
<file>qml/MenuFingerterm.qml</file>
<file>qml/NotifyWin.qml</file>
<file>qml/PopupWindow.qml</file>
<file>icons/backspace.png</file>
<file>icons/down.png</file>
<file>icons/enter.png</file>
<file>icons/left.png</file>
<file>icons/menu.png</file>
<file>icons/right.png</file>
<file>icons/shift.png</file>
<file>icons/tab.png</file>
<file>icons/up.png</file>
<file>qml/UrlWindow.qml</file>
<file>data/menu.xml</file>
<file>icons/scroll-indicator.png</file>
<file>data/english.layout</file>
<file>data/finnish.layout</file>
<file>data/french.layout</file>
<file>data/german.layout</file>
<file>data/qwertz.layout</file>
<file>qml/LayoutWindow.qml</file>
</qresource>
</RCC>
6 changes: 4 additions & 2 deletions rpm/fingerterm.spec
@@ -1,5 +1,5 @@
Name: fingerterm
Version: 1.3.2
Version: 1.3.5
Release: 1
Summary: A terminal emulator with a custom virtual keyboard
Group: System/Base
Expand All @@ -24,7 +24,9 @@ Provides: meego-terminal > 0.2.2
%defattr(-,root,root,-)
%{_bindir}/*
%{_datadir}/applications/*.desktop

%{_datadir}/%{name}/*.qml
%{_datadir}/%{name}/data/*
%{_datadir}/%{name}/icons/*

%prep
%setup -q -n %{name}-%{version}
Expand Down

0 comments on commit 1d0fc67

Please sign in to comment.