PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 1ms RepoModel.GetById 39ms app.codeStats 1ms

/src/Preferences.mm

http://firefox-mac-pdf.googlecode.com/
Objective C++ | 95 lines | 65 code | 9 blank | 21 comment | 2 complexity | 272ba0d65ccbf17a94a745bde92c7a9c MD5 | raw file
 1/*
 2 * Copyright (c) 2008 Samuel Gross.
 3 *
 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
 5 * of this software and associated documentation files (the "Software"), to deal
 6 * in the Software without restriction, including without limitation the rights
 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 8 * copies of the Software, and to permit persons to whom the Software is
 9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22#import "Preferences.h"
23
24#include "xpcom-config.h"
25#include "nsIPrefBranch.h"
26#include "nsIPrefService.h"
27#include "nsCOMPtr.h"
28#include "nsDirectoryServiceUtils.h"
29
30@implementation Preferences
31
32+ (BOOL)getBoolPreference:(const char*)key
33{
34  nsCOMPtr<nsIPrefService> prefsService;
35  prefsService = do_GetService("@mozilla.org/preferences-service;1");
36  nsCOMPtr<nsIPrefBranch> prefs;
37  prefsService->GetBranch("extensions.firefox-pdf-mac.", getter_AddRefs(prefs));
38  PRBool value = false;
39  prefs->GetBoolPref(key, &value);
40  return value;
41}
42
43+ (float)getFloatPreference:(const char*)key
44{
45  nsCOMPtr<nsIPrefService> prefsService;
46  prefsService = do_GetService("@mozilla.org/preferences-service;1");
47  nsCOMPtr<nsIPrefBranch> prefs;
48  prefsService->GetBranch("extensions.firefox-pdf-mac.", getter_AddRefs(prefs));
49  char* value = NULL;
50  prefs->GetCharPref(key, &value);
51  if (value == NULL) {
52    return 1.0;
53  }
54  return [[NSString stringWithCString:value encoding:NSASCIIStringEncoding] floatValue];
55}
56
57+ (int)getIntPreference:(const char*)key
58{
59  nsCOMPtr<nsIPrefService> prefsService;
60  prefsService = do_GetService("@mozilla.org/preferences-service;1");
61  nsCOMPtr<nsIPrefBranch> prefs;
62  prefsService->GetBranch("extensions.firefox-pdf-mac.", getter_AddRefs(prefs));
63  int value = 1;
64  prefs->GetIntPref(key, &value);
65  return value;
66}
67
68+ (void)setBoolPreference:(const char*)key value:(BOOL)value
69{
70  nsCOMPtr<nsIPrefService> prefsService;
71  prefsService = do_GetService("@mozilla.org/preferences-service;1");
72  nsCOMPtr<nsIPrefBranch> prefs;
73  prefsService->GetBranch("extensions.firefox-pdf-mac.", getter_AddRefs(prefs));
74  prefs->SetBoolPref(key, value);
75}
76
77+ (void)setFloatPreference:(const char*)key value:(float)value
78{
79  nsCOMPtr<nsIPrefService> prefsService;
80  prefsService = do_GetService("@mozilla.org/preferences-service;1");
81  nsCOMPtr<nsIPrefBranch> prefs;
82  prefsService->GetBranch("extensions.firefox-pdf-mac.", getter_AddRefs(prefs));
83  prefs->SetCharPref(key, [[NSString stringWithFormat:@"%f", value] cStringUsingEncoding:NSASCIIStringEncoding]);
84}
85
86+ (void)setIntPreference:(const char*)key value:(int)value
87{
88  nsCOMPtr<nsIPrefService> prefsService;
89  prefsService = do_GetService("@mozilla.org/preferences-service;1");
90  nsCOMPtr<nsIPrefBranch> prefs;
91  prefsService->GetBranch("extensions.firefox-pdf-mac.", getter_AddRefs(prefs));
92  prefs->SetIntPref(key, value);
93}
94
95@end