diff options
author | George Hazan <george.hazan@gmail.com> | 2013-09-07 11:57:39 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-09-07 11:57:39 +0000 |
commit | 0ac4b544972fb011e7c7c69e60a1d5d180ada0ac (patch) | |
tree | dfeedccf29e74d70e4516d536ef0c4cae8f858a1 | |
parent | 93bd92b6468356ea844cb1a3d7bb257b71c8c6bf (diff) |
MS_CLIST_GROUPEXISTS - new service to detect the clist group's presence
git-svn-id: http://svn.miranda-ng.org/main/trunk@5993 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | include/delphi/m_clist.inc | 8 | ||||
-rw-r--r-- | include/m_clist.h | 14 | ||||
-rw-r--r-- | src/modules/clist/groups.cpp | 41 |
3 files changed, 57 insertions, 6 deletions
diff --git a/include/delphi/m_clist.inc b/include/delphi/m_clist.inc index c3ea28b48d..294f7fd0d9 100644 --- a/include/delphi/m_clist.inc +++ b/include/delphi/m_clist.inc @@ -466,6 +466,14 @@ const ME_CLIST_GROUPCHANGE:PAnsiChar = 'CList/GroupChange';
{
+ checks that a group exists
+ wParam : 0 (unused)
+ lParam : (PWideChar)groupName
+ returns 0 if a group is not found or group handle on success
+ }
+ MS_CLIST_GROUPEXISTS:PAnsiChar = 'CList/GroupExists';
+
+ {
wParam : HPARENTGROUP
lParam : 0 or Pointer to new group name
Affect : Create a new group and calls CLUI to display it, see notes
diff --git a/include/m_clist.h b/include/m_clist.h index 587a3cb35b..df82559883 100644 --- a/include/m_clist.h +++ b/include/m_clist.h @@ -468,6 +468,16 @@ typedef struct { #define ME_CLIST_GROUPCHANGE "CList/GroupChange"
+//checks that a group exists v0.1.1.0+
+//wParam = 0 (unused)
+//lParam = (TCHAR*)groupName
+//returns 0 if a group is not found or group handle on success
+#define MS_CLIST_GROUPEXISTS "CList/GroupExists"
+
+__forceinline HANDLE Clist_GroupExists(LPCTSTR ptszGroupName)
+{ return (HANDLE)CallService(MS_CLIST_GROUPEXISTS, 0, (LPARAM)ptszGroupName);
+}
+
//creates a new group and calls CLUI to display it v0.1.1.0+
//wParam = hParentGroup
//lParam = groupName
@@ -478,6 +488,10 @@ typedef struct { //API to create unique name by itself
#define MS_CLIST_GROUPCREATE "CList/GroupCreate"
+__forceinline HANDLE Clist_CreateGroup(HANDLE hParent, LPCTSTR ptszGroupName)
+{ return (HANDLE)CallService(MS_CLIST_GROUPCREATE, (WPARAM)hParent, (LPARAM)ptszGroupName);
+}
+
//deletes a group and calls CLUI to display the change v0.1.1.0+
//wParam = (WPARAM)(HANDLE)hGroup
//lParam = 0
diff --git a/src/modules/clist/groups.cpp b/src/modules/clist/groups.cpp index fe0a7b6ffb..d99ed04a09 100644 --- a/src/modules/clist/groups.cpp +++ b/src/modules/clist/groups.cpp @@ -65,17 +65,25 @@ static int GroupNameExists(const TCHAR *name, int skipGroup) return 0;
}
-static INT_PTR CreateGroup(WPARAM wParam, LPARAM lParam)
+static INT_PTR GroupExists(WPARAM, LPARAM lParam)
+{
+ if (lParam == 0)
+ return FALSE;
+
+ return GroupNameExists((LPCTSTR)lParam, -1);
+}
+
+static INT_PTR CreateGroupInternal(INT_PTR iParent, const TCHAR *ptszName)
{
int newId = CountGroups();
TCHAR newBaseName[127], newName[128];
char str[33];
int i;
- DBVARIANT dbv;
- const TCHAR* grpName = lParam ? (TCHAR*)lParam : TranslateT("New Group");
- if (wParam) {
- _itoa(wParam - 1, str, 10);
+ const TCHAR* grpName = ptszName ? ptszName : TranslateT("New Group");
+ if (iParent) {
+ _itoa(iParent - 1, str, 10);
+ DBVARIANT dbv;
if (db_get_ts(NULL, "CListGroups", str, &dbv))
return 0;
@@ -86,7 +94,7 @@ static INT_PTR CreateGroup(WPARAM wParam, LPARAM lParam) _itoa(newId, str, 10);
lstrcpyn(newName + 1, newBaseName, SIZEOF(newName) - 1);
- if (lParam) {
+ if (ptszName) {
i = GroupNameExists(newBaseName, -1);
if (i) newId = i - 1;
i = !i;
@@ -109,6 +117,26 @@ static INT_PTR CreateGroup(WPARAM wParam, LPARAM lParam) return newId + 1;
}
+static INT_PTR CreateGroup(WPARAM wParam, LPARAM lParam)
+{
+ if (lParam == 0)
+ return CreateGroupInternal(wParam, NULL);
+
+ LPCTSTR ptszName = (LPCTSTR)lParam;
+ if (ptszName == NULL || ptszName[0] == '\0' || ptszName[0] == '\\')
+ return 0;
+
+ TCHAR *tszName = NEWTSTR_ALLOCA(ptszName);
+ for (TCHAR *p = tszName; *p; p++) {
+ if (*p == '\\') {
+ *p = '\0';
+ CreateGroupInternal(wParam, tszName);
+ *p = '\\';
+ }
+ }
+ return CreateGroupInternal(wParam, tszName);
+}
+
static INT_PTR GetGroupName2(WPARAM wParam, LPARAM lParam)
{
char idstr[33];
@@ -552,6 +580,7 @@ int InitGroupServices(void) db_free(&dbv);
}
+ CreateServiceFunction(MS_CLIST_GROUPEXISTS, GroupExists);
CreateServiceFunction(MS_CLIST_GROUPCREATE, CreateGroup);
CreateServiceFunction(MS_CLIST_GROUPDELETE, DeleteGroup);
CreateServiceFunction(MS_CLIST_GROUPRENAME, RenameGroup);
|