toolprops.cpp 2.7 KB

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