//Sample code file: var/ndk/webBuildengine/tmp/viewable_samples/c5607871-120e-404c-9042-2603fb37af10/SFOLDER/CPP/SHARE.CPP

//Warning: This code has been marked up for HTML

/***************************************************************************
$name: SHARE.CPP
$version: 1.0 
$date_modified: 121498 
$description: Shared folder options using the share folder dialog.
$owner: GroupWise SDK Team Lead
Copyright (c) 1998 Novell, Inc. All Rights Reserved.

THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND TREATIES.
USE AND REDISTRIBUTION OF THIS WORK IS SUBJECT TO THE LICENSE AGREEMENT
ACCOMPANYING THE SOFTWARE DEVELOPMENT KIT (SDK) THAT CONTAINS THIS WORK.
PURSUANT TO THE SDK LICENSE AGREEMENT, NOVELL HEREBY GRANTS TO DEVELOPER A
ROYALTY-FREE, NON-EXCLUSIVE LICENSE TO INCLUDE NOVELL'S SAMPLE CODE IN ITS
PRODUCT. NOVELL GRANTS DEVELOPER WORLDWIDE DISTRIBUTION RIGHTS TO MARKET,
DISTRIBUTE, OR SELL NOVELL'S SAMPLE CODE AS A COMPONENT OF DEVELOPER'S
PRODUCTS. NOVELL SHALL HAVE NO OBLIGATIONS TO DEVELOPER OR DEVELOPER'S
CUSTOMERS WITH RESPECT TO THIS CODE.
****************************************************************************/
#include <windows.h>
#include <commctrl.h>
#include "resource.h"
#include "share.h"
#include "gwoapi.h"
#include "util.h"
#include "abook.h"


/*====== PROTOTYPES =======*/
LONG APIENTRY ShareFolderDlgProc(HWND, UINT, WPARAM, LONG);
void InitShareFolderControls(HWND);
void OnListSelectionChanged(HWND);
void OnAllowShare(HWND);
void OnAddUser(HWND);
void OnRemoveUser(HWND);
void OnAllowAdd(HWND);
void OnAllowModify(HWND);
void OnAllowDelete(HWND);


/*---- GLOBALS from main.cpp ----*/
extern HINSTANCE ghInst;
extern IGWAccount* pIGWAccount;
extern HWND hWndTView;


/*----  GLOBALS ----*/
IGWFolder* pIGWSharedFolder;
IGWFolderRightsCollection* pIGWFolderRightsCollection = NULL;



/*---------------------------------------------------------------
ShareFolder

IN:      hWndDlg      -   Handle to dialog

NOTE:   Share an existing folder with a specified user.
---------------------------------------------------------------*/
void ShareFolder(HWND hWndDlg)
{
   DialogBox(ghInst, MAKEINTRESOURCE(IDD_SHAREFOLDER),hWndDlg, (DLGPROC)ShareFolderDlgProc);
}



/*-----------------------------------------------------------------------------------
ShareFolderDlgProc

  IN:      hWndDlg      -   Handle to dialog
         message      -   Message to watch for
         wParam      -   ...
         lParam      -   ...

  RETURN:   0
-----------------------------------------------------------------------------------*/
LONG APIENTRY ShareFolderDlgProc(HWND hWndDlg, UINT message, WPARAM wParam, LONG lParam)
{
BSTR bstrSubject, bstrBodyText;
TV_ITEM tvItem;
VARIANT vTmp;
LPNMHDR pnmHdr;
SharedFolderConstants scShared;



   switch(message) {
      case WM_INITDIALOG: {
         InitShareFolderControls(hWndDlg);
         break;
      }


      case WM_NOTIFY:
         pnmHdr = (LPNMHDR)lParam;

         if(pnmHdr->idFrom == IDC_SHAREDLIST) {
            switch(pnmHdr->code) {
               case NM_CLICK:
                  OnListSelectionChanged(hWndDlg);
                  break;
            }
         }
         break;


      case WM_COMMAND:
         switch(LOWORD(wParam)) {
            case IDC_SHARED:
               OnAllowShare(hWndDlg);
               break;


            case IDC_ADD:
               OnAddUser(hWndDlg);
               break;


            case IDC_REMOVE:
               OnRemoveUser(hWndDlg);
               break;


            case IDC_ALLOWADD:
               OnAllowAdd(hWndDlg);
               break;


            case IDC_ALLOWMODIFY:
               OnAllowModify(hWndDlg);
               break;


            case IDC_ALLOWDELETE:
               OnAllowDelete(hWndDlg);
               break;


            case IDOK:
               if(pIGWFolderRightsCollection) {
                  VariantInit(&vTmp);
                  V_VT(&vTmp) = VT_EMPTY;

                  bstrSubject = SysAllocString(OLESTR("Shared folder notification"));
                  bstrBodyText = SysAllocString(OLESTR("Shared folder"));

                  //----- N O T E ---

                  // This is where the changes will actually be commited.

                  // If commit is not called, changes will not be made

                  pIGWFolderRightsCollection->Commit(bstrSubject, bstrBodyText, vTmp);

                  pIGWFolderRightsCollection->Release();
                  pIGWFolderRightsCollection = NULL;
               }

               pIGWSharedFolder->Refresh();

               // Set the icon in the tree view to the shared folder

               tvItem.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
               tvItem.hItem = TreeView_GetSelection(hWndTView);

               // Is this a shared folder?

               pIGWSharedFolder->get_Shared(&scShared);

               // Set the folder icon to shared or not-shared

               if(scShared == egwNotShared) {
                  tvItem.iImage = 0;
                  tvItem.iSelectedImage = 0;
               }
               else {
                  tvItem.iImage = 1;
                  tvItem.iSelectedImage = 1;
               }

               TreeView_SetItem(hWndTView, &tvItem);

               pIGWSharedFolder->Refresh();
               pIGWSharedFolder->Release();

               EndDialog(hWndDlg, IDOK);
               break;


            case IDCANCEL:
               if(pIGWFolderRightsCollection) {
                  pIGWFolderRightsCollection->Release();
                  pIGWFolderRightsCollection = NULL;
               }

               if(pIGWSharedFolder)
                  pIGWSharedFolder->Release();

               EndDialog(hWndDlg, IDCANCEL);
               break;
         }
           break;


      case WM_CLOSE:
         ShowWindow(hWndDlg, SW_HIDE);
           EndDialog(hWndDlg, 0);
          break;

   }

   return(0);
}



/*---------------------------------------------------------
InitShareFolderControls

IN:      hWndDlg      -   Handle to dialog

NOTE:   Initialize the controls on the Share folder dialog
---------------------------------------------------------*/
void InitShareFolderControls(HWND hWndDlg)
{
DIGWFolder* pDIGWFolder;
DIGWFolderRightsCollection* pDIGWFolderRightsCollection;
DIGWFolderRights* pDIGWFolderRights;
DIGWAddress* pDIGWAddress;
IGWFolderRights* pIGWFolderRights;
IGWAddress* pIGWAddress;
HTREEITEM hTreeItem;
HWND hShared, hLView, hAdd, hRemove;
HWND hStaticSharedList, hSharedList, hStaticRights;
HWND hAllowAdd, hAllowModify, hAllowDelete;
LV_COLUMN lvCol;
TV_ITEM tvItem;
BSTR bstrFolderId;
SharedFolderConstants fShared;
long lStyle;

   

   // Get handles to controls   

   hShared = GetDlgItem(hWndDlg, IDC_SHARED);
   hLView = GetDlgItem(hWndDlg, IDC_SHAREDLIST);
   hAllowAdd = GetDlgItem(hWndDlg, IDC_ALLOWADD);
   hAllowModify = GetDlgItem(hWndDlg, IDC_ALLOWMODIFY);
   hAllowDelete = GetDlgItem(hWndDlg, IDC_ALLOWDELETE);


   lStyle = GetWindowLong(hLView, GWL_STYLE);
   lStyle |= LVS_SHOWSELALWAYS;
   SetWindowLong(hLView, GWL_STYLE, lStyle);

   // Set up column headers for list view

   // --------------------------------------

   //| Name  | Read | Add | Modify | Delete |

   // --------------------------------------


   lvCol.mask = LVCF_TEXT | LVCF_WIDTH;
   lvCol.fmt = LVCFMT_LEFT;
   lvCol.iSubItem = 0;
   lvCol.cx = 100;

   lvCol.pszText = "Name";
   ListView_InsertColumn(hLView, 0, &lvCol);

   lvCol.pszText = "Read";
   ListView_InsertColumn(hLView, 1, &lvCol);

   lvCol.pszText = "Add";
   ListView_InsertColumn(hLView, 2, &lvCol);

   lvCol.pszText = "Modify";
   ListView_InsertColumn(hLView, 3, &lvCol);

   lvCol.pszText = "Delete";
   ListView_InsertColumn(hLView, 4, &lvCol);


   // Get the currently selected Tree view node

   hTreeItem = TreeView_GetSelection(hWndTView);

   tvItem.mask = TVIF_PARAM;
   tvItem.hItem = hTreeItem;

   TreeView_GetItem(hWndTView, &tvItem);

   // Get the folder Id

   bstrFolderId = (BSTR) tvItem.lParam;

   // Get the folder by folder ID

   pIGWAccount->GetFolder(bstrFolderId, &pDIGWFolder);

   if(pDIGWFolder && SUCCEEDED(pDIGWFolder->QueryInterface(IID_IGWFolder, (void**)&pIGWSharedFolder))) {
      pDIGWFolder->Release();

      pIGWSharedFolder->get_Shared(&fShared);

      if(fShared == egwNotShared) {
         hAdd = GetDlgItem(hWndDlg, IDC_ADD);
         hRemove = GetDlgItem(hWndDlg, IDC_REMOVE);
         hStaticSharedList = GetDlgItem(hWndDlg, IDC_STATICSHAREDLIST);
         hSharedList = GetDlgItem(hWndDlg, IDC_SHAREDLIST);
         hStaticRights = GetDlgItem(hWndDlg, IDC_STATICRIGHTS);

         EnableWindow(hAdd, FALSE);
         EnableWindow(hRemove, FALSE);

         EnableWindow(hStaticSharedList, FALSE);
         EnableWindow(hSharedList, FALSE);
         EnableWindow(hStaticRights, FALSE);
         EnableWindow(hAllowAdd, FALSE);
         EnableWindow(hAllowModify, FALSE);
         EnableWindow(hAllowDelete, FALSE);

         // Get the folder rights collection object for this folder

         pIGWSharedFolder->get_FolderRights(&pDIGWFolderRightsCollection);

         if(pDIGWFolderRightsCollection && SUCCEEDED(pDIGWFolderRightsCollection->QueryInterface(IID_IGWFolderRightsCollection, (void**)&pIGWFolderRightsCollection)))
            pDIGWFolderRightsCollection->Release();
      }
      else {
         CheckDlgButton(hWndDlg, IDC_SHARED, 1);

         // Get the folder rights collection object for this folder

         pIGWSharedFolder->get_FolderRights(&pDIGWFolderRightsCollection);

         if(pDIGWFolderRightsCollection && SUCCEEDED(pDIGWFolderRightsCollection->QueryInterface(IID_IGWFolderRightsCollection, (void**)&pIGWFolderRightsCollection))) {
            pDIGWFolderRightsCollection->Release();

            VARIANT_BOOL vbStatus;
            VARIANT vIdx;
            BSTR bstrDisplayName;
            long lCount;
            int i;
            LV_ITEM lvItem;


            VariantInit(&vIdx);

            V_VT(&vIdx) = VT_I4;

            // How many folder rights does this collection have?

            pIGWFolderRightsCollection->get_Count(&lCount);

            for(i=0; i<lCount; i++) {
               V_I4(&vIdx) = i + 1;

               // Get each folder right object from the collection

               pIGWFolderRightsCollection->Item(vIdx, &pDIGWFolderRights);

               // Get the interface for folder right object

               if(pDIGWFolderRights && SUCCEEDED(pDIGWFolderRights->QueryInterface(IID_IGWFolderRights, (void**)&pIGWFolderRights))) {
                  pDIGWFolderRights->Release();

                  // Get Address object from folder right object

                  pIGWFolderRights->get_Address(&pDIGWAddress);

                  if(pDIGWAddress && SUCCEEDED(pDIGWAddress->QueryInterface(IID_IGWAddress, (void**)&pIGWAddress))) {
                     pDIGWAddress->Release();

                     // Get the display name of the user

                     pIGWAddress->get_DisplayName(&bstrDisplayName);


                     lvItem.mask = LVIF_TEXT;
                     lvItem.iItem = 0;
                     lvItem.iSubItem = 0;
                     lvItem.pszText = FROM_OLE_STRING(bstrDisplayName);

                     // Insert Display Name into list view control

                     ListView_InsertItem(hLView, &lvItem);

                     // Free the display name

                     SysFreeString(bstrDisplayName);

                     pIGWAddress->Release();
                  }


                  // Allow Read (Always checked by default)

                  ListView_SetItemText(hLView, i, 1, "X");

                  // Allow Add

                  pIGWFolderRights->get_AllowAdd(&vbStatus);

                  if(vbStatus)
                     ListView_SetItemText(hLView, i, 2, "X");

                  // Allow Modify

                  pIGWFolderRights->get_AllowModify(&vbStatus);

                  if(vbStatus)
                     ListView_SetItemText(hLView, i, 3, "X");

                  // Allow Delete

                  pIGWFolderRights->get_AllowDelete(&vbStatus);

                  if(vbStatus)
                     ListView_SetItemText(hLView, i, 4, "X");

                  EnableWindow(hAllowAdd, FALSE);
                  EnableWindow(hAllowModify, FALSE);
                  EnableWindow(hAllowDelete, FALSE);

                  pIGWFolderRights->Release();
               }
            }
         }
      }
   }
}



/*-----------------------------------------------------------
OnListSelectionChanged

IN:      hWndDlg      -   Handle to dialog

NOTE:   Called when user selects different user in shared
      folder access list view.
-----------------------------------------------------------*/
void OnListSelectionChanged(HWND hWndDlg)
{
DIGWFolderRights* pDIGWFolderRights;
IGWFolderRights* pIGWFolderRights;
VARIANT_BOOL vbStatus;
VARIANT vIdx;
HWND hLView;
int cStatus;



   hLView = GetDlgItem(hWndDlg, IDC_SHAREDLIST);

   cStatus = ListView_GetNextItem(hLView, -1, LVNI_SELECTED);

   if(cStatus != -1) {
      EnableWindow(GetDlgItem(hWndDlg, IDC_ALLOWADD), TRUE);
      EnableWindow(GetDlgItem(hWndDlg, IDC_ALLOWMODIFY), TRUE);
      EnableWindow(GetDlgItem(hWndDlg, IDC_ALLOWDELETE), TRUE);

      VariantInit(&vIdx);

      V_VT(&vIdx) = VT_I4;
      V_I4(&vIdx) = cStatus + 1;

      pIGWFolderRightsCollection->Item(vIdx, &pDIGWFolderRights);

      // Get the interface for folder right object

      if(pDIGWFolderRights && SUCCEEDED(pDIGWFolderRights->QueryInterface(IID_IGWFolderRights, (void**)&pIGWFolderRights))) {
         pDIGWFolderRights->Release();

         // Allow Add

         pIGWFolderRights->get_AllowAdd(&vbStatus);

         if(vbStatus)
            CheckDlgButton(hWndDlg, IDC_ALLOWADD, 1);
         else
            CheckDlgButton(hWndDlg, IDC_ALLOWADD, 0);

         // Allow Modify

         pIGWFolderRights->get_AllowModify(&vbStatus);

         if(vbStatus)
            CheckDlgButton(hWndDlg, IDC_ALLOWMODIFY, 1);
         else
            CheckDlgButton(hWndDlg, IDC_ALLOWMODIFY, 0);

         // Allow Delete

         pIGWFolderRights->get_AllowDelete(&vbStatus);

         if(vbStatus)
            CheckDlgButton(hWndDlg, IDC_ALLOWDELETE, 1);
         else
            CheckDlgButton(hWndDlg, IDC_ALLOWDELETE, 0);

         pIGWFolderRights->Release();
      }
   }
   else {
      EnableWindow(GetDlgItem(hWndDlg, IDC_ALLOWADD), FALSE);
      EnableWindow(GetDlgItem(hWndDlg, IDC_ALLOWMODIFY), FALSE);
      EnableWindow(GetDlgItem(hWndDlg, IDC_ALLOWDELETE), FALSE);
   }
}



/*-----------------------------------------------------------------
OnAllowShare

  IN:      hWndDlg      -   Handle to dialog

  NOTE:      Called when user changes the "Share foler" checkbox on
         the share dialog.
------------------------------------------------------------------*/
void OnAllowShare(HWND hWndDlg)
{
DIGWFolderRights* pDIGWFolderRights;
IGWFolderRights* pIGWFolderRights;
VARIANT vIdx;
long lCount;
int i, cStatus;

   
   
   cStatus = IsDlgButtonChecked(hWndDlg, IDC_SHARED);

   if(cStatus) {
      EnableWindow(GetDlgItem(hWndDlg, IDC_ADD), TRUE);
      EnableWindow(GetDlgItem(hWndDlg, IDC_REMOVE), TRUE);
      EnableWindow(GetDlgItem(hWndDlg, IDC_STATICSHAREDLIST), TRUE);
      EnableWindow(GetDlgItem(hWndDlg, IDC_SHAREDLIST), TRUE);
      EnableWindow(GetDlgItem(hWndDlg, IDC_STATICRIGHTS), TRUE);
   }
   else {
      VariantInit(&vIdx);
      V_VT(&vIdx) = VT_I4;

      pIGWFolderRightsCollection->get_Count(&lCount);


      for(i=0; i<lCount; i++) {
         V_I4(&vIdx) = i + 1;

         // Get folder rights object specified by vIdx

         pIGWFolderRightsCollection->Item(vIdx, &pDIGWFolderRights);

         // Delete the user rights

         if(pDIGWFolderRights && SUCCEEDED(pDIGWFolderRights->QueryInterface(IID_IGWFolderRights, (void**)&pIGWFolderRights))) {
            pDIGWFolderRights->Release();
            pIGWFolderRights->Delete();
            pIGWFolderRights->Release();
         }
      }

      EnableWindow(GetDlgItem(hWndDlg, IDC_ADD), FALSE);
      EnableWindow(GetDlgItem(hWndDlg, IDC_REMOVE), FALSE);
      EnableWindow(GetDlgItem(hWndDlg, IDC_STATICSHAREDLIST), FALSE);
      EnableWindow(GetDlgItem(hWndDlg, IDC_SHAREDLIST), FALSE);
      EnableWindow(GetDlgItem(hWndDlg, IDC_STATICRIGHTS), FALSE);
      EnableWindow(GetDlgItem(hWndDlg, IDC_ALLOWADD), FALSE);
      EnableWindow(GetDlgItem(hWndDlg, IDC_ALLOWMODIFY), FALSE);
      EnableWindow(GetDlgItem(hWndDlg, IDC_ALLOWDELETE), FALSE);
   }
}



/*----------------------------------------------------------------
OnAddUser

IN:      hWndDlg      -   Handle to dialog

NOTE:   Called when user adds another user to share folder with.
----------------------------------------------------------------*/
void OnAddUser(HWND hWndDlg)
{
DIGWAddressBookEntry* pDIGWAddressBookEntry;
IGWAddressBookEntry* pIGWAddressBookEntry;
VARIANT vAddress;
HWND hLView;
LV_ITEM lvItem;
BSTR bstrDisplayName;



   if(ShowAddressBook(hWndDlg, &pDIGWAddressBookEntry) == IDOK) {
      hLView = GetDlgItem(hWndDlg, IDC_SHAREDLIST);

      // Set variant to the AddressBookEntry dispatch we got from

      // the address book.

      VariantInit(&vAddress);
      V_VT(&vAddress) = VT_DISPATCH;
      V_DISPATCH(&vAddress) = pDIGWAddressBookEntry;

      // Try to add usr to shared folder collection

      if(SUCCEEDED(pIGWFolderRightsCollection->Add(vAddress, egwAllowAdd))) {
         if(SUCCEEDED(pDIGWAddressBookEntry->QueryInterface(IID_IGWAddressBookEntry, (void**)&pIGWAddressBookEntry))) {
            pDIGWAddressBookEntry->Release();

            // We succeeded so lets get the display name and insert it

            // into the list view control along with the other info below.

            pIGWAddressBookEntry->get_DisplayName(&bstrDisplayName);

            int nItem = ListView_GetItemCount(hLView);

            lvItem.mask = LVIF_TEXT;
            lvItem.iItem = nItem;
            lvItem.iSubItem = 0;
            lvItem.pszText = FROM_OLE_STRING(bstrDisplayName);

            ListView_InsertItem(hLView, &lvItem);
            ListView_SetItemText(hLView, nItem, 1, "X");
            ListView_SetItemText(hLView, nItem, 2, "X");

            SysFreeString(bstrDisplayName);

            pIGWAddressBookEntry->Release();
         }
      }
      else {
         MessageBox(hWndDlg, "OOPS!", "Did't work", MB_OK);
      }
   }
}



/*----------------------------------------------------------------
OnRemoveUser

IN:      hWndDlg      - Handle to dialog

NOTE:   Called when a user is deleted out of the shared list view.
----------------------------------------------------------------*/
void OnRemoveUser(HWND hWndDlg)
{
DIGWFolderRights* pDIGWFolderRights;
IGWFolderRights* pIGWFolderRights;
VARIANT vIdx;
HWND hLView;
int nSel;


   hLView = GetDlgItem(hWndDlg, IDC_SHAREDLIST);

   nSel = ListView_GetNextItem(hLView, -1, LVNI_SELECTED);

   if(nSel != -1) {
      VariantInit(&vIdx);
      V_VT(&vIdx) = VT_I4;
      V_I4(&vIdx) = nSel + 1;

      // Get folder rights object specified by vIdx

      pIGWFolderRightsCollection->Item(vIdx, &pDIGWFolderRights);

      if(pDIGWFolderRights && SUCCEEDED(pDIGWFolderRights->QueryInterface(IID_IGWFolderRights, (void**)&pIGWFolderRights))) {
         pDIGWFolderRights->Release();

         // Delete the folder rights object from the collection

         pIGWFolderRights->Delete();

         // Delete user from shared list view

         ListView_DeleteItem(hLView, nSel);

         pIGWFolderRights->Release();
      }
   }
}



/*----------------------------------------------------------------
OnAllowAdd

IN:      hWndDlg      -   Handle to dialog

NOTE:   Called when user changes Allow add checkbox
----------------------------------------------------------------*/
void OnAllowAdd(HWND hWndDlg)
{
DIGWFolderRights* pDIGWFolderRights;
IGWFolderRights* pIGWFolderRights;
HWND hLView;
int nSel, cStatus;
VARIANT vIdx;



   hLView = GetDlgItem(hWndDlg, IDC_SHAREDLIST);

   // Get selected item

   nSel = ListView_GetNextItem(hLView, -1, LVNI_SELECTED);

   if(nSel != -1) {
      cStatus = IsDlgButtonChecked(hWndDlg, IDC_ALLOWADD);

      VariantInit(&vIdx);
      V_VT(&vIdx) = VT_I4;
      V_I4(&vIdx) = nSel + 1;   // Add 1 since Item method index is 1 based


      // Get folder right specified by vIdx

      pIGWFolderRightsCollection->Item(vIdx, &pDIGWFolderRights);


      if(pDIGWFolderRights && SUCCEEDED(pDIGWFolderRights->QueryInterface(IID_IGWFolderRights, (void**)&pIGWFolderRights))) {
         pDIGWFolderRights->Release();

         if(cStatus == 1) {
            pIGWFolderRights->put_AllowAdd(TRUE);
            ListView_SetItemText(hLView, nSel, 2, "X");
         }
         else if(cStatus == 0) {
            pIGWFolderRights->put_AllowAdd(FALSE);
            ListView_SetItemText(hLView, nSel, 2, " ");
         }

         pIGWFolderRights->Release();
      }
   }
}



/*----------------------------------------------------------------
OnAllowModify

IN:      hWndDlg      -   Handle to dialog

NOTE:   Called when user changes Allow modify checkbox
----------------------------------------------------------------*/
void OnAllowModify(HWND hWndDlg)
{
DIGWFolderRights* pDIGWFolderRights;
IGWFolderRights* pIGWFolderRights;
HWND hLView;
int nSel, cStatus;
VARIANT vIdx;



   hLView = GetDlgItem(hWndDlg, IDC_SHAREDLIST);

   nSel = ListView_GetNextItem(hLView, -1, LVNI_SELECTED);

   if(nSel != -1) {
      cStatus = IsDlgButtonChecked(hWndDlg, IDC_ALLOWMODIFY);

      VariantInit(&vIdx);
      V_VT(&vIdx) = VT_I4;
      V_I4(&vIdx) = nSel + 1;

      pIGWFolderRightsCollection->Item(vIdx, &pDIGWFolderRights);


      if(pDIGWFolderRights && SUCCEEDED(pDIGWFolderRights->QueryInterface(IID_IGWFolderRights, (void**)&pIGWFolderRights))) {
         pDIGWFolderRights->Release();

         if(cStatus == 1) {
            pIGWFolderRights->put_AllowModify(TRUE);
            ListView_SetItemText(hLView, nSel, 3, "X");
         }
         else if(cStatus == 0) {
            pIGWFolderRights->put_AllowModify(FALSE);
            ListView_SetItemText(hLView, nSel, 3, " ");
         }

         pIGWFolderRights->Release();
      }
   }
}



/*----------------------------------------------------------------
OnAllowDelete

IN:      hWndDlg      -   Handle to dialog

NOTE:   Called when user changes Allow Delete checkbox
----------------------------------------------------------------*/
void OnAllowDelete(HWND hWndDlg)
{
DIGWFolderRights* pDIGWFolderRights;
IGWFolderRights* pIGWFolderRights;
HWND hLView;
int nSel, cStatus;
VARIANT vIdx;



   hLView = GetDlgItem(hWndDlg, IDC_SHAREDLIST);

   nSel = ListView_GetNextItem(hLView, -1, LVNI_SELECTED);

   if(nSel != -1) {
      cStatus = IsDlgButtonChecked(hWndDlg, IDC_ALLOWDELETE);

      VariantInit(&vIdx);
      V_VT(&vIdx) = VT_I4;
      V_I4(&vIdx) = nSel + 1;

      pIGWFolderRightsCollection->Item(vIdx, &pDIGWFolderRights);


      if(pDIGWFolderRights && SUCCEEDED(pDIGWFolderRights->QueryInterface(IID_IGWFolderRights, (void**)&pIGWFolderRights))) {
         pDIGWFolderRights->Release();

         if(cStatus == 1) {
            pIGWFolderRights->put_AllowDelete(TRUE);
            ListView_SetItemText(hLView, nSel, 4, "X");
         }
         else if(cStatus == 0) {
            pIGWFolderRights->put_AllowDelete(FALSE);
            ListView_SetItemText(hLView, nSel, 4, " ");
         }

         pIGWFolderRights->Release();
      }
   }
}