diff --git a/src/FileStore.cpp b/src/FileStore.cpp index 119643b94..c01c2a751 100644 --- a/src/FileStore.cpp +++ b/src/FileStore.cpp @@ -426,9 +426,7 @@ FileStoreDialog::createFolderClicked() { FolderNameDialog dialog(this); int ret = dialog.exec(); - printf("CREATE\n"); if (ret == QDialog::Accepted && dialog.name() != "") { - printf("CREATE22\n"); // go and create it ! store->createFolder(pathname + "/" + dialog.name()); diff --git a/src/OAuthDialog.cpp b/src/OAuthDialog.cpp index f2fd5c3e6..8c8233dd4 100644 --- a/src/OAuthDialog.cpp +++ b/src/OAuthDialog.cpp @@ -133,10 +133,14 @@ OAuthDialog::OAuthDialog(Context *context, OAuthSite site) : urlstr.append("response_type=code&"); urlstr.append("client_id=").append(GC_GOOGLE_CALENDAR_CLIENT_ID); } else if (site == GOOGLE_DRIVE) { + const QString scope = + appsettings->cvalue( + context->athlete->cyclist, + GC_GOOGLE_DRIVE_AUTH_SCOPE, "drive.appdata").toString(); // OAUTH 2.0 - Google flow for installed applications urlstr = QString("https://accounts.google.com/o/oauth2/auth?"); // We only request access to the application data folder, not all files. - urlstr.append("scope=https://www.googleapis.com/auth/drive.appdata&"); + urlstr.append("scope=https://www.googleapis.com/auth/" + scope + "&"); urlstr.append("redirect_uri=urn:ietf:wg:oauth:2.0:oob&"); urlstr.append("response_type=code&"); urlstr.append("client_id=").append(GC_GOOGLE_DRIVE_CLIENT_ID); diff --git a/src/Pages.cpp b/src/Pages.cpp index 4b36b578b..04219126b 100644 --- a/src/Pages.cpp +++ b/src/Pages.cpp @@ -376,7 +376,7 @@ CredentialsPage::CredentialsPage(QWidget *parent, Context *context) : QScrollAre connect(twitterAuthorise, SIGNAL(clicked()), this, SLOT(authoriseTwitter())); #endif - + #if QT_VERSION >= 0x050000 // only in QT5 or higher // // Authorising Dropbox via an OAuthDialog... @@ -425,7 +425,6 @@ CredentialsPage::CredentialsPage(QWidget *parent, Context *context) : QScrollAre googleDriveFolder->setText( appsettings->cvalue(context->athlete->cyclist, GC_GOOGLE_DRIVE_FOLDER, "").toString()); - QLabel *googleDriveAuthLabel = new QLabel(tr("Authorise")); googleDriveAuthorise = new QPushButton(tr("Authorise"), this); googleDriveAuthorised = new QPushButton(this); @@ -436,27 +435,60 @@ CredentialsPage::CredentialsPage(QWidget *parent, Context *context) : QScrollAre googleDriveAuthorised->setFixedWidth(16); grid->addWidget(googleDriveLabel, ++row, 0); - grid->addWidget(googleDriveAuthLabel, ++row, 0); - grid->addWidget(googleDriveAuthorise, row, 1, - Qt::AlignLeft | Qt::AlignVCenter); + + QHBoxLayout *gdauthlayout = new QHBoxLayout; + //grid->addWidget(googleDriveAuthorise, row, 1, + //Qt::AlignLeft | Qt::AlignVCenter); + gdauthlayout->addWidget(googleDriveAuthorise); if (appsettings->cvalue(context->athlete->cyclist, GC_GOOGLE_DRIVE_REFRESH_TOKEN, "") != "") { - grid->addWidget(googleDriveAuthorised, row, 2, - Qt::AlignLeft | Qt::AlignVCenter); + //grid->addWidget(googleDriveAuthorised, row, 2, + //Qt::AlignLeft | Qt::AlignVCenter); + gdauthlayout->addWidget(googleDriveAuthorised); } else { googleDriveAuthorised->hide(); // if no token no show } + QComboBox *google_drive_scope = new QComboBox; + int item = 0; + const QString scope = + appsettings->cvalue( + context->athlete->cyclist, + GC_GOOGLE_DRIVE_AUTH_SCOPE, "drive.appdata").toString(); + google_drive_scope->setEditable(false); + google_drive_scope->insertItem(item++, "drive.appdata"); + google_drive_scope->insertItem(item++, "drive.file"); + google_drive_scope->insertItem(item++, "drive"); + if (scope == "drive.appdata") { + google_drive_scope->setCurrentIndex(0); + } else if (scope == "drive.file") { + google_drive_scope->setCurrentIndex(1); + } else if (scope == "drive") { + google_drive_scope->setCurrentIndex(2); + } else { + google_drive_scope->setCurrentIndex(0); + // re-write default. + appsettings->setCValue( + context->athlete->cyclist, + GC_GOOGLE_DRIVE_AUTH_SCOPE, "drive.appdata"); + } + connect(google_drive_scope, SIGNAL(currentIndexChanged(const QString&)), + this, SLOT(chooseGoogleDriveAuthScope(const QString&))); + gdauthlayout->addWidget(google_drive_scope); connect(googleDriveAuthorise, SIGNAL(clicked()), this, SLOT(authoriseGoogleDrive())); - // + + QLabel *googleDriveAuthLabel = new QLabel(tr("Authorise")); + grid->addWidget(googleDriveAuthLabel, ++row, 0); + grid->addLayout(gdauthlayout, row, 1); // No stretch. // Selecting the athlete folder in GoogleDrive - QLabel *googleDriveFolderLabel = new QLabel(tr("Athlete Folder")); googleDriveBrowse = new QPushButton(tr("Browse")); connect(googleDriveBrowse, SIGNAL(clicked()), this, SLOT(chooseGoogleDriveFolder())); QHBoxLayout *gdfchoose = new QHBoxLayout; gdfchoose->addWidget(googleDriveFolder); gdfchoose->addWidget(googleDriveBrowse); + + QLabel *googleDriveFolderLabel = new QLabel(tr("Athlete Folder")); grid->addWidget(googleDriveFolderLabel, ++row, 0); grid->addLayout(gdfchoose, row, 1); #endif @@ -662,7 +694,7 @@ CredentialsPage::CredentialsPage(QWidget *parent, Context *context) : QScrollAre #if QT_VERSION >= 0x050000 // only in QT5 or higher #endif - + grid->addWidget(dv, ++row, 0); grid->addWidget(dvTypeLabel, ++row, 0); @@ -837,7 +869,6 @@ void CredentialsPage::chooseDropboxFolder() if (ret == QDialog::Accepted) dropboxFolder->setText(dialog.pathnameSelected()); } - void CredentialsPage::chooseGoogleDriveFolder() { GoogleDrive google_drive(context); @@ -868,6 +899,16 @@ void CredentialsPage::chooseGoogleDriveFolder() googleDriveFolder->setText(dialog.pathnameSelected()); } } + +void CredentialsPage::chooseGoogleDriveAuthScope(const QString& scope) { + appsettings->setCValue(context->athlete->cyclist, + GC_GOOGLE_DRIVE_AUTH_SCOPE, scope); + // Clear out now invalid access tokens. + appsettings->setCValue(context->athlete->cyclist, + GC_GOOGLE_DRIVE_ACCESS_TOKEN, ""); + appsettings->setCValue(context->athlete->cyclist, + GC_GOOGLE_DRIVE_REFRESH_TOKEN, ""); +} #endif @@ -2731,7 +2772,7 @@ CustomMetricsPage::editClicked() QTreeWidgetItem *item = table->selectedItems().first(); int row = table->invisibleRootItem()->indexOfChild(item); - // edit it + // edit it UserMetricSettings here = metrics[row]; EditUserMetricDialog editor(context, here); diff --git a/src/Pages.h b/src/Pages.h index c815f261e..81fa22932 100644 --- a/src/Pages.h +++ b/src/Pages.h @@ -218,13 +218,14 @@ class CredentialsPage : public QScrollArea #if QT_VERSION >= 0x050000 void authoriseDropbox(); void chooseDropboxFolder(); - void authoriseGoogleDrive(); - void chooseGoogleDriveFolder(); + void authoriseGoogleDrive(); + void chooseGoogleDriveFolder(); + void chooseGoogleDriveAuthScope(const QString& scope); #endif void authoriseStrava(); void authoriseCyclingAnalytics(); void authoriseGoogleCalendar(); - void dvCALDAVTypeChanged(int); + void dvCALDAVTypeChanged(int); void chooseLocalFileStoreFolder(); private: @@ -233,7 +234,7 @@ class CredentialsPage : public QScrollArea DRIVE, }; void authoriseGoogle(GoogleType type); - + Context *context; QLineEdit *tpUser; diff --git a/src/Settings.h b/src/Settings.h index 8064e43df..c3842d2be 100644 --- a/src/Settings.h +++ b/src/Settings.h @@ -265,6 +265,7 @@ //Twitter oauth keys #define GC_DROPBOX_TOKEN "dropbox/token" #define GC_DROPBOX_FOLDER "dropbox/folder" +#define GC_GOOGLE_DRIVE_AUTH_SCOPE "google-drive/auth_scope" #define GC_GOOGLE_DRIVE_ACCESS_TOKEN "google-drive/access_token" #define GC_GOOGLE_DRIVE_REFRESH_TOKEN "google-drive/refresh_token" #define GC_GOOGLE_DRIVE_LAST_ACCESS_TOKEN_REFRESH "google-drive/last_access_token_refresh"