76 return; |
76 return; |
77 } |
77 } |
78 if (existing == dbPath) { |
78 if (existing == dbPath) { |
79 ServiceDatabase *db = 0; |
79 ServiceDatabase *db = 0; |
80 DatabaseManager::DbScope scope; |
80 DatabaseManager::DbScope scope; |
81 if (dbPath == m_manager->m_userDb->databasePath()) { |
81 if (m_manager->m_userDb && dbPath == m_manager->m_userDb->databasePath()) { |
82 db = m_manager->m_userDb; |
82 db = m_manager->m_userDb; |
83 scope = DatabaseManager::UserOnlyScope; |
83 scope = DatabaseManager::UserOnlyScope; |
84 } else if (dbPath == m_manager->m_systemDb->databasePath()) { |
84 } else if (dbPath == m_manager->m_systemDb->databasePath()) { |
85 db = m_manager->m_systemDb; |
85 db = m_manager->m_systemDb; |
86 scope = DatabaseManager::SystemScope; |
86 scope = DatabaseManager::SystemScope; |
287 settingsScope = QSettings::UserScope; |
298 settingsScope = QSettings::UserScope; |
288 dbIdentifier = "_user"; |
299 dbIdentifier = "_user"; |
289 db = m_userDb; |
300 db = m_userDb; |
290 } |
301 } |
291 |
302 |
292 QSettings settings(QSettings::IniFormat, settingsScope, |
303 #ifdef Q_OS_SYMBIAN |
293 QLatin1String("Nokia"), QLatin1String("QtServiceFramework")); |
304 QDir dir(QDir::toNativeSeparators("C:\\Data\\temp\\QtServiceFW")); |
294 QFileInfo fi(settings.fileName()); |
305 #else |
295 QDir dir = fi.dir(); |
306 QSettings settings(QSettings::IniFormat, settingsScope, |
|
307 QLatin1String("Nokia"), QLatin1String("QtServiceFramework")); |
|
308 QFileInfo fi(settings.fileName()); |
|
309 QDir dir = fi.dir(); |
|
310 #endif |
296 QString qtVersion(qVersion()); |
311 QString qtVersion(qVersion()); |
297 qtVersion = qtVersion.left(qtVersion.size() -2); //strip off patch version |
312 qtVersion = qtVersion.left(qtVersion.size() -2); //strip off patch version |
298 QString dbName = QString("QtServiceFramework_") + qtVersion + dbIdentifier + QLatin1String(".db"); |
313 QString dbName = QString("QtServiceFramework_") + qtVersion + dbIdentifier + QLatin1String(".db"); |
299 db->setDatabasePath(dir.path() + QDir::separator() + dbName); |
314 db->setDatabasePath(dir.path() + QDir::separator() + dbName); |
300 } |
315 } |
370 } |
393 } |
371 } |
394 } |
372 } |
395 } |
373 |
396 |
374 /* |
397 /* |
|
398 Removes the initialization specific information of \serviceName from the database |
|
399 corresponding to a \scope. |
|
400 |
|
401 Returns true if teh operation succeeded, false otherwise. |
|
402 The last error is set when this function is called. |
|
403 */ |
|
404 bool DatabaseManager::serviceInitialized(const QString &serviceName, DbScope scope) |
|
405 { |
|
406 ServiceDatabase *db = (scope == DatabaseManager::SystemScope) ? m_systemDb : m_userDb; |
|
407 |
|
408 if (!openDb(scope)) { |
|
409 return false; |
|
410 } else { |
|
411 if (!db->serviceInitialized(serviceName)) { |
|
412 m_lastError = db->lastError(); |
|
413 return false; |
|
414 } else { |
|
415 m_lastError.setError(DBError::NoError); |
|
416 return true; |
|
417 } |
|
418 } |
|
419 } |
|
420 |
|
421 /* |
375 Retrieves a list of interface descriptors that fulfill the constraints specified |
422 Retrieves a list of interface descriptors that fulfill the constraints specified |
376 by \a filter at a given \a scope. |
423 by \a filter at a given \a scope. |
377 |
424 |
378 The last error is set when this function is called. |
425 The last error is set when this function is called. |
379 */ |
426 */ |
380 QList<QServiceInterfaceDescriptor> DatabaseManager::getInterfaces(const QServiceFilter &filter, DbScope scope) |
427 QList<QServiceInterfaceDescriptor> DatabaseManager::getInterfaces(const QServiceFilter &filter, DbScope scope) |
381 { |
428 { |
|
429 #ifdef Q_OS_SYMBIAN |
|
430 QService::Scope requestedScope; |
|
431 if (scope == UserScope) { |
|
432 requestedScope = QService::UserScope; |
|
433 } else { |
|
434 requestedScope = QService::SystemScope; |
|
435 } |
|
436 scope = SystemScope; |
|
437 #endif |
|
438 |
382 QList<QServiceInterfaceDescriptor> descriptors; |
439 QList<QServiceInterfaceDescriptor> descriptors; |
383 |
440 |
384 int userDescriptorCount = 0; |
441 int userDescriptorCount = 0; |
385 if (scope == UserScope) { |
442 if (scope == UserScope) { |
386 if (!openDb(UserScope)) |
443 if (!openDb(UserScope)) |
478 |
543 |
479 The last error is set when this function is called. |
544 The last error is set when this function is called. |
480 */ |
545 */ |
481 QServiceInterfaceDescriptor DatabaseManager::interfaceDefault(const QString &interfaceName, DbScope scope) |
546 QServiceInterfaceDescriptor DatabaseManager::interfaceDefault(const QString &interfaceName, DbScope scope) |
482 { |
547 { |
|
548 #ifdef Q_OS_SYMBIAN |
|
549 QService::Scope requestedScope; |
|
550 if (scope == UserScope) { |
|
551 requestedScope = QService::UserScope; |
|
552 } else { |
|
553 requestedScope = QService::SystemScope; |
|
554 } |
|
555 scope = SystemScope; |
|
556 #endif |
|
557 |
483 QServiceInterfaceDescriptor descriptor; |
558 QServiceInterfaceDescriptor descriptor; |
484 if (scope == UserScope) { |
559 if (scope == UserScope) { |
485 if (!openDb(UserScope)) |
560 if (!openDb(UserScope)) |
486 return QServiceInterfaceDescriptor(); |
561 return QServiceInterfaceDescriptor(); |
487 QString interfaceID; |
562 QString interfaceID; |
542 //or because we're specifically only querying at system scope |
617 //or because we're specifically only querying at system scope |
543 if (!openDb(SystemScope)) { |
618 if (!openDb(SystemScope)) { |
544 if (scope == SystemScope) { |
619 if (scope == SystemScope) { |
545 m_lastError = m_systemDb->lastError(); |
620 m_lastError = m_systemDb->lastError(); |
546 return QServiceInterfaceDescriptor(); |
621 return QServiceInterfaceDescriptor(); |
547 } else if (scope == UserScope && m_userDb->lastError().code() == DBError::NotFound) { |
622 } else if (scope == UserScope && m_userDb && m_userDb->lastError().code() == DBError::NotFound) { |
548 m_lastError = m_userDb->lastError(); |
623 m_lastError = m_userDb->lastError(); |
549 return QServiceInterfaceDescriptor(); |
624 return QServiceInterfaceDescriptor(); |
550 } |
625 } |
551 } else { |
626 } else { |
552 descriptor = m_systemDb->interfaceDefault(interfaceName); |
627 descriptor = m_systemDb->interfaceDefault(interfaceName); |
553 if (m_systemDb->lastError().code() == DBError::NoError) { |
628 if (m_systemDb->lastError().code() == DBError::NoError) { |
554 descriptor.d->scope = QService::SystemScope; |
629 #ifdef Q_OS_SYMBIAN |
|
630 descriptor.d->scope = requestedScope; |
|
631 #else |
|
632 descriptor.d->scope = QService::SystemScope; |
|
633 #endif |
555 return descriptor; |
634 return descriptor; |
556 } else if (m_systemDb->lastError().code() == DBError::NotFound) { |
635 } else if (m_systemDb->lastError().code() == DBError::NotFound) { |
557 m_lastError = m_systemDb->lastError(); |
636 m_lastError = m_systemDb->lastError(); |
558 return QServiceInterfaceDescriptor(); |
637 return QServiceInterfaceDescriptor(); |
559 } else { |
638 } else { |
615 Returns true if the operation succeeded, false otherwise. |
694 Returns true if the operation succeeded, false otherwise. |
616 The last error is set when this function is called. |
695 The last error is set when this function is called. |
617 */ |
696 */ |
618 bool DatabaseManager::setInterfaceDefault(const QServiceInterfaceDescriptor &descriptor, DbScope scope) |
697 bool DatabaseManager::setInterfaceDefault(const QServiceInterfaceDescriptor &descriptor, DbScope scope) |
619 { |
698 { |
620 if (scope == UserScope) { |
699 #ifdef Q_OS_SYMBIAN |
621 if (!openDb(UserScope)) |
700 Q_UNUSED(scope); |
|
701 if (!openDb(SystemScope)) { |
622 return false; |
702 return false; |
623 if (descriptor.scope() == QService::UserScope) { //if a user scope descriptor, just set it in the user db |
703 } else { |
624 if(m_userDb->setInterfaceDefault(descriptor)) { |
704 if (m_systemDb->setInterfaceDefault(descriptor)) { |
625 m_lastError.setError(DBError::NoError); |
705 m_lastError.setError(DBError::NoError); |
626 return true; |
706 return true; |
627 } else { |
707 } else { |
628 m_lastError = m_userDb->lastError(); |
708 m_lastError = m_systemDb->lastError(); |
629 return false; |
709 return false; |
630 } |
710 } |
631 } else { //otherwise we need to get the interfaceID from the system db and set this |
711 } |
632 //as an external default interface ID in the user db |
712 #else |
633 if (!openDb(SystemScope)) |
713 if (scope == UserScope) { |
|
714 if (!openDb(UserScope)) |
634 return false; |
715 return false; |
635 |
716 if (descriptor.scope() == QService::UserScope) { //if a user scope descriptor, just set it in the user db |
636 QString interfaceDescriptorID = m_systemDb->getInterfaceID(descriptor); |
717 if(m_userDb->setInterfaceDefault(descriptor)) { |
637 if (m_systemDb->lastError().code() == DBError::NoError) { |
|
638 if(m_userDb->setInterfaceDefault(descriptor, interfaceDescriptorID)) { |
|
639 m_lastError.setError(DBError::NoError); |
718 m_lastError.setError(DBError::NoError); |
640 return true; |
719 return true; |
641 } else { |
720 } else { |
642 m_lastError = m_userDb->lastError(); |
721 m_lastError = m_userDb->lastError(); |
643 return false; |
722 return false; |
644 } |
723 } |
645 } else { |
724 } else { //otherwise we need to get the interfaceID from the system db and set this |
646 m_lastError = m_systemDb->lastError(); |
725 //as an external default interface ID in the user db |
647 return false; |
726 if (!openDb(SystemScope)) |
648 } |
727 return false; |
649 } |
728 |
650 } else { //scope == SystemScope |
729 QString interfaceDescriptorID = m_systemDb->getInterfaceID(descriptor); |
651 if (descriptor.scope() == QService::UserScope) { |
730 if (m_systemDb->lastError().code() == DBError::NoError) { |
652 QString errorText("Cannot set default service at system scope with a user scope " |
731 if(m_userDb->setInterfaceDefault(descriptor, interfaceDescriptorID)) { |
653 "interface descriptor"); |
732 m_lastError.setError(DBError::NoError); |
654 m_lastError.setError(DBError::InvalidDescriptorScope, errorText); |
733 return true; |
655 return false; |
734 } else { |
656 } else { |
735 m_lastError = m_userDb->lastError(); |
657 if (!openDb(SystemScope)) { |
736 return false; |
658 return false; |
737 } |
659 } else { |
|
660 if (m_systemDb->setInterfaceDefault(descriptor)) { |
|
661 m_lastError.setError(DBError::NoError); |
|
662 return true; |
|
663 } else { |
738 } else { |
664 m_lastError = m_systemDb->lastError(); |
739 m_lastError = m_systemDb->lastError(); |
665 return false; |
740 return false; |
666 } |
741 } |
667 } |
742 } |
668 } |
743 } else { //scope == SystemScope |
669 } |
744 if (descriptor.scope() == QService::UserScope) { |
|
745 QString errorText("Cannot set default service at system scope with a user scope " |
|
746 "interface descriptor"); |
|
747 m_lastError.setError(DBError::InvalidDescriptorScope, errorText); |
|
748 return false; |
|
749 } else { |
|
750 if (!openDb(SystemScope)) { |
|
751 return false; |
|
752 } else { |
|
753 if (m_systemDb->setInterfaceDefault(descriptor)) { |
|
754 m_lastError.setError(DBError::NoError); |
|
755 return true; |
|
756 } else { |
|
757 m_lastError = m_systemDb->lastError(); |
|
758 return false; |
|
759 } |
|
760 } |
|
761 } |
|
762 } |
|
763 #endif |
670 } |
764 } |
671 |
765 |
672 /* |
766 /* |
673 Opens a database connection with the database at a specific \a scope. |
767 Opens a database connection with the database at a specific \a scope. |
674 |
768 |
675 The last error is set when this function is called. |
769 The last error is set when this function is called. |
676 */ |
770 */ |
677 bool DatabaseManager::openDb(DbScope scope) |
771 bool DatabaseManager::openDb(DbScope scope) |
678 { |
772 { |
|
773 #ifdef Q_OS_SYMBIAN |
|
774 scope = SystemScope; |
|
775 #endif |
|
776 |
679 if (scope == SystemScope && m_systemDb->isOpen() && !QFile::exists(m_systemDb->databasePath())) { |
777 if (scope == SystemScope && m_systemDb->isOpen() && !QFile::exists(m_systemDb->databasePath())) { |
680 delete m_systemDb; |
778 delete m_systemDb; |
681 m_systemDb = new ServiceDatabase; |
779 m_systemDb = new ServiceDatabase; |
682 initDbPath(SystemScope); |
780 initDbPath(SystemScope); |
683 m_alreadyWarnedOpenError = false; |
781 m_alreadyWarnedOpenError = false; |
737 } |
835 } |
738 |
836 |
739 //if we are opening the system database while the user database is open, |
837 //if we are opening the system database while the user database is open, |
740 //cleanup and reset any old external defaults |
838 //cleanup and reset any old external defaults |
741 //from the user scope database |
839 //from the user scope database |
742 if (scope == SystemScope && m_userDb->isOpen()) { |
840 if (scope == SystemScope && m_userDb && m_userDb->isOpen()) { |
743 QList<QPair<QString,QString> > externalDefaultsInfo; |
841 QList<QPair<QString,QString> > externalDefaultsInfo; |
744 externalDefaultsInfo = m_userDb->externalDefaultsInfo(); |
842 externalDefaultsInfo = m_userDb->externalDefaultsInfo(); |
745 QServiceInterfaceDescriptor descriptor; |
843 QServiceInterfaceDescriptor descriptor; |
746 QPair<QString,QString> defaultInfo; |
844 QPair<QString,QString> defaultInfo; |
747 |
845 |