diff --git a/resources/misc/db_init.sql b/resources/misc/db_init.sql index e1ba478ee..70ca3009f 100644 --- a/resources/misc/db_init.sql +++ b/resources/misc/db_init.sql @@ -1,73 +1,75 @@ -DROP TABLE IF EXISTS Information; --- ! -CREATE TABLE IF NOT EXISTS Information ( - key TEXT PRIMARY KEY, - value TEXT NOT NULL -); --- ! -INSERT INTO Information VALUES ('schema_version', '0.0.1'); --- ! -DROP TABLE IF EXISTS Categories; --- ! -CREATE TABLE IF NOT EXISTS Categories ( - id INTEGER PRIMARY KEY, - parent_id INTEGER NOT NULL, - title TEXT NOT NULL UNIQUE CHECK (title != ''), - description TEXT, - date_created TEXT NOT NULL CHECK (date_created != ''), - icon BLOB, - type INTEGER NOT NULL, - - FOREIGN KEY (parent_id) REFERENCES Categories (id) -); --- ! -DROP TABLE IF EXISTS Feeds; --- ! -CREATE TABLE IF NOT EXISTS Feeds ( - id INTEGER PRIMARY KEY, - title TEXT NOT NULL CHECK (title != ''), - description TEXT, - date_created TEXT NOT NULL CHECK (date_created != ''), - icon BLOB, - category INTEGER NOT NULL CHECK (category >= -1), - encoding TEXT NOT NULL CHECK (encoding != ''), - url TEXT NOT NULL UNIQUE CHECK (url != ''), - language TEXT, - type INTEGER NOT NULL CHECK (type > 0) -); --- ! -DROP TABLE IF EXISTS FeedsData; --- ! -CREATE TABLE IF NOT EXISTS FeedsData ( - id INTEGER NOT NULL, - key TEXT NOT NULL, - value TEXT, - - PRIMARY KEY (id, key), - FOREIGN KEY (id) REFERENCES Feeds (id) -); --- ! -DROP TABLE IF EXISTS Messages; --- ! -CREATE TABLE IF NOT EXISTS Messages ( - id INTEGER PRIMARY KEY, - read INTEGER(1) NOT NULL CHECK (read >= 0 AND read <= 1) DEFAULT (0), - deleted INTEGER(1) NOT NULL CHECK (deleted >= 0 AND deleted <= 1) DEFAULT (0), - important INTEGER(1) NOT NULL CHECK (important >= 0 AND important <= 1) DEFAULT (0), - feed INTEGER NOT NULL, - title TEXT NOT NULL CHECK (title != ''), - url TEXT, - author TEXT, - date_created TEXT NOT NULL CHECK (date_created != ''), - date_updated TEXT, - contents TEXT, - - FOREIGN KEY (feed) REFERENCES Feeds (id) -); --- ! -INSERT INTO Feeds (title, date_created, category, encoding, url, type) VALUES ('abcd', '1994-11-05T08:15:30-05:00', -1, 'UTF-8', 'http://www.seznam1.cz', 1); -INSERT INTO Feeds (title, date_created, category, encoding, url, type) VALUES ('qqq', '1994-11-05T08:15:30-05:00', 0, 'UTF-8', 'http://www.seznam2.cz', 1); -INSERT INTO Feeds (title, date_created, category, encoding, url, type) VALUES ('vwvw', '1994-11-05T08:15:30-05:00', 1, 'UTF-8', 'http://www.seznam3.cz', 1); -INSERT INTO Feeds (title, date_created, category, encoding, url, type) VALUES ('tttt', '1994-11-05T08:15:30-05:00', 1, 'UTF-8', 'http://www.seznam4.cz', 1); -INSERT INTO Categories (id, parent_id, title, date_created, type) VALUES (0, -1, 'aaa', '1994-11-05T08:15:30-05:00', 0); -INSERT INTO Categories (id, parent_id, title, date_created, type) VALUES (1, 0, 'bbb', '1994-11-05T08:15:30-05:00', 0); \ No newline at end of file +DROP TABLE IF EXISTS Information; +-- ! +CREATE TABLE IF NOT EXISTS Information ( + key TEXT PRIMARY KEY, + value TEXT NOT NULL +); +-- ! +INSERT INTO Information VALUES ('schema_version', '0.0.1'); +-- ! +DROP TABLE IF EXISTS Categories; +-- ! +CREATE TABLE IF NOT EXISTS Categories ( + id INTEGER PRIMARY KEY, + parent_id INTEGER NOT NULL, + title TEXT NOT NULL UNIQUE CHECK (title != ''), + description TEXT, + date_created TEXT NOT NULL CHECK (date_created != ''), + icon BLOB, + type INTEGER NOT NULL, + + FOREIGN KEY (parent_id) REFERENCES Categories (id) +); +-- ! +DROP TABLE IF EXISTS Feeds; +-- ! +CREATE TABLE IF NOT EXISTS Feeds ( + id INTEGER PRIMARY KEY, + title TEXT NOT NULL CHECK (title != ''), + description TEXT, + date_created TEXT NOT NULL CHECK (date_created != ''), + icon BLOB, + category INTEGER NOT NULL CHECK (category >= -1), + encoding TEXT NOT NULL CHECK (encoding != ''), + url TEXT NOT NULL UNIQUE CHECK (url != ''), + language TEXT, + type INTEGER NOT NULL CHECK (type >= 0) +); +-- ! +DROP TABLE IF EXISTS FeedsData; +-- ! +CREATE TABLE IF NOT EXISTS FeedsData ( + id INTEGER NOT NULL, + key TEXT NOT NULL, + value TEXT, + + PRIMARY KEY (id, key), + FOREIGN KEY (id) REFERENCES Feeds (id) +); +-- ! +DROP TABLE IF EXISTS Messages; +-- ! +CREATE TABLE IF NOT EXISTS Messages ( + id INTEGER PRIMARY KEY, + read INTEGER(1) NOT NULL CHECK (read >= 0 AND read <= 1) DEFAULT (0), + deleted INTEGER(1) NOT NULL CHECK (deleted >= 0 AND deleted <= 1) DEFAULT (0), + important INTEGER(1) NOT NULL CHECK (important >= 0 AND important <= 1) DEFAULT (0), + feed INTEGER NOT NULL, + title TEXT NOT NULL CHECK (title != ''), + url TEXT, + author TEXT, + date_created TEXT NOT NULL CHECK (date_created != ''), + date_updated TEXT, + contents TEXT, + + FOREIGN KEY (feed) REFERENCES Feeds (id) +); +-- ! +INSERT INTO Feeds (title, date_created, category, encoding, url, type) VALUES ('qqq', '1994-11-05T08:15:30-05:00', 0, 'UTF-8', 'http://www.seznam2.cz', 1); +INSERT INTO Feeds (title, date_created, category, encoding, url, type) VALUES ('vwvw', '1994-11-05T08:15:30-05:00', 1, 'UTF-8', 'http://www.seznam3.cz', 1); +INSERT INTO Feeds (title, date_created, category, encoding, url, type) VALUES ('cbcd', '1994-11-05T08:15:30-05:00', -1, 'UTF-8', 'http://www.seznam1.cz', 1); +INSERT INTO Feeds (title, date_created, category, encoding, url, type) VALUES ('attt', '1994-11-05T08:15:30-05:00', 1, 'UTF-8', 'http://www.seznam4.cz', 0); +INSERT INTO Feeds (title, date_created, category, encoding, url, type) VALUES ('ahht', '1994-11-05T08:15:30-05:00', -1, 'UTF-8', 'http://www.seznam6.cz', 0); +INSERT INTO Categories (id, parent_id, title, date_created, type) VALUES (1, 0, 'bbb', '1994-11-05T08:15:30-05:00', 0); +INSERT INTO Categories (id, parent_id, title, date_created, type) VALUES (0, -1, 'aaa', '1994-11-05T08:15:30-05:00', 0); +INSERT INTO Categories (id, parent_id, title, date_created, type) VALUES (2, 0, 'ccc', '1994-11-05T08:15:30-05:00', 0); \ No newline at end of file diff --git a/src/core/databasefactory.cpp b/src/core/databasefactory.cpp index b62ffccca..66259ef07 100644 --- a/src/core/databasefactory.cpp +++ b/src/core/databasefactory.cpp @@ -135,6 +135,11 @@ QSqlDatabase DatabaseFactory::addConnection(const QString &connection_name) { // Setup database file path. database.setDatabaseName(db_file.fileName()); + if (!database.open()) { + qFatal("Database was NOT opened. Delivered error message: '%s'", + qPrintable(database.lastError().text())); + } + return database; } } diff --git a/src/core/databasefactory.h b/src/core/databasefactory.h index 08585ef46..3e8dfb33d 100644 --- a/src/core/databasefactory.h +++ b/src/core/databasefactory.h @@ -37,6 +37,8 @@ class DatabaseFactory : public QObject { QString getDatabasePath(); // Database manipulators. + + // NOTE: This returns OPENED database. QSqlDatabase addConnection(const QString &connection_name); QSqlDatabase getConnection(const QString &connection_name); void removeConnection(const QString &connection_name); diff --git a/src/core/defs.h.in b/src/core/defs.h.in index 21d060c6e..e90eb9024 100755 --- a/src/core/defs.h.in +++ b/src/core/defs.h.in @@ -26,6 +26,8 @@ #define MAX_ZOOM_FACTOR 10.0 #define ICON_SIZE_SETTINGS 16 #define DATABASE_DRIVER "QSQLITE" +#define NO_PARENT_FEED -1 +#define NO_PARENT_CATEGORY -1 #define APP_DB_INIT_FILE "db_init.sql" #define APP_DB_INIT_SPLIT "-- !\n" diff --git a/src/core/feedsmodel.cpp b/src/core/feedsmodel.cpp index d810026a0..53f6fcc7d 100644 --- a/src/core/feedsmodel.cpp +++ b/src/core/feedsmodel.cpp @@ -9,6 +9,7 @@ #include "core/defs.h" #include "core/databasefactory.h" #include "gui/iconthemefactory.h" +#include "gui/iconfactory.h" FeedsModel::FeedsModel(QObject *parent) : QAbstractItemModel(parent) { @@ -22,7 +23,7 @@ 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(); @@ -46,11 +47,13 @@ FeedsModel::FeedsModel(QObject *parent) : QAbstractItemModel(parent) { m_rootItem->appendChild(cat1); m_rootItem->appendChild(feed3); + */ } FeedsModel::~FeedsModel() { qDebug("Destroying FeedsModel instance."); delete m_rootItem; + DatabaseFactory::getInstance()->removeConnection(objectName()); } QVariant FeedsModel::data(const QModelIndex &index, int role) const { @@ -161,15 +164,13 @@ int FeedsModel::columnCount(const QModelIndex &parent) const { } void FeedsModel::loadFromDatabase() { + qDeleteAll(m_rootItem->m_childItems); + QSqlDatabase database = DatabaseFactory::getInstance()->addConnection(objectName()); - QList > categories; - QList > feeds; - - if (!database.open()) { - qFatal("Database was NOT opened. Delivered error message: '%s'", - qPrintable(database.lastError().text())); - } + CategoryAssignment categories; + FeedAssignment feeds; + // Obtain data for categories from the database. QSqlQuery query_categories = database.exec("SELECT * FROM Categories;"); if (query_categories.lastError().isValid()) { @@ -182,7 +183,7 @@ void FeedsModel::loadFromDatabase() { switch (type) { case FeedsModelCategory::Standard: { - QPair pair; + CategoryAssignmentItem pair; pair.first = query_categories.value(CAT_DB_PARENT_ID_INDEX).toInt(); pair.second = FeedsModelStandardCategory::loadFromRecord(query_categories.record()); @@ -213,17 +214,82 @@ void FeedsModel::loadFromDatabase() { case FeedsModelFeed::StandardAtom: case FeedsModelFeed::StandardRdf: case FeedsModelFeed::StandardRss: { - QPair pair; + FeedAssignmentItem pair; pair.first = query_feeds.value(FDS_DB_CATEGORY_INDEX).toInt(); - // TODO: pokračovat tady, ve stejnym stylu jako u kategorii + pair.second = FeedsModelStandardFeed::loadFromRecord(query_feeds.record()); + pair.second->setType(type); + + feeds << pair; break; } - default: break; } - } + // All data are now obtained, lets create the hierarchy. + assembleCategories(categories); + assembleFeeds(feeds); +} + +QHash FeedsModel::getCategories(FeedsModelRootItem *root) { + QHash categories; + + foreach (FeedsModelRootItem *child, root->m_childItems) { + FeedsModelCategory *converted = dynamic_cast(child); + + if (converted != NULL) { + // This child is some kind of category. + categories.insert(converted->id(), converted); + + // Moreover, add all child categories of this category. + categories.unite(getCategories(converted)); + } + } + + return categories; +} + +QHash FeedsModel::getCategories() { + return getCategories(m_rootItem); +} + +void FeedsModel::assembleFeeds(FeedAssignment feeds) { + QHash categories = getCategories(); + + foreach (FeedAssignmentItem feed, feeds) { + if (feed.first == NO_PARENT_CATEGORY) { + // This is top-level feed, add it to the root item. + m_rootItem->appendChild(feed.second); + } + else { + // This feed belongs to some category. + categories.value(feed.first)->appendChild(feed.second); + } + } +} + +void FeedsModel::assembleCategories(CategoryAssignment categories) { + QHash assignments; + assignments.insert(-1, m_rootItem); + + // Add top-level categories. + while (!categories.isEmpty()) { + for (int i = 0; i < categories.size(); i++) { + if (assignments.contains(categories.at(i).first)) { + // Parent category of this category is already added. + assignments.value(categories.at(i).first)->appendChild(categories.at(i).second); + + // Now, added category can be parent for another categories, add it. + assignments.insert(categories.at(i).second->id(), + categories.at(i).second); + + // Remove the category from the list, because it was + // added to the final collection. + categories.removeAt(i); + i--; + } + } + } } diff --git a/src/core/feedsmodel.h b/src/core/feedsmodel.h index d429e5b87..19a3c45c4 100644 --- a/src/core/feedsmodel.h +++ b/src/core/feedsmodel.h @@ -6,6 +6,13 @@ class FeedsModelRootItem; +class FeedsModelCategory; +class FeedsModelFeed; + +typedef QList > CategoryAssignment; +typedef QPair CategoryAssignmentItem; +typedef QList > FeedAssignment; +typedef QPair FeedAssignmentItem; class FeedsModel : public QAbstractItemModel { Q_OBJECT @@ -24,6 +31,15 @@ class FeedsModel : public QAbstractItemModel { void loadFromDatabase(); + QHash getCategories(); + QHash getCategories(FeedsModelRootItem *root); + + bool addFeed(FeedsModelFeed *feed, int parent_id); + + protected: + void assembleCategories(CategoryAssignment categories); + void assembleFeeds(FeedAssignment feeds); + private: FeedsModelRootItem *m_rootItem; QList m_headerData; diff --git a/src/core/feedsmodelcategory.cpp b/src/core/feedsmodelcategory.cpp index c6a97cc7b..96a05a3a1 100644 --- a/src/core/feedsmodelcategory.cpp +++ b/src/core/feedsmodelcategory.cpp @@ -35,3 +35,11 @@ FeedsModelCategory:: Type FeedsModelCategory::type() const { void FeedsModelCategory::setType(const Type &type) { m_type = type; } + +QString FeedsModelCategory::title() const { + return m_title; +} + +void FeedsModelCategory::setTitle(const QString &title) { + m_title = title; +} diff --git a/src/core/feedsmodelcategory.h b/src/core/feedsmodelcategory.h index 8bbbf7bca..0ce01d97d 100644 --- a/src/core/feedsmodelcategory.h +++ b/src/core/feedsmodelcategory.h @@ -26,9 +26,12 @@ class FeedsModelCategory : public FeedsModelRootItem { Type type() const; void setType(const Type &type); - protected: - Type m_type; + QString title() const; + void setTitle(const QString &title); + protected: + QString m_title; + Type m_type; }; #endif // FEEDSMODELCLASSICCATEGORY_H diff --git a/src/core/feedsmodelfeed.cpp b/src/core/feedsmodelfeed.cpp index a8d86c16f..85e77ad5e 100644 --- a/src/core/feedsmodelfeed.cpp +++ b/src/core/feedsmodelfeed.cpp @@ -2,7 +2,7 @@ FeedsModelFeed::FeedsModelFeed(FeedsModelRootItem *parent_item) - : FeedsModelRootItem(parent_item), m_totalCount(0), m_unreadCount(1) { + : FeedsModelRootItem(parent_item), m_totalCount(0), m_unreadCount(0) { } FeedsModelFeed::~FeedsModelFeed() { @@ -38,3 +38,10 @@ void FeedsModelFeed::setType(const Type &type) { m_type = type; } +void FeedsModelFeed::setTitle(const QString &title) { + m_title = title; +} + +QString FeedsModelFeed::title() const { + return m_title; +} diff --git a/src/core/feedsmodelfeed.h b/src/core/feedsmodelfeed.h index 2818bf192..0423b0f93 100644 --- a/src/core/feedsmodelfeed.h +++ b/src/core/feedsmodelfeed.h @@ -30,7 +30,11 @@ class FeedsModelFeed : public FeedsModelRootItem { Type type() const; void setType(const Type &type); + QString title() const; + void setTitle(const QString &title); + protected: + QString m_title; Type m_type; int m_totalCount; int m_unreadCount; diff --git a/src/core/feedsmodelrootitem.h b/src/core/feedsmodelrootitem.h index 551c3a33f..36d01bc23 100644 --- a/src/core/feedsmodelrootitem.h +++ b/src/core/feedsmodelrootitem.h @@ -8,6 +8,8 @@ // NOTE: This class is derived to add functionality for // all other non-root items of FeedsModel. class FeedsModelRootItem { + friend class FeedsModel; + public: // Constructors and destructors. explicit FeedsModelRootItem(FeedsModelRootItem *parent_item = NULL); diff --git a/src/core/feedsmodelstandardcategory.cpp b/src/core/feedsmodelstandardcategory.cpp index 63ac623a2..00e571266 100644 --- a/src/core/feedsmodelstandardcategory.cpp +++ b/src/core/feedsmodelstandardcategory.cpp @@ -19,7 +19,7 @@ QVariant FeedsModelStandardCategory::data(int column, int role) const { switch (role) { case Qt::DisplayRole: if (column == FDS_MODEL_TITLE_INDEX) { - return "m_title"; + return QString("%1%2").arg(m_title, "-C"); } else if (column == FDS_MODEL_COUNTS_INDEX) { return QString("(%1)").arg(QString::number(countOfUnreadMessages())); @@ -56,14 +56,6 @@ FeedsModelStandardCategory *FeedsModelStandardCategory::loadFromRecord(const QSq return category; } -QString FeedsModelStandardCategory::title() const { - return m_title; -} - -void FeedsModelStandardCategory::setTitle(const QString &title) { - m_title = title; -} - QString FeedsModelStandardCategory::description() const { return m_description; } @@ -79,6 +71,3 @@ QDateTime FeedsModelStandardCategory::creationDate() const { void FeedsModelStandardCategory::setCreationDate(const QDateTime &creation_date) { m_creationDate = creation_date; } - - - diff --git a/src/core/feedsmodelstandardcategory.h b/src/core/feedsmodelstandardcategory.h index b87c04229..40d60d05b 100644 --- a/src/core/feedsmodelstandardcategory.h +++ b/src/core/feedsmodelstandardcategory.h @@ -20,20 +20,16 @@ class FeedsModelStandardCategory : public FeedsModelCategory { QVariant data(int column, int role) const; - static FeedsModelStandardCategory *loadFromRecord(const QSqlRecord &record); - - QString title() const; - void setTitle(const QString &title); - QString description() const; void setDescription(const QString &description); QDateTime creationDate() const; void setCreationDate(const QDateTime &creation_date); + static FeedsModelStandardCategory *loadFromRecord(const QSqlRecord &record); + private: QDateTime m_creationDate; - QString m_title; QString m_description; }; diff --git a/src/core/feedsmodelstandardfeed.cpp b/src/core/feedsmodelstandardfeed.cpp index f16ee673f..a06b67b11 100644 --- a/src/core/feedsmodelstandardfeed.cpp +++ b/src/core/feedsmodelstandardfeed.cpp @@ -1,6 +1,7 @@ #include #include "core/defs.h" +#include "gui/iconfactory.h" #include "gui/iconthemefactory.h" #include "core/feedsmodelstandardfeed.h" @@ -17,8 +18,56 @@ void FeedsModelStandardFeed::setDescription(const QString &description) { m_description = description; } -void FeedsModelStandardFeed::setTitle(const QString &title) { - m_title = title; +FeedsModelStandardFeed *FeedsModelStandardFeed::loadFromRecord(const QSqlRecord &record) { + FeedsModelStandardFeed *feed = new FeedsModelStandardFeed(NULL); + + feed->setTitle(record.value(FDS_DB_TITLE_INDEX).toString()); + feed->setId(record.value(FDS_DB_ID_INDEX).toInt()); + feed->setDescription(record.value(FDS_DB_DESCRIPTION_INDEX).toString()); + feed->setCreationDate(QDateTime::fromString(record.value(FDS_DB_DCREATED_INDEX).toString(), + Qt::ISODate)); + 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()); + + return feed; +} + +QDateTime FeedsModelStandardFeed::creationDate() const { + return m_creationDate; +} + +void FeedsModelStandardFeed::setCreationDate(const QDateTime &creation_date) { + m_creationDate = creation_date; +} + +QString FeedsModelStandardFeed::encoding() const { + return m_encoding; +} + +void FeedsModelStandardFeed::setEncoding(const QString &encoding) { + m_encoding = encoding; +} + +QString FeedsModelStandardFeed::url() const { + return m_url; +} + +void FeedsModelStandardFeed::setUrl(const QString &url) { + m_url = url; +} + +QString FeedsModelStandardFeed::language() const { + return m_language; +} + +void FeedsModelStandardFeed::setLanguage(const QString &language) { + m_language = language; +} + +QString FeedsModelStandardFeed::description() const { + return m_description; } QVariant FeedsModelStandardFeed::data(int column, int role) const { diff --git a/src/core/feedsmodelstandardfeed.h b/src/core/feedsmodelstandardfeed.h index 0ff214b12..38e2bcba5 100644 --- a/src/core/feedsmodelstandardfeed.h +++ b/src/core/feedsmodelstandardfeed.h @@ -2,6 +2,7 @@ #define FEEDSMODELSTANDARDFEED_H #include +#include #include "core/feedsmodelfeed.h" @@ -17,11 +18,25 @@ class FeedsModelStandardFeed : public FeedsModelFeed { QVariant data(int column, int role) const; - void setTitle(const QString &title); + // Various getters/setters. + QString description() const; void setDescription(const QString &description); + QDateTime creationDate() const; + void setCreationDate(const QDateTime &creation_date); + + QString encoding() const; + void setEncoding(const QString &encoding); + + QString url() const; + void setUrl(const QString &url); + + QString language() const; + void setLanguage(const QString &language); + + static FeedsModelStandardFeed *loadFromRecord(const QSqlRecord &record); + private: - QString m_title; QDateTime m_creationDate; QString m_encoding; QString m_url; diff --git a/src/core/feedsproxymodel.cpp b/src/core/feedsproxymodel.cpp index 6a3a27408..20cd2a3a8 100644 --- a/src/core/feedsproxymodel.cpp +++ b/src/core/feedsproxymodel.cpp @@ -1,5 +1,8 @@ #include "core/feedsproxymodel.h" #include "core/feedsmodel.h" +#include "core/feedsmodelcategory.h" +#include "core/feedsmodelfeed.h" +#include "core/feedsmodelrootitem.h" FeedsProxyModel::FeedsProxyModel(QObject *parent) @@ -8,7 +11,13 @@ FeedsProxyModel::FeedsProxyModel(QObject *parent) - + setObjectName("FeedsProxyModel"); + setSortRole(Qt::EditRole); + setSortCaseSensitivity(Qt::CaseInsensitive); + setFilterCaseSensitivity(Qt::CaseInsensitive); + setFilterKeyColumn(-1); + setFilterRole(Qt::EditRole); + setDynamicSortFilter(true); setSourceModel(m_sourceModel); } @@ -22,5 +31,37 @@ FeedsModel *FeedsProxyModel::sourceModel() { bool FeedsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const { - return QSortFilterProxyModel::lessThan(left, right); + if (left.isValid() && right.isValid()) { + FeedsModelRootItem *left_item = static_cast(left.internalPointer()); + FeedsModelRootItem *right_item = static_cast(right.internalPointer()); + + FeedsModelFeed *left_feed = dynamic_cast(left_item); + FeedsModelFeed *right_feed = dynamic_cast(right_item); + + FeedsModelCategory *left_category = dynamic_cast(left_item); + FeedsModelCategory *right_category = dynamic_cast(right_item); + + if (left_feed != NULL && right_feed != NULL) { + // Both items are feeds. + return left_feed->title() < right_feed->title(); + } + else if (left_category != NULL && right_category != NULL) { + // Both items are categories. + return left_category->title() < right_category->title(); + } + else if (left_feed != NULL) { + // Left item is feed, right item is category. + return false; + } + else { + // Left item is category, right item is feed. + return true; + } + + + return true; + } + else { + return false; + } } diff --git a/src/gui/feedsview.cpp b/src/gui/feedsview.cpp index ca0ee7d8a..ded1110bf 100644 --- a/src/gui/feedsview.cpp +++ b/src/gui/feedsview.cpp @@ -18,6 +18,11 @@ FeedsView::~FeedsView() { qDebug("Destroying FeedsView instance."); } +void FeedsView::setSortingEnabled(bool enable) { + QTreeView::setSortingEnabled(enable); + header()->setSortIndicatorShown(false); +} + void FeedsView::setupAppearance() { #if QT_VERSION >= 0x050000 // Setup column resize strategies. @@ -33,6 +38,8 @@ void FeedsView::setupAppearance() { setUniformRowHeights(true); setAcceptDrops(false); setDragEnabled(false); + setSortingEnabled(true); + sortByColumn(0, Qt::AscendingOrder); setDragDropMode(QAbstractItemView::NoDragDrop); setAllColumnsShowFocus(true); setSelectionMode(QAbstractItemView::ExtendedSelection); diff --git a/src/gui/feedsview.h b/src/gui/feedsview.h index c6c4cb1ce..29b7bb234 100644 --- a/src/gui/feedsview.h +++ b/src/gui/feedsview.h @@ -14,6 +14,8 @@ class FeedsView : public QTreeView { // Constructors and destructors. explicit FeedsView(QWidget *parent = 0); virtual ~FeedsView(); + + void setSortingEnabled(bool enable); protected: void setupAppearance(); diff --git a/src/main.cpp b/src/main.cpp index 5a8bb2ed1..55b591274 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,7 +30,8 @@ int main(int argc, char *argv[]) { //: Name of language, e.g. English. QObject::tr("LANG_NAME"); //: Abbreviation of language, e.g. en. - //: Use ISO 639-1 code here! + //: Use ISO 639-1 code here. They may be combined with ISO 3166-1 (alpha-2) codes. + //: Examples: "cs", "nl", "en", "cs_CZ", "en_GB", "en_US". QObject::tr("LANG_ABBREV"); //: Version of your translation, e.g. 1.0. QObject::tr("LANG_VERSION"); @@ -61,13 +62,6 @@ int main(int argc, char *argv[]) { return EXIT_SUCCESS; } - // Add 3rd party plugin directory to application PATH variable. - // This is useful for styles, encoders, ... - // This is probably not needed on Windows or Linux, not sure about Mac OS X. -#if defined(Q_OS_MAC) - QtSingleApplication::addLibraryPath(APP_PLUGIN_PATH); -#endif - // Add an extra path for non-system icon themes and set current icon theme // and skin. IconThemeFactory::getInstance()->setupSearchPaths();