void WizFramelessWebDialog::onPageLoadFinished(bool ok)
{
    if (ok)
    {
        while (!m_timerIDList.isEmpty())
        {
            int nTimerID = m_timerIDList.first();
            killTimer(nTimerID);
            m_timerIDList.removeFirst();
        }
        //avoid QDialog::exec: Recursive call
        disconnect(m_frame, SIGNAL(loadFinished(bool)), this, SLOT(onPageLoadFinished(bool)));
        //
        WizExecuteOnThread(WIZ_THREAD_MAIN, [=]{
            //
            if (m_bVisibling)
                return;
            //
            m_bVisibling = true;
            show();
            m_bVisibling = false;
            //
        });
    }
    else
    {
示例#2
0
void WizTokenPrivate::requestToken()
{
    if (m_bProcessing)
    {
        qDebug() << "Querying token...";
        return;
    }
    //
    class GetTokenRunnable : public QObject
    {
        WizTokenPrivate* m_p;
    public:
        GetTokenRunnable(WizTokenPrivate* p)
            : m_p(p)
        {
        }

        void run()
        {
            m_p->m_bProcessing = true;
            QString token = m_p->token();
            m_p->m_bProcessing = false;
            Q_EMIT m_p->q->tokenAcquired(token);
        }
    };
    WizExecuteOnThread(WIZ_THREAD_NETWORK, [=](){
        GetTokenRunnable runnable(this);
        runnable.run();
    });
}
示例#3
0
void WizNoteManager::downloadTemplatePurchaseRecord()
{
    //下载用户购买的模板列表
    WizExecuteOnThread(WIZ_THREAD_NETWORK, [=]() {
        WizEnsurePathExists(Utils::WizPathResolve::customNoteTemplatesPath());
        //
        QNetworkAccessManager manager;
        QString url = WizCommonApiEntry::asServerUrl() + "/a/templates/record?token=" + WizToken::token();
//        qDebug() << "get templates record from url : " << url;
        //
        QByteArray ba;
        {
            QNetworkReply* reply = manager.get(QNetworkRequest(url));
            WizAutoTimeOutEventLoop loop(reply);
            loop.exec();
            //
            if (loop.error() != QNetworkReply::NoError || loop.result().isEmpty())
                return;

            ba = loop.result();
            QString jsonFile = Utils::WizPathResolve::wizTemplatePurchaseRecordFile();
            std::ofstream recordFile(jsonFile.toUtf8().constData(), std::ios::out | std::ios::trunc);
            recordFile << ba.constData();
        }
    });
}
示例#4
0
void WizNoteManager::createIntroductionNoteForNewRegisterAccount()
{
    WizExecuteOnThread(WIZ_THREAD_DEFAULT, [=](){
        //get local note
        QDir dir(Utils::WizPathResolve::introductionNotePath());
        QStringList introductions = dir.entryList(QDir::Files);
        if (introductions.isEmpty())
            return;

        QSettings settings(Utils::WizPathResolve::introductionNotePath() + "settings.ini", QSettings::IniFormat);
        //copy note to new account
        WizDatabase& db = m_dbMgr.db();
        for (QString fileName : introductions)
        {
            QString filePath = Utils::WizPathResolve::introductionNotePath() + fileName;
            QFileInfo info(filePath);
            if (info.suffix() == "ini")
                continue;
            settings.beginGroup("Location");
            QString location = settings.value(info.baseName(), "/My Notes/").toByteArray();
            settings.endGroup();
            WIZTAGDATA tag;
            WIZDOCUMENTDATA doc;
            settings.beginGroup("Title");
            doc.strTitle = settings.value(info.baseName()).toString();
            settings.endGroup();
            if (!db.createDocumentByTemplate(filePath, location, tag, doc))
            {
                qCritical() << "create introduction note failed : " << filePath;
            }
        }
    });
}
示例#5
0
void WizNoteManager::updateTemplateJS(const QString& local)
{
    //软件启动之后获取模板信息,检查template.js是否存在、是否是最新版。需要下载时进行下载
    WizExecuteOnThread(WIZ_THREAD_NETWORK, [=]() {
        //NOTE:现在编辑器依赖template.js文件。需要确保该文件存在。如果文件不存在则拷贝
        WizEnsurePathExists(Utils::WizPathResolve::customNoteTemplatesPath());
        if (!QFile::exists(Utils::WizPathResolve::wizTemplateJsFilePath()))
        {
            QString localJs = Utils::WizPathResolve::resourcesPath() + "files/wizeditor/wiz_template.js";
            WizCopyFile(localJs, Utils::WizPathResolve::wizTemplateJsFilePath(), true);
        }

        QNetworkAccessManager manager;
        QString url = WizCommonApiEntry::asServerUrl() + "/a/templates?language_type=" + local;
#ifdef Q_OS_MAC
        url.append("&client_type=macosx");
#else
        url.append("&client_type=linux");
#endif
//        qDebug() << "get templates message from url : " << url;
        //
        QByteArray ba;
        {
            QNetworkReply* reply = manager.get(QNetworkRequest(url));
            WizAutoTimeOutEventLoop loop(reply);
            loop.exec();
            //
            if (loop.error() != QNetworkReply::NoError || loop.result().isEmpty())
                return;

            ba = loop.result();
        }

        //根据线上的内容来判断本地的模板文件是否需要更新
        if (!updateLocalTemplates(ba, manager))
            return;

        //更新成功之后将数据保存到本地
        QString jsonFile = Utils::WizPathResolve::wizTemplateJsonFilePath();
        std::ofstream logFile(jsonFile.toUtf8().constData(), std::ios::out | std::ios::trunc);
        logFile << ba.constData();
    });
}