summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
Diffstat (limited to 'protocols')
-rw-r--r--protocols/JabberG/src/jabber.h3
-rw-r--r--protocols/JabberG/src/jabber_byte.cpp2
-rw-r--r--protocols/JabberG/src/jabber_caps.cpp2
-rw-r--r--protocols/JabberG/src/jabber_disco.cpp4
-rw-r--r--protocols/JabberG/src/jabber_events.cpp36
-rw-r--r--protocols/JabberG/src/jabber_file.cpp22
-rw-r--r--protocols/JabberG/src/jabber_ft.cpp6
-rw-r--r--protocols/JabberG/src/jabber_groupchat.cpp2
-rw-r--r--protocols/JabberG/src/jabber_ibb.cpp2
-rw-r--r--protocols/JabberG/src/jabber_iq.h16
-rw-r--r--protocols/JabberG/src/jabber_iq_handlers.cpp2
-rw-r--r--protocols/JabberG/src/jabber_iqid.cpp4
-rw-r--r--protocols/JabberG/src/jabber_menu.cpp39
-rw-r--r--protocols/JabberG/src/jabber_opt.cpp4
-rw-r--r--protocols/JabberG/src/jabber_privacy.cpp999
-rw-r--r--protocols/JabberG/src/jabber_privacy.h12
-rw-r--r--protocols/JabberG/src/jabber_search.cpp2
-rw-r--r--protocols/JabberG/src/jabber_svc.cpp180
-rw-r--r--protocols/JabberG/src/jabber_thread.cpp7
-rw-r--r--protocols/JabberG/src/ui_utils.cpp775
-rw-r--r--protocols/JabberG/src/ui_utils.h4
21 files changed, 900 insertions, 1223 deletions
diff --git a/protocols/JabberG/src/jabber.h b/protocols/JabberG/src/jabber.h
index eefd600481..195d046210 100644
--- a/protocols/JabberG/src/jabber.h
+++ b/protocols/JabberG/src/jabber.h
@@ -429,8 +429,7 @@ struct filetransfer
JABBER_SOCKET s;
JABBER_FILE_STATE state;
TCHAR *jid;
- int fileId;
- TCHAR *iqId;
+ int fileId, iqId;
TCHAR *sid;
int bCompleted;
HANDLE hWaitEvent;
diff --git a/protocols/JabberG/src/jabber_byte.cpp b/protocols/JabberG/src/jabber_byte.cpp
index d2d5fcf0d5..f0e2fcf91a 100644
--- a/protocols/JabberG/src/jabber_byte.cpp
+++ b/protocols/JabberG/src/jabber_byte.cpp
@@ -422,7 +422,7 @@ void CJabberProto::IqResultStreamActivate(HXML iqNode, CJabberIqInfo*)
mir_sntprintf(listJid, SIZEOF(listJid), _T("ftproxy_%d"), id);
JABBER_LIST_ITEM *item = ListGetItemPtr(LIST_FTIQID, listJid);
- if ( !item)
+ if (item == NULL)
return;
if ( !lstrcmp(xmlGetAttrValue(iqNode, _T("type")), _T("result")))
diff --git a/protocols/JabberG/src/jabber_caps.cpp b/protocols/JabberG/src/jabber_caps.cpp
index ce01ed053a..e2397005b7 100644
--- a/protocols/JabberG/src/jabber_caps.cpp
+++ b/protocols/JabberG/src/jabber_caps.cpp
@@ -184,7 +184,7 @@ JabberCapsBits CJabberProto::GetTotalJidCapabilites(const TCHAR *jid)
JabberStripJid(jid, szBareJid, SIZEOF(szBareJid));
JABBER_LIST_ITEM *item = ListGetItemPtr(LIST_ROSTER, szBareJid);
- if ( !item)
+ if (item == NULL)
item = ListGetItemPtr(LIST_VCARD_TEMP, szBareJid);
JabberCapsBits jcbToReturn = JABBER_RESOURCE_CAPS_NONE;
diff --git a/protocols/JabberG/src/jabber_disco.cpp b/protocols/JabberG/src/jabber_disco.cpp
index 6d3e12de4d..53fcf7ec48 100644
--- a/protocols/JabberG/src/jabber_disco.cpp
+++ b/protocols/JabberG/src/jabber_disco.cpp
@@ -176,7 +176,7 @@ void CJabberProto::OnIqResultServiceDiscoveryInfo(HXML iqNode, CJabberIqInfo *pI
if (pInfo->GetIqType() == JABBER_IQ_TYPE_RESULT) {
HXML query = xmlGetChild(iqNode , "query");
- if ( !query)
+ if (query == NULL)
pNode->SetInfoRequestId(JABBER_DISCO_RESULT_ERROR);
else {
HXML feature;
@@ -222,7 +222,7 @@ void CJabberProto::OnIqResultServiceDiscoveryItems(HXML iqNode, CJabberIqInfo *p
if (pInfo->GetIqType() == JABBER_IQ_TYPE_RESULT) {
HXML query = xmlGetChild(iqNode , "query");
- if ( !query)
+ if (query == NULL)
pNode->SetItemsRequestId(JABBER_DISCO_RESULT_ERROR);
else {
HXML item;
diff --git a/protocols/JabberG/src/jabber_events.cpp b/protocols/JabberG/src/jabber_events.cpp
index b4fc432a5d..f71ee0dcc6 100644
--- a/protocols/JabberG/src/jabber_events.cpp
+++ b/protocols/JabberG/src/jabber_events.cpp
@@ -77,32 +77,22 @@ static TCHAR* sttSettingToTchar(DBCONTACTWRITESETTING* cws)
void __cdecl CJabberProto::OnRenameGroup(DBCONTACTWRITESETTING* cws, HANDLE hContact)
{
- DBVARIANT jid, dbv;
- if (getTString(hContact, "jid", &jid))
- return;
-
- JABBER_LIST_ITEM *item = ListGetItemPtr(LIST_ROSTER, jid.ptszVal);
- db_free(&jid);
+ JABBER_LIST_ITEM *item = ListGetItemPtr(LIST_ROSTER, ptrT( getTStringA(hContact, "jid")));
if (item == NULL)
return;
- TCHAR *nick;
- if ( !db_get_ts(hContact, "CList", "MyHandle", &dbv)) {
- nick = mir_tstrdup(dbv.ptszVal);
- db_free(&dbv);
- }
- else if ( !getTString(hContact, "Nick", &dbv)) {
- nick = mir_tstrdup(dbv.ptszVal);
- db_free(&dbv);
- }
- else nick = JabberNickFromJID(item->jid);
- if (nick == NULL)
+ ptrT tszNick( db_get_tsa(hContact, "CList", "MyHandle"));
+ if (tszNick == NULL)
+ tszNick = getTStringA(hContact, "Nick");
+ if (tszNick == NULL)
+ tszNick = JabberNickFromJID(item->jid);
+ if (tszNick == NULL)
return;
if (cws->value.type == DBVT_DELETED) {
if (item->group != NULL) {
Log("Group set to nothing");
- AddContactToRoster(item->jid, nick, NULL);
+ AddContactToRoster(item->jid, tszNick, NULL);
}
}
else {
@@ -110,21 +100,15 @@ void __cdecl CJabberProto::OnRenameGroup(DBCONTACTWRITESETTING* cws, HANDLE hCon
if (cws->value.pszVal != NULL && lstrcmp(p, item->group)) {
Log("Group set to %S", p);
if (p)
- AddContactToRoster(item->jid, nick, p);
+ AddContactToRoster(item->jid, tszNick, p);
}
mir_free(p);
}
- mir_free(nick);
}
void __cdecl CJabberProto::OnRenameContact(DBCONTACTWRITESETTING* cws, HANDLE hContact)
{
- DBVARIANT jid;
- if (getTString(hContact, "jid", &jid))
- return;
-
- JABBER_LIST_ITEM *item = ListGetItemPtr(LIST_ROSTER, jid.ptszVal);
- db_free(&jid);
+ JABBER_LIST_ITEM *item = ListGetItemPtr(LIST_ROSTER, ptrT( getTStringA(hContact, "jid")));
if (item == NULL)
return;
diff --git a/protocols/JabberG/src/jabber_file.cpp b/protocols/JabberG/src/jabber_file.cpp
index d00b2324bc..d88ef968c6 100644
--- a/protocols/JabberG/src/jabber_file.cpp
+++ b/protocols/JabberG/src/jabber_file.cpp
@@ -284,33 +284,24 @@ void __cdecl CJabberProto::FileServerThread(filetransfer *ft)
char *pFileName = mir_urlEncode( ptrA( mir_utf8encodeT(p)));
if (pFileName != NULL) {
- int id = SerialNext();
- if (ft->iqId) mir_free(ft->iqId);
- size_t size = strlen(JABBER_IQID) + 20;
- ft->iqId = (TCHAR *)mir_alloc(sizeof(TCHAR) * size);
- mir_sntprintf(ft->iqId, size, _T(JABBER_IQID)_T("%d"), id);
-
- char *myAddr = NULL;
- DBVARIANT dbv;
- if (m_options.BsDirect && m_options.BsDirectManual) {
- if ( !getString("BsDirectAddr", &dbv))
- myAddr = dbv.pszVal;
- }
+ ft->iqId = SerialNext();
+ ptrA myAddr;
+ if (m_options.BsDirect && m_options.BsDirectManual)
+ myAddr = getStringA("BsDirectAddr");
if (myAddr == NULL)
myAddr = (char*)CallService(MS_NETLIB_ADDRESSTOSTRING, 1, nlb.dwExternalIP);
- char szAddr[ 256 ];
+ char szAddr[256];
mir_snprintf(szAddr, sizeof(szAddr), "http://%s:%d/%s", myAddr, nlb.wPort, pFileName);
mir_free(pFileName);
- mir_free(myAddr);
int len = lstrlen(ptszResource) + lstrlen(ft->jid) + 2;
TCHAR *fulljid = (TCHAR *)alloca(sizeof(TCHAR) * len);
mir_sntprintf(fulljid, len, _T("%s/%s"), ft->jid, ptszResource);
- XmlNodeIq iq(_T("set"), id, fulljid);
+ XmlNodeIq iq(_T("set"), ft->iqId, fulljid);
HXML query = iq << XQUERY(JABBER_FEAT_OOB);
query << XCHILD(_T("url"), _A2T(szAddr));
query << XCHILD(_T("desc"), ft->szDescription);
@@ -478,7 +469,6 @@ filetransfer::~filetransfer()
if (jid) mir_free(jid);
if (sid) mir_free(sid);
- if (iqId) mir_free(iqId);
if (fileSize) mir_free(fileSize);
if (httpHostName) mir_free(httpHostName);
if (httpPath) mir_free(httpPath);
diff --git a/protocols/JabberG/src/jabber_ft.cpp b/protocols/JabberG/src/jabber_ft.cpp
index 2bf763e775..811405828c 100644
--- a/protocols/JabberG/src/jabber_ft.cpp
+++ b/protocols/JabberG/src/jabber_ft.cpp
@@ -352,7 +352,7 @@ void CJabberProto::FtHandleSiRequest(HXML iqNode)
ft->jid = mir_tstrdup(from);
ft->std.hContact = HContactFromJID(from);
ft->sid = mir_tstrdup(sid);
- ft->iqId = mir_tstrdup(szId);
+ ft->iqId = _ttoi(szId+4);
ft->type = ftType;
ft->std.totalFiles = 1;
ft->std.tszCurrentFile = mir_tstrdup(filename);
@@ -449,7 +449,7 @@ BOOL CJabberProto::FtHandleBytestreamRequest(HXML iqNode, CJabberIqInfo *pInfo)
BOOL CJabberProto::FtHandleIbbRequest(HXML iqNode, BOOL bOpen)
{
- if ( !iqNode) return FALSE;
+ if (iqNode == NULL) return FALSE;
const TCHAR *id = xmlGetAttrValue(iqNode, _T("id"));
const TCHAR *from = xmlGetAttrValue(iqNode, _T("from"));
@@ -464,7 +464,7 @@ BOOL CJabberProto::FtHandleIbbRequest(HXML iqNode, BOOL bOpen)
// already closed?
JABBER_LIST_ITEM *item = ListGetItemPtr(LIST_FTRECV, sid);
- if ( !item) {
+ if (item == NULL) {
m_ThreadInfo->send(
XmlNodeIq(_T("error"), id, from)
<< XCHILD(_T("error")) << XATTRI(_T("code"), 404) << XATTR(_T("type"), _T("cancel"))
diff --git a/protocols/JabberG/src/jabber_groupchat.cpp b/protocols/JabberG/src/jabber_groupchat.cpp
index 62a64bd4b6..7e14ae7c32 100644
--- a/protocols/JabberG/src/jabber_groupchat.cpp
+++ b/protocols/JabberG/src/jabber_groupchat.cpp
@@ -335,7 +335,7 @@ void CJabberProto::OnIqResultDiscovery(HXML iqNode, CJabberIqInfo *pInfo)
if (pInfo->GetIqType() == JABBER_IQ_TYPE_RESULT)
{
HXML query = xmlGetChild(iqNode , "query");
- if ( !query)
+ if (query == NULL)
{
sttRoomListAppend(hwndList, RoomInfo::ROOM_FAIL,
TranslateT("Jabber Error"),
diff --git a/protocols/JabberG/src/jabber_ibb.cpp b/protocols/JabberG/src/jabber_ibb.cpp
index f696e98b5e..0c5ab25e2c 100644
--- a/protocols/JabberG/src/jabber_ibb.cpp
+++ b/protocols/JabberG/src/jabber_ibb.cpp
@@ -168,7 +168,7 @@ void __cdecl CJabberProto::IbbReceiveThread(JABBER_IBB_TRANSFER *jibb)
BOOL CJabberProto::OnIbbRecvdData(const TCHAR *data, const TCHAR *sid, const TCHAR *seq)
{
JABBER_LIST_ITEM *item = ListGetItemPtr(LIST_FTRECV, sid);
- if ( !item) return FALSE;
+ if (item == NULL) return FALSE;
WORD wSeq = (WORD)_ttoi(seq);
if (wSeq != item->jibb->wPacketId) {
diff --git a/protocols/JabberG/src/jabber_iq.h b/protocols/JabberG/src/jabber_iq.h
index 57afea900b..349ea65e58 100644
--- a/protocols/JabberG/src/jabber_iq.h
+++ b/protocols/JabberG/src/jabber_iq.h
@@ -55,16 +55,16 @@ protected:
JABBER_IQ_HANDLER m_pHandler;
CJabberIqInfo *m_pNext;
- int m_nIqId;
- DWORD m_dwParamsToParse;
- DWORD m_dwRequestTime;
- DWORD m_dwTimeout;
+ int m_nIqId;
+ DWORD m_dwParamsToParse;
+ DWORD m_dwRequestTime;
+ DWORD m_dwTimeout;
TCHAR *m_szReceiver;
- int m_iPriority;
+ int m_iPriority;
+
public:
- void *m_pUserData;
-public:// parsed data
- int m_nIqType;
+ void *m_pUserData;
+ int m_nIqType;
TCHAR *m_szFrom;
TCHAR *m_szChildTagXmlns;
TCHAR *m_szChildTagName;
diff --git a/protocols/JabberG/src/jabber_iq_handlers.cpp b/protocols/JabberG/src/jabber_iq_handlers.cpp
index 36e6ee9381..de7ab1f006 100644
--- a/protocols/JabberG/src/jabber_iq_handlers.cpp
+++ b/protocols/JabberG/src/jabber_iq_handlers.cpp
@@ -653,7 +653,7 @@ BOOL CJabberProto::OnIqRequestOOB(HXML, CJabberIqInfo *pInfo)
}
if (pInfo->GetIdStr())
- ft->iqId = mir_tstrdup(pInfo->GetIdStr());
+ ft->iqId = pInfo->GetIqId();
if (ft->httpHostName && ft->httpPath) {
TCHAR *desc = NULL;
diff --git a/protocols/JabberG/src/jabber_iqid.cpp b/protocols/JabberG/src/jabber_iqid.cpp
index ec36891932..7addbc3138 100644
--- a/protocols/JabberG/src/jabber_iqid.cpp
+++ b/protocols/JabberG/src/jabber_iqid.cpp
@@ -30,7 +30,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
void CJabberProto::OnIqResultServerDiscoInfo(HXML iqNode, CJabberIqInfo*)
{
- if ( !iqNode)
+ if (iqNode == NULL)
return;
const TCHAR *type = xmlGetAttrValue(iqNode, _T("type"));
@@ -38,7 +38,7 @@ void CJabberProto::OnIqResultServerDiscoInfo(HXML iqNode, CJabberIqInfo*)
return;
HXML query = xmlGetChildByTag(iqNode, "query", "xmlns", JABBER_FEAT_DISCO_INFO);
- if ( !query)
+ if (query == NULL)
return;
HXML identity;
diff --git a/protocols/JabberG/src/jabber_menu.cpp b/protocols/JabberG/src/jabber_menu.cpp
index 4c27ddf361..909feaae84 100644
--- a/protocols/JabberG/src/jabber_menu.cpp
+++ b/protocols/JabberG/src/jabber_menu.cpp
@@ -1081,7 +1081,7 @@ int CJabberProto::OnProcessSrmmIconClick(WPARAM wParam, LPARAM lParam)
JABBER_LIST_ITEM *LI = ListGetItemPtr(LIST_ROSTER, dbv.ptszVal);
db_free(&dbv);
- if ( !LI)
+ if (LI == NULL)
return 0;
HMENU hMenu = CreatePopupMenu();
@@ -1131,15 +1131,12 @@ INT_PTR __cdecl CJabberProto::OnMenuHandleResource(WPARAM wParam, LPARAM, LPARAM
return 0;
HANDLE hContact = (HANDLE)wParam;
-
- DBVARIANT dbv;
- if (getTString(hContact, "jid", &dbv))
+ ptrT tszJid( getTStringA(hContact, "jid"));
+ if (tszJid == NULL)
return 0;
- JABBER_LIST_ITEM *LI = ListGetItemPtr(LIST_ROSTER, dbv.ptszVal);
- db_free(&dbv);
-
- if ( !LI)
+ JABBER_LIST_ITEM *LI = ListGetItemPtr(LIST_ROSTER, tszJid);
+ if (LI == NULL)
return 0;
if (res == MENUITEM_LASTSEEN) {
@@ -1168,35 +1165,32 @@ INT_PTR __cdecl CJabberProto::OnMenuHandleDirectPresence(WPARAM wParam, LPARAM l
HANDLE hContact = (HANDLE)wParam;
TCHAR *jid, text[ 1024 ];
+ ptrT tszJid( getTStringA(hContact, "jid"));
+ if (tszJid == NULL) {
+ ptrT roomid( getTStringA(hContact, "ChatRoomID"));
+ if (roomid == NULL)
+ return 0;
- DBVARIANT dbv;
- int result = getTString(hContact, "jid", &dbv);
- if (result)
- {
- result = getTString(hContact, "ChatRoomID", &dbv);
- if (result) return 0;
-
- JABBER_LIST_ITEM *item = ListGetItemPtr(LIST_CHATROOM, dbv.ptszVal);
- if ( !item) return 0;
+ JABBER_LIST_ITEM *item = ListGetItemPtr(LIST_CHATROOM, roomid);
+ if (item == NULL)
+ return 0;
mir_sntprintf(text, SIZEOF(text), _T("%s/%s"), item->jid, item->nick);
jid = text;
}
- else
- jid = dbv.ptszVal;
+ else jid = tszJid;
TCHAR buf[1024] = _T("");
EnterString(buf, SIZEOF(buf), TranslateT("Status Message"), JES_MULTINE);
SendPresenceTo(res, jid, NULL, buf);
- db_free(&dbv);
return 0;
}
////////////////////////////////////////////////////////////////////////
// Choose protocol instance
-CJabberProto *JabberChooseInstance(bool bIsLink)
+CJabberProto* JabberChooseInstance(bool bIsLink)
{
if (g_Instances.getCount() == 0)
return NULL;
@@ -1207,11 +1201,10 @@ CJabberProto *JabberChooseInstance(bool bIsLink)
return NULL;
}
- if (bIsLink) {
+ if (bIsLink)
for (int i=0; i < g_Instances.getCount(); i++)
if (g_Instances[i]->m_options.ProcessXMPPLinks)
return g_Instances[i];
- }
CLISTMENUITEM clmi = { sizeof(clmi) };
diff --git a/protocols/JabberG/src/jabber_opt.cpp b/protocols/JabberG/src/jabber_opt.cpp
index 8e3abd8694..e8d3901e6a 100644
--- a/protocols/JabberG/src/jabber_opt.cpp
+++ b/protocols/JabberG/src/jabber_opt.cpp
@@ -1037,11 +1037,11 @@ void CJabberProto::_RosterHandleGetRequest(HXML node, CJabberIqInfo*)
{
_RosterListClear(rrud.hwndDlg);
HXML query = xmlGetChild(node , "query");
- if ( !query) return;
+ if (query == NULL) return;
int i = 1;
while (TRUE) {
HXML item = xmlGetNthChild(query, _T("item"), i++);
- if ( !item)
+ if (item == NULL)
break;
const TCHAR *jid = xmlGetAttrValue(item, _T("jid"));
diff --git a/protocols/JabberG/src/jabber_privacy.cpp b/protocols/JabberG/src/jabber_privacy.cpp
index 9fcb7046c9..748a0d8df5 100644
--- a/protocols/JabberG/src/jabber_privacy.cpp
+++ b/protocols/JabberG/src/jabber_privacy.cpp
@@ -32,22 +32,20 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
BOOL CJabberProto::OnIqRequestPrivacyLists(HXML, CJabberIqInfo *pInfo)
{
if (pInfo->GetIqType() == JABBER_IQ_TYPE_SET) {
- if ( !m_pDlgPrivacyLists)
- {
+ if ( !m_pDlgPrivacyLists) {
m_privacyListManager.RemoveAllLists();
QueryPrivacyLists();
}
else m_pDlgPrivacyLists->SetStatusText(TranslateT("Warning: privacy lists were changed on server."));
- XmlNodeIq iq(_T("result"), pInfo);
- m_ThreadInfo->send(iq);
+ m_ThreadInfo->send( XmlNodeIq(_T("result"), pInfo));
}
return TRUE;
}
void CJabberProto::OnIqResultPrivacyListModify(HXML, CJabberIqInfo *pInfo)
{
- if ( !pInfo->m_pUserData)
+ if (!pInfo->m_pUserData)
return;
CPrivacyListModifyUserParam *pParam = (CPrivacyListModifyUserParam *)pInfo->m_pUserData;
@@ -71,77 +69,78 @@ void CJabberProto::OnIqResultPrivacyListModify(HXML, CJabberIqInfo *pInfo)
void CJabberProto::OnIqResultPrivacyList(HXML iqNode, CJabberIqInfo*)
{
- if ( !iqNode)
+ if (iqNode == NULL)
return;
const TCHAR *type = xmlGetAttrValue(iqNode, _T("type"));
- if ( !type)
+ if (type == NULL)
return;
- if ( !_tcscmp(type, _T("result"))) {
- HXML query = xmlGetChild(iqNode , "query");
- if ( !query)
- return;
- HXML list = xmlGetChild(query , "list");
- if ( !list)
- return;
- TCHAR *szListName = (TCHAR*)xmlGetAttrValue(list, _T("name"));
- if ( !szListName)
+ if ( _tcscmp(type, _T("result")))
+ return;
+
+ HXML query = xmlGetChild(iqNode , "query");
+ if (query == NULL)
+ return;
+ HXML list = xmlGetChild(query, "list");
+ if (list == NULL)
+ return;
+ TCHAR *szListName = (TCHAR*)xmlGetAttrValue(list, _T("name"));
+ if ( !szListName)
+ return;
+
+ mir_cslockfull lck(m_privacyListManager.m_cs);
+ CPrivacyList *pList = m_privacyListManager.FindList(szListName);
+ if (pList == NULL) {
+ m_privacyListManager.AddList(szListName);
+ pList = m_privacyListManager.FindList(szListName);
+ if (pList == NULL)
return;
- m_privacyListManager.Lock();
- CPrivacyList* pList = m_privacyListManager.FindList(szListName);
- if ( !pList) {
- m_privacyListManager.AddList(szListName);
- pList = m_privacyListManager.FindList(szListName);
- if ( !pList) {
- m_privacyListManager.Unlock();
- return;
- } }
-
- HXML item;
- for (int i = 1; (item = xmlGetNthChild(list, _T("item"), i)) != NULL; i++) {
- const TCHAR *itemType = xmlGetAttrValue(item, _T("type"));
- PrivacyListRuleType nItemType = Else;
- if (itemType) {
- if ( !_tcsicmp(itemType, _T("jid")))
- nItemType = Jid;
- else if ( !_tcsicmp(itemType, _T("group")))
- nItemType = Group;
- else if ( !_tcsicmp(itemType, _T("subscription")))
- nItemType = Subscription;
- }
+ }
- const TCHAR *itemValue = xmlGetAttrValue(item, _T("value"));
-
- const TCHAR *itemAction = xmlGetAttrValue(item, _T("action"));
- BOOL bAllow = TRUE;
- if (itemAction && !_tcsicmp(itemAction, _T("deny")))
- bAllow = FALSE;
-
- const TCHAR *itemOrder = xmlGetAttrValue(item, _T("order"));
- DWORD dwOrder = 0;
- if (itemOrder)
- dwOrder = _ttoi(itemOrder);
-
- DWORD dwPackets = 0;
- if (xmlGetChild(item , "message"))
- dwPackets |= JABBER_PL_RULE_TYPE_MESSAGE;
- if (xmlGetChild(item , "presence-in"))
- dwPackets |= JABBER_PL_RULE_TYPE_PRESENCE_IN;
- if (xmlGetChild(item , "presence-out"))
- dwPackets |= JABBER_PL_RULE_TYPE_PRESENCE_OUT;
- if (xmlGetChild(item , "iq"))
- dwPackets |= JABBER_PL_RULE_TYPE_IQ;
-
- pList->AddRule(nItemType, itemValue, bAllow, dwOrder, dwPackets);
+ HXML item;
+ for (int i = 1; (item = xmlGetNthChild(list, _T("item"), i)) != NULL; i++) {
+ const TCHAR *itemType = xmlGetAttrValue(item, _T("type"));
+ PrivacyListRuleType nItemType = Else;
+ if (itemType) {
+ if ( !_tcsicmp(itemType, _T("jid")))
+ nItemType = Jid;
+ else if ( !_tcsicmp(itemType, _T("group")))
+ nItemType = Group;
+ else if ( !_tcsicmp(itemType, _T("subscription")))
+ nItemType = Subscription;
}
- pList->Reorder();
- pList->SetLoaded();
- pList->SetModified(FALSE);
- m_privacyListManager.Unlock();
- UI_SAFE_NOTIFY(m_pDlgPrivacyLists, WM_JABBER_REFRESH);
-} }
+ const TCHAR *itemValue = xmlGetAttrValue(item, _T("value"));
+
+ const TCHAR *itemAction = xmlGetAttrValue(item, _T("action"));
+ BOOL bAllow = TRUE;
+ if (itemAction && !_tcsicmp(itemAction, _T("deny")))
+ bAllow = FALSE;
+
+ const TCHAR *itemOrder = xmlGetAttrValue(item, _T("order"));
+ DWORD dwOrder = 0;
+ if (itemOrder)
+ dwOrder = _ttoi(itemOrder);
+
+ DWORD dwPackets = 0;
+ if (xmlGetChild(item , "message"))
+ dwPackets |= JABBER_PL_RULE_TYPE_MESSAGE;
+ if (xmlGetChild(item , "presence-in"))
+ dwPackets |= JABBER_PL_RULE_TYPE_PRESENCE_IN;
+ if (xmlGetChild(item , "presence-out"))
+ dwPackets |= JABBER_PL_RULE_TYPE_PRESENCE_OUT;
+ if (xmlGetChild(item , "iq"))
+ dwPackets |= JABBER_PL_RULE_TYPE_IQ;
+ pList->AddRule(nItemType, itemValue, bAllow, dwOrder, dwPackets);
+ }
+ pList->Reorder();
+ pList->SetLoaded();
+ pList->SetModified(FALSE);
+
+ lck.unlock();
+ UI_SAFE_NOTIFY(m_pDlgPrivacyLists, WM_JABBER_REFRESH);
+}
CPrivacyList* GetSelectedList(HWND hDlg)
{
@@ -176,32 +175,29 @@ void CJabberProto::OnIqResultPrivacyListActive(HXML iqNode, CJabberIqInfo *pInfo
if (m_pDlgPrivacyLists)
EnableWindow(GetDlgItem(m_pDlgPrivacyLists->GetHwnd(), IDC_ACTIVATE), TRUE);
- if ( !iqNode)
+ if (iqNode == NULL)
return;
const TCHAR *type = xmlGetAttrValue(iqNode, _T("type"));
- if ( !type)
+ if (type == NULL)
return;
- TCHAR szText[ 512 ];
- szText[0] = _T('\0');
- m_privacyListManager.Lock();
+ CMString szText;
+
if ( !_tcscmp(type, _T("result"))) {
+ mir_cslock lck(m_privacyListManager.m_cs);
if (pList) {
m_privacyListManager.SetActiveListName(pList->GetListName());
- mir_sntprintf(szText, SIZEOF(szText), TranslateT("Privacy list %s set as active"), pList->GetListName());
+ szText.Format( TranslateT("Privacy list %s set as active"), pList->GetListName());
}
else {
m_privacyListManager.SetActiveListName(NULL);
- mir_sntprintf(szText, SIZEOF(szText), TranslateT("Active privacy list successfully declined"));
+ szText.Format( TranslateT("Active privacy list successfully declined"));
}
}
- else mir_sntprintf(szText, SIZEOF(szText), TranslateT("Error occurred while setting active list"));
+ else szText = TranslateT("Error occurred while setting active list");
- m_privacyListManager.Unlock();
-
- if (m_pDlgPrivacyLists)
- {
+ if (m_pDlgPrivacyLists) {
m_pDlgPrivacyLists->SetStatusText(szText);
RedrawWindow(GetDlgItem(m_pDlgPrivacyLists->GetHwnd(), IDC_LB_LISTS), NULL, NULL, RDW_INVALIDATE);
}
@@ -211,38 +207,35 @@ void CJabberProto::OnIqResultPrivacyListActive(HXML iqNode, CJabberIqInfo *pInfo
void CJabberProto::OnIqResultPrivacyListDefault(HXML iqNode, CJabberIqInfo *pInfo)
{
- CPrivacyList *pList = (CPrivacyList *)pInfo->GetUserData();
-
if (m_pDlgPrivacyLists)
EnableWindow(GetDlgItem(m_pDlgPrivacyLists->GetHwnd(), IDC_SET_DEFAULT), TRUE);
- if ( !iqNode)
+ if (iqNode == NULL)
return;
const TCHAR *type = xmlGetAttrValue(iqNode, _T("type"));
- if ( !type)
+ if (type == NULL)
return;
TCHAR szText[ 512 ];
szText[0] = _T('\0');
- m_privacyListManager.Lock();
- if ( !_tcscmp(type, _T("result"))) {
- if (pList) {
- m_privacyListManager.SetDefaultListName(pList->GetListName());
- mir_sntprintf(szText, SIZEOF(szText), TranslateT("Privacy list %s set as default"), pList->GetListName());
- }
- else {
- m_privacyListManager.SetDefaultListName(NULL);
- mir_sntprintf(szText, SIZEOF(szText), TranslateT("Default privacy list successfully declined"));
+ {
+ mir_cslock lck(m_privacyListManager.m_cs);
+ if ( !_tcscmp(type, _T("result"))) {
+ CPrivacyList *pList = (CPrivacyList *)pInfo->GetUserData();
+ if (pList) {
+ m_privacyListManager.SetDefaultListName(pList->GetListName());
+ mir_sntprintf(szText, SIZEOF(szText), TranslateT("Privacy list %s set as default"), pList->GetListName());
+ }
+ else {
+ m_privacyListManager.SetDefaultListName(NULL);
+ mir_sntprintf(szText, SIZEOF(szText), TranslateT("Default privacy list successfully declined"));
+ }
}
+ else mir_sntprintf(szText, SIZEOF(szText), TranslateT("Error occurred while setting default list"));
}
- else {
- mir_sntprintf(szText, SIZEOF(szText), TranslateT("Error occurred while setting default list"));
- }
- m_privacyListManager.Unlock();
- if (m_pDlgPrivacyLists)
- {
+ if (m_pDlgPrivacyLists) {
m_pDlgPrivacyLists->SetStatusText(szText);
RedrawWindow(GetDlgItem(m_pDlgPrivacyLists->GetHwnd(), IDC_LB_LISTS), NULL, NULL, RDW_INVALIDATE);
}
@@ -254,45 +247,44 @@ void CJabberProto::OnIqResultPrivacyLists(HXML iqNode, CJabberIqInfo *pInfo)
return;
HXML query = xmlGetChild(iqNode, "query");
- if ( !query)
+ if (query == NULL)
return;
if (m_ThreadInfo)
m_ThreadInfo->jabberServerCaps |= JABBER_CAPS_PRIVACY_LISTS;
+ {
+ mir_cslock lck(m_privacyListManager.m_cs);
+ m_privacyListManager.RemoveAllLists();
- m_privacyListManager.Lock();
- m_privacyListManager.RemoveAllLists();
-
- for (int i = 1; ; i++) {
- HXML list = xmlGetNthChild(query, _T("list"), i);
- if ( !list)
- break;
-
- const TCHAR *listName = xmlGetAttrValue(list, _T("name"));
- if (listName) {
- m_privacyListManager.AddList((TCHAR*)listName);
-
- // Query contents only if list editior is visible!
- if (m_pDlgPrivacyLists)
- m_ThreadInfo->send(
- XmlNodeIq( AddIQ(&CJabberProto::OnIqResultPrivacyList, JABBER_IQ_TYPE_GET))
- << XQUERY(JABBER_FEAT_PRIVACY_LISTS) << XCHILD(_T("list")) << XATTR(_T("name"), listName));
- } }
-
- const TCHAR *szName = NULL;
- HXML node = xmlGetChild(query , "active");
- if (node)
- szName = xmlGetAttrValue(node, _T("name"));
- m_privacyListManager.SetActiveListName(szName);
+ for (int i = 1; ; i++) {
+ HXML list = xmlGetNthChild(query, _T("list"), i);
+ if (list == NULL)
+ break;
- szName = NULL;
- node = xmlGetChild(query , "default");
- if (node)
- szName = xmlGetAttrValue(node, _T("name"));
- m_privacyListManager.SetDefaultListName(szName);
+ const TCHAR *listName = xmlGetAttrValue(list, _T("name"));
+ if (listName) {
+ m_privacyListManager.AddList((TCHAR*)listName);
- m_privacyListManager.Unlock();
+ // Query contents only if list editior is visible!
+ if (m_pDlgPrivacyLists)
+ m_ThreadInfo->send(
+ XmlNodeIq( AddIQ(&CJabberProto::OnIqResultPrivacyList, JABBER_IQ_TYPE_GET))
+ << XQUERY(JABBER_FEAT_PRIVACY_LISTS) << XCHILD(_T("list")) << XATTR(_T("name"), listName));
+ }
+ }
+ const TCHAR *szName = NULL;
+ HXML node = xmlGetChild(query , "active");
+ if (node)
+ szName = xmlGetAttrValue(node, _T("name"));
+ m_privacyListManager.SetActiveListName(szName);
+
+ szName = NULL;
+ node = xmlGetChild(query , "default");
+ if (node)
+ szName = xmlGetAttrValue(node, _T("name"));
+ m_privacyListManager.SetDefaultListName(szName);
+ }
UI_SAFE_NOTIFY(m_pDlgPrivacyLists, WM_JABBER_REFRESH);
BuildPrivacyListsMenu(true);
@@ -372,8 +364,7 @@ public:
TCHAR *szTypes[] = { _T("JID"), _T("Group"), _T("Subscription"), _T("Any") };
int i, nTypes[] = { Jid, Group, Subscription, Else };
- for (i=0; i < SIZEOF(szTypes); i++)
- {
+ for (i=0; i < SIZEOF(szTypes); i++) {
LRESULT nItem = SendDlgItemMessage(m_hwnd, IDC_COMBO_TYPE, CB_ADDSTRING, 0, (LPARAM)TranslateTS(szTypes[i]));
SendDlgItemMessage(m_hwnd, IDC_COMBO_TYPE, CB_SETITEMDATA, nItem, nTypes[i]);
if (m_pRule->GetType() == nTypes[i])
@@ -382,8 +373,7 @@ public:
SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUE, CB_RESETCONTENT, 0, 0);
TCHAR *szSubscriptions[] = { _T("none"), _T("from"), _T("to"), _T("both") };
- for (i=0; i < SIZEOF(szSubscriptions); i++)
- {
+ for (i=0; i < SIZEOF(szSubscriptions); i++) {
LRESULT nItem = SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUE, CB_ADDSTRING, 0, (LPARAM)TranslateTS(szSubscriptions[i]));
SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUE, CB_SETITEMDATA, nItem, (LPARAM)szSubscriptions[i]);
}
@@ -421,13 +411,12 @@ public:
LRESULT nItemData = SendDlgItemMessage(m_hwnd, IDC_COMBO_TYPE, CB_GETITEMDATA, nCurSel, 0);
switch (nItemData) {
- case Jid:
- {
- ShowWindow(GetDlgItem(m_hwnd, IDC_COMBO_VALUES), SW_SHOW);
- ShowWindow(GetDlgItem(m_hwnd, IDC_COMBO_VALUE), SW_HIDE);
-
- SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUES, CB_RESETCONTENT, 0, 0);
+ case Jid:
+ ShowWindow(GetDlgItem(m_hwnd, IDC_COMBO_VALUES), SW_SHOW);
+ ShowWindow(GetDlgItem(m_hwnd, IDC_COMBO_VALUE), SW_HIDE);
+ SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUES, CB_RESETCONTENT, 0, 0);
+ {
for (HANDLE hContact = db_find_first(m_proto->m_szModuleName); hContact; hContact = db_find_next(hContact, m_proto->m_szModuleName)) {
DBVARIANT dbv;
if ( !m_proto->getTString(hContact, "jid", &dbv)) {
@@ -443,64 +432,54 @@ public:
if (item = m_proto->ListGetItemPtrFromIndex(i))
SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUES, CB_ADDSTRING, 0, (LPARAM)item->jid);
}
-
- // FIXME: ugly code :)
- if (m_pRule->GetValue())
- {
- SetDlgItemText(m_hwnd, IDC_COMBO_VALUES, m_pRule->GetValue());
- LRESULT nSelPos = SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUES, CB_FINDSTRINGEXACT , -1, (LPARAM)m_pRule->GetValue());
- if (nSelPos != CB_ERR)
- SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUES, CB_SETCURSEL, nSelPos, 0);
- }
- break;
}
- case Group:
- {
- ShowWindow(GetDlgItem(m_hwnd, IDC_COMBO_VALUES), SW_SHOW);
- ShowWindow(GetDlgItem(m_hwnd, IDC_COMBO_VALUE), SW_HIDE);
+ // FIXME: ugly code :)
+ if (m_pRule->GetValue()) {
+ SetDlgItemText(m_hwnd, IDC_COMBO_VALUES, m_pRule->GetValue());
+ LRESULT nSelPos = SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUES, CB_FINDSTRINGEXACT , -1, (LPARAM)m_pRule->GetValue());
+ if (nSelPos != CB_ERR)
+ SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUES, CB_SETCURSEL, nSelPos, 0);
+ }
+ break;
- SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUES, CB_RESETCONTENT, 0, 0);
+ case Group:
+ ShowWindow(GetDlgItem(m_hwnd, IDC_COMBO_VALUES), SW_SHOW);
+ ShowWindow(GetDlgItem(m_hwnd, IDC_COMBO_VALUE), SW_HIDE);
+ SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUES, CB_RESETCONTENT, 0, 0);
+ {
TCHAR *grpName;
for (int i=1; (grpName = pcli->pfnGetGroupName(i, NULL)) != NULL; i++)
SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUES, CB_ADDSTRING, 0, (LPARAM)grpName);
+ }
- // FIXME: ugly code :)
- if (m_pRule->GetValue())
- {
- SetDlgItemText(m_hwnd, IDC_COMBO_VALUES, m_pRule->GetValue());
- LRESULT nSelPos = SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUES, CB_FINDSTRINGEXACT , -1, (LPARAM)m_pRule->GetValue());
- if (nSelPos != CB_ERR)
- SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUES, CB_SETCURSEL, nSelPos, 0);
- }
- break;
+ // FIXME: ugly code :)
+ if (m_pRule->GetValue()) {
+ SetDlgItemText(m_hwnd, IDC_COMBO_VALUES, m_pRule->GetValue());
+ LRESULT nSelPos = SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUES, CB_FINDSTRINGEXACT , -1, (LPARAM)m_pRule->GetValue());
+ if (nSelPos != CB_ERR)
+ SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUES, CB_SETCURSEL, nSelPos, 0);
}
+ break;
- case Subscription:
- {
- ShowWindow(GetDlgItem(m_hwnd, IDC_COMBO_VALUES), SW_HIDE);
- ShowWindow(GetDlgItem(m_hwnd, IDC_COMBO_VALUE), SW_SHOW);
+ case Subscription:
+ ShowWindow(GetDlgItem(m_hwnd, IDC_COMBO_VALUES), SW_HIDE);
+ ShowWindow(GetDlgItem(m_hwnd, IDC_COMBO_VALUE), SW_SHOW);
- if (m_pRule->GetValue())
- {
- LRESULT nSelected = SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUE, CB_SELECTSTRING, -1, (LPARAM)TranslateTS(m_pRule->GetValue()));
- if (nSelected == CB_ERR)
- SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUE, CB_SETCURSEL, 0, 0);
- }
- else SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUE, CB_SETCURSEL, 0, 0);
- break;
+ if (m_pRule->GetValue()) {
+ LRESULT nSelected = SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUE, CB_SELECTSTRING, -1, (LPARAM)TranslateTS(m_pRule->GetValue()));
+ if (nSelected == CB_ERR)
+ SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUE, CB_SETCURSEL, 0, 0);
}
+ else SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUE, CB_SETCURSEL, 0, 0);
+ break;
- case Else:
- {
- ShowWindow(GetDlgItem(m_hwnd, IDC_COMBO_VALUES), SW_HIDE);
- ShowWindow(GetDlgItem(m_hwnd, IDC_COMBO_VALUE), SW_HIDE);
- break;
- }
+ case Else:
+ ShowWindow(GetDlgItem(m_hwnd, IDC_COMBO_VALUES), SW_HIDE);
+ ShowWindow(GetDlgItem(m_hwnd, IDC_COMBO_VALUE), SW_HIDE);
+ break;
}
-
- return;
}
void btnOk_OnClick(CCtrlButton *)
@@ -510,29 +489,27 @@ public:
if (nCurSel != CB_ERR)
nItemData = SendDlgItemMessage(m_hwnd, IDC_COMBO_TYPE, CB_GETITEMDATA, nCurSel, 0);
- switch (nItemData)
- {
- case Jid:
- case Group:
+ switch (nItemData) {
+ case Jid:
+ case Group:
{
TCHAR szText[ 512 ];
GetDlgItemText(m_hwnd, IDC_COMBO_VALUES, szText, SIZEOF(szText));
m_pRule->SetValue(szText);
- break;
- }
- case Subscription:
- {
- nCurSel = SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUE, CB_GETCURSEL, 0, 0);
- if (nCurSel != CB_ERR)
- m_pRule->SetValue((TCHAR*)SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUE, CB_GETITEMDATA, nCurSel, 0));
- else
- m_pRule->SetValue(_T("none"));
- break;
}
+ break;
- default:
- m_pRule->SetValue(NULL);
- break;
+ case Subscription:
+ nCurSel = SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUE, CB_GETCURSEL, 0, 0);
+ if (nCurSel != CB_ERR)
+ m_pRule->SetValue((TCHAR*)SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUE, CB_GETITEMDATA, nCurSel, 0));
+ else
+ m_pRule->SetValue(_T("none"));
+ break;
+
+ default:
+ m_pRule->SetValue(NULL);
+ break;
}
m_pRule->SetType((PrivacyListRuleType)nItemData);
@@ -671,8 +648,7 @@ protected:
TCLCInfo(): newJids(1, TJidData::cmp), bChanged(false), pList(0) {}
~TCLCInfo()
{
- for (int i=0; i < newJids.getCount(); i++)
- {
+ for (int i=0; i < newJids.getCount(); i++) {
mir_free(newJids[i]->jid);
mir_free(newJids[i]);
}
@@ -899,23 +875,23 @@ void CJabberDlgPrivacyLists::OnProtoRefresh(WPARAM, LPARAM)
LRESULT nItemId = SendDlgItemMessage(m_hwnd, IDC_LB_LISTS, LB_ADDSTRING, 0, (LPARAM)TranslateT("<none>"));
SendDlgItemMessage(m_hwnd, IDC_LB_LISTS, LB_SETITEMDATA, nItemId, 0);
+ {
+ mir_cslock lck(m_proto->m_privacyListManager.m_cs);
- m_proto->m_privacyListManager.Lock();
- CPrivacyList* pList = m_proto->m_privacyListManager.GetFirstList();
- while (pList) {
- if ( !pList->IsDeleted()) {
- nItemId = SendDlgItemMessage(m_hwnd, IDC_LB_LISTS, LB_ADDSTRING, 0, (LPARAM)pList->GetListName());
- SendDlgItemMessage(m_hwnd, IDC_LB_LISTS, LB_SETITEMDATA, nItemId, (LPARAM)pList);
+ CPrivacyList *pList = m_proto->m_privacyListManager.GetFirstList();
+ while (pList) {
+ if ( !pList->IsDeleted()) {
+ nItemId = SendDlgItemMessage(m_hwnd, IDC_LB_LISTS, LB_ADDSTRING, 0, (LPARAM)pList->GetListName());
+ SendDlgItemMessage(m_hwnd, IDC_LB_LISTS, LB_SETITEMDATA, nItemId, (LPARAM)pList);
+ }
+ pList = pList->GetNext();
}
- pList = pList->GetNext();
- }
-
- if ( !szCurrentSelectedList || (SendDlgItemMessage(m_hwnd, IDC_LB_LISTS, LB_SELECTSTRING, -1, (LPARAM)szCurrentSelectedList) == LB_ERR))
- SendDlgItemMessage(m_hwnd, IDC_LB_LISTS, LB_SETCURSEL, 0, 0);
- if (szCurrentSelectedList)
- mir_free(szCurrentSelectedList);
- m_proto->m_privacyListManager.Unlock();
+ if ( !szCurrentSelectedList || (SendDlgItemMessage(m_hwnd, IDC_LB_LISTS, LB_SELECTSTRING, -1, (LPARAM)szCurrentSelectedList) == LB_ERR))
+ SendDlgItemMessage(m_hwnd, IDC_LB_LISTS, LB_SETCURSEL, 0, 0);
+ if (szCurrentSelectedList)
+ mir_free(szCurrentSelectedList);
+ }
PostMessage(m_hwnd, WM_COMMAND, MAKEWPARAM(IDC_LB_LISTS, LBN_SELCHANGE), 0);
EnableEditorControls();
@@ -942,6 +918,22 @@ BOOL CJabberDlgPrivacyLists::OnWmMeasureItem(UINT, WPARAM, LPARAM lParam)
return TRUE;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
+struct
+{
+ TCHAR *textEng;
+ char *icon;
+ TCHAR *text;
+}
+static drawItems[] =
+{
+ { _T("Message"), "pl_msg_allow" },
+ { _T("Presence (in)"), "pl_prin_allow" },
+ { _T("Presence (out)"), "pl_prout_allow" },
+ { _T("Query"), "pl_iq_allow" }
+};
+
BOOL CJabberDlgPrivacyLists::OnWmDrawItem(UINT, WPARAM, LPARAM lParam)
{
LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
@@ -950,27 +942,12 @@ BOOL CJabberDlgPrivacyLists::OnWmDrawItem(UINT, WPARAM, LPARAM lParam)
DrawRulesList(lpdis);
else if (lpdis->CtlID == IDC_LB_LISTS)
DrawLists(lpdis);
- else if (lpdis->CtlID == IDC_CANVAS)
- {
- static struct
- {
- TCHAR *textEng;
- char *icon;
- TCHAR *text;
- } items[] =
- {
- { _T("Message"), "pl_msg_allow" },
- { _T("Presence (in)"), "pl_prin_allow" },
- { _T("Presence (out)"), "pl_prout_allow" },
- { _T("Query"), "pl_iq_allow" },
- };
-
+ else if (lpdis->CtlID == IDC_CANVAS) {
int i, totalWidth = -5; // spacing for last item
- for (i=0; i < SIZEOF(items); i++)
- {
+ for (i=0; i < SIZEOF(drawItems); i++) {
SIZE sz = {0};
- items[i].text = TranslateTS(items[i].textEng);
- GetTextExtentPoint32(lpdis->hDC, items[i].text, lstrlen(items[i].text), &sz);
+ drawItems[i].text = TranslateTS(drawItems[i].textEng);
+ GetTextExtentPoint32(lpdis->hDC, drawItems[i].text, lstrlen(drawItems[i].text), &sz);
totalWidth += sz.cx + 18 + 5; // 18 pixels for icon, 5 pixel spacing
}
@@ -978,12 +955,11 @@ BOOL CJabberDlgPrivacyLists::OnWmDrawItem(UINT, WPARAM, LPARAM lParam)
RECT rc = lpdis->rcItem;
rc.left = (rc.left + rc.right - totalWidth)/2;
- for (i=0; i < SIZEOF(items); i++)
- {
- DrawIconEx(lpdis->hDC, rc.left, (rc.top+rc.bottom-16)/2, m_proto->LoadIconEx(items[i].icon),
+ for (i=0; i < SIZEOF(drawItems); i++) {
+ DrawIconEx(lpdis->hDC, rc.left, (rc.top+rc.bottom-16)/2, m_proto->LoadIconEx(drawItems[i].icon),
16, 16, 0, NULL, DI_NORMAL);
rc.left += 18;
- DrawNextRulePart(lpdis->hDC, clText, items[i].text, &rc);
+ DrawNextRulePart(lpdis->hDC, clText, drawItems[i].text, &rc);
rc.left += 5;
}
}
@@ -1008,7 +984,6 @@ void CJabberDlgPrivacyLists::ShowAdvancedList(CPrivacyList *pList)
BOOL bListEmpty = TRUE;
CPrivacyListRule* pRule = pList->GetFirstRule();
-
while (pRule) {
bListEmpty = FALSE;
TCHAR szTypeValue[ 512 ];
@@ -1052,7 +1027,8 @@ void CJabberDlgPrivacyLists::ShowAdvancedList(CPrivacyList *pList)
if (_tcslen(szPackets))
_tcscat(szPackets, _T(", "));
_tcscat(szPackets, _T("queries"));
- } }
+ }
+ }
TCHAR szListItem[ 512 ];
mir_sntprintf(szListItem, SIZEOF(szListItem), _T("%s %s %s"), szTypeValue, pRule->GetAction() ? _T("allow") : _T("deny"), szPackets);
@@ -1086,10 +1062,8 @@ void CJabberDlgPrivacyLists::DrawRuleAction(HDC hdc, COLORREF clLine1, COLORREF,
{
DrawNextRulePart(hdc, clLine1, pRule->GetAction() ? TranslateT("allow ") : TranslateT("deny "), rc);
if ( !pRule->GetPackets() || (pRule->GetPackets() == JABBER_PL_RULE_TYPE_ALL))
- {
DrawNextRulePart(hdc, clLine1, TranslateT("all."), rc);
- } else
- {
+ else {
bool needComma = false;
int itemCount =
((pRule->GetPackets() & JABBER_PL_RULE_TYPE_MESSAGE) ? 1 : 0) +
@@ -1097,30 +1071,26 @@ void CJabberDlgPrivacyLists::DrawRuleAction(HDC hdc, COLORREF clLine1, COLORREF,
((pRule->GetPackets() & JABBER_PL_RULE_TYPE_PRESENCE_OUT) ? 1 : 0) +
((pRule->GetPackets() & JABBER_PL_RULE_TYPE_IQ) ? 1 : 0);
- if (pRule->GetPackets() & JABBER_PL_RULE_TYPE_MESSAGE)
- {
+ if (pRule->GetPackets() & JABBER_PL_RULE_TYPE_MESSAGE) {
--itemCount;
needComma = true;
DrawNextRulePart(hdc, clLine1, TranslateT("messages"), rc);
}
- if (pRule->GetPackets() & JABBER_PL_RULE_TYPE_PRESENCE_IN)
- {
+ if (pRule->GetPackets() & JABBER_PL_RULE_TYPE_PRESENCE_IN) {
--itemCount;
if (needComma)
DrawNextRulePart(hdc, clLine1, itemCount ? _T(", ") : TranslateT(" and "), rc);
needComma = true;
DrawNextRulePart(hdc, clLine1, TranslateT("incoming presences"), rc);
}
- if (pRule->GetPackets() & JABBER_PL_RULE_TYPE_PRESENCE_OUT)
- {
+ if (pRule->GetPackets() & JABBER_PL_RULE_TYPE_PRESENCE_OUT) {
--itemCount;
if (needComma)
DrawNextRulePart(hdc, clLine1, itemCount ? _T(", ") : TranslateT(" and "), rc);
needComma = true;
DrawNextRulePart(hdc, clLine1, TranslateT("outgoing presences"), rc);
}
- if (pRule->GetPackets() & JABBER_PL_RULE_TYPE_IQ)
- {
+ if (pRule->GetPackets() & JABBER_PL_RULE_TYPE_IQ) {
--itemCount;
if (needComma)
DrawNextRulePart(hdc, clLine1, itemCount ? _T(", ") : TranslateT(" and "), rc);
@@ -1139,13 +1109,12 @@ void CJabberDlgPrivacyLists::DrawRulesList(LPDRAWITEMSTRUCT lpdis)
CPrivacyListRule *pRule = (CPrivacyListRule *)lpdis->itemData;
COLORREF clLine1, clLine2, clBack;
- if (lpdis->itemState & ODS_SELECTED)
- {
+ if (lpdis->itemState & ODS_SELECTED) {
FillRect(lpdis->hDC, &lpdis->rcItem, GetSysColorBrush(COLOR_HIGHLIGHT));
clBack = GetSysColor(COLOR_HIGHLIGHT);
clLine1 = GetSysColor(COLOR_HIGHLIGHTTEXT);
- } else
- {
+ }
+ else {
FillRect(lpdis->hDC, &lpdis->rcItem, GetSysColorBrush(COLOR_WINDOW));
clBack = GetSysColor(COLOR_WINDOW);
clLine1 = GetSysColor(COLOR_WINDOWTEXT);
@@ -1153,13 +1122,11 @@ void CJabberDlgPrivacyLists::DrawRulesList(LPDRAWITEMSTRUCT lpdis)
clLine2 = RGB(
GetRValue(clLine1) * 0.66 + GetRValue(clBack) * 0.34,
GetGValue(clLine1) * 0.66 + GetGValue(clBack) * 0.34,
- GetBValue(clLine1) * 0.66 + GetBValue(clBack) * 0.34
- );
+ GetBValue(clLine1) * 0.66 + GetBValue(clBack) * 0.34);
SetBkMode(lpdis->hDC, TRANSPARENT);
RECT rc;
-
if ( !pRule) {
rc = lpdis->rcItem;
rc.left += 25;
@@ -1181,9 +1148,8 @@ void CJabberDlgPrivacyLists::DrawRulesList(LPDRAWITEMSTRUCT lpdis)
rc.bottom -= (rc.bottom - rc.top) / 2;
rc.left += 25;
- switch (pRule->GetType())
- {
- case Jid:
+ switch (pRule->GetType()) {
+ case Jid:
{
DrawNextRulePart(lpdis->hDC, clLine2, TranslateT("If jabber id is '"), &rc);
DrawNextRulePart(lpdis->hDC, clLine1, pRule->GetValue(), &rc);
@@ -1199,16 +1165,17 @@ void CJabberDlgPrivacyLists::DrawRulesList(LPDRAWITEMSTRUCT lpdis)
break;
}
- case Group:
- DrawNextRulePart(lpdis->hDC, clLine2, TranslateT("If group is '"), &rc);
- DrawNextRulePart(lpdis->hDC, clLine1, pRule->GetValue(), &rc);
- DrawNextRulePart(lpdis->hDC, clLine2, TranslateT("'"), &rc);
- break;
- case Subscription:
- DrawNextRulePart(lpdis->hDC, clLine2, TranslateT("If subscription is '"), &rc);
- DrawNextRulePart(lpdis->hDC, clLine1, pRule->GetValue(), &rc);
- DrawNextRulePart(lpdis->hDC, clLine2, TranslateT("'"), &rc);
- break;
+ case Group:
+ DrawNextRulePart(lpdis->hDC, clLine2, TranslateT("If group is '"), &rc);
+ DrawNextRulePart(lpdis->hDC, clLine1, pRule->GetValue(), &rc);
+ DrawNextRulePart(lpdis->hDC, clLine2, TranslateT("'"), &rc);
+ break;
+
+ case Subscription:
+ DrawNextRulePart(lpdis->hDC, clLine2, TranslateT("If subscription is '"), &rc);
+ DrawNextRulePart(lpdis->hDC, clLine1, pRule->GetValue(), &rc);
+ DrawNextRulePart(lpdis->hDC, clLine2, TranslateT("'"), &rc);
+ break;
}
rc = lpdis->rcItem;
@@ -1222,15 +1189,12 @@ void CJabberDlgPrivacyLists::DrawRulesList(LPDRAWITEMSTRUCT lpdis)
DrawIconEx(lpdis->hDC, lpdis->rcItem.left+4, (lpdis->rcItem.top+lpdis->rcItem.bottom-16)/2,
m_proto->LoadIconEx("main"), 16, 16, 0, NULL, DI_NORMAL);
- if (pRule)
- {
+ if (pRule)
DrawIconEx(lpdis->hDC, lpdis->rcItem.left+4, (lpdis->rcItem.top+lpdis->rcItem.bottom-16)/2,
m_proto->LoadIconEx(pRule->GetAction() ? "disco_ok" : "disco_fail"),
16, 16, 0, NULL, DI_NORMAL);
- }
- if (lpdis->itemState & ODS_FOCUS)
- {
+ if (lpdis->itemState & ODS_FOCUS) {
LRESULT sel = SendDlgItemMessage(m_hwnd, lpdis->CtlID, LB_GETCURSEL, 0, 0);
if ((sel == LB_ERR) || (sel == (LRESULT)lpdis->itemID))
DrawFocusRect(lpdis->hDC, &lpdis->rcItem);
@@ -1245,13 +1209,12 @@ void CJabberDlgPrivacyLists::DrawLists(LPDRAWITEMSTRUCT lpdis)
CPrivacyList *pList = (CPrivacyList *)lpdis->itemData;
COLORREF clLine1, clLine2, clBack;
- if (lpdis->itemState & ODS_SELECTED)
- {
+ if (lpdis->itemState & ODS_SELECTED) {
FillRect(lpdis->hDC, &lpdis->rcItem, GetSysColorBrush(COLOR_HIGHLIGHT));
clBack = GetSysColor(COLOR_HIGHLIGHT);
clLine1 = GetSysColor(COLOR_HIGHLIGHTTEXT);
- } else
- {
+ }
+ else {
FillRect(lpdis->hDC, &lpdis->rcItem, GetSysColorBrush(COLOR_WINDOW));
clBack = GetSysColor(COLOR_WINDOW);
clLine1 = GetSysColor(COLOR_WINDOWTEXT);
@@ -1259,17 +1222,17 @@ void CJabberDlgPrivacyLists::DrawLists(LPDRAWITEMSTRUCT lpdis)
clLine2 = RGB(
GetRValue(clLine1) * 0.66 + GetRValue(clBack) * 0.34,
GetGValue(clLine1) * 0.66 + GetGValue(clBack) * 0.34,
- GetBValue(clLine1) * 0.66 + GetBValue(clBack) * 0.34
- );
+ GetBValue(clLine1) * 0.66 + GetBValue(clBack) * 0.34);
SetBkMode(lpdis->hDC, TRANSPARENT);
- RECT rc;
- m_proto->m_privacyListManager.Lock();
- TCHAR *szDefault = NEWTSTR_ALLOCA(m_proto->m_privacyListManager.GetDefaultListName());
- TCHAR *szActive = NEWTSTR_ALLOCA(m_proto->m_privacyListManager.GetActiveListName());
- m_proto->m_privacyListManager.Unlock();
+ TCHAR *szDefault, *szActive;
+ { mir_cslock lck(m_proto->m_privacyListManager.m_cs);
+ szDefault = NEWTSTR_ALLOCA(m_proto->m_privacyListManager.GetDefaultListName());
+ szActive = NEWTSTR_ALLOCA(m_proto->m_privacyListManager.GetActiveListName());
+ }
+ RECT rc;
rc = lpdis->rcItem;
rc.left +=3;
@@ -1277,21 +1240,19 @@ void CJabberDlgPrivacyLists::DrawLists(LPDRAWITEMSTRUCT lpdis)
bool bDefault = false;
TCHAR *szName;
- if ( !pList)
- {
+ if ( !pList) {
if ( !szActive) bActive = true;
if ( !szDefault) bDefault = true;
szName = TranslateT("<none>");
- } else
- {
+ }
+ else {
if ( !lstrcmp(pList->GetListName(), szActive)) bActive = true;
if ( !lstrcmp(pList->GetListName(), szDefault)) bDefault = true;
szName = pList->GetListName();
}
HFONT hfnt = NULL;
- if (bActive)
- {
+ if (bActive) {
LOGFONT lf;
GetObject(GetCurrentObject(lpdis->hDC, OBJ_FONT), sizeof(lf), &lf);
lf.lfWeight = FW_BOLD;
@@ -1319,8 +1280,7 @@ void CJabberDlgPrivacyLists::DrawLists(LPDRAWITEMSTRUCT lpdis)
if (hfnt)
DeleteObject(SelectObject(lpdis->hDC, hfnt));
- if (lpdis->itemState & ODS_FOCUS)
- {
+ if (lpdis->itemState & ODS_FOCUS) {
int sel = SendDlgItemMessage(m_hwnd, lpdis->CtlID, LB_GETCURSEL, 0, 0);
if ((sel == LB_ERR) || (sel == (int)lpdis->itemID))
DrawFocusRect(lpdis->hDC, &lpdis->rcItem);
@@ -1364,25 +1324,19 @@ void CJabberDlgPrivacyLists::CListSetupIcons(HWND, HANDLE hItem, int iSlot, DWOR
HANDLE CJabberDlgPrivacyLists::CListAddContact(HWND hwndList, TCHAR *jid)
{
- HANDLE hItem = 0;
-
HANDLE hContact = m_proto->HContactFromJID(jid);
- if ( !hContact) {
- hItem = clc_info.findJid(jid);
- if ( !hItem)
- {
- CLCINFOITEM cii = {0};
- cii.cbSize = sizeof(cii);
- cii.pszText = jid;
- hItem = m_clcClist.AddInfoItem(&cii);
- CListResetIcons(hwndList, hItem);
- clc_info.addJid(hItem, jid);
- }
- } else
- {
- hItem = m_clcClist.FindContact(hContact);
+ if (hContact)
+ return m_clcClist.FindContact(hContact);
+
+ HANDLE hItem = clc_info.findJid(jid);
+ if ( !hItem) {
+ CLCINFOITEM cii = {0};
+ cii.cbSize = sizeof(cii);
+ cii.pszText = jid;
+ hItem = m_clcClist.AddInfoItem(&cii);
+ CListResetIcons(hwndList, hItem);
+ clc_info.addJid(hItem, jid);
}
-
return hItem;
}
@@ -1417,39 +1371,31 @@ void CJabberDlgPrivacyLists::CListApplyList(HWND hwndList, CPrivacyList *pList)
if ( !pList)
goto lbl_return;
- CPrivacyListRule *pRule;
- for (pRule = pList->GetFirstRule(); pRule; pRule = pRule->GetNext())
- {
+ for (CPrivacyListRule *pRule = pList->GetFirstRule(); pRule; pRule = pRule->GetNext()) {
HANDLE hItem = 0;
- switch (pRule->GetType())
- {
- case Jid:
- {
- hItem = CListAddContact(hwndList, pRule->GetValue());
- break;
- }
- case Group:
- {
- HANDLE hGroup = Clist_GroupExists(pRule->GetValue());
- hItem = m_clcClist.FindGroup(hGroup);
- break;
- }
- case Subscription:
- {
- if ( !lstrcmp(pRule->GetValue(), _T("none"))) hItem = clc_info.hItemSubNone;
- else if ( !lstrcmp(pRule->GetValue(), _T("from"))) hItem = clc_info.hItemSubFrom;
- else if ( !lstrcmp(pRule->GetValue(), _T("to"))) hItem = clc_info.hItemSubTo;
- else if ( !lstrcmp(pRule->GetValue(), _T("both"))) hItem = clc_info.hItemSubBoth;
- break;
- }
- case Else:
- {
- hItem = clc_info.hItemDefault;
- break;
- }
+ switch (pRule->GetType()) {
+ case Jid:
+ hItem = CListAddContact(hwndList, pRule->GetValue());
+ break;
+
+ case Group:
+ hItem = m_clcClist.FindGroup( Clist_GroupExists(pRule->GetValue()));
+ break;
+
+ case Subscription:
+ if ( !lstrcmp(pRule->GetValue(), _T("none"))) hItem = clc_info.hItemSubNone;
+ else if ( !lstrcmp(pRule->GetValue(), _T("from"))) hItem = clc_info.hItemSubFrom;
+ else if ( !lstrcmp(pRule->GetValue(), _T("to"))) hItem = clc_info.hItemSubTo;
+ else if ( !lstrcmp(pRule->GetValue(), _T("both"))) hItem = clc_info.hItemSubBoth;
+ break;
+
+ case Else:
+ hItem = clc_info.hItemDefault;
+ break;
}
- if ( !hItem) continue;
+ if (!hItem)
+ continue;
DWORD dwPackets = pRule->GetPackets();
if ( !dwPackets) dwPackets = JABBER_PL_RULE_TYPE_ALL;
@@ -1467,9 +1413,7 @@ DWORD CJabberDlgPrivacyLists::CListGetPackets(HWND, HANDLE hItem, bool bAction)
{
DWORD result = 0;
- int iIcon = 0;
-
- iIcon = m_clcClist.GetExtraImage(hItem, 0);
+ int iIcon = m_clcClist.GetExtraImage(hItem, 0);
if (bAction && (iIcon == 1)) result |= JABBER_PL_RULE_TYPE_MESSAGE;
else if ( !bAction && (iIcon == 2)) result |= JABBER_PL_RULE_TYPE_MESSAGE;
@@ -1490,9 +1434,8 @@ DWORD CJabberDlgPrivacyLists::CListGetPackets(HWND, HANDLE hItem, bool bAction)
void CJabberDlgPrivacyLists::CListBuildList(HWND hwndList, CPrivacyList *pList)
{
- if ( !pList) return;
-
- if ( !clc_info.bChanged) return;
+ if (!pList || !clc_info.bChanged)
+ return;
clc_info.bChanged = false;
@@ -1583,10 +1526,11 @@ void CJabberDlgPrivacyLists::CListBuildList(HWND hwndList, CPrivacyList *pList)
void CJabberDlgPrivacyLists::EnableEditorControls()
{
- m_proto->m_privacyListManager.Lock();
- BOOL bListsLoaded = m_proto->m_privacyListManager.IsAllListsLoaded();
- BOOL bListsModified = m_proto->m_privacyListManager.IsModified() || clc_info.bChanged;
- m_proto->m_privacyListManager.Unlock();
+ BOOL bListsLoaded, bListsModified;
+ { mir_cslock lck(m_proto->m_privacyListManager.m_cs);
+ bListsLoaded = m_proto->m_privacyListManager.IsAllListsLoaded();
+ bListsModified = m_proto->m_privacyListManager.IsModified() || clc_info.bChanged;
+ }
int nCurSel = SendDlgItemMessage(m_hwnd, IDC_PL_RULES_LIST, LB_GETCURSEL, 0, 0);
int nItemCount = SendDlgItemMessage(m_hwnd, IDC_PL_RULES_LIST, LB_GETCOUNT, 0, 0);
@@ -1654,9 +1598,10 @@ LRESULT CALLBACK CJabberDlgPrivacyLists::LstRulesSubclassProc(HWND hwnd, UINT ms
BOOL CJabberDlgPrivacyLists::CanExit()
{
- m_proto->m_privacyListManager.Lock();
- BOOL bModified = m_proto->m_privacyListManager.IsModified();
- m_proto->m_privacyListManager.Unlock();
+ BOOL bModified;
+ { mir_cslock lck(m_proto->m_privacyListManager.m_cs);
+ bModified = m_proto->m_privacyListManager.IsModified();
+ }
if (clc_info.bChanged)
bModified = TRUE;
@@ -1700,55 +1645,55 @@ void CJabberDlgPrivacyLists::btnAddJid_OnClick(CCtrlButton *)
void CJabberDlgPrivacyLists::btnActivate_OnClick(CCtrlButton *)
{
- if (m_proto->m_bJabberOnline)
- {
- m_proto->m_privacyListManager.Lock();
- CPrivacyList* pList = GetSelectedList(m_hwnd);
- if (pList && pList->IsModified()) {
- m_proto->m_privacyListManager.Unlock();
- MessageBox(m_hwnd, TranslateT("Please save list before activating"), TranslateT("First, save the list"), MB_OK | MB_ICONSTOP);
- return;
- }
- EnableWindow(GetDlgItem(m_hwnd, IDC_ACTIVATE), FALSE);
- SetWindowLongPtr(GetDlgItem(m_hwnd, IDC_ACTIVATE), GWLP_USERDATA, (LONG_PTR)pList);
- XmlNodeIq iq(m_proto->AddIQ(&CJabberProto::OnIqResultPrivacyListActive, JABBER_IQ_TYPE_SET, NULL, 0, -1, pList));
- HXML query = iq << XQUERY(JABBER_FEAT_PRIVACY_LISTS);
- HXML active = query << XCHILD(_T("active"));
- if (pList)
- active << XATTR(_T("name"), pList->GetListName());
- m_proto->m_privacyListManager.Unlock();
-
- SetStatusText(TranslateT(JABBER_PL_BUSY_MSG));
+ if (!m_proto->m_bJabberOnline)
+ return;
- m_proto->m_ThreadInfo->send(iq);
+ mir_cslockfull lck(m_proto->m_privacyListManager.m_cs);
+
+ CPrivacyList *pList = GetSelectedList(m_hwnd);
+ if (pList && pList->IsModified()) {
+ lck.unlock();
+ MessageBox(m_hwnd, TranslateT("Please save list before activating"), TranslateT("First, save the list"), MB_OK | MB_ICONSTOP);
+ return;
}
+ EnableWindow(GetDlgItem(m_hwnd, IDC_ACTIVATE), FALSE);
+ SetWindowLongPtr(GetDlgItem(m_hwnd, IDC_ACTIVATE), GWLP_USERDATA, (LONG_PTR)pList);
+ XmlNodeIq iq(m_proto->AddIQ(&CJabberProto::OnIqResultPrivacyListActive, JABBER_IQ_TYPE_SET, NULL, 0, -1, pList));
+ HXML query = iq << XQUERY(JABBER_FEAT_PRIVACY_LISTS);
+ HXML active = query << XCHILD(_T("active"));
+ if (pList)
+ active << XATTR(_T("name"), pList->GetListName());
+
+ lck.unlock();
+ SetStatusText(TranslateT(JABBER_PL_BUSY_MSG));
+ m_proto->m_ThreadInfo->send(iq);
}
void CJabberDlgPrivacyLists::btnSetDefault_OnClick(CCtrlButton *)
{
- if (m_proto->m_bJabberOnline)
- {
- m_proto->m_privacyListManager.Lock();
- CPrivacyList* pList = GetSelectedList(m_hwnd);
- if (pList && pList->IsModified()) {
- m_proto->m_privacyListManager.Unlock();
- MessageBox(m_hwnd, TranslateT("Please save list before you make it the default list"), TranslateT("First, save the list"), MB_OK | MB_ICONSTOP);
- return;
- }
- EnableWindow(GetDlgItem(m_hwnd, IDC_SET_DEFAULT), FALSE);
- SetWindowLongPtr(GetDlgItem(m_hwnd, IDC_SET_DEFAULT), GWLP_USERDATA, (LONG_PTR)pList);
-
- XmlNodeIq iq(m_proto->AddIQ(&CJabberProto::OnIqResultPrivacyListDefault, JABBER_IQ_TYPE_SET, NULL, 0, -1, pList));
- HXML query = iq << XQUERY(JABBER_FEAT_PRIVACY_LISTS);
- HXML defaultTag = query << XCHILD(_T("default"));
- if (pList)
- xmlAddAttr(defaultTag, _T("name"), pList->GetListName());
- m_proto->m_privacyListManager.Unlock();
+ if (!m_proto->m_bJabberOnline)
+ return;
- SetStatusText(TranslateT(JABBER_PL_BUSY_MSG));
+ mir_cslockfull lck(m_proto->m_privacyListManager.m_cs);
- m_proto->m_ThreadInfo->send(iq);
+ CPrivacyList *pList = GetSelectedList(m_hwnd);
+ if (pList && pList->IsModified()) {
+ lck.unlock();
+ MessageBox(m_hwnd, TranslateT("Please save list before you make it the default list"), TranslateT("First, save the list"), MB_OK | MB_ICONSTOP);
+ return;
}
+ EnableWindow(GetDlgItem(m_hwnd, IDC_SET_DEFAULT), FALSE);
+ SetWindowLongPtr(GetDlgItem(m_hwnd, IDC_SET_DEFAULT), GWLP_USERDATA, (LONG_PTR)pList);
+
+ XmlNodeIq iq(m_proto->AddIQ(&CJabberProto::OnIqResultPrivacyListDefault, JABBER_IQ_TYPE_SET, NULL, 0, -1, pList));
+ HXML query = iq << XQUERY(JABBER_FEAT_PRIVACY_LISTS);
+ HXML defaultTag = query << XCHILD(_T("default"));
+ if (pList)
+ xmlAddAttr(defaultTag, _T("name"), pList->GetListName());
+
+ lck.unlock();
+ SetStatusText(TranslateT(JABBER_PL_BUSY_MSG));
+ m_proto->m_ThreadInfo->send(iq);
}
void CJabberDlgPrivacyLists::lbLists_OnSelChange(CCtrlListBox *)
@@ -1760,14 +1705,12 @@ void CJabberDlgPrivacyLists::lbLists_OnSelChange(CCtrlListBox *)
LRESULT nErr = SendDlgItemMessage(m_hwnd, IDC_LB_LISTS, LB_GETITEMDATA, nCurSel, 0);
if (nErr == LB_ERR)
return;
- if (nErr == 0)
- {
- if (IsWindowVisible(GetDlgItem(m_hwnd, IDC_CLIST)))
- {
+ if (nErr == 0) {
+ if (IsWindowVisible(GetDlgItem(m_hwnd, IDC_CLIST))) {
CListBuildList(GetDlgItem(m_hwnd, IDC_CLIST), clc_info.pList);
CListApplyList(GetDlgItem(m_hwnd, IDC_CLIST), NULL);
- } else
- {
+ }
+ else {
EnableWindow(GetDlgItem(m_hwnd, IDC_PL_RULES_LIST), FALSE);
SendDlgItemMessage(m_hwnd, IDC_PL_RULES_LIST, LB_RESETCONTENT, 0, 0);
SendDlgItemMessage(m_hwnd, IDC_PL_RULES_LIST, LB_ADDSTRING, 0, (LPARAM)TranslateTS(_T("No list selected")));
@@ -1775,141 +1718,132 @@ void CJabberDlgPrivacyLists::lbLists_OnSelChange(CCtrlListBox *)
EnableEditorControls();
return;
}
-
- m_proto->m_privacyListManager.Lock();
- if (IsWindowVisible(GetDlgItem(m_hwnd, IDC_CLIST)))
{
- CListBuildList(GetDlgItem(m_hwnd, IDC_CLIST), clc_info.pList);
- CListApplyList(GetDlgItem(m_hwnd, IDC_CLIST), (CPrivacyList*)nErr);
+ mir_cslock lck(m_proto->m_privacyListManager.m_cs);
+ if (IsWindowVisible(GetDlgItem(m_hwnd, IDC_CLIST))) {
+ CListBuildList(GetDlgItem(m_hwnd, IDC_CLIST), clc_info.pList);
+ CListApplyList(GetDlgItem(m_hwnd, IDC_CLIST), (CPrivacyList*)nErr);
+ }
+ else ShowAdvancedList((CPrivacyList*)nErr);
}
- else ShowAdvancedList((CPrivacyList*)nErr);
-
- m_proto->m_privacyListManager.Unlock();
-
EnableEditorControls();
}
-void CJabberDlgPrivacyLists::lbLists_OnDblClick(CCtrlListBox *)
+void CJabberDlgPrivacyLists::lbLists_OnDblClick(CCtrlListBox*)
{
PostMessage(m_hwnd, WM_COMMAND, MAKEWPARAM(IDC_ACTIVATE, 0), 0);
}
-void CJabberDlgPrivacyLists::lbRules_OnSelChange(CCtrlListBox *)
+void CJabberDlgPrivacyLists::lbRules_OnSelChange(CCtrlListBox*)
{
EnableEditorControls();
}
-void CJabberDlgPrivacyLists::lbRules_OnDblClick(CCtrlListBox *)
+void CJabberDlgPrivacyLists::lbRules_OnDblClick(CCtrlListBox*)
{
PostMessage(m_hwnd, WM_COMMAND, MAKEWPARAM(IDC_EDIT_RULE, 0), 0);
}
-void CJabberDlgPrivacyLists::btnEditRule_OnClick(CCtrlButton *)
+void CJabberDlgPrivacyLists::btnEditRule_OnClick(CCtrlButton*)
{
// FIXME: potential deadlock due to PLM lock while editing rule
- m_proto->m_privacyListManager.Lock();
- {
- CPrivacyListRule* pRule = GetSelectedRule(m_hwnd);
- CPrivacyList* pList = GetSelectedList(m_hwnd);
- if (pList && pRule) {
- CJabberDlgPrivacyRule dlgPrivacyRule(m_proto, m_hwnd, pRule);
- int nResult = dlgPrivacyRule.DoModal();
- if (nResult) {
- pList->SetModified();
- PostMessage(m_hwnd, WM_JABBER_REFRESH, 0, 0);
- } } }
- m_proto->m_privacyListManager.Unlock();
+ mir_cslock lck(m_proto->m_privacyListManager.m_cs);
+
+ CPrivacyListRule* pRule = GetSelectedRule(m_hwnd);
+ CPrivacyList *pList = GetSelectedList(m_hwnd);
+ if (pList && pRule) {
+ CJabberDlgPrivacyRule dlgPrivacyRule(m_proto, m_hwnd, pRule);
+ int nResult = dlgPrivacyRule.DoModal();
+ if (nResult) {
+ pList->SetModified();
+ PostMessage(m_hwnd, WM_JABBER_REFRESH, 0, 0);
+ }
+ }
}
-void CJabberDlgPrivacyLists::btnAddRule_OnClick(CCtrlButton *)
+void CJabberDlgPrivacyLists::btnAddRule_OnClick(CCtrlButton*)
{
// FIXME: potential deadlock due to PLM lock while editing rule
- m_proto->m_privacyListManager.Lock();
- {
- CPrivacyList* pList = GetSelectedList(m_hwnd);
- if (pList) {
- CPrivacyListRule* pRule = new CPrivacyListRule(m_proto, Jid, _T(""), FALSE);
- CJabberDlgPrivacyRule dlgPrivacyRule(m_proto, m_hwnd, pRule);
- int nResult = dlgPrivacyRule.DoModal();
- if (nResult) {
- pList->AddRule(pRule);
- pList->Reorder();
- pList->SetModified();
- PostMessage(m_hwnd, WM_JABBER_REFRESH, 0, 0);
- }
- else delete pRule;
- } }
- m_proto->m_privacyListManager.Unlock();
-}
-
-void CJabberDlgPrivacyLists::btnRemoveRule_OnClick(CCtrlButton *)
-{
- m_proto->m_privacyListManager.Lock();
- {
- CPrivacyList* pList = GetSelectedList(m_hwnd);
- CPrivacyListRule* pRule = GetSelectedRule(m_hwnd);
-
- if (pList && pRule) {
- pList->RemoveRule(pRule);
- int nCurSel = SendDlgItemMessage(m_hwnd, IDC_PL_RULES_LIST, LB_GETCURSEL, 0, 0);
- int nItemCount = SendDlgItemMessage(m_hwnd, IDC_PL_RULES_LIST, LB_GETCOUNT, 0, 0);
- SendDlgItemMessage(m_hwnd, IDC_PL_RULES_LIST, LB_SETCURSEL, nCurSel != nItemCount - 1 ? nCurSel : nCurSel - 1, 0);
+ mir_cslock lck(m_proto->m_privacyListManager.m_cs);
+
+ CPrivacyList *pList = GetSelectedList(m_hwnd);
+ if (pList) {
+ CPrivacyListRule* pRule = new CPrivacyListRule(m_proto, Jid, _T(""), FALSE);
+ CJabberDlgPrivacyRule dlgPrivacyRule(m_proto, m_hwnd, pRule);
+ int nResult = dlgPrivacyRule.DoModal();
+ if (nResult) {
+ pList->AddRule(pRule);
pList->Reorder();
pList->SetModified();
PostMessage(m_hwnd, WM_JABBER_REFRESH, 0, 0);
- } }
-
- m_proto->m_privacyListManager.Unlock();
+ }
+ else delete pRule;
+ }
}
-void CJabberDlgPrivacyLists::btnUpRule_OnClick(CCtrlButton *)
+void CJabberDlgPrivacyLists::btnRemoveRule_OnClick(CCtrlButton*)
{
- m_proto->m_privacyListManager.Lock();
- {
- CPrivacyList* pList = GetSelectedList(m_hwnd);
- CPrivacyListRule* pRule = GetSelectedRule(m_hwnd);
+ mir_cslock lck(m_proto->m_privacyListManager.m_cs);
+
+ CPrivacyList *pList = GetSelectedList(m_hwnd);
+ CPrivacyListRule* pRule = GetSelectedRule(m_hwnd);
+
+ if (pList && pRule) {
+ pList->RemoveRule(pRule);
int nCurSel = SendDlgItemMessage(m_hwnd, IDC_PL_RULES_LIST, LB_GETCURSEL, 0, 0);
+ int nItemCount = SendDlgItemMessage(m_hwnd, IDC_PL_RULES_LIST, LB_GETCOUNT, 0, 0);
+ SendDlgItemMessage(m_hwnd, IDC_PL_RULES_LIST, LB_SETCURSEL, nCurSel != nItemCount - 1 ? nCurSel : nCurSel - 1, 0);
+ pList->Reorder();
+ pList->SetModified();
+ PostMessage(m_hwnd, WM_JABBER_REFRESH, 0, 0);
+ }
+}
- if (pList && pRule && nCurSel) {
- pRule->SetOrder(pRule->GetOrder() - 11);
- SendDlgItemMessage(m_hwnd, IDC_PL_RULES_LIST, LB_SETCURSEL, nCurSel - 1, 0);
- pList->Reorder();
- pList->SetModified();
- PostMessage(m_hwnd, WM_JABBER_REFRESH, 0, 0);
- } }
+void CJabberDlgPrivacyLists::btnUpRule_OnClick(CCtrlButton*)
+{
+ mir_cslock lck(m_proto->m_privacyListManager.m_cs);
- m_proto->m_privacyListManager.Unlock();
+ CPrivacyList *pList = GetSelectedList(m_hwnd);
+ CPrivacyListRule* pRule = GetSelectedRule(m_hwnd);
+ int nCurSel = SendDlgItemMessage(m_hwnd, IDC_PL_RULES_LIST, LB_GETCURSEL, 0, 0);
+
+ if (pList && pRule && nCurSel) {
+ pRule->SetOrder(pRule->GetOrder() - 11);
+ SendDlgItemMessage(m_hwnd, IDC_PL_RULES_LIST, LB_SETCURSEL, nCurSel - 1, 0);
+ pList->Reorder();
+ pList->SetModified();
+ PostMessage(m_hwnd, WM_JABBER_REFRESH, 0, 0);
+ }
}
-void CJabberDlgPrivacyLists::btnDownRule_OnClick(CCtrlButton *)
+void CJabberDlgPrivacyLists::btnDownRule_OnClick(CCtrlButton*)
{
- m_proto->m_privacyListManager.Lock();
- {
- CPrivacyList* pList = GetSelectedList(m_hwnd);
- CPrivacyListRule* pRule = GetSelectedRule(m_hwnd);
- int nCurSel = SendDlgItemMessage(m_hwnd, IDC_PL_RULES_LIST, LB_GETCURSEL, 0, 0);
- int nItemCount = SendDlgItemMessage(m_hwnd, IDC_PL_RULES_LIST, LB_GETCOUNT, 0, 0);
+ mir_cslock lck(m_proto->m_privacyListManager.m_cs);
- if (pList && pRule && (nCurSel != (nItemCount - 1))) {
- pRule->SetOrder(pRule->GetOrder() + 11);
- SendDlgItemMessage(m_hwnd, IDC_PL_RULES_LIST, LB_SETCURSEL, nCurSel + 1, 0);
- pList->Reorder();
- pList->SetModified();
- PostMessage(m_hwnd, WM_JABBER_REFRESH, 0, 0);
- } }
+ CPrivacyList *pList = GetSelectedList(m_hwnd);
+ CPrivacyListRule* pRule = GetSelectedRule(m_hwnd);
+ int nCurSel = SendDlgItemMessage(m_hwnd, IDC_PL_RULES_LIST, LB_GETCURSEL, 0, 0);
+ int nItemCount = SendDlgItemMessage(m_hwnd, IDC_PL_RULES_LIST, LB_GETCOUNT, 0, 0);
- m_proto->m_privacyListManager.Unlock();
+ if (pList && pRule && (nCurSel != (nItemCount - 1))) {
+ pRule->SetOrder(pRule->GetOrder() + 11);
+ SendDlgItemMessage(m_hwnd, IDC_PL_RULES_LIST, LB_SETCURSEL, nCurSel + 1, 0);
+ pList->Reorder();
+ pList->SetModified();
+ PostMessage(m_hwnd, WM_JABBER_REFRESH, 0, 0);
+ }
}
-void CJabberDlgPrivacyLists::btnAddList_OnClick(CCtrlButton *)
+void CJabberDlgPrivacyLists::btnAddList_OnClick(CCtrlButton*)
{
// FIXME: line length is hard coded in dialog procedure
CJabberDlgPrivacyAddList dlgPrivacyAddList(m_proto, m_hwnd);
int nRetVal = dlgPrivacyAddList.DoModal();
if (nRetVal && _tcslen(dlgPrivacyAddList.szLine)) {
- m_proto->m_privacyListManager.Lock();
- CPrivacyList* pList = m_proto->m_privacyListManager.FindList(dlgPrivacyAddList.szLine);
- if ( !pList) {
+ mir_cslockfull lck(m_proto->m_privacyListManager.m_cs);
+
+ CPrivacyList *pList = m_proto->m_privacyListManager.FindList(dlgPrivacyAddList.szLine);
+ if (pList == NULL) {
m_proto->m_privacyListManager.AddList(dlgPrivacyAddList.szLine);
pList = m_proto->m_privacyListManager.FindList(dlgPrivacyAddList.szLine);
if (pList) {
@@ -1925,29 +1859,31 @@ void CJabberDlgPrivacyLists::btnAddList_OnClick(CCtrlButton *)
SendDlgItemMessage(m_hwnd, IDC_LB_LISTS, LB_SETITEMDATA, nSelected, (LPARAM)pList);
SendDlgItemMessage(m_hwnd, IDC_LB_LISTS, LB_SETCURSEL, nSelected, 0);
}
- m_proto->m_privacyListManager.Unlock();
+
+ lck.unlock();
PostMessage(m_hwnd, WM_JABBER_REFRESH, 0, 0);
}
}
void CJabberDlgPrivacyLists::btnRemoveList_OnClick(CCtrlButton *)
{
- m_proto->m_privacyListManager.Lock();
- {
- CPrivacyList* pList = GetSelectedList(m_hwnd);
- if (pList) {
- TCHAR *szListName = pList->GetListName();
- if ((m_proto->m_privacyListManager.GetActiveListName() && !_tcscmp(szListName, m_proto->m_privacyListManager.GetActiveListName()))
- || (m_proto->m_privacyListManager.GetDefaultListName() && !_tcscmp(szListName, m_proto->m_privacyListManager.GetDefaultListName()))) {
- m_proto->m_privacyListManager.Unlock();
- MessageBox(m_hwnd, TranslateTS(_T("Can't remove active or default list")), TranslateTS(_T("Sorry")), MB_OK | MB_ICONSTOP);
- return;
- }
- pList->SetDeleted();
- pList->SetModified();
- } }
+ mir_cslockfull lck(m_proto->m_privacyListManager.m_cs);
+
+ CPrivacyList *pList = GetSelectedList(m_hwnd);
+ if (pList) {
+ TCHAR *szListName = pList->GetListName();
+ if ((m_proto->m_privacyListManager.GetActiveListName() && !_tcscmp(szListName, m_proto->m_privacyListManager.GetActiveListName())) ||
+ (m_proto->m_privacyListManager.GetDefaultListName() && !_tcscmp(szListName, m_proto->m_privacyListManager.GetDefaultListName())))
+ {
+ lck.unlock();
+ MessageBox(m_hwnd, TranslateTS(_T("Can't remove active or default list")), TranslateTS(_T("Sorry")), MB_OK | MB_ICONSTOP);
+ return;
+ }
+ pList->SetDeleted();
+ pList->SetModified();
+ }
- m_proto->m_privacyListManager.Unlock();
+ lck.unlock();
PostMessage(m_hwnd, WM_JABBER_REFRESH, 0, 0);
}
@@ -1958,13 +1894,13 @@ void CJabberDlgPrivacyLists::btnApply_OnClick(CCtrlButton *)
return;
}
- m_proto->m_privacyListManager.Lock();
{
+ mir_cslock lck(m_proto->m_privacyListManager.m_cs);
if (IsWindowVisible(GetDlgItem(m_hwnd, IDC_CLIST)))
CListBuildList(GetDlgItem(m_hwnd, IDC_CLIST), clc_info.pList);
CPrivacyListModifyUserParam *pUserData = NULL;
- CPrivacyList* pList = m_proto->m_privacyListManager.GetFirstList();
+ CPrivacyList *pList = m_proto->m_privacyListManager.GetFirstList();
while (pList) {
if (pList->IsModified()) {
CPrivacyListRule* pRule = pList->GetFirstRule();
@@ -2023,8 +1959,8 @@ void CJabberDlgPrivacyLists::btnApply_OnClick(CCtrlButton *)
}
pList = pList->GetNext();
} }
- m_proto->m_privacyListManager.Unlock();
- SetStatusText(TranslateT(JABBER_PL_BUSY_MSG));
+
+ SetStatusText( TranslateT(JABBER_PL_BUSY_MSG));
PostMessage(m_hwnd, WM_JABBER_REFRESH, 0, 0);
}
@@ -2051,16 +1987,15 @@ void CJabberDlgPrivacyLists::clcClist_OnOptionsChanged(CCtrlClc::TEventInfo*)
void CJabberDlgPrivacyLists::clcClist_OnClick(CCtrlClc::TEventInfo *evt)
{
- HANDLE hItem;
- DWORD hitFlags;
- int iImage;
+ if (evt->info->iColumn == -1)
+ return;
- if (evt->info->iColumn==-1) return;
- hItem = m_clcClist.HitTest(evt->info->pt.x, evt->info->pt.y, &hitFlags);
- if (hItem == NULL) return;
- if ( !(hitFlags&CLCHT_ONITEMEXTRA)) return;
+ DWORD hitFlags;
+ HANDLE hItem = m_clcClist.HitTest(evt->info->pt.x, evt->info->pt.y, &hitFlags);
+ if (hItem == NULL || !(hitFlags & CLCHT_ONITEMEXTRA))
+ return;
- iImage = m_clcClist.GetExtraImage(hItem, evt->info->iColumn);
+ int iImage = m_clcClist.GetExtraImage(hItem, evt->info->iColumn);
if (iImage != EMPTY_EXTRA_ICON) {
if (iImage == 0)
iImage = evt->info->iColumn * 2 + 2;
@@ -2133,11 +2068,9 @@ void CJabberProto::QueryPrivacyLists(ThreadData *pThreadInfo)
INT_PTR __cdecl CJabberProto::menuSetPrivacyList(WPARAM, LPARAM, LPARAM iList)
{
- m_privacyListManager.Lock();
+ mir_cslockfull lck(m_privacyListManager.m_cs);
CPrivacyList *pList = NULL;
-
- if (iList)
- {
+ if (iList) {
pList = m_privacyListManager.GetFirstList();
for (int i = 1; pList && (i < iList); i++)
pList = pList->GetNext();
@@ -2148,7 +2081,7 @@ INT_PTR __cdecl CJabberProto::menuSetPrivacyList(WPARAM, LPARAM, LPARAM iList)
HXML active = query << XCHILD(_T("active"));
if (pList)
active << XATTR(_T("name"), pList->GetListName());
- m_privacyListManager.Unlock();
+ lck.unlock();
m_ThreadInfo->send(iq);
return 0;
@@ -2182,15 +2115,13 @@ void CJabberProto::BuildPrivacyMenu()
void CJabberProto::BuildPrivacyListsMenu(bool bDeleteOld)
{
- int i;
if (bDeleteOld)
- for (i=0; i < m_hPrivacyMenuItems.getCount(); i++)
+ for (int i=0; i < m_hPrivacyMenuItems.getCount(); i++)
CallService(MO_REMOVEMENUITEM, (WPARAM)m_hPrivacyMenuItems[i], 0);
m_hPrivacyMenuItems.destroy();
- m_privacyListManager.Lock();
+ mir_cslock lck(m_privacyListManager.m_cs);
- i = 0;
char srvFce[MAX_PATH + 64], *svcName = srvFce+strlen(m_szModuleName);
CLISTMENUITEM mi = { sizeof(mi) };
@@ -2199,16 +2130,14 @@ void CJabberProto::BuildPrivacyListsMenu(bool bDeleteOld)
mi.hParentMenu = m_hPrivacyMenuRoot;
mi.pszService = srvFce;
+ int i=0;
mir_snprintf(srvFce, SIZEOF(srvFce), "%s/menuPrivacy%d", m_szModuleName, i);
if (i > m_privacyMenuServiceAllocated) {
CreateProtoServiceParam(svcName, &CJabberProto::menuSetPrivacyList, i);
m_privacyMenuServiceAllocated = i;
}
mi.position++;
- mi.icolibItem = LoadSkinnedIconHandle(
- m_privacyListManager.GetActiveListName() ?
- SKINICON_OTHER_SMALLDOT :
- SKINICON_OTHER_EMPTYBLOB);
+ mi.icolibItem = LoadSkinnedIconHandle(m_privacyListManager.GetActiveListName() ? SKINICON_OTHER_SMALLDOT : SKINICON_OTHER_EMPTYBLOB);
mi.ptszName = LPGENT("<none>");
m_hPrivacyMenuItems.insert(Menu_AddProtoMenuItem(&mi));
@@ -2229,6 +2158,4 @@ void CJabberProto::BuildPrivacyListsMenu(bool bDeleteOld)
mi.ptszName = pList->GetListName();
m_hPrivacyMenuItems.insert(Menu_AddProtoMenuItem(&mi));
}
-
- m_privacyListManager.Unlock();
}
diff --git a/protocols/JabberG/src/jabber_privacy.h b/protocols/JabberG/src/jabber_privacy.h
index 440c400319..6867b8b073 100644
--- a/protocols/JabberG/src/jabber_privacy.h
+++ b/protocols/JabberG/src/jabber_privacy.h
@@ -321,11 +321,11 @@ protected:
TCHAR *m_szActiveListName;
TCHAR *m_szDefaultListName;
CPrivacyList *m_pLists;
- CRITICAL_SECTION m_cs;
BOOL m_bModified;
public:
CJabberProto* m_proto;
+ CRITICAL_SECTION m_cs;
CPrivacyListManager(CJabberProto *ppro)
{
@@ -343,16 +343,6 @@ public:
RemoveAllLists();
DeleteCriticalSection(&m_cs);
};
- BOOL Lock()
- {
- EnterCriticalSection(&m_cs);
- return TRUE;
- }
- BOOL Unlock()
- {
- LeaveCriticalSection(&m_cs);
- return TRUE;
- }
void SetActiveListName(const TCHAR *szListName)
{
replaceStrT(m_szActiveListName, szListName);
diff --git a/protocols/JabberG/src/jabber_search.cpp b/protocols/JabberG/src/jabber_search.cpp
index e024ee28d6..df04e24891 100644
--- a/protocols/JabberG/src/jabber_search.cpp
+++ b/protocols/JabberG/src/jabber_search.cpp
@@ -137,7 +137,7 @@ void CJabberProto::OnIqResultGetSearchFields(HXML iqNode, CJabberIqInfo *pInfo)
return;
LPCTSTR type = xmlGetAttrValue(iqNode, _T("type"));
- if ( !type)
+ if (type == NULL)
return;
if ( !lstrcmp(type, _T("result"))) {
diff --git a/protocols/JabberG/src/jabber_svc.cpp b/protocols/JabberG/src/jabber_svc.cpp
index e8f13708a3..cea9a5b30d 100644
--- a/protocols/JabberG/src/jabber_svc.cpp
+++ b/protocols/JabberG/src/jabber_svc.cpp
@@ -38,7 +38,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
INT_PTR __cdecl CJabberProto::GetMyAwayMsg(WPARAM wParam, LPARAM lParam)
{
TCHAR *szStatus = NULL;
- INT_PTR nRetVal = 0;
mir_cslock lck(m_csModeMsgMutex);
switch (wParam ? (int)wParam : m_iStatus) {
@@ -63,10 +62,10 @@ INT_PTR __cdecl CJabberProto::GetMyAwayMsg(WPARAM wParam, LPARAM lParam)
default: // Should not reach here
break;
}
- if (szStatus)
- nRetVal = (lParam & SGMA_UNICODE) ? (INT_PTR)mir_t2u(szStatus) : (INT_PTR)mir_t2a(szStatus);
- return nRetVal;
+ if (szStatus)
+ return (lParam & SGMA_UNICODE) ? (INT_PTR)mir_t2u(szStatus) : (INT_PTR)mir_t2a(szStatus);
+ return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -75,7 +74,7 @@ INT_PTR __cdecl CJabberProto::GetMyAwayMsg(WPARAM wParam, LPARAM lParam)
INT_PTR __cdecl CJabberProto::JabberGetAvatar(WPARAM wParam, LPARAM lParam)
{
TCHAR *buf = (TCHAR*)wParam;
- int size = (int)lParam;
+ int size = (int)lParam;
if (buf == NULL || size <= 0)
return -1;
@@ -144,29 +143,27 @@ INT_PTR __cdecl CJabberProto::JabberGetAvatarInfo(WPARAM wParam, LPARAM lParam)
}
if ((wParam & GAIF_FORCE) != 0 && AI->hContact != NULL && m_bJabberOnline) {
- DBVARIANT dbv;
- if ( !getTString(AI->hContact, "jid", &dbv)) {
- JABBER_LIST_ITEM *item = ListGetItemPtr(LIST_ROSTER, dbv.ptszVal);
+ ptrT tszJid( getTStringA(AI->hContact, "jid"));
+ if (tszJid != NULL) {
+ JABBER_LIST_ITEM *item = ListGetItemPtr(LIST_ROSTER, tszJid);
if (item != NULL) {
BOOL isXVcard = getByte(AI->hContact, "AvatarXVcard", 0);
- TCHAR szJid[JABBER_MAX_JID_LEN];
- if (item->arResources.getCount() != NULL && !isXVcard) {
- TCHAR *bestResName = ListGetBestClientResourceNamePtr(dbv.ptszVal);
- mir_sntprintf(szJid, SIZEOF(szJid), bestResName?_T("%s/%s"):_T("%s"), dbv.ptszVal, bestResName);
- }
- else lstrcpyn(szJid, dbv.ptszVal, SIZEOF(szJid));
+ TCHAR szJid[JABBER_MAX_JID_LEN]; szJid[0] = 0;
+ if (item->arResources.getCount() != NULL && !isXVcard)
+ if (TCHAR *bestResName = ListGetBestClientResourceNamePtr(tszJid))
+ mir_sntprintf(szJid, SIZEOF(szJid), _T("%s/%s"), tszJid, bestResName);
+
+ if (szJid[0] == 0)
+ _tcsncpy_s(szJid, SIZEOF(szJid), tszJid, _TRUNCATE);
Log("Rereading %s for %S", isXVcard ? JABBER_FEAT_VCARD_TEMP : JABBER_FEAT_AVATAR, szJid);
m_ThreadInfo->send((isXVcard) ?
XmlNodeIq( AddIQ(&CJabberProto::OnIqResultGetVCardAvatar, JABBER_IQ_TYPE_GET, szJid)) << XCHILDNS(_T("vCard"), JABBER_FEAT_VCARD_TEMP) :
XmlNodeIq( AddIQ(&CJabberProto::OnIqResultGetClientAvatar, JABBER_IQ_TYPE_GET, szJid)) << XQUERY(JABBER_FEAT_AVATAR));
-
- db_free(&dbv);
return GAIR_WAITFOR;
}
- db_free(&dbv);
}
}
@@ -180,19 +177,16 @@ INT_PTR __cdecl CJabberProto::JabberGetAvatarInfo(WPARAM wParam, LPARAM lParam)
INT_PTR __cdecl CJabberProto::OnGetEventTextChatStates(WPARAM, LPARAM lParam)
{
DBEVENTGETTEXT *pdbEvent = (DBEVENTGETTEXT *)lParam;
-
- INT_PTR nRetVal = 0;
-
if (pdbEvent->dbei->cbBlob > 0) {
if (pdbEvent->dbei->pBlob[0] == JABBER_DB_EVENT_CHATSTATES_GONE) {
if (pdbEvent->datatype == DBVT_WCHAR)
- nRetVal = (INT_PTR)mir_tstrdup(TranslateTS(_T("closed chat session")));
+ return (INT_PTR)mir_tstrdup(TranslateTS(_T("closed chat session")));
else if (pdbEvent->datatype == DBVT_ASCIIZ)
- nRetVal = (INT_PTR)mir_strdup(Translate("closed chat session"));
+ return (INT_PTR)mir_strdup(Translate("closed chat session"));
}
}
- return nRetVal;
+ return NULL;
}
////////////////////////////////////////////////////////////////////////////////////////
@@ -201,56 +195,53 @@ INT_PTR __cdecl CJabberProto::OnGetEventTextChatStates(WPARAM, LPARAM lParam)
INT_PTR __cdecl CJabberProto::OnGetEventTextPresence(WPARAM, LPARAM lParam)
{
DBEVENTGETTEXT *pdbEvent = (DBEVENTGETTEXT *)lParam;
-
- INT_PTR nRetVal = 0;
-
if (pdbEvent->dbei->cbBlob > 0) {
switch (pdbEvent->dbei->pBlob[0]) {
case JABBER_DB_EVENT_PRESENCE_SUBSCRIBE:
if (pdbEvent->datatype == DBVT_WCHAR)
- nRetVal = (INT_PTR)mir_tstrdup(TranslateTS(_T("sent subscription request")));
+ return (INT_PTR)mir_tstrdup(TranslateTS(_T("sent subscription request")));
else if (pdbEvent->datatype == DBVT_ASCIIZ)
- nRetVal = (INT_PTR)mir_strdup(Translate("sent subscription request"));
+ return (INT_PTR)mir_strdup(Translate("sent subscription request"));
break;
case JABBER_DB_EVENT_PRESENCE_SUBSCRIBED:
if (pdbEvent->datatype == DBVT_WCHAR)
- nRetVal = (INT_PTR)mir_tstrdup(TranslateTS(_T("approved subscription request")));
+ return (INT_PTR)mir_tstrdup(TranslateTS(_T("approved subscription request")));
else if (pdbEvent->datatype == DBVT_ASCIIZ)
- nRetVal = (INT_PTR)mir_strdup(Translate("approved subscription request"));
+ return (INT_PTR)mir_strdup(Translate("approved subscription request"));
break;
case JABBER_DB_EVENT_PRESENCE_UNSUBSCRIBE:
if (pdbEvent->datatype == DBVT_WCHAR)
- nRetVal = (INT_PTR)mir_tstrdup(TranslateTS(_T("declined subscription")));
+ return (INT_PTR)mir_tstrdup(TranslateTS(_T("declined subscription")));
else if (pdbEvent->datatype == DBVT_ASCIIZ)
- nRetVal = (INT_PTR)mir_strdup(Translate("declined subscription"));
+ return (INT_PTR)mir_strdup(Translate("declined subscription"));
break;
case JABBER_DB_EVENT_PRESENCE_UNSUBSCRIBED:
if (pdbEvent->datatype == DBVT_WCHAR)
- nRetVal = (INT_PTR)mir_tstrdup(TranslateTS(_T("declined subscription")));
+ return (INT_PTR)mir_tstrdup(TranslateTS(_T("declined subscription")));
else if (pdbEvent->datatype == DBVT_ASCIIZ)
- nRetVal = (INT_PTR)mir_strdup(Translate("declined subscription"));
+ return (INT_PTR)mir_strdup(Translate("declined subscription"));
break;
case JABBER_DB_EVENT_PRESENCE_ERROR:
if (pdbEvent->datatype == DBVT_WCHAR)
- nRetVal = (INT_PTR)mir_tstrdup(TranslateTS(_T("sent error presence")));
+ return (INT_PTR)mir_tstrdup(TranslateTS(_T("sent error presence")));
else if (pdbEvent->datatype == DBVT_ASCIIZ)
- nRetVal = (INT_PTR)mir_strdup(Translate("sent error presence"));
+ return (INT_PTR)mir_strdup(Translate("sent error presence"));
break;
default:
if (pdbEvent->datatype == DBVT_WCHAR)
- nRetVal = (INT_PTR)mir_tstrdup(TranslateTS(_T("sent unknown presence type")));
+ return (INT_PTR)mir_tstrdup(TranslateTS(_T("sent unknown presence type")));
else if (pdbEvent->datatype == DBVT_ASCIIZ)
- nRetVal = (INT_PTR)mir_strdup(Translate("sent unknown presence type"));
+ return (INT_PTR)mir_strdup(Translate("sent unknown presence type"));
break;
}
}
- return nRetVal;
+ return 0;
}
////////////////////////////////////////////////////////////////////////////////////////
@@ -280,8 +271,8 @@ INT_PTR __cdecl CJabberProto::JabberSetAvatar(WPARAM, LPARAM lParam)
return 1;
}
- long dwPngSize = _filelength(fileIn);
- char* pResult = new char[ dwPngSize ];
+ long dwPngSize = _filelength(fileIn);
+ char *pResult = new char[ dwPngSize ];
if (pResult == NULL) {
_close(fileIn);
mir_free(tszFileName);
@@ -307,7 +298,7 @@ INT_PTR __cdecl CJabberProto::JabberSetAvatar(WPARAM, LPARAM lParam)
m_options.AvatarType = ProtoGetBufferFormat(pResult);
GetAvatarFileName(NULL, tFileName, MAX_PATH);
- FILE* out = _tfopen(tFileName, _T("wb"));
+ FILE *out = _tfopen(tFileName, _T("wb"));
if (out != NULL) {
fwrite(pResult, dwPngSize, 1, out);
fclose(out);
@@ -394,7 +385,7 @@ INT_PTR __cdecl CJabberProto::JabberGCGetToolTipText(WPARAM wParam, LPARAM lPara
if (_tcschr(info->m_tszResourceName, _T('@')) != NULL)
appendString(bIsTipper, _T("JID:"), info->m_tszResourceName, outBuf, SIZEOF(outBuf));
else if (lParam) //or simple nick
- appendString(bIsTipper, _T("Nick:"), (TCHAR*) lParam, outBuf, SIZEOF(outBuf));
+ appendString(bIsTipper, _T("Nick:"), (TCHAR*)lParam, outBuf, SIZEOF(outBuf));
// status
if (info->m_iStatus >= ID_STATUS_OFFLINE && info->m_iStatus <= ID_STATUS_IDLE )
@@ -452,39 +443,35 @@ INT_PTR __cdecl CJabberProto::JabberServiceParseXmppURI(WPARAM wParam, LPARAM lP
if (szSecondParam)
*(szSecondParam++) = 0;
-// TCHAR *szThirdParam = szSecondParam ? _tcschr(szSecondParam, _T(';')) : NULL;
-// if (szThirdParam)
-// *(szThirdParam++) = 0;
-
// no command or message command
if ( !szCommand || (szCommand && !_tcsicmp(szCommand, _T("message")))) {
// message
- if (ServiceExists(MS_MSG_SENDMESSAGE)) {
- HANDLE hContact = HContactFromJID(szJid, TRUE);
- TCHAR *szMsgBody = NULL;
- if ( !hContact)
- hContact = DBCreateContact(szJid, szJid, TRUE, TRUE);
- if ( !hContact)
- return 1;
-
- if (szSecondParam) { //there are parameters to message
- szMsgBody = _tcsstr(szSecondParam, _T("body="));
- if (szMsgBody) {
- szMsgBody += 5;
- TCHAR *szDelim = _tcschr(szMsgBody, _T(';'));
- if (szDelim)
- szDelim = 0;
- JabberHttpUrlDecode(szMsgBody);
- } }
-
- CallService(MS_MSG_SENDMESSAGE "W",(WPARAM)hContact, (LPARAM)szMsgBody);
-
- return 0;
+ if ( !ServiceExists(MS_MSG_SENDMESSAGEW))
+ return 1;
+
+ TCHAR *szMsgBody = NULL;
+ HANDLE hContact = HContactFromJID(szJid, TRUE);
+ if (hContact == NULL)
+ hContact = DBCreateContact(szJid, szJid, TRUE, TRUE);
+ if (hContact == NULL)
+ return 1;
+
+ if (szSecondParam) { //there are parameters to message
+ szMsgBody = _tcsstr(szSecondParam, _T("body="));
+ if (szMsgBody) {
+ szMsgBody += 5;
+ TCHAR *szDelim = _tcschr(szMsgBody, _T(';'));
+ if (szDelim)
+ szDelim = 0;
+ JabberHttpUrlDecode(szMsgBody);
+ }
}
- return 1;
+
+ CallService(MS_MSG_SENDMESSAGEW, (WPARAM)hContact, (LPARAM)szMsgBody);
+ return 0;
}
- else if ( !_tcsicmp(szCommand, _T("roster")))
- {
+
+ if (!_tcsicmp(szCommand, _T("roster"))) {
if ( !HContactFromJID(szJid)) {
JABBER_SEARCH_RESULT jsr = { 0 };
jsr.hdr.cbSize = sizeof(JABBER_SEARCH_RESULT);
@@ -501,47 +488,46 @@ INT_PTR __cdecl CJabberProto::JabberServiceParseXmppURI(WPARAM wParam, LPARAM lP
}
return 0;
}
- else if ( !_tcsicmp(szCommand, _T("join")))
- {
- // chat join invitation
+
+ // chat join invitation
+ if ( !_tcsicmp(szCommand, _T("join"))) {
GroupchatJoinRoomByJid(NULL, szJid);
return 0;
}
- else if ( !_tcsicmp(szCommand, _T("disco")))
- {
- // service discovery request
+
+ // service discovery request
+ if ( !_tcsicmp(szCommand, _T("disco"))) {
OnMenuHandleServiceDiscovery(0, (LPARAM)szJid);
return 0;
}
- else if ( !_tcsicmp(szCommand, _T("command")))
- {
- // ad-hoc commands
+
+ // ad-hoc commands
+ if ( !_tcsicmp(szCommand, _T("command"))) {
if (szSecondParam) {
if ( !_tcsnicmp(szSecondParam, _T("node="), 5)) {
szSecondParam += 5;
if ( !*szSecondParam)
szSecondParam = NULL;
}
- else
- szSecondParam = NULL;
+ else szSecondParam = NULL;
}
CJabberAdhocStartupParams* pStartupParams = new CJabberAdhocStartupParams(this, szJid, szSecondParam);
ContactMenuRunCommands(0, (LPARAM)pStartupParams);
return 0;
}
- else if ( !_tcsicmp(szCommand, _T("sendfile")))
- {
- // send file
- if (ServiceExists(MS_FILE_SENDFILE)) {
- HANDLE hContact = HContactFromJID(szJid, TRUE);
- if ( !hContact)
- hContact = DBCreateContact(szJid, szJid, TRUE, TRUE);
- if ( !hContact)
- return 1;
- CallService(MS_FILE_SENDFILE, (WPARAM)hContact, (LPARAM)NULL);
- return 0;
- }
- return 1;
+
+ // send file
+ if ( !_tcsicmp(szCommand, _T("sendfile"))) {
+ if (!ServiceExists(MS_FILE_SENDFILE))
+ return 1;
+
+ HANDLE hContact = HContactFromJID(szJid, TRUE);
+ if (hContact == NULL)
+ hContact = DBCreateContact(szJid, szJid, TRUE, TRUE);
+ if (hContact == NULL)
+ return 1;
+ CallService(MS_FILE_SENDFILE, (WPARAM)hContact, (LPARAM)NULL);
+ return 0;
}
return 1; /* parse failed */
@@ -606,9 +592,7 @@ BOOL CJabberProto::SendHttpAuthReply(CJabberHttpAuthParams *pParams, BOOL bAutho
m_ThreadInfo->send(msg);
}
- else
- return FALSE;
-
+ else return FALSE;
return TRUE;
}
diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp
index 0aaca01f15..7c826345e5 100644
--- a/protocols/JabberG/src/jabber_thread.cpp
+++ b/protocols/JabberG/src/jabber_thread.cpp
@@ -1168,7 +1168,7 @@ void CJabberProto::OnProcessMessage(HXML node, ThreadData* info)
// If message is from a stranger (not in roster), item is NULL
JABBER_LIST_ITEM *item = ListGetItemPtr(LIST_ROSTER, from);
- if ( !item)
+ if (item == NULL)
item = ListGetItemPtr(LIST_VCARD_TEMP, from);
time_t msgTime = 0;
@@ -1863,7 +1863,6 @@ void CJabberProto::OnProcessIq(HXML node)
if ((type=xmlGetAttrValue(node, _T("type"))) == NULL) return;
int id = JabberGetPacketID(node);
- const TCHAR *idStr = xmlGetAttrValue(node, _T("id"));
queryNode = xmlGetChild(node , "query");
xmlns = xmlGetAttrValue(queryNode, _T("xmlns"));
@@ -1887,7 +1886,7 @@ void CJabberProto::OnProcessIq(HXML node)
LISTFOREACH(i, this, LIST_FILE)
{
JABBER_LIST_ITEM *item = ListGetItemPtrFromIndex(i);
- if (item->ft != NULL && item->ft->state == FT_CONNECTING && !_tcscmp(idStr, item->ft->iqId)) {
+ if (item->ft != NULL && item->ft->state == FT_CONNECTING && id == item->ft->iqId) {
Log("Denying file sending request");
item->ft->state = FT_DENIED;
if (item->ft->hFileEvent != NULL)
@@ -1896,7 +1895,7 @@ void CJabberProto::OnProcessIq(HXML node)
}
}
else if ((!_tcscmp(type, _T("get")) || !_tcscmp(type, _T("set")))) {
- XmlNodeIq iq(_T("error"), idStr, xmlGetAttrValue(node, _T("from")));
+ XmlNodeIq iq(_T("error"), id, xmlGetAttrValue(node, _T("from")));
HXML pFirstChild = xmlGetChild(node , 0);
if (pFirstChild)
diff --git a/protocols/JabberG/src/ui_utils.cpp b/protocols/JabberG/src/ui_utils.cpp
index f4f7dfa7f7..96606221ca 100644
--- a/protocols/JabberG/src/ui_utils.cpp
+++ b/protocols/JabberG/src/ui_utils.cpp
@@ -69,51 +69,48 @@ int CDlgBase::Resizer(UTILRESIZECONTROL*)
INT_PTR CDlgBase::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
{
- switch (msg)
- {
- case WM_INITDIALOG:
+ switch (msg) {
+ case WM_INITDIALOG:
+ m_initialized = false;
+ TranslateDialogDefault(m_hwnd);
{
- m_initialized = false;
- TranslateDialogDefault(m_hwnd);
-
for (CCtrlBase* p = m_first; p != NULL; p = p->m_next)
AddControl(p);
-
- NotifyControls(&CCtrlBase::OnInit);
- OnInitDialog();
-
- m_initialized = true;
- return TRUE;
}
+ NotifyControls(&CCtrlBase::OnInit);
+ OnInitDialog();
- case WM_MEASUREITEM:
+ m_initialized = true;
+ return TRUE;
+
+ case WM_MEASUREITEM:
{
MEASUREITEMSTRUCT *param = (MEASUREITEMSTRUCT *)lParam;
if (param && param->CtlID)
if (CCtrlBase *ctrl = FindControl(param->CtlID))
return ctrl->OnMeasureItem(param);
- return FALSE;
}
+ return FALSE;
- case WM_DRAWITEM:
+ case WM_DRAWITEM:
{
DRAWITEMSTRUCT *param = (DRAWITEMSTRUCT *)lParam;
if (param && param->CtlID)
if (CCtrlBase *ctrl = FindControl(param->CtlID))
return ctrl->OnDrawItem(param);
- return FALSE;
}
+ return FALSE;
- case WM_DELETEITEM:
+ case WM_DELETEITEM:
{
DELETEITEMSTRUCT *param = (DELETEITEMSTRUCT *)lParam;
if (param && param->CtlID)
if (CCtrlBase *ctrl = FindControl(param->CtlID))
return ctrl->OnDeleteItem(param);
- return FALSE;
}
+ return FALSE;
- case WM_COMMAND:
+ case WM_COMMAND:
{
HWND hwndCtrl = (HWND)lParam;
WORD idCtrl = LOWORD(wParam);
@@ -133,20 +130,16 @@ INT_PTR CDlgBase::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
return FALSE;
}
- case WM_NOTIFY:
+ case WM_NOTIFY:
{
int idCtrl = wParam;
NMHDR *pnmh = (NMHDR *)lParam;
-
- if (pnmh->idFrom == 0)
- {
- if (pnmh->code == PSN_APPLY)
- {
+ if (pnmh->idFrom == 0) {
+ if (pnmh->code == PSN_APPLY) {
NotifyControls(&CCtrlBase::OnApply);
OnApply();
}
- else if (pnmh->code == PSN_RESET)
- {
+ else if (pnmh->code == PSN_RESET) {
NotifyControls(&CCtrlBase::OnReset);
OnReset();
}
@@ -157,52 +150,42 @@ INT_PTR CDlgBase::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
return FALSE;
}
- case WM_SIZE:
- {
- if (m_forceResizable || (GetWindowLongPtr(m_hwnd, GWL_STYLE) & WS_SIZEBOX))
- {
- UTILRESIZEDIALOG urd;
- urd.cbSize = sizeof(urd);
- urd.hwndDlg = m_hwnd;
- urd.hInstance = hInst;
- urd.lpTemplate = MAKEINTRESOURCEA(m_idDialog);
- urd.lParam = 0;
- urd.pfnResizer = GlobalDlgResizer;
- CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM)&urd);
- }
- return TRUE;
+ case WM_SIZE:
+ if (m_forceResizable || (GetWindowLongPtr(m_hwnd, GWL_STYLE) & WS_SIZEBOX)) {
+ UTILRESIZEDIALOG urd;
+ urd.cbSize = sizeof(urd);
+ urd.hwndDlg = m_hwnd;
+ urd.hInstance = hInst;
+ urd.lpTemplate = MAKEINTRESOURCEA(m_idDialog);
+ urd.lParam = 0;
+ urd.pfnResizer = GlobalDlgResizer;
+ CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM)&urd);
}
+ return TRUE;
- case WM_CLOSE:
- {
- m_lresult = FALSE;
- OnClose();
- if ( !m_lresult)
- {
- if (m_isModal)
- EndDialog(m_hwnd, 0);
- else
- DestroyWindow(m_hwnd);
- }
- return TRUE;
+ case WM_CLOSE:
+ m_lresult = FALSE;
+ OnClose();
+ if ( !m_lresult) {
+ if (m_isModal)
+ EndDialog(m_hwnd, 0);
+ else
+ DestroyWindow(m_hwnd);
}
+ return TRUE;
- case WM_DESTROY:
- {
- OnDestroy();
- NotifyControls(&CCtrlBase::OnDestroy);
+ case WM_DESTROY:
+ OnDestroy();
+ NotifyControls(&CCtrlBase::OnDestroy);
- SetWindowLongPtr(m_hwnd, GWLP_USERDATA, 0);
- m_hwnd = NULL;
- if (m_isModal)
- {
- m_isModal = false;
- } else
- { // modeless dialogs MUST be allocated with 'new'
- delete this;
- }
- return TRUE;
- }
+ SetWindowLongPtr(m_hwnd, GWLP_USERDATA, 0);
+ m_hwnd = NULL;
+ if (m_isModal)
+ m_isModal = false;
+ else // modeless dialogs MUST be allocated with 'new'
+ delete this;
+
+ return TRUE;
}
return FALSE;
@@ -211,17 +194,15 @@ INT_PTR CDlgBase::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
INT_PTR CALLBACK CDlgBase::GlobalDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
CDlgBase *wnd = NULL;
- if (msg == WM_INITDIALOG)
- {
+ if (msg == WM_INITDIALOG) {
SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
wnd = (CDlgBase *)lParam;
wnd->m_hwnd = hwnd;
- } else
- {
- wnd = (CDlgBase *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
}
+ else wnd = (CDlgBase *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
- if ( !wnd) return FALSE;
+ if (!wnd)
+ return FALSE;
wnd->m_msg.hwnd = hwnd;
wnd->m_msg.message = msg;
@@ -233,9 +214,7 @@ INT_PTR CALLBACK CDlgBase::GlobalDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPA
int CDlgBase::GlobalDlgResizer(HWND hwnd, LPARAM, UTILRESIZECONTROL *urc)
{
CDlgBase *wnd = (CDlgBase *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
- if ( !wnd) return 0;
-
- return wnd->Resizer(urc);
+ return (wnd == NULL) ? 0 : wnd->Resizer(urc);
}
void CDlgBase::ThemeDialogBackground(BOOL tabbed)
@@ -364,11 +343,10 @@ CCtrlListBox::CCtrlListBox(CDlgBase* dlg, int ctrlId) :
BOOL CCtrlListBox::OnCommand(HWND, WORD, WORD idCode)
{
- switch (idCode)
- {
- case LBN_DBLCLK: OnDblClick(this); break;
- case LBN_SELCANCEL: OnSelCancel(this); break;
- case LBN_SELCHANGE: OnSelChange(this); break;
+ switch (idCode) {
+ case LBN_DBLCLK: OnDblClick(this); break;
+ case LBN_SELCANCEL: OnSelCancel(this); break;
+ case LBN_SELCHANGE: OnSelChange(this); break;
}
return TRUE;
}
@@ -609,20 +587,19 @@ CCtrlClc::CCtrlClc(CDlgBase* dlg, int ctrlId):
BOOL CCtrlClc::OnNotify(int, NMHDR *pnmh)
{
TEventInfo evt = { this, (NMCLISTCONTROL *)pnmh };
- switch (pnmh->code)
- {
- case CLN_EXPANDED: OnExpanded(&evt); break;
- case CLN_LISTREBUILT: OnListRebuilt(&evt); break;
- case CLN_ITEMCHECKED: OnItemChecked(&evt); break;
- case CLN_DRAGGING: OnDragging(&evt); break;
- case CLN_DROPPED: OnDropped(&evt); break;
- case CLN_LISTSIZECHANGE: OnListSizeChange(&evt); break;
- case CLN_OPTIONSCHANGED: OnOptionsChanged(&evt); break;
- case CLN_DRAGSTOP: OnDragStop(&evt); break;
- case CLN_NEWCONTACT: OnNewContact(&evt); break;
- case CLN_CONTACTMOVED: OnContactMoved(&evt); break;
- case CLN_CHECKCHANGED: OnCheckChanged(&evt); break;
- case NM_CLICK: OnClick(&evt); break;
+ switch (pnmh->code) {
+ case CLN_EXPANDED: OnExpanded(&evt); break;
+ case CLN_LISTREBUILT: OnListRebuilt(&evt); break;
+ case CLN_ITEMCHECKED: OnItemChecked(&evt); break;
+ case CLN_DRAGGING: OnDragging(&evt); break;
+ case CLN_DROPPED: OnDropped(&evt); break;
+ case CLN_LISTSIZECHANGE: OnListSizeChange(&evt); break;
+ case CLN_OPTIONSCHANGED: OnOptionsChanged(&evt); break;
+ case CLN_DRAGSTOP: OnDragStop(&evt); break;
+ case CLN_NEWCONTACT: OnNewContact(&evt); break;
+ case CLN_CONTACTMOVED: OnContactMoved(&evt); break;
+ case CLN_CHECKCHANGED: OnCheckChanged(&evt); break;
+ case NM_CLICK: OnClick(&evt); break;
}
return FALSE;
}
@@ -865,7 +842,7 @@ HIMAGELIST CCtrlListView::CreateImageList(int iImageList)
void CCtrlListView::AddColumn(int iSubItem, TCHAR *name, int cx)
{
LVCOLUMN lvc;
- lvc.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM;
+ lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
lvc.iImage = 0;
lvc.pszText = name;
lvc.cx = cx;
@@ -877,7 +854,7 @@ void CCtrlListView::AddGroup(int iGroupId, TCHAR *name)
{
LVGROUP lvg = {0};
lvg.cbSize = sizeof(lvg);
- lvg.mask = LVGF_HEADER|LVGF_GROUPID;
+ lvg.mask = LVGF_HEADER | LVGF_GROUPID;
lvg.pszHeader = name;
lvg.cchHeader = lstrlen(lvg.pszHeader);
lvg.iGroupId = iGroupId;
@@ -887,20 +864,16 @@ void CCtrlListView::AddGroup(int iGroupId, TCHAR *name)
int CCtrlListView::AddItem(TCHAR *text, int iIcon, LPARAM lParam, int iGroupId)
{
LVITEM lvi = {0};
- lvi.mask = LVIF_PARAM|LVIF_TEXT|LVIF_IMAGE;
+ lvi.mask = LVIF_PARAM | LVIF_TEXT | LVIF_IMAGE;
lvi.iSubItem = 0;
lvi.pszText = text;
lvi.iImage = iIcon;
lvi.lParam = lParam;
-
-
- if ((iGroupId >= 0))
- {
+ if (iGroupId >= 0) {
lvi.mask |= LVIF_GROUPID;
lvi.iGroupId = iGroupId;
}
-
return InsertItem(&lvi);
}
@@ -911,9 +884,7 @@ void CCtrlListView::SetItem(int iItem, int iSubItem, TCHAR *text, int iIcon)
lvi.iItem = iItem;
lvi.iSubItem = iSubItem;
lvi.pszText = text;
-
- if (iIcon >= 0)
- {
+ if (iIcon >= 0) {
lvi.mask |= LVIF_IMAGE;
lvi.iImage = iIcon;
}
@@ -991,48 +962,12 @@ int CCtrlListView::GetCountPerPage()
HWND CCtrlListView::GetEditControl()
{ return ListView_GetEditControl(m_hwnd);
}
-//void CCtrlListView::GetEmptyText(PWSTR pszText, UINT cchText)
-//{ ListView_GetEmptyText(m_hwnd, pszText, cchText);
-//}
DWORD CCtrlListView::GetExtendedListViewStyle()
{ return ListView_GetExtendedListViewStyle(m_hwnd);
}
-//INT CCtrlListView::GetFocusedGroup()
-//{ return ListView_GetFocusedGroup(m_hwnd);
-//}
-//void CCtrlListView::GetFooterInfo(LPLVFOOTERINFO plvfi)
-//{ ListView_GetFooterInfo(m_hwnd, plvfi);
-//}
-//void CCtrlListView::GetFooterItem(UINT iItem, LVFOOTERITEM *pfi)
-//{ ListView_GetFooterItem(m_hwnd, iItem, pfi);
-//}
-//void CCtrlListView::GetFooterItemRect(UINT iItem, RECT *prc)
-//{ ListView_GetFooterItemRect(m_hwnd, iItem, prc);
-//}
-//void CCtrlListView::GetFooterRect(RECT *prc)
-//{ ListView_GetFooterRect(m_hwnd, prc);
-//}
-//int CCtrlListView::GetGroupCount()
-//{ return ListView_GetGroupCount(m_hwnd);
-//}
-//HIMAGELIST CCtrlListView::GetGroupHeaderImageList()
-//{ return ListView_GetGroupHeaderImageList(m_hwnd);
-//}
-//void CCtrlListView::GetGroupInfo(int iGroupId, PLVGROUP pgrp)
-//{ ListView_GetGroupInfo(m_hwnd, iGroupId, pgrp);
-//}
-//void CCtrlListView::GetGroupInfoByIndex(int iIndex, PLVGROUP pgrp)
-//{ ListView_GetGroupInfoByIndex(m_hwnd, iIndex, pgrp);
-//}
void CCtrlListView::GetGroupMetrics(LVGROUPMETRICS *pGroupMetrics)
{ ListView_GetGroupMetrics(m_hwnd, pGroupMetrics);
}
-//BOOL CCtrlListView::GetGroupRect(int iGroupId, RECT *prc)
-//{ return ListView_GetGroupRect(m_hwnd, iGroupId, prc);
-//}
-//UINT CCtrlListView::GetGroupState(UINT dwGroupId, UINT dwMask)
-//{ return ListView_GetGroupState(m_hwnd, dwGroupId, dwMask);
-//}
HWND CCtrlListView::GetHeader()
{ return ListView_GetHeader(m_hwnd);
}
@@ -1066,9 +1001,6 @@ void CCtrlListView::GetItem(LPLVITEM pitem)
int CCtrlListView::GetItemCount()
{ return ListView_GetItemCount(m_hwnd);
}
-//void CCtrlListView::GetItemIndexRect(LVITEMINDEX *plvii, LONG iSubItem, LONG code, LPRECT prc)
-//{ ListView_GetItemIndexRect(m_hwnd, plvii, iSubItem, code, prc);
-//}
void CCtrlListView::GetItemPosition(int i, POINT *ppt)
{ ListView_GetItemPosition(m_hwnd, i, ppt);
}
@@ -1087,9 +1019,6 @@ void CCtrlListView::GetItemText(int iItem, int iSubItem, LPTSTR pszText, int cch
int CCtrlListView::GetNextItem(int iStart, UINT flags)
{ return ListView_GetNextItem(m_hwnd, iStart, flags);
}
-//BOOL CCtrlListView::GetNextItemIndex(LVITEMINDEX *plvii, LPARAM flags)
-//{ return ListView_GetNextItemIndex(m_hwnd, plvii, flags);
-//}
BOOL CCtrlListView::GetNumberOfWorkAreas(LPUINT lpuWorkAreas)
{ return ListView_GetNumberOfWorkAreas(m_hwnd, lpuWorkAreas);
}
@@ -1150,9 +1079,6 @@ BOOL CCtrlListView::HasGroup(int dwGroupId)
int CCtrlListView::HitTest(LPLVHITTESTINFO pinfo)
{ return ListView_HitTest(m_hwnd, pinfo);
}
-//int CCtrlListView::HitTestEx(LPLVHITTESTINFO pinfo)
-//{ return ListView_HitTestEx(m_hwnd, pinfo);
-//}
int CCtrlListView::InsertColumn(int iCol, const LPLVCOLUMN pcol)
{ return ListView_InsertColumn(m_hwnd, iCol, pcol);
}
@@ -1171,9 +1097,6 @@ BOOL CCtrlListView::InsertMarkHitTest(LPPOINT point, LVINSERTMARK *plvim)
BOOL CCtrlListView::IsGroupViewEnabled()
{ return ListView_IsGroupViewEnabled(m_hwnd);
}
-//UINT CCtrlListView::IsItemVisible(UINT index)
-//{ return ListView_IsItemVisible(m_hwnd, index);
-//}
UINT CCtrlListView::MapIDToIndex(UINT id)
{ return ListView_MapIDToIndex(m_hwnd, id);
}
@@ -1219,18 +1142,12 @@ void CCtrlListView::SetExtendedListViewStyle(DWORD dwExStyle)
void CCtrlListView::SetExtendedListViewStyleEx(DWORD dwExMask, DWORD dwExStyle)
{ ListView_SetExtendedListViewStyleEx(m_hwnd, dwExMask, dwExStyle);
}
-//HIMAGELIST CCtrlListView::SetGroupHeaderImageList(HIMAGELIST himl)
-//{ return ListView_SetGroupHeaderImageList(m_hwnd, himl);
-//}
int CCtrlListView::SetGroupInfo(int iGroupId, PLVGROUP pgrp)
{ return ListView_SetGroupInfo(m_hwnd, iGroupId, pgrp);
}
void CCtrlListView::SetGroupMetrics(PLVGROUPMETRICS pGroupMetrics)
{ ListView_SetGroupMetrics(m_hwnd, pGroupMetrics);
}
-//void CCtrlListView::SetGroupState(UINT dwGroupId, UINT dwMask, UINT dwState)
-//{ ListView_SetGroupState(m_hwnd, dwGroupId, dwMask, dwState);
-//}
HCURSOR CCtrlListView::SetHotCursor(HCURSOR hCursor)
{ return ListView_SetHotCursor(m_hwnd, hCursor);
}
@@ -1264,9 +1181,6 @@ void CCtrlListView::SetItemCount(int cItems)
void CCtrlListView::SetItemCountEx(int cItems, DWORD dwFlags)
{ ListView_SetItemCountEx(m_hwnd, cItems, dwFlags);
}
-//HRESULT CCtrlListView::SetItemIndexState(LVITEMINDEX *plvii, UINT data, UINT mask)
-//{ return ListView_SetItemIndexState(m_hwnd, plvii, data, mask);
-//}
BOOL CCtrlListView::SetItemPosition(int i, int x, int y)
{ return ListView_SetItemPosition(m_hwnd, i, x, y);
}
@@ -1352,7 +1266,6 @@ struct CFilterData : public MZeroedObject
void ReleaseFilterData()
{
- //DeleteObject(m_hfntNormal); m_hfntNormal = NULL; // managed by system
DeleteObject(m_hfntEmpty); m_hfntEmpty = NULL;
}
@@ -1390,57 +1303,45 @@ void CCtrlFilterListView::OnInit()
static LRESULT CALLBACK sttEditBoxSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
CFilterData *fdat = (CFilterData *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
- if ( !fdat) return DefWindowProc(hwnd, msg, wParam, lParam);
-
- switch (msg)
- {
- case WM_GETDLGCODE:
- if ((wParam == VK_RETURN) || (wParam == VK_ESCAPE))
- return DLGC_WANTMESSAGE;
- break;
-
- case WM_SYSKEYDOWN:
- case WM_KEYDOWN:
- {
- if (wParam == VK_RETURN)
- {
- if (fdat->m_filterText) mir_free(fdat->m_filterText);
- int length = GetWindowTextLength(hwnd) + 1;
- if (length == 1)
- {
- fdat->m_filterText = 0;
- } else
- {
- fdat->m_filterText = (TCHAR *)mir_alloc(sizeof(TCHAR) * length);
- GetWindowText(hwnd, fdat->m_filterText, length);
- }
-
- DestroyWindow(hwnd);
- RedrawWindow(fdat->m_hwndOwner, NULL, NULL, RDW_INVALIDATE|RDW_FRAME);
- PostMessage(fdat->m_hwndOwner, WM_APP, 0, 0);
- } else
- if (wParam == VK_ESCAPE)
- {
- DestroyWindow(hwnd);
- return 0;
- } else
- {
- PostMessage(fdat->m_hwndOwner, WM_APP, 1, 0);
+ if (fdat == NULL)
+ return DefWindowProc(hwnd, msg, wParam, lParam);
+
+ switch (msg) {
+ case WM_GETDLGCODE:
+ if ((wParam == VK_RETURN) || (wParam == VK_ESCAPE))
+ return DLGC_WANTMESSAGE;
+ break;
+
+ case WM_SYSKEYDOWN:
+ case WM_KEYDOWN:
+ if (wParam == VK_RETURN) {
+ if (fdat->m_filterText) mir_free(fdat->m_filterText);
+ int length = GetWindowTextLength(hwnd) + 1;
+ if (length == 1)
+ fdat->m_filterText = 0;
+ else {
+ fdat->m_filterText = (TCHAR *)mir_alloc(sizeof(TCHAR) * length);
+ GetWindowText(hwnd, fdat->m_filterText, length);
}
- break;
+ DestroyWindow(hwnd);
+ RedrawWindow(fdat->m_hwndOwner, NULL, NULL, RDW_INVALIDATE|RDW_FRAME);
+ PostMessage(fdat->m_hwndOwner, WM_APP, 0, 0);
}
-
- case WM_KILLFOCUS:
- {
+ else if (wParam == VK_ESCAPE) {
DestroyWindow(hwnd);
return 0;
}
- case WM_DESTROY:
- {
- fdat->m_hwndEditBox = NULL;
- }
+ PostMessage(fdat->m_hwndOwner, WM_APP, 1, 0);
+ break;
+
+ case WM_KILLFOCUS:
+ DestroyWindow(hwnd);
+ return 0;
+
+ case WM_DESTROY:
+ fdat->m_hwndEditBox = NULL;
}
return CallWindowProc(fdat->m_oldWndProc, hwnd, msg, wParam, lParam);
@@ -1450,20 +1351,15 @@ void CCtrlFilterListView::FilterHighlight(TCHAR *str)
{
TCHAR buf[256];
int count = GetItemCount();
- for (int i=0; i < count; i++)
- {
+ for (int i=0; i < count; i++) {
bool found = false;
-
- if (str)
- {
- for (int j = 0; j < 10; ++j)
- {
+ if (str) {
+ for (int j = 0; j < 10; ++j) {
GetItemText(i, j, buf, SIZEOF(buf));
if ( !*buf)
break;
- if (_tcsstr(buf, str))
- {
+ if (_tcsstr(buf, str)) {
found = true;
break;
}
@@ -1476,67 +1372,56 @@ void CCtrlFilterListView::FilterHighlight(TCHAR *str)
LRESULT CCtrlFilterListView::CustomWndProc(UINT msg, WPARAM wParam, LPARAM lParam)
{
- switch (msg)
- {
- case WM_APP:
- {
- switch (wParam)
- {
- case 0:
- {
- OnFilterChanged(this);
- if ( !m_keepHiglight) FilterHighlight(NULL);
- break;
- }
+ POINT pt;
- case 1:
- {
- if (m_trackFilter && fdat->m_hwndEditBox)
- {
- TCHAR *str = 0;
- int length = GetWindowTextLength(fdat->m_hwndEditBox) + 1;
- if (length == 1)
- {
- str = 0;
- } else
- {
- str = (TCHAR *)mir_alloc(sizeof(TCHAR) * length);
- GetWindowText(fdat->m_hwndEditBox, str, length);
- }
- FilterHighlight(str);
- if (str) mir_free(str);
- }
- break;
+ switch (msg) {
+ case WM_APP:
+ switch (wParam) {
+ case 0:
+ OnFilterChanged(this);
+ if (!m_keepHiglight)
+ FilterHighlight(NULL);
+ break;
+
+ case 1:
+ if (m_trackFilter && fdat->m_hwndEditBox) {
+ TCHAR *str = 0;
+ int length = GetWindowTextLength(fdat->m_hwndEditBox) + 1;
+ if (length == 1)
+ str = 0;
+ else {
+ str = (TCHAR *)mir_alloc(sizeof(TCHAR) * length);
+ GetWindowText(fdat->m_hwndEditBox, str, length);
}
+ FilterHighlight(str);
+ if (str) mir_free(str);
+ }
+ break;
- case 2:
- {
- fdat->m_hwndOwner = m_hwnd;
- fdat->m_hwndEditBox = CreateWindow(_T("edit"), fdat->m_filterText,
- WS_CHILD|WS_VISIBLE|WS_TABSTOP|ES_LEFT|ES_AUTOHSCROLL,
- 0, 0, 0, 0,
- ::GetParent(m_hwnd), (HMENU)-1, hInst, NULL);
+ case 2:
+ fdat->m_hwndOwner = m_hwnd;
+ fdat->m_hwndEditBox = CreateWindow(_T("edit"), fdat->m_filterText,
+ WS_CHILD|WS_VISIBLE|WS_TABSTOP|ES_LEFT|ES_AUTOHSCROLL,
+ 0, 0, 0, 0,
+ ::GetParent(m_hwnd), (HMENU)-1, hInst, NULL);
- SendMessage(fdat->m_hwndEditBox, WM_SETFONT, (WPARAM)fdat->m_hfntNormal, 0);
+ SendMessage(fdat->m_hwndEditBox, WM_SETFONT, (WPARAM)fdat->m_hfntNormal, 0);
- RECT rc = fdat->m_rcEditBox;
- MapWindowPoints(m_hwnd, ::GetParent(m_hwnd), (LPPOINT)&rc, 2);
- SetWindowPos(fdat->m_hwndEditBox, HWND_TOP, rc.left-5, rc.top+2, rc.right-rc.left, rc.bottom-rc.top-4, SWP_SHOWWINDOW);
- SendMessage(fdat->m_hwndEditBox, EM_SETSEL, 0, -1);
+ RECT rc = fdat->m_rcEditBox;
+ MapWindowPoints(m_hwnd, ::GetParent(m_hwnd), (LPPOINT)&rc, 2);
+ SetWindowPos(fdat->m_hwndEditBox, HWND_TOP, rc.left-5, rc.top+2, rc.right-rc.left, rc.bottom-rc.top-4, SWP_SHOWWINDOW);
+ SendMessage(fdat->m_hwndEditBox, EM_SETSEL, 0, -1);
- fdat->m_oldWndProc = (WNDPROC)GetWindowLongPtr(fdat->m_hwndEditBox, GWLP_WNDPROC);
- SetWindowLongPtr(fdat->m_hwndEditBox, GWLP_USERDATA, (LONG_PTR)fdat);
- SetWindowLongPtr(fdat->m_hwndEditBox, GWLP_WNDPROC, (LONG_PTR)sttEditBoxSubclassProc);
+ fdat->m_oldWndProc = (WNDPROC)GetWindowLongPtr(fdat->m_hwndEditBox, GWLP_WNDPROC);
+ SetWindowLongPtr(fdat->m_hwndEditBox, GWLP_USERDATA, (LONG_PTR)fdat);
+ SetWindowLongPtr(fdat->m_hwndEditBox, GWLP_WNDPROC, (LONG_PTR)sttEditBoxSubclassProc);
- SetFocus(m_hwnd); // hack to avoid popping of list over the box...
- SetFocus(fdat->m_hwndEditBox);
- break;
- }
- }
- break;
+ SetFocus(m_hwnd); // hack to avoid popping of list over the box...
+ SetFocus(fdat->m_hwndEditBox);
}
+ break;
- case WM_NCCALCSIZE:
+ case WM_NCCALCSIZE:
{
RECT *prect = (RECT *)lParam;
@@ -1546,7 +1431,8 @@ LRESULT CCtrlFilterListView::CustomWndProc(UINT msg, WPARAM wParam, LPARAM lPara
fdat->ReleaseFilterData();
fdat->m_hfntNormal = (HFONT)SendMessage(m_hwnd, WM_GETFONT, 0, 0);
- if (!fdat->m_hfntNormal) fdat->m_hfntNormal = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
+ if (!fdat->m_hfntNormal)
+ fdat->m_hfntNormal = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
LOGFONT lf;
GetObject(fdat->m_hfntNormal, sizeof(lf), &lf);
@@ -1558,50 +1444,16 @@ LRESULT CCtrlFilterListView::CustomWndProc(UINT msg, WPARAM wParam, LPARAM lPara
fdat->m_clGray = RGB(
(GetRValue(clBack) + 2*GetRValue(clText)) / 3,
(GetGValue(clBack) + 2*GetGValue(clText)) / 3,
- (GetBValue(clBack) + 2*GetBValue(clText)) / 3
- );
+ (GetBValue(clBack) + 2*GetBValue(clText)) / 3);
- if (fdat->m_hwndEditBox) DestroyWindow(fdat->m_hwndEditBox);
-
- return 0;
+ if (fdat->m_hwndEditBox)
+ DestroyWindow(fdat->m_hwndEditBox);
}
+ return 0;
- case WM_NCPAINT:
+ case WM_NCPAINT:
+ CSuper::CustomWndProc(msg, wParam, lParam);
{
-/*
- {
- HRGN hrgnUpdate, hrgnTmp;
- RECT rc;
- GetWindowRect(m_hwnd, &rc);
- OffsetRect(&rc, -rc.left, -rc.top);
-
- RECT rcClient;
- GetClientRect(m_hwnd, &rcClient);
-
- hrgnTmp = CreateRectRgn(rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
- if (wParam == 1)
- {
- hrgnUpdate = CreateRectRgn(rc.left, rc.top, rc.right, rc.bottom);
- CombineRgn(hrgnUpdate, hrgnUpdate, hrgnTmp, RGN_DIFF);
- } else
- {
- hrgnUpdate = CreateRectRgn(0, 0, 0, 0);
- CombineRgn(hrgnUpdate, (HRGN)wParam, hrgnTmp, RGN_DIFF);
- }
- DeleteObject(hrgnTmp);
-
- InflateRect(&rc, -1, -1);
- rc.top = rc.bottom - FILTER_BOX_HEIGHT;
- hrgnTmp = CreateRectRgn(rc.left, rc.top, rc.right, rc.bottom);
- CombineRgn(hrgnUpdate, hrgnUpdate, hrgnTmp, RGN_DIFF);
- DeleteObject(hrgnTmp);
-
- CSuper::CustomWndProc(msg, (WPARAM)hrgnUpdate, lParam);
- DeleteObject(hrgnUpdate);
- }
-*/
- CSuper::CustomWndProc(msg, wParam, lParam);
-
RECT rc;
GetWindowRect(m_hwnd, &rc);
OffsetRect(&rc, -rc.left, -rc.top);
@@ -1624,8 +1476,7 @@ LRESULT CCtrlFilterListView::CustomWndProc(UINT msg, WPARAM wParam, LPARAM lPara
SetBkMode(hdc, TRANSPARENT);
- if (fdat->m_filterText)
- {
+ if (fdat->m_filterText) {
SetRect(&fdat->m_rcButtonClear,
rc.right - FILTER_BOX_HEIGHT + (FILTER_BOX_HEIGHT-16)/2, rc.top + (FILTER_BOX_HEIGHT-16)/2,
rc.right - FILTER_BOX_HEIGHT + (FILTER_BOX_HEIGHT-16)/2 + 16, rc.top + (FILTER_BOX_HEIGHT-16)/2 + 16);
@@ -1641,8 +1492,8 @@ LRESULT CCtrlFilterListView::CustomWndProc(UINT msg, WPARAM wParam, LPARAM lPara
SelectObject(hdc, fdat->m_hfntNormal);
::SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
DrawText(hdc, fdat->m_filterText, -1, &rc, DT_SINGLELINE|DT_VCENTER|DT_NOPREFIX|DT_END_ELLIPSIS);
- } else
- {
+ }
+ else {
SetRect(&fdat->m_rcButtonClear, 0, 0, 0, 0);
DrawIconEx(hdc, rc.left + (FILTER_BOX_HEIGHT-16)/2, rc.top + (FILTER_BOX_HEIGHT-16)/2, g_LoadIconEx("sd_filter_reset"), 16, 16, 0, NULL, DI_NORMAL);
@@ -1660,59 +1511,46 @@ LRESULT CCtrlFilterListView::CustomWndProc(UINT msg, WPARAM wParam, LPARAM lPara
ReleaseDC(m_hwnd, hdc);
DeleteObject(hrgnFilter);
-
- return 0;
}
-
- case WM_NCHITTEST:
- {
- POINT pt;
- pt.x = LOWORD(lParam);
- pt.y = HIWORD(lParam);
- MapWindowPoints(NULL, m_hwnd, &pt, 1);
-
- if (PtInRect(&fdat->m_rcButtonClear, pt))
- return HTBORDER;
- if (PtInRect(&fdat->m_rcEditBox, pt))
- return HTBORDER;
-
- break;
- }
-
- case WM_NCLBUTTONUP:
- {
- POINT pt;
- pt.x = LOWORD(lParam);
- pt.y = HIWORD(lParam);
- MapWindowPoints(NULL, m_hwnd, &pt, 1);
-
- if (PtInRect(&fdat->m_rcButtonClear, pt))
- {
- SetFocus(m_hwnd);
- if (fdat->m_filterText) mir_free(fdat->m_filterText);
- fdat->m_filterText = NULL;
- RedrawWindow(m_hwnd, NULL, NULL, RDW_INVALIDATE|RDW_FRAME);
- OnFilterChanged(this);
- FilterHighlight(NULL);
- } else
- if (PtInRect(&fdat->m_rcEditBox, pt))
- {
- PostMessage(m_hwnd, WM_APP, 2, 0);
- }
-
- break;
- }
-
- case WM_KEYDOWN:
- {
- if (wParam == 'F' && GetAsyncKeyState(VK_CONTROL))
- PostMessage(m_hwnd, WM_APP, 2, 0);
- break;
+ return 0;
+
+ case WM_NCHITTEST:
+ pt.x = LOWORD(lParam);
+ pt.y = HIWORD(lParam);
+ MapWindowPoints(NULL, m_hwnd, &pt, 1);
+
+ if (PtInRect(&fdat->m_rcButtonClear, pt))
+ return HTBORDER;
+ if (PtInRect(&fdat->m_rcEditBox, pt))
+ return HTBORDER;
+ break;
+
+ case WM_NCLBUTTONUP:
+ pt.x = LOWORD(lParam);
+ pt.y = HIWORD(lParam);
+ MapWindowPoints(NULL, m_hwnd, &pt, 1);
+
+ if (PtInRect(&fdat->m_rcButtonClear, pt)) {
+ SetFocus(m_hwnd);
+ if (fdat->m_filterText) mir_free(fdat->m_filterText);
+ fdat->m_filterText = NULL;
+ RedrawWindow(m_hwnd, NULL, NULL, RDW_INVALIDATE|RDW_FRAME);
+ OnFilterChanged(this);
+ FilterHighlight(NULL);
}
+ else if (PtInRect(&fdat->m_rcEditBox, pt))
+ PostMessage(m_hwnd, WM_APP, 2, 0);
+ break;
+
+ case WM_KEYDOWN:
+ if (wParam == 'F' && GetAsyncKeyState(VK_CONTROL))
+ PostMessage(m_hwnd, WM_APP, 2, 0);
+ break;
}
return CSuper::CustomWndProc(msg, wParam, lParam);
}
+
/////////////////////////////////////////////////////////////////////////////////////////
// CCtrlTreeView
@@ -1725,8 +1563,7 @@ BOOL CCtrlTreeView::OnNotify(int, NMHDR *pnmh)
{
TEventInfo evt = { this, pnmh };
- switch (pnmh->code)
- {
+ switch (pnmh->code) {
case TVN_BEGINDRAG: OnBeginDrag(&evt); return TRUE;
case TVN_BEGINLABELEDIT: OnBeginLabelEdit(&evt); return TRUE;
case TVN_BEGINRDRAG: OnBeginRDrag(&evt); return TRUE;
@@ -1748,9 +1585,8 @@ BOOL CCtrlTreeView::OnNotify(int, NMHDR *pnmh)
void CCtrlTreeView::TranslateItem(HTREEITEM hItem)
{
- TCHAR buf[128];
TVITEMEX tvi;
-
+ TCHAR buf[128];
GetItem(hItem, &tvi, buf, SIZEOF(buf));
tvi.pszText = TranslateTS(tvi.pszText);
tvi.cchTextMax = lstrlen(tvi.pszText);
@@ -1760,8 +1596,7 @@ void CCtrlTreeView::TranslateItem(HTREEITEM hItem)
void CCtrlTreeView::TranslateTree()
{
HTREEITEM hItem = GetRoot();
- while (hItem)
- {
+ while (hItem) {
TranslateItem(hItem);
HTREEITEM hItemTmp = 0;
@@ -1769,13 +1604,11 @@ void CCtrlTreeView::TranslateTree()
hItem = hItemTmp;
else if (hItemTmp = GetNextSibling(hItem))
hItem = hItemTmp;
- else
- {
- while (1)
- {
- if ( !(hItem = GetParent(hItem))) break;
- if (hItemTmp = GetNextSibling(hItem))
- {
+ else {
+ while (true) {
+ if ( !(hItem = GetParent(hItem)))
+ break;
+ if (hItemTmp = GetNextSibling(hItem)) {
hItem = hItemTmp;
break;
}
@@ -1801,8 +1634,7 @@ HTREEITEM CCtrlTreeView::FindNamedItem(HTREEITEM hItem, const TCHAR *name)
tvi.pszText = str;
tvi.cchTextMax = SIZEOF(str);
- while (tvi.hItem)
- {
+ while (tvi.hItem) {
GetItem(&tvi);
if ( !lstrcmp(tvi.pszText, name))
@@ -2090,9 +1922,7 @@ void CCtrlPages::OnInit()
LRESULT CCtrlPages::CustomWndProc(UINT msg, WPARAM wParam, LPARAM lParam)
{
if (msg == WM_SIZE)
- {
ShowPage(m_pActivePage);
- }
return CSuper::CustomWndProc(msg, wParam, lParam);
}
@@ -2132,16 +1962,14 @@ void CCtrlPages::AttachDialog(int iPage, CDlgBase *pDlg)
tci.mask = TCIF_PARAM;
TabCtrl_GetItem(m_hwnd, iPage, &tci);
- if (TPageInfo *info = (TPageInfo *)tci.lParam)
- {
+ if (TPageInfo *info = (TPageInfo *)tci.lParam) {
if (info->m_pDlg)
info->m_pDlg->Close();
info->m_pDlg = pDlg;
//SetParent(info->m_pDlg->GetHwnd(), m_hwnd);
- if (iPage == TabCtrl_GetCurSel(m_hwnd))
- {
+ if (iPage == TabCtrl_GetCurSel(m_hwnd)) {
m_pActivePage = info->m_pDlg;
ShowPage(info->m_pDlg);
}
@@ -2167,48 +1995,41 @@ void CCtrlPages::ActivatePage(int iPage)
BOOL CCtrlPages::OnNotify(int /*idCtrl*/, NMHDR *pnmh)
{
- switch (pnmh->code)
- {
+ switch (pnmh->code) {
case TCN_SELCHANGING:
- {
- TCITEM tci = {0};
- tci.mask = TCIF_PARAM;
- TabCtrl_GetItem(m_hwnd, TabCtrl_GetCurSel(m_hwnd), &tci);
-
- if (TPageInfo *info = (TPageInfo *)tci.lParam)
{
- if (info->m_pDlg)
- {
- m_pActivePage = NULL;
- ShowWindow(info->m_pDlg->GetHwnd(), SW_HIDE);
+ TCITEM tci = {0};
+ tci.mask = TCIF_PARAM;
+ TabCtrl_GetItem(m_hwnd, TabCtrl_GetCurSel(m_hwnd), &tci);
+
+ if (TPageInfo *info = (TPageInfo *)tci.lParam) {
+ if (info->m_pDlg) {
+ m_pActivePage = NULL;
+ ShowWindow(info->m_pDlg->GetHwnd(), SW_HIDE);
+ }
}
}
-
return TRUE;
- }
case TCN_SELCHANGE:
- {
- TCITEM tci = {0};
- tci.mask = TCIF_PARAM;
- TabCtrl_GetItem(m_hwnd, TabCtrl_GetCurSel(m_hwnd), &tci);
-
- if (TPageInfo *info = (TPageInfo *)tci.lParam)
{
- if (info->m_pDlg)
- {
- m_pActivePage = info->m_pDlg;
- ShowPage(info->m_pDlg);
- } else
- {
- m_pActivePage = NULL;
- info->m_onCreate(info->m_param);
+ TCITEM tci = {0};
+ tci.mask = TCIF_PARAM;
+ TabCtrl_GetItem(m_hwnd, TabCtrl_GetCurSel(m_hwnd), &tci);
+
+ if (TPageInfo *info = (TPageInfo *)tci.lParam) {
+ if (info->m_pDlg) {
+ m_pActivePage = info->m_pDlg;
+ ShowPage(info->m_pDlg);
+ }
+ else {
+ m_pActivePage = NULL;
+ info->m_onCreate(info->m_param);
+ }
}
}
-
return TRUE;
}
- }
return FALSE;
}
@@ -2216,14 +2037,12 @@ BOOL CCtrlPages::OnNotify(int /*idCtrl*/, NMHDR *pnmh)
void CCtrlPages::OnDestroy()
{
int count = TabCtrl_GetItemCount(m_hwnd);
- for (int i=0; i < count ; i++)
- {
+ for (int i=0; i < count; i++) {
TCITEM tci = {0};
tci.mask = TCIF_PARAM;
TabCtrl_GetItem(m_hwnd, i, &tci);
- if (TPageInfo *info = (TPageInfo *)tci.lParam)
- {
+ if (TPageInfo *info = (TPageInfo *)tci.lParam) {
if (info->m_pDlg)
info->m_pDlg->Close();
@@ -2233,8 +2052,7 @@ void CCtrlPages::OnDestroy()
TabCtrl_DeleteAllItems(m_hwnd);
- if (m_hIml)
- {
+ if (m_hIml) {
TabCtrl_SetImageList(m_hwnd, NULL);
ImageList_Destroy(m_hIml);
}
@@ -2349,8 +2167,7 @@ void CCtrlBase::Subclass()
void CCtrlBase::Unsubclass()
{
- if (m_wndproc)
- {
+ if (m_wndproc) {
SetWindowLongPtr(m_hwnd, GWLP_WNDPROC, (LONG_PTR)m_wndproc);
SetWindowLongPtr(m_hwnd, GWLP_USERDATA, (LONG_PTR)0);
m_wndproc = 0;
@@ -2417,8 +2234,7 @@ void CDbLink::SaveInt(DWORD value)
TCHAR* CDbLink::LoadText()
{
if (dbv.type != DBVT_DELETED) db_free(&dbv);
- if ( !db_get_ts(NULL, m_szModule, m_szSetting, &dbv))
- {
+ if (!db_get_ts(NULL, m_szModule, m_szSetting, &dbv)) {
if (dbv.type == DBVT_TCHAR)
return dbv.ptszVal;
return m_szDefault;
@@ -2436,7 +2252,7 @@ void CDbLink::SaveText(TCHAR *value)
/////////////////////////////////////////////////////////////////////////////////////////
// Base protocol dialog
-void CProtoIntDlgBase::SetStatusText(TCHAR *statusText)
+void CProtoIntDlgBase::SetStatusText(const TCHAR *statusText)
{
if (m_hwndStatus)
SendMessage(m_hwndStatus, SB_SETTEXT, 0, (LPARAM)statusText);
@@ -2444,81 +2260,76 @@ void CProtoIntDlgBase::SetStatusText(TCHAR *statusText)
INT_PTR CProtoIntDlgBase::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
{
- switch (msg)
- {
- case WM_INITDIALOG:
- { // call inherited init code first
- INT_PTR result = CSuper::DlgProc(msg, wParam, lParam);
- if (m_show_label)
- {
- m_hwndStatus = CreateStatusWindow(WS_CHILD|WS_VISIBLE, NULL, m_hwnd, IDC_STATUSBAR);
- SetWindowPos(m_hwndStatus, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
- UpdateStatusBar();
- UpdateProtoTitle();
- }
- return result;
- }
-
- case WM_SETTEXT:
- if (m_show_label && IsWindowUnicode(m_hwnd))
-
- {
- TCHAR *szTitle = (TCHAR *)lParam;
- if ( !_tcsstr(szTitle, m_proto_interface->m_tszUserName))
- {
- UpdateProtoTitle(szTitle);
- return TRUE;
- }
- }
- break;
+ INT_PTR result;
- case WM_SIZE:
- if (m_hwndStatus)
- {
- RECT rcStatus; GetWindowRect(m_hwndStatus, &rcStatus);
- RECT rcClient; GetClientRect(m_hwnd, &rcClient);
- SetWindowPos(m_hwndStatus, NULL, 0, rcClient.bottom-(rcStatus.bottom-rcStatus.top), rcClient.right, (rcStatus.bottom-rcStatus.top), SWP_NOZORDER);
- UpdateStatusBar();
+ switch (msg) {
+ case WM_INITDIALOG: // call inherited init code first
+ result = CSuper::DlgProc(msg, wParam, lParam);
+ if (m_show_label) {
+ m_hwndStatus = CreateStatusWindow(WS_CHILD | WS_VISIBLE, NULL, m_hwnd, IDC_STATUSBAR);
+ SetWindowPos(m_hwndStatus, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
+ UpdateStatusBar();
+ UpdateProtoTitle();
+ }
+ return result;
+
+ case WM_SETTEXT:
+ if (m_show_label && IsWindowUnicode(m_hwnd)) {
+ TCHAR *szTitle = (TCHAR *)lParam;
+ if ( !_tcsstr(szTitle, m_proto_interface->m_tszUserName)) {
+ UpdateProtoTitle(szTitle);
+ return TRUE;
}
- break;
-
- // Protocol events
- case WM_PROTO_ACTIVATE:
- OnProtoActivate(wParam, lParam);
- return m_lresult;
- case WM_PROTO_CHECK_ONLINE:
- if (m_hwndStatus)
- UpdateStatusBar();
- OnProtoCheckOnline(wParam, lParam);
- return m_lresult;
- case WM_PROTO_REFRESH:
- OnProtoRefresh(wParam, lParam);
- return m_lresult;
+ }
+ break;
+
+ case WM_SIZE:
+ if (m_hwndStatus) {
+ RECT rcStatus; GetWindowRect(m_hwndStatus, &rcStatus);
+ RECT rcClient; GetClientRect(m_hwnd, &rcClient);
+ SetWindowPos(m_hwndStatus, NULL, 0, rcClient.bottom-(rcStatus.bottom-rcStatus.top), rcClient.right, (rcStatus.bottom-rcStatus.top), SWP_NOZORDER);
+ UpdateStatusBar();
+ }
+ break;
+
+ // Protocol events
+ case WM_PROTO_ACTIVATE:
+ OnProtoActivate(wParam, lParam);
+ return m_lresult;
+
+ case WM_PROTO_CHECK_ONLINE:
+ if (m_hwndStatus)
+ UpdateStatusBar();
+ OnProtoCheckOnline(wParam, lParam);
+ return m_lresult;
+
+ case WM_PROTO_REFRESH:
+ OnProtoRefresh(wParam, lParam);
+ return m_lresult;
}
return CSuper::DlgProc(msg, wParam, lParam);
}
-void CProtoIntDlgBase::UpdateProtoTitle(TCHAR *szText)
+void CProtoIntDlgBase::UpdateProtoTitle(const TCHAR *szText)
{
if ( !m_show_label) return;
int curLength;
- TCHAR *curText;
+ const TCHAR *curText;
- if (szText)
- {
+ if (szText) {
curText = szText;
curLength = lstrlen(curText);
- } else
- {
+ }
+ else {
curLength = GetWindowTextLength(m_hwnd) + 1;
- curText = (TCHAR *)_alloca(curLength * sizeof(TCHAR));
- GetWindowText(m_hwnd, curText, curLength);
+ TCHAR *tmp = (TCHAR *)_alloca(curLength * sizeof(TCHAR));
+ GetWindowText(m_hwnd, tmp, curLength);
+ curText = tmp;
}
- if ( !_tcsstr(curText, m_proto_interface->m_tszUserName))
- {
+ if ( !_tcsstr(curText, m_proto_interface->m_tszUserName)) {
int length = curLength + lstrlen(m_proto_interface->m_tszUserName) + 256;
TCHAR *text = (TCHAR *)_alloca(length * sizeof(TCHAR));
mir_sntprintf(text, length, _T("%s [%s: %s]"), curText, TranslateT("Account"), m_proto_interface->m_tszUserName);
diff --git a/protocols/JabberG/src/ui_utils.h b/protocols/JabberG/src/ui_utils.h
index 49d7daadfd..bae324ee0f 100644
--- a/protocols/JabberG/src/ui_utils.h
+++ b/protocols/JabberG/src/ui_utils.h
@@ -1240,7 +1240,7 @@ public:
__inline PROTO_INTERFACE *GetProtoInterface() { return m_proto_interface; }
- void SetStatusText(TCHAR *statusText);
+ void SetStatusText(const TCHAR *statusText);
protected:
PROTO_INTERFACE *m_proto_interface;
@@ -1254,7 +1254,7 @@ protected:
virtual void OnProtoCheckOnline(WPARAM, LPARAM) {}
private:
- void UpdateProtoTitle(TCHAR *szText = NULL);
+ void UpdateProtoTitle(const TCHAR *szText = NULL);
void UpdateStatusBar();
};