Skip to content

Latest commit

 

History

History
254 lines (215 loc) · 9.68 KB

main.cpp

File metadata and controls

254 lines (215 loc) · 9.68 KB
 
Feb 20, 2013
Feb 20, 2013
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
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/>.
*/
#include "qplatformdefs.h"
#include <QtGui>
Jul 22, 2013
Jul 22, 2013
23
#include <QtQml>
Feb 20, 2013
Feb 20, 2013
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
extern "C" {
#include <pty.h>
#include <stdlib.h>
#include <unistd.h>
#include <pwd.h>
#include <sys/types.h>
}
#include "mainwindow.h"
#include "ptyiface.h"
#include "terminal.h"
#include "textrender.h"
#include "util.h"
#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);
Mar 19, 2015
Mar 19, 2015
49
50
QCoreApplication::setApplicationName("Fingerterm");
Jul 22, 2013
Jul 22, 2013
51
// fork the child process before creating QGuiApplication
Feb 20, 2013
Feb 20, 2013
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
int socketM;
int pid = forkpty(&socketM,NULL,NULL,NULL);
if( pid==-1 ) {
qFatal("forkpty failed");
exit(1);
} else if( pid==0 ) {
setenv("TERM", settings->value("terminal/envVarTERM").toByteArray(), 1);
QString execCmd;
for(int i=0; i<argc-1; i++) {
if( QString(argv[i]) == "-e" )
execCmd = QString(argv[i+1]);
}
if(execCmd.isEmpty()) {
execCmd = settings->value("general/execCmd").toString();
}
if(execCmd.isEmpty()) {
// execute the user's default shell
passwd *pwdstruct = getpwuid(getuid());
execCmd = QString(pwdstruct->pw_shell);
execCmd.append(" --login");
}
if(settings)
delete settings; // don't need 'em here
QStringList execParts = execCmd.split(' ', QString::SkipEmptyParts);
if(execParts.length()==0)
exit(0);
char *ptrs[execParts.length()+1];
for(int i=0; i<execParts.length(); i++) {
Jun 16, 2013
Jun 16, 2013
83
84
85
ptrs[i] = new char[execParts.at(i).toLatin1().length()+1];
memcpy(ptrs[i], execParts.at(i).toLatin1().data(), execParts.at(i).toLatin1().length());
ptrs[i][execParts.at(i).toLatin1().length()] = 0;
Feb 20, 2013
Feb 20, 2013
86
87
88
}
ptrs[execParts.length()] = 0;
Jun 16, 2013
Jun 16, 2013
89
execvp(execParts.first().toLatin1(), ptrs);
Feb 20, 2013
Feb 20, 2013
90
91
92
exit(0);
}
Jul 22, 2013
Jul 22, 2013
93
QGuiApplication app(argc, argv);
Feb 20, 2013
Feb 20, 2013
94
Oct 10, 2013
Oct 10, 2013
95
96
97
98
99
100
101
102
103
QScreen* sc = app.primaryScreen();
if(sc){
sc->setOrientationUpdateMask(Qt::PrimaryOrientation
| Qt::LandscapeOrientation
| Qt::PortraitOrientation
| Qt::InvertedLandscapeOrientation
| Qt::InvertedPortraitOrientation);
}
Feb 20, 2013
Feb 20, 2013
104
105
106
107
108
109
110
111
112
113
114
115
qmlRegisterType<TextRender>("TextRender",1,0,"TextRender");
MainWindow view;
Terminal term;
Util util(settings);
term.setUtil(&util);
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");
Mar 31, 2014
Mar 31, 2014
116
copyFileFromResources(":/data/french.layout", util.configPath()+"/french.layout");
Jan 17, 2014
Jan 17, 2014
117
118
copyFileFromResources(":/data/german.layout", util.configPath()+"/german.layout");
copyFileFromResources(":/data/qwertz.layout", util.configPath()+"/qwertz.layout");
Feb 20, 2013
Feb 20, 2013
119
120
121
122
123
124
125
126
127
128
129
130
131
KeyLoader keyLoader;
keyLoader.setUtil(&util);
bool ret = keyLoader.loadLayout( settings->value("ui/keyboardLayout").toString() );
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");
ret = keyLoader.loadLayout(":/data/english.layout");
if(!ret)
qFatal("failure loading keyboard layout");
}
Jul 22, 2013
Jul 22, 2013
132
QQmlContext *context = view.rootContext();
Feb 20, 2013
Feb 20, 2013
133
134
135
136
137
context->setContextProperty( "term", &term );
context->setContextProperty( "util", &util );
context->setContextProperty( "keyLoader", &keyLoader );
view.setSource(QUrl("qrc:/qml/Main.qml"));
Apr 29, 2016
Apr 29, 2016
138
view.setResizeMode(QQuickView::SizeRootObjectToView);
Feb 20, 2013
Feb 20, 2013
139
Aug 14, 2013
Aug 14, 2013
140
141
QObject *root = view.rootObject();
if(!root)
Feb 20, 2013
Feb 20, 2013
142
143
qFatal("no root object - qml error");
Aug 14, 2013
Aug 14, 2013
144
145
QObject* win = root->findChild<QObject*>("window");
Feb 20, 2013
Feb 20, 2013
146
147
148
if(!startupErrorMsg.isEmpty())
QMetaObject::invokeMethod(win, "showErrorMessage", Qt::QueuedConnection, Q_ARG(QVariant, startupErrorMsg));
Aug 14, 2013
Aug 14, 2013
149
TextRender *tr = root->findChild<TextRender*>("textrender");
Feb 20, 2013
Feb 20, 2013
150
151
152
153
154
155
156
157
158
159
160
tr->setUtil(&util);
tr->setTerminal(&term);
term.setRenderer(tr);
term.setWindow(&view);
util.setWindow(&view);
util.setTerm(&term);
util.setRenderer(tr);
QObject::connect(&term,SIGNAL(displayBufferChanged()),win,SLOT(displayBufferChanged()));
QObject::connect(view.engine(),SIGNAL(quit()),&app,SLOT(quit()));
Jul 22, 2013
Jul 22, 2013
161
162
QSize screenSize = QGuiApplication::primaryScreen()->size();
if ((screenSize.width() < 1024 || screenSize.height() < 768 || app.arguments().contains("-fs"))
Feb 20, 2013
Feb 20, 2013
163
&& !app.arguments().contains("-nofs"))
Jul 22, 2013
Jul 22, 2013
164
{
Feb 20, 2013
Feb 20, 2013
165
view.showFullScreen();
Jul 22, 2013
Jul 22, 2013
166
} else
Feb 20, 2013
Feb 20, 2013
167
view.show();
May 4, 2016
May 4, 2016
168
Feb 20, 2013
Feb 20, 2013
169
170
171
172
173
174
175
176
177
178
179
PtyIFace ptyiface(pid, socketM, &term,
settings->value("terminal/charset").toString());
if( ptyiface.failed() )
qFatal("pty failure");
return app.exec();
}
void defaultSettings(QSettings* settings)
{
Aug 14, 2013
Aug 14, 2013
180
181
if(!settings->contains("ui/orientationLockMode"))
settings->setValue("ui/orientationLockMode", "auto");
Feb 20, 2013
Feb 20, 2013
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
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"))
May 4, 2016
May 4, 2016
199
settings->setValue("ui/fontFamily", DEFAULT_FONTFAMILY);
Feb 20, 2013
Feb 20, 2013
200
201
202
203
204
205
206
if(!settings->contains("ui/fontSize"))
settings->setValue("ui/fontSize", 11);
if(!settings->contains("ui/keyboardMargins"))
settings->setValue("ui/keyboardMargins", 10);
if(!settings->contains("ui/allowSwipe"))
settings->setValue("ui/allowSwipe", "auto"); // "true", "false", "auto"
if(!settings->contains("ui/keyboardFadeOutDelay"))
Dec 10, 2013
Dec 10, 2013
207
settings->setValue("ui/keyboardFadeOutDelay", 4000);
Feb 20, 2013
Feb 20, 2013
208
209
210
if(!settings->contains("ui/showExtraLinesFromCursor"))
settings->setValue("ui/showExtraLinesFromCursor", 1);
if(!settings->contains("ui/vkbShowMethod"))
Dec 10, 2013
Dec 10, 2013
211
settings->setValue("ui/vkbShowMethod", "move"); // "fade", "move", "off"
Feb 20, 2013
Feb 20, 2013
212
213
214
if(!settings->contains("ui/keyPressFeedback"))
settings->setValue("ui/keyPressFeedback", true);
if(!settings->contains("ui/dragMode"))
Dec 10, 2013
Dec 10, 2013
215
settings->setValue("ui/dragMode", "scroll"); // "gestures, "scroll", "select" ("off" would also be ok)
Feb 20, 2013
Feb 20, 2013
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
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
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 {
qFatal("failed to copy default config from resources");
}
}
}