kexi

kexiprojectdata.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2003 Lucijan Busch <lucijan@gmx.at>
00003    Copyright (C) 2003-2004 Jaroslaw Staniek <js@iidea.pl>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include <sys/types.h>
00022 #include <unistd.h>
00023 
00024 #include <qdom.h>
00025 #include <qdir.h>
00026 #include <qfile.h>
00027 #include <qregexp.h>
00028 
00029 #include <kglobal.h>
00030 #include <kstandarddirs.h>
00031 #include <kdebug.h>
00032 #include <kio/netaccess.h>
00033 #include <kurl.h>
00034 #include <klocale.h>
00035 #include <kmessagebox.h>
00036 
00037 #include <kexidb/drivermanager.h>
00038 #include "kexiprojectdata.h"
00039 
00040 
00042 class KexiProjectDataPrivate
00043 {
00044 public:
00045     KexiProjectDataPrivate()
00046      : userMode(false)
00047      , readOnly(false)
00048     {}
00049     
00050     KexiDB::ConnectionData connData;
00051     QDateTime lastOpened;
00052     bool userMode : 1;
00053     bool readOnly : 1;
00054 };
00055 
00056 //---------------------------------------
00057 
00058 KexiProjectData::KexiProjectData()
00059  : QObject(0, "KexiProjectData")
00060  , KexiDB::SchemaData()
00061  , formatVersion(0)
00062  , d( new KexiProjectDataPrivate() )
00063 {
00064 }
00065 
00066 KexiProjectData::KexiProjectData( 
00067     const KexiDB::ConnectionData &cdata, const QString& dbname, const QString& caption )
00068  : QObject(0, "KexiProjectData")
00069  , KexiDB::SchemaData()
00070  , formatVersion(0)
00071  , d( new KexiProjectDataPrivate() )
00072 {
00073     d->connData = cdata;
00074     setDatabaseName(dbname);
00075     setCaption(caption);
00076 }
00077 
00078 KexiProjectData::KexiProjectData( const KexiProjectData& pdata )
00079  : QObject(0, "KexiProjectData"), KexiDB::SchemaData()
00080  , d( 0 )
00081 {
00082     *this = pdata;
00083     autoopenObjects = pdata.autoopenObjects;
00084 /*
00085     d->connData = *pdata.connectionData();
00086     setDatabaseName(pdata.databaseName());
00087     setCaption(pdata.caption());*/
00088 }
00089 
00090 KexiProjectData::~KexiProjectData()
00091 {
00092     delete d;
00093 }
00094 
00095 KexiProjectData& KexiProjectData::operator=(const KexiProjectData& pdata)
00096 {
00097     delete d; //this is old
00098     static_cast<KexiDB::SchemaData&>(*this) = static_cast<const KexiDB::SchemaData&>(pdata);
00099     //deep copy
00100     d = new KexiProjectDataPrivate();
00101     *d = *pdata.d;
00102 //  d->connData = *pdata.constConnectionData();
00103 //  setDatabaseName(pdata.databaseName());
00104 //  setCaption(pdata.caption());
00105 //  setDescription(pdata.description());
00106     return *this;
00107 }
00108 
00109 KexiDB::ConnectionData* KexiProjectData::connectionData()
00110 {
00111     return &d->connData;
00112 }
00113 
00114 const KexiDB::ConnectionData* KexiProjectData::constConnectionData() const
00115 {
00116     return &d->connData;
00117 }
00118 
00119 QString KexiProjectData::databaseName() const
00120 {
00121     return KexiDB::SchemaData::name();
00122 }
00123 
00124 void KexiProjectData::setDatabaseName(const QString& dbName)
00125 {
00126     KexiDB::SchemaData::setName(dbName);
00127 }
00128 
00129 bool KexiProjectData::userMode() const
00130 {
00131     return d->userMode;
00132 }
00133 
00134 QDateTime KexiProjectData::lastOpened() const
00135 {
00136     return d->lastOpened;
00137 }
00138 
00139 void KexiProjectData::setLastOpened(const QDateTime& lastOpened)
00140 {
00141     d->lastOpened=lastOpened;
00142 
00143 }
00144 QString KexiProjectData::description() const
00145 {
00146     return KexiDB::SchemaData::description();
00147 }
00148 
00149 void KexiProjectData::setDescription(const QString& desc)
00150 {
00151     return KexiDB::SchemaData::setDescription(desc);
00152 }
00153 
00154 QString KexiProjectData::infoString(bool nobr) const
00155 {
00156     if (constConnectionData()->fileName().isEmpty()) {
00157         //server-based
00158         return QString(nobr ? "<nobr>" : "") + QString("\"%1\"").arg(databaseName()) + (nobr ? "</nobr>" : "")
00159             + (nobr ? " <nobr>" : " ") + i18n("database connection", "(connection %1)")
00160             .arg(constConnectionData()->serverInfoString()) + (nobr ? "</nobr>" : "");
00161     }
00162     //file-based
00163     return QString(nobr ? "<nobr>" : "") 
00164         + QString("\"%1\"").arg(constConnectionData()->fileName()) + (nobr ? "</nobr>" : "");
00165 }
00166 
00167 void KexiProjectData::setReadOnly(bool set)
00168 {
00169     d->readOnly = set;
00170 }
00171 
00172 bool KexiProjectData::isReadOnly() const
00173 {
00174     return d->readOnly;
00175 }
00176 
KDE Home | KDE Accessibility Home | Description of Access Keys