noteobj.cpp
author insilmaril
Fri, 08 Jul 2005 07:24:42 +0000
changeset 107 4afcc3383157
parent 0 7a96bd401351
child 185 6691000c3262
permissions -rw-r--r--
changes for 1.6.9
     1 #include <qfile.h>
     2 #include <qtextstream.h>
     3 #include <qmessagebox.h>
     4 #include <qregexp.h>
     5 
     6 #include "noteobj.h"
     7 
     8 /////////////////////////////////////////////////////////////////
     9 // NoteObj
    10 /////////////////////////////////////////////////////////////////
    11 
    12 NoteObj::NoteObj()
    13 {
    14 	clear();
    15 }
    16 
    17 void NoteObj::copy (NoteObj other)
    18 {
    19 	note=other.note;
    20 	fonthint=other.fonthint;
    21 	filenamehint="";
    22 }
    23 
    24 void NoteObj::clear()
    25 {
    26 	note="";
    27 	fonthint="undef";
    28 	filenamehint="";
    29 }
    30 
    31 void NoteObj::setNote (const QString &s)
    32 {
    33 	note=s;
    34 }
    35 
    36 QString NoteObj::getNote()
    37 {
    38 	return note;
    39 }
    40 
    41 void NoteObj::setFontHint (const QString &s)
    42 {
    43 	// only for backward compatibility (pre 1.5 )
    44 	fonthint=s;
    45 }
    46 
    47 QString NoteObj::getFontHint()
    48 {
    49 	// only for backward compatibility (pre 1.5 )
    50 	return fonthint;
    51 }
    52 
    53 void NoteObj::setFilenameHint (const QString &s)
    54 {
    55 	filenamehint=s;
    56 }
    57 
    58 QString NoteObj::getFilenameHint()
    59 {
    60 	return filenamehint;
    61 }
    62 
    63 bool NoteObj::isEmpty ()
    64 {
    65 	return note.isEmpty();
    66 }
    67 
    68 QString NoteObj::saveToDir ()
    69 {
    70 	// QTextEdit may generate fontnames with unquoted &, like
    71 	// in "Lucida B&H". This is invalid in XML and thus would crash
    72 	// the XML parser
    73 	uint pos=0;
    74 	uint pos2;
    75 	bool inbracket=false;
    76 	bool inquot=false;
    77 	while (pos<note.length())
    78 	{
    79 		if (note.mid(pos,1)=="<") inbracket=true;
    80 		if (note.mid(pos,1)==">") inbracket=false;
    81 		if (note.mid(pos,1)=="\"" && inbracket)
    82 		{
    83 			if (!inquot)
    84 				inquot=true;
    85 			else
    86 				inquot=false;
    87 		}
    88 		if (note.mid(pos,1)=="&" && inquot)
    89 		{
    90 			// Now we are inside  <  "  "  >
    91 			// look for ending "
    92 			pos2=pos+1;
    93 			while (note.mid(pos2,1)!=";" && note.mid(pos2,1)!="\"")
    94 				pos2++;
    95 			if (note.mid(pos2,1)=="\"")
    96 			{
    97 				note.replace(pos,1,"&amp;");
    98 				pos=pos2;
    99 			}
   100 		}
   101 		pos++;
   102 	}
   103 	return beginElement ("htmlnote",attribut("fonthint",fonthint)) + "\n"+ note+ "\n" +endElement ("htmlnote");
   104 }
   105