Beispiel #1
0
int AH_ImExporterOFX_Import(AB_IMEXPORTER *ie,
                            AB_IMEXPORTER_CONTEXT *ctx,
                            GWEN_IO_LAYER *io,
                            GWEN_DB_NODE *params,
                            uint32_t guiid)
{
  AH_IMEXPORTER_OFX *ieh;
  LibofxContextPtr ofxctx;
  GWEN_BUFFER *dbuf;
  int rv;
  GWEN_STRINGLIST *paths;

  assert(ie);
  ieh=GWEN_INHERIT_GETDATA(AB_IMEXPORTER, AH_IMEXPORTER_OFX, ie);
  assert(ieh);

  ieh->context=ctx;
  ofxctx=libofx_get_new_context();

  ofx_set_account_cb(ofxctx,
                     AH_ImExporterOFX_AccountCallback_cb,
                     ieh);
  ofx_set_transaction_cb(ofxctx,
                         AH_ImExporterOFX_TransactionCallback_cb,
                         ieh);

  paths=AB_Banking_GetGlobalDataDirs();
  if (paths) {
    GWEN_BUFFER *fbuf;
    int rv;

    fbuf=GWEN_Buffer_new(0, 256, 0, 1);
    rv=GWEN_Directory_FindPathForFile(paths,
                                      "libofx"
                                      DIRSEP
                                      "dtd"
                                      DIRSEP
                                      "ofx150.dtd",
                                      fbuf);
    GWEN_StringList_free(paths);
    if (rv==0) {
      GWEN_Buffer_AppendString(fbuf,
                               DIRSEP
                               "libofx"
                               DIRSEP
                               "dtd"
                               DIRSEP);
#ifdef LIBOFX_GT_0_8_4
      DBG_INFO(AQBANKING_LOGDOMAIN,
               "Setting path for DTD files to [%s]",
               GWEN_Buffer_GetStart(fbuf));
      libofx_set_dtd_dir(ofxctx, GWEN_Buffer_GetStart(fbuf));
#else
      DBG_INFO(AQBANKING_LOGDOMAIN,
               "Cannot set path for DTD files to [%s]: libofx is 0.8.3 or older",
               GWEN_Buffer_GetStart(fbuf));
#endif
    }
    GWEN_Buffer_free(fbuf);
  }

  /* read whole stream into buffer */
  dbuf=GWEN_Buffer_new(0, 2048, 0, 1);
  GWEN_Buffer_SetStep(dbuf, 4096);
  rv=GWEN_Io_Layer_ReadToBufferUntilEof(io, dbuf, guiid, 2000);
  if (rv<0) {
    DBG_INFO(AQBANKING_LOGDOMAIN, "here (%d)", rv);
    GWEN_Buffer_free(dbuf);
    libofx_free_context(ofxctx);
    return rv;
  }

  /* setup debugging parameters */
  extern int ofx_PARSER_msg;
  extern int ofx_DEBUG_msg;
  extern int ofx_WARNING_msg;
  extern int ofx_ERROR_msg;
  extern int ofx_INFO_msg;
  extern int ofx_STATUS_msg;

  ofx_PARSER_msg=GWEN_DB_GetIntValue(params, "show_parser_msg", 0, 0);
  ofx_DEBUG_msg=GWEN_DB_GetIntValue(params, "show_debug_msg", 0, 0);
  ofx_WARNING_msg=GWEN_DB_GetIntValue(params, "show_warning_msg", 0, 1);
  ofx_ERROR_msg=GWEN_DB_GetIntValue(params, "show_error_msg", 0, 1);
  ofx_INFO_msg=GWEN_DB_GetIntValue(params, "show_info_msg", 0, 1);
  ofx_STATUS_msg=GWEN_DB_GetIntValue(params, "show_status_msg", 0, 1);

  /* now the buffer contains all the data */
  rv=libofx_proc_buffer(ofxctx,
                        GWEN_Buffer_GetStart(dbuf),
                        GWEN_Buffer_GetUsedBytes(dbuf));
  DBG_ERROR(0, "I'm back");
  GWEN_Buffer_free(dbuf);
  libofx_free_context(ofxctx);

  ieh->context=0;
  if (rv)
    return GWEN_ERROR_BAD_DATA;

  DBG_ERROR(0, "Returning");
  return 0;
}
Beispiel #2
0
void gnc_file_ofx_import (void)
{
    extern int ofx_PARSER_msg;
    extern int ofx_DEBUG_msg;
    extern int ofx_WARNING_msg;
    extern int ofx_ERROR_msg;
    extern int ofx_INFO_msg;
    extern int ofx_STATUS_msg;
    char *selected_filename;
    char *default_dir;
    LibofxContextPtr libofx_context = libofx_get_new_context();

    ofx_PARSER_msg = false;
    ofx_DEBUG_msg = false;
    ofx_WARNING_msg = true;
    ofx_ERROR_msg = true;
    ofx_INFO_msg = true;
    ofx_STATUS_msg = false;

    DEBUG("gnc_file_ofx_import(): Begin...\n");

    default_dir = gnc_get_default_directory(GNC_PREFS_GROUP);
    selected_filename = gnc_file_dialog(_("Select an OFX/QFX file to process"),
                                        NULL,
                                        default_dir,
                                        GNC_FILE_DIALOG_IMPORT);
    g_free(default_dir);

    if (selected_filename != NULL)
    {
#ifdef G_OS_WIN32
        gchar *conv_name;
#endif

        /* Remember the directory as the default. */
        default_dir = g_path_get_dirname(selected_filename);
        gnc_set_default_directory(GNC_PREFS_GROUP, default_dir);
        g_free(default_dir);

        /*strncpy(file,selected_filename, 255);*/
        DEBUG("Filename found: %s", selected_filename);

        /* Create the Generic transaction importer GUI. */
        gnc_ofx_importer_gui = gnc_gen_trans_list_new(NULL, NULL, FALSE, 42);

        /* Look up the needed preferences */
        auto_create_commodity =
            gnc_prefs_get_bool (GNC_PREFS_GROUP_IMPORT, GNC_PREF_AUTO_COMMODITY);

        /* Initialize libofx */

        /*ofx_set_statement_cb(libofx_context, ofx_proc_statement_cb, 0);*/
        ofx_set_account_cb(libofx_context, ofx_proc_account_cb, 0);
        ofx_set_transaction_cb(libofx_context, ofx_proc_transaction_cb, 0);
        ofx_set_security_cb(libofx_context, ofx_proc_security_cb, 0);
        /*ofx_set_status_cb(libofx_context, ofx_proc_status_cb, 0);*/

#ifdef G_OS_WIN32
        conv_name = g_win32_locale_filename_from_utf8(selected_filename);
        g_free(selected_filename);
        selected_filename = conv_name;
#endif

        DEBUG("Opening selected file");
        libofx_proc_file(libofx_context, selected_filename, AUTODETECT);
        g_free(selected_filename);
    }

    if (ofx_created_commodites)
    {
        /* FIXME: Present some result window about the newly created
         * commodities */
        g_warning("Created %d new commodities during import", g_list_length(ofx_created_commodites));
        g_list_free(ofx_created_commodites);
        ofx_created_commodites = NULL;
    }
    else
    {
        //g_warning("No new commodities created");
    }
}