package cx.fbn.nevernote.gui;\r
\r
+import java.io.FileInputStream;\r
+import java.io.FileNotFoundException;\r
+import java.io.IOException;\r
+import java.io.UnsupportedEncodingException;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.apache.http.HttpResponse;\r
+import org.apache.http.NameValuePair;\r
+import org.apache.http.client.ClientProtocolException;\r
+import org.apache.http.client.HttpClient;\r
+import org.apache.http.client.entity.UrlEncodedFormEntity;\r
+import org.apache.http.client.methods.HttpPost;\r
+import org.apache.http.impl.client.DefaultHttpClient;\r
+import org.apache.http.message.BasicNameValuePair;\r
+import org.apache.http.util.EntityUtils;\r
+\r
+import com.evernote.edam.type.User;\r
import com.trolltech.qt.core.QBuffer;\r
import com.trolltech.qt.core.QByteArray;\r
import com.trolltech.qt.core.QIODevice;\r
import com.trolltech.qt.webkit.QWebPage;\r
\r
import cx.fbn.nevernote.Global;\r
+import cx.fbn.nevernote.oauth.OAuthTokenizer;\r
import cx.fbn.nevernote.sql.DatabaseConnection;\r
import cx.fbn.nevernote.threads.ThumbnailRunner;\r
+import cx.fbn.nevernote.utilities.AESEncrypter;\r
import cx.fbn.nevernote.utilities.ApplicationLogger;\r
import cx.fbn.nevernote.utilities.ListManager;\r
\r
QByteArray b = buffer.buffer();\r
conn.getNoteTable().setThumbnail(guid, b);\r
conn.getNoteTable().setThumbnailNeeded(guid, false);\r
+ \r
+ // サムネイルをEvernoteサーバから取得\r
+ User user = Global.getUserInformation();\r
+ String serverUrl = Global.getServer();\r
+ String shardId = user.getShardId();\r
+ if (shardId == null || shardId.equals("")) {\r
+ return;\r
+ }\r
+ \r
+ OAuthTokenizer tokenizer = new OAuthTokenizer();\r
+ AESEncrypter aes = new AESEncrypter();\r
+ try {\r
+ aes.decrypt(new FileInputStream(Global.getFileManager().getHomeDirFile("oauth.txt")));\r
+ } catch (FileNotFoundException e) {\r
+ e.printStackTrace();\r
+ }\r
+ String authString = aes.getString();\r
+ String oauthToken = new String();\r
+ if (!authString.equals("")) {\r
+ tokenizer.tokenize(authString);\r
+ oauthToken = tokenizer.oauth_token;\r
+ }\r
+ \r
+ HttpClient httpClient = new DefaultHttpClient();\r
+\r
+ HttpPost httpPost = new HttpPost("https://" + serverUrl + "/shard/" + user.getShardId() + "/thm/note/" + guid);\r
+ httpPost.setHeader("Content-type", "application/x-www-form-urlencoded");\r
+ httpPost.setHeader("Host", serverUrl);\r
+\r
+ List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);\r
+ nameValuePairs.add(new BasicNameValuePair("auth", oauthToken));\r
+ nameValuePairs.add(new BasicNameValuePair("size", "80"));\r
+ \r
+ try {\r
+ httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));\r
+ // Webサーバからのレスポンスを処理\r
+ HttpResponse response = null;\r
+ response = httpClient.execute(httpPost);\r
+ byte[] bytes = EntityUtils.toByteArray(response.getEntity());\r
+ QByteArray data = new QByteArray(bytes);\r
+ // データベースにEvernoteサーバから取得したサムネイルを保存。例↓\r
+ // conn.getNoteTable().setThumbnail(guid, data);\r
+ } catch (UnsupportedEncodingException e) {\r
+ e.printStackTrace();\r
+ } catch (ClientProtocolException e) {\r
+ e.printStackTrace();\r
+ } catch (IOException e) {\r
+ e.printStackTrace();\r
+ }\r
+\r
+ httpClient.getConnectionManager().shutdown();\r
}\r
}\r