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 defaultStatusMsg: "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 (1) "+type+" "+status+", "+statusMessage);
65 var i = presenceToStatusIndex(type);
66 globalStatusIcon.source = statusesModel.get(i).icon;
67 globalStatusMsgText.text = statusMessage === ""? defaultStatusMsg: statusMessage;
68 presenceText.text = presenceToStr( type );
69 log("onGlobalPresenceChanged "+type+" "+status+", "+statusMessage);
72 function onAccountsModelChanged(model){
74 // this is emited every change
76 _model.accountCountChanged.connect(
82 function onPresenceManagerChaged(manager){
83 _presenceManager = manager;
84 _presenceManager.globalPresenceChanged.connect( onGlobalPresenceChanged);
87 function presenceToStr(i){
89 case Makneto.TelepathyTypes.ConnectionPresenceTypeAvailable: return "Available";
90 case Makneto.TelepathyTypes.ConnectionPresenceTypeOffline: return "Offline";
91 case Makneto.TelepathyTypes.ConnectionPresenceTypeAway: return "Away";
92 case Makneto.TelepathyTypes.ConnectionPresenceTypeExtendedAway: return "ExtendedAway";
93 case Makneto.TelepathyTypes.ConnectionPresenceTypeBusy: return "Busy";
94 case Makneto.TelepathyTypes.ConnectionPresenceTypeHidden: return "Hidden";
99 function statusIndexToPressence(i){
101 case 0: return Makneto.TelepathyTypes.ConnectionPresenceTypeAvailable;
102 case 1: return Makneto.TelepathyTypes.ConnectionPresenceTypeOffline;
103 case 2: return Makneto.TelepathyTypes.ConnectionPresenceTypeAway;
104 case 3: return Makneto.TelepathyTypes.ConnectionPresenceTypeExtendedAway;
105 case 4: return Makneto.TelepathyTypes.ConnectionPresenceTypeBusy;
106 case 5: return Makneto.TelepathyTypes.ConnectionPresenceTypeHidden;
108 return Makneto.TelepathyTypes.ConnectionPresenceTypeOffline;
110 function presenceToStatusIndex(i){
112 case Makneto.TelepathyTypes.ConnectionPresenceTypeAvailable: return 0;
113 case Makneto.TelepathyTypes.ConnectionPresenceTypeOffline: return 1;
114 case Makneto.TelepathyTypes.ConnectionPresenceTypeAway: return 2;
115 case Makneto.TelepathyTypes.ConnectionPresenceTypeExtendedAway: return 3;
116 case Makneto.TelepathyTypes.ConnectionPresenceTypeBusy: return 4;
117 case Makneto.TelepathyTypes.ConnectionPresenceTypeHidden: return 5;
122 Component.onCompleted: {
123 //main.addAccountsModelListener( globalStatusComponent );
124 main.accountsModelChanged.connect(onAccountsModelChanged);
125 main.presenceManagerChanged.connect(onPresenceManagerChaged);
130 ListElement { text: "Online"; icon: "img/status-online.png" ; index: 0}
131 ListElement { text: "Offline"; icon: "img/status-offline.png" ; index: 1}
132 ListElement { text: "Away"; icon: "img/status-away.png" ; index: 2}
133 ListElement { text: "eXtended Away"; icon: "img/status-xa.png" ; index: 3}
134 ListElement { text: "DND"; icon: "img/status-dnd.png" ; index: 4}
135 ListElement { text: "Invisible"; icon: "img/status-invisible.png" ; index: 5}
138 SystemPalette{ id: syspal }
148 anchors.verticalCenter: parent.verticalCenter
149 source: statusesModel.get(Makneto.TelepathyTypes.ConnectionPresenceTypeOffline).icon
150 height: parent.height - 6
155 height: presenceText.height + globalStatusMsgText.height
156 anchors.verticalCenter: globalStatusIcon.verticalCenter
157 anchors.left: globalStatusIcon.right
158 anchors.right: parent.right
159 anchors.leftMargin: 5
166 anchors.top: parent.top
167 anchors.right: parent.right
168 anchors.left: parent.left
169 wrapMode: Text.NoWrap
170 color: main.useSyspal? syspal.windowText : "white"
174 id: globalStatusMsgText
175 text: defaultStatusMsg
176 color: main.useSyspal? syspal.windowText : "white"
178 anchors.right: parent.right
179 anchors.left: parent.left
180 anchors.top: presenceText.bottom
181 //anchors.verticalCenter: globalStatusIcon.verticalCenter
183 //height: parent.height
184 wrapMode: Text.NoWrap
186 elide: Text.ElideRight; textFormat: Text.PlainText // this adds \x2026 (…) when text is too long
192 //log("clicked on statusIndicator ");
194 if(statusPopupComponent.status != Component.Ready){
195 error("Component "+statusPopupComponent.url+" is not ready!");
196 error(statusPopupComponent.errorString());
200 if (popup !== undefined && popup !== null && popup.state != "hide"){
204 popup = statusPopupComponent.createObject(main);
206 error("error creating popup");
207 error(statusPopupComponent.errorString());
210 var pos = statusIndicator.mapToItem(main,statusIndicator.width - main.toolbarHeight, main.toolbarHeight);
211 popup.popupFromX = pos.x;
212 popup.popupFromY = pos.y;
213 popup.finalWidth = main.width * .7;
214 popup.finalHeight = main.height * .5;
215 popup.statusesModel = statusesModel;
217 if (globalStatusComponent._presenceManager === undefined)
218 error("we don't have pressenceManager!");
219 popup.setGlobalStatusComponent( globalStatusComponent );
221 popup.state = "visible"
222 //log("visible popup "+JSON.stringify(parent));