diff --git a/src/CalDAV.cpp b/src/CalDAV.cpp index eb2a3a66e..32eba481c 100644 --- a/src/CalDAV.cpp +++ b/src/CalDAV.cpp @@ -21,7 +21,7 @@ CalDAV::CalDAV(MainWindow *main) : main(main), mode(None) { nam = new QNetworkAccessManager(this); - connect(nam, SIGNAL(finished(QNetworkReply*)), this, SLOT(authenticateResponse(QNetworkReply*))); + connect(nam, SIGNAL(finished(QNetworkReply*)), this, SLOT(requestReply(QNetworkReply*))); connect(nam, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), this, SLOT(userpass(QNetworkReply*,QAuthenticator*))); @@ -29,8 +29,11 @@ CalDAV::CalDAV(MainWindow *main) : main(main), mode(None) // SLOT(sslErrors(QNetworkReply*,QList))); } +// +// GET event directory listing +// bool -CalDAV::authenticate() +CalDAV::download() { QString url = appsettings->cvalue(main->cyclist, GC_DVURL, "").toString(); if (url == "") return false; // not configured @@ -46,35 +49,44 @@ CalDAV::authenticate() return true; } -void -CalDAV::authenticateResponse(QNetworkReply *reply) + +// +// REPORT of "all" VEVENTS +// +bool +CalDAV::report() { - switch (mode) { - case Events: - main->rideCalendar->refreshRemote(reply->readAll()); - break; - default: - case Put: - break; + QString url = appsettings->cvalue(main->cyclist, GC_DVURL, "").toString(); + if (url == "") return false; // not configured + + QNetworkRequest request = QNetworkRequest(QUrl(url)); + QByteArray *queryText = new QByteArray("" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + ""); + + QBuffer *query = new QBuffer(queryText); + + mode = Report; + QNetworkReply *reply = nam->sendCustomRequest(request, "REPORT", query); + if (reply->error() != QNetworkReply::NoError) { + QMessageBox::warning(main, tr("CalDAV REPORT url error"), reply->errorString()); + mode = None; + return false; } - mode = None; + return true; } -void -CalDAV::userpass(QNetworkReply*,QAuthenticator*a) -{ - QString user = appsettings->cvalue(main->cyclist, GC_DVUSER, "").toString(); - QString pass = appsettings->cvalue(main->cyclist, GC_DVPASS, "").toString(); - a->setUser(user); - a->setPassword(pass); -} - -void -CalDAV::sslErrors(QNetworkReply*,QList&) -{ -} - -// convert a rideItem into a vcard ICal Event +// utility function to create a VCALENDAR from a single RideItem static icalcomponent *createEvent(RideItem *rideItem) { @@ -141,6 +153,9 @@ icalcomponent *createEvent(RideItem *rideItem) return root; } +// +// PUT a ride item +// bool CalDAV::upload(RideItem *rideItem) { @@ -174,3 +189,41 @@ CalDAV::upload(RideItem *rideItem) return true; } +// +// All queries/commands respond here +// +void +CalDAV::requestReply(QNetworkReply *reply) +{ + QString response = reply->readAll(); + switch (mode) { + case Report: + case Events: + main->rideCalendar->refreshRemote(response); + break; + default: + case Put: + break; + } + mode = None; +} + +// +// Provide user credentials, called when receive a 401 +// +void +CalDAV::userpass(QNetworkReply*,QAuthenticator*a) +{ + QString user = appsettings->cvalue(main->cyclist, GC_DVUSER, "").toString(); + QString pass = appsettings->cvalue(main->cyclist, GC_DVPASS, "").toString(); + a->setUser(user); + a->setPassword(pass); +} + +// +// Trap SSL errors, does nothing ... for now +// +void +CalDAV::sslErrors(QNetworkReply*,QList&) +{ +} diff --git a/src/CalDAV.h b/src/CalDAV.h index 513ae52c1..ed06339cb 100644 --- a/src/CalDAV.h +++ b/src/CalDAV.h @@ -51,7 +51,7 @@ class CalDAV : public QObject Q_OBJECT G_OBJECT - enum action { Put, Get, Events, None }; + enum action { Put, Get, Events, Report, None }; typedef enum action ActionType; public: @@ -61,20 +61,22 @@ public: public slots: // authentication (and refresh all events) - bool authenticate(); + bool download(); - // upload ride and data (as attachment) to calendar + // Query CalDAV server for events ... + bool report(); + + // Upload ride as a VEVENT bool upload(RideItem *rideItem); + // Catch NAM signals ... + void requestReply(QNetworkReply *reply); void userpass(QNetworkReply*r,QAuthenticator*a); void sslErrors(QNetworkReply*,QList&); - void authenticateResponse(QNetworkReply *reply); private: MainWindow *main; QNetworkAccessManager *nam; ActionType mode; - -/* CalendarParser *parser; */ }; #endif diff --git a/src/DiaryWindow.cpp b/src/DiaryWindow.cpp index bdd77f59d..6cc191b95 100644 --- a/src/DiaryWindow.cpp +++ b/src/DiaryWindow.cpp @@ -36,9 +36,8 @@ DiaryWindow::DiaryWindow(MainWindow *mainWindow) : bold.setPointSize(14); bold.setWeight(QFont::Bold); title = new QLabel("", this); + title->setAlignment(Qt::AlignCenter | Qt::AlignVCenter); title->setFont(bold); - title->setFixedWidth(250); - title->setAlignment(Qt::AlignCenter); QIcon prevIcon(":images/toolbar/back_alt.png"); QIcon nextIcon(":images/toolbar/forward_alt.png"); @@ -59,15 +58,11 @@ DiaryWindow::DiaryWindow(MainWindow *mainWindow) : viewMode->setCurrentIndex(appsettings->cvalue(mainWindow->cyclist, GC_DIARY_VIEW, "1").toInt()); - QLabel *spacer = new QLabel(this); - spacer->setFixedWidth(120); // same as viewMode, centering controls... - - controls->addWidget(spacer); - controls->addStretch(); controls->addWidget(prev); - controls->addWidget(title); controls->addWidget(next); controls->addStretch(); + controls->addWidget(title, Qt::AlignCenter | Qt::AlignVCenter); + controls->addStretch(); controls->addWidget(viewMode); vlayout->addLayout(controls); @@ -85,6 +80,7 @@ DiaryWindow::DiaryWindow(MainWindow *mainWindow) : monthlyView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); monthlyView->verticalHeader()->setResizeMode(QHeaderView::Stretch); monthlyView->viewport()->installEventFilter(this); + monthlyView->setGridStyle(Qt::DotLine); // weekly view via QxtScheduleView weeklyView = new QxtScheduleView; diff --git a/src/GcCalendarModel.h b/src/GcCalendarModel.h index 38076b2c8..b8cd61a81 100644 --- a/src/GcCalendarModel.h +++ b/src/GcCalendarModel.h @@ -417,13 +417,13 @@ class GcCalendarDelegate : public QItemDelegate QPen pen; pen.setColor(Qt::black); - pen.setWidth(2); + painter->setPen(Qt::NoPen); QColor fillColor = colors[i++]; - fillColor.setAlpha(250); + fillColor.setAlpha(200); painter->setBrush(fillColor); - painter->setPen(pen); painter->setRenderHint(QPainter::Antialiasing); painter->drawPath(cachePath); + painter->setPen(pen); painter->drawText(bd, text); } } diff --git a/src/ICalendar.cpp b/src/ICalendar.cpp index 506ae80fa..28e72cc44 100644 --- a/src/ICalendar.cpp +++ b/src/ICalendar.cpp @@ -255,16 +255,26 @@ QVariant ICalendar::data(QDate date, int role) QList*p = localCalendar.value(date, NULL); if (p) { foreach(icalcomponent*event, *p) { + QString desc; + icalproperty *summary = icalcomponent_get_first_property(event, ICAL_SUMMARY_PROPERTY); + desc = propertyToString(summary); icalproperty *property = icalcomponent_get_first_property(event, ICAL_DESCRIPTION_PROPERTY); - strings << propertyToString(property); + desc += " "; + desc += propertyToString(property); + strings << desc; } } // remote p = remoteCalendar.value(date, NULL); if (p) { foreach(icalcomponent*event, *p) { + QString desc; + icalproperty *summary = icalcomponent_get_first_property(event, ICAL_SUMMARY_PROPERTY); + desc = propertyToString(summary); icalproperty *property = icalcomponent_get_first_property(event, ICAL_DESCRIPTION_PROPERTY); - strings << propertyToString(property); + desc += " "; + desc += propertyToString(property); + strings << desc; } } return strings; diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 1c832a3b6..2340240ba 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -320,7 +320,7 @@ MainWindow::MainWindow(const QDir &home) : #ifdef GC_HAVE_ICAL rideCalendar = new ICalendar(this); // my local/remote calendar entries davCalendar = new CalDAV(this); // remote caldav - davCalendar->authenticate(); // login + davCalendar->download(); // login #endif QTreeWidgetItem *last = NULL; @@ -1805,7 +1805,7 @@ void MainWindow::refreshCalendar() { #ifdef GC_HAVE_ICAL - davCalendar->authenticate(); + davCalendar->download(); calendarDownload->download(); #endif }