Fix detecting of binary file status for new files
[vng.git] / src / Configuration.h
blob319c588c8664cd8791fa7e6f61846e3f75d5d81f
1 /*
2 * This file is part of the vng project
3 * Copyright (C) 2008-2009 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 #ifndef CONFIGURATION_H
19 #define CONFIGURATION_H
21 #include <QString>
22 #include <QDir>
23 #include <QHash>
24 #include <QTextStream>
25 #include <QMutex>
27 #include "patches/Branch.h"
28 #include "TrackedBranch.h"
29 #include "RemoteRepo.h"
31 /**
32 * The Configuration represents environment config.
34 class Configuration {
35 public:
36 /**
37 * Creates a Configuration object which is initialized with settings from for the section.
38 * If the user has settings in his user-wide-profile for the section passed, these will
39 * be read and made available using the contains() and optionArgument() methods.
40 * @param section the command-name which this configuration object will link to.
42 Configuration(const char *section);
44 QString section() const { return m_section; }
46 /**
47 * returns true if the option was found in the configuration files.
48 * @see optionArgument()
50 bool contains(const QString & key) const;
51 /**
52 * Return the argument passed to an option.
53 * @see contains()
55 QString optionArgument(const QString &optionName, const QString &defaultValue = QString()) const;
57 /// return the base directory of this repository.
58 QDir repository() const;
59 /// returns the directory where the database and other meta data is stored.
60 QDir repositoryMetaDir() const;
62 /**
63 * Returns true if the current terminal supports colors.
64 * You normally want to just call colorize() and related methods.
65 * @see colorize(), colorize2(), normalColor()
67 bool colorTerm() const;
70 /**
71 * In case the current terminal is a colorTerm() this method will make the stream use a color.
72 * @see normalColor()
74 inline void colorize(QTextStream &stream) const {
75 if (colorTerm())
76 stream << QChar(27) << '[' << 34 << 'm'; // to blue
79 /**
80 * In case the current terminal is a colorTerm() this method will make the stream use a strong color.
81 * @see normalColor()
83 inline void colorize2(QTextStream &stream) const {
84 if (colorTerm())
85 stream << QChar(27) << '[' << 31 << 'm'; // to red
88 /**
89 * Reset the terminal color to normal.
90 * @see colorize()
92 inline void normalColor(QTextStream &stream) const {
93 if (colorTerm())
94 stream << QChar(27) << '[' << 0 << 'm'; // reset
97 /// returns true when there is a repository, but it has not had its initial commit yet.
98 bool isEmptyRepo() const;
99 /// return the branches in the current repo.
100 QList<Branch> allBranches();
101 /// return the local branches in the current repo.
102 QList<Branch> branches();
103 /// return the branches in the current repo.
104 QList<Branch> remoteBranches();
106 /// Allow multiple configuration objects to share discovered data and avoid access to disk
107 void pullConfigDataFrom(const Configuration &other);
109 QList<TrackedBranch> trackedBranches();
110 QList<RemoteRepo> remotes();
112 enum AddStrategy {
113 AddAsDefault,
114 AddNotDefault
117 void addRepo(const RemoteRepo &repo, AddStrategy strategy = AddNotDefault);
119 private:
120 void readVngConfig();
121 void readConfig();
122 void fetchBranches();
124 QDir m_repoDir;
125 QDir m_repoMetaDataDir;
126 QString m_section;
127 bool m_vngConfigRead, m_emptyRepo, m_fetchedBranches;
128 bool m_configRead;
129 QHash<QString, QString> m_options;
130 QList<Branch> m_localBranches;
131 QList<Branch> m_remoteBranches;
132 QList<RemoteRepo> m_remoteRepos;
133 QList<TrackedBranch> m_trackedBranches;
136 #endif