toolprops.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. ktigcc - TIGCC IDE for KDE
  3. Copyright (C) 2006-2007 Kevin Kofler
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software Foundation,
  14. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #include "toolprops.h"
  17. #include <QVariant>
  18. #include <QImage>
  19. #include <QPixmap>
  20. #include <ktextedit.h>
  21. #include <kurl.h>
  22. #include <kurlrequester.h>
  23. #include <kfiledialog.h>
  24. #include <kprocess.h>
  25. #include "ktigcc.h"
  26. void ToolProperties::init()
  27. {
  28. if (toolIndex>=0) {
  29. Tool &tool=tempTools[toolIndex];
  30. toolTitle->setText(tool.title);
  31. commandLine->setText(tool.commandLine);
  32. if (!tool.workingDirectory.isEmpty())
  33. workingDirectory->setUrl(KUrl(tool.workingDirectory));
  34. runInTerminal->setChecked(tool.runInTerminal);
  35. }
  36. }
  37. void ToolProperties::accept()
  38. {
  39. Tool tool(toolTitle->text(),commandLine->text(),
  40. workingDirectory->url().isEmpty()?QString():
  41. KUrl(workingDirectory->url()).path(),runInTerminal->isChecked());
  42. if (toolIndex>=0)
  43. tempTools[toolIndex]=tool;
  44. else
  45. tempTools.append(tool);
  46. QDialog::accept();
  47. }
  48. void ToolProperties::validate()
  49. {
  50. okButton->setEnabled(!toolTitle->text().isEmpty()
  51. && !commandLine->text().isEmpty()
  52. && (workingDirectory->url().isEmpty()
  53. || (KUrl(workingDirectory->url()).isValid()
  54. && KUrl(workingDirectory->url()).isLocalFile())));
  55. }
  56. void ToolProperties::browseButton_clicked()
  57. {
  58. QString ret=KFileDialog::getOpenFileName(KUrl("/usr/bin"),
  59. "application/x-executable application/x-executable-script",this,
  60. "Choose executable");
  61. if (!ret.isEmpty())
  62. commandLine->setText(KProcess::quote(ret));
  63. }
  64. /*
  65. * Constructs a ToolProperties as a child of 'parent', with the
  66. * name 'name' and widget flags set to 'f'.
  67. *
  68. * The dialog will by default be modeless, unless you set 'modal' to
  69. * true to construct a modal dialog.
  70. */
  71. ToolProperties::ToolProperties(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl)
  72. : QDialog(parent, name, modal, fl)
  73. {
  74. setupUi(this);
  75. init();
  76. }
  77. /*
  78. * Destroys the object and frees any allocated resources
  79. */
  80. ToolProperties::~ToolProperties()
  81. {
  82. // no need to delete child widgets, Qt does it all for us
  83. }
  84. /*
  85. * Sets the strings of the subwidgets using the current
  86. * language.
  87. */
  88. void ToolProperties::languageChange()
  89. {
  90. retranslateUi(this);
  91. }