diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mir_app/src/clc.h | 6 | ||||
-rw-r--r-- | src/mir_app/src/clistgroups.cpp | 41 | ||||
-rw-r--r-- | src/mir_app/src/ignore.cpp | 68 |
3 files changed, 81 insertions, 34 deletions
diff --git a/src/mir_app/src/clc.h b/src/mir_app/src/clc.h index 1639d14692..cace9520c9 100644 --- a/src/mir_app/src/clc.h +++ b/src/mir_app/src/clc.h @@ -177,7 +177,8 @@ struct CGroupInternal CGroupInternal(int _id, const wchar_t *_name, int _flags);
~CGroupInternal();
- int groupId, flags, oldId;
+ int groupId, flags, oldId = -1;
+ uint32_t ignore = 0;
bool bSaveExpanded;
wchar_t *groupName;
@@ -186,3 +187,6 @@ struct CGroupInternal };
void Clist_RebuildGroups(HWND hwnd, ClcData *dat);
+void Clist_GroupSetIgnore(MGROUP hGroup, uint32_t mask);
+
+CGroupInternal* FindGroup(const wchar_t *ptszGroupName);
diff --git a/src/mir_app/src/clistgroups.cpp b/src/mir_app/src/clistgroups.cpp index e6547cd2f1..3deced7d3a 100644 --- a/src/mir_app/src/clistgroups.cpp +++ b/src/mir_app/src/clistgroups.cpp @@ -77,7 +77,7 @@ void CGroupInternal::save() Clist_BroadcastAsync(INTM_GROUPSCHANGED, 0, LPARAM(this));
JSONNode grp;
- grp << WCHAR_PARAM("name", groupName) << INT_PARAM("flags", flags);
+ grp << WCHAR_PARAM("name", groupName) << INT_PARAM("flags", flags) << INT_PARAM("ignore", ignore);
char szSetting[40];
itoa(groupId, szSetting, 10);
@@ -86,21 +86,26 @@ void CGroupInternal::save() /////////////////////////////////////////////////////////////////////////////////////////
-static int GroupNameExists(const wchar_t *ptszGroupName, int skipGroup)
+CGroupInternal* FindGroup(const wchar_t *ptszGroupName)
{
if (ptszGroupName == nullptr)
return 0;
- CGroupInternal *tmp = (CGroupInternal*)_alloca(sizeof(CGroupInternal));
- tmp->groupName = (wchar_t*)ptszGroupName;
- if (tmp = arByName.find(tmp))
- return (skipGroup == tmp->groupId) ? 0 : tmp->groupId + 1;
+ CGroupInternal *tmp = (CGroupInternal *)_alloca(sizeof(CGroupInternal));
+ tmp->groupName = (wchar_t *)ptszGroupName;
+ return arByName.find(tmp);
+}
+
+static int GroupNameExists(const wchar_t *ptszGroupName)
+{
+ if (auto *tmp = FindGroup(ptszGroupName))
+ return tmp->groupId + 1;
return 0;
}
MIR_APP_DLL(MGROUP) Clist_GroupExists(LPCTSTR ptszGroupName)
{
- return GroupNameExists(ptszGroupName, -1);
+ return GroupNameExists(ptszGroupName);
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -143,12 +148,12 @@ static INT_PTR CreateGroupInternal(MGROUP hParent, const wchar_t *ptszName) mir_wstrncpy(newName, newBaseName, _countof(newName) - 1);
if (ptszName) {
- int id = GroupNameExists(newBaseName, -1);
+ int id = GroupNameExists(newBaseName);
if (id)
return id;
}
else {
- for (int idCopy = 1; GroupNameExists(newName, -1); idCopy++)
+ for (int idCopy = 1; GroupNameExists(newName); idCopy++)
mir_snwprintf(newName, L"%s (%d)", newBaseName, idCopy);
}
@@ -348,7 +353,8 @@ MIR_APP_DLL(int) Clist_GroupMoveBefore(MGROUP hGroup, MGROUP hGroupBefore) static int RenameGroupWithMove(int groupId, const wchar_t *szName, int move)
{
- if (GroupNameExists(szName, groupId)) {
+ auto existingId = GroupNameExists(szName);
+ if (existingId && existingId != groupId) {
MessageBoxW(nullptr, TranslateT("You already have a group with that name. Please enter a unique name for the group."), TranslateT("Rename group"), MB_ICONERROR | MB_OK);
return 1;
}
@@ -437,8 +443,6 @@ MIR_APP_DLL(void) Clist_GroupRestoreExpanded() }
}
-/////////////////////////////////////////////////////////////////////////////////////////
-
MIR_APP_DLL(int) Clist_GroupSetExpanded(MGROUP hGroup, int iNewState)
{
CGroupInternal *pGroup = FindGroup(hGroup-1);
@@ -455,9 +459,19 @@ MIR_APP_DLL(int) Clist_GroupSetExpanded(MGROUP hGroup, int iNewState) /////////////////////////////////////////////////////////////////////////////////////////
+void Clist_GroupSetIgnore(MGROUP hGroup, uint32_t mask)
+{
+ if (auto *pGroup = FindGroup(hGroup - 1)) {
+ pGroup->ignore = mask;
+ pGroup->save();
+ }
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
MIR_APP_DLL(int) Clist_GroupSetFlags(MGROUP hGroup, LPARAM iNewFlags)
{
- CGroupInternal *pGroup = FindGroup(hGroup-1);
+ auto *pGroup = FindGroup(hGroup-1);
if (pGroup == nullptr)
return 1;
@@ -584,6 +598,7 @@ static int enumGroups(const char *szSetting, void *) JSONNode node(JSONNode::parse(dbv.pszVal));
if (node) {
CGroupInternal *p = new CGroupInternal(atoi(szSetting), node["name"].as_mstring(), node["flags"].as_int());
+ p->ignore = node["ignore"].as_int();
arByIds.insert(p);
arByName.insert(p);
}
diff --git a/src/mir_app/src/ignore.cpp b/src/mir_app/src/ignore.cpp index d4e46b8a1f..c0e2ef8e5f 100644 --- a/src/mir_app/src/ignore.cpp +++ b/src/mir_app/src/ignore.cpp @@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "stdafx.h"
+#include "clc.h"
#define IGNOREEVENT_MAX 6
@@ -34,17 +35,30 @@ static uint32_t ignoreIdToPf4[IGNOREEVENT_MAX] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFF static uint32_t GetMask(MCONTACT hContact)
{
uint32_t mask = db_get_dw(hContact, "Ignore", "Mask1", (uint32_t)-1);
- if (mask == (uint32_t)-1) {
- if (hContact == 0)
- mask = 0;
- else {
- if ((Contact::IsHidden(hContact) && !db_mc_isSub(hContact)) || !Contact::OnList(hContact))
- mask = db_get_dw(0, "Ignore", "Mask1", 0);
+ if (mask != (uint32_t)-1)
+ return mask;
+
+ if (hContact == 0)
+ return 0;
+
+ ptrW pwszGroup(Clist_GetGroup(hContact));
+ if (pwszGroup) {
+ while (true) {
+ if (auto *pGroup = FindGroup(pwszGroup))
+ if (pGroup->ignore)
+ return pGroup->ignore;
+
+ auto *p = wcsrchr(pwszGroup, '\\');
+ if (p)
+ *p = 0;
else
- mask = db_get_dw(0, "Ignore", "Default1", 0);
+ break;
}
}
- return mask;
+
+ if ((Contact::IsHidden(hContact) && !db_mc_isSub(hContact)) || !Contact::OnList(hContact))
+ return db_get_dw(0, "Ignore", "Mask1", 0);
+ return db_get_dw(0, "Ignore", "Default1", 0);
}
static void SaveItemValue(MCONTACT hContact, const char *pszSetting, uint32_t dwValue)
@@ -63,19 +77,32 @@ class IgnoreOptsDlg : public CDlgBase CCtrlClc m_clist;
+ void SaveGroupValue(HANDLE hFirstItem)
+ {
+ int typeOfFirst = m_clist.GetItemType(hFirstItem);
+
+ HANDLE hItem = (typeOfFirst == CLCIT_GROUP) ? hFirstItem : m_clist.GetNextItem(hFirstItem, CLGN_NEXTGROUP);
+ while (hItem) {
+ if (HANDLE hChildItem = m_clist.GetNextItem(hItem, CLGN_CHILD))
+ SaveGroupValue(hChildItem);
+
+ MGROUP hGroup = UINT_PTR(hItem) & ~HCONTACT_ISGROUP;
+ Clist_GroupSetIgnore(hGroup, GetItemMask(hItem));
+
+ hItem = m_clist.GetNextItem(hItem, CLGN_NEXTGROUP);
+ }
+ }
+
void SetListGroupIcons(HANDLE hFirstItem, HANDLE hParentItem, int *groupChildCount)
{
int iconOn[IGNOREEVENT_MAX] = { 1, 1, 1, 1, 1, 1 };
int childCount[IGNOREEVENT_MAX] = { 0, 0, 0, 0, 0, 0 };
- HANDLE hItem, hChildItem;
-
int typeOfFirst = m_clist.GetItemType(hFirstItem);
// check groups
- hItem = (typeOfFirst == CLCIT_GROUP) ? hFirstItem : m_clist.GetNextItem(hFirstItem, CLGN_NEXTGROUP);
+ HANDLE hItem = (typeOfFirst == CLCIT_GROUP) ? hFirstItem : m_clist.GetNextItem(hFirstItem, CLGN_NEXTGROUP);
while (hItem) {
- hChildItem = m_clist.GetNextItem(hItem, CLGN_CHILD);
- if (hChildItem)
+ if (HANDLE hChildItem = m_clist.GetNextItem(hItem, CLGN_CHILD))
SetListGroupIcons(hChildItem, hItem, childCount);
for (int i = 0; i < _countof(iconOn); i++)
@@ -114,8 +141,7 @@ class IgnoreOptsDlg : public CDlgBase // check groups
HANDLE hItem = (typeOfFirst == CLCIT_GROUP) ? hFirstItem : m_clist.GetNextItem(hFirstItem, CLGN_NEXTGROUP);
while (hItem) {
- HANDLE hChildItem = m_clist.GetNextItem(hItem, CLGN_CHILD);
- if (hChildItem)
+ if (HANDLE hChildItem = m_clist.GetNextItem(hItem, CLGN_CHILD))
SetAllChildIcons(hChildItem, iColumn, iImage);
hItem = m_clist.GetNextItem(hItem, CLGN_NEXTGROUP);
}
@@ -170,7 +196,7 @@ class IgnoreOptsDlg : public CDlgBase m_clist.SetExtraImage(hItem, IGNOREEVENT_MAX + 1, 2);
}
- void SaveItemMask(MCONTACT hContact, HANDLE hItem, const char *pszSetting)
+ uint32_t GetItemMask(HANDLE hItem)
{
uint32_t mask = 0;
for (int i = 0; i < IGNOREEVENT_MAX; i++) {
@@ -178,7 +204,7 @@ class IgnoreOptsDlg : public CDlgBase if (iImage && iImage != EMPTY_EXTRA_ICON)
mask |= masks[i];
}
- SaveItemValue(hContact, pszSetting, mask);
+ return mask;
}
void SetAllContactIcons()
@@ -259,12 +285,14 @@ public: for (auto &hContact : Contacts()) {
HANDLE hItem = m_clist.FindContact(hContact);
if (hItem)
- SaveItemMask(hContact, hItem, "Mask1");
+ SaveItemValue(hContact, "Mask1", GetItemMask(hItem));
Contact::Hide(hContact, !m_clist.GetCheck(hItem));
}
- SaveItemMask(0, hItemAll, "Default1");
- SaveItemMask(0, hItemUnknown, "Mask1");
+ SaveGroupValue(m_clist.GetNextItem(0, CLGN_ROOT));
+
+ SaveItemValue(0, "Default1", GetItemMask(hItemAll));
+ SaveItemValue(0, "Mask1", GetItemMask(hItemUnknown));
return true;
}
|