-rw-r--r-- | noncore/settings/usermanager/userdialog.cpp | 37 | ||||
-rw-r--r-- | noncore/settings/usermanager/userdialog.h | 1 | ||||
-rw-r--r-- | noncore/settings/usermanager/usermanager.cpp | 7 |
3 files changed, 39 insertions, 6 deletions
diff --git a/noncore/settings/usermanager/userdialog.cpp b/noncore/settings/usermanager/userdialog.cpp index 6940a3b..c6b8a57 100644 --- a/noncore/settings/usermanager/userdialog.cpp +++ b/noncore/settings/usermanager/userdialog.cpp | |||
@@ -194,24 +194,34 @@ bool UserDialog::addUser(int uid, int gid) { | |||
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 | QListViewItemIterator it( adduserDialog->groupsListView ); | 201 | QListViewItemIterator it( adduserDialog->groupsListView ); |
202 | for ( ; it.current(); ++it ) { | 202 | for ( ; it.current(); ++it ) { |
203 | if ( it.current()->isSelected() ) | 203 | if ( it.current()->isSelected() ) |
204 | accounts->addGroupMember(it.current()->text(0),adduserDialog->loginLineEdit->text()); | 204 | accounts->addGroupMember(it.current()->text(0),adduserDialog->loginLineEdit->text()); |
205 | } | 205 | } |
206 | // Copy image to pics/users/ | ||
207 | if(!(adduserDialog->userImage.isNull())) { | ||
208 | QDir d; | ||
209 | if(!(d.exists("/opt/QtPalmtop/pics/users"))) { | ||
210 | d.mkdir("/opt/QtPalmtop/pics/users"); | ||
211 | } | ||
212 | QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; | ||
213 | adduserDialog->userImage=adduserDialog->userImage.smoothScale(48,48); | ||
214 | adduserDialog->userImage.save(filename,"PNG"); | ||
215 | } | ||
206 | return true; | 216 | return true; |
207 | } | 217 | } |
208 | 218 | ||
209 | /** | 219 | /** |
210 | * Deletes the user account. | 220 | * Deletes the user account. |
211 | * | 221 | * |
212 | * @param username User to be deleted. | 222 | * @param username User to be deleted. |
213 | * | 223 | * |
214 | * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. | 224 | * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. |
215 | * | 225 | * |
216 | */ | 226 | */ |
217 | bool UserDialog::delUser(const char *username) { | 227 | bool UserDialog::delUser(const char *username) { |
@@ -287,39 +297,58 @@ bool UserDialog::editUser(const char *username) { | |||
287 | 297 | ||
288 | // Remove user from all groups he/she is a member of. (could be done in a better way I guess, this was simple though.) | 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.) |
289 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) { | 299 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) { |
290 | accounts->delGroupMember((*it).left((*it).find(":")),username); | 300 | accounts->delGroupMember((*it).left((*it).find(":")),username); |
291 | } | 301 | } |
292 | 302 | ||
293 | // Add User to additional groups that he/she is a member of. | 303 | // Add User to additional groups that he/she is a member of. |
294 | QListViewItemIterator it( edituserDialog->groupsListView ); | 304 | QListViewItemIterator it( edituserDialog->groupsListView ); |
295 | for ( ; it.current(); ++it ) { | 305 | for ( ; it.current(); ++it ) { |
296 | if ( it.current()->isSelected() ) | 306 | if ( it.current()->isSelected() ) |
297 | accounts->addGroupMember(it.current()->text(0),edituserDialog->loginLineEdit->text()); | 307 | accounts->addGroupMember(it.current()->text(0),edituserDialog->loginLineEdit->text()); |
298 | } | 308 | } |
309 | |||
310 | // Copy image to pics/users/ | ||
311 | if(!(edituserDialog->userImage.isNull())) { | ||
312 | QDir d; | ||
313 | if(!(d.exists("/opt/QtPalmtop/pics/users"))) { | ||
314 | d.mkdir("/opt/QtPalmtop/pics/users"); | ||
315 | } | ||
316 | QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; | ||
317 | edituserDialog->userImage=edituserDialog->userImage.smoothScale(48,48); | ||
318 | edituserDialog->userImage.save(filename,"PNG"); | ||
319 | } | ||
299 | return true; | 320 | return true; |
300 | } | 321 | } |
301 | 322 | ||
302 | /** | 323 | /** |
303 | * "OK" has been clicked. Verify some information before closing the dialog. | 324 | * "OK" has been clicked. Verify some information before closing the dialog. |
304 | * | 325 | * |
305 | */ | 326 | */ |
306 | void UserDialog::accept() { | 327 | void UserDialog::accept() { |
307 | // Add checking... valid username? username taken? | 328 | // Add checking... valid username? username taken? |
308 | if(loginLineEdit->text().isEmpty()) { | 329 | if(loginLineEdit->text().isEmpty()) { |
309 | QMessageBox::information(0,"Empty Login","Please enter a login."); | 330 | QMessageBox::information(0,"Empty Login","Please enter a login."); |
310 | return; | 331 | return; |
311 | } | 332 | } |
312 | QDialog::accept(); | 333 | QDialog::accept(); |
313 | } | 334 | } |
314 | 335 | ||
315 | /** | 336 | /** |
316 | * This slot is called when the usericon is clicked, this loads (should) the iconselector. | 337 | * This slot is called when the usericon is clicked, this loads (should) the iconselector. |
317 | * | 338 | * |
318 | */ | 339 | */ |
319 | void UserDialog::clickedPicture() { | 340 | void UserDialog::clickedPicture() { |
320 | QString filename=OFileDialog::getOpenFileName(OFileSelector::EXTENDED,"/opt/QtPalmtop/pics"); | 341 | QString filename=OFileDialog::getOpenFileName(OFileSelector::EXTENDED,"/opt/QtPalmtop/pics"); |
321 | // OFileDialog *fd=new OFileDialog("Select Icon",this, OFileSelector::OPEN, OFileSelector::EXTENDED,"/"); | 342 | if(!(filename.isEmpty())) { |
322 | //fd->showMaximized(); | 343 | userImage.reset(); |
323 | //fd->exec(); | 344 | if(!(userImage.load(filename))) { |
324 | QMessageBox::information(0,"Sorry!","Icon selection not yet implemented.\nComming real soon now! (tm)\n"+filename); | 345 | QMessageBox::information(0,"Sorry!","Icon selection not yet implemented.\nComming real soon now! (tm)\n"+filename); |
346 | } else { | ||
347 | userImage=userImage.smoothScale(48,48); | ||
348 | QPixmap *picture; | ||
349 | picture=(QPixmap *)picturePushButton->pixmap(); | ||
350 | picture->convertFromImage(userImage,0); | ||
351 | picturePushButton->update(); | ||
352 | } | ||
353 | } | ||
325 | } | 354 | } |
diff --git a/noncore/settings/usermanager/userdialog.h b/noncore/settings/usermanager/userdialog.h index df54269..a878588 100644 --- a/noncore/settings/usermanager/userdialog.h +++ b/noncore/settings/usermanager/userdialog.h | |||
@@ -27,24 +27,25 @@ private: | |||
27 | QTabWidget *myTabWidget; | 27 | QTabWidget *myTabWidget; |
28 | QPushButton *picturePushButton; | 28 | QPushButton *picturePushButton; |
29 | QLineEdit *loginLineEdit; | 29 | QLineEdit *loginLineEdit; |
30 | QLineEdit *uidLineEdit; | 30 | QLineEdit *uidLineEdit; |
31 | QLineEdit *gecosLineEdit; | 31 | QLineEdit *gecosLineEdit; |
32 | QLineEdit *passwordLineEdit; | 32 | QLineEdit *passwordLineEdit; |
33 | QComboBox *shellComboBox; | 33 | QComboBox *shellComboBox; |
34 | QComboBox *groupComboBox; | 34 | QComboBox *groupComboBox; |
35 | QListView *groupsListView; | 35 | QListView *groupsListView; |
36 | 36 | ||
37 | QStringList groupMembers; | 37 | QStringList groupMembers; |
38 | QString pictureLocation; | 38 | QString pictureLocation; |
39 | QImage userImage; | ||
39 | int groupID; | 40 | int groupID; |
40 | int userID; | 41 | int userID; |
41 | 42 | ||
42 | void setupTab1(void); | 43 | void setupTab1(void); |
43 | void setupTab2(void); | 44 | void setupTab2(void); |
44 | void accept(void); | 45 | void accept(void); |
45 | 46 | ||
46 | private slots: | 47 | private slots: |
47 | void clickedPicture(void); | 48 | void clickedPicture(void); |
48 | 49 | ||
49 | public: | 50 | public: |
50 | UserDialog( QWidget* parent = 0, const char* name = 0, bool modal=true, WFlags fl = 0 ); | 51 | UserDialog( QWidget* parent = 0, const char* name = 0, bool modal=true, WFlags fl = 0 ); |
diff --git a/noncore/settings/usermanager/usermanager.cpp b/noncore/settings/usermanager/usermanager.cpp index 87dd7f1..ed18b7f 100644 --- a/noncore/settings/usermanager/usermanager.cpp +++ b/noncore/settings/usermanager/usermanager.cpp | |||
@@ -64,24 +64,25 @@ UserConfig::UserConfig(QWidget* parent, const char* name, WFlags fl) : QMainWind | |||
64 | UserConfig::~UserConfig() { | 64 | UserConfig::~UserConfig() { |
65 | accounts->close(); | 65 | accounts->close(); |
66 | delete accounts; | 66 | delete accounts; |
67 | } | 67 | } |
68 | 68 | ||
69 | void UserConfig::setupTabAccounts() { | 69 | void UserConfig::setupTabAccounts() { |
70 | QWidget *tabpage = new QWidget(this); | 70 | QWidget *tabpage = new QWidget(this); |
71 | QVBoxLayout *layout = new QVBoxLayout(tabpage); | 71 | QVBoxLayout *layout = new QVBoxLayout(tabpage); |
72 | layout->setMargin(5); | 72 | layout->setMargin(5); |
73 | 73 | ||
74 | usersIconView=new QIconView(tabpage,"users"); | 74 | usersIconView=new QIconView(tabpage,"users"); |
75 | usersIconView->setItemTextPos(QIconView::Right); | 75 | usersIconView->setItemTextPos(QIconView::Right); |
76 | usersIconView->setArrangement(QIconView::LeftToRight); | ||
76 | layout->addWidget(usersIconView); | 77 | layout->addWidget(usersIconView); |
77 | 78 | ||
78 | myTabWidget->addTab(tabpage,"Users"); | 79 | myTabWidget->addTab(tabpage,"Users"); |
79 | } | 80 | } |
80 | 81 | ||
81 | void UserConfig::setupTabAllUsers() { | 82 | void UserConfig::setupTabAllUsers() { |
82 | QWidget *tabpage = new QWidget(this); | 83 | QWidget *tabpage = new QWidget(this); |
83 | QVBoxLayout *layout = new QVBoxLayout(tabpage); | 84 | QVBoxLayout *layout = new QVBoxLayout(tabpage); |
84 | layout->setMargin(5); | 85 | layout->setMargin(5); |
85 | 86 | ||
86 | usersListView=new QListView(tabpage,"allusers"); | 87 | usersListView=new QListView(tabpage,"allusers"); |
87 | usersListView->addColumn("UID"); | 88 | usersListView->addColumn("UID"); |
@@ -114,32 +115,34 @@ void UserConfig::getUsers() { | |||
114 | 115 | ||
115 | // Empty the iconview & the listview. | 116 | // Empty the iconview & the listview. |
116 | usersIconView->clear(); | 117 | usersIconView->clear(); |
117 | usersListView->clear(); | 118 | usersListView->clear(); |
118 | 119 | ||
119 | // availableUID is used as a deposite for the next available UID on the system, this should start at an ID over 500. | 120 | // availableUID is used as a deposite for the next available UID on the system, this should start at an ID over 500. |
120 | availableUID=500; | 121 | availableUID=500; |
121 | for(QStringList::Iterator it=accounts->passwdStringList.begin(); it!=accounts->passwdStringList.end(); ++it) { | 122 | for(QStringList::Iterator it=accounts->passwdStringList.begin(); it!=accounts->passwdStringList.end(); ++it) { |
122 | accounts->splitPasswdEntry(*it); // Split the string into it's components and store in variables in the accounts object. ("pr_name" and so on.) | 123 | accounts->splitPasswdEntry(*it); // Split the string into it's components and store in variables in the accounts object. ("pr_name" and so on.) |
123 | new QListViewItem(usersListView,QString::number(accounts->pw_uid),accounts->pw_name,accounts->pw_gecos); | 124 | new QListViewItem(usersListView,QString::number(accounts->pw_uid),accounts->pw_name,accounts->pw_gecos); |
124 | if((accounts->pw_uid>=500) && (accounts->pw_uid<65000)) {// Is this user a "normal" user ? | 125 | if((accounts->pw_uid>=500) && (accounts->pw_uid<65000)) {// Is this user a "normal" user ? |
125 | mytext=QString(accounts->pw_name)+" - ("+QString(accounts->pw_gecos)+")"; // The string displayed next to the icon. | 126 | mytext=QString(accounts->pw_name)+" - ("+QString(accounts->pw_gecos)+")"; // The string displayed next to the icon. |
126 | mypixmap=Resource::loadPixmap(QString("users/"+accounts->pw_name));// Is there an icon for this user? | 127 | // mypixmap=Resource::loadPixmap(QString("users/"+accounts->pw_name));// Is there an icon for this user? Resource::loadPixmap is caching, doesn't work. |
127 | if(mypixmap.isNull()) { | 128 | if(!(mypixmap.load("/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"))) { |
129 | // if(mypixmap.isNull()) { | ||
128 | mypixmap=Resource::loadPixmap(QString("usermanager/usericon"));// If this user has no icon, load the default icon. | 130 | mypixmap=Resource::loadPixmap(QString("usermanager/usericon"));// If this user has no icon, load the default icon. |
129 | } | 131 | } |
130 | new QIconViewItem(usersIconView,mytext,mypixmap);// Add the icon+text to the qiconview. | 132 | new QIconViewItem(usersIconView,mytext,mypixmap);// Add the icon+text to the qiconview. |
131 | } | 133 | } |
132 | if((accounts->pw_uid>=availableUID) && (accounts->pw_uid<65000)) availableUID=accounts->pw_uid+1; // Increase 1 to the latest know UID to get a free uid. | 134 | if((accounts->pw_uid>=availableUID) && (accounts->pw_uid<65000)) availableUID=accounts->pw_uid+1; // Increase 1 to the latest know UID to get a free uid. |
133 | } | 135 | } |
136 | usersIconView->sort(); | ||
134 | } | 137 | } |
135 | 138 | ||
136 | void UserConfig::addUser() { | 139 | void UserConfig::addUser() { |
137 | if(UserDialog::addUser(availableUID,availableGID)) {// Add the user to the system, also send next available UID and GID. | 140 | if(UserDialog::addUser(availableUID,availableGID)) {// Add the user to the system, also send next available UID and GID. |
138 | getUsers(); // Update users views. | 141 | getUsers(); // Update users views. |
139 | getGroups(); // Update groups view. | 142 | getGroups(); // Update groups view. |
140 | } | 143 | } |
141 | } | 144 | } |
142 | 145 | ||
143 | void UserConfig::editUser() { | 146 | void UserConfig::editUser() { |
144 | QString username; | 147 | QString username; |
145 | if(myTabWidget->currentPageIndex()==0) {// Users | 148 | if(myTabWidget->currentPageIndex()==0) {// Users |