projectoptions.cpp 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. /*
  2. ktigcc - TIGCC IDE for KDE
  3. Copyright (C) 2004-2007 Kevin Kofler
  4. Copyright (C) 2006 Joey Adams
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software Foundation,
  15. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  16. */
  17. #include "projectoptions.h"
  18. #include <qvariant.h>
  19. #include <qimage.h>
  20. #include <qpixmap.h>
  21. #include <q3accel.h>
  22. #include <kmessagebox.h>
  23. #include <kfiledialog.h>
  24. #include <kprocess.h>
  25. #include "ktigcc.h"
  26. #include "tpr.h"
  27. #include "programoptions.h"
  28. ProgramOptions *programoptions;
  29. //the program options subdialog is created at initialization of a ProjectOptions and remains existant until the ProjectOptions is destroyed.
  30. void ProjectOptions::init()
  31. {
  32. if (!have_fargo) FargoProgram->hide();
  33. if (!have_flashos) FlashOperatingSystem->hide();
  34. //Create the Program Options dialog
  35. programoptions=new ProgramOptions(this);
  36. //Toggle controls to match settings.
  37. ImportSettings();
  38. //Update stuff
  39. CheckOncalcNames();
  40. UpdateVisibilities();
  41. }
  42. void ProjectOptions::destroy()
  43. {
  44. //Save settings
  45. if (result()==QDialog::Accepted)
  46. ExportSettings();
  47. delete(programoptions);
  48. }
  49. void ProjectOptions::ImportSettings(void)
  50. {
  51. Boolean isregular;
  52. //Tab: General
  53. OncalcVariableName_1->setText(settings.data_var);
  54. if (settings.copy_data_var)
  55. {
  56. if (settings.copy_data_var_arc)
  57. CreateCopyIfArchived->setChecked(TRUE);
  58. else
  59. CreateCopyAlways->setChecked(TRUE);
  60. }
  61. OncalcVariableName_2->setText(settings.pack_name);
  62. isregular=TRUE;
  63. if (settings.fargo)
  64. FargoProgram->setChecked(TRUE),isregular=FALSE;
  65. if (settings.flash_os)
  66. FlashOperatingSystem->setChecked(TRUE),isregular=FALSE;
  67. if (settings.archive)
  68. FunctionArchive->setChecked(TRUE),isregular=FALSE;
  69. if (isregular)
  70. {
  71. if (settings.use_data_var)
  72. {
  73. ExternalDataVariable->setChecked(TRUE);
  74. LOncalcVariableName_1->setEnabled(TRUE);
  75. OncalcVariableName_1->setEnabled(TRUE);
  76. LCreateCopyNever->setEnabled(TRUE);
  77. CreateCopyNever->setEnabled(TRUE);
  78. CreateCopyIfArchived->setEnabled(TRUE);
  79. CreateCopyAlways->setEnabled(TRUE);
  80. }
  81. if (settings.pack)
  82. {
  83. CompressProgram->setChecked(TRUE);
  84. LOncalcVariableName_2->setEnabled(TRUE);
  85. OncalcVariableName_2->setEnabled(TRUE);
  86. }
  87. }
  88. else
  89. {
  90. ExternalDataVariable->setEnabled(FALSE);
  91. CompressProgram->setEnabled(FALSE);
  92. }
  93. //Tab: Compilation
  94. GCCSwitches->setText(settings.cc_switches);
  95. AsSwitches->setText(settings.as_switches);
  96. A68kSwitches->setText(settings.a68k_switches);
  97. GenerateDebugInformation->setChecked(settings.debug_info);
  98. //Tab: Linking
  99. NOPs->setChecked(settings.optimize_nops);
  100. ReturnSequences->setChecked(settings.optimize_returns);
  101. Branches->setChecked(settings.optimize_branches);
  102. MoveLoadPushInstructions->setChecked(settings.optimize_moves);
  103. TestCompareInstructions->setChecked(settings.optimize_tests);
  104. CalculationInstructions->setChecked(settings.optimize_calcs);
  105. RemoveUnusedSections->setChecked(settings.remove_unused);
  106. ReorderSections->setChecked(settings.reorder_sections);
  107. CutUnusedRanges->setChecked(settings.cut_ranges);
  108. MergeConstants->setChecked(settings.merge_constants);
  109. LinkAgainstStandardLibrary->setChecked(settings.std_lib);
  110. InitializeBSSSection->setChecked(settings.initialize_bss);
  111. OutputVariableImageWithoutWrapper->setChecked(settings.outputbin);
  112. //Tab: Post-Build
  113. CallAfterBuilding->setText(settings.post_build);
  114. Parameters->setText(settings.cmd_line);
  115. programoptions->ImportSettings();
  116. }
  117. void ProjectOptions::ExportSettings(void)
  118. {
  119. //Tab: General
  120. settings.fargo=FALSE;
  121. settings.flash_os=FALSE;
  122. settings.archive=FALSE;
  123. settings.use_data_var=FALSE;
  124. settings.pack=FALSE;
  125. if (FargoProgram->isChecked())
  126. settings.fargo=TRUE;
  127. else if (FlashOperatingSystem->isChecked())
  128. settings.flash_os=TRUE;
  129. else if (FunctionArchive->isChecked())
  130. settings.archive=TRUE;
  131. else if (RegularProgram->isChecked()) //the original TIGCC IDE automatically unchecked External data variable and Compress program when you toggled away from Regular Program, so we will only consider these two if Regular Program is toggled
  132. {
  133. if (ExternalDataVariable->isChecked())
  134. settings.use_data_var=TRUE;
  135. if (CompressProgram->isChecked())
  136. settings.pack=TRUE;
  137. }
  138. //Subselections for External data variable and Compress program are always preserved.
  139. settings.data_var=OncalcVariableName_1->text();
  140. settings.copy_data_var_arc=FALSE;
  141. if (CreateCopyNever->isChecked())
  142. settings.copy_data_var=FALSE;
  143. else
  144. {
  145. settings.copy_data_var=TRUE;
  146. if (CreateCopyIfArchived->isChecked())
  147. settings.copy_data_var_arc=TRUE;
  148. }
  149. settings.pack_name=OncalcVariableName_2->text();
  150. //Tab: Compilation
  151. settings.cc_switches=GCCSwitches->text();
  152. settings.as_switches=AsSwitches->text();
  153. settings.a68k_switches=A68kSwitches->text();
  154. settings.debug_info=GenerateDebugInformation->isChecked();
  155. //Tab: Linking
  156. settings.optimize_nops=NOPs->isChecked();
  157. settings.optimize_returns=ReturnSequences->isChecked();
  158. settings.optimize_branches=Branches->isChecked();
  159. settings.optimize_moves=MoveLoadPushInstructions->isChecked();
  160. settings.optimize_tests=TestCompareInstructions->isChecked();
  161. settings.optimize_calcs=CalculationInstructions->isChecked();
  162. settings.remove_unused=RemoveUnusedSections->isChecked();
  163. settings.reorder_sections=ReorderSections->isChecked();
  164. settings.cut_ranges=CutUnusedRanges->isChecked();
  165. settings.merge_constants=MergeConstants->isChecked();
  166. settings.std_lib=LinkAgainstStandardLibrary->isChecked();
  167. settings.initialize_bss=InitializeBSSSection->isChecked();
  168. settings.outputbin=OutputVariableImageWithoutWrapper->isChecked();
  169. //Tab: Post-Build
  170. settings.post_build=CallAfterBuilding->text();
  171. settings.cmd_line=Parameters->text();
  172. programoptions->ExportSettings();
  173. }
  174. void ProjectOptions::RegularProgram_toggled(bool state)
  175. {
  176. if (!state)
  177. {
  178. ExternalDataVariable->setChecked(FALSE);
  179. CompressProgram->setChecked(FALSE);
  180. ExternalDataVariable_toggled(FALSE);
  181. CompressProgram_toggled(FALSE);
  182. }
  183. ExternalDataVariable->setEnabled(state);
  184. CompressProgram->setEnabled(state);
  185. }
  186. void ProjectOptions::ExternalDataVariable_toggled(bool state)
  187. {
  188. LOncalcVariableName_1->setEnabled(state);
  189. OncalcVariableName_1->setEnabled(state);
  190. LCreateCopyNever->setEnabled(state);
  191. CreateCopyNever->setEnabled(state);
  192. CreateCopyIfArchived->setEnabled(state);
  193. CreateCopyAlways->setEnabled(state);
  194. CheckOncalcNames();
  195. }
  196. void ProjectOptions::CompressProgram_toggled(bool state)
  197. {
  198. LOncalcVariableName_2->setEnabled(state);
  199. OncalcVariableName_2->setEnabled(state);
  200. CheckOncalcNames();
  201. }
  202. void ProjectOptions::CheckOncalcNames()
  203. {
  204. const QString &edvname=OncalcVariableName_1->text();
  205. const QString &compname=OncalcVariableName_2->text();
  206. Boolean edvon=OncalcVariableName_1->isEnabled();
  207. Boolean compon=OncalcVariableName_2->isEnabled();
  208. if ((edvon&&edvname.isEmpty()) || (compon&&compname.isEmpty()) || (edvon&&compon&&!edvname.compare(compname)))
  209. buttonOk->setEnabled(FALSE);
  210. else
  211. buttonOk->setEnabled(TRUE);
  212. }
  213. void ProjectOptions::UpdateVisibilities()
  214. {
  215. Boolean regularprogram=RegularProgram->isChecked();
  216. Boolean functionarchive=FunctionArchive->isChecked();
  217. if (regularprogram)
  218. ProgramOptionsButton->show();
  219. else
  220. ProgramOptionsButton->hide();
  221. PO_TabWidget->setTabEnabled(PO_TabWidget->page(2),!functionarchive);
  222. PO_TabWidget->setTabEnabled(PO_TabWidget->page(3),!functionarchive);
  223. }
  224. void ProjectOptions::ProgramOptionsFunc()
  225. {
  226. programoptions->exec();
  227. }
  228. void ProjectOptions::browseButton_clicked()
  229. {
  230. QString ret=KFileDialog::getOpenFileName("/usr/bin",
  231. "application/x-executable application/x-executable-script",this,
  232. "Choose executable");
  233. if (!ret.isEmpty())
  234. CallAfterBuilding->setText(KProcess::quote(ret)+" \"($TI89File)\" \"($TI92PlusFile)\" \"($V200File)\"");
  235. }
  236. /*
  237. * Constructs a ProjectOptions as a child of 'parent', with the
  238. * name 'name' and widget flags set to 'f'.
  239. *
  240. * The dialog will by default be modeless, unless you set 'modal' to
  241. * true to construct a modal dialog.
  242. */
  243. ProjectOptions::ProjectOptions(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl)
  244. : QDialog(parent, name, modal, fl)
  245. {
  246. setupUi(this);
  247. init();
  248. }
  249. /*
  250. * Destroys the object and frees any allocated resources
  251. */
  252. ProjectOptions::~ProjectOptions()
  253. {
  254. destroy();
  255. // no need to delete child widgets, Qt does it all for us
  256. }
  257. /*
  258. * Sets the strings of the subwidgets using the current
  259. * language.
  260. */
  261. void ProjectOptions::languageChange()
  262. {
  263. retranslateUi(this);
  264. }