summaryrefslogtreecommitdiff
authorumopapisdn <umopapisdn>2002-10-14 20:42:04 (UTC)
committer umopapisdn <umopapisdn>2002-10-14 20:42:04 (UTC)
commit14f450ead20011e5697bb36a4ad087cc648b439d (patch) (unidiff)
tree7b474bbeeba4ceebb50c2da0bf26d80002062970
parent8140420efa133ea59310d3f8de721950fd1d13af (diff)
downloadopie-14f450ead20011e5697bb36a4ad087cc648b439d.zip
opie-14f450ead20011e5697bb36a4ad087cc648b439d.tar.gz
opie-14f450ead20011e5697bb36a4ad087cc648b439d.tar.bz2
New users added in OpenZaurus now by default belong to some groups. (video, audio, time, power, input, sharp, tty)
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/usermanager/userdialog.cpp23
1 files changed, 20 insertions, 3 deletions
diff --git a/noncore/settings/usermanager/userdialog.cpp b/noncore/settings/usermanager/userdialog.cpp
index 90e27d5..c43b391 100644
--- a/noncore/settings/usermanager/userdialog.cpp
+++ b/noncore/settings/usermanager/userdialog.cpp
@@ -1,379 +1,396 @@
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#include <qfile.h>
15 16
16#include <stdlib.h> 17#include <stdlib.h>
17 18
18#include <stdio.h> 19#include <stdio.h>
19#include <sys/types.h> 20#include <sys/types.h>
20#include <sys/wait.h> 21#include <sys/wait.h>
21#include <unistd.h> 22#include <unistd.h>
22#include <signal.h> 23#include <signal.h>
23 24
24#include "passwd.h" 25#include "passwd.h"
25 26
26/** 27/**
27 * UserDialog constructor. Setup the dialog, fill the groupComboBox & groupsListView with all groups. 28 * UserDialog constructor. Setup the dialog, fill the groupComboBox & groupsListView with all groups.
28 * 29 *
29 */ 30 */
30UserDialog::UserDialog(QWidget* parent, const char* name, bool modal, WFlags fl) : QDialog(parent, name, modal, fl) { 31UserDialog::UserDialog(QWidget* parent, const char* name, bool modal, WFlags fl) : QDialog(parent, name, modal, fl) {
31 QVBoxLayout *layout = new QVBoxLayout(this); 32 QVBoxLayout *layout = new QVBoxLayout(this);
32 myTabWidget=new QTabWidget(this,"User Tab Widget"); 33 myTabWidget=new QTabWidget(this,"User Tab Widget");
33 layout->addWidget(myTabWidget); 34 layout->addWidget(myTabWidget);
34 setupTab1(); 35 setupTab1();
35 setupTab2(); 36 setupTab2();
36 37
37 accounts->groupStringList.sort(); 38 accounts->groupStringList.sort();
38 // And also fill the listview & the combobox with all available groups. 39 // And also fill the listview & the combobox with all available groups.
39 for( QStringList::Iterator it = accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) { 40 for( QStringList::Iterator it = accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) {
40 accounts->splitGroupEntry(*it); 41 accounts->splitGroupEntry(*it);
41 new QCheckListItem(groupsListView,accounts->gr_name,QCheckListItem::CheckBox); 42 new QCheckListItem(groupsListView,accounts->gr_name,QCheckListItem::CheckBox);
42 groupComboBox->insertItem(accounts->gr_name); 43 groupComboBox->insertItem(accounts->gr_name);
43 } 44 }
44 showMaximized(); 45 showMaximized();
45} 46}
46 47
47/** 48/**
48 * Empty destructor. 49 * Empty destructor.
49 * 50 *
50 */ 51 */
51UserDialog::~UserDialog() { 52UserDialog::~UserDialog() {
52} 53}
53 54
54/** 55/**
55 * Creates the first tab, all userinfo is here. 56 * Creates the first tab, all userinfo is here.
56 * 57 *
57 */ 58 */
58void UserDialog::setupTab1() { 59void UserDialog::setupTab1() {
59 QPixmap mypixmap; 60 QPixmap mypixmap;
60 QWidget *tabpage = new QWidget(myTabWidget,"page1"); 61 QWidget *tabpage = new QWidget(myTabWidget,"page1");
61 QVBoxLayout *layout = new QVBoxLayout(tabpage); 62 QVBoxLayout *layout = new QVBoxLayout(tabpage);
62 layout->setMargin(5); 63 layout->setMargin(5);
63 64
64 // Picture 65 // Picture
65 picturePushButton = new QPushButton(tabpage,"Label"); 66 picturePushButton = new QPushButton(tabpage,"Label");
66 picturePushButton->setMinimumSize(48,48); 67 picturePushButton->setMinimumSize(48,48);
67 picturePushButton->setMaximumSize(48,48); 68 picturePushButton->setMaximumSize(48,48);
68 picturePushButton->setPixmap(Resource::loadPixmap("usermanager/usericon"));// Load default usericon. 69 picturePushButton->setPixmap(Resource::loadPixmap("usermanager/usericon"));// Load default usericon.
69 connect(picturePushButton,SIGNAL(clicked()),this,SLOT(clickedPicture()));// Clicking the picture should invoke pictureselector. 70 connect(picturePushButton,SIGNAL(clicked()),this,SLOT(clickedPicture()));// Clicking the picture should invoke pictureselector.
70 71
71 // Login 72 // Login
72 QLabel *loginLabel=new QLabel(tabpage,"Login: "); 73 QLabel *loginLabel=new QLabel(tabpage,"Login: ");
73 loginLabel->setText("Login: "); 74 loginLabel->setText("Login: ");
74 loginLineEdit=new QLineEdit(tabpage,"Login: "); 75 loginLineEdit=new QLineEdit(tabpage,"Login: ");
75 76
76 // UID 77 // UID
77 QLabel *uidLabel=new QLabel(tabpage,"uid: "); 78 QLabel *uidLabel=new QLabel(tabpage,"uid: ");
78 uidLabel->setText("UserID: "); 79 uidLabel->setText("UserID: ");
79 uidLineEdit=new QLineEdit(tabpage,"uid: "); 80 uidLineEdit=new QLineEdit(tabpage,"uid: ");
80 uidLineEdit->setEnabled(false); 81 uidLineEdit->setEnabled(false);
81 82
82 // Username (gecos) 83 // Username (gecos)
83 QLabel *gecosLabel=new QLabel(tabpage,"gecos"); 84 QLabel *gecosLabel=new QLabel(tabpage,"gecos");
84 gecosLabel->setText("Username: "); 85 gecosLabel->setText("Username: ");
85 gecosLineEdit=new QLineEdit(tabpage,"gecos"); 86 gecosLineEdit=new QLineEdit(tabpage,"gecos");
86 87
87 // Password 88 // Password
88 QLabel *passwordLabel=new QLabel(tabpage,"password"); 89 QLabel *passwordLabel=new QLabel(tabpage,"password");
89 passwordLabel->setText("Password: "); 90 passwordLabel->setText("Password: ");
90 passwordLineEdit=new QLineEdit(tabpage,"password"); 91 passwordLineEdit=new QLineEdit(tabpage,"password");
91 passwordLineEdit->setEchoMode(QLineEdit::Password); 92 passwordLineEdit->setEchoMode(QLineEdit::Password);
92 93
93 // Shell 94 // Shell
94 QLabel *shellLabel=new QLabel(tabpage,"shell"); 95 QLabel *shellLabel=new QLabel(tabpage,"shell");
95 shellLabel->setText("Shell: "); 96 shellLabel->setText("Shell: ");
96 shellComboBox=new QComboBox(tabpage,"shell"); 97 shellComboBox=new QComboBox(tabpage,"shell");
97 shellComboBox->setEditable(true); 98 shellComboBox->setEditable(true);
98 shellComboBox->insertItem("/bin/sh"); 99 shellComboBox->insertItem("/bin/sh");
99 shellComboBox->insertItem("/bin/ash"); 100 shellComboBox->insertItem("/bin/ash");
100 shellComboBox->insertItem("/bin/false"); 101 shellComboBox->insertItem("/bin/false");
101 102
102 // Primary Group 103 // Primary Group
103 QLabel *groupLabel=new QLabel(tabpage,"group"); 104 QLabel *groupLabel=new QLabel(tabpage,"group");
104 groupLabel->setText("Primary group: "); 105 groupLabel->setText("Primary group: ");
105 groupComboBox=new QComboBox(tabpage,"PrimaryGroup"); 106 groupComboBox=new QComboBox(tabpage,"PrimaryGroup");
106 107
107 // Copy /etc/skel 108 // Copy /etc/skel
108 QLabel *skelLabel=new QLabel(tabpage,"skel"); 109 QLabel *skelLabel=new QLabel(tabpage,"skel");
109 skelLabel->setText("Copy /etc/skel: "); 110 skelLabel->setText("Copy /etc/skel: ");
110 skelCheckBox=new QCheckBox(tabpage); 111 skelCheckBox=new QCheckBox(tabpage);
111 skelCheckBox->setChecked(true); 112 skelCheckBox->setChecked(true);
112 skelLabel->setDisabled(true); 113 skelLabel->setDisabled(true);
113 skelCheckBox->setDisabled(true); 114 skelCheckBox->setDisabled(true);
114 115
115 // Widget layout 116 // Widget layout
116 QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout"); 117 QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout");
117 layout->addWidget(picturePushButton); 118 layout->addWidget(picturePushButton);
118 layout->addSpacing(5); 119 layout->addSpacing(5);
119 layout->addLayout(hlayout); 120 layout->addLayout(hlayout);
120 QVBoxLayout *vlayout1=new QVBoxLayout(-1,"vlayout1"); 121 QVBoxLayout *vlayout1=new QVBoxLayout(-1,"vlayout1");
121 QVBoxLayout *vlayout2=new QVBoxLayout(-1,"vlayout2"); 122 QVBoxLayout *vlayout2=new QVBoxLayout(-1,"vlayout2");
122 // First column, labels 123 // First column, labels
123 vlayout1->addWidget(loginLabel); 124 vlayout1->addWidget(loginLabel);
124 vlayout1->addSpacing(5); 125 vlayout1->addSpacing(5);
125 vlayout1->addWidget(uidLabel); 126 vlayout1->addWidget(uidLabel);
126 vlayout1->addSpacing(5); 127 vlayout1->addSpacing(5);
127 vlayout1->addWidget(gecosLabel); 128 vlayout1->addWidget(gecosLabel);
128 vlayout1->addSpacing(5); 129 vlayout1->addSpacing(5);
129 vlayout1->addWidget(passwordLabel); 130 vlayout1->addWidget(passwordLabel);
130 vlayout1->addSpacing(5); 131 vlayout1->addSpacing(5);
131 vlayout1->addWidget(shellLabel); 132 vlayout1->addWidget(shellLabel);
132 vlayout1->addSpacing(5); 133 vlayout1->addSpacing(5);
133 vlayout1->addWidget(groupLabel); 134 vlayout1->addWidget(groupLabel);
134 vlayout1->addSpacing(5); 135 vlayout1->addSpacing(5);
135 vlayout1->addWidget(skelLabel); 136 vlayout1->addWidget(skelLabel);
136 // Second column, data 137 // Second column, data
137 vlayout2->addWidget(loginLineEdit); 138 vlayout2->addWidget(loginLineEdit);
138 vlayout2->addSpacing(5); 139 vlayout2->addSpacing(5);
139 vlayout2->addWidget(uidLineEdit); 140 vlayout2->addWidget(uidLineEdit);
140 vlayout2->addSpacing(5); 141 vlayout2->addSpacing(5);
141 vlayout2->addWidget(gecosLineEdit); 142 vlayout2->addWidget(gecosLineEdit);
142 vlayout2->addSpacing(5); 143 vlayout2->addSpacing(5);
143 vlayout2->addWidget(passwordLineEdit); 144 vlayout2->addWidget(passwordLineEdit);
144 vlayout2->addSpacing(5); 145 vlayout2->addSpacing(5);
145 vlayout2->addWidget(shellComboBox); 146 vlayout2->addWidget(shellComboBox);
146 vlayout2->addSpacing(5); 147 vlayout2->addSpacing(5);
147 vlayout2->addWidget(groupComboBox); 148 vlayout2->addWidget(groupComboBox);
148 vlayout2->addSpacing(5); 149 vlayout2->addSpacing(5);
149 vlayout2->addWidget(skelCheckBox); 150 vlayout2->addWidget(skelCheckBox);
150 hlayout->addLayout(vlayout1); 151 hlayout->addLayout(vlayout1);
151 hlayout->addLayout(vlayout2); 152 hlayout->addLayout(vlayout2);
152 153
153 myTabWidget->addTab(tabpage,"User Info"); 154 myTabWidget->addTab(tabpage,"User Info");
154} 155}
155 156
156/** 157/**
157 * Creates the second tab containing additional groups for the user. 158 * Creates the second tab containing additional groups for the user.
158 * 159 *
159 */ 160 */
160void UserDialog::setupTab2() { 161void UserDialog::setupTab2() {
161 QWidget *tabpage = new QWidget(myTabWidget,"page2"); 162 QWidget *tabpage = new QWidget(myTabWidget,"page2");
162 QVBoxLayout *layout = new QVBoxLayout(tabpage); 163 QVBoxLayout *layout = new QVBoxLayout(tabpage);
163 layout->setMargin(5); 164 layout->setMargin(5);
164 165
165 // Additional groups 166 // Additional groups
166 groupsListView=new QListView(tabpage,"groups"); 167 groupsListView=new QListView(tabpage,"groups");
167 groupsListView->addColumn("Additional groups"); 168 groupsListView->addColumn("Additional groups");
168 groupsListView->setColumnWidthMode(0,QListView::Maximum); 169 groupsListView->setColumnWidthMode(0,QListView::Maximum);
169 groupsListView->setMultiSelection(false); 170 groupsListView->setMultiSelection(false);
170 groupsListView->setAllColumnsShowFocus(false); 171 groupsListView->setAllColumnsShowFocus(false);
171 172
172 layout->addSpacing(5); 173 layout->addSpacing(5);
173 // Grouplist 174 // Grouplist
174 layout->addWidget(groupsListView); 175 layout->addWidget(groupsListView);
175 176
176 myTabWidget->addTab(tabpage,"User Groups"); 177 myTabWidget->addTab(tabpage,"User Groups");
177} 178}
178 179
179/** 180/**
180 * Static function that creates the userinfo dialog. 181 * Static function that creates the userinfo dialog.
181 * The user will be prompted to add a user. 182 * The user will be prompted to add a user.
182 * 183 *
183 * @param uid This is a suggested available UID. 184 * @param uid This is a suggested available UID.
184 * @param gid This is a suggested available GID. 185 * @param gid This is a suggested available GID.
185 * 186 *
186 * @return <code>true</code> if the user was successfully added, otherwise <code>false</code>. 187 * @return <code>true</code> if the user was successfully added, otherwise <code>false</code>.
187 * 188 *
188 */ 189 */
189bool UserDialog::addUser(int uid, int gid) { 190bool UserDialog::addUser(int uid, int gid) {
191 QCheckListItem *temp;
192 QFile ozTest;
193 int oz=ozTest.exists("/etc/oz_version");
190 UserDialog *adduserDialog=new UserDialog(); 194 UserDialog *adduserDialog=new UserDialog();
191 adduserDialog->setCaption(tr("Add User")); 195 adduserDialog->setCaption(tr("Add User"));
192 adduserDialog->userID=uid;// Set next available UID as default uid. 196 adduserDialog->userID=uid;// Set next available UID as default uid.
193 adduserDialog->groupID=gid;// Set next available GID as default gid. 197 adduserDialog->groupID=gid;// Set next available GID as default gid.
194 // Insert default group into groupComboBox 198 // Insert default group into groupComboBox
195 adduserDialog->groupComboBox->insertItem("<create new group>",0); 199 adduserDialog->groupComboBox->insertItem("<create new group>",0);
196 adduserDialog->uidLineEdit->setText(QString::number(uid)); 200 adduserDialog->uidLineEdit->setText(QString::number(uid));
201 // If we're running on OZ, add new users to some default groups.
202 if(oz) {
203 QListViewItemIterator iter( adduserDialog->groupsListView );
204 for ( ; iter.current(); ++iter ) {
205 temp=(QCheckListItem*)iter.current();
206 if (temp->text()=="video") temp->setOn(true);
207 if (temp->text()=="audio") temp->setOn(true);
208 if (temp->text()=="time") temp->setOn(true);
209 if (temp->text()=="power") temp->setOn(true);
210 if (temp->text()=="input") temp->setOn(true);
211 if (temp->text()=="sharp") temp->setOn(true);
212 if (temp->text()=="tty") temp->setOn(true);
213 }
214 }
197 // Show the dialog! 215 // Show the dialog!
198 if(!(adduserDialog->exec())) return false; 216 if(!(adduserDialog->exec())) return false;
199 if((adduserDialog->groupComboBox->currentItem()!=0)) { 217 if((adduserDialog->groupComboBox->currentItem()!=0)) {
200 accounts->findGroup(adduserDialog->groupComboBox->currentText()); 218 accounts->findGroup(adduserDialog->groupComboBox->currentText());
201 adduserDialog->groupID=accounts->gr_gid; 219 adduserDialog->groupID=accounts->gr_gid;
202 qWarning(QString::number(accounts->gr_gid)); 220 qWarning(QString::number(accounts->gr_gid));
203 } 221 }
204 if(!(accounts->addUser(adduserDialog->loginLineEdit->text(), adduserDialog->passwordLineEdit->text(), 222 if(!(accounts->addUser(adduserDialog->loginLineEdit->text(), adduserDialog->passwordLineEdit->text(),
205 adduserDialog->uidLineEdit->text().toInt(), adduserDialog->groupID, adduserDialog->gecosLineEdit->text(), 223 adduserDialog->uidLineEdit->text().toInt(), adduserDialog->groupID, adduserDialog->gecosLineEdit->text(),
206 QString("/home/")+adduserDialog->loginLineEdit->text() , adduserDialog->shellComboBox->currentText()))) { 224 QString("/home/")+adduserDialog->loginLineEdit->text() , adduserDialog->shellComboBox->currentText()))) {
207 QMessageBox::information(0,"Ooops!","Something went wrong!\nUnable to add user."); 225 QMessageBox::information(0,"Ooops!","Something went wrong!\nUnable to add user.");
208 return false; 226 return false;
209 } 227 }
210 228
211 // Add User to additional groups. 229 // Add User to additional groups.
212 QCheckListItem *temp;
213 QListViewItemIterator it( adduserDialog->groupsListView ); 230 QListViewItemIterator it( adduserDialog->groupsListView );
214 for ( ; it.current(); ++it ) { 231 for ( ; it.current(); ++it ) {
215 temp=(QCheckListItem*)it.current(); 232 temp=(QCheckListItem*)it.current();
216 if (temp->isOn() ) 233 if (temp->isOn() )
217 accounts->addGroupMember(it.current()->text(0),adduserDialog->loginLineEdit->text()); 234 accounts->addGroupMember(it.current()->text(0),adduserDialog->loginLineEdit->text());
218 } 235 }
219 // Copy image to pics/users/ 236 // Copy image to pics/users/
220 if(!(adduserDialog->userImage.isNull())) { 237 if(!(adduserDialog->userImage.isNull())) {
221 QDir d; 238 QDir d;
222 if(!(d.exists("/opt/QtPalmtop/pics/users"))) { 239 if(!(d.exists("/opt/QtPalmtop/pics/users"))) {
223 d.mkdir("/opt/QtPalmtop/pics/users"); 240 d.mkdir("/opt/QtPalmtop/pics/users");
224 } 241 }
225 QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; 242 QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png";
226 // adduserDialog->userImage=adduserDialog->userImage.smoothScale(48,48); 243 // adduserDialog->userImage=adduserDialog->userImage.smoothScale(48,48);
227 adduserDialog->userImage.save(filename,"PNG"); 244 adduserDialog->userImage.save(filename,"PNG");
228 } 245 }
229 return true; 246 return true;
230} 247}
231 248
232/** 249/**
233 * Deletes the user account. 250 * Deletes the user account.
234 * 251 *
235 * @param username User to be deleted. 252 * @param username User to be deleted.
236 * 253 *
237 * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. 254 * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>.
238 * 255 *
239 */ 256 */
240bool UserDialog::delUser(const char *username) { 257bool UserDialog::delUser(const char *username) {
241 if((accounts->findUser(username))) {// Does that user exist? 258 if((accounts->findUser(username))) {// Does that user exist?
242 if(!(accounts->delUser(username))) {// Delete the user. 259 if(!(accounts->delUser(username))) {// Delete the user.
243 QMessageBox::information(0,"Ooops!","Something went wrong\nUnable to delete user: "+QString(username)+"."); 260 QMessageBox::information(0,"Ooops!","Something went wrong\nUnable to delete user: "+QString(username)+".");
244 } 261 }
245 } else { 262 } else {
246 QMessageBox::information(0,"Invalid Username","That username ("+QString(username)+")does not exist."); 263 QMessageBox::information(0,"Invalid Username","That username ("+QString(username)+")does not exist.");
247 return false; 264 return false;
248 } 265 }
249 return true; 266 return true;
250} 267}
251 268
252/** 269/**
253 * This displays a confirmation dialog wether a user should be deleted or not. 270 * This displays a confirmation dialog wether a user should be deleted or not.
254 * (And also deletes the account) 271 * (And also deletes the account)
255 * 272 *
256 * @param username User to be deleted. 273 * @param username User to be deleted.
257 * 274 *
258 * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. 275 * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>.
259 * 276 *
260 */ 277 */
261bool UserDialog::editUser(const char *username) { 278bool UserDialog::editUser(const char *username) {
262 int invalid_group=0; 279 int invalid_group=0;
263 UserDialog *edituserDialog=new UserDialog();// Create Dialog 280 UserDialog *edituserDialog=new UserDialog();// Create Dialog
264 edituserDialog->setCaption(tr("Edit User")); 281 edituserDialog->setCaption(tr("Edit User"));
265 accounts->findUser(username);// Locate user in database and fill variables in 'accounts' object. 282 accounts->findUser(username);// Locate user in database and fill variables in 'accounts' object.
266 if(!(accounts->findGroup(accounts->pw_gid))) {// Locate the user's primary group, and fill group variables in 'accounts' object. 283 if(!(accounts->findGroup(accounts->pw_gid))) {// Locate the user's primary group, and fill group variables in 'accounts' object.
267 invalid_group=1; 284 invalid_group=1;
268 } 285 }
269 // Fill widgets with userinfo. 286 // Fill widgets with userinfo.
270 edituserDialog->loginLineEdit->setText(accounts->pw_name); 287 edituserDialog->loginLineEdit->setText(accounts->pw_name);
271 edituserDialog->uidLineEdit->setText(QString::number(accounts->pw_uid)); 288 edituserDialog->uidLineEdit->setText(QString::number(accounts->pw_uid));
272 edituserDialog->gecosLineEdit->setText(accounts->pw_gecos); 289 edituserDialog->gecosLineEdit->setText(accounts->pw_gecos);
273 // Set password to '........', we will later check if this still is the contents, if not, the password has been changed. 290 // Set password to '........', we will later check if this still is the contents, if not, the password has been changed.
274 edituserDialog->passwordLineEdit->setText("........"); 291 edituserDialog->passwordLineEdit->setText("........");
275 // If this user is not using /bin/sh,/bin/ash or /bin/false as shell, add that entry to the shell-combobox. 292 // If this user is not using /bin/sh,/bin/ash or /bin/false as shell, add that entry to the shell-combobox.
276 if(accounts->pw_shell!="/bin/sh" && accounts->pw_shell!="/bin/ash" && accounts->pw_shell!="/bin/false") { 293 if(accounts->pw_shell!="/bin/sh" && accounts->pw_shell!="/bin/ash" && accounts->pw_shell!="/bin/false") {
277 edituserDialog->shellComboBox->insertItem(accounts->pw_shell,0); 294 edituserDialog->shellComboBox->insertItem(accounts->pw_shell,0);
278 edituserDialog->shellComboBox->setCurrentItem(0); 295 edituserDialog->shellComboBox->setCurrentItem(0);
279 } 296 }
280 // Select the primary group for this user. 297 // Select the primary group for this user.
281 for(int i=0;i<edituserDialog->groupComboBox->count();++i) { 298 for(int i=0;i<edituserDialog->groupComboBox->count();++i) {
282 if(accounts->gr_name==edituserDialog->groupComboBox->text(i)) { 299 if(accounts->gr_name==edituserDialog->groupComboBox->text(i)) {
283 edituserDialog->groupComboBox->setCurrentItem(i); 300 edituserDialog->groupComboBox->setCurrentItem(i);
284 break; 301 break;
285 } 302 }
286 } 303 }
287 if(invalid_group) { 304 if(invalid_group) {
288 edituserDialog->groupComboBox->insertItem("<Undefined group>",0); 305 edituserDialog->groupComboBox->insertItem("<Undefined group>",0);
289 edituserDialog->groupComboBox->setCurrentItem(0); 306 edituserDialog->groupComboBox->setCurrentItem(0);
290 } 307 }
291 // Select the groups in the listview, to which the user belongs. 308 // Select the groups in the listview, to which the user belongs.
292 QCheckListItem *temp; 309 QCheckListItem *temp;
293 QRegExp userRegExp(QString("[:\\s]%1\\s").arg(username)); 310 QRegExp userRegExp(QString("[:\\s]%1\\s").arg(username));
294 QStringList tempList=accounts->groupStringList.grep(userRegExp);// Find all entries in the group database, that the user is a member of. 311 QStringList tempList=accounts->groupStringList.grep(userRegExp);// Find all entries in the group database, that the user is a member of.
295 for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) {// Iterate over all of them. 312 for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) {// Iterate over all of them.
296 QListViewItemIterator lvit( edituserDialog->groupsListView );// Compare to all groups. 313 QListViewItemIterator lvit( edituserDialog->groupsListView );// Compare to all groups.
297 for ( ; lvit.current(); ++lvit ) { 314 for ( ; lvit.current(); ++lvit ) {
298 if(lvit.current()->text(0)==(*it).left((*it).find(":"))) { 315 if(lvit.current()->text(0)==(*it).left((*it).find(":"))) {
299 temp=(QCheckListItem*)lvit.current(); 316 temp=(QCheckListItem*)lvit.current();
300 temp->setOn(true);// If we find a line with that groupname, select it.; 317 temp->setOn(true);// If we find a line with that groupname, select it.;
301 } 318 }
302 } 319 }
303 } 320 }
304 321
305 if(!(edituserDialog->exec())) return false;// SHOW THE DIALOG! 322 if(!(edituserDialog->exec())) return false;// SHOW THE DIALOG!
306 323
307 accounts->findUser(username);// Fill user variables in 'acccounts' object. 324 accounts->findUser(username);// Fill user variables in 'acccounts' object.
308 accounts->pw_name=edituserDialog->loginLineEdit->text(); 325 accounts->pw_name=edituserDialog->loginLineEdit->text();
309 // Has the password been changed ? Make a new "crypt":ed password. 326 // Has the password been changed ? Make a new "crypt":ed password.
310 if(edituserDialog->passwordLineEdit->text()!="........") accounts->pw_passwd=crypt(edituserDialog->passwordLineEdit->text(), accounts->crypt_make_salt()); 327 if(edituserDialog->passwordLineEdit->text()!="........") accounts->pw_passwd=crypt(edituserDialog->passwordLineEdit->text(), accounts->crypt_make_salt());
311 328
312 // Set all variables in accounts object, that will be used when calling 'updateUser()' 329 // Set all variables in accounts object, that will be used when calling 'updateUser()'
313 accounts->pw_uid=edituserDialog->uidLineEdit->text().toInt(); 330 accounts->pw_uid=edituserDialog->uidLineEdit->text().toInt();
314 if(accounts->findGroup(edituserDialog->groupComboBox->currentText())) {// Fill all group variables in 'accounts' object. 331 if(accounts->findGroup(edituserDialog->groupComboBox->currentText())) {// Fill all group variables in 'accounts' object.
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. 332 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 } 333 }
317 accounts->pw_gecos=edituserDialog->gecosLineEdit->text(); 334 accounts->pw_gecos=edituserDialog->gecosLineEdit->text();
318 accounts->pw_shell=edituserDialog->shellComboBox->currentText(); 335 accounts->pw_shell=edituserDialog->shellComboBox->currentText();
319 // Update userinfo, using the information stored in the user variables stored in the accounts object. 336 // Update userinfo, using the information stored in the user variables stored in the accounts object.
320 accounts->updateUser(username); 337 accounts->updateUser(username);
321 338
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.) 339 // Remove user from all groups he/she is a member of. (could be done in a better way I guess, this was simple though.)
323 for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) { 340 for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) {
324 accounts->delGroupMember((*it).left((*it).find(":")),username); 341 accounts->delGroupMember((*it).left((*it).find(":")),username);
325 } 342 }
326 343
327 // Add User to additional groups that he/she is a member of. 344 // Add User to additional groups that he/she is a member of.
328 QListViewItemIterator it( edituserDialog->groupsListView ); 345 QListViewItemIterator it( edituserDialog->groupsListView );
329 for ( ; it.current(); ++it ) { 346 for ( ; it.current(); ++it ) {
330 temp=(QCheckListItem*)it.current(); 347 temp=(QCheckListItem*)it.current();
331 if ( temp->isOn() ) 348 if ( temp->isOn() )
332 accounts->addGroupMember(it.current()->text(0),edituserDialog->loginLineEdit->text()); 349 accounts->addGroupMember(it.current()->text(0),edituserDialog->loginLineEdit->text());
333 } 350 }
334 351
335 // Copy image to pics/users/ 352 // Copy image to pics/users/
336 if(!(edituserDialog->userImage.isNull())) { 353 if(!(edituserDialog->userImage.isNull())) {
337 QDir d; 354 QDir d;
338 if(!(d.exists("/opt/QtPalmtop/pics/users"))) { 355 if(!(d.exists("/opt/QtPalmtop/pics/users"))) {
339 d.mkdir("/opt/QtPalmtop/pics/users"); 356 d.mkdir("/opt/QtPalmtop/pics/users");
340 } 357 }
341 QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; 358 QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png";
342 // edituserDialog->userImage=edituserDialog->userImage.smoothScale(48,48); 359 // edituserDialog->userImage=edituserDialog->userImage.smoothScale(48,48);
343 edituserDialog->userImage.save(filename,"PNG"); 360 edituserDialog->userImage.save(filename,"PNG");
344 } 361 }
345 return true; 362 return true;
346} 363}
347 364
348/** 365/**
349 * "OK" has been clicked. Verify some information before closing the dialog. 366 * "OK" has been clicked. Verify some information before closing the dialog.
350 * 367 *
351 */ 368 */
352void UserDialog::accept() { 369void UserDialog::accept() {
353 // Add checking... valid username? username taken? 370 // Add checking... valid username? username taken?
354 if(loginLineEdit->text().isEmpty()) { 371 if(loginLineEdit->text().isEmpty()) {
355 QMessageBox::information(0,"Empty Login","Please enter a login."); 372 QMessageBox::information(0,"Empty Login","Please enter a login.");
356 return; 373 return;
357 } 374 }
358 QDialog::accept(); 375 QDialog::accept();
359} 376}
360 377
361/** 378/**
362 * This slot is called when the usericon is clicked, this loads (should) the iconselector. 379 * This slot is called when the usericon is clicked, this loads (should) the iconselector.
363 * 380 *
364 */ 381 */
365void UserDialog::clickedPicture() { 382void UserDialog::clickedPicture() {
366 QString filename=OFileDialog::getOpenFileName(OFileSelector::EXTENDED,"/opt/QtPalmtop/pics"); 383 QString filename=OFileDialog::getOpenFileName(OFileSelector::EXTENDED,"/opt/QtPalmtop/pics");
367 if(!(filename.isEmpty())) { 384 if(!(filename.isEmpty())) {
368 userImage.reset(); 385 userImage.reset();
369 if(!(userImage.load(filename))) { 386 if(!(userImage.load(filename))) {
370 QMessageBox::information(0,"Sorry!","That icon could not be loaded.\nLoading failed on: "+filename); 387 QMessageBox::information(0,"Sorry!","That icon could not be loaded.\nLoading failed on: "+filename);
371 } else { 388 } else {
372 // userImage=userImage.smoothScale(48,48); 389 // userImage=userImage.smoothScale(48,48);
373 QPixmap *picture; 390 QPixmap *picture;
374 picture=(QPixmap *)picturePushButton->pixmap(); 391 picture=(QPixmap *)picturePushButton->pixmap();
375 picture->convertFromImage(userImage,0); 392 picture->convertFromImage(userImage,0);
376 picturePushButton->update(); 393 picturePushButton->update();
377 } 394 }
378 } 395 }
379} 396}