示例#1
0
bool resource_add_name_to_deleted_ones_if_standard_template(const ustring & filename)
/*
 If the filename given is a standard template, it adds the name of the resource
 to the list of deleted ones and then returns true.
 */
{
  ustring directory = gw_path_get_dirname(filename);
  if (directory == Directories->get_package_data()) {
    ustring deleted_filename = gw_build_filename(Directories->get_resources(), "deleted");
    ReadText rt(deleted_filename, true, true);
    ustring title = resource_get_title(filename);
    rt.lines.push_back(title);
    write_lines(deleted_filename, rt.lines);
    return true;
  }
  return false;
}
示例#2
0
ustring resource_url_get(const ustring& url, const ustring& templatefile)
/*
 Some urls are given as full ones, e.g. http://bibledit.org.
 These don't need any modification.
 Other urls are given as plain filenames only. It is assumed for these that 
 they are given relative to the resource directory where these reside. 
 These need to be modified so as to include the full path and the file:// prefix.
 */
{
  ustring modified_url(url);
  if (url.find ("http") != 0) {
    ustring path = gw_path_get_dirname(templatefile);
    modified_url = resource_file_prefix();
    modified_url.append(gw_build_filename(path, url));
  }
  return modified_url;
}
示例#3
0
// Constructor
directories::directories(char *argv0)
{
  char *dirname = (char *)g_path_get_dirname (argv0);
  rundir = dirname;
  free(dirname);
  char *basename = (char *)g_path_get_basename (argv0);
  exename = basename;
  free(basename);

  // Instead of re-computing the directory every time
  // get_package_data() is called, we compute it once and store it,
  // making repeated calls more efficient by simply returning the
  // answer we have pre-computed.
#ifdef WIN32
  // A clever way to take a path like C:\Program
  // Files\Bibledit-Gtk\editor\bin\ and chop the
  // last component to get back to <something>\Bibledit-Gtk\editor...
  package_data = gw_path_get_dirname(rundir);
  // ... Then add two more dirs back on, resulting in
  // <something>Bibledit-Gtk\editor\share\bibledit
  package_data = gw_build_filename(package_data, "share", "bibledit");
#else
  // For Linux, this is hard-coded to match the variable set in config.h
  package_data = PACKAGE_DATA_DIR;
#endif
  package_data = fix_slashes(package_data);

  // The root directory of all data.
  root = tiny_directories_get_root();
  root = fix_slashes(root);

  // Directory containing all the projects
  projects = tiny_directories_get_projects();
  projects = fix_slashes(projects);

  // Directory with the notes
  notes = gw_build_filename(root, "notes");
  notes = fix_slashes(notes);

  // Directory with the stylesheets
  stylesheets = gw_build_filename(root, "stylesheets");
  stylesheets = fix_slashes(stylesheets);

  // Directory with the configuration
  configuration = gw_build_filename(root, "configuration");
  configuration = fix_slashes(configuration);

  // Directory with the pictures
  pictures = gw_build_filename(root, "pictures");
  pictures = fix_slashes(pictures);

  // Directory with the resources.
  resources = gw_build_filename(root, "resources");
  resources = fix_slashes(resources);

  // Directory with the scripts.
  scripts = gw_build_filename(root, "scripts");
  scripts = fix_slashes(scripts);

  // Temporary directory bibledit uses.
  temp = gw_build_filename(g_get_tmp_dir(), "bibledit");
  temp = fix_slashes(temp);

  // Directory with the templates
  templates = gw_build_filename(get_temp(), "templates");
  templates = fix_slashes(templates);

  // Directory with the User's custom raw templates
  templates_user = gw_build_filename(root, "templates");
  templates_user = fix_slashes(templates_user);

  // Directory, if exists, to restore from
  restore = root + ".restored";
  restore = fix_slashes(restore);
}
示例#4
0
void ImportAssistant::on_button_files ()
// Selection and processing of the files to import.
{
  // Set directory.
  ustring directory;
  if (!files_names.empty()) {
    directory = gw_path_get_dirname (files_names[0]);
  }

  // Processing variables.
  files_messages.clear();
  files_book_ids.clear();
  
  // Select files.
  {
    vector <ustring> files = gtkw_file_chooser_open_multiple (assistant, "", directory);
    if (!files.empty()) {
      files_names = files;
    }
  }

  // Ensure that there are only uncompressed files, or only one compressed file.
  vector <ustring> compressed_files;
  for (unsigned int i = 0; i < files_names.size(); i++) {
    if (compressed_archive_recognized (files_names[i]))
      compressed_files.push_back (files_names[i]);
  }
  if (!compressed_files.empty()) {
    if (compressed_files.size() > 1) {
      files_messages.push_back (_("You have selected more than one compressed file"));
    }
    if (compressed_files.size() == 1) {
      if (files_names.size() != 1) {
        files_messages.push_back (_("You have selected a mixture of normal and compressed files"));
      }
    }
  }

  // Optionally uncompress the archive and let the user select files from within it.
  if (files_messages.empty()) {
    if (compressed_files.size() == 1) {
      ustring unpack_directory = gw_build_filename (Directories->get_temp (), "uncompress");
      unix_rmdir (unpack_directory);
      uncompress (compressed_files[0], unpack_directory);
      gtkw_dialog_info (assistant, _("You will now be asked to select files from within the compressed archive"));
      files_names = gtkw_file_chooser_open_multiple (assistant, "", unpack_directory);
    }
  }

  // Check that all files are in Unicode.
  if (files_messages.empty()) {
    vector <ustring> unicode_files;
    vector <ustring> non_unicode_files;
    for (unsigned int i = 0; i < files_names.size(); i++) {
      ustring contents;
      gchar *s;
      g_file_get_contents(files_names[i].c_str(), &s, NULL, NULL);
      contents = s;
      g_free(s);
      if (contents.validate()) {
        unicode_files.push_back (files_names[i]);
      } else {
        non_unicode_files.push_back (files_names[i]);
      }
    }
    files_names = unicode_files;
    if (!non_unicode_files.empty()) {
      files_messages.push_back (_("The following files are not in the right Unicode format and are therefore not fit for import:"));
      for (unsigned int i = 0; i < non_unicode_files.size(); i++) {
        files_messages.push_back (non_unicode_files[i]);
      }
      files_messages.push_back (_("The online help provides more information about how to make these fit for use."));
    }
  }

  // Check that at least one file was selected.
  if (files_messages.empty()) {
    if (files_names.empty()) {
      files_messages.push_back (_("No files were selected"));
    }
  }

  // Specific checks for each import type. 
  if (files_messages.empty()) {
    switch (get_type ()) {
    case itBible:
      {
        switch (get_bible_type()) {
        case ibtUsfm:
          {
            import_check_usfm_files (files_names, files_book_ids, bible_name, files_messages);
            break;
          }
        case ibtBibleWorks:
          {
            import_check_bibleworks_file (files_names, files_book_ids, bible_name, files_messages);
            break;
          }
        case ibtOnlineBible:
          {
            break;
          }
        case ibtRawText:
          {
            break;
          }
        }
        break;
      }
    case itReferences:
      {
        break;
      }
    case itStylesheet:
      {
        break;
      }
    case itNotes:
      {
        break;
      }
    case itKeyterms:
      {
        break;
      }
    }
  }

  // Gui update.
  on_assistant_prepare (vbox_files);
}