KWWidgets
vtkKWFileBrowserUtilities.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Module: $RCSfile: vtkKWFileBrowserUtilities.h,v $
4 
5  Copyright (c) Kitware, Inc.
6  All rights reserved.
7  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without even
10  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  PURPOSE. See the above copyright notice for more information.
12 
13 =========================================================================*/
14 // .NAME vtkKWFileBrowserUtilities - some constants
15 // This work is part of the National Alliance for Medical Image
16 // Computing (NAMIC), funded by the National Institutes of Health
17 // through the NIH Roadmap for Medical Research, Grant U54 EB005149.
18 // Information on the National Centers for Biomedical Computing
19 // can be obtained from http://nihroadmap.nih.gov/bioinformatics.
20 
21 #ifndef __vtkKWFileBrowserUtilities_h
22 #define __vtkKWFileBrowserUtilities_h
23 
24 #include <vtksys/SystemTools.hxx>
25 #include <vtksys/stl/string>
26 
27 #ifdef _WIN32
28 #define KWFileBrowser_PATH_SEPARATOR "\\"
29 #else
30 #define KWFileBrowser_PATH_SEPARATOR "/"
31 #endif
32 
33 #define KWFileBrowser_UNIX_ROOT_DIRECTORY "/"
34 #define KWFileBrowser_ESCAPE_CHARS "{}[]$\"\\"
35 #define VTK_KW_FAVORITE_TOPLEVEL "KWFileBrowserFavorites"
36 
37 static char* KWFileBrowser_GetUnixPath(const char* path)
38 {
39  if(path && *path)
40  {
41  vtksys_stl::string sBuffer = path;
42  vtksys::SystemTools::ConvertToUnixSlashes(sBuffer);
43  static char buffer[512];
44  strcpy(buffer, sBuffer.c_str());
45  return buffer;
46  }
47  return NULL;
48 };
49 
50 static int KWFileBrowser_HasTrailingSlash(const char *dir)
51 {
52  size_t dir_len = strlen(dir);
53  int has_slash =
54  (dir_len && (dir[dir_len - 1] == '/' || dir[dir_len - 1] == '\\'));
55 
56  return has_slash;
57 };
58 
59 static bool KWFileBrowser_ComparePath(const char *dir1, const char* dir2)
60 {
61  if(!dir1 || !dir2)
62  {
63  return false;
64  }
65  vtksys_stl::string path1 = dir1;
66  vtksys_stl::string path2 = dir2;
67  int dirslash1 = KWFileBrowser_HasTrailingSlash(dir1);
68  int dirslash2 = KWFileBrowser_HasTrailingSlash(dir2);
69  if(!dirslash1 && dirslash2)
70  {
71  path1 += "/";
72  }
73  else if(dirslash1 && !dirslash2)
74  {
75  path2 += "/";
76  }
77  vtksys::SystemTools::ConvertToUnixSlashes(path1);
78  vtksys::SystemTools::ConvertToUnixSlashes(path2);
79  return vtksys::SystemTools::ComparePath(path1.c_str(), path2.c_str());
80 };
81 
82 #endif