comparison common.cpp @ 79:aaeabc920ca8

* Some work toward doing the Right Thing with each possible combination of existing/nonexisting directories in Open dialog
author Chris Cannam
date Mon, 22 Nov 2010 12:30:40 +0000
parents 07405f3a428b
children 32fa40c3d174
comparison
equal deleted inserted replaced
78:07405f3a428b 79:aaeabc920ca8
175 default: 175 default:
176 exit(0); 176 exit(0);
177 } 177 }
178 #endif 178 #endif
179 } 179 }
180
181 FolderStatus getFolderStatus(QString path)
182 {
183 QFileInfo fi(path);
184 if (fi.exists()) {
185 QDir dir(path);
186 if (!dir.exists()) { // returns false for files
187 return FolderIsFile;
188 }
189 if (QDir(dir.filePath(".hg")).exists()) {
190 return FolderHasRepo;
191 }
192 return FolderExists;
193 } else {
194 QDir parent = fi.dir();
195 if (parent.exists()) {
196 return FolderParentExists;
197 }
198 return FolderUnknown;
199 }
200 }
201
202 QString getContainingRepoFolder(QString path)
203 {
204 if (getFolderStatus(path) == FolderHasRepo) return "";
205
206 QFileInfo me(path);
207 QFileInfo parent(me.dir().absolutePath());
208
209 while (me != parent) {
210 QString parentPath = parent.filePath();
211 if (getFolderStatus(parentPath) == FolderHasRepo) {
212 return parentPath;
213 }
214 me = parent;
215 parent = me.dir().absolutePath();
216 }
217
218 return "";
219 }
220
221 QString xmlEncode(QString s)
222 {
223 s
224 .replace("&", "&")
225 .replace("<", "&lt;")
226 .replace(">", "&gt;")
227 .replace("\"", "&quot;")
228 .replace("'", "&apos;");
229
230 return s;
231 }