/***************************************************************************
                          stardict.cpp  -  description

                             -------------------
    begin                : 27. November 2009
    copyright            : (c) 2007 by Iven Wold - 526f6c616e642053756368616e
    email                : hour.glass2@yahoo.com
    license              : GPL v 2.0
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This file is part of QTrans.                                          *
 *                                                                         *
 *   QTrans 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; version 2 of the License.               *
 *                                                                         *
 *   QTrans 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 QTrans. If not, see <http://www.gnu.org/licenses/> or      *
 *   write to the Free Software Foundation, Inc.,                          *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.         *
 *                                                                         *
 ***************************************************************************/

#include <QMessageBox>
//#include <KLocale>    //oooo
#include <KLocalizedString> //xxxx
#include <QDebug>		//ooo
#include <QByteArray>
#include <QIODevice>		//ooo
#include <QStack>		//ooo
#include <QTextDocument>	//ooo
#include <QTextCursor>		//ooo

#include <zlib.h>

#include <iostream>		//ooo
#include <stdio.h>		//ooo
#include <stdlib.h>		//ooo
#include <assert.h>		//ooo

#include "stardict.h"

#define CHUNK 0xffffL

#define GZ_XLEN         10

#define DICT_UNKNOWN    0
#define DICT_TEXT       1
#define DICT_GZIP       2
#define DICT_DZIP       3


StarDict::StarDict(const QString &filename, bool wholeStarDict, bool wholeWordsOnly, bool wordStartsWith)
{
	
	b_wholeStarDict = wholeStarDict;
	b_wholeWordsOnly = wholeWordsOnly;
	b_wordStartsWith = wordStartsWith;
	//p_filename = filename.toAscii().data();  //oooo
    p_filename = filename.toLatin1().data();    //xxxx

	ifoFile = new QFile(filename);

	if (!ifoFile->open(QIODevice::ReadOnly)) {
		//return text = "error *.ifo";
	}

	QString ifoline;

	while( !ifoFile->atEnd() ) {
		//ifoFile->readLine( ifoline, 1024 );
		ifoline = ifoFile->readLine();

		//if( ifoline.find( "=" ) == -1 ) continue;
		//ifoline.remove( "\n" );
		if( ifoline.section( "=", 0, 0 ) == "version" ) m_version = ifoline.section( "=", 1 );
		if( ifoline.section( "=", 0, 0 ) == "bookname" ) m_bookname = ifoline.section( "=", 1 );
		if( ifoline.section( "=", 0, 0 ) == "sametypesequence" ) m_sametypesequence = ifoline.section( "=", 1 );
		if( ifoline.section( "=", 0, 0 ) == "idxfilesize" ) m_idxfilesize = ifoline.section( "=", 1 ).toULong();
		if( ifoline.section( "=", 0, 0 ) == "wordcount" ) m_wordcount = ifoline.section( "=", 1 ).toUInt();
		if( ifoline.section( "=", 0, 0 ) == "author" ) m_author = ifoline.section( "=", 1 );
		if( ifoline.section( "=", 0, 0 ) == "email" ) m_email = ifoline.section( "=", 1 );
		if( ifoline.section( "=", 0, 0 ) == "website" ) m_website = ifoline.section( "=", 1 );
		if( ifoline.section( "=", 0, 0 ) == "description" ) m_description = ifoline.section( "=", 1 );
		if( ifoline.section( "=", 0, 0 ) == "date" ) m_date = ifoline.section( "=", 1 );
	}

	ifoFile->close();

	QString file_holder_str = filename;

	file_holder_str.replace( ".ifo", ".idx" );

	if( !QFile::exists( file_holder_str ) ) {
		//m_isOk = false;
		return;
	}

	idxFile = new QFile( file_holder_str );

	file_holder_str.replace( ".idx", ".dict" );

	if( QFile::exists( file_holder_str ) ) {
		dictFile = new QFile( file_holder_str );
		isCompressed = false;
	} else {
		if( !QFile::exists( file_holder_str + ".dz" ) ) {
			//m_isOk = false;
			return;
		}
	
		// The definition file is compressed (.dict.dz)
		// Read the header
		dictFile = new QFile( file_holder_str + ".dz" );
		isCompressed = true;

		if (!dictFile->open(QIODevice::ReadOnly )) {
			//return text = "error *.dict.dz";
		}
		
		this->headerLength = GZ_XLEN - 1;	//ooo

		//ID1 = 31 (0x1f, \037)
		dictFile->getChar(&c);

		if ( c != 0x1f ) {		//ooo
			//m_isOk = false;
			return;
		}
		
		//ID2 = 139 (0x8b, \213)
		dictFile->getChar(&c);
		
		if ( (unsigned char)c != 0x8b ) {	
			return;
		}

		// COMPRESSION
		dictFile->getChar(&c);
		CM = /*(unsigned char)*/c;

		if ( c == 0x08 ) {
			
		}

		// FLAGS		// 0x0c
		dictFile->getChar(&c);
		FLAGS = (unsigned char)c;

		FTEXT    = FLAGS & 1;		// bit 0
		FHCRC    = FLAGS & 2;		// bit 1
		FEXTRA   = FLAGS & 4;		// bit 2	ooo
		FNAME    = FLAGS & 8;		// bit 3
		FCOMMENT = FLAGS & 16;		// bit 4

		dictFile->getChar(&c);
		MTIME  = (unsigned char)c << 0;
		dictFile->getChar(&c);
		MTIME |= (unsigned char)c << 8;
		dictFile->getChar(&c);
		MTIME |= (unsigned char)c << 16;
		dictFile->getChar(&c);
		MTIME |= (unsigned char)c << 24;
		
		// Compression type
		// specific compression method		//ooo
		dictFile->getChar(&c);
		
		if ( c == 0x02 ) {
			//return;
		}
		
		// Operating System
		dictFile->getChar(&c);

		if ( FEXTRA ) {			//ooo
			
			dictFile->getChar(&c);
			XLEN = (unsigned char)c << 0;
			dictFile->getChar(&c);
			XLEN |= (unsigned char)c << 8;
			
			this->headerLength += XLEN + 2;		//ooo

			readExtraField();
		}

		if( FNAME ) {
			readFileName();
			
			this->origFilename = buffer;					//ooo
			this->headerLength += this->origFilename.length() + 1;		//ooo
		}

		if( FCOMMENT ) {
			readFileName();
			
			comment = buffer;			//ooo
			headerLength += comment.length()+1;	//ooo
		}

		if( FHCRC ) {
			
			dictFile->getChar(&c);
			*crc16[0] = (unsigned char)c;
			dictFile->getChar(&c);
			*crc16[1] = (unsigned char)c;
			
			this->headerLength += 2;	//ooo
		}

		offset = dictFile->pos();
		//offsetAdditional = offset;	//ooo
		
		offsetAdditional = this->headerLength + 1;	//ooo
		
		for ( int i = 0; i < this->CHCNT; i++) {

			offsetsWithHeader.append(offsetAdditional);	//ooo
			offsetAdditional += offsets[i];			//ooo
		}
		
		dictFile->close();
	}
}


StarDict::~StarDict()
{

	delete ifoFile;
	delete idxFile;
	delete dictFile;

}


void StarDict::readExtraField()
{
	//kdDebug() << "readExtraField()" << endl;
	offsets.clear();

	dictFile->getChar(&c);
	SI1 = /*(unsigned char)*/c;

	dictFile->getChar(&c);
	SI2 = /*(unsigned char)*/c;
		
	// length of the subfield data
	// length of the subfield data, excluding the 4 initial bytes		//ooo

	if ( SI1 == 'R' || SI2 == 'A' ) {
	  
		dictFile->getChar(&c);
		LEN = (unsigned char)c << 0;
		dictFile->getChar(&c);
		LEN |= (unsigned char)c << 8;
	}

	//int size = (int)LEN - 6;
	int size = (int)LEN + 4;	//ooo
	
	// Version
	dictFile->getChar(&c);
	VER = (unsigned char)c << 0;
	dictFile->getChar(&c);
	VER |= (unsigned char)c << 8;
	
	// length of a "chunk" of data
	dictFile->getChar(&c);
	CHLEN = (unsigned char)c << 0;
	dictFile->getChar(&c);
	CHLEN |= (unsigned char)c << 8;
	
	// how many chunks are preset
	dictFile->getChar(&c);
	CHCNT = (unsigned char)c << 0;
	dictFile->getChar(&c);
	CHCNT |= (unsigned char)c << 8;

	unsigned long data;
	//uint data;	//ooo

	for(int a = 0; a < CHCNT; a++) {		//ooo

		// how long is each chunk after compression

		dictFile->getChar(&c);
		data  = (unsigned char)c << 0;
		dictFile->getChar(&c);
		data |= (unsigned char)c << 8;
		
		offsets.append( data );
	}
	
	this->type = DICT_DZIP;		//ooo
	
}


void StarDict::readFileName()
{

	QString filename_str;
	//char byte;
	//char *byte;	//ooo
	
	//byte = dictFile->getChar(c);

	/*if ( dictFile->getChar(&c) ) {
		//byte = c;
		*byte = c;
	}*/
	
	byte = buffer;		//ooo

	//while( byte != '\0' ) {
	while( dictFile->getChar(&c) && c != EOF ) {		//ooo
		//filename_str += byte;
		*byte++ = c;			//ooo
		//byte = dictFile->getChar(c);

		/*if ( dictFile->getChar(&c) ) {
			byte = c;
		}*/

	}
	
	*byte = '\0';	//ooo

	//m_filename = filename_str;
	m_filename = buffer;	//ooo
	
}


QString StarDict::search( const QString &word )
{

	struct entry entry;
	//struct entries entries;			//ooo

	QByteArray line;
	line.resize(256);
	line.clear();				//ooo
	QString headword;
	headword.clear();			//ooo
	headwords.clear();			//ooo
	positions.clear();			//ooo
	sizes.clear();				//ooo
	bool found = false;
	//bool goThroughWholeDic = true;	//ooo
	uint p = 0;				//ooo
	bool foundWholeWord = false;		//ooo
	

	if (!idxFile->open(QIODevice::ReadOnly )) {

	}

	QString text;		//ooo
	text.clear();		//ooo

	// Find the headword in index file
	uint a;

	//idxFile->seek(4);

	while( !idxFile->atEnd() ) {

		a = 0;
		bool finished = false;	//ooo

		do {

			idxFile->getChar(&c);
			line[a] = (unsigned char)c;

			a++;

		} while ( line[a-1] != '\0' );

		headword = QString::fromUtf8(line.data());

		for( a = 0; a < 8; a++ ) {

			idxFile->getChar(&c);
			line[a] = (unsigned char)c;

		}
		
		/*QString word2;
		word2 = "<p i=01>" + word;
		
		int pos = 0;
		int p = 0;
		bool wordFound = false;
		
		QRegExp rx( "<(p|p\\si=\\d*)>('?-?\\w*-?'?\\w*|\\W*)" );
		
		if ( (pos = rx.indexIn(headword, pos)) != -1 ) {	//ooo
			
			if ( QString::compare( rx.cap(2), word, Qt::CaseInsensitive) == 0 ) {
		  
				wordFound = true;
				
			}
		}*/

		int indexOfWord = headword.indexOf(word, 1, Qt::CaseInsensitive);

		//if( QString::compare( headword, word, Qt::CaseInsensitive) != 0 ) continue;
		//if( QString::compare( headword, word, Qt::CaseInsensitive) != 0 && QString::compare( headword, word2, Qt::CaseInsensitive) != 0 ) continue;	//ooo
		//if( QString::compare( headword, word, Qt::CaseInsensitive) != 0 && !wordFound ) continue;	//ooo
		//if( QString::compare( headword, word, Qt::CaseInsensitive) != 0 && !headword.contains( word, Qt::CaseInsensitive) ) continue;	//ooo
		//if( QString::compare( headword, word, Qt::CaseInsensitive) != 0 && headword.at(headword.indexOf(word)-1) != '>' ) continue;	//ooo
		//if( headword.contains( word, Qt::CaseInsensitive) ) continue;			//ooo
		//if ( QString::compare(headword, word, Qt::CaseInsensitive) != 0 && (indexOfWord < 0 || (indexOfWord > 0 && headword.at(indexOfWord-1) != '>') )
			//&& ( b_wholeStarDict && !headword.contains( word, Qt::CaseInsensitive)) ) continue;	//ooo
			
		if (b_wholeWordsOnly && headword.contains(word, Qt::CaseInsensitive)) {

			QTextDocument document(headword, 0);			//ooo
			QTextCursor highlightCursor(&document);			//ooo
			//QTextCursor cursor(&document);			//ooo

			while (!highlightCursor.isNull() && !highlightCursor.atEnd()) {
        			highlightCursor = document.find(word, highlightCursor, QTextDocument::FindWholeWords);

        			if (!highlightCursor.isNull()) {
					foundWholeWord = true;
					break;
				}
			}
		}
			
		if (!b_wholeStarDict) {
			
			if (QString::compare(headword, word, Qt::CaseInsensitive) != 0 
			&& (indexOfWord < 0 || (indexOfWord > 0 && headword.at(indexOfWord-1) != '>')) ) continue;
			
		} else {
		  
		  	if (b_wholeWordsOnly) {
				if (!foundWholeWord) continue;
					foundWholeWord = false;
			} else if (b_wordStartsWith) {
				//if (!headword.startsWith( word, Qt::CaseInsensitive) && !headword.contains( " "+word, Qt::CaseInsensitive)
				  //&& !headword.contains( ">"+word, Qt::CaseInsensitive) && !headword.contains( "-"+word, Qt::CaseInsensitive)) continue;
				if (!headword.contains(word, Qt::CaseInsensitive)) continue;
				//if (!headword.startsWith(word, Qt::CaseInsensitive)) continue;
				int index = headword.indexOf(word, 0, Qt::CaseInsensitive);
				if (index > 0) {
					QChar ch = headword.at(index-1);
					
					//if (ch != ' ' && ch != '<' && ch != '-') continue;
					if (ch != QChar(0x20) && ch != QChar(0x3E) && ch != QChar(0x2D)) continue;
				}
			} else {
				if (!headword.contains( word, Qt::CaseInsensitive)) continue;
			}
		}

		/*if ( QString::compare(headword, word, Qt::CaseInsensitive) != 0 ) {		//ooo
			if ( indexOfWord <= 0 ) {
				continue;
			} else if ( headword.at(indexOfWord - 1) != '>' ) {
				continue;
			}
		}*/

		found = true;

		// Catch the position of definition in definition file
		entry.position = (unsigned char)line[3] + 256 * (unsigned char)line[2] + 256 * 256 * (unsigned char)line[1] + 256 * 256 * 256 *(unsigned char)line[0];

		// Catch the size of definition in definition file
		entry.size = (unsigned char)line[7] + 256 * (unsigned char)line[6] + 256 * 256 * (unsigned char)line[5] + 256 * 256 * 256 *(unsigned char)line[4];

		// Word found. Break the loop.
		//break;
		
		if (!b_wholeStarDict) {	//ooo
			break;
		} else {
			//headwords.append(headword);
			headwords.append(headword.toUtf8());
			positions.append(entry.position);
			sizes.append(entry.size);
			continue;
			//entries.position.insert(position);
			//entries.size(size);
			//entries.position[p] = position;
			//entries.size[p] = size;
			//p++;
		}

	}

	idxFile->close();

	//if( !found ) return text = "*** nothing ***";	//ooo
	if( !found ) return text = "";	//ooo

	// Check if the definition file is compressed
	if( isCompressed ) {
	  
		char pt[CHUNK];		//ooo
		//ulong a = 0;
		//uint a = 0;		//ooo
		uint a;			//ooo
		QByteArray result;	//ooo
		result.clear();		//ooo

		if (b_wholeStarDict) {
		  
			dictFile->open( QIODevice::ReadOnly );
			
			for (int i = 0; i < headwords.size(); i++) {
		  
				a = 0;
				uint chunk = positions.at(i) / CHLEN ;
				uint pos = positions.at(i) % CHLEN;
				uint lastChunk = (positions.at(i) + sizes.at(i)) / CHLEN;		//ooo
				uint lastPos = (positions.at(i) + sizes.at(i)) % CHLEN;			//ooo
			
				//QByteArray result;
				//result.clear();		//ooo
				//result.append("<p><l>"+headwords.at(i).toAscii()+"</l></p>"); //oooo
				result.append("<p><l>"+headwords.at(i).toLatin1()+"</l></p>");  //xxxx
				//result.append("\n");

				//dictFile->open( QIODevice::ReadOnly );
			
				for (uint i = chunk; i <= lastChunk; i++) {	//ooo
		  
					dictFile->seek( offsetsWithHeader[i] );
					unsigned int chunkLen = offsets[i];

					unsigned char data[chunkLen];		//ooo

					for(unsigned long a = 0; a < offsets[i]; a++) {
						dictFile->getChar(&c);
						data[a] = (unsigned char)c;
					}
			
					if( i == chunk && i == lastChunk) {
			  
						memcpy(pt, Inflate(data, offsets[i]) + pos, lastPos - pos);
						pt[lastPos-pos] = '\0';						//ooo
			  
					} else {
			
						if( i == chunk ) {
							memcpy(pt, Inflate(data, offsets[i]) + pos, CHLEN - pos);
							pt[CHLEN - pos] = '\0';						//ooo
						} else if( i == lastChunk) {
							memcpy(pt, Inflate(data, offsets[i]), lastPos);
							pt[lastPos] = '\0';						//ooo
						} else {
							memcpy(pt, Inflate(data, offsets[i]), CHLEN);
							pt[CHLEN] = '\0';						//ooo
						}
					}
					result.append(pt);
				}
				result.append("<hr width=\"5\" size=\"1\" align=\"center\">");
			}
			
		} else {

		// Calculate how many chunks we have to skip
		uint chunk = entry.position / CHLEN ;
		// Calculate the position of definition in chunk
		uint pos = entry.position % CHLEN;
		// Calculate the last chunk
		uint lastChunk = (entry.position + entry.size) / CHLEN;		//ooo
		// Calculate the last position of definition in chunk
		uint lastPos = (entry.position + entry.size) % CHLEN;		//ooo

		// Stores the decompressed data
		//QByteArray result;
		//result.clear();		//ooo

		// Definition file
		dictFile->open( QIODevice::ReadOnly );

		// Decompress the data
		for(uint i = chunk; i <= lastChunk; i++) {	//ooo
		 
			// Jump to chunk we are looking for
			dictFile->seek( offsetsWithHeader[i] );
			unsigned int chunkLen = offsets[i];

			unsigned char data[chunkLen];		//ooo

			// Get the compressed data
			for(unsigned long a = 0; a < offsets[i]; a++) {
				dictFile->getChar(&c);
				data[a] = (unsigned char)c;
			}
			
			if( i == chunk && i == lastChunk) {

				memcpy(pt, Inflate(data, offsets[i]) + pos, lastPos - pos);
				pt[lastPos-pos] = '\0';						//ooo
			  
			} else {

				if( i == chunk ) {
			
					memcpy(pt, Inflate(data, offsets[i]) + pos, CHLEN - pos);
					pt[CHLEN - pos] = '\0';						//ooo
				
				} else if( i == lastChunk) {
			
					memcpy(pt, Inflate(data, offsets[i]), lastPos);
					pt[lastPos] = '\0';						//ooo
			 
				} else {
			 
					memcpy(pt, Inflate(data, offsets[i]), CHLEN);
					pt[CHLEN] = '\0';						//ooo
			 
				}
			}
			
			//result.append( Inflate( data4, offsets[i] ));
			//result.append( parseData(pt).toAscii().data() );			//ooo
			result.append(pt);

		}
		}	//else
		dictFile->close();
		
		// Returns only the definition
		return QString::fromUtf8(result);	//ooo

	} else {

		// The file is not compressed
		if (!dictFile->open(QIODevice::ReadOnly)) {

		}

		// Jump to position of definition
		dictFile->seek(entry.position);

		// Get the definition
		QByteArray result;
		result.clear();		//ooo
		result.resize( entry.size + 1 );

		for( uint a = 0; a < entry.size; a++ ) {

			dictFile->getChar(&c);
			result[a] = c;

		}

		result.insert(entry.size, QByteArray("\0"));	//ooo

		dictFile->close();

		// Return the result
		return QString::fromUtf8( result.data() );
	}
}


char* StarDict::Inflate( unsigned char *data, unsigned long size )		//ooo
{
	
	int ret;
	unsigned have;			//ooo
	//int have;			//ooo
	z_stream strm;
	char in[CHUNK];			//ooo
	char out[CHUNK];
        char *result;	//xxx
        result = (char *)malloc( CHUNK + 1 );	//xxx

	// Inicialization of zlib
	/* allocate inflate state */	//ooo
	strm.zalloc = Z_NULL;
	strm.zfree = Z_NULL;
	strm.opaque = Z_NULL;
	strm.avail_in = 0;
	strm.next_in = Z_NULL;
	//ret = inflateInit2( &strm, -MAX_WBITS );
	ret = inflateInit2( &strm, -15 );		//ooo
	//ret = inflateInit2( &strm, 8 );		//ooo
	//ret = inflateInit(&strm);			//ooo
	if (ret != Z_OK)
		return "/////";
	
	/* decompress until deflate stream ends or end of file */
	//do {								//ooo
		//strm.avail_in = fread(in, 1, CHUNK, source);		//ooo
		
		// Compressed data
		strm.avail_in = size;			//ooo
		strm.next_in = (Bytef*)data;		//ooo
	
		/* run inflate() on input until output buffer not full */
		do {
			strm.avail_out = CHUNK;
			strm.next_out = (Bytef*)out;
			//ret = inflate(&strm, Z_SYNC_FLUSH);
			//ret = inflate(&strm, Z_NO_FLUSH);	//ooo
			ret = inflate(&strm, Z_PARTIAL_FLUSH);	//ooo
			//assert(ret != Z_STREAM_ERROR);  /* state not clobbered */	//ooo

			if ( ret != Z_OK ) {

			}
		
			switch (ret) {
				case Z_NEED_DICT:
					ret = Z_DATA_ERROR;     /* and fall through */
					
				case Z_STREAM_ERROR:
					break;
					
				case Z_DATA_ERROR:
					break;
				  
				case Z_MEM_ERROR:
					(void)inflateEnd(&strm);
					break;
			}
			
			have = CHUNK - strm.avail_out;		//ooo
			
			/*if (fwrite(out, 1, have, dest) != have || ferror(dest)) {	//ooo
				(void)inflateEnd(&strm);
				return Z_ERRNO;
			}*/

		} while (strm.avail_out == 0);
		
	/* done when inflate() says it's done */
	//} while (ret != Z_STREAM_END);
	
	/* clean up and return */
	//ret = inflateEnd(&strm);
	(void)inflateEnd(&strm);	//ooo
        strcpy(result, out);	//xxx

	return result;
	
	//std::cout << "StarDict::parseData = " << parseData(out).toAscii().data() << "\n";	//ooo

	//return &out[0];			//ooo
}


QString StarDict::parseData(const char *data)
{
	//return QString();	//ooo
	return "Not implemented";
}



QString StarDict::printMessage()
{
	//QMessageBox::about(this, tr("About Diagram Scene"), tr("printMessage(: 1"));
	//QMessageBox::about(i18n("About Menu"), QString("%1").arg("printMessage(: 1"));

	return "StarDict <---> !!!";
}

/*bool StarDict::open()
{
	//unsigned char buf[6];
	//int i;

	f = fopen( m_filename.c_str(), "r" );

	if( f == NULL ) {
		return false;
	}

	return true;
}*/

//void StarDict::Info_Ifo(FILE & f)
void StarDict::Info_Ifo(QFile & file)
{
	/*QString line = "";
	bool ok;

	QTextStream in(&file);

	line = in.readLine();

	//if ( f.gets() != "StarDict's dict ifo file" ) {

	//}

	if ( line != "StarDict's dict ifo file" ) {

	}

	while (!line.isNull()) {

		if ( line.startsWith("wordcount=") ) {
			wordcount = line.section('=', 1, 1).toInt(&ok, 0);
			//wordcount = line.section('=', 1, 1);
		} else if ( line.startsWith("idxfilesize=") ) {
			idxfilesize = line.section('=', 1, 1).toInt(&ok, 0);
			//idxfilesize = line.section('=', 1, 1);
		}

		line = in.readLine();
	}*/
}


void StarDict::Info_Idx(QFile & file)
{
	QString line = "";

	QTextStream in(&file);
	//QDataStream in(&file);

	//line = in.readLine();

	while (!in.atEnd()) {

		line = in.readLine();
		//printf( "%s\n", line.toAscii().data() );    //oooo
        printf( "%s\n", line.toLatin1().data() );   //xxxx

	}

	/*QString str;
	qint32 a;
	in >> str;
	printf( "%s\n", str.toAscii().data() );
	qDebug() << str;*/

}

//#include "stardict.moc"
