summaryrefslogtreecommitdiffstats
path: root/kandy/src/commandscheduler.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 (patch)
tree67208f7c145782a7e90b123b982ca78d88cc2c87 /kandy/src/commandscheduler.cpp
downloadtdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.tar.gz
tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kandy/src/commandscheduler.cpp')
-rw-r--r--kandy/src/commandscheduler.cpp140
1 files changed, 140 insertions, 0 deletions
diff --git a/kandy/src/commandscheduler.cpp b/kandy/src/commandscheduler.cpp
new file mode 100644
index 000000000..23544e8a2
--- /dev/null
+++ b/kandy/src/commandscheduler.cpp
@@ -0,0 +1,140 @@
+/*
+ This file is part of Kandy.
+
+ Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include <kdebug.h>
+#include <klocale.h>
+
+#include "modem.h"
+
+#include "commandscheduler.h"
+#include "commandscheduler.moc"
+
+CommandScheduler::CommandScheduler(Modem *modem,QObject *parent,
+ const char *name) :
+ QObject(parent,name),
+ mModem(modem)
+{
+ connect(mModem,SIGNAL(gotLine(const char *)),
+ SLOT(processOutput(const char *)));
+}
+
+void CommandScheduler::execute(ATCommand *command)
+{
+ if (!mModem->isOpen()) {
+ kdDebug(5960) << "Warning! Modem not open." << endl;
+ return;
+ }
+
+ mCommandQueue.append(command);
+
+// if (mCommandQueue.count() == 1) sendCommand(command->cmdString());
+ if (mCommandQueue.count() == 1) sendCommand(command->cmd());
+}
+
+void CommandScheduler::execute(const QString &command)
+{
+ ATCommand *cmd = new ATCommand("",command);
+ cmd->setAutoDelete(true);
+
+ execute(cmd);
+}
+
+void CommandScheduler::executeId(const QString &id)
+{
+ QPtrList<ATCommand> *cmds = mCommandSet.commandList();
+
+ for(uint i=0;i<cmds->count();++i) {
+ if (cmds->at(i)->id() == id) {
+ execute(cmds->at(i));
+ return;
+ }
+ }
+ kdDebug(5960) << "CommandScheduler::executeId(): Id '" << id << "' not found" << endl;
+}
+
+void CommandScheduler::sendCommand(const QString &command)
+{
+ if (command.isEmpty()) {
+ kdDebug(5960) << "CommandScheduler::sendCommand(): Warning! Empty command."
+ << endl;
+ return;
+ }
+
+ kdDebug(5960) << "CommandScheduler:sendCommand(): " << command << endl;
+
+ mModem->writeLine(command.latin1());
+}
+
+
+void CommandScheduler::processOutput(const char *line)
+{
+ QString l = line;
+ ATCommand *cmd = mCommandQueue.first();
+ if (l == "OK") {
+ mState = WAITING;
+ emit result(mResult);
+ cmd->setResultString(mResult);
+ emit commandProcessed(cmd);
+ nextCommand();
+ } else if (l == "ERROR") {
+ mState = WAITING;
+ emit result(i18n("Error"));
+ nextCommand();
+ } else {
+ if (mState == WAITING) {
+ mState = PROCESSING;
+ mResult = "";
+ } else if (mState == PROCESSING) {
+ if (!l.isEmpty()) {
+ mResult += l;
+ mResult += "\n";
+ }
+ }
+ }
+}
+
+void CommandScheduler::nextCommand()
+{
+ if (mCommandQueue.first()->autoDelete()) delete mCommandQueue.first();
+ mCommandQueue.removeFirst();
+ if (mCommandQueue.count() > 0) {
+ sendCommand(mCommandQueue.first()->cmd());
+ }
+}
+
+bool CommandScheduler::loadProfile(const QString& filename)
+{
+ mCommandSet.clear();
+
+ if (!mCommandSet.loadFile(filename)) return false;
+
+ return true;
+}
+
+bool CommandScheduler::saveProfile(const QString& filename)
+{
+ if (!mCommandSet.saveFile(filename)) return false;
+
+ return true;
+}