kpilot

pilotMemo.cc

Go to the documentation of this file.
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 #include <qnamespace.h>
00032 
00033 #include "pilotMemo.h"
00034 #include "pilotDatabase.h"
00035 
00036 
00037 
00038 PilotMemo::PilotMemo(const PilotRecord * rec) : PilotRecordBase(rec)
00039 {
00040     FUNCTIONSETUP;
00041     fText = Pilot::fromPilot((const char *)(rec->data()),rec->size());
00042 }
00043 
00044 PilotRecord *PilotMemo::pack()
00045 {
00046     FUNCTIONSETUPL(4);
00047     int i;
00048     
00049     int len = fText.length() + 8;
00050     struct Memo buf;
00051     buf.text = new char[len];
00052 
00053     // put our text into buf
00054     i = Pilot::toPilot(fText, buf.text, len);
00055 
00056     pi_buffer_t *b = pi_buffer_new(len);
00057     i = pack_Memo(&buf, b, memo_v1);
00058 
00059     DEBUGKPILOT << fname << ": original text: [" << fText 
00060         << "], buf.text: [" << buf.text 
00061         << "], b->data: [" << b->data << "]" << endl;
00062 
00063     if (i<0)
00064     {
00065         // Generic error from the pack_*() functions.
00066         delete[] buf.text;
00067         return 0;
00068     }
00069 
00070     // pack_Appointment sets b->used
00071     PilotRecord *r = new PilotRecord(b, this);
00072     delete[] buf.text;
00073     return r;
00074 }
00075 
00076 
00077 QString PilotMemo::getTextRepresentation(Qt::TextFormat richText)
00078 {
00079     if (richText==Qt::RichText)
00080     {
00081         return i18n("<i>Title:</i> %1<br>\n<i>MemoText:</i><br>%2").
00082             arg(rtExpand(getTitle(), richText)).arg(rtExpand(text(), richText));
00083     }
00084     else
00085     {
00086         return i18n("Title: %1\nMemoText:\n%2").arg(getTitle()).arg(text());
00087     }
00088 }
00089 
00090 
00091 QString PilotMemo::getTitle() const
00092 {
00093     if (fText.isEmpty()) return QString::null;
00094 
00095     int memoTitleLen = fText.find('\n');
00096     if (-1 == memoTitleLen) memoTitleLen=fText.length();
00097     return fText.left(memoTitleLen);
00098 }
00099 
00100 QString PilotMemo::shortTitle() const
00101 {
00102     FUNCTIONSETUP;
00103     QString t = QString(getTitle()).simplifyWhiteSpace();
00104 
00105     if (t.length() < 32)
00106         return t;
00107     t.truncate(40);
00108 
00109     int spaceIndex = t.findRev(' ');
00110 
00111     if (spaceIndex > 32)
00112     {
00113         t.truncate(spaceIndex);
00114     }
00115 
00116     t += CSL1("...");
00117 
00118     return t;
00119 }
00120 
00121 QString PilotMemo::sensibleTitle() const
00122 {
00123     FUNCTIONSETUP;
00124     QString s = getTitle();
00125 
00126     if (!s.isEmpty())
00127     {
00128         return s;
00129     }
00130     else
00131     {
00132         return i18n("[unknown]");
00133     }
00134 }
00135