~ubuntu-branches/ubuntu/precise/kbibtex/precise

« back to all changes in this revision

Viewing changes to src/entrywidgetauthor.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
 
 
23
 
#include <kdialog.h>
24
 
#include <klocale.h>
25
 
 
26
 
#include <fieldlistview.h>
27
 
#include <entrywidgetwarningsitem.h>
28
 
#include "entrywidgetauthor.h"
29
 
 
30
 
namespace KBibTeX
31
 
{
32
 
 
33
 
    EntryWidgetAuthor::EntryWidgetAuthor( BibTeX::File *bibtexfile, bool isReadOnly, QWidget *parent, const char *name )
34
 
            : EntryWidgetTab( bibtexfile, isReadOnly, parent, name )
35
 
    {
36
 
        setupGUI();
37
 
    }
38
 
 
39
 
    EntryWidgetAuthor::~EntryWidgetAuthor()
40
 
    {
41
 
        // nothing
42
 
    }
43
 
 
44
 
    bool EntryWidgetAuthor::isModified()
45
 
    {
46
 
        return m_fieldListViewAuthor->isModified() || m_fieldListViewEditor->isModified();
47
 
    }
48
 
 
49
 
    void EntryWidgetAuthor::updateGUI( BibTeX::Entry::EntryType entryType, bool enableAll )
50
 
    {
51
 
        bool enableWidget = enableAll || BibTeX::Entry::getRequireStatus( entryType, BibTeX::EntryField::ftAuthor ) != BibTeX::Entry::frsIgnored;
52
 
        m_fieldListViewAuthor->setEnabled( enableWidget );
53
 
 
54
 
        enableWidget = enableAll || BibTeX::Entry::getRequireStatus( entryType, BibTeX::EntryField::ftEditor ) != BibTeX::Entry::frsIgnored;
55
 
        m_fieldListViewEditor->setEnabled( enableWidget );
56
 
    }
57
 
 
58
 
    void EntryWidgetAuthor::apply( BibTeX::Entry *entry )
59
 
    {
60
 
        BibTeX::Value * value = m_fieldListViewAuthor->value();
61
 
        setValue( entry, BibTeX::EntryField::ftAuthor, value );
62
 
        if ( value != NULL ) delete value;
63
 
 
64
 
        value = m_fieldListViewEditor->value();
65
 
        setValue( entry, BibTeX::EntryField::ftEditor, value );
66
 
        if ( value != NULL ) delete value;
67
 
    }
68
 
 
69
 
    void EntryWidgetAuthor::reset( BibTeX::Entry *entry )
70
 
    {
71
 
        BibTeX::EntryField * field = entry->getField( BibTeX::EntryField::ftAuthor );
72
 
        m_fieldListViewAuthor->setValue( field != NULL ? field->value() : NULL );
73
 
 
74
 
        field = entry->getField( BibTeX::EntryField::ftEditor );
75
 
        m_fieldListViewEditor->setValue( field != NULL ? field->value() : NULL );
76
 
    }
77
 
 
78
 
    void EntryWidgetAuthor::updateWarnings( BibTeX::Entry::EntryType entryType, QListView *listViewWarnings )
79
 
    {
80
 
        if ( entryType == BibTeX::Entry::etBook || entryType == BibTeX::Entry::etInBook )
81
 
        {
82
 
            if ( m_fieldListViewAuthor->isEmpty() && m_fieldListViewEditor->isEmpty() )
83
 
                new EntryWidgetWarningsItem( EntryWidgetWarningsItem::wlWarning, i18n( "The fields 'Author' or 'Editor' are required, but both are missing" ), m_fieldListViewAuthor, listViewWarnings, "warning" );
84
 
        }
85
 
        else
86
 
        {
87
 
            addMissingWarning( entryType, BibTeX::EntryField::ftAuthor, m_fieldListViewAuthor->caption(), !m_fieldListViewAuthor->isEmpty(), m_fieldListViewAuthor, listViewWarnings );
88
 
 
89
 
            addMissingWarning( entryType, BibTeX::EntryField::ftEditor, m_fieldListViewEditor->caption(), !m_fieldListViewEditor->isEmpty(), m_fieldListViewEditor, listViewWarnings );
90
 
        }
91
 
    }
92
 
 
93
 
    void EntryWidgetAuthor::setupGUI()
94
 
    {
95
 
        QGridLayout * gridLayout = new QGridLayout( this, 2, 3, KDialog::marginHint(), KDialog::spacingHint(), "gridLayout" );
96
 
        gridLayout->setColSpacing( 1, KDialog::spacingHint() * 4 );
97
 
 
98
 
        QLabel *label = new QLabel( QString( "%1:" ).arg( i18n( "Author" ) ), this );
99
 
        gridLayout->addWidget( label, 0, 0 );
100
 
        m_fieldListViewAuthor = new KBibTeX::FieldListView( i18n( "Author" ), i18n( "May only contain ASCII characters, in case of doubt keep English form", "NewAuthor" ), m_isReadOnly, this );
101
 
        m_fieldListViewAuthor->setFieldType( BibTeX::EntryField::ftAuthor );
102
 
        gridLayout->addWidget( m_fieldListViewAuthor, 1, 0 );
103
 
        label->setBuddy( m_fieldListViewAuthor );
104
 
 
105
 
        label = new QLabel( QString( "%1:" ).arg( i18n( "Editor" ) ), this );
106
 
        gridLayout->addWidget( label, 0, 2 );
107
 
        m_fieldListViewEditor = new KBibTeX::FieldListView( i18n( "Editor" ), i18n( "May only contain ASCII characters, in case of doubt keep English form", "NewEditor" ), m_isReadOnly, this );
108
 
        m_fieldListViewEditor->setFieldType( BibTeX::EntryField::ftEditor );
109
 
        gridLayout->addWidget( m_fieldListViewEditor, 1, 2 );
110
 
        label->setBuddy( m_fieldListViewEditor );
111
 
    }
112
 
 
113
 
}
114
 
#include "entrywidgetauthor.moc"