-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from fabsi/master
Gmail plugin
- Loading branch information
Showing
5 changed files
with
245 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
if( !empty($_POST['Frequency']) && !empty($_POST['Email']) && !empty($_POST['Password']) ) | ||
{ | ||
$retour = $ojnAPI->getApiString("bunny/".$_SESSION['bunny']."/gmail/setConfig?Frequency=".$_POST['Frequency']."&Email=".$_POST['Email']."&Password=".$_POST['Password']."&".$ojnAPI->getToken()); | ||
$_SESSION['message'] = isset($retour['ok']) ? $retour['ok'] : "Error : ".$retour['error']; | ||
header("Location: bunny_plugin.php?p=gmail"); | ||
} | ||
|
||
list($frequency, $email,$password) = $ojnAPI->getApiList("bunny/".$_SESSION['bunny']."/gmail/getConfig?".$ojnAPI->getToken()); | ||
|
||
?> | ||
|
||
<form method="post"> | ||
<fieldset> | ||
<legend>Configuration of your Gmail account</legend> | ||
Frequency <i>(in minutes)</i>:<br> | ||
<input type="text" name="Frequency" maxlength="30" style="width: 50px" value="<?php echo $frequency; ?>" /></td> | ||
<br><br> | ||
Email <i>(for example john.doe@gmail.com)</i>:<br> | ||
<input type="text" name="Email" maxlength="30" style="width: 250px" value="<?php echo $email; ?>" /></td> | ||
<br><br> | ||
Password <i>(gmail account password)</i>:<br> | ||
<input type="password" name="Password" maxlength="30" style="width: 200px" value="<?php echo $password; ?>" /></td> | ||
<br> | ||
|
||
<input type="submit" value="Save"> | ||
</fieldset> | ||
</form> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
###################################################################### | ||
# Automatically generated by qmake (2.01a) sam. janv. 19 19:10:01 2008 | ||
###################################################################### | ||
|
||
TEMPLATE = lib | ||
CONFIG -= #DEBUG | ||
CONFIG += plugin qt #DEBUG | ||
QT += network | ||
QT -= gui | ||
INCLUDEPATH += . ../../server ../../lib | ||
TARGET = plugin_gmail | ||
DESTDIR = ../../bin/plugins | ||
DEPENDPATH += . ../../server ../../lib | ||
LIBS += -L../../bin/ -lcommon | ||
MOC_DIR = ./tmp/moc | ||
OBJECTS_DIR = ./tmp/obj | ||
win32 { | ||
QMAKE_CXXFLAGS_WARN_ON += -WX | ||
} | ||
unix { | ||
QMAKE_LFLAGS += -Wl,-rpath,\'\$$ORIGIN\' | ||
QMAKE_CXXFLAGS += -Werror | ||
} | ||
|
||
# Input | ||
HEADERS += plugin_gmail.h | ||
SOURCES += plugin_gmail.cpp | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
#include "plugin_gmail.h" | ||
#include "cron.h" | ||
#include <QMapIterator> | ||
#include "bunny.h" | ||
#include "bunnymanager.h" | ||
#include "messagepacket.h" | ||
#include "ambientpacket.h" | ||
#include "ttsmanager.h" | ||
#include "log.h" | ||
#include <QHttp> | ||
|
||
|
||
Q_EXPORT_PLUGIN2(plugin_gmail, PluginGmail) | ||
|
||
PluginGmail::PluginGmail():PluginInterface("gmail", "Gmail Configuration",BunnyPlugin) | ||
{ | ||
} | ||
|
||
PluginGmail::~PluginGmail() | ||
{ | ||
Cron::UnregisterAll(this); | ||
} | ||
|
||
void PluginGmail::OnBunnyConnect(Bunny * b) | ||
{ | ||
int frequency = b->GetPluginSetting(GetName(), "Frequency", 0).toInt(); | ||
if(frequency < 1) | ||
frequency = 1; | ||
if(frequency > 500) | ||
frequency = 500; | ||
Cron::Register(this, frequency, 0, 0, b, QVariant( (int) NULL) ); | ||
} | ||
|
||
void PluginGmail::OnBunnyDisconnect(Bunny * b) | ||
{ | ||
Cron::UnregisterAllForBunny(this, b); | ||
|
||
} | ||
|
||
void PluginGmail::OnCron(Bunny * b, QVariant) | ||
{ | ||
QMapIterator<Bunny *, QString> i(bunnyList); | ||
QString email = b->GetPluginSetting(GetName(), QString("Email"), QString()).toString(); | ||
QString password = b->GetPluginSetting(GetName(), QString("Password"), QString()).toString(); | ||
|
||
|
||
connect(&http, SIGNAL(readyRead(QHttpResponseHeader)),this, SLOT(readData(QHttpResponseHeader))); | ||
xml.clear(); | ||
|
||
if((email != "") && (password != "")) | ||
{ | ||
http.setHost("mail.google.com", QHttp::ConnectionModeHttps); | ||
http.setUser(email, password); | ||
http.setProperty("BunnyID", b->GetID()); | ||
http.get("/mail/feed/atom"); | ||
} | ||
|
||
return; | ||
} | ||
|
||
|
||
void PluginGmail::readData(const QHttpResponseHeader &resp) | ||
{ | ||
Bunny * bunny = BunnyManager::GetBunny(this, http.property("BunnyID").toByteArray()); | ||
|
||
if (resp.statusCode() != 200) | ||
{ | ||
http.abort(); | ||
LogWarning("Connection error"); | ||
} | ||
else { | ||
xml.addData(http.readAll()); | ||
|
||
while (!xml.atEnd()) { | ||
xml.readNext(); | ||
if (xml.isStartElement()) { | ||
currentTag = xml.name().toString(); | ||
} else if (xml.isCharacters() && !xml.isWhitespace()) { | ||
if (currentTag == "fullcount") | ||
{ | ||
bool ok; | ||
emailsCount = xml.text().toString().toInt(&ok); | ||
if (emailsCount > 0) | ||
{ | ||
bunny->SendPacket(AmbientPacket(AmbientPacket::Service_Nose, 1)); | ||
|
||
} | ||
else | ||
{ | ||
bunny->SendPacket(AmbientPacket(AmbientPacket::Service_Nose, 0)); | ||
|
||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
/******* | ||
* API * | ||
*******/ | ||
|
||
void PluginGmail::InitApiCalls() | ||
{ | ||
DECLARE_PLUGIN_BUNNY_API_CALL("setConfig()", PluginGmail, Api_SetConfig); | ||
DECLARE_PLUGIN_BUNNY_API_CALL("getConfig()", PluginGmail, Api_GetConfig); | ||
} | ||
|
||
|
||
|
||
PLUGIN_BUNNY_API_CALL(PluginGmail::Api_SetConfig) | ||
{ | ||
Q_UNUSED(account); | ||
|
||
|
||
if(!hRequest.HasArg("Frequency")) | ||
return new ApiManager::ApiError(QString("Missing argument 'Frequency' for plugin Gmail")); | ||
if(!hRequest.HasArg("Email")) | ||
return new ApiManager::ApiError(QString("Missing argument 'Email' for plugin Gmail")); | ||
if(!hRequest.HasArg("Password")) | ||
return new ApiManager::ApiError(QString("Missing argument 'Password' for plugin Gmail")); | ||
|
||
bunny->SetPluginSetting(GetName(), "Frequency", hRequest.GetArg("Frequency")); | ||
bunny->SetPluginSetting(GetName(), "Email", hRequest.GetArg("Email")); | ||
bunny->SetPluginSetting(GetName(), "Password", hRequest.GetArg("Password")); | ||
|
||
return new ApiManager::ApiOk(QString("Account '%1' will be verified every '%2' minute(s) for bunny '%3'").arg(hRequest.GetArg("Email"),hRequest.GetArg("Frequency"), QString(bunny->GetID()))); | ||
} | ||
|
||
PLUGIN_BUNNY_API_CALL(PluginGmail::Api_GetConfig) | ||
{ | ||
Q_UNUSED(account); | ||
Q_UNUSED(hRequest); | ||
|
||
QList<QString> list; | ||
list.append(bunny->GetPluginSetting(GetName(), "Frequency", QString()).toString()); | ||
list.append(bunny->GetPluginSetting(GetName(), "Email", QString()).toString()); | ||
list.append(bunny->GetPluginSetting(GetName(), "Password", QString()).toString()); | ||
|
||
return new ApiManager::ApiList(list); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#ifndef _PLUGINGMAIL_H_ | ||
#define _PLUGINGMAIL_H_ | ||
|
||
#include <QHttp> | ||
#include <QMultiMap> | ||
#include <QTextStream> | ||
#include <QThread> | ||
#include <QTcpSocket> | ||
#include "plugininterface.h" | ||
#include <QXmlStreamReader> | ||
|
||
class PluginGmail : public PluginInterface | ||
{ | ||
Q_OBJECT | ||
Q_INTERFACES(PluginInterface) | ||
|
||
public: | ||
PluginGmail(); | ||
virtual ~PluginGmail(); | ||
void OnCron(Bunny*, QVariant); | ||
void OnBunnyConnect(Bunny *); | ||
void OnBunnyDisconnect(Bunny *); | ||
void InitApiCalls(); | ||
PLUGIN_BUNNY_API_CALL(Api_SetConfig); | ||
PLUGIN_BUNNY_API_CALL(Api_GetConfig); | ||
|
||
private: | ||
QMap<Bunny*, QString> bunnyList; | ||
QTcpSocket *socket; | ||
int emailsCount; | ||
int connectionId; | ||
QXmlStreamReader xml; | ||
QHttp http; | ||
QString currentTag; | ||
|
||
|
||
private slots: | ||
void readData(const QHttpResponseHeader &); | ||
|
||
|
||
|
||
}; | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
TEMPLATE = subdirs | ||
SUBDIRS = system clock colorbreathing dice sleep test tts tv packet music ephemeride taichi surprise weather webradio ears airquality cinema wizzflux ratp memo callurl | ||
SUBDIRS = system clock colorbreathing dice sleep test tts tv packet music ephemeride taichi surprise weather webradio ears airquality cinema wizzflux ratp memo callurl gmail |