parent
93e08950bc
commit
36e024d9a3
@ -1,78 +0,0 @@ |
||||
/*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#include "UBAbstractVotingSystem.h" |
||||
|
||||
#ifdef Q_WS_WIN |
||||
|
||||
#include "UBReply2005VotingSystem.h" |
||||
#include "UBReplyWRS970VotingSystem.h" |
||||
|
||||
#endif |
||||
|
||||
#include "gui/UBMainWindow.h" |
||||
|
||||
#include "core/memcheck.h" |
||||
|
||||
UBAbstractVotingSystem::UBAbstractVotingSystem(QObject *parent) |
||||
: QObject(parent) |
||||
{ |
||||
// NOOP
|
||||
|
||||
} |
||||
|
||||
|
||||
UBAbstractVotingSystem::~UBAbstractVotingSystem() |
||||
{ |
||||
// NOOP
|
||||
} |
||||
|
||||
|
||||
void UBAbstractVotingSystem::setLastError(QString pLastError) |
||||
{ |
||||
mLastError = pLastError; |
||||
qDebug() << "Voting System error: " << pLastError; |
||||
} |
||||
|
||||
|
||||
UBAbstractVotingSystem* UBVotingSystemFactory::createVotingSystem() |
||||
{ |
||||
|
||||
#ifdef Q_WS_WIN |
||||
|
||||
// TODO UB 4.x .. be smarter
|
||||
UBReplyWRS970VotingSystem* wrs970 = new UBReplyWRS970VotingSystem(UBApplication::mainWindow); |
||||
|
||||
if (wrs970->isVotingSystemAvailable()) |
||||
return wrs970; |
||||
else |
||||
{ |
||||
delete wrs970; |
||||
|
||||
UBReply2005VotingSystem* reply2005 = new UBReply2005VotingSystem(UBApplication::mainWindow); |
||||
|
||||
if (reply2005->isVotingSystemAvailable()) |
||||
return reply2005; |
||||
else |
||||
delete reply2005; |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
#else |
||||
return 0; |
||||
#endif |
||||
|
||||
} |
@ -1,82 +0,0 @@ |
||||
/*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef UBABSTRACTVOTINGSYSTEM_H_ |
||||
#define UBABSTRACTVOTINGSYSTEM_H_ |
||||
|
||||
#include <QtCore> |
||||
|
||||
#include "core/UBApplication.h" |
||||
|
||||
class UBAbstractVotingSystem : public QObject |
||||
{ |
||||
Q_OBJECT; |
||||
|
||||
Q_PROPERTY(QString lastError READ lastError); |
||||
|
||||
public: |
||||
UBAbstractVotingSystem(QObject *parent = 0); |
||||
virtual ~UBAbstractVotingSystem(); |
||||
|
||||
virtual bool connectToVotingSystem() = 0; |
||||
|
||||
virtual bool startPolling() = 0; |
||||
|
||||
virtual bool stopPolling() = 0; |
||||
|
||||
virtual bool disconnectFromVotingSystem() = 0; |
||||
|
||||
virtual QMap<int, int> votingState() = 0; |
||||
|
||||
QString lastError() const |
||||
{ |
||||
return mLastError; |
||||
} |
||||
|
||||
signals: |
||||
|
||||
void voteReceived(int keypadID, int value); |
||||
|
||||
void errorReceived(const QString& error); |
||||
|
||||
protected: |
||||
|
||||
void setLastError(QString pLastError); |
||||
|
||||
private: |
||||
|
||||
QString mLastError; |
||||
|
||||
}; |
||||
|
||||
class UBVotingSystemFactory : public QObject |
||||
{ |
||||
private: |
||||
UBVotingSystemFactory() |
||||
{ |
||||
// NOOP
|
||||
} |
||||
|
||||
~UBVotingSystemFactory() |
||||
{ |
||||
// NOOP
|
||||
} |
||||
|
||||
public: |
||||
|
||||
static UBAbstractVotingSystem* createVotingSystem(); |
||||
}; |
||||
|
||||
#endif /* UBABSTRACTVOTINGSYSTEM_H_ */ |
@ -1,151 +0,0 @@ |
||||
/*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#include "UBReply2005VotingSystem.h" |
||||
|
||||
#include "core/UBSettings.h" |
||||
|
||||
#include "core/memcheck.h" |
||||
|
||||
UBReply2005VotingSystem::UBReply2005VotingSystem(QWidget *parent) |
||||
: UBAbstractVotingSystem(parent) |
||||
, mParent(parent) |
||||
, mReplyVotingSystem(0) |
||||
, mMaxKeyValue(99) |
||||
{ |
||||
// NOOP
|
||||
} |
||||
|
||||
UBReply2005VotingSystem::~UBReply2005VotingSystem() |
||||
{ |
||||
if (mReplyVotingSystem) |
||||
delete mReplyVotingSystem; |
||||
} |
||||
|
||||
bool UBReply2005VotingSystem::isVotingSystemAvailable() |
||||
{ |
||||
if (!mReplyVotingSystem) |
||||
mReplyVotingSystem = new ReplyXControl1::ReplyX(mParent); |
||||
|
||||
return (!mReplyVotingSystem->isNull()); |
||||
} |
||||
|
||||
|
||||
bool UBReply2005VotingSystem::connectToVotingSystem() |
||||
{ |
||||
bool result = false; |
||||
|
||||
if (isVotingSystemAvailable()) |
||||
{ |
||||
connect(mReplyVotingSystem, SIGNAL(OnKeypadDataReceived(int, int)), |
||||
this, SLOT(keypadDataReceived(int, int))); |
||||
|
||||
mReplyVotingSystem->SetSerialPort(UBSettings::settings()->replyWWSerialPort->get().toInt()); |
||||
mReplyVotingSystem->SetReplyModel(ReplyXControl1::mReply2005); |
||||
|
||||
result = mReplyVotingSystem->Connect(); |
||||
|
||||
if (!result) |
||||
setLastError("Cannot connect to voting system"); |
||||
} |
||||
else |
||||
{ |
||||
setLastError("Reply2005 driver not available"); |
||||
} |
||||
|
||||
return result; |
||||
} |
||||
|
||||
void UBReply2005VotingSystem::keypadDataReceived(int keyPadID, int val) |
||||
{ |
||||
qDebug() << "received vote from " << keyPadID << " : " << val; |
||||
|
||||
mVotes.insert(keyPadID, val); |
||||
|
||||
emit voteReceived(keyPadID, val); |
||||
} |
||||
|
||||
|
||||
bool UBReply2005VotingSystem::startPolling() |
||||
{ |
||||
mVotes.clear(); |
||||
|
||||
if (isVotingSystemAvailable()) |
||||
{ |
||||
mReplyVotingSystem->StartPolling(); |
||||
} |
||||
else |
||||
{ |
||||
setLastError("Reply2005 driver not available"); |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
|
||||
bool UBReply2005VotingSystem::stopPolling() |
||||
{ |
||||
if (isVotingSystemAvailable()) |
||||
{ |
||||
mReplyVotingSystem->StopPolling(); |
||||
} |
||||
else |
||||
{ |
||||
setLastError("Reply2005 driver not available"); |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
|
||||
bool UBReply2005VotingSystem::disconnectFromVotingSystem() |
||||
{ |
||||
if (isVotingSystemAvailable()) |
||||
{ |
||||
mReplyVotingSystem->Disconnect(); |
||||
} |
||||
else |
||||
{ |
||||
setLastError("Reply2005 driver not available"); |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
QMap<int, int> UBReply2005VotingSystem::votingState() |
||||
{ |
||||
QMap<int, int> results; |
||||
|
||||
for(int i = 0; i < mMaxKeyValue; i++) |
||||
{ |
||||
results.insert(i, 0); |
||||
} |
||||
|
||||
foreach(int vote, mVotes.values()) |
||||
{ |
||||
int voteCount = 0; |
||||
|
||||
if(results.keys().contains(vote)) |
||||
{ |
||||
voteCount = results.value(vote); |
||||
voteCount++; |
||||
results.insert(vote, voteCount); |
||||
} |
||||
} |
||||
|
||||
return results; |
||||
} |
||||
|
||||
|
@ -1,60 +0,0 @@ |
||||
/*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef UBREPLY2005VOTINGSYSTEM_H_ |
||||
#define UBREPLY2005VOTINGSYSTEM_H_ |
||||
|
||||
#include "UBAbstractVotingSystem.h" |
||||
|
||||
#include <QtGui> |
||||
|
||||
#include "replyxcontrol1.h" |
||||
|
||||
class UBReply2005VotingSystem: public UBAbstractVotingSystem |
||||
{ |
||||
Q_OBJECT; |
||||
|
||||
public: |
||||
UBReply2005VotingSystem(QWidget *parent = 0); |
||||
virtual ~UBReply2005VotingSystem(); |
||||
|
||||
public slots: |
||||
|
||||
virtual bool connectToVotingSystem(); |
||||
virtual bool disconnectFromVotingSystem(); |
||||
|
||||
virtual bool startPolling(); |
||||
virtual bool stopPolling(); |
||||
|
||||
virtual QMap<int, int> votingState(); |
||||
|
||||
bool isVotingSystemAvailable(); |
||||
|
||||
protected: |
||||
ReplyXControl1::ReplyX *mReplyVotingSystem; |
||||
|
||||
private: |
||||
|
||||
QWidget* mParent; |
||||
|
||||
QMap <int, int> mVotes; |
||||
|
||||
int mMaxKeyValue; |
||||
|
||||
private slots: |
||||
void keypadDataReceived(int, int); |
||||
}; |
||||
|
||||
#endif /* UBREPLY2005VOTINGSYSTEM_H_ */ |
@ -1,279 +0,0 @@ |
||||
/*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#include "UBReplyWRS970VotingSystem.h" |
||||
|
||||
#include "core/UBSettings.h" |
||||
#include "core/UBApplication.h" |
||||
|
||||
#include "core/memcheck.h" |
||||
|
||||
UBReplyWRS970VotingSystem::UBReplyWRS970VotingSystem(QWidget *parent) |
||||
: UBAbstractVotingSystem(parent) |
||||
, mParent(parent) |
||||
, mReplyVotingSystem(0) |
||||
, mMaxKeyValue(99) |
||||
, mCurrentQuestionNumber(0) |
||||
{ |
||||
// NOOP
|
||||
} |
||||
|
||||
|
||||
UBReplyWRS970VotingSystem::~UBReplyWRS970VotingSystem() |
||||
{ |
||||
if (mReplyVotingSystem) |
||||
delete mReplyVotingSystem; |
||||
} |
||||
|
||||
|
||||
bool UBReplyWRS970VotingSystem::isVotingSystemAvailable() |
||||
{ |
||||
if (!mReplyVotingSystem) |
||||
{ |
||||
mReplyVotingSystem = new WRS970::WRS970X(mParent); |
||||
|
||||
connect(mReplyVotingSystem, SIGNAL(OnKeypadData(QString, int, int, QString, int, QString, int, int)), |
||||
this, SLOT(keypadData(QString, int, int, QString, int, QString, int, int))); |
||||
|
||||
connect(mReplyVotingSystem, SIGNAL(OnError(QString)), this, SLOT(error(QString))); |
||||
connect(mReplyVotingSystem, SIGNAL(OnDebug(QString)), this, SLOT(debug(QString))); |
||||
|
||||
mReplyVotingSystem->SetVersion3(true); |
||||
mReplyVotingSystem->SetExceptionsEnabled(false); |
||||
mReplyVotingSystem->SetErrorsEnabled(true); |
||||
|
||||
bool ok; |
||||
int maxKeypadsAllowed = UBSettings::settings()->replyPlusMaxKeypads->get().toInt(&ok); |
||||
|
||||
if (ok) |
||||
{ |
||||
mReplyVotingSystem->SetMaxKeypadsAllowed(maxKeypadsAllowed); |
||||
|
||||
for(int i = 0 ; i < maxKeypadsAllowed; i += 100) |
||||
{ |
||||
mReplyVotingSystem->AddStaticKeypad("00000", i + 1, true); |
||||
} |
||||
} |
||||
|
||||
if (UBApplication::app()->isVerbose()) |
||||
{ |
||||
mReplyVotingSystem->SetDebugEnabled(true); |
||||
} |
||||
} |
||||
|
||||
return (!mReplyVotingSystem->isNull()); |
||||
} |
||||
|
||||
|
||||
bool UBReplyWRS970VotingSystem::connectToVotingSystem() |
||||
{ |
||||
bool connected = false; |
||||
|
||||
if (isVotingSystemAvailable()) |
||||
{ |
||||
mCurrentQuestionNumber = 0; |
||||
QString targetBase; |
||||
|
||||
QString connectionURL = UBSettings::settings()->replyPlusConnectionURL->get().toString(); |
||||
|
||||
if (connectionURL.toLower() == "usb") |
||||
{ |
||||
QString baseSerial = mReplyVotingSystem->GetAvailableBases(false); |
||||
|
||||
if (baseSerial == "No device found") |
||||
{ |
||||
setLastError("No WRS970 device found via USB"); |
||||
return false; |
||||
} |
||||
|
||||
QStringList bases = baseSerial.split(","); |
||||
|
||||
if (bases.count() == 0) |
||||
{ |
||||
setLastError("No base found via USB"); |
||||
return false; |
||||
} |
||||
|
||||
targetBase = bases.at(0); |
||||
|
||||
mReplyVotingSystem->Connect(targetBase); |
||||
} |
||||
else |
||||
{ |
||||
QString ip; |
||||
QString port; |
||||
|
||||
targetBase = connectionURL; |
||||
|
||||
QStringList addressTokens = connectionURL.split(":"); |
||||
|
||||
if (addressTokens.length() > 0) |
||||
ip = addressTokens.at(0); |
||||
|
||||
if (addressTokens.length() > 1) |
||||
port = addressTokens.at(1); |
||||
|
||||
if (ip.length() > 0) |
||||
{ |
||||
mReplyVotingSystem->SetCommType(WRS970::ctTCP); |
||||
mReplyVotingSystem->SetTCPAddress(ip); |
||||
|
||||
bool ok; |
||||
int iPort = port.toInt(&ok); |
||||
|
||||
if (port.length() > 0 && ok) |
||||
mReplyVotingSystem->SetTCPPort(iPort); |
||||
} |
||||
|
||||
mReplyVotingSystem->Connect(NULL); |
||||
|
||||
} |
||||
|
||||
connected = mReplyVotingSystem->Connected(); |
||||
|
||||
if (!connected) |
||||
setLastError("Error connecting to base " + targetBase); |
||||
|
||||
qDebug() << "Reply WRS 970 connected:" << connected; |
||||
|
||||
if (connected) |
||||
{ |
||||
QString addressingMode = UBSettings::settings()->replyPlusAddressingMode->get().toString(); |
||||
|
||||
if (addressingMode.toLower() == "static") |
||||
mReplyVotingSystem->SetAddressMode(WRS970::addrStatic); |
||||
else |
||||
mReplyVotingSystem->SetAddressMode(WRS970::addrDynamic); |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
setLastError("WRS970 driver not available"); |
||||
} |
||||
|
||||
return connected; |
||||
} |
||||
|
||||
|
||||
void UBReplyWRS970VotingSystem::keypadData(QString serialNumber, int keypadID, int timeStamp, QString version |
||||
, int batteryLevel, QString value, int questionNumber, int keypadType) |
||||
{ |
||||
Q_UNUSED(serialNumber); |
||||
Q_UNUSED(timeStamp); |
||||
Q_UNUSED(version); |
||||
Q_UNUSED(batteryLevel); |
||||
Q_UNUSED(questionNumber); |
||||
Q_UNUSED(keypadType); |
||||
|
||||
qDebug() << "Received vote from " << keypadID << " : " << value; |
||||
|
||||
mVotes.insert(keypadID, value.toInt()); |
||||
|
||||
emit voteReceived(keypadID, value.toInt()); |
||||
} |
||||
|
||||
|
||||
void UBReplyWRS970VotingSystem::error(QString error) |
||||
{ |
||||
setLastError(error); |
||||
|
||||
emit errorReceived(error); |
||||
|
||||
//UBApplication::showMessage(tr("Voting System Error: %1").arg(error));
|
||||
} |
||||
|
||||
|
||||
void UBReplyWRS970VotingSystem::debug(QString error) |
||||
{ |
||||
qDebug() << error; |
||||
} |
||||
|
||||
|
||||
|
||||
bool UBReplyWRS970VotingSystem::startPolling() |
||||
{ |
||||
mVotes.clear(); |
||||
|
||||
if (isVotingSystemAvailable()) |
||||
{ |
||||
++mCurrentQuestionNumber; |
||||
mReplyVotingSystem->BeginQuestion(mCurrentQuestionNumber, WRS970::atSingleDigit); |
||||
} |
||||
else |
||||
{ |
||||
setLastError("WRS970 driver not available"); |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
|
||||
bool UBReplyWRS970VotingSystem::stopPolling() |
||||
{ |
||||
if (isVotingSystemAvailable()) |
||||
{ |
||||
//mReplyVotingSystem->
|
||||
} |
||||
else |
||||
{ |
||||
setLastError("WRS970 driver not available"); |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
|
||||
bool UBReplyWRS970VotingSystem::disconnectFromVotingSystem() |
||||
{ |
||||
if (isVotingSystemAvailable()) |
||||
{ |
||||
mReplyVotingSystem->Disconnect(); |
||||
} |
||||
else |
||||
{ |
||||
setLastError("WRS970 driver not available"); |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
QMap<int, int> UBReplyWRS970VotingSystem::votingState() |
||||
{ |
||||
QMap<int, int> results; |
||||
|
||||
for(int i = 0; i < mMaxKeyValue; i++) |
||||
{ |
||||
results.insert(i, 0); |
||||
} |
||||
|
||||
foreach(int vote, mVotes.values()) |
||||
{ |
||||
if(results.keys().contains(vote)) |
||||
{ |
||||
int voteCount = results.value(vote); |
||||
voteCount++; |
||||
results.insert(vote, voteCount); |
||||
} |
||||
} |
||||
|
||||
foreach(int key, results.keys()) |
||||
{ |
||||
qDebug() << "Vote" << key << ":" << results.value(key); |
||||
} |
||||
|
||||
return results; |
||||
} |
||||
|
||||
|
@ -1,63 +0,0 @@ |
||||
/*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef UBREPLYWRS970VOTINGSYSTEM_H_ |
||||
#define UBREPLYWRS970VOTINGSYSTEM_H_ |
||||
|
||||
#include "UBAbstractVotingSystem.h" |
||||
|
||||
#include "wrs970.h" |
||||
|
||||
class UBReplyWRS970VotingSystem : public UBAbstractVotingSystem |
||||
{ |
||||
Q_OBJECT; |
||||
|
||||
public: |
||||
UBReplyWRS970VotingSystem(QWidget *parent = 0); |
||||
virtual ~UBReplyWRS970VotingSystem(); |
||||
|
||||
public slots: |
||||
|
||||
virtual bool connectToVotingSystem(); |
||||
virtual bool disconnectFromVotingSystem(); |
||||
|
||||
virtual bool startPolling(); |
||||
virtual bool stopPolling(); |
||||
|
||||
virtual QMap<int, int> votingState(); |
||||
|
||||
bool isVotingSystemAvailable(); |
||||
|
||||
protected: |
||||
WRS970::WRS970X *mReplyVotingSystem; |
||||
|
||||
private: |
||||
|
||||
QWidget* mParent; |
||||
QMap <int, int> mVotes; |
||||
int mMaxKeyValue; |
||||
int mCurrentQuestionNumber; |
||||
|
||||
private slots: |
||||
|
||||
void keypadData(QString, int, int, QString, int, QString, int, int); |
||||
|
||||
void error(QString error); |
||||
|
||||
void debug(QString error); |
||||
|
||||
}; |
||||
|
||||
#endif /* UBREPLYWRS970VOTINGSYSTEM_H_ */ |
@ -1,112 +0,0 @@ |
||||
/*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#include "UBWidgetVotingSystemAPI.h" |
||||
|
||||
#include "adaptors/voting/UBAbstractVotingSystem.h" |
||||
|
||||
#include "core/memcheck.h" |
||||
|
||||
UBWidgetVotingSystemAPI::UBWidgetVotingSystemAPI(QObject* parent) |
||||
: QObject(parent) |
||||
, mVotingSystem(0) |
||||
{ |
||||
// NOOP
|
||||
} |
||||
|
||||
|
||||
UBWidgetVotingSystemAPI::~UBWidgetVotingSystemAPI() |
||||
{ |
||||
// NOOP
|
||||
} |
||||
|
||||
|
||||
QString UBWidgetVotingSystemAPI::lastError() |
||||
{ |
||||
return mLastError; |
||||
} |
||||
|
||||
|
||||
void UBWidgetVotingSystemAPI::setLastError(const QString& pLastError) |
||||
{ |
||||
mLastError = pLastError; |
||||
qDebug() << mLastError; |
||||
|
||||
emit error(mLastError); |
||||
} |
||||
|
||||
|
||||
void UBWidgetVotingSystemAPI::errorReceived(const QString& pLastError) |
||||
{ |
||||
setLastError(pLastError); |
||||
} |
||||
|
||||
|
||||
bool UBWidgetVotingSystemAPI::startPoll() |
||||
{ |
||||
if (!mVotingSystem) |
||||
{ |
||||
mVotingSystem = UBVotingSystemFactory::createVotingSystem(); |
||||
} |
||||
|
||||
if (!mVotingSystem) |
||||
{ |
||||
setLastError("No voting system available"); |
||||
return false; |
||||
} |
||||
|
||||
connect(mVotingSystem, SIGNAL(errorReceived(const QString&)), this, SLOT(errorReceived(const QString&))); |
||||
|
||||
bool connected = mVotingSystem->connectToVotingSystem(); |
||||
|
||||
if (!connected) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
bool started = mVotingSystem->startPolling(); |
||||
|
||||
if (!started) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
|
||||
QVariantMap UBWidgetVotingSystemAPI::closePoll() |
||||
{ |
||||
if (!mVotingSystem) |
||||
return QVariantMap(); |
||||
|
||||
mVotingSystem->stopPolling(); |
||||
|
||||
QMap<int, int> results = mVotingSystem->votingState(); |
||||
|
||||
mVotingSystem->disconnectFromVotingSystem(); |
||||
|
||||
delete mVotingSystem; |
||||
mVotingSystem = 0; |
||||
|
||||
QVariantMap scriptResults; |
||||
|
||||
foreach(int key, results.keys()) |
||||
{ |
||||
scriptResults.insert(QString("%1").arg(key), QVariant(results.value(key))); |
||||
} |
||||
|
||||
return scriptResults; |
||||
} |
@ -1,54 +0,0 @@ |
||||
/*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef UBWIDGETVOTINGSYSTEMAPI_H_ |
||||
#define UBWIDGETVOTINGSYSTEMAPI_H_ |
||||
|
||||
#include <QtCore> |
||||
|
||||
class UBAbstractVotingSystem; |
||||
|
||||
class UBWidgetVotingSystemAPI : public QObject |
||||
{ |
||||
Q_OBJECT; |
||||
|
||||
Q_PROPERTY(QString lastError READ lastError); |
||||
|
||||
public: |
||||
UBWidgetVotingSystemAPI(QObject* parent = 0); |
||||
virtual ~UBWidgetVotingSystemAPI(); |
||||
|
||||
QString lastError(); |
||||
void setLastError(const QString& pLastError); |
||||
|
||||
signals: |
||||
void error(const QString&); |
||||
|
||||
public slots: |
||||
|
||||
bool startPoll(); |
||||
QVariantMap closePoll(); |
||||
|
||||
private slots: |
||||
|
||||
void errorReceived(const QString& error); |
||||
|
||||
private: |
||||
UBAbstractVotingSystem* mVotingSystem; |
||||
QString mLastError; |
||||
|
||||
}; |
||||
|
||||
#endif /* UBWIDGETVOTINGSYSTEMAPI_H_ */ |
Loading…
Reference in new issue