kexi

connectiondata.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2003 Jaroslaw Staniek <js@iidea.pl>
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include <kexidb/connectiondata.h>
21
22#include <kexidb/drivermanager.h>
23
24#include <tqfileinfo.h>
25#include <tqdir.h>
26
27#include <tdelocale.h>
28
29using namespace KexiDB;
30
31namespace KexiDB {
33class ConnectionData::Private {
34public:
35 Private() {
36 dummy=false;
37 }
38 ~Private() {}
39 bool dummy;
40};
41}
42
43/*================================================================*/
44
45ConnectionDataBase::ConnectionDataBase()
46 : id(-1), port(0), useLocalSocketFile(true), savePassword(false)
47{
48}
49
50/*================================================================*/
51
52ConnectionData::ConnectionData()
53: TQObject()
55, formatVersion(0)
56, priv(new ConnectionData::Private())
57{
58}
59
60ConnectionData::ConnectionData(const ConnectionData& cd)
61: TQObject()
63, priv(0)
64{
65 static_cast<ConnectionData&>(*this) = static_cast<const ConnectionData&>(cd);//copy data members
66}
67
68ConnectionData::~ConnectionData()
69{
70 delete priv;
71 priv = 0;
72}
73
74ConnectionData& ConnectionData::operator=(const ConnectionData& cd)
75{
76 if (this != &cd) {
77 delete priv; //this is old
78 static_cast<ConnectionDataBase&>(*this) = static_cast<const ConnectionDataBase&>(cd);//copy data members
79 priv = new ConnectionData::Private();
80 *priv = *cd.priv;
81 }
82 return *this;
83}
84
85void ConnectionData::setFileName( const TQString& fn )
86{
87 TQFileInfo file(fn);
88 if (!fn.isEmpty() && m_fileName != file.absFilePath()) {
89 m_fileName = TQDir::convertSeparators(file.absFilePath());
90 m_dbPath = TQDir::convertSeparators(file.dirPath(true));
91 m_dbFileName = file.fileName();
92 }
93}
94
95TQString ConnectionData::serverInfoString(bool addUser) const
96{
97 const TQString& i18nFile = i18n("file");
98
99 if (!m_dbFileName.isEmpty())
100 return i18nFile+": "+(m_dbPath.isEmpty() ? "" : m_dbPath
101 + TQDir::separator()) + m_dbFileName;
102
103 DriverManager man;
104 if (!driverName.isEmpty()) {
105 Driver::Info info = man.driverInfo(driverName);
106 if (!info.name.isEmpty() && info.fileBased)
107 return TQString("<")+i18nFile+">";
108 }
109
110 return ( (userName.isEmpty() || !addUser) ? TQString("") : (userName+"@"))
111 + (hostName.isEmpty() ? TQString("localhost") : hostName)
112 + (port!=0 ? (TQString(":")+TQString::number(port)) : TQString());
113}
114
TQString m_fileName
The filename for file-based databases.
TQString m_dbFileName
Filename of the database file.
TQString userName
Username used for the connection.
TQString driverName
the name of the driver that should be used to create a connection
unsigned short int port
Port used for the remote connection.
TQString hostName
Host name used for the remote connection.
TQString m_dbPath
Absolute path to the database file.
Database specific connection data, e.g. host, port.
void setFileName(const TQString &fn)
Set the filename used by the connection.
TQString serverInfoString(bool addUser=true) const
A user-friendly string for the server.
Database driver management, e.g. finding and loading drivers.
bool fileBased
true is the driver is for file-based database backend
Definition driver.h:78
High-level database connectivity library with database backend drivers.