[SCM] Development fot GoFind! branch, master, updated. 4b845fe0c7c8e3d0dd9db014ed1d2f4f007fbe76

Miriam Ruiz miriam at debian.org
Sun Nov 23 10:50:51 UTC 2008


The following commit has been merged in the master branch:
commit 4b845fe0c7c8e3d0dd9db014ed1d2f4f007fbe76
Author: Miriam Ruiz <miriam at debian.org>
Date:   Sun Nov 23 11:53:28 2008 +0100

    Make FLTK GUI use real tag lists and package data

diff --git a/Makefile b/Makefile
index 9abc058..74b689b 100644
--- a/Makefile
+++ b/Makefile
@@ -19,12 +19,13 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 CFLAGS= -O2 -g `pkg-config libtagcoll2 boolstuff-0.1 --cflags` -Wall -Werror -fPIC
+#LDFLAGS= -Wl,-z,defs -Wl,--as-needed -Wl,--no-undefined
 LDFLAGS= 
 LIBS= -lept -lept-core -lapt-pkg -lxapian -ldl `pkg-config libtagcoll2 boolstuff-0.1 --libs`
 
 OBJS= Engine.o Environment.o filter.o field.o gofind.o \
 	taghandler.o cfgmanager.o boolparser.o \
-	utf8.o dll.o guiplugin.o
+	utf8.o dll.o guiplugin.o pkgdata.o
 
 PLUGINS= gui_cli.so gui_fltk.so
 
@@ -46,7 +47,7 @@ gui_cli.so: gui_cli.o slre.o
 	gcc -o $@ -c $+ $(CFLAGS)
 
 %.so : %.o
-	g++ $(CFLAGS) -shared $^ -o $@
+	g++ $(LDFLAGS) -shared $^ -o $@
 
 gui_fltk.so : fltk/ui.h gui_fltk.o fltk/aux.o fltk/windows.o fltk/pkgbrowser.o fltk/ui.o
 	g++ $(LDFLAGS) -shared $^ -o $@ `fltk-config --ldflags --use-images` $(LIBS)
diff --git a/gofind.cpp b/gofind.cpp
index 48efc97..853d693 100644
--- a/gofind.cpp
+++ b/gofind.cpp
@@ -24,7 +24,7 @@
 
 #include "Environment.h"
 #include "GamesOptions.h"
-#include "Engine.h"
+#include "pkgdata.h"
 
 #include <ept/apt/packagerecord.h>
 #include <wibble/regexp.h>
@@ -46,276 +46,38 @@
 
 namespace std {
 
-template<typename TAG, typename _Traits>
-basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>& out, const std::set<TAG>& tags)
-{
-	for (typename std::set<TAG>::const_iterator i = tags.begin();
-			i != tags.end(); i++)
-		if (i == tags.begin())
-			out << i->fullname();
-		else
-			out << ", " << i->fullname();
-	return out;
-}
-
-template<typename TAG, typename _Traits>
-basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>& out, const wibble::Singleton<TAG>& tags)
-{
-	out << *tags.begin();
-	return out;
-}
-
-template<typename TAG, typename _Traits>
-basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>& out, const wibble::Empty<TAG>&)
-{
-	return out;
-}
-
-}
-
-using namespace std;
-using namespace ept;
-using namespace ept::debtags;
-using namespace ept::apt;
-using namespace ept::textsearch;
-
-char* tagString(const Tag& tag)
-{
-	static map<string, char*> table;
-	map<string, char*>::iterator i = table.find(tag.fullname());
-	if (i == table.end())
-	{
-		pair< map<string, char*>::iterator, bool > tmp =
-			table.insert(make_pair(tag.fullname(), strdup(tag.fullname().c_str())));
-		i = tmp.first;
-	}
-	return i->second;
-}
-char* pkgString(const std::string& name)
-{
-	static map<string, char*> table;
-	map<string, char*>::iterator i = table.find(name);
-	if (i == table.end())
-	{
-		pair< map<string, char*>::iterator, bool > tmp =
-			table.insert(make_pair(name, strdup(name.c_str())));
-		i = tmp.first;
-	}
-	return i->second;
-}
-
-void printResults(Engine& engine)
-{
-	const vector<Result>& packages = engine.results();
-	for (vector<Result>::const_iterator i = packages.begin();
-			i != packages.end(); ++i)
-	{
-		PackageRecord pkg = engine.apt().rawRecord(i->name);
-		cerr << "PKG " << pkg.package() << " - " << pkg.shortDescription() << endl;
-	}
-
-	const set<Tag>& ttags = engine.types();
-	for (set<Tag>::const_iterator i = ttags.begin();
-			i != ttags.end(); ++i)
-	{
-		cerr << "TTAG " << i->fullname() << endl;
-	}
-
-	const set<Tag>& ftags = engine.interfaces();
-	for (set<Tag>::const_iterator i = ftags.begin();
-			i != ftags.end(); ++i)
-	{
-		cerr << "ITAG " << i->fullname() << endl;
-	}
-}
-
-/*
-const char* ReadFlChoice(Fl_Choice& c)
-{
-	const Fl_Menu_Item* cur = c.mvalue();
-	if (cur->user_data_)
-		return (const char*)cur->user_data_;
-	else
-		return "";
-}
-
-static void UpdateUILists(GamesUI& ui)
-{
-	// Defining this here, non-const, because fltk's interface want non-const
-	// strings and I did not have time to check whether it would attempt to
-	// modify the parameter or not.  Likely not, and thus a
-	// const_cast<char*>(VoidString) would probably have been better.
-	// --Enrico
-	char VoidString[1] = "";
-	Engine& engine = *ui.engine;
-	const char* oldType = ReadFlChoice(*ui.TypeSelection);
-	const char* oldIface = ReadFlChoice(*ui.InterfaceSelection);
-	ui.TypeSelection->clear();
-	ui.TypeSelection->add(_("Any type"), 0, NULL, VoidString, FL_NORMAL_LABEL);
-	ui.InterfaceSelection->clear();
-	ui.InterfaceSelection->add(_("Any interface"), 0, NULL, VoidString, FL_NORMAL_LABEL);
-
-	static int widths_with_popcon[] = { 100, 300, 0 }; // widths for each column
-	static int widths_without_popcon[] = { 100, 0 };
-	ui.ResultsBrowser->clear();
-	if (engine.popcon().hasData())
+	template<typename TAG, typename _Traits>
+	basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>& out, const std::set<TAG>& tags)
 	{
-		ui.ResultsBrowser->column_widths(widths_with_popcon);
-		// tab delimited columns with colors
-		ui.ResultsBrowser->add(_("@B12 at C7@b at .PACKAGE\t at B12@C7 at b@.DESCRIPTION\t at B12@C7 at b@.POPCON"));
-	}
-	else
-	{
-		ui.ResultsBrowser->column_widths(widths_without_popcon);
-		// tab delimited columns with colors
-		ui.ResultsBrowser->add(_("@B12 at C7@b at .PACKAGE\t at B12@C7 at b@.DESCRIPTION"));
+		for (typename std::set<TAG>::const_iterator i = tags.begin();
+				i != tags.end(); i++)
+			if (i == tags.begin())
+				out << i->fullname();
+			else
+				out << ", " << i->fullname();
+		return out;
 	}
 
-	// FIXME: there are better ways to remember the previous item
-	
-	const set<Tag> types = engine.types();
-	int newIdx = 0;
-	for (set<Tag>::const_iterator i = types.begin();
-			i != types.end(); ++i)
-	{
-		int idx = ui.TypeSelection->add(gettext(i->shortDescription().c_str()),
-							0, NULL, tagString(*i), FL_NORMAL_LABEL);
-		if (i->fullname() == oldType)
-			newIdx = idx;
-	}
-	ui.TypeSelection->value(newIdx);
-	
-	const set<Tag> ifaces = engine.interfaces();
-	newIdx = 0;
-	for (set<Tag>::const_iterator i = ifaces.begin();
-			i != ifaces.end(); ++i)
+	template<typename TAG, typename _Traits>
+	basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>& out, const wibble::Singleton<TAG>& tags)
 	{
-		int idx = ui.InterfaceSelection->add(gettext(i->shortDescription().c_str()),
-							0, NULL, tagString(*i), FL_NORMAL_LABEL);
-		if (i->fullname() == oldIface)
-			newIdx = idx;
+		out << *tags.begin();
+		return out;
 	}
-	ui.InterfaceSelection->value(newIdx);
 
-	const std::vector<Result> res = engine.results();
-	for (vector<Result>::const_iterator i = res.begin();
-			i != res.end(); ++i)
+	template<typename TAG, typename _Traits>
+	basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>& out, const wibble::Empty<TAG>&)
 	{
-		PackageRecord rec(engine.apt().rawRecord(i->name));
-		char* userData = pkgString(rec.package());
-
-		// Available Colors: FL_BLACK, FL_BLUE, FL_CYAN, FL_DARK_BLUE,
-		// FL_DARK_CYAN, FL_DARK_GREEN FL_DARK_MAGENTA, FL_DARK_RED,
-		// FL_DARK_YELLOW, FL_GREEN, FL_MAGENTA, FL_RED, FL_WHITE, FL_YELLOW
-
-		Fl_Color bk(FL_WHITE);
-		Fl_Color fr(FL_BLACK);
-		set<Tag> tags = ui.engine->debtags().getTagsOfItem((const char *)rec.package().c_str());
-		switch (pkgfilter.TagsValue(tags))
-		{
-			case PackageFilter::Green:
-				fr = FL_BLACK; bk = FL_GREEN; break;
-			case PackageFilter::Yellow:
-				fr = FL_BLACK; bk = FL_YELLOW; break;
-			case PackageFilter::Red:
-				fr = FL_WHITE; bk = FL_RED; break;
-			case PackageFilter::Black:
-				fr = FL_WHITE; bk = FL_BLACK; break;
-			default:
-				fr = FL_BLACK; bk = FL_WHITE; break;
-		}
-
-		char fmtstr[16];
-		snprintf(fmtstr, sizeof(fmtstr), "@B%d at C%d at .", bk, fr);
-
-		string desc = string(fmtstr) + rec.package() + "\t" + 
-			string(fmtstr) + rec.shortDescription();
-		if (engine.popcon().hasData() && i->popcon)
-		{
-			desc += "\t" + string(fmtstr);
-			char stars[16];
-			snprintf(stars, sizeof(stars), "%%%d/8/1;",
-				(int)rintf(log(i->popcon) * 100 / log(engine.popconLocalMax())));
-			desc += stars;
-			//printf ("%s (%s): POPCON=%f\n", rec.package().c_str(), rec.shortDescription().c_str(), i->popcon);
-		}
-		ui.ResultsBrowser->add(desc.c_str(), userData);
-
-		// Relevance is 0 to 100
-		// Popcon is a weird floating point number (to be improved)
-		//FIXMEaddToResults(rec.package() + " - " + rec.shortDescription(), i->relevance, i->popcon);
+		return out;
 	}
-}
-
-static void CallBackTypeSelection(Fl_Choice* choice, void *data)
-{
-	//printf("CallBackTypeSelection\n");
-	//fflush(stdout);
-	GamesUI& ui = *static_cast<GamesUI*>(data);
-	Tag tag = ui.engine->voc().tagByName(ReadFlChoice(*choice));
-	ui.engine->setTypeFilter(tag);
-	UpdateUILists(ui);
-}
-
-static void CallBackInterfaceSelection(Fl_Choice* choice, void *data)
-{
-	//printf("CallBackInterfaceSelection\n");
-	//fflush(stdout);
-	GamesUI& ui = *static_cast<GamesUI*>(data);
-	Tag tag = ui.engine->voc().tagByName(ReadFlChoice(*choice));
-	ui.engine->setInterfaceFilter(tag);
-	UpdateUILists(ui);
-}
-
-static void CallBackSearchInput(Fl_Input* input, void *data)
-{
-	//printf("CallBackSearchInput\n"); fflush(stdout);
-	GamesUI& ui = *static_cast<GamesUI*>(data);
-	ui.engine->setKeywordFilter(input->value());
-	UpdateUILists(ui);
-}
-
-static void CallBackAlreadyInstalled(Fl_Round_Button*, void *data)
-{
-	//printf("CallBackInstalled\n"); fflush(stdout);
-	GamesUI& ui = *static_cast<GamesUI*>(data);
-	ui.AlreadyInstalled->value(1); ui.AlreadyInstalled->redraw();
-	ui.ToBeInstalled->value(0); ui.ToBeInstalled->redraw();
-	ui.InstalledOrNot->value(0); ui.InstalledOrNot->redraw();
-	ui.engine->setInstalledFilter(Engine::INSTALLED);
-	UpdateUILists(ui);
-}
-
-static void CallBackToBeInstalled(Fl_Round_Button*, void *data)
-{
-	//printf("CallBackToBeInstalled\n"); fflush(stdout);
-	GamesUI& ui = *static_cast<GamesUI*>(data);
-	ui.AlreadyInstalled->value(0); ui.AlreadyInstalled->redraw();
-	ui.ToBeInstalled->value(1); ui.ToBeInstalled->redraw();
-	ui.InstalledOrNot->value(0); ui.InstalledOrNot->redraw();
-	ui.engine->setInstalledFilter(Engine::NOTINSTALLED);
-	UpdateUILists(ui);
-}
 
-static void CallBackInstalledOrNot(Fl_Round_Button*, void *data)
-{
-	//printf("CallBackToBeInstalled\n"); fflush(stdout);
-	GamesUI& ui = *static_cast<GamesUI*>(data);
-	ui.AlreadyInstalled->value(0); ui.AlreadyInstalled->redraw();
-	ui.ToBeInstalled->value(0); ui.ToBeInstalled->redraw();
-	ui.InstalledOrNot->value(1); ui.InstalledOrNot->redraw();
-	ui.engine->setInstalledFilter(Engine::ANY);
-	UpdateUILists(ui);
 }
 
-#if 0
-static void OnResultsBrowserClick(Fl_Browser*, void *data)
-{
-	printf("OnResultsBrowserClick\n"); fflush(stdout);
-//	GamesUI& ui = *static_cast<GamesUI*>(data);
-}
-#endif
-*/
+using namespace std;
+using namespace ept;
+using namespace ept::debtags;
+using namespace ept::apt;
+using namespace ept::textsearch;
 
 #ifndef UNIT_TEST
 int main(int argc, const char* argv[])
@@ -356,58 +118,58 @@ int main(int argc, const char* argv[])
 		if (opts.out_debug->boolValue())
 			::Environment::get().debug(true);
 
-		Engine engine;
+		PackageData pkgdata;
 
 		if (wibble::str::endsWith(argv[0], "learn") || opts.gowhere->stringValue() == "learn")
 		{
-			engine.mainFacet = "field";
-			engine.secondaryFacet = "interface";
-			engine.globalFilter = Xapian::Query(Xapian::Query::OP_AND,
+			pkgdata.mainFacet = "field";
+			pkgdata.secondaryFacet = "interface";
+			pkgdata.globalFilter = Xapian::Query(Xapian::Query::OP_AND,
 									Xapian::Query(Xapian::Query::OP_OR,
 										Xapian::Query("XTrole::documentation"),
 										Xapian::Query("XTrole::program")),
 									Xapian::Query("XTuse::learning"));
 		} else if (wibble::str::endsWith(argv[0], "admin") || opts.gowhere->stringValue() == "admin") {
-			engine.mainFacet = "admin";
-			engine.secondaryFacet = "interface";
-			engine.globalFilter = Xapian::Query(Xapian::Query::OP_OR,
+			pkgdata.mainFacet = "admin";
+			pkgdata.secondaryFacet = "interface";
+			pkgdata.globalFilter = Xapian::Query(Xapian::Query::OP_OR,
 										Xapian::Query("XTrole::documentation"),
 										Xapian::Query("XTrole::program"));
 		} else if (wibble::str::endsWith(argv[0], "net") || opts.gowhere->stringValue() == "net") {
-			engine.mainFacet = "network";
-			engine.secondaryFacet = "interface";
-			engine.globalFilter = Xapian::Query(Xapian::Query::OP_OR,
+			pkgdata.mainFacet = "network";
+			pkgdata.secondaryFacet = "interface";
+			pkgdata.globalFilter = Xapian::Query(Xapian::Query::OP_OR,
 										Xapian::Query("XTrole::documentation"),
 										Xapian::Query("XTrole::program"));
 		} else if (wibble::str::endsWith(argv[0], "office") || opts.gowhere->stringValue() == "office") {
-			engine.mainFacet = "office";
-			engine.secondaryFacet = "interface";
-			engine.globalFilter = Xapian::Query(Xapian::Query::OP_OR,
+			pkgdata.mainFacet = "office";
+			pkgdata.secondaryFacet = "interface";
+			pkgdata.globalFilter = Xapian::Query(Xapian::Query::OP_OR,
 										Xapian::Query("XTrole::documentation"),
 										Xapian::Query("XTrole::program"));
 		} else if (wibble::str::endsWith(argv[0], "safe") || opts.gowhere->stringValue() == "safe") {
-			engine.mainFacet = "security";
-			engine.secondaryFacet = "interface";
-			engine.globalFilter = Xapian::Query(Xapian::Query::OP_OR,
+			pkgdata.mainFacet = "security";
+			pkgdata.secondaryFacet = "interface";
+			pkgdata.globalFilter = Xapian::Query(Xapian::Query::OP_OR,
 										Xapian::Query("XTrole::documentation"),
 										Xapian::Query("XTrole::program"));
 		} else if (wibble::str::endsWith(argv[0], "web") || opts.gowhere->stringValue() == "web") {
-			engine.mainFacet = "web";
-			engine.secondaryFacet = "interface";
-			engine.globalFilter = Xapian::Query(Xapian::Query::OP_OR,
+			pkgdata.mainFacet = "web";
+			pkgdata.secondaryFacet = "interface";
+			pkgdata.globalFilter = Xapian::Query(Xapian::Query::OP_OR,
 										Xapian::Query("XTrole::documentation"),
 										Xapian::Query("XTrole::program"));
 		} else {
-			engine.mainFacet = "game";
-			engine.secondaryFacet = "interface";
-			engine.globalFilter = Xapian::Query("XTrole::program");
+			pkgdata.mainFacet = "game";
+			pkgdata.secondaryFacet = "interface";
+			pkgdata.globalFilter = Xapian::Query("XTrole::program");
 		}
 
 		if (opts.mainFacet->isSet())
-			engine.mainFacet = opts.mainFacet->stringValue();
+			pkgdata.mainFacet = opts.mainFacet->stringValue();
 
 		if (opts.secondaryFacet->isSet())
-			engine.secondaryFacet = opts.secondaryFacet->stringValue();
+			pkgdata.secondaryFacet = opts.secondaryFacet->stringValue();
 
 		if (opts.ftags->isSet())
 		{
@@ -425,29 +187,27 @@ int main(int argc, const char* argv[])
 				else
 					fquery = Xapian::Query(Xapian::Query::OP_AND, fquery, Xapian::Query("XT"+*i));
 			}
-			engine.globalFilter = fquery;
+			pkgdata.globalFilter = fquery;
 		}
 
 		/*
 		cerr << " *** Initial:" << endl;
-		printResults(engine);
+		printResults(pkgdata);
 
-		engine.setTypeFilter(engine.voc().tagByName("game::arcade"));
+		pkgdata.setTypeFilter(pkgdata.voc().tagByName("game::arcade"));
 		cerr << " *** Arcades:" << endl;
-		printResults(engine);
+		printResults(pkgdata);
 
-		engine.setInterfaceFilter(engine.voc().tagByName("interface::x11"));
+		pkgdata.setInterfaceFilter(pkgdata.voc().tagByName("interface::x11"));
 		cerr << " *** X11 Arcades:" << endl;
-		printResults(engine);
+		printResults(pkgdata);
 
-		engine.setInstalledFilter(Engine::INSTALLED);
+		pkgdata.setInstalledFilter(pkgdata::INSTALLED);
 		cerr << " *** Installed X11 Arcades:" << endl;
-		printResults(engine);
+		printResults(pkgdata);
 		*/
 
-		PackageFilter pkgfilter;
-		GUIPlugInData data(engine, pkgfilter);
-		gui->Go(data);
+		gui->Go(pkgdata);
 
 		delete gui;
 		return 0;
diff --git a/gui_cli.cpp b/gui_cli.cpp
index 5416dd7..48fdc56 100644
--- a/gui_cli.cpp
+++ b/gui_cli.cpp
@@ -68,7 +68,7 @@ class GUIPlugInCLI : public GUIPlugIn
 	}
 
 	virtual void Comment(const char *szFormat, ...);
-	virtual bool Go(GUIPlugInData &data);
+	virtual bool Go(PackageData &pkgdata);
 };
 
 void GUIPlugInCLI::Comment(const char *szFormat, ...)
@@ -85,11 +85,9 @@ void GUIPlugInCLI::Comment(const char *szFormat, ...)
 	std::cout << "# " << str << std::endl;
 }
 
-bool GUIPlugInCLI::Go(GUIPlugInData &data)
+bool GUIPlugInCLI::Go(PackageData &pkgdata)
 {
 	std::ostream &out = std::cout;
-	Engine &engine = data.GetEngine();
-	PackageFilter &pkgfilter = data.GetPackageFilter();
 
 	bool run = true;
 
@@ -158,7 +156,7 @@ bool GUIPlugInCLI::Go(GUIPlugInData &data)
 				{
 					case 'T': case 't':
 					{
-						const set<Tag> types = engine.types();
+						const set<Tag> types = pkgdata.types();
 						for (set<Tag>::const_iterator i = types.begin(); i != types.end(); ++i)
 						{
 							out << " " << i->shortDescription().c_str() << std::endl;
@@ -168,7 +166,7 @@ bool GUIPlugInCLI::Go(GUIPlugInData &data)
 					}
 					case 'I': case 'i':
 					{
-						const set<Tag> ifaces = engine.interfaces();
+						const set<Tag> ifaces = pkgdata.interfaces();
 						for (set<Tag>::const_iterator i = ifaces.begin();
 								i != ifaces.end(); ++i)
 						{
@@ -179,14 +177,14 @@ bool GUIPlugInCLI::Go(GUIPlugInData &data)
 					}
 					case 'R': case 'r':
 					{
-						const std::vector<Result> res = engine.results();
+						const std::vector<Result> res = pkgdata.results();
 						for (vector<Result>::const_iterator i = res.begin();
 								i != res.end(); ++i)
 						{
-							PackageRecord rec(engine.apt().rawRecord(i->name));
+							PackageRecord rec(pkgdata.apt().rawRecord(i->name));
 //							char* userData = pkgString(rec.package());
-								set<Tag> tags = engine.debtags().getTagsOfItem((const char *)rec.package().c_str());
-							switch (pkgfilter.TagsValue(tags))
+								set<Tag> tags = pkgdata.debtags().getTagsOfItem((const char *)rec.package().c_str());
+							switch (pkgdata.GetPackageFilter().TagsValue(tags))
 							{
 								case PackageFilter::Green:
 									break;
@@ -205,12 +203,12 @@ bool GUIPlugInCLI::Go(GUIPlugInData &data)
 							// Relevance is 0 to 100
 							// Popcon is a weird floating point number (to be improved)
 							//FIXMEaddToResults(rec.package() + " - " + rec.shortDescription(), i->relevance, i->popcon);
-							if (engine.popcon().hasData() && i->popcon)
+							if (pkgdata.popcon().hasData() && i->popcon)
 							{
-								out << "\tPOPCON=" << (int)rintf(log(i->popcon) * 100 / log(engine.popconLocalMax()));
+								out << "\tPOPCON=" << (int)rintf(log(i->popcon) * 100 / log(pkgdata.popconLocalMax()));
 							}
 
-							if (engine.popcon().hasData() && i->relevance)
+							if (pkgdata.popcon().hasData() && i->relevance)
 							{
 								out << "\tRELEVANCE=" << i->relevance;
 							}
@@ -231,7 +229,7 @@ bool GUIPlugInCLI::Go(GUIPlugInData &data)
 				out << "#get " << name << std::endl ;
 				if (memcmp(captures[2].ptr, "INSTALLED", 9) == 0)
 				{
-					switch (engine.getInstalledFilter())
+					switch (pkgdata.getInstalledFilter())
 					{
 						case Engine::INSTALLED:
 							out << "installed=yes" << std::endl ;
@@ -249,7 +247,7 @@ bool GUIPlugInCLI::Go(GUIPlugInData &data)
 				}
 				if (memcmp(captures[2].ptr, "KEYWORD", 7) == 0)
 				{
-					out << "keyword=\"" << engine.getKeywordFilter() << "\"" << std::endl ;
+					out << "keyword=\"" << pkgdata.getKeywordFilter() << "\"" << std::endl ;
 				}
 				if (memcmp(captures[2].ptr, "TYPE", 4) == 0)
 				{
diff --git a/gui_fltk.cpp b/gui_fltk.cpp
index e97f486..8c45421 100644
--- a/gui_fltk.cpp
+++ b/gui_fltk.cpp
@@ -37,6 +37,9 @@
 
 #include <stdarg.h>
 #include <string.h>
+#include <math.h>
+
+#include <ept/apt/packagerecord.h>
 
 class GUIPlugInFLTK : public GUIPlugIn
 {
@@ -52,7 +55,7 @@ class GUIPlugInFLTK : public GUIPlugIn
 	}
 
 	virtual void Comment(const char *szFormat, ...);
-	virtual bool Go(GUIPlugInData &data);
+	virtual bool Go(PackageData &pkgdata);
 };
 
 void GUIPlugInFLTK::Comment(const char *szFormat, ...)
@@ -70,27 +73,36 @@ void GUIPlugInFLTK::Comment(const char *szFormat, ...)
 }
 
 
+static const char* ReadFlChoice(Fl_Choice& c)
+{
+	const Fl_Menu_Item* cur = c.mvalue();
+	if (cur->user_data_)
+		return (const char*)cur->user_data_;
+	else
+		return "";
+}
 
 static void UpdateUILists(GamesUI& ui)
 {
+	PackageData &pkgdata = *(PackageData *)(ui.user_data);
+
 	// Defining this here, non-const, because fltk's interface want non-const
 	// strings and I did not have time to check whether it would attempt to
 	// modify the parameter or not.  Likely not, and thus a
 	// const_cast<char*>(VoidString) would probably have been better.
 	// --Enrico
 	char VoidString[1] = "";
-//	const char* oldType = ReadFlChoice(*ui.TypeSelection);
-//	const char* oldIface = ReadFlChoice(*ui.InterfaceSelection);
+	const char* oldType = ReadFlChoice(*ui.TypeSelection);
+	const char* oldIface = ReadFlChoice(*ui.InterfaceSelection);
 	ui.TypeSelection->clear();
 	ui.TypeSelection->add(_("Any type"), 0, NULL, VoidString, FL_NORMAL_LABEL);
 	ui.InterfaceSelection->clear();
 	ui.InterfaceSelection->add(_("Any interface"), 0, NULL, VoidString, FL_NORMAL_LABEL);
 
-	bool PopconAvailable = true;
 	static int widths_with_popcon[] = { 100, 300, 0 }; // widths for each column
 	static int widths_without_popcon[] = { 100, 0 };
 	ui.ResultsBrowser->clear();
-	if (PopconAvailable)
+	if (pkgdata.popcon().hasData())
 	{
 		ui.ResultsBrowser->column_widths(widths_with_popcon);
 		// tab delimited columns with colors
@@ -102,6 +114,81 @@ static void UpdateUILists(GamesUI& ui)
 		// tab delimited columns with colors
 		ui.ResultsBrowser->add(_("@B12 at C7@b at .PACKAGE\t at B12@C7 at b@.DESCRIPTION"));
 	}
+
+	// FIXME: there are better ways to remember the previous item
+
+	const PackageData::TagSet types = pkgdata.types();
+	int newIdx = 0;
+	for (PackageData::TagSet::const_iterator i = types.begin();
+			i != types.end(); ++i)
+	{
+		int idx = ui.TypeSelection->add(gettext(i->shortDescription().c_str()),
+							0, NULL, pkgdata.TagString(*i), FL_NORMAL_LABEL);
+		if (i->fullname() == oldType)
+			newIdx = idx;
+	}
+	ui.TypeSelection->value(newIdx);
+
+	const PackageData::TagSet ifaces = pkgdata.interfaces();
+	newIdx = 0;
+	for (PackageData::TagSet::const_iterator i = ifaces.begin();
+			i != ifaces.end(); ++i)
+	{
+		int idx = ui.InterfaceSelection->add(gettext(i->shortDescription().c_str()),
+							0, NULL, pkgdata.TagString(*i), FL_NORMAL_LABEL);
+		if (i->fullname() == oldIface)
+			newIdx = idx;
+	}
+	ui.InterfaceSelection->value(newIdx);
+
+	const std::vector<Result> res = pkgdata.results();
+	for (vector<Result>::const_iterator i = res.begin();
+			i != res.end(); ++i)
+	{
+		ept::apt::PackageRecord rec(pkgdata.apt().rawRecord(i->name));
+		char* userData = pkgdata.PackageString(rec.package());
+
+		// Available Colors: FL_BLACK, FL_BLUE, FL_CYAN, FL_DARK_BLUE,
+		// FL_DARK_CYAN, FL_DARK_GREEN FL_DARK_MAGENTA, FL_DARK_RED,
+		// FL_DARK_YELLOW, FL_GREEN, FL_MAGENTA, FL_RED, FL_WHITE, FL_YELLOW
+
+		Fl_Color bk(FL_WHITE);
+		Fl_Color fr(FL_BLACK);
+		PackageData::TagSet tags = pkgdata.debtags().getTagsOfItem((const char *)rec.package().c_str());
+		switch (pkgdata.GetPackageFilter().TagsValue(tags))
+		{
+			case PackageFilter::Green:
+				fr = FL_BLACK; bk = FL_GREEN; break;
+			case PackageFilter::Yellow:
+				fr = FL_BLACK; bk = FL_YELLOW; break;
+			case PackageFilter::Red:
+				fr = FL_WHITE; bk = FL_RED; break;
+			case PackageFilter::Black:
+				fr = FL_WHITE; bk = FL_BLACK; break;
+			default:
+				fr = FL_BLACK; bk = FL_WHITE; break;
+		}
+
+		char fmtstr[16];
+		snprintf(fmtstr, sizeof(fmtstr), "@B%d at C%d at .", bk, fr);
+
+		string desc = string(fmtstr) + rec.package() + "\t" + 
+			string(fmtstr) + rec.shortDescription();
+		if (pkgdata.popcon().hasData() && i->popcon)
+		{
+			desc += "\t" + string(fmtstr);
+			char stars[16];
+			snprintf(stars, sizeof(stars), "%%%d/8/1;",
+				(int)rintf(log(i->popcon) * 100 / log(pkgdata.popconLocalMax())));
+			desc += stars;
+			//printf ("%s (%s): POPCON=%f\n", rec.package().c_str(), rec.shortDescription().c_str(), i->popcon);
+		}
+		ui.ResultsBrowser->add(desc.c_str(), userData);
+
+		// Relevance is 0 to 100
+		// Popcon is a weird floating point number (to be improved)
+		//FIXMEaddToResults(rec.package() + " - " + rec.shortDescription(), i->relevance, i->popcon);
+	}
 }
 
 static void CallBackTypeSelection(Fl_Choice* choice, void *data)
@@ -160,7 +247,7 @@ static void CallBackInstalledOrNot(Fl_Round_Button*, void *data)
 	UpdateUILists(ui);
 }
 
-bool GUIPlugInFLTK::Go(GUIPlugInData &data)
+bool GUIPlugInFLTK::Go(PackageData &pkgdata)
 {
 #ifdef USE_GETTEXT
 	setlocale (LC_MESSAGES, "");
@@ -171,7 +258,7 @@ bool GUIPlugInFLTK::Go(GUIPlugInData &data)
 #endif
 
 	GamesUI mainui;
-	mainui.user_data = NULL;
+	mainui.user_data = &pkgdata;
 	Fl_Double_Window *window = mainui.CreateWindows();
 	mainui.TypeSelection->callback((Fl_Callback*)CallBackTypeSelection, &mainui);
 	mainui.TypeSelection->when(FL_WHEN_CHANGED);
diff --git a/guiplugin.h b/guiplugin.h
index 28b077c..1052350 100644
--- a/guiplugin.h
+++ b/guiplugin.h
@@ -23,8 +23,7 @@
 #define _GOFIND_GUIPLUGIN_H
 
 #include "dll.h"
-#include "Engine.h"
-#include "filter.h"
+#include "pkgdata.h"
 
 #include <iostream>
 
@@ -34,29 +33,6 @@ using namespace ept;
 
 class GUIPlugInFactory;
 
-class GUIPlugInData
-{
- public:
-	 GUIPlugInData(Engine &e, PackageFilter &pf) :
-		engine(e), pkgfilter(pf)
-	{
-	}
-
-	Engine &GetEngine()
-	{
-		return engine;
-	}
-
-	PackageFilter &GetPackageFilter()
-	{
-		return pkgfilter;
-	}
-
- protected:
-	Engine &engine;
-	PackageFilter &pkgfilter;
-};
-
 class GUIPlugIn
 {
  public:
@@ -65,7 +41,7 @@ class GUIPlugIn
 	virtual ~GUIPlugIn();
 
 	virtual void Comment(const char *szFormat, ...) = 0;
-	virtual bool Go(GUIPlugInData &data) = 0;
+	virtual bool Go(PackageData &data) = 0;
  
  protected:
 	GUIPlugInFactory *factory;
diff --git a/pkgdata.cpp b/pkgdata.cpp
new file mode 100644
index 0000000..491dfae
--- /dev/null
+++ b/pkgdata.cpp
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2008  Miriam Ruiz <little_miry at yahoo.es>
+ *
+ * http://www.jdkoftinoff.com/main/Articles/Linux_Articles/ELF_Plugins/ 
+ *
+ * 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 "pkgdata.h"
+#include "common.h"
+
+#include "Environment.h"
+#include "GamesOptions.h"
+#include "pkgdata.h"
+
+#include <ept/apt/packagerecord.h>
+#include <wibble/regexp.h>
+#include <wibble/string.h>
+#include <xapian.h>
+
+#include <iostream>
+#include <cmath>
+
+#ifdef USE_GETTEXT
+#include <libintl.h>
+#include <locale.h>
+#else
+// Work-around until goplay is actually gettextised
+#define gettext(a) (a)
+#endif
+
+#include <string.h>
+
+PackageData::PackageData()
+{
+}
+
+PackageData::~PackageData()
+{
+}
+
+char *PackageData::TagString(const Tag& tag)
+{
+	static std::map<std::string, char*> table;
+	std::map<std::string, char*>::iterator i = table.find(tag.fullname());
+	if (i == table.end())
+	{
+		std::pair< std::map<std::string, char*>::iterator, bool > tmp =
+			table.insert(make_pair(tag.fullname(), strdup(tag.fullname().c_str())));
+		i = tmp.first;
+	}
+	return i->second;
+}
+
+char *PackageData::PackageString(const std::string& name)
+{
+	static std::map<std::string, char*> table;
+	std::map<std::string, char*>::iterator i = table.find(name);
+	if (i == table.end())
+	{
+		std::pair< std::map<std::string, char*>::iterator, bool > tmp =
+			table.insert(make_pair(name, strdup(name.c_str())));
+		i = tmp.first;
+	}
+	return i->second;
+}
+
+void PackageData::PrintResults()
+{
+	const vector<Result>& packages = results();
+	for (vector<Result>::const_iterator i = packages.begin();
+			i != packages.end(); ++i)
+	{
+		ept::apt::PackageRecord pkg = apt().rawRecord(i->name);
+		std::cerr << "PKG " << pkg.package() << " - " << pkg.shortDescription() << std::endl;
+	}
+
+	const std::set<Tag>& ttags = types();
+	for (std::set<Tag>::const_iterator i = ttags.begin();
+			i != ttags.end(); ++i)
+	{
+		std::cerr << "TTAG " << i->fullname() << std::endl;
+	}
+
+	const std::set<Tag>& ftags = interfaces();
+	for (std::set<Tag>::const_iterator i = ftags.begin();
+			i != ftags.end(); ++i)
+	{
+		std::cerr << "ITAG " << i->fullname() << std::endl;
+	}
+}
diff --git a/guiplugin.cpp b/pkgdata.h
similarity index 61%
copy from guiplugin.cpp
copy to pkgdata.h
index 1786050..1f5d4ba 100644
--- a/guiplugin.cpp
+++ b/pkgdata.h
@@ -1,5 +1,4 @@
 /*
- * Copyright (C) 1995  Jeff Koftinoff <jeffk at jdkoftinoff.com>
  * Copyright (C) 2008  Miriam Ruiz <little_miry at yahoo.es>
  *
  * http://www.jdkoftinoff.com/main/Articles/Linux_Articles/ELF_Plugins/ 
@@ -19,28 +18,37 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include "common.h"
-#include "guiplugin.h"
+#ifndef _GOFIND_PACKAGEDATA_H
+#define _GOFIND_PACKAGEDATA_H
 
-#include <typeinfo>
-#include <iostream>
+#include "dll.h"
+#include "Engine.h"
+#include "filter.h"
 
-#ifdef GUIPLUGIN_VERSION
-	const unsigned int GUIPlugInFactory::version = GUIPLUGIN_VERSION;
-#endif
+#include <ept/debtags/tag.h>
 
-//
-// Announce to the world that the PlugIn base
-// class has been created or destroyed
-//
+using namespace ept;
 
-GUIPlugIn::GUIPlugIn(GUIPlugInFactory *f) : factory(f)
+class PackageData : public Engine
 {
-	std::cout << "GUIPlugIn Created" << std::endl;
-}
+ public:
+	PackageData();
+	~PackageData();
 
-GUIPlugIn::~GUIPlugIn()
-{
-	std::cout << "GUIPlugIn Destroyed" << std::endl;
-}
+	typedef ept::debtags::Tag Tag;
+	typedef std::set<Tag> TagSet;
+
+	char *TagString(const Tag& tag);
+	char *PackageString(const std::string& name);
+	void PrintResults();
+
+	PackageFilter &GetPackageFilter()
+	{
+		return pkgfilter;
+	}
+
+protected:
+	PackageFilter pkgfilter;
+};
 
+#endif // _GOFIND_PACKAGEDATA_H

-- 
Development fot GoFind!



More information about the Pkg-games-commits mailing list