KWWidgets
|
00001 /*========================================================================= 00002 00003 Module: $RCSfile: vtkKWFileBrowserUtilities.h,v $ 00004 00005 Copyright (c) Kitware, Inc. 00006 All rights reserved. 00007 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00008 00009 This software is distributed WITHOUT ANY WARRANTY; without even 00010 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00011 PURPOSE. See the above copyright notice for more information. 00012 00013 =========================================================================*/ 00014 // .NAME vtkKWFileBrowserUtilities - some constants 00015 // This work is part of the National Alliance for Medical Image 00016 // Computing (NAMIC), funded by the National Institutes of Health 00017 // through the NIH Roadmap for Medical Research, Grant U54 EB005149. 00018 // Information on the National Centers for Biomedical Computing 00019 // can be obtained from http://nihroadmap.nih.gov/bioinformatics. 00020 00021 #ifndef __vtkKWFileBrowserUtilities_h 00022 #define __vtkKWFileBrowserUtilities_h 00023 00024 #include <vtksys/SystemTools.hxx> 00025 #include <vtksys/stl/string> 00026 00027 #ifdef _WIN32 00028 #define KWFileBrowser_PATH_SEPARATOR "\\" 00029 #else 00030 #define KWFileBrowser_PATH_SEPARATOR "/" 00031 #endif 00032 00033 #define KWFileBrowser_UNIX_ROOT_DIRECTORY "/" 00034 #define KWFileBrowser_ESCAPE_CHARS "{}[]$\"\\" 00035 #define VTK_KW_FAVORITE_TOPLEVEL "KWFileBrowserFavorites" 00036 00037 static char* KWFileBrowser_GetUnixPath(const char* path) 00038 { 00039 if(path && *path) 00040 { 00041 vtksys_stl::string sBuffer = path; 00042 vtksys::SystemTools::ConvertToUnixSlashes(sBuffer); 00043 static char buffer[512]; 00044 strcpy(buffer, sBuffer.c_str()); 00045 return buffer; 00046 } 00047 return NULL; 00048 }; 00049 00050 static int KWFileBrowser_HasTrailingSlash(const char *dir) 00051 { 00052 size_t dir_len = strlen(dir); 00053 int has_slash = 00054 (dir_len && (dir[dir_len - 1] == '/' || dir[dir_len - 1] == '\\')); 00055 00056 return has_slash; 00057 }; 00058 00059 static bool KWFileBrowser_ComparePath(const char *dir1, const char* dir2) 00060 { 00061 if(!dir1 || !dir2) 00062 { 00063 return false; 00064 } 00065 vtksys_stl::string path1 = dir1; 00066 vtksys_stl::string path2 = dir2; 00067 int dirslash1 = KWFileBrowser_HasTrailingSlash(dir1); 00068 int dirslash2 = KWFileBrowser_HasTrailingSlash(dir2); 00069 if(!dirslash1 && dirslash2) 00070 { 00071 path1 += "/"; 00072 } 00073 else if(dirslash1 && !dirslash2) 00074 { 00075 path2 += "/"; 00076 } 00077 vtksys::SystemTools::ConvertToUnixSlashes(path1); 00078 vtksys::SystemTools::ConvertToUnixSlashes(path2); 00079 return vtksys::SystemTools::ComparePath(path1.c_str(), path2.c_str()); 00080 }; 00081 00082 #endif