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
***************************************************************************/
21
#include <qlineedit.h>
25
#include <qcombobox.h>
27
#include <kiconloader.h>
28
#include <klistview.h>
30
#include <kpushbutton.h>
31
#include <kdialogbase.h>
32
#include <kmessagebox.h>
35
#include "settingssearchurl.h"
39
SettingsSearchURL::SettingsSearchURL( QWidget *parent, const char *name )
40
: QWidget( parent, name ), m_counter( 1 )
46
SettingsSearchURL::~SettingsSearchURL()
51
void SettingsSearchURL::applyData()
53
Settings * settings = Settings::self();
54
settings->searchURLs.clear();
55
for ( QListViewItemIterator it( m_listviewSearchURLs ); it.current(); it++ )
57
Settings::SearchURL *searchURL = new Settings::SearchURL;
58
searchURL->description = it.current() ->text( 0 );
59
searchURL->includeAuthor = it.current() ->text( 1 ) == i18n( "Yes" );
60
searchURL->url = it.current() ->text( 2 );
61
settings->searchURLs.append( searchURL );
65
void SettingsSearchURL::readData()
67
Settings * settings = Settings::self();
69
m_listviewSearchURLs->clear();
70
for ( QValueList<Settings::SearchURL*>::ConstIterator it = settings->searchURLs.begin(); it != settings->searchURLs.end(); ++it )
72
KListViewItem *item = new KListViewItem( m_listviewSearchURLs, ( *it ) ->description, ( *it ) ->includeAuthor ? i18n( "Yes" ) : i18n( "No" ), ( *it ) ->url );
73
item->setPixmap( 0, SmallIcon( "html" ) );
77
void SettingsSearchURL::slotNew()
84
void SettingsSearchURL::slotDelete()
86
QListViewItem * item = m_listviewSearchURLs->selectedItem();
89
m_listviewSearchURLs->removeItem( item );
95
void SettingsSearchURL::slotEdit()
97
QListViewItem * item = m_listviewSearchURLs->selectedItem();
101
emit configChanged();
106
void SettingsSearchURL::slotReset()
108
if ( KMessageBox:: warningContinueCancel( this, i18n( "The list of URLs will be checked and known entries will be replaced by the program standards. Search entries you have defined by yourself will be kept most likely." ), i18n( "Reset list of URLs" ), KGuiItem( i18n( "Reset" ), "reload" ) ) == KMessageBox::Continue )
110
Settings::self() ->restoreDefaultSearchURLs();
112
emit configChanged();
117
void SettingsSearchURL::updateGUI()
119
bool enable = m_listviewSearchURLs->selectedItem() != NULL;
120
m_pushbuttonEdit->setEnabled( enable );
121
m_pushbuttonDelete->setEnabled( enable );
124
void SettingsSearchURL::setupGUI()
126
QGridLayout * layout = new QGridLayout( this, 5, 2, 0, KDialog::spacingHint() );
127
layout->setRowStretch( 3, 1 );
128
layout->setColStretch( 0, 1 );
130
m_listviewSearchURLs = new KListView( this );
131
layout->addMultiCellWidget( m_listviewSearchURLs, 0, 4, 0, 0 );
132
m_listviewSearchURLs->setAllColumnsShowFocus( TRUE );
133
m_listviewSearchURLs->addColumn( i18n( "Description" ) );
134
m_listviewSearchURLs->addColumn( i18n( "Author" ) );
135
m_listviewSearchURLs->addColumn( i18n( "URL" ) );
136
m_listviewSearchURLs->header()->setClickEnabled( FALSE );
137
m_listviewSearchURLs->setFullWidth( true );
138
m_listviewSearchURLs->setMinimumWidth( 384 );
140
m_pushbuttonNew = new KPushButton( i18n( "search url", "New" ), this );
141
m_pushbuttonNew->setIconSet( QIconSet( SmallIcon( "add" ) ) );
142
layout->addWidget( m_pushbuttonNew, 0, 1 );
144
m_pushbuttonEdit = new KPushButton( i18n( "search url", "Edit" ), this );
145
m_pushbuttonEdit->setIconSet( QIconSet( SmallIcon( "edit" ) ) );
146
layout->addWidget( m_pushbuttonEdit, 1, 1 );
148
m_pushbuttonDelete = new KPushButton( i18n( "search url", "Delete" ), this );
149
m_pushbuttonDelete->setIconSet( QIconSet( SmallIcon( "editdelete" ) ) );
150
layout->addWidget( m_pushbuttonDelete, 2, 1 );
152
m_pushbuttonReset = new KPushButton( i18n( "search url", "Reset" ), this );
153
m_pushbuttonReset->setIconSet( QIconSet( SmallIcon( "reload" ) ) );
154
layout->addWidget( m_pushbuttonReset, 4, 1 );
156
connect( m_pushbuttonNew, SIGNAL( clicked() ), this, SLOT( slotNew() ) );
157
connect( m_pushbuttonEdit, SIGNAL( clicked() ), this, SLOT( slotEdit() ) );
158
connect( m_listviewSearchURLs, SIGNAL( doubleClicked( QListViewItem *, const QPoint &, int ) ), this, SLOT( slotEdit() ) );
159
connect( m_pushbuttonDelete, SIGNAL( clicked() ), this, SLOT( slotDelete() ) );
160
connect( m_pushbuttonReset, SIGNAL( clicked() ), this, SLOT( slotReset() ) );
161
connect( m_listviewSearchURLs, SIGNAL( selectionChanged( QListViewItem * ) ), this, SLOT( updateGUI() ) );
162
connect( m_listviewSearchURLs, SIGNAL( currentChanged( QListViewItem * ) ), this, SLOT( updateGUI() ) );
163
connect( m_listviewSearchURLs, SIGNAL( onItem( QListViewItem * ) ), this, SLOT( updateGUI() ) );
168
void SettingsSearchURL::urlDialog( QListViewItem * item )
170
KDialogBase * dlg = new KDialogBase( this, "urldialog", TRUE, item == NULL ? i18n( "New URL" ) : i18n( "Edit URL" ), KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, TRUE );
171
QWidget *container = new QWidget( dlg, "container" );
172
QGridLayout *layout = new QGridLayout( container, 3, 2, 0, KDialog::spacingHint() );
173
QLabel *label = new QLabel( i18n( "Description:" ), container );
174
layout->addWidget( label, 0, 0 );
175
QLineEdit *descr = new QLineEdit( container );
176
label->setBuddy( descr );
177
layout->addWidget( descr, 0, 1 );
178
label = new QLabel( i18n( "URL:" ), container );
179
layout->addWidget( label, 1, 0 );
180
QLineEdit *url = new QLineEdit( container );
181
layout->addWidget( url, 1, 1 );
182
label->setBuddy( url );
183
url->setMinimumWidth( 384 );
184
QToolTip::add( url, i18n( "Within the URL, '%1' will be replaced by the search term." ) );
185
label = new QLabel( i18n( "Include Author:" ), container );
186
layout->addWidget( label, 2, 0 );
187
QComboBox *cbIncludeAuthor = new QComboBox( FALSE, container );
188
layout->addWidget( cbIncludeAuthor, 2, 1 );
189
label->setBuddy( cbIncludeAuthor );
190
cbIncludeAuthor->insertItem( i18n( "Yes" ) );
191
cbIncludeAuthor->insertItem( i18n( "No" ) );
193
dlg->setMainWidget( container );
197
descr->setText( item->text( 0 ) );
198
url->setText( item->text( 2 ) );
199
cbIncludeAuthor->setCurrentItem( item->text( 1 ) == i18n( "Yes" ) ? 0 : 1 );
202
if ( dlg->exec() == QDialog::Accepted )
206
KListViewItem *item = new KListViewItem( m_listviewSearchURLs, descr->text(), cbIncludeAuthor->currentItem() == 0 ? i18n( "Yes" ) : i18n( "No" ), url->text() );
207
item->setPixmap( 0, SmallIcon( "html" ) );
211
item->setText( 0, descr->text() );
212
item->setText( 1, cbIncludeAuthor->currentItem() == 0 ? i18n( "Yes" ) : i18n( "No" ) );
213
item->setText( 2, url->text() );
221
#include "settingssearchurl.moc"