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