Пример #1
0
void latex_export_pdffile(GuLatex* lc, GuEditor* ec, const gchar* path,
                          gboolean prompt_overrite)
{
  gchar* savepath = NULL;
  GError* err = NULL;
  gint ret = 0;

  if (!STR_EQU(path + strlen(path) - 4, ".pdf"))
    savepath = g_strdup_printf("%s.pdf", path);
  else
    savepath = g_strdup(path);

  if (prompt_overrite && utils_path_exists(savepath)) {
    ret = utils_yes_no_dialog(_("The file already exists. Overwrite?"));
    if (GTK_RESPONSE_YES != ret) {
      g_free(savepath);
      return;
    }
  }
  if (!utils_copy_file(ec->pdffile, savepath, &err)) {
    slog(L_G_ERROR, _("Unable to export PDF file.\n\n%s"),
         err->message);
    g_error_free(err);
  }

  g_free(savepath);
}
Пример #2
0
void snippets_set_default (GuSnippets* sc) {
    GError* err = NULL;
    gchar* snip = g_build_filename (GUMMI_DATA, "snippets", "snippets.cfg", NULL);
    GList* current = sc->closure_data;

    /* Remove all accelerator */
    while (current) {
        gtk_accel_group_disconnect (sc->accel_group,
                TUPLE2 (current->data)->second);
        slog (L_DEBUG, "Accelerator for `%s' disconnected\n",
                TUPLE2 (current->data)->first);
        current = g_list_next (current);
    }
    g_list_free (sc->closure_data);
    sc->closure_data = NULL;

    if (!utils_copy_file (snip, sc->filename, &err)) {
        slog (L_G_ERROR, "can't open snippets file for writing, snippets may "
                "not work properly\n");
        g_error_free (err);
    } else {
        snippets_load (sc);
    }
    g_free (snip);
}
Пример #3
0
G_MODULE_EXPORT
void on_prefs_reset_clicked(GtkWidget* widget, void* user)
{
  config_set_default();
  utils_copy_file(C_DEFAULTTEXT, C_WELCOMETEXT, NULL);

  set_all_tab_settings(gui->prefsgui);
}
Пример #4
0
void iofunctions_load_default_text (gboolean loopedonce) {
    GError* readerr = NULL;
    GError* copyerr = NULL;
    gchar* text = NULL;

    GuEditor* ec = gummi_get_active_editor();

    if (!g_file_get_contents (C_WELCOMETEXT, &text, NULL, &readerr)) {
        slog (L_WARNING, "Could not find default welcome text, resetting..\n");
        utils_copy_file (C_DEFAULTTEXT, C_WELCOMETEXT, &copyerr);
        if (!loopedonce) return iofunctions_load_default_text (TRUE);
    }
    
    if (text) editor_fill_buffer (ec, text);
    
    gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (ec->buffer), FALSE);
    g_free (text);
}
Пример #5
0
G_MODULE_EXPORT
void on_menu_docstat_activate(GtkWidget *widget, void *user)
{
  gint i = 0;
  gchar* output = 0;
  gchar* cmd = 0;
  gchar** matched = NULL;
  GError* err = NULL;
  GMatchInfo* match_info;
  GRegex* regexs[TEXCOUNT_OUTPUT_LINES];
  gchar* res[TEXCOUNT_OUTPUT_LINES] = { 0 };


  /* TODO: can we deprecate this? */
  const gchar* terms[] = {
    _("Words in text"),
    _("Words in headers"),
    _("Words in float captions"),
    _("Number of headers"),
    _("Number of floats"),
    _("Number of math inlines"),
    _("Number of math displayed")
  };

  const gchar* terms_regex[] = {
    "Words in text: ([0-9]*)",
    "Words in headers: ([0-9]*)",
    "Words in float captions: ([0-9]*)",
    "Number of headers: ([0-9]*)",
    "Number of floats: ([0-9]*)",
    "Number of math inlines: ([0-9]*)",
    "Number of math displayed: ([0-9]*)"
  };


  /* TODO: move to non gui class (latex perhaps) */
  if (external_exists("texcount")) {
    /* Copy workfile to /tmp to remove any spaces in filename to avoid
     * segfaults */
    gchar* tmpfile = g_strdup_printf("%s.state", g_active_editor->fdname);
    if (!utils_copy_file(g_active_editor->workfile, tmpfile, &err)) {
      slog(L_G_ERROR, "utils_copy_file (): %s\n", err->message);
      g_free(tmpfile);
      g_error_free(err);
      goto cleanup;
    }

    cmd = g_strdup_printf("texcount '%s'", tmpfile);
    Tuple2 result = utils_popen_r(cmd, NULL);

    for (i = 0; i < TEXCOUNT_OUTPUT_LINES; ++i)
      if (!(regexs[i] = g_regex_new(terms_regex[i], 0, 0, &err))) {
        slog(L_G_ERROR, "utils_copy_file (): %s\n", err->message);
        g_free(tmpfile);
        g_error_free(err);
        goto cleanup;
      }

    for (i = 0; i < TEXCOUNT_OUTPUT_LINES; ++i) {
      if (g_regex_match(regexs[i], result.second, 0, &match_info)) {
        matched = g_match_info_fetch_all(match_info);
        if (NULL == matched[1]) {
          slog(L_WARNING, "can't extract info: %s\n", terms[i]);
          res[i] = g_strdup("N/A");
        } else {
          res[i] = g_strdup(matched[1]);
        }
        g_strfreev(matched);
        g_match_info_free(match_info);
      }
    }
    g_free(result.second);
    g_free(tmpfile);
  } else {
    cmd = NULL;
    slog(L_G_ERROR, "The 'texcount' utility could not be found.\n");
    return;
  }

  gchararray items[6] = {"stats_words", "stats_head", "stats_float",
                         "stats_nrhead", "stats_nrfloat", "stats_nrmath"
                        };
  int j = 0;
  GtkLabel *tmp;

  for (j = 0; j < 6; j++) {
    gchar *value = items[j];
    tmp = GTK_LABEL(gtk_builder_get_object(gui->builder, value));
    gtk_label_set_text(tmp, res[j]);
  }


  gtk_label_set_text(GTK_LABEL(gtk_builder_get_object(gui->builder,
                               "stats_filename")), tabmanagergui_get_labeltext(g_active_tab->page));
  gtk_widget_show(gui->docstatswindow);
  return;

cleanup:
  for (i = 0; i < TEXCOUNT_OUTPUT_LINES; ++i) {
    g_regex_unref(regexs[i]);
    g_free(res[i]);
  }
  g_free(cmd);
  g_free(output);
}