diff -Nru history-service-0.1+14.04.20140319/debian/changelog history-service-0.1+14.04.20140326/debian/changelog --- history-service-0.1+14.04.20140319/debian/changelog 2014-03-26 19:56:12.000000000 +0000 +++ history-service-0.1+14.04.20140326/debian/changelog 2014-03-26 19:56:12.000000000 +0000 @@ -1,3 +1,11 @@ +history-service (0.1+14.04.20140326-0ubuntu1) trusty; urgency=low + + [ Gustavo Pichorim Boiko ] + * Delay the loading of model data until after the model properties are + set. + + -- Ubuntu daily release Wed, 26 Mar 2014 19:51:27 +0000 + history-service (0.1+14.04.20140319-0ubuntu1) trusty; urgency=low [ Gustavo Pichorim Boiko ] diff -Nru history-service-0.1+14.04.20140319/Ubuntu/History/historyeventmodel.cpp history-service-0.1+14.04.20140326/Ubuntu/History/historyeventmodel.cpp --- history-service-0.1+14.04.20140319/Ubuntu/History/historyeventmodel.cpp 2014-03-19 02:39:44.000000000 +0000 +++ history-service-0.1+14.04.20140326/Ubuntu/History/historyeventmodel.cpp 2014-03-26 19:51:17.000000000 +0000 @@ -36,7 +36,7 @@ HistoryEventModel::HistoryEventModel(QObject *parent) : QAbstractListModel(parent), mCanFetchMore(true), mFilter(0), - mSort(0), mType(HistoryThreadModel::EventTypeText), mEventWritingTimer(0) + mSort(0), mType(HistoryThreadModel::EventTypeText), mEventWritingTimer(0), mFetchTimer(0) { // configure the roles mRoles[AccountIdRole] = "accountId"; @@ -353,8 +353,12 @@ } mAttachmentCache.clear(); - // get an initial set of results - fetchMore(QModelIndex()); + if (mFetchTimer) { + killTimer(mFetchTimer); + } + + // delay the loading of the model data until the settings settle down + mFetchTimer = startTimer(100); } void HistoryEventModel::onEventsAdded(const History::Events &events) @@ -415,20 +419,22 @@ void HistoryEventModel::timerEvent(QTimerEvent *event) { - if (event->timerId() != mEventWritingTimer) { - return; - } - - killTimer(mEventWritingTimer); - mEventWritingTimer = 0; + if (event->timerId() == mEventWritingTimer) { + killTimer(mEventWritingTimer); + mEventWritingTimer = 0; - if (mEventWritingQueue.isEmpty()) { - return; - } + if (mEventWritingQueue.isEmpty()) { + return; + } - qDebug() << "Goint to update" << mEventWritingQueue.count() << "events."; - if (History::Manager::instance()->writeEvents(mEventWritingQueue)) { - qDebug() << "... succeeded!"; - mEventWritingQueue.clear(); + qDebug() << "Goint to update" << mEventWritingQueue.count() << "events."; + if (History::Manager::instance()->writeEvents(mEventWritingQueue)) { + qDebug() << "... succeeded!"; + mEventWritingQueue.clear(); + } + } else if (event->timerId() == mFetchTimer) { + killTimer(mFetchTimer); + mFetchTimer = 0; + fetchMore(QModelIndex()); } } diff -Nru history-service-0.1+14.04.20140319/Ubuntu/History/historyeventmodel.h history-service-0.1+14.04.20140326/Ubuntu/History/historyeventmodel.h --- history-service-0.1+14.04.20140319/Ubuntu/History/historyeventmodel.h 2014-03-19 02:39:44.000000000 +0000 +++ history-service-0.1+14.04.20140326/Ubuntu/History/historyeventmodel.h 2014-03-26 19:51:17.000000000 +0000 @@ -107,6 +107,7 @@ mutable QMap > mAttachmentCache; History::Events mEventWritingQueue; int mEventWritingTimer; + int mFetchTimer; }; #endif // HISTORYEVENTMODEL_H diff -Nru history-service-0.1+14.04.20140319/Ubuntu/History/historythreadmodel.cpp history-service-0.1+14.04.20140326/Ubuntu/History/historythreadmodel.cpp --- history-service-0.1+14.04.20140319/Ubuntu/History/historythreadmodel.cpp 2014-03-19 02:39:44.000000000 +0000 +++ history-service-0.1+14.04.20140326/Ubuntu/History/historythreadmodel.cpp 2014-03-26 19:51:17.000000000 +0000 @@ -30,11 +30,12 @@ #include "historyqmltexteventattachment.h" #include "voiceevent.h" #include +#include Q_DECLARE_METATYPE(History::TextEventAttachments) HistoryThreadModel::HistoryThreadModel(QObject *parent) : - QAbstractListModel(parent), mCanFetchMore(true), mFilter(0), mSort(0), mType(EventTypeText) + QAbstractListModel(parent), mCanFetchMore(true), mFilter(0), mSort(0), mType(EventTypeText), mFetchTimer(0) { // configure the roles mRoles[AccountIdRole] = "accountId"; @@ -354,7 +355,12 @@ } mAttachmentCache.clear(); - fetchMore(QModelIndex()); + if (mFetchTimer) { + killTimer(mFetchTimer); + } + + // delay the loading just to give the settings some time to settle down + mFetchTimer = startTimer(100); } void HistoryThreadModel::onThreadsAdded(const History::Threads &threads) @@ -399,3 +405,13 @@ // removed by another client, it will still show up when a new page is requested. Maybe it // should be handle internally in History::ThreadView? } + +void HistoryThreadModel::timerEvent(QTimerEvent *event) +{ + if (event->timerId() == mFetchTimer) { + killTimer(mFetchTimer); + mFetchTimer = 0; + + fetchMore(QModelIndex()); + } +} diff -Nru history-service-0.1+14.04.20140319/Ubuntu/History/historythreadmodel.h history-service-0.1+14.04.20140326/Ubuntu/History/historythreadmodel.h --- history-service-0.1+14.04.20140319/Ubuntu/History/historythreadmodel.h 2014-03-19 02:39:44.000000000 +0000 +++ history-service-0.1+14.04.20140326/Ubuntu/History/historythreadmodel.h 2014-03-26 19:51:17.000000000 +0000 @@ -124,6 +124,9 @@ void onThreadsModified(const History::Threads &threads); void onThreadsRemoved(const History::Threads &threads); +protected: + void timerEvent(QTimerEvent *event); + private: History::ThreadViewPtr mThreadView; History::Threads mThreads; @@ -133,6 +136,7 @@ EventType mType; QHash mRoles; mutable QMap > mAttachmentCache; + int mFetchTimer; }; #endif // HISTORYTHREADMODEL_H