-
Notifications
You must be signed in to change notification settings - Fork 1
/
dialog3.cpp
151 lines (135 loc) · 4.4 KB
/
dialog3.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
#include "dialog3.h"
#include "ui_dialog3.h"
#include "cityinfo.h"
#include "clockd/libtime.h"
#include "osso-intl.h"
#include <QSettings>
/* Setting of the worldclock cities */
Dialog3::Dialog3(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog3)
{
ui->setupUi(this);
this->setProperty("X-Maemo-Orientation", 2);
this->setWindowTitle(_("cloc_ti_search_city_title"));
ui->cancelSearch_pushButton->setIcon(QIcon::fromTheme("general_close"));
ui->swidget->hide();
this->selected = "";
// int ret = 0;
char current_tz[32];
// ret = time_get_timezone(¤t_tz[0],32);
QString defTZ = QString::fromUtf8(current_tz);
ui->listWidget->clear();
Cityinfo **cities = cityinfo_get_all();
for (int i = 0; cities && cities[i]; ++i) {
QString name = QString::fromUtf8(cityinfo_get_name(cities[i]));
QString country = QString::fromUtf8(cityinfo_get_country(cities[i]));
QString zone = ":" + QString::fromUtf8(cityinfo_get_zone(cities[i]));
QString timeoffset;
QString sign;
int offset = time_get_utc_offset(cityinfo_get_zone(cities[i]));
if (offset > 0)
sign = "";
else
sign = "+";
if((offset % 3600)==0)
timeoffset = QString("[%1]GMT %3 (%1, %2)").arg(name).arg(country).arg(sign+QString::number(-offset/3600));
else
{
int minutes = -offset/60 %60;
timeoffset = QString("[%1]GMT %3:%4 (%1, %2)").arg(name).arg(country).arg(sign+QString::number(-offset/3600)).arg(abs(minutes));
}
QListWidgetItem *item1 = new QListWidgetItem(ui->listWidget);
item1->setText(timeoffset);
item1->setStatusTip(QString::number(cities[i]->id));
if (qstrcmp(cityinfo_get_code(cities[i]),"IS") == 0)
{
// use Iceland for own UTC zone
timeoffset = QString("[%1]GMT %3 (%1/%2)").arg("GMT").arg("UTC").arg(sign+QString::number(-offset/3600));
QListWidgetItem *item1 = new QListWidgetItem(ui->listWidget);
item1->setText(timeoffset);
// and give this own UTC its unique own number
item1->setStatusTip(QString::number(999));
}
if (zone == defTZ)
defTZ = timeoffset;
}
cityinfo_free_all(cities);
// sort cities
ui->listWidget->sortItems();
// and remove the sort key (cityname) in front
for ( int i=0; i < ui->listWidget->count(); ++i)
{
QString cityInfoLine = ui->listWidget->item(i)->text();
cityInfoLine.remove(QRegExp("^\\[.+\\]"));
ui->listWidget->item(i)->setText(cityInfoLine);
}
connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(orientationChanged()));
ui->listWidget->viewport()->installEventFilter(this);
}
Dialog3::~Dialog3()
{
delete ui;
}
void Dialog3::on_cancelSearch_pushButton_pressed()
{
ui->search->setText("");
ui->swidget->hide();
}
void Dialog3::keyReleaseEvent(QKeyEvent *k)
{
if ( ui->search->hasFocus()==false )
{
ui->swidget->show();
ui->search->setFocus();
if ( k->key() == 16777219 )
{
// backspace
QString pepe = ui->search->text();
if ( pepe.length() > 0 ) pepe.remove(pepe.length()-1,1);
ui->search->setFocus(); ui->search->setText(pepe);
return;
}
else
{
ui->search->setText( ui->search->text() + k->text() );
}
}
}
void Dialog3::on_search_textChanged(QString filter)
{
for ( int i=0; i < ui->listWidget->count(); ++i)
{
if ( ui->listWidget->item(i)->text().toLower().indexOf( filter.toLower() ) == -1 )
{
ui->listWidget->item(i)->setHidden(true);
}
else
{
ui->listWidget->item(i)->setHidden(false);
}
}
}
bool Dialog3::eventFilter(QObject *, QEvent *e)
{
if (e->type() == QEvent::MouseButtonPress
&& static_cast<QMouseEvent*>(e)->y() > ui->listWidget->viewport()->height() - 25
&& ui->swidget->isHidden()) {
ui->swidget->show();
}
return false;
}
void Dialog3::orientationChanged()
{
if (QApplication::desktop()->screenGeometry().width() < QApplication::desktop()->screenGeometry().height())
{
// restore portrait size
this->setMinimumHeight(680);
this->setMaximumHeight(680);
}
}
void Dialog3::on_listWidget_itemActivated(QListWidgetItem* item)
{
this->selected = item->statusTip();
this->accept();
}