summaryrefslogtreecommitdiff
path: root/plugins/NewsAggregator
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/NewsAggregator')
-rw-r--r--plugins/NewsAggregator/Src/Authentication.cpp119
-rw-r--r--plugins/NewsAggregator/Src/CheckFeed.cpp10
-rw-r--r--plugins/NewsAggregator/Src/Options.cpp2
-rw-r--r--plugins/NewsAggregator/Src/Options.h30
-rw-r--r--plugins/NewsAggregator/Src/Utils.cpp22
-rw-r--r--plugins/NewsAggregator/Src/stdafx.h6
6 files changed, 160 insertions, 29 deletions
diff --git a/plugins/NewsAggregator/Src/Authentication.cpp b/plugins/NewsAggregator/Src/Authentication.cpp
index e53c4791a0..67fddd0f22 100644
--- a/plugins/NewsAggregator/Src/Authentication.cpp
+++ b/plugins/NewsAggregator/Src/Authentication.cpp
@@ -19,19 +19,21 @@ Boston, MA 02111-1307, USA.
#include "stdafx.h"
-void CreateAuthString(char *auth, MCONTACT hContact, HWND hwndDlg)
+void CreateAuthString(char *auth, MCONTACT hContact, CFeedEditor *pDlg)
{
wchar_t *tlogin = nullptr, *tpass = nullptr;
if (hContact && db_get_b(hContact, MODULE, "UseAuth", 0)) {
tlogin = db_get_wsa(hContact, MODULE, "Login");
tpass = db_get_wsa(hContact, MODULE, "Password");
}
- else if (hwndDlg && IsDlgButtonChecked(hwndDlg, IDC_USEAUTH)) {
- wchar_t buf[MAX_PATH] = {0};
- GetDlgItemText(hwndDlg, IDC_LOGIN, buf, _countof(buf));
- tlogin = mir_wstrdup(buf);
- GetDlgItemText(hwndDlg, IDC_PASSWORD, buf, _countof(buf));
- tpass = mir_wstrdup(buf);
+ else if (pDlg && pDlg->m_useauth.IsChecked()) {
+ ptrW strlogin(pDlg->m_login.GetText());
+ //wchar_t buf[MAX_PATH] = {0};
+ //GetDlgItemText(hwndDlg, IDC_LOGIN, buf, _countof(buf));
+ tlogin = mir_wstrdup(strlogin);
+ ptrW strpass(pDlg->m_password.GetText());
+ //GetDlgItemText(hwndDlg, IDC_PASSWORD, buf, _countof(buf));
+ tpass = mir_wstrdup(strpass);
}
char *user = mir_u2a(tlogin), *pass = mir_u2a(tpass);
@@ -45,7 +47,106 @@ void CreateAuthString(char *auth, MCONTACT hContact, HWND hwndDlg)
mir_snprintf(auth, 250, "Basic %s", ptrA(mir_base64_encode(str, len)));
}
-INT_PTR CALLBACK AuthenticationProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+CAuthRequest::CAuthRequest(CFeedEditor *pDlg, MCONTACT hContact)
+ : CSuper(hInst, IDD_AUTHENTICATION),
+ m_feedname(this, IDC_FEEDNAME), m_username(this, IDC_FEEDUSERNAME),
+ m_password(this, IDC_FEEDPASSWORD), m_ok(this, IDOK)
+{
+ m_pDlg = pDlg;
+ m_hContact = hContact;
+ m_ok.OnClick = Callback(this, &CAuthRequest::OnOk);
+}
+
+void CAuthRequest::OnInitDialog()
+{
+ if (m_pDlg) {
+ //wchar_t str[MAX_PATH];
+ ptrW strfeedtitle(m_pDlg->m_feedtitle.GetText());
+
+ if (strfeedtitle)
+ m_feedname.SetText(strfeedtitle);
+ else {
+ ptrW strfeedurl(m_pDlg->m_feedurl.GetText());
+ m_feedname.SetText(strfeedurl);
+ }
+
+ /*if (GetDlgItemText(SelItem.hwndList, IDC_FEEDTITLE, str, _countof(str)))
+ SetDlgItemText(hwndDlg, IDC_FEEDNAME, str);
+ else {
+ GetDlgItemText(SelItem.hwndList, IDC_FEEDURL, str, _countof(str));
+ SetDlgItemText(hwndDlg, IDC_FEEDNAME, str);
+ }*/
+ }
+ else if (m_hContact) {
+ wchar_t *ptszNick = db_get_wsa(m_hContact, MODULE, "Nick");
+ if (ptszNick) {
+ m_feedname.SetText(ptszNick);
+ //SetDlgItemText(hwndDlg, IDC_FEEDNAME, ptszNick);
+ mir_free(ptszNick);
+ }
+ else {
+ wchar_t *ptszURL = db_get_wsa(m_hContact, MODULE, "URL");
+ if (ptszURL) {
+ m_feedname.SetText(ptszURL);
+ //SetDlgItemText(hwndDlg, IDC_FEEDNAME, ptszURL);
+ mir_free(ptszURL);
+ }
+ }
+ }
+}
+
+void CAuthRequest::OnOk(CCtrlBase*)
+{
+ //ItemInfo &SelItem = *(ItemInfo*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
+ //wchar_t username[MAX_PATH];
+ //char passw[MAX_PATH];
+
+ ptrW strfeedusername(m_username.GetText());
+ if (!strfeedusername || mir_wstrcmp(strfeedusername, L"") == 0) {
+ MessageBox(m_hwnd, TranslateT("Enter your username"), TranslateT("Error"), MB_OK | MB_ICONERROR);
+ return;
+ }
+ ptrA strfeedpassword(m_password.GetTextA());
+ if (!strfeedpassword || mir_strcmp(strfeedpassword, "") == 0) {
+ MessageBox(m_hwnd, TranslateT("Enter your password"), TranslateT("Error"), MB_OK | MB_ICONERROR);
+ return;
+ }
+ /*if (!GetDlgItemText(hwndDlg, IDC_FEEDUSERNAME, username, _countof(username))) {
+ MessageBox(hwndDlg, TranslateT("Enter your username"), TranslateT("Error"), MB_OK | MB_ICONERROR);
+ break;
+ }
+ if (!GetDlgItemTextA(hwndDlg, IDC_FEEDPASSWORD, passw, _countof(passw))) {
+ MessageBox(hwndDlg, TranslateT("Enter your password"), TranslateT("Error"), MB_OK | MB_ICONERROR);
+ break;
+ }*/
+ if (m_pDlg) {
+ m_pDlg->m_useauth.SetState(1);
+ m_pDlg->m_login.Enable(1);
+ m_pDlg->m_password.Enable(1);
+ m_pDlg->m_login.SetText(strfeedusername);
+ m_pDlg->m_password.SetTextA(strfeedpassword);
+ }
+ else if (m_hContact) {
+ db_set_b(m_hContact, MODULE, "UseAuth", 1);
+ db_set_ws(m_hContact, MODULE, "Login", strfeedusername);
+ db_set_s(m_hContact, MODULE, "Password", strfeedpassword);
+
+ }
+ /*if (SelItem.hwndList) {
+ CheckDlgButton(SelItem.hwndList, IDC_USEAUTH, BST_CHECKED);
+ EnableWindow(GetDlgItem(SelItem.hwndList, IDC_LOGIN), TRUE);
+ EnableWindow(GetDlgItem(SelItem.hwndList, IDC_PASSWORD), TRUE);
+ SetDlgItemText(SelItem.hwndList, IDC_LOGIN, username);
+ SetDlgItemTextA(SelItem.hwndList, IDC_PASSWORD, passw);
+ }
+ else if (SelItem.hContact) {
+ db_set_b(SelItem.hContact, MODULE, "UseAuth", 1);
+ db_set_ws(SelItem.hContact, MODULE, "Login", username);
+ db_set_s(SelItem.hContact, MODULE, "Password", passw);
+ }*/
+}
+
+/*INT_PTR CALLBACK AuthenticationProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_INITDIALOG:
@@ -120,4 +221,4 @@ INT_PTR CALLBACK AuthenticationProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
break;
}
return FALSE;
-} \ No newline at end of file
+}*/ \ No newline at end of file
diff --git a/plugins/NewsAggregator/Src/CheckFeed.cpp b/plugins/NewsAggregator/Src/CheckFeed.cpp
index 11e482f5e0..448cf8d1da 100644
--- a/plugins/NewsAggregator/Src/CheckFeed.cpp
+++ b/plugins/NewsAggregator/Src/CheckFeed.cpp
@@ -19,11 +19,11 @@ Boston, MA 02111-1307, USA.
#include "stdafx.h"
-LPCTSTR CheckFeed(wchar_t *tszURL, HWND hwndDlg)
+LPCTSTR CheckFeed(wchar_t *tszURL, CFeedEditor *pEditDlg)
{
Netlib_LogfW(hNetlibUser, L"Started validating feed %s.", tszURL);
char *szData = nullptr;
- GetNewsData(tszURL, &szData, NULL, hwndDlg);
+ GetNewsData(tszURL, &szData, NULL, pEditDlg);
if (szData) {
wchar_t *tszData = mir_utf8decodeW(szData);
if (!tszData)
@@ -70,7 +70,7 @@ LPCTSTR CheckFeed(wchar_t *tszURL, HWND hwndDlg)
if (!mir_wstrcmpi(xmlGetName(child), L"title")) {
wchar_t mes[MAX_PATH];
mir_snwprintf(mes, TranslateT("%s\nis a valid feed's address."), tszURL);
- MessageBox(hwndDlg, mes, TranslateT("News Aggregator"), MB_OK | MB_ICONINFORMATION);
+ MessageBox(pEditDlg->GetHwnd(), mes, TranslateT("News Aggregator"), MB_OK | MB_ICONINFORMATION);
if (!mir_wstrcmpi(codepage, L"koi8-r")) {
wchar_t buf[MAX_PATH];
MultiByteToWideChar(20866, 0, _T2A(xmlGetText(child)), -1, buf, _countof(buf));
@@ -87,7 +87,7 @@ LPCTSTR CheckFeed(wchar_t *tszURL, HWND hwndDlg)
if (!mir_wstrcmpi(xmlGetName(child), L"title")) {
wchar_t mes[MAX_PATH];
mir_snwprintf(mes, TranslateT("%s\nis a valid feed's address."), tszURL);
- MessageBox(hwndDlg, mes, TranslateT("News Aggregator"), MB_OK | MB_ICONINFORMATION);
+ MessageBox(pEditDlg->GetHwnd(), mes, TranslateT("News Aggregator"), MB_OK | MB_ICONINFORMATION);
if (!mir_wstrcmpi(codepage, L"koi8-r")) {
wchar_t buf[MAX_PATH];
MultiByteToWideChar(20866, 0, _T2A(xmlGetText(child)), -1, buf, _countof(buf));
@@ -106,7 +106,7 @@ LPCTSTR CheckFeed(wchar_t *tszURL, HWND hwndDlg)
Netlib_LogfW(hNetlibUser, L"%s is not a valid feed's address.", tszURL);
wchar_t mes[MAX_PATH];
mir_snwprintf(mes, TranslateT("%s\nis not a valid feed's address."), tszURL);
- MessageBox(hwndDlg, mes, TranslateT("News Aggregator"), MB_OK | MB_ICONERROR);
+ MessageBox(pEditDlg->GetHwnd(), mes, TranslateT("News Aggregator"), MB_OK | MB_ICONERROR);
return nullptr;
}
diff --git a/plugins/NewsAggregator/Src/Options.cpp b/plugins/NewsAggregator/Src/Options.cpp
index 01b2262edc..f98fc6665e 100644
--- a/plugins/NewsAggregator/Src/Options.cpp
+++ b/plugins/NewsAggregator/Src/Options.cpp
@@ -773,7 +773,7 @@ void CFeedEditor::OnCheckFeed(CCtrlBase*)
wchar_t *tszTitle = nullptr;
ptrW strfeedurl(m_feedurl.GetText());
if (strfeedurl || mir_wstrcmp(strfeedurl, L"http://") != 0 || mir_wstrcmp(strfeedurl, L"") != 0)
- tszTitle = (wchar_t*)CheckFeed(strfeedurl, m_hwnd);
+ tszTitle = (wchar_t*)CheckFeed(strfeedurl, this);
else
MessageBox(m_hwnd, TranslateT("Enter Feed URL"), TranslateT("Error"), MB_OK);
m_feedtitle.SetText(tszTitle);
diff --git a/plugins/NewsAggregator/Src/Options.h b/plugins/NewsAggregator/Src/Options.h
index 51bafad7b3..0d75eda729 100644
--- a/plugins/NewsAggregator/Src/Options.h
+++ b/plugins/NewsAggregator/Src/Options.h
@@ -33,6 +33,8 @@ public:
class CFeedEditor : public CDlgBase
{
+ friend class CAuthRequest;
+
private:
typedef CDlgBase CSuper;
@@ -45,9 +47,6 @@ private:
CCtrlEdit m_checktime;
CCtrlSpin m_checktimespin;
CCtrlButton m_checkfeed;
- CCtrlCheck m_useauth;
- CCtrlEdit m_login;
- CCtrlEdit m_password;
CCtrlEdit m_tagedit;
CCtrlButton m_reset;
CCtrlButton m_help;
@@ -63,6 +62,10 @@ protected:
void OnUseAuth(CCtrlBase*);
public:
+ CCtrlCheck m_useauth;
+ CCtrlEdit m_login;
+ CCtrlEdit m_password;
+
CFeedEditor(int iItem, CCtrlListView *m_list, MCONTACT Contact);
__inline MCONTACT getContact() const { return m_hContact; }
@@ -131,4 +134,25 @@ public:
CExportFeed();
};
+class CAuthRequest : public CDlgBase
+{
+private:
+ typedef CDlgBase CSuper;
+
+ CFeedEditor *m_pDlg;
+ MCONTACT m_hContact;
+
+ CCtrlLabel m_feedname;
+ CCtrlEdit m_username;
+ CCtrlEdit m_password;
+ CCtrlButton m_ok;
+
+protected:
+ void OnInitDialog();
+ void OnOk(CCtrlBase*);
+
+public:
+ CAuthRequest(CFeedEditor *pDlg, MCONTACT hContact);
+};
+
#endif //_OPTIONS_H_ \ No newline at end of file
diff --git a/plugins/NewsAggregator/Src/Utils.cpp b/plugins/NewsAggregator/Src/Utils.cpp
index 43eb082f0f..03efcd2991 100644
--- a/plugins/NewsAggregator/Src/Utils.cpp
+++ b/plugins/NewsAggregator/Src/Utils.cpp
@@ -44,7 +44,7 @@ void NetlibUnInit()
hNetlibUser = nullptr;
}
-void GetNewsData(wchar_t *tszUrl, char **szData, MCONTACT hContact, HWND hwndDlg)
+void GetNewsData(wchar_t *tszUrl, char **szData, MCONTACT hContact, CFeedEditor *pEditDlg)
{
Netlib_LogfW(hNetlibUser, L"Getting feed data %s.", tszUrl);
NETLIBHTTPREQUEST nlhr = { 0 };
@@ -72,11 +72,11 @@ void GetNewsData(wchar_t *tszUrl, char **szData, MCONTACT hContact, HWND hwndDlg
nlhr.headers[3].szName = "Connection";
nlhr.headers[3].szValue = "close";
char auth[256];
- if (db_get_b(hContact, MODULE, "UseAuth", 0) || IsDlgButtonChecked(hwndDlg, IDC_USEAUTH)) {
+ if (db_get_b(hContact, MODULE, "UseAuth", 0) || pEditDlg->m_useauth.IsChecked() /*IsDlgButtonChecked(hwndDlg, IDC_USEAUTH)*/) {
nlhr.headersCount++;
nlhr.headers[4].szName = "Authorization";
- CreateAuthString(auth, hContact, hwndDlg);
+ CreateAuthString(auth, hContact, pEditDlg);
nlhr.headers[4].szValue = auth;
}
@@ -93,11 +93,17 @@ void GetNewsData(wchar_t *tszUrl, char **szData, MCONTACT hContact, HWND hwndDlg
}
else if (nlhrReply->resultCode == 401) {
Netlib_LogfW(hNetlibUser, L"Code 401: feed %s needs auth data.", tszUrl);
- ItemInfo SelItem = {};
- SelItem.hwndList = hwndDlg;
- SelItem.hContact = hContact;
- if (DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_AUTHENTICATION), hwndDlg, AuthenticationProc, (LPARAM)&SelItem) == IDOK)
- GetNewsData(tszUrl, szData, hContact, hwndDlg);
+
+ CAuthRequest *pDlg = new CAuthRequest(pEditDlg, hContact);
+ if (pDlg->DoModal() == IDOK)
+ GetNewsData(tszUrl, szData, hContact, pEditDlg);
+
+
+ //ItemInfo SelItem = {};
+ //SelItem.hwndList = hwndDlg;
+ //SelItem.hContact = hContact;
+ //if (DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_AUTHENTICATION), hwndDlg, AuthenticationProc, (LPARAM)&SelItem) == IDOK)
+ //GetNewsData(tszUrl, szData, hContact, hwndDlg);
}
else Netlib_LogfW(hNetlibUser, L"Code %d: Failed getting feed data %s.", nlhrReply->resultCode, tszUrl);
diff --git a/plugins/NewsAggregator/Src/stdafx.h b/plugins/NewsAggregator/Src/stdafx.h
index cc1978b908..213e858cc6 100644
--- a/plugins/NewsAggregator/Src/stdafx.h
+++ b/plugins/NewsAggregator/Src/stdafx.h
@@ -128,15 +128,15 @@ void CALLBACK timerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime
void CALLBACK timerProc2(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime);
bool IsMyContact(MCONTACT hContact);
-void GetNewsData(wchar_t *szUrl, char **szData, MCONTACT hContact, HWND hwndDlg);
+void GetNewsData(wchar_t *szUrl, char **szData, MCONTACT hContact, CFeedEditor *pEditDlg);
time_t __stdcall DateToUnixTime(const wchar_t *stamp, bool FeedType);
void CheckCurrentFeed(MCONTACT hContact);
void CheckCurrentFeedAvatar(MCONTACT hContact);
-LPCTSTR CheckFeed(wchar_t* tszURL, HWND hwndDlg);
+LPCTSTR CheckFeed(wchar_t* tszURL, CFeedEditor *pEditDlg);
void UpdateMenu(bool State);
LPCTSTR ClearText(CMStringW &value, const wchar_t *message);
bool DownloadFile(LPCTSTR tszURL, LPCTSTR tszLocal);
-void CreateAuthString(char *auth, MCONTACT hContact, HWND hwndDlg);
+void CreateAuthString(char *auth, MCONTACT hContact, CFeedEditor *pDlg);
INT_PTR CALLBACK AuthenticationProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
MCONTACT GetContactByNick(const wchar_t *nick);
MCONTACT GetContactByURL(const wchar_t *url);