projectoptions.cpp 9.3 KB

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