summaryrefslogtreecommitdiffstats
path: root/src/mergeelements.h
blob: 88c011ecfcb860d8eb9bb9339ddf821798cc3743 (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
/***************************************************************************
 *   Copyright (C) 2004-2009 by Thomas Fischer                             *
 *   fischer@unix-ag.uni-kl.de                                             *
 *                                                                         *
 *   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.             *
 ***************************************************************************/
#ifndef KBIBTEXMERGEELEMENTS_H
#define KBIBTEXMERGEELEMENTS_H

#include <kdialogbase.h>

#include <findduplicates.h>
#include <file.h>
#include <entry.h>

class KPushButton;
class KTextEdit;
class KListView;
class QProgressBar;

namespace KBibTeX
{
    class MergeElementsCliqueItem : public QObject, public QCheckListItem
    {
        Q_OBJECT
    public:
        MergeElementsCliqueItem( BibTeX::Entry* entry, BibTeX::Macro* macro, BibTeX::Preamble* preamble, QListView *parent );
        BibTeX::Entry* entry;
        BibTeX::Macro* macro;
        BibTeX::Preamble* preamble;

    protected:
        void stateChange( bool );

    signals:
        void stateChanged( MergeElementsCliqueItem* );
    };

    class MergeEntriesAlternativesController: public QCheckListItem
    {
    public:
        MergeEntriesAlternativesController( const QString &label, QListView *parent );
        MergeEntriesAlternativesController( BibTeX::EntryField::FieldType fieldType, QListView *parent );
        BibTeX::EntryField::FieldType fieldType;
        const QString fieldName;
    };

    class MergeMacrosAlternativesController: public QCheckListItem
    {
    public:
        MergeMacrosAlternativesController( bool isKey, QListView *parent );
    };


    class MergeEntriesAlternativesItem: public QCheckListItem
    {
    public:
        MergeEntriesAlternativesItem( BibTeX::EntryField *field, MergeEntriesAlternativesController *parent );
        BibTeX::EntryField *field;
    };

    class MergeMacrosAlternativesItem: public QCheckListItem
    {
    public:
        MergeMacrosAlternativesItem( BibTeX::Value *value, MergeMacrosAlternativesController *parent );
        BibTeX::Value *value;
    };

    class MergeElementsAlternativesId: public QCheckListItem
    {
    public:
        MergeElementsAlternativesId( const QString &id, MergeEntriesAlternativesController *parent );
        QString id;
    };

    class MergeMacroAlternativesKey: public QCheckListItem
    {
    public:
        MergeMacroAlternativesKey( const QString &key, MergeMacrosAlternativesController *parent );
        QString key;
    };


    class MergeEntriesAlternativesEntryType: public QCheckListItem
    {
    public:
        MergeEntriesAlternativesEntryType( const QString &typeString, MergeEntriesAlternativesController *parent );
        MergeEntriesAlternativesEntryType( BibTeX::Entry::EntryType type, MergeEntriesAlternativesController *parent );
        QString typeString;
        BibTeX::Entry::EntryType type;
    };

    class MergePreambleAlternativesController: public QCheckListItem
    {
    public:
        MergePreambleAlternativesController( QListView *parent );
    };

    class MergePreambleAlternatives: public QCheckListItem
    {
    public:
        MergePreambleAlternatives( const QString &text, MergePreambleAlternativesController *parent );
        QString text;
    };

    /**
     @author Thomas Fischer <fischer@unix-ag.uni-kl.de>
    */
    class MergeElements : public KDialogBase
    {
        Q_OBJECT
    public:
        MergeElements( QWidget *parent );
        ~MergeElements();
        int mergeDuplicates( BibTeX::File *bibTeXFile );

    protected:
        void showEvent( QShowEvent * );

    protected slots:
        void slotRefreshAlternatives();
        void slotNextClique();
        void slotPreviousClique();
        void slotPreviewElement( QListViewItem *item );
        void saveCurrentMergeSet();
        void slotRestore();

    private:
        typedef struct
        {
            BibTeX::Macro *macro;
            BibTeX::Entry *entry;
            BibTeX::EntryField *field;
        } First;

        typedef struct
        {
            QValueList<BibTeX::Macro*> macros;
            QValueList<BibTeX::Entry*> entries;
            QValueList<BibTeX::EntryField*> fields;
            QValueList<BibTeX::Preamble*> preambles;
            QString macroKey;
            BibTeX::Value *macroValue;
            QString id, typeString;
            BibTeX::Entry::EntryType type;
            QString preambleText;
        } MergeSet;

        KListView *m_listViewClique;
        KListView *m_listViewAlternatives;
        QProgressBar *m_progressBar;
        FindDuplicates::DuplicateCliqueList m_duplicateCliqueList;
        MergeSet **m_mergeSetList;
        int m_currentCliqueIndex;

        void setupGUI();
        void setClique( int cliqueIndex );
        void restoreCurrentMergeSet();
        void applyMergeSet( BibTeX::File *bibTeXFile, BibTeX::File *otherBibTeXFile = NULL );
        void restoreWindowSize( KConfig *config );
        void saveWindowSize( KConfig *config ) const;
    };

}

#endif // KBIBTEXMERGEELEMENTS_H