[gcalctool] Tidied up GConf schema, use native GConf types (Robert Ancell, Bug #493946)



commit 27e717d6e28d12e75463bb6f0e6d2d35f6ebddd4
Author: Robert Ancell <robert ancell gmail com>
Date:   Mon May 4 10:53:00 2009 +1000

    Tidied up GConf schema, use native GConf types (Robert Ancell, Bug #493946)
---
 ChangeLog                 |    3 +-
 data/gcalctool.schemas.in |   79 +++++++++++++++++++++-----------------------
 gcalctool/get.c           |   81 ++++++++++++++++++++-------------------------
 gcalctool/get.h           |    2 +-
 4 files changed, 77 insertions(+), 88 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 25480c8..d41d3b3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,7 +10,8 @@ gcalctool change history.
 2009-05-04 Robert Ancell <robert ancell gmail com>
 
     * Make GConf schemas translatable (Robert Ancell, Bug #571948)
-    * Tidy up error messages (Robert Ancell, Bug #521184)
+    * Tidied up error messages (Robert Ancell, Bug #521184)
+    * Tidied up GConf schema, use native GConf types (Robert Ancell, Bug #493946)
 
 2009-04-20 Robert Ancell <robert ancell gmail com>
 
diff --git a/data/gcalctool.schemas.in b/data/gcalctool.schemas.in
index b1975ae..e1c8d9e 100644
--- a/data/gcalctool.schemas.in
+++ b/data/gcalctool.schemas.in
@@ -18,7 +18,7 @@ To change the gconftool target use the - -config-source=blah option to gconftool
       <applyto>/apps/gcalctool/accuracy</applyto>
       <key>/schemas/apps/gcalctool/accuracy</key>
       <owner>gcalctool</owner>
-      <type>string</type>
+      <type>int</type>
       <default>9</default>
       <locale name="C">
         <short>Accuracy value</short>
@@ -82,8 +82,8 @@ To change the gconftool target use the - -config-source=blah option to gconftool
       <applyto>/apps/gcalctool/showzeroes</applyto>
       <key>/schemas/apps/gcalctool/showzeroes</key>
       <owner>gcalctool</owner>
-      <type>string</type>
-      <default>false</default>
+      <type>bool</type>
+      <default>FALSE</default>
       <locale name="C">
         <short>Show Trailing Zeroes</short>
         <long>
@@ -92,44 +92,30 @@ To change the gconftool target use the - -config-source=blah option to gconftool
         </long>
       </locale>
     </schema>
-    <schema> 
-      <applyto>/apps/gcalctool/showhelp</applyto> 
-      <key>/schemas/apps/gcalctool/showhelp</key> 
-      <owner>gcalctool</owner> 
-      <type>string</type>
-      <default>false</default> 
-      <locale name="C">  
-        <short>Show Help</short> 
-        <long>  
-          Indicates whether tooltip help should be enabled.
-        </long> 
-      </locale> 
-    </schema>
     <schema>
-      <applyto>/apps/gcalctool/showregisters</applyto>
-      <key>/schemas/apps/gcalctool/showregisters</key>
+      <applyto>/apps/gcalctool/showthousands</applyto>
+      <key>/schemas/apps/gcalctool/showthousands</key>
       <owner>gcalctool</owner>
-      <type>string</type>
-      <default>false</default>
+      <type>bool</type>
+      <default>FALSE</default>
       <locale name="C">
-        <short>Show Registers</short>
+        <short>Show Thousands Separator</short>
         <long>
-          Indicates whether the memory register window is 
-          initially displayed.
+          Indicates whether thousands separators are shown in large numbers.
         </long>
       </locale>
     </schema>
     <schema>
-      <applyto>/apps/gcalctool/righthanded</applyto>
-      <key>/schemas/apps/gcalctool/righthanded</key>
+      <applyto>/apps/gcalctool/showregisters</applyto>
+      <key>/schemas/apps/gcalctool/showregisters</key>
       <owner>gcalctool</owner>
-      <type>string</type>
-      <default>true</default>
+      <type>bool</type>
+      <default>FALSE</default>
       <locale name="C">
-        <short>Right Handed</short>
+        <short>Show Registers</short>
         <long>
-          Indicates whether the calculator is started with a
-          "right-handed" display style.
+          Indicates whether the memory register window is 
+          initially displayed.
         </long>
       </locale>
     </schema>
@@ -149,18 +135,29 @@ To change the gconftool target use the - -config-source=blah option to gconftool
         </long>
       </locale>
     </schema>
-    <schema>
-      <applyto>/apps/gcalctool/beep</applyto>
-      <key>/schemas/apps/gcalctool/beep</key>
-      <owner>gcalctool</owner>
-      <type>string</type>
-      <default>true</default>
-      <locale name="C">
-        <short>Beep</short>
+    <schema> 
+      <applyto>/apps/gcalctool/xposition</applyto>
+      <key>/schemas/apps/gcalctool/xposition</key> 
+      <owner>gcalctool</owner> 
+      <type>int</type>
+      <default>-1</default> 
+      <locale name="C"> 
+        <short>The initial x-coordinate for the window</short>
+        <long>
+          The number of pixels to place the window from the left of the screen.
+        </long>
+      </locale>
+    </schema>
+    <schema> 
+      <applyto>/apps/gcalctool/yposition</applyto>
+      <key>/schemas/apps/gcalctool/yposition</key> 
+      <owner>gcalctool</owner> 
+      <type>int</type>
+      <default>-1</default> 
+      <locale name="C"> 
+        <short>The initial y-coordinate for the window</short>
         <long>
-          Indicates whether a beep should sound in the
-          event of an error (such as invalid input, or
-          if the display needs to be cleared).
+          The number of pixels to place the window from the top of the screen.
         </long>
       </locale>
     </schema>
diff --git a/gcalctool/get.c b/gcalctool/get.c
index 4097ac2..5842703 100644
--- a/gcalctool/get.c
+++ b/gcalctool/get.c
@@ -51,7 +51,7 @@ get_resource(const char *key)
 {
     char key_name[MAXLINE];
     SNPRINTF(key_name, MAXLINE, "/apps/gcalctool/%s", key);
-    return(gconf_client_get_string(client, key_name, NULL));
+    return gconf_client_get_string(client, key_name, NULL);
 }
 
 
@@ -67,20 +67,18 @@ set_resource(const char *key, const char *value)
 void
 set_int_resource(const char *key, int value)
 {
-    char intvalue[MAXLINE];
-    SNPRINTF(intvalue, MAXLINE, "%d", value);
-    set_resource(key, intvalue);
+    char key_name[MAXLINE];
+    SNPRINTF(key_name, MAXLINE, "/apps/gcalctool/%s", key);    
+    gconf_client_set_int(client, key_name, value, NULL);
 }
 
 
 void
 set_boolean_resource(const char *key, int value)
 {
-    if (value) {
-        set_resource(key, "true");
-    } else {
-        set_resource(key, "false");
-    }
+    char key_name[MAXLINE];
+    SNPRINTF(key_name, MAXLINE, "/apps/gcalctool/%s", key);    
+    gconf_client_set_bool(client, key_name, value, NULL);
 }
 
 
@@ -93,42 +91,34 @@ void set_enumerated_resource(const char *key, const char *values[], int value)
 int
 get_int_resource(const char *key, int *intval)
 {
-    char *val;
- 
-    val = get_resource(key);
-    if (!val)
-        return(FALSE);
-    *intval = atoi(val);
+    char key_name[MAXLINE];
+    GError *error = NULL;
+    gint v;
 
-    g_free(val);
-    return(TRUE);
+    SNPRINTF(key_name, MAXLINE, "/apps/gcalctool/%s", key);
+    v = gconf_client_get_int(client, key_name, &error);
+    if (error)
+        return FALSE;
+    *intval = v;
+    
+    return TRUE;
 }
 
 
 int
 get_boolean_resource(const char *key, int *boolval)
 {
-    char *val, tempstr[MAXLINE];
-    int len, n;
-
-    val = get_resource(key);
-    if (!val)
-        return(FALSE);
-    STRNCPY(tempstr, val, MAXLINE - 1);
-    g_free(val);
-    len = strlen(tempstr);
-    for (n = 0; n < len; n++) {
-        if (isupper((int) tempstr[n])) {
-            tempstr[n] = tolower((int) tempstr[n]);
-        }
-    }
-    if (EQUAL(tempstr, "true")) {
-        *boolval = TRUE;
-    } else {
-        *boolval = FALSE;
-    }
-
-    return(TRUE);
+    char key_name[MAXLINE];
+    GError *error = NULL;
+    gboolean v;
+    
+    SNPRINTF(key_name, MAXLINE, "/apps/gcalctool/%s", key);
+    v = gconf_client_get_bool(client, key_name, &error);
+    if (error)
+        return FALSE;
+    *boolval = v;
+    
+    return TRUE;
 }
 
 
@@ -136,26 +126,28 @@ int
 get_enumerated_resource(const char *key, const char *values[], int *value)
 {
     char *val;
-    int i;
+    int i, retval = FALSE;
 
     val = get_resource(key);
     if (!val)
-       return(FALSE);
+       return FALSE;
    
-    for (i = 0; values[i]; i++)
+    for (i = 0; values[i]; i++) {
        if (strcmp(values[i], val) == 0) {
            *value = i;
-           return(TRUE);
+           retval = TRUE;
+           break;
        }
+    }
+    free(val);
  
-   return(FALSE);
+    return retval;
 }
 
 
 /* Return the radix character. For most locales, this is a period. 
  * If nl_langinfo(RADIXCHAR) returns an empty string, return ",".
  */
-
 const char *
 get_radix()
 {
@@ -177,7 +169,6 @@ get_radix()
 /* Return the thousands separator string. For most locales, this is a 
  * comma. 
  */
-
 const char *
 get_tsep()
 {
diff --git a/gcalctool/get.h b/gcalctool/get.h
index b7c5566..d1adc0b 100644
--- a/gcalctool/get.h
+++ b/gcalctool/get.h
@@ -27,7 +27,7 @@
 #define R_ACCURACY "accuracy"
 #define R_BASE     "base"
 #define R_DISPLAY  "display"
-#define R_MODE     "modetype"
+#define R_MODE     "mode"
 #define R_REGS     "showregisters"
 #define R_TRIG     "trigtype"
 #define R_ZEROES   "showzeroes"



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]