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
1=== modified file 'src/Ubuntu/Components/Extras/Browser/history-domain-model.cpp'
2--- src/Ubuntu/Components/Extras/Browser/history-domain-model.cpp 2013-08-06 10:18:18 +0000
3+++ src/Ubuntu/Components/Extras/Browser/history-domain-model.cpp 2013-08-06 15:52:58 +0000
4@@ -40,6 +40,11 @@
5 HistoryDomainModel::HistoryDomainModel(QObject* parent)
6 : QSortFilterProxyModel(parent)
7 {
8+ connect(this, SIGNAL(layoutChanged(QList<QPersistentModelIndex>, QAbstractItemModel::LayoutChangeHint)), SLOT(onModelChanged()));
9+ connect(this, SIGNAL(modelReset()), SLOT(onModelChanged()));
10+ connect(this, SIGNAL(rowsInserted(QModelIndex, int, int)), SLOT(onModelChanged()));
11+ connect(this, SIGNAL(rowsRemoved(QModelIndex, int, int)), SLOT(onModelChanged()));
12+ connect(this, SIGNAL(dataChanged(QModelIndex, QModelIndex, QVector<int>)), SLOT(onModelChanged()));
13 }
14
15 HistoryTimeframeModel* HistoryDomainModel::sourceModel() const
16@@ -69,18 +74,28 @@
17 }
18 }
19
20-bool HistoryDomainModel::sourceEntryMatchesDomain(int row, const QModelIndex& parent) const
21+const QDateTime& HistoryDomainModel::lastVisit() const
22+{
23+ return m_lastVisit;
24+}
25+
26+bool HistoryDomainModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
27 {
28 if (m_domain.isEmpty()) {
29 return true;
30 }
31- QModelIndex index = sourceModel()->index(row, 0, parent);
32+ QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
33 QUrl url = sourceModel()->data(index, HistoryModel::Url).toUrl();
34 QString domain = DomainUtils::extractTopLevelDomainName(url);
35 return (domain.compare(m_domain, Qt::CaseInsensitive) == 0);
36 }
37
38-bool HistoryDomainModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
39+void HistoryDomainModel::onModelChanged()
40 {
41- return sourceEntryMatchesDomain(source_row, source_parent);
42+ if (rowCount() > 0) {
43+ m_lastVisit = data(index(0, 0), HistoryModel::LastVisit).toDateTime();
44+ } else {
45+ m_lastVisit = QDateTime();
46+ }
47+ Q_EMIT lastVisitChanged();
48 }
49
50=== modified file 'src/Ubuntu/Components/Extras/Browser/history-domain-model.h'
51--- src/Ubuntu/Components/Extras/Browser/history-domain-model.h 2013-08-06 10:18:18 +0000
52+++ src/Ubuntu/Components/Extras/Browser/history-domain-model.h 2013-08-06 15:52:58 +0000
53@@ -20,6 +20,7 @@
54 #define __HISTORY_DOMAIN_MODEL_H__
55
56 // Qt
57+#include <QtCore/QDateTime>
58 #include <QtCore/QSortFilterProxyModel>
59 #include <QtCore/QString>
60
61@@ -31,6 +32,7 @@
62
63 Q_PROPERTY(HistoryTimeframeModel* sourceModel READ sourceModel WRITE setSourceModel NOTIFY sourceModelChanged)
64 Q_PROPERTY(QString domain READ domain WRITE setDomain NOTIFY domainChanged)
65+ Q_PROPERTY(QDateTime lastVisit READ lastVisit NOTIFY lastVisitChanged)
66
67 public:
68 HistoryDomainModel(QObject* parent=0);
69@@ -41,11 +43,12 @@
70 const QString& domain() const;
71 void setDomain(const QString& domain);
72
73- bool sourceEntryMatchesDomain(int row, const QModelIndex& parent) const;
74+ const QDateTime& lastVisit() const;
75
76 Q_SIGNALS:
77 void sourceModelChanged() const;
78 void domainChanged() const;
79+ void lastVisitChanged() const;
80
81 protected:
82 // reimplemented from QSortFilterProxyModel
83@@ -53,6 +56,10 @@
84
85 private:
86 QString m_domain;
87+ QDateTime m_lastVisit;
88+
89+private Q_SLOTS:
90+ void onModelChanged();
91 };
92
93 #endif // __HISTORY_DOMAIN_MODEL_H__
94
95=== modified file 'src/Ubuntu/Components/Extras/Browser/history-domainlist-model.cpp'
96--- src/Ubuntu/Components/Extras/Browser/history-domainlist-model.cpp 2013-08-06 15:25:38 +0000
97+++ src/Ubuntu/Components/Extras/Browser/history-domainlist-model.cpp 2013-08-06 15:52:58 +0000
98@@ -75,17 +75,7 @@
99 case Domain:
100 return domain;
101 case LastVisit:
102- {
103- // At this point, entries might not have been filtered yet,
104- // so the first entry is not guaranteed to be the one we want.
105- int count = entries->rowCount();
106- for (int i = 0; i < count; ++i) {
107- if (entries->sourceEntryMatchesDomain(i, QModelIndex())) {
108- return entries->data(entries->index(i, 0), HistoryModel::LastVisit).toDateTime();
109- }
110- }
111- return QDateTime();
112- }
113+ return entries->lastVisit();
114 case Entries:
115 return QVariant::fromValue(entries);
116 default:
117@@ -179,6 +169,7 @@
118 connect(model, SIGNAL(layoutChanged(QList<QPersistentModelIndex>, QAbstractItemModel::LayoutChangeHint)), SLOT(onDomainDataChanged()));
119 connect(model, SIGNAL(dataChanged(QModelIndex, QModelIndex)), SLOT(onDomainDataChanged()));
120 connect(model, SIGNAL(modelReset()), SLOT(onDomainDataChanged()));
121+ connect(model, SIGNAL(lastVisitChanged()), SLOT(onDomainDataChanged()));
122 m_domains.insert(domain, model);
123 }
124
125
126=== modified file 'tests/unittests/history-domainlist-model/tst_HistoryDomainListModelTests.cpp'
127--- tests/unittests/history-domainlist-model/tst_HistoryDomainListModelTests.cpp 2013-08-06 10:52:58 +0000
128+++ tests/unittests/history-domainlist-model/tst_HistoryDomainListModelTests.cpp 2013-08-06 15:52:58 +0000
129@@ -98,7 +98,7 @@
130
131 history->add(QUrl("http://example.org/test.html"), "Test page", QUrl());
132 QVERIFY(spyRowsInserted.isEmpty());
133- QCOMPARE(spyDataChanged.count(), 1);
134+ QVERIFY(!spyDataChanged.isEmpty());
135 args = spyDataChanged.takeFirst();
136 QCOMPARE(args.at(0).toModelIndex().row(), 1);
137 QCOMPARE(args.at(1).toModelIndex().row(), 1);

Subscribers

People subscribed via source and target branches

to status/vote changes: