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