File indexing completed on 2024-04-21 05:41:01
0001 /* 0002 SPDX-FileCopyrightText: 2011 Vishesh Yadav <vishesh3y@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef HGCONFIG_H 0008 #define HGCONFIG_H 0009 0010 #include <QString> 0011 #include <QProcess> 0012 #include <QMap> 0013 0014 class KConfig; 0015 0016 /** 0017 * Provides a wrapper to read and write Mercurial settings in hgrc files. 0018 * Also provides interface to read/write other settings as well, for which 0019 * a direct function is not provided. 0020 */ 0021 class HgConfig 0022 { 0023 public: 0024 /** 0025 * Type of hgrc file. 0026 * 0027 * RepoConfig: hgrc of the local/current repository. 0028 * GlobalConfig: Global hgrc file. Under *nix, ~/.hgrc file 0029 * TempConfig: A temporary config file, that can be used by some commands 0030 * for just one time. Usually after taking input from user to 0031 * override default settings. 0032 */ 0033 enum ConfigType { 0034 RepoConfig, GlobalConfig, TempConfig 0035 }; 0036 0037 explicit HgConfig(ConfigType configFile); 0038 ~HgConfig(); 0039 0040 // Related to config file 0041 0042 /** 0043 * Return the path of hgrc file currently loaded 0044 */ 0045 QString configFilePath() const; 0046 0047 // Repo specific 0048 0049 /** 0050 * Set path of repository associated with given given alias 0051 */ 0052 void setRepoRemotePath(const QString &alias, const QString &url); 0053 0054 /** 0055 * Delete alias/path of repository associated with given given alias 0056 */ 0057 void deleteRepoRemotePath(const QString &alias); 0058 0059 /** 0060 * Return path of repository associated with given given alias 0061 */ 0062 QString repoRemotePath(const QString &alias) const; 0063 0064 /** 0065 * Return a list of alias-path pair of remote repository paths 0066 */ 0067 QMap<QString, QString> repoRemotePathList() const; 0068 0069 /////////// 0070 0071 /** 0072 * Get the value of a property in a given section. 0073 * 0074 * @param section The settings group in hgrc file. 0075 * @param propertyName Name of the property in section whose value is\ 0076 * required 0077 * @return Value of property in the section given. 0078 */ 0079 QString property(const QString §ion, const QString &propertyName)const; 0080 0081 /** 0082 * Set the value of a property in a given section. 0083 * 0084 * @param section The settings group in hgrc file. 0085 * @param propertyName Name of the property in section whose value is 0086 * to be modified. 0087 * @param propertyValue Value to be set of given property. Deletes the 0088 * entry if empty. 0089 */ 0090 void setProperty(const QString §ion, const QString &propertyName, 0091 const QString &propertyValue); 0092 0093 // user interface section 0094 QString username() const; 0095 void setUsername(const QString &userName); 0096 0097 QString editor() const; 0098 void setEditor(const QString &pathToEditor); 0099 0100 QString merge() const; 0101 void setMerge(const QString &pathToMergeTool); 0102 0103 private: 0104 /** 0105 * Used during construction to determine the path of config files 0106 * based on given ConfigType enum 0107 */ 0108 bool getConfigFilePath(); 0109 bool loadConfig(); 0110 0111 private: 0112 ConfigType m_configType; 0113 QString m_configFilePath; 0114 KConfig *m_config; 0115 0116 }; 0117 0118 #endif //HGCONFIG_H 0119