summaryrefslogtreecommitdiffstats
path: root/src/entrywidgetauthor.cpp
blob: e31bafbe7100069703947e88647893a18f120701 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/***************************************************************************
*   Copyright (C) 2004-2009 by Thomas Fischer                             *
*   [email protected]                                             *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
*   This program is distributed in the hope that it will be useful,       *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
*   GNU General Public License for more details.                          *
*                                                                         *
*   You should have received a copy of the GNU General Public License     *
*   along with this program; if not, write to the                         *
*   Free Software Foundation, Inc.,                                       *
*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
***************************************************************************/
#include <ntqlayout.h>
#include <ntqlabel.h>

#include <kdialog.h>
#include <tdelocale.h>

#include <fieldlistview.h>
#include <entrywidgetwarningsitem.h>
#include "entrywidgetauthor.h"

namespace KBibTeX
{

    EntryWidgetAuthor::EntryWidgetAuthor( BibTeX::File *bibtexfile, bool isReadOnly, TQWidget *parent, const char *name )
            : EntryWidgetTab( bibtexfile, isReadOnly, parent, name )
    {
        setupGUI();
    }

    EntryWidgetAuthor::~EntryWidgetAuthor()
    {
        // nothing
    }

    bool EntryWidgetAuthor::isModified()
    {
        return m_fieldListViewAuthor->isModified() || m_fieldListViewEditor->isModified();
    }

    void EntryWidgetAuthor::updateGUI( BibTeX::Entry::EntryType entryType, bool enableAll )
    {
        bool enableWidget = enableAll || BibTeX::Entry::getRequireStatus( entryType, BibTeX::EntryField::ftAuthor ) != BibTeX::Entry::frsIgnored;
        m_fieldListViewAuthor->setEnabled( enableWidget );

        enableWidget = enableAll || BibTeX::Entry::getRequireStatus( entryType, BibTeX::EntryField::ftEditor ) != BibTeX::Entry::frsIgnored;
        m_fieldListViewEditor->setEnabled( enableWidget );
    }

    void EntryWidgetAuthor::apply( BibTeX::Entry *entry )
    {
        BibTeX::Value * value = m_fieldListViewAuthor->value();
        setValue( entry, BibTeX::EntryField::ftAuthor, value );
        if ( value != NULL ) delete value;

        value = m_fieldListViewEditor->value();
        setValue( entry, BibTeX::EntryField::ftEditor, value );
        if ( value != NULL ) delete value;
    }

    void EntryWidgetAuthor::reset( BibTeX::Entry *entry )
    {
        BibTeX::EntryField * field = entry->getField( BibTeX::EntryField::ftAuthor );
        m_fieldListViewAuthor->setValue( field != NULL ? field->value() : NULL );

        field = entry->getField( BibTeX::EntryField::ftEditor );
        m_fieldListViewEditor->setValue( field != NULL ? field->value() : NULL );
    }

    void EntryWidgetAuthor::updateWarnings( BibTeX::Entry::EntryType entryType, TQListView *listViewWarnings )
    {
        if ( entryType == BibTeX::Entry::etBook || entryType == BibTeX::Entry::etInBook )
        {
            if ( m_fieldListViewAuthor->isEmpty() && m_fieldListViewEditor->isEmpty() )
                new EntryWidgetWarningsItem( EntryWidgetWarningsItem::wlWarning, i18n( "The fields 'Author' or 'Editor' are required, but both are missing" ), m_fieldListViewAuthor, listViewWarnings, "warning" );
        }
        else
        {
            addMissingWarning( entryType, BibTeX::EntryField::ftAuthor, m_fieldListViewAuthor->caption(), !m_fieldListViewAuthor->isEmpty(), m_fieldListViewAuthor, listViewWarnings );

            addMissingWarning( entryType, BibTeX::EntryField::ftEditor, m_fieldListViewEditor->caption(), !m_fieldListViewEditor->isEmpty(), m_fieldListViewEditor, listViewWarnings );
        }
    }

    void EntryWidgetAuthor::setupGUI()
    {
        TQGridLayout * gridLayout = new TQGridLayout( this, 2, 3, KDialog::marginHint(), KDialog::spacingHint(), "gridLayout" );
        gridLayout->setColSpacing( 1, KDialog::spacingHint() * 4 );

        TQLabel *label = new TQLabel( TQString( "%1:" ).arg( i18n( "Author" ) ), this );
        gridLayout->addWidget( label, 0, 0 );
        m_fieldListViewAuthor = new KBibTeX::FieldListView( i18n( "Author" ), i18n( "May only contain ASCII characters, in case of doubt keep English form", "NewAuthor" ), m_isReadOnly, this );
        m_fieldListViewAuthor->setFieldType( BibTeX::EntryField::ftAuthor );
        gridLayout->addWidget( m_fieldListViewAuthor, 1, 0 );
        label->setBuddy( m_fieldListViewAuthor );

        label = new TQLabel( TQString( "%1:" ).arg( i18n( "Editor" ) ), this );
        gridLayout->addWidget( label, 0, 2 );
        m_fieldListViewEditor = new KBibTeX::FieldListView( i18n( "Editor" ), i18n( "May only contain ASCII characters, in case of doubt keep English form", "NewEditor" ), m_isReadOnly, this );
        m_fieldListViewEditor->setFieldType( BibTeX::EntryField::ftEditor );
        gridLayout->addWidget( m_fieldListViewEditor, 1, 2 );
        label->setBuddy( m_fieldListViewEditor );
    }

}
#include "entrywidgetauthor.moc"