Diffstat (limited to 'noncore/settings/usermanager/userdialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/usermanager/userdialog.cpp | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/noncore/settings/usermanager/userdialog.cpp b/noncore/settings/usermanager/userdialog.cpp index 719dd1e..b7827a4 100644 --- a/noncore/settings/usermanager/userdialog.cpp +++ b/noncore/settings/usermanager/userdialog.cpp | |||
@@ -146,25 +146,25 @@ void UserDialog::setupTab1() { | |||
146 | * Creates the second tab containing additional groups for the user. | 146 | * Creates the second tab containing additional groups for the user. |
147 | * | 147 | * |
148 | */ | 148 | */ |
149 | void UserDialog::setupTab2() { | 149 | void UserDialog::setupTab2() { |
150 | QWidget *tabpage = new QWidget(myTabWidget,"page2"); | 150 | QWidget *tabpage = new QWidget(myTabWidget,"page2"); |
151 | QVBoxLayout *layout = new QVBoxLayout(tabpage); | 151 | QVBoxLayout *layout = new QVBoxLayout(tabpage); |
152 | layout->setMargin(5); | 152 | layout->setMargin(5); |
153 | 153 | ||
154 | // Additional groups | 154 | // Additional groups |
155 | groupsListView=new QListView(tabpage,"groups"); | 155 | groupsListView=new QListView(tabpage,"groups"); |
156 | groupsListView->addColumn("Additional groups"); | 156 | groupsListView->addColumn("Additional groups"); |
157 | groupsListView->setColumnWidthMode(0,QListView::Maximum); | 157 | groupsListView->setColumnWidthMode(0,QListView::Maximum); |
158 | groupsListView->setMultiSelection(true); | 158 | groupsListView->setMultiSelection(false); |
159 | groupsListView->setAllColumnsShowFocus(false); | 159 | groupsListView->setAllColumnsShowFocus(false); |
160 | 160 | ||
161 | layout->addSpacing(5); | 161 | layout->addSpacing(5); |
162 | // Grouplist | 162 | // Grouplist |
163 | layout->addWidget(groupsListView); | 163 | layout->addWidget(groupsListView); |
164 | 164 | ||
165 | myTabWidget->addTab(tabpage,"User Groups"); | 165 | myTabWidget->addTab(tabpage,"User Groups"); |
166 | } | 166 | } |
167 | 167 | ||
168 | /** | 168 | /** |
169 | * Static function that creates the userinfo dialog. | 169 | * Static function that creates the userinfo dialog. |
170 | * The user will be prompted to add a user. | 170 | * The user will be prompted to add a user. |
@@ -189,37 +189,39 @@ bool UserDialog::addUser(int uid, int gid) { | |||
189 | accounts->findGroup(adduserDialog->groupComboBox->currentText()); | 189 | accounts->findGroup(adduserDialog->groupComboBox->currentText()); |
190 | adduserDialog->groupID=accounts->gr_gid; | 190 | adduserDialog->groupID=accounts->gr_gid; |
191 | qWarning(QString::number(accounts->gr_gid)); | 191 | qWarning(QString::number(accounts->gr_gid)); |
192 | } | 192 | } |
193 | if(!(accounts->addUser(adduserDialog->loginLineEdit->text(), adduserDialog->passwordLineEdit->text(), | 193 | if(!(accounts->addUser(adduserDialog->loginLineEdit->text(), adduserDialog->passwordLineEdit->text(), |
194 | adduserDialog->uidLineEdit->text().toInt(), adduserDialog->groupID, adduserDialog->gecosLineEdit->text(), | 194 | adduserDialog->uidLineEdit->text().toInt(), adduserDialog->groupID, adduserDialog->gecosLineEdit->text(), |
195 | QString("/home/")+adduserDialog->loginLineEdit->text() , adduserDialog->shellComboBox->currentText()))) { | 195 | QString("/home/")+adduserDialog->loginLineEdit->text() , adduserDialog->shellComboBox->currentText()))) { |
196 | QMessageBox::information(0,"Ooops!","Something went wrong!\nUnable to add user."); | 196 | QMessageBox::information(0,"Ooops!","Something went wrong!\nUnable to add user."); |
197 | return false; | 197 | return false; |
198 | } | 198 | } |
199 | 199 | ||
200 | // Add User to additional groups. | 200 | // Add User to additional groups. |
201 | QCheckListItem *temp; | ||
201 | QListViewItemIterator it( adduserDialog->groupsListView ); | 202 | QListViewItemIterator it( adduserDialog->groupsListView ); |
202 | for ( ; it.current(); ++it ) { | 203 | for ( ; it.current(); ++it ) { |
203 | if ( it.current()->isSelected() ) | 204 | temp=(QCheckListItem*)it.current(); |
205 | if (temp->isOn() ) | ||
204 | accounts->addGroupMember(it.current()->text(0),adduserDialog->loginLineEdit->text()); | 206 | accounts->addGroupMember(it.current()->text(0),adduserDialog->loginLineEdit->text()); |
205 | } | 207 | } |
206 | // Copy image to pics/users/ | 208 | // Copy image to pics/users/ |
207 | if(!(adduserDialog->userImage.isNull())) { | 209 | if(!(adduserDialog->userImage.isNull())) { |
208 | QDir d; | 210 | QDir d; |
209 | if(!(d.exists("/opt/QtPalmtop/pics/users"))) { | 211 | if(!(d.exists("/opt/QtPalmtop/pics/users"))) { |
210 | d.mkdir("/opt/QtPalmtop/pics/users"); | 212 | d.mkdir("/opt/QtPalmtop/pics/users"); |
211 | } | 213 | } |
212 | QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; | 214 | QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; |
213 | adduserDialog->userImage=adduserDialog->userImage.smoothScale(48,48); | 215 | // adduserDialog->userImage=adduserDialog->userImage.smoothScale(48,48); |
214 | adduserDialog->userImage.save(filename,"PNG"); | 216 | adduserDialog->userImage.save(filename,"PNG"); |
215 | } | 217 | } |
216 | return true; | 218 | return true; |
217 | } | 219 | } |
218 | 220 | ||
219 | /** | 221 | /** |
220 | * Deletes the user account. | 222 | * Deletes the user account. |
221 | * | 223 | * |
222 | * @param username User to be deleted. | 224 | * @param username User to be deleted. |
223 | * | 225 | * |
224 | * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. | 226 | * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. |
225 | * | 227 | * |
@@ -259,31 +261,33 @@ bool UserDialog::editUser(const char *username) { | |||
259 | // If this user is not using /bin/sh,/bin/ash or /bin/false as shell, add that entry to the shell-combobox. | 261 | // If this user is not using /bin/sh,/bin/ash or /bin/false as shell, add that entry to the shell-combobox. |
260 | if(accounts->pw_shell!="/bin/sh" && accounts->pw_shell!="/bin/ash" && accounts->pw_shell!="/bin/false") { | 262 | if(accounts->pw_shell!="/bin/sh" && accounts->pw_shell!="/bin/ash" && accounts->pw_shell!="/bin/false") { |
261 | edituserDialog->shellComboBox->insertItem(accounts->pw_shell,0); | 263 | edituserDialog->shellComboBox->insertItem(accounts->pw_shell,0); |
262 | edituserDialog->shellComboBox->setCurrentItem(0); | 264 | edituserDialog->shellComboBox->setCurrentItem(0); |
263 | } | 265 | } |
264 | // Select the primary group for this user. | 266 | // Select the primary group for this user. |
265 | for(int i=0;i<edituserDialog->groupComboBox->count();++i) { | 267 | for(int i=0;i<edituserDialog->groupComboBox->count();++i) { |
266 | if(accounts->gr_name==edituserDialog->groupComboBox->text(i)) { | 268 | if(accounts->gr_name==edituserDialog->groupComboBox->text(i)) { |
267 | edituserDialog->groupComboBox->setCurrentItem(i); | 269 | edituserDialog->groupComboBox->setCurrentItem(i); |
268 | } | 270 | } |
269 | } | 271 | } |
270 | // Select the groups in the listview, to which the user belongs. | 272 | // Select the groups in the listview, to which the user belongs. |
273 | QCheckListItem *temp; | ||
271 | QRegExp userRegExp(QString("[:\\s]%1\\s").arg(username)); | 274 | QRegExp userRegExp(QString("[:\\s]%1\\s").arg(username)); |
272 | QStringList tempList=accounts->groupStringList.grep(userRegExp);// Find all entries in the group database, that the user is a member of. | 275 | QStringList tempList=accounts->groupStringList.grep(userRegExp);// Find all entries in the group database, that the user is a member of. |
273 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) {// Iterate over all of them. | 276 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) {// Iterate over all of them. |
274 | QListViewItemIterator lvit( edituserDialog->groupsListView );// Compare to all groups. | 277 | QListViewItemIterator lvit( edituserDialog->groupsListView );// Compare to all groups. |
275 | for ( ; lvit.current(); ++lvit ) { | 278 | for ( ; lvit.current(); ++lvit ) { |
276 | if(lvit.current()->text(0)==(*it).left((*it).find(":"))) { | 279 | if(lvit.current()->text(0)==(*it).left((*it).find(":"))) { |
277 | lvit.current()->setSelected(true);// If we find a line with that groupname, select it.; | 280 | temp=(QCheckListItem*)lvit.current(); |
281 | temp->setOn(true);// If we find a line with that groupname, select it.; | ||
278 | } | 282 | } |
279 | } | 283 | } |
280 | } | 284 | } |
281 | 285 | ||
282 | if(!(edituserDialog->exec())) return false;// SHOW THE DIALOG! | 286 | if(!(edituserDialog->exec())) return false;// SHOW THE DIALOG! |
283 | 287 | ||
284 | accounts->findUser(username);// Fill user variables in 'acccounts' object. | 288 | accounts->findUser(username);// Fill user variables in 'acccounts' object. |
285 | accounts->pw_name=edituserDialog->loginLineEdit->text(); | 289 | accounts->pw_name=edituserDialog->loginLineEdit->text(); |
286 | // Has the password been changed ? Make a new "crypt":ed password. | 290 | // Has the password been changed ? Make a new "crypt":ed password. |
287 | if(edituserDialog->passwordLineEdit->text()!="........") accounts->pw_passwd=crypt(edituserDialog->passwordLineEdit->text(), accounts->crypt_make_salt()); | 291 | if(edituserDialog->passwordLineEdit->text()!="........") accounts->pw_passwd=crypt(edituserDialog->passwordLineEdit->text(), accounts->crypt_make_salt()); |
288 | 292 | ||
289 | // Set all variables in accounts object, that will be used when calling 'updateUser()' | 293 | // Set all variables in accounts object, that will be used when calling 'updateUser()' |
@@ -294,36 +298,37 @@ bool UserDialog::editUser(const char *username) { | |||
294 | accounts->pw_shell=edituserDialog->shellComboBox->currentText(); | 298 | accounts->pw_shell=edituserDialog->shellComboBox->currentText(); |
295 | // Update userinfo, using the information stored in the user variables stored in the accounts object. | 299 | // Update userinfo, using the information stored in the user variables stored in the accounts object. |
296 | accounts->updateUser(username); | 300 | accounts->updateUser(username); |
297 | 301 | ||
298 | // Remove user from all groups he/she is a member of. (could be done in a better way I guess, this was simple though.) | 302 | // Remove user from all groups he/she is a member of. (could be done in a better way I guess, this was simple though.) |
299 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) { | 303 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) { |
300 | accounts->delGroupMember((*it).left((*it).find(":")),username); | 304 | accounts->delGroupMember((*it).left((*it).find(":")),username); |
301 | } | 305 | } |
302 | 306 | ||
303 | // Add User to additional groups that he/she is a member of. | 307 | // Add User to additional groups that he/she is a member of. |
304 | QListViewItemIterator it( edituserDialog->groupsListView ); | 308 | QListViewItemIterator it( edituserDialog->groupsListView ); |
305 | for ( ; it.current(); ++it ) { | 309 | for ( ; it.current(); ++it ) { |
306 | if ( it.current()->isSelected() ) | 310 | temp=(QCheckListItem*)it.current(); |
311 | if ( temp->isOn() ) | ||
307 | accounts->addGroupMember(it.current()->text(0),edituserDialog->loginLineEdit->text()); | 312 | accounts->addGroupMember(it.current()->text(0),edituserDialog->loginLineEdit->text()); |
308 | } | 313 | } |
309 | 314 | ||
310 | // Copy image to pics/users/ | 315 | // Copy image to pics/users/ |
311 | if(!(edituserDialog->userImage.isNull())) { | 316 | if(!(edituserDialog->userImage.isNull())) { |
312 | QDir d; | 317 | QDir d; |
313 | if(!(d.exists("/opt/QtPalmtop/pics/users"))) { | 318 | if(!(d.exists("/opt/QtPalmtop/pics/users"))) { |
314 | d.mkdir("/opt/QtPalmtop/pics/users"); | 319 | d.mkdir("/opt/QtPalmtop/pics/users"); |
315 | } | 320 | } |
316 | QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; | 321 | QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; |
317 | edituserDialog->userImage=edituserDialog->userImage.smoothScale(48,48); | 322 | // edituserDialog->userImage=edituserDialog->userImage.smoothScale(48,48); |
318 | edituserDialog->userImage.save(filename,"PNG"); | 323 | edituserDialog->userImage.save(filename,"PNG"); |
319 | } | 324 | } |
320 | return true; | 325 | return true; |
321 | } | 326 | } |
322 | 327 | ||
323 | /** | 328 | /** |
324 | * "OK" has been clicked. Verify some information before closing the dialog. | 329 | * "OK" has been clicked. Verify some information before closing the dialog. |
325 | * | 330 | * |
326 | */ | 331 | */ |
327 | void UserDialog::accept() { | 332 | void UserDialog::accept() { |
328 | // Add checking... valid username? username taken? | 333 | // Add checking... valid username? username taken? |
329 | if(loginLineEdit->text().isEmpty()) { | 334 | if(loginLineEdit->text().isEmpty()) { |
@@ -335,20 +340,20 @@ void UserDialog::accept() { | |||
335 | 340 | ||
336 | /** | 341 | /** |
337 | * This slot is called when the usericon is clicked, this loads (should) the iconselector. | 342 | * This slot is called when the usericon is clicked, this loads (should) the iconselector. |
338 | * | 343 | * |
339 | */ | 344 | */ |
340 | void UserDialog::clickedPicture() { | 345 | void UserDialog::clickedPicture() { |
341 | QString filename=OFileDialog::getOpenFileName(OFileSelector::EXTENDED,"/opt/QtPalmtop/pics"); | 346 | QString filename=OFileDialog::getOpenFileName(OFileSelector::EXTENDED,"/opt/QtPalmtop/pics"); |
342 | if(!(filename.isEmpty())) { | 347 | if(!(filename.isEmpty())) { |
343 | userImage.reset(); | 348 | userImage.reset(); |
344 | if(!(userImage.load(filename))) { | 349 | if(!(userImage.load(filename))) { |
345 | QMessageBox::information(0,"Sorry!","That icon could not be loaded.\nLoading failed on: "+filename); | 350 | QMessageBox::information(0,"Sorry!","That icon could not be loaded.\nLoading failed on: "+filename); |
346 | } else { | 351 | } else { |
347 | userImage=userImage.smoothScale(48,48); | 352 | // userImage=userImage.smoothScale(48,48); |
348 | QPixmap *picture; | 353 | QPixmap *picture; |
349 | picture=(QPixmap *)picturePushButton->pixmap(); | 354 | picture=(QPixmap *)picturePushButton->pixmap(); |
350 | picture->convertFromImage(userImage,0); | 355 | picture->convertFromImage(userImage,0); |
351 | picturePushButton->update(); | 356 | picturePushButton->update(); |
352 | } | 357 | } |
353 | } | 358 | } |
354 | } | 359 | } |