diff options
Diffstat (limited to 'plugins/NewStory/src/history_array.cpp')
-rw-r--r-- | plugins/NewStory/src/history_array.cpp | 115 |
1 files changed, 49 insertions, 66 deletions
diff --git a/plugins/NewStory/src/history_array.cpp b/plugins/NewStory/src/history_array.cpp index 38d16de58e..34b8113e64 100644 --- a/plugins/NewStory/src/history_array.cpp +++ b/plugins/NewStory/src/history_array.cpp @@ -6,8 +6,7 @@ bool HistoryArray::ItemData::load(EventLoadMode mode) if (mode == ELM_NOTHING) return true; - if ((mode == ELM_INFO) && !dbeOk) - { + if ((mode == ELM_INFO) && !dbeOk) { dbeOk = true; dbe.cbBlob = 0; dbe.pBlob = 0; @@ -15,57 +14,52 @@ bool HistoryArray::ItemData::load(EventLoadMode mode) return true; } - if ((mode == ELM_DATA) && (!dbeOk || !dbe.cbBlob)) - { + if ((mode == ELM_DATA) && (!dbeOk || !dbe.cbBlob)) { dbeOk = true; dbe.cbBlob = db_event_getBlobSize(hEvent); - dbe.pBlob = (PBYTE)calloc(dbe.cbBlob+1, 1); + dbe.pBlob = (PBYTE)calloc(dbe.cbBlob + 1, 1); db_event_get(hEvent, &dbe); int aLength = 0; atext = 0; wtext = 0; - switch (dbe.eventType) - { - case EVENTTYPE_STATUSCHANGE: - case EVENTTYPE_MESSAGE: + switch (dbe.eventType) { + case EVENTTYPE_STATUSCHANGE: + case EVENTTYPE_MESSAGE: { atext = (char *)dbe.pBlob; atext_del = false; aLength = lstrlenA(atext); - if (dbe.cbBlob > (DWORD)aLength + 1) - { + if (dbe.cbBlob > (DWORD)aLength + 1) { wtext = (WCHAR *)(dbe.pBlob + aLength + 1); wtext_del = false; } break; } - case EVENTTYPE_AUTHREQUEST: + case EVENTTYPE_AUTHREQUEST: { atext = new char[512]; atext_del = true; - if ((dbe.cbBlob>8) && *(dbe.pBlob+8)) - { + if ((dbe.cbBlob > 8) && *(dbe.pBlob + 8)) { mir_snprintf(atext, 512, ("%s requested authorization"), dbe.pBlob + 8); - } else - { + } + else { mir_snprintf(atext, 512, ("%d requested authorization"), *(DWORD*)(dbe.pBlob)); } aLength = lstrlenA(atext); break; } - case EVENTTYPE_ADDED: + case EVENTTYPE_ADDED: { atext = new char[512]; atext_del = true; - if ((dbe.cbBlob>8) && *(dbe.pBlob+8)) - { + if ((dbe.cbBlob > 8) && *(dbe.pBlob + 8)) { mir_snprintf(atext, 512, ("%s added you to the contact list"), dbe.pBlob + 8); - } else - { + } + else { mir_snprintf(atext, 512, ("%d added you to the contact list"), *(DWORD*)(dbe.pBlob)); } aLength = lstrlenA(atext); @@ -73,29 +67,28 @@ bool HistoryArray::ItemData::load(EventLoadMode mode) } } - if (atext && !wtext) - { + if (atext && !wtext) { #ifdef UNICODE - int bufSize = MultiByteToWideChar(CP_ACP, 0, atext, aLength+1, 0, 0); - wtext = new WCHAR[bufSize+1]; - MultiByteToWideChar(CP_ACP, 0, atext, aLength+1, wtext, bufSize); - wtext_del = true; + int bufSize = MultiByteToWideChar(CP_ACP, 0, atext, aLength + 1, 0, 0); + wtext = new WCHAR[bufSize + 1]; + MultiByteToWideChar(CP_ACP, 0, atext, aLength + 1, wtext, bufSize); + wtext_del = true; #else - this->wtext = 0; - wtext_del = false; - #endif - } else - if (!atext && wtext) - { - // strange situation, really :) I'll fix this later - } else - if (!atext && !wtext) - { - atext = ""; - atext_del = false; - wtext = L""; + this->wtext = 0; wtext_del = false; + #endif } + else + if (!atext && wtext) { + // strange situation, really :) I'll fix this later + } + else + if (!atext && !wtext) { + atext = ""; + atext_del = false; + wtext = L""; + wtext_del = false; + } return true; } @@ -105,13 +98,12 @@ bool HistoryArray::ItemData::load(EventLoadMode mode) HistoryArray::ItemData::~ItemData() { - if (dbeOk && dbe.pBlob) - { + if (dbeOk && dbe.pBlob) { free(dbe.pBlob); dbe.pBlob = 0; } - if (wtext && wtext_del) delete [] wtext; - if (atext && atext_del) delete [] atext; + if (wtext && wtext_del) delete[] wtext; + if (atext && atext_del) delete[] atext; if (data) MTextDestroy(data); } @@ -138,11 +130,10 @@ bool HistoryArray::allocateBlock(int count) newBlock->prev = tail; newBlock->next = 0; - if (tail) - { + if (tail) { tail->next = newBlock; - } else - { + } + else { head = newBlock; } tail = newBlock; @@ -152,12 +143,11 @@ bool HistoryArray::allocateBlock(int count) void HistoryArray::clear() { - while (head) - { + while (head) { ItemBlock *next = head->next; -// for (int i = 0; i < head->count; ++i) -// destroyEvent(head->items[i]); - delete [] head->items; + // for (int i = 0; i < head->count; ++i) + // destroyEvent(head->items[i]); + delete[] head->items; head = next; } @@ -173,16 +163,13 @@ bool HistoryArray::addHistory(MCONTACT hContact, EventLoadMode) int i = 0; MEVENT hEvent = db_event_first(hContact); - while (hEvent) - { + while (hEvent) { tail->items[i].hContact = hContact; tail->items[i].hEvent = hEvent; ++i; hEvent = db_event_next(hEvent, 0); } -// char buf[666]; - return true; } @@ -218,15 +205,12 @@ HistoryArray::ItemData *HistoryArray::get(int id, EventLoadMode mode) caching = false; if (caching) EnterCriticalSection(&csItems); int offset = 0; - for (ItemBlock *p = head; p; p = p->next) - { - if (id < offset + p->count) - { + for (ItemBlock *p = head; p; p = p->next) { + if (id < offset + p->count) { if (mode != ELM_NOTHING) p->items[id - offset].load(mode); - if (caching) - { + if (caching) { if (caching_complete) caching = false; LeaveCriticalSection(&csItems); } @@ -234,8 +218,7 @@ HistoryArray::ItemData *HistoryArray::get(int id, EventLoadMode mode) } offset += p->count; } - if (caching) - { + if (caching) { if (caching_complete) caching = false; LeaveCriticalSection(&csItems); } @@ -249,4 +232,4 @@ void HistoryArray::CacheThreadFunc(void *arg) HistoryArray *_this = (HistoryArray *)arg; _this->caching_complete = true; _endthread(); -}
\ No newline at end of file +} |