Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize library #5

Merged
merged 17 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions examples/facebookdemo/fbdemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ FBDemo::FBDemo(QObject *parent) :
store->setGroupKey("facebook");
o2Facebook_->setStore(store);

connect(o2Facebook_, SIGNAL(linkedChanged()), this, SLOT(onLinkedChanged()));
connect(o2Facebook_, SIGNAL(linkingFailed()), this, SIGNAL(linkingFailed()));
connect(o2Facebook_, SIGNAL(linkingSucceeded()), this, SLOT(onLinkingSucceeded()));
connect(o2Facebook_, SIGNAL(openBrowser(QUrl)), this, SLOT(onOpenBrowser(QUrl)));
connect(o2Facebook_, SIGNAL(closeBrowser()), this, SLOT(onCloseBrowser()));
connect(o2Facebook_, &O2Facebook::linkedChanged, this, &FBDemo::onLinkedChanged);
connect(o2Facebook_, &O2Facebook::linkingFailed, this, &FBDemo::linkingFailed);
connect(o2Facebook_, &O2Facebook::linkingSucceeded, this, &FBDemo::onLinkingSucceeded);
connect(o2Facebook_, &O2Facebook::openBrowser, this, &FBDemo::onOpenBrowser);
connect(o2Facebook_, &O2Facebook::closeBrowser, this, &FBDemo::onCloseBrowser);
}

void FBDemo::doOAuth(O2::GrantFlow grantFlowType) {
Expand All @@ -60,7 +60,7 @@ void FBDemo::validateToken() {
QNetworkRequest request = QNetworkRequest(QUrl(debugUrlStr));
QNetworkAccessManager *mgr = new QNetworkAccessManager(this);
QNetworkReply *reply = mgr->get(request);
connect(reply, SIGNAL(finished()), this, SLOT(onFinished()));
connect(reply, &QNetworkReply::finished, this, &FBDemo::onFinished);
qDebug() << "Validating user token. Please wait...";
}

Expand All @@ -84,8 +84,8 @@ void FBDemo::onLinkingSucceeded() {
if (!extraTokens.isEmpty()) {
emit extraTokensReady(extraTokens);
qDebug() << "Extra tokens in response:";
foreach (QString key, extraTokens.keys()) {
qDebug() << "\t" << key << ":" << (extraTokens.value(key).toString().left(3) + "...");
for (auto it = extraTokens.constBegin(); it != extraTokens.constEnd(); ++it) {
qDebug() << "\t" << it.key() << ":" << (it.value().toString().left(3) + "...");
}
}
emit linkingSucceeded();
Expand Down
2 changes: 1 addition & 1 deletion examples/facebookdemo/fbdemo.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class FBDemo : public QObject
Q_OBJECT

public:
explicit FBDemo(QObject *parent = 0);
explicit FBDemo(QObject *parent = nullptr);

signals:
void extraTokensReady(const QVariantMap &extraTokens);
Expand Down
10 changes: 5 additions & 5 deletions examples/facebookdemo/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ class Helper : public QObject {
Q_OBJECT

public:
Helper() : QObject(), fbdemo_(this), waitForMsg_(false), msg_(QString()) {}
Helper() : QObject(), fbdemo_(this) {}

public slots:
void processArgs() {
QStringList argList = qApp->arguments();
QByteArray help = QString(USAGE).arg(OPT_OAUTH_CODE,
OPT_VALIDATE_TOKEN).toLatin1();
const char* helpText = help.constData();
connect(&fbdemo_, SIGNAL(linkingFailed()), this, SLOT(onLinkingFailed()));
connect(&fbdemo_, SIGNAL(linkingSucceeded()), this, SLOT(onLinkingSucceeded()));
connect(&fbdemo_, &FBDemo::linkingFailed, this, &Helper::onLinkingFailed);
connect(&fbdemo_, &FBDemo::linkingSucceeded, this, &Helper::onLinkingSucceeded);
if (argList.contains(OPT_OAUTH_CODE)) {
// Start OAuth
fbdemo_.doOAuth(O2::GrantFlowAuthorizationCode);
Expand Down Expand Up @@ -57,7 +57,7 @@ public slots:

private:
FBDemo fbdemo_;
bool waitForMsg_;
bool waitForMsg_{false};
QString msg_;
};

Expand All @@ -67,7 +67,7 @@ int main(int argc, char *argv[]) {
QCoreApplication::setOrganizationDomain("mysoft.com");
QCoreApplication::setApplicationName("facebookdemo");
Helper helper;
QTimer::singleShot(0, &helper, SLOT(processArgs()));
QTimer::singleShot(0, &helper, &Helper::processArgs);
return a.exec();
}

Expand Down
16 changes: 11 additions & 5 deletions examples/msgraphdemo/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ class Helper : public QObject {

public slots:
void run() {
connect(&demo_, SIGNAL(linkingFailed()), this, SLOT(onLinkingFailed()));
connect(&demo_, SIGNAL(linkingSucceeded()), this, SLOT(onLinkingSucceeded()));
connect(&demo_, SIGNAL(userPrincipalNameReceived()), this, SLOT(onUserPrincipalNameReceived()));
connect(&demo_, SIGNAL(userPrincipalNameFailed()), this, SLOT(onUserPrincipalNameFailed()));
connect(&demo_, &MsgraphDemo::linkingFailed, this, &Helper::onLinkingFailed);
connect(&demo_, &MsgraphDemo::linkingSucceeded, this, &Helper::onLinkingSucceeded);
connect(&demo_,
&MsgraphDemo::userPrincipalNameReceived,
this,
&Helper::onUserPrincipalNameReceived);
connect(&demo_,
&MsgraphDemo::userPrincipalNameFailed,
this,
&Helper::onUserPrincipalNameFailed);

demo_.doOAuth(O2::GrantFlowAuthorizationCode);
}
Expand Down Expand Up @@ -53,7 +59,7 @@ int main(int argc, char *argv[]) {
QCoreApplication::setOrganizationName("O2");
QCoreApplication::setApplicationName("Msgraph Example");
Helper helper;
QTimer::singleShot(0, &helper, SLOT(run()));
QTimer::singleShot(0, &helper, &Helper::run);
return a.exec();
}

Expand Down
20 changes: 10 additions & 10 deletions examples/msgraphdemo/msgraphdemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const int localPort = 8888;
#define GRANTFLOW_STR(v) QString(QENUM_NAME(O2, GrantFlow, v))

MsgraphDemo::MsgraphDemo(QObject *parent) :
QObject(parent), requestId_(0) {
QObject(parent) {
o2Msgraph_ = new O2Msgraph(this);

o2Msgraph_->setClientId(MSGRAPH_APP_ID);
Expand All @@ -35,11 +35,11 @@ MsgraphDemo::MsgraphDemo(QObject *parent) :
store->setGroupKey("msgraph");
o2Msgraph_->setStore(store);

connect(o2Msgraph_, SIGNAL(linkedChanged()), this, SLOT(onLinkedChanged()));
connect(o2Msgraph_, SIGNAL(linkingFailed()), this, SIGNAL(linkingFailed()));
connect(o2Msgraph_, SIGNAL(linkingSucceeded()), this, SLOT(onLinkingSucceeded()));
connect(o2Msgraph_, SIGNAL(openBrowser(QUrl)), this, SLOT(onOpenBrowser(QUrl)));
connect(o2Msgraph_, SIGNAL(closeBrowser()), this, SLOT(onCloseBrowser()));
connect(o2Msgraph_, &O0BaseAuth::linkedChanged, this, &MsgraphDemo::onLinkedChanged);
connect(o2Msgraph_, &O0BaseAuth::linkingFailed, this, &MsgraphDemo::linkingFailed);
connect(o2Msgraph_, &O0BaseAuth::linkingSucceeded, this, &MsgraphDemo::onLinkingSucceeded);
connect(o2Msgraph_, &O0BaseAuth::openBrowser, this, &MsgraphDemo::onOpenBrowser);
connect(o2Msgraph_, &O0BaseAuth::closeBrowser, this, &MsgraphDemo::onCloseBrowser);
}

void MsgraphDemo::doOAuth(O2::GrantFlow grantFlowType) {
Expand All @@ -63,8 +63,8 @@ void MsgraphDemo::getUserPrincipalName() {
requestor->setAddAccessTokenInQuery(false);
requestor->setAccessTokenInAuthenticationHTTPHeaderFormat("Bearer %1");
requestId_ = requestor->get(request);
connect(requestor, SIGNAL(finished(int, QNetworkReply::NetworkError, QByteArray)),
this, SLOT(onFinished(int, QNetworkReply::NetworkError, QByteArray))
connect(requestor, qOverload<int, QNetworkReply::NetworkError, QByteArray >(&O2Requestor::finished),
this, &MsgraphDemo::onFinished
);
qDebug() << "Getting user info... Please wait.";
}
Expand All @@ -89,8 +89,8 @@ void MsgraphDemo::onLinkingSucceeded() {
if (!extraTokens.isEmpty()) {
emit extraTokensReady(extraTokens);
qDebug() << "Extra tokens in response:";
foreach (QString key, extraTokens.keys()) {
qDebug() << "\t" << key << ":" << (extraTokens.value(key).toString().left(3) + "...");
for (auto it = extraTokens.constBegin(); it != extraTokens.constEnd(); ++it) {
qDebug() << "\t" << it.key() << ":" << (it.value().toString().left(3) + "...");
}
}
emit linkingSucceeded();
Expand Down
4 changes: 2 additions & 2 deletions examples/msgraphdemo/msgraphdemo.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MsgraphDemo : public QObject
Q_OBJECT

public:
explicit MsgraphDemo(QObject *parent = 0);
explicit MsgraphDemo(QObject *parent = nullptr);

signals:
void extraTokensReady(const QVariantMap &extraTokens);
Expand All @@ -32,7 +32,7 @@ private slots:

private:
O2Msgraph *o2Msgraph_;
int requestId_;
int requestId_{0};
};

#endif // MSGRAPHDEMO_H
16 changes: 11 additions & 5 deletions examples/msgraphexternalinterceptordemo/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ class Helper : public QObject {

public slots:
void run() {
connect(&demo_, SIGNAL(linkingFailed()), this, SLOT(onLinkingFailed()));
connect(&demo_, SIGNAL(linkingSucceeded()), this, SLOT(onLinkingSucceeded()));
connect(&demo_, SIGNAL(userPrincipalNameReceived()), this, SLOT(onUserPrincipalNameReceived()));
connect(&demo_, SIGNAL(userPrincipalNameFailed()), this, SLOT(onUserPrincipalNameFailed()));
connect(&demo_, &MsgraphDemo::linkingFailed, this, &Helper::onLinkingFailed);
connect(&demo_, &MsgraphDemo::linkingSucceeded, this, &Helper::onLinkingSucceeded);
connect(&demo_,
&MsgraphDemo::userPrincipalNameReceived,
this,
&Helper::onUserPrincipalNameReceived);
connect(&demo_,
&MsgraphDemo::userPrincipalNameFailed,
this,
&Helper::onUserPrincipalNameFailed);

// Start OAuth
demo_.doOAuth(O2::GrantFlowAuthorizationCode);
Expand Down Expand Up @@ -51,7 +57,7 @@ int main(int argc, char *argv[]) {
QCoreApplication::setOrganizationName("O2");
QCoreApplication::setApplicationName("Msgraph Example");
Helper helper;
QTimer::singleShot(0, &helper, SLOT(run()));
QTimer::singleShot(0, &helper, &Helper::run);
return a.exec();
}

Expand Down
34 changes: 20 additions & 14 deletions examples/msgraphexternalinterceptordemo/msgraphdemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const char MSGRAPH_USER_INFO_URL[] = "https://graph.microsoft.com/v1.0/me";
#define GRANTFLOW_STR(v) QString(QENUM_NAME(O2, GrantFlow, v))

MsgraphDemo::MsgraphDemo(QObject *parent) :
QObject(parent), authDialog(NULL), requestId_(0) {
QObject(parent) {
o2Msgraph_ = new O2Msgraph(this);

o2Msgraph_->setClientId(MSGRAPH_APP_ID);
Expand All @@ -34,11 +34,11 @@ MsgraphDemo::MsgraphDemo(QObject *parent) :
store->setGroupKey("msgraph");
o2Msgraph_->setStore(store);

connect(o2Msgraph_, SIGNAL(linkedChanged()), this, SLOT(onLinkedChanged()));
connect(o2Msgraph_, SIGNAL(linkingFailed()), this, SIGNAL(linkingFailed()));
connect(o2Msgraph_, SIGNAL(linkingSucceeded()), this, SLOT(onLinkingSucceeded()));
connect(o2Msgraph_, SIGNAL(openBrowser(QUrl)), this, SLOT(onOpenBrowser(QUrl)));
connect(o2Msgraph_, SIGNAL(closeBrowser()), this, SLOT(onCloseBrowser()));
connect(o2Msgraph_, &O0BaseAuth::linkedChanged, this, &MsgraphDemo::onLinkedChanged);
connect(o2Msgraph_, &O0BaseAuth::linkingFailed, this, &MsgraphDemo::linkingFailed);
connect(o2Msgraph_, &O0BaseAuth::linkingSucceeded, this, &MsgraphDemo::onLinkingSucceeded);
connect(o2Msgraph_, &O0BaseAuth::openBrowser, this, &MsgraphDemo::onOpenBrowser);
connect(o2Msgraph_, &O0BaseAuth::closeBrowser, this, &MsgraphDemo::onCloseBrowser);
}

void MsgraphDemo::doOAuth(O2::GrantFlow grantFlowType) {
Expand All @@ -62,32 +62,38 @@ void MsgraphDemo::getUserPrincipalName() {
requestor->setAddAccessTokenInQuery(false);
requestor->setAccessTokenInAuthenticationHTTPHeaderFormat("Bearer %1");
requestId_ = requestor->get(request);
connect(requestor, SIGNAL(finished(int, QNetworkReply::NetworkError, QByteArray)),
this, SLOT(onFinished(int, QNetworkReply::NetworkError, QByteArray))
connect(requestor, qOverload<int, QNetworkReply::NetworkError, QByteArray>(&O2Requestor::finished),
this, &MsgraphDemo::onFinished
);
qDebug() << "Getting user info... Please wait.";
}

void MsgraphDemo::onOpenBrowser(const QUrl &url) {
if (authDialog == Q_NULLPTR) {
authDialog = new WebWindow(QSize(650, 600), url, MSGRAPH_REDIRECT_URI, false);
QObject::connect(authDialog, SIGNAL(callbackCalled(const QString &)), this, SLOT(onAuthWindowCallbackCalled(const QString &)));
QObject::connect(authDialog, SIGNAL(windowClosed()), this, SLOT(onAuthWindowClosed()));
QObject::connect(authDialog,
&WebWindow::callbackCalled,
this,
&MsgraphDemo::onAuthWindowCallbackCalled);
QObject::connect(authDialog,
&WebWindow::windowClosed,
this,
&MsgraphDemo::onAuthWindowClosed);
authDialog->exec();
}
}

void MsgraphDemo::onAuthWindowCallbackCalled(const QString &inURLString)
{
if(o2Msgraph_ != NULL)
if(o2Msgraph_ != nullptr)
{
QUrl getTokenUrl(inURLString);
QUrlQuery query(getTokenUrl);
QList< QPair<QString, QString> > tokens = query.queryItems();

QMultiMap<QString, QString> queryParams;
QPair<QString, QString> tokenPair;
foreach (tokenPair, tokens) {
for (const QPair<QString, QString>& tokenPair: tokens) {
// FIXME: We are decoding key and value again. This helps with Google OAuth, but is it mandated by the standard?
QString key = QUrl::fromPercentEncoding(QByteArray().append(tokenPair.first.trimmed().toLatin1()));
QString value = QUrl::fromPercentEncoding(QByteArray().append(tokenPair.second.trimmed().toLatin1()));
Expand Down Expand Up @@ -123,8 +129,8 @@ void MsgraphDemo::onLinkingSucceeded() {
if (!extraTokens.isEmpty()) {
emit extraTokensReady(extraTokens);
qDebug() << "Extra tokens in response:";
foreach (QString key, extraTokens.keys()) {
qDebug() << "\t" << key << ":" << (extraTokens.value(key).toString().left(3) + "...");
for (auto it = extraTokens.constBegin(); it != extraTokens.constEnd(); ++it) {
qDebug() << "\t" << it.key() << ":" << (it.value().toString().left(3) + "...");
}
}
emit linkingSucceeded();
Expand Down
6 changes: 3 additions & 3 deletions examples/msgraphexternalinterceptordemo/msgraphdemo.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class MsgraphDemo : public QObject
Q_OBJECT

public:
explicit MsgraphDemo(QObject *parent = 0);
explicit MsgraphDemo(QObject *parent = nullptr);

signals:
void extraTokensReady(const QVariantMap &extraTokens);
Expand All @@ -35,8 +35,8 @@ private slots:

private:
O2Msgraph *o2Msgraph_;
WebWindow* authDialog;
int requestId_;
WebWindow* authDialog{nullptr};
int requestId_{0};
};

#endif // MSGRAPHDEMO_H
19 changes: 14 additions & 5 deletions examples/msgraphexternalinterceptordemo/webenginepage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,25 @@ QWebEnginePage *WebEnginePage::createWindow(WebWindowType type)
case QWebEnginePage::WebDialog:
{
WebWindow *webViewDialog = new WebWindow(QSize(600, 500), QUrl(), mRedirectURLString, false);
QObject::connect(webViewDialog, SIGNAL(callbackCalled(const QString &)), this, SLOT(onAuthWindowCallbackCalled(const QString &)));
QObject::connect(webViewDialog, SIGNAL(windowClosed()), this, SLOT(onCreatedWindowClosed()));
QObject::connect(webViewDialog->GetWebEnginePage(), SIGNAL(windowCloseRequested()), this, SLOT(onWindowCloseRequested()));
mCreatedWindows.push_back(webViewDialog);
QObject::connect(webViewDialog,
&WebWindow::callbackCalled,
this,
&WebEnginePage::onAuthWindowCallbackCalled);
QObject::connect(webViewDialog,
&WebWindow::windowClosed,
this,
&WebEnginePage::onCreatedWindowClosed);
QObject::connect(webViewDialog->GetWebEnginePage(),
&QWebEnginePage::windowCloseRequested,
this,
&WebEnginePage::onWindowCloseRequested);
mCreatedWindows.push_back(webViewDialog);
webViewDialog->open();
return webViewDialog->GetWebEnginePage();
}
}

return NULL;
return nullptr;
}

void WebEnginePage::onAuthWindowCallbackCalled(const QString &inURLString)
Expand Down
6 changes: 3 additions & 3 deletions examples/msgraphexternalinterceptordemo/webenginepage.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ class WebEnginePage : public QWebEnginePage

WebEnginePage(QWebEngineProfile *inProfile, const QString &inRedirectURLString) : QWebEnginePage(inProfile), mRedirectURLString(inRedirectURLString) { }

virtual ~WebEnginePage();
~WebEnginePage() override;

bool acceptNavigationRequest(const QUrl & url, QWebEnginePage::NavigationType type, bool isMainFrame);
bool acceptNavigationRequest(const QUrl & url, QWebEnginePage::NavigationType type, bool isMainFrame) override;

protected:
QWebEnginePage *createWindow(WebWindowType type);
QWebEnginePage *createWindow(WebWindowType type) override;

signals:
void callbackCatched(const QString &inURLString);
Expand Down
12 changes: 6 additions & 6 deletions examples/msgraphexternalinterceptordemo/webwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ WebWindow::WebWindow(QSize inWindowSize, QUrl inLoginURL, QString inRedirectURLS

mWebEngineProfile = new QWebEngineProfile();

mWebEnginePage = new WebEnginePage(mWebEngineProfile, inRedirectURLString);
QObject::connect(mWebEnginePage, SIGNAL(callbackCatched(const QString &)), this, SLOT(onCallbackCatched(const QString &)));
WebEnginePage* page = new WebEnginePage(mWebEngineProfile, inRedirectURLString);
QObject::connect(page, &WebEnginePage::callbackCatched, this, &WebWindow::onCallbackCatched);
mWebEnginePage = page;

mWebView->setPage(mWebEnginePage);

Expand Down Expand Up @@ -59,13 +60,13 @@ WebWindow::~WebWindow()

void WebWindow::closeEvent(QCloseEvent *)
{
emit (windowClosed());
emit windowClosed();
}

void WebWindow::onCallbackCatched(const QString &inURLString)
{
mCatchedOAuthURL = inURLString;
QTimer::singleShot(100, this, SLOT(onCallbackCatchedSafe()));
QTimer::singleShot(100, this, &WebWindow::onCallbackCatchedSafe);
}

void WebWindow::onCallbackCatchedSafe()
Expand All @@ -77,8 +78,7 @@ void WebWindow::onCallbackCatchedSafe()
QList< QPair<QString, QString> > tokens = query.queryItems();

QMultiMap<QString, QString> queryParams;
QPair<QString, QString> tokenPair;
foreach (tokenPair, tokens) {
for (const QPair<QString, QString>& tokenPair: tokens) {
QString key = QUrl::fromPercentEncoding(QByteArray().append(tokenPair.first.trimmed().toLatin1()));
QString value = QUrl::fromPercentEncoding(QByteArray().append(tokenPair.second.trimmed().toLatin1()));
queryParams.insert(key, value);
Expand Down
Loading
Loading