2 * This file is part of the vng project
3 * Copyright (C) 2008 Thomas Zander <tzander@trolltech.com>
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 3 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, see <http://www.gnu.org/licenses/>.
18 #include "Configuration.h"
27 Configuration::Configuration(const QString
§ion
)
35 bool Configuration::contains(const QString
& key
) const
37 const_cast<Configuration
*> (this)->readConfig();
38 return m_options
.contains(key
);
41 QDir
Configuration::repository() const
43 const_cast<Configuration
*> (this)->readConfig();
47 void Configuration::readConfig()
52 QObject deleterParent
;
54 QDir dir
= QDir::current();
59 QDir
refs(git
.absoluteFilePath("refs/heads"));
60 m_emptyRepo
= refs
.count() == 2; // only '.' and '..'
65 } while(!dir
.isRoot());
67 QString home
= QDir::homePath();
69 config
= new QFile(home
+ "/.vng/config", &deleterParent
);
70 if (! config
->exists())
71 config
= new QFile(home
+ "/.darcs/defaults", &deleterParent
);
72 if (config
->exists()) {
73 if (! config
->open(QIODevice::ReadOnly
)) {
74 Logger::error() << "Failed to open config file, is it readable?\n";
80 qint64 lineLength
= config
->readLine(buf
, sizeof(buf
));
83 QString line
= QString::fromUtf8(buf
, lineLength
);
85 if (line
.startsWith("ALL "))
86 option
= line
.mid(3).trimmed();
87 else if (line
.length() > m_section
.length() && line
.startsWith(m_section
))
88 option
= line
.mid(m_section
.length()).trimmed();
89 if (! option
.isEmpty()) {
90 const int index
= option
.indexOf(' ');
92 m_options
.insert(option
.left(index
).trimmed(), option
.mid(index
).trimmed());
95 m_options
.insert(option
, QString());
102 QString
Configuration::optionArgument(const QString
&optionName
, const QString
&defaultValue
) const
104 if (m_options
.contains(optionName
))
105 return m_options
[optionName
];
109 bool Configuration::colorTerm() const
113 return QString(getenv("TERM")) != QString("dumb") && !Logger::hasNonColorPager();
118 bool Configuration::isEmptyRepo() const
120 const_cast<Configuration
*> (this)->readConfig();