void MainApp::ArgvReceived(int32 argc, char** argv) { char cwd[B_PATH_NAME_LENGTH]; getcwd(cwd, sizeof(cwd)); BMessage message(B_REFS_RECEIVED); for (int i = 1; i < argc; i++) { BPath path; if (argv[i][0] != '/') path.SetTo(cwd, argv[i]); else path.SetTo(argv[i]); BEntry entry(path.Path(), true); if (!entry.Exists() || !entry.IsFile()) continue; entry_ref ref; if (entry.GetRef(&ref) == B_OK) message.AddRef("refs", &ref); } if (message.HasRef("refs")) RefsReceived(&message); }
// Called when a message has been received. void app::MessageReceived(BMessage *msg) { bool failed; switch(msg->what) { case B_SIMPLE_DATA: RefsReceived(msg); break; case MOUNT_IMAGE: { failed=false; if (MountImage(imagepath.String(), "bfs")<0) if (MountImage(imagepath.String(), "hfs")<0) if (MountImage(imagepath.String(), "iso9660")<0) if (MountImage(imagepath.String(), "dos")<0) { failed=true; } if (quit) PostMessage(new BMessage(B_QUIT_REQUESTED)); else if (w->Lock()) { if (failed) sv->SetHighColor(150, 100, 100); else sv->SetHighColor(100, 150, 100); sv->SetText(failed ? "Not an image file!" : "Image mounted successfully."); w->Unlock(); } break; } default: BApplication::MessageReceived(msg); break; } }
void LauncherApp::ReadyToRun() { // Since we will essentially run the GUI... set_thread_priority(Thread(), B_DISPLAY_PRIORITY); BWebPage::InitializeOnce(); BWebPage::SetCacheModel(B_WEBKIT_CACHE_MODEL_WEB_BROWSER); BFile settingsFile; BRect windowFrameFromSettings = m_lastWindowFrame; if (openSettingsFile(settingsFile, B_READ_ONLY)) { BMessage settingsArchive; settingsArchive.Unflatten(&settingsFile); settingsArchive.FindRect("window frame", &windowFrameFromSettings); } m_lastWindowFrame = windowFrameFromSettings; m_initialized = true; if (m_launchRefsMessage) { RefsReceived(m_launchRefsMessage); delete m_launchRefsMessage; m_launchRefsMessage = 0; } else { LauncherWindow* window = new LauncherWindow(m_lastWindowFrame); window->Show(); } }
void FileTypes::ArgvReceived(int32 argc, char **argv) { BMessage *message = CurrentMessage(); BDirectory currentDirectory; if (message) currentDirectory.SetTo(message->FindString("cwd")); BMessage refs; for (int i = 1 ; i < argc ; i++) { BPath path; if (argv[i][0] == '/') path.SetTo(argv[i]); else path.SetTo(¤tDirectory, argv[i]); status_t status; entry_ref ref; BEntry entry; if ((status = entry.SetTo(path.Path(), false)) != B_OK || (status = entry.GetRef(&ref)) != B_OK) { fprintf(stderr, "Could not open file \"%s\": %s\n", path.Path(), strerror(status)); continue; } refs.AddRef("refs", &ref); } RefsReceived(&refs); }
void TPeopleApp::ArgvReceived(int32 argc, char** argv) { BMessage message(B_REFS_RECEIVED); for (int32 i = 1; i < argc; i++) { BEntry entry(argv[i]); entry_ref ref; if (entry.Exists() && entry.GetRef(&ref) == B_OK) message.AddRef("refs", &ref); } RefsReceived(&message); }
void PecoApp::MessageReceived(BMessage *msg) { switch( msg->what ) { case B_SIMPLE_DATA: RefsReceived (msg); break; case MSG_MENU_NEW: New(); NoRenamer(); break; case MSG_SELECT_FILES: fFilePanel->Show(); break; case MSG_DO_IT: MakeList(); DoIt(); break; case MSG_RENAMER: ChangeRenamer(); break; case MSG_RENAME_SETTINGS: MakeList(); break; case MSG_MENU_SCRIPT: if (!NothingToDo()) fScriptFilePanel->Show(); break; case B_SAVE_REQUESTED: CreateScript(msg); break; default: BApplication::MessageReceived(msg); } };
void ExpanderApp::ArgvReceived(int32 argc, char **argv) { BMessage* msg = NULL; for (int32 i = 1; i < argc; i++) { entry_ref ref; status_t err = get_ref_for_path(argv[i], &ref); if (err == B_OK) { if (!msg) { msg = new BMessage; msg->what = B_REFS_RECEIVED; } msg->AddRef("refs", &ref); } } if (msg) RefsReceived(msg); }
void DjVuApp::ArgvReceived(int32 argc, char **argv) { BMessage *pmsg = NULL; for (int32 i = 1; i < argc; i++) { entry_ref ref; status_t err = get_ref_for_path(argv[i], &ref); if (err == B_OK) { if (!pmsg) { pmsg = new BMessage; pmsg->what = B_REFS_RECEIVED; } pmsg->AddRef("refs", &ref); } } if (pmsg) { RefsReceived(pmsg); delete pmsg; } }
void BrowserApp::ArgvReceived(int32 argc, char** argv) { BMessage message(B_REFS_RECEIVED); for (int i = 1; i < argc; i++) { if (strcmp("-f", argv[i]) == 0 || strcmp("--fullscreen", argv[i]) == 0) { message.AddBool("fullscreen", true); continue; } const char* url = argv[i]; BEntry entry(argv[i], true); BPath path; if (entry.Exists() && entry.GetPath(&path) == B_OK) url = path.Path(); message.AddString("url", url); } // Upon program launch, it will buffer a copy of the message, since // ArgReceived() is called before ReadyToRun(). RefsReceived(&message); }
void MyApplication::MessageReceived(BMessage *message) { switch (message->what){ case SAVE_AUDIO: if (Pool.save_selection && Pool.selection != NONE){ save_start = Pool.pointer; // save selection save_end = Pool.r_sel_pointer; }else{ save_start = 0; // save the whole memory save_end = Pool.size; } Save(message); break; case B_SIMPLE_DATA: case B_MIME_DATA: if (Pool.size == 0){ // drop on empty is load RefsReceived(message); }else{ app_info info; GetAppInfo(&info); be_roster->Launch(info.signature, message); } break; case UPDATE_MENU: Pool.UpdateMenu(); break; case DROP_PASTE: case B_PASTE: case CHANGE_LANGUAGE: mainWindow->PostMessage(message); break; default: BApplication::MessageReceived(message); break; } }
void Application::ArgvReceived(int32 argc, char** argv) { PRINT(("Application::ArgvReceived()\n")); BMessage msg (B_REFS_RECEIVED); for (int32 i = 1; i < argc; i++) { BEntry entry (argv[i]); entry_ref ref; entry.GetRef (& ref); if (entry.Exists()) msg.AddRef ("refs", & ref); else printf("File not found: %s\n", argv[i]); } RefsReceived(& msg); }
void BepdfApplication::ReadyToRun() { #if 1 mStdoutTracer = new OutputTracer(1, "stdout", GetSettings()); mStderrTracer = new OutputTracer(2, "stderr", GetSettings()); #else mStdoutTracer = mStderrTracer = NULL; #endif Initialize(); if (! mGotSomething) { // open start document entry_ref defaultDocument; BMessage msg(B_REFS_RECEIVED); get_ref_for_path (mDefaultPDF.Path(), &defaultDocument); msg.AddRef ("refs", &defaultDocument); RefsReceived (&msg); if (!mGotSomething) { // on error open file open dialog OpenFilePanel(); } } }
void FileTypes::MessageReceived(BMessage *message) { switch (message->what) { case kMsgSettingsChanged: fSettings.UpdateFrom(message); break; case kMsgOpenTypesWindow: if (fTypesWindow == NULL) { fTypesWindow = new FileTypesWindow(fSettings.Message()); fTypesWindow->Show(); fWindowCount++; } else fTypesWindow->Activate(true); break; case kMsgTypesWindowClosed: fTypesWindow = NULL; _WindowClosed(); break; case kMsgOpenApplicationTypesWindow: if (fApplicationTypesWindow == NULL) { fApplicationTypesWindow = new ApplicationTypesWindow( fSettings.Message()); fApplicationTypesWindow->Show(); fWindowCount++; } else fApplicationTypesWindow->Activate(true); break; case kMsgApplicationTypesWindowClosed: fApplicationTypesWindow = NULL; _WindowClosed(); break; case kMsgTypeWindowClosed: fTypeWindowCount--; // supposed to fall through case kMsgWindowClosed: _WindowClosed(); break; case kMsgOpenFilePanel: { // the open file panel sends us a message when it's done const char* subTitle; if (message->FindString("title", &subTitle) != B_OK) subTitle = B_TRANSLATE("Open file"); int32 what; if (message->FindInt32("message", &what) != B_OK) what = B_REFS_RECEIVED; BMessenger target; if (message->FindMessenger("target", &target) != B_OK) target = be_app_messenger; BString title = B_TRANSLATE("FileTypes"); if (subTitle != NULL && subTitle[0]) { title.Append(": "); title.Append(subTitle); } fFilePanel->SetMessage(new BMessage(what)); fFilePanel->Window()->SetTitle(title.String()); fFilePanel->SetTarget(target); if (!fFilePanel->IsShowing()) fFilePanel->Show(); break; } case B_SILENT_RELAUNCH: // In case we were launched via the add-on, there is no types // window yet. if (fTypesWindow == NULL) PostMessage(kMsgOpenTypesWindow); break; case B_CANCEL: if (fWindowCount == 0) PostMessage(B_QUIT_REQUESTED); break; case B_SIMPLE_DATA: RefsReceived(message); break; default: BApplication::MessageReceived(message); break; } }
void PApp::MessageReceived(BMessage *msg) { try { switch (msg->what) { case msg_SaveAll: { const doclist& lst = CDoc::DocList(); doclist::const_iterator di; for (di = lst.begin(); di != lst.end(); di++) { BWindow *w = dynamic_cast<PDoc*>(*di); if (w) w->PostMessage(msg_Save); } break; } case msg_CloseAll: { const doclist& lst = CDoc::DocList(); doclist::const_reverse_iterator di; for (di = lst.rbegin(); di != lst.rend(); di++) { PDoc *doc = dynamic_cast<PDoc*>(*di); if (doc && ! doc->IsWorksheet() && doc->Lock()) { if (doc->QuitRequested()) doc->Quit(); else { doc->Unlock(); break; } } } break; } case B_NODE_MONITOR: { CDoc::HandleFolderNodeMonitorMsg(msg); break; } case msg_OpenSelected: DialogCreator<COpenSelection>::CreateDialog(NULL); break; case msg_OpenInclude: { const char *i; FailOSErr(msg->FindString("include", &i)); const char *src = NULL; msg->FindString("from-source", &src); FindAndOpen(i, src); break; } case msg_FindCmd: { int c = 1 << current_workspace(); if (gPrefs->GetPrefInt(prf_I_SmartWorkspaces, 1)) FindDialog()->SetWorkspaces(c); FindDialog()->SetCaller(PDoc::TopWindow()); FindDialog()->Show(); FindDialog()->Activate(true); break; } case B_REFS_RECEIVED: case 'OpFi': RefsReceived(msg); break; case msg_About: { AboutWindow *abwin = new AboutWindow(); abwin->Show(); break; } case msg_IdeBringToFront: PDoc::IDEBringToFront(); break; case msg_IdeProjectToGroup: PDoc::IDEProject2Group(); break; case msg_FindDifferences: { BRect r(100,100,500,250); new CDiffWindow(r, "Differences"); break; } case msg_Open: { if (fOpenPanel->IsShowing()) { fOpenPanel->Window()->SetWorkspaces(1 << current_workspace()); fOpenPanel->Window()->Activate(); } else { BEntry entry; gCWD.GetEntry(&entry); BAutolock lock(fOpenPanel->Window()); entry_ref ref; entry.GetRef(&ref); fOpenPanel->SetPanelDirectory(&ref); fOpenPanel->Window()->SetWorkspaces(1 << current_workspace()); if (gPrefs->GetPrefInt(prf_I_ZoomOpenPanel, 0)) { BRect r = BScreen().Frame(); fOpenPanel->Window()->MoveTo(r.left + 80, r.top + 40); fOpenPanel->Window()->ResizeTo(480, r.Height() - 50); } fOpenPanel->Show(); } break; } case msg_CommandLineOpen: { entry_ref doc; FailOSErr (msg->FindRef("refs", &doc)); CDocWindow *w; BEntry e; if (e.SetTo(&doc) == B_OK && e.Exists()) w = dynamic_cast<CDocWindow*>(OpenWindow(doc)); else { w = NewWindow(NULL); w->SetEntryRef(&doc); } long lineNr; if (w && msg->FindInt32("line", &lineNr) == B_OK) { BMessage m(msg_SelectLines); FailOSErr(m.AddInt32("from", lineNr)); FailOSErr(m.AddInt32("to", lineNr - 1)); w->PostMessage(&m, w->PreferredHandler()); } if (w) { BMessage reply; reply.AddInt32("thread", w->Thread()); msg->SendReply(&reply); } break; } case B_SILENT_RELAUNCH: case msg_New: if (be_roster->IsRunning("application/x-vnd.dw-Paladin")) { BMessage newMsg(PALADIN_SHOW_ADD_NEW_PANEL); BMessenger msgr("application/x-vnd.dw-Paladin"); msgr.SendMessage(&newMsg); } else NewWindow(); break; case msg_Select: { PDoc *doc; if ((doc = PDoc::TopWindow()) != NULL) { BMessage copy(*msg); doc->PostMessage(©); } break; } case msg_DocClosed: if (CDoc::CountDocs() == 0) Quit(); break; case msg_Tile: PDoc::Tile(); break; case msg_Stack: PDoc::Stack(); break; case msg_Zoom: if (PDoc::TopWindow()) PDoc::TopWindow()->Zoom(); break; case msg_Worksheet: OpenWorksheet(); break; case msg_NewGroup: new PGroupWindow; break; case 1: puts(rcsid); break; case msg_Quit: PostMessage(B_QUIT_REQUESTED); break; case msg_Preferences: { long l; if (fPrefOpener) wait_for_thread(fPrefOpener, &l); fPrefOpener = (thread_id)NULL; if (fPrefsDialog) { BAutolock lock(fPrefsDialog); if (!lock.IsLocked()) { THROW(("Preferences panel failed to lock")); break; } int c = 1 << current_workspace(); if (gPrefs->GetPrefInt(prf_I_SmartWorkspaces, 1)) fPrefsDialog->SetWorkspaces(c); if (fPrefsDialog->IsHidden()) { fPrefsDialog->Show(); } fPrefsDialog->Activate(true); } else THROW(("Preferences panel failed to open")); break; } default: BApplication::MessageReceived(msg); } } catch (HErr& e) { e.DoError(); } } /* PApp::MessageReceived */
void FileTypes::MessageReceived(BMessage* message) { switch (message->what) { case kMsgSettingsChanged: fSettings.UpdateFrom(message); break; case kMsgOpenTypesWindow: if (fTypesWindow == NULL) { fTypesWindow = new FileTypesWindow(fSettings.Message()); if (fArgvType.Length() > 0) { // Set the window to the type that was requested on the // command line (-type), we do this only once, if we // ever opened more than one FileTypesWindow. fTypesWindow->SelectType(fArgvType.String()); fArgvType = ""; } fTypesWindow->Show(); fWindowCount++; } else fTypesWindow->Activate(true); break; case kMsgTypesWindowClosed: fTypesWindow = NULL; _WindowClosed(); break; case kMsgOpenApplicationTypesWindow: if (fApplicationTypesWindow == NULL) { fApplicationTypesWindow = new ApplicationTypesWindow( fSettings.Message()); fApplicationTypesWindow->Show(); fWindowCount++; } else fApplicationTypesWindow->Activate(true); break; case kMsgApplicationTypesWindowClosed: fApplicationTypesWindow = NULL; _WindowClosed(); break; case kMsgTypeWindowClosed: fTypeWindowCount--; // supposed to fall through case kMsgWindowClosed: _WindowClosed(); break; case kMsgOpenFilePanel: { // the open file panel sends us a message when it's done const char* subTitle; if (message->FindString("title", &subTitle) != B_OK) subTitle = B_TRANSLATE("Open file"); int32 what; if (message->FindInt32("message", &what) != B_OK) what = B_REFS_RECEIVED; BMessenger target; if (message->FindMessenger("target", &target) != B_OK) target = be_app_messenger; BString title = B_TRANSLATE("FileTypes"); if (subTitle != NULL && subTitle[0]) { title.Append(": "); title.Append(subTitle); } uint32 flavors = B_FILE_NODE; if (message->FindBool("allowDirs")) flavors |= B_DIRECTORY_NODE; fFilePanel->SetNodeFlavors(flavors); fFilePanel->SetMessage(new BMessage(what)); fFilePanel->Window()->SetTitle(title.String()); fFilePanel->SetTarget(target); if (!fFilePanel->IsShowing()) fFilePanel->Show(); break; } case B_SILENT_RELAUNCH: // In case we were launched via the add-on, there is no types // window yet. if (fTypesWindow == NULL) PostMessage(kMsgOpenTypesWindow); break; case B_CANCEL: if (fWindowCount == 0) PostMessage(B_QUIT_REQUESTED); break; case B_SIMPLE_DATA: RefsReceived(message); break; default: BApplication::MessageReceived(message); break; } }
void App::ArgvReceived(int32 argc,char **argv) { bool showUsage = false; bool verbose = false; int32 i = 1; for (i = 1; i < argc; i++) { int arglen = strlen(argv[i]); char *arg = argv[i]; char opt; if (arglen == 2 && arg[0] == '-') opt = arg[1]; else break; switch (opt) { case 'b': { gBuildMode = true; break; } case 'm': { gMakeMode = true; break; } case 'r': { gBuildMode = true; fBuildCleanMode = true; break; } case 's': { gSingleThreadedBuild = true; break; } #ifdef USE_TRACE_TOOLS case 'v': { verbose = true; break; } case 'd': { gPrintDebugMode = 1; break; } #endif default: { showUsage = true; break; } } } if (gPrintDebugMode > 0 && verbose) gPrintDebugMode = 2; if (showUsage) { PrintUsage(); // A quick hack to not show the start window before // the quit request has been processed sWindowCount++; PostMessage(B_QUIT_REQUESTED); return; } if (gPrintDebugMode == 1) printf(B_TRANSLATE("Printing debug output\n")); else if (gPrintDebugMode == 2) printf(B_TRANSLATE("Printing debug output with extra detail\n")); if (gSingleThreadedBuild) STRACE(1,("Disabling multithreaded project building\n")); BMessage refmsg; int32 refcount = 0; // No initialization -- keep the value from the previous loop BEntry projfolder(gProjectPath.GetFullPath()); entry_ref projref; projfolder.GetRef(&projref); for (; i < argc; i++) { // See if the project specified lacks an extension and append it BString projPath(argv[i]); if (projPath.FindLast(".pld") != projPath.CountChars() - 4) { projPath << ".pld"; printf(B_TRANSLATE("Attempting to open %s\n"), projPath.String()); } BEntry entry(projPath.String()); entry_ref ref; if (!entry.Exists()) { ref = FindProject(projref,projPath.String()); if (!ref.name) { printf(B_TRANSLATE("Can't find file %s\n"),argv[i]); continue; } } else entry.GetRef(&ref); refmsg.AddRef("refs",&ref); refcount++; optind++; if (refcount == 1 && (gBuildMode || gMakeMode)) break; } if (refcount > 0) RefsReceived(&refmsg); else if (gBuildMode || gMakeMode) Quit(); }
void BYdpMainWindow::MessageReceived(BMessage *Message) { int item; this->DisableUpdates(); switch (Message->what) { case MSG_MODIFIED_INPUT: HandleModifiedInput(false); break; case MSG_LIST_INVOKED: item = dictList->CurrentSelection(0); wordInput->SetText(((BStringItem*)dictList->ItemAt(item))->Text()); break; case MSG_LIST_SELECTED: item = dictList->CurrentSelection(0); if (item>dictList->CountItems()) item = dictList->CountItems(); if (item>=0) myDict->GetDefinition(myDict->wordPairs[item+dictList->topIndex]); break; case MSG_LISTUP: case MSG_LISTDOWN: // printf("got listup\n"); myDict->GetDefinition(myDict->wordPairs[dictList->topIndex+dictList->CurrentSelection(0)]); break; // case MSG_LISTDOWN: // printf("got listdown\n"); // myDict->GetDefinition(myDict->wordPairs[dictList->topIndex+dictList->CurrentSelection(0)]); // break; case MSG_CLEAR_INPUT: wordInput->SetText(""); wordInput->MakeFocus(); break; case MENU_ENG2POL: UpdateLanguages(true); break; case MENU_POL2ENG: UpdateLanguages(false); break; case MENU_SWITCH: UpdateLanguages(!config->toPolish); break; case MENU_FUZZY: config->searchmode = SEARCH_FUZZY; config->save(); HandleModifiedInput(true); UpdateMenus(); break; case MENU_PLAIN: config->searchmode = SEARCH_BEGINS; config->save(); HandleModifiedInput(true); UpdateMenus(); break; /* case MENU_ENGINESQ2: SwitchEngine(DICTIONARY_SQ2); break; */ case MENU_ENGINESAP: SwitchEngine(DICTIONARY_SAP); break; case MENU_ENGINEYDP: SwitchEngine(DICTIONARY_YDP); break; case MENU_PATH: ConfigPath(); break; case MENU_COLOR0: ConfigColour(0); break; case MENU_COLOR1: ConfigColour(1); break; case MENU_COLOR2: ConfigColour(2); break; case MENU_COLOR3: ConfigColour(3); break; case MENU_CLIP: config->clipboardTracking = !config->clipboardTracking; config->save(); UpdateMenus(); break; case MENU_FOCUS: config->setFocusOnSelf = !config->setFocusOnSelf; config->save(); UpdateMenus(); break; case MENU_DISTANCE: ConfigDistance(); break; /* case MENU_SQL: ConfigSQLTables(); break; */ case MENU_ABOUT: { BString about; about = "\n\n" APP_NAME " " APP_VERSION "\n"; about += "English-Polish, Polish-English dictionary\n"; about += "\n\nBeOS version:\n"; about += "Maciej Witkowiak <*****@*****.**>"; about += "\n\nSAP engine based on sap v0.2b\n"; about += "(c) 1998 Bohdan R. Rau,\n(c) 2001 Daniel Mealha Cabrita"; about += "\nYDP and SQL engines by Maciej Witkowiak\n"; about += "\n\nSoftware released under GNU/GPL license"; about += "\n\nvisit:\n"; about += "http://home.elysium.pl/ytm/html/beos.html\n"; about += "\nDevelopment has been encouraged by:\n"; about += "http://www.haiku-os.pl"; outputView->SetText(about.String()); } break; case FONT_SIZE: { float fontSize; Message->FindFloat("size",&fontSize); SetFontSize(fontSize); } break; case FONT_FAMILY: { const char * fontFamily = 0, * fontStyle = 0; void * ptr; if (Message->FindPointer("source",&ptr) == B_OK) { currentFontItem = static_cast<BMenuItem*>(ptr); fontFamily = currentFontItem->Label(); } SetFontStyle(fontFamily, fontStyle); } case FONT_STYLE: { const char * fontFamily = 0, * fontStyle = 0; void * ptr; if (Message->FindPointer("source",&ptr) == B_OK) { BMenuItem * item = static_cast<BMenuItem*>(ptr); fontStyle = item->Label(); BMenu * menu = item->Menu(); if (menu != 0) { currentFontItem = menu->Superitem(); if (currentFontItem != 0) { fontFamily = currentFontItem->Label(); } } } SetFontStyle(fontFamily, fontStyle); } case MSG_SCROLL: // printf("scroll value changed\n"); if (scrollBar->Value() != dictList->topIndex) { dictList->ListScrolled(scrollBar->Value()); myDict->GetDefinition(myDict->wordPairs[dictList->topIndex+dictList->CurrentSelection(0)]); } break; case MSG_COLOURUPDATE: // printf("colour update\n"); myDict->ReGetDefinition(); break; case MSG_FUZZYUPDATE: // printf("fuzzy update\n"); if (config->searchmode == SEARCH_FUZZY) HandleModifiedInput(true); break; /* case MSG_SQLTABLESUPDATE: // printf("sql tables updated\n"); myDict->FlushCache(); SwitchEngine(config->dictionarymode); break; */ case B_CLIPBOARD_CHANGED: NewClipData(); break; case B_REFS_RECEIVED: RefsReceived(Message); break; case B_CANCEL: // printf("canceled\n"); if (firstStart) { config->dictionarymode = DICTIONARY_SAP; // will be saved in QuitRequested below BAlert *alert = new BAlert(APP_NAME, "Couldn't open dictionary. Dictionary engine has been reset to SAP.", "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); alert->Go(); QuitRequested(); } else delete myPanel; // break; default: BWindow::MessageReceived(Message); break; } this->EnableUpdates(); }
void ExpanderWindow::MessageReceived(BMessage* msg) { switch (msg->what) { case MSG_SOURCE: { BEntry entry(fSourceText->Text(), true); entry_ref srcRef; if (entry.Exists() && entry.IsDirectory()) entry.GetRef(&srcRef); if (!fSourcePanel) { BMessenger messenger(this); fSourcePanel = new BFilePanel(B_OPEN_PANEL, &messenger, &srcRef, B_FILE_NODE, false, NULL, new RuleRefFilter(fRules), true); (fSourcePanel->Window())->SetTitle( B_TRANSLATE("Expander: Open")); } else fSourcePanel->SetPanelDirectory(&srcRef); fSourcePanel->Show(); break; } case MSG_DEST: { BEntry entry(fDestText->Text(), true); entry_ref destRef; if (entry.Exists() && entry.IsDirectory()) entry.GetRef(&destRef); if (!fDestPanel) { BMessenger messenger(this); fDestPanel = new DirectoryFilePanel(B_OPEN_PANEL, &messenger, &destRef, B_DIRECTORY_NODE, false, NULL, new DirectoryRefFilter(), true); } else fDestPanel->SetPanelDirectory(&destRef); fDestPanel->Show(); break; } case MSG_DIRECTORY: { entry_ref ref; fDestPanel->GetPanelDirectory(&ref); fDestRef = ref; BEntry entry(&ref); BPath path(&entry); fDestText->SetText(path.Path()); fDestPanel->Hide(); break; } case B_SIMPLE_DATA: case B_REFS_RECEIVED: RefsReceived(msg); break; case MSG_EXPAND: if (!ValidateDest()) break; if (!fExpandingStarted) { StartExpanding(); break; } // supposed to fall through case MSG_STOP: if (fExpandingStarted) { fExpandingThread->SuspendExternalExpander(); BAlert* alert = new BAlert("stopAlert", B_TRANSLATE("Are you sure you want to stop expanding this\n" "archive? The expanded items may not be complete."), B_TRANSLATE("Stop"), B_TRANSLATE("Continue"), NULL, B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_WARNING_ALERT); if (alert->Go() == 0) { fExpandingThread->ResumeExternalExpander(); StopExpanding(); } else fExpandingThread->ResumeExternalExpander(); } break; case MSG_SHOW: fShowContents->SetValue(fShowContents->Value() == B_CONTROL_OFF ? B_CONTROL_ON : B_CONTROL_OFF); // supposed to fall through case MSG_SHOWCONTENTS: // change menu item label fShowItem->SetLabel(fShowContents->Value() == B_CONTROL_OFF ? B_TRANSLATE("Show contents") : B_TRANSLATE("Hide contents")); if (fShowContents->Value() == B_CONTROL_OFF) { if (fListingStarted) StopListing(); _UpdateWindowSize(false); } else StartListing(); break; case MSG_SOURCETEXT: { BEntry entry(fSourceText->Text(), true); if (!entry.Exists()) { BAlert* alert = new BAlert("srcAlert", B_TRANSLATE("The file doesn't exist"), B_TRANSLATE("Cancel"), NULL, NULL, B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_WARNING_ALERT); alert->Go(); break; } entry_ref ref; entry.GetRef(&ref); ExpanderRule* rule = fRules.MatchingRule(&ref); if (rule) { fSourceChanged = true; fSourceRef = ref; fShowContents->SetEnabled(true); fExpandButton->SetEnabled(true); fExpandItem->SetEnabled(true); fShowItem->SetEnabled(true); break; } BString string = "The file : "; string += fSourceText->Text(); string += B_TRANSLATE_MARK(" is not supported"); BAlert* alert = new BAlert("srcAlert", string.String(), B_TRANSLATE("Cancel"), NULL, NULL, B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_INFO_ALERT); alert->Go(); fShowContents->SetEnabled(false); fExpandButton->SetEnabled(false); fExpandItem->SetEnabled(false); fShowItem->SetEnabled(false); } break; case MSG_DESTTEXT: ValidateDest(); break; case MSG_PREFERENCES: if (!fPreferences) fPreferences = new ExpanderPreferences(&fSettings); fPreferences->Show(); break; case 'outp': if (!fExpandingStarted && fListingStarted) { BString string; int32 i = 0; while (msg->FindString("output", i++, &string) == B_OK) { float length = fListingText->StringWidth(string.String()); if (length > fLongestLine) fLongestLine = length; fListingText->Insert(string.String()); } fListingText->ScrollToSelection(); } else if (fExpandingStarted) { BString string; int32 i = 0; while (msg->FindString("output", i++, &string) == B_OK) { if (strstr(string.String(), "Enter password") != NULL) { fExpandingThread->SuspendExternalExpander(); BString password; PasswordAlert* alert = new PasswordAlert("passwordAlert", string); alert->Go(password); fExpandingThread->ResumeExternalExpander(); fExpandingThread->PushInput(password); } } } break; case 'errp': { BString string; if (msg->FindString("error", &string) == B_OK && fExpandingStarted) { fExpandingThread->SuspendExternalExpander(); if (strstr(string.String(), "password") != NULL) { BString password; PasswordAlert* alert = new PasswordAlert("passwordAlert", string); alert->Go(password); fExpandingThread->ResumeExternalExpander(); fExpandingThread->PushInput(password); } else { BAlert* alert = new BAlert("stopAlert", string, B_TRANSLATE("Stop"), B_TRANSLATE("Continue"), NULL, B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_WARNING_ALERT); if (alert->Go() == 0) { fExpandingThread->ResumeExternalExpander(); StopExpanding(); } else fExpandingThread->ResumeExternalExpander(); } } break; } case 'exit': // thread has finished (finished, quit, killed, we don't know) // reset window state if (fExpandingStarted) { fStatusView->SetText(B_TRANSLATE("File expanded")); StopExpanding(); OpenDestFolder(); CloseWindowOrKeepOpen(); } else if (fListingStarted) { fSourceChanged = false; StopListing(); _ExpandListingText(); } else fStatusView->SetText(""); break; case 'exrr': // thread has finished // reset window state fStatusView->SetText(B_TRANSLATE("Error when expanding archive")); CloseWindowOrKeepOpen(); break; default: BWindow::MessageReceived(msg); break; } }