Commit c3f5491c authored by Pekka Vuorela's avatar Pekka Vuorela

Avoid writing settings defaults to .ini file

Makes it harder to change global defaults later.
parent 2be98206
......@@ -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++) {
......@@ -116,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);
......@@ -133,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");
......@@ -168,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");
......@@ -177,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
......
......@@ -1265,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)
{
......
......@@ -439,19 +439,19 @@ QPointF TextRender::scrollBackBuffer(QPointF now, QPointF last)
void TextRender::doGesture(PanGesture gesture)
{
if( gesture==PanLeft ) {
sUtil->notifyText(sUtil->settingsValue("gestures/panLeftTitle").toString());
sTerm->putString(sUtil->settingsValue("gestures/panLeftCommand").toString(), true);
sUtil->notifyText(sUtil->settingsValue("gestures/panLeftTitle", "Alt-Right").toString());
sTerm->putString(sUtil->settingsValue("gestures/panLeftCommand", "\\e\\e[C").toString(), true);
}
else if( gesture==PanRight ) {
sUtil->notifyText(sUtil->settingsValue("gestures/panRightTitle").toString());
sTerm->putString(sUtil->settingsValue("gestures/panRightCommand").toString(), true);
sUtil->notifyText(sUtil->settingsValue("gestures/panRightTitle", "Alt-Left").toString());
sTerm->putString(sUtil->settingsValue("gestures/panRightCommand", "\\e\\e[D").toString(), true);
}
else if( gesture==PanDown ) {
sUtil->notifyText(sUtil->settingsValue("gestures/panDownTitle").toString());
sTerm->putString(sUtil->settingsValue("gestures/panDownCommand").toString(), true);
sUtil->notifyText(sUtil->settingsValue("gestures/panDownTitle", "Page Up").toString());
sTerm->putString(sUtil->settingsValue("gestures/panDownCommand", "\\e[5~").toString(), true);
}
else if( gesture==PanUp ) {
sUtil->notifyText(sUtil->settingsValue("gestures/panUpTitle").toString());
sTerm->putString(sUtil->settingsValue("gestures/panUpCommand").toString(), true);
sUtil->notifyText(sUtil->settingsValue("gestures/panUpTitle", "Page Down").toString());
sTerm->putString(sUtil->settingsValue("gestures/panUpCommand", "\\e[6~").toString(), true);
}
}
......@@ -45,6 +45,7 @@ Util::Util(QSettings *settings, QObject *parent) :
Util::~Util()
{
delete iSettings;
}
void Util::setWindow(QQuickView* win)
......@@ -102,12 +103,12 @@ QString Util::configPath()
return f.path();
}
QVariant Util::settingsValue(QString key)
QVariant Util::settingsValue(QString key, const QVariant &defaultValue)
{
if(!iSettings)
return QVariant();
return defaultValue;
return iSettings->value(key);
return iSettings->value(key, defaultValue);
}
void Util::setSettingsValue(QString key, QVariant value)
......@@ -128,7 +129,7 @@ int Util::uiFontSize()
int Util::fontSize()
{
return settingsValue("ui/fontSize").toInt();
return settingsValue("ui/fontSize", 11).toInt();
}
void Util::setFontSize(int size)
......@@ -143,7 +144,7 @@ void Util::setFontSize(int size)
void Util::keyPressFeedback()
{
if( !settingsValue("ui/keyPressFeedback").toBool() )
if( !settingsValue("ui/keyPressFeedback", true).toBool() )
return;
#ifdef HAVE_FEEDBACK
......@@ -153,7 +154,7 @@ void Util::keyPressFeedback()
void Util::keyReleaseFeedback()
{
if( !settingsValue("ui/keyPressFeedback").toBool() )
if( !settingsValue("ui/keyPressFeedback", true).toBool() )
return;
// TODO: check what's more comfortable, only press, or press and release
......@@ -167,19 +168,19 @@ void Util::bellAlert()
if(!iWindow)
return;
if( settingsValue("general/visualBell").toBool() ) {
if( settingsValue("general/visualBell", true).toBool() ) {
emit visualBell();
}
}
QString Util::fontFamily()
{
return settingsValue("ui/fontFamily").toString();
return settingsValue("ui/fontFamily", DEFAULT_FONTFAMILY).toString();
}
int Util::dragMode()
{
QString mode = settingsValue("ui/dragMode").toString();
QString mode = settingsValue("ui/dragMode", "scroll").toString();
if (mode == "gestures") {
return DragGestures;
......@@ -220,7 +221,7 @@ void Util::setDragMode(int mode)
int Util::keyboardMode()
{
QString mode = settingsValue("ui/vkbShowMethod").toString();
QString mode = settingsValue("ui/vkbShowMethod", "move").toString();
if (mode == "fade") {
return KeyboardFade;
......@@ -256,7 +257,7 @@ void Util::setKeyboardMode(int mode)
int Util::keyboardFadeOutDelay()
{
return settingsValue("ui/keyboardFadeOutDelay").toInt();
return settingsValue("ui/keyboardFadeOutDelay", 4000).toInt();
}
void Util::setKeyboardFadeOutDelay(int delay)
......@@ -271,7 +272,7 @@ void Util::setKeyboardFadeOutDelay(int delay)
QString Util::keyboardLayout()
{
return settingsValue("ui/keyboardLayout").toString();
return settingsValue("ui/keyboardLayout", "english").toString();
}
void Util::setKeyboardLayout(const QString &layout)
......@@ -286,22 +287,22 @@ void Util::setKeyboardLayout(const QString &layout)
int Util::extraLinesFromCursor()
{
return settingsValue("ui/showExtraLinesFromCursor").toInt();
return settingsValue("ui/showExtraLinesFromCursor", 1).toInt();
}
QString Util::charset()
{
return settingsValue("terminal/charset").toString();
return settingsValue("terminal/charset", "UTF-8").toString();
}
int Util::keyboardMargins()
{
return settingsValue("ui/keyboardMargins").toInt();
return settingsValue("ui/keyboardMargins", 10).toInt();
}
int Util::orientationMode()
{
QString mode = settingsValue("ui/orientationLockMode").toString();
QString mode = settingsValue("ui/orientationLockMode", "auto").toString();
if (mode == "auto") {
return OrientationAuto;
......@@ -337,7 +338,7 @@ void Util::setOrientationMode(int mode)
bool Util::showWelcomeScreen()
{
return settingsValue("state/showWelcomeScreen").toBool();
return settingsValue("state/showWelcomeScreen", true).toBool();
}
void Util::setShowWelcomeScreen(bool value)
......
......@@ -83,7 +83,7 @@ public:
Q_INVOKABLE QString versionString();
Q_INVOKABLE QString configPath();
QVariant settingsValue(QString key);
QVariant settingsValue(QString key, const QVariant &defaultValue = QVariant());
void setSettingsValue(QString key, QVariant value);
int uiFontSize();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment