kpilot

pilotDatabase.cc

Go to the documentation of this file.
00001 /* KPilot
00002 **
00003 ** Copyright (C) 1998-2001 by Dan Pilone
00004 ** Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00005 ** Copyright (C) 2005-2006 Adriaan de Groot <groot@kde.org>
00006 **
00007 ** This is the abstract base class for databases, which is used both
00008 ** by local databases and by the serial databases held in the Pilot.
00009 */
00010 
00011 /*
00012 ** This program is free software; you can redistribute it and/or modify
00013 ** it under the terms of the GNU Lesser General Public License as published by
00014 ** the Free Software Foundation; either version 2.1 of the License, or
00015 ** (at your option) any later version.
00016 **
00017 ** This program is distributed in the hope that it will be useful,
00018 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00020 ** GNU Lesser General Public License for more details.
00021 **
00022 ** You should have received a copy of the GNU Lesser General Public License
00023 ** along with this program in a file called COPYING; if not, write to
00024 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00025 ** MA 02110-1301, USA.
00026 */
00027 
00028 /*
00029 ** Bug reports and questions can be sent to kde-pim@kde.org
00030 */
00031 
00032 #include "options.h"
00033 
00034 #include <time.h> // Needed by pilot-link include
00035 #include <pi-appinfo.h>
00036 
00037 #include <qstringlist.h>
00038 
00039 #include <kglobal.h>
00040 
00041 #include "pilotDatabase.h"
00042 #include "pilotRecord.h"
00043 
00044 static int creationCount = 0;
00045 static QStringList *createdNames = 0L;
00046 
00047 PilotDatabase::PilotDatabase(const QString &s) :
00048     fDBOpen(false),
00049     fName(s)
00050 {
00051     FUNCTIONSETUP;
00052     creationCount++;
00053     if (!createdNames)
00054     {
00055         createdNames = new QStringList();
00056     }
00057     createdNames->append(s.isEmpty() ? CSL1("<empty>") : s);
00058 }
00059 
00060 /* virtual */ PilotDatabase::~PilotDatabase()
00061 {
00062     FUNCTIONSETUP;
00063     creationCount--;
00064     if (createdNames)
00065     {
00066         createdNames->remove(fName.isEmpty() ? CSL1("<empty>") : fName);
00067     }
00068 }
00069 
00070 /* static */ int PilotDatabase::instanceCount()
00071 {
00072     FUNCTIONSETUP;
00073     DEBUGKPILOT << fname << ": " << creationCount << " databases." << endl;
00074     if (createdNames)
00075     {
00076         DEBUGKPILOT << fname << ": "
00077             << createdNames->join(CSL1(",")) << endl;
00078     }
00079     return creationCount;
00080 }
00081 
00082 /* virtual */ Pilot::RecordIDList PilotDatabase::idList()
00083 {
00084     Pilot::RecordIDList l;
00085 
00086     for (unsigned int i = 0 ; ; i++)
00087     {
00088         PilotRecord *r = readRecordByIndex(i);
00089         if (!r) break;
00090         l.append(r->id());
00091         delete r;
00092     }
00093 
00094     return l;
00095 }
00096 
00097 /* virtual */ Pilot::RecordIDList PilotDatabase::modifiedIDList()
00098 {
00099     Pilot::RecordIDList l;
00100 
00101     resetDBIndex();
00102     while(1)
00103     {
00104         PilotRecord *r = readNextModifiedRec();
00105         if (!r) break;
00106         l.append(r->id());
00107         delete r;
00108     }
00109 
00110     return l;
00111 }
00112