Skip to content

Commit

Permalink
Merge branch 'master' into 'master'
Browse files Browse the repository at this point in the history
Refactor some more

@jpetrell @rainemak

See merge request !13
  • Loading branch information
pvuorela committed Jul 6, 2016
2 parents 12f8f8e + a7aa9f2 commit f18fd22
Show file tree
Hide file tree
Showing 22 changed files with 528 additions and 449 deletions.
3 changes: 2 additions & 1 deletion fingerterm.pro
Expand Up @@ -49,7 +49,8 @@ OTHER_FILES += \
qml/MenuFingerterm.qml \
qml/NotifyWin.qml \
qml/UrlWindow.qml \
qml/LayoutWindow.qml
qml/LayoutWindow.qml \
qml/PopupWindow.qml

RESOURCES += \
resources.qrc
Expand Down
76 changes: 7 additions & 69 deletions main.cpp
Expand Up @@ -38,13 +38,11 @@ extern "C" {
#include "version.h"
#include "keyloader.h"

void defaultSettings(QSettings* settings);
void copyFileFromResources(QString from, QString to);

int main(int argc, char *argv[])
{
QSettings *settings = new QSettings(QDir::homePath()+"/.config/FingerTerm/settings.ini", QSettings::IniFormat);
defaultSettings(settings);

QCoreApplication::setApplicationName("Fingerterm");

Expand All @@ -55,7 +53,7 @@ int main(int argc, char *argv[])
qFatal("forkpty failed");
exit(1);
} else if( pid==0 ) {
setenv("TERM", settings->value("terminal/envVarTERM").toByteArray(), 1);
setenv("TERM", settings->value("terminal/envVarTERM", "xterm").toByteArray(), 1);

QString execCmd;
for(int i=0; i<argc-1; i++) {
Expand Down Expand Up @@ -100,7 +98,8 @@ int main(int argc, char *argv[])
| Qt::InvertedPortraitOrientation);
}

qmlRegisterType<TextRender>("TextRender",1,0,"TextRender");
qmlRegisterType<TextRender>("FingerTerm", 1, 0, "TextRender");
qmlRegisterUncreatableType<Util>("FingerTerm", 1, 0, "Util", "Util is created by app");
QQuickView view;

bool fullscreen = !app.arguments().contains("-nofs");
Expand All @@ -115,7 +114,7 @@ int main(int argc, char *argv[])
}

Terminal term;
Util util(settings);
Util util(settings); // takes ownership
term.setUtil(&util);
TextRender::setUtil(&util);
TextRender::setTerminal(&term);
Expand All @@ -132,11 +131,11 @@ int main(int argc, char *argv[])

KeyLoader keyLoader;
keyLoader.setUtil(&util);
bool ret = keyLoader.loadLayout( settings->value("ui/keyboardLayout").toString() );
bool ret = keyLoader.loadLayout(util.keyboardLayout());
if(!ret) {
// on failure, try to load the default one (english) directly from resources
startupErrorMsg = "There was an error loading the keyboard layout.<br>\nUsing the default one instead.";
settings->setValue("ui/keyboardLayout", "english");
util.setKeyboardLayout("english");
ret = keyLoader.loadLayout(":/data/english.layout");
if(!ret)
qFatal("failure loading keyboard layout");
Expand Down Expand Up @@ -167,75 +166,14 @@ int main(int argc, char *argv[])
view.show();
}

PtyIFace ptyiface(pid, socketM, &term,
settings->value("terminal/charset").toString());
PtyIFace ptyiface(pid, socketM, &term, util.charset());

if( ptyiface.failed() )
qFatal("pty failure");

return app.exec();
}

void defaultSettings(QSettings* settings)
{
if(!settings->contains("ui/orientationLockMode"))
settings->setValue("ui/orientationLockMode", "auto");
if(!settings->contains("general/execCmd"))
settings->setValue("general/execCmd", "");
if(!settings->contains("general/visualBell"))
settings->setValue("general/visualBell", true);
if(!settings->contains("general/backgroundBellNotify"))
settings->setValue("general/backgroundBellNotify", true);
if(!settings->contains("general/grabUrlsFromBackbuffer"))
settings->setValue("general/grabUrlsFromBackbuffer", false);

if(!settings->contains("terminal/envVarTERM"))
settings->setValue("terminal/envVarTERM", "xterm");
if(!settings->contains("terminal/charset"))
settings->setValue("terminal/charset", "UTF-8");

if(!settings->contains("ui/keyboardLayout"))
settings->setValue("ui/keyboardLayout", "english");
if(!settings->contains("ui/fontFamily"))
settings->setValue("ui/fontFamily", DEFAULT_FONTFAMILY);
if(!settings->contains("ui/fontSize"))
settings->setValue("ui/fontSize", 11);
if(!settings->contains("ui/keyboardMargins"))
settings->setValue("ui/keyboardMargins", 10);
if(!settings->contains("ui/keyboardFadeOutDelay"))
settings->setValue("ui/keyboardFadeOutDelay", 4000);
if(!settings->contains("ui/showExtraLinesFromCursor"))
settings->setValue("ui/showExtraLinesFromCursor", 1);
if(!settings->contains("ui/vkbShowMethod"))
settings->setValue("ui/vkbShowMethod", "move"); // "fade", "move", "off"
if(!settings->contains("ui/keyPressFeedback"))
settings->setValue("ui/keyPressFeedback", true);
if(!settings->contains("ui/dragMode"))
settings->setValue("ui/dragMode", "scroll"); // "gestures, "scroll", "select" ("off" would also be ok)

if(!settings->contains("state/showWelcomeScreen"))
settings->setValue("state/showWelcomeScreen", true);
if(!settings->contains("state/createdByVersion"))
settings->setValue("state/createdByVersion", PROGRAM_VERSION);

if(!settings->contains("gestures/panLeftTitle"))
settings->setValue("gestures/panLeftTitle", "Alt-Right");
if(!settings->contains("gestures/panLeftCommand"))
settings->setValue("gestures/panLeftCommand", "\\e\\e[C");
if(!settings->contains("gestures/panRightTitle"))
settings->setValue("gestures/panRightTitle", "Alt-Left");
if(!settings->contains("gestures/panRightCommand"))
settings->setValue("gestures/panRightCommand", "\\e\\e[D");
if(!settings->contains("gestures/panUpTitle"))
settings->setValue("gestures/panUpTitle", "Page Down");
if(!settings->contains("gestures/panUpCommand"))
settings->setValue("gestures/panUpCommand", "\\e[6~");
if(!settings->contains("gestures/panDownTitle"))
settings->setValue("gestures/panDownTitle", "Page Up");
if(!settings->contains("gestures/panDownCommand"))
settings->setValue("gestures/panDownCommand", "\\e[5~");
}

void copyFileFromResources(QString from, QString to)
{
// copy a file from resources to the config dir if it does not exist there
Expand Down
10 changes: 5 additions & 5 deletions ptyiface.cpp
Expand Up @@ -68,8 +68,8 @@ PtyIFace::PtyIFace(int pid, int masterFd, Terminal *term, QString charset, QObje

iTerm->setPtyIFace(this);

resize(iTerm->termSize());
connect(iTerm,SIGNAL(termSizeChanged(QSize)),this,SLOT(resize(QSize)));
resize(iTerm->rows(), iTerm->columns());
connect(iTerm,SIGNAL(termSizeChanged(int,int)),this,SLOT(resize(int,int)));

iReadNotifier = new QSocketNotifier(iMasterFd, QSocketNotifier::Read, this);
connect(iReadNotifier,SIGNAL(activated(int)),this,SLOT(readActivated()));
Expand Down Expand Up @@ -104,14 +104,14 @@ void PtyIFace::readActivated()
iTerm->insertInBuffer( iTextCodec->toUnicode(data) );
}

void PtyIFace::resize(QSize newSize)
void PtyIFace::resize(int rows, int columns)
{
if(childProcessQuit)
return;

winsize winp;
winp.ws_col = newSize.width();
winp.ws_row = newSize.height();
winp.ws_col = columns;
winp.ws_row = rows;

ioctl(iMasterFd, TIOCSWINSZ, &winp);
}
Expand Down
4 changes: 1 addition & 3 deletions ptyiface.h
Expand Up @@ -38,10 +38,8 @@ class PtyIFace : public QObject
void writeTerm(const QString &chars);
bool failed() { return iFailed; }

public slots:
void resize(QSize newSize);

private slots:
void resize(int rows, int columns);
void readActivated();

private:
Expand Down
4 changes: 2 additions & 2 deletions qml/Key.qml
Expand Up @@ -72,7 +72,7 @@ Rectangle {
opacity: key.labelOpacity * (highlighted ? 1.0 : 0.2)
Behavior on opacity { NumberAnimation { duration: 100 } }

font.family: util.settingsValue("ui/fontFamily");
font.family: util.fontFamily
font.pointSize: (highlighted ? window.fontSizeLarge : window.fontSizeSmall) * (text.length > 1 ? 0.5 : 1.0)
Behavior on font.pointSize { NumberAnimation { duration: 100 } }
}
Expand Down Expand Up @@ -100,7 +100,7 @@ Rectangle {
opacity: key.labelOpacity * (highlighted ? 1.0 : 0.2)
Behavior on opacity { NumberAnimation { duration: 100 } }

font.family: util.settingsValue("ui/fontFamily");
font.family: util.fontFamily
font.pointSize: (highlighted ? window.fontSizeLarge : window.fontSizeSmall) * (text.length > 1 ? 0.5 : 1.0)
Behavior on font.pointSize { NumberAnimation { duration: 100 } }
}
Expand Down
31 changes: 16 additions & 15 deletions qml/Keyboard.qml
Expand Up @@ -19,7 +19,7 @@

import QtQuick 2.0

Rectangle {
Item {
id: keyboard

property int keyModifiers
Expand All @@ -34,12 +34,11 @@ Rectangle {

property bool active

property int outmargins: util.settingsValue("ui/keyboardMargins")
property int outmargins: util.keyboardMargins
property int keyspacing: 6
property int keysPerRow: keyLoader.vkbColumns()
property real keywidth: (keyboard.width - keyspacing*keysPerRow - outmargins*2)/keysPerRow;

color: "transparent"
width: parent.width
height: childrenRect.height + outmargins

Expand Down Expand Up @@ -99,21 +98,23 @@ Rectangle {
}
}

function reloadLayout()
{
var ret = keyLoader.loadLayout(util.settingsValue("ui/keyboardLayout"));
if (!ret) {
showErrorMessage("There was an error loading the keyboard layout.<br>\nUsing the default one instead.");
util.setSettingsValue("ui/keyboardLayout", "english");
ret = keyLoader.loadLayout(":/data/english.layout"); //try the default as a fallback (load from resources to ensure it will succeed)
Connections {
target: util
onKeyboardLayoutChanged: {
var ret = keyLoader.loadLayout(util.keyboardLayout)
if (!ret) {
console.log("keyboard layout fail");
Qt.quit();
showErrorMessage("There was an error loading the keyboard layout.<br>\nUsing the default one instead.");
util.keyboardLayout = "english"
ret = keyLoader.loadLayout(":/data/english.layout"); //try the default as a fallback (load from resources to ensure it will succeed)
if (!ret) {
console.log("keyboard layout fail");
Qt.quit();
}
}
// makes the keyboard component reload itself with new data
keyboardLoader.sourceComponent = undefined
keyboardLoader.sourceComponent = keyboardContents
}
// makes the keyboard component reload itself with new data
keyboardLoader.sourceComponent = undefined
keyboardLoader.sourceComponent = keyboardContents
}

//borrowed from nemo-keyboard
Expand Down
51 changes: 6 additions & 45 deletions qml/LayoutWindow.qml
Expand Up @@ -19,29 +19,15 @@

import QtQuick 2.0

Rectangle {
PopupWindow {
id: layoutWindow

property string currentLayout: util.settingsValue("ui/keyboardLayout");
property variant layouts: [""]

width: window.width-1
height: window.height-1
color: "#000000"
y: -(height+1)
border.color: "#c0c0c0"
border.width: 1
radius: window.radiusMedium

MouseArea {
// event eater
anchors.fill: parent
}

Component {
id: listDelegate
Rectangle {
color: currentLayout === modelData ? "#909090" : "#404040"
color: util.keyboardLayout === modelData ? "#909090" : "#404040"
width: parent.width
height: selectButton.height+4*window.pixelRatio
border.width: 1
Expand All @@ -66,10 +52,9 @@ Rectangle {
width: 70*window.pixelRatio
anchors.rightMargin: window.paddingSmall
onClicked: {
util.setSettingsValue("ui/keyboardLayout", modelData);
vkb.reloadLayout();
layoutWindow.state = "";
util.notifyText(modelData);
util.keyboardLayout = modelData
layoutWindow.show = false
util.notifyText(modelData)
}
}
}
Expand Down Expand Up @@ -99,30 +84,6 @@ Rectangle {
anchors.bottom: parent.bottom
anchors.bottomMargin: window.paddingMedium
text: "Back"
onClicked: {
layoutWindow.state = ""
}
onClicked: layoutWindow.show = false
}

states: [
State {
name: "visible"
PropertyChanges {
target: layoutWindow
y: 0
}
StateChangeScript {
script:
currentLayout = util.settingsValue("ui/keyboardLayout");
}
}
]

transitions: [
Transition {
from: "*"
to: "*"
PropertyAnimation { target: layoutWindow; properties: "y"; duration: 200; easing.type: Easing.InOutCubic }
}
]
}

0 comments on commit f18fd22

Please sign in to comment.