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

📄 callbacks.c

📁 unix/linux下支持各种压缩算法的软件
💻 C
📖 第 1 页 / 共 4 页
字号:
/* *  Xarchiver * *  Copyright (C) 2005 Giuseppe Torelli - Colossus * *  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 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 Street #330, Boston, MA 02111-1307, USA. */#ifdef HAVE_CONFIG_H#include <config.h>#endif#include "callbacks.h"#include "interface.h"#include "support.h"#include "main.h"extern GList *ArchiveType;extern GList *ArchiveSuffix;extern gboolean file_to_open;extern gchar *tmp;gchar *CurrentFolder = NULL;GList *Suffix , *Name;void WaitExitStatus ( GPid child_pid , gchar *temp_file){    int status;    int waiting = TRUE;    int ps;    OffDeleteandViewButtons();    while (waiting)    {        ps = waitpid ( (pid_t)child_pid, &status, WNOHANG);        if (ps < 0) waiting = FALSE;        else         {            while (gtk_events_pending())                gtk_main_iteration();        }    }    OffTooltipPadlock();    if ( WIFEXITED (status) )	{		if ( WEXITSTATUS (status) )		{            Update_StatusBar ( _("Operation failed."));            gtk_tooltips_disable ( pad_tooltip );            gtk_widget_hide ( pad_image );			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 accessing the archive.\nDo you want to view the shell output ?") );			if (response == GTK_RESPONSE_YES) ShowShellOutput (NULL,FALSE);			return;		}	}    archive_error = FALSE;    //temp_file contains the filename created in /tmp to add/delete on tar.bzip2 / tar.gzip archives (look in bzip2.c:313 )    if ( temp_file != NULL)    {        unlink ( temp_file );        g_free (temp_file);    }	//This to automatically reload the content of the archive after adding or deleting	if (action == add || action == delete)	{        Update_StatusBar ( _("Please wait while the content of the archive is being updated..."));        RemoveColumnsListStore();        action = inactive;		switch ( CurrentArchiveType )		{			//case 0:			//Bzip2: not needed						//case 1:			//Gzip: not needed						case 2:			OpenRar ( FALSE , path );			break;			case 3:			OpenTar ( FALSE , path );			break;            case 4:            OpenBzip2 ( FALSE , path );            break;            case 5:            OpenGzip ( FALSE , path );            break;            case 6:			case 7:			OpenZip ( FALSE , path );			break;            //case 8:            //RPM: only open and extract            case 9:            Open7Zip ( FALSE, path );            break;            case 10:            //This to avoid generating an error when reloading an unexistent archive if the user            //deletes the whole content since arj deletes it instead of remaining it empty            if (g_file_test ( path , G_FILE_TEST_EXISTS) == TRUE) OpenArj ( FALSE, path );                else Update_StatusBar ( _("Operation successfully completed."));            break;		}        return;	}    //This to disable the Add and Delete buttons in case a bzip2 / gzip file has been decompressed    if ( ! bz_gz ) SetButtonState ( 1,1,1,1,1 );        else SetButtonState (1,1,0,0,0);    //Let's restore the liststore    if ( CurrentArchiveType != 0 && CurrentArchiveType != 1)    {        gtk_tree_view_set_model (GTK_TREE_VIEW(treeview1), model);        g_object_unref(model);    }    if ( password != NULL || PasswordProtectedArchive )    {        gtk_widget_show ( pad_image );        gtk_tooltips_enable ( pad_tooltip );    }    else    {        gtk_tooltips_disable ( pad_tooltip );        gtk_widget_hide ( pad_image );    }    //This to enable only the Extract button in case an RPM was opened    if (CurrentArchiveType == 8) SetButtonState (1,1,0,0,1);        if ( CurrentArchiveType == 2 || CurrentArchiveType == 6 || CurrentArchiveType == 7 || CurrentArchiveType == 9 || CurrentArchiveType == 10) gtk_widget_set_sensitive ( add_pwd , TRUE );     else gtk_widget_set_sensitive ( add_pwd , FALSE );    gtk_window_set_title ( GTK_WINDOW (MainWindow) , path );    Update_StatusBar ( _("Operation successfully completed."));}void on_new1_activate (GtkMenuItem *menuitem, gpointer user_data){	path = Show_File_Dialog ( 1 , "new" );	if (path == NULL) return;	if ( g_file_test ( path , G_FILE_TEST_EXISTS ) )	{		response = ShowGtkMessageDialog (GTK_WINDOW (MainWindow),						GTK_DIALOG_MODAL,						GTK_MESSAGE_QUESTION,						GTK_BUTTONS_YES_NO,						_("This archive already exists. Do you want to overwrite it ?")						);		if (response != GTK_RESPONSE_YES)		{			g_free (path);			return;		}        //The following to avoid the archivers updates the archive instead of adding to it since the filename exists        unlink ( path );	}    EmptyTextBuffer();    PasswordProtectedArchive = FALSE;    //Let's off the delete and view buttons and the menu entries to avoid misterious behaviour    OffDeleteandViewButtons ();    //This to delete a possible RPM file from /tmp since we don't need it anymore    if ( tmp != NULL )    {        unlink (tmp);        tmp = NULL;    }	if ( liststore != NULL ) RemoveColumnsListStore();	gtk_window_set_title ( GTK_WINDOW ( MainWindow) , path );	if ( CurrentArchiveType == 0 || CurrentArchiveType == 1 )    {        bz_gz = TRUE;        SetButtonState (1,1,1,0,0 );    }    else    {        SetButtonState (1,1,1,1,0 );        bz_gz = FALSE;    }    if ( CurrentArchiveType == 2 || CurrentArchiveType == 6 || CurrentArchiveType == 7 || CurrentArchiveType == 9 || CurrentArchiveType == 10 )    {        gtk_widget_set_sensitive ( add_pwd , TRUE );        Update_StatusBar ( _("Choose Action->Set Password to create a password protected archive."));    }    else    {        gtk_widget_set_sensitive ( add_pwd , FALSE );        Update_StatusBar ( _("Choose Add File or Add Folder to create the archive."));    }    gtk_tooltips_disable ( pad_tooltip );    gtk_widget_hide ( pad_image );    if (password != NULL) g_free (password);    password = NULL;}int ShowGtkMessageDialog ( GtkWindow *window, int mode,int type,int button, gchar *message){	dialog = gtk_message_dialog_new (window, mode, type, button,message);	gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);	response = gtk_dialog_run (GTK_DIALOG (dialog) );	gtk_widget_destroy (GTK_WIDGET (dialog) );	return response;}void on_open1_activate (GtkMenuItem *menuitem, gpointer user_data){	if ( ! file_to_open )	{		path = Show_File_Dialog ( 1 , "open" );		if (path == NULL) return;	}	file_to_open = FALSE;	if ( liststore != NULL )	{		RemoveColumnsListStore();		EmptyTextBuffer ();	}    //Did the user previously open an RPM file ? Delete it from /tmp since we don't need it anymore    if ( CurrentArchiveType == 8 ) unlink (tmp);    EmptyTextBuffer();    if ( GTK_WIDGET_VISIBLE (OutputWindow )) gtk_widget_hide (OutputWindow);    PasswordProtectedArchive = FALSE;    OffDeleteandViewButtons();    CurrentArchiveType = DetectArchiveType ( path );    if ( CurrentArchiveType == -1 ) return;    path = EscapeBadChars ( path );	bz_gz = FALSE;    gtk_widget_show ( viewport2 );    Update_StatusBar ( _("Please wait while the content of the archive is being read..."));	switch ( CurrentArchiveType )	{		case 0:		OpenBzip2 ( TRUE , path );		break;		case 1:		OpenGzip ( TRUE , path );		break;		case 2:		OpenRar ( TRUE , path );		break;		case 3:		OpenTar ( TRUE , path );		break;		case 7:		OpenZip ( TRUE , path );		break;        case 8:        OpenRPM ( TRUE , path );        break;        case 9:        Open7Zip ( TRUE , path );        break;		case 10:		OpenArj ( TRUE , path );		break;	}    if (password != NULL) g_free (password);    password = NULL;}void on_quit1_activate (GtkMenuItem *menuitem, gpointer user_data){    if ( GTK_WIDGET_VISIBLE (viewport2) ) return;    g_list_free ( Suffix );	g_list_free ( Name );	if ( path != NULL ) g_free (path);    if ( extract_path != NULL )        if ( strcmp (extract_path,"/tmp/") != 0) g_free (extract_path);    //This to delete a CPIO temp file in /tmp if existing    if ( tmp != NULL )    {        unlink (tmp);        tmp = NULL;    }    gtk_main_quit();}void on_delete1_activate (GtkMenuItem *menuitem, gpointer user_data){	gchar *command = NULL;	GtkTreeSelection *selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW (treeview1) );	names = g_string_new ( " " );	gtk_tree_selection_selected_foreach (selection, (GtkTreeSelectionForeachFunc) ConcatenateFileNames, names );	action = delete;	Update_StatusBar ( _("Deleting files from the archive, please wait..."));	switch (CurrentArchiveType)	{		case 2:		command = g_strconcat ( "rar d " , path , names->str , NULL );		break;		        case 3:		command = g_strconcat ( "tar --delete -vf " , path , names->str , NULL );		break;		        case 4:        DecompressBzipGzip ( names , path , 0  , 0 );        break;		        case 5:        DecompressBzipGzip ( names , path , 1 , 0 );		break;	        case 6:        case 7:		command = g_strconcat ( "zip -d " , path , names->str , NULL );		break;        case 9:        command = g_strconcat ( "7za d " , path , names->str , NULL );        break;        case 10:        command = g_strconcat ( "arj d " , path , names->str, NULL);        break;	}	if (command != NULL)    {        ExtractAddDelete ( command );        g_free (command);    }	g_string_free (names , FALSE );}void on_add_files_activate ( GtkMenuItem *menuitem, gpointer user_data ){    gchar *name = NULL;	gchar *command = NULL;	GSList *Files_to_Add  = Add_File_Dialog ( user_data );	if ( Files_to_Add == NULL) return;	names = g_string_new ( " " );    Files_to_Add = g_slist_reverse (Files_to_Add);    //Set the current dir so to avoid archiving the leading directory inside the archive    name = g_path_get_dirname ( Files_to_Add->data );	chdir ( name );    g_free ( name );    while ( Files_to_Add != NULL )	{        //Strip the path from the filename        name = g_path_get_basename ( Files_to_Add->data );        ConcatenateFileNames2 ( name , names );        Files_to_Add = g_slist_next ( Files_to_Add );	}			action = add;			switch (CurrentArchiveType)

⌨️ 快捷键说明

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