diff options
author | Kirill Volinsky <mataes2007@gmail.com> | 2013-07-21 10:34:15 +0000 |
---|---|---|
committer | Kirill Volinsky <mataes2007@gmail.com> | 2013-07-21 10:34:15 +0000 |
commit | 25bbf4a64df769564aa3b177712dfd21d910edab (patch) | |
tree | 503427c269d2be71237771bd66e336dffab721df /plugins/NewsAggregator | |
parent | f8f7f8976a4c05afb34e6b4a89116d244ce73d5f (diff) |
import now working correctly
git-svn-id: http://svn.miranda-ng.org/main/trunk@5439 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/NewsAggregator')
-rw-r--r-- | plugins/NewsAggregator/Res/Resource.rc | 2 | ||||
-rw-r--r-- | plugins/NewsAggregator/Src/ExportImport.cpp | 349 | ||||
-rw-r--r-- | plugins/NewsAggregator/Src/Options.cpp | 2 | ||||
-rw-r--r-- | plugins/NewsAggregator/Src/Services.cpp | 2 |
4 files changed, 352 insertions, 3 deletions
diff --git a/plugins/NewsAggregator/Res/Resource.rc b/plugins/NewsAggregator/Res/Resource.rc index 7cea0b83f8..ab418aebdf 100644 --- a/plugins/NewsAggregator/Res/Resource.rc +++ b/plugins/NewsAggregator/Res/Resource.rc @@ -126,7 +126,7 @@ CAPTION "Import" FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
LTEXT "Import from:",IDC_STATIC,6,7,47,8
- EDITTEXT IDC_IMPORTFILEPATH,59,5,186,14,ES_AUTOHSCROLL,WS_EX_ACCEPTFILES
+ EDITTEXT IDC_IMPORTFILEPATH,59,5,186,14,ES_AUTOHSCROLL | ES_READONLY
PUSHBUTTON "...",IDC_BROWSEIMPORTFILE,248,5,22,14
LTEXT "Available feeds:",IDC_STATIC,6,26,100,8
LTEXT "Feeds to be imported:",IDC_STATIC,150,26,101,8
diff --git a/plugins/NewsAggregator/Src/ExportImport.cpp b/plugins/NewsAggregator/Src/ExportImport.cpp index 3aadc4f22f..021f4078df 100644 --- a/plugins/NewsAggregator/Src/ExportImport.cpp +++ b/plugins/NewsAggregator/Src/ExportImport.cpp @@ -193,23 +193,372 @@ int ImportFeedsDialog() INT_PTR CALLBACK DlgProcImportOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
+ HWND FeedsList = GetDlgItem(hwndDlg, IDC_FEEDSLIST);
+ HWND FeedsImportList = GetDlgItem(hwndDlg, IDC_FEEDSIMPORTLIST);
+
switch (msg) {
case WM_INITDIALOG:
TranslateDialogDefault(hwndDlg);
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
Utils_RestoreWindowPositionNoSize(hwndDlg, NULL, MODULE, "ImportDlg");
+ EnableWindow(GetDlgItem(hwndDlg, IDC_REMOVEFEED), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_REMOVEALLFEEDS), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDOK), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_ADDFEED), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_ADDALLFEEDS), FALSE);
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
{
+ TCHAR FileName[MAX_PATH];
+ GetDlgItemText(hwndDlg, IDC_IMPORTFILEPATH, FileName, SIZEOF(FileName));
+ int bytesParsed = 0;
+ HXML hXml = xi.parseFile(FileName, &bytesParsed, NULL);
+ if(hXml != NULL) {
+ HWND hwndList = (HWND)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
+ BYTE isTitleUTF = 0, isURLUTF = 0, isSiteURLUTF = 0, isGroupUTF = 0;
+ HXML node = xi.getChildByPath(hXml, _T("opml/body/outline"), 0);
+ if ( !node)
+ node = xi.getChildByPath(hXml, _T("body/outline"), 0);
+ if (node) {
+ while (node) {
+ int outlineAttr = xi.getAttrCount(node);
+ int outlineChildsCount = xi.getChildCount(node);
+ TCHAR *type = (TCHAR *)xi.getAttrValue(node, _T("type"));
+ if ( !type && !outlineChildsCount) {
+ HXML tmpnode = node;
+ node = xi.getNextNode(node);
+ if ( !node) {
+ do {
+ node = tmpnode;
+ node = xi.getParent(node);
+ tmpnode = node;
+ node = xi.getNextNode(node);
+ if (node)
+ break;
+ } while (lstrcmpi(xi.getName(node), _T("body")));
+ }
+ }
+ else if (!type && outlineChildsCount)
+ node = xi.getFirstChild(node);
+ else if (type) {
+ TCHAR *title = NULL, *url = NULL, *siteurl = NULL, *group = NULL, *utfgroup = NULL;
+ BYTE NeedToImport = FALSE;
+ for (int i = 0; i < outlineAttr; i++) {
+ if (!lstrcmpi(xi.getAttrName(node, i), _T("title"))) {
+ title = mir_utf8decodeT(_T2A(xi.getAttrValue(node, xi.getAttrName(node, i))));
+ if ( !title) {
+ isTitleUTF = 0;
+ title = (TCHAR *)xi.getAttrValue(node, xi.getAttrName(node, i));
+ } else
+ isTitleUTF = 1;
+
+ int count = SendMessage(FeedsImportList, LB_GETCOUNT, 0, 0);
+ for (int i = 0; i < count; i++) {
+ TCHAR item[MAX_PATH];
+ SendMessage(FeedsImportList, LB_GETTEXT, i, (LPARAM)item);
+ if (!lstrcmpi(item, title)) {
+ NeedToImport = TRUE;
+ break;
+ }
+ }
+ continue;
+ }
+ if (!lstrcmpi(xi.getAttrName(node, i), _T("xmlUrl"))) {
+ url = mir_utf8decodeT(_T2A(xi.getAttrValue(node, xi.getAttrName(node, i))));
+ if ( !url) {
+ isURLUTF = 0;
+ url = (TCHAR *)xi.getAttrValue(node, xi.getAttrName(node, i));
+ } else
+ isURLUTF = 1;
+ continue;
+ }
+ if (!lstrcmpi(xi.getAttrName(node, i), _T("htmlUrl"))) {
+ siteurl = mir_utf8decodeT(_T2A(xi.getAttrValue(node, xi.getAttrName(node, i))));
+ if ( !siteurl) {
+ isSiteURLUTF = 0;
+ siteurl = (TCHAR *)xi.getAttrValue(node, xi.getAttrName(node, i));
+ } else
+ isSiteURLUTF = 1;
+ continue;
+ }
+ if (title && url && siteurl)
+ break;
+ }
+
+ if (NeedToImport) {
+ HXML parent = xi.getParent(node);
+ while (lstrcmpi(xi.getName(parent), _T("body"))) {
+ for (int i = 0; i < xi.getAttrCount(parent); i++) {
+ if (!lstrcmpi(xi.getAttrName(parent, i), _T("title"))) {
+ if ( !group)
+ group = (TCHAR *)xi.getAttrValue(parent, xi.getAttrName(parent, i));
+ else {
+ TCHAR tmpgroup[1024];
+ mir_sntprintf(tmpgroup, SIZEOF(tmpgroup), _T("%s\\%s"), xi.getAttrValue(parent, xi.getAttrName(parent, i)), group);
+ group = tmpgroup;
+ }
+ break;
+ }
+ }
+ parent = xi.getParent(parent);
+ }
+
+ if (group) {
+ utfgroup = mir_utf8decodeT(_T2A(group));
+ if ( !utfgroup) {
+ isGroupUTF = 0;
+ utfgroup = group;
+ } else
+ isGroupUTF = 1;
+ }
+
+ HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_ADD, 0, 0);
+ CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hContact, (LPARAM)MODULE);
+ db_set_ts(hContact, MODULE, "Nick", title);
+ db_set_ts(hContact, MODULE, "URL", url);
+ db_set_ts(hContact, MODULE, "Homepage", siteurl);
+ db_set_b(hContact, MODULE, "CheckState", 1);
+ db_set_dw(hContact, MODULE, "UpdateTime", DEFAULT_UPDATE_TIME);
+ db_set_ts(hContact, MODULE, "MsgFormat", _T(TAGSDEFAULT));
+ db_set_w(hContact, MODULE, "Status", CallProtoService(MODULE, PS_GETSTATUS, 0, 0));
+ if (utfgroup) {
+ db_set_ts(hContact, "CList", "Group", utfgroup);
+ int hGroup = 1;
+ char *group_name;
+ BYTE GroupExist = 0;
+ do {
+ group_name = (char *)CallService(MS_CLIST_GROUPGETNAME, (WPARAM)hGroup, 0);
+ if (group_name != NULL && !strcmp(group_name, _T2A(utfgroup))) {
+ GroupExist = 1;
+ break;
+ }
+ hGroup++;
+ }
+ while (group_name);
+
+ if(!GroupExist)
+ CallService(MS_CLIST_GROUPCREATE, 0, (LPARAM)utfgroup);
+ }
+ if (isTitleUTF)
+ mir_free(title);
+ if (isURLUTF)
+ mir_free(url);
+ if (isGroupUTF)
+ mir_free(utfgroup);
+ if (isSiteURLUTF)
+ mir_free(siteurl);
+ }
+
+ HXML tmpnode = node;
+ node = xi.getNextNode(node);
+ if ( !node) {
+ do {
+ node = tmpnode;
+ node = xi.getParent(node);
+ tmpnode = node;
+ node = xi.getNextNode(node);
+ if (node)
+ break;
+ }
+ while (lstrcmpi(xi.getName(tmpnode), _T("body")));
+ }
+ }
+ }
+ }
+ xi.destroyNode(hXml);
+ if (hwndList) {
+ DeleteAllItems(hwndList);
+ UpdateList(hwndList);
+ }
+ }
}
case IDCANCEL:
DestroyWindow(hwndDlg);
break;
+ case IDC_BROWSEIMPORTFILE:
+ {
+ TCHAR FileName[MAX_PATH];
+ TCHAR *tszMirDir = Utils_ReplaceVarsT(_T("%miranda_path%"));
+
+ OPENFILENAME ofn = {0};
+ ofn.lStructSize = sizeof(ofn);
+ TCHAR tmp[MAX_PATH];
+ mir_sntprintf(tmp, SIZEOF(tmp), _T("%s (*.opml, *.xml)%c*.opml;*.xml%c%c"), TranslateT("OPML files"), 0, 0, 0);
+ ofn.lpstrFilter = tmp;
+ ofn.hwndOwner = 0;
+ ofn.lpstrFile = FileName;
+ ofn.nMaxFile = MAX_PATH;
+ ofn.nMaxFileTitle = MAX_PATH;
+ ofn.Flags = OFN_HIDEREADONLY;
+ ofn.lpstrInitialDir = tszMirDir;
+ *FileName = '\0';
+ ofn.lpstrDefExt = _T("");
+
+ if (GetOpenFileName(&ofn)) {
+ int bytesParsed = 0;
+ HXML hXml = xi.parseFile(FileName, &bytesParsed, NULL);
+ if(hXml != NULL) {
+ BYTE isTitleUTF = 0;
+ HXML node = xi.getChildByPath(hXml, _T("opml/body/outline"), 0);
+ if ( !node)
+ node = xi.getChildByPath(hXml, _T("body/outline"), 0);
+ if (node) {
+ while (node) {
+ int outlineAttr = xi.getAttrCount(node);
+ int outlineChildsCount = xi.getChildCount(node);
+ TCHAR *type = (TCHAR *)xi.getAttrValue(node, _T("type"));
+ if ( !type && !outlineChildsCount) {
+ HXML tmpnode = node;
+ node = xi.getNextNode(node);
+ if ( !node) {
+ do {
+ node = tmpnode;
+ node = xi.getParent(node);
+ tmpnode = node;
+ node = xi.getNextNode(node);
+ if (node)
+ break;
+ } while (lstrcmpi(xi.getName(node), _T("body")));
+ }
+ }
+ else if (!type && outlineChildsCount)
+ node = xi.getFirstChild(node);
+ else if (type) {
+ TCHAR *title = NULL;
+ for (int i = 0; i < outlineAttr; i++) {
+ if (!lstrcmpi(xi.getAttrName(node, i), _T("title"))) {
+ title = mir_utf8decodeT(_T2A(xi.getAttrValue(node, xi.getAttrName(node, i))));
+ if ( !title) {
+ isTitleUTF = 0;
+ title = (TCHAR *)xi.getAttrValue(node, xi.getAttrName(node, i));
+ } else
+ isTitleUTF = 1;
+ SendMessage(FeedsList, LB_ADDSTRING, 0, (LPARAM)title);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_ADDFEED), TRUE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_ADDALLFEEDS), TRUE);
+ continue;
+ }
+ }
+
+ if (isTitleUTF)
+ mir_free(title);
+
+ HXML tmpnode = node;
+ node = xi.getNextNode(node);
+ if ( !node) {
+ do {
+ node = tmpnode;
+ node = xi.getParent(node);
+ tmpnode = node;
+ node = xi.getNextNode(node);
+ if (node)
+ break;
+ } while (lstrcmpi(xi.getName(tmpnode), _T("body")));
+ }
+ }
+ }
+ }
+ else
+ MessageBox(NULL, TranslateT("Not valid import file."), TranslateT("Error"), MB_OK | MB_ICONERROR);
+ xi.destroyNode(hXml);
+ SetDlgItemText(hwndDlg, IDC_IMPORTFILEPATH, FileName);
+ }
+ else
+ MessageBox(NULL, TranslateT("Not valid import file."), TranslateT("Error"), MB_OK | MB_ICONERROR);
+
+ mir_free(tszMirDir);
+ break;
+ }
+ mir_free(tszMirDir);
+ break;
+ }
+ break;
+
+ case IDC_ADDFEED:
+ {
+ if (!IsWindowEnabled(GetDlgItem(hwndDlg, IDC_REMOVEFEED)))
+ EnableWindow(GetDlgItem(hwndDlg, IDC_REMOVEFEED), TRUE);
+ if (!IsWindowEnabled(GetDlgItem(hwndDlg, IDC_REMOVEALLFEEDS)))
+ EnableWindow(GetDlgItem(hwndDlg, IDC_REMOVEALLFEEDS), TRUE);
+ if (!IsWindowEnabled(GetDlgItem(hwndDlg, IDOK)))
+ EnableWindow(GetDlgItem(hwndDlg, IDOK), TRUE);
+ int cursel = SendMessage(FeedsList, LB_GETCURSEL, 0, 0);
+ TCHAR item[MAX_PATH];
+ SendMessage(FeedsList, LB_GETTEXT, cursel, (LPARAM)item);
+ SendMessage(FeedsImportList, LB_ADDSTRING, 0, (LPARAM)item);
+ SendMessage(FeedsList, LB_DELETESTRING, cursel, 0);
+ if (!SendMessage(FeedsList, LB_GETCOUNT, 0, 0)) {
+ EnableWindow(GetDlgItem(hwndDlg, IDC_ADDFEED), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_ADDALLFEEDS), FALSE);
+ }
+ }
+ break;
+
+ case IDC_REMOVEFEED:
+ {
+ if (!IsWindowEnabled(GetDlgItem(hwndDlg, IDC_ADDFEED)))
+ EnableWindow(GetDlgItem(hwndDlg, IDC_ADDFEED), TRUE);
+ if (!IsWindowEnabled(GetDlgItem(hwndDlg, IDC_ADDALLFEEDS)))
+ EnableWindow(GetDlgItem(hwndDlg, IDC_ADDALLFEEDS), TRUE);
+ int cursel = SendMessage(FeedsImportList, LB_GETCURSEL, 0, 0);
+ TCHAR item[MAX_PATH];
+ SendMessage(FeedsImportList, LB_GETTEXT, cursel, (LPARAM)item);
+ SendMessage(FeedsList, LB_ADDSTRING, 0, (LPARAM)item);
+ SendMessage(FeedsImportList, LB_DELETESTRING, cursel, 0);
+ if (!SendMessage(FeedsImportList, LB_GETCOUNT, 0, 0))
+ {
+ EnableWindow(GetDlgItem(hwndDlg, IDC_REMOVEFEED), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_REMOVEALLFEEDS), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDOK), FALSE);
+ }
+ }
+ break;
+
+ case IDC_ADDALLFEEDS:
+ {
+ if (!IsWindowEnabled(GetDlgItem(hwndDlg, IDC_REMOVEFEED)))
+ EnableWindow(GetDlgItem(hwndDlg, IDC_REMOVEFEED), TRUE);
+ if (!IsWindowEnabled(GetDlgItem(hwndDlg, IDC_REMOVEALLFEEDS)))
+ EnableWindow(GetDlgItem(hwndDlg, IDC_REMOVEALLFEEDS), TRUE);
+ if (!IsWindowEnabled(GetDlgItem(hwndDlg, IDOK)))
+ EnableWindow(GetDlgItem(hwndDlg, IDOK), TRUE);
+ int count = SendMessage(FeedsList, LB_GETCOUNT, 0, 0);
+ for (int i = 0; i < count; i++) {
+ TCHAR item[MAX_PATH];
+ SendMessage(FeedsList, LB_GETTEXT, i, (LPARAM)item);
+ SendMessage(FeedsImportList, LB_ADDSTRING, 0, (LPARAM)item);
+ }
+ for (int i = count - 1; i > -1; i--)
+ SendMessage(FeedsList, LB_DELETESTRING, i, 0);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_ADDFEED), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_ADDALLFEEDS), FALSE);
+ }
+ break;
+
+ case IDC_REMOVEALLFEEDS:
+ {
+ if (!IsWindowEnabled(GetDlgItem(hwndDlg, IDC_ADDFEED)))
+ EnableWindow(GetDlgItem(hwndDlg, IDC_ADDFEED), TRUE);
+ if (!IsWindowEnabled(GetDlgItem(hwndDlg, IDC_ADDALLFEEDS)))
+ EnableWindow(GetDlgItem(hwndDlg, IDC_ADDALLFEEDS), TRUE);
+ int count = SendMessage(FeedsImportList, LB_GETCOUNT, 0, 0);
+ for (int i = 0; i < count; i++) {
+ TCHAR item[MAX_PATH];
+ SendMessage(FeedsImportList, LB_GETTEXT, i, (LPARAM)item);
+ SendMessage(FeedsList, LB_ADDSTRING, 0, (LPARAM)item);
+ }
+ for (int i = count - 1; i > -1; i--)
+ SendMessage(FeedsImportList, LB_DELETESTRING, i, 0);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_REMOVEFEED), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_REMOVEALLFEEDS), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDOK), FALSE);
+ }
+ break;
}
break;
diff --git a/plugins/NewsAggregator/Src/Options.cpp b/plugins/NewsAggregator/Src/Options.cpp index b00dfae7fb..bcc128ab46 100644 --- a/plugins/NewsAggregator/Src/Options.cpp +++ b/plugins/NewsAggregator/Src/Options.cpp @@ -529,7 +529,7 @@ INT_PTR CALLBACK UpdateNotifyOptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPA return FALSE;
case IDC_IMPORT:
- CreateDialog(hInst, MAKEINTRESOURCE(IDD_FEEDIMPORT), hwndDlg, DlgProcImportOpts);
+ CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_FEEDIMPORT), hwndDlg, DlgProcImportOpts, (LPARAM)hwndList);
return FALSE;
case IDC_EXPORT:
diff --git a/plugins/NewsAggregator/Src/Services.cpp b/plugins/NewsAggregator/Src/Services.cpp index f4d296ebfe..733d325dd9 100644 --- a/plugins/NewsAggregator/Src/Services.cpp +++ b/plugins/NewsAggregator/Src/Services.cpp @@ -186,7 +186,7 @@ INT_PTR ChangeFeed(WPARAM wParam, LPARAM lParam) INT_PTR ImportFeeds(WPARAM wParam, LPARAM lParam)
{
- ImportFeedsDialog();
+ CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_FEEDIMPORT), NULL, DlgProcImportOpts, NULL);
return 0;
}
|