31#include <tqtextedit.h> 
   32#include <tqlistview.h> 
   34#include <tqtextstream.h> 
   36#include <tqlineedit.h> 
   37#include <tqcheckbox.h> 
   39#include <tqpushbutton.h> 
   42#include <tdemessagebox.h> 
   47#include <kinputdialog.h> 
   51#include "cmdpropertiesdialog.h" 
   52#include "commanditem.h" 
   54#include "commandscheduler.h" 
   55#include "kandyprefs.h" 
   58#include "kandyview.moc" 
   64  mScheduler = scheduler;
 
   66  TQBoxLayout *topLayout = 
new TQVBoxLayout( 
this );
 
   68  TQSplitter *mainSplitter = 
new TQSplitter( TQt::Horizontal, 
this );
 
   69  topLayout->addWidget( mainSplitter );
 
   71  TQWidget *commandBox = 
new TQWidget( mainSplitter );
 
   73  TQBoxLayout *commandLayout = 
new TQVBoxLayout( commandBox );
 
   74  commandLayout->setMargin( KDialog::marginHint() );
 
   75  commandLayout->setSpacing( KDialog::spacingHint() );
 
   77  mCommandList = 
new TQListView( commandBox );
 
   78  mCommandList->addColumn( i18n( 
"Name" ) );
 
   79  mCommandList->addColumn( i18n( 
"Command" ) );
 
   80  mCommandList->addColumn( i18n( 
"Hex" ) );
 
   81  commandLayout->addWidget( mCommandList );
 
   83  connect( mCommandList, TQ_SIGNAL( doubleClicked(TQListViewItem*) ),
 
   84           TQ_SLOT( executeCommand() ) );
 
   86  TQPushButton *buttonAdd = 
new TQPushButton( i18n(
"Add..."), commandBox );
 
   87  commandLayout->addWidget( buttonAdd );
 
   88  connect( buttonAdd, TQ_SIGNAL( clicked() ), TQ_SLOT( addCommand() ) );
 
   90  TQPushButton *buttonEdit = 
new TQPushButton( i18n(
"Edit..."), commandBox );
 
   91  commandLayout->addWidget( buttonEdit );
 
   92  connect( buttonEdit, TQ_SIGNAL( clicked() ), TQ_SLOT( editCommand() ) );
 
   94  TQPushButton *buttonDelete = 
new TQPushButton( i18n(
"Delete"), commandBox );
 
   95  commandLayout->addWidget( buttonDelete );
 
   96  connect( buttonDelete, TQ_SIGNAL( clicked() ), TQ_SLOT( deleteCommand() ) );
 
   98  TQPushButton *buttonExecute = 
new TQPushButton( i18n(
"Execute"), commandBox );
 
   99  commandLayout->addWidget( buttonExecute );
 
  100  connect( buttonExecute, TQ_SIGNAL( clicked() ), TQ_SLOT( executeCommand() ) );
 
  102  TQSplitter *ioSplitter = 
new TQSplitter( TQt::Vertical, mainSplitter );
 
  104  TQWidget *inBox = 
new TQWidget( ioSplitter );
 
  106  TQBoxLayout *inLayout = 
new TQVBoxLayout( inBox );
 
  108  TQLabel *inLabel = 
new TQLabel( i18n(
"Input:"), inBox );
 
  109  inLabel->setMargin( 2 );
 
  110  inLayout->addWidget( inLabel );
 
  112  mInput = 
new TQTextEdit( inBox );
 
  113  inLayout->addWidget( mInput );
 
  115  TQWidget *outBox = 
new TQWidget( ioSplitter );
 
  117  TQBoxLayout *outLayout = 
new TQVBoxLayout( outBox );
 
  119  TQLabel *outLabel = 
new TQLabel( i18n( 
"Output:"), outBox );
 
  120  outLabel->setMargin( 2 );
 
  121  outLayout->addWidget( outLabel );
 
  123  mOutput = 
new TQTextEdit( outBox );
 
  124  mOutput->setReadOnly( 
true );
 
  125  outLayout->addWidget( mOutput );
 
  127  TQVBox *resultBox = 
new TQVBox( mainSplitter );
 
  129  TQLabel *resultLabel = 
new TQLabel( i18n(
"Result:"), resultBox );
 
  130  resultLabel->setMargin( 2 );
 
  132  mResultView = 
new TQTextEdit( resultBox );
 
  133  mResultView->setReadOnly( 
true );
 
  135  connect (mInput,TQ_SIGNAL(returnPressed()),TQ_SLOT(processLastLine()));
 
  137  connect(mScheduler->modem(),TQ_SIGNAL(gotLine(
const char *)),
 
  138          TQ_SLOT(appendOutput(
const char *)));
 
  140  connect(mScheduler,TQ_SIGNAL(result(
const TQString &)),
 
  141          mResultView,TQ_SLOT(setText(
const TQString &)));
 
  142  connect(mScheduler,TQ_SIGNAL(commandProcessed(
ATCommand *)),
 
  161  connect (mMobileGui,TQ_SIGNAL(phonebookRead()),mMobileGui,TQ_SLOT(writeKab()));
 
  162  mMobileGui->readPhonebook();
 
  166void KandyView::slotSetTitle(
const TQString& title)
 
  171void KandyView::processLastLine()
 
  175  mInput->getCursorPosition( ¶, &row );
 
  178    mLastInput = mInput->text( para - 1 );
 
  180    kdDebug(5960) << 
"processLastLine(): " << mLastInput << endl;
 
  182    mScheduler->execute(mLastInput);
 
  186void KandyView::appendOutput(
const char *line)
 
  189  mOutput->append(line);
 
  190  mOutput->setCursorPosition(mOutput->paragraphs()-1,0);
 
  193void KandyView::setResult(
ATCommand *command)
 
  196    kdDebug(5960) << 
"KandyView::setResult(): Error! No command." << endl;
 
  197    mResultView->setText(i18n(
"Error"));
 
  204  mResultView->setText(command->cmdName() + 
":\n" + command->processOutput());
 
  207void KandyView::addCommand()
 
  211  CmdPropertiesDialog *dlg = 
new CmdPropertiesDialog(cmd,
this,
"cmdprop",
true);
 
  213  int result = dlg->exec();
 
  215  if (result == TQDialog::Accepted) {
 
  217    mScheduler->commandSet()->addCommand(cmd);
 
  224void KandyView::editCommand()
 
  226  TQListViewItem *item = mCommandList->currentItem();
 
  231    CmdPropertiesDialog *dlg = 
new CmdPropertiesDialog(cmd,
this,
"cmdprop",
true);
 
  233    int result = dlg->exec();
 
  235    if (result == TQDialog::Accepted) {
 
  236      cmdItem->setItemText();
 
  242void KandyView::executeCommand()
 
  247    TQPtrList<ATParameter> paraList = cmd->parameters();
 
  248    for(uint i=0;i<paraList.count();++i) {
 
  249      ATParameter *p = paraList.at(i);
 
  250      if (p->userInput()) {
 
  252        TQString value = KInputDialog::getText(TQString(),
 
  253            i18n(
"Enter value for %1:").arg(p->name()),TQString(),&ok,
this);
 
  259    kdDebug(5960) << 
"KandyView::executeCommand(): " << cmd->cmd() << endl;
 
  260    mScheduler->execute(cmd);
 
  264void KandyView::deleteCommand()
 
  268    mScheduler->commandSet()->deleteCommand(item->command());
 
  274bool KandyView::loadFile(
const TQString& filename)
 
  276  mCommandList->clear();
 
  278  if (!mScheduler->loadProfile(filename)) 
return false;
 
  280  TQPtrList<ATCommand> *cmds = mScheduler->commandSet()->commandList();
 
  282  for(uint i=0;i<cmds->count();++i) {
 
  286  TDEConfig *config = TDEGlobal::config();
 
  287  config->setGroup(
"General");
 
  288  config->writeEntry(
"CurrentProfile",filename);
 
  295bool KandyView::saveFile(
const TQString& filename)
 
  297  if (!mScheduler->saveProfile(filename)) 
return false;
 
  299  TDEConfig *config = TDEGlobal::config();
 
  300  config->setGroup(
"General");
 
  301  config->writeEntry(
"CurrentProfile",filename);
 
  308void KandyView::setModified(
bool modified)
 
  310  if (modified != mModified) {
 
  311    mModified = modified;
 
  312    emit modifiedChanged(mModified);
 
  316bool KandyView::isModified()
 
This class provides an abstraction of an AT command.
TQListView item representing a modem command.
void signalChangeCaption(const TQString &text)
Use this signal to change the content of the caption.
void print(TQPainter *, int height, int width)
Print this view to any medium – paper or not.
void importPhonebook()
Import phonebook from mobile phone and save it to Kab.
virtual ~KandyView()
Destructor.
KandyView(CommandScheduler *, TQWidget *parent)
Default constructor.