-
Notifications
You must be signed in to change notification settings - Fork 8
/
ufraw_chooser.c
174 lines (160 loc) · 6.85 KB
/
ufraw_chooser.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
* UFRaw - Unidentified Flying Raw converter for digital camera images
*
* ufraw_chooser.c - A very simple file chooser for UFRaw.
* Copyright 2004-2016 by Udi Fuchs
*
* 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.
*/
#include "ufraw.h"
#include "uf_gtk.h"
#include <string.h>
#include <glib/gi18n.h>
void ufraw_chooser_toggle(GtkToggleButton *button, GtkFileChooser *fileChooser)
{
gtk_file_chooser_set_show_hidden(fileChooser,
gtk_toggle_button_get_active(button));
}
/* Create a GtkFileChooser dialog for selecting raw files */
GtkFileChooser *ufraw_raw_chooser(conf_data *conf,
const char *defPath,
const gchar *label,
GtkWindow *toplevel,
const gchar *cancel,
gboolean multiple)
{
GtkFileChooser *fileChooser;
GtkFileFilter *filter;
char *cp;
char **extList, **l, ext[max_name];
fileChooser = GTK_FILE_CHOOSER(gtk_file_chooser_dialog_new(label, toplevel,
GTK_FILE_CHOOSER_ACTION_OPEN,
cancel, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL));
if (toplevel == NULL)
gtk_window_set_type_hint(GTK_WINDOW(fileChooser),
GDK_WINDOW_TYPE_HINT_NORMAL);
else
ufraw_focus(fileChooser, TRUE);
gtk_window_set_icon_name(GTK_WINDOW(fileChooser), "ufraw");
ufraw_message(UFRAW_SET_PARENT, (char *)fileChooser);
if (defPath != NULL) {
char *fullPath = uf_file_set_absolute(defPath);
gtk_file_chooser_set_current_folder(fileChooser, fullPath);
g_free(fullPath);
}
filter = GTK_FILE_FILTER(gtk_file_filter_new());
gtk_file_filter_set_name(filter, _("Raw images"));
extList = g_strsplit(raw_ext, ",", 100);
for (l = extList; *l != NULL; l++)
if (strcmp(*l, "jpeg") && strcmp(*l, "jpg") && strcmp(*l, "tif") &&
strcmp(*l, "tiff") && strcmp(*l, "ufraw")) {
snprintf(ext, max_name, "*.%s", *l);
gtk_file_filter_add_pattern(filter, ext);
gtk_file_filter_add_pattern(filter, cp = g_ascii_strup(ext, -1));
g_free(cp);
#ifdef HAVE_LIBZ
snprintf(ext, max_name, "*.%s.gz", *l);
gtk_file_filter_add_pattern(filter, ext);
snprintf(ext, max_name, "*.%s.GZ", *l);
gtk_file_filter_add_pattern(filter, ext);
snprintf(ext, max_name, "*.%s.gz", cp = g_ascii_strup(*l, -1));
g_free(cp);
gtk_file_filter_add_pattern(filter, ext);
snprintf(ext, max_name, "*.%s.GZ", cp = g_ascii_strup(*l, -1));
g_free(cp);
gtk_file_filter_add_pattern(filter, ext);
#endif
#ifdef HAVE_LIBBZ2
snprintf(ext, max_name, "*.%s.bz2", *l);
gtk_file_filter_add_pattern(filter, ext);
snprintf(ext, max_name, "*.%s.BZ2", *l);
gtk_file_filter_add_pattern(filter, ext);
snprintf(ext, max_name, "*.%s.bz2", cp = g_ascii_strup(*l, -1));
g_free(cp);
gtk_file_filter_add_pattern(filter, ext);
snprintf(ext, max_name, "*.%s.BZ2", cp = g_ascii_strup(*l, -1));
g_free(cp);
gtk_file_filter_add_pattern(filter, ext);
#endif
}
g_strfreev(extList);
gtk_file_chooser_add_filter(fileChooser, filter);
filter = GTK_FILE_FILTER(gtk_file_filter_new());
gtk_file_filter_set_name(filter, _("UFRaw ID files"));
gtk_file_filter_add_pattern(filter, "*.ufraw");
gtk_file_filter_add_pattern(filter, "*.UFRAW");
gtk_file_chooser_add_filter(fileChooser, filter);
filter = GTK_FILE_FILTER(gtk_file_filter_new());
gtk_file_filter_set_name(filter, _("Raw jpeg's"));
gtk_file_filter_add_pattern(filter, "*.jpeg");
gtk_file_filter_add_pattern(filter, "*.jpg");
gtk_file_filter_add_pattern(filter, "*.JPEG");
gtk_file_filter_add_pattern(filter, "*.JPG");
gtk_file_chooser_add_filter(fileChooser, filter);
filter = GTK_FILE_FILTER(gtk_file_filter_new());
gtk_file_filter_set_name(filter, _("Raw tiff's"));
gtk_file_filter_add_pattern(filter, "*.tif");
gtk_file_filter_add_pattern(filter, "*.tiff");
gtk_file_filter_add_pattern(filter, "*.TIF");
gtk_file_filter_add_pattern(filter, "*.TIFF");
gtk_file_chooser_add_filter(fileChooser, filter);
filter = GTK_FILE_FILTER(gtk_file_filter_new());
gtk_file_filter_set_name(filter, _("All files"));
gtk_file_filter_add_pattern(filter, "*");
gtk_file_chooser_add_filter(fileChooser, filter);
gtk_file_chooser_set_show_hidden(fileChooser, FALSE);
GtkWidget *button = gtk_check_button_new_with_label(_("Show hidden files"));
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), FALSE);
g_signal_connect(G_OBJECT(button), "toggled",
G_CALLBACK(ufraw_chooser_toggle), fileChooser);
gtk_file_chooser_set_extra_widget(fileChooser, button);
if (multiple)
gtk_file_chooser_set_select_multiple(fileChooser, TRUE);
/* Add shortcut to folder of last opened file */
if (strlen(conf->inputFilename) > 0) {
char *cp = g_path_get_dirname(conf->inputFilename);
gtk_file_chooser_add_shortcut_folder(fileChooser, cp, NULL);
g_free(cp);
}
gtk_widget_show(GTK_WIDGET(fileChooser));
return fileChooser;
}
void ufraw_chooser(conf_data *rc, conf_data *conf, conf_data *cmd,
const char *defPath)
{
ufraw_data *uf;
GtkFileChooser *fileChooser;
GSList *list, *saveList;
char *filename;
fileChooser = ufraw_raw_chooser(rc, defPath, "UFRaw", NULL,
GTK_STOCK_QUIT, TRUE);
while (gtk_dialog_run(GTK_DIALOG(fileChooser)) == GTK_RESPONSE_ACCEPT) {
for (list = saveList = gtk_file_chooser_get_filenames(fileChooser);
list != NULL; list = g_slist_next(list)) {
filename = list->data;
uf = ufraw_open(filename);
if (uf == NULL) {
ufraw_message(UFRAW_REPORT, NULL);
continue;
}
int status = ufraw_config(uf, rc, conf, cmd);
if (status == UFRAW_ERROR) {
ufraw_close_darkframe(uf->conf);
ufraw_close(uf);
} else {
ufraw_preview(uf, rc, FALSE, NULL);
}
g_free(uf);
g_free(filename);
}
g_slist_free(saveList);
}
if (rc->darkframe != NULL)
ufraw_close_darkframe(rc);
gtk_widget_destroy(GTK_WIDGET(fileChooser));
ufraw_message(UFRAW_SET_PARENT, NULL);
}