diff --git a/src/core/defs.h.in b/src/core/defs.h.in index 23ccf0654..98b79085f 100755 --- a/src/core/defs.h.in +++ b/src/core/defs.h.in @@ -94,8 +94,9 @@ #define FDS_DB_CATEGORY_INDEX 5 #define FDS_DB_ENCODING_INDEX 6 #define FDS_DB_URL_INDEX 7 -#define FDS_DB_LANGUAGE_INDEX 8 -#define FDS_DB_TYPE_INDEX 9 +#define FDS_DB_TYPE_INDEX 8 +//#define FDS_DB_LANGUAGE_INDEX 8 +//#define FDS_DB_TYPE_INDEX 9 // Indexes of columns for feed models. #define FDS_MODEL_TITLE_INDEX 0 diff --git a/src/core/feedsmodelrootitem.h b/src/core/feedsmodelrootitem.h index 84680a4e8..9ddf9a7f8 100755 --- a/src/core/feedsmodelrootitem.h +++ b/src/core/feedsmodelrootitem.h @@ -72,16 +72,17 @@ class FeedsModelRootItem { return m_childItems; } - // Checks whether this instance is child (can be nested) - // if given root item. - bool isChildOf(FeedsModelRootItem *root) { + // Checks whether THIS object is child (direct or indirect) + // of the given root. + bool isChildOf(FeedsModelRootItem *root) { + FeedsModelRootItem *this_item = this; - while (root->kind() != FeedsModelRootItem::RootItem) { - if (root->childItems().contains(this)) { + while (this_item->kind() != FeedsModelRootItem::RootItem) { + if (root->childItems().contains(this_item)) { return true; } else { - root = root->parent(); + this_item = this_item->parent(); } } diff --git a/src/core/feedsmodelstandardfeed.cpp b/src/core/feedsmodelstandardfeed.cpp index d7cd4ec6e..8cd6ec3f9 100755 --- a/src/core/feedsmodelstandardfeed.cpp +++ b/src/core/feedsmodelstandardfeed.cpp @@ -32,7 +32,6 @@ FeedsModelStandardFeed *FeedsModelStandardFeed::loadFromRecord(const QSqlRecord feed->setIcon(IconFactory::fromByteArray(record.value(FDS_DB_ICON_INDEX).toByteArray())); feed->setEncoding(record.value(FDS_DB_ENCODING_INDEX).toString()); feed->setUrl(record.value(FDS_DB_URL_INDEX).toString()); - feed->setLanguage(record.value(FDS_DB_LANGUAGE_INDEX).toString()); feed->updateCounts(); return feed; @@ -74,14 +73,11 @@ QVariant FeedsModelStandardFeed::data(int column, int role) const { if (column == FDS_MODEL_TITLE_INDEX) { return QObject::tr("%1 (%2)\n" "%3\n\n" - "Encoding: %4\n" - "Language: %5").arg(m_title, + "Encoding: %4").arg(m_title, FeedsModelFeed::typeToString(m_type), m_description, - m_encoding, - m_language.isEmpty() ? - "-" : - m_language); } + m_encoding); + } else if (column == FDS_MODEL_COUNTS_INDEX) { return QObject::tr("%n unread message(s).", "", countOfUnreadMessages()); } diff --git a/src/core/feedsmodelstandardfeed.h b/src/core/feedsmodelstandardfeed.h index 204cef314..3ec23ee05 100644 --- a/src/core/feedsmodelstandardfeed.h +++ b/src/core/feedsmodelstandardfeed.h @@ -45,14 +45,6 @@ class FeedsModelStandardFeed : public FeedsModelFeed { m_url = url; } - inline QString language() const { - return m_language; - } - - inline void setLanguage(const QString &language) { - m_language = language; - } - // Loads standard feed object from given SQL record. static FeedsModelStandardFeed *loadFromRecord(const QSqlRecord &record); @@ -65,7 +57,6 @@ class FeedsModelStandardFeed : public FeedsModelFeed { private: QString m_encoding; QString m_url; - QString m_language; }; #endif // FEEDSMODELSTANDARDFEED_H diff --git a/src/gui/feedsview.cpp b/src/gui/feedsview.cpp index 61b85dfa3..268d14fdb 100644 --- a/src/gui/feedsview.cpp +++ b/src/gui/feedsview.cpp @@ -7,6 +7,7 @@ #include "core/feedsproxymodel.h" #include "core/feedsmodelrootitem.h" #include "core/feedsmodelcategory.h" +#include "core/feedsmodelstandardfeed.h" #include "core/feedsmodelstandardcategory.h" #include "gui/formmain.h" #include "gui/formstandardcategorydetails.h" @@ -111,10 +112,9 @@ void FeedsView::addNewStandardCategory() { } void FeedsView::editStandardCategory(FeedsModelStandardCategory *category) { - FeedsModelStandardCategory *std_category = static_cast(category); QPointer form_pointer = new FormStandardCategoryDetails(m_sourceModel, this); - if (form_pointer.data()->exec(std_category) == QDialog::Accepted) { + if (form_pointer.data()->exec(category) == QDialog::Accepted) { // TODO: kategorie upravena } else { @@ -160,6 +160,19 @@ void FeedsView::addNewStandardFeed() { SystemFactory::instance()->applicationCloseLock()->unlock(); } +void FeedsView::editStandardFeed(FeedsModelStandardFeed *feed) { + QPointer form_pointer = new FormStandardFeedDetails(m_sourceModel, this); + + if (form_pointer.data()->exec(feed) == QDialog::Accepted) { + // TODO: kategorie upravena + } + else { + // TODO: kategorie neupravena (uživatel zrušil dialog) + } + + delete form_pointer.data(); +} + void FeedsView::editSelectedItem() { if (!SystemFactory::instance()->applicationCloseLock()->tryLockForWrite()) { // Lock was not obtained because @@ -199,6 +212,19 @@ void FeedsView::editSelectedItem() { } else if ((feed = isCurrentIndexFeed()) != NULL) { // Feed is selected. + switch (feed->type()) { + case FeedsModelFeed::StandardAtom10: + case FeedsModelFeed::StandardRdf: + case FeedsModelFeed::StandardRss0X: + case FeedsModelFeed::StandardRss2X: { + // User wants to edit standard feed. + editStandardFeed(static_cast(feed)); + break; + } + + default: + break; + } } // Changes are done, unlock the update master lock. diff --git a/src/gui/feedsview.h b/src/gui/feedsview.h index 63dfed5c6..316d671fe 100644 --- a/src/gui/feedsview.h +++ b/src/gui/feedsview.h @@ -78,6 +78,7 @@ class FeedsView : public QTreeView { // Standard feed manipulators. void addNewStandardFeed(); + void editStandardFeed(FeedsModelStandardFeed *feed); // Reloads counts for selected feeds. void updateCountsOfSelectedFeeds(bool update_total_too = true); diff --git a/src/gui/formstandardcategorydetails.cpp b/src/gui/formstandardcategorydetails.cpp index d8ad0a23f..e41865906 100644 --- a/src/gui/formstandardcategorydetails.cpp +++ b/src/gui/formstandardcategorydetails.cpp @@ -65,6 +65,11 @@ void FormStandardCategoryDetails::setEditableCategory(FeedsModelStandardCategory } int FormStandardCategoryDetails::exec(FeedsModelStandardCategory *input_category) { + // Load categories. + loadCategories(m_feedsModel->allCategories().values(), + m_feedsModel->rootItem(), + input_category); + if (input_category == NULL) { // User is adding new category. setWindowTitle(tr("Add new standard category")); @@ -79,11 +84,6 @@ int FormStandardCategoryDetails::exec(FeedsModelStandardCategory *input_category setEditableCategory(input_category); } - // Load categories. - loadCategories(m_feedsModel->allCategories().values(), - m_feedsModel->rootItem(), - input_category); - // Run the dialog. return QDialog::exec(); } @@ -211,7 +211,6 @@ void FormStandardCategoryDetails::loadCategories(const QListparent() == category || category->isChildOf(input_category))) { // This category cannot be selected as the new // parent for currently edited category, so diff --git a/src/gui/formstandardfeeddetails.cpp b/src/gui/formstandardfeeddetails.cpp index 401f8e243..0ed90c413 100644 --- a/src/gui/formstandardfeeddetails.cpp +++ b/src/gui/formstandardfeeddetails.cpp @@ -2,9 +2,12 @@ #include "core/textfactory.h" #include "core/feedsmodel.h" +#include "core/feedsmodelrootitem.h" +#include "core/feedsmodelcategory.h" #include "core/feedsmodelfeed.h" #include "core/feedsmodelstandardfeed.h" #include "gui/iconthemefactory.h" +#include "gui/baselineedit.h" #if !defined(Q_OS_WIN) #include "gui/messagebox.h" @@ -15,7 +18,9 @@ FormStandardFeedDetails::FormStandardFeedDetails(FeedsModel *model, QWidget *parent) - : QDialog(parent) { + : QDialog(parent), + m_editableFeed(NULL), + m_feedsModel(model) { initialize(); } @@ -24,6 +29,11 @@ FormStandardFeedDetails::~FormStandardFeedDetails() { } int FormStandardFeedDetails::exec(FeedsModelStandardFeed *input_feed) { + // Load categories. + loadCategories(m_feedsModel->allCategories().values(), + m_feedsModel->rootItem(), + input_feed); + if (input_feed == NULL) { // User is adding new category. setWindowTitle(tr("Add new standard feed")); @@ -31,15 +41,25 @@ int FormStandardFeedDetails::exec(FeedsModelStandardFeed *input_feed) { else { // User is editing existing category. setWindowTitle(tr("Edit existing standard feed")); - // TODO: set editable feed. + setEditableFeed(input_feed); } - // TODO: Load categories. - // Run the dialog. return QDialog::exec(); } +void FormStandardFeedDetails::setEditableFeed(FeedsModelStandardFeed *editable_feed) { + 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_cmbType->setCurrentIndex(m_ui->m_cmbType->findData(QVariant::fromValue((void*) editable_feed->type()))); + m_ui->m_cmbEncoding->setCurrentIndex(m_ui->m_cmbEncoding->findData(editable_feed->encoding(), Qt::DisplayRole)); + m_ui->m_txtUrl->lineEdit()->setText(editable_feed->url()); +} + void FormStandardFeedDetails::initialize() { m_ui = new Ui::FormStandardFeedDetails(); m_ui->setupUi(this); @@ -56,10 +76,10 @@ void FormStandardFeedDetails::initialize() { #endif // Add standard feed types. - m_ui->m_cmbType->addItem(FeedsModelFeed::typeToString(FeedsModelFeed::StandardAtom10), QVariant::fromValue(FeedsModelFeed::StandardAtom10)); - m_ui->m_cmbType->addItem(FeedsModelFeed::typeToString(FeedsModelFeed::StandardRdf), QVariant::fromValue(FeedsModelFeed::StandardRdf)); - m_ui->m_cmbType->addItem(FeedsModelFeed::typeToString(FeedsModelFeed::StandardRss0X), QVariant::fromValue(FeedsModelFeed::StandardRss0X)); - m_ui->m_cmbType->addItem(FeedsModelFeed::typeToString(FeedsModelFeed::StandardRss2X), QVariant::fromValue(FeedsModelFeed::StandardRss2X)); + m_ui->m_cmbType->addItem(FeedsModelFeed::typeToString(FeedsModelFeed::StandardAtom10), QVariant::fromValue((void*) FeedsModelFeed::StandardAtom10)); + m_ui->m_cmbType->addItem(FeedsModelFeed::typeToString(FeedsModelFeed::StandardRdf), QVariant::fromValue((void*) FeedsModelFeed::StandardRdf)); + m_ui->m_cmbType->addItem(FeedsModelFeed::typeToString(FeedsModelFeed::StandardRss0X), QVariant::fromValue((void*) FeedsModelFeed::StandardRss0X)); + m_ui->m_cmbType->addItem(FeedsModelFeed::typeToString(FeedsModelFeed::StandardRss2X), QVariant::fromValue((void*) FeedsModelFeed::StandardRss2X)); // Load available encodings. QList encodings = QTextCodec::availableCodecs(); @@ -71,5 +91,19 @@ void FormStandardFeedDetails::initialize() { qSort(encoded_encodings.begin(), encoded_encodings.end(), TextFactory::isCaseInsensitiveLessThan); m_ui->m_cmbEncoding->addItems(encoded_encodings); - +} + +void FormStandardFeedDetails::loadCategories(const QList categories, + FeedsModelRootItem *root_item, + FeedsModelStandardFeed *input_feed) { + m_ui->m_cmbParentCategory->addItem(root_item->icon(), + root_item->title(), + QVariant::fromValue((void*) root_item)); + + foreach (FeedsModelCategory *category, categories) { + m_ui->m_cmbParentCategory->addItem(category->data(FDS_MODEL_TITLE_INDEX, + Qt::DecorationRole).value(), + category->title(), + QVariant::fromValue((void*) category)); + } } diff --git a/src/gui/formstandardfeeddetails.h b/src/gui/formstandardfeeddetails.h index 5dbaf64b7..db0c3607d 100644 --- a/src/gui/formstandardfeeddetails.h +++ b/src/gui/formstandardfeeddetails.h @@ -12,6 +12,8 @@ namespace Ui { class FeedsModel; class FeedsModelStandardFeed; +class FeedsModelCategory; +class FeedsModelRootItem; class FormStandardFeedDetails : public QDialog { Q_OBJECT @@ -25,10 +27,23 @@ class FormStandardFeedDetails : public QDialog { int exec(FeedsModelStandardFeed *input_feed); protected: + void setEditableFeed(FeedsModelStandardFeed *editable_feed); void initialize(); + // Loads categories into the dialog from the model. + void loadCategories(const QList categories, + FeedsModelRootItem *root_item, + FeedsModelStandardFeed *input_feed); + private: Ui::FormStandardFeedDetails *m_ui; + FeedsModelStandardFeed *m_editableFeed; + FeedsModel *m_feedsModel; + + QMenu *m_iconMenu; + QAction *m_actionLoadIconFromFile; + QAction *m_actionUseDefaultIcon; + QAction *m_actionNoIcon; }; #endif // FORMSTANDARDFEEDDETAILS_H diff --git a/src/gui/formstandardfeeddetails.ui b/src/gui/formstandardfeeddetails.ui index ca95604e6..c690d00bd 100644 --- a/src/gui/formstandardfeeddetails.ui +++ b/src/gui/formstandardfeeddetails.ui @@ -84,7 +84,7 @@ - +