1 /* ============================================================
2 *
3 * This file is a part of digiKam project
4 * https://www.digikam.org
5 *
6 * Date : 2017-01-24
7 * Description : Web Service settings container.
8 *
9 * Copyright (C) 2017-2021 by Gilles Caulier <caulier dot gilles at gmail dot com>
10 * Copyright (C) 2018 by Thanh Trung Dinh <dinhthanhtrung1996 at gmail dot com>
11 *
12 * This program is free software; you can redistribute it
13 * and/or modify it under the terms of the GNU General
14 * Public License as published by the Free Software Foundation;
15 * either version 2, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * ============================================================ */
23
24 #include "wssettings.h"
25
26 // Qt includes
27
28 #include <QSettings>
29
30 // KDE includes
31
32 #include <klocalizedstring.h>
33 #include <kconfiggroup.h>
34
35 // Local includes
36
37 #include "wstoolutils.h"
38 #include "o0globals.h"
39
40 namespace Digikam
41 {
42
WSSettings(QObject * const parent)43 WSSettings::WSSettings(QObject* const parent)
44 : QObject (parent),
45 selMode (EXPORT),
46 addFileProperties (false),
47 imagesChangeProp (false),
48 removeMetadata (false),
49 imageCompression (75),
50 attLimitInMbytes (17),
51 webService (FLICKR),
52 userName (QString()),
53 currentAlbumId (QString()),
54 imageSize (1024),
55 imageFormat (JPEG)
56 {
57 oauthSettings = WSToolUtils::getOauthSettings(parent);
58 oauthSettingsStore = new O0SettingsStore(oauthSettings, QLatin1String(O2_ENCRYPTION_KEY), this);
59 }
60
~WSSettings()61 WSSettings::~WSSettings()
62 {
63 delete oauthSettings;
64 delete oauthSettingsStore;
65 }
66
readSettings(KConfigGroup & group)67 void WSSettings::readSettings(KConfigGroup& group)
68 {
69 selMode = (Selection)group.readEntry("SelMode",
70 (int)EXPORT);
71 addFileProperties = group.readEntry("AddCommentsAndTags",
72 false);
73 imagesChangeProp = group.readEntry("ImagesChangeProp",
74 false);
75 removeMetadata = group.readEntry("RemoveMetadata",
76 false);
77 imageCompression = group.readEntry("ImageCompression",
78 75);
79 attLimitInMbytes = group.readEntry("AttLimitInMbytes",
80 17);
81 webService = (WebService)group.readEntry("WebService",
82 (int)FLICKR);
83 userName = group.readEntry("UserName",
84 QString());
85 currentAlbumId = group.readEntry("Album",
86 QString());
87 imageSize = group.readEntry("ImageSize",
88 1024);
89 imageFormat = (ImageFormat)group.readEntry("ImageFormat",
90 (int)JPEG);
91 }
92
writeSettings(KConfigGroup & group)93 void WSSettings::writeSettings(KConfigGroup& group)
94 {
95 group.writeEntry("SelMode", (int)selMode);
96 group.writeEntry("AddCommentsAndTags", addFileProperties);
97 group.writeEntry("ImagesChangeProp", imagesChangeProp);
98 group.writeEntry("RemoveMetadata", removeMetadata);
99 group.writeEntry("ImageCompression", imageCompression);
100 group.writeEntry("AttLimitInMbytes", attLimitInMbytes);
101 group.writeEntry("WebService", (int)webService);
102 group.writeEntry("UserName", userName);
103 group.writeEntry("Album", currentAlbumId);
104 group.writeEntry("ImageSize", imageSize);
105 group.writeEntry("ImageFormat", (int)imageFormat);
106 }
107
format() const108 QString WSSettings::format() const
109 {
110 if (imageFormat == JPEG)
111 {
112 return QLatin1String("JPEG");
113 }
114
115 return QLatin1String("PNG");
116 }
117
webServiceNames()118 QMap<WSSettings::WebService, QString> WSSettings::webServiceNames()
119 {
120 QMap<WebService, QString> services;
121
122 services[FLICKR] = i18nc("Web Service: FLICKR", "Flickr");
123 services[DROPBOX] = i18nc("Web Service: DROPBOX", "Dropbox");
124 services[IMGUR] = i18nc("Web Service: IMGUR", "Imgur");
125 services[FACEBOOK] = i18nc("Web Service: FACEBOOK", "Facebook");
126 services[SMUGMUG] = i18nc("Web Service: SMUGMUG", "Smugmug");
127 services[GDRIVE] = i18nc("Web Service: GDRIVE", "Google Drive");
128 services[GPHOTO] = i18nc("Web Service: GPHOTO", "Google Photo");
129
130 return services;
131 }
132
imageFormatNames()133 QMap<WSSettings::ImageFormat, QString> WSSettings::imageFormatNames()
134 {
135 QMap<ImageFormat, QString> frms;
136
137 frms[JPEG] = i18nc("Image format: JPEG", "Jpeg");
138 frms[PNG] = i18nc("Image format: PNG", "Png");
139
140 return frms;
141 }
142
allUserNames(const QString & serviceName)143 QStringList WSSettings::allUserNames(const QString& serviceName)
144 {
145 QStringList userNames;
146
147 oauthSettings->beginGroup(serviceName);
148 oauthSettings->beginGroup(QLatin1String("users"));
149 userNames = oauthSettings->allKeys();
150 oauthSettings->endGroup();
151 oauthSettings->endGroup();
152
153 return userNames;
154 }
155
156 } // namespace Digikam
157