From 051fa9db8fd4a3fbb213f0b60c8c39dff946f3ad Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Sun, 20 Oct 2013 21:34:46 +0100 Subject: [PATCH 01/13] Changed logging to UTF-8 --- openlp/core/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/core/__init__.py b/openlp/core/__init__.py index f86f9036f..f3edf476e 100644 --- a/openlp/core/__init__.py +++ b/openlp/core/__init__.py @@ -230,7 +230,7 @@ def set_up_logging(log_path): """ check_directory_exists(log_path, True) filename = os.path.join(log_path, 'openlp.log') - logfile = logging.FileHandler(filename, 'w') + logfile = logging.FileHandler(filename, 'w', encoding="UTF-8") logfile.setFormatter(logging.Formatter('%(asctime)s %(name)-55s %(levelname)-8s %(message)s')) log.addHandler(logfile) if log.isEnabledFor(logging.DEBUG): From f6c3881d03c2b81ec170d1892bbe21a288ae322d Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Sun, 20 Oct 2013 21:42:40 +0100 Subject: [PATCH 02/13] Unicodified C Library --- .../lib/pptviewlib/pptviewlib.cpp | 218 +++++++++--------- .../presentations/lib/pptviewlib/pptviewlib.h | 18 +- .../lib/pptviewlib/pptviewlib.vcproj | 6 +- 3 files changed, 121 insertions(+), 121 deletions(-) diff --git a/openlp/plugins/presentations/lib/pptviewlib/pptviewlib.cpp b/openlp/plugins/presentations/lib/pptviewlib/pptviewlib.cpp index b9ed433ca..a4ee5053c 100644 --- a/openlp/plugins/presentations/lib/pptviewlib/pptviewlib.cpp +++ b/openlp/plugins/presentations/lib/pptviewlib/pptviewlib.cpp @@ -61,18 +61,18 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ulReasonForCall, switch(ulReasonForCall) { case DLL_PROCESS_ATTACH: - DEBUG("PROCESS_ATTACH\n"); + DEBUG(L"PROCESS_ATTACH\n"); break; case DLL_THREAD_ATTACH: - //DEBUG("THREAD_ATTACH\n"); + //DEBUG(L"THREAD_ATTACH\n"); break; case DLL_THREAD_DETACH: - //DEBUG("THREAD_DETACH\n"); + //DEBUG(L"THREAD_DETACH\n"); break; case DLL_PROCESS_DETACH: // Clean up... hopefully there is only the one process attached? // We'll find out soon enough during tests! - DEBUG("PROCESS_DETACH\n"); + DEBUG(L"PROCESS_DETACH\n"); for (int i = 0; i < MAX_PPTS; i++) ClosePPT(i); break; @@ -84,18 +84,18 @@ DllExport void SetDebug(BOOL onOff) { printf("SetDebug\n"); debug = onOff; - DEBUG("enabled\n"); + DEBUG(L"enabled\n"); } DllExport BOOL CheckInstalled() { - char cmdLine[MAX_PATH * 2]; + wchar_t cmdLine[MAX_PATH * 2]; - DEBUG("CheckInstalled\n"); + DEBUG(L"CheckInstalled\n"); BOOL found = GetPPTViewerPath(cmdLine, sizeof(cmdLine)); if(found) { - DEBUG("Exe: %s\n", cmdLine); + DEBUG(L"Exe: %s\n", cmdLine); } return found; } @@ -106,20 +106,20 @@ DllExport BOOL CheckInstalled() // ".bmp" will be appended to complete the path. E.g. "c:\temp\slide" would // create "c:\temp\slide1.bmp" slide2.bmp, slide3.bmp etc. // It will also create a *info.txt containing information about the ppt -DllExport int OpenPPT(char *filename, HWND hParentWnd, RECT rect, - char *previewPath) +DllExport int OpenPPT(wchar_t *filename, HWND hParentWnd, RECT rect, + wchar_t *previewPath) { STARTUPINFO si; PROCESS_INFORMATION pi; - char cmdLine[MAX_PATH * 2]; + wchar_t cmdLine[MAX_PATH * 2]; int id; - DEBUG("OpenPPT start: %s; %s\n", filename, previewPath); - DEBUG("OpenPPT start: %u; %i, %i, %i, %i\n", hParentWnd, rect.top, + DEBUG(L"OpenPPT start: %s; %s\n", filename, previewPath); + DEBUG(L"OpenPPT start: %u; %i, %i, %i, %i\n", hParentWnd, rect.top, rect.left, rect.bottom, rect.right); if (GetPPTViewerPath(cmdLine, sizeof(cmdLine)) == FALSE) { - DEBUG("OpenPPT: GetPPTViewerPath failed\n"); + DEBUG(L"OpenPPT: GetPPTViewerPath failed\n"); return -1; } id = -1; @@ -133,12 +133,12 @@ DllExport int OpenPPT(char *filename, HWND hParentWnd, RECT rect, } if (id < 0) { - DEBUG("OpenPPT: Too many PPTs\n"); + DEBUG(L"OpenPPT: Too many PPTs\n"); return -1; } memset(&pptView[id], 0, sizeof(PPTVIEW)); - strcpy_s(pptView[id].filename, MAX_PATH, filename); - strcpy_s(pptView[id].previewPath, MAX_PATH, previewPath); + wcscpy_s(pptView[id].filename, MAX_PATH, filename); + wcscpy_s(pptView[id].previewPath, MAX_PATH, previewPath); pptView[id].state = PPT_CLOSED; pptView[id].slideCount = 0; pptView[id].currentSlide = 0; @@ -169,9 +169,9 @@ DllExport int OpenPPT(char *filename, HWND hParentWnd, RECT rect, pptView[id].rect.bottom = rect.bottom; pptView[id].rect.right = rect.right; } - strcat_s(cmdLine, MAX_PATH * 2, " /F /S \""); - strcat_s(cmdLine, MAX_PATH * 2, filename); - strcat_s(cmdLine, MAX_PATH * 2, "\""); + wcscat_s(cmdLine, MAX_PATH * 2, L" /F /S \""); + wcscat_s(cmdLine, MAX_PATH * 2, filename); + wcscat_s(cmdLine, MAX_PATH * 2, L"\""); memset(&si, 0, sizeof(si)); memset(&pi, 0, sizeof(pi)); BOOL gotInfo = GetPPTInfo(id); @@ -190,7 +190,7 @@ DllExport int OpenPPT(char *filename, HWND hParentWnd, RECT rect, globalHook = SetWindowsHookEx(WH_CBT, CbtProc, hInstance, NULL); if (globalHook == 0) { - DEBUG("OpenPPT: SetWindowsHookEx failed\n"); + DEBUG(L"OpenPPT: SetWindowsHookEx failed\n"); ClosePPT(id); return -1; } @@ -198,7 +198,7 @@ DllExport int OpenPPT(char *filename, HWND hParentWnd, RECT rect, Sleep(10); if (!CreateProcess(NULL, cmdLine, NULL, NULL, FALSE, 0, 0, NULL, &si, &pi)) { - DEBUG("OpenPPT: CreateProcess failed: %s\n", cmdLine); + DEBUG(L"OpenPPT: CreateProcess failed: %s\n", cmdLine); ClosePPT(id); return -1; } @@ -210,13 +210,13 @@ DllExport int OpenPPT(char *filename, HWND hParentWnd, RECT rect, Sleep(10); if (gotInfo) { - DEBUG("OpenPPT: Info loaded, no refresh\n"); + DEBUG(L"OpenPPT: Info loaded, no refresh\n"); pptView[id].state = PPT_LOADED; Resume(id); } else { - DEBUG("OpenPPT: Get info\n"); + DEBUG(L"OpenPPT: Get info\n"); pptView[id].steps = 0; int steps = 0; while (pptView[id].state == PPT_OPENED) @@ -224,18 +224,18 @@ DllExport int OpenPPT(char *filename, HWND hParentWnd, RECT rect, if (steps <= pptView[id].steps) { Sleep(20); - DEBUG("OpenPPT: Step %d/%d\n", steps, pptView[id].steps); + DEBUG(L"OpenPPT: Step %d/%d\n", steps, pptView[id].steps); steps++; NextStep(id); } Sleep(10); } - DEBUG("OpenPPT: Slides %d, Steps %d, first slide steps %d\n", + DEBUG(L"OpenPPT: Slides %d, Steps %d, first slide steps %d\n", pptView[id].slideCount, pptView[id].steps, pptView[id].firstSlideSteps); for(int i = 1; i <= pptView[id].slideCount; i++) { - DEBUG("OpenPPT: Slide %d = %d\n", i, pptView[id].slideNos[i]); + DEBUG(L"OpenPPT: Slide %d = %d\n", i, pptView[id].slideNos[i]); } SavePPTInfo(id); if (pptView[id].state == PPT_CLOSING @@ -257,7 +257,7 @@ DllExport int OpenPPT(char *filename, HWND hParentWnd, RECT rect, } pptView[id].msgHook = NULL; } - DEBUG("OpenPPT: Exit: id=%i\n", id); + DEBUG(L"OpenPPT: Exit: id=%i\n", id); return id; } // Load information about the ppt from an info.txt file. @@ -270,75 +270,75 @@ DllExport int OpenPPT(char *filename, HWND hParentWnd, RECT rect, BOOL GetPPTInfo(int id) { struct _stat fileStats; - char info[MAX_PATH]; + wchar_t info[MAX_PATH]; FILE* pFile; - char buf[100]; + wchar_t buf[100]; - DEBUG("GetPPTInfo: start\n"); - if (_stat(pptView[id].filename, &fileStats) != 0) + DEBUG(L"GetPPTInfo: start\n"); + if (_wstat(pptView[id].filename, &fileStats) != 0) { return FALSE; } - sprintf_s(info, MAX_PATH, "%sinfo.txt", pptView[id].previewPath); - int err = fopen_s(&pFile, info, "r"); + swprintf_s(info, MAX_PATH, L"%sinfo.txt", pptView[id].previewPath); + int err = _wfopen_s(&pFile, info, L"r"); if (err != 0) { - DEBUG("GetPPTInfo: file open failed - %d\n", err); + DEBUG(L"GetPPTInfo: file open failed - %d\n", err); return FALSE; } - fgets(buf, 100, pFile); // version == 1 - fgets(buf, 100, pFile); - if (fileStats.st_mtime != atoi(buf)) + fgetws(buf, 100, pFile); // version == 1 + fgetws(buf, 100, pFile); + if (fileStats.st_mtime != _wtoi(buf)) { - DEBUG("GetPPTInfo: date changed\n"); + DEBUG(L"GetPPTInfo: date changed\n"); fclose (pFile); return FALSE; } - fgets(buf, 100, pFile); - if (fileStats.st_size != atoi(buf)) + fgetws(buf, 100, pFile); + if (fileStats.st_size != _wtoi(buf)) { - DEBUG("GetPPTInfo: size changed\n"); + DEBUG(L"GetPPTInfo: size changed\n"); fclose (pFile); return FALSE; } - fgets(buf, 100, pFile); // slidecount - int slideCount = atoi(buf); - fgets(buf, 100, pFile); // first slide steps - int firstSlideSteps = atoi(buf); + fgetws(buf, 100, pFile); // slidecount + int slideCount = _wtoi(buf); + fgetws(buf, 100, pFile); // first slide steps + int firstSlideSteps = _wtoi(buf); // check all the preview images still exist for (int i = 1; i <= slideCount; i++) { - sprintf_s(info, MAX_PATH, "%s%i.bmp", pptView[id].previewPath, i); + swprintf_s(info, MAX_PATH, L"%s%i.bmp", pptView[id].previewPath, i); if (GetFileAttributes(info) == INVALID_FILE_ATTRIBUTES) { - DEBUG("GetPPTInfo: bmp not found\n"); + DEBUG(L"GetPPTInfo: bmp not found\n"); return FALSE; } } fclose(pFile); pptView[id].slideCount = slideCount; pptView[id].firstSlideSteps = firstSlideSteps; - DEBUG("GetPPTInfo: exit ok\n"); + DEBUG(L"GetPPTInfo: exit ok\n"); return TRUE; } BOOL SavePPTInfo(int id) { struct _stat fileStats; - char info[MAX_PATH]; + wchar_t info[MAX_PATH]; FILE* pFile; - DEBUG("SavePPTInfo: start\n"); - if (_stat(pptView[id].filename, &fileStats) != 0) + DEBUG(L"SavePPTInfo: start\n"); + if (_wstat(pptView[id].filename, &fileStats) != 0) { - DEBUG("SavePPTInfo: stat of %s failed\n", pptView[id].filename); + DEBUG(L"SavePPTInfo: stat of %s failed\n", pptView[id].filename); return FALSE; } - sprintf_s(info, MAX_PATH, "%sinfo.txt", pptView[id].previewPath); - int err = fopen_s(&pFile, info, "w"); + swprintf_s(info, MAX_PATH, L"%sinfo.txt", pptView[id].previewPath); + int err = _wfopen_s(&pFile, info, L"w"); if (err != 0) { - DEBUG("SavePPTInfo: fopen of %s failed%i\n", info, err); + DEBUG(L"SavePPTInfo: fopen of %s failed%i\n", info, err); return FALSE; } fprintf(pFile, "1\n"); @@ -347,21 +347,21 @@ BOOL SavePPTInfo(int id) fprintf(pFile, "%u\n", pptView[id].slideCount); fprintf(pFile, "%u\n", pptView[id].firstSlideSteps); fclose(pFile); - DEBUG("SavePPTInfo: exit ok\n"); + DEBUG(L"SavePPTInfo: exit ok\n"); return TRUE; } // Get the path of the PowerPoint viewer from the registry -BOOL GetPPTViewerPath(char *pptViewerPath, int stringSize) +BOOL GetPPTViewerPath(wchar_t *pptViewerPath, int stringSize) { - char cwd[MAX_PATH]; + wchar_t cwd[MAX_PATH]; - DEBUG("GetPPTViewerPath: start\n"); + DEBUG(L"GetPPTViewerPath: start\n"); if(GetPPTViewerPathFromReg(pptViewerPath, stringSize)) { - if(_access(pptViewerPath, 0) != -1) + if(_waccess(pptViewerPath, 0) != -1) { - DEBUG("GetPPTViewerPath: exit registry\n"); + DEBUG(L"GetPPTViewerPath: exit registry\n"); return TRUE; } } @@ -370,37 +370,37 @@ BOOL GetPPTViewerPath(char *pptViewerPath, int stringSize) // upset those who like to put things somewhere else // Viewer 2007 in 64bit Windows: - if(_access("C:\\Program Files (x86)\\Microsoft Office\\Office12\\PPTVIEW.EXE", + if(_waccess(L"C:\\Program Files (x86)\\Microsoft Office\\Office12\\PPTVIEW.EXE", 0) != -1) { - strcpy_s( - "C:\\Program Files (x86)\\Microsoft Office\\Office12\\PPTVIEW.EXE", + wcscpy_s( + L"C:\\Program Files (x86)\\Microsoft Office\\Office12\\PPTVIEW.EXE", stringSize, pptViewerPath); - DEBUG("GetPPTViewerPath: exit 64bit 2007\n"); + DEBUG(L"GetPPTViewerPath: exit 64bit 2007\n"); return TRUE; } // Viewer 2007 in 32bit Windows: - if(_access("C:\\Program Files\\Microsoft Office\\Office12\\PPTVIEW.EXE", 0) + if(_waccess(L"C:\\Program Files\\Microsoft Office\\Office12\\PPTVIEW.EXE", 0) != -1) { - strcpy_s("C:\\Program Files\\Microsoft Office\\Office12\\PPTVIEW.EXE", + wcscpy_s(L"C:\\Program Files\\Microsoft Office\\Office12\\PPTVIEW.EXE", stringSize, pptViewerPath); - DEBUG("GetPPTViewerPath: exit 32bit 2007\n"); + DEBUG(L"GetPPTViewerPath: exit 32bit 2007\n"); return TRUE; } // Give them the opportunity to place it in the same folder as the app - _getcwd(cwd, MAX_PATH); - strcat_s(cwd, MAX_PATH, "\\PPTVIEW.EXE"); - if(_access(cwd, 0) != -1) + _wgetcwd(cwd, MAX_PATH); + wcscat_s(cwd, MAX_PATH, L"\\PPTVIEW.EXE"); + if(_waccess(cwd, 0) != -1) { - strcpy_s(pptViewerPath, stringSize, cwd); - DEBUG("GetPPTViewerPath: exit local\n"); + wcscpy_s(pptViewerPath, stringSize, cwd); + DEBUG(L"GetPPTViewerPath: exit local\n"); return TRUE; } - DEBUG("GetPPTViewerPath: exit fail\n"); + DEBUG(L"GetPPTViewerPath: exit fail\n"); return FALSE; } -BOOL GetPPTViewerPathFromReg(char *pptViewerPath, int stringSize) +BOOL GetPPTViewerPathFromReg(wchar_t *pptViewerPath, int stringSize) { HKEY hKey; DWORD dwType, dwSize; @@ -411,17 +411,17 @@ BOOL GetPPTViewerPathFromReg(char *pptViewerPath, int stringSize) // PPT Viewer 2003 (recent versions) // PPT Viewer 2003 (older versions) // PPT Viewer 97 - if ((RegOpenKeyEx(HKEY_CLASSES_ROOT, - "PowerPointViewer.Show.12\\shell\\Show\\command", 0, KEY_READ, &hKey) + if ((RegOpenKeyExW(HKEY_CLASSES_ROOT, + L"PowerPointViewer.Show.12\\shell\\Show\\command", 0, KEY_READ, &hKey) != ERROR_SUCCESS) - && (RegOpenKeyEx(HKEY_CLASSES_ROOT, - "PowerPointViewer.Show.11\\shell\\Show\\command", 0, KEY_READ, &hKey) + && (RegOpenKeyExW(HKEY_CLASSES_ROOT, + L"PowerPointViewer.Show.11\\shell\\Show\\command", 0, KEY_READ, &hKey) != ERROR_SUCCESS) - && (RegOpenKeyEx(HKEY_CLASSES_ROOT, - "Applications\\PPTVIEW.EXE\\shell\\open\\command", 0, KEY_READ, &hKey) + && (RegOpenKeyExW(HKEY_CLASSES_ROOT, + L"Applications\\PPTVIEW.EXE\\shell\\open\\command", 0, KEY_READ, &hKey) != ERROR_SUCCESS) - && (RegOpenKeyEx(HKEY_CLASSES_ROOT, - "Applications\\PPTVIEW.EXE\\shell\\Show\\command", 0, KEY_READ, &hKey) + && (RegOpenKeyExW(HKEY_CLASSES_ROOT, + L"Applications\\PPTVIEW.EXE\\shell\\Show\\command", 0, KEY_READ, &hKey) != ERROR_SUCCESS)) { return FALSE; @@ -436,14 +436,14 @@ BOOL GetPPTViewerPathFromReg(char *pptViewerPath, int stringSize) return FALSE; } // remove "%1" from end of key value - pptViewerPath[strlen(pptViewerPath) - 4] = '\0'; + pptViewerPath[wcslen(pptViewerPath) - 4] = '\0'; return TRUE; } // Unhook the Windows hook void Unhook(int id) { - DEBUG("Unhook: start %d\n", id); + DEBUG(L"Unhook: start %d\n", id); if (pptView[id].hook != NULL) { UnhookWindowsHookEx(pptView[id].hook); @@ -454,13 +454,13 @@ void Unhook(int id) } pptView[id].hook = NULL; pptView[id].msgHook = NULL; - DEBUG("Unhook: exit ok\n"); + DEBUG(L"Unhook: exit ok\n"); } // Close the PowerPoint viewer, release resources DllExport void ClosePPT(int id) { - DEBUG("ClosePPT: start%d\n", id); + DEBUG(L"ClosePPT: start%d\n", id); pptView[id].state = PPT_CLOSED; Unhook(id); if (pptView[id].hWnd == 0) @@ -474,13 +474,13 @@ DllExport void ClosePPT(int id) CloseHandle(pptView[id].hThread); CloseHandle(pptView[id].hProcess); memset(&pptView[id], 0, sizeof(PPTVIEW)); - DEBUG("ClosePPT: exit ok\n"); + DEBUG(L"ClosePPT: exit ok\n"); return; } // Moves the show back onto the display DllExport void Resume(int id) { - DEBUG("Resume: %d\n", id); + DEBUG(L"Resume: %d\n", id); MoveWindow(pptView[id].hWnd, pptView[id].rect.left, pptView[id].rect.top, pptView[id].rect.right - pptView[id].rect.left, @@ -490,7 +490,7 @@ DllExport void Resume(int id) // Moves the show off the screen so it can't be seen DllExport void Stop(int id) { - DEBUG("Stop:%d\n", id); + DEBUG(L"Stop:%d\n", id); MoveWindow(pptView[id].hWnd, -32000, -32000, pptView[id].rect.right - pptView[id].rect.left, pptView[id].rect.bottom - pptView[id].rect.top, TRUE); @@ -499,7 +499,7 @@ DllExport void Stop(int id) // Return the total number of slides DllExport int GetSlideCount(int id) { - DEBUG("GetSlideCount:%d\n", id); + DEBUG(L"GetSlideCount:%d\n", id); if (pptView[id].state == 0) { return -1; @@ -513,7 +513,7 @@ DllExport int GetSlideCount(int id) // Return the number of the slide currently viewing DllExport int GetCurrentSlide(int id) { - DEBUG("GetCurrentSlide:%d\n", id); + DEBUG(L"GetCurrentSlide:%d\n", id); if (pptView[id].state == 0) { return -1; @@ -527,7 +527,7 @@ DllExport int GetCurrentSlide(int id) // Take a step forwards through the show DllExport void NextStep(int id) { - DEBUG("NextStep:%d (%d)\n", id, pptView[id].currentSlide); + DEBUG(L"NextStep:%d (%d)\n", id, pptView[id].currentSlide); if (pptView[id].currentSlide > pptView[id].slideCount) return; if (pptView[id].currentSlide < pptView[id].slideCount) { @@ -540,7 +540,7 @@ DllExport void NextStep(int id) // Take a step backwards through the show DllExport void PrevStep(int id) { - DEBUG("PrevStep:%d (%d)\n", id, pptView[id].currentSlide); + DEBUG(L"PrevStep:%d (%d)\n", id, pptView[id].currentSlide); if (pptView[id].currentSlide > 1) { pptView[id].guess = pptView[id].currentSlide - 1; @@ -556,7 +556,7 @@ DllExport void Blank(int id) // So send random unmapped letter first (say 'A'), then we can // better guarantee B will blank instead of trying to guess // whether it was already blank or not. - DEBUG("Blank:%d\n", id); + DEBUG(L"Blank:%d\n", id); HWND h1 = GetForegroundWindow(); HWND h2 = GetFocus(); SetForegroundWindow(pptView[id].hWnd); @@ -573,7 +573,7 @@ DllExport void Blank(int id) // Unblank the show DllExport void Unblank(int id) { - DEBUG("Unblank:%d\n", id); + DEBUG(L"Unblank:%d\n", id); // Pressing any key resumes. // For some reason SendMessage works for unblanking, but not blanking. SendMessage(pptView[id].hWnd2, WM_CHAR, 'A', 0); @@ -582,7 +582,7 @@ DllExport void Unblank(int id) // Go directly to a slide DllExport void GotoSlide(int id, int slideNo) { - DEBUG("GotoSlide %i %i:\n", id, slideNo); + DEBUG(L"GotoSlide %i %i:\n", id, slideNo); // Did try WM_KEYDOWN/WM_CHAR/WM_KEYUP with SendMessage but didn't work // perhaps I was sending to the wrong window? No idea. // Anyway fall back to keybd_event, which is OK as long we makesure @@ -619,7 +619,7 @@ DllExport void RestartShow(int id) // Only way I've found to get around this is to step backwards all the way // through. Lets move the window out of the way first so the audience // doesn't see this. - DEBUG("RestartShow:%d\n", id); + DEBUG(L"RestartShow:%d\n", id); Stop(id); GotoSlide(id, pptView[id].slideCount); for (int i=0; i <= pptView[id].steps - pptView[id].lastSlideSteps; i++) @@ -644,12 +644,12 @@ LRESULT CALLBACK CbtProc(int nCode, WPARAM wParam, LPARAM lParam) HHOOK hook = globalHook; if (nCode == HCBT_CREATEWND) { - char csClassName[16]; + wchar_t csClassName[32]; HWND hCurrWnd = (HWND)wParam; DWORD retProcId = NULL; GetClassName(hCurrWnd, csClassName, sizeof(csClassName)); - if ((strcmp(csClassName, "paneClassDC") == 0) - ||(strcmp(csClassName, "screenClass") == 0)) + if ((wcscmp(csClassName, L"paneClassDC") == 0) + ||(wcscmp(csClassName, L"screenClass") == 0)) { int id = -1; DWORD windowThread = GetWindowThreadProcessId(hCurrWnd, NULL); @@ -663,7 +663,7 @@ LRESULT CALLBACK CbtProc(int nCode, WPARAM wParam, LPARAM lParam) } if (id >= 0) { - if (strcmp(csClassName, "paneClassDC") == 0) + if (wcscmp(csClassName, L"paneClassDC") == 0) { pptView[id].hWnd2 = hCurrWnd; } @@ -737,7 +737,7 @@ LRESULT CALLBACK CwpProc(int nCode, WPARAM wParam, LPARAM lParam){ CWPSTRUCT *cwp; cwp = (CWPSTRUCT *)lParam; HHOOK hook = NULL; - char filename[MAX_PATH]; + wchar_t filename[MAX_PATH]; DWORD windowThread = GetWindowThreadProcessId(cwp->hwnd, NULL); int id = -1; @@ -758,9 +758,9 @@ LRESULT CALLBACK CwpProc(int nCode, WPARAM wParam, LPARAM lParam){ { if ((pptView[id].currentSlide > 0) && (pptView[id].previewPath != NULL - && strlen(pptView[id].previewPath) > 0)) + && wcslen(pptView[id].previewPath) > 0)) { - sprintf_s(filename, MAX_PATH, "%s%i.bmp", + swprintf_s(filename, MAX_PATH, L"%s%i.bmp", pptView[id].previewPath, pptView[id].currentSlide); CaptureAndSaveWindow(cwp->hwnd, filename); @@ -820,7 +820,7 @@ LRESULT CALLBACK CwpProc(int nCode, WPARAM wParam, LPARAM lParam){ return CallNextHookEx(hook, nCode, wParam, lParam); } -VOID CaptureAndSaveWindow(HWND hWnd, CHAR* filename) +VOID CaptureAndSaveWindow(HWND hWnd, wchar_t* filename) { HBITMAP hBmp; if ((hBmp = CaptureWindow(hWnd)) == NULL) @@ -863,7 +863,7 @@ VOID CaptureAndSaveWindow(HWND hWnd, CHAR* filename) // Writing: FILE* pFile; - int err = fopen_s(&pFile, filename, "wb"); + int err = _wfopen_s(&pFile, filename, L"wb"); if (err == 0) { fwrite(&bmf, sizeof(bmf), 1, pFile); @@ -893,7 +893,7 @@ HBITMAP CaptureWindow(HWND hWnd) if ((hMemDC = CreateCompatibleDC(hDC)) != NULL) { hDCBmp = (HBITMAP)SelectObject(hMemDC, hImage); - HMODULE hLib = LoadLibrary("User32"); + HMODULE hLib = LoadLibrary(L"User32"); // PrintWindow works for windows outside displayable area // but was only introduced in WinXP. BitBlt requires the window to // be topmost and within the viewable area of the display diff --git a/openlp/plugins/presentations/lib/pptviewlib/pptviewlib.h b/openlp/plugins/presentations/lib/pptviewlib/pptviewlib.h index 65f3b9b69..ce7e4e4dc 100644 --- a/openlp/plugins/presentations/lib/pptviewlib/pptviewlib.h +++ b/openlp/plugins/presentations/lib/pptviewlib/pptviewlib.h @@ -26,13 +26,13 @@ #define DllExport extern "C" __declspec( dllexport ) -#define DEBUG(...) if (debug) printf(__VA_ARGS__) +#define DEBUG(...) if (debug) wprintf(__VA_ARGS__) enum PPTVIEWSTATE {PPT_CLOSED, PPT_STARTED, PPT_OPENED, PPT_LOADED, PPT_CLOSING}; -DllExport int OpenPPT(char *filename, HWND hParentWnd, RECT rect, - char *previewPath); +DllExport int OpenPPT(wchar_t *filename, HWND hParentWnd, RECT rect, + wchar_t *previewPath); DllExport BOOL CheckInstalled(); DllExport void ClosePPT(int id); DllExport int GetCurrentSlide(int id); @@ -50,11 +50,11 @@ DllExport void SetDebug(BOOL onOff); LRESULT CALLBACK CbtProc(int nCode, WPARAM wParam, LPARAM lParam); LRESULT CALLBACK CwpProc(int nCode, WPARAM wParam, LPARAM lParam); LRESULT CALLBACK GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam); -BOOL GetPPTViewerPath(char *pptViewerPath, int stringSize); -BOOL GetPPTViewerPathFromReg(char *pptViewerPath, int stringSize); +BOOL GetPPTViewerPath(wchar_t *pptViewerPath, int stringSize); +BOOL GetPPTViewerPathFromReg(wchar_t *pptViewerPath, int stringSize); HBITMAP CaptureWindow(HWND hWnd); -VOID SaveBitmap(CHAR* filename, HBITMAP hBmp) ; -VOID CaptureAndSaveWindow(HWND hWnd, CHAR* filename); +VOID SaveBitmap(wchar_t* filename, HBITMAP hBmp) ; +VOID CaptureAndSaveWindow(HWND hWnd, wchar_t* filename); BOOL GetPPTInfo(int id); BOOL SavePPTInfo(int id); void Unhook(int id); @@ -80,8 +80,8 @@ struct PPTVIEW int lastSlideSteps; int steps; int guess; - char filename[MAX_PATH]; - char previewPath[MAX_PATH]; + wchar_t filename[MAX_PATH]; + wchar_t previewPath[MAX_PATH]; int slideNos[MAX_SLIDES]; PPTVIEWSTATE state; }; diff --git a/openlp/plugins/presentations/lib/pptviewlib/pptviewlib.vcproj b/openlp/plugins/presentations/lib/pptviewlib/pptviewlib.vcproj index f20db6c8f..dd1b0b505 100644 --- a/openlp/plugins/presentations/lib/pptviewlib/pptviewlib.vcproj +++ b/openlp/plugins/presentations/lib/pptviewlib/pptviewlib.vcproj @@ -18,10 +18,10 @@ Date: Sun, 20 Oct 2013 21:49:39 +0100 Subject: [PATCH 03/13] Fixed up pptviewcontroller to work with the unicode changes to the c library --- openlp/plugins/presentations/lib/pptviewcontroller.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/openlp/plugins/presentations/lib/pptviewcontroller.py b/openlp/plugins/presentations/lib/pptviewcontroller.py index 34f5129b8..9f39419e4 100644 --- a/openlp/plugins/presentations/lib/pptviewcontroller.py +++ b/openlp/plugins/presentations/lib/pptviewcontroller.py @@ -27,8 +27,8 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### -import os import logging +import os if os.name == 'nt': from ctypes import cdll @@ -123,10 +123,14 @@ class PptviewDocument(PresentationDocument): log.debug('LoadPresentation') size = ScreenList().current['size'] rect = RECT(size.x(), size.y(), size.right(), size.bottom()) - filepath = str(self.filepath.replace('/', '\\')) + file_path = os.path.normpath(self.filepath) + preview_path = os.path.join(self.get_temp_folder(), 'slide') + # Ensure that the paths are null terminated + file_path = file_path.encode('utf-16-le') + b'\0' + preview_path = preview_path.encode('utf-16-le') + b'\0' if not os.path.isdir(self.get_temp_folder()): os.makedirs(self.get_temp_folder()) - self.ppt_id = self.controller.process.OpenPPT(filepath, None, rect, str(self.get_temp_folder()) + '\\slide') + self.ppt_id = self.controller.process.OpenPPT(file_path, None, rect, preview_path) if self.ppt_id >= 0: self.create_thumbnails() self.stop_presentation() From f374c58d390c77864125bf86677a53b5d60ad493 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Mon, 28 Oct 2013 21:15:16 +0000 Subject: [PATCH 04/13] Tidying up some uneeded str() --- openlp/plugins/presentations/lib/mediaitem.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index f1d0f1110..e669e17b0 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -161,7 +161,7 @@ class PresentationMediaItem(MediaManagerItem): self.main_window.increment_progress_bar() if current_list.count(file) > 0: continue - filename = os.path.split(str(file))[1] + filename = os.path.split(file)[1] if not os.path.exists(file): item_name = QtGui.QListWidgetItem(filename) item_name.setIcon(build_icon(ERROR_IMAGE)) @@ -179,7 +179,7 @@ class PresentationMediaItem(MediaManagerItem): controller_name = self.findControllerByType(filename) if controller_name: controller = self.controllers[controller_name] - doc = controller.add_document(str(file)) + doc = controller.add_document(file) thumb = os.path.join(doc.get_thumbnail_folder(), 'icon.png') preview = doc.get_thumbnail_path(1, True) if not preview and not initial_load: From a69b2d86ef4de193091d1bab6bcb0eb970aa0366 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Mon, 28 Oct 2013 21:23:17 +0000 Subject: [PATCH 05/13] More uneeded str's --- openlp/core/lib/__init__.py | 4 ++-- openlp/core/lib/mediamanageritem.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index bc427830e..1bec55743 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -217,9 +217,9 @@ def create_thumb(image_path, thumb_path, return_icon=True, size=None): if not return_icon: return if os.path.exists(thumb_path): - return build_icon(str(thumb_path)) + return build_icon(thumb_path) # Fallback for files with animation support. - return build_icon(str(image_path)) + return build_icon(image_path) def validate_thumb(file_path, thumb_path): diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index 9e7eb8d73..c086c7494 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -372,7 +372,7 @@ class MediaManagerItem(QtGui.QWidget): if target_group is None: self.list_view.clear() self.load_list(full_list, target_group) - last_dir = os.path.split(str(files[0]))[0] + last_dir = os.path.split(files[0])[0] Settings().setValue(self.settings_section + '/last directory', last_dir) Settings().setValue('%s/%s files' % (self.settings_section, self.settings_section), self.get_file_list()) if duplicates_found: From 4345608759b628dd3d6f65dce59fbe43497c9760 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Fri, 1 Nov 2013 19:30:26 +0000 Subject: [PATCH 06/13] fixed issue with not all PPTS not loading correctly using PPTViewer --- openlp/plugins/presentations/lib/pptviewlib/pptviewlib.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/plugins/presentations/lib/pptviewlib/pptviewlib.cpp b/openlp/plugins/presentations/lib/pptviewlib/pptviewlib.cpp index a4ee5053c..ac51f1155 100644 --- a/openlp/plugins/presentations/lib/pptviewlib/pptviewlib.cpp +++ b/openlp/plugins/presentations/lib/pptviewlib/pptviewlib.cpp @@ -223,7 +223,7 @@ DllExport int OpenPPT(wchar_t *filename, HWND hParentWnd, RECT rect, { if (steps <= pptView[id].steps) { - Sleep(20); + Sleep(100); DEBUG(L"OpenPPT: Step %d/%d\n", steps, pptView[id].steps); steps++; NextStep(id); From 2535bda1bb4d44b74399d75a807a7e6cdb69db90 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Thu, 7 Nov 2013 20:33:55 +0000 Subject: [PATCH 07/13] Added tests for load presentation --- .../presentations/test_pptviewcontroller.py | 141 ++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 tests/functional/openlp_plugins/presentations/test_pptviewcontroller.py diff --git a/tests/functional/openlp_plugins/presentations/test_pptviewcontroller.py b/tests/functional/openlp_plugins/presentations/test_pptviewcontroller.py new file mode 100644 index 000000000..2492488e5 --- /dev/null +++ b/tests/functional/openlp_plugins/presentations/test_pptviewcontroller.py @@ -0,0 +1,141 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2013 Raoul Snyman # +# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # +# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # +# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # +# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # +# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # +# --------------------------------------------------------------------------- # +# This program is free software; you can redistribute it and/or modify it # +# under the terms of the GNU General Public License as published by the Free # +# Software Foundation; version 2 of the License. # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT # +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # +# more details. # +# # +# You should have received a copy of the GNU General Public License along # +# with this program; if not, write to the Free Software Foundation, Inc., 59 # +# Temple Place, Suite 330, Boston, MA 02111-1307 USA # +############################################################################### +""" +This module contains tests for the pptviewcontroller module of the Presentations plugin. +""" +from unittest import TestCase +from mock import MagicMock, patch + +from openlp.plugins.presentations.lib.pptviewcontroller import PptviewDocument + +#TODO: Items left to test +# PptviewController +# __init__ +# check_availablecheck_installed +# start_process(self) +# kill + +class TestPptviewDocument(TestCase): + """ + Test the PptviewDocument Class + """ + #TODO: Items left to test + # PptviewDocument + # __init__ + # create_thumbnails + # close_presentation + # is_loaded + # is_active + # blank_screen + # unblank_screen + # is_blank + # stop_presentation + # start_presentation + # get_slide_number + # get_slide_count + # goto_slide + # next_step + # previous_step + + def setUp(self): + """ + Set up the patches and mocks need for all tests. + """ + self.os_patcher = patch('openlp.plugins.presentations.lib.pptviewcontroller.os') + self.pptview_document_create_thumbnails_patcher = patch( + 'openlp.plugins.presentations.lib.pptviewcontroller.PptviewDocument.create_thumbnails') + self.pptview_document_stop_presentation_patcher = patch( + 'openlp.plugins.presentations.lib.pptviewcontroller.PptviewDocument.stop_presentation') + self.presentation_document_get_temp_folder_patcher = patch( + 'openlp.plugins.presentations.lib.pptviewcontroller.PresentationDocument.get_temp_folder') + self.presentation_document_setup_patcher = patch( + 'openlp.plugins.presentations.lib.pptviewcontroller.PresentationDocument._setup') + self.rect_patcher = patch('openlp.plugins.presentations.lib.pptviewcontroller.RECT') + self.screen_list_patcher = patch('openlp.plugins.presentations.lib.pptviewcontroller.ScreenList') + + self.mock_os = self.os_patcher.start() + self.mock_pptview_document_create_thumbnails = self.pptview_document_create_thumbnails_patcher.start() + self.mock_pptview_document_stop_presentation = self.pptview_document_stop_presentation_patcher.start() + self.mock_presentation_document_get_temp_folder = self.presentation_document_get_temp_folder_patcher.start() + self.mock_presentation_document_setup = self.presentation_document_setup_patcher.start() + self.mock_rect = self.rect_patcher.start() + self.mock_screen_list = self.screen_list_patcher.start() + + self.mock_controller = MagicMock() + self.mock_presentation = MagicMock() + + self.mock_presentation_document_get_temp_folder.return_value = 'temp folder' + + def tearDown(self): + """ + Stop the patches + """ + self.os_patcher.stop() + self.pptview_document_create_thumbnails_patcher.stop() + self.pptview_document_stop_presentation_patcher.stop() + self.presentation_document_get_temp_folder_patcher.stop() + self.presentation_document_setup_patcher.stop() + self.rect_patcher.stop() + self.screen_list_patcher.stop() + + def oload_presentation_succesfull_test(self): + """ + Test the PptviewDocument.load_presentation() method when the PPT is successfully opened + """ + # GIVEN: A reset mocked_os + self.mock_os.reset() + + # WHEN: The temporary directory exists and OpenPPT returns successfully (not -1) + self.mock_os.path.isdir.return_value = True + self.mock_controller.process.OpenPPT.return_value = 0 + instance = PptviewDocument(self.mock_controller, self.mock_presentation) + instance.filepath = 'test\path.ppt' + result = instance.load_presentation() + + # THEN: PptviewDocument.load_presentation should return True + self.assertTrue(result) + + def load_presentation_unsuccesfull_test(self): + """ + Test the PptviewDocument.load_presentation() method when the temporary directory does not exist and the PPT is + not successfully opened + """ + # GIVEN: A reset mocked_os + self.mock_os.reset() + + # WHEN: The temporary directory does not exist and OpenPPT returns unsuccessfully (-1) + self.mock_os.path.isdir.return_value = False + self.mock_controller.process.OpenPPT.return_value = -1 + instance = PptviewDocument(self.mock_controller, self.mock_presentation) + instance.filepath = 'xyc' + result = instance.load_presentation() + + # THEN: The temporary directory should be created and PptviewDocument.load_presentation should return False + self.mock_os.makedirs.assert_called_once_with('temp folder') + self.assertFalse(result) From 61da0e8ad956708c5c89b1a8fc082a7f3d7613f7 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Thu, 7 Nov 2013 20:35:02 +0000 Subject: [PATCH 08/13] Some refactoring --- .bzrignore | 1 + openlp/plugins/presentations/lib/pptviewcontroller.py | 7 ++++--- .../plugins/presentations/lib/pptviewlib/pptviewlib.cpp | 4 ++-- .../plugins/presentations/lib/presentationcontroller.py | 8 +++++++- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.bzrignore b/.bzrignore index d87c55a61..f149d97a7 100644 --- a/.bzrignore +++ b/.bzrignore @@ -28,3 +28,4 @@ tests.kdev4 *.nja *.orig __pycache__ +*.dll diff --git a/openlp/plugins/presentations/lib/pptviewcontroller.py b/openlp/plugins/presentations/lib/pptviewcontroller.py index 9f39419e4..9c9f81028 100644 --- a/openlp/plugins/presentations/lib/pptviewcontroller.py +++ b/openlp/plugins/presentations/lib/pptviewcontroller.py @@ -121,15 +121,16 @@ class PptviewDocument(PresentationDocument): the background PptView task started earlier. """ log.debug('LoadPresentation') + temp_folder = self.get_temp_folder() size = ScreenList().current['size'] rect = RECT(size.x(), size.y(), size.right(), size.bottom()) file_path = os.path.normpath(self.filepath) - preview_path = os.path.join(self.get_temp_folder(), 'slide') + preview_path = os.path.join(temp_folder, 'slide') # Ensure that the paths are null terminated file_path = file_path.encode('utf-16-le') + b'\0' preview_path = preview_path.encode('utf-16-le') + b'\0' - if not os.path.isdir(self.get_temp_folder()): - os.makedirs(self.get_temp_folder()) + if not os.path.isdir(temp_folder): + os.makedirs(temp_folder) self.ppt_id = self.controller.process.OpenPPT(file_path, None, rect, preview_path) if self.ppt_id >= 0: self.create_thumbnails() diff --git a/openlp/plugins/presentations/lib/pptviewlib/pptviewlib.cpp b/openlp/plugins/presentations/lib/pptviewlib/pptviewlib.cpp index ac51f1155..8b0df45ec 100644 --- a/openlp/plugins/presentations/lib/pptviewlib/pptviewlib.cpp +++ b/openlp/plugins/presentations/lib/pptviewlib/pptviewlib.cpp @@ -223,12 +223,12 @@ DllExport int OpenPPT(wchar_t *filename, HWND hParentWnd, RECT rect, { if (steps <= pptView[id].steps) { - Sleep(100); + Sleep(25); DEBUG(L"OpenPPT: Step %d/%d\n", steps, pptView[id].steps); steps++; NextStep(id); } - Sleep(10); + Sleep(75); } DEBUG(L"OpenPPT: Slides %d, Steps %d, first slide steps %d\n", pptView[id].slideCount, pptView[id].steps, diff --git a/openlp/plugins/presentations/lib/presentationcontroller.py b/openlp/plugins/presentations/lib/presentationcontroller.py index 17911606c..03efa989f 100644 --- a/openlp/plugins/presentations/lib/presentationcontroller.py +++ b/openlp/plugins/presentations/lib/presentationcontroller.py @@ -96,8 +96,14 @@ class PresentationDocument(object): """ Constructor for the PresentationController class """ - self.slidenumber = 0 self.controller = controller + self._setup(name) + + def _setup(self, name): + """ + Run some initial setup. This method is separate from __init__ in order to mock it out in tests. + """ + self.slidenumber = 0 self.filepath = name check_directory_exists(self.get_thumbnail_folder()) From 47292d3ec78839b36874b060851192dee02f03d1 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Thu, 7 Nov 2013 20:42:21 +0000 Subject: [PATCH 09/13] Changed test path --- .../openlp_plugins/presentations/test_pptviewcontroller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/openlp_plugins/presentations/test_pptviewcontroller.py b/tests/functional/openlp_plugins/presentations/test_pptviewcontroller.py index 2492488e5..338f7825c 100644 --- a/tests/functional/openlp_plugins/presentations/test_pptviewcontroller.py +++ b/tests/functional/openlp_plugins/presentations/test_pptviewcontroller.py @@ -133,7 +133,7 @@ class TestPptviewDocument(TestCase): self.mock_os.path.isdir.return_value = False self.mock_controller.process.OpenPPT.return_value = -1 instance = PptviewDocument(self.mock_controller, self.mock_presentation) - instance.filepath = 'xyc' + instance.filepath = 'test\path.ppt' result = instance.load_presentation() # THEN: The temporary directory should be created and PptviewDocument.load_presentation should return False From cc3cdf71269a20ed1e2418af1829002d76a31d30 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Sat, 16 Nov 2013 10:05:41 +0000 Subject: [PATCH 10/13] added some tests for PresentationController --- .../lib/pptviewlib/pptviewlib.cpp | 4 +- .../presentations/test_pptviewcontroller.py | 4 +- .../test_presentationcontroller.py | 138 ++++++++++++++++++ 3 files changed, 142 insertions(+), 4 deletions(-) create mode 100644 tests/functional/openlp_plugins/presentations/test_presentationcontroller.py diff --git a/openlp/plugins/presentations/lib/pptviewlib/pptviewlib.cpp b/openlp/plugins/presentations/lib/pptviewlib/pptviewlib.cpp index 8b0df45ec..ac51f1155 100644 --- a/openlp/plugins/presentations/lib/pptviewlib/pptviewlib.cpp +++ b/openlp/plugins/presentations/lib/pptviewlib/pptviewlib.cpp @@ -223,12 +223,12 @@ DllExport int OpenPPT(wchar_t *filename, HWND hParentWnd, RECT rect, { if (steps <= pptView[id].steps) { - Sleep(25); + Sleep(100); DEBUG(L"OpenPPT: Step %d/%d\n", steps, pptView[id].steps); steps++; NextStep(id); } - Sleep(75); + Sleep(10); } DEBUG(L"OpenPPT: Slides %d, Steps %d, first slide steps %d\n", pptView[id].slideCount, pptView[id].steps, diff --git a/tests/functional/openlp_plugins/presentations/test_pptviewcontroller.py b/tests/functional/openlp_plugins/presentations/test_pptviewcontroller.py index 338f7825c..d2d8bb5bd 100644 --- a/tests/functional/openlp_plugins/presentations/test_pptviewcontroller.py +++ b/tests/functional/openlp_plugins/presentations/test_pptviewcontroller.py @@ -29,8 +29,8 @@ """ This module contains tests for the pptviewcontroller module of the Presentations plugin. """ -from unittest import TestCase from mock import MagicMock, patch +from unittest import TestCase from openlp.plugins.presentations.lib.pptviewcontroller import PptviewDocument @@ -104,7 +104,7 @@ class TestPptviewDocument(TestCase): self.rect_patcher.stop() self.screen_list_patcher.stop() - def oload_presentation_succesfull_test(self): + def load_presentation_succesfull_test(self): """ Test the PptviewDocument.load_presentation() method when the PPT is successfully opened """ diff --git a/tests/functional/openlp_plugins/presentations/test_presentationcontroller.py b/tests/functional/openlp_plugins/presentations/test_presentationcontroller.py new file mode 100644 index 000000000..8ebf52c09 --- /dev/null +++ b/tests/functional/openlp_plugins/presentations/test_presentationcontroller.py @@ -0,0 +1,138 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2013 Raoul Snyman # +# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # +# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # +# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # +# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # +# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # +# --------------------------------------------------------------------------- # +# This program is free software; you can redistribute it and/or modify it # +# under the terms of the GNU General Public License as published by the Free # +# Software Foundation; version 2 of the License. # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT # +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # +# more details. # +# # +# You should have received a copy of the GNU General Public License along # +# with this program; if not, write to the Free Software Foundation, Inc., 59 # +# Temple Place, Suite 330, Boston, MA 02111-1307 USA # +############################################################################### +""" +This module contains tests for the pptviewcontroller module of the Presentations plugin. +""" +from mock import MagicMock, patch +from unittest import TestCase + +from openlp.plugins.presentations.lib.presentationcontroller import PresentationDocument + +# TODO: Items left to test +# PresentationController +# __init__ +# enabled +# is_available +# check_available +# start_process +# kill +# add_document +# remove_doc +# close_presentation +# _get_plugin_manager + + +class TestPptviewDocument(TestCase): + """ + Test the PptviewDocument Class + """ + # TODO: Items left to test + # PresentationDocument + # __init__ + # load_presentation + # presentation_deleted + # get_file_name + # get_thumbnail_folder + # get_temp_folder + # check_thumbnails + # close_presentation + # is_active + # is_loaded + # blank_screen + # unblank_screen + # is_blank + # stop_presentation + # start_presentation + # get_slide_number + # get_slide_count + # goto_slide + # next_step + # previous_step + # convert_thumbnail + # get_thumbnail_path + # poll_slidenumber + # get_slide_text + # get_slide_notes + + def setUp(self): + """ + Set up the patches and mocks need for all tests. + """ + self.check_directory_exists_patcher = patch( + 'openlp.plugins.presentations.lib.presentationcontroller.check_directory_exists') + self.get_thumbnail_folder_patcher = patch( + 'openlp.plugins.presentations.lib.presentationcontroller.PresentationDocument.get_thumbnail_folder') + self._setup_patcher = patch( + 'openlp.plugins.presentations.lib.presentationcontroller.PresentationDocument._setup') + + self.mock_check_directory_exists = self.check_directory_exists_patcher.start() + self.mock_get_thumbnail_folder = self.get_thumbnail_folder_patcher.start() + self.mock_setup = self._setup_patcher.start() + + self.mock_controller = MagicMock() + + self.mock_get_thumbnail_folder.return_value = 'returned/path/' + + + def tearDown(self): + """ + Stop the patches + """ + self.check_directory_exists_patcher.stop() + self.get_thumbnail_folder_patcher.stop() + self._setup_patcher.stop() + + def initalise_presentation_document_test(self): + """ + Test the PresentationDocument __init__ method when initalising the PresentationDocument Class + """ + # GIVEN: A reset mock_setup and mocked controller + self.mock_setup.reset() + + # WHEN: Creating an instance of PresentationDocument + instance = PresentationDocument(self.mock_controller, 'Name') + + # THEN: PresentationDocument.__init__ should have been called with the correct arguments + self.mock_setup.assert_called_once_with('Name') + + def presentation_document_setup_test(self): + """ + Test the PresentationDocument _setup method when initalising the PresentationDocument Class + """ + self._setup_patcher.stop() + + # GIVEN: A mocked controller, patched check_directory_exists_patcher and patched get_thumbnail_folder method + + # WHEN: Creating an instance of PresentationDocument + instance = PresentationDocument(self.mock_controller, 'Name') + + # THEN: check_directory_exists should have been called with the correct arguments + self.mock_check_directory_exists.assert_called_once_with('returned/path/') + + self._setup_patcher.start() From 20ae5d13b008c004e550a8aefd26ae0b54fad8f0 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Sat, 16 Nov 2013 10:16:06 +0000 Subject: [PATCH 11/13] some final cleanups --- .../plugins/presentations/lib/pptviewlib/pptviewlib.vcproj | 2 +- .../openlp_plugins/presentations/test_pptviewcontroller.py | 4 +++- .../presentations/test_presentationcontroller.py | 7 ++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/openlp/plugins/presentations/lib/pptviewlib/pptviewlib.vcproj b/openlp/plugins/presentations/lib/pptviewlib/pptviewlib.vcproj index dd1b0b505..d2843e510 100644 --- a/openlp/plugins/presentations/lib/pptviewlib/pptviewlib.vcproj +++ b/openlp/plugins/presentations/lib/pptviewlib/pptviewlib.vcproj @@ -18,7 +18,7 @@ Date: Sat, 16 Nov 2013 10:54:24 +0000 Subject: [PATCH 12/13] Fix doc strings --- .../presentations/test_presentationcontroller.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/functional/openlp_plugins/presentations/test_presentationcontroller.py b/tests/functional/openlp_plugins/presentations/test_presentationcontroller.py index 3ea949b80..e836bd756 100644 --- a/tests/functional/openlp_plugins/presentations/test_presentationcontroller.py +++ b/tests/functional/openlp_plugins/presentations/test_presentationcontroller.py @@ -50,9 +50,9 @@ from openlp.plugins.presentations.lib.presentationcontroller import Presentation # _get_plugin_manager -class TestPptviewDocument(TestCase): +class TestPresentationDocument(TestCase): """ - Test the PptviewDocument Class + Test the PresentationDocument Class """ # TODO: Items left to test # PresentationDocument From b718b76c8c0e7d42a3e184abab1e71ecf30f8567 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Tue, 11 Feb 2014 21:07:06 +0000 Subject: [PATCH 13/13] HEAD --- .../openlp_plugins/presentations/test_presentationcontroller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/openlp_plugins/presentations/test_presentationcontroller.py b/tests/functional/openlp_plugins/presentations/test_presentationcontroller.py index 1feb0c473..151fc5495 100644 --- a/tests/functional/openlp_plugins/presentations/test_presentationcontroller.py +++ b/tests/functional/openlp_plugins/presentations/test_presentationcontroller.py @@ -51,7 +51,7 @@ class TestPresentationController(TestCase): # close_presentation # _get_plugin_manager - def constructor_tvest(self): + def constructor_test(self): """ Test the Constructor """