diff --git a/autotests/common/libwacomdata/testlibwacomdata.cpp b/autotests/common/libwacomdata/testlibwacomdata.cpp --- a/autotests/common/libwacomdata/testlibwacomdata.cpp +++ b/autotests/common/libwacomdata/testlibwacomdata.cpp @@ -79,7 +79,7 @@ bool inLocal = false; bool inLibWacom = false; - if (TabletDatabase::instance().lookupTablet(localInfo.get (TabletInfo::TabletId), localInfo)) { + if (TabletDatabase::instance().lookupTablet(localInfo.get (TabletInfo::TabletId), localInfo.get (TabletInfo::CompanyId), localInfo)) { inLocal = true; } diff --git a/src/common/tabletdatabase.h b/src/common/tabletdatabase.h --- a/src/common/tabletdatabase.h +++ b/src/common/tabletdatabase.h @@ -57,6 +57,19 @@ QString lookupBackend(const QString& companyId) const; + /** + * Looks up tablet information from database and sets all available information + * on the given tablet information object. + * + * @param tabletId The tablet identifier to lookup. + * @param companyId The company ID of the tablet to lookup. + * @param tabletInfo The tablet information object to set the data on. + * + * @return True if the tablet was found, else false. + */ + bool lookupTablet(const QString& tabletId, const QString& companyId, Wacom::TabletInformation& tabletInfo) const; + + /** * Looks up tablet information from database and sets all available information * on the given tablet information object. diff --git a/src/common/tabletdatabase.cpp b/src/common/tabletdatabase.cpp --- a/src/common/tabletdatabase.cpp +++ b/src/common/tabletdatabase.cpp @@ -80,6 +80,39 @@ return companyGroup.readEntry("driver"); } +bool TabletDatabase::lookupTablet(const QString& tabletId, const QString& companyId, TabletInformation& tabletInfo) const +{ + KSharedConfig::Ptr companyConfig; + + KConfigGroup companyGroup; + KConfigGroup tabletGroup; + QString tabletsConfigFile; + + if (!openCompanyConfig(companyConfig)) { + return false; + } + + // get company group section + companyGroup = KConfigGroup (companyConfig, companyId.toLower()); + + // get tablet database configuration file for this company + tabletsConfigFile = companyGroup.readEntry("listfile"); + + if (tabletsConfigFile.isEmpty()) { + qCWarning(COMMON) << QString::fromLatin1("Company group '%1' does not have a device list file!").arg(companyGroup.name()); + return false; + } + + // lookup tablet + if (lookupTabletGroup (tabletsConfigFile, tabletId, tabletGroup)) { + // found tablet + getInformation (tabletGroup, tabletId, companyId, companyGroup.readEntry("name"), tabletInfo); + getButtonMap (tabletGroup, tabletInfo); + return true; + } + + return false; +} bool TabletDatabase::lookupTablet(const QString& tabletId, TabletInformation& tabletInfo) const { @@ -90,9 +123,7 @@ } // find tablet - KConfigGroup companyGroup; KConfigGroup tabletGroup; - QString tabletsConfigFile; // first check the localdb // here we support only Wacom tablet at the moment @@ -110,22 +141,7 @@ foreach(const QString &companyId, companyConfig->groupList()) { - // get company group section - companyGroup = KConfigGroup (companyConfig, companyId.toLower()); - - // get tablet database configuration file for this company - tabletsConfigFile = companyGroup.readEntry("listfile"); - - if (tabletsConfigFile.isEmpty()) { - qCWarning(COMMON) << QString::fromLatin1("Company group '%1' does not have a device list file!").arg(companyGroup.name()); - continue; - } - - // lookup tablet - if (lookupTabletGroup (tabletsConfigFile, tabletId, tabletGroup)) { - // found tablet - getInformation (tabletGroup, tabletId, companyId, companyGroup.readEntry("name"), tabletInfo); - getButtonMap (tabletGroup, tabletInfo); + if (lookupTablet(tabletId, companyId, tabletInfo)) { return true; } }