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 133 134 135 136 137 138 139 140 141 142 143
|
#include <QtGui>
#include "notifier.h"
#include <stdio.h>
#include <iostream>
#include <string>
#include <time.h>
#include <vector>
#include <fstream>
#include <ctime>
#include "windows.h"
#include <qmessagebox.h>
#include "adddialog.h"
#include <QString>
using namespace std;
Notifier::Notifier(QWidget *parent)
:QDialog(parent)
{
label = new QLabel(tr("URL: "));
lineEdit = new QLineEdit;
label->setBuddy(lineEdit);
startButton = new QPushButton(tr("&Start"));
// connect(linEdit, SIGNAL(textChanged(const QString &)),
// this, SLOT());
connect(this, SIGNAL(updated()), this, SLOT(addEntry()));
connect(startButton, SIGNAL(clicked()),
this, SLOT(cycle()));
QVBoxLayout *rightLayout = new QVBoxLayout;
rightLayout ->addWidget(startButton);
rightLayout ->addWidget(label);
rightLayout ->addWidget(lineEdit);
QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addLayout(rightLayout);
setLayout(mainLayout);
setWindowTitle(tr("Notifier"));
setFixedHeight(sizeHint().height());
}
vector<string> getInfo2();
void overWrite()
{
ofstream newfile ("C:\\Users\\Alec Cheung\\Notifierv2-build-desktop\\Temp.txt");
int stop = getInfo2().size();
int count = 0;
if (newfile.is_open())
{
while ( count <stop)
{
newfile << getInfo2().at(count)<< endl;
count++;
}
newfile.close();
}
}
vector<string> getInfo1()
{
string tempLine;
vector <string> archiveT;
ifstream tempFile ("C:\\Users\\Alec Cheung\\Notifierv2-build-desktop\\Temp.txt");
if (tempFile.is_open())
{
while (getline (tempFile, tempLine))
{
archiveT.push_back(tempLine);
}
}
return archiveT;
}
vector<string> getInfo2()
{
vector <string> archiveC;
string tempLine;
ifstream curFile ("C:\\Users\\Alec Cheung\\Notifierv2-build-desktop\\Current.txt");
if (curFile.is_open())
{
while (getline (curFile, tempLine))
{
archiveC.push_back(tempLine);
}
}
return archiveC;
}
bool compare(vector<string> original1 , vector<string> latest1)
{
int x = 0;
while (x<original1.size())
{
if (original1[x].compare(latest1[x])!= 0)
{
return true;
}
x++;
}
return false;
}
void hasUpdate()
{
// AddDialog note;
//connect (note,SIGNAL(note.hasUpdate()), this, SLOT(addEntry()));
time_t now;
if (compare(getInfo1(), getInfo2()))
{
time (&now);
// ctime(&now);
emit updated();
//connect(addButton, SIGNAL(clicked()), this, SLOT(addEntry()));
}
}
void Notifier::cycle()
{
int repeat = 86400;
int x = 0;
char* thing = "curl http://www.mangareader.net >Temp.txt";
system(thing); //dumps output from curl into a text file
// while (x<repeat)
// {
//Sleep(7500);
Sleep(2000);
system("curl http://www.mangareader.net > Current.txt");
hasUpdate();
x++;
// }
}
void Notifier::addEntry()
{
AddDialog aDialog;
aDialog.exec();
}
|