2018-11-04 09:48:33 -05:00
|
|
|
/*******************************************************************************
|
|
|
|
* plugins/FeedReader/gui/AddFeedDialog.cpp *
|
|
|
|
* *
|
|
|
|
* Copyright (C) 2012 by Thunder *
|
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Affero General Public License as *
|
|
|
|
* published by the Free Software Foundation, either version 3 of the *
|
|
|
|
* License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU Affero General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Affero General Public License *
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
2012-08-02 09:17:53 -04:00
|
|
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QPushButton>
|
|
|
|
|
|
|
|
#include "AddFeedDialog.h"
|
|
|
|
#include "ui_AddFeedDialog.h"
|
2012-08-13 17:35:11 -04:00
|
|
|
#include "PreviewFeedDialog.h"
|
|
|
|
#include "FeedReaderStringDefs.h"
|
2012-09-04 19:53:04 -04:00
|
|
|
#include "gui/settings/rsharesettings.h"
|
2014-11-24 17:40:29 -05:00
|
|
|
#include "gui/common/UIStateHelper.h"
|
2012-08-13 17:35:11 -04:00
|
|
|
|
2014-11-24 17:40:29 -05:00
|
|
|
#include <retroshare/rsgxsforums.h>
|
2023-04-10 18:36:41 -04:00
|
|
|
#include <retroshare/rsposted.h>
|
2014-11-24 17:40:29 -05:00
|
|
|
#include <iostream>
|
2012-08-02 09:17:53 -04:00
|
|
|
|
2023-04-10 18:36:41 -04:00
|
|
|
#define TOKEN_TYPE_FORUM_GROUPS 1
|
|
|
|
#define TOKEN_TYPE_POSTED_GROUPS 2
|
2012-08-02 09:17:53 -04:00
|
|
|
|
2012-08-13 17:35:11 -04:00
|
|
|
AddFeedDialog::AddFeedDialog(RsFeedReader *feedReader, FeedReaderNotify *notify, QWidget *parent)
|
2012-09-04 19:53:04 -04:00
|
|
|
: QDialog(parent, Qt::Window), mFeedReader(feedReader), mNotify(notify), ui(new Ui::AddFeedDialog)
|
2012-08-02 09:17:53 -04:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2014-11-24 17:40:29 -05:00
|
|
|
/* Setup UI helper */
|
|
|
|
mStateHelper = new UIStateHelper(this);
|
|
|
|
|
2020-11-08 07:22:59 -05:00
|
|
|
mFeedId = 0;
|
|
|
|
mParentId = 0;
|
|
|
|
|
2014-11-24 17:40:29 -05:00
|
|
|
mStateHelper->addWidget(TOKEN_TYPE_FORUM_GROUPS, ui->forumComboBox, UISTATE_LOADING_DISABLED);
|
|
|
|
mStateHelper->addWidget(TOKEN_TYPE_FORUM_GROUPS, ui->buttonBox->button(QDialogButtonBox::Ok), UISTATE_LOADING_DISABLED);
|
2023-04-10 18:36:41 -04:00
|
|
|
mStateHelper->addWidget(TOKEN_TYPE_POSTED_GROUPS, ui->postedComboBox, UISTATE_LOADING_DISABLED);
|
|
|
|
mStateHelper->addWidget(TOKEN_TYPE_POSTED_GROUPS, ui->buttonBox->button(QDialogButtonBox::Ok), UISTATE_LOADING_DISABLED);
|
2014-11-24 17:40:29 -05:00
|
|
|
|
|
|
|
/* Setup TokenQueue */
|
2023-04-10 18:36:41 -04:00
|
|
|
mForumTokenQueue = new TokenQueue(rsGxsForums->getTokenService(), this);
|
|
|
|
mPostedTokenQueue = new TokenQueue(rsPosted->getTokenService(), this);
|
2014-11-24 17:40:29 -05:00
|
|
|
|
|
|
|
/* Connect signals */
|
2012-08-02 09:17:53 -04:00
|
|
|
connect(ui->buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(createFeed()));
|
|
|
|
connect(ui->buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(reject()));
|
|
|
|
|
|
|
|
connect(ui->useAuthenticationCheckBox, SIGNAL(toggled(bool)), this, SLOT(authenticationToggled()));
|
|
|
|
connect(ui->useStandardStorageTimeCheckBox, SIGNAL(toggled(bool)), this, SLOT(useStandardStorageTimeToggled()));
|
|
|
|
connect(ui->useStandardUpdateInterval, SIGNAL(toggled(bool)), this, SLOT(useStandardUpdateIntervalToggled()));
|
|
|
|
connect(ui->useStandardProxyCheckBox, SIGNAL(toggled(bool)), this, SLOT(useStandardProxyToggled()));
|
2023-04-10 18:36:41 -04:00
|
|
|
connect(ui->typeForumCheckBox, SIGNAL(toggled(bool)), this, SLOT(typeForumToggled()));
|
|
|
|
connect(ui->typePostedCheckBox, SIGNAL(toggled(bool)), this, SLOT(typePostedToggled()));
|
|
|
|
connect(ui->typeLocalCheckBox, SIGNAL(toggled(bool)), this, SLOT(typeLocalToggled()));
|
|
|
|
connect(ui->postedFirstImageCheckBox, SIGNAL(toggled(bool)), this, SLOT(postedFirstImageToggled()));
|
2012-08-13 17:35:11 -04:00
|
|
|
connect(ui->previewButton, SIGNAL(clicked()), this, SLOT(preview()));
|
2012-08-02 09:17:53 -04:00
|
|
|
|
2014-11-24 17:40:29 -05:00
|
|
|
/* currently only for local feeds */
|
2023-04-10 18:36:41 -04:00
|
|
|
connect(ui->saveCompletePageCheckBox, SIGNAL(toggled(bool)), this, SLOT(denyForumAndPostedToggled()));
|
2012-08-10 14:06:29 -04:00
|
|
|
|
2012-08-02 09:17:53 -04:00
|
|
|
connect(ui->urlLineEdit, SIGNAL(textChanged(QString)), this, SLOT(validate()));
|
|
|
|
connect(ui->nameLineEdit, SIGNAL(textChanged(QString)), this, SLOT(validate()));
|
|
|
|
connect(ui->useInfoFromFeedCheckBox, SIGNAL(toggled(bool)), this, SLOT(validate()));
|
2023-04-10 18:36:41 -04:00
|
|
|
connect(ui->typeLocalCheckBox, SIGNAL(toggled(bool)), this, SLOT(validate()));
|
|
|
|
connect(ui->typeForumCheckBox, SIGNAL(toggled(bool)), this, SLOT(validate()));
|
2014-11-24 17:40:29 -05:00
|
|
|
connect(ui->forumComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(validate()));
|
2023-04-10 18:36:41 -04:00
|
|
|
connect(ui->typePostedCheckBox, SIGNAL(toggled(bool)), this, SLOT(validate()));
|
|
|
|
connect(ui->postedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(validate()));
|
2014-11-24 17:40:29 -05:00
|
|
|
|
|
|
|
connect(ui->clearCachePushButton, SIGNAL(clicked()), this, SLOT(clearMessageCache()));
|
2012-08-02 09:17:53 -04:00
|
|
|
|
2012-12-18 08:41:36 -05:00
|
|
|
ui->headerFrame->setHeaderText(tr("Feed Details"));
|
|
|
|
ui->headerFrame->setHeaderImage(QPixmap(":/images/FeedReader.png"));
|
|
|
|
|
2012-08-02 09:17:53 -04:00
|
|
|
ui->activatedCheckBox->setChecked(true);
|
2014-11-24 17:40:29 -05:00
|
|
|
mStateHelper->setWidgetEnabled(ui->forumComboBox, false);
|
2023-04-10 18:36:41 -04:00
|
|
|
mStateHelper->setWidgetEnabled(ui->postedComboBox, false);
|
2012-08-02 09:17:53 -04:00
|
|
|
ui->useInfoFromFeedCheckBox->setChecked(true);
|
|
|
|
ui->updateForumInfoCheckBox->setEnabled(false);
|
|
|
|
ui->updateForumInfoCheckBox->setChecked(true);
|
2023-04-10 18:36:41 -04:00
|
|
|
ui->updatePostedInfoCheckBox->setEnabled(false);
|
|
|
|
ui->updatePostedInfoCheckBox->setChecked(true);
|
|
|
|
ui->postedFirstImageCheckBox->setEnabled(false);
|
|
|
|
ui->postedFirstImageCheckBox->setChecked(false);
|
|
|
|
ui->postedOnlyImageCheckBox->setEnabled(false);
|
|
|
|
ui->postedOnlyImageCheckBox->setChecked(false);
|
2023-04-26 15:53:59 -04:00
|
|
|
ui->postedShinkImageCheckBox->setEnabled(false);
|
2023-05-09 01:49:34 -04:00
|
|
|
ui->postedShinkImageCheckBox->setChecked(true);
|
2012-08-02 09:17:53 -04:00
|
|
|
ui->useAuthenticationCheckBox->setChecked(false);
|
|
|
|
ui->useStandardStorageTimeCheckBox->setChecked(true);
|
|
|
|
ui->useStandardUpdateInterval->setChecked(true);
|
|
|
|
ui->useStandardProxyCheckBox->setChecked(true);
|
2023-04-10 18:36:41 -04:00
|
|
|
ui->embedImagesCheckBox->setChecked(true);
|
|
|
|
ui->saveCompletePageCheckBox->setEnabled(false);
|
2012-08-02 09:17:53 -04:00
|
|
|
|
|
|
|
/* not yet supported */
|
|
|
|
ui->authenticationGroupBox->setEnabled(false);
|
|
|
|
|
2013-01-21 19:11:43 -05:00
|
|
|
mTransformationType = RS_FEED_TRANSFORMATION_TYPE_NONE;
|
|
|
|
ui->transformationTypeLabel->setText(FeedReaderStringDefs::transforationTypeString(mTransformationType));
|
|
|
|
|
2014-11-24 17:40:29 -05:00
|
|
|
ui->clearCachePushButton->show();
|
|
|
|
|
2012-08-02 09:17:53 -04:00
|
|
|
/* fill own forums */
|
2014-11-24 17:40:29 -05:00
|
|
|
requestForumGroups();
|
2012-08-02 09:17:53 -04:00
|
|
|
|
2023-04-10 18:36:41 -04:00
|
|
|
/* fill own posted */
|
|
|
|
requestPostedGroups();
|
|
|
|
|
2012-08-02 09:17:53 -04:00
|
|
|
validate();
|
|
|
|
|
|
|
|
ui->urlLineEdit->setFocus();
|
2012-09-04 19:53:04 -04:00
|
|
|
|
|
|
|
/* load settings */
|
|
|
|
processSettings(true);
|
2012-08-02 09:17:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
AddFeedDialog::~AddFeedDialog()
|
|
|
|
{
|
2012-09-04 19:53:04 -04:00
|
|
|
/* save settings */
|
|
|
|
processSettings(false);
|
|
|
|
|
2014-11-24 17:40:29 -05:00
|
|
|
delete(ui);
|
2023-04-10 18:36:41 -04:00
|
|
|
delete(mForumTokenQueue);
|
|
|
|
delete(mPostedTokenQueue);
|
2012-08-02 09:17:53 -04:00
|
|
|
}
|
|
|
|
|
2012-09-04 19:53:04 -04:00
|
|
|
void AddFeedDialog::processSettings(bool load)
|
|
|
|
{
|
|
|
|
Settings->beginGroup(QString("AddFeedDialog"));
|
|
|
|
|
|
|
|
if (load) {
|
|
|
|
// load settings
|
|
|
|
QByteArray geometry = Settings->value("Geometry").toByteArray();
|
|
|
|
if (!geometry.isEmpty()) {
|
|
|
|
restoreGeometry(geometry);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// save settings
|
|
|
|
Settings->setValue("Geometry", saveGeometry());
|
|
|
|
}
|
|
|
|
|
|
|
|
Settings->endGroup();
|
|
|
|
}
|
|
|
|
|
2012-08-02 09:17:53 -04:00
|
|
|
void AddFeedDialog::authenticationToggled()
|
|
|
|
{
|
|
|
|
bool checked = ui->useAuthenticationCheckBox->isChecked();
|
|
|
|
ui->userLineEdit->setEnabled(checked);
|
|
|
|
ui->passwordLineEdit->setEnabled(checked);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddFeedDialog::useStandardStorageTimeToggled()
|
|
|
|
{
|
|
|
|
bool checked = ui->useStandardStorageTimeCheckBox->isChecked();
|
|
|
|
ui->storageTimeSpinBox->setEnabled(!checked);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddFeedDialog::useStandardUpdateIntervalToggled()
|
|
|
|
{
|
|
|
|
bool checked = ui->useStandardUpdateInterval->isChecked();
|
|
|
|
ui->updateIntervalSpinBox->setEnabled(!checked);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddFeedDialog::useStandardProxyToggled()
|
|
|
|
{
|
|
|
|
bool checked = ui->useStandardProxyCheckBox->isChecked();
|
|
|
|
ui->proxyAddressLineEdit->setEnabled(!checked);
|
|
|
|
ui->proxyPortSpinBox->setEnabled(!checked);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddFeedDialog::typeForumToggled()
|
|
|
|
{
|
2023-04-10 18:36:41 -04:00
|
|
|
bool checked = ui->typeForumCheckBox->isChecked();
|
2014-11-24 17:40:29 -05:00
|
|
|
mStateHelper->setWidgetEnabled(ui->forumComboBox, checked);
|
2012-08-02 09:17:53 -04:00
|
|
|
ui->updateForumInfoCheckBox->setEnabled(checked);
|
2023-04-10 18:36:41 -04:00
|
|
|
|
|
|
|
if (checked) {
|
|
|
|
ui->typeLocalCheckBox->setChecked(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddFeedDialog::postedFirstImageToggled()
|
|
|
|
{
|
|
|
|
bool checked = ui->postedFirstImageCheckBox->isChecked();
|
|
|
|
ui->postedOnlyImageCheckBox->setEnabled(checked);
|
|
|
|
|
|
|
|
if (!checked) {
|
|
|
|
ui->postedOnlyImageCheckBox->setChecked(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddFeedDialog::typePostedToggled()
|
|
|
|
{
|
|
|
|
bool checked = ui->typePostedCheckBox->isChecked();
|
|
|
|
mStateHelper->setWidgetEnabled(ui->postedComboBox, checked);
|
|
|
|
ui->updatePostedInfoCheckBox->setEnabled(checked);
|
|
|
|
ui->postedFirstImageCheckBox->setEnabled(checked);
|
2023-04-26 15:53:59 -04:00
|
|
|
ui->postedShinkImageCheckBox->setEnabled(checked);
|
2023-04-10 18:36:41 -04:00
|
|
|
|
|
|
|
if (checked) {
|
|
|
|
ui->typeLocalCheckBox->setChecked(false);
|
|
|
|
}else {
|
|
|
|
ui->postedFirstImageCheckBox->setChecked(false);
|
|
|
|
}
|
2012-08-02 09:17:53 -04:00
|
|
|
}
|
|
|
|
|
2023-04-10 18:36:41 -04:00
|
|
|
void AddFeedDialog::typeLocalToggled()
|
|
|
|
{
|
|
|
|
bool checked = ui->typeLocalCheckBox->isChecked();
|
|
|
|
if (checked) {
|
|
|
|
mStateHelper->setWidgetEnabled(ui->forumComboBox, false);
|
|
|
|
mStateHelper->setWidgetEnabled(ui->postedComboBox, false);
|
|
|
|
ui->typeForumCheckBox->setChecked(false);
|
|
|
|
ui->typePostedCheckBox->setChecked(false);
|
|
|
|
ui->saveCompletePageCheckBox->setEnabled(true);
|
|
|
|
} else {
|
|
|
|
ui->saveCompletePageCheckBox->setEnabled(false);
|
|
|
|
ui->saveCompletePageCheckBox->setChecked(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddFeedDialog::denyForumAndPostedToggled()
|
2012-08-10 14:06:29 -04:00
|
|
|
{
|
2013-01-21 19:11:43 -05:00
|
|
|
if (ui->saveCompletePageCheckBox->isChecked()) {
|
2023-04-10 18:36:41 -04:00
|
|
|
ui->typeForumCheckBox->setEnabled(false);
|
|
|
|
ui->typeForumCheckBox->setChecked(false);
|
|
|
|
ui->typePostedCheckBox->setEnabled(false);
|
|
|
|
ui->typePostedCheckBox->setChecked(false);
|
|
|
|
ui->typeLocalCheckBox->setChecked(true);
|
2012-08-10 14:06:29 -04:00
|
|
|
} else {
|
2023-04-10 18:36:41 -04:00
|
|
|
ui->typeForumCheckBox->setEnabled(true);
|
|
|
|
ui->typePostedCheckBox->setEnabled(true);
|
2012-08-10 14:06:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-02 09:17:53 -04:00
|
|
|
void AddFeedDialog::validate()
|
|
|
|
{
|
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
if (ui->urlLineEdit->text().isEmpty()) {
|
|
|
|
ok = false;
|
|
|
|
}
|
|
|
|
if (ui->nameLineEdit->text().isEmpty() && !ui->useInfoFromFeedCheckBox->isChecked()) {
|
|
|
|
ok = false;
|
|
|
|
}
|
2012-08-13 17:35:11 -04:00
|
|
|
|
|
|
|
ui->previewButton->setEnabled(ok);
|
|
|
|
|
2023-04-10 18:36:41 -04:00
|
|
|
if (!ui->typeLocalCheckBox->isChecked() && !ui->typeForumCheckBox->isChecked() && !ui->typePostedCheckBox->isChecked()) {
|
|
|
|
ok = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ui->typeForumCheckBox->isChecked() && ui->forumComboBox->itemData(ui->forumComboBox->currentIndex()).toString().isEmpty()) {
|
2012-08-10 14:06:29 -04:00
|
|
|
ok = false;
|
|
|
|
}
|
2012-08-02 09:17:53 -04:00
|
|
|
|
2023-04-10 18:36:41 -04:00
|
|
|
if (ui->typePostedCheckBox->isChecked() && ui->postedComboBox->itemData(ui->postedComboBox->currentIndex()).toString().isEmpty()) {
|
2014-11-24 17:40:29 -05:00
|
|
|
ok = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mStateHelper->setWidgetEnabled(ui->buttonBox->button(QDialogButtonBox::Ok), ok);
|
2012-08-02 09:17:53 -04:00
|
|
|
}
|
|
|
|
|
2020-11-08 07:22:59 -05:00
|
|
|
void AddFeedDialog::setParent(uint32_t parentId)
|
2012-08-02 09:17:53 -04:00
|
|
|
{
|
|
|
|
mParentId = parentId;
|
|
|
|
}
|
|
|
|
|
2020-11-08 07:22:59 -05:00
|
|
|
bool AddFeedDialog::fillFeed(uint32_t feedId)
|
2012-08-02 09:17:53 -04:00
|
|
|
{
|
|
|
|
mFeedId = feedId;
|
|
|
|
|
2020-11-08 07:22:59 -05:00
|
|
|
if (mFeedId) {
|
2012-08-02 09:17:53 -04:00
|
|
|
FeedInfo feedInfo;
|
|
|
|
if (!mFeedReader->getFeedInfo(mFeedId, feedInfo)) {
|
2020-11-08 07:22:59 -05:00
|
|
|
mFeedId = 0;
|
2012-08-02 09:17:53 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
setWindowTitle(tr("Edit feed"));
|
|
|
|
|
|
|
|
mParentId = feedInfo.parentId;
|
|
|
|
|
|
|
|
ui->nameLineEdit->setText(QString::fromUtf8(feedInfo.name.c_str()));
|
|
|
|
ui->urlLineEdit->setText(QString::fromUtf8(feedInfo.url.c_str()));
|
|
|
|
ui->useInfoFromFeedCheckBox->setChecked(feedInfo.flag.infoFromFeed);
|
|
|
|
ui->updateForumInfoCheckBox->setChecked(feedInfo.flag.updateForumInfo);
|
2023-04-10 18:36:41 -04:00
|
|
|
ui->updatePostedInfoCheckBox->setChecked(feedInfo.flag.updatePostedInfo);
|
|
|
|
ui->postedFirstImageCheckBox->setChecked(feedInfo.flag.postedFirstImage);
|
|
|
|
ui->postedOnlyImageCheckBox->setChecked(feedInfo.flag.postedOnlyImage);
|
2023-04-26 15:53:59 -04:00
|
|
|
ui->postedShinkImageCheckBox->setChecked(feedInfo.flag.postedShrinkImage);
|
2012-08-02 09:17:53 -04:00
|
|
|
ui->activatedCheckBox->setChecked(!feedInfo.flag.deactivated);
|
2012-08-10 14:06:29 -04:00
|
|
|
ui->embedImagesCheckBox->setChecked(feedInfo.flag.embedImages);
|
|
|
|
ui->saveCompletePageCheckBox->setChecked(feedInfo.flag.saveCompletePage);
|
2012-08-02 09:17:53 -04:00
|
|
|
|
|
|
|
ui->descriptionPlainTextEdit->setPlainText(QString::fromUtf8(feedInfo.description.c_str()));
|
|
|
|
|
2023-04-10 18:36:41 -04:00
|
|
|
if (feedInfo.flag.forum || feedInfo.flag.posted) {
|
|
|
|
if (feedInfo.flag.forum) {
|
|
|
|
mStateHelper->setWidgetEnabled(ui->forumComboBox, true);
|
|
|
|
ui->typeForumCheckBox->setChecked(true);
|
2012-08-02 09:17:53 -04:00
|
|
|
|
2023-04-10 18:36:41 -04:00
|
|
|
setActiveForumId(feedInfo.forumId);
|
|
|
|
}
|
|
|
|
if (feedInfo.flag.posted) {
|
|
|
|
mStateHelper->setWidgetEnabled(ui->postedComboBox, true);
|
|
|
|
ui->typePostedCheckBox->setChecked(true);
|
|
|
|
|
|
|
|
setActivePostedId(feedInfo.postedId);
|
|
|
|
}
|
|
|
|
ui->saveCompletePageCheckBox->setEnabled(false);
|
2012-08-02 09:17:53 -04:00
|
|
|
} else {
|
2023-04-10 18:36:41 -04:00
|
|
|
ui->typeLocalCheckBox->setChecked(true);
|
2014-11-24 17:40:29 -05:00
|
|
|
mStateHelper->setWidgetEnabled(ui->forumComboBox, false);
|
2012-08-02 09:17:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ui->useAuthenticationCheckBox->setChecked(feedInfo.flag.authentication);
|
|
|
|
ui->userLineEdit->setText(QString::fromUtf8(feedInfo.user.c_str()));
|
|
|
|
ui->passwordLineEdit->setText(QString::fromUtf8(feedInfo.password.c_str()));
|
|
|
|
|
|
|
|
ui->useStandardProxyCheckBox->setChecked(feedInfo.flag.standardProxy);
|
|
|
|
ui->proxyAddressLineEdit->setText(QString::fromUtf8(feedInfo.proxyAddress.c_str()));
|
|
|
|
ui->proxyPortSpinBox->setValue(feedInfo.proxyPort);
|
|
|
|
|
|
|
|
ui->useStandardUpdateInterval->setChecked(feedInfo.flag.standardUpdateInterval);
|
|
|
|
ui->updateIntervalSpinBox->setValue(feedInfo.updateInterval / 60);
|
|
|
|
QDateTime dateTime;
|
|
|
|
dateTime.setTime_t(feedInfo.lastUpdate);
|
|
|
|
ui->lastUpdate->setText(dateTime.toString());
|
|
|
|
|
|
|
|
ui->useStandardStorageTimeCheckBox->setChecked(feedInfo.flag.standardStorageTime);
|
|
|
|
ui->storageTimeSpinBox->setValue(feedInfo.storageTime / (60 * 60 *24));
|
2012-09-04 19:53:04 -04:00
|
|
|
|
2013-01-21 19:11:43 -05:00
|
|
|
mTransformationType = feedInfo.transformationType;
|
2012-09-04 19:53:04 -04:00
|
|
|
mXPathsToUse = feedInfo.xpathsToUse;
|
|
|
|
mXPathsToRemove = feedInfo.xpathsToRemove;
|
2013-01-21 19:11:43 -05:00
|
|
|
mXslt = feedInfo.xslt;
|
|
|
|
|
|
|
|
ui->transformationTypeLabel->setText(FeedReaderStringDefs::transforationTypeString(mTransformationType));
|
2014-11-24 17:40:29 -05:00
|
|
|
|
|
|
|
ui->clearCachePushButton->show();
|
2012-08-02 09:17:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-24 17:40:29 -05:00
|
|
|
void AddFeedDialog::setActiveForumId(const std::string &forumId)
|
|
|
|
{
|
|
|
|
if (mStateHelper->isLoading(TOKEN_TYPE_FORUM_GROUPS)) {
|
|
|
|
mFillForumId = forumId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int index = ui->forumComboBox->findData(QString::fromStdString(forumId));
|
|
|
|
if (index >= 0) {
|
|
|
|
ui->forumComboBox->setCurrentIndex(index);
|
|
|
|
} else {
|
|
|
|
ui->forumComboBox->setCurrentIndex(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-10 18:36:41 -04:00
|
|
|
void AddFeedDialog::setActivePostedId(const std::string &postedId)
|
|
|
|
{
|
|
|
|
if (mStateHelper->isLoading(TOKEN_TYPE_POSTED_GROUPS)) {
|
|
|
|
mFillPostedId = postedId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int index = ui->postedComboBox->findData(QString::fromStdString(postedId));
|
|
|
|
if (index >= 0) {
|
|
|
|
ui->postedComboBox->setCurrentIndex(index);
|
|
|
|
} else {
|
|
|
|
ui->postedComboBox->setCurrentIndex(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-13 17:35:11 -04:00
|
|
|
void AddFeedDialog::getFeedInfo(FeedInfo &feedInfo)
|
2012-08-02 09:17:53 -04:00
|
|
|
{
|
|
|
|
feedInfo.parentId = mParentId;
|
|
|
|
|
|
|
|
feedInfo.name = ui->nameLineEdit->text().toUtf8().constData();
|
|
|
|
feedInfo.url = ui->urlLineEdit->text().toUtf8().constData();
|
|
|
|
feedInfo.flag.infoFromFeed = ui->useInfoFromFeedCheckBox->isChecked();
|
|
|
|
feedInfo.flag.updateForumInfo = ui->updateForumInfoCheckBox->isChecked() && ui->updateForumInfoCheckBox->isEnabled();
|
2023-04-10 18:36:41 -04:00
|
|
|
feedInfo.flag.updatePostedInfo = ui->updatePostedInfoCheckBox->isChecked() && ui->updatePostedInfoCheckBox->isEnabled();
|
|
|
|
feedInfo.flag.postedFirstImage = ui->postedFirstImageCheckBox->isChecked() && ui->postedFirstImageCheckBox->isEnabled();
|
|
|
|
feedInfo.flag.postedOnlyImage = ui->postedOnlyImageCheckBox->isChecked() && ui->postedOnlyImageCheckBox->isEnabled();
|
2023-04-26 15:53:59 -04:00
|
|
|
feedInfo.flag.postedShrinkImage = ui->postedShinkImageCheckBox->isChecked() && ui->postedShinkImageCheckBox->isEnabled();
|
2012-08-02 09:17:53 -04:00
|
|
|
feedInfo.flag.deactivated = !ui->activatedCheckBox->isChecked();
|
2012-08-10 14:06:29 -04:00
|
|
|
feedInfo.flag.embedImages = ui->embedImagesCheckBox->isChecked();
|
|
|
|
feedInfo.flag.saveCompletePage = ui->saveCompletePageCheckBox->isChecked();
|
2012-08-02 09:17:53 -04:00
|
|
|
|
|
|
|
feedInfo.description = ui->descriptionPlainTextEdit->toPlainText().toUtf8().constData();
|
|
|
|
|
2023-04-10 18:36:41 -04:00
|
|
|
feedInfo.flag.forum = ui->typeForumCheckBox->isChecked();
|
2014-11-24 17:40:29 -05:00
|
|
|
|
|
|
|
if (feedInfo.flag.forum) {
|
|
|
|
feedInfo.forumId = ui->forumComboBox->itemData(ui->forumComboBox->currentIndex()).toString().toStdString();
|
2012-08-02 09:17:53 -04:00
|
|
|
}
|
|
|
|
|
2023-04-10 18:36:41 -04:00
|
|
|
feedInfo.flag.posted = ui->typePostedCheckBox->isChecked();
|
|
|
|
|
|
|
|
if (feedInfo.flag.posted) {
|
|
|
|
feedInfo.postedId = ui->postedComboBox->itemData(ui->postedComboBox->currentIndex()).toString().toStdString();
|
|
|
|
}
|
|
|
|
|
2012-08-02 09:17:53 -04:00
|
|
|
feedInfo.flag.authentication = ui->useAuthenticationCheckBox->isChecked();
|
|
|
|
feedInfo.user = ui->userLineEdit->text().toUtf8().constData();
|
|
|
|
feedInfo.password = ui->passwordLineEdit->text().toUtf8().constData();
|
|
|
|
|
|
|
|
feedInfo.flag.standardProxy = ui->useStandardProxyCheckBox->isChecked();
|
|
|
|
feedInfo.proxyAddress = ui->proxyAddressLineEdit->text().toUtf8().constData();
|
|
|
|
feedInfo.proxyPort = ui->proxyPortSpinBox->value();
|
|
|
|
|
|
|
|
feedInfo.flag.standardUpdateInterval = ui->useStandardUpdateInterval->isChecked();
|
|
|
|
feedInfo.updateInterval = ui->updateIntervalSpinBox->value() * 60;
|
|
|
|
|
|
|
|
feedInfo.flag.standardStorageTime = ui->useStandardStorageTimeCheckBox->isChecked();
|
|
|
|
feedInfo.storageTime = ui->storageTimeSpinBox->value() * 60 *60 * 24;
|
2012-09-04 19:53:04 -04:00
|
|
|
|
2013-01-21 19:11:43 -05:00
|
|
|
feedInfo.transformationType = mTransformationType;
|
2012-09-04 19:53:04 -04:00
|
|
|
feedInfo.xpathsToUse = mXPathsToUse;
|
|
|
|
feedInfo.xpathsToRemove = mXPathsToRemove;
|
2013-01-21 19:11:43 -05:00
|
|
|
feedInfo.xslt = mXslt;
|
2012-08-13 17:35:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void AddFeedDialog::createFeed()
|
|
|
|
{
|
|
|
|
FeedInfo feedInfo;
|
2020-11-08 07:22:59 -05:00
|
|
|
if (mFeedId) {
|
2012-08-13 17:35:11 -04:00
|
|
|
if (!mFeedReader->getFeedInfo(mFeedId, feedInfo)) {
|
|
|
|
QMessageBox::critical(this, tr("Edit feed"), tr("Can't edit feed. Feed does not exist."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getFeedInfo(feedInfo);
|
2012-08-02 09:17:53 -04:00
|
|
|
|
2020-11-08 07:22:59 -05:00
|
|
|
if (mFeedId == 0) {
|
2012-08-02 09:17:53 -04:00
|
|
|
/* add new feed */
|
2023-04-13 14:16:10 -04:00
|
|
|
RsFeedResult result = mFeedReader->addFeed(feedInfo, mFeedId);
|
2012-08-13 17:35:11 -04:00
|
|
|
if (FeedReaderStringDefs::showError(this, result, tr("Create feed"), tr("Cannot create feed."))) {
|
2012-08-02 09:17:53 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2023-04-13 14:16:10 -04:00
|
|
|
RsFeedResult result = mFeedReader->setFeed(mFeedId, feedInfo);
|
2012-08-13 17:35:11 -04:00
|
|
|
if (FeedReaderStringDefs::showError(this, result, tr("Edit feed"), tr("Cannot change feed."))) {
|
2012-08-02 09:17:53 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
close();
|
|
|
|
}
|
2012-08-13 17:35:11 -04:00
|
|
|
|
|
|
|
void AddFeedDialog::preview()
|
|
|
|
{
|
|
|
|
FeedInfo feedInfo;
|
|
|
|
getFeedInfo(feedInfo);
|
|
|
|
|
|
|
|
PreviewFeedDialog dialog(mFeedReader, mNotify, feedInfo, this);
|
2012-09-04 19:53:04 -04:00
|
|
|
if (dialog.exec() == QDialog::Accepted) {
|
2013-01-21 19:11:43 -05:00
|
|
|
mTransformationType = dialog.getData(mXPathsToUse, mXPathsToRemove, mXslt);
|
|
|
|
ui->transformationTypeLabel->setText(FeedReaderStringDefs::transforationTypeString(mTransformationType));
|
2012-09-04 19:53:04 -04:00
|
|
|
}
|
2012-08-13 17:35:11 -04:00
|
|
|
}
|
2014-11-24 17:40:29 -05:00
|
|
|
|
|
|
|
void AddFeedDialog::clearMessageCache()
|
|
|
|
{
|
2020-11-08 07:22:59 -05:00
|
|
|
if (mFeedId == 0) {
|
2014-11-24 17:40:29 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mFeedReader->clearMessageCache(mFeedId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddFeedDialog::requestForumGroups()
|
|
|
|
{
|
|
|
|
mStateHelper->setLoading(TOKEN_TYPE_FORUM_GROUPS, true);
|
|
|
|
|
|
|
|
RsTokReqOptions opts;
|
|
|
|
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
|
|
|
|
|
2023-04-10 18:36:41 -04:00
|
|
|
mForumTokenQueue->cancelActiveRequestTokens(TOKEN_TYPE_FORUM_GROUPS);
|
2014-11-24 17:40:29 -05:00
|
|
|
|
|
|
|
uint32_t token;
|
2023-04-10 18:36:41 -04:00
|
|
|
mForumTokenQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, TOKEN_TYPE_FORUM_GROUPS);
|
2014-11-24 17:40:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void AddFeedDialog::loadForumGroups(const uint32_t &token)
|
|
|
|
{
|
|
|
|
std::vector<RsGxsForumGroup> groups;
|
|
|
|
rsGxsForums->getGroupData(token, groups);
|
|
|
|
|
|
|
|
ui->forumComboBox->clear();
|
|
|
|
|
|
|
|
for (std::vector<RsGxsForumGroup>::iterator it = groups.begin(); it != groups.end(); ++it) {
|
|
|
|
const RsGxsForumGroup &group = *it;
|
|
|
|
|
|
|
|
/* show only own forums */
|
2015-06-09 14:03:09 -04:00
|
|
|
if (IS_GROUP_PUBLISHER(group.mMeta.mSubscribeFlags) && IS_GROUP_ADMIN(group.mMeta.mSubscribeFlags) && !group.mMeta.mAuthorId.isNull()) {
|
2014-11-24 17:40:29 -05:00
|
|
|
ui->forumComboBox->addItem(QString::fromUtf8(group.mMeta.mGroupName.c_str()), QString::fromStdString(group.mMeta.mGroupId.toStdString()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* insert empty item */
|
|
|
|
ui->forumComboBox->insertItem(0, "", "");
|
|
|
|
ui->forumComboBox->setCurrentIndex(0);
|
|
|
|
|
|
|
|
mStateHelper->setLoading(TOKEN_TYPE_FORUM_GROUPS, false);
|
|
|
|
|
|
|
|
if (!mFillForumId.empty()) {
|
|
|
|
setActiveForumId(mFillForumId);
|
|
|
|
mFillForumId.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-10 18:36:41 -04:00
|
|
|
void AddFeedDialog::requestPostedGroups()
|
|
|
|
{
|
|
|
|
mStateHelper->setLoading(TOKEN_TYPE_POSTED_GROUPS, true);
|
|
|
|
|
|
|
|
RsTokReqOptions opts;
|
|
|
|
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
|
|
|
|
|
|
|
|
mPostedTokenQueue->cancelActiveRequestTokens(TOKEN_TYPE_POSTED_GROUPS);
|
|
|
|
|
|
|
|
uint32_t token;
|
|
|
|
mPostedTokenQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, TOKEN_TYPE_POSTED_GROUPS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddFeedDialog::loadPostedGroups(const uint32_t &token)
|
|
|
|
{
|
|
|
|
std::vector<RsPostedGroup> groups;
|
|
|
|
rsPosted->getGroupData(token, groups);
|
|
|
|
|
|
|
|
ui->postedComboBox->clear();
|
|
|
|
|
|
|
|
for (std::vector<RsPostedGroup>::iterator it = groups.begin(); it != groups.end(); ++it) {
|
|
|
|
const RsPostedGroup &group = *it;
|
|
|
|
|
|
|
|
/* show only own posted */
|
|
|
|
if (IS_GROUP_PUBLISHER(group.mMeta.mSubscribeFlags) && IS_GROUP_ADMIN(group.mMeta.mSubscribeFlags) && !group.mMeta.mAuthorId.isNull()) {
|
|
|
|
ui->postedComboBox->addItem(QString::fromUtf8(group.mMeta.mGroupName.c_str()), QString::fromStdString(group.mMeta.mGroupId.toStdString()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* insert empty item */
|
|
|
|
ui->postedComboBox->insertItem(0, "", "");
|
|
|
|
ui->postedComboBox->setCurrentIndex(0);
|
|
|
|
|
|
|
|
mStateHelper->setLoading(TOKEN_TYPE_POSTED_GROUPS, false);
|
|
|
|
|
|
|
|
if (!mFillPostedId.empty()) {
|
|
|
|
setActivePostedId(mFillPostedId);
|
|
|
|
mFillPostedId.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-24 17:40:29 -05:00
|
|
|
void AddFeedDialog::loadRequest(const TokenQueue *queue, const TokenRequest &req)
|
|
|
|
{
|
2023-04-10 18:36:41 -04:00
|
|
|
if (queue == mForumTokenQueue)
|
2014-11-24 17:40:29 -05:00
|
|
|
{
|
|
|
|
/* now switch on req */
|
|
|
|
switch(req.mUserType)
|
|
|
|
{
|
|
|
|
case TOKEN_TYPE_FORUM_GROUPS:
|
|
|
|
loadForumGroups(req.mToken);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
std::cerr << "AddFeedDialog::loadRequest() ERROR: INVALID TYPE";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2023-04-10 18:36:41 -04:00
|
|
|
|
|
|
|
if (queue == mPostedTokenQueue)
|
|
|
|
{
|
|
|
|
/* now switch on req */
|
|
|
|
switch(req.mUserType)
|
|
|
|
{
|
|
|
|
case TOKEN_TYPE_POSTED_GROUPS:
|
|
|
|
loadPostedGroups(req.mToken);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
std::cerr << "AddFeedDialog::loadRequest() ERROR: INVALID TYPE";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2014-11-24 17:40:29 -05:00
|
|
|
}
|