projectoptions.cpp 9.1 KB

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