4 #include "entrieswindow.h"
5 #include "contentwindow.h"
7 EntriesWindow::EntriesWindow(QWidget *parent, Feed *f) : QMainWindow(parent) {
8 setAttribute(Qt::WA_Maemo5StackedWindow);
12 menuBar()->addAction(tr("Fetch more"), this, SLOT(sync()));
13 menuBar()->addAction(tr("Mark all as read"), this, SLOT(markRead()));
15 QActionGroup *filter_group = new QActionGroup(this);
16 show_all = new QAction(tr("Show All"), filter_group);
17 show_all->setCheckable(true);
18 show_all->setChecked(true);
19 show_updated = new QAction(tr("Show Updated"), filter_group);
20 show_updated->setCheckable(true);
21 menuBar()->addActions(filter_group->actions());
23 setWindowTitle(f->title);
25 list = new QListView();
26 setCentralWidget(list);
27 list->setItemDelegate(new EntryListDelegate(this));
29 connect(list, SIGNAL(activated(const QModelIndex &)),
30 SLOT(entrySelected(const QModelIndex &)));
32 connect(feed, SIGNAL(updateFeedComplete()),
33 SLOT(entriesUpdated()));
35 if(feed->getEntriesSize() == 0 || feed->lastUpdated < feed->reader->lastUpdated)
41 EntriesWindow::~EntriesWindow() {
44 void EntriesWindow::sync() {
45 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
46 feed->fetch(feed->lastUpdated > feed->reader->lastUpdated);
49 void EntriesWindow::markRead() {
53 void EntriesWindow::entriesUpdated() {
54 QList<Entry *>entries = feed->getEntries();
55 QAbstractItemModel *old_model = list->model();
56 EntryListModel *new_model = new EntryListModel(this, entries, show_updated->isChecked());
57 list->setModel(new_model);
58 connect(show_updated, SIGNAL(toggled(bool)), new_model, SLOT(showUpdated(bool)));
60 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
63 void EntriesWindow::entrySelected(const QModelIndex &index) {
64 Entry *e = qVariantValue<Entry *>(index.data());
66 ContentWindow *w = new ContentWindow(this, e);
70 int EntryListModel::rowCount(const QModelIndex &) const {
74 for(int i = 0; i < entry_list.size(); i++) {
75 if((entry_list.at(i)->flags & ENTRY_FLAG_READ) == 0)
80 size = entry_list.size();
85 QVariant EntryListModel::data(const QModelIndex &index, int role) const {
89 if(index.row() >= rowCount() || index.row() < 0) {
93 if(role == Qt::DisplayRole) {
96 for(i = 0, j = 0; i < entry_list.size(); i++) {
97 if((entry_list.at(i)->flags & ENTRY_FLAG_READ) == 0) j++;
99 return qVariantFromValue(entry_list.at(i));
103 return qVariantFromValue(entry_list.at(index.row()));
109 void EntryListModel::showUpdated(bool updated) {
111 show_updated = updated;
115 void EntryListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
116 const QModelIndex &index) const {
118 QStyledItemDelegate::paint(painter, option, index);
120 Entry *e = qVariantValue<Entry *>(index.data());
122 QFont font = option.font;
123 QRect rect = option.rect;
124 rect.adjust(20, 8, -20, -8);
125 QPoint topleft = rect.topLeft();
127 rect.adjust(36, 0, 0, 0);
131 if(((e->flags & ENTRY_FLAG_READ) == 0) &&
132 !(option.state & QStyle::State_Selected)) {
133 painter->setPen(option.palette.highlight().color());
136 painter->drawText(rect, Qt::AlignTop | Qt::AlignLeft, e->title);
138 painter->setPen(option.palette.mid().color());
139 font.setPointSizeF(font.pointSizeF() * 0.70);
140 painter->setFont(font);
142 painter->drawText(rect, Qt::AlignBottom | Qt::AlignLeft, e->author);
145 if(e->published.date() == QDateTime::currentDateTime().date())
146 date = e->published.time().toString(Qt::DefaultLocaleShortDate);
148 date = e->published.date().toString();
150 painter->drawText(rect, Qt::AlignBottom | Qt::AlignRight, date);
152 if(e->flags & ENTRY_FLAG_STARRED) {
153 QImage img = QImage(QLatin1String(":/images/star-1"));
154 painter->drawImage(topleft, img);