diff --git a/src/services/tt-rss/gui/formeditfeed.cpp b/src/services/tt-rss/gui/formeditfeed.cpp index 62ec5b80e..b55bca0d8 100755 --- a/src/services/tt-rss/gui/formeditfeed.cpp +++ b/src/services/tt-rss/gui/formeditfeed.cpp @@ -32,6 +32,7 @@ FormEditFeed::FormEditFeed(TtRssServiceRoot *root, QWidget *parent) m_ui->setupUi(this); initialize(); + connect(m_ui->m_txtUrl->lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(onUrlChanged(QString))); connect(m_ui->m_gbAuthentication, SIGNAL(toggled(bool)), this, SLOT(onAuthenticationSwitched())); connect(m_ui->m_cmbAutoUpdateType, SIGNAL(currentIndexChanged(int)), this, SLOT(onAutoUpdateTypeChanged(int))); connect(m_ui->m_buttonBox, SIGNAL(accepted()), this, SLOT(performAction())); @@ -44,6 +45,8 @@ FormEditFeed::~FormEditFeed() { int FormEditFeed::execForEdit(TtRssFeed *input_feed) { loadCategories(m_root->getSubTreeCategories(), m_root); loadFeed(input_feed); + m_ui->m_txtUrl->lineEdit()->setFocus(); + return QDialog::exec(); } @@ -52,7 +55,10 @@ int FormEditFeed::execForAdd() { m_ui->m_txtUrl->lineEdit()->setText(qApp->clipboard()->text()); } - // TODO: todo + loadCategories(m_root->getSubTreeCategories(), m_root); + loadFeed(NULL); + m_ui->m_txtUrl->lineEdit()->setFocus(); + return QDialog::exec(); } @@ -82,7 +88,7 @@ void FormEditFeed::performAction() { saveFeed(); } else { - // TODO: Add new feed. + addNewFeed(); } accept(); @@ -145,24 +151,39 @@ void FormEditFeed::initialize() { m_ui->m_txtUrl->lineEdit()->setPlaceholderText(tr("Full feed url including scheme")); m_ui->m_txtUsername->lineEdit()->setPlaceholderText(tr("Username")); m_ui->m_txtPassword->lineEdit()->setPlaceholderText(tr("Password")); + + onAuthenticationSwitched(); } void FormEditFeed::loadFeed(TtRssFeed *input_feed) { m_loadedFeed = input_feed; - setWindowTitle(tr("Edit existing feed")); + if (input_feed != NULL) { + setWindowTitle(tr("Edit existing 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_lblUrl->setEnabled(false); - m_ui->m_lblParentCategory->setEnabled(false); - m_ui->m_cmbParentCategory->setEnabled(false); + // 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_lblUrl->setEnabled(false); + m_ui->m_lblParentCategory->setEnabled(false); + m_ui->m_cmbParentCategory->setEnabled(false); - m_ui->m_cmbParentCategory->setCurrentIndex(m_ui->m_cmbParentCategory->findData(QVariant::fromValue((void*) input_feed->parent()))); - m_ui->m_cmbAutoUpdateType->setCurrentIndex(m_ui->m_cmbAutoUpdateType->findData(QVariant::fromValue((int) input_feed->autoUpdateType()))); - m_ui->m_spinAutoUpdateInterval->setValue(input_feed->autoUpdateInitialInterval()); + m_ui->m_cmbParentCategory->setCurrentIndex(m_ui->m_cmbParentCategory->findData(QVariant::fromValue((void*) input_feed->parent()))); + m_ui->m_cmbAutoUpdateType->setCurrentIndex(m_ui->m_cmbAutoUpdateType->findData(QVariant::fromValue((int) input_feed->autoUpdateType()))); + m_ui->m_spinAutoUpdateInterval->setValue(input_feed->autoUpdateInitialInterval()); + } + else { + setWindowTitle(tr("Add new feed")); + + // Tiny Tiny RSS does not support editing of these features. + // User can edit only individual auto-update statuses. + m_ui->m_gbAuthentication->setEnabled(true); + m_ui->m_txtUrl->setEnabled(true); + m_ui->m_lblUrl->setEnabled(true); + m_ui->m_lblParentCategory->setEnabled(true); + m_ui->m_cmbParentCategory->setEnabled(true); + } } void FormEditFeed::saveFeed() { @@ -176,6 +197,12 @@ void FormEditFeed::saveFeed() { delete new_feed_data; } +void FormEditFeed::addNewFeed() { + // Store feed online and if successfull, then store into DB/model. + + // TODO: todo +} + void FormEditFeed::loadCategories(const QList categories, RootItem *root_item) { m_ui->m_cmbParentCategory->addItem(root_item->icon(), root_item->title(), diff --git a/src/services/tt-rss/gui/formeditfeed.h b/src/services/tt-rss/gui/formeditfeed.h index 026e9f61c..57a9c19a1 100755 --- a/src/services/tt-rss/gui/formeditfeed.h +++ b/src/services/tt-rss/gui/formeditfeed.h @@ -54,6 +54,7 @@ class FormEditFeed : public QDialog { void initialize(); void loadFeed(TtRssFeed *input_feed); void saveFeed(); + void addNewFeed(); void loadCategories(const QList categories, RootItem *root_item); Ui::FormEditFeed *m_ui; diff --git a/src/services/tt-rss/ttrssserviceroot.cpp b/src/services/tt-rss/ttrssserviceroot.cpp index 4499ad3c4..d6bd20f6f 100755 --- a/src/services/tt-rss/ttrssserviceroot.cpp +++ b/src/services/tt-rss/ttrssserviceroot.cpp @@ -29,6 +29,7 @@ #include "services/tt-rss/definitions.h" #include "services/tt-rss/network/ttrssnetworkfactory.h" #include "services/tt-rss/gui/formeditaccount.h" +#include "services/tt-rss/gui/formeditfeed.h" #include #include @@ -38,7 +39,9 @@ TtRssServiceRoot::TtRssServiceRoot(RootItem *parent) - : ServiceRoot(parent), m_recycleBin(new TtRssRecycleBin(this)), m_actionSyncIn(NULL), m_serviceMenu(QList()), m_network(new TtRssNetworkFactory) { + : ServiceRoot(parent), m_recycleBin(new TtRssRecycleBin(this)), + m_actionSyncIn(NULL), m_serviceMenu(QList()), m_addItemMenu(QList()), + m_network(new TtRssNetworkFactory) { setIcon(TtRssServiceEntryPoint().icon()); setCreationDate(QDateTime::currentDateTime()); } @@ -136,7 +139,14 @@ QVariant TtRssServiceRoot::data(int column, int role) const { } QList TtRssServiceRoot::addItemMenu() { - return QList(); + if (m_addItemMenu.isEmpty()) { + QAction *action_new_feed = new QAction(qApp->icons()->fromTheme("folder-feed"), tr("Add new feed"), this); + connect(action_new_feed, SIGNAL(triggered()), this, SLOT(addNewFeed())); + + m_addItemMenu.append(action_new_feed); + } + + return m_addItemMenu; } RecycleBin *TtRssServiceRoot::recycleBin() { @@ -585,6 +595,13 @@ void TtRssServiceRoot::syncIn() { itemChanged(QList() << this); } +void TtRssServiceRoot::addNewFeed() { + QPointer form_pointer = new FormEditFeed(this, qApp->mainForm()); + + form_pointer.data()->execForAdd(); + delete form_pointer.data(); +} + QStringList TtRssServiceRoot::customIDsOfMessages(const QList > &changes) { QStringList list; diff --git a/src/services/tt-rss/ttrssserviceroot.h b/src/services/tt-rss/ttrssserviceroot.h index 065d147c6..1609fe21c 100755 --- a/src/services/tt-rss/ttrssserviceroot.h +++ b/src/services/tt-rss/ttrssserviceroot.h @@ -85,6 +85,9 @@ class TtRssServiceRoot : public ServiceRoot { public slots: void syncIn(); + private slots: + void addNewFeed(); + private: QStringList customIDsOfMessages(const QList > &changes); QStringList customIDsOfMessages(const QList &messages); @@ -102,6 +105,7 @@ class TtRssServiceRoot : public ServiceRoot { QAction *m_actionSyncIn; QList m_serviceMenu; + QList m_addItemMenu; TtRssNetworkFactory *m_network; };