Example #1
0
void CWizSync::processObjectData(const WIZOBJECTDATA& data)
{
    WIZOBJECTDATA conflictObjectData(data);
    conflictObjectData.strObjectGUID = WizGenGUIDLowerCaseLetterOnly();
    conflictObjectData.strDisplayName += tr("(conflict backup)");

    // set dirty flag, uploaded needed
    m_conflictDownloadedInfo.nVersion = -1;
    m_conflictDownloadedInfo.strGUID = conflictObjectData.strObjectGUID;
    m_conflictDownloadedInfo.strTitle += tr("(conflict backup)");
    m_conflictDownloadedInfo.strInfoMD5 = m_db.CalDocumentInfoMD5(m_conflictDownloadedInfo);

    if (m_db.CreateDocumentEx(m_conflictDownloadedInfo)) {
        m_db.UpdateSyncObjectLocalData(conflictObjectData);
        TOLOG1(tr("Conflict backup created: %1"), m_conflictDownloadedInfo.strTitle);
    } else {
        TOLOG("unable to create conflict backup while create document");
    }

    std::deque<WIZDOCUMENTDATABASE>::iterator it;
    for (it = m_arrayAllDocumentsNeedToBeDownloaded.begin(); \
            it != m_arrayAllDocumentsNeedToBeDownloaded.end();
            it++) {
        WIZDOCUMENTDATABASE data = *it;

        if (data.strGUID == m_conflictedDocument.strGUID) {
            m_arrayAllDocumentsNeedToBeDownloaded.erase(it);
            break;
        }
    }

    // chain back
    onQueryDocumentInfo(m_conflictedDocument);
}
Example #2
0
void CWizKbSync::processConflictObjectData(const WIZOBJECTDATA& data)
{
    WIZOBJECTDATA conflictObjectData(data);
    conflictObjectData.strObjectGUID = WizGenGUIDLowerCaseLetterOnly();
    conflictObjectData.strDisplayName += tr("(conflict backup)");

    // set dirty flag, upload needed
    m_conflictDownloadedInfo.nVersion = -1;
    m_conflictDownloadedInfo.strKbGUID = kbGUID();
    m_conflictDownloadedInfo.strGUID = conflictObjectData.strObjectGUID;
    m_conflictDownloadedInfo.strTitle += tr("(conflict backup)");
    m_conflictDownloadedInfo.strInfoMD5 = m_db->CalDocumentInfoMD5(m_conflictDownloadedInfo);

    if (m_db->CreateDocumentEx(m_conflictDownloadedInfo)) {
        m_db->UpdateSyncObjectLocalData(conflictObjectData);
        Q_EMIT processLog(WizFormatString1(tr("Conflict backup created: %1"), m_conflictDownloadedInfo.strTitle));
    } else {
        Q_EMIT processLog("unable to create conflict backup while create document");
    }

    // chain back
    onQueryDocumentInfo(m_conflictDownloadedInfo);
}
void CWizCrashReportDialog::on_btn_yes_clicked()
{
    accept();

    QString text = m_reports;
    QtConcurrent::run([text](){
        QString reportText = text;
        const int maxSize = 1024 * 128 - 100;
        if (reportText.size() > maxSize)
        {
            reportText.truncate(maxSize);
            reportText.append("\n Wow! too may words, truncated!");
        }

        //
        QString url = WizService::WizApiEntry::crashReportUrl();
        QNetworkRequest request(url);
        request.setHeader(QNetworkRequest::ContentTypeHeader,
            "application/x-www-form-urlencoded");

        QUrlQuery postData;
        postData.addQueryItem("platform", "mac");
        postData.addQueryItem("token", "");
        postData.addQueryItem("subject", "Version: " + QString(WIZ_CLIENT_VERSION) + "  UUID : " + WizGenGUIDLowerCaseLetterOnly());
        postData.addQueryItem("error", reportText);

        QNetworkAccessManager net;
        QNetworkReply* reply = net.post(request, postData.toString(QUrl::FullyEncoded).toUtf8());

        CWizAutoTimeOutEventLoop loop(reply);
        loop.exec();

        if (loop.error() != QNetworkReply::NoError)
        {
            qDebug() << "[Crash report]Upload failed!";
            return;
        }

        rapidjson::Document d;
        d.Parse<0>(loop.result().toUtf8().constData());

        if (!d.HasMember("return_code"))
        {
            qDebug() << "[Crash report]Can not get return code ";
            return;
        }

        int returnCode = d.FindMember("return_code")->value.GetInt();
        if (returnCode != 200)
        {
            qDebug() << "[Crash report]Return code was not 200, error :  " << returnCode << loop.result();
            return;
        }
        else
        {
            qDebug() << "[Crash report]Upload OK";
        }

    });
}
bool WizKMCombineDocumentsToHtmlFile(WizDatabaseManager& dbMgr, const CWizDocumentDataArray& arrayDocument, QString splitter, bool addTitle, QString& strResultFileName, CWizDocumentAttachmentDataArray& arrayAttachment, QString& strError)
{
    QString strTempPath = Utils::WizPathResolve::tempPath() + WizGenGUIDLowerCaseLetterOnly() + "/";
    ::WizEnsurePathExists(strTempPath);
    //
    CWizStdStringArray htmls;
    //
    size_t nCount = arrayDocument.size();
    for (size_t i = 0; i < nCount; i++)
    {
        WIZDOCUMENTDATA doc = arrayDocument[i];
        //
        WizDatabase& db = dbMgr.db(doc.strKbGUID);
        if (!db.isDocumentDownloaded(doc.strGUID))
        {
            strError = QObject::tr("Note has not been downloaded");
            return false;
        }
        //
        if (!db.documentToHtmlFile(doc, strTempPath))
        {
            strError = QObject::tr("Failed to get note data");
            return false;
        }
        //
        QString htmlFileName = strTempPath + "index.html";
        if (!QFileInfo::exists(htmlFileName))
        {
            strError = QObject::tr("Failed to get note data");
            return false;
        }
        //
        QString html;
        if (!WizLoadUnicodeTextFromFile(htmlFileName, html))
        {
            strError = QObject::tr("Failed to read note data");
            return false;
        }
        //
        htmls.push_back(html);
        //
        CWizDocumentAttachmentDataArray atts;
        db.getDocumentAttachments(doc.strGUID, atts);
        for (WIZDOCUMENTATTACHMENTDATA att : atts)
        {
            if (!db.isAttachmentDownloaded(att.strGUID))
            {
                strError = QObject::tr("Note attachment %1 has not been downloaded").arg(att.strName);
                return false;
            }
            //
            arrayAttachment.push_back(att);
        }
    }
    //
    CString strAllHTML;
    //
    for (size_t i = 0; i < nCount; i++)
    {
        CString html = htmls[i];
        WIZDOCUMENTDATA doc = arrayDocument[i];
        if (-1 != WizStrStrI_Pos(html, CString(_T("<frameset"))))
        {
            strError = QObject::tr("Cannot combine html because html contains frame set");
            return false;
        }
        //
        CString strTitle = doc.strTitle;
        WizOleDateTime t = doc.tCreated;
        CString strDate = t.toLocalLongDate();
        //
        if (addTitle)
        {
            CString strInfoHtml = WizFormatString2(_T("<h2>%1 (%2)</h2>"), strTitle, strDate);
            ::WizHTMLInsertTextBeforeBody(strInfoHtml, html);
        }
        //
        if (!WizCombineHtmlText(strAllHTML, html))
        {
            strError = QObject::tr("Cannot combine html");
            return false;
        }
        //
        if (i < nCount - 1)
        {
            if (!splitter.isEmpty())
            {
                WizCombineHtmlText(strAllHTML, splitter);
            }
        }
    }
    //
    strResultFileName = strTempPath + "index.html";
    //
    bool ret = ::WizSaveUnicodeTextToUtf8File(strResultFileName, strAllHTML);
    if (!ret)
    {
        strError = QObject::tr("Cannot save note html");
        return false;
    }
    return true;
}
void WizCombineNotesDialog::accept()
{
    if (WizMainWindow* mainWindow = WizMainWindow::instance())
    {
        WizUserSettings& settings = mainWindow->userSettings();
        QString splitter = ui->editSplitter->text();
        if (splitter.isEmpty())
        {
            splitter = "<!--none-->";
        }
        settings.set("CombineNote", "splitter", splitter);
        //
        settings.set("CombineNote", "addTitle", ui->btnAddTitle->isChecked() ? "1" : "0");
    }
    //
    QString strResultFileName;
    CWizDocumentAttachmentDataArray arrayAttachment;
    QString strError;
    bool ret = WizKMCombineDocumentsToHtmlFile(m_dbMgr, getResultDocuments(), ui->editSplitter->text(), ui->btnAddTitle->isChecked(), strResultFileName, arrayAttachment, strError);
    if (!ret)
    {
        WizMessageBox::critical(this, tr("Failed to combine note: %1").arg(strError));
        return;
    }
    //
    QString folder = Utils::WizMisc::extractFilePath(strResultFileName);
    QString strZiwFileName = folder + WizGenGUIDLowerCaseLetterOnly() + ".ziw";
    bool bZip = ::WizFolder2Zip(folder, strZiwFileName);
    if (!bZip)
    {
        WizMessageBox::critical(this, tr("Info"), tr("Failled to compress notes data"));
        return;
    }
    //
    WIZDOCUMENTDATA doc = m_documents[0];
    doc.strGUID.clear();
    doc.strTitle = ui->editNewTitle->text();
    //
    WizNoteManager noteManager(m_dbMgr);
    if (!noteManager.createNoteByTemplate(doc, WIZTAGDATA(), strZiwFileName))
    {
        WizMessageBox::critical(this, tr("Info"), tr("Failed to create new data"));
        return;
    }
    //
    for (auto att: arrayAttachment)
    {
        WizDatabase& db = m_dbMgr.db(att.strKbGUID);
        //
        WIZDOCUMENTATTACHMENTDATA attRet;
        if (!db.addAttachment(doc, db.getAttachmentFileName(att.strGUID), attRet))
        {
            WizMessageBox::critical(this, tr("Info"), tr("Failed to add attachment"));
            return;
        }
        //
        attRet.strName = att.strName;
        db.updateAttachment(attRet);
    }

    //
    if (WizMainWindow* mainWindow = WizMainWindow::instance())
    {
        if (WizDocumentListView* list = mainWindow->documentList())
        {
            int index = list->documentIndexFromGUID(doc.strGUID);
            if (index != -1)
            {
                WizDocumentListViewDocumentItem* pItem = list->documentItemAt(index);
                pItem->document().tCreated = pItem->document().tCreated.addSecs(-5);
            } else {
                doc.tCreated = doc.tCreated.addSecs(-5);    //避免自动进入编辑模式
            }
            //
            list->addAndSelectDocument(doc);
        }
    }
    //
    QDialog::accept();
}