[ros-diffs] [ekohl] 33901: - User properties: Fix a memory leak. Enable the Apply button when the users full name or description is changed. - Group properties: The group description can be changed. Update the group list when the group description changes.

ekohl at svn.reactos.org ekohl at svn.reactos.org
Sun Jun 8 15:34:43 CEST 2008


Author: ekohl
Date: Sun Jun  8 08:34:42 2008
New Revision: 33901

URL: http://svn.reactos.org/svn/reactos?rev=33901&view=rev
Log:
- User properties:
  Fix a memory leak.
  Enable the Apply button when the users full name or description is changed.
- Group properties:
  The group description can be changed.
  Update the group list when the group description changes.
  

Modified:
    trunk/reactos/dll/cpl/usrmgr/groupprops.c
    trunk/reactos/dll/cpl/usrmgr/groups.c
    trunk/reactos/dll/cpl/usrmgr/userprops.c

Modified: trunk/reactos/dll/cpl/usrmgr/groupprops.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/usrmgr/groupprops.c?rev=33901&r1=33900&r2=33901&view=diff
==============================================================================
--- trunk/reactos/dll/cpl/usrmgr/groupprops.c [iso-8859-1] (original)
+++ trunk/reactos/dll/cpl/usrmgr/groupprops.c [iso-8859-1] Sun Jun  8 08:34:42 2008
@@ -61,7 +61,8 @@
 
 
 static VOID
-GetGroupData(HWND hwndDlg, LPTSTR lpGroupName)
+GetGeneralGroupData(HWND hwndDlg,
+                    PGENERAL_GROUP_DATA pGroupData)
 {
     PLOCALGROUP_INFO_1 groupInfo = NULL;
     PLOCALGROUP_MEMBERS_INFO_1 membersInfo = NULL;
@@ -101,15 +102,15 @@
     (void)ListView_InsertColumn(hwndLV, 0, &column);
 
     /* Set group name */
-    SetDlgItemText(hwndDlg, IDC_GROUP_GENERAL_NAME, lpGroupName);
+    SetDlgItemText(hwndDlg, IDC_GROUP_GENERAL_NAME, pGroupData->szGroupName);
 
     /* Set group description */
-    NetLocalGroupGetInfo(NULL, lpGroupName, 1, (LPBYTE*)&groupInfo);
+    NetLocalGroupGetInfo(NULL, pGroupData->szGroupName, 1, (LPBYTE*)&groupInfo);
     SetDlgItemText(hwndDlg, IDC_GROUP_GENERAL_DESCRIPTION, groupInfo->lgrpi1_comment);
     NetApiBufferFree(groupInfo);
 
     /* Set group members */
-    NetLocalGroupGetMembers(NULL, lpGroupName, 1, (LPBYTE*)&membersInfo,
+    NetLocalGroupGetMembers(NULL, pGroupData->szGroupName, 1, (LPBYTE*)&membersInfo,
                             MAX_PREFERRED_LENGTH, &dwRead, &dwTotal,
                             &resumeHandle);
 
@@ -130,7 +131,6 @@
 
             wsprintf(szGroupName,
                      TEXT("%s\\%s (%s)"),
-                     
                      membersInfo[i].lgrmi1_name,
                      szSid);
 
@@ -141,6 +141,42 @@
     }
 
     NetApiBufferFree(membersInfo);
+}
+
+
+static BOOL
+SetGeneralGroupData(HWND hwndDlg,
+                    PGENERAL_GROUP_DATA pGroupData)
+{
+    LOCALGROUP_INFO_1 groupInfo;
+    LPTSTR pszComment = NULL;
+    INT nLength;
+    NET_API_STATUS status;
+    DWORD dwIndex;
+
+    /* Get the group description */
+    nLength = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_GROUP_GENERAL_DESCRIPTION));
+    if (nLength == 0)
+    {
+        groupInfo.lgrpi1_comment = NULL;
+    }
+    else
+    {
+        pszComment = HeapAlloc(GetProcessHeap(), 0, (nLength + 1) * sizeof(TCHAR));
+        GetDlgItemText(hwndDlg, IDC_GROUP_GENERAL_DESCRIPTION, pszComment, nLength + 1);
+        groupInfo.lgrpi1_comment = pszComment;
+    }
+
+    status = NetLocalGroupSetInfo(NULL, pGroupData->szGroupName, 1, (LPBYTE)&groupInfo, &dwIndex);
+    if (status != NERR_Success)
+    {
+        DebugPrintf(_T("Status: %lu  Index: %lu"), status, dwIndex);
+    }
+
+    if (pszComment)
+        HeapFree(GetProcessHeap(), 0, pszComment);
+
+    return TRUE;
 }
 
 
@@ -150,21 +186,49 @@
                      WPARAM wParam,
                      LPARAM lParam)
 {
+    PGENERAL_GROUP_DATA pGroupData;
+
     UNREFERENCED_PARAMETER(lParam);
     UNREFERENCED_PARAMETER(wParam);
     UNREFERENCED_PARAMETER(hwndDlg);
 
+    pGroupData= (PGENERAL_GROUP_DATA)GetWindowLongPtr(hwndDlg, DWLP_USER);
+
     switch (uMsg)
     {
         case WM_INITDIALOG:
-            GetGroupData(hwndDlg,
-                         (LPTSTR)((PROPSHEETPAGE *)lParam)->lParam);
+            pGroupData = (PGENERAL_GROUP_DATA)HeapAlloc(GetProcessHeap(),
+                                                        HEAP_ZERO_MEMORY,
+                                                        sizeof(GENERAL_GROUP_DATA) + 
+                                                        lstrlen((LPTSTR)((PROPSHEETPAGE *)lParam)->lParam) * sizeof(TCHAR));
+            lstrcpy(pGroupData->szGroupName, (LPTSTR)((PROPSHEETPAGE *)lParam)->lParam);
+
+            SetWindowLongPtr(hwndDlg, DWLP_USER, (INT_PTR)pGroupData);
+
+            GetGeneralGroupData(hwndDlg,
+                                pGroupData);
             break;
 
         case WM_COMMAND:
+            switch (LOWORD(wParam))
+            {
+                case IDC_GROUP_GENERAL_DESCRIPTION:
+                    if (HIWORD(wParam) == EN_CHANGE)
+                        PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
+                    break;
+            }
+            break;
+
+        case WM_NOTIFY:
+            if (((LPPSHNOTIFY)lParam)->hdr.code == PSN_APPLY)
+            {
+                SetGeneralGroupData(hwndDlg, pGroupData);
+                return TRUE;
+            }
             break;
 
         case WM_DESTROY:
+            HeapFree(GetProcessHeap(), 0, pGroupData);
             break;
     }
 

Modified: trunk/reactos/dll/cpl/usrmgr/groups.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/usrmgr/groups.c?rev=33901&r1=33900&r2=33901&view=diff
==============================================================================
--- trunk/reactos/dll/cpl/usrmgr/groups.c [iso-8859-1] (original)
+++ trunk/reactos/dll/cpl/usrmgr/groups.c [iso-8859-1] Sun Jun  8 08:34:42 2008
@@ -84,6 +84,35 @@
             break;
     }
 
+}
+
+
+static VOID
+UpdateGroupProperties(HWND hwndDlg)
+{
+    TCHAR szGroupName[UNLEN];
+    INT iItem;
+    HWND hwndLV;
+    NET_API_STATUS status;
+    PLOCALGROUP_INFO_1 pGroupInfo = NULL;
+
+    hwndLV = GetDlgItem(hwndDlg, IDC_GROUPS_LIST);
+    iItem = ListView_GetNextItem(hwndLV, -1, LVNI_SELECTED);
+    if (iItem == -1)
+        return;
+
+    /* Get the group name */
+    ListView_GetItemText(hwndLV,
+                         iItem, 0,
+                         szGroupName,
+                         UNLEN);
+
+    status = NetLocalGroupGetInfo(NULL, szGroupName, 1, (LPBYTE*)&pGroupInfo);
+
+    ListView_SetItemText(hwndLV, iItem, 1,
+                         pGroupInfo->lgrpi1_comment);
+
+    NetApiBufferFree(pGroupInfo);
 }
 
 
@@ -461,7 +490,8 @@
                     break;
 
                 case IDM_GROUP_PROPERTIES:
-                    GroupProperties(hwndDlg);
+                    if (GroupProperties(hwndDlg) == IDOK)
+                        UpdateGroupProperties(hwndDlg);
                     break;
             }
             break;

Modified: trunk/reactos/dll/cpl/usrmgr/userprops.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/usrmgr/userprops.c?rev=33901&r1=33900&r2=33901&view=diff
==============================================================================
--- trunk/reactos/dll/cpl/usrmgr/userprops.c [iso-8859-1] (original)
+++ trunk/reactos/dll/cpl/usrmgr/userprops.c [iso-8859-1] Sun Jun  8 08:34:42 2008
@@ -310,6 +310,9 @@
     if (pszFullName)
         HeapFree(GetProcessHeap(), 0, pszFullName);
 
+    if (pszComment)
+        HeapFree(GetProcessHeap(), 0, pszComment);
+
     NetApiBufferFree(pUserInfo);
 
     return (status == NERR_Success);
@@ -339,15 +342,21 @@
                                                       lstrlen((LPTSTR)((PROPSHEETPAGE *)lParam)->lParam) * sizeof(TCHAR));
             lstrcpy(pUserData->szUserName, (LPTSTR)((PROPSHEETPAGE *)lParam)->lParam);
 
+            SetWindowLongPtr(hwndDlg, DWLP_USER, (INT_PTR)pUserData);
+
             GetGeneralUserData(hwndDlg,
                                pUserData);
-
-            SetWindowLongPtr(hwndDlg, DWLP_USER, (INT_PTR)pUserData);
             break;
 
         case WM_COMMAND:
             switch (LOWORD(wParam))
             {
+                case IDC_USER_GENERAL_FULL_NAME:
+                case IDC_USER_GENERAL_DESCRIPTION:
+                    if (HIWORD(wParam) == EN_CHANGE)
+                        PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
+                    break;
+
                 case IDC_USER_GENERAL_FORCE_CHANGE:
                     pUserData->dwPasswordExpired = !pUserData->dwPasswordExpired;
                     UpdateUserOptions(hwndDlg, pUserData, FALSE);



More information about the Ros-diffs mailing list