Work on #287 - right now heavily broken.

This commit is contained in:
Martin Rotter 2020-11-26 14:33:58 +01:00
parent ab04a9ada3
commit 96711c6f41
26 changed files with 706 additions and 866 deletions

View File

@ -154,7 +154,6 @@ HEADERS += core/feeddownloader.h \
services/inoreader/network/inoreadernetworkfactory.h \
services/owncloud/definitions.h \
services/owncloud/gui/formeditowncloudaccount.h \
services/owncloud/gui/formowncloudfeeddetails.h \
services/owncloud/network/owncloudnetworkfactory.h \
services/owncloud/owncloudfeed.h \
services/owncloud/owncloudserviceentrypoint.h \
@ -164,6 +163,7 @@ HEADERS += core/feeddownloader.h \
services/standard/gui/formstandardcategorydetails.h \
services/standard/gui/formstandardfeeddetails.h \
services/standard/gui/formstandardimportexport.h \
services/standard/gui/standardfeeddetails.h \
services/standard/jsonparser.h \
services/standard/rdfparser.h \
services/standard/rssparser.h \
@ -174,7 +174,6 @@ HEADERS += core/feeddownloader.h \
services/standard/standardserviceroot.h \
services/tt-rss/definitions.h \
services/tt-rss/gui/formeditttrssaccount.h \
services/tt-rss/gui/formttrssfeeddetails.h \
services/tt-rss/network/ttrssnetworkfactory.h \
services/tt-rss/ttrssfeed.h \
services/tt-rss/ttrssserviceentrypoint.h \
@ -302,7 +301,6 @@ SOURCES += core/feeddownloader.cpp \
services/inoreader/inoreaderserviceroot.cpp \
services/inoreader/network/inoreadernetworkfactory.cpp \
services/owncloud/gui/formeditowncloudaccount.cpp \
services/owncloud/gui/formowncloudfeeddetails.cpp \
services/owncloud/network/owncloudnetworkfactory.cpp \
services/owncloud/owncloudfeed.cpp \
services/owncloud/owncloudserviceentrypoint.cpp \
@ -312,6 +310,7 @@ SOURCES += core/feeddownloader.cpp \
services/standard/gui/formstandardcategorydetails.cpp \
services/standard/gui/formstandardfeeddetails.cpp \
services/standard/gui/formstandardimportexport.cpp \
services/standard/gui/standardfeeddetails.cpp \
services/standard/jsonparser.cpp \
services/standard/rdfparser.cpp \
services/standard/rssparser.cpp \
@ -321,7 +320,6 @@ SOURCES += core/feeddownloader.cpp \
services/standard/standardserviceentrypoint.cpp \
services/standard/standardserviceroot.cpp \
services/tt-rss/gui/formeditttrssaccount.cpp \
services/tt-rss/gui/formttrssfeeddetails.cpp \
services/tt-rss/network/ttrssnetworkfactory.cpp \
services/tt-rss/ttrssfeed.cpp \
services/tt-rss/ttrssserviceentrypoint.cpp \
@ -365,6 +363,7 @@ FORMS += gui/dialogs/formabout.ui \
services/owncloud/gui/formeditowncloudaccount.ui \
services/standard/gui/formstandardcategorydetails.ui \
services/standard/gui/formstandardimportexport.ui \
services/standard/gui/standardfeeddetails.ui \
services/tt-rss/gui/formeditttrssaccount.ui \
services/gmail/gui/formdownloadattachment.ui \
services/gmail/gui/formaddeditemail.ui \

View File

@ -95,8 +95,8 @@ class DatabaseQueries {
static bool cleanImportantMessages(const QSqlDatabase& db, bool clean_read_only, int account_id);
static bool cleanFeeds(const QSqlDatabase& db, const QStringList& ids, bool clean_read_only, int account_id);
static bool storeAccountTree(const QSqlDatabase& db, RootItem* tree_root, int account_id);
static bool editBaseFeed(const QSqlDatabase& db, int feed_id, Feed::AutoUpdateType auto_update_type,
int auto_update_interval);
static bool editBaseFeed(const QSqlDatabase& db, int feed_id,
Feed::AutoUpdateType auto_update_type, int auto_update_interval);
template<typename T>
static Assignment getCategories(const QSqlDatabase& db, int account_id, bool* ok = nullptr);

View File

@ -10,6 +10,7 @@
#include "miscellaneous/mutex.h"
#include "miscellaneous/textfactory.h"
#include "services/abstract/cacheforserviceroot.h"
#include "services/abstract/gui/formfeeddetails.h"
#include "services/abstract/importantnode.h"
#include "services/abstract/labelsnode.h"
#include "services/abstract/recyclebin.h"
@ -21,6 +22,11 @@ Feed::Feed(RootItem* parent)
: RootItem(parent), m_url(QString()), m_status(Status::Normal), m_autoUpdateType(AutoUpdateType::DefaultAutoUpdate),
m_autoUpdateInitialInterval(DEFAULT_AUTO_UPDATE_INTERVAL), m_autoUpdateRemainingInterval(DEFAULT_AUTO_UPDATE_INTERVAL),
m_messageFilters(QList<QPointer<MessageFilter>>()) {
m_passwordProtected = false;
m_username = QString();
m_password = QString();
setKind(RootItem::Kind::Feed);
}
@ -56,6 +62,10 @@ Feed::Feed(const Feed& other) : RootItem(other) {
setAutoUpdateInitialInterval(other.autoUpdateInitialInterval());
setAutoUpdateRemainingInterval(other.autoUpdateRemainingInterval());
setMessageFilters(other.messageFilters());
setPasswordProtected(other.passwordProtected());
setUsername(other.username());
setPassword(other.password());
}
Feed::~Feed() = default;
@ -66,6 +76,30 @@ QList<Message> Feed::undeletedMessages() const {
return DatabaseQueries::getUndeletedMessagesForFeed(database, customId(), getParentServiceRoot()->accountId());
}
bool Feed::passwordProtected() const {
return m_passwordProtected;
}
void Feed::setPasswordProtected(bool passwordProtected) {
m_passwordProtected = passwordProtected;
}
QString Feed::username() const {
return m_username;
}
void Feed::setUsername(const QString& username) {
m_username = username;
}
QString Feed::password() const {
return m_password;
}
void Feed::setPassword(const QString& password) {
m_password = password;
}
QVariant Feed::data(int column, int role) const {
switch (role) {
case Qt::ForegroundRole:
@ -112,6 +146,32 @@ void Feed::setCountOfUnreadMessages(int count_unread_messages) {
m_unreadCount = count_unread_messages;
}
bool Feed::canBeEdited() const {
return true;
}
bool Feed::editViaGui() {
QScopedPointer<FormFeedDetails> form_pointer(new FormFeedDetails(getParentServiceRoot(), qApp->mainFormWidget()));
form_pointer->editBaseFeed(this);
return false;
}
bool Feed::editItself(Feed* new_feed_data) {
QSqlDatabase database = qApp->database()->connection(metaObject()->className());
// TODO: aby editbasefeed editoval i http/basic autentizační data.
if (DatabaseQueries::editBaseFeed(database, id(), new_feed_data->autoUpdateType(),
new_feed_data->autoUpdateInitialInterval())) {
setAutoUpdateType(new_feed_data->autoUpdateType());
setAutoUpdateInitialInterval(new_feed_data->autoUpdateInitialInterval());
return true;
}
else {
return false;
}
}
void Feed::setAutoUpdateInitialInterval(int auto_update_interval) {
// If new initial auto-update interval is set, then
// we should reset time that remains to the next auto-update.
@ -173,6 +233,10 @@ bool Feed::cleanMessages(bool clean_read_only) {
return getParentServiceRoot()->cleanFeeds(QList<Feed*>() << this, clean_read_only);
}
QList<Message> Feed::obtainNewMessages(bool* error_during_obtaining) {
return {};
}
bool Feed::markAsReadUnread(RootItem::ReadStatus status) {
ServiceRoot* service = getParentServiceRoot();
auto* cache = dynamic_cast<CacheForServiceRoot*>(service);

View File

@ -46,13 +46,18 @@ class Feed : public RootItem {
virtual QString additionalTooltip() const;
virtual bool markAsReadUnread(ReadStatus status);
virtual bool cleanMessages(bool clean_read_only);
virtual QList<Message> obtainNewMessages(bool* error_during_obtaining) = 0;
virtual QList<Message> obtainNewMessages(bool* error_during_obtaining);
virtual int countOfAllMessages() const;
virtual int countOfUnreadMessages() const;
void setCountOfAllMessages(int count_all_messages);
void setCountOfUnreadMessages(int count_unread_messages);
bool canBeEdited() const;
bool editViaGui();
bool editItself(Feed* new_feed_data);
QVariant data(int column, int role) const;
int autoUpdateInitialInterval() const;
@ -70,6 +75,15 @@ class Feed : public RootItem {
QString url() const;
void setUrl(const QString& url);
bool passwordProtected() const;
void setPasswordProtected(bool passwordProtected);
QString username() const;
void setUsername(const QString& username);
QString password() const;
void setPassword(const QString& password);
void appendMessageFilter(MessageFilter* filter);
QList<QPointer<MessageFilter>> messageFilters() const;
void setMessageFilters(const QList<QPointer<MessageFilter>>& messageFilters);
@ -93,6 +107,9 @@ class Feed : public RootItem {
int m_totalCount{};
int m_unreadCount{};
QList<QPointer<MessageFilter>> m_messageFilters;
bool m_passwordProtected{};
QString m_username;
QString m_password;
};
Q_DECLARE_METATYPE(Feed::AutoUpdateType)

View File

@ -15,10 +15,7 @@
#include "services/standard/standardfeed.h"
#include "services/standard/standardserviceroot.h"
#include <QClipboard>
#include <QFileDialog>
#include <QMenu>
#include <QMimeData>
#include <QNetworkReply>
#include <QPair>
#include <QPushButton>
@ -32,91 +29,47 @@ FormFeedDetails::FormFeedDetails(ServiceRoot* service_root, QWidget* parent)
createConnections();
// Initialize that shit.
onTitleChanged(QString());
onDescriptionChanged(QString());
onUrlChanged(QString());
onUsernameChanged(QString());
onPasswordChanged(QString());
}
int FormFeedDetails::addEditFeed(Feed* input_feed, RootItem* parent_to_select, const QString& url) {
// Load categories.
loadCategories(m_serviceRoot->getSubTreeCategories(), m_serviceRoot);
if (input_feed == nullptr) {
// User is adding new feed.
setWindowTitle(tr("Add new feed"));
// Make sure that "default" icon is used as the default option for new
// feed.
m_actionUseDefaultIcon->trigger();
int default_encoding_index = m_ui->m_cmbEncoding->findText(DEFAULT_FEED_ENCODING);
if (default_encoding_index >= 0) {
m_ui->m_cmbEncoding->setCurrentIndex(default_encoding_index);
}
if (parent_to_select != nullptr) {
if (parent_to_select->kind() == RootItem::Kind::Category) {
m_ui->m_cmbParentCategory->setCurrentIndex(m_ui->m_cmbParentCategory->findData(QVariant::fromValue((void*) parent_to_select)));
}
else if (parent_to_select->kind() == RootItem::Kind::Feed) {
int target_item = m_ui->m_cmbParentCategory->findData(QVariant::fromValue((void*) parent_to_select->parent()));
if (target_item >= 0) {
m_ui->m_cmbParentCategory->setCurrentIndex(target_item);
}
}
}
if (!url.isEmpty()) {
m_ui->m_txtUrl->lineEdit()->setText(url);
}
else if (Application::clipboard()->mimeData()->hasText()) {
m_ui->m_txtUrl->lineEdit()->setText(Application::clipboard()->text());
}
}
else {
// User is editing existing category.
setWindowTitle(tr("Edit feed '%1'").arg(input_feed->title()));
setEditableFeed(input_feed);
}
int FormFeedDetails::editBaseFeed(Feed* input_feed) {
setEditableFeed(input_feed);
// Run the dialog.
return QDialog::exec();
}
void FormFeedDetails::onTitleChanged(const QString& new_title) {
if (new_title.simplified().size() >= MIN_CATEGORY_NAME_LENGTH) {
m_ui->m_txtTitle->setStatus(LineEditWithStatus::StatusType::Ok, tr("Feed name is ok."));
}
else {
m_ui->m_txtTitle->setStatus(LineEditWithStatus::StatusType::Error, tr("Feed name is too short."));
}
void FormFeedDetails::insertCustomTab(QWidget* custom_tab, const QString& title, int index) {
m_ui->m_tabWidget->insertTab(index, custom_tab, title);
}
void FormFeedDetails::onDescriptionChanged(const QString& new_description) {
if (new_description.simplified().isEmpty()) {
m_ui->m_txtDescription->setStatus(LineEditWithStatus::StatusType::Warning, tr("Description is empty."));
}
else {
m_ui->m_txtDescription->setStatus(LineEditWithStatus::StatusType::Ok, tr("The description is ok."));
}
}
void FormFeedDetails::apply() {
Feed new_feed;
void FormFeedDetails::onUrlChanged(const QString& new_url) {
if (QRegularExpression(URL_REGEXP).match(new_url).hasMatch()) {
// New url is well-formed.
m_ui->m_txtUrl->setStatus(LineEditWithStatus::StatusType::Ok, tr("The URL is ok."));
}
else if (!new_url.simplified().isEmpty()) {
// New url is not well-formed but is not empty on the other hand.
m_ui->m_txtUrl->setStatus(LineEditWithStatus::StatusType::Warning,
tr(R"(The URL does not meet standard pattern. Does your URL start with "http://" or "https://" prefix.)"));
}
else {
// New url is empty.
m_ui->m_txtUrl->setStatus(LineEditWithStatus::StatusType::Error, tr("The URL is empty."));
// Setup data for new_feed.
new_feed.setPasswordProtected(m_ui->m_gbAuthentication->isChecked());
new_feed.setUsername(m_ui->m_txtUsername->lineEdit()->text());
new_feed.setPassword(m_ui->m_txtPassword->lineEdit()->text());
new_feed.setAutoUpdateType(static_cast<Feed::AutoUpdateType>(m_ui->m_cmbAutoUpdateType->itemData(
m_ui->m_cmbAutoUpdateType->currentIndex()).toInt()));
new_feed.setAutoUpdateInitialInterval(int(m_ui->m_spinAutoUpdateInterval->value()));
if (m_editableFeed != nullptr) {
// NOTE: Co s tim?
//new_feed->setParent(m_editableFeed->parent());
// Edit the feed.
bool edited = m_editableFeed->editItself(&new_feed);
if (edited) {
accept();
}
else {
qApp->showGuiMessage(tr("Cannot edit feed"),
tr("Feed was not edited due to error."),
QSystemTrayIcon::MessageIcon::Critical, this, true);
}
}
}
@ -161,131 +114,25 @@ void FormFeedDetails::onAutoUpdateTypeChanged(int new_index) {
}
}
void FormFeedDetails::onLoadIconFromFile() {
QFileDialog dialog(this, tr("Select icon file for the feed"),
qApp->homeFolder(), tr("Images (*.bmp *.jpg *.jpeg *.png *.svg *.tga)"));
dialog.setFileMode(QFileDialog::ExistingFile);
dialog.setWindowIcon(qApp->icons()->fromTheme(QSL("image-x-generic")));
dialog.setOptions(QFileDialog::DontUseNativeDialog | QFileDialog::ReadOnly);
dialog.setViewMode(QFileDialog::Detail);
dialog.setLabelText(QFileDialog::Accept, tr("Select icon"));
dialog.setLabelText(QFileDialog::Reject, tr("Cancel"));
//: Label for field with icon file name textbox for selection dialog.
dialog.setLabelText(QFileDialog::LookIn, tr("Look in:"));
dialog.setLabelText(QFileDialog::FileName, tr("Icon name:"));
dialog.setLabelText(QFileDialog::FileType, tr("Icon type:"));
if (dialog.exec() == QDialog::Accepted) {
m_ui->m_btnIcon->setIcon(QIcon(dialog.selectedFiles().value(0)));
}
}
void FormFeedDetails::onUseDefaultIcon() {
m_ui->m_btnIcon->setIcon(QIcon());
}
void FormFeedDetails::guessFeed() {
QPair<StandardFeed*, QNetworkReply::NetworkError> result = StandardFeed::guessFeed(m_ui->m_txtUrl->lineEdit()->text(),
m_ui->m_txtUsername->lineEdit()->text(),
m_ui->m_txtPassword->lineEdit()->text());
if (result.first != nullptr) {
// Icon or whole feed was guessed.
m_ui->m_btnIcon->setIcon(result.first->icon());
m_ui->m_txtTitle->lineEdit()->setText(result.first->title());
m_ui->m_txtDescription->lineEdit()->setText(result.first->description());
m_ui->m_cmbType->setCurrentIndex(m_ui->m_cmbType->findData(QVariant::fromValue((int) result.first->type())));
int encoding_index = m_ui->m_cmbEncoding->findText(result.first->encoding(), Qt::MatchFixedString);
if (encoding_index >= 0) {
m_ui->m_cmbEncoding->setCurrentIndex(encoding_index);
}
else {
m_ui->m_cmbEncoding->setCurrentIndex(m_ui->m_cmbEncoding->findText(DEFAULT_FEED_ENCODING,
Qt::MatchFixedString));
}
if (result.second == QNetworkReply::NoError) {
m_ui->m_lblFetchMetadata->setStatus(WidgetWithStatus::StatusType::Ok,
tr("All metadata fetched successfully."),
tr("Feed and icon metadata fetched."));
}
else {
m_ui->m_lblFetchMetadata->setStatus(WidgetWithStatus::StatusType::Warning,
tr("Result: %1.").arg(NetworkFactory::networkErrorText(result.second)),
tr("Feed or icon metadata not fetched."));
}
// Remove temporary feed object.
delete result.first;
}
else {
// No feed guessed, even no icon available.
m_ui->m_lblFetchMetadata->setStatus(WidgetWithStatus::StatusType::Error,
tr("Error: %1.").arg(NetworkFactory::networkErrorText(result.second)),
tr("No metadata fetched."));
}
}
void FormFeedDetails::guessIconOnly() {
QPair<StandardFeed*, QNetworkReply::NetworkError> result = StandardFeed::guessFeed(m_ui->m_txtUrl->lineEdit()->text(),
m_ui->m_txtUsername->lineEdit()->text(),
m_ui->m_txtPassword->lineEdit()->text());
if (result.first != nullptr) {
// Icon or whole feed was guessed.
m_ui->m_btnIcon->setIcon(result.first->icon());
if (result.second == QNetworkReply::NoError) {
m_ui->m_lblFetchMetadata->setStatus(WidgetWithStatus::StatusType::Ok,
tr("Icon fetched successfully."),
tr("Icon metadata fetched."));
}
else {
m_ui->m_lblFetchMetadata->setStatus(WidgetWithStatus::StatusType::Warning,
tr("Result: %1.").arg(NetworkFactory::networkErrorText(result.second)),
tr("Icon metadata not fetched."));
}
// Remove temporary feed object.
delete result.first;
}
else {
// No feed guessed, even no icon available.
m_ui->m_lblFetchMetadata->setStatus(WidgetWithStatus::StatusType::Error,
tr("Error: %1.").arg(NetworkFactory::networkErrorText(result.second)),
tr("No icon fetched."));
}
}
void FormFeedDetails::createConnections() {
// General connections.
connect(m_ui->m_buttonBox, &QDialogButtonBox::accepted, this, &FormFeedDetails::apply);
connect(m_ui->m_txtTitle->lineEdit(), &BaseLineEdit::textChanged, this, &FormFeedDetails::onTitleChanged);
connect(m_ui->m_txtDescription->lineEdit(), &BaseLineEdit::textChanged, this, &FormFeedDetails::onDescriptionChanged);
connect(m_ui->m_txtUrl->lineEdit(), &BaseLineEdit::textChanged, this, &FormFeedDetails::onUrlChanged);
connect(m_ui->m_txtUsername->lineEdit(), &BaseLineEdit::textChanged, this, &FormFeedDetails::onUsernameChanged);
connect(m_ui->m_txtPassword->lineEdit(), &BaseLineEdit::textChanged, this, &FormFeedDetails::onPasswordChanged);
connect(m_ui->m_gbAuthentication, &QGroupBox::toggled, this, &FormFeedDetails::onAuthenticationSwitched);
connect(m_ui->m_cmbAutoUpdateType, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
&FormFeedDetails::onAutoUpdateTypeChanged);
connect(m_ui->m_btnFetchMetadata, &QPushButton::clicked, this, &FormFeedDetails::guessFeed);
// Icon connections.
connect(m_actionFetchIcon, &QAction::triggered, this, &FormFeedDetails::guessIconOnly);
connect(m_actionLoadIconFromFile, &QAction::triggered, this, &FormFeedDetails::onLoadIconFromFile);
connect(m_actionUseDefaultIcon, &QAction::triggered, this, &FormFeedDetails::onUseDefaultIcon);
}
void FormFeedDetails::setEditableFeed(Feed* editable_feed) {
setWindowTitle(tr("Edit feed '%1'").arg(editable_feed->title()));
m_editableFeed = editable_feed;
m_ui->m_cmbParentCategory->setCurrentIndex(m_ui->m_cmbParentCategory->findData(QVariant::fromValue((void*) editable_feed->parent())));
m_ui->m_txtTitle->lineEdit()->setText(editable_feed->title());
m_ui->m_txtDescription->lineEdit()->setText(editable_feed->description());
m_ui->m_btnIcon->setIcon(editable_feed->icon());
m_ui->m_txtUrl->lineEdit()->setText(editable_feed->url());
m_ui->m_gbAuthentication->setChecked(editable_feed->passwordProtected());
m_ui->m_txtUsername->lineEdit()->setText(editable_feed->username());
m_ui->m_txtPassword->lineEdit()->setText(editable_feed->password());
m_ui->m_cmbAutoUpdateType->setCurrentIndex(m_ui->m_cmbAutoUpdateType->findData(QVariant::fromValue((int) editable_feed->autoUpdateType())));
m_ui->m_spinAutoUpdateInterval->setValue(editable_feed->autoUpdateInitialInterval());
}
@ -299,60 +146,11 @@ void FormFeedDetails::initialize() {
setWindowIcon(qApp->icons()->fromTheme(QSL("application-rss+xml")));
// Set text boxes.
m_ui->m_txtTitle->lineEdit()->setPlaceholderText(tr("Feed title"));
m_ui->m_txtTitle->lineEdit()->setToolTip(tr("Set title for your feed."));
m_ui->m_txtDescription->lineEdit()->setPlaceholderText(tr("Feed description"));
m_ui->m_txtDescription->lineEdit()->setToolTip(tr("Set description for your feed."));
m_ui->m_txtUrl->lineEdit()->setPlaceholderText(tr("Full feed url including scheme"));
m_ui->m_txtUrl->lineEdit()->setToolTip(tr("Set url for your feed."));
m_ui->m_txtUsername->lineEdit()->setPlaceholderText(tr("Username"));
m_ui->m_txtUsername->lineEdit()->setToolTip(tr("Set username to access the feed."));
m_ui->m_txtPassword->lineEdit()->setPlaceholderText(tr("Password"));
m_ui->m_txtPassword->lineEdit()->setToolTip(tr("Set password to access the feed."));
// Add standard feed types.
m_ui->m_cmbType->addItem(StandardFeed::typeToString(StandardFeed::Type::Atom10), QVariant::fromValue(int(StandardFeed::Type::Atom10)));
m_ui->m_cmbType->addItem(StandardFeed::typeToString(StandardFeed::Type::Rdf), QVariant::fromValue(int(StandardFeed::Type::Rdf)));
m_ui->m_cmbType->addItem(StandardFeed::typeToString(StandardFeed::Type::Rss0X), QVariant::fromValue(int(StandardFeed::Type::Rss0X)));
m_ui->m_cmbType->addItem(StandardFeed::typeToString(StandardFeed::Type::Rss2X), QVariant::fromValue(int(StandardFeed::Type::Rss2X)));
m_ui->m_cmbType->addItem(StandardFeed::typeToString(StandardFeed::Type::Json), QVariant::fromValue(int(StandardFeed::Type::Json)));
// Load available encodings.
const QList<QByteArray> encodings = QTextCodec::availableCodecs();
QStringList encoded_encodings;
for (const QByteArray& encoding : encodings) {
encoded_encodings.append(encoding);
}
// Sort encodings and add them.
std::sort(encoded_encodings.begin(), encoded_encodings.end(), [](const QString& lhs, const QString& rhs) {
return lhs.toLower() < rhs.toLower();
});
m_ui->m_cmbEncoding->addItems(encoded_encodings);
// Setup menu & actions for icon selection.
m_iconMenu = new QMenu(tr("Icon selection"), this);
m_actionLoadIconFromFile = new QAction(qApp->icons()->fromTheme(QSL("image-x-generic")),
tr("Load icon from file..."),
this);
m_actionUseDefaultIcon = new QAction(qApp->icons()->fromTheme(QSL("application-rss+xml")),
tr("Use default icon from icon theme"),
this);
m_actionFetchIcon = new QAction(qApp->icons()->fromTheme(QSL("emblem-downloads")),
tr("Fetch icon from feed"),
this);
m_iconMenu->addAction(m_actionFetchIcon);
m_iconMenu->addAction(m_actionLoadIconFromFile);
m_iconMenu->addAction(m_actionUseDefaultIcon);
m_ui->m_btnIcon->setMenu(m_iconMenu);
// Set feed metadata fetch label.
m_ui->m_lblFetchMetadata->setStatus(WidgetWithStatus::StatusType::Information,
tr("No metadata fetched so far."),
tr("No metadata fetched so far."));
// Setup auto-update options.
m_ui->m_spinAutoUpdateInterval->setValue(DEFAULT_AUTO_UPDATE_INTERVAL);
m_ui->m_cmbAutoUpdateType->addItem(tr("Auto-update using global interval"),
@ -361,31 +159,4 @@ void FormFeedDetails::initialize() {
QVariant::fromValue(int(Feed::AutoUpdateType::SpecificAutoUpdate)));
m_ui->m_cmbAutoUpdateType->addItem(tr("Do not auto-update at all"),
QVariant::fromValue(int(Feed::AutoUpdateType::DontAutoUpdate)));
// Set tab order.
setTabOrder(m_ui->m_cmbParentCategory, m_ui->m_cmbType);
setTabOrder(m_ui->m_cmbType, m_ui->m_cmbEncoding);
setTabOrder(m_ui->m_cmbEncoding, m_ui->m_cmbAutoUpdateType);
setTabOrder(m_ui->m_cmbAutoUpdateType, m_ui->m_spinAutoUpdateInterval);
setTabOrder(m_ui->m_spinAutoUpdateInterval, m_ui->m_txtTitle->lineEdit());
setTabOrder(m_ui->m_txtTitle->lineEdit(), m_ui->m_txtDescription->lineEdit());
setTabOrder(m_ui->m_txtDescription->lineEdit(), m_ui->m_txtUrl->lineEdit());
setTabOrder(m_ui->m_txtUrl->lineEdit(), m_ui->m_btnFetchMetadata);
setTabOrder(m_ui->m_btnFetchMetadata, m_ui->m_btnIcon);
setTabOrder(m_ui->m_btnIcon, m_ui->m_gbAuthentication);
setTabOrder(m_ui->m_gbAuthentication, m_ui->m_txtUsername->lineEdit());
setTabOrder(m_ui->m_txtUsername->lineEdit(), m_ui->m_txtPassword->lineEdit());
m_ui->m_txtUrl->lineEdit()->setFocus(Qt::TabFocusReason);
}
void FormFeedDetails::loadCategories(const QList<Category*>& categories, RootItem* root_item) {
m_ui->m_cmbParentCategory->addItem(root_item->fullIcon(),
root_item->title(),
QVariant::fromValue((void*) root_item));
for (Category* category : categories) {
m_ui->m_cmbParentCategory->addItem(category->fullIcon(),
category->title(),
QVariant::fromValue((void*) category));
}
}

View File

@ -24,33 +24,21 @@ class FormFeedDetails : public QDialog {
virtual ~FormFeedDetails() = default;
public slots:
// Executes add/edit standard feed dialog.
int addEditFeed(Feed* input_feed, RootItem* parent_to_select, const QString& url = QString());
int editBaseFeed(Feed* input_feed);
protected slots:
void insertCustomTab(QWidget* custom_tab, const QString& title, int index);
// Applies changes.
// NOTE: This must be reimplemented in subclasses. Also this
// base implementation must be called first.
virtual void apply() = 0;
virtual void apply();
void guessFeed();
void guessIconOnly();
// Trigerred when title/description/url/username/password changes.
void onTitleChanged(const QString& new_title);
void onDescriptionChanged(const QString& new_description);
void onUrlChanged(const QString& new_url);
void onUsernameChanged(const QString& new_username);
void onPasswordChanged(const QString& new_password);
void onAuthenticationSwitched();
void onAutoUpdateTypeChanged(int new_index);
// Icon selectors.
void onLoadIconFromFile();
void onUseDefaultIcon();
protected:
// Sets the feed which will be edited.
@ -64,17 +52,10 @@ class FormFeedDetails : public QDialog {
// Initializes the dialog.
void initialize();
// Loads categories into the dialog from the model.
void loadCategories(const QList<Category*>& categories, RootItem* root_item);
protected:
QScopedPointer<Ui::FormFeedDetails> m_ui;
Feed* m_editableFeed;
ServiceRoot* m_serviceRoot;
QMenu* m_iconMenu{};
QAction* m_actionLoadIconFromFile{};
QAction* m_actionUseDefaultIcon{};
QAction* m_actionFetchIcon{};
};
#endif // FORMFEEDDETAILS_H

View File

@ -15,197 +15,10 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTabWidget" name="tabWidget">
<widget class="QTabWidget" name="m_tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tabGeneral">
<attribute name="title">
<string>General</string>
</attribute>
<layout class="QFormLayout" name="formLayout_4">
<item row="0" column="0">
<widget class="QLabel" name="m_lblParentCategory">
<property name="text">
<string>Parent category</string>
</property>
<property name="buddy">
<cstring>m_cmbParentCategory</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="m_cmbParentCategory">
<property name="toolTip">
<string>Select parent item for your feed.</string>
</property>
<property name="iconSize">
<size>
<width>12</width>
<height>12</height>
</size>
</property>
<property name="frame">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Type</string>
</property>
<property name="buddy">
<cstring>m_cmbType</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="m_cmbType">
<property name="toolTip">
<string>Select type of the standard feed.</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Encoding</string>
</property>
<property name="buddy">
<cstring>m_cmbEncoding</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="m_cmbEncoding">
<property name="toolTip">
<string>Select encoding of the standard feed. If you are unsure about the encoding, then select &quot;UTF-8&quot; encoding.</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="m_lblTitle">
<property name="text">
<string>Title</string>
</property>
<property name="buddy">
<cstring>m_txtTitle</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="LineEditWithStatus" name="m_txtTitle" native="true"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="m_lblDescription">
<property name="text">
<string>Description</string>
</property>
<property name="buddy">
<cstring>m_txtDescription</cstring>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="LineEditWithStatus" name="m_txtDescription" native="true"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>URL</string>
</property>
<property name="buddy">
<cstring>m_txtUrl</cstring>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="LineEditWithStatus" name="m_txtUrl" native="true"/>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Fetch metadata</string>
</property>
<property name="buddy">
<cstring>m_btnFetchMetadata</cstring>
</property>
</widget>
</item>
<item row="6" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="m_btnFetchMetadata">
<property name="text">
<string>Fetch it now</string>
</property>
</widget>
</item>
<item>
<widget class="LabelWithStatus" name="m_lblFetchMetadata" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
</widget>
</item>
</layout>
</item>
<item row="7" column="0">
<widget class="QLabel" name="m_lblIcon">
<property name="text">
<string>Icon</string>
</property>
<property name="buddy">
<cstring>m_btnIcon</cstring>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QToolButton" name="m_btnIcon">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>40</width>
<height>40</height>
</size>
</property>
<property name="toolTip">
<string>Select icon for your feed.</string>
</property>
<property name="text">
<string notr="true"/>
</property>
<property name="iconSize">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
</property>
<property name="autoRaise">
<bool>false</bool>
</property>
<property name="arrowType">
<enum>Qt::NoArrow</enum>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabUpdating">
<attribute name="title">
<string>Auto-updating</string>
@ -313,12 +126,6 @@
</layout>
</widget>
<customwidgets>
<customwidget>
<class>LabelWithStatus</class>
<extends>QWidget</extends>
<header>labelwithstatus.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>LineEditWithStatus</class>
<extends>QWidget</extends>
@ -340,8 +147,8 @@
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
<x>325</x>
<y>342</y>
</hint>
<hint type="destinationlabel">
<x>286</x>

View File

@ -1,86 +0,0 @@
// For license of this file, see <project-root-folder>/LICENSE.md.
#include "services/owncloud/gui/formowncloudfeeddetails.h"
#include "miscellaneous/application.h"
#include "services/owncloud/network/owncloudnetworkfactory.h"
#include "services/owncloud/owncloudfeed.h"
#include "services/owncloud/owncloudserviceroot.h"
#include <QTimer>
FormOwnCloudFeedDetails::FormOwnCloudFeedDetails(ServiceRoot* service_root, QWidget* parent)
: FormFeedDetails(service_root, parent) {
m_ui->m_spinAutoUpdateInterval->setEnabled(false);
m_ui->m_cmbAutoUpdateType->setEnabled(false);
m_ui->m_cmbType->setEnabled(false);
m_ui->m_cmbEncoding->setEnabled(false);
m_ui->m_btnFetchMetadata->setEnabled(false);
m_ui->m_btnIcon->setEnabled(false);
m_ui->m_txtTitle->setEnabled(false);
m_ui->m_txtUrl->setEnabled(true);
m_ui->m_txtDescription->setEnabled(false);
}
void FormOwnCloudFeedDetails::apply() {
if (m_editableFeed != nullptr) {
bool renamed = false;
if (m_ui->m_txtTitle->lineEdit()->text() != m_editableFeed->title()) {
if (!qobject_cast<OwnCloudServiceRoot*>(m_serviceRoot)->network()->renameFeed(m_ui->m_txtTitle->lineEdit()->text(),
m_editableFeed->customId())) {
qCriticalNN << LOGSEC_NEXTCLOUD
<< "Nextcloud: Problem with feed renaming ID:"
<< QUOTE_W_SPACE_DOT(m_editableFeed->customId());
}
else {
renamed = true;
}
}
// User edited auto-update status. Save it.
auto* new_feed_data = new OwnCloudFeed();
new_feed_data->setAutoUpdateType(static_cast<Feed::AutoUpdateType>(m_ui->m_cmbAutoUpdateType->itemData(
m_ui->m_cmbAutoUpdateType->currentIndex()).toInt()));
new_feed_data->setAutoUpdateInitialInterval(int(m_ui->m_spinAutoUpdateInterval->value()));
qobject_cast<OwnCloudFeed*>(m_editableFeed)->editItself(new_feed_data);
delete new_feed_data;
if (renamed) {
QTimer::singleShot(200, m_serviceRoot, SLOT(syncIn()));
}
}
else {
const RootItem* parent = static_cast<RootItem*>(m_ui->m_cmbParentCategory->itemData(
m_ui->m_cmbParentCategory->currentIndex()).value<void*>());
const int category_id = parent->kind() == RootItem::Kind::ServiceRoot ? 0 : parent->customNumericId();
const bool response = qobject_cast<OwnCloudServiceRoot*>(m_serviceRoot)->network()->createFeed(m_ui->m_txtUrl->lineEdit()->text(),
category_id);
if (response) {
// Feed was added online.
accept();
qApp->showGuiMessage(tr("Feed added"), tr("Feed was added, triggering sync in now."), QSystemTrayIcon::Information);
QTimer::singleShot(100, m_serviceRoot, SLOT(syncIn()));
}
else {
reject();
qApp->showGuiMessage(tr("Cannot add feed"),
tr("Feed was not added due to error."),
QSystemTrayIcon::Critical, qApp->mainFormWidget(), true);
}
}
accept();
}
void FormOwnCloudFeedDetails::setEditableFeed(Feed* editable_feed) {
m_ui->m_cmbAutoUpdateType->setEnabled(true);
FormFeedDetails::setEditableFeed(editable_feed);
m_ui->m_txtTitle->setEnabled(true);
m_ui->m_gbAuthentication->setEnabled(false);
m_ui->m_txtUrl->setEnabled(false);
m_ui->m_lblParentCategory->setEnabled(false);
m_ui->m_cmbParentCategory->setEnabled(false);
}

View File

@ -1,21 +0,0 @@
// For license of this file, see <project-root-folder>/LICENSE.md.
#ifndef FORMOWNCLOUDFEEDDETAILS_H
#define FORMOWNCLOUDFEEDDETAILS_H
#include "services/abstract/gui/formfeeddetails.h"
class FormOwnCloudFeedDetails : public FormFeedDetails {
Q_OBJECT
public:
explicit FormOwnCloudFeedDetails(ServiceRoot* service_root, QWidget* parent = 0);
protected slots:
void apply();
protected:
void setEditableFeed(Feed* editable_feed);
};
#endif // FORMOWNCLOUDFEEDDETAILS_H

View File

@ -4,7 +4,6 @@
#include "miscellaneous/databasequeries.h"
#include "miscellaneous/iconfactory.h"
#include "services/owncloud/gui/formowncloudfeeddetails.h"
#include "services/owncloud/network/owncloudnetworkfactory.h"
#include "services/owncloud/owncloudserviceroot.h"
@ -16,18 +15,6 @@ OwnCloudFeed::OwnCloudFeed(const QSqlRecord& record) : Feed(record) {}
OwnCloudFeed::~OwnCloudFeed() = default;
bool OwnCloudFeed::canBeEdited() const {
return true;
}
bool OwnCloudFeed::editViaGui() {
QScopedPointer<FormOwnCloudFeedDetails> form_pointer(new FormOwnCloudFeedDetails(serviceRoot(),
qApp->mainFormWidget()));
form_pointer->addEditFeed(this, this);
return false;
}
bool OwnCloudFeed::canBeDeleted() const {
return true;
}
@ -42,21 +29,6 @@ bool OwnCloudFeed::deleteViaGui() {
}
}
bool OwnCloudFeed::editItself(OwnCloudFeed* new_feed_data) {
QSqlDatabase database = qApp->database()->connection(metaObject()->className());
if (!DatabaseQueries::editBaseFeed(database, id(), new_feed_data->autoUpdateType(),
new_feed_data->autoUpdateInitialInterval())) {
// Persistent storage update failed, no way to continue now.
return false;
}
else {
setAutoUpdateType(new_feed_data->autoUpdateType());
setAutoUpdateInitialInterval(new_feed_data->autoUpdateInitialInterval());
return true;
}
}
bool OwnCloudFeed::removeItself() {
QSqlDatabase database = qApp->database()->connection(metaObject()->className());

View File

@ -15,12 +15,9 @@ class OwnCloudFeed : public Feed {
explicit OwnCloudFeed(const QSqlRecord& record);
virtual ~OwnCloudFeed();
bool canBeEdited() const;
bool editViaGui();
bool canBeDeleted() const;
bool deleteViaGui();
bool editItself(OwnCloudFeed* new_feed_data);
bool removeItself();
OwnCloudServiceRoot* serviceRoot() const;

View File

@ -11,7 +11,6 @@
#include "services/abstract/importantnode.h"
#include "services/abstract/recyclebin.h"
#include "services/owncloud/gui/formeditowncloudaccount.h"
#include "services/owncloud/gui/formowncloudfeeddetails.h"
#include "services/owncloud/network/owncloudnetworkfactory.h"
#include "services/owncloud/owncloudfeed.h"
#include "services/owncloud/owncloudserviceentrypoint.h"
@ -56,7 +55,7 @@ bool OwnCloudServiceRoot::deleteViaGui() {
}
bool OwnCloudServiceRoot::supportsFeedAdding() const {
return true;
return false;
}
bool OwnCloudServiceRoot::supportsCategoryAdding() const {
@ -155,27 +154,6 @@ void OwnCloudServiceRoot::saveAccountDataToDatabase() {
}
}
void OwnCloudServiceRoot::addNewFeed(RootItem* selected_item, const QString& url) {
Q_UNUSED(selected_item)
if (!qApp->feedUpdateLock()->tryLock()) {
// Lock was not obtained because
// it is used probably by feed updater or application
// is quitting.
qApp->showGuiMessage(tr("Cannot add item"),
tr("Cannot add feed because another critical operation is ongoing."),
QSystemTrayIcon::Warning, qApp->mainFormWidget(), true);
// Thus, cannot delete and quit the method.
return;
}
QScopedPointer<FormOwnCloudFeedDetails> form_pointer(new FormOwnCloudFeedDetails(this, qApp->mainFormWidget()));
form_pointer->addEditFeed(nullptr, selected_item, url);
qApp->feedUpdateLock()->unlock();
}
RootItem* OwnCloudServiceRoot::obtainNewTreeForSyncIn() const {
OwnCloudGetFeedsCategoriesResponse feed_cats_response = m_network->feedsCategories();

View File

@ -36,9 +36,6 @@ class OwnCloudServiceRoot : public ServiceRoot, public CacheForServiceRoot {
void saveAllCachedData(bool async = true);
public slots:
void addNewFeed(RootItem* selected_item, const QString& url);
protected:
virtual RootItem* obtainNewTreeForSyncIn() const;

View File

@ -3,26 +3,296 @@
#include "services/standard/gui/formstandardfeeddetails.h"
#include "miscellaneous/application.h"
#include "miscellaneous/iconfactory.h"
#include "network-web/networkfactory.h"
#include "services/abstract/category.h"
#include "services/abstract/serviceroot.h"
#include "services/standard/gui/standardfeeddetails.h"
#include "services/standard/standardfeed.h"
#include <QClipboard>
#include <QFileDialog>
#include <QMimeData>
#include <QTextCodec>
FormStandardFeedDetails::FormStandardFeedDetails(ServiceRoot* service_root, QWidget* parent)
: FormFeedDetails(service_root, parent) {}
: FormFeedDetails(service_root, parent), m_standardFeedDetails(new StandardFeedDetails(this)) {
insertCustomTab(m_standardFeedDetails, tr("General"), 0);
m_standardFeedDetails->ui->m_txtTitle->lineEdit()->setPlaceholderText(tr("Feed title"));
m_standardFeedDetails->ui->m_txtTitle->lineEdit()->setToolTip(tr("Set title for your feed."));
m_standardFeedDetails->ui->m_txtDescription->lineEdit()->setPlaceholderText(tr("Feed description"));
m_standardFeedDetails->ui->m_txtDescription->lineEdit()->setToolTip(tr("Set description for your feed."));
m_standardFeedDetails->ui->m_txtUrl->lineEdit()->setPlaceholderText(tr("Full feed url including scheme"));
m_standardFeedDetails->ui->m_txtUrl->lineEdit()->setToolTip(tr("Set url for your feed."));
// Add standard feed types.
m_standardFeedDetails->ui->m_cmbType->addItem(StandardFeed::typeToString(StandardFeed::Type::Atom10), QVariant::fromValue(int(StandardFeed::Type::Atom10)));
m_standardFeedDetails->ui->m_cmbType->addItem(StandardFeed::typeToString(StandardFeed::Type::Rdf), QVariant::fromValue(int(StandardFeed::Type::Rdf)));
m_standardFeedDetails->ui->m_cmbType->addItem(StandardFeed::typeToString(StandardFeed::Type::Rss0X), QVariant::fromValue(int(StandardFeed::Type::Rss0X)));
m_standardFeedDetails->ui->m_cmbType->addItem(StandardFeed::typeToString(StandardFeed::Type::Rss2X), QVariant::fromValue(int(StandardFeed::Type::Rss2X)));
m_standardFeedDetails->ui->m_cmbType->addItem(StandardFeed::typeToString(StandardFeed::Type::Json), QVariant::fromValue(int(StandardFeed::Type::Json)));
// Load available encodings.
const QList<QByteArray> encodings = QTextCodec::availableCodecs();
QStringList encoded_encodings;
for (const QByteArray& encoding : encodings) {
encoded_encodings.append(encoding);
}
// Sort encodings and add them.
std::sort(encoded_encodings.begin(), encoded_encodings.end(), [](const QString& lhs, const QString& rhs) {
return lhs.toLower() < rhs.toLower();
});
m_standardFeedDetails->ui->m_cmbEncoding->addItems(encoded_encodings);
// Setup menu & actions for icon selection.
m_iconMenu = new QMenu(tr("Icon selection"), this);
m_actionLoadIconFromFile = new QAction(qApp->icons()->fromTheme(QSL("image-x-generic")),
tr("Load icon from file..."),
this);
m_actionUseDefaultIcon = new QAction(qApp->icons()->fromTheme(QSL("application-rss+xml")),
tr("Use default icon from icon theme"),
this);
m_actionFetchIcon = new QAction(qApp->icons()->fromTheme(QSL("emblem-downloads")),
tr("Fetch icon from feed"),
this);
m_iconMenu->addAction(m_actionFetchIcon);
m_iconMenu->addAction(m_actionLoadIconFromFile);
m_iconMenu->addAction(m_actionUseDefaultIcon);
m_standardFeedDetails->ui->m_btnIcon->setMenu(m_iconMenu);
m_standardFeedDetails->ui->m_txtUrl->lineEdit()->setFocus(Qt::TabFocusReason);
// Set feed metadata fetch label.
m_standardFeedDetails->ui->m_lblFetchMetadata->setStatus(WidgetWithStatus::StatusType::Information,
tr("No metadata fetched so far."),
tr("No metadata fetched so far."));
connect(m_standardFeedDetails->ui->m_txtTitle->lineEdit(), &BaseLineEdit::textChanged, this, &FormStandardFeedDetails::onTitleChanged);
connect(m_standardFeedDetails->ui->m_txtDescription->lineEdit(), &BaseLineEdit::textChanged, this, &FormStandardFeedDetails::onDescriptionChanged);
connect(m_standardFeedDetails->ui->m_txtUrl->lineEdit(), &BaseLineEdit::textChanged, this, &FormStandardFeedDetails::onUrlChanged);
connect(m_standardFeedDetails->ui->m_btnFetchMetadata, &QPushButton::clicked, this, &FormStandardFeedDetails::guessFeed);
connect(m_actionFetchIcon, &QAction::triggered, this, &FormStandardFeedDetails::guessIconOnly);
connect(m_actionLoadIconFromFile, &QAction::triggered, this, &FormStandardFeedDetails::onLoadIconFromFile);
connect(m_actionUseDefaultIcon, &QAction::triggered, this, &FormStandardFeedDetails::onUseDefaultIcon);
onTitleChanged(QString());
onDescriptionChanged(QString());
onUrlChanged(QString());
}
void FormStandardFeedDetails::loadCategories(const QList<Category*>& categories, RootItem* root_item) {
m_standardFeedDetails->ui->m_cmbParentCategory->addItem(root_item->fullIcon(),
root_item->title(),
QVariant::fromValue((void*) root_item));
for (Category* category : categories) {
m_standardFeedDetails->ui->m_cmbParentCategory->addItem(category->fullIcon(),
category->title(),
QVariant::fromValue((void*) category));
}
}
int FormStandardFeedDetails::addEditFeed(Feed* input_feed, RootItem* parent_to_select, const QString& url) {
// Load categories.
loadCategories(m_serviceRoot->getSubTreeCategories(), m_serviceRoot);
if (input_feed == nullptr) {
// User is adding new feed.
setWindowTitle(tr("Add new feed"));
// Make sure that "default" icon is used as the default option for new
// feed.
m_actionUseDefaultIcon->trigger();
int default_encoding_index = m_standardFeedDetails->ui->m_cmbEncoding->findText(DEFAULT_FEED_ENCODING);
if (default_encoding_index >= 0) {
m_standardFeedDetails->ui->m_cmbEncoding->setCurrentIndex(default_encoding_index);
}
if (parent_to_select != nullptr) {
if (parent_to_select->kind() == RootItem::Kind::Category) {
m_standardFeedDetails->ui->m_cmbParentCategory->setCurrentIndex(m_standardFeedDetails->ui->m_cmbParentCategory->findData(QVariant::fromValue((void*)
parent_to_select)));
}
else if (parent_to_select->kind() == RootItem::Kind::Feed) {
int target_item = m_standardFeedDetails->ui->m_cmbParentCategory->findData(QVariant::fromValue((void*) parent_to_select->parent()));
if (target_item >= 0) {
m_standardFeedDetails->ui->m_cmbParentCategory->setCurrentIndex(target_item);
}
}
}
if (!url.isEmpty()) {
m_standardFeedDetails->ui->m_txtUrl->lineEdit()->setText(url);
}
else if (Application::clipboard()->mimeData()->hasText()) {
m_standardFeedDetails->ui->m_txtUrl->lineEdit()->setText(Application::clipboard()->text());
}
}
else {
// User is editing existing category.
setWindowTitle(tr("Edit feed '%1'").arg(input_feed->title()));
setEditableFeed(input_feed);
}
// Run the dialog.
return QDialog::exec();
}
void FormStandardFeedDetails::onTitleChanged(const QString& new_title) {
if (new_title.simplified().size() >= MIN_CATEGORY_NAME_LENGTH) {
m_standardFeedDetails->ui->m_txtTitle->setStatus(LineEditWithStatus::StatusType::Ok, tr("Feed name is ok."));
}
else {
m_standardFeedDetails->ui->m_txtTitle->setStatus(LineEditWithStatus::StatusType::Error, tr("Feed name is too short."));
}
}
void FormStandardFeedDetails::onDescriptionChanged(const QString& new_description) {
if (new_description.simplified().isEmpty()) {
m_standardFeedDetails->ui->m_txtDescription->setStatus(LineEditWithStatus::StatusType::Warning, tr("Description is empty."));
}
else {
m_standardFeedDetails->ui->m_txtDescription->setStatus(LineEditWithStatus::StatusType::Ok, tr("The description is ok."));
}
}
void FormStandardFeedDetails::onUrlChanged(const QString& new_url) {
if (QRegularExpression(URL_REGEXP).match(new_url).hasMatch()) {
// New url is well-formed.
m_standardFeedDetails->ui->m_txtUrl->setStatus(LineEditWithStatus::StatusType::Ok, tr("The URL is ok."));
}
else if (!new_url.simplified().isEmpty()) {
// New url is not well-formed but is not empty on the other hand.
m_standardFeedDetails->ui->m_txtUrl->setStatus(LineEditWithStatus::StatusType::Warning,
tr(R"(The URL does not meet standard pattern. Does your URL start with "http://" or "https://" prefix.)"));
}
else {
// New url is empty.
m_standardFeedDetails->ui->m_txtUrl->setStatus(LineEditWithStatus::StatusType::Error, tr("The URL is empty."));
}
}
void FormStandardFeedDetails::onLoadIconFromFile() {
QFileDialog dialog(this, tr("Select icon file for the feed"),
qApp->homeFolder(), tr("Images (*.bmp *.jpg *.jpeg *.png *.svg *.tga)"));
dialog.setFileMode(QFileDialog::ExistingFile);
dialog.setWindowIcon(qApp->icons()->fromTheme(QSL("image-x-generic")));
dialog.setOptions(QFileDialog::DontUseNativeDialog | QFileDialog::ReadOnly);
dialog.setViewMode(QFileDialog::Detail);
dialog.setLabelText(QFileDialog::Accept, tr("Select icon"));
dialog.setLabelText(QFileDialog::Reject, tr("Cancel"));
//: Label for field with icon file name textbox for selection dialog.
dialog.setLabelText(QFileDialog::LookIn, tr("Look in:"));
dialog.setLabelText(QFileDialog::FileName, tr("Icon name:"));
dialog.setLabelText(QFileDialog::FileType, tr("Icon type:"));
if (dialog.exec() == QDialog::Accepted) {
m_standardFeedDetails->ui->m_btnIcon->setIcon(QIcon(dialog.selectedFiles().value(0)));
}
}
void FormStandardFeedDetails::onUseDefaultIcon() {
m_standardFeedDetails->ui->m_btnIcon->setIcon(QIcon());
}
void FormStandardFeedDetails::guessFeed() {
QPair<StandardFeed*, QNetworkReply::NetworkError> result = StandardFeed::guessFeed(m_standardFeedDetails->ui->m_txtUrl->lineEdit()->text(),
m_ui->m_txtUsername->lineEdit()->text(),
m_ui->m_txtPassword->lineEdit()->text());
if (result.first != nullptr) {
// Icon or whole feed was guessed.
m_standardFeedDetails->ui->m_btnIcon->setIcon(result.first->icon());
m_standardFeedDetails->ui->m_txtTitle->lineEdit()->setText(result.first->title());
m_standardFeedDetails->ui->m_txtDescription->lineEdit()->setText(result.first->description());
m_standardFeedDetails->ui->m_cmbType->setCurrentIndex(m_standardFeedDetails->ui->m_cmbType->findData(QVariant::fromValue((int) result.first->type())));
int encoding_index = m_standardFeedDetails->ui->m_cmbEncoding->findText(result.first->encoding(), Qt::MatchFixedString);
if (encoding_index >= 0) {
m_standardFeedDetails->ui->m_cmbEncoding->setCurrentIndex(encoding_index);
}
else {
m_standardFeedDetails->ui->m_cmbEncoding->setCurrentIndex(m_standardFeedDetails->ui->m_cmbEncoding->findText(DEFAULT_FEED_ENCODING,
Qt::MatchFixedString));
}
if (result.second == QNetworkReply::NoError) {
m_standardFeedDetails->ui->m_lblFetchMetadata->setStatus(WidgetWithStatus::StatusType::Ok,
tr("All metadata fetched successfully."),
tr("Feed and icon metadata fetched."));
}
else {
m_standardFeedDetails->ui->m_lblFetchMetadata->setStatus(WidgetWithStatus::StatusType::Warning,
tr("Result: %1.").arg(NetworkFactory::networkErrorText(result.second)),
tr("Feed or icon metadata not fetched."));
}
// Remove temporary feed object.
delete result.first;
}
else {
// No feed guessed, even no icon available.
m_standardFeedDetails->ui->m_lblFetchMetadata->setStatus(WidgetWithStatus::StatusType::Error,
tr("Error: %1.").arg(NetworkFactory::networkErrorText(result.second)),
tr("No metadata fetched."));
}
}
void FormStandardFeedDetails::guessIconOnly() {
QPair<StandardFeed*, QNetworkReply::NetworkError> result = StandardFeed::guessFeed(m_standardFeedDetails->ui->m_txtUrl->lineEdit()->text(),
m_ui->m_txtUsername->lineEdit()->text(),
m_ui->m_txtPassword->lineEdit()->text());
if (result.first != nullptr) {
// Icon or whole feed was guessed.
m_standardFeedDetails->ui->m_btnIcon->setIcon(result.first->icon());
if (result.second == QNetworkReply::NoError) {
m_standardFeedDetails->ui->m_lblFetchMetadata->setStatus(WidgetWithStatus::StatusType::Ok,
tr("Icon fetched successfully."),
tr("Icon metadata fetched."));
}
else {
m_standardFeedDetails->ui->m_lblFetchMetadata->setStatus(WidgetWithStatus::StatusType::Warning,
tr("Result: %1.").arg(NetworkFactory::networkErrorText(result.second)),
tr("Icon metadata not fetched."));
}
// Remove temporary feed object.
delete result.first;
}
else {
// No feed guessed, even no icon available.
m_standardFeedDetails->ui->m_lblFetchMetadata->setStatus(WidgetWithStatus::StatusType::Error,
tr("Error: %1.").arg(NetworkFactory::networkErrorText(result.second)),
tr("No icon fetched."));
}
}
void FormStandardFeedDetails::apply() {
RootItem* parent = static_cast<RootItem*>(m_ui->m_cmbParentCategory->itemData(m_ui->m_cmbParentCategory->currentIndex()).value<void*>());
RootItem* parent =
static_cast<RootItem*>(m_standardFeedDetails->ui->m_cmbParentCategory->itemData(
m_standardFeedDetails->ui->m_cmbParentCategory->currentIndex()).value<void*>());
StandardFeed::Type type = static_cast<StandardFeed::Type>(m_ui->m_cmbType->itemData(m_ui->m_cmbType->currentIndex()).value<int>());
StandardFeed::Type type =
static_cast<StandardFeed::Type>(m_standardFeedDetails->ui->m_cmbType->itemData(m_standardFeedDetails->ui->m_cmbType->currentIndex()).value<int>());
auto* new_feed = new StandardFeed();
// Setup data for new_feed.
new_feed->setTitle(m_ui->m_txtTitle->lineEdit()->text());
new_feed->setTitle(m_standardFeedDetails->ui->m_txtTitle->lineEdit()->text());
new_feed->setCreationDate(QDateTime::currentDateTime());
new_feed->setDescription(m_ui->m_txtDescription->lineEdit()->text());
new_feed->setIcon(m_ui->m_btnIcon->icon());
new_feed->setEncoding(m_ui->m_cmbEncoding->currentText());
new_feed->setDescription(m_standardFeedDetails->ui->m_txtDescription->lineEdit()->text());
new_feed->setIcon(m_standardFeedDetails->ui->m_btnIcon->icon());
new_feed->setEncoding(m_standardFeedDetails->ui->m_cmbEncoding->currentText());
new_feed->setType(type);
new_feed->setUrl(m_ui->m_txtUrl->lineEdit()->text());
new_feed->setUrl(m_standardFeedDetails->ui->m_txtUrl->lineEdit()->text());
new_feed->setPasswordProtected(m_ui->m_gbAuthentication->isChecked());
new_feed->setUsername(m_ui->m_txtUsername->lineEdit()->text());
new_feed->setPassword(m_ui->m_txtPassword->lineEdit()->text());
@ -65,11 +335,17 @@ void FormStandardFeedDetails::apply() {
void FormStandardFeedDetails::setEditableFeed(Feed* editable_feed) {
FormFeedDetails::setEditableFeed(editable_feed);
auto* feed = qobject_cast<StandardFeed*>(editable_feed);
m_ui->m_cmbType->setCurrentIndex(m_ui->m_cmbType->findData(QVariant::fromValue(int(feed->type()))));
m_ui->m_cmbEncoding->setCurrentIndex(m_ui->m_cmbEncoding->findData(feed->encoding(), Qt::DisplayRole, Qt::MatchFixedString));
m_ui->m_gbAuthentication->setChecked(feed->passwordProtected());
m_ui->m_txtUsername->lineEdit()->setText(feed->username());
m_ui->m_txtPassword->lineEdit()->setText(feed->password());
m_standardFeedDetails->ui->m_cmbParentCategory->setCurrentIndex(m_standardFeedDetails->ui->m_cmbParentCategory->findData(QVariant::fromValue((void*)
editable_feed->
parent())));
m_standardFeedDetails->ui->m_txtTitle->lineEdit()->setText(editable_feed->title());
m_standardFeedDetails->ui->m_txtDescription->lineEdit()->setText(editable_feed->description());
m_standardFeedDetails->ui->m_btnIcon->setIcon(editable_feed->icon());
m_standardFeedDetails->ui->m_txtUrl->lineEdit()->setText(editable_feed->url());
m_standardFeedDetails->ui->m_cmbType->setCurrentIndex(m_standardFeedDetails->ui->m_cmbType->findData(QVariant::fromValue(int(feed->type()))));
m_standardFeedDetails->ui->m_cmbEncoding->setCurrentIndex(m_standardFeedDetails->ui->m_cmbEncoding->findData(feed->encoding(), Qt::DisplayRole,
Qt::MatchFixedString));
}

View File

@ -5,17 +5,40 @@
#include "services/abstract/gui/formfeeddetails.h"
class StandardFeedDetails;
class FormStandardFeedDetails : public FormFeedDetails {
Q_OBJECT
public:
explicit FormStandardFeedDetails(ServiceRoot* service_root, QWidget* parent = nullptr);
protected slots:
void apply();
public slots:
int addEditFeed(Feed* input_feed, RootItem* parent_to_select, const QString& url = QString());
protected:
void setEditableFeed(Feed* editable_feed);
private slots:
void onTitleChanged(const QString& new_title);
void onDescriptionChanged(const QString& new_description);
void onUrlChanged(const QString& new_url);
void guessFeed();
void guessIconOnly();
void onLoadIconFromFile();
void onUseDefaultIcon();
virtual void apply();
private:
virtual void setEditableFeed(Feed* editable_feed);
// Loads categories into the dialog from the model.
void loadCategories(const QList<Category*>& categories, RootItem* root_item);
private:
StandardFeedDetails* m_standardFeedDetails;
QMenu* m_iconMenu{};
QAction* m_actionLoadIconFromFile{};
QAction* m_actionUseDefaultIcon{};
QAction* m_actionFetchIcon{};
};
#endif // FORMSSFEEDDETAILS_H

View File

@ -0,0 +1,13 @@
#include "standardfeeddetails.h"
StandardFeedDetails::StandardFeedDetails(QWidget* parent) :
QWidget(parent),
ui(new Ui::StandardFeedDetails)
{
ui->setupUi(this);
}
StandardFeedDetails::~StandardFeedDetails()
{
delete ui;
}

View File

@ -0,0 +1,22 @@
#ifndef STANDARDFEEDDETAILS_H
#define STANDARDFEEDDETAILS_H
#include <QWidget>
#include "ui_standardfeeddetails.h"
class StandardFeedDetails : public QWidget
{
Q_OBJECT
friend class FormStandardFeedDetails;
public:
explicit StandardFeedDetails(QWidget* parent = nullptr);
~StandardFeedDetails();
private:
Ui::StandardFeedDetails* ui;
};
#endif // STANDARDFEEDDETAILS_H

View File

@ -0,0 +1,222 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>StandardFeedDetails</class>
<widget class="QWidget" name="StandardFeedDetails">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>429</width>
<height>260</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="m_lblParentCategory">
<property name="text">
<string>Parent category</string>
</property>
<property name="buddy">
<cstring>m_cmbParentCategory</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="m_cmbParentCategory">
<property name="toolTip">
<string>Select parent item for your feed.</string>
</property>
<property name="iconSize">
<size>
<width>12</width>
<height>12</height>
</size>
</property>
<property name="frame">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Type</string>
</property>
<property name="buddy">
<cstring>m_cmbType</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="m_cmbType">
<property name="toolTip">
<string>Select type of the standard feed.</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Encoding</string>
</property>
<property name="buddy">
<cstring>m_cmbEncoding</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="m_cmbEncoding">
<property name="toolTip">
<string>Select encoding of the standard feed. If you are unsure about the encoding, then select &quot;UTF-8&quot; encoding.</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="m_lblTitle">
<property name="text">
<string>Title</string>
</property>
<property name="buddy">
<cstring>m_txtTitle</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="LineEditWithStatus" name="m_txtTitle" native="true"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="m_lblDescription">
<property name="text">
<string>Description</string>
</property>
<property name="buddy">
<cstring>m_txtDescription</cstring>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="LineEditWithStatus" name="m_txtDescription" native="true"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>URL</string>
</property>
<property name="buddy">
<cstring>m_txtUrl</cstring>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="LineEditWithStatus" name="m_txtUrl" native="true"/>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Fetch metadata</string>
</property>
<property name="buddy">
<cstring>m_btnFetchMetadata</cstring>
</property>
</widget>
</item>
<item row="6" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="m_btnFetchMetadata">
<property name="text">
<string>Fetch it now</string>
</property>
</widget>
</item>
<item>
<widget class="LabelWithStatus" name="m_lblFetchMetadata" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
</widget>
</item>
</layout>
</item>
<item row="7" column="0">
<widget class="QLabel" name="m_lblIcon">
<property name="text">
<string>Icon</string>
</property>
<property name="buddy">
<cstring>m_btnIcon</cstring>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QToolButton" name="m_btnIcon">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>40</width>
<height>40</height>
</size>
</property>
<property name="toolTip">
<string>Select icon for your feed.</string>
</property>
<property name="text">
<string notr="true"/>
</property>
<property name="iconSize">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
</property>
<property name="autoRaise">
<bool>false</bool>
</property>
<property name="arrowType">
<enum>Qt::NoArrow</enum>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>LabelWithStatus</class>
<extends>QWidget</extends>
<header>labelwithstatus.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>LineEditWithStatus</class>
<extends>QWidget</extends>
<header>lineeditwithstatus.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>m_cmbParentCategory</tabstop>
<tabstop>m_cmbType</tabstop>
<tabstop>m_cmbEncoding</tabstop>
<tabstop>m_btnFetchMetadata</tabstop>
<tabstop>m_btnIcon</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>

View File

@ -32,9 +32,6 @@
StandardFeed::StandardFeed(RootItem* parent_item)
: Feed(parent_item) {
m_passwordProtected = false;
m_username = QString();
m_password = QString();
m_networkError = QNetworkReply::NoError;
m_type = Type::Rss0X;
m_encoding = QString();
@ -42,16 +39,13 @@ StandardFeed::StandardFeed(RootItem* parent_item)
StandardFeed::StandardFeed(const StandardFeed& other)
: Feed(other) {
m_passwordProtected = other.passwordProtected();
m_username = other.username();
m_password = other.password();
m_networkError = other.networkError();
m_type = other.type();
m_encoding = other.encoding();
}
StandardFeed::~StandardFeed() {
qDebugNN << LOGSEC_CORE << "Destroying Feed instance.";
qDebugNN << LOGSEC_CORE << "Destroying StandardFeed instance.";
}
QList<QAction*> StandardFeed::contextMenuFeedsList() {
@ -397,30 +391,6 @@ void StandardFeed::setType(StandardFeed::Type type) {
m_type = type;
}
bool StandardFeed::passwordProtected() const {
return m_passwordProtected;
}
void StandardFeed::setPasswordProtected(bool passwordProtected) {
m_passwordProtected = passwordProtected;
}
QString StandardFeed::username() const {
return m_username;
}
void StandardFeed::setUsername(const QString& username) {
m_username = username;
}
QString StandardFeed::password() const {
return m_password;
}
void StandardFeed::setPassword(const QString& password) {
m_password = password;
}
QString StandardFeed::encoding() const {
return m_encoding;
}

View File

@ -57,12 +57,7 @@ class StandardFeed : public Feed {
// Other getters/setters.
Type type() const;
void setType(Type type);
bool passwordProtected() const;
void setPasswordProtected(bool passwordProtected);
QString username() const;
void setUsername(const QString& username);
QString password() const;
void setPassword(const QString& password);
QString encoding() const;
void setEncoding(const QString& encoding);
@ -86,9 +81,6 @@ class StandardFeed : public Feed {
void fetchMetadataForItself();
private:
bool m_passwordProtected{};
QString m_username;
QString m_password;
Type m_type;
QNetworkReply::NetworkError m_networkError;

View File

@ -1,76 +0,0 @@
// For license of this file, see <project-root-folder>/LICENSE.md.
#include "services/tt-rss/gui/formttrssfeeddetails.h"
#include "miscellaneous/application.h"
#include "services/tt-rss/definitions.h"
#include "services/tt-rss/network/ttrssnetworkfactory.h"
#include "services/tt-rss/ttrssfeed.h"
#include "services/tt-rss/ttrssserviceroot.h"
#include <QTimer>
FormTtRssFeedDetails::FormTtRssFeedDetails(ServiceRoot* service_root, QWidget* parent)
: FormFeedDetails(service_root, parent) {
m_ui->m_spinAutoUpdateInterval->setEnabled(false);
m_ui->m_cmbAutoUpdateType->setEnabled(false);
m_ui->m_cmbType->setEnabled(false);
m_ui->m_cmbEncoding->setEnabled(false);
m_ui->m_btnFetchMetadata->setEnabled(false);
m_ui->m_btnIcon->setEnabled(false);
m_ui->m_txtTitle->setEnabled(false);
m_ui->m_txtDescription->setEnabled(false);
}
void FormTtRssFeedDetails::apply() {
if (m_editableFeed != nullptr) {
// User edited auto-update status. Save it.
auto* new_feed_data = new TtRssFeed();
new_feed_data->setAutoUpdateType(static_cast<Feed::AutoUpdateType>(m_ui->m_cmbAutoUpdateType->itemData(
m_ui->m_cmbAutoUpdateType->currentIndex()).toInt()));
new_feed_data->setAutoUpdateInitialInterval(m_ui->m_spinAutoUpdateInterval->value());
qobject_cast<TtRssFeed*>(m_editableFeed)->editItself(new_feed_data);
delete new_feed_data;
}
else {
RootItem* parent = static_cast<RootItem*>(m_ui->m_cmbParentCategory->itemData(
m_ui->m_cmbParentCategory->currentIndex()).value<void*>());
auto* root = qobject_cast<TtRssServiceRoot*>(parent->getParentServiceRoot());
const int category_id = parent->kind() == RootItem::Kind::ServiceRoot ?
0 :
parent->customId().toInt();
const TtRssSubscribeToFeedResponse response = root->network()->subscribeToFeed(m_ui->m_txtUrl->lineEdit()->text(),
category_id,
m_ui->m_gbAuthentication->isChecked(),
m_ui->m_txtUsername->lineEdit()->text(),
m_ui->m_txtPassword->lineEdit()->text());
if (response.code() == STF_INSERTED) {
// Feed was added online.
accept();
qApp->showGuiMessage(tr("Feed added"), tr("Feed was added, triggering sync in now."), QSystemTrayIcon::Information);
QTimer::singleShot(100, root, SLOT(syncIn()));
}
else {
reject();
qApp->showGuiMessage(tr("Cannot add feed"),
tr("Feed was not added due to error."),
QSystemTrayIcon::Critical, qApp->mainFormWidget(), true);
}
}
accept();
}
void FormTtRssFeedDetails::setEditableFeed(Feed* editable_feed) {
m_ui->m_cmbAutoUpdateType->setEnabled(true);
FormFeedDetails::setEditableFeed(editable_feed);
// Tiny Tiny RSS does not support editing of these features.
// User can edit only individual auto-update statuses.
m_ui->m_gbAuthentication->setEnabled(false);
m_ui->m_txtUrl->setEnabled(false);
m_ui->m_lblParentCategory->setEnabled(false);
m_ui->m_cmbParentCategory->setEnabled(false);
}

View File

@ -1,23 +0,0 @@
// For license of this file, see <project-root-folder>/LICENSE.md.
#ifndef FORMTTRSSFEEDDETAILS_H
#define FORMTTRSSFEEDDETAILS_H
#include "services/abstract/gui/formfeeddetails.h"
class FormTtRssFeedDetails : public FormFeedDetails {
Q_OBJECT
public:
explicit FormTtRssFeedDetails(ServiceRoot* service_root, QWidget* parent = 0);
// FormFeedDetails interface
protected slots:
void apply();
protected:
void setEditableFeed(Feed* editable_feed);
};
#endif // FORMTTRSSFEEDDETAILS_H

View File

@ -8,7 +8,6 @@
#include "miscellaneous/iconfactory.h"
#include "miscellaneous/textfactory.h"
#include "services/tt-rss/definitions.h"
#include "services/tt-rss/gui/formttrssfeeddetails.h"
#include "services/tt-rss/network/ttrssnetworkfactory.h"
#include "services/tt-rss/ttrssserviceroot.h"
@ -24,18 +23,6 @@ TtRssServiceRoot* TtRssFeed::serviceRoot() const {
return qobject_cast<TtRssServiceRoot*>(getParentServiceRoot());
}
bool TtRssFeed::canBeEdited() const {
return true;
}
bool TtRssFeed::editViaGui() {
QPointer<FormTtRssFeedDetails> form_pointer = new FormTtRssFeedDetails(serviceRoot(), qApp->mainFormWidget());
form_pointer.data()->addEditFeed(this, this);
delete form_pointer.data();
return false;
}
bool TtRssFeed::canBeDeleted() const {
return true;
}
@ -55,20 +42,6 @@ bool TtRssFeed::deleteViaGui() {
}
}
bool TtRssFeed::editItself(TtRssFeed* new_feed_data) {
QSqlDatabase database = qApp->database()->connection(metaObject()->className());
if (DatabaseQueries::editBaseFeed(database, id(), new_feed_data->autoUpdateType(),
new_feed_data->autoUpdateInitialInterval())) {
setAutoUpdateType(new_feed_data->autoUpdateType());
setAutoUpdateInitialInterval(new_feed_data->autoUpdateInitialInterval());
return true;
}
else {
return false;
}
}
QList<Message> TtRssFeed::obtainNewMessages(bool* error_during_obtaining) {
QList<Message> messages;
int newly_added_messages = 0;

View File

@ -19,12 +19,9 @@ class TtRssFeed : public Feed {
TtRssServiceRoot* serviceRoot() const;
bool canBeEdited() const;
bool editViaGui();
bool canBeDeleted() const;
bool deleteViaGui();
bool editItself(TtRssFeed* new_feed_data);
bool removeItself();
QList<Message> obtainNewMessages(bool* error_during_obtaining);

View File

@ -14,7 +14,6 @@
#include "services/abstract/recyclebin.h"
#include "services/tt-rss/definitions.h"
#include "services/tt-rss/gui/formeditttrssaccount.h"
#include "services/tt-rss/gui/formttrssfeeddetails.h"
#include "services/tt-rss/network/ttrssnetworkfactory.h"
#include "services/tt-rss/ttrssfeed.h"
#include "services/tt-rss/ttrssserviceentrypoint.h"
@ -84,34 +83,13 @@ bool TtRssServiceRoot::deleteViaGui() {
}
bool TtRssServiceRoot::supportsFeedAdding() const {
return true;
return false;
}
bool TtRssServiceRoot::supportsCategoryAdding() const {
return false;
}
void TtRssServiceRoot::addNewFeed(RootItem* selected_item, const QString& url) {
Q_UNUSED(selected_item)
if (!qApp->feedUpdateLock()->tryLock()) {
// Lock was not obtained because
// it is used probably by feed updater or application
// is quitting.
qApp->showGuiMessage(tr("Cannot add item"),
tr("Cannot add feed because another critical operation is ongoing."),
QSystemTrayIcon::Warning, qApp->mainFormWidget(), true);
// Thus, cannot delete and quit the method.
return;
}
QScopedPointer<FormTtRssFeedDetails> form_pointer(new FormTtRssFeedDetails(this, qApp->mainFormWidget()));
form_pointer->addEditFeed(nullptr, selected_item, url);
qApp->feedUpdateLock()->unlock();
}
bool TtRssServiceRoot::canBeEdited() const {
return true;
}

View File

@ -39,9 +39,6 @@ class TtRssServiceRoot : public ServiceRoot, public CacheForServiceRoot {
void saveAccountDataToDatabase();
void updateTitle();
public slots:
virtual void addNewFeed(RootItem* selected_item, const QString& url = QString());
protected:
virtual RootItem* obtainNewTreeForSyncIn() const;