summaryrefslogtreecommitdiff
path: root/noncore/settings/usermanager
Unidiff
Diffstat (limited to 'noncore/settings/usermanager') (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/usermanager/userdialog.cpp35
-rw-r--r--noncore/settings/usermanager/userdialog.h1
-rw-r--r--noncore/settings/usermanager/usermanager.cpp7
3 files changed, 38 insertions, 5 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
@@ -182,48 +182,58 @@ bool UserDialog::addUser(int uid, int gid) {
182 adduserDialog->groupID=gid;// Set next available GID as default gid. 182 adduserDialog->groupID=gid;// Set next available GID as default gid.
183 // Insert default group into groupComboBox 183 // Insert default group into groupComboBox
184 adduserDialog->groupComboBox->insertItem("<create new group>",0); 184 adduserDialog->groupComboBox->insertItem("<create new group>",0);
185 adduserDialog->uidLineEdit->setText(QString::number(uid)); 185 adduserDialog->uidLineEdit->setText(QString::number(uid));
186 // Show the dialog! 186 // Show the dialog!
187 if(!(adduserDialog->exec())) return false; 187 if(!(adduserDialog->exec())) return false;
188 if((adduserDialog->groupComboBox->currentItem()!=0)) { 188 if((adduserDialog->groupComboBox->currentItem()!=0)) {
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 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 */
217bool UserDialog::delUser(const char *username) { 227bool UserDialog::delUser(const char *username) {
218 if((accounts->findUser(username))) {// Does that user exist? 228 if((accounts->findUser(username))) {// Does that user exist?
219 if(!(accounts->delUser(username))) {// Delete the user. 229 if(!(accounts->delUser(username))) {// Delete the user.
220 QMessageBox::information(0,"Ooops!","Something went wrong\nUnable to delete user: "+QString(username)+"."); 230 QMessageBox::information(0,"Ooops!","Something went wrong\nUnable to delete user: "+QString(username)+".");
221 } 231 }
222 } else { 232 } else {
223 QMessageBox::information(0,"Invalid Username","That username ("+QString(username)+")does not exist."); 233 QMessageBox::information(0,"Invalid Username","That username ("+QString(username)+")does not exist.");
224 return false; 234 return false;
225 } 235 }
226 return true; 236 return true;
227} 237}
228 238
229/** 239/**
@@ -275,51 +285,70 @@ bool UserDialog::editUser(const char *username) {
275 accounts->pw_name=edituserDialog->loginLineEdit->text(); 285 accounts->pw_name=edituserDialog->loginLineEdit->text();
276 // Has the password been changed ? Make a new "crypt":ed password. 286 // Has the password been changed ? Make a new "crypt":ed password.
277 if(edituserDialog->passwordLineEdit->text()!="........") accounts->pw_passwd=crypt(edituserDialog->passwordLineEdit->text(), accounts->crypt_make_salt()); 287 if(edituserDialog->passwordLineEdit->text()!="........") accounts->pw_passwd=crypt(edituserDialog->passwordLineEdit->text(), accounts->crypt_make_salt());
278 288
279 // Set all variables in accounts object, that will be used when calling 'updateUser()' 289 // Set all variables in accounts object, that will be used when calling 'updateUser()'
280 accounts->pw_uid=edituserDialog->uidLineEdit->text().toInt(); 290 accounts->pw_uid=edituserDialog->uidLineEdit->text().toInt();
281 accounts->findGroup(edituserDialog->groupComboBox->currentText());// Fill all group variables in 'accounts' object. 291 accounts->findGroup(edituserDialog->groupComboBox->currentText());// Fill all group variables in 'accounts' object.
282 accounts->pw_gid=accounts->gr_gid; 292 accounts->pw_gid=accounts->gr_gid;
283 accounts->pw_gecos=edituserDialog->gecosLineEdit->text(); 293 accounts->pw_gecos=edituserDialog->gecosLineEdit->text();
284 accounts->pw_shell=edituserDialog->shellComboBox->currentText(); 294 accounts->pw_shell=edituserDialog->shellComboBox->currentText();
285 // Update userinfo, using the information stored in the user variables stored in the accounts object. 295 // Update userinfo, using the information stored in the user variables stored in the accounts object.
286 accounts->updateUser(username); 296 accounts->updateUser(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 */
306void UserDialog::accept() { 327void 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 */
319void UserDialog::clickedPicture() { 340void 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
@@ -15,43 +15,44 @@
15#include <qlistview.h> 15#include <qlistview.h>
16#include <qtabwidget.h> 16#include <qtabwidget.h>
17#include <qpushbutton.h> 17#include <qpushbutton.h>
18 18
19#include <qpe/resource.h> 19#include <qpe/resource.h>
20 20
21#include <opie/ofiledialog.h> 21#include <opie/ofiledialog.h>
22 22
23class UserDialog : public QDialog 23class UserDialog : public QDialog
24{ 24{
25 Q_OBJECT 25 Q_OBJECT
26private: 26private:
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
46private slots: 47private slots:
47 void clickedPicture(void); 48 void clickedPicture(void);
48 49
49public: 50public:
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 );
51 ~UserDialog(); 52 ~UserDialog();
52 static bool addUser(int uid, int gid); 53 static bool addUser(int uid, int gid);
53 static bool editUser(const char *username); 54 static bool editUser(const char *username);
54 static bool delUser(const char *username); 55 static bool delUser(const char *username);
55}; 56};
56 57
57#endif 58#endif
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
@@ -52,48 +52,49 @@ UserConfig::UserConfig(QWidget* parent, const char* name, WFlags fl) : QMainWind
52 // Add a tabwidget and all the tabs. 52 // Add a tabwidget and all the tabs.
53 myTabWidget = new QTabWidget(this,"My Tab Widget"); 53 myTabWidget = new QTabWidget(this,"My Tab Widget");
54 setupTabAccounts(); 54 setupTabAccounts();
55 setupTabAllUsers(); 55 setupTabAllUsers();
56 setupTabAllGroups(); 56 setupTabAllGroups();
57 57
58 getUsers(); // Fill out the iconview & listview with all users. 58 getUsers(); // Fill out the iconview & listview with all users.
59 getGroups(); // Fill out the group listview with all groups. 59 getGroups(); // Fill out the group listview with all groups.
60 60
61 setCentralWidget(myTabWidget); 61 setCentralWidget(myTabWidget);
62} 62}
63 63
64UserConfig::~UserConfig() { 64UserConfig::~UserConfig() {
65 accounts->close(); 65 accounts->close();
66 delete accounts; 66 delete accounts;
67} 67}
68 68
69void UserConfig::setupTabAccounts() { 69void 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
81void UserConfig::setupTabAllUsers() { 82void 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");
88 usersListView->addColumn("Login"); 89 usersListView->addColumn("Login");
89 usersListView->addColumn("Username"); 90 usersListView->addColumn("Username");
90 layout->addWidget(usersListView); 91 layout->addWidget(usersListView);
91 usersListView->setSorting(1,1); 92 usersListView->setSorting(1,1);
92 usersListView->setAllColumnsShowFocus(true); 93 usersListView->setAllColumnsShowFocus(true);
93 94
94 myTabWidget->addTab(tabpage,"All Users"); 95 myTabWidget->addTab(tabpage,"All Users");
95} 96}
96 97
97void UserConfig::setupTabAllGroups() { 98void UserConfig::setupTabAllGroups() {
98 QWidget *tabpage = new QWidget(this); 99 QWidget *tabpage = new QWidget(this);
99 QVBoxLayout *layout = new QVBoxLayout(tabpage); 100 QVBoxLayout *layout = new QVBoxLayout(tabpage);
@@ -102,56 +103,58 @@ void UserConfig::setupTabAllGroups() {
102 groupsListView=new QListView(tabpage,"groups"); 103 groupsListView=new QListView(tabpage,"groups");
103 groupsListView->addColumn("GID"); 104 groupsListView->addColumn("GID");
104 groupsListView->addColumn("Groupname"); 105 groupsListView->addColumn("Groupname");
105 layout->addWidget(groupsListView); 106 layout->addWidget(groupsListView);
106 groupsListView->setSorting(1,1); 107 groupsListView->setSorting(1,1);
107 groupsListView->setAllColumnsShowFocus(true); 108 groupsListView->setAllColumnsShowFocus(true);
108 109
109 myTabWidget->addTab(tabpage,"All Groups"); 110 myTabWidget->addTab(tabpage,"All Groups");
110} 111}
111void UserConfig::getUsers() { 112void UserConfig::getUsers() {
112 QString mytext; 113 QString mytext;
113 QPixmap mypixmap; 114 QPixmap mypixmap;
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
136void UserConfig::addUser() { 139void 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
143void UserConfig::editUser() { 146void UserConfig::editUser() {
144 QString username; 147 QString username;
145 if(myTabWidget->currentPageIndex()==0) {// Users 148 if(myTabWidget->currentPageIndex()==0) {// Users
146 if(usersIconView->currentItem()) {// Any icon selected? 149 if(usersIconView->currentItem()) {// Any icon selected?
147 username=usersIconView->currentItem()->text();// Get the text associated with the icon. 150 username=usersIconView->currentItem()->text();// Get the text associated with the icon.
148 username=username.left(username.find(" - (",0,true));// Strip out the username. 151 username=username.left(username.find(" - (",0,true));// Strip out the username.
149 if(UserDialog::editUser(username)) {// Bring up the userinfo dialog. 152 if(UserDialog::editUser(username)) {// Bring up the userinfo dialog.
150 // If there were any changed also update the views. 153 // If there were any changed also update the views.
151 getUsers(); 154 getUsers();
152 getGroups(); 155 getGroups();
153 } 156 }
154 } else { 157 } else {
155 QMessageBox::information(this,"No selection.","No user has been selected."); 158 QMessageBox::information(this,"No selection.","No user has been selected.");
156 } 159 }
157 } 160 }