Diffstat (limited to 'noncore/settings/usermanager/userdialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/usermanager/userdialog.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/noncore/settings/usermanager/userdialog.cpp b/noncore/settings/usermanager/userdialog.cpp index 3654639..75a96a6 100644 --- a/noncore/settings/usermanager/userdialog.cpp +++ b/noncore/settings/usermanager/userdialog.cpp | |||
@@ -149,195 +149,198 @@ void UserDialog::setupTab1() | |||
149 | if(vm==VIEWMODE_NEW) | 149 | if(vm==VIEWMODE_NEW) |
150 | { | 150 | { |
151 | vlayout1->addSpacing(5); | 151 | vlayout1->addSpacing(5); |
152 | vlayout1->addWidget(skelLabel); | 152 | vlayout1->addWidget(skelLabel); |
153 | } | 153 | } |
154 | // Second column, data | 154 | // Second column, data |
155 | vlayout2->addWidget(loginLineEdit); | 155 | vlayout2->addWidget(loginLineEdit); |
156 | vlayout2->addSpacing(5); | 156 | vlayout2->addSpacing(5); |
157 | vlayout2->addWidget(uidLineEdit); | 157 | vlayout2->addWidget(uidLineEdit); |
158 | vlayout2->addSpacing(5); | 158 | vlayout2->addSpacing(5); |
159 | vlayout2->addWidget(gecosLineEdit); | 159 | vlayout2->addWidget(gecosLineEdit); |
160 | vlayout2->addSpacing(5); | 160 | vlayout2->addSpacing(5); |
161 | vlayout2->addWidget(passwordLineEdit); | 161 | vlayout2->addWidget(passwordLineEdit); |
162 | vlayout2->addSpacing(5); | 162 | vlayout2->addSpacing(5); |
163 | vlayout2->addWidget(shellComboBox); | 163 | vlayout2->addWidget(shellComboBox); |
164 | vlayout2->addSpacing(5); | 164 | vlayout2->addSpacing(5); |
165 | vlayout2->addWidget(groupComboBox); | 165 | vlayout2->addWidget(groupComboBox); |
166 | if(vm==VIEWMODE_NEW) | 166 | if(vm==VIEWMODE_NEW) |
167 | { | 167 | { |
168 | vlayout2->addSpacing(5); | 168 | vlayout2->addSpacing(5); |
169 | vlayout2->addWidget(skelCheckBox); | 169 | vlayout2->addWidget(skelCheckBox); |
170 | } | 170 | } |
171 | hlayout->addLayout(vlayout1); | 171 | hlayout->addLayout(vlayout1); |
172 | hlayout->addLayout(vlayout2); | 172 | hlayout->addLayout(vlayout2); |
173 | 173 | ||
174 | myTabWidget->addTab(tabpage,"User Info"); | 174 | myTabWidget->addTab(tabpage,"User Info"); |
175 | } | 175 | } |
176 | 176 | ||
177 | /** | 177 | /** |
178 | * Creates the second tab containing additional groups for the user. | 178 | * Creates the second tab containing additional groups for the user. |
179 | * | 179 | * |
180 | */ | 180 | */ |
181 | void UserDialog::setupTab2() | 181 | void UserDialog::setupTab2() |
182 | { | 182 | { |
183 | QWidget *tabpage = new QWidget(myTabWidget,"page2"); | 183 | QWidget *tabpage = new QWidget(myTabWidget,"page2"); |
184 | QVBoxLayout *layout = new QVBoxLayout(tabpage); | 184 | QVBoxLayout *layout = new QVBoxLayout(tabpage); |
185 | layout->setMargin(5); | 185 | layout->setMargin(5); |
186 | 186 | ||
187 | // Additional groups | 187 | // Additional groups |
188 | groupsListView=new QListView(tabpage,"groups"); | 188 | groupsListView=new QListView(tabpage,"groups"); |
189 | groupsListView->addColumn("Additional groups"); | 189 | groupsListView->addColumn("Additional groups"); |
190 | groupsListView->setColumnWidthMode(0,QListView::Maximum); | 190 | groupsListView->setColumnWidthMode(0,QListView::Maximum); |
191 | groupsListView->setMultiSelection(false); | 191 | groupsListView->setMultiSelection(false); |
192 | groupsListView->setAllColumnsShowFocus(false); | 192 | groupsListView->setAllColumnsShowFocus(false); |
193 | 193 | ||
194 | layout->addSpacing(5); | 194 | layout->addSpacing(5); |
195 | // Grouplist | 195 | // Grouplist |
196 | layout->addWidget(groupsListView); | 196 | layout->addWidget(groupsListView); |
197 | 197 | ||
198 | myTabWidget->addTab(tabpage,"User Groups"); | 198 | myTabWidget->addTab(tabpage,"User Groups"); |
199 | } | 199 | } |
200 | 200 | ||
201 | /** | 201 | /** |
202 | * Static function that creates the userinfo dialog. | 202 | * Static function that creates the userinfo dialog. |
203 | * The user will be prompted to add a user. | 203 | * The user will be prompted to add a user. |
204 | * | 204 | * |
205 | * @param uid This is a suggested available UID. | 205 | * @param uid This is a suggested available UID. |
206 | * @param gid This is a suggested available GID. | 206 | * @param gid This is a suggested available GID. |
207 | * | 207 | * |
208 | * @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>. |
209 | * | 209 | * |
210 | */ | 210 | */ |
211 | bool UserDialog::addUser(int uid, int gid) | 211 | bool UserDialog::addUser(int uid, int gid) |
212 | { | 212 | { |
213 | QCheckListItem *temp; | 213 | QCheckListItem *temp; |
214 | QFile ozTest; | 214 | QFile ozTest; |
215 | int oz=false; | 215 | int oz=false; |
216 | if(ODevice::inst()->system()==System_OpenZaurus) oz=true; | 216 | if(ODevice::inst()->system()==System_OpenZaurus) oz=true; |
217 | // viewmode is a workaround for a bug in qte-2.3.4 that gives bus error on manipulating adduserDialog's widgets here. | 217 | // viewmode is a workaround for a bug in qte-2.3.4 that gives bus error on manipulating adduserDialog's widgets here. |
218 | UserDialog *adduserDialog=new UserDialog(VIEWMODE_NEW); | 218 | UserDialog *adduserDialog=new UserDialog(VIEWMODE_NEW); |
219 | adduserDialog->setCaption(tr("Add User")); | 219 | adduserDialog->setCaption(tr("Add User")); |
220 | adduserDialog->userID=uid; // Set next available UID as default uid. | 220 | adduserDialog->userID=uid; // Set next available UID as default uid. |
221 | adduserDialog->groupID=gid; // Set next available GID as default gid. | 221 | adduserDialog->groupID=gid; // Set next available GID as default gid. |
222 | // Insert default group into groupComboBox | 222 | // Insert default group into groupComboBox |
223 | adduserDialog->groupComboBox->insertItem("<create new group>",0); | 223 | adduserDialog->groupComboBox->insertItem("<create new group>",0); |
224 | adduserDialog->uidLineEdit->setText(QString::number(uid)); | 224 | adduserDialog->uidLineEdit->setText(QString::number(uid)); |
225 | // If we're running on OZ, add new users to some default groups. | 225 | // If we're running on OZ, add new users to some default groups. |
226 | if(oz) | 226 | if(oz) |
227 | { | 227 | { |
228 | QListViewItemIterator iter( adduserDialog->groupsListView ); | 228 | QListViewItemIterator iter( adduserDialog->groupsListView ); |
229 | for ( ; iter.current(); ++iter ) | 229 | for ( ; iter.current(); ++iter ) |
230 | { | 230 | { |
231 | temp=(QCheckListItem*)iter.current(); | 231 | temp=(QCheckListItem*)iter.current(); |
232 | if (temp->text()=="video") temp->setOn(true); | 232 | if (temp->text()=="video") temp->setOn(true); |
233 | if (temp->text()=="audio") temp->setOn(true); | 233 | if (temp->text()=="audio") temp->setOn(true); |
234 | if (temp->text()=="time") temp->setOn(true); | 234 | if (temp->text()=="time") temp->setOn(true); |
235 | if (temp->text()=="power") temp->setOn(true); | 235 | if (temp->text()=="power") temp->setOn(true); |
236 | if (temp->text()=="input") temp->setOn(true); | 236 | if (temp->text()=="input") temp->setOn(true); |
237 | if (temp->text()=="sharp") temp->setOn(true); | 237 | if (temp->text()=="sharp") temp->setOn(true); |
238 | if (temp->text()=="tty") temp->setOn(true); | 238 | if (temp->text()=="tty") temp->setOn(true); |
239 | } | 239 | } |
240 | } | 240 | } |
241 | // Show the dialog! | 241 | // Show the dialog! |
242 | if(!(adduserDialog->exec())) return false; | 242 | if(!(adduserDialog->exec())) return false; |
243 | if((adduserDialog->groupComboBox->currentItem()!=0)) | 243 | if((adduserDialog->groupComboBox->currentItem()!=0)) |
244 | { | 244 | { |
245 | accounts->findGroup(adduserDialog->groupComboBox->currentText()); | 245 | // making the call findGroup() puts the group info in the accounts gr_gid |
246 | adduserDialog->groupID=accounts->gr_gid; | 246 | if (accounts->findGroup(adduserDialog->groupComboBox->currentText())) |
247 | owarn << QString::number(accounts->gr_gid) << oendl; | 247 | { |
248 | adduserDialog->groupID=accounts->gr_gid; | ||
249 | owarn << QString::number(accounts->gr_gid) << oendl; | ||
250 | } | ||
248 | } | 251 | } |
249 | if(!(accounts->addUser(adduserDialog->loginLineEdit->text(), adduserDialog->passwordLineEdit->text(), | 252 | if(!(accounts->addUser(adduserDialog->loginLineEdit->text(), adduserDialog->passwordLineEdit->text(), |
250 | adduserDialog->uidLineEdit->text().toInt(), adduserDialog->groupID, adduserDialog->gecosLineEdit->text(), | 253 | adduserDialog->uidLineEdit->text().toInt(), adduserDialog->groupID, adduserDialog->gecosLineEdit->text(), |
251 | QString("/home/")+adduserDialog->loginLineEdit->text() , adduserDialog->shellComboBox->currentText()))) | 254 | QString("/home/")+adduserDialog->loginLineEdit->text() , adduserDialog->shellComboBox->currentText()))) |
252 | { | 255 | { |
253 | QMessageBox::information(0,"Ooops!","Something went wrong!\nUnable to add user."); | 256 | QMessageBox::information(0,"Ooops!","Something went wrong!\nUnable to add user."); |
254 | return false; | 257 | return false; |
255 | } | 258 | } |
256 | 259 | ||
257 | // Add User to additional groups. | 260 | // Add User to additional groups. |
258 | QListViewItemIterator it( adduserDialog->groupsListView ); | 261 | QListViewItemIterator it( adduserDialog->groupsListView ); |
259 | for ( ; it.current(); ++it ) | 262 | for ( ; it.current(); ++it ) |
260 | { | 263 | { |
261 | temp=(QCheckListItem*)it.current(); | 264 | temp=(QCheckListItem*)it.current(); |
262 | if (temp->isOn() ) | 265 | if (temp->isOn() ) |
263 | accounts->addGroupMember(it.current()->text(0),adduserDialog->loginLineEdit->text()); | 266 | accounts->addGroupMember(it.current()->text(0),adduserDialog->loginLineEdit->text()); |
264 | } | 267 | } |
265 | // Copy image to pics/users/ | 268 | // Copy image to pics/users/ |
266 | if(!(adduserDialog->userImage.isNull())) | 269 | if(!(adduserDialog->userImage.isNull())) |
267 | { | 270 | { |
268 | QDir d; | 271 | QDir d; |
269 | if(!(d.exists(QPEApplication::qpeDir() + "pics/users"))) | 272 | if(!(d.exists(QPEApplication::qpeDir() + "pics/users"))) |
270 | { | 273 | { |
271 | d.mkdir(QPEApplication::qpeDir() + "pics/users"); | 274 | d.mkdir(QPEApplication::qpeDir() + "pics/users"); |
272 | } | 275 | } |
273 | QString filename= QPEApplication::qpeDir()+"pics/users/"+accounts->pw_name+".png"; | 276 | QString filename= QPEApplication::qpeDir()+"pics/users/"+accounts->pw_name+".png"; |
274 | // adduserDialog->userImage=adduserDialog->userImage.smoothScale(48,48); | 277 | // adduserDialog->userImage=adduserDialog->userImage.smoothScale(48,48); |
275 | adduserDialog->userImage.save(filename,"PNG"); | 278 | adduserDialog->userImage.save(filename,"PNG"); |
276 | } | 279 | } |
277 | 280 | ||
278 | // Should we copy the skeleton homedirectory /etc/skel to the user's homedirectory? | 281 | // Should we copy the skeleton homedirectory /etc/skel to the user's homedirectory? |
279 | accounts->findUser(adduserDialog->loginLineEdit->text()); | 282 | accounts->findUser(adduserDialog->loginLineEdit->text()); |
280 | if(adduserDialog->skelCheckBox->isChecked()) | 283 | if(adduserDialog->skelCheckBox->isChecked()) |
281 | { | 284 | { |
282 | QString command_cp; | 285 | QString command_cp; |
283 | QString command_chown; | 286 | QString command_chown; |
284 | command_cp.sprintf("cp -a /etc/skel/* %s/",accounts->pw_dir.latin1()); | 287 | command_cp.sprintf("cp -a /etc/skel/* %s/",accounts->pw_dir.latin1()); |
285 | system(command_cp); | 288 | system(command_cp); |
286 | 289 | ||
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? | 290 | 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); | 291 | system(command_cp); |
289 | 292 | ||
290 | command_chown.sprintf("chown -R %d:%d %s",accounts->pw_uid,accounts->pw_gid,accounts->pw_dir.latin1()); | 293 | command_chown.sprintf("chown -R %d:%d %s",accounts->pw_uid,accounts->pw_gid,accounts->pw_dir.latin1()); |
291 | system(command_chown); | 294 | system(command_chown); |
292 | } | 295 | } |
293 | 296 | ||
294 | return true; | 297 | return true; |
295 | } | 298 | } |
296 | 299 | ||
297 | /** | 300 | /** |
298 | * Deletes the user account. | 301 | * Deletes the user account. |
299 | * | 302 | * |
300 | * @param username User to be deleted. | 303 | * @param username User to be deleted. |
301 | * | 304 | * |
302 | * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. | 305 | * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. |
303 | * | 306 | * |
304 | */ | 307 | */ |
305 | bool UserDialog::delUser(const char *username) | 308 | bool UserDialog::delUser(const char *username) |
306 | { | 309 | { |
307 | if((accounts->findUser(username))) | 310 | if((accounts->findUser(username))) |
308 | { // Does that user exist? | 311 | { // Does that user exist? |
309 | if(!(accounts->delUser(username))) | 312 | if(!(accounts->delUser(username))) |
310 | { // Delete the user. | 313 | { // Delete the user. |
311 | QMessageBox::information(0,"Ooops!","Something went wrong\nUnable to delete user: "+QString(username)+"."); | 314 | QMessageBox::information(0,"Ooops!","Something went wrong\nUnable to delete user: "+QString(username)+"."); |
312 | } | 315 | } |
313 | } | 316 | } |
314 | else | 317 | else |
315 | { | 318 | { |
316 | QMessageBox::information(0,"Invalid Username","That username ("+QString(username)+")does not exist."); | 319 | QMessageBox::information(0,"Invalid Username","That username ("+QString(username)+")does not exist."); |
317 | return false; | 320 | return false; |
318 | } | 321 | } |
319 | return true; | 322 | return true; |
320 | } | 323 | } |
321 | 324 | ||
322 | /** | 325 | /** |
323 | * This displays a confirmation dialog wether a user should be deleted or not. | 326 | * This displays a confirmation dialog wether a user should be deleted or not. |
324 | * (And also deletes the account) | 327 | * (And also deletes the account) |
325 | * | 328 | * |
326 | * @param username User to be deleted. | 329 | * @param username User to be deleted. |
327 | * | 330 | * |
328 | * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. | 331 | * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. |
329 | * | 332 | * |
330 | */ | 333 | */ |
331 | bool UserDialog::editUser(const char *username) | 334 | bool UserDialog::editUser(const char *username) |
332 | { | 335 | { |
333 | int invalid_group=0; | 336 | int invalid_group=0; |
334 | // viewmode is a workaround for a bug in qte-2.3.4 that gives bus error on manipulating edituserDialog's widgets here. | 337 | // viewmode is a workaround for a bug in qte-2.3.4 that gives bus error on manipulating edituserDialog's widgets here. |
335 | UserDialog *edituserDialog=new UserDialog(VIEWMODE_EDIT); // Create Dialog | 338 | UserDialog *edituserDialog=new UserDialog(VIEWMODE_EDIT); // Create Dialog |
336 | edituserDialog->setCaption(tr("Edit User")); | 339 | edituserDialog->setCaption(tr("Edit User")); |
337 | accounts->findUser(username); // Locate user in database and fill variables in 'accounts' object. | 340 | accounts->findUser(username); // Locate user in database and fill variables in 'accounts' object. |
338 | if(!(accounts->findGroup(accounts->pw_gid))) | 341 | if(!(accounts->findGroup(accounts->pw_gid))) |
339 | { // Locate the user's primary group, and fill group variables in 'accounts' object. | 342 | { // Locate the user's primary group, and fill group variables in 'accounts' object. |
340 | invalid_group=1; | 343 | invalid_group=1; |
341 | } | 344 | } |
342 | // Fill widgets with userinfo. | 345 | // Fill widgets with userinfo. |
343 | edituserDialog->loginLineEdit->setText(accounts->pw_name); | 346 | edituserDialog->loginLineEdit->setText(accounts->pw_name); |