1 /*
2 * geolocationdlg.cpp
3 * Copyright (C) 2009 Evgeny Khryukin
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 */
20
21 #include "geolocationdlg.h"
22
23 #include "xmpp_pubsubitem.h"
24 #include "xmpp_client.h"
25 #include "xmpp_task.h"
26 #include "psiaccount.h"
27 #include "pepmanager.h"
28 #include "geolocation.h"
29 #include <QLineEdit>
30
GeoLocationDlg(QList<PsiAccount * > list)31 GeoLocationDlg::GeoLocationDlg(QList<PsiAccount*> list) : QDialog(0), pa_(list)
32 {
33 setAttribute(Qt::WA_DeleteOnClose);
34 if(pa_.isEmpty())
35 close();
36 ui_.setupUi(this);
37 setModal(false);
38 connect(ui_.pb_cancel, SIGNAL(clicked()), SLOT(close()));
39 connect(ui_.pb_ok, SIGNAL(clicked()), SLOT(setGeoLocation()));
40 connect(ui_.pb_reset, SIGNAL(clicked()), SLOT(reset()));
41
42 PsiAccount *pa = pa_.first();
43 GeoLocation geoloc = pa->geolocation();
44 if(geoloc.isNull())
45 return;
46
47 if (geoloc.alt().hasValue())
48 ui_.le_altitude->setText(QString::number(geoloc.alt().value()));
49
50 if (!geoloc.area().isEmpty())
51 ui_.le_area->setText(geoloc.area());
52
53 if (geoloc.bearing().hasValue())
54 ui_.le_bearing->setText(QString::number(geoloc.bearing().value()));
55
56 if (!geoloc.building().isEmpty())
57 ui_.le_building->setText(geoloc.building());
58
59 if (!geoloc.country().isEmpty())
60 ui_.le_country->setText(geoloc.country());
61
62 if (!geoloc.datum().isEmpty())
63 ui_.le_datum->setText(geoloc.datum());
64
65 if (!geoloc.description().isEmpty())
66 ui_.le_description->setText(geoloc.description());
67
68 if (geoloc.error().hasValue())
69 ui_.le_error->setText(QString::number(geoloc.error().value()));
70
71 if (!geoloc.floor().isEmpty())
72 ui_.le_floor->setText(geoloc.floor());
73
74 if (geoloc.lat().hasValue())
75 ui_.le_latitude->setText(QString::number(geoloc.lat().value()));
76
77 if (!geoloc.locality().isEmpty())
78 ui_.le_locality->setText(geoloc.locality());
79
80 if (geoloc.lon().hasValue())
81 ui_.le_longitude->setText(QString::number(geoloc.lon().value()));
82
83 if (!geoloc.postalcode().isEmpty())
84 ui_.le_postalcode->setText(geoloc.postalcode());
85
86 if (!geoloc.region().isEmpty())
87 ui_.le_region->setText(geoloc.region());
88
89 if (!geoloc.room().isEmpty())
90 ui_.le_room->setText(geoloc.room());
91
92 if (!geoloc.street().isEmpty())
93 ui_.le_street->setText(geoloc.street());
94
95 if (!geoloc.text().isEmpty())
96 ui_.le_text->setText(geoloc.text());
97 }
98
reset()99 void GeoLocationDlg::reset()
100 {
101 foreach(QLineEdit *le, this->findChildren<QLineEdit*>()) {
102 le->setText("");
103 }
104 }
105
setGeoLocation()106 void GeoLocationDlg::setGeoLocation()
107 {
108 GeoLocation geoloc;
109
110 if(!ui_.le_altitude->text().isEmpty())
111 geoloc.setAlt(ui_.le_altitude->text().toFloat());
112
113 if(!ui_.le_bearing->text().isEmpty())
114 geoloc.setBearing(ui_.le_bearing->text().toFloat());
115
116 if(!ui_.le_error->text().isEmpty())
117 geoloc.setError(ui_.le_error->text().toFloat());
118
119 if(!ui_.le_latitude->text().isEmpty())
120 geoloc.setLat(ui_.le_latitude->text().toFloat());
121
122 if(!ui_.le_longitude->text().isEmpty())
123 geoloc.setLon(ui_.le_longitude->text().toFloat());
124
125 if(!ui_.le_datum->text().isEmpty())
126 geoloc.setDatum(ui_.le_datum->text());
127
128 if(!ui_.le_description->text().isEmpty())
129 geoloc.setDescription(ui_.le_description->text());
130
131 if(!ui_.le_country->text().isEmpty())
132 geoloc.setCountry(ui_.le_country->text());
133
134 if(!ui_.le_region->text().isEmpty())
135 geoloc.setRegion(ui_.le_region->text());
136
137 if(!ui_.le_locality->text().isEmpty())
138 geoloc.setLocality(ui_.le_locality->text());
139
140 if(!ui_.le_area->text().isEmpty())
141 geoloc.setArea(ui_.le_area->text());
142
143 if(!ui_.le_street->text().isEmpty())
144 geoloc.setStreet(ui_.le_street->text());
145
146 if(!ui_.le_building->text().isEmpty())
147 geoloc.setBuilding(ui_.le_building->text());
148
149 if(!ui_.le_floor->text().isEmpty())
150 geoloc.setFloor(ui_.le_floor->text());
151
152 if(!ui_.le_room->text().isEmpty())
153 geoloc.setRoom(ui_.le_room->text());
154
155 if(!ui_.le_postalcode->text().isEmpty())
156 geoloc.setPostalcode(ui_.le_postalcode->text());
157
158 if(!ui_.le_text->text().isEmpty())
159 geoloc.setText(ui_.le_text->text());
160
161 foreach(PsiAccount *pa, pa_) {
162 if (geoloc.isNull()) {
163 pa->pepManager()->disable(PEP_GEOLOC_TN, PEP_GEOLOC_NS, "current");
164 }
165 else {
166 pa->pepManager()->publish(PEP_GEOLOC_NS, PubSubItem("current",geoloc.toXml(*pa->client()->rootTask()->doc())));
167 }
168 }
169 close();
170 }
171
172