r3010 - software/ui/src
Enrico Zini
enrico at alioth.debian.org
Wed Jun 20 11:51:34 UTC 2007
Author: enrico
Date: 2007-06-20 11:51:33 +0000 (Wed, 20 Jun 2007)
New Revision: 3010
Added:
software/ui/src/Engine.cc
software/ui/src/Engine.h
Removed:
software/ui/src/Environment.tcc
Modified:
software/ui/src/Environment.cc
software/ui/src/Environment.h
software/ui/src/Makefile.am
Log:
Added prototype interface
Added: software/ui/src/Engine.cc
===================================================================
--- software/ui/src/Engine.cc (rev 0)
+++ software/ui/src/Engine.cc 2007-06-20 11:51:33 UTC (rev 3010)
@@ -0,0 +1,116 @@
+/*
+ * Backend engine for game installer UI
+ *
+ * Copyright (C) 2003--2007 Enrico Zini <enrico at debian.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "Engine.h"
+
+using namespace std;
+
+void Engine::recompute()
+{
+ Xapian::Query query;
+ Xapian::Query kwquery;
+ Xapian::Query typequery;
+ Xapian::Query ifacequery;
+
+ if (!m_filter_keywords.empty())
+ kwquery = m_textsearch.makeORQuery(m_filter_keywords);
+ if (m_filter_type.valid())
+ typequery = Xapian::Query("T"+m_filter_type.fullname());
+ if (m_filter_iface.valid())
+ ifacequery = Xapian::Query("T"+m_filter_iface.fullname());
+
+ if (kwquery.empty())
+ if (typequery.empty())
+ if (ifacequery.empty())
+ ;
+ else
+ query = ifacequery;
+ else
+ if (ifacequery.empty())
+ query = tagquery;
+ else
+ query = Xapian::Query(Xapian::Query::OP_AND, ifacequery, tagquery);
+ else
+ if (typequery.empty())
+ if (ifacequery.empty())
+ query = kwquery;
+ else
+ query = Xapian::Query(Xapian::Query::OP_AND, kwquery, ifacequery);
+ else
+ if (ifacequery.empty())
+ query = Xapian::Query(Xapian::Query::OP_AND, kwquery, typequery);
+ else
+ query = Xapian::Query(Xapian::Query::OP_AND, kwquery,
+ Xapian::Query(Xapian::Query::OP_AND(typequery, ifacequery)));
+
+ if (query.empty())
+ {
+ // Query all games
+ set<Tag> games = voc().tags("game");
+ vector<string> terms;
+ for (set<Tag>::const_iterator i = games.begin();
+ i != games.end(); ++i)
+ terms.push_back("T" + i->fullname());
+ query = Xapian::Query(Xapian::Query::OP_OR, terms.begin(), terms.end());
+ }
+
+ Xapian::Enquire enquire(m_textsearch.db());
+ enquire.set_query(Xapian::Query(Xapian::Query::OP_AND,
+ Xapian::Query("Trole::program"),
+ query));
+
+ m_dirty = false;
+}
+
+std::vector<ept::debtags::Tag> Engine::types() const
+{
+ if (m_dirty) recompute();
+}
+
+std::vector<ept::debtags::Tag> Engine::interfaces() const
+{
+ if (m_dirty) recompute();
+}
+
+void Engine::setKeywordFilter(const std::string& keywords)
+{
+ m_filter_keywords = keywords;
+ m_dirty = true;
+}
+
+void Engine::setTypeFilter(const ept::debtags::Tag& tag)
+{
+ m_filter_type = tag;
+ m_dirty = true;
+}
+
+void Engine::setInterfaceFilter(const ept::debtags::Tag& tag)
+{
+ m_filter_interface = tag;
+ m_dirty = true;
+}
+
+void Engine::setInstalledFilter(State state)
+{
+ m_filter_state = state;
+ m_dirty = true;
+}
+
+// vim:set ts=4 sw=4:
Added: software/ui/src/Engine.h
===================================================================
--- software/ui/src/Engine.h (rev 0)
+++ software/ui/src/Engine.h 2007-06-20 11:51:33 UTC (rev 3010)
@@ -0,0 +1,121 @@
+#ifndef GAMEUI_ENGINE_H
+#define GAMEUI_ENGINE_H
+
+/*
+ * Backend engine for game installer UI
+ *
+ * Copyright (C) 2003--2007 Enrico Zini <enrico at debian.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <ept/apt/apt.h>
+#include <ept/debtags/debtags.h>
+#include <ept/textsearch/textsearch.h>
+#include <ept/popcon/popcon.h>
+#include <string>
+
+namespace ept {
+namespace apt {
+class Apt;
+}
+}
+
+struct Result
+{
+ std::string name;
+ float popcon;
+ int relevance;
+};
+
+class Engine
+{
+public:
+ enum { ANY, INSTALLED, NOTINSTALLED } State;
+
+protected:
+ /// Apt data provider
+ ept::apt::Apt m_apt;
+
+ /// Debtags data provider
+ ept::debtags::Debtags m_debtags;
+
+ /// Xapian data provider
+ ept::textsearch::TextSearch m_textsearch;
+
+ /// Popcon scores
+ ept::popcon::Popcon m_popcon;
+
+ std::string m_filter_keywords;
+ Tag m_filter_type;
+ Tag m_filter_iface;
+ State m_filter_state;
+
+ bool m_dirty;
+
+ std::vector<Result> m_results;
+
+ void recompute();
+
+public:
+ Engine() : m_filter_state(ANY), m_dirty(false) {}
+
+ /// Access the apt data provider
+ ept::apt::Apt& apt() { return m_apt; }
+
+ /// Access the debtags data provider
+ ept::debtags::Debtags& debtags() { return m_debtags; }
+
+ /// Access the tag vocabulary
+ ept::debtags::Vocabulary& voc() { return m_debtags->vocabulary(); }
+
+ /// Get the list of available game types
+ std::vector<ept::debtags::Tag> types();
+
+ /// Get the list of available interfaces
+ std::vector<ept::debtags::Tag> interfaces();
+
+ /// Get the resulting list of packages
+ const std::vector<Result>& results()
+ {
+ if (m_dirty)
+ recompute();
+ return m_results;
+ }
+
+ /**
+ * Set the keyword filter from the given string (which will be tokenized
+ * and stemmed properly)
+ */
+ void setKeywordFilter(const std::string& keywords);
+
+ /**
+ * Set the game type filter
+ */
+ void setTypeFilter(const ept::debtags::Tag& tag);
+
+ /**
+ * Set the interface type filter
+ */
+ void setInterfaceFilter(const ept::debtags::Tag& tag);
+
+ /**
+ * Set the installed state filter
+ */
+ void setInstalledFilter(State state);
+};
+
+// vim:set ts=4 sw=4:
+#endif
Modified: software/ui/src/Environment.cc
===================================================================
--- software/ui/src/Environment.cc 2007-06-20 11:48:27 UTC (rev 3009)
+++ software/ui/src/Environment.cc 2007-06-20 11:51:33 UTC (rev 3010)
@@ -20,8 +20,6 @@
#include "Environment.h"
-#include <ept/apt/apt.h>
-
#include <stdio.h>
#include <stdarg.h>
#include <unistd.h> // isatty
@@ -42,14 +40,8 @@
// Initialize the environment with default values
Environment::Environment() throw ()
- : m_apt(0), m_debtags(0), _verbose(false), _debug(false) {}
+ : _verbose(false), _debug(false) {}
-void Environment::init(bool editable)
-{
- m_apt = new ept::apt::Apt;
- m_debtags = new ept::debtags::Debtags(editable);
-}
-
void fatal_error(const char* fmt, ...) throw() ATTR_PRINTF(1, 2)
{
fprintf(stderr, "debtags: ");
Modified: software/ui/src/Environment.h
===================================================================
--- software/ui/src/Environment.h 2007-06-20 11:48:27 UTC (rev 3009)
+++ software/ui/src/Environment.h 2007-06-20 11:51:33 UTC (rev 3010)
@@ -21,24 +21,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <ept/debtags/debtags.h>
#include <string>
-namespace ept {
-namespace apt {
-class Apt;
-}
-}
-
class Environment
{
protected:
- /// Apt data provider
- ept::apt::Apt* m_apt;
-
- /// Debtags data provider
- ept::debtags::Debtags* m_debtags;
-
// True when operations should be verbose
bool _verbose;
@@ -50,22 +37,6 @@
public:
static Environment& get() throw ();
- /**
- * Initialise the data providers.
- *
- * This method must be called before they can be accessed.
- */
- void init(bool editable = false);
-
- /// Access the apt data provider
- ept::apt::Apt& apt() { return *m_apt; }
-
- /// Access the debtags data provider
- ept::debtags::Debtags& debtags() { return *m_debtags; }
-
- /// Access the tag vocabulary
- ept::debtags::Vocabulary& voc() { return m_debtags->vocabulary(); }
-
// Accessor methods
bool verbose() const throw () { return _verbose; }
Deleted: software/ui/src/Environment.tcc
===================================================================
--- software/ui/src/Environment.tcc 2007-06-20 11:48:27 UTC (rev 3009)
+++ software/ui/src/Environment.tcc 2007-06-20 11:51:33 UTC (rev 3010)
@@ -1,67 +0,0 @@
-/*
- * debtags - Implement package tags support for Debian
- *
- * Copyright (C) 2003--2007 Enrico Zini <enrico at debian.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifndef DEBTAGS_ENVIRONMENT_TCC
-#define DEBTAGS_ENVIRONMENT_TCC
-
-#include "Environment.h"
-
-#include <pkg/debtags/maint/serializer.h>
-
-#include <tagcoll/input/stdio.h>
-#include <tagcoll/TextFormat.h>
-
-
-template<typename OUT>
-void Environment::readCollection(const string& file, const OUT& out)
-{
- if (file == "-")
- {
- input::Stdio input(stdin, "<stdin>");
- textformat::parse(input,
- pkg::debtags::stringToInt(pkgid, voc(),
- pkg::debtags::intToPkg(pkgid, voc(), out)));
- }
- else
- {
- input::Stdio input(file);
- textformat::parse(input,
- pkg::debtags::stringToInt(pkgid, voc(),
- pkg::debtags::intToPkg(pkgid, voc(), out)));
- }
-}
-
-template<typename OUT>
-void Environment::readCollectionRaw(const string& file, const OUT& out)
-{
- if (file == "-")
- {
- input::Stdio input(stdin, "<stdin>");
- textformat::parse(input, out);
- }
- else
- {
- input::Stdio input(file);
- textformat::parse(input, out);
- }
-}
-
-#endif
-// vim:set ts=4 sw=4:
Modified: software/ui/src/Makefile.am
===================================================================
--- software/ui/src/Makefile.am 2007-06-20 11:48:27 UTC (rev 3009)
+++ software/ui/src/Makefile.am 2007-06-20 11:51:33 UTC (rev 3010)
@@ -5,6 +5,7 @@
games_SOURCES = \
Environment.cc \
+ Engine.cc \
games.cc
games_LDADD = $(LIBEPT_LIBS)
@@ -13,4 +14,4 @@
INCLUDES = -I.. $(LIBEPT_CFLAGS)
-EXTRA_DIST = GamesOptions.h Environment.h
+EXTRA_DIST = GamesOptions.h Environment.h Engine.h
More information about the Pkg-games-commits
mailing list