2 * Copyright (c) 2004 Szombathelyi György <gyurco@freemail.hu>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library 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 GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
22 #include <QVBoxLayout>
27 #include <kmessagebox.h>
28 #include <kinputdialog.h>
30 #include "ku_global.h"
31 #include "ku_selectconn.h"
32 #include "ku_configdlg.h"
34 KU_SelectConn::KU_SelectConn(const QString
&selected
, QWidget
*parent
) :
38 setButtons(Ok
| Apply
| Cancel
| User1
| User2
| User3
);
39 setCaption(i18n("Connection Selection"));
40 setButtonText( User3
, i18n("&New...") );
41 setButtonText( User2
, i18n("&Edit") );
42 setButtonText( User1
, i18n("&Delete") );
44 QFrame
*page
= new QFrame();
45 setMainWidget( page
);
46 QVBoxLayout
*topLayout
= new QVBoxLayout( page
);
47 topLayout
->setSpacing( KDialog::spacingHint() );
48 QLabel
*label
= new QLabel( i18n("Defined connections:"), page
);
49 mCombo
= new KComboBox( page
);
51 kDebug() << "selected item: " << mSelected
;
53 conns
= KGlobal::config()->groupList();
54 QStringList::iterator it
= conns
.begin();
56 while ( it
!= conns
.end() ) {
57 if ( (*it
).startsWith( "connection-" ) ) {
58 (*it
).remove( QRegExp("^connection-") );
59 if ( (*it
) == mSelected
) sel
= i
;
63 it
= conns
.erase( it
);
65 mCombo
->insertItems( 0, conns
);
66 if ( mCombo
->count() == 0 ) mCombo
->addItem( "default" );
67 mCombo
->setCurrentIndex( sel
);
68 mSelected
= connSelected();
69 topLayout
->addWidget( label
);
70 topLayout
->addWidget( mCombo
);
72 connect( this, SIGNAL(user1Clicked()), SLOT(slotUser1()) );
73 connect( this, SIGNAL(user2Clicked()), SLOT(slotUser2()) );
74 connect( this, SIGNAL(user3Clicked()), SLOT(slotUser3()) );
75 connect( this, SIGNAL(applyClicked()), SLOT(slotApply()));
78 QString
KU_SelectConn::connSelected()
80 return mCombo
->currentText();
83 void KU_SelectConn::slotUser3()
85 newconn
= KInputDialog::getText( QString::null
, //krazy:exclude=nullstrassign for old broken gcc
86 i18n("Please type the name of the new connection:") );
87 if ( newconn
.isEmpty() ) return;
88 if ( KGlobal::config()->groupList().contains( "connection-" + newconn
) ) {
89 KMessageBox::sorry( 0, i18n("A connection with this name already exists.") );
93 KSharedConfig::Ptr
config( KGlobal::config() );
94 KU_PrefsBase
kcfg( config
, newconn
);
96 KU_ConfigDlg
cfgdlg( &kcfg
, this );
97 connect(&cfgdlg
, SIGNAL(settingsChanged(const QString
&)), this, SLOT(slotNewApplySettings()));
100 if ( newconn
.isEmpty() )
101 emit( applyClicked() );
104 void KU_SelectConn::slotNewApplySettings()
106 if ( !newconn
.isEmpty() ) {
107 mCombo
->addItem( newconn
);
108 mCombo
->setCurrentIndex( mCombo
->count()-1 );
113 void KU_SelectConn::slotUser2()
115 kDebug() << "slotUser2: " << connSelected();
117 KSharedConfig::Ptr
config( KGlobal::config() );
118 KU_PrefsBase
kcfg( config
, connSelected() );
121 KU_ConfigDlg
cfgdlg( &kcfg
, this );
122 connect( &cfgdlg
, SIGNAL(settingsChanged(const QString
&)), this, SLOT(slotApplySettings()) );
126 void KU_SelectConn::slotUser1()
128 QString conn
= connSelected();
129 if ( KMessageBox::warningContinueCancel( 0, i18n("Do you really want to delete the connection '%1'?",
130 conn
),i18n("Delete Connection"),KStandardGuiItem::del() ) == KMessageBox::Cancel
) return;
132 KGlobal::config()->deleteGroup( "connection-" + conn
);
133 KGlobal::config()->sync();
134 mCombo
->removeItem( mCombo
->currentIndex() );
135 if ( mCombo
->count() == 0 ) {
136 mCombo
->addItem( "default" );
137 mCombo
->setCurrentIndex( 0 );
139 kDebug() << "slotUser1: " << conn
<< " " << mSelected
;
140 if ( mSelected
== conn
)
141 emit( applyClicked() );
144 void KU_SelectConn::slotApply()
146 kDebug() << "slotApply()";
147 if ( connSelected() != mSelected
) {
148 mSelected
= connSelected();
149 emit( applyClicked() );
153 void KU_SelectConn::slotApplySettings()
155 kDebug() << "slotApplySettings()";
156 if ( connSelected() == mSelected
)
157 emit( applyClicked() );
160 #include "ku_selectconn.moc"