kandy

cmdpropertiesdialog.cpp
1/*
2 This file is part of Kandy.
3
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20 As a special exception, permission is given to link this program
21 with any edition of TQt, and distribute the resulting executable,
22 without including the source code for TQt in the source distribution.
23*/
24
25#include <tqlistview.h>
26#include <tqlineedit.h>
27#include <tqcheckbox.h>
28
29#include <kinputdialog.h>
30#include <tdelocale.h>
31
32#include "atcommand.h"
33
34#include "cmdpropertiesdialog.h"
35#include "cmdpropertiesdialog.moc"
36
37class ParameterItem : public TQCheckListItem {
38 public:
39 ParameterItem(ATParameter *p,TQListView *parent) :
40 TQCheckListItem(parent,p->name(),CheckBox),mParameter(p)
41 {
42 setText(1,p->value());
43 setOn(p->userInput());
44 }
45
46 void writeParameter()
47 {
48 mParameter->setName(text(0));
49 mParameter->setValue(text(1));
50 mParameter->setUserInput(isOn());
51 }
52
53 private:
54 ATParameter *mParameter;
55};
56
57
58/*
59 * Constructs a CmdPropertiesDialog which is a child of 'parent', with the
60 * name 'name' and widget flags set to 'f'
61 *
62 * The dialog will by default be modeless, unless you set 'modal' to
63 * TRUE to construct a modal dialog.
64 */
65CmdPropertiesDialog::CmdPropertiesDialog(ATCommand *cmd, TQWidget* parent,
66 const char* name, bool modal,
67 WFlags fl )
68 : CmdPropertiesDialog_base( parent, name, modal, fl )
69{
70 mCmd = cmd;
71
72 readCommand();
73}
74
75CmdPropertiesDialog::~CmdPropertiesDialog()
76{
77}
78
79void CmdPropertiesDialog::readCommand()
80{
81 mNameEdit->setText(mCmd->cmdName());
82 mStringEdit->setText(mCmd->cmdString());
83 mHexCheck->setChecked(mCmd->hexOutput());
84
85 TQPtrList<ATParameter> parameters = mCmd->parameters();
86 for(int i=(int)parameters.count()-1;i>=0;--i) {
87 ATParameter *p = parameters.at(i);
88 new ParameterItem(p,mParameterList);
89 }
90}
91
92void CmdPropertiesDialog::writeCommand()
93{
94 mCmd->setCmdName(mNameEdit->text());
95 mCmd->setCmdString(mStringEdit->text());
96 mCmd->setHexOutput(mHexCheck->isChecked());
97 ParameterItem *item = (ParameterItem *)mParameterList->firstChild();
98 while (item) {
99 item->writeParameter();
100 item = (ParameterItem *)item->nextSibling();
101 }
102}
103
104void CmdPropertiesDialog::editParameterName(TQListViewItem *item)
105{
106 bool ok = false;
107
108 TQString newName = KInputDialog::getText(TQString(),
109 i18n("Enter parameter name:"),item->text(0),&ok,this);
110
111 if (ok) {
112 item->setText(0,newName);
113 }
114}
115
116void CmdPropertiesDialog::slotAccept()
117{
118 writeCommand();
119 accept();
120}
This class provides an abstraction of an AT command.
Definition: atcommand.h:54