~ubuntu-branches/ubuntu/raring/kbibtex/raring

« back to all changes in this revision

Viewing changes to src/settingssearchurl.cpp

  • Committer: Package Import Robot
  • Author(s): Michael Hanke
  • Date: 2011-07-18 09:29:48 UTC
  • mfrom: (1.1.6) (2.1.5 sid)
  • Revision ID: package-import@ubuntu.com-20110718092948-ksxjmg7kdfamolmg
Tags: 0.3-1
* First upstream release for KDE4 (Closes: #634255). A number of search
  engines are still missing, in comparison to the 0.2 series.
* Bumped Standards-Version to 3.9.2, no changes necessary.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
*   Copyright (C) 2004-2009 by Thomas Fischer                             *
3
 
*   fischer@unix-ag.uni-kl.de                                             *
4
 
*                                                                         *
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.                                   *
9
 
*                                                                         *
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.                          *
14
 
*                                                                         *
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
 
***************************************************************************/
20
 
#include <qlayout.h>
21
 
#include <qlineedit.h>
22
 
#include <qlabel.h>
23
 
#include <qtooltip.h>
24
 
#include <qheader.h>
25
 
#include <qcombobox.h>
26
 
 
27
 
#include <kiconloader.h>
28
 
#include <klistview.h>
29
 
#include <klocale.h>
30
 
#include <kpushbutton.h>
31
 
#include <kdialogbase.h>
32
 
#include <kmessagebox.h>
33
 
 
34
 
#include <settings.h>
35
 
#include "settingssearchurl.h"
36
 
 
37
 
namespace KBibTeX
38
 
{
39
 
    SettingsSearchURL::SettingsSearchURL( QWidget *parent, const char *name )
40
 
            : QWidget( parent, name ), m_counter( 1 )
41
 
    {
42
 
        setupGUI();
43
 
    }
44
 
 
45
 
 
46
 
    SettingsSearchURL::~SettingsSearchURL()
47
 
    {
48
 
        // nothing
49
 
    }
50
 
 
51
 
    void SettingsSearchURL::applyData()
52
 
    {
53
 
        Settings * settings = Settings::self();
54
 
        settings->searchURLs.clear();
55
 
        for ( QListViewItemIterator it( m_listviewSearchURLs ); it.current(); it++ )
56
 
        {
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 );
62
 
        }
63
 
    }
64
 
 
65
 
    void SettingsSearchURL::readData()
66
 
    {
67
 
        Settings * settings = Settings::self();
68
 
 
69
 
        m_listviewSearchURLs->clear();
70
 
        for ( QValueList<Settings::SearchURL*>::ConstIterator it = settings->searchURLs.begin(); it != settings->searchURLs.end(); ++it )
71
 
        {
72
 
            KListViewItem *item = new KListViewItem( m_listviewSearchURLs, ( *it ) ->description, ( *it ) ->includeAuthor ? i18n( "Yes" ) : i18n( "No" ), ( *it ) ->url );
73
 
            item->setPixmap( 0, SmallIcon( "html" ) );
74
 
        }
75
 
    }
76
 
 
77
 
    void SettingsSearchURL::slotNew()
78
 
    {
79
 
        urlDialog();
80
 
        emit configChanged();
81
 
        updateGUI();
82
 
    }
83
 
 
84
 
    void SettingsSearchURL::slotDelete()
85
 
    {
86
 
        QListViewItem * item = m_listviewSearchURLs->selectedItem();
87
 
        if ( item != NULL )
88
 
        {
89
 
            m_listviewSearchURLs->removeItem( item );
90
 
            emit configChanged();
91
 
        }
92
 
        updateGUI();
93
 
    }
94
 
 
95
 
    void SettingsSearchURL::slotEdit()
96
 
    {
97
 
        QListViewItem * item = m_listviewSearchURLs->selectedItem();
98
 
        if ( item != NULL )
99
 
        {
100
 
            urlDialog( item );
101
 
            emit configChanged();
102
 
        }
103
 
        updateGUI();
104
 
    }
105
 
 
106
 
    void SettingsSearchURL::slotReset()
107
 
    {
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 )
109
 
        {
110
 
            Settings::self() ->restoreDefaultSearchURLs();
111
 
            readData();
112
 
            emit configChanged();
113
 
        }
114
 
        updateGUI();
115
 
    }
116
 
 
117
 
    void SettingsSearchURL::updateGUI()
118
 
    {
119
 
        bool enable = m_listviewSearchURLs->selectedItem() != NULL;
120
 
        m_pushbuttonEdit->setEnabled( enable );
121
 
        m_pushbuttonDelete->setEnabled( enable );
122
 
    }
123
 
 
124
 
    void SettingsSearchURL::setupGUI()
125
 
    {
126
 
        QGridLayout * layout = new QGridLayout( this, 5, 2, 0, KDialog::spacingHint() );
127
 
        layout->setRowStretch( 3, 1 );
128
 
        layout->setColStretch( 0, 1 );
129
 
 
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 );
139
 
 
140
 
        m_pushbuttonNew = new KPushButton( i18n( "search url", "New" ), this );
141
 
        m_pushbuttonNew->setIconSet( QIconSet( SmallIcon( "add" ) ) );
142
 
        layout->addWidget( m_pushbuttonNew, 0, 1 );
143
 
 
144
 
        m_pushbuttonEdit = new KPushButton( i18n( "search url", "Edit" ), this );
145
 
        m_pushbuttonEdit->setIconSet( QIconSet( SmallIcon( "edit" ) ) );
146
 
        layout->addWidget( m_pushbuttonEdit, 1, 1 );
147
 
 
148
 
        m_pushbuttonDelete = new KPushButton( i18n( "search url", "Delete" ), this );
149
 
        m_pushbuttonDelete->setIconSet( QIconSet( SmallIcon( "editdelete" ) ) );
150
 
        layout->addWidget( m_pushbuttonDelete, 2, 1 );
151
 
 
152
 
        m_pushbuttonReset = new KPushButton( i18n( "search url", "Reset" ), this );
153
 
        m_pushbuttonReset->setIconSet( QIconSet( SmallIcon( "reload" ) ) );
154
 
        layout->addWidget( m_pushbuttonReset, 4, 1 );
155
 
 
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() ) );
164
 
 
165
 
        updateGUI();
166
 
    }
167
 
 
168
 
    void SettingsSearchURL::urlDialog( QListViewItem * item )
169
 
    {
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" ) );
192
 
 
193
 
        dlg->setMainWidget( container );
194
 
 
195
 
        if ( item != NULL )
196
 
        {
197
 
            descr->setText( item->text( 0 ) );
198
 
            url->setText( item->text( 2 ) );
199
 
            cbIncludeAuthor->setCurrentItem( item->text( 1 ) == i18n( "Yes" ) ? 0 : 1 );
200
 
        }
201
 
 
202
 
        if ( dlg->exec() == QDialog::Accepted )
203
 
        {
204
 
            if ( item == NULL )
205
 
            {
206
 
                KListViewItem *item = new KListViewItem( m_listviewSearchURLs, descr->text(), cbIncludeAuthor->currentItem() == 0 ? i18n( "Yes" ) : i18n( "No" ), url->text() );
207
 
                item->setPixmap( 0, SmallIcon( "html" ) );
208
 
            }
209
 
            else
210
 
            {
211
 
                item->setText( 0, descr->text() );
212
 
                item->setText( 1, cbIncludeAuthor->currentItem() == 0 ? i18n( "Yes" ) : i18n( "No" ) );
213
 
                item->setText( 2, url->text() );
214
 
            }
215
 
        }
216
 
 
217
 
        delete dlg;
218
 
    }
219
 
}
220
 
 
221
 
#include "settingssearchurl.moc"