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) {
|
void GoogleDriveService::LazyPopulate(QStandardItem* item) {
|
||||||
switch (item->data(InternetModel::Role_Type).toInt()) {
|
switch (item->data(InternetModel::Role_Type).toInt()) {
|
||||||
case InternetModel::Type_Service:
|
case InternetModel::Type_Service:
|
||||||
if (!client_->is_authenticated()) {
|
if (refresh_token().isEmpty()) {
|
||||||
|
ShowSettingsDialog();
|
||||||
|
} else if (!client_->is_authenticated()) {
|
||||||
Connect();
|
Connect();
|
||||||
}
|
}
|
||||||
library_model_->Init();
|
library_model_->Init();
|
||||||
@ -84,12 +86,15 @@ void GoogleDriveService::LazyPopulate(QStandardItem* item) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GoogleDriveService::Connect() {
|
QString GoogleDriveService::refresh_token() const {
|
||||||
QSettings s;
|
QSettings s;
|
||||||
s.beginGroup(kSettingsGroup);
|
s.beginGroup(kSettingsGroup);
|
||||||
|
|
||||||
google_drive::ConnectResponse* response =
|
return s.value("refresh_token").toString();
|
||||||
client_->Connect(s.value("refresh_token").toString());
|
}
|
||||||
|
|
||||||
|
void GoogleDriveService::Connect() {
|
||||||
|
google_drive::ConnectResponse* response = client_->Connect(refresh_token());
|
||||||
NewClosure(response, SIGNAL(Finished()),
|
NewClosure(response, SIGNAL(Finished()),
|
||||||
this, SLOT(ConnectFinished(google_drive::ConnectResponse*)),
|
this, SLOT(ConnectFinished(google_drive::ConnectResponse*)),
|
||||||
response);
|
response);
|
||||||
@ -122,7 +127,11 @@ void GoogleDriveService::ConnectFinished(google_drive::ConnectResponse* response
|
|||||||
QSettings s;
|
QSettings s;
|
||||||
s.beginGroup(kSettingsGroup);
|
s.beginGroup(kSettingsGroup);
|
||||||
s.setValue("refresh_token", response->refresh_token());
|
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();
|
emit Connected();
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ class GoogleDriveService : public InternetService {
|
|||||||
static const char* kSettingsGroup;
|
static const char* kSettingsGroup;
|
||||||
|
|
||||||
google_drive::Client* client() const { return client_; }
|
google_drive::Client* client() const { return client_; }
|
||||||
|
QString refresh_token() const;
|
||||||
|
|
||||||
QStandardItem* CreateRootItem();
|
QStandardItem* CreateRootItem();
|
||||||
void LazyPopulate(QStandardItem* item);
|
void LazyPopulate(QStandardItem* item);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user