summaryrefslogtreecommitdiffstats
path: root/src/entryfield.cpp
blob: bb7cb9d36fc63eaa25ea9046458c04a0bea6a957 (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/***************************************************************************
*   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 "entryfield.h"

namespace BibTeX
{

    EntryField::EntryField( FieldType fieldType ) : m_fieldType( fieldType )
    {
        m_fieldTypeName = fieldTypeToString( m_fieldType );
        m_value = new Value();
    }

    EntryField::EntryField( const QString &fieldTypeName ) : m_fieldTypeName( fieldTypeName )
    {
        m_fieldType = fieldTypeFromString( m_fieldTypeName );
        m_value = new Value();
    }

    EntryField::EntryField( BibTeX::EntryField *other ) : m_fieldType( other->m_fieldType ), m_fieldTypeName( other->m_fieldTypeName ), m_value( NULL )
    {
        setValue( other->m_value );
    }

    EntryField::~EntryField()
    {
        delete m_value;
    }

    QString EntryField::fieldTypeName() const
    {
        return m_fieldTypeName;
    }

    void EntryField::setFieldType( FieldType fieldType, const QString& fieldTypeName )
    {
        m_fieldType = fieldType;
        m_fieldTypeName = fieldTypeName;
    }

    EntryField::FieldType EntryField::fieldType() const
    {
        return m_fieldType;
    }

    QString EntryField::fieldTypeToString( const FieldType fieldType )
    {
        switch ( fieldType )
        {
        case ftAbstract:
            return QString( "abstract" );
        case ftAddress:
            return QString( "address" );
        case ftAnnote:
            return QString( "annote" );
        case ftAuthor:
            return QString( "author" );
        case ftBookTitle:
            return QString( "booktitle" );
        case ftChapter:
            return QString( "chapter" );
        case ftCrossRef:
            return QString( "crossref" );
        case ftDoi:
            return QString( "doi" );
        case ftEdition:
            return QString( "edition" );
        case ftEditor:
            return QString( "editor" );
        case ftHowPublished:
            return QString( "howpublished" );
        case ftInstitution:
            return QString( "institution" );
        case ftISBN:
            return QString( "isbn" );
        case ftISSN:
            return QString( "issn" );
        case ftJournal:
            return QString( "journal" );
        case ftKey:
            return QString( "key" );
        case ftKeywords:
            return QString( "keywords" );
        case ftLocalFile:
            return QString( "localfile" );
        case ftLocation:
            return QString( "location" );
        case ftMonth:
            return QString( "month" );
        case ftNote:
            return QString( "note" );
        case ftNumber:
            return QString( "number" );
        case ftOrganization:
            return QString( "organization" );
        case ftPages:
            return QString( "pages" );
        case ftPublisher:
            return QString( "publisher" );
        case ftSeries:
            return QString( "series" );
        case ftSchool:
            return QString( "school" );
        case ftTitle:
            return QString( "title" );
        case ftType:
            return QString( "type" );
        case ftURL:
            return QString( "url" );
        case ftVolume:
            return QString( "volume" );
        case ftYear:
            return QString( "year" );
        default:
            return QString( "unknown" );
        }
    }

    EntryField::FieldType EntryField::fieldTypeFromString( const QString & fieldTypeString )
    {
        QString fieldTypeStringLower = fieldTypeString.lower();

        if ( fieldTypeStringLower == "abstract" )
            return ftAbstract;
        else if ( fieldTypeStringLower == "address" )
            return ftAddress;
        else if ( fieldTypeStringLower == "annote" )
            return ftAnnote;
        else if ( fieldTypeStringLower == "author" )
            return ftAuthor;
        else if ( fieldTypeStringLower == "booktitle" )
            return ftBookTitle;
        else if ( fieldTypeStringLower == "chapter" )
            return ftChapter;
        else if ( fieldTypeStringLower == "crossref" )
            return ftCrossRef;
        else if ( fieldTypeStringLower == "doi" )
            return ftDoi;
        else if ( fieldTypeStringLower == "edition" )
            return ftEdition;
        else if ( fieldTypeStringLower == "editor" )
            return ftEditor;
        else if ( fieldTypeStringLower == "howpublished" )
            return ftHowPublished;
        else if ( fieldTypeStringLower == "institution" )
            return ftInstitution;
        else if ( fieldTypeStringLower == "isbn" )
            return ftISBN;
        else if ( fieldTypeStringLower == "issn" )
            return ftISSN;
        else if ( fieldTypeStringLower == "journal" )
            return ftJournal;
        else if ( fieldTypeStringLower == "key" )
            return ftKey;
        else if ( fieldTypeStringLower == "keywords" )
            return ftKeywords;
        else if ( fieldTypeStringLower == "localfile" )
            return ftLocalFile;
        else if ( fieldTypeStringLower == "location" )
            return ftLocation;
        else if ( fieldTypeStringLower == "month" )
            return ftMonth;
        else if ( fieldTypeStringLower == "note" )
            return ftNote;
        else if ( fieldTypeStringLower == "number" )
            return ftNumber;
        else if ( fieldTypeStringLower == "organization" )
            return ftOrganization;
        else if ( fieldTypeStringLower == "pages" )
            return ftPages;
        else if ( fieldTypeStringLower == "publisher" )
            return ftPublisher;
        else if ( fieldTypeStringLower == "series" )
            return ftSeries;
        else if ( fieldTypeStringLower == "school" )
            return ftSchool;
        else if ( fieldTypeStringLower == "title" )
            return ftTitle;
        else if ( fieldTypeStringLower == "type" )
            return ftType;
        else if ( fieldTypeStringLower == "url" )
            return ftURL;
        else if ( fieldTypeStringLower == "volume" )
            return ftVolume;
        else if ( fieldTypeStringLower == "year" )
            return ftYear;
        else
            return ftUnknown;
    }

    Value *EntryField::value()
    {
        return m_value;
    }

    void EntryField::setValue( const Value *value )
    {
        if ( value != m_value )
        {
            delete m_value;

            if ( value != NULL )
            {
                m_value = new Value( value );
            }
            else
                m_value = new Value();
        }
    }
}