1 #ifndef OPTSDBUS_H
2 #define OPTSDBUS_H
3 /*
4     roxterm - VTE/GTK terminal emulator with tabs
5     Copyright (C) 2004-2015 Tony Houghton <h@realh.co.uk>
6 
7     This program 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 2 of the License, or
10     (at your option) any later version.
11 
12     This program 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 this program; if not, write to the Free Software
19     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 */
21 
22 
23 /* ROXTerm's interface to dbus */
24 
25 #include "rtdbus.h"
26 
27 /* A ROXTerm D-BUS option consists of:
28  * Profile name (including "Profiles/", "Colours/" etc)
29  * Option key
30  * Option value (string or int)
31  */
32 
33 /* Possible values for what_happened in optsdbus_send_stuff_changed_signal */
34 #define OPTSDBUS_DELETED "OptionsDeleted"
35 #define OPTSDBUS_ADDED "OptionsAdded"
36 #define OPTSDBUS_RENAMED "OptionsRenamed"
37 #define OPTSDBUS_CHANGED "OptionsChanged"
38 
39 #ifdef ROXTERM_CAPPLET
40 
41 gboolean optsdbus_init(void);
42 
43 gboolean optsdbus_send_string_opt_signal(const char *profile_name,
44 	const char *key, const char *value);
45 
46 gboolean optsdbus_send_int_opt_signal(const char *profile_name,
47 	const char *key, int value);
48 
49 gboolean optsdbus_send_float_opt_signal(const char *profile_name,
50 	const char *key, double value);
51 
52 /* new_name may be NULL if not a rename operation */
53 gboolean optsdbus_send_stuff_changed_signal(const char *what_happened,
54 		const char *family_name, const char *current_name,
55 		const char *new_name);
56 
57 #else /* !ROXTERM_CAPPLET */
58 
59 typedef enum {
60 	OptsDBus_InvalidOpt,
61 	OptsDBus_StringOpt,
62 	OptsDBus_IntOpt,
63 	OptsDBus_FloatOpt
64 } OptsDBusOptType;
65 
66 typedef union {
67 	const char *s;
68 	int i;
69 	double f;
70 } OptsDBusValue;
71 
72 /* profile_name includes "Profiles/", "Colours/" etc.
73  * Only one of str_val or int_val will be valid at a time. */
74 typedef void (*OptsDBusOptionHandler) (const char *profile_name,
75 	const char *key, OptsDBusOptType, OptsDBusValue);
76 
77 void optsdbus_listen_for_opt_signals(OptsDBusOptionHandler handler);
78 
79 /* new_name is NULL if what_happened isn't rename */
80 typedef void (*OptsDBusStuffChangedHandler)(const char *what_happened,
81 		const char *family_name, const char *current_name,
82 		const char *new_name);
83 
84 void optsdbus_listen_for_stuff_changed_signals(
85 		OptsDBusStuffChangedHandler handler);
86 
87 typedef void (*OptsDBusSetProfileHandler)(void *roxterm_id,
88         const char *profile_name);
89 
90 void optsdbus_listen_for_set_profile_signals(OptsDBusSetProfileHandler);
91 void optsdbus_listen_for_set_colour_scheme_signals(OptsDBusSetProfileHandler);
92 void optsdbus_listen_for_set_shortcut_scheme_signals(OptsDBusSetProfileHandler);
93 
94 #endif /* !ROXTERM_CAPPLET */
95 
96 /* In capplet this sends a D-BUS message to another instance; in terminal
97  * it starts a new instance of the capplet which will either forward the
98  * message to a previous instance or handle it itself. */
99 gboolean optsdbus_send_edit_opts_message(const char *method, const char *arg);
100 
101 inline static gboolean
optsdbus_send_edit_profile_message(const char * profile_name)102 optsdbus_send_edit_profile_message(const char *profile_name)
103 {
104 	return optsdbus_send_edit_opts_message("EditProfile", profile_name);
105 }
106 
107 inline static gboolean
optsdbus_send_edit_colour_scheme_message(const char * profile_name)108 optsdbus_send_edit_colour_scheme_message(const char *profile_name)
109 {
110 	return optsdbus_send_edit_opts_message("EditColourScheme", profile_name);
111 }
112 
113 #endif /* OPTSDBUS_H */
114 
115 /* vi:set sw=4 ts=4 noet cindent cino= */
116