22#include "migratemanager.h"
23#include "migratemanager_p.h"
24#include "keximigrate.h"
26#include <klibloader.h>
27#include <tdeparts/componentfactory.h>
35#include <tqapplication.h>
39#define KexiDBDbg if (0) kdDebug()
43MigrateManagerInternal* MigrateManagerInternal::s_self = 0L;
52MigrateManagerInternal::MigrateManagerInternal()
53 : TQObject( 0,
"KexiMigrate::MigrateManagerInternal" )
55 , m_drivers(17, false)
57 , lookupDriversNeeded(true)
59 m_drivers.setAutoDelete(
true);
64MigrateManagerInternal::~MigrateManagerInternal()
66 KexiDBDbg <<
"MigrateManagerInternal::~MigrateManagerInternal()" << endl;
70 KexiDBDbg <<
"MigrateManagerInternal::~MigrateManagerInternal() ok" << endl;
73void MigrateManagerInternal::slotAppQuits()
75 if (tqApp->mainWidget() && tqApp->mainWidget()->isVisible())
77 KexiDBDbg <<
"MigrateManagerInternal::slotAppQuits(): let's clear drivers..." << endl;
81MigrateManagerInternal *MigrateManagerInternal::self()
84 s_self =
new MigrateManagerInternal();
89bool MigrateManagerInternal::lookupDrivers()
91 if (!lookupDriversNeeded)
95 connect(tqApp,TQ_SIGNAL(aboutToQuit()),
this,TQ_SLOT(slotAppQuits()));
101 lookupDriversNeeded =
false;
103 TDETrader::OfferList tlist = TDETrader::self()->query(
"Kexi/MigrationDriver");
104 TDETrader::OfferList::ConstIterator it(tlist.constBegin());
105 for(; it != tlist.constEnd(); ++it)
107 KService::Ptr ptr = (*it);
108 TQString srv_name = ptr->property(
"X-Kexi-MigrationDriverName").toString();
109 if (srv_name.isEmpty()) {
110 KexiDBWarn <<
"MigrateManagerInternal::lookupDrivers(): "
111 "X-Kexi-MigrationDriverName must be set for migration driver \""
112 << ptr->property(
"Name").toString() <<
"\" service!\n -- skipped!" << endl;
115 if (m_services_lcase.contains(srv_name.lower())) {
121 TQString srv_ver_str = ptr->property(
"X-Kexi-KexiMigrationVersion").toString();
122 TQStringList lst( TQStringList::split(
".", srv_ver_str) );
123 int minor_ver, major_ver;
124 bool ok = (lst.count() == 2);
126 major_ver = lst[0].toUInt(&ok);
128 minor_ver = lst[1].toUInt(&ok);
130 KexiDBWarn <<
"MigrateManagerInternal::lookupDrivers(): problem with detecting '"
131 << srv_name.lower() <<
"' driver's version -- skipping it!" << endl;
132 possibleProblems += TQString(
"\"%1\" migration driver has unrecognized version; "
133 "required driver version is \"%2.%3\"")
134 .arg(srv_name.lower())
139 KexiDBWarn << TQString(
"MigrateManagerInternal::lookupDrivers(): '%1' driver"
140 " has version '%2' but required migration driver version is '%3.%4'\n"
141 " -- skipping this driver!").arg(srv_name.lower()).arg(srv_ver_str)
143 possibleProblems += TQString(
"\"%1\" migration driver has version \"%2\" "
144 "but required driver version is \"%3.%4\"")
145 .arg(srv_name.lower()).arg(srv_ver_str)
151 TQString mime = ptr->property(
"X-Kexi-FileDBDriverMime").toString().lower();
152 TQString drvType = ptr->property(
"X-Kexi-MigrationDriverType").toString().lower();
153 if (drvType==
"file") {
154 if (!mime.isEmpty()) {
155 if (!m_services_by_mimetype.contains(mime)) {
156 m_services_by_mimetype.insert(mime, ptr);
159 KexiDBWarn <<
"MigrateManagerInternal::lookupDrivers(): more than one driver for '"
160 << mime <<
"' mime type!" << endl;
164 m_services.insert(srv_name, ptr);
165 m_services_lcase.insert(srv_name.lower(), ptr);
166 KexiDBDbg <<
"MigrateManager::lookupDrivers(): registered driver: " << ptr->name()
167 <<
"(" << ptr->library() <<
")" << endl;
172 setError(ERR_DRIVERMANAGER, i18n(
"Could not find any import/export database drivers.") );
178KexiMigrate* MigrateManagerInternal::driver(
const TQString& name)
180 if (!lookupDrivers())
184 KexiDBDbg <<
"MigrationrManagerInternal::migrationDriver(): loading " << name << endl;
186 KexiMigrate *drv = name.isEmpty() ? 0 : m_drivers.find(name.latin1());
190 if (!m_services_lcase.contains(name.lower())) {
191 setError(ERR_DRIVERMANAGER, i18n(
"Could not find import/export database driver \"%1\".").arg(name) );
195 KService::Ptr ptr= *(m_services_lcase.find(name.lower()));
196 TQString srv_name = ptr->property(
"X-Kexi-MigrationDriverName").toString();
198 KexiDBDbg <<
"MigrateManagerInternal::driver(): library: "<<ptr->library()<<endl;
199 drv = KParts::ComponentFactory::createInstanceFromService<KexiMigrate>(ptr,
200 this, srv_name.latin1(), TQStringList(),&m_serverResultNum);
203 setError(ERR_DRIVERMANAGER, i18n(
"Could not load import/export database driver \"%1\".")
205 if (m_componentLoadingErrors.isEmpty()) {
206 m_componentLoadingErrors[KParts::ComponentFactory::ErrNoServiceFound]=
"ErrNoServiceFound";
207 m_componentLoadingErrors[KParts::ComponentFactory::ErrServiceProvidesNoLibrary]=
"ErrServiceProvidesNoLibrary";
208 m_componentLoadingErrors[KParts::ComponentFactory::ErrNoLibrary]=
"ErrNoLibrary";
209 m_componentLoadingErrors[KParts::ComponentFactory::ErrNoFactory]=
"ErrNoFactory";
210 m_componentLoadingErrors[KParts::ComponentFactory::ErrNoComponent]=
"ErrNoComponent";
212 m_serverResultName=m_componentLoadingErrors[m_serverResultNum];
215 KexiDBDbg <<
"MigrateManagerInternal::driver(): loading succeed: " << name <<endl;
216 KexiDBDbg <<
"drv="<<(long)drv <<endl;
229 m_drivers.insert(name.latin1(), drv);
233void MigrateManagerInternal::incRefCount()
236 KexiDBDbg <<
"MigrateManagerInternal::incRefCount(): " << m_refCount << endl;
239void MigrateManagerInternal::decRefCount()
242 KexiDBDbg <<
"MigrateManagerInternal::decRefCount(): " << m_refCount << endl;
254MigrateManager::MigrateManager()
255 : TQObject( 0,
"KexiMigrate::MigrateManager" )
257 , d_int( MigrateManagerInternal::self() )
259 d_int->incRefCount();
265MigrateManager::~MigrateManager()
267 KexiDBDbg <<
"MigrateManager::~MigrateManager()" << endl;
276 d_int->decRefCount();
277 if (d_int->m_refCount==0) {
283 KexiDBDbg <<
"MigrateManager::~MigrateManager() ok" << endl;
289 if (!d_int->lookupDrivers()) {
290 kdDebug() <<
"MigrateManager::driverNames() lookupDrivers failed" << endl;
291 return TQStringList();
294 if (d_int->m_services.isEmpty()) {
295 kdDebug() <<
"MigrateManager::driverNames() MigrateManager::ServicesMap is empty" << endl;
296 return TQStringList();
299 if (d_int->error()) {
300 kdDebug() <<
"MigrateManager::driverNames() Error: " << d_int->errorMsg() << endl;
301 return TQStringList();
304 return d_int->m_services.keys();
309 if (!d_int->lookupDrivers()) {
310 kdDebug() <<
"MigrateManager::driverForMimeType() lookupDrivers() failed" << endl;
315 KService::Ptr ptr = d_int->m_services_by_mimetype[mimeType.lower()];
317 kdDebug() << TQString(
"MigrateManager::driverForMimeType(%1) No such mimetype").arg(mimeType) << endl;
321 return ptr->property(
"X-Kexi-MigrationDriverName").toString();
327 if (d_int->error()) {
328 kdDebug() << TQString(
"MigrateManager::driver(%1) Error: %2").arg(name).arg(d_int->errorMsg()) << endl;
336 return d_int->m_serverErrMsg;
341 return d_int->m_serverResultNum;
346 return d_int->m_serverResultName;
351 d_int->m_serverErrMsg=TQString();
352 d_int->m_serverResultNum=0;
353 d_int->m_serverResultName=TQString();
358 if (d_int->possibleProblems.isEmpty())
363 for (TQStringList::ConstIterator it = d_int->possibleProblems.constBegin();
364 it!=d_int->possibleProblems.constEnd(); ++it)
366 str += (TQString::fromLatin1(
"<li>") + *it + TQString::fromLatin1(
"</li>"));
376 return KEXI_MIGRATION_VERSION_MAJOR;
381 return KEXI_MIGRATION_VERSION_MINOR;
384#include "migratemanager_p.moc"
virtual void setError(int code=ERR_OTHER, const TQString &msg=TQString())
Imports non-native databases into Kexi projects.
Migration library management, for finding and loading mogration drivers.
TQString possibleProblemsInfoMsg() const
virtual void drv_clearServerResult()
KexiMigrate * driver(const TQString &name)
virtual TQString serverErrorMsg()
server error is set if there is error at KService level (useful for debugging)
virtual TQString serverResultName()
const TQStringList driverNames()
virtual int serverResult()
TQString driverForMimeType(const TQString &mimeType)
Framework for importing databases into native KexiDB databases.
KEXIMIGR_EXPORT int versionMajor()
KEXIMIGR_EXPORT int versionMinor()