1
/***************************************************************************
2
* Copyright (C) 2004-2009 by Thomas Fischer *
3
* fischer@unix-ag.uni-kl.de *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
***************************************************************************/
33
#include <klistview.h>
34
#include <kpushbutton.h>
35
#include <kiconloader.h>
36
#include <kdialogbase.h>
37
#include <kmessagebox.h>
39
#include <kcombobox.h>
40
#include <klineedit.h>
42
#include "settingsz3950.h"
47
ServerListViewItem::ServerListViewItem( KListView *list, const QString &_id, Settings::Z3950Server& _server, bool _newItem )
48
: KListViewItem( list, _server.name, _server.database ), server( _server ), id( _id ), newItem( _newItem )
53
ServerListViewItem::ServerListViewItem( KListViewItem *item, const QString &_id, Settings::Z3950Server& _server, bool _newItem )
54
: KListViewItem( item, _server.name, _server.database ), server( _server ), id( _id ), newItem( _newItem )
59
void ServerListViewItem::refresh( )
61
setText( 0, server.name );
62
setText( 1, server.database );
65
SettingsZ3950Edit::SettingsZ3950Edit( QString &id, Settings::Z3950Server& _server, QWidget *parent, const char *name )
66
: QWidget( parent, name ), m_id( id ), m_server( _server ), m_lineEditId( NULL )
68
QGridLayout *layout = new QGridLayout( this, 10, 2 , 0, KDialog::spacingHint() );
71
label = new QLabel( i18n( "Name:" ), this );
72
layout->addWidget( label, 1, 0 );
73
m_lineEditName = new KLineEdit( m_server.name, this );
74
layout->addWidget( m_lineEditName, 1, 1 );
75
label->setBuddy( m_lineEditName );
77
label = new QLabel( i18n( "Database:" ), this );
78
layout->addWidget( label, 2, 0 );
79
m_lineEditDatabase = new KLineEdit( m_server.database, this );
80
layout->addWidget( m_lineEditDatabase, 2, 1 );
81
label->setBuddy( m_lineEditDatabase );
83
label = new QLabel( i18n( "Host:" ), this );
84
layout->addWidget( label, 3, 0 );
85
m_lineEditHost = new KLineEdit( m_server.host, this );
86
layout->addWidget( m_lineEditHost, 3, 1 );
87
label->setBuddy( m_lineEditHost );
89
label = new QLabel( i18n( "Port:" ), this );
90
layout->addWidget( label, 4, 0 );
91
m_spinBoxPort = new QSpinBox( this );
92
m_spinBoxPort->setMinValue( 1 );
93
m_spinBoxPort->setMaxValue( 65535 );
94
m_spinBoxPort->setValue( m_server.port );
95
layout->addWidget( m_spinBoxPort, 4, 1 );
96
label->setBuddy( m_spinBoxPort );
98
label = new QLabel( i18n( "User:" ), this );
99
layout->addWidget( label, 5, 0 );
100
m_lineEditUser = new KLineEdit( m_server.user, this );
101
layout->addWidget( m_lineEditUser, 5, 1 );
102
label->setBuddy( m_lineEditUser );
104
label = new QLabel( i18n( "Password:" ), this );
105
layout->addWidget( label, 6, 0 );
106
m_lineEditPassword = new KLineEdit( m_server.password, this );
107
layout->addWidget( m_lineEditPassword, 6, 1 );
108
label->setBuddy( m_lineEditPassword );
110
label = new QLabel( i18n( "Syntax:" ), this );
111
layout->addWidget( label, 7, 0 );
112
m_comboBoxSyntax = new KComboBox( true, this );
113
layout->addWidget( m_comboBoxSyntax, 7, 1 );
114
label->setBuddy( m_comboBoxSyntax );
115
m_comboBoxSyntax->insertItem( "grs-1" );
116
m_comboBoxSyntax->insertItem( "marc21" );
117
m_comboBoxSyntax->insertItem( "mods" );
118
m_comboBoxSyntax->insertItem( "unimarc" );
119
m_comboBoxSyntax->insertItem( "usmarc" );
120
m_comboBoxSyntax->setCurrentText( m_server.syntax );
122
label = new QLabel( i18n( "Locale:" ), this );
123
layout->addWidget( label, 8, 0 );
124
m_comboBoxLocale = new KComboBox( true, this );
125
m_comboBoxLocale->setCurrentText( m_server.locale );
126
layout->addWidget( m_comboBoxLocale, 8, 1 );
127
label->setBuddy( m_comboBoxLocale );
129
label = new QLabel( i18n( "Charset:" ), this );
130
layout->addWidget( label, 9, 0 );
131
m_comboBoxCharset = new KComboBox( true, this );
132
layout->addWidget( m_comboBoxCharset, 9, 1 );
133
label->setBuddy( m_comboBoxCharset );
134
m_comboBoxCharset->insertItem( "iso-5426" );
135
m_comboBoxCharset->insertItem( "iso-8859-1" );
136
m_comboBoxCharset->insertItem( "marc8" );
137
m_comboBoxCharset->insertItem( "marc-8" );
138
m_comboBoxCharset->insertItem( "utf-8" );
139
m_comboBoxCharset->setCurrentText( m_server.charset );
142
SettingsZ3950Edit::~SettingsZ3950Edit()
147
int SettingsZ3950Edit::execute( QWidget *parent, QString &id, Settings::Z3950Server &server )
149
KDialogBase *dlg = new KDialogBase( parent, "SettingsZ3950Edit", true, i18n( "Edit Z39.50 Server" ), KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, false );
150
SettingsZ3950Edit *edit = new SettingsZ3950Edit( id, server, dlg, "SettingsZ3950Edit" );
151
dlg->setMainWidget( edit );
152
connect( dlg, SIGNAL( apply() ), edit, SLOT( slotApply() ) );
153
connect( dlg, SIGNAL( okClicked() ), edit, SLOT( slotApply() ) );
158
void SettingsZ3950Edit::slotApply()
160
m_server.charset = m_comboBoxCharset->currentText();
161
m_server.database = m_lineEditDatabase->text();
162
m_server.host = m_lineEditHost->text();
163
m_server.locale = m_comboBoxLocale->currentText();
164
m_server.name = m_lineEditName->text();
165
m_server.syntax = m_comboBoxSyntax->currentText();
166
m_server.user = m_lineEditUser->text();
167
m_server.password = m_lineEditPassword->text();
168
m_server.port = m_spinBoxPort->value();
170
if ( m_id.isEmpty() )
172
m_id = QString( m_server.name ).lower().replace( QRegExp( "[^a-z0-9]" ), "" );
173
qDebug( "Setting id to %s", m_id.latin1() );
177
SettingsZ3950::SettingsZ3950( QWidget *parent, const char *name )
178
: QWidget( parent, name )
183
SettingsZ3950::~SettingsZ3950()
188
void SettingsZ3950::applyData()
190
Settings *settings = Settings::self();
191
settings->z3950_ServerList.clear();
193
for ( QListViewItemIterator it( m_listServers ); it.current(); ++it )
195
ServerListViewItem *item = dynamic_cast<ServerListViewItem*>( *it );
196
settings->z3950_ServerList[item->id] = item->server;
200
void SettingsZ3950::readData()
202
Settings *settings = Settings::self();
203
m_listServers->clear();
205
for ( QMap<QString, Settings::Z3950Server>::Iterator it = settings->z3950_ServerList.begin(); it != settings-> z3950_ServerList.end(); ++it )
207
ServerListViewItem *item = new ServerListViewItem( m_listServers, it.key(), it.data(), false );
208
item->setPixmap( 0, SmallIcon( "server" ) );
214
void SettingsZ3950::slotNewServer()
216
Settings::Z3950Server server;
218
ServerListViewItem * item = new ServerListViewItem( m_listServers, "", server, true );
219
item->setPixmap( 0, SmallIcon( "server" ) );
220
m_listServers->setSelected( item, TRUE );
221
QTimer::singleShot( 100, this, SLOT( slotEditServer() ) );
224
void SettingsZ3950::slotEditServer()
226
ServerListViewItem * item = static_cast<ServerListViewItem*>( m_listServers->selectedItem() );
229
if ( SettingsZ3950Edit::execute( this, item->id, item->server ) == QDialog::Accepted )
232
emit configChanged();
234
else if ( item->newItem )
242
void SettingsZ3950::slotDeleteServer()
244
delete m_listServers->selectedItem();
245
emit configChanged();
249
void SettingsZ3950::slotMoveUpServer()
251
ServerListViewItem * item = dynamic_cast<ServerListViewItem*>( m_listServers->selectedItem() );
252
ServerListViewItem *itemAbove = NULL;
253
if ( item != NULL && ( itemAbove = dynamic_cast<ServerListViewItem*>( item->itemAbove() ) ) != NULL )
255
Settings::Z3950Server server = item->server;
256
item->server = itemAbove->server;
257
itemAbove->server = server;
258
QString id = item->id;
259
item->id = itemAbove->id;
261
for ( int i = 0; i < 2; ++i )
263
QString swap = item->text( i );
264
item->setText( i, itemAbove->text( i ) );
265
itemAbove->setText( i, swap );
267
m_listServers->setCurrentItem( itemAbove );
268
m_listServers->ensureItemVisible( itemAbove );
272
void SettingsZ3950::slotMoveDownServer()
274
ServerListViewItem * item = dynamic_cast<ServerListViewItem*>( m_listServers->selectedItem() );
275
ServerListViewItem *itemBelow = NULL;
276
if ( item != NULL && ( itemBelow = dynamic_cast<ServerListViewItem*>( item->itemBelow() ) ) != NULL )
278
Settings::Z3950Server server = item->server;
279
item->server = itemBelow->server;
280
itemBelow->server = server;
281
QString id = item->id;
282
item->id = itemBelow->id;
284
for ( int i = 0; i < 2; ++i )
286
QString swap = item->text( i );
287
item->setText( i, itemBelow->text( i ) );
288
itemBelow->setText( i, swap );
290
m_listServers->setCurrentItem( itemBelow );
291
m_listServers->ensureItemVisible( itemBelow );
295
void SettingsZ3950::slotResetToDefault()
297
if ( KMessageBox::warningContinueCancel( this, i18n( "All Z39.50 server configurations will be reset to defaults." ), i18n( "Reset to Default" ), KGuiItem( i18n( "Reset" ), "reload" ) ) == KMessageBox::Continue )
299
Settings *settings = Settings::self();
300
settings->z3950clearAll();
301
settings->z3950loadDefault();
306
void SettingsZ3950::updateGUI()
308
QListViewItem *item = m_listServers->selectedItem();
309
bool selected = item != NULL;
310
m_buttonEditServer->setEnabled( selected );
311
m_buttonDeleteServer->setEnabled( selected );
312
m_buttonMoveDownServer->setEnabled( selected && item->itemBelow() != NULL );
313
m_buttonMoveUpServer->setEnabled( selected && item->itemAbove() != NULL );
316
void SettingsZ3950::setupGUI()
318
QGridLayout * gridLayout = new QGridLayout( this, 7, 2, 0, KDialog::spacingHint(), "gridLayout" );
319
gridLayout->setRowStretch( 5, 1 );
320
gridLayout->setColStretch( 0, 1 );
322
m_listServers = new KListView( this );
323
m_listServers->setSorting( -1, FALSE );
324
m_listServers->addColumn( i18n( "z3950 server", "Name" ) );
325
m_listServers->addColumn( i18n( "z3950 server", "Database" ) );
326
m_listServers->header()->setClickEnabled( FALSE );
327
m_listServers->setFullWidth( true );
328
m_listServers->setAllColumnsShowFocus( true );
329
gridLayout->addMultiCellWidget( m_listServers, 0, 7, 0, 0 );
330
connect( m_listServers, SIGNAL( selectionChanged() ), this, SLOT( updateGUI() ) );
331
connect( m_listServers, SIGNAL( currentChanged( QListViewItem * ) ), this, SLOT( updateGUI() ) );
332
connect( m_listServers, SIGNAL( doubleClicked( QListViewItem*, const QPoint &, int ) ), this, SLOT( slotEditServer() ) );
334
m_buttonNewServer = new KPushButton( i18n( "z3950 server", "New" ), this );
335
m_buttonNewServer->setIconSet( QIconSet( SmallIcon( "add" ) ) );
336
gridLayout->addWidget( m_buttonNewServer, 0, 1 );
337
connect( m_buttonNewServer, SIGNAL( clicked() ), this, SLOT( slotNewServer() ) );
338
m_buttonEditServer = new KPushButton( i18n( "z3950 server", "Edit" ), this );
339
m_buttonEditServer->setIconSet( QIconSet( SmallIcon( "edit" ) ) );
340
gridLayout->addWidget( m_buttonEditServer, 1, 1 );
341
connect( m_buttonEditServer, SIGNAL( clicked() ), this, SLOT( slotEditServer() ) );
342
m_buttonDeleteServer = new KPushButton( i18n( "z3950 server", "Delete" ), this );
343
m_buttonDeleteServer->setIconSet( QIconSet( SmallIcon( "editdelete" ) ) );
344
gridLayout->addWidget( m_buttonDeleteServer, 2, 1 );
345
connect( m_buttonDeleteServer, SIGNAL( clicked() ), this, SLOT( slotDeleteServer() ) );
346
m_buttonMoveUpServer = new KPushButton( i18n( "z3950 server", "Up" ), this );
347
m_buttonMoveUpServer->setIconSet( QIconSet( SmallIcon( "up" ) ) );
348
gridLayout->addWidget( m_buttonMoveUpServer, 3, 1 );
349
connect( m_buttonMoveUpServer, SIGNAL( clicked() ), this, SLOT( slotMoveUpServer() ) );
350
m_buttonMoveDownServer = new KPushButton( i18n( "z3950 server", "Down" ), this );
351
m_buttonMoveDownServer->setIconSet( QIconSet( SmallIcon( "down" ) ) );
352
gridLayout->addWidget( m_buttonMoveDownServer, 4, 1 );
353
connect( m_buttonMoveDownServer, SIGNAL( clicked() ), this, SLOT( slotMoveDownServer() ) );
355
m_buttonResetToDefault = new KPushButton( i18n( "z3950 server", "Reset" ), this );
356
m_buttonResetToDefault->setIconSet( QIconSet( SmallIcon( "reload" ) ) );
357
gridLayout->addWidget( m_buttonResetToDefault, 6, 1 );
358
connect( m_buttonResetToDefault, SIGNAL( clicked() ), this, SLOT( slotResetToDefault() ) );
362
#include "settingsz3950.moc"