kexi

kexiprojectdata.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2003 Lucijan Busch <lucijan@gmx.at>
3 Copyright (C) 2003-2004 Jaroslaw Staniek <js@iidea.pl>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include <sys/types.h>
22#include <unistd.h>
23
24#include <tqdom.h>
25#include <tqdir.h>
26#include <tqfile.h>
27#include <tqregexp.h>
28
29#include <tdeglobal.h>
30#include <kstandarddirs.h>
31#include <kdebug.h>
32#include <tdeio/netaccess.h>
33#include <kurl.h>
34#include <tdelocale.h>
35#include <tdemessagebox.h>
36
37#include <kexidb/drivermanager.h>
38#include "kexiprojectdata.h"
39
40
42class KexiProjectDataPrivate
43{
44public:
45 KexiProjectDataPrivate()
46 : userMode(false)
47 , readOnly(false)
48 {}
49
51 TQDateTime lastOpened;
52 bool userMode : 1;
53 bool readOnly : 1;
54};
55
56//---------------------------------------
57
58KexiProjectData::KexiProjectData()
59 : TQObject(0, "KexiProjectData")
60 , KexiDB::SchemaData()
61 , formatVersion(0)
62 , d( new KexiProjectDataPrivate() )
63{
64}
65
66KexiProjectData::KexiProjectData(
67 const KexiDB::ConnectionData &cdata, const TQString& dbname, const TQString& caption )
68 : TQObject(0, "KexiProjectData")
69 , KexiDB::SchemaData()
70 , formatVersion(0)
71 , d( new KexiProjectDataPrivate() )
72{
73 d->connData = cdata;
74 setDatabaseName(dbname);
75 setCaption(caption);
76}
77
78KexiProjectData::KexiProjectData( const KexiProjectData& pdata )
79 : TQObject(0, "KexiProjectData"), KexiDB::SchemaData()
80 , d( 0 )
81{
82 *this = pdata;
84/*
85 d->connData = *pdata.connectionData();
86 setDatabaseName(pdata.databaseName());
87 setCaption(pdata.caption());*/
88}
89
90KexiProjectData::~KexiProjectData()
91{
92 delete d;
93}
94
95KexiProjectData& KexiProjectData::operator=(const KexiProjectData& pdata)
96{
97 delete d; //this is old
98 static_cast<KexiDB::SchemaData&>(*this) = static_cast<const KexiDB::SchemaData&>(pdata);
99 //deep copy
100 d = new KexiProjectDataPrivate();
101 *d = *pdata.d;
102// d->connData = *pdata.constConnectionData();
103// setDatabaseName(pdata.databaseName());
104// setCaption(pdata.caption());
105// setDescription(pdata.description());
106 return *this;
107}
108
109KexiDB::ConnectionData* KexiProjectData::connectionData()
110{
111 return &d->connData;
112}
113
114const KexiDB::ConnectionData* KexiProjectData::constConnectionData() const
115{
116 return &d->connData;
117}
118
120{
121 return KexiDB::SchemaData::name();
122}
123
124void KexiProjectData::setDatabaseName(const TQString& dbName)
125{
126 KexiDB::SchemaData::setName(dbName);
127}
128
130{
131 return d->userMode;
132}
133
134TQDateTime KexiProjectData::lastOpened() const
135{
136 return d->lastOpened;
137}
138
139void KexiProjectData::setLastOpened(const TQDateTime& lastOpened)
140{
141 d->lastOpened=lastOpened;
142
143}
144TQString KexiProjectData::description() const
145{
146 return KexiDB::SchemaData::description();
147}
148
149void KexiProjectData::setDescription(const TQString& desc)
150{
151 return KexiDB::SchemaData::setDescription(desc);
152}
153
154TQString KexiProjectData::infoString(bool nobr) const
155{
156 if (constConnectionData()->fileName().isEmpty()) {
157 //server-based
158 return TQString(nobr ? "<nobr>" : "") + TQString("\"%1\"").arg(databaseName()) + (nobr ? "</nobr>" : "")
159 + (nobr ? " <nobr>" : " ") + i18n("database connection", "(connection %1)")
160 .arg(constConnectionData()->serverInfoString()) + (nobr ? "</nobr>" : "");
161 }
162 //file-based
163 return TQString(nobr ? "<nobr>" : "")
164 + TQString("\"%1\"").arg(constConnectionData()->fileName()) + (nobr ? "</nobr>" : "");
165}
166
168{
169 d->readOnly = set;
170}
171
173{
174 return d->readOnly;
175}
176
Database specific connection data, e.g. host, port.
TQString serverInfoString(bool addUser=true) const
A user-friendly string for the server.
TQString fileName() const
Get the filename used by the connection.
Kexi project core data member.
TQValueList< ObjectInfo > autoopenObjects
bool userMode() const
void setReadOnly(bool set)
TQString infoString(bool nobr=true) const
bool isReadOnly() const
TQString databaseName() const
High-level database connectivity library with database backend drivers.