static DBusHandlerResult request_navit_add_message(DBusConnection *connection, DBusMessage *message) { struct navit *navit; char *usermessage; DBusMessageIter iter; navit=object_get_from_message(message, "navit"); if (! navit) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; dbus_message_iter_init(message, &iter); dbus_message_iter_get_basic(&iter, &usermessage); navit_add_message(navit, usermessage); return empty_reply(connection, message); }
static int bookmarks_store_bookmarks_to_file(struct bookmarks *this_, int limit,int replace) { FILE *f; struct bookmark_item_priv *item,*parent_item; char *fullname; const char *prostr; int result; GHashTable *dedup=g_hash_table_new_full(g_str_hash,g_str_equal,g_free_func,NULL); f=fopen(this_->working_file, replace ? "w+" : "a+"); if (f==NULL) { navit_add_message(this_->parent->u.navit,"Failed to write bookmarks file"); return FALSE; } this_->bookmarks_list=g_list_first(this_->bookmarks_list); while (this_->bookmarks_list) { item=(struct bookmark_item_priv*)this_->bookmarks_list->data; parent_item=item; fullname=g_strdup(item->label); while ((parent_item=parent_item->parent)) { char *pathHelper; if (parent_item->label) { pathHelper=g_strconcat(parent_item->label,"/",fullname,NULL); g_free(fullname); fullname=g_strdup(pathHelper); g_free(pathHelper); dbg(1,"full name: %s\n",fullname); } } if (!g_hash_table_lookup(dedup,fullname)) { g_hash_table_insert(dedup,fullname,fullname); if (item->type == type_bookmark) { prostr = projection_to_name(projection_mg,NULL); if (fprintf(f,"%s%s%s0x%x %s0x%x type=%s label=\"%s\" path=\"%s\"\n", prostr, *prostr ? ":" : "", item->c.x >= 0 ? "":"-", item->c.x >= 0 ? item->c.x : -item->c.x, item->c.y >= 0 ? "":"-", item->c.y >= 0 ? item->c.y : -item->c.y, "bookmark", item->label,fullname)<1) { g_free(fullname); break; } } if (item->type == type_bookmark_folder) { prostr = projection_to_name(projection_mg,NULL); if (fprintf(f,"%s%s%s0x%x %s0x%x type=%s label=\"%s\" path=\"%s\"\n", prostr, *prostr ? ":" : "", "", 0, "", 0, "bookmark_folder", item->label,fullname)<1) { g_free(fullname); break; } } } /* Limit could be zero, so we start decrementing it from zero and never reach 1 or it was bigger and we decreased it earlier. So when this counter becomes 1, we know that we have enough entries in bookmarks file */ if (limit==1) { break; } limit--; this_->bookmarks_list=g_list_next(this_->bookmarks_list); } fclose(f); g_hash_table_destroy(dedup); if (this_->mr) { map_rect_destroy(this_->mr); this_->mr = 0; } unlink(this_->bookmark_file); result=(rename(this_->working_file,this_->bookmark_file)==0); if (!result) { navit_add_message(this_->parent->u.navit,"Failed to write bookmarks file"); } return result; }