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 000000000..2d46b788a Binary files /dev/null and b/resources/graphics/icons/mini-kfaenza/folder-red.png differ 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