#ifndef MESSAGESMODEL_H #define MESSAGESMODEL_H #include #include #include #include #include "core/defs.h" // Represents single message. // NOTE: This is primarily used for transfering data // to WebBrowser responsible for displaying of messages. class Message { private: QString m_title; QString m_url; QString m_author; QString m_contents; QDateTime m_updated; friend class WebBrowser; friend class MessagesModel; }; class MessagesModel : public QSqlTableModel { Q_OBJECT public: // Constructors and destructors. explicit MessagesModel(QObject *parent = 0); virtual ~MessagesModel(); // Model implementation. bool setData(const QModelIndex &idx, const QVariant &value, int role = Qt::EditRole); QVariant data(const QModelIndex &idx, int role = Qt::DisplayRole) const; QVariant data(int row, int column, int role = Qt::DisplayRole) const; QVariant headerData(int section, Qt::Orientation orientation, int role) const; Qt::ItemFlags flags(const QModelIndex &idx) const; public: // Sets up all icons which are used directly by this model. void setupIcons(); // Returns message at given index. Message messageAt(int row_index) const; public slots: // Message manipulators. bool switchMessageImportance(int row_index); bool setMessageDeleted(int row_index, int deleted); bool setMessageRead(int row_index, int read); // Fetches ALL available data to the model. // NOTE: This is almost always needed when sorting // and makes the model more predictable. void fetchAll(); // Loads messages of given feeds. void loadMessages(const QList feed_ids); private: // Sets up header data. void setupHeaderData(); // Creates "normal" and "bold" fonts. void setupFonts(); private: QList m_currentFeeds; QList m_headerData; bool m_isInEditingMode; QFont m_normalFont; QFont m_boldFont; QIcon m_favoriteIcon; QIcon m_readIcon; QIcon m_unreadIcon; }; #endif // MESSAGESMODEL_H