File indexing completed on 2024-12-22 04:56:57
0001 /* 0002 SPDX-FileCopyrightText: 2009 Grégory Oestreicher <greg@kamago.net> 0003 Based on an original work for the IMAP resource which is : 0004 SPDX-FileCopyrightText: 2008 Volker Krause <vkrause@kde.org> 0005 SPDX-FileCopyrightText: 2008 Omat Holding B.V. <info@omat.nl> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #pragma once 0011 0012 #include "settingsbase.h" 0013 0014 #include <KDAV/DavUrl> 0015 0016 #include <QMap> 0017 0018 class Settings : public SettingsBase 0019 { 0020 Q_OBJECT 0021 0022 public: 0023 class UrlConfiguration 0024 { 0025 public: 0026 UrlConfiguration(); 0027 explicit UrlConfiguration(const QString &serialized); 0028 0029 /** 0030 * Serializes the object. 0031 * The string is the concatenation of the fields separated by a "|" : 0032 * user|protocol|url 0033 * The "protocol" component is the symbolic name of the protocol, 0034 * as returned by Utils::protocolName(). 0035 */ 0036 QString serialize(); 0037 QString mUrl; 0038 QString mUser; 0039 QString mPassword; 0040 int mProtocol; 0041 }; 0042 0043 Settings(); 0044 ~Settings() override; 0045 static Settings *self(); 0046 void setWinId(WId wid); 0047 void cleanup(); 0048 0049 void setResourceIdentifier(const QString &identifier); 0050 void setDefaultPassword(const QString &password); 0051 QString defaultPassword(); 0052 0053 KDAV::DavUrl::List configuredDavUrls(); 0054 0055 /** 0056 * Creates and returns the DavUrl that corresponds to the configuration for searchUrl. 0057 * If finalUrl is supplied, then it will be used in the returned object instead of the searchUrl. 0058 */ 0059 KDAV::DavUrl configuredDavUrl(KDAV::Protocol protocol, const QString &searchUrl, const QString &finalUrl = QString()); 0060 0061 /** 0062 * Creates and return the DavUrl from the configured URL that has a mapping with @p collectionUrl. 0063 * If @p finalUrl is supplied it will be used in the returned object, else @p collectionUrl will 0064 * be used. 0065 * If no configured URL can be found the returned DavUrl will have an empty url(). 0066 */ 0067 KDAV::DavUrl davUrlFromCollectionUrl(const QString &collectionUrl, const QString &finalUrl = QString()); 0068 0069 /** 0070 * Add a new mapping between the collection URL, as seen on the backend, and the 0071 * URL configured by the user. A mapping here means that the collectionUrl has 0072 * been discovered by a KDAV::DavCollectionsFetchJob on the configuredUrl. 0073 */ 0074 void addCollectionUrlMapping(KDAV::Protocol protocol, const QString &collectionUrl, const QString &configuredUrl); 0075 0076 /** 0077 * Returns the collections URLs mapped behind @p configuredUrl and @p protocol. 0078 */ 0079 QStringList mappedCollections(KDAV::Protocol protocol, const QString &configuredUrl); 0080 0081 /** 0082 * Reloads the resource configuration taking into account any new modification 0083 * 0084 * Whenever the resource configuration is modified it needs to be reload in order 0085 * to make the resource use the new config. This slot will call the needed methods 0086 * to be sure that any new setting is taken into account. 0087 */ 0088 void reloadConfig(); 0089 0090 void newUrlConfiguration(UrlConfiguration *urlConfig); 0091 void removeUrlConfiguration(KDAV::Protocol protocol, const QString &url); 0092 UrlConfiguration *urlConfiguration(KDAV::Protocol protocol, const QString &url); 0093 0094 // KDAV::Protocol protocol( const QString &url ) const; 0095 QString username(KDAV::Protocol protocol, const QString &url) const; 0096 QString password(KDAV::Protocol protocol, const QString &url); 0097 QDateTime getSyncRangeStart() const; 0098 0099 private: 0100 void buildUrlsList(); 0101 void loadMappings(); 0102 void updateRemoteUrls(); 0103 void savePassword(const QString &key, const QString &user, const QString &password); 0104 QString loadPassword(const QString &key, const QString &user); 0105 QString promptForPassword(const QString &user); 0106 0107 void updateToV2(); 0108 void updateToV3(); 0109 0110 WId mWinId; 0111 QString mResourceIdentifier; 0112 QMap<QString, UrlConfiguration *> mUrls; 0113 QMap<QString, QString> mPasswordsCache; 0114 QString mCollectionsUrlsMappingCache; 0115 QMap<QString, QString> mCollectionsUrlsMapping; 0116 QList<UrlConfiguration *> mToDeleteUrlConfigs; 0117 };