File: main.c

package info (click to toggle)
thunar-vcs-plugin 0.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 4,832 kB
  • sloc: ansic: 14,489; sh: 4,174; makefile: 306
file content (264 lines) | stat: -rw-r--r-- 7,612 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/*-
 * Copyright (C) 2007-2011  Peter de Ridder <peter@xfce.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif

#include <glib.h>
#include <glib/gprintf.h>
#include <gtk/gtk.h>

#include <libxfce4util/libxfce4util.h>

#include "tgh-common.h"

#include "tgh-add.h"
#include "tgh-blame.h"
#include "tgh-branch.h"
#include "tgh-clone.h"
#include "tgh-clean.h"
#include "tgh-log.h"
#include "tgh-move.h"
#include "tgh-reset.h"
#include "tgh-stash.h"
#include "tgh-status.h"

static GPid pid;
static gboolean has_child = FALSE;

void tgh_replace_child (gboolean new_child, GPid new_pid)
{
  if(has_child)
    g_spawn_close_pid(pid);

  has_child = new_child;
  pid = new_pid;
}

int main (int argc, char *argv[])
{
  /* CMD-line options */
  gboolean print_version = FALSE;
  gboolean add = FALSE;
  gboolean blame = FALSE;
  gboolean branch = FALSE;
  gboolean clean = FALSE;
  gboolean clone = FALSE;
  gboolean log = FALSE;
  gboolean move = FALSE;
  gboolean reset = FALSE;
  gboolean stash = FALSE;
  gboolean status = FALSE;
  gchar **files = NULL;
  GError *error = NULL;

  GOptionGroup *option_group;
  GOptionContext *option_context;

  GOptionEntry general_options_table[] =
  {
    { "version", 'v', 0, G_OPTION_ARG_NONE, &print_version, N_("Print version information"), NULL },
    { G_OPTION_REMAINING, '\0', G_OPTION_ARG_FILENAME, G_OPTION_ARG_FILENAME_ARRAY, &files, NULL, NULL },
    { NULL, '\0', 0, 0, NULL, NULL, NULL }
  };

  GOptionEntry add_options_table[] =
  {
    { "add", '\0', 0, G_OPTION_ARG_NONE, &add, N_("Execute add action"), NULL },
    { NULL, '\0', 0, 0, NULL, NULL, NULL }
  };

  GOptionEntry branch_options_table[] =
  {
    { "blame", '\0', 0, G_OPTION_ARG_NONE, &blame, N_("Execute blame action"), NULL },
    { NULL, '\0', 0, 0, NULL, NULL, NULL }
  };

  GOptionEntry blame_options_table[] =
  {
    { "branch", '\0', 0, G_OPTION_ARG_NONE, &branch, N_("Execute branch action"), NULL },
    { NULL, '\0', 0, 0, NULL, NULL, NULL }
  };

  GOptionEntry clean_options_table[] =
  {
    { "clean", '\0', 0, G_OPTION_ARG_NONE, &clean, N_("Execute clean action"), NULL },
    { NULL, '\0', 0, 0, NULL, NULL, NULL }
  };

  GOptionEntry clone_options_table[] =
  {
    { "clone", '\0', 0, G_OPTION_ARG_NONE, &clone, N_("Execute clone action"), NULL },
    { NULL, '\0', 0, 0, NULL, NULL, NULL }
  };

  GOptionEntry log_options_table[] =
  {
    { "log", '\0', 0, G_OPTION_ARG_NONE, &log, N_("Execute log action"), NULL },
    { NULL, '\0', 0, 0, NULL, NULL, NULL }
  };

  GOptionEntry move_options_table[] =
  {
    { "move", '\0', 0, G_OPTION_ARG_NONE, &move, N_("Execute move action"), NULL },
    { NULL, '\0', 0, 0, NULL, NULL, NULL }
  };

  GOptionEntry reset_options_table[] =
  {
    { "reset", '\0', 0, G_OPTION_ARG_NONE, &reset, N_("Execute reset action"), NULL },
    { NULL, '\0', 0, 0, NULL, NULL, NULL }
  };

  GOptionEntry stash_options_table[] =
  {
    { "stash", '\0', 0, G_OPTION_ARG_NONE, &stash, N_("Execute stash action"), NULL },
    { NULL, '\0', 0, 0, NULL, NULL, NULL }
  };

  GOptionEntry status_options_table[] =
  {
    { "status", '\0', 0, G_OPTION_ARG_NONE, &status, N_("Execute status action"), NULL },
    { NULL, '\0', 0, 0, NULL, NULL, NULL }
  };

  /* setup translation domain */
  xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");

  option_context = g_option_context_new("<action> [options] [args]");

  g_option_context_add_main_entries(option_context, general_options_table, GETTEXT_PACKAGE);
  g_option_context_add_group(option_context, gtk_get_option_group(TRUE));

  option_group = g_option_group_new("add", N_("Add Related Options:"), N_("Add"), NULL, NULL);
  g_option_group_add_entries(option_group, add_options_table);
  g_option_context_add_group(option_context, option_group);

  option_group = g_option_group_new("blame", N_("Blame Related Options:"), N_("Blame"), NULL, NULL);
  g_option_group_add_entries(option_group, blame_options_table);
  g_option_context_add_group(option_context, option_group);

  option_group = g_option_group_new("branch", N_("Branch Related Options:"), N_("Branch"), NULL, NULL);
  g_option_group_add_entries(option_group, branch_options_table);
  g_option_context_add_group(option_context, option_group);

  option_group = g_option_group_new("clean", N_("Clone Related Options:"), N_("Clean"), NULL, NULL);
  g_option_group_add_entries(option_group, clean_options_table);
  g_option_context_add_group(option_context, option_group);

  option_group = g_option_group_new("clone", N_("Clone Related Options:"), N_("Clone"), NULL, NULL);
  g_option_group_add_entries(option_group, clone_options_table);
  g_option_context_add_group(option_context, option_group);

  option_group = g_option_group_new("log", N_("Log Related Options:"), N_("Log"), NULL, NULL);
  g_option_group_add_entries(option_group, log_options_table);
  g_option_context_add_group(option_context, option_group);

  option_group = g_option_group_new("move", N_("Move Related Options:"), N_("Move"), NULL, NULL);
  g_option_group_add_entries(option_group, move_options_table);
  g_option_context_add_group(option_context, option_group);

  option_group = g_option_group_new("reset", N_("Reset Related Options:"), N_("Reset"), NULL, NULL);
  g_option_group_add_entries(option_group, reset_options_table);
  g_option_context_add_group(option_context, option_group);

  option_group = g_option_group_new("stash", N_("Stash Related Options:"), N_("Stash"), NULL, NULL);
  g_option_group_add_entries(option_group, stash_options_table);
  g_option_context_add_group(option_context, option_group);

  option_group = g_option_group_new("status", N_("Status Related Options:"), N_("Status"), NULL, NULL);
  g_option_group_add_entries(option_group, status_options_table);
  g_option_context_add_group(option_context, option_group);

  if(!g_option_context_parse(option_context, &argc, &argv, &error))
  {
    g_fprintf(stderr, "%s: %s\n\tTry --help-all\n", g_get_prgname(), error->message);
    g_error_free(error);
  }

  if(print_version)
  {
    g_print(PACKAGE_STRING "\n\tcompiled on " __DATE__ ", " __TIME__ "\n");
    return EXIT_SUCCESS;
  }

  if(add)
  {
    has_child = tgh_add(files, &pid);
  }

  if(blame)
  {
    has_child = tgh_blame(files, &pid);
  }

  if(branch)
  {
    has_child = tgh_branch(files, &pid);
  }

  if(clean)
  {
    has_child = tgh_clean(files, &pid);
  }

  if(clone)
  {
    has_child = tgh_clone(files, &pid);
  }

  if(log)
  {
    has_child = tgh_log(files, &pid);
  }

  if(move)
  {
    has_child = tgh_move(files, &pid);
  }

  if(reset)
  {
    has_child = tgh_reset(files, &pid);
  }

  if(stash)
  {
    has_child = tgh_stash(files, &pid);
  }

  if(status)
  {
    has_child = tgh_status(files, &pid);
  }

  if(has_child)
  {
    gtk_main ();

    tgh_replace_child(FALSE, 0);
  }

  return EXIT_SUCCESS;
}