bool CWizIndexBase::SQLToTagDataArray(const CString& strSQL, CWizTagDataArray& arrayTag) { try { CppSQLite3Query query = m_db.execQuery(strSQL); while (!query.eof()) { WIZTAGDATA data; data.strKbGUID = kbGUID(); data.strGUID = query.getStringField(tagTAG_GUID); data.strParentGUID = query.getStringField(tagTAG_GROUP_GUID); data.strName = query.getStringField(tagTAG_NAME); data.strDescription = query.getStringField(tagTAG_DESCRIPTION); data.tModified = query.getTimeField(tagDT_MODIFIED); data.nVersion = query.getInt64Field(tagVersion); arrayTag.push_back(data); query.nextRow(); } std::sort(arrayTag.begin(), arrayTag.end()); return true; } catch (const CppSQLite3Exception& e) { return LogSQLException(e, strSQL); } }
bool CWizIndexBase::TagFromGUID(const CString& strTagGUID, WIZTAGDATA& data) { if (!strTagGUID || !*strTagGUID) { TOLOG(_T("TagGUID is empty")); return false; } CString strWhere; strWhere.Format(_T("TAG_GUID=%s"), STR2SQL(strTagGUID).utf16() ); CString strSQL = FormatQuerySQL(TABLE_NAME_WIZ_TAG, FIELD_LIST_WIZ_TAG, strWhere); CWizTagDataArray arrayTag; if (!SQLToTagDataArray(strSQL, arrayTag)) { TOLOG(_T("Failed to get tag by guid")); return false; } if (arrayTag.empty()) { //TOLOG(_T("Failed to get tag by guid, result is empty")); return false; } data = arrayTag[0]; return true; }
bool CWizDatabase::UpdateTags(const CWizTagDataArray& arrayTag) { if (arrayTag.empty()) return false; qint64 nVersion = -1; bool bHasError = false; CWizTagDataArray::const_iterator it; for (it = arrayTag.begin(); it != arrayTag.end(); it++) { const WIZTAGDATA& tag = *it; Q_EMIT processLog("tag: " + tag.strName); if (!UpdateTag(tag)) { bHasError = true; } nVersion = qMax(nVersion, tag.nVersion); } if (!bHasError) { SetObjectVersion(WIZTAGDATA::ObjectName(), nVersion); } return !bHasError; }
void CWizKbSync::onTagPostList(const CWizTagDataArray& arrayData) { CWizTagDataArray::const_iterator it; for (it = arrayData.begin(); it != arrayData.end(); it++) { m_db->ModifyObjectVersion(it->strGUID, WIZTAGDATA::ObjectName(), 0); } uploadNextTags(); }
void CWizNoteInfoForm::setDocument(const WIZDOCUMENTDATA& data) { Q_ASSERT(!data.strKbGUID.isEmpty()); m_docKbGuid = data.strKbGUID; m_docGuid = data.strGUID; CWizDatabase& db = CWizDatabaseManager::instance()->db(data.strKbGUID); QString doc = db.GetDocumentFileName(data.strGUID); QString sz = ::WizGetFileSizeHumanReadalbe(doc); ui->editTitle->setText(data.strTitle); // private document if (data.strKbGUID == CWizDatabaseManager::instance()->db().kbGUID()) { ui->labelNotebook->setText(data.strLocation); QString tags = db.GetDocumentTagsText(data.strGUID); ui->labelTags->setText(tags); ui->editAuthor->setText(data.strAuthor); // group document } else { CWizTagDataArray arrayTag; if (!db.GetDocumentTags(data.strGUID, arrayTag)) { ui->labelNotebook->clear(); } else { if (arrayTag.size() > 1) { TOLOG1("Group document should only have one tag: %1", data.strTitle); } QString tagText; if (arrayTag.size()) { tagText = db.getTagTreeText(arrayTag[0].strGUID); } ui->labelNotebook->setText("/" + db.name() + tagText + "/"); } ui->labelTags->clear(); ui->editAuthor->setText(data.strAuthor); } // common fields ui->editCreateTime->setText(data.tCreated.toString()); ui->editUpdateTime->setText(data.tModified.toString()); ui->editURL->setText(data.strURL); ui->labelOpenURL->setText(WizFormatString2("<a href=\"%1\">%2</a>", data.strURL, tr("Open"))); ui->labelSize->setText(sz); ui->checkEncrypted->setChecked(data.nProtected ? true : false); bool canEdit = (db.CanEditDocument(data) && !CWizDatabase::IsInDeletedItems(data.strLocation)); ui->editAuthor->setReadOnly(!canEdit); ui->editTitle->setReadOnly(!canEdit); ui->editURL->setReadOnly(!canEdit); ui->checkEncrypted->setEnabled(canEdit && !db.IsGroup()); }
void CWizKbSync::onTagGetList(const CWizTagDataArray& arrayRet) { m_db->UpdateTags(arrayRet); m_arrayAllTagsDownloaded.insert(m_arrayAllTagsDownloaded.end(), arrayRet.begin(), arrayRet.end()); qDebug() << "[Syncing]download size: " << m_arrayAllTagsDownloaded.size(); if (arrayRet.size() < WIZAPI_PAGE_MAX) { onDownloadTagsCompleted(); } else { downloadNextTags(WizObjectsGetMaxVersion<WIZTAGDATA>(arrayRet)); } }
bool CWizIndexBase::GetAllChildTagsSize(const CString& strParentTagGUID, int& size) { int nSizeCurrent; GetChildTagsSize(strParentTagGUID, nSizeCurrent); size += nSizeCurrent; CWizTagDataArray arrayTagCurrent; GetChildTags(strParentTagGUID, arrayTagCurrent); CWizTagDataArray::const_iterator it; for (it = arrayTagCurrent.begin(); it != arrayTagCurrent.end(); it++) { GetAllChildTagsSize(it->strGUID, size); } return true; }
void CWizKbSync::uploadNextTags() { if (m_arrayAllTagsNeedToBeUploaded.empty()) { onUploadTagsCompleted(); } else { int countPerPage = WIZAPI_PAGE_MAX; CWizTagDataArray arrayCurr; if (m_arrayAllTagsNeedToBeUploaded.size() > (size_t)countPerPage) { arrayCurr.assign(m_arrayAllTagsNeedToBeUploaded.begin(), \ m_arrayAllTagsNeedToBeUploaded.begin() + countPerPage); m_arrayAllTagsNeedToBeUploaded.erase(m_arrayAllTagsNeedToBeUploaded.begin(), \ m_arrayAllTagsNeedToBeUploaded.begin() + countPerPage); } else { arrayCurr.assign(m_arrayAllTagsNeedToBeUploaded.begin(), \ m_arrayAllTagsNeedToBeUploaded.end()); m_arrayAllTagsNeedToBeUploaded.clear(); } callTagPostList(arrayCurr); } }
void CWizCategoryViewGroupItem::drop(const WIZDOCUMENTDATA& data, bool forceCopy) { if (!acceptDrop(data)) return; CWizDatabase& myDb = CWizDatabaseManager::instance()->db(kbGUID()); if (!forceCopy && data.strKbGUID == m_strKbGUID) { CWizDocument doc(myDb, data); if (data.strLocation == LOCATION_DELETED_ITEMS) { CWizFolder folder(myDb, myDb.GetDefaultNoteLocation()); doc.MoveDocument(&folder); } CWizTagDataArray arrayTag; myDb.GetDocumentTags(data.strGUID, arrayTag); if (arrayTag.size() > 0) { for (CWizTagDataArray::const_iterator it = arrayTag.begin(); it != arrayTag.end(); it++) { doc.RemoveTag(*it); } } doc.AddTag(tag()); } else { CWizDatabase& sourceDb = CWizDatabaseManager::instance()->db(data.strKbGUID); QString strLocation = myDb.GetDefaultNoteLocation(); Internal::MainWindow* window = qobject_cast<Internal::MainWindow *>(m_app.mainWindow()); QString strNewDocGUID; sourceDb.CopyDocumentTo(data.strGUID, myDb, strLocation, m_tag, strNewDocGUID, window->downloaderHost()); } }
bool CWizIndexBase::GetAllChildTags(const CString& strParentTagGUID, CWizTagDataArray& arrayTag) { CWizTagDataArray arrayTagCurrent; GetChildTags(strParentTagGUID, arrayTagCurrent); arrayTag.insert(arrayTag.begin(), arrayTagCurrent.begin(), arrayTagCurrent.end()); CWizTagDataArray::const_iterator it; for (it = arrayTagCurrent.begin(); it != arrayTagCurrent.end(); it++) { GetAllChildTags(it->strGUID, arrayTag); } return true; }