summaryrefslogtreecommitdiff
path: root/plugins/NewsAggregator/Src
diff options
context:
space:
mode:
authorKirill Volinsky <mataes2007@gmail.com>2015-08-09 16:07:24 +0000
committerKirill Volinsky <mataes2007@gmail.com>2015-08-09 16:07:24 +0000
commit5d9c244a7e5d677d51a57c5c681608e80b50f149 (patch)
tree26139ca1a534035a53d7414d3ea1c5482b920f66 /plugins/NewsAggregator/Src
parentbe0f676c577a79d71e91b6da864659809df1c5a9 (diff)
added support koi8r codepage
git-svn-id: http://svn.miranda-ng.org/main/trunk@14886 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/NewsAggregator/Src')
-rw-r--r--plugins/NewsAggregator/Src/CheckFeed.cpp138
-rw-r--r--plugins/NewsAggregator/Src/Options.cpp15
2 files changed, 125 insertions, 28 deletions
diff --git a/plugins/NewsAggregator/Src/CheckFeed.cpp b/plugins/NewsAggregator/Src/CheckFeed.cpp
index 8c2eac19fd..aa24ef077f 100644
--- a/plugins/NewsAggregator/Src/CheckFeed.cpp
+++ b/plugins/NewsAggregator/Src/CheckFeed.cpp
@@ -33,10 +33,19 @@ LPCTSTR CheckFeed(TCHAR *tszURL, HWND hwndDlg)
mir_free(tszData);
mir_free(szData);
if (hXml != NULL) {
+ LPCTSTR codepage = NULL;
int childcount = 0;
HXML node;
- if (!mir_tstrcmpi(xmlGetName(hXml), _T("xml")))
+ if (!mir_tstrcmpi(xmlGetName(hXml), _T("xml"))) {
+ for (int i = 0; xmlGetAttrCount(hXml); i++) {
+ LPCTSTR szAttrName = xmlGetAttrName(hXml, i);
+ if (!mir_tstrcmpi(szAttrName, _T("encoding"))) {
+ codepage = xmlGetAttrValue(hXml, szAttrName);
+ break;
+ }
+ }
node = xmlGetChild(hXml, childcount);
+ }
else
node = hXml;
while (node) {
@@ -49,7 +58,13 @@ LPCTSTR CheckFeed(TCHAR *tszURL, HWND hwndDlg)
TCHAR mes[MAX_PATH];
mir_sntprintf(mes, _countof(mes), TranslateT("%s\nis a valid feed's address."), tszURL);
MessageBox(hwndDlg, mes, TranslateT("News Aggregator"), MB_OK | MB_ICONINFORMATION);
- return xmlGetText(child);
+ if (!mir_tstrcmpi(codepage, _T("koi8-r"))) {
+ TCHAR buf[MAX_PATH];
+ MultiByteToWideChar(20866, 0, _T2A(xmlGetText(child)), -1, buf, _countof(buf));
+ return mir_tstrdup(buf);
+ }
+ else
+ return mir_tstrdup(xmlGetText(child));
}
}
}
@@ -60,7 +75,13 @@ LPCTSTR CheckFeed(TCHAR *tszURL, HWND hwndDlg)
TCHAR mes[MAX_PATH];
mir_sntprintf(mes, _countof(mes), TranslateT("%s\nis a valid feed's address."), tszURL);
MessageBox(hwndDlg, mes, TranslateT("News Aggregator"), MB_OK | MB_ICONINFORMATION);
- return xmlGetText(child);
+ if (!mir_tstrcmpi(codepage, _T("koi8-r"))) {
+ TCHAR buf[MAX_PATH];
+ MultiByteToWideChar(20866, 0, _T2A(xmlGetText(child)), -1, buf, _countof(buf));
+ return mir_tstrdup(buf);
+ }
+ else
+ return mir_tstrdup(xmlGetText(child));
}
}
}
@@ -182,10 +203,19 @@ void CheckCurrentFeed(MCONTACT hContact)
CMString szValue;
if (hXml != NULL) {
+ LPCTSTR codepage = NULL;
int childcount = 0;
HXML node;
- if (!mir_tstrcmpi(xmlGetName(hXml), _T("xml")))
+ if (!mir_tstrcmpi(xmlGetName(hXml), _T("xml"))) {
+ for (int i = 0; xmlGetAttrCount(hXml); i++) {
+ LPCTSTR szAttrName = xmlGetAttrName(hXml, i);
+ if (!mir_tstrcmpi(szAttrName, _T("encoding"))) {
+ codepage = xmlGetAttrValue(hXml, szAttrName);
+ break;
+ }
+ }
node = xmlGetChild(hXml, childcount);
+ }
else
node = hXml;
while (node) {
@@ -211,17 +241,38 @@ void CheckCurrentFeed(MCONTACT hContact)
HXML child = xmlGetChild(chan, j);
LPCTSTR childName = xmlGetName(child);
if (!mir_tstrcmpi(childName, _T("title"))) {
- LPCTSTR szChildText = xmlGetText(child);
+ LPCTSTR szChildText = NULL;
+ if (!mir_tstrcmpi(codepage, _T("koi8-r"))) {
+ TCHAR buf[MAX_PATH];
+ MultiByteToWideChar(20866, 0, _T2A(xmlGetText(child)), -1, buf, _countof(buf));
+ szChildText = buf;
+ }
+ else
+ szChildText = xmlGetText(child);
if (szChildText)
db_set_ts(hContact, MODULE, "FirstName", ClearText(szValue, szChildText));
}
else if (!mir_tstrcmpi(childName, _T("link"))) {
- LPCTSTR szChildText = xmlGetText(child);
+ LPCTSTR szChildText = NULL;
+ if (!mir_tstrcmpi(codepage, _T("koi8-r"))) {
+ TCHAR buf[MAX_PATH];
+ MultiByteToWideChar(20866, 0, _T2A(xmlGetText(child)), -1, buf, _countof(buf));
+ szChildText = buf;
+ }
+ else
+ szChildText = xmlGetText(child);
if (szChildText)
db_set_ts(hContact, MODULE, "Homepage", ClearText(szValue, szChildText));
}
else if (!mir_tstrcmpi(childName, _T("description"))) {
- LPCTSTR szChildText = xmlGetText(child);
+ LPCTSTR szChildText = NULL;
+ if (!mir_tstrcmpi(codepage, _T("koi8-r"))) {
+ TCHAR buf[MAX_PATH];
+ MultiByteToWideChar(20866, 0, _T2A(xmlGetText(child)), -1, buf, _countof(buf));
+ szChildText = buf;
+ }
+ else
+ szChildText = xmlGetText(child);
if (szChildText) {
ClearText(szValue, szChildText);
db_set_ts(hContact, MODULE, "About", szValue);
@@ -229,22 +280,50 @@ void CheckCurrentFeed(MCONTACT hContact)
}
}
else if (!mir_tstrcmpi(childName, _T("language"))) {
- LPCTSTR szChildText = xmlGetText(child);
+ LPCTSTR szChildText = NULL;
+ if (!mir_tstrcmpi(codepage, _T("koi8-r"))) {
+ TCHAR buf[MAX_PATH];
+ MultiByteToWideChar(20866, 0, _T2A(xmlGetText(child)), -1, buf, _countof(buf));
+ szChildText = buf;
+ }
+ else
+ szChildText = xmlGetText(child);
if (szChildText)
db_set_ts(hContact, MODULE, "Language1", ClearText(szValue, szChildText));
}
else if (!mir_tstrcmpi(childName, _T("managingEditor"))) {
- LPCTSTR szChildText = xmlGetText(child);
+ LPCTSTR szChildText = NULL;
+ if (!mir_tstrcmpi(codepage, _T("koi8-r"))) {
+ TCHAR buf[MAX_PATH];
+ MultiByteToWideChar(20866, 0, _T2A(xmlGetText(child)), -1, buf, _countof(buf));
+ szChildText = buf;
+ }
+ else
+ szChildText = xmlGetText(child);
if (szChildText)
db_set_ts(hContact, MODULE, "e-mail", ClearText(szValue, szChildText));
}
else if (!mir_tstrcmpi(childName, _T("category"))) {
- LPCTSTR szChildText = xmlGetText(child);
+ LPCTSTR szChildText = NULL;
+ if (!mir_tstrcmpi(codepage, _T("koi8-r"))) {
+ TCHAR buf[MAX_PATH];
+ MultiByteToWideChar(20866, 0, _T2A(xmlGetText(child)), -1, buf, _countof(buf));
+ szChildText = buf;
+ }
+ else
+ szChildText = xmlGetText(child);
if (szChildText)
db_set_ts(hContact, MODULE, "Interest0Text", ClearText(szValue, szChildText));
}
else if (!mir_tstrcmpi(childName, _T("copyright"))) {
- LPCTSTR szChildText = xmlGetText(child);
+ LPCTSTR szChildText = NULL;
+ if (!mir_tstrcmpi(codepage, _T("koi8-r"))) {
+ TCHAR buf[MAX_PATH];
+ MultiByteToWideChar(20866, 0, _T2A(xmlGetText(child)), -1, buf, _countof(buf));
+ szChildText = buf;
+ }
+ else
+ szChildText = xmlGetText(child);
if (szChildText)
db_set_s(hContact, "UserInfo", "MyNotes", _T2A(ClearText(szValue, szChildText)));
}
@@ -279,10 +358,16 @@ void CheckCurrentFeed(MCONTACT hContact)
}
}
else if (!mir_tstrcmpi(childName, _T("lastBuildDate"))) {
- LPCTSTR szChildText = xmlGetText(child);
+ LPCTSTR szChildText = NULL;
+ if (!mir_tstrcmpi(codepage, _T("koi8-r"))) {
+ TCHAR buf[MAX_PATH];
+ MultiByteToWideChar(20866, 0, _T2A(xmlGetText(child)), -1, buf, _countof(buf));
+ szChildText = buf;
+ }
+ else
+ szChildText = xmlGetText(child);
if (szChildText) {
- TCHAR *lastupdtime = (TCHAR *)xmlGetText(child);
- time_t stamp = DateToUnixTime(lastupdtime, 0);
+ time_t stamp = DateToUnixTime(szChildText, 0);
double deltaupd = difftime(time(NULL), stamp);
double deltacheck = difftime(time(NULL), (time_t)db_get_dw(hContact, MODULE, "LastCheck", 0));
if (deltaupd - deltacheck >= 0) {
@@ -298,31 +383,40 @@ void CheckCurrentFeed(MCONTACT hContact)
for (int z = 0; z < xmlGetChildCount(child); z++) {
HXML itemval = xmlGetChild(child, z);
LPCTSTR itemName = xmlGetName(itemval);
+ LPCTSTR value = NULL;
+ if (!mir_tstrcmpi(codepage, _T("koi8-r"))) {
+ TCHAR buf[MAX_PATH];
+ MultiByteToWideChar(20866, 0, _T2A(xmlGetText(itemval)), -1, buf, _countof(buf));
+ value = buf;
+ }
+ else
+ value = xmlGetText(itemval);
+
// We only use the first tag for now and ignore the rest.
if (!mir_tstrcmpi(itemName, _T("title")))
- ClearText(title, xmlGetText(itemval));
+ ClearText(title, value);
else if (!mir_tstrcmpi(itemName, _T("link")))
- ClearText(link, xmlGetText(itemval));
+ ClearText(link, value);
else if (!mir_tstrcmpi(itemName, _T("pubDate")) || !mir_tstrcmpi(itemName, _T("date"))) {
if (stamp == 0)
- stamp = DateToUnixTime(xmlGetText(itemval), 0);
+ stamp = DateToUnixTime(value, 0);
}
else if (!mir_tstrcmpi(itemName, _T("description")) || !mir_tstrcmpi(itemName, _T("encoded")))
- ClearText(descr, xmlGetText(itemval));
+ ClearText(descr, value);
else if (!mir_tstrcmpi(itemName, _T("author")) || !mir_tstrcmpi(itemName, _T("creator")))
- ClearText(author, xmlGetText(itemval));
+ ClearText(author, value);
else if (!mir_tstrcmpi(itemName, _T("comments")))
- ClearText(comments, xmlGetText(itemval));
+ ClearText(comments, value);
else if (!mir_tstrcmpi(itemName, _T("guid")))
- ClearText(guid, xmlGetText(itemval));
+ ClearText(guid, value);
else if (!mir_tstrcmpi(itemName, _T("category")))
- ClearText(category, xmlGetText(itemval));
+ ClearText(category, value);
}
XmlToMsg(hContact, title, link, descr, author, comments, guid, category, stamp);
diff --git a/plugins/NewsAggregator/Src/Options.cpp b/plugins/NewsAggregator/Src/Options.cpp
index 5ee94c2f90..ad0f4eaa46 100644
--- a/plugins/NewsAggregator/Src/Options.cpp
+++ b/plugins/NewsAggregator/Src/Options.cpp
@@ -115,12 +115,13 @@ INT_PTR CALLBACK DlgProcAddFeedOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
EnableWindow(GetDlgItem(hwndDlg, IDC_DISCOVERY), FALSE);
SetDlgItemText(hwndDlg, IDC_DISCOVERY, TranslateT("Wait..."));
TCHAR tszURL[MAX_PATH] = { 0 };
- const TCHAR *tszTitle = NULL;
+ TCHAR *tszTitle = NULL;
if (GetDlgItemText(hwndDlg, IDC_FEEDURL, tszURL, _countof(tszURL)) || mir_tstrcmp(tszURL, _T("http://")) != 0)
- tszTitle = CheckFeed(tszURL, hwndDlg);
+ tszTitle = (TCHAR*)CheckFeed(tszURL, hwndDlg);
else
MessageBox(hwndDlg, TranslateT("Enter Feed URL"), TranslateT("Error"), MB_OK);
SetDlgItemText(hwndDlg, IDC_FEEDTITLE, tszTitle);
+ mir_free(tszTitle);
EnableWindow(GetDlgItem(hwndDlg, IDC_DISCOVERY), TRUE);
SetDlgItemText(hwndDlg, IDC_DISCOVERY, TranslateT("Check Feed"));
}
@@ -282,8 +283,9 @@ INT_PTR CALLBACK DlgProcChangeFeedOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP
if (GetDlgItemText(hwndDlg, IDC_FEEDURL, tszURL, _countof(tszURL)) || mir_tstrcmp(tszURL, _T("http://")) != 0) {
EnableWindow(GetDlgItem(hwndDlg, IDC_DISCOVERY), FALSE);
SetDlgItemText(hwndDlg, IDC_DISCOVERY, TranslateT("Wait..."));
- const TCHAR *tszTitle = CheckFeed(tszURL, hwndDlg);
+ TCHAR *tszTitle = (TCHAR*)CheckFeed(tszURL, hwndDlg);
SetDlgItemText(hwndDlg, IDC_FEEDTITLE, tszTitle);
+ mir_free(tszTitle);
EnableWindow(GetDlgItem(hwndDlg, IDC_DISCOVERY), TRUE);
SetDlgItemText(hwndDlg, IDC_DISCOVERY, TranslateT("Check Feed"));
}
@@ -437,8 +439,9 @@ INT_PTR CALLBACK DlgProcChangeFeedMenu(HWND hwndDlg, UINT msg, WPARAM wParam, LP
if (GetDlgItemText(hwndDlg, IDC_FEEDURL, tszURL, _countof(tszURL)) || mir_tstrcmp(tszURL, _T("http://")) != 0) {
EnableWindow(GetDlgItem(hwndDlg, IDC_DISCOVERY), FALSE);
SetDlgItemText(hwndDlg, IDC_DISCOVERY, TranslateT("Wait..."));
- const TCHAR *tszTitle = CheckFeed(tszURL, hwndDlg);
+ TCHAR *tszTitle = (TCHAR*)CheckFeed(tszURL, hwndDlg);
SetDlgItemText(hwndDlg, IDC_FEEDTITLE, tszTitle);
+ mir_free(tszTitle);
EnableWindow(GetDlgItem(hwndDlg, IDC_DISCOVERY), TRUE);
SetDlgItemText(hwndDlg, IDC_DISCOVERY, TranslateT("Check Feed"));
}
@@ -497,7 +500,7 @@ INT_PTR CALLBACK UpdateNotifyOptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPA
case IDC_REMOVE:
if (MessageBox(hwndDlg, TranslateT("Are you sure?"), TranslateT("Contact deleting"), MB_YESNO | MB_ICONWARNING) == IDYES) {
TCHAR nick[MAX_PATH], url[MAX_PATH];
- sel = ListView_GetSelectionMark(hwndList);
+ int sel = ListView_GetSelectionMark(hwndList);
ListView_GetItemText(hwndList, sel, 0, nick, _countof(nick));
ListView_GetItemText(hwndList, sel, 1, url, _countof(url));
@@ -567,7 +570,7 @@ INT_PTR CALLBACK UpdateNotifyOptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPA
case LVN_ITEMCHANGED:
NMLISTVIEW *nmlv = (NMLISTVIEW *)lParam;
- sel = ListView_GetSelectionMark(hwndList);
+ int sel = ListView_GetSelectionMark(hwndList);
if (sel == -1) {
EnableWindow(GetDlgItem(hwndDlg, IDC_CHANGE), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_REMOVE), FALSE);