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

« back to all changes in this revision

Viewing changes to src/settingsediting.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 <qlabel.h>
22
 
#include <qdir.h>
23
 
#include <qheader.h>
24
 
#include <qcombobox.h>
25
 
#include <qslider.h>
26
 
#include <qtooltip.h>
27
 
#include <qwhatsthis.h>
28
 
#include <qgroupbox.h>
29
 
#include <qpushbutton.h>
30
 
#include <qcheckbox.h>
31
 
 
32
 
#include <kpushbutton.h>
33
 
#include <kdirselectdialog.h>
34
 
#include <kiconloader.h>
35
 
#include <klocale.h>
36
 
#include <kurlrequester.h>
37
 
#include <kmessagebox.h>
38
 
#include <klineedit.h>
39
 
#include <kdialog.h>
40
 
#include <kfontdialog.h>
41
 
#include <kurlcompletion.h>
42
 
 
43
 
#include <documentlistview.h>
44
 
#include "settingsediting.h"
45
 
 
46
 
namespace KBibTeX
47
 
{
48
 
    const QChar SettingsEditing::pathListSeparator = QChar( ';' );
49
 
 
50
 
    SettingsEditingPaths::SettingsEditingPaths( QStringList& pathList, QWidget*parent, const char *name )
51
 
            : QWidget( parent, name ), m_pathList( pathList )
52
 
    {
53
 
        QGridLayout *layout = new QGridLayout( this, 5, 3, 0, KDialog::spacingHint() );
54
 
        setMinimumWidth( 480 );
55
 
 
56
 
        QLabel *label = new QLabel( i18n( "Path to add:" ), this );
57
 
        layout->addWidget( label, 0, 0 );
58
 
        m_urlRequesterNewPath = new KURLRequester( this );
59
 
        m_urlRequesterNewPath->setMode( KFile::Directory | KFile::ExistingOnly | KFile::LocalOnly );
60
 
        m_urlRequesterNewPath->completionObject()->setDir( QDir::currentDirPath() );
61
 
        label->setBuddy( m_urlRequesterNewPath );
62
 
        layout->addWidget( m_urlRequesterNewPath, 1, 0 );
63
 
        QToolTip::add( m_urlRequesterNewPath->button(), i18n( "Select a path to add" ) );
64
 
        m_pushButtonAddDir = new KPushButton( i18n( "Add" ), this );
65
 
        m_pushButtonAddDir->setIconSet( QIconSet( SmallIcon( "add" ) ) );
66
 
        m_pushButtonAddDir->setEnabled( FALSE );
67
 
        QToolTip::add( m_pushButtonAddDir, i18n( "Add chosen path to list" ) );
68
 
        layout->addWidget( m_pushButtonAddDir, 1, 2 );
69
 
 
70
 
        label = new QLabel( i18n( "List of paths:" ), this );
71
 
        layout->addWidget( label, 2, 0 );
72
 
        m_listViewPathList = new KListView( this );
73
 
        m_listViewPathList->addColumn( i18n( "Path" ) );
74
 
        m_listViewPathList->header()->setClickEnabled( false );
75
 
        m_listViewPathList->setFullWidth( true );
76
 
        label->setBuddy( m_listViewPathList );
77
 
        layout->addMultiCellWidget( m_listViewPathList, 3, 4, 0, 1 );
78
 
        m_pushButtonDelDir = new KPushButton( i18n( "Delete" ), this );
79
 
        layout->addWidget( m_pushButtonDelDir, 3, 2 );
80
 
        m_pushButtonDelDir->setEnabled( FALSE );
81
 
        m_pushButtonDelDir->setIconSet( QIconSet( SmallIcon( "editdelete" ) ) );
82
 
        QToolTip::add( m_pushButtonDelDir, i18n( "Remove selected path from list" ) );
83
 
 
84
 
        layout->setRowStretch( 4, 1 );
85
 
        layout->setColStretch( 0, 1 );
86
 
 
87
 
        connect( m_urlRequesterNewPath, SIGNAL( textChanged( const QString& ) ), this, SLOT( slotTextChanged( const QString& ) ) );
88
 
        connect( m_urlRequesterNewPath, SIGNAL( urlSelected( const QString& ) ), this, SLOT( slotTextChanged( const QString& ) ) );
89
 
        connect( m_pushButtonAddDir, SIGNAL( clicked() ), this, SLOT( slotAddDir() ) );
90
 
        connect( m_listViewPathList, SIGNAL( selectionChanged() ), this, SLOT( slotSelectionChanged() ) );
91
 
        connect( m_pushButtonDelDir, SIGNAL( clicked() ), this, SLOT( slotDelDir() ) );
92
 
 
93
 
        for ( QStringList::Iterator it = pathList.begin(); it != pathList.end(); ++it )
94
 
            new QListViewItem( m_listViewPathList, *it );
95
 
    }
96
 
 
97
 
    bool SettingsEditingPaths::execute( QWidget *parent, QStringList &pathList )
98
 
    {
99
 
        KDialogBase *dlg = new KDialogBase( parent, "SettingsEditingPathsDialog", true, i18n( "Edit Document Search Paths" ), KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, false );
100
 
        SettingsEditingPaths *sep = new SettingsEditingPaths( pathList, dlg, "SettingsEditingPaths" );
101
 
        dlg->setMainWidget( sep );
102
 
        connect( dlg, SIGNAL( apply() ), sep, SLOT( slotApply() ) );
103
 
        connect( dlg, SIGNAL( okClicked() ), sep, SLOT( slotApply() ) );
104
 
 
105
 
        bool result = dlg->exec() == QDialog::Accepted;
106
 
        delete dlg;
107
 
 
108
 
        return result;
109
 
    }
110
 
 
111
 
    void SettingsEditingPaths::slotApply()
112
 
    {
113
 
        m_pathList.clear();
114
 
        QListViewItem *item = m_listViewPathList->firstChild();
115
 
        while ( item != NULL )
116
 
        {
117
 
            m_pathList.append( item->text( 0 ) );
118
 
            item = item->nextSibling();
119
 
        }
120
 
    }
121
 
 
122
 
    void SettingsEditingPaths::slotTextChanged( const QString&text )
123
 
    {
124
 
        QDir pathObj( text );
125
 
        m_pushButtonAddDir->setEnabled( pathObj.exists() && pathObj.isReadable() );
126
 
    }
127
 
 
128
 
    void SettingsEditingPaths::slotAddDir()
129
 
    {
130
 
        QString path = m_urlRequesterNewPath->lineEdit()->text();
131
 
        QDir pathObj( path );
132
 
        if ( pathObj.exists() && pathObj.isReadable() )
133
 
        {
134
 
            QListViewItem *item = new KListViewItem( m_listViewPathList, path );
135
 
            m_listViewPathList->ensureItemVisible( item );
136
 
            m_listViewPathList->setSelected( item, TRUE );
137
 
            slotSelectionChanged();
138
 
        }
139
 
        else
140
 
            KMessageBox::error( this, QString( i18n( "Folder '%1' does not exist or is not readable." ) ).arg( path ) );
141
 
    }
142
 
 
143
 
    void SettingsEditingPaths::slotSelectionChanged()
144
 
    {
145
 
        m_pushButtonDelDir->setEnabled( m_listViewPathList->selectedItem() != NULL );
146
 
    }
147
 
 
148
 
    void SettingsEditingPaths::slotDelDir()
149
 
    {
150
 
        m_listViewPathList->takeItem( m_listViewPathList->selectedItem() );
151
 
        slotSelectionChanged();
152
 
    }
153
 
 
154
 
    SettingsEditing::SettingsEditing( QWidget *parent, const char *name )
155
 
            : QWidget( parent, name ), m_findDuplicatesSensitivityMin( 3 ), m_findDuplicatesSensitivityMax( 13 )
156
 
    {
157
 
        QGroupBox * group = NULL;
158
 
        QVBoxLayout *layout = new QVBoxLayout( this, 0, KDialog::spacingHint() );
159
 
 
160
 
        group = new QGroupBox( 2, Qt::Horizontal, i18n( "Main List" ), this );
161
 
        layout->addWidget( group );
162
 
        QLabel *label = new QLabel( i18n( "&Sorting:" ), group );
163
 
        m_comboBoxSortingColumn = new QComboBox( FALSE, group );
164
 
        m_comboBoxSortingColumn->insertItem( i18n( "Element Type" ) );
165
 
        m_comboBoxSortingColumn->insertItem( i18n( "Entry Id" ) );
166
 
        for ( int i = 0; i <= ( int ) BibTeX::EntryField::ftYear - ( int ) BibTeX::EntryField::ftAbstract; i++ )
167
 
        {
168
 
            BibTeX::EntryField::FieldType fieldType = ( BibTeX::EntryField::FieldType )( i + ( int ) BibTeX::EntryField::ftAbstract );
169
 
            QString label = Settings::fieldTypeToI18NString( fieldType );
170
 
            m_comboBoxSortingColumn->insertItem( label );
171
 
        }
172
 
        label->setBuddy( m_comboBoxSortingColumn );
173
 
 
174
 
        label = new QLabel( i18n( "So&rting order:" ), group );
175
 
        m_comboBoxSortingOrder = new QComboBox( FALSE, group );
176
 
        m_comboBoxSortingOrder->insertItem( i18n( "Ascending" ) );
177
 
        m_comboBoxSortingOrder->insertItem( i18n( "Descending" ) );
178
 
        label->setBuddy( m_comboBoxSortingOrder );
179
 
 
180
 
        label = new QLabel( i18n( "&Double click action:" ), group );
181
 
        m_comboBoxDoubleClickAction = new QComboBox( FALSE, group );
182
 
        m_comboBoxDoubleClickAction->insertItem( i18n( "Edit element" ) );
183
 
        m_comboBoxDoubleClickAction->insertItem( i18n( "Open document" ) );
184
 
        label->setBuddy( m_comboBoxDoubleClickAction );
185
 
 
186
 
        label = new QLabel( i18n( "On dragging with mouse:" ), group );
187
 
        m_comboBoxDragAction = new QComboBox( FALSE, group );
188
 
        m_comboBoxDragAction->insertItem( i18n( "Copy reference (\\cite{...})" ) );
189
 
        m_comboBoxDragAction->insertItem( i18n( "Copy BibTeX text (@article{...})" ) );
190
 
        label->setBuddy( m_comboBoxDragAction );
191
 
 
192
 
        group = new QGroupBox( 1, Qt::Vertical, i18n( "Entry Editing" ), this );
193
 
        layout->addWidget( group );
194
 
        m_checkBoxEnableAllFields = new QCheckBox( i18n( "Enable all &fields for editing" ), group );
195
 
 
196
 
        group = new QGroupBox( 1, Qt::Vertical, i18n( "Search Bar" ), this );
197
 
        layout->addWidget( group );
198
 
        m_checkBoxSearchBarClearField = new QCheckBox( i18n( "Reset field filter when changing filter text" ), group );
199
 
 
200
 
        group = new QGroupBox( 2, Qt::Horizontal, i18n( "Presentation" ), this );
201
 
        layout->addWidget( group );
202
 
        m_checkBoxUseSpecialFont = new QCheckBox( i18n( "Use special &font" ), group );
203
 
        m_pushButtonSpecialFont = new QPushButton( group );
204
 
        label = new QLabel( i18n( "Author and editor names:" ), group );
205
 
        m_comboBoxNameOrder = new QComboBox( group );
206
 
        label->setBuddy( m_comboBoxNameOrder );
207
 
        m_comboBoxNameOrder->insertItem( i18n( "John Doe" ) );
208
 
        m_comboBoxNameOrder->insertItem( i18n( "Doe, John" ) );
209
 
        QToolTip::add( m_comboBoxNameOrder, i18n( "Show names as 'John Doe' instead of 'Doe, John'" ) );
210
 
        QWhatsThis::add( m_comboBoxNameOrder, i18n( "Show names as 'John Doe' instead of 'Doe, John'.\n\nTakes only effect after the next start of KBibTeX." ) );
211
 
 
212
 
        group = new QGroupBox( 1, Qt::Vertical, i18n( "Document Search Paths" ), this );
213
 
        layout->addWidget( group );
214
 
        KPushButton *btnSelectDocumentSearchPath = new KPushButton( SmallIcon( "fileopen" ), i18n( "Edit Search Paths" ), group );
215
 
 
216
 
        group = new QGroupBox( 1, Qt::Vertical, i18n( "Find Duplicates" ), this );
217
 
        layout->addWidget( group );
218
 
        label = new QLabel( i18n( "Sensitivity:" ), group );
219
 
        QWidget *spacer = new QWidget( group );
220
 
        spacer->setFixedSize( KDialog::spacingHint() * 3, KDialog::spacingHint() );
221
 
        QLabel *label2 = new QLabel( i18n( "Low" ), group );
222
 
        m_sliderBarFindDuplicatesSensitivity = new QSlider( Qt::Horizontal, group );
223
 
        m_sliderBarFindDuplicatesSensitivity->setMinValue( m_findDuplicatesSensitivityMin );
224
 
        m_sliderBarFindDuplicatesSensitivity->setMaxValue( m_findDuplicatesSensitivityMax );
225
 
        m_sliderBarFindDuplicatesSensitivity->setLineStep( 1 );
226
 
        m_sliderBarFindDuplicatesSensitivity->setPageStep( 5 );
227
 
        label->setBuddy( m_sliderBarFindDuplicatesSensitivity );
228
 
        label2 = new QLabel( i18n( "High" ), group );
229
 
 
230
 
        layout->addStretch();
231
 
 
232
 
        connect( m_checkBoxSearchBarClearField, SIGNAL( toggled( bool ) ), this, SLOT( slotConfigChanged() ) );
233
 
        connect( m_checkBoxEnableAllFields, SIGNAL( toggled( bool ) ), this, SLOT( slotConfigChanged() ) );
234
 
        connect( m_comboBoxDoubleClickAction, SIGNAL( activated( int ) ), this, SLOT( slotConfigChanged() ) );
235
 
        connect( m_comboBoxDragAction, SIGNAL( activated( int ) ), this, SLOT( slotConfigChanged() ) );
236
 
        connect( m_comboBoxSortingColumn, SIGNAL( activated( int ) ), this, SLOT( slotConfigChanged() ) );
237
 
        connect( m_comboBoxSortingOrder, SIGNAL( activated( int ) ), this, SLOT( slotConfigChanged() ) );
238
 
        connect( m_pushButtonSpecialFont, SIGNAL( clicked() ), this, SLOT( slotSelectSpecialFont() ) );
239
 
        connect( m_checkBoxUseSpecialFont, SIGNAL( toggled( bool ) ), m_pushButtonSpecialFont, SLOT( setEnabled( bool ) ) );
240
 
        connect( m_checkBoxUseSpecialFont, SIGNAL( toggled( bool ) ), this, SLOT( slotConfigChanged() ) );
241
 
        connect( btnSelectDocumentSearchPath, SIGNAL( clicked() ), this, SLOT( slotSelectDocumentSearchPath() ) );
242
 
    }
243
 
 
244
 
 
245
 
    SettingsEditing::~SettingsEditing()
246
 
    {
247
 
        // nothing
248
 
    }
249
 
 
250
 
    void SettingsEditing::applyData()
251
 
    {
252
 
        Settings * settings = Settings::self();
253
 
 
254
 
        settings->editing_SearchBarClearField = m_checkBoxSearchBarClearField->isChecked();
255
 
        settings->editing_EnableAllFields = m_checkBoxEnableAllFields->isChecked();
256
 
        settings->editing_MainListSortingColumn = m_comboBoxSortingColumn->currentItem();
257
 
        settings->editing_MainListSortingOrder = m_comboBoxSortingOrder->currentItem() == 0 ? 1 : -1;
258
 
        settings->editing_MainListDoubleClickAction = m_comboBoxDoubleClickAction->currentItem();
259
 
        settings->editing_DragAction = m_comboBoxDragAction->currentItem() == 0 ? Settings::COPYREFERENCE : Settings::COPYBIBTEX;
260
 
 
261
 
        settings->editing_UseSpecialFont = m_checkBoxUseSpecialFont->isChecked();
262
 
        settings->editing_SpecialFont = m_specialFont;
263
 
 
264
 
        settings->editing_FirstNameFirst = m_comboBoxNameOrder->currentItem() == 0;
265
 
 
266
 
        settings->editing_DocumentSearchPaths.clear();
267
 
        for ( QStringList::Iterator it = m_documentSearchPaths.begin(); it != m_documentSearchPaths.end(); ++it )
268
 
            settings->editing_DocumentSearchPaths.append( *it );
269
 
 
270
 
        settings->editing_findDuplicatesSensitivity = ( m_findDuplicatesSensitivityMin + m_findDuplicatesSensitivityMax ) - m_sliderBarFindDuplicatesSensitivity->value();
271
 
    }
272
 
 
273
 
    void SettingsEditing::readData()
274
 
    {
275
 
        Settings * settings = Settings::self();
276
 
 
277
 
        m_checkBoxSearchBarClearField->setChecked( settings->editing_SearchBarClearField );
278
 
        m_checkBoxEnableAllFields->setChecked( settings->editing_EnableAllFields );
279
 
        m_comboBoxSortingColumn->setCurrentItem( settings->editing_MainListSortingColumn );
280
 
        m_comboBoxSortingOrder->setCurrentItem( settings->editing_MainListSortingOrder == 1 ? 0 : 1 );
281
 
        m_comboBoxDoubleClickAction->setCurrentItem( settings->editing_MainListDoubleClickAction );
282
 
        m_comboBoxDragAction->setCurrentItem( settings->editing_DragAction == Settings::COPYREFERENCE ? 0 : 1 );
283
 
 
284
 
        m_checkBoxUseSpecialFont->setChecked( settings->editing_UseSpecialFont );
285
 
        m_specialFont = settings->editing_SpecialFont;
286
 
        updateFontData();
287
 
        m_pushButtonSpecialFont->setEnabled( m_checkBoxUseSpecialFont->isChecked() );
288
 
 
289
 
        m_comboBoxNameOrder->setCurrentItem( settings->editing_FirstNameFirst ? 0 : 1 );
290
 
 
291
 
        m_documentSearchPaths.clear();
292
 
        for ( QStringList::Iterator it = settings->editing_DocumentSearchPaths.begin(); it != settings->editing_DocumentSearchPaths.end(); ++it )
293
 
            m_documentSearchPaths.append( *it );
294
 
 
295
 
        m_sliderBarFindDuplicatesSensitivity->setValue(( m_findDuplicatesSensitivityMin + m_findDuplicatesSensitivityMax ) - settings->editing_findDuplicatesSensitivity );
296
 
    }
297
 
 
298
 
    void SettingsEditing::slotConfigChanged()
299
 
    {
300
 
        emit configChanged();
301
 
    }
302
 
 
303
 
    void SettingsEditing::slotSelectSpecialFont()
304
 
    {
305
 
        int result = KFontDialog::getFont( m_specialFont );
306
 
        if ( result == KFontDialog::Accepted )
307
 
        {
308
 
            updateFontData();
309
 
            emit configChanged();
310
 
        }
311
 
    }
312
 
 
313
 
    void SettingsEditing::slotSelectDocumentSearchPath()
314
 
    {
315
 
        if ( editPathList( m_documentSearchPaths ) )
316
 
            slotConfigChanged();
317
 
    }
318
 
 
319
 
    void SettingsEditing::updateFontData()
320
 
    {
321
 
        m_pushButtonSpecialFont->setText( m_specialFont.family() );
322
 
        m_pushButtonSpecialFont->setFont( m_specialFont );
323
 
    }
324
 
 
325
 
    bool SettingsEditing::editPathList( QStringList &pathList )
326
 
    {
327
 
        return SettingsEditingPaths::execute( this, pathList );
328
 
    }
329
 
}
330
 
 
331
 
#include "settingsediting.moc"