Merge lp:~osomon/webbrowser-app/lastVisit into lp:webbrowser-app

Proposed by Olivier Tilloy
Status: Merged
Approved by: Günter Schwann
Approved revision: 274
Merged at revision: 273
Proposed branch: lp:~osomon/webbrowser-app/lastVisit
Merge into: lp:webbrowser-app
Diff against target: 137 lines (+30/-17)
4 files modified
src/Ubuntu/Components/Extras/Browser/history-domain-model.cpp (+19/-4)
src/Ubuntu/Components/Extras/Browser/history-domain-model.h (+8/-1)
src/Ubuntu/Components/Extras/Browser/history-domainlist-model.cpp (+2/-11)
tests/unittests/history-domainlist-model/tst_HistoryDomainListModelTests.cpp (+1/-1)
To merge this branch: bzr merge lp:~osomon/webbrowser-app/lastVisit
Reviewer Review Type Date Requested Status
Günter Schwann (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+178790@code.launchpad.net

Commit message

Add a 'lastVisit' property to the HistoryDomainModel, update it accordingly, and use it in the HistoryDomainListModel.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Günter Schwann (schwann) wrote :

Looks good and works

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/Ubuntu/Components/Extras/Browser/history-domain-model.cpp'
--- src/Ubuntu/Components/Extras/Browser/history-domain-model.cpp 2013-08-06 10:18:18 +0000
+++ src/Ubuntu/Components/Extras/Browser/history-domain-model.cpp 2013-08-06 15:52:58 +0000
@@ -40,6 +40,11 @@
40HistoryDomainModel::HistoryDomainModel(QObject* parent)40HistoryDomainModel::HistoryDomainModel(QObject* parent)
41 : QSortFilterProxyModel(parent)41 : QSortFilterProxyModel(parent)
42{42{
43 connect(this, SIGNAL(layoutChanged(QList<QPersistentModelIndex>, QAbstractItemModel::LayoutChangeHint)), SLOT(onModelChanged()));
44 connect(this, SIGNAL(modelReset()), SLOT(onModelChanged()));
45 connect(this, SIGNAL(rowsInserted(QModelIndex, int, int)), SLOT(onModelChanged()));
46 connect(this, SIGNAL(rowsRemoved(QModelIndex, int, int)), SLOT(onModelChanged()));
47 connect(this, SIGNAL(dataChanged(QModelIndex, QModelIndex, QVector<int>)), SLOT(onModelChanged()));
43}48}
4449
45HistoryTimeframeModel* HistoryDomainModel::sourceModel() const50HistoryTimeframeModel* HistoryDomainModel::sourceModel() const
@@ -69,18 +74,28 @@
69 }74 }
70}75}
7176
72bool HistoryDomainModel::sourceEntryMatchesDomain(int row, const QModelIndex& parent) const77const QDateTime& HistoryDomainModel::lastVisit() const
78{
79 return m_lastVisit;
80}
81
82bool HistoryDomainModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
73{83{
74 if (m_domain.isEmpty()) {84 if (m_domain.isEmpty()) {
75 return true;85 return true;
76 }86 }
77 QModelIndex index = sourceModel()->index(row, 0, parent);87 QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
78 QUrl url = sourceModel()->data(index, HistoryModel::Url).toUrl();88 QUrl url = sourceModel()->data(index, HistoryModel::Url).toUrl();
79 QString domain = DomainUtils::extractTopLevelDomainName(url);89 QString domain = DomainUtils::extractTopLevelDomainName(url);
80 return (domain.compare(m_domain, Qt::CaseInsensitive) == 0);90 return (domain.compare(m_domain, Qt::CaseInsensitive) == 0);
81}91}
8292
83bool HistoryDomainModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const93void HistoryDomainModel::onModelChanged()
84{94{
85 return sourceEntryMatchesDomain(source_row, source_parent);95 if (rowCount() > 0) {
96 m_lastVisit = data(index(0, 0), HistoryModel::LastVisit).toDateTime();
97 } else {
98 m_lastVisit = QDateTime();
99 }
100 Q_EMIT lastVisitChanged();
86}101}
87102
=== modified file 'src/Ubuntu/Components/Extras/Browser/history-domain-model.h'
--- src/Ubuntu/Components/Extras/Browser/history-domain-model.h 2013-08-06 10:18:18 +0000
+++ src/Ubuntu/Components/Extras/Browser/history-domain-model.h 2013-08-06 15:52:58 +0000
@@ -20,6 +20,7 @@
20#define __HISTORY_DOMAIN_MODEL_H__20#define __HISTORY_DOMAIN_MODEL_H__
2121
22// Qt22// Qt
23#include <QtCore/QDateTime>
23#include <QtCore/QSortFilterProxyModel>24#include <QtCore/QSortFilterProxyModel>
24#include <QtCore/QString>25#include <QtCore/QString>
2526
@@ -31,6 +32,7 @@
3132
32 Q_PROPERTY(HistoryTimeframeModel* sourceModel READ sourceModel WRITE setSourceModel NOTIFY sourceModelChanged)33 Q_PROPERTY(HistoryTimeframeModel* sourceModel READ sourceModel WRITE setSourceModel NOTIFY sourceModelChanged)
33 Q_PROPERTY(QString domain READ domain WRITE setDomain NOTIFY domainChanged)34 Q_PROPERTY(QString domain READ domain WRITE setDomain NOTIFY domainChanged)
35 Q_PROPERTY(QDateTime lastVisit READ lastVisit NOTIFY lastVisitChanged)
3436
35public:37public:
36 HistoryDomainModel(QObject* parent=0);38 HistoryDomainModel(QObject* parent=0);
@@ -41,11 +43,12 @@
41 const QString& domain() const;43 const QString& domain() const;
42 void setDomain(const QString& domain);44 void setDomain(const QString& domain);
4345
44 bool sourceEntryMatchesDomain(int row, const QModelIndex& parent) const;46 const QDateTime& lastVisit() const;
4547
46Q_SIGNALS:48Q_SIGNALS:
47 void sourceModelChanged() const;49 void sourceModelChanged() const;
48 void domainChanged() const;50 void domainChanged() const;
51 void lastVisitChanged() const;
4952
50protected:53protected:
51 // reimplemented from QSortFilterProxyModel54 // reimplemented from QSortFilterProxyModel
@@ -53,6 +56,10 @@
5356
54private:57private:
55 QString m_domain;58 QString m_domain;
59 QDateTime m_lastVisit;
60
61private Q_SLOTS:
62 void onModelChanged();
56};63};
5764
58#endif // __HISTORY_DOMAIN_MODEL_H__65#endif // __HISTORY_DOMAIN_MODEL_H__
5966
=== modified file 'src/Ubuntu/Components/Extras/Browser/history-domainlist-model.cpp'
--- src/Ubuntu/Components/Extras/Browser/history-domainlist-model.cpp 2013-08-06 15:25:38 +0000
+++ src/Ubuntu/Components/Extras/Browser/history-domainlist-model.cpp 2013-08-06 15:52:58 +0000
@@ -75,17 +75,7 @@
75 case Domain:75 case Domain:
76 return domain;76 return domain;
77 case LastVisit:77 case LastVisit:
78 {78 return entries->lastVisit();
79 // At this point, entries might not have been filtered yet,
80 // so the first entry is not guaranteed to be the one we want.
81 int count = entries->rowCount();
82 for (int i = 0; i < count; ++i) {
83 if (entries->sourceEntryMatchesDomain(i, QModelIndex())) {
84 return entries->data(entries->index(i, 0), HistoryModel::LastVisit).toDateTime();
85 }
86 }
87 return QDateTime();
88 }
89 case Entries:79 case Entries:
90 return QVariant::fromValue(entries);80 return QVariant::fromValue(entries);
91 default:81 default:
@@ -179,6 +169,7 @@
179 connect(model, SIGNAL(layoutChanged(QList<QPersistentModelIndex>, QAbstractItemModel::LayoutChangeHint)), SLOT(onDomainDataChanged()));169 connect(model, SIGNAL(layoutChanged(QList<QPersistentModelIndex>, QAbstractItemModel::LayoutChangeHint)), SLOT(onDomainDataChanged()));
180 connect(model, SIGNAL(dataChanged(QModelIndex, QModelIndex)), SLOT(onDomainDataChanged()));170 connect(model, SIGNAL(dataChanged(QModelIndex, QModelIndex)), SLOT(onDomainDataChanged()));
181 connect(model, SIGNAL(modelReset()), SLOT(onDomainDataChanged()));171 connect(model, SIGNAL(modelReset()), SLOT(onDomainDataChanged()));
172 connect(model, SIGNAL(lastVisitChanged()), SLOT(onDomainDataChanged()));
182 m_domains.insert(domain, model);173 m_domains.insert(domain, model);
183}174}
184175
185176
=== modified file 'tests/unittests/history-domainlist-model/tst_HistoryDomainListModelTests.cpp'
--- tests/unittests/history-domainlist-model/tst_HistoryDomainListModelTests.cpp 2013-08-06 10:52:58 +0000
+++ tests/unittests/history-domainlist-model/tst_HistoryDomainListModelTests.cpp 2013-08-06 15:52:58 +0000
@@ -98,7 +98,7 @@
9898
99 history->add(QUrl("http://example.org/test.html"), "Test page", QUrl());99 history->add(QUrl("http://example.org/test.html"), "Test page", QUrl());
100 QVERIFY(spyRowsInserted.isEmpty());100 QVERIFY(spyRowsInserted.isEmpty());
101 QCOMPARE(spyDataChanged.count(), 1);101 QVERIFY(!spyDataChanged.isEmpty());
102 args = spyDataChanged.takeFirst();102 args = spyDataChanged.takeFirst();
103 QCOMPARE(args.at(0).toModelIndex().row(), 1);103 QCOMPARE(args.at(0).toModelIndex().row(), 1);
104 QCOMPARE(args.at(1).toModelIndex().row(), 1);104 QCOMPARE(args.at(1).toModelIndex().row(), 1);

Subscribers

People subscribed via source and target branches

to status/vote changes: