navit  0.5.1-trunk
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Groups
bookmarksProxy.h
Go to the documentation of this file.
1 #ifndef NAVIT_GUI_QML_BOOKMARKSPROXY_H
2 #define NAVIT_GUI_QML_BOOKMARKSPROXY_H
3 
4 class NGQProxyBookmarks : public NGQProxy {
5  Q_OBJECT;
6 
7 public:
8  NGQProxyBookmarks(struct gui_priv* object, QObject* parent) : NGQProxy(object,parent) { };
9 
10 public slots:
11  void moveRoot() {
12  struct attr mattr;
13  navit_get_attr(this->object->nav, attr_bookmarks, &mattr, NULL);
15  }
16  void moveUp() {
17  struct attr mattr;
18  navit_get_attr(this->object->nav, attr_bookmarks, &mattr, NULL);
20  }
21  void moveDown(QString path) {
22  struct attr mattr;
23  navit_get_attr(this->object->nav, attr_bookmarks, &mattr, NULL);
24  bookmarks_move_down(mattr.u.bookmarks,path.toLocal8Bit().constData());
25  }
26 
27  QString getBookmarks() {
28  struct attr attr,mattr;
29  struct item* item;
30  struct coord c;
31  QDomDocument retDoc("bookmarks");
32  QDomElement entries;
33 
34  entries=retDoc.createElement("bookmarks");
35  retDoc.appendChild(entries);
36 
37  navit_get_attr(this->object->nav, attr_bookmarks, &mattr, NULL);
38 
39  if (bookmarks_item_cwd(mattr.u.bookmarks)) {
40  QDomElement entry=retDoc.createElement("bookmark");
41  entry.appendChild(this->_fieldValueHelper(retDoc,"label",".."));
42  entry.appendChild(this->_fieldValueHelper(retDoc,"path",".."));
43  entry.appendChild(this->_fieldValueHelper(retDoc,"type",QString(item_to_name(type_bookmark_folder))));
44  entry.appendChild(this->_fieldValueHelper(retDoc,"distance",""));
45  entry.appendChild(this->_fieldValueHelper(retDoc,"direction",""));
46  entry.appendChild(this->_fieldValueHelper(retDoc,"coords",QString("%1 %2").arg(0).arg(0)));
47  entries.appendChild(entry);
48  }
49 
51  while ((item=bookmarks_get_item(mattr.u.bookmarks))) {
52  QString label;
53  QString path;
54 
55  if (item->type != type_bookmark && item->type != type_bookmark_folder) continue;
56  if (!item_attr_get(item, attr_label, &attr)) continue;
57  label=QString::fromLocal8Bit(attr.u.str);
58  if (!item_attr_get(item, attr_path, &attr)) {
59  path="";
60  }
61  path=QString::fromLocal8Bit(attr.u.str);
62  item_coord_get(item, &c, 1);
63  QDomElement entry=retDoc.createElement("bookmark");
64  entry.appendChild(this->_fieldValueHelper(retDoc,"label",label));
65  entry.appendChild(this->_fieldValueHelper(retDoc,"path",path));
66  entry.appendChild(this->_fieldValueHelper(retDoc,"type",QString(item_to_name(item->type))));
67  //entry.appendChild(this->_fieldValueHelper(retDoc,"distance",QString::number(idist/1000)));
68  entry.appendChild(this->_fieldValueHelper(retDoc,"distance","100500"));
69  //entry.appendChild(this->_fieldValueHelper(retDoc,"direction",dirbuf));
70  entry.appendChild(this->_fieldValueHelper(retDoc,"direction","nahut"));
71  entry.appendChild(this->_fieldValueHelper(retDoc,"coords",QString("%1 %2").arg(c.x).arg(c.y)));
72  entries.appendChild(entry);
73  }
74 
75  dbg(lvl_info,"%s\n",retDoc.toString().toLocal8Bit().constData());
76  return retDoc.toString();
77  }
78  QString AddFolder(QString description) {
79  struct attr attr;
80  navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL);
81  if (!bookmarks_add_bookmark(attr.u.bookmarks, NULL, description.toLocal8Bit().constData()) ) {
82  return "Failed!";
83  } else {
84  return "Success";
85  }
86  }
87  QString AddBookmark(QString description) {
88  struct attr attr;
89  navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL);
90  if (!bookmarks_add_bookmark(attr.u.bookmarks, this->object->currentPoint->pc(), description.toLocal8Bit().constData()) ) {
91  return "Failed!";
92  } else {
93  return "Success";
94  }
95  }
96  QString Cut(QString description) {
97  struct attr attr;
98  navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL);
99  if (!bookmarks_cut_bookmark(attr.u.bookmarks, description.toLocal8Bit().constData()) ) {
100  return "Failed!";
101  } else {
102  return "Success";
103  }
104  }
105  QString Copy(QString description) {
106  struct attr attr;
107  navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL);
108  if (!bookmarks_copy_bookmark(attr.u.bookmarks, description.toLocal8Bit().constData()) ) {
109  return "Failed!";
110  } else {
111  return "Success";
112  }
113  }
114  QString Paste() {
115  struct attr attr;
116  navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL);
117  if (!bookmarks_paste_bookmark(attr.u.bookmarks) ) {
118  return "Failed!";
119  } else {
120  return "Success";
121  }
122  }
123  QString Delete(QString bookmark) {
124  struct attr attr;
125  navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL);
126  if (!bookmarks_delete_bookmark(attr.u.bookmarks, bookmark.toLocal8Bit().constData()) ) {
127  return "Failed!";
128  } else {
129  return "Success";
130  }
131  }
132  void setPoint(QString bookmark) {
133  struct attr attr, mattr;
134  struct item* item;
135  struct coord c;
136 
137  navit_get_attr(this->object->nav, attr_bookmarks, &mattr, NULL);
138 
140  while ((item=bookmarks_get_item(mattr.u.bookmarks))) {
141  QString label;
142 
143  if (item->type != type_bookmark) continue;
144  if (!item_attr_get(item, attr_label, &attr)) continue;
145 
146  label=QString::fromLocal8Bit(attr.u.str);
147  dbg(lvl_debug,"Bookmark is %s\n",bookmark.toStdString().c_str());
148  if (label.compare(bookmark)) continue;
149  item_coord_get(item, &c, 1);
150  if (this->object->currentPoint!=NULL) {
151  delete this->object->currentPoint;
152  }
153  this->object->currentPoint=new NGQPoint(this->object,&c,bookmark,Bookmark,NULL);
154  this->object->guiWidget->rootContext()->setContextProperty("point",this->object->currentPoint);
155  }
156 
157  return;
158  }
159 
160 protected:
161  int getAttrFunc(enum attr_type type, struct attr* attr, struct attr_iter* iter) { return 0; }
162  int setAttrFunc(struct attr* attr) {return 0; }
163  struct attr_iter* getIterFunc() { return NULL; };
164  void dropIterFunc(struct attr_iter* iter) { return; };
165 
166 private:
167 };
168 
169 #include "bookmarksProxy.moc"
170 
171 #endif /* NAVIT_GUI_QML_BOOKMARKSPROXY_H */
QString AddBookmark(QString description)
Definition: bookmarksProxy.h:87
attr_type
Definition: attr.h:34
int bookmarks_add_bookmark(struct bookmarks *this_, struct pcoord *pc, const char *description)
Definition: bookmarks.c:491
int item_coord_get(struct item *it, struct coord *c, int count)
Gets the next coordinates from an item.
Definition: item.c:168
Definition: debug.h:50
int item_attr_get(struct item *it, enum attr_type attr_type, struct attr *attr)
Definition: item.c:256
tuple iter
Definition: eval.py:8
Definition: gpx2navit_txt.h:51
static char * description(struct search_param *search, GtkTreeIter *iter)
Definition: destination.c:71
int y
Definition: coord.h:36
int navit_get_attr(struct navit *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
Definition: navit.c:2736
QString Delete(QString bookmark)
Definition: bookmarksProxy.h:123
Definition: item.h:99
void dropIterFunc(struct attr_iter *iter)
Definition: bookmarksProxy.h:164
QString AddFolder(QString description)
Definition: bookmarksProxy.h:78
QString Copy(QString description)
Definition: bookmarksProxy.h:105
int getAttrFunc(enum attr_type type, struct attr *attr, struct attr_iter *iter)
Definition: bookmarksProxy.h:161
enum item_type type
Definition: item.h:100
NGQProxyBookmarks(struct gui_priv *object, QObject *parent)
Definition: bookmarksProxy.h:8
void bookmarks_move_root(struct bookmarks *this_)
Definition: bookmarks.c:83
void moveDown(QString path)
Definition: bookmarksProxy.h:21
int bookmarks_paste_bookmark(struct bookmarks *this_)
Definition: bookmarks.c:555
Definition: ngqpoint.h:32
char * item_to_name(enum item_type item)
Definition: item.c:310
int bookmarks_move_down(struct bookmarks *this_, const char *name)
Definition: bookmarks.c:96
Definition: graphics_win32.h:52
QString Cut(QString description)
Definition: bookmarksProxy.h:96
void setPoint(QString bookmark)
Definition: bookmarksProxy.h:132
QDomElement _fieldValueHelper(QDomDocument doc, QString field, QString value)
Definition: proxy.h:98
#define dbg(level,...)
Definition: debug.h:59
struct attr_iter * getIterFunc()
Definition: bookmarksProxy.h:163
Definition: debug.h:52
Definition: config_.c:48
int bookmarks_copy_bookmark(struct bookmarks *this_, const char *label)
Definition: bookmarks.c:532
union attr::@0 u
struct navit * nav
Definition: graphics_win32.h:53
Definition: attr.h:156
QString Paste()
Definition: bookmarksProxy.h:114
static struct item_bin item
Definition: osm.c:52
Definition: bookmarksProxy.h:4
const char * bookmarks_item_cwd(struct bookmarks *this_)
Definition: bookmarks.c:146
struct item * bookmarks_get_item(struct bookmarks *this_)
Definition: bookmarks.c:119
void bookmarks_move_up(struct bookmarks *this_)
Definition: bookmarks.c:89
char * str
Definition: attr.h:159
int bookmarks_cut_bookmark(struct bookmarks *this_, const char *label)
Definition: bookmarks.c:524
void moveUp()
Definition: bookmarksProxy.h:16
void bookmarks_item_rewind(struct bookmarks *this_)
Definition: bookmarks.c:114
struct gui_priv * object
Definition: proxy.h:89
int bookmarks_delete_bookmark(struct bookmarks *this_, const char *label)
Definition: bookmarks.c:588
Definition: ngqpoint.h:34
static GtkActionEntry entries[]
Definition: gui_gtk_action.c:224
struct bookmarks * bookmarks
Definition: attr.h:201
struct label_data_offset label
Definition: garmin_img.c:409
char type[3]
Definition: garmin_img.c:130
void moveRoot()
Definition: bookmarksProxy.h:11
Definition: coord.h:34
class NGQPoint * currentPoint
Definition: gui_qml.cpp:80
int setAttrFunc(struct attr *attr)
Definition: bookmarksProxy.h:162
Definition: proxy.h:21
QString getBookmarks()
Definition: bookmarksProxy.h:27
int x
Definition: coord.h:35