summaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2019-12-14 16:10:16 -0600
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2019-12-14 16:10:16 -0600
commit3a0c398b72f463d09bc87e598fbb6889000b6232 (patch)
treef291fe89a2004e34b3b4bdaf01e34ea18b7ef620 /ui
parent37d282b7a12c884f8441317c89ee3703bd29210c (diff)
downloadhorizon-3a0c398b72f463d09bc87e598fbb6889000b6232.tar.gz
horizon-3a0c398b72f463d09bc87e598fbb6889000b6232.tar.bz2
horizon-3a0c398b72f463d09bc87e598fbb6889000b6232.tar.xz
horizon-3a0c398b72f463d09bc87e598fbb6889000b6232.zip
Qt UI: Implement user avatar selection
Diffstat (limited to 'ui')
-rw-r--r--ui/qt5/CMakeLists.txt1
-rw-r--r--ui/qt5/avatardialog.cc72
-rw-r--r--ui/qt5/avatardialog.hh30
-rw-r--r--ui/qt5/horizonwizard.cc4
-rw-r--r--ui/qt5/main.cc6
-rw-r--r--ui/qt5/useraccountwidget.cc13
-rw-r--r--ui/qt5/useraccountwidget.hh3
7 files changed, 127 insertions, 2 deletions
diff --git a/ui/qt5/CMakeLists.txt b/ui/qt5/CMakeLists.txt
index b286915..ca3ef67 100644
--- a/ui/qt5/CMakeLists.txt
+++ b/ui/qt5/CMakeLists.txt
@@ -8,6 +8,7 @@ set(UI_SOURCES
main.cc
${CMAKE_SOURCE_DIR}/3rdparty/Section.cpp
useraccountwidget.cc
+ avatardialog.cc
crypt_sha512.c
intropage.cc
diff --git a/ui/qt5/avatardialog.cc b/ui/qt5/avatardialog.cc
new file mode 100644
index 0000000..b7662b9
--- /dev/null
+++ b/ui/qt5/avatardialog.cc
@@ -0,0 +1,72 @@
+/*
+ * avatardialog.cc - Implementation of a dialog for selecting a user's avatar
+ * horizon-qt5, the Qt 5 user interface for
+ * Project Horizon
+ *
+ * Copyright (c) 2019 Adélie Linux and contributors. All rights reserved.
+ * This code is licensed under the AGPL 3.0 license, as noted in the
+ * LICENSE-code file in the root directory of this repository.
+ *
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+#include "avatardialog.hh"
+
+#include <QDirIterator>
+#include <QHBoxLayout>
+#include <QListWidget>
+#include <QPushButton>
+#include <QVBoxLayout>
+
+AvatarDialog::AvatarDialog(QWidget *parent)
+ : QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint) {
+ setWindowTitle(tr("Choose Avatar"));
+
+ aviList = new QListWidget;
+ aviList->setGridSize(QSize(52, 52));
+ aviList->setIconSize(QSize(48, 48));
+ aviList->setViewMode(QListView::IconMode);
+ loadAvatars();
+ connect(aviList, &QListWidget::itemSelectionChanged, [=]{
+ if(aviList->selectedItems().isEmpty()) return;
+ path = aviList->selectedItems()[0]->data(Qt::ToolTipRole).toString();
+ });
+
+ QPushButton *ok = new QPushButton(tr("Choose"));
+ connect(ok, &QPushButton::clicked, this, &QDialog::accept);
+ QPushButton *cancel = new QPushButton(tr("Cancel"));
+ connect(cancel, &QPushButton::clicked, this, &QDialog::reject);
+
+ QVBoxLayout *buttonLayout = new QVBoxLayout;
+ buttonLayout->setAlignment(Qt::AlignTop);
+ buttonLayout->addWidget(ok);
+ buttonLayout->addWidget(cancel);
+
+ QHBoxLayout *mainBox = new QHBoxLayout;
+ mainBox->addWidget(aviList);
+ mainBox->addLayout(buttonLayout);
+
+ setLayout(mainBox);
+}
+
+void AvatarDialog::loadAvatars() {
+ QDirIterator it("/usr/share/user-manager/avatars", {}, QDir::Files, QDirIterator::Subdirectories);
+ while(it.hasNext()) {
+ QString path = it.next();
+ QListWidgetItem *item = new QListWidgetItem(aviList);
+ item->setData(Qt::ToolTipRole, path);
+ item->setIcon(QPixmap(path));
+ }
+}
+
+QString AvatarDialog::avatar() const {
+ return this->path;
+}
+
+void AvatarDialog::setAvatar(QString path) {
+ QList<QListWidgetItem *> items = aviList->findItems(path, Qt::MatchExactly);
+ if(items.size() == 0)
+ aviList->clearSelection();
+ else
+ aviList->setItemSelected(items.at(0), true);
+}
diff --git a/ui/qt5/avatardialog.hh b/ui/qt5/avatardialog.hh
new file mode 100644
index 0000000..040e8f0
--- /dev/null
+++ b/ui/qt5/avatardialog.hh
@@ -0,0 +1,30 @@
+/*
+ * avatardialog.hh - Definition of a dialog for selecting a user's avatar
+ * horizon-qt5, the Qt 5 user interface for
+ * Project Horizon
+ *
+ * Copyright (c) 2019 Adélie Linux and contributors. All rights reserved.
+ * This code is licensed under the AGPL 3.0 license, as noted in the
+ * LICENSE-code file in the root directory of this repository.
+ *
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+#ifndef AVATARDIALOG_HH
+#define AVATARDIALOG_HH
+
+#include <QDialog>
+#include <QListWidget>
+
+class AvatarDialog : public QDialog {
+public:
+ explicit AvatarDialog(QWidget *parent = nullptr);
+ QString avatar(void) const;
+ void setAvatar(QString path);
+private:
+ void loadAvatars();
+ QListWidget *aviList;
+ QString path;
+};
+
+#endif /* !AVATARDIALOG_HH */
diff --git a/ui/qt5/horizonwizard.cc b/ui/qt5/horizonwizard.cc
index 4364f90..2a8c9cc 100644
--- a/ui/qt5/horizonwizard.cc
+++ b/ui/qt5/horizonwizard.cc
@@ -416,6 +416,10 @@ QString HorizonWizard::toHScript() {
lines << ("usergroups " + acctWidget->accountText() + " " +
"users,lp,audio,cdrom,cdrw,video,games");
}
+ if(!acctWidget->avatarPath().isEmpty()) {
+ lines << ("usericon " + acctWidget->accountText() + " " +
+ acctWidget->avatarPath());
+ }
}
return lines.join("\n");
diff --git a/ui/qt5/main.cc b/ui/qt5/main.cc
index fe97b51..7ebe113 100644
--- a/ui/qt5/main.cc
+++ b/ui/qt5/main.cc
@@ -27,10 +27,12 @@ public:
void reject() override;
};
-WaitDialog::WaitDialog(QWidget *parent) : QDialog(parent) {
+WaitDialog::WaitDialog(QWidget *parent) : QDialog(parent,
+ Qt::FramelessWindowHint) {
setWindowTitle(tr("Loading..."));
QVBoxLayout *layout = new QVBoxLayout;
- QLabel *descLabel = new QLabel(tr("System Installation is loading.\n\nPlease wait a moment."));
+ QLabel *descLabel = new QLabel(tr("System Installation is loading.\n\n"
+ "Please wait a moment."));
descLabel->setAlignment(Qt::AlignCenter);
layout->addWidget(descLabel);
setLayout(layout);
diff --git a/ui/qt5/useraccountwidget.cc b/ui/qt5/useraccountwidget.cc
index 9151572..72afc37 100644
--- a/ui/qt5/useraccountwidget.cc
+++ b/ui/qt5/useraccountwidget.cc
@@ -12,6 +12,7 @@
#include "useraccountwidget.hh"
+#include "avatardialog.hh"
#include <QAction>
#include <QHBoxLayout>
#include <QMenu>
@@ -78,6 +79,14 @@ UserAccountWidget::UserAccountWidget(QWidget *parent)
aviButton->setIconSize(QSize(32, 32));
aviButton->setToolTip(tr("Change this user's avatar"));
aviButton->setWhatsThis(tr("Allows you to choose the user's avatar, which will be shown on the log in screen."));
+ connect(aviButton, &QPushButton::clicked, [=]{
+ AvatarDialog *d = new AvatarDialog;
+ if(d->exec() == QDialog::Accepted) {
+ aviPath = d->avatar();
+ aviButton->setIcon(QPixmap(aviPath));
+ }
+ d->deleteLater();
+ });
overallLayout->addWidget(aviButton);
overallLayout->addLayout(detailLayout);
@@ -127,6 +136,10 @@ void UserAccountWidget::setAccountText(QString account) {
accountName->textEdited(account);
}
+QString UserAccountWidget::avatarPath() const {
+ return aviPath;
+}
+
QString UserAccountWidget::passphraseText(void) const {
return passphrase->text();
}
diff --git a/ui/qt5/useraccountwidget.hh b/ui/qt5/useraccountwidget.hh
index 71a23b7..8fc12b4 100644
--- a/ui/qt5/useraccountwidget.hh
+++ b/ui/qt5/useraccountwidget.hh
@@ -28,6 +28,8 @@ public:
QString accountText(void) const;
/*! Sets the current text in the Account Name text entry. */
void setAccountText(QString);
+ /*! Returns the current avatar location (or an empty string). */
+ QString avatarPath(void) const;
/*! Returns the current text in the passphrase entry. */
QString passphraseText(void) const;
/*! Returns the current text in the Personal Name text entry. */
@@ -50,6 +52,7 @@ private:
QLineEdit *passphrase;
QPushButton *aviButton;
QCheckBox *adminTick;
+ QString aviPath;
/*! When set, auto-update of accountName from personalName is prevented. */
bool acctEverTouched;
};