projectoptions.cpp 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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>
  19. #include <QImage>
  20. #include <QPixmap>
  21. #include <QButtonGroup>
  22. #include <kmessagebox.h>
  23. #include <kfiledialog.h>
  24. #include <kshell.h>
  25. #include <kurl.h>
  26. #include "ktigcc.h"
  27. #include "tpr.h"
  28. #include "programoptions.h"
  29. ProgramOptions *programoptions;
  30. //the program options subdialog is created at initialization of a ProjectOptions and remains existant until the ProjectOptions is destroyed.
  31. ProjectOptions::ProjectOptions(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl)
  32. : QDialog(parent, name, modal, fl)
  33. {
  34. setupUi(this);
  35. if (!have_fargo) FargoProgram->hide();
  36. if (!have_flashos) FlashOperatingSystem->hide();
  37. //Create the Program Options dialog
  38. programoptions=new ProgramOptions(this);
  39. //Toggle controls to match settings.
  40. ImportSettings();
  41. //Update stuff
  42. CheckOncalcNames();
  43. UpdateVisibilities();
  44. }
  45. ProjectOptions::~ProjectOptions()
  46. {
  47. //Save settings
  48. if (result()==QDialog::Accepted)
  49. ExportSettings();
  50. delete(programoptions);
  51. }
  52. void ProjectOptions::ImportSettings(void)
  53. {
  54. Boolean isregular;
  55. //Tab: General
  56. QButtonGroup *group=new QButtonGroup(this);
  57. group->addButton(CreateCopyNever);
  58. group->addButton(CreateCopyIfArchived);
  59. group->addButton(CreateCopyAlways);
  60. OncalcVariableName_1->setText(settings.data_var);
  61. if (settings.copy_data_var)
  62. {
  63. if (settings.copy_data_var_arc)
  64. CreateCopyIfArchived->setChecked(TRUE);
  65. else
  66. CreateCopyAlways->setChecked(TRUE);
  67. }
  68. OncalcVariableName_2->setText(settings.pack_name);
  69. isregular=TRUE;
  70. if (settings.fargo)
  71. FargoProgram->setChecked(TRUE),isregular=FALSE;
  72. if (settings.flash_os)
  73. FlashOperatingSystem->setChecked(TRUE),isregular=FALSE;
  74. if (settings.archive)
  75. FunctionArchive->setChecked(TRUE),isregular=FALSE;
  76. if (isregular)
  77. {
  78. RegularProgram->setChecked(TRUE);
  79. if (settings.use_data_var)
  80. {
  81. ExternalDataVariable->setChecked(TRUE);
  82. LOncalcVariableName_1->setEnabled(TRUE);
  83. OncalcVariableName_1->setEnabled(TRUE);
  84. LCreateCopyNever->setEnabled(TRUE);
  85. CreateCopyNever->setEnabled(TRUE);
  86. CreateCopyIfArchived->setEnabled(TRUE);
  87. CreateCopyAlways->setEnabled(TRUE);
  88. }
  89. if (settings.pack)
  90. {
  91. CompressProgram->setChecked(TRUE);
  92. LOncalcVariableName_2->setEnabled(TRUE);
  93. OncalcVariableName_2->setEnabled(TRUE);
  94. }
  95. }
  96. else
  97. {
  98. ExternalDataVariable->setEnabled(FALSE);
  99. CompressProgram->setEnabled(FALSE);
  100. }
  101. //Tab: Compilation
  102. GCCSwitches->setText(settings.cc_switches);
  103. AsSwitches->setText(settings.as_switches);
  104. A68kSwitches->setText(settings.a68k_switches);
  105. GenerateDebugInformation->setChecked(settings.debug_info);
  106. //Tab: Linking
  107. NOPs->setChecked(settings.optimize_nops);
  108. ReturnSequences->setChecked(settings.optimize_returns);
  109. Branches->setChecked(settings.optimize_branches);
  110. MoveLoadPushInstructions->setChecked(settings.optimize_moves);
  111. TestCompareInstructions->setChecked(settings.optimize_tests);
  112. CalculationInstructions->setChecked(settings.optimize_calcs);
  113. RemoveUnusedSections->setChecked(settings.remove_unused);
  114. ReorderSections->setChecked(settings.reorder_sections);
  115. CutUnusedRanges->setChecked(settings.cut_ranges);
  116. MergeConstants->setChecked(settings.merge_constants);
  117. LinkAgainstStandardLibrary->setChecked(settings.std_lib);
  118. InitializeBSSSection->setChecked(settings.initialize_bss);
  119. OutputVariableImageWithoutWrapper->setChecked(settings.outputbin);
  120. //Tab: Post-Build
  121. CallAfterBuilding->setText(settings.post_build);
  122. Parameters->setText(settings.cmd_line);
  123. programoptions->ImportSettings();
  124. }
  125. void ProjectOptions::ExportSettings(void)
  126. {
  127. //Tab: General
  128. settings.fargo=FALSE;
  129. settings.flash_os=FALSE;
  130. settings.archive=FALSE;
  131. settings.use_data_var=FALSE;
  132. settings.pack=FALSE;
  133. if (FargoProgram->isChecked())
  134. settings.fargo=TRUE;
  135. else if (FlashOperatingSystem->isChecked())
  136. settings.flash_os=TRUE;
  137. else if (FunctionArchive->isChecked())
  138. settings.archive=TRUE;
  139. 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
  140. {
  141. if (ExternalDataVariable->isChecked())
  142. settings.use_data_var=TRUE;
  143. if (CompressProgram->isChecked())
  144. settings.pack=TRUE;
  145. }
  146. //Subselections for External data variable and Compress program are always preserved.
  147. settings.data_var=OncalcVariableName_1->text();
  148. settings.copy_data_var_arc=FALSE;
  149. if (CreateCopyNever->isChecked())
  150. settings.copy_data_var=FALSE;
  151. else
  152. {
  153. settings.copy_data_var=TRUE;
  154. if (CreateCopyIfArchived->isChecked())
  155. settings.copy_data_var_arc=TRUE;
  156. }
  157. settings.pack_name=OncalcVariableName_2->text();
  158. //Tab: Compilation
  159. settings.cc_switches=GCCSwitches->text();
  160. settings.as_switches=AsSwitches->text();
  161. settings.a68k_switches=A68kSwitches->text();
  162. settings.debug_info=GenerateDebugInformation->isChecked();
  163. //Tab: Linking
  164. settings.optimize_nops=NOPs->isChecked();
  165. settings.optimize_returns=ReturnSequences->isChecked();
  166. settings.optimize_branches=Branches->isChecked();
  167. settings.optimize_moves=MoveLoadPushInstructions->isChecked();
  168. settings.optimize_tests=TestCompareInstructions->isChecked();
  169. settings.optimize_calcs=CalculationInstructions->isChecked();
  170. settings.remove_unused=RemoveUnusedSections->isChecked();
  171. settings.reorder_sections=ReorderSections->isChecked();
  172. settings.cut_ranges=CutUnusedRanges->isChecked();
  173. settings.merge_constants=MergeConstants->isChecked();
  174. settings.std_lib=LinkAgainstStandardLibrary->isChecked();
  175. settings.initialize_bss=InitializeBSSSection->isChecked();
  176. settings.outputbin=OutputVariableImageWithoutWrapper->isChecked();
  177. //Tab: Post-Build
  178. settings.post_build=CallAfterBuilding->text();
  179. settings.cmd_line=Parameters->text();
  180. programoptions->ExportSettings();
  181. }
  182. void ProjectOptions::RegularProgram_toggled(bool state)
  183. {
  184. if (!state)
  185. {
  186. ExternalDataVariable->setChecked(FALSE);
  187. CompressProgram->setChecked(FALSE);
  188. ExternalDataVariable_toggled(FALSE);
  189. CompressProgram_toggled(FALSE);
  190. }
  191. ExternalDataVariable->setEnabled(state);
  192. CompressProgram->setEnabled(state);
  193. }
  194. void ProjectOptions::ExternalDataVariable_toggled(bool state)
  195. {
  196. LOncalcVariableName_1->setEnabled(state);
  197. OncalcVariableName_1->setEnabled(state);
  198. LCreateCopyNever->setEnabled(state);
  199. CreateCopyNever->setEnabled(state);
  200. CreateCopyIfArchived->setEnabled(state);
  201. CreateCopyAlways->setEnabled(state);
  202. CheckOncalcNames();
  203. }
  204. void ProjectOptions::CompressProgram_toggled(bool state)
  205. {
  206. LOncalcVariableName_2->setEnabled(state);
  207. OncalcVariableName_2->setEnabled(state);
  208. CheckOncalcNames();
  209. }
  210. void ProjectOptions::CheckOncalcNames()
  211. {
  212. const QString &edvname=OncalcVariableName_1->text();
  213. const QString &compname=OncalcVariableName_2->text();
  214. Boolean edvon=OncalcVariableName_1->isEnabled();
  215. Boolean compon=OncalcVariableName_2->isEnabled();
  216. if ((edvon&&edvname.isEmpty()) || (compon&&compname.isEmpty()) || (edvon&&compon&&!edvname.compare(compname)))
  217. buttonOk->setEnabled(FALSE);
  218. else
  219. buttonOk->setEnabled(TRUE);
  220. }
  221. void ProjectOptions::UpdateVisibilities()
  222. {
  223. Boolean regularprogram=RegularProgram->isChecked();
  224. Boolean functionarchive=FunctionArchive->isChecked();
  225. if (regularprogram)
  226. ProgramOptionsButton->show();
  227. else
  228. ProgramOptionsButton->hide();
  229. PO_TabWidget->setTabEnabled(PO_TabWidget->page(2),!functionarchive);
  230. PO_TabWidget->setTabEnabled(PO_TabWidget->page(3),!functionarchive);
  231. }
  232. void ProjectOptions::ProgramOptionsFunc()
  233. {
  234. programoptions->exec();
  235. }
  236. void ProjectOptions::browseButton_clicked()
  237. {
  238. QString ret=KFileDialog::getOpenFileName(KUrl("/usr/bin"),
  239. "application/x-executable application/x-executable-script",this,
  240. "Choose executable");
  241. if (!ret.isEmpty())
  242. CallAfterBuilding->setText(KShell::quoteArg(ret)+" \"($TI89File)\" \"($TI92PlusFile)\" \"($V200File)\"");
  243. }
  244. void ProjectOptions::languageChange()
  245. {
  246. retranslateUi(this);
  247. }