kpilot/lib
pilotMemo.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "options.h"
00030
00031
00032 #include "pilotMemo.h"
00033 #include "pilotDatabase.h"
00034
00035
00036
00037 PilotMemo::PilotMemo(const PilotRecord * rec) : PilotRecordBase(rec)
00038 {
00039 FUNCTIONSETUP;
00040 fText = Pilot::fromPilot((const char *)(rec->data()),rec->size());
00041 }
00042
00043 PilotRecord *PilotMemo::pack()
00044 {
00045 pi_buffer_t *b = pi_buffer_new(fText.length()+8);
00046 b->used = Pilot::toPilot(fText, b->data, b->allocated);
00047 PilotRecord *r = new PilotRecord(b, this);
00048 return r;
00049 }
00050
00051
00052 QString PilotMemo::getTextRepresentation(bool richText)
00053 {
00054 if (richText)
00055 return i18n("<i>Title:</i> %1<br>\n<i>MemoText:</i><br>%2").
00056 arg(rtExpand(getTitle(), richText)).arg(rtExpand(text(), richText));
00057 else
00058 return i18n("Title: %1\nMemoText:\n%2").arg(getTitle()).arg(text());
00059 }
00060
00061
00062 QString PilotMemo::getTitle() const
00063 {
00064 if (fText.isEmpty()) return QString::null;
00065
00066 int memoTitleLen = fText.find('\n');
00067 if (-1 == memoTitleLen) memoTitleLen=fText.length();
00068 return fText.left(memoTitleLen);
00069 }
00070
00071 QString PilotMemo::shortTitle() const
00072 {
00073 FUNCTIONSETUP;
00074 QString t = QString(getTitle()).simplifyWhiteSpace();
00075
00076 if (t.length() < 32)
00077 return t;
00078 t.truncate(40);
00079
00080 int spaceIndex = t.findRev(' ');
00081
00082 if (spaceIndex > 32)
00083 {
00084 t.truncate(spaceIndex);
00085 }
00086
00087 t += CSL1("...");
00088
00089 return t;
00090 }
00091
00092 QString PilotMemo::sensibleTitle() const
00093 {
00094 FUNCTIONSETUP;
00095 QString s = getTitle();
00096
00097 if (!s.isEmpty())
00098 {
00099 return s;
00100 }
00101 else
00102 {
00103 return i18n("[unknown]");
00104 }
00105 }
00106
|