1 /* 2 confobj.h Configuration Class Header 3 Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2009 Kriang Lerdsuwanakij 4 email: lerdsuwa@users.sourceforge.net 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, write to the Free Software 18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 */ 20 21 #ifndef __K_CONFOBJ_H 22 #define __K_CONFOBJ_H 23 24 #include "config.h" 25 #include "setupcurses.h" 26 #include "list.h" 27 #include "gzfileio.h" 28 29 #ifdef CLIB_HAVE_REGEX 30 # include <sys/types.h> 31 # include <regex.h> 32 int k_regcomp(regex_t *r, const string &s1, int flags); 33 #endif 34 35 #include CXX__HEADER_climits 36 #include CXX__HEADER_map 37 #include CXX__HEADER_vector 38 39 USING_NAMESPACE_STD; 40 41 enum MountActionType { 42 mountActionSkip = 0, 43 mountActionAll, 44 mountActionTree, 45 mountActionFileList 46 }; 47 48 typedef vector<MountActionType> MountActionOrderType; 49 50 enum ShowNewDirType { 51 showNewDirNo = 0, 52 showNewDirYes, 53 showNewDirMulti 54 }; 55 56 struct DirConfig { 57 string dir; 58 bool regex; 59 60 bool globDot; 61 bool globPath; 62 63 #ifdef CLIB_HAVE_REGEX 64 regex_t regex_buffer; 65 #endif 66 DirConfigDirConfig67 DirConfig(string dir_, bool regex_, bool globDot_, bool globPath_) : 68 dir(dir_), regex(regex_), globDot(globDot_), globPath(globPath_) { 69 70 #ifdef CLIB_HAVE_REGEX 71 k_regcomp(®ex_buffer, dir, REG_EXTENDED); 72 #endif 73 } 74 75 virtual bool operator ==(const DirConfig& d) const { 76 return dir == d.dir && regex == d.regex 77 && globDot == d.globDot 78 && globPath == d.globPath; 79 } 80 virtual bool operator !=(const DirConfig& d) const { 81 return !(*this == d); 82 } ~DirConfigDirConfig83 virtual ~DirConfig() {} 84 }; 85 86 struct MountDirConfig : public DirConfig { 87 MountActionOrderType mountAction; 88 MountDirConfigMountDirConfig89 MountDirConfig(string dir_, bool regex_, bool globDot_, 90 bool globPath_, const MountActionOrderType &mountAction_) : 91 DirConfig(dir_, regex_, globDot_, globPath_), mountAction(mountAction_) {} 92 virtual bool operator ==(const MountDirConfig& d) const { 93 return this->DirConfig::operator ==(d) 94 && mountAction == d.mountAction; 95 } 96 }; 97 98 typedef sptr_list<DirConfig> DirList; 99 typedef sptr<DirConfig> DirItem; 100 typedef sptr_list<MountDirConfig> MountDirList; 101 typedef sptr<MountDirConfig> MountDirItem; 102 103 #define SCAN_MODE_FULL 0 104 #define SCAN_MODE_SMART 1 105 #define SCAN_MODE_PARTIAL 2 106 107 enum KeyBindingType { 108 keyBindingDefault = 0, 109 keyBindingVi, 110 keyBindingEmacs 111 }; 112 113 extern string confLocalFile; 114 115 #define DEFAULT_COLOR INT_MAX /* Must be the same type as 116 in AttrConfig */ 117 struct AttrConfig { 118 COLOR_TYPE colorForeground; 119 COLOR_TYPE colorBackground; 120 ATTR_TYPE colorAttr; 121 ATTR_TYPE bwAttr; 122 }; 123 124 struct KcdConfig { 125 bool cfgQuietFull; 126 bool cfgQuietSmart; 127 bool cfgQuietPartial; 128 129 bool cfgAutoScan; 130 bool cfgSpaceSelect; 131 bool cfgSortTree; 132 bool cfgCaseSensitiveSort; 133 bool cfgGraphicChar; 134 bool cfgScrollBar; 135 136 bool cfgGlobDot; 137 bool cfgGlobPath; 138 139 KeyBindingType cfgKey; 140 141 unsigned cfgShowListThreshold; 142 unsigned cfgFuzzySize; 143 unsigned cfgMouseScrollRate; 144 145 ShowNewDirType cfgShowNewDir; 146 147 AttrConfig cfgAttrNormal; 148 AttrConfig cfgAttrLink; 149 AttrConfig cfgAttrHighlight; 150 AttrConfig cfgAttrURL; 151 AttrConfig cfgAttrHeader; 152 AttrConfig cfgAttrBold; 153 AttrConfig cfgAttrItalic; 154 AttrConfig cfgAttrScrollArrow; 155 AttrConfig cfgAttrScrollBlock; 156 AttrConfig cfgAttrScrollBar; 157 AttrConfig cfgAttrTitle; 158 AttrConfig cfgAttrMore; 159 AttrConfig cfgAttrLinkBold; 160 AttrConfig cfgAttrLinkItalic; 161 AttrConfig cfgAttrHighlightBold; 162 AttrConfig cfgAttrHighlightItalic; 163 164 COLOR_TYPE cfgDefaultBackground; 165 166 DirList *cfgSkipDir; 167 DirList *cfgStartDir; 168 169 DirList *cfgDefaultTree; 170 171 MountDirList *cfgMountDir; 172 173 KcdConfig(); 174 ~KcdConfig(); 175 176 KcdConfig(const KcdConfig &c); 177 KcdConfig& operator=(const KcdConfig &c); 178 179 void ForceQuiet(int forceQuiet); 180 SetAttrKcdConfig181 void SetAttr(AttrConfig &cfg, int colorFg, int colorBg, 182 ATTR_TYPE colorAttr, ATTR_TYPE bwAttr) { 183 cfg.colorForeground = colorFg; 184 cfg.colorBackground = colorBg; 185 cfg.colorAttr = colorAttr; 186 cfg.bwAttr = bwAttr; 187 } 188 }; 189 190 typedef map<string, KcdConfig> configMap; 191 extern KcdConfig kcdConfig; 192 extern KcdConfig defConfig; 193 extern configMap allConfig; 194 195 bool FindSkipDir(const string &str); 196 bool FindStartDir(const string &str); 197 bool FindMountDir(const string &str); 198 199 int k_fnmatch(const string &pattern, const string &str); 200 201 #endif /* __K_CONFOBJ_H */ 202