File indexing completed on 2024-12-22 05:07:40
0001 /* 0002 * SPDX-FileCopyrightText: 2014 Sandro Knauß <knauss@kolabsys.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 // This code was taken from kmail-account-wizard 0008 0009 #include "autoconfigkolabfreebusy.h" 0010 0011 #include <QDomDocument> 0012 0013 AutoconfigKolabFreebusy::AutoconfigKolabFreebusy(QObject *parent) 0014 : AutoconfigKolabMail(parent) 0015 { 0016 } 0017 0018 void AutoconfigKolabFreebusy::lookupInDb(bool auth, bool crypt) 0019 { 0020 if (serverType() == DataBase) { 0021 setServerType(IspAutoConfig); 0022 } 0023 0024 startJob(lookupUrl(QStringLiteral("freebusy"), QStringLiteral("1.0"), auth, crypt)); 0025 } 0026 0027 void AutoconfigKolabFreebusy::parseResult(const QDomDocument &document) 0028 { 0029 const QDomElement docElem = document.documentElement(); 0030 const QDomNodeList l = docElem.elementsByTagName(QStringLiteral("freebusyProvider")); 0031 0032 if (l.isEmpty()) { 0033 Q_EMIT finished(false); 0034 return; 0035 } 0036 0037 for (int i = 0; i < l.count(); ++i) { 0038 QDomElement e = l.at(i).toElement(); 0039 freebusy s = createFreebusyServer(e); 0040 if (s.isValid()) { 0041 mFreebusyServer[e.attribute(QStringLiteral("id"))] = s; 0042 } 0043 } 0044 0045 Q_EMIT finished(true); 0046 } 0047 0048 freebusy AutoconfigKolabFreebusy::createFreebusyServer(const QDomElement &n) 0049 { 0050 QDomNode o = n.firstChild(); 0051 freebusy s; 0052 while (!o.isNull()) { 0053 QDomElement f = o.toElement(); 0054 if (!f.isNull()) { 0055 const QString tagName(f.tagName()); 0056 if (tagName == QLatin1String("hostname")) { 0057 s.hostname = replacePlaceholders(f.text()); 0058 } else if (tagName == QLatin1String("port")) { 0059 s.port = f.text().toInt(); 0060 } else if (tagName == QLatin1String("socketType")) { 0061 const QString type(f.text()); 0062 if (type == QLatin1String("plain")) { 0063 s.socketType = None; 0064 } else if (type == QLatin1String("SSL")) { 0065 s.socketType = SSL; 0066 } 0067 if (type == QLatin1String("TLS")) { 0068 s.socketType = StartTLS; 0069 } 0070 } else if (tagName == QLatin1String("username")) { 0071 s.username = replacePlaceholders(f.text()); 0072 } else if (tagName == QLatin1String("password")) { 0073 s.password = f.text(); 0074 } else if (tagName == QLatin1String("authentication")) { 0075 const QString type(f.text()); 0076 if (type == QLatin1String("none") || type == QLatin1String("plain")) { 0077 s.authentication = Plain; 0078 } else if (type == QLatin1String("basic")) { 0079 s.authentication = Basic; 0080 } 0081 } else if (tagName == QLatin1String("path")) { 0082 s.path = f.text(); 0083 } 0084 } 0085 o = o.nextSibling(); 0086 } 0087 return s; 0088 } 0089 0090 QHash<QString, freebusy> AutoconfigKolabFreebusy::freebusyServers() const 0091 { 0092 return mFreebusyServer; 0093 }