summaryrefslogtreecommitdiff
path: root/plugins/NewsAggregator/Src
diff options
context:
space:
mode:
authorKirill Volinsky <mataes2007@gmail.com>2018-03-10 14:43:21 +0300
committerKirill Volinsky <mataes2007@gmail.com>2018-03-10 14:43:21 +0300
commit9ac7612dc78f25b9b8bcb2fa97e4b9eb587abf3a (patch)
tree9d21ace4d688791ae1d4cd8ddbd9bdcca33c4513 /plugins/NewsAggregator/Src
parentab48946296156b94919b0ee31d2ac6404a3cc4c2 (diff)
NewsAggregator: crash fix, fully on m_gui
Diffstat (limited to 'plugins/NewsAggregator/Src')
-rw-r--r--plugins/NewsAggregator/Src/Authentication.cpp120
-rw-r--r--plugins/NewsAggregator/Src/Options.cpp34
-rw-r--r--plugins/NewsAggregator/Src/Options.h2
-rw-r--r--plugins/NewsAggregator/Src/Services.cpp11
-rw-r--r--plugins/NewsAggregator/Src/Utils.cpp72
-rw-r--r--plugins/NewsAggregator/Src/stdafx.h10
6 files changed, 43 insertions, 206 deletions
diff --git a/plugins/NewsAggregator/Src/Authentication.cpp b/plugins/NewsAggregator/Src/Authentication.cpp
index 67fddd0f22..7ff29ede9a 100644
--- a/plugins/NewsAggregator/Src/Authentication.cpp
+++ b/plugins/NewsAggregator/Src/Authentication.cpp
@@ -27,13 +27,8 @@ void CreateAuthString(char *auth, MCONTACT hContact, CFeedEditor *pDlg)
tpass = db_get_wsa(hContact, MODULE, "Password");
}
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);
+ tlogin = pDlg->m_login.GetText();
+ tpass = pDlg->m_password.GetText();
}
char *user = mir_u2a(tlogin), *pass = mir_u2a(tpass);
@@ -60,7 +55,6 @@ CAuthRequest::CAuthRequest(CFeedEditor *pDlg, MCONTACT hContact)
void CAuthRequest::OnInitDialog()
{
if (m_pDlg) {
- //wchar_t str[MAX_PATH];
ptrW strfeedtitle(m_pDlg->m_feedtitle.GetText());
if (strfeedtitle)
@@ -69,26 +63,17 @@ void CAuthRequest::OnInitDialog()
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);
}
}
@@ -97,10 +82,6 @@ void CAuthRequest::OnInitDialog()
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);
@@ -111,14 +92,6 @@ void CAuthRequest::OnOk(CCtrlBase*)
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);
@@ -132,93 +105,4 @@ void CAuthRequest::OnOk(CCtrlBase*)
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:
- {
- TranslateDialogDefault(hwndDlg);
- ItemInfo &SelItem = *(ItemInfo*)lParam;
- SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)&SelItem);
-
- if (SelItem.hwndList) {
- wchar_t str[MAX_PATH];
- 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 (SelItem.hContact) {
- wchar_t *ptszNick = db_get_wsa(SelItem.hContact, MODULE, "Nick");
- if (ptszNick) {
- SetDlgItemText(hwndDlg, IDC_FEEDNAME, ptszNick);
- mir_free(ptszNick);
- }
- else {
- wchar_t *ptszURL = db_get_wsa(SelItem.hContact, MODULE, "URL");
- if (ptszURL) {
- SetDlgItemText(hwndDlg, IDC_FEEDNAME, ptszURL);
- mir_free(ptszURL);
- }
- }
- }
- }
- return TRUE;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDOK:
- {
- ItemInfo &SelItem = *(ItemInfo*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
- wchar_t username[MAX_PATH];
- char passw[MAX_PATH];
- 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 (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);
- }
- EndDialog(hwndDlg, IDOK);
- return TRUE;
- }
-
- case IDCANCEL:
- {
- EndDialog(hwndDlg, IDCANCEL);
- return TRUE;
- }
- }
- break;
- }
- return FALSE;
-}*/ \ No newline at end of file
diff --git a/plugins/NewsAggregator/Src/Options.cpp b/plugins/NewsAggregator/Src/Options.cpp
index f98fc6665e..8fc2685e8c 100644
--- a/plugins/NewsAggregator/Src/Options.cpp
+++ b/plugins/NewsAggregator/Src/Options.cpp
@@ -952,14 +952,42 @@ void COptionsMain::OnAddButtonClick(CCtrlBase*)
pAddFeedDialog->SetParent(m_hwnd);
pAddFeedDialog->Show();
}
+ else {
+ SetForegroundWindow(pAddFeedDialog->GetHwnd());
+ SetFocus(pAddFeedDialog->GetHwnd());
+ }
}
void COptionsMain::OnChangeButtonClick(CCtrlBase*)
{
int isel = m_feeds.GetSelectionMark();
- CFeedEditor *pDlg = new CFeedEditor(isel, &m_feeds, NULL);
- pDlg->SetParent(m_hwnd);
- pDlg->Show();
+ CFeedEditor *pDlg = nullptr;
+ for (auto &it : g_arFeeds)
+ {
+ wchar_t nick[MAX_PATH], url[MAX_PATH];
+ m_feeds.GetItemText(isel, 0, nick, _countof(nick));
+ m_feeds.GetItemText(isel, 1, url, _countof(url));
+
+ ptrW dbNick(db_get_wsa(it->getContact(), MODULE, "Nick"));
+ if ((dbNick == NULL) || (mir_wstrcmp(dbNick, nick) != 0))
+ continue;
+
+ ptrW dbURL(db_get_wsa(it->getContact(), MODULE, "URL"));
+ if ((dbURL == NULL) || (mir_wstrcmp(dbURL, url) != 0))
+ continue;
+
+ pDlg = it;
+ }
+
+ if (pDlg == nullptr) {
+ pDlg = new CFeedEditor(isel, &m_feeds, NULL);
+ pDlg->SetParent(m_hwnd);
+ pDlg->Show();
+ }
+ else {
+ SetForegroundWindow(pDlg->GetHwnd());
+ SetFocus(pDlg->GetHwnd());
+ }
}
void COptionsMain::OnDeleteButtonClick(CCtrlBase*)
diff --git a/plugins/NewsAggregator/Src/Options.h b/plugins/NewsAggregator/Src/Options.h
index 0d75eda729..9abe024737 100644
--- a/plugins/NewsAggregator/Src/Options.h
+++ b/plugins/NewsAggregator/Src/Options.h
@@ -142,7 +142,7 @@ private:
CFeedEditor *m_pDlg;
MCONTACT m_hContact;
- CCtrlLabel m_feedname;
+ CCtrlBase m_feedname;
CCtrlEdit m_username;
CCtrlEdit m_password;
CCtrlButton m_ok;
diff --git a/plugins/NewsAggregator/Src/Services.cpp b/plugins/NewsAggregator/Src/Services.cpp
index 07a40ef28f..8999731766 100644
--- a/plugins/NewsAggregator/Src/Services.cpp
+++ b/plugins/NewsAggregator/Src/Services.cpp
@@ -56,8 +56,6 @@ int NewsAggrInit(WPARAM, LPARAM)
int NewsAggrPreShutdown(WPARAM, LPARAM)
{
- //WindowList_Broadcast(hChangeFeedDlgList, WM_CLOSE, 0, 0);
-
KillTimer(nullptr, timerId);
NetlibUnInit();
return 0;
@@ -149,9 +147,14 @@ INT_PTR CheckAllFeeds(WPARAM, LPARAM lParam)
INT_PTR AddFeed(WPARAM, LPARAM)
{
- if (pAddFeedDialog == nullptr)
+ if (pAddFeedDialog == nullptr) {
pAddFeedDialog = new CFeedEditor(-1, nullptr, NULL);
- pAddFeedDialog->Show();
+ pAddFeedDialog->Show();
+ }
+ else {
+ SetForegroundWindow(pAddFeedDialog->GetHwnd());
+ SetFocus(pAddFeedDialog->GetHwnd());
+ }
return 0;
}
diff --git a/plugins/NewsAggregator/Src/Utils.cpp b/plugins/NewsAggregator/Src/Utils.cpp
index 03efcd2991..75bb109315 100644
--- a/plugins/NewsAggregator/Src/Utils.cpp
+++ b/plugins/NewsAggregator/Src/Utils.cpp
@@ -72,7 +72,7 @@ void GetNewsData(wchar_t *tszUrl, char **szData, MCONTACT hContact, CFeedEditor
nlhr.headers[3].szName = "Connection";
nlhr.headers[3].szValue = "close";
char auth[256];
- if (db_get_b(hContact, MODULE, "UseAuth", 0) || pEditDlg->m_useauth.IsChecked() /*IsDlgButtonChecked(hwndDlg, IDC_USEAUTH)*/) {
+ if (db_get_b(hContact, MODULE, "UseAuth", 0) || (pEditDlg && pEditDlg->m_useauth.IsChecked()) /*IsDlgButtonChecked(hwndDlg, IDC_USEAUTH)*/) {
nlhr.headersCount++;
nlhr.headers[4].szName = "Authorization";
@@ -94,16 +94,8 @@ void GetNewsData(wchar_t *tszUrl, char **szData, MCONTACT hContact, CFeedEditor
else if (nlhrReply->resultCode == 401) {
Netlib_LogfW(hNetlibUser, L"Code 401: feed %s needs auth data.", tszUrl);
- CAuthRequest *pDlg = new CAuthRequest(pEditDlg, hContact);
- if (pDlg->DoModal() == IDOK)
+ if (CAuthRequest(pEditDlg, hContact).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);
@@ -114,66 +106,6 @@ void GetNewsData(wchar_t *tszUrl, char **szData, MCONTACT hContact, CFeedEditor
mir_free(szUrl);
}
-void CreateList(HWND hwndList)
-{
- SendMessage(hwndList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES);
-
- LVCOLUMN lvc = { 0 };
- // Initialize the LVCOLUMN structure.
- // The mask specifies that the format, width, text, and
- // subitem members of the structure are valid.
- lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
- lvc.fmt = LVCFMT_LEFT;
-
- lvc.iSubItem = 0;
- lvc.pszText = TranslateT("Feed");
- lvc.cx = 160; // width of column in pixels
- ListView_InsertColumn(hwndList, 0, &lvc);
-
- lvc.iSubItem = 1;
- lvc.pszText = TranslateT("URL");
- lvc.cx = 276; // width of column in pixels
- ListView_InsertColumn(hwndList, 1, &lvc);
-}
-
-void UpdateList(HWND hwndList)
-{
- LVITEM lvI = { 0 };
-
- // Some code to create the list-view control.
- // Initialize LVITEM members that are common to all
- // items.
- int i = 0;
- for (MCONTACT hContact = db_find_first(MODULE); hContact; hContact = db_find_next(hContact, MODULE)) {
- UpdateListFlag = TRUE;
- lvI.mask = LVIF_TEXT;
- lvI.iSubItem = 0;
- wchar_t *ptszNick = db_get_wsa(hContact, MODULE, "Nick");
- if (ptszNick) {
- lvI.pszText = ptszNick;
- lvI.iItem = i;
- ListView_InsertItem(hwndList, &lvI);
- lvI.iSubItem = 1;
-
- wchar_t *ptszURL = db_get_wsa(hContact, MODULE, "URL");
- if (ptszURL) {
- lvI.pszText = ptszURL;
- ListView_SetItem(hwndList, &lvI);
- i++;
- ListView_SetCheckState(hwndList, lvI.iItem, db_get_b(hContact, MODULE, "CheckState", 1));
- mir_free(ptszURL);
- }
- mir_free(ptszNick);
- }
- }
- UpdateListFlag = FALSE;
-}
-
-void DeleteAllItems(HWND hwndList)
-{
- ListView_DeleteAllItems(hwndList);
-}
-
time_t __stdcall DateToUnixTime(const wchar_t *stamp, bool FeedType)
{
struct tm timestamp;
diff --git a/plugins/NewsAggregator/Src/stdafx.h b/plugins/NewsAggregator/Src/stdafx.h
index 213e858cc6..0c5fa1436d 100644
--- a/plugins/NewsAggregator/Src/stdafx.h
+++ b/plugins/NewsAggregator/Src/stdafx.h
@@ -69,15 +69,6 @@ extern bool ThreadRunning;
extern bool UpdateListFlag;
extern wchar_t tszRoot[MAX_PATH];
-struct ItemInfo
-{
- HWND hwndList;
- MCONTACT hContact;
- int SelNumber;
- wchar_t nick[MAX_PATH];
- wchar_t url[MAX_PATH];
-};
-
//============ STRUCT USED TO MAKE AN UPDATE LIST ============
struct NEWSCONTACTLIST {
@@ -137,7 +128,6 @@ void UpdateMenu(bool State);
LPCTSTR ClearText(CMStringW &value, const wchar_t *message);
bool DownloadFile(LPCTSTR tszURL, LPCTSTR tszLocal);
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);