summaryrefslogtreecommitdiff
path: root/noncore/settings/usermanager
authorar <ar>2004-02-21 16:02:01 (UTC)
committer ar <ar>2004-02-21 16:02:01 (UTC)
commitdb2afda83e495bff9fc19fa14a30072f1cd4c67a (patch) (unidiff)
tree0281ec10dad24d83179283370661ae9225016de0 /noncore/settings/usermanager
parent460258f203be746ff79e14f32a823f381b8ea513 (diff)
downloadopie-db2afda83e495bff9fc19fa14a30072f1cd4c67a.zip
opie-db2afda83e495bff9fc19fa14a30072f1cd4c67a.tar.gz
opie-db2afda83e495bff9fc19fa14a30072f1cd4c67a.tar.bz2
improve support for BigScreen
Diffstat (limited to 'noncore/settings/usermanager') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/usermanager/userdialog.cpp743
1 files changed, 397 insertions, 346 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,434 +5,485 @@
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)
33 vm=viewmode; 38{
34 QVBoxLayout *layout = new QVBoxLayout(this); 39 vm=viewmode;
35 myTabWidget=new QTabWidget(this,"User Tab Widget"); 40 QVBoxLayout *layout = new QVBoxLayout(this);
36 layout->addWidget(myTabWidget); 41 myTabWidget=new QTabWidget(this,"User Tab Widget");
37 setupTab1(); 42 layout->addWidget(myTabWidget);
38 setupTab2(); 43 setupTab1();
39 44 setupTab2();
40 accounts->groupStringList.sort(); 45
41 // And also fill the listview & the combobox with all available groups. 46 accounts->groupStringList.sort();
42 for( QStringList::Iterator it = accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) { 47 // And also fill the listview & the combobox with all available groups.
43 accounts->splitGroupEntry(*it); 48 for( QStringList::Iterator it = accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it)
44 if(accounts->gr_name.find(QRegExp("^#"),0)) {// Skip commented lines. 49 {
45 new QCheckListItem(groupsListView,accounts->gr_name,QCheckListItem::CheckBox); 50 accounts->splitGroupEntry(*it);
46 groupComboBox->insertItem(accounts->gr_name); 51 if(accounts->gr_name.find(QRegExp("^#"),0))
47 } 52 {// Skip commented lines.
48 } 53 new QCheckListItem(groupsListView,accounts->gr_name,QCheckListItem::CheckBox);
49 showMaximized(); 54 groupComboBox->insertItem(accounts->gr_name);
55 }
56 }
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()
64 QPixmap mypixmap; 72{
65 QWidget *tabpage = new QWidget(myTabWidget,"page1"); 73 QPixmap mypixmap;
66 QVBoxLayout *layout = new QVBoxLayout(tabpage); 74 QWidget *tabpage = new QWidget(myTabWidget,"page1");
67 layout->setMargin(5); 75 QVBoxLayout *layout = new QVBoxLayout(tabpage);
68 76 layout->setMargin(5);
69 // Picture 77
70 picturePushButton = new QPushButton(tabpage,"Label"); 78 // Picture
71 picturePushButton->setMinimumSize(48,48); 79 picturePushButton = new QPushButton(tabpage,"Label");
72 picturePushButton->setMaximumSize(48,48); 80 picturePushButton->setMinimumSize(48,48);
73 picturePushButton->setPixmap(Resource::loadPixmap("usermanager/usericon"));// Load default usericon. 81 picturePushButton->setMaximumSize(48,48);
74 connect(picturePushButton,SIGNAL(clicked()),this,SLOT(clickedPicture()));// Clicking the picture should invoke pictureselector. 82 picturePushButton->setPixmap(Resource::loadPixmap("usermanager/usericon"));// Load default usericon.
75 83 connect(picturePushButton,SIGNAL(clicked()),this,SLOT(clickedPicture()));// Clicking the picture should invoke pictureselector.
76 // Login 84
77 QLabel *loginLabel=new QLabel(tabpage,"Login: "); 85 // Login
78 loginLabel->setText("Login: "); 86 QLabel *loginLabel=new QLabel(tabpage,"Login: ");
79 loginLineEdit=new QLineEdit(tabpage,"Login: "); 87 loginLabel->setText("Login: ");
80 88 loginLineEdit=new QLineEdit(tabpage,"Login: ");
81 // UID 89
82 QLabel *uidLabel=new QLabel(tabpage,"uid: "); 90 // UID
83 uidLabel->setText("UserID: "); 91 QLabel *uidLabel=new QLabel(tabpage,"uid: ");
84 uidLineEdit=new QLineEdit(tabpage,"uid: "); 92 uidLabel->setText("UserID: ");
85 uidLineEdit->setEnabled(false); 93 uidLineEdit=new QLineEdit(tabpage,"uid: ");
86 94 uidLineEdit->setEnabled(false);
87 // Username (gecos) 95
88 QLabel *gecosLabel=new QLabel(tabpage,"gecos"); 96 // Username (gecos)
89 gecosLabel->setText("Username: "); 97 QLabel *gecosLabel=new QLabel(tabpage,"gecos");
90 gecosLineEdit=new QLineEdit(tabpage,"gecos"); 98 gecosLabel->setText("Username: ");
91 99 gecosLineEdit=new QLineEdit(tabpage,"gecos");
92 // Password 100
93 QLabel *passwordLabel=new QLabel(tabpage,"password"); 101 // Password
94 passwordLabel->setText("Password: "); 102 QLabel *passwordLabel=new QLabel(tabpage,"password");
95 passwordLineEdit=new QLineEdit(tabpage,"password"); 103 passwordLabel->setText("Password: ");
96 passwordLineEdit->setEchoMode(QLineEdit::Password); 104 passwordLineEdit=new QLineEdit(tabpage,"password");
97 105 passwordLineEdit->setEchoMode(QLineEdit::Password);
98 // Shell 106
99 QLabel *shellLabel=new QLabel(tabpage,"shell"); 107 // Shell
100 shellLabel->setText("Shell: "); 108 QLabel *shellLabel=new QLabel(tabpage,"shell");
101 shellComboBox=new QComboBox(tabpage,"shell"); 109 shellLabel->setText("Shell: ");
102 shellComboBox->setEditable(true); 110 shellComboBox=new QComboBox(tabpage,"shell");
103 shellComboBox->insertItem("/bin/sh"); 111 shellComboBox->setEditable(true);
104 shellComboBox->insertItem("/bin/ash"); 112 shellComboBox->insertItem("/bin/sh");
105 shellComboBox->insertItem("/bin/false"); 113 shellComboBox->insertItem("/bin/ash");
106 114 shellComboBox->insertItem("/bin/false");
107 // Primary Group 115
108 QLabel *groupLabel=new QLabel(tabpage,"group"); 116 // Primary Group
109 groupLabel->setText("Primary group: "); 117 QLabel *groupLabel=new QLabel(tabpage,"group");
110 groupComboBox=new QComboBox(tabpage,"PrimaryGroup"); 118 groupLabel->setText("Primary group: ");
111 119 groupComboBox=new QComboBox(tabpage,"PrimaryGroup");
112 if(vm==VIEWMODE_NEW) { 120
113 // Copy /etc/skel 121 if(vm==VIEWMODE_NEW)
114 skelLabel=new QLabel(tabpage,"skel"); 122 {
115 skelLabel->setText("Copy /etc/skel: "); 123 // Copy /etc/skel
116 skelCheckBox=new QCheckBox(tabpage); 124 skelLabel=new QLabel(tabpage,"skel");
117 skelCheckBox->setChecked(true); 125 skelLabel->setText("Copy /etc/skel: ");
118 } 126 skelCheckBox=new QCheckBox(tabpage);
119 127 skelCheckBox->setChecked(true);
120 // Widget layout 128 }
121 QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout"); 129
122 layout->addWidget(picturePushButton); 130 // Widget layout
123 layout->addSpacing(5); 131 QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout");
124 layout->addLayout(hlayout); 132 layout->addWidget(picturePushButton);
125 QVBoxLayout *vlayout1=new QVBoxLayout(-1,"vlayout1"); 133 layout->addSpacing(5);
126 QVBoxLayout *vlayout2=new QVBoxLayout(-1,"vlayout2"); 134 layout->addLayout(hlayout);
127 // First column, labels 135 QVBoxLayout *vlayout1=new QVBoxLayout(-1,"vlayout1");
128 vlayout1->addWidget(loginLabel); 136 QVBoxLayout *vlayout2=new QVBoxLayout(-1,"vlayout2");
129 vlayout1->addSpacing(5); 137 // First column, labels
130 vlayout1->addWidget(uidLabel); 138 vlayout1->addWidget(loginLabel);
131 vlayout1->addSpacing(5); 139 vlayout1->addSpacing(5);
132 vlayout1->addWidget(gecosLabel); 140 vlayout1->addWidget(uidLabel);
133 vlayout1->addSpacing(5); 141 vlayout1->addSpacing(5);
134 vlayout1->addWidget(passwordLabel); 142 vlayout1->addWidget(gecosLabel);
135 vlayout1->addSpacing(5); 143 vlayout1->addSpacing(5);
136 vlayout1->addWidget(shellLabel); 144 vlayout1->addWidget(passwordLabel);
137 vlayout1->addSpacing(5); 145 vlayout1->addSpacing(5);
138 vlayout1->addWidget(groupLabel); 146 vlayout1->addWidget(shellLabel);
139 if(vm==VIEWMODE_NEW) { 147 vlayout1->addSpacing(5);
140 vlayout1->addSpacing(5); 148 vlayout1->addWidget(groupLabel);
141 vlayout1->addWidget(skelLabel); 149 if(vm==VIEWMODE_NEW)
142 } 150 {
143 // Second column, data 151 vlayout1->addSpacing(5);
144 vlayout2->addWidget(loginLineEdit); 152 vlayout1->addWidget(skelLabel);
145 vlayout2->addSpacing(5); 153 }
146 vlayout2->addWidget(uidLineEdit); 154 // Second column, data
147 vlayout2->addSpacing(5); 155 vlayout2->addWidget(loginLineEdit);
148 vlayout2->addWidget(gecosLineEdit); 156 vlayout2->addSpacing(5);
149 vlayout2->addSpacing(5); 157 vlayout2->addWidget(uidLineEdit);
150 vlayout2->addWidget(passwordLineEdit); 158 vlayout2->addSpacing(5);
151 vlayout2->addSpacing(5); 159 vlayout2->addWidget(gecosLineEdit);
152 vlayout2->addWidget(shellComboBox); 160 vlayout2->addSpacing(5);
153 vlayout2->addSpacing(5); 161 vlayout2->addWidget(passwordLineEdit);
154 vlayout2->addWidget(groupComboBox); 162 vlayout2->addSpacing(5);
155 if(vm==VIEWMODE_NEW) { 163 vlayout2->addWidget(shellComboBox);
156 vlayout2->addSpacing(5); 164 vlayout2->addSpacing(5);
157 vlayout2->addWidget(skelCheckBox); 165 vlayout2->addWidget(groupComboBox);
158 } 166 if(vm==VIEWMODE_NEW)
159 hlayout->addLayout(vlayout1); 167 {
160 hlayout->addLayout(vlayout2); 168 vlayout2->addSpacing(5);
161 169 vlayout2->addWidget(skelCheckBox);
162 myTabWidget->addTab(tabpage,"User Info"); 170 }
171 hlayout->addLayout(vlayout1);
172 hlayout->addLayout(vlayout2);
173
174 myTabWidget->addTab(tabpage,"User Info");
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()
170 QWidget *tabpage = new QWidget(myTabWidget,"page2"); 182{
171 QVBoxLayout *layout = new QVBoxLayout(tabpage); 183 QWidget *tabpage = new QWidget(myTabWidget,"page2");
172 layout->setMargin(5); 184 QVBoxLayout *layout = new QVBoxLayout(tabpage);
173 185 layout->setMargin(5);
174 // Additional groups 186
175 groupsListView=new QListView(tabpage,"groups"); 187 // Additional groups
176 groupsListView->addColumn("Additional groups"); 188 groupsListView=new QListView(tabpage,"groups");
177 groupsListView->setColumnWidthMode(0,QListView::Maximum); 189 groupsListView->addColumn("Additional groups");
178 groupsListView->setMultiSelection(false); 190 groupsListView->setColumnWidthMode(0,QListView::Maximum);
179 groupsListView->setAllColumnsShowFocus(false); 191 groupsListView->setMultiSelection(false);
180 192 groupsListView->setAllColumnsShowFocus(false);
181 layout->addSpacing(5); 193
182 // Grouplist 194 layout->addSpacing(5);
183 layout->addWidget(groupsListView); 195 // Grouplist
184 196 layout->addWidget(groupsListView);
185 myTabWidget->addTab(tabpage,"User Groups"); 197
198 myTabWidget->addTab(tabpage,"User Groups");
186} 199}
187 200
188/** 201/**
189 * Static function that creates the userinfo dialog. 202 * Static function that creates the userinfo dialog.
190 * The user will be prompted to add a user. 203 * The user will be prompted to add a user.
191 * 204 *
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)
199 QCheckListItem *temp; 212{
200 QFile ozTest; 213 QCheckListItem *temp;
201 int oz=false; 214 QFile ozTest;
202 if(ODevice::inst()->system()==System_OpenZaurus) oz=true; 215 int oz=false;
203 // viewmode is a workaround for a bug in qte-2.3.4 that gives bus error on manipulating adduserDialog's widgets here. 216 if(ODevice::inst()->system()==System_OpenZaurus) oz=true;
204 UserDialog *adduserDialog=new UserDialog(VIEWMODE_NEW); 217 // viewmode is a workaround for a bug in qte-2.3.4 that gives bus error on manipulating adduserDialog's widgets here.
205 adduserDialog->setCaption(tr("Add User")); 218 UserDialog *adduserDialog=new UserDialog(VIEWMODE_NEW);
206 adduserDialog->userID=uid;// Set next available UID as default uid. 219 adduserDialog->setCaption(tr("Add User"));
207 adduserDialog->groupID=gid;// Set next available GID as default gid. 220 adduserDialog->userID=uid;// Set next available UID as default uid.
208 // Insert default group into groupComboBox 221 adduserDialog->groupID=gid;// Set next available GID as default gid.
209 adduserDialog->groupComboBox->insertItem("<create new group>",0); 222 // Insert default group into groupComboBox
210 adduserDialog->uidLineEdit->setText(QString::number(uid)); 223 adduserDialog->groupComboBox->insertItem("<create new group>",0);
211 // If we're running on OZ, add new users to some default groups. 224 adduserDialog->uidLineEdit->setText(QString::number(uid));
212 if(oz) { 225 // If we're running on OZ, add new users to some default groups.
213 QListViewItemIterator iter( adduserDialog->groupsListView ); 226 if(oz)
214 for ( ; iter.current(); ++iter ) { 227 {
215 temp=(QCheckListItem*)iter.current(); 228 QListViewItemIterator iter( adduserDialog->groupsListView );
216 if (temp->text()=="video") temp->setOn(true); 229 for ( ; iter.current(); ++iter )
217 if (temp->text()=="audio") temp->setOn(true); 230 {
218 if (temp->text()=="time") temp->setOn(true); 231 temp=(QCheckListItem*)iter.current();
219 if (temp->text()=="power") temp->setOn(true); 232 if (temp->text()=="video") temp->setOn(true);
220 if (temp->text()=="input") temp->setOn(true); 233 if (temp->text()=="audio") temp->setOn(true);
221 if (temp->text()=="sharp") temp->setOn(true); 234 if (temp->text()=="time") temp->setOn(true);
222 if (temp->text()=="tty") temp->setOn(true); 235 if (temp->text()=="power") temp->setOn(true);
223 } 236 if (temp->text()=="input") temp->setOn(true);
224 } 237 if (temp->text()=="sharp") temp->setOn(true);
225 // Show the dialog! 238 if (temp->text()=="tty") temp->setOn(true);
226 if(!(adduserDialog->exec())) return false; 239 }
227 if((adduserDialog->groupComboBox->currentItem()!=0)) { 240 }
228 accounts->findGroup(adduserDialog->groupComboBox->currentText()); 241 // Show the dialog!
229 adduserDialog->groupID=accounts->gr_gid; 242 if(!(adduserDialog->exec())) return false;
230 qWarning(QString::number(accounts->gr_gid)); 243 if((adduserDialog->groupComboBox->currentItem()!=0))
231 } 244 {
232 if(!(accounts->addUser(adduserDialog->loginLineEdit->text(), adduserDialog->passwordLineEdit->text(), 245 accounts->findGroup(adduserDialog->groupComboBox->currentText());
233 adduserDialog->uidLineEdit->text().toInt(), adduserDialog->groupID, adduserDialog->gecosLineEdit->text(), 246 adduserDialog->groupID=accounts->gr_gid;
234 QString("/home/")+adduserDialog->loginLineEdit->text() , adduserDialog->shellComboBox->currentText()))) { 247 qWarning(QString::number(accounts->gr_gid));
235 QMessageBox::information(0,"Ooops!","Something went wrong!\nUnable to add user."); 248 }
236 return false; 249 if(!(accounts->addUser(adduserDialog->loginLineEdit->text(), adduserDialog->passwordLineEdit->text(),
237 } 250 adduserDialog->uidLineEdit->text().toInt(), adduserDialog->groupID, adduserDialog->gecosLineEdit->text(),
238 251 QString("/home/")+adduserDialog->loginLineEdit->text() , adduserDialog->shellComboBox->currentText())))
239 // Add User to additional groups. 252 {
240 QListViewItemIterator it( adduserDialog->groupsListView ); 253 QMessageBox::information(0,"Ooops!","Something went wrong!\nUnable to add user.");
241 for ( ; it.current(); ++it ) { 254 return false;
242 temp=(QCheckListItem*)it.current(); 255 }
243 if (temp->isOn() ) 256
244 accounts->addGroupMember(it.current()->text(0),adduserDialog->loginLineEdit->text()); 257 // Add User to additional groups.
245 } 258 QListViewItemIterator it( adduserDialog->groupsListView );
246 // Copy image to pics/users/ 259 for ( ; it.current(); ++it )
247 if(!(adduserDialog->userImage.isNull())) { 260 {
248 QDir d; 261 temp=(QCheckListItem*)it.current();
249 if(!(d.exists("/opt/QtPalmtop/pics/users"))) { 262 if (temp->isOn() )
250 d.mkdir("/opt/QtPalmtop/pics/users"); 263 accounts->addGroupMember(it.current()->text(0),adduserDialog->loginLineEdit->text());
251 } 264 }
252 QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; 265 // Copy image to pics/users/
253 // adduserDialog->userImage=adduserDialog->userImage.smoothScale(48,48); 266 if(!(adduserDialog->userImage.isNull()))
254 adduserDialog->userImage.save(filename,"PNG"); 267 {
255 } 268 QDir d;
256 269 if(!(d.exists("/opt/QtPalmtop/pics/users")))
257 // Should we copy the skeleton homedirectory /etc/skel to the user's homedirectory? 270 {
258 accounts->findUser(adduserDialog->loginLineEdit->text()); 271 d.mkdir("/opt/QtPalmtop/pics/users");
259 if(adduserDialog->skelCheckBox->isChecked()) { 272 }
260 QString command_cp; 273 QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png";
261 QString command_chown; 274 // adduserDialog->userImage=adduserDialog->userImage.smoothScale(48,48);
262 command_cp.sprintf("cp -a /etc/skel/* %s/",accounts->pw_dir.latin1()); 275 adduserDialog->userImage.save(filename,"PNG");
263 system(command_cp); 276 }
264 277
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? 278 // Should we copy the skeleton homedirectory /etc/skel to the user's homedirectory?
266 system(command_cp); 279 accounts->findUser(adduserDialog->loginLineEdit->text());
267 280 if(adduserDialog->skelCheckBox->isChecked())
268 command_chown.sprintf("chown -R %d:%d %s",accounts->pw_uid,accounts->pw_gid,accounts->pw_dir.latin1()); 281 {
269 system(command_chown); 282 QString command_cp;
270 } 283 QString command_chown;
271 284 command_cp.sprintf("cp -a /etc/skel/* %s/",accounts->pw_dir.latin1());
272 return true; 285 system(command_cp);
286
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?
288 system(command_cp);
289
290 command_chown.sprintf("chown -R %d:%d %s",accounts->pw_uid,accounts->pw_gid,accounts->pw_dir.latin1());
291 system(command_chown);
292 }
293
294 return true;
273} 295}
274 296
275/** 297/**
276 * Deletes the user account. 298 * Deletes the user account.
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)))
286 QMessageBox::information(0,"Ooops!","Something went wrong\nUnable to delete user: "+QString(username)+"."); 308 {// Does that user exist?
287 } 309 if(!(accounts->delUser(username)))
288 } else { 310 {// Delete the user.
289 QMessageBox::information(0,"Invalid Username","That username ("+QString(username)+")does not exist."); 311 QMessageBox::information(0,"Ooops!","Something went wrong\nUnable to delete user: "+QString(username)+".");
290 return false; 312 }
291 } 313 }
292 return true; 314 else
315 {
316 QMessageBox::information(0,"Invalid Username","That username ("+QString(username)+")does not exist.");
317 return false;
318 }
319 return true;
293} 320}
294 321
295/** 322/**
296 * This displays a confirmation dialog wether a user should be deleted or not. 323 * This displays a confirmation dialog wether a user should be deleted or not.
297 * (And also deletes the account) 324 * (And also deletes the account)
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)
305 int invalid_group=0; 332{
306 // viewmode is a workaround for a bug in qte-2.3.4 that gives bus error on manipulating edituserDialog's widgets here. 333 int invalid_group=0;
307 UserDialog *edituserDialog=new UserDialog(VIEWMODE_EDIT);// Create Dialog 334 // viewmode is a workaround for a bug in qte-2.3.4 that gives bus error on manipulating edituserDialog's widgets here.
308 edituserDialog->setCaption(tr("Edit User")); 335 UserDialog *edituserDialog=new UserDialog(VIEWMODE_EDIT);// Create Dialog
309 accounts->findUser(username);// Locate user in database and fill variables in 'accounts' object. 336 edituserDialog->setCaption(tr("Edit User"));
310 if(!(accounts->findGroup(accounts->pw_gid))) {// Locate the user's primary group, and fill group variables in 'accounts' object. 337 accounts->findUser(username);// Locate user in database and fill variables in 'accounts' object.
311 invalid_group=1; 338 if(!(accounts->findGroup(accounts->pw_gid)))
312 } 339 {// Locate the user's primary group, and fill group variables in 'accounts' object.
313 // Fill widgets with userinfo. 340 invalid_group=1;
314 edituserDialog->loginLineEdit->setText(accounts->pw_name); 341 }
315 edituserDialog->uidLineEdit->setText(QString::number(accounts->pw_uid)); 342 // Fill widgets with userinfo.
316 edituserDialog->gecosLineEdit->setText(accounts->pw_gecos); 343 edituserDialog->loginLineEdit->setText(accounts->pw_name);
317 // Set password to '........', we will later check if this still is the contents, if not, the password has been changed. 344 edituserDialog->uidLineEdit->setText(QString::number(accounts->pw_uid));
318 edituserDialog->passwordLineEdit->setText("........"); 345 edituserDialog->gecosLineEdit->setText(accounts->pw_gecos);
319 // If this user is not using /bin/sh,/bin/ash or /bin/false as shell, add that entry to the shell-combobox. 346 // Set password to '........', we will later check if this still is the contents, if not, the password has been changed.
320 if(accounts->pw_shell!="/bin/sh" && accounts->pw_shell!="/bin/ash" && accounts->pw_shell!="/bin/false") { 347 edituserDialog->passwordLineEdit->setText("........");
321 edituserDialog->shellComboBox->insertItem(accounts->pw_shell,0); 348 // If this user is not using /bin/sh,/bin/ash or /bin/false as shell, add that entry to the shell-combobox.
322 edituserDialog->shellComboBox->setCurrentItem(0); 349 if(accounts->pw_shell!="/bin/sh" && accounts->pw_shell!="/bin/ash" && accounts->pw_shell!="/bin/false")
323 } 350 {
324 // Select the primary group for this user. 351 edituserDialog->shellComboBox->insertItem(accounts->pw_shell,0);
325 for(int i=0;i<edituserDialog->groupComboBox->count();++i) { 352 edituserDialog->shellComboBox->setCurrentItem(0);
326 if(accounts->gr_name==edituserDialog->groupComboBox->text(i)) { 353 }
327 edituserDialog->groupComboBox->setCurrentItem(i); 354 // Select the primary group for this user.
328 break; 355 for(int i=0;i<edituserDialog->groupComboBox->count();++i)
329 } 356 {
330 } 357 if(accounts->gr_name==edituserDialog->groupComboBox->text(i))
331 if(invalid_group) { 358 {
332 edituserDialog->groupComboBox->insertItem("<Undefined group>",0); 359 edituserDialog->groupComboBox->setCurrentItem(i);
333 edituserDialog->groupComboBox->setCurrentItem(0); 360 break;
334 } 361 }
335 362 }
336 // Select the groups in the listview, to which the user belongs. 363 if(invalid_group)
337 QCheckListItem *temp; 364 {
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. 365 edituserDialog->groupComboBox->insertItem("<Undefined group>",0);
339 QRegExp userRegExp(QString("[:,]%1$").arg(username));// The end of line variant. 366 edituserDialog->groupComboBox->setCurrentItem(0);
340 QStringList tempList=accounts->groupStringList.grep(userRegExp);// Find all entries in the group database, that the user is a member of. 367 }
341 for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) {// Iterate over all of them. 368
342 qWarning(*it); 369 // Select the groups in the listview, to which the user belongs.
343 QListViewItemIterator lvit( edituserDialog->groupsListView );// Compare to all groups. 370 QCheckListItem *temp;
344 for ( ; lvit.current(); ++lvit ) { 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.
345 if(lvit.current()->text(0)==(*it).left((*it).find(":"))) { 372 QRegExp userRegExp(QString("[:,]%1$").arg(username));// The end of line variant.
346 temp=(QCheckListItem*)lvit.current(); 373 QStringList tempList=accounts->groupStringList.grep(userRegExp);// Find all entries in the group database, that the user is a member of.
347 temp->setOn(true);// If we find a line with that groupname, select it.; 374 for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it)
348 } 375 {// Iterate over all of them.
349 } 376 qWarning(*it);
350 } 377 QListViewItemIterator lvit( edituserDialog->groupsListView );// Compare to all groups.
351 userRegExp=QRegExp(QString("[:,]%1,").arg(username));// And the other one. (not end of line.) 378 for ( ; lvit.current(); ++lvit )
352 tempList=accounts->groupStringList.grep(userRegExp);// Find all entries in the group database, that the user is a member of. 379 {
353 for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) {// Iterate over all of them. 380 if(lvit.current()->text(0)==(*it).left((*it).find(":")))
354 qWarning(*it); 381 {
355 QListViewItemIterator lvit( edituserDialog->groupsListView );// Compare to all groups. 382 temp=(QCheckListItem*)lvit.current();
356 for ( ; lvit.current(); ++lvit ) { 383 temp->setOn(true);// If we find a line with that groupname, select it.;
357 if(lvit.current()->text(0)==(*it).left((*it).find(":"))) { 384 }
358 temp=(QCheckListItem*)lvit.current(); 385 }
359 temp->setOn(true);// If we find a line with that groupname, select it.; 386 }
360 } 387 userRegExp=QRegExp(QString("[:,]%1,").arg(username));// And the other one. (not end of line.)
361 } 388 tempList=accounts->groupStringList.grep(userRegExp);// Find all entries in the group database, that the user is a member of.
362 } 389 for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it)
363 390 {// Iterate over all of them.
364 if(!(edituserDialog->exec())) return false;// SHOW THE DIALOG! 391 qWarning(*it);
365 392 QListViewItemIterator lvit( edituserDialog->groupsListView );// Compare to all groups.
366 accounts->findUser(username);// Fill user variables in 'acccounts' object. 393 for ( ; lvit.current(); ++lvit )
367 accounts->pw_name=edituserDialog->loginLineEdit->text(); 394 {
368 // Has the password been changed ? Make a new "crypt":ed password. 395 if(lvit.current()->text(0)==(*it).left((*it).find(":")))
369 if(edituserDialog->passwordLineEdit->text()!="........") accounts->pw_passwd=crypt(edituserDialog->passwordLineEdit->text(), accounts->crypt_make_salt()); 396 {
370 397 temp=(QCheckListItem*)lvit.current();
371 // Set all variables in accounts object, that will be used when calling 'updateUser()' 398 temp->setOn(true);// If we find a line with that groupname, select it.;
372 accounts->pw_uid=edituserDialog->uidLineEdit->text().toInt(); 399 }
373 if(accounts->findGroup(edituserDialog->groupComboBox->currentText())) {// Fill all group variables in 'accounts' object. 400 }
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. 401 }
375 } 402
376 accounts->pw_gecos=edituserDialog->gecosLineEdit->text(); 403 if(!(edituserDialog->exec())) return false;// SHOW THE DIALOG!
377 accounts->pw_shell=edituserDialog->shellComboBox->currentText(); 404
378 // Update userinfo, using the information stored in the user variables stored in the accounts object. 405 accounts->findUser(username);// Fill user variables in 'acccounts' object.
379 accounts->updateUser(username); 406 accounts->pw_name=edituserDialog->loginLineEdit->text();
380 407 // Has the password been changed ? Make a new "crypt":ed password.
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.) 408 if(edituserDialog->passwordLineEdit->text()!="........") accounts->pw_passwd=crypt(edituserDialog->passwordLineEdit->text(), accounts->crypt_make_salt());
382 for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) { 409
383 accounts->delGroupMember((*it).left((*it).find(":")),username); 410 // Set all variables in accounts object, that will be used when calling 'updateUser()'
384 } 411 accounts->pw_uid=edituserDialog->uidLineEdit->text().toInt();
385 412 if(accounts->findGroup(edituserDialog->groupComboBox->currentText()))
386 // Add User to additional groups that he/she is a member of. 413 {// Fill all group variables in 'accounts' object.
387 QListViewItemIterator it( edituserDialog->groupsListView ); 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.
388 for ( ; it.current(); ++it ) { 415 }
389 temp=(QCheckListItem*)it.current(); 416 accounts->pw_gecos=edituserDialog->gecosLineEdit->text();
390 if ( temp->isOn() ) 417 accounts->pw_shell=edituserDialog->shellComboBox->currentText();
391 accounts->addGroupMember(it.current()->text(0),edituserDialog->loginLineEdit->text()); 418 // Update userinfo, using the information stored in the user variables stored in the accounts object.
392 } 419 accounts->updateUser(username);
393 420
394 // Copy image to pics/users/ 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.)
395 if(!(edituserDialog->userImage.isNull())) { 422 for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it)
396 QDir d; 423 {
397 if(!(d.exists("/opt/QtPalmtop/pics/users"))) { 424 accounts->delGroupMember((*it).left((*it).find(":")),username);
398 d.mkdir("/opt/QtPalmtop/pics/users"); 425 }
399 } 426
400 QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; 427 // Add User to additional groups that he/she is a member of.
401 // edituserDialog->userImage=edituserDialog->userImage.smoothScale(48,48); 428 QListViewItemIterator it( edituserDialog->groupsListView );
402 edituserDialog->userImage.save(filename,"PNG"); 429 for ( ; it.current(); ++it )
403 } 430 {
404 return true; 431 temp=(QCheckListItem*)it.current();
432 if ( temp->isOn() )
433 accounts->addGroupMember(it.current()->text(0),edituserDialog->loginLineEdit->text());
434 }
435
436 // Copy image to pics/users/
437 if(!(edituserDialog->userImage.isNull()))
438 {
439 QDir d;
440 if(!(d.exists("/opt/QtPalmtop/pics/users")))
441 {
442 d.mkdir("/opt/QtPalmtop/pics/users");
443 }
444 QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png";
445 // edituserDialog->userImage=edituserDialog->userImage.smoothScale(48,48);
446 edituserDialog->userImage.save(filename,"PNG");
447 }
448 return true;
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()
412 // Add checking... valid username? username taken? 456{
413 if(loginLineEdit->text().isEmpty()) { 457 // Add checking... valid username? username taken?
414 QMessageBox::information(0,"Empty Login","Please enter a login."); 458 if(loginLineEdit->text().isEmpty())
415 return; 459 {
416 } 460 QMessageBox::information(0,"Empty Login","Please enter a login.");
417 QDialog::accept(); 461 return;
462 }
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()
425 QString filename=OFileDialog::getOpenFileName(OFileSelector::EXTENDED, QString::null); 471{
426 if(!(filename.isEmpty())) { 472 QString filename=OFileDialog::getOpenFileName(OFileSelector::EXTENDED, QString::null);
427 userImage.reset(); 473 if(!(filename.isEmpty()))
428 if(!(userImage.load(filename))) { 474 {
429 QMessageBox::information(0,"Sorry!","That icon could not be loaded.\nLoading failed on: "+filename); 475 userImage.reset();
430 } else { 476 if(!(userImage.load(filename)))
431 // userImage=userImage.smoothScale(48,48); 477 {
432 QPixmap *picture; 478 QMessageBox::information(0,"Sorry!","That icon could not be loaded.\nLoading failed on: "+filename);
433 picture=(QPixmap *)picturePushButton->pixmap(); 479 }
434 picture->convertFromImage(userImage,0); 480 else
435 picturePushButton->update(); 481 {
436 } 482 // userImage=userImage.smoothScale(48,48);
437 } 483 QPixmap *picture;
484 picture=(QPixmap *)picturePushButton->pixmap();
485 picture->convertFromImage(userImage,0);
486 picturePushButton->update();
487 }
488 }
438} 489}