summaryrefslogtreecommitdiff
path: root/noncore/settings/usermanager/userdialog.cpp
Unidiff
Diffstat (limited to 'noncore/settings/usermanager/userdialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/usermanager/userdialog.cpp35
1 files changed, 21 insertions, 14 deletions
diff --git a/noncore/settings/usermanager/userdialog.cpp b/noncore/settings/usermanager/userdialog.cpp
index 36bcf86..c82cc9d 100644
--- a/noncore/settings/usermanager/userdialog.cpp
+++ b/noncore/settings/usermanager/userdialog.cpp
@@ -11,49 +11,50 @@
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(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 QVBoxLayout *layout = new QVBoxLayout(this); 37 QVBoxLayout *layout = new QVBoxLayout(this);
37 myTabWidget=new QTabWidget(this,"User Tab Widget"); 38 myTabWidget=new QTabWidget(this,"User Tab Widget");
38 layout->addWidget(myTabWidget); 39 layout->addWidget(myTabWidget);
39 setupTab1(); 40 setupTab1();
40 setupTab2(); 41 setupTab2();
41 42
42 accounts->groupStringList.sort(); 43 accounts->groupStringList.sort();
43 // And also fill the listview & the combobox with all available groups. 44 // And also fill the listview & the combobox with all available groups.
44 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) {
45 accounts->splitGroupEntry(*it); 46 accounts->splitGroupEntry(*it);
46 new QCheckListItem(groupsListView,accounts->gr_name,QCheckListItem::CheckBox); 47 new QCheckListItem(groupsListView,accounts->gr_name,QCheckListItem::CheckBox);
47 groupComboBox->insertItem(accounts->gr_name); 48 groupComboBox->insertItem(accounts->gr_name);
48 } 49 }
49 showMaximized(); 50 showMaximized();
50} 51}
51 52
52/** 53/**
53 * Empty destructor. 54 * Empty destructor.
54 * 55 *
55 */ 56 */
56UserDialog::~UserDialog() { 57UserDialog::~UserDialog() {
57} 58}
58 59
59/** 60/**
@@ -88,136 +89,141 @@ void UserDialog::setupTab1() {
88 QLabel *gecosLabel=new QLabel(tabpage,"gecos"); 89 QLabel *gecosLabel=new QLabel(tabpage,"gecos");
89 gecosLabel->setText("Username: "); 90 gecosLabel->setText("Username: ");
90 gecosLineEdit=new QLineEdit(tabpage,"gecos"); 91 gecosLineEdit=new QLineEdit(tabpage,"gecos");
91 92
92 // Password 93 // Password
93 QLabel *passwordLabel=new QLabel(tabpage,"password"); 94 QLabel *passwordLabel=new QLabel(tabpage,"password");
94 passwordLabel->setText("Password: "); 95 passwordLabel->setText("Password: ");
95 passwordLineEdit=new QLineEdit(tabpage,"password"); 96 passwordLineEdit=new QLineEdit(tabpage,"password");
96 passwordLineEdit->setEchoMode(QLineEdit::Password); 97 passwordLineEdit->setEchoMode(QLineEdit::Password);
97 98
98 // Shell 99 // Shell
99 QLabel *shellLabel=new QLabel(tabpage,"shell"); 100 QLabel *shellLabel=new QLabel(tabpage,"shell");
100 shellLabel->setText("Shell: "); 101 shellLabel->setText("Shell: ");
101 shellComboBox=new QComboBox(tabpage,"shell"); 102 shellComboBox=new QComboBox(tabpage,"shell");
102 shellComboBox->setEditable(true); 103 shellComboBox->setEditable(true);
103 shellComboBox->insertItem("/bin/sh"); 104 shellComboBox->insertItem("/bin/sh");
104 shellComboBox->insertItem("/bin/ash"); 105 shellComboBox->insertItem("/bin/ash");
105 shellComboBox->insertItem("/bin/false"); 106 shellComboBox->insertItem("/bin/false");
106 107
107 // Primary Group 108 // Primary Group
108 QLabel *groupLabel=new QLabel(tabpage,"group"); 109 QLabel *groupLabel=new QLabel(tabpage,"group");
109 groupLabel->setText("Primary group: "); 110 groupLabel->setText("Primary group: ");
110 groupComboBox=new QComboBox(tabpage,"PrimaryGroup"); 111 groupComboBox=new QComboBox(tabpage,"PrimaryGroup");
111 112
112 // Copy /etc/skel 113 if(vm==VIEWMODE_NEW) {
113 QLabel *skelLabel=new QLabel(tabpage,"skel"); 114 // Copy /etc/skel
114 skelLabel->setText("Copy /etc/skel: "); 115 skelLabel=new QLabel(tabpage,"skel");
115 skelCheckBox=new QCheckBox(tabpage); 116 skelLabel->setText("Copy /etc/skel: ");
116 skelCheckBox->setChecked(true); 117 skelCheckBox=new QCheckBox(tabpage);
117 //skelLabel->setDisabled(true); 118 skelCheckBox->setChecked(true);
118 //skelCheckBox->setDisabled(true); 119 }
119 120
120 // Widget layout 121 // Widget layout
121 QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout"); 122 QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout");
122 layout->addWidget(picturePushButton); 123 layout->addWidget(picturePushButton);
123 layout->addSpacing(5); 124 layout->addSpacing(5);
124 layout->addLayout(hlayout); 125 layout->addLayout(hlayout);
125 QVBoxLayout *vlayout1=new QVBoxLayout(-1,"vlayout1"); 126 QVBoxLayout *vlayout1=new QVBoxLayout(-1,"vlayout1");
126 QVBoxLayout *vlayout2=new QVBoxLayout(-1,"vlayout2"); 127 QVBoxLayout *vlayout2=new QVBoxLayout(-1,"vlayout2");
127 // First column, labels 128 // First column, labels
128 vlayout1->addWidget(loginLabel); 129 vlayout1->addWidget(loginLabel);
129 vlayout1->addSpacing(5); 130 vlayout1->addSpacing(5);
130 vlayout1->addWidget(uidLabel); 131 vlayout1->addWidget(uidLabel);
131 vlayout1->addSpacing(5); 132 vlayout1->addSpacing(5);
132 vlayout1->addWidget(gecosLabel); 133 vlayout1->addWidget(gecosLabel);
133 vlayout1->addSpacing(5); 134 vlayout1->addSpacing(5);
134 vlayout1->addWidget(passwordLabel); 135 vlayout1->addWidget(passwordLabel);
135 vlayout1->addSpacing(5); 136 vlayout1->addSpacing(5);
136 vlayout1->addWidget(shellLabel); 137 vlayout1->addWidget(shellLabel);
137 vlayout1->addSpacing(5); 138 vlayout1->addSpacing(5);
138 vlayout1->addWidget(groupLabel); 139 vlayout1->addWidget(groupLabel);
139 vlayout1->addSpacing(5); 140 if(vm==VIEWMODE_NEW) {
140 vlayout1->addWidget(skelLabel); 141 vlayout1->addSpacing(5);
142 vlayout1->addWidget(skelLabel);
143 }
141 // Second column, data 144 // Second column, data
142 vlayout2->addWidget(loginLineEdit); 145 vlayout2->addWidget(loginLineEdit);
143 vlayout2->addSpacing(5); 146 vlayout2->addSpacing(5);
144 vlayout2->addWidget(uidLineEdit); 147 vlayout2->addWidget(uidLineEdit);
145 vlayout2->addSpacing(5); 148 vlayout2->addSpacing(5);
146 vlayout2->addWidget(gecosLineEdit); 149 vlayout2->addWidget(gecosLineEdit);
147 vlayout2->addSpacing(5); 150 vlayout2->addSpacing(5);
148 vlayout2->addWidget(passwordLineEdit); 151 vlayout2->addWidget(passwordLineEdit);
149 vlayout2->addSpacing(5); 152 vlayout2->addSpacing(5);
150 vlayout2->addWidget(shellComboBox); 153 vlayout2->addWidget(shellComboBox);
151 vlayout2->addSpacing(5); 154 vlayout2->addSpacing(5);
152 vlayout2->addWidget(groupComboBox); 155 vlayout2->addWidget(groupComboBox);
153 vlayout2->addSpacing(5); 156 if(vm==VIEWMODE_NEW) {
154 vlayout2->addWidget(skelCheckBox); 157 vlayout2->addSpacing(5);
158 vlayout2->addWidget(skelCheckBox);
159 }
155 hlayout->addLayout(vlayout1); 160 hlayout->addLayout(vlayout1);
156 hlayout->addLayout(vlayout2); 161 hlayout->addLayout(vlayout2);
157 162
158 myTabWidget->addTab(tabpage,"User Info"); 163 myTabWidget->addTab(tabpage,"User Info");
159} 164}
160 165
161/** 166/**
162 * Creates the second tab containing additional groups for the user. 167 * Creates the second tab containing additional groups for the user.
163 * 168 *
164 */ 169 */
165void UserDialog::setupTab2() { 170void UserDialog::setupTab2() {
166 QWidget *tabpage = new QWidget(myTabWidget,"page2"); 171 QWidget *tabpage = new QWidget(myTabWidget,"page2");
167 QVBoxLayout *layout = new QVBoxLayout(tabpage); 172 QVBoxLayout *layout = new QVBoxLayout(tabpage);
168 layout->setMargin(5); 173 layout->setMargin(5);
169 174
170 // Additional groups 175 // Additional groups
171 groupsListView=new QListView(tabpage,"groups"); 176 groupsListView=new QListView(tabpage,"groups");
172 groupsListView->addColumn("Additional groups"); 177 groupsListView->addColumn("Additional groups");
173 groupsListView->setColumnWidthMode(0,QListView::Maximum); 178 groupsListView->setColumnWidthMode(0,QListView::Maximum);
174 groupsListView->setMultiSelection(false); 179 groupsListView->setMultiSelection(false);
175 groupsListView->setAllColumnsShowFocus(false); 180 groupsListView->setAllColumnsShowFocus(false);
176 181
177 layout->addSpacing(5); 182 layout->addSpacing(5);
178 // Grouplist 183 // Grouplist
179 layout->addWidget(groupsListView); 184 layout->addWidget(groupsListView);
180 185
181 myTabWidget->addTab(tabpage,"User Groups"); 186 myTabWidget->addTab(tabpage,"User Groups");
182} 187}
183 188
184/** 189/**
185 * Static function that creates the userinfo dialog. 190 * Static function that creates the userinfo dialog.
186 * The user will be prompted to add a user. 191 * The user will be prompted to add a user.
187 * 192 *
188 * @param uid This is a suggested available UID. 193 * @param uid This is a suggested available UID.
189 * @param gid This is a suggested available GID. 194 * @param gid This is a suggested available GID.
190 * 195 *
191 * @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>.
192 * 197 *
193 */ 198 */
194bool UserDialog::addUser(int uid, int gid) { 199bool UserDialog::addUser(int uid, int gid) {
195 QCheckListItem *temp; 200 QCheckListItem *temp;
196 QFile ozTest; 201 QFile ozTest;
197 int oz=false; 202 int oz=false;
198 if(ODevice::inst()->system()==System_OpenZaurus) oz=true; 203 if(ODevice::inst()->system()==System_OpenZaurus) oz=true;
199 UserDialog *adduserDialog=new UserDialog(); 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);
200 adduserDialog->setCaption(tr("Add User")); 206 adduserDialog->setCaption(tr("Add User"));
201 adduserDialog->userID=uid;// Set next available UID as default uid. 207 adduserDialog->userID=uid;// Set next available UID as default uid.
202 adduserDialog->groupID=gid;// Set next available GID as default gid. 208 adduserDialog->groupID=gid;// Set next available GID as default gid.
203 // Insert default group into groupComboBox 209 // Insert default group into groupComboBox
204 adduserDialog->groupComboBox->insertItem("<create new group>",0); 210 adduserDialog->groupComboBox->insertItem("<create new group>",0);
205 adduserDialog->uidLineEdit->setText(QString::number(uid)); 211 adduserDialog->uidLineEdit->setText(QString::number(uid));
206 // 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.
207 if(oz) { 213 if(oz) {
208 QListViewItemIterator iter( adduserDialog->groupsListView ); 214 QListViewItemIterator iter( adduserDialog->groupsListView );
209 for ( ; iter.current(); ++iter ) { 215 for ( ; iter.current(); ++iter ) {
210 temp=(QCheckListItem*)iter.current(); 216 temp=(QCheckListItem*)iter.current();
211 if (temp->text()=="video") temp->setOn(true); 217 if (temp->text()=="video") temp->setOn(true);
212 if (temp->text()=="audio") temp->setOn(true); 218 if (temp->text()=="audio") temp->setOn(true);
213 if (temp->text()=="time") temp->setOn(true); 219 if (temp->text()=="time") temp->setOn(true);
214 if (temp->text()=="power") temp->setOn(true); 220 if (temp->text()=="power") temp->setOn(true);
215 if (temp->text()=="input") temp->setOn(true); 221 if (temp->text()=="input") temp->setOn(true);
216 if (temp->text()=="sharp") temp->setOn(true); 222 if (temp->text()=="sharp") temp->setOn(true);
217 if (temp->text()=="tty") temp->setOn(true); 223 if (temp->text()=="tty") temp->setOn(true);
218 } 224 }
219 } 225 }
220 // Show the dialog! 226 // Show the dialog!
221 if(!(adduserDialog->exec())) return false; 227 if(!(adduserDialog->exec())) return false;
222 if((adduserDialog->groupComboBox->currentItem()!=0)) { 228 if((adduserDialog->groupComboBox->currentItem()!=0)) {
223 accounts->findGroup(adduserDialog->groupComboBox->currentText()); 229 accounts->findGroup(adduserDialog->groupComboBox->currentText());
@@ -277,49 +283,50 @@ bool UserDialog::addUser(int uid, int gid) {
277 */ 283 */
278bool UserDialog::delUser(const char *username) { 284bool UserDialog::delUser(const char *username) {
279 if((accounts->findUser(username))) {// Does that user exist? 285 if((accounts->findUser(username))) {// Does that user exist?
280 if(!(accounts->delUser(username))) {// Delete the user. 286 if(!(accounts->delUser(username))) {// Delete the user.
281 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)+".");
282 } 288 }
283 } else { 289 } else {
284 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.");
285 return false; 291 return false;
286 } 292 }
287 return true; 293 return true;
288} 294}
289 295
290/** 296/**
291 * 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.
292 * (And also deletes the account) 298 * (And also deletes the account)
293 * 299 *
294 * @param username User to be deleted. 300 * @param username User to be deleted.
295 * 301 *
296 * @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>.
297 * 303 *
298 */ 304 */
299bool UserDialog::editUser(const char *username) { 305bool UserDialog::editUser(const char *username) {
300 int invalid_group=0; 306 int invalid_group=0;
301 UserDialog *edituserDialog=new UserDialog();// Create Dialog 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
302 edituserDialog->setCaption(tr("Edit User")); 309 edituserDialog->setCaption(tr("Edit User"));
303 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.
304 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.
305 invalid_group=1; 312 invalid_group=1;
306 } 313 }
307 // Fill widgets with userinfo. 314 // Fill widgets with userinfo.
308 edituserDialog->loginLineEdit->setText(accounts->pw_name); 315 edituserDialog->loginLineEdit->setText(accounts->pw_name);
309 edituserDialog->uidLineEdit->setText(QString::number(accounts->pw_uid)); 316 edituserDialog->uidLineEdit->setText(QString::number(accounts->pw_uid));
310 edituserDialog->gecosLineEdit->setText(accounts->pw_gecos); 317 edituserDialog->gecosLineEdit->setText(accounts->pw_gecos);
311 // 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.
312 edituserDialog->passwordLineEdit->setText("........"); 319 edituserDialog->passwordLineEdit->setText("........");
313 // 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.
314 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") {
315 edituserDialog->shellComboBox->insertItem(accounts->pw_shell,0); 322 edituserDialog->shellComboBox->insertItem(accounts->pw_shell,0);
316 edituserDialog->shellComboBox->setCurrentItem(0); 323 edituserDialog->shellComboBox->setCurrentItem(0);
317 } 324 }
318 // Select the primary group for this user. 325 // Select the primary group for this user.
319 for(int i=0;i<edituserDialog->groupComboBox->count();++i) { 326 for(int i=0;i<edituserDialog->groupComboBox->count();++i) {
320 if(accounts->gr_name==edituserDialog->groupComboBox->text(i)) { 327 if(accounts->gr_name==edituserDialog->groupComboBox->text(i)) {
321 edituserDialog->groupComboBox->setCurrentItem(i); 328 edituserDialog->groupComboBox->setCurrentItem(i);
322 break; 329 break;
323 } 330 }
324 } 331 }
325 if(invalid_group) { 332 if(invalid_group) {