Skip to content
This repository has been archived by the owner on Jul 20, 2022. It is now read-only.

Commit

Permalink
Add keyboard select view
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroHLC committed Oct 2, 2019
1 parent c1891a2 commit c0cce2a
Show file tree
Hide file tree
Showing 9 changed files with 204 additions and 10 deletions.
3 changes: 1 addition & 2 deletions README.md
Expand Up @@ -34,7 +34,7 @@ So you won't need Wayland, neither X nor a WM.

# Dependencies
```
yay -S qt5-base qt5-quickcontrols2 libevdev
yay -S qt5-base qt5-quickcontrols2 libinput libxkbcommon
```

# How to compile?
Expand All @@ -49,7 +49,6 @@ make
Open a TTY without an open graphical session (`Ctrl+Alt+F3` should do it):

```
export QT_QPA_EGLFS_NO_LIBINPUT=1
./bin/chaotic-installer
```

Expand Down
6 changes: 4 additions & 2 deletions chaotic-installer.pro
Expand Up @@ -7,8 +7,10 @@ VPATH *= $${BASEDIR}/src

TRANSLATIONS = langs/en_US.ts langs/pt_BR.ts

HEADERS = chaotic-installer.hpp lib/language.hpp
SOURCES = main.cpp lib/language.cpp
HEADERS = chaotic-installer.hpp \
lib/language.hpp lib/locale.hpp
SOURCES = main.cpp \
lib/language.cpp lib/locale.cpp
TARGET = bin/chaotic-installer

lupdate_only {
Expand Down
1 change: 0 additions & 1 deletion launcher/startchaotic
@@ -1,5 +1,4 @@
#!/usr/bin/env sh
export QT_QPA_EGLFS_NO_LIBINPUT=1
export QT_QPA_PLATFORM=eglfs
export XDG_RUNTIME_DIR=/tmp/chaotic-intaller-runtime
mkdir -p "$XDG_RUNTIME_DIR" && chmod 0700 "$XDG_RUNTIME_DIR"
Expand Down
92 changes: 92 additions & 0 deletions qml/KeyboardPicker.qml
@@ -0,0 +1,92 @@
/* Chaotic Installer Keyboard Picker Screen
I like to write this by hand, do whatever you want, but keep diff clean to read, so I
can keep writing it manually.
Also, consider this file copyright-free.
*/

import QtQuick 2.2
import QtQuick.Controls 2.12
import QtQuick.Controls.Material 2.12

Component {
Column {
Row {
id: pickKeyboardTitleRow
anchors.top: parent.top
anchors.topMargin: 20
anchors.horizontalCenter: parent.horizontalCenter

Text {
text: qsTr('Select your key-map:\n\nIf unsure leave default')
}
}
Row {
id: pickKeyboardListView
anchors.top: pickKeyboardTitleRow.bottom
anchors.bottom: pickKeyboardActionRow.top
anchors.bottomMargin: 20
width: parent.width

//Flickable {
ScrollView {
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
width: 320
clip: true

contentWidth: pickKeyboardList.width
contentHeight: pickKeyboardList.height

ScrollBar.vertical: ScrollBar {
policy: ScrollBar.AlwaysOn;
parent: pickKeyboardListView
anchors.top: parent.top
anchors.right: parent.right
anchors.bottom: parent.bottom
}

Column {
id: pickKeyboardList

Repeater {
model: allKeyboards

RadioButton {text: modelData; onClicked: setupLocale.selectedKeyboard = modelData }
}
}
}
}

Row {
id: pickKeyboardActionRow
anchors.bottom: parent.bottom
anchors.bottomMargin: 20
anchors.horizontalCenter: parent.horizontalCenter
spacing: 80

Column {
Button {
text: qsTr('Back')
onClicked: contentStack.pop()
}
}

Column {
TextField {
placeholderText: qsTr('Testing area')
}
}

Column {
Button {
text: qsTr('Next')
highlighted: true
Material.background: Material.Indigo
}
}
}
}
}
12 changes: 7 additions & 5 deletions qml/LanguagePicker.qml
Expand Up @@ -23,6 +23,7 @@ Component {
}
}
Row {
id: pickLangListView
anchors.top: pickLangTitleRow.bottom
anchors.bottom: pickLangActionRow.top
anchors.bottomMargin: 20
Expand All @@ -41,9 +42,9 @@ Component {

ScrollBar.vertical: ScrollBar {
policy: ScrollBar.AlwaysOn;
parent: parent.parent
parent: pickLangListView
anchors.top: parent.top
anchors.left: parent.right
anchors.right: parent.right
anchors.bottom: parent.bottom
}

Expand Down Expand Up @@ -81,16 +82,17 @@ Component {

Column {
Button {
text: qsTr('Leave')
onClicked: Qt.quit()
text: qsTr('Abort')
onClicked: Qt.quit()
}
}

Column {
Button {
text: qsTr('Confirm')
text: qsTr('Next')
highlighted: true
Material.background: Material.Indigo
onClicked: contentStack.push(keyboardPicker)
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions qml/MainContainer.qml
Expand Up @@ -30,6 +30,7 @@ Rectangle {
Rectangle {
width: 640
height: 480
clip: true
anchors.centerIn: parent
color: Material.background

Expand Down Expand Up @@ -74,4 +75,5 @@ Rectangle {
}

LanguagePicker { id: languagePicker }
KeyboardPicker { id: keyboardPicker }
}
57 changes: 57 additions & 0 deletions src/lib/locale.cpp
@@ -0,0 +1,57 @@
#include <QProcess>
#include <QDebug>
#include <QtPlatformHeaders/QEglFSFunctions>

#include "locale.hpp"

Locale::Locale(QObject *parent) :
QObject (parent) {}

void Locale::toggleLocale(QString locale) {
//TODO
}

QString Locale::getSelectedKeyboard()
{
return selectedKeyboard;
}

QStringList Locale::getSelectedLocales()
{
return selectedLocales;
}

QString Locale::getSelectedZone()
{
return selectedZone;
}

void Locale::setKeyboard(const QString &keymap) {
qDebug() << "Setting keymap " << keymap;

selectedKeyboard = keymap;
QProcess::execute(QStringLiteral("loadkeys %1").arg(keymap));
QProcess::execute(QStringLiteral("localectl set-keymap %1").arg(keymap));
QEglFSFunctions::loadKeymap(
keymapDir.filePath(QStringLiteral("%1.map.gz").arg(keymap))
);

emit keyboardChanged();
}

void Locale::setZone(const QString &zone) {
//TODO
}

QStringList Locale::keyboardsCache = QStringList();
QDir Locale::keymapDir = QDir(QStringLiteral("/usr/share/kbd/keymaps/i386/qwerty"));

QStringList Locale::allKeyboards() const {
if(keyboardsCache.size() < 1) {
keymapDir.setNameFilters(QStringList() << "*.map.gz");
keyboardsCache = keymapDir
.entryList()
.replaceInStrings(".map.gz", "");
}
return keyboardsCache;
}
37 changes: 37 additions & 0 deletions src/lib/locale.hpp
@@ -0,0 +1,37 @@
#ifndef LOCALE_H
#define LOCALE_H

#include <QObject>
#include <QDir>

class Locale : public QObject {
Q_OBJECT
Q_PROPERTY(QString selectedKeyboard READ getSelectedKeyboard WRITE setKeyboard NOTIFY keyboardChanged)
Q_PROPERTY(QStringList selectedLocales READ getSelectedLocales NOTIFY localesChanged)
Q_PROPERTY(QString selectedZone READ getSelectedZone WRITE setZone NOTIFY zoneChanged)

private:
QString selectedKeyboard;
QStringList selectedLocales;
QString selectedZone;
static QStringList keyboardsCache;
static QDir keymapDir;

public:
explicit Locale(QObject *parent = nullptr);

void setKeyboard(const QString &keymap);
void setZone(const QString &locale);
Q_INVOKABLE void toggleLocale(const QString locale);

QStringList allKeyboards() const;
QString getSelectedKeyboard();
QStringList getSelectedLocales();
QString getSelectedZone();
signals:
void keyboardChanged();
void localesChanged();
void zoneChanged();
};

#endif // LOCALE_H
4 changes: 4 additions & 0 deletions src/main.cpp
Expand Up @@ -30,6 +30,7 @@

#include "chaotic-installer.hpp"
#include "lib/language.hpp"
#include "lib/locale.hpp"

int main(int argc, char *argv[])
{
Expand All @@ -47,11 +48,14 @@ int main(int argc, char *argv[])
// Components
//Component * m_compo = new Component(&view);
Lang * m_lang = new Lang(&app, view.engine(), &view);
Locale * m_locale = new Locale(&view);

// Context props
//context->setContextProperty(QStringLiteral("compo"), m_compo);
context->setContextProperty(QStringLiteral("lang"), m_lang);
context->setContextProperty(QStringLiteral("setupLocale"), m_locale);
context->setContextProperty(QStringLiteral("assetsPath"), appPath.resolved(QStringLiteral(ASSETS_PATH)));
context->setContextProperty(QStringLiteral("allKeyboards"), QVariant::fromValue(m_locale->allKeyboards()));

// Some connections
QObject::connect(view.engine(), &QQmlApplicationEngine::quit, &QGuiApplication::quit);
Expand Down

0 comments on commit c0cce2a

Please sign in to comment.