Guest

Rohan Prabhu

By: a guest on Feb 27th, 2011  |  syntax: C++ (with QT extensions)  |  size: 4.07 KB  |  hits: 344  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. //newWrapper does not search clientMap for existing entries
  2. //a search must be performed prior to this call.
  3. //However, since now clientMap is actually a QHash, it wouldn't
  4. //hurt to perform a check here as well.
  5. SWrapper::ClientResolution SWrapper::Client::newWrapper(KWin::Client* client, QScriptEngine* eng)
  6.     {
  7.     SWrapper::Client* wrapper = new SWrapper::Client(client);
  8.     wrapper->setEngine(eng);
  9.     QScriptValue value;
  10.  
  11.     // Use this value to avoid repeated function generations
  12.     // for function aliases.
  13.     QScriptValue func;
  14.  
  15.     /*
  16.      * Step1: Prepping
  17.      * Connect all signals and slots from client to
  18.      * the wrapper object.
  19.      */
  20.  
  21.  
  22.     //End of prepping
  23.  
  24.     /*
  25.      * Step2: Conversion
  26.      * Wrap the object, set the data parameter
  27.      * and obtain a QScriptValue
  28.      */
  29.  
  30.     value = eng->newQObject(wrapper,
  31.                             QScriptEngine::AutoOwnership,
  32.                             QScriptEngine::ExcludeSuperClassContents | QScriptEngine::ExcludeDeleteLater
  33.                            );
  34.  
  35.     wrapper->tl_centralObject = client;
  36.     tl_append(value, eng);
  37.  
  38.     //End of Conversion
  39.  
  40.     /*
  41.      * Step3: Spice
  42.      * Add the static functions and other things
  43.      * that rely on the value of data() and not the
  44.      * wrapper address.
  45.      */
  46.  
  47.     value.setProperty("caption", eng->newFunction(caption, 0), QScriptValue::Undeletable);
  48.     value.setProperty("close", eng->newFunction(close, 0), QScriptValue::Undeletable);
  49.     value.setProperty("resize", eng->newFunction(resize, 1), QScriptValue::Undeletable);
  50.     value.setProperty("move", eng->newFunction(move, 1), QScriptValue::Undeletable);
  51.     value.setProperty("setGeometry", eng->newFunction(setGeometry, 1), QScriptValue::Undeletable);
  52.     value.setProperty("getWindowInfo", eng->newFunction(getWindowInfo, 0), QScriptValue::Undeletable);
  53.     value.setProperty("isTransient", eng->newFunction(isTransient, 0), QScriptValue::Undeletable);
  54.     value.setProperty("transientFor", eng->newFunction(transientFor, 0), QScriptValue::Undeletable);
  55.     value.setProperty("activate", eng->newFunction(activate, 1), QScriptValue::Undeletable);
  56.     value.setProperty("setCaption", eng->newFunction(setCaption, 1), QScriptValue::Undeletable);
  57.     value.setProperty("setFullScreen", eng->newFunction(setFullScreen, 2), QScriptValue::Undeletable);
  58.     value.setProperty("isFullScreen", eng->newFunction(isFullScreen, 0), QScriptValue::Undeletable);
  59.     value.setProperty("isFullScreenable", eng->newFunction(isFullScreenable, 0), QScriptValue::Undeletable);
  60.     value.setProperty("minimize", eng->newFunction(minimize, 0), QScriptValue::Undeletable);
  61.     value.setProperty("clientGroup", eng->newFunction(clientGroup, 0), QScriptValue::Undeletable);
  62.     value.setProperty("maximize", eng->newFunction(maximize, 0), QScriptValue::Undeletable);
  63.     value.setProperty("setMaximize", eng->newFunction(setMaximize, 2), QScriptValue::Undeletable);
  64.     value.setProperty("desktop", eng->newFunction(desktop, 0), QScriptValue::Undeletable);
  65.     value.setProperty("setKeepAbove", eng->newFunction(setKeepAbove, 0), QScriptValue::Undeletable);
  66.     value.setProperty("setKeepBelow", eng->newFunction(setKeepBelow, 0), QScriptValue::Undeletable);
  67.  
  68.     BOOLATTACHCLIENT(isShade)
  69.     BOOLATTACHCLIENT(isShadeable)
  70.     BOOLATTACHCLIENT(isMinimized)
  71.     BOOLATTACHCLIENT(isMinimizable)
  72.     BOOLATTACHCLIENT(isMaximizable)
  73.     BOOLATTACHCLIENT(isResizable)
  74.     BOOLATTACHCLIENT(isMovable)
  75.     BOOLATTACHCLIENT(isMovableAcrossScreens)
  76.     BOOLATTACHCLIENT(isCloseable)
  77.     BOOLATTACHCLIENT(keepAbove)
  78.     BOOLATTACHCLIENT(keepBelow)
  79.  
  80.     func = eng->newFunction(unminimize, 0);
  81.     value.setProperty("unminimize", func, QScriptValue::Undeletable);
  82.     value.setProperty("restore", func, QScriptValue::Undeletable);
  83.  
  84.     ClientResolution final(wrapper, value);
  85.  
  86.     //Finally, append the entire thing to the clientMap
  87.     //clientMap.insert(const_cast<KWin::Client*>(client), ClientResolution(wrapper, value));
  88.  
  89.     //And.. we're done
  90.     (client->scriptCache)->insert(eng, final);
  91.     return final;
  92.     }