Navit SVN

/work/compile/navit/src/navit/gui/qml/bookmarksProxy.h

00001 #ifndef NAVIT_GUI_QML_BOOKMARKSPROXY_H
00002 #define NAVIT_GUI_QML_BOOKMARKSPROXY_H
00003 
00004 class NGQProxyBookmarks : public NGQProxy {
00005     Q_OBJECT;
00006 
00007 public:
00008         NGQProxyBookmarks(struct gui_priv* object, QObject* parent) : NGQProxy(object,parent) { };
00009 
00010 public slots:
00011         void moveRoot() {
00012                 struct attr mattr;
00013                 navit_get_attr(this->object->nav, attr_bookmarks, &mattr, NULL);
00014                 bookmarks_move_root(mattr.u.bookmarks);
00015         }
00016         void moveUp() {
00017                 struct attr mattr;
00018                 navit_get_attr(this->object->nav, attr_bookmarks, &mattr, NULL);
00019                 bookmarks_move_up(mattr.u.bookmarks);
00020         }
00021         void moveDown(QString path) {
00022                 struct attr mattr;
00023                 navit_get_attr(this->object->nav, attr_bookmarks, &mattr, NULL);
00024                 bookmarks_move_down(mattr.u.bookmarks,path.toLocal8Bit().constData());
00025         }
00026 
00027         QString getBookmarks() {
00028                 struct attr attr,mattr;
00029                 struct item* item;
00030                 struct coord c;
00031                 QDomDocument retDoc("bookmarks");
00032                 QDomElement entries;
00033 
00034                 entries=retDoc.createElement("bookmarks");
00035                 retDoc.appendChild(entries);
00036 
00037                 navit_get_attr(this->object->nav, attr_bookmarks, &mattr, NULL);
00038 
00039         if (bookmarks_item_cwd(mattr.u.bookmarks)) {
00040                         QDomElement entry=retDoc.createElement("bookmark");
00041                         entry.appendChild(this->_fieldValueHelper(retDoc,"label",".."));
00042                         entry.appendChild(this->_fieldValueHelper(retDoc,"path",".."));
00043                         entry.appendChild(this->_fieldValueHelper(retDoc,"type",QString(item_to_name(type_bookmark_folder))));
00044                         entry.appendChild(this->_fieldValueHelper(retDoc,"distance",""));
00045                         entry.appendChild(this->_fieldValueHelper(retDoc,"direction",""));
00046                         entry.appendChild(this->_fieldValueHelper(retDoc,"coords",QString("%1 %2").arg(0).arg(0)));
00047                         entries.appendChild(entry);
00048                 }
00049 
00050                 bookmarks_item_rewind(mattr.u.bookmarks);
00051                 while ((item=bookmarks_get_item(mattr.u.bookmarks))) {
00052                         QString label;
00053                         QString path;
00054                         
00055                         if (item->type != type_bookmark && item->type != type_bookmark_folder) continue;
00056                         if (!item_attr_get(item, attr_label, &attr)) continue;
00057                         label=QString::fromLocal8Bit(attr.u.str);
00058                         if (!item_attr_get(item, attr_path, &attr)) {
00059                                 path="";
00060                         }
00061                         path=QString::fromLocal8Bit(attr.u.str);
00062                         item_coord_get(item, &c, 1);
00063                         QDomElement entry=retDoc.createElement("bookmark");
00064                         entry.appendChild(this->_fieldValueHelper(retDoc,"label",label));
00065                         entry.appendChild(this->_fieldValueHelper(retDoc,"path",path));
00066                         entry.appendChild(this->_fieldValueHelper(retDoc,"type",QString(item_to_name(item->type))));
00067                         //entry.appendChild(this->_fieldValueHelper(retDoc,"distance",QString::number(idist/1000)));
00068                         entry.appendChild(this->_fieldValueHelper(retDoc,"distance","100500"));
00069                         //entry.appendChild(this->_fieldValueHelper(retDoc,"direction",dirbuf));
00070                         entry.appendChild(this->_fieldValueHelper(retDoc,"direction","nahut"));
00071                         entry.appendChild(this->_fieldValueHelper(retDoc,"coords",QString("%1 %2").arg(c.x).arg(c.y)));
00072                         entries.appendChild(entry);
00073                 }
00074 
00075                 dbg(2,"%s\n",retDoc.toString().toLocal8Bit().constData());
00076                 return retDoc.toString();
00077         }
00078         QString AddFolder(QString description) {
00079                 struct attr attr;
00080                 navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL);
00081                 if (!bookmarks_add_bookmark(attr.u.bookmarks, NULL, description.toLocal8Bit().constData()) ) {
00082                         return "Failed!";
00083                 } else {
00084                         return "Success";
00085                 }
00086         }
00087         QString AddBookmark(QString description) {
00088                 struct attr attr;
00089                 navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL);
00090                 if (!bookmarks_add_bookmark(attr.u.bookmarks, this->object->currentPoint->pc(), description.toLocal8Bit().constData()) ) {
00091                         return "Failed!";
00092                 } else {
00093                         return "Success";
00094                 }
00095         }
00096         QString Cut(QString description) {
00097                 struct attr attr;
00098                 navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL);
00099                 if (!bookmarks_cut_bookmark(attr.u.bookmarks, description.toLocal8Bit().constData()) ) {
00100                         return "Failed!";
00101                 } else {
00102                         return "Success";
00103                 }
00104         }
00105         QString Copy(QString description) {
00106                 struct attr attr;
00107                 navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL);
00108                 if (!bookmarks_copy_bookmark(attr.u.bookmarks, description.toLocal8Bit().constData()) ) {
00109                         return "Failed!";
00110                 } else {
00111                         return "Success";
00112                 }
00113         }
00114         QString Paste() {
00115                 struct attr attr;
00116                 navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL);
00117                 if (!bookmarks_paste_bookmark(attr.u.bookmarks) ) {
00118                         return "Failed!";
00119                 } else {
00120                         return "Success";
00121                 }
00122         }
00123         QString Delete(QString bookmark) {
00124                 struct attr attr;
00125                 navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL);
00126                 if (!bookmarks_delete_bookmark(attr.u.bookmarks, bookmark.toLocal8Bit().constData()) ) {
00127                         return "Failed!";
00128                 } else {
00129                         return "Success";
00130                 }
00131         }
00132         void setPoint(QString bookmark) {
00133                 struct attr attr, mattr;
00134                 struct item* item;
00135                 struct coord c;
00136 
00137                 navit_get_attr(this->object->nav, attr_bookmarks, &mattr, NULL);
00138 
00139                 bookmarks_item_rewind(mattr.u.bookmarks);
00140                 while ((item=bookmarks_get_item(mattr.u.bookmarks))) {
00141                         QString label;
00142 
00143                         if (item->type != type_bookmark) continue;
00144                         if (!item_attr_get(item, attr_label, &attr)) continue;
00145 
00146                         label=QString::fromLocal8Bit(attr.u.str);
00147                         dbg(0,"Bookmark is %s\n",bookmark.toStdString().c_str());
00148                         if (label.compare(bookmark)) continue;
00149                         item_coord_get(item, &c, 1);
00150                         if (this->object->currentPoint!=NULL) {
00151                                 delete this->object->currentPoint;
00152                         }
00153                         this->object->currentPoint=new NGQPoint(this->object,&c,bookmark,Bookmark,NULL);
00154                         this->object->guiWidget->rootContext()->setContextProperty("point",this->object->currentPoint);
00155                 }
00156 
00157                 return;
00158         }
00159 
00160 protected:
00161         int getAttrFunc(enum attr_type type, struct attr* attr, struct attr_iter* iter) { return 0; }
00162         int setAttrFunc(struct attr* attr) {return 0; }
00163         struct attr_iter* getIterFunc() { return NULL; };
00164         void dropIterFunc(struct attr_iter* iter) { return; };
00165 
00166 private:
00167 };
00168 
00169 #include "bookmarksProxy.moc"
00170 
00171 #endif /* NAVIT_GUI_QML_BOOKMARKSPROXY_H */