schedulator: only count bugs that you were the *last* one to resolve, but
[wvapps.git] / unikonf / ukconfig.cc
blob1cbca0dc957d4f5e55c547135d08e133511a4703
1 /*
2 * ** Copyright (C) 2002 Net Integration Technologies
3 * **
4 * ** This program is free software; you can redistribute it and/or modify
5 * ** it under the terms of the GNU Lesser General Public License as published by
6 * ** the Free Software Foundation; either version 2 of the License, or
7 * ** (at your option) any later version.
8 * **
9 * ** This program is distributed in the hope that it will be useful,
10 * ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * ** GNU General Public License for more details.
13 * **
14 * ** You should have received a copy of the GNU Lesser General Public License
15 * ** along with this program; if not, write to the Free Software
16 * ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 * */
19 #include "ukconfig.h"
20 #include "ukconfig.moc"
22 #include "kapplication.h"
24 // little helper borrowed from the KMail Sources: - thanks guys ;)
25 static inline QPixmap loadIcon( const char * name )
27 return KGlobal::instance()->iconLoader()->loadIcon( QString::fromLatin1(name), KIcon::NoGroup, KIcon::SizeMedium);
30 /**************************************************************************/
31 /* */
32 /* UniKonfAddMount Starts Here */
34 UniKonfAddMount::UniKonfAddMount(QWidget *parent, const char *name, KSimpleConfig *_config)
35 : KDialog(parent, name, true),
36 config(_config)//, mp_modified(false)
38 aslayout = new QGridLayout(this,5,4,3,-1);
39 CHECK_PTR(aslayout);
41 ok = new KPushButton(i18n("Ok"),this,"prefs_ok");
42 CHECK_PTR(ok);
44 ok->setDefault(TRUE);
46 close = new KPushButton(i18n("Close"),this,"prefs_close");
47 CHECK_PTR(close);
49 help = new KPushButton(i18n("Help"),this,"prefs_help");
50 CHECK_PTR(help);
52 monikerl = new QLabel(NULL, i18n("Moniker:"), this);
53 moniker = new KLineEdit(this);
54 mountpointl = new QLabel(NULL, i18n("Mount Point:"), this);
55 mountpoint = new KLineEdit(this);
56 mountpoint->setText("/");
58 aslayout->addWidget(monikerl, 0, 0);
59 aslayout->addMultiCellWidget(moniker, 0, 0, 1, 3);
60 aslayout->addWidget(mountpointl, 2, 0);
61 aslayout->addMultiCellWidget(mountpoint, 2, 2, 1, 3);
62 aslayout->addWidget(ok,5,1);
63 aslayout->addWidget(close,5,2);
64 aslayout->addWidget(help,5,3);
66 connect( ok, SIGNAL(clicked()), SLOT(createnew()));
67 connect( close, SIGNAL(clicked()), SLOT(reject()));
69 adjustSize();
72 UniKonfAddMount::UniKonfAddMount(QString *_mountpoint, QWidget *parent,
73 const char *name, KSimpleConfig *_config)
74 : KDialog(parent,name,TRUE),
75 config(_config),
76 old_mount(*_mountpoint)
78 config->setGroup(_mountpoint->latin1());
79 aslayout = new QGridLayout(this,5,4,3,-1);
80 CHECK_PTR(aslayout);
82 ok = new KPushButton(i18n("Ok"),this,"prefs_ok");
83 CHECK_PTR(ok);
85 ok->setDefault(TRUE);
87 close = new KPushButton(i18n("Close"),this,"prefs_close");
88 CHECK_PTR(close);
90 help = new KPushButton(i18n("Help"),this,"prefs_help");
91 CHECK_PTR(help);
93 monikerl = new QLabel(NULL, i18n("Moniker:"), this);
94 moniker = new KLineEdit(this);
95 moniker->setText(config->readEntry("moniker"));
97 mountpointl = new QLabel(NULL, i18n("Mount Point:"), this);
98 mountpoint = new KLineEdit(this);
99 mountpoint->setText(_mountpoint->latin1());
101 aslayout->addWidget(monikerl, 0, 0);
102 aslayout->addMultiCellWidget(moniker, 0, 0, 1, 3);
103 aslayout->addWidget(mountpointl, 2, 0);
104 aslayout->addMultiCellWidget(mountpoint, 2, 2, 1, 3);
106 aslayout->addWidget(ok,4,1);
107 aslayout->addWidget(close,4,2);
108 aslayout->addWidget(help,4,3);
110 connect( ok, SIGNAL(clicked()), SLOT(modify()));
111 connect( close, SIGNAL(clicked()), SLOT(reject()));
115 UniKonfAddMount::~UniKonfAddMount()
120 void UniKonfAddMount::createnew()
122 config->setGroup(mountpoint->text());
123 config->writeEntry("moniker", moniker->text());
124 config->sync();
125 QWidget::close();
128 void UniKonfAddMount::modify()
130 config->setGroup(mountpoint->text());
131 config->deleteGroup(old_mount, true);
132 config->writeEntry("moniker", moniker->text());
133 config->sync();
134 QWidget::close();
137 /**************************************************************************/
138 /* */
139 /* UniKonfCfgConn Starts Here */
140 /* - Configurationof mountpoints */
142 UniKonfCfgConn::UniKonfCfgConn(QWidget *parent, const char *name, KSimpleConfig *_config)
143 : UniKonfCfgPage(parent,name),
144 config(_config)
146 servername = new QString(QString::null);
147 CHECK_PTR(servername);
149 connectlayout = new QGridLayout(this,5,3,3,-1);
150 CHECK_PTR(connectlayout);
151 connectwindow = new KListBox(this,"connectwindow");
152 CHECK_PTR(connectwindow);
153 connect_add = new KPushButton(i18n("Add"),this,"connect_add");
154 CHECK_PTR(connect_add);
155 connect_mod = new KPushButton(i18n("Modify"),this,"connect_mod");
156 CHECK_PTR(connect_mod);
157 connect_del = new KPushButton(i18n("Delete"),this,"connect_del");
158 CHECK_PTR(connect_del);
160 connectlayout->addMultiCellWidget(connectwindow,0,4,0,1);
161 connectlayout->addWidget(connect_add,0,2);
162 connectlayout->addWidget(connect_mod,1,2);
163 connectlayout->addWidget(connect_del,2,2);
164 connectlayout->addRowSpacing(3,50);
165 connectlayout->addRowSpacing(4,50);
167 connect(connect_add,SIGNAL(clicked()),SLOT(addMountPoint()));
168 connect(connect_mod,SIGNAL(clicked()),SLOT(modMountPoint()));
169 connect(connect_del,SIGNAL(clicked()),SLOT(delMountPoint()));
170 connect(connectwindow,SIGNAL(highlighted(const QString &)), SLOT(setMountPoint(const QString &)));
171 fillwindow();
174 UniKonfCfgConn::~UniKonfCfgConn()
179 QString UniKonfCfgConn::helpAnchor() {
180 return QString::fromLatin1("configure-connections");
183 void UniKonfCfgConn::fillwindow()
185 connectwindow->clear();
186 QStringList sectlist(config->groupList());
187 int count = 0;
188 for ( QStringList::Iterator it = sectlist.begin(); it != sectlist.end(); ++it )
190 if (((*it).contains("KFile") == 0) &&
191 ((*it).contains("Global") == 0 ) &&
192 ((*it).contains("Cert") == 0 ) &&
193 ((*it).contains("<default>") == 0) )
194 connectwindow->insertItem((*it).latin1(), count++);
198 void UniKonfCfgConn::addMountPoint()
200 UniKonfAddMount dlg(this,"kdiradm",config);
201 dlg.setCaption("Add Server");
202 dlg.exec();
203 fillwindow();
206 void UniKonfCfgConn::modMountPoint()
208 if (!servername->isNull())
210 UniKonfAddMount dlg(servername, this,"kdiradm",config);
211 dlg.setCaption(i18n("Modify Server"));
212 dlg.exec();
213 fillwindow();
214 } else {
215 KMessageBox::sorry(this,i18n("You Must Select a Server from the list!"));
219 void UniKonfCfgConn::delMountPoint()
221 if (!servername->isNull())
223 config->deleteGroup(servername->latin1());
224 config->sync();
225 } else {
226 KMessageBox::sorry(this,i18n("You Must Select a Server from the list!"));
228 fillwindow();
231 void UniKonfCfgConn::setMountPoint(const QString &_selected)
233 servername = new QString(_selected);
236 void UniKonfCfgConn::apply()
238 // For this page, apply doesn't really make sense, so this is just an empty
239 // function
242 /**************************************************************************/
243 /* */
244 /* UniKonfPrefs Starts Here */
246 UniKonfCfg::UniKonfCfg(QWidget *parent, const char *name, KSimpleConfig *_config)
247 : KDialogBase(IconList, i18n("Configure"), Help|Apply|Ok|Cancel, Ok, parent, name, true, true )
249 setIconListAllVisible( true );
251 QWidget *page;
252 QVBoxLayout *vlay;
254 // Connections to UniKonf mountpoints.
255 // -> Client, IniFile, etc.
256 page = addPage( i18n("Mountpoints"), i18n("Mountpoints"), loadIcon("network"));
257 CHECK_PTR(page);
259 vlay = new QVBoxLayout( page, 0, spacingHint() );
260 CHECK_PTR(vlay);
262 connwidget = new UniKonfCfgConn( page, "connections", _config);
263 CHECK_PTR(connwidget);
265 vlay->addWidget(connwidget);
267 connwidget->setPageIndex( pageIndex( page ) );
270 UniKonfCfg::~UniKonfCfg()
275 void UniKonfCfg::slotHelp()
277 int activePage = activePageIndex();
279 if ( activePage == connwidget->pageIndex() )
280 kapp->invokeHelp( connwidget->helpAnchor() );
283 void UniKonfCfg::slotApply()
285 apply(false);
288 void UniKonfCfg::slotOk()
290 apply(true);
291 accept();
294 void UniKonfCfg::apply(bool AboutToClose)
296 int activePage = activePageIndex();
298 if ( AboutToClose || activePage == connwidget->pageIndex() )
299 connwidget->apply();