Commit f18fd22c authored by pvuorela's avatar pvuorela

Merge branch 'master' into 'master'

Refactor some more

@jpetrell @rainemak

See merge request !13
parents 12f8f8eb a7aa9f29
......@@ -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
......
......@@ -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");
......@@ -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++) {
......@@ -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");
......@@ -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);
......@@ -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");
......@@ -167,8 +166,7 @@ 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");
......@@ -176,66 +174,6 @@ int main(int argc, char *argv[])
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
......
......@@ -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()));
......@@ -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);
}
......
......@@ -38,10 +38,8 @@ public:
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:
......
......@@ -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 } }
}
......@@ -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 } }
}
......
......@@ -19,7 +19,7 @@
import QtQuick 2.0
Rectangle {
Item {
id: keyboard
property int keyModifiers
......@@ -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
......@@ -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
......
......@@ -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
......@@ -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)
}
}
}
......@@ -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 }
}
]
}
......@@ -18,28 +18,32 @@
*/
import QtQuick 2.0
import FingerTerm 1.0
Rectangle {
id: lineView
property variant lines: [""]
property int fontPointSize: util.settingsValue("ui/fontSize")*window.pixelRatio;
property int fontPointSize: util.fontSize
property int cursorX: 1
property int cursorWidth: 10
property int cursorHeight: 10
property int extraLines: 1
property int extraLines: util.extraLinesFromCursor
property bool show
y: show ? 0 : -(height+window.paddingSmall)
color: "#404040"
border.width: 2
border.color: "#909090"
radius: window.radiusSmall
width: parent.width
height: lineTextCol.height + 8*window.pixelRatio
Text {
id: fontHeightHack
visible: false
text: "X"
font.family: util.settingsValue("ui/fontFamily");
font.family: util.fontFamily
font.pointSize: lineView.fontPointSize
}
......@@ -56,11 +60,13 @@ Rectangle {
Column {
id: lineTextCol
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.right: parent.right
anchors.leftMargin: 2*window.pixelRatio
anchors.rightMargin: 2*window.pixelRatio
Repeater {
model: lines
delegate: Item {
......@@ -68,7 +74,7 @@ Rectangle {
width: lineTextCol.width
Text {
color: "#ffffff"
font.family: util.settingsValue("ui/fontFamily");
font.family: util.fontFamily
font.pointSize: lineView.fontPointSize
text: modelData
textFormat: Text.PlainText
......@@ -78,29 +84,5 @@ Rectangle {
}
}
}
onHeightChanged: {
if(lineView.visible)
lineView.height = height+8*window.pixelRatio
setPosition(vkb.active)
}
}
Component.onCompleted: {
extraLines = util.settingsValue("ui/showExtraLinesFromCursor");
}
function setPosition(vkbActive)
{
if( util.settingsValue("ui/vkbShowMethod")==="off" ) {
lineView.visible = false;
return;
}
lineView.visible = true;
if(vkbActive && util.settingsValue("ui/vkbShowMethod")!=="move") {
y = 0;
} else {
y = -(height+window.paddingSmall)
}
}
}
This diff is collapsed.
This diff is collapsed.
......@@ -19,26 +19,13 @@
import QtQuick 2.0
Rectangle {
PopupWindow {
id: notifyWin
property string text
signal dismissed()
width: window.width-1
height: window.height-1
color: "#000000"
y: -(height+1)
state: ""
border.color: "#c0c0c0"
border.width: 1
radius: window.radiusMedium
MouseArea {
// event eater
anchors.fill: parent
}
Item {
anchors.top: notifyWin.top
anchors.left: notifyWin.left
......@@ -66,26 +53,8 @@ Rectangle {
anchors.bottomMargin: window.paddingMedium
text: "OK"
onClicked: {
notifyWin.state = ""
notifyWin.show = false
notifyWin.dismissed();
}
}
states: [
State {
name: "visible"
PropertyChanges {
target: notifyWin
y: 0
}
}
]
transitions: [
Transition {
from: "*"
to: "*"
PropertyAnimation { target: notifyWin; properties: "y"; duration: 200; easing.type: Easing.InOutCubic }
}
]
}
/*
Copyright 2011-2012 Heikki Holstila <heikki.holstila@gmail.com>
This file is part of FingerTerm.
FingerTerm is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
FingerTerm is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FingerTerm. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.0
Rectangle {
id: root
property bool show
width: window.width
height: window.height
color: "#000000"
y: -height
border.color: "#c0c0c0"
border.width: 1
radius: window.radiusMedium
MouseArea {
// event eater
anchors.fill: parent
}
states: [
State {
name: "shown"
when: root.show
PropertyChanges { target: root; y: 0 }
}
]
transitions: [
Transition {
to: "*"
NumberAnimation {
properties: "y"
duration: 200
easing.type: Easing.InOutCubic
}
}
]
}
......@@ -19,24 +19,11 @@
import QtQuick 2.0
Rectangle {
PopupWindow {
id: urlWindow
property variant urls: [""]
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 {
......@@ -104,26 +91,6 @@ Rectangle {
anchors.bottom: parent.bottom
anchors.bottomMargin: window.paddingMedium
text: "Back"
onClicked: {
urlWindow.state = ""
}
onClicked: urlWindow.show = false
}
states: [
State {
name: "visible"
PropertyChanges {
target: urlWindow
y: 0
}
}
]
transitions: [
Transition {
from: "*"
to: "*"
PropertyAnimation { target: urlWindow; properties: "y"; duration: 200; easing.type: Easing.InOutCubic }
}
]
}
......@@ -7,6 +7,7 @@
<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>
......
Name: fingerterm
Version: 1.1.14
Version: 1.3.0
Release: 1
Summary: A terminal emulator with a custom virtual keyboard
Group: System/Base
......
......@@ -26,6 +26,18 @@
#include "textrender.h"
#include "util.h"
static bool charIsHexDigit(QChar ch)
{
if (ch.isDigit()) // 0-9
return true;
else if (ch.toLatin1() >= 65 && ch.toLatin1() <= 70) // A-F
return true;
else if (ch.toLatin1() >= 97 && ch.toLatin1() <= 102) // a-f
return true;
return false;
}
Terminal::Terminal(QObject *parent) :
QObject(parent), iPtyIFace(0), iWindow(0), iUtil(0),
iTermSize(0,0), iEmitCursorChangeSignal(true),
......@@ -116,7 +128,7 @@ void Terminal::setTermSize(QSize size)
resetTabs();
emit termSizeChanged(size);
emit termSizeChanged(size.height(), size.width());
}
}
......@@ -133,7 +145,7 @@ void Terminal::putString(QString str, bool unEscape)
while(str.indexOf("\\x") != -1) {
int i = str.indexOf("\\x")+2;
QString num;
while(num.length() < 2 && str.length()>i && Util::charIsHexDigit(str.at(i))) {
while(num.length() < 2 && str.length()>i && charIsHexDigit(str.at(i))) {
num.append(str.at(i));
i++;
}
......@@ -337,7 +349,7 @@ void Terminal::insertInBuffer(const QString& chars)
if(iNewLineMode)
setCursorPos(QPoint(1,cursorPos().y()));
}
else if(cursorPos().x() <= termSize().width()) // ignore newline after <termwidth> cols (terminfo: xenl)
else if(cursorPos().x() <= columns()) // ignore newline after <termwidth> cols (terminfo: xenl)
{
if(iNewLineMode)
setCursorPos(QPoint(1,cursorPos().y()+1));
......@@ -1034,9 +1046,9 @@ void Terminal::escControlChar(const QString& seq)
return;
if( seq.at(0) == '#' && seq.at(1)=='8' ) { // test mode, fill screen with 'E'
clearAll(true);
for(int i=0; i<termSize().height(); i++) {
for (int i = 0; i < rows(); i++) {
QList<TermChar> line;
for(int j=0; j<termSize().width(); j++) {
for(int j = 0; j < columns(); j++) {
TermChar c = zeroChar;
c.c = 'E';
line.append(c);
......@@ -1253,7 +1265,7 @@ const QStringList Terminal::grabURLsFromBuffer()
QByteArray buf;
//backbuffer
if ((iUtil->settingsValue("general/grabUrlsFromBackbuffer").toBool()
if ((iUtil->settingsValue("general/grabUrlsFromBackbuffer", false).toBool()
&& !iUseAltScreenBuffer)
|| backBufferScrollPos() > 0) //a lazy workaround: just grab everything when the buffer is being scrolled (TODO: make a proper fix)
{
......@@ -1486,6 +1498,16 @@ void Terminal::clearSelection()
emit selectionChanged();
}
int Terminal::rows()
{
return iTermSize.height();
}
int Terminal::columns()
{
return iTermSize.width();
}
QRect Terminal::selection()
{
return iSelection;
......
......@@ -53,6 +53,9 @@ struct TermAttribs {
class Terminal : public QObject
{
Q_OBJECT
Q_PROPERTY(int rows READ rows NOTIFY termSizeChanged)
Q_PROPERTY(int columns READ columns NOTIFY termSizeChanged)
public:
static const int defaultFgColor = 7;
static const int defaultBgColor = 0;
......@@ -70,7 +73,7 @@ public:
void setCursorPos(QPoint pos);
bool showCursor();
Q_INVOKABLE QSize termSize() { return iTermSize; }
QSize termSize() { return iTermSize; }
void setTermSize(QSize size);
QList<QList<TermChar> >& buffer();
......@@ -98,11 +101,14 @@ public:
Q_INVOKABLE void clearSelection();
bool hasSelection();
int rows();
int columns();
TermChar zeroChar;
signals:
void cursorPosChanged(QPoint newPos);
void termSizeChanged(QSize newSize);
void termSizeChanged(int rows, int columns);
void displayBufferChanged();
void selectionChanged();
void scrollBackBufferAdjusted(bool reset);
......
......@@ -27,7 +27,8 @@ Util* TextRender::sUtil = 0;
TextRender::TextRender(QQuickItem *parent) :
QQuickPaintedItem(parent),
newSelection(true)
newSelection(true),
iAllowGestures(true)
{
setFlag(ItemHasContents);
......@@ -74,8 +75,7 @@ TextRender::TextRender(QQuickItem *parent) :