bool do_choose_perms(Buffer &b) { #if DEBUG //msg(PLUGIN_NAME": in do_choose_perms"); #endif Options mask; projectBuffer = &b; tempOpts.pub = projectBuffer->readLong(); tempOpts.sub = projectBuffer->readLong(); mask.pub = projectBuffer->readLong(); mask.sub = projectBuffer->readLong(); Options current = tempOpts; #if DEBUG msg(PLUGIN_NAME": P %x S %x \n", (unsigned int)tempOpts.pub, (unsigned int)tempOpts.sub); #endif int numOptions = projectBuffer->readInt(); numOptionsGlobal = numOptions; optLabels = (char**)qalloc(numOptions * sizeof(char*)); for (int i = 0; i < numOptions; i++) { optLabels[i] = projectBuffer->readUTF8(); } showOptionsDlg(mainWindow, optLabels, numOptionsGlobal, &tempOpts, &tempOpts, &mask); for (int i = 0; i < numOptionsGlobal; i++) { qfree(optLabels[i]); } qfree(optLabels); optLabels = NULL; return memcmp(¤t, &tempOpts, sizeof(Options)) != 0; }
//The global projectBuffer pointer should be initialized to point to //the incoming buffer that contains the project list to be displayed in //the project list dialog PRIOR to calling DialogBox BOOL CALLBACK ProjectDlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: { int numProjects = projectBuffer->readInt(); numProjectsGlobal = numProjects; projects = (int*)qalloc(numProjects * sizeof(int)); snapUpdateIDs = (unsigned long long*)qalloc(numProjects * sizeof(unsigned long long)); optMasks = (Options*)qalloc(numProjects * sizeof(Options)); SetDlgItemText(hwndDlg, IDC_PROJECT_LIST, ""); SetDlgItemText(hwndDlg, IDC_DESCRIPTION, ""); //the New project is always listed as the first option SendDlgItemMessage(hwndDlg, IDC_PROJECT_LIST, CB_ADDSTRING, (WPARAM)0, (LPARAM)"<New project>"); for (int i = 0; i < numProjects; i++) { projects[i] = projectBuffer->readInt(); snapUpdateIDs[i] = projectBuffer->readLong(); //if (snapUpdateIDs[i] > 0 ) { // msg(PLUGIN_NAME": project %d is a snapshot\n", i+1); //} char *desc = projectBuffer->readUTF8(); int isSnapShot = 0; if ( snapUpdateIDs[i] !=0 ) { isSnapShot = 1; } #if DEBUG msg(PLUGIN_NAME": %d : %d - %s (%d) ", i, projects[i], desc, isSnapShot); #endif SendDlgItemMessage(hwndDlg, IDC_PROJECT_LIST, CB_ADDSTRING, (WPARAM)0, (LPARAM)desc); qfree(desc); //need to read options mask for this project //but for now everything is enabled //memset(optMasks + i, 0xFF, sizeof(Options)); optMasks[i].pub = projectBuffer->readLong(); optMasks[i].sub = projectBuffer->readLong(); #if DEBUG msg(PLUGIN_NAME": P %x S %x \n", (unsigned int)optMasks[i].pub, (unsigned int)optMasks[i].sub); #endif } int numOptions = projectBuffer->readInt(); numOptionsGlobal = numOptions; optLabels = (char**)qalloc(numOptions * sizeof(char*)); for (int i = 0; i < numOptions; i++) { optLabels[i] = projectBuffer->readUTF8(); } CheckDlgButton(hwndDlg, IDC_PUBLISH, BST_CHECKED); CheckDlgButton(hwndDlg, IDC_SUBSCRIBE, BST_CHECKED); return TRUE; } case WM_COMMAND: { switch (LOWORD(wParam)) { case IDOK: {//OK Button int selected = SendDlgItemMessage(hwndDlg, IDC_PROJECT_LIST, CB_GETCURSEL, 0, 0); if (selected != LB_ERR) { if (selected != 0) { if (numProjectsGlobal > 1) { if (snapUpdateIDs[selected - 1] > 0) { GetDlgItemText(hwndDlg, IDC_DESCRIPTION, description, sizeof(description)); isSnapShotGlobal = 1; } } selected = projects[selected - 1]; } else { // selected == 0, new project GetDlgItemText(hwndDlg, IDC_DESCRIPTION, description, sizeof(description)); } } else { selected = -1; } //there is still some value in keeping these as they limit the //amount of traffic the client will generate to some extent publish = userOpts.pub != 0; subscribe = userOpts.sub != 0; //remember these as the current options setUserOpts(userOpts); // publish = IsDlgButtonChecked(hwndDlg, IDC_PUBLISH) == BST_CHECKED; // subscribe = IsDlgButtonChecked(hwndDlg, IDC_SUBSCRIBE) == BST_CHECKED; EndDialog(hwndDlg, selected); return TRUE; } case IDCANCEL: { //Cancel Button EndDialog(hwndDlg, -1); return TRUE; } case IDC_PROJECT_LIST: { if (HIWORD(wParam) == CBN_SELCHANGE) { int selected = SendDlgItemMessage(hwndDlg, IDC_PROJECT_LIST, CB_GETCURSEL, 0, 0); HWND desc = GetDlgItem(hwndDlg, IDC_DESCRIPTION); if (selected == 0) { //New project //enable all persmissions for new projects memset(&userOpts, 0xFF, sizeof(userOpts)); //enable description control for new projects EnableWindow(desc, TRUE); } // else if (numProjectsGlobal > 1) { else if (numProjectsGlobal > 0) { if (snapUpdateIDs[selected - 1] != 0) { //enable all persmissions for new projects memset(&userOpts, 0xFF, sizeof(userOpts)); EnableWindow(desc, TRUE); } else { userOpts = optMasks[selected - 1]; EnableWindow(desc, FALSE); } } else { //unreachable? msg(PLUGIN_NAME": unkown desc window state entered, please tell developers\n"); EnableWindow(desc, FALSE); } return TRUE; } break; } case IDC_OPTIONS: { #if DEBUG msg(PLUGIN_NAME": calling showOptionsDlg\n"); #endif showOptionsDlg(hwndDlg, optLabels, numOptionsGlobal, &userOpts, &userOpts, &userOpts); return TRUE; } } } } return FALSE; }
//The global projectBuffer pointer should be initialized to point to //the incoming buffer that contains the project list to be displayed in //the project list dialog PRIOR to calling DialogBox BOOL CALLBACK ProjectDlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: { int numProjects = projectBuffer->readInt(); numProjectsGlobal = numProjects; projects = (int*)qalloc(numProjects * sizeof(int)); snapUpdateIDs = (uint64_t*)qalloc(numProjects * sizeof(uint64_t)); optMasks = (Options*)qalloc(numProjects * sizeof(Options)); SetDlgItemText(hwndDlg, IDC_PROJECT_LIST, ""); SetDlgItemText(hwndDlg, IDC_DESCRIPTION, ""); //the New project is always listed as the first option SendDlgItemMessage(hwndDlg, IDC_PROJECT_LIST, CB_ADDSTRING, (WPARAM)0, (LPARAM)"<New project>"); for (int i = 0; i < numProjects; i++) { projects[i] = projectBuffer->readInt(); snapUpdateIDs[i] = projectBuffer->readLong(); //if (snapUpdateIDs[i] > 0 ) { // msg(PLUGIN_NAME": project %d is a snapshot\n", i + 1); //} char *desc = projectBuffer->readUTF8(); int isSnapShot = 0; if ( snapUpdateIDs[i] !=0 ) { isSnapShot = 1; } #ifdef DEBUG msg(PLUGIN_NAME": %d : %d - %s (%d) ", i, projects[i], desc, isSnapShot); #endif SendDlgItemMessage(hwndDlg, IDC_PROJECT_LIST, CB_ADDSTRING, (WPARAM)0, (LPARAM)desc); qfree(desc); //need to read options mask for this project //but for now everything is enabled //memset(optMasks + i, 0xFF, sizeof(Options)); optMasks[i].pub.ll = projectBuffer->readLong(); optMasks[i].sub.ll = projectBuffer->readLong(); #ifdef DEBUG msg(PLUGIN_NAME": P %x S %x \n", optMasks[i].pub.ii[0], optMasks[i].sub.ii[0]); #endif } int numOptions = projectBuffer->readInt(); numOptionsGlobal = numOptions; optLabels = (char**)qalloc(numOptions * sizeof(char*)); for (int i = 0; i < numOptions; i++) { optLabels[i] = projectBuffer->readUTF8(); } CheckDlgButton(hwndDlg, IDC_PUBLISH, BST_CHECKED); CheckDlgButton(hwndDlg, IDC_SUBSCRIBE, BST_CHECKED); return TRUE; } case WM_COMMAND: { switch (LOWORD(wParam)) { case IDOK: {//OK Button char description[1024]; int selected = SendDlgItemMessage(hwndDlg, IDC_PROJECT_LIST, CB_GETCURSEL, 0, 0); GetDlgItemText(hwndDlg, IDC_DESCRIPTION, description, sizeof(description)); if (selected == 0) { //new project, make sure that user hasn't tried to name the project using //an existing project name int count = SendDlgItemMessage(hwndDlg, IDC_PROJECT_LIST, CB_GETCOUNT, 0, 0); for (int n = 1; n < count; n++) { int len = SendDlgItemMessage(hwndDlg, IDC_PROJECT_LIST, CB_GETLBTEXTLEN, n, 0); if (len != CB_ERR) { char *item = new char[len + 1]; SendDlgItemMessage(hwndDlg, IDC_PROJECT_LIST, CB_GETLBTEXT, n, (LPARAM)item); char *i = strchr(item, ']'); if (i != NULL) { i += 2; if (strcmp(i, description) == 0) { ::MessageBox(hwndDlg, "Project already exists. Join existing project or change name.", "Error", MB_OK | MB_ICONERROR); delete [] item; return FALSE; } } delete [] item; } } } selected = chooseProject(selected, description); EndDialog(hwndDlg, selected); return TRUE; } case IDCANCEL: { //Cancel Button EndDialog(hwndDlg, -1); return TRUE; } case IDC_PROJECT_LIST: { if (HIWORD(wParam) == CBN_SELCHANGE) { int selected = SendDlgItemMessage(hwndDlg, IDC_PROJECT_LIST, CB_GETCURSEL, 0, 0); HWND desc = GetDlgItem(hwndDlg, IDC_DESCRIPTION); if (changeProject(selected)) { EnableWindow(desc, TRUE); } else { EnableWindow(desc, FALSE); } return TRUE; } break; } case IDC_OPTIONS: { #ifdef DEBUG msg(PLUGIN_NAME": calling showOptionsDlg\n"); #endif showOptionsDlg(hwndDlg, optLabels, numOptionsGlobal, &userOpts, &userOpts, &userOpts); return TRUE; } } } } return FALSE; }