summaryrefslogtreecommitdiffstats
path: root/src/settings.h
blob: ff8275b96e669ba854b9edae8ea50ed0d467a875 (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
/***************************************************************************
*   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 SETTINGS_H
#define SETTINGS_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <qstringlist.h>

#include <kcompletion.h>

#include <file.h>
#include <fieldlineedit.h>
#include <fileexporterbibtex.h>
#include <fileexporterexternal.h>
#include <entryfield.h>
#include <entry.h>

class KConfig;
class KStandardDirs;
class KURL;
class QString;
class QRegExp;
class QChar;
class QFont;

namespace KBibTeX
{
    class Settings
    {
    public:
        struct SearchURL
        {
            QString description;
            QString url;
            bool includeAuthor;
        };

        struct UserDefinedInputFields
        {
            QString name;
            QString label;
            FieldLineEdit::InputType inputType;
        };

        static Settings* self( BibTeX::File *bibtexFile = NULL );

        void load( KConfig * config );
        void save( KConfig * config );

        static QString fieldTypeToI18NString( const BibTeX::EntryField::FieldType fieldType );
        static QString entryTypeToI18NString( const BibTeX::Entry::EntryType entryType );

        static KURL doiURL( const QString& doiText );
        static bool kpsewhich( const QString& filename );
        static KURL locateFile( const QString& filename, const QString& bibTeXFileName = QString::null, QWidget *window = NULL );
        KURL locateFile( const QString& filename, QWidget *window = NULL );
        static QString resolveLink( const QString& originalFilename, const QString& linkFilename );
        static bool openUrl( const KURL& url, QWidget *parent );

#ifdef HAVE_YAZ
        void z3950clearAll();
        void z3950loadDefault();
        void z3950loadUser( KConfig * config );
        void z3950saveUser( KConfig *config );
        typedef struct Z3950Server_
        {
            QString charset, database, host, locale, name, syntax, user, password;
            int port;
        } Z3950Server;
        QMap<QString, Z3950Server> z3950_ServerList;
#endif // HAVE_YAZ

        enum DragAction {COPYREFERENCE = 1, COPYBIBTEX = 2};

        // FileIO section
        QString fileIO_Encoding;
        QString fileIO_ExportLanguage;
        QString fileIO_ExportBibliographyStyle;
        QChar fileIO_BibtexStringOpenDelimiter;
        QChar fileIO_BibtexStringCloseDelimiter;
        BibTeX::FileExporterBibTeX::KeywordCasing fileIO_KeywordCasing;
        BibTeX::FileExporterExternal::Exporter fileIO_ExporterHTML;
        bool fileIO_EmbedFiles;
        bool fileIO_EnclosingCurlyBrackets;
        bool fileIO_useBibUtils;
        QString fileIO_bib2db5BasePath;
        QString fileIO_bib2db5ClassPath;
        int fileIO_NumberOfBackups;

        bool updateBib2Db5ClassPath( const QString& newBasePath, bool testOnly = false );

        // Editing section
        bool editing_SearchBarClearField;
        bool editing_EnableAllFields;
        int editing_MainListDoubleClickAction;
        int editing_MainListSortingColumn;
        int editing_MainListSortingOrder;
        QStringList editing_FilterHistory;
        bool editing_ShowMacros;
        bool editing_ShowComments;
        QValueList<int> editing_MainListColumnsWidth;
        QValueList<int> editing_MainListColumnsIndex;
        QValueList<int> editing_HorSplitterSizes;
        QValueList<int> editing_VertSplitterSizes;
        QFont editing_SpecialFont;
        bool editing_UseSpecialFont;
        bool editing_FirstNameFirst;
        QStringList editing_DocumentSearchPaths;
        DragAction editing_DragAction;
        int editing_findDuplicatesSensitivity;

        // SearchURLs section
        QValueList<SearchURL*> searchURLs;

        // UserDefinedInputFields section
        QValueList<UserDefinedInputFields*> userDefinedInputFields;

        // External section
        QString external_XSLTStylesheetHTML;
        bool external_bibconvAvailable;
        bool external_bibtex2htmlAvailable;
        bool external_bib2xhtmlAvailable;
        bool external_latex2rtfAvailable;
        bool external_xml2bibAvailable;
        bool external_end2xmlAvailable;
        bool external_ris2xmlAvailable;

        // Id Suggestions
        QStringList idSuggestions_formatStrList;
        int idSuggestions_default;
        bool idSuggestions_forceDefault;
        QStringList idSuggestions_smallWords;

        // Auto-completion for user fields (non-persistant)
        void addToCompletion( BibTeX::File *file );
        void addToCompletion( BibTeX::Element *element );
        void addToCompletion( BibTeX::Value *value, BibTeX::EntryField::FieldType fieldType );
        KCompletion* completion( BibTeX::EntryField::FieldType fieldType );
        KCompletion* completionMacro;

        // Keyword list
        QStringList keyword_GlobalList;

        // Online Database Search;
        int webQuery_LastEngine;
        QString webQuery_LastSearchTerm;
        int webQuery_LastNumberOfResults;
        bool webQuery_ImportAll;

        // Current BibTeX file
        BibTeX::File *currentBibTeXFile;

        void restoreDefaultSearchURLs();

        QString detectLyXInPipe();

        // web query history/default values
        QString getWebQueryDefault( const QString &key );
        void setWebQueryDefault( const QString &key, const QString& value );

        // characters that do match this regexp are
        // not allowed in entry ids or macro keys
        static const QRegExp noIdChars;

        /** Create backup of file as specified in fileIO_NumberOfBackups */
        bool createBackup( const KURL &url, QWidget *window = NULL );

    private:
        static Settings* staticSettings;
        KCompletion **m_completion;
        static QStringList m_lyxRcFileNames;

        QMap<QString, QString> m_webQueryDefaults;

        Settings();
        ~Settings();

        bool checkExternalToolAvailable( const QString &binary );
        void checkExternalToolsAvailable();

        int completionFieldTypeToIndex( BibTeX::EntryField::FieldType fieldType );
    };
}

#endif