void Advanced_Settings_Window::on_TB_Add_Emulator_clicked() { Emulator_Options_Window *emulatorOptionsWin = new Emulator_Options_Window( this ); emulatorOptionsWin->Set_All_Emulators_Names( Get_All_Emulators_Names() ); emulatorOptionsWin->Set_Emulator( Emulator() ); if( emulatorOptionsWin->exec() == QDialog::Accepted ) { Emulator new_emul = emulatorOptionsWin->Get_Emulator(); // This Default Emulator? bool finded = false; for( int ix = 0; ix < Emulators.count(); ix++ ) { if( Emulators[ix].Get_Type() == new_emul.Get_Type() && Emulators[ix].Get_Default() ) { finded = true; } } if( finded == false ) new_emul.Set_Default( true ); Emulators << new_emul; Update_Emulators_Info(); } delete emulatorOptionsWin; }
void ArpRemoteTerminal::SendEmulatorsMsg(void) { if( !device.IsValid() || !manager ) return; BAutolock(manager->Lock()); BMessage msg(TERM_EMULATORS_MSG); const ArpEmulationType* type = Emulator().EmulationType(); if( !add_emu_info(msg,type) ) return; for( int i=0; i<manager->CountAddons(); i++ ) { ArpEmulatorManager::EmulatorAddon* adimage = (ArpEmulatorManager::EmulatorAddon*) manager->AddonAt(i); const ArpEmulatorAddon* addon = adimage->GetEmulator(); if( addon ) { for( int j=0; j<addon->CountEmulations(); j++ ) { type = addon->EmulationType(j); if( !add_emu_info(msg,type) ) return; } } } device.SendMessage(&msg); }
status_t ArpRemoteTerminal::PutConfiguration(const BMessage* values) { if( !values ) return B_BAD_VALUE; // Use the ArpMessage interface for extracting our values, since it // provides some convenience functions for working with colors // and fonts. ArpMessage msg(*values); int i; const bool locked = LockLooper(); try { int32 mode = 0; bool hasMode = msg.HasInt32(ModeConfigName); if( hasMode ) TermSetMode((mode=msg.GetInt32(ModeConfigName, TermMode()))); if( msg.HasString(LFCharsConfigName) ) TermSetLFChars(msg.GetString(LFCharsConfigName, TermLFChars())); else if( hasMode && (mode&1<<1) ) TermSetLFChars("\n"); if( msg.HasString(CRCharsConfigName) ) TermSetCRChars(msg.GetString(CRCharsConfigName, TermCRChars())); else if( hasMode && (mode&1<<1) ) TermSetCRChars("\n\r"); if( msg.HasString(EnterStreamConfigName) ) TermSetEnterStream(msg.GetString(EnterStreamConfigName, TermEnterStream())); else if( hasMode && (mode&1<<6) ) TermSetEnterStream("\n"); if( msg.HasFont(PlainFontConfigName) ) { BFont font(&GetStyledFont(TERM_STYLEPLAIN)); if( msg.FindFont(PlainFontConfigName, &font) == B_OK ) { SetFont(&font); } } if( msg.HasInt32(EncodingConfigName) ) TermSetEncoding(msg.GetInt32(EncodingConfigName, TermEncoding())); if( msg.HasInt32(StyleConfigName) ) TermSetStyle(msg.GetInt32(StyleConfigName, TermStyle())); if( msg.HasFloat("Tint Foreground") ) { SetTintForeground(msg.GetFloat("Tint Foreground", 1.75)); } if( msg.HasFloat("Tint Background") ) { SetTintBackground(msg.GetFloat("Tint Background", .25)); } { char* name; type_code type; int32 count; for( i=0; msg.GetInfo(B_RGB_COLOR_TYPE,i,&name,&type,&count)==B_OK; i++ ) { int32 idx = ColorVar2Index(name); if( idx >= 0 ) { bool bg=false; TermColorID col = ColorIndex2ID(idx, &bg); if( bg ) backcolor_from_msg(msg, name, 0, col); else forecolor_from_msg(msg, name, 0, col); } } } if( msg.HasInt32(NumRowsConfigName) || msg.HasInt32(NumColsConfigName) ) { int32 r=0,c=0; TermGetFixedSize(&r, &c); TermSetFixedSize(msg.GetInt32(NumRowsConfigName, r), msg.GetInt32(NumColsConfigName, c)); } if( msg.HasInt32(RegionTopConfigName) || msg.HasInt32(RegionBottomConfigName) || msg.HasInt32(RegionLeftConfigName) || msg.HasInt32(RegionRightConfigName) ) { int32 t=0, b=0, l=0, r=0; TermGetRegion(&t, &b, &l, &r); TermSetRegion(msg.GetInt32(RegionTopConfigName, t), msg.GetInt32(RegionBottomConfigName, b), msg.GetInt32(RegionLeftConfigName, l), msg.GetInt32(RegionRightConfigName, r)); } if( msg.HasInt32(AutoScrollConfigName) ) SetAutoScrollMode((AutoScrollType)msg.GetInt32(AutoScrollConfigName, AutoScrollMode())); if( msg.HasInt32(HistoryUseConfigName) ) SetHistoryUse((HistoryUseType)msg.GetInt32(HistoryUseConfigName, HistoryUse())); if( msg.HasInt32(HistorySizeConfigName) ) SetHistorySize(msg.GetInt32(HistorySizeConfigName, HistorySize())); if( msg.HasBool(VerifyPasteConfigName) ) SetPasteVerified(msg.GetBool(VerifyPasteConfigName, PasteVerified())); if( msg.HasBool(RMBPasteConfigName) ) SetRMBPaste(msg.GetBool(RMBPasteConfigName, RMBPaste())); if( msg.HasString(CurEmulatorConfigName) ) { const char* name = msg.GetString(CurEmulatorConfigName, 0); if( name ) { const ArpEmulationType* type = Emulator().EmulationType(); if( !type || strcmp(name, type->Name) ) { delete SetEmulator(name); } } } TermClean(); } catch(...) { if( locked ) UnlockLooper(); throw; } ReportChange(&msg); if( locked ) UnlockLooper(); return msg.GetError(); }
void ArpRemoteTerminal::MessageReceived(BMessage *message) { ArpD(cdb << ADH << "ArpRemoteTerminal::MessageReceived: " << *message << endl); switch( message->what ) { case TERM_XFER_TEXT_MSG: { #if 1 const ichar* txt = NULL; long len=0; int32 idx=0; while( message->FindData("text", B_ASCII_TYPE, idx, (const void**)&txt, &len) == B_NO_ERROR ) { if( txt && len > 0 ) { Emulator().EmulateToTTY(txt,len); } idx++; } message->SendReply(B_NO_REPLY); #else int32 recpos = 0; BMessage* curmsg = Window()->DetachCurrentMessage(); BMessageQueue* queue = Window()->MessageQueue(); while( curmsg ) { ichar* txt = NULL; long len=0; int32 idx=0; while( curmsg->FindData("text", B_ASCII_TYPE, idx, &txt, &len) == B_NO_ERROR ) { if( txt ) { if( recpos + len > sizeof(receiveBuffer) ) { if( recpos > 0 ) { Emulator().EmulateToTTY(&receiveBuffer[0],recpos); recpos = 0; } } if( len > sizeof(receiveBuffer) ) { Emulator().EmulateToTTY(txt,len); } else { memcpy(&receiveBuffer[recpos],txt,len); recpos += len; } } idx++; } delete curmsg; curmsg = NULL; if( queue ) { curmsg = queue->FindMessage((int32)0); if( curmsg && curmsg->what == TERM_XFER_TEXT_MSG ) { curmsg = queue->NextMessage(); } else curmsg = NULL; } } if( recpos > 0 ) { Emulator().EmulateToTTY(&receiveBuffer[0],recpos); } return; #endif } break; case TERM_RESET_MSG: { bool hard = false; if( message->FindBool("hard", &hard) != B_OK ) hard = false; Emulator().Reset(hard); TermClean(); // HACK: The emulator often changes the terminal's mode // flags after calling its reset, leaving any active // settings view with incorrect settings. Until we can // do better at tracking state changes, for this situation // send another update to the settings view. if( HaveWatchers() ) { BMessage config; if( GetConfiguration(&config) == B_NO_ERROR ) { ArpD(cdb << ADH << "Reporting change: " << config << endl); ReportChange(&config); } } } break; case TERM_START_SESSION_MSG: { StartSession(); TermClean(); Owner().SendMessage(message); } break; case TERM_END_SESSION_MSG: { EndSession(); TermClean(); Owner().SendMessage(message); } break; case TERM_REQUEST_STATUS_MSG: { int32 rows,cols; TermGetSize(&rows,&cols); SendSizeMsg(rows,cols); SendEmulatorsMsg(); } break; case TERM_WINDOW_SIZE_MSG: { int32 rows,cols; TermGetFixedSize(&rows,&cols); message->FindInt32("rows",&rows); message->FindInt32("columns",&cols); TermSetFixedSize(rows,cols); } break; case TERM_SELECT_EMULATION_MSG: { BMenuItem* item = NULL; if( message->FindPointer("source",(void**)&item) ) item = NULL; BMenu* menu = NULL; if( item ) menu = item->Menu(); int32 num=0; type_code type; if( !message->GetInfo("name",&type,&num) ) { for( int i=0; i<num; i++ ) { const char* str; if( !message->FindString("name",i,&str) ) { delete SetEmulator(str); if( !IsDefaultEmulator() ) { if( menu ) CheckEmulationMenu(menu); return; } } } } if( menu ) CheckEmulationMenu(menu); } break; case ARP_PUT_CONFIGURATION_MSG: { BMessage config; if( message->FindMessage("settings",&config) == B_NO_ERROR ) { PutConfiguration(&config); } else { inherited::MessageReceived(message); } } break; case TERM_ADD_WATCHER_MSG: { BMessenger w; if( message->FindMessenger("watch",&w) == B_NO_ERROR ) { AddWatcher(w); BMessage config; if( GetConfiguration(&config) == B_NO_ERROR ) { ReportChange(&config, &w); } } else { inherited::MessageReceived(message); } } break; case TERM_REM_WATCHER_MSG: { BMessenger w; if( message->FindMessenger("watch",&w) == B_NO_ERROR ) { RemWatcher(w); } else { inherited::MessageReceived(message); } } break; default: inherited::MessageReceived(message); } }
status_t ArpRemoteTerminal::GetConfiguration(BMessage* values) const { if( !values ) return B_BAD_VALUE; // Use the ArpMessage interface for adding our values, since it // provides some convenience functions for working with colors // and fonts. ArpMessage msg(*values); int i; const bool locked = const_cast<ArpRemoteTerminal*>(this)->LockLooper(); try { ArpD(cdb << ADH << "Getting settings; initial error = " << (msg.GetError()) << endl); msg.SetInt32(ModeConfigName, TermMode()); msg.SetString(LFCharsConfigName, TermLFChars()); msg.SetString(CRCharsConfigName, TermCRChars()); msg.SetString(EnterStreamConfigName, TermEnterStream()); msg.SetFont(PlainFontConfigName, &GetStyledFont(TERM_STYLEPLAIN)); msg.SetInt32(EncodingConfigName, TermEncoding()); msg.SetInt32(StyleConfigName, TermStyle()); const char* varName; for( i=0; (varName=ColorIndex2Var(i)) != 0; i++ ) { bool bg=false; TermColorID col = ColorIndex2ID(i, &bg); if( bg ) msg.SetRGBColor(varName, ArpColor(TermTextBackground(col))); else msg.SetRGBColor(varName, ArpColor(TermTextForeground(col))); } { int32 r=0,c=0; TermGetFixedSize(&r, &c); msg.SetInt32(NumRowsConfigName, r); msg.SetInt32(NumColsConfigName, c); } { int32 t=0, b=0, l=0, r=0; TermGetRegion(&t, &b, &l, &r); msg.SetInt32(RegionTopConfigName, t); msg.SetInt32(RegionBottomConfigName, b); msg.SetInt32(RegionLeftConfigName, l); msg.SetInt32(RegionRightConfigName, r); } msg.SetInt32(AutoScrollConfigName, AutoScrollMode()); msg.SetInt32(HistoryUseConfigName, HistoryUse()); msg.SetInt32(HistorySizeConfigName, HistorySize()); msg.SetBool(VerifyPasteConfigName, PasteVerified()); msg.SetBool(RMBPasteConfigName, RMBPaste()); const ArpEmulationType* type = Emulator().EmulationType(); if( type ) { msg.AddString(CurEmulatorConfigName, type->Synonym ? type->Synonym : type->Name); } ArpD(cdb << ADH << "Got settings; final error = " << (msg.GetError()) << endl); if( msg.GetError() == B_NO_ERROR ) { *values = msg; } } catch(...) { if( locked ) const_cast<ArpRemoteTerminal*>(this)->UnlockLooper(); throw; } if( locked ) const_cast<ArpRemoteTerminal*>(this)->UnlockLooper(); return msg.GetError(); }