kandyview.cpp
00001
00002
00003 #include <unistd.h>
00004
00005 #include <qpainter.h>
00006 #include <qlayout.h>
00007 #include <qhbox.h>
00008 #include <qmultilineedit.h>
00009 #include <qlistview.h>
00010 #include <qdom.h>
00011 #include <qtextstream.h>
00012 #include <qfile.h>
00013 #include <qlineedit.h>
00014 #include <qcheckbox.h>
00015
00016 #include <kurl.h>
00017 #include <kmessagebox.h>
00018 #include <kdebug.h>
00019 #include <klocale.h>
00020 #include <kglobal.h>
00021 #include <kconfig.h>
00022 #include <klineeditdlg.h>
00023
00024 #include "modem.h"
00025 #include "cmdpropertiesdialog.h"
00026 #include "commanditem.h"
00027 #include "atcommand.h"
00028 #include "commandscheduler.h"
00029 #include "kandyprefs.h"
00030
00031 #include "kandyview.h"
00032 #include "kandyview.moc"
00033
00034 KandyView::KandyView(CommandScheduler *scheduler,QWidget *parent)
00035 : KandyView_base(parent)
00036 {
00037 mModified = false;
00038 mScheduler = scheduler;
00039
00040 connect (mInput,SIGNAL(returnPressed()),SLOT(processLastLine()));
00041
00042 connect(mScheduler->modem(),SIGNAL(gotLine(const char *)),
00043 SLOT(appendOutput(const char *)));
00044
00045 connect(mScheduler,SIGNAL(result(const QString &)),
00046 mResultView,SLOT(setText(const QString &)));
00047 connect(mScheduler,SIGNAL(commandProcessed(ATCommand *)),
00048 SLOT(setResult(ATCommand *)));
00049 }
00050
00051 KandyView::~KandyView()
00052 {
00053 }
00054
00055
00056 void KandyView::print(QPainter *, int, int)
00057 {
00058
00059
00060 }
00061
00062 void KandyView::importPhonebook()
00063 {
00064 #if 0
00065 createMobileGui();
00066 connect (mMobileGui,SIGNAL(phonebookRead()),mMobileGui,SLOT(writeKab()));
00067 mMobileGui->readPhonebook();
00068 #endif
00069 }
00070
00071 void KandyView::slotSetTitle(const QString& title)
00072 {
00073 emit signalChangeCaption(title);
00074 }
00075
00076 void KandyView::processLastLine()
00077 {
00078 int line = 0;
00079 int row = 0;
00080 mInput->getCursorPosition(&line,&row);
00081
00082 if (line > 0) {
00083 mLastInput = mInput->textLine(line-1);
00084 mScheduler->execute(mLastInput);
00085 }
00086 }
00087
00088 void KandyView::appendOutput(const char *line)
00089 {
00090
00091 mOutput->append(line);
00092 mOutput->setCursorPosition(mOutput->numLines()-1,0);
00093 }
00094
00095 void KandyView::setResult(ATCommand *command)
00096 {
00097 if (command == 0) {
00098 kdDebug() << "KandyView::setResult(): Error! No command." << endl;
00099 mResultView->setText(i18n("Error"));
00100 return;
00101 }
00102
00103
00104
00105
00106 mResultView->setText(command->cmdName() + ":\n" + command->processOutput());
00107 }
00108
00109 void KandyView::addCommand()
00110 {
00111 ATCommand *cmd = new ATCommand(mLastInput);
00112
00113 CmdPropertiesDialog *dlg = new CmdPropertiesDialog(cmd,this,"cmdprop",true);
00114
00115 int result = dlg->exec();
00116
00117 if (result == QDialog::Accepted) {
00118 new CommandItem(mCommandList,cmd);
00119 mScheduler->commandSet()->addCommand(cmd);
00120 setModified();
00121 } else {
00122 delete cmd;
00123 }
00124 }
00125
00126 void KandyView::editCommand()
00127 {
00128 QListViewItem *item = mCommandList->currentItem();
00129 if (item) {
00130 CommandItem *cmdItem = (CommandItem *)item;
00131 ATCommand *cmd = cmdItem->command();
00132
00133 CmdPropertiesDialog *dlg = new CmdPropertiesDialog(cmd,this,"cmdprop",true);
00134
00135 int result = dlg->exec();
00136
00137 if (result == QDialog::Accepted) {
00138 cmdItem->setItemText();
00139 setModified();
00140 }
00141 }
00142 }
00143
00144 void KandyView::executeCommand()
00145 {
00146 CommandItem *item = (CommandItem *)(mCommandList->currentItem());
00147 if (item) {
00148 ATCommand *cmd = item->command();
00149 QPtrList<ATParameter> paraList = cmd->parameters();
00150 for(uint i=0;i<paraList.count();++i) {
00151 ATParameter *p = paraList.at(i);
00152 if (p->userInput()) {
00153 bool ok = false;
00154 QString value = KLineEditDlg::getText(i18n("Enter Value for %1").arg(p->name()),
00155 "",&ok,this);
00156 if (ok) {
00157 p->setValue(value);
00158 } else {
00159 return;
00160 }
00161 }
00162 }
00163 kdDebug() << "KandyView::executeCommand(): " << cmd->cmd() << endl;
00164 mScheduler->execute(cmd);
00165 }
00166 }
00167
00168 void KandyView::deleteCommand()
00169 {
00170 CommandItem *item = dynamic_cast<CommandItem *>(mCommandList->currentItem());
00171 if (item) {
00172 mScheduler->commandSet()->deleteCommand(item->command());
00173 delete item;
00174 setModified();
00175 }
00176 }
00177
00178 bool KandyView::loadFile(const QString& filename)
00179 {
00180 mCommandList->clear();
00181
00182 if (!mScheduler->loadProfile(filename)) return false;
00183
00184 QPtrList<ATCommand> *cmds = mScheduler->commandSet()->commandList();
00185
00186 for(uint i=0;i<cmds->count();++i) {
00187 new CommandItem(mCommandList,cmds->at(i));
00188 }
00189
00190 KConfig *config = KGlobal::config();
00191 config->setGroup("General");
00192 config->writeEntry("CurrentProfile",filename);
00193
00194 setModified(false);
00195
00196 return true;
00197 }
00198
00199 bool KandyView::saveFile(const QString& filename)
00200 {
00201 if (!mScheduler->saveProfile(filename)) return false;
00202
00203 KConfig *config = KGlobal::config();
00204 config->setGroup("General");
00205 config->writeEntry("CurrentProfile",filename);
00206
00207 setModified(false);
00208
00209 return true;
00210 }
00211
00212 void KandyView::setModified(bool modified)
00213 {
00214 if (modified != mModified) {
00215 mModified = modified;
00216 emit modifiedChanged(mModified);
00217 }
00218 }
00219
00220 bool KandyView::isModified()
00221 {
00222 return mModified;
00223 }
This file is part of the documentation for kdelibs Version 3.1.5.