2 * Copyright (c) 1998 Denis Perchine <dyp@perchine.com>
3 * Copyright (c) 2004 Szombathelyi GyĂśrgy <gyurco@freemail.hu>
4 * Former maintainer: Adriaan de Groot <groot@kde.org>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public
8 * License version 2 or at your option version 3 as published by
9 * the Free Software Foundation.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
23 #include <kxmlguifactory.h>
25 #include <kiconloader.h>
28 #include <kstandardaction.h>
29 #include <kactioncollection.h>
30 #include <ktoggleaction.h>
32 #include <kstatusbar.h>
33 #include <kedittoolbar.h>
36 #include "ku_global.h"
37 #include "ku_configdlg.h"
38 #include "ku_mainwidget.h"
39 #include "ku_selectconn.h"
40 #include "ku_mainview.h"
42 KU_MainWidget::KU_MainWidget() : KXmlGuiWindow(0)
44 mv
= new KU_MainView(this);
47 mv
->setShowSys( mShowSys
->isChecked() );
51 statusBar()->insertItem(i18n("Reading configuration"), 0);
57 statusBar()->changeItem(i18n("Ready"), 0);
60 KU_MainWidget::~KU_MainWidget()
65 bool KU_MainWidget::queryClose()
67 return mv
->queryClose();
70 void KU_MainWidget::setupActions()
72 KStandardAction::quit(this, SLOT(close()), actionCollection());
73 KStandardAction::keyBindings(guiFactory(), SLOT(configureShortcuts()), actionCollection());
75 KStandardAction::preferences(this, SLOT(properties()), actionCollection());
78 action
= new KAction(KIcon("list-add-user"), i18n("&Add..."), this);
79 actionCollection()->addAction("add_user", action
);
80 connect( action
, SIGNAL(triggered(bool)), mv
, SLOT(useradd()) );
82 action
= new KAction(KIcon("user-properties"), i18n("&Edit..."), this);
83 actionCollection()->addAction("edit_user", action
);
84 connect( action
, SIGNAL(triggered(bool)), mv
, SLOT(useredit()) );
86 action
= new KAction(KIcon("list-remove-user"), i18n("&Delete..."), this);
87 actionCollection()->addAction("delete_user", action
);
88 connect( action
, SIGNAL(triggered(bool)), mv
, SLOT(userdel()) );
90 action
= new KAction(KIcon("preferences-desktop-user-password"), i18n("&Set Password..."), this);
91 actionCollection()->addAction("set_password_user", action
);
92 connect( action
, SIGNAL(triggered(bool)), mv
, SLOT(setpwd()) );
94 action
= new KAction(KIcon("user-group-new"), i18n("&Add..."), this);
95 actionCollection()->addAction("add_group", action
);
96 connect( action
, SIGNAL(triggered(bool)), mv
, SLOT(grpadd()) );
98 action
= new KAction(KIcon("user-group-properties"), i18n("&Edit..."), this);
99 actionCollection()->addAction("edit_group", action
);
100 connect( action
, SIGNAL(triggered(bool)), mv
, SLOT(grpedit()) );
102 action
= new KAction(KIcon("user-group-delete"), i18n("&Delete..."), this);
103 actionCollection()->addAction("delete_group", action
);
104 connect( action
, SIGNAL(triggered(bool)), mv
, SLOT(grpdel()) );
106 action
= new KAction(KIcon("view-refresh"), i18n("&Reload..."), this);
107 actionCollection()->addAction("reload", action
);
108 connect( action
, SIGNAL(triggered(bool)), this, SLOT(reload()) );
110 action
= new KAction(i18n("&Select Connection..."), this);
111 actionCollection()->addAction("select_conn", action
);
112 connect( action
, SIGNAL(triggered(bool)), this, SLOT(selectconn()) );
114 mShowSys
= new KToggleAction(i18n("Show System Users/Groups"), this);
115 actionCollection()->addAction("show_sys", mShowSys
);
116 connect( mShowSys
, SIGNAL(triggered(bool)), this, SLOT(showSys(bool)) );
118 mShowSys
->setCheckedState(KGuiItem(i18n("Hide System Users/Groups")));
119 mShowSys
->setChecked( KU_Global::kcfg()->showsys() );
122 void KU_MainWidget::showSys( bool show
)
124 KU_Global::kcfg()->setShowsys( show
);
125 mv
->setShowSys( show
);
130 void KU_MainWidget::properties()
132 KU_ConfigDlg
*configdlg
= new KU_ConfigDlg( KU_Global::kcfg(), this );
133 connect(configdlg
, SIGNAL(settingsChanged(const QString
&)), this, SLOT(slotApplySettings()));
138 void KU_MainWidget::reload()
143 void KU_MainWidget::init()
150 rw
= ! ( KU_Global::users()->getCaps() & KU_Users::Cap_ReadOnly
);
151 kDebug() << "Users rw()" << rw
;
152 actionCollection()->action("add_user")->setEnabled( rw
);
153 actionCollection()->action("edit_user")->setEnabled( rw
);
154 actionCollection()->action("delete_user")->setEnabled( rw
);
155 actionCollection()->action("set_password_user")->setEnabled( rw
);
157 connect( mv
, SIGNAL(userSelected(bool)),
158 actionCollection()->action("edit_user"), SLOT(setEnabled(bool)) );
159 connect( mv
, SIGNAL(userSelected(bool)),
160 actionCollection()->action("delete_user"), SLOT(setEnabled(bool)) );
161 connect( mv
, SIGNAL(userSelected(bool)),
162 actionCollection()->action("set_password_user"), SLOT(setEnabled(bool)) );
164 disconnect( mv
, SIGNAL(userSelected(bool)), 0, 0 );
167 rw
= ! ( KU_Global::groups()->getCaps() & KU_Groups::Cap_ReadOnly
);
168 kDebug() << "Groups rw()" << rw
;
169 actionCollection()->action("add_group")->setEnabled( rw
);
170 actionCollection()->action("edit_group")->setEnabled( rw
);
171 actionCollection()->action("delete_group")->setEnabled( rw
);
173 connect( mv
, SIGNAL(groupSelected(bool)),
174 actionCollection()->action("edit_group"), SLOT(setEnabled(bool)) );
175 connect( mv
, SIGNAL(groupSelected(bool)),
176 actionCollection()->action("delete_group"), SLOT(setEnabled(bool)) );
178 disconnect( mv
, SIGNAL(groupSelected(bool)), 0, 0 );
182 QTimer::singleShot( 0, mv
, SLOT(slotTabChanged()) );
185 void KU_MainWidget::slotApplySettings()
187 kDebug() << "settings changed!";
191 void KU_MainWidget::slotApplyConnection()
193 kDebug() << "slotApplyConnection()";
194 QString conn
= sc
->connSelected();
195 KU_Global::kcfg()->setConnection( conn
);
196 KU_Global::initCfg( conn
);
200 void KU_MainWidget::selectconn()
202 sc
= new KU_SelectConn( KU_Global::kcfg()->connection(), this );
203 connect( sc
, SIGNAL(applyClicked()), SLOT(slotApplyConnection()) );
204 connect( sc
, SIGNAL(okClicked()), SLOT(slotApplyConnection()) );
208 #include "ku_mainwidget.moc"