~ubuntu-branches/ubuntu/wily/kbibtex/wily

« back to all changes in this revision

Viewing changes to src/entrywidgetother.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Hanke
  • Date: 2009-06-15 12:41:19 UTC
  • mfrom: (1.1.3 upstream) (2.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090615124119-eoojhlvkmw3o9tkm
Tags: 0.2.2-1
* New upstream version (Closes: #487301, #507837, #518959, #520392).
* Bumped Standards-Version to 3.8.1. No changes necessary.
* Added 'DM-Upload-Allowed: yes'.
* Added missing '${misc:Depends}'.
* Support for per-file encoding settings (Closes: #514356)
* Upgrade debhelper compatibility to version 5.
* Update debian/copyright for 2009 release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/***************************************************************************
2
 
*   Copyright (C) 2004-2008 by Thomas Fischer                             *
 
2
*   Copyright (C) 2004-2009 by Thomas Fischer                             *
3
3
*   fischer@unix-ag.uni-kl.de                                             *
4
4
*                                                                         *
5
5
*   This program is free software; you can redistribute it and/or modify  *
17
17
*   Free Software Foundation, Inc.,                                       *
18
18
*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19
19
***************************************************************************/
20
 
#include <qpushbutton.h>
21
 
#include <qlineedit.h>
22
20
#include <qstringlist.h>
23
21
#include <qlayout.h>
24
22
#include <qtooltip.h>
32
30
#include <klocale.h>
33
31
#include <kiconloader.h>
34
32
#include <kio/netaccess.h>
 
33
#include <kpushbutton.h>
 
34
#include <klineedit.h>
35
35
 
36
36
#include <fieldlineedit.h>
37
37
#include <settings.h>
63
63
 
64
64
    void EntryWidgetOther::apply( BibTeX::Entry *entry )
65
65
    {
66
 
        for ( QStringList::iterator it = m_deletedFields.begin(); it != m_deletedFields.end(); it++ )
 
66
        Settings * settings = Settings::self();
 
67
        QStringList toBeDeleted;
 
68
        for ( QValueList<BibTeX::EntryField*>::ConstIterator it = entry->begin(); it != entry->end(); it++ )
 
69
        {
 
70
            BibTeX::EntryField *field = *it;
 
71
            bool doDel = field->fieldType() == BibTeX::EntryField::ftUnknown;
 
72
            if ( !doDel ) continue;
 
73
 
 
74
            QString ftn = field->fieldTypeName().lower();
 
75
            for ( unsigned int i = 0; doDel && i < settings->userDefinedInputFields.count(); ++i )
 
76
                doDel &= settings->userDefinedInputFields[i]->name.lower() != ftn;
 
77
 
 
78
            if ( doDel )
 
79
                toBeDeleted.append( ftn );
 
80
        }
 
81
        for ( QStringList::ConstIterator it = toBeDeleted.begin(); it != toBeDeleted.end(); ++it )
67
82
            entry->deleteField( *it );
68
 
        m_deletedFields.clear();
69
83
 
70
84
        for ( QListViewItemIterator it( m_listViewFields ); it.current(); it++ )
71
85
        {
72
86
            ValueListViewItem *vlvi = dynamic_cast<KBibTeX::ValueListViewItem*>( it.current() );
73
87
            if ( vlvi != NULL )
74
88
            {
75
 
                BibTeX::EntryField * field = entry->getField( vlvi->title() );
76
 
                if ( field == NULL )
77
 
                {
78
 
                    field = new BibTeX::EntryField( vlvi->title() );
79
 
                    entry->addField( field );
80
 
                }
81
 
 
 
89
                BibTeX::EntryField * field = new BibTeX::EntryField( vlvi->title() );
82
90
                field->setValue( vlvi->value() );
 
91
                entry->addField( field );
83
92
            }
84
93
        }
85
94
 
89
98
    void EntryWidgetOther::reset( BibTeX::Entry *entry )
90
99
    {
91
100
        m_listViewFields->clear();
92
 
        m_deletedFields.clear();
93
101
 
94
 
        for ( QValueList<BibTeX::EntryField*>::const_iterator it = entry->begin(); it != entry->end(); it++ )
 
102
        Settings * settings = Settings::self();
 
103
        for ( QValueList<BibTeX::EntryField*>::ConstIterator it = entry->begin(); it != entry->end(); it++ )
95
104
        {
96
105
            BibTeX::EntryField *field = *it;
97
106
            bool doAdd = field->fieldType() == BibTeX::EntryField::ftUnknown;
 
107
            if ( !doAdd ) continue;
98
108
 
99
 
            Settings * settings = Settings::self();
100
109
            QString ftn = field->fieldTypeName().lower();
101
110
            for ( unsigned int i = 0; doAdd && i < settings->userDefinedInputFields.count(); ++i )
102
111
                doAdd &= settings->userDefinedInputFields[i]->name.lower() != ftn;
117
126
    {
118
127
        QGridLayout * gridLayout = new QGridLayout( this, 5, 3, KDialog::marginHint(), KDialog::spacingHint(), "gridLayout" );
119
128
 
120
 
        m_lineEditKey = new QLineEdit( this, "m_lineEditKey" );
 
129
        m_lineEditKey = new KLineEdit( this, "m_lineEditKey" );
121
130
        m_lineEditKey->setReadOnly( m_isReadOnly );
122
131
        gridLayout->addWidget( m_lineEditKey, 0, 1 );
123
132
        QToolTip::add( m_lineEditKey, i18n( "Name of the user-defined field" ) );
126
135
        label->setBuddy( m_lineEditKey );
127
136
        gridLayout->addWidget( label, 0, 0 );
128
137
 
129
 
        m_pushButtonAdd = new QPushButton( i18n( "&Add" ), this, "m_pushButtonAdd" );
 
138
        m_pushButtonAdd = new KPushButton( i18n( "&Add" ), this, "m_pushButtonAdd" );
130
139
        gridLayout->addWidget( m_pushButtonAdd, 0, 2 );
131
140
        m_pushButtonAdd->setIconSet( QIconSet( SmallIcon( "add" ) ) );
132
141
 
153
162
        label->setAlignment( Qt::AlignTop );
154
163
        gridLayout->addWidget( label, 3, 0 );
155
164
 
156
 
        m_pushButtonDelete = new QPushButton( i18n( "&Delete" ), this, "m_pushButtonDelete" );
 
165
        m_pushButtonDelete = new KPushButton( i18n( "&Delete" ), this, "m_pushButtonDelete" );
157
166
        gridLayout->addWidget( m_pushButtonDelete, 3, 2 );
158
167
        m_pushButtonDelete->setIconSet( QIconSet( SmallIcon( "delete" ) ) );
159
168
 
160
 
        m_pushButtonOpen = new QPushButton( i18n( "Op&en" ), this, "m_pushButtonOpen" );
 
169
        m_pushButtonOpen = new KPushButton( i18n( "Op&en" ), this, "m_pushButtonOpen" );
161
170
        gridLayout->addWidget( m_pushButtonOpen, 4, 2 );
162
171
        m_pushButtonOpen->setIconSet( QIconSet( SmallIcon( "fileopen" ) ) );
163
172
 
170
179
 
171
180
        connect( m_listViewFields, SIGNAL( clicked( QListViewItem*, const QPoint&, int ) ), this, SLOT( fieldExecute( QListViewItem* ) ) );
172
181
        connect( m_lineEditKey, SIGNAL( textChanged( const QString& ) ), this, SLOT( updateGUI() ) );
 
182
        connect( m_fieldLineEditValue, SIGNAL( textChanged( ) ), this, SLOT( updateGUI() ) );
173
183
        connect( m_pushButtonAdd, SIGNAL( clicked( ) ), this, SLOT( addClicked( ) ) );
174
184
        connect( m_pushButtonDelete, SIGNAL( clicked( ) ), this, SLOT( deleteClicked( ) ) );
175
185
        connect( m_pushButtonOpen, SIGNAL( clicked() ), this, SLOT( openClicked() ) );
188
198
            m_listViewFields->clearSelection();
189
199
 
190
200
        m_pushButtonDelete->setEnabled( !m_isReadOnly && contains );
191
 
        m_pushButtonAdd->setEnabled( !m_isReadOnly && !text.isEmpty() && isUnknown );
 
201
        m_pushButtonAdd->setEnabled( !m_isReadOnly && !text.isEmpty() && !m_fieldLineEditValue->isEmpty() && isUnknown );
192
202
        m_pushButtonAdd->setText( contains ? i18n( "&Apply" ) : i18n( "&Add" ) );
193
203
        m_pushButtonAdd->setIconSet( QIconSet( SmallIcon( contains ? "apply" : "fileopen" ) ) );
194
204
 
214
224
 
215
225
    void EntryWidgetOther::addClicked()
216
226
    {
217
 
        QString text = m_lineEditKey->text();
218
 
        QListViewItem * item = m_listViewFields->findItem( text, 0 ) ;
 
227
        QString key = m_lineEditKey->text();
 
228
        QListViewItem * item = m_listViewFields->findItem( key, 0 ) ;
219
229
        ValueListViewItem * vlvi = item != NULL ? dynamic_cast<KBibTeX::ValueListViewItem*>( item ) : NULL;
220
230
 
221
231
        if ( vlvi != NULL )
222
232
            vlvi->setValue( m_fieldLineEditValue->value() );
223
233
        else
224
 
            new ValueListViewItem( text, m_fieldLineEditValue->value(), m_listViewFields );
 
234
            new ValueListViewItem( key, m_fieldLineEditValue->value(), m_listViewFields );
225
235
 
226
236
        updateGUI();
227
237
 
234
244
 
235
245
        if ( item != NULL )
236
246
        {
237
 
            m_deletedFields.append( item->text( 0 ) );
238
247
            delete item;
239
248
            m_lineEditKey->setText( "" );
240
249
            m_fieldLineEditValue->setValue( new BibTeX::Value() );