void MainApp::ReadyToRun() { // make sure we have at least one window open if (fPlayerCount == 0) { MainWin* window = NewWindow(); if (window == NULL) { PostMessage(B_QUIT_REQUESTED); return; } BMessage lastPlaylistArchive; if (_RestoreCurrentPlaylist(&lastPlaylistArchive) == B_OK) { lastPlaylistArchive.what = M_OPEN_PREVIOUS_PLAYLIST; window->PostMessage(&lastPlaylistArchive); } else window->Show(); } // setup the settings window now, we need to have it fSettingsWindow = new SettingsWindow(BRect(150, 150, 450, 520)); fSettingsWindow->Hide(); fSettingsWindow->Show(); _InstallPlaylistMimeType(); }
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); int ret = FALSE; WSADATA wsad; ret = WSAStartup(MAKEWORD(2, 2), &wsad); if (ret != 0) { OutputDebugString(_T("WSAStartup failed!\n")); return FALSE; } GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); MWinMgr::Init(hInstance); MWinMgr* mgr = MWinMgr::GetInstance(); MainWin* mainWin = new MainWin(); if (mainWin->Create(NULL)) { mainWin->Show(nCmdShow); mainWin->Update(); mgr->LoadAccelerators(IDC_NBKSHELL); ret = mgr->MainLoop(); } delete mainWin; mgr->Quit(); GdiplusShutdown(gdiplusToken); WSACleanup(); return ret; }
void MainApp::MessageReceived(BMessage* message) { switch (message->what) { case M_NEW_PLAYER: { MainWin* window = NewWindow(); if (window != NULL) window->Show(); break; } case M_PLAYER_QUIT: { // store the window settings of this instance MainWin* window = NULL; bool audioOnly = false; BRect windowFrame; bigtime_t creationTime; if (message->FindPointer("instance", (void**)&window) == B_OK && message->FindBool("audio only", &audioOnly) == B_OK && message->FindRect("window frame", &windowFrame) == B_OK && message->FindInt64("creation time", &creationTime) == B_OK) { if (audioOnly && (!fAudioWindowFrameSaved || creationTime < fLastSavedAudioWindowCreationTime)) { fAudioWindowFrameSaved = true; fLastSavedAudioWindowCreationTime = creationTime; Settings::Default()->SetAudioPlayerWindowFrame(windowFrame); } } // Store the playlist if there is one. Since the app is doing // this, it is "atomic". If the user has multiple instances // playing audio at the same time, the last instance which is // quit wins. BMessage playlistArchive; if (message->FindMessage("playlist", &playlistArchive) == B_OK) _StoreCurrentPlaylist(&playlistArchive); // quit if this was the last player window fPlayerCount--; if (fPlayerCount == 0) PostMessage(B_QUIT_REQUESTED); break; } case B_SOME_APP_LAUNCHED: case B_SOME_APP_QUIT: { const char* mimeSig; if (message->FindString("be:signature", &mimeSig) < B_OK) break; bool isMediaServer = strcmp(mimeSig, kMediaServerSig) == 0; bool isAddonServer = strcmp(mimeSig, kMediaServerAddOnSig) == 0; if (!isMediaServer && !isAddonServer) break; bool running = (message->what == B_SOME_APP_LAUNCHED); if (isMediaServer) fMediaServerRunning = running; if (isAddonServer) fMediaAddOnServerRunning = running; if (!fMediaServerRunning && !fMediaAddOnServerRunning) { fprintf(stderr, "media server has quit.\n"); // trigger closing of media nodes BMessage broadcast(M_MEDIA_SERVER_QUIT); _BroadcastMessage(broadcast); } else if (fMediaServerRunning && fMediaAddOnServerRunning) { fprintf(stderr, "media server has launched.\n"); // HACK! // quit our now invalid instance of the media roster // so that before new nodes are created, // we get a new roster (it is a normal looper) // TODO: This functionality could become part of // BMediaRoster. It could detect the start/quit of // the servers like it is done here, and either quit // itself, or re-establish the connection, and send some // notification to the app... something along those lines. BMediaRoster* roster = BMediaRoster::CurrentRoster(); if (roster) { roster->Lock(); roster->Quit(); } // give the servers some time to init... snooze(3000000); // trigger re-init of media nodes BMessage broadcast(M_MEDIA_SERVER_STARTED); _BroadcastMessage(broadcast); } break; } case M_SETTINGS: _ShowSettingsWindow(); break; case M_SHOW_OPEN_PANEL: _ShowOpenFilePanel(message); break; case M_SHOW_SAVE_PANEL: _ShowSaveFilePanel(message); break; case M_OPEN_PANEL_RESULT: _HandleOpenPanelResult(message); break; case M_SAVE_PANEL_RESULT: _HandleSavePanelResult(message); break; case B_CANCEL: { // The user canceled a file panel, but store at least the current // file panel folder. uint32 oldWhat; if (message->FindInt32("old_what", (int32*)&oldWhat) != B_OK) break; if (oldWhat == M_OPEN_PANEL_RESULT && fOpenFilePanel != NULL) fOpenFilePanel->GetPanelDirectory(&fLastFilePanelFolder); else if (oldWhat == M_SAVE_PANEL_RESULT && fSaveFilePanel != NULL) fSaveFilePanel->GetPanelDirectory(&fLastFilePanelFolder); break; } default: BApplication::MessageReceived(message); break; } }