summaryrefslogtreecommitdiffstats
path: root/kexi/core/kexiprojectdata.cpp
blob: 53daea99d2f26e4bab21890d4e74f5cb4ae1e9d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/* This file is part of the KDE project
   Copyright (C) 2003 Lucijan Busch <lucijan@gmx.at>
   Copyright (C) 2003-2004 Jaroslaw Staniek <js@iidea.pl>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#include <sys/types.h>
#include <unistd.h>

#include <tqdom.h>
#include <tqdir.h>
#include <tqfile.h>
#include <tqregexp.h>

#include <tdeglobal.h>
#include <kstandarddirs.h>
#include <kdebug.h>
#include <tdeio/netaccess.h>
#include <kurl.h>
#include <tdelocale.h>
#include <tdemessagebox.h>

#include <kexidb/drivermanager.h>
#include "kexiprojectdata.h"


//! @internal
class KexiProjectDataPrivate
{
public:
	KexiProjectDataPrivate()
	 : userMode(false)
	 , readOnly(false)
	{}
	
	KexiDB::ConnectionData connData;
	TQDateTime lastOpened;
	bool userMode : 1;
	bool readOnly : 1;
};

//---------------------------------------

KexiProjectData::KexiProjectData()
 : TQObject(0, "KexiProjectData")
 , KexiDB::SchemaData()
 , formatVersion(0)
 , d( new KexiProjectDataPrivate() )
{
}

KexiProjectData::KexiProjectData( 
	const KexiDB::ConnectionData &cdata, const TQString& dbname, const TQString& caption )
 : TQObject(0, "KexiProjectData")
 , KexiDB::SchemaData()
 , formatVersion(0)
 , d( new KexiProjectDataPrivate() )
{
	d->connData = cdata;
	setDatabaseName(dbname);
	setCaption(caption);
}

KexiProjectData::KexiProjectData( const KexiProjectData& pdata )
 : TQObject(0, "KexiProjectData"), KexiDB::SchemaData()
 , d( 0 )
{
	*this = pdata;
	autoopenObjects = pdata.autoopenObjects;
/*
	d->connData = *pdata.connectionData();
	setDatabaseName(pdata.databaseName());
	setCaption(pdata.caption());*/
}

KexiProjectData::~KexiProjectData()
{
	delete d;
}

KexiProjectData& KexiProjectData::operator=(const KexiProjectData& pdata)
{
	delete d; //this is old
	static_cast<KexiDB::SchemaData&>(*this) = static_cast<const KexiDB::SchemaData&>(pdata);
	//deep copy
	d = new KexiProjectDataPrivate();
	*d = *pdata.d;
//	d->connData = *pdata.constConnectionData();
//	setDatabaseName(pdata.databaseName());
//	setCaption(pdata.caption());
//	setDescription(pdata.description());
	return *this;
}

KexiDB::ConnectionData* KexiProjectData::connectionData()
{
	return &d->connData;
}

const KexiDB::ConnectionData* KexiProjectData::constConnectionData() const
{
	return &d->connData;
}

TQString KexiProjectData::databaseName() const
{
	return KexiDB::SchemaData::name();
}

void KexiProjectData::setDatabaseName(const TQString& dbName)
{
	KexiDB::SchemaData::setName(dbName);
}

bool KexiProjectData::userMode() const
{
	return d->userMode;
}

TQDateTime KexiProjectData::lastOpened() const
{
	return d->lastOpened;
}

void KexiProjectData::setLastOpened(const TQDateTime& lastOpened)
{
	d->lastOpened=lastOpened;

}
TQString KexiProjectData::description() const
{
	return KexiDB::SchemaData::description();
}

void KexiProjectData::setDescription(const TQString& desc)
{
	return KexiDB::SchemaData::setDescription(desc);
}

TQString KexiProjectData::infoString(bool nobr) const
{
	if (constConnectionData()->fileName().isEmpty()) {
		//server-based
		return TQString(nobr ? "<nobr>" : "") + TQString("\"%1\"").arg(databaseName()) + (nobr ? "</nobr>" : "")
			+ (nobr ? " <nobr>" : " ") + i18n("database connection", "(connection %1)")
			.arg(constConnectionData()->serverInfoString()) + (nobr ? "</nobr>" : "");
	}
	//file-based
	return TQString(nobr ? "<nobr>" : "") 
		+ TQString("\"%1\"").arg(constConnectionData()->fileName()) + (nobr ? "</nobr>" : "");
}

void KexiProjectData::setReadOnly(bool set)
{
	d->readOnly = set;
}

bool KexiProjectData::isReadOnly() const
{
	return d->readOnly;
}