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> | ||
41 | #include <KI18n/klocalizedstring.h> | ||||
42 | 42 | | |||
43 | AccountInfo::AccountInfo(AccountModel* model, QWidget* parent, Qt::WindowFlags f) | 43 | AccountInfo::AccountInfo(AccountModel* model, QWidget* parent, Qt::WindowFlags f) | ||
44 | : QWidget(parent, f) | 44 | : QWidget(parent, f) | ||
45 | , m_info(new Ui::AccountInfo()) | 45 | , m_info(new Ui::AccountInfo()) | ||
46 | , m_model(model) | 46 | , m_model(model) | ||
47 | , m_passwordEdit(new PasswordEdit(this)) | | |||
48 | { | 47 | { | ||
49 | m_info->setupUi(this); | 48 | 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 | 49 | | |||
54 | connect(m_info->username, &QLineEdit::textEdited, this, &AccountInfo::hasChanged); | 50 | connect(m_info->username, &QLineEdit::textEdited, this, &AccountInfo::hasChanged); | ||
55 | connect(m_info->realName, &QLineEdit::textEdited, this, &AccountInfo::hasChanged); | 51 | connect(m_info->realName, &QLineEdit::textEdited, this, &AccountInfo::hasChanged); | ||
56 | connect(m_info->email, &QLineEdit::textEdited, this, &AccountInfo::hasChanged); | 52 | connect(m_info->email, &QLineEdit::textEdited, this, &AccountInfo::hasChanged); | ||
57 | connect(m_info->administrator, &QAbstractButton::clicked, this, &AccountInfo::hasChanged); | 53 | connect(m_info->administrator, &QAbstractButton::clicked, this, &AccountInfo::hasChanged); | ||
58 | connect(m_info->automaticLogin, &QAbstractButton::clicked, this, &AccountInfo::hasChanged); | 54 | connect(m_info->automaticLogin, &QAbstractButton::clicked, this, &AccountInfo::hasChanged); | ||
59 | connect(m_passwordEdit, &PasswordEdit::focused, this, &AccountInfo::changePassword); | 55 | connect(m_info->changePasswordButton, &QPushButton::clicked, this, &AccountInfo::changePassword); | ||
60 | connect(m_passwordEdit, &QLineEdit::textEdited, this, &AccountInfo::changePassword); | | |||
61 | 56 | | |||
62 | connect(m_model, &QAbstractItemModel::dataChanged, this, &AccountInfo::dataChanged); | 57 | connect(m_model, &QAbstractItemModel::dataChanged, this, &AccountInfo::dataChanged); | ||
63 | m_info->face->setPopupMode(QToolButton::InstantPopup); | 58 | m_info->face->setPopupMode(QToolButton::InstantPopup); | ||
64 | QMenu* menu = new QMenu(this); | 59 | QMenu* menu = new QMenu(this); | ||
65 | 60 | | |||
66 | QAction *gallery = new QAction(i18n("Choose from Gallery..."), this); | 61 | QAction *gallery = new QAction(i18n("Choose from Gallery..."), this); | ||
67 | gallery->setIcon(QIcon::fromTheme(QStringLiteral("shape-choose"))); // TODO proper icon | 62 | gallery->setIcon(QIcon::fromTheme(QStringLiteral("shape-choose"))); // TODO proper icon | ||
68 | connect(gallery, &QAction::triggered, this, &AccountInfo::openGallery); | 63 | connect(gallery, &QAction::triggered, this, &AccountInfo::openGallery); | ||
Show All 16 Lines | |||||
85 | m_info->face->setMinimumSize(iconSize); | 80 | m_info->face->setMinimumSize(iconSize); | ||
86 | m_info->face->setMenu(menu); | 81 | m_info->face->setMenu(menu); | ||
87 | 82 | | |||
88 | int size = QFontMetrics(QFontDatabase::systemFont(QFontDatabase::FixedFont)).xHeight() * 29; | 83 | int size = QFontMetrics(QFontDatabase::systemFont(QFontDatabase::FixedFont)).xHeight() * 29; | ||
89 | m_info->username->setMinimumWidth(size); | 84 | m_info->username->setMinimumWidth(size); | ||
90 | m_info->realName->setMinimumWidth(size); | 85 | m_info->realName->setMinimumWidth(size); | ||
91 | m_info->email->setMinimumWidth(size); | 86 | m_info->email->setMinimumWidth(size); | ||
92 | 87 | | |||
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->administrator, &row, &role); | | |||
103 | m_info->formLayout->insertRow(row, m_info->label_3, m_passwordEdit); | | |||
104 | | ||||
105 | int pixmapSize = m_info->username->sizeHint().height(); | 88 | int pixmapSize = m_info->username->sizeHint().height(); | ||
106 | m_negative = QIcon::fromTheme(QStringLiteral("dialog-cancel")).pixmap(pixmapSize, pixmapSize); | 89 | m_negative = QIcon::fromTheme(QStringLiteral("dialog-cancel")).pixmap(pixmapSize, pixmapSize); | ||
107 | } | 90 | } | ||
108 | 91 | | |||
109 | AccountInfo::~AccountInfo() | 92 | AccountInfo::~AccountInfo() | ||
110 | { | 93 | { | ||
111 | delete m_info; | 94 | delete m_info; | ||
112 | } | 95 | } | ||
Show All 14 Lines | 109 | { | |||
127 | return m_index; | 110 | return m_index; | ||
128 | } | 111 | } | ||
129 | 112 | | |||
130 | void AccountInfo::loadFromModel() | 113 | void AccountInfo::loadFromModel() | ||
131 | { | 114 | { | ||
132 | QString username = m_model->data(m_index, AccountModel::Username).toString(); | 115 | QString username = m_model->data(m_index, AccountModel::Username).toString(); | ||
133 | if (!username.isEmpty()) { | 116 | if (!username.isEmpty()) { | ||
134 | m_info->username->setDisabled(true);//Do not allow to change the username | 117 | m_info->username->setDisabled(true);//Do not allow to change the username | ||
118 | m_info->changePasswordButton->setText(i18nc("@label:button", "Change Password")); | ||||
135 | } else { | 119 | } else { | ||
136 | m_info->username->setDisabled(false); | 120 | m_info->username->setDisabled(false); | ||
121 | m_info->changePasswordButton->setText(i18nc("@label:button", "Set Password")); | ||||
137 | } | 122 | } | ||
138 | m_info->username->setText(username); | 123 | m_info->username->setText(username); | ||
139 | 124 | | |||
140 | m_info->face->setIcon(QIcon(m_model->data(m_index, AccountModel::Face).value<QPixmap>())); | 125 | 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()); | 126 | 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()); | 127 | 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()); | 128 | 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()); | 129 | m_info->automaticLogin->setChecked(m_model->data(m_index, AccountModel::AutomaticLogin).toBool()); | ||
145 | m_passwordEdit->clear(); | | |||
146 | } | 130 | } | ||
147 | 131 | | |||
148 | bool AccountInfo::save() | 132 | bool AccountInfo::save() | ||
149 | { | 133 | { | ||
150 | if (m_infoToSave.isEmpty()) { | 134 | if (m_infoToSave.isEmpty()) { | ||
151 | return false; | 135 | return false; | ||
152 | } | 136 | } | ||
153 | 137 | | |||
▲ Show 20 Lines • Show All 153 Lines • ▼ Show 20 Line(s) | 277 | { | |||
307 | char first = userchar.at(0); | 291 | char first = userchar.at(0); | ||
308 | bool valid = (first >= 'a' && first <= 'z'); | 292 | bool valid = (first >= 'a' && first <= 'z'); | ||
309 | 293 | | |||
310 | if (!valid) { | 294 | if (!valid) { | ||
311 | errorTooltip.append(i18n("The username must start with a letter")); | 295 | errorTooltip.append(i18n("The username must start with a letter")); | ||
312 | errorTooltip.append(QStringLiteral("\n")); | 296 | errorTooltip.append(QStringLiteral("\n")); | ||
313 | } | 297 | } | ||
314 | 298 | | |||
315 | Q_FOREACH(const char c, userchar) { | 299 | for (const char c : userchar) { | ||
316 | valid = ( | 300 | valid = ( | ||
317 | (c >= 'a' && c <= 'z') || | 301 | (c >= 'a' && c <= 'z') || | ||
318 | (c >= 'A' && c <= 'Z') || | 302 | (c >= 'A' && c <= 'Z') || | ||
319 | (c >= '0' && c <= '9') || | 303 | (c >= '0' && c <= '9') || | ||
320 | (c == '_') || (c == '.') || | 304 | (c == '_') || (c == '.') || | ||
321 | (c == '-') | 305 | (c == '-') | ||
322 | ); | 306 | ); | ||
323 | if (!valid) { | 307 | if (!valid) { | ||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Line(s) | 386 | { | |||
409 | m_info->face->setIcon(QIcon(path)); | 393 | m_info->face->setIcon(QIcon(path)); | ||
410 | m_infoToSave.insert(AccountModel::Face, path); | 394 | m_infoToSave.insert(AccountModel::Face, path); | ||
411 | Q_EMIT changed(true); | 395 | Q_EMIT changed(true); | ||
412 | } | 396 | } | ||
413 | 397 | | |||
414 | QStringList AccountInfo::imageFormats() const | 398 | QStringList AccountInfo::imageFormats() const | ||
415 | { | 399 | { | ||
416 | QStringList result; | 400 | QStringList result; | ||
417 | for(const QByteArray &b: QImageReader::supportedMimeTypes()) { | 401 | const QList<QByteArray> supportedMimes = QImageReader::supportedMimeTypes(); | ||
402 | for (const QByteArray &b: supportedMimes) { | ||||
418 | if (! b.isEmpty()) | 403 | if (! b.isEmpty()) | ||
419 | result.append(QString::fromLatin1(b)); | 404 | result.append(QString::fromLatin1(b)); | ||
420 | } | 405 | } | ||
421 | return result; | 406 | return result; | ||
422 | } | 407 | } | ||
423 | 408 | | |||
424 | void AccountInfo::openAvatarSlot() | 409 | void AccountInfo::openAvatarSlot() | ||
425 | { | 410 | { | ||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | 459 | { | |||
475 | QScopedPointer<PasswordDialog> dialog(new PasswordDialog(this)); | 460 | QScopedPointer<PasswordDialog> dialog(new PasswordDialog(this)); | ||
476 | dialog->setUsername(m_model->data(m_index, AccountModel::Username).toByteArray()); | 461 | dialog->setUsername(m_model->data(m_index, AccountModel::Username).toByteArray()); | ||
477 | dialog->setModal(true); | 462 | dialog->setModal(true); | ||
478 | if (!dialog->exec()) { | 463 | if (!dialog->exec()) { | ||
479 | return; | 464 | return; | ||
480 | } | 465 | } | ||
481 | 466 | | |||
482 | m_infoToSave[AccountModel::Password] = dialog->password(); | 467 | m_infoToSave[AccountModel::Password] = dialog->password(); | ||
483 | m_passwordEdit->setText(dialog->password()); | | |||
484 | Q_EMIT changed(true); | 468 | Q_EMIT changed(true); | ||
485 | } | 469 | } |