Don't do seafile stuff unless signed in.
This commit is contained in:
parent
01ae151f8a
commit
0cd3d9b34f
@ -53,20 +53,9 @@ SeafileService::SeafileService(Application* app, InternetModel* parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool SeafileService::has_credentials() const {
|
bool SeafileService::has_credentials() const {
|
||||||
return !access_token().isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SeafileService::is_authenticated() const {
|
|
||||||
return !access_token_.isEmpty();
|
return !access_token_.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString SeafileService::access_token() const {
|
|
||||||
QSettings s;
|
|
||||||
s.beginGroup(kSettingsGroup);
|
|
||||||
|
|
||||||
return s.value("access_token").toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SeafileService::AddAuthorizationHeader(QNetworkRequest* request) const {
|
void SeafileService::AddAuthorizationHeader(QNetworkRequest* request) const {
|
||||||
request->setRawHeader("Authorization",
|
request->setRawHeader("Authorization",
|
||||||
QString("Token %1").arg(access_token_).toAscii());
|
QString("Token %1").arg(access_token_).toAscii());
|
||||||
@ -177,7 +166,7 @@ void SeafileService::ChangeLibrary(const QString& new_library) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SeafileService::Connect() {
|
void SeafileService::Connect() {
|
||||||
if (is_authenticated()) {
|
if (has_credentials()) {
|
||||||
UpdateLibraries();
|
UpdateLibraries();
|
||||||
} else {
|
} else {
|
||||||
ShowSettingsDialog();
|
ShowSettingsDialog();
|
||||||
|
@ -48,7 +48,7 @@ class SeafileService : public CloudFileService {
|
|||||||
static const char* kServiceName;
|
static const char* kServiceName;
|
||||||
static const char* kSettingsGroup;
|
static const char* kSettingsGroup;
|
||||||
|
|
||||||
virtual bool has_credentials() const;
|
bool has_credentials() const;
|
||||||
QUrl GetStreamingUrlFromSongId(const QString& library,
|
QUrl GetStreamingUrlFromSongId(const QString& library,
|
||||||
const QString& filepath);
|
const QString& filepath);
|
||||||
// Get the token for an user (simple rest api)
|
// Get the token for an user (simple rest api)
|
||||||
@ -100,9 +100,6 @@ signals:
|
|||||||
const QString& mime_type);
|
const QString& mime_type);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString access_token() const;
|
|
||||||
bool is_authenticated() const;
|
|
||||||
|
|
||||||
void AddAuthorizationHeader(QNetworkRequest* request) const;
|
void AddAuthorizationHeader(QNetworkRequest* request) const;
|
||||||
|
|
||||||
void UpdateLibraries();
|
void UpdateLibraries();
|
||||||
|
@ -108,8 +108,10 @@ void SeafileSettingsPage::Save() {
|
|||||||
s.setValue("library", id);
|
s.setValue("library", id);
|
||||||
// Don't need to save the password
|
// Don't need to save the password
|
||||||
|
|
||||||
|
if (service_->has_credentials()) {
|
||||||
service_->ChangeLibrary(id);
|
service_->ChangeLibrary(id);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SeafileSettingsPage::Login() {
|
void SeafileSettingsPage::Login() {
|
||||||
ui_->login_button->setEnabled(false);
|
ui_->login_button->setEnabled(false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user