source: src-qt4/pc-usermanager/pcbsdusermanager.cpp @ 7cc177e

9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3
Last change on this file since 7cc177e was 7cc177e, checked in by Kris Moore <kris@…>, 13 months ago

Fix up all the last bits of clang / HEAD fussiness

  • Property mode set to 100644
File size: 4.4 KB
Line 
1/***************************************************************************
2 *   Copyright (C) 2007, 2012 by Tim McCormick   *
3 *   tim@pcbsd.org   *
4 *                                                                         *
5 *   Permission is hereby granted, free of charge, to any person obtaining *
6 *   a copy of this software and associated documentation files (the       *
7 *   "Software"), to deal in the Software without restriction, including   *
8 *   without limitation the rights to use, copy, modify, merge, publish,   *
9 *   distribute, sublicense, and/or sell copies of the Software, and to    *
10 *   permit persons to whom the Software is furnished to do so, subject to *
11 *   the following conditions:                                             *
12 *                                                                         *
13 *   The above copyright notice and this permission notice shall be        *
14 *   included in all copies or substantial portions of the Software.       *
15 *                                                                         *
16 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       *
17 *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    *
18 *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR     *
20 *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
21 *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
22 *   OTHER DEALINGS IN THE SOFTWARE.                                       *
23 ***************************************************************************/
24
25#include <qlayout.h>
26#include <qtranslator.h>
27#include <qtextcodec.h>
28#include <unistd.h>
29#include <sys/types.h>
30
31#include "pcbsdusermanager.h"
32
33void PCBSDUserManager::setupUMDialogs()
34{
35    layout = new QGridLayout(widgetUserContainer);
36    changesMade = false;
37
38    //Init GUI
39    if (getuid() == 0) //Check for root
40    {
41       // Setup our buttons
42       pushSave->setEnabled(false);
43       connect(pushClose, SIGNAL(clicked()), this, SLOT(slotClose()));
44       connect(pushSave, SIGNAL(clicked()), this, SLOT(slotSave()));
45
46       back = new UserManagerBackend(wDir);
47       advancedGui = new mainDlgCode();
48       advancedGui->programInit(back, wDir);
49       simpleGui = new SimpleDlgCode();
50       simpleGui->programInit(back, wDir);
51       layout->addWidget(simpleGui);
52 
53       connect(advancedGui, SIGNAL(changed( bool )), this, SLOT(configChanged()));
54       connect(simpleGui, SIGNAL(changed()), this, SLOT(configChanged()));
55       connect(simpleGui, SIGNAL(advancedView()), this, SLOT(switchToAdvanced()));
56       connect(advancedGui, SIGNAL(simpleView()), this, SLOT(switchToSimple()));
57    }
58    else
59    {
60       qDebug("Error, needs to be run as root");
61       exit(1);
62    }
63};
64
65
66PCBSDUserManager::~PCBSDUserManager()
67{
68}
69
70void PCBSDUserManager::switchToAdvanced()
71{
72    simpleGui->setParent(0);
73    layout->addWidget(advancedGui);
74    advancedGui->setParent(widgetUserContainer);
75    advancedGui->show();
76}
77
78void PCBSDUserManager::switchToSimple()
79{
80    advancedGui->setParent(0);
81    simpleGui->setParent(widgetUserContainer);
82    layout->addWidget(simpleGui);
83    simpleGui->show();
84}
85
86void PCBSDUserManager::configChanged()
87{
88  pushSave->setEnabled(true);
89  changesMade = true;
90}
91
92void PCBSDUserManager::slotSave()
93{
94  if (back->commit())
95  {
96    pushSave->setEnabled(false);
97    changesMade = false;
98  }
99}
100
101void PCBSDUserManager::slotClose()
102{
103  if(changesMade)
104  {
105      int answer = QMessageBox::question(this,
106                                         tr("Apply pending changes?"),
107                                         tr("There are pending changes which have not been applied. Would you like to apply them before quitting?") ,
108                                         QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
109                                         QMessageBox::Cancel);
110      if(answer == QMessageBox::Yes) back->commit();
111      else if(answer == QMessageBox::Cancel) return;
112  }
113  close();
114}
115
116/**
117  * Override QDialog's closeEvent() which is triggered when the window 'X' is hit and use our close slot
118  */
119void PCBSDUserManager::closeEvent(QCloseEvent*)
120{
121    slotClose();
122}
123
124void PCBSDUserManager::setWardenMode(QString d, QString ip)
125{
126  wDir = d;
127  wIP = ip;
128  setWindowTitle(tr("Editing Users for Jail:") + " " + wIP );
129}
Note: See TracBrowser for help on using the repository browser.