00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "device.h"
00022
00023 namespace SaX {
00024
00025
00026
00027 SaXManipulateDevices::SaXManipulateDevices (
00028 SaXImport* desktop ,SaXImport* card ,SaXImport* layout
00029 ) {
00030
00038
00039 desktopHandlingAllowed = false;
00040 inputHandlingAllowed = false;
00041 if ( (!desktop) || (!card) || (!layout)) {
00042 excNullPointerArgument ();
00043 qError (errorString(),EXC_NULLPOINTERARGUMENT);
00044 return;
00045 }
00046 if ( desktop->getSectionID() != SAX_DESKTOP ) {
00047 excDesktopImportBindFailed ( desktop->getSectionID() );
00048 qError (errorString(),EXC_DESKTOPIMPORTBINDFAILED);
00049 return;
00050 }
00051 if ( card->getSectionID() != SAX_CARD ) {
00052 excCardImportBindFailed ( card->getSectionID() );
00053 qError (errorString(),EXC_CARDIMPORTBINDFAILED);
00054 return;
00055 }
00056 if ( layout->getSectionID() != SAX_LAYOUT ) {
00057 excLayoutImportBindFailed ( layout->getSectionID() );
00058 qError (errorString(),EXC_LAYOUTIMPORTBINDFAILED);
00059 return;
00060 }
00061 desktopHandlingAllowed = true;
00062 mDesktop = desktop;
00063 mCard = card;
00064 mLayout = layout;
00065 mInput = 0;
00066 }
00067
00068
00069
00070
00071 SaXManipulateDevices::SaXManipulateDevices (
00072 SaXImport* input, SaXImport* layout
00073 ) {
00074
00081
00082 desktopHandlingAllowed = false;
00083 inputHandlingAllowed = false;
00084 if ((!input) || (!layout)) {
00085 excNullPointerArgument ();
00086 qError (errorString(),EXC_NULLPOINTERARGUMENT);
00087 return;
00088 }
00089 if (layout->getSectionID() != SAX_LAYOUT) {
00090 excLayoutImportBindFailed ( layout->getSectionID() );
00091 qError (errorString(),EXC_LAYOUTIMPORTBINDFAILED);
00092 return;
00093 }
00094 if (
00095 (input->getSectionID() != SAX_POINTERS) &&
00096 (input->getSectionID() != SAX_KEYBOARD)
00097 ) {
00098 excPointerImportBindFailed ( input->getSectionID() );
00099 qError (errorString(),EXC_POINTERIMPORTBINDFAILED);
00100 return;
00101 }
00102 inputHandlingAllowed = true;
00103 mInput = input;
00104 mLayout = layout;
00105 mDesktop = 0;
00106 mCard = 0;
00107 }
00108
00109
00110
00111
00112 int SaXManipulateDevices::addDesktopDevice (void) {
00113
00116
00117 if (! desktopHandlingAllowed) {
00118 return -1;
00119 }
00120
00121
00122
00123 int newID = mCard->getCount();
00124 if (! mCard->addID ( newID )) {
00125 return -1;
00126 }
00127 if (! mDesktop->addID ( newID )) {
00128 return -1;
00129 }
00130
00131
00132
00133 QString newIDstring;
00134 newIDstring.sprintf ("%d",newID);
00135 mCard -> setItem ("Identifier",QString("Device[" + newIDstring + "]"));
00136 mDesktop -> setItem ("Device" ,QString("Device[" + newIDstring + "]"));
00137 mDesktop -> setItem ("Identifier",QString("Screen[" + newIDstring + "]"));
00138 mDesktop -> setItem ("Monitor" ,QString("Monitor["+ newIDstring + "]"));
00139
00140
00141
00142 mCard -> setItem ("Driver","fbdev");
00143
00144
00145
00146 if (newID == 0) {
00147 mLayout -> setItem ("Screen:Screen[0]","<none> <none> <none> <none>");
00148 return mDesktop -> getCurrentID();
00149 }
00150
00151
00152
00153 updateLayout (newID);
00154 return mDesktop -> getCurrentID();
00155 }
00156
00157
00158
00159
00160 int SaXManipulateDevices::addInputDevice (const char* fashion) {
00161
00166
00167 if (! inputHandlingAllowed) {
00168 return -1;
00169 }
00170
00171
00172
00173 QString inputFashion (fashion);
00174 if (
00175 (inputFashion != SAX_INPUT_TOUCHPANEL) &&
00176 (inputFashion != SAX_INPUT_TABLET) &&
00177 (inputFashion != SAX_INPUT_PEN) &&
00178 (inputFashion != SAX_INPUT_PAD) &&
00179 (inputFashion != SAX_INPUT_ERASER) &&
00180 (inputFashion != SAX_INPUT_MOUSE) &&
00181 (inputFashion != SAX_INPUT_VNC) &&
00182 (inputFashion != SAX_INPUT_KEYBOARD)
00183 ) {
00184 excWrongInputFashion (fashion);
00185 qError (errorString(),EXC_WRONGINPUTFASHION);
00186 return -1;
00187 }
00188
00189
00190
00191 QString baseID ("Mouse");
00192 QString baseDriver ("mouse");
00193 if (fashion == (char*)SAX_INPUT_VNC) {
00194 baseDriver = "rfbmouse";
00195 }
00196 Q3Dict<QString>* data = mInput->getTablePointer (0);
00197 int newID = mInput->getCount (true) * 2 + 1;
00198 if ((data) && (! data->isEmpty())) {
00199 baseDriver ="kbd";
00200 if (fashion == (char*)SAX_INPUT_VNC) {
00201 baseDriver = "rfbkeyb";
00202 }
00203 baseID = "Keyboard";
00204 newID = mInput->getCount (true) * 2;
00205 }
00206 if (! mInput -> addID (newID)) {
00207 return -1;
00208 }
00209
00210
00211
00212 QString newIDstring;
00213 newIDstring.sprintf ("%d",newID);
00214 mInput -> setItem ("Identifier",baseID + "[" + newIDstring + "]");
00215 mInput -> setItem ("InputFashion",fashion);
00216
00217
00218
00219 mInput -> setItem ("Driver",baseDriver);
00220
00221
00222
00223 if (baseID == "Mouse") {
00224 QString inputDevice; QTextOStream (&inputDevice)
00225 << mLayout -> getItem ("InputDevice")
00226 << ",Mouse[" << newIDstring << "]";
00227 mLayout -> setItem ("InputDevice",inputDevice);
00228 }
00229 if (baseID == "Keyboard") {
00230 QString inputDevice; QTextOStream (&inputDevice)
00231 << mLayout -> getItem ("Keyboard")
00232 << ",Keyboard[" << newIDstring << "]";
00233 mLayout -> setItem ("Keyboard",inputDevice);
00234 }
00235 return mInput -> getCurrentID();
00236 }
00237
00238
00239
00240
00241 int SaXManipulateDevices::removeDesktopDevice (int id) {
00242
00248
00249 if (! desktopHandlingAllowed) {
00250 return -1;
00251 }
00252
00253
00254
00255 if (id <= 0) {
00256 excInvalidArgument (id);
00257 qError (errorString(),EXC_INVALIDARGUMENT);
00258 return -1;
00259 }
00260
00261
00262
00263 if (! mCard->delID (id)) {
00264 return -1;
00265 }
00266 if (! mDesktop->delID (id)) {
00267 return -1;
00268 }
00269 int newID = id - 1;
00270
00271
00272
00273 mCard -> setID (newID);
00274 mDesktop -> setID (newID);
00275
00276
00277
00278 updateLayout (mDesktop->getCount());
00279 return mDesktop -> getCurrentID();
00280 }
00281
00282
00283
00284
00285 int SaXManipulateDevices::removeInputDevice (int id) {
00286
00292
00293 if (! inputHandlingAllowed) {
00294 return -1;
00295 }
00296
00297
00298
00299 if ((id <= 1) && (mInput->getCount() <= 2)) {
00300 excInvalidArgument (id);
00301 qError (errorString(),EXC_INVALIDARGUMENT);
00302 return -1;
00303 }
00304
00305
00306
00307 if (! mInput->delID (id)) {
00308 return -1;
00309 }
00310
00311
00312
00313 for (int i=1;i<=2;i++) {
00314 Q3Dict<QString>* data = mInput->getTablePointer (i);
00315 if ((data) && (! data->isEmpty())) {
00316 mInput->setID (i);
00317 break;
00318 }
00319 }
00320
00321
00322
00323 bool isMouse = true;
00324 QString baseItem ("InputDevice");
00325 QString baseID ("Mouse");
00326 if (mInput->getCurrentID() % 2 == 0) {
00327 isMouse = false;
00328 baseItem = "Keyboard";
00329 baseID = "Keyboard";
00330 }
00331
00332
00333
00334 QString result;
00335 QString IDstring;
00336 IDstring.sprintf ("%d",id);
00337 QString deviceList = mLayout -> getItem (baseItem);
00338 QStringList optlist = QStringList::split ( ",", deviceList );
00339 for ( QStringList::Iterator
00340 in = optlist.begin(); in != optlist.end(); ++in
00341 ) {
00342 QString item (*in);
00343 if (item == QString(baseID + "["+IDstring+"]")) {
00344 continue;
00345 }
00346 QRegExp identifier ("\\[(.+)\\]");
00347 int pos = identifier.search (item);
00348 if (pos >= 0) {
00349 int curID = identifier.cap(1).toInt();
00350 if ( curID > id ) {
00351 QString newMK;
00352 newMK.sprintf ("%s[%d],",baseID.ascii(),curID - 2);
00353 result.append ( newMK );
00354 } else {
00355 result.append (item+",");
00356 }
00357 }
00358 }
00359 result.remove (result.length()-1,result.length());
00360 mLayout -> setItem (baseItem,result);
00361 return mInput -> getCurrentID();
00362 }
00363
00364
00365
00366
00367 void SaXManipulateDevices::updateLayout (int newID) {
00368
00374
00375
00376
00377
00378 for (int n=0;n<=newID;n++) {
00379 QString idString; idString.sprintf ("%d",n);
00380 mLayout -> removeEntry (QString("Screen:Screen["+ idString + "]"));
00381 }
00382
00383
00384
00385 int existing = newID;
00386 for (int n=0;n<=newID;n++) {
00387 if (! mCard -> getTablePointer (n)) {
00388 existing--;
00389 }
00390 }
00391
00392
00393
00394 if (existing == 0) {
00395 mLayout -> setItem (
00396 "Screen:Screen[0]","<none> <none> <none> <none>"
00397 );
00398 return;
00399 }
00400
00401
00402
00403 for (int n=0;n<=existing;n++) {
00404 QString baseID,val;
00405 baseID.sprintf ("%d",n);
00406 QString key ("Screen:Screen[" + baseID + "]");
00407 for (int pos=0;pos<4;pos++) {
00408 int posID = 0;
00409 QString idString;
00410 switch (pos) {
00411 case 0:
00412 posID = n - 1;
00413 break;
00414 case 1:
00415 posID = n + 1;
00416 break;
00417 default:
00418 idString = "<none>";
00419 break;
00420 };
00421 if (idString.isEmpty()) {
00422 if ((posID < 0) || (posID > newID)) {
00423 idString.sprintf ("<none>");
00424 } else {
00425 idString.sprintf ("Screen[%d]",posID);
00426 }
00427 }
00428 QTextOStream (&val)
00429 << val << " " << idString;
00430 }
00431 val = val.stripWhiteSpace();
00432 mLayout -> setItem (key,val);
00433 }
00434 }
00435 }