[yast-commit] r66185 - in /branches/tmp/lslezak/sound/sound/src: Joystick.ycp joy_dialog.ycp joystick.ycp
Author: lslezak Date: Fri Sep 30 11:07:25 2011 New Revision: 66185 URL: http://svn.opensuse.org/viewcvs/yast?rev=66185&view=rev Log: refactoring joystick configuration, added support for USB joysticks Modified: branches/tmp/lslezak/sound/sound/src/Joystick.ycp branches/tmp/lslezak/sound/sound/src/joy_dialog.ycp branches/tmp/lslezak/sound/sound/src/joystick.ycp Modified: branches/tmp/lslezak/sound/sound/src/Joystick.ycp URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/sound/sound/src/Joystick.ycp?rev=66185&r1=66184&r2=66185&view=diff ============================================================================== --- branches/tmp/lslezak/sound/sound/src/Joystick.ycp (original) +++ branches/tmp/lslezak/sound/sound/src/Joystick.ycp Fri Sep 30 11:07:25 2011 @@ -39,6 +39,13 @@ // database entry global string generic_joystick_translated = _("Generic Analog Joystick"); + list<map> detected_joysticks = []; + + global list<map> Detected() + { + return detected_joysticks; + } + /** * Get list of all required joystick kernel modules * @return list list of modules @@ -173,6 +180,8 @@ } joystick_backup = joystick; + + detected_joysticks = (list<map>)SCR::Read(.probe.joystick); return true; } Modified: branches/tmp/lslezak/sound/sound/src/joy_dialog.ycp URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/sound/sound/src/joy_dialog.ycp?rev=66185&r1=66184&r2=66185&view=diff ============================================================================== --- branches/tmp/lslezak/sound/sound/src/joy_dialog.ycp (original) +++ branches/tmp/lslezak/sound/sound/src/joy_dialog.ycp Fri Sep 30 11:07:25 2011 @@ -14,12 +14,13 @@ textdomain "sound"; import "Wizard"; + import "WizardHW"; import "Joystick"; import "Sound"; - import "Joystick"; import "Package"; import "Label"; import "Popup"; + import "String"; include "sound/joysticks.ycp"; include "sound/ui.ycp"; @@ -503,6 +504,7 @@ `next : Label::NextButton() ]; + Wizard::OpenNextBackDialog(); Wizard::SetContents (caption, contents, helptext, true, true); Wizard::SetNextButton(`next, nextbutton[button]:Label::NextButton() ); if (!Mode::installation()) Wizard::HideBackButton(); @@ -583,9 +585,329 @@ } if (!Mode::installation()) Wizard::RestoreBackButton(); + Wizard::CloseDialog(); return s; } + define list<map<string,any> > joystick_table() + { + list<map<string,any> > content = []; + foreach(map js, Joystick::Detected(), + { + string device = js["dev_name2"]:""; + string model = js["model"]:""; + list<string> descr = []; + + if (js["detail","axes"]:0 > 0) + { + descr = add(descr, sformat(_("Number of axes: %1"), js["detail","axes"]:0)); + } + + if (js["detail","buttons"]:0 > 0) + { + descr = add(descr, sformat(_("Number of buttons: %1"), js["detail","buttons"]:0)); + } + + map<string,any> j = $[ + "id" : device, + "table_descr" : [ js["model"]:"", device, js["bus"]:"" ], + "rich_descr" : WizardHW::CreateRichTextDescription(model, descr) + ]; + + content = add(content, j); + }); + + return content; + } + + map find_joystick(string device) + { + return find(map j, Joystick::Detected(), {return j["dev_name2"]:"" == device;}); + } + + void test_joystick(string device) + { + map js = find_joystick(device); + if (js == nil) + { + y2error("Cannot find joystick %1", device); + return; + } + + // generate appropriate dialog for the joystick + term joy_attrib = `VBox(); + integer min = -32767; // see js_event.value in linux/joystick.h + integer max = 32767; + integer i = 0; + + while (i < js["detail","axes"]:0) + { + // progress bar label + string widget_name = sformat(_("Axis %1"), i); + string widget_id = sformat("Axis %1", i); + + if (UI::HasSpecialWidget(`Slider)) + { + joy_attrib = add(joy_attrib, `Slider(`id(widget_id), `opt(`disabled), widget_name, min, max, 0)); + } + else + { + joy_attrib = add(joy_attrib, `IntField(`id(widget_id), `opt(`disabled), widget_name, min, max, 0)); + } + + joy_attrib = add(joy_attrib, `VSpacing(0.3)); + i = i + 1; + } + + term joy_buttons = `HBox(); + string not_pressed = " "; + string pressed = UI::Glyph(`CheckMark); + + i = 0; + while (i < js["detail","buttons"]:0) + { + // label + string widget_name = sformat(_("Button %1"), i); + string widget_id = sformat ("Button %1", i); + joy_buttons = add (joy_buttons, + `Label (`id(widget_id), widget_name + " " + not_pressed)); + joy_buttons = add (joy_buttons, `HSpacing(2)); + i = i + 1; + } + joy_attrib = add (joy_attrib, joy_buttons); + + UI::OpenDialog(`opt(`decorated), `HBox(`HSpacing(1.5), + `VSpacing(18), + `VBox( + `HSpacing(50), + `VSpacing(1), + // Popup label + `Heading(_("Joystick Test")), + `VSpacing(1), + joy_attrib, + `VSpacing(1), + `PushButton(`id(`done), `opt(`default), Label::OKButton()), + `VSpacing(1) + ), + `HSpacing(1.5) + )); + + string command = sformat("/usr/bin/jstest --event '%1'", String::Quote(device)); + integer process = (integer)SCR::Execute(.process.start_shell, command); + + symbol ret = nil; + + // read the jstest output until "OK" button is pushed + do + { + if (SCR::Read(.process.running, process) == false) + { + y2error("Unexpected exit"); + break; + } + + string out = (string)SCR::Read(.process.read_line, process); + + if (out != nil) + { + y2debug("jstest output: %1", out); + + // the output is like "Event: type 2, time 26263500, number 0, value 0" + string type_str = regexpsub(out, "type ([0-9]+)", "\\1"); + string number_str = regexpsub(out, "number ([0-9]+)", "\\1"); + string value_str = regexpsub(out, "value ([-]{0,1}[0-9]+)", "\\1"); + + if (type_str != nil && number_str != nil && value_str != nil) + { + integer type = tointeger(type_str); + integer number = tointeger(number_str); + integer value = tointeger(value_str); + + if (type == 1) + { + // button state changed + UI::ChangeWidget(`id(sformat("Button %1", number)), `Value, + // label text ("Button" is joystick's button no. %1) + sformat(_("Button %1"), number) + " " + (value == 1 ? pressed : not_pressed)); + } + else if (type == 2) + { + // change in some axis + UI::ChangeWidget(`id(sformat ("Axis %1", number)), `Value, value) ; + } + } + } + ret = (symbol)UI::PollInput(); + } + while (ret == nil); + + y2milestone ("killing"); + SCR::Execute(.process.kill, process); + + // release the process from the agent + SCR::Execute(.process.release, process); + + UI::CloseDialog(); + } + + + integer select_sound_card(list gameport_cards) + { + list tcont = maplist (map card, (list<map>) gameport_cards, ``{ + map jconf = Joystick::joystick[ card["card_no"]:0 ]:$[]; + string jmodel = jconf["model"]:""; + + // translate generic joystick + if (jmodel == Joystick::generic_joystick) + jmodel = Joystick::generic_joystick_translated; + + return `item( + `id(card["card_no"]:0), + sformat("%1", card["card_no"]:0), + card["name"]:"Sound card", + jmodel + ); + }); + + term dialog = `VBox( + `Heading(_("Configured Sound Cards with Joystick Support")), + `Table(`id(`cards), `header( + // table header (number) + _("No."), + // table header (card name) + _("Sound card"), + // table header (joystick type) + _("Joystick")), tcont + ), + `Label("To add an USB joystick close this dialog and just connect it."), + `ButtonBox( + // button label + `PushButton(`id(`ok), _("&Configure joystick")), + `PushButton(`id(`cancel), Label::CancelButton()) + ) + ); + + UI::OpenDialog(`opt(`decorated), dialog); + + // preselect first card + UI::ChangeWidget (`id(`cards), `CurrentItem, gameport_cards[0,"card_no"]:0); + + symbol ret = (symbol) UI::UserInput(); + y2internal("UI: %1", ret); + + if (ret == `cancel || ret == `abort) { + y2milestone("Sound card selection canceled"); + return nil; + } + + integer joy_card = (integer) UI::QueryWidget(`id(`cards), `CurrentItem); + y2milestone("Selected sound card: %1", joy_card); + + return joy_card; + } + + boolean is_usb(string device) + { + map js = find_joystick(device); + if (js == nil) return false; + + return js["bus"]:"" == "USB"; + } + + define symbol joystick_overview() + { + list<list> extra_buttons = [ + // menu item + [`test, _("&Test...")], + ]; + + // dialog title + WizardHW::CreateHWDialog(_("Joysticks"), + "", + // table header + [_("Model"), _("Device name"), _("Attached to")], + extra_buttons + ); + + // create description for WizardHW + list<map<string,any> > items = joystick_table(); + y2debug("items: %1", items); + + WizardHW::SetContents(items); + + symbol ret = `dummy; + + while (!contains([`abort, `back, `next],ret)) + { + map<string,any> ev = WizardHW::WaitForEvent(); + y2milestone("WaitForEvent: %1", ev); + + ret = (symbol)ev["event","ID"]:nil; + string device = WizardHW::SelectedItem(); + + if (ret == `add) + { + list jcards = Sound::GetSoundCardListWithJoy(); + + // no sound card with gameport + if (size(jcards) == 0) + { + string message = _("There is no soundcard with joystick support (gameport).") + + "\n" + _("USB joysticks do not need any configuration, just plug them."); + + Popup::Message(message); + } + else + { + integer selected = nil; + + if (size(jcards) == 1) + { + selected = jcards[0, "card_no"]:0; + } + else + { + selected = select_sound_card(jcards); + } + + if (selected != nil) + { + joy_dialog(selected, `ok); + } + } + } + else if (ret == `edit) + { + if (is_usb(device)) + { + // popup message - pressed [Edit] when an USB joystick is selected + Popup::Message("USB joysticks do not need any configuration."); + } + else + { + } + } + else if (ret == `delete) + { + if (is_usb(device)) + { + // popup message - pressed [Delete] when an USB joystick is selected + Popup::Message("USB joysticks cannot be deleted, just unplug them."); + } + else + { + } + } + else if (ret == `test) + { + test_joystick(device); + } + } + + y2internal("Joystick overview result: %1", ret); + return ret; + } + /* EOF */ } Modified: branches/tmp/lslezak/sound/sound/src/joystick.ycp URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/sound/sound/src/joystick.ycp?rev=66185&r1=66184&r2=66185&view=diff ============================================================================== --- branches/tmp/lslezak/sound/sound/src/joystick.ycp (original) +++ branches/tmp/lslezak/sound/sound/src/joystick.ycp Fri Sep 30 11:07:25 2011 @@ -61,6 +61,8 @@ */ define symbol joystick_configuration() ``{ + return joystick_overview(); + // helptext string helptext = _("<P>Two or more sound cards in your system support joysticks.</P> <P>To configure a joystick, select the sound card and press <B>Configure Joystick</B>.</P> -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
lslezak@svn2.opensuse.org