Skip to content

Commit

Permalink
Fixed writing empty schedule files and breaking application
Browse files Browse the repository at this point in the history
  • Loading branch information
k0rmarun committed Dec 24, 2016
1 parent 2fa304b commit 828f9a6
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/schedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Schedule::Schedule(QObject *parent) : QObject(parent)
mFilename = mDirname+"/cache.json";
qDebug() << "filename" << mFilename;
nam = new QNetworkAccessManager(this);
mUpdating = false;
emit updatingChanged(mUpdating);
if(!loadFromDisk()){
loadFromNetwork();
}
Expand All @@ -18,10 +20,15 @@ bool Schedule::loadFromDisk(){
QFile file(mFilename);
if(file.open(QIODevice::ReadOnly)){
mSchedule = QString(file.readAll());
emit scheduleChanged(mSchedule);
file.close();
qDebug() << "LOAD FROM DISK SUCCEEDED";
return true;
if(!mSchedule.isEmpty()){
emit scheduleChanged(mSchedule);
qDebug() << "LOAD FROM DISK SUCCEEDED";
return true;
} else {
qDebug() << "LOAD FROM DISK FAILED";
return false;
}
} else {
emit loadFromDiskFailed();
qDebug() << "LOAD FROM DISK FAILED";
Expand All @@ -43,7 +50,7 @@ void Schedule::loadFromNetwork(){
void Schedule::RequestFinished(QNetworkReply *reply){
if(reply->error() == QNetworkReply::NoError){
QString tmp = QString(reply->readAll());
if(mSchedule != tmp){
if(mSchedule != tmp && !tmp.isEmpty()){
mSchedule = tmp;
emit scheduleChanged(mSchedule);
write(mSchedule);
Expand Down

0 comments on commit 828f9a6

Please sign in to comment.