Example #1
0
void File::WriteToDisk(std::string &basePath, DiskWriter *writer) {
    if (!written || rewrite) {
        writer->WriteFile(basePath.c_str(), filename.c_str(), data.getData(), data.getLength());
        data=CharArray();
        written=true;
        rewrite=false;
        ReportChange();
    }
}
Example #2
0
void Directory::WriteToDisk(std::string &basePath, DiskWriter *writer) {
    if (!written) {
        writer->WriteDirectory(basePath.c_str(), filename.c_str());
        written=true;
        ReportChange();
    }
    std::string newBasePath=basePath+'/'+filename;
    for (std::list<Ptr>::iterator it=children.begin(); it != children.end(); ++it) {
        (*it)->WriteToDisk(newBasePath, writer);
    }
}
void ArpRemoteTerminal::TermReset(bool hard)
{
	ArpD(cdb << ADH << "ArpRemoteTerminal: Reset hard=" << hard << endl);
	inherited::TermReset(hard);
	if( HaveWatchers() ) {
		BMessage config;
		if( GetConfiguration(&config) == B_NO_ERROR ) {
			ArpD(cdb << ADH << "Reporting change: " << config << endl);
			ReportChange(&config);
		}
	}
}
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::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();
}