}
static
-string parse_data(const gchar *data)
+string parse_data(const gchar *data,
+ const gchar *oword)
{
if (!data)
return "";
- string res;
+ string mark;
guint32 data_size, sec_size = 0;
gchar *m_str;
const gchar *p = data;
data_size = *((guint32 *) p);
p += sizeof(guint32);
+ size_t iPlugin;
+ size_t nPlugins = pMStarDict->oStarDictPlugins->ParseDataPlugins.nplugins();
+ unsigned int parsed_size;
+ ParseResult parse_result;
+
while (guint32(p - data) < data_size) {
+ for (iPlugin = 0; iPlugin < nPlugins; iPlugin++) {
+ parse_result.clear();
+ if (pMStarDict->oStarDictPlugins->ParseDataPlugins.parse(iPlugin, p, &parsed_size, parse_result, oword)) {
+ p += parsed_size;
+ break;
+ }
+ }
+ if (iPlugin != nPlugins) {
+ for (std::list<ParseResultItem>::iterator it = parse_result.item_list.begin(); it != parse_result.item_list.end(); ++it) {
+ switch (it->type) {
+ case ParseResultItemType_mark:
+ g_debug("ParseResultItemType_mark");
+ mark += it->mark->pango;
+ break;
+ case ParseResultItemType_link:
+// g_debug("ParseResultItemType_link: %s", it->mark->pango.c_str());
+ mark += it->mark->pango;
+ break;
+ case ParseResultItemType_res:
+ {
+ g_debug("ParseResultItemType_res");
+ bool loaded = false;
+ if (it->res->type == "image") {
+ } else if (it->res->type == "sound") {
+ } else if (it->res->type == "video") {
+ } else {
+ }
+ if (!loaded) {
+ mark += "<span foreground=\"red\">";
+ gchar *m_str = g_markup_escape_text(it->res->key.c_str(), -1);
+ mark += m_str;
+ g_free(m_str);
+ mark += "</span>";
+ }
+ break;
+ }
+ case ParseResultItemType_widget:
+ g_debug("ParseResultItemType_widget");
+ break;
+ default:
+ g_debug("ParseResultItemType_default");
+ break;
+ }
+ }
+ parse_result.clear();
+ continue;
+ }
+
switch (*p++) {
case 'g':
+ case 'h':
case 'm':
case 'l': //need more work...
sec_size = strlen(p);
if (sec_size) {
- res += "\n";
+ mark += "\n";
m_str = g_strndup(p, sec_size);
- res += m_str;
+ mark += m_str;
g_free(m_str);
}
sec_size++;
case 'x':
sec_size = strlen(p);
if (sec_size) {
- res += "\n";
+ mark += "\n";
m_str = g_strndup(p, sec_size);
- res += xdxf2text(m_str);
+ mark += xdxf2text(m_str);
g_free(m_str);
}
sec_size++;
case 't':
sec_size = strlen(p);
if (sec_size) {
- res += "\n";
+ mark += "\n";
m_str = g_strndup(p, sec_size);
- res += "[" + string(m_str) + "]";
+ mark += "[" + string(m_str) + "]";
g_free(m_str);
}
sec_size++;
p += sec_size;
}
- return res;
+ return mark;
}
void
sizeof(CurrentIndex) *
query_dictmask.size());
- pMStarDict->ResultsListClear();
+ oStarDict->ResultsListClear();
int iWordCount = 0;
const gchar *poCurrentWord = poGetCurrentWord(iIndex, query_dictmask, 0);
if (poCurrentWord) {
- pMStarDict->ResultsListInsertLast(poCurrentWord);
+ oStarDict->ResultsListInsertLast(poCurrentWord);
iWordCount++;
while (iWordCount < 30 && (poCurrentWord = poGetNextWord(NULL, iIndex, query_dictmask, 0))) {
- pMStarDict->ResultsListInsertLast(poCurrentWord);
+ oStarDict->ResultsListInsertLast(poCurrentWord);
iWordCount++;
}
}
- pMStarDict->ReScroll();
+ oStarDict->ResultsReScroll();
if (iCurrent)
g_free(iCurrent);
int iRealLib;
bool bFound = false, bLookupWord = false, bLookupSynonymWord = false;
gint nWord = 0, count = 0, i = 0, j = 0;
+ glong iWordIdx;
iRealLib = dictmask[iLib].index;
count = GetOrigWordCount(iIndex[iLib].idx, iRealLib, true);
for (i = 0; i < count; i++) {
res_list.push_back(TSearchResult(dict_name(iLib),
- poGetWord(iIndex[iLib].idx, iRealLib,
- 0),
- parse_data
- (poGetOrigWordData
- (iIndex[iLib].idx + i, iRealLib))));
+ poGetOrigWord(iIndex[iLib].idx, iRealLib),
+ parse_data(poGetOrigWordData(iIndex[iLib].idx + i, iRealLib),
+ poGetOrigWord(iIndex[iLib].idx, iRealLib))));
}
i = 1;
} else {
i = 0;
}
for (j = 0; i < nWord; i++, j++) {
+ iWordIdx = poGetOrigSynonymWordIdx(iIndex[iLib].synidx + j, iRealLib);
res_list.push_back(TSearchResult(dict_name(iLib),
- poGetWord(iIndex[iLib].synidx + j,
- iRealLib, 0),
- parse_data(poGetOrigWordData
- (iIndex[iLib].synidx + j, iRealLib))));
+ poGetOrigWord(iWordIdx, iRealLib),
+ parse_data(poGetOrigWordData(iWordIdx, iRealLib),
+ poGetOrigWord(iWordIdx, iRealLib))));
}
bFound = true;
gchar *fuzzy_reslist[MAX_FUZZY_MATCH_ITEM];
bool bFound = false;
- pMStarDict->ResultsListClear();
+ oStarDict->ResultsListClear();
bFound = Libs::LookupWithFuzzy(sWord, fuzzy_reslist, MAX_FUZZY_MATCH_ITEM, query_dictmask);
if (bFound) {
SimpleLookup(fuzzy_reslist[0], iCurrentIndex);
for (int i = 0; i < MAX_FUZZY_MATCH_ITEM && fuzzy_reslist[i]; i++) {
- pMStarDict->ResultsListInsertLast(fuzzy_reslist[i]);
+ oStarDict->ResultsListInsertLast(fuzzy_reslist[i]);
g_free(fuzzy_reslist[i]);
}
- pMStarDict->ReScroll();
+ oStarDict->ResultsReScroll();
}
return bFound;
gchar **ppMatchWord =
(gchar **) g_malloc(sizeof(gchar *) * (MAX_MATCH_ITEM_PER_LIB) * query_dictmask.size());
- pMStarDict->ResultsListClear();
+ oStarDict->ResultsListClear();
iMatchCount = Libs::LookupWithRule(sWord, ppMatchWord, query_dictmask);
if (iMatchCount) {
for (gint i = 0; i < iMatchCount; i++)
- pMStarDict->ResultsListInsertLast(ppMatchWord[i]);
+ oStarDict->ResultsListInsertLast(ppMatchWord[i]);
SimpleLookup(ppMatchWord[0], iCurrentIndex);
- pMStarDict->ReScroll();
+ oStarDict->ResultsReScroll();
for (gint i = 0; i < iMatchCount; i++)
g_free(ppMatchWord[i]);
gchar **ppMatchWord =
(gchar **) g_malloc(sizeof(gchar *) * (MAX_MATCH_ITEM_PER_LIB) * query_dictmask.size());
- pMStarDict->ResultsListClear();
+ oStarDict->ResultsListClear();
iMatchCount = Libs::LookupWithRegex(sWord, ppMatchWord, query_dictmask);
if (iMatchCount) {
for (gint i = 0; i < iMatchCount; i++)
- pMStarDict->ResultsListInsertLast(ppMatchWord[i]);
+ oStarDict->ResultsListInsertLast(ppMatchWord[i]);
SimpleLookup(ppMatchWord[0], iCurrentIndex);
- pMStarDict->ReScroll();
+ oStarDict->ResultsReScroll();
for (gint i = 0; i < iMatchCount; i++)
g_free(ppMatchWord[i]);
return bFound;
}
+static void
+LookupProgressDialogUpdate(gpointer data,
+ double fraction)
+{
+ GtkWidget *dialog = GTK_WIDGET(data);
+ GtkWidget *progress;
+
+ progress = GTK_WIDGET(g_object_get_data(G_OBJECT(dialog), "progress_bar"));
+ gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress), fraction);
+
+ while (gtk_events_pending())
+ gtk_main_iteration();
+}
+
bool
Library::LookupData(const gchar *sWord)
{
+ GtkWidget *dialog;
bool cancel = false;
bool bFound = false;
std::vector < std::vector < gchar * > > reslist(query_dictmask.size());
- pMStarDict->ResultsListClear();
- pMStarDict->ShowProgressIndicator(true);
- bFound = Libs::LookupData(sWord, &reslist[0], NULL, NULL, &cancel, query_dictmask);
+ oStarDict->ResultsListClear();
+ oStarDict->ShowProgressIndicator(true);
+ dialog = oStarDict->CreateLookupProgressDialog(&cancel);
+
+ bFound = Libs::LookupData(sWord, &reslist[0], LookupProgressDialogUpdate, (gpointer) dialog, &cancel, query_dictmask);
if (bFound) {
for (size_t iLib = 0; iLib < query_dictmask.size(); iLib++) {
if (!reslist[iLib].empty()) {
for (std::vector < gchar *>::iterator i = reslist[iLib].begin();
i != reslist[iLib].end(); ++i) {
- pMStarDict->ResultsListInsertLast(*i);
+ oStarDict->ResultsListInsertLast(*i);
}
break;
}
}
- pMStarDict->ReScroll();
+ oStarDict->ResultsReScroll();
}
- pMStarDict->ShowProgressIndicator(false);
+ oStarDict->ShowProgressIndicator(false);
+ oStarDict->DestroyLookupProgressDialog(dialog);
return bFound;
}
-Library::Library():Libs(NULL, FALSE, 0, 0)
+Library::Library(MStarDict *mStarDict):Libs(NULL, FALSE, 0, 0)
{
+ oStarDict = mStarDict;
iCurrentIndex = NULL;
}