File indexing completed on 2024-04-28 16:01:31
0001 /****************************************************************************** 0002 * This file is part of the libqgit2 library 0003 * Copyright (c) 2012 Laszlo Papp <djszapi@archlinux.us> 0004 * Copyright (C) 2013 Leonardo Giordani 0005 * 0006 * This library is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU Lesser General Public 0008 * License as published by the Free Software Foundation; either 0009 * version 2.1 of the License, or (at your option) any later version. 0010 * 0011 * This library is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 * Lesser General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU Lesser General Public 0017 * License along with this library; if not, write to the Free Software 0018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 0019 */ 0020 0021 #ifndef LIBQGIT2_CONFIG_H 0022 #define LIBQGIT2_CONFIG_H 0023 0024 #include <QtCore/QVariant> 0025 0026 #include "git2.h" 0027 0028 #include "libqgit2_export.h" 0029 0030 #include "qgitrepository.h" 0031 0032 namespace LibQGit2 0033 { 0034 /** 0035 * @brief Represents the git configuration file. 0036 * 0037 * @ingroup LibQGit2 0038 * @{ 0039 */ 0040 class LIBQGIT2_EXPORT Config 0041 { 0042 public: 0043 /** 0044 * Default constructor to create a new configuration object. 0045 * 0046 * @param cfg when given, the instance is used instead of creating a new one 0047 */ 0048 Config(git_config *cfg = 0); 0049 Config(const Config &other); 0050 virtual ~Config(); 0051 0052 /** 0053 * Creates a new configuration object and adds the global Git configuration when found. 0054 * Otherwise an empty configuration object is created. 0055 * 0056 * @return the new instance 0057 */ 0058 static Config fromGlobalConfig(); 0059 0060 /** 0061 * Appends a config file with the given access priority. 0062 * 0063 * @param path the absolute path to the config file 0064 * @param priority the access priority; values with higher priority are accessed first 0065 * @param repo optional repository to allow parsing of conditional includes 0066 * @param force replace config file at the given priority level 0067 * 0068 * @return true on success 0069 */ 0070 bool append(const QString& path, git_config_level_t level, const Repository &repo = Repository(), bool force = false); 0071 0072 /** 0073 * Reads a single value from the configuration. 0074 * 0075 * @return the value as QVariant or an empty QVariant instance 0076 */ 0077 QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const; 0078 0079 /** 0080 * Writes a value in the configuration with the highest priority. 0081 * 0082 * @param key the name of the value to write 0083 * @param value the value 0084 * 0085 * @todo handle the QVariant type correctly 0086 */ 0087 void setValue(const QString &key, const QVariant &value); 0088 0089 /** 0090 * Remove a value from the configuration. 0091 * 0092 * @param key the name for the value to remove 0093 */ 0094 void remove(const QString &key); 0095 0096 public: 0097 /** 0098 * Searches for the global configuration file located in $HOME. 0099 * @see git_config_find_global 0100 */ 0101 static QString findGlobal(); 0102 0103 /** 0104 * Searches for the system configuration file. 0105 * @see git_config_find_system 0106 */ 0107 static QString findSystem(); 0108 0109 private: 0110 git_config * d; //!< internal pointer to the libgit2 config instance 0111 }; 0112 0113 /**@}*/ 0114 } 0115 0116 #endif // LIBQGIT2_CONFIG_H