Changeset View
Changeset View
Standalone View
Standalone View
src/usermanager.cpp
Show All 35 Lines | |||||
36 | 36 | | |||
37 | UserManager::UserManager(QWidget* parent, const QVariantList& args) | 37 | UserManager::UserManager(QWidget* parent, const QVariantList& args) | ||
38 | : KCModule(parent, args) | 38 | : KCModule(parent, args) | ||
39 | , m_saveNeeded(false) | 39 | , m_saveNeeded(false) | ||
40 | , m_model(new AccountModel(this)) | 40 | , m_model(new AccountModel(this)) | ||
41 | , m_widget(new AccountInfo(m_model, this)) | 41 | , m_widget(new AccountInfo(m_model, this)) | ||
42 | , m_ui(new Ui::KCMUserManager) | 42 | , m_ui(new Ui::KCMUserManager) | ||
43 | { | 43 | { | ||
44 | Q_UNUSED(args); | 44 | Q_UNUSED(args) | ||
45 | | ||||
46 | // No default button | ||||
47 | setButtons( Apply | Help); | ||||
48 | | ||||
45 | QVBoxLayout *layout = new QVBoxLayout(); | 49 | QVBoxLayout *layout = new QVBoxLayout(); | ||
46 | m_ui->setupUi(this); | 50 | m_ui->setupUi(this); | ||
47 | m_ui->accountInfo->setLayout(layout); | 51 | m_ui->accountInfo->setLayout(layout); | ||
48 | layout->addWidget(m_widget); | 52 | layout->addWidget(m_widget); | ||
49 | 53 | | |||
50 | m_selectionModel = new QItemSelectionModel(m_model); | 54 | m_selectionModel = new QItemSelectionModel(m_model); | ||
51 | connect(m_selectionModel, &QItemSelectionModel::currentChanged, this, &UserManager::currentChanged); | 55 | connect(m_selectionModel, &QItemSelectionModel::currentChanged, this, &UserManager::currentChanged); | ||
52 | m_selectionModel->setCurrentIndex(m_model->index(0), QItemSelectionModel::SelectCurrent); | 56 | m_selectionModel->setCurrentIndex(m_model->index(0), QItemSelectionModel::SelectCurrent); | ||
53 | 57 | | |||
54 | m_ui->userList->setModel(m_model); | 58 | m_ui->userList->setModel(m_model); | ||
55 | m_ui->userList->setSelectionModel(m_selectionModel); | 59 | m_ui->userList->setSelectionModel(m_selectionModel); | ||
56 | const auto iconSize = style()->pixelMetric(QStyle::PM_LargeIconSize); | 60 | const auto iconSize = style()->pixelMetric(QStyle::PM_LargeIconSize); | ||
57 | m_ui->userList->setIconSize(QSize(iconSize, iconSize)); | 61 | m_ui->userList->setIconSize(QSize(iconSize, iconSize)); | ||
58 | 62 | | |||
59 | ModelTest* test = new ModelTest(m_model, nullptr); | 63 | ModelTest* test = new ModelTest(m_model, nullptr); | ||
60 | Q_UNUSED(test) | 64 | Q_UNUSED(test) | ||
61 | 65 | | |||
62 | connect(m_ui->addBtn, &QAbstractButton::clicked, this, &UserManager::addNewUser); | 66 | connect(m_ui->addBtn, &QAbstractButton::clicked, this, &UserManager::addNewUser); | ||
63 | connect(m_ui->removeBtn, &QAbstractButton::clicked, this, &UserManager::removeUser); | 67 | connect(m_ui->removeBtn, &QAbstractButton::clicked, this, &UserManager::removeUser); | ||
64 | connect(m_widget, SIGNAL(changed(bool)), SIGNAL(changed(bool))); | 68 | connect(m_widget, &AccountInfo::changed, this, &KCModule::changed); | ||
65 | connect(m_model, &QAbstractItemModel::dataChanged, this, &UserManager::dataChanged); | 69 | connect(m_model, &QAbstractItemModel::dataChanged, this, &UserManager::dataChanged); | ||
66 | } | 70 | } | ||
67 | 71 | | |||
68 | UserManager::~UserManager() | 72 | UserManager::~UserManager() | ||
69 | { | 73 | { | ||
70 | delete m_model; | 74 | delete m_model; | ||
71 | } | 75 | } | ||
72 | 76 | | |||
73 | void UserManager::load() | 77 | void UserManager::load() | ||
74 | { | 78 | { | ||
75 | m_widget->loadFromModel(); | 79 | m_widget->loadFromModel(); | ||
76 | } | 80 | } | ||
77 | 81 | | |||
78 | void UserManager::save() | 82 | void UserManager::save() | ||
79 | { | 83 | { | ||
80 | m_widget->save(); | 84 | m_widget->save(); | ||
81 | } | 85 | } | ||
82 | 86 | | |||
83 | void UserManager::currentChanged(const QModelIndex& selected, const QModelIndex& previous) | 87 | void UserManager::currentChanged(const QModelIndex& selected, const QModelIndex& previous) | ||
84 | { | 88 | { | ||
85 | Q_UNUSED(previous); | 89 | Q_UNUSED(previous) | ||
86 | m_widget->setModelIndex(selected); | 90 | m_widget->setModelIndex(selected); | ||
87 | bool enabled = false; | 91 | bool enabled = false; | ||
88 | 92 | | |||
89 | //If it is not last and not first | 93 | //If it is not last and not first | ||
90 | if (selected.row() < m_model->rowCount() - 1 && selected.row() > 0) { | 94 | if (selected.row() < m_model->rowCount() - 1 && selected.row() > 0) { | ||
91 | enabled = true; | 95 | enabled = true; | ||
92 | } | 96 | } | ||
93 | 97 | | |||
94 | m_ui->removeBtn->setEnabled(enabled); | 98 | m_ui->removeBtn->setEnabled(enabled); | ||
95 | m_selectionModel->setCurrentIndex(selected, QItemSelectionModel::SelectCurrent); | 99 | m_selectionModel->setCurrentIndex(selected, QItemSelectionModel::SelectCurrent); | ||
96 | } | 100 | } | ||
97 | 101 | | |||
98 | void UserManager::dataChanged(const QModelIndex& topLeft, const QModelIndex& topRight) | 102 | void UserManager::dataChanged(const QModelIndex& topLeft, const QModelIndex& topRight) | ||
99 | { | 103 | { | ||
100 | Q_UNUSED(topRight); | 104 | Q_UNUSED(topRight) | ||
101 | if (m_selectionModel->currentIndex() != topLeft) { | 105 | if (m_selectionModel->currentIndex() != topLeft) { | ||
102 | return; | 106 | return; | ||
103 | } | 107 | } | ||
104 | 108 | | |||
105 | currentChanged(topLeft, topLeft); | 109 | currentChanged(topLeft, topLeft); | ||
106 | } | 110 | } | ||
107 | 111 | | |||
108 | void UserManager::addNewUser() | 112 | void UserManager::addNewUser() | ||
Show All 19 Lines | 118 | { | |||
128 | int result = KMessageBox::questionYesNoCancel(this, warning, i18n("Delete User"), keep, deletefiles); | 132 | int result = KMessageBox::questionYesNoCancel(this, warning, i18n("Delete User"), keep, deletefiles); | ||
129 | if (result == KMessageBox::Cancel) { | 133 | if (result == KMessageBox::Cancel) { | ||
130 | return; | 134 | return; | ||
131 | } | 135 | } | ||
132 | 136 | | |||
133 | bool deleteFiles = result == KMessageBox::Yes ? false : true; | 137 | bool deleteFiles = result == KMessageBox::Yes ? false : true; | ||
134 | m_model->removeAccountKeepingFiles(index.row(), deleteFiles); | 138 | m_model->removeAccountKeepingFiles(index.row(), deleteFiles); | ||
135 | 139 | | |||
136 | Q_EMIT changed(false); | 140 | emit changed(false); | ||
137 | } | 141 | } | ||
138 | 142 | | |||
139 | #include "usermanager.moc" | 143 | #include "usermanager.moc" |