File indexing completed on 2025-01-19 03:55:39

0001 #include <cstddef>
0002 
0003 #include "o1smugmug.h"
0004 
0005 static QString basicAuthorizationUrl() {
0006     return "https://secure.smugmug.com/services/oauth/1.0a/authorize";
0007 }
0008 
0009 static const char *accessToString(O1SmugMug::Access access) {
0010     const char * const strings[] = {
0011         "Public",
0012         "Full"
0013     };
0014     const std::size_t stringsSize = sizeof(strings) / sizeof(strings[0]);
0015     Q_ASSERT(access >= 0 && static_cast<std::size_t>(access) < stringsSize
0016                 && "Unsupported SmugMug authorization access!");
0017     Q_UNUSED(stringsSize)
0018 
0019     return strings[access];
0020 }
0021 
0022 static const char *permissionsToString(O1SmugMug::Permissions permissions) {
0023     const char * const strings[] = {
0024         "Read",
0025         "Add",
0026         "Modify"
0027     };
0028     const std::size_t stringsSize = sizeof(strings) / sizeof(strings[0]);
0029     Q_ASSERT(permissions >= 0 && static_cast<std::size_t>(permissions) < stringsSize
0030                 && "Unsupported SmugMug authorization permissions!");
0031     Q_UNUSED(stringsSize)
0032 
0033     return strings[permissions];
0034 }
0035 
0036 
0037 void O1SmugMug::initAuthorizationUrl(Access access, Permissions permissions) {
0038     setAuthorizeUrl(QUrl(::basicAuthorizationUrl()
0039                          + "?Access=" + ::accessToString(access)
0040                          + "&Permissions=" + ::permissionsToString(permissions)));
0041 }
0042 
0043 #if QT_VERSION >= 0x050000
0044 
0045 void O1SmugMug::AuthorizationUrlBuilder::setAccess(Access value) {
0046     query_.addQueryItem("Access", ::accessToString(value));
0047 }
0048 
0049 void O1SmugMug::AuthorizationUrlBuilder::setPermissions(Permissions value) {
0050     query_.addQueryItem("Permissions", ::permissionsToString(value));
0051 }
0052 
0053 void O1SmugMug::AuthorizationUrlBuilder::setAllowThirdPartyLogin(bool value) {
0054     query_.addQueryItem("allowThirdPartyLogin", value ? "1" : "0");
0055 }
0056 
0057 void O1SmugMug::AuthorizationUrlBuilder::setShowSignUpButton(bool value) {
0058     query_.addQueryItem("showSignUpButton", value ? "true" : "false");
0059 }
0060 
0061 void O1SmugMug::AuthorizationUrlBuilder::setPrepopulatedUsername(const QString &value) {
0062     query_.addQueryItem("username", value);
0063 }
0064 
0065 void O1SmugMug::AuthorizationUrlBuilder::setViewportScale(double value) {
0066     Q_ASSERT(value >= 0 && value <= 1 && "Invalid SmugMug authorization viewportScale!");
0067     query_.addQueryItem("viewportScale", QString::number(value, 'f'));
0068 }
0069 
0070 QUrl O1SmugMug::AuthorizationUrlBuilder::url() const {
0071     QUrl result(::basicAuthorizationUrl());
0072     result.setQuery(query_);
0073     return result;
0074 }
0075 
0076 void O1SmugMug::initAuthorizationUrl(const AuthorizationUrlBuilder &builder) {
0077     setAuthorizeUrl(builder.url());
0078 }
0079 
0080 #endif // QT_VERSION >= 0x050000
0081 
0082 O1SmugMug::O1SmugMug(QObject *parent, QNetworkAccessManager *manager, O0AbstractStore *store)
0083     : O1(parent, manager, store) {
0084    setRequestTokenUrl(QUrl("https://secure.smugmug.com/services/oauth/1.0a/getRequestToken"));
0085    setAccessTokenUrl(QUrl("https://secure.smugmug.com/services/oauth/1.0a/getAccessToken"));
0086 }
0087 
0088 #include "moc_o1smugmug.cpp"