1 
2 /*
3  * The Real SoundTracker - User activity history (header)
4  *
5  * Copyright (C) 2019, 2020 Yury Aliaev
6  * Copyright (C) 1998-2019 Michael Krause
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  */
22 
23 #include <gtk/gtk.h>
24 
25 typedef enum {
26     HISTORY_ACTION_POINTER,
27     HISTORY_ACTION_POINTER_NOFREE, /* Don't free argument on history record removal */
28     HISTORY_ACTION_INT
29 } HistoryActionType;
30 
31 typedef enum {
32     HISTORY_STATUS_OK,
33     HISTORY_STATUS_COLLATED,
34     HISTORY_STATUS_NOMEM
35 } HistoryStatus;
36 
37 enum {
38     HISTORY_FLAG_COLLATABLE = 1 << 8, /* 8 lowest bits for parameter given through flags */
39     HISTORY_FLAG_LOG_PAGE = 1 << 9,
40     HISTORY_FLAG_LOG_INS = 1 << 10,
41     HISTORY_FLAG_LOG_SMP = 1 << 11,
42     HISTORY_FLAG_LOG_POS = 1 << 12,
43     HISTORY_FLAG_LOG_PAT = 1 << 13,
44     HISTORY_FLAG_FORCE_PAT = 1 << 14, /* Mutually exclusive with _FORCE_PAGE */
45     HISTORY_FLAG_FORCE_PAGE = 1 << 15
46 };
47 
48 #define HISTORY_FLAG_LOG_ALL (HISTORY_FLAG_LOG_PAGE | HISTORY_FLAG_LOG_INS | HISTORY_FLAG_LOG_SMP)
49 #define HISTORY_SET_PAGE(page) (HISTORY_FLAG_FORCE_PAGE | page)
50 #define HISTORY_SET_PAT(pat) (HISTORY_FLAG_FORCE_PAT | pat)
51 /* Extra flags can be used for distinguishing between similarly looking actions */
52 #define HISTORY_EXTRA_FLAGS_MASK 0xffff0000
53 #define HISTORY_FLAG_PARAMETER_MASK 0xff
54 #define HISTORY_EXTRA_FLAGS(flags) (flags << 16)
55 
56 extern gboolean history_skip;
57 
58 void history_init(GtkBuilder* bd);
59 void history_clear(const gboolean set_modified);
60 void history_save(void);
61 gboolean history_get_modified(void);
62 gboolean history_check_size(gsize size);
63 gboolean _history_query_irreversible(GtkWidget *parent, const gchar* message);
64 
65 static inline gboolean
history_query_oversized(GtkWidget * parent)66 history_query_oversized(GtkWidget *parent) {
67     return _history_query_irreversible(parent,
68         N_("The operation requres too much memory.\nYou will not be able to undo it.\n"
69            "Do you want to continue?"));
70 }
71 
72 static inline gboolean
history_query_irreversible(GtkWidget * parent)73 history_query_irreversible(GtkWidget *parent) {
74     return _history_query_irreversible(parent,
75         N_("You are about to do some irreversible action.\nYou will not be able to undo it.\n"
76            "Do you want to continue?"));
77 }
78 
79 /* Checks if the specified action can be collated with the previous logged one */
80 gboolean history_test_collate(HistoryActionType type,
81     const gint flags,
82     gpointer data);
83 
84 HistoryStatus history_log_action_full(HistoryActionType type,
85     const gchar* title,
86     const gint flags,
87     void (*undo_func)(const gint ins, const gint smp, const gboolean redo,
88         gpointer arg, gpointer data),
89     void (*cleanup_func)(gpointer arg),
90     gpointer data,
91     gsize arg_size, ...); /* The last argument can have various type */
92 #define history_log_action(type, title, flags, undo_func, data, arg_size, arg)\
93     history_log_action_full(type, title, flags, undo_func, NULL, data, arg_size, arg)
94 
95 /* Convenience function for most common actions */
96 void history_log_spin_button(GtkSpinButton* sb,
97     const gchar* title,
98     const gint flags, /* Collatable is ignored (always TRUE) */
99     const gint prev_value);
100 
101 void history_log_entry(GtkEntry* en,
102     const gchar* title,
103     const gint maxlen,
104     const gint flags, /* Also always collatable */
105     const gchar* prev_value);
106 
107 void history_log_toggle_button(GtkToggleButton* tb,
108     const gchar* title,
109     const gint flags,
110     const gboolean prev_value);
111 
112 void history_log_radio_group(GtkWidget** group,
113     const gchar* title,
114     const gint flags,
115     const gint prev_value,
116     const gint number);
117