コード例 #1
0
ファイル: device.cpp プロジェクト: BackupTheBerlios/sax-svn
//====================================
// removeInputDevice
//------------------------------------
int SaXManipulateDevices::removeInputDevice (int id) {
	// .../
	//! remove the input device of the given id (id) and return the
	//! previous input device id. The current input device id is set
	//! to this previous input device id. If the input device does
	//! not exist or the input device id is the core (0|1) mouse or
	//! keyboard the method will return (-1)
	// ----
	if (! inputHandlingAllowed) {
		return -1;
	}
	//====================================
	// don't allow removing the core entry   
	//------------------------------------
	if ((id <= 1) && (mInput->getCount() <= 2)) {
		excInvalidArgument (id);
		qError (errorString(),EXC_INVALIDARGUMENT);
		return -1;
	}
	//====================================
	// remove input devices...
	//------------------------------------
	if (! mInput->delID (id)) {
		return -1;
	}
	//====================================
	// select previous input device
	//------------------------------------
	for (int i=1;i<=2;i++) {
		Q3Dict<QString>* data = mInput->getTablePointer (i);
		if ((data) && (! data->isEmpty())) {
			mInput->setID (i);
			break;
		}
	}
	//====================================
	// check input device type
	//------------------------------------
	bool isMouse = true;
	QString baseItem ("InputDevice");
	QString baseID   ("Mouse");
	if (mInput->getCurrentID() % 2 == 0) {
		isMouse  = false;
		baseItem = "Keyboard";
		baseID   = "Keyboard";
	}
	//====================================
	// update server layout
	//------------------------------------
	QString result;
	QString IDstring;
	IDstring.sprintf ("%d",id);
	QString deviceList  = mLayout -> getItem (baseItem);
	QStringList optlist = QStringList::split ( ",", deviceList );
	for ( QStringList::Iterator
		in = optlist.begin(); in != optlist.end(); ++in
	) {
		QString item (*in);
		if (item == QString(baseID + "["+IDstring+"]")) {
			continue;
		}
		QRegExp identifier ("\\[(.+)\\]");
		int pos = identifier.search (item);
		if (pos >= 0) {
			int curID = identifier.cap(1).toInt();
			if ( curID > id ) {
				QString newMK;
				newMK.sprintf ("%s[%d],",baseID.ascii(),curID - 2);
				result.append ( newMK );
			} else {
				result.append (item+",");
			}
		}
	}
	result.remove (result.length()-1,result.length());
	mLayout -> setItem (baseItem,result);
	return mInput -> getCurrentID();
}
コード例 #2
0
ファイル: device.cpp プロジェクト: BackupTheBerlios/sax-svn
//====================================
// addInputDevice
//------------------------------------
int SaXManipulateDevices::addInputDevice (const char* fashion) {
	// .../
	//! add a new input device at the end of the current input
	//! device list. The new input device ID is returned. pointer
	//! input devices are following the odd order (1,3,5,7...)
	//! whereas keyboard input devices use the even order (0,2,4,6...)
	// ----
	if (! inputHandlingAllowed) {
		return -1;
	}
	//====================================
	// check fashion string...
	//------------------------------------
	QString inputFashion (fashion);
	if (
		(inputFashion != SAX_INPUT_TOUCHPANEL) &&
		(inputFashion != SAX_INPUT_TABLET)     &&
		(inputFashion != SAX_INPUT_PEN)        &&
		(inputFashion != SAX_INPUT_PAD)        &&
		(inputFashion != SAX_INPUT_ERASER)     &&
		(inputFashion != SAX_INPUT_MOUSE)      &&
		(inputFashion != SAX_INPUT_VNC)        &&
		(inputFashion != SAX_INPUT_KEYBOARD)
	) {
		excWrongInputFashion (fashion);
		qError (errorString(),EXC_WRONGINPUTFASHION);
		return -1;
	}
	//====================================
	// determine new input device ID...
	//------------------------------------
	QString baseID ("Mouse");
	QString baseDriver ("mouse");
	if (fashion == (char*)SAX_INPUT_VNC) {
		baseDriver = "rfbmouse";
	}
	Q3Dict<QString>* data = mInput->getTablePointer (0);
	int newID = mInput->getCount (true) * 2 + 1;
	if ((data) && (! data->isEmpty())) {
		baseDriver ="kbd";
		if (fashion == (char*)SAX_INPUT_VNC) {
			baseDriver = "rfbkeyb";
		}
		baseID = "Keyboard";
		newID  = mInput->getCount (true) * 2;
	}
	if (! mInput -> addID (newID)) {
		return -1;
	}
	//====================================
	// add new input device section...
	//------------------------------------
	QString newIDstring;
	newIDstring.sprintf ("%d",newID);
	mInput -> setItem ("Identifier",baseID + "[" + newIDstring + "]");
	mInput -> setItem ("InputFashion",fashion);
	//====================================
	// set some defaults...
	//------------------------------------
	mInput -> setItem ("Driver",baseDriver);
	//====================================
	// update server layout
	//------------------------------------
	if (baseID == "Mouse") {
		QString inputDevice; QTextOStream (&inputDevice) 
			<< mLayout -> getItem ("InputDevice")
			<< ",Mouse[" << newIDstring << "]";
		mLayout -> setItem ("InputDevice",inputDevice);
	}
	if (baseID == "Keyboard") {
		QString inputDevice; QTextOStream (&inputDevice)
			<< mLayout -> getItem ("Keyboard")
			<< ",Keyboard[" << newIDstring << "]";
		mLayout -> setItem ("Keyboard",inputDevice);
	}
	return mInput -> getCurrentID();
}