navit 0.5.3-trunk
Loading...
Searching...
No Matches
bookmarksProxy.h
Go to the documentation of this file.
1#ifndef NAVIT_GUI_QML_BOOKMARKSPROXY_H
2#define NAVIT_GUI_QML_BOOKMARKSPROXY_H
3
4class 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)
56 continue;
57 if (!item_attr_get(item, attr_label, &attr))
58 continue;
59 label = QString::fromLocal8Bit(attr.u.str);
60 if (!item_attr_get(item, attr_path, &attr)) {
61 path = "";
62 }
63 path = QString::fromLocal8Bit(attr.u.str);
64 item_coord_get(item, &c, 1);
65 QDomElement entry = retDoc.createElement("bookmark");
66 entry.appendChild(this->_fieldValueHelper(retDoc, "label", label));
67 entry.appendChild(this->_fieldValueHelper(retDoc, "path", path));
68 entry.appendChild(this->_fieldValueHelper(retDoc, "type", QString(item_to_name(item->type))));
69 // entry.appendChild(this->_fieldValueHelper(retDoc,"distance",QString::number(idist/1000)));
70 entry.appendChild(this->_fieldValueHelper(retDoc, "distance", "100500"));
71 // entry.appendChild(this->_fieldValueHelper(retDoc,"direction",dirbuf));
72 entry.appendChild(this->_fieldValueHelper(retDoc, "direction", "nahut"));
73 entry.appendChild(this->_fieldValueHelper(retDoc, "coords", QString("%1 %2").arg(c.x).arg(c.y)));
74 entries.appendChild(entry);
75 }
76
77 dbg(lvl_info, "%s", retDoc.toString().toLocal8Bit().constData());
78 return retDoc.toString();
79 }
80 QString AddFolder(QString description) {
81 struct attr attr;
82 navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL);
83 if (!bookmarks_add_bookmark(attr.u.bookmarks, NULL, description.toLocal8Bit().constData())) {
84 return "Failed!";
85 } else {
86 return "Success";
87 }
88 }
89 QString AddBookmark(QString description) {
90 struct attr attr;
91 navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL);
92 if (!bookmarks_add_bookmark(attr.u.bookmarks, this->object->currentPoint->pc(),
93 description.toLocal8Bit().constData())) {
94 return "Failed!";
95 } else {
96 return "Success";
97 }
98 }
99 QString Cut(QString description) {
100 struct attr attr;
101 navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL);
102 if (!bookmarks_cut_bookmark(attr.u.bookmarks, description.toLocal8Bit().constData())) {
103 return "Failed!";
104 } else {
105 return "Success";
106 }
107 }
108 QString Copy(QString description) {
109 struct attr attr;
110 navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL);
111 if (!bookmarks_copy_bookmark(attr.u.bookmarks, description.toLocal8Bit().constData())) {
112 return "Failed!";
113 } else {
114 return "Success";
115 }
116 }
117 QString Paste() {
118 struct attr attr;
119 navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL);
121 return "Failed!";
122 } else {
123 return "Success";
124 }
125 }
126 QString Delete(QString bookmark) {
127 struct attr attr;
128 navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL);
129 if (!bookmarks_delete_bookmark(attr.u.bookmarks, bookmark.toLocal8Bit().constData())) {
130 return "Failed!";
131 } else {
132 return "Success";
133 }
134 }
135 void setPoint(QString bookmark) {
136 struct attr attr, mattr;
137 struct item *item;
138 struct coord c;
139
140 navit_get_attr(this->object->nav, attr_bookmarks, &mattr, NULL);
141
143 while ((item = bookmarks_get_item(mattr.u.bookmarks))) {
144 QString label;
145
146 if (item->type != type_bookmark)
147 continue;
148 if (!item_attr_get(item, attr_label, &attr))
149 continue;
150
151 label = QString::fromLocal8Bit(attr.u.str);
152 dbg(lvl_debug, "Bookmark is %s", bookmark.toStdString().c_str());
153 if (label.compare(bookmark))
154 continue;
155 item_coord_get(item, &c, 1);
156 if (this->object->currentPoint != NULL) {
157 delete this->object->currentPoint;
158 }
159 this->object->currentPoint = new NGQPoint(this->object, &c, bookmark, Bookmark, NULL);
160 this->object->guiWidget->rootContext()->setContextProperty("point", this->object->currentPoint);
161 }
162
163 return;
164 }
165
166 protected:
167 int getAttrFunc(enum attr_type type, struct attr *attr, struct attr_iter *iter) {
168 return 0;
169 }
170 int setAttrFunc(struct attr *attr) {
171 return 0;
172 }
174 return NULL;
175 };
176 void dropIterFunc(struct attr_iter *iter) {
177 return;
178 };
179
180 private:
181};
182
183#include "bookmarksProxy.moc"
184
185#endif /* NAVIT_GUI_QML_BOOKMARKSPROXY_H */
attr_type
Definition attr_type_def.h:11
int bookmarks_add_bookmark(struct bookmarks *this_, struct pcoord *pc, const char *description)
Definition bookmarks.c:481
const char * bookmarks_item_cwd(struct bookmarks *this_)
Definition bookmarks.c:145
int bookmarks_copy_bookmark(struct bookmarks *this_, const char *label)
Definition bookmarks.c:519
int bookmarks_paste_bookmark(struct bookmarks *this_)
Definition bookmarks.c:541
int bookmarks_cut_bookmark(struct bookmarks *this_, const char *label)
Definition bookmarks.c:512
struct item * bookmarks_get_item(struct bookmarks *this_)
Definition bookmarks.c:118
void bookmarks_item_rewind(struct bookmarks *this_)
Definition bookmarks.c:113
void bookmarks_move_root(struct bookmarks *this_)
Definition bookmarks.c:82
int bookmarks_move_down(struct bookmarks *this_, const char *name)
Definition bookmarks.c:95
void bookmarks_move_up(struct bookmarks *this_)
Definition bookmarks.c:88
int bookmarks_delete_bookmark(struct bookmarks *this_, const char *label)
Definition bookmarks.c:573
Definition ngqpoint.h:38
Definition bookmarksProxy.h:4
QString Paste()
Definition bookmarksProxy.h:117
void moveRoot()
Definition bookmarksProxy.h:11
QString getBookmarks()
Definition bookmarksProxy.h:27
void dropIterFunc(struct attr_iter *iter)
Definition bookmarksProxy.h:176
void setPoint(QString bookmark)
Definition bookmarksProxy.h:135
QString Delete(QString bookmark)
Definition bookmarksProxy.h:126
QString Copy(QString description)
Definition bookmarksProxy.h:108
QString Cut(QString description)
Definition bookmarksProxy.h:99
int setAttrFunc(struct attr *attr)
Definition bookmarksProxy.h:170
QString AddFolder(QString description)
Definition bookmarksProxy.h:80
NGQProxyBookmarks(struct gui_priv *object, QObject *parent)
Definition bookmarksProxy.h:8
QString AddBookmark(QString description)
Definition bookmarksProxy.h:89
struct attr_iter * getIterFunc()
Definition bookmarksProxy.h:173
void moveUp()
Definition bookmarksProxy.h:16
int getAttrFunc(enum attr_type type, struct attr *attr, struct attr_iter *iter)
Definition bookmarksProxy.h:167
void moveDown(QString path)
Definition bookmarksProxy.h:21
Definition proxy.h:28
struct gui_priv * object
Definition proxy.h:98
QDomElement _fieldValueHelper(QDomDocument doc, QString field, QString value)
Definition proxy.h:111
@ lvl_info
Definition debug.h:50
@ lvl_debug
Definition debug.h:52
#define dbg(level,...)
Definition debug.h:59
static char * description(struct search_param *search, GtkTreeIter *iter)
Definition destination.c:56
struct label_data_offset label
Definition garmin_img.c:1
char type[3]
Definition garmin_img.c:2
int navit_get_attr(struct navit *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
Definition navit.c:2794
static GtkActionEntry entries[]
Definition gui_gtk_action.c:196
int item_attr_get(struct item *it, enum attr_type attr_type, struct attr *attr)
Gets the next matching attribute from an item.
Definition item.c:414
char * item_to_name(enum item_type item)
Definition item.c:483
int item_coord_get(struct item *it, struct coord *c, int count)
Gets the next coordinates from an item.
Definition item.c:163
@ Bookmark
Definition ngqpoint.h:32
static struct pcoord c
Definition popup.c:375
Definition config_.c:47
Definition attr.h:138
struct bookmarks * bookmarks
Definition attr.h:184
char * str
Definition attr.h:141
union attr::@0 u
Definition coord.h:33
Definition graphics_win32.h:50
class NGQPoint * currentPoint
Definition gui_qml.cpp:80
struct navit * nav
Definition graphics_win32.h:51
Represents an object on a map.
Definition item.h:122
enum item_type type
Definition item.h:123
Definition gpx2navit_txt.h:50
int y
Definition coord.h:54
int x
Definition coord.h:53