void MainMenuState::updateSettingsFromKeysButtons() { for(int i = 0; i < 4; i++) { KeySettings::PlayerKeys& playerKeys = m_settingsManager.getKeySettings().getPlayerKeys(i); playerKeys.leftKey = stringToKey(std::string(m_playersKeys[i][0])); playerKeys.rightKey = stringToKey(std::string(m_playersKeys[i][1])); playerKeys.jumpKey = stringToKey(std::string(m_playersKeys[i][2])); } }
void KAccel::readSettings(KConfig* config) { QString s; KConfig *pConfig = config?config:kapp->getConfig(); pConfig->setGroup( aGroup.data() ); QDictIterator<KKeyEntry> aKeyIt( aKeyDict ); aKeyIt.toFirst(); #define pE aKeyIt.current() while ( pE ) { s = pConfig->readEntry( aKeyIt.currentKey() ); if ( s.isNull() ) pE->aConfigKeyCode = pE->aDefaultKeyCode; else pE->aConfigKeyCode = stringToKey( s.data() ); pE->aCurrentKeyCode = pE->aConfigKeyCode; if ( pE->aAccelId && pE->aCurrentKeyCode ) { pAccel->disconnectItem( pE->aAccelId, pE->receiver, pE->member ); pAccel->removeItem( pE->aAccelId ); pAccel->insertItem( pE->aCurrentKeyCode, pE->aAccelId ); pAccel->connectItem( pE->aAccelId, pE->receiver, pE->member); } ++aKeyIt; } #undef pE }
bool InputManager::processKeyState(LSHandle* handle, LSMessage* msg, void* userData) { // {"get": string} VALIDATE_SCHEMA_AND_RETURN(handle, msg, SCHEMA_1(REQUIRED(get, string))); bool success = false; const char* keyString = NULL; QEvent::Type state = QEvent::None; LSError err; json_object* root = 0; LSErrorInit(&err); // get the text name of the key const char* str = LSMessageGetPayload(msg); if (!str) { g_debug("%s: Unable to get JSON payload from message", __PRETTY_FUNCTION__); return false; } root = json_tokener_parse(str); if (root && !is_error(root)) { // Get the key name from the msg -- the format will be {"get":"NAME"}, // where NAME is something like ringer, slider, etc keyString = json_object_get_string(json_object_object_get(root, "get")); if (keyString) { // lookup the state of the key Qt::Key key = stringToKey(keyString); state = getKeyState(key); success = true; } } json_object* response = 0; if (success) { response = createKeyJson(keyString, state); } else { response = json_object_new_object(); } json_object_object_add(response, "returnValue", json_object_new_boolean(success)); if (!LSMessageReply(handle, msg, json_object_to_json_string(response), &err)) { LSErrorPrint(&err, stderr); LSErrorFree(&err); } if (root && !is_error(root)) json_object_put(root); json_object_put(response); return true; }
void KKeyChooser::readGlobalKeys() { debug("KKeyChooser::readGlobalKeys()"); globalDict->clear(); // QDict<int> *tmpDict = new QDict<int> ( 37, false ); // Insert all global keys into globalDict int *keyCode; KConfig *pConfig = kapp->getConfig(); KEntryIterator *gIt = pConfig->entryIterator( "Global Keys" ); gIt->toFirst(); while ( gIt->current() ) { keyCode = new int; *keyCode = stringToKey( gIt->current()->aValue ); globalDict->insert( gIt->currentKey(), keyCode); //debug( " %s, %d", gIt->currentKey(), *keyCode ); ++(*gIt); } // Only insert global keys which don't appear in the dictionary to be configured aIt->toFirst(); while ( aIt->current() ) { if ( globalDict->find( aIt->currentKey() ) ) { // Tried removing but it didn't work. Hence set them to zero // instead keyCode = new int; *keyCode = 0; if ( globalDict->remove( aIt->currentKey() ) ) debug("remove: %s", aIt->currentKey() ); //debug("%s, %d", aIt->currentKey(), *globalDict->find( //aIt->currentKey() )); } ++ ( *aIt ); } globalDict->clear(); debug("Global dict contents"); QDictIterator<int> dIt( *globalDict ); dIt.toFirst(); while ( dIt.current() ) { debug("current %s:%d", dIt.currentKey(), *dIt.current()); ++dIt; } }
bool KGlobalAccel::insertItem( const char * action, const char * keyCode, bool configurable ) { uint iKeyCode = stringToKey( keyCode ); if ( iKeyCode == 0 ) { QString str; str.sprintf( "KGlobalAccel : cannot insert item with invalid key string %s", keyCode ); warning( str ); return FALSE; } return insertItem(action, iKeyCode, configurable); }
void KGlobalAccel::readSettings() { QString s; KConfig *pConfig = kapp->getConfig(); pConfig->setGroup( aGroup.data() ); QDictIterator<KKeyEntry> aKeyIt( aKeyDict ); aKeyIt.toFirst(); #define pE aKeyIt.current() while ( pE ) { s = pConfig->readEntry( aKeyIt.currentKey() ); if ( s.isNull() ) pE->aConfigKeyCode = pE->aDefaultKeyCode; else pE->aConfigKeyCode = stringToKey( s.data() ); if ( pE->bEnabled ) { uint keysym = keyToXSym( pE->aCurrentKeyCode ); uint mod = keyToXMod( pE->aCurrentKeyCode ); ungrabKey( keysym, mod ); } pE->aCurrentKeyCode = pE->aConfigKeyCode; if ( pE->bEnabled ) { uint keysym = keyToXSym( pE->aCurrentKeyCode ); uint mod = keyToXMod( pE->aCurrentKeyCode ); grabKey( keysym, mod ); } ++aKeyIt; } #undef pE }
void BindingsConfiguration::generateDefaults() { NC::Key::Type k = NC::Key::None; if (notBound(k = stringToKey("mouse"))) bind(k, Actions::Type::MouseEvent); if (notBound(k = stringToKey("up"))) bind(k, Actions::Type::ScrollUp); if (notBound(k = stringToKey("k"))) bind(k, Actions::Type::ScrollUp); if (notBound(k = stringToKey("shift-up"))) bind(k, Binding::ActionChain({ &Actions::get(Actions::Type::SelectItem), &Actions::get(Actions::Type::ScrollUp) })); if (notBound(k = stringToKey("down"))) bind(k, Actions::Type::ScrollDown); if (notBound(k = stringToKey("j"))) bind(k, Actions::Type::ScrollDown); if (notBound(k = stringToKey("shift-down"))) bind(k, Binding::ActionChain({ &Actions::get(Actions::Type::SelectItem), &Actions::get(Actions::Type::ScrollDown) })); if (notBound(k = stringToKey("["))) bind(k, Actions::Type::ScrollUpAlbum); if (notBound(k = stringToKey("]"))) bind(k, Actions::Type::ScrollDownAlbum); if (notBound(k = stringToKey("{"))) bind(k, Actions::Type::ScrollUpArtist); if (notBound(k = stringToKey("}"))) bind(k, Actions::Type::ScrollDownArtist); if (notBound(k = stringToKey("page_up"))) bind(k, Actions::Type::PageUp); if (notBound(k = stringToKey("ctrl-b"))) bind(k, Actions::Type::PageUp); if (notBound(k = stringToKey("ctrl-u"))) bind(k, Actions::Type::PageUp); if (notBound(k = stringToKey("page_down"))) bind(k, Actions::Type::PageDown); if (notBound(k = stringToKey("ctrl-f"))) bind(k, Actions::Type::PageDown); if (notBound(k = stringToKey("ctrl-d"))) bind(k, Actions::Type::PageDown); if (notBound(k = stringToKey("home"))) bind(k, Actions::Type::MoveHome); if (notBound(k = stringToKey("end"))) bind(k, Actions::Type::MoveEnd); if (notBound(k = stringToKey("insert"))) bind(k, Actions::Type::SelectItem); if (notBound(k = stringToKey("enter"))) { bind(k, Actions::Type::EnterDirectory); bind(k, Actions::Type::ToggleOutput); bind(k, Actions::Type::RunAction); bind(k, Actions::Type::PlayItem); } if (notBound(k = stringToKey("space"))) { bind(k, Actions::Type::AddItemToPlaylist); bind(k, Actions::Type::ToggleLyricsUpdateOnSongChange); bind(k, Actions::Type::ToggleVisualizationType); } if (notBound(k = stringToKey("delete"))) { bind(k, Actions::Type::DeletePlaylistItems); bind(k, Actions::Type::DeleteBrowserItems); bind(k, Actions::Type::DeleteStoredPlaylist); } if (notBound(k = stringToKey("right"))) { bind(k, Actions::Type::NextColumn); bind(k, Actions::Type::SlaveScreen); bind(k, Actions::Type::VolumeUp); } if (notBound(k = stringToKey("l"))) { bind(k, Actions::Type::NextColumn); bind(k, Actions::Type::SlaveScreen); bind(k, Actions::Type::VolumeUp); } if (notBound(k = stringToKey("+"))) bind(k, Actions::Type::VolumeUp); if (notBound(k = stringToKey("left"))) { bind(k, Actions::Type::PreviousColumn); bind(k, Actions::Type::MasterScreen); bind(k, Actions::Type::VolumeDown); } if (notBound(k = stringToKey("h"))) { bind(k, Actions::Type::PreviousColumn); bind(k, Actions::Type::MasterScreen); bind(k, Actions::Type::VolumeDown); } if (notBound(k = stringToKey("-"))) bind(k, Actions::Type::VolumeDown); if (notBound(k = stringToKey(":"))) bind(k, Actions::Type::ExecuteCommand); if (notBound(k = stringToKey("tab"))) bind(k, Actions::Type::NextScreen); if (notBound(k = stringToKey("shift-tab"))) bind(k, Actions::Type::PreviousScreen); if (notBound(k = stringToKey("f1"))) bind(k, Actions::Type::ShowHelp); if (notBound(k = stringToKey("1"))) bind(k, Actions::Type::ShowPlaylist); if (notBound(k = stringToKey("2"))) { bind(k, Actions::Type::ShowBrowser); bind(k, Actions::Type::ChangeBrowseMode); } if (notBound(k = stringToKey("3"))) { bind(k, Actions::Type::ShowSearchEngine); bind(k, Actions::Type::ResetSearchEngine); } if (notBound(k = stringToKey("4"))) { bind(k, Actions::Type::ShowMediaLibrary); bind(k, Actions::Type::ToggleMediaLibraryColumnsMode); } if (notBound(k = stringToKey("5"))) bind(k, Actions::Type::ShowPlaylistEditor); if (notBound(k = stringToKey("6"))) bind(k, Actions::Type::ShowTagEditor); if (notBound(k = stringToKey("7"))) bind(k, Actions::Type::ShowOutputs); if (notBound(k = stringToKey("8"))) bind(k, Actions::Type::ShowVisualizer); if (notBound(k = stringToKey("="))) bind(k, Actions::Type::ShowClock); if (notBound(k = stringToKey("@"))) bind(k, Actions::Type::ShowServerInfo); if (notBound(k = stringToKey("s"))) bind(k, Actions::Type::Stop); if (notBound(k = stringToKey("p"))) bind(k, Actions::Type::Pause); if (notBound(k = stringToKey(">"))) bind(k, Actions::Type::Next); if (notBound(k = stringToKey("<"))) bind(k, Actions::Type::Previous); if (notBound(k = stringToKey("ctrl-h"))) { bind(k, Actions::Type::JumpToParentDirectory); bind(k, Actions::Type::ReplaySong); } if (notBound(k = stringToKey("backspace"))) { bind(k, Actions::Type::JumpToParentDirectory); bind(k, Actions::Type::ReplaySong); } if (notBound(k = stringToKey("f"))) bind(k, Actions::Type::SeekForward); if (notBound(k = stringToKey("b"))) bind(k, Actions::Type::SeekBackward); if (notBound(k = stringToKey("r"))) bind(k, Actions::Type::ToggleRepeat); if (notBound(k = stringToKey("z"))) bind(k, Actions::Type::ToggleRandom); if (notBound(k = stringToKey("y"))) { bind(k, Actions::Type::SaveTagChanges); bind(k, Actions::Type::StartSearching); bind(k, Actions::Type::ToggleSingle); } if (notBound(k = stringToKey("R"))) bind(k, Actions::Type::ToggleConsume); if (notBound(k = stringToKey("Y"))) bind(k, Actions::Type::ToggleReplayGainMode); if (notBound(k = stringToKey("T"))) bind(k, Actions::Type::ToggleAddMode); if (notBound(k = stringToKey("|"))) bind(k, Actions::Type::ToggleMouse); if (notBound(k = stringToKey("#"))) bind(k, Actions::Type::ToggleBitrateVisibility); if (notBound(k = stringToKey("Z"))) bind(k, Actions::Type::Shuffle); if (notBound(k = stringToKey("x"))) bind(k, Actions::Type::ToggleCrossfade); if (notBound(k = stringToKey("X"))) bind(k, Actions::Type::SetCrossfade); if (notBound(k = stringToKey("u"))) bind(k, Actions::Type::UpdateDatabase); if (notBound(k = stringToKey("ctrl-s"))) { bind(k, Actions::Type::SortPlaylist); bind(k, Actions::Type::ToggleBrowserSortMode); bind(k, Actions::Type::ToggleMediaLibrarySortMode); } if (notBound(k = stringToKey("ctrl-r"))) bind(k, Actions::Type::ReversePlaylist); if (notBound(k = stringToKey("ctrl-f"))) bind(k, Actions::Type::ApplyFilter); if (notBound(k = stringToKey("ctrl-_"))) bind(k, Actions::Type::SelectFoundItems); if (notBound(k = stringToKey("/"))) { bind(k, Actions::Type::Find); bind(k, Actions::Type::FindItemForward); } if (notBound(k = stringToKey("?"))) { bind(k, Actions::Type::Find); bind(k, Actions::Type::FindItemBackward); } if (notBound(k = stringToKey("."))) bind(k, Actions::Type::NextFoundItem); if (notBound(k = stringToKey(","))) bind(k, Actions::Type::PreviousFoundItem); if (notBound(k = stringToKey("w"))) bind(k, Actions::Type::ToggleFindMode); if (notBound(k = stringToKey("e"))) { bind(k, Actions::Type::EditSong); bind(k, Actions::Type::EditLibraryTag); bind(k, Actions::Type::EditLibraryAlbum); bind(k, Actions::Type::EditDirectoryName); bind(k, Actions::Type::EditPlaylistName); bind(k, Actions::Type::EditLyrics); } if (notBound(k = stringToKey("i"))) bind(k, Actions::Type::ShowSongInfo); if (notBound(k = stringToKey("I"))) bind(k, Actions::Type::ShowArtistInfo); if (notBound(k = stringToKey("g"))) bind(k, Actions::Type::JumpToPositionInSong); if (notBound(k = stringToKey("L"))) bind(k, Actions::Type::ShowLyrics); if (notBound(k = stringToKey("ctrl-v"))) bind(k, Actions::Type::SelectRange); if (notBound(k = stringToKey("v"))) bind(k, Actions::Type::ReverseSelection); if (notBound(k = stringToKey("V"))) bind(k, Actions::Type::RemoveSelection); if (notBound(k = stringToKey("B"))) bind(k, Actions::Type::SelectAlbum); if (notBound(k = stringToKey("a"))) bind(k, Actions::Type::AddSelectedItems); if (notBound(k = stringToKey("c"))) { bind(k, Actions::Type::ClearPlaylist); bind(k, Actions::Type::ClearMainPlaylist); } if (notBound(k = stringToKey("C"))) { bind(k, Actions::Type::CropPlaylist); bind(k, Actions::Type::CropMainPlaylist); } if (notBound(k = stringToKey("m"))) { bind(k, Actions::Type::MoveSortOrderUp); bind(k, Actions::Type::MoveSelectedItemsUp); bind(k, Actions::Type::SetVisualizerSampleMultiplier); } if (notBound(k = stringToKey("n"))) { bind(k, Actions::Type::MoveSortOrderDown); bind(k, Actions::Type::MoveSelectedItemsDown); } if (notBound(k = stringToKey("M"))) bind(k, Actions::Type::MoveSelectedItemsTo); if (notBound(k = stringToKey("A"))) bind(k, Actions::Type::Add); if (notBound(k = stringToKey("S"))) bind(k, Actions::Type::SavePlaylist); if (notBound(k = stringToKey("o"))) bind(k, Actions::Type::JumpToPlayingSong); if (notBound(k = stringToKey("G"))) { bind(k, Actions::Type::JumpToBrowser); bind(k, Actions::Type::JumpToPlaylistEditor); } if (notBound(k = stringToKey("~"))) bind(k, Actions::Type::JumpToMediaLibrary); if (notBound(k = stringToKey("E"))) bind(k, Actions::Type::JumpToTagEditor); if (notBound(k = stringToKey("U"))) bind(k, Actions::Type::TogglePlayingSongCentering); if (notBound(k = stringToKey("P"))) bind(k, Actions::Type::ToggleDisplayMode); if (notBound(k = stringToKey("\\"))) bind(k, Actions::Type::ToggleInterface); if (notBound(k = stringToKey("!"))) bind(k, Actions::Type::ToggleSeparatorsBetweenAlbums); if (notBound(k = stringToKey("ctrl-L"))) bind(k, Actions::Type::ToggleLyricsFetcher); if (notBound(k = stringToKey("F"))) bind(k, Actions::Type::ToggleFetchingLyricsInBackground); if (notBound(k = stringToKey("ctrl-l"))) bind(k, Actions::Type::ToggleScreenLock); if (notBound(k = stringToKey("`"))) { bind(k, Actions::Type::ToggleLibraryTagType); bind(k, Actions::Type::RefetchLyrics); bind(k, Actions::Type::AddRandomItems); } if (notBound(k = stringToKey("ctrl-p"))) bind(k, Actions::Type::SetSelectedItemsPriority); if (notBound(k = stringToKey("q"))) bind(k, Actions::Type::Quit); if (notBound(k = stringToKey("-"))) bind(k, Actions::Type::VolumeDown); }
bool BindingsConfiguration::read(const std::string &file) { enum class InProgress { None, Command, Key }; bool result = true; std::ifstream f(file); if (!f.is_open()) return result; // shared variables InProgress in_progress = InProgress::None; size_t line_no = 0; std::string line; Binding::ActionChain actions; // def_key specific variables NC::Key::Type key = NC::Key::None; std::string strkey; // def_command specific variables bool cmd_immediate = false; std::string cmd_name; auto error = [&]() -> std::ostream & { std::cerr << file << ":" << line_no << ": error: "; in_progress = InProgress::None; result = false; return std::cerr; }; auto bind_in_progress = [&]() -> bool { if (in_progress == InProgress::Command) { if (!actions.empty()) { m_commands.insert(std::make_pair(cmd_name, Command(std::move(actions), cmd_immediate))); actions.clear(); return true; } else { error() << "definition of command '" << cmd_name << "' cannot be empty\n"; return false; } } else if (in_progress == InProgress::Key) { if (!actions.empty()) { bind(key, actions); actions.clear(); return true; } else { error() << "definition of key '" << strkey << "' cannot be empty\n"; return false; } } return true; }; const char def_command[] = "def_command"; const char def_key[] = "def_key"; while (!f.eof() && ++line_no) { getline(f, line); if (line.empty() || line[0] == '#') continue; // beginning of command definition if (!line.compare(0, const_strlen(def_command), def_command)) { if (!bind_in_progress()) break; in_progress = InProgress::Command; cmd_name = getEnclosedString(line, '"', '"', 0); if (cmd_name.empty()) { error() << "command must have non-empty name\n"; break; } if (m_commands.find(cmd_name) != m_commands.end()) { error() << "redefinition of command '" << cmd_name << "'\n"; break; } std::string cmd_type = getEnclosedString(line, '[', ']', 0); if (cmd_type == "immediate") cmd_immediate = true; else if (cmd_type == "deferred") cmd_immediate = false; else { error() << "invalid type of command: '" << cmd_type << "'\n"; break; } } // beginning of key definition else if (!line.compare(0, const_strlen(def_key), def_key)) { if (!bind_in_progress()) break; in_progress = InProgress::Key; strkey = getEnclosedString(line, '"', '"', 0); key = stringToKey(strkey); if (key == NC::Key::None) { error() << "invalid key: '" << strkey << "'\n"; break; } } else if (isspace(line[0])) // name of action to be bound { boost::trim(line); auto action = parseActionLine(line, error); if (action) actions.push_back(action); else { error() << "unknown action: '" << line << "'\n"; break; } } else { error() << "invalid line: '" << line << "'\n"; break; } } bind_in_progress(); f.close(); return result; }
bool KAccel::insertItem( const char* descr, const char * action, const char * keyCode, bool configurable ) { uint iKeyCode = stringToKey( keyCode ); return insertItem( descr, action, iKeyCode, configurable ); }