projectoptions.cpp 8.9 KB

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