kexi
connectiondata.cpp
00001 /* This file is part of the KDE project 00002 Copyright (C) 2003 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 <kexidb/connectiondata.h> 00021 00022 #include <kexidb/drivermanager.h> 00023 00024 #include <qfileinfo.h> 00025 #include <qdir.h> 00026 00027 #include <klocale.h> 00028 00029 using namespace KexiDB; 00030 00031 namespace KexiDB { 00033 class ConnectionData::Private { 00034 public: 00035 Private() { 00036 dummy=false; 00037 } 00038 ~Private() {} 00039 bool dummy; 00040 }; 00041 } 00042 00043 /*================================================================*/ 00044 00045 ConnectionDataBase::ConnectionDataBase() 00046 : id(-1), port(0), useLocalSocketFile(true), savePassword(false) 00047 { 00048 } 00049 00050 /*================================================================*/ 00051 00052 ConnectionData::ConnectionData() 00053 : QObject() 00054 , ConnectionDataBase() 00055 , formatVersion(0) 00056 , priv(new ConnectionData::Private()) 00057 { 00058 } 00059 00060 ConnectionData::ConnectionData(const ConnectionData& cd) 00061 : QObject() 00062 , ConnectionDataBase() 00063 , priv(0) 00064 { 00065 static_cast<ConnectionData&>(*this) = static_cast<const ConnectionData&>(cd);//copy data members 00066 } 00067 00068 ConnectionData::~ConnectionData() 00069 { 00070 delete priv; 00071 priv = 0; 00072 } 00073 00074 ConnectionData& ConnectionData::operator=(const ConnectionData& cd) 00075 { 00076 if (this != &cd) { 00077 delete priv; //this is old 00078 static_cast<ConnectionDataBase&>(*this) = static_cast<const ConnectionDataBase&>(cd);//copy data members 00079 priv = new ConnectionData::Private(); 00080 *priv = *cd.priv; 00081 } 00082 return *this; 00083 } 00084 00085 void ConnectionData::setFileName( const QString& fn ) 00086 { 00087 QFileInfo file(fn); 00088 if (!fn.isEmpty() && m_fileName != file.absFilePath()) { 00089 m_fileName = QDir::convertSeparators(file.absFilePath()); 00090 m_dbPath = QDir::convertSeparators(file.dirPath(true)); 00091 m_dbFileName = file.fileName(); 00092 } 00093 } 00094 00095 QString ConnectionData::serverInfoString(bool addUser) const 00096 { 00097 const QString& i18nFile = i18n("file"); 00098 00099 if (!m_dbFileName.isEmpty()) 00100 return i18nFile+": "+(m_dbPath.isEmpty() ? "" : m_dbPath 00101 + QDir::separator()) + m_dbFileName; 00102 00103 DriverManager man; 00104 if (!driverName.isEmpty()) { 00105 Driver::Info info = man.driverInfo(driverName); 00106 if (!info.name.isEmpty() && info.fileBased) 00107 return QString("<")+i18nFile+">"; 00108 } 00109 00110 return ( (userName.isEmpty() || !addUser) ? QString("") : (userName+"@")) 00111 + (hostName.isEmpty() ? QString("localhost") : hostName) 00112 + (port!=0 ? (QString(":")+QString::number(port)) : QString::null); 00113 } 00114