diff options
author | George Hazan <george.hazan@gmail.com> | 2023-11-23 12:53:42 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2023-11-23 12:53:42 +0300 |
commit | b8fcbbd4a229485f217dde7d4fa641e8c708cdb7 (patch) | |
tree | e8771ba54cf2178bf2a64fc40c174c439b94f202 /protocols/NewsAggregator/Src/FeedEditor.cpp | |
parent | 7675a61c539439908e4573f36921484d44322dba (diff) |
more code reordering
Diffstat (limited to 'protocols/NewsAggregator/Src/FeedEditor.cpp')
-rw-r--r-- | protocols/NewsAggregator/Src/FeedEditor.cpp | 227 |
1 files changed, 227 insertions, 0 deletions
diff --git a/protocols/NewsAggregator/Src/FeedEditor.cpp b/protocols/NewsAggregator/Src/FeedEditor.cpp new file mode 100644 index 0000000000..bcf6c3535f --- /dev/null +++ b/protocols/NewsAggregator/Src/FeedEditor.cpp @@ -0,0 +1,227 @@ +/* +Copyright (C) 2012-23 Miranda NG team (https://miranda-ng.org) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation version 2 +of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "stdafx.h" + +CFeedEditor::CFeedEditor(int iItem, CCtrlListView *m_feeds, MCONTACT Contact) : + CSuper(g_plugin, IDD_ADDFEED), + m_feedtitle(this, IDC_FEEDTITLE), m_feedurl(this, IDC_FEEDURL), + m_checktime(this, IDC_CHECKTIME), m_checktimespin(this, IDC_TIMEOUT_VALUE_SPIN, 999), + m_checkfeed(this, IDC_DISCOVERY), m_useauth(this, IDC_USEAUTH), + m_login(this, IDC_LOGIN), m_password(this, IDC_PASSWORD), + m_tagedit(this, IDC_TAGSEDIT), m_reset(this, IDC_RESET), + m_help(this, IDC_TAGHELP), + m_iItem(iItem) +{ + m_list = m_feeds; + m_hContact = Contact; + m_checkfeed.OnClick = Callback(this, &CFeedEditor::OnCheckFeed); + m_useauth.OnChange = Callback(this, &CFeedEditor::OnUseAuth); + m_reset.OnClick = Callback(this, &CFeedEditor::OnReset); + m_help.OnClick = Callback(this, &CFeedEditor::OnHelp); +} + +bool CFeedEditor::OnInitDialog() +{ + if (m_iItem == -1 && m_hContact == NULL) + SetWindowText(m_hwnd, TranslateT("Add Feed")); + else + SetWindowText(m_hwnd, TranslateT("Change Feed")); + m_checktime.SetMaxLength(3); + + if (m_iItem > -1 && m_hContact == 0) { + wchar_t SelNick[MAX_PATH], SelUrl[MAX_PACKAGE_NAME]; + m_list->GetItemText(m_iItem, 0, SelNick, _countof(SelNick)); + m_list->GetItemText(m_iItem, 1, SelUrl, _countof(SelNick)); + + for (auto &hContact : Contacts(MODULENAME)) { + ptrW dbNick(g_plugin.getWStringA(hContact, "Nick")); + if ((dbNick == NULL) || (mir_wstrcmp(dbNick, SelNick) != 0)) + continue; + + ptrW dbURL(g_plugin.getWStringA(hContact, "URL")); + if ((dbURL == NULL) || (mir_wstrcmp(dbURL, SelUrl) != 0)) + continue; + + m_hContact = hContact; + m_feedtitle.SetText(SelNick); + m_feedurl.SetText(SelUrl); + m_checktime.SetInt(g_plugin.getDword(hContact, "UpdateTime", DEFAULT_UPDATE_TIME)); + + ptrW szMsgFormat(g_plugin.getWStringA(hContact, "MsgFormat")); + if (szMsgFormat) + m_tagedit.SetText(szMsgFormat); + + if (g_plugin.getByte(hContact, "UseAuth", 0)) { + m_useauth.SetState(1); + m_login.Enable(); + m_password.Enable(); + + ptrW szLogin(g_plugin.getWStringA(hContact, "Login")); + if (szLogin) + m_login.SetText(szLogin); + + pass_ptrA pwd(g_plugin.getStringA(hContact, "Password")); + m_password.SetTextA(pwd); + } + g_arFeeds.insert(this); + Utils_RestoreWindowPositionNoSize(m_hwnd, hContact, MODULENAME, "ChangeDlg"); + break; + } + } + else if (m_iItem == -1 && m_hContact == NULL) { + m_feedurl.SetText(L"https://"); + m_tagedit.SetText(TAGSDEFAULT); + m_checktime.SetInt(DEFAULT_UPDATE_TIME); + Utils_RestoreWindowPositionNoSize(m_hwnd, NULL, MODULENAME, "AddDlg"); + } + else if (m_hContact != NULL) { + ptrW dbNick(g_plugin.getWStringA(m_hContact, "Nick")); + ptrW dbURL(g_plugin.getWStringA(m_hContact, "URL")); + + m_feedtitle.SetText(dbNick); + m_feedurl.SetText(dbURL); + m_checktime.SetInt(g_plugin.getDword(m_hContact, "UpdateTime", DEFAULT_UPDATE_TIME)); + + ptrW szMsgFormat(g_plugin.getWStringA(m_hContact, "MsgFormat")); + if (szMsgFormat) + m_tagedit.SetText(szMsgFormat); + + if (g_plugin.getByte(m_hContact, "UseAuth")) { + m_useauth.SetState(1); + m_login.Enable(); + m_password.Enable(); + + ptrW szLogin(g_plugin.getWStringA(m_hContact, "Login")); + if (szLogin) + m_login.SetText(szLogin); + + pass_ptrA pwd(g_plugin.getStringA(m_hContact, "Password")); + m_password.SetTextA(pwd); + } + g_arFeeds.insert(this); + Utils_RestoreWindowPositionNoSize(m_hwnd, m_hContact, MODULENAME, "ChangeDlg"); + } + return true; +} + +void CFeedEditor::OnCheckFeed(CCtrlBase*) +{ + m_checkfeed.Disable(); + m_checkfeed.SetText(TranslateT("Wait...")); + 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, this); + else + MessageBox(m_hwnd, TranslateT("Enter Feed URL"), TranslateT("Error"), MB_OK); + m_feedtitle.SetText(tszTitle); + mir_free(tszTitle); + m_checkfeed.Enable(); + m_checkfeed.SetText(TranslateT("Check Feed")); +} + +void CFeedEditor::OnReset(CCtrlBase*) +{ + if (MessageBox(m_hwnd, TranslateT("Are you sure?"), TranslateT("Tags Mask Reset"), MB_YESNO | MB_ICONWARNING) == IDYES) + m_tagedit.SetText(TAGSDEFAULT); +} + +void CFeedEditor::OnHelp(CCtrlBase*) +{ + CMStringW wszTagHelp; + wszTagHelp.Format(L"%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s", + L"#<title>#", TranslateT("The title of the item."), + L"#<description>#", TranslateT("The item synopsis."), + L"#<link>#", TranslateT("The URL of the item."), + L"#<author>#", TranslateT("Email address of the author of the item."), + L"#<comments>#", TranslateT("URL of a page for comments relating to the item."), + L"#<guid>#", TranslateT("A string that uniquely identifies the item."), + L"#<category>#", TranslateT("Specify one or more categories that the item belongs to.")); + MessageBox(m_hwnd, wszTagHelp, TranslateT("Feed Tag Help"), MB_OK); +} + +bool CFeedEditor::OnApply() +{ + ptrW strfeedtitle(m_feedtitle.GetText()); + if (!strfeedtitle || mir_wstrcmp(strfeedtitle, L"") == 0) { + MessageBox(m_hwnd, TranslateT("Enter Feed name"), TranslateT("Error"), MB_OK); + return false; + } + + ptrW strfeedurl(m_feedurl.GetText()); + if (!strfeedurl || mir_wstrcmp(strfeedurl, L"http://") == 0 || mir_wstrcmp(strfeedurl, L"") == 0) { + MessageBox(m_hwnd, TranslateT("Enter Feed URL"), TranslateT("Error"), MB_OK); + return false; + } + + ptrW strtagedit(m_tagedit.GetText()); + if (!strtagedit || mir_wstrcmp(strtagedit, L"") == 0) { + MessageBox(m_hwnd, TranslateT("Enter message format"), TranslateT("Error"), MB_OK); + return false; + } + + MCONTACT hContact; + if (m_iItem == -1 && m_hContact == NULL) { + hContact = db_add_contact(); + Proto_AddToContact(hContact, MODULENAME); + g_plugin.setByte(hContact, "CheckState", 1); + Contact::Readonly(hContact); + } + else hContact = m_hContact; + + g_plugin.setWString(hContact, "Nick", strfeedtitle); + g_plugin.setWString(hContact, "URL", strfeedurl); + g_plugin.setDword(hContact, "UpdateTime", m_checktime.GetInt()); + g_plugin.setWString(hContact, "MsgFormat", strtagedit); + g_plugin.setWord(hContact, "Status", Proto_GetStatus(MODULENAME)); + if (m_useauth.IsChecked()) { + g_plugin.setByte(hContact, "UseAuth", 1); + g_plugin.setWString(hContact, "Login", m_login.GetText()); + g_plugin.setString(hContact, "Password", m_password.GetTextA()); + } + else { + g_plugin.delSetting(hContact, "UseAuth"); + g_plugin.delSetting(hContact, "Login"); + g_plugin.delSetting(hContact, "Password"); + } + + if (m_iItem == -1 && m_list != nullptr && m_hContact == NULL) { + int iItem = m_list->AddItem(strfeedtitle, -1); + m_list->SetItem(iItem, 1, strfeedurl); + m_list->SetCheckState(iItem, 1); + } + else if (m_iItem > -1) { + m_list->SetItem(m_iItem, 0, strfeedtitle); + m_list->SetItem(m_iItem, 1, strfeedurl); + } + return true; +} + +void CFeedEditor::OnDestroy() +{ + g_arFeeds.remove(this); + Utils_SaveWindowPosition(m_hwnd, NULL, MODULENAME, m_iItem == -1 ? "AddDlg" : "ChangeDlg"); + if (pAddFeedDialog == this) + pAddFeedDialog = nullptr; +} + +void CFeedEditor::OnUseAuth(CCtrlBase*) +{ + m_login.Enable(m_useauth.GetState()); + m_password.Enable(m_useauth.GetState()); +} |