Diffstat (limited to 'noncore/settings/usermanager/usermanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/usermanager/usermanager.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/noncore/settings/usermanager/usermanager.cpp b/noncore/settings/usermanager/usermanager.cpp index a1130d4..1d345ee 100644 --- a/noncore/settings/usermanager/usermanager.cpp +++ b/noncore/settings/usermanager/usermanager.cpp | |||
@@ -1,113 +1,116 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * This program is free software; you can redistribute it and/or modify * | 3 | * This program is free software; you can redistribute it and/or modify * |
4 | * it under the terms of the GNU General Public License as published by * | 4 | * it under the terms of the GNU General Public License as published by * |
5 | * the Free Software Foundation; either version 2 of the License, or * | 5 | * the Free Software Foundation; either version 2 of the License, or * |
6 | * (at your option) any later version. * | 6 | * (at your option) any later version. * |
7 | * * | 7 | * * |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | 9 | ||
10 | #include "usermanager.h" | 10 | #include "usermanager.h" |
11 | 11 | ||
12 | #include <qlayout.h> | 12 | /* OPIE */ |
13 | #include <opie2/odebug.h> | ||
14 | #include <qpe/resource.h> | ||
15 | using namespace Opie::Core; | ||
13 | 16 | ||
17 | /* QT */ | ||
18 | #include <qlayout.h> | ||
14 | #include <qmessagebox.h> | 19 | #include <qmessagebox.h> |
15 | #include <qfile.h> | 20 | #include <qfile.h> |
16 | #include <qpe/resource.h> | ||
17 | |||
18 | #include <qregexp.h> | 21 | #include <qregexp.h> |
19 | 22 | ||
20 | /** | 23 | /** |
21 | * The mainwindow constructor. | 24 | * The mainwindow constructor. |
22 | * | 25 | * |
23 | * @param QWidget *parent | 26 | * @param QWidget *parent |
24 | * @param const char *name | 27 | * @param const char *name |
25 | * @ param WFlags fl | 28 | * @ param WFlags fl |
26 | * | 29 | * |
27 | */ | 30 | */ |
28 | UserConfig::UserConfig(QWidget* parent, const char* name, WFlags fl) : QMainWindow(parent, name, fl) { | 31 | UserConfig::UserConfig(QWidget* parent, const char* name, WFlags fl) : QMainWindow(parent, name, fl) { |
29 | setCaption(tr("Opie User Manager")); | 32 | setCaption(tr("Opie User Manager")); |
30 | 33 | ||
31 | // Create an instance of the global object 'accounts'. This holds all user/group info, and functions to modify them. | 34 | // Create an instance of the global object 'accounts'. This holds all user/group info, and functions to modify them. |
32 | accounts=new Passwd(); | 35 | accounts=new Passwd(); |
33 | accounts->open();// This actually loads the files /etc/passwd & /etc/group into memory. | 36 | accounts->open();// This actually loads the files /etc/passwd & /etc/group into memory. |
34 | 37 | ||
35 | // Create the toolbar. | 38 | // Create the toolbar. |
36 | QToolBar *toolbar = new QToolBar(this,"Toolbar"); | 39 | QToolBar *toolbar = new QToolBar(this,"Toolbar"); |
37 | toolbar->setHorizontalStretchable(1); // Is there any other way to get the toolbar to stretch of the full screen!? | 40 | toolbar->setHorizontalStretchable(1); // Is there any other way to get the toolbar to stretch of the full screen!? |
38 | adduserToolButton = new QToolButton(Resource::loadPixmap("usermanager/adduser"),"Add User",0,this,SLOT(addUser()),toolbar,"Add User"); | 41 | adduserToolButton = new QToolButton(Resource::loadPixmap("usermanager/adduser"),"Add User",0,this,SLOT(addUser()),toolbar,"Add User"); |
39 | edituserToolButton = new QToolButton(Resource::loadPixmap("usermanager/edituser"),"Edit User",0,this,SLOT(editUser()),toolbar,"Edit User"); | 42 | edituserToolButton = new QToolButton(Resource::loadPixmap("usermanager/edituser"),"Edit User",0,this,SLOT(editUser()),toolbar,"Edit User"); |
40 | deleteuserToolButton = new QToolButton(Resource::loadPixmap("usermanager/deleteuser"),"Delete User",0,this,SLOT(delUser()),toolbar,"Delete User"); | 43 | deleteuserToolButton = new QToolButton(Resource::loadPixmap("usermanager/deleteuser"),"Delete User",0,this,SLOT(delUser()),toolbar,"Delete User"); |
41 | QToolButton *userstext = new QToolButton(0,"User",0,0,0,toolbar,"User"); | 44 | QToolButton *userstext = new QToolButton(0,"User",0,0,0,toolbar,"User"); |
42 | userstext->setUsesTextLabel(true); | 45 | userstext->setUsesTextLabel(true); |
43 | toolbar->addSeparator(); | 46 | toolbar->addSeparator(); |
44 | addgroupToolButton = new QToolButton(Resource::loadPixmap("usermanager/addgroup"),"Add Group",0,this,SLOT(addGroup()),toolbar,"Add Group"); | 47 | addgroupToolButton = new QToolButton(Resource::loadPixmap("usermanager/addgroup"),"Add Group",0,this,SLOT(addGroup()),toolbar,"Add Group"); |
45 | editgroupToolButton = new QToolButton(Resource::loadPixmap("usermanager/editgroup"),"Edit Group",0,this,SLOT(editGroup()),toolbar,"Edit Group"); | 48 | editgroupToolButton = new QToolButton(Resource::loadPixmap("usermanager/editgroup"),"Edit Group",0,this,SLOT(editGroup()),toolbar,"Edit Group"); |
46 | deletegroupToolButton = new QToolButton(Resource::loadPixmap("usermanager/deletegroup"),"Delete Group",0,this,SLOT(delGroup()),toolbar,"Delete Group"); | 49 | deletegroupToolButton = new QToolButton(Resource::loadPixmap("usermanager/deletegroup"),"Delete Group",0,this,SLOT(delGroup()),toolbar,"Delete Group"); |
47 | QToolButton *groupstext = new QToolButton(0,"Group",0,0,0,toolbar,"Group"); | 50 | QToolButton *groupstext = new QToolButton(0,"Group",0,0,0,toolbar,"Group"); |
48 | groupstext->setUsesTextLabel(true); | 51 | groupstext->setUsesTextLabel(true); |
49 | addToolBar(toolbar,"myToolBar"); | 52 | addToolBar(toolbar,"myToolBar"); |
50 | 53 | ||
51 | // Add a tabwidget and all the tabs. | 54 | // Add a tabwidget and all the tabs. |
52 | myTabWidget = new QTabWidget(this,"My Tab Widget"); | 55 | myTabWidget = new QTabWidget(this,"My Tab Widget"); |
53 | setupTabAccounts(); | 56 | setupTabAccounts(); |
54 | setupTabAllUsers(); | 57 | setupTabAllUsers(); |
55 | setupTabAllGroups(); | 58 | setupTabAllGroups(); |
56 | userPopupMenu.insertItem("Copy",0); | 59 | userPopupMenu.insertItem("Copy",0); |
57 | 60 | ||
58 | getUsers(); // Fill out the iconview & listview with all users. | 61 | getUsers(); // Fill out the iconview & listview with all users. |
59 | getGroups(); // Fill out the group listview with all groups. | 62 | getGroups(); // Fill out the group listview with all groups. |
60 | 63 | ||
61 | setCentralWidget(myTabWidget); | 64 | setCentralWidget(myTabWidget); |
62 | } | 65 | } |
63 | 66 | ||
64 | UserConfig::~UserConfig() { | 67 | UserConfig::~UserConfig() { |
65 | accounts->close(); | 68 | accounts->close(); |
66 | delete accounts; | 69 | delete accounts; |
67 | } | 70 | } |
68 | 71 | ||
69 | void UserConfig::setupTabAccounts() { | 72 | void UserConfig::setupTabAccounts() { |
70 | QWidget *tabpage = new QWidget(this); | 73 | QWidget *tabpage = new QWidget(this); |
71 | QVBoxLayout *layout = new QVBoxLayout(tabpage); | 74 | QVBoxLayout *layout = new QVBoxLayout(tabpage); |
72 | layout->setMargin(5); | 75 | layout->setMargin(5); |
73 | 76 | ||
74 | usersIconView=new QListView(tabpage,"users"); | 77 | usersIconView=new QListView(tabpage,"users"); |
75 | usersIconView->addColumn("Icon"); | 78 | usersIconView->addColumn("Icon"); |
76 | usersIconView->addColumn("Username"); | 79 | usersIconView->addColumn("Username"); |
77 | usersIconView->setAllColumnsShowFocus(true); | 80 | usersIconView->setAllColumnsShowFocus(true); |
78 | layout->addWidget(usersIconView); | 81 | layout->addWidget(usersIconView); |
79 | 82 | ||
80 | connect(usersIconView,SIGNAL(returnPressed(QListViewItem*)),this,SLOT(showUserMenu(QListViewItem*))); | 83 | connect(usersIconView,SIGNAL(returnPressed(QListViewItem*)),this,SLOT(showUserMenu(QListViewItem*))); |
81 | 84 | ||
82 | myTabWidget->addTab(tabpage,"Users"); | 85 | myTabWidget->addTab(tabpage,"Users"); |
83 | } | 86 | } |
84 | 87 | ||
85 | void UserConfig::setupTabAllUsers() { | 88 | void UserConfig::setupTabAllUsers() { |
86 | QWidget *tabpage = new QWidget(this); | 89 | QWidget *tabpage = new QWidget(this); |
87 | QVBoxLayout *layout = new QVBoxLayout(tabpage); | 90 | QVBoxLayout *layout = new QVBoxLayout(tabpage); |
88 | layout->setMargin(5); | 91 | layout->setMargin(5); |
89 | 92 | ||
90 | usersListView=new QListView(tabpage,"allusers"); | 93 | usersListView=new QListView(tabpage,"allusers"); |
91 | usersListView->addColumn("UID"); | 94 | usersListView->addColumn("UID"); |
92 | usersListView->addColumn("Login"); | 95 | usersListView->addColumn("Login"); |
93 | usersListView->addColumn("Username"); | 96 | usersListView->addColumn("Username"); |
94 | layout->addWidget(usersListView); | 97 | layout->addWidget(usersListView); |
95 | usersListView->setSorting(1,1); | 98 | usersListView->setSorting(1,1); |
96 | usersListView->setAllColumnsShowFocus(true); | 99 | usersListView->setAllColumnsShowFocus(true); |
97 | 100 | ||
98 | myTabWidget->addTab(tabpage,"All Users"); | 101 | myTabWidget->addTab(tabpage,"All Users"); |
99 | } | 102 | } |
100 | 103 | ||
101 | void UserConfig::setupTabAllGroups() { | 104 | void UserConfig::setupTabAllGroups() { |
102 | QWidget *tabpage = new QWidget(this); | 105 | QWidget *tabpage = new QWidget(this); |
103 | QVBoxLayout *layout = new QVBoxLayout(tabpage); | 106 | QVBoxLayout *layout = new QVBoxLayout(tabpage); |
104 | layout->setMargin(5); | 107 | layout->setMargin(5); |
105 | 108 | ||
106 | groupsListView=new QListView(tabpage,"groups"); | 109 | groupsListView=new QListView(tabpage,"groups"); |
107 | groupsListView->addColumn("GID"); | 110 | groupsListView->addColumn("GID"); |
108 | groupsListView->addColumn("Groupname"); | 111 | groupsListView->addColumn("Groupname"); |
109 | layout->addWidget(groupsListView); | 112 | layout->addWidget(groupsListView); |
110 | groupsListView->setSorting(1,1); | 113 | groupsListView->setSorting(1,1); |
111 | groupsListView->setAllColumnsShowFocus(true); | 114 | groupsListView->setAllColumnsShowFocus(true); |
112 | 115 | ||
113 | myTabWidget->addTab(tabpage,"All Groups"); | 116 | myTabWidget->addTab(tabpage,"All Groups"); |
@@ -160,98 +163,98 @@ void UserConfig::editUser() { | |||
160 | getGroups(); | 163 | getGroups(); |
161 | } | 164 | } |
162 | } else { | 165 | } else { |
163 | QMessageBox::information(this,"No selection.","No user has been selected."); | 166 | QMessageBox::information(this,"No selection.","No user has been selected."); |
164 | } | 167 | } |
165 | } | 168 | } |
166 | if(myTabWidget->currentPageIndex()==1) {// All users | 169 | if(myTabWidget->currentPageIndex()==1) {// All users |
167 | if(usersListView->currentItem()) {// Anything changed!? | 170 | if(usersListView->currentItem()) {// Anything changed!? |
168 | username=usersListView->currentItem()->text(1);// Get the username. | 171 | username=usersListView->currentItem()->text(1);// Get the username. |
169 | if(UserDialog::editUser(username)) {// Bring up the userinfo dialog. | 172 | if(UserDialog::editUser(username)) {// Bring up the userinfo dialog. |
170 | // And again update the views if there were any changes. | 173 | // And again update the views if there were any changes. |
171 | getUsers(); | 174 | getUsers(); |
172 | getGroups(); | 175 | getGroups(); |
173 | } | 176 | } |
174 | } else { | 177 | } else { |
175 | QMessageBox::information(this,"No selection.","No user has been selected."); | 178 | QMessageBox::information(this,"No selection.","No user has been selected."); |
176 | } | 179 | } |
177 | } | 180 | } |
178 | } | 181 | } |
179 | 182 | ||
180 | void UserConfig::delUser() { | 183 | void UserConfig::delUser() { |
181 | QString username; | 184 | QString username; |
182 | 185 | ||
183 | if(myTabWidget->currentPageIndex()==0) {// Users, Iconview. | 186 | if(myTabWidget->currentPageIndex()==0) {// Users, Iconview. |
184 | if(usersIconView->currentItem()) {// Anything selected? | 187 | if(usersIconView->currentItem()) {// Anything selected? |
185 | username=usersIconView->currentItem()->text(1);// Get string associated with icon. | 188 | username=usersIconView->currentItem()->text(1);// Get string associated with icon. |
186 | username=username.left(username.find(" - (",0,true));// Strip out the username. | 189 | username=username.left(username.find(" - (",0,true));// Strip out the username. |
187 | if(QMessageBox::warning(this,"Delete user","Are you sure you want to\ndelete this user? \""+QString(username)+"\" ?","&No","&Yes",0,0,1)) { | 190 | if(QMessageBox::warning(this,"Delete user","Are you sure you want to\ndelete this user? \""+QString(username)+"\" ?","&No","&Yes",0,0,1)) { |
188 | if(UserDialog::delUser(username)) {// Delete the user if possible. | 191 | if(UserDialog::delUser(username)) {// Delete the user if possible. |
189 | // Update views. | 192 | // Update views. |
190 | getUsers(); | 193 | getUsers(); |
191 | getGroups(); | 194 | getGroups(); |
192 | } | 195 | } |
193 | } | 196 | } |
194 | } else { | 197 | } else { |
195 | QMessageBox::information(this,"No selection","No user has been selected."); | 198 | QMessageBox::information(this,"No selection","No user has been selected."); |
196 | } | 199 | } |
197 | } | 200 | } |
198 | if(myTabWidget->currentPageIndex()==1) {// All users | 201 | if(myTabWidget->currentPageIndex()==1) {// All users |
199 | if(usersListView->currentItem()) {// Anything changed!? | 202 | if(usersListView->currentItem()) {// Anything changed!? |
200 | username=usersListView->currentItem()->text(1);// Get the username. | 203 | username=usersListView->currentItem()->text(1);// Get the username. |
201 | if(QMessageBox::warning(this,"Delete user","Are you sure you want to\ndelete this user? \""+QString(username)+"\" ?","&No","&Yes",0,0,1)) { | 204 | if(QMessageBox::warning(this,"Delete user","Are you sure you want to\ndelete this user? \""+QString(username)+"\" ?","&No","&Yes",0,0,1)) { |
202 | if(UserDialog::delUser(username)) {// Try to delete the user. | 205 | if(UserDialog::delUser(username)) {// Try to delete the user. |
203 | // Update views. | 206 | // Update views. |
204 | getUsers(); | 207 | getUsers(); |
205 | getGroups(); | 208 | getGroups(); |
206 | } | 209 | } |
207 | } | 210 | } |
208 | } else { | 211 | } else { |
209 | QMessageBox::information(this,"No selection","No user has been selected."); | 212 | QMessageBox::information(this,"No selection","No user has been selected."); |
210 | } | 213 | } |
211 | } | 214 | } |
212 | 215 | ||
213 | } | 216 | } |
214 | 217 | ||
215 | void UserConfig::getGroups() { | 218 | void UserConfig::getGroups() { |
216 | groupsListView->clear();// Empty the listview. | 219 | groupsListView->clear();// Empty the listview. |
217 | availableGID=500;// We need to find the next free GID, and are only interested in values between 500 & 65000. | 220 | availableGID=500;// We need to find the next free GID, and are only interested in values between 500 & 65000. |
218 | for(QStringList::Iterator it=accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) {// Split the list into lines. | 221 | for(QStringList::Iterator it=accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) {// Split the list into lines. |
219 | accounts->splitGroupEntry(*it);// Split the line into its components and fill the variables of 'accounts'. (gr_name, gr_uid & gr_mem). | 222 | accounts->splitGroupEntry(*it);// Split the line into its components and fill the variables of 'accounts'. (gr_name, gr_uid & gr_mem). |
220 | if(accounts->gr_name.find(QRegExp("^#"),0)) {// Skip commented lines. | 223 | if(accounts->gr_name.find(QRegExp("^#"),0)) {// Skip commented lines. |
221 | new QListViewItem(groupsListView,QString::number(accounts->gr_gid),accounts->gr_name); | 224 | new QListViewItem(groupsListView,QString::number(accounts->gr_gid),accounts->gr_name); |
222 | if((accounts->gr_gid>=availableGID) && (accounts->gr_gid<65000)) availableGID=accounts->gr_gid+1;// Maybe a new free GID. | 225 | if((accounts->gr_gid>=availableGID) && (accounts->gr_gid<65000)) availableGID=accounts->gr_gid+1;// Maybe a new free GID. |
223 | } | 226 | } |
224 | } | 227 | } |
225 | } | 228 | } |
226 | 229 | ||
227 | void UserConfig::addGroup() { | 230 | void UserConfig::addGroup() { |
228 | if(GroupDialog::addGroup(availableGID)) getGroups();// Bring up the add group dialog. | 231 | if(GroupDialog::addGroup(availableGID)) getGroups();// Bring up the add group dialog. |
229 | } | 232 | } |
230 | 233 | ||
231 | void UserConfig::editGroup() { | 234 | void UserConfig::editGroup() { |
232 | int gid; | 235 | int gid; |
233 | if(groupsListView->currentItem()) {// Any group selected? | 236 | if(groupsListView->currentItem()) {// Any group selected? |
234 | gid=groupsListView->currentItem()->text(0).toInt();// Get the GID from the listview. | 237 | gid=groupsListView->currentItem()->text(0).toInt();// Get the GID from the listview. |
235 | if(GroupDialog::editGroup(gid)) getGroups();// Bring up the edit group dialog. | 238 | if(GroupDialog::editGroup(gid)) getGroups();// Bring up the edit group dialog. |
236 | } else { | 239 | } else { |
237 | QMessageBox::information(this,"No selection","No group has been selected."); | 240 | QMessageBox::information(this,"No selection","No group has been selected."); |
238 | } | 241 | } |
239 | } | 242 | } |
240 | 243 | ||
241 | void UserConfig::delGroup() { | 244 | void UserConfig::delGroup() { |
242 | const char *groupname; | 245 | const char *groupname; |
243 | if(groupsListView->currentItem()) {// Any group selected? | 246 | if(groupsListView->currentItem()) {// Any group selected? |
244 | groupname=groupsListView->currentItem()->text(1);// Get the groupname from the listview. | 247 | groupname=groupsListView->currentItem()->text(1);// Get the groupname from the listview. |
245 | if(QMessageBox::warning(this,"Delete group","Are you sure you want to\ndelete the group \""+QString(groupname)+"\" ?","&No","&Yes",0,0,1)) { | 248 | if(QMessageBox::warning(this,"Delete group","Are you sure you want to\ndelete the group \""+QString(groupname)+"\" ?","&No","&Yes",0,0,1)) { |
246 | // If confirmed, try to delete the group. | 249 | // If confirmed, try to delete the group. |
247 | if(GroupDialog::delGroup(groupname)) getGroups(); // And also update the view afterwards if the user was deleted. | 250 | if(GroupDialog::delGroup(groupname)) getGroups(); // And also update the view afterwards if the user was deleted. |
248 | } | 251 | } |
249 | } else { | 252 | } else { |
250 | QMessageBox::information(this,"No selection","No group has been selected."); | 253 | QMessageBox::information(this,"No selection","No group has been selected."); |
251 | } | 254 | } |
252 | } | 255 | } |
253 | 256 | ||
254 | void UserConfig::showUserMenu(QListViewItem *item) { | 257 | void UserConfig::showUserMenu(QListViewItem *item) { |
255 | //userPopupMenu.exec(item->mapToGlobal(QPoint(0,0))); | 258 | //userPopupMenu.exec(item->mapToGlobal(QPoint(0,0))); |
256 | qWarning("Pressed!"); | 259 | owarn << "Pressed!" << oendl; |
257 | } | 260 | } |