annotate src/remote.c @ 1516:c30965f99b3c

improved Scroll reset method in preferences dialog
author nadvornik
date Sun, 05 Apr 2009 09:25:48 +0000
parents 9c16a93a0fdf
children 24a12aa0cb54
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
1 /*
196
f6e307c7bad6 rename GQview -> Geeqie over the code
nadvornik
parents: 64
diff changeset
2 * Geeqie
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
3 * (C) 2004 John Ellis
1284
8b89e3ff286b Add year 2009 to copyright info everywhere.
zas_
parents: 1145
diff changeset
4 * Copyright (C) 2008 - 2009 The Geeqie Team
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
5 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
6 * Author: John Ellis
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
7 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
8 * This software is released under the GNU General Public License (GNU GPL).
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
9 * Please read the included file COPYING for more information.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
10 * This software comes with no warranty of any kind, use at your own risk!
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
11 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
12
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
13
281
9995c5fb202a gqview.h -> main.h
zas_
parents: 196
diff changeset
14 #include "main.h"
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
15 #include "remote.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
16
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
17 #include "collect.h"
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
18 #include "filedata.h"
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
19 #include "img-view.h"
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
20 #include "layout.h"
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
21 #include "layout_image.h"
1022
9962b24b6b43 Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents: 1000
diff changeset
22 #include "misc.h"
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
23 #include "slideshow.h"
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
24 #include "ui_fileops.h"
1467
2b95dbb20a87 added "load config" command to remote control
nadvornik
parents: 1444
diff changeset
25 #include "rcfile.h"
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
26
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
27 #include <sys/socket.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
28 #include <sys/un.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
29 #include <signal.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
30 #include <errno.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
31
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
32
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
33 #define SERVER_MAX_CLIENTS 8
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
34
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
35 #define REMOTE_SERVER_BACKLOG 4
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
36
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
37
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
38 #ifndef UNIX_PATH_MAX
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
39 #define UNIX_PATH_MAX 108
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
40 #endif
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
41
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
42
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
43 static RemoteConnection *remote_client_open(const gchar *path);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
44 static gint remote_client_send(RemoteConnection *rc, const gchar *text);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
45
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
46
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
47 typedef struct _RemoteClient RemoteClient;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
48 struct _RemoteClient {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
49 gint fd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
50 gint channel_id;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
51 RemoteConnection *rc;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
52 };
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
53
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
54 typedef struct _RemoteData RemoteData;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
55 struct _RemoteData {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
56 CollectionData *command_collection;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
57 };
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
58
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
59
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
60 static gboolean remote_server_client_cb(GIOChannel *source, GIOCondition condition, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
61 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
62 RemoteClient *client = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
63 RemoteConnection *rc;
1299
d53d4a448fae hopefully fixed a freeze on solaris
nadvornik
parents: 1291
diff changeset
64 GIOStatus status = G_IO_STATUS_NORMAL;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
65
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
66 rc = client->rc;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
67
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
68 if (condition & G_IO_IN)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
69 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
70 GList *queue = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
71 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
72 gchar *buffer = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
73 GError *error = NULL;
1300
bd1c6e445396 fixed compiler warning
nadvornik
parents: 1299
diff changeset
74 gsize termpos;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
75
1299
d53d4a448fae hopefully fixed a freeze on solaris
nadvornik
parents: 1291
diff changeset
76 while ((status = g_io_channel_read_line(source, &buffer, NULL, &termpos, &error)) == G_IO_STATUS_NORMAL)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
77 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
78 if (buffer)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
79 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
80 buffer[termpos] = '\0';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
81
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
82 if (strlen(buffer) > 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
83 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
84 queue = g_list_append(queue, buffer);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
85 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
86 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
87 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
88 g_free(buffer);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
89 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
90
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
91 buffer = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
92 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
93 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
94
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
95 if (error)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
96 {
673
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 671
diff changeset
97 log_printf("error reading socket: %s\n", error->message);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
98 g_error_free(error);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
99 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
100
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
101 work = queue;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
102 while (work)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
103 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
104 gchar *command = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
105 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
106
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
107 if (rc->read_func) rc->read_func(rc, command, rc->read_data);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
108 g_free(command);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
109 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
110
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
111 g_list_free(queue);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
112 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
113
1299
d53d4a448fae hopefully fixed a freeze on solaris
nadvornik
parents: 1291
diff changeset
114 if (condition & G_IO_HUP || status == G_IO_STATUS_EOF || status == G_IO_STATUS_ERROR)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
115 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
116 rc->clients = g_list_remove(rc->clients, client);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
117
506
fc9c8a3e1a8b Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents: 495
diff changeset
118 DEBUG_1("HUP detected, closing client.");
fc9c8a3e1a8b Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents: 495
diff changeset
119 DEBUG_1("client count %d", g_list_length(rc->clients));
495
c7a2471e5c4e Introduce macros to display debug messages.
zas_
parents: 475
diff changeset
120
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
121 g_source_remove(client->channel_id);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
122 close(client->fd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
123 g_free(client);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
124 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
125
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
126 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
127 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
128
1000
4fe8f9656107 For the sake of consistency, use glib basic types everywhere.
zas_
parents: 995
diff changeset
129 static void remote_server_client_add(RemoteConnection *rc, gint fd)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
130 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
131 RemoteClient *client;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
132 GIOChannel *channel;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
133
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
134 if (g_list_length(rc->clients) > SERVER_MAX_CLIENTS)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
135 {
673
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 671
diff changeset
136 log_printf("maximum remote clients of %d exceeded, closing connection\n", SERVER_MAX_CLIENTS);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
137 close(fd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
138 return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
139 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
140
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
141 client = g_new0(RemoteClient, 1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
142 client->rc = rc;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
143 client->fd = fd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
144
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
145 channel = g_io_channel_unix_new(fd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
146 client->channel_id = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, G_IO_IN | G_IO_HUP,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
147 remote_server_client_cb, client, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
148 g_io_channel_unref(channel);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
149
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
150 rc->clients = g_list_append(rc->clients, client);
506
fc9c8a3e1a8b Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents: 495
diff changeset
151 DEBUG_1("client count %d", g_list_length(rc->clients));
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
152 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
153
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
154 static void remote_server_clients_close(RemoteConnection *rc)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
155 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
156 while (rc->clients)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
157 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
158 RemoteClient *client = rc->clients->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
159
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
160 rc->clients = g_list_remove(rc->clients, client);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
161
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
162 g_source_remove(client->channel_id);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
163 close(client->fd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
164 g_free(client);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
165 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
166 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
167
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
168 static gboolean remote_server_read_cb(GIOChannel *source, GIOCondition condition, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
169 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
170 RemoteConnection *rc = data;
1000
4fe8f9656107 For the sake of consistency, use glib basic types everywhere.
zas_
parents: 995
diff changeset
171 gint fd;
4fe8f9656107 For the sake of consistency, use glib basic types everywhere.
zas_
parents: 995
diff changeset
172 guint alen;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
173
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
174 fd = accept(rc->fd, NULL, &alen);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
175 if (fd == -1)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
176 {
673
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 671
diff changeset
177 log_printf("error accepting socket: %s\n", strerror(errno));
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
178 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
179 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
180
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
181 remote_server_client_add(rc, fd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
182
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
183 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
184 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
185
1444
a005287bffc7 gint -> gboolean.
zas_
parents: 1437
diff changeset
186 static gboolean remote_server_exists(const gchar *path)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
187 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
188 RemoteConnection *rc;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
189
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
190 /* verify server up */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
191 rc = remote_client_open(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
192 remote_close(rc);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
193
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
194 if (rc) return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
195
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
196 /* unable to connect, remove socket file to free up address */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
197 unlink(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
198 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
199 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
200
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
201 static RemoteConnection *remote_server_open(const gchar *path)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
202 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
203 RemoteConnection *rc;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
204 struct sockaddr_un addr;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
205 gint sun_path_len;
1000
4fe8f9656107 For the sake of consistency, use glib basic types everywhere.
zas_
parents: 995
diff changeset
206 gint fd;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
207 GIOChannel *channel;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
208
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
209 if (remote_server_exists(path))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
210 {
673
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 671
diff changeset
211 log_printf("Address already in use: %s\n", path);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
212 return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
213 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
214
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
215 fd = socket(PF_UNIX, SOCK_STREAM, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
216 if (fd == -1) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
217
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
218 addr.sun_family = AF_UNIX;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
219 sun_path_len = MIN(strlen(path) + 1, UNIX_PATH_MAX);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
220 strncpy(addr.sun_path, path, sun_path_len);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
221 if (bind(fd, &addr, sizeof(addr)) == -1 ||
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
222 listen(fd, REMOTE_SERVER_BACKLOG) == -1)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
223 {
673
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 671
diff changeset
224 log_printf("error subscribing to socket: %s\n", strerror(errno));
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
225 close(fd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
226 return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
227 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
228
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
229 rc = g_new0(RemoteConnection, 1);
1367
fe4da037be21 When g_new0() is used, drop redundant initializations to NULL, FALSE or 0, second pass.
zas_
parents: 1307
diff changeset
230
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
231 rc->server = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
232 rc->fd = fd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
233 rc->path = g_strdup(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
234
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
235 channel = g_io_channel_unix_new(rc->fd);
1291
50ae02a4a675 replaced bar_info with an universal bar, restored the original
nadvornik
parents: 1284
diff changeset
236 g_io_channel_set_flags(channel, G_IO_FLAG_NONBLOCK, NULL);
50ae02a4a675 replaced bar_info with an universal bar, restored the original
nadvornik
parents: 1284
diff changeset
237
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
238 rc->channel_id = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, G_IO_IN,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
239 remote_server_read_cb, rc, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
240 g_io_channel_unref(channel);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
241
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
242 return rc;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
243 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
244
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
245 static void remote_server_subscribe(RemoteConnection *rc, RemoteReadFunc *func, gpointer data)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
246 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
247 if (!rc || !rc->server) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
248
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
249 rc->read_func = func;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
250 rc->read_data = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
251 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
252
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
253
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
254 static RemoteConnection *remote_client_open(const gchar *path)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
255 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
256 RemoteConnection *rc;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
257 struct stat st;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
258 struct sockaddr_un addr;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
259 gint sun_path_len;
1000
4fe8f9656107 For the sake of consistency, use glib basic types everywhere.
zas_
parents: 995
diff changeset
260 gint fd;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
261
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
262 if (stat(path, &st) != 0 || !S_ISSOCK(st.st_mode)) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
263
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
264 fd = socket(PF_UNIX, SOCK_STREAM, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
265 if (fd == -1) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
266
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
267 addr.sun_family = AF_UNIX;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
268 sun_path_len = MIN(strlen(path) + 1, UNIX_PATH_MAX);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
269 strncpy(addr.sun_path, path, sun_path_len);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
270 if (connect(fd, &addr, sizeof(addr)) == -1)
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 371
diff changeset
271 {
506
fc9c8a3e1a8b Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents: 495
diff changeset
272 DEBUG_1("error connecting to socket: %s", strerror(errno));
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 371
diff changeset
273 close(fd);
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 371
diff changeset
274 return NULL;
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 371
diff changeset
275 }
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
276
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
277 rc = g_new0(RemoteConnection, 1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
278 rc->server = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
279 rc->fd = fd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
280 rc->path = g_strdup(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
281
371
7997b6704fdb this might fix the freezes on freebsd, solaris, etc.
nadvornik
parents: 281
diff changeset
282 /* this might fix the freezes on freebsd, solaris, etc. - completely untested */
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 371
diff changeset
283 remote_client_send(rc, "\n");
371
7997b6704fdb this might fix the freezes on freebsd, solaris, etc.
nadvornik
parents: 281
diff changeset
284
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
285 return rc;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
286 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
287
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
288 static sig_atomic_t sigpipe_occured = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
289
1000
4fe8f9656107 For the sake of consistency, use glib basic types everywhere.
zas_
parents: 995
diff changeset
290 static void sighandler_sigpipe(gint sig)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
291 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
292 sigpipe_occured = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
293 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
294
1444
a005287bffc7 gint -> gboolean.
zas_
parents: 1437
diff changeset
295 static gboolean remote_client_send(RemoteConnection *rc, const gchar *text)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
296 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
297 struct sigaction new_action, old_action;
1437
a3d3208b0c50 gint -> gboolean.
zas_
parents: 1416
diff changeset
298 gboolean ret = FALSE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
299
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
300 if (!rc || rc->server) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
301 if (!text) return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
302
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
303 sigpipe_occured = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
304
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
305 new_action.sa_handler = sighandler_sigpipe;
512
f9bf33be53ff Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents: 507
diff changeset
306 sigemptyset(&new_action.sa_mask);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
307 new_action.sa_flags = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
308
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
309 /* setup our signal handler */
512
f9bf33be53ff Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents: 507
diff changeset
310 sigaction(SIGPIPE, &new_action, &old_action);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
311
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
312 if (write(rc->fd, text, strlen(text)) == -1 ||
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
313 write(rc->fd, "\n", 1) == -1)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
314 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
315 if (sigpipe_occured)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
316 {
673
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 671
diff changeset
317 log_printf("SIGPIPE writing to socket: %s\n", rc->path);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
318 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
319 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
320 {
673
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 671
diff changeset
321 log_printf("error writing to socket: %s\n", strerror(errno));
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
322 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
323 ret = FALSE;;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
324 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
325 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
326 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
327 ret = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
328 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
329
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
330 /* restore the original signal handler */
512
f9bf33be53ff Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents: 507
diff changeset
331 sigaction(SIGPIPE, &old_action, NULL);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
332
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
333 return ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
334 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
335
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
336 void remote_close(RemoteConnection *rc)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
337 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
338 if (!rc) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
339
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
340 if (rc->server)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
341 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
342 remote_server_clients_close(rc);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
343
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
344 g_source_remove(rc->channel_id);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
345 unlink(rc->path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
346 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
347
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
348 if (rc->read_data)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
349 g_free(rc->read_data);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
350
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
351 close(rc->fd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
352
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
353 g_free(rc->path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
354 g_free(rc);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
355 }
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
356
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
357 /*
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
358 *-----------------------------------------------------------------------------
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
359 * remote functions
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
360 *-----------------------------------------------------------------------------
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
361 */
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
362
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
363 static void gr_image_next(const gchar *text, gpointer data)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
364 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
365 layout_image_next(NULL);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
366 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
367
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
368 static void gr_image_prev(const gchar *text, gpointer data)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
369 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
370 layout_image_prev(NULL);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
371 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
372
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
373 static void gr_image_first(const gchar *text, gpointer data)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
374 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
375 layout_image_first(NULL);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
376 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
377
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
378 static void gr_image_last(const gchar *text, gpointer data)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
379 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
380 layout_image_last(NULL);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
381 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
382
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
383 static void gr_fullscreen_toggle(const gchar *text, gpointer data)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
384 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
385 layout_image_full_screen_toggle(NULL);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
386 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
387
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
388 static void gr_fullscreen_start(const gchar *text, gpointer data)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
389 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
390 layout_image_full_screen_start(NULL);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
391 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
392
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
393 static void gr_fullscreen_stop(const gchar *text, gpointer data)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
394 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
395 layout_image_full_screen_stop(NULL);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
396 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
397
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
398 static void gr_slideshow_start_rec(const gchar *text, gpointer data)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
399 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
400 GList *list;
783
d6a7fb4b8e7c replaced directory path with FileData* dir_fd
nadvornik
parents: 781
diff changeset
401 FileData *dir_fd = file_data_new_simple(text);
d6a7fb4b8e7c replaced directory path with FileData* dir_fd
nadvornik
parents: 781
diff changeset
402 list = filelist_recursive(dir_fd);
d6a7fb4b8e7c replaced directory path with FileData* dir_fd
nadvornik
parents: 781
diff changeset
403 file_data_unref(dir_fd);
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
404 if (!list) return;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
405 //printf("length: %d\n", g_list_length(list));
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
406 layout_image_slideshow_stop(NULL);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
407 layout_image_slideshow_start_from_list(NULL, list);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
408 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
409
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
410 static void gr_slideshow_toggle(const gchar *text, gpointer data)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
411 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
412 layout_image_slideshow_toggle(NULL);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
413 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
414
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
415 static void gr_slideshow_start(const gchar *text, gpointer data)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
416 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
417 layout_image_slideshow_start(NULL);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
418 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
419
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
420 static void gr_slideshow_stop(const gchar *text, gpointer data)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
421 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
422 layout_image_slideshow_stop(NULL);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
423 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
424
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
425 static void gr_slideshow_delay(const gchar *text, gpointer data)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
426 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
427 gdouble n;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
428
1307
e8f21b91885d Glibification again.
zas_
parents: 1300
diff changeset
429 n = g_ascii_strtod(text, NULL);
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
430 if (n < SLIDESHOW_MIN_SECONDS || n > SLIDESHOW_MAX_SECONDS)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
431 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
432 printf_term("Remote slideshow delay out of range (%.1f to %.1f)\n",
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
433 SLIDESHOW_MIN_SECONDS, SLIDESHOW_MAX_SECONDS);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
434 return;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
435 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
436 options->slideshow.delay = (gint)(n * 10.0 + 0.01);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
437 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
438
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
439 static void gr_tools_show(const gchar *text, gpointer data)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
440 {
1416
9fe2fede7ae5 Use gboolean pseudo type where applicable.
zas_
parents: 1367
diff changeset
441 gboolean popped;
9fe2fede7ae5 Use gboolean pseudo type where applicable.
zas_
parents: 1367
diff changeset
442 gboolean hidden;
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
443
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
444 if (layout_tools_float_get(NULL, &popped, &hidden) && hidden)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
445 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
446 layout_tools_float_set(NULL, popped, FALSE);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
447 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
448 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
449
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
450 static void gr_tools_hide(const gchar *text, gpointer data)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
451 {
1416
9fe2fede7ae5 Use gboolean pseudo type where applicable.
zas_
parents: 1367
diff changeset
452 gboolean popped;
9fe2fede7ae5 Use gboolean pseudo type where applicable.
zas_
parents: 1367
diff changeset
453 gboolean hidden;
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
454
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
455 if (layout_tools_float_get(NULL, &popped, &hidden) && !hidden)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
456 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
457 layout_tools_float_set(NULL, popped, TRUE);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
458 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
459 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
460
1444
a005287bffc7 gint -> gboolean.
zas_
parents: 1437
diff changeset
461 static gboolean gr_quit_idle_cb(gpointer data)
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
462 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
463 exit_program();
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
464
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
465 return FALSE;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
466 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
467
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
468 static void gr_quit(const gchar *text, gpointer data)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
469 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
470 /* schedule exit when idle, if done from within a
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
471 * remote handler remote_close will crash
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
472 */
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
473 g_idle_add(gr_quit_idle_cb, NULL);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
474 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
475
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
476 static void gr_file_load(const gchar *text, gpointer data)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
477 {
653
e06947d07086 Expand tilde with file: and view: remote parameters.
zas_
parents: 652
diff changeset
478 gchar *filename = expand_tilde(text);
e06947d07086 Expand tilde with file: and view: remote parameters.
zas_
parents: 652
diff changeset
479
e06947d07086 Expand tilde with file: and view: remote parameters.
zas_
parents: 652
diff changeset
480 if (isfile(filename))
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
481 {
781
2d2cca2bceb0 Replace hardcoded collection filename extension by a macro (GQ_COLLECTION_EXT).
zas_
parents: 713
diff changeset
482 if (file_extension_match(filename, GQ_COLLECTION_EXT))
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
483 {
653
e06947d07086 Expand tilde with file: and view: remote parameters.
zas_
parents: 652
diff changeset
484 collection_window_new(filename);
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
485 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
486 else
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
487 {
653
e06947d07086 Expand tilde with file: and view: remote parameters.
zas_
parents: 652
diff changeset
488 layout_set_path(NULL, filename);
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
489 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
490 }
653
e06947d07086 Expand tilde with file: and view: remote parameters.
zas_
parents: 652
diff changeset
491 else if (isdir(filename))
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
492 {
653
e06947d07086 Expand tilde with file: and view: remote parameters.
zas_
parents: 652
diff changeset
493 layout_set_path(NULL, filename);
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
494 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
495 else
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
496 {
673
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 671
diff changeset
497 log_printf("remote sent filename that does not exist:\"%s\"\n", filename);
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
498 }
653
e06947d07086 Expand tilde with file: and view: remote parameters.
zas_
parents: 652
diff changeset
499
e06947d07086 Expand tilde with file: and view: remote parameters.
zas_
parents: 652
diff changeset
500 g_free(filename);
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
501 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
502
1467
2b95dbb20a87 added "load config" command to remote control
nadvornik
parents: 1444
diff changeset
503 static void gr_config_load(const gchar *text, gpointer data)
2b95dbb20a87 added "load config" command to remote control
nadvornik
parents: 1444
diff changeset
504 {
2b95dbb20a87 added "load config" command to remote control
nadvornik
parents: 1444
diff changeset
505 gchar *filename = expand_tilde(text);
2b95dbb20a87 added "load config" command to remote control
nadvornik
parents: 1444
diff changeset
506
2b95dbb20a87 added "load config" command to remote control
nadvornik
parents: 1444
diff changeset
507 if (isfile(filename))
2b95dbb20a87 added "load config" command to remote control
nadvornik
parents: 1444
diff changeset
508 {
1484
9c16a93a0fdf improved sidebar configuration
nadvornik
parents: 1475
diff changeset
509 load_config_from_file(filename, FALSE);
1467
2b95dbb20a87 added "load config" command to remote control
nadvornik
parents: 1444
diff changeset
510 }
2b95dbb20a87 added "load config" command to remote control
nadvornik
parents: 1444
diff changeset
511 else
2b95dbb20a87 added "load config" command to remote control
nadvornik
parents: 1444
diff changeset
512 {
2b95dbb20a87 added "load config" command to remote control
nadvornik
parents: 1444
diff changeset
513 log_printf("remote sent filename that does not exist:\"%s\"\n", filename);
2b95dbb20a87 added "load config" command to remote control
nadvornik
parents: 1444
diff changeset
514 }
2b95dbb20a87 added "load config" command to remote control
nadvornik
parents: 1444
diff changeset
515
2b95dbb20a87 added "load config" command to remote control
nadvornik
parents: 1444
diff changeset
516 g_free(filename);
2b95dbb20a87 added "load config" command to remote control
nadvornik
parents: 1444
diff changeset
517 }
2b95dbb20a87 added "load config" command to remote control
nadvornik
parents: 1444
diff changeset
518
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
519 static void gr_file_view(const gchar *text, gpointer data)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
520 {
653
e06947d07086 Expand tilde with file: and view: remote parameters.
zas_
parents: 652
diff changeset
521 gchar *filename = expand_tilde(text);
e06947d07086 Expand tilde with file: and view: remote parameters.
zas_
parents: 652
diff changeset
522
e06947d07086 Expand tilde with file: and view: remote parameters.
zas_
parents: 652
diff changeset
523 view_window_new(file_data_new_simple(filename));
e06947d07086 Expand tilde with file: and view: remote parameters.
zas_
parents: 652
diff changeset
524 g_free(filename);
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
525 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
526
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
527 static void gr_list_clear(const gchar *text, gpointer data)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
528 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
529 RemoteData *remote_data = data;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
530
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
531 if (remote_data->command_collection)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
532 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
533 collection_unref(remote_data->command_collection);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
534 remote_data->command_collection = NULL;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
535 }
995
6ca2c5fd7b13 Whitespaces cleanup.
zas_
parents: 783
diff changeset
536 }
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
537
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
538 static void gr_list_add(const gchar *text, gpointer data)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
539 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
540 RemoteData *remote_data = data;
1437
a3d3208b0c50 gint -> gboolean.
zas_
parents: 1416
diff changeset
541 gboolean new = TRUE;
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
542
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
543 if (!remote_data->command_collection)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
544 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
545 CollectionData *cd;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
546
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
547 cd = collection_new("");
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
548
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
549 g_free(cd->path);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
550 cd->path = NULL;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
551 g_free(cd->name);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
552 cd->name = g_strdup(_("Command line"));
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
553
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
554 remote_data->command_collection = cd;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
555 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
556 else
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
557 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
558 new = (!collection_get_first(remote_data->command_collection));
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
559 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
560
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
561 if (collection_add(remote_data->command_collection, file_data_new_simple(text), FALSE) && new)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
562 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
563 layout_image_set_collection(NULL, remote_data->command_collection,
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
564 collection_get_first(remote_data->command_collection));
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
565 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
566 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
567
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
568 static void gr_raise(const gchar *text, gpointer data)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
569 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
570 LayoutWindow *lw = NULL;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
571
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
572 if (layout_valid(&lw))
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
573 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
574 gtk_window_present(GTK_WINDOW(lw->window));
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
575 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
576 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
577
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
578 typedef struct _RemoteCommandEntry RemoteCommandEntry;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
579 struct _RemoteCommandEntry {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
580 gchar *opt_s;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
581 gchar *opt_l;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
582 void (*func)(const gchar *text, gpointer data);
1444
a005287bffc7 gint -> gboolean.
zas_
parents: 1437
diff changeset
583 gboolean needs_extra;
a005287bffc7 gint -> gboolean.
zas_
parents: 1437
diff changeset
584 gboolean prefer_command_line;
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
585 gchar *description;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
586 };
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
587
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
588 static RemoteCommandEntry remote_commands[] = {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
589 /* short, long callback, extra, prefer,description */
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
590 { "-n", "--next", gr_image_next, FALSE, FALSE, N_("next image") },
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
591 { "-b", "--back", gr_image_prev, FALSE, FALSE, N_("previous image") },
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
592 { NULL, "--first", gr_image_first, FALSE, FALSE, N_("first image") },
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
593 { NULL, "--last", gr_image_last, FALSE, FALSE, N_("last image") },
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
594 { "-f", "--fullscreen", gr_fullscreen_toggle, FALSE, TRUE, N_("toggle full screen") },
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
595 { "-fs","--fullscreen-start", gr_fullscreen_start, FALSE, FALSE, N_("start full screen") },
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
596 { "-fS","--fullscreen-stop", gr_fullscreen_stop, FALSE, FALSE, N_("stop full screen") },
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
597 { "-s", "--slideshow", gr_slideshow_toggle, FALSE, TRUE, N_("toggle slide show") },
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
598 { "-ss","--slideshow-start", gr_slideshow_start, FALSE, FALSE, N_("start slide show") },
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
599 { "-sS","--slideshow-stop", gr_slideshow_stop, FALSE, FALSE, N_("stop slide show") },
1475
f43e4ee8fb2d more consistent remote options naming
nadvornik
parents: 1467
diff changeset
600 { NULL, "--slideshow-recurse:", gr_slideshow_start_rec, TRUE, FALSE, N_("start recursive slide show") },
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
601 { "-d", "--delay=", gr_slideshow_delay, TRUE, FALSE, N_("set slide show delay in seconds") },
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
602 { "+t", "--tools-show", gr_tools_show, FALSE, TRUE, N_("show tools") },
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
603 { "-t", "--tools-hide", gr_tools_hide, FALSE, TRUE, N_("hide tools") },
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
604 { "-q", "--quit", gr_quit, FALSE, FALSE, N_("quit") },
1475
f43e4ee8fb2d more consistent remote options naming
nadvornik
parents: 1467
diff changeset
605 { NULL, "--config-load:", gr_config_load, TRUE, FALSE, N_("load config file") },
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
606 { NULL, "file:", gr_file_load, TRUE, FALSE, N_("open file") },
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
607 { NULL, "view:", gr_file_view, TRUE, FALSE, N_("open file in new window") },
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
608 { NULL, "--list-clear", gr_list_clear, FALSE, FALSE, NULL },
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
609 { NULL, "--list-add:", gr_list_add, TRUE, FALSE, NULL },
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
610 { NULL, "raise", gr_raise, FALSE, FALSE, NULL },
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
611 { NULL, NULL, NULL, FALSE, FALSE, NULL }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
612 };
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
613
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
614 static RemoteCommandEntry *remote_command_find(const gchar *text, const gchar **offset)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
615 {
1437
a3d3208b0c50 gint -> gboolean.
zas_
parents: 1416
diff changeset
616 gboolean match = FALSE;
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
617 gint i;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
618
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
619 i = 0;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
620 while (!match && remote_commands[i].func != NULL)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
621 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
622 if (remote_commands[i].needs_extra)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
623 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
624 if (remote_commands[i].opt_s &&
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
625 strncmp(remote_commands[i].opt_s, text, strlen(remote_commands[i].opt_s)) == 0)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
626 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
627 if (offset) *offset = text + strlen(remote_commands[i].opt_s);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
628 return &remote_commands[i];
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
629 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
630 else if (remote_commands[i].opt_l &&
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
631 strncmp(remote_commands[i].opt_l, text, strlen(remote_commands[i].opt_l)) == 0)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
632 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
633 if (offset) *offset = text + strlen(remote_commands[i].opt_l);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
634 return &remote_commands[i];
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
635 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
636 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
637 else
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
638 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
639 if ((remote_commands[i].opt_s && strcmp(remote_commands[i].opt_s, text) == 0) ||
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
640 (remote_commands[i].opt_l && strcmp(remote_commands[i].opt_l, text) == 0))
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
641 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
642 if (offset) *offset = text;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
643 return &remote_commands[i];
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
644 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
645 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
646
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
647 i++;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
648 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
650 return NULL;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
651 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
652
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
653 static void remote_cb(RemoteConnection *rc, const gchar *text, gpointer data)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
654 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
655 RemoteCommandEntry *entry;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
656 const gchar *offset;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
657
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
658 entry = remote_command_find(text, &offset);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
659 if (entry && entry->func)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
660 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
661 entry->func(offset, data);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
662 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
663 else
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
664 {
673
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 671
diff changeset
665 log_printf("unknown remote command:%s\n", text);
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
666 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
667 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
668
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
669 void remote_help(void)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
670 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
671 gint i;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
672
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
673 print_term(_("Remote command list:\n"));
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
674
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
675 i = 0;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
676 while (remote_commands[i].func != NULL)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
677 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
678 if (remote_commands[i].description)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
679 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
680 printf_term(" %-3s%s %-20s %s\n",
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
681 (remote_commands[i].opt_s) ? remote_commands[i].opt_s : "",
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
682 (remote_commands[i].opt_s && remote_commands[i].opt_l) ? "," : " ",
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
683 (remote_commands[i].opt_l) ? remote_commands[i].opt_l : "",
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
684 _(remote_commands[i].description));
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
685 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
686 i++;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
687 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
688 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
689
1000
4fe8f9656107 For the sake of consistency, use glib basic types everywhere.
zas_
parents: 995
diff changeset
690 GList *remote_build_list(GList *list, gint argc, gchar *argv[], GList **errors)
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
691 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
692 gint i;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
693
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
694 i = 1;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
695 while (i < argc)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
696 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
697 RemoteCommandEntry *entry;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
698
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
699 entry = remote_command_find(argv[i], NULL);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
700 if (entry)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
701 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
702 list = g_list_append(list, argv[i]);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
703 }
652
9bcfd6d7a902 Display a message when invalid remote options are used.
zas_
parents: 649
diff changeset
704 else if (errors)
9bcfd6d7a902 Display a message when invalid remote options are used.
zas_
parents: 649
diff changeset
705 {
9bcfd6d7a902 Display a message when invalid remote options are used.
zas_
parents: 649
diff changeset
706 *errors = g_list_append(*errors, argv[i]);
9bcfd6d7a902 Display a message when invalid remote options are used.
zas_
parents: 649
diff changeset
707 }
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
708 i++;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
709 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
710
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
711 return list;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
712 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
713
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
714 void remote_control(const gchar *arg_exec, GList *remote_list, const gchar *path,
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
715 GList *cmd_list, GList *collection_list)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
716 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
717 RemoteConnection *rc;
1437
a3d3208b0c50 gint -> gboolean.
zas_
parents: 1416
diff changeset
718 gboolean started = FALSE;
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
719 gchar *buf;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
720
1145
3a7af6a8cd5f Use functions to return directories instead of constants.
zas_
parents: 1144
diff changeset
721 buf = g_build_filename(get_rc_dir(), ".command", NULL);
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
722 rc = remote_client_open(buf);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
723 if (!rc)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
724 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
725 GString *command;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
726 GList *work;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
727 gint retry_count = 12;
1437
a3d3208b0c50 gint -> gboolean.
zas_
parents: 1416
diff changeset
728 gboolean blank = FALSE;
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
729
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
730 printf_term(_("Remote %s not running, starting..."), GQ_APPNAME);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
731
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
732 command = g_string_new(arg_exec);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
733
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
734 work = remote_list;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
735 while (work)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
736 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
737 gchar *text;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
738 RemoteCommandEntry *entry;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
739
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
740 text = work->data;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
741 work = work->next;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
742
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
743 entry = remote_command_find(text, NULL);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
744 if (entry)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
745 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
746 if (entry->prefer_command_line)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
747 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
748 remote_list = g_list_remove(remote_list, text);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
749 g_string_append(command, " ");
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
750 g_string_append(command, text);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
751 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
752 if (entry->opt_l && strcmp(entry->opt_l, "file:") == 0)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
753 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
754 blank = TRUE;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
755 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
756 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
757 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
758
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
759 if (blank || cmd_list || path) g_string_append(command, " --blank");
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
760 if (get_debug_level()) g_string_append(command, " --debug");
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
761
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
762 g_string_append(command, " &");
1144
5fe3b8b3a612 Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents: 1055
diff changeset
763 runcmd(command->str);
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
764 g_string_free(command, TRUE);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
765
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
766 while (!rc && retry_count > 0)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
767 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
768 usleep((retry_count > 10) ? 500000 : 1000000);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
769 rc = remote_client_open(buf);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
770 if (!rc) print_term(".");
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
771 retry_count--;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
772 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
773
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
774 print_term("\n");
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
775
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
776 started = TRUE;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
777 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
778 g_free(buf);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
779
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
780 if (rc)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
781 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
782 GList *work;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
783 const gchar *prefix;
1437
a3d3208b0c50 gint -> gboolean.
zas_
parents: 1416
diff changeset
784 gboolean use_path = TRUE;
a3d3208b0c50 gint -> gboolean.
zas_
parents: 1416
diff changeset
785 gboolean sent = FALSE;
649
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
786
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
787 work = remote_list;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
788 while (work)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
789 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
790 gchar *text;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
791 RemoteCommandEntry *entry;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
792
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
793 text = work->data;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
794 work = work->next;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
795
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
796 entry = remote_command_find(text, NULL);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
797 if (entry &&
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
798 entry->opt_l &&
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
799 strcmp(entry->opt_l, "file:") == 0) use_path = FALSE;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
800
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
801 remote_client_send(rc, text);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
802
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
803 sent = TRUE;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
804 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
805
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
806 if (cmd_list && cmd_list->next)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
807 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
808 prefix = "--list-add:";
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
809 remote_client_send(rc, "--list-clear");
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
810 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
811 else
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
812 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
813 prefix = "file:";
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
814 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
815
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
816 work = cmd_list;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
817 while (work)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
818 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
819 FileData *fd;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
820 gchar *text;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
821
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
822 fd = work->data;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
823 work = work->next;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
824
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
825 text = g_strconcat(prefix, fd->path, NULL);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
826 remote_client_send(rc, text);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
827 g_free(text);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
828
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
829 sent = TRUE;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
830 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
831
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
832 if (path && !cmd_list && use_path)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
833 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
834 gchar *text;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
835
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
836 text = g_strdup_printf("file:%s", path);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
837 remote_client_send(rc, text);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
838 g_free(text);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
839
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
840 sent = TRUE;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
841 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
842
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
843 work = collection_list;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
844 while (work)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
845 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
846 const gchar *name;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
847 gchar *text;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
848
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
849 name = work->data;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
850 work = work->next;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
851
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
852 text = g_strdup_printf("file:%s", name);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
853 remote_client_send(rc, text);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
854 g_free(text);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
855
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
856 sent = TRUE;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
857 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
858
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
859 if (!started && !sent)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
860 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
861 remote_client_send(rc, "raise");
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
862 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
863 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
864 else
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
865 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
866 print_term(_("Remote not available\n"));
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
867 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
868
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
869 _exit(0);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
870 }
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
871
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
872 RemoteConnection *remote_server_init(gchar *path, CollectionData *command_collection)
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
873 {
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
874 RemoteConnection *remote_connection = remote_server_open(path);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
875 RemoteData *remote_data = g_new(RemoteData, 1);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
876
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
877 remote_data->command_collection = command_collection;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
878
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
879 remote_server_subscribe(remote_connection, remote_cb, remote_data);
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
880 return remote_connection;
3097880d7d95 Move all remote stuff from main.c to remote.[ch].
zas_
parents: 512
diff changeset
881 }
1055
1646720364cf Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents: 1022
diff changeset
882 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */