diff --git a/src/common/davcollectionsfetchjob.h b/src/common/davcollectionsfetchjob.h --- a/src/common/davcollectionsfetchjob.h +++ b/src/common/davcollectionsfetchjob.h @@ -78,6 +78,7 @@ void collectionsFetchFinished(KJob *); void doCollectionsFetch(const QUrl &url); void subjobFinished(); + QColor colorFromText(QString colorValue); DavUrl mUrl; DavCollection::List mCollections; diff --git a/src/common/davcollectionsfetchjob.cpp b/src/common/davcollectionsfetchjob.cpp --- a/src/common/davcollectionsfetchjob.cpp +++ b/src/common/davcollectionsfetchjob.cpp @@ -299,10 +299,7 @@ const QDomElement colorElement = Utils::firstChildElementNS(propElement, QStringLiteral("http://apple.com/ns/ical/"), QStringLiteral("calendar-color")); QColor color; if (!colorElement.isNull()) { - QString colorValue = colorElement.text(); - if (QColor::isValidColor(colorValue)) { - color.setNamedColor(colorValue); - } + color = this->colorFromText(colorElement.text()); } // extract allowed content types @@ -346,3 +343,25 @@ } } +QColor DavCollectionsFetchJob::colorFromText(QString colorValue) { + // Color is of type "#RRGGBB" or "#RRGGBBAA" + if (colorValue.size() < 7) { + return QColor(); + } + + // If no alpha channel, define it as FF + if (colorValue.size() == 7) { + colorValue.append(QStringLiteral("FF")); + } + + QList intColorValues; + bool correctConversion; + for (int i = 0 ; i < 4 ; i++) { + intColorValues[i] = colorValue.mid(1 + 2*i, 2).toInt(&correctConversion, 16); + if (!correctConversion) { + return QColor(); + } + } + + return QColor(intColorValues[0], intColorValues[1], intColorValues[2], intColorValues[3]); +}