toolprops.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 <kshell.h>
  25. #include "ktigcc.h"
  26. ToolProperties::ToolProperties(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl)
  27. : QDialog(parent, name, modal, fl)
  28. {
  29. setupUi(this);
  30. workingDirectory->setMode(KFile::LocalOnly|KFile::ExistingOnly|KFile::Directory);
  31. if (toolIndex>=0) {
  32. Tool &tool=tempTools[toolIndex];
  33. toolTitle->setText(tool.title);
  34. commandLine->setText(tool.commandLine);
  35. if (!tool.workingDirectory.isEmpty())
  36. workingDirectory->setUrl(KUrl(tool.workingDirectory));
  37. runInTerminal->setChecked(tool.runInTerminal);
  38. }
  39. }
  40. ToolProperties::~ToolProperties()
  41. {
  42. }
  43. void ToolProperties::accept()
  44. {
  45. Tool tool(toolTitle->text(),commandLine->text(),
  46. workingDirectory->url().isEmpty()?QString():
  47. KUrl(workingDirectory->url()).path(),runInTerminal->isChecked());
  48. if (toolIndex>=0)
  49. tempTools[toolIndex]=tool;
  50. else
  51. tempTools.append(tool);
  52. QDialog::accept();
  53. }
  54. void ToolProperties::validate()
  55. {
  56. okButton->setEnabled(!toolTitle->text().isEmpty()
  57. && !commandLine->text().isEmpty()
  58. && (workingDirectory->url().isEmpty()
  59. || (KUrl(workingDirectory->url()).isValid()
  60. && KUrl(workingDirectory->url()).isLocalFile())));
  61. }
  62. void ToolProperties::browseButton_clicked()
  63. {
  64. QString ret=KFileDialog::getOpenFileName(KUrl("/usr/bin"),
  65. "application/x-executable application/x-executable-script",this,
  66. "Choose executable");
  67. if (!ret.isEmpty())
  68. commandLine->setText(KShell::quoteArg(ret));
  69. }
  70. void ToolProperties::languageChange()
  71. {
  72. retranslateUi(this);
  73. }