/* * libqrae - Biblioteca para consultar el diccionario castellano de la RAE * * Copyright (C) 2013-2015 Javier Llorente * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) version 3. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #include "libqrae.h" #include #if QT_VERSION >= 0x050000 #include #endif DRAE::DRAE() { } QUrl DRAE::consultar(QString termino) { QUrl url("http://lema.rae.es/drae/srv/search"); QString draeQuery = "val"; if (!termino.isEmpty()) { QByteArray valBA; QByteArray terBA; // codificación de caracteres termino.replace(QString::fromUtf8("á"), "%E1"); termino.replace(QString::fromUtf8("é"), "%E9"); termino.replace(QString::fromUtf8("í"), "%ED"); termino.replace(QString::fromUtf8("ó"), "%F3"); termino.replace(QString::fromUtf8("ú"), "%FA"); termino.replace(QString::fromUtf8("ñ"), "%F1"); termino.replace(QString::fromUtf8("ü"), "%FC"); termino.replace(QString::fromUtf8("Á"), "%C1"); termino.replace(QString::fromUtf8("É"), "%C9"); termino.replace(QString::fromUtf8("Í"), "%CD"); termino.replace(QString::fromUtf8("Ó"), "%D3"); termino.replace(QString::fromUtf8("Ú"), "%DA"); termino.replace(QString::fromUtf8("Ñ"), "%D1"); termino.replace(QString::fromUtf8("Ü"), "%DC"); valBA.append(draeQuery); terBA.append(termino); #if QT_VERSION >= 0x050000 QUrlQuery urlQuery; urlQuery.addQueryItem(valBA, terBA); url.setQuery(urlQuery); #else url.addEncodedQueryItem(valBA, terBA); #endif } return url; } QString DRAE::getErrorMsg() { QString errorMsg( "" "" "Error" "" "" "" "

Error: No se ha podido cargar la página

" "Por favor, comprueba que tu ordenador esté conectado a Internet." "
" "En caso afirmativo, inténtalo de nuevo." "" "" ); return errorMsg; }