1 /* 2 * Copyright 2004-2006, the Haiku project. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors in chronological order: 6 * mccall@digitalparadise.co.uk 7 * Jérôme Duval 8 * Marcus Overhagen 9 */ 10 11 12 #include "KeyboardSettings.h" 13 14 #include <FindDirectory.h> 15 #include <File.h> 16 #include <Path.h> 17 #include <stdio.h> 18 19 20 KeyboardSettings::KeyboardSettings() 21 { 22 if (get_key_repeat_rate(&fSettings.key_repeat_rate) != B_OK) 23 fSettings.key_repeat_rate = kb_default_key_repeat_rate; 24 25 if (get_key_repeat_delay(&fSettings.key_repeat_delay) != B_OK) 26 fSettings.key_repeat_delay = kb_default_key_repeat_delay; 27 28 fOriginalSettings = fSettings; 29 30 BPath path; 31 BFile file; 32 33 status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path); 34 if (status == B_OK) { 35 status = path.Append(kb_settings_file); 36 if (status == B_OK) { 37 status = file.SetTo(path.Path(), B_READ_ONLY); 38 } 39 } 40 } 41 42 43 KeyboardSettings::~KeyboardSettings() 44 { 45 BPath path; 46 BFile file; 47 48 if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) < B_OK) 49 return; 50 51 if (path.Append(kb_settings_file) < B_OK) 52 return; 53 54 // be careful: don't create the file if it doesn't already exist 55 if (file.SetTo(path.Path(), B_WRITE_ONLY) < B_OK) 56 return; 57 } 58 59 void 60 KeyboardSettings::SetKeyboardRepeatRate(int32 rate) 61 { 62 if (set_key_repeat_rate(rate) != B_OK) 63 fprintf(stderr, "error while set_key_repeat_rate!\n"); 64 fSettings.key_repeat_rate = rate; 65 } 66 67 68 void 69 KeyboardSettings::SetKeyboardRepeatDelay(bigtime_t delay) 70 { 71 if (set_key_repeat_delay(delay) != B_OK) 72 fprintf(stderr, "error while set_key_repeat_delay!\n"); 73 fSettings.key_repeat_delay = delay; 74 } 75 76 void 77 KeyboardSettings::Revert() 78 { 79 SetKeyboardRepeatDelay(fOriginalSettings.key_repeat_delay); 80 SetKeyboardRepeatRate(fOriginalSettings.key_repeat_rate); 81 } 82 83 84 void 85 KeyboardSettings::Defaults() 86 { 87 SetKeyboardRepeatDelay(kb_default_key_repeat_delay); 88 SetKeyboardRepeatRate(kb_default_key_repeat_rate); 89 } 90 91 92 bool 93 KeyboardSettings::IsDefaultable() 94 { 95 return fSettings.key_repeat_delay != kb_default_key_repeat_delay 96 || fSettings.key_repeat_rate != kb_default_key_repeat_rate; 97 } 98