/**************************************************************************************
* *
* This application contains code from OpenDivX and is released as a "Larger Work" *
* under that license. Consistant with that license, this application is released *
* under the GNU General Public License. *
* *
* The OpenDivX license can be found at: http://www.projectmayo.com/opendivx/docs.php *
* The GPL can be found at: http://www.gnu.org/copyleft/gpl.html *
* *
* Copyright (c) 2001 - Project Mayo *
* *
* Authors: Damien Chavarria <adrc at projectmayo.com> *
* *
**************************************************************************************/
#include "debug.h"
#include "Skin.h"
#include "Playback.h"
#include "Playlist.h"
#include "DirDialog.h"
#include "SkinList.h"
#include "Resizer.h"
#ifdef WIN32
#include "../build/win32/ressources.h"
#include "../build/win32/resource.h"
#endif
#include <math.h>
#include <commctrl.h>
#include <windows.h>
#include <windowsx.h>
/*
* Intervals for the timers
*/
#define TIMER_ID 1
#define TIMER_RATE 100
/*
* Variables
*
* Please regroup that in a struct...
*
*
*/
DWORD anonymous;
HWND hwndDisplay;
#ifdef _DEBUG__
FILE *debug_file;
#endif
int action = ACTION_NONE;
DWORD count = 0;
DWORD use_subtitles = 1;
DWORD no_resize = 0;
char skinPath[256];
UINT uTimerID;
RECT clientRect;
RECT windowRect, fullwindowRect;
int moveX = 0, moveY = 0;
Skin *skin;
Playback *playback;
Playlist *playlist;
CDirDialog *dirChooser;
SkinList *skinList;
Resizer *resizer;
char Name[] = "The \"Playa\"";
char *RecentFiles[5];
HWND hwnd, about, urlW = NULL;
HMENU popupMenu;
HACCEL hAccel;
POINT pt2;
POINT oldPt;
HINSTANCE hInstance;
int showing_cursor;
options_t options, tmpOptions;
/*
* needed definitions
*/
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
void OpenFileForPlaying(HWND hwnd, char *filename, int type);
/*
* Save and load options
*/
void LoadOptions() {
HKEY key;
DWORD created, size;
LONG result;
DWORD type, i;
char file[256], name[5];
/*
* Put the default options
*
*/
options.change_fullscreen_res = 0;
options.loop = 1;
options.maintain_aspect_ratio = 1;
options.on_top = 1;
options.use_bilinear = 0;
/*
* Init the recent file list
*/
for(i=0; i < 5; i++) {
RecentFiles[i] = NULL;
}
/*
* Open the registry key
*/
result = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\DivXNetworks\\ThePlaya",
0, "CONFIG", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
NULL, &key, &created);
if(result != ERROR_SUCCESS) {
MessageBox(NULL, "Couldn't load options", "", MB_OK);
return;
}
switch(created) {
case REG_CREATED_NEW_KEY:
/*
* First time launch (we keep the default)
*
*/
break;
case REG_OPENED_EXISTING_KEY:
/*
* We can read the values
*/
size = 4;
result = RegQueryValueEx(key, "UseBilinear", 0, &type, (BYTE *)&options.use_bilinear, &size);
size = 4;
result = RegQueryValueEx(key, "MaintainAspectRatio", 0, &type, (BYTE *)&options.maintain_aspect_ratio, &size);
size = 4;
result = RegQueryValueEx(key, "ChangeFullscreenRes", 0, &type, (BYTE *)&options.change_fullscreen_res, &size);
size = 4;
result = RegQueryValueEx(key, "UseSubtitles", 0, &type, (BYTE *)&use_subtitles, &size);
size = 4;
result = RegQueryValueEx(key, "Loop", 0, &type, (BYTE *)&options.loop, &size);
size = 4;
result = RegQueryValueEx(key, "OnTop", 0, &type, (BYTE *)&options.on_top, &size);
size = 256;
result = RegQueryValueEx(key, "SkinPath", 0, &type, (BYTE *)skinPath, &size);
/*
* And the recent files
*/
for(i=0; i < 5; i++) {
sprintf(name, "File%d", i+1);
size = 256;
result = RegQueryValueEx(key, name, 0, &type, (BYTE *)&file, &size);
if(result == ERROR_SUCCESS) {
RecentFiles[i] = (char *) malloc(size);
strncpy(RecentFiles[i], file, size);
}
}
break;
default:
break;
}
RegCloseKey(key);
}
void SaveOptions() {
HKEY key;
LONG result;
DWORD created, i;
char name[5];
/*
* Try to open the registry key
*/
result = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\DivXNetworks\\ThePlaya",
0, "CONFIG", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
NULL, &key, &created);
if(result != ERROR_SUCCESS) {
MessageBox(NULL, "Couldn't save options", "", MB_OK);
RegCloseKey(key);
return;
}
RegSetValueEx(key, "UseBilinear", 0, REG_DWORD, (BYTE *) &options.use_bilinear, 4);
RegSetValueEx(key, "MaintainAspectRatio", 0, REG_DWORD, (BYTE *) &options.maintain_aspect_ratio, 4);
RegSetValueEx(key, "ChangeFullscreenRes", 0, REG_DWORD, (BYTE *) &options.change_fullscreen_res, 4);
RegSetValueEx(key, "UseSubtitles", 0, REG_DWORD, (BYTE *) &use_subtitles, 4);
RegSetValueEx(key, "Loop", 0, REG_DWORD, (BYTE *) &options.loop, 4);
RegSetValueEx(key, "OnTop", 0, REG_DWORD, (BYTE *) &options.on_top, 4);
if(strcmp(skinPath, "Default") != 0)
RegSetValueEx(key, "SkinPath", 0, REG_SZ, (BYTE *) skinPath, strlen(skinPath));
else
RegSetValueEx(key, "SkinPath", 0, REG_SZ, (BYTE *) "Default", strlen("Default"));
/*
* The recent file list
*/
for(i=0; i < 5; i++) {
if(RecentFiles[i] != NULL) {
sprintf(name, "File%d\0", i+1);
RegSetValueEx(key, name, 0, REG_SZ,
(BYTE *) RecentFiles[i], strlen(RecentFiles[i]));
}
}
RegCloseKey(key);
}
void Cleanup()
{
DWORD i;
for(i=0; i < 5; i++) {
if(RecentFiles[i] != NULL) {
free(RecentFiles[i]);
}
}
DestroyMenu(popupMenu);
delete playback;
delete skinList;
delete resizer;
delete playlist;
}
/*******************************************************************************************/
static BOOL APIENTRY PreferencesGeneralDlgProc( HWND hDlg, UINT message, UINT wParam, LONG lParam) {
switch(message) {
case WM_INITDIALOG:
SetWindowPos(hDlg, HWND_TOP, 15, 35, 0, 0, SWP_NOSIZE);
CheckDlgButton(hDlg, IDC_CHECK_LOOP, tmpOptions.loop);
CheckDlgButton(hDlg, IDC_CHECK_ON_TOP, tmpOptions.on_top);
return TRUE;
case WM_COMMAND:
switch (wParam)
{
case IDC_CHECK_LOOP:
tmpOptions.loop = tmpOptions.loop ? 0 : 1;
break;
case IDC_CHECK_ON_TOP:
tmpOptions.on_top = tmpOptions.on_top ? 0 : 1;
break;
}
case WM_DESTROY:
return TRUE;
}
return FALSE;
}
static BOOL APIENTRY PreferencesVideoDlgProc( HWND hDlg, UINT message, UINT wParam, LONG lParam) {
switch(message) {
case WM_INITDIALOG:
SetWindowPos(hDlg, HWND_TOP, 15, 35, 0, 0, SWP_NOSIZE);
CheckDlgButton(hDlg, IDC_CHECK_MAINTAIN, tmpOptions.maintain_aspect_ratio);
CheckDlgButton(hDlg, IDC_CHECK_BILINEAR, tmpOptions.use_bilinear);
CheckDlgButton(hDlg, IDC_CHECK_CHANGE_RES, !tmpOptions.change_fullscreen_res);
return TRUE;
case WM_COMMAND:
switch (wParam)
{
case IDC_CHECK_MAINTAIN:
tmpOptions.maintain_aspect_ratio = tmpOp