int PushDAO::add(const Push &push) { int insertId = -1; QSqlQuery sqlQuery(SQLConnection()); const QString query("INSERT INTO push (seqnum, pushdate, type, pushtime, extension, content, unread)" "VALUES(:seqnum, :pushdate, :type, :pushtime, :extension, :content, :unread)"); sqlQuery.prepare(query); sqlQuery.bindValue(":pushdate", push.pushDateAsString()); sqlQuery.bindValue(":type", push.contentType()); sqlQuery.bindValue(":pushtime", push.pushTime()); sqlQuery.bindValue(":extension", push.fileExtension()); sqlQuery.bindValue(":content", push.content().toBase64(), QSql::In | QSql::Binary); sqlQuery.bindValue(":unread", push.unread()); sqlQuery.exec(); const QSqlError err = sqlQuery.lastError(); if (err.isValid()) { qWarning() << "Error executing SQL statement: " << query << ". ERROR: " << err.text(); } else { if (sqlQuery.lastInsertId().isValid()) { insertId = sqlQuery.lastInsertId().toInt(); } } return insertId; }
void PushContentController::setCurrentPush(const Push &push) { // Fill the property values with the data from the passed Push object m_pushDateTime = QString::fromLatin1("%1 - %2").arg(push.pushDateAsString()).arg(push.pushTime()); if (push.contentType() == CONTENT_TYPE_TEXT || push.fileExtension() == FILE_EXTENSION_XML) { m_contentType = QLatin1String("plainText"); m_textContent = QString::fromUtf8(push.content().data()); } else if (push.contentType() == CONTENT_TYPE_IMAGE) { m_contentType = QLatin1String("image"); m_imageContent = QVariant::fromValue(bb::cascades::Image(push.content())); } else if (push.fileExtension() == FILE_EXTENSION_HTML) { m_contentType = QLatin1String("richText"); m_textContent = QString::fromUtf8(push.content().data()); } // Emit the change notification signal to let the UI update itself emit pushContentChanged(); }