-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.cpp
More file actions
132 lines (111 loc) · 3.99 KB
/
controller.cpp
File metadata and controls
132 lines (111 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include "controller.h"
#include <QDebug>
#include <QTimer>
#include <QProcess>
#include <QDir>
#include "speech.h"
QString pathToProject = "/media/smartmirror2";
QTimer *timerGit;
Controller::Controller(QObject *parent) : QObject(parent)
{
timerGit = new QTimer(this);
connect(timerGit, SIGNAL(timeout()), this, SLOT(onCheckGitVersion()));
timerGit->start(10000);
// m_settings.clear();
// m_settings.setValue("123", "123");
// m_settings.setValue("gitVersion", 123);
if(!m_settings.contains("firstTime")){
m_settings.setValue("firstTime", true);
// QFile f(QDir::homePath()+"/test.txt");
// QString command = "cd "+pathToProject+" && git show --name-only >"+QDir::homePath()+"/test.txt";
// system(command.toLatin1());
// f.open(QFile::ReadOnly | QFile::Text);
// QTextStream in(&f);
// //in.readAll().remove(" ").split("\n").at(4);
// m_settings.setValue("gitVersion", in.readAll().split("\n").at(0).split(" ").at(1));
// system("pip install tweepy");
// QProcess process;
// process.start("pip install tweepy");
system("pip install tweepy");
Speech speech;
speech.sayWelcome();
} else {
m_settings.setValue("firstTime", false);
}
}
bool Controller::setNewUser(QString info)
{
m_settings.setValue(info, info);
return true;
}
bool Controller::isThereUser(QString user)
{
return m_settings.contains(user);
}
bool Controller::firstTimeApp()
{
//returns if it's first time that the app is openned
return m_settings.value("firstTime").toBool();
}
void Controller::onCheckGitVersion()
{
QString command = "> "+QDir::tempPath()+"/tempSmartMirror.txt &&"+"cd "+pathToProject+" && git pull >"+QDir::tempPath()+"/tempSmartMirror.txt";
system(command.toLatin1());
QFile f(QDir::tempPath()+"/tempSmartMirror.txt");
f.open(QFile::ReadOnly | QFile::Text);
QTextStream in(&f);
QString version = in.readAll();
f.close();
if(version != "Already up-to-date.\n"){
QString command = "> "+QDir::tempPath()+"/tempSmartMirror.txt &&"+"cd "+pathToProject+" && git log -1 >"+QDir::tempPath()+"/tempSmartMirror.txt";
system(command.toLatin1());
QFile f(QDir::tempPath()+"/tempSmartMirror.txt");
f.open(QFile::ReadOnly | QFile::Text);
QTextStream in(&f);
QString lastestCommit = in.readAll().remove(" ").split("\n").at(4);
f.close();
emit hasUpdate(lastestCommit);
} else {
qDebug() << __func__ << "Already up-to-date.";
}
}
void Controller::updateApp()
{
timerGit->stop();
QString command = "cd "+pathToProject+" && " +
"cd .. && cp -r smartmirror2 /tmp";
system(command.toLatin1());
emit progress("A aplicação será reiniciada... ");
command = "cd /tmp/smartmirror2 && qmake ";
system(command.toLatin1());
emit progress("A aplicação será reiniciada... ");
command = "cd /tmp/smartmirror2 && make && rm /usr/bin/smartmirror2 && cp smartmirror2 /usr/bin";
system(command.toLatin1());
command = "reboot";
system(command.toLatin1());
// m_settings.setValue("gitVersion", version.split("\n").at(0).split(" ").at(1));
// m_settings.sync();
timerGit->start();
}
void Controller::getTwitter() {
QString filename1 = QString(pathToProject+"/twitter/twitter_time_line.py");
QString filename2 = QString("p_pedrinhu");
QString filename3 = QString(pathToProject+"/twitter/");
QString cmd_qt = QString("python %1 %2 %3").arg(filename1).arg(filename2).arg(filename3);
qDebug()<<cmd_qt;
const char* cmd = cmd_qt.toLocal8Bit().constData();
system(cmd);
QFile file(filename3+filename2+".csv");
if (!file.open(QIODevice::ReadOnly))
{
qDebug() << file.errorString();
// return 1;
}
QStringList wordList;
while (!file.atEnd())
{
QByteArray line = file.readLine();
wordList.append(line.split(',').first());
}
emit answerTwitter(wordList);
}