Example #1
0
File: net.c Project: eldesh/nanonet
struct addrinfo * make_addrinfo(char const * host, char const * port) {
	struct addrinfo * res=NULL;
// IPv6 will be choiced by default @Win7
//	struct addrinfo hint=make_hint(AF_UNSPEC, SOCK_STREAM, IPPROTO_TCP);
	struct addrinfo hint=make_hint(AF_INET, SOCK_STREAM, IPPROTO_TCP);
	int err=getaddrinfo(host, port, &hint, &res);
	if (err) {
		NANOLOG("getaddrinfo failed <%d>\n", nanonet_error());
		return NULL;
	}
	return res;
}
Example #2
0
static void
add_compare_to_menu(GList* actions, GtkWidget* window, GList* files, char* menu_name, GString* (*make_hint)(va_list, char*), GCallback callback, ...) {
  GtkAction* action;    
  GtkIconTheme* theme = gtk_icon_theme_get_default();
  GList* head = g_queue_peek_head_link(_saved);
  xdiff_ext_submenu_action* submenu;
  GString* name = g_string_new("");
  int n = 1;
  va_list args;
  
  va_start(args, callback);
  
  submenu = xdiff_ext_submenu_action_new("xdiff-ext::compare_to_menu", menu_name, "", NULL);
  actions = g_list_append(actions, submenu);

  while(head) {
    gchar* head_file = (gchar*)head->data;    
    ThunarVfsPath* vfs_path = thunar_vfs_path_new(head_file, NULL);
    ThunarVfsInfo* vfs_info = thunar_vfs_info_new_for_path(vfs_path, NULL);
    const gchar* icon_name = thunar_vfs_info_get_custom_icon(vfs_info);
    GString* hint = make_hint(args, head_file);
    
    if(icon_name == NULL) {
      icon_name = thunar_vfs_mime_info_lookup_icon_name(vfs_info->mime_info, theme);
    }
    
    thunar_vfs_path_unref(vfs_path);
    thunar_vfs_info_unref(vfs_info);
    
    g_string_printf(name, "xdiff-ext::compare_to_%d", n);
    
    action = gtk_action_new(name->str, head_file, hint->str, icon_name);
    g_signal_connect(G_OBJECT(action), "activate", callback, window);
    g_object_set_data_full(G_OBJECT(action), "xdiff-ext::compare_to", thunarx_file_info_list_copy(files),(GDestroyNotify)thunarx_file_info_list_free);
    g_object_set_data(G_OBJECT(action), "xdiff-ext::saved", head);
    xdiff_ext_submenu_action_add(submenu, action);
    
    g_string_free(hint, TRUE);

    head = g_list_next(head);
    n++;
  }
  
  xdiff_ext_submenu_action_add(submenu, NULL);
  
  action = gtk_action_new("xdiff-ext::clear", _("Clear"), _("Clear selected files list"), GTK_STOCK_CLEAR);
  g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(clear), window);
  xdiff_ext_submenu_action_add(submenu, action);
  
  g_string_free(name, TRUE);
  va_end(args);
}
Example #3
0
void traitement_sigsegv ( gint signal_nb )
{
    gchar *gsb_file_default_dir;
    gchar *errmsg = g_strdup ( "" );
	gchar *old_errmsg;
    gchar *tmpstr;
    GtkWidget * dialog;
#ifdef HAVE_BACKTRACE
    GtkWidget * expander;
#endif

    /*   il y a 3 possibilités : */
    /*     soit on était en train de charger un fichier, c'est que celui-ci est corrompu */
    /* soit on était en train de sauver un fichier, et là on peut rien faire */
    /* sinon on essaie de sauver le fichier sous le nom entouré de # */

    if ( run.is_loading || 
	 run.is_saving || 
	 !gsb_file_get_modified ( ) )
    {

	if ( run.is_loading )
	{
	    old_errmsg = errmsg;
	    errmsg = g_strconcat ( errmsg, _("File is corrupted."), NULL );
	    g_free ( old_errmsg );
	}

	if ( run.is_saving )
	{
	    old_errmsg = errmsg;
	    errmsg = g_strconcat ( errmsg, _("Error occured saving file."), NULL );
	    g_free ( old_errmsg );
	}
    }
    else 
    {
	/* c'est un bug pendant le fonctionnement de Grisbi s'il n'y a
	   pas de nom de fichier, on le crée, sinon on rajoute #
	   autour */

        gsb_file_default_dir = (gchar *) my_get_gsb_file_default_dir();

	if ( nom_fichier_comptes )
	    /* set # around the filename */
	    nom_fichier_comptes = g_path_get_basename (nom_fichier_comptes);
	else
	    /* no name for the file, create it */
	    nom_fichier_comptes = g_strconcat ( gsb_file_default_dir,
						"/#grisbi_crash_no_name#",
						NULL );

	gsb_status_message ( _("Save file") );

	gsb_file_save_save_file ( nom_fichier_comptes,
				  conf.compress_file,
				  FALSE );

	gsb_status_clear();

    old_errmsg = errmsg;
	errmsg = g_strconcat ( errmsg, 
			       g_strdup_printf ( _("Grisbi made a backup file at '%s'."),
						 nom_fichier_comptes ),
			       NULL );
	g_free ( old_errmsg );
    }

    old_errmsg = errmsg;
    errmsg = g_strconcat ( errmsg, 
			   "\n\n",
			   _("Please report this problem to <tt>http://www.grisbi.org/bugtracking/</tt>.  "),
			   NULL );
     g_free ( old_errmsg );

#ifdef HAVE_BACKTRACE
    old_errmsg = errmsg;
    errmsg = g_strconcat ( errmsg, _("Copy and paste the following backtrace with your bug "
                        "report."),
			   NULL );
     g_free ( old_errmsg );
#endif

    dialog = dialogue_special_no_run ( GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
				       make_hint ( _("Grisbi terminated due to a segmentation fault."),
						   errmsg ));
    g_free ( errmsg );

#ifdef HAVE_BACKTRACE
    tmpstr = g_strconcat ( "<b>", _("Backtrace"), "</b>", NULL );
    expander = gtk_expander_new ( tmpstr );
    g_free ( tmpstr );

    gtk_expander_set_use_markup ( GTK_EXPANDER ( expander ), TRUE );
    gtk_container_add ( GTK_CONTAINER ( expander ), print_backtrace() );
    gtk_box_pack_start ( GTK_BOX ( GTK_DIALOG(dialog)->vbox ), expander, FALSE, FALSE, 6 );

    gtk_widget_show_all ( dialog );
#endif
    gtk_dialog_run ( GTK_DIALOG ( dialog ) );

    /*     on évite le message du fichier ouvert à la prochaine ouverture */

    gsb_file_util_modify_lock ( FALSE );

    exit(1);
}
Example #4
0
/**
 * propose to save the file if changed
 * if the current file is not changed, return GTK_RESPONSE_NO directly, without dialog
 *
 * \param
 *
 * \return GTK_RESPONSE_OK to save, GTK_RESPONSE_NO not to save, other to cancel
 * */
static gint gsb_file_dialog_save ( void )
{
    gchar * hint;
    gchar* time_elapsed;
    time_t now = time ( NULL );
    gint result;
    GtkWidget *dialog;
    gint difference = (gint) difftime ( now, run.file_modification );
    gchar* message;
	gchar* tmpstr1;
	gchar* tmpstr2;

    /*     si le fichier n'est pas modifié on renvoie qu'on ne veut pas enregistrer */

    if ( ! gsb_file_get_modified ( ) )
	return GTK_RESPONSE_NO;

    if ( conf.sauvegarde_auto &&
	 ( !etat.fichier_deja_ouvert || conf.force_enregistrement ) &&
	 nom_fichier_comptes )
      return GTK_RESPONSE_OK;

    /*     si le fichier était déjà locké et que force enregistrement n'est pas mis, */
    /*     on prévient ici */

    dialog = gtk_message_dialog_new ( GTK_WINDOW ( run.window ),
				      GTK_DIALOG_DESTROY_WITH_PARENT,
				      GTK_MESSAGE_WARNING,
				      GTK_BUTTONS_NONE,
				      " " );
    if ( etat.fichier_deja_ouvert
	 &&
	 !conf.force_enregistrement )
    {
	hint = g_strdup(_("Save locked files?"));
	message = g_strdup_printf ( _("The document '%s' is locked but modified. If you want to save it, you must cancel and save it with another name or activate the \"%s\" option in setup."),
				    (nom_fichier_comptes ? g_path_get_basename(nom_fichier_comptes) : _("unnamed")),
				    _("Force saving of locked files"));
	gtk_dialog_add_buttons ( GTK_DIALOG(dialog),
				 _("Close without saving"), GTK_RESPONSE_NO,
				 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
				 NULL );
	gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_CANCEL );
    }
    else
    {
	hint = g_strdup_printf (_("Save changes to document '%s' before closing?"),
				(nom_fichier_comptes ? g_path_get_basename(nom_fichier_comptes) : _("unnamed")));
        message = g_strdup("");
	gtk_dialog_add_buttons ( GTK_DIALOG(dialog),
				 _("Close without saving"), GTK_RESPONSE_NO,
				 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
				 GTK_STOCK_SAVE, GTK_RESPONSE_OK,
				 NULL );
	gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_OK );
    }

    if ( difference >= 120 )
    {
	time_elapsed = g_strdup_printf ( _( "%d minutes and %d seconds" ),
					 difference / 60, difference % 60 );
    }
    else if ( difference >= 60 )
    {
	time_elapsed = g_strdup_printf ( _( "1 minute and %d seconds" ),
					 difference % 60 );
    }
    else
    {
	time_elapsed = g_strdup_printf ( _( "%d seconds" ), difference );
    }
    tmpstr1 = message;
    tmpstr2 = g_strdup_printf ( _("If you close without saving, all of your changes "
						"since %s will be discarded."),
					      time_elapsed );
    message = g_strconcat ( tmpstr1, tmpstr2 , NULL );
    g_free ( tmpstr1 );
    g_free ( tmpstr2 );
    g_free ( time_elapsed );

    gtk_label_set_markup ( GTK_LABEL ( GTK_MESSAGE_DIALOG(dialog)->label ),
			   make_hint ( hint, message ) );

    g_free ( message );
    g_free ( hint );
    gtk_window_set_modal ( GTK_WINDOW ( dialog ), TRUE );

    result = gtk_dialog_run (GTK_DIALOG (dialog));
    gtk_widget_destroy ( dialog );

    return result;
}
Example #5
0
/**
 * Fill in all graphical elements of preview page with data from a CSV
 * file.
 *
 * \param assistant	Assistant that contains the page.
 *
 * \return		FALSE
 */
gboolean import_enter_csv_preview_page ( GtkWidget * assistant )
{
    GtkWidget * entry;
    GSList * files;
    gchar *contents, *tmp_str, *filename = NULL;
    gsize size;
    gsize bytes_written;
    GError * error;
    struct imported_file * imported = NULL;

    /* Find first CSV to import. */
    files = import_selected_files ( assistant );
    while ( files )
    {
        imported = files -> data;

        if ( !strcmp ( imported -> type, "CSV" ) )
        {
            filename = imported -> name;
            break;
        }
        files = files -> next;
    }
    g_return_val_if_fail ( filename, FALSE );

    /* Open file */
    if ( ! g_file_get_contents ( filename, &tmp_str, &size, &error ) )
    {
        g_print ( _("Unable to read file: %s\n"), error -> message);
        g_error_free ( error );
        return FALSE;
    }

    /* Convert in UTF8 */
    error = NULL;
    contents = g_convert_with_fallback ( tmp_str, -1, "UTF-8", imported -> coding_system,
                        "?", &size, &bytes_written, &error );

    if ( contents == NULL )
    {
        g_error_free ( error );
        error = NULL;
        size = 0;
        bytes_written = 0;

        dialogue_special ( GTK_MESSAGE_WARNING, make_hint (
                            _("The conversion to utf8 went wrong."),
                            _("If the result does not suit you, try again by selecting the "
                            "correct character set in the window for selecting files.") ) );

        contents = g_convert_with_fallback ( tmp_str, -1, "UTF-8", "ISO-8859-1",
                        "?", &size, &bytes_written, &error );
        if ( bytes_written == 0 )
        {
            g_print ( _("Unable to read file: %s\n"), error -> message);
            g_error_free ( error );
            return FALSE;
        }
    }

    g_free ( tmp_str );
    g_object_set_data ( G_OBJECT(assistant), "contents", contents );

    entry = g_object_get_data ( G_OBJECT(assistant), "entry" );
    if ( entry )
    {
	if ( etat.csv_separator )
	{
	    gtk_entry_set_text ( GTK_ENTRY(entry), etat.csv_separator );
	}
	else
	{
	    gtk_entry_set_text ( GTK_ENTRY(entry), csv_import_guess_separator ( contents ) );
	}
    }

    csv_import_update_validity_check ( assistant );

    return FALSE;
}
Example #6
0
/* get the line af the file,
 * convert it in UTF8 and fill string with that line
 *
 * \param fichier
 * \param string
 * \param coding_system	the orig coding system of the string
 *
 * \return EOF, 1 if ok, 0 if problem
 * */
gint get_utf8_line_from_file ( FILE *fichier,
                        gchar **string,
                        const gchar *coding_system )
{
    gchar c = 0;
    gint i = 0;
    gint j = 0;
    gchar *pointeur_char = NULL;
    gchar *tmp_string;

    if ( !fichier )
	return 0;
	    
    /* allocate 30 characters, and increase it 30 by 30 */
    pointeur_char = (gchar*)g_realloc(pointeur_char,30*sizeof(gchar));

    if ( !pointeur_char )
    {
	/* ouch, not enough memory */
	dialogue_error ( _("Memory allocation error" ));
	return 0;
    }

    /* get the string untill \n or \r (windows format) */
    c =(gchar)fgetc(fichier);
    while ( ( c != '\n' ) && (c != '\r') && !feof (fichier))
    {
	pointeur_char[j++] = c;

	if ( ++i == 29 )
	{
	    pointeur_char = (gchar*)g_realloc(pointeur_char, j + 1 + 30*sizeof(gchar));

	    if ( !pointeur_char )
	    {
		/* ouch, not enough memory */
		dialogue_error ( _("Memory allocation error" ));
		return 0;
	    }
	    i = 0;
	}
	c =(gchar)fgetc(fichier);
    }
    pointeur_char[j] = 0;

    /* if we finished on \r, jump the \n after it */
    if ( c == '\r' )
    {
	c =(gchar)fgetc(fichier);
	if ( c != '\n' )
	{
	    ungetc ( c, fichier );
	}
    }

    tmp_string = g_convert ( pointeur_char, -1, "UTF-8", 
			     coding_system, NULL, NULL,
			     NULL );
    if (!tmp_string)
    {
        devel_debug ("convert to utf8 failed, will use latin2utf8");
        tmp_string = latin2utf8 (pointeur_char);
        if ( tmp_string == NULL )
        {
            dialogue_special ( GTK_MESSAGE_ERROR, make_hint (
                            _("Convert to utf8 failed."),
                            _("If the result is not correct, try again by selecting the "
                            "correct character set in the window for selecting files.") ) );
            return 0;
        }
    }
    *string = tmp_string;
    g_free (pointeur_char);

    if ( feof(fichier))
        return EOF;
    else
        return 1;
}
Example #7
0
/**
 * Display a tip.
 *
 * \param force  Forcefully display the tip even if show_tip option
 *		 has been disabled.
 */
void display_tip ( gboolean force )
{
    GtkWidget * checkbox;
    GtkWidget * dialog = NULL;
    GtkWidget *btn_back, *btn_forward, *btn_close;
    gchar *tmpstr;

    if ( !force && !conf.show_tip )
        return;

    conf.last_tip = CLAMP ( conf.last_tip+1, 0, sizeof(tips)/sizeof(gpointer)-1);

    dialog = dialogue_special_no_run ( GTK_MESSAGE_INFO, GTK_BUTTONS_NONE,
                        make_hint ( _("Did you know that..."),
                        /* We use the Grisbi-tips catalog */
                        g_dgettext(NULL, tips[conf.last_tip]) ) );
    gtk_window_set_modal ( GTK_WINDOW ( dialog ), FALSE );

    checkbox = gsb_automem_checkbutton_new ( _("Display tips at next start"),
                        &(conf.show_tip), NULL, NULL );
    gtk_box_pack_start ( GTK_BOX ( GTK_DIALOG(dialog) -> vbox ), checkbox, FALSE, FALSE, 6 );
    gtk_widget_show ( checkbox );

    btn_back =    gtk_dialog_add_button (GTK_DIALOG(dialog), GTK_STOCK_GO_BACK, 1);
    btn_forward = gtk_dialog_add_button (GTK_DIALOG(dialog), GTK_STOCK_GO_FORWARD, 2);
    btn_close =   gtk_dialog_add_button (GTK_DIALOG(dialog), GTK_STOCK_CLOSE, 3);

    /* gtk_widget_set_size_request ( dialog, 450, -1 ); */
    /* We iterate as user can select several tips. */
    while ( TRUE )
    {
    if ( conf.last_tip == sizeof(tips)/sizeof(gpointer)-1)
        gtk_widget_set_sensitive (btn_forward, FALSE);
    if ( conf.last_tip == 0)
        gtk_widget_set_sensitive (btn_back, FALSE);

    switch ( gtk_dialog_run ( GTK_DIALOG(dialog) ) )
    {
        case 1:
        if ( conf.last_tip > 0 )
            conf.last_tip--;
        gtk_widget_set_sensitive (btn_forward, TRUE);
        tmpstr = g_strconcat ( make_pango_attribut (
                        "size=\"larger\" weight=\"bold\"", _("Did you know that...") ),
                        "\n\n",
                        g_dgettext (NULL, tips[conf.last_tip] ),
                        NULL );

        gtk_label_set_markup ( GTK_LABEL ( GTK_MESSAGE_DIALOG(dialog) -> label ),
                        tmpstr );
        g_free ( tmpstr );
        break;

        case 2:
        if ( conf.last_tip < sizeof(tips)/sizeof(gpointer)-1)
            conf.last_tip++;
        tmpstr = g_strconcat ( make_pango_attribut (
                        "size=\"larger\" weight=\"bold\"", _("Did you know that...") ),
                        "\n\n",
                        g_dgettext (NULL, tips[conf.last_tip] ),
                        NULL );

        gtk_label_set_markup ( GTK_LABEL ( GTK_MESSAGE_DIALOG(dialog) -> label ),
                        tmpstr );
        g_free ( tmpstr );
        gtk_widget_set_sensitive (btn_back, TRUE);
        break;

        default:
        gtk_widget_destroy ( dialog );
        return;
    }
    }
}