//==================================== // 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_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 == SAX_INPUT_VNC) { baseDriver = "rfbmouse"; } QDict<QString>* data = mInput->getTablePointer (0); int newID = mInput->getCount (true) * 2 + 1; if ((data) && (! data->isEmpty())) { baseDriver ="kbd"; if (fashion == 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(); }
//==================================== // 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) { 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++) { QDict<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(); }
//==================================== // remove and reorganize section ID... //------------------------------------ bool SaXStorage::delID ( int id ) { // .../ //! remove a data record and adapt the Identifier strings //! to provide consistency // ---- if ((! mData.at (id)) || (mData.at(id)->isEmpty())) { return false; } int step = 1; int type = SAX_DESKTOP_TYPE; QString ident = *mData.at(id)->find ("Identifier"); if (ident.contains ("Mouse")) { type = SAX_POINTER_TYPE; step = 2; } if (ident.contains ("Keyboard")) { type = SAX_KEYBOARD_TYPE; step = 2; } int index = -1; QListIterator < QDict<QString> > in (mData); for (; in.current(); ++in) { index++; QDict<QString>* data = in.current(); QString* ident = data->find ("Identifier"); if (! ident) { continue; } int curType = SAX_DESKTOP_TYPE; if (ident->contains("Mouse")) { curType = SAX_POINTER_TYPE; } if (ident->contains("Keyboard")) { curType = SAX_KEYBOARD_TYPE; } if ((data->isEmpty()) || (index <= id) || (curType != type)) { continue; } QString oIDstr; QString nIDstr; oIDstr.sprintf ("%d",index); nIDstr.sprintf ("%d",index - step); QString mouseIDstr ("Mouse[" + oIDstr +"]"); QString keyboardIDstr ("Keyboard["+ oIDstr +"]"); QString deviceIDstr ("Device[" + oIDstr +"]"); QString monitorIDstr ("Monitor[" + oIDstr +"]"); QString screenIDstr ("Screen[" + oIDstr +"]"); QDictIterator<QString> it (*data); for (; it.current(); ++it) { QString val = *it.current(); QString key = it.currentKey(); if (val == mouseIDstr) { QString* nMouseIDstr = new QString ("Mouse["+nIDstr+"]"); data -> replace (key,nMouseIDstr); } if (val == keyboardIDstr) { QString* nKbdIDstr = new QString ("Keyboard["+nIDstr+"]"); data -> replace (key,nKbdIDstr); } if (val == deviceIDstr) { QString* nDeviceIDstr = new QString ("Device["+nIDstr+"]"); data -> replace (key,nDeviceIDstr); } if (val == monitorIDstr) { QString* nMonitorIDstr = new QString ("Monitor["+nIDstr+"]"); data -> replace (key,nMonitorIDstr); } if (val == screenIDstr) { QString* nScreenIDstr = new QString ("Screen["+nIDstr+"]"); data -> replace (key,nScreenIDstr); } if ((key == "Screen") && (val == oIDstr)) { QString* nScreenIDstr = new QString (nIDstr); data -> replace (key,nScreenIDstr); } } } mData.remove (id); if ((mData.at(id)) && (mData.at(id)->isEmpty())) { mData.remove (id); } return true; }