[yast-commit] r66209 - in /branches/tmp/lslezak/sound/sound/src: Joystick.ycp joy_dialog.ycp joystick.ycp volume.ycp
Author: lslezak Date: Mon Oct 3 17:51:13 2011 New Revision: 66209 URL: http://svn.opensuse.org/viewcvs/yast?rev=66209&view=rev Log: joystick - store the sound card to which it is connected, reload drivers and refresh the table after changes, connect detected and configured 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 branches/tmp/lslezak/sound/sound/src/volume.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=66209&r1=66208&r2=66209&view=diff ============================================================================== --- branches/tmp/lslezak/sound/sound/src/Joystick.ycp (original) +++ branches/tmp/lslezak/sound/sound/src/Joystick.ycp Mon Oct 3 17:51:13 2011 @@ -46,6 +46,11 @@ return detected_joysticks; } + global void Detect() + { + detected_joysticks = (list<map>)SCR::Read(.probe.joystick); + } + /** * Get list of all required joystick kernel modules * @return list list of modules @@ -77,6 +82,26 @@ return ret; } + string format_model_line(string model, string attached_to) + { + return sformat("# Model: %1, Attached to: %2\n", model, attached_to); + } + + list<string> parse_model_line(string line) + { + string regexp = "^#[ \t]*Model: (.*),[ \t]*Attached to:[ \t]*(.*)$"; + + string model = regexpsub(line, regexp, "\\1"); + string attached_to = regexpsub(line, regexp, "\\2"); + + if (model == nil) model = ""; + if (attached_to == nil) attached_to = ""; + + y2milestone("Parsed model line: %1 -> model: %2, attached_to: %3", line, model, attached_to); + + return [model, attached_to]; + } + /** * Read all joystick settings from the SCR * @param abort A block that can be called by Read to find @@ -114,6 +139,7 @@ // read model comment string model = (string) SCR::Read(topath( sformat(".sysconfig.joystick.JOYSTICK_MODULE_%1.comment",pos))); + string attached_to = ""; y2debug("Read model comment: %1", model); @@ -151,28 +177,14 @@ } else { - // remove comment char - if (substring(model, 0, 1) == "#") - { - if (size(model) > 1) - { - model = substring(model, 1); - } - else - { - model = ""; - } - } + list<string> info = parse_model_line(model); - // remove new line char - if (size(model) > 1 && - substring(model, size(model) - 1, 1) == "\n") - { - model = substring(model, 0, size(model) - 1); - } + model = info[0]:""; + attached_to = info[1]:""; } - j = add(j, "model", model); + j["model"] = model; + j["attached_to"] = attached_to; joystick = add(joystick, j); @@ -181,7 +193,7 @@ joystick_backup = joystick; - detected_joysticks = (list<map>)SCR::Read(.probe.joystick); + Detect(); return true; } @@ -224,13 +236,14 @@ // write model comment string model = j["model"]:""; + string attached_to = j["attached_to"]:""; // add comment before first model if (pos == 0) { if (size(model) > 0) { - model = module_comment + "\n#" + model + "\n"; + model = module_comment + "\n" + format_model_line(model, attached_to); } else { @@ -241,7 +254,7 @@ { if (size(model) > 0) { - model = "#" + model + "\n"; + model = format_model_line(model, attached_to); } } 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=66209&r1=66208&r2=66209&view=diff ============================================================================== --- branches/tmp/lslezak/sound/sound/src/joy_dialog.ycp (original) +++ branches/tmp/lslezak/sound/sound/src/joy_dialog.ycp Mon Oct 3 17:51:13 2011 @@ -25,6 +25,7 @@ include "sound/joysticks.ycp"; include "sound/ui.ycp"; include "sound/volume_routines.ycp"; + include "sound/routines.ycp"; list joylist = []; @@ -385,35 +386,46 @@ return true; } + integer find_sound_card_id(map sound_card) + { + integer i = 0; + integer ret = nil; + + foreach(map card, Sound::modules_conf, { + if (card["unique_key"]:"" == sound_card["unique_key"]:"") + { + ret = i; + } + + i = i + 1; + }); + + return ret; + } + /** * Joystick configuration dialog. * Configuration of joystick attached to specified sound card. - * @param card_id Sound card card_id + * @param joy_id Joystick index (in the sysconfig file) * @param button Label for `next button: `finish, `ok or `next * @return symbol Id of pressed button in the dialog */ - define symbol joy_dialog (integer card_id, symbol button) ``{ + define symbol joy_dialog (integer joy_id, symbol button, map sound_card) ``{ // item in joystick types string nonejoy = _("No joystick"); - if (card_id == nil) + if (joy_id == nil) { return `back; } - list jcards = Sound::GetSoundCardListWithJoy(); - // find card name - string cardname = ""; - foreach (map<string,any> card, (list<map<string,any> >)jcards, ``{ - if (card["card_no"]:-1 == card_id) - cardname = card["name"]:""; - }); + string cardname = sound_card["model"]:""; - // dialog header - %1: card name (e.g "Soundblaster 16"), %2: card ID (a number) - string caption = sformat(_("Joystick Configuration - %1 (snd-card-%2)"), cardname, card_id); + // dialog header - %1: card name (e.g "Soundblaster 16") + string caption = sformat(_("Joystick Configuration - %1"), cardname); string helptext = // help text for joystick configuration 1/4 @@ -434,10 +446,10 @@ _("<P><B>Note:</B> Connect your joystick to your computer before pressing <B>Test</B> or <B>Next</B>.</P>"); - map joy = Joystick::joystick[card_id]:$[]; + map joy = Joystick::joystick[joy_id]:$[]; string mod = joy["model"]:""; - y2milestone("Joystick configuration of snd-card-%1 started", card_id); + y2milestone("Joystick configuration started, index: %1", joy_id); // translate model from /etc/sysconfig/joystick if (mod == Joystick::generic_joystick) @@ -531,6 +543,7 @@ if (s == `next) { + integer card_id = find_sound_card_id(sound_card); string modname = Sound::modules_conf[card_id, "module"]:""; map joy_entry = Sound::GetJoystickSettings (modname); integer joymodidx = (integer)UI::QueryWidget(`id(`os),`CurrentItem); @@ -553,13 +566,13 @@ y2debug("selected joy module: %1, model: %2", joymod, model); - joy_entry = add (joy_entry, "JOYSTICK_MODULE", joymod); - joy_entry = add (joy_entry, "model", model); - + joy_entry["JOYSTICK_MODULE"] = joymod; + joy_entry["model"] = model; + joy_entry["attached_to"] = sound_card["unique_key"]:""; } update_sound_card_joy_config (card_id, joymod != ""); - Joystick::joystick[card_id] = joy_entry; + Joystick::joystick[joy_id] = joy_entry; Joystick::modified = true; y2milestone("New joystick configuration: %1", joy_entry); @@ -602,20 +615,33 @@ if (bus == "Gameport" && size(js["parent_unique_key"]:"") > 0) { list<map> soundcards = (list<map>)SCR::Read(.probe.sound); - string unique_id = js["parent_unique_key"]:""; + string unique_key = js["parent_unique_key"]:""; - map card = find(map c, soundcards, {return c["unique_key"]:"" == unique_id;}); + map card = find(map c, soundcards, {return c["unique_key"]:"" == unique_key;}); if (card != nil) { // joystick details, %1 is the sound card name to which is the joystick connected bus = sformat("%1 (%2)", bus, card["model"]:""); } + + map j_config = find(map j, (list<map>)Joystick::joystick, {return j["attached_to"]:"" == unique_key;}); + if (j_config != nil) + { + string config_model = j_config["model"]:""; + + if (config_model != nil && config_model != "") + { + y2milestone("Adding joystick model: %1", config_model); + + model = sformat("%1 (%2)", model, config_model); + } + } } map<string,any> j = $[ "id" : device, - "table_descr" : [ js["model"]:"", device, bus ], + "table_descr" : [ model, device, bus ], "rich_descr" : WizardHW::CreateRichTextDescription(model, descr) ]; @@ -758,66 +784,61 @@ list unconfigured_sound_cards(list gameport_cards) { list ret = filter(map card, (list<map>) gameport_cards, { - return Joystick::joystick[ card["card_no"]:0, "model" ]:"" == ""; + return find(map j, (list<map>)Joystick::joystick, {return j["attached_to"]:"" == card["unique_key"]:"";}) == nil; }); y2milestone("Unconfigured gameport cards: %1", ret); return ret; } - integer select_sound_card(list gameport_cards) + map select_sound_card(list gameport_cards) { + integer i = -1; 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; - + i = i + 1; return `item( - `id(card["card_no"]:0), - sformat("%1", card["card_no"]:0), - card["name"]:"Sound card", - jmodel + `id(i), + card["model"]:"Sound card" ); }); - 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()) + term dialog = `HBox( + `VSpacing(10), + `VBox( + `Heading(_("Sound Cards with Joystick Support")), + `Table(`id(`cards), `header( + // table header (card name) + _("Sound card") + ), + 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); + // preselect the first card + UI::ChangeWidget(`id(`cards), `CurrentItem, 0); symbol ret = (symbol) UI::UserInput(); - y2internal("UI: %1", ret); + + integer joy_card = (integer) UI::QueryWidget(`id(`cards), `CurrentItem); + y2milestone("Selected sound card: %1", joy_card); + + UI::CloseDialog(); 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; + return gameport_cards[joy_card]:$[]; } boolean is_usb(string device) @@ -828,6 +849,92 @@ return js["bus"]:"" == "USB"; } + integer find_joystick_number(string parent_id) + { + integer i = 0; + boolean found = false; + + foreach(map j, (list<map>)Joystick::joystick, { + if (j["attached_to"]:"" == parent_id) + { + found = true; + break; + } + i = i + 1; + }); + + integer ret = i; + + if (!found) + { + ret = nil; + } + y2milestone("Joystick index with parent id %1: %2", parent_id, ret); + + return ret; + } + + integer find_free_number() + { + integer i = 0; + boolean found = false; + + foreach(map j, (list<map>)Joystick::joystick, { + if (j["JOYSTICK_MODULE"]:"" == "") + { + found = true; + break; + } + i = i + 1; + }); + + integer ret = i; + + if (!found) + { + ret = nil; + } + y2milestone("Unconfigured joystick at index: %1", ret); + + return ret; + } + + define void restart_joystick(integer num) + { + // restart joystick service to reload the driver + Joystick::Stop(); + Joystick::SaveOneJoystick(num); + Joystick::WriteConfig(); + Joystick::StartAndEnable(); + + // re-detect attached joysticks + Joystick::Detect(); + } + + define void refresh_table() + { + list<map<string,any> > items = joystick_table(); + WizardHW::SetContents(items); + } + + list<map> sound_cards_with_joystick() + { + list<map> sound_cards = (list<map>)SCR::Read(.probe.sound); + + sound_cards = filter(map sound_card, sound_cards, { + string driver = get_module(sound_card)["name"]:""; + + if (driver == nil || driver == "") + { + driver = String::Replace(sound_card["driver_module"]:"", "_", "-"); + } + + return Sound::db_modules[driver, "joystick"]:$[] != $[]; + }); + + return sound_cards; + } + define symbol joystick_overview() { list<list> extra_buttons = [ @@ -857,11 +964,14 @@ y2milestone("WaitForEvent: %1", ev); ret = (symbol)ev["event","ID"]:nil; + + if (ret == `cancel) ret = `abort; + string device = WizardHW::SelectedItem(); if (ret == `add) { - list jcards = Sound::GetSoundCardListWithJoy(); + list<map> jcards = sound_cards_with_joystick(); y2milestone("Sound cards with gameport: %1", jcards); // no sound card with gameport @@ -888,12 +998,17 @@ else { // if there is just one card just use it otherwise ask user - integer selected = (size(unconfigured) == 1) ? unconfigured[0, "card_no"]:0 : select_sound_card(unconfigured); + map card = (size(unconfigured) == 1) ? unconfigured[0]:$[] : select_sound_card(unconfigured); + integer joy_index = find_free_number(); // selection canceled? - if (selected != nil) + if (card != nil) { - joy_dialog(selected, `ok); + joy_dialog(joy_index, `ok, card); + + restart_joystick(joy_index); + + refresh_table(); } } } @@ -907,6 +1022,21 @@ } else { + string uid = find_joystick(device)["parent_unique_key"]:""; + integer num = find_joystick_number(uid); + list<map> soundcards = (list<map>)SCR::Read(.probe.sound); + map card = find(map c, soundcards, {return c["unique_key"]:"" == uid;}); + + symbol ui = joy_dialog(num, `ok, card); + + if (ui == `next || ui == `finish) + { + // restart joystick service to reload the driver + restart_joystick(num); + + // refresh table content + refresh_table(); + } } } else if (ret == `delete) @@ -918,6 +1048,18 @@ } else { + integer num = find_joystick_number(find_joystick(device)["parent_unique_key"]:""); + y2milestone("Deleting joystick %1 (index %2)", device, num); + + // modify joystick config + Joystick::joystick[num] = $[]; + Joystick::modified = true; + + // restart joystick service to reload the driver + restart_joystick(num); + + // refresh table content + refresh_table(); } } else if (ret == `test) @@ -926,7 +1068,9 @@ } } + y2milestone("Final joystick config: %1", Joystick::joystick); y2milestone("Joystick overview result: %1", ret); + return ret; } 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=66209&r1=66208&r2=66209&view=diff ============================================================================== --- branches/tmp/lslezak/sound/sound/src/joystick.ycp (original) +++ branches/tmp/lslezak/sound/sound/src/joystick.ycp Mon Oct 3 17:51:13 2011 @@ -211,12 +211,6 @@ "detect" : $[ `next : "save", `abort : `abort, - `config : "joystick" - ], - - "joystick" : $[ - `abort : `abort, - `next : "detect" ], "save" : $[ @@ -227,7 +221,6 @@ // aliases for dialogs map aliases = $[ "detect" : ``(joystick_configuration()), - "joystick" : [ ``(joy_dialog(selected_card, label)), true ], "save" : ``(saveconfig()) ]; Modified: branches/tmp/lslezak/sound/sound/src/volume.ycp URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/sound/sound/src/volume.ycp?rev=66209&r1=66208&r2=66209&view=diff ============================================================================== --- branches/tmp/lslezak/sound/sound/src/volume.ycp (original) +++ branches/tmp/lslezak/sound/sound/src/volume.ycp Mon Oct 3 17:51:13 2011 @@ -176,7 +176,7 @@ } else if (ui == `next && Sound::conf_joystick && !Mode::config()) { - symbol ret = joy_dialog(card_id, `next); + symbol ret = nil; //FIXME: joy_dialog(card_id, `next); if (ret == `back) { con = VolumeCon(save_entry, vol); @@ -357,7 +357,7 @@ { break; } - symbol s = joy_dialog (card_id, `next); + symbol s = nil; // FIXME: joy_dialog (card_id, `next); if (s == `abort || s == `cancel) { ui = `abort; @@ -396,7 +396,7 @@ if (Sound::conf_joystick == true && Sound::use_ui) { - joy_dialog(card_id, `next); + // FIXME: joy_dialog(card_id, `next); } ui = `next; } -- 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