diff --git a/src/modules/users/CMakeLists.txt b/src/modules/users/CMakeLists.txt new file mode 100644 index 000000000..7930d25d2 --- /dev/null +++ b/src/modules/users/CMakeLists.txt @@ -0,0 +1,15 @@ +include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui ) +calamares_add_plugin( users + TYPE viewmodule + EXPORT_MACRO PLUGINDLLEXPORT_PRO + CONFIG_FILE module.conf + SOURCES +# CreateUserJob.cpp + UsersViewStep.cpp + UsersPage.cpp + UI + page_usersetup.ui + LINK_LIBRARIES + calamaresui + SHARED_LIB +) diff --git a/src/modules/users/UsersPage.cpp b/src/modules/users/UsersPage.cpp new file mode 100644 index 000000000..7daa84024 --- /dev/null +++ b/src/modules/users/UsersPage.cpp @@ -0,0 +1,207 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Teo Mrnjavac + * + * Portions from the Manjaro Installation Framework + * by Roland Singer + * Copyright (C) 2007 Free Software Foundation, Inc. + * + * 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 . + */ + +#include "UsersPage.h" +#include "ui_page_usersetup.h" + +#include +#include +#include +#include +#include + + + +UsersPage::UsersPage( QWidget* parent ) + : QWidget( parent ) + , ui( new Ui::Page_UserSetup ) + , m_readyUsername( false ) + , m_readyHostname( false ) + , m_readyPassword( false ) + , m_readyRootPassword( false ) +{ + ui->setupUi( this ); + + // Connect signals and slots + connect( ui->textBoxUsername, &QLineEdit::textChanged, + this, &UsersPage::onUsernameTextChanged ); + connect( ui->textBoxHostname, &QLineEdit::textChanged, + this, &UsersPage::onHostnameTextChanged ); + connect( ui->textBoxUserPassword, &QLineEdit::textChanged, + this, &UsersPage::onPasswordTextChanged ); + connect( ui->textBoxUserVerifiedPassword, &QLineEdit::textChanged, + this, &UsersPage::onPasswordTextChanged ); + connect( ui->textBoxRootPassword, &QLineEdit::textChanged, + this, &UsersPage::onRootPasswordTextChanged ); + connect( ui->textBoxVerifiedRootPassword, &QLineEdit::textChanged, + this, &UsersPage::onRootPasswordTextChanged ); +} + + +UsersPage::~UsersPage() +{ + delete ui; +} + + +bool +UsersPage::isReady() +{ + return m_readyHostname && m_readyPassword && m_readyRootPassword && m_readyUsername; +} + + +void +UsersPage::onUsernameTextChanged( const QString& textRef ) +{ + QString text = textRef; + QRegExp rx( "^[a-z][-a-z0-9_]*\\$" ); + QRegExpValidator val( rx ); + int pos = -1; + + if ( text.isEmpty() ) + { + ui->labelUsernameError->clear(); + ui->labelUsername->clear(); + m_readyUsername = false; + } + else if ( val.validate( text, pos ) == QValidator::Invalid ) + { + ui->labelUsername->setPixmap( QPixmap( ":/images/invalid.png" ) ); + --pos; + + if ( pos >= 0 && pos < text.size() ) + ui->labelUsernameError->setText( + tr( "Your username contains an invalid character '%1'" ) + .arg( text.at( pos ) ) ); + else + ui->labelUsernameError->setText( + tr( "Your username contains invalid characters!" ) ); + + m_readyUsername = false; + } + else { + ui->labelUsername->setPixmap( QPixmap( ":/images/valid.png" ) ); + ui->labelUsernameError->clear(); + m_readyUsername = true; + } + + emit checkReady( isReady() ); +} + + +void +UsersPage::onHostnameTextChanged( const QString& textRef ) +{ + QString text = textRef; + QRegExp rx( "^[a-zA-Z][-a-zA-Z0-9_]*\\$" ); + QRegExpValidator val( rx ); + int pos = -1; + + if ( text.isEmpty() ) + { + ui->labelHostnameError->clear(); + ui->labelHostname->clear(); + m_readyHostname= false; + } + else if ( val.validate( text, pos ) == QValidator::Invalid ) + { + ui->labelHostname->setPixmap( QPixmap( ":/images/invalid.png" ) ); + --pos; + + if ( pos >= 0 && pos < text.size() ) + ui->labelHostnameError->setText( + tr( "Your username contains an invalid character '%1'" ) + .arg( text.at( pos ) ) ); + else + ui->labelHostnameError->setText( + tr( "Your username contains invalid characters!" ) ); + + m_readyHostname = false; + } + else + { + ui->labelHostname->setPixmap( QPixmap( ":/images/valid.png" ) ); + ui->labelHostnameError->clear(); + m_readyHostname = true; + } + + emit checkReady( isReady() ); +} + + +void +UsersPage::onPasswordTextChanged( const QString& ) +{ + QString pw1 = ui->textBoxUserPassword->text(); + QString pw2 = ui->textBoxUserVerifiedPassword->text(); + + if ( pw1.isEmpty() && pw2.isEmpty() ) + { + ui->labelUserPasswordError->clear(); + ui->labelUserPassword->clear(); + m_readyPassword = false; + } + else if ( pw1 != pw2 ) + { + ui->labelUserPasswordError->setText( tr( "Your passwords do not match!" ) ); + ui->labelUserPassword->setPixmap( QPixmap( ":/images/invalid.png" ) ); + m_readyPassword = false; + } + else + { + ui->labelUserPasswordError->clear(); + ui->labelUserPassword->setPixmap( QPixmap( ":/images/valid.png" ) ); + m_readyPassword = true; + } + + emit checkReady( isReady() ); +} + + +void +UsersPage::onRootPasswordTextChanged( const QString& ) +{ + QString pw1 = ui->textBoxRootPassword->text(); + QString pw2 = ui->textBoxVerifiedRootPassword->text(); + + if ( pw1.isEmpty() && pw2.isEmpty() ) + { + ui->labelRootPasswordError->clear(); + ui->labelRootPassword->clear(); + m_readyRootPassword = false; + } + else if ( pw1 != pw2 ) + { + ui->labelRootPasswordError->setText( tr( "Your passwords do not match!" ) ); + ui->labelRootPassword->setPixmap( QPixmap( ":/images/invalid.png" ) ); + m_readyRootPassword = false; + } + else + { + ui->labelRootPasswordError->clear(); + ui->labelRootPassword->setPixmap( QPixmap( ":/images/valid.png" ) ); + m_readyRootPassword = true; + } + + emit checkReady( isReady() ); +} diff --git a/src/modules/users/UsersPage.h b/src/modules/users/UsersPage.h new file mode 100644 index 000000000..bce927015 --- /dev/null +++ b/src/modules/users/UsersPage.h @@ -0,0 +1,59 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Teo Mrnjavac + * + * Portions from the Manjaro Installation Framework + * by Roland Singer + * Copyright (C) 2007 Free Software Foundation, Inc. + * + * 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 . + */ + +#ifndef USERSPAGE_H +#define USERSPAGE_H + +#include + +namespace Ui { +class Page_UserSetup; +} + +class UsersPage : public QWidget +{ + Q_OBJECT +public: + explicit UsersPage( QWidget* parent = nullptr ); + virtual ~UsersPage(); + + bool isReady(); + +protected slots: + void onUsernameTextChanged( const QString& ); + void onHostnameTextChanged( const QString& ); + void onPasswordTextChanged( const QString& ); + void onRootPasswordTextChanged( const QString& ); + +signals: + void checkReady( bool ); + +private: + Ui::Page_UserSetup* ui; + bool m_readyUsername; + bool m_readyHostname; + bool m_readyPassword; + bool m_readyRootPassword; + +}; + +#endif // USERSPAGE_H diff --git a/src/modules/users/UsersViewStep.cpp b/src/modules/users/UsersViewStep.cpp new file mode 100644 index 000000000..c4a0ec574 --- /dev/null +++ b/src/modules/users/UsersViewStep.cpp @@ -0,0 +1,92 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Teo Mrnjavac + * + * 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 . + */ + +#include "UsersViewStep.h" + +#include "UsersPage.h" + +UsersViewStep::UsersViewStep( QObject* parent ) + : Calamares::ViewStep( parent ) + , m_widget( new UsersPage() ) +{ + emit nextStatusChanged( true ); + connect( m_widget, &UsersPage::checkReady, + this, &UsersViewStep::nextStatusChanged ); +} + + +UsersViewStep::~UsersViewStep() +{ + if ( m_widget && m_widget->parent() == nullptr ) + m_widget->deleteLater(); +} + + +QString +UsersViewStep::prettyName() const +{ + return tr( "Users" ); +} + + +QWidget* +UsersViewStep::widget() +{ + return m_widget; +} + + +void +UsersViewStep::next() +{ + emit done(); +} + + +void +UsersViewStep::back() +{} + + +bool +UsersViewStep::isNextEnabled() const +{ + return m_widget->isReady(); +} + + +bool +UsersViewStep::isAtBeginning() const +{ + return true; +} + + +bool +UsersViewStep::isAtEnd() const +{ + return true; +} + + +QList< Calamares::job_ptr > +UsersViewStep::jobs() const +{ + return QList< Calamares::job_ptr >(); +} + diff --git a/src/modules/users/UsersViewStep.h b/src/modules/users/UsersViewStep.h new file mode 100644 index 000000000..28a9f2853 --- /dev/null +++ b/src/modules/users/UsersViewStep.h @@ -0,0 +1,58 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Teo Mrnjavac + * + * 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 . + */ + +#ifndef USERSPAGEPLUGIN_H +#define USERSPAGEPLUGIN_H + +#include + +#include "viewpages/ViewStep.h" +#include "PluginDllMacro.h" + +class UsersPage; + +class PLUGINDLLEXPORT UsersViewStep : public Calamares::ViewStep +{ + Q_OBJECT + Q_PLUGIN_METADATA( IID "calamares.ViewModule/1.0" ) + + Q_INTERFACES( Calamares::ViewStep ) + +public: + explicit UsersViewStep( QObject* parent = nullptr ); + virtual ~UsersViewStep(); + + QString prettyName() const override; + + QWidget* widget() override; + + void next() override; + void back() override; + + bool isNextEnabled() const override; + + bool isAtBeginning() const override; + bool isAtEnd() const override; + + QList< Calamares::job_ptr > jobs() const override; + +private: + UsersPage* m_widget; +}; + +#endif // USERSPAGEPLUGIN_H diff --git a/src/modules/users/images/invalid.png b/src/modules/users/images/invalid.png new file mode 100644 index 000000000..2cb032501 Binary files /dev/null and b/src/modules/users/images/invalid.png differ diff --git a/src/modules/users/images/valid.png b/src/modules/users/images/valid.png new file mode 100644 index 000000000..3ccfc5596 Binary files /dev/null and b/src/modules/users/images/valid.png differ diff --git a/src/modules/users/module.conf b/src/modules/users/module.conf new file mode 100644 index 000000000..d20511811 --- /dev/null +++ b/src/modules/users/module.conf @@ -0,0 +1,10 @@ +# Module metadata file for users viewmodule +# Syntax is YAML 1.2 +--- +type: "view" #core or view +name: "users" #the module name. must be unique and same as the parent directory +interface: "qtplugin" #can be: qtplugin, python, process, ... +requires: [] #list of module names that must also be loaded. only applies to + #binary plugins! these are actual link-time dependencies, not + #conceptual dependencies for the setup procedure +load: "libcalamares_viewmodule_users.so" diff --git a/src/modules/users/page_usersetup.ui b/src/modules/users/page_usersetup.ui new file mode 100644 index 000000000..dc4f1a266 --- /dev/null +++ b/src/modules/users/page_usersetup.ui @@ -0,0 +1,603 @@ + + + Page_UserSetup + + + + 0 + 0 + 866 + 601 + + + + Form + + + + + + + + What name do you want to use to log in? + + + false + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 200 + 0 + + + + + + + + font-weight: normal + + + <small>If more than one person will use this computer, you can set up multiple accounts after installation.</small> + + + true + + + + + + + + 0 + 0 + + + + + 24 + 24 + + + + + 24 + 24 + + + + true + + + + + + + + 1 + 0 + + + + + 200 + 0 + + + + + + + Qt::AlignVCenter + + + true + + + + + + + + + Qt::Horizontal + + + + + + + + + + + Choose a password to keep your account safe. + + + false + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + font-weight: normal + + + <small>Enter the same password twice, so that it can be checked for typing errors.</small> + + + true + + + + + + + + 0 + 0 + + + + + 24 + 24 + + + + + 24 + 24 + + + + true + + + + + + + + 1 + 0 + + + + + 100 + 0 + + + + + + + Qt::AlignVCenter + + + true + + + + + + + + 0 + 0 + + + + + 200 + 0 + + + + QLineEdit::Password + + + + + + + + 0 + 0 + + + + + 200 + 0 + + + + QLineEdit::Password + + + + + + + + + Qt::Horizontal + + + + + + + + + + + What is the name of this computer? + + + false + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 200 + 0 + + + + + + + + font-weight: normal + + + <small>This name will be used if you make the computer visible to others on a network.</small> + + + false + + + + + + + + 0 + 0 + + + + + 24 + 24 + + + + + 24 + 24 + + + + true + + + + + + + + 1 + 0 + + + + + 200 + 0 + + + + + + + Qt::AlignVCenter + + + true + + + + + + + + + Qt::Horizontal + + + + + + + + + + + Choose a root password. + + + false + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + font-weight: normal + + + <small>Enter the same password twice, so that it can be checked for typing errors.</small> + + + true + + + + + + + + 0 + 0 + + + + + 24 + 24 + + + + + 24 + 24 + + + + true + + + + + + + + 1 + 0 + + + + + 100 + 0 + + + + + + + Qt::AlignVCenter + + + true + + + + + + + + 0 + 0 + + + + + 200 + 0 + + + + QLineEdit::Password + + + + + + + + 0 + 0 + + + + + 200 + 0 + + + + QLineEdit::Password + + + + + + + + + Qt::Horizontal + + + + + + + + + + + Login Options: + + + false + + + + + + + + 2 + + + 2 + + + 2 + + + 2 + + + + + Log in automatically + + + false + + + + + + + Require my password to log in + + + true + + + + + + + + + + + + textBoxUsername + textBoxUserPassword + textBoxUserVerifiedPassword + textBoxHostname + textBoxRootPassword + textBoxVerifiedRootPassword + checkBoxLoginNormal + checkBoxLoginAuto + + + + diff --git a/src/modules/users/resources.qrc b/src/modules/users/resources.qrc new file mode 100644 index 000000000..70392c32b --- /dev/null +++ b/src/modules/users/resources.qrc @@ -0,0 +1,6 @@ + + + images/invalid.png + images/valid.png + +