[gcalctool] Fix permissions on currency cache



commit 1e4f091d4ab173ab0a0297b1a0977e649819eeaa
Author: Robert Ancell <robert ancell gmail com>
Date:   Tue Oct 6 11:24:49 2009 +1100

    Fix permissions on currency cache
    Make currency UI consistent with existing financial UI
    Fix whitespace

 data/financial.ui |   25 ++++++++++++++++++++++---
 src/currency.c    |   23 ++++++++++-------------
 src/gtk.c         |   23 +++++++++++++++--------
 3 files changed, 47 insertions(+), 24 deletions(-)
---
diff --git a/data/financial.ui b/data/financial.ui
index 925b6ab..b127b25 100644
--- a/data/financial.ui
+++ b/data/financial.ui
@@ -1778,7 +1778,8 @@
     </action-widgets>
   </object>
   <object class="GtkDialog" id="currency_dialog">
-    <property name="border_width">5</property>
+    <property name="border_width">6</property>
+    <property name="title" translatable="yes">Currency Conversion</property>
     <property name="type_hint">normal</property>
     <property name="has_separator">False</property>
     <child internal-child="vbox">
@@ -1789,6 +1790,7 @@
         <child>
           <object class="GtkTable" id="table11">
             <property name="visible">True</property>
+            <property name="border_width">6</property>
             <property name="n_rows">3</property>
             <property name="n_columns">2</property>
             <property name="column_spacing">6</property>
@@ -1843,6 +1845,7 @@
                 <property name="right_attach">2</property>
                 <property name="top_attach">1</property>
                 <property name="bottom_attach">2</property>
+                <property name="y_options"></property>
               </packing>
             </child>
             <child>
@@ -1855,6 +1858,7 @@
                 <property name="right_attach">2</property>
                 <property name="top_attach">2</property>
                 <property name="bottom_attach">3</property>
+                <property name="y_options"></property>
               </packing>
             </child>
           </object>
@@ -1867,8 +1871,8 @@
             <property name="visible">True</property>
             <property name="layout_style">end</property>
             <child>
-              <object class="GtkButton" id="button21">
-                <property name="label">gtk-ok</property>
+              <object class="GtkButton" id="button22">
+                <property name="label">gtk-cancel</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
@@ -1880,6 +1884,20 @@
                 <property name="position">0</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkButton" id="button21">
+                <property name="label">C_alculate</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
           </object>
           <packing>
             <property name="expand">False</property>
@@ -1890,6 +1908,7 @@
       </object>
     </child>
     <action-widgets>
+      <action-widget response="-6">button22</action-widget>
       <action-widget response="-5">button21</action-widget>
     </action-widgets>
   </object>
diff --git a/src/currency.c b/src/currency.c
index 01bace5..7bc3eda 100644
--- a/src/currency.c
+++ b/src/currency.c
@@ -77,16 +77,15 @@ currency_download_rates()
     gchar *filename, *directory;
     GError *e = NULL;
     SoupSession *session = soup_session_sync_new();
-    SoupMessage *msg = soup_message_new(
-        "GET",
-        "http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml";);
+    SoupMessage *msg = soup_message_new("GET",
+                                        "http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml";);
     soup_session_send_message(session, msg);
     if (msg->status_code != 200) {
         return 0;
     }
     filename = get_rate_filepath();
     directory = g_path_get_dirname(filename);
-    g_mkdir_with_parents(directory, 755);
+    g_mkdir_with_parents(directory, 0755);
     g_free(directory);
 
     g_file_set_contents(filename,
@@ -143,13 +142,11 @@ void currency_load_rates()
         return;
     }
 
-    xmlXPathRegisterNs(
-        xpath_ctx,
-        BAD_CAST("xref"),
-        BAD_CAST("http://www.ecb.int/vocabulary/2002-08-01/eurofxref";));
-    xpath_obj = xmlXPathEvalExpression(
-        BAD_CAST("//xref:Cube[ currency][@rate]"),
-        xpath_ctx);
+    xmlXPathRegisterNs(xpath_ctx,
+                       BAD_CAST("xref"),
+                       BAD_CAST("http://www.ecb.int/vocabulary/2002-08-01/eurofxref";));
+    xpath_obj = xmlXPathEvalExpression(BAD_CAST("//xref:Cube[ currency][@rate]"),
+                                       xpath_ctx);
 
     if (xpath_obj == NULL) {
         xmlXPathFreeContext(xpath_ctx);
@@ -166,7 +163,7 @@ void currency_load_rates()
             set_rate(xpath_obj->nodesetval->nodeTab[i], &currencies[i]);
         }
 
-       // Avoid accessing removed elements
+        // Avoid accessing removed elements
         if (xpath_obj->nodesetval->nodeTab[i]->type != XML_NAMESPACE_DECL)
             xpath_obj->nodesetval->nodeTab[i] = NULL;
     }
@@ -202,6 +199,7 @@ void
 currency_free_resources()
 {
     int i;
+
     for (i = 0; i < currency_count; i++) {
         if (currencies[i].short_name != NULL)
             xmlFree(currencies[i].short_name);
@@ -209,5 +207,4 @@ currency_free_resources()
     g_slice_free1(currency_count * sizeof(currency), currencies);
     currencies = NULL;
     currency_count = 0;
-
 }
diff --git a/src/gtk.c b/src/gtk.c
index 7b638bd..71779ee 100644
--- a/src/gtk.c
+++ b/src/gtk.c
@@ -757,8 +757,8 @@ setup_finc_dialogs(void)
         "currency_type_lower"));
 
     currency_store = gtk_list_store_new(2,
-                                                      G_TYPE_INT,
-                                                      G_TYPE_STRING);
+                                        G_TYPE_INT,
+                                        G_TYPE_STRING);
 
     gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(currency_store),
                                          1,
@@ -928,6 +928,7 @@ static void
 recalculate_currency(CurrencyTargetRow target)
 {
     int upper_index, lower_index;
+
     GtkComboBox *combo_upper = GTK_COMBO_BOX(gtk_builder_get_object(
         X.financial,
         "currency_type_upper"));
@@ -989,6 +990,7 @@ setup_currency_rates ()
     int i;
     GtkListStore *currency_store;
     GObject *currency_type;
+
     if (has_run)
         return;
 
@@ -1041,6 +1043,7 @@ currency_cb(GtkWidget *widget, GdkEventButton *event)
     GtkDialog *win;
     GtkSpinButton *c_amount_upper, *c_amount_lower;
     MPNumber display_val;
+
     if (X.financial == NULL)
         setup_finc_dialogs();
 
@@ -1058,14 +1061,18 @@ currency_cb(GtkWidget *widget, GdkEventButton *event)
         gtk_spin_button_set_value(c_amount_upper, start_val);
     }
     gtk_widget_grab_focus(GTK_WIDGET(c_amount_upper));
-    gtk_dialog_run(win);
 
-    char* result = g_strdup_printf("%.2f",
-                                   gtk_spin_button_get_value(c_amount_lower));
-    mp_set_from_string(result, &display_val);
-    g_free(result);
+    if (gtk_dialog_run(win) == GTK_RESPONSE_OK) {
+        gchar *result;
+        
+        result = g_strdup_printf("%.2f",
+                                 gtk_spin_button_get_value(c_amount_lower));
+        mp_set_from_string(result, &display_val);
+        g_free(result);
+
+        display_set_number(&v->display, &display_val);
+    }
 
-    display_set_number(&v->display, &display_val);
     gtk_widget_hide(GTK_WIDGET(win));
 }
 



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