-
Notifications
You must be signed in to change notification settings - Fork 1
/
citydetail.cpp
207 lines (191 loc) · 7.15 KB
/
citydetail.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#include "citydetail.h"
#include "ui_citydetail.h"
#include "osso-intl.h"
#include "clockd/libtime.h"
#include <QMaemo5Style>
#include <QDateTime>
#include <QSettings>
#include <QTimer>
static const char *getHildonTranslation(const char *string)
{
setlocale (LC_ALL, "");
const char *translation = ::dgettext("hildon-libs", string);
if (qstrcmp(string, translation) == 0)
return 0;
return translation;
}
const char *hldon24hFormat = getHildonTranslation("wdgt_va_24h_time");
const char *hldon12hAMFormat = getHildonTranslation("wdgt_va_12h_time_am");
const char *hldon12hPMFormat = getHildonTranslation("wdgt_va_12h_time_pm");
const char *hldonHHFormat = getHildonTranslation("wdgt_va_24h_hours");
bool HH24true;
int OffSetSecs;
QString CityCode;
static QString formatHildonDate(const QDateTime &dt, const char *format)
{
if (!format)
return QString();
char buf[255];
struct tm tm = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
if (!dt.date().isNull()) {
tm.tm_wday = dt.date().dayOfWeek() % 7;
tm.tm_mday = dt.date().day();
tm.tm_mon = dt.date().month() - 1;
tm.tm_year = dt.date().year() - 1900;
}
if (!dt.time().isNull()) {
tm.tm_sec = dt.time().second();
tm.tm_min = dt.time().minute();
tm.tm_hour = dt.time().hour();
}
size_t resultSize = ::strftime(buf, sizeof(buf), format, &tm);
if (!resultSize)
return QString();
return QString::fromUtf8(buf, resultSize);
}
CityDetail::CityDetail(QWidget *parent, QString city_country, QString city_code, QString external_gmt, QString local_gmt, bool hh24, int offset_sec ) :
QMainWindow(parent),
ui(new Ui::CityDetail)
{
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
this->setAttribute(Qt::WA_Maemo5AutoOrientation, true);
this->setAttribute(Qt::WA_Maemo5StackedWindow);
this->setWindowTitle(_("cloc_ti_world_clock_details"));
HH24true = hh24;
OffSetSecs = offset_sec;
CityCode = city_code;
// set secondary colors
QColor secondaryColor = QMaemo5Style::standardColor("SecondaryTextColor");
ui->time_diff->setStyleSheet(QString("color: rgb(%1, %2, %3);")
.arg(secondaryColor.red())
.arg(secondaryColor.green())
.arg(secondaryColor.blue()));
ui->city_country->setStyleSheet(QString("color: rgb(%1, %2, %3);")
.arg(secondaryColor.red())
.arg(secondaryColor.green())
.arg(secondaryColor.blue()));
ui->external_time->setStyleSheet(QString("color: rgb(%1, %2, %3);")
.arg(secondaryColor.red())
.arg(secondaryColor.green())
.arg(secondaryColor.blue()));
ui->loc_time->setStyleSheet(QString("color: rgb(%1, %2, %3);")
.arg(secondaryColor.red())
.arg(secondaryColor.green())
.arg(secondaryColor.blue()));
// set texts
ui->city_country->setText("(" + city_country + ")");
ui->gmt_offset->setText(external_gmt);
ui->loc_time_gmt->setText(_("cloc_fi_local_time") + " " + local_gmt);
ui->ext_time_header->setText(_("cloc_fi_remote_time"));
ui->time_diff_header->setText(_("cloc_fi_time_difference"));
// external GMT offset
int offset_minutes_ext_gmt = 0;
int offset_hours_ext_gmt = 0;
QString offset_time_ext_gmt = ui->gmt_offset->text().section( " ", 1, 1 );
if ( offset_time_ext_gmt.contains(":"))
{
// we also have minutes
offset_hours_ext_gmt = offset_time_ext_gmt.section( ":", 0, 0 ).toInt();
offset_hours_ext_gmt = offset_hours_ext_gmt * 60;
offset_minutes_ext_gmt = offset_time_ext_gmt.section( ":", 1, 1 ).toInt();
}
else
{
offset_hours_ext_gmt = offset_time_ext_gmt.toInt();
offset_hours_ext_gmt = offset_hours_ext_gmt * 60;
}
// local GMT offset
int offset_minutes_loc_gmt = 0;
int offset_hours_loc_gmt = 0;
QString offset_time_loc_gmt = local_gmt.section( " ", 1, 1 );
QString timediff_txt = "";
if ( offset_time_loc_gmt.contains(":"))
{
// we also have minutes
offset_hours_loc_gmt = offset_time_loc_gmt.section( ":", 0, 0 ).toInt();
offset_hours_loc_gmt = offset_hours_loc_gmt * 60;
offset_minutes_loc_gmt = offset_time_loc_gmt.section( ":", 1, 1 ).toInt();
}
else
{
offset_hours_loc_gmt = offset_time_loc_gmt.toInt();
offset_hours_loc_gmt = offset_hours_loc_gmt * 60;
}
QString tot_diff_txt = "";
int tot_diff_min = (- offset_minutes_loc_gmt + offset_minutes_ext_gmt) %60;
int tot_diff_hour = (-offset_hours_loc_gmt + offset_hours_ext_gmt )/60;
timediff_txt = QString::fromUtf8(ngettext("cloc_va_amount_hour", "cloc_va_amount_hours", abs(tot_diff_hour)));
if (tot_diff_hour > 0)
tot_diff_txt = "+" + QString::number(tot_diff_hour);
else
tot_diff_txt = QString::number(tot_diff_hour);
if (tot_diff_min != 0)
{
timediff_txt = timediff_txt + " " + _("cloc_va_diff_hours_mins");
timediff_txt.replace("%s %d",QString::number(abs(tot_diff_min)));
}
timediff_txt.replace("%+d",tot_diff_txt);
ui->time_diff->setText(timediff_txt);
intl("osso-connectivity-ui");
ui->actionDelete->setText(_("conn_bd_devices_delete"));
intl("osso-clock");
updateInfo();
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(updateInfo()));
timer->start(4000);
}
CityDetail::~CityDetail()
{
delete ui;
}
void CityDetail::on_actionDelete_triggered()
{
// remove city from the config file
QSettings settings("worldclock", "worldclock");
QStringList citylist = settings.value("Cities",QStringList()).toStringList();
citylist.removeOne(CityCode);
settings.setValue("Cities", citylist);
settings.sync();
this->close();
}
void CityDetail::updateInfo()
{
// refesh screen info
QDate curdate = QDate::currentDate();
QDateTime ext_datetime = QDateTime::currentDateTime();
ext_datetime = ext_datetime.toUTC();
ext_datetime = ext_datetime.addSecs( -OffSetSecs );
QString CurrTime;
QString ExtTime;
if (HH24true)
{
CurrTime = formatHildonDate(QDateTime::currentDateTime(), hldon24hFormat);
ExtTime = formatHildonDate(ext_datetime, hldon24hFormat);
}
else
{
QString HH = formatHildonDate(QDateTime::currentDateTime(), hldonHHFormat);
if ( HH.toInt() > 11 )
{
CurrTime = formatHildonDate(QDateTime::currentDateTime(), hldon12hPMFormat);
}
else
{
CurrTime = formatHildonDate(QDateTime::currentDateTime(), hldon12hAMFormat);
}
HH = formatHildonDate(ext_datetime, hldonHHFormat);
if ( HH.toInt() > 11 )
{
ExtTime = formatHildonDate(ext_datetime, hldon12hPMFormat);
}
else
{
ExtTime = formatHildonDate(ext_datetime, hldon12hAMFormat);
}
}
CurrTime = CurrTime + " - " + curdate.toString(Qt::DefaultLocaleLongDate);
ExtTime = ExtTime + " - " + ext_datetime.date().toString(Qt::DefaultLocaleLongDate);
ui->loc_time->setText(CurrTime);
ui->external_time->setText(ExtTime);
}