summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/usermanager/userdialog.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/noncore/settings/usermanager/userdialog.cpp b/noncore/settings/usermanager/userdialog.cpp
index 42a9144..36bcf86 100644
--- a/noncore/settings/usermanager/userdialog.cpp
+++ b/noncore/settings/usermanager/userdialog.cpp
@@ -1,289 +1,294 @@
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>
28using namespace Opie;
29
30
27/** 31/**
28 * 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.
29 * 33 *
30 */ 34 */
31UserDialog::UserDialog(QWidget* parent, const char* name, bool modal, WFlags fl) : QDialog(parent, name, modal, fl) { 35UserDialog::UserDialog(QWidget* parent, const char* name, bool modal, WFlags fl) : QDialog(parent, name, modal, fl) {
32 QVBoxLayout *layout = new QVBoxLayout(this); 36 QVBoxLayout *layout = new QVBoxLayout(this);
33 myTabWidget=new QTabWidget(this,"User Tab Widget"); 37 myTabWidget=new QTabWidget(this,"User Tab Widget");
34 layout->addWidget(myTabWidget); 38 layout->addWidget(myTabWidget);
35 setupTab1(); 39 setupTab1();
36 setupTab2(); 40 setupTab2();
37 41
38 accounts->groupStringList.sort(); 42 accounts->groupStringList.sort();
39 // And also fill the listview & the combobox with all available groups. 43 // And also fill the listview & the combobox with all available groups.
40 for( QStringList::Iterator it = accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) { 44 for( QStringList::Iterator it = accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) {
41 accounts->splitGroupEntry(*it); 45 accounts->splitGroupEntry(*it);
42 new QCheckListItem(groupsListView,accounts->gr_name,QCheckListItem::CheckBox); 46 new QCheckListItem(groupsListView,accounts->gr_name,QCheckListItem::CheckBox);
43 groupComboBox->insertItem(accounts->gr_name); 47 groupComboBox->insertItem(accounts->gr_name);
44 } 48 }
45 showMaximized(); 49 showMaximized();
46} 50}
47 51
48/** 52/**
49 * Empty destructor. 53 * Empty destructor.
50 * 54 *
51 */ 55 */
52UserDialog::~UserDialog() { 56UserDialog::~UserDialog() {
53} 57}
54 58
55/** 59/**
56 * Creates the first tab, all userinfo is here. 60 * Creates the first tab, all userinfo is here.
57 * 61 *
58 */ 62 */
59void UserDialog::setupTab1() { 63void UserDialog::setupTab1() {
60 QPixmap mypixmap; 64 QPixmap mypixmap;
61 QWidget *tabpage = new QWidget(myTabWidget,"page1"); 65 QWidget *tabpage = new QWidget(myTabWidget,"page1");
62 QVBoxLayout *layout = new QVBoxLayout(tabpage); 66 QVBoxLayout *layout = new QVBoxLayout(tabpage);
63 layout->setMargin(5); 67 layout->setMargin(5);
64 68
65 // Picture 69 // Picture
66 picturePushButton = new QPushButton(tabpage,"Label"); 70 picturePushButton = new QPushButton(tabpage,"Label");
67 picturePushButton->setMinimumSize(48,48); 71 picturePushButton->setMinimumSize(48,48);
68 picturePushButton->setMaximumSize(48,48); 72 picturePushButton->setMaximumSize(48,48);
69 picturePushButton->setPixmap(Resource::loadPixmap("usermanager/usericon"));// Load default usericon. 73 picturePushButton->setPixmap(Resource::loadPixmap("usermanager/usericon"));// Load default usericon.
70 connect(picturePushButton,SIGNAL(clicked()),this,SLOT(clickedPicture()));// Clicking the picture should invoke pictureselector. 74 connect(picturePushButton,SIGNAL(clicked()),this,SLOT(clickedPicture()));// Clicking the picture should invoke pictureselector.
71 75
72 // Login 76 // Login
73 QLabel *loginLabel=new QLabel(tabpage,"Login: "); 77 QLabel *loginLabel=new QLabel(tabpage,"Login: ");
74 loginLabel->setText("Login: "); 78 loginLabel->setText("Login: ");
75 loginLineEdit=new QLineEdit(tabpage,"Login: "); 79 loginLineEdit=new QLineEdit(tabpage,"Login: ");
76 80
77 // UID 81 // UID
78 QLabel *uidLabel=new QLabel(tabpage,"uid: "); 82 QLabel *uidLabel=new QLabel(tabpage,"uid: ");
79 uidLabel->setText("UserID: "); 83 uidLabel->setText("UserID: ");
80 uidLineEdit=new QLineEdit(tabpage,"uid: "); 84 uidLineEdit=new QLineEdit(tabpage,"uid: ");
81 uidLineEdit->setEnabled(false); 85 uidLineEdit->setEnabled(false);
82 86
83 // Username (gecos) 87 // Username (gecos)
84 QLabel *gecosLabel=new QLabel(tabpage,"gecos"); 88 QLabel *gecosLabel=new QLabel(tabpage,"gecos");
85 gecosLabel->setText("Username: "); 89 gecosLabel->setText("Username: ");
86 gecosLineEdit=new QLineEdit(tabpage,"gecos"); 90 gecosLineEdit=new QLineEdit(tabpage,"gecos");
87 91
88 // Password 92 // Password
89 QLabel *passwordLabel=new QLabel(tabpage,"password"); 93 QLabel *passwordLabel=new QLabel(tabpage,"password");
90 passwordLabel->setText("Password: "); 94 passwordLabel->setText("Password: ");
91 passwordLineEdit=new QLineEdit(tabpage,"password"); 95 passwordLineEdit=new QLineEdit(tabpage,"password");
92 passwordLineEdit->setEchoMode(QLineEdit::Password); 96 passwordLineEdit->setEchoMode(QLineEdit::Password);
93 97
94 // Shell 98 // Shell
95 QLabel *shellLabel=new QLabel(tabpage,"shell"); 99 QLabel *shellLabel=new QLabel(tabpage,"shell");
96 shellLabel->setText("Shell: "); 100 shellLabel->setText("Shell: ");
97 shellComboBox=new QComboBox(tabpage,"shell"); 101 shellComboBox=new QComboBox(tabpage,"shell");
98 shellComboBox->setEditable(true); 102 shellComboBox->setEditable(true);
99 shellComboBox->insertItem("/bin/sh"); 103 shellComboBox->insertItem("/bin/sh");
100 shellComboBox->insertItem("/bin/ash"); 104 shellComboBox->insertItem("/bin/ash");
101 shellComboBox->insertItem("/bin/false"); 105 shellComboBox->insertItem("/bin/false");
102 106
103 // Primary Group 107 // Primary Group
104 QLabel *groupLabel=new QLabel(tabpage,"group"); 108 QLabel *groupLabel=new QLabel(tabpage,"group");
105 groupLabel->setText("Primary group: "); 109 groupLabel->setText("Primary group: ");
106 groupComboBox=new QComboBox(tabpage,"PrimaryGroup"); 110 groupComboBox=new QComboBox(tabpage,"PrimaryGroup");
107 111
108 // Copy /etc/skel 112 // Copy /etc/skel
109 QLabel *skelLabel=new QLabel(tabpage,"skel"); 113 QLabel *skelLabel=new QLabel(tabpage,"skel");
110 skelLabel->setText("Copy /etc/skel: "); 114 skelLabel->setText("Copy /etc/skel: ");
111 skelCheckBox=new QCheckBox(tabpage); 115 skelCheckBox=new QCheckBox(tabpage);
112 skelCheckBox->setChecked(true); 116 skelCheckBox->setChecked(true);
113 //skelLabel->setDisabled(true); 117 //skelLabel->setDisabled(true);
114 //skelCheckBox->setDisabled(true); 118 //skelCheckBox->setDisabled(true);
115 119
116 // Widget layout 120 // Widget layout
117 QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout"); 121 QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout");
118 layout->addWidget(picturePushButton); 122 layout->addWidget(picturePushButton);
119 layout->addSpacing(5); 123 layout->addSpacing(5);
120 layout->addLayout(hlayout); 124 layout->addLayout(hlayout);
121 QVBoxLayout *vlayout1=new QVBoxLayout(-1,"vlayout1"); 125 QVBoxLayout *vlayout1=new QVBoxLayout(-1,"vlayout1");
122 QVBoxLayout *vlayout2=new QVBoxLayout(-1,"vlayout2"); 126 QVBoxLayout *vlayout2=new QVBoxLayout(-1,"vlayout2");
123 // First column, labels 127 // First column, labels
124 vlayout1->addWidget(loginLabel); 128 vlayout1->addWidget(loginLabel);
125 vlayout1->addSpacing(5); 129 vlayout1->addSpacing(5);
126 vlayout1->addWidget(uidLabel); 130 vlayout1->addWidget(uidLabel);
127 vlayout1->addSpacing(5); 131 vlayout1->addSpacing(5);
128 vlayout1->addWidget(gecosLabel); 132 vlayout1->addWidget(gecosLabel);
129 vlayout1->addSpacing(5); 133 vlayout1->addSpacing(5);
130 vlayout1->addWidget(passwordLabel); 134 vlayout1->addWidget(passwordLabel);
131 vlayout1->addSpacing(5); 135 vlayout1->addSpacing(5);
132 vlayout1->addWidget(shellLabel); 136 vlayout1->addWidget(shellLabel);
133 vlayout1->addSpacing(5); 137 vlayout1->addSpacing(5);
134 vlayout1->addWidget(groupLabel); 138 vlayout1->addWidget(groupLabel);
135 vlayout1->addSpacing(5); 139 vlayout1->addSpacing(5);
136 vlayout1->addWidget(skelLabel); 140 vlayout1->addWidget(skelLabel);
137 // Second column, data 141 // Second column, data
138 vlayout2->addWidget(loginLineEdit); 142 vlayout2->addWidget(loginLineEdit);
139 vlayout2->addSpacing(5); 143 vlayout2->addSpacing(5);
140 vlayout2->addWidget(uidLineEdit); 144 vlayout2->addWidget(uidLineEdit);
141 vlayout2->addSpacing(5); 145 vlayout2->addSpacing(5);
142 vlayout2->addWidget(gecosLineEdit); 146 vlayout2->addWidget(gecosLineEdit);
143 vlayout2->addSpacing(5); 147 vlayout2->addSpacing(5);
144 vlayout2->addWidget(passwordLineEdit); 148 vlayout2->addWidget(passwordLineEdit);
145 vlayout2->addSpacing(5); 149 vlayout2->addSpacing(5);
146 vlayout2->addWidget(shellComboBox); 150 vlayout2->addWidget(shellComboBox);
147 vlayout2->addSpacing(5); 151 vlayout2->addSpacing(5);
148 vlayout2->addWidget(groupComboBox); 152 vlayout2->addWidget(groupComboBox);
149 vlayout2->addSpacing(5); 153 vlayout2->addSpacing(5);
150 vlayout2->addWidget(skelCheckBox); 154 vlayout2->addWidget(skelCheckBox);
151 hlayout->addLayout(vlayout1); 155 hlayout->addLayout(vlayout1);
152 hlayout->addLayout(vlayout2); 156 hlayout->addLayout(vlayout2);
153 157
154 myTabWidget->addTab(tabpage,"User Info"); 158 myTabWidget->addTab(tabpage,"User Info");
155} 159}
156 160
157/** 161/**
158 * Creates the second tab containing additional groups for the user. 162 * Creates the second tab containing additional groups for the user.
159 * 163 *
160 */ 164 */
161void UserDialog::setupTab2() { 165void UserDialog::setupTab2() {
162 QWidget *tabpage = new QWidget(myTabWidget,"page2"); 166 QWidget *tabpage = new QWidget(myTabWidget,"page2");
163 QVBoxLayout *layout = new QVBoxLayout(tabpage); 167 QVBoxLayout *layout = new QVBoxLayout(tabpage);
164 layout->setMargin(5); 168 layout->setMargin(5);
165 169
166 // Additional groups 170 // Additional groups
167 groupsListView=new QListView(tabpage,"groups"); 171 groupsListView=new QListView(tabpage,"groups");
168 groupsListView->addColumn("Additional groups"); 172 groupsListView->addColumn("Additional groups");
169 groupsListView->setColumnWidthMode(0,QListView::Maximum); 173 groupsListView->setColumnWidthMode(0,QListView::Maximum);
170 groupsListView->setMultiSelection(false); 174 groupsListView->setMultiSelection(false);
171 groupsListView->setAllColumnsShowFocus(false); 175 groupsListView->setAllColumnsShowFocus(false);
172 176
173 layout->addSpacing(5); 177 layout->addSpacing(5);
174 // Grouplist 178 // Grouplist
175 layout->addWidget(groupsListView); 179 layout->addWidget(groupsListView);
176 180
177 myTabWidget->addTab(tabpage,"User Groups"); 181 myTabWidget->addTab(tabpage,"User Groups");
178} 182}
179 183
180/** 184/**
181 * Static function that creates the userinfo dialog. 185 * Static function that creates the userinfo dialog.
182 * The user will be prompted to add a user. 186 * The user will be prompted to add a user.
183 * 187 *
184 * @param uid This is a suggested available UID. 188 * @param uid This is a suggested available UID.
185 * @param gid This is a suggested available GID. 189 * @param gid This is a suggested available GID.
186 * 190 *
187 * @return <code>true</code> if the user was successfully added, otherwise <code>false</code>. 191 * @return <code>true</code> if the user was successfully added, otherwise <code>false</code>.
188 * 192 *
189 */ 193 */
190bool UserDialog::addUser(int uid, int gid) { 194bool UserDialog::addUser(int uid, int gid) {
191 QCheckListItem *temp; 195 QCheckListItem *temp;
192 QFile ozTest; 196 QFile ozTest;
193 int oz=ozTest.exists("/etc/oz_version"); 197 int oz=false;
198 if(ODevice::inst()->system()==System_OpenZaurus) oz=true;
194 UserDialog *adduserDialog=new UserDialog(); 199 UserDialog *adduserDialog=new UserDialog();
195 adduserDialog->setCaption(tr("Add User")); 200 adduserDialog->setCaption(tr("Add User"));
196 adduserDialog->userID=uid;// Set next available UID as default uid. 201 adduserDialog->userID=uid;// Set next available UID as default uid.
197 adduserDialog->groupID=gid;// Set next available GID as default gid. 202 adduserDialog->groupID=gid;// Set next available GID as default gid.
198 // Insert default group into groupComboBox 203 // Insert default group into groupComboBox
199 adduserDialog->groupComboBox->insertItem("<create new group>",0); 204 adduserDialog->groupComboBox->insertItem("<create new group>",0);
200 adduserDialog->uidLineEdit->setText(QString::number(uid)); 205 adduserDialog->uidLineEdit->setText(QString::number(uid));
201 // If we're running on OZ, add new users to some default groups. 206 // If we're running on OZ, add new users to some default groups.
202 if(oz) { 207 if(oz) {
203 QListViewItemIterator iter( adduserDialog->groupsListView ); 208 QListViewItemIterator iter( adduserDialog->groupsListView );
204 for ( ; iter.current(); ++iter ) { 209 for ( ; iter.current(); ++iter ) {
205 temp=(QCheckListItem*)iter.current(); 210 temp=(QCheckListItem*)iter.current();
206 if (temp->text()=="video") temp->setOn(true); 211 if (temp->text()=="video") temp->setOn(true);
207 if (temp->text()=="audio") temp->setOn(true); 212 if (temp->text()=="audio") temp->setOn(true);
208 if (temp->text()=="time") temp->setOn(true); 213 if (temp->text()=="time") temp->setOn(true);
209 if (temp->text()=="power") temp->setOn(true); 214 if (temp->text()=="power") temp->setOn(true);
210 if (temp->text()=="input") temp->setOn(true); 215 if (temp->text()=="input") temp->setOn(true);
211 if (temp->text()=="sharp") temp->setOn(true); 216 if (temp->text()=="sharp") temp->setOn(true);
212 if (temp->text()=="tty") temp->setOn(true); 217 if (temp->text()=="tty") temp->setOn(true);
213 } 218 }
214 } 219 }
215 // Show the dialog! 220 // Show the dialog!
216 if(!(adduserDialog->exec())) return false; 221 if(!(adduserDialog->exec())) return false;
217 if((adduserDialog->groupComboBox->currentItem()!=0)) { 222 if((adduserDialog->groupComboBox->currentItem()!=0)) {
218 accounts->findGroup(adduserDialog->groupComboBox->currentText()); 223 accounts->findGroup(adduserDialog->groupComboBox->currentText());
219 adduserDialog->groupID=accounts->gr_gid; 224 adduserDialog->groupID=accounts->gr_gid;
220 qWarning(QString::number(accounts->gr_gid)); 225 qWarning(QString::number(accounts->gr_gid));
221 } 226 }
222 if(!(accounts->addUser(adduserDialog->loginLineEdit->text(), adduserDialog->passwordLineEdit->text(), 227 if(!(accounts->addUser(adduserDialog->loginLineEdit->text(), adduserDialog->passwordLineEdit->text(),
223 adduserDialog->uidLineEdit->text().toInt(), adduserDialog->groupID, adduserDialog->gecosLineEdit->text(), 228 adduserDialog->uidLineEdit->text().toInt(), adduserDialog->groupID, adduserDialog->gecosLineEdit->text(),
224 QString("/home/")+adduserDialog->loginLineEdit->text() , adduserDialog->shellComboBox->currentText()))) { 229 QString("/home/")+adduserDialog->loginLineEdit->text() , adduserDialog->shellComboBox->currentText()))) {
225 QMessageBox::information(0,"Ooops!","Something went wrong!\nUnable to add user."); 230 QMessageBox::information(0,"Ooops!","Something went wrong!\nUnable to add user.");
226 return false; 231 return false;
227 } 232 }
228 233
229 // Add User to additional groups. 234 // Add User to additional groups.
230 QListViewItemIterator it( adduserDialog->groupsListView ); 235 QListViewItemIterator it( adduserDialog->groupsListView );
231 for ( ; it.current(); ++it ) { 236 for ( ; it.current(); ++it ) {
232 temp=(QCheckListItem*)it.current(); 237 temp=(QCheckListItem*)it.current();
233 if (temp->isOn() ) 238 if (temp->isOn() )
234 accounts->addGroupMember(it.current()->text(0),adduserDialog->loginLineEdit->text()); 239 accounts->addGroupMember(it.current()->text(0),adduserDialog->loginLineEdit->text());
235 } 240 }
236 // Copy image to pics/users/ 241 // Copy image to pics/users/
237 if(!(adduserDialog->userImage.isNull())) { 242 if(!(adduserDialog->userImage.isNull())) {
238 QDir d; 243 QDir d;
239 if(!(d.exists("/opt/QtPalmtop/pics/users"))) { 244 if(!(d.exists("/opt/QtPalmtop/pics/users"))) {
240 d.mkdir("/opt/QtPalmtop/pics/users"); 245 d.mkdir("/opt/QtPalmtop/pics/users");
241 } 246 }
242 QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; 247 QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png";
243 // adduserDialog->userImage=adduserDialog->userImage.smoothScale(48,48); 248 // adduserDialog->userImage=adduserDialog->userImage.smoothScale(48,48);
244 adduserDialog->userImage.save(filename,"PNG"); 249 adduserDialog->userImage.save(filename,"PNG");
245 } 250 }
246 251
247 // Should we copy the skeleton homedirectory /etc/skel to the user's homedirectory? 252 // Should we copy the skeleton homedirectory /etc/skel to the user's homedirectory?
248 accounts->findUser(adduserDialog->loginLineEdit->text()); 253 accounts->findUser(adduserDialog->loginLineEdit->text());
249 if(adduserDialog->skelCheckBox->isChecked()) { 254 if(adduserDialog->skelCheckBox->isChecked()) {
250 QString command_cp; 255 QString command_cp;
251 QString command_chown; 256 QString command_chown;
252 command_cp.sprintf("cp -a /etc/skel/* %s/",accounts->pw_dir.latin1()); 257 command_cp.sprintf("cp -a /etc/skel/* %s/",accounts->pw_dir.latin1());
253 system(command_cp); 258 system(command_cp);
254 259
255 command_cp.sprintf("cp -a /etc/skel/.[!.]* %s/",accounts->pw_dir.latin1());// Bug in busybox, ".*" includes parent directory, does this work as a workaround? 260 command_cp.sprintf("cp -a /etc/skel/.[!.]* %s/",accounts->pw_dir.latin1());// Bug in busybox, ".*" includes parent directory, does this work as a workaround?
256 system(command_cp); 261 system(command_cp);
257 262
258 command_chown.sprintf("chown -R %d:%d %s",accounts->pw_uid,accounts->pw_gid,accounts->pw_dir.latin1()); 263 command_chown.sprintf("chown -R %d:%d %s",accounts->pw_uid,accounts->pw_gid,accounts->pw_dir.latin1());
259 system(command_chown); 264 system(command_chown);
260 } 265 }
261 266
262 return true; 267 return true;
263} 268}
264 269
265/** 270/**
266 * Deletes the user account. 271 * Deletes the user account.
267 * 272 *
268 * @param username User to be deleted. 273 * @param username User to be deleted.
269 * 274 *
270 * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. 275 * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>.
271 * 276 *
272 */ 277 */
273bool UserDialog::delUser(const char *username) { 278bool UserDialog::delUser(const char *username) {
274 if((accounts->findUser(username))) {// Does that user exist? 279 if((accounts->findUser(username))) {// Does that user exist?
275 if(!(accounts->delUser(username))) {// Delete the user. 280 if(!(accounts->delUser(username))) {// Delete the user.
276 QMessageBox::information(0,"Ooops!","Something went wrong\nUnable to delete user: "+QString(username)+"."); 281 QMessageBox::information(0,"Ooops!","Something went wrong\nUnable to delete user: "+QString(username)+".");
277 } 282 }
278 } else { 283 } else {
279 QMessageBox::information(0,"Invalid Username","That username ("+QString(username)+")does not exist."); 284 QMessageBox::information(0,"Invalid Username","That username ("+QString(username)+")does not exist.");
280 return false; 285 return false;
281 } 286 }
282 return true; 287 return true;
283} 288}
284 289
285/** 290/**
286 * This displays a confirmation dialog wether a user should be deleted or not. 291 * This displays a confirmation dialog wether a user should be deleted or not.
287 * (And also deletes the account) 292 * (And also deletes the account)
288 * 293 *
289 * @param username User to be deleted. 294 * @param username User to be deleted.