"add_bookmark",
"remove_bookmark",
"send_message",
+ "extract_dictionary",
+ "return_extracted_dict",
NULL};
guint array_size = 0;
return WS_DBUS_STATUS_ERROR;
};
- osso_rpc_free_val (retval);
+ osso_rpc_free_val (retval);
g_free (retval);
return WS_DBUS_STATUS_OK;
};
if (result != OSSO_OK)
{
g_debug ("Error message: %s\n", retval->value.s);
- osso_rpc_free_val (retval);
+ osso_rpc_free_val (retval);
g_free (retval);
return WS_DBUS_STATUS_ERROR;
};
- osso_rpc_free_val (retval);
+ osso_rpc_free_val (retval);
g_free (retval);
return WS_DBUS_STATUS_OK;
};
return WS_DBUS_STATUS_ERROR;
};
- osso_rpc_free_val (retval);
+ osso_rpc_free_val (retval);
g_free (retval);
return WS_DBUS_STATUS_OK;
};
return WS_DBUS_STATUS_ERROR;
};
- osso_rpc_free_val (retval);
+ osso_rpc_free_val (retval);
g_free (retval);
return WS_DBUS_STATUS_OK;
};
g_free (retval);
return WS_DBUS_STATUS_OK;
};
+
+WSDBusStatus ws_dbus_extract_dictionary(WSDBusData * ws_dbus_data,
+ gchar* path)
+
+{
+ osso_return_t result;
+ osso_rpc_t *retval;
+
+ retval = g_try_malloc (sizeof (osso_rpc_t));
+
+ if (retval == NULL)
+ {
+ g_debug("DBUS: Error in function %s:",__FUNCTION__);
+ g_debug(" Couldn't allocate memory for message's return value\n");
+ };
+
+ result = osso_rpc_run(ws_dbus_data->context,
+ ws_dbus_data->remote_service,
+ ws_dbus_data->remote_object,
+ ws_dbus_data->remote_iface,
+ "extract_dictionary",
+ retval,
+ DBUS_TYPE_STRING,
+ path,
+ DBUS_TYPE_INVALID);
+
+ g_debug ("\nDBUS: %s: ", __FUNCTION__);
+
+ ws_dbus_libosso_errors (result);
+
+ if (result != OSSO_OK)
+ {
+ g_debug ("Error message: %s\n", retval->value.s);
+ osso_rpc_free_val (retval);
+ g_free (retval);
+ return WS_DBUS_STATUS_ERROR;
+ };
+
+ osso_rpc_free_val (retval);
+ g_free (retval);
+ return WS_DBUS_STATUS_OK;
+};
+
+WSDBusStatus ws_dbus_server_return_extracted_dict(WSDBusData* ws_dbus_data,
+ gchar* path)
+{
+ osso_return_t result;
+ osso_rpc_t *retval;
+
+ retval = g_try_malloc (sizeof (osso_rpc_t));
+
+ if (retval == NULL)
+ {
+ g_debug("DBUS: Error in function %s:", __FUNCTION__);
+ g_debug(" Couldn't allocate memory for message's return value\n");
+ };
+
+ result = osso_rpc_run(ws_dbus_data->context,
+ ws_dbus_data->remote_service,
+ ws_dbus_data->remote_object,
+ ws_dbus_data->remote_iface,
+ "return_extracted_dict",
+ retval,
+ DBUS_TYPE_STRING,
+ path,
+ DBUS_TYPE_INVALID);
+
+ g_debug ("\nDBUS: %s: ", __FUNCTION__);
+
+ ws_dbus_libosso_errors (result);
+
+ if (result != OSSO_OK)
+ {
+ g_debug ("Error message: %s\n", retval->value.s);
+ osso_rpc_free_val (retval);
+ g_free (retval);
+ return WS_DBUS_STATUS_ERROR;
+ };
+
+ osso_rpc_free_val (retval);
+ g_free (retval);
+ return WS_DBUS_STATUS_OK;
+};
--- /dev/null
+#ifndef _WS_UNTAR
+#define _WS_UNTAR
+
+#include <glib.h>
+/*
+Usage example:
+
+decompress_file ("comn_dictd04_wn.tar.bz2", "./");
+
+The above example extracts a given archive, to the current directory
+*/
+
+gint decompress_file(gchar *in_file, gchar *out_path);
+
+
+#endif /*_WS_UNTAR*/
CC = gcc
DEBUG = -g -Wall
-INCLUDE = include
+INCLUDE = ./include
INCLUDE_DBUS_WRAPPER = ../../include
-LIBS = `pkg-config --libs glib-2.0 gmodule-2.0 libosso gconf-2.0 ` -lpthread
+LIBS = `pkg-config --libs glib-2.0 gmodule-2.0 libosso gconf-2.0 ` -lpthread -lbz2
SQLITE=-DSQLITE=0
FLAGS = `pkg-config --cflags glib-2.0 gmodule-2.0 libosso gconf-2.0 ` -I${INCLUDE} -I${INCLUDE_DBUS_WRAPPER} ${SQLITE}
SOURCE = src
EXECUTABLE = ${BINARY}/WhiteStorkManager
-all: ${BINARY}/ws_manager.o ${BINARY}/whitestork.o ${MAIN_BINARIES}/ws_dbus.o ${BINARY}/pc-instances.o
+all: ${BINARY}/ws_manager.o ${BINARY}/whitestork.o ${MAIN_BINARIES}/ws_dbus.o ${BINARY}/pc-instances.o ${BINARY}/untar.o
@echo Compiling with ${SQLITE} flag
-
- @${CC} ${DEBUG} ${BINARY}/ws_manager.o ${BINARY}/whitestork.o ${MAIN_BINARIES}/ws_dbus.o ${BINARY}/pc-instances.o -o ${EXECUTABLE} ${LIBS} ${FLAGS}
+ @${CC} ${DEBUG} ${BINARY}/ws_manager.o ${BINARY}/whitestork.o ${MAIN_BINARIES}/ws_dbus.o ${BINARY}/pc-instances.o ${BINARY}/untar.o -o ${EXECUTABLE} ${LIBS} ${FLAGS}
@cp ${EXECUTABLE} ${MAIN_BINARIES}
${BINARY}/pc-instances.o: ${SOURCE}/pc-instances.c
@${CC} ${DEBUG} -c ${SOURCE}/whitestork.c -o ${BINARY}/whitestork.o ${FLAGS}
${BINARY}/ws_manager.o: ${SOURCE}/ws_manager.c
- @echo ${FLAGS}
@${CC} ${DEBUG} -c ${SOURCE}/ws_manager.c -o ${BINARY}/ws_manager.o ${FLAGS}
+${BINARY}/untar.o: ${SOURCE}/untar.c
+ @${CC} ${DEBUG} -c ${SOURCE}/untar.c -o ${BINARY}/untar.o ${FLAGS}
${MAIN_BINARIES}/ws_dbus.o:
@cd ../dbus_wrapper && make
--- /dev/null
+#include <untar.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <bzlib.h>
+#include <sys/stat.h>
+#include <glib-2.0/glib.h>
+
+#define BLOCK_SIZE 512
+#define BUFFER_SIZE BLOCK_SIZE*32
+#define ASCII_NR(NR) (NR + 0x30)
+
+typedef struct _TarHeader
+{
+ gchar name[100];
+ gchar mode[8];
+ gchar uid[8];
+ gchar gid[8];
+ gchar size[12];
+ gchar mtime[12];
+ gchar chksum[8];
+ gchar typeflag;
+ gchar linkname[100];
+ gchar magic[6];
+ gchar version[2];
+ gchar uname[32];
+ gchar gname[32];
+ gchar devmajor[8];
+ gchar devminor[8];
+ gchar prefix[155];
+ gchar padding[12];
+ gchar *gnu_longname;
+ gchar *gnu_longlink;
+} TarHeader;
+
+typedef enum _RecordType
+{
+ File = ASCII_NR (0),
+ ARCHLINK = ASCII_NR (1),
+ SYMLINK = ASCII_NR (2),
+ CHARDEV = ASCII_NR (3),
+ BLOCKDEV = ASCII_NR (4),
+ Dir = ASCII_NR (5),
+ FIFO = ASCII_NR (6),
+ RESERVED = ASCII_NR (7)
+} RecordType;
+
+static gint unpack_file_contents(BZFILE *bz2_file,
+ TarHeader *header,
+ gchar *out_name);
+
+
+static gint unpack_file_contents(BZFILE *bz2_file,
+ TarHeader *header,
+ gchar *out_name)
+{
+ gchar* buffer;
+ guint i;
+ FILE *file_out;
+ gulong length;
+ guint result;
+ gint bzerror;
+
+ file_out = fopen(out_name, "w");
+
+ if (file_out == NULL) return -1;
+
+ sscanf(header->size, "%12lo", &length);
+ printf ("File size: %ld\n", length);
+
+ for (i=0; i < (length / BLOCK_SIZE); ++i)
+ {
+ buffer = (gchar*) g_try_malloc (BLOCK_SIZE * sizeof(gchar));
+
+ result = BZ2_bzRead ( &bzerror, bz2_file, buffer, BLOCK_SIZE *
+ sizeof (gchar));
+
+ fwrite (buffer, BLOCK_SIZE * sizeof(gchar), 1, file_out);
+ g_free (buffer);
+ };
+
+ i = length % BLOCK_SIZE;
+
+ if (i != 0)
+ {
+ buffer = (gchar*) g_try_malloc (BLOCK_SIZE * sizeof(gchar));
+
+ if (buffer == NULL)
+ {
+ printf ("Memory not allocated");
+ return -1;
+ };
+
+ result = BZ2_bzRead(&bzerror, bz2_file, buffer,
+ BLOCK_SIZE * sizeof(gchar));
+
+ if (bzerror == BZ_OK)
+ {
+ fwrite (buffer, i * sizeof(gchar), 1, file_out);
+ }
+
+ else
+ {
+ printf ("bzerror = %d", bzerror);
+ return -1;
+ };
+
+ g_free(buffer);
+
+ };
+
+ fclose(file_out);
+
+ return 0;
+};
+
+gint decompress_file (gchar *in_file, gchar *out_path)
+{
+ FILE *file;
+ BZFILE *bz2_file;
+ guint result;
+ TarHeader* header;
+ gint bzerror;
+
+ header = (TarHeader*) g_try_malloc (BLOCK_SIZE * sizeof(gchar));
+
+ if (header == NULL) printf ("\nCould not allocate memory\n");
+
+ file = fopen (in_file, "rb");
+
+ if (file != NULL)
+
+ {
+ bz2_file = BZ2_bzReadOpen (&bzerror, file, 0, 0, NULL, 0);
+
+ if ( bzerror != BZ_OK )
+ {
+ BZ2_bzReadClose ( &bzerror, bz2_file );
+ printf ("There was an error while reading the compressed file\n");
+ }
+
+ bzerror = BZ_OK;
+ while (1)
+ {
+
+ result = BZ2_bzRead ( &bzerror, bz2_file, header,
+ BLOCK_SIZE * sizeof (char));
+
+// printf ("Jestem\n");
+
+ if ( bzerror == BZ_OK )
+ {
+ if (strlen (header->name) == 0)
+ {
+ printf ("\nFilename length is 0, exitting\n");
+ break;
+ };
+
+ printf ("Name: %s\n", header->name);
+ printf ("Prefix: %s\n", header->prefix);
+
+
+ gchar *temp = g_strconcat (out_path,
+ header->name, NULL);
+
+ switch (header->typeflag)
+ {
+ case File:
+ printf ("File\n");
+ unpack_file_contents (bz2_file,
+ header, temp);
+ break;
+
+ case Dir:
+
+ printf ("Dir %s\n", temp);
+ if (mkdir (temp, S_IRUSR|
+ S_IWUSR|S_IXUSR) != 0)
+ {
+ printf ("Couldn't create directory %s",
+ temp);
+ };
+
+
+ break;
+
+ default:
+ printf ("Only files and dirs can be unpacked");
+ }
+
+ g_free (temp);
+
+ }
+
+ else if ( bzerror != BZ_STREAM_END )
+ {
+ printf ("\nBZ2 READ_CLOSE(stream end) %d\n", bzerror);
+ BZ2_bzReadClose ( &bzerror, bz2_file );
+ break;
+ }
+
+ else
+ {
+ printf ("\nExitting, error nr %d\n", bzerror);
+ BZ2_bzReadClose ( &bzerror, bz2_file );
+ break;
+ };
+
+ };
+
+ }
+ else
+ {
+ printf ("There was an error while trying to read the archive file");
+ return -100;
+ };
+
+ return 100;
+
+ fclose (file);
+};
#include <unistd.h>
#include <glib/gstdio.h>
-//#include <glib.h>
#include <gconf/gconf-client.h>
#include <gconf/gconf.h>
#include <pthread.h>
#include <gmodule.h>
#include <string.h>
-#include "ws_manager.h"
-
+#include <ws_manager.h>
+#include <untar.h>
#define GCONF_KEY "/apps/maemo/WhiteStork/Dictionaries"
#define GCONF_LIB_PATH "/apps/maemo/WhiteStork/Engines"
return NULL;
}
+static void ws_mng_extract_dictionary(GError *error, GArray *word,
+ gpointer user_data);
/**
* Public function, see ws_manager.h
*/
{
g_debug("->%s", __FUNCTION__);
WSMngSearchData *data = (WSMngSearchData *) user_data;
+
+
//decrement returned results count
//data->returned_results--;
data->returned_trans_results--;
+
//if there is returned translation
+ g_printf("\ndla slowa %s\n", pattern);
+ g_printf("ile slownikow %d\n", data->returned_trans_results);
+ g_printf("moje tlmumaczenie %s\n", data->trans);
if (translation != NULL)
{
if (data->trans == NULL)
"<PATTERN_CLOSED><TRANSLATION_OPEN>",
translation,
"<TRANSLATION_CLOSED>",
- NULL);
- }
+ NULL);
+ }
else //if thre was stored trnasloation
{
- if (data->returned_trans_results >= 0)
+ if (data->returned_trans_results > 0)
{
//copy stored trnasloation to temporery variable
gchar* tmp = g_strconcat(data->trans,
{
data->search_in_history = FALSE;
data->is_seraching_trans = FALSE;
- //send translation to gui
- ws_dbus_server_return_translations(data->dbus_data,
+ //send translation to gui
+ ws_dbus_server_return_translations(data->dbus_data,
data->trans);
g_free(data->trans); data->trans = NULL;
}
NULL,
ws_mng_search_word,
data); //create thread and run search
- g_debug("<-%s", __FUNCTION__);
+ g_debug("<-%s", __FUNCTION__);
}
*@param word pattern to serch for translation
*@param user_data data needed to send results to UI
*/
-static void ws_mng_on_search_in_history (GError *error, GArray *word,
+static void ws_mng_on_search_in_history(GError *error, GArray *word,
gpointer user_data)
{
g_debug("->%s", __FUNCTION__);
"remove_bookmark",
ws_mng_remove_bookmark,
data);//set callback for remove bookmarks signal
+ ws_dbus_set_cb(data->dbus_data,
+ "extract_dictionary",
+ ws_mng_extract_dictionary,
+ data);
g_debug("<-%s", __FUNCTION__);
g_debug("<-%s", __FUNCTION__);
}
+static void ws_mng_extract_dictionary(GError *error, GArray* param,
+ gpointer user_data)
+{
+ g_debug("->%s", __FUNCTION__);
+ WSMngSearchData *data = (WSMngSearchData *) user_data;
+ osso_rpc_t *osso_data;
+ //get the data sended by dbus
+ osso_data = &g_array_index (param, osso_rpc_t, 0);
+ //get the path sended by dbus
+ gchar* path = g_strdup(osso_data->value.s);
+ gint result = -1;
+ if (path != NULL)
+ {
+ result = decompress_file(path,"./");
+ }
+ if (result > 0)
+ {
+ ws_dbus_server_return_extracted_dict(data->dbus_data,
+ path);
+ }else
+ {
+ ws_dbus_server_return_extracted_dict(data->dbus_data,
+ NULL);
+ }
+ g_debug("<-%s", __FUNCTION__);
+}
#ifdef __cplusplus
}
#endif