Diffstat (limited to 'noncore/settings/usermanager/usermanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/usermanager/usermanager.cpp | 2 |
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,176 +1,176 @@ | |||
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 | */ |
28 | UserConfig::UserConfig(QWidget* parent, const char* name, WFlags fl) : QMainWindow(parent, name, fl) { | 28 | UserConfig::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 | ||
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 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 | ||
85 | void UserConfig::setupTabAllUsers() { | 85 | void 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 | ||
101 | void UserConfig::setupTabAllGroups() { | 101 | void 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 | } |
115 | void UserConfig::getUsers() { | 115 | void 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 | ||
144 | void UserConfig::addUser() { | 144 | void 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 | ||
151 | void UserConfig::editUser() { | 151 | void 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 | } |