File indexing completed on 2024-12-01 06:51:47
0001 // 0002 // C++ Implementation: cscripteditor 0003 // 0004 // Description: 0005 // 0006 /* 0007 Copyright 2002-2011 Tomas Mecir <kmuddy@kmuddy.com> 0008 0009 This program is free software; you can redistribute it and/or 0010 modify it under the terms of the GNU General Public License as 0011 published by the Free Software Foundation; either version 2 of 0012 the License, or (at your option) any later version. 0013 0014 This program is distributed in the hope that it will be useful, 0015 but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0017 GNU General Public License for more details. 0018 0019 You should have received a copy of the GNU General Public License 0020 along with this program. If not, see <http://www.gnu.org/licenses/>. 0021 */ 0022 0023 #include "cscripteditor.h" 0024 0025 #include "cactionmanager.h" 0026 #include "cprofilemanager.h" 0027 #include "cprofilesettings.h" 0028 0029 #include <QCheckBox> 0030 #include <QGridLayout> 0031 #include <QGroupBox> 0032 #include <QLabel> 0033 #include <QPushButton> 0034 #include <QRegExpValidator> 0035 #include "kfiledialog.h" 0036 #include <klineedit.h> 0037 #include <KLocalizedString> 0038 0039 struct cScriptEditor::Private { 0040 KLineEdit *workdir, *cmd, *sname; 0041 QCheckBox *sendusercommands, *useadvcomm, *singleinstance, *chkflowcontrol, *chkallowvars; 0042 }; 0043 0044 cScriptEditor::cScriptEditor (QWidget *parent) 0045 : cListEditor (parent) 0046 { 0047 d = new Private; 0048 } 0049 0050 cScriptEditor::~cScriptEditor () 0051 { 0052 // the GUI elements will be destroyed automatically 0053 delete d; 0054 } 0055 0056 void cScriptEditor::createGUI(QWidget *parent) 0057 { 0058 QGridLayout *layout = new QGridLayout (parent); 0059 0060 //name 0061 QLabel *label1 = new QLabel (i18n ("Script &name"), parent); 0062 d->sname = new KLineEdit (parent); 0063 d->sname->setValidator (new QRegExpValidator (QRegExp("^[0-9A-Za-z_]+$"), this)); 0064 label1->setBuddy (d->sname); 0065 d->sname->setWhatsThis (i18n ("Name of this script.")); 0066 d->sname->setFocus(); 0067 0068 //command 0069 QLabel *label2 = new QLabel (i18n ("&Command to execute"), parent); 0070 d->cmd = new KLineEdit (parent); 0071 label2->setBuddy (d->cmd); 0072 QPushButton *cmdbutton = new QPushButton (i18n ("Browse..."), parent); 0073 d->cmd->setWhatsThis (i18n ("Command to execute, including parameters. " 0074 "Note that you can specify more parameters when executing the command " 0075 "from the input line, if you enable the Allow parameters checkbox.")); 0076 0077 //workdir 0078 QLabel *label3 = new QLabel (i18n ("&Working directory"), parent); 0079 d->workdir = new KLineEdit (parent); 0080 label3->setBuddy (d->workdir); 0081 QPushButton *wrkbutton = new QPushButton (i18n ("Browse..."), parent); 0082 d->workdir->setWhatsThis (i18n ("Working directory for the script. Script " 0083 "will behave exactly as if it was run from this directory in console.")); 0084 0085 //options groupbox 0086 QGroupBox *options = new QGroupBox (i18n ("&Options"), parent); 0087 QGridLayout *optionsLayout = new QGridLayout (options); 0088 0089 //send user commands 0090 d->sendusercommands = new QCheckBox (i18n ("Send user commands"), options); 0091 d->sendusercommands->setWhatsThis (i18n ("If script input is enabled, " 0092 "this enables sending of all sent commands to the script.")); 0093 //adv.communication 0094 d->useadvcomm = new QCheckBox (i18n ("Enable communication"), options); 0095 d->useadvcomm->setWhatsThis (i18n ("Enables identification of lines of " 0096 "server output. Refer to the manual for more information.")); 0097 //single-instance 0098 d->singleinstance = new QCheckBox (i18n ("Single-instance script"), options); 0099 d->singleinstance->setWhatsThis (i18n ("If an instance of this script " 0100 "is already running, another one can not be started.")); 0101 //no flow control 0102 d->chkflowcontrol = new QCheckBox (i18n ("Use flow control"), options); 0103 d->chkflowcontrol->setWhatsThis (i18n ("<p>If enabled, flow control will " 0104 "be used for this script. Flow control ensures that scripts " 0105 "are kept in sync, that means, that if two lines arrive from the " 0106 "server, the second one is not sent to the scripts until all running " 0107 "scripts have received the first one. However, in some situations, " 0108 "it's better not to use this feature.</p><p>If you don't need to " 0109 "disable flow control for some reason, leave this on.</p>")); 0110 //allow variables 0111 d->chkallowvars = new QCheckBox (i18n ("Communicate variables"), options); 0112 d->chkallowvars->setWhatsThis (i18n ("If enabled, a UNIX domain " 0113 "socket will be created, allowing you to obtain and modify actual " 0114 "variable values. More information in the documentation.")); 0115 optionsLayout->addWidget (d->sendusercommands, 0, 0); 0116 optionsLayout->addWidget (d->useadvcomm, 1, 0); 0117 optionsLayout->addWidget (d->singleinstance, 2, 0); 0118 optionsLayout->addWidget (d->chkflowcontrol, 0, 1); 0119 optionsLayout->addWidget (d->chkallowvars, 1, 1); 0120 0121 //activate Browse... buttons 0122 connect (cmdbutton, SIGNAL (clicked ()), this, SLOT (browse1())); 0123 connect (wrkbutton, SIGNAL (clicked ()), this, SLOT (browse2())); 0124 0125 //place'em there! 0126 layout->setSpacing (5); 0127 layout->addWidget (label1, 0, 0); 0128 layout->addWidget (d->sname, 0, 1, 1, 2); 0129 layout->addWidget (label2, 2, 0); 0130 layout->addWidget (d->cmd, 2, 1); 0131 layout->addWidget (cmdbutton, 2, 2); 0132 layout->addWidget (label3, 3, 0); 0133 layout->addWidget (d->workdir, 3, 1); 0134 layout->addWidget (wrkbutton, 3, 2); 0135 layout->addWidget (options, 4, 0, 1, 3); 0136 } 0137 0138 void cScriptEditor::browse1 () 0139 { 0140 //open some executable and place its name to the edit box 0141 if (!object()) return; 0142 cProfileSettings *sett = cProfileManager::self()->settings (object()->list()->session()); 0143 if (!sett) return; 0144 QString fName = KFileDialog::getOpenFileName 0145 (sett->getString ("script-directory"), QString(), this, i18n ("Choose script")); 0146 if (!(fName.isEmpty())) 0147 d->cmd->setText (fName); 0148 } 0149 0150 void cScriptEditor::browse2 () 0151 { 0152 QString fName = KFileDialog::getExistingDirectory (d->workdir->text(), 0153 this, i18n ("Choose working directory")); 0154 d->workdir->setText (fName); 0155 } 0156 0157 void cScriptEditor::fillGUI (const cListObjectData &data) 0158 { 0159 d->sname->setText (data.name); 0160 d->cmd->setText (data.strValue ("command")); 0161 d->workdir->setText (data.strValue ("work-directory")); 0162 d->sendusercommands->setChecked (data.boolValue ("send-user-commands")); 0163 d->useadvcomm->setChecked (data.boolValue ("adv-comunication")); 0164 d->singleinstance->setChecked (data.boolValue ("single-instance")); 0165 d->chkflowcontrol->setChecked (data.boolValue ("flow-control")); 0166 d->chkallowvars->setChecked (data.boolValue ("enable-variables")); 0167 } 0168 0169 void cScriptEditor::getDataFromGUI (cListObjectData *data) 0170 { 0171 data->name = d->sname->text(); 0172 data->strValues["command"] = d->cmd->text(); 0173 data->strValues["work-directory"] = d->workdir->text(); 0174 data->boolValues["send-user-commands"] = d->sendusercommands->isChecked(); 0175 data->boolValues["adv-comunication"] = d->useadvcomm->isChecked(); 0176 data->boolValues["single-instance"] = d->singleinstance->isChecked(); 0177 data->boolValues["flow-control"] = d->chkflowcontrol->isChecked(); 0178 data->boolValues["enable-variables"] = d->chkallowvars->isChecked(); 0179 } 0180 0181 #include "moc_cscripteditor.cpp"