2 * Copyright (C) 2011 Lukáš Karas <lukas.karas@centrum.cz>
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.
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.
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.
22 import org.makneto 0.1 as Makneto
25 id: globalStatusComponent
27 property variant _model: ListModel {}
28 property variant _presenceManager : undefined
29 property variant popup: undefined;
30 property string globalStatusMsg: "Click here for change your status"
31 property string globalStatus: "offline";
32 property variant statusPopupComponent : Qt.createComponent("GlobalStatusPopup.qml");
35 console.log("II [GlobalStatus.qml]: "+msg);
38 console.log("EE [GlobalStatus.qml]: "+msg);
41 console.log("WW [GlobalStatus.qml]: "+msg);
44 function setGlobalStatus(statusIndex, status, statusMessage){
47 var presence = statusIndexToPressence(statusIndex);
48 log("set global presence to "+presence );
49 for (var i=0; i< _model.accountCount; i++){
50 var id = _model.data(i, Makneto.AccountsModel.IdRole);
51 var account = _model.accountItemForId(id);
52 account.setRequestedPresence(presence, status, statusMessage);
58 var presence = statusIndexToPressence(statusIndex);
59 _presenceManager.requestGlobalPresence(presence, status, statusMessage);
60 //log("request global presence...");
63 function onGlobalPresenceChanged(type, status, statusMessage){
64 //log("onGlobalPresenceChanged "+type+" "+status+", "+statusMessage);
65 var i = presenceToStatusIndex(type);
66 globalStatusIcon.source = statusesModel.get(i).icon;
67 globalStatusMsg = statusMessage;
70 function onAccountsModelChanged(model){
72 // this is emited every change
74 _model.accountCountChanged.connect(
80 function onPresenceManagerChaged(manager){
81 _presenceManager = manager;
82 _presenceManager.globalPresenceChanged.connect( onGlobalPresenceChanged);
85 function statusIndexToPressence(i){
87 case 0: return Makneto.TelepathyTypes.ConnectionPresenceTypeAvailable;
88 case 1: return Makneto.TelepathyTypes.ConnectionPresenceTypeOffline;
89 case 2: return Makneto.TelepathyTypes.ConnectionPresenceTypeAway;
90 case 3: return Makneto.TelepathyTypes.ConnectionPresenceTypeExtendedAway;
91 case 4: return Makneto.TelepathyTypes.ConnectionPresenceTypeBusy;
92 case 5: return Makneto.TelepathyTypes.ConnectionPresenceTypeHidden;
94 return Makneto.TelepathyTypes.ConnectionPresenceTypeOffline;
96 function presenceToStatusIndex(i){
98 case Makneto.TelepathyTypes.ConnectionPresenceTypeAvailable: return 0;
99 case Makneto.TelepathyTypes.ConnectionPresenceTypeOffline: return 1;
100 case Makneto.TelepathyTypes.ConnectionPresenceTypeAway: return 2;
101 case Makneto.TelepathyTypes.ConnectionPresenceTypeExtendedAway: return 3;
102 case Makneto.TelepathyTypes.ConnectionPresenceTypeBusy: return 4;
103 case Makneto.TelepathyTypes.ConnectionPresenceTypeHidden: return 5;
108 Component.onCompleted: {
109 //main.addAccountsModelListener( globalStatusComponent );
110 main.accountsModelChanged.connect(onAccountsModelChanged);
111 main.presenceManagerChanged.connect(onPresenceManagerChaged);
116 ListElement { text: "Online"; icon: "img/status-online.png" ; index: 0}
117 ListElement { text: "Offline"; icon: "img/status-offline.png" ; index: 1}
118 ListElement { text: "Away"; icon: "img/status-away.png" ; index: 2}
119 ListElement { text: "eXtended Away"; icon: "img/status-xa.png" ; index: 3}
120 ListElement { text: "DND"; icon: "img/status-dnd.png" ; index: 4}
121 ListElement { text: "Invisible"; icon: "img/status-invisible.png" ; index: 5}
132 source: "img/status-"+globalStatus+".png"
133 height: parent.height
137 id: globalStatusMsgText
138 text: globalStatusMsg
141 anchors.left: globalStatusIcon.right
142 anchors.right: parent.right
143 anchors.leftMargin: 5
144 anchors.verticalCenter: globalStatusIcon.verticalCenter
146 //height: parent.height
147 wrapMode: Text.NoWrap
149 elide: Text.ElideRight; textFormat: Text.PlainText // this adds \x2026 (…) when text is too long
154 //log("clicked on statusIndicator ");
156 if(statusPopupComponent.status != Component.Ready){
157 error("Component "+statusPopupComponent.url+" is not ready!");
158 error(statusPopupComponent.errorString());
162 if (popup !== undefined && popup !== null && popup.state != "hide"){
166 popup = statusPopupComponent.createObject(main);
168 error("error creating popup");
169 error(statusPopupComponent.errorString());
172 var pos = statusIndicator.mapToItem(main,statusIndicator.width - 10, 10);
173 popup.popupFromX = pos.x;
174 popup.popupFromY = pos.y;
175 popup.finalWidth = main.width * .7;
176 popup.finalHeight = main.height * .5;
177 popup.statusesModel = statusesModel;
179 if (globalStatusComponent._presenceManager === undefined)
180 error("we don't have pressenceManager!");
181 popup.setGlobalStatusComponent( globalStatusComponent );
183 popup.state = "visible"
184 //log("visible popup "+JSON.stringify(parent));