2020-03-25 16:08:12 +01:00
|
|
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
|
|
|
*
|
|
|
|
* Copyright 2019-2020, Adriaan de Groot <groot@kde.org>
|
2020-04-03 10:18:07 +02:00
|
|
|
* Copyright 2020, Camilo Higuita <milo.h@aol.com>
|
2020-03-25 16:08:12 +01:00
|
|
|
*
|
|
|
|
* Calamares 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 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Calamares 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 Calamares. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef KEYBOARD_CONFIG_H
|
|
|
|
#define KEYBOARD_CONFIG_H
|
|
|
|
|
2020-04-03 10:18:07 +02:00
|
|
|
#include "Job.h"
|
|
|
|
#include "KeyboardLayoutModel.h"
|
|
|
|
|
2020-03-26 15:57:02 +01:00
|
|
|
#include <QAbstractListModel>
|
|
|
|
#include <QMap>
|
2020-03-25 16:08:12 +01:00
|
|
|
#include <QObject>
|
|
|
|
#include <QTimer>
|
2020-03-26 15:57:02 +01:00
|
|
|
#include <QUrl>
|
2020-03-25 16:08:12 +01:00
|
|
|
|
|
|
|
class KeyboardModelsModel : public QAbstractListModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2020-03-26 15:57:02 +01:00
|
|
|
Q_PROPERTY( int currentIndex WRITE setCurrentIndex READ currentIndex NOTIFY currentIndexChanged )
|
2020-03-25 16:08:12 +01:00
|
|
|
|
|
|
|
public:
|
2020-03-26 15:57:02 +01:00
|
|
|
explicit KeyboardModelsModel( QObject* parent = nullptr );
|
|
|
|
int rowCount( const QModelIndex& = QModelIndex() ) const override;
|
|
|
|
QVariant data( const QModelIndex& index, int role ) const override;
|
2020-03-25 16:08:12 +01:00
|
|
|
|
2020-03-26 15:57:02 +01:00
|
|
|
void setCurrentIndex( const int& index );
|
2020-03-25 16:08:12 +01:00
|
|
|
int currentIndex() const;
|
2020-03-26 15:57:02 +01:00
|
|
|
const QMap< QString, QString > item( const int& index ) const;
|
2020-03-25 16:08:12 +01:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void refresh();
|
|
|
|
|
|
|
|
protected:
|
2020-03-26 15:57:02 +01:00
|
|
|
QHash< int, QByteArray > roleNames() const override;
|
2020-03-25 16:08:12 +01:00
|
|
|
|
|
|
|
private:
|
2020-03-26 15:57:02 +01:00
|
|
|
int m_currentIndex = -1;
|
|
|
|
QVector< QMap< QString, QString > > m_list;
|
2020-03-25 16:08:12 +01:00
|
|
|
void detectModels();
|
|
|
|
|
|
|
|
signals:
|
2020-03-26 15:57:02 +01:00
|
|
|
void currentIndexChanged( int index );
|
2020-03-25 16:08:12 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class KeyboardVariantsModel : public QAbstractListModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2020-03-26 15:57:02 +01:00
|
|
|
Q_PROPERTY( int currentIndex WRITE setCurrentIndex READ currentIndex NOTIFY currentIndexChanged )
|
2020-03-25 16:08:12 +01:00
|
|
|
|
|
|
|
public:
|
2020-03-26 15:57:02 +01:00
|
|
|
explicit KeyboardVariantsModel( QObject* parent = nullptr );
|
|
|
|
void setVariants( QMap< QString, QString > variants );
|
2020-03-25 16:08:12 +01:00
|
|
|
|
2020-03-26 15:57:02 +01:00
|
|
|
int rowCount( const QModelIndex& = QModelIndex() ) const override;
|
|
|
|
QVariant data( const QModelIndex& index, int role ) const override;
|
2020-03-25 16:08:12 +01:00
|
|
|
|
2020-03-26 15:57:02 +01:00
|
|
|
void setCurrentIndex( const int& index );
|
2020-03-25 16:08:12 +01:00
|
|
|
int currentIndex() const;
|
|
|
|
|
2020-03-26 15:57:02 +01:00
|
|
|
const QMap< QString, QString > item( const int& index ) const;
|
2020-03-25 16:08:12 +01:00
|
|
|
|
|
|
|
protected:
|
2020-03-26 15:57:02 +01:00
|
|
|
QHash< int, QByteArray > roleNames() const override;
|
2020-03-25 16:08:12 +01:00
|
|
|
|
|
|
|
private:
|
2020-03-26 15:57:02 +01:00
|
|
|
int m_currentIndex = -1;
|
|
|
|
QVector< QMap< QString, QString > > m_list;
|
2020-03-25 16:08:12 +01:00
|
|
|
|
|
|
|
signals:
|
2020-03-26 15:57:02 +01:00
|
|
|
void currentIndexChanged( int index );
|
2020-03-25 16:08:12 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class Config : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2020-03-26 15:57:02 +01:00
|
|
|
Q_PROPERTY( KeyboardModelsModel* keyboardModelsModel READ keyboardModels CONSTANT FINAL )
|
|
|
|
Q_PROPERTY( KeyboardLayoutModel* keyboardLayoutsModel READ keyboardLayouts CONSTANT FINAL )
|
|
|
|
Q_PROPERTY( KeyboardVariantsModel* keyboardVariantsModel READ keyboardVariants CONSTANT FINAL )
|
|
|
|
Q_PROPERTY( QString prettyStatus READ prettyStatus NOTIFY prettyStatusChanged FINAL )
|
2020-03-25 16:08:12 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
Config( QObject* parent = nullptr );
|
|
|
|
|
|
|
|
void init();
|
|
|
|
|
2020-03-26 15:57:02 +01:00
|
|
|
Calamares::JobList
|
|
|
|
createJobs( const QString& xOrgConfFileName, const QString& convertedKeymapPath, bool writeEtcDefaultKeyboard );
|
2020-03-25 16:08:12 +01:00
|
|
|
QString prettyStatus() const;
|
|
|
|
|
|
|
|
void onActivate();
|
|
|
|
void finalize();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void guessLayout( const QStringList& langParts );
|
2020-03-26 15:57:02 +01:00
|
|
|
void updateVariants( const QPersistentModelIndex& currentItem, QString currentVariant = QString() );
|
2020-03-25 16:08:12 +01:00
|
|
|
|
2020-03-26 15:57:02 +01:00
|
|
|
KeyboardModelsModel* m_keyboardModelsModel;
|
|
|
|
KeyboardLayoutModel* m_keyboardLayoutsModel;
|
|
|
|
KeyboardVariantsModel* m_keyboardVariantsModel;
|
2020-03-25 16:08:12 +01:00
|
|
|
|
|
|
|
QString m_selectedLayout;
|
|
|
|
QString m_selectedModel;
|
|
|
|
QString m_selectedVariant;
|
|
|
|
QTimer m_setxkbmapTimer;
|
|
|
|
|
|
|
|
protected:
|
2020-03-26 15:57:02 +01:00
|
|
|
KeyboardModelsModel* keyboardModels() const;
|
|
|
|
KeyboardLayoutModel* keyboardLayouts() const;
|
|
|
|
KeyboardVariantsModel* keyboardVariants() const;
|
2020-03-25 16:08:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void prettyStatusChanged();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|