kpilot/lib

pilotDatabase.cc

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::count()
00071 {
00072     FUNCTIONSETUP;
00073 #ifdef DEBUG
00074     DEBUGLIBRARY << fname << ": " << creationCount << " databases." << endl;
00075     if (createdNames)
00076     {
00077         DEBUGLIBRARY << fname << ": "
00078             << createdNames->join(CSL1(",")) << endl;
00079     }
00080 #endif
00081     return creationCount;
00082 }
00083 
00084 /* virtual */ Pilot::RecordIDList PilotDatabase::idList()
00085 {
00086     Pilot::RecordIDList l;
00087 
00088     for (unsigned int i = 0 ; ; i++)
00089     {
00090         PilotRecord *r = readRecordByIndex(i);
00091         if (!r) break;
00092         l.append(r->id());
00093         delete r;
00094     }
00095 
00096     return l;
00097 }
00098 
00099 /* virtual */ Pilot::RecordIDList PilotDatabase::modifiedIDList()
00100 {
00101     Pilot::RecordIDList l;
00102 
00103     resetDBIndex();
00104     while(1)
00105     {
00106         PilotRecord *r = readNextModifiedRec();
00107         if (!r) break;
00108         l.append(r->id());
00109         delete r;
00110     }
00111 
00112     return l;
00113 }
00114 
KDE Home | KDE Accessibility Home | Description of Access Keys