Changeset View
Changeset View
Standalone View
Standalone View
src/accountinfo.cpp
Show All 15 Lines | |||||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * | 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * | ||
17 | *************************************************************************************/ | 17 | *************************************************************************************/ | ||
18 | 18 | | |||
19 | #include "accountinfo.h" | 19 | #include "accountinfo.h" | ||
20 | #include "ui_account.h" | 20 | #include "ui_account.h" | ||
21 | #include "createavatarjob.h" | 21 | #include "createavatarjob.h" | ||
22 | #include "passworddialog.h" | 22 | #include "passworddialog.h" | ||
23 | #include "lib/accountmodel.h" | 23 | #include "lib/accountmodel.h" | ||
24 | #include "passwordedit.h" | | |||
25 | #include "avatargallery.h" | 24 | #include "avatargallery.h" | ||
26 | 25 | | |||
27 | #include <pwd.h> | 26 | #include <pwd.h> | ||
28 | #include <unistd.h> | 27 | #include <unistd.h> | ||
29 | 28 | | |||
30 | #include <QMenu> | 29 | #include <QMenu> | ||
31 | #include <QToolButton> | 30 | #include <QToolButton> | ||
32 | #include <QStandardPaths> | 31 | #include <QStandardPaths> | ||
33 | #include <QImageReader> | 32 | #include <QImageReader> | ||
34 | #include <QFontDatabase> | 33 | #include <QFontDatabase> | ||
35 | #include <QFileDialog> | 34 | #include <QFileDialog> | ||
36 | 35 | | |||
37 | #include "user_manager_debug.h" | 36 | #include "user_manager_debug.h" | ||
38 | #include <KJob> | 37 | #include <KJob> | ||
39 | #include <KIO/CopyJob> | 38 | #include <KIO/CopyJob> | ||
40 | #include <KIconLoader> | 39 | #include <KIconLoader> | ||
41 | #include <KUser> | 40 | #include <KUser> | ||
42 | 41 | | |||
43 | AccountInfo::AccountInfo(AccountModel* model, QWidget* parent, Qt::WindowFlags f) | 42 | AccountInfo::AccountInfo(AccountModel* model, QWidget* parent, Qt::WindowFlags f) | ||
44 | : QWidget(parent, f) | 43 | : QWidget(parent, f) | ||
45 | , m_info(new Ui::AccountInfo()) | 44 | , m_info(new Ui::AccountInfo()) | ||
46 | , m_model(model) | 45 | , m_model(model) | ||
47 | , m_passwordEdit(new PasswordEdit(this)) | | |||
48 | { | 46 | { | ||
49 | m_info->setupUi(this); | 47 | m_info->setupUi(this); | ||
50 | //If I remove this from the .ui file the layouting gets screwed... | | |||
51 | m_info->formLayout->removeWidget(m_info->passwordEdit); | | |||
52 | delete m_info->passwordEdit; | | |||
53 | 48 | | |||
54 | connect(m_info->username, &QLineEdit::textEdited, this, &AccountInfo::hasChanged); | 49 | connect(m_info->username, &QLineEdit::textEdited, this, &AccountInfo::hasChanged); | ||
55 | connect(m_info->realName, &QLineEdit::textEdited, this, &AccountInfo::hasChanged); | 50 | connect(m_info->realName, &QLineEdit::textEdited, this, &AccountInfo::hasChanged); | ||
56 | connect(m_info->email, &QLineEdit::textEdited, this, &AccountInfo::hasChanged); | 51 | connect(m_info->email, &QLineEdit::textEdited, this, &AccountInfo::hasChanged); | ||
57 | connect(m_info->administrator, &QAbstractButton::clicked, this, &AccountInfo::hasChanged); | 52 | connect(m_info->administrator, &QAbstractButton::clicked, this, &AccountInfo::hasChanged); | ||
58 | connect(m_info->automaticLogin, &QAbstractButton::clicked, this, &AccountInfo::hasChanged); | 53 | connect(m_info->automaticLogin, &QAbstractButton::clicked, this, &AccountInfo::hasChanged); | ||
59 | connect(m_passwordEdit, &PasswordEdit::focused, this, &AccountInfo::changePassword); | 54 | connect(m_info->changePasswordButton, &QPushButton::clicked, this, &AccountInfo::changePassword); | ||
60 | connect(m_passwordEdit, &QLineEdit::textEdited, this, &AccountInfo::changePassword); | | |||
61 | 55 | | |||
62 | connect(m_model, &QAbstractItemModel::dataChanged, this, &AccountInfo::dataChanged); | 56 | connect(m_model, &QAbstractItemModel::dataChanged, this, &AccountInfo::dataChanged); | ||
63 | m_info->face->setPopupMode(QToolButton::InstantPopup); | 57 | m_info->face->setPopupMode(QToolButton::InstantPopup); | ||
64 | QMenu* menu = new QMenu(this); | 58 | QMenu* menu = new QMenu(this); | ||
65 | 59 | | |||
66 | QAction *gallery = new QAction(i18n("Choose from Gallery..."), this); | 60 | QAction *gallery = new QAction(i18n("Choose from Gallery..."), this); | ||
67 | gallery->setIcon(QIcon::fromTheme(QStringLiteral("shape-choose"))); // TODO proper icon | 61 | gallery->setIcon(QIcon::fromTheme(QStringLiteral("shape-choose"))); // TODO proper icon | ||
68 | connect(gallery, &QAction::triggered, this, &AccountInfo::openGallery); | 62 | connect(gallery, &QAction::triggered, this, &AccountInfo::openGallery); | ||
Show All 16 Lines | |||||
85 | m_info->face->setMinimumSize(iconSize); | 79 | m_info->face->setMinimumSize(iconSize); | ||
86 | m_info->face->setMenu(menu); | 80 | m_info->face->setMenu(menu); | ||
87 | 81 | | |||
88 | int size = QFontMetrics(QFontDatabase::systemFont(QFontDatabase::FixedFont)).xHeight() * 29; | 82 | int size = QFontMetrics(QFontDatabase::systemFont(QFontDatabase::FixedFont)).xHeight() * 29; | ||
89 | m_info->username->setMinimumWidth(size); | 83 | m_info->username->setMinimumWidth(size); | ||
90 | m_info->realName->setMinimumWidth(size); | 84 | m_info->realName->setMinimumWidth(size); | ||
91 | m_info->email->setMinimumWidth(size); | 85 | m_info->email->setMinimumWidth(size); | ||
92 | 86 | | |||
93 | QWidget::setTabOrder(m_info->email, m_passwordEdit); | | |||
94 | QWidget::setTabOrder(m_passwordEdit, m_info->administrator); | | |||
95 | | ||||
96 | m_passwordEdit->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); | | |||
97 | m_passwordEdit->setMinimumWidth(size); | | |||
98 | m_passwordEdit->setEchoMode(QLineEdit::Password); | | |||
99 | | ||||
100 | int row; | | |||
101 | QFormLayout::ItemRole role; | | |||
102 | m_info->formLayout->getWidgetPosition(m_info->label_2, &row, &role); | | |||
103 | m_info->formLayout->insertRow(row, m_info->label_3, m_passwordEdit); | | |||
104 | | ||||
105 | int pixmapSize = m_info->username->sizeHint().height(); | 87 | int pixmapSize = m_info->username->sizeHint().height(); | ||
106 | m_negative = QIcon::fromTheme(QStringLiteral("dialog-cancel")).pixmap(pixmapSize, pixmapSize); | 88 | m_negative = QIcon::fromTheme(QStringLiteral("dialog-cancel")).pixmap(pixmapSize, pixmapSize); | ||
107 | } | 89 | } | ||
108 | 90 | | |||
109 | AccountInfo::~AccountInfo() | 91 | AccountInfo::~AccountInfo() | ||
110 | { | 92 | { | ||
111 | delete m_info; | 93 | delete m_info; | ||
112 | } | 94 | } | ||
Show All 24 Lines | 113 | { | |||
137 | } | 119 | } | ||
138 | m_info->username->setText(username); | 120 | m_info->username->setText(username); | ||
139 | 121 | | |||
140 | m_info->face->setIcon(QIcon(m_model->data(m_index, AccountModel::Face).value<QPixmap>())); | 122 | m_info->face->setIcon(QIcon(m_model->data(m_index, AccountModel::Face).value<QPixmap>())); | ||
141 | m_info->realName->setText(m_model->data(m_index, AccountModel::RealName).toString()); | 123 | m_info->realName->setText(m_model->data(m_index, AccountModel::RealName).toString()); | ||
142 | m_info->email->setText(m_model->data(m_index, AccountModel::Email).toString()); | 124 | m_info->email->setText(m_model->data(m_index, AccountModel::Email).toString()); | ||
143 | m_info->administrator->setChecked(m_model->data(m_index, AccountModel::Administrator).toBool()); | 125 | m_info->administrator->setChecked(m_model->data(m_index, AccountModel::Administrator).toBool()); | ||
144 | m_info->automaticLogin->setChecked(m_model->data(m_index, AccountModel::AutomaticLogin).toBool()); | 126 | m_info->automaticLogin->setChecked(m_model->data(m_index, AccountModel::AutomaticLogin).toBool()); | ||
145 | m_passwordEdit->clear(); | | |||
146 | } | 127 | } | ||
147 | 128 | | |||
148 | bool AccountInfo::save() | 129 | bool AccountInfo::save() | ||
149 | { | 130 | { | ||
150 | if (m_infoToSave.isEmpty()) { | 131 | if (m_infoToSave.isEmpty()) { | ||
151 | return false; | 132 | return false; | ||
152 | } | 133 | } | ||
153 | 134 | | |||
▲ Show 20 Lines • Show All 153 Lines • ▼ Show 20 Line(s) | 274 | { | |||
307 | char first = userchar.at(0); | 288 | char first = userchar.at(0); | ||
308 | bool valid = (first >= 'a' && first <= 'z'); | 289 | bool valid = (first >= 'a' && first <= 'z'); | ||
309 | 290 | | |||
310 | if (!valid) { | 291 | if (!valid) { | ||
311 | errorTooltip.append(i18n("The username must start with a letter")); | 292 | errorTooltip.append(i18n("The username must start with a letter")); | ||
312 | errorTooltip.append(QStringLiteral("\n")); | 293 | errorTooltip.append(QStringLiteral("\n")); | ||
313 | } | 294 | } | ||
314 | 295 | | |||
315 | Q_FOREACH(const char c, userchar) { | 296 | for (const char c : userchar) { | ||
316 | valid = ( | 297 | valid = ( | ||
317 | (c >= 'a' && c <= 'z') || | 298 | (c >= 'a' && c <= 'z') || | ||
318 | (c >= 'A' && c <= 'Z') || | 299 | (c >= 'A' && c <= 'Z') || | ||
319 | (c >= '0' && c <= '9') || | 300 | (c >= '0' && c <= '9') || | ||
320 | (c == '_') || (c == '.') || | 301 | (c == '_') || (c == '.') || | ||
321 | (c == '-') | 302 | (c == '-') | ||
322 | ); | 303 | ); | ||
323 | if (!valid) { | 304 | if (!valid) { | ||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Line(s) | 383 | { | |||
409 | m_info->face->setIcon(QIcon(path)); | 390 | m_info->face->setIcon(QIcon(path)); | ||
410 | m_infoToSave.insert(AccountModel::Face, path); | 391 | m_infoToSave.insert(AccountModel::Face, path); | ||
411 | Q_EMIT changed(true); | 392 | Q_EMIT changed(true); | ||
412 | } | 393 | } | ||
413 | 394 | | |||
414 | QStringList AccountInfo::imageFormats() const | 395 | QStringList AccountInfo::imageFormats() const | ||
415 | { | 396 | { | ||
416 | QStringList result; | 397 | QStringList result; | ||
417 | for(const QByteArray &b: QImageReader::supportedMimeTypes()) { | 398 | const QList<QByteArray> supportedMimes = QImageReader::supportedMimeTypes(); | ||
399 | for (const QByteArray &b: supportedMimes) { | ||||
418 | if (! b.isEmpty()) | 400 | if (! b.isEmpty()) | ||
419 | result.append(QString::fromLatin1(b)); | 401 | result.append(QString::fromLatin1(b)); | ||
420 | } | 402 | } | ||
421 | return result; | 403 | return result; | ||
422 | } | 404 | } | ||
423 | 405 | | |||
424 | void AccountInfo::openAvatarSlot() | 406 | void AccountInfo::openAvatarSlot() | ||
425 | { | 407 | { | ||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | 456 | { | |||
475 | QScopedPointer<PasswordDialog> dialog(new PasswordDialog(this)); | 457 | QScopedPointer<PasswordDialog> dialog(new PasswordDialog(this)); | ||
476 | dialog->setUsername(m_model->data(m_index, AccountModel::Username).toByteArray()); | 458 | dialog->setUsername(m_model->data(m_index, AccountModel::Username).toByteArray()); | ||
477 | dialog->setModal(true); | 459 | dialog->setModal(true); | ||
478 | if (!dialog->exec()) { | 460 | if (!dialog->exec()) { | ||
479 | return; | 461 | return; | ||
480 | } | 462 | } | ||
481 | 463 | | |||
482 | m_infoToSave[AccountModel::Password] = dialog->password(); | 464 | m_infoToSave[AccountModel::Password] = dialog->password(); | ||
483 | m_passwordEdit->setText(dialog->password()); | | |||
484 | Q_EMIT changed(true); | 465 | Q_EMIT changed(true); | ||
485 | } | 466 | } |