|
|
@ -71,7 +71,6 @@ bool operator== ( const docBookmark &s1, const docBookmark &s2)
|
|
|
|
|
|
|
|
|
|
|
|
int docMatchBookmark::findMatches(TQString doctext, bmkList &fBookmarks) {
|
|
|
|
int docMatchBookmark::findMatches(TQString doctext, bmkList &fBookmarks) {
|
|
|
|
FUNCTIONSETUP;
|
|
|
|
FUNCTIONSETUP;
|
|
|
|
// bmkList res;
|
|
|
|
|
|
|
|
int pos = 0, nr=0, found=0;
|
|
|
|
int pos = 0, nr=0, found=0;
|
|
|
|
#ifdef DEBUG
|
|
|
|
#ifdef DEBUG
|
|
|
|
DEBUGKPILOT<<"Finding matches of "<<pattern<<endl;
|
|
|
|
DEBUGKPILOT<<"Finding matches of "<<pattern<<endl;
|
|
|
@ -86,7 +85,7 @@ int docMatchBookmark::findMatches(TQString doctext, bmkList &fBookmarks) {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
++found;
|
|
|
|
++found;
|
|
|
|
if (found>=from && found<=to) {
|
|
|
|
if (found>=from && found<=to) {
|
|
|
|
fBookmarks.append(new docBookmark(pattern, pos));
|
|
|
|
fBookmarks.push_back(new docBookmark(pattern, pos));
|
|
|
|
++nr;
|
|
|
|
++nr;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -101,7 +100,6 @@ int docMatchBookmark::findMatches(TQString doctext, bmkList &fBookmarks) {
|
|
|
|
int docRegExpBookmark::findMatches(TQString doctext, bmkList &fBookmarks)
|
|
|
|
int docRegExpBookmark::findMatches(TQString doctext, bmkList &fBookmarks)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
FUNCTIONSETUP;
|
|
|
|
FUNCTIONSETUP;
|
|
|
|
// bmkList res;
|
|
|
|
|
|
|
|
TQRegExp rx(pattern);
|
|
|
|
TQRegExp rx(pattern);
|
|
|
|
int pos = 0, nr=0, found=0;
|
|
|
|
int pos = 0, nr=0, found=0;
|
|
|
|
|
|
|
|
|
|
|
@ -114,7 +112,7 @@ int docRegExpBookmark::findMatches(TQString doctext, bmkList &fBookmarks)
|
|
|
|
++found;
|
|
|
|
++found;
|
|
|
|
if (found>=from && found<to) {
|
|
|
|
if (found>=from && found<to) {
|
|
|
|
if (capSubexpression>=0) {
|
|
|
|
if (capSubexpression>=0) {
|
|
|
|
fBookmarks.append(new docBookmark(/*bmkName.left(16)*/rx.cap(capSubexpression), pos));
|
|
|
|
fBookmarks.push_back(new docBookmark(/*bmkName.left(16)*/rx.cap(capSubexpression), pos));
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// TODO: use the subexpressions from the regexp for the bmk name ($1..$9) (given as separate regexp)
|
|
|
|
// TODO: use the subexpressions from the regexp for the bmk name ($1..$9) (given as separate regexp)
|
|
|
|
TQString bmkText(bmkName);
|
|
|
|
TQString bmkText(bmkName);
|
|
|
@ -122,7 +120,7 @@ int docRegExpBookmark::findMatches(TQString doctext, bmkList &fBookmarks)
|
|
|
|
bmkText.replace(CSL1("$%1").arg(i), rx.cap(i));
|
|
|
|
bmkText.replace(CSL1("$%1").arg(i), rx.cap(i));
|
|
|
|
bmkText.replace(CSL1("\\%1").arg(i), rx.cap(i));
|
|
|
|
bmkText.replace(CSL1("\\%1").arg(i), rx.cap(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fBookmarks.append(new docBookmark(bmkText.left(16), pos));
|
|
|
|
fBookmarks.push_back(new docBookmark(bmkText.left(16), pos));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++nr;
|
|
|
|
++nr;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -148,13 +146,16 @@ DOCConverter::DOCConverter(TQObject *parent, const char *name):TQObject(parent,n
|
|
|
|
FUNCTIONSETUP;
|
|
|
|
FUNCTIONSETUP;
|
|
|
|
docdb=0L;
|
|
|
|
docdb=0L;
|
|
|
|
eSortBookmarks=eSortNone;
|
|
|
|
eSortBookmarks=eSortNone;
|
|
|
|
fBookmarks.setAutoDelete( TRUE );
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DOCConverter::~DOCConverter() {
|
|
|
|
DOCConverter::~DOCConverter() {
|
|
|
|
FUNCTIONSETUP;
|
|
|
|
FUNCTIONSETUP;
|
|
|
|
|
|
|
|
for (docBookmark *bmk : fBookmarks)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
delete bmk;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -241,7 +242,7 @@ int DOCConverter::findBmkEndtags(TQString &text, bmkList&fBmks) {
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (text[pos] == '<') {
|
|
|
|
if (text[pos] == '<') {
|
|
|
|
fBmks.append(new docMatchBookmark(text.mid(pos + 1, endpos - pos - 1)));
|
|
|
|
fBmks.push_back(new docMatchBookmark(text.mid(pos + 1, endpos - pos - 1)));
|
|
|
|
++nr;
|
|
|
|
++nr;
|
|
|
|
DEBUGKPILOT<<"Found opening < at position "<<pos<<", bookmarktext ="<<text.mid(pos+1, endpos-pos-1)<<endl;
|
|
|
|
DEBUGKPILOT<<"Found opening < at position "<<pos<<", bookmarktext ="<<text.mid(pos+1, endpos-pos-1)<<endl;
|
|
|
|
text.remove(pos, text.length());
|
|
|
|
text.remove(pos, text.length());
|
|
|
@ -257,7 +258,6 @@ int DOCConverter::findBmkEndtags(TQString &text, bmkList&fBmks) {
|
|
|
|
|
|
|
|
|
|
|
|
int DOCConverter::findBmkInline(TQString &text, bmkList &fBmks) {
|
|
|
|
int DOCConverter::findBmkInline(TQString &text, bmkList &fBmks) {
|
|
|
|
FUNCTIONSETUP;
|
|
|
|
FUNCTIONSETUP;
|
|
|
|
// bmkList res;
|
|
|
|
|
|
|
|
int nr=0;
|
|
|
|
int nr=0;
|
|
|
|
TQRegExp rx(CSL1("<\\*(.*)\\*>"));
|
|
|
|
TQRegExp rx(CSL1("<\\*(.*)\\*>"));
|
|
|
|
|
|
|
|
|
|
|
@ -266,7 +266,7 @@ int DOCConverter::findBmkInline(TQString &text, bmkList &fBmks) {
|
|
|
|
while (pos >= 0) {
|
|
|
|
while (pos >= 0) {
|
|
|
|
pos = rx.search(text, pos);
|
|
|
|
pos = rx.search(text, pos);
|
|
|
|
if (pos >= 0) {
|
|
|
|
if (pos >= 0) {
|
|
|
|
fBmks.append(new docBookmark(rx.cap(1), pos+1));
|
|
|
|
fBmks.push_back(new docBookmark(rx.cap(1), pos+1));
|
|
|
|
++nr;
|
|
|
|
++nr;
|
|
|
|
text = text.remove(pos, rx.matchedLength());
|
|
|
|
text = text.remove(pos, rx.matchedLength());
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -315,7 +315,7 @@ int DOCConverter::findBmkFile(TQString &, bmkList &fBmks) {
|
|
|
|
if (fieldnr>1) {
|
|
|
|
if (fieldnr>1) {
|
|
|
|
TQString name(bmkinfo[1]);
|
|
|
|
TQString name(bmkinfo[1]);
|
|
|
|
DEBUGKPILOT<<"Bookmark \""<<name<<"\" set at position "<<pos<<endl;
|
|
|
|
DEBUGKPILOT<<"Bookmark \""<<name<<"\" set at position "<<pos<<endl;
|
|
|
|
fBmks.append(new docBookmark(name, pos));
|
|
|
|
fBmks.push_back(new docBookmark(name, pos));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (bookmark==CSL1("-") || bookmark==CSL1("+")) {
|
|
|
|
} else if (bookmark==CSL1("-") || bookmark==CSL1("+")) {
|
|
|
|
if (fieldnr>1) {
|
|
|
|
if (fieldnr>1) {
|
|
|
@ -349,7 +349,7 @@ int DOCConverter::findBmkFile(TQString &, bmkList &fBmks) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fBmks.append(bmk);
|
|
|
|
fBmks.push_back(bmk);
|
|
|
|
bmk=0L;
|
|
|
|
bmk=0L;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
DEBUGKPILOT<<"Could not allocate bookmark "<<name<<endl;
|
|
|
|
DEBUGKPILOT<<"Could not allocate bookmark "<<name<<endl;
|
|
|
@ -366,7 +366,7 @@ int DOCConverter::findBmkFile(TQString &, bmkList &fBmks) {
|
|
|
|
if (bmk) {
|
|
|
|
if (bmk) {
|
|
|
|
bmk->from=1;
|
|
|
|
bmk->from=1;
|
|
|
|
bmk->to=1;
|
|
|
|
bmk->to=1;
|
|
|
|
fBmks.append(bmk);
|
|
|
|
fBmks.push_back(bmk);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // fieldnr>0
|
|
|
|
} // fieldnr>0
|
|
|
@ -403,10 +403,8 @@ bool DOCConverter::convertTXTtoPDB() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Process the bookmarks: find the occurrences of the regexps, and sort them if requested:
|
|
|
|
// Process the bookmarks: find the occurrences of the regexps, and sort them if requested:
|
|
|
|
bmkSortedList pdbBookmarks;
|
|
|
|
bmkList pdbBookmarks;
|
|
|
|
pdbBookmarks.setAutoDelete(TRUE);
|
|
|
|
for (docBookmark *bmk : fBookmarks)
|
|
|
|
docBookmark*bmk;
|
|
|
|
|
|
|
|
for (bmk = fBookmarks.first(); bmk; bmk = fBookmarks.next())
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bmk->findMatches(text, pdbBookmarks);
|
|
|
|
bmk->findMatches(text, pdbBookmarks);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -415,12 +413,11 @@ bool DOCConverter::convertTXTtoPDB() {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
case eSortName:
|
|
|
|
case eSortName:
|
|
|
|
docBookmark::compare_pos=false;
|
|
|
|
docBookmark::compare_pos=false;
|
|
|
|
// qHeapSort(pdbBookmarks);
|
|
|
|
pdbBookmarks.sort([](docBookmark *a, docBookmark *b) { return *a < *b; });
|
|
|
|
pdbBookmarks.sort();
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case eSortPos:
|
|
|
|
case eSortPos:
|
|
|
|
docBookmark::compare_pos=true;
|
|
|
|
docBookmark::compare_pos=true;
|
|
|
|
pdbBookmarks.sort();
|
|
|
|
pdbBookmarks.sort([](docBookmark *a, docBookmark *b) { return *a < *b; });
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case eSortNone:
|
|
|
|
case eSortNone:
|
|
|
|
default:
|
|
|
|
default:
|
|
|
@ -429,7 +426,7 @@ bool DOCConverter::convertTXTtoPDB() {
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
#ifdef DEBUG
|
|
|
|
DEBUGKPILOT << "Bookmarks: "<<endl;
|
|
|
|
DEBUGKPILOT << "Bookmarks: "<<endl;
|
|
|
|
for (bmk = pdbBookmarks.first(); bmk; bmk = pdbBookmarks.next())
|
|
|
|
for (bmk : pdbBookmarks)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
DEBUGKPILOT<<bmk->bmkName.left(20)<<" at position "<<bmk->position<<endl;
|
|
|
|
DEBUGKPILOT<<bmk->bmkName.left(20)<<" at position "<<bmk->position<<endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -437,6 +434,10 @@ bool DOCConverter::convertTXTtoPDB() {
|
|
|
|
|
|
|
|
|
|
|
|
if (!docdb->isOpen()) {
|
|
|
|
if (!docdb->isOpen()) {
|
|
|
|
emit logError(i18n("Unable to open palm doc database %1").arg(docdb->dbPathName()) );
|
|
|
|
emit logError(i18n("Unable to open palm doc database %1").arg(docdb->dbPathName()) );
|
|
|
|
|
|
|
|
for (docBookmark *bmk : pdbBookmarks)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
delete bmk;
|
|
|
|
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -480,8 +481,7 @@ bool DOCConverter::convertTXTtoPDB() {
|
|
|
|
|
|
|
|
|
|
|
|
recnum=0;
|
|
|
|
recnum=0;
|
|
|
|
// Finally, write out the bookmarks
|
|
|
|
// Finally, write out the bookmarks
|
|
|
|
for (bmk = pdbBookmarks.first(); bmk; bmk = pdbBookmarks.next())
|
|
|
|
for (docBookmark *bmk : pdbBookmarks)
|
|
|
|
// for (bmkList::const_iterator it=pdbBookmarks.begin(); it!=pdbBookmarks.end(); ++it)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
++recnum;
|
|
|
|
++recnum;
|
|
|
|
DEBUGKPILOT << "Bookmark #"<<recnum<<", Name="<<bmk->bmkName.left(20)<<", Position="<<bmk->position<<endl;
|
|
|
|
DEBUGKPILOT << "Bookmark #"<<recnum<<", Name="<<bmk->bmkName.left(20)<<", Position="<<bmk->position<<endl;
|
|
|
@ -494,7 +494,15 @@ bool DOCConverter::convertTXTtoPDB() {
|
|
|
|
KPILOT_DELETE(bmkRecord);
|
|
|
|
KPILOT_DELETE(bmkRecord);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (docBookmark *bmk : pdbBookmarks)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
delete bmk;
|
|
|
|
|
|
|
|
}
|
|
|
|
pdbBookmarks.clear();
|
|
|
|
pdbBookmarks.clear();
|
|
|
|
|
|
|
|
for (docBookmark *bmk : fBookmarks)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
delete bmk;
|
|
|
|
|
|
|
|
}
|
|
|
|
fBookmarks.clear();
|
|
|
|
fBookmarks.clear();
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
@ -561,8 +569,7 @@ bool DOCConverter::convertPDBtoTXT()
|
|
|
|
// After the document records possibly come a few bookmark records, so read them in and put them in a separate bookmark file.
|
|
|
|
// After the document records possibly come a few bookmark records, so read them in and put them in a separate bookmark file.
|
|
|
|
// for the ztxt conduit there might be annotations after the bookmarks, so the upper bound needs to be adapted.
|
|
|
|
// for the ztxt conduit there might be annotations after the bookmarks, so the upper bound needs to be adapted.
|
|
|
|
int upperBmkRec=docdb->recordCount();
|
|
|
|
int upperBmkRec=docdb->recordCount();
|
|
|
|
bmkSortedList bmks;
|
|
|
|
bmkList bmks;
|
|
|
|
bmks.setAutoDelete(TRUE);
|
|
|
|
|
|
|
|
for (int i=header.numRecords+1; i<upperBmkRec; ++i)
|
|
|
|
for (int i=header.numRecords+1; i<upperBmkRec; ++i)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
PilotRecord*rec=docdb->readRecordByIndex(i);
|
|
|
|
PilotRecord*rec=docdb->readRecordByIndex(i);
|
|
|
@ -570,7 +577,7 @@ bool DOCConverter::convertPDBtoTXT()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
PilotDOCBookmark bookie(rec);
|
|
|
|
PilotDOCBookmark bookie(rec);
|
|
|
|
docBookmark*bmk=new docBookmark(TQString::fromLatin1(bookie.bookmarkName), bookie.pos);
|
|
|
|
docBookmark*bmk=new docBookmark(TQString::fromLatin1(bookie.bookmarkName), bookie.pos);
|
|
|
|
bmks.append(bmk);
|
|
|
|
bmks.push_back(bmk);
|
|
|
|
KPILOT_DELETE(rec);
|
|
|
|
KPILOT_DELETE(rec);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
emit logMessage(i18n("Could not read bookmark record #%1 from Database %2").arg(i).arg(docdb->dbPathName()));
|
|
|
|
emit logMessage(i18n("Could not read bookmark record #%1 from Database %2").arg(i).arg(docdb->dbPathName()));
|
|
|
@ -578,9 +585,9 @@ bool DOCConverter::convertPDBtoTXT()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// TODO: Sort the list of bookmarks according to their position
|
|
|
|
// TODO: Sort the list of bookmarks according to their position
|
|
|
|
docBookmark::compare_pos=true;
|
|
|
|
docBookmark::compare_pos=true;
|
|
|
|
bmks.sort();
|
|
|
|
bmks.sort([](docBookmark *a, docBookmark *b) { return *a < *b; });
|
|
|
|
|
|
|
|
|
|
|
|
if ((fBmkTypes & eBmkFile) && (bmks.count()>0))
|
|
|
|
if ((fBmkTypes & eBmkFile) && (bmks.size()>0))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
TQString bmkfilename = docfile.name();
|
|
|
|
TQString bmkfilename = docfile.name();
|
|
|
|
if (bmkfilename.endsWith(CSL1(".txt"))){
|
|
|
|
if (bmkfilename.endsWith(CSL1(".txt"))){
|
|
|
@ -598,7 +605,7 @@ bool DOCConverter::convertPDBtoTXT()
|
|
|
|
DEBUGKPILOT<<"Writing "<<upperBmkRec-header.numRecords<<
|
|
|
|
DEBUGKPILOT<<"Writing "<<upperBmkRec-header.numRecords<<
|
|
|
|
"("<<upperBmkRec<<") bookmarks to file "<<bmkfilename<<endl;
|
|
|
|
"("<<upperBmkRec<<") bookmarks to file "<<bmkfilename<<endl;
|
|
|
|
TQTextStream bmkstream(&bmkfile);
|
|
|
|
TQTextStream bmkstream(&bmkfile);
|
|
|
|
for (docBookmark*bmk=bmks.first(); bmk; bmk=bmks.next())
|
|
|
|
for (docBookmark *bmk : bmks)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bmkstream<<bmk->position<<", "<<bmk->bmkName<<endl;
|
|
|
|
bmkstream<<bmk->position<<", "<<bmk->bmkName<<endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -608,8 +615,9 @@ bool DOCConverter::convertPDBtoTXT()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fBmkTypes & eBmkInline)
|
|
|
|
if (fBmkTypes & eBmkInline)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for (docBookmark*bmk=bmks.last(); bmk; bmk=bmks.prev())
|
|
|
|
for (bmkList::reverse_iterator rit = bmks.rbegin(); rit!= bmks.rend(); ++rit)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
docBookmark *bmk = *rit;
|
|
|
|
doctext.insert(bmk->position, TQString(CSL1("<*") +
|
|
|
|
doctext.insert(bmk->position, TQString(CSL1("<*") +
|
|
|
|
bmk->bmkName +
|
|
|
|
bmk->bmkName +
|
|
|
|
CSL1("*>")));
|
|
|
|
CSL1("*>")));
|
|
|
@ -624,6 +632,10 @@ bool DOCConverter::convertPDBtoTXT()
|
|
|
|
docdb->cleanup();
|
|
|
|
docdb->cleanup();
|
|
|
|
// reset all records to unchanged. I don't know if this is really such a wise idea?
|
|
|
|
// reset all records to unchanged. I don't know if this is really such a wise idea?
|
|
|
|
docdb->resetSyncFlags();
|
|
|
|
docdb->resetSyncFlags();
|
|
|
|
|
|
|
|
for (docBookmark *bmk : bmks)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
delete bmk;
|
|
|
|
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|