summaryrefslogtreecommitdiff
path: root/noncore/settings/usermanager/userdialog.cpp
Unidiff
Diffstat (limited to 'noncore/settings/usermanager/userdialog.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/usermanager/userdialog.cpp149
1 files changed, 100 insertions, 49 deletions
diff --git a/noncore/settings/usermanager/userdialog.cpp b/noncore/settings/usermanager/userdialog.cpp
index d87a005..08de352 100644
--- a/noncore/settings/usermanager/userdialog.cpp
+++ b/noncore/settings/usermanager/userdialog.cpp
@@ -5,65 +5,74 @@
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#include "passwd.h"
12
13/* OPIE */
14#include <opie/odevice.h>
15#include <qpe/qpeapplication.h>
11 16
17/* QT */
12#include <qlayout.h> 18#include <qlayout.h>
13#include <qlabel.h> 19#include <qlabel.h>
14#include <qmessagebox.h> 20#include <qmessagebox.h>
15#include <qfile.h> 21#include <qfile.h>
16 22
23/* STD */
17#include <sys/types.h> 24#include <sys/types.h>
18#include <sys/wait.h> 25#include <sys/wait.h>
19#include <unistd.h> 26#include <unistd.h>
20#include <signal.h> 27#include <signal.h>
21 28
22#include "passwd.h"
23 29
24#include <opie/odevice.h>
25using namespace Opie; 30using namespace Opie;
26 31
27 32
28/** 33/**
29 * UserDialog constructor. Setup the dialog, fill the groupComboBox & groupsListView with all groups. 34 * UserDialog constructor. Setup the dialog, fill the groupComboBox & groupsListView with all groups.
30 * 35 *
31 */ 36 */
32UserDialog::UserDialog(int viewmode, QWidget* parent, const char* name, bool modal, WFlags fl) : QDialog(parent, name, modal, fl) { 37UserDialog::UserDialog(int viewmode, QWidget* parent, const char* name, bool modal, WFlags fl) : QDialog(parent, name, modal, fl)
38{
33 vm=viewmode; 39 vm=viewmode;
34 QVBoxLayout *layout = new QVBoxLayout(this); 40 QVBoxLayout *layout = new QVBoxLayout(this);
35 myTabWidget=new QTabWidget(this,"User Tab Widget"); 41 myTabWidget=new QTabWidget(this,"User Tab Widget");
36 layout->addWidget(myTabWidget); 42 layout->addWidget(myTabWidget);
37 setupTab1(); 43 setupTab1();
38 setupTab2(); 44 setupTab2();
39 45
40 accounts->groupStringList.sort(); 46 accounts->groupStringList.sort();
41 // And also fill the listview & the combobox with all available groups. 47 // And also fill the listview & the combobox with all available groups.
42 for( QStringList::Iterator it = accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) { 48 for( QStringList::Iterator it = accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it)
49 {
43 accounts->splitGroupEntry(*it); 50 accounts->splitGroupEntry(*it);
44 if(accounts->gr_name.find(QRegExp("^#"),0)) {// Skip commented lines. 51 if(accounts->gr_name.find(QRegExp("^#"),0))
52 {// Skip commented lines.
45 new QCheckListItem(groupsListView,accounts->gr_name,QCheckListItem::CheckBox); 53 new QCheckListItem(groupsListView,accounts->gr_name,QCheckListItem::CheckBox);
46 groupComboBox->insertItem(accounts->gr_name); 54 groupComboBox->insertItem(accounts->gr_name);
47 } 55 }
48 } 56 }
49 showMaximized(); 57 QPEApplication::showDialog( this );
50} 58}
51 59
52/** 60/**
53 * Empty destructor. 61 * Empty destructor.
54 * 62 *
55 */ 63 */
56UserDialog::~UserDialog() { 64UserDialog::~UserDialog()
57} 65{}
58 66
59/** 67/**
60 * Creates the first tab, all userinfo is here. 68 * Creates the first tab, all userinfo is here.
61 * 69 *
62 */ 70 */
63void UserDialog::setupTab1() { 71void UserDialog::setupTab1()
72{
64 QPixmap mypixmap; 73 QPixmap mypixmap;
65 QWidget *tabpage = new QWidget(myTabWidget,"page1"); 74 QWidget *tabpage = new QWidget(myTabWidget,"page1");
66 QVBoxLayout *layout = new QVBoxLayout(tabpage); 75 QVBoxLayout *layout = new QVBoxLayout(tabpage);
67 layout->setMargin(5); 76 layout->setMargin(5);
68 77
69 // Picture 78 // Picture
@@ -106,13 +115,14 @@ void UserDialog::setupTab1() {
106 115
107 // Primary Group 116 // Primary Group
108 QLabel *groupLabel=new QLabel(tabpage,"group"); 117 QLabel *groupLabel=new QLabel(tabpage,"group");
109 groupLabel->setText("Primary group: "); 118 groupLabel->setText("Primary group: ");
110 groupComboBox=new QComboBox(tabpage,"PrimaryGroup"); 119 groupComboBox=new QComboBox(tabpage,"PrimaryGroup");
111 120
112 if(vm==VIEWMODE_NEW) { 121 if(vm==VIEWMODE_NEW)
122 {
113 // Copy /etc/skel 123 // Copy /etc/skel
114 skelLabel=new QLabel(tabpage,"skel"); 124 skelLabel=new QLabel(tabpage,"skel");
115 skelLabel->setText("Copy /etc/skel: "); 125 skelLabel->setText("Copy /etc/skel: ");
116 skelCheckBox=new QCheckBox(tabpage); 126 skelCheckBox=new QCheckBox(tabpage);
117 skelCheckBox->setChecked(true); 127 skelCheckBox->setChecked(true);
118 } 128 }
@@ -133,13 +143,14 @@ void UserDialog::setupTab1() {
133 vlayout1->addSpacing(5); 143 vlayout1->addSpacing(5);
134 vlayout1->addWidget(passwordLabel); 144 vlayout1->addWidget(passwordLabel);
135 vlayout1->addSpacing(5); 145 vlayout1->addSpacing(5);
136 vlayout1->addWidget(shellLabel); 146 vlayout1->addWidget(shellLabel);
137 vlayout1->addSpacing(5); 147 vlayout1->addSpacing(5);
138 vlayout1->addWidget(groupLabel); 148 vlayout1->addWidget(groupLabel);
139 if(vm==VIEWMODE_NEW) { 149 if(vm==VIEWMODE_NEW)
150 {
140 vlayout1->addSpacing(5); 151 vlayout1->addSpacing(5);
141 vlayout1->addWidget(skelLabel); 152 vlayout1->addWidget(skelLabel);
142 } 153 }
143 // Second column, data 154 // Second column, data
144 vlayout2->addWidget(loginLineEdit); 155 vlayout2->addWidget(loginLineEdit);
145 vlayout2->addSpacing(5); 156 vlayout2->addSpacing(5);
@@ -149,13 +160,14 @@ void UserDialog::setupTab1() {
149 vlayout2->addSpacing(5); 160 vlayout2->addSpacing(5);
150 vlayout2->addWidget(passwordLineEdit); 161 vlayout2->addWidget(passwordLineEdit);
151 vlayout2->addSpacing(5); 162 vlayout2->addSpacing(5);
152 vlayout2->addWidget(shellComboBox); 163 vlayout2->addWidget(shellComboBox);
153 vlayout2->addSpacing(5); 164 vlayout2->addSpacing(5);
154 vlayout2->addWidget(groupComboBox); 165 vlayout2->addWidget(groupComboBox);
155 if(vm==VIEWMODE_NEW) { 166 if(vm==VIEWMODE_NEW)
167 {
156 vlayout2->addSpacing(5); 168 vlayout2->addSpacing(5);
157 vlayout2->addWidget(skelCheckBox); 169 vlayout2->addWidget(skelCheckBox);
158 } 170 }
159 hlayout->addLayout(vlayout1); 171 hlayout->addLayout(vlayout1);
160 hlayout->addLayout(vlayout2); 172 hlayout->addLayout(vlayout2);
161 173
@@ -163,13 +175,14 @@ void UserDialog::setupTab1() {
163} 175}
164 176
165/** 177/**
166 * Creates the second tab containing additional groups for the user. 178 * Creates the second tab containing additional groups for the user.
167 * 179 *
168 */ 180 */
169void UserDialog::setupTab2() { 181void UserDialog::setupTab2()
182{
170 QWidget *tabpage = new QWidget(myTabWidget,"page2"); 183 QWidget *tabpage = new QWidget(myTabWidget,"page2");
171 QVBoxLayout *layout = new QVBoxLayout(tabpage); 184 QVBoxLayout *layout = new QVBoxLayout(tabpage);
172 layout->setMargin(5); 185 layout->setMargin(5);
173 186
174 // Additional groups 187 // Additional groups
175 groupsListView=new QListView(tabpage,"groups"); 188 groupsListView=new QListView(tabpage,"groups");
@@ -192,13 +205,14 @@ void UserDialog::setupTab2() {
192 * @param uid This is a suggested available UID. 205 * @param uid This is a suggested available UID.
193 * @param gid This is a suggested available GID. 206 * @param gid This is a suggested available GID.
194 * 207 *
195 * @return <code>true</code> if the user was successfully added, otherwise <code>false</code>. 208 * @return <code>true</code> if the user was successfully added, otherwise <code>false</code>.
196 * 209 *
197 */ 210 */
198bool UserDialog::addUser(int uid, int gid) { 211bool UserDialog::addUser(int uid, int gid)
212{
199 QCheckListItem *temp; 213 QCheckListItem *temp;
200 QFile ozTest; 214 QFile ozTest;
201 int oz=false; 215 int oz=false;
202 if(ODevice::inst()->system()==System_OpenZaurus) oz=true; 216 if(ODevice::inst()->system()==System_OpenZaurus) oz=true;
203 // viewmode is a workaround for a bug in qte-2.3.4 that gives bus error on manipulating adduserDialog's widgets here. 217 // viewmode is a workaround for a bug in qte-2.3.4 that gives bus error on manipulating adduserDialog's widgets here.
204 UserDialog *adduserDialog=new UserDialog(VIEWMODE_NEW); 218 UserDialog *adduserDialog=new UserDialog(VIEWMODE_NEW);
@@ -206,60 +220,68 @@ bool UserDialog::addUser(int uid, int gid) {
206 adduserDialog->userID=uid;// Set next available UID as default uid. 220 adduserDialog->userID=uid;// Set next available UID as default uid.
207 adduserDialog->groupID=gid;// Set next available GID as default gid. 221 adduserDialog->groupID=gid;// Set next available GID as default gid.
208 // Insert default group into groupComboBox 222 // Insert default group into groupComboBox
209 adduserDialog->groupComboBox->insertItem("<create new group>",0); 223 adduserDialog->groupComboBox->insertItem("<create new group>",0);
210 adduserDialog->uidLineEdit->setText(QString::number(uid)); 224 adduserDialog->uidLineEdit->setText(QString::number(uid));
211 // If we're running on OZ, add new users to some default groups. 225 // If we're running on OZ, add new users to some default groups.
212 if(oz) { 226 if(oz)
227 {
213 QListViewItemIterator iter( adduserDialog->groupsListView ); 228 QListViewItemIterator iter( adduserDialog->groupsListView );
214 for ( ; iter.current(); ++iter ) { 229 for ( ; iter.current(); ++iter )
230 {
215 temp=(QCheckListItem*)iter.current(); 231 temp=(QCheckListItem*)iter.current();
216 if (temp->text()=="video") temp->setOn(true); 232 if (temp->text()=="video") temp->setOn(true);
217 if (temp->text()=="audio") temp->setOn(true); 233 if (temp->text()=="audio") temp->setOn(true);
218 if (temp->text()=="time") temp->setOn(true); 234 if (temp->text()=="time") temp->setOn(true);
219 if (temp->text()=="power") temp->setOn(true); 235 if (temp->text()=="power") temp->setOn(true);
220 if (temp->text()=="input") temp->setOn(true); 236 if (temp->text()=="input") temp->setOn(true);
221 if (temp->text()=="sharp") temp->setOn(true); 237 if (temp->text()=="sharp") temp->setOn(true);
222 if (temp->text()=="tty") temp->setOn(true); 238 if (temp->text()=="tty") temp->setOn(true);
223 } 239 }
224 } 240 }
225 // Show the dialog! 241 // Show the dialog!
226 if(!(adduserDialog->exec())) return false; 242 if(!(adduserDialog->exec())) return false;
227 if((adduserDialog->groupComboBox->currentItem()!=0)) { 243 if((adduserDialog->groupComboBox->currentItem()!=0))
244 {
228 accounts->findGroup(adduserDialog->groupComboBox->currentText()); 245 accounts->findGroup(adduserDialog->groupComboBox->currentText());
229 adduserDialog->groupID=accounts->gr_gid; 246 adduserDialog->groupID=accounts->gr_gid;
230 qWarning(QString::number(accounts->gr_gid)); 247 qWarning(QString::number(accounts->gr_gid));
231 } 248 }
232 if(!(accounts->addUser(adduserDialog->loginLineEdit->text(), adduserDialog->passwordLineEdit->text(), 249 if(!(accounts->addUser(adduserDialog->loginLineEdit->text(), adduserDialog->passwordLineEdit->text(),
233 adduserDialog->uidLineEdit->text().toInt(), adduserDialog->groupID, adduserDialog->gecosLineEdit->text(), 250 adduserDialog->uidLineEdit->text().toInt(), adduserDialog->groupID, adduserDialog->gecosLineEdit->text(),
234 QString("/home/")+adduserDialog->loginLineEdit->text() , adduserDialog->shellComboBox->currentText()))) { 251 QString("/home/")+adduserDialog->loginLineEdit->text() , adduserDialog->shellComboBox->currentText())))
252 {
235 QMessageBox::information(0,"Ooops!","Something went wrong!\nUnable to add user."); 253 QMessageBox::information(0,"Ooops!","Something went wrong!\nUnable to add user.");
236 return false; 254 return false;
237 } 255 }
238 256
239 // Add User to additional groups. 257 // Add User to additional groups.
240 QListViewItemIterator it( adduserDialog->groupsListView ); 258 QListViewItemIterator it( adduserDialog->groupsListView );
241 for ( ; it.current(); ++it ) { 259 for ( ; it.current(); ++it )
260 {
242 temp=(QCheckListItem*)it.current(); 261 temp=(QCheckListItem*)it.current();
243 if (temp->isOn() ) 262 if (temp->isOn() )
244 accounts->addGroupMember(it.current()->text(0),adduserDialog->loginLineEdit->text()); 263 accounts->addGroupMember(it.current()->text(0),adduserDialog->loginLineEdit->text());
245 } 264 }
246 // Copy image to pics/users/ 265 // Copy image to pics/users/
247 if(!(adduserDialog->userImage.isNull())) { 266 if(!(adduserDialog->userImage.isNull()))
267 {
248 QDir d; 268 QDir d;
249 if(!(d.exists("/opt/QtPalmtop/pics/users"))) { 269 if(!(d.exists("/opt/QtPalmtop/pics/users")))
270 {
250 d.mkdir("/opt/QtPalmtop/pics/users"); 271 d.mkdir("/opt/QtPalmtop/pics/users");
251 } 272 }
252 QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; 273 QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png";
253 // adduserDialog->userImage=adduserDialog->userImage.smoothScale(48,48); 274 // adduserDialog->userImage=adduserDialog->userImage.smoothScale(48,48);
254 adduserDialog->userImage.save(filename,"PNG"); 275 adduserDialog->userImage.save(filename,"PNG");
255 } 276 }
256 277
257 // Should we copy the skeleton homedirectory /etc/skel to the user's homedirectory? 278 // Should we copy the skeleton homedirectory /etc/skel to the user's homedirectory?
258 accounts->findUser(adduserDialog->loginLineEdit->text()); 279 accounts->findUser(adduserDialog->loginLineEdit->text());
259 if(adduserDialog->skelCheckBox->isChecked()) { 280 if(adduserDialog->skelCheckBox->isChecked())
281 {
260 QString command_cp; 282 QString command_cp;
261 QString command_chown; 283 QString command_chown;
262 command_cp.sprintf("cp -a /etc/skel/* %s/",accounts->pw_dir.latin1()); 284 command_cp.sprintf("cp -a /etc/skel/* %s/",accounts->pw_dir.latin1());
263 system(command_cp); 285 system(command_cp);
264 286
265 command_cp.sprintf("cp -a /etc/skel/.[!.]* %s/",accounts->pw_dir.latin1());// Bug in busybox, ".*" includes parent directory, does this work as a workaround? 287 command_cp.sprintf("cp -a /etc/skel/.[!.]* %s/",accounts->pw_dir.latin1());// Bug in busybox, ".*" includes parent directory, does this work as a workaround?
@@ -277,18 +299,23 @@ bool UserDialog::addUser(int uid, int gid) {
277 * 299 *
278 * @param username User to be deleted. 300 * @param username User to be deleted.
279 * 301 *
280 * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. 302 * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>.
281 * 303 *
282 */ 304 */
283bool UserDialog::delUser(const char *username) { 305bool UserDialog::delUser(const char *username)
284 if((accounts->findUser(username))) {// Does that user exist? 306{
285 if(!(accounts->delUser(username))) {// Delete the user. 307 if((accounts->findUser(username)))
308 {// Does that user exist?
309 if(!(accounts->delUser(username)))
310 {// Delete the user.
286 QMessageBox::information(0,"Ooops!","Something went wrong\nUnable to delete user: "+QString(username)+"."); 311 QMessageBox::information(0,"Ooops!","Something went wrong\nUnable to delete user: "+QString(username)+".");
287 } 312 }
288 } else { 313 }
314 else
315 {
289 QMessageBox::information(0,"Invalid Username","That username ("+QString(username)+")does not exist."); 316 QMessageBox::information(0,"Invalid Username","That username ("+QString(username)+")does not exist.");
290 return false; 317 return false;
291 } 318 }
292 return true; 319 return true;
293} 320}
294 321
@@ -298,66 +325,78 @@ bool UserDialog::delUser(const char *username) {
298 * 325 *
299 * @param username User to be deleted. 326 * @param username User to be deleted.
300 * 327 *
301 * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. 328 * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>.
302 * 329 *
303 */ 330 */
304bool UserDialog::editUser(const char *username) { 331bool UserDialog::editUser(const char *username)
332{
305 int invalid_group=0; 333 int invalid_group=0;
306 // viewmode is a workaround for a bug in qte-2.3.4 that gives bus error on manipulating edituserDialog's widgets here. 334 // viewmode is a workaround for a bug in qte-2.3.4 that gives bus error on manipulating edituserDialog's widgets here.
307 UserDialog *edituserDialog=new UserDialog(VIEWMODE_EDIT);// Create Dialog 335 UserDialog *edituserDialog=new UserDialog(VIEWMODE_EDIT);// Create Dialog
308 edituserDialog->setCaption(tr("Edit User")); 336 edituserDialog->setCaption(tr("Edit User"));
309 accounts->findUser(username);// Locate user in database and fill variables in 'accounts' object. 337 accounts->findUser(username);// Locate user in database and fill variables in 'accounts' object.
310 if(!(accounts->findGroup(accounts->pw_gid))) {// Locate the user's primary group, and fill group variables in 'accounts' object. 338 if(!(accounts->findGroup(accounts->pw_gid)))
339 {// Locate the user's primary group, and fill group variables in 'accounts' object.
311 invalid_group=1; 340 invalid_group=1;
312 } 341 }
313 // Fill widgets with userinfo. 342 // Fill widgets with userinfo.
314 edituserDialog->loginLineEdit->setText(accounts->pw_name); 343 edituserDialog->loginLineEdit->setText(accounts->pw_name);
315 edituserDialog->uidLineEdit->setText(QString::number(accounts->pw_uid)); 344 edituserDialog->uidLineEdit->setText(QString::number(accounts->pw_uid));
316 edituserDialog->gecosLineEdit->setText(accounts->pw_gecos); 345 edituserDialog->gecosLineEdit->setText(accounts->pw_gecos);
317 // Set password to '........', we will later check if this still is the contents, if not, the password has been changed. 346 // Set password to '........', we will later check if this still is the contents, if not, the password has been changed.
318 edituserDialog->passwordLineEdit->setText("........"); 347 edituserDialog->passwordLineEdit->setText("........");
319 // If this user is not using /bin/sh,/bin/ash or /bin/false as shell, add that entry to the shell-combobox. 348 // If this user is not using /bin/sh,/bin/ash or /bin/false as shell, add that entry to the shell-combobox.
320 if(accounts->pw_shell!="/bin/sh" && accounts->pw_shell!="/bin/ash" && accounts->pw_shell!="/bin/false") { 349 if(accounts->pw_shell!="/bin/sh" && accounts->pw_shell!="/bin/ash" && accounts->pw_shell!="/bin/false")
350 {
321 edituserDialog->shellComboBox->insertItem(accounts->pw_shell,0); 351 edituserDialog->shellComboBox->insertItem(accounts->pw_shell,0);
322 edituserDialog->shellComboBox->setCurrentItem(0); 352 edituserDialog->shellComboBox->setCurrentItem(0);
323 } 353 }
324 // Select the primary group for this user. 354 // Select the primary group for this user.
325 for(int i=0;i<edituserDialog->groupComboBox->count();++i) { 355 for(int i=0;i<edituserDialog->groupComboBox->count();++i)
326 if(accounts->gr_name==edituserDialog->groupComboBox->text(i)) { 356 {
357 if(accounts->gr_name==edituserDialog->groupComboBox->text(i))
358 {
327 edituserDialog->groupComboBox->setCurrentItem(i); 359 edituserDialog->groupComboBox->setCurrentItem(i);
328 break; 360 break;
329 } 361 }
330 } 362 }
331 if(invalid_group) { 363 if(invalid_group)
364 {
332 edituserDialog->groupComboBox->insertItem("<Undefined group>",0); 365 edituserDialog->groupComboBox->insertItem("<Undefined group>",0);
333 edituserDialog->groupComboBox->setCurrentItem(0); 366 edituserDialog->groupComboBox->setCurrentItem(0);
334 } 367 }
335 368
336 // Select the groups in the listview, to which the user belongs. 369 // Select the groups in the listview, to which the user belongs.
337 QCheckListItem *temp; 370 QCheckListItem *temp;
338 // BAH!!! QRegExp in qt2 sucks... or maybe I do... can't figure out how to check for EITHER end of input ($) OR a comma, so here we do two different QRegExps instead. 371 // BAH!!! QRegExp in qt2 sucks... or maybe I do... can't figure out how to check for EITHER end of input ($) OR a comma, so here we do two different QRegExps instead.
339 QRegExp userRegExp(QString("[:,]%1$").arg(username));// The end of line variant. 372 QRegExp userRegExp(QString("[:,]%1$").arg(username));// The end of line variant.
340 QStringList tempList=accounts->groupStringList.grep(userRegExp);// Find all entries in the group database, that the user is a member of. 373 QStringList tempList=accounts->groupStringList.grep(userRegExp);// Find all entries in the group database, that the user is a member of.
341 for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) {// Iterate over all of them. 374 for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it)
375 {// Iterate over all of them.
342 qWarning(*it); 376 qWarning(*it);
343 QListViewItemIterator lvit( edituserDialog->groupsListView );// Compare to all groups. 377 QListViewItemIterator lvit( edituserDialog->groupsListView );// Compare to all groups.
344 for ( ; lvit.current(); ++lvit ) { 378 for ( ; lvit.current(); ++lvit )
345 if(lvit.current()->text(0)==(*it).left((*it).find(":"))) { 379 {
380 if(lvit.current()->text(0)==(*it).left((*it).find(":")))
381 {
346 temp=(QCheckListItem*)lvit.current(); 382 temp=(QCheckListItem*)lvit.current();
347 temp->setOn(true);// If we find a line with that groupname, select it.; 383 temp->setOn(true);// If we find a line with that groupname, select it.;
348 } 384 }
349 } 385 }
350 } 386 }
351 userRegExp=QRegExp(QString("[:,]%1,").arg(username));// And the other one. (not end of line.) 387 userRegExp=QRegExp(QString("[:,]%1,").arg(username));// And the other one. (not end of line.)
352 tempList=accounts->groupStringList.grep(userRegExp);// Find all entries in the group database, that the user is a member of. 388 tempList=accounts->groupStringList.grep(userRegExp);// Find all entries in the group database, that the user is a member of.
353 for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) {// Iterate over all of them. 389 for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it)
390 {// Iterate over all of them.
354 qWarning(*it); 391 qWarning(*it);
355 QListViewItemIterator lvit( edituserDialog->groupsListView );// Compare to all groups. 392 QListViewItemIterator lvit( edituserDialog->groupsListView );// Compare to all groups.
356 for ( ; lvit.current(); ++lvit ) { 393 for ( ; lvit.current(); ++lvit )
357 if(lvit.current()->text(0)==(*it).left((*it).find(":"))) { 394 {
395 if(lvit.current()->text(0)==(*it).left((*it).find(":")))
396 {
358 temp=(QCheckListItem*)lvit.current(); 397 temp=(QCheckListItem*)lvit.current();
359 temp->setOn(true);// If we find a line with that groupname, select it.; 398 temp->setOn(true);// If we find a line with that groupname, select it.;
360 } 399 }
361 } 400 }
362 } 401 }
363 402
@@ -367,37 +406,42 @@ bool UserDialog::editUser(const char *username) {
367 accounts->pw_name=edituserDialog->loginLineEdit->text(); 406 accounts->pw_name=edituserDialog->loginLineEdit->text();
368 // Has the password been changed ? Make a new "crypt":ed password. 407 // Has the password been changed ? Make a new "crypt":ed password.
369 if(edituserDialog->passwordLineEdit->text()!="........") accounts->pw_passwd=crypt(edituserDialog->passwordLineEdit->text(), accounts->crypt_make_salt()); 408 if(edituserDialog->passwordLineEdit->text()!="........") accounts->pw_passwd=crypt(edituserDialog->passwordLineEdit->text(), accounts->crypt_make_salt());
370 409
371 // Set all variables in accounts object, that will be used when calling 'updateUser()' 410 // Set all variables in accounts object, that will be used when calling 'updateUser()'
372 accounts->pw_uid=edituserDialog->uidLineEdit->text().toInt(); 411 accounts->pw_uid=edituserDialog->uidLineEdit->text().toInt();
373 if(accounts->findGroup(edituserDialog->groupComboBox->currentText())) {// Fill all group variables in 'accounts' object. 412 if(accounts->findGroup(edituserDialog->groupComboBox->currentText()))
413 {// Fill all group variables in 'accounts' object.
374 accounts->pw_gid=accounts->gr_gid;// Only do this if the group is a valid group (ie. "<Undefined group>"), otherwise keep the old group. 414 accounts->pw_gid=accounts->gr_gid;// Only do this if the group is a valid group (ie. "<Undefined group>"), otherwise keep the old group.
375 } 415 }
376 accounts->pw_gecos=edituserDialog->gecosLineEdit->text(); 416 accounts->pw_gecos=edituserDialog->gecosLineEdit->text();
377 accounts->pw_shell=edituserDialog->shellComboBox->currentText(); 417 accounts->pw_shell=edituserDialog->shellComboBox->currentText();
378 // Update userinfo, using the information stored in the user variables stored in the accounts object. 418 // Update userinfo, using the information stored in the user variables stored in the accounts object.
379 accounts->updateUser(username); 419 accounts->updateUser(username);
380 420
381 // Remove user from all groups he/she is a member of. (could be done in a better way I guess, this was simple though.) 421 // Remove user from all groups he/she is a member of. (could be done in a better way I guess, this was simple though.)
382 for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) { 422 for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it)
423 {
383 accounts->delGroupMember((*it).left((*it).find(":")),username); 424 accounts->delGroupMember((*it).left((*it).find(":")),username);
384 } 425 }
385 426
386 // Add User to additional groups that he/she is a member of. 427 // Add User to additional groups that he/she is a member of.
387 QListViewItemIterator it( edituserDialog->groupsListView ); 428 QListViewItemIterator it( edituserDialog->groupsListView );
388 for ( ; it.current(); ++it ) { 429 for ( ; it.current(); ++it )
430 {
389 temp=(QCheckListItem*)it.current(); 431 temp=(QCheckListItem*)it.current();
390 if ( temp->isOn() ) 432 if ( temp->isOn() )
391 accounts->addGroupMember(it.current()->text(0),edituserDialog->loginLineEdit->text()); 433 accounts->addGroupMember(it.current()->text(0),edituserDialog->loginLineEdit->text());
392 } 434 }
393 435
394 // Copy image to pics/users/ 436 // Copy image to pics/users/
395 if(!(edituserDialog->userImage.isNull())) { 437 if(!(edituserDialog->userImage.isNull()))
438 {
396 QDir d; 439 QDir d;
397 if(!(d.exists("/opt/QtPalmtop/pics/users"))) { 440 if(!(d.exists("/opt/QtPalmtop/pics/users")))
441 {
398 d.mkdir("/opt/QtPalmtop/pics/users"); 442 d.mkdir("/opt/QtPalmtop/pics/users");
399 } 443 }
400 QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; 444 QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png";
401 // edituserDialog->userImage=edituserDialog->userImage.smoothScale(48,48); 445 // edituserDialog->userImage=edituserDialog->userImage.smoothScale(48,48);
402 edituserDialog->userImage.save(filename,"PNG"); 446 edituserDialog->userImage.save(filename,"PNG");
403 } 447 }
@@ -405,32 +449,39 @@ bool UserDialog::editUser(const char *username) {
405} 449}
406 450
407/** 451/**
408 * "OK" has been clicked. Verify some information before closing the dialog. 452 * "OK" has been clicked. Verify some information before closing the dialog.
409 * 453 *
410 */ 454 */
411void UserDialog::accept() { 455void UserDialog::accept()
456{
412 // Add checking... valid username? username taken? 457 // Add checking... valid username? username taken?
413 if(loginLineEdit->text().isEmpty()) { 458 if(loginLineEdit->text().isEmpty())
459 {
414 QMessageBox::information(0,"Empty Login","Please enter a login."); 460 QMessageBox::information(0,"Empty Login","Please enter a login.");
415 return; 461 return;
416 } 462 }
417 QDialog::accept(); 463 QDialog::accept();
418} 464}
419 465
420/** 466/**
421 * This slot is called when the usericon is clicked, this loads (should) the iconselector. 467 * This slot is called when the usericon is clicked, this loads (should) the iconselector.
422 * 468 *
423 */ 469 */
424void UserDialog::clickedPicture() { 470void UserDialog::clickedPicture()
471{
425 QString filename=OFileDialog::getOpenFileName(OFileSelector::EXTENDED, QString::null); 472 QString filename=OFileDialog::getOpenFileName(OFileSelector::EXTENDED, QString::null);
426 if(!(filename.isEmpty())) { 473 if(!(filename.isEmpty()))
474 {
427 userImage.reset(); 475 userImage.reset();
428 if(!(userImage.load(filename))) { 476 if(!(userImage.load(filename)))
477 {
429 QMessageBox::information(0,"Sorry!","That icon could not be loaded.\nLoading failed on: "+filename); 478 QMessageBox::information(0,"Sorry!","That icon could not be loaded.\nLoading failed on: "+filename);
430 } else { 479 }
480 else
481 {
431 // userImage=userImage.smoothScale(48,48); 482 // userImage=userImage.smoothScale(48,48);
432 QPixmap *picture; 483 QPixmap *picture;
433 picture=(QPixmap *)picturePushButton->pixmap(); 484 picture=(QPixmap *)picturePushButton->pixmap();
434 picture->convertFromImage(userImage,0); 485 picture->convertFromImage(userImage,0);
435 picturePushButton->update(); 486 picturePushButton->update();
436 } 487 }