diff --git a/src/apps/mediaplayer/Jamfile b/src/apps/mediaplayer/Jamfile index 8d0f312661..c7139f1fd8 100644 --- a/src/apps/mediaplayer/Jamfile +++ b/src/apps/mediaplayer/Jamfile @@ -9,6 +9,7 @@ local sourceDirs = playlist supplier support + settings ; local sourceDir ; @@ -28,6 +29,10 @@ Application MediaPlayer : PlaylistWindow.cpp RemovePLItemsCommand.cpp + # supplier + Settings.cpp + SettingsWindow.cpp + # supplier AudioSupplier.cpp MediaTrackAudioSupplier.cpp @@ -42,6 +47,8 @@ Application MediaPlayer : ListenerAdapter.cpp Notifier.cpp RWLocker.cpp + FileReadWrite.cpp + TPreferences.cpp # . Controller.cpp @@ -59,7 +66,7 @@ Application MediaPlayer : VideoView.cpp VolumeSlider.cpp - : be media tracker translation $(TARGET_LIBSTDC++) + : be media tracker translation textencoding $(TARGET_LIBSTDC++) : MediaPlayer.rdef ; diff --git a/src/apps/mediaplayer/MainWin.cpp b/src/apps/mediaplayer/MainWin.cpp index 59b57826de..cc3b51a56c 100644 --- a/src/apps/mediaplayer/MainWin.cpp +++ b/src/apps/mediaplayer/MainWin.cpp @@ -2,8 +2,8 @@ * MainWin.cpp - Media Player for the Haiku Operating System * * Copyright (C) 2006 Marcus Overhagen - * Copyright (C) 2007 Stephan Aßmus - * Copyright (C) 2007 Fredrik Modéen + * Copyright (C) 2007-2008 Stephan Aßmus (GPL->MIT ok) + * Copyright (C) 2007-2008 Fredrik Modéen * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -16,7 +16,8 @@ * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. * */ #include "MainWin.h" @@ -42,6 +43,7 @@ #include "MainApp.h" #include "PlaylistObserver.h" #include "PlaylistWindow.h" +#include "SettingsWindow.h" #define NAME "MediaPlayer" #define MIN_WIDTH 250 @@ -70,7 +72,7 @@ enum { M_TOGGLE_NO_BORDER_NO_MENU_NO_CONTROLS, M_TOGGLE_ALWAYS_ON_TOP, M_TOGGLE_KEEP_ASPECT_RATIO, - M_PREFERENCES, + M_SETTINGS, M_VOLUME_UP, M_VOLUME_DOWN, M_SKIP_NEXT, @@ -94,10 +96,12 @@ enum { MainWin::MainWin() - : BWindow(BRect(100,100,350,300), NAME, B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS /* | B_WILL_ACCEPT_FIRST_CLICK */) + : BWindow(BRect(100,100,400,300), NAME, B_TITLED_WINDOW, + B_ASYNCHRONOUS_CONTROLS /* | B_WILL_ACCEPT_FIRST_CLICK */) , fFilePanel(NULL) , fInfoWin(NULL) , fPlaylistWindow(NULL) + , fSettingsWindow(NULL) , fHasFile(false) , fHasVideo(false) , fHasAudio(false) @@ -127,7 +131,8 @@ MainWin::MainWin() BRect rect = Bounds(); // background - fBackground = new BView(rect, "background", B_FOLLOW_ALL, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE); + fBackground = new BView(rect, "background", B_FOLLOW_ALL, + B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE); fBackground->SetViewColor(0,0,0); AddChild(fBackground); @@ -141,12 +146,15 @@ MainWin::MainWin() fMenuBar->SetResizingMode(B_FOLLOW_NONE); // video view - rect = BRect(0, fMenuBarHeight, fBackground->Bounds().right, fMenuBarHeight + 10); - fVideoView = new VideoView(rect, "video display", B_FOLLOW_NONE, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE); + rect = BRect(0, fMenuBarHeight, fBackground->Bounds().right, + fMenuBarHeight + 10); + fVideoView = new VideoView(rect, "video display", B_FOLLOW_NONE, + B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE); fBackground->AddChild(fVideoView); // controls - rect = BRect(0, fMenuBarHeight + 11, fBackground->Bounds().right, fBackground->Bounds().bottom); + rect = BRect(0, fMenuBarHeight + 11, fBackground->Bounds().right, + fBackground->Bounds().bottom); fControls = new ControllerView(rect, fController, fPlaylist); fBackground->AddChild(fControls); fControls->ResizeToPreferred(); @@ -155,7 +163,8 @@ MainWin::MainWin() fControls->SetResizingMode(B_FOLLOW_BOTTOM | B_FOLLOW_LEFT_RIGHT); // fControls->MoveTo(0, fBackground->Bounds().bottom - fControlsHeight + 1); -// fVideoView->ResizeTo(fBackground->Bounds().Width(), fBackground->Bounds().Height() - fMenuBarHeight - fControlsHeight); +// fVideoView->ResizeTo(fBackground->Bounds().Width(), +// fBackground->Bounds().Height() - fMenuBarHeight - fControlsHeight); fPlaylist->AddListener(fPlaylistObserver); fController->SetVideoView(fVideoView); @@ -168,9 +177,15 @@ MainWin::MainWin() _SetupWindow(); + // setup the settings window now, we need to have it + fSettingsWindow = new SettingsWindow(BRect(150, 150, 450, 520)); + fSettingsWindow->Hide(); + fSettingsWindow->Show(); + // setup the playlist window now, we need to have it // running for the undo/redo playlist editing - fPlaylistWindow = new PlaylistWindow(BRect(150, 150, 400, 500), fPlaylist, fController); + fPlaylistWindow = new PlaylistWindow(BRect(150, 150, 500, 600), fPlaylist, + fController); fPlaylistWindow->Hide(); fPlaylistWindow->Show(); // this makes sure the window thread is running without @@ -200,6 +215,11 @@ MainWin::~MainWin() fPlaylistWindow->Lock(); fPlaylistWindow->Quit(); } + + if (fSettingsWindow) { + fSettingsWindow->Lock(); + fSettingsWindow->Quit(); + } delete fPlaylist; delete fController; @@ -220,10 +240,13 @@ MainWin::FrameResized(float new_width, float new_height) bool no_menu = fNoMenu || fIsFullscreen; bool no_controls = fNoControls || fIsFullscreen; - printf("FrameResized enter: new_width %.0f, new_height %.0f\n", new_width, new_height); + printf("FrameResized enter: new_width %.0f, new_height %.0f\n", + new_width, new_height); int max_video_width = int(new_width) + 1; - int max_video_height = int(new_height) + 1 - (no_menu ? 0 : fMenuBarHeight) - (no_controls ? 0 : fControlsHeight); + int max_video_height = int(new_height) + 1 + - (no_menu ? 0 : fMenuBarHeight) + - (no_controls ? 0 : fControlsHeight); ASSERT(max_video_height >= 0); @@ -374,7 +397,8 @@ MainWin::MessageReceived(BMessage *msg) fPlaylist->SetCurrentRefIndex(fPlaylist->CurrentRefIndex() + 1); break; case MSG_CONTROLLER_FILE_CHANGED: - // TODO: move all other GUI changes as a reaction to this notification + // TODO: move all other GUI changes as a reaction to this + // notification // _UpdatePlaylistMenu(); break; case MSG_CONTROLLER_VIDEO_TRACK_CHANGED: { @@ -441,7 +465,7 @@ MainWin::MessageReceived(BMessage *msg) case B_ABOUT_REQUESTED: BAlert *alert; alert = new BAlert("about", NAME"\n\n Written by Marcus Overhagen " - "and Stephan Aßmus", "Thanks"); + ", Stephan Aßmus and Frederik Modéen", "Thanks"); if (fAlwaysOnTop) { _ToggleAlwaysOnTop(); alert->Go(); @@ -536,7 +560,7 @@ MainWin::MessageReceived(BMessage *msg) printf("B_RELEASE_OVERLAY_LOCK\n"); fVideoView->OverlayLockRelease(); break; - + case B_MOUSE_WHEEL_CHANGED: { printf("B_MOUSE_WHEEL_CHANGED\n"); @@ -593,16 +617,19 @@ MainWin::MessageReceived(BMessage *msg) case M_ASPECT_544_576: VideoFormatChange(544, 576, 1.41176, 1.0); break; -/* - case M_PREFERENCES: + + case M_SETTINGS: + ShowSettingsWindow(); break; - +/* default: - if (msg->what >= M_SELECT_CHANNEL && msg->what <= M_SELECT_CHANNEL_END) { + if (msg->what >= M_SELECT_CHANNEL + && msg->what <= M_SELECT_CHANNEL_END) { SelectChannel(msg->what - M_SELECT_CHANNEL); break; } - if (msg->what >= M_SELECT_INTERFACE && msg->what <= M_SELECT_INTERFACE_END) { + if (msg->what >= M_SELECT_INTERFACE + && msg->what <= M_SELECT_INTERFACE_END) { SelectInterface(msg->what - M_SELECT_INTERFACE - 1); break; } @@ -647,8 +674,6 @@ MainWin::OpenFile(const entry_ref &ref) (new BAlert("error", s, "OK"))->Go(); } else { // just go to the next file and don't bother user - // TODO: this makes it impossible to skip backwards - // over a non recognized file! fPlaylist->SetCurrentRefIndex(fPlaylist->CurrentRefIndex() + 1); } fHasFile = false; @@ -664,6 +689,7 @@ MainWin::OpenFile(const entry_ref &ref) _SetupWindow(); } + void MainWin::ShowFileInfo() { @@ -694,16 +720,32 @@ MainWin::ShowPlaylistWindow() void -MainWin::VideoFormatChange(int width, int height, float width_scale, float height_scale) +MainWin::ShowSettingsWindow() +{ + if (fSettingsWindow->Lock()) { + if (fSettingsWindow->IsHidden()) + fSettingsWindow->Show(); + else + fSettingsWindow->Activate(); + fSettingsWindow->Unlock(); + } +} + + +void +MainWin::VideoFormatChange(int width, int height, float width_scale, + float height_scale) { // called when video format or aspect ratio changes - printf("VideoFormatChange enter: width %d, height %d, width_scale %.6f, height_scale %.6f\n", width, height, width_scale, height_scale); + printf("VideoFormatChange enter: width %d, height %d, width_scale %.6f, " + "height_scale %.6f\n", width, height, width_scale, height_scale); if (width_scale < 1.0 && height_scale >= 1.0) { width_scale = 1.0 / width_scale; height_scale = 1.0 / height_scale; - printf("inverting! new values: width_scale %.6f, height_scale %.6f\n", width_scale, height_scale); + printf("inverting! new values: width_scale %.6f, height_scale %.6f\n", + width_scale, height_scale); } fSourceWidth = width; @@ -740,7 +782,6 @@ void MainWin::_SetupWindow() { printf("MainWin::_SetupWindow\n"); - // Populate the track menus _SetupTrackMenus(); // Enable both if a file was loaded @@ -752,8 +793,7 @@ MainWin::_SetupWindow() fVideoMenu->SetEnabled(fHasVideo); fAudioMenu->SetEnabled(fHasAudio); - fDebugMenu->SetEnabled(fHasVideo); - +// fDebugMenu->SetEnabled(fHasVideo); if (fHasVideo) { fController->GetSize(&fSourceWidth, &fSourceHeight); fWidthScale = 1.0; @@ -764,7 +804,6 @@ MainWin::_SetupWindow() fWidthScale = 1.0; fHeightScale = 1.0; } - _UpdateControlsEnabledStatus(); _ResizeWindow(100); @@ -783,7 +822,7 @@ MainWin::_CreateMenu() fSettingsMenu = new BMenu("Settings"); fAudioTrackMenu = new BMenu("Track"); fVideoTrackMenu = new BMenu("Track"); - fDebugMenu = new BMenu("Debug"); +// fDebugMenu = new BMenu("Debug"); fMenuBar->AddItem(fFileMenu); fMenuBar->AddItem(fAudioMenu); @@ -791,10 +830,13 @@ MainWin::_CreateMenu() fMenuBar->AddItem(fSettingsMenu); // fMenuBar->AddItem(fDebugMenu); - fFileMenu->AddItem(new BMenuItem("New Player"B_UTF8_ELLIPSIS, new BMessage(M_FILE_NEWPLAYER), 'N', B_COMMAND_KEY)); + fFileMenu->AddItem(new BMenuItem("New Player"B_UTF8_ELLIPSIS, + new BMessage(M_FILE_NEWPLAYER), 'N')); fFileMenu->AddSeparatorItem(); - fFileMenu->AddItem(new BMenuItem("Open File"B_UTF8_ELLIPSIS, new BMessage(M_FILE_OPEN), 'O', B_COMMAND_KEY)); - fFileMenu->AddItem(new BMenuItem("File Info"B_UTF8_ELLIPSIS, new BMessage(M_FILE_INFO), 'I', B_COMMAND_KEY)); + fFileMenu->AddItem(new BMenuItem("Open File"B_UTF8_ELLIPSIS, + new BMessage(M_FILE_OPEN), 'O')); + fFileMenu->AddItem(new BMenuItem("File Info"B_UTF8_ELLIPSIS, + new BMessage(M_FILE_INFO), 'I')); fFileMenu->AddItem(fPlaylistMenu); fPlaylistMenu->Superitem()->SetShortcut('P', B_COMMAND_KEY); fPlaylistMenu->Superitem()->SetMessage(new BMessage(M_FILE_PLAYLIST)); @@ -803,8 +845,8 @@ MainWin::_CreateMenu() fFileMenu->AddItem(new BMenuItem("About" NAME B_UTF8_ELLIPSIS, new BMessage(B_ABOUT_REQUESTED))); fFileMenu->AddSeparatorItem(); - fFileMenu->AddItem(new BMenuItem("Close", new BMessage(M_FILE_CLOSE), 'W', B_COMMAND_KEY)); - fFileMenu->AddItem(new BMenuItem("Quit", new BMessage(M_FILE_QUIT), 'Q', B_COMMAND_KEY)); + fFileMenu->AddItem(new BMenuItem("Close", new BMessage(M_FILE_CLOSE), 'W')); + fFileMenu->AddItem(new BMenuItem("Quit", new BMessage(M_FILE_QUIT), 'Q')); fPlaylistMenu->SetRadioMode(true); @@ -812,40 +854,51 @@ MainWin::_CreateMenu() fVideoMenu->AddItem(fVideoTrackMenu); fVideoMenu->AddSeparatorItem(); - fVideoMenu->AddItem(new BMenuItem("50% scale", new BMessage(M_VIEW_50), '0', B_COMMAND_KEY)); - fVideoMenu->AddItem(new BMenuItem("100% scale", new BMessage(M_VIEW_100), '1', B_COMMAND_KEY)); - fVideoMenu->AddItem(new BMenuItem("200% scale", new BMessage(M_VIEW_200), '2', B_COMMAND_KEY)); - fVideoMenu->AddItem(new BMenuItem("300% scale", new BMessage(M_VIEW_300), '3', B_COMMAND_KEY)); - fVideoMenu->AddItem(new BMenuItem("400% scale", new BMessage(M_VIEW_400), '4', B_COMMAND_KEY)); + fVideoMenu->AddItem(new BMenuItem("50% scale", + new BMessage(M_VIEW_50), '0')); + fVideoMenu->AddItem(new BMenuItem("100% scale", + new BMessage(M_VIEW_100), '1')); + fVideoMenu->AddItem(new BMenuItem("200% scale", + new BMessage(M_VIEW_200), '2')); + fVideoMenu->AddItem(new BMenuItem("300% scale", + new BMessage(M_VIEW_300), '3')); + fVideoMenu->AddItem(new BMenuItem("400% scale", + new BMessage(M_VIEW_400), '4')); fVideoMenu->AddSeparatorItem(); - fVideoMenu->AddItem(new BMenuItem("Full Screen", new BMessage(M_TOGGLE_FULLSCREEN), 'F', B_COMMAND_KEY)); - fVideoMenu->AddItem(new BMenuItem("Keep Aspect Ratio", new BMessage(M_TOGGLE_KEEP_ASPECT_RATIO), 'K', B_COMMAND_KEY)); + fVideoMenu->AddItem(new BMenuItem("Full Screen", + new BMessage(M_TOGGLE_FULLSCREEN), 'F')); + fVideoMenu->AddItem(new BMenuItem("Keep Aspect Ratio", + new BMessage(M_TOGGLE_KEEP_ASPECT_RATIO), 'K')); - fSettingsMenu->AddItem(new BMenuItem("No Menu", new BMessage(M_TOGGLE_NO_MENU), 'M', B_COMMAND_KEY)); - fSettingsMenu->AddItem(new BMenuItem("No Border", new BMessage(M_TOGGLE_NO_BORDER), 'B', B_COMMAND_KEY)); - fSettingsMenu->AddItem(new BMenuItem("No Controls", new BMessage(M_TOGGLE_NO_CONTROLS), 'C', B_COMMAND_KEY)); - fSettingsMenu->AddItem(new BMenuItem("Always on Top", new BMessage(M_TOGGLE_ALWAYS_ON_TOP), 'T', B_COMMAND_KEY)); + fSettingsMenu->AddItem(new BMenuItem("No Menu", + new BMessage(M_TOGGLE_NO_MENU), 'M')); + fSettingsMenu->AddItem(new BMenuItem("No Border", + new BMessage(M_TOGGLE_NO_BORDER), 'B')); + fSettingsMenu->AddItem(new BMenuItem("No Controls", + new BMessage(M_TOGGLE_NO_CONTROLS), 'C')); + fSettingsMenu->AddItem(new BMenuItem("Always on Top", + new BMessage(M_TOGGLE_ALWAYS_ON_TOP), 'T')); // fSettingsMenu->AddSeparatorItem(); -// fSettingsMenu->AddItem(new BMenuItem("Preferences"B_UTF8_ELLIPSIS, new BMessage(M_PREFERENCES), 'P', B_COMMAND_KEY)); +// fSettingsMenu->AddItem(new BMenuItem("Settings"B_UTF8_ELLIPSIS, +// new BMessage(M_SETTINGS), 'S')); - fDebugMenu->AddItem(new BMenuItem("pixel aspect ratio 1.00000:1", new BMessage(M_ASPECT_100000_1))); - fDebugMenu->AddItem(new BMenuItem("pixel aspect ratio 1.06666:1", new BMessage(M_ASPECT_106666_1))); - fDebugMenu->AddItem(new BMenuItem("pixel aspect ratio 1.09091:1", new BMessage(M_ASPECT_109091_1))); - fDebugMenu->AddItem(new BMenuItem("pixel aspect ratio 1.41176:1", new BMessage(M_ASPECT_141176_1))); - fDebugMenu->AddItem(new BMenuItem("force 720 x 576, display aspect 4:3", new BMessage(M_ASPECT_720_576))); - fDebugMenu->AddItem(new BMenuItem("force 704 x 576, display aspect 4:3", new BMessage(M_ASPECT_704_576))); - fDebugMenu->AddItem(new BMenuItem("force 544 x 576, display aspect 4:3", new BMessage(M_ASPECT_544_576))); +// fDebugMenu->AddItem(new BMenuItem("pixel aspect ratio 1.00000:1", +// new BMessage(M_ASPECT_100000_1))); +// fDebugMenu->AddItem(new BMenuItem("pixel aspect ratio 1.06666:1", +// new BMessage(M_ASPECT_106666_1))); +// fDebugMenu->AddItem(new BMenuItem("pixel aspect ratio 1.09091:1", +// new BMessage(M_ASPECT_109091_1))); +// fDebugMenu->AddItem(new BMenuItem("pixel aspect ratio 1.41176:1", +// new BMessage(M_ASPECT_141176_1))); +// fDebugMenu->AddItem(new BMenuItem("force 720 x 576, display aspect 4:3", +// new BMessage(M_ASPECT_720_576))); +// fDebugMenu->AddItem(new BMenuItem("force 704 x 576, display aspect 4:3", +// new BMessage(M_ASPECT_704_576))); +// fDebugMenu->AddItem(new BMenuItem("force 544 x 576, display aspect 4:3", +// new BMessage(M_ASPECT_544_576))); fAudioTrackMenu->SetRadioMode(true); fVideoTrackMenu->SetRadioMode(true); -/* - fSettingsMenu->ItemAt(3)->SetMarked(fIsFullscreen); - fSettingsMenu->ItemAt(5)->SetMarked(fNoMenu); - fSettingsMenu->ItemAt(6)->SetMarked(fNoBorder); - fSettingsMenu->ItemAt(7)->SetMarked(fAlwaysOnTop); - fSettingsMenu->ItemAt(8)->SetMarked(fKeepAspectRatio); - fSettingsMenu->ItemAt(10)->SetEnabled(false); // XXX disable unused preference menu -*/ } @@ -861,7 +914,8 @@ MainWin::_SetupTrackMenus() c = fController->AudioTrackCount(); for (i = 0; i < c; i++) { sprintf(s, "Track %d", i + 1); - fAudioTrackMenu->AddItem(new BMenuItem(s, new BMessage(M_SELECT_AUDIO_TRACK + i))); + fAudioTrackMenu->AddItem(new BMenuItem(s, + new BMessage(M_SELECT_AUDIO_TRACK + i))); } if (!c) fAudioTrackMenu->AddItem(new BMenuItem("none", new BMessage(M_DUMMY))); @@ -869,7 +923,8 @@ MainWin::_SetupTrackMenus() c = fController->VideoTrackCount(); for (i = 0; i < c; i++) { sprintf(s, "Track %d", i + 1); - fVideoTrackMenu->AddItem(new BMenuItem(s, new BMessage(M_SELECT_VIDEO_TRACK + i))); + fVideoTrackMenu->AddItem(new BMenuItem(s, + new BMessage(M_SELECT_VIDEO_TRACK + i))); } if (!c) fVideoTrackMenu->AddItem(new BMenuItem("none", new BMessage(M_DUMMY))); @@ -882,9 +937,11 @@ MainWin::_SetWindowSizeLimits() int minWidth = fNoControls ? MIN_WIDTH : fControlsWidth; if (!fNoMenu) minWidth = max_c(minWidth, fMenuBarWidth); - int minHeight = (fNoMenu ? 0 : fMenuBarHeight) + (fNoControls ? 0 : fControlsHeight); + int minHeight = (fNoMenu ? 0 : fMenuBarHeight) + + (fNoControls ? 0 : fControlsHeight); - SetSizeLimits(minWidth - 1, 32000, minHeight - 1, fHasVideo ? 32000 : minHeight - 1); + SetSizeLimits(minWidth - 1, 32000, minHeight - 1, fHasVideo ? + 32000 : minHeight - 1); } @@ -916,7 +973,8 @@ MainWin::_ResizeWindow(int percent) void MainWin::_ResizeVideoView(int x, int y, int width, int height) { - printf("_ResizeVideoView: %d,%d, width %d, height %d\n", x, y, width, height); + printf("_ResizeVideoView: %d,%d, width %d, height %d\n", x, y, + width, height); if (fKeepAspectRatio) { // Keep aspect ratio, place video view inside @@ -953,7 +1011,8 @@ MainWin::_MouseDown(BMessage *msg, BView* originalHandler) BPoint screen_where; uint32 buttons = msg->FindInt32("buttons"); - // On Zeta, only "screen_where" is relyable, "where" and "be:view_where" seem to be broken + // On Zeta, only "screen_where" is relyable, "where" and "be:view_where" + // seem to be broken if (B_OK != msg->FindPoint("screen_where", &screen_where)) { // Workaround for BeOS R5, it has no "screen_where" if (!originalHandler || msg->FindPoint("where", &screen_where) < B_OK) @@ -966,7 +1025,8 @@ MainWin::_MouseDown(BMessage *msg, BView* originalHandler) // if (1 == msg->FindInt32("buttons") && msg->FindInt32("clicks") == 1) { if (1 == buttons && msg->FindInt32("clicks") % 2 == 0) { - BRect r(screen_where.x - 1, screen_where.y - 1, screen_where.x + 1, screen_where.y + 1); + BRect r(screen_where.x - 1, screen_where.y - 1, screen_where.x + 1, + screen_where.y + 1); if (r.Contains(fMouseDownMousePos)) { PostMessage(M_TOGGLE_FULLSCREEN); return; @@ -974,7 +1034,8 @@ MainWin::_MouseDown(BMessage *msg, BView* originalHandler) } if (2 == buttons && msg->FindInt32("clicks") % 2 == 0) { - BRect r(screen_where.x - 1, screen_where.y - 1, screen_where.x + 1, screen_where.y + 1); + BRect r(screen_where.x - 1, screen_where.y - 1, screen_where.x + 1, + screen_where.y + 1); if (r.Contains(fMouseDownMousePos)) { PostMessage(M_TOGGLE_NO_BORDER_NO_MENU_NO_CONTROLS); return; @@ -983,14 +1044,16 @@ MainWin::_MouseDown(BMessage *msg, BView* originalHandler) /* // very broken in Zeta: - fMouseDownMousePos = fVideoView->ConvertToScreen(msg->FindPoint("where")); + fMouseDownMousePos = fVideoView->ConvertToScreen( + msg->FindPoint("where")); */ fMouseDownMousePos = screen_where; fMouseDownWindowPos = Frame().LeftTop(); if (buttons == 1 && !fIsFullscreen) { // start mouse tracking - fVideoView->SetMouseEventMask(B_POINTER_EVENTS | B_NO_POINTER_HISTORY /* | B_LOCK_WINDOW_FOCUS */); + fVideoView->SetMouseEventMask(B_POINTER_EVENTS | B_NO_POINTER_HISTORY + /* | B_LOCK_WINDOW_FOCUS */); fMouseDownTracking = true; } @@ -1061,38 +1124,51 @@ MainWin::_ShowContextMenu(const BPoint &screen_point) printf("Show context menu\n"); BPopUpMenu *menu = new BPopUpMenu("context menu", false, false); BMenuItem *item; - menu->AddItem(item = new BMenuItem("Full Screen", new BMessage(M_TOGGLE_FULLSCREEN), 'F', B_COMMAND_KEY)); + menu->AddItem(item = new BMenuItem("Full Screen", + new BMessage(M_TOGGLE_FULLSCREEN), 'F')); item->SetMarked(fIsFullscreen); item->SetEnabled(fHasVideo); - menu->AddItem(item = new BMenuItem("Keep Aspect Ratio", new BMessage(M_TOGGLE_KEEP_ASPECT_RATIO), 'K', B_COMMAND_KEY)); + menu->AddItem(item = new BMenuItem("Keep Aspect Ratio", + new BMessage(M_TOGGLE_KEEP_ASPECT_RATIO), 'K')); item->SetMarked(fKeepAspectRatio); item->SetEnabled(fHasVideo); menu->AddSeparatorItem(); - menu->AddItem(item = new BMenuItem("No Menu", new BMessage(M_TOGGLE_NO_MENU), 'M', B_COMMAND_KEY)); + menu->AddItem(item = new BMenuItem("No Menu", + new BMessage(M_TOGGLE_NO_MENU), 'M')); item->SetMarked(fNoMenu); - menu->AddItem(item = new BMenuItem("No Border", new BMessage(M_TOGGLE_NO_BORDER), 'B', B_COMMAND_KEY)); + menu->AddItem(item = new BMenuItem("No Border", + new BMessage(M_TOGGLE_NO_BORDER), 'B')); item->SetMarked(fNoBorder); - menu->AddItem(item = new BMenuItem("Always on Top", new BMessage(M_TOGGLE_ALWAYS_ON_TOP), 'T', B_COMMAND_KEY)); + menu->AddItem(item = new BMenuItem("Always on Top", + new BMessage(M_TOGGLE_ALWAYS_ON_TOP), 'T')); item->SetMarked(fAlwaysOnTop); menu->AddSeparatorItem(); menu->AddItem(new BMenuItem("About" NAME B_UTF8_ELLIPSIS, new BMessage(B_ABOUT_REQUESTED))); menu->AddSeparatorItem(); - menu->AddItem(new BMenuItem("Quit", new BMessage(M_FILE_QUIT), 'Q', B_COMMAND_KEY)); + menu->AddItem(new BMenuItem("Quit", new BMessage(M_FILE_QUIT), 'Q')); menu->AddSeparatorItem(); - menu->AddItem(new BMenuItem("pixel aspect ratio 1.00000:1", new BMessage(M_ASPECT_100000_1))); - menu->AddItem(new BMenuItem("pixel aspect ratio 1.06666:1", new BMessage(M_ASPECT_106666_1))); - menu->AddItem(new BMenuItem("pixel aspect ratio 1.09091:1", new BMessage(M_ASPECT_109091_1))); - menu->AddItem(new BMenuItem("pixel aspect ratio 1.41176:1", new BMessage(M_ASPECT_141176_1))); - menu->AddItem(new BMenuItem("force 720 x 576, display aspect 4:3", new BMessage(M_ASPECT_720_576))); - menu->AddItem(new BMenuItem("force 704 x 576, display aspect 4:3", new BMessage(M_ASPECT_704_576))); - menu->AddItem(new BMenuItem("force 544 x 576, display aspect 4:3", new BMessage(M_ASPECT_544_576))); + menu->AddItem(new BMenuItem("pixel aspect ratio 1.00000:1", + new BMessage(M_ASPECT_100000_1))); + menu->AddItem(new BMenuItem("pixel aspect ratio 1.06666:1", + new BMessage(M_ASPECT_106666_1))); + menu->AddItem(new BMenuItem("pixel aspect ratio 1.09091:1", + new BMessage(M_ASPECT_109091_1))); + menu->AddItem(new BMenuItem("pixel aspect ratio 1.41176:1", + new BMessage(M_ASPECT_141176_1))); + menu->AddItem(new BMenuItem("force 720 x 576, display aspect 4:3", + new BMessage(M_ASPECT_720_576))); + menu->AddItem(new BMenuItem("force 704 x 576, display aspect 4:3", + new BMessage(M_ASPECT_704_576))); + menu->AddItem(new BMenuItem("force 544 x 576, display aspect 4:3", + new BMessage(M_ASPECT_544_576))); menu->SetTargetForItems(this); - BRect r(screen_point.x - 5, screen_point.y - 5, screen_point.x + 5, screen_point.y + 5); + BRect r(screen_point.x - 5, screen_point.y - 5, screen_point.x + 5, + screen_point.y + 5); menu->Go(screen_point, true, true, r, true); } @@ -1109,7 +1185,8 @@ MainWin::_KeyDown(BMessage *msg) uint32 raw_char = msg->FindInt32("raw_char"); uint32 modifiers = msg->FindInt32("modifiers"); - printf("key 0x%lx, raw_char 0x%lx, modifiers 0x%lx\n", key, raw_char, modifiers); + printf("key 0x%lx, raw_char 0x%lx, modifiers 0x%lx\n", key, raw_char, + modifiers); switch (raw_char) { case B_SPACE: @@ -1134,7 +1211,8 @@ MainWin::_KeyDown(BMessage *msg) break; case B_TAB: - if ((modifiers & (B_COMMAND_KEY | B_CONTROL_KEY | B_OPTION_KEY | B_MENU_KEY)) == 0) { + if ((modifiers & (B_COMMAND_KEY | B_CONTROL_KEY | B_OPTION_KEY + | B_MENU_KEY)) == 0) { PostMessage(M_TOGGLE_FULLSCREEN); return B_OK; } else @@ -1260,7 +1338,9 @@ MainWin::_ToggleFullscreen() // switch to fullscreen fSavedFrame = Frame(); - printf("saving current frame: %d %d %d %d\n", int(fSavedFrame.left), int(fSavedFrame.top), int(fSavedFrame.right), int(fSavedFrame.bottom)); + printf("saving current frame: %d %d %d %d\n", int(fSavedFrame.left), + int(fSavedFrame.top), int(fSavedFrame.right), + int(fSavedFrame.bottom)); BScreen screen(this); BRect rect(screen.Frame()); diff --git a/src/apps/mediaplayer/MainWin.h b/src/apps/mediaplayer/MainWin.h index e8128fb100..6cadb333ae 100644 --- a/src/apps/mediaplayer/MainWin.h +++ b/src/apps/mediaplayer/MainWin.h @@ -32,10 +32,10 @@ #include "VideoView.h" #include "Playlist.h" - class ControllerObserver; class PlaylistObserver; class PlaylistWindow; +class SettingsWindow; class MainWin : public BWindow { public: @@ -54,6 +54,7 @@ public: void ShowFileInfo(); void ShowPlaylistWindow(); + void ShowSettingsWindow(); void VideoFormatChange(int width, int height, float widthScale, float heightScale); @@ -100,6 +101,7 @@ private: ControllerView* fControls; InfoWin* fInfoWin; PlaylistWindow* fPlaylistWindow; + SettingsWindow* fSettingsWindow; BMenu* fFileMenu; BMenu* fAudioMenu; diff --git a/src/apps/mediaplayer/playlist/Playlist.cpp b/src/apps/mediaplayer/playlist/Playlist.cpp index 2fe74fe03c..67aa8671f6 100644 --- a/src/apps/mediaplayer/playlist/Playlist.cpp +++ b/src/apps/mediaplayer/playlist/Playlist.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2006 Marcus Overhagen * Copyright (C) 2007 Stephan Aßmus - * Copyright (C) 2007 Fredrik Modéen + * Copyright (C) 2008 Fredrik Modéen (I have no problem changing my things to MIT) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -34,6 +34,8 @@ #include #include +#include "FileReadWrite.h" + using std::nothrow; // TODO: using BList for objects is bad, replace it with a template @@ -281,8 +283,7 @@ Playlist::AppendRefs(const BMessage* refsReceivedMessage, int32 appendIndex) entry_ref ref; for (int i = 0; refsReceivedMessage->FindRef("refs", i, &ref) == B_OK; i++) - AppendToPlaylistRecursive(ref, playlist); - + AppendToPlaylistRecursive(ref, playlist); playlist->Sort(); if (add) @@ -300,10 +301,17 @@ Playlist::AppendToPlaylistRecursive(const entry_ref& ref, Playlist* playlist) { // recursively append the ref (dive into folders) BEntry entry(&ref, true); - if (entry.InitCheck() < B_OK) + if (entry.InitCheck() < B_OK) { + printf("Not OK\n"); return; - if (!entry.Exists()) + } + + if (!entry.Exists()) { + BPath path = BPath(&ref); + //printf("Don't exist - %s\n", path.Path()); return; + } + if (entry.IsDirectory()) { BDirectory dir(&entry); if (dir.InitCheck() < B_OK) @@ -313,13 +321,35 @@ Playlist::AppendToPlaylistRecursive(const entry_ref& ref, Playlist* playlist) while (dir.GetNextRef(&subRef) == B_OK) AppendToPlaylistRecursive(subRef, playlist); } else if (entry.IsFile()) { + //printf("Is File\n"); BString mimeString = _MIMEString(&ref); - if (_IsMediaFile(mimeString)) + if (_IsMediaFile(mimeString)) { + //printf("Adding\n"); playlist->AddRef(ref); - else if (_IsPlaylist(mimeString)) { - printf("Playlist::AppendToPlaylistRecursive() - " - "TODO: implement playlist file loading\n"); - } + } else if (_IsPlaylist(mimeString)) { + //printf("RunPlaylist thing\n"); + BFile file(&ref, B_READ_ONLY); + FileReadWrite lineReader(&file); + + BString str; + entry_ref refPath; + status_t err; + BPath path; + while (lineReader.Next(str)) { + str = str.RemoveFirst("file://"); + str = str.RemoveLast(".."); + path = BPath(str.String()); + printf("Line %s\n", path.Path()); + if (path.Path() != NULL) { + if ((err = get_ref_for_path(path.Path(), &refPath)) == B_OK) { + playlist->AddRef(refPath); + } else + printf("Error - %s: [%lx]\n", strerror(err), (int32) err); + } else + printf("Error - No File Found in playlist\n"); + } + } else + printf("MIME Type = %s\n", mimeString.String()); } } @@ -331,7 +361,6 @@ int Playlist::playlist_cmp(const void *p1, const void *p2) { // compare complete path - BEntry a(*(const entry_ref **)p1, false); BEntry b(*(const entry_ref **)p2, false); @@ -342,6 +371,30 @@ Playlist::playlist_cmp(const void *p1, const void *p2) } +/*static*/ void +Playlist::_AddPlayListFileToPlayList(const entry_ref& ref, Playlist* playlist) +{ + + BFile file(&ref, B_READ_ONLY); + FileReadWrite lineReader(&file); + + BString str; + while (lineReader.Next(str)) { + BPath path = BPath(str.String()); + entry_ref refPath; + status_t err; + if ((err = get_ref_for_path(path.Path(), &refPath)) == B_OK) { + AppendToPlaylistRecursive(refPath, playlist); + } else + printf("Error - %s: [%lx]\n", strerror(err), (int32) err); + } + /* + Read line for x to the end of file (while?) + make a enty_ref and call AppendToPlaylistRecursive(with new entry, playlist) + */ +} + + /*static*/ bool Playlist::_IsMediaFile(const BString& mimeString) { diff --git a/src/apps/mediaplayer/playlist/Playlist.h b/src/apps/mediaplayer/playlist/Playlist.h index f41d6aa4fe..a5ee9eff23 100644 --- a/src/apps/mediaplayer/playlist/Playlist.h +++ b/src/apps/mediaplayer/playlist/Playlist.h @@ -1,8 +1,9 @@ /* * Playlist.h - Media Player for the Haiku Operating System * - * Copyright (C) 2006 Marcus Overhagen - * Copyright (C) 2007 Stephan Aßmus + * Copyright (C) 2006 Marcus Overhagen + * Copyright (C) 2007 Stephan Aßmus + * Copyright (C) 2008 Fredrik Modéen (I have no problem changing my things to MIT) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -88,7 +89,8 @@ private: static bool _IsMediaFile(const BString& mimeString); static bool _IsPlaylist(const BString& mimeString); static BString _MIMEString(const entry_ref* entry); - + static void _AddPlayListFileToPlayList(const entry_ref& ref, + Playlist* playlist); void _NotifyRefAdded(const entry_ref& ref, int32 index) const; void _NotifyRefRemoved(int32 index) const; diff --git a/src/apps/mediaplayer/playlist/PlaylistWindow.cpp b/src/apps/mediaplayer/playlist/PlaylistWindow.cpp index 330689953e..a949ce4ee7 100644 --- a/src/apps/mediaplayer/playlist/PlaylistWindow.cpp +++ b/src/apps/mediaplayer/playlist/PlaylistWindow.cpp @@ -3,21 +3,40 @@ * Distributed under the terms of the MIT License. * * Authors: - * Stephan Aßmus + * Stephan Aßmus + * Fredrik Modéen */ + #include "PlaylistWindow.h" +#include + +#include +#include +#include #include #include #include #include #include #include +#include +#include +#include #include "CommandStack.h" #include "PlaylistListView.h" #include "RWLocker.h" +#define DEBUG 1 + +enum { + M_PLAYLIST_OPEN = 'open', + M_PLAYLIST_SAVE = 'save', + M_PLAYLIST_EMPTY = 'emty' +}; + +#define SPACE 5 PlaylistWindow::PlaylistWindow(BRect frame, Playlist* playlist, Controller* controller) @@ -28,18 +47,19 @@ PlaylistWindow::PlaylistWindow(BRect frame, Playlist* playlist, , fCommandStack(new CommandStack(fLocker)) , fCommandStackListener(this) { - frame = Bounds(); - + frame = Bounds(); + _CreateMenu(frame); - + // will adjust frame to account for menubar + frame.right -= B_V_SCROLL_BAR_WIDTH; fListView = new PlaylistListView(frame, playlist, controller, fCommandStack); - BScrollView* scrollView = new BScrollView("playlist scrollview", - fListView, B_FOLLOW_ALL, 0, false, true, B_NO_BORDER); + BScrollView* scrollView = new BScrollView("playlist scrollview", fListView, + B_FOLLOW_ALL_SIDES, 0, false, true, B_NO_BORDER); - fTopView = scrollView; + fTopView = scrollView; AddChild(fTopView); // small visual tweak @@ -109,7 +129,23 @@ PlaylistWindow::MessageReceived(BMessage* message) } break; } - + + case M_PLAYLIST_SAVE: + if (!fSavePanel) + fSavePanel = new BFilePanel(B_SAVE_PANEL); + fSavePanel->Show(); + break; + case B_SAVE_REQUESTED: + printf("We are saving\n"); + //Use fListView and have a SaveToFile? + break; + case M_PLAYLIST_OPEN: + if (!fOpenPanel) + fOpenPanel = new BFilePanel(B_OPEN_PANEL); + fOpenPanel->Show(); + break; + case M_PLAYLIST_EMPTY: + break; default: BWindow::MessageReceived(message); break; @@ -127,15 +163,22 @@ PlaylistWindow::_CreateMenu(BRect& frame) BMenuBar* menuBar = new BMenuBar(frame, "main menu"); BMenu* fileMenu = new BMenu("Playlist"); menuBar->AddItem(fileMenu); - // TODO add some items: "Open", "Save", "Make Empty"... +// fileMenu->AddItem(new BMenuItem("Open"B_UTF8_ELLIPSIS, +// new BMessage(M_PLAYLIST_OPEN), 'O')); +// fileMenu->AddItem(new BMenuItem("Save"B_UTF8_ELLIPSIS, +// new BMessage(M_PLAYLIST_SAVE), 'S')); +// fileMenu->AddSeparatorItem(); + fileMenu->AddItem(new BMenuItem("Close", + new BMessage(B_QUIT_REQUESTED), 'W')); BMenu* editMenu = new BMenu("Edit"); - BMessage* message = new BMessage(B_UNDO); - fUndoMI = new BMenuItem("Undo", message); + fUndoMI = new BMenuItem("Undo", new BMessage(B_UNDO), 'Z'); editMenu->AddItem(fUndoMI); - message = new BMessage(B_REDO); - fRedoMI = new BMenuItem("Undo", message); + fRedoMI = new BMenuItem("Redo", new BMessage(B_REDO), 'Z', B_SHIFT_KEY); editMenu->AddItem(fRedoMI); + editMenu->AddSeparatorItem(); + editMenu->AddItem(new BMenuItem("Make Empty", + new BMessage(M_PLAYLIST_EMPTY), 'N')); menuBar->AddItem(editMenu); AddChild(menuBar); diff --git a/src/apps/mediaplayer/playlist/PlaylistWindow.h b/src/apps/mediaplayer/playlist/PlaylistWindow.h index 20501dc8e2..9e1b6d3391 100644 --- a/src/apps/mediaplayer/playlist/PlaylistWindow.h +++ b/src/apps/mediaplayer/playlist/PlaylistWindow.h @@ -3,8 +3,10 @@ * Distributed under the terms of the MIT License. * * Authors: - * Stephan Aßmus + * Stephan Aßmus + * Fredrik Modéen */ + #ifndef PLAYLIST_WINDOW_H #define PLAYLIST_WINDOW_H @@ -21,6 +23,7 @@ class Notifier; class Playlist; class PlaylistListView; class RWLocker; +class BButton; class PlaylistWindow : public BWindow { public: @@ -42,6 +45,9 @@ class PlaylistWindow : public BWindow { BView* fTopView; BMenuItem* fUndoMI; BMenuItem* fRedoMI; + + BFilePanel* fOpenPanel; + BFilePanel* fSavePanel; RWLocker* fLocker; CommandStack* fCommandStack;