pilotMemo.cc
00001
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,v 1.8 2003/10/01 10:13:39 kainhofe Exp $";
00030
00031 #include "options.h"
00032
00033 #include <qtextcodec.h>
00034
00035 #include "pilotMemo.h"
00036
00037
00038
00039 PilotMemo::PilotMemo(PilotRecord * rec) : PilotAppCategory(rec)
00040 {
00041 FUNCTIONSETUP;
00042 unpack(rec->getData(), 1);
00043 (void) pilotMemo_id;
00044 }
00045
00046 void PilotMemo::unpack(const void *text, int )
00047 {
00048 FUNCTIONSETUP;
00049
00050 fText = codec()->toUnicode((const char *)text);
00051 }
00052
00053
00054 void *PilotMemo::internalPack(unsigned char *buf)
00055 {
00056 FUNCTIONSETUP;
00057 QCString s = codec()->fromUnicode(fText);
00058 return strcpy((char *) buf, (const char *)s);
00059 }
00060
00061 void *PilotMemo::pack(void *buf, int *len)
00062 {
00063 FUNCTIONSETUP;
00064 if (((unsigned)*len) < fText.length())
00065 return NULL;
00066
00067 *len = fText.length();
00068
00069 return internalPack((unsigned char *) buf);
00070 }
00071
00072
00073 QString PilotMemo::getTextRepresentation(bool richText)
00074 {
00075 if (richText)
00076 return i18n("<i>Title:</i> %1<br>\n<i>MemoText:</i><br>%2").
00077 arg(rtExpand(getTitle(), richText)).arg(rtExpand(text(), richText));
00078 else
00079 return i18n("Title: %1\nMemoText:\n%2").arg(getTitle()).arg(text());
00080 }
00081
00082
00083 QString PilotMemo::getTitle() const
00084 {
00085 if (fText.isEmpty()) return QString::null;
00086
00087 int memoTitleLen = fText.find('\n');
00088 if (-1 == memoTitleLen) memoTitleLen=fText.length();
00089 return fText.left(memoTitleLen);
00090 }
00091
00092 QString PilotMemo::shortTitle() const
00093 {
00094 FUNCTIONSETUP;
00095 QString t = QString(getTitle()).simplifyWhiteSpace();
00096
00097 if (t.length() < 32)
00098 return t;
00099 t.truncate(40);
00100
00101 int spaceIndex = t.findRev(' ');
00102
00103 if (spaceIndex > 32)
00104 {
00105 t.truncate(spaceIndex);
00106 }
00107
00108 t += CSL1("...");
00109
00110 return t;
00111 }
00112
00113 QString PilotMemo::sensibleTitle() const
00114 {
00115 FUNCTIONSETUP;
00116 QString s = getTitle();
00117
00118 if (!s.isEmpty())
00119 {
00120 return s;
00121 }
00122 else
00123 {
00124 return QString(i18n("[unknown]"));
00125 }
00126 }
This file is part of the documentation for kpilot Library Version 3.2.2.