This commit is contained in:
Atlante45 2014-07-01 12:57:39 -07:00
parent 958367f579
commit e9826250cb
3 changed files with 21 additions and 18 deletions

View file

@ -398,22 +398,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
}
Application::~Application() {
// In order to get the end of the session, we nned to give the account manager enough time to send the packet.
QEventLoop loop;
// Here we connect the callbacks to stop the event loop
JSONCallbackParameters params;
params.jsonCallbackReceiver = &loop;
params.errorCallbackReceiver = &loop;
params.jsonCallbackMethod = "quit";
params.errorCallbackMethod = "quit";
// In case something goes wrong, we also setup a timer so that the delai is not greater than DELAY_TIME
int DELAY_TIME = 1000;
QTimer timer;
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
// Now we can log it
UserActivityLogger::getInstance().close(params);
timer.start(DELAY_TIME);
loop.exec();
UserActivityLogger::getInstance().close(DELAY_TIME);
qInstallMessageHandler(NULL);

View file

@ -11,8 +11,10 @@
#include "UserActivityLogger.h"
#include <QHttpMultiPart>
#include <QEventLoop>
#include <QJsonDocument>
#include <QHttpMultiPart>
#include <QTimer>
static const QString USER_ACTIVITY_URL = "/api/v1/user_activities";
@ -76,9 +78,24 @@ void UserActivityLogger::launch(QString applicationVersion) {
logAction(ACTION_NAME, actionDetails);
}
void UserActivityLogger::close(JSONCallbackParameters params) {
void UserActivityLogger::close(int delayTime) {
const QString ACTION_NAME = "close";
// In order to get the end of the session, we need to give the account manager enough time to send the packet.
QEventLoop loop;
// Here we connect the callbacks to stop the event loop
JSONCallbackParameters params;
params.jsonCallbackReceiver = &loop;
params.errorCallbackReceiver = &loop;
params.jsonCallbackMethod = "quit";
params.errorCallbackMethod = "quit";
// In case something goes wrong, we also setup a timer so that the delai is not greater than delayTime
QTimer timer;
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
// Now we can log it
logAction(ACTION_NAME, QJsonObject(), params);
timer.start(delayTime);
loop.exec();
}
void UserActivityLogger::changedDisplayName(QString displayName) {

View file

@ -29,7 +29,7 @@ public slots:
void logAction(QString action, QJsonObject details = QJsonObject(), JSONCallbackParameters params = JSONCallbackParameters());
void launch(QString applicationVersion);
void close(JSONCallbackParameters params = JSONCallbackParameters());
void close(int delayTime);
void changedDisplayName(QString displayName);
void changedModel(QString typeOfModel, QString modelURL);
void changedDomain(QString domainURL);