CMakeSetupGUIImplementation.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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. * Insert Properties on the Scroll/Pack widget
  25. */
  26. void
  27. CMakeSetupGUIImplementation
  28. ::InsertProperties( void )
  29. {
  30. for(unsigned int i=0; i<20; i++)
  31. {
  32. std::cout << "new button" << std::endl;
  33. new Fl_Button(30,30*i,100,25,"Azucar");
  34. }
  35. }
  36. /**
  37. * Show the graphic interface
  38. */
  39. void
  40. CMakeSetupGUIImplementation
  41. ::Show( void )
  42. {
  43. dialogWindow->show();
  44. }
  45. /**
  46. * Hide the graphic interface
  47. */
  48. void
  49. CMakeSetupGUIImplementation
  50. ::Close( void )
  51. {
  52. dialogWindow->hide();
  53. }
  54. /**
  55. * Browse for the path to the sources
  56. */
  57. void
  58. CMakeSetupGUIImplementation
  59. ::BrowseForSourcePath( void )
  60. {
  61. const char * path =
  62. fl_file_chooser(
  63. "Path to Sources",
  64. "",
  65. sourcePathTextInput->value() );
  66. if( !path )
  67. {
  68. return;
  69. }
  70. SetSourcePath( path );
  71. }
  72. /**
  73. * Browse for the path to the binaries
  74. */
  75. void
  76. CMakeSetupGUIImplementation
  77. ::BrowseForBinaryPath( void )
  78. {
  79. const char * path =
  80. fl_file_chooser(
  81. "Path to Binaries",
  82. "",
  83. binaryPathTextInput->value() );
  84. if( !path )
  85. {
  86. return;
  87. }
  88. SetBinaryPath( path );
  89. }
  90. /**
  91. * Set the source path
  92. */
  93. void
  94. CMakeSetupGUIImplementation
  95. ::SetSourcePath( const char * path )
  96. {
  97. if( VerifySourcePath( path ) )
  98. {
  99. sourcePathTextInput->value( path );
  100. }
  101. }
  102. /**
  103. * Set the binary path
  104. */
  105. void
  106. CMakeSetupGUIImplementation
  107. ::SetBinaryPath( const char * path )
  108. {
  109. if( VerifyBinaryPath( path ) )
  110. {
  111. binaryPathTextInput->value( path );
  112. }
  113. LoadCacheFromDiskToGUI();
  114. }
  115. /**
  116. * Verify the path to binaries
  117. */
  118. bool
  119. CMakeSetupGUIImplementation
  120. ::VerifyBinaryPath( const char * path )
  121. {
  122. if( !path || strlen(path)==0 )
  123. {
  124. fl_alert("Please select the path to the binaries");
  125. return false;
  126. }
  127. if( !filename_isdir( path ) )
  128. {
  129. fl_alert("%s \n Doesn't exist or is not a directory",path);
  130. return false;
  131. }
  132. return true;
  133. }
  134. /**
  135. * Verify the path to sources
  136. */
  137. bool
  138. CMakeSetupGUIImplementation
  139. ::VerifySourcePath( const char * path )
  140. {
  141. if( !path || strlen(path)==0 )
  142. {
  143. fl_alert("Please select the path to the sources");
  144. return false;
  145. }
  146. if( !filename_isdir( path ) )
  147. {
  148. fl_alert("%s \n Doesn't exist or is not a directory",path);
  149. return false;
  150. }
  151. return true;
  152. }
  153. /**
  154. * Build the project files
  155. */
  156. void
  157. CMakeSetupGUIImplementation
  158. ::BuildProjectFiles( void )
  159. {
  160. // Verify that source path is a valid directory
  161. if( !VerifySourcePath( sourcePathTextInput->value() ) )
  162. {
  163. return;
  164. }
  165. // Verify that binary path is a valid directory
  166. if( !VerifyBinaryPath( binaryPathTextInput->value() ) )
  167. {
  168. return;
  169. }
  170. SaveCacheFromGUI();
  171. fl_message("Building project files ... please wait");
  172. }
  173. /**
  174. * Load Cache from disk to GUI
  175. */
  176. void
  177. CMakeSetupGUIImplementation
  178. ::LoadCacheFromDiskToGUI( void )
  179. {
  180. const char * m_WhereBuild = binaryPathTextInput->value();
  181. if( m_WhereBuild != "" )
  182. {
  183. cmCacheManager::GetInstance()->LoadCache(m_WhereBuild);
  184. // Make sure the internal "CMAKE" cache entry is set.
  185. const char* cacheValue = cmCacheManager::GetInstance()->GetCacheValue("CMAKE");
  186. if(!cacheValue)
  187. {
  188. // Find our own exectuable.
  189. std::string cMakeCMD = "\""+cmSystemTools::GetProgramPath(_pgmptr);
  190. cMakeCMD += "/CMakeSetupCMD.exe\"";
  191. // Save the value in the cache
  192. cmCacheManager::GetInstance()->AddCacheEntry("CMAKE",
  193. cMakeCMD.c_str(),
  194. "Path to CMake executable.",
  195. cmCacheManager::INTERNAL);
  196. }
  197. this->FillCacheGUIFromCacheManager();
  198. }
  199. }
  200. /**
  201. * Save Cache from disk to GUI
  202. */
  203. void
  204. CMakeSetupGUIImplementation
  205. ::SaveCacheFromGUI( void )
  206. {
  207. }
  208. /**
  209. * Fill Cache GUI from cache manager
  210. */
  211. void
  212. CMakeSetupGUIImplementation
  213. ::FillCacheGUIFromCacheManager( void )
  214. {
  215. const cmCacheManager::CacheEntryMap &cache =
  216. cmCacheManager::GetInstance()->GetCacheMap();
  217. for(cmCacheManager::CacheEntryMap::const_iterator i = cache.begin();
  218. i != cache.end(); ++i)
  219. {
  220. const char* key = i->first.c_str();
  221. const cmCacheManager::CacheEntry& value = i->second;
  222. switch(value.m_Type )
  223. {
  224. case cmCacheManager::BOOL:
  225. if(cmCacheManager::GetInstance()->IsOn(key))
  226. {
  227. m_CacheEntriesList.AddProperty(key,
  228. "ON",
  229. value.m_HelpString.c_str(),
  230. fltk::PropertyList::CHECKBOX,"");
  231. }
  232. else
  233. {
  234. m_CacheEntriesList.AddProperty(key,
  235. "OFF",
  236. value.m_HelpString.c_str(),
  237. fltk::PropertyList::CHECKBOX,"");
  238. }
  239. break;
  240. case cmCacheManager::PATH:
  241. m_CacheEntriesList.AddProperty(key,
  242. value.m_Value.c_str(),
  243. value.m_HelpString.c_str(),
  244. fltk::PropertyList::PATH,"");
  245. break;
  246. case cmCacheManager::FILEPATH:
  247. m_CacheEntriesList.AddProperty(key,
  248. value.m_Value.c_str(),
  249. value.m_HelpString.c_str(),
  250. fltk::PropertyList::FILE,"");
  251. break;
  252. case cmCacheManager::STRING:
  253. m_CacheEntriesList.AddProperty(key,
  254. value.m_Value.c_str(),
  255. value.m_HelpString.c_str(),
  256. fltk::PropertyList::EDIT,"");
  257. break;
  258. case cmCacheManager::INTERNAL:
  259. break;
  260. }
  261. }
  262. this->UpdateData(false);
  263. }
  264. /**
  265. * UpdateData
  266. */
  267. void
  268. CMakeSetupGUIImplementation
  269. ::UpdateData( bool option )
  270. {
  271. dialogWindow->redraw();
  272. Fl::check();
  273. }