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);
|
14 |
bookmarks_move_root(mattr.u.bookmarks);
|
15 |
}
|
16 |
void moveUp() {
|
17 |
struct attr mattr;
|
18 |
navit_get_attr(this->object->nav, attr_bookmarks, &mattr, NULL);
|
19 |
bookmarks_move_up(mattr.u.bookmarks);
|
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 |
|
50 |
bookmarks_item_rewind(mattr.u.bookmarks);
|
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(2,"%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 |
|
139 |
bookmarks_item_rewind(mattr.u.bookmarks);
|
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(0,"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 */
|