kexi

kexiprojectset.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2003-2005 Jaroslaw Staniek <js@iidea.pl>
00003 
00004    This program is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this program; see the file COPYING.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018  */
00019 
00020 #include "kexiprojectset.h"
00021 #include "kexi.h"
00022 
00023 #include <kexidb/driver.h>
00024 #include <kexidb/connection.h>
00025 #include <kexidb/msghandler.h>
00026 
00027 #include <kdebug.h>
00028 
00029 //#define ERRMSG(a1, a2) 
00030 //  { if (m_msgHandler) m_msgHandler->showErrorMessage(a1, a2); }
00031 
00033 class KexiProjectSetPrivate
00034 {
00035 public:
00036     KexiProjectSetPrivate()
00037     {
00038 //      list.setAutoDelete(true);
00039     }
00040     KexiProjectData::List list;
00041 //  KexiDB::MessageHandler* msgHandler;
00042 };
00043 
00044 KexiProjectSet::KexiProjectSet(KexiDB::MessageHandler* handler)
00045 : KexiDB::Object(handler) 
00046 , d(new KexiProjectSetPrivate())
00047 {
00048 }
00049 
00050 KexiProjectSet::KexiProjectSet(KexiDB::ConnectionData &conndata,
00051     KexiDB::MessageHandler* handler)
00052 : KexiDB::Object(handler) 
00053 , d(new KexiProjectSetPrivate())
00054 {
00055     KexiDB::Driver *drv = Kexi::driverManager().driver(conndata.driverName);
00056     if (!drv) {
00057         setError(&Kexi::driverManager());
00058         return;
00059     }
00060     KexiDB::Connection *conn = drv->createConnection(conndata);
00061     if (!conn) {
00062         setError(drv);
00063         return;
00064     }
00065     if (!conn->connect()) {
00066         setError(conn);
00067         delete conn;
00068         return;
00069     }
00070     QStringList dbnames = conn->databaseNames(false/*skip system*/);
00071 //  kexidbg << dbnames.count() << endl;
00072     if (conn->error()) {
00073         setError(conn);
00074         delete conn;
00075         return;
00076     }
00077     delete conn;
00078     conn = 0;
00079     for (QStringList::ConstIterator it = dbnames.constBegin(); it!=dbnames.constEnd(); ++it) {
00080         // project's caption is just the same as database name - nothing better is available
00081         KexiProjectData *pdata = new KexiProjectData(conndata, *it, *it);
00082         d->list.append( pdata );
00083     }
00084     clearError();
00085 }
00086 
00087 
00088 KexiProjectSet::~KexiProjectSet()
00089 {
00090     delete d;
00091 }
00092 
00093 void KexiProjectSet::addProjectData(KexiProjectData *data)
00094 {
00095     d->list.append(data);
00096 }
00097 
00098 KexiProjectData::List KexiProjectSet::list() const
00099 {
00100     return d->list;
00101 }
00102 
00103 KexiProjectData* KexiProjectSet::findProject(const QString &dbName) const
00104 {
00105     const QString _dbName = dbName.lower();
00106     QPtrListIterator<KexiProjectData> it( d->list );
00107     for (;it.current();++it) {
00108         if (it.current()->databaseName().lower()==_dbName)
00109             return it.current();
00110     }
00111     return 0;
00112 }
KDE Home | KDE Accessibility Home | Description of Access Keys