r3024 - software/ui/src

Miriam Ruiz baby-guest at alioth.debian.org
Wed Jun 20 17:26:43 UTC 2007


Author: baby-guest
Date: 2007-06-20 17:26:43 +0000 (Wed, 20 Jun 2007)
New Revision: 3024

Modified:
   software/ui/src/games.cpp
   software/ui/src/ui.fld
Log:
First prototype works! :)



Modified: software/ui/src/games.cpp
===================================================================
--- software/ui/src/games.cpp	2007-06-20 15:36:51 UTC (rev 3023)
+++ software/ui/src/games.cpp	2007-06-20 17:26:43 UTC (rev 3024)
@@ -78,6 +78,31 @@
 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();
@@ -103,6 +128,116 @@
 	}
 }
 
+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 char *VoidString = "";
+
+void UpdateUILists(GamesUI& ui)
+{
+	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);
+	ui.ResultsBrowser->clear();
+	
+	// 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)
+	{
+		int idx = ui.InterfaceSelection->add(gettext(i->shortDescription().c_str()),
+							0, NULL, tagString(*i), FL_NORMAL_LABEL);
+		if (i->fullname() == oldIface)
+			newIdx = idx;
+	}
+	ui.InterfaceSelection->value(newIdx);
+
+	const std::vector<Result> res = engine.results();
+	for (vector<Result>::const_iterator i = res.begin();
+			i != res.end(); ++i)
+	{
+		PackageRecord rec(engine.apt().rawRecord(i->name));
+		char* userData = pkgString(rec.package());
+		ui.ResultsBrowser->add((rec.package() + " - " + rec.shortDescription()).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);
+	}
+}
+
+void CallBackSearchButton(Fl_Button *button, void *data)
+{
+	GamesUI& ui = *static_cast<GamesUI*>(data);
+	printf("CallBackSearchButton\n");
+	fflush(stdout);
+	UpdateUILists(ui);
+}
+
+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);
+}
+
+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);
+}
+
+void CallBackInstalledButton(Fl_Check_Button*, void *data)
+{
+	GamesUI& ui = *static_cast<GamesUI*>(data);
+	printf("CallBackInstalledButton\n");
+	fflush(stdout);
+	//ui.engine->setInstalledFilter(Engine::ANY);
+	ui.engine->setInstalledFilter(Engine::INSTALLED);
+	UpdateUILists(ui);
+}
+
+void CallBackToBeInstalledButton(Fl_Check_Button*, void *data)
+{
+	GamesUI& ui = *static_cast<GamesUI*>(data);
+	printf("CallBackToBeInstalledButton\n");
+	fflush(stdout);
+	//ui.engine->setInstalledFilter(Engine::ANY);
+	ui.engine->setInstalledFilter(Engine::NOTINSTALLED);
+	UpdateUILists(ui);
+}
+
 int main(int argc, const char* argv[])
 {
 #ifdef USE_GETTEXT
@@ -130,6 +265,7 @@
 
 		Engine engine;
 
+		/*
 		cerr << " *** Initial:" << endl;
 		printResults(engine);
 
@@ -144,9 +280,20 @@
 		engine.setInstalledFilter(Engine::INSTALLED);
 		cerr << " *** Installed X11 Arcades:" << endl;
 		printResults(engine);
+		*/
 
 		GamesUI mainui;
+		mainui.engine = &engine;
 		Fl_Double_Window *window = mainui.CreateMainWindow();
+		mainui.SearchButton->callback((Fl_Callback*)CallBackSearchButton, &mainui);
+		mainui.TypeSelection->when(FL_WHEN_RELEASE);
+		mainui.TypeSelection->callback((Fl_Callback*)CallBackTypeSelection, &mainui);
+		mainui.TypeSelection->when(FL_WHEN_CHANGED);
+		mainui.InterfaceSelection->callback((Fl_Callback*)CallBackInterfaceSelection, &mainui);
+		mainui.InterfaceSelection->when(FL_WHEN_CHANGED);
+
+		UpdateUILists(mainui);
+
 		window->show(argc, (char**)argv);
 		while (Fl::wait());
 		return 0;

Modified: software/ui/src/ui.fld
===================================================================
--- software/ui/src/ui.fld	2007-06-20 15:36:51 UTC (rev 3023)
+++ software/ui/src/ui.fld	2007-06-20 17:26:43 UTC (rev 3024)
@@ -5,61 +5,63 @@
 i18n_function _ 
 header_name {.h} 
 code_name {.cpp}
+decl {class Engine;} {public
+} 
+
 class GamesUI {open
 } {
   Function {CreateMainWindow()} {open
   } {
     Fl_Window {} {open
-      xywh {635 83 305 360} type Double resizable visible
+      xywh {633 63 385 360} type Double resizable visible
     } {
-      Fl_Group {} {
-        label Install open
-        xywh {5 29 295 36} box UP_BOX
+      Fl_Group {} {open
+        xywh {5 14 375 82} box UP_FRAME
       } {
         Fl_Tile {} {open
-          xywh {14 35 280 25}
+          xywh {10 15 365 36}
         } {
           Fl_Check_Button AlreadyInstalledButton {
-            label {Already installed}
-            xywh {19 35 25 25} down_box DOWN_BOX
+            label {Already installed} selected
+            xywh {14 15 25 36} down_box DOWN_BOX
           }
           Fl_Check_Button ToBeInstalledButton {
             label {To be installed}
-            xywh {164 35 25 25} down_box DOWN_BOX
+            xywh {195 15 25 36} down_box DOWN_BOX
           }
         }
       }
+      Fl_Browser ResultsBrowser {
+        xywh {5 105 375 220} resizable
+      }
+      Fl_Button SearchButton {
+        label Search
+        xywh {5 330 375 25}
+      }
       Fl_Tile {} {open
-        xywh {25 75 460 150}
+        xywh {10 60 365 30}
       } {
         Fl_Choice TypeSelection {
           label Type open
-          xywh {55 75 25 25} down_box BORDER_BOX
+          xywh {60 60 125 30} down_box BORDER_BOX when 1
         } {
           MenuItem {} {
             label {Any type}
-            xywh {0 0 100 20}
+            xywh {15 15 100 20}
           }
         }
         Fl_Choice InterfaceSelection {
           label Interface open
-          xywh {215 75 25 25} down_box BORDER_BOX
+          xywh {260 60 115 30} down_box BORDER_BOX
         } {
           MenuItem {} {
             label {Any interface}
-            xywh {0 0 100 20}
+            xywh {15 15 100 20}
           }
         }
       }
-      Fl_Browser ResultsBrowser {
-        xywh {5 115 295 210}
-      }
-      Fl_Button {} {
-        label Search
-        callback {printf("BUTTON\\n");
-fflush(stdout);} selected
-        xywh {5 330 295 25} resizable
-      }
     }
   }
+  decl {Engine *engine;} {public
+  }
 } 




More information about the Pkg-games-commits mailing list