mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-16 19:31:02 +01:00
When the user opens the Google Drive section for the first time, open the settings dialog to prompt them to login instead of opening a browser to start OAuth straight away. Also fix a bug where the user's email address would be lost on subsequent authentications.
This commit is contained in:
parent
252f1e38d8
commit
7ca7ecbe99
@ -72,7 +72,9 @@ QStandardItem* GoogleDriveService::CreateRootItem() {
|
||||
void GoogleDriveService::LazyPopulate(QStandardItem* item) {
|
||||
switch (item->data(InternetModel::Role_Type).toInt()) {
|
||||
case InternetModel::Type_Service:
|
||||
if (!client_->is_authenticated()) {
|
||||
if (refresh_token().isEmpty()) {
|
||||
ShowSettingsDialog();
|
||||
} else if (!client_->is_authenticated()) {
|
||||
Connect();
|
||||
}
|
||||
library_model_->Init();
|
||||
@ -84,12 +86,15 @@ void GoogleDriveService::LazyPopulate(QStandardItem* item) {
|
||||
}
|
||||
}
|
||||
|
||||
void GoogleDriveService::Connect() {
|
||||
QString GoogleDriveService::refresh_token() const {
|
||||
QSettings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
|
||||
google_drive::ConnectResponse* response =
|
||||
client_->Connect(s.value("refresh_token").toString());
|
||||
return s.value("refresh_token").toString();
|
||||
}
|
||||
|
||||
void GoogleDriveService::Connect() {
|
||||
google_drive::ConnectResponse* response = client_->Connect(refresh_token());
|
||||
NewClosure(response, SIGNAL(Finished()),
|
||||
this, SLOT(ConnectFinished(google_drive::ConnectResponse*)),
|
||||
response);
|
||||
@ -122,7 +127,11 @@ void GoogleDriveService::ConnectFinished(google_drive::ConnectResponse* response
|
||||
QSettings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
s.setValue("refresh_token", response->refresh_token());
|
||||
s.setValue("user_email", response->user_email());
|
||||
|
||||
if (!response->user_email().isEmpty()) {
|
||||
// We only fetch the user's email address the first time we authenticate.
|
||||
s.setValue("user_email", response->user_email());
|
||||
}
|
||||
|
||||
emit Connected();
|
||||
|
||||
|
@ -30,6 +30,7 @@ class GoogleDriveService : public InternetService {
|
||||
static const char* kSettingsGroup;
|
||||
|
||||
google_drive::Client* client() const { return client_; }
|
||||
QString refresh_token() const;
|
||||
|
||||
QStandardItem* CreateRootItem();
|
||||
void LazyPopulate(QStandardItem* item);
|
||||
|
Loading…
Reference in New Issue
Block a user