Add postprocessor setting dropdown (MR 18)

This commit is contained in:
Martijn Braam
2022-06-24 14:53:30 +02:00
parent 46b07c6c4d
commit ee26b8e6f7
4 changed files with 126 additions and 17 deletions

View File

@@ -1,6 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<interface> <interface>
<requires lib="gtk" version="4.0"/> <requires lib="gtk" version="4.0"/>
<object class="GtkListStore" id="list-postprocessors">
<columns>
<column type="gchararray"/>
<column type="gchararray"/>
</columns>
</object>
<object class="GtkWindow" id="window"> <object class="GtkWindow" id="window">
<property name="can-focus">0</property> <property name="can-focus">0</property>
<property name="default-width">360</property> <property name="default-width">360</property>
@@ -247,6 +253,27 @@
</child> </child>
</object> </object>
</child> </child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="halign">start</property>
<property name="label">Postprocessor</property>
</object>
</child>
<child>
<object class="GtkComboBox" id="setting-processor">
<property name="visible">True</property>
<property name="model">list-postprocessors</property>
<property name="entry-text-column">1</property>
<property name="id-column">0</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
</child>
<child> <child>
<object class="GtkCheckButton" id="setting-raw"> <object class="GtkCheckButton" id="setting-raw">
<property name="label">Save raw files</property> <property name="label">Save raw files</property>

View File

@@ -1001,6 +1001,10 @@ activate(GtkApplication *app, gpointer data)
GTK_WIDGET(gtk_builder_get_object(builder, "flash-controls-button")); GTK_WIDGET(gtk_builder_get_object(builder, "flash-controls-button"));
GtkWidget *setting_dng_button = GtkWidget *setting_dng_button =
GTK_WIDGET(gtk_builder_get_object(builder, "setting-raw")); GTK_WIDGET(gtk_builder_get_object(builder, "setting-raw"));
GtkWidget *setting_postprocessor_combo =
GTK_WIDGET(gtk_builder_get_object(builder, "setting-processor"));
GtkListStore *setting_postprocessor_list = GTK_LIST_STORE(
gtk_builder_get_object(builder, "list-postprocessors"));
preview = GTK_WIDGET(gtk_builder_get_object(builder, "preview")); preview = GTK_WIDGET(gtk_builder_get_object(builder, "preview"));
main_stack = GTK_WIDGET(gtk_builder_get_object(builder, "main_stack")); main_stack = GTK_WIDGET(gtk_builder_get_object(builder, "main_stack"));
open_last_stack = open_last_stack =
@@ -1050,26 +1054,35 @@ activate(GtkApplication *app, gpointer data)
// Setup settings // Setup settings
settings = g_settings_new("org.postmarketos.Megapixels"); settings = g_settings_new("org.postmarketos.Megapixels");
char* setting_postproc = g_settings_get_string(settings, "postprocessor"); char *setting_postproc = g_settings_get_string(settings, "postprocessor");
// Initialize the postprocessing gsetting to the old processor if // Initialize the postprocessing gsetting to the old processor if
// it was not set yet // it was not set yet
if(setting_postproc == NULL || setting_postproc[0] == '\0') { if (setting_postproc == NULL || setting_postproc[0] == '\0') {
printf("Initializing postprocessor gsetting\n"); printf("Initializing postprocessor gsetting\n");
setting_postproc = malloc(512); setting_postproc = malloc(512);
if(!mp_process_find_processor(setting_postproc)) { if (!mp_process_find_processor(setting_postproc)) {
printf("No processor found\n"); printf("No processor found\n");
exit(1); exit(1);
} }
g_settings_set_string(settings, "postprocessor", setting_postproc); g_settings_set_string(settings, "postprocessor", setting_postproc);
printf("Initialized postprocessor to %s\n", setting_postproc); printf("Initialized postprocessor to %s\n", setting_postproc);
} }
// Find all postprocessors for the settings list
mp_process_find_all_processors(setting_postprocessor_list);
// Bind settings widgets to the actual settings
g_settings_bind(settings, g_settings_bind(settings,
"save-raw", "save-raw",
setting_dng_button, setting_dng_button,
"active", "active",
G_SETTINGS_BIND_DEFAULT); G_SETTINGS_BIND_DEFAULT);
g_settings_bind(settings,
"postprocessor",
setting_postprocessor_combo,
"active-id",
G_SETTINGS_BIND_DEFAULT);
// Listen for phosh rotation // Listen for phosh rotation
GDBusConnection *conn = GDBusConnection *conn =

View File

@@ -76,6 +76,73 @@ register_custom_tiff_tags(TIFF *tif)
sizeof(custom_fields) / sizeof(custom_fields[0])); sizeof(custom_fields) / sizeof(custom_fields[0]));
} }
void
mp_process_find_all_processors(GtkListStore *store)
{
GtkTreeIter iter;
char buffer[512];
// Find all the original postprocess.sh locations
// Check postprocess.sh in the current working directory
if (access("./data/postprocess.sh", F_OK) != -1) {
gtk_list_store_insert(store, &iter, -1);
gtk_list_store_set(store,
&iter,
0,
"./data/postprocess.sh",
1,
"(cwd) postprocess.sh",
-1);
}
// Check for a script in XDG_CONFIG_HOME
sprintf(buffer, "%s/megapixels/postprocess.sh", g_get_user_config_dir());
if (access(buffer, F_OK) != -1) {
gtk_list_store_insert(store, &iter, -1);
gtk_list_store_set(
store, &iter, 0, buffer, 1, "(user) postprocess.sh", -1);
}
// Check user overridden /etc/megapixels/postprocessor.sh
sprintf(buffer, "%s/megapixels/postprocess.sh", SYSCONFDIR);
if (access(buffer, F_OK) != -1) {
gtk_list_store_insert(store, &iter, -1);
gtk_list_store_set(
store, &iter, 0, buffer, 1, "(system) postprocess.sh", -1);
}
// Check user overridden /usr/share/megapixels/postprocessor.sh
sprintf(buffer, "%s/megapixels/postprocess.sh", DATADIR);
if (access(buffer, F_OK) != -1) {
gtk_list_store_insert(store, &iter, -1);
gtk_list_store_set(
store, &iter, 0, buffer, 1, "(built-in) postprocess.sh", -1);
}
// Find extra packaged postprocessor scripts
// These should be packaged in
// /usr/share/megapixels/postprocessor.d/executable
sprintf(buffer, "%s/megapixels/postprocessor.d", DATADIR);
DIR *d;
struct dirent *dir;
d = opendir(buffer);
if (d) {
while ((dir = readdir(d)) != NULL) {
if (dir->d_name[0] == '.') {
continue;
}
sprintf(buffer,
"%s/megapixels/postprocessor.d/%s",
DATADIR,
dir->d_name);
gtk_list_store_insert(store, &iter, -1);
gtk_list_store_set(
store, &iter, 0, buffer, 1, dir->d_name, -1);
}
closedir(d);
}
}
bool bool
mp_process_find_processor(char *script) mp_process_find_processor(char *script)
{ {
@@ -117,7 +184,7 @@ static void
setup(MPPipeline *pipeline, const void *data) setup(MPPipeline *pipeline, const void *data)
{ {
TIFFSetTagExtender(register_custom_tiff_tags); TIFFSetTagExtender(register_custom_tiff_tags);
settings = g_settings_new("org.postmarketos.Megapixels"); settings = g_settings_new("org.postmarketos.Megapixels");
} }
void void
@@ -650,8 +717,8 @@ process_capture_burst(GdkTexture *thumb)
timestamp); timestamp);
} }
bool save_dng = g_settings_get_boolean(settings, "save-raw"); bool save_dng = g_settings_get_boolean(settings, "save-raw");
char* postprocessor = g_settings_get_string(settings, "postprocessor"); char *postprocessor = g_settings_get_string(settings, "postprocessor");
char save_dng_s[2] = "0"; char save_dng_s[2] = "0";
if (save_dng) { if (save_dng) {

View File

@@ -2,6 +2,7 @@
#include "camera.h" #include "camera.h"
#include "camera_config.h" #include "camera_config.h"
#include <gtk/gtk.h>
typedef struct _GdkSurface GdkSurface; typedef struct _GdkSurface GdkSurface;
@@ -30,6 +31,7 @@ struct mp_process_pipeline_state {
}; };
bool mp_process_find_processor(char *script); bool mp_process_find_processor(char *script);
void mp_process_find_all_processors(GtkListStore *store);
void mp_process_pipeline_start(); void mp_process_pipeline_start();
void mp_process_pipeline_stop(); void mp_process_pipeline_stop();