kpilot/lib

pilotMemo.cc

00001 /* KPilot
00002 **
00003 ** Copyright (C) 1998-2001 by Dan Pilone
00004 **
00005 ** This is a C++ wrapper for the Pilot's Memo Pad structures.
00006 */
00007 
00008 /*
00009 ** This program is free software; you can redistribute it and/or modify
00010 ** it under the terms of the GNU Lesser General Public License as published by
00011 ** the Free Software Foundation; either version 2.1 of the License, or
00012 ** (at your option) any later version.
00013 **
00014 ** This program is distributed in the hope that it will be useful,
00015 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00017 ** GNU Lesser General Public License for more details.
00018 **
00019 ** You should have received a copy of the GNU Lesser General Public License
00020 ** along with this program in a file called COPYING; if not, write to
00021 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00022 ** MA 02110-1301, USA.
00023 */
00024 
00025 /*
00026 ** Bug reports and questions can be sent to kde-pim@kde.org
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 
KDE Home | KDE Accessibility Home | Description of Access Keys