Esempio n. 1
0
void EvernoteSession::getNoteContent(NoteWrapper* note){
    qDebug() << "EvernoteSession :: auth" << endl;
    noteLoadStarted(note);
    try {
        note->note.tagGuids = DatabaseManager::instance()->getNoteTagGuids(note->note);
        note->note.resources = DatabaseManager::instance()->getNoteResources(note->note);


        if(!FileUtils::noteCached(note)){
            recreateSyncClient(false);
            std::string content = "";
            syncClient->getNoteContent(content, Settings::instance()->getAuthToken().toStdString(),note->getGuid());
            FileUtils::cacheNoteContent(note, QString::fromStdString(content));
        }
        if(cancelGetNote){
            return;
        }
        noteContentDownloaded(/*FileUtils::noteContentFilePath(note)*/note);
        sleep(1);
        for(int i=0;i<note->note.resources.size();i++){
            Resource r = note->note.resources.at(i);
            if(!FileUtils::resourceCached(r)){
                recreateSyncClient(false);
                syncClient->getResource(r, Settings::instance()->getAuthToken().toStdString(),r.guid, true, false, true, false);
                FileUtils::cacheResourceContent(r);
                r.data.bodyHash = ResourceWrapper::convertToHex(r.data.bodyHash).toStdString();
            }
            if(cancelGetNote){
                return;
            }
            ResourceWrapper* w = new ResourceWrapper(r);
            resourceDownloaded(w);
        }

        noteLoadFinished(note);
    } catch (TException &tx) {
        qDebug() << "EvernoteSession :: excetion while getNoteContent: " << tx.what();
        if(!cancelGetNote){
            noteLoadError(QString::fromLocal8Bit(tx.what()));
        }else{
            qDebug() << "note load canceled, supress errors";
        }
    }
}
Esempio n. 2
0
QVariant DataBrowser::loadResource(int type, const QUrl & name)
{
    if(type == QTextDocument::ImageResource || type == QTextDocument::StyleSheetResource)
    {
        if(resources.contains(name.toString()))
        {
            return resources.take(name.toString());
        }
        else if(!requestedResources.contains(name.toString()))
        {
            qDebug() << "Requesting resource" << name.toString();
            requestedResources.insert(name.toString());

            QNetworkRequest newRequest(QUrl("https://www.hedgewars.org" + name.toString()));
            newRequest.setAttribute(typeAttribute, type);
            newRequest.setAttribute(urlAttribute, name);

            QNetworkReply *reply = manager->get(newRequest);
            connect(reply, SIGNAL(finished()), this, SLOT(resourceDownloaded()));
        }
    }

    return QVariant();
}