summaryrefslogtreecommitdiff
path: root/noncore/settings/usermanager/usermanager.cpp
Unidiff
Diffstat (limited to 'noncore/settings/usermanager/usermanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/usermanager/usermanager.cpp21
1 files changed, 11 insertions, 10 deletions
diff --git a/noncore/settings/usermanager/usermanager.cpp b/noncore/settings/usermanager/usermanager.cpp
index ed18b7f..2735e6a 100644
--- a/noncore/settings/usermanager/usermanager.cpp
+++ b/noncore/settings/usermanager/usermanager.cpp
@@ -50,155 +50,156 @@ UserConfig::UserConfig(QWidget* parent, const char* name, WFlags fl) : QMainWind
50 addToolBar(toolbar,"myToolBar"); 50 addToolBar(toolbar,"myToolBar");
51 51
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 QListView(tabpage,"users");
75 usersIconView->setItemTextPos(QIconView::Right); 75 usersIconView->addColumn("Icon");
76 usersIconView->setArrangement(QIconView::LeftToRight); 76 usersIconView->addColumn("Username");
77 usersIconView->setAllColumnsShowFocus(true);
77 layout->addWidget(usersIconView); 78 layout->addWidget(usersIconView);
78 79
79 myTabWidget->addTab(tabpage,"Users"); 80 myTabWidget->addTab(tabpage,"Users");
80} 81}
81 82
82void UserConfig::setupTabAllUsers() { 83void UserConfig::setupTabAllUsers() {
83 QWidget *tabpage = new QWidget(this); 84 QWidget *tabpage = new QWidget(this);
84 QVBoxLayout *layout = new QVBoxLayout(tabpage); 85 QVBoxLayout *layout = new QVBoxLayout(tabpage);
85 layout->setMargin(5); 86 layout->setMargin(5);
86 87
87 usersListView=new QListView(tabpage,"allusers"); 88 usersListView=new QListView(tabpage,"allusers");
88 usersListView->addColumn("UID"); 89 usersListView->addColumn("UID");
89 usersListView->addColumn("Login"); 90 usersListView->addColumn("Login");
90 usersListView->addColumn("Username"); 91 usersListView->addColumn("Username");
91 layout->addWidget(usersListView); 92 layout->addWidget(usersListView);
92 usersListView->setSorting(1,1); 93 usersListView->setSorting(1,1);
93 usersListView->setAllColumnsShowFocus(true); 94 usersListView->setAllColumnsShowFocus(true);
94 95
95 myTabWidget->addTab(tabpage,"All Users"); 96 myTabWidget->addTab(tabpage,"All Users");
96} 97}
97 98
98void UserConfig::setupTabAllGroups() { 99void UserConfig::setupTabAllGroups() {
99 QWidget *tabpage = new QWidget(this); 100 QWidget *tabpage = new QWidget(this);
100 QVBoxLayout *layout = new QVBoxLayout(tabpage); 101 QVBoxLayout *layout = new QVBoxLayout(tabpage);
101 layout->setMargin(5); 102 layout->setMargin(5);
102 103
103 groupsListView=new QListView(tabpage,"groups"); 104 groupsListView=new QListView(tabpage,"groups");
104 groupsListView->addColumn("GID"); 105 groupsListView->addColumn("GID");
105 groupsListView->addColumn("Groupname"); 106 groupsListView->addColumn("Groupname");
106 layout->addWidget(groupsListView); 107 layout->addWidget(groupsListView);
107 groupsListView->setSorting(1,1); 108 groupsListView->setSorting(1,1);
108 groupsListView->setAllColumnsShowFocus(true); 109 groupsListView->setAllColumnsShowFocus(true);
109 110
110 myTabWidget->addTab(tabpage,"All Groups"); 111 myTabWidget->addTab(tabpage,"All Groups");
111} 112}
112void UserConfig::getUsers() { 113void UserConfig::getUsers() {
113 QString mytext; 114 QString mytext;
114 QPixmap mypixmap; 115 QPixmap mypixmap;
115 116 QListViewItem *listviewitem;
117
116 // Empty the iconview & the listview. 118 // Empty the iconview & the listview.
117 usersIconView->clear(); 119 usersIconView->clear();
118 usersListView->clear(); 120 usersListView->clear();
119 121
120 // availableUID is used as a deposite for the next available UID on the system, this should start at an ID over 500. 122 // availableUID is used as a deposite for the next available UID on the system, this should start at an ID over 500.
121 availableUID=500; 123 availableUID=500;
122 for(QStringList::Iterator it=accounts->passwdStringList.begin(); it!=accounts->passwdStringList.end(); ++it) { 124 for(QStringList::Iterator it=accounts->passwdStringList.begin(); it!=accounts->passwdStringList.end(); ++it) {
123 accounts->splitPasswdEntry(*it); // Split the string into it's components and store in variables in the accounts object. ("pr_name" and so on.) 125 accounts->splitPasswdEntry(*it); // Split the string into it's components and store in variables in the accounts object. ("pr_name" and so on.)
124 new QListViewItem(usersListView,QString::number(accounts->pw_uid),accounts->pw_name,accounts->pw_gecos); 126 new QListViewItem(usersListView,QString::number(accounts->pw_uid),accounts->pw_name,accounts->pw_gecos);
125 if((accounts->pw_uid>=500) && (accounts->pw_uid<65000)) {// Is this user a "normal" user ? 127 if((accounts->pw_uid>=500) && (accounts->pw_uid<65000)) {// Is this user a "normal" user ?
126 mytext=QString(accounts->pw_name)+" - ("+QString(accounts->pw_gecos)+")"; // The string displayed next to the icon. 128 mytext=QString(accounts->pw_name)+" - ("+QString(accounts->pw_gecos)+")"; // The string displayed next to the icon.
127 // mypixmap=Resource::loadPixmap(QString("users/"+accounts->pw_name));// Is there an icon for this user? Resource::loadPixmap is caching, doesn't work. 129 if(!(mypixmap.load("/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"))) { // Is there an icon for this user? Resource::loadPixmap is caching, doesn't work.
128 if(!(mypixmap.load("/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"))) {
129 // if(mypixmap.isNull()) {
130 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.
131 } 131 }
132 new QIconViewItem(usersIconView,mytext,mypixmap);// Add the icon+text to the qiconview. 132 listviewitem=new QListViewItem(usersIconView,"",mytext);// Add the icon+text to the qiconview.
133 listviewitem->setPixmap(0,mypixmap);
133 } 134 }
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. 135 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.
135 } 136 }
136 usersIconView->sort(); 137 usersIconView->sort();
137} 138}
138 139
139void UserConfig::addUser() { 140void UserConfig::addUser() {
140 if(UserDialog::addUser(availableUID,availableGID)) {// Add the user to the system, also send next available UID and GID. 141 if(UserDialog::addUser(availableUID,availableGID)) {// Add the user to the system, also send next available UID and GID.
141 getUsers(); // Update users views. 142 getUsers(); // Update users views.
142 getGroups(); // Update groups view. 143 getGroups(); // Update groups view.
143 } 144 }
144} 145}
145 146
146void UserConfig::editUser() { 147void UserConfig::editUser() {
147 QString username; 148 QString username;
148 if(myTabWidget->currentPageIndex()==0) {// Users 149 if(myTabWidget->currentPageIndex()==0) {// Users
149 if(usersIconView->currentItem()) {// Any icon selected? 150 if(usersIconView->currentItem()) {// Any icon selected?
150 username=usersIconView->currentItem()->text();// Get the text associated with the icon. 151 username=usersIconView->currentItem()->text(1);// Get the text associated with the icon.
151 username=username.left(username.find(" - (",0,true));// Strip out the username. 152 username=username.left(username.find(" - (",0,true));// Strip out the username.
152 if(UserDialog::editUser(username)) {// Bring up the userinfo dialog. 153 if(UserDialog::editUser(username)) {// Bring up the userinfo dialog.
153 // If there were any changed also update the views. 154 // If there were any changed also update the views.
154 getUsers(); 155 getUsers();
155 getGroups(); 156 getGroups();
156 } 157 }
157 } else { 158 } else {
158 QMessageBox::information(this,"No selection.","No user has been selected."); 159 QMessageBox::information(this,"No selection.","No user has been selected.");
159 } 160 }
160 } 161 }
161 if(myTabWidget->currentPageIndex()==1) {// All users 162 if(myTabWidget->currentPageIndex()==1) {// All users
162 if(usersListView->currentItem()) {// Anything changed!? 163 if(usersListView->currentItem()) {// Anything changed!?
163 username=usersListView->currentItem()->text(1);// Get the username. 164 username=usersListView->currentItem()->text(1);// Get the username.
164 if(UserDialog::editUser(username)) {// Bring up the userinfo dialog. 165 if(UserDialog::editUser(username)) {// Bring up the userinfo dialog.
165 // And again update the views if there were any changes. 166 // And again update the views if there were any changes.
166 getUsers(); 167 getUsers();
167 getGroups(); 168 getGroups();
168 } 169 }
169 } else { 170 } else {
170 QMessageBox::information(this,"No selection.","No user has been selected."); 171 QMessageBox::information(this,"No selection.","No user has been selected.");
171 } 172 }
172 } 173 }
173} 174}
174 175
175void UserConfig::delUser() { 176void UserConfig::delUser() {
176 QString username; 177 QString username;
177 178
178 if(myTabWidget->currentPageIndex()==0) {// Users, Iconview. 179 if(myTabWidget->currentPageIndex()==0) {// Users, Iconview.
179 if(usersIconView->currentItem()) {// Anything selected? 180 if(usersIconView->currentItem()) {// Anything selected?
180 username=usersIconView->currentItem()->text();// Get string associated with icon. 181 username=usersIconView->currentItem()->text(1);// Get string associated with icon.
181 username=username.left(username.find(" - (",0,true));// Strip out the username. 182 username=username.left(username.find(" - (",0,true));// Strip out the username.
182 if(QMessageBox::warning(this,"Delete user","Are you sure you want to\ndelete this user? \""+QString(username)+"\" ?","&No","&Yes",0,0,1)) { 183 if(QMessageBox::warning(this,"Delete user","Are you sure you want to\ndelete this user? \""+QString(username)+"\" ?","&No","&Yes",0,0,1)) {
183 if(UserDialog::delUser(username)) {// Delete the user if possible. 184 if(UserDialog::delUser(username)) {// Delete the user if possible.
184 // Update views. 185 // Update views.
185 getUsers(); 186 getUsers();
186 getGroups(); 187 getGroups();
187 } 188 }
188 } 189 }
189 } else { 190 } else {
190 QMessageBox::information(this,"No selection","No user has been selected."); 191 QMessageBox::information(this,"No selection","No user has been selected.");
191 } 192 }
192 } 193 }
193 if(myTabWidget->currentPageIndex()==1) {// All users 194 if(myTabWidget->currentPageIndex()==1) {// All users
194 if(usersListView->currentItem()) {// Anything changed!? 195 if(usersListView->currentItem()) {// Anything changed!?
195 username=usersListView->currentItem()->text(1);// Get the username. 196 username=usersListView->currentItem()->text(1);// Get the username.
196 if(QMessageBox::warning(this,"Delete user","Are you sure you want to\ndelete this user? \""+QString(username)+"\" ?","&No","&Yes",0,0,1)) { 197 if(QMessageBox::warning(this,"Delete user","Are you sure you want to\ndelete this user? \""+QString(username)+"\" ?","&No","&Yes",0,0,1)) {
197 if(UserDialog::delUser(username)) {// Try to delete the user. 198 if(UserDialog::delUser(username)) {// Try to delete the user.
198 // Update views. 199 // Update views.
199 getUsers(); 200 getUsers();
200 getGroups(); 201 getGroups();
201 } 202 }
202 } 203 }
203 } else { 204 } else {
204 QMessageBox::information(this,"No selection","No user has been selected."); 205 QMessageBox::information(this,"No selection","No user has been selected.");