navit  0.5.1-trunk
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Groups
searchProxy.h
Go to the documentation of this file.
1 #ifndef NAVIT_GUI_QML_SEARCHPROXY_H
2 #define NAVIT_GUI_QML_SEARCHPROXY_H
3 
4 void __setNewPoint(struct gui_priv* this_,struct pcoord* pc, NGQPointTypes type);
5 
6 class NGQProxySearch : public NGQProxy {
7  Q_OBJECT;
8 
9  Q_PROPERTY(QString countryName READ countryName WRITE setCountryName NOTIFY countryNameSignal);
10  Q_PROPERTY(QString countryISO2 READ countryISO2 WRITE setCountryISO2 NOTIFY countryISO2Signal);
11  Q_PROPERTY(QString townName READ townName WRITE setTownName NOTIFY townNameSignal);
12  Q_PROPERTY(QString streetName READ streetName WRITE setStreetName NOTIFY streetNameSignal);
13 
14  Q_PROPERTY(QString searchContext READ searchContext WRITE setSearchContext);
15 
16 public:
17  NGQProxySearch(struct gui_priv* this_,QObject* parent) : NGQProxy(this_,parent) {
18  struct attr search_attr, country_name, country_iso2, *country_attr;
19  struct item *item;
20  struct country_search *cs;
21  struct tracking *tracking;
22  struct search_list_result *res;
23 
25  this->search_context="country";
26 
27  country_attr=country_default();
28  tracking=navit_get_tracking(this->object->nav);
29  if (tracking && tracking_get_attr(tracking, attr_country_id, &search_attr, NULL))
30  country_attr=&search_attr;
31  if (country_attr) {
32  cs=country_search_new(country_attr, 0);
33  item=country_search_get_item(cs);
34  if (item && item_attr_get(item, attr_country_name, &country_name)) {
35  search_attr.type=attr_country_all;
36  dbg(lvl_debug,"country %s\n", country_name.u.str);
37  this->country_name=QString::fromLocal8Bit(country_name.u.str);
38  search_attr.u.str=country_name.u.str;
39  search_list_search(this->sl, &search_attr, 0);
40  while((res=search_list_get_result(this->sl)));
41  if (item_attr_get(item, attr_country_iso2, &country_iso2)) {
42  this->country_iso2=QString::fromLocal8Bit(country_iso2.u.str);
43  }
44  }
46  } else {
47  dbg(lvl_error,"warning: no default country found\n");
48  if (!this->country_iso2.isEmpty()) {
49  dbg(lvl_debug,"attempting to use country '%s'\n",this->country_iso2.toStdString().c_str());
50  search_attr.type=attr_country_iso2;
51  search_attr.u.str=(char*)this->country_iso2.toStdString().c_str();
52  search_list_search(this->sl, &search_attr, 0);
53  while((res=search_list_get_result(this->sl)));
54  }
55  }
56  }
58  search_list_destroy(this->sl);
59  }
60 
61 signals:
62  void countryNameSignal(QString);
63  void countryISO2Signal(QString);
64  void townNameSignal(QString);
65  void streetNameSignal(QString);
66 
67 public slots:
69  struct attr attr;
70  struct search_list_result *res;
71 
72  if (this->street_name.length()>0) {
73  attr.type=attr_street_name;
74  attr.u.str=this->street_name.toLocal8Bit().data();
75  } else if (this->town_name.length()>0) {
76  attr.type=attr_town_or_district_name;
77  attr.u.str=this->town_name.toLocal8Bit().data();
78  } else if (this->country_name.length()>0) {
79  attr.type=attr_country_name;
80  attr.u.str=this->country_name.toLocal8Bit().data();
81  }
82  search_list_search(this->sl,&attr,0);
83  if ((res=search_list_get_result(this->sl))) {
84  __setNewPoint(this->object,res->c,PointOfInterest);
85  }
86  return;
87  }
88  QString searchXml() {
90  struct attr attr;
91  struct search_list_result *res;
92  int counter=0;
93  QDomDocument retDoc;
94  QDomElement entries;
95 
96  entries=retDoc.createElement("search");
97  retDoc.appendChild(entries);
98 
99  if (this->search_context=="country") {
100  attr.type=attr_country_name;
101  attr.u.str=this->country_name.toLocal8Bit().data();
102  }
103  if (this->search_context=="town") {
104  if (this->town_name.length()<3) {
105  return retDoc.toString();
106  }
107  attr.type=attr_town_or_district_name;
108  attr.u.str=this->town_name.toLocal8Bit().data();
109  }
110  if (this->search_context=="street") {
111  attr.type=attr_street_name;
112  attr.u.str=this->street_name.toLocal8Bit().data();
113  }
114 
115  search_list_search(this->sl,&attr,1);
116 
117  while ((res=search_list_get_result(this->sl))) {
118  QStandardItem* curItem=new QStandardItem();
119  QDomElement entry=retDoc.createElement("item");
120  entries.appendChild(entry);
121  //Result processing depends on search type
122  if (this->search_context=="country") {
123  entry.appendChild(this->_fieldValueHelper(retDoc,QString("id"), QString::number(counter)));
124  entry.appendChild(this->_fieldValueHelper(retDoc,QString("name"), QString::fromLocal8Bit(res->country->name)));
125  entry.appendChild(this->_fieldValueHelper(retDoc,QString("icon"), QString("country_%1%2").arg(res->country->iso2).arg(".svgz")));
126  }
127  if (this->search_context=="town") {
128  entry.appendChild(this->_fieldValueHelper(retDoc,QString("id"), QString::number(counter)));
129  if (res->town->common.town_name) {
130  entry.appendChild(this->_fieldValueHelper(retDoc,QString("name"),QString::fromLocal8Bit(res->town->common.town_name)));
131  }
132  if (res->town->common.district_name) {
133  entry.appendChild(this->_fieldValueHelper(retDoc,QString("name"), QString::fromLocal8Bit(res->town->common.district_name)));
134  }
135  }
136  if (this->search_context=="street") {
137  entry.appendChild(this->_fieldValueHelper(retDoc,QString("id"), QString::number(counter)));
138  entry.appendChild(this->_fieldValueHelper(retDoc,QString("name"),QString::fromLocal8Bit(res->street->name)));
139  }
140  counter++;
141  ret->appendRow(curItem);
142  }
143 
144  return retDoc.toString();
145  }
146  QString countryName() {
147  return this->country_name;
148  }
149  void setCountryName(QString countryName) {
151  struct attr attr;
152  struct search_list_result *res;
153 
154  //We need to update ISO2
155  attr.type=attr_country_name;
156  attr.u.str=countryName.toLocal8Bit().data();
157  search_list_search(this->sl,&attr,0);
158  while ((res=search_list_get_result(this->sl))) {
159  this->setCountryISO2(QString::fromLocal8Bit(res->country->iso2));
160  }
161  //...and current town
162  this->town_name="";
163  this->street_name="";
164 
165  countryNameSignal(countryName);
166  }
167  QString countryISO2() {
168  return this->country_iso2;
169  }
170  void setCountryISO2(QString countryISO2) {
172  countryISO2Signal(countryISO2);
173  }
174  QString townName() {
175  return this->town_name;
176  }
177  void setTownName(QString townName) {
178  struct attr attr;
179 
180  this->town_name=townName;
181 
182  //Specialize search
183  attr.type=attr_town_or_district_name;
184  attr.u.str=townName.toLocal8Bit().data();
185  search_list_search(this->sl,&attr,0);
186 
187  //...and street
188  this->street_name="";
189 
190  townNameSignal(townName);
191  }
192  QString streetName() {
193  return this->street_name;
194  }
195  void setStreetName(QString streetName) {
196  struct attr attr;
197 
198  this->street_name=streetName;
199 
200  //Specialize search
201  attr.type=attr_street_name;
202  attr.u.str=streetName.toLocal8Bit().data();
203  search_list_search(this->sl,&attr,0);
204 
205  streetNameSignal(streetName);
206  }
207  QString searchContext() {
208  return this->search_context;
209  }
212  }
213 
214 protected:
215  virtual int getAttrFunc(enum attr_type type, struct attr *attr, struct attr_iter *iter) {
216  return 0;
217  }
218  virtual int setAttrFunc(struct attr *attr) {
219  return 0;
220  }
221 private:
222  struct search_list *sl;
223  QString search_context;
225 };
226 
227 #include "searchProxy.moc"
228 
229 #endif /* NAVIT_GUI_QML_SEARCHPROXY_H */
attr_type
Definition: attr.h:34
Definition: country.c:296
Definition: mg.h:144
int item_attr_get(struct item *it, enum attr_type attr_type, struct attr *attr)
Definition: item.c:256
void setStreetName(QString streetName)
Definition: searchProxy.h:195
QString searchXml()
Definition: searchProxy.h:88
QString countryISO2()
Definition: searchProxy.h:167
tuple iter
Definition: eval.py:8
Definition: gpx2navit_txt.h:51
struct search_list * sl
Definition: searchProxy.h:222
struct search_list_result * search_list_get_result(struct search_list *this_)
Get (next) result from a search.
Definition: search.c:848
Definition: item.h:99
QString search_context
Definition: searchProxy.h:223
void countryNameSignal(QString)
struct search_list_country * country
Definition: search.h:68
struct attr * country_default(void)
Definition: country.c:419
int tracking_get_attr(struct tracking *_this, enum attr_type type, struct attr *attr, struct attr_iter *attr_iter)
Definition: track.c:334
Definition: proxy.h:4
void setSearchContext(QString searchContext)
Definition: searchProxy.h:210
void streetNameSignal(QString)
void countryISO2Signal(QString)
void country_search_destroy(struct country_search *this_)
Definition: country.c:434
struct search_list_town * town
Definition: search.h:69
Definition: track.c:85
void setCountryISO2(QString countryISO2)
Definition: searchProxy.h:170
struct tracking * navit_get_tracking(struct navit *this_)
Definition: navit.c:227
struct mapset * navit_get_mapset(struct navit *this_)
Definition: navit.c:216
QString streetName()
Definition: searchProxy.h:192
QString street_name
Definition: searchProxy.h:224
Definition: graphics_win32.h:52
QString countryName()
Definition: searchProxy.h:146
QDomElement _fieldValueHelper(QDomDocument doc, QString field, QString value)
Definition: proxy.h:98
void __setNewPoint(struct gui_priv *this_, struct pcoord *pc, NGQPointTypes type)
Definition: guiProxy.h:146
void search_list_search(struct search_list *this_, struct attr *search_attr, int partial)
Start a search.
Definition: search.c:347
#define dbg(level,...)
Definition: debug.h:59
struct pcoord * c
Definition: search.h:67
Definition: debug.h:46
Definition: debug.h:52
Definition: config_.c:48
QString townName()
Definition: searchProxy.h:174
union attr::@0 u
void setPointToResult()
Definition: searchProxy.h:68
Definition: search.c:61
struct navit * nav
Definition: graphics_win32.h:53
QString country_iso2
Definition: searchProxy.h:224
Definition: attr.h:156
static struct item_bin item
Definition: osm.c:52
char * iso2
Definition: search.h:42
struct search_list * search_list_new(struct mapset *ms)
Create new instance of search_list to run a search.
Definition: search.c:100
enum attr_type type
Definition: attr.h:157
char * name
Definition: search.h:56
struct country_search * country_search_new(struct attr *search, int partial)
Definition: country.c:361
virtual int getAttrFunc(enum attr_type type, struct attr *attr, struct attr_iter *iter)
Definition: searchProxy.h:215
void setCountryName(QString countryName)
Definition: searchProxy.h:149
void setTownName(QString townName)
Definition: searchProxy.h:177
void townNameSignal(QString)
void search_list_destroy(struct search_list *this_)
Definition: search.c:1041
QString searchContext()
Definition: searchProxy.h:207
char * str
Definition: attr.h:159
char * name
Definition: search.h:44
~NGQProxySearch()
Definition: searchProxy.h:57
Definition: search.h:65
Definition: ngqpoint.h:32
NGQPointTypes
Definition: ngqpoint.h:32
struct item * country_search_get_item(struct country_search *this_)
Definition: country.c:398
Definition: searchProxy.h:6
char * town_name
Definition: search.h:31
struct gui_priv * object
Definition: proxy.h:89
virtual int setAttrFunc(struct attr *attr)
Definition: searchProxy.h:218
NGQProxySearch(struct gui_priv *this_, QObject *parent)
Definition: searchProxy.h:17
struct search_list_street * street
Definition: search.h:70
static GtkActionEntry entries[]
Definition: gui_gtk_action.c:224
char type[3]
Definition: garmin_img.c:130
QString country_name
Definition: searchProxy.h:224
char * district_name
Definition: search.h:32
struct search_list_common common
Definition: search.h:49
Definition: coord.h:40
Definition: proxy.h:21
QString town_name
Definition: searchProxy.h:224