1
/***************************************************************************
2
* Copyright (C) 2004-2010 by Thomas Fischer *
3
* fischer@unix-ag.uni-kl.de *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
***************************************************************************/
22
#include <KStandardDirs>
23
#include <KSharedConfig>
24
#include <KConfigGroup>
29
#include "bibtexentries.h"
31
static const int BibTeXEntriesMax = 256;
33
class BibTeXEntries::BibTeXEntriesPrivate
38
KConfig *systemDefaultsConfig;
39
KSharedConfigPtr userConfig;
41
static BibTeXEntries *singleton;
43
BibTeXEntriesPrivate(BibTeXEntries *parent)
45
systemDefaultsConfig = new KConfig(KStandardDirs::locate("appdata", "entrytypes.rc"), KConfig::SimpleConfig);
46
userConfig = KSharedConfig::openConfig(KStandardDirs::locateLocal("appdata", "entrytypes.rc"), KConfig::SimpleConfig);
49
~BibTeXEntriesPrivate() {
50
delete systemDefaultsConfig;
57
// TODO: Dummy implementation
60
for (int col = 1; col < BibTeXEntriesMax; ++col) {
61
QString groupName = QString("EntryType%1").arg(col);
62
KConfigGroup usercg(userConfig, groupName);
63
KConfigGroup systemcg(systemDefaultsConfig, groupName);
65
ed.upperCamelCase = systemcg.readEntry("UpperCamelCase", "");
66
ed.upperCamelCase = usercg.readEntry("UpperCamelCase", ed.upperCamelCase);
67
if (ed.upperCamelCase.isEmpty()) continue;
68
ed.upperCamelCaseAlt = systemcg.readEntry("UpperCamelCaseAlt", "");
69
ed.upperCamelCaseAlt = usercg.readEntry("UpperCamelCaseAlt", ed.upperCamelCaseAlt);
70
ed.label = systemcg.readEntry("Label", ed.upperCamelCase);;
71
ed.label = usercg.readEntry("Label", ed.label);;
77
BibTeXEntries *BibTeXEntries::BibTeXEntriesPrivate::singleton = NULL;
80
BibTeXEntries::BibTeXEntries()
81
: d(new BibTeXEntriesPrivate(this))
86
BibTeXEntries::~BibTeXEntries()
91
BibTeXEntries* BibTeXEntries::self()
93
if (BibTeXEntriesPrivate::singleton == NULL)
94
BibTeXEntriesPrivate::singleton = new BibTeXEntries();
95
return BibTeXEntriesPrivate::singleton;
98
QString BibTeXEntries::format(const QString& name, KBibTeX::Casing casing) const
100
QString iName = name.toLower();
103
case KBibTeX::cLowerCase: return iName;
104
case KBibTeX::cUpperCase: return name.toUpper();
105
case KBibTeX::cInitialCapital:
106
iName[0] = iName[0].toUpper();
108
case KBibTeX::cLowerCamelCase: {
109
for (ConstIterator it = begin(); it != end(); ++it) {
110
/// configuration file uses camel-case
111
QString itName = (*it).upperCamelCase.toLower();
112
if (itName == iName && (*it).upperCamelCase == QString::null) {
113
iName = (*it).upperCamelCase;
118
/// make an educated guess how camel-case would look like
119
iName[0] = iName[0].toLower();
122
case KBibTeX::cUpperCamelCase: {
123
for (ConstIterator it = begin(); it != end(); ++it) {
124
/// configuration file uses camel-case
125
QString itName = (*it).upperCamelCase.toLower();
126
if (itName == iName && (*it).upperCamelCase == QString::null) {
127
iName = (*it).upperCamelCase;
132
/// make an educated guess how camel-case would look like
133
iName[0] = iName[0].toUpper();
140
QString BibTeXEntries::label(const QString& name) const
142
const QString iName = name.toLower();
144
for (ConstIterator it = begin(); it != end(); ++it) {
145
/// configuration file uses camel-case
146
QString itName = (*it).upperCamelCase.toLower();
147
if (itName == iName || (!(itName = (*it).upperCamelCaseAlt.toLower()).isEmpty() && itName == iName))
150
return QString::null;