diff --git a/CMakeLists.txt b/CMakeLists.txt index d7ceafa71..5df6a68e5 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -255,6 +255,7 @@ set(APP_SOURCES src/gui/messagesview.cpp src/gui/statusbar.cpp src/gui/iconfactory.cpp + src/gui/formcategorydetails.cpp # CORE sources. src/core/debugging.cpp @@ -316,6 +317,7 @@ set(APP_HEADERS src/gui/feedsview.h src/gui/messagesview.h src/gui/statusbar.h + src/gui/formcategorydetails.h # CORE headers. src/core/settings.h diff --git a/src/core/feedsmodel.cpp b/src/core/feedsmodel.cpp index 75947b081..eefa4c89d 100644 --- a/src/core/feedsmodel.cpp +++ b/src/core/feedsmodel.cpp @@ -294,12 +294,25 @@ QList FeedsModel::feedsForIndex(const QModelIndex &index) { return getFeeds(item); } -bool FeedsModel::isUnequal(FeedsModelFeed *lhs, FeedsModelFeed *rhs) { - return !isEqual(lhs, rhs); -} +QList FeedsModel::feedsForIndexes(const QModelIndexList &indexes) { + QList feeds; -bool FeedsModel::isEqual(FeedsModelFeed *lhs, FeedsModelFeed *rhs) { - return lhs->id() == rhs->id(); + // Get selected feeds for each index. + foreach (const QModelIndex &index, indexes) { + feeds.append(feedsForIndex(index)); + } + + // Now we obtained all feeds from corresponding indexes. + if (indexes.size() != feeds.size()) { + // Selection contains duplicate feeds (for + // example situation where feed and its parent category are both + // selected). So, remove duplicates from the list. + qSort(feeds.begin(), feeds.end(), FeedsModelRootItem::lessThan); + feeds.erase(std::unique(feeds.begin(), feeds.end(), FeedsModelRootItem::isEqual), + feeds.end()); + } + + return feeds; } bool FeedsModel::markFeedsRead(const QList &feeds, @@ -370,28 +383,6 @@ bool FeedsModel::markFeedsDeleted(const QList &feeds, } } - -QList FeedsModel::feedsForIndexes(const QModelIndexList &indexes) { - QList feeds; - - // Get selected feeds for each index. - foreach (const QModelIndex &index, indexes) { - feeds.append(feedsForIndex(index)); - } - - // Now we obtained all feeds from corresponding indexes. - if (indexes.size() != feeds.size()) { - // Selection contains duplicate feeds (for - // example situation where feed and its parent category are both - // selected). So, remove duplicates from the list. - qSort(feeds.begin(), feeds.end(), isUnequal); - feeds.erase(std::unique(feeds.begin(), feeds.end(), isEqual), - feeds.end()); - } - - return feeds; -} - QHash FeedsModel::getAllCategories() { return getCategories(m_rootItem); } diff --git a/src/core/feedsmodel.h b/src/core/feedsmodel.h index f5a144174..52fe8fd4c 100644 --- a/src/core/feedsmodel.h +++ b/src/core/feedsmodel.h @@ -54,10 +54,6 @@ class FeedsModel : public QAbstractItemModel { // Returns feeds contained within single index. QList feedsForIndex(const QModelIndex &index); - // Equality "operators" used for identifying duplicate feeds. - static bool isUnequal(FeedsModelFeed *lhs, FeedsModelFeed *rhs); - static bool isEqual(FeedsModelFeed *lhs, FeedsModelFeed *rhs); - public slots: bool markFeedsRead(const QList &feeds, int read); bool markFeedsDeleted(const QList &feeds, int deleted); diff --git a/src/core/feedsmodelrootitem.cpp b/src/core/feedsmodelrootitem.cpp index 488077b5e..4644e32c3 100755 --- a/src/core/feedsmodelrootitem.cpp +++ b/src/core/feedsmodelrootitem.cpp @@ -98,3 +98,18 @@ QList FeedsModelRootItem::childItems() const { void FeedsModelRootItem::clearChilds() { m_childItems.clear(); } + +bool FeedsModelRootItem::isEqual(FeedsModelRootItem *lhs, + FeedsModelRootItem *rhs) { + return (lhs->kind() == rhs->kind()) && (lhs->id() == rhs->id()); +} + +bool FeedsModelRootItem::lessThan(FeedsModelRootItem *lhs, + FeedsModelRootItem *rhs) { + if (lhs->kind() == rhs->kind()) { + return lhs->id() < rhs->id(); + } + else { + return false; + } +} diff --git a/src/core/feedsmodelrootitem.h b/src/core/feedsmodelrootitem.h index 2e7bdf059..fdb1046f5 100755 --- a/src/core/feedsmodelrootitem.h +++ b/src/core/feedsmodelrootitem.h @@ -54,6 +54,10 @@ class FeedsModelRootItem { // Removes all childs from this item. void clearChilds(); + // Compares two model items. + static bool isEqual(FeedsModelRootItem *lhs, FeedsModelRootItem *rhs); + static bool lessThan(FeedsModelRootItem *lhs, FeedsModelRootItem *rhs); + protected: Kind m_kind; QString m_title; diff --git a/src/gui/feedmessageviewer.cpp b/src/gui/feedmessageviewer.cpp index 47807c664..8ca418f76 100644 --- a/src/gui/feedmessageviewer.cpp +++ b/src/gui/feedmessageviewer.cpp @@ -185,6 +185,8 @@ void FeedMessageViewer::createConnections() { SIGNAL(triggered()), this, SLOT(updateSelectedFeeds())); connect(FormMain::getInstance()->m_ui->m_actionUpdateAllFeeds, SIGNAL(triggered()), this, SLOT(updateAllFeeds())); + connect(FormMain::getInstance()->m_ui->m_actionAddNewCategory, + SIGNAL(triggered()), m_feedsView, SLOT(addNewCategory())); } void FeedMessageViewer::initialize() { diff --git a/src/gui/feedsview.cpp b/src/gui/feedsview.cpp index a433555d3..1b5e996bd 100644 --- a/src/gui/feedsview.cpp +++ b/src/gui/feedsview.cpp @@ -6,10 +6,12 @@ #include "core/feedsproxymodel.h" #include "core/feedsmodelrootitem.h" #include "gui/formmain.h" +#include "gui/formcategorydetails.h" #include #include #include +#include FeedsView::FeedsView(QWidget *parent) : QTreeView(parent), m_contextMenu(NULL) { @@ -51,6 +53,18 @@ void FeedsView::clearSelectedFeeds() { setSelectedFeedsClearStatus(1); } +void FeedsView::addNewCategory() { + QPointer form_pointer = new FormCategoryDetails(this); + + if (form_pointer.data()->exec() == QDialog::Accepted) { + // User submitted some new category. + + + } + + delete form_pointer.data(); +} + void FeedsView::markSelectedFeedsReadStatus(int read) { m_sourceModel->markFeedsRead(selectedFeeds(), read); updateCountsOfSelectedFeeds(false); diff --git a/src/gui/feedsview.h b/src/gui/feedsview.h index 37367ae85..f49f56b47 100644 --- a/src/gui/feedsview.h +++ b/src/gui/feedsview.h @@ -33,6 +33,9 @@ class FeedsView : public QTreeView { void setSelectedFeedsClearStatus(int clear); void clearSelectedFeeds(); + // Category operators. + void addNewCategory(); + // Reloads counts for selected feeds. void updateCountsOfSelectedFeeds(bool update_total_too = true); diff --git a/src/gui/formcategorydetails.cpp b/src/gui/formcategorydetails.cpp new file mode 100644 index 000000000..ffa4ed019 --- /dev/null +++ b/src/gui/formcategorydetails.cpp @@ -0,0 +1,25 @@ +#include "gui/formcategorydetails.h" + +#include "gui/iconthemefactory.h" +#include "gui/feedsview.h" + + +FormCategoryDetails::FormCategoryDetails(FeedsView *parent) + : QDialog(parent) { + // Set flags and attributes. + setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog); + setWindowIcon(IconThemeFactory::getInstance()->fromTheme("document-new")); +} + +FormCategoryDetails::FormCategoryDetails(FeedsModelCategory *category, + FeedsView *parent) + :QDialog(parent) { + // Set flags and attributes. + setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog); + setWindowIcon(IconThemeFactory::getInstance()->fromTheme("document-new")); + +} + +FormCategoryDetails::~FormCategoryDetails() { + qDebug("Destroying FormCategoryDetails instance."); +} diff --git a/src/gui/formcategorydetails.h b/src/gui/formcategorydetails.h new file mode 100644 index 000000000..527e13e02 --- /dev/null +++ b/src/gui/formcategorydetails.h @@ -0,0 +1,31 @@ +#ifndef FORMCATEGORYDETAILS_H +#define FORMCATEGORYDETAILS_H + +#include + + +class FeedsModelCategory; +class FeedsView; + +class FormCategoryDetails : public QDialog { + Q_OBJECT + + public: + // Constructors and destructors. + // This constructor is supposed to create new categories. + explicit FormCategoryDetails(FeedsView *parent = 0); + + // This constructor is supposed to edit existing categories. + explicit FormCategoryDetails(FeedsModelCategory *category, + FeedsView *parent = 0); + + // Destructor. + virtual ~FormCategoryDetails(); + + signals: + + public slots: + +}; + +#endif // FORMCATEGORYDETAILS_H