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 current_row = index.row();
68 content = new ContentWindow(this, e);
70 connect(content, SIGNAL(showNextEntry()), SLOT(showNextEntry()));
71 connect(content, SIGNAL(showPrevEntry()), SLOT(showPrevEntry()));
76 void EntriesWindow::showNextEntry() {
77 QAbstractListModel *model = static_cast<QAbstractListModel *>(list->model());
78 if(current_row + 1 < model->rowCount()) {
80 content->showEntry(qVariantValue<Entry *>(model->index(current_row).data()));
84 void EntriesWindow::showPrevEntry() {
85 QAbstractListModel *model = static_cast<QAbstractListModel *>(list->model());
88 content->showEntry(qVariantValue<Entry *>(model->index(current_row).data()));
92 int EntryListModel::rowCount(const QModelIndex &) const {
96 for(int i = 0; i < entry_list.size(); i++) {
97 if((entry_list.at(i)->flags & ENTRY_FLAG_READ) == 0)
102 size = entry_list.size();
107 QVariant EntryListModel::data(const QModelIndex &index, int role) const {
111 if(index.row() >= rowCount() || index.row() < 0) {
115 if(role == Qt::DisplayRole) {
118 for(i = 0, j = 0; i < entry_list.size(); i++) {
119 if((entry_list.at(i)->flags & ENTRY_FLAG_READ) == 0) j++;
121 return qVariantFromValue(entry_list.at(i));
125 return qVariantFromValue(entry_list.at(index.row()));
131 void EntryListModel::showUpdated(bool updated) {
133 show_updated = updated;
137 void EntryListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
138 const QModelIndex &index) const {
140 QStyledItemDelegate::paint(painter, option, index);
142 Entry *e = qVariantValue<Entry *>(index.data());
144 QFont font = option.font;
145 QRect rect = option.rect;
146 rect.adjust(20, 8, -20, -8);
147 QPoint topleft = rect.topLeft();
148 QPoint bottomleft = rect.bottomLeft();
149 rect.adjust(36, 0, 0, 0);
153 if(((e->flags & ENTRY_FLAG_READ) == 0) &&
154 !(option.state & QStyle::State_Selected)) {
155 painter->setPen(option.palette.highlight().color());
158 painter->drawText(rect, Qt::AlignTop | Qt::AlignLeft, e->title);
160 painter->setPen(option.palette.mid().color());
161 font.setPointSizeF(font.pointSizeF() * 0.70);
162 painter->setFont(font);
164 painter->drawText(rect, Qt::AlignBottom | Qt::AlignLeft, e->author);
167 if(e->published.date() == QDateTime::currentDateTime().date())
168 date = e->published.time().toString(Qt::DefaultLocaleShortDate);
170 date = e->published.date().toString();
172 painter->drawText(rect, Qt::AlignBottom | Qt::AlignRight, date);
174 if(e->flags & ENTRY_FLAG_STARRED) {
175 QImage img = QImage(QLatin1String(":/images/star-1"));
176 painter->drawImage(topleft, img);
179 if(e->flags & ENTRY_FLAG_SHARED) {
180 QImage img = QImage(QLatin1String(":/images/shared-1"));
181 bottomleft.ry() -= img.height();
182 painter->drawImage(bottomleft, img);