summaryrefslogtreecommitdiff
path: root/plugins/Scriver
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2017-08-25 18:48:18 +0300
committerGeorge Hazan <ghazan@miranda.im>2017-08-25 18:48:18 +0300
commit425b12911e11a8902d2f1963c2ac9c17a8904b30 (patch)
tree73f135ae8d471498517c3a6b8f305fa46aa5871e /plugins/Scriver
parentcd4e21415d7f87e9c749eeb7749b832cfb79b69d (diff)
Scriver: killing that old shit with error dialog
Diffstat (limited to 'plugins/Scriver')
-rw-r--r--plugins/Scriver/src/globals.cpp9
-rw-r--r--plugins/Scriver/src/msgdialog.cpp4
-rw-r--r--plugins/Scriver/src/msgs.h29
-rw-r--r--plugins/Scriver/src/msgtimedout.cpp98
-rw-r--r--plugins/Scriver/src/sendqueue.cpp14
-rw-r--r--plugins/Scriver/src/version.h2
6 files changed, 68 insertions, 88 deletions
diff --git a/plugins/Scriver/src/globals.cpp b/plugins/Scriver/src/globals.cpp
index 670aabd547..7a174bf528 100644
--- a/plugins/Scriver/src/globals.cpp
+++ b/plugins/Scriver/src/globals.cpp
@@ -128,13 +128,8 @@ static int ackevent(WPARAM, LPARAM lParam)
if (hwndSender != nullptr) {
SendMessage(hwndSender, DM_STOPMESSAGESENDING, 0, 0);
- ErrorWindowData *ewd = (ErrorWindowData*)mir_alloc(sizeof(ErrorWindowData));
- ewd->szName = mir_wstrdup(pcli->pfnGetContactDisplayName(item->hContact, 0));
- ewd->szDescription = mir_a2u((char *)pAck->lParam);
- ewd->szText = GetSendBufferMsg(item);
- ewd->hwndParent = hwndSender;
- ewd->queueItem = item;
- SendMessage(hwndSender, DM_SHOWERRORMESSAGE, 0, (LPARAM)ewd);
+ CErrorDlg *pDlg = new CErrorDlg(_A2T((char *)pAck->lParam), hwndSender, item);
+ SendMessage(hwndSender, DM_SHOWERRORMESSAGE, 0, (LPARAM)pDlg);
}
else RemoveSendQueueItem(item);
}
diff --git a/plugins/Scriver/src/msgdialog.cpp b/plugins/Scriver/src/msgdialog.cpp
index 838642e9b3..b47ae074f9 100644
--- a/plugins/Scriver/src/msgdialog.cpp
+++ b/plugins/Scriver/src/msgdialog.cpp
@@ -1542,9 +1542,9 @@ INT_PTR CSrmmWindow::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
case DM_SHOWERRORMESSAGE:
if (lParam) {
- ErrorWindowData *ewd = (ErrorWindowData *)lParam;
SendMessage(m_hwnd, DM_STOPMESSAGESENDING, 0, 0);
- ewd->queueItem->hwndErrorDlg = CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_MSGSENDERROR), m_hwnd, ErrorDlgProc, (LPARAM)ewd);//m_hwnd
+ CErrorDlg *pDlg = (CErrorDlg*)lParam;
+ pDlg->Create();
}
break;
diff --git a/plugins/Scriver/src/msgs.h b/plugins/Scriver/src/msgs.h
index 86de8bf663..bb209cb686 100644
--- a/plugins/Scriver/src/msgs.h
+++ b/plugins/Scriver/src/msgs.h
@@ -36,15 +36,6 @@ struct ToolbarButton
int width;
};
-struct ErrorWindowData
-{
- wchar_t *szName;
- wchar_t *szDescription;
- wchar_t *szText;
- MessageSendQueueItem *queueItem;
- HWND hwndParent;
-};
-
struct TabCtrlData
{
int lastClickTime;
@@ -276,7 +267,25 @@ public:
#define EVENTTYPE_JABBER_CHATSTATES 2000
#define EVENTTYPE_JABBER_PRESENCE 2001
-INT_PTR CALLBACK ErrorDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
+class CErrorDlg : public CDlgBase
+{
+ ptrW m_wszText;
+ CMStringW m_wszName, m_wszDescr;
+ MessageSendQueueItem *m_queueItem;
+ HWND m_hwndParent;
+
+ CCtrlButton m_btnOk, m_btnCancel;
+
+protected:
+ virtual void OnInitDialog() override;
+
+public:
+ CErrorDlg(const wchar_t *pwszDescr, HWND, MessageSendQueueItem*);
+
+ void onOk(CCtrlButton*);
+ void onCancel(CCtrlButton*);
+};
+
int DbEventIsShown(DBEVENTINFO &dbei);
int DbEventIsCustomForMsgWindow(DBEVENTINFO *dbei);
int DbEventIsMessageOrCustom(DBEVENTINFO *dbei);
diff --git a/plugins/Scriver/src/msgtimedout.cpp b/plugins/Scriver/src/msgtimedout.cpp
index 19dbca5900..e9fb7d7435 100644
--- a/plugins/Scriver/src/msgtimedout.cpp
+++ b/plugins/Scriver/src/msgtimedout.cpp
@@ -23,64 +23,50 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "stdafx.h"
-INT_PTR CALLBACK ErrorDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+CErrorDlg::CErrorDlg(const wchar_t *pwszDescr, HWND hWnd, MessageSendQueueItem *pItem)
+ : CDlgBase(g_hInst, IDD_MSGSENDERROR),
+ m_wszText(mir_utf8decodeW(pItem->sendBuffer)),
+ m_wszDescr(pwszDescr != nullptr ? pwszDescr : TranslateT("An unknown error has occurred.")),
+ m_hwndParent(hWnd),
+ m_queueItem(pItem),
+
+ m_btnOk(this, IDOK),
+ m_btnCancel(this, IDCANCEL)
+{
+ const wchar_t *pwszName = pcli->pfnGetContactDisplayName(pItem->hContact, 0);
+ if (pwszName)
+ m_wszName.Format(L"%s - %s", TranslateT("Send error"), pwszName);
+ else
+ m_wszName = TranslateT("Send error");
+
+ m_btnOk.OnClick = Callback(this, &CErrorDlg::onOk);
+ m_btnCancel.OnClick = Callback(this, &CErrorDlg::onCancel);
+}
+
+void CErrorDlg::OnInitDialog()
{
- ErrorWindowData *ewd = (ErrorWindowData *) GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
- //if (ewd==nullptr && msg!=WM_INITDIALOG) return FALSE;
- switch (msg) {
- case WM_INITDIALOG:
- {
- RECT rc, rcParent;
- wchar_t szText[2048];
- ewd = (ErrorWindowData *) lParam;
- SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR) ewd);
- TranslateDialogDefault(hwndDlg);
- if (ewd != nullptr) {
- ShowWindow(GetParent(ewd->hwndParent), SW_RESTORE);
- if (ewd->szDescription)
- SetDlgItemText(hwndDlg, IDC_ERRORTEXT, ewd->szDescription);
- else
- SetDlgItemText(hwndDlg, IDC_ERRORTEXT, TranslateT("An unknown error has occurred."));
+ ShowWindow(GetParent(m_hwndParent), SW_RESTORE);
+
+ SetDlgItemText(m_hwnd, IDC_ERRORTEXT, m_wszDescr);
+ SetWindowText(m_hwnd, m_wszName);
- if (ewd->szText) {
- SETTEXTEX st = {0};
- st.flags = ST_DEFAULT;
- st.codepage = 1200;
-
- SendDlgItemMessage(hwndDlg, IDC_MSGTEXT, EM_SETTEXTEX, (WPARAM)&st, (LPARAM)ewd->szText);
- }
- if (ewd->szName)
- mir_snwprintf(szText, L"%s - %s", TranslateT("Send error"), ewd->szName);
- else
- wcsncpy_s(szText, TranslateT("Send error"), _TRUNCATE);
+ SETTEXTEX st = { 0 };
+ st.flags = ST_DEFAULT;
+ st.codepage = 1200;
+ SendDlgItemMessage(m_hwnd, IDC_MSGTEXT, EM_SETTEXTEX, (WPARAM)&st, (LPARAM)m_wszText.get());
- SetWindowText(hwndDlg, szText);
- GetWindowRect(hwndDlg, &rc);
- GetWindowRect(GetParent(ewd->hwndParent), &rcParent);
- SetWindowPos(hwndDlg, HWND_TOP, rcParent.left + (rcParent.right - rcParent.left - rc.right + rc.left) / 2, rcParent.top + (rcParent.bottom - rcParent.top - rc.bottom + rc.top) / 2, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
- }
- }
- return TRUE;
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDOK:
- SendMessage(ewd->hwndParent, DM_ERRORDECIDED, MSGERROR_RETRY, (LPARAM)ewd->queueItem);
- DestroyWindow(hwndDlg);
- break;
- case IDCANCEL:
- SendMessage(ewd->hwndParent, DM_ERRORDECIDED, MSGERROR_CANCEL, (LPARAM)ewd->queueItem);
- DestroyWindow(hwndDlg);
- break;
- }
- break;
- case WM_DESTROY:
- SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0);
- mir_free(ewd->szName);
- mir_free(ewd->szDescription);
- mir_free(ewd->szText);
- mir_free(ewd);
- break;
+ RECT rc, rcParent;
+ GetWindowRect(m_hwnd, &rc);
+ GetWindowRect(GetParent(m_hwndParent), &rcParent);
+ SetWindowPos(m_hwnd, HWND_TOP, rcParent.left + (rcParent.right - rcParent.left - rc.right + rc.left) / 2, rcParent.top + (rcParent.bottom - rcParent.top - rc.bottom + rc.top) / 2, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
+}
- }
- return FALSE;
+void CErrorDlg::onOk(CCtrlButton*)
+{
+ SendMessage(m_hwndParent, DM_ERRORDECIDED, MSGERROR_RETRY, (LPARAM)m_queueItem);
+}
+
+void CErrorDlg::onCancel(CCtrlButton*)
+{
+ SendMessage(m_hwndParent, DM_ERRORDECIDED, MSGERROR_CANCEL, (LPARAM)m_queueItem);
}
diff --git a/plugins/Scriver/src/sendqueue.cpp b/plugins/Scriver/src/sendqueue.cpp
index 576f7a9131..b4bbd3055f 100644
--- a/plugins/Scriver/src/sendqueue.cpp
+++ b/plugins/Scriver/src/sendqueue.cpp
@@ -26,11 +26,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static MessageSendQueueItem *global_sendQueue = nullptr;
static mir_cs queueMutex;
-wchar_t* GetSendBufferMsg(MessageSendQueueItem *item)
-{
- return mir_utf8decodeW(item->sendBuffer);
-}
-
MessageSendQueueItem* CreateSendQueueItem(HWND hwndSender)
{
MessageSendQueueItem *item = (MessageSendQueueItem*)mir_calloc(sizeof(MessageSendQueueItem));
@@ -103,13 +98,8 @@ void ReportSendQueueTimeouts(HWND hwndSender)
if (item->timeout >= timeout) {
if (item->hwndSender == hwndSender && item->hwndErrorDlg == nullptr) {
if (hwndSender != nullptr) {
- ErrorWindowData *ewd = (ErrorWindowData *)mir_alloc(sizeof(ErrorWindowData));
- ewd->szName = mir_wstrdup(pcli->pfnGetContactDisplayName(item->hContact, 0));
- ewd->szDescription = mir_wstrdup(TranslateT("The message send timed out."));
- ewd->szText = GetSendBufferMsg(item);
- ewd->hwndParent = hwndSender;
- ewd->queueItem = item;
- PostMessage(hwndSender, DM_SHOWERRORMESSAGE, 0, (LPARAM)ewd);
+ CErrorDlg *pDlg = new CErrorDlg(TranslateT("The message send timed out."), hwndSender, item);
+ PostMessage(hwndSender, DM_SHOWERRORMESSAGE, 0, (LPARAM)pDlg);
}
else {
/* TODO: Handle errors outside messaging window in a better way */
diff --git a/plugins/Scriver/src/version.h b/plugins/Scriver/src/version.h
index 0e20a58284..b695210147 100644
--- a/plugins/Scriver/src/version.h
+++ b/plugins/Scriver/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 3
#define __MINOR_VERSION 0
#define __RELEASE_NUM 1
-#define __BUILD_NUM 6
+#define __BUILD_NUM 7
#include <stdver.h>