summaryrefslogtreecommitdiff
path: root/noncore/settings/usermanager
Unidiff
Diffstat (limited to 'noncore/settings/usermanager') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/usermanager/usermanager.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/settings/usermanager/usermanager.cpp b/noncore/settings/usermanager/usermanager.cpp
index 5411995..a1130d4 100644
--- a/noncore/settings/usermanager/usermanager.cpp
+++ b/noncore/settings/usermanager/usermanager.cpp
@@ -1,257 +1,257 @@
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#include <qlayout.h>
13 13
14#include <qmessagebox.h> 14#include <qmessagebox.h>
15#include <qfile.h> 15#include <qfile.h>
16#include <qpe/resource.h> 16#include <qpe/resource.h>
17 17
18#include <qregexp.h> 18#include <qregexp.h>
19 19
20/** 20/**
21 * The mainwindow constructor. 21 * The mainwindow constructor.
22 * 22 *
23 * @param QWidget *parent 23 * @param QWidget *parent
24 * @param const char *name 24 * @param const char *name
25 * @ param WFlags fl 25 * @ param WFlags fl
26 * 26 *
27 */ 27 */
28UserConfig::UserConfig(QWidget* parent, const char* name, WFlags fl) : QMainWindow(parent, name, fl) { 28UserConfig::UserConfig(QWidget* parent, const char* name, WFlags fl) : QMainWindow(parent, name, fl) {
29 setCaption(tr("Opie User Manager")); 29 setCaption(tr("Opie User Manager"));
30 30
31 // Create an instance of the global object 'accounts'. This holds all user/group info, and functions to modify them. 31 // Create an instance of the global object 'accounts'. This holds all user/group info, and functions to modify them.
32 accounts=new Passwd(); 32 accounts=new Passwd();
33 accounts->open();// This actually loads the files /etc/passwd & /etc/group into memory. 33 accounts->open();// This actually loads the files /etc/passwd & /etc/group into memory.
34 34
35 // Create the toolbar. 35 // Create the toolbar.
36 QToolBar *toolbar = new QToolBar(this,"Toolbar"); 36 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!? 37 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"); 38 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"); 39 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"); 40 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"); 41 QToolButton *userstext = new QToolButton(0,"User",0,0,0,toolbar,"User");
42 userstext->setUsesTextLabel(true); 42 userstext->setUsesTextLabel(true);
43 toolbar->addSeparator(); 43 toolbar->addSeparator();
44 addgroupToolButton = new QToolButton(Resource::loadPixmap("usermanager/addgroup"),"Add Group",0,this,SLOT(addGroup()),toolbar,"Add Group"); 44 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"); 45 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"); 46 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"); 47 QToolButton *groupstext = new QToolButton(0,"Group",0,0,0,toolbar,"Group");
48 groupstext->setUsesTextLabel(true); 48 groupstext->setUsesTextLabel(true);
49 addToolBar(toolbar,"myToolBar"); 49 addToolBar(toolbar,"myToolBar");
50 50
51 // Add a tabwidget and all the tabs. 51 // Add a tabwidget and all the tabs.
52 myTabWidget = new QTabWidget(this,"My Tab Widget"); 52 myTabWidget = new QTabWidget(this,"My Tab Widget");
53 setupTabAccounts(); 53 setupTabAccounts();
54 setupTabAllUsers(); 54 setupTabAllUsers();
55 setupTabAllGroups(); 55 setupTabAllGroups();
56 userPopupMenu.insertItem("Copy",0); 56 userPopupMenu.insertItem("Copy",0);
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 QListView(tabpage,"users"); 74 usersIconView=new QListView(tabpage,"users");
75 usersIconView->addColumn("Icon"); 75 usersIconView->addColumn("Icon");
76 usersIconView->addColumn("Username"); 76 usersIconView->addColumn("Username");
77 usersIconView->setAllColumnsShowFocus(true); 77 usersIconView->setAllColumnsShowFocus(true);
78 layout->addWidget(usersIconView); 78 layout->addWidget(usersIconView);
79 79
80 connect(usersIconView,SIGNAL(returnPressed(QListViewItem *)),this,SLOT(showUserMenu(QListViewItem *))); 80 connect(usersIconView,SIGNAL(returnPressed(QListViewItem*)),this,SLOT(showUserMenu(QListViewItem*)));
81 81
82 myTabWidget->addTab(tabpage,"Users"); 82 myTabWidget->addTab(tabpage,"Users");
83} 83}
84 84
85void UserConfig::setupTabAllUsers() { 85void UserConfig::setupTabAllUsers() {
86 QWidget *tabpage = new QWidget(this); 86 QWidget *tabpage = new QWidget(this);
87 QVBoxLayout *layout = new QVBoxLayout(tabpage); 87 QVBoxLayout *layout = new QVBoxLayout(tabpage);
88 layout->setMargin(5); 88 layout->setMargin(5);
89 89
90 usersListView=new QListView(tabpage,"allusers"); 90 usersListView=new QListView(tabpage,"allusers");
91 usersListView->addColumn("UID"); 91 usersListView->addColumn("UID");
92 usersListView->addColumn("Login"); 92 usersListView->addColumn("Login");
93 usersListView->addColumn("Username"); 93 usersListView->addColumn("Username");
94 layout->addWidget(usersListView); 94 layout->addWidget(usersListView);
95 usersListView->setSorting(1,1); 95 usersListView->setSorting(1,1);
96 usersListView->setAllColumnsShowFocus(true); 96 usersListView->setAllColumnsShowFocus(true);
97 97
98 myTabWidget->addTab(tabpage,"All Users"); 98 myTabWidget->addTab(tabpage,"All Users");
99} 99}
100 100
101void UserConfig::setupTabAllGroups() { 101void UserConfig::setupTabAllGroups() {
102 QWidget *tabpage = new QWidget(this); 102 QWidget *tabpage = new QWidget(this);
103 QVBoxLayout *layout = new QVBoxLayout(tabpage); 103 QVBoxLayout *layout = new QVBoxLayout(tabpage);
104 layout->setMargin(5); 104 layout->setMargin(5);
105 105
106 groupsListView=new QListView(tabpage,"groups"); 106 groupsListView=new QListView(tabpage,"groups");
107 groupsListView->addColumn("GID"); 107 groupsListView->addColumn("GID");
108 groupsListView->addColumn("Groupname"); 108 groupsListView->addColumn("Groupname");
109 layout->addWidget(groupsListView); 109 layout->addWidget(groupsListView);
110 groupsListView->setSorting(1,1); 110 groupsListView->setSorting(1,1);
111 groupsListView->setAllColumnsShowFocus(true); 111 groupsListView->setAllColumnsShowFocus(true);
112 112
113 myTabWidget->addTab(tabpage,"All Groups"); 113 myTabWidget->addTab(tabpage,"All Groups");
114} 114}
115void UserConfig::getUsers() { 115void UserConfig::getUsers() {
116 QString mytext; 116 QString mytext;
117 QPixmap mypixmap; 117 QPixmap mypixmap;
118 QListViewItem *listviewitem; 118 QListViewItem *listviewitem;
119 119
120 // Empty the iconview & the listview. 120 // Empty the iconview & the listview.
121 usersIconView->clear(); 121 usersIconView->clear();
122 usersListView->clear(); 122 usersListView->clear();
123 123
124 // availableUID is used as a deposite for the next available UID on the system, this should start at an ID over 500. 124 // availableUID is used as a deposite for the next available UID on the system, this should start at an ID over 500.
125 availableUID=500; 125 availableUID=500;
126 for(QStringList::Iterator it=accounts->passwdStringList.begin(); it!=accounts->passwdStringList.end(); ++it) { 126 for(QStringList::Iterator it=accounts->passwdStringList.begin(); it!=accounts->passwdStringList.end(); ++it) {
127 accounts->splitPasswdEntry(*it); // Split the string into it's components and store in variables in the accounts object. ("pr_name" and so on.) 127 accounts->splitPasswdEntry(*it); // Split the string into it's components and store in variables in the accounts object. ("pr_name" and so on.)
128 if(accounts->pw_name.find(QRegExp("^#"),0)) {// Skip commented lines. 128 if(accounts->pw_name.find(QRegExp("^#"),0)) {// Skip commented lines.
129 new QListViewItem(usersListView,QString::number(accounts->pw_uid),accounts->pw_name,accounts->pw_gecos); 129 new QListViewItem(usersListView,QString::number(accounts->pw_uid),accounts->pw_name,accounts->pw_gecos);
130 if((accounts->pw_uid>=500) && (accounts->pw_uid<65000)) {// Is this user a "normal" user ? 130 if((accounts->pw_uid>=500) && (accounts->pw_uid<65000)) {// Is this user a "normal" user ?
131 mytext=QString(accounts->pw_name)+" - ("+QString(accounts->pw_gecos)+")"; // The string displayed next to the icon. 131 mytext=QString(accounts->pw_name)+" - ("+QString(accounts->pw_gecos)+")"; // The string displayed next to the icon.
132 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. 132 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.
133 mypixmap=Resource::loadPixmap(QString("usermanager/usericon"));// If this user has no icon, load the default icon. 133 mypixmap=Resource::loadPixmap(QString("usermanager/usericon"));// If this user has no icon, load the default icon.
134 } 134 }
135 listviewitem=new QListViewItem(usersIconView,"",mytext);// Add the icon+text to the qiconview. 135 listviewitem=new QListViewItem(usersIconView,"",mytext);// Add the icon+text to the qiconview.
136 listviewitem->setPixmap(0,mypixmap); 136 listviewitem->setPixmap(0,mypixmap);
137 } 137 }
138 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. 138 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.
139 } 139 }
140 } 140 }
141 usersIconView->sort(); 141 usersIconView->sort();
142} 142}
143 143
144void UserConfig::addUser() { 144void UserConfig::addUser() {
145 if(UserDialog::addUser(availableUID,availableGID)) {// Add the user to the system, also send next available UID and GID. 145 if(UserDialog::addUser(availableUID,availableGID)) {// Add the user to the system, also send next available UID and GID.
146 getUsers(); // Update users views. 146 getUsers(); // Update users views.
147 getGroups(); // Update groups view. 147 getGroups(); // Update groups view.
148 } 148 }
149} 149}
150 150
151void UserConfig::editUser() { 151void UserConfig::editUser() {
152 QString username; 152 QString username;
153 if(myTabWidget->currentPageIndex()==0) {// Users 153 if(myTabWidget->currentPageIndex()==0) {// Users
154 if(usersIconView->currentItem()) {// Any icon selected? 154 if(usersIconView->currentItem()) {// Any icon selected?
155 username=usersIconView->currentItem()->text(1);// Get the text associated with the icon. 155 username=usersIconView->currentItem()->text(1);// Get the text associated with the icon.
156 username=username.left(username.find(" - (",0,true));// Strip out the username. 156 username=username.left(username.find(" - (",0,true));// Strip out the username.
157 if(UserDialog::editUser(username)) {// Bring up the userinfo dialog. 157 if(UserDialog::editUser(username)) {// Bring up the userinfo dialog.
158 // If there were any changed also update the views. 158 // If there were any changed also update the views.
159 getUsers(); 159 getUsers();
160 getGroups(); 160 getGroups();
161 } 161 }
162 } else { 162 } else {
163 QMessageBox::information(this,"No selection.","No user has been selected."); 163 QMessageBox::information(this,"No selection.","No user has been selected.");
164 } 164 }
165 } 165 }
166 if(myTabWidget->currentPageIndex()==1) {// All users 166 if(myTabWidget->currentPageIndex()==1) {// All users
167 if(usersListView->currentItem()) {// Anything changed!? 167 if(usersListView->currentItem()) {// Anything changed!?
168 username=usersListView->currentItem()->text(1);// Get the username. 168 username=usersListView->currentItem()->text(1);// Get the username.
169 if(UserDialog::editUser(username)) {// Bring up the userinfo dialog. 169 if(UserDialog::editUser(username)) {// Bring up the userinfo dialog.
170 // And again update the views if there were any changes. 170 // And again update the views if there were any changes.
171 getUsers(); 171 getUsers();
172 getGroups(); 172 getGroups();
173 } 173 }
174 } else { 174 } else {
175 QMessageBox::information(this,"No selection.","No user has been selected."); 175 QMessageBox::information(this,"No selection.","No user has been selected.");
176 } 176 }
177 } 177 }
178} 178}
179 179
180void UserConfig::delUser() { 180void UserConfig::delUser() {
181 QString username; 181 QString username;
182 182
183 if(myTabWidget->currentPageIndex()==0) {// Users, Iconview. 183 if(myTabWidget->currentPageIndex()==0) {// Users, Iconview.
184 if(usersIconView->currentItem()) {// Anything selected? 184 if(usersIconView->currentItem()) {// Anything selected?
185 username=usersIconView->currentItem()->text(1);// Get string associated with icon. 185 username=usersIconView->currentItem()->text(1);// Get string associated with icon.
186 username=username.left(username.find(" - (",0,true));// Strip out the username. 186 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)) { 187 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. 188 if(UserDialog::delUser(username)) {// Delete the user if possible.
189 // Update views. 189 // Update views.
190 getUsers(); 190 getUsers();
191 getGroups(); 191 getGroups();
192 } 192 }
193 } 193 }
194 } else { 194 } else {
195 QMessageBox::information(this,"No selection","No user has been selected."); 195 QMessageBox::information(this,"No selection","No user has been selected.");
196 } 196 }
197 } 197 }
198 if(myTabWidget->currentPageIndex()==1) {// All users 198 if(myTabWidget->currentPageIndex()==1) {// All users
199 if(usersListView->currentItem()) {// Anything changed!? 199 if(usersListView->currentItem()) {// Anything changed!?
200 username=usersListView->currentItem()->text(1);// Get the username. 200 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)) { 201 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. 202 if(UserDialog::delUser(username)) {// Try to delete the user.
203 // Update views. 203 // Update views.
204 getUsers(); 204 getUsers();
205 getGroups(); 205 getGroups();
206 } 206 }
207 } 207 }
208 } else { 208 } else {
209 QMessageBox::information(this,"No selection","No user has been selected."); 209 QMessageBox::information(this,"No selection","No user has been selected.");
210 } 210 }
211 } 211 }
212 212
213} 213}
214 214
215void UserConfig::getGroups() { 215void UserConfig::getGroups() {
216 groupsListView->clear();// Empty the listview. 216 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. 217 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. 218 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). 219 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. 220 if(accounts->gr_name.find(QRegExp("^#"),0)) {// Skip commented lines.
221 new QListViewItem(groupsListView,QString::number(accounts->gr_gid),accounts->gr_name); 221 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. 222 if((accounts->gr_gid>=availableGID) && (accounts->gr_gid<65000)) availableGID=accounts->gr_gid+1;// Maybe a new free GID.
223 } 223 }
224 } 224 }
225} 225}
226 226
227void UserConfig::addGroup() { 227void UserConfig::addGroup() {
228 if(GroupDialog::addGroup(availableGID)) getGroups();// Bring up the add group dialog. 228 if(GroupDialog::addGroup(availableGID)) getGroups();// Bring up the add group dialog.
229} 229}
230 230
231void UserConfig::editGroup() { 231void UserConfig::editGroup() {
232 int gid; 232 int gid;
233 if(groupsListView->currentItem()) {// Any group selected? 233 if(groupsListView->currentItem()) {// Any group selected?
234 gid=groupsListView->currentItem()->text(0).toInt();// Get the GID from the listview. 234 gid=groupsListView->currentItem()->text(0).toInt();// Get the GID from the listview.
235 if(GroupDialog::editGroup(gid)) getGroups();// Bring up the edit group dialog. 235 if(GroupDialog::editGroup(gid)) getGroups();// Bring up the edit group dialog.
236 } else { 236 } else {
237 QMessageBox::information(this,"No selection","No group has been selected."); 237 QMessageBox::information(this,"No selection","No group has been selected.");
238 } 238 }
239} 239}
240 240
241void UserConfig::delGroup() { 241void UserConfig::delGroup() {
242 const char *groupname; 242 const char *groupname;
243 if(groupsListView->currentItem()) {// Any group selected? 243 if(groupsListView->currentItem()) {// Any group selected?
244 groupname=groupsListView->currentItem()->text(1);// Get the groupname from the listview. 244 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)) { 245 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. 246 // If confirmed, try to delete the group.
247 if(GroupDialog::delGroup(groupname)) getGroups(); // And also update the view afterwards if the user was deleted. 247 if(GroupDialog::delGroup(groupname)) getGroups(); // And also update the view afterwards if the user was deleted.
248 } 248 }
249 } else { 249 } else {
250 QMessageBox::information(this,"No selection","No group has been selected."); 250 QMessageBox::information(this,"No selection","No group has been selected.");
251 } 251 }
252} 252}
253 253
254void UserConfig::showUserMenu(QListViewItem *item) { 254void UserConfig::showUserMenu(QListViewItem *item) {
255 //userPopupMenu.exec(item->mapToGlobal(QPoint(0,0))); 255 //userPopupMenu.exec(item->mapToGlobal(QPoint(0,0)));
256 qWarning("Pressed!"); 256 qWarning("Pressed!");
257} 257}