From d6ee69df0d44647f5fb51fe115621c36a57f683e Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Sat, 28 Dec 2013 16:44:21 +0100 Subject: [PATCH] Work on adding categories. --- CMakeLists.txt | 1 + .../icons/mini-kfaenza/folder-red.png | Bin 0 -> 2026 bytes src/core/feedsmodel.cpp | 32 +---- src/core/feedsmodel.h | 3 + src/core/feedsmodelrootitem.cpp | 4 + src/core/feedsmodelrootitem.h | 1 + src/gui/feedsview.cpp | 8 ++ src/gui/feedsview.h | 3 + src/gui/formcategorydetails.cpp | 52 +++++++- src/gui/formcategorydetails.h | 18 ++- src/gui/formcategorydetails.ui | 126 ++++++++++++++++++ src/gui/formsettings.ui | 6 +- 12 files changed, 216 insertions(+), 38 deletions(-) create mode 100644 resources/graphics/icons/mini-kfaenza/folder-red.png create mode 100644 src/gui/formcategorydetails.ui diff --git a/CMakeLists.txt b/CMakeLists.txt index 5df6a68e5..00a857474 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -340,6 +340,7 @@ set(APP_FORMS src/gui/formsettings.ui src/gui/formwelcome.ui src/gui/formabout.ui + src/gui/formcategorydetails.ui ) # Add resources. diff --git a/resources/graphics/icons/mini-kfaenza/folder-red.png b/resources/graphics/icons/mini-kfaenza/folder-red.png new file mode 100644 index 0000000000000000000000000000000000000000..2d46b788a9c8e21f16de58f2b6412da0d4a4db62 GIT binary patch literal 2026 zcmV_cuLfgE$N*Tfh55FE%MkX!;z5Ss*q4I2j~EA2|Vl2)2s z&1hz->iN)JJ=N7cGup8v_iX$@Pxth6*VKFUy}zn%;8Xm6gN|{HypL;raJ-oz?mZLq z6DpjXoUDwGkB3Sr$;|hy04b%GQkqt))!y0JX#mi}clC4-tB0yDlC1mENJR}8`nVVX0!Q+?_PQ1$L)6eR=r-Y15h8k*C&X)Q4MOf+QZc8%>Vtl zXWyJ_HZP&w8vY+D72Gb5tv&nhAHV;P?d^3UY7F1l{h?Z|>b12sjXuoFFrZeem6TG| zA1*IHJ$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Ha4xQfsk%q;rn0j{>J;FbwMF%{u5!LMbGTMNKaL+kW}C{gjVK#N{k zpcPyvQ6OCoNB1&GDJeA{(2xE_P>AmX?73bFFa}b}BnblY5+UCNdQFDp{rM*iKMLf} z2MkDrECUA7e-s$tGeP%Bga9Bh0e?|s)S`er_L&e(iIH+vyaE8wT2mYzM3O(V8v=nO z@hPGrTqg9L5n>w#h1NQEN{paYB)nY+V5AvPK+{j)Ga#b?4GhQxqXkiS64a;vs4&1i zwp-3(Z%!&47Y#`<1b`UbFGZyQcXw_y08%D^J`9MfLEUv8eic~6(YJ6%-R}KqJ)M|9 zej=1y?;CD!eFKrFvd_AhLlQ#+{O|ISXBBu=*0xU7DE(gE9CHw}3`m*42>F8J2u#jrjQ$LG(2z5LpDF-=T@)c9glGY(%$)l!(Ws*d zRze72jIj@fMhcKp8YyK*Ypwp(Y~23R*!X83m?y<8f&l+)Hg6eYl$5d~gwQ~&fb-|i ztAm4sdqi~b+Sbj#URikbTa_>jljI?_Fxq2|VA$U+*mJz>oge1+r0;}7Hl3f`*!(jy z@3-6Sd(~<+RT1kO2^{4-f!yR*a5wPQ>#M zg0kmQb%vdcjVEMH&N+rR(>vfC7)MH}tBuC)OV|JR-nCBWFGTcSsZ{!KeSLi!Kw|40 z1i_tVv$+`r!PO61N1gBd=fnR3m>?qi=IBU*nKd&X0Js(e!J1O)Mi2yd0Pl?v0I1b! z6=t51QqD5-j4@`?zh(r%Qp!C5J6h{)DdjEq?Xiq-D=RDE*4EYpGgpi;L%lLvBoGlx zDHVX`+}vD!b#*oM5>!9o1OU0RvT~{&JZ-G5t^(1Uqq)h=N0kzvb`Lubf&c&j07*qo IM6N<$g7jXUbpQYW literal 0 HcmV?d00001 diff --git a/src/core/feedsmodel.cpp b/src/core/feedsmodel.cpp index eefa4c89d..2539fc9dd 100644 --- a/src/core/feedsmodel.cpp +++ b/src/core/feedsmodel.cpp @@ -20,7 +20,9 @@ FeedsModel::FeedsModel(QObject *parent) : QAbstractItemModel(parent) { setObjectName("FeedsModel"); m_rootItem = new FeedsModelRootItem(); + m_rootItem->setId(NO_PARENT_CATEGORY); m_rootItem->setTitle(tr("root")); + m_rootItem->setIcon(IconThemeFactory::getInstance()->fromTheme("folder-red")); m_countsIcon = IconThemeFactory::getInstance()->fromTheme("mail-mark-unread"); @@ -29,32 +31,6 @@ FeedsModel::FeedsModel(QObject *parent) : QAbstractItemModel(parent) { tr("Counts of unread/all meesages."); loadFromDatabase(); - - /* - FeedsModelStandardCategory *cat1 = new FeedsModelStandardCategory(); - FeedsModelStandardCategory *cat2 = new FeedsModelStandardCategory(); - FeedsModelStandardFeed *feed1 = new FeedsModelStandardFeed(); - FeedsModelStandardFeed *feed2 = new FeedsModelStandardFeed(); - FeedsModelStandardFeed *feed3 = new FeedsModelStandardFeed(); - FeedsModelStandardFeed *feed4 = new FeedsModelStandardFeed(); - FeedsModelStandardFeed *feed5 = new FeedsModelStandardFeed(); - - feed1->setTitle("aaa"); - feed2->setTitle("aaa"); - feed3->setTitle("aaa"); - feed4->setTitle("aaa"); - feed5->setTitle("aaa"); - - cat1->appendChild(feed1); - cat1->appendChild(feed2); - cat1->appendChild(cat2); - - cat2->appendChild(feed4); - cat2->appendChild(feed5); - - m_rootItem->appendChild(cat1); - m_rootItem->appendChild(feed3); - */ } FeedsModel::~FeedsModel() { @@ -463,6 +439,10 @@ void FeedsModel::assembleFeeds(FeedAssignment feeds) { } } +FeedsModelRootItem *FeedsModel::rootItem() const { + return m_rootItem; +} + void FeedsModel::assembleCategories(CategoryAssignment categories) { QHash assignments; assignments.insert(NO_PARENT_CATEGORY, m_rootItem); diff --git a/src/core/feedsmodel.h b/src/core/feedsmodel.h index 52fe8fd4c..d7fb69624 100644 --- a/src/core/feedsmodel.h +++ b/src/core/feedsmodel.h @@ -54,6 +54,9 @@ class FeedsModel : public QAbstractItemModel { // Returns feeds contained within single index. QList feedsForIndex(const QModelIndex &index); + // Access to root item. + FeedsModelRootItem *rootItem() const; + 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 4644e32c3..8b8dfa3a4 100755 --- a/src/core/feedsmodelrootitem.cpp +++ b/src/core/feedsmodelrootitem.cpp @@ -27,6 +27,10 @@ FeedsModelRootItem::Kind FeedsModelRootItem::kind() const { return m_kind; } +QIcon FeedsModelRootItem::icon() const { + return m_icon; +} + FeedsModelRootItem *FeedsModelRootItem::child(int row) { return m_childItems.value(row); } diff --git a/src/core/feedsmodelrootitem.h b/src/core/feedsmodelrootitem.h index fdb1046f5..416ee8b6d 100755 --- a/src/core/feedsmodelrootitem.h +++ b/src/core/feedsmodelrootitem.h @@ -37,6 +37,7 @@ class FeedsModelRootItem { virtual Kind kind() const; // Each item has icon. + QIcon icon() const; void setIcon(const QIcon &icon); // Each item has some kind of id. diff --git a/src/gui/feedsview.cpp b/src/gui/feedsview.cpp index 1b5e996bd..940da5d41 100644 --- a/src/gui/feedsview.cpp +++ b/src/gui/feedsview.cpp @@ -26,6 +26,14 @@ FeedsView::~FeedsView() { qDebug("Destroying FeedsView instance."); } +FeedsProxyModel *FeedsView::model() { + return m_proxyModel; +} + +FeedsModel *FeedsView::sourceModel() { + return m_sourceModel; +} + void FeedsView::setSortingEnabled(bool enable) { QTreeView::setSortingEnabled(enable); header()->setSortIndicatorShown(false); diff --git a/src/gui/feedsview.h b/src/gui/feedsview.h index f49f56b47..6002a0335 100644 --- a/src/gui/feedsview.h +++ b/src/gui/feedsview.h @@ -16,6 +16,9 @@ class FeedsView : public QTreeView { explicit FeedsView(QWidget *parent = 0); virtual ~FeedsView(); + FeedsProxyModel *model(); + FeedsModel *sourceModel(); + // Enables or disables sorting. void setSortingEnabled(bool enable); diff --git a/src/gui/formcategorydetails.cpp b/src/gui/formcategorydetails.cpp index ffa4ed019..b0fbaeba5 100644 --- a/src/gui/formcategorydetails.cpp +++ b/src/gui/formcategorydetails.cpp @@ -1,25 +1,63 @@ #include "gui/formcategorydetails.h" +#include "core/defs.h" +#include "core/feedsmodelrootitem.h" +#include "core/feedsmodelcategory.h" +#include "core/feedsmodel.h" #include "gui/iconthemefactory.h" #include "gui/feedsview.h" +#include + FormCategoryDetails::FormCategoryDetails(FeedsView *parent) : QDialog(parent) { - // Set flags and attributes. - setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog); - setWindowIcon(IconThemeFactory::getInstance()->fromTheme("document-new")); + initialize(parent); + loadCategories(parent->sourceModel()->getAllCategories().values(), + parent->sourceModel()->rootItem()); + + setWindowTitle(tr("Add new category")); } FormCategoryDetails::FormCategoryDetails(FeedsModelCategory *category, FeedsView *parent) - :QDialog(parent) { - // Set flags and attributes. - setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog); - setWindowIcon(IconThemeFactory::getInstance()->fromTheme("document-new")); + : QDialog(parent) { + initialize(parent); + loadCategories(parent->sourceModel()->getAllCategories().values(), + parent->sourceModel()->rootItem()); + setWindowTitle(tr("Edit existing category")); } FormCategoryDetails::~FormCategoryDetails() { qDebug("Destroying FormCategoryDetails instance."); } + +void FormCategoryDetails::initialize(FeedsView *view) { + m_ui = new Ui::FormCategoryDetails(); + m_ui->setupUi(this); + + // Set flags and attributes. + setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog); + setWindowIcon(IconThemeFactory::getInstance()->fromTheme("document-new")); + + // Add button for obtaining data about feed from internet. + m_btnObtainDetails = m_ui->m_buttonBox->addButton(tr("Get details via internet"), + QDialogButtonBox::ActionRole); + m_btnObtainDetails->setIcon(IconThemeFactory::getInstance()->fromTheme("document-save")); +} + +void FormCategoryDetails::loadCategories(const QList categories, + FeedsModelRootItem *root_item) { + m_ui->m_cmbParentCategory->addItem(root_item->icon(), + root_item->title(), + root_item->id()); + + foreach (FeedsModelCategory *category, categories) { + m_ui->m_cmbParentCategory->addItem(category->data(FDS_MODEL_TITLE_INDEX, + Qt::DecorationRole).value(), + category->title(), + category->id()); + } + +} diff --git a/src/gui/formcategorydetails.h b/src/gui/formcategorydetails.h index 527e13e02..9b2a52c3e 100644 --- a/src/gui/formcategorydetails.h +++ b/src/gui/formcategorydetails.h @@ -1,10 +1,17 @@ #ifndef FORMCATEGORYDETAILS_H #define FORMCATEGORYDETAILS_H +#include "ui_formcategorydetails.h" + #include +namespace Ui { + class FormSettings; +} + class FeedsModelCategory; +class FeedsModelRootItem; class FeedsView; class FormCategoryDetails : public QDialog { @@ -22,9 +29,16 @@ class FormCategoryDetails : public QDialog { // Destructor. virtual ~FormCategoryDetails(); - signals: + protected: + void initialize(FeedsView *view); - public slots: + // Loads categories into the dialog. + void loadCategories(const QList categories, + FeedsModelRootItem *root_item); + + private: + Ui::FormCategoryDetails *m_ui; + QPushButton *m_btnObtainDetails; }; diff --git a/src/gui/formcategorydetails.ui b/src/gui/formcategorydetails.ui new file mode 100644 index 000000000..cb4fbe73a --- /dev/null +++ b/src/gui/formcategorydetails.ui @@ -0,0 +1,126 @@ + + + FormCategoryDetails + + + + 0 + 0 + 362 + 183 + + + + Dialog + + + + + + + + Parent category + + + + + + + + + + Title + + + + + + + Title of the category + + + + + + + Description + + + + + + + Description of the category + + + + + + + Icon + + + + + + + + 40 + 40 + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + m_buttonBox + accepted() + FormCategoryDetails + accept() + + + 248 + 254 + + + 157 + 274 + + + + + m_buttonBox + rejected() + FormCategoryDetails + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/gui/formsettings.ui b/src/gui/formsettings.ui index 079030707..21c612b37 100644 --- a/src/gui/formsettings.ui +++ b/src/gui/formsettings.ui @@ -17,7 +17,7 @@ - 4 + 0 @@ -583,7 +583,7 @@ - 0 + 1 @@ -714,7 +714,7 @@ false - -1 + 0