Skip to content

Commit 116f89f

Browse files
committed
Implement configuration profiles
All instances of lxterminal invoked with the same --profile=NAME argument will share one configuration file (lxterminal-NAME.conf) and one socket. Based on pull request #128 by foxharp.
1 parent b4a2026 commit 116f89f

9 files changed

+52
-19
lines changed

man/lxterminal.1

+6-1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ Set the terminal\*(Aqs title\&. Use comma for multiple tabs\&.
7777
.RS 4
7878
Set the terminal\*(Aqs working directory\&.
7979
.RE
80+
.PP
81+
\fB\-\-profile=\fR\fB\fINAME\fR\fR
82+
.RS 4
83+
If set, then all instances of lxterminal invoked in the same way will share a config file named lxterminal\-NAME\&.conf\&.
84+
.RE
8085
.SH "AUTHOR"
8186
.PP
8287
This manual page was written by paulliu
@@ -90,7 +95,7 @@ General Public License, Version 2 any later version published by the Free Softwa
9095
On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common\-licenses/GPL\&.
9196
.SH "FILES"
9297
.PP
93-
The configuration file can be found in ~/\&.config/lxterminal/lxterminal\&.conf\&.
98+
The configuration file lxterminal\&.conf (or lxterminal\-NAME\&.conf) can be found in ~/\&.config/lxterminal/\&.
9499
.SH "AUTHOR"
95100
.PP
96101
\fBYing\-Chun Liu\fR

man/lxterminal.xml

+11-1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ Except in the <option>--command=</option> form, this must be the last option on
8585
<listitem> <para>Set the terminal's working directory.</para>
8686
</listitem>
8787
</varlistentry>
88+
<varlistentry>
89+
<term>
90+
<option>--profile=<replaceable>NAME</replaceable></option>
91+
</term>
92+
<listitem>
93+
<para>If set, then all instances of lxterminal invoked in the same way will
94+
share a config file named lxterminal-NAME.conf.
95+
</para>
96+
</listitem>
97+
</varlistentry>
8898
</variablelist>
8999
</refsect1>
90100

@@ -104,6 +114,6 @@ Except in the <option>--command=</option> form, this must be the last option on
104114

105115
<refsect1> <title>FILES</title>
106116

107-
<para>The configuration file can be found in ~/.config/lxterminal/lxterminal.conf.</para>
117+
<para>The configuration file lxterminal.conf (or lxterminal-NAME.conf) can be found in ~/.config/lxterminal/.</para>
108118

109119
</refsect1></refentry>

src/lxterminal.c

+12-2
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ static gchar usage_display[] = {
120120
" --tabs=NAME[,NAME[,NAME[...]]] Set the terminal's title\n"
121121
" --working-directory=DIRECTORY Set the terminal's working directory\n"
122122
" --no-remote Do not accept or send remote commands\n"
123+
" --profile=NAME Use a separate configuration profile\n"
123124
" -v, --version Version information\n"
124125
};
125126

@@ -863,6 +864,8 @@ static void terminal_window_exit(LXTerminal * terminal, GObject * where_the_obje
863864
{
864865
LXTermWindow * lxtermwin = terminal->parent;
865866

867+
g_free(terminal->profile);
868+
866869
/* If last window, exit main loop. */
867870
if (lxtermwin->windows->len == 1) {
868871
gtk_main_quit();
@@ -1541,6 +1544,12 @@ gboolean lxterminal_process_arguments(gint argc, gchar * * argv, CommandArgument
15411544
arguments->working_directory = &argument[20];
15421545
}
15431546

1547+
/* --profile=<config-identifier> */
1548+
else if (strncmp(argument, "--profile=", 10) == 0)
1549+
{
1550+
arguments->profile = &argument[10];
1551+
}
1552+
15441553
/* --no-remote: Do not accept or send remote commands */
15451554
else if (strcmp(argument, "--no-remote") == 0) {
15461555
arguments->no_remote = TRUE;
@@ -1619,6 +1628,7 @@ LXTerminal * lxterminal_initialize(LXTermWindow * lxtermwin, CommandArguments *
16191628
g_ptr_array_add(lxtermwin->windows, terminal);
16201629
terminal->index = terminal->parent->windows->len - 1;
16211630
terminal->scale = 1.0;
1631+
terminal->profile = g_strdup(arguments->profile);
16221632
Setting * setting = get_setting();
16231633

16241634
/* Create toplevel window. */
@@ -1941,11 +1951,11 @@ int main(gint argc, gchar * * argv)
19411951
LXTermWindow * lxtermwin = g_slice_new0(LXTermWindow);
19421952

19431953
/* Initialize socket. If we were able to get another LXTerminal to manage the window, exit. */
1944-
if (!arguments.no_remote && !lxterminal_socket_initialize(lxtermwin, argc, argv))
1954+
if (!arguments.no_remote && !lxterminal_socket_initialize(lxtermwin, arguments.profile, argc, argv))
19451955
return 0;
19461956

19471957
/* Load user preferences. */
1948-
load_setting();
1958+
load_setting(arguments.profile);
19491959

19501960
/* Finish initializing the impure area and start the first LXTerminal. */
19511961
lxtermwin->windows = g_ptr_array_new();

src/lxterminal.h

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ typedef struct _lxterminal {
5555
gdouble scale; /* Terminal scale */
5656
glong col; /* Saved horizontal size */
5757
glong row; /* Saved vertical size */
58+
gchar *profile; /* Configuration profile */
5859
} LXTerminal;
5960

6061
/* Representative of a tab within a toplevel window. */
@@ -87,6 +88,7 @@ typedef struct _command_arguments {
8788
char * title; /* Value of -t, -T, --title; points into argument vector */
8889
char * tabs; /* Value of --tab; points into argument vector */
8990
char * working_directory; /* Value of --working-directory; points into argument vector */
91+
char * profile; /* Value of --profile; points into argument vector */
9092
gboolean login_shell; /* Terminal will spawn login shells */
9193
gboolean no_remote;
9294
} CommandArguments;

src/preferences.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ void terminal_preferences_dialog(GtkAction * action, LXTerminal * terminal)
492492
if (result == GTK_RESPONSE_OK)
493493
{
494494
set_setting(setting);
495-
save_setting();
495+
save_setting(terminal->profile);
496496
terminal_settings_apply_to_all(terminal);
497497
}
498498
else

src/setting.c

+9-5
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ void set_setting(Setting * new_setting)
179179
}
180180

181181
/* Save settings to configuration file. */
182-
void save_setting()
182+
void save_setting(const char *profile)
183183
{
184184
int i;
185185
g_return_if_fail (setting != NULL);
@@ -258,7 +258,8 @@ void save_setting()
258258

259259
/* Convert GKeyFile to text and build path to configuration file. */
260260
gchar * file_data = g_key_file_to_data(setting->keyfile, NULL, NULL);
261-
gchar * config_path = g_build_filename(g_get_user_config_dir(), "lxterminal/lxterminal.conf", NULL);
261+
gchar * config_filename = g_strdup_printf("lxterminal%s%s.conf", profile ? "-" : "", profile ? profile : "");
262+
gchar * config_path = g_build_filename(g_get_user_config_dir(), "lxterminal", config_filename, NULL);
262263

263264
if ((file_data != NULL) && (config_path != NULL))
264265
{
@@ -279,6 +280,7 @@ void save_setting()
279280
/* Deallocate memory. */
280281
g_free(file_data);
281282
g_free(config_path);
283+
g_free(config_filename);
282284
}
283285

284286
/* Deep copy settings. */
@@ -338,13 +340,15 @@ void free_setting(Setting ** setting)
338340
}
339341

340342
/* Load settings from configuration file. */
341-
Setting * load_setting()
343+
Setting * load_setting(const char * profile)
342344
{
343345
int i;
344346
gchar * dir = g_build_filename(g_get_user_config_dir(), "lxterminal" , NULL);
345347
g_mkdir_with_parents(dir, S_IRUSR | S_IWUSR | S_IXUSR);
346-
gchar * user_config_path = g_build_filename(dir, "lxterminal.conf", NULL);
348+
gchar * config_filename = g_strdup_printf("lxterminal%s%s.conf", profile ? "-" : "", profile ? profile : "");
349+
gchar * user_config_path = g_build_filename(dir, config_filename, NULL);
347350
g_free(dir);
351+
g_free(config_filename);
348352
gchar * system_config_path = g_strdup(PACKAGE_DATA_DIR "/lxterminal/lxterminal.conf");
349353
gchar * config_path = user_config_path;
350354

@@ -564,7 +568,7 @@ Setting * load_setting()
564568

565569
if (need_save)
566570
{
567-
save_setting();
571+
save_setting(profile);
568572
}
569573
//print_setting();
570574
return setting;

src/setting.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ typedef struct _colorpreset {
149149
} ColorPreset;
150150

151151
extern Setting * get_setting();
152-
extern void save_setting();
153-
extern Setting * load_setting();
152+
extern void save_setting(const char *);
153+
extern Setting * load_setting(const char *);
154154

155155
/* Utils for chsnge setting through preference */
156156
extern void set_setting(Setting * setting);

src/unixsocket.c

+8-6
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ typedef struct _client_info {
3535
int fd;
3636
} ClientInfo;
3737

38-
static gboolean init(LXTermWindow* lxtermwin, gint argc, gchar** argv);
38+
static gboolean init(LXTermWindow* lxtermwin, const char *profile, gint argc, gchar** argv);
3939
static void start_controller(struct sockaddr_un* sock_addr, LXTermWindow* lxtermwin, int fd);
4040
static void send_msg_to_controller(int fd, gint argc, gchar** argv);
4141
static gboolean handle_client(GIOChannel* source, GIOCondition condition, LXTermWindow* lxtermwin);
4242
static void accept_client(GIOChannel* source, LXTermWindow* lxtermwin);
4343
static gboolean handle_request(GIOChannel* gio, GIOCondition condition, ClientInfo* info);
4444

45-
static gboolean init(LXTermWindow* lxtermwin, gint argc, gchar** argv) {
45+
static gboolean init(LXTermWindow* lxtermwin, const char *profile, gint argc, gchar** argv) {
4646
/* Normally, LXTerminal uses one process to control all of its windows.
4747
* The first process to start will create a Unix domain socket in
4848
* g_get_user_runtime_dir(). It will then bind and listen on this socket.
@@ -59,12 +59,14 @@ static gboolean init(LXTermWindow* lxtermwin, gint argc, gchar** argv) {
5959

6060
/* Formulate the path for the Unix domain socket. */
6161
#if GLIB_CHECK_VERSION (2, 28, 0)
62-
gchar * socket_path = g_strdup_printf("%s/.lxterminal-socket-%s",
62+
gchar * socket_path = g_strdup_printf("%s/.lxterminal-socket%s%s-%s",
6363
g_get_user_runtime_dir(),
64+
profile ? "-" : "", profile ? profile : "",
6465
gdk_display_get_name(gdk_display_get_default()));
6566
#else
66-
gchar * socket_path = g_strdup_printf("%s/.lxterminal-socket-%s",
67+
gchar * socket_path = g_strdup_printf("%s/.lxterminal-socket%s%s-%s",
6768
g_get_user_cache_dir(),
69+
profile ? "-" : "", profile ? profile : "",
6870
gdk_display_get_name(gdk_display_get_default()));
6971
#endif
7072

@@ -262,6 +264,6 @@ static gboolean handle_request(GIOChannel* gio, GIOCondition condition, ClientIn
262264
return TRUE;
263265
}
264266

265-
gboolean lxterminal_socket_initialize(LXTermWindow* lxtermwin, gint argc, gchar** argv) {
266-
return init(lxtermwin, argc, argv);
267+
gboolean lxterminal_socket_initialize(LXTermWindow* lxtermwin, const char *profile, gint argc, gchar** argv) {
268+
return init(lxtermwin, profile, argc, argv);
267269
}

src/unixsocket.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#ifndef LXTERMINAL_UNIXSOCKET_H
2222
#define LXTERMINAL_UNIXSOCKET_H
2323

24-
extern gboolean lxterminal_socket_initialize(LXTermWindow* lxtermwin, gint argc, gchar** argv);
24+
extern gboolean lxterminal_socket_initialize(LXTermWindow* lxtermwin, const char *profile, gint argc, gchar** argv);
2525

2626
#endif
2727

0 commit comments

Comments
 (0)