summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2012-06-15 17:31:47 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2012-06-15 19:49:37 -0300
commitb2c6b373a5874472f37a02b263a48346a0843077 (patch)
tree6ca7836e89f87c4115035e54776db711b772a1f7
parenta35e1d525d4a6f71ffb4def97353307b3ae16fdd (diff)
downloadsnowshoe-b2c6b373a5874472f37a02b263a48346a0843077.tar.gz
BookmarkModel::insert uses a more low level approach to data insertion.
It now uses a SQL query instead of a QSqlRecord. The reason for using the former is that insertion through QSqlRecord increases the row count, and emits a signal advertising it, before the row is commited to the database. This inconsistent state is causing trouble with the pin/unpin button in the mobile UI. Reviewed-by: Rafael Brandão
-rw-r--r--src/core/BookmarkModel.cpp19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/core/BookmarkModel.cpp b/src/core/BookmarkModel.cpp
index 9726902..cef0c36 100644
--- a/src/core/BookmarkModel.cpp
+++ b/src/core/BookmarkModel.cpp
@@ -55,14 +55,19 @@ bool BookmarkModel::select()
void BookmarkModel::insert(const QString& name, const QString& url)
{
- if (contains(url))
+ if (url.isEmpty() || contains(url))
return;
- QSqlRecord record = this->record();
- record.setValue(QLatin1String("name"), name);
- record.setValue(QLatin1String("url"), url);
- record.setValue(QLatin1String("dateAdded"), QDateTime::currentDateTime().toTime_t());
-
- insertRecord(-1, record);
+ QModelIndex index = QModelIndex();
+ beginInsertRows(index, rowCount(index), rowCount(index));
+ QSqlQuery sqlQuery(database());
+ static QString insertStatement = QLatin1String("INSERT INTO bookmarks (name, url, dateAdded) VALUES (?, ?, ?)");
+ sqlQuery.prepare(insertStatement);
+ sqlQuery.addBindValue(name);
+ sqlQuery.addBindValue(url);
+ sqlQuery.addBindValue(QDateTime::currentDateTime().toTime_t());
+ sqlQuery.exec();
+ select();
+ endInsertRows();
submitAll();
}