kpilot Library API Documentation

pilotMemo.cc

00001 /* pilotMemo.cc         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., 59 Temple Place, Suite 330, Boston,
00022 ** MA 02111-1307, USA.
00023 */
00024 
00025 /*
00026 ** Bug reports and questions can be sent to kde-pim@kde.org
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 /* firstTime */)
00047 {
00048     FUNCTIONSETUP;
00049 
00050     fText = codec()->toUnicode((const char *)text);
00051 }
00052 
00053 // The indirection just to make the base class happy
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 }
KDE Logo
This file is part of the documentation for kpilot Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:36:49 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003