1 /*
2  * This file is part of Siril, an astronomy image processor.
3  * Copyright (C) 2005-2011 Francois Meyer (dulle at free.fr)
4  * Copyright (C) 2012-2021 team free-astro (see more in AUTHORS file)
5  * Reference site is https://free-astro.org/index.php/Siril
6  *
7  * Siril is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * Siril is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with Siril. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include "core/siril.h"
22 #include "core/proto.h"
23 #include "gui/utils.h"
24 #include "gui/histogram.h"
25 #include "filters/asinh.h"
26 #include "filters/deconv.h"
27 #include "filters/clahe.h"
28 #include "filters/saturation.h"
29 #include "filters/wavelets.h"
30 
31 #include "gui/dialogs.h"
32 
33 static const SirilDialogEntry entries[] =
34 {
35 		{"asinh_dialog", IMAGE_PROCESSING_DIALOG, TRUE, apply_asinh_cancel},
36 		{"background_extraction_dialog", IMAGE_PROCESSING_DIALOG, FALSE, NULL},
37 		{"canon_fixbanding_dialog", IMAGE_PROCESSING_DIALOG, FALSE, NULL},
38 		{"CLAHE_dialog", IMAGE_PROCESSING_DIALOG, TRUE, apply_clahe_cancel},
39 		{"composition_dialog", IMAGE_PROCESSING_DIALOG, FALSE, NULL},
40 		{"color_calibration", IMAGE_PROCESSING_DIALOG, FALSE, NULL},
41 		{"cosmetic_dialog", IMAGE_PROCESSING_DIALOG, FALSE, NULL},
42 		{"crop_dialog", IMAGE_PROCESSING_DIALOG, FALSE, NULL},
43 		{"deconvolution_dialog", IMAGE_PROCESSING_DIALOG, TRUE, apply_deconv_cancel},
44 		{"dialog_FFT", IMAGE_PROCESSING_DIALOG, FALSE, NULL},
45 		{"extract_channel_dialog", OTHER_DIALOG, FALSE, NULL},
46 		{"extract_wavelets_layers_dialog", OTHER_DIALOG, FALSE, NULL},
47 		{"file_information", INFORMATION_DIALOG, FALSE, NULL},
48 		{"histogram_dialog", IMAGE_PROCESSING_DIALOG, TRUE, apply_histo_cancel},
49 		{"ImagePlateSolver_Dial", IMAGE_PROCESSING_DIALOG, FALSE, NULL},
50 		{"linearmatch_dialog", IMAGE_PROCESSING_DIALOG, FALSE, NULL},
51 		{"Median_dialog", IMAGE_PROCESSING_DIALOG, FALSE, NULL},
52 		{"resample_dialog", IMAGE_PROCESSING_DIALOG, FALSE, NULL},
53 		{"rgradient_dialog", IMAGE_PROCESSING_DIALOG, FALSE, NULL},
54 		{"rotation_dialog", IMAGE_PROCESSING_DIALOG, FALSE, NULL},
55 		{"satu_dialog", IMAGE_PROCESSING_DIALOG, TRUE, apply_satu_cancel},
56 		{"SCNR_dialog", IMAGE_PROCESSING_DIALOG,  FALSE, NULL},
57 		{"search_objects", SEARCH_ENTRY_DIALOG, FALSE, NULL},
58 		{"settings_window", INFORMATION_DIALOG, FALSE, NULL},
59 		{"seqlist_dialog", INFORMATION_DIALOG, FALSE, NULL},
60 		{"split_cfa_dialog", OTHER_DIALOG, FALSE, NULL},
61 		{"stars_list_window", INFORMATION_DIALOG, FALSE, NULL},
62 		{"StatWindow", INFORMATION_DIALOG, FALSE, NULL},
63 		{"wavelets_dialog", IMAGE_PROCESSING_DIALOG, TRUE, apply_wavelets_cancel}
64 };
65 
get_entry_by_id(gchar * id)66 static SirilDialogEntry get_entry_by_id(gchar *id) {
67 	int i;
68 	SirilDialogEntry retvalue = {NULL, NO_DIALOG, FALSE, NULL};
69 
70 	for (i = 0; i < G_N_ELEMENTS(entries); i++) {
71 		if (!g_ascii_strcasecmp(id, entries[i].identifier)) {
72 			return entries[i];
73 		}
74 	}
75 	return retvalue;
76 }
77 
check_escape(GtkWidget * widget,GdkEventKey * event,gpointer data)78 static gboolean check_escape(GtkWidget *widget, GdkEventKey *event,
79 		gpointer data) {
80 	if (event->keyval == GDK_KEY_Escape) {
81 		gtk_widget_hide(widget);
82 		return TRUE;
83 	}
84 	return FALSE;
85 }
86 
siril_open_dialog(gchar * id)87 void siril_open_dialog(gchar *id) {
88 	int i;
89 	gint x, y;
90 	gboolean win_already_shown = FALSE;
91 	GtkWindow *win = GTK_WINDOW(gtk_builder_get_object(builder, id));
92 
93 	if (get_entry_by_id(id).type != INFORMATION_DIALOG) {
94 		for (i = 0; i < G_N_ELEMENTS(entries); i++) {
95 			GtkWidget *w = lookup_widget(entries[i].identifier);
96 			if (gtk_widget_get_visible(w) && entries[i].type != INFORMATION_DIALOG) {
97 				win_already_shown = TRUE;
98 				gtk_window_get_position(GTK_WINDOW(w), &x, &y);
99 				if (entries[i].has_preview)
100 					entries[i].apply_function();
101 				gtk_widget_hide(w);
102 				break;
103 			}
104 		}
105 	}
106 	if (get_entry_by_id(id).type == SEARCH_ENTRY_DIALOG) {
107 		g_signal_connect(win, "key_press_event", G_CALLBACK(check_escape), NULL);
108 	}
109 
110 	if (win_already_shown && x >= 0 && y >= 0) {
111 		gtk_window_move(win, x, y);
112 	} else {
113 		gtk_window_set_position(win, GTK_WIN_POS_CENTER);
114 	}
115 	gtk_window_set_type_hint(win, GDK_WINDOW_TYPE_HINT_DIALOG);
116 	gtk_window_set_transient_for(win, GTK_WINDOW(GTK_APPLICATION_WINDOW(lookup_widget("control_window"))));
117 	gtk_window_present_with_time(win, GDK_CURRENT_TIME);
118 }
119 
siril_close_dialog(gchar * id)120 void siril_close_dialog(gchar *id) {
121 	gtk_widget_hide(lookup_widget(id));
122 }
123 
siril_close_preview_dialogs()124 void siril_close_preview_dialogs() {
125 	for (int i = 0; i < G_N_ELEMENTS(entries); i++) {
126 		GtkWidget *w = lookup_widget(entries[i].identifier);
127 		if (gtk_widget_get_visible(w) && (entries[i].has_preview)) {
128 			entries[i].apply_function();
129 			gtk_widget_hide(w);
130 		}
131 	}
132 }
133