| 1 |
#include <qvariant.h> |
|---|
| 2 |
#include <qheader.h> |
|---|
| 3 |
#include <qlistview.h> |
|---|
| 4 |
#include <qtabwidget.h> |
|---|
| 5 |
#include <qwidget.h> |
|---|
| 6 |
#include <qlayout.h> |
|---|
| 7 |
#include <qtooltip.h> |
|---|
| 8 |
#include <qwhatsthis.h> |
|---|
| 9 |
#include <qaction.h> |
|---|
| 10 |
#include <qmenubar.h> |
|---|
| 11 |
#include <qpopupmenu.h> |
|---|
| 12 |
#include <qtoolbar.h> |
|---|
| 13 |
#include <qimage.h> |
|---|
| 14 |
#include <qpixmap.h> |
|---|
| 15 |
#include <qcolor.h> |
|---|
| 16 |
#include <qinputdialog.h> |
|---|
| 17 |
#include <qfont.h> |
|---|
| 18 |
#include <qwindowsstyle.h> |
|---|
| 19 |
#include <qtextcodec.h> |
|---|
| 20 |
#include <qapplication.h> |
|---|
| 21 |
#include <qfiledialog.h> |
|---|
| 22 |
#include <qregexp.h> |
|---|
| 23 |
#include <qmessagebox.h> |
|---|
| 24 |
|
|---|
| 25 |
#include "lime-user.h" |
|---|
| 26 |
#include "qrfuser.h" |
|---|
| 27 |
#include "qaddnew.h" |
|---|
| 28 |
#include "qaddnewgroup.h" |
|---|
| 29 |
#include "qusersetupform.h" |
|---|
| 30 |
#include "qgroupsetupform.h" |
|---|
| 31 |
#include "qsetpwdform.h" |
|---|
| 32 |
#include "libdefine.h" |
|---|
| 33 |
#include "corefile/define.h" |
|---|
| 34 |
#include <unistd.h> |
|---|
| 35 |
#include <stdio.h> |
|---|
| 36 |
#include <sys/types.h> |
|---|
| 37 |
#include <map> |
|---|
| 38 |
#include <vector> |
|---|
| 39 |
#include <string> |
|---|
| 40 |
|
|---|
| 41 |
#include "icons/addgroup.xpm" |
|---|
| 42 |
#include "icons/adduser.xpm" |
|---|
| 43 |
#include "icons/del.xpm" |
|---|
| 44 |
#include "icons/fresh.xpm" |
|---|
| 45 |
#include "icons/general.xpm" |
|---|
| 46 |
#include "icons/hide_system.xpm" |
|---|
| 47 |
#include "icons/info.xpm" |
|---|
| 48 |
#include "icons/main.xpm" |
|---|
| 49 |
#include "icons/manual.xpm" |
|---|
| 50 |
#include "icons/properites.xpm" |
|---|
| 51 |
#include "icons/rename.xpm" |
|---|
| 52 |
#include "icons/show_all.xpm" |
|---|
| 53 |
#include "icons/smalluser.xpm" |
|---|
| 54 |
#include "icons/kuser.xpm" |
|---|
| 55 |
#include "icons/commonuser.xpm" |
|---|
| 56 |
#include "icons/commonuser-small.xpm" |
|---|
| 57 |
#include "icons/systemuser.xpm" |
|---|
| 58 |
#include "icons/systemuser-small.xpm" |
|---|
| 59 |
#include "icons/commongroup.xpm" |
|---|
| 60 |
#include "icons/commongroup-small.xpm" |
|---|
| 61 |
#include "icons/systemgroup.xpm" |
|---|
| 62 |
#include "icons/systemgroup-small.xpm" |
|---|
| 63 |
|
|---|
| 64 |
#include <qfileinfo.h> |
|---|
| 65 |
#ifdef HAVE_CONFIG_H |
|---|
| 66 |
#include "config.h" |
|---|
| 67 |
#endif |
|---|
| 68 |
|
|---|
| 69 |
using namespace std; |
|---|
| 70 |
bool displayAll = false; |
|---|
| 71 |
|
|---|
| 72 |
RFMSnapin* CreateSnapinInstance(RFMConsole *c, QObject *parent) |
|---|
| 73 |
{ |
|---|
| 74 |
bindtextdomain (PACKAGE,LOCALEDIR); |
|---|
| 75 |
return new RfUserMinSnapin(c, parent); |
|---|
| 76 |
} |
|---|
| 77 |
|
|---|
| 78 |
RfUserMinSnapin::RfUserMinSnapin(RFMConsole *c, QObject *parent, const char *name) |
|---|
| 79 |
:RFMSnapin(c, parent, name) |
|---|
| 80 |
{ |
|---|
| 81 |
setRootItem(new QRFUserMin(c->getPivotRoot(),c)); |
|---|
| 82 |
} |
|---|
| 83 |
|
|---|
| 84 |
void RfUserMinSnapin::initConsole() |
|---|
| 85 |
{ |
|---|
| 86 |
RFMConsole *c = getConsole(); |
|---|
| 87 |
if(!c) return; |
|---|
| 88 |
|
|---|
| 89 |
RFMConsole::CommandItem cmds[] = { |
|---|
| 90 |
{ID_ADDNEWUSER, QIconSet(QPixmap((char **)adduser_xpm)),_("Add new &User"),_("Add new user"),_("Add new user"), QString::null, 0, 0}, |
|---|
| 91 |
{ID_ADDNEWGROUP, QIconSet(QPixmap((char **)addgroup_xpm)),_("Add new &Group"),_("Add new group"),_("Add new group"), QString::null, 0, 0}, |
|---|
| 92 |
{ID_RENAME, QIconSet(QPixmap((char **)rename_xpm)),_("&Rename"),_("Rename the current user or group"),_("Rename the current user or group"), |
|---|
| 93 |
QString::null, 0, 0}, |
|---|
| 94 |
{ID_DELETE, QIconSet(QPixmap((char **)del_xpm)),_("&Delete"),_("Delete"),_("Delete"), QString::null, 0, 0}, |
|---|
| 95 |
{ID_REFRESH, QIconSet(QPixmap((char **)fresh_xpm)),_("&Refresh"),_("Refresh"),_("Refresh"), QString::null, 0, 0}, |
|---|
| 96 |
{ ID_SWITCHER, QIconSet(QPixmap(show_all_xpm)),_("&Show all accounts"),_("Show all accounts"), |
|---|
| 97 |
_("Show all users and groups"), QString::null, 0, 0}, |
|---|
| 98 |
{0, QIconSet(), QString::null, QString::null, QString::null, QString::null, 0, 0} |
|---|
| 99 |
}; |
|---|
| 100 |
|
|---|
| 101 |
for(int i=0; cmds[i].id; ++i) { |
|---|
| 102 |
c->allocateCommandItem(cmds[i]); |
|---|
| 103 |
} |
|---|
| 104 |
} |
|---|
| 105 |
|
|---|
| 106 |
void RfUserMinSnapin::onHostChange(RFMConsole *c,HostItem *hostItem) |
|---|
| 107 |
{ |
|---|
| 108 |
(static_cast<QRFUserMin*>(getRootItem()))->onHostChange(c,hostItem); |
|---|
| 109 |
} |
|---|
| 110 |
|
|---|
| 111 |
void RfUserMinSnapin::onHostDelete(RFMConsole *c,HostItem *hostItem) |
|---|
| 112 |
{ |
|---|
| 113 |
(static_cast<QRFUserMin*>(getRootItem()))->onHostDelete(c,hostItem); |
|---|
| 114 |
} |
|---|
| 115 |
|
|---|
| 116 |
QString RfUserMinSnapin::getTitle() const { |
|---|
| 117 |
return _("User and Group Manager"); |
|---|
| 118 |
} |
|---|
| 119 |
|
|---|
| 120 |
QString RfUserMinSnapin::getDescription() const { |
|---|
| 121 |
return getTitle(); |
|---|
| 122 |
} |
|---|
| 123 |
|
|---|
| 124 |
QString RfUserMinSnapin::getProvider() const { |
|---|
| 125 |
return _("Red Flag Software Ltd."); |
|---|
| 126 |
} |
|---|
| 127 |
|
|---|
| 128 |
QString RfUserMinSnapin::getVersion() const { |
|---|
| 129 |
#ifdef PACKAGE_VERSION |
|---|
| 130 |
return PACKAGE_VERSION; |
|---|
| 131 |
#else |
|---|
| 132 |
return "unknown version"; |
|---|
| 133 |
#endif |
|---|
| 134 |
} |
|---|
| 135 |
|
|---|
| 136 |
QString RfUserMinSnapin::getHelpAddr() const { |
|---|
| 137 |
#ifdef PKGDOCDIR |
|---|
| 138 |
QString manual; |
|---|
| 139 |
QString locale = QTextCodec::locale(); |
|---|
| 140 |
locale = locale.section('.',0,0); |
|---|
| 141 |
manual = PKGDOCDIR"/lime-user_manual_"+locale+".xml"; |
|---|
| 142 |
QFileInfo finfo(manual); |
|---|
| 143 |
if(!finfo.exists()) |
|---|
| 144 |
manual = PKGDOCDIR"/lime-user_manual.xml"; |
|---|
| 145 |
return manual; |
|---|
| 146 |
#endif |
|---|
| 147 |
return QString::null; |
|---|
| 148 |
} |
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 |
QRFUserMin::QRFUserMin(RFMScopeItem * parent,RFMConsole * c) : RFMScopeItem(parent, Static,1),console(c) |
|---|
| 152 |
{ |
|---|
| 153 |
userList=NULL; |
|---|
| 154 |
groupList=NULL; |
|---|
| 155 |
currentHostItem=NULL; |
|---|
| 156 |
userItem=new UserItem(this); |
|---|
| 157 |
groupItem=new GroupItem(this); |
|---|
| 158 |
} |
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
QRFUserMin::~QRFUserMin() |
|---|
| 162 |
{ |
|---|
| 163 |
while(! hostDataMap.empty()) |
|---|
| 164 |
{ |
|---|
| 165 |
onHostDelete(getConsole(),hostDataMap.begin()->first); |
|---|
| 166 |
} |
|---|
| 167 |
for(vector<MyAssociator*>::iterator mpos=associatorList.begin();mpos!=associatorList.end();mpos++) |
|---|
| 168 |
{ |
|---|
| 169 |
delete *mpos; |
|---|
| 170 |
} |
|---|
| 171 |
associatorList.clear(); |
|---|
| 172 |
} |
|---|
| 173 |
|
|---|
| 174 |
QString QRFUserMin::text(int column) const |
|---|
| 175 |
{ |
|---|
| 176 |
if(column == 0) |
|---|
| 177 |
return _("User Management"); |
|---|
| 178 |
else return QString::null; |
|---|
| 179 |
} |
|---|
| 180 |
|
|---|
| 181 |
|
|---|
| 182 |
QPixmap * QRFUserMin::pixmap(int column, QIconSet::Size size, QIconSet::Mode mode, QIconSet::State state) const |
|---|
| 183 |
{ |
|---|
| 184 |
Q_UNUSED(mode); |
|---|
| 185 |
Q_UNUSED(state); |
|---|
| 186 |
QPixmap *p = NULL; |
|---|
| 187 |
if(column == 0) { |
|---|
| 188 |
if(size == QIconSet::Automatic || size == QIconSet::Small) { |
|---|
| 189 |
p = new QPixmap((const char**)lime_user_small_xpm); |
|---|
| 190 |
} |
|---|
| 191 |
else if(size == QIconSet::Large) { |
|---|
| 192 |
p = new QPixmap((const char**)lime_user_xpm); |
|---|
| 193 |
} |
|---|
| 194 |
} |
|---|
| 195 |
return p; |
|---|
| 196 |
} |
|---|
| 197 |
|
|---|
| 198 |
void QRFUserMin::onHostChange(RFMConsole *c,HostItem *hostItem) |
|---|
| 199 |
{ |
|---|
| 200 |
int ret=0; |
|---|
| 201 |
if(hostItem == NULL) return ; |
|---|
| 202 |
//auth failed, then sucess not refresh |
|---|
| 203 |
if(userItem) userItem->clearResultItem(); |
|---|
| 204 |
if(groupItem) groupItem->clearResultItem(); |
|---|
| 205 |
if(currentHostItem) |
|---|
| 206 |
{ |
|---|
| 207 |
map<HostItem*,HostData*>::iterator it=hostDataMap.find(currentHostItem); |
|---|
| 208 |
if(it==hostDataMap.end()) |
|---|
| 209 |
{ |
|---|
| 210 |
HostData * hd=new HostData; |
|---|
| 211 |
hd->userList=userList; |
|---|
| 212 |
hd->groupList=groupList; |
|---|
| 213 |
hostDataMap.insert(pair<HostItem*,HostData*>(currentHostItem,hd)); |
|---|
| 214 |
} |
|---|
| 215 |
else |
|---|
| 216 |
{ |
|---|
| 217 |
HostData * hd=NULL; |
|---|
| 218 |
if(!(*it).second) |
|---|
| 219 |
{ |
|---|
| 220 |
hd=new HostData; |
|---|
| 221 |
hostDataMap.insert(pair<HostItem*,HostData*>(currentHostItem,hd)); |
|---|
| 222 |
} |
|---|
| 223 |
hd=(*it).second; |
|---|
| 224 |
hd->userList=userList; |
|---|
| 225 |
hd->groupList=groupList; |
|---|
| 226 |
} |
|---|
| 227 |
} |
|---|
| 228 |
if(hostItem) |
|---|
| 229 |
{ |
|---|
| 230 |
map<HostItem*,HostData*>::iterator it=hostDataMap.find(hostItem); |
|---|
| 231 |
if(it==hostDataMap.end()) |
|---|
| 232 |
{ |
|---|
| 233 |
HostData * hd=new HostData; |
|---|
| 234 |
hostDataMap.insert(pair<HostItem*,HostData*>(hostItem,hd)); |
|---|
| 235 |
userList=hd->userList=NULL; |
|---|
| 236 |
groupList=hd->groupList=NULL; |
|---|
| 237 |
} |
|---|
| 238 |
else |
|---|
| 239 |
{ |
|---|
| 240 |
HostData * hd=NULL; |
|---|
| 241 |
if(!(*it).second) |
|---|
| 242 |
{ |
|---|
| 243 |
hd=new HostData; |
|---|
| 244 |
userList=hd->userList=NULL; |
|---|
| 245 |
groupList=hd->groupList=NULL; |
|---|
| 246 |
hostDataMap.insert(pair<HostItem*,HostData*>(hostItem,hd)); |
|---|
| 247 |
} |
|---|
| 248 |
else |
|---|
| 249 |
{ |
|---|
| 250 |
hd=(*it).second; |
|---|
| 251 |
userList=hd->userList; |
|---|
| 252 |
groupList=hd->groupList; |
|---|
| 253 |
} |
|---|
| 254 |
} |
|---|
| 255 |
} |
|---|
| 256 |
currentHostItem=hostItem; |
|---|
| 257 |
if(currentHostItem == NULL || currentHostItem->client==NULL) return; |
|---|
| 258 |
|
|---|
| 259 |
bool flag=false; |
|---|
| 260 |
if(userList==NULL) |
|---|
| 261 |
{ |
|---|
| 262 |
flag=RFListAllUsers(); |
|---|
| 263 |
} |
|---|
| 264 |
if(groupList==NULL && flag) |
|---|
| 265 |
{ |
|---|
| 266 |
RFListAllGroups(); |
|---|
| 267 |
} |
|---|
| 268 |
show_data(); |
|---|
| 269 |
} |
|---|
| 270 |
|
|---|
| 271 |
void QRFUserMin::onHostDelete(RFMConsole * c, HostItem * hostItem) |
|---|
| 272 |
{ |
|---|
| 273 |
map<HostItem*,HostData*>::iterator it=hostDataMap.find(hostItem); |
|---|
| 274 |
if(it!=hostDataMap.end()) |
|---|
| 275 |
{ |
|---|
| 276 |
HostData * hd=(*it).second; |
|---|
| 277 |
if(hd) |
|---|
| 278 |
{ |
|---|
| 279 |
if(hd->userList) |
|---|
| 280 |
{ |
|---|
| 281 |
for(map<string,User*>::iterator pos=hd->userList->begin();pos!=hd->userList->end();pos++) |
|---|
| 282 |
{ |
|---|
| 283 |
delete (*pos).second; |
|---|
| 284 |
} |
|---|
| 285 |
hd->userList->clear(); |
|---|
| 286 |
delete hd->userList; |
|---|
| 287 |
} |
|---|
| 288 |
if(hd->groupList) |
|---|
| 289 |
{ |
|---|
| 290 |
for(map<string,Group*>::iterator pos=hd->groupList->begin();pos!=hd->groupList->end();pos++) |
|---|
| 291 |
{ |
|---|
| 292 |
delete (*pos).second; |
|---|
| 293 |
} |
|---|
| 294 |
hd->groupList->clear(); |
|---|
| 295 |
delete hd->groupList; |
|---|
| 296 |
} |
|---|
| 297 |
delete hd; |
|---|
| 298 |
} |
|---|
| 299 |
hostDataMap.erase(it); |
|---|
| 300 |
} |
|---|
| 301 |
} |
|---|
| 302 |
|
|---|
| 303 |
bool QRFUserMin::onSelect(RFMConsole *c, RFMSelection *s) |
|---|
| 304 |
{ |
|---|
| 305 |
RFMScopeItem::onSelect(c , s); |
|---|
| 306 |
c->insertCommandButton(ID_REFRESH,RFMConsole::ToolBar); |
|---|
| 307 |
c->insertCommandButton(ID_REFRESH,RFMConsole::MenuAction); |
|---|
| 308 |
} |
|---|
| 309 |
|
|---|
| 310 |
bool QRFUserMin::onCommand(RFMConsole *c, int commandID, RFMSelection *s) |
|---|
| 311 |
{ |
|---|
| 312 |
if(commandID==ID_REFRESH) |
|---|
| 313 |
{ |
|---|
| 314 |
if(RFListAllUsers()) RFListAllGroups(); |
|---|
| 315 |
RFRefresh(); |
|---|
| 316 |
} |
|---|
| 317 |
return true; |
|---|
| 318 |
} |
|---|
| 319 |
|
|---|
| 320 |
bool QRFUserMin::RFListAllUsers() |
|---|
| 321 |
{ |
|---|
| 322 |
if(userList==NULL) userList=new map<string,User*>; |
|---|
| 323 |
if(currentHostItem == NULL || currentHostItem->client == NULL) return false; |
|---|
| 324 |
if(!userList->empty()) |
|---|
| 325 |
{ |
|---|
| 326 |
for(map<string,User*>::iterator pos=userList->begin();pos!=userList->end();pos++) delete(pos->second); |
|---|
| 327 |
} |
|---|
| 328 |
userList->clear(); |
|---|
| 329 |
|
|---|
| 330 |
int ret=0; |
|---|
| 331 |
try{ |
|---|
| 332 |
User::fetchUserList(userList,currentHostItem->client); |
|---|
| 333 |
}CATCH_EXCEPTION(NULL,_("Fetch user list failed! "),_("Can not fetch the user list from the host!"),ret) |
|---|
| 334 |
while(ret==2) |
|---|
| 335 |
{ |
|---|
| 336 |
ret=0; |
|---|
| 337 |
if(! getConsole()->getHostListBar()->sltEditHost()) return false; |
|---|
| 338 |
currentHostItem=getConsole()->getHostListBar()->currentHostItem(); |
|---|
| 339 |
try{ |
|---|
| 340 |
User::fetchUserList(userList,currentHostItem->client); |
|---|
| 341 |
}CATCH_EXCEPTION(NULL,_("Fetch user list failed! "),_("Can not fetch the user list from the host!"),ret) |
|---|
| 342 |
} |
|---|
| 343 |
return true; |
|---|
| 344 |
} |
|---|
| 345 |
|
|---|
| 346 |
bool QRFUserMin::RFListAllGroups() |
|---|
| 347 |
{ |
|---|
| 348 |
if(groupList==NULL) groupList=new map<string,Group*>; |
|---|
| 349 |
if(currentHostItem == NULL || currentHostItem->client == NULL) return false; |
|---|
| 350 |
if(!groupList->empty()) |
|---|
| 351 |
{ |
|---|
| 352 |
for(map<string,Group*>::iterator pos=groupList->begin();pos!=groupList->end();pos++) delete(pos->second); |
|---|
| 353 |
} |
|---|
| 354 |
groupList->clear(); |
|---|
| 355 |
|
|---|
| 356 |
int ret=0; |
|---|
| 357 |
try{ |
|---|
| 358 |
Group::fetchGroupList(groupList,currentHostItem->client); |
|---|
| 359 |
}CATCH_EXCEPTION(NULL,_("Fetch group list failed! "),_("Can not fetch the group list from the host!"),ret) |
|---|
| 360 |
while(ret==2) |
|---|
| 361 |
{ |
|---|
| 362 |
ret=0; |
|---|
| 363 |
if(! getConsole()->getHostListBar()->sltEditHost()) return false; |
|---|
| 364 |
currentHostItem=getConsole()->getHostListBar()->currentHostItem(); |
|---|
| 365 |
try{ |
|---|
| 366 |
Group::fetchGroupList(groupList,currentHostItem->client); |
|---|
| 367 |
}CATCH_EXCEPTION(NULL,_("Fetch group list failed! "),_("Can not fetch the group list from the host!"),ret) |
|---|
| 368 |
} |
|---|
| 369 |
for(map<string,Group*>::iterator pos=groupList->begin();pos!=groupList->end();pos++) |
|---|
| 370 |
{ |
|---|
| 371 |
(*pos).second->enumUser(currentHostItem->client); |
|---|
| 372 |
} |
|---|
| 373 |
return true; |
|---|
| 374 |
} |
|---|
| 375 |
|
|---|
| 376 |
|
|---|
| 377 |
void QRFUserMin::show_data() |
|---|
| 378 |
{ |
|---|
| 379 |
if(userItem) userItem->show_data(); |
|---|
| 380 |
if(groupItem) groupItem->show_data(); |
|---|
| 381 |
} |
|---|
| 382 |
|
|---|
| 383 |
void QRFUserMin::RFAddNewUser() |
|---|
| 384 |
{ |
|---|
| 385 |
if(currentHostItem == NULL || currentHostItem->client == NULL) return; |
|---|
| 386 |
QAddNewUser* userForm; |
|---|
| 387 |
userForm = new QAddNewUser(this); |
|---|
| 388 |
userForm->exec(); |
|---|
| 389 |
if(userItem) |
|---|
| 390 |
{ |
|---|
| 391 |
RFListAllUsers(); |
|---|
| 392 |
RFListAllGroups(); |
|---|
| 393 |
userItem->clearResultItem(); |
|---|
| 394 |
userItem->show_data(); |
|---|
| 395 |
} |
|---|
| 396 |
} |
|---|
| 397 |
|
|---|
| 398 |
|
|---|
| 399 |
void QRFUserMin::RFAddNewGroup() |
|---|
| 400 |
{ |
|---|
| 401 |
if(currentHostItem == NULL || currentHostItem->client == NULL) return; |
|---|
| 402 |
QAddNewGroup* newGroupForm = new QAddNewGroup( this); |
|---|
| 403 |
newGroupForm->exec(); |
|---|
| 404 |
if(groupItem) |
|---|
| 405 |
{ |
|---|
| 406 |
RFListAllUsers(); |
|---|
| 407 |
RFListAllGroups(); |
|---|
| 408 |
groupItem->clearResultItem(); |
|---|
| 409 |
groupItem->show_data(); |
|---|
| 410 |
} |
|---|
| 411 |
} |
|---|
| 412 |
|
|---|
| 413 |
|
|---|
| 414 |
void QRFUserMin::RFSetUserPropties(QString userName) |
|---|
| 415 |
{ |
|---|
| 416 |
User *userToSet=NULL; |
|---|
| 417 |
map<string,User*>::iterator upos=userList->find(userName.latin1()); |
|---|
| 418 |
if(upos!=userList->end()) |
|---|
| 419 |
{ |
|---|
| 420 |
userToSet = upos->second; |
|---|
| 421 |
} |
|---|
| 422 |
RFSetUserPropties(userToSet); |
|---|
| 423 |
} |
|---|
| 424 |
|
|---|
| 425 |
void QRFUserMin::RFSetUserPropties(User *userToSet) |
|---|
| 426 |
{ |
|---|
| 427 |
if(currentHostItem == NULL || currentHostItem->client==NULL || userToSet ==NULL) return; |
|---|
| 428 |
for(vector<MyAssociator*>::iterator pos=associatorList.begin();pos!=associatorList.end();pos++) |
|---|
| 429 |
{ |
|---|
| 430 |
delete (*pos); |
|---|
| 431 |
} |
|---|
| 432 |
associatorList.clear(); |
|---|
| 433 |
int ret=0; |
|---|
| 434 |
try{ |
|---|
| 435 |
MyAssociator::enumAssociatorFromUser(currentHostItem->client, |
|---|
| 436 |
userToSet,groupList,&associatorList); |
|---|
| 437 |
}CATCH_EXCEPTION(NULL,_("Enumeration associator of user failed! "),_("Enumeration associator of user failed!"),ret); |
|---|
| 438 |
if (ret != 0) |
|---|
| 439 |
return; |
|---|
| 440 |
QUserSetupForm* userSetupForm = new QUserSetupForm( this, userToSet); |
|---|
| 441 |
userSetupForm->exec(); |
|---|
| 442 |
if(userItem) |
|---|
| 443 |
{ |
|---|
| 444 |
userItem->clearResultItem(); |
|---|
| 445 |
userItem->show_data(); |
|---|
| 446 |
} |
|---|
| 447 |
} |
|---|
| 448 |
|
|---|
| 449 |
void QRFUserMin::RFSetGroupPropties(QString groupName) |
|---|
| 450 |
{ |
|---|
| 451 |
Group *groupToSet=NULL; |
|---|
| 452 |
map<string,Group*>::iterator gpos=groupList->find(groupName.latin1()); |
|---|
| 453 |
if(gpos!=groupList->end()) |
|---|
| 454 |
{ |
|---|
| 455 |
groupToSet = gpos->second; |
|---|
| 456 |
} |
|---|
| 457 |
RFSetGroupPropties(groupToSet); |
|---|
| 458 |
} |
|---|
| 459 |
|
|---|
| 460 |
void QRFUserMin::RFSetGroupPropties(Group *groupToSet) |
|---|
| 461 |
{ |
|---|
| 462 |
if(currentHostItem == NULL || currentHostItem->client==NULL || groupToSet==NULL) return; |
|---|
| 463 |
int ret=0; |
|---|
| 464 |
for(vector<MyAssociator*>::iterator pos=associatorList.begin();pos!=associatorList.end();pos++) |
|---|
| 465 |
{ |
|---|
| 466 |
delete (*pos); |
|---|
| 467 |
} |
|---|
| 468 |
associatorList.clear(); |
|---|
| 469 |
try{ |
|---|
| 470 |
MyAssociator::enumAssociatorFromGroup(currentHostItem->client, |
|---|
| 471 |
groupToSet,userList,&associatorList); |
|---|
| 472 |
}CATCH_EXCEPTION(NULL, _("Enumeration associator of group failed! "),_("Enumeration associator of group failed!"),ret) |
|---|
| 473 |
if (ret != 0) |
|---|
| 474 |
return; |
|---|
| 475 |
QGroupSetupForm* groupSetupForm = new QGroupSetupForm( this, groupToSet); |
|---|
| 476 |
groupSetupForm->exec(); |
|---|
| 477 |
if(groupItem) |
|---|
| 478 |
{ |
|---|
| 479 |
groupItem->clearResultItem(); |
|---|
| 480 |
groupItem->show_data(); |
|---|
| 481 |
} |
|---|
| 482 |
} |
|---|
| 483 |
|
|---|
| 484 |
|
|---|
| 485 |
void QRFUserMin::RFRefresh() |
|---|
| 486 |
{ |
|---|
| 487 |
if(userItem) userItem->clearResultItem(); |
|---|
| 488 |
if(groupItem) groupItem->clearResultItem(); |
|---|
| 489 |
show_data(); |
|---|
| 490 |
} |
|---|
| 491 |
|
|---|
| 492 |
void QRFUserMin::RFAbout() |
|---|
| 493 |
{ |
|---|
| 494 |
} |
|---|
| 495 |
|
|---|
| 496 |
void QRFUserMin::RFSetPassword(QString userName) |
|---|
| 497 |
{ |
|---|
| 498 |
map<string,User*>::iterator upos=userList->find(userName.latin1()); |
|---|
| 499 |
if(upos!=userList->end()) RFSetPassword((*upos).second); |
|---|
| 500 |
} |
|---|
| 501 |
|
|---|
| 502 |
void QRFUserMin::RFSetPassword(User * user) |
|---|
| 503 |
{ |
|---|
| 504 |
if(currentHostItem == NULL || currentHostItem->client==NULL || user ==NULL) return; |
|---|
| 505 |
QSetPwdForm* setPwdForm = new QSetPwdForm(this, user); |
|---|
| 506 |
setPwdForm->exec(); |
|---|
| 507 |
} |
|---|
| 508 |
|
|---|
| 509 |
void QRFUserMin::RFDeleteUser(QString userName) |
|---|
| 510 |
{ |
|---|
| 511 |
map<string,User*>::iterator upos=userList->find(userName.latin1()); |
|---|
| 512 |
if(upos==userList->end()) return; |
|---|
| 513 |
RFDeleteUser((*upos).second); |
|---|
| 514 |
} |
|---|
| 515 |
|
|---|
| 516 |
void QRFUserMin::RFDeleteUser(User * user) |
|---|
| 517 |
{ |
|---|
| 518 |
if(currentHostItem== NULL || currentHostItem->client==NULL || user==NULL) return; |
|---|
| 519 |
QMessageBox a; |
|---|
| 520 |
|
|---|
| 521 |
QString UID=user->uid.c_str(); |
|---|
| 522 |
bool ok; |
|---|
| 523 |
int uid = UID.toInt(&ok, 10); |
|---|
| 524 |
|
|---|
| 525 |
if(uid == (int)getuid()) |
|---|
| 526 |
{ |
|---|
| 527 |
RFWarn( _("Warning"),_("Ok"), NULL, _("operation denied.") ); |
|---|
| 528 |
return; |
|---|
| 529 |
} |
|---|
| 530 |
if(uid<500) |
|---|
| 531 |
{ |
|---|
| 532 |
RFWarn( _("Warning"),_("Ok"), NULL, _("operation denied.") ); |
|---|
| 533 |
return; |
|---|
| 534 |
} |
|---|
| 535 |
if(0 != a.warning( NULL, _ ("Warning"),_ ("delete the user from system(the home directory will not be removed), really do?"), |
|---|
| 536 |
_("Ok"),_("Cancel"),NULL, 0, 1 )) |
|---|
| 537 |
return; |
|---|
| 538 |
int ret=0; |
|---|
| 539 |
try{ |
|---|
| 540 |
MyAssociator::enumAssociatorFromUser(currentHostItem->client, |
|---|
| 541 |
user,groupList,&associatorList); |
|---|
| 542 |
}CATCH_EXCEPTION(NULL,_( "Enumeration associator of user failed! "),_( "Enumeration associator of user failed! "),ret); |
|---|
| 543 |
if (ret != 0) |
|---|
| 544 |
return; |
|---|
| 545 |
|
|---|
| 546 |
for(vector<MyAssociator*>::iterator pos=associatorList.begin();pos!=associatorList.end();pos++) |
|---|
| 547 |
{ |
|---|
| 548 |
try{ |
|---|
| 549 |
(*pos)->deleteMyAssociator(currentHostItem->client); |
|---|
| 550 |
}CATCH_EXCEPTION(NULL,_("Delete associator failed! "),_("Delete associator failed! "),ret); |
|---|
| 551 |
if(ret!=0) return; |
|---|
| 552 |
delete(*pos); |
|---|
| 553 |
} |
|---|
| 554 |
associatorList.clear(); |
|---|
| 555 |
try{ |
|---|
| 556 |
user->deleteUser(currentHostItem->client); |
|---|
| 557 |
}CATCH_EXCEPTION(NULL,_("Delete user failed! "),_("Delete user failed! "),ret); |
|---|
| 558 |
QString userMainGroup=user->mainGroup.c_str(); |
|---|
| 559 |
map<string,User*>::iterator upos=userList->find(user->name.c_str()); |
|---|
| 560 |
if(upos!=userList->end()) userList->erase(upos); |
|---|
| 561 |
delete user; |
|---|
| 562 |
RFListAllGroups(); |
|---|
| 563 |
if(userItem) userItem->clearResultItem(); |
|---|
| 564 |
if(groupItem) groupItem->clearResultItem(); |
|---|
| 565 |
map<string,Group*>::iterator gpos=groupList->find(userMainGroup.latin1()); |
|---|
| 566 |
if(gpos!=groupList->end()) |
|---|
| 567 |
{ |
|---|
| 568 |
try{ |
|---|
| 569 |
MyAssociator::enumAssociatorFromGroup(currentHostItem->client,gpos->second,userList,&associatorList); |
|---|
| 570 |
}catch(...){}//CATCH_EXCEPTION(this,_("Enumeration associator of group failed!"), |
|---|
| 571 |
//_("Enumeration associator of group failed!"),ret); |
|---|
| 572 |
if(associatorList.size()==0) RFDeleteGroup(userMainGroup); |
|---|
| 573 |
} |
|---|
| 574 |
RFListAllUsers(); |
|---|
| 575 |
RFListAllGroups(); |
|---|
| 576 |
RFRefresh(); |
|---|
| 577 |
} |
|---|
| 578 |
|
|---|
| 579 |
void QRFUserMin::RFDeleteGroup(QString groupName) |
|---|
| 580 |
{ |
|---|
| 581 |
map<string,Group*>::iterator gpos=groupList->find(groupName.latin1()); |
|---|
| 582 |
if(gpos==groupList->end()) return; |
|---|
| 583 |
RFDeleteGroup((*gpos).second); |
|---|
| 584 |
} |
|---|
| 585 |
|
|---|
| 586 |
void QRFUserMin::RFDeleteGroup(Group * group) |
|---|
| 587 |
{ |
|---|
| 588 |
if(currentHostItem == NULL || currentHostItem->client==NULL || group==NULL) return; |
|---|
| 589 |
|
|---|
| 590 |
QString GID=group->gid.c_str(); |
|---|
| 591 |
int gid=GID.toInt(0,10); |
|---|
| 592 |
if(0 == gid) |
|---|
| 593 |
{ |
|---|
| 594 |
RFWarn( _("Warning"),_("Ok"), NULL, _("operation denied.") ); |
|---|
| 595 |
return; |
|---|
| 596 |
} |
|---|
| 597 |
if(gid<500) |
|---|
| 598 |
{ |
|---|
| 599 |
RFWarn( _("Warning"),_("Ok"), NULL, _("operation denied.") ); |
|---|
| 600 |
return; |
|---|
| 601 |
} |
|---|
| 602 |
int ret = 0; |
|---|
| 603 |
|
|---|
| 604 |
|
|---|
| 605 |
try{ |
|---|
| 606 |
if(group->isMainGroup(currentHostItem->client) == 1) |
|---|
| 607 |
{ |
|---|
| 608 |
QMessageBox::warning(NULL,_("Delete group failed! "), |
|---|
| 609 |
_("Can not remove user's primary group.")); |
|---|
| 610 |
return; |
|---|
| 611 |
} |
|---|
| 612 |
}CATCH_EXCEPTION(NULL,_("Delete group failed! "), |
|---|
| 613 |
_("Can not get group information! "),ret); |
|---|
| 614 |
if(ret != 0) |
|---|
| 615 |
return; |
|---|
| 616 |
|
|---|
| 617 |
if(0 != QMessageBox::warning( NULL, _ ("Warning"), _ ("delete the user group from system, really do?"), |
|---|
| 618 |
_("Ok"),_("Cancel"),NULL, 0, 1 )) |
|---|
| 619 |
return; |
|---|
| 620 |
|
|---|
| 621 |
//////////////////////////////////////////////////////////////////// |
|---|
| 622 |
|
|---|
| 623 |
for(vector<MyAssociator*>::iterator pos=associatorList.begin();pos!=associatorList.end();pos++) |
|---|
| 624 |
{ |
|---|
| 625 |
delete (*pos); |
|---|
| 626 |
} |
|---|
| 627 |
associatorList.clear(); |
|---|
| 628 |
|
|---|
| 629 |
try{ |
|---|
| 630 |
MyAssociator::enumAssociatorFromGroup(currentHostItem->client, |
|---|
| 631 |
group,userList,&associatorList); |
|---|
| 632 |
}CATCH_EXCEPTION(NULL,_("Enumeration associator of group failed! "),_("Enumeration associator of group failed! "),ret); |
|---|
| 633 |
if (ret != 0) |
|---|
| 634 |
return; |
|---|
| 635 |
for(vector<MyAssociator*>::iterator pos=associatorList.begin();pos!=associatorList.end();pos++) |
|---|
| 636 |
{ |
|---|
| 637 |
try{ |
|---|
| 638 |
(*pos)->deleteMyAssociator(currentHostItem->client); |
|---|
| 639 |
}CATCH_EXCEPTION(NULL,_("Delete associator failed! "),_("Delete associator failed! "),ret); |
|---|
| 640 |
if(ret!=0) return; |
|---|
| 641 |
delete(*pos); |
|---|
| 642 |
} |
|---|
| 643 |
associatorList.clear(); |
|---|
| 644 |
try{ |
|---|
| 645 |
group->deleteGroup(currentHostItem->client); |
|---|
| 646 |
}CATCH_EXCEPTION(NULL,_("Delete group failed! "),_("Delete group failed! "),ret); |
|---|
| 647 |
map<string,Group*>::iterator gpos=groupList->find(group->name.c_str()); |
|---|
| 648 |
groupList->erase(gpos); |
|---|
| 649 |
delete group; |
|---|
| 650 |
RFListAllUsers(); |
|---|
| 651 |
RFListAllGroups(); |
|---|
| 652 |
RFRefresh(); |
|---|
| 653 |
} |
|---|
| 654 |
|
|---|
| 655 |
void QRFUserMin::ejectUserPopupMenu ( QListViewItem *, const QPoint &, int c ){ |
|---|
| 656 |
|
|---|
| 657 |
QPopupMenu *fileMenu; |
|---|
| 658 |
|
|---|
| 659 |
if(c!=-1) |
|---|
| 660 |
{ // not blank place |
|---|
| 661 |
fileMenu = new QPopupMenu; // file sub menu |
|---|
| 662 |
fileMenu->insertItem( QIconSet(QPixmap(adduser_xpm)),_("Set Password"), this, SLOT(RFSetPassword()), 67 ); |
|---|
| 663 |
fileMenu->insertItem( QIconSet(QPixmap(rename_xpm)),_("Rename"), this, SLOT(RFRename()), 65 ); |
|---|
| 664 |
fileMenu->insertItem( QIconSet(QPixmap(del_xpm)),_("Delete"), this, SLOT(RFDeleteUser()), 68 ); |
|---|
| 665 |
fileMenu->insertSeparator(4); |
|---|
| 666 |
fileMenu->insertItem( QIconSet(QPixmap(properties_xpm)),_("Properties"),this,SLOT(RFSetPropties()), 69 ); |
|---|
| 667 |
fileMenu->exec(QCursor::pos()); |
|---|
| 668 |
} |
|---|
| 669 |
else |
|---|
| 670 |
{ |
|---|
| 671 |
fileMenu = new QPopupMenu; // file sub menu |
|---|
| 672 |
fileMenu->insertItem( QIconSet(QPixmap(adduser_xpm)),_("Add New User"), this, SLOT(RFAddNewUser()), 67 ); |
|---|
| 673 |
fileMenu->exec(QCursor::pos()); |
|---|
| 674 |
} |
|---|
| 675 |
} |
|---|
| 676 |
|
|---|
| 677 |
void QRFUserMin::ejectGroupPopupMenu ( QListViewItem *, const QPoint &, int c ) |
|---|
| 678 |
{ |
|---|
| 679 |
QPopupMenu *fileMenu; |
|---|
| 680 |
if(c!=-1) |
|---|
| 681 |
{ |
|---|
| 682 |
fileMenu = new QPopupMenu; // file sub menu |
|---|
| 683 |
fileMenu->insertItem( QIconSet(QPixmap(del_xpm)),_("Delete"), this, SLOT(RFDeleteGroup( )), 68 ); |
|---|
| 684 |
fileMenu->insertItem( QIconSet(QPixmap(rename_xpm)),_("Rename"), this, SLOT(RFRename()), 65 ); |
|---|
| 685 |
fileMenu->insertSeparator(3); |
|---|
| 686 |
fileMenu->insertItem( QIconSet(QPixmap(properties_xpm)),_("Properties"),this, SLOT( RFSetPropties() ), 69 ); |
|---|
| 687 |
fileMenu->exec(QCursor::pos()); |
|---|
| 688 |
} |
|---|
| 689 |
else |
|---|
| 690 |
{ |
|---|
| 691 |
fileMenu = new QPopupMenu; // file sub menu |
|---|
| 692 |
fileMenu->insertItem( QIconSet(QPixmap(addgroup_xpm)),_("Add New Group"),this,SLOT(RFAddNewGroup()),67); |
|---|
| 693 |
fileMenu->exec(QCursor::pos()); |
|---|
| 694 |
} |
|---|
| 695 |
} |
|---|
| 696 |
|
|---|
| 697 |
void QRFUserMin::RFRenameUser(QString userName) |
|---|
| 698 |
{ |
|---|
| 699 |
map<string,User*>::iterator upos=userList->find(userName.latin1()); |
|---|
| 700 |
if(upos==userList->end()) return; |
|---|
| 701 |
RFRenameUser((*upos).second); |
|---|
| 702 |
} |
|---|
| 703 |
|
|---|
| 704 |
void QRFUserMin::RFRenameUser(User * user) |
|---|
| 705 |
{ |
|---|
| 706 |
if(currentHostItem == NULL || currentHostItem->client==NULL || user==NULL) return; |
|---|
| 707 |
QString s; |
|---|
| 708 |
bool ok; |
|---|
| 709 |
s.append( _( "Enter new name for \"" ) ); |
|---|
| 710 |
s.append(user->name.c_str()); |
|---|
| 711 |
s.append( "\" :"); |
|---|
| 712 |
QString text= QInputDialog::getText(_( "RenameDialog" ),s,QLineEdit::Normal, QString::null, &ok, NULL ); |
|---|
| 713 |
if(ok && RFVerifyString(text.latin1())==0 ) |
|---|
| 714 |
{ |
|---|
| 715 |
RFWarn( _("Warning"),_("Ok"), NULL, _("invalid name.")); |
|---|
| 716 |
} |
|---|
| 717 |
else if ( ok) |
|---|
| 718 |
{ |
|---|
| 719 |
int ret=0; |
|---|
| 720 |
if( text.compare(user->name.c_str())==0 ) return; |
|---|
| 721 |
if(userList->find(text.latin1())!=userList->end()) |
|---|
| 722 |
{ |
|---|
| 723 |
RFWarn( _("Warning"),_("Ok"),NULL,_("user name already exists.")); |
|---|
| 724 |
return; |
|---|
| 725 |
} |
|---|
| 726 |
//fetch old associators between user and group |
|---|
| 727 |
for(vector<MyAssociator*>::iterator mpos=associatorList.begin();mpos!=associatorList.end();mpos++) |
|---|
| 728 |
{ |
|---|
| 729 |
delete (*mpos); |
|---|
| 730 |
} |
|---|
| 731 |
associatorList.clear(); |
|---|
| 732 |
try{ |
|---|
| 733 |
MyAssociator::enumAssociatorFromUser(currentHostItem->client, |
|---|
| 734 |
user,groupList,&associatorList); |
|---|
| 735 |
}CATCH_EXCEPTION(NULL,_("Rename user failed"),_("Enumeration associator of user failed! "),ret); |
|---|
| 736 |
//CATCH_EXCEPTION(NULL,_("Enumeration associator of user failed"),_("Enumeration associator of user failed! "),ret); |
|---|
| 737 |
if (ret != 0) |
|---|
| 738 |
return; |
|---|
| 739 |
//clear old associators |
|---|
| 740 |
for(vector<MyAssociator*>::iterator mpos=associatorList.begin();mpos!=associatorList.end();mpos++) |
|---|
| 741 |
{ |
|---|
| 742 |
try{ |
|---|
| 743 |
(*mpos)->deleteMyAssociator(currentHostItem->client); |
|---|
| 744 |
}CATCH_EXCEPTION(NULL,_("Rename user failed"),_("Delete associator failed! "),ret); |
|---|
| 745 |
if(ret!=0) return; |
|---|
| 746 |
} |
|---|
| 747 |
//delete old user |
|---|
| 748 |
try{ |
|---|
| 749 |
user->deleteUser(currentHostItem->client); |
|---|
| 750 |
}CATCH_EXCEPTION(NULL,_("Rename user failed"),_("Delete user failed! "),ret); |
|---|
| 751 |
if(ret!=0) return; |
|---|
| 752 |
//modify the new user |
|---|
| 753 |
map<string,User*>::iterator upos=userList->find(user->name.c_str()); |
|---|
| 754 |
if(upos!=userList->end()) userList->erase(upos); |
|---|
| 755 |
user->passwdEffective=true; |
|---|
| 756 |
user->password.erase(); |
|---|
| 757 |
user->name=text.latin1(); |
|---|
| 758 |
//create the new user (no password) |
|---|
| 759 |
try{ |
|---|
| 760 |
user->createUser(currentHostItem->client); |
|---|
| 761 |
}CATCH_EXCEPTION(NULL,_("Rename user failed"),_("Create user failed! "),ret); |
|---|
| 762 |
if(ret!=0) return; |
|---|
| 763 |
//add the new associators as old associator |
|---|
| 764 |
for(vector<MyAssociator*>::iterator mpos=associatorList.begin();mpos!=associatorList.end();mpos++) |
|---|
| 765 |
{ |
|---|
| 766 |
try{ |
|---|
| 767 |
(*mpos)->createMyAssociator(currentHostItem->client); |
|---|
| 768 |
}catch(...){} |
|---|
| 769 |
//CATCH_EXCEPTION(NULL,_("Create associator failed! "),_("Create associator failed! "),ret); |
|---|
| 770 |
} |
|---|
| 771 |
userList->insert(pair<string,User*>(user->name.c_str(),user)); |
|---|
| 772 |
RFListAllUsers(); |
|---|
| 773 |
RFListAllGroups(); |
|---|
| 774 |
RFWarn( _("Warning"),_("Ok"),NULL,_("The old password can not be used any more for this user.\nAn empty password is used instead.\nPlease re-set a new password for this user.")); |
|---|
| 775 |
} |
|---|
| 776 |
RFRefresh(); |
|---|
| 777 |
} |
|---|
| 778 |
|
|---|
| 779 |
|
|---|
| 780 |
void QRFUserMin::RFRenameGroup(QString groupName) |
|---|
| 781 |
{ |
|---|
| 782 |
map<string,Group*>::iterator gpos=groupList->find(groupName.latin1()); |
|---|
| 783 |
if(gpos==groupList->end()) return; |
|---|
| 784 |
RFRenameGroup((*gpos).second); |
|---|
| 785 |
} |
|---|
| 786 |
|
|---|
| 787 |
void QRFUserMin::RFRenameGroup(Group * group) |
|---|
| 788 |
{ |
|---|
| 789 |
if(currentHostItem == NULL ||currentHostItem->client==NULL || group==NULL) return; |
|---|
| 790 |
QString s; |
|---|
| 791 |
bool ok; |
|---|
| 792 |
s.append( _( "Enter new name for \"" ) ); |
|---|
| 793 |
s.append(group->name.c_str()); |
|---|
| 794 |
s.append( "\" :"); |
|---|
| 795 |
QString text= QInputDialog::getText(_( "RenameDialog" ),s,QLineEdit::Normal, QString::null, &ok, NULL ); |
|---|
| 796 |
if(ok && RFVerifyString(text.latin1())==0 ) |
|---|
| 797 |
{ |
|---|
| 798 |
RFWarn( _("Warning"),_("Ok"), NULL, _("invalid name.")); |
|---|
| 799 |
} |
|---|
| 800 |
else if ( ok) |
|---|
| 801 |
{ |
|---|
| 802 |
int ret=0; |
|---|
| 803 |
if( text.compare(group->name.c_str())==0 ) return; |
|---|
| 804 |
if(groupList->find(text.latin1())!=groupList->end()) |
|---|
| 805 |
{ |
|---|
| 806 |
RFWarn( _("Warning"),_("Ok"),NULL,_("group name already exists.")); |
|---|
| 807 |
return; |
|---|
| 808 |
} |
|---|
| 809 |
//fetch old associators between user and group |
|---|
| 810 |
for(vector<MyAssociator*>::iterator mpos=associatorList.begin();mpos!=associatorList.end();mpos++) |
|---|
| 811 |
{ |
|---|
| 812 |
delete (*mpos); |
|---|
| 813 |
} |
|---|
| 814 |
associatorList.clear(); |
|---|
| 815 |
try{ |
|---|
| 816 |
MyAssociator::enumAssociatorFromGroup(currentHostItem->client, |
|---|
| 817 |
group,userList,&associatorList); |
|---|
| 818 |
}CATCH_EXCEPTION(NULL,_("Rename group failed"),_("Enumeration associator of group failed! "),ret); |
|---|
| 819 |
//CATCH_EXCEPTION(NULL,_("Enumeration associator of group failed"),_("Enumeration associator of group failed! "),ret); |
|---|
| 820 |
if (ret != 0) |
|---|
| 821 |
return; |
|---|
| 822 |
|
|---|
| 823 |
//clear old associators |
|---|
| 824 |
for(vector<MyAssociator*>::iterator mpos=associatorList.begin();mpos!=associatorList.end();mpos++) |
|---|
| 825 |
{ |
|---|
| 826 |
try{ |
|---|
| 827 |
(*mpos)->deleteMyAssociator(currentHostItem->client); |
|---|
| 828 |
}CATCH_EXCEPTION(NULL,_("Rename group failed"),_("Delete associator failed! "),ret); |
|---|
| 829 |
if(ret!=0) return; |
|---|
| 830 |
} |
|---|
| 831 |
//delete old group |
|---|
| 832 |
try{ |
|---|
| 833 |
group->deleteGroup(currentHostItem->client); |
|---|
| 834 |
}CATCH_EXCEPTION(NULL,_("Rename group failed"),_("Delete group failed! "),ret); |
|---|
| 835 |
if(ret!=0) return; |
|---|
| 836 |
map<string,Group*>::iterator gpos=groupList->find(group->name.c_str()); |
|---|
| 837 |
if(gpos!=groupList->end()) groupList->erase(gpos); |
|---|
| 838 |
group->name=text.latin1(); |
|---|
| 839 |
//create the new group (no password) |
|---|
| 840 |
try{ |
|---|
| 841 |
group->createGroup(currentHostItem->client); |
|---|
| 842 |
}CATCH_EXCEPTION(NULL,_("Rename group failed"),_("Create group failed! "),ret); |
|---|
| 843 |
if(ret!=0) return; |
|---|
| 844 |
//add the new associators as old associator |
|---|
| 845 |
for(vector<MyAssociator*>::iterator mpos=associatorList.begin();mpos!=associatorList.end();mpos++) |
|---|
| 846 |
{ |
|---|
| 847 |
try{ |
|---|
| 848 |
(*mpos)->createMyAssociator(currentHostItem->client); |
|---|
| 849 |
}catch(...){} |
|---|
| 850 |
//CATCH_EXCEPTION(NULL,_("Create associator failed! "),_("Create associator failed! "),ret); |
|---|
| 851 |
} |
|---|
| 852 |
groupList->insert(pair<string,Group *>(group->name.c_str(),group)); |
|---|
| 853 |
RFListAllUsers(); |
|---|
| 854 |
RFListAllGroups(); |
|---|
| 855 |
} |
|---|
| 856 |
RFRefresh(); |
|---|
| 857 |
} |
|---|
| 858 |
|
|---|
| 859 |
UserItem::UserItem(QRFUserMin * parent) : RFMScopeItem((RFMScopeItem *)parent) |
|---|
| 860 |
{ |
|---|
| 861 |
already=false; |
|---|
| 862 |
p=parent; |
|---|
| 863 |
} |
|---|
| 864 |
|
|---|
| 865 |
void UserItem::setupListViewColumns(RFMConsole *c) |
|---|
| 866 |
{ |
|---|
| 867 |
c->addColumn(_("User Name")); |
|---|
| 868 |
c->addColumn(_("User ID")); |
|---|
| 869 |
c->addColumn(_("Main Group")); |
|---|
| 870 |
c->addColumn(_("Description")); |
|---|
| 871 |
c->addColumn(_("Login Shell")); |
|---|
| 872 |
c->addColumn(_("Home Direction")); |
|---|
| 873 |
} |
|---|
| 874 |
|
|---|
| 875 |
QPixmap * UserItem::pixmap(int column, QIconSet::Size size, QIconSet::Mode mode, QIconSet::State state) const |
|---|
| 876 |
{ |
|---|
| 877 |
QPixmap *p = NULL; |
|---|
| 878 |
static QPixmap *userItems = NULL; |
|---|
| 879 |
static QPixmap *userItemsLarge = NULL; |
|---|
| 880 |
if(column == 0) { |
|---|
| 881 |
if(size == QIconSet::Automatic || size == QIconSet::Small) { |
|---|
| 882 |
if(userItems == NULL) |
|---|
| 883 |
userItems = p = new QPixmap((const char**)commonuser_small); |
|---|
| 884 |
else |
|---|
| 885 |
p = userItems; |
|---|
| 886 |
} |
|---|
| 887 |
else if(size == QIconSet::Large) { |
|---|
| 888 |
if(userItemsLarge == NULL) |
|---|
| 889 |
userItemsLarge = p = new QPixmap((const char**)commonuser); |
|---|
| 890 |
else |
|---|
| 891 |
p = userItemsLarge; |
|---|
| 892 |
} |
|---|
| 893 |
} |
|---|
| 894 |
return p; |
|---|
| 895 |
} |
|---|
| 896 |
|
|---|
| 897 |
bool UserItem::onSelect(RFMConsole *c, RFMSelection *s) |
|---|
| 898 |
{ |
|---|
| 899 |
RFMScopeItem::onSelect(c , s); |
|---|
| 900 |
c->insertCommandButton(ID_ADDNEWUSER, RFMConsole::ToolBar); |
|---|
| 901 |
c->insertCommandButton(ID_ADDNEWUSER, RFMConsole::MenuAction); |
|---|
| 902 |
c->insertCommandButton(ID_REFRESH,RFMConsole::ToolBar); |
|---|
| 903 |
c->insertCommandButton(ID_REFRESH,RFMConsole::MenuAction); |
|---|
| 904 |
c->insertCommandButton(ID_SWITCHER, RFMConsole::ToolBar); |
|---|
| 905 |
c->insertCommandButton(ID_SWITCHER, RFMConsole::MenuAction); |
|---|
| 906 |
if(p&&c) |
|---|
| 907 |
{ |
|---|
| 908 |
p->onHostChange(c,c->currentHostItem()); |
|---|
| 909 |
} |
|---|
| 910 |
show_data(); |
|---|
| 911 |
return true; |
|---|
| 912 |
} |
|---|
| 913 |
|
|---|
| 914 |
void UserItem::show_data() |
|---|
| 915 |
{ |
|---|
| 916 |
if(p && p->currentHostItem!=NULL &&p->currentHostItem->client!=NULL) |
|---|
| 917 |
{ |
|---|
| 918 |
if(!already) |
|---|
| 919 |
{ |
|---|
| 920 |
if(p->userList==NULL) p->RFListAllUsers(); |
|---|
| 921 |
for(map<string,User*>::iterator pos=p->userList->begin();pos!=p->userList->end();pos++) |
|---|
| 922 |
{ |
|---|
| 923 |
long int uid=strtoul(pos->second->uid.c_str(),NULL,10); |
|---|
| 924 |
if( displayAll == FALSE && (uid < 500||uid==65534) ) |
|---|
| 925 |
{ |
|---|
| 926 |
continue; |
|---|
| 927 |
} |
|---|
| 928 |
UserRecordItem* n=new UserRecordItem(this,(*pos).second); |
|---|
| 929 |
p->getConsole()->insertResultItem(getScopeItemHandle(), n); |
|---|
| 930 |
} |
|---|
| 931 |
already=true; |
|---|
| 932 |
} |
|---|
| 933 |
} |
|---|
| 934 |
} |
|---|
| 935 |
|
|---|
| 936 |
bool UserItem::onCommand(RFMConsole *c, int commandID, RFMSelection *s) |
|---|
| 937 |
{ |
|---|
| 938 |
p->onCommand(c , commandID , s); |
|---|
| 939 |
if(commandID==ID_ADDNEWUSER) |
|---|
| 940 |
{ |
|---|
| 941 |
if(p) |
|---|
| 942 |
{ |
|---|
| 943 |
p->RFAddNewUser(); |
|---|
| 944 |
} |
|---|
| 945 |
} |
|---|
| 946 |
else if(commandID==ID_SWITCHER) |
|---|
| 947 |
{ |
|---|
| 948 |
c->removeCommandButton(ID_SWITCHER, RFMConsole::MenuAction); |
|---|
| 949 |
c->removeCommandButton(ID_SWITCHER, RFMConsole::ToolBar); |
|---|
| 950 |
c->destroyCommandItem(ID_SWITCHER); |
|---|
| 951 |
displayAll=!displayAll; |
|---|
| 952 |
if(displayAll) |
|---|
| 953 |
{ |
|---|
| 954 |
RFMConsole::CommandItem cmd = { ID_SWITCHER, QIconSet(QPixmap(hide_system_xpm)),_("&Hide the system accounts"),_("Hide the system accounts"), |
|---|
| 955 |
_("Hide the system users and groups"), QString::null, 0, 0}; |
|---|
| 956 |
c->allocateCommandItem(cmd); |
|---|
| 957 |
} |
|---|
| 958 |
else |
|---|
| 959 |
{ |
|---|
| 960 |
RFMConsole::CommandItem cmd = { ID_SWITCHER, QIconSet(QPixmap(show_all_xpm)),_("&Show all accounts"),_("Show all accounts"), |
|---|
| 961 |
_("Show all users and groups"), QString::null, 0, 0}; |
|---|
| 962 |
c->allocateCommandItem(cmd); |
|---|
| 963 |
} |
|---|
| 964 |
c->insertCommandButton(ID_SWITCHER, RFMConsole::ToolBar); |
|---|
| 965 |
c->insertCommandButton(ID_SWITCHER, RFMConsole::MenuAction); |
|---|
| 966 |
if(p) |
|---|
| 967 |
{ |
|---|
| 968 |
p->RFRefresh(); |
|---|
| 969 |
} |
|---|
| 970 |
} |
|---|
| 971 |
return true; |
|---|
| 972 |
} |
|---|
| 973 |
|
|---|
| 974 |
QString UserItem::text(int column) const |
|---|
| 975 |
{ |
|---|
| 976 |
if(column == 0) return _("User"); |
|---|
| 977 |
else return QString::null; |
|---|
| 978 |
} |
|---|
| 979 |
|
|---|
| 980 |
void UserItem::clearResultItem() |
|---|
| 981 |
{ |
|---|
| 982 |
QPtrList<RFMItem> *l = children(); |
|---|
| 983 |
if(l) { |
|---|
| 984 |
QPtrListIterator<RFMItem> it(*l); |
|---|
| 985 |
RFMItem *i; |
|---|
| 986 |
while((i = it.current()) != 0) { |
|---|
| 987 |
++it; |
|---|
| 988 |
if(p&&p->getConsole()) { |
|---|
| 989 |
p->getConsole()->removeResultItem(i->getResultItemHandle()); |
|---|
| 990 |
} |
|---|
| 991 |
delete i; |
|---|
| 992 |
} |
|---|
| 993 |
delete l; |
|---|
| 994 |
already=false; |
|---|
| 995 |
} |
|---|
| 996 |
} |
|---|
| 997 |
|
|---|
| 998 |
GroupItem::GroupItem(QRFUserMin * parent): RFMScopeItem((RFMScopeItem *)parent) |
|---|
| 999 |
{ |
|---|
| 1000 |
already=false; |
|---|
| 1001 |
p=parent; |
|---|
| 1002 |
} |
|---|
| 1003 |
|
|---|
| 1004 |
void GroupItem::setupListViewColumns(RFMConsole *c) |
|---|
| 1005 |
{ |
|---|
| 1006 |
c->addColumn(_("Group Name")); |
|---|
| 1007 |
c->addColumn(_("Group ID")); |
|---|
| 1008 |
c->addColumn(_("Group Members")); |
|---|
| 1009 |
} |
|---|
| 1010 |
|
|---|
| 1011 |
QPixmap * GroupItem::pixmap(int column, QIconSet::Size size, QIconSet::Mode mode, QIconSet::State state) const |
|---|
| 1012 |
{ |
|---|
| 1013 |
QPixmap *p = NULL; |
|---|
| 1014 |
static QPixmap *groupItems = NULL; |
|---|
| 1015 |
static QPixmap *groupItemsLarge = NULL; |
|---|
| 1016 |
if(column == 0) { |
|---|
| 1017 |
if(size == QIconSet::Automatic || size == QIconSet::Small) { |
|---|
| 1018 |
if(groupItems == NULL) |
|---|
| 1019 |
groupItems = p = new QPixmap((const char**)commongroup_small); |
|---|
| 1020 |
else |
|---|
| 1021 |
p = groupItems; |
|---|
| 1022 |
} |
|---|
| 1023 |
else if(size == QIconSet::Large) { |
|---|
| 1024 |
if(groupItemsLarge == NULL) |
|---|
| 1025 |
groupItemsLarge = p = new QPixmap((const char**)commongroup); |
|---|
| 1026 |
else |
|---|
| 1027 |
p = groupItemsLarge; |
|---|
| 1028 |
} |
|---|
| 1029 |
} |
|---|
| 1030 |
return p; |
|---|
| 1031 |
} |
|---|
| 1032 |
|
|---|
| 1033 |
bool GroupItem::onSelect(RFMConsole *c, RFMSelection *s) |
|---|
| 1034 |
{ |
|---|
| 1035 |
RFMScopeItem::onSelect(c , s); |
|---|
| 1036 |
c->insertCommandButton(ID_ADDNEWGROUP, RFMConsole::ToolBar); |
|---|
| 1037 |
c->insertCommandButton(ID_ADDNEWGROUP, RFMConsole::MenuAction); |
|---|
| 1038 |
c->insertCommandButton(ID_REFRESH,RFMConsole::ToolBar); |
|---|
| 1039 |
c->insertCommandButton(ID_REFRESH,RFMConsole::MenuAction); |
|---|
| 1040 |
c->insertCommandButton(ID_SWITCHER, RFMConsole::ToolBar); |
|---|
| 1041 |
c->insertCommandButton(ID_SWITCHER, RFMConsole::MenuAction); |
|---|
| 1042 |
if(p&&c) |
|---|
| 1043 |
{ |
|---|
| 1044 |
p->onHostChange(c,c->currentHostItem()); |
|---|
| 1045 |
} |
|---|
| 1046 |
show_data(); |
|---|
| 1047 |
} |
|---|
| 1048 |
|
|---|
| 1049 |
void GroupItem::show_data() |
|---|
| 1050 |
{ |
|---|
| 1051 |
if(p&&p->currentHostItem!=NULL && p->currentHostItem->client!=NULL) |
|---|
| 1052 |
{ |
|---|
| 1053 |
if(!already) |
|---|
| 1054 |
{ |
|---|
| 1055 |
if(p->groupList==NULL) p->RFListAllGroups(); |
|---|
| 1056 |
for(map<string,Group*>::iterator gpos=p->groupList->begin();gpos!=p->groupList->end();gpos++) |
|---|
| 1057 |
{ |
|---|
| 1058 |
long int gid=strtoul(gpos->second->gid.c_str(),NULL,10); |
|---|
| 1059 |
if( displayAll == FALSE && (gid < 500||gid==65534) ) |
|---|
| 1060 |
{ |
|---|
| 1061 |
continue; |
|---|
| 1062 |
} |
|---|
| 1063 |
GroupRecordItem* n=new GroupRecordItem(this,(*gpos).second); |
|---|
| 1064 |
p->getConsole()->insertResultItem(getScopeItemHandle(), n); |
|---|
| 1065 |
} |
|---|
| 1066 |
already=true; |
|---|
| 1067 |
} |
|---|
| 1068 |
} |
|---|
| 1069 |
} |
|---|
| 1070 |
|
|---|
| 1071 |
bool GroupItem::onCommand(RFMConsole *c, int commandID, RFMSelection *s) |
|---|
| 1072 |
{ |
|---|
| 1073 |
p->onCommand(c , commandID , s); |
|---|
| 1074 |
if(commandID==ID_ADDNEWGROUP) |
|---|
| 1075 |
{ |
|---|
| 1076 |
if(p) |
|---|
| 1077 |
{ |
|---|
| 1078 |
p->RFAddNewGroup(); |
|---|
| 1079 |
} |
|---|
| 1080 |
} |
|---|
| 1081 |
else if(commandID==ID_SWITCHER) |
|---|
| 1082 |
{ |
|---|
| 1083 |
c->removeCommandButton(ID_SWITCHER, RFMConsole::MenuAction); |
|---|
| 1084 |
c->removeCommandButton(ID_SWITCHER, RFMConsole::ToolBar); |
|---|
| 1085 |
c->destroyCommandItem(ID_SWITCHER); |
|---|
| 1086 |
displayAll=!displayAll; |
|---|
| 1087 |
if(displayAll) |
|---|
| 1088 |
{ |
|---|
| 1089 |
RFMConsole::CommandItem cmd = { ID_SWITCHER, QIconSet(QPixmap(hide_system_xpm)),_("&Hide the system accounts"),_("Hide the system accounts"), |
|---|
| 1090 |
_("Hide the system users and groups"), QString::null, 0, 0}; |
|---|
| 1091 |
c->allocateCommandItem(cmd); |
|---|
| 1092 |
} |
|---|
| 1093 |
else |
|---|
| 1094 |
{ |
|---|
| 1095 |
RFMConsole::CommandItem cmd = { ID_SWITCHER, QIconSet(QPixmap(show_all_xpm)),_("&Show all accounts"),_("Show all accounts"), |
|---|
| 1096 |
_("Show all users and groups"), QString::null, 0, 0}; |
|---|
| 1097 |
c->allocateCommandItem(cmd); |
|---|
| 1098 |
} |
|---|
| 1099 |
c->insertCommandButton(ID_SWITCHER, RFMConsole::ToolBar); |
|---|
| 1100 |
c->insertCommandButton(ID_SWITCHER, RFMConsole::MenuAction); |
|---|
| 1101 |
if(p) |
|---|
| 1102 |
{ |
|---|
| 1103 |
p->RFRefresh(); |
|---|
| 1104 |
} |
|---|
| 1105 |
} |
|---|
| 1106 |
return true; |
|---|
| 1107 |
} |
|---|
| 1108 |
|
|---|
| 1109 |
QString GroupItem::text(int column) const |
|---|
| 1110 |
{ |
|---|
| 1111 |
if(column == 0) return _("Group"); |
|---|
| 1112 |
else return QString::null; |
|---|
| 1113 |
} |
|---|
| 1114 |
|
|---|
| 1115 |
|
|---|
| 1116 |
void GroupItem::clearResultItem() |
|---|
| 1117 |
{ |
|---|
| 1118 |
QPtrList<RFMItem> *l = children(); |
|---|
| 1119 |
if(l) { |
|---|
| 1120 |
QPtrListIterator<RFMItem> it(*l); |
|---|
| 1121 |
RFMItem *i; |
|---|
| 1122 |
while((i = it.current()) != 0) { |
|---|
| 1123 |
++it; |
|---|
| 1124 |
if(p&&p->getConsole()) { |
|---|
| 1125 |
p->getConsole()->removeResultItem(i->getResultItemHandle()); |
|---|
| 1126 |
} |
|---|
| 1127 |
delete i; |
|---|
| 1128 |
} |
|---|
| 1129 |
delete l; |
|---|
| 1130 |
already=false; |
|---|
| 1131 |
} |
|---|
| 1132 |
} |
|---|
| 1133 |
|
|---|
| 1134 |
|
|---|
| 1135 |
UserRecordItem::UserRecordItem(UserItem *parent,User* u): RFMResultItem((RFMScopeItem *)parent) |
|---|
| 1136 |
{ |
|---|
| 1137 |
p=parent; |
|---|
| 1138 |
user=u; |
|---|
| 1139 |
} |
|---|
| 1140 |
|
|---|
| 1141 |
QString UserRecordItem::text(int column) const |
|---|
| 1142 |
{ |
|---|
| 1143 |
if(user==NULL) return QString::null; |
|---|
| 1144 |
switch(column) |
|---|
| 1145 |
{ |
|---|
| 1146 |
case 0: |
|---|
| 1147 |
return user->name.c_str(); |
|---|
| 1148 |
case 1: |
|---|
| 1149 |
return user->uid.c_str(); |
|---|
| 1150 |
case 2: |
|---|
| 1151 |
return user->mainGroup.c_str(); |
|---|
| 1152 |
case 3: |
|---|
| 1153 |
return user->description.c_str(); |
|---|
| 1154 |
case 4: |
|---|
| 1155 |
return user->shell.c_str(); |
|---|
| 1156 |
case 5: |
|---|
| 1157 |
return user->home.c_str(); |
|---|
| 1158 |
default: |
|---|
| 1159 |
return QString::null; |
|---|
| 1160 |
} |
|---|
| 1161 |
} |
|---|
| 1162 |
|
|---|
| 1163 |
QPixmap * UserRecordItem::pixmap(int column, QIconSet::Size size, QIconSet::Mode mode, QIconSet::State state) const |
|---|
| 1164 |
{ |
|---|
| 1165 |
|
|---|
| 1166 |
if(column != 0) |
|---|
| 1167 |
return NULL; |
|---|
| 1168 |
QPixmap *p = NULL; |
|---|
| 1169 |
static QPixmap *commUserIcon = NULL; |
|---|
| 1170 |
static QPixmap *commUserIconLarge = NULL; |
|---|
| 1171 |
static QPixmap *sysUserIcon = NULL; |
|---|
| 1172 |
static QPixmap *sysUserIconLarge = NULL; |
|---|
| 1173 |
long int uid=strtoul(user->uid.c_str(),NULL,10); |
|---|
| 1174 |
bool systemUser = false; |
|---|
| 1175 |
if(uid < 500 || uid == 65534) |
|---|
| 1176 |
systemUser = true; |
|---|
| 1177 |
if(size == QIconSet::Automatic || size == QIconSet::Small) { |
|---|
| 1178 |
if(systemUser) |
|---|
| 1179 |
{ |
|---|
| 1180 |
if (sysUserIcon == NULL) |
|---|
| 1181 |
sysUserIcon = p = new QPixmap((const char**)systemuser_small); |
|---|
| 1182 |
else |
|---|
| 1183 |
p = sysUserIcon; |
|---|
| 1184 |
} |
|---|
| 1185 |
else |
|---|
| 1186 |
{ |
|---|
| 1187 |
if (commUserIcon == NULL) |
|---|
| 1188 |
commUserIcon = p = new QPixmap((const char**)commonuser_small); |
|---|
| 1189 |
else |
|---|
| 1190 |
p = commUserIcon; |
|---|
| 1191 |
} |
|---|
| 1192 |
} |
|---|
| 1193 |
else if(size == QIconSet::Large) { |
|---|
| 1194 |
if(systemUser) |
|---|
| 1195 |
{ |
|---|
| 1196 |
if(sysUserIconLarge == NULL) |
|---|
| 1197 |
sysUserIconLarge = p = new QPixmap((const char**)systemuser); |
|---|
| 1198 |
else |
|---|
| 1199 |
p = sysUserIconLarge; |
|---|
| 1200 |
} |
|---|
| 1201 |
else |
|---|
| 1202 |
{ |
|---|
| 1203 |
if(commUserIconLarge == NULL) |
|---|
| 1204 |
commUserIconLarge = p = new QPixmap((const char**)commonuser); |
|---|
| 1205 |
else |
|---|
| 1206 |
p = commUserIconLarge; |
|---|
| 1207 |
} |
|---|
| 1208 |
} |
|---|
| 1209 |
return p; |
|---|
| 1210 |
} |
|---|
| 1211 |
|
|---|
| 1212 |
bool UserRecordItem::onSelect(RFMConsole *c, RFMSelection *s) |
|---|
| 1213 |
{ |
|---|
| 1214 |
c->insertCommandButton(ID_ADDNEWUSER, RFMConsole::ToolBar); |
|---|
| 1215 |
c->insertCommandButton(ID_ADDNEWUSER, RFMConsole::MenuAction); |
|---|
| 1216 |
c->insertCommandButton(ID_DELETE, RFMConsole::ToolBar); |
|---|
| 1217 |
c->insertCommandButton(ID_DELETE, RFMConsole::MenuAction); |
|---|
| 1218 |
c->insertCommandButton(ID_RENAME, RFMConsole::ToolBar); |
|---|
| 1219 |
c->insertCommandButton(ID_RENAME, RFMConsole::MenuAction); |
|---|
| 1220 |
c->insertCommandButton(ID_REFRESH, RFMConsole::ToolBar); |
|---|
| 1221 |
c->insertCommandButton(ID_REFRESH, RFMConsole::MenuAction); |
|---|
| 1222 |
c->insertCommandButton(ID_SWITCHER, RFMConsole::ToolBar); |
|---|
| 1223 |
c->insertCommandButton(ID_SWITCHER, RFMConsole::MenuAction); |
|---|
| 1224 |
c->insertCommandButton(RFMConsole::CmdProperties, RFMConsole::ToolBar); |
|---|
| 1225 |
c->setCommandState(RFMConsole::CmdProperties, true, true); |
|---|
| 1226 |
} |
|---|
| 1227 |
|
|---|
| 1228 |
bool UserRecordItem::onCommand(RFMConsole *c, int commandID, RFMSelection *s) |
|---|
| 1229 |
{ |
|---|
| 1230 |
if(p==NULL) return false; |
|---|
| 1231 |
p->onCommand(c , commandID , s); |
|---|
| 1232 |
if(commandID == ID_DELETE) |
|---|
| 1233 |
{ |
|---|
| 1234 |
if(p->p) p->p->RFDeleteUser(user); |
|---|
| 1235 |
} |
|---|
| 1236 |
else if(commandID == ID_RENAME) |
|---|
| 1237 |
{ |
|---|
| 1238 |
if(p->p) p->p->RFRenameUser(user); |
|---|
| 1239 |
} |
|---|
| 1240 |
return true; |
|---|
| 1241 |
} |
|---|
| 1242 |
|
|---|
| 1243 |
bool UserRecordItem::onProperties(RFMConsole *c, RFMSelection* s) |
|---|
| 1244 |
{ |
|---|
| 1245 |
if(p==NULL) return false; |
|---|
| 1246 |
if(p->p) |
|---|
| 1247 |
{ |
|---|
| 1248 |
p->p->RFSetUserPropties(user); |
|---|
| 1249 |
} |
|---|
| 1250 |
} |
|---|
| 1251 |
|
|---|
| 1252 |
GroupRecordItem::GroupRecordItem(GroupItem *parent,Group* g): RFMResultItem((RFMScopeItem *)parent) |
|---|
| 1253 |
{ |
|---|
| 1254 |
p=parent; |
|---|
| 1255 |
group=g; |
|---|
| 1256 |
} |
|---|
| 1257 |
|
|---|
| 1258 |
QString GroupRecordItem::text(int column) const |
|---|
| 1259 |
{ |
|---|
| 1260 |
if(group==NULL) return QString::null; |
|---|
| 1261 |
if(column==0) return group->name.c_str(); |
|---|
| 1262 |
else if(column==1) return group->gid.c_str(); |
|---|
| 1263 |
else if(column==2) |
|---|
| 1264 |
{ |
|---|
| 1265 |
QString members; |
|---|
| 1266 |
for(vector<string>::iterator mpos=group->members->begin(); mpos!=group->members->end();mpos++) |
|---|
| 1267 |
{ |
|---|
| 1268 |
if(mpos==group->members->begin()) members=(*mpos).c_str(); |
|---|
| 1269 |
else members =members+ ","+(*mpos).c_str(); |
|---|
| 1270 |
} |
|---|
| 1271 |
return members; |
|---|
| 1272 |
} |
|---|
| 1273 |
return QString::null; |
|---|
| 1274 |
} |
|---|
| 1275 |
|
|---|
| 1276 |
QPixmap * GroupRecordItem::pixmap(int column, QIconSet::Size size, QIconSet::Mode mode, QIconSet::State state) const |
|---|
| 1277 |
{ |
|---|
| 1278 |
|
|---|
| 1279 |
if(column != 0) |
|---|
| 1280 |
return NULL; |
|---|
| 1281 |
QPixmap *p = NULL; |
|---|
| 1282 |
static QPixmap *commGroupIcon = NULL; |
|---|
| 1283 |
static QPixmap *commGroupIconLarge = NULL; |
|---|
| 1284 |
static QPixmap *sysGroupIcon = NULL; |
|---|
| 1285 |
static QPixmap *sysGroupIconLarge = NULL; |
|---|
| 1286 |
long int uid=strtoul(group->gid.c_str(),NULL,10); |
|---|
| 1287 |
bool systemGroup = false; |
|---|
| 1288 |
if(uid < 500 || uid == 65534) |
|---|
| 1289 |
systemGroup = true; |
|---|
| 1290 |
if(size == QIconSet::Automatic || size == QIconSet::Small) { |
|---|
| 1291 |
if(systemGroup) |
|---|
| 1292 |
{ |
|---|
| 1293 |
if (sysGroupIcon == NULL) |
|---|
| 1294 |
sysGroupIcon = p = new QPixmap((const char**)systemgroup_small); |
|---|
| 1295 |
else |
|---|
| 1296 |
p = sysGroupIcon; |
|---|
| 1297 |
} |
|---|
| 1298 |
else |
|---|
| 1299 |
{ |
|---|
| 1300 |
if (commGroupIcon == NULL) |
|---|
| 1301 |
commGroupIcon = p = new QPixmap((const char**)commongroup_small); |
|---|
| 1302 |
else |
|---|
| 1303 |
p = commGroupIcon; |
|---|
| 1304 |
} |
|---|
| 1305 |
} |
|---|
| 1306 |
else if(size == QIconSet::Large) { |
|---|
| 1307 |
if(systemGroup) |
|---|
| 1308 |
{ |
|---|
| 1309 |
if(sysGroupIconLarge == NULL) |
|---|
| 1310 |
sysGroupIconLarge = p = new QPixmap((const char**)systemgroup); |
|---|
| 1311 |
else |
|---|
| 1312 |
p = sysGroupIconLarge; |
|---|
| 1313 |
} |
|---|
| 1314 |
else |
|---|
| 1315 |
{ |
|---|
| 1316 |
if(commGroupIconLarge == NULL) |
|---|
| 1317 |
commGroupIconLarge = p = new QPixmap((const char**)commongroup); |
|---|
| 1318 |
else |
|---|
| 1319 |
p = commGroupIconLarge; |
|---|
| 1320 |
} |
|---|
| 1321 |
} |
|---|
| 1322 |
return p; |
|---|
| 1323 |
} |
|---|
| 1324 |
|
|---|
| 1325 |
bool GroupRecordItem::onSelect(RFMConsole *c, RFMSelection *s) |
|---|
| 1326 |
{ |
|---|
| 1327 |
c->insertCommandButton(ID_ADDNEWGROUP, RFMConsole::ToolBar); |
|---|
| 1328 |
c->insertCommandButton(ID_ADDNEWGROUP, RFMConsole::MenuAction); |
|---|
| 1329 |
c->insertCommandButton(ID_DELETE, RFMConsole::ToolBar); |
|---|
| 1330 |
c->insertCommandButton(ID_DELETE, RFMConsole::MenuAction); |
|---|
| 1331 |
c->insertCommandButton(ID_RENAME, RFMConsole::ToolBar); |
|---|
| 1332 |
c->insertCommandButton(ID_RENAME, RFMConsole::MenuAction); |
|---|
| 1333 |
c->insertCommandButton(ID_REFRESH, RFMConsole::ToolBar); |
|---|
| 1334 |
c->insertCommandButton(ID_REFRESH, RFMConsole::MenuAction); |
|---|
| 1335 |
c->insertCommandButton(ID_SWITCHER, RFMConsole::ToolBar); |
|---|
| 1336 |
c->insertCommandButton(ID_SWITCHER, RFMConsole::MenuAction); |
|---|
| 1337 |
c->insertCommandButton(RFMConsole::CmdProperties, RFMConsole::ToolBar); |
|---|
| 1338 |
c->setCommandState(RFMConsole::CmdProperties, true, true); |
|---|
| 1339 |
} |
|---|
| 1340 |
|
|---|
| 1341 |
bool GroupRecordItem::onCommand(RFMConsole *c, int commandID, RFMSelection *s) |
|---|
| 1342 |
{ |
|---|
| 1343 |
if(p==NULL) return false; |
|---|
| 1344 |
p->onCommand(c , commandID , s); |
|---|
| 1345 |
if(commandID == ID_DELETE) |
|---|
| 1346 |
{ |
|---|
| 1347 |
if(p->p) |
|---|
| 1348 |
p->p->RFDeleteGroup(group); |
|---|
| 1349 |
} |
|---|
| 1350 |
else if(commandID == ID_RENAME) |
|---|
| 1351 |
{ |
|---|
| 1352 |
if(p->p) p->p->RFRenameGroup(group); |
|---|
| 1353 |
} |
|---|
| 1354 |
return true; |
|---|
| 1355 |
} |
|---|
| 1356 |
|
|---|
| 1357 |
bool GroupRecordItem::onProperties(RFMConsole *c, RFMSelection* s) |
|---|
| 1358 |
{ |
|---|
| 1359 |
if(p==NULL) return false; |
|---|
| 1360 |
if(p->p) |
|---|
| 1361 |
p->p->RFSetGroupPropties(group); |
|---|
| 1362 |
} |
|---|