/*************************************************************************** * import.c * * Copyright 2005 Ian McIntosh * ian_mcintosh@linuxadvocate.org ****************************************************************************/ /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include #include "main.h" #include "import.h" #include "importwindow.h" #include "import_tiger.h" #include "db.h" #ifdef USE_GNOME_VFS #include #endif #if ROADSTER_DEAD_CODE static void import_progress_pulse(void) { importwindow_progress_pulse(); } #endif /* ROADSTER_DEAD_CODE */ gboolean import_from_uri(const gchar* pszURI) { #ifdef USE_GNOME_VFS gboolean bResult = FALSE; importwindow_show(); GnomeVFSFileInfo *info = gnome_vfs_file_info_new(); if(GNOME_VFS_OK != gnome_vfs_get_file_info(pszURI, info, GNOME_VFS_FILE_INFO_DEFAULT)) { importwindow_log_append("Couldn't read %s\n", pszURI); return FALSE; } // func_progress_callback(0.0, pCallbackData); gchar* pszFileBaseName = info->name; g_return_val_if_fail(pszFileBaseName != NULL, FALSE); // does it look like a tgr file name (tgr00000.zip) ? if(strlen(pszFileBaseName) == 12 && g_str_has_prefix(pszFileBaseName, "TGR") && g_str_has_suffix(pszFileBaseName, ".ZIP")) { importwindow_log_append("Importing TIGER file %s", pszFileBaseName); // NOTE: no "\n" so we can add ... gchar buf[6]; memcpy(buf, &pszFileBaseName[3], 5); buf[5] = '\0'; gint nTigerSetNumber = atoi(buf); // just assume it's a TIGER file for now since it's all we support // db_disable_keys(); bResult = import_tiger_from_uri(pszURI, nTigerSetNumber); // db_enable_keys(); if(bResult) { importwindow_log_append("success.\n\n"); } else { importwindow_log_append("\n** Failed.\n\n"); } } // g_free(pszFileBaseName); // free file info gnome_vfs_file_info_unref(info); // func_progress_callback(1.0, pCallbackData); return bResult; #endif }