File indexing completed on 2025-01-19 03:55:41
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2017-01-24 0007 * Description : Web Service settings container. 0008 * 0009 * SPDX-FileCopyrightText: 2017-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * SPDX-FileCopyrightText: 2018 by Thanh Trung Dinh <dinhthanhtrung1996 at gmail dot com> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #include "wssettings.h" 0017 0018 // Qt includes 0019 0020 0021 // KDE includes 0022 0023 #include <klocalizedstring.h> 0024 #include <kconfiggroup.h> 0025 0026 // Local includes 0027 0028 #include "wstoolutils.h" 0029 #include "o0globals.h" 0030 0031 namespace Digikam 0032 { 0033 0034 WSSettings::WSSettings(QObject* const parent) 0035 : QObject (parent), 0036 selMode (EXPORT), 0037 addFileProperties (false), 0038 imagesChangeProp (false), 0039 removeMetadata (false), 0040 imageCompression (75), 0041 attLimitInMbytes (17), 0042 webService (FLICKR), 0043 userName (QString()), 0044 currentAlbumId (QString()), 0045 imageSize (1024), 0046 imageFormat (JPEG) 0047 { 0048 oauthSettings = WSToolUtils::getOauthSettings(parent); 0049 oauthSettingsStore = new O0SettingsStore(oauthSettings, QLatin1String(O2_ENCRYPTION_KEY), this); 0050 } 0051 0052 WSSettings::~WSSettings() 0053 { 0054 delete oauthSettings; 0055 delete oauthSettingsStore; 0056 } 0057 0058 void WSSettings::readSettings(KConfigGroup& group) 0059 { 0060 selMode = (Selection)group.readEntry("SelMode", 0061 (int)EXPORT); 0062 addFileProperties = group.readEntry("AddCommentsAndTags", 0063 false); 0064 imagesChangeProp = group.readEntry("ImagesChangeProp", 0065 false); 0066 removeMetadata = group.readEntry("RemoveMetadata", 0067 false); 0068 imageCompression = group.readEntry("ImageCompression", 0069 75); 0070 attLimitInMbytes = group.readEntry("AttLimitInMbytes", 0071 17); 0072 webService = (WebService)group.readEntry("WebService", 0073 (int)FLICKR); 0074 userName = group.readEntry("UserName", 0075 QString()); 0076 currentAlbumId = group.readEntry("Album", 0077 QString()); 0078 imageSize = group.readEntry("ImageSize", 0079 1024); 0080 imageFormat = (ImageFormat)group.readEntry("ImageFormat", 0081 (int)JPEG); 0082 } 0083 0084 void WSSettings::writeSettings(KConfigGroup& group) 0085 { 0086 group.writeEntry("SelMode", (int)selMode); 0087 group.writeEntry("AddCommentsAndTags", addFileProperties); 0088 group.writeEntry("ImagesChangeProp", imagesChangeProp); 0089 group.writeEntry("RemoveMetadata", removeMetadata); 0090 group.writeEntry("ImageCompression", imageCompression); 0091 group.writeEntry("AttLimitInMbytes", attLimitInMbytes); 0092 group.writeEntry("WebService", (int)webService); 0093 group.writeEntry("UserName", userName); 0094 group.writeEntry("Album", currentAlbumId); 0095 group.writeEntry("ImageSize", imageSize); 0096 group.writeEntry("ImageFormat", (int)imageFormat); 0097 } 0098 0099 QString WSSettings::format() const 0100 { 0101 if (imageFormat == JPEG) 0102 { 0103 return QLatin1String("JPEG"); 0104 } 0105 0106 return QLatin1String("PNG"); 0107 } 0108 0109 QMap<WSSettings::WebService, QString> WSSettings::webServiceNames() 0110 { 0111 QMap<WebService, QString> services; 0112 0113 services[FLICKR] = i18nc("Web Service: FLICKR", "Flickr"); 0114 services[DROPBOX] = i18nc("Web Service: DROPBOX", "Dropbox"); 0115 services[IMGUR] = i18nc("Web Service: IMGUR", "Imgur"); 0116 services[FACEBOOK] = i18nc("Web Service: FACEBOOK", "Facebook"); 0117 services[SMUGMUG] = i18nc("Web Service: SMUGMUG", "Smugmug"); 0118 services[GDRIVE] = i18nc("Web Service: GDRIVE", "Google Drive"); 0119 services[GPHOTO] = i18nc("Web Service: GPHOTO", "Google Photo"); 0120 0121 return services; 0122 } 0123 0124 QMap<WSSettings::ImageFormat, QString> WSSettings::imageFormatNames() 0125 { 0126 QMap<ImageFormat, QString> frms; 0127 0128 frms[JPEG] = i18nc("Image format: JPEG", "Jpeg"); 0129 frms[PNG] = i18nc("Image format: PNG", "Png"); 0130 0131 return frms; 0132 } 0133 0134 QStringList WSSettings::allUserNames(const QString& serviceName) 0135 { 0136 QStringList userNames; 0137 0138 oauthSettings->beginGroup(serviceName); 0139 oauthSettings->beginGroup(QLatin1String("users")); 0140 userNames = oauthSettings->allKeys(); 0141 oauthSettings->endGroup(); 0142 oauthSettings->endGroup(); 0143 0144 return userNames; 0145 } 0146 0147 } // namespace Digikam 0148 0149 #include "moc_wssettings.cpp"