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 <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 
KDE Home | KDE Accessibility Home | Description of Access Keys