+eDVBDBBouquetQuery::eDVBDBBouquetQuery(eDVBDB *db, const eServiceReference &source, eDVBChannelQuery *query)
+ :eDVBDBQueryBase(db, source, query), m_cursor(db->m_bouquets[query->m_bouquet_name].m_services.begin())
+{
+}
+
+RESULT eDVBDBBouquetQuery::getNextResult(eServiceReferenceDVB &ref)
+{
+ eBouquet &bouquet = m_db->m_bouquets[m_query->m_bouquet_name];
+ std::list<eServiceReference> &list = bouquet.m_services;
+ while (m_cursor != list.end())
+ {
+ ref = *((eServiceReferenceDVB*)&(*m_cursor));
+
+ std::map<eServiceReferenceDVB, ePtr<eDVBService> >::iterator it =
+ m_db->m_services.find(ref);
+
+ int res = (!m_query) || it == m_db->m_services.end() || it->second->checkFilter(ref, *m_query);
+
+ ++m_cursor;
+
+ if (res)
+ return 0;
+ }
+
+ ref.type = eServiceReference::idInvalid;
+
+ return 1;
+}
+
+eDVBDBListQuery::eDVBDBListQuery(eDVBDB *db, const eServiceReference &source, eDVBChannelQuery *query)
+ :eDVBDBQueryBase(db, source, query), m_cursor(m_list.end())
+{
+}
+
+RESULT eDVBDBListQuery::getNextResult(eServiceReferenceDVB &ref)
+{
+ if (m_cursor != m_list.end())
+ {
+ ref = *m_cursor++;
+ return 0;
+ }
+ ref.type = eServiceReference::idInvalid;
+ return 1;
+}
+
+int eDVBDBListQuery::compareLessEqual(const eServiceReferenceDVB &a, const eServiceReferenceDVB &b)
+{
+ if ( m_query->m_sort == eDVBChannelQuery::tSatellitePosition )
+ {
+ int x = (a.getDVBNamespace().get() >> 16);
+ int y = (b.getDVBNamespace().get() >> 16);
+ if ( x > 1800 )
+ x -= 3600;
+ if ( y > 1800 )
+ y -= 3600;
+ return x < y;
+ }
+ std::string aa = a.name, bb = b.name;
+ makeUpper(aa);
+ makeUpper(bb);
+ return aa < bb;
+}
+
+eDVBDBSatellitesQuery::eDVBDBSatellitesQuery(eDVBDB *db, const eServiceReference &source, eDVBChannelQuery *query)
+ :eDVBDBListQuery(db, source, query)
+{
+ for (std::map<eServiceReferenceDVB, ePtr<eDVBService> >::iterator it(m_db->m_services.begin());
+ it != m_db->m_services.end(); ++it)
+ {
+ int res = it->second->checkFilter(it->first, *query);
+ if (res)
+ {
+ unsigned int dvbnamespace = it->first.getDVBNamespace().get()&0xFFFF0000;
+ bool found=0;
+ for (std::list<eServiceReferenceDVB>::iterator i(m_list.begin()); i != m_list.end(); ++i)
+ if ( (i->getDVBNamespace().get()&0xFFFF0000) == dvbnamespace )
+ {
+ found=true;
+ break;
+ }
+ if (!found)
+ {
+ eServiceReferenceDVB ref;
+ ref.setDVBNamespace(dvbnamespace);
+ ref.flags=eServiceReference::flagDirectory;
+ char buf[128];
+ snprintf(buf, 128, "(satellitePosition == %d) && ", dvbnamespace>>16);
+
+ ref.path=buf+source.path;
+ unsigned int pos=ref.path.find("FROM");
+ ref.path.erase(pos);
+ ref.path+="ORDER BY name";
+// eDebug("ref.path now %s", ref.path.c_str());
+ m_list.push_back(ref);
+
+ ref.path=buf+source.path;
+ pos=ref.path.find("FROM");
+ ref.path.erase(pos+5);
+ ref.path+="PROVIDERS ORDER BY name";
+// eDebug("ref.path now %s", ref.path.c_str());
+ m_list.push_back(ref);
+
+ snprintf(buf, 128, "(satellitePosition == %d) && (flags == %d) && ", dvbnamespace>>16, eDVBService::dxNewFound);
+ ref.path=buf+source.path;
+ pos=ref.path.find("FROM");
+ ref.path.erase(pos);
+ ref.path+="ORDER BY name";
+// eDebug("ref.path now %s", ref.path.c_str());
+ m_list.push_back(ref);
+ }
+ }
+ }
+ m_cursor=m_list.begin();
+}
+
+eDVBDBProvidersQuery::eDVBDBProvidersQuery(eDVBDB *db, const eServiceReference &source, eDVBChannelQuery *query)
+ :eDVBDBListQuery(db, source, query)
+{
+ for (std::map<eServiceReferenceDVB, ePtr<eDVBService> >::iterator it(m_db->m_services.begin());
+ it != m_db->m_services.end(); ++it)
+ {
+ int res = it->second->checkFilter(it->first, *query);
+ if (res)
+ {
+ bool found=0;
+
+ const char *provider_name = it->second->m_provider_name.length() ?
+ it->second->m_provider_name.c_str() :
+ "Unknown";
+
+ for (std::list<eServiceReferenceDVB>::iterator i(m_list.begin()); i != m_list.end(); ++i)
+ if (i->name == provider_name)
+ {
+ found=true;
+ break;
+ }
+ if (!found)
+ {
+ eServiceReferenceDVB ref;
+ char buf[64];
+ ref.name=provider_name;
+ snprintf(buf, 64, "(provider == \"%s\") && ", provider_name);
+ ref.path=buf+source.path;
+ unsigned int pos = ref.path.find("FROM");
+ ref.flags=eServiceReference::flagDirectory;
+ ref.path.erase(pos);
+ ref.path+="ORDER BY name";
+// eDebug("ref.path now %s", ref.path.c_str());
+ m_list.push_back(ref);
+ }
+ }
+ }
+ m_cursor=m_list.begin();
+}
+
+/* (<name|provider|type|bouquet|satpos|chid> <==|...> <"string"|int>)[||,&& (..)] */
+
+static int decodeType(const std::string &type)
+{
+ if (type == "name")
+ return eDVBChannelQuery::tName;
+ else if (type == "provider")
+ return eDVBChannelQuery::tProvider;
+ else if (type == "type")
+ return eDVBChannelQuery::tType;
+ else if (type == "bouquet")
+ return eDVBChannelQuery::tBouquet;
+ else if (type == "satellitePosition")
+ return eDVBChannelQuery::tSatellitePosition;
+ else if (type == "channelID")
+ return eDVBChannelQuery::tChannelID;
+ else if (type == "flags")
+ return eDVBChannelQuery::tFlags;
+ else
+ return -1;
+}