Example #1
0
bool CWizIndexBase::SQLToStyleDataArray(const CString& strSQL, CWizStyleDataArray& arrayStyle)
{
    try
    {
        CppSQLite3Query query = m_db.execQuery(strSQL);
        while (!query.eof())
        {
            WIZSTYLEDATA data;
            data.strKbGUID = kbGUID();
            data.strGUID = query.getStringField(styleSTYLE_GUID);
            data.strName = query.getStringField(styleSTYLE_NAME);
            data.strDescription = query.getStringField(styleSTYLE_DESCRIPTION);
            data.crTextColor = query.getColorField(styleSTYLE_TEXT_COLOR);
            data.crBackColor = query.getColorField(styleSTYLE_BACK_COLOR);
            data.bTextBold = query.getBoolField(styleSTYLE_TEXT_BOLD);
            data.nFlagIndex = query.getIntField(styleSTYLE_FLAG_INDEX);
            data.tModified = query.getTimeField(styleDT_MODIFIED);
            data.nVersion = query.getInt64Field(styleVersion);

            arrayStyle.push_back(data);
            query.nextRow();
        }

        std::sort(arrayStyle.begin(), arrayStyle.end());
        return true;
    }
    catch (const CppSQLite3Exception& e)
    {
        return LogSQLException(e, strSQL);
    }
}
Example #2
0
bool CWizIndexBase::StyleFromGUID(const CString& strStyleGUID, WIZSTYLEDATA& data)
{
    if (!strStyleGUID || !*strStyleGUID) {
        TOLOG(_T("StyleGUID is empty"));
        return false;
    }

    CString strWhere;
    strWhere.Format(_T("STYLE_GUID=%s"),
        STR2SQL(strStyleGUID).utf16()
        );

    CString strSQL = FormatQuerySQL(TABLE_NAME_WIZ_STYLE, FIELD_LIST_WIZ_STYLE, strWhere);

    CWizStyleDataArray arrayStyle;
    if (!SQLToStyleDataArray(strSQL, arrayStyle)) {
        TOLOG(_T("Failed to get style by guid"));
        return false;
    }

    if (arrayStyle.empty()) {
        //TOLOG(_T("Failed to get style by guid, result is empty"));
        return false;
    }

    data = arrayStyle[0];
    return true;
}
bool CWizDatabase::UpdateStyles(const CWizStyleDataArray& arrayStyle)
{
    if (arrayStyle.empty())
        return true;

    qint64 nVersion = -1;

    bool bHasError = false;
    CWizStyleDataArray::const_iterator it;
    for (it = arrayStyle.begin(); it != arrayStyle.end(); it++) {
        const WIZSTYLEDATA& data = *it;

        Q_EMIT processLog("style: " + data.strName);

        if (!UpdateStyle(data)) {
            bHasError = true;
        }

        nVersion = qMax(nVersion, data.nVersion);
    }

    if (!bHasError) {
        SetObjectVersion(WIZSTYLEDATA::ObjectName(), nVersion);
    }

    return !bHasError;
}
Example #4
0
void CWizKbSync::onStylePostList(const CWizStyleDataArray& arrayData)
{
    CWizStyleDataArray::const_iterator it;
    for (it = arrayData.begin(); it != arrayData.end(); it++) {
        m_db->ModifyObjectVersion(it->strGUID, WIZSTYLEDATA::ObjectName(), 0);
    }

    uploadNextStyles();
}
Example #5
0
void CWizKbSync::onStyleGetList(const CWizStyleDataArray& arrayRet)
{
    m_db->UpdateStyles(arrayRet);

    m_arrayAllStylesDownloaded.insert(m_arrayAllStylesDownloaded.end(),
                                      arrayRet.begin(), arrayRet.end());

    qDebug() << "[Syncing]download size: " << m_arrayAllStylesDownloaded.size();

    if (arrayRet.size() < WIZAPI_PAGE_MAX) {
        onDownloadStylesCompleted();
    } else {
        downloadNextStyles(WizObjectsGetMaxVersion<WIZSTYLEDATA>(arrayRet));
    }
}
Example #6
0
void CWizKbSync::uploadNextStyles()
{
    if (m_arrayAllStylesNeedToBeUploaded.empty()) {
        onUploadStylesCompleted();
    } else {
        int countPerPage = WIZAPI_PAGE_MAX;

        CWizStyleDataArray arrayCurr;
        if (m_arrayAllStylesNeedToBeUploaded.size() > (size_t)countPerPage) {
            arrayCurr.assign(m_arrayAllStylesNeedToBeUploaded.begin(), \
                             m_arrayAllStylesNeedToBeUploaded.begin() + countPerPage);
            m_arrayAllStylesNeedToBeUploaded.erase(m_arrayAllStylesNeedToBeUploaded.begin(), \
                                                   m_arrayAllStylesNeedToBeUploaded.begin() + countPerPage);
        } else {
            arrayCurr.assign(m_arrayAllStylesNeedToBeUploaded.begin(), \
                             m_arrayAllStylesNeedToBeUploaded.end());
            m_arrayAllStylesNeedToBeUploaded.clear();
        }

        callStylePostList(arrayCurr);
    }
}