bool CThumbIndex::PhoneAbstractFromGUID(const CString& guid, WIZABSTRACT &abstract) { return AbstractFromGUID(guid, abstract, PHONE_TYPE); }
bool CThumbIndex::UpdateAbstract(const WIZABSTRACT &abstractNew, const CString& type) { if(!m_dbThumb.IsOpened()) { TOLOG(_T("Fault error: thumb database does not opened")); return false; } // QByteArray data; if (abstractNew.image.width() > 0 && abstractNew.image.height() > 0) { int width = abstractNew.image.width(); int height = abstractNew.image.height(); // QImage img; if (width > 120 || height > 120) { img = abstractNew.image.scaled(120, 120, Qt::KeepAspectRatio, Qt::SmoothTransformation); } else { img = abstractNew.image; } // if (img.isNull()) { TOLOG(_T("Faile to scale image to abstract")); return false; } // QBuffer buffer(&data); buffer.open(QIODevice::WriteOnly); if (!img.save(&buffer, "JPG")) { TOLOG(_T("Faile to save abstract image data to buffer")); return false; } buffer.close(); } // // WIZABSTRACT abstractOld; if (AbstractFromGUID(abstractNew.guid ,abstractOld, type)) { CString whereFiled = CString("ABSTRACT_GUID=") + STR2SQL(abstractNew.guid) +(" AND ABSTRACT_TYPE = ") +STR2SQL(type); // sqlite use '' instead of ' CString absText = CString(abstractNew.text); absText = absText.replace("'",""); CString sql = CString("update ") + \ TABLE_NAME_ABSTRACT + \ " set ABSTRACT_TEXT" + "='" + \ absText + "' where " + whereFiled; try { m_dbThumb.execDML(sql); m_dbThumb.updateBlob(TABLE_NAME_ABSTRACT, "ABSTRACT_IMAGE", (const unsigned char*)data.constData() , data.length(), whereFiled); return true; } catch (const CppSQLite3Exception& e) { TOLOG(e.errorMessage()); TOLOG(sql); return false; } catch (...) { TOLOG("Unknown exception while update document"); return false; } } else { CString sql = CString("insert into ") + TABLE_NAME_ABSTRACT + ("(") + FIELD_LIST_ABSTRACT + (")") + " values(" + STR2SQL(abstractNew.guid) + (",") + STR2SQL(type) + (",") + STR2SQL(abstractNew.text) + (",?)"); try { m_dbThumb.insertBlob(sql, (const unsigned char*)data.constData() , data.length()); return true; } catch (const CppSQLite3Exception& e) { TOLOG(e.errorMessage()); TOLOG(sql); return false; } catch (...) { TOLOG("Unknown exception while update document"); return false; } } // return true; }
bool CThumbIndex::UpdateAbstract(const WIZABSTRACT &abstractNew, const CString& type) { if(!m_dbThumb.IsOpened()) { TOLOG(_T("Fault error: thumb database does not opened")); return false; } QByteArray data; if (abstractNew.image.width() > 0 && abstractNew.image.height() > 0) { int width = abstractNew.image.width(); int height = abstractNew.image.height(); // process thumbnail QImage img; if (width >= 120 && height >= 120) { if (width > height) { img = abstractNew.image.scaledToHeight(120, Qt::SmoothTransformation); img = img.copy((img.width() - 120)/2, 0, 120, 120); } else { img = abstractNew.image.scaledToWidth(120, Qt::SmoothTransformation); img = img.copy(0, (img.height() - 120)/2, 120, 120); } } else if (width > 120 || height > 120) { img = abstractNew.image.scaled(120, 120, Qt::KeepAspectRatio, Qt::SmoothTransformation); } else { img = abstractNew.image; } if (img.isNull()) { TOLOG(_T("Faile to scale image to abstract")); return false; } // QBuffer buffer(&data); buffer.open(QIODevice::WriteOnly); if (!img.save(&buffer, "JPG")) { TOLOG(_T("Faile to save abstract image data to buffer")); return false; } buffer.close(); } WIZABSTRACT abstractOld; if (AbstractFromGUID(abstractNew.guid ,abstractOld, type)) { CString whereField = CString("ABSTRACT_GUID=%1 and ABSTRACT_TYPE=%2") .arg(STR2SQL(abstractNew.guid)) .arg(STR2SQL(type)); CString strSql = CString("update %1 set ABSTRACT_TEXT=%2 where %3") .arg(TABLE_NAME_ABSTRACT) .arg(STR2SQL(abstractNew.text)) .arg(whereField); try { m_dbThumb.execDML(strSql); m_dbThumb.updateBlob(TABLE_NAME_ABSTRACT, "ABSTRACT_IMAGE", (const unsigned char*)data.constData() , data.length(), whereField); return true; } catch (const CppSQLite3Exception& e) { TOLOG(e.errorMessage()); TOLOG(strSql); return false; } catch (...) { TOLOG("Unknown exception while update document"); return false; } } else { CString strSql = CString("insert into %1 (%2) values(%3, %4, %5, ?)") .arg(TABLE_NAME_ABSTRACT) .arg(FIELD_LIST_ABSTRACT) .arg(STR2SQL(abstractNew.guid)) .arg(STR2SQL(type)) .arg(STR2SQL(abstractNew.text)); try { m_dbThumb.insertBlob(strSql, (const unsigned char*)data.constData() , data.length()); return true; } catch (const CppSQLite3Exception& e) { TOLOG(e.errorMessage()); TOLOG(strSql); return false; } catch (...) { TOLOG("Unknown exception while update document"); return false; } } return true; }