not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / plasma / scriptengines / javascript / tests / script-nowplaying / contents / code / main.js
blobed201e7893f8d5eee4c8641308dbae4ec3b367b5
1 // set up the engine, player and controller
2 engine = dataEngine("nowplaying");
3 watchingPlayer = engine.sources[0];
4 controller = service("nowplaying", watchingPlayer);
6 // define a few functions
7 plasmoid.dataUpdate = function(a, b)
9     label.text = "Playing " + b.Title + " by " + b.Artist + ". time: " +
10                  Math.floor(b.Position/60) + ":" + (parseInt(b.Position)%60);
11     progress.value = 100*b.Position/b.Length;
14 plasmoid.stop = function()
16     data = controller.operationDescription("stop");
17     print(controller.name());
18     for ( var i in data ) {
19         print(i + ' -> ' + data[i] );
20     }
22     controller.startOperationCall(controller.operationDescription("stop"));
23     print("stopping");
26 plasmoid.setProgress = function(progress)
28     operation = controller.operationDescription("seek");
29     operation.seconds = progress;
30     for ( var i in operation ) {
31         print(i + ' -> ' + operation[i] );
32     }
34     controller.startOperationCall(operation);
35     print("set progress to " + progress);
38 // Set up the UI
39 layout = new LinearLayout(plasmoid);
40 layout.setOrientation(QtVertical);
41 label = new Label();
42 layout.addItem(label);
44 stop = new PushButton();
45 stop.text = "Stop";
46 layout.addItem(stop);
48 progress = new Slider();
49 progress.orientation = QtHorizontal;
50 layout.addItem(progress);
52 // Glue things together
53 stop.clicked.connect(plasmoid.stop);
54 progress.sliderMoved.connect(plasmoid.setProgress);
56 controller.associateWidget(stop, "stop");
57 controller.associateWidget(progress, "progress");
59 engine.connectSource(watchingPlayer, plasmoid, 500);