~ubuntu-dev/gnucash/ubuntu

« back to all changes in this revision

Viewing changes to src/import-export/aqbanking/gnc-ab-getbalance.c

  • Committer: Reinhard Tartler
  • Date: 2008-08-03 07:38:54 UTC
  • mfrom: (2.1.2 debian)
  • Revision ID: siretart@tauware.de-20080803073854-23i4uqi1e73no4oz
mergeĀ fromĀ debian/unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * gnc-ab-getbalance.c --
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU General Public License as
 
6
 * published by the Free Software Foundation; either version 2 of
 
7
 * the License, or (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, contact:
 
16
 *
 
17
 * Free Software Foundation           Voice:  +1-617-542-5942
 
18
 * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
 
19
 * Boston, MA  02110-1301,  USA       gnu@gnu.org
 
20
 */
 
21
 
 
22
/**
 
23
 * @internal
 
24
 * @file gnc-ab-getbalance.c
 
25
 * @brief AqBanking getbalance functions
 
26
 * @author Copyright (C) 2002 Christian Stimming <stimming@tuhh.de>
 
27
 * @author Copyright (C) 2008 Andreas Koehler <andi5.py@gmx.net>
 
28
 */
 
29
 
 
30
#include "config.h"
 
31
 
 
32
#include <glib/gi18n.h>
 
33
#include <aqbanking/banking.h>
 
34
#include <aqbanking/jobgetbalance.h>
 
35
 
 
36
#include "gnc-ab-getbalance.h"
 
37
#include "gnc-ab-kvp.h"
 
38
#include "gnc-ab-utils.h"
 
39
#include "gnc-gwen-gui.h"
 
40
#include "gnc-ui.h"
 
41
 
 
42
/* This static indicates the debugging module that this .o belongs to.  */
 
43
static QofLogModule log_module = G_LOG_DOMAIN;
 
44
 
 
45
void
 
46
gnc_ab_getbalance(GtkWidget *parent, Account *gnc_acc)
 
47
{
 
48
    AB_BANKING *api;
 
49
    gboolean online = FALSE;
 
50
    AB_ACCOUNT *ab_acc;
 
51
    AB_JOB *job = NULL;
 
52
    AB_JOB_LIST2 *job_list = NULL;
 
53
    GncGWENGui *gui = NULL;
 
54
    AB_IMEXPORTER_CONTEXT *context = NULL;
 
55
    GncABImExContextImport *ieci = NULL;
 
56
 
 
57
    g_return_if_fail(parent && gnc_acc);
 
58
 
 
59
    /* Get the API */
 
60
    api = gnc_AB_BANKING_new();
 
61
    if (!api) {
 
62
        g_warning("gnc_ab_gettrans: Couldn't get AqBanking API");
 
63
        return;
 
64
    }
 
65
    if (AB_Banking_OnlineInit(api) != 0) {
 
66
        g_warning("gnc_ab_gettrans: Couldn't initialize AqBanking API");
 
67
        goto cleanup;
 
68
    }
 
69
    online = TRUE;
 
70
 
 
71
    /* Get the AqBanking Account */
 
72
    ab_acc = gnc_ab_get_ab_account(api, gnc_acc);
 
73
    if (!ab_acc) {
 
74
        g_warning("gnc_ab_getbalance: No AqBanking account found");
 
75
        goto cleanup;
 
76
    }
 
77
 
 
78
    /* Get a GetBalance job and enqueue it */
 
79
    job = AB_JobGetBalance_new(ab_acc);
 
80
    if (!job || AB_Job_CheckAvailability(job, 0)) {
 
81
        g_warning("gnc_ab_getbalance: JobGetBalance not available for this "
 
82
                  "account");
 
83
        goto cleanup;
 
84
    }
 
85
    job_list = AB_Job_List2_new();
 
86
    AB_Job_List2_PushBack(job_list, job);
 
87
 
 
88
    /* Get a GUI object */
 
89
    gui = gnc_GWEN_Gui_get(parent);
 
90
    if (!gui) {
 
91
        g_warning("gnc_ab_getbalance: Couldn't initialize Gwenhywfar GUI");
 
92
        goto cleanup;
 
93
    }
 
94
 
 
95
    /* Create a context to store the results */
 
96
    context = AB_ImExporterContext_new();
 
97
 
 
98
    /* Execute the job */
 
99
    if (AB_Banking_ExecuteJobs(api, job_list, context, 0)) {
 
100
        g_warning("gnc_ab_getbalance: Error on executing job");
 
101
        goto cleanup;
 
102
    }
 
103
 
 
104
    /* Import the results */
 
105
    ieci = gnc_ab_import_context(context, AWAIT_BALANCES, FALSE, NULL, parent);
 
106
 
 
107
cleanup:
 
108
    if (ieci)
 
109
        g_free(ieci);
 
110
    if (context)
 
111
        AB_ImExporterContext_free(context);
 
112
    if (gui)
 
113
        gnc_GWEN_Gui_release(gui);
 
114
    if (job_list)
 
115
        AB_Job_List2_free(job_list);
 
116
    if (job)
 
117
        AB_Job_free(job);
 
118
    if (online)
 
119
        AB_Banking_OnlineFini(api);
 
120
    gnc_AB_BANKING_fini(api);
 
121
}