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.2.4.4 2003/03/12 23:31:15 adridg 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::getTitle() const
00074 {
00075         if (fText.isEmpty()) return QString::null;
00076         
00077         int memoTitleLen = fText.find('\n');
00078         if (-1 == memoTitleLen) memoTitleLen=fText.length();
00079         return fText.left(memoTitleLen);
00080 }
00081 
00082 QString PilotMemo::shortTitle() const
00083 {
00084         FUNCTIONSETUP;
00085         QString t = QString(getTitle()).simplifyWhiteSpace();
00086 
00087         if (t.length() < 32)
00088                 return t;
00089         t.truncate(40);
00090 
00091         int spaceIndex = t.findRev(' ');
00092 
00093         if (spaceIndex > 32)
00094         {
00095                 t.truncate(spaceIndex);
00096         }
00097 
00098         t += CSL1("...");
00099 
00100         return t;
00101 }
00102 
00103 QString PilotMemo::sensibleTitle() const
00104 {
00105         FUNCTIONSETUP;
00106         QString s = getTitle();
00107 
00108         if (!s.isEmpty())
00109         {
00110                 return s;
00111         }
00112         else
00113         {
00114                 return QString(i18n("[unknown]"));
00115         }
00116 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:40:44 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001