kpilot

pilotAppInfo.cc

Go to the documentation of this file.
00001 /* pilotAppInfo.cc      KPilot
00002 **
00003 ** Copyright (C) 2005-2006 Adriaan de Groot <groot@kde.org>
00004 **
00005 */
00006 
00007 /*
00008 ** This program is free software; you can redistribute it and/or modify
00009 ** it under the terms of the GNU Lesser General Public License as published by
00010 ** the Free Software Foundation; either version 2.1 of the License, or
00011 ** (at your option) any later version.
00012 **
00013 ** This program is distributed in the hope that it will be useful,
00014 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016 ** GNU Lesser General Public License for more details.
00017 **
00018 ** You should have received a copy of the GNU Lesser General Public License
00019 ** along with this program in a file called COPYING; if not, write to
00020 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00021 ** MA 02110-1301, USA.
00022 */
00023 
00024 /*
00025 ** Bug reports and questions can be sent to kde-pim@kde.org
00026 */
00027 
00028 
00029 #include "options.h"
00030 
00031 #include <stdio.h>
00032 
00033 #include "pilotAppInfo.h"
00034 
00035 PilotAppInfoBase::PilotAppInfoBase(PilotDatabase *d) :
00036     fC( 0L ),
00037     fLen(0),
00038     fOwn(true)
00039 {
00040     FUNCTIONSETUP;
00041     int appLen = Pilot::MAX_APPINFO_SIZE;
00042     unsigned char buffer[Pilot::MAX_APPINFO_SIZE];
00043 
00044     if (!d || !d->isOpen())
00045     {
00046         WARNINGKPILOT << "Bad database pointer." << endl;
00047         fLen = 0;
00048         KPILOT_DELETE( fC );
00049         return;
00050     }
00051 
00052     fC = new struct CategoryAppInfo;
00053     fLen = appLen = d->readAppBlock(buffer,appLen);
00054     unpack_CategoryAppInfo(fC, buffer, appLen);
00055 }
00056 
00057 PilotAppInfoBase::~PilotAppInfoBase()
00058 {
00059     if (fOwn)
00060     {
00061         delete fC;
00062     }
00063 }
00064 
00065 bool PilotAppInfoBase::setCategoryName(unsigned int i, const QString &s)
00066 {
00067     if ( (i>=Pilot::CATEGORY_COUNT) || // bad category number
00068         (!categoryInfo())) // Nowhere to write to
00069     {
00070         return false;
00071     }
00072 
00073     (void) Pilot::toPilot(s, categoryInfo()->name[i], Pilot::CATEGORY_SIZE - 1);
00074     return true;
00075 }
00076 
00077