Show a nicer success page when oauth is complete.

This commit is contained in:
David Sansome 2012-07-27 18:59:03 +01:00
parent f48383c73e
commit 51631169fa
5 changed files with 75 additions and 3 deletions

View File

@ -348,5 +348,6 @@
<file>volumeslider-handle_glow.png</file>
<file>volumeslider-handle.png</file>
<file>volumeslider-inset.png</file>
<file>oauthsuccess.html</file>
</qresource>
</RCC>

37
data/oauthsuccess.html Normal file
View File

@ -0,0 +1,37 @@
<html>
<head>
<title>tr("Return to Clementine")</title>
<style>
#container {
margin: 6em auto 0px auto;
max-width: 800px;
font-family: sans;
}
#container img {
width: 16px;
height: 16px;
float: left;
margin-right: 0.5em;
}
#container h1 {
margin: 0px 0px 0.75em 0px;
font-size: 15pt;
}
#container p {
margin-top: 0px;
}
</style>
</head>
<body>
<div id="container">
<h1>tr("Success!")</h1>
<img src="data:image/png;base64,@IMAGE_DATA@"/>
<p>tr("Please close your browser and return to Clementine.")</p>
</div>
</body>
</html>

View File

@ -1026,6 +1026,7 @@ add_pot(POT
${CMAKE_CURRENT_SOURCE_DIR}/translations/header
${CMAKE_CURRENT_SOURCE_DIR}/translations/translations.pot
${SOURCES} ${MOC} ${UIC} ${OTHER_SOURCES}
../data/oauthsuccess.html
)
add_po(PO clementine_
LANGUAGES ${LANGUAGES}

View File

@ -1,7 +1,11 @@
#include "oauthenticator.h"
#include <QApplication>
#include <QBuffer>
#include <QDesktopServices>
#include <QFile>
#include <QStringList>
#include <QStyle>
#include <QTcpSocket>
#include <QUrl>
@ -48,8 +52,37 @@ void OAuthenticator::NewConnection() {
NewClosure(socket, SIGNAL(readyRead()),
this, SLOT(RedirectArrived(QTcpSocket*, QByteArray)), socket, buffer);
// Everything is bon.
// Everything is bon. Prepare and display the success page.
QFile page_file(":oauthsuccess.html");
page_file.open(QIODevice::ReadOnly);
QString page_data = QString::fromLatin1(page_file.readAll());
// Translate the strings inside
QRegExp tr_regexp("tr\\(\"([^\"]+)\"\\)");
int offset = 0;
forever {
offset = tr_regexp.indexIn(page_data, offset);
if (offset == -1) {
break;
}
page_data.replace(offset, tr_regexp.matchedLength(),
tr(tr_regexp.cap(1).toAscii()));
offset += tr_regexp.matchedLength();
}
// Add the tick image.
QBuffer image_buffer;
image_buffer.open(QIODevice::ReadWrite);
QApplication::style()->standardIcon(QStyle::SP_DialogOkButton)
.pixmap(16).toImage().save(&image_buffer, "PNG");
page_data.replace("@IMAGE_DATA@", image_buffer.data().toBase64());
socket->write("HTTP/1.0 200 OK\r\n");
socket->write("Content-type: text/html;charset=UTF-8\r\n");
socket->write("\r\n\r\n");
socket->write(page_data.toUtf8());
socket->flush();
}

View File

@ -17,9 +17,9 @@ class OAuthenticator : public QObject {
signals:
// Token to use now.
void AccessTokenAvailable(QString token);
void AccessTokenAvailable(const QString& token);
// Token to use to get a new access token when it expires.
void RefreshTokenAvailable(QString token);
void RefreshTokenAvailable(const QString& token);
private slots:
void NewConnection();