MCPcopy Create free account
hub / github.com/baumgarr/nixnote2 / downloadInkNoteImage

Method downloadInkNoteImage

communication/communicationmanager.cpp:1012–1093  ·  view source on GitHub ↗

Download an ink note image

Source from the content-addressed store, hash-verified

1010
1011// Download an ink note image
1012void CommunicationManager::downloadInkNoteImage(QString guid, Resource *r, QString shard, QString authToken) {
1013// Windows Check
1014#ifdef _WIN32
1015 Q_UNUSED(guid)
1016 Q_UNUSED(r)
1017 Q_UNUSED(shard)
1018 Q_UNUSED(authToken)
1019#else
1020 UserTable userTable(db);
1021 QImage *newImage = NULL;
1022 User u;
1023 userTable.getUser(u);
1024 if (shard == "")
1025 shard = u.shardId;
1026 QString urlBase = QString("https://")+evernoteHost
1027 +QString("/shard/")
1028 +shard
1029 +QString("/res/")
1030 +guid +QString(".ink?slice=");
1031 int sliceCount = 1+((r->height-1)/600);
1032
1033 QSize size;
1034 size.setHeight(r->height);
1035 size.setWidth(r->width);
1036
1037#if QT_VERSION < 0x050000
1038 QUrl postData;
1039#else
1040 QUrlQuery postData;
1041#endif
1042 postData.clear();
1043 postData.addQueryItem("auth", authToken);
1044
1045 CURL *curl;
1046 FILE *fp;
1047 CURLcode res;
1048
1049 curl = curl_easy_init();
1050 if (curl) {
1051 int position = 0;
1052 for (int i=0; i<sliceCount && position >=0; i++) {
1053
1054 QTemporaryFile tempFile;
1055 tempFile.open();
1056 tempFile.close();
1057 fp = fopen(tempFile.fileName().toStdString().c_str(), "wb");
1058
1059 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curlWriter);
1060 curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
1061
1062#if QT_VERSION < 0x050000
1063 QString url = urlBase+QString::number(i+1)+"&"+postData.encodedQuery();
1064#else
1065 QString url = urlBase+QString::number(i+1)+"&"+postData.query();
1066#endif
1067 curl_easy_setopt(curl, CURLOPT_URL, url.toStdString().c_str());
1068 res = curl_easy_perform(curl);
1069 QLOG_DEBUG() << "curl inknote result " << res;

Callers

nothing calls this directly

Calls 9

openMethod · 0.80
loadMethod · 0.80
removeMethod · 0.80
formatMethod · 0.80
QStringClass · 0.50
getUserMethod · 0.45
clearMethod · 0.45
closeMethod · 0.45
queryMethod · 0.45

Tested by

no test coverage detected