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 #include <tqnamespace.h>
00032
00033 #include "pilotMemo.h"
00034 #include "pilotDatabase.h"
00035
00036
00037
00038 PilotMemo::PilotMemo(const PilotRecord * rec) : PilotRecordBase(rec)
00039 {
00040 FUNCTIONSETUP;
00041 fText = Pilot::fromPilot((const char *)(rec->data()),rec->size());
00042 }
00043
00044 PilotRecord *PilotMemo::pack()
00045 {
00046 FUNCTIONSETUPL(4);
00047 int i;
00048
00049 int len = fText.length() + 8;
00050 struct Memo buf;
00051 buf.text = new char[len];
00052
00053
00054 i = Pilot::toPilot(fText, buf.text, len);
00055
00056 pi_buffer_t *b = pi_buffer_new(len);
00057 i = pack_Memo(&buf, b, memo_v1);
00058
00059 DEBUGKPILOT << fname << ": original text: [" << fText
00060 << "], buf.text: [" << buf.text
00061 << "], b->data: [" << b->data << "]" << endl;
00062
00063 if (i<0)
00064 {
00065
00066 delete[] buf.text;
00067 return 0;
00068 }
00069
00070
00071 PilotRecord *r = new PilotRecord(b, this);
00072 delete[] buf.text;
00073 return r;
00074 }
00075
00076
00077 TQString PilotMemo::getTextRepresentation(Qt::TextFormat richText)
00078 {
00079 if (richText==Qt::RichText)
00080 {
00081 return i18n("<i>Title:</i> %1<br>\n<i>MemoText:</i><br>%2").
00082 arg(rtExpand(getTitle(), richText)).arg(rtExpand(text(), richText));
00083 }
00084 else
00085 {
00086 return i18n("Title: %1\nMemoText:\n%2").arg(getTitle()).arg(text());
00087 }
00088 }
00089
00090
00091 TQString PilotMemo::getTitle() const
00092 {
00093 if (fText.isEmpty()) return TQString::null;
00094
00095 int memoTitleLen = fText.find('\n');
00096 if (-1 == memoTitleLen) memoTitleLen=fText.length();
00097 return fText.left(memoTitleLen);
00098 }
00099
00100 TQString PilotMemo::shortTitle() const
00101 {
00102 FUNCTIONSETUP;
00103 TQString t = TQString(getTitle()).simplifyWhiteSpace();
00104
00105 if (t.length() < 32)
00106 return t;
00107 t.truncate(40);
00108
00109 int spaceIndex = t.findRev(' ');
00110
00111 if (spaceIndex > 32)
00112 {
00113 t.truncate(spaceIndex);
00114 }
00115
00116 t += CSL1("...");
00117
00118 return t;
00119 }
00120
00121 TQString PilotMemo::sensibleTitle() const
00122 {
00123 FUNCTIONSETUP;
00124 TQString s = getTitle();
00125
00126 if (!s.isEmpty())
00127 {
00128 return s;
00129 }
00130 else
00131 {
00132 return i18n("[unknown]");
00133 }
00134 }
00135
|