add some comments
[makneto-zunavac1.git] / src / ui-mobile / declarative / SessionScene.qml
blob74e2d0ccc412ad5453e6fa8eb834c47cb9506eaa
1 /*
2  *   Copyright (C) 2011 Lukáš Karas <lukas.karas@centrum.cz>
3  *
4  *   This program is free software; you can redistribute it and/or modify
5  *   it under the terms of the GNU General Public License as published by
6  *   the Free Software Foundation; either version 2 of the License, or
7  *   (at your option) any later version.
8  *
9  *   This program is distributed in the hope that it will be useful,
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *   GNU General Public License for more details.
13  *
14  *   You should have received a copy of the GNU General Public License
15  *   along with this program; if not, write to the
16  *   Free Software Foundation, Inc.,
17  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18  */
19 import QtQuick 1.0
20 import org.makneto 0.1 as Makneto
22 Scene {
23     id: sessionScene
24     color: "black"
26     property bool fullscreen: false;
27     property int sessionWidth : sessionScene.width;
28     //property variant sessionModel: {};
29     property variant sessionId
31     signal whiteboardMessageReceived(string data, string contact)
32     signal textMessageReceived(string text, string contact)
33     signal chatStateChanged(variant chatState, string contact);
34     signal messageSent(string content);
36     function log(msg){
37         console.log("II [SessionScene.qml]: "+msg);
38     }
39     function error(msg){
40         console.log("EE [SessionScene.qml]: "+msg);
41     }
42     function warn(msg){
43         console.log("WW [SessionScene.qml]: "+msg);
44     }
45     function setSessionsModel(model){
46         chatWidget.sendMessage.connect(model.sendTextMessage);
47         chatWidget.changeChatState.connect(model.changeChatState);
48         boardComponent.sendWbMessage.connect(model.sendWhiteboardMessage);
49         sessionToolbar.requestCall.connect(model.startCall);
50         sessionToolbar.requestHangup.connect(model.hangup);
52         // initial setup sessin type
53         sessionTypeChanged(model.getSessionType(sessionId));
54     }
56     function sessionTypeChanged(type){
57         log("session type changed "+type+" (audio: "+Makneto.Session.SessionTypeAudio+", video: "+Makneto.Session.SessionTypeVideo+")")
58         setAudioCall( (type & Makneto.Session.SessionTypeAudio) !==0 );
59         setVideoCall( (type & Makneto.Session.SessionTypeVideo) !==0 );
60     }
62     BoardWidget{
63         id: boardComponent
64         /*
65         height: parent.height * 0.6
66         width: parent.width * 0.6
67         */
68     }
70     VideoWidget{
71         id: videoComponent
72         height: boardComponent.height
73         anchors{ top: parent.top; right: parent.right; left: board.right }
74     }
76     ChatWidget{
77         id: chatWidget
78         anchors{top: boardComponent.bottom; right: parent.right; bottom: parent.bottom; left: parent.left}
79     }
81     SessionControlPanel{
82         id: sessionToolbar
83         z: 200
84     }
86     Component.onCompleted:{
87         updateLayout();
88         whiteboardMessageReceived.connect(boardComponent.whiteboardMessageReceived);
89         whiteboardMessageReceived.connect( function(data, contact){
90                                               if (!sessionScene.board){
91                                                   setBoard(true);
92                                               }
93                                           });
94         messageSent.connect(boardComponent.messageSent);
95         textMessageReceived.connect(chatWidget.textMessageReceived);
96         chatStateChanged.connect(chatWidget.chatStateChanged);
97         //textMessageReceived("text", "contact");
98     }
100     onWidthChanged:{
101         updateLayout();
102     }
103     onHeightChanged:{
104         updateLayout();
105     }
106     onStateChanged: {
107         // hack for nonfunctional clip property for WebView
108         boardComponent.hideWebView( (state !== "center") );
109     }
111     function updateLayout(){
112         // states
113         if ((!videoCall) && videoComponent.state != "normal")
114             videoComponent.state = "normal";
115         if ((!board) && boardComponent.state != "normal")
116             boardComponent.state = "normal";
118         if (videoComponent.state == "fullscreen")
119             boardComponent.state = "normal";
121         if (!fullscreen)
122             sessionWidth = sessionScene.width;
124         // compute dimensions
125         var boardHeight = (board || videoCall)? sessionScene.height * 0.6: 0;
126         var videoHeight = boardHeight;
128         var boardWidth = board? (videoCall? sessionWidth * 0.6 : sessionWidth): 0;
129         var videoWidth = (sessionWidth - boardWidth);
131         // z layer
132         boardComponent.z = (!board)? -1 : (boardComponent.state == "fullscreen"? 100: 0);
133         videoComponent.z = (!videoCall)? -1 : (videoComponent.state == "fullscreen"? 100: 0);
135         // opacity
136         boardComponent.opacity = board? 1:0;
137         videoComponent.opacity = videoCall? 1:0;
139         // fullscreen?
140         fullscreen = (videoComponent.state == "fullscreen" || boardComponent.state == "fullscreen");
141         //main.getStageController().fullScreen( fullScreen );
142         if (fullscreen){
143             main.getLeftPanel().state = "hided";
144         }
146         // debug
147         /*
148         log("update layout {board:"+board+", videoCall:"+videoCall+"}");
149         log("board: "+boardWidth+"x"+boardHeight+" video: "+videoWidth+"x"+videoHeight+" / "+
150                       boardComponent.width+"x"+boardComponent.height+"  "+videoComponent.width+"x"+videoComponent.height);
151         */
153         // set dimensions
154         if (!fullscreen){
155             boardComponent.width = boardWidth;
156             boardComponent.height = boardHeight;
157             //boardComponent.setDimensions(boardWidth, boardHeight);
158             videoComponent.width = videoWidth;
159             videoComponent.height = videoHeight;
160         }
161     }
163     property bool videoCall : false;
164     function setVideoCall(b){
165         if (b != sessionToolbar.videoCall){
166             sessionScene.videoCall = b;
167             sessionToolbar.state = sessionScene.videoCall || sessionScene.audioCall ? "call": "chat";
168             updateLayout();
169         }
170     }
172     property bool audioCall : false;
173     function setAudioCall(b){
174         if (b != sessionScene.audioCall){
175             sessionScene.audioCall = b;
176             sessionToolbar.state = sessionScene.audioCall || sessionScene.audioCall ? "call": "chat";
177             updateLayout();
178         }
179     }
181     property bool board : false
182     function setBoard(b){
183         if (b != sessionScene.board){
184             sessionScene.board = b;
185             updateLayout();
186         }
187     }
189     function closeSession(){
190         if (sessionScene.videoCall || sessionScene.audioCall)
191             sessionToolbar.requestHangup(sessionScene.sessionId);
193         main.getSessionController().closeSession(sessionScene.sessionId);
194     }
195     function fullScreenVideo(){
196         if (videoComponent.state == "fullscreen")
197             return;
198         videoComponent.state = "fullscreen";
199         updateLayout();
200     }
201     function minimizeVideo(){
202         if (videoComponent.state == "normal")
203             return;
204         videoComponent.state = "normal";
205         updateLayout();
206     }