Format code style.

This commit is contained in:
zhangzihao 2021-04-26 15:06:47 +08:00
parent a70be3f810
commit 422c73fd1e
141 changed files with 11473 additions and 12282 deletions

View File

@ -24,8 +24,7 @@
static ChineseSegmentation *global_instance_chinese_segmentation = nullptr;
QMutex ChineseSegmentation::m_mutex;
ChineseSegmentation::ChineseSegmentation()
{
ChineseSegmentation::ChineseSegmentation() {
const char * const DICT_PATH = "/usr/share/ukui-search/res/dict/jieba.dict.utf8";
const char * const HMM_PATH = "/usr/share/ukui-search/res/dict/hmm_model.utf8";
const char * const USER_DICT_PATH = "/usr/share/ukui-search/res/dict/user.dict.utf8";
@ -39,15 +38,13 @@ ChineseSegmentation::ChineseSegmentation()
STOP_WORD_PATH);
}
ChineseSegmentation::~ChineseSegmentation()
{
ChineseSegmentation::~ChineseSegmentation() {
if(m_jieba)
delete m_jieba;
m_jieba = nullptr;
}
ChineseSegmentation *ChineseSegmentation::getInstance()
{
ChineseSegmentation *ChineseSegmentation::getInstance() {
QMutexLocker locker(&m_mutex);
if(!global_instance_chinese_segmentation) {
global_instance_chinese_segmentation = new ChineseSegmentation;
@ -55,8 +52,7 @@ ChineseSegmentation *ChineseSegmentation::getInstance()
return global_instance_chinese_segmentation;
}
QVector<SKeyWord> ChineseSegmentation::callSegement(QString str)
{
QVector<SKeyWord> ChineseSegmentation::callSegement(QString str) {
std::string s;
s = str.toStdString();
str.squeeze();
@ -76,8 +72,7 @@ QVector<SKeyWord> ChineseSegmentation::callSegement(QString str)
}
void ChineseSegmentation::convert(std::vector<cppjieba::KeywordExtractor::Word> &keywordres, QVector<SKeyWord> &kw)
{
void ChineseSegmentation::convert(std::vector<cppjieba::KeywordExtractor::Word> &keywordres, QVector<SKeyWord> &kw) {
for(auto i : keywordres) {
SKeyWord temp;
temp.word = i.word;

View File

@ -43,8 +43,7 @@ struct SKeyWord{
}
};
class CHINESESEGMENTATION_EXPORT ChineseSegmentation
{
class CHINESESEGMENTATION_EXPORT ChineseSegmentation {
public:
static ChineseSegmentation *getInstance();
~ChineseSegmentation();

View File

@ -90,21 +90,16 @@ class DictTrie {
trie_->Find(begin, end, res, max_word_len);
}
bool Find(const string& word)
{
bool Find(const string& word) {
const DictUnit *tmp = NULL;
RuneStrArray runes;
if (!DecodeRunesInString(word, runes))
{
if(!DecodeRunesInString(word, runes)) {
XLOG(ERROR) << "Decode failed.";
}
tmp = Find(runes.begin(), runes.end());
if (tmp == NULL)
{
if(tmp == NULL) {
return false;
}
else
{
} else {
return true;
}
}

View File

@ -95,8 +95,7 @@ class Jieba {
return dict_trie_.InsertUserWord(word, freq, tag);
}
bool Find(const string& word)
{
bool Find(const string& word) {
return dict_trie_.Find(word);
}

View File

@ -28,7 +28,11 @@ namespace cppjieba {
class TextRankExtractor {
public:
typedef struct _Word {string word;vector<size_t> offsets;double weight;} Word; // struct Word
typedef struct _Word {
string word;
vector<size_t> offsets;
double weight;
} Word; // struct Word
private:
typedef std::map<string, Word> WordMap;

View File

@ -30,8 +30,7 @@ break;
println("+---------------------------------------------------------------+");
//read a line from a command line.
static fstring getLine( FILE *fp, fstring __dst )
{
static fstring getLine(FILE *fp, fstring __dst) {
register int c;
register fstring cs;
@ -56,8 +55,7 @@ static fstring getLine( FILE *fp, fstring __dst )
}*/
//int friso_test(int argc, char **argv)
int friso_test()
{
int friso_test() {
clock_t s_time, e_time;
char line[__INPUT_LENGTH__] = {0};

View File

@ -18,8 +18,7 @@
//friso instance about function
/* {{{ create a new friso configuration variable.
*/
FRISO_API friso_t friso_new( void )
{
FRISO_API friso_t friso_new(void) {
friso_t e = (friso_t) FRISO_MALLOC(sizeof(friso_entry));
if(e == NULL) {
___ALLOCATION_ERROR___
@ -37,8 +36,7 @@ FRISO_API friso_t friso_new( void )
* @return 1 for successfully and 0 for failed.
*/
FRISO_API int friso_init_from_ifile(
friso_t friso, friso_config_t config, fstring __ifile )
{
friso_t friso, friso_config_t config, fstring __ifile) {
FILE *__stream;
char __chars__[256], __key__[128], *__line__;
char __lexi__[160], lexpath[160];
@ -198,8 +196,7 @@ FRISO_API int friso_init_from_ifile(
/* {{{ friso free functions.
* here we have to free its dictionary.
*/
FRISO_API void friso_free( friso_t friso )
{
FRISO_API void friso_free(friso_t friso) {
//free the dictionary
if(friso->dic != NULL) {
friso_dic_free(friso->dic);
@ -211,8 +208,7 @@ FRISO_API void friso_free( friso_t friso )
/* {{{ set the current split mode
* view the friso.h#friso_mode_t
*/
FRISO_API void friso_set_mode( friso_config_t config, friso_mode_t mode )
{
FRISO_API void friso_set_mode(friso_config_t config, friso_mode_t mode) {
config->mode = mode;
switch(config->mode) {
@ -233,8 +229,7 @@ FRISO_API void friso_set_mode( friso_config_t config, friso_mode_t mode )
/* {{{ create a new friso configuration entry and initialize
* it with default value.*/
FRISO_API friso_config_t friso_new_config( void )
{
FRISO_API friso_config_t friso_new_config(void) {
friso_config_t cfg = (friso_config_t)
FRISO_MALLOC(sizeof(friso_config_entry));
if(cfg == NULL) {
@ -249,8 +244,7 @@ FRISO_API friso_config_t friso_new_config( void )
/* }}} */
/* {{{ initialize the specified friso config entry with default value.*/
FRISO_API void friso_init_config( friso_config_t cfg )
{
FRISO_API void friso_init_config(friso_config_t cfg) {
cfg->max_len = DEFAULT_SEGMENT_LENGTH;
cfg->r_name = 1;
cfg->mix_len = DEFAULT_MIX_LENGTH;
@ -273,8 +267,7 @@ FRISO_API void friso_init_config( friso_config_t cfg )
/* {{{ create a new segment task entry.
*/
FRISO_API friso_task_t friso_new_task()
{
FRISO_API friso_task_t friso_new_task() {
friso_task_t task = (friso_task_t) FRISO_MALLOC(sizeof(friso_task_entry));
if(task == NULL) {
___ALLOCATION_ERROR___
@ -296,8 +289,7 @@ FRISO_API friso_task_t friso_new_task()
/* }}} */
/* {{{ free the specified task*/
FRISO_API void friso_free_task( friso_task_t task )
{
FRISO_API void friso_free_task(friso_task_t task) {
//free the allocation of the poll link list.
if(task->pool != NULL) {
free_link_list(task->pool);
@ -318,8 +310,7 @@ FRISO_API void friso_free_task( friso_task_t task )
/* }}} */
/* {{{ create a new friso token */
FRISO_API friso_token_t friso_new_token( void )
{
FRISO_API friso_token_t friso_new_token(void) {
friso_token_t token = (friso_token_t)
FRISO_MALLOC(sizeof(friso_token_entry));
if(token == NULL) {
@ -344,8 +335,7 @@ FRISO_API friso_token_t friso_new_token( void )
* and the most important one - clear the poll link list.
*/
FRISO_API void friso_set_text(
friso_task_t task, fstring text )
{
friso_task_t task, fstring text) {
task->text = text;
task->idx = 0; //reset the index
task->length = strlen(text);
@ -364,8 +354,7 @@ __STATIC_API__ uint_t readNextWord(
friso_t friso, //friso instance
friso_task_t task, //token task
uint_t *idx, //current index.
fstring __word ) //work buffer.
{
fstring __word) { //work buffer.
if(friso->charset == FRISO_UTF8) {
//@reader: task->unicode = get_utf8_unicode(task->buffer) is moved insite
// function utf8_next_word from friso 1.6.0 .
@ -383,8 +372,7 @@ __STATIC_API__ uint_t readNextWord(
FRISO_API lex_entry_t next_simple_cjk(
friso_t friso,
friso_config_t config,
friso_task_t task )
{
friso_task_t task) {
uint_t t, idx = task->idx, __length__;
string_buffer_t sb = new_string_buffer_with_string(task->buffer);
lex_entry_t e = friso_dic_get(friso->dic, __LEX_CJK_WORDS__, sb->buffer);
@ -479,8 +467,7 @@ FRISO_API lex_entry_t next_simple_cjk(
__STATIC_API__ lex_entry_t next_basic_latin(
friso_t friso,
friso_config_t config,
friso_task_t task )
{
friso_task_t task) {
int __convert = 0, t = 0, blen = 0;
int chkecm = 0, chkunits = 1, wspace = 0;
@ -737,8 +724,7 @@ __STATIC_API__ friso_array_t get_next_match(
friso_t friso,
friso_config_t config,
friso_task_t task,
uint_t idx )
{
uint_t idx) {
register uint_t t;
string_buffer_t sb = new_string_buffer_with_string(task->buffer);
@ -795,8 +781,7 @@ typedef friso_chunk_entry * friso_chunk_t;
/* {{{ create a new chunks*/
__STATIC_API__ friso_chunk_t new_chunk(
friso_array_t words, uint_t length )
{
friso_array_t words, uint_t length) {
friso_chunk_t chunk = (friso_chunk_t)
FRISO_MALLOC(sizeof(friso_chunk_entry));
if(chunk == NULL) {
@ -814,8 +799,7 @@ __STATIC_API__ friso_chunk_t new_chunk(
/* }}} */
/* {{{ free the specified chunk */
__STATIC_API__ void free_chunk( friso_chunk_t chunk )
{
__STATIC_API__ void free_chunk(friso_chunk_t chunk) {
FRISO_FREE(chunk);
}
/* }}} */
@ -823,8 +807,7 @@ __STATIC_API__ void free_chunk( friso_chunk_t chunk )
/* {{{ a static function to count the average word length
* of the given chunk.
*/
__STATIC_API__ float count_chunk_avl( friso_chunk_t chunk )
{
__STATIC_API__ float count_chunk_avl(friso_chunk_t chunk) {
chunk->average_word_length =
((float) chunk->length) / chunk->words->length;
return chunk->average_word_length;
@ -834,8 +817,7 @@ __STATIC_API__ float count_chunk_avl( friso_chunk_t chunk )
/* {{{ a static function to count the word length variance
* of the given chunk.
*/
__STATIC_API__ float count_chunk_var( friso_chunk_t chunk )
{
__STATIC_API__ float count_chunk_var(friso_chunk_t chunk) {
float var = 0, tmp = 0; //snapshot
register uint_t t;
lex_entry_t e;
@ -855,8 +837,7 @@ __STATIC_API__ float count_chunk_var( friso_chunk_t chunk )
/* {{{ a static function to count the single word morpheme degree of freedom
* of the given chunk.
*/
__STATIC_API__ float count_chunk_mdf( friso_chunk_t chunk )
{
__STATIC_API__ float count_chunk_mdf(friso_chunk_t chunk) {
float __mdf__ = 0;
register uint_t t;
lex_entry_t e;
@ -898,8 +879,7 @@ putchar('\n'); \
* 3. smallest word length variance.
* 4. largest single word morpheme degrees of freedom.
*/
__STATIC_API__ friso_chunk_t mmseg_core_invoke( friso_array_t chunks )
{
__STATIC_API__ friso_chunk_t mmseg_core_invoke(friso_array_t chunks) {
register uint_t t/*, j*/;
float max;
friso_chunk_t e;
@ -1057,8 +1037,7 @@ __STATIC_API__ friso_chunk_t mmseg_core_invoke( friso_array_t chunks )
FRISO_API lex_entry_t next_complex_cjk(
friso_t friso,
friso_config_t config,
friso_task_t task )
{
friso_task_t task) {
register uint_t x, y, z;
/*bakup the task->bytes here*/
uint_t __idx__ = task->bytes;
@ -1199,8 +1178,7 @@ FRISO_API lex_entry_t next_complex_cjk(
* */
__STATIC_API__ void token_sphinx_output(
friso_task_t task,
lex_entry_t lex )
{
lex_entry_t lex) {
uint_t i, j, len;
fstring _word;
len = lex->length;
@ -1231,8 +1209,7 @@ __STATIC_API__ void token_sphinx_output(
__STATIC_API__ void token_normal_output(
friso_task_t task,
lex_entry_t lex,
int front )
{
int front) {
uint_t i;
fstring _word;
lex_entry_t e;
@ -1265,8 +1242,7 @@ __STATIC_API__ lex_entry_t en_second_seg(
friso_t friso,
friso_config_t config,
friso_task_t task,
lex_entry_t lex, int retfw )
{
lex_entry_t lex, int retfw) {
//printf("sseg: %d\n", (task->ctrlMask & START_SS_MASK));
int j, p = 0, start = 0;
@ -1367,8 +1343,7 @@ __STATIC_API__ lex_entry_t en_second_seg(
FRISO_API friso_token_t next_mmseg_token(
friso_t friso,
friso_config_t config,
friso_task_t task )
{
friso_task_t task) {
uint_t j, len = 0;
string_buffer_t sb = NULL;
lex_entry_t lex = NULL, tmp = NULL, sword = NULL;
@ -1505,7 +1480,8 @@ FRISO_API friso_token_t next_mmseg_token(
lex->offset = j;
check_free_otlex_entry(tmp);
free_string_buffer(sb);
tmp = NULL; sb = NULL;
tmp = NULL;
sb = NULL;
}
}
@ -1708,8 +1684,7 @@ FRISO_API friso_token_t next_mmseg_token(
* with simple forward maximum matching algorithm
*/
FRISO_API friso_token_t next_detect_token(
friso_t friso, friso_config_t config, friso_task_t task )
{
friso_t friso, friso_config_t config, friso_task_t task) {
lex_entry_t lex = NULL;
int i, __convert = 0, tbytes, wbytes;

View File

@ -18,8 +18,7 @@
FRISO_API int gbk_next_word(
friso_task_t task,
uint_t *idx,
fstring __word )
{
fstring __word) {
int c;
if(*idx >= task->length) return 0;
@ -46,8 +45,7 @@ FRISO_API int gbk_next_word(
//check if the given buffer is a gbk word (ANSII string).
// included the simplified and traditional words.
FRISO_API int gbk_cn_string(char *str)
{
FRISO_API int gbk_cn_string(char *str) {
int c1 = (uchar_t) str[0];
int c2 = (uchar_t) str[1];
//GBK/2: gb2312 chinese word.
@ -65,8 +63,7 @@ FRISO_API int gbk_cn_string(char *str)
/*check if the given char is a ASCII letter
* include all the arabic number, letters and english puntuations.*/
FRISO_API int gbk_halfwidth_en_char( char c )
{
FRISO_API int gbk_halfwidth_en_char(char c) {
int u = (uchar_t) c;
return (u >= 32 && u <= 126);
}
@ -76,8 +73,7 @@ FRISO_API int gbk_halfwidth_en_char( char c )
* include the full-width arabic numeber, letters.
* but not the full-width puntuations.
*/
FRISO_API int gbk_fullwidth_en_char( char *str )
{
FRISO_API int gbk_fullwidth_en_char(char *str) {
int c1 = (uchar_t) str[0];
int c2 = (uchar_t) str[1];
return ((c1 == 0xA3)
@ -88,8 +84,7 @@ FRISO_API int gbk_fullwidth_en_char( char *str )
//check if the given char is a upper case english letter.
// included the full-width and half-width letters.
FRISO_API int gbk_uppercase_letter( char *str )
{
FRISO_API int gbk_uppercase_letter(char *str) {
int c1 = (uchar_t) str[0];
int c2 = (uchar_t) str[1];
if(c1 <= 0x80) { //half-width
@ -101,8 +96,7 @@ FRISO_API int gbk_uppercase_letter( char *str )
//check if the given char is a lower case char.
// included the full-width and half-width letters.
FRISO_API int gbk_lowercase_letter( char *str )
{
FRISO_API int gbk_lowercase_letter(char *str) {
int c1 = (uchar_t) str[0];
int c2 = (uchar_t) str[1];
if(c1 <= 0x80) { //half-width
@ -114,8 +108,7 @@ FRISO_API int gbk_lowercase_letter( char *str )
//check if the given char is a arabic numeric.
// included the full-width and half-width arabic numeric.
FRISO_API int gbk_numeric_letter( char *str )
{
FRISO_API int gbk_numeric_letter(char *str) {
int c1 = (uchar_t) str[0];
int c2 = (uchar_t) str[1];
if(c1 <= 0x80) { //half-width
@ -129,8 +122,7 @@ FRISO_API int gbk_numeric_letter( char *str )
* check if the given fstring is make up with numeric chars.
* both full-width,half-width numeric is ok.
*/
FRISO_API int gbk_numeric_string( char *str )
{
FRISO_API int gbk_numeric_string(char *str) {
char *s = str;
int c1 = 0;
int c2 = 0;
@ -149,8 +141,7 @@ FRISO_API int gbk_numeric_string( char *str )
return 1;
}
FRISO_API int gbk_decimal_string( char *str )
{
FRISO_API int gbk_decimal_string(char *str) {
int c1 = 0;
int c2 = 0;
int len = strlen(str), i, p = 0;
@ -180,8 +171,7 @@ FRISO_API int gbk_decimal_string( char *str )
//check if the given char is a english(ASCII) letter.
// (full-width and half-width), not the punctuation/arabic of course.
FRISO_API int gbk_en_letter( char *str )
{
FRISO_API int gbk_en_letter(char *str) {
int c1 = (uchar_t) str[0];
int c2 = (uchar_t) str[1];
if(c1 <= 0x80) {
@ -198,8 +188,7 @@ FRISO_API int gbk_en_letter( char *str )
//check the given char is a whitespace or not.
// included full-width and half-width whitespace.
FRISO_API int gbk_whitespace( char *str )
{
FRISO_API int gbk_whitespace(char *str) {
int c1 = (uchar_t) str[0];
int c2 = (uchar_t) str[1];
if(c1 <= 0x80) {
@ -211,8 +200,7 @@ FRISO_API int gbk_whitespace( char *str )
/* check if the given char is a letter number like 'ⅠⅡ'
*/
FRISO_API int gbk_letter_number( char *str )
{
FRISO_API int gbk_letter_number(char *str) {
int c1 = (uchar_t) str[0];
int c2 = (uchar_t) str[1];
return ((c1 == 0xa2)
@ -223,16 +211,14 @@ FRISO_API int gbk_letter_number( char *str )
/*
* check if the given char is a other number like ''
*/
FRISO_API int gbk_other_number( char *str )
{
FRISO_API int gbk_other_number(char *str) {
int c1 = (uchar_t) str[0];
int c2 = (uchar_t) str[1];
return ((c1 == 0xa2) && (c2 >= 0xc5 && c2 <= 0xee));
}
//check if the given char is a english punctuation.
FRISO_API int gbk_en_punctuation( char c )
{
FRISO_API int gbk_en_punctuation(char c) {
int u = (uchar_t) c;
return ((u > 32 && u < 48)
|| (u > 57 && u < 65)
@ -241,8 +227,7 @@ FRISO_API int gbk_en_punctuation( char c )
}
//check the given char is a chinese punctuation.
FRISO_API int gbk_cn_punctuation( char *str )
{
FRISO_API int gbk_cn_punctuation(char *str) {
int c1 = (uchar_t) str[0];
int c2 = (uchar_t) str[1];
//full-width en punctuation.

View File

@ -18,8 +18,7 @@
FRISO_API int utf8_next_word(
friso_task_t task,
uint_t *idx,
fstring __word )
{
fstring __word) {
if(*idx >= task->length) return 0;
//register uint_t t;
@ -47,8 +46,7 @@ FRISO_API int utf8_next_word(
*
* @param int
*/
FRISO_API void print_char_binary( char value )
{
FRISO_API void print_char_binary(char value) {
register uint_t t;
for(t = 0; t < __CHAR_BYTES__; t++) {
@ -68,8 +66,7 @@ FRISO_API void print_char_binary( char value )
* @param __char
* @return int
*/
FRISO_API int get_utf8_bytes( char value )
{
FRISO_API int get_utf8_bytes(char value) {
register uint_t t = 0;
//one byte ascii char.
@ -87,8 +84,7 @@ FRISO_API int get_utf8_bytes( char value )
* @param ch
* @return int.
*/
FRISO_API int get_utf8_unicode( const fstring ch )
{
FRISO_API int get_utf8_unicode(const fstring ch) {
int code = 0, bytes = get_utf8_bytes(*ch);
register uchar_t *bit = (uchar_t *) &code;
register char b1, b2, b3;
@ -119,8 +115,7 @@ FRISO_API int get_utf8_unicode( const fstring ch )
}
//turn the unicode serial to a utf-8 string.
FRISO_API int unicode_to_utf8( uint_t u, fstring __word )
{
FRISO_API int unicode_to_utf8(uint_t u, fstring __word) {
if(u <= 0x0000007F) {
//U-00000000 - U-0000007F
//0xxxxxxx
@ -205,8 +200,7 @@ FRISO_API int unicode_to_utf8( uint_t u, fstring __word )
#define FRISO_CJK_CHK_C
//#define FRISO_CJK_CHK_J
//#define FRISO_CJK_CHK_K
FRISO_API int utf8_cjk_string( uint_t u )
{
FRISO_API int utf8_cjk_string(uint_t u) {
int c = 0, j = 0, k = 0;
//Chinese.
#ifdef FRISO_CJK_CHK_C
@ -240,8 +234,7 @@ FRISO_API int utf8_cjk_string( uint_t u )
* @param c
* @return int 1 for yes and 0 for not.
*/
FRISO_API int utf8_halfwidth_en_char( uint_t u )
{
FRISO_API int utf8_halfwidth_en_char(uint_t u) {
return (u >= 32 && u <= 126);
}
@ -253,8 +246,7 @@ FRISO_API int utf8_halfwidth_en_char( uint_t u )
* @param c
* @return int
*/
FRISO_API int utf8_fullwidth_en_char( uint_t u )
{
FRISO_API int utf8_fullwidth_en_char(uint_t u) {
return ((u >= 65296 && u <= 65305) //arabic number
|| (u >= 65313 && u <= 65338) //upper case letters
|| (u >= 65345 && u <= 65370)); //lower case letters
@ -262,32 +254,28 @@ FRISO_API int utf8_fullwidth_en_char( uint_t u )
//check the given char is a upper case letters or not.
// included the full-width and half-width letters.
FRISO_API int utf8_uppercase_letter( uint_t u )
{
FRISO_API int utf8_uppercase_letter(uint_t u) {
if(u > 65280) u -= 65248;
return (u >= 65 && u <= 90);
}
//check the given char is a upper case letters or not.
// included the full-width and half-width letters.
FRISO_API int utf8_lowercase_letter( uint_t u )
{
FRISO_API int utf8_lowercase_letter(uint_t u) {
if(u > 65280) u -= 65248;
return (u >= 97 && u <= 122);
}
//check the given char is a numeric
// included the full-width and half-width arabic numeric.
FRISO_API int utf8_numeric_letter( uint_t u )
{
FRISO_API int utf8_numeric_letter(uint_t u) {
if(u > 65280) u -= 65248; //make full-width half-width.
return ((u >= 48 && u <= 57));
}
//check the given char is a english letter.(included the full-width)
// not the punctuation of course.
FRISO_API int utf8_en_letter( uint_t u )
{
FRISO_API int utf8_en_letter(uint_t u) {
if(u > 65280) u -= 65248;
return ((u >= 65 && u <= 90)
|| (u >= 97 && u <= 122));
@ -310,8 +298,7 @@ FRISO_API int utf8_en_letter( uint_t u )
* 65304,
* 65305,
*/
FRISO_API int utf8_numeric_string( const fstring str )
{
FRISO_API int utf8_numeric_string(const fstring str) {
fstring s = str;
int bytes, u;
@ -337,8 +324,7 @@ FRISO_API int utf8_numeric_string( const fstring str )
return 1;
}
FRISO_API int utf8_decimal_string( const fstring str )
{
FRISO_API int utf8_decimal_string(const fstring str) {
int len = strlen(str), i, p = 0;
int bytes = 0, u;
@ -371,8 +357,7 @@ FRISO_API int utf8_decimal_string( const fstring str )
* @param ch
* @return int 1 for yes and 0 for not.
*/
FRISO_API int utf8_whitespace( uint_t u )
{
FRISO_API int utf8_whitespace(uint_t u) {
if(u == 32 || u == 12288) {
return 1;
}
@ -386,8 +371,7 @@ FRISO_API int utf8_whitespace( uint_t u )
* @param ch
* @return int
*/
FRISO_API int utf8_en_punctuation( uint_t u )
{
FRISO_API int utf8_en_punctuation(uint_t u) {
//if ( u > 65280 ) u = u - 65248; //make full-width half-width
return ((u > 32 && u < 48)
|| (u > 57 && u < 65)
@ -402,8 +386,7 @@ FRISO_API int utf8_en_punctuation( uint_t u )
* @param ch
* @return int
*/
FRISO_API int utf8_cn_punctuation( uint_t u )
{
FRISO_API int utf8_cn_punctuation(uint_t u) {
return ((u > 65280 && u < 65296)
|| (u > 65305 && u < 65312)
|| (u > 65338 && u < 65345)
@ -419,8 +402,7 @@ FRISO_API int utf8_cn_punctuation( uint_t u )
* @param ch
* @return int
*/
FRISO_API int utf8_letter_number( uint_t u )
{
FRISO_API int utf8_letter_number(uint_t u) {
return 0;
}
@ -430,8 +412,7 @@ FRISO_API int utf8_letter_number( uint_t u )
* @param ch
* @return int
*/
FRISO_API int utf8_other_number( uint_t u )
{
FRISO_API int utf8_other_number(uint_t u) {
return 0;
}

View File

@ -10,8 +10,7 @@
/* ********************************************
* friso array list static functions block *
**********************************************/
__STATIC_API__ void **create_array_entries( uint_t __blocks )
{
__STATIC_API__ void **create_array_entries(uint_t __blocks) {
register uint_t t;
void **block = (void **) FRISO_CALLOC(sizeof(void *), __blocks);
if(block == NULL) {
@ -29,8 +28,7 @@ __STATIC_API__ void **create_array_entries( uint_t __blocks )
//resize the array. (the opacity should not be smaller than array->length)
__STATIC_API__ friso_array_t resize_array_list(
friso_array_t array,
uint_t opacity )
{
uint_t opacity) {
register uint_t t;
void **block = create_array_entries(opacity);
@ -55,8 +53,7 @@ __STATIC_API__ friso_array_t resize_array_list(
//}
//create a new array list with a given opacity.
FRISO_API friso_array_t new_array_list_with_opacity( uint_t opacity )
{
FRISO_API friso_array_t new_array_list_with_opacity(uint_t opacity) {
friso_array_t array = (friso_array_t)
FRISO_MALLOC(sizeof(friso_array_entry));
if(array == NULL) {
@ -75,8 +72,7 @@ FRISO_API friso_array_t new_array_list_with_opacity( uint_t opacity )
* free the given friso array.
* and its items, but never where its items item pointed to .
*/
FRISO_API void free_array_list( friso_array_t array )
{
FRISO_API void free_array_list(friso_array_t array) {
//free the allocation that all the items pointed to
//register int t;
//if ( flag == 1 ) {
@ -92,8 +88,7 @@ FRISO_API void free_array_list( friso_array_t array )
}
//add a new item to the array.
FRISO_API void array_list_add( friso_array_t array, void *value )
{
FRISO_API void array_list_add(friso_array_t array, void *value) {
//check the condition to resize.
if(array->length == array->allocs) {
resize_array_list(array, array->length * 2 + 1);
@ -105,8 +100,7 @@ FRISO_API void array_list_add( friso_array_t array, void *value )
FRISO_API void array_list_insert(
friso_array_t array,
uint_t idx,
void *value )
{
void *value) {
register uint_t t;
if(idx <= array->length) {
@ -129,8 +123,7 @@ FRISO_API void array_list_insert(
}
//get the item at a specified position.
FRISO_API void *array_list_get( friso_array_t array, uint_t idx )
{
FRISO_API void *array_list_get(friso_array_t array, uint_t idx) {
if(idx < array->length) {
return array->items[idx];
}
@ -142,8 +135,7 @@ FRISO_API void *array_list_get( friso_array_t array, uint_t idx )
FRISO_API void * array_list_set(
friso_array_t array,
uint_t idx,
void * value )
{
void * value) {
void * oval = NULL;
if(idx < array->length) {
oval = array->items[idx];
@ -155,8 +147,7 @@ FRISO_API void * array_list_set(
//remove the item at a specified position.
//this will return the value of the removed item.
FRISO_API void * array_list_remove(
friso_array_t array, uint_t idx )
{
friso_array_t array, uint_t idx) {
register uint_t t;
void *oval = NULL;
@ -174,8 +165,7 @@ FRISO_API void * array_list_remove(
}
/*trim the array list*/
FRISO_API friso_array_t array_list_trim( friso_array_t array )
{
FRISO_API friso_array_t array_list_trim(friso_array_t array) {
if(array->length < array->allocs) {
return resize_array_list(array, array->length);
}
@ -188,8 +178,7 @@ FRISO_API friso_array_t array_list_trim( friso_array_t array )
* but will not free the point array allocations,
* and will reset the length of it.
*/
FRISO_API friso_array_t array_list_clear( friso_array_t array )
{
FRISO_API friso_array_t array_list_clear(friso_array_t array) {
register uint_t t;
//free all the allocations that the array->length's pointer pointed.
for(t = 0; t < array->length; t++) {

View File

@ -18,8 +18,7 @@
* */
FRISO_API int friso_cn_string(
friso_charset_t charset,
friso_task_t task )
{
friso_task_t task) {
if(charset == FRISO_UTF8) {
return utf8_cjk_string(task->unicode);
} else if(charset == FRISO_GBK) {
@ -32,8 +31,7 @@ FRISO_API int friso_cn_string(
//check if the specified word is a whitespace.
FRISO_API int friso_whitespace(
friso_charset_t charset,
friso_task_t task )
{
friso_task_t task) {
if(charset == FRISO_UTF8) {
return utf8_whitespace(task->unicode);
} else if(charset == FRISO_GBK) {
@ -46,8 +44,7 @@ FRISO_API int friso_whitespace(
//check if the specifiled word is a numeric letter.
FRISO_API int friso_numeric_letter(
friso_charset_t charset,
friso_task_t task)
{
friso_task_t task) {
if(charset == FRISO_UTF8) {
return utf8_numeric_letter((uint_t) task->text[task->idx]);
} else if(charset == FRISO_GBK) {
@ -60,8 +57,7 @@ FRISO_API int friso_numeric_letter(
//check if the specified word is aa english letter.
FRISO_API int friso_en_letter(
friso_charset_t charset,
friso_task_t task )
{
friso_task_t task) {
if(charset == FRISO_UTF8) {
return utf8_en_letter((uint_t) task->text[task->idx]);
} else if(charset == FRISO_GBK) {
@ -75,8 +71,7 @@ FRISO_API int friso_en_letter(
// punctuations are inclued.
FRISO_API int friso_halfwidth_en_char(
friso_charset_t charset,
friso_task_t task )
{
friso_task_t task) {
if(charset == FRISO_UTF8) {
return utf8_halfwidth_en_char(task->unicode);
} else if(charset == FRISO_GBK) {
@ -90,8 +85,7 @@ FRISO_API int friso_halfwidth_en_char(
// full-width punctuations are not included.
FRISO_API int friso_fullwidth_en_char(
friso_charset_t charset,
friso_task_t task )
{
friso_task_t task) {
if(charset == FRISO_UTF8) {
return utf8_fullwidth_en_char(task->unicode);
} else if(charset == FRISO_GBK) {
@ -104,8 +98,7 @@ FRISO_API int friso_fullwidth_en_char(
//check if the specified word is an english punctuations.
FRISO_API int friso_en_punctuation(
friso_charset_t charset,
friso_task_t task )
{
friso_task_t task) {
if(charset == FRISO_UTF8) {
return utf8_en_punctuation(task->unicode);
} else if(charset == FRISO_GBK) {
@ -118,8 +111,7 @@ FRISO_API int friso_en_punctuation(
//check if the specified word ia sn chinese punctuation.
FRISO_API int friso_cn_punctuation(
friso_charset_t charset,
friso_task_t task )
{
friso_task_t task) {
if(charset == FRISO_UTF8) {
return utf8_cn_punctuation(task->unicode);
} else if(charset == FRISO_GBK) {
@ -131,15 +123,13 @@ FRISO_API int friso_cn_punctuation(
FRISO_API int friso_letter_number(
friso_charset_t charset,
friso_task_t task )
{
friso_task_t task) {
return 0;
}
FRISO_API int friso_other_number(
friso_charset_t charset,
friso_task_t task )
{
friso_task_t task) {
return 0;
}
@ -159,8 +149,7 @@ FRISO_API int friso_other_number(
//check if the specified char is en english punctuation.
// this function is the same as friso_en_punctuation.
FRISO_API int is_en_punctuation(
friso_charset_t charset, char c )
{
friso_charset_t charset, char c) {
if(charset == FRISO_UTF8) {
return utf8_en_punctuation((uint_t) c);
} else if(charset == FRISO_GBK) {
@ -173,8 +162,7 @@ FRISO_API int is_en_punctuation(
//check the specified string is make up with numeric.
FRISO_API int friso_numeric_string(
friso_charset_t charset,
char *buffer )
{
char *buffer) {
if(charset == FRISO_UTF8) {
return utf8_numeric_string(buffer);
} else if(charset == FRISO_GBK) {
@ -186,8 +174,7 @@ FRISO_API int friso_numeric_string(
//check the specified string is a decimal string.
FRISO_API int friso_decimal_string(
friso_charset_t charset, char *buffer )
{
friso_charset_t charset, char *buffer) {
if(charset == FRISO_UTF8) {
return utf8_decimal_string(buffer);
} else if(charset == FRISO_GBK) {
@ -201,8 +188,7 @@ FRISO_API int friso_decimal_string(
// included full-width and half-width letters.
FRISO_API int friso_uppercase_letter(
friso_charset_t charset,
friso_task_t task )
{
friso_task_t task) {
if(charset == FRISO_UTF8) {
return utf8_uppercase_letter(task->unicode);
} else if(charset == FRISO_GBK) {
@ -218,8 +204,7 @@ FRISO_API int friso_uppercase_letter(
*/
FRISO_API friso_enchar_t friso_enchar_type(
friso_charset_t charset,
friso_task_t task )
{
friso_task_t task) {
//Unicode or ASCII.(Both UTF-8 and GBK are valid)
uint_t u = 0;
@ -245,8 +230,7 @@ FRISO_API friso_enchar_t friso_enchar_type(
* the type will be the constants defined above.
* (the char should be half-width english char only)
*/
FRISO_API friso_enchar_t get_enchar_type( char ch )
{
FRISO_API friso_enchar_t get_enchar_type(char ch) {
uint_t u = (uchar_t) ch;
//range check.

View File

@ -16,8 +16,7 @@
/* ************************
* mapping function area *
**************************/
__STATIC_API__ uint_t hash( fstring str, uint_t length )
{
__STATIC_API__ uint_t hash(fstring str, uint_t length) {
//hash code
uint_t h = 0;
@ -29,8 +28,7 @@ __STATIC_API__ uint_t hash( fstring str, uint_t length )
}
/*test if a integer is a prime.*/
__STATIC_API__ int is_prime( int n )
{
__STATIC_API__ int is_prime(int n) {
int j;
if(n == 2 || n == 3) {
return 1;
@ -50,8 +48,7 @@ __STATIC_API__ int is_prime( int n )
}
/*get the next prime just after the speicified integer.*/
__STATIC_API__ int next_prime( int n )
{
__STATIC_API__ int next_prime(int n) {
if(n % 2 == 0) n++;
for(; ! is_prime(n); n = n + 2) ;
@ -79,8 +76,7 @@ __STATIC_API__ int next_prime( int n )
__STATIC_API__ hash_entry_t new_hash_entry(
fstring key,
void * value,
hash_entry_t next )
{
hash_entry_t next) {
hash_entry_t e = (hash_entry_t)
FRISO_MALLOC(sizeof(friso_hash_entry));
if(e == NULL) {
@ -96,8 +92,7 @@ __STATIC_API__ hash_entry_t new_hash_entry(
}
//create blocks copy of entries.
__STATIC_API__ hash_entry_t * create_hash_entries( uint_t blocks )
{
__STATIC_API__ hash_entry_t * create_hash_entries(uint_t blocks) {
register uint_t t;
hash_entry_t *e = (hash_entry_t *)
FRISO_CALLOC(sizeof(hash_entry_t), blocks);
@ -113,8 +108,7 @@ __STATIC_API__ hash_entry_t * create_hash_entries( uint_t blocks )
}
//a static function to do the re-hash work.
__STATIC_API__ void rebuild_hash( friso_hash_t _hash )
{
__STATIC_API__ void rebuild_hash(friso_hash_t _hash) {
//printf("rehashed.\n");
//find the next prime as the length of the hashtable.
uint_t t, length = next_prime(_hash->length * 2 + 1);
@ -149,8 +143,7 @@ __STATIC_API__ void rebuild_hash( friso_hash_t _hash )
* ********************************/
//create a new hash table.
FRISO_API friso_hash_t new_hash_table( void )
{
FRISO_API friso_hash_t new_hash_table(void) {
friso_hash_t _hash = (friso_hash_t) FRISO_MALLOC(sizeof(friso_hash_cdt));
if(_hash == NULL) {
___ALLOCATION_ERROR___
@ -168,8 +161,7 @@ FRISO_API friso_hash_t new_hash_table( void )
FRISO_API void free_hash_table(
friso_hash_t _hash,
fhash_callback_fn_t fentry_func )
{
fhash_callback_fn_t fentry_func) {
register uint_t j;
hash_entry_t e, n;
@ -194,8 +186,7 @@ FRISO_API void free_hash_table(
FRISO_API void *hash_put_mapping(
friso_hash_t _hash,
fstring key,
void * value )
{
void * value) {
uint_t bucket = (key == NULL) ? 0 : hash(key, _hash->length);
hash_entry_t e = *(_hash->table + bucket);
void *oval = NULL;
@ -226,8 +217,7 @@ FRISO_API void *hash_put_mapping(
//check the existence of the mapping associated with the given key.
FRISO_API int hash_exist_mapping(
friso_hash_t _hash, fstring key )
{
friso_hash_t _hash, fstring key) {
uint_t bucket = (key == NULL) ? 0 : hash(key, _hash->length);
hash_entry_t e;
@ -244,8 +234,7 @@ FRISO_API int hash_exist_mapping(
}
//get the value associated with the given key.
FRISO_API void *hash_get_value( friso_hash_t _hash, fstring key )
{
FRISO_API void *hash_get_value(friso_hash_t _hash, fstring key) {
uint_t bucket = (key == NULL) ? 0 : hash(key, _hash->length);
hash_entry_t e;
@ -263,8 +252,7 @@ FRISO_API void *hash_get_value( friso_hash_t _hash, fstring key )
//remove the mapping associated with the given key.
FRISO_API hash_entry_t hash_remove_mapping(
friso_hash_t _hash, fstring key )
{
friso_hash_t _hash, fstring key) {
uint_t bucket = (key == NULL) ? 0 : hash(key, _hash->length);
hash_entry_t e, prev = NULL;
hash_entry_t b;

View File

@ -15,8 +15,7 @@
#define __FRISO_LEX_IFILE__ "friso.lex.ini"
//create a new lexicon
FRISO_API friso_dic_t friso_dic_new()
{
FRISO_API friso_dic_t friso_dic_new() {
register uint_t t;
friso_dic_t dic = (friso_dic_t) FRISO_CALLOC(
sizeof(friso_hash_t), __FRISO_LEXICON_LENGTH__);
@ -37,8 +36,7 @@ FRISO_API friso_dic_t friso_dic_new()
*
* @date 2013-06-12
*/
__STATIC_API__ void default_fdic_callback( hash_entry_t e )
{
__STATIC_API__ void default_fdic_callback(hash_entry_t e) {
register uint_t i;
friso_array_t syn;
lex_entry_t lex = (lex_entry_t) e->_val;
@ -58,8 +56,7 @@ __STATIC_API__ void default_fdic_callback( hash_entry_t e )
FRISO_FREE(lex);
}
FRISO_API void friso_dic_free( friso_dic_t dic )
{
FRISO_API void friso_dic_free(friso_dic_t dic) {
register uint_t t;
for(t = 0; t < __FRISO_LEXICON_LENGTH__; t++) {
//free the hash table
@ -76,8 +73,7 @@ FRISO_API lex_entry_t new_lex_entry(
friso_array_t syn,
uint_t fre,
uint_t length,
uint_t type )
{
uint_t type) {
lex_entry_t e = (lex_entry_t)
FRISO_MALLOC(sizeof(lex_entry_cdt));
if(e == NULL) {
@ -107,8 +103,7 @@ FRISO_API lex_entry_t new_lex_entry(
* 3. free its pos. (friso_array_t)
* 4. free the lex_entry_t.
*/
FRISO_API void free_lex_entry_full( lex_entry_t e )
{
FRISO_API void free_lex_entry_full(lex_entry_t e) {
register uint_t i;
friso_array_t syn;
@ -128,8 +123,7 @@ FRISO_API void free_lex_entry_full( lex_entry_t e )
FRISO_FREE(e);
}
FRISO_API void free_lex_entry( lex_entry_t e )
{
FRISO_API void free_lex_entry(lex_entry_t e) {
//if ( e->syn != NULL ) {
// if ( flag == 1 ) free_array_list( e->syn);
// else free_array_list( e->syn );
@ -144,8 +138,7 @@ FRISO_API void friso_dic_add(
friso_dic_t dic,
friso_lex_t lex,
fstring word,
friso_array_t syn )
{
friso_array_t syn) {
void *olex = NULL;
if(lex >= 0 && lex < __FRISO_LEXICON_LENGTH__) {
//printf("lex=%d, word=%s, syn=%s\n", lex, word, syn);
@ -163,8 +156,7 @@ FRISO_API void friso_dic_add_with_fre(
friso_lex_t lex,
fstring word,
friso_array_t syn,
uint_t frequency )
{
uint_t frequency) {
void *olex = NULL;
if(lex >= 0 && lex < __FRISO_LEXICON_LENGTH__) {
olex = hash_put_mapping(dic[lex], word,
@ -182,8 +174,7 @@ FRISO_API void friso_dic_add_with_fre(
*
* @date 2012-11-24
*/
FRISO_API fstring file_get_line( fstring __dst, FILE * _stream )
{
FRISO_API fstring file_get_line(fstring __dst, FILE * _stream) {
register int c;
fstring cs;
@ -204,8 +195,7 @@ FRISO_API fstring file_get_line( fstring __dst, FILE * _stream )
__STATIC_API__ fstring string_copy(
fstring _src,
fstring __dst,
uint_t blocks )
{
uint_t blocks) {
register fstring __src = _src;
register uint_t t;
@ -228,8 +218,7 @@ __STATIC_API__ fstring string_copy(
* @param blocks number of bytes to copy
*/
__STATIC_API__ fstring string_copy_heap(
fstring _src, uint_t blocks )
{
fstring _src, uint_t blocks) {
register uint_t t;
fstring str = (fstring) FRISO_MALLOC(blocks + 1);
@ -251,8 +240,7 @@ __STATIC_API__ fstring string_copy_heap(
* address of the char in the fstring will be return .
* if not found NULL will be return .
*/
__STATIC_API__ fstring indexOf( fstring __str, char delimiter )
{
__STATIC_API__ fstring indexOf(fstring __str, char delimiter) {
uint_t i, __length__;
__length__ = strlen(__str);
@ -278,8 +266,7 @@ FRISO_API void friso_dic_load(
friso_config_t config,
friso_lex_t lex,
fstring lex_file,
uint_t length )
{
uint_t length) {
FILE * _stream;
char __char[1024], _buffer[512];
@ -386,8 +373,7 @@ FRISO_API void friso_dic_load(
* @param _key
* @return int
*/
__STATIC_API__ friso_lex_t get_lexicon_type_with_constant( fstring _key )
{
__STATIC_API__ friso_lex_t get_lexicon_type_with_constant(fstring _key) {
if(strcmp(_key, "__LEX_CJK_WORDS__") == 0) {
return __LEX_CJK_WORDS__;
} else if(strcmp(_key, "__LEX_CJK_UNITS__") == 0) {
@ -430,8 +416,7 @@ FRISO_API void friso_dic_load_from_ifile(
friso_t friso,
friso_config_t config,
fstring _path,
uint_t _limits )
{
uint_t _limits) {
//1.parse the configuration file.
FILE *__stream;
@ -514,8 +499,7 @@ FRISO_API void friso_dic_load_from_ifile(
FRISO_API int friso_dic_match(
friso_dic_t dic,
friso_lex_t lex,
fstring word )
{
fstring word) {
if(lex >= 0 && lex < __FRISO_LEXICON_LENGTH__) {
return hash_exist_mapping(dic[lex], word);
}
@ -526,8 +510,7 @@ FRISO_API int friso_dic_match(
FRISO_API lex_entry_t friso_dic_get(
friso_dic_t dic,
friso_lex_t lex,
fstring word )
{
fstring word) {
if(lex >= 0 && lex < __FRISO_LEXICON_LENGTH__) {
return (lex_entry_t) hash_get_value(dic[lex], word);
}
@ -537,8 +520,7 @@ FRISO_API lex_entry_t friso_dic_get(
//get the size of the specified type dictionary.
FRISO_API uint_t friso_spec_dic_size(
friso_dic_t dic,
friso_lex_t lex )
{
friso_lex_t lex) {
if(lex >= 0 && lex < __FRISO_LEXICON_LENGTH__) {
return hash_get_size(dic[lex]);
}
@ -547,8 +529,7 @@ FRISO_API uint_t friso_spec_dic_size(
//get size of the whole dictionary.
FRISO_API uint_t friso_all_dic_size(
friso_dic_t dic )
{
friso_dic_t dic) {
register uint_t size = 0, t;
for(t = 0; t < __FRISO_LEXICON_LENGTH__; t++) {

View File

@ -13,8 +13,7 @@
__STATIC_API__ link_node_t new_node_entry(
void * value,
link_node_t prev,
link_node_t next )
{
link_node_t next) {
link_node_t node = (link_node_t)
FRISO_MALLOC(sizeof(link_node_entry));
if(node == NULL) {
@ -29,8 +28,7 @@ __STATIC_API__ link_node_t new_node_entry(
}
//create a new link list
FRISO_API friso_link_t new_link_list( void )
{
FRISO_API friso_link_t new_link_list(void) {
friso_link_t e = (friso_link_t)
FRISO_MALLOC(sizeof(friso_link_entry));
if(e == NULL) {
@ -47,8 +45,7 @@ FRISO_API friso_link_t new_link_list( void )
}
//free the given link list
FRISO_API void free_link_list( friso_link_t link )
{
FRISO_API void free_link_list(friso_link_t link) {
link_node_t node, next;
for(node = link->head; node != NULL;) {
next = node->next;
@ -61,12 +58,10 @@ FRISO_API void free_link_list( friso_link_t link )
//clear all nodes in the link list.
FRISO_API friso_link_t link_list_clear(
friso_link_t link )
{
friso_link_t link) {
link_node_t node, next;
//free all the middle nodes.
for ( node = link->head->next; node != link->tail; )
{
for(node = link->head->next; node != link->tail;) {
next = node->next;
FRISO_FREE(node);
node = next;
@ -95,13 +90,11 @@ FRISO_API friso_link_t link_list_clear(
* static
*/
__STATIC_API__ link_node_t get_node(
friso_link_t link, uint_t idx )
{
friso_link_t link, uint_t idx) {
link_node_t p = NULL;
register uint_t t;
if ( idx >= 0 && idx < link->size )
{
if(idx >= 0 && idx < link->size) {
if(idx < link->size / 2) { //find from the head.
p = link->head;
for(t = 0; t <= idx; t++)
@ -148,8 +141,7 @@ __STATIC_API__ link_node_t get_node(
* @return the value of the removed node.
*/
__STATIC_API__ void * remove_node(
friso_link_t link, link_node_t node )
{
friso_link_t link, link_node_t node) {
void * _value = node->value;
node->prev->next = node->next;
@ -164,15 +156,13 @@ __STATIC_API__ void * remove_node(
//add a new node to the link list.(insert just before the tail)
FRISO_API void link_list_add(
friso_link_t link, void * value )
{
friso_link_t link, void * value) {
insert_before(link, link->tail, value);
}
//add a new node before the given index.
FRISO_API void link_list_insert_before(
friso_link_t link, uint_t idx, void * value )
{
friso_link_t link, uint_t idx, void * value) {
link_node_t node = get_node(link, idx);
if(node != NULL) {
insert_before(link, node, value);
@ -185,8 +175,7 @@ FRISO_API void link_list_insert_before(
* @return the value of the node.
*/
FRISO_API void * link_list_get(
friso_link_t link, uint_t idx )
{
friso_link_t link, uint_t idx) {
link_node_t node = get_node(link, idx);
if(node != NULL) {
return node->value;
@ -203,8 +192,7 @@ FRISO_API void * link_list_get(
*/
FRISO_API void *link_list_set(
friso_link_t link,
uint_t idx, void * value )
{
uint_t idx, void * value) {
link_node_t node = get_node(link, idx);
void * _value = NULL;
@ -223,8 +211,7 @@ FRISO_API void *link_list_set(
* @return the value of the node removed.
*/
FRISO_API void *link_list_remove(
friso_link_t link, uint_t idx )
{
friso_link_t link, uint_t idx) {
link_node_t node = get_node(link, idx);
if(node != NULL) {
@ -243,15 +230,13 @@ FRISO_API void *link_list_remove(
*/
FRISO_API void *link_list_remove_node(
friso_link_t link,
link_node_t node )
{
link_node_t node) {
return remove_node(link, node);
}
//remove the first node after the head
FRISO_API void *link_list_remove_first(
friso_link_t link )
{
friso_link_t link) {
if(link->size > 0) {
return remove_node(link, link->head->next);
}
@ -260,8 +245,7 @@ FRISO_API void *link_list_remove_first(
//remove the last node just before the tail.
FRISO_API void *link_list_remove_last(
friso_link_t link )
{
friso_link_t link) {
if(link->size > 0) {
return remove_node(link, link->tail->prev);
}
@ -271,14 +255,12 @@ FRISO_API void *link_list_remove_last(
//append a node from the tail.
FRISO_API void link_list_add_last(
friso_link_t link,
void *value )
{
void *value) {
insert_before(link, link->tail, value);
}
//append a note just after the head.
FRISO_API void link_list_add_first(
friso_link_t link, void *value )
{
friso_link_t link, void *value) {
insert_before(link, link->head->next, value);
}

View File

@ -21,8 +21,7 @@
*
* @date: 2014-10-16
*/
__STATIC_API__ fstring create_buffer( uint_t length )
{
__STATIC_API__ fstring create_buffer(uint_t length) {
fstring buffer = (fstring) FRISO_MALLOC(length + 1);
if(buffer == NULL) {
___ALLOCATION_ERROR___
@ -35,8 +34,7 @@ __STATIC_API__ fstring create_buffer( uint_t length )
//the __allocs should not be smaller than sb->length
__STATIC_API__ string_buffer_t resize_buffer(
string_buffer_t sb, uint_t __allocs )
{
string_buffer_t sb, uint_t __allocs) {
//create a new buffer.
//if ( __allocs < sb->length ) __allocs = sb->length + 1;
fstring str = create_buffer(__allocs);
@ -61,8 +59,7 @@ __STATIC_API__ string_buffer_t resize_buffer(
//}
//create a new fstring buffer with the given opacity.
FRISO_API string_buffer_t new_string_buffer_with_opacity( uint_t opacity )
{
FRISO_API string_buffer_t new_string_buffer_with_opacity(uint_t opacity) {
string_buffer_t sb = (string_buffer_t)
FRISO_MALLOC(sizeof(string_buffer_entry));
if(sb == NULL) {
@ -77,8 +74,7 @@ FRISO_API string_buffer_t new_string_buffer_with_opacity( uint_t opacity )
}
//create a buffer with the given string.
FRISO_API string_buffer_t new_string_buffer_with_string( fstring str )
{
FRISO_API string_buffer_t new_string_buffer_with_string(fstring str) {
//buffer allocations.
string_buffer_t sb = (string_buffer_t)
FRISO_MALLOC(sizeof(string_buffer_entry));
@ -102,8 +98,7 @@ FRISO_API string_buffer_t new_string_buffer_with_string( fstring str )
}
FRISO_API void string_buffer_append(
string_buffer_t sb, fstring __str )
{
string_buffer_t sb, fstring __str) {
register uint_t __len__ = strlen(__str);
//check the necessity to resize the buffer.
@ -121,8 +116,7 @@ FRISO_API void string_buffer_append(
}
FRISO_API void string_buffer_append_char(
string_buffer_t sb, char ch )
{
string_buffer_t sb, char ch) {
//check the necessity to resize the buffer.
if(sb->length + 1 > sb->allocs) {
sb = resize_buffer(sb, sb->length * 2 + 1);
@ -134,8 +128,7 @@ FRISO_API void string_buffer_append_char(
FRISO_API void string_buffer_insert(
string_buffer_t sb,
uint_t idx,
fstring __str )
{
fstring __str) {
}
/*
@ -147,8 +140,7 @@ FRISO_API void string_buffer_insert(
FRISO_API fstring string_buffer_remove(
string_buffer_t sb,
uint_t idx,
uint_t length )
{
uint_t length) {
uint_t t;
//move the bytes after the idx + length
for(t = idx + length; t < sb->length; t++) {
@ -172,8 +164,7 @@ FRISO_API fstring string_buffer_remove(
* turn the string_buffer to a string.
* or return the buffer of the string_buffer.
*/
FRISO_API string_buffer_t string_buffer_trim( string_buffer_t sb )
{
FRISO_API string_buffer_t string_buffer_trim(string_buffer_t sb) {
//resize the buffer.
if(sb->length < sb->allocs - 1) {
sb = resize_buffer(sb, sb->length + 1);
@ -187,8 +178,7 @@ FRISO_API string_buffer_t string_buffer_trim( string_buffer_t sb )
* string_buffer_t->buffer, we return it to you, if there is
* a necessary you could free it youself by calling free();
*/
FRISO_API fstring string_buffer_devote( string_buffer_t sb )
{
FRISO_API fstring string_buffer_devote(string_buffer_t sb) {
fstring buffer = sb->buffer;
FRISO_FREE(sb);
return buffer;
@ -198,15 +188,13 @@ FRISO_API fstring string_buffer_devote( string_buffer_t sb )
* clear the given fstring buffer.
* reset its buffer with 0 and reset its length to 0.
*/
FRISO_API void string_buffer_clear( string_buffer_t sb )
{
FRISO_API void string_buffer_clear(string_buffer_t sb) {
memset(sb->buffer, 0x00, sb->length);
sb->length = 0;
}
//free everything of the fstring buffer.
FRISO_API void free_string_buffer( string_buffer_t sb )
{
FRISO_API void free_string_buffer(string_buffer_t sb) {
FRISO_FREE(sb->buffer);
FRISO_FREE(sb);
}
@ -220,8 +208,7 @@ FRISO_API void free_string_buffer( string_buffer_t sb )
*/
FRISO_API string_split_t new_string_split(
fstring delimiter,
fstring source )
{
fstring source) {
string_split_t e = (string_split_t)
FRISO_MALLOC(sizeof(string_split_entry));
if(e == NULL) {
@ -240,8 +227,7 @@ FRISO_API string_split_t new_string_split(
FRISO_API void string_split_reset(
string_split_t sst,
fstring delimiter,
fstring source )
{
fstring source) {
sst->delimiter = delimiter;
sst->delLen = strlen(delimiter);
sst->source = source;
@ -250,23 +236,20 @@ FRISO_API void string_split_reset(
}
FRISO_API void string_split_set_source(
string_split_t sst, fstring source )
{
string_split_t sst, fstring source) {
sst->source = source;
sst->srcLen = strlen(source);
sst->idx = 0;
}
FRISO_API void string_split_set_delimiter(
string_split_t sst, fstring delimiter )
{
string_split_t sst, fstring delimiter) {
sst->delimiter = delimiter;
sst->delLen = strlen(delimiter);
sst->idx = 0;
}
FRISO_API void free_string_split( string_split_t sst )
{
FRISO_API void free_string_split(string_split_t sst) {
FRISO_FREE(sst);
}
@ -280,8 +263,7 @@ FRISO_API void free_string_split( string_split_t sst )
* or there is no more segmentation)
*/
FRISO_API fstring string_split_next(
string_split_t sst, fstring __dst)
{
string_split_t sst, fstring __dst) {
uint_t i, _ok;
fstring _dst = __dst;

View File

@ -32,8 +32,7 @@ break;
println("+---------------------------------------------------------------+");
//read a line from a command line.
static fstring getLine( FILE *fp, fstring __dst )
{
static fstring getLine(FILE *fp, fstring __dst) {
register int c;
register fstring cs;
@ -57,8 +56,7 @@ static fstring getLine( FILE *fp, fstring __dst )
putchar('\n');
}*/
int main(int argc, char **argv)
{
int main(int argc, char **argv) {
clock_t s_time, e_time;
char line[__INPUT_LENGTH__] = {0};

View File

@ -12,8 +12,7 @@ void print_hash_info( friso_hash_t _hash ) {
_hash->size, _hash->factor, _hash->threshold);
}
int main(int argc, char **argv)
{
int main(int argc, char **argv) {
friso_hash_t _hash = new_hash_table();
char *names[] = {
"陈满文", "阳清华",

View File

@ -16,8 +16,7 @@
printf("3. other search the words in the dictionary.\n"); \
printf("4. quit exit the programe.\n");
int main(int argc, char **argv)
{
int main(int argc, char **argv) {
lex_entry_t e;
int lex = __LEX_CJK_WORDS__;
char _line[__LENGTH__];

View File

@ -8,8 +8,7 @@
#include <stdio.h>
#include <stdlib.h>
int main ( int argc, char **args )
{
int main(int argc, char **args) {
fstring source = ",I am a chinese,,my name is Lion,and i am the author of friso,bug report email chenxin619315@gmail.com,qq:1187582057";
char buffer[128];
string_split_t split = new_string_split(",", source);

View File

@ -23,8 +23,7 @@
static AppMatch *app_match_Class = nullptr;
AppMatch *AppMatch::getAppMatch()
{
AppMatch *AppMatch::getAppMatch() {
if(!app_match_Class) {
app_match_Class = new AppMatch;
}
@ -44,8 +43,7 @@ AppMatch::AppMatch(QObject *parent) : QThread(parent)
m_interFace = new QDBusInterface("com.kylin.softwarecenter.getsearchresults", "/com/kylin/softwarecenter/getsearchresults",
"com.kylin.getsearchresults",
QDBusConnection::sessionBus());
if (!m_interFace->isValid())
{
if(!m_interFace->isValid()) {
qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message());
}
qDebug() << "AppMatch is new";
@ -101,8 +99,7 @@ void AppMatch::getAllDesktopFilePath(QString path){
bool isDir = fileInfo.isDir();
if(isDir) {
getAllDesktopFilePath(fileInfo.filePath());
}
else{
} else {
//过滤LXQt、KDE
QString filePathStr = fileInfo.filePath();
if(filePathStr.contains("KDE", Qt::CaseInsensitive) ||
@ -112,8 +109,7 @@ void AppMatch::getAllDesktopFilePath(QString path){
continue;
}
//过滤后缀不是.desktop的文件
if(!filePathStr.endsWith(".desktop"))
{
if(!filePathStr.endsWith(".desktop")) {
i++;
continue;
}
@ -121,21 +117,17 @@ void AppMatch::getAllDesktopFilePath(QString path){
char* filepath = fpbyte.data();
g_key_file_load_from_file(keyfile, filepath, flags, nullptr);
char* ret_1 = g_key_file_get_locale_string(keyfile, "Desktop Entry", "NoDisplay", nullptr, nullptr);
if(ret_1!=nullptr)
{
if(ret_1 != nullptr) {
QString str = QString::fromLocal8Bit(ret_1);
if(str.contains("true"))
{
if(str.contains("true")) {
i++;
continue;
}
}
char* ret_2 = g_key_file_get_locale_string(keyfile, "Desktop Entry", "NotShowIn", nullptr, nullptr);
if(ret_2!=nullptr)
{
if(ret_2 != nullptr) {
QString str = QString::fromLocal8Bit(ret_2);
if(str.contains("UKUI"))
{
if(str.contains("UKUI")) {
i++;
continue;
}
@ -143,20 +135,16 @@ void AppMatch::getAllDesktopFilePath(QString path){
//过滤中英文名为空的情况
QLocale cn;
QString language = cn.languageToString(cn.language());
if(QString::compare(language,"Chinese")==0)
{
if(QString::compare(language, "Chinese") == 0) {
char* nameCh = g_key_file_get_string(keyfile, "Desktop Entry", "Name[zh_CN]", nullptr);
char* nameEn = g_key_file_get_string(keyfile, "Desktop Entry", "Name", nullptr);
if(QString::fromLocal8Bit(nameCh).isEmpty() && QString::fromLocal8Bit(nameEn).isEmpty())
{
if(QString::fromLocal8Bit(nameCh).isEmpty() && QString::fromLocal8Bit(nameEn).isEmpty()) {
i++;
continue;
}
}
else {
} else {
char* name = g_key_file_get_string(keyfile, "Desktop Entry", "Name", nullptr);
if(QString::fromLocal8Bit(name).isEmpty())
{
if(QString::fromLocal8Bit(name).isEmpty()) {
i++;
continue;
}
@ -181,8 +169,7 @@ void AppMatch::getAllDesktopFilePath(QString path){
* @brief AppMatch::getDesktopFilePath
*
*/
void AppMatch::getDesktopFilePath()
{
void AppMatch::getDesktopFilePath() {
m_filePathList.clear();
m_installAppMap.clear();
m_filePathList.append("/usr/share/applications/software-properties-livepatch.desktop");
@ -239,8 +226,7 @@ void AppMatch::getDesktopFilePath()
// }
}
void AppMatch::getAppName(QMap<NameString,QStringList> &installed)
{
void AppMatch::getAppName(QMap<NameString, QStringList> &installed) {
QMap<NameString, QStringList>::const_iterator i;
for(i = m_installAppMap.constBegin(); i != m_installAppMap.constEnd(); ++i) {
appNameMatch(i.key().app_name, installed);
@ -260,8 +246,7 @@ void AppMatch::appNameMatch(QString appname,QMap<NameString,QStringList> &instal
QStringList pinyinlist;
pinyinlist = FileUtils::findMultiToneWords(appname);
QMapIterator<NameString, QStringList> iter(m_installAppMap);
while(iter.hasNext())
{
while(iter.hasNext()) {
iter.next();
if(iter.key().app_name == appname) {
list = iter.value();
@ -303,12 +288,9 @@ void AppMatch::softWareCenterSearch(QMap<NameString,QStringList> &softwarereturn
void AppMatch::slotDBusCallFinished(QMap<NameString, QStringList> &softwarereturn) {
QDBusReply<QList<QMap<QString, QString>>> reply = m_interFace->call("get_search_result", m_sourceText); //阻塞,直到远程方法调用完成。
// QDBusPendingReply<QList<QMap<QString,QString>>> reply = *call;
if (reply.isValid())
{
if(reply.isValid()) {
parseSoftWareCenterReturn(reply.value(), softwarereturn);
}
else
{
} else {
qWarning() << "value method called failed!";
}
// call->deleteLater();

View File

@ -30,8 +30,7 @@
#include <QElapsedTimer>
#include <QThread>
class NameString
{
class NameString {
public:
explicit NameString(const QString &str_) : app_name(str_) {}
NameString() = default;
@ -52,8 +51,7 @@ public:
// }
//};
class AppMatch : public QThread
{
class AppMatch : public QThread {
Q_OBJECT
public:
static AppMatch *getAppMatch();

View File

@ -28,12 +28,10 @@ unsigned short FileUtils::_index_status = 0;
FileUtils::SearchMethod FileUtils::searchMethod = FileUtils::SearchMethod::DIRECTSEARCH;
QMap<QString, QStringList> FileUtils::map_chinese2pinyin = QMap<QString, QStringList>();
FileUtils::FileUtils()
{
FileUtils::FileUtils() {
}
std::string FileUtils::makeDocUterm(QString path)
{
std::string FileUtils::makeDocUterm(QString path) {
return QCryptographicHash::hash(path.toUtf8(), QCryptographicHash::Md5).toHex().toStdString();
}
@ -43,8 +41,7 @@ std::string FileUtils::makeDocUterm(QString path)
* @param checkValid
* @return
*/
QIcon FileUtils::getFileIcon(const QString &uri, bool checkValid)
{
QIcon FileUtils::getFileIcon(const QString &uri, bool checkValid) {
auto file = wrapGFile(g_file_new_for_uri(uri.toUtf8().constData()));
auto info = wrapGFileInfo(g_file_query_info(file.get()->get(),
G_FILE_ATTRIBUTE_STANDARD_ICON,
@ -181,8 +178,7 @@ QString FileUtils::getSettingName(const QString& setting) {
}
void FileUtils::loadHanziTable(const QString &fileName)
{
void FileUtils::loadHanziTable(const QString &fileName) {
QFile file(fileName);
if(!file.open(QFile::ReadOnly | QFile::Text)) {
qDebug("File: '%s' open failed!", file.fileName().toStdString().c_str());
@ -200,8 +196,7 @@ void FileUtils::loadHanziTable(const QString &fileName)
return;
}
QMimeType FileUtils::getMimetype(QString &path)
{
QMimeType FileUtils::getMimetype(QString &path) {
QMimeDatabase mdb;
QMimeType type = mdb.mimeTypeForFile(path, QMimeDatabase::MatchContent);
@ -209,8 +204,7 @@ QMimeType FileUtils::getMimetype(QString &path)
}
//aborted
QString FileUtils::find(const QString &hanzi)
{
QString FileUtils::find(const QString &hanzi) {
// static QMap<QString, QStringList> map = loadHanziTable("://index/pinyinWithoutTone.txt");
// static QMap<QString, QStringList> map;
QString output;
@ -238,8 +232,7 @@ void stitchMultiToneWordsDFS(const QString& hanzi, const QString& resultAllPinYi
for(auto i : FileUtils::map_chinese2pinyin[hanzi.at(0)]) {
stitchMultiToneWordsDFS(hanzi.right(hanzi.size() - 1), resultAllPinYin + i, resultFirst + i.at(0), resultList);
}
}
else{
} else {
stitchMultiToneWordsDFS(hanzi.right(hanzi.size() - 1), resultAllPinYin + hanzi.at(0), resultFirst + hanzi.at(0), resultList);
}
}
@ -254,8 +247,7 @@ void stitchMultiToneWordsBFSStack(const QString& hanzi, QStringList& resultList)
for(auto i : FileUtils::map_chinese2pinyin[tempHanzi.at(0)]) {
tempQueue.enqueue(i);
}
}
else{
} else {
tempQueue.enqueue(tempHanzi.at(0));
}
tempHanzi = tempHanzi.right(tempHanzi.size() - 1);
@ -268,8 +260,7 @@ void stitchMultiToneWordsBFSStack(const QString& hanzi, QStringList& resultList)
}
tempQueue.dequeue();
}
}
else{
} else {
for(int j = 0; j < tempQueueSize; ++j) {
tempQueue.enqueue(tempQueue.head() + tempHanzi.at(0));
tempQueue.dequeue();
@ -291,8 +282,7 @@ void stitchMultiToneWordsBFSHeap(const QString& hanzi, QStringList& resultList){
for(auto i : FileUtils::map_chinese2pinyin[tempHanzi.at(0)]) {
tempQueue->enqueue(i);
}
}
else{
} else {
tempQueue->enqueue(tempHanzi.at(0));
}
tempHanzi = tempHanzi.right(tempHanzi.size() - 1);
@ -305,8 +295,7 @@ void stitchMultiToneWordsBFSHeap(const QString& hanzi, QStringList& resultList){
}
tempQueue->dequeue();
}
}
else{
} else {
for(int j = 0; j < tempQueueSize; ++j) {
tempQueue->enqueue(tempQueue->head() + tempHanzi.at(0));
tempQueue->dequeue();
@ -342,8 +331,7 @@ void stitchMultiToneWordsBFSHeapLess3(const QString& hanzi, QStringList& resultL
if(FileUtils::map_chinese2pinyin.contains(i)) {
oneResult += FileUtils::map_chinese2pinyin[i].first();
oneResultFirst += FileUtils::map_chinese2pinyin[i].first().at(0);
}
else{
} else {
oneResult += i;
oneResultFirst += i;
}
@ -358,8 +346,7 @@ void stitchMultiToneWordsBFSHeapLess3(const QString& hanzi, QStringList& resultL
tempQueue->enqueue(i);
tempQueueFirst->enqueue(i.at(0));
}
}
else{
} else {
tempQueue->enqueue(tempHanzi.at(0));
tempQueueFirst->enqueue(tempHanzi.at(0));
}
@ -375,8 +362,7 @@ void stitchMultiToneWordsBFSHeapLess3(const QString& hanzi, QStringList& resultL
tempQueue->dequeue();
tempQueueFirst->dequeue();
}
}
else{
} else {
for(int j = 0; j < tempQueueSize; ++j) {
tempQueue->enqueue(tempQueue->head() + tempHanzi.at(0));
tempQueueFirst->enqueue(tempQueueFirst->head() + tempHanzi.at(0));
@ -418,8 +404,7 @@ void stitchMultiToneWordsBFSStackLess3(const QString& hanzi, QStringList& result
if(FileUtils::map_chinese2pinyin.contains(i)) {
oneResult += FileUtils::map_chinese2pinyin[i].first();
oneResultFirst += FileUtils::map_chinese2pinyin[i].first().at(0);
}
else{
} else {
oneResult += i;
oneResultFirst += i;
}
@ -434,8 +419,7 @@ void stitchMultiToneWordsBFSStackLess3(const QString& hanzi, QStringList& result
tempQueue.enqueue(i);
tempQueueFirst.enqueue(i.at(0));
}
}
else{
} else {
tempQueue.enqueue(tempHanzi.at(0));
tempQueueFirst.enqueue(tempHanzi.at(0));
}
@ -451,8 +435,7 @@ void stitchMultiToneWordsBFSStackLess3(const QString& hanzi, QStringList& result
tempQueue.dequeue();
tempQueueFirst.dequeue();
}
}
else{
} else {
for(int j = 0; j < tempQueueSize; ++j) {
tempQueue.enqueue(tempQueue.head() + tempHanzi.at(0));
tempQueueFirst.enqueue(tempQueueFirst.head() + tempHanzi.at(0));
@ -473,8 +456,7 @@ void stitchMultiToneWordsBFSStackLess3(const QString& hanzi, QStringList& result
return;
}
QStringList FileUtils::findMultiToneWords(const QString& hanzi)
{
QStringList FileUtils::findMultiToneWords(const QString& hanzi) {
// QStringList* output = new QStringList();
QStringList output;
QString tempAllPinYin, tempFirst;
@ -491,8 +473,7 @@ QStringList FileUtils::findMultiToneWords(const QString& hanzi)
* @param path: abs path
* @return docx to QString
*/
void FileUtils::getDocxTextContent(QString &path,QString &textcontent)
{
void FileUtils::getDocxTextContent(QString &path, QString &textcontent) {
//fix me :optimized by xpath??
QFileInfo info = QFileInfo(path);
if(!info.exists() || info.isDir())
@ -512,18 +493,14 @@ void FileUtils::getDocxTextContent(QString &path,QString &textcontent)
fileR.close();
QDomElement first = doc.firstChildElement("w:document");
QDomElement body = first.firstChildElement("w:body");
while(!body.isNull())
{
while(!body.isNull()) {
QDomElement wp = body.firstChildElement("w:p");
while(!wp.isNull())
{
while(!wp.isNull()) {
QDomElement wr = wp.firstChildElement("w:r");
while(!wr.isNull())
{
while(!wr.isNull()) {
QDomElement wt = wr.firstChildElement("w:t");
textcontent.append(wt.text().replace("\n", ""));
if(textcontent.length() >= MAX_CONTENT_LENGTH/3)
{
if(textcontent.length() >= MAX_CONTENT_LENGTH / 3) {
file.close();
return;
}
@ -537,8 +514,7 @@ void FileUtils::getDocxTextContent(QString &path,QString &textcontent)
return;
}
void FileUtils::getPptxTextContent(QString &path, QString &textcontent)
{
void FileUtils::getPptxTextContent(QString &path, QString &textcontent) {
QFileInfo info = QFileInfo(path);
if(!info.exists() || info.isDir())
return;
@ -547,8 +523,7 @@ void FileUtils::getPptxTextContent(QString &path, QString &textcontent)
return;
QString prefix("ppt/slides/slide");
QStringList fileList;
for(QString i : file.getFileNameList())
{
for(QString i : file.getFileNameList()) {
if(i.startsWith(prefix))
fileList << i;
}
@ -562,11 +537,9 @@ void FileUtils::getPptxTextContent(QString &path, QString &textcontent)
QDomDocument doc;
QDomElement at;
// QDomNodeList atList;
for(int i =0;i<fileList.size();++i)
{
for(int i = 0; i < fileList.size(); ++i) {
QString name = prefix + QString::number(i + 1) + ".xml";
if(!file.setCurrentFile(name))
{
if(!file.setCurrentFile(name)) {
continue;
}
QuaZipFile fileR(&file);
@ -595,24 +568,18 @@ void FileUtils::getPptxTextContent(QString &path, QString &textcontent)
// }
//This is ugly but seems more efficient when handel a large file.
sptree = doc.firstChildElement("p:sld").firstChildElement("p:cSld").firstChildElement("p:spTree");
while(!sptree.isNull())
{
while(!sptree.isNull()) {
sp = sptree.firstChildElement("p:sp");
while(!sp.isNull())
{
while(!sp.isNull()) {
txbody = sp.firstChildElement("p:txBody");
while(!txbody.isNull())
{
while(!txbody.isNull()) {
ap = txbody.firstChildElement("a:p");
while(!ap.isNull())
{
while(!ap.isNull()) {
ar = ap.firstChildElement("a:r");
while(!ar.isNull())
{
while(!ar.isNull()) {
at = ar.firstChildElement("a:t");
textcontent.append(at.text().replace("\r", "")).replace("\t", "");
if(textcontent.length() >= MAX_CONTENT_LENGTH/3)
{
if(textcontent.length() >= MAX_CONTENT_LENGTH / 3) {
file.close();
return;
}
@ -631,8 +598,7 @@ void FileUtils::getPptxTextContent(QString &path, QString &textcontent)
return;
}
void FileUtils::getXlsxTextContent(QString &path, QString &textcontent)
{
void FileUtils::getXlsxTextContent(QString &path, QString &textcontent) {
QFileInfo info = QFileInfo(path);
if(!info.exists() || info.isDir())
return;
@ -653,25 +619,19 @@ void FileUtils::getXlsxTextContent(QString &path, QString &textcontent)
QDomElement si;
QDomElement r;
QDomElement t;
while(!sst.isNull())
{
while(!sst.isNull()) {
si = sst.firstChildElement("si");
while(!si.isNull())
{
while(!si.isNull()) {
r = si.firstChildElement("r");
if(r.isNull())
{
if(r.isNull()) {
t = si.firstChildElement("t");
}
else
{
} else {
t = r.firstChildElement("t");
}
if(t.isNull())
continue;
textcontent.append(t.text().replace("\r", "").replace("\n", ""));
if(textcontent.length() >= MAX_CONTENT_LENGTH/3)
{
if(textcontent.length() >= MAX_CONTENT_LENGTH / 3) {
file.close();
return;
}
@ -683,15 +643,13 @@ void FileUtils::getXlsxTextContent(QString &path, QString &textcontent)
return;
}
void FileUtils::getPdfTextContent(QString &path, QString &textcontent)
{
void FileUtils::getPdfTextContent(QString &path, QString &textcontent) {
Poppler::Document *doc = Poppler::Document::load(path);
if(doc->isLocked())
return;
const QRectF qf;
int pageNum = doc->numPages();
for(int i = 0; i<pageNum; ++i)
{
for(int i = 0; i < pageNum; ++i) {
textcontent.append(doc->page(i)->text(qf).replace("\n", ""));
if(textcontent.length() >= MAX_CONTENT_LENGTH / 3)
break;
@ -700,8 +658,7 @@ void FileUtils::getPdfTextContent(QString &path, QString &textcontent)
return;
}
void FileUtils::getTxtContent(QString &path, QString &textcontent)
{
void FileUtils::getTxtContent(QString &path, QString &textcontent) {
QFile file(path);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;

View File

@ -59,8 +59,7 @@
#define UKUI_SEARCH_PIPE_PATH (QDir::homePath()+"/.config/org.ukui/ukui-search/ukuisearch").toLocal8Bit().constData()
class LIBSEARCH_EXPORT FileUtils
{
class LIBSEARCH_EXPORT FileUtils {
public:
static std::string makeDocUterm(QString);
static QIcon getFileIcon(const QString &, bool checkValid = true);

View File

@ -25,16 +25,14 @@
static GlobalSettings *global_instance_of_global_settings = nullptr;
GlobalSettings *GlobalSettings::getInstance()
{
GlobalSettings *GlobalSettings::getInstance() {
if(!global_instance_of_global_settings) {
global_instance_of_global_settings = new GlobalSettings;
}
return global_instance_of_global_settings;
}
GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent)
{
GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent) {
m_settings = new QSettings(MAIN_SETTINGS, QSettings::IniFormat, this);
// m_settings->setAtomicSyncRequired(false);
m_block_dirs_settings = new QSettings(BLOCK_DIRS, QSettings::IniFormat, this);
@ -42,8 +40,7 @@ GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent)
m_search_record_settings = new QSettings(SEARCH_HISTORY, QSettings::IniFormat, this);
m_search_record_settings->setIniCodec(QTextCodec::codecForName("UTF-8"));
for(QString i:m_search_record_settings->allKeys())
{
for(QString i : m_search_record_settings->allKeys()) {
m_history.append(QUrl::fromPercentEncoding(i.toLocal8Bit()));
}
if(!QDBusConnection::sessionBus().connect("org.kylinssoclient.dbus",
@ -94,18 +91,15 @@ GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent)
}
}
const QVariant GlobalSettings::getValue(const QString &key)
{
const QVariant GlobalSettings::getValue(const QString &key) {
return m_cache.value(key);
}
bool GlobalSettings::isExist(const QString &key)
{
bool GlobalSettings::isExist(const QString &key) {
return !m_cache.value(key).isNull();
}
void GlobalSettings::reset(const QString &key)
{
void GlobalSettings::reset(const QString &key) {
m_cache.remove(key);
QtConcurrent::run([ = ]() {
// if (m_mutex.tryLock(1000)) {
@ -117,8 +111,7 @@ void GlobalSettings::reset(const QString &key)
Q_EMIT this->valueChanged(key);
}
void GlobalSettings::resetAll()
{
void GlobalSettings::resetAll() {
QStringList tmp = m_cache.keys();
m_cache.clear();
for(auto key : tmp) {
@ -133,12 +126,9 @@ void GlobalSettings::resetAll()
});
}
bool GlobalSettings::setBlockDirs(const QString &path, int &returnCode, bool remove)
{
if(remove)
{
if(path.isEmpty())
{
bool GlobalSettings::setBlockDirs(const QString &path, int &returnCode, bool remove) {
if(remove) {
if(path.isEmpty()) {
returnCode = PATH_EMPTY;
return false;
}
@ -146,8 +136,7 @@ bool GlobalSettings::setBlockDirs(const QString &path, int &returnCode, bool rem
m_block_dirs_settings->remove(path);
return true;
}
if(!path.startsWith("/home"))
{
if(!path.startsWith("/home")) {
// returnCode = QString(tr("I can only search your user directory, it doesn't make any sense if you block an directory which is not in user directory!"));
returnCode = PATH_NOT_IN_HOME;
return false;
@ -157,10 +146,8 @@ bool GlobalSettings::setBlockDirs(const QString &path, int &returnCode, bool rem
QString pathKey = path.right(path.length() - 1);
QStringList blockDirs = m_block_dirs_settings->allKeys();
for(QString i:blockDirs)
{
if(pathKey.startsWith(i))
{
for(QString i : blockDirs) {
if(pathKey.startsWith(i)) {
// returnCode = QString(tr("My parent folder has been blocked!"));
returnCode = PATH_PARENT_BLOCKED;
return false;
@ -173,8 +160,7 @@ bool GlobalSettings::setBlockDirs(const QString &path, int &returnCode, bool rem
return true;
}
QStringList GlobalSettings::getBlockDirs()
{
QStringList GlobalSettings::getBlockDirs() {
return m_block_dirs_settings->allKeys();
}
@ -198,8 +184,7 @@ QStringList GlobalSettings::getBlockDirs()
// }
//}
void GlobalSettings::setSearchRecord(const QString &word, const QDateTime &time)
{
void GlobalSettings::setSearchRecord(const QString &word, const QDateTime &time) {
QStringList keys = m_search_record_settings->allKeys();
if(keys.contains(QString(QUrl::toPercentEncoding(word))))
m_history.removeOne(word);
@ -209,8 +194,7 @@ void GlobalSettings::setSearchRecord(const QString &word, const QDateTime &time)
m_history.append(word);
}
QStringList GlobalSettings::getSearchRecord()
{
QStringList GlobalSettings::getSearchRecord() {
return m_history;
}
@ -263,8 +247,7 @@ QStringList GlobalSettings::getSearchRecord()
//here should be override
//MouseZhangZh
void GlobalSettings::setValue(const QString &key, const QVariant &value)
{
void GlobalSettings::setValue(const QString &key, const QVariant &value) {
// qDebug()<<"setvalue========"<<key<<":"<<value;
m_cache.insert(key, value);
// m_settings->sync();
@ -281,8 +264,7 @@ void GlobalSettings::setValue(const QString &key, const QVariant &value)
});
}
void GlobalSettings::forceSync(const QString &key)
{
void GlobalSettings::forceSync(const QString &key) {
m_settings->sync();
if(key.isNull()) {
m_cache.clear();
@ -295,14 +277,11 @@ void GlobalSettings::forceSync(const QString &key)
}
}
void GlobalSettings::updateSearchHistory(QString key)
{
if(key == "search")
{
void GlobalSettings::updateSearchHistory(QString key) {
if(key == "search") {
m_search_record_settings->sync();
m_history.clear();
for(QString i:m_search_record_settings->allKeys())
{
for(QString i : m_search_record_settings->allKeys()) {
m_history.append(QUrl::fromPercentEncoding(i.toLocal8Bit()));
}
}

View File

@ -56,8 +56,7 @@
//#define CLOUD_HISTORY "history"
//#define CLOUD_APPLICATIONS "applications"
class LIBSEARCH_EXPORT GlobalSettings : public QObject
{
class LIBSEARCH_EXPORT GlobalSettings : public QObject {
Q_OBJECT
public:
static GlobalSettings *getInstance();

View File

@ -25,8 +25,7 @@
template<class T>
class gobjecttemplate
{
class gobjecttemplate {
public:
//do not use this constructor.
gobjecttemplate();

View File

@ -27,14 +27,12 @@
//extern QList<Document> *_doc_list_path;
//extern QMutex _mutex_doc_list_path;
ConstructDocumentForPath::ConstructDocumentForPath(QVector<QString> list)
{
ConstructDocumentForPath::ConstructDocumentForPath(QVector<QString> list) {
this->setAutoDelete(true);
m_list = std::move(list);
}
void ConstructDocumentForPath::run()
{
void ConstructDocumentForPath::run() {
// qDebug()<<"ConstructDocumentForPath";
if(!_doc_list_path)
_doc_list_path = new QList<Document>;
@ -72,19 +70,16 @@ void ConstructDocumentForPath::run()
// temp.append(index_text);
temp.append(pinyin_text_list)*/;
int postingCount = 0;
while(postingCount < index_text.size())
{
while(postingCount < index_text.size()) {
// QVector<size_t> p;
// p.append(postingCount);
doc.addPosting(QUrl::toPercentEncoding(index_text.at(postingCount)).toStdString(), postingCount);
++postingCount;
}
int i = 0;
for (QString& s : pinyin_text_list)
{
for(QString& s : pinyin_text_list) {
i = 0;
while(i < s.size())
{
while(i < s.size()) {
doc.addPosting(QUrl::toPercentEncoding(s.at(i)).toStdString(), postingCount);
++postingCount;
++i;
@ -99,14 +94,12 @@ void ConstructDocumentForPath::run()
return;
}
ConstructDocumentForContent::ConstructDocumentForContent(QString path)
{
ConstructDocumentForContent::ConstructDocumentForContent(QString path) {
this->setAutoDelete(true);
m_path = std::move(path);
}
void ConstructDocumentForContent::run()
{
void ConstructDocumentForContent::run() {
// qDebug() << "ConstructDocumentForContent currentThreadId()" << QThread::currentThreadId();
// 构造文本索引的document
if(!_doc_list_content)
@ -125,8 +118,7 @@ void ConstructDocumentForContent::run()
doc.setUniqueTerm(uniqueterm);
doc.addTerm(upTerm);
doc.addValue(m_path);
for(int i = 0;i<term.size();++i)
{
for(int i = 0; i < term.size(); ++i) {
doc.addPosting(term.at(i).word, term.at(i).offsets, static_cast<int>(term.at(i).weight));
}

View File

@ -28,8 +28,7 @@
//extern QList<Document> *_doc_list_path;
//extern QMutex _mutex_doc_list_path;
class IndexGenerator;
class ConstructDocumentForPath : public QRunnable
{
class ConstructDocumentForPath : public QRunnable {
public:
explicit ConstructDocumentForPath(QVector<QString> list);
~ConstructDocumentForPath() = default;
@ -39,8 +38,7 @@ private:
QVector<QString> m_list;
};
class ConstructDocumentForContent : public QRunnable
{
class ConstructDocumentForContent : public QRunnable {
public:
explicit ConstructDocumentForContent(QString path);
~ConstructDocumentForContent() = default;

View File

@ -20,28 +20,24 @@
#include "document.h"
#include <QDebug>
void Document::setData(QString data)
{
void Document::setData(QString data) {
if(data.isEmpty())
return;
m_document.set_data(data.toStdString());
}
void Document::addPosting(std::string term,QVector<size_t> offset, int weight)
{
void Document::addPosting(std::string term, QVector<size_t> offset, int weight) {
if(term == "")
return;
if(term.length() > 240)
term = QString::fromStdString(term).left(30).toStdString();
for(size_t i : offset)
{
for(size_t i : offset) {
m_document.add_posting(term, i, weight);
}
}
void Document::addPosting(std::string term, unsigned int offset, int weight)
{
void Document::addPosting(std::string term, unsigned int offset, int weight) {
if(term == "")
return;
if(term.length() > 240)
@ -50,20 +46,17 @@ void Document::addPosting(std::string term, unsigned int offset, int weight)
m_document.add_posting(term, offset, weight);
}
void Document::addTerm(QString term)
{
void Document::addTerm(QString term) {
if(term.isEmpty())
return;
m_document.add_term(term.toStdString());
}
void Document::addValue(QString value)
{
void Document::addValue(QString value) {
m_document.add_value(1, value.toStdString());
}
void Document::setUniqueTerm(QString term)
{
void Document::setUniqueTerm(QString term) {
if(term.isEmpty())
return;
m_document.add_term(term.toStdString());
@ -71,26 +64,22 @@ void Document::setUniqueTerm(QString term)
// m_unique_term = new QString(term);
m_unique_term = std::move(term);
}
std::string Document::getUniqueTerm()
{
std::string Document::getUniqueTerm() {
// qDebug()<<"m_unique_term!"<<*m_unique_term;
// qDebug() << QString::fromStdString(m_unique_term.toStdString());
return m_unique_term.toStdString();
}
void Document::setIndexText(QStringList indexText)
{
void Document::setIndexText(QStringList indexText) {
// QStringList indexTextList = indexText;
// m_index_text = new QStringList(indexText);
m_index_text = std::move(indexText);
}
QStringList Document::getIndexText()
{
QStringList Document::getIndexText() {
return m_index_text;
}
Xapian::Document Document::getXapianDocument()
{
Xapian::Document Document::getXapianDocument() {
return m_document;
}

View File

@ -25,8 +25,7 @@
#include <QStringList>
#include <QVector>
class Document
{
class Document {
public:
Document() = default;
~Document() {}

View File

@ -21,47 +21,35 @@
#include "file-utils.h"
#include "binary-parser.h"
FileReader::FileReader(QObject *parent) : QObject(parent)
{
FileReader::FileReader(QObject *parent) : QObject(parent) {
}
void FileReader::getTextContent(QString path, QString &textContent)
{
void FileReader::getTextContent(QString path, QString &textContent) {
QMimeType type = FileUtils::getMimetype(path);
QString name = type.name();
QFileInfo file(path);
QString strsfx = file.suffix();
if(name== "application/zip")
{
if(name == "application/zip") {
if(strsfx.endsWith("docx"))
FileUtils::getDocxTextContent(path, textContent);
if(strsfx.endsWith("pptx"))
FileUtils::getPptxTextContent(path, textContent);
if(strsfx.endsWith("xlsx"))
FileUtils::getXlsxTextContent(path, textContent);
}
else if(name == "text/plain")
{
} else if(name == "text/plain") {
if(strsfx.endsWith("txt"))
FileUtils::getTxtContent(path, textContent);
}
else if(type.inherits("application/msword") || type.name() == "application/x-ole-storage")
{
} else if(type.inherits("application/msword") || type.name() == "application/x-ole-storage") {
if(strsfx.endsWith("doc") || strsfx.endsWith("dot") || strsfx.endsWith("wps") || strsfx.endsWith("ppt") ||
strsfx.endsWith("pps") ||strsfx.endsWith("dps") || strsfx.endsWith("et") || strsfx.endsWith("xls"))
{
strsfx.endsWith("pps") || strsfx.endsWith("dps") || strsfx.endsWith("et") || strsfx.endsWith("xls")) {
KBinaryParser searchdata;
searchdata.RunParser(path, textContent);
}
}
else if(name == "application/pdf")
{
} else if(name == "application/pdf") {
if(strsfx.endsWith("pdf"))
FileUtils::getPdfTextContent(path, textContent);
}
else
{
} else {
qWarning() << "Unsupport format:[" << path << "][" << type.name() << "]";
}

View File

@ -23,8 +23,7 @@
#include <QObject>
#include <QFileInfo>
class FileReader : public QObject
{
class FileReader : public QObject {
Q_OBJECT
public:
explicit FileReader(QObject *parent = nullptr);

View File

@ -32,30 +32,23 @@ size_t FileSearcher::uniqueSymbol3 = 0;
QMutex FileSearcher::m_mutex1;
QMutex FileSearcher::m_mutex2;
QMutex FileSearcher::m_mutex3;
FileSearcher::FileSearcher(QObject *parent) : QObject(parent)
{
FileSearcher::FileSearcher(QObject *parent) : QObject(parent) {
}
FileSearcher::~FileSearcher()
{
FileSearcher::~FileSearcher() {
}
int FileSearcher::getCurrentIndexCount()
{
try
{
int FileSearcher::getCurrentIndexCount() {
try {
Xapian::Database db(INDEX_PATH);
return db.get_doccount();
}
catch(const Xapian::Error &e)
{
} catch(const Xapian::Error &e) {
qWarning() << QString::fromStdString(e.get_description());
return 0;
}
}
void FileSearcher::onKeywordSearch(QString keyword,QQueue<QString> *searchResultFile,QQueue<QString> *searchResultDir,QQueue<QPair<QString,QStringList>> *searchResultContent)
{
void FileSearcher::onKeywordSearch(QString keyword, QQueue<QString> *searchResultFile, QQueue<QString> *searchResultDir, QQueue<QPair<QString, QStringList>> *searchResultContent) {
m_mutex1.lock();
++uniqueSymbol1;
m_mutex1.unlock();
@ -78,8 +71,7 @@ void FileSearcher::onKeywordSearch(QString keyword,QQueue<QString> *searchResult
int num = 5;
int resultCount = 0;
int total = 0;
while(total < 100)
{
while(total < 100) {
resultCount = keywordSearchfile(uniqueSymbol1, keyword, "0", 1, begin, num);
if(resultCount == 0 || resultCount == -1)
break;
@ -97,8 +89,7 @@ void FileSearcher::onKeywordSearch(QString keyword,QQueue<QString> *searchResult
int num = 5;
int resultCount = 0;
int total = 0;
while(total<100)
{
while(total < 100) {
resultCount = keywordSearchfile(uniqueSymbol2, keyword, "1", 1, begin, num);
if(resultCount == 0 || resultCount == -1)
break;
@ -117,8 +108,7 @@ void FileSearcher::onKeywordSearch(QString keyword,QQueue<QString> *searchResult
int resultCount = 0;
int total = 0;
while(total<50)
{
while(total < 50) {
resultCount = keywordSearchContent(uniqueSymbol3, keyword, begin, num);
if(resultCount == 0 || resultCount == -1)
break;
@ -130,24 +120,19 @@ void FileSearcher::onKeywordSearch(QString keyword,QQueue<QString> *searchResult
// Q_EMIT this->resultContent(m_search_result_content);
}
int FileSearcher::keywordSearchfile(size_t uniqueSymbol, QString keyword, QString value, unsigned slot, int begin, int num)
{
try
{
int FileSearcher::keywordSearchfile(size_t uniqueSymbol, QString keyword, QString value, unsigned slot, int begin, int num) {
try {
qDebug() << "--keywordSearchfile start--";
Xapian::Database db(INDEX_PATH);
Xapian::Query query = creatQueryForFileSearch(keyword, db);
Xapian::Enquire enquire(db);
Xapian::Query queryFile;
if(!value.isEmpty())
{
if(!value.isEmpty()) {
std::string slotValue = value.toStdString();
Xapian::Query queryValue = Xapian::Query(Xapian::Query::OP_VALUE_RANGE, slot, slotValue, slotValue);
queryFile = Xapian::Query(Xapian::Query::OP_AND, query, queryValue);
}
else
{
} else {
queryFile = query;
}
@ -164,19 +149,15 @@ int FileSearcher::keywordSearchfile(size_t uniqueSymbol, QString keyword, QStrin
qDebug() << "--keywordSearchfile finish--";
return resultCount;
}
catch(const Xapian::Error &e)
{
} catch(const Xapian::Error &e) {
qWarning() << QString::fromStdString(e.get_description());
qDebug() << "--keywordSearchfile finish--";
return -1;
}
}
int FileSearcher::keywordSearchContent(size_t uniqueSymbol, QString keyword, int begin, int num)
{
try
{
int FileSearcher::keywordSearchContent(size_t uniqueSymbol, QString keyword, int begin, int num) {
try {
qDebug() << "--keywordSearchContent search start--";
Xapian::Database db(CONTENT_INDEX_PATH);
@ -188,8 +169,7 @@ int FileSearcher::keywordSearchContent(size_t uniqueSymbol, QString keyword, int
QVector<SKeyWord> sKeyWord = ChineseSegmentation::getInstance()->callSegement(keyword);
//Creat a query
std::string words;
for(int i=0;i<sKeyWord.size();i++)
{
for(int i = 0; i < sKeyWord.size(); i++) {
words.append(sKeyWord.at(i).word).append(" ");
}
Xapian::Query query = qp.parse_query(words);
@ -216,16 +196,13 @@ int FileSearcher::keywordSearchContent(size_t uniqueSymbol, QString keyword, int
qDebug() << "--keywordSearchContent search finish--";
return resultCount;
}
catch(const Xapian::Error &e)
{
} catch(const Xapian::Error &e) {
qWarning() << QString::fromStdString(e.get_description());
qDebug() << "--keywordSearchContent search finish--";
return -1;
}
}
Xapian::Query FileSearcher::creatQueryForFileSearch(QString keyword, Xapian::Database &db)
{
Xapian::Query FileSearcher::creatQueryForFileSearch(QString keyword, Xapian::Database &db) {
// Xapian::QueryParser qp;
// qp.set_default_op(Xapian::Query::OP_PHRASE);
// qp.set_database(db);
@ -241,8 +218,7 @@ Xapian::Query FileSearcher::creatQueryForFileSearch(QString keyword, Xapian::Dat
//Creat a query
// Xapian::Query queryPhrase = qp.parse_query(userInput.toStdString(),Xapian::QueryParser::FLAG_PHRASE|Xapian::QueryParser::FLAG_SYNONYM);
std::vector<Xapian::Query> v;
for(int i=0;i<userInput.size();i++)
{
for(int i = 0; i < userInput.size(); i++) {
v.push_back(Xapian::Query(QUrl::toPercentEncoding(userInput.at(i)).toStdString()));
// qDebug()<<QString::fromStdString(Xapian::Query(QString(userInput.at(i)).toStdString()).get_description());
}
@ -254,20 +230,17 @@ Xapian::Query FileSearcher::creatQueryForFileSearch(QString keyword, Xapian::Dat
return queryPhrase;
}
Xapian::Query FileSearcher::creatQueryForContentSearch(QString keyword, Xapian::Database &db)
{
Xapian::Query FileSearcher::creatQueryForContentSearch(QString keyword, Xapian::Database &db) {
}
int FileSearcher::getResult(size_t uniqueSymbol, Xapian::MSet &result, QString value)
{
int FileSearcher::getResult(size_t uniqueSymbol, Xapian::MSet &result, QString value) {
//QStringList *pathTobeDelete = new QStringList;
//Delete those path doc which is not already exist.
// QStringList searchResult = QStringList();
for (auto it = result.begin(); it != result.end(); ++it)
{
for(auto it = result.begin(); it != result.end(); ++it) {
Xapian::Document doc = it.get_document();
std::string data = doc.get_data();
Xapian::weight docScoreWeight = it.get_weight();
@ -279,24 +252,17 @@ int FileSearcher::getResult(size_t uniqueSymbol, Xapian::MSet &result, QString v
QFileInfo info(path);
if(!info.exists())
{
if(!info.exists()) {
// pathTobeDelete->append(QString::fromStdString(data));
qDebug() << path << "is not exist!!";
}
else
{
switch (value.toInt())
{
} else {
switch(value.toInt()) {
case 1:
m_mutex1.lock();
if(uniqueSymbol == FileSearcher::uniqueSymbol1)
{
if(uniqueSymbol == FileSearcher::uniqueSymbol1) {
m_search_result_dir->enqueue(path);
m_mutex1.unlock();
}
else
{
} else {
m_mutex1.unlock();
return -1;
}
@ -304,13 +270,10 @@ int FileSearcher::getResult(size_t uniqueSymbol, Xapian::MSet &result, QString v
break;
case 0:
m_mutex2.lock();
if(uniqueSymbol == FileSearcher::uniqueSymbol2)
{
if(uniqueSymbol == FileSearcher::uniqueSymbol2) {
m_search_result_file->enqueue(path);
m_mutex2.unlock();
}
else
{
} else {
m_mutex2.unlock();
return -1;
}
@ -327,8 +290,7 @@ int FileSearcher::getResult(size_t uniqueSymbol, Xapian::MSet &result, QString v
return 0;
}
int FileSearcher::getContentResult(size_t uniqueSymbol, Xapian::MSet &result, std::string &keyWord)
{
int FileSearcher::getContentResult(size_t uniqueSymbol, Xapian::MSet &result, std::string &keyWord) {
//QStringList *pathTobeDelete = new QStringList;
//Delete those path doc which is not already exist.
@ -339,8 +301,7 @@ int FileSearcher::getContentResult(size_t uniqueSymbol, Xapian::MSet &result, st
totalSize = 5;
// QMap<QString,QStringList> searchResult;
for (auto it = result.begin(); it != result.end(); ++it)
{
for(auto it = result.begin(); it != result.end(); ++it) {
Xapian::Document doc = it.get_document();
std::string data = doc.get_data();
double docScoreWeight = it.get_weight();
@ -352,8 +313,7 @@ int FileSearcher::getContentResult(size_t uniqueSymbol, Xapian::MSet &result, st
QFileInfo info(path);
if(!info.exists())
{
if(!info.exists()) {
// pathTobeDelete->append(QString::fromStdString(data));
qDebug() << path << "is not exist!!";
continue;
@ -363,8 +323,7 @@ int FileSearcher::getContentResult(size_t uniqueSymbol, Xapian::MSet &result, st
auto term = doc.termlist_begin();
term.skip_to(wordTobeFound.toStdString());
int count = 0;
for(auto pos = term.positionlist_begin();pos != term.positionlist_end()&&count < 6;++pos)
{
for(auto pos = term.positionlist_begin(); pos != term.positionlist_end() && count < 6; ++pos) {
QByteArray snippetByte = QByteArray::fromStdString(data);
QString snippet = "..." + QString(snippetByte.left(*pos)).right(size + totalSize) + QString(snippetByte.mid(*pos, -1)).left(size + totalSize) + "...";
// qDebug()<<snippet;
@ -372,14 +331,11 @@ int FileSearcher::getContentResult(size_t uniqueSymbol, Xapian::MSet &result, st
++count;
}
m_mutex3.lock();
if(uniqueSymbol == FileSearcher::uniqueSymbol3)
{
if(uniqueSymbol == FileSearcher::uniqueSymbol3) {
m_search_result_content->enqueue(qMakePair(path, snippets));
m_mutex3.unlock();
}
else
{
} else {
m_mutex3.unlock();
return -1;
}
@ -391,11 +347,9 @@ int FileSearcher::getContentResult(size_t uniqueSymbol, Xapian::MSet &result, st
return 0;
}
bool FileSearcher::isBlocked(QString &path)
{
bool FileSearcher::isBlocked(QString &path) {
QStringList blockList = GlobalSettings::getInstance()->getBlockDirs();
for(QString i : blockList)
{
for(QString i : blockList) {
if(path.startsWith(i.prepend("/")))
return true;
}

View File

@ -32,8 +32,7 @@
#define CONTENT_INDEX_PATH (QStandardPaths::writableLocation(QStandardPaths::HomeLocation)+"/.config/org.ukui/ukui-search/content_index_data").toStdString()
class FileSearcher : public QObject
{
class FileSearcher : public QObject {
Q_OBJECT
public:
explicit FileSearcher(QObject *parent = nullptr);

View File

@ -25,12 +25,10 @@
#define NEW_QUEUE(a) a = new QQueue<QString>(); qDebug("---------------------------%s %s %s new at %d..",__FILE__,__FUNCTION__,#a,__LINE__);
//#define DELETE_QUEUE(a )
FirstIndex::FirstIndex()
{
FirstIndex::FirstIndex() {
}
FirstIndex::~FirstIndex()
{
FirstIndex::~FirstIndex() {
qDebug() << "~FirstIndex";
if(this->q_index)
delete this->q_index;
@ -62,8 +60,7 @@ void FirstIndex::run(){
unlink(UKUI_SEARCH_PIPE_PATH);
int retval = mkfifo(UKUI_SEARCH_PIPE_PATH, 0777);
if(retval == -1)
{
if(retval == -1) {
qCritical() << "creat fifo error!!";
syslog(LOG_ERR, "creat fifo error!!\n");
assert(false);
@ -82,14 +79,12 @@ void FirstIndex::run(){
/* || contentIndexDataBaseStatus == ""*/
if(indexDataBaseStatus == "") {
this->bool_dataBaseExist = false;
}
else{
} else {
this->bool_dataBaseExist = true;
}
if(indexDataBaseStatus != "2" || contentIndexDataBaseStatus != "2" || inotifyIndexStatus != "2") {
this->bool_dataBaseStatusOK = false;
}
else{
} else {
this->bool_dataBaseStatusOK = true;
}
@ -104,8 +99,7 @@ void FirstIndex::run(){
buffer[0] = 0x1;
buffer[1] = '\0';
fifo_fd = open(UKUI_SEARCH_PIPE_PATH, O_RDWR);
if(fifo_fd == -1)
{
if(fifo_fd == -1) {
perror("open fifo error\n");
assert(false);
}
@ -119,21 +113,18 @@ void FirstIndex::run(){
pid_t pid;
pid = fork();
if(pid == 0)
{
if(pid == 0) {
prctl(PR_SET_PDEATHSIG, SIGTERM);
prctl(PR_SET_NAME, "first-index");
if(this->bool_dataBaseExist) {
if(this->bool_dataBaseStatusOK) {
::_exit(0);
}
else{
} else {
//if the parameter is false, index won't be rebuild
//if it is true, index will be rebuild
p_indexGenerator = IndexGenerator::getInstance(true, this);
}
}
else{
} else {
// p_indexGenerator = IndexGenerator::getInstance(false,this);
p_indexGenerator = IndexGenerator::getInstance(true, this);
@ -206,13 +197,9 @@ void FirstIndex::run(){
p_indexGenerator = nullptr;
// GlobalSettings::getInstance()->forceSync();
::_exit(0);
}
else if(pid < 0)
{
} else if(pid < 0) {
qWarning() << "First Index fork error!!";
}
else
{
} else {
waitpid(pid, NULL, 0);
--FileUtils::_index_status;
}
@ -220,8 +207,7 @@ void FirstIndex::run(){
GlobalSettings::getInstance()->setValue(INOTIFY_NORMAL_EXIT, "2");
int retval1 = write(fifo_fd, buffer, strlen(buffer));
if(retval1 == -1)
{
if(retval1 == -1) {
qWarning("write error\n");
}
qDebug("write data ok!\n");

View File

@ -42,8 +42,7 @@
#include "inotify-index.h"
#include "file-utils.h"
class FirstIndex : public QThread, public Traverse_BFS
{
class FirstIndex : public QThread, public Traverse_BFS {
public:
FirstIndex();
~FirstIndex();

View File

@ -42,8 +42,7 @@ QList<Document> *_doc_list_path;
QMutex _mutex_doc_list_path;
QList<Document> *_doc_list_content;
QMutex _mutex_doc_list_content;
IndexGenerator *IndexGenerator::getInstance(bool rebuild, QObject *parent)
{
IndexGenerator *IndexGenerator::getInstance(bool rebuild, QObject *parent) {
QMutexLocker locker(&m_mutex);
if(!global_instance) {
qDebug() << "IndexGenerator=================";
@ -54,14 +53,12 @@ IndexGenerator *IndexGenerator::getInstance(bool rebuild, QObject *parent)
return global_instance;
}
bool IndexGenerator::setIndexdataPath()
{
bool IndexGenerator::setIndexdataPath() {
return true;
}
//文件名索引
bool IndexGenerator::creatAllIndex(QQueue<QVector<QString> > *messageList)
{
bool IndexGenerator::creatAllIndex(QQueue<QVector<QString> > *messageList) {
// FileUtils::_index_status |= 0x1;
// qDebug() << messageList->size();
HandlePathList(messageList);
@ -70,8 +67,7 @@ bool IndexGenerator::creatAllIndex(QQueue<QVector<QString> > *messageList)
}
qDebug() << "begin creatAllIndex";
GlobalSettings::getInstance()->setValue(INDEX_DATABASE_STATE, "0");
try
{
try {
// m_indexer = new Xapian::TermGenerator();
// m_indexer.set_database(*m_database_path);
//可以实现拼写纠正
@ -89,9 +85,7 @@ bool IndexGenerator::creatAllIndex(QQueue<QVector<QString> > *messageList)
// }
}
m_database_path->commit();
}
catch(const Xapian::Error &e)
{
} catch(const Xapian::Error &e) {
qWarning() << "creatAllIndex fail!" << QString::fromStdString(e.get_description());
//need a record
GlobalSettings::getInstance()->setValue(INDEX_DATABASE_STATE, "1");
@ -107,8 +101,7 @@ bool IndexGenerator::creatAllIndex(QQueue<QVector<QString> > *messageList)
return true;
}
//文件内容索引
bool IndexGenerator::creatAllIndex(QQueue<QString> *messageList)
{
bool IndexGenerator::creatAllIndex(QQueue<QString> *messageList) {
// FileUtils::_index_status |= 0x2;
HandlePathList(messageList);
qDebug() << "begin creatAllIndex for content";
@ -117,11 +110,9 @@ bool IndexGenerator::creatAllIndex(QQueue<QString> *messageList)
}
int size = _doc_list_content->size();
qDebug() << "begin creatAllIndex for content" << size;
if(!size == 0)
{
if(!size == 0) {
GlobalSettings::getInstance()->setValue(CONTENT_INDEX_DATABASE_STATE, "0");
try
{
try {
int count = 0;
for(auto i : *_doc_list_content) {
insertIntoContentDatabase(i);
@ -131,9 +122,7 @@ bool IndexGenerator::creatAllIndex(QQueue<QString> *messageList)
}
}
m_database_content->commit();
}
catch(const Xapian::Error &e)
{
} catch(const Xapian::Error &e) {
qWarning() << "creat content Index fail!" << QString::fromStdString(e.get_description());
GlobalSettings::getInstance()->setValue(CONTENT_INDEX_DATABASE_STATE, "1");
// FileUtils::_index_status &= ~0x2;
@ -151,27 +140,20 @@ bool IndexGenerator::creatAllIndex(QQueue<QString> *messageList)
}
IndexGenerator::IndexGenerator(bool rebuild, QObject *parent) : QObject(parent)
{
IndexGenerator::IndexGenerator(bool rebuild, QObject *parent) : QObject(parent) {
QDir database(QString::fromStdString(INDEX_PATH));
if(database.exists())
{
if(database.exists()) {
if(rebuild)
qDebug() << "remove" << database.removeRecursively();
}
else
{
} else {
qDebug() << "create index path" << database.mkpath(QString::fromStdString(INDEX_PATH));
}
database.setPath(QString::fromStdString(CONTENT_INDEX_PATH));
if(database.exists())
{
if(database.exists()) {
if(rebuild)
qDebug() << "remove" << database.removeRecursively();
}
else
{
} else {
qDebug() << "create content index path" << database.mkpath(QString::fromStdString(CONTENT_INDEX_PATH));
}
@ -179,8 +161,7 @@ IndexGenerator::IndexGenerator(bool rebuild, QObject *parent) : QObject(parent)
m_database_content = new Xapian::WritableDatabase(CONTENT_INDEX_PATH, Xapian::DB_CREATE_OR_OPEN);
}
IndexGenerator::~IndexGenerator()
{
IndexGenerator::~IndexGenerator() {
QMutexLocker locker(&m_mutex);
qDebug() << "~IndexGenerator";
if(m_database_path)
@ -216,8 +197,7 @@ IndexGenerator::~IndexGenerator()
qDebug() << "~IndexGenerator end";
}
void IndexGenerator::insertIntoDatabase(Document& doc)
{
void IndexGenerator::insertIntoDatabase(Document& doc) {
// qDebug()<< "--index start--";
Xapian::Document document = doc.getXapianDocument();
// m_indexer.set_document(document);
@ -235,16 +215,14 @@ void IndexGenerator::insertIntoDatabase(Document& doc)
return;
}
//#define fun(a) a=new ;printf()
void IndexGenerator::insertIntoContentDatabase(Document& doc)
{
void IndexGenerator::insertIntoContentDatabase(Document& doc) {
Xapian::docid innerId = m_database_content->replace_document(doc.getUniqueTerm(), doc.getXapianDocument());
// qDebug()<<"replace doc docid="<<static_cast<int>(innerId);
// qDebug()<< "--index finish--";
return;
}
void IndexGenerator::HandlePathList(QQueue<QVector<QString>> *messageList)
{
void IndexGenerator::HandlePathList(QQueue<QVector<QString>> *messageList) {
qDebug() << "Begin HandlePathList!";
qDebug() << messageList->size();
// qDebug()<<QString::number(quintptr(QThread::currentThreadId()));
@ -259,8 +237,7 @@ void IndexGenerator::HandlePathList(QQueue<QVector<QString>> *messageList)
pool.setMaxThreadCount(((QThread::idealThreadCount() - 1) / 2) + 1);
pool.setExpiryTimeout(100);
ConstructDocumentForPath *constructer;
while(!messageList->isEmpty())
{
while(!messageList->isEmpty()) {
constructer = new ConstructDocumentForPath(messageList->dequeue());
pool.start(constructer);
}
@ -280,8 +257,7 @@ void IndexGenerator::HandlePathList(QQueue<QVector<QString>> *messageList)
return;
}
void IndexGenerator::HandlePathList(QQueue<QString> *messageList)
{
void IndexGenerator::HandlePathList(QQueue<QString> *messageList) {
qDebug() << "Begin HandlePathList for content index!";
qDebug() << messageList->size();
// qDebug()<<QString::number(quintptr(QThread::currentThreadId()));
@ -291,8 +267,7 @@ void IndexGenerator::HandlePathList(QQueue<QString> *messageList)
// pool.setMaxThreadCount(((QThread::idealThreadCount() - 1) / 2) + 1);
pool.setMaxThreadCount(1);
pool.setExpiryTimeout(100);
while(!messageList->isEmpty())
{
while(!messageList->isEmpty()) {
constructer = new ConstructDocumentForContent(messageList->dequeue());
pool.start(constructer);
}
@ -321,8 +296,7 @@ void IndexGenerator::HandlePathList(QQueue<QString> *messageList)
}
Document IndexGenerator::GenerateDocument(const QVector<QString> &list)
{
Document IndexGenerator::GenerateDocument(const QVector<QString> &list) {
Document doc;
// qDebug()<<QString::number(quintptr(QThread::currentThreadId()));
//0-filename 1-filepathname 2-file or dir
@ -367,8 +341,7 @@ Document IndexGenerator::GenerateDocument(const QVector<QString> &list)
}
Document IndexGenerator::GenerateContentDocument(const QString &path)
{
Document IndexGenerator::GenerateContentDocument(const QString &path) {
// 构造文本索引的document
QString content;
QStringList tmp;
@ -386,8 +359,7 @@ Document IndexGenerator::GenerateContentDocument(const QString &path)
doc.setUniqueTerm(uniqueterm);
doc.addTerm(upTerm);
doc.addValue(path);
for(int i = 0;i<term.size();++i)
{
for(int i = 0; i < term.size(); ++i) {
doc.addPosting(term.at(i).word, term.at(i).offsets, static_cast<int>(term.at(i).weight));
}
@ -408,8 +380,7 @@ Document IndexGenerator::GenerateContentDocument(const QString &path)
return doc;
}
bool IndexGenerator::isIndexdataExist()
{
bool IndexGenerator::isIndexdataExist() {
// Xapian::Database db(m_index_data_path->toStdString());
return true;
@ -417,11 +388,9 @@ bool IndexGenerator::isIndexdataExist()
}
QStringList IndexGenerator::IndexSearch(QString indexText)
{
QStringList IndexGenerator::IndexSearch(QString indexText) {
QStringList searchResult;
try
{
try {
qDebug() << "--search start--";
Xapian::Database db(INDEX_PATH);
@ -439,8 +408,7 @@ QStringList IndexGenerator::IndexSearch(QString indexText)
//Creat a query
Xapian::Query queryPhrase = qp.parse_query(queryStr, Xapian::QueryParser::FLAG_PHRASE);
std::vector<Xapian::Query> v;
for(int i=0;i<userInput.size();i++)
{
for(int i = 0; i < userInput.size(); i++) {
v.push_back(Xapian::Query(QString(userInput.at(i)).toStdString()));
qDebug() << userInput.at(i);
qDebug() << QString::fromStdString(Xapian::Query(QString(userInput.at(i)).toStdString()).get_description());
@ -465,13 +433,10 @@ QStringList IndexGenerator::IndexSearch(QString indexText)
// QFileInfo *info = new QFileInfo(QString::fromStdString(data));
QFileInfo info(QString::fromStdString(data));
if(!info.exists())
{
if(!info.exists()) {
// pathTobeDelete->append(QString::fromStdString(data));
qDebug() << QString::fromStdString(data) << "is not exist!!";
}
else
{
} else {
searchResult.append(QString::fromStdString(data));
}
@ -482,9 +447,7 @@ QStringList IndexGenerator::IndexSearch(QString indexText)
// deleteAllIndex(pathTobeDelete);
qDebug() << "--search finish--";
}
catch(const Xapian::Error &e)
{
} catch(const Xapian::Error &e) {
qDebug() << QString::fromStdString(e.get_description());
}
return searchResult;
@ -555,17 +518,14 @@ QStringList IndexGenerator::IndexSearch(QString indexText)
// }
//}
bool IndexGenerator::deleteAllIndex(QStringList *pathlist)
{
bool IndexGenerator::deleteAllIndex(QStringList *pathlist) {
QStringList *list = pathlist;
if(list->isEmpty())
return true;
for(int i = 0;i<list->size();i++)
{
for(int i = 0; i < list->size(); i++) {
QString doc = list->at(i);
std::string uniqueterm = FileUtils::makeDocUterm(doc);
try
{
try {
qDebug() << "--delete start--";
m_database_path->delete_document(uniqueterm);
m_database_content->delete_document(uniqueterm);
@ -577,9 +537,7 @@ bool IndexGenerator::deleteAllIndex(QStringList *pathlist)
// qDebug()<<"m_database_path->get_lastdocid()!!!"<<m_database_path->get_lastdocid();
// qDebug()<<"m_database_path->get_doccount()!!!"<<m_database_path->get_doccount();
}
catch(const Xapian::Error &e)
{
} catch(const Xapian::Error &e) {
qWarning() << QString::fromStdString(e.get_description());
return false;
}

View File

@ -37,8 +37,7 @@ extern QMutex _mutex_doc_list_path;
extern QList<Document> *_doc_list_content;
extern QMutex _mutex_doc_list_content;
class IndexGenerator : public QObject
{
class IndexGenerator : public QObject {
Q_OBJECT
public:
static IndexGenerator *getInstance(bool rebuild = false, QObject *parent = nullptr);

View File

@ -46,8 +46,7 @@
CREATE_FILE_NAME_INDEX \
CREATE_FILE_CONTENT_INDEX
InotifyIndex::InotifyIndex(const QString& path) : Traverse_BFS(path)
{
InotifyIndex::InotifyIndex(const QString& path) : Traverse_BFS(path) {
qDebug() << "setInotifyMaxUserWatches start";
UkuiSearchQDBus usQDBus;
usQDBus.setInotifyMaxUserWatches();
@ -55,8 +54,7 @@ InotifyIndex::InotifyIndex(const QString& path) : Traverse_BFS(path)
}
InotifyIndex::~InotifyIndex()
{
InotifyIndex::~InotifyIndex() {
IndexGenerator::getInstance()->~IndexGenerator();
qWarning() << "~InotifyIndex";
}
@ -138,12 +136,10 @@ bool InotifyIndex::RemoveWatch(const QString &path, bool removeFromDatabase){
/*--------------------------------*/
currentPath.erase(i++);
// i++;
}
else{
} else {
i++;
}
}
else{
} else {
i++;
}
}
@ -163,12 +159,10 @@ bool InotifyIndex::RemoveWatch(const QString &path, bool removeFromDatabase){
// assert(ret == 0);
currentPath.erase(i++);
// i++;
}
else{
} else {
i++;
}
}
else{
} else {
i++;
}
}
@ -231,8 +225,7 @@ void InotifyIndex::eventProcess(const char* buf, ssize_t tmp){
// IndexGenerator::getInstance()->deleteAllIndex(new QStringList(currentPath[event->wd] + '/' + event->name));
CREATE_FILE
TRAVERSE_DIR
}
else {
} else {
IndexGenerator::getInstance()->deleteAllIndex(new QStringList(currentPath[event->wd] + '/' + event->name));
CREATE_FILE
}
@ -261,14 +254,12 @@ void InotifyIndex::run(){
char buffer[2];
memset(buffer, 0, sizeof(buffer));
fifo_fd = open(UKUI_SEARCH_PIPE_PATH, O_RDWR);
if(fifo_fd == -1)
{
if(fifo_fd == -1) {
perror("open fifo error\n");
assert(false);
}
int retval = read(fifo_fd, buffer, sizeof(buffer));
if(retval == -1)
{
if(retval == -1) {
perror("read error\n");
assert(false);
}
@ -317,8 +308,7 @@ void InotifyIndex::run(){
pid_t pid;
pid = fork();
if(pid == 0)
{
if(pid == 0) {
prctl(PR_SET_PDEATHSIG, SIGTERM);
prctl(PR_SET_NAME, "inotify-index");
if(numRead == 0) {
@ -336,8 +326,7 @@ void InotifyIndex::run(){
read_timeout->tv_sec = 40;
read_timeout->tv_usec = 0;
for(;;)
{
for(;;) {
FD_ZERO(&read_fds);
FD_SET(m_fd, &read_fds);
qDebug() << read_timeout->tv_sec;
@ -347,8 +336,7 @@ void InotifyIndex::run(){
qWarning() << "select result < 0, error!";
GlobalSettings::getInstance()->setValue(INOTIFY_NORMAL_EXIT, "1");
assert(false);
}
else if ( rc == 0 ) {
} else if(rc == 0) {
qDebug() << "select timeout!";
::free(read_timeout);
IndexGenerator::getInstance()->~IndexGenerator();
@ -368,13 +356,11 @@ void InotifyIndex::run(){
GlobalSettings::getInstance()->setValue(INOTIFY_NORMAL_EXIT, "2");
}
}
}
else if (pid > 0){
} else if(pid > 0) {
memset(buf, 0x00, BUF_LEN);
waitpid(pid, NULL, 0);
--FileUtils::_index_status;
}
else{
} else {
assert(false);
}
}

View File

@ -34,8 +34,7 @@
#define BUF_LEN 1024000
class InotifyIndex;
static InotifyIndex* global_instance_of_index = nullptr;
class InotifyIndex : public QThread, public Traverse_BFS
{
class InotifyIndex : public QThread, public Traverse_BFS {
Q_OBJECT
public:
static InotifyIndex* getInstance(const QString& path) {

View File

@ -25,18 +25,15 @@ size_t SearchManager::uniqueSymbol3 = 0;
QMutex SearchManager::m_mutex1;
QMutex SearchManager::m_mutex2;
QMutex SearchManager::m_mutex3;
SearchManager::SearchManager(QObject *parent) : QObject(parent)
{
SearchManager::SearchManager(QObject *parent) : QObject(parent) {
m_pool.setMaxThreadCount(2);
m_pool.setExpiryTimeout(1000);
}
SearchManager::~SearchManager()
{
SearchManager::~SearchManager() {
}
int SearchManager::getCurrentIndexCount()
{
int SearchManager::getCurrentIndexCount() {
try {
Xapian::Database db(INDEX_PATH);
return db.get_doccount();
@ -47,8 +44,7 @@ int SearchManager::getCurrentIndexCount()
}
void SearchManager::onKeywordSearch(QString keyword, QQueue<QString> *searchResultFile, QQueue<QString> *searchResultDir,
QQueue<QPair<QString,QStringList>> *searchResultContent)
{
QQueue<QPair<QString, QStringList>> *searchResultContent) {
m_mutex1.lock();
++uniqueSymbol1;
m_mutex1.unlock();
@ -81,11 +77,9 @@ void SearchManager::onKeywordSearch(QString keyword,QQueue<QString> *searchResul
return;
}
bool SearchManager::isBlocked(QString &path)
{
bool SearchManager::isBlocked(QString &path) {
QStringList blockList = GlobalSettings::getInstance()->getBlockDirs();
for(QString i : blockList)
{
for(QString i : blockList) {
if(path.startsWith(i.prepend("/")))
return true;
}
@ -93,8 +87,7 @@ bool SearchManager::isBlocked(QString &path)
}
FileSearch::FileSearch(QQueue<QString> *searchResult,size_t uniqueSymbol, QString keyword, QString value, unsigned slot, int begin, int num)
{
FileSearch::FileSearch(QQueue<QString> *searchResult, size_t uniqueSymbol, QString keyword, QString value, unsigned slot, int begin, int num) {
this->setAutoDelete(true);
m_search_result = searchResult;
m_uniqueSymbol = uniqueSymbol;
@ -105,13 +98,11 @@ FileSearch::FileSearch(QQueue<QString> *searchResult,size_t uniqueSymbol, QStrin
m_num = num;
}
FileSearch::~FileSearch()
{
FileSearch::~FileSearch() {
m_search_result = nullptr;
}
void FileSearch::run()
{
void FileSearch::run() {
if(!m_search_result->isEmpty()) {
m_search_result->clear();
}
@ -127,8 +118,7 @@ void FileSearch::run()
return;
}
int FileSearch::keywordSearchfile()
{
int FileSearch::keywordSearchfile() {
try {
qDebug() << "--keywordSearchfile start--";
Xapian::Database db(INDEX_PATH);
@ -164,8 +154,7 @@ int FileSearch::keywordSearchfile()
}
}
Xapian::Query FileSearch::creatQueryForFileSearch(Xapian::Database &db)
{
Xapian::Query FileSearch::creatQueryForFileSearch(Xapian::Database &db) {
auto userInput = m_keyword.toLower();
std::vector<Xapian::Query> v;
for(int i = 0; i < userInput.size(); i++) {
@ -176,8 +165,7 @@ Xapian::Query FileSearch::creatQueryForFileSearch(Xapian::Database &db)
return queryPhrase;
}
int FileSearch::getResult(Xapian::MSet &result)
{
int FileSearch::getResult(Xapian::MSet &result) {
for(auto it = result.begin(); it != result.end(); ++it) {
Xapian::Document doc = it.get_document();
std::string data = doc.get_data();
@ -230,8 +218,7 @@ int FileSearch::getResult(Xapian::MSet &result)
return 0;
}
FileContentSearch::FileContentSearch(QQueue<QPair<QString,QStringList>> *searchResult, size_t uniqueSymbol, QString keyword, int begin, int num)
{
FileContentSearch::FileContentSearch(QQueue<QPair<QString, QStringList>> *searchResult, size_t uniqueSymbol, QString keyword, int begin, int num) {
this->setAutoDelete(true);
m_search_result = searchResult;
m_uniqueSymbol = uniqueSymbol;
@ -240,13 +227,11 @@ FileContentSearch::FileContentSearch(QQueue<QPair<QString,QStringList>> *searchR
m_num = num;
}
FileContentSearch::~FileContentSearch()
{
FileContentSearch::~FileContentSearch() {
m_search_result = nullptr;
}
void FileContentSearch::run()
{
void FileContentSearch::run() {
if(!m_search_result->isEmpty()) {
m_search_result->clear();
}
@ -264,8 +249,7 @@ void FileContentSearch::run()
return;
}
int FileContentSearch::keywordSearchContent()
{
int FileContentSearch::keywordSearchContent() {
try {
qDebug() << "--keywordSearchContent search start--";
@ -342,8 +326,7 @@ int FileContentSearch::keywordSearchContent()
}
}
int FileContentSearch::getResult(Xapian::MSet &result, std::string &keyWord)
{
int FileContentSearch::getResult(Xapian::MSet &result, std::string &keyWord) {
for(auto it = result.begin(); it != result.end(); ++it) {
Xapian::Document doc = it.get_document();
std::string data = doc.get_data();
@ -419,8 +402,7 @@ int FileContentSearch::getResult(Xapian::MSet &result, std::string &keyWord)
return 0;
}
DirectSearch::DirectSearch(QString keyword, QQueue<QString> *searchResultFile, QQueue<QString> *searchResultDir, size_t uniqueSymbol)
{
DirectSearch::DirectSearch(QString keyword, QQueue<QString> *searchResultFile, QQueue<QString> *searchResultDir, size_t uniqueSymbol) {
this->setAutoDelete(true);
m_keyword = keyword;
m_searchResultFile = searchResultFile;
@ -428,8 +410,7 @@ DirectSearch::DirectSearch(QString keyword, QQueue<QString> *searchResultFile, Q
m_uniqueSymbol = uniqueSymbol;
}
void DirectSearch::run()
{
void DirectSearch::run() {
QQueue<QString> bfs;
bfs.enqueue(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
QFileInfoList list;

View File

@ -46,8 +46,7 @@
#define CONTENT_INDEX_PATH (QStandardPaths::writableLocation(QStandardPaths::HomeLocation)+"/.config/org.ukui/ukui-search/content_index_data").toStdString()
class SearchManager : public QObject
{
class SearchManager : public QObject {
friend class FileSearch;
friend class FileContentSearch;
Q_OBJECT
@ -96,8 +95,7 @@ private:
QThreadPool m_pool;
};
class FileSearch : public QRunnable
{
class FileSearch : public QRunnable {
public:
explicit FileSearch(QQueue<QString> *searchResult, size_t uniqueSymbol, QString keyword, QString value, unsigned slot = 1, int begin = 0, int num = 20);
~FileSearch();
@ -117,8 +115,7 @@ private:
int m_num = 20;
};
class FileContentSearch : public QRunnable
{
class FileContentSearch : public QRunnable {
public:
explicit FileContentSearch(QQueue<QPair<QString, QStringList>> *searchResult, size_t uniqueSymbol, QString keyword, int begin = 0, int num = 20);
~FileContentSearch();
@ -135,8 +132,7 @@ private:
int m_num = 20;
};
class DirectSearch : public QRunnable
{
class DirectSearch : public QRunnable {
public:
explicit DirectSearch(QString keyword, QQueue<QString> *searchResultFile, QQueue<QString> *searchResultDir, size_t uniqueSymbol);
protected:

View File

@ -1,7 +1,6 @@
#include "searchmethodmanager.h"
void SearchMethodManager::searchMethod(FileUtils::SearchMethod sm)
{
void SearchMethodManager::searchMethod(FileUtils::SearchMethod sm) {
qWarning() << "searchMethod start: " << static_cast<int>(sm);
if(FileUtils::SearchMethod::INDEXSEARCH == sm || FileUtils::SearchMethod::DIRECTSEARCH == sm) {
FileUtils::searchMethod = sm;

View File

@ -4,8 +4,7 @@
#include "first-index.h"
#include "inotify-index.h"
class SearchMethodManager
{
class SearchMethodManager {
public:
SearchMethodManager() = default;
void searchMethod(FileUtils::SearchMethod sm);

View File

@ -19,8 +19,7 @@
*/
#include "traverse_bfs.h"
Traverse_BFS::Traverse_BFS(const QString& path)
{
Traverse_BFS::Traverse_BFS(const QString& path) {
Q_ASSERT('/' == path.at(0));
this->path = path;
}

View File

@ -25,8 +25,7 @@
#include <QDir>
#include <QQueue>
class Traverse_BFS
{
class Traverse_BFS {
public:
Traverse_BFS() = default;
void Traverse();

View File

@ -20,8 +20,7 @@
#include "ukui-search-qdbus.h"
#include <QDebug>
UkuiSearchQDBus::UkuiSearchQDBus()
{
UkuiSearchQDBus::UkuiSearchQDBus() {
this->tmpSystemQDBusInterface = new QDBusInterface("com.ukui.search.qt.systemdbus",
"/",
"com.ukui.search.interface",
@ -37,8 +36,7 @@ UkuiSearchQDBus::~UkuiSearchQDBus(){
}
//一键三连
void UkuiSearchQDBus::setInotifyMaxUserWatches()
{
void UkuiSearchQDBus::setInotifyMaxUserWatches() {
// /proc/sys/fs/inotify/max_user_watches
this->tmpSystemQDBusInterface->call("setInotifyMaxUserWatchesStep1");
// sysctl

View File

@ -22,8 +22,7 @@
#include <QDBusInterface>
class UkuiSearchQDBus
{
class UkuiSearchQDBus {
public:
UkuiSearchQDBus();
~UkuiSearchQDBus();

View File

@ -32,8 +32,7 @@
#include "index/inotify-index.h"
#include "index/search-manager.h"
class LIBSEARCH_EXPORT GlobalSearch
{
class LIBSEARCH_EXPORT GlobalSearch {
public:
static QStringList fileSearch(QString keyword, int begin = 0, int num = -1);

View File

@ -4317,8 +4317,7 @@ static const Properties uc_properties[] = {
};
static inline const Properties *qGetProp(ushort ucs2)
{
static inline const Properties *qGetProp(ushort ucs2) {
int index = GET_PROP_INDEX_UCS2(ucs2);
return uc_properties + index;
}
@ -4375,41 +4374,34 @@ static size_t tMaxElements = 0;
(unsigned long)(a[(i)+1])<<16|\
(unsigned long)(a[i])<<24)
void* xmalloc(size_t tSize)
{
void* xmalloc(size_t tSize) {
void *pvTmp;
if (tSize == 0)
{
if(tSize == 0) {
tSize = 1;
}
pvTmp = malloc(tSize);
if (pvTmp == NULL)
{
if(pvTmp == NULL) {
return NULL;
}
return pvTmp;
} /* end of xmalloc */
void* xcalloc(size_t tNmemb, size_t tSize)
{
void* xcalloc(size_t tNmemb, size_t tSize) {
void *pvTmp;
if (tNmemb == 0 || tSize == 0)
{
if(tNmemb == 0 || tSize == 0) {
tNmemb = 1;
tSize = 1;
}
pvTmp = calloc(tNmemb, tSize);
if (pvTmp == NULL)
{
if(pvTmp == NULL) {
return NULL;
}
return pvTmp;
} /* end of xcalloc */
void* xrealloc(void *pvArg, size_t tSize)
{
void* xrealloc(void *pvArg, size_t tSize) {
void *pvTmp;
pvTmp = realloc(pvArg, tSize);
@ -4417,25 +4409,20 @@ void* xrealloc(void *pvArg, size_t tSize)
} /* end of xrealloc */
void* xfree(void *pvArg)
{
if (pvArg != NULL)
{
void* xfree(void *pvArg) {
if(pvArg != NULL) {
free(pvArg);
}
return NULL;
} /* end of xfree */
bool bReadBytes(unsigned char *aucBytes, size_t tMemb, long lOffset, FILE *pFile)
{
bool bReadBytes(unsigned char *aucBytes, size_t tMemb, long lOffset, FILE *pFile) {
// printf("[%s]-[%d] wana read [%d] offset[%d]\n",__FUNCTION__,__LINE__,tMemb, lOffset);
if (fseek(pFile, lOffset, SEEK_SET) != 0)
{
if(fseek(pFile, lOffset, SEEK_SET) != 0) {
return false;
}
if (fread(aucBytes, sizeof(unsigned char), tMemb, pFile) != tMemb)
{
if(fread(aucBytes, sizeof(unsigned char), tMemb, pFile) != tMemb) {
return false;
}
return true;
@ -4443,8 +4430,7 @@ bool bReadBytes(unsigned char *aucBytes, size_t tMemb, long lOffset, FILE *pFile
#define SIZE_RATIO (BIG_BLOCK_SIZE/SMALL_BLOCK_SIZE)
ULONG ulDepotOffset(ULONG ulIndex, size_t tBlockSize)
{
ULONG ulDepotOffset(ULONG ulIndex, size_t tBlockSize) {
ULONG ulTmp;
size_t tTmp;
@ -4455,8 +4441,7 @@ ULONG ulDepotOffset(ULONG ulIndex, size_t tBlockSize)
tTmp = (size_t)(ulIndex / SIZE_RATIO);
ulTmp = ulIndex % SIZE_RATIO;
if(aulSmallBlockList == NULL ||
tTmp >= tSmallBlockListLen)
{
tTmp >= tSmallBlockListLen) {
return 0;
}
return ((aulSmallBlockList[tTmp] + 1) * SIZE_RATIO +
@ -4468,34 +4453,28 @@ ULONG ulDepotOffset(ULONG ulIndex, size_t tBlockSize)
bool bReadBuffer(FILE *pFile, ULONG ulStartBlock,
const ULONG *aulBlockDepot, size_t tBlockDepotLen, size_t tBlockSize,
UCHAR *aucBuffer, ULONG ulOffset, size_t tToRead)
{
UCHAR *aucBuffer, ULONG ulOffset, size_t tToRead) {
ULONG ulBegin, ulIndex;
size_t tLen;
for(ulIndex = ulStartBlock;
ulIndex != END_OF_CHAIN && tToRead != 0;
ulIndex = aulBlockDepot[ulIndex])
{
if (ulIndex >= (ULONG)tBlockDepotLen)
{
if (tBlockSize >= BIG_BLOCK_SIZE)
{
ulIndex = aulBlockDepot[ulIndex]) {
if(ulIndex >= (ULONG)tBlockDepotLen) {
if(tBlockSize >= BIG_BLOCK_SIZE) {
qWarning() << "The Big Block Depot is damaged";
} else {
qWarning() << "The Small Block Depot is damaged";
}
}
if (ulOffset >= (ULONG)tBlockSize)
{
if(ulOffset >= (ULONG)tBlockSize) {
ulOffset -= tBlockSize;
continue;
}
ulBegin = ulDepotOffset(ulIndex, tBlockSize) + ulOffset;
tLen = min(tBlockSize - (size_t)ulOffset, tToRead);
ulOffset = 0;
if (!bReadBytes(aucBuffer, tLen, ulBegin, pFile))
{
if(!bReadBytes(aucBuffer, tLen, ulBegin, pFile)) {
return false;
}
aucBuffer += tLen;
@ -4504,48 +4483,41 @@ bool bReadBuffer(FILE *pFile, ULONG ulStartBlock,
return (tToRead == 0);
} /* end of bReadBuffer */
static ULONG ulReadLong(FILE *pFile, ULONG ulOffset)
{
static ULONG ulReadLong(FILE *pFile, ULONG ulOffset) {
UCHAR aucBytes[4];
if (!bReadBytes(aucBytes, 4, ulOffset, pFile))
{
if(!bReadBytes(aucBytes, 4, ulOffset, pFile)) {
return -1;
}
return ulGetLong(0, aucBytes);
} /* end of ulReadLong */
static size_t tReadBlockIndices(FILE *pFile, ULONG *aulBlockDepot,
size_t tMaxRec, ULONG ulOffset)
{
size_t tMaxRec, ULONG ulOffset) {
size_t tDone;
int iIndex;
UCHAR aucBytes[BIG_BLOCK_SIZE];
/* Read a big block with BBD or SBD indices */
if (!bReadBytes(aucBytes, BIG_BLOCK_SIZE, ulOffset, pFile))
{
if(!bReadBytes(aucBytes, BIG_BLOCK_SIZE, ulOffset, pFile)) {
return 0;
}
/* Split the big block into indices, an index is four bytes */
tDone = min(tMaxRec, (size_t)BIG_BLOCK_SIZE / 4);
for (iIndex = 0; iIndex < (int)tDone; iIndex++)
{
for(iIndex = 0; iIndex < (int)tDone; iIndex++) {
aulBlockDepot[iIndex] = ulGetLong(4 * iIndex, aucBytes);
}
return tDone;
} /* end of tReadBlockIndices */
static bool bGetSBD(FILE *pFile, const ULONG *aulDepot, size_t tDepotLen,
ULONG *aulSBD, size_t tSBDLen)
{
ULONG *aulSBD, size_t tSBDLen) {
ULONG ulBegin;
size_t tToGo, tDone;
int iIndex;
tToGo = tSBDLen;
for (iIndex = 0; iIndex < (int)tDepotLen && tToGo != 0; iIndex++)
{
for(iIndex = 0; iIndex < (int)tDepotLen && tToGo != 0; iIndex++) {
ulBegin = (aulDepot[iIndex] + 1) * BIG_BLOCK_SIZE;
tDone = tReadBlockIndices(pFile, aulSBD, tToGo, ulBegin);
if(tDone == 0) {
@ -4557,30 +4529,25 @@ static bool bGetSBD(FILE *pFile, const ULONG *aulDepot, size_t tDepotLen,
return tToGo == 0;
} /* end of bGetSBD */
static void vName2String(char *szName, const UCHAR *aucBytes, size_t tNameSize)
{
static void vName2String(char *szName, const UCHAR *aucBytes, size_t tNameSize) {
char *pcChar;
size_t tIndex;
if (tNameSize < 2)
{
if(tNameSize < 2) {
szName[0] = '\0';
return;
}
for (tIndex = 0, pcChar = szName; tIndex < 2 * tNameSize; tIndex += 2, pcChar++)
{
for(tIndex = 0, pcChar = szName; tIndex < 2 * tNameSize; tIndex += 2, pcChar++) {
*pcChar = (char)aucBytes[tIndex];
}
szName[tNameSize - 1] = '\0';
} /* end of vName2String */
void vAdd2PropModList(const UCHAR *aucPropMod)
{
void vAdd2PropModList(const UCHAR *aucPropMod) {
size_t tSize, tLen;
if (tNextFree >= tMaxElements)
{
if(tNextFree >= tMaxElements) {
tMaxElements += ELEMENTS_TO_ADD;
tSize = tMaxElements * sizeof(UCHAR **);
ppAnchor = (UCHAR**)xrealloc(ppAnchor, tSize);
@ -4593,37 +4560,31 @@ void vAdd2PropModList(const UCHAR *aucPropMod)
} /* end of vAdd2PropModList */
static void vComputePPSlevels(ppsEntryType *atPPSlist, ppsEntryType *pNode,
int iLevel, int iRecursionLevel)
{
if (iRecursionLevel > 25)
{
int iLevel, int iRecursionLevel) {
if(iRecursionLevel > 25) {
/* This removes the possibility of an infinite recursion */
return;
}
if (pNode->iLevel <= iLevel)
{
if(pNode->iLevel <= iLevel) {
/* Avoid entering a loop */
return;
}
pNode->iLevel = iLevel;
if (pNode->ulDir != PPS_NUMBER_INVALID)
{
if(pNode->ulDir != PPS_NUMBER_INVALID) {
vComputePPSlevels(atPPSlist,
&atPPSlist[pNode->ulDir],
iLevel + 1,
iRecursionLevel + 1);
}
if (pNode->ulNext != PPS_NUMBER_INVALID)
{
if(pNode->ulNext != PPS_NUMBER_INVALID) {
vComputePPSlevels(atPPSlist,
&atPPSlist[pNode->ulNext],
iLevel,
iRecursionLevel + 1);
}
if (pNode->ulPrevious != PPS_NUMBER_INVALID)
{
if(pNode->ulPrevious != PPS_NUMBER_INVALID) {
vComputePPSlevels(atPPSlist,
&atPPSlist[pNode->ulPrevious],
iLevel,
@ -4633,8 +4594,7 @@ static void vComputePPSlevels(ppsEntryType *atPPSlist, ppsEntryType *pNode,
bool KBinaryParser::bGetPPS(FILE *pFile,
const ULONG *aulRootList, size_t tRootListLen, ppsInfoType *pPPS)
{
const ULONG *aulRootList, size_t tRootListLen, ppsInfoType *pPPS) {
ppsEntryType *atPPSlist;
ULONG ulBegin, ulOffset, ulTmp;
size_t tNbrOfPPS, tNameSize;
@ -4650,16 +4610,14 @@ bool KBinaryParser::bGetPPS(FILE *pFile,
atPPSlist = (ppsEntryType*)xcalloc(tNbrOfPPS, sizeof(ppsEntryType));
iRootIndex = 0;
for (iIndex = 0; iIndex < (int)tNbrOfPPS; iIndex++)
{
for(iIndex = 0; iIndex < (int)tNbrOfPPS; iIndex++) {
ulTmp = (ULONG)iIndex * PROPERTY_SET_STORAGE_SIZE;
iStartBlock = (int)(ulTmp / BIG_BLOCK_SIZE);
ulOffset = ulTmp % BIG_BLOCK_SIZE;
ulBegin = (aulRootList[iStartBlock] + 1) * BIG_BLOCK_SIZE +
ulOffset;
if(!bReadBytes(aucBytes, PROPERTY_SET_STORAGE_SIZE,
ulBegin, pFile))
{
ulBegin, pFile)) {
atPPSlist = (ppsEntryType*)xfree(atPPSlist);
return false;
}
@ -4667,8 +4625,7 @@ bool KBinaryParser::bGetPPS(FILE *pFile,
tNameSize = (tNameSize + 1) / 2;
vName2String(atPPSlist[iIndex].szName, aucBytes, tNameSize);
atPPSlist[iIndex].ucType = ucGetByte(0x42, aucBytes);
if (atPPSlist[iIndex].ucType == 5)
{
if(atPPSlist[iIndex].ucType == 5) {
iRootIndex = iIndex;
}
@ -4688,8 +4645,7 @@ bool KBinaryParser::bGetPPS(FILE *pFile,
(atPPSlist[iIndex].ulNext >= (ULONG)tNbrOfPPS &&
atPPSlist[iIndex].ulNext != PPS_NUMBER_INVALID) ||
(atPPSlist[iIndex].ulDir >= (ULONG)tNbrOfPPS &&
atPPSlist[iIndex].ulDir != PPS_NUMBER_INVALID))
{
atPPSlist[iIndex].ulDir != PPS_NUMBER_INVALID)) {
atPPSlist = (ppsEntryType*)xfree(atPPSlist);
return false;
}
@ -4698,11 +4654,9 @@ bool KBinaryParser::bGetPPS(FILE *pFile,
/* Add level information to each entry */
vComputePPSlevels(atPPSlist, &atPPSlist[iRootIndex], 0, 0);
for (iIndex = 0; iIndex < (int)tNbrOfPPS; iIndex++)
{
for(iIndex = 0; iIndex < (int)tNbrOfPPS; iIndex++) {
if(atPPSlist[iIndex].szName[0] == '\0' ||
atPPSlist[iIndex].ulSize == 0)
{
atPPSlist[iIndex].ulSize == 0) {
/* This entry can be ignored */
continue;
}
@ -4715,64 +4669,47 @@ bool KBinaryParser::bGetPPS(FILE *pFile,
bTypeFind = true;
}
else */if(pPPS->tWordDocument.ulSize == 0 &&
STREQ(atPPSlist[iIndex].szName, "WordDocument"))
{
STREQ(atPPSlist[iIndex].szName, "WordDocument")) {
pPPS->tWordDocument.ulSB = atPPSlist[iIndex].ulSB;
pPPS->tWordDocument.ulSize = atPPSlist[iIndex].ulSize;
pPPS->type = Word;
bTypeFind = true;
}
else if (pPPS->tData.ulSize == 0 &&
STREQ(atPPSlist[iIndex].szName, "Data"))
{
} else if(pPPS->tData.ulSize == 0 &&
STREQ(atPPSlist[iIndex].szName, "Data")) {
pPPS->tData.ulSB = atPPSlist[iIndex].ulSB;
pPPS->tData.ulSize = atPPSlist[iIndex].ulSize;
}
else if (pPPS->t0Table.ulSize == 0 &&
STREQ(atPPSlist[iIndex].szName, "0Table"))
{
} else if(pPPS->t0Table.ulSize == 0 &&
STREQ(atPPSlist[iIndex].szName, "0Table")) {
pPPS->t0Table.ulSB = atPPSlist[iIndex].ulSB;
pPPS->t0Table.ulSize = atPPSlist[iIndex].ulSize;
}
else if (pPPS->t1Table.ulSize == 0 &&
STREQ(atPPSlist[iIndex].szName, "1Table"))
{
} else if(pPPS->t1Table.ulSize == 0 &&
STREQ(atPPSlist[iIndex].szName, "1Table")) {
pPPS->t1Table.ulSB = atPPSlist[iIndex].ulSB;
pPPS->t1Table.ulSize = atPPSlist[iIndex].ulSize;
}
else if (pPPS->tSummaryInfo.ulSize == 0 &&
} else if(pPPS->tSummaryInfo.ulSize == 0 &&
STREQ(atPPSlist[iIndex].szName,
"\005SummaryInformation"))
{
"\005SummaryInformation")) {
pPPS->tSummaryInfo.ulSB = atPPSlist[iIndex].ulSB;
pPPS->tSummaryInfo.ulSize = atPPSlist[iIndex].ulSize;
}
else if (pPPS->tDocSummaryInfo.ulSize == 0 &&
} else if(pPPS->tDocSummaryInfo.ulSize == 0 &&
STREQ(atPPSlist[iIndex].szName,
"\005DocumentSummaryInformation"))
{
"\005DocumentSummaryInformation")) {
pPPS->tDocSummaryInfo.ulSB = atPPSlist[iIndex].ulSB;
pPPS->tDocSummaryInfo.ulSize = atPPSlist[iIndex].ulSize;
}
else if (pPPS->tWorkBook.ulSize == 0 &&
(STREQ(atPPSlist[iIndex].szName, "Book") || STREQ(atPPSlist[iIndex].szName, "Workbook")))
{
} else if(pPPS->tWorkBook.ulSize == 0 &&
(STREQ(atPPSlist[iIndex].szName, "Book") || STREQ(atPPSlist[iIndex].szName, "Workbook"))) {
pPPS->tWorkBook.ulSB = atPPSlist[iIndex].ulSB;
pPPS->tWorkBook.ulSize = atPPSlist[iIndex].ulSize;
pPPS->type = Excel;
bTypeFind = true;
}
else if (pPPS->tPPTDocument.ulSize == 0 &&
STREQ(atPPSlist[iIndex].szName, "PowerPoint Document"))
{
} else if(pPPS->tPPTDocument.ulSize == 0 &&
STREQ(atPPSlist[iIndex].szName, "PowerPoint Document")) {
pPPS->tPPTDocument.ulSB = atPPSlist[iIndex].ulSB;
pPPS->tPPTDocument.ulSize = atPPSlist[iIndex].ulSize;
pPPS->type = Ppt;
bTypeFind = true;
}
else if (pPPS->tCurrentUser.ulSize == 0 &&
STREQ(atPPSlist[iIndex].szName, "Current User"))
{
} else if(pPPS->tCurrentUser.ulSize == 0 &&
STREQ(atPPSlist[iIndex].szName, "Current User")) {
pPPS->tCurrentUser.ulSB = atPPSlist[iIndex].ulSB;
pPPS->tCurrentUser.ulSize = atPPSlist[iIndex].ulSize;
}
@ -4784,8 +4721,7 @@ bool KBinaryParser::bGetPPS(FILE *pFile,
return bTypeFind;
}/* end of bGetPPS */
int KBinaryParser::readData(rdPara &readParam, uchar *aucBuffer, ulong ulOffset, size_t tToRead)
{
int KBinaryParser::readData(rdPara &readParam, uchar *aucBuffer, ulong ulOffset, size_t tToRead) {
/* Read the headerblock */
if(!bReadBuffer(readParam.pFile, readParam.ulStBlk,
readParam.ulBBd, readParam.tBBdLen, readParam.usBlkSize,
@ -4795,8 +4731,7 @@ int KBinaryParser::readData(rdPara &readParam, uchar *aucBuffer, ulong ulOffset,
}
bool bCreateSmallBlockList(ULONG ulStartblock, const ULONG *aulBBD, size_t tBBDLen)
{
bool bCreateSmallBlockList(ULONG ulStartblock, const ULONG *aulBBD, size_t tBBDLen) {
ULONG ulTmp;
size_t tSize;
int iIndex;
@ -4804,15 +4739,12 @@ bool bCreateSmallBlockList(ULONG ulStartblock, const ULONG *aulBBD, size_t tBBDL
/* Find the length of the small block list */
for(tSmallBlockListLen = 0, ulTmp = ulStartblock;
tSmallBlockListLen < tBBDLen && ulTmp != END_OF_CHAIN;
tSmallBlockListLen++, ulTmp = aulBBD[ulTmp])
{
if (ulTmp >= (ULONG)tBBDLen)
{
tSmallBlockListLen++, ulTmp = aulBBD[ulTmp]) {
if(ulTmp >= (ULONG)tBBDLen) {
}
}
if (tSmallBlockListLen == 0)
{
if(tSmallBlockListLen == 0) {
/* There is no small block list */
aulSmallBlockList = NULL;
return true;
@ -4823,10 +4755,8 @@ bool bCreateSmallBlockList(ULONG ulStartblock, const ULONG *aulBBD, size_t tBBDL
aulSmallBlockList = (ULONG*)xmalloc(tSize);
for(iIndex = 0, ulTmp = ulStartblock;
iIndex < (int)tBBDLen && ulTmp != END_OF_CHAIN;
iIndex++, ulTmp = aulBBD[ulTmp])
{
if (ulTmp >= (ULONG)tBBDLen)
{
iIndex++, ulTmp = aulBBD[ulTmp]) {
if(ulTmp >= (ULONG)tBBDLen) {
return false;
}
aulSmallBlockList[iIndex] = ulTmp;
@ -4835,31 +4765,26 @@ bool bCreateSmallBlockList(ULONG ulStartblock, const ULONG *aulBBD, size_t tBBDL
} /* end of bCreateSmallBlockList */
static void vGetBbdList(FILE *pFile, int iNbr, ULONG *aulBbdList, ULONG ulOffset)
{
static void vGetBbdList(FILE *pFile, int iNbr, ULONG *aulBbdList, ULONG ulOffset) {
int iIndex;
for (iIndex = 0; iIndex < iNbr; iIndex++)
{
for(iIndex = 0; iIndex < iNbr; iIndex++) {
aulBbdList[iIndex] = ulReadLong(pFile, ulOffset + 4 * (ULONG)iIndex);
}
} /* end of vGetBbdList */
static bool bGetBBD(FILE *pFile, const ULONG *aulDepot, size_t tDepotLen,
ULONG *aulBBD, size_t tBBDLen)
{
ULONG *aulBBD, size_t tBBDLen) {
ULONG ulBegin;
size_t tToGo, tDone;
int iIndex;
tToGo = tBBDLen;
for (iIndex = 0; iIndex < (int)tDepotLen && tToGo != 0; iIndex++)
{
for(iIndex = 0; iIndex < (int)tDepotLen && tToGo != 0; iIndex++) {
ulBegin = (aulDepot[iIndex] + 1) * BIG_BLOCK_SIZE;
tDone = tReadBlockIndices(pFile, aulBBD, tToGo, ulBegin);
if (tDone == 0)
{
if(tDone == 0) {
return false;
}
aulBBD += tDone;
@ -4873,16 +4798,14 @@ static bool bGetBBD(FILE *pFile, const ULONG *aulDepot, size_t tDepotLen,
hashHaystack -= (a) << sl_minus_1; \
hashHaystack <<= 1
static inline uint foldCase(const ushort *ch, const ushort *start)
{
static inline uint foldCase(const ushort *ch, const ushort *start) {
uint c = *ch;
if(QChar(c).isLowSurrogate() && ch > start && QChar(*(ch - 1)).isHighSurrogate())
c = QChar::surrogateToUcs4(*(ch - 1), c);
return *ch + qGetProp(c)->caseFoldDiff;
}
static inline uint foldCase(uint ch, uint &last)
{
static inline uint foldCase(uint ch, uint &last) {
uint c = ch;
if(QChar(c).isLowSurrogate() && QChar(last).isHighSurrogate())
c = QChar::surrogateToUcs4(last, c);
@ -4890,14 +4813,12 @@ static inline uint foldCase(uint ch, uint &last)
return ch + qGetProp(c)->caseFoldDiff;
}
static inline ushort foldCase(ushort ch)
{
static inline ushort foldCase(ushort ch) {
return ch + qGetProp(ch)->caseFoldDiff;
}
static int ucstricmp(const ushort *a, const ushort *ae, const ushort *b, const ushort *be)
{
static int ucstricmp(const ushort *a, const ushort *ae, const ushort *b, const ushort *be) {
if(a == b)
return (ae - be);
if(a == 0)
@ -4929,13 +4850,11 @@ static int ucstricmp(const ushort *a, const ushort *ae, const ushort *b, const u
return 1;
}
static int ucstrnicmp(const ushort *a, const ushort *b, int l)
{
static int ucstrnicmp(const ushort *a, const ushort *b, int l) {
return ucstricmp(a, a + l, b, b + l);
}
static int ucstrncmp(const QChar *a, const QChar *b, int l)
{
static int ucstrncmp(const QChar *a, const QChar *b, int l) {
while(l-- && *a == *b)
a++, b++;
if(l == -1)
@ -4943,8 +4862,7 @@ static int ucstrncmp(const QChar *a, const QChar *b, int l)
return a->unicode() - b->unicode();
}
inline uint _Ucs2ToUcs4( ushort lead, ushort trail)
{
inline uint _Ucs2ToUcs4(ushort lead, ushort trail) {
unsigned int ucs4 = (trail - 0xDC00); //low 10 bit
ucs4 |= ((lead - 0xD800)) << 10; //high 10 bit
return ucs4 + 0x10000;
@ -4953,8 +4871,7 @@ inline uint _Ucs2ToUcs4( ushort lead, ushort trail)
bool KBinaryParser::read8DocText(FILE *pFile, const ppsInfoType *pPPS,
const ULONG *aulBBD, size_t tBBDLen,
const ULONG *aulSBD, size_t tSBDLen,
const UCHAR *aucHeader,QString &content)
{
const UCHAR *aucHeader, QString &content) {
const ULONG *aulBlockDepot;
ULONG ulTextOffset, ulBeginTextInfo;
ULONG ulTotLength, ulLen;
@ -4970,15 +4887,12 @@ bool KBinaryParser::read8DocText(FILE *pFile, const ppsInfoType *pPPS,
if(pPPS->tTable.ulSize == 0)
return false;
if (pPPS->tTable.ulSize < MIN_SIZE_FOR_BBD_USE)
{
if(pPPS->tTable.ulSize < MIN_SIZE_FOR_BBD_USE) {
/* Use the Small Block Depot */
aulBlockDepot = aulSBD;
tBlockDepotLen = tSBDLen;
tBlockSize = SMALL_BLOCK_SIZE;
}
else
{
} else {
/* Use the Big Block Depot */
aulBlockDepot = aulBBD;
tBlockDepotLen = tBBDLen;
@ -4992,17 +4906,14 @@ bool KBinaryParser::read8DocText(FILE *pFile, const ppsInfoType *pPPS,
return false;
lOff = 0;
while (lOff < (long)tTextInfoLen)
{
while(lOff < (long)tTextInfoLen) {
iType = (int)ucGetByte(lOff, aucBuffer);
lOff++;
if (iType == 0)
{
if(iType == 0) {
lOff++;
continue;
}
if (iType == 1)
{
if(iType == 1) {
iLen = (int)usGetWord(lOff, aucBuffer);
vAdd2PropModList(aucBuffer + lOff);
lOff += (long)iLen + 2;
@ -5019,18 +4930,14 @@ bool KBinaryParser::read8DocText(FILE *pFile, const ppsInfoType *pPPS,
lOff += 4;
lPieces = (long)((ulLen - 4) / 12);
for (lIndex = 0; lIndex < lPieces; lIndex++)
{
for(lIndex = 0; lIndex < lPieces; lIndex++) {
ulTextOffset = ulGetLong(lOff + (lPieces + 1) * 4 + lIndex * 8 + 2, aucBuffer);
usPropMod = usGetWord(lOff + (lPieces + 1) * 4 + lIndex * 8 + 6, aucBuffer);
ulTotLength = ulGetLong(lOff + (lIndex + 1) * 4, aucBuffer) - ulGetLong(lOff + lIndex * 4, aucBuffer);
if ((ulTextOffset & BIT(30)) == 0)
{
if((ulTextOffset & BIT(30)) == 0) {
bUsesUnicode = true;
ulTotLength *= 2;
}
else
{
} else {
bUsesUnicode = false;
ulTextOffset &= ~BIT(30);
ulTextOffset /= 2;
@ -5041,8 +4948,7 @@ bool KBinaryParser::read8DocText(FILE *pFile, const ppsInfoType *pPPS,
ULONG ulFileOffset = (pPPS->tWordDocument.ulSB + 1) * BIG_BLOCK_SIZE + ulTextOffset;
if(pPPS->tWordDocument.ulSize < MIN_SIZE_FOR_BBD_USE)
ulFileOffset = ulDepotOffset(pPPS->tWordDocument.ulSB, SMALL_BLOCK_SIZE) + ulTextOffset;
while (uOff < ulTotLength)
{
while(uOff < ulTotLength) {
ULONG iAllocSize = MAX_BUFF_SIZE;
if((ulTotLength - uOff) < MAX_BUFF_SIZE)
iAllocSize = ulTotLength - uOff;
@ -5056,17 +4962,14 @@ bool KBinaryParser::read8DocText(FILE *pFile, const ppsInfoType *pPPS,
ulFileOffset += iAllocSize;
uOff += iAllocSize;
if (bUsesUnicode)
{
if(bUsesUnicode) {
ushort* usAucData = (ushort*)ptaucBytes;
content.append(QString::fromUtf16(usAucData).replace("\r", ""));
usAucData = (ushort*)xfree((void*)usAucData);
ptaucBytes = NULL;
if(content.length() >= 682666) //20480000/3
break;
}
else
{
} else {
//need more format document
ptaucBytes = (UCHAR*)xfree((void*)ptaucBytes);
qWarning() << "Parser error:" << m_strFileName;
@ -5081,8 +4984,7 @@ bool KBinaryParser::read8DocText(FILE *pFile, const ppsInfoType *pPPS,
return false;
}/* end of bGet8DocumentText */
int KBinaryParser:: readSSTRecord(readDataParam &rdParam, ppsInfoType PPS_info, ulong &ulOff, ushort usPartLen, QString &content)
{
int KBinaryParser:: readSSTRecord(readDataParam &rdParam, ppsInfoType PPS_info, ulong &ulOff, ushort usPartLen, QString &content) {
UCHAR chSizeData[8];
if(readData(rdParam, chSizeData, ulOff, 8) != 0)
return -1;
@ -5092,8 +4994,7 @@ int KBinaryParser:: readSSTRecord(readDataParam &rdParam, ppsInfoType PPS_info,
ulong ulSize = ulGetLong(0x04, chSizeData) + 1;
ulong ulCount = 1;
ulong ulNextOff = 0;
while ((ulCount < ulSize) && (ulOff < PPS_info.tWorkBook.ulSize))
{
while((ulCount < ulSize) && (ulOff < PPS_info.tWorkBook.ulSize)) {
UCHAR chHeader[3];
if(readData(rdParam, chHeader, ulOff + ulNextOff, 3) != 0)
break;
@ -5110,8 +5011,7 @@ int KBinaryParser:: readSSTRecord(readDataParam &rdParam, ppsInfoType PPS_info,
if(!eRrd.bUni)
ustotalLen += uscharlen;
UCHAR* chData = (UCHAR*)xmalloc(ustotalLen);
if (ulNextOff < usPartLen && (ulNextOff + ustotalLen) >= usPartLen)
{
if(ulNextOff < usPartLen && (ulNextOff + ustotalLen) >= usPartLen) {
ushort usIdf = usPartLen - ulNextOff;
uchar chTemp[MAX_BUFF_SIZE];
memset(chTemp, 0, MAX_BUFF_SIZE);
@ -5126,13 +5026,11 @@ int KBinaryParser:: readSSTRecord(readDataParam &rdParam, ppsInfoType PPS_info,
bool bAnotherCompare = (usOthTxtLen == 0 || (usCharByteLen - usIdf) == 0) || usCharByteLen < usIdf;
ulong ulNoUse = 0;
bool bUniFlg = false;
if (!bAnotherCompare)
{
if(!bAnotherCompare) {
uchar chFlag;
memcpy(&chFlag, chTemp + usIdf + 4, 1);
if (chFlag == 0x00 || chFlag == 0x01 || chFlag == 0x05 || chFlag == 0x09 || chFlag == 0x08 || chFlag == 0x04 || chFlag == 0x0c)
{
if(chFlag == 0x00 || chFlag == 0x01 || chFlag == 0x05 || chFlag == 0x09 || chFlag == 0x08 || chFlag == 0x04 || chFlag == 0x0c) {
bTemp = true;
ulOff ++;
@ -5149,8 +5047,7 @@ int KBinaryParser:: readSSTRecord(readDataParam &rdParam, ppsInfoType PPS_info,
ulNextOff = 0;
ustotalLen = usOthTxtLen + ulNoUse;
if (usOthTxtLen > 0)
{
if(usOthTxtLen > 0) {
memset(chTemp, 0, MAX_BUFF_SIZE);
if(readData(rdParam, chTemp, ulOff, usOthTxtLen) != 0)
return -1;
@ -5158,21 +5055,16 @@ int KBinaryParser:: readSSTRecord(readDataParam &rdParam, ppsInfoType PPS_info,
}
if(bTemp)
usPartLen --;
}
else
{
} else {
if(readData(rdParam, chData, ulOff + ulNextOff, ustotalLen) != 0)
break;
}
if (eRrd.bUni)
{
if(eRrd.bUni) {
qDebug() << QString((const char*)chData);
chData = (UCHAR*)xfree((void*)chData);
qWarning() << "Unsupport excel type:" << m_strFileName;
}
else
{
} else {
ushort* usData = (ushort*)chData;
content.append(QString::fromUtf16(usData).replace("\r", ""));
@ -5189,35 +5081,30 @@ int KBinaryParser:: readSSTRecord(readDataParam &rdParam, ppsInfoType PPS_info,
return -1;
}
int KBinaryParser::read8BiffRecord(uchar ucFlag, ulong ulOff, ulong &ulNext, readDataParam &rdParam, excelRecord &eR)
{
int KBinaryParser::read8BiffRecord(uchar ucFlag, ulong ulOff, ulong &ulNext, readDataParam &rdParam, excelRecord &eR) {
bool butf8 = true;
if (ucFlag & 0x08)
{
if(ucFlag & 0x08) {
uchar chiRich[2];
if(readData(rdParam, chiRich, ulOff + ulNext, 2) != 0)
return -1;
eR.usRichLen = usGetWord(0x00, chiRich);
ulNext += 2;
}
if(ucFlag & 0x04)
{
if(ucFlag & 0x04) {
uchar chExt[4];
if(readData(rdParam, chExt, ulOff + ulNext, 4) != 0)
return -1;
eR.ulWLen = ulGetLong(0x00, chExt);
ulNext += 4;
}
if ((ucFlag & 0x01))
{
if((ucFlag & 0x01)) {
butf8 = false;
}
eR.bUni = butf8;
return 0;
}
ULONG KBinaryParser::readPPtRecord(FILE* pFile, ppsInfoType* PPS_info, ULONG* aulBBD, size_t tBBDLen, ULONG ulPos,QString &content)
{
ULONG KBinaryParser::readPPtRecord(FILE* pFile, ppsInfoType* PPS_info, ULONG* aulBBD, size_t tBBDLen, ULONG ulPos, QString &content) {
UCHAR aucHeader[PPT_RECORD_HEADER];
ULONG ulOff = ulPos;
/* Read the headerblock */
@ -5231,17 +5118,12 @@ ULONG KBinaryParser::readPPtRecord(FILE* pFile, ppsInfoType* PPS_info, ULONG* au
USHORT usType = usGetWord(0x02, aucHeader);
ULONG ulLen = ulGetLong(0x04, aucHeader);
USHORT usVer = usVersion & 0xF;
if (usVer == 0xF)
{
while (ulOff < ulLen)
{
if(usVer == 0xF) {
while(ulOff < ulLen) {
ulOff = readPPtRecord(pFile, PPS_info, aulBBD, tBBDLen, ulOff, content);
}
}
else
{
if (usType == PPT_TEXTBYTEATOM || usType == PPT_TEXTCHARATOM)
{
} else {
if(usType == PPT_TEXTBYTEATOM || usType == PPT_TEXTCHARATOM) {
long llen = (long)ulLen;
UCHAR* chData = (UCHAR*)xmalloc(llen);
if(!bReadBuffer(pFile, PPS_info->tPPTDocument.ulSB,
@ -5262,8 +5144,7 @@ ULONG KBinaryParser::readPPtRecord(FILE* pFile, ppsInfoType* PPS_info, ULONG* au
return ulOff;
}
int KBinaryParser::InitDocOle(FILE* pFile,long lFilesize,QString &content)
{
int KBinaryParser::InitDocOle(FILE* pFile, long lFilesize, QString &content) {
ppsInfoType PPS_info;
ULONG *aulBBD, *aulSBD;
ULONG *aulRootList, *aulBbdList, *aulSbdList;
@ -5304,8 +5185,7 @@ int KBinaryParser::InitDocOle(FILE* pFile,long lFilesize,QString &content)
vGetBbdList(pFile, min(iToGo, 109), aulBbdList, 0x4c);
ulStart = 109;
iToGo -= 109;
while (ulAdditionalBBDlist != END_OF_CHAIN && iToGo > 0)
{
while(ulAdditionalBBDlist != END_OF_CHAIN && iToGo > 0) {
ulBdbListStart = (ulAdditionalBBDlist + 1) * BIG_BLOCK_SIZE;
vGetBbdList(pFile, min(iToGo, 127),
aulBbdList + ulStart, ulBdbListStart);
@ -5325,8 +5205,7 @@ int KBinaryParser::InitDocOle(FILE* pFile,long lFilesize,QString &content)
for(iIndex = 0, ulTmp = ulSbdStartblock;
iIndex < (int)tBBDLen && ulTmp != END_OF_CHAIN;
iIndex++, ulTmp = aulBBD[ulTmp])
{
iIndex++, ulTmp = aulBBD[ulTmp]) {
if(ulTmp >= (ULONG)tBBDLen)
qWarning("The Big Block Depot is damaged");
@ -5341,8 +5220,7 @@ int KBinaryParser::InitDocOle(FILE* pFile,long lFilesize,QString &content)
/* Root list */
for(tRootListLen = 0, ulTmp = ulRootStartblock;
tRootListLen < tBBDLen && ulTmp != END_OF_CHAIN;
tRootListLen++, ulTmp = aulBBD[ulTmp])
{
tRootListLen++, ulTmp = aulBBD[ulTmp]) {
if(ulTmp >= (ULONG)tBBDLen)
return -1;
@ -5353,8 +5231,7 @@ int KBinaryParser::InitDocOle(FILE* pFile,long lFilesize,QString &content)
aulRootList = (ULONG*)xcalloc(tRootListLen, sizeof(ULONG));
for(iIndex = 0, ulTmp = ulRootStartblock;
iIndex < (int)tBBDLen && ulTmp != END_OF_CHAIN;
iIndex++, ulTmp = aulBBD[ulTmp])
{
iIndex++, ulTmp = aulBBD[ulTmp]) {
if(ulTmp >= (ULONG)tBBDLen)
return -1;
@ -5370,16 +5247,14 @@ int KBinaryParser::InitDocOle(FILE* pFile,long lFilesize,QString &content)
readParam.tBBdLen = tBBDLen;
readParam.ulBBd = aulBBD;
readParam.usBlkSize = BIG_BLOCK_SIZE;
if (PPS_info.type == Word)
{
if(PPS_info.type == Word) {
readParam.ulStBlk = PPS_info.tWordDocument.ulSB;
UCHAR aucHeader[HEADER_SIZE];
/* Small block list */
if(!bCreateSmallBlockList(ulSBLstartblock, aulBBD, tBBDLen))
return -1;
if (PPS_info.tWordDocument.ulSize < MIN_SIZE_FOR_BBD_USE)
{
if(PPS_info.tWordDocument.ulSize < MIN_SIZE_FOR_BBD_USE) {
readParam.ulBBd = aulSBD;
readParam.tBBdLen = tSBDLen;
readParam.usBlkSize = SMALL_BLOCK_SIZE;
@ -5409,9 +5284,7 @@ int KBinaryParser::InitDocOle(FILE* pFile,long lFilesize,QString &content)
&PPS_info,
aulBBD, tBBDLen, aulSBD, tSBDLen,
aucHeader, content);
}
else if (PPS_info.type == Excel)
{
} else if(PPS_info.type == Excel) {
readParam.ulStBlk = PPS_info.tWorkBook.ulSB;
UCHAR aucHeader[4];
ulong ulOff = 0;
@ -5420,8 +5293,7 @@ int KBinaryParser::InitDocOle(FILE* pFile,long lFilesize,QString &content)
ulOff += 4;
USHORT usType = usGetWord(0x00, aucHeader);
while (ulOff < PPS_info.tWorkBook.ulSize)
{
while(ulOff < PPS_info.tWorkBook.ulSize) {
USHORT usLen = usGetWord(0x02, aucHeader);
ulOff += usLen;
if(readData(readParam, aucHeader, ulOff, 4) != 0)
@ -5429,33 +5301,25 @@ int KBinaryParser::InitDocOle(FILE* pFile,long lFilesize,QString &content)
ulOff += 4;
usType = usGetWord(0x00, aucHeader);
ushort usPartLen = usGetWord(0x02, aucHeader);
if (usType == 0x00FC)
{
if(usType == 0x00FC) {
if(readSSTRecord(readParam, PPS_info, ulOff, usPartLen, content) != 0)
break;
}
}
}
else if (PPS_info.type == Ppt)
{
} else if(PPS_info.type == Ppt) {
ULONG ulOff = 0;
while (ulOff < PPS_info.tPPTDocument.ulSize)
{
while(ulOff < PPS_info.tPPTDocument.ulSize) {
ulOff = readPPtRecord(pFile, &PPS_info, aulBBD, tBBDLen, ulOff, content);
}
}
else
{
} else {
qWarning() << "Unsupport doc type:" << m_strFileName;
}
return 0;
}
long lGetFilesize(const char *szFilename)
{
long lGetFilesize(const char *szFilename) {
struct stat tBuffer;
if (stat(szFilename, &tBuffer) != 0)
{
if(stat(szFilename, &tBuffer) != 0) {
//qWarning() << "Get Filesize error";
return -1;
}
@ -5468,24 +5332,20 @@ long lGetFilesize(const char *szFilename)
KBinaryParser::KBinaryParser(QObject *parent)
: QObject(parent)
,m_strFileName("")
{
, m_strFileName("") {
}
KBinaryParser::~KBinaryParser()
{}
bool KBinaryParser::RunParser(QString strFile,QString &content)
{
bool KBinaryParser::RunParser(QString strFile, QString &content) {
FILE* pFile = fopen(strFile.toLocal8Bit().data(), "rb");
if (!pFile)
{
if(!pFile) {
return false;
}
m_strFileName = strFile;
long lFileSize = lGetFilesize(strFile.toLocal8Bit().data());
if (lFileSize < 0)
{
if(lFileSize < 0) {
qWarning() << "ERROR SIZE";
(void)fclose(pFile);
return false;

View File

@ -7,22 +7,19 @@
#define UCHAR unsigned char
#define USHORT unsigned short
typedef enum
{
typedef enum {
Word = 0,
Excel,
Ppt
} TYPE;
/* Property Set Storage */
typedef struct pps_tag
{
typedef struct pps_tag {
ULONG ulSB;
ULONG ulSize;
} ppsTag;
typedef struct pps_info_tag
{
typedef struct pps_info_tag {
ppsTag tWordDocument; /* Text stream */
ppsTag tWorkBook;
ppsTag tPPTDocument;
@ -37,8 +34,7 @@ typedef struct pps_info_tag
} ppsInfoType;
/* Private type for Property Set Storage entries */
typedef struct pps_entry_tag
{
typedef struct pps_entry_tag {
ULONG ulNext;
ULONG ulPrevious;
ULONG ulDir;
@ -50,10 +46,8 @@ typedef struct pps_entry_tag
} ppsEntryType;
/* Excel Record Struct*/
typedef struct excelRecord
{
excelRecord()
{
typedef struct excelRecord {
excelRecord() {
usLen = 0;
usRichLen = 0;
ulWLen = 0;
@ -65,10 +59,8 @@ typedef struct excelRecord
bool bUni;
} excelRecord;
typedef struct readDataParam
{
readDataParam()
{
typedef struct readDataParam {
readDataParam() {
ulStBlk = 0;
pFile = NULL;
ulBBd = NULL;
@ -82,8 +74,7 @@ typedef struct readDataParam
ushort usBlkSize;
} rdPara;
class KBinaryParser :public QObject
{
class KBinaryParser : public QObject {
Q_OBJECT
public:
KBinaryParser(QObject *parent = 0);

View File

@ -19,8 +19,7 @@
*/
#include "setting-match.h"
#include "file-utils.h"
SettingsMatch::SettingsMatch(QObject *parent) : QObject(parent)
{
SettingsMatch::SettingsMatch(QObject *parent) : QObject(parent) {
xmlElement();
}
@ -97,14 +96,12 @@ QStringList SettingsMatch::matching(){
for(i = m_chine_searchList.constBegin(); i != m_chine_searchList.constEnd(); ++i) {
regmatch = *i;
key = i.key();
for(int t=0; t<regmatch.size();t++)
{
for(int t = 0; t < regmatch.size(); t++) {
if(m_sourceText == "/")
continue;
QString str = regmatch.at(t);
pinyinlist = FileUtils::findMultiToneWords(str);
if(str.contains(m_sourceText))
{
if(str.contains(m_sourceText)) {
str = key + "/" + str;
returnresult.append(str);//中文名
continue;
@ -134,8 +131,7 @@ QStringList SettingsMatch::matching(){
for(i = m_English_searchList.constBegin(); i != m_English_searchList.constEnd(); ++i) {
regmatch = *i;
key = i.key();
for(int t=0; t<regmatch.size();t++)
{
for(int t = 0; t < regmatch.size(); t++) {
if(m_sourceText == "/")
continue;
QString str = regmatch.at(t);

View File

@ -30,8 +30,7 @@
#include <QStringList>
#include <QTimer>
#include <QDebug>
class SettingsMatch : public QObject
{
class SettingsMatch : public QObject {
Q_OBJECT
public:
explicit SettingsMatch(QObject *parent = nullptr);

View File

@ -24,8 +24,7 @@
#include <QTimer>
#include "config-file.h"
ContentWidget::ContentWidget(QWidget * parent):QStackedWidget(parent)
{
ContentWidget::ContentWidget(QWidget * parent): QStackedWidget(parent) {
initUI();
initListView();
//快速入口应用列表
@ -37,8 +36,7 @@ ContentWidget::ContentWidget(QWidget * parent):QStackedWidget(parent)
<< "/usr/share/applications/claws-mail.desktop" ;
}
ContentWidget::~ContentWidget()
{
ContentWidget::~ContentWidget() {
if(m_homePage) {
delete m_homePage;
m_homePage = nullptr;
@ -103,8 +101,7 @@ void ContentWidget::initUI() {
/**
* @brief ContentWidget::initListView
*/
void ContentWidget::initListView()
{
void ContentWidget::initListView() {
m_fileListView = new SearchListView(m_resultList, QStringList(), SearchItem::SearchType::Files);
m_dirListView = new SearchListView(m_resultList, QStringList(), SearchItem::SearchType::Dirs);
m_contentListView = new SearchListView(m_resultList, QStringList(), SearchItem::SearchType::Contents);
@ -232,8 +229,7 @@ void ContentWidget::initListView()
/**
* @brief ContentWidget::hideListView
*/
void ContentWidget::hideListView()
{
void ContentWidget::hideListView() {
m_bestTitleLabel->hide();
m_bestListView->hide();
m_appTitleLabel->hide();
@ -279,8 +275,7 @@ void ContentWidget::setupConnect(SearchListView * listview) {
/**
* @brief ContentWidget::resetHeight
*/
void ContentWidget::resetListHeight()
{
void ContentWidget::resetListHeight() {
int height = 0;
if(! m_bestListView->isHidden) {
height += m_bestTitleLabel->height();
@ -328,8 +323,7 @@ void ContentWidget::resetListHeight()
m_resultList->setFixedHeight(height);
}
void ContentWidget::appendBestItem(const int &type, const QString &path)
{
void ContentWidget::appendBestItem(const int &type, const QString &path) {
m_bestList.append(QPair<int, QString>(type, path));
m_bestListView->appendBestItem(QPair<int, QString>(type, path));
appendSearchItem(SearchItem::SearchType::Best, path);
@ -428,8 +422,7 @@ int ContentWidget::currentPage() {
/**
* @brief ContentWidget::resetSearchList
*/
void ContentWidget::resetSearchList()
{
void ContentWidget::resetSearchList() {
// this->hideListView();
if(m_fileListView) {
m_fileListView->hide();
@ -514,8 +507,7 @@ void ContentWidget::resetSearchList()
* @brief ContentWidget::setSettingList
* @param settingList
*/
void ContentWidget::setSettingList(const QStringList & settingList)
{
void ContentWidget::setSettingList(const QStringList & settingList) {
if(settingList.isEmpty())
return;
m_settingList = settingList;
@ -691,8 +683,7 @@ void ContentWidget::clearLayout(QLayout * layout) {
if(! layout) return;
QLayoutItem * child;
while((child = layout->takeAt(0)) != 0) {
if(child->widget())
{
if(child->widget()) {
child->widget()->setParent(NULL); //防止删除后窗口看上去没有消失
}
delete child;
@ -705,8 +696,7 @@ void ContentWidget::clearLayout(QLayout * layout) {
* @param type
* @param path
*/
void ContentWidget::onListViewRowChanged(SearchListView * listview, const int &type, const QString &path)
{
void ContentWidget::onListViewRowChanged(SearchListView * listview, const int &type, const QString &path) {
if(type == SearchItem::SearchType::Contents && !m_contentDetailList.isEmpty()) {
m_detailView->isContent = true;
m_detailView->setContent(m_contentDetailList.at(listview->currentIndex().row()), m_keyword);
@ -745,8 +735,7 @@ void ContentWidget::onListViewRowChanged(SearchListView * listview, const int &t
* @param type
* @param path
*/
void ContentWidget::onListViewRowDoubleClicked(SearchListView * listview, const int &type, const QString &path)
{
void ContentWidget::onListViewRowDoubleClicked(SearchListView * listview, const int &type, const QString &path) {
qDebug() << "A row has been double clicked.Type = " << type << "; Name = " << path;
if(type == SearchItem::SearchType::Best && m_bestList.at(listview->currentIndex().row()).first != SearchItem::SearchType::Apps) {
m_detailView->doubleClickAction(m_bestList.at(listview->currentIndex().row()).first, path);
@ -782,8 +771,7 @@ void ContentWidget::setContentList(const QStringList& list) {
* @brief ContentWidget::setKeyword
* @param keyword
*/
void ContentWidget::setKeyword(QString keyword)
{
void ContentWidget::setKeyword(QString keyword) {
m_keyword = keyword;
m_fileListView->setKeyword(keyword);
m_dirListView->setKeyword(keyword);
@ -798,15 +786,13 @@ void ContentWidget::setKeyword(QString keyword)
* @brief ContentWidget::setQuicklyOpenList
* @param list
*/
void ContentWidget::setQuicklyOpenList(const QStringList & list)
{
void ContentWidget::setQuicklyOpenList(const QStringList & list) {
m_quicklyOpenList = list;
}
/**
* @brief ContentWidget::closeWebView webview未关闭
*/
void ContentWidget::closeWebView()
{
void ContentWidget::closeWebView() {
m_detailView->closeWebWidget();
}

View File

@ -30,8 +30,7 @@
#include "show-more-label.h"
#include "title-label.h"
class ContentWidget : public QStackedWidget
{
class ContentWidget : public QStackedWidget {
Q_OBJECT
public:
ContentWidget(QWidget *);

View File

@ -26,8 +26,7 @@
#include <QFileInfo>
#include <QDir>
#define HOMEPAGE_SETTINGS QDir::homePath()+"/.config/org.ukui/ukui-search/ukui-search-homepage.conf"
class ConfigFile : public QObject
{
class ConfigFile : public QObject {
Q_OBJECT
public:
static bool writeConfig(QString message);

View File

@ -22,14 +22,12 @@
#include <QIcon>
#include <QEvent>
FolderListItem::FolderListItem(QWidget *parent, const QString &path) : QWidget(parent)
{
FolderListItem::FolderListItem(QWidget *parent, const QString &path) : QWidget(parent) {
m_path = path;
initUi();
}
FolderListItem::~FolderListItem()
{
FolderListItem::~FolderListItem() {
}

View File

@ -26,8 +26,7 @@
#include <QVBoxLayout>
#include <QLabel>
class FolderListItem : public QWidget
{
class FolderListItem : public QWidget {
Q_OBJECT
public:
explicit FolderListItem(QWidget *parent = nullptr, const QString &path = 0);

View File

@ -27,8 +27,7 @@
#include <QAbstractTextDocumentLayout>
#include "global-settings.h"
HighlightItemDelegate::HighlightItemDelegate(QObject *parent) : QStyledItemDelegate (parent)
{
HighlightItemDelegate::HighlightItemDelegate(QObject *parent) : QStyledItemDelegate(parent) {
}
/**
@ -37,8 +36,7 @@ HighlightItemDelegate::HighlightItemDelegate(QObject *parent) : QStyledItemDeleg
* \param option
* \param index
*/
void HighlightItemDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
{
void HighlightItemDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const {
QStyleOptionViewItemV4 optionV4 = option;
initStyleOption(&optionV4, index);
@ -80,8 +78,7 @@ void HighlightItemDelegate::paint(QPainter * painter, const QStyleOptionViewItem
* @param index
* @return
*/
QString HighlightItemDelegate::getHtmlText(QPainter *painter, const QStyleOptionViewItem &itemOption, const QModelIndex &index) const
{
QString HighlightItemDelegate::getHtmlText(QPainter *painter, const QStyleOptionViewItem &itemOption, const QModelIndex &index) const {
int indexFindLeft = 0;
QString indexString = index.model()->data(index, Qt::DisplayRole).toString();
QFont ft(painter->font().family(), GlobalSettings::getInstance()->getValue(FONT_SIZE_KEY).toInt());
@ -123,8 +120,7 @@ QString HighlightItemDelegate::getHtmlText(QPainter *painter, const QStyleOption
* @param str
* @return
*/
QString HighlightItemDelegate::escapeHtml(const QString & str) const
{
QString HighlightItemDelegate::escapeHtml(const QString & str) const {
QString temp = str;
temp.replace("<", "&lt;");
temp.replace(">", "&gt;");
@ -139,8 +135,7 @@ QString HighlightItemDelegate::escapeHtml(const QString & str) const
* @param indexFindLeft
* @param keywordLength
*/
void HighlightItemDelegate::paintKeywordHighlight(QPainter *painter, const QStyleOptionViewItem &itemOption, const QString &indexColString, const int &indexFindLeft, const int &keywordLength) const
{
void HighlightItemDelegate::paintKeywordHighlight(QPainter *painter, const QStyleOptionViewItem &itemOption, const QString &indexColString, const int &indexFindLeft, const int &keywordLength) const {
QPen pen(Qt::black);
painter->setPen(pen);
QFont font = QApplication::font(itemOption.widget);
@ -157,8 +152,7 @@ void HighlightItemDelegate::paintKeywordHighlight(QPainter *painter, const QStyl
QStyle * m_QStyle = m_QWidget ? m_QWidget->style() : QApplication::style(); //得到当前的style
QRect m_QRect = itemOption.rect;//得到Item的自己的Rect
QPalette::ColorRole textDisplayRole = QPalette::NoRole; //设置text的role
if (itemOption.state & QStyle::State_Selected)
{
if(itemOption.state & QStyle::State_Selected) {
textDisplayRole = QPalette::HighlightedText; //当选中字体的时候字体显示高亮
} else {
textDisplayRole = QPalette::Text;
@ -177,8 +171,7 @@ void HighlightItemDelegate::paintKeywordHighlight(QPainter *painter, const QStyl
* \brief treewidget_styledItemDelegate::search_keyword
* \param regFindKeyWords
*/
void HighlightItemDelegate::setSearchKeyword(const QString &regFindKeyWords)
{
void HighlightItemDelegate::setSearchKeyword(const QString &regFindKeyWords) {
m_regFindKeyWords.clear();
m_regFindKeyWords = regFindKeyWords;
}

View File

@ -23,8 +23,7 @@
#include <QStyledItemDelegate>
class HighlightItemDelegate : public QStyledItemDelegate
{
class HighlightItemDelegate : public QStyledItemDelegate {
Q_OBJECT
public:
explicit HighlightItemDelegate(QObject *parent = nullptr);

View File

@ -28,8 +28,7 @@
#include <QUrl>
#include <QApplication>
HomePageItem::HomePageItem(QWidget *parent, const int& type, const QString& path) : QWidget(parent)
{
HomePageItem::HomePageItem(QWidget *parent, const int& type, const QString& path) : QWidget(parent) {
setupUi(type, path);
m_transparency = 0.06;
connect(qApp, &QApplication::paletteChanged, this, [ = ]() {
@ -44,8 +43,7 @@ HomePageItem::HomePageItem(QWidget *parent, const int& type, const QString& path
});
}
HomePageItem::~HomePageItem()
{
HomePageItem::~HomePageItem() {
}
/**
@ -131,8 +129,7 @@ void HomePageItem::setupUi(const int& type, const QString& path) {
m_vlayout->addWidget(m_namelabel);
}
void HomePageItem::onItemClicked()
{
void HomePageItem::onItemClicked() {
switch(SearchListView::getResType(m_path)) {
case SearchListView::ResType::App: {
GDesktopAppInfo * desktopAppInfo = g_desktop_app_info_new_from_filename(m_path.toLocal8Bit().data());

View File

@ -28,8 +28,7 @@
#include "file-utils.h"
#include "search-list-view.h"
class HomePageItem : public QWidget
{
class HomePageItem : public QWidget {
Q_OBJECT
public:
explicit HomePageItem(QWidget *, const int&, const QString&);

View File

@ -22,8 +22,7 @@
#include <QDebug>
#include <QEvent>
OptionView::OptionView(QWidget *parent) : QWidget(parent)
{
OptionView::OptionView(QWidget *parent) : QWidget(parent) {
m_mainLyt = new QVBoxLayout(this);
this->setLayout(m_mainLyt);
m_mainLyt->setContentsMargins(0, 8, 0, 0);
@ -31,8 +30,7 @@ OptionView::OptionView(QWidget *parent) : QWidget(parent)
initUI();
}
OptionView::~OptionView()
{
OptionView::~OptionView() {
if(m_openLabel) {
delete m_openLabel;
m_openLabel = NULL;
@ -91,8 +89,7 @@ void OptionView::setupOptions(const int& type, bool is_appInstalled) {
}
void OptionView::initUI()
{
void OptionView::initUI() {
m_optionFrame = new QFrame(this);
m_optionLyt = new QVBoxLayout(m_optionFrame);
m_optionLyt->setContentsMargins(8, 0, 0, 0);
@ -180,8 +177,7 @@ void OptionView::setupOptionLabel(const int& opt) {
}
}
void OptionView::hideOptions()
{
void OptionView::hideOptions() {
m_openLabel->hide();
m_shortcutLabel->hide();
m_panelLabel->hide();

View File

@ -28,8 +28,7 @@
#include <QHBoxLayout>
#include "search-list-view.h"
class OptionView : public QWidget
{
class OptionView : public QWidget {
Q_OBJECT
public:
explicit OptionView(QWidget *);

View File

@ -37,13 +37,11 @@
//#include <QWebEngineCookieStore>
#include "config-file.h"
SearchDetailView::SearchDetailView(QWidget *parent) : QWidget(parent)
{
SearchDetailView::SearchDetailView(QWidget *parent) : QWidget(parent) {
initUI();
}
SearchDetailView::~SearchDetailView()
{
SearchDetailView::~SearchDetailView() {
if(m_layout) {
delete m_layout;
m_layout = NULL;
@ -101,8 +99,7 @@ void SearchDetailView::setContent(const QString& text, const QString& keyword) {
* @brief SearchDetailView::isEmpty
* @return
*/
bool SearchDetailView::isEmpty()
{
bool SearchDetailView::isEmpty() {
return m_isEmpty;
}
@ -110,8 +107,7 @@ bool SearchDetailView::isEmpty()
* @brief SearchDetailView::getType
* @return
*/
int SearchDetailView::getType()
{
int SearchDetailView::getType() {
return m_type;
}
@ -119,8 +115,7 @@ int SearchDetailView::getType()
* @brief SearchDetailView::setWebWidget
* @param keyword
*/
void SearchDetailView::setWebWidget(const QString& keyword)
{
void SearchDetailView::setWebWidget(const QString& keyword) {
clearLayout();
m_isEmpty = false;
m_reload = false;
@ -191,8 +186,7 @@ void SearchDetailView::setWebWidget(const QString& keyword)
// m_webView->show();
}
void SearchDetailView::setAppWidget(const QString &appname, const QString &path, const QString &iconpath, const QString &description)
{
void SearchDetailView::setAppWidget(const QString &appname, const QString &path, const QString &iconpath, const QString &description) {
m_type = SearchListView::ResType::App;
m_path = path;
m_name = appname.contains("/") ? appname.left(appname.indexOf("/")) : appname;
@ -235,8 +229,7 @@ void SearchDetailView::setAppWidget(const QString &appname, const QString &path,
m_typeLabel->setText(tr("Application"));
}
void SearchDetailView::closeWebWidget()
{
void SearchDetailView::closeWebWidget() {
// if (m_webView) {
// m_webView->close();
// m_webView = NULL;
@ -249,8 +242,7 @@ void SearchDetailView::closeWebWidget()
* @param path
* @return
*/
bool SearchDetailView::doubleClickAction(const int &type, const QString &path)
{
bool SearchDetailView::doubleClickAction(const int &type, const QString &path) {
if(type == SearchListView::ResType::App && !path.contains(".desktop")) {
return installAppAction(path.mid(path.indexOf("/") + 1));
} else {
@ -289,8 +281,7 @@ QString SearchDetailView::getHtmlText(const QString & text, const QString & keyw
* @param str
* @return
*/
QString SearchDetailView::escapeHtml(const QString & str)
{
QString SearchDetailView::escapeHtml(const QString & str) {
QString temp = str;
temp.replace("<", "&lt;");
temp.replace(">", "&gt;");
@ -474,8 +465,7 @@ bool SearchDetailView::writeConfigFile(const QString& path) {
/**
* @brief SearchDetailView::initUI ui
*/
void SearchDetailView::initUI()
{
void SearchDetailView::initUI() {
m_layout = new QVBoxLayout(this);
this->setLayout(m_layout);
m_layout->setContentsMargins(16, 60, 16, 24);
@ -587,8 +577,7 @@ bool SearchDetailView::addDesktopShortcut(const QString& path) {
QFile file(path);
QString newName = QString(dirpath + "/" + desktopfn);
bool ret = file.copy(QString(dirpath + "/" + desktopfn));
if(ret)
{
if(ret) {
QProcess process;
process.startDetached(QString("chmod a+x %1").arg(newName));
return true;
@ -641,8 +630,7 @@ bool SearchDetailView::copyPathAction(const QString& path) {
* @param name
* @return
*/
bool SearchDetailView::installAppAction(const QString & name)
{
bool SearchDetailView::installAppAction(const QString & name) {
QDBusInterface * interface = new QDBusInterface("com.kylin.softwarecenter",
"/com/kylin/softwarecenter",
"com.kylin.utiliface",

View File

@ -30,8 +30,7 @@
#include "option-view.h"
#include "global-settings.h"
class SearchDetailView : public QWidget
{
class SearchDetailView : public QWidget {
Q_OBJECT
public:
explicit SearchDetailView(QWidget *parent = nullptr);

View File

@ -23,8 +23,7 @@
#include <QFileInfo>
#include "custom-style.h"
SearchListView::SearchListView(QWidget * parent, const QStringList& list, const int& type) : QTreeView(parent)
{
SearchListView::SearchListView(QWidget * parent, const QStringList& list, const int& type) : QTreeView(parent) {
CustomStyle * style = new CustomStyle(GlobalSettings::getInstance()->getValue(STYLE_NAME_KEY).toString());
this->setStyle(style);
@ -51,8 +50,7 @@ SearchListView::SearchListView(QWidget * parent, const QStringList& list, const
connect(this->selectionModel(), &QItemSelectionModel::selectionChanged, this, [ = ](const QItemSelection & selected, const QItemSelection & deselected) {
Q_EMIT this->currentRowChanged(this, getCurrentType(), m_item->m_pathlist.at(this->currentIndex().row()));
m_isSelected = true;
if(!selected.isEmpty())
{
if(!selected.isEmpty()) {
QRegion region = visualRegionForSelection(selected);
QRect rect = region.boundingRect();
Q_EMIT this->currentSelectPos(mapToParent(rect.topLeft()));
@ -64,8 +62,7 @@ SearchListView::SearchListView(QWidget * parent, const QStringList& list, const
});
}
SearchListView::~SearchListView()
{
SearchListView::~SearchListView() {
if(m_model) {
delete m_model;
m_model = NULL;
@ -88,8 +85,7 @@ void SearchListView::appendItem(QString path) {
/**
* @brief SearchListView::setList
*/
void SearchListView::setList(QStringList list)
{
void SearchListView::setList(QStringList list) {
QModelIndex index = this->currentIndex();
m_model->setList(list);
if(index.row() >= 0 && index.row() < list.length() && m_isSelected) {
@ -101,13 +97,11 @@ void SearchListView::setList(QStringList list)
this->setFixedHeight(m_item->getCurrentSize() * rowheight + 4);
}
void SearchListView::setAppList(const QStringList &pathlist, const QStringList &iconlist)
{
void SearchListView::setAppList(const QStringList &pathlist, const QStringList &iconlist) {
m_model->setAppList(pathlist, iconlist);
}
void SearchListView::appendBestItem(const QPair<int, QString> &pair)
{
void SearchListView::appendBestItem(const QPair<int, QString> &pair) {
m_model->appendBestItem(pair);
}
@ -118,8 +112,7 @@ void SearchListView::removeItem(QString path) {
m_model->removeItem(path);
}
void SearchListView::clear()
{
void SearchListView::clear() {
this->blockSignals(true);
this->clearSelection();
this->blockSignals(false);
@ -132,8 +125,7 @@ void SearchListView::clear()
* @brief SearchListView::setKeyword
* @param keyword
*/
void SearchListView::setKeyword(QString keyword)
{
void SearchListView::setKeyword(QString keyword) {
m_styleDelegate->setSearchKeyword(keyword);
}
@ -141,8 +133,7 @@ void SearchListView::setKeyword(QString keyword)
* @brief SearchListView::getType
* @return
*/
int SearchListView::getType()
{
int SearchListView::getType() {
return m_type;
}
@ -150,15 +141,12 @@ int SearchListView::getType()
* @brief SearchListView::getLength
* @return
*/
int SearchListView::getLength()
{
int SearchListView::getLength() {
return m_item->getCurrentSize();
}
void SearchListView::mousePressEvent(QMouseEvent *event)
{
if(event->button() == Qt::LeftButton)
{
void SearchListView::mousePressEvent(QMouseEvent *event) {
if(event->button() == Qt::LeftButton) {
Q_EMIT mousePressed();
}
QTreeView::mousePressEvent(event);

View File

@ -28,8 +28,7 @@
#include "model/search-item.h"
#include "highlight-item-delegate.h"
class SearchListView : public QTreeView
{
class SearchListView : public QTreeView {
Q_OBJECT
public:
explicit SearchListView(QWidget *, const QStringList&, const int&);

View File

@ -22,20 +22,17 @@
#include <QEvent>
#include <QDebug>
ShowMoreLabel::ShowMoreLabel(QWidget *parent) : QWidget(parent)
{
ShowMoreLabel::ShowMoreLabel(QWidget *parent) : QWidget(parent) {
initUi();
m_timer = new QTimer;
connect(m_timer, &QTimer::timeout, this, &ShowMoreLabel::refreshLoadState);
connect(this, &ShowMoreLabel::showMoreClicked, this, &ShowMoreLabel::startLoading);
}
ShowMoreLabel::~ShowMoreLabel()
{
ShowMoreLabel::~ShowMoreLabel() {
}
void ShowMoreLabel::resetLabel()
{
void ShowMoreLabel::resetLabel() {
m_isOpen = false;
m_textLabel->setText(tr("Show More..."));
}
@ -44,13 +41,11 @@ void ShowMoreLabel::resetLabel()
* @brief ShowMoreLabel::getExpanded
* @return true已展开false已收起
*/
bool ShowMoreLabel::getExpanded()
{
bool ShowMoreLabel::getExpanded() {
return m_isOpen;
}
void ShowMoreLabel::initUi()
{
void ShowMoreLabel::initUi() {
m_layout = new QHBoxLayout(this);
m_layout->setContentsMargins(0, 0, 0, 6);
m_textLabel = new QLabel(this);
@ -66,16 +61,14 @@ void ShowMoreLabel::initUi()
// m_layout->addWidget(m_loadingIconLabel);
}
void ShowMoreLabel::startLoading()
{
void ShowMoreLabel::startLoading() {
// m_textLabel->hide();
// m_loadingIconLabel->show();
m_timer->start(0.4 * 1000);
m_textLabel->setCursor(QCursor(Qt::ArrowCursor));
}
void ShowMoreLabel::stopLoading()
{
void ShowMoreLabel::stopLoading() {
// m_loadingIconLabel->hide();
// m_textLabel->show();
if(m_timer->isActive()) {
@ -89,8 +82,7 @@ void ShowMoreLabel::stopLoading()
m_textLabel->setCursor(QCursor(Qt::PointingHandCursor));
}
void ShowMoreLabel::refreshLoadState()
{
void ShowMoreLabel::refreshLoadState() {
switch(m_currentState) {
case 0: {
m_textLabel->setText(tr("Loading"));

View File

@ -26,8 +26,7 @@
#include <QHBoxLayout>
#include <QTimer>
class ShowMoreLabel : public QWidget
{
class ShowMoreLabel : public QWidget {
Q_OBJECT
public:
explicit ShowMoreLabel(QWidget *parent = nullptr);

View File

@ -22,19 +22,16 @@
#include <QPainter>
#include <QStyleOption>
TitleLabel::TitleLabel(QWidget * parent) : QLabel(parent)
{
TitleLabel::TitleLabel(QWidget * parent) : QLabel(parent) {
this->setContentsMargins(8, 0, 0, 0);
this->setFixedHeight(24);
}
TitleLabel::~TitleLabel()
{
TitleLabel::~TitleLabel() {
}
void TitleLabel::paintEvent(QPaintEvent * event)
{
void TitleLabel::paintEvent(QPaintEvent * event) {
Q_UNUSED(event)
QStyleOption opt;

View File

@ -23,8 +23,7 @@
#include <QLabel>
class TitleLabel : public QLabel
{
class TitleLabel : public QLabel {
public:
TitleLabel(QWidget * parent = nullptr);
~TitleLabel();

View File

@ -22,16 +22,14 @@
#include "create-index-ask-dialog.h"
#include <QPainter>
CreateIndexAskDialog::CreateIndexAskDialog(QWidget *parent) : QDialog(parent)
{
CreateIndexAskDialog::CreateIndexAskDialog(QWidget *parent) : QDialog(parent) {
this->setWindowIcon(QIcon::fromTheme("kylin-search"));
this->setWindowTitle(tr("ukui-search"));
initUi();
}
void CreateIndexAskDialog::initUi()
{
void CreateIndexAskDialog::initUi() {
this->setFixedSize(380, 202);
m_mainLyt = new QVBoxLayout(this);
this->setLayout(m_mainLyt);
@ -116,8 +114,7 @@ void CreateIndexAskDialog::initUi()
/**
* @brief CreateIndexAskDialog::paintEvent
*/
void CreateIndexAskDialog::paintEvent(QPaintEvent *event)
{
void CreateIndexAskDialog::paintEvent(QPaintEvent *event) {
Q_UNUSED(event)
QPainter p(this);

View File

@ -31,8 +31,7 @@
#include <QPushButton>
#include <QStyleOption>
class CreateIndexAskDialog : public QDialog
{
class CreateIndexAskDialog : public QDialog {
Q_OBJECT
public:
CreateIndexAskDialog(QWidget *parent = nullptr);

View File

@ -21,19 +21,19 @@
#include "custom-style.h"
CustomStyle::CustomStyle(const QString &proxyStyleName, QObject *parent) : QProxyStyle(proxyStyleName)
{
CustomStyle::CustomStyle(const QString &proxyStyleName, QObject *parent) : QProxyStyle(proxyStyleName) {
}
QSize CustomStyle::sizeFromContents(QStyle::ContentsType type, const QStyleOption *option, const QSize &contentsSize, const QWidget *widget) const
{
QSize CustomStyle::sizeFromContents(QStyle::ContentsType type, const QStyleOption *option, const QSize &contentsSize, const QWidget *widget) const {
switch(type) {
case CT_ItemViewItem: {
QSize size(0, GlobalSettings::getInstance()->getValue(FONT_SIZE_KEY).toDouble() * 2);
return size;
} break;
default: break;
}
break;
default:
break;
}
return QProxyStyle::sizeFromContents(type, option, contentsSize, widget);
}

View File

@ -24,8 +24,7 @@
#include <QProxyStyle>
#include "global-settings.h"
class CustomStyle : public QProxyStyle
{
class CustomStyle : public QProxyStyle {
Q_OBJECT
public:
explicit CustomStyle(const QString &proxyStyleName = "windows", QObject *parent = nullptr);

View File

@ -23,39 +23,32 @@
/**
* @brief ukui-search顶部搜索界面
*/
SeachBarWidget::SeachBarWidget(QWidget *parent):QWidget(parent)
{
SeachBarWidget::SeachBarWidget(QWidget *parent): QWidget(parent) {
}
SeachBarWidget::~SeachBarWidget()
{
SeachBarWidget::~SeachBarWidget() {
}
/**
* @brief ukui-search ui
*/
SeachBar::SeachBar()
{
SeachBar::SeachBar() {
setFocusPolicy(Qt::NoFocus);
}
SearchBarWidgetLayout::SearchBarWidgetLayout()
{
SearchBarWidgetLayout::SearchBarWidgetLayout() {
}
SearchBarWidgetLayout::~SearchBarWidgetLayout()
{
SearchBarWidgetLayout::~SearchBarWidgetLayout() {
}
SeachBar::~SeachBar()
{
SeachBar::~SeachBar() {
}
/**
* @brief
*/
SearchBarHLayout::SearchBarHLayout(QWidget *parent):QHBoxLayout(parent)
{
SearchBarHLayout::SearchBarHLayout(QWidget *parent): QHBoxLayout(parent) {
initUI();
m_timer = new QTimer;
@ -80,14 +73,12 @@ SearchBarHLayout::SearchBarHLayout(QWidget *parent):QHBoxLayout(parent)
});
}
SearchBarHLayout::~SearchBarHLayout()
{
SearchBarHLayout::~SearchBarHLayout() {
if(m_timer) {
delete m_timer;
m_timer = NULL;
}
if(m_queryLineEdit)
{
if(m_queryLineEdit) {
delete m_queryLineEdit;
m_queryLineEdit = nullptr;
}
@ -96,8 +87,7 @@ SearchBarHLayout::~SearchBarHLayout()
/**
* @brief ui
*/
void SearchBarHLayout::initUI()
{
void SearchBarHLayout::initUI() {
m_queryLineEdit = new SearchLineEdit();
m_queryLineEdit->installEventFilter(this);
m_queryLineEdit->setTextMargins(30, 1, 0, 1);
@ -145,8 +135,7 @@ void SearchBarHLayout::initUI()
});
}
void SearchBarHLayout::effectiveSearchRecord()
{
void SearchBarHLayout::effectiveSearchRecord() {
m_queryLineEdit->record();
}
@ -172,8 +161,7 @@ QString SearchBarHLayout::text() {
return m_queryLineEdit->text();
}
bool SearchBarHLayout::eventFilter(QObject *watched, QEvent *event)
{
bool SearchBarHLayout::eventFilter(QObject *watched, QEvent *event) {
if(watched == m_queryLineEdit) {
if(event->type() == QEvent::FocusIn) {
if(m_queryLineEdit->text().isEmpty()) {
@ -205,8 +193,7 @@ bool SearchBarHLayout::eventFilter(QObject *watched, QEvent *event)
/**
* @brief UKuiSearchLineEdit
*/
SearchLineEdit::SearchLineEdit()
{
SearchLineEdit::SearchLineEdit() {
this->setFocusPolicy(Qt::ClickFocus);
this->installEventFilter(this);
// this->setContextMenuPolicy(Qt::NoContextMenu);
@ -237,8 +224,7 @@ SearchLineEdit::SearchLineEdit()
});
}
void SearchLineEdit::record()
{
void SearchLineEdit::record() {
if(m_isRecorded == true || text().size() <= 1 || text().isEmpty())
return;
GlobalSettings::getInstance()->setSearchRecord(text(), QDateTime::currentDateTime());
@ -246,8 +232,7 @@ void SearchLineEdit::record()
m_model->setStringList(GlobalSettings::getInstance()->getSearchRecord());
}
SearchLineEdit::~SearchLineEdit()
{
SearchLineEdit::~SearchLineEdit() {
}
@ -259,8 +244,7 @@ SearchLineEdit::~SearchLineEdit()
* QDBusConnection::sessionBus().connect(QString(), QString("/lineEdit/textChanged"), "org.ukui.search.inputbox", "InputBoxTextChanged", this, SLOT(client_get(QString)));
* client_get(void) 
*/
void SearchLineEdit::lineEditTextChanged(QString arg)
{
void SearchLineEdit::lineEditTextChanged(QString arg) {
QDBusMessage message = QDBusMessage::createSignal("/lineEdit/textChanged", "org.ukui.search.inputbox", "InputBoxTextChanged");
message << arg;
QDBusConnection::sessionBus().send(message);

View File

@ -34,15 +34,13 @@
class SearchLineEdit;
class SeachBarWidget:public QWidget
{
class SeachBarWidget: public QWidget {
public:
SeachBarWidget(QWidget *parent = nullptr);
~SeachBarWidget();
};
class SeachBar:public QWidget
{
class SeachBar: public QWidget {
public:
SeachBar();
~SeachBar();
@ -51,8 +49,7 @@ private:
// QLineEdit *m_queryLineEdit=nullptr;
};
class SearchBarHLayout : public QHBoxLayout
{
class SearchBarHLayout : public QHBoxLayout {
Q_OBJECT
public:
SearchBarHLayout(QWidget *parent = nullptr);
@ -83,8 +80,7 @@ public Q_SLOTS:
void effectiveSearchRecord();
};
class SearchBarWidgetLayout : public QHBoxLayout
{
class SearchBarWidgetLayout : public QHBoxLayout {
public:
SearchBarWidgetLayout();
~SearchBarWidgetLayout();
@ -93,8 +89,7 @@ private:
};
class SearchLineEdit : public QLineEdit
{
class SearchLineEdit : public QLineEdit {
Q_OBJECT
/*

View File

@ -143,8 +143,7 @@ void searchMethod(FileUtils::SearchMethod sm){
qWarning() << "searchMethod end: " << static_cast<int>(FileUtils::searchMethod);
}
*/
int main(int argc, char *argv[])
{
int main(int argc, char *argv[]) {
//Init log module
initUkuiLog4qt("ukui-search");
@ -152,21 +151,18 @@ int main(int argc, char *argv[])
char *p_home = NULL;
unsigned int i = 0;
while(p_home == NULL)
{
while(p_home == NULL) {
::sleep(1);
++i;
p_home = getenv("HOME");
if(i%5==0)
{
if(i % 5 == 0) {
qWarning() << "I can't find home! I'm done here!!";
printf("I can't find home! I'm done here!!");
syslog(LOG_ERR, "I can't find home! I'm done here!!\n");
}
}
p_home = NULL;
while(!QDir(QDir::homePath()).exists())
{
while(!QDir(QDir::homePath()).exists()) {
qWarning() << "Home is not exits!!";
printf("Home is not exits!!");
syslog(LOG_ERR, "Home is not exits!!\n");
@ -194,8 +190,7 @@ int main(int argc, char *argv[])
QtSingleApplication app("ukui-search", argc, argv);
app.setQuitOnLastWindowClosed(false);
if(app.isRunning())
{
if(app.isRunning()) {
app.sendMessage(QApplication::arguments().length() > 1 ? QApplication::arguments().at(1) : app.applicationFilePath());
qDebug() << QObject::tr("ukui-search is already running!");
return EXIT_SUCCESS;

View File

@ -50,8 +50,7 @@ extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int tran
*
*/
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
QMainWindow(parent) {
m_searcher = new SearchManager(this);
m_settingsMatch = new SettingsMatch(this);
@ -120,8 +119,7 @@ MainWindow::MainWindow(QWidget *parent) :
m_sys_tray_icon->setToolTip(tr("Global Search"));
m_sys_tray_icon->show();
connect(m_sys_tray_icon, &QSystemTrayIcon::activated, this, [ = ](QSystemTrayIcon::ActivationReason reason) {
if(reason == QSystemTrayIcon::Trigger)
{
if(reason == QSystemTrayIcon::Trigger) {
if(!this->isVisible()) {
clearSearchResult();
// this->moveToPanel();
@ -146,8 +144,7 @@ MainWindow::MainWindow(QWidget *parent) :
}
MainWindow::~MainWindow()
{
MainWindow::~MainWindow() {
if(m_searchWidget) {
delete m_searchWidget;
m_searchWidget = NULL;
@ -178,8 +175,7 @@ MainWindow::~MainWindow()
* @brief initUi
* this->setFixedSize(640, 640);
*/
void MainWindow::initUi()
{
void MainWindow::initUi() {
this->setFixedSize(640, 590);
m_frame = new QFrame(this);
@ -321,8 +317,7 @@ void MainWindow::initUi()
* @brief bootOptionsFilter
* @param opt
*/
void MainWindow::bootOptionsFilter(QString opt)
{
void MainWindow::bootOptionsFilter(QString opt) {
if(opt == "-s" || opt == "--show") {
clearSearchResult();
// this->moveToPanel();
@ -347,8 +342,7 @@ void MainWindow::clearSearchResult() {
/**
* @brief MainWindow::createIndexSlot
*/
void MainWindow::createIndexSlot()
{
void MainWindow::createIndexSlot() {
}
/**
@ -360,8 +354,7 @@ void MainWindow::createIndexSlot()
* @brief monitorResolutionChange
* @param rect
*/
void MainWindow::monitorResolutionChange(QRect rect)
{
void MainWindow::monitorResolutionChange(QRect rect) {
Q_UNUSED(rect);
}
@ -369,8 +362,7 @@ void MainWindow::monitorResolutionChange(QRect rect)
* @brief primaryScreenChangedSlot
* @param screen
*/
void MainWindow::primaryScreenChangedSlot(QScreen *screen)
{
void MainWindow::primaryScreenChangedSlot(QScreen *screen) {
Q_UNUSED(screen);
}
@ -399,8 +391,7 @@ void MainWindow::searchContent(QString keyword){
/**
* @brief MainWindow::moveToPanel
*/
void MainWindow::moveToPanel()
{
void MainWindow::moveToPanel() {
QRect availableGeometry = qApp->primaryScreen()->availableGeometry();
QRect screenGeometry = qApp->primaryScreen()->geometry();
@ -476,8 +467,7 @@ void MainWindow::centerToScreen(QWidget* widget) {
widget->move(desk_x / 2 - x / 2 + desk_rect.left(), desk_y / 2 - y / 2 + desk_rect.top());
}
void MainWindow::initGsettings()
{
void MainWindow::initGsettings() {
const QByteArray id(UKUI_SEARCH_SCHEMAS);
if(QGSettings::isSchemaInstalled(id)) {
m_search_gsettings = new QGSettings(id);
@ -503,13 +493,11 @@ void MainWindow::initGsettings()
}
//使用GSetting获取当前窗口应该使用的透明度
double MainWindow::getTransparentData()
{
double MainWindow::getTransparentData() {
return GlobalSettings::getInstance()->getValue(TRANSPARENCY_KEY).toDouble();
}
void MainWindow::initTimer()
{
void MainWindow::initTimer() {
m_askTimer = new QTimer;
m_askTimer->setInterval(5 * 1000);
connect(m_askTimer, &QTimer::timeout, this, [ = ]() {
@ -534,8 +522,7 @@ void MainWindow::initTimer()
* @brief MainWindow::setSearchMethod
* @param is_index_search true为索引搜索false为暴力搜索
*/
void MainWindow::setSearchMethod(const bool &is_index_search)
{
void MainWindow::setSearchMethod(const bool &is_index_search) {
if(is_index_search) {
//调用创建索引接口
Q_EMIT this->searchMethodChanged(FileUtils::SearchMethod::INDEXSEARCH);
@ -554,8 +541,7 @@ void MainWindow::setSearchMethod(const bool &is_index_search)
* @param result
* @return
*/
bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)
{
bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result) {
Q_UNUSED(result);
if(eventType != "xcb_generic_event_t") {
return false;
@ -583,8 +569,7 @@ bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *r
return false;
}
void MainWindow::keyPressEvent(QKeyEvent *event)
{
void MainWindow::keyPressEvent(QKeyEvent *event) {
if(event->key() == Qt::Key_Escape) {
this->hide();
m_contentFrame->closeWebView();

View File

@ -59,8 +59,7 @@
#define WEB_ENGINE_KEY "webEngine"
class SearchResult;
class MainWindow : public QMainWindow
{
class MainWindow : public QMainWindow {
friend class SearchResult;
Q_OBJECT

View File

@ -21,8 +21,7 @@
#include "search-item-model.h"
#include <QDebug>
SearchItemModel::SearchItemModel(QObject *parent) : QAbstractItemModel (parent)
{
SearchItemModel::SearchItemModel(QObject *parent) : QAbstractItemModel(parent) {
}
SearchItemModel::~SearchItemModel() {
@ -36,8 +35,7 @@ SearchItemModel::~SearchItemModel(){
* @param parent
* @return
*/
QModelIndex SearchItemModel::index(int row, int column, const QModelIndex &parent) const
{
QModelIndex SearchItemModel::index(int row, int column, const QModelIndex &parent) const {
if(row < 0 || row > m_item->m_pathlist.count() - 1)
return QModelIndex();
return createIndex(row, column, m_item);
@ -48,8 +46,7 @@ QModelIndex SearchItemModel::index(int row, int column, const QModelIndex &paren
* @param child
* @return
*/
QModelIndex SearchItemModel::parent(const QModelIndex &child) const
{
QModelIndex SearchItemModel::parent(const QModelIndex &child) const {
return QModelIndex();
}
@ -59,8 +56,7 @@ QModelIndex SearchItemModel::parent(const QModelIndex &child) const
* @param index
* @return model显示的行数
*/
int SearchItemModel::rowCount(const QModelIndex& index) const
{
int SearchItemModel::rowCount(const QModelIndex& index) const {
return index.isValid() ? 0 : m_item->m_pathlist.count();
}
@ -69,8 +65,7 @@ int SearchItemModel::rowCount(const QModelIndex& index) const
* @param index
* @return model显示的列数
*/
int SearchItemModel::columnCount(const QModelIndex& index) const
{
int SearchItemModel::columnCount(const QModelIndex& index) const {
return index.isValid() ? 0 : 2;
}
@ -92,8 +87,7 @@ int SearchItemModel::columnCount(const QModelIndex& index) const
* @param role
* @return
*/
QVariant SearchItemModel::data(const QModelIndex &index, int role) const
{
QVariant SearchItemModel::data(const QModelIndex &index, int role) const {
if(!index.isValid())
return QVariant();
switch(index.column()) {
@ -123,8 +117,7 @@ QVariant SearchItemModel::data(const QModelIndex &index, int role) const
return QVariant();
}
bool SearchItemModel::insertRows(int row, int count, const QModelIndex &parent)
{
bool SearchItemModel::insertRows(int row, int count, const QModelIndex &parent) {
this->beginInsertRows(parent, row, count);
this->endInsertRows();
return true;
@ -152,15 +145,13 @@ void SearchItemModel::appendItem(QString path) {
* @brief SearchItemModel::setList
* @param list
*/
void SearchItemModel::setList(QStringList list)
{
void SearchItemModel::setList(QStringList list) {
this->beginResetModel();
m_item->m_pathlist = list;
this->endResetModel();
}
void SearchItemModel::setAppList(const QStringList &pathlist, const QStringList &iconlist)
{
void SearchItemModel::setAppList(const QStringList &pathlist, const QStringList &iconlist) {
this->beginResetModel();
m_item->m_app_pathlist = pathlist;
m_item->m_app_iconlist = iconlist;
@ -171,8 +162,7 @@ void SearchItemModel::setAppList(const QStringList &pathlist, const QStringList
* @brief SearchItemModel::insertBestItem
* @param pair <>
*/
void SearchItemModel::appendBestItem(const QPair<int, QString> & pair)
{
void SearchItemModel::appendBestItem(const QPair<int, QString> & pair) {
m_item->m_bestList.append(pair);
}
@ -183,8 +173,7 @@ void SearchItemModel::removeItem(QString path) {
m_item->removeItem(path);
}
void SearchItemModel::clear()
{
void SearchItemModel::clear() {
this->beginResetModel();
m_item->clear();
this->endResetModel();
@ -195,8 +184,7 @@ void SearchItemModel::clear()
* @param str
* @param is_installed
*/
void SearchItemModel::setBestAppIcon(const QString &str, const bool & is_installed)
{
void SearchItemModel::setBestAppIcon(const QString &str, const bool & is_installed) {
if(is_installed) {
m_item->m_bestAppIcon = QIcon::fromTheme(str);
} else {

View File

@ -27,8 +27,7 @@
class SearchItem;
class SearchItemModel : public QAbstractItemModel
{
class SearchItemModel : public QAbstractItemModel {
friend class SearchItem;
Q_OBJECT
public:

View File

@ -22,12 +22,10 @@
#include <QDebug>
#include <QFileInfo>
SearchItem::SearchItem(QObject *parent) : QObject(parent)
{
SearchItem::SearchItem(QObject *parent) : QObject(parent) {
}
SearchItem::~SearchItem()
{
SearchItem::~SearchItem() {
}
/**
@ -99,8 +97,7 @@ QString SearchItem::getName(int index) {
* @param index
* @return
*/
QIcon SearchItem::getBestIcon(const int &index)
{
QIcon SearchItem::getBestIcon(const int &index) {
// if (m_pathlist.at(index).endsWith(".desktop")) {
// return FileUtils::getAppIcon(m_pathlist.at(index));
// } else if (QFileInfo(m_pathlist.at(index)).isFile() || QFileInfo(m_pathlist.at(index)).isDir()) {
@ -128,8 +125,7 @@ QIcon SearchItem::getBestIcon(const int &index)
* @param index
* @return
*/
QString SearchItem::getBestName(const int &index)
{
QString SearchItem::getBestName(const int &index) {
if(m_bestList.isEmpty() || !m_bestList.length() > index) return "";
switch(m_bestList.at(index).first) {
case Apps: {
@ -167,8 +163,7 @@ int SearchItem::getCurrentSize() {
return m_pathlist.length();
}
void SearchItem::clear()
{
void SearchItem::clear() {
m_pathlist.clear();
m_app_pathlist.clear();
m_app_iconlist.clear();

View File

@ -26,8 +26,7 @@
#include "search-item-model.h"
#include "file-utils.h"
class SearchItem : public QObject
{
class SearchItem : public QObject {
friend class SearchItemModel;
friend class SearchListView;
Q_OBJECT

View File

@ -3,14 +3,12 @@
size_t uniqueSymbol = 0;
QMutex m_mutex;
SearchAppThread::SearchAppThread(QObject *parent) : QObject(parent)
{
SearchAppThread::SearchAppThread(QObject *parent) : QObject(parent) {
m_pool.setMaxThreadCount(1);
m_pool.setExpiryTimeout(1000);
}
void SearchAppThread::startSearch(const QString & keyword)
{
void SearchAppThread::startSearch(const QString & keyword) {
SearchApp *appsearch;
appsearch = new SearchApp(keyword);
// appsearch->setKeyword(keyword);
@ -19,13 +17,11 @@ void SearchAppThread::startSearch(const QString & keyword)
}
SearchApp::SearchApp(const QString& keyword, QObject * parent) : QObject(parent)
{
SearchApp::SearchApp(const QString& keyword, QObject * parent) : QObject(parent) {
m_keyword = keyword;
}
SearchApp::~SearchApp()
{
SearchApp::~SearchApp() {
}
///**
@ -37,8 +33,7 @@ SearchApp::~SearchApp()
// m_keyword = keyword;
//}
void SearchApp::run()
{
void SearchApp::run() {
m_mutex.lock();
uniqueSymbol++;
m_mutex.unlock();
@ -47,8 +42,7 @@ void SearchApp::run()
QVector<QStringList> appVector;
AppMatch::getAppMatch()->startMatchApp(m_keyword, m_installed_apps, m_uninstalled_apps);
QMapIterator<NameString, QStringList> installed_iter(m_installed_apps);
while(installed_iter.hasNext())
{
while(installed_iter.hasNext()) {
installed_iter.next();
nameList << installed_iter.key().app_name;
pathList << installed_iter.value().at(0);
@ -56,8 +50,7 @@ void SearchApp::run()
descList << installed_iter.value().at(3);
}
QMapIterator<NameString, QStringList> uninstalled_iter(m_uninstalled_apps);
while(uninstalled_iter.hasNext())
{
while(uninstalled_iter.hasNext()) {
uninstalled_iter.next();
QString name;
//当返回列表的value中含包名时将名称按“应用名/包名”的格式存储

View File

@ -5,8 +5,7 @@
#include <QRunnable>
#include "libsearch.h"
class SearchAppThread : public QObject
{
class SearchAppThread : public QObject {
Q_OBJECT
public:
@ -20,8 +19,7 @@ Q_SIGNALS:
};
class SearchApp : public QObject, public QRunnable
{
class SearchApp : public QObject, public QRunnable {
Q_OBJECT
public:
SearchApp(const QString& keyword, QObject * parent = nullptr);

View File

@ -20,8 +20,7 @@
*/
#include "search-result.h"
SearchResult::SearchResult(QObject * parent) : QThread(parent)
{
SearchResult::SearchResult(QObject * parent) : QThread(parent) {
m_mainwindow = static_cast<MainWindow *>(parent);
// m_timer = new QTimer;
// QObject::connect(m_timer, &QTimer::timeout, this, [ = ](){
@ -31,16 +30,14 @@ SearchResult::SearchResult(QObject * parent) : QThread(parent)
// });
}
SearchResult::~SearchResult()
{
SearchResult::~SearchResult() {
// if (m_timer) {
// delete m_timer;
// m_timer = NULL;
// }
}
void SearchResult::run()
{
void SearchResult::run() {
QTimer * m_timer = new QTimer;
m_timer->setInterval(3000);
int emptyLists = 0;

View File

@ -25,8 +25,7 @@
#include <QTimer>
#include "mainwindow.h"
class SearchResult : public QThread
{
class SearchResult : public QThread {
Q_OBJECT
public:
SearchResult(QObject * parent = nullptr);

View File

@ -30,8 +30,7 @@
#include "file-utils.h"
extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed);
SettingsWidget::SettingsWidget(QWidget *parent) : QWidget(parent)
{
SettingsWidget::SettingsWidget(QWidget *parent) : QWidget(parent) {
this->setWindowIcon(QIcon::fromTheme("kylin-search"));
this->setWindowTitle(tr("ukui-search-settings"));
// this->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint);
@ -48,8 +47,7 @@ SettingsWidget::SettingsWidget(QWidget *parent) : QWidget(parent)
resetWebEngine();
}
SettingsWidget::~SettingsWidget()
{
SettingsWidget::~SettingsWidget() {
}
/**
@ -250,8 +248,7 @@ void SettingsWidget::clearLayout(QLayout * layout) {
if(! layout) return;
QLayoutItem * child;
while((child = layout->takeAt(0)) != 0) {
if(child->widget())
{
if(child->widget()) {
child->widget()->setParent(NULL);
}
delete child;
@ -262,8 +259,7 @@ void SettingsWidget::clearLayout(QLayout * layout) {
/**
* @brief SettingsWidget::refreshIndexState
*/
void SettingsWidget::refreshIndexState()
{
void SettingsWidget::refreshIndexState() {
// qDebug()<<"FileUtils::_index_status: "<<FileUtils::_index_status;
if(FileUtils::_index_status != 0) {
this->setIndexState(true);
@ -317,8 +313,7 @@ void SettingsWidget::onBtnDelClicked(const QString& path) {
/**
* @brief SettingsWidget::resetWebEngine UI控件上
*/
void SettingsWidget::resetWebEngine()
{
void SettingsWidget::resetWebEngine() {
QString engine = GlobalSettings::getInstance()->getValue(WEB_ENGINE).toString();
m_engineBtnGroup->blockSignals(true);
if(!engine.isEmpty()) {
@ -339,8 +334,7 @@ void SettingsWidget::resetWebEngine()
* @brief SettingsWidget::setWebEngine
* @param engine
*/
void SettingsWidget::setWebEngine(const QString& engine)
{
void SettingsWidget::setWebEngine(const QString& engine) {
// GlobalSettings::getInstance()->setValue(WEB_ENGINE, engine);
Q_EMIT this->webEngineChanged(engine);
}
@ -368,8 +362,7 @@ void SettingsWidget::setIndexNum(int num) {
/**
* @brief SettingsWidget::showWidget
*/
void SettingsWidget::showWidget()
{
void SettingsWidget::showWidget() {
Qt::WindowFlags flags = this->windowFlags();
flags |= Qt::WindowStaysOnTopHint;
this->setWindowFlags(flags);
@ -479,8 +472,7 @@ void SettingsWidget::paintEvent(QPaintEvent *event) {
/**
* @brief SettingsWidget::resize
*/
void SettingsWidget::resize()
{
void SettingsWidget::resize() {
// if (m_blockdirs <= 1) {
// this->setFixedSize(528, 455);
// } else if (m_blockdirs <= 3) {
@ -502,8 +494,7 @@ void SettingsWidget::resize()
* @brief SettingsWidget::showWarningDialog
* @param errorCode
*/
void SettingsWidget::showWarningDialog(const int & errorCode)
{
void SettingsWidget::showWarningDialog(const int & errorCode) {
qWarning() << "Add block dir in onBtnAddClicked() failed. Code: " << errorCode << " ->settings-widget.cpp #238";
QString errorMessage;
switch(errorCode) {

View File

@ -35,8 +35,7 @@
#include <libsearch.h>
#include "xatom-helper.h"
class SettingsWidget : public QWidget
{
class SettingsWidget : public QWidget {
Q_OBJECT
public:
explicit SettingsWidget(QWidget *parent = nullptr);

View File

@ -61,8 +61,7 @@ namespace QtLP_Private {
const char* QtLocalPeer::ack = "ack";
QtLocalPeer::QtLocalPeer(QObject* parent, const QString &appId)
: QObject(parent), id(appId)
{
: QObject(parent), id(appId) {
QString prefix = id;
if(id.isEmpty()) {
id = QCoreApplication::applicationFilePath();
@ -103,8 +102,7 @@ QtLocalPeer::QtLocalPeer(QObject* parent, const QString &appId)
bool QtLocalPeer::isClient()
{
bool QtLocalPeer::isClient() {
if(lockFile.isLocked())
return false;
@ -127,8 +125,7 @@ bool QtLocalPeer::isClient()
}
bool QtLocalPeer::sendMessage(const QString &message, int timeout)
{
bool QtLocalPeer::sendMessage(const QString &message, int timeout) {
if(!isClient())
return false;
@ -166,8 +163,7 @@ bool QtLocalPeer::sendMessage(const QString &message, int timeout)
/**
* @brief QtLocalPeer::receiveConnection server,server接收到newConnection信号并触发此槽函数
*/
void QtLocalPeer::receiveConnection()
{
void QtLocalPeer::receiveConnection() {
QLocalSocket* socket = server->nextPendingConnection(); //获取新进程的socket
if(!socket)
return;

View File

@ -50,16 +50,16 @@
#include "qt-locked-file.h"
class QtLocalPeer : public QObject
{
class QtLocalPeer : public QObject {
Q_OBJECT
public:
QtLocalPeer(QObject *parent = 0, const QString &appId = QString());
bool isClient();
bool sendMessage(const QString &message, int timeout);
QString applicationId() const
{ return id; }
QString applicationId() const {
return id;
}
Q_SIGNALS:
void messageReceived(const QString &message);

View File

@ -46,8 +46,7 @@
#include "qt-locked-file.h"
bool QtLockedFile::lock(LockMode mode, bool block)
{
bool QtLockedFile::lock(LockMode mode, bool block) {
if(!isOpen()) {
qWarning("QtLockedFile::lock(): file is not opened");
return false;
@ -82,8 +81,7 @@ bool QtLockedFile::lock(LockMode mode, bool block)
}
bool QtLockedFile::unlock()
{
bool QtLockedFile::unlock() {
if(!isOpen()) {
qWarning("QtLockedFile::unlock(): file is not opened");
return false;
@ -108,8 +106,7 @@ bool QtLockedFile::unlock()
return true;
}
QtLockedFile::~QtLockedFile()
{
QtLockedFile::~QtLockedFile() {
if(isOpen())
unlock();
}

View File

@ -82,8 +82,7 @@
\sa QFile::QFile()
*/
QtLockedFile::QtLockedFile()
: QFile()
{
: QFile() {
#ifdef Q_OS_WIN
wmutex = 0;
rmutex = 0;
@ -99,8 +98,7 @@ QtLockedFile::QtLockedFile()
\sa QFile::QFile()
*/
QtLockedFile::QtLockedFile(const QString &name)
: QFile(name)
{
: QFile(name) {
#ifdef Q_OS_WIN
wmutex = 0;
rmutex = 0;
@ -121,8 +119,7 @@ QtLockedFile::QtLockedFile(const QString &name)
\sa QFile::open(), QFile::resize()
*/
bool QtLockedFile::open(OpenMode mode)
{
bool QtLockedFile::open(OpenMode mode) {
if(mode & QIODevice::Truncate) {
qWarning("QtLockedFile::open(): Truncate mode not allowed.");
return false;
@ -136,8 +133,7 @@ bool QtLockedFile::open(OpenMode mode)
\sa lockMode()
*/
bool QtLockedFile::isLocked() const
{
bool QtLockedFile::isLocked() const {
return m_lock_mode != NoLock;
}
@ -147,8 +143,7 @@ bool QtLockedFile::isLocked() const
\sa isLocked()
*/
QtLockedFile::LockMode QtLockedFile::lockMode() const
{
QtLockedFile::LockMode QtLockedFile::lockMode() const {
return m_lock_mode;
}

View File

@ -65,8 +65,7 @@
namespace QtLP_Private {
class QT_QTLOCKEDFILE_EXPORT QtLockedFile : public QFile
{
class QT_QTLOCKEDFILE_EXPORT QtLockedFile : public QFile {
public:
enum LockMode { NoLock = 0, ReadLock, WriteLock };

View File

@ -141,8 +141,7 @@
*/
void QtSingleApplication::sysInit(const QString &appId)
{
void QtSingleApplication::sysInit(const QString &appId) {
actWin = 0;
peer = new QtLocalPeer(this, appId);
// connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&)));
@ -161,8 +160,7 @@ void QtSingleApplication::sysInit(const QString &appId)
*/
QtSingleApplication::QtSingleApplication(int &argc, char **argv, bool GUIenabled)
: QApplication(argc, argv, GUIenabled)
{
: QApplication(argc, argv, GUIenabled) {
sysInit();
}
@ -174,8 +172,7 @@ QtSingleApplication::QtSingleApplication(int &argc, char **argv, bool GUIenabled
*/
QtSingleApplication::QtSingleApplication(const QString &appId, int &argc, char **argv)
: QApplication(argc, argv)
{
: QApplication(argc, argv) {
sysInit(appId);
}
@ -187,8 +184,7 @@ QtSingleApplication::QtSingleApplication(const QString &appId, int &argc, char *
argv, and \a type are passed on to the QAppliation constructor.
*/
QtSingleApplication::QtSingleApplication(int &argc, char **argv, Type type)
: QApplication(argc, argv, type)
{
: QApplication(argc, argv, type) {
sysInit();
}
@ -201,8 +197,7 @@ QtSingleApplication::QtSingleApplication(int &argc, char **argv, Type type)
and \a cmap are passed on to the QApplication constructor.
*/
QtSingleApplication::QtSingleApplication(Display* dpy, Qt::HANDLE visual, Qt::HANDLE cmap)
: QApplication(dpy, visual, cmap)
{
: QApplication(dpy, visual, cmap) {
sysInit();
}
@ -214,8 +209,7 @@ QtSingleApplication::QtSingleApplication(Display* dpy, Qt::HANDLE visual, Qt::HA
constructor.
*/
QtSingleApplication::QtSingleApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual, Qt::HANDLE cmap)
: QApplication(dpy, argc, argv, visual, cmap)
{
: QApplication(dpy, argc, argv, visual, cmap) {
sysInit();
}
@ -227,8 +221,7 @@ QtSingleApplication::QtSingleApplication(Display *dpy, int &argc, char **argv, Q
constructor.
*/
QtSingleApplication::QtSingleApplication(Display* dpy, const QString &appId, int argc, char **argv, Qt::HANDLE visual, Qt::HANDLE cmap)
: QApplication(dpy, argc, argv, visual, cmap)
{
: QApplication(dpy, argc, argv, visual, cmap) {
sysInit(appId);
}
# endif // Q_WS_X11
@ -246,8 +239,7 @@ QtSingleApplication::QtSingleApplication(Display* dpy, const QString &appId, int
\sa sendMessage()
*/
bool QtSingleApplication::isRunning()
{
bool QtSingleApplication::isRunning() {
return peer->isClient();
}
@ -265,8 +257,7 @@ bool QtSingleApplication::isRunning()
\sa isRunning(), messageReceived()
*/
bool QtSingleApplication::sendMessage(const QString &message, int timeout)
{
bool QtSingleApplication::sendMessage(const QString &message, int timeout) {
return peer->sendMessage(message, timeout);
}
@ -275,8 +266,7 @@ bool QtSingleApplication::sendMessage(const QString &message, int timeout)
Returns the application identifier. Two processes with the same
identifier will be regarded as instances of the same application.
*/
QString QtSingleApplication::id() const
{
QString QtSingleApplication::id() const {
return peer->applicationId();
}
@ -293,8 +283,7 @@ QString QtSingleApplication::id() const
\sa activateWindow(), messageReceived()
*/
void QtSingleApplication::setActivationWindow(QWidget* aw, bool activateOnMessage)
{
void QtSingleApplication::setActivationWindow(QWidget* aw, bool activateOnMessage) {
actWin = aw;
//目前不需要用到此处的置顶方法,故此信号槽暂时注释掉,若后续需要根据新起进程传递的信号执行部分操作时可以把这里放开
// if (activateOnMessage)
@ -310,8 +299,7 @@ void QtSingleApplication::setActivationWindow(QWidget* aw, bool activateOnMessag
\sa setActivationWindow()
*/
QWidget* QtSingleApplication::activationWindow() const
{
QWidget* QtSingleApplication::activationWindow() const {
return actWin;
}
@ -330,8 +318,7 @@ QWidget* QtSingleApplication::activationWindow() const
\sa setActivationWindow(), messageReceived(), initialize()
*/
void QtSingleApplication::activateWindow()
{
void QtSingleApplication::activateWindow() {
//单例置顶策略由于bootOptionsFilter in mainwindow自带置顶策略故注掉此处
// if (actWin) {
// if(this->applicationState() & Qt::ApplicationInactive)

View File

@ -64,8 +64,7 @@ class QtLocalPeer;
# define QT_QTSINGLEAPPLICATION_EXPORT
#endif
class QT_QTSINGLEAPPLICATION_EXPORT QtSingleApplication : public QApplication
{
class QT_QTSINGLEAPPLICATION_EXPORT QtSingleApplication : public QApplication {
Q_OBJECT
public:
@ -87,8 +86,10 @@ public:
QWidget* activationWindow() const;
// Obsolete:
void initialize(bool dummy = true)
{ isRunning(); Q_UNUSED(dummy) }
void initialize(bool dummy = true) {
isRunning();
Q_UNUSED(dummy)
}
public Q_SLOTS:
bool sendMessage(const QString &message, int timeout = 5000);

View File

@ -32,15 +32,13 @@
static XAtomHelper *global_instance = nullptr;
XAtomHelper *XAtomHelper::getInstance()
{
XAtomHelper *XAtomHelper::getInstance() {
if(!global_instance)
global_instance = new XAtomHelper;
return global_instance;
}
bool XAtomHelper::isFrameLessWindow(int winId)
{
bool XAtomHelper::isFrameLessWindow(int winId) {
auto hints = getInstance()->getWindowMotifHint(winId);
if(hints.flags == MWM_HINTS_DECORATIONS && hints.functions == 1) {
return true;
@ -48,13 +46,11 @@ bool XAtomHelper::isFrameLessWindow(int winId)
return false;
}
bool XAtomHelper::isWindowDecorateBorderOnly(int winId)
{
bool XAtomHelper::isWindowDecorateBorderOnly(int winId) {
return isWindowMotifHintDecorateBorderOnly(getInstance()->getWindowMotifHint(winId));
}
bool XAtomHelper::isWindowMotifHintDecorateBorderOnly(const MotifWmHints &hint)
{
bool XAtomHelper::isWindowMotifHintDecorateBorderOnly(const MotifWmHints &hint) {
bool isDeco = false;
if(hint.flags & MWM_HINTS_DECORATIONS && hint.flags != MWM_HINTS_DECORATIONS) {
if(hint.decorations == MWM_DECOR_BORDER)
@ -63,14 +59,12 @@ bool XAtomHelper::isWindowMotifHintDecorateBorderOnly(const MotifWmHints &hint)
return isDeco;
}
bool XAtomHelper::isUKUICsdSupported()
{
bool XAtomHelper::isUKUICsdSupported() {
// fixme:
return false;
}
bool XAtomHelper::isUKUIDecorationWindow(int winId)
{
bool XAtomHelper::isUKUIDecorationWindow(int winId) {
if(m_ukuiDecorationAtion == None)
return false;
@ -97,8 +91,7 @@ bool XAtomHelper::isUKUIDecorationWindow(int winId)
return isUKUIDecoration;
}
UnityCorners XAtomHelper::getWindowBorderRadius(int winId)
{
UnityCorners XAtomHelper::getWindowBorderRadius(int winId) {
UnityCorners corners;
Atom type;
@ -128,8 +121,7 @@ UnityCorners XAtomHelper::getWindowBorderRadius(int winId)
return corners;
}
void XAtomHelper::setWindowBorderRadius(int winId, const UnityCorners &data)
{
void XAtomHelper::setWindowBorderRadius(int winId, const UnityCorners &data) {
if(m_unityBorderRadiusAtom == None)
return;
@ -139,8 +131,7 @@ void XAtomHelper::setWindowBorderRadius(int winId, const UnityCorners &data)
32, XCB_PROP_MODE_REPLACE, (const unsigned char *) &corners, sizeof(corners) / sizeof(corners[0]));
}
void XAtomHelper::setWindowBorderRadius(int winId, int topLeft, int topRight, int bottomLeft, int bottomRight)
{
void XAtomHelper::setWindowBorderRadius(int winId, int topLeft, int topRight, int bottomLeft, int bottomRight) {
if(m_unityBorderRadiusAtom == None)
return;
@ -150,16 +141,14 @@ void XAtomHelper::setWindowBorderRadius(int winId, int topLeft, int topRight, in
32, XCB_PROP_MODE_REPLACE, (const unsigned char *) &corners, sizeof(corners) / sizeof(corners[0]));
}
void XAtomHelper::setUKUIDecoraiontHint(int winId, bool set)
{
void XAtomHelper::setUKUIDecoraiontHint(int winId, bool set) {
if(m_ukuiDecorationAtion == None)
return;
XChangeProperty(QX11Info::display(), winId, m_ukuiDecorationAtion, m_ukuiDecorationAtion, 32, XCB_PROP_MODE_REPLACE, (const unsigned char *) &set, 1);
}
void XAtomHelper::setWindowMotifHint(int winId, const MotifWmHints &hints)
{
void XAtomHelper::setWindowMotifHint(int winId, const MotifWmHints &hints) {
if(m_unityBorderRadiusAtom == None)
return;
@ -167,8 +156,7 @@ void XAtomHelper::setWindowMotifHint(int winId, const MotifWmHints &hints)
32, XCB_PROP_MODE_REPLACE, (const unsigned char *)&hints, sizeof(MotifWmHints) / sizeof(ulong));
}
MotifWmHints XAtomHelper::getWindowMotifHint(int winId)
{
MotifWmHints XAtomHelper::getWindowMotifHint(int winId) {
MotifWmHints hints;
if(m_unityBorderRadiusAtom == None)
@ -193,8 +181,7 @@ MotifWmHints XAtomHelper::getWindowMotifHint(int winId)
return hints;
}
XAtomHelper::XAtomHelper(QObject *parent) : QObject(parent)
{
XAtomHelper::XAtomHelper(QObject *parent) : QObject(parent) {
if(!QX11Info::isPlatformX11())
return;
@ -203,13 +190,11 @@ XAtomHelper::XAtomHelper(QObject *parent) : QObject(parent)
m_ukuiDecorationAtion = XInternAtom(QX11Info::display(), "_KWIN_UKUI_DECORAION", false);
}
Atom XAtomHelper::registerUKUICsdNetWmSupportAtom()
{
Atom XAtomHelper::registerUKUICsdNetWmSupportAtom() {
// fixme:
return None;
}
void XAtomHelper::unregisterUKUICsdNetWmSupportAtom()
{
void XAtomHelper::unregisterUKUICsdNetWmSupportAtom() {
// fixme:
}

View File

@ -75,8 +75,7 @@ namespace UKUI {
class Decoration;
}
class XAtomHelper : public QObject
{
class XAtomHelper : public QObject {
// friend class UKUI::Decoration;
Q_OBJECT
public:

Some files were not shown because too many files have changed in this diff Show More