Replenish context menus for bins/services.
This commit is contained in:
parent
3fb7e82822
commit
2b85b06b48
9 changed files with 89 additions and 26 deletions
|
@ -1 +1 @@
|
|||
Subproject commit d44aacc99fdc997648c924f0d5444566164f142e
|
||||
Subproject commit ae7084718c41afc01919779e58cd449e0eebd401
|
|
@ -43,11 +43,8 @@
|
|||
#include <QTimer>
|
||||
|
||||
FeedsView::FeedsView(QWidget* parent)
|
||||
: QTreeView(parent),
|
||||
m_contextMenuCategories(nullptr),
|
||||
m_contextMenuFeeds(nullptr),
|
||||
m_contextMenuEmptySpace(nullptr),
|
||||
m_contextMenuOtherItems(nullptr) {
|
||||
: QTreeView(parent), m_contextMenuService(nullptr), m_contextMenuBin(nullptr), m_contextMenuCategories(nullptr),
|
||||
m_contextMenuFeeds(nullptr), m_contextMenuEmptySpace(nullptr), m_contextMenuOtherItems(nullptr) {
|
||||
setObjectName(QSL("FeedsView"));
|
||||
|
||||
// Allocate models.
|
||||
|
@ -422,6 +419,53 @@ QModelIndex FeedsView::nextUnreadItem(QModelIndex default_row) {
|
|||
return QModelIndex();
|
||||
}
|
||||
|
||||
QMenu* FeedsView::initializeContextMenuBin(RootItem* clicked_item) {
|
||||
if (m_contextMenuBin == nullptr) {
|
||||
m_contextMenuBin = new QMenu(tr("Context menu for recycle bins"), this);
|
||||
}
|
||||
else {
|
||||
m_contextMenuBin->clear();
|
||||
}
|
||||
|
||||
QList<QAction*> specific_actions = clicked_item->contextMenu();
|
||||
m_contextMenuBin->addActions(QList<QAction*>() <<
|
||||
qApp->mainForm()->m_ui->m_actionViewSelectedItemsNewspaperMode <<
|
||||
qApp->mainForm()->m_ui->m_actionMarkSelectedItemsAsRead <<
|
||||
qApp->mainForm()->m_ui->m_actionMarkSelectedItemsAsUnread);
|
||||
|
||||
if (!specific_actions.isEmpty()) {
|
||||
m_contextMenuBin->addSeparator();
|
||||
m_contextMenuBin->addActions(specific_actions);
|
||||
}
|
||||
|
||||
return m_contextMenuBin;
|
||||
}
|
||||
|
||||
QMenu* FeedsView::initializeContextMenuService(RootItem* clicked_item) {
|
||||
if (m_contextMenuService == nullptr) {
|
||||
m_contextMenuService = new QMenu(tr("Context menu for accounts"), this);
|
||||
}
|
||||
else {
|
||||
m_contextMenuService->clear();
|
||||
}
|
||||
|
||||
QList<QAction*> specific_actions = clicked_item->contextMenu();
|
||||
m_contextMenuService->addActions(QList<QAction*>() <<
|
||||
qApp->mainForm()->m_ui->m_actionUpdateSelectedItems <<
|
||||
qApp->mainForm()->m_ui->m_actionEditSelectedItem <<
|
||||
qApp->mainForm()->m_ui->m_actionViewSelectedItemsNewspaperMode <<
|
||||
qApp->mainForm()->m_ui->m_actionMarkSelectedItemsAsRead <<
|
||||
qApp->mainForm()->m_ui->m_actionMarkSelectedItemsAsUnread <<
|
||||
qApp->mainForm()->m_ui->m_actionDeleteSelectedItem);
|
||||
|
||||
if (!specific_actions.isEmpty()) {
|
||||
m_contextMenuService->addSeparator();
|
||||
m_contextMenuService->addActions(specific_actions);
|
||||
}
|
||||
|
||||
return m_contextMenuService;
|
||||
}
|
||||
|
||||
void FeedsView::switchVisibility() {
|
||||
setVisible(!isVisible());
|
||||
}
|
||||
|
@ -570,6 +614,12 @@ void FeedsView::contextMenuEvent(QContextMenuEvent* event) {
|
|||
// Display context menu for feeds.
|
||||
initializeContextMenuFeeds(clicked_item)->exec(event->globalPos());
|
||||
}
|
||||
else if (clicked_item->kind() == RootItemKind::Bin) {
|
||||
initializeContextMenuBin(clicked_item)->exec(event->globalPos());
|
||||
}
|
||||
else if (clicked_item->kind() == RootItemKind::ServiceRoot) {
|
||||
initializeContextMenuService(clicked_item)->exec(event->globalPos());
|
||||
}
|
||||
else {
|
||||
initializeContextMenuOtherItem(clicked_item)->exec(event->globalPos());
|
||||
}
|
||||
|
|
|
@ -122,6 +122,8 @@ class FeedsView : public QTreeView {
|
|||
QModelIndex nextUnreadItem(QModelIndex default_row);
|
||||
|
||||
// Initializes context menus.
|
||||
QMenu* initializeContextMenuBin(RootItem* clicked_item);
|
||||
QMenu* initializeContextMenuService(RootItem* clicked_item);
|
||||
QMenu* initializeContextMenuCategories(RootItem* clicked_item);
|
||||
QMenu* initializeContextMenuFeeds(RootItem* clicked_item);
|
||||
QMenu* initializeContextMenuEmptySpace();
|
||||
|
@ -132,6 +134,8 @@ class FeedsView : public QTreeView {
|
|||
|
||||
void saveExpandStates(RootItem* item);
|
||||
|
||||
QMenu* m_contextMenuService;
|
||||
QMenu* m_contextMenuBin;
|
||||
QMenu* m_contextMenuCategories;
|
||||
QMenu* m_contextMenuFeeds;
|
||||
QMenu* m_contextMenuEmptySpace;
|
||||
|
|
|
@ -1552,6 +1552,9 @@ QList<ServiceRoot*> DatabaseQueries::getInoreaderAccounts(QSqlDatabase db, bool*
|
|||
root->setId(query.value(0).toInt());
|
||||
root->setAccountId(query.value(0).toInt());
|
||||
root->network()->setUsername(query.value(1).toString());
|
||||
root->network()->oauth()->setClientId(query.value(2).toString());
|
||||
root->network()->oauth()->setClientSecret(query.value(3).toString());
|
||||
root->network()->oauth()->setRedirectUrl(query.value(4).toString());
|
||||
root->network()->oauth()->setRefreshToken(query.value(5).toString());
|
||||
root->network()->setBatchSize(query.value(6).toInt());
|
||||
root->updateTitle();
|
||||
|
|
|
@ -55,7 +55,7 @@ OAuth2Service::OAuth2Service(QString authUrl, QString tokenUrl, QString clientId
|
|||
QString clientSecret, QString scope, QObject* parent)
|
||||
: QObject(parent), m_tokensExpireIn(QDateTime()) {
|
||||
|
||||
m_redirectUri = QSL(INOREADER_OAUTH_CLI_REDIRECT);
|
||||
m_redirectUrl = QSL(INOREADER_OAUTH_CLI_REDIRECT);
|
||||
m_tokenGrantType = QSL("authorization_code");
|
||||
m_tokenUrl = QUrl(tokenUrl);
|
||||
m_authUrl = authUrl;
|
||||
|
@ -99,7 +99,7 @@ void OAuth2Service::retrieveAccessToken(QString auth_code) {
|
|||
.arg(m_clientSecret)
|
||||
.arg(auth_code)
|
||||
.arg(m_tokenGrantType)
|
||||
.arg(m_redirectUri);
|
||||
.arg(m_redirectUrl);
|
||||
|
||||
m_networkManager.post(networkRequest, content.toUtf8());
|
||||
}
|
||||
|
@ -194,12 +194,12 @@ void OAuth2Service::setClientId(const QString& client_id) {
|
|||
m_clientId = client_id;
|
||||
}
|
||||
|
||||
QString OAuth2Service::redirectUri() const {
|
||||
return m_redirectUri;
|
||||
QString OAuth2Service::redirectUrl() const {
|
||||
return m_redirectUrl;
|
||||
}
|
||||
|
||||
void OAuth2Service::setRedirectUri(const QString& redirect_uri) {
|
||||
m_redirectUri = redirect_uri;
|
||||
void OAuth2Service::setRedirectUrl(const QString& redirect_url) {
|
||||
m_redirectUrl = redirect_url;
|
||||
}
|
||||
|
||||
QString OAuth2Service::refreshToken() const {
|
||||
|
@ -242,7 +242,7 @@ void OAuth2Service::retrieveAuthCode() {
|
|||
QString auth_url = m_authUrl + QString("?client_id=%1&scope=%2&"
|
||||
"redirect_uri=%3&response_type=code&state=abcdef").arg(m_clientId,
|
||||
m_scope,
|
||||
m_redirectUri);
|
||||
m_redirectUrl);
|
||||
OAuthLogin login_page(qApp->mainFormWidget());
|
||||
|
||||
connect(&login_page, &OAuthLogin::authGranted, this, &OAuth2Service::authCodeObtained);
|
||||
|
@ -250,5 +250,5 @@ void OAuth2Service::retrieveAuthCode() {
|
|||
cleanTokens();
|
||||
emit authFailed();
|
||||
});
|
||||
login_page.login(auth_url, m_redirectUri);
|
||||
login_page.login(auth_url, m_redirectUrl);
|
||||
}
|
||||
|
|
|
@ -62,8 +62,8 @@ class OAuth2Service : public QObject {
|
|||
QString refreshToken() const;
|
||||
void setRefreshToken(const QString& refresh_token);
|
||||
|
||||
QString redirectUri() const;
|
||||
void setRedirectUri(const QString& redirect_uri);
|
||||
QString redirectUrl() const;
|
||||
void setRedirectUrl(const QString& redirect_url);
|
||||
|
||||
QString clientId() const;
|
||||
void setClientId(const QString& client_id);
|
||||
|
@ -109,7 +109,7 @@ class OAuth2Service : public QObject {
|
|||
QString m_accessToken;
|
||||
QString m_refreshToken;
|
||||
QString m_tokenGrantType;
|
||||
QString m_redirectUri;
|
||||
QString m_redirectUrl;
|
||||
QString m_clientId;
|
||||
QString m_clientSecret;
|
||||
QUrl m_tokenUrl;
|
||||
|
|
|
@ -65,9 +65,16 @@ FormEditInoreaderAccount::FormEditInoreaderAccount(QWidget* parent) : QDialog(pa
|
|||
FormEditInoreaderAccount::~FormEditInoreaderAccount() {}
|
||||
|
||||
void FormEditInoreaderAccount::testSetup() {
|
||||
if (m_oauth->clientId() != m_ui.m_txtAppId->lineEdit()->text() ||
|
||||
m_oauth->clientSecret() != m_ui.m_txtAppKey->lineEdit()->text() ||
|
||||
m_oauth->redirectUrl() != m_ui.m_txtRedirectUrl->lineEdit()->text()) {
|
||||
// User changed some important settings. Log out.
|
||||
m_oauth->logout();
|
||||
}
|
||||
|
||||
m_oauth->setClientId(m_ui.m_txtAppId->lineEdit()->text());
|
||||
m_oauth->setClientSecret(m_ui.m_txtAppKey->lineEdit()->text());
|
||||
m_oauth->setRedirectUri(m_ui.m_txtRedirectUrl->lineEdit()->text());
|
||||
m_oauth->setRedirectUrl(m_ui.m_txtRedirectUrl->lineEdit()->text());
|
||||
|
||||
if (m_oauth->login()) {
|
||||
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Ok,
|
||||
|
@ -93,7 +100,7 @@ void FormEditInoreaderAccount::onClickedOk() {
|
|||
|
||||
m_editableRoot->network()->oauth()->setClientId(m_ui.m_txtAppId->lineEdit()->text());
|
||||
m_editableRoot->network()->oauth()->setClientSecret(m_ui.m_txtAppKey->lineEdit()->text());
|
||||
m_editableRoot->network()->oauth()->setRedirectUri(m_ui.m_txtRedirectUrl->lineEdit()->text());
|
||||
m_editableRoot->network()->oauth()->setRedirectUrl(m_ui.m_txtRedirectUrl->lineEdit()->text());
|
||||
|
||||
m_editableRoot->network()->setUsername(m_ui.m_txtUsername->lineEdit()->text());
|
||||
m_editableRoot->network()->setBatchSize(m_ui.m_spinLimitMessages->value());
|
||||
|
@ -164,14 +171,15 @@ void FormEditInoreaderAccount::execForEdit(InoreaderServiceRoot* existing_root)
|
|||
// We copy settings from existing OAuth to our testing OAuth.
|
||||
m_oauth->setClientId(existing_root->network()->oauth()->clientId());
|
||||
m_oauth->setClientSecret(existing_root->network()->oauth()->clientSecret());
|
||||
m_oauth->setRedirectUri(existing_root->network()->oauth()->redirectUri());
|
||||
m_oauth->setRedirectUrl(existing_root->network()->oauth()->redirectUrl());
|
||||
m_oauth->setRefreshToken(existing_root->network()->oauth()->refreshToken());
|
||||
m_oauth->setAccessToken(existing_root->network()->oauth()->accessToken());
|
||||
m_oauth->setTokensExpireIn(existing_root->network()->oauth()->tokensExpireIn());
|
||||
|
||||
// Setup the GUI.
|
||||
m_ui.m_txtAppId->lineEdit()->setText(existing_root->network()->oauth()->clientId());
|
||||
m_ui.m_txtAppKey->lineEdit()->setText(existing_root->network()->oauth()->clientSecret());
|
||||
m_ui.m_txtRedirectUrl->lineEdit()->setText(existing_root->network()->oauth()->redirectUri());
|
||||
m_ui.m_txtRedirectUrl->lineEdit()->setText(existing_root->network()->oauth()->redirectUrl());
|
||||
|
||||
m_ui.m_txtUsername->lineEdit()->setText(existing_root->network()->userName());
|
||||
m_ui.m_spinLimitMessages->setValue(existing_root->network()->batchSize());
|
||||
|
|
|
@ -69,7 +69,7 @@ void InoreaderServiceRoot::saveAccountDataToDatabase() {
|
|||
if (DatabaseQueries::overwriteInoreaderAccount(database, m_network->userName(),
|
||||
m_network->oauth()->clientId(),
|
||||
m_network->oauth()->clientSecret(),
|
||||
m_network->oauth()->redirectUri(),
|
||||
m_network->oauth()->redirectUrl(),
|
||||
m_network->oauth()->refreshToken(),
|
||||
m_network->batchSize(),
|
||||
accountId())) {
|
||||
|
@ -86,7 +86,7 @@ void InoreaderServiceRoot::saveAccountDataToDatabase() {
|
|||
m_network->userName(),
|
||||
m_network->oauth()->clientId(),
|
||||
m_network->oauth()->clientSecret(),
|
||||
m_network->oauth()->redirectUri(),
|
||||
m_network->oauth()->redirectUrl(),
|
||||
m_network->oauth()->refreshToken(),
|
||||
m_network->batchSize())) {
|
||||
setId(id_to_assign);
|
||||
|
|
|
@ -145,8 +145,6 @@ QList<Message> InoreaderNetworkFactory::decodeMessages(const QString& messages_j
|
|||
QList<Message> messages;
|
||||
QJsonArray json = QJsonDocument::fromJson(messages_json_data.toUtf8()).object()["items"].toArray();
|
||||
|
||||
IOFactory::writeTextFile("aa.aa", messages_json_data.toUtf8());
|
||||
|
||||
messages.reserve(json.count());
|
||||
|
||||
foreach (const QJsonValue& obj, json) {
|
||||
|
@ -155,7 +153,7 @@ QList<Message> InoreaderNetworkFactory::decodeMessages(const QString& messages_j
|
|||
|
||||
message.m_title = message_obj["title"].toString();
|
||||
message.m_author = message_obj["author"].toString();
|
||||
message.m_created = QDateTime::fromMSecsSinceEpoch(message_obj["published"].toInt());
|
||||
message.m_created = QDateTime::fromSecsSinceEpoch(message_obj["published"].toInt());
|
||||
message.m_createdFromFeed = true;
|
||||
message.m_customId = message_obj["id"].toString();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue