Fix refactoring issue; only do an ls once
[vng.git] / Configuration.h
blob8e72796cb18b1343f57e6c75cb87619c5a05a2dd
1 /*
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 #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"
29 class Configuration {
30 public:
31 /// creates a simple configuration object which does not check for section specific settings.
32 Configuration();
33 /**
34 * Creates a Configuration object which is initialized with settings from for the section.
35 * If the user has settings in his user-wide-profile for the section passed, these will
36 * be read and made available using the contains() and optionArgument() methods.
37 * @param section the command-name which this configuration object will link to.
39 Configuration(const QString &section);
41 QString section() const { return m_section; }
43 /**
44 * returns true if the option was found in the configuration files.
45 * @see optionArgument()
47 bool contains(const QString & key) const;
48 /**
49 * Return the argument passed to an option.
50 * @see contains()
52 QString optionArgument(const QString &optionName, const QString &defaultValue = QString()) const;
54 /// return the base directory of this repository.
55 QDir repository() const;
56 /// returns the directory where the database and other meta data is stored.
57 QDir repositoryMetaDir() const;
59 /**
60 * Returns true if the current terminal supports colors.
61 * You normally want to just call colorize() and related methods.
62 * @see colorize(), colorize2(), normalColor()
64 bool colorTerm() const;
67 /**
68 * In case the current terminal is a colorTerm() this method will make the stream use a color.
69 * @see normalColor()
71 inline void colorize(QTextStream &stream) const {
72 if (colorTerm())
73 stream << QChar(27) << '[' << 34 << 'm'; // to blue
76 /**
77 * In case the current terminal is a colorTerm() this method will make the stream use a strong color.
78 * @see normalColor()
80 inline void colorize2(QTextStream &stream) const {
81 if (colorTerm())
82 stream << QChar(27) << '[' << 31 << 'm'; // to red
85 /**
86 * Reset the terminal color to normal.
87 * @see colorize()
89 inline void normalColor(QTextStream &stream) const {
90 if (colorTerm())
91 stream << QChar(27) << '[' << 0 << 'm'; // reset
94 /// returns true when there is a repository, but it has not had its initial commit yet.
95 bool isEmptyRepo() const;
97 /**
98 * When this returns true this repo requres 'vng edit' before editing a file.
99 * If this is true all repository-query features will only work on files that are opened for edit.
101 bool useEditMode() const;
103 void setEditMode(bool enabled);
105 /// return the list of files that are currently being edited. Only relevant if useEditMode() returns true.
106 QList<QByteArray> editedFiles();
107 void addEditedFiles(const QList<QByteArray> &newFileNames);
108 void removeEditedFiles(const QList<QByteArray> &fileNames);
109 /// convenience method.
110 void addEditedFiles(const QStringList &newFileNames);
111 /// convenience method.
112 void removeEditedFiles(const QStringList &fileNames);
114 /// return the branches in the current repo.
115 QList<Branch> allBranches();
116 /// return the branches in the current repo.
117 QList<Branch> branches();
118 /// return the branches in the current repo.
119 QList<Branch> remoteBranches();
121 private:
122 void readConfig();
123 void fetchBranches();
125 QDir m_repoDir;
126 QDir m_repoMetaDataDir;
127 QString m_section;
128 bool m_dirty, m_emptyRepo, m_fetchedBranches;
129 QHash<QString, QString> m_options;
130 QList<Branch> m_localBranches;
131 QList<Branch> m_remoteBranches;
133 enum TryState {
134 StateUnknown,
135 StateTrue,
136 StateFalse
138 QMutex m_editedFilesLock;
139 QList<QByteArray> m_editedFiles;
140 bool m_editedFilesFetched;
141 TryState m_editMode;
144 #endif