2
* Copyright (c) 2010 Mark Liversedge (liversedge@gmail.com)
4
* This program is free software; you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License as published by the Free
6
* Software Foundation; either version 2 of the License, or (at your option)
9
* This program is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14
* You should have received a copy of the GNU General Public License along
15
* with this program; if not, write to the Free Software Foundation, Inc., 51
16
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
#include "CalendarDownload.h"
21
#include "ICalendar.h"
22
#include <libical/ical.h>
25
CalendarDownload::CalendarDownload(MainWindow *main) : main(main)
27
nam = new QNetworkAccessManager(this);
28
connect(nam, SIGNAL(finished(QNetworkReply*)), this, SLOT(downloadFinished(QNetworkReply*)));
32
CalendarDownload::download()
34
QString request = appsettings->cvalue(main->cyclist, GC_WEBCAL_URL, "").toString();
35
if (request == "") return false;
37
// change webcal to http, since it is basically the same port
38
QRegExp webcal("^webcal:");
39
request.replace(webcal, QString("http:"));
42
QNetworkReply *reply = nam->get(QNetworkRequest(QUrl(request)));
44
if (reply->error() != QNetworkReply::NoError) {
45
QMessageBox::warning(main, tr("Calendar Data Download"), reply->errorString());
52
CalendarDownload::downloadFinished(QNetworkReply *reply)
54
QString fulltext = reply->readAll();
58
QString remoteCache = main->home.absolutePath()+"/remote.ics";
59
QFile remoteCacheFile(remoteCache);
63
// update remote cache - write to it!
64
remoteCacheFile.open(QFile::ReadWrite | QFile::Text);
65
QTextStream out(&remoteCacheFile);
67
remoteCacheFile.close();
71
if (remoteCacheFile.exists()) {
73
msgBox.setText(tr("Remote Calendar not available, reverting to cached workouts."));
74
msgBox.setIcon(QMessageBox::Information);
78
// read in the whole thing
79
remoteCacheFile.open(QFile::ReadOnly | QFile::Text);
80
QTextStream in(&remoteCacheFile);
81
fulltext = in.readAll();
82
remoteCacheFile.close();
86
if (fulltext != "") main->rideCalendar->refreshRemote(fulltext);