📄 gsegyfileview.c
字号:
/* * GTKSEISVIEWUI - Library of interface elements for GSEGYView * * Copyright (C) 2006 Vladimir Bashkardin * * 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 av. * * 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 Place - Suite 330, * Boston, MA 02111-1307, USA. * * Author: Vladimir Bashkardin <vovizmus@users.sourceforge.net> */#include <gsegyfile/gsegyfile.h>#include "gsegyfileaux.h"#include "gsegyfileview.h"#include "gsegyfileinfo.h"#include "gsegysortview.h"#include "gsegypreferences.h"#include "gsegyfileui_marshal.h"G_DEFINE_TYPE (GSEGYFileView, g_segy_file_view, G_TYPE_OBJECT)#define G_SEGY_FILE_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), G_SEGY_TYPE_FILE_VIEW, GSEGYFileViewPrivate))typedef struct _GSEGYFileViewPrivate GSEGYFileViewPrivate;struct _GSEGYFileViewPrivate { GtkWidget *expander; GtkWidget *hbox; GtkWidget *padding_label; GtkWidget *vbox; GtkWidget *title_hbox; GtkWidget *add_view_button; GtkWidget *add_view_icon; GtkWidget *info_button; GtkWidget *info_icon; GtkWidget *pref_button; GtkWidget *pref_icon; GtkWidget *close_file_button; GtkWidget *close_file_icon; GtkWidget *progress_bar; GtkWidget *label; GtkWidget *combo_sort_one; GtkWidget *combo_sort_two; GtkWidget *hsep; GtkTooltips *fileview_tips; gint first_sort_level_id; gint second_sort_level_id; GtkWidget *close_confirm_dialog; GSEGYFile *segy_file; GSEGYFormatWizard *format_wizard; gchar *short_filename; GAsyncQueue *scan_progress; GThread *scanning_thread; GMutex *file_mutex; gfloat fraction; GSEGYFileError file_error; GPtrArray *sorts_views; GSEGYFileInfo *file_info; GSEGYPreferences *preferences;};static void g_segy_file_view_init (GSEGYFileView *self) { GSEGYFileViewPrivate *private = G_SEGY_FILE_VIEW_GET_PRIVATE (self); private->expander = NULL; private->hbox = NULL; private->padding_label = NULL; private->vbox = NULL; private->title_hbox = NULL; private->add_view_button = NULL; private->add_view_icon = NULL; private->info_button = NULL; private->info_icon = NULL; private->pref_button = NULL; private->pref_icon = NULL; private->close_file_button = NULL; private->close_file_icon = NULL; private->label = NULL; private->progress_bar = NULL; private->combo_sort_one = NULL; private->combo_sort_two = NULL; private->hsep = NULL; private->fileview_tips = NULL; private->close_confirm_dialog = NULL; private->segy_file = NULL; private->short_filename = NULL; private->scan_progress = g_async_queue_new (); private->scanning_thread = NULL; private->file_mutex = g_mutex_new (); private->first_sort_level_id = -1; private->second_sort_level_id = -1; private->sorts_views = g_ptr_array_new (); private->format_wizard = NULL; private->file_error.gerror = NULL; private->file_error.id = G_SEGY_FILE_NO_ERROR; private->file_info = NULL; private->preferences = NULL;#ifdef DEBUG g_print ("<GSEGYFileView is inited>\n");#endif}static void g_segy_file_view_stop_thread (GSEGYFileView *self) { GSEGYFileViewPrivate *private = G_SEGY_FILE_VIEW_GET_PRIVATE (self); if (private->scan_progress && private->scanning_thread) { g_async_queue_push (private->scan_progress, self); g_thread_join (private->scanning_thread); }}static void g_segy_file_view_finalize (GObject *object) { GSEGYFileView *self = G_SEGY_FILE_VIEW (object); GSEGYFileViewPrivate *private = G_SEGY_FILE_VIEW_GET_PRIVATE (self); g_segy_file_view_stop_thread (self); while (g_idle_remove_by_data ((gpointer)self)); if (private->sorts_views) { guint i, view_num = private->sorts_views->len; for (i = 0; i < view_num; i++) g_object_unref (G_OBJECT (g_ptr_array_index (private->sorts_views, i))); g_ptr_array_free (private->sorts_views, TRUE); } if (private->preferences) g_object_unref (G_OBJECT (private->preferences)); if (private->file_info) g_object_unref (G_OBJECT (private->file_info)); if (private->close_confirm_dialog) gtk_widget_destroy (private->close_confirm_dialog); if (private->segy_file) g_object_unref (G_OBJECT (private->segy_file)); if (private->short_filename) g_free (private->short_filename); if (private->format_wizard) g_object_unref (G_OBJECT (private->format_wizard)); if (private->scan_progress) g_async_queue_unref (private->scan_progress); if (private->file_mutex) g_mutex_free (private->file_mutex); if (private->expander) gtk_widget_destroy (private->expander); if (private->file_error.gerror) g_error_free (private->file_error.gerror); if (private->fileview_tips) g_object_unref (G_OBJECT (private->fileview_tips));#ifdef DEBUG g_print ("<GSEGYFileView is finalized>\n");#endif if (G_OBJECT_CLASS (g_segy_file_view_parent_class)->finalize) G_OBJECT_CLASS (g_segy_file_view_parent_class)->finalize (object);}static gboolean g_segy_file_view_close_signal (GSEGYFileView *self) { g_signal_emit (self, G_SEGY_FILE_VIEW_GET_CLASS (self)->file_close_id, 0); return FALSE;}static gboolean g_segy_file_view_close_signal_thread (GSEGYFileView *self) { gdk_threads_enter (); g_segy_file_view_close_signal (self); gdk_threads_leave (); return FALSE;}static void g_segy_file_view_class_init (GSEGYFileViewClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); gobject_class->finalize = g_segy_file_view_finalize; g_type_class_add_private (klass, sizeof (GSEGYFileViewPrivate)); klass->file_close = NULL; klass->file_close_id = g_signal_new ("file_close", G_TYPE_FROM_CLASS ((gpointer)G_OBJECT_CLASS (klass)), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GSEGYFileViewClass, file_close), NULL, NULL, g_segyui_marshal_VOID__VOID, G_TYPE_NONE, 0);#ifdef DEBUG g_print ("<GSEGYFileView class is inited>\n");#endif}static gboolean g_segy_file_view_close_handler (GtkWidget *widget, gpointer data) { GSEGYFileViewPrivate *private = G_SEGY_FILE_VIEW_GET_PRIVATE (G_SEGY_FILE_VIEW (data)); if (NULL == private->close_confirm_dialog) { if (private->short_filename) private->close_confirm_dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_toplevel (private->expander)), GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, _("Are you sure that you want to close the file" " %s and its views?"), private->short_filename); else private->close_confirm_dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_toplevel (private->expander)), GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, _("Are you sure that you want to close the file" " and its views?")); } if (GTK_RESPONSE_YES == gtk_dialog_run (GTK_DIALOG (private->close_confirm_dialog))) { gtk_widget_hide (GTK_WIDGET (private->close_confirm_dialog)); g_segy_file_view_close_signal (G_SEGY_FILE_VIEW (data)); return FALSE; } else gtk_widget_hide (GTK_WIDGET (private->close_confirm_dialog)); return TRUE;}static void g_segy_file_view_preferences_handler (GtkWidget *widget, gpointer data) { GSEGYFileViewPrivate *private = G_SEGY_FILE_VIEW_GET_PRIVATE (G_SEGY_FILE_VIEW (data)); gtk_widget_show (g_segy_preferences_get_main_widget (private->preferences));}static void g_segy_file_view_file_info_handler (GtkWidget *widget, gpointer data) { GSEGYFileViewPrivate *private = G_SEGY_FILE_VIEW_GET_PRIVATE (G_SEGY_FILE_VIEW (data)); if (NULL == private->file_info) private->file_info = g_segy_file_info_new (g_segy_file_get_file_accessor (private->segy_file)); gtk_widget_show (g_segy_file_info_get_main_widget (private->file_info));}static void g_segy_file_view_sort_view_remove_handler (GSEGYSortView *sort_view, gpointer data) { GSEGYFileViewPrivate *private = G_SEGY_FILE_VIEW_GET_PRIVATE (G_SEGY_FILE_VIEW (data)); g_ptr_array_remove (private->sorts_views, (gpointer)sort_view); g_object_unref (G_OBJECT (sort_view));}static void g_segy_file_view_sort_view_add_handler (GtkWidget *button, gpointer data) { GSEGYFileViewPrivate *private = G_SEGY_FILE_VIEW_GET_PRIVATE (G_SEGY_FILE_VIEW (data));#if GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION <= 4 GtkTreeIter iter; gchar *sort_name = NULL; gchar *first_sort_name = NULL; gchar *second_sort_name = NULL; if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (private->combo_sort_one), &iter)) gtk_tree_model_get (gtk_combo_box_get_model (GTK_COMBO_BOX (private->combo_sort_one)), &iter, 0, &first_sort_name, -1); if (private->second_sort_level_id != 0 && gtk_combo_box_get_active_iter (GTK_COMBO_BOX (private->combo_sort_two), &iter)) gtk_tree_model_get (gtk_combo_box_get_model (GTK_COMBO_BOX (private->combo_sort_two)), &iter, 0, &second_sort_name, -1); if (private->short_filename) { if (first_sort_name && second_sort_name) sort_name = g_strconcat (private->short_filename, _(" sorted by "), first_sort_name, _(" and "), second_sort_name, NULL); else if (first_sort_name) sort_name = g_strconcat (private->short_filename, _(" sorted by "), first_sort_name, NULL); else sort_name = g_strdup (private->short_filename); }#else gchar *sort_name = private->second_sort_level_id != 0 ? g_strconcat (private->short_filename, _(" sorted by "), gtk_combo_box_get_active_text (GTK_COMBO_BOX (private->combo_sort_one)), _(" and "), gtk_combo_box_get_active_text (GTK_COMBO_BOX (private->combo_sort_two)), NULL) : g_strconcat (private->short_filename, _(" sorted by "), gtk_combo_box_get_active_text (GTK_COMBO_BOX (private->combo_sort_one)), NULL);#endif GSEGYSortView* sort_view = g_segy_sort_view_new (sort_name); g_ptr_array_add (private->sorts_views, (gpointer)sort_view); gtk_box_pack_start (GTK_BOX (private->vbox), g_segy_sort_view_get_main_widget (sort_view), FALSE, FALSE, 0); g_segy_sort_view_set_data_view_pref (sort_view, g_segy_preferences_get_data_view_pref (private->preferences)); GSEGYSeismicAccessor *seismic_accessor = g_segy_file_get_seismic_accessor (private->segy_file); g_signal_connect (G_OBJECT (sort_view), "view_remove", (GCallback)g_segy_file_view_sort_view_remove_handler, (gpointer)G_SEGY_FILE_VIEW (data)); g_segy_sort_view_set_seismic_accessor (sort_view, seismic_accessor, private->first_sort_level_id + 1, private->second_sort_level_id); g_object_unref (G_OBJECT (seismic_accessor)); g_free (sort_name); gtk_widget_show_all (g_segy_sort_view_get_main_widget (sort_view));}static void g_segy_file_view_combo_one_changed_handler (GtkComboBox *combo_box, gpointer data) { GSEGYFileView *self = (GSEGYFileView*)data; GSEGYFileViewPrivate *private = G_SEGY_FILE_VIEW_GET_PRIVATE (self); private->first_sort_level_id = gtk_combo_box_get_active (combo_box); if (private->first_sort_level_id >= 0 && private->second_sort_level_id >= 0) gtk_widget_set_sensitive (private->add_view_button, TRUE);}static void g_segy_file_view_combo_two_changed_handler (GtkComboBox *combo_box, gpointer data) { GSEGYFileView *self = (GSEGYFileView*)data; GSEGYFileViewPrivate *private = G_SEGY_FILE_VIEW_GET_PRIVATE (self); private->second_sort_level_id = gtk_combo_box_get_active (combo_box); if (private->first_sort_level_id >= 0 && private->second_sort_level_id >= 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -