summaryrefslogtreecommitdiff
path: root/src/modules/clist/groups.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-09-07 11:57:39 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-09-07 11:57:39 +0000
commit0ac4b544972fb011e7c7c69e60a1d5d180ada0ac (patch)
treedfeedccf29e74d70e4516d536ef0c4cae8f858a1 /src/modules/clist/groups.cpp
parent93bd92b6468356ea844cb1a3d7bb257b71c8c6bf (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
Diffstat (limited to 'src/modules/clist/groups.cpp')
-rw-r--r--src/modules/clist/groups.cpp41
1 files changed, 35 insertions, 6 deletions
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);