-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstructure-qml.php
More file actions
361 lines (322 loc) · 17.1 KB
/
Copy pathstructure-qml.php
File metadata and controls
361 lines (322 loc) · 17.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
<pre>
<?php
/*
structure reads the pluto_main database and deciphers a
given skin and UI into a tree containing all relevant
information to recreate the screen in another descriptive
language / layout engine
*/
include_once("lib.inc.php");
error_reporting(E_ALL);
function PrintWithIndent($value) {
static $indentCounter = 0;
global $screenFile;
if (substr($value,0,4) == "<div") {
$indentCounter++;
$value = "";
}
if (substr($value,0,5) == "</div") {
$indentCounter--;
$value = "";
}
$indentCounter = 1;
if ($value != "") {
for ($i=0; $i<$indentCounter; $i++) {
fwrite( $screenFile, "\t");
// print "\t";
}
fwrite ($screenFile, $value);
// print $value;
}
}
function getBackground($FK_DesignObj,$x=0,$y=0) {
global $link;
$background = "";
$skin = "Basic";
// Now we get the background image from the main variation (if such a thing exists)
$query = "Select Value from DesignObjVariation_DesignObjParameter";
$query .= " Join DesignObjVariation On FK_DesignObjVariation = PK_DesignObjVariation";
$query .= " Where Value Is Not Null And Value <> '' And DesignObjVariation.FK_DesignObj = $FK_DesignObj and (FK_UI is null Or FK_UI = 1)";
$query .= " Order By FK_UI Desc";
$background = getMyValue($link,$query);
if (($background == 1) or ($background == "")) {
$background = "";
} else {
// some path names for images still contain a backslash instead
// of a forward slash, probably thanks to HADesigner's roots.
$background = str_replace("\\","/",$background);
// We do have spaces in there. Let's replace those with %20
$background = str_replace(" ","%20",$background);
// atm we hardcode the skin Basic
$background = "skins/$skin/" . $background;
}
return $background;
}
function getDesignObjText($FK_DesignObj,$x=0,$y=0,$parentwidth,$parentheight) {
global $link;
$query = "select PK_DesignObjVariation,Text_LS.FK_Text,Text_LS.FK_Language,Text_LS.Description,";
$query .= " DesignObjVariation_Text_Skin_Language.X, DesignObjVariation_Text_Skin_Language.Y,";
$query .= " DesignObjVariation_Text_Skin_Language.Width, DesignObjVariation_Text_Skin_Language.Height,";
$query .= " DesignObjVariation_Text_Skin_Language.*";
$query .= " from DesignObjVariation";
$query .= " Join DesignObjVariation_Text On PK_DesignObjVariation = FK_DesignObjVariation";
$query .= " Join Text_LS On Text_LS.FK_Text = DesignObjVariation_Text.FK_Text";
$query .= " Join DesignObjVariation_Text_Skin_Language On DesignObjVariation_Text_Skin_Language.FK_DesignObjVariation_Text = PK_DesignObjVariation_Text";
$query .= " Where DesignObjVariation.FK_DesignObj = " . $FK_DesignObj;
$query .= " And Text_LS.FK_Language = 1";
$query .= " And (DesignObjVariation.FK_UI = 1 or DesignObjVariation.FK_UI IS NULL)";
$query .= " And DesignObjVariation_Text_Skin_Language.FK_Skin Is Null";
$query .= " Order By Text_LS.FK_Language";
$arr = getMyArray($link,$query);
$label = "";
if (is_array($arr)) {
outputGroupOn($FK_DesignObj);
foreach ($arr as $designobj) {
$designobj["X"] = $designobj["X"]+$x;
$designobj["Y"] = $designobj["Y"]+$y;
outputText($designobj,$parentwidth,$parentheight);
// We only return the last label of the text. TODO - this might be problematic.
$label = $designobj["Description"];
}
outputGroupOff();
}
return $label;
}
function getCommandGroup_D($FK_DesignObj,$onClick=0) {
global $link;
$query = "select FK_CommandGroup_D_OnActivate from DesignObjVariation Where FK_DesignObj = $FK_DesignObj";
$query .= " and (FK_UI is null Or FK_UI = 1) AND FK_CommandGroup_D_OnActivate != '';";
$arr = getMyArray($link,$query);
if (! empty($arr)) {
PrintWithIndent( "function onActivate".$FK_DesignObj . "() \n");
PrintWithIndent( "{\n");
if ($onClick==0) {
// PrintWithIndent( "<li>On ActivateCommandGroups</li>");
outputGroupOn($FK_DesignObj);
}
foreach ($arr as $commandOnActivate) {
if ($commandOnActivate["FK_CommandGroup_D_OnActivate"] != "") {
OutputCommandGroup($commandOnActivate["FK_CommandGroup_D_OnActivate"]); // i.e. FK_Command_Group_D = 9490
// PrintWithIndent( "\t//DoCommand(" . $commandOnActivate["FK_CommandGroup_D_OnActivate"] . ")\n");
}
}
PrintWithIndent("}\n");
if ($onClick==0) {
outputGroupOff();
}
}
}
function OutputCommandGroup($FK_CommandGroup_D) {
global $link;
$query = "SELECT PK_CommandGroup_D_Command,FK_Command,FK_DeviceTemplate,FK_DeviceCategory,BroadcastLevel,RelativeToSender From CommandGroup_D_Command WHERE FK_CommandGroup_D = $FK_CommandGroup_D Order By OrderNum;";
$arr = getMyArray($link,$query);
if (is_array($arr) <= 0) {
return false;
} else {
foreach($arr as $commandGroup_Command) {
$destination = $commandGroup_Command["FK_DeviceTemplate"];
$broadcastLevel = "";
if ( ! is_null($commandGroup_Command["FK_DeviceCategory"]) ) {
$destination = $commandGroup_Command["FK_DeviceCategory"];
}
if ( ! is_null($commandGroup_Command["BroadcastLevel"]) ) {
$broadcastLevel = "-bl " . $commandGroup_Command["BroadcastLevel"];
}
$query = "SELECT Description FROM Command WHERE PK_Command = " . $commandGroup_Command["FK_Command"];
$commandDescription = getMyValue($link,$query);
PrintWithIndent (" // Calling Command " . $commandGroup_Command["FK_Command"] . " (" . $commandDescription . ") with CommandGroup_Parameters from " . $commandGroup_Command["PK_CommandGroup_D_Command"] . "\n" );
$query = "SELECT FK_CommandParameter, IK_CommandParameter FROM CommandGroup_D_Command_CommandParameter WHERE FK_CommandGroup_D_Command = " . $commandGroup_Command["PK_CommandGroup_D_Command"] . " and IK_CommandParameter IS NOT NULL;";
$parameterArr = getMyArray($link,$query);
if (is_array($parameterArr) > 0) {
$knownFunction = ""; // Contains the qOrbiter function that the Orbiter function is mapped to.
$parameter = "";
$functionCall = "";
foreach($parameterArr as $commandParameter) {
// We know about Goto Screen
if ($commandGroup_Command["FK_Command"] == 741 and $commandParameter["FK_CommandParameter"] == 159) { // Goto Screen And PK_Screen as parameter
$knownFunction = "\tgotoQScreen(\"Screen_" . $commandParameter["IK_CommandParameter"] . ".qml\")";
}
// We know about Go back
elseif ($commandGroup_Command["FK_Command"] == 240) {
// or maybe we do not... $knownFunction = "\tgotoQScreen(\"Screen_" . $commandParameter["IK_CommandParameter"] . ".qml\")";
$knownFunction .= "";
}
$parameter .= $commandParameter["FK_CommandParameter"];
$parameter .= " \\\"" . translateOrbiter2qOrbiterVars($commandParameter["IK_CommandParameter"]) . "\\\" ";
}
$functionCall .= "\tmanager.sendDceMessage(";
$functionCall .= "srouterip + \" \"";
$functionCall .= "+deviceid + \"";
$functionCall .= " " . $destination;
$functionCall .= " " . 1; // we send a command
$functionCall .= " " . $commandGroup_Command["FK_Command"];
$functionCall .= " " . $parameter;
$functionCall .= "\")\n";
if ($knownFunction != "") {
PrintWithIndent( $knownFunction . "\n");
} else {
PrintWithIndent ( $functionCall);
}
}
}
}
}
function translateOrbiter2qOrbiterVars($orbiterVar) {
// This little function should translate the original Orbiter variables
// into stuff understood by qOrbiter.
$qOrbiterVar = $orbiterVar;
$nPos= strpos("<%=",$orbiterVar);
if ($nPos > 0) {
$nPosEnde = strpos("%>",$orbiterVar);
$lmceOrbiterVar = substr($orbiterVar,$nPos,$nPosEnde-$nPos);
switch ($lmceOrbiterVar) {
case "E":
$qtOrbiterVar = "currentRoom";
break;
case "!":
$qtOrbiterVar = "deviceid";
break;
}
}
$qOrbiterVar = mysql_real_escape_string($qOrbiterVar);
return $qOrbiterVar;
}
function getDesignObj($FK_DesignObj,$level=0,$x=0,$y=0) {
global $link;
// Return the position and designobj childs of the FK_DesignObj
$query = "Select PK_DesignObjVariation_DesignObj, DesignObj.Description, DesignObjVariation_DesignObj.FK_DesignObj_Child,";
$query .= " DesignObjVariation_DesignObj_Skin_Language.X, DesignObjVariation_DesignObj_Skin_Language.Y,";
$query .= " DesignObjVariation_DesignObj_Skin_Language.Width, DesignObjVariation_DesignObj_Skin_Language.Height";
$query .= " From DesignObjVariation_DesignObj_Skin_Language";
$query .= " Join DesignObjVariation_DesignObj On FK_DesignObjVariation_DesignObj = PK_DesignObjVariation_DesignObj";
$query .= " Join DesignObjVariation On FK_DesignObjVariation_Parent = PK_DesignObjVariation";
$query .= " Join DesignObj On PK_DesignObj = FK_DesignObj_Child";
$query .= " Where DesignObjVariation.FK_DesignObj = $FK_DesignObj";
$queryUI1 = $query . " And DesignObjVariation.FK_UI = 1";
$queryStandard = $query . " And DesignObjVariation.FK_UI Is Null";
$arrUI1 = getMyArray($link,$queryUI1);
// Sometimes a DesignObj itself is not available for UI1 one but only for the standard.
$arrStandard = getMyArray($link,$queryStandard);
// We merge the UI1 and Standard DesignObj together.
$arr = array_merge($arrUI1,$arrStandard);
if (is_array($arr)) {
outputGroupOn($FK_DesignObj);
foreach ($arr as $designobj) {
$currentFK_DesignObj = $designobj["FK_DesignObj_Child"];
$designobj["X"] = $x + $designobj["X"];
$designobj["Y"] = $y + $designobj["Y"];
// Create the function to call commands associated with this designobj.
outputFunction($designobj["FK_DesignObj_Child"]);
// We output the current DesignObj
outputObject($designobj);
// Check recursively for more kids.
getDesignObj($currentFK_DesignObj,$level+1,$x+$designobj["X"],$y+$designobj["Y"]);
}
outputGroupOff();
}
return $arr;
}
function outputGroupOn($FK_DesignObj = "") {
if ($FK_DesignObj == "") {
PrintWithIndent( "<div>\n");
} else {
PrintWithIndent( "<div id=$FK_DesignObj>");
}
}
function outputGroupOff() {
PrintWithIndent( "</div>\n");
}
function outputFunction($currentFK_DesignObj) {
// Create a function that calls each of the commands for the current designobj.
getCommandGroup_D($currentFK_DesignObj);
}
function outputObject($arrDesignObj) {
global $screen;
static $buttonCounter=0;
$currentFK_DesignObj = $arrDesignObj["FK_DesignObj_Child"];
// A DesignObj can have multiple text associated.
$buttonLabel = getDesignObjText($currentFK_DesignObj,$arrDesignObj["X"],$arrDesignObj["Y"],$arrDesignObj["Width"],$arrDesignObj["Height"]);
if (getBackground($currentFK_DesignObj) != "") {
$buttonCounter++;
PrintWithIndent( "ButtonSq {\n");
PrintWithIndent( "\tid: button" . $currentFK_DesignObj . "_" . $buttonCounter . "\n");
PrintWithIndent( "\tx: " . ResizeX($arrDesignObj["X"]) . "\n");
PrintWithIndent( "\ty: " . ResizeY($arrDesignObj["Y"]) . "\n");
PrintWithIndent( "\twidth: " . ResizeX($arrDesignObj["Width"]) . "\n");
PrintWithIndent( "\theight: " . ResizeY($arrDesignObj["Height"]) . "\n");
PrintWithIndent( "\tbuttonbackground: \"" . getBackground($currentFK_DesignObj) . "\"\n");
PrintWithIndent( "\tbuttontext: \"" . $buttonLabel . "\"\n");
PrintWithIndent( "\tclickHandler.onClicked: onActivate". $arrDesignObj["FK_DesignObj_Child"] . "()\n");
PrintWithIndent( "}\n");
}
}
function outputText($arrDesignObj,$parentwidth,$parentheight) {
if ($arrDesignObj["Width"] == 0) {
$arrDesignObj["Width"] = $parentwidth;
}
if ($arrDesignObj["Height"] == 0) {
$arrDesignObj["Height"] = $parentheight;
}
// TODO: posde seems to be too stupid for vertical aligning next
// within a known box.
PrintWithIndent( "StyledText {\n");
// PrintWithIndent( "\tid: styledText" . $arrDesignObj["PK_DesignObjVariation"] . "\n");
PrintWithIndent( "\tx: " . ResizeX($arrDesignObj["X"]) . "\n");
PrintWithIndent( "\ty: " . ResizeY($arrDesignObj["Y"]) . "\n");
PrintWithIndent( "\theight: " . ResizeX($arrDesignObj["Height"]) . "\n");
PrintWithIndent( "\twidth: " . ResizeY($arrDesignObj["Width"]) . "\n");
// PrintWithIndent( "\tz: 1\n");
PrintWithIndent( "\ttextLabel: \"" . trim($arrDesignObj["Description"]) . "\"\n");
PrintWithIndent( "}\n");
}
function ResizeX($oldX) {
// Resizes the X value from a 2128 to 1920
$newX = round($oldX / 2128 * 1920);
return $newX;
}
function ResizeY($oldY) {
// Resizes the Y value from 1596 to 1080
$newY = round($oldY / 1596 * 1080);
return $newY;
}
connectDB();
global $currentUser, $currentScreen, $currentRoom, $currentEntertainArea, $link, $mediaLink, $screenFile;
// Get all data for the standard variation
$screen = 48; // MythTV Remote
if (isset($_GET["screen"])) {
$screen = $_GET["screen"];
$screens = array($screen => "A Screen");
} else {
$query = "SELECT PK_Screen, Description FROM Screen";
$screens = getMyArray($link,$query);
}
foreach ($screens as $screen) {
$query = "SELECT FK_DesignObj From Screen_DesignObj Where FK_Screen = " . $screen["PK_Screen"] . " AND FK_UI Is Null AND FK_Skin Is Null";
$FK_DesignObj = getMyValue($link,$query);
print "Checking screen " . $screen["PK_Screen"] . "\n";
if ( ! empty($FK_DesignObj)) {
$screenFile = fopen("Screen_". $screen["PK_Screen"] . ".qml","w");
// Header for each QML
fwrite($screenFile, "// UI1 Screen " . $screen["Description"] . " (" . $screen["PK_Screen"] . ")\n");
fwrite($screenFile, "// Created using structure-qml.php from Peer Oliver Schmidt\m");
fwrite($screenFile, "// based on the LinuxMCE database\n");
fwrite($screenFile, "import QtQuick 1.0\n");
fwrite($screenFile, "import \"../components\"\n");
fwrite($screenFile, "Item {\n");
$background = getBackground($FK_DesignObj);
PrintWithIndent( "Image {\n");
PrintWithIndent( "\tsource: \"$background\"\n");
PrintWithIndent( "\twidth: 1920\n");
PrintWithIndent( "\theight: 1080\n");
PrintWithIndent( "}\n");
// Now that we have the basic background, let's try and find all the objects on this screen.
// Each screen has ONE base DesignObj that all other DesignObj are childs of.
$arr = getDesignObj($FK_DesignObj);
// Done with the screen.
fwrite($screenFile, "}");
fclose($screenFile);
}
}
mysql_close($mediaLink);
mysql_close($link);
?>