⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 callbacks.c

📁 unix/linux下支持各种压缩算法的软件
💻 C
📖 第 1 页 / 共 4 页
字号:
	textview = gtk_text_view_new();	gtk_text_view_set_editable (GTK_TEXT_VIEW(textview), FALSE);	gtk_container_add (GTK_CONTAINER(scrollwin), textview);	gtk_box_pack_start (GTK_BOX(vbox), scrollwin, TRUE, TRUE, 0);	gtk_container_add (GTK_CONTAINER(OutputWindow), vbox);	textbuf = gtk_text_view_get_buffer ( GTK_TEXT_VIEW(textview) );	gtk_text_buffer_get_start_iter (textbuf, &enditer);	gtk_text_buffer_create_tag (textbuf, "red_foreground","foreground", "red", NULL);		gtk_widget_show (vbox);	gtk_widget_show (scrollwin);	gtk_widget_show (textview);}void Cancel_Operation ( GtkMenuItem *menuitem , gpointer user_data ){    if ( kill ( child_pid , SIGABRT ) < 0 )    {        response = ShowGtkMessageDialog (GTK_WINDOW (MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK, strerror(errno));	    return;    }    //This in case the user cancel the opening a password protected archive    if (PasswordProtectedArchive) PasswordProtectedArchive = FALSE;}void View_File_Window ( GtkMenuItem *menuitem , gpointer user_data ){    gchar *command = NULL;    if ( PasswordProtectedArchive )    {            Show_pwd_Window ( NULL , NULL );            if ( password == NULL) return;    }    extract_path = "/tmp/";    names = g_string_new ( "" );    GtkTreeSelection *selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW (treeview1) );    gtk_tree_selection_selected_foreach (selection, (GtkTreeSelectionForeachFunc) ConcatenateFileNames, names );    command = ChooseCommandtoExecute ( 0 );   	compressor_pid = SpawnAsyncProcess ( command , 0 , 0);    g_free ( command );	if ( compressor_pid == 0 )    {        g_string_free ( names , FALSE );        return;    }    SetIOChannel (error_fd, G_IO_IN|G_IO_PRI|G_IO_ERR|G_IO_HUP|G_IO_NVAL,GenError, NULL );    g_child_watch_add ( compressor_pid , (GChildWatchFunc) ViewFileFromArchive , names );}GChildWatchFunc *ViewFileFromArchive (GPid pid , gint status , GString *data){    GIOChannel *ioc_view = NULL;    gchar *line = NULL;    gchar *filename = NULL;    GError *error = NULL;    gchar *string = NULL;    gboolean tofree = FALSE;    if ( WIFEXITED( status ) )    {   	    if ( WEXITSTATUS ( status ) )    	{	    	archive_error = TRUE;    		SetButtonState (1,1,0,0,0);	    	gtk_window_set_title ( GTK_WINDOW (MainWindow) , "Xarchiver " VERSION );		    response = ShowGtkMessageDialog (GTK_WINDOW 		(MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_QUESTION,GTK_BUTTONS_YES_NO,_("An error occurred while extracting the file to be viewed.\nDo you want to view the shell output ?") );            if (response == GTK_RESPONSE_YES) ShowShellOutput (NULL , FALSE);            unlink ( (char*)data );			return;        }    }    string = StripPathFromFilename ( data->str );    if (  string == NULL )    {        data->str++;        filename = g_strconcat ( "/tmp/" , data->str , NULL );    }    else    {        if ( strchr ( string , ' ' ) )        {            string = RemoveBackSlashes ( string );            tofree = TRUE;        }        filename = g_strconcat ( "/tmp" , string , NULL );        if ( tofree ) g_free ( string );    }    if ( g_file_test ( filename , G_FILE_TEST_IS_DIR ) )    {       response = ShowGtkMessageDialog (GTK_WINDOW (MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,	GTK_BUTTONS_OK,_("Please select a file, not a directory !") );        rmdir ( filename );        g_string_free ( data , FALSE );        g_free ( filename );        return;    }    view_window = view_win();	ioc_view = g_io_channel_new_file ( filename , "r" , &error );    if (error == NULL)     {        g_io_channel_set_encoding (ioc_view, "ISO8859-1" , NULL);        g_io_channel_set_flags ( ioc_view , G_IO_FLAG_NONBLOCK , NULL );        g_io_channel_read_to_end ( ioc_view , &line , NULL, NULL );        gtk_text_buffer_get_end_iter ( viewtextbuf, &viewenditer );        gtk_text_buffer_insert (viewtextbuf, &viewenditer, line, strlen ( line ) );        g_free ( line );        g_io_channel_shutdown ( ioc_view , TRUE , NULL );        g_io_channel_unref (ioc_view);    }    unlink ( filename );    gtk_widget_show (view_window);    g_free (filename);    g_string_free ( data , FALSE );}void Show_pwd_Window ( GtkMenuItem *menuitem , gpointer user_data ){    pwd_window = passwd_win();    password_entry = lookup_widget ( pwd_window , "pwd_entry" );    repeat_password = lookup_widget ( pwd_window , "entry2");            gtk_dialog_set_default_response (GTK_DIALOG (pwd_window), GTK_RESPONSE_OK);    done = FALSE;	while ( ! done )	{		switch ( gtk_dialog_run ( GTK_DIALOG ( pwd_window ) ) )		{			case GTK_RESPONSE_CANCEL:			case GTK_RESPONSE_DELETE_EVENT:			done = TRUE;            password = NULL;            break;						case GTK_RESPONSE_OK:			password  = g_strdup ( gtk_entry_get_text( GTK_ENTRY ( password_entry ) ) );             if ( strlen ( password ) == 0 || strlen(gtk_entry_get_text( GTK_ENTRY ( repeat_password )) ) == 0 )            {                response = ShowGtkMessageDialog (GTK_WINDOW (MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,_("Please type a password !") );                break;            }            if ( strcmp (password , gtk_entry_get_text( GTK_ENTRY ( repeat_password ) ) ) )            {                response = ShowGtkMessageDialog (GTK_WINDOW (MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,_("The passwords don't match !!") );                gtk_entry_set_text ( GTK_ENTRY ( password_entry ) , "" );                gtk_entry_set_text ( GTK_ENTRY ( repeat_password ) , "" );            }            else done = TRUE;            break;        }    }    gtk_widget_destroy ( pwd_window );}//Taken from xarchive - http://xarchive.sourceforge.netint is_escaped_char(char c){    switch ( c )    {        case ' ':	        case '\'':	        case '"':	        case '(':	        case ')':	        case '$':	        case '\\':	        case ';':	        case '<':	        case '>':	        case '&':	        case '#':	        case '*':	        case '|':	        case '`':	        case '!':	            return 1;        default:	            return 0;    }}gchar *EscapeBadChars ( gchar *string ){	char *q;	char *escaped;	int escapechars = 0;	char *p = string;	while (*p != '\000')	{        	if (is_escaped_char(*p)) escapechars++;	        p++;    }	if (!escapechars) return g_strdup(string);	escaped = (char *) malloc (strlen(string) + escapechars + 1);	p = string;	q = escaped;	while (*p != '\000')	{        	if (is_escaped_char(*p)) *q++ = '\\';		*q++ = *p++;	}	*q = '\000';	return escaped;}//End code from xarchivevoid Activate_buttons (){	if ( archive_error ) return;	GtkTreeSelection *selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW (treeview1) );	gint selected = gtk_tree_selection_count_selected_rows ( selection );	if (selected == 0 ) OffDeleteandViewButtons();    else	{        if ( CurrentArchiveType != 8 )         {            gtk_widget_set_sensitive ( delete_menu , TRUE );		    gtk_widget_set_sensitive ( Delete_button , TRUE );        }        if (selected > 1 || CurrentArchiveType == 8)        {            gtk_widget_set_sensitive ( View_button , FALSE);		    gtk_widget_set_sensitive ( view_menu, FALSE );        }        else        {            gtk_widget_set_sensitive ( View_button , TRUE );		    gtk_widget_set_sensitive ( view_menu, TRUE );        }	}}void ConcatenateFileNames2 (gchar *filename , GString *data){	gchar *esc_filename = EscapeBadChars ( filename );	g_string_prepend (data, esc_filename);	g_string_prepend_c (data, ' ');	g_free (esc_filename);	g_free (filename);}void ConcatenateFileNames (GtkTreeModel *model, GtkTreePath *treepath, GtkTreeIter *iter, GString *data){	gchar *filename;	gtk_tree_model_get (model, iter, 0, &filename, -1);	ConcatenateFileNames2 ( filename , data );}void ExtractAddDelete ( gchar *command ){	EmptyTextBuffer ();	compressor_pid = SpawnAsyncProcess ( command , 1 , 0);	if ( compressor_pid == 0 ) return;    gtk_widget_show ( viewport2 );	SetIOChannel (output_fd, G_IO_IN|G_IO_PRI|G_IO_ERR|G_IO_HUP|G_IO_NVAL , GenOutput, NULL );	SetIOChannel (error_fd, G_IO_IN|G_IO_PRI|G_IO_ERR|G_IO_HUP|G_IO_NVAL , GenError, NULL );    WaitExitStatus ( child_pid , NULL );}void Update_StatusBar ( gchar *msg)  {    gtk_label_set_text (GTK_LABEL (info_label), msg);}gboolean GenError (GIOChannel *ioc, GIOCondition cond, gpointer data){	if (cond & (G_IO_IN | G_IO_PRI) )	{		gchar *line = NULL;		g_io_channel_read_line ( ioc, &line, NULL, NULL, NULL );        gtk_progress_bar_pulse ( GTK_PROGRESS_BAR (progressbar) );        while (gtk_events_pending() )			gtk_main_iteration();		if (line != NULL && strcmp (line,"\n") )		{			gtk_text_buffer_insert_with_tags_by_name (textbuf, &enditer, line , -1, "red_foreground", NULL);			g_free (line);		}		return TRUE;	}	else if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL) )	{		g_io_channel_shutdown ( ioc,TRUE,NULL );        g_io_channel_unref (ioc);		return FALSE;	}}gboolean GenOutput (GIOChannel *ioc, GIOCondition cond, gpointer data){	gchar *line = NULL;	if (cond & (G_IO_IN | G_IO_PRI) )	{		g_io_channel_read_line ( ioc, &line, NULL, NULL, NULL );        gtk_progress_bar_pulse ( GTK_PROGRESS_BAR (progressbar) );        while (gtk_events_pending() )			gtk_main_iteration();		if (line != NULL )		{			gtk_text_buffer_insert (textbuf, &enditer, line, strlen ( line ) );			g_free (line);		}	}	else if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL) )	{	    g_io_channel_shutdown ( ioc,TRUE,NULL );        g_io_channel_unref (ioc);		return FALSE;	}	return TRUE;}gchar *StripPathFromFilename ( gchar *name ){    return g_strrstr ( name , "/" );}gchar *JoinPathArchiveName ( const gchar *extract_path , gchar *path ){	gchar *full_path = NULL;	full_path = g_strconcat (extract_path,path,NULL);	return full_path;}void OffDeleteandViewButtons(){    gtk_widget_set_sensitive ( Delete_button, FALSE);    gtk_widget_set_sensitive ( delete_menu, FALSE);    gtk_widget_set_sensitive ( View_button, FALSE);    gtk_widget_set_sensitive ( view_menu, FALSE);}void OffTooltipPadlock(){    gtk_widget_hide (viewport2);    if ( ! PasswordProtectedArchive )    {        gtk_tooltips_disable ( pad_tooltip );        gtk_widget_hide ( pad_image );    }}int CountCharacter ( gchar *string , int chr ){    int n = 0;    while ( *string )    {        if ( *string == chr ) n++;        string++;    }    return n;    }gchar *RemoveBackSlashes ( gchar *name){    gchar *nome, *q;    int x = CountCharacter ( name , '\\' );    nome = (char *) malloc (strlen(name) - x + 1);    q = nome;    while ( *name )    {        if ( *name == '\\' ) name++;        *q++ = *name++;    }    *q = '\000';    return nome;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -