CMakeSetupGUIImplementation.cxx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. #include "CMakeSetupGUIImplementation.h"
  2. #include "Fl/fl_file_chooser.H"
  3. #include "Fl/filename.H"
  4. #include "Fl/fl_ask.H"
  5. #include "cstring"
  6. #include "../cmCacheManager.h"
  7. #include "../cmMakefile.h"
  8. #include <iostream>
  9. /**
  10. * Constructor
  11. */
  12. CMakeSetupGUIImplementation
  13. ::CMakeSetupGUIImplementation()
  14. {
  15. }
  16. /**
  17. * Destructor
  18. */
  19. CMakeSetupGUIImplementation
  20. ::~CMakeSetupGUIImplementation()
  21. {
  22. }
  23. /**
  24. * Show the graphic interface
  25. */
  26. void
  27. CMakeSetupGUIImplementation
  28. ::Show( void )
  29. {
  30. dialogWindow->show();
  31. }
  32. /**
  33. * Hide the graphic interface
  34. */
  35. void
  36. CMakeSetupGUIImplementation
  37. ::Close( void )
  38. {
  39. dialogWindow->hide();
  40. }
  41. /**
  42. * Browse for the path to the sources
  43. */
  44. void
  45. CMakeSetupGUIImplementation
  46. ::BrowseForSourcePath( void )
  47. {
  48. const char * path =
  49. fl_file_chooser(
  50. "Path to Sources",
  51. "",
  52. sourcePathTextInput->value() );
  53. if( !path )
  54. {
  55. return;
  56. }
  57. SetSourcePath( path );
  58. }
  59. /**
  60. * Browse for the path to the binaries
  61. */
  62. void
  63. CMakeSetupGUIImplementation
  64. ::BrowseForBinaryPath( void )
  65. {
  66. const char * path =
  67. fl_file_chooser(
  68. "Path to Binaries",
  69. "",
  70. binaryPathTextInput->value() );
  71. if( !path )
  72. {
  73. return;
  74. }
  75. SetBinaryPath( path );
  76. }
  77. /**
  78. * Set the source path
  79. */
  80. void
  81. CMakeSetupGUIImplementation
  82. ::SetSourcePath( const char * path )
  83. {
  84. if( VerifySourcePath( path ) )
  85. {
  86. m_WhereSource = path;
  87. sourcePathTextInput->value( path );
  88. }
  89. }
  90. /**
  91. * Set the binary path
  92. */
  93. void
  94. CMakeSetupGUIImplementation
  95. ::SetBinaryPath( const char * path )
  96. {
  97. if( VerifyBinaryPath( path ) )
  98. {
  99. m_WhereBuild = path;
  100. binaryPathTextInput->value( path );
  101. }
  102. LoadCacheFromDiskToGUI();
  103. }
  104. /**
  105. * Verify the path to binaries
  106. */
  107. bool
  108. CMakeSetupGUIImplementation
  109. ::VerifyBinaryPath( const char * path )
  110. {
  111. if( !path || strlen(path)==0 )
  112. {
  113. fl_alert("Please select the path to the binaries");
  114. return false;
  115. }
  116. if( !filename_isdir( path ) )
  117. {
  118. fl_alert("%s \n Doesn't exist or is not a directory",path);
  119. return false;
  120. }
  121. return true;
  122. }
  123. /**
  124. * Verify the path to sources
  125. */
  126. bool
  127. CMakeSetupGUIImplementation
  128. ::VerifySourcePath( const char * path )
  129. {
  130. if( !path || strlen(path)==0 )
  131. {
  132. fl_alert("Please select the path to the sources");
  133. return false;
  134. }
  135. if( !filename_isdir( path ) )
  136. {
  137. fl_alert("%s \n Doesn't exist or is not a directory",path);
  138. return false;
  139. }
  140. return true;
  141. }
  142. /**
  143. * Build the project files
  144. */
  145. void
  146. CMakeSetupGUIImplementation
  147. ::BuildProjectFiles( void )
  148. {
  149. // Verify that source path is a valid directory
  150. if( !VerifySourcePath( sourcePathTextInput->value() ) )
  151. {
  152. return;
  153. }
  154. // Verify that binary path is a valid directory
  155. if( !VerifyBinaryPath( binaryPathTextInput->value() ) )
  156. {
  157. return;
  158. }
  159. SaveCacheFromGUI();
  160. fl_message("Building project files ... please wait");
  161. }
  162. /**
  163. * Load Cache from disk to GUI
  164. */
  165. void
  166. CMakeSetupGUIImplementation
  167. ::LoadCacheFromDiskToGUI( void )
  168. {
  169. if( m_WhereBuild != "" )
  170. {
  171. cmCacheManager::GetInstance()->LoadCache( m_WhereBuild.c_str() );
  172. this->FillCacheGUIFromCacheManager();
  173. }
  174. }
  175. /**
  176. * Save Cache from disk to GUI
  177. */
  178. void
  179. CMakeSetupGUIImplementation
  180. ::SaveCacheFromGUI( void )
  181. {
  182. }
  183. /**
  184. * Fill Cache GUI from cache manager
  185. */
  186. void
  187. CMakeSetupGUIImplementation
  188. ::FillCacheGUIFromCacheManager( void )
  189. {
  190. // Prepare to add rows to the scroll
  191. propertyListPack->begin();
  192. const cmCacheManager::CacheEntryMap &cache =
  193. cmCacheManager::GetInstance()->GetCacheMap();
  194. for(cmCacheManager::CacheEntryMap::const_iterator i = cache.begin();
  195. i != cache.end(); ++i)
  196. {
  197. const char* key = i->first.c_str();
  198. const cmCacheManager::CacheEntry& value = i->second;
  199. switch(value.m_Type )
  200. {
  201. case cmCacheManager::BOOL:
  202. if(cmCacheManager::GetInstance()->IsOn(key))
  203. {
  204. m_CacheEntriesList.AddProperty(key,
  205. "ON",
  206. value.m_HelpString.c_str(),
  207. fltk::PropertyList::CHECKBOX,"");
  208. }
  209. else
  210. {
  211. m_CacheEntriesList.AddProperty(key,
  212. "OFF",
  213. value.m_HelpString.c_str(),
  214. fltk::PropertyList::CHECKBOX,"");
  215. }
  216. break;
  217. case cmCacheManager::PATH:
  218. m_CacheEntriesList.AddProperty(key,
  219. value.m_Value.c_str(),
  220. value.m_HelpString.c_str(),
  221. fltk::PropertyList::PATH,"");
  222. break;
  223. case cmCacheManager::FILEPATH:
  224. m_CacheEntriesList.AddProperty(key,
  225. value.m_Value.c_str(),
  226. value.m_HelpString.c_str(),
  227. fltk::PropertyList::FILE,"");
  228. break;
  229. case cmCacheManager::STRING:
  230. m_CacheEntriesList.AddProperty(key,
  231. value.m_Value.c_str(),
  232. value.m_HelpString.c_str(),
  233. fltk::PropertyList::EDIT,"");
  234. break;
  235. case cmCacheManager::INTERNAL:
  236. break;
  237. }
  238. }
  239. propertyListPack->end();
  240. propertyListPack->init_sizes();
  241. cacheValuesScroll->position( 0, 0 );
  242. this->UpdateData(false);
  243. }
  244. /**
  245. * UpdateData
  246. */
  247. void
  248. CMakeSetupGUIImplementation
  249. ::UpdateData( bool option )
  250. {
  251. dialogWindow->redraw();
  252. Fl::check();
  253. }