Commit ccf28e1858c7ca734ca652c8350f2de868f576e2
1 parent
11730591
Exists in
master
Gera biblioteca compartilhada integrada com o repositório de atualização de dicionário e software
Showing
11 changed files
with
528 additions
and
32 deletions
Show diff stats
Makefile
| @@ -22,19 +22,26 @@ VERSION = 0.2 | @@ -22,19 +22,26 @@ VERSION = 0.2 | ||
| 22 | 22 | ||
| 23 | CFLAGS =\ | 23 | CFLAGS =\ |
| 24 | -I$(INCDIR)\ | 24 | -I$(INCDIR)\ |
| 25 | - `python-config --cflags` | 25 | + -I/usr/include/python2.7 -I/usr/include/x86_64-linux-gnu/python2.7 -I/usr/local/include\ |
| 26 | + -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector\ | ||
| 27 | + --param=ssp-buffer-size=4 -Wformat -Werror=format-security -DNDEBUG -g -fwrapv -O2 -Wall | ||
| 26 | 28 | ||
| 27 | LDFLAGS =\ | 29 | LDFLAGS =\ |
| 28 | `python-config --ldflags`\ | 30 | `python-config --ldflags`\ |
| 29 | - -lX11 | 31 | + -lX11\ |
| 32 | + -lcurl\ | ||
| 33 | + -llavid_base\ | ||
| 34 | + -llavid_io | ||
| 30 | 35 | ||
| 31 | -HEADERS = \ | 36 | +HEADERS =\ |
| 32 | py_tradutor.h\ | 37 | py_tradutor.h\ |
| 33 | - core_plugin.h | 38 | + core_plugin.h\ |
| 39 | + property.h | ||
| 34 | 40 | ||
| 35 | SOURCES = \ | 41 | SOURCES = \ |
| 36 | $(SRCDIR)/py_tradutor.cpp\ | 42 | $(SRCDIR)/py_tradutor.cpp\ |
| 37 | - $(SRCDIR)/core_plugin.cpp | 43 | + $(SRCDIR)/core_plugin.cpp\ |
| 44 | + $(SRCDIR)/property.cpp | ||
| 38 | 45 | ||
| 39 | .SUFFIXES: .cpp .o .h | 46 | .SUFFIXES: .cpp .o .h |
| 40 | 47 |
Makefile.build
| @@ -6,9 +6,10 @@ all: shared | @@ -6,9 +6,10 @@ all: shared | ||
| 6 | shared: | 6 | shared: |
| 7 | @mkdir $(PLUGINDIR) > /dev/null 2>&1 && \ | 7 | @mkdir $(PLUGINDIR) > /dev/null 2>&1 && \ |
| 8 | echo "Create directory $(PLUGINDIR)... $(OK)" || echo -n "" | 8 | echo "Create directory $(PLUGINDIR)... $(OK)" || echo -n "" |
| 9 | + @echo -n Compiling $(LIB) ... | ||
| 10 | + @$(CXX) -shared -fPIC $(CFLAGS) $(SOURCES) -o $(PLUGINDIR)/$(LIB) $(LDFLAGS) &&\ | ||
| 11 | + echo " $(OK)" || (echo " $(FAILED)"; exit 1;) | ||
| 9 | @echo -n Linking $(LIB) ... | 12 | @echo -n Linking $(LIB) ... |
| 10 | - @$(CXX) -shared -fPIC $(CFLAGS) $(SOURCES) $(LDFLAGS) -o $(PLUGINDIR)/$(LIB) || \ | ||
| 11 | - (echo " $(FAILED)"; exit 1;) | ||
| 12 | @cd $(PLUGINDIR); \ | 13 | @cd $(PLUGINDIR); \ |
| 13 | ln -f -s $(LIB) lib$(LIBNAME).so; \ | 14 | ln -f -s $(LIB) lib$(LIBNAME).so; \ |
| 14 | cd .. && echo " $(OK)" || (echo " $(FAILED)"; exit 1;) | 15 | cd .. && echo " $(OK)" || (echo " $(FAILED)"; exit 1;) |
| @@ -17,3 +18,8 @@ clean: | @@ -17,3 +18,8 @@ clean: | ||
| 17 | @echo -n Cleaning... | 18 | @echo -n Cleaning... |
| 18 | @rm -rf $(addprefix $(SRCDIR),$(OBJS)) $(PLUGINDIR) 2> /dev/null && \ | 19 | @rm -rf $(addprefix $(SRCDIR),$(OBJS)) $(PLUGINDIR) 2> /dev/null && \ |
| 19 | echo " $(OK)" || (echo " $(FAILED)"; exit 1;) | 20 | echo " $(OK)" || (echo " $(FAILED)"; exit 1;) |
| 21 | + | ||
| 22 | +vlibras_test: | ||
| 23 | + @echo -n Compiling source test file... | ||
| 24 | + @$(CXX) $(CFLAGS) $(SOURCES) $(TESTSDIR)/main.cpp $(LDFLAGS) -o $(TESTSDIR)/vlibras_test && \ | ||
| 25 | + echo " $(OK)" || (echo " $(FAILED)"; exit 1;) | ||
| 20 | \ No newline at end of file | 26 | \ No newline at end of file |
Makefile.top
| @@ -0,0 +1 @@ | @@ -0,0 +1 @@ | ||
| 1 | +endpoint_update=http://vlibras.lavid.ufpb.br/api/dicionario/ |
include/core_plugin.h
| @@ -17,17 +17,47 @@ | @@ -17,17 +17,47 @@ | ||
| 17 | #define COREPLUGIN_H_ | 17 | #define COREPLUGIN_H_ |
| 18 | 18 | ||
| 19 | #include <string> | 19 | #include <string> |
| 20 | -#include <stdio.h> | 20 | +#include <sstream> |
| 21 | +#include <stdio.h> | ||
| 22 | +#include <iostream> | ||
| 23 | +#include <stdlib.h> | ||
| 24 | +#include <unistd.h> | ||
| 25 | +#include <sys/types.h> | ||
| 26 | +#include <lavidlib/base/RuntimeException.h> | ||
| 27 | +#include <curl/curl.h> | ||
| 28 | + | ||
| 29 | +// install libjson | ||
| 30 | +// sudo apt-get install libjson0 libjson0-dev | ||
| 31 | + | ||
| 21 | #include "py_tradutor.h" | 32 | #include "py_tradutor.h" |
| 33 | +#include "property.h" | ||
| 34 | + | ||
| 35 | +#define SCRIPT_UPDATE_VLIBRAS "gksudo -m \"<b>Para continuar, você precisa se autenticar.</b>\" \"gnome-terminal --hide-menubar -x bash -c '/./opt/vlibras_desktop/script/update_vlibras.sh;'\"" | ||
| 36 | +#define SCRIPT_UPDATE_DICT "gksudo -m \"<b>Para continuar, você precisa se autenticar.</b>\" \"gnome-terminal --hide-menubar -x bash -c '/./opt/vlibras_desktop/script/update_dict.sh;'\"" | ||
| 37 | +#define SCRIPT_INSTALL_DICT "gksudo -m \"<b>Para continuar, você precisa se autenticar.</b>\" \"gnome-terminal --hide-menubar -x bash -c '/./opt/vlibras_desktop/script/dict_install.sh;'\"" | ||
| 38 | + | ||
| 39 | + | ||
| 40 | +// TODO | ||
| 41 | +#define FILEPATH_CONFIG "config/vlibras.conf" | ||
| 42 | + | ||
| 43 | +// TODO | ||
| 44 | +#define ENDPOINT_UPDATE_ID "endpoint_update" | ||
| 45 | + | ||
| 46 | +// TODO | ||
| 47 | +#define DIC_PACKAGE "dicionario-vlibras" | ||
| 48 | + | ||
| 49 | +// TODO | ||
| 50 | +#define APP_PACKAGE "vlibras-desktop" | ||
| 22 | 51 | ||
| 23 | #define MAX_BUFFER_SELECTION 1024 | 52 | #define MAX_BUFFER_SELECTION 1024 |
| 24 | - #define REPLACE_CHARACTERS "\r\n" | 53 | +#define REPLACE_CHARACTERS "\r\n" |
| 25 | 54 | ||
| 26 | #ifdef __cplusplus | 55 | #ifdef __cplusplus |
| 27 | extern "C" { | 56 | extern "C" { |
| 28 | #endif | 57 | #endif |
| 29 | 58 | ||
| 30 | - PyTradutor *tradutor; | 59 | + //PyTradutor *tradutor; |
| 60 | + //int app_current_version, dict_current_version; | ||
| 31 | 61 | ||
| 32 | /** \brief Inicializa o ambiente core | 62 | /** \brief Inicializa o ambiente core |
| 33 | * | 63 | * |
| @@ -53,8 +83,77 @@ extern "C" { | @@ -53,8 +83,77 @@ extern "C" { | ||
| 53 | */ | 83 | */ |
| 54 | int coreFinalize(); | 84 | int coreFinalize(); |
| 55 | 85 | ||
| 86 | + | ||
| 87 | + /** \brief ? | ||
| 88 | + * | ||
| 89 | + * \return ? | ||
| 90 | + */ | ||
| 91 | + int coreUpdateInstall_player(); | ||
| 92 | + | ||
| 93 | + | ||
| 94 | + /** \brief ? | ||
| 95 | + * | ||
| 96 | + * \return ? | ||
| 97 | + */ | ||
| 98 | + int coreUpdateInstall_dict(); | ||
| 99 | + | ||
| 100 | + | ||
| 101 | + /** \brief ? | ||
| 102 | + * | ||
| 103 | + * \return ? | ||
| 104 | + */ | ||
| 105 | + int coreUpdateCheck(); | ||
| 106 | + | ||
| 107 | + | ||
| 108 | + /** \brief ? | ||
| 109 | + * | ||
| 110 | + * \return ? | ||
| 111 | + */ | ||
| 56 | char * get_text_selection(); | 112 | char * get_text_selection(); |
| 57 | - void remove_special_chars(std::string *_word, std::string _chars); | 113 | + |
| 114 | + | ||
| 115 | + /** \brief ? | ||
| 116 | + * | ||
| 117 | + * \return ? | ||
| 118 | + */ | ||
| 119 | + void remove_special_chars(std::string *_word, std::string _chars, char* new_char); | ||
| 120 | + | ||
| 121 | + | ||
| 122 | + /** \brief ? | ||
| 123 | + * | ||
| 124 | + * \return ? | ||
| 125 | + */ | ||
| 126 | + static size_t writeDataCallback( | ||
| 127 | + char *contents, size_t size, size_t nmemb, std::string *writer_data); | ||
| 128 | + | ||
| 129 | + | ||
| 130 | + /** \brief ? | ||
| 131 | + * | ||
| 132 | + * \return ? | ||
| 133 | + */ | ||
| 134 | + std::string request_current_versions(); | ||
| 135 | + | ||
| 136 | + | ||
| 137 | + /** \brief ? | ||
| 138 | + * | ||
| 139 | + * \return ? | ||
| 140 | + */ | ||
| 141 | + int get_version_from_json(std::string json_message, std::string _key); | ||
| 142 | + | ||
| 143 | + | ||
| 144 | + /** \brief ? | ||
| 145 | + * | ||
| 146 | + * \return ? | ||
| 147 | + */ | ||
| 148 | + int get_installed_version_deb_package(std::string _package_id); | ||
| 149 | + | ||
| 150 | + | ||
| 151 | + /** \brief ? | ||
| 152 | + * | ||
| 153 | + * \return ? | ||
| 154 | + */ | ||
| 155 | + int get_version_from_string(std::string json_message, std::string _key); | ||
| 156 | + | ||
| 58 | 157 | ||
| 59 | #ifdef __cplusplus | 158 | #ifdef __cplusplus |
| 60 | } | 159 | } |
| @@ -0,0 +1,46 @@ | @@ -0,0 +1,46 @@ | ||
| 1 | +/*************************************************************************** | ||
| 2 | + * Universidade Federal da Paraíba * | ||
| 3 | + * Copyright (C) 2013 by Laboratório de Aplicações de Vídeo Digital * | ||
| 4 | + * * | ||
| 5 | + * Centro de Informática - UFPB - Campus I * | ||
| 6 | + * João Pessoa - PB - Brasil * | ||
| 7 | + * * | ||
| 8 | + * Author: Leonardo de Araújo Domingues (leonardo.araujo@lavid.ufpb.br) * | ||
| 9 | + * Date: Qui Nov 28 14:05:39 BRT 2013 * | ||
| 10 | + * * | ||
| 11 | + **************************************************************************/ | ||
| 12 | + | ||
| 13 | + #ifndef PROPERTYHANDLER_H | ||
| 14 | + #define PROPERTYHANDLER_H | ||
| 15 | + | ||
| 16 | + #include <stdio.h> | ||
| 17 | + #include <stdlib.h> | ||
| 18 | + #include <string> | ||
| 19 | + #include <string.h> | ||
| 20 | + #include <lavidlib/io/BufferedReader.h> | ||
| 21 | + #include <lavidlib/io/FileIO.h> | ||
| 22 | + #include <lavidlib/io/IOException.h> | ||
| 23 | + #include <lavidlib/io/EOFException.h> | ||
| 24 | + #include <lavidlib/base/RuntimeException.h> | ||
| 25 | + | ||
| 26 | + using namespace lavidlib; | ||
| 27 | + | ||
| 28 | + namespace util { | ||
| 29 | + | ||
| 30 | + class PropertyHandler { | ||
| 31 | + | ||
| 32 | + public: | ||
| 33 | + PropertyHandler(std::string filename); | ||
| 34 | + virtual ~PropertyHandler(); | ||
| 35 | + std::string getAttributeValue(std::string attr); | ||
| 36 | + | ||
| 37 | + private: | ||
| 38 | + BufferedReader* rbuffer; | ||
| 39 | + FileIO* file_property; | ||
| 40 | + int checkFileExtension(std::string &filename); | ||
| 41 | + | ||
| 42 | + }; | ||
| 43 | + | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + #endif /* PROPERTYHANDLER_H */ | ||
| 0 | \ No newline at end of file | 47 | \ No newline at end of file |
| @@ -0,0 +1,23 @@ | @@ -0,0 +1,23 @@ | ||
| 1 | +#!/bin/bash | ||
| 2 | +# | ||
| 3 | +# | ||
| 4 | +#-------------------- IMPORTANT ------------------------ | ||
| 5 | +# -> To run this script you need to be a sudo user | | ||
| 6 | +#------------------------------------------------------- | ||
| 7 | + | ||
| 8 | +# Update the list of repositories | ||
| 9 | +apt-get update | ||
| 10 | + | ||
| 11 | +if [ $1 == "vlibras-desktop" ]; then | ||
| 12 | + # Install the new version of vlibras-desktop | ||
| 13 | + notify-send -u critical "O VLibras está sendo atualizado! Aguarde..." | ||
| 14 | + #apt-get install --only-upgrade vlibras-desktop | ||
| 15 | +else | ||
| 16 | + if [ $1 == "dicionario-vlibras" ]; then | ||
| 17 | + # Install the new version of dicionario-vlibras | ||
| 18 | + notify-send -u critical "O Dicionário de sinais do VLibras está sendo atualizado..." | ||
| 19 | + #apt-get install --only-upgrade dicionario-vlibras | ||
| 20 | + fi | ||
| 21 | +fi | ||
| 22 | + | ||
| 23 | +/./opt/vlibras_desktop/script/launcher.sh | ||
| 0 | \ No newline at end of file | 24 | \ No newline at end of file |
src/core_plugin.cpp
| @@ -16,7 +16,13 @@ | @@ -16,7 +16,13 @@ | ||
| 16 | #include "core_plugin.h" | 16 | #include "core_plugin.h" |
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | +/* Variables */ | ||
| 19 | 20 | ||
| 21 | +PyTradutor *tradutor; | ||
| 22 | +int app_current_version, dict_current_version; | ||
| 23 | + | ||
| 24 | + | ||
| 25 | +/* Functions */ | ||
| 20 | 26 | ||
| 21 | int coreInitialize() | 27 | int coreInitialize() |
| 22 | { | 28 | { |
| @@ -24,27 +30,227 @@ int coreInitialize() | @@ -24,27 +30,227 @@ int coreInitialize() | ||
| 24 | return 1; | 30 | return 1; |
| 25 | } | 31 | } |
| 26 | 32 | ||
| 33 | + | ||
| 27 | const char* coreExecute() | 34 | const char* coreExecute() |
| 28 | { | 35 | { |
| 29 | return tradutor->convertStringToGlosa((const char*) get_text_selection()); | 36 | return tradutor->convertStringToGlosa((const char*) get_text_selection()); |
| 30 | } | 37 | } |
| 31 | 38 | ||
| 39 | + | ||
| 32 | int coreFinalize() | 40 | int coreFinalize() |
| 33 | { | 41 | { |
| 34 | if (!tradutor) | 42 | if (!tradutor) |
| 35 | return -1; | 43 | return -1; |
| 36 | delete tradutor; | 44 | delete tradutor; |
| 37 | - return 1; | 45 | + return 1; |
| 46 | +} | ||
| 47 | + | ||
| 48 | + | ||
| 49 | +int coreUpdateInstall_player() | ||
| 50 | +{ | ||
| 51 | + system(SCRIPT_UPDATE_VLIBRAS); | ||
| 52 | + return system("/./opt/vlibras_desktop/script/launcher.sh &"); | ||
| 38 | } | 53 | } |
| 54 | + | ||
| 39 | 55 | ||
| 40 | -char * get_text_selection() | 56 | +int coreUpdateInstall_dict() |
| 41 | { | 57 | { |
| 58 | + dict_current_version = get_installed_version_deb_package(DIC_PACKAGE); | ||
| 59 | + if (dict_current_version == 0) | ||
| 60 | + return system(SCRIPT_INSTALL_DICT); | ||
| 61 | + return system(SCRIPT_UPDATE_DICT); | ||
| 62 | +} | ||
| 42 | 63 | ||
| 43 | - FILE *comm_file_p = popen("xsel -o ", "r"); | ||
| 44 | - if (!comm_file_p) | 64 | + |
| 65 | +int coreUpdateCheck() | ||
| 66 | +{ | ||
| 67 | + app_current_version = get_installed_version_deb_package(APP_PACKAGE); | ||
| 68 | + dict_current_version = get_installed_version_deb_package(DIC_PACKAGE); | ||
| 69 | + | ||
| 70 | + std::string response_api_str = request_current_versions().c_str(); | ||
| 71 | + if (response_api_str.compare("null") == 0) | ||
| 72 | + return -1; | ||
| 73 | + | ||
| 74 | + if (get_version_from_string(response_api_str, "playerVersion") > app_current_version) | ||
| 75 | + return 1; | ||
| 76 | + else | ||
| 77 | + if (get_version_from_string(response_api_str, "dictionaryVersion") > dict_current_version) | ||
| 78 | + return 2; | ||
| 79 | + return 0; | ||
| 80 | +} | ||
| 81 | + | ||
| 82 | + | ||
| 83 | +int get_installed_version_deb_package(std::string _package_id) | ||
| 84 | +{ | ||
| 85 | + std::string _deb_package_name = "dpkg -s "; | ||
| 86 | + _deb_package_name.append(_package_id); | ||
| 87 | + | ||
| 88 | + FILE *comm_file_p = popen(_deb_package_name.c_str(), "r"); | ||
| 89 | + | ||
| 90 | + char line_buff [MAX_BUFFER_SELECTION]; | ||
| 91 | + std::string version_str = ""; | ||
| 92 | + bool found_flag = false; | ||
| 93 | + | ||
| 94 | + if (comm_file_p == NULL) perror ("Error opening file"); | ||
| 95 | + else | ||
| 96 | + { | ||
| 97 | + while ( ! feof (comm_file_p) ) | ||
| 98 | + { | ||
| 99 | + if ( fgets (line_buff , (int) sizeof(line_buff) , comm_file_p) == NULL ) break; | ||
| 100 | + | ||
| 101 | + version_str = (std::string) line_buff; | ||
| 102 | + if ( version_str.find("Version:") != std::string::npos ) | ||
| 103 | + { | ||
| 104 | + found_flag = true; | ||
| 105 | + break; | ||
| 106 | + } | ||
| 107 | + } | ||
| 108 | + fclose (comm_file_p); | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + if (!found_flag) return 0; | ||
| 112 | + | ||
| 113 | + char *line_version_ptr = strtok ((char*) version_str.c_str(), " "); | ||
| 114 | + | ||
| 115 | + if (line_version_ptr == NULL) | ||
| 45 | { | 116 | { |
| 46 | - return NULL; | 117 | + printf("Version of the deb package is null!\n"); |
| 118 | + return 0; | ||
| 47 | } | 119 | } |
| 120 | + | ||
| 121 | + line_version_ptr = strtok (NULL, " "); | ||
| 122 | + version_str = (std::string) line_version_ptr; | ||
| 123 | + remove_special_chars(&version_str, ".", (char*) ""); | ||
| 124 | + | ||
| 125 | + printf("%s installed version: %s\n", _package_id.c_str(), version_str.c_str()); | ||
| 126 | + | ||
| 127 | + return atoi(version_str.c_str()); | ||
| 128 | + | ||
| 129 | +} | ||
| 130 | + | ||
| 131 | + | ||
| 132 | + | ||
| 133 | +int get_version_from_string(std::string json_message, std::string _key) | ||
| 134 | +{ | ||
| 135 | + int position = json_message.find(_key); | ||
| 136 | + if (position == -1) | ||
| 137 | + return position; | ||
| 138 | + | ||
| 139 | + std::string version_str_cpy = json_message.substr(position, json_message.find(",")); | ||
| 140 | + | ||
| 141 | + remove_special_chars(&version_str_cpy, ".\":,", (char*) ""); | ||
| 142 | + char *tokens_ptr; | ||
| 143 | + if ( version_str_cpy.find("_") != std::string::npos ) | ||
| 144 | + { | ||
| 145 | + tokens_ptr = strtok ((char*) version_str_cpy.c_str(), "_"); | ||
| 146 | + if (tokens_ptr == NULL) | ||
| 147 | + printf("[Error] Cannot handler the version of dictionary.\n"); | ||
| 148 | + version_str_cpy = (std::string) tokens_ptr; | ||
| 149 | + } | ||
| 150 | + | ||
| 151 | + tokens_ptr = strtok ((char*) version_str_cpy.c_str(), " "); | ||
| 152 | + if (tokens_ptr == NULL) | ||
| 153 | + { | ||
| 154 | + printf("[Error] Cannot split string with versions.\n"); | ||
| 155 | + return -1; | ||
| 156 | + } | ||
| 157 | + tokens_ptr = strtok (NULL, " "); | ||
| 158 | + version_str_cpy = (std::string) tokens_ptr; | ||
| 159 | + | ||
| 160 | + return atoi(version_str_cpy.c_str()); | ||
| 161 | +} | ||
| 162 | + | ||
| 163 | + | ||
| 164 | +//@Deprecated | ||
| 165 | +int get_version_from_json(std::string json_message, std::string _key) | ||
| 166 | +{ | ||
| 167 | + | ||
| 168 | + return -1; | ||
| 169 | + | ||
| 170 | + /*//Code to JsonCpp | ||
| 171 | + Json::Value parsed_from_str; | ||
| 172 | + Json::Reader json_reader; | ||
| 173 | + bool parsing_flag = json_reader.parse(json_message, parsed_from_str); | ||
| 174 | + | ||
| 175 | + if (!parsing_flag) | ||
| 176 | + throw new RuntimeException("Cannot convert the json message to string."); | ||
| 177 | + | ||
| 178 | + std::string version_str = parsed_from_str[_key].asString(); | ||
| 179 | + | ||
| 180 | + // Check if the version of dictionary contains '_' token. | ||
| 181 | + if ( version_str.find("_") != std::string::npos ) | ||
| 182 | + { | ||
| 183 | + char *tokens_ptr = strtok ((char*) version_str.c_str(), "_"); | ||
| 184 | + if (tokens_ptr == NULL) | ||
| 185 | + throw new RuntimeException("Cannot handler the version of dictionary."); | ||
| 186 | + version_str = (std::string) tokens_ptr; | ||
| 187 | + } | ||
| 188 | + | ||
| 189 | + remove_special_chars(&version_str, ".", (char*) ""); | ||
| 190 | + return atoi(version_str.c_str()); | ||
| 191 | + */ | ||
| 192 | +} | ||
| 193 | + | ||
| 194 | + | ||
| 195 | + | ||
| 196 | +std::string request_current_versions() | ||
| 197 | +{ | ||
| 198 | + CURL *curl_ptr; | ||
| 199 | + CURLcode curl_response; | ||
| 200 | + std::string data_str; | ||
| 201 | + | ||
| 202 | + util::PropertyHandler *property_handler_ptr; | ||
| 203 | + property_handler_ptr = new util::PropertyHandler((std::string) FILEPATH_CONFIG); | ||
| 204 | + | ||
| 205 | + curl_ptr = curl_easy_init(); | ||
| 206 | + if(curl_ptr) | ||
| 207 | + { | ||
| 208 | + std::string url_endpoint = property_handler_ptr->getAttributeValue(ENDPOINT_UPDATE_ID); | ||
| 209 | + | ||
| 210 | + std::stringstream ss_convert; | ||
| 211 | + ss_convert << dict_current_version; | ||
| 212 | + url_endpoint.append(ss_convert.str()); | ||
| 213 | + | ||
| 214 | + if (url_endpoint.size() <= 0) | ||
| 215 | + throw new RuntimeException("The URL for this Endpoint is not available on the file config."); | ||
| 216 | + | ||
| 217 | + curl_easy_setopt(curl_ptr, CURLOPT_URL, (char*) url_endpoint.c_str()); | ||
| 218 | + curl_easy_setopt(curl_ptr, CURLOPT_WRITEFUNCTION, writeDataCallback); | ||
| 219 | + curl_easy_setopt(curl_ptr, CURLOPT_WRITEDATA, (char*) &data_str); | ||
| 220 | + | ||
| 221 | + curl_response = curl_easy_perform(curl_ptr); | ||
| 222 | + | ||
| 223 | + if(curl_response != CURLE_OK) | ||
| 224 | + { | ||
| 225 | + fprintf(stderr, "curl_easy_perform() failed: %s\n", | ||
| 226 | + curl_easy_strerror(curl_response)); | ||
| 227 | + return "null"; | ||
| 228 | + } | ||
| 229 | + | ||
| 230 | + /* always cleanup */ | ||
| 231 | + curl_easy_cleanup(curl_ptr); | ||
| 232 | + | ||
| 233 | + } | ||
| 234 | + return data_str; | ||
| 235 | +} | ||
| 236 | + | ||
| 237 | + | ||
| 238 | +static size_t writeDataCallback( | ||
| 239 | + char *contents, size_t size, size_t nmemb, std::string *writer_data) | ||
| 240 | +{ | ||
| 241 | + if (writer_data == NULL) | ||
| 242 | + return 0; | ||
| 243 | + | ||
| 244 | + writer_data->append(contents, (size * nmemb)); | ||
| 245 | + return (size * nmemb); | ||
| 246 | +} | ||
| 247 | + | ||
| 248 | + | ||
| 249 | +char* get_text_selection() | ||
| 250 | +{ | ||
| 251 | + | ||
| 252 | + FILE *comm_file_p = popen("xsel -o ", "r"); | ||
| 253 | + | ||
| 48 | char line_buff [MAX_BUFFER_SELECTION]; | 254 | char line_buff [MAX_BUFFER_SELECTION]; |
| 49 | std::string line_str = ""; | 255 | std::string line_str = ""; |
| 50 | 256 | ||
| @@ -58,20 +264,20 @@ char * get_text_selection() | @@ -58,20 +264,20 @@ char * get_text_selection() | ||
| 58 | } | 264 | } |
| 59 | fclose (comm_file_p); | 265 | fclose (comm_file_p); |
| 60 | } | 266 | } |
| 61 | - remove_special_chars(&line_str, (std::string) REPLACE_CHARACTERS); | 267 | + remove_special_chars(&line_str, (std::string) REPLACE_CHARACTERS, (char*) " "); |
| 62 | 268 | ||
| 63 | return (char*) line_str.c_str(); | 269 | return (char*) line_str.c_str(); |
| 64 | 270 | ||
| 65 | } | 271 | } |
| 66 | 272 | ||
| 67 | -void remove_special_chars(std::string *_word, std::string _chars) | 273 | +void remove_special_chars(std::string *_word, std::string _chars, char* new_char) |
| 68 | { | 274 | { |
| 69 | int index = -1; | 275 | int index = -1; |
| 70 | - for (int i = 0; i < _chars.size(); i++) | 276 | + for (int i = 0; i < (int) _chars.size(); i++) |
| 71 | { | 277 | { |
| 72 | - while ( (index = (int) _word->find(_chars[i])) != std::string::npos) | 278 | + while ( (index = (int) _word->find(_chars[i])) != (int) std::string::npos) |
| 73 | { | 279 | { |
| 74 | - _word->replace(index, 1, " "); // remove chars replacing your position by " " | 280 | + _word->replace(index, 1, new_char); |
| 75 | } | 281 | } |
| 76 | } | 282 | } |
| 77 | } | 283 | } |
| 78 | \ No newline at end of file | 284 | \ No newline at end of file |
| @@ -0,0 +1,80 @@ | @@ -0,0 +1,80 @@ | ||
| 1 | +/*************************************************************************** | ||
| 2 | + * Universidade Federal da Paraíba * | ||
| 3 | + * Copyright (C) 2013 by Laboratório de Aplicações de Vídeo Digital * | ||
| 4 | + * * | ||
| 5 | + * Centro de Informática - UFPB - Campus I * | ||
| 6 | + * João Pessoa - PB - Brasil * | ||
| 7 | + * * | ||
| 8 | + * Author: Leonardo de Araújo Domingues (leonardo.araujo@lavid.ufpb.br) * | ||
| 9 | + * Date: Qui Nov 28 14:06:10 BRT 2013 * | ||
| 10 | + * * | ||
| 11 | + **************************************************************************/ | ||
| 12 | + | ||
| 13 | + #include "property.h" | ||
| 14 | + | ||
| 15 | + | ||
| 16 | + namespace util { | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + PropertyHandler::PropertyHandler(std::string filename) { | ||
| 20 | + try { | ||
| 21 | + if (checkFileExtension(filename) != 1) | ||
| 22 | + throw new RuntimeException("Format file not is recognized!"); | ||
| 23 | + file_property = new FileIO(filename, FileIO::MODE_READ); | ||
| 24 | + } catch (lavidlib::IOException &ex) { | ||
| 25 | + printf("[FAILED] Cannot open file %s.\n%s\n", filename.c_str(), | ||
| 26 | + ex.getMessage().c_str()); | ||
| 27 | + } | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + | ||
| 31 | + PropertyHandler::~PropertyHandler() { | ||
| 32 | + if (rbuffer) | ||
| 33 | + delete rbuffer; | ||
| 34 | + if (file_property) | ||
| 35 | + delete file_property; | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + | ||
| 39 | + std::string PropertyHandler::getAttributeValue(std::string attr) { | ||
| 40 | + | ||
| 41 | + rbuffer = new BufferedReader(file_property); | ||
| 42 | + std::string fline; | ||
| 43 | + try { | ||
| 44 | + int target_pos = -1, begin = 0; | ||
| 45 | + std::string attr_t, value_t; | ||
| 46 | + | ||
| 47 | + while((fline = rbuffer->readLine()).size() > 0) { | ||
| 48 | + target_pos = fline.find("="); | ||
| 49 | + if (target_pos < 2) | ||
| 50 | + throw new RuntimeException("The assignment symbol was not found."); | ||
| 51 | + | ||
| 52 | + attr_t = fline.substr(begin, target_pos); | ||
| 53 | + begin = target_pos+1; | ||
| 54 | + value_t = fline.substr(begin, fline.size()); | ||
| 55 | + if (attr.compare(attr_t) == 0) { | ||
| 56 | + file_property->seek(0); | ||
| 57 | + return value_t; | ||
| 58 | + } | ||
| 59 | + target_pos = -1; | ||
| 60 | + begin = 0; | ||
| 61 | + } | ||
| 62 | + } catch (lavidlib::EOFException &ex) { | ||
| 63 | + printf("[INFO] File is completed.\n%s\n", ex.getMessage().c_str()); | ||
| 64 | + } | ||
| 65 | + file_property->seek(0); | ||
| 66 | + //FIXME: throw new exception | ||
| 67 | + return fline; | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + #define EXTENSION ".conf" | ||
| 71 | + | ||
| 72 | + int PropertyHandler::checkFileExtension(std::string &filename) { | ||
| 73 | + | ||
| 74 | + return (filename.find(EXTENSION) > 0 && | ||
| 75 | + (filename.size() == (filename.find(EXTENSION) + strlen(EXTENSION)))) ? 1 : -1; | ||
| 76 | + | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + | ||
| 80 | + } | ||
| 0 | \ No newline at end of file | 81 | \ No newline at end of file |
test/main.cpp
| @@ -13,8 +13,7 @@ | @@ -13,8 +13,7 @@ | ||
| 13 | * \date Janeiro 2015 | 13 | * \date Janeiro 2015 |
| 14 | */ | 14 | */ |
| 15 | 15 | ||
| 16 | -#include <py_tradutor.h> | ||
| 17 | -//#include <core_plugin.h> | 16 | +#include <core_plugin.h> |
| 18 | 17 | ||
| 19 | #include <iostream> | 18 | #include <iostream> |
| 20 | #include <fstream> | 19 | #include <fstream> |
| @@ -22,21 +21,46 @@ | @@ -22,21 +21,46 @@ | ||
| 22 | 21 | ||
| 23 | int main() | 22 | int main() |
| 24 | { | 23 | { |
| 24 | + | ||
| 25 | + if (coreInitialize() != 1) | ||
| 26 | + { | ||
| 27 | + printf("Cannot initialize the CorePlugin.\n"); | ||
| 28 | + exit(-1); | ||
| 29 | + } | ||
| 25 | 30 | ||
| 31 | + int result_check = coreUpdateCheck(); | ||
| 32 | + switch (result_check) | ||
| 33 | + { | ||
| 34 | + case 0: | ||
| 35 | + printf("The VLibras is up-to-date!\n"); | ||
| 36 | + break; | ||
| 37 | + case 1: | ||
| 38 | + printf("The VLibras is outdated! Upgrading...\n"); | ||
| 39 | + break; | ||
| 40 | + case 2: | ||
| 41 | + printf("Only the dictionary is outdated! Upgrading...\n"); | ||
| 42 | + break; | ||
| 43 | + case -1: | ||
| 44 | + printf("Error!\n"); | ||
| 45 | + break; | ||
| 46 | + default: | ||
| 47 | + printf("Option not found! Try again.\n"); | ||
| 48 | + } | ||
| 49 | + | ||
| 26 | // Inicializa o tradutor | 50 | // Inicializa o tradutor |
| 27 | - PyTradutor *tradutorTest; | ||
| 28 | - tradutorTest = new PyTradutor(); | 51 | + //PyTradutor *tradutorTest; |
| 52 | + //tradutorTest = new PyTradutor(); | ||
| 29 | 53 | ||
| 30 | // Pega o conteúdo do clipboard e salva em `pasteboardContent` | 54 | // Pega o conteúdo do clipboard e salva em `pasteboardContent` |
| 31 | //std::string pasteboardContent = Pasteboard::getGeneralContent(); | 55 | //std::string pasteboardContent = Pasteboard::getGeneralContent(); |
| 32 | // Traduz o conteúdo do clipboard em `pasteboardContent` para a string `traducao` | 56 | // Traduz o conteúdo do clipboard em `pasteboardContent` para a string `traducao` |
| 33 | - char* str = new char[10]; | ||
| 34 | - strcpy(str, "o gato comeu o rato"); | ||
| 35 | - std::string traducao = tradutorTest->convertStringToGlosa(str); | 57 | + //char* str = new char[10]; |
| 58 | + //strcpy(str, "o gato comeu o rato"); | ||
| 59 | + //std::string traducao = tradutorTest->convertStringToGlosa(str); | ||
| 36 | 60 | ||
| 37 | // [LOG] Exibe o conteudo do buffer de clipboard em `pasteboardContent` e traduz para glosa salvando seu resultado em `traducao` | 61 | // [LOG] Exibe o conteudo do buffer de clipboard em `pasteboardContent` e traduz para glosa salvando seu resultado em `traducao` |
| 38 | - std::cout << "[[ Conteudo em memoria ]]\n" << str << std::endl; | ||
| 39 | - std::cout << "[[ Tradução ]]\n" << traducao << std::endl; | 62 | + //std::cout << "[[ Conteudo em memoria ]]\n" << str << std::endl; |
| 63 | + //std::cout << "[[ Tradução ]]\n" << traducao << std::endl; | ||
| 40 | 64 | ||
| 41 | //std::cout << "\n##### ##### #####" << std::endl; | 65 | //std::cout << "\n##### ##### #####" << std::endl; |
| 42 | 66 | ||
| @@ -49,5 +73,6 @@ int main() | @@ -49,5 +73,6 @@ int main() | ||
| 49 | 73 | ||
| 50 | // Exclui o que foi utilizado | 74 | // Exclui o que foi utilizado |
| 51 | // delete tradutorTest; | 75 | // delete tradutorTest; |
| 76 | + | ||
| 52 | return 0; | 77 | return 0; |
| 53 | -} | 78 | -} |
| 79 | +} | ||
| 54 | \ No newline at end of file | 80 | \ No newline at end of file |