Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
film_gui.c
Go to the documentation of this file.
1/*
2 * This file is part of darktable,
3 * Copyright (C) 2016 johannes hanika.
4 * Copyright (C) 2016, 2020 Tobias Ellinghaus.
5 * Copyright (C) 2020 Pascal Obry.
6 * Copyright (C) 2021 Sakari Kapanen.
7 * Copyright (C) 2022 Martin Baƙinka.
8 *
9 * darktable is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * darktable is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with darktable. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23
24#include "gui/common/film_gui.h"
25
26#include "common/film.h"
27#include "control/signal.h"
28#include "system/mem_alloc.h"
29#include "gui/application.h"
30
31#include <glib/gi18n.h>
32#include <gtk/gtk.h>
35
36#ifdef GDK_WINDOWING_QUARTZ
37#include "osx/osx.h"
38#endif
39
40/* Runs on the GUI thread via g_idle_add(): dt_film_remove_empty() is reached from worker
41 * threads, and gtk_dialog_run() must not be. Takes ownership of the list. */
42static gboolean _ask_and_delete(gpointer user_data)
43{
44 GList *empty_dirs = (GList *)user_data;
45 const int n_empty_dirs = g_list_length(empty_dirs);
46
48 GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(win), GTK_DIALOG_DESTROY_WITH_PARENT,
49 GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
50 ngettext("do you want to remove this empty directory?",
51 "do you want to remove these empty directories?",
52 n_empty_dirs));
53#ifdef GDK_WINDOWING_QUARTZ
55#endif
56
57 gtk_window_set_title(GTK_WINDOW(dialog),
58 ngettext("remove empty directory?", "remove empty directories?", n_empty_dirs));
59
60 GtkWidget *content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
61
62 GtkWidget *scroll = gtk_scrolled_window_new(NULL, NULL);
63 gtk_widget_set_vexpand(scroll, TRUE);
64 dt_gui_add_class(scroll, "dt_recessed_scroll");
65
66 GtkListStore *store = gtk_list_store_new(1, G_TYPE_STRING);
67
68 for(GList *list_iter = empty_dirs; list_iter; list_iter = g_list_next(list_iter))
69 {
70 GtkTreeIter iter;
71 gtk_list_store_append(store, &iter);
72 gtk_list_store_set(store, &iter, 0, list_iter->data, -1);
73 }
74
75 GtkWidget *tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
76 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree), FALSE);
77 gtk_widget_set_name(GTK_WIDGET(tree), "delete-dialog");
78 GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes(_("name"), gtk_cell_renderer_text_new(),
79 "text", 0, NULL);
80 gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
81
82 gtk_container_add(GTK_CONTAINER(scroll), tree);
83 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
84 gtk_scrolled_window_set_min_content_height(GTK_SCROLLED_WINDOW(scroll), DT_PIXEL_APPLY_DPI(25));
85
86 gtk_container_add(GTK_CONTAINER(content_area), scroll);
87
88 gtk_widget_show_all(dialog); // needed for the content area!
89
90 const gint res = gtk_dialog_run(GTK_DIALOG(dialog));
91 gtk_widget_destroy(dialog);
92
93 // The deleting itself is the backend's job; this module only obtained consent.
94 if(res == GTK_RESPONSE_YES) dt_film_remove_directories(empty_dirs);
95
96 g_list_free_full(empty_dirs, dt_free_gpointer);
97 g_object_unref(store);
98
99 return FALSE;
100}
101
102static void _confirm_rmdir(GList *empty_dirs)
103{
104 // defer to the GUI thread; ownership travels with the list
105 g_idle_add(_ask_and_delete, empty_dirs);
106}
107
108/* The backend states the fact; the signal is how this application distributes it. Raised on
109 * whichever thread changed the rolls, same as the emission this replaces -- the Library
110 * panel's handler is what marshals itself onto the GUI thread. */
115
121
122// clang-format off
123// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
124// vim: shiftwidth=2 expandtab tabstop=2 cindent
125// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
126// clang-format on
GtkWidget * dt_gui_main_window(void)
#define TRUE
Definition ashift_lsd.c:162
#define FALSE
Definition ashift_lsd.c:158
struct _GtkWidget GtkWidget
GtkWidget, opaque, spelled exactly as GTK spells it.
Definition colorspaces.h:98
GtkTreeStore * store
its model, owned by the view
const int res
Definition dtpthread.h:351
void dt_film_set_rolls_changed_handler(dt_film_rolls_changed_handler_t handler)
Install the handler, or NULL to remove it.
Definition film.c:242
void dt_film_remove_directories(const GList *dirs)
Definition film.c:253
void dt_film_set_confirm_rmdir_handler(dt_film_confirm_rmdir_handler_t handler)
Definition film.c:233
static void _confirm_rmdir(GList *empty_dirs)
Definition film_gui.c:102
static gboolean _ask_and_delete(gpointer user_data)
Definition film_gui.c:42
void dt_film_gui_register_handlers(void)
Definition film_gui.c:116
static void _rolls_changed(void)
Definition film_gui.c:111
static void dt_free_gpointer(gpointer ptr)
g_free() one pointer, with the signature GDestroyNotify wants.
Definition mem_alloc.h:184
void dt_osx_disallow_fullscreen(GtkWidget *widget)
Definition osx.mm:105
#define DT_DEBUG_CONTROL_SIGNAL_RAISE(ctlsig, signal,...)
Definition signal.h:390
struct dt_control_signal_t * dt_control_signal_get_global(void)
Definition darktable.c:619
@ DT_SIGNAL_FILMROLLS_CHANGED
This signal is raised when a filmroll is deleted/changed but not imported.
Definition signal.h:160
#define DT_PIXEL_APPLY_DPI(value)
void dt_gui_add_class(GtkWidget *widget, const gchar *class_name)