File indexing completed on 2024-12-22 04:45:43

0001 /*
0002    SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "oauthsettingswidget.h"
0008 #include <KLocalizedString>
0009 #include <QCheckBox>
0010 #include <QFormLayout>
0011 #include <QLabel>
0012 #include <QLineEdit>
0013 
0014 OauthSettingsWidget::OauthSettingsWidget(RocketChatAccount *account, QWidget *parent)
0015     : SettingsWidgetBase(account, parent)
0016     , mSignWithApple(new QCheckBox(i18n("Sign in with Apple"), this))
0017     , mAccountsOAuthAppleId(new QLineEdit(this))
0018     , mAccountsOAuthAppleIss(new QLineEdit(this))
0019     , mAccountsOAuthAppleKid(new QLineEdit(this))
0020     , mTwitterLogin(new QCheckBox(i18n("Twitter Login"), this))
0021     , mTwitterId(new QLineEdit(this))
0022     , mTwitterSecret(new QLineEdit(this))
0023     , mTwitterCallbackURL(new QLineEdit(this))
0024     , mLinkedInLogin(new QCheckBox(i18n("LinkedIn Login"), this))
0025     , mLinkedInId(new QLineEdit(this))
0026     , mLinkedInSecret(new QLineEdit(this))
0027     , mLinkedInCallbackURL(new QLineEdit(this))
0028     , mProxyHost(new QLineEdit(this))
0029     , mProxyServices(new QLineEdit(this))
0030     , mMeteorLogin(new QCheckBox(i18n("Meteor Login"), this))
0031     , mMeteorId(new QLineEdit(this))
0032     , mMeteorSecret(new QLineEdit(this))
0033     , mMeteorCallbackURL(new QLineEdit(this))
0034     , mFacebookLogin(new QCheckBox(i18n("Facebook Login"), this))
0035     , mFacebookId(new QLineEdit(this))
0036     , mFacebookSecret(new QLineEdit(this))
0037     , mFacebookCallbackURL(new QLineEdit(this))
0038     , mGithubLogin(new QCheckBox(i18n("Github Login"), this))
0039     , mGithubId(new QLineEdit(this))
0040     , mGithubSecret(new QLineEdit(this))
0041     , mGithubCallbackURL(new QLineEdit(this))
0042     , mTokenpassLogin(new QCheckBox(i18n("Tokenpass Login"), this))
0043     , mTokenpassId(new QLineEdit(this))
0044     , mTokenpassSecret(new QLineEdit(this))
0045     , mTokenpassCallbackURL(new QLineEdit(this))
0046     , mTokenpassServerURL(new QLineEdit(this))
0047     , mGoogleLogin(new QCheckBox(i18n("Google Login"), this))
0048     , mGoogleId(new QLineEdit(this))
0049     , mGoogleSecret(new QLineEdit(this))
0050     , mGoogleCallbackURL(new QLineEdit(this))
0051     , mDolphinUrl(new QLineEdit(this))
0052     , mDolphinEnable(new QCheckBox(i18n("Enable"), this))
0053     , mDolphinId(new QLineEdit(this))
0054     , mDolphinSecret(new QLineEdit(this))
0055 {
0056     auto appleLabel = createBoldLabel(i18n("Apple"));
0057     appleLabel->setObjectName(QStringLiteral("appleLabel"));
0058     mMainLayout->addWidget(appleLabel);
0059 
0060     mSignWithApple->setObjectName(QStringLiteral("mSignWithApple"));
0061     mMainLayout->addWidget(mSignWithApple);
0062     mSignWithApple->setToolTip(i18n("If you want Apple login enabled only on mobile, you can leave all fields empty."));
0063     connectCheckBox(mSignWithApple, QStringLiteral("Accounts_OAuth_Apple"));
0064 
0065     mAccountsOAuthAppleId->setObjectName(QStringLiteral("mAccountsOAuthAppleId"));
0066     addLineEdit(i18n("OAuth Apple Id"), mAccountsOAuthAppleId, QStringLiteral("Accounts_OAuth_Apple_id"));
0067 
0068     mAccountsOAuthAppleIss->setObjectName(QStringLiteral("mAccountsOAuthAppleIss"));
0069     addLineEdit(i18n("OAuth Apple Iss"), mAccountsOAuthAppleIss, QStringLiteral("Accounts_OAuth_Apple_iss"));
0070 
0071     mAccountsOAuthAppleKid->setObjectName(QStringLiteral("AccountsOAuthAppleKid"));
0072     addLineEdit(i18n("OAuth Apple Kid"), mAccountsOAuthAppleKid, QStringLiteral("Accounts_OAuth_Apple_kid"));
0073 
0074     auto dolphinLabel = createBoldLabel(i18n("Dolphin"));
0075     dolphinLabel->setObjectName(QStringLiteral("dolphinLabel"));
0076     mMainLayout->addWidget(dolphinLabel);
0077 
0078     mDolphinUrl->setObjectName(QStringLiteral("mDolphinUrl"));
0079     addLineEdit(i18n("Url"), mDolphinUrl, QStringLiteral("Accounts_OAuth_Dolphin_URL"));
0080 
0081     mDolphinEnable->setObjectName(QStringLiteral("mDolphinEnable"));
0082     mMainLayout->addWidget(mDolphinEnable);
0083     connectCheckBox(mDolphinEnable, QStringLiteral("Accounts_OAuth_Dolphin"));
0084 
0085     mDolphinId->setObjectName(QStringLiteral("mDolphinId"));
0086     addLineEdit(i18n("Id"), mDolphinId, QStringLiteral("Accounts_OAuth_Dolphin_id"));
0087 
0088     mDolphinSecret->setObjectName(QStringLiteral("mDolphinSecret"));
0089     addLineEdit(i18n("Secret"), mDolphinSecret, QStringLiteral("Accounts_OAuth_Dolphin_secret"));
0090     // TODO
0091 
0092     auto twitterLabel = createBoldLabel(i18n("Twitter"));
0093     twitterLabel->setObjectName(QStringLiteral("twitterLabel"));
0094     mMainLayout->addWidget(twitterLabel);
0095 
0096     mTwitterLogin->setObjectName(QStringLiteral("mTwitterLogin"));
0097     mMainLayout->addWidget(mTwitterLogin);
0098     connectCheckBox(mTwitterLogin, QStringLiteral("Accounts_OAuth_Twitter"));
0099 
0100     mTwitterId->setObjectName(QStringLiteral("mTwitterId"));
0101     addLineEdit(i18n("Twitter Id"), mTwitterId, QStringLiteral("Accounts_OAuth_Twitter_id"));
0102 
0103     mTwitterSecret->setObjectName(QStringLiteral("mTwitterSecret"));
0104     addLineEdit(i18n("Twitter Secret"), mTwitterSecret, QStringLiteral("Accounts_OAuth_Twitter_secret"));
0105 
0106     mTwitterCallbackURL->setObjectName(QStringLiteral("mTwitterCallbackURL"));
0107     addLineEdit(i18n("Twitter Secret"), mTwitterCallbackURL, QStringLiteral("Accounts_OAuth_Twitter_callback_url"), true);
0108 
0109     auto linkedInLabel = createBoldLabel(i18n("LinkedIn"));
0110     linkedInLabel->setObjectName(QStringLiteral("linkedInLabel"));
0111     mMainLayout->addWidget(linkedInLabel);
0112 
0113     mLinkedInLogin->setObjectName(QStringLiteral("mLinkedInLogin"));
0114     mMainLayout->addWidget(mLinkedInLogin);
0115     connectCheckBox(mLinkedInLogin, QStringLiteral("Accounts_OAuth_Linkedin"));
0116 
0117     mLinkedInId->setObjectName(QStringLiteral("mLinkedInId"));
0118     addLineEdit(i18n("LinkedIn Id"), mLinkedInId, QStringLiteral("Accounts_OAuth_Linkedin_id"));
0119 
0120     mLinkedInSecret->setObjectName(QStringLiteral("mLinkedInSecret"));
0121     addLineEdit(i18n("LinkedIn Secret"), mLinkedInSecret, QStringLiteral("Accounts_OAuth_Linkedin_secret"));
0122 
0123     mLinkedInCallbackURL->setObjectName(QStringLiteral("mLinkedInCallbackURL"));
0124     addLineEdit(i18n("LinkedIn Secret"), mLinkedInCallbackURL, QStringLiteral("Accounts_OAuth_Linkedin_callback_url"), true);
0125 
0126     auto proxyLabel = createBoldLabel(i18n("Proxy"));
0127     proxyLabel->setObjectName(QStringLiteral("proxyLabel"));
0128     mMainLayout->addWidget(proxyLabel);
0129 
0130     mProxyHost->setObjectName(QStringLiteral("mProxyHost"));
0131     addLineEdit(i18n("Proxy Host"), mProxyHost, QStringLiteral("Accounts_OAuth_Proxy_host"));
0132 
0133     mProxyServices->setObjectName(QStringLiteral("mProxyServices"));
0134     addLineEdit(i18n("Proxy Services"), mProxyServices, QStringLiteral("Accounts_OAuth_Proxy_services"));
0135 
0136     // Meteor
0137     auto meteorLabel = createBoldLabel(i18n("Meteor"));
0138     meteorLabel->setObjectName(QStringLiteral("meteorLabel"));
0139     mMainLayout->addWidget(meteorLabel);
0140 
0141     mMeteorLogin->setObjectName(QStringLiteral("mMeteorLogin"));
0142     mMainLayout->addWidget(mMeteorLogin);
0143     connectCheckBox(mMeteorLogin, QStringLiteral("Accounts_OAuth_Meteor"));
0144 
0145     mMeteorId->setObjectName(QStringLiteral("mMeteorId"));
0146     addLineEdit(i18n("Meteor Id"), mMeteorId, QStringLiteral("Accounts_OAuth_Meteor_id"));
0147 
0148     mMeteorSecret->setObjectName(QStringLiteral("mMeteorSecret"));
0149     addLineEdit(i18n("Meteor Secret"), mMeteorSecret, QStringLiteral("Accounts_OAuth_Meteor_secret"));
0150 
0151     mMeteorCallbackURL->setObjectName(QStringLiteral("mMeteorCallbackURL"));
0152     addLineEdit(i18n("Meteor Secret"), mMeteorCallbackURL, QStringLiteral("Accounts_OAuth_Meteor_callback_url"), true);
0153 
0154     // Facebook
0155     auto facebookLabel = createBoldLabel(i18n("Facebook"));
0156     facebookLabel->setObjectName(QStringLiteral("facebookLabel"));
0157     mMainLayout->addWidget(facebookLabel);
0158 
0159     mFacebookLogin->setObjectName(QStringLiteral("mFacebookLogin"));
0160     mMainLayout->addWidget(mFacebookLogin);
0161     connectCheckBox(mFacebookLogin, QStringLiteral("Accounts_OAuth_Facebook"));
0162 
0163     mFacebookId->setObjectName(QStringLiteral("mFacebookId"));
0164     addLineEdit(i18n("Facebook Id"), mFacebookId, QStringLiteral("Accounts_OAuth_Facebook_id"));
0165 
0166     mFacebookSecret->setObjectName(QStringLiteral("mFacebookSecret"));
0167     addLineEdit(i18n("Facebook Secret"), mFacebookSecret, QStringLiteral("Accounts_OAuth_Facebook_secret"));
0168 
0169     mFacebookCallbackURL->setObjectName(QStringLiteral("mFacebookCallbackURL"));
0170     addLineEdit(i18n("Facebook Secret"), mFacebookCallbackURL, QStringLiteral("Accounts_OAuth_Facebook_callback_url"), true);
0171 
0172     // Github
0173     auto githubLabel = createBoldLabel(i18n("Github"));
0174     githubLabel->setObjectName(QStringLiteral("githubLabel"));
0175     mMainLayout->addWidget(githubLabel);
0176 
0177     mGithubLogin->setObjectName(QStringLiteral("mGithubLogin"));
0178     mMainLayout->addWidget(mGithubLogin);
0179     connectCheckBox(mGithubLogin, QStringLiteral("Accounts_OAuth_Github"));
0180 
0181     mGithubId->setObjectName(QStringLiteral("mGithubId"));
0182     addLineEdit(i18n("Github Id"), mGithubId, QStringLiteral("Accounts_OAuth_Github_id"));
0183 
0184     mGithubSecret->setObjectName(QStringLiteral("mGithubSecret"));
0185     addLineEdit(i18n("Github Secret"), mGithubSecret, QStringLiteral("Accounts_OAuth_Github_secret"));
0186 
0187     mGithubCallbackURL->setObjectName(QStringLiteral("mGithubCallbackURL"));
0188     addLineEdit(i18n("Github Secret"), mGithubCallbackURL, QStringLiteral("Accounts_OAuth_Github_callback_url"), true);
0189 
0190     // Tokenpass
0191     auto tokenpassLabel = createBoldLabel(i18n("Tokenpass"));
0192     tokenpassLabel->setObjectName(QStringLiteral("tokenpassLabel"));
0193     mMainLayout->addWidget(tokenpassLabel);
0194 
0195     mTokenpassLogin->setObjectName(QStringLiteral("mTokenpassLogin"));
0196     mMainLayout->addWidget(mTokenpassLogin);
0197     connectCheckBox(mTokenpassLogin, QStringLiteral("Accounts_OAuth_Tokenpass"));
0198 
0199     mTokenpassServerURL->setObjectName(QStringLiteral("mTokenpassServerURL"));
0200     mTokenpassServerURL->setToolTip(i18n("Example: https://domain.com (excluding trailing slash)"));
0201     addLineEdit(i18n("Tokenpass Server URL"), mTokenpassServerURL, QStringLiteral("API_Tokenpass_URL"));
0202 
0203     mTokenpassId->setObjectName(QStringLiteral("mTokenpassId"));
0204     addLineEdit(i18n("Tokenpass Id"), mTokenpassId, QStringLiteral("Accounts_OAuth_Tokenpass_id"));
0205 
0206     mTokenpassSecret->setObjectName(QStringLiteral("mTokenpassSecret"));
0207     addLineEdit(i18n("Tokenpass Secret"), mTokenpassSecret, QStringLiteral("Accounts_OAuth_Tokenpass_secret"));
0208 
0209     mTokenpassCallbackURL->setObjectName(QStringLiteral("mTokenpassCallbackURL"));
0210     addLineEdit(i18n("Tokenpass Secret"), mTokenpassCallbackURL, QStringLiteral("Accounts_OAuth_Tokenpass_callback_url"), true);
0211 
0212     // Google
0213     auto googleLabel = createBoldLabel(i18n("Google"));
0214     googleLabel->setObjectName(QStringLiteral("googleLabel"));
0215     mMainLayout->addWidget(googleLabel);
0216 
0217     mGoogleLogin->setObjectName(QStringLiteral("mGoogleLogin"));
0218     mMainLayout->addWidget(mGoogleLogin);
0219     connectCheckBox(mGoogleLogin, QStringLiteral("Accounts_OAuth_Google"));
0220 
0221     mGoogleId->setObjectName(QStringLiteral("mGoogleId"));
0222     addLineEdit(i18n("Google Id"), mGoogleId, QStringLiteral("Accounts_OAuth_Google_id"));
0223 
0224     mGoogleSecret->setObjectName(QStringLiteral("mGoogleSecret"));
0225     addLineEdit(i18n("Google Secret"), mGoogleSecret, QStringLiteral("Accounts_OAuth_Google_secret"));
0226 
0227     mGoogleCallbackURL->setObjectName(QStringLiteral("mGoogleCallbackURL"));
0228     addLineEdit(i18n("Google Secret"), mGoogleCallbackURL, QStringLiteral("Accounts_OAuth_Google_callback_url"), true);
0229 }
0230 
0231 OauthSettingsWidget::~OauthSettingsWidget() = default;
0232 
0233 void OauthSettingsWidget::initialize(const QMap<QString, QVariant> &mapSettings)
0234 {
0235     initializeWidget(mSignWithApple, mapSettings, false);
0236     initializeWidget(mAccountsOAuthAppleId, mapSettings, QString());
0237     initializeWidget(mAccountsOAuthAppleIss, mapSettings, QString());
0238     initializeWidget(mAccountsOAuthAppleKid, mapSettings, QString());
0239     initializeWidget(mTwitterLogin, mapSettings, false);
0240     initializeWidget(mTwitterId, mapSettings, QString());
0241     initializeWidget(mTwitterSecret, mapSettings, QString());
0242     initializeWidget(mTwitterCallbackURL, mapSettings, urlFromRelativePath(QStringLiteral("_oauth/twitter")));
0243 
0244     initializeWidget(mLinkedInLogin, mapSettings, false);
0245     initializeWidget(mLinkedInId, mapSettings, QString());
0246     initializeWidget(mLinkedInSecret, mapSettings, QString());
0247     initializeWidget(mLinkedInCallbackURL, mapSettings, urlFromRelativePath(QStringLiteral("_oauth/linkedin")));
0248 
0249     initializeWidget(mProxyHost, mapSettings, QStringLiteral("https://oauth-proxy.rocket.chat"));
0250     initializeWidget(mProxyServices, mapSettings, QString());
0251 
0252     initializeWidget(mMeteorLogin, mapSettings, false);
0253     initializeWidget(mMeteorId, mapSettings, QString());
0254     initializeWidget(mMeteorSecret, mapSettings, QString());
0255     initializeWidget(mMeteorCallbackURL, mapSettings, urlFromRelativePath(QStringLiteral("_oauth/meteor")));
0256 
0257     initializeWidget(mFacebookLogin, mapSettings, false);
0258     initializeWidget(mFacebookId, mapSettings, QString());
0259     initializeWidget(mFacebookSecret, mapSettings, QString());
0260     initializeWidget(mFacebookCallbackURL, mapSettings, urlFromRelativePath(QStringLiteral("_oauth/facebook")));
0261 
0262     initializeWidget(mGithubLogin, mapSettings, false);
0263     initializeWidget(mGithubId, mapSettings, QString());
0264     initializeWidget(mGithubSecret, mapSettings, QString());
0265     initializeWidget(mGithubCallbackURL, mapSettings, urlFromRelativePath(QStringLiteral("_oauth/github")));
0266 
0267     initializeWidget(mTokenpassLogin, mapSettings, false);
0268     initializeWidget(mTokenpassId, mapSettings, QString());
0269     initializeWidget(mTokenpassSecret, mapSettings, QString());
0270     initializeWidget(mTokenpassCallbackURL, mapSettings, urlFromRelativePath(QStringLiteral("_oauth/tokenpass")));
0271     initializeWidget(mTokenpassServerURL, mapSettings, QString());
0272 
0273     initializeWidget(mGoogleLogin, mapSettings, false);
0274     initializeWidget(mGoogleId, mapSettings, QString());
0275     initializeWidget(mGoogleSecret, mapSettings, QString());
0276     initializeWidget(mGoogleCallbackURL, mapSettings, urlFromRelativePath(QStringLiteral("_oauth/google")));
0277 
0278     initializeWidget(mDolphinUrl, mapSettings, QString());
0279     initializeWidget(mDolphinEnable, mapSettings, false);
0280     initializeWidget(mDolphinId, mapSettings, QString());
0281     initializeWidget(mDolphinSecret, mapSettings, QString());
0282 }
0283 
0284 #include "moc_oauthsettingswidget.cpp"