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 static const char *pilotMemo_id =
00029 "$Id: pilotMemo.cc 437980 2005-07-23 19:53:57Z kainhofe $";
00030
00031 #include "options.h"
00032
00033 #include <qtextcodec.h>
00034
00035 #include "pilotMemo.h"
00036 #include "pilotDatabase.h"
00037
00038
00039
00040 PilotMemo::PilotMemo(const PilotRecord * rec) : PilotAppCategory(rec)
00041 {
00042 FUNCTIONSETUP;
00043 fText = codec()->toUnicode((const char *)(rec->data()),rec->size());
00044 (void) pilotMemo_id;
00045 }
00046
00047 void PilotMemo::unpack(const void *text, int )
00048 {
00049 FUNCTIONSETUP;
00050 kdWarning() << k_funcinfo << ": deprecated and broken function." << endl;
00051 fText = codec()->toUnicode((const char *)text);
00052 }
00053
00054 PilotRecord *PilotMemo::pack()
00055 {
00056 char *buf = new char[fText.length() + 8];
00057 int len = fText.length() + 8;
00058 pack_(buf,&len);
00059 PilotRecord *r = new PilotRecord(buf, len, attributes(), category(), id());
00060 delete[] buf;
00061 return r;
00062 }
00063
00064 void *PilotMemo::pack_(void *buf, int *len)
00065 {
00066 FUNCTIONSETUP;
00067 if (!*len) return NULL;
00068 if (*len < 0) return NULL;
00069 if (fText.length() > (unsigned) *len) return NULL;
00070
00071 QCString s = codec()->fromUnicode(fText);
00072
00073 int use_length = *len;
00074 if (MAX_MEMO_LEN < use_length) use_length = MAX_MEMO_LEN;
00075
00076
00077 memset(buf,0,use_length);
00078
00079
00080
00081
00082
00083 strlcpy(( char *)buf,(const char *)s,use_length);
00084
00085
00086
00087 if ((int)s.length() < use_length) use_length = s.length()+1;
00088 *len = use_length;
00089 return buf;
00090 }
00091
00092
00093 QString PilotMemo::getTextRepresentation(bool richText)
00094 {
00095 if (richText)
00096 return i18n("<i>Title:</i> %1<br>\n<i>MemoText:</i><br>%2").
00097 arg(rtExpand(getTitle(), richText)).arg(rtExpand(text(), richText));
00098 else
00099 return i18n("Title: %1\nMemoText:\n%2").arg(getTitle()).arg(text());
00100 }
00101
00102
00103 QString PilotMemo::getTitle() const
00104 {
00105 if (fText.isEmpty()) return QString::null;
00106
00107 int memoTitleLen = fText.find('\n');
00108 if (-1 == memoTitleLen) memoTitleLen=fText.length();
00109 return fText.left(memoTitleLen);
00110 }
00111
00112 QString PilotMemo::shortTitle() const
00113 {
00114 FUNCTIONSETUP;
00115 QString t = QString(getTitle()).simplifyWhiteSpace();
00116
00117 if (t.length() < 32)
00118 return t;
00119 t.truncate(40);
00120
00121 int spaceIndex = t.findRev(' ');
00122
00123 if (spaceIndex > 32)
00124 {
00125 t.truncate(spaceIndex);
00126 }
00127
00128 t += CSL1("...");
00129
00130 return t;
00131 }
00132
00133 QString PilotMemo::sensibleTitle() const
00134 {
00135 FUNCTIONSETUP;
00136 QString s = getTitle();
00137
00138 if (!s.isEmpty())
00139 {
00140 return s;
00141 }
00142 else
00143 {
00144 return i18n("[unknown]");
00145 }
00146 }
00147
|