summaryrefslogtreecommitdiff
path: root/plugins/NewStory
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2020-05-04 13:03:00 +0300
committerGeorge Hazan <ghazan@miranda.im>2020-05-04 13:03:00 +0300
commit7df671fa2b5260ab25ec456af143ce66e17a43d5 (patch)
treedbc8f0e348b7662f76ad7bdbf62692447796fb75 /plugins/NewStory
parent1f6bcd03f61b94992bf8171b5271a979f6203828 (diff)
NewStory:
- mind blowing enum EventLoadMode removed and replaced with the simple bool flag; - massive memory leak removed; - wtext_del flag removed (now all strings are allocated via mir_alloc()); - displayed events now are marked as read if needed
Diffstat (limited to 'plugins/NewStory')
-rw-r--r--plugins/NewStory/src/history.cpp3
-rw-r--r--plugins/NewStory/src/history_array.cpp130
-rw-r--r--plugins/NewStory/src/history_array.h25
-rw-r--r--plugins/NewStory/src/history_control.cpp22
-rw-r--r--plugins/NewStory/src/options.cpp4
-rw-r--r--plugins/NewStory/src/stdafx.h2
6 files changed, 68 insertions, 118 deletions
diff --git a/plugins/NewStory/src/history.cpp b/plugins/NewStory/src/history.cpp
index e295d7ccf3..a9a0a05ba3 100644
--- a/plugins/NewStory/src/history.cpp
+++ b/plugins/NewStory/src/history.cpp
@@ -991,8 +991,7 @@ public:
tvi.hItem = TreeView_GetSelection(m_timeTree.GetHwnd());
tvi.mask = TVIF_HANDLE | TVIF_TEXT;
TreeView_GetItem(m_timeTree.GetHwnd(), &tvi);
- wchar_t* tmp, * tmp2;
- tmp = tvi.pszText;
+
/*HTREEITEM hti2 = TreeView_GetParent(m_timeTree.GetHwnd(), hti);
if (hti2) {
tvi.hItem = hti2;
diff --git a/plugins/NewStory/src/history_array.cpp b/plugins/NewStory/src/history_array.cpp
index 0a021831d4..6f9de4be95 100644
--- a/plugins/NewStory/src/history_array.cpp
+++ b/plugins/NewStory/src/history_array.cpp
@@ -32,80 +32,65 @@ bool Filter::check(ItemData *item)
}
if (flags & (EVENTTEXT | EVENTONLY)) {
- item->loadInline(ItemData::ELM_DATA);
+ item->load(true);
return CheckFilter(item->getWBuf(), text);
}
return true;
};
// Event
-bool ItemData::load(EventLoadMode mode)
+void ItemData::load(bool bFullLoad)
{
- if (mode == ItemData::ELM_NOTHING)
- return true;
-
- if ((mode == ItemData::ELM_INFO) && !dbeOk) {
- dbeOk = true;
- dbe.cbBlob = 0;
- dbe.pBlob = 0;
- db_event_get(hEvent, &dbe);
- return true;
- }
+ if (!bFullLoad || bLoaded)
+ return;
- if ((mode == ItemData::ELM_DATA) && (!dbeOk || !dbe.cbBlob)) {
- dbeOk = true;
- dbe.cbBlob = db_event_getBlobSize(hEvent);
- dbe.pBlob = (PBYTE)mir_calloc(dbe.cbBlob + 1);
- db_event_get(hEvent, &dbe);
+ dbe.cbBlob = db_event_getBlobSize(hEvent);
+ dbe.pBlob = (PBYTE)mir_calloc(dbe.cbBlob + 1);
+ if (db_event_get(hEvent, &dbe))
+ return;
- wtext = 0;
+ bLoaded = true;
- switch (dbe.eventType) {
- case EVENTTYPE_STATUSCHANGE:
- case EVENTTYPE_MESSAGE:
- wtext = mir_utf8decodeW((char*)dbe.pBlob);
- wtext_del = false;
- break;
+ switch (dbe.eventType) {
+ case EVENTTYPE_STATUSCHANGE:
+ wtext = mir_utf8decodeW((char*)dbe.pBlob);
+ break;
- case EVENTTYPE_JABBER_PRESENCE:
- wtext = DbEvent_GetTextW(&dbe, CP_ACP);
- wtext_del = false;
- break;
-
- case EVENTTYPE_AUTHREQUEST:
- wtext = new wchar_t[512];
- wtext_del = true;
- if ((dbe.cbBlob > 8) && *(dbe.pBlob + 8)) {
- mir_snwprintf(wtext, 512, L"%s requested authorization", Utf2T((char*)dbe.pBlob + 8).get());
- }
- else {
- mir_snwprintf(wtext, 512, L"%d requested authorization", *(DWORD *)(dbe.pBlob));
- }
- break;
+ case EVENTTYPE_MESSAGE:
+ wtext = mir_utf8decodeW((char *)dbe.pBlob);
- case EVENTTYPE_ADDED:
- wtext = new wchar_t[512];
- wtext_del = true;
- if ((dbe.cbBlob > 8) && *(dbe.pBlob + 8)) {
- mir_snwprintf(wtext, 512, L"%s added you to the contact list", Utf2T((char *)dbe.pBlob + 8).get());
- }
- else {
- mir_snwprintf(wtext, 512, L"%d added you to the contact list", *(DWORD *)(dbe.pBlob));
- }
- break;
+ if (!(dbe.flags & DBEF_SENT)) {
+ if (!dbe.markedRead())
+ db_event_markRead(hContact, hEvent);
+ g_clistApi.pfnRemoveEvent(hContact, hEvent);
}
-
- return true;
+ break;
+
+ case EVENTTYPE_JABBER_PRESENCE:
+ wtext = DbEvent_GetTextW(&dbe, CP_ACP);
+ break;
+
+ case EVENTTYPE_AUTHREQUEST:
+ if ((dbe.cbBlob > 8) && *(dbe.pBlob + 8))
+ wtext = CMStringW(FORMAT, L"%s requested authorization", Utf2T((char*)dbe.pBlob + 8).get()).Detach();
+ else
+ wtext = CMStringW(FORMAT, L"%d requested authorization", *(DWORD *)(dbe.pBlob)).Detach();
+ break;
+
+ case EVENTTYPE_ADDED:
+ if ((dbe.cbBlob > 8) && *(dbe.pBlob + 8))
+ wtext = CMStringW(FORMAT, L"%s added you to the contact list", Utf2T((char *)dbe.pBlob + 8).get()).Detach();
+ else
+ wtext = CMStringW(FORMAT, L"%d added you to the contact list", *(DWORD *)(dbe.pBlob)).Detach();
+ break;
}
-
- return false;
}
bool ItemData::isGrouped() const
{
if (pPrev && g_plugin.bMsgGrouping) {
- if (!pPrev->dbeOk)
- pPrev->load(EventLoadMode::ELM_DATA);
+ if (!pPrev->bLoaded)
+ pPrev->load(true);
if (pPrev->hContact == hContact && (pPrev->dbe.flags & DBEF_SENT) == (dbe.flags & DBEF_SENT))
return true;
@@ -115,12 +100,11 @@ bool ItemData::isGrouped() const
ItemData::~ItemData()
{
- if (dbeOk && dbe.pBlob) {
+ if (bLoaded)
mir_free(dbe.pBlob);
- dbe.pBlob = 0;
- }
- if (wtext && wtext_del) delete[] wtext;
- if (data) MTextDestroy(data);
+ mir_free(wtext);
+ if (data)
+ MTextDestroy(data);
}
// Array
@@ -162,7 +146,7 @@ void HistoryArray::addChatEvent(SESSION_INFO *si, LOGINFO *lin)
auto &p = allocateItem();
p.hContact = si->hContact;
p.wtext = wszText.Detach();
- p.dbeOk = true;
+ p.bLoaded = true;
p.dbe.cbBlob = 1;
p.dbe.pBlob = (BYTE *)p.wtext;
p.dbe.eventType = EVENTTYPE_MESSAGE;
@@ -208,33 +192,15 @@ ItemData& HistoryArray::allocateItem()
return p.data[iLastPageCounter++];
}
-/*
-bool HistoryArray::preloadEvents(int count)
-{
- for (int i = 0; i < count; ++i)
- {
- preBlock->items[preIndex].load(ItemData::ELM_DATA);
- if (++preIndex == preBlock->count)
- {
- preBlock = preBlock->next;
- if (!preBlock)
- return false;
- preIndex = 0;
- }
- }
- return true;
-}
-*/
-
-ItemData* HistoryArray::get(int id, ItemData::EventLoadMode mode)
+ItemData* HistoryArray::get(int id, bool bLoad)
{
int pageNo = id / HIST_BLOCK_SIZE;
if (pageNo >= pages.getCount())
return nullptr;
auto *p = &pages[pageNo].data[id % HIST_BLOCK_SIZE];
- if (mode != ItemData::ELM_NOTHING)
- p->load(mode);
+ if (bLoad && !p->bLoaded)
+ p->load(true);
return p;
}
diff --git a/plugins/NewStory/src/history_array.h b/plugins/NewStory/src/history_array.h
index 02a2b7f471..22b1327dad 100644
--- a/plugins/NewStory/src/history_array.h
+++ b/plugins/NewStory/src/history_array.h
@@ -3,19 +3,11 @@
struct ItemData
{
- enum EventLoadMode
- {
- ELM_NOTHING,
- ELM_INFO,
- ELM_DATA
- };
-
MCONTACT hContact = 0;
MEVENT hEvent = 0;
- bool wtext_del = false;
bool bSelected = false;
- bool dbeOk = false;
+ bool bLoaded = false;
DBEVENTINFO dbe;
wchar_t *wtext = 0;
@@ -27,18 +19,12 @@ struct ItemData
ItemData() { memset(&dbe, 0, sizeof(dbe)); }
~ItemData();
- bool load(EventLoadMode mode);
+ void load(bool bFullLoad);
bool isGrouped() const;
- inline bool loadInline(EventLoadMode mode)
- {
- if (((mode >= ItemData::ELM_INFO) && !dbeOk) || ((mode == ItemData::ELM_DATA) && !dbe.pBlob))
- return load(mode);
- return true;
- }
inline wchar_t *getWBuf()
{
- loadInline(ItemData::ELM_DATA);
+ load(true);
return wtext;
}
};
@@ -142,9 +128,8 @@ public:
// bool preloadEvents(int count = 10);
- ItemData* get(int id, ItemData::EventLoadMode mode = ItemData::ELM_NOTHING);
- ItemData* operator[] (int id) { return get(id, ItemData::ELM_DATA); }
- ItemData* operator() (int id) { return get(id, ItemData::ELM_INFO); }
+ ItemData* get(int id, bool bLoad = false);
+ ItemData* operator[] (int id) { return get(id, true); }
int FindRel(int id, int dir, Filter filter)
{
diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp
index 5ae150bb97..2d9c07cdf2 100644
--- a/plugins/NewStory/src/history_control.cpp
+++ b/plugins/NewStory/src/history_control.cpp
@@ -40,7 +40,7 @@ struct NewstoryListData : public MZeroedObject
void OnContextMenu(int index)
{
- ItemData* item = items.get(index, ItemData::ELM_DATA);
+ ItemData* item = items[index];
}
void OnTimer(CTimer *pTimer)
@@ -68,7 +68,7 @@ struct NewstoryListData : public MZeroedObject
int itemHeight = LayoutItem(idx);
while (top < height) {
if (idx == index) {
- ItemData *item = items.get(index, ItemData::ELM_DATA);
+ ItemData *item = items[index];
int tpl;
int fontid;
@@ -209,7 +209,7 @@ struct NewstoryListData : public MZeroedObject
RECT rc; GetClientRect(hwnd, &rc);
int width = rc.right - rc.left;
- ItemData *item = items.get(index, ItemData::ELM_DATA);
+ ItemData *item = items[index];
if (!item) {
DeleteDC(hdc);
return 0;
@@ -270,7 +270,7 @@ struct NewstoryListData : public MZeroedObject
int PaintItem(HDC hdc, int index, int top, int width)
{
- auto *item = items.get(index, ItemData::ELM_DATA);
+ auto *item = items[index];
// LOGFONT lfText;
COLORREF clText, clBack, clLine;
@@ -497,7 +497,7 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
std::swap(start, end);
for (int i = start; i <= end; ++i) {
- auto *p = data->items.get(i, ItemData::ELM_NOTHING);
+ auto *p = data->items.get(i, false);
p->bSelected = true;
}
@@ -513,7 +513,7 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
std::swap(start, end);
for (int i = start; i <= end; ++i) {
- auto *p = data->items.get(i, ItemData::ELM_NOTHING);
+ auto *p = data->items.get(i, false);
p->bSelected = !p->bSelected;
}
@@ -530,7 +530,7 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
int count = data->items.getCount();
for (int i = 0; i < count; ++i) {
- auto *p = data->items.get(i, ItemData::ELM_NOTHING);
+ auto *p = data->items.get(i, false);
if ((i >= start) && (i <= end))
p->bSelected = true;
else
@@ -551,7 +551,7 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
start ^= end;
}
for (int i = start; i <= end; ++i) {
- auto *p = data->items.get(i, ItemData::ELM_NOTHING);
+ auto *p = data->items.get(i, false);
p->bSelected = false;
}
@@ -617,7 +617,7 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
{
int eventCount = data->items.getCount();
for (int i = 0; i < eventCount; i++) {
- auto *p = data->items.get(i, ItemData::ELM_NOTHING);
+ auto *p = data->items.get(i, false);
if (p->dbe.timestamp >= wParam) {
SendMessage(hwnd, NSM_SELECTITEMS2, i, i);
SendMessage(hwnd, NSM_SETCARET, i, TRUE);
@@ -642,7 +642,7 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
int eventCount = data->items.getCount();
for (int i = eventCount - 1; i >= 0; i--) {
- auto *p = data->items.get(i, ItemData::ELM_NOTHING);
+ auto *p = data->items.get(i, false);
if (p->hEvent && p->hContact)
db_event_delete(p->hEvent);
}
@@ -660,7 +660,7 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
int eventCount = data->items.getCount();
for (int i = 0; i < eventCount; i++) {
- ItemData *p = data->items.get(i, ItemData::ELM_NOTHING);
+ ItemData *p = data->items.get(i, false);
if (p->bSelected)
res.Append(ptrW(TplFormatString(TPL_COPY_MESSAGE, p->hContact, p)));
}
diff --git a/plugins/NewStory/src/options.cpp b/plugins/NewStory/src/options.cpp
index 666aed1226..f1c82568e0 100644
--- a/plugins/NewStory/src/options.cpp
+++ b/plugins/NewStory/src/options.cpp
@@ -38,7 +38,7 @@ class CTemplateOptsDlg : public CDlgBase
ItemData item;
item.hContact = m_hContact;
item.hEvent = m_hDbEVent;
- item.load(ItemData::ELM_DATA);
+ item.load(true);
ptrW wszText(TplFormatStringEx(int(m_curr-templates), m_curr->tmpValue, item.hContact, &item));
preview.SetText(wszText);
@@ -77,7 +77,7 @@ public:
DBEVENTINFO dbei = {};
dbei.pBlob = (BYTE *)"The quick brown fox jumps over the lazy dog";
- dbei.cbBlob = strlen((char*)dbei.pBlob);
+ dbei.cbBlob = (DWORD)strlen((char*)dbei.pBlob);
dbei.flags = DBEF_TEMPORARY;
dbei.eventType = EVENTTYPE_MESSAGE;
dbei.timestamp = time(0);
diff --git a/plugins/NewStory/src/stdafx.h b/plugins/NewStory/src/stdafx.h
index 52d19c9a3d..b2e65af798 100644
--- a/plugins/NewStory/src/stdafx.h
+++ b/plugins/NewStory/src/stdafx.h
@@ -32,7 +32,7 @@ Boston, MA 02111-1307, USA.
#include "win2k.h"
#include "m_chat_int.h"
#include "m_clc.h"
-#include "m_clist.h"
+#include "m_clistint.h"
#include "m_options.h"
#include "m_skin.h"
#include "m_langpack.h"