-rw-r--r-- | noncore/settings/usermanager/userdialog.cpp | 32 | ||||
-rw-r--r-- | noncore/settings/usermanager/userdialog.h | 3 | ||||
-rw-r--r-- | noncore/settings/usermanager/usermanager.cpp | 8 | ||||
-rw-r--r-- | noncore/settings/usermanager/usermanager.h | 9 |
4 files changed, 42 insertions, 10 deletions
diff --git a/noncore/settings/usermanager/userdialog.cpp b/noncore/settings/usermanager/userdialog.cpp index b7827a4..90e27d5 100644 --- a/noncore/settings/usermanager/userdialog.cpp +++ b/noncore/settings/usermanager/userdialog.cpp | |||
@@ -1,359 +1,379 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * This program is free software; you can redistribute it and/or modify * | 3 | * This program is free software; you can redistribute it and/or modify * |
4 | * it under the terms of the GNU General Public License as published by * | 4 | * it under the terms of the GNU General Public License as published by * |
5 | * the Free Software Foundation; either version 2 of the License, or * | 5 | * the Free Software Foundation; either version 2 of the License, or * |
6 | * (at your option) any later version. * | 6 | * (at your option) any later version. * |
7 | * * | 7 | * * |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | 9 | ||
10 | #include "userdialog.h" | 10 | #include "userdialog.h" |
11 | 11 | ||
12 | #include <qlayout.h> | 12 | #include <qlayout.h> |
13 | #include <qlabel.h> | 13 | #include <qlabel.h> |
14 | #include <qmessagebox.h> | 14 | #include <qmessagebox.h> |
15 | 15 | ||
16 | #include <stdlib.h> | 16 | #include <stdlib.h> |
17 | 17 | ||
18 | #include <stdio.h> | 18 | #include <stdio.h> |
19 | #include <sys/types.h> | 19 | #include <sys/types.h> |
20 | #include <sys/wait.h> | 20 | #include <sys/wait.h> |
21 | #include <unistd.h> | 21 | #include <unistd.h> |
22 | #include <signal.h> | 22 | #include <signal.h> |
23 | 23 | ||
24 | #include "passwd.h" | 24 | #include "passwd.h" |
25 | 25 | ||
26 | /** | 26 | /** |
27 | * UserDialog constructor. Setup the dialog, fill the groupComboBox & groupsListView with all groups. | 27 | * UserDialog constructor. Setup the dialog, fill the groupComboBox & groupsListView with all groups. |
28 | * | 28 | * |
29 | */ | 29 | */ |
30 | UserDialog::UserDialog(QWidget* parent, const char* name, bool modal, WFlags fl) : QDialog(parent, name, modal, fl) { | 30 | UserDialog::UserDialog(QWidget* parent, const char* name, bool modal, WFlags fl) : QDialog(parent, name, modal, fl) { |
31 | QVBoxLayout *layout = new QVBoxLayout(this); | 31 | QVBoxLayout *layout = new QVBoxLayout(this); |
32 | myTabWidget=new QTabWidget(this,"User Tab Widget"); | 32 | myTabWidget=new QTabWidget(this,"User Tab Widget"); |
33 | layout->addWidget(myTabWidget); | 33 | layout->addWidget(myTabWidget); |
34 | setupTab1(); | 34 | setupTab1(); |
35 | setupTab2(); | 35 | setupTab2(); |
36 | 36 | ||
37 | accounts->groupStringList.sort(); | ||
37 | // And also fill the listview & the combobox with all available groups. | 38 | // And also fill the listview & the combobox with all available groups. |
38 | for( QStringList::Iterator it = accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) { | 39 | for( QStringList::Iterator it = accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) { |
39 | accounts->splitGroupEntry(*it); | 40 | accounts->splitGroupEntry(*it); |
40 | //new QListViewItem(groupsListView,accounts->gr_name); | ||
41 | new QCheckListItem(groupsListView,accounts->gr_name,QCheckListItem::CheckBox); | 41 | new QCheckListItem(groupsListView,accounts->gr_name,QCheckListItem::CheckBox); |
42 | groupComboBox->insertItem(accounts->gr_name); | 42 | groupComboBox->insertItem(accounts->gr_name); |
43 | } | 43 | } |
44 | |||
45 | showMaximized(); | 44 | showMaximized(); |
46 | } | 45 | } |
47 | 46 | ||
48 | /** | 47 | /** |
49 | * Empty destructor. | 48 | * Empty destructor. |
50 | * | 49 | * |
51 | */ | 50 | */ |
52 | UserDialog::~UserDialog() { | 51 | UserDialog::~UserDialog() { |
53 | } | 52 | } |
54 | 53 | ||
55 | /** | 54 | /** |
56 | * Creates the first tab, all userinfo is here. | 55 | * Creates the first tab, all userinfo is here. |
57 | * | 56 | * |
58 | */ | 57 | */ |
59 | void UserDialog::setupTab1() { | 58 | void UserDialog::setupTab1() { |
60 | QPixmap mypixmap; | 59 | QPixmap mypixmap; |
61 | QWidget *tabpage = new QWidget(myTabWidget,"page1"); | 60 | QWidget *tabpage = new QWidget(myTabWidget,"page1"); |
62 | QVBoxLayout *layout = new QVBoxLayout(tabpage); | 61 | QVBoxLayout *layout = new QVBoxLayout(tabpage); |
63 | layout->setMargin(5); | 62 | layout->setMargin(5); |
64 | 63 | ||
65 | // Picture | 64 | // Picture |
66 | picturePushButton = new QPushButton(tabpage,"Label"); | 65 | picturePushButton = new QPushButton(tabpage,"Label"); |
67 | picturePushButton->setMinimumSize(48,48); | 66 | picturePushButton->setMinimumSize(48,48); |
68 | picturePushButton->setMaximumSize(48,48); | 67 | picturePushButton->setMaximumSize(48,48); |
69 | picturePushButton->setPixmap(Resource::loadPixmap("usermanager/usericon"));// Load default usericon. | 68 | picturePushButton->setPixmap(Resource::loadPixmap("usermanager/usericon"));// Load default usericon. |
70 | connect(picturePushButton,SIGNAL(clicked()),this,SLOT(clickedPicture()));// Clicking the picture should invoke pictureselector. | 69 | connect(picturePushButton,SIGNAL(clicked()),this,SLOT(clickedPicture()));// Clicking the picture should invoke pictureselector. |
71 | 70 | ||
72 | // Login | 71 | // Login |
73 | QLabel *loginLabel=new QLabel(tabpage,"Login: "); | 72 | QLabel *loginLabel=new QLabel(tabpage,"Login: "); |
74 | loginLabel->setText("Login: "); | 73 | loginLabel->setText("Login: "); |
75 | loginLineEdit=new QLineEdit(tabpage,"Login: "); | 74 | loginLineEdit=new QLineEdit(tabpage,"Login: "); |
76 | 75 | ||
77 | // UID | 76 | // UID |
78 | QLabel *uidLabel=new QLabel(tabpage,"uid: "); | 77 | QLabel *uidLabel=new QLabel(tabpage,"uid: "); |
79 | uidLabel->setText("UserID: "); | 78 | uidLabel->setText("UserID: "); |
80 | uidLineEdit=new QLineEdit(tabpage,"uid: "); | 79 | uidLineEdit=new QLineEdit(tabpage,"uid: "); |
81 | uidLineEdit->setEnabled(false); | 80 | uidLineEdit->setEnabled(false); |
82 | 81 | ||
83 | // Username (gecos) | 82 | // Username (gecos) |
84 | QLabel *gecosLabel=new QLabel(tabpage,"gecos"); | 83 | QLabel *gecosLabel=new QLabel(tabpage,"gecos"); |
85 | gecosLabel->setText("Username: "); | 84 | gecosLabel->setText("Username: "); |
86 | gecosLineEdit=new QLineEdit(tabpage,"gecos"); | 85 | gecosLineEdit=new QLineEdit(tabpage,"gecos"); |
87 | 86 | ||
88 | // Password | 87 | // Password |
89 | QLabel *passwordLabel=new QLabel(tabpage,"password"); | 88 | QLabel *passwordLabel=new QLabel(tabpage,"password"); |
90 | passwordLabel->setText("Password: "); | 89 | passwordLabel->setText("Password: "); |
91 | passwordLineEdit=new QLineEdit(tabpage,"password"); | 90 | passwordLineEdit=new QLineEdit(tabpage,"password"); |
92 | passwordLineEdit->setEchoMode(QLineEdit::Password); | 91 | passwordLineEdit->setEchoMode(QLineEdit::Password); |
93 | 92 | ||
94 | // Shell | 93 | // Shell |
95 | QLabel *shellLabel=new QLabel(tabpage,"shell"); | 94 | QLabel *shellLabel=new QLabel(tabpage,"shell"); |
96 | shellLabel->setText("Shell: "); | 95 | shellLabel->setText("Shell: "); |
97 | shellComboBox=new QComboBox(tabpage,"shell"); | 96 | shellComboBox=new QComboBox(tabpage,"shell"); |
98 | shellComboBox->setEditable(true); | 97 | shellComboBox->setEditable(true); |
99 | shellComboBox->insertItem("/bin/sh"); | 98 | shellComboBox->insertItem("/bin/sh"); |
100 | shellComboBox->insertItem("/bin/ash"); | 99 | shellComboBox->insertItem("/bin/ash"); |
101 | shellComboBox->insertItem("/bin/false"); | 100 | shellComboBox->insertItem("/bin/false"); |
102 | 101 | ||
103 | // Primary Group | 102 | // Primary Group |
104 | QLabel *groupLabel=new QLabel(tabpage,"group"); | 103 | QLabel *groupLabel=new QLabel(tabpage,"group"); |
105 | groupLabel->setText("Primary group: "); | 104 | groupLabel->setText("Primary group: "); |
106 | groupComboBox=new QComboBox(tabpage,"PrimaryGroup"); | 105 | groupComboBox=new QComboBox(tabpage,"PrimaryGroup"); |
107 | 106 | ||
108 | // Widget layout | 107 | // Copy /etc/skel |
108 | QLabel *skelLabel=new QLabel(tabpage,"skel"); | ||
109 | skelLabel->setText("Copy /etc/skel: "); | ||
110 | skelCheckBox=new QCheckBox(tabpage); | ||
111 | skelCheckBox->setChecked(true); | ||
112 | skelLabel->setDisabled(true); | ||
113 | skelCheckBox->setDisabled(true); | ||
114 | |||
115 | // Widget layout | ||
109 | QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout"); | 116 | QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout"); |
110 | layout->addWidget(picturePushButton); | 117 | layout->addWidget(picturePushButton); |
111 | layout->addSpacing(5); | 118 | layout->addSpacing(5); |
112 | layout->addLayout(hlayout); | 119 | layout->addLayout(hlayout); |
113 | QVBoxLayout *vlayout1=new QVBoxLayout(-1,"vlayout1"); | 120 | QVBoxLayout *vlayout1=new QVBoxLayout(-1,"vlayout1"); |
114 | QVBoxLayout *vlayout2=new QVBoxLayout(-1,"vlayout2"); | 121 | QVBoxLayout *vlayout2=new QVBoxLayout(-1,"vlayout2"); |
115 | // First column, labels | 122 | // First column, labels |
116 | vlayout1->addWidget(loginLabel); | 123 | vlayout1->addWidget(loginLabel); |
117 | vlayout1->addSpacing(5); | 124 | vlayout1->addSpacing(5); |
118 | vlayout1->addWidget(uidLabel); | 125 | vlayout1->addWidget(uidLabel); |
119 | vlayout1->addSpacing(5); | 126 | vlayout1->addSpacing(5); |
120 | vlayout1->addWidget(gecosLabel); | 127 | vlayout1->addWidget(gecosLabel); |
121 | vlayout1->addSpacing(5); | 128 | vlayout1->addSpacing(5); |
122 | vlayout1->addWidget(passwordLabel); | 129 | vlayout1->addWidget(passwordLabel); |
123 | vlayout1->addSpacing(5); | 130 | vlayout1->addSpacing(5); |
124 | vlayout1->addWidget(shellLabel); | 131 | vlayout1->addWidget(shellLabel); |
125 | vlayout1->addSpacing(5); | 132 | vlayout1->addSpacing(5); |
126 | vlayout1->addWidget(groupLabel); | 133 | vlayout1->addWidget(groupLabel); |
134 | vlayout1->addSpacing(5); | ||
135 | vlayout1->addWidget(skelLabel); | ||
127 | // Second column, data | 136 | // Second column, data |
128 | vlayout2->addWidget(loginLineEdit); | 137 | vlayout2->addWidget(loginLineEdit); |
129 | vlayout2->addSpacing(5); | 138 | vlayout2->addSpacing(5); |
130 | vlayout2->addWidget(uidLineEdit); | 139 | vlayout2->addWidget(uidLineEdit); |
131 | vlayout2->addSpacing(5); | 140 | vlayout2->addSpacing(5); |
132 | vlayout2->addWidget(gecosLineEdit); | 141 | vlayout2->addWidget(gecosLineEdit); |
133 | vlayout2->addSpacing(5); | 142 | vlayout2->addSpacing(5); |
134 | vlayout2->addWidget(passwordLineEdit); | 143 | vlayout2->addWidget(passwordLineEdit); |
135 | vlayout2->addSpacing(5); | 144 | vlayout2->addSpacing(5); |
136 | vlayout2->addWidget(shellComboBox); | 145 | vlayout2->addWidget(shellComboBox); |
137 | vlayout2->addSpacing(5); | 146 | vlayout2->addSpacing(5); |
138 | vlayout2->addWidget(groupComboBox); | 147 | vlayout2->addWidget(groupComboBox); |
148 | vlayout2->addSpacing(5); | ||
149 | vlayout2->addWidget(skelCheckBox); | ||
139 | hlayout->addLayout(vlayout1); | 150 | hlayout->addLayout(vlayout1); |
140 | hlayout->addLayout(vlayout2); | 151 | hlayout->addLayout(vlayout2); |
141 | 152 | ||
142 | myTabWidget->addTab(tabpage,"User Info"); | 153 | myTabWidget->addTab(tabpage,"User Info"); |
143 | } | 154 | } |
144 | 155 | ||
145 | /** | 156 | /** |
146 | * Creates the second tab containing additional groups for the user. | 157 | * Creates the second tab containing additional groups for the user. |
147 | * | 158 | * |
148 | */ | 159 | */ |
149 | void UserDialog::setupTab2() { | 160 | void UserDialog::setupTab2() { |
150 | QWidget *tabpage = new QWidget(myTabWidget,"page2"); | 161 | QWidget *tabpage = new QWidget(myTabWidget,"page2"); |
151 | QVBoxLayout *layout = new QVBoxLayout(tabpage); | 162 | QVBoxLayout *layout = new QVBoxLayout(tabpage); |
152 | layout->setMargin(5); | 163 | layout->setMargin(5); |
153 | 164 | ||
154 | // Additional groups | 165 | // Additional groups |
155 | groupsListView=new QListView(tabpage,"groups"); | 166 | groupsListView=new QListView(tabpage,"groups"); |
156 | groupsListView->addColumn("Additional groups"); | 167 | groupsListView->addColumn("Additional groups"); |
157 | groupsListView->setColumnWidthMode(0,QListView::Maximum); | 168 | groupsListView->setColumnWidthMode(0,QListView::Maximum); |
158 | groupsListView->setMultiSelection(false); | 169 | groupsListView->setMultiSelection(false); |
159 | groupsListView->setAllColumnsShowFocus(false); | 170 | groupsListView->setAllColumnsShowFocus(false); |
160 | 171 | ||
161 | layout->addSpacing(5); | 172 | layout->addSpacing(5); |
162 | // Grouplist | 173 | // Grouplist |
163 | layout->addWidget(groupsListView); | 174 | layout->addWidget(groupsListView); |
164 | 175 | ||
165 | myTabWidget->addTab(tabpage,"User Groups"); | 176 | myTabWidget->addTab(tabpage,"User Groups"); |
166 | } | 177 | } |
167 | 178 | ||
168 | /** | 179 | /** |
169 | * Static function that creates the userinfo dialog. | 180 | * Static function that creates the userinfo dialog. |
170 | * The user will be prompted to add a user. | 181 | * The user will be prompted to add a user. |
171 | * | 182 | * |
172 | * @param uid This is a suggested available UID. | 183 | * @param uid This is a suggested available UID. |
173 | * @param gid This is a suggested available GID. | 184 | * @param gid This is a suggested available GID. |
174 | * | 185 | * |
175 | * @return <code>true</code> if the user was successfully added, otherwise <code>false</code>. | 186 | * @return <code>true</code> if the user was successfully added, otherwise <code>false</code>. |
176 | * | 187 | * |
177 | */ | 188 | */ |
178 | bool UserDialog::addUser(int uid, int gid) { | 189 | bool UserDialog::addUser(int uid, int gid) { |
179 | UserDialog *adduserDialog=new UserDialog(); | 190 | UserDialog *adduserDialog=new UserDialog(); |
180 | adduserDialog->setCaption(tr("Add User")); | 191 | adduserDialog->setCaption(tr("Add User")); |
181 | adduserDialog->userID=uid;// Set next available UID as default uid. | 192 | adduserDialog->userID=uid;// Set next available UID as default uid. |
182 | adduserDialog->groupID=gid;// Set next available GID as default gid. | 193 | adduserDialog->groupID=gid;// Set next available GID as default gid. |
183 | // Insert default group into groupComboBox | 194 | // Insert default group into groupComboBox |
184 | adduserDialog->groupComboBox->insertItem("<create new group>",0); | 195 | adduserDialog->groupComboBox->insertItem("<create new group>",0); |
185 | adduserDialog->uidLineEdit->setText(QString::number(uid)); | 196 | adduserDialog->uidLineEdit->setText(QString::number(uid)); |
186 | // Show the dialog! | 197 | // Show the dialog! |
187 | if(!(adduserDialog->exec())) return false; | 198 | if(!(adduserDialog->exec())) return false; |
188 | if((adduserDialog->groupComboBox->currentItem()!=0)) { | 199 | if((adduserDialog->groupComboBox->currentItem()!=0)) { |
189 | accounts->findGroup(adduserDialog->groupComboBox->currentText()); | 200 | accounts->findGroup(adduserDialog->groupComboBox->currentText()); |
190 | adduserDialog->groupID=accounts->gr_gid; | 201 | adduserDialog->groupID=accounts->gr_gid; |
191 | qWarning(QString::number(accounts->gr_gid)); | 202 | qWarning(QString::number(accounts->gr_gid)); |
192 | } | 203 | } |
193 | if(!(accounts->addUser(adduserDialog->loginLineEdit->text(), adduserDialog->passwordLineEdit->text(), | 204 | if(!(accounts->addUser(adduserDialog->loginLineEdit->text(), adduserDialog->passwordLineEdit->text(), |
194 | adduserDialog->uidLineEdit->text().toInt(), adduserDialog->groupID, adduserDialog->gecosLineEdit->text(), | 205 | adduserDialog->uidLineEdit->text().toInt(), adduserDialog->groupID, adduserDialog->gecosLineEdit->text(), |
195 | QString("/home/")+adduserDialog->loginLineEdit->text() , adduserDialog->shellComboBox->currentText()))) { | 206 | QString("/home/")+adduserDialog->loginLineEdit->text() , adduserDialog->shellComboBox->currentText()))) { |
196 | QMessageBox::information(0,"Ooops!","Something went wrong!\nUnable to add user."); | 207 | QMessageBox::information(0,"Ooops!","Something went wrong!\nUnable to add user."); |
197 | return false; | 208 | return false; |
198 | } | 209 | } |
199 | 210 | ||
200 | // Add User to additional groups. | 211 | // Add User to additional groups. |
201 | QCheckListItem *temp; | 212 | QCheckListItem *temp; |
202 | QListViewItemIterator it( adduserDialog->groupsListView ); | 213 | QListViewItemIterator it( adduserDialog->groupsListView ); |
203 | for ( ; it.current(); ++it ) { | 214 | for ( ; it.current(); ++it ) { |
204 | temp=(QCheckListItem*)it.current(); | 215 | temp=(QCheckListItem*)it.current(); |
205 | if (temp->isOn() ) | 216 | if (temp->isOn() ) |
206 | accounts->addGroupMember(it.current()->text(0),adduserDialog->loginLineEdit->text()); | 217 | accounts->addGroupMember(it.current()->text(0),adduserDialog->loginLineEdit->text()); |
207 | } | 218 | } |
208 | // Copy image to pics/users/ | 219 | // Copy image to pics/users/ |
209 | if(!(adduserDialog->userImage.isNull())) { | 220 | if(!(adduserDialog->userImage.isNull())) { |
210 | QDir d; | 221 | QDir d; |
211 | if(!(d.exists("/opt/QtPalmtop/pics/users"))) { | 222 | if(!(d.exists("/opt/QtPalmtop/pics/users"))) { |
212 | d.mkdir("/opt/QtPalmtop/pics/users"); | 223 | d.mkdir("/opt/QtPalmtop/pics/users"); |
213 | } | 224 | } |
214 | QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; | 225 | QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; |
215 | // adduserDialog->userImage=adduserDialog->userImage.smoothScale(48,48); | 226 | // adduserDialog->userImage=adduserDialog->userImage.smoothScale(48,48); |
216 | adduserDialog->userImage.save(filename,"PNG"); | 227 | adduserDialog->userImage.save(filename,"PNG"); |
217 | } | 228 | } |
218 | return true; | 229 | return true; |
219 | } | 230 | } |
220 | 231 | ||
221 | /** | 232 | /** |
222 | * Deletes the user account. | 233 | * Deletes the user account. |
223 | * | 234 | * |
224 | * @param username User to be deleted. | 235 | * @param username User to be deleted. |
225 | * | 236 | * |
226 | * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. | 237 | * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. |
227 | * | 238 | * |
228 | */ | 239 | */ |
229 | bool UserDialog::delUser(const char *username) { | 240 | bool UserDialog::delUser(const char *username) { |
230 | if((accounts->findUser(username))) {// Does that user exist? | 241 | if((accounts->findUser(username))) {// Does that user exist? |
231 | if(!(accounts->delUser(username))) {// Delete the user. | 242 | if(!(accounts->delUser(username))) {// Delete the user. |
232 | QMessageBox::information(0,"Ooops!","Something went wrong\nUnable to delete user: "+QString(username)+"."); | 243 | QMessageBox::information(0,"Ooops!","Something went wrong\nUnable to delete user: "+QString(username)+"."); |
233 | } | 244 | } |
234 | } else { | 245 | } else { |
235 | QMessageBox::information(0,"Invalid Username","That username ("+QString(username)+")does not exist."); | 246 | QMessageBox::information(0,"Invalid Username","That username ("+QString(username)+")does not exist."); |
236 | return false; | 247 | return false; |
237 | } | 248 | } |
238 | return true; | 249 | return true; |
239 | } | 250 | } |
240 | 251 | ||
241 | /** | 252 | /** |
242 | * This displays a confirmation dialog wether a user should be deleted or not. | 253 | * This displays a confirmation dialog wether a user should be deleted or not. |
243 | * (And also deletes the account) | 254 | * (And also deletes the account) |
244 | * | 255 | * |
245 | * @param username User to be deleted. | 256 | * @param username User to be deleted. |
246 | * | 257 | * |
247 | * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. | 258 | * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. |
248 | * | 259 | * |
249 | */ | 260 | */ |
250 | bool UserDialog::editUser(const char *username) { | 261 | bool UserDialog::editUser(const char *username) { |
262 | int invalid_group=0; | ||
251 | UserDialog *edituserDialog=new UserDialog();// Create Dialog | 263 | UserDialog *edituserDialog=new UserDialog();// Create Dialog |
252 | edituserDialog->setCaption(tr("Edit User")); | 264 | edituserDialog->setCaption(tr("Edit User")); |
253 | accounts->findUser(username);// Locate user in database and fill variables in 'accounts' object. | 265 | accounts->findUser(username);// Locate user in database and fill variables in 'accounts' object. |
254 | accounts->findGroup(accounts->pw_gid);// Locate the user's primary group, and fill group variables in 'accounts' object. | 266 | if(!(accounts->findGroup(accounts->pw_gid))) {// Locate the user's primary group, and fill group variables in 'accounts' object. |
267 | invalid_group=1; | ||
268 | } | ||
255 | // Fill widgets with userinfo. | 269 | // Fill widgets with userinfo. |
256 | edituserDialog->loginLineEdit->setText(accounts->pw_name); | 270 | edituserDialog->loginLineEdit->setText(accounts->pw_name); |
257 | edituserDialog->uidLineEdit->setText(QString::number(accounts->pw_uid)); | 271 | edituserDialog->uidLineEdit->setText(QString::number(accounts->pw_uid)); |
258 | edituserDialog->gecosLineEdit->setText(accounts->pw_gecos); | 272 | edituserDialog->gecosLineEdit->setText(accounts->pw_gecos); |
259 | // Set password to '........', we will later check if this still is the contents, if not, the password has been changed. | 273 | // Set password to '........', we will later check if this still is the contents, if not, the password has been changed. |
260 | edituserDialog->passwordLineEdit->setText("........"); | 274 | edituserDialog->passwordLineEdit->setText("........"); |
261 | // If this user is not using /bin/sh,/bin/ash or /bin/false as shell, add that entry to the shell-combobox. | 275 | // If this user is not using /bin/sh,/bin/ash or /bin/false as shell, add that entry to the shell-combobox. |
262 | if(accounts->pw_shell!="/bin/sh" && accounts->pw_shell!="/bin/ash" && accounts->pw_shell!="/bin/false") { | 276 | if(accounts->pw_shell!="/bin/sh" && accounts->pw_shell!="/bin/ash" && accounts->pw_shell!="/bin/false") { |
263 | edituserDialog->shellComboBox->insertItem(accounts->pw_shell,0); | 277 | edituserDialog->shellComboBox->insertItem(accounts->pw_shell,0); |
264 | edituserDialog->shellComboBox->setCurrentItem(0); | 278 | edituserDialog->shellComboBox->setCurrentItem(0); |
265 | } | 279 | } |
266 | // Select the primary group for this user. | 280 | // Select the primary group for this user. |
267 | for(int i=0;i<edituserDialog->groupComboBox->count();++i) { | 281 | for(int i=0;i<edituserDialog->groupComboBox->count();++i) { |
268 | if(accounts->gr_name==edituserDialog->groupComboBox->text(i)) { | 282 | if(accounts->gr_name==edituserDialog->groupComboBox->text(i)) { |
269 | edituserDialog->groupComboBox->setCurrentItem(i); | 283 | edituserDialog->groupComboBox->setCurrentItem(i); |
284 | break; | ||
270 | } | 285 | } |
271 | } | 286 | } |
287 | if(invalid_group) { | ||
288 | edituserDialog->groupComboBox->insertItem("<Undefined group>",0); | ||
289 | edituserDialog->groupComboBox->setCurrentItem(0); | ||
290 | } | ||
272 | // Select the groups in the listview, to which the user belongs. | 291 | // Select the groups in the listview, to which the user belongs. |
273 | QCheckListItem *temp; | 292 | QCheckListItem *temp; |
274 | QRegExp userRegExp(QString("[:\\s]%1\\s").arg(username)); | 293 | QRegExp userRegExp(QString("[:\\s]%1\\s").arg(username)); |
275 | QStringList tempList=accounts->groupStringList.grep(userRegExp);// Find all entries in the group database, that the user is a member of. | 294 | QStringList tempList=accounts->groupStringList.grep(userRegExp);// Find all entries in the group database, that the user is a member of. |
276 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) {// Iterate over all of them. | 295 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) {// Iterate over all of them. |
277 | QListViewItemIterator lvit( edituserDialog->groupsListView );// Compare to all groups. | 296 | QListViewItemIterator lvit( edituserDialog->groupsListView );// Compare to all groups. |
278 | for ( ; lvit.current(); ++lvit ) { | 297 | for ( ; lvit.current(); ++lvit ) { |
279 | if(lvit.current()->text(0)==(*it).left((*it).find(":"))) { | 298 | if(lvit.current()->text(0)==(*it).left((*it).find(":"))) { |
280 | temp=(QCheckListItem*)lvit.current(); | 299 | temp=(QCheckListItem*)lvit.current(); |
281 | temp->setOn(true);// If we find a line with that groupname, select it.; | 300 | temp->setOn(true);// If we find a line with that groupname, select it.; |
282 | } | 301 | } |
283 | } | 302 | } |
284 | } | 303 | } |
285 | 304 | ||
286 | if(!(edituserDialog->exec())) return false;// SHOW THE DIALOG! | 305 | if(!(edituserDialog->exec())) return false;// SHOW THE DIALOG! |
287 | 306 | ||
288 | accounts->findUser(username);// Fill user variables in 'acccounts' object. | 307 | accounts->findUser(username);// Fill user variables in 'acccounts' object. |
289 | accounts->pw_name=edituserDialog->loginLineEdit->text(); | 308 | accounts->pw_name=edituserDialog->loginLineEdit->text(); |
290 | // Has the password been changed ? Make a new "crypt":ed password. | 309 | // Has the password been changed ? Make a new "crypt":ed password. |
291 | if(edituserDialog->passwordLineEdit->text()!="........") accounts->pw_passwd=crypt(edituserDialog->passwordLineEdit->text(), accounts->crypt_make_salt()); | 310 | if(edituserDialog->passwordLineEdit->text()!="........") accounts->pw_passwd=crypt(edituserDialog->passwordLineEdit->text(), accounts->crypt_make_salt()); |
292 | 311 | ||
293 | // Set all variables in accounts object, that will be used when calling 'updateUser()' | 312 | // Set all variables in accounts object, that will be used when calling 'updateUser()' |
294 | accounts->pw_uid=edituserDialog->uidLineEdit->text().toInt(); | 313 | accounts->pw_uid=edituserDialog->uidLineEdit->text().toInt(); |
295 | accounts->findGroup(edituserDialog->groupComboBox->currentText());// Fill all group variables in 'accounts' object. | 314 | if(accounts->findGroup(edituserDialog->groupComboBox->currentText())) {// Fill all group variables in 'accounts' object. |
296 | accounts->pw_gid=accounts->gr_gid; | 315 | accounts->pw_gid=accounts->gr_gid;// Only do this if the group is a valid group (ie. "<Undefined group>"), otherwise keep the old group. |
316 | } | ||
297 | accounts->pw_gecos=edituserDialog->gecosLineEdit->text(); | 317 | accounts->pw_gecos=edituserDialog->gecosLineEdit->text(); |
298 | accounts->pw_shell=edituserDialog->shellComboBox->currentText(); | 318 | accounts->pw_shell=edituserDialog->shellComboBox->currentText(); |
299 | // Update userinfo, using the information stored in the user variables stored in the accounts object. | 319 | // Update userinfo, using the information stored in the user variables stored in the accounts object. |
300 | accounts->updateUser(username); | 320 | accounts->updateUser(username); |
301 | 321 | ||
302 | // Remove user from all groups he/she is a member of. (could be done in a better way I guess, this was simple though.) | 322 | // Remove user from all groups he/she is a member of. (could be done in a better way I guess, this was simple though.) |
303 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) { | 323 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) { |
304 | accounts->delGroupMember((*it).left((*it).find(":")),username); | 324 | accounts->delGroupMember((*it).left((*it).find(":")),username); |
305 | } | 325 | } |
306 | 326 | ||
307 | // Add User to additional groups that he/she is a member of. | 327 | // Add User to additional groups that he/she is a member of. |
308 | QListViewItemIterator it( edituserDialog->groupsListView ); | 328 | QListViewItemIterator it( edituserDialog->groupsListView ); |
309 | for ( ; it.current(); ++it ) { | 329 | for ( ; it.current(); ++it ) { |
310 | temp=(QCheckListItem*)it.current(); | 330 | temp=(QCheckListItem*)it.current(); |
311 | if ( temp->isOn() ) | 331 | if ( temp->isOn() ) |
312 | accounts->addGroupMember(it.current()->text(0),edituserDialog->loginLineEdit->text()); | 332 | accounts->addGroupMember(it.current()->text(0),edituserDialog->loginLineEdit->text()); |
313 | } | 333 | } |
314 | 334 | ||
315 | // Copy image to pics/users/ | 335 | // Copy image to pics/users/ |
316 | if(!(edituserDialog->userImage.isNull())) { | 336 | if(!(edituserDialog->userImage.isNull())) { |
317 | QDir d; | 337 | QDir d; |
318 | if(!(d.exists("/opt/QtPalmtop/pics/users"))) { | 338 | if(!(d.exists("/opt/QtPalmtop/pics/users"))) { |
319 | d.mkdir("/opt/QtPalmtop/pics/users"); | 339 | d.mkdir("/opt/QtPalmtop/pics/users"); |
320 | } | 340 | } |
321 | QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; | 341 | QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; |
322 | // edituserDialog->userImage=edituserDialog->userImage.smoothScale(48,48); | 342 | // edituserDialog->userImage=edituserDialog->userImage.smoothScale(48,48); |
323 | edituserDialog->userImage.save(filename,"PNG"); | 343 | edituserDialog->userImage.save(filename,"PNG"); |
324 | } | 344 | } |
325 | return true; | 345 | return true; |
326 | } | 346 | } |
327 | 347 | ||
328 | /** | 348 | /** |
329 | * "OK" has been clicked. Verify some information before closing the dialog. | 349 | * "OK" has been clicked. Verify some information before closing the dialog. |
330 | * | 350 | * |
331 | */ | 351 | */ |
332 | void UserDialog::accept() { | 352 | void UserDialog::accept() { |
333 | // Add checking... valid username? username taken? | 353 | // Add checking... valid username? username taken? |
334 | if(loginLineEdit->text().isEmpty()) { | 354 | if(loginLineEdit->text().isEmpty()) { |
335 | QMessageBox::information(0,"Empty Login","Please enter a login."); | 355 | QMessageBox::information(0,"Empty Login","Please enter a login."); |
336 | return; | 356 | return; |
337 | } | 357 | } |
338 | QDialog::accept(); | 358 | QDialog::accept(); |
339 | } | 359 | } |
340 | 360 | ||
341 | /** | 361 | /** |
342 | * This slot is called when the usericon is clicked, this loads (should) the iconselector. | 362 | * This slot is called when the usericon is clicked, this loads (should) the iconselector. |
343 | * | 363 | * |
344 | */ | 364 | */ |
345 | void UserDialog::clickedPicture() { | 365 | void UserDialog::clickedPicture() { |
346 | QString filename=OFileDialog::getOpenFileName(OFileSelector::EXTENDED,"/opt/QtPalmtop/pics"); | 366 | QString filename=OFileDialog::getOpenFileName(OFileSelector::EXTENDED,"/opt/QtPalmtop/pics"); |
347 | if(!(filename.isEmpty())) { | 367 | if(!(filename.isEmpty())) { |
348 | userImage.reset(); | 368 | userImage.reset(); |
349 | if(!(userImage.load(filename))) { | 369 | if(!(userImage.load(filename))) { |
350 | QMessageBox::information(0,"Sorry!","That icon could not be loaded.\nLoading failed on: "+filename); | 370 | QMessageBox::information(0,"Sorry!","That icon could not be loaded.\nLoading failed on: "+filename); |
351 | } else { | 371 | } else { |
352 | // userImage=userImage.smoothScale(48,48); | 372 | // userImage=userImage.smoothScale(48,48); |
353 | QPixmap *picture; | 373 | QPixmap *picture; |
354 | picture=(QPixmap *)picturePushButton->pixmap(); | 374 | picture=(QPixmap *)picturePushButton->pixmap(); |
355 | picture->convertFromImage(userImage,0); | 375 | picture->convertFromImage(userImage,0); |
356 | picturePushButton->update(); | 376 | picturePushButton->update(); |
357 | } | 377 | } |
358 | } | 378 | } |
359 | } | 379 | } |
diff --git a/noncore/settings/usermanager/userdialog.h b/noncore/settings/usermanager/userdialog.h index a878588..133b35d 100644 --- a/noncore/settings/usermanager/userdialog.h +++ b/noncore/settings/usermanager/userdialog.h | |||
@@ -1,58 +1,61 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * This program is free software; you can redistribute it and/or modify * | 3 | * This program is free software; you can redistribute it and/or modify * |
4 | * it under the terms of the GNU General Public License as published by * | 4 | * it under the terms of the GNU General Public License as published by * |
5 | * the Free Software Foundation; either version 2 of the License, or * | 5 | * the Free Software Foundation; either version 2 of the License, or * |
6 | * (at your option) any later version. * | 6 | * (at your option) any later version. * |
7 | * * | 7 | * * |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | #ifndef USERDIALOG_H | 9 | #ifndef USERDIALOG_H |
10 | #define USERDIALOG_H | 10 | #define USERDIALOG_H |
11 | 11 | ||
12 | #include <qdialog.h> | 12 | #include <qdialog.h> |
13 | #include <qlineedit.h> | 13 | #include <qlineedit.h> |
14 | #include <qcombobox.h> | 14 | #include <qcombobox.h> |
15 | #include <qlistview.h> | 15 | #include <qlistview.h> |
16 | #include <qtabwidget.h> | 16 | #include <qtabwidget.h> |
17 | #include <qpushbutton.h> | 17 | #include <qpushbutton.h> |
18 | #include <qcheckbox.h> | ||
18 | 19 | ||
19 | #include <qpe/resource.h> | 20 | #include <qpe/resource.h> |
20 | 21 | ||
21 | #include <opie/ofiledialog.h> | 22 | #include <opie/ofiledialog.h> |
22 | 23 | ||
23 | class UserDialog : public QDialog | 24 | class UserDialog : public QDialog |
24 | { | 25 | { |
25 | Q_OBJECT | 26 | Q_OBJECT |
26 | private: | 27 | private: |
27 | QTabWidget *myTabWidget; | 28 | QTabWidget *myTabWidget; |
28 | QPushButton *picturePushButton; | 29 | QPushButton *picturePushButton; |
29 | QLineEdit *loginLineEdit; | 30 | QLineEdit *loginLineEdit; |
30 | QLineEdit *uidLineEdit; | 31 | QLineEdit *uidLineEdit; |
31 | QLineEdit *gecosLineEdit; | 32 | QLineEdit *gecosLineEdit; |
32 | QLineEdit *passwordLineEdit; | 33 | QLineEdit *passwordLineEdit; |
33 | QComboBox *shellComboBox; | 34 | QComboBox *shellComboBox; |
34 | QComboBox *groupComboBox; | 35 | QComboBox *groupComboBox; |
36 | QLabel *skelLabel; | ||
37 | QCheckBox *skelCheckBox; | ||
35 | QListView *groupsListView; | 38 | QListView *groupsListView; |
36 | 39 | ||
37 | QStringList groupMembers; | 40 | QStringList groupMembers; |
38 | QString pictureLocation; | 41 | QString pictureLocation; |
39 | QImage userImage; | 42 | QImage userImage; |
40 | int groupID; | 43 | int groupID; |
41 | int userID; | 44 | int userID; |
42 | 45 | ||
43 | void setupTab1(void); | 46 | void setupTab1(void); |
44 | void setupTab2(void); | 47 | void setupTab2(void); |
45 | void accept(void); | 48 | void accept(void); |
46 | 49 | ||
47 | private slots: | 50 | private slots: |
48 | void clickedPicture(void); | 51 | void clickedPicture(void); |
49 | 52 | ||
50 | public: | 53 | public: |
51 | UserDialog( QWidget* parent = 0, const char* name = 0, bool modal=true, WFlags fl = 0 ); | 54 | UserDialog( QWidget* parent = 0, const char* name = 0, bool modal=true, WFlags fl = 0 ); |
52 | ~UserDialog(); | 55 | ~UserDialog(); |
53 | static bool addUser(int uid, int gid); | 56 | static bool addUser(int uid, int gid); |
54 | static bool editUser(const char *username); | 57 | static bool editUser(const char *username); |
55 | static bool delUser(const char *username); | 58 | static bool delUser(const char *username); |
56 | }; | 59 | }; |
57 | 60 | ||
58 | #endif | 61 | #endif |
diff --git a/noncore/settings/usermanager/usermanager.cpp b/noncore/settings/usermanager/usermanager.cpp index 2735e6a..57efa71 100644 --- a/noncore/settings/usermanager/usermanager.cpp +++ b/noncore/settings/usermanager/usermanager.cpp | |||
@@ -1,246 +1,254 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * This program is free software; you can redistribute it and/or modify * | 3 | * This program is free software; you can redistribute it and/or modify * |
4 | * it under the terms of the GNU General Public License as published by * | 4 | * it under the terms of the GNU General Public License as published by * |
5 | * the Free Software Foundation; either version 2 of the License, or * | 5 | * the Free Software Foundation; either version 2 of the License, or * |
6 | * (at your option) any later version. * | 6 | * (at your option) any later version. * |
7 | * * | 7 | * * |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | 9 | ||
10 | #include "usermanager.h" | 10 | #include "usermanager.h" |
11 | 11 | ||
12 | #include <qlayout.h> | 12 | #include <qlayout.h> |
13 | #include <stdio.h> | 13 | #include <stdio.h> |
14 | 14 | ||
15 | #include <qmessagebox.h> | 15 | #include <qmessagebox.h> |
16 | #include <qfile.h> | 16 | #include <qfile.h> |
17 | #include <qpe/resource.h> | 17 | #include <qpe/resource.h> |
18 | 18 | ||
19 | #include <qregexp.h> | 19 | #include <qregexp.h> |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * The mainwindow constructor. | 22 | * The mainwindow constructor. |
23 | * | 23 | * |
24 | * @param QWidget *parent | 24 | * @param QWidget *parent |
25 | * @param const char *name | 25 | * @param const char *name |
26 | * @ param WFlags fl | 26 | * @ param WFlags fl |
27 | * | 27 | * |
28 | */ | 28 | */ |
29 | UserConfig::UserConfig(QWidget* parent, const char* name, WFlags fl) : QMainWindow(parent, name, fl) { | 29 | UserConfig::UserConfig(QWidget* parent, const char* name, WFlags fl) : QMainWindow(parent, name, fl) { |
30 | setCaption(tr("OPIE User Manager")); | 30 | setCaption(tr("OPIE User Manager")); |
31 | 31 | ||
32 | // Create an instance of the global object 'accounts'. This holds all user/group info, and functions to modify them. | 32 | // Create an instance of the global object 'accounts'. This holds all user/group info, and functions to modify them. |
33 | accounts=new Passwd(); | 33 | accounts=new Passwd(); |
34 | accounts->open();// This actually loads the files /etc/passwd & /etc/group into memory. | 34 | accounts->open();// This actually loads the files /etc/passwd & /etc/group into memory. |
35 | 35 | ||
36 | // Create the toolbar. | 36 | // Create the toolbar. |
37 | QPEToolBar *toolbar = new QPEToolBar(this,"Toolbar"); | 37 | QPEToolBar *toolbar = new QPEToolBar(this,"Toolbar"); |
38 | toolbar->setHorizontalStretchable(1); // Is there any other way to get the toolbar to stretch of the full screen!? | 38 | toolbar->setHorizontalStretchable(1); // Is there any other way to get the toolbar to stretch of the full screen!? |
39 | adduserToolButton = new QToolButton(Resource::loadPixmap("usermanager/adduser"),"Add User",0,this,SLOT(addUser()),toolbar,"Add User"); | 39 | adduserToolButton = new QToolButton(Resource::loadPixmap("usermanager/adduser"),"Add User",0,this,SLOT(addUser()),toolbar,"Add User"); |
40 | edituserToolButton = new QToolButton(Resource::loadPixmap("usermanager/edituser"),"Edit User",0,this,SLOT(editUser()),toolbar,"Edit User"); | 40 | edituserToolButton = new QToolButton(Resource::loadPixmap("usermanager/edituser"),"Edit User",0,this,SLOT(editUser()),toolbar,"Edit User"); |
41 | deleteuserToolButton = new QToolButton(Resource::loadPixmap("usermanager/deleteuser"),"Delete User",0,this,SLOT(delUser()),toolbar,"Delete User"); | 41 | deleteuserToolButton = new QToolButton(Resource::loadPixmap("usermanager/deleteuser"),"Delete User",0,this,SLOT(delUser()),toolbar,"Delete User"); |
42 | QToolButton *userstext = new QToolButton(0,"User",0,0,0,toolbar,"User"); | 42 | QToolButton *userstext = new QToolButton(0,"User",0,0,0,toolbar,"User"); |
43 | userstext->setUsesTextLabel(true); | 43 | userstext->setUsesTextLabel(true); |
44 | toolbar->addSeparator(); | 44 | toolbar->addSeparator(); |
45 | addgroupToolButton = new QToolButton(Resource::loadPixmap("usermanager/addgroup"),"Add Group",0,this,SLOT(addGroup()),toolbar,"Add Group"); | 45 | addgroupToolButton = new QToolButton(Resource::loadPixmap("usermanager/addgroup"),"Add Group",0,this,SLOT(addGroup()),toolbar,"Add Group"); |
46 | editgroupToolButton = new QToolButton(Resource::loadPixmap("usermanager/editgroup"),"Edit Group",0,this,SLOT(editGroup()),toolbar,"Edit Group"); | 46 | editgroupToolButton = new QToolButton(Resource::loadPixmap("usermanager/editgroup"),"Edit Group",0,this,SLOT(editGroup()),toolbar,"Edit Group"); |
47 | deletegroupToolButton = new QToolButton(Resource::loadPixmap("usermanager/deletegroup"),"Delete Group",0,this,SLOT(delGroup()),toolbar,"Delete Group"); | 47 | deletegroupToolButton = new QToolButton(Resource::loadPixmap("usermanager/deletegroup"),"Delete Group",0,this,SLOT(delGroup()),toolbar,"Delete Group"); |
48 | QToolButton *groupstext = new QToolButton(0,"Group",0,0,0,toolbar,"Group"); | 48 | QToolButton *groupstext = new QToolButton(0,"Group",0,0,0,toolbar,"Group"); |
49 | groupstext->setUsesTextLabel(true); | 49 | groupstext->setUsesTextLabel(true); |
50 | addToolBar(toolbar,"myToolBar"); | 50 | addToolBar(toolbar,"myToolBar"); |
51 | 51 | ||
52 | // Add a tabwidget and all the tabs. | 52 | // Add a tabwidget and all the tabs. |
53 | myTabWidget = new QTabWidget(this,"My Tab Widget"); | 53 | myTabWidget = new QTabWidget(this,"My Tab Widget"); |
54 | setupTabAccounts(); | 54 | setupTabAccounts(); |
55 | setupTabAllUsers(); | 55 | setupTabAllUsers(); |
56 | setupTabAllGroups(); | 56 | setupTabAllGroups(); |
57 | userPopupMenu.insertItem("Copy",0); | ||
57 | 58 | ||
58 | getUsers(); // Fill out the iconview & listview with all users. | 59 | getUsers(); // Fill out the iconview & listview with all users. |
59 | getGroups(); // Fill out the group listview with all groups. | 60 | getGroups(); // Fill out the group listview with all groups. |
60 | 61 | ||
61 | setCentralWidget(myTabWidget); | 62 | setCentralWidget(myTabWidget); |
62 | } | 63 | } |
63 | 64 | ||
64 | UserConfig::~UserConfig() { | 65 | UserConfig::~UserConfig() { |
65 | accounts->close(); | 66 | accounts->close(); |
66 | delete accounts; | 67 | delete accounts; |
67 | } | 68 | } |
68 | 69 | ||
69 | void UserConfig::setupTabAccounts() { | 70 | void UserConfig::setupTabAccounts() { |
70 | QWidget *tabpage = new QWidget(this); | 71 | QWidget *tabpage = new QWidget(this); |
71 | QVBoxLayout *layout = new QVBoxLayout(tabpage); | 72 | QVBoxLayout *layout = new QVBoxLayout(tabpage); |
72 | layout->setMargin(5); | 73 | layout->setMargin(5); |
73 | 74 | ||
74 | usersIconView=new QListView(tabpage,"users"); | 75 | usersIconView=new QListView(tabpage,"users"); |
75 | usersIconView->addColumn("Icon"); | 76 | usersIconView->addColumn("Icon"); |
76 | usersIconView->addColumn("Username"); | 77 | usersIconView->addColumn("Username"); |
77 | usersIconView->setAllColumnsShowFocus(true); | 78 | usersIconView->setAllColumnsShowFocus(true); |
78 | layout->addWidget(usersIconView); | 79 | layout->addWidget(usersIconView); |
79 | 80 | ||
81 | connect(usersIconView,SIGNAL(returnPressed(QListViewItem *)),this,SLOT(showUserMenu(QListViewItem *))); | ||
82 | |||
80 | myTabWidget->addTab(tabpage,"Users"); | 83 | myTabWidget->addTab(tabpage,"Users"); |
81 | } | 84 | } |
82 | 85 | ||
83 | void UserConfig::setupTabAllUsers() { | 86 | void UserConfig::setupTabAllUsers() { |
84 | QWidget *tabpage = new QWidget(this); | 87 | QWidget *tabpage = new QWidget(this); |
85 | QVBoxLayout *layout = new QVBoxLayout(tabpage); | 88 | QVBoxLayout *layout = new QVBoxLayout(tabpage); |
86 | layout->setMargin(5); | 89 | layout->setMargin(5); |
87 | 90 | ||
88 | usersListView=new QListView(tabpage,"allusers"); | 91 | usersListView=new QListView(tabpage,"allusers"); |
89 | usersListView->addColumn("UID"); | 92 | usersListView->addColumn("UID"); |
90 | usersListView->addColumn("Login"); | 93 | usersListView->addColumn("Login"); |
91 | usersListView->addColumn("Username"); | 94 | usersListView->addColumn("Username"); |
92 | layout->addWidget(usersListView); | 95 | layout->addWidget(usersListView); |
93 | usersListView->setSorting(1,1); | 96 | usersListView->setSorting(1,1); |
94 | usersListView->setAllColumnsShowFocus(true); | 97 | usersListView->setAllColumnsShowFocus(true); |
95 | 98 | ||
96 | myTabWidget->addTab(tabpage,"All Users"); | 99 | myTabWidget->addTab(tabpage,"All Users"); |
97 | } | 100 | } |
98 | 101 | ||
99 | void UserConfig::setupTabAllGroups() { | 102 | void UserConfig::setupTabAllGroups() { |
100 | QWidget *tabpage = new QWidget(this); | 103 | QWidget *tabpage = new QWidget(this); |
101 | QVBoxLayout *layout = new QVBoxLayout(tabpage); | 104 | QVBoxLayout *layout = new QVBoxLayout(tabpage); |
102 | layout->setMargin(5); | 105 | layout->setMargin(5); |
103 | 106 | ||
104 | groupsListView=new QListView(tabpage,"groups"); | 107 | groupsListView=new QListView(tabpage,"groups"); |
105 | groupsListView->addColumn("GID"); | 108 | groupsListView->addColumn("GID"); |
106 | groupsListView->addColumn("Groupname"); | 109 | groupsListView->addColumn("Groupname"); |
107 | layout->addWidget(groupsListView); | 110 | layout->addWidget(groupsListView); |
108 | groupsListView->setSorting(1,1); | 111 | groupsListView->setSorting(1,1); |
109 | groupsListView->setAllColumnsShowFocus(true); | 112 | groupsListView->setAllColumnsShowFocus(true); |
110 | 113 | ||
111 | myTabWidget->addTab(tabpage,"All Groups"); | 114 | myTabWidget->addTab(tabpage,"All Groups"); |
112 | } | 115 | } |
113 | void UserConfig::getUsers() { | 116 | void UserConfig::getUsers() { |
114 | QString mytext; | 117 | QString mytext; |
115 | QPixmap mypixmap; | 118 | QPixmap mypixmap; |
116 | QListViewItem *listviewitem; | 119 | QListViewItem *listviewitem; |
117 | 120 | ||
118 | // Empty the iconview & the listview. | 121 | // Empty the iconview & the listview. |
119 | usersIconView->clear(); | 122 | usersIconView->clear(); |
120 | usersListView->clear(); | 123 | usersListView->clear(); |
121 | 124 | ||
122 | // availableUID is used as a deposite for the next available UID on the system, this should start at an ID over 500. | 125 | // availableUID is used as a deposite for the next available UID on the system, this should start at an ID over 500. |
123 | availableUID=500; | 126 | availableUID=500; |
124 | for(QStringList::Iterator it=accounts->passwdStringList.begin(); it!=accounts->passwdStringList.end(); ++it) { | 127 | for(QStringList::Iterator it=accounts->passwdStringList.begin(); it!=accounts->passwdStringList.end(); ++it) { |
125 | accounts->splitPasswdEntry(*it); // Split the string into it's components and store in variables in the accounts object. ("pr_name" and so on.) | 128 | accounts->splitPasswdEntry(*it); // Split the string into it's components and store in variables in the accounts object. ("pr_name" and so on.) |
126 | new QListViewItem(usersListView,QString::number(accounts->pw_uid),accounts->pw_name,accounts->pw_gecos); | 129 | new QListViewItem(usersListView,QString::number(accounts->pw_uid),accounts->pw_name,accounts->pw_gecos); |
127 | if((accounts->pw_uid>=500) && (accounts->pw_uid<65000)) {// Is this user a "normal" user ? | 130 | if((accounts->pw_uid>=500) && (accounts->pw_uid<65000)) {// Is this user a "normal" user ? |
128 | mytext=QString(accounts->pw_name)+" - ("+QString(accounts->pw_gecos)+")"; // The string displayed next to the icon. | 131 | mytext=QString(accounts->pw_name)+" - ("+QString(accounts->pw_gecos)+")"; // The string displayed next to the icon. |
129 | if(!(mypixmap.load("/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"))) { // Is there an icon for this user? Resource::loadPixmap is caching, doesn't work. | 132 | if(!(mypixmap.load("/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"))) { // Is there an icon for this user? Resource::loadPixmap is caching, doesn't work. |
130 | mypixmap=Resource::loadPixmap(QString("usermanager/usericon"));// If this user has no icon, load the default icon. | 133 | mypixmap=Resource::loadPixmap(QString("usermanager/usericon"));// If this user has no icon, load the default icon. |
131 | } | 134 | } |
132 | listviewitem=new QListViewItem(usersIconView,"",mytext);// Add the icon+text to the qiconview. | 135 | listviewitem=new QListViewItem(usersIconView,"",mytext);// Add the icon+text to the qiconview. |
133 | listviewitem->setPixmap(0,mypixmap); | 136 | listviewitem->setPixmap(0,mypixmap); |
134 | } | 137 | } |
135 | if((accounts->pw_uid>=availableUID) && (accounts->pw_uid<65000)) availableUID=accounts->pw_uid+1; // Increase 1 to the latest know UID to get a free uid. | 138 | if((accounts->pw_uid>=availableUID) && (accounts->pw_uid<65000)) availableUID=accounts->pw_uid+1; // Increase 1 to the latest know UID to get a free uid. |
136 | } | 139 | } |
137 | usersIconView->sort(); | 140 | usersIconView->sort(); |
138 | } | 141 | } |
139 | 142 | ||
140 | void UserConfig::addUser() { | 143 | void UserConfig::addUser() { |
141 | if(UserDialog::addUser(availableUID,availableGID)) {// Add the user to the system, also send next available UID and GID. | 144 | if(UserDialog::addUser(availableUID,availableGID)) {// Add the user to the system, also send next available UID and GID. |
142 | getUsers(); // Update users views. | 145 | getUsers(); // Update users views. |
143 | getGroups(); // Update groups view. | 146 | getGroups(); // Update groups view. |
144 | } | 147 | } |
145 | } | 148 | } |
146 | 149 | ||
147 | void UserConfig::editUser() { | 150 | void UserConfig::editUser() { |
148 | QString username; | 151 | QString username; |
149 | if(myTabWidget->currentPageIndex()==0) {// Users | 152 | if(myTabWidget->currentPageIndex()==0) {// Users |
150 | if(usersIconView->currentItem()) {// Any icon selected? | 153 | if(usersIconView->currentItem()) {// Any icon selected? |
151 | username=usersIconView->currentItem()->text(1);// Get the text associated with the icon. | 154 | username=usersIconView->currentItem()->text(1);// Get the text associated with the icon. |
152 | username=username.left(username.find(" - (",0,true));// Strip out the username. | 155 | username=username.left(username.find(" - (",0,true));// Strip out the username. |
153 | if(UserDialog::editUser(username)) {// Bring up the userinfo dialog. | 156 | if(UserDialog::editUser(username)) {// Bring up the userinfo dialog. |
154 | // If there were any changed also update the views. | 157 | // If there were any changed also update the views. |
155 | getUsers(); | 158 | getUsers(); |
156 | getGroups(); | 159 | getGroups(); |
157 | } | 160 | } |
158 | } else { | 161 | } else { |
159 | QMessageBox::information(this,"No selection.","No user has been selected."); | 162 | QMessageBox::information(this,"No selection.","No user has been selected."); |
160 | } | 163 | } |
161 | } | 164 | } |
162 | if(myTabWidget->currentPageIndex()==1) {// All users | 165 | if(myTabWidget->currentPageIndex()==1) {// All users |
163 | if(usersListView->currentItem()) {// Anything changed!? | 166 | if(usersListView->currentItem()) {// Anything changed!? |
164 | username=usersListView->currentItem()->text(1);// Get the username. | 167 | username=usersListView->currentItem()->text(1);// Get the username. |
165 | if(UserDialog::editUser(username)) {// Bring up the userinfo dialog. | 168 | if(UserDialog::editUser(username)) {// Bring up the userinfo dialog. |
166 | // And again update the views if there were any changes. | 169 | // And again update the views if there were any changes. |
167 | getUsers(); | 170 | getUsers(); |
168 | getGroups(); | 171 | getGroups(); |
169 | } | 172 | } |
170 | } else { | 173 | } else { |
171 | QMessageBox::information(this,"No selection.","No user has been selected."); | 174 | QMessageBox::information(this,"No selection.","No user has been selected."); |
172 | } | 175 | } |
173 | } | 176 | } |
174 | } | 177 | } |
175 | 178 | ||
176 | void UserConfig::delUser() { | 179 | void UserConfig::delUser() { |
177 | QString username; | 180 | QString username; |
178 | 181 | ||
179 | if(myTabWidget->currentPageIndex()==0) {// Users, Iconview. | 182 | if(myTabWidget->currentPageIndex()==0) {// Users, Iconview. |
180 | if(usersIconView->currentItem()) {// Anything selected? | 183 | if(usersIconView->currentItem()) {// Anything selected? |
181 | username=usersIconView->currentItem()->text(1);// Get string associated with icon. | 184 | username=usersIconView->currentItem()->text(1);// Get string associated with icon. |
182 | username=username.left(username.find(" - (",0,true));// Strip out the username. | 185 | username=username.left(username.find(" - (",0,true));// Strip out the username. |
183 | if(QMessageBox::warning(this,"Delete user","Are you sure you want to\ndelete this user? \""+QString(username)+"\" ?","&No","&Yes",0,0,1)) { | 186 | if(QMessageBox::warning(this,"Delete user","Are you sure you want to\ndelete this user? \""+QString(username)+"\" ?","&No","&Yes",0,0,1)) { |
184 | if(UserDialog::delUser(username)) {// Delete the user if possible. | 187 | if(UserDialog::delUser(username)) {// Delete the user if possible. |
185 | // Update views. | 188 | // Update views. |
186 | getUsers(); | 189 | getUsers(); |
187 | getGroups(); | 190 | getGroups(); |
188 | } | 191 | } |
189 | } | 192 | } |
190 | } else { | 193 | } else { |
191 | QMessageBox::information(this,"No selection","No user has been selected."); | 194 | QMessageBox::information(this,"No selection","No user has been selected."); |
192 | } | 195 | } |
193 | } | 196 | } |
194 | if(myTabWidget->currentPageIndex()==1) {// All users | 197 | if(myTabWidget->currentPageIndex()==1) {// All users |
195 | if(usersListView->currentItem()) {// Anything changed!? | 198 | if(usersListView->currentItem()) {// Anything changed!? |
196 | username=usersListView->currentItem()->text(1);// Get the username. | 199 | username=usersListView->currentItem()->text(1);// Get the username. |
197 | if(QMessageBox::warning(this,"Delete user","Are you sure you want to\ndelete this user? \""+QString(username)+"\" ?","&No","&Yes",0,0,1)) { | 200 | if(QMessageBox::warning(this,"Delete user","Are you sure you want to\ndelete this user? \""+QString(username)+"\" ?","&No","&Yes",0,0,1)) { |
198 | if(UserDialog::delUser(username)) {// Try to delete the user. | 201 | if(UserDialog::delUser(username)) {// Try to delete the user. |
199 | // Update views. | 202 | // Update views. |
200 | getUsers(); | 203 | getUsers(); |
201 | getGroups(); | 204 | getGroups(); |
202 | } | 205 | } |
203 | } | 206 | } |
204 | } else { | 207 | } else { |
205 | QMessageBox::information(this,"No selection","No user has been selected."); | 208 | QMessageBox::information(this,"No selection","No user has been selected."); |
206 | } | 209 | } |
207 | } | 210 | } |
208 | 211 | ||
209 | } | 212 | } |
210 | 213 | ||
211 | void UserConfig::getGroups() { | 214 | void UserConfig::getGroups() { |
212 | groupsListView->clear();// Empty the listview. | 215 | groupsListView->clear();// Empty the listview. |
213 | availableGID=500;// We need to find the next free GID, and are only interested in values between 500 & 65000. | 216 | availableGID=500;// We need to find the next free GID, and are only interested in values between 500 & 65000. |
214 | for(QStringList::Iterator it=accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) {// Split the list into lines. | 217 | for(QStringList::Iterator it=accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) {// Split the list into lines. |
215 | accounts->splitGroupEntry(*it);// Split the line into its components and fill the variables of 'accounts'. (gr_name, gr_uid & gr_mem). | 218 | accounts->splitGroupEntry(*it);// Split the line into its components and fill the variables of 'accounts'. (gr_name, gr_uid & gr_mem). |
216 | new QListViewItem(groupsListView,QString::number(accounts->gr_gid),accounts->gr_name); | 219 | new QListViewItem(groupsListView,QString::number(accounts->gr_gid),accounts->gr_name); |
217 | if((accounts->gr_gid>=availableGID) && (accounts->gr_gid<65000)) availableGID=accounts->gr_gid+1;// Maybe a new free GID. | 220 | if((accounts->gr_gid>=availableGID) && (accounts->gr_gid<65000)) availableGID=accounts->gr_gid+1;// Maybe a new free GID. |
218 | } | 221 | } |
219 | } | 222 | } |
220 | 223 | ||
221 | void UserConfig::addGroup() { | 224 | void UserConfig::addGroup() { |
222 | if(GroupDialog::addGroup(availableGID)) getGroups();// Bring up the add group dialog. | 225 | if(GroupDialog::addGroup(availableGID)) getGroups();// Bring up the add group dialog. |
223 | } | 226 | } |
224 | 227 | ||
225 | void UserConfig::editGroup() { | 228 | void UserConfig::editGroup() { |
226 | int gid; | 229 | int gid; |
227 | if(groupsListView->currentItem()) {// Any group selected? | 230 | if(groupsListView->currentItem()) {// Any group selected? |
228 | gid=groupsListView->currentItem()->text(0).toInt();// Get the GID from the listview. | 231 | gid=groupsListView->currentItem()->text(0).toInt();// Get the GID from the listview. |
229 | if(GroupDialog::editGroup(gid)) getGroups();// Bring up the edit group dialog. | 232 | if(GroupDialog::editGroup(gid)) getGroups();// Bring up the edit group dialog. |
230 | } else { | 233 | } else { |
231 | QMessageBox::information(this,"No selection","No group has been selected."); | 234 | QMessageBox::information(this,"No selection","No group has been selected."); |
232 | } | 235 | } |
233 | } | 236 | } |
234 | 237 | ||
235 | void UserConfig::delGroup() { | 238 | void UserConfig::delGroup() { |
236 | const char *groupname; | 239 | const char *groupname; |
237 | if(groupsListView->currentItem()) {// Any group selected? | 240 | if(groupsListView->currentItem()) {// Any group selected? |
238 | groupname=groupsListView->currentItem()->text(1);// Get the groupname from the listview. | 241 | groupname=groupsListView->currentItem()->text(1);// Get the groupname from the listview. |
239 | if(QMessageBox::warning(this,"Delete group","Are you sure you want to\ndelete the group \""+QString(groupname)+"\" ?","&No","&Yes",0,0,1)) { | 242 | if(QMessageBox::warning(this,"Delete group","Are you sure you want to\ndelete the group \""+QString(groupname)+"\" ?","&No","&Yes",0,0,1)) { |
240 | // If confirmed, try to delete the group. | 243 | // If confirmed, try to delete the group. |
241 | if(GroupDialog::delGroup(groupname)) getGroups(); // And also update the view afterwards if the user was deleted. | 244 | if(GroupDialog::delGroup(groupname)) getGroups(); // And also update the view afterwards if the user was deleted. |
242 | } | 245 | } |
243 | } else { | 246 | } else { |
244 | QMessageBox::information(this,"No selection","No group has been selected."); | 247 | QMessageBox::information(this,"No selection","No group has been selected."); |
245 | } | 248 | } |
246 | } | 249 | } |
250 | |||
251 | void UserConfig::showUserMenu(QListViewItem *item) { | ||
252 | //userPopupMenu.exec(item->mapToGlobal(QPoint(0,0))); | ||
253 | qWarning("Pressed!"); | ||
254 | } | ||
diff --git a/noncore/settings/usermanager/usermanager.h b/noncore/settings/usermanager/usermanager.h index 9909242..6782923 100644 --- a/noncore/settings/usermanager/usermanager.h +++ b/noncore/settings/usermanager/usermanager.h | |||
@@ -1,65 +1,66 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * This program is free software; you can redistribute it and/or modify * | 3 | * This program is free software; you can redistribute it and/or modify * |
4 | * it under the terms of the GNU General Public License as published by * | 4 | * it under the terms of the GNU General Public License as published by * |
5 | * the Free Software Foundation; either version 2 of the License, or * | 5 | * the Free Software Foundation; either version 2 of the License, or * |
6 | * (at your option) any later version. * | 6 | * (at your option) any later version. * |
7 | * * | 7 | * * |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | 9 | ||
10 | #ifndef USERCONFIG_H | 10 | #ifndef USERCONFIG_H |
11 | #define USERCONFIG_H | 11 | #define USERCONFIG_H |
12 | 12 | ||
13 | #include <qmainwindow.h> | 13 | #include <qmainwindow.h> |
14 | #include <qtabwidget.h> | 14 | #include <qtabwidget.h> |
15 | #include <qlistview.h> | 15 | #include <qlistview.h> |
16 | //#include <qiconview.h> | ||
17 | |||
18 | #include <qpe/qpemenubar.h> | ||
19 | #include <qpopupmenu.h> | 16 | #include <qpopupmenu.h> |
20 | #include <qpe/qpetoolbar.h> | ||
21 | #include <qtoolbutton.h> | 17 | #include <qtoolbutton.h> |
22 | 18 | ||
19 | #include <qpe/qpetoolbar.h> | ||
20 | |||
23 | #include "userdialog.h" | 21 | #include "userdialog.h" |
24 | #include "groupdialog.h" | 22 | #include "groupdialog.h" |
25 | #include "passwd.h" | 23 | #include "passwd.h" |
26 | 24 | ||
27 | class UserConfig : public QMainWindow | 25 | class UserConfig : public QMainWindow |
28 | { | 26 | { |
29 | Q_OBJECT | 27 | Q_OBJECT |
30 | 28 | ||
31 | public: | 29 | public: |
32 | UserConfig( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); | 30 | UserConfig( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); |
33 | ~UserConfig(); | 31 | ~UserConfig(); |
34 | 32 | ||
35 | private: | 33 | private: |
36 | QToolButton *adduserToolButton; | 34 | QToolButton *adduserToolButton; |
37 | QToolButton *edituserToolButton; | 35 | QToolButton *edituserToolButton; |
38 | QToolButton *deleteuserToolButton; | 36 | QToolButton *deleteuserToolButton; |
39 | QToolButton *addgroupToolButton; | 37 | QToolButton *addgroupToolButton; |
40 | QToolButton *editgroupToolButton; | 38 | QToolButton *editgroupToolButton; |
41 | QToolButton *deletegroupToolButton; | 39 | QToolButton *deletegroupToolButton; |
42 | QTabWidget *myTabWidget; | 40 | QTabWidget *myTabWidget; |
43 | QListView *usersIconView; | 41 | QListView *usersIconView; |
44 | QListView *usersListView; | 42 | QListView *usersListView; |
45 | QListView *groupsListView; | 43 | QListView *groupsListView; |
44 | QPopupMenu userPopupMenu; | ||
45 | QPopupMenu groupPopupMenu; | ||
46 | int availableUID; | 46 | int availableUID; |
47 | int availableGID; | 47 | int availableGID; |
48 | void setupTabAccounts(); | 48 | void setupTabAccounts(); |
49 | void setupTabAllUsers(); | 49 | void setupTabAllUsers(); |
50 | void setupTabAllGroups(); | 50 | void setupTabAllGroups(); |
51 | void setupTabPrefs(); | 51 | void setupTabPrefs(); |
52 | void setupTabAbout(); | 52 | void setupTabAbout(); |
53 | void getUsers(); | 53 | void getUsers(); |
54 | void getGroups(); | 54 | void getGroups(); |
55 | 55 | ||
56 | private slots: | 56 | private slots: |
57 | void addUser(); | 57 | void addUser(); |
58 | void editUser(); | 58 | void editUser(); |
59 | void delUser(); | 59 | void delUser(); |
60 | void addGroup(); | 60 | void addGroup(); |
61 | void editGroup(); | 61 | void editGroup(); |
62 | void delGroup(); | 62 | void delGroup(); |
63 | void showUserMenu(QListViewItem *item); | ||
63 | }; | 64 | }; |
64 | 65 | ||
65 | #endif // USERCONFIG_H | 66 | #endif // USERCONFIG_H |