summaryrefslogtreecommitdiffstats
path: root/src/documentwidget.h
blob: 9256b966df17668c134523b12cc903865d667dc3 (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
/***************************************************************************
*   Copyright (C) 2004-2006 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 KBIBTEXDOCUMENTWIDGET_H
#define KBIBTEXDOCUMENTWIDGET_H

#include <tqtabwidget.h>

#include <kdirwatch.h>

#include "fileimporter.h"
#include "file.h"
#include "settings.h"

class TQIODevice;
class TQProgressDialog;
class TQListViewItem;
class TQWidget;
class TQSplitter;

class TDEPopupMenu;
class TDEActionMenu;
class KURL;
class KTextEdit;
class KLineEdit;

namespace KBibTeX
{
    class DocumentListView;
    class DocumentListViewItem;
    class DocumentSourceView;
    class SearchBar;
    class SideBar;
    class WebQuery;

    class DocumentWidget : public TQTabWidget
    {
        Q_OBJECT
    public:
        DocumentWidget( bool isReadOnly, TQWidget *parent = 0, const char *name = 0 );
        ~DocumentWidget();

        bool open( const TQString &fileName, bool mergeOnly = FALSE );
        bool open( TQIODevice *iodevice, bool mergeOnly = FALSE, const TQString &label = TQString::null, BibTeX::FileImporter *importer = NULL );
        bool save( const TQString &fileName, TQStringList *errorLog = NULL );
        bool save( TQIODevice *iodevice, BibTeX::File::FileFormat format = BibTeX::File::formatBibTeX, const TQString &label = TQString::null, TQStringList *errorLog = NULL );

        bool newElement( const TQString& elementType );
        void searchWebsites( const TQString& searchURL, bool includeAuthor );
        void updateViews();
        void showStatistics();

        void setFactory( KXMLGUIFactory *factory, KXMLGUIClient *client );
        void updateViewDocumentMenu( );
        void updateAssignKeywords( );

        void deferredInitialization();
        void saveState();
        void restoreState();

        KDirWatch &dirWatch();

    signals:
        void modified();
        void listViewSelectionChanged( int numSelected );
        void undoChanged( bool undoAvailable );

    public slots:
        void executeElement( DocumentListViewItem* );
        bool editElement();
        bool editElement( DocumentListViewItem* );
        bool editElement( BibTeX::Element* );
        void deleteElements();
        void sendSelectedToLyx();
        void cutElements();
        void copyElements();
        void copyRefElements();
        void pasteElements();
        void selectAll();
        void setReadOnly( bool isReadOnly );
        void configureEditor();
        void undoEditor();
        void find();
        void findNext();
        void refreshBibTeXFile();
        void onlineSearch();
        void findDuplicates();
        void slotViewFirstDocument();
        void slotViewFirstDocumentsOnlineRef();
        void slotNormalizeIds();

    private:
        enum EditMode
        {
            emList, emSource
        };

        KLineEdit *m_lineEditNewKeyword;
        bool m_isReadOnly;
        TQSplitter *m_horSplitter;
        TQSplitter *m_vertSplitter;
        TQWidget *m_container;
        SearchBar *m_searchBar;
        DocumentListView *m_listViewElements;
        KTextEdit * m_preview;
        DocumentSourceView *m_sourceView;
        SideBar* m_sideBar;
        BibTeX::File *m_bibtexfile;
        TQString m_filename;
        TQProgressDialog *m_progressDialog;
        int m_newElementCounter;
        EditMode m_editMode;
        TDEActionMenu *m_viewDocumentActionMenu;
        TDEActionMenu *m_assignKeywordsActionMenu;
        TQStringList m_viewDocumentActionMenuURLs;
        TQMap<int, TQString> m_assignKeywordsActionMenuURLs;
        TDEActionMenu *m_searchWebsitesActionMenu;
        TDEAction *m_actionEditCut;
        TDEAction *m_actionEditCopy;
        TDEAction *m_actionEditCopyRef;
        TDEAction *m_actionEditPaste;
        TDEAction *m_actionEditSelectAll;
        TDEAction *m_actionEditFind;
        TDEAction *m_actionEditFindNext;
        TDEAction *m_actionNormalizeIds;
        KDirWatch m_dirWatch;

        void setupGUI();

        void startProgress( const TQString &label, TQObject *progressFrom );
        void endProgress( TQObject *progressFrom );

        void searchWebsites( BibTeX::Element *element, const TQString& searchURL, bool includeAuthor );

        bool editElementDialog( BibTeX::Element *element );
        void updateFromGUI();
        TQString nextNewEntry();

        KURL::List getEntryURLs( BibTeX::Entry *entry );

        BibTeX::FileImporter *fileImporterFactory( const TQString &fileName );

    private slots:
        void slotShowProgress( int current, int total );
        void slotSelectionChanged();
        void slotPreviewElement( TQListViewItem * item = NULL );
        void slotTabChanged( TQWidget *tab );
        void slotModified();
        void slotFileGotDirty( const TQString& path );
        void slotRefreshDirtyFile();
        void slotViewDocument( int id );
        void slotAssignKeywords( int id );
        void slotAddKeyword();
    };

}

#endif