~ubuntu-branches/debian/sid/grip/sid

« back to all changes in this revision

Viewing changes to src/main.c

  • Committer: Package Import Robot
  • Author(s): Tiago Ilieve
  • Date: 2016-04-04 14:26:23 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20160404142623-zw16rooy7z3xadvu
Tags: 4.1.0-1
Initial release (Closes: #790611)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* main.c
2
 
 *
3
 
 * Copyright (c) 1998-2004  Mike Oliphant <grip@nostatic.org>
4
 
 *
5
 
 *   http://www.nostatic.org/grip
6
 
 *
7
 
 * This program is free software; you can redistribute it and/or 
8
 
 * modify it under the terms of the GNU General Public License as 
9
 
 * published by the Free Software Foundation; either version 2 of the
10
 
 * License, or (at your option) any later version.
11
 
 *
12
 
 * This program is distributed in the hope that it will be useful,
13
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
 * GNU General Public License for more details.
16
 
 *
17
 
 * You should have received a copy of the GNU General Public License
18
 
 * along with this program; if not, write to the Free Software
19
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20
 
 * USA
21
 
 */
22
 
 
23
 
#include <config.h>
24
 
#include <gnome.h>
25
 
#include <stdlib.h>
26
 
 
27
 
#include "grip.h"
28
 
 
29
 
static gint KillSession(GnomeClient* client, gpointer client_data);
30
 
static gint SaveSession(GnomeClient *client, gint phase, 
31
 
                        GnomeSaveStyle save_style,
32
 
                        gint is_shutdown, GnomeInteractStyle interact_style,
33
 
                        gint is_fast, gpointer client_data);
34
 
static gint TimeOut(gpointer data);
35
 
 
36
 
gboolean do_debug=TRUE;
37
 
GtkWidget* grip_app;
38
 
 
39
 
/* popt table */
40
 
static char *geometry=NULL;
41
 
static char *config_filename=NULL;
42
 
static char *device=NULL;
43
 
static char *scsi_device=NULL;
44
 
static int force_small=FALSE;
45
 
static int local_mode=FALSE;
46
 
static int no_redirect=FALSE;
47
 
static int verbose=FALSE;
48
 
 
49
 
struct poptOption options[] = {
50
 
  { 
51
 
    "geometry",
52
 
    '\0',
53
 
    POPT_ARG_STRING,
54
 
    &geometry,
55
 
    0,
56
 
    N_("Specify the geometry of the main window"),
57
 
    N_("GEOMETRY")
58
 
  },
59
 
  {
60
 
    "config",
61
 
    '\0',
62
 
    POPT_ARG_STRING,
63
 
    &config_filename,
64
 
    0,
65
 
    N_("Specify the config file to use (in your home dir)"),
66
 
    N_("CONFIG")
67
 
  },
68
 
  { 
69
 
    "device",
70
 
    '\0',
71
 
    POPT_ARG_STRING,
72
 
    &device,
73
 
    0,
74
 
    N_("Specify the cdrom device to use"),
75
 
    N_("DEVICE")
76
 
  },
77
 
  { 
78
 
    "scsi-device",
79
 
    '\0',
80
 
    POPT_ARG_STRING,
81
 
    &scsi_device,
82
 
    0,
83
 
    N_("Specify the generic scsi device to use"),
84
 
    N_("DEVICE")
85
 
  },
86
 
  { 
87
 
    "small",
88
 
    '\0',
89
 
    POPT_ARG_NONE,
90
 
    &force_small,
91
 
    0,
92
 
    N_("Launch in \"small\" (cd-only) mode"),
93
 
    NULL
94
 
  },
95
 
  { 
96
 
    "local",
97
 
    '\0',
98
 
    POPT_ARG_NONE,
99
 
    &local_mode,
100
 
    0,
101
 
    N_("\"Local\" mode -- do not look up disc info on the net"),
102
 
    NULL
103
 
  },
104
 
  { 
105
 
    "no-redirect",
106
 
    '\0',
107
 
    POPT_ARG_NONE,
108
 
    &no_redirect,
109
 
    0,
110
 
    N_("Do not do I/O redirection"),
111
 
    NULL
112
 
  },
113
 
  { 
114
 
    "verbose",
115
 
    '\0',
116
 
    POPT_ARG_NONE,
117
 
    &verbose,
118
 
    0,
119
 
    N_("Run in verbose (debug) mode"),
120
 
    NULL
121
 
  },
122
 
  {
123
 
    NULL,
124
 
    '\0',
125
 
    0,
126
 
    NULL,
127
 
    0,
128
 
    NULL,
129
 
    NULL
130
 
  }
131
 
};
132
 
 
133
 
void Debug(char *fmt,...)
134
 
{
135
 
  va_list args;
136
 
  char *msg;
137
 
 
138
 
  if(do_debug) {
139
 
    va_start(args,fmt);
140
 
 
141
 
    msg=g_strdup_vprintf(fmt,args);
142
 
    if(msg) {
143
 
      g_printerr(msg);
144
 
      g_free(msg);
145
 
    }
146
 
  }
147
 
 
148
 
  va_end(args);
149
 
}
150
 
 
151
 
int Cmain(int argc, char* argv[])
152
 
{
153
 
  GnomeClient *client;
154
 
 
155
 
  /* Unbuffer stdout */
156
 
  setvbuf(stdout, 0, _IONBF, 0);
157
 
 
158
 
  /* setup locale, i18n */
159
 
  gtk_set_locale();
160
 
  bindtextdomain(GETTEXT_PACKAGE,GNOMELOCALEDIR);
161
 
  textdomain(GETTEXT_PACKAGE);
162
 
 
163
 
  gnome_program_init(PACKAGE,VERSION,LIBGNOMEUI_MODULE,argc,argv, 
164
 
                     GNOME_PARAM_POPT_TABLE,options,
165
 
                     GNOME_PROGRAM_STANDARD_PROPERTIES,NULL);
166
 
 
167
 
  bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF8");
168
 
  setenv("CHARSET","UTF-8",1);
169
 
 
170
 
  /* Session Management */
171
 
  
172
 
  client=gnome_master_client();
173
 
  gtk_signal_connect(GTK_OBJECT(client),"save_yourself",
174
 
                     GTK_SIGNAL_FUNC(SaveSession),argv[0]);
175
 
  gtk_signal_connect(GTK_OBJECT(client),"die",
176
 
                     GTK_SIGNAL_FUNC(KillSession),NULL);
177
 
  
178
 
 
179
 
  do_debug=verbose;
180
 
 
181
 
  if(scsi_device) printf("scsi=[%s]\n",scsi_device);
182
 
 
183
 
  /* Start a new Grip app */
184
 
  grip_app=GripNew(geometry,device,scsi_device,config_filename,
185
 
                   force_small,local_mode,
186
 
                   no_redirect);
187
 
 
188
 
  gtk_widget_show(grip_app);
189
 
 
190
 
  gtk_timeout_add(1000,TimeOut,0);
191
 
 
192
 
  gtk_main();
193
 
 
194
 
  return 0;
195
 
}
196
 
 
197
 
/* Save the session */
198
 
static gint SaveSession(GnomeClient *client, gint phase,
199
 
                        GnomeSaveStyle save_style,
200
 
                        gint is_shutdown, GnomeInteractStyle interact_style,
201
 
                        gint is_fast, gpointer client_data)
202
 
{
203
 
  gchar** argv;
204
 
  guint argc;
205
 
 
206
 
  /* allocate 0-filled, so it will be NULL-terminated */
207
 
  argv = g_malloc0(sizeof(gchar*)*4);
208
 
  argc = 1;
209
 
 
210
 
  argv[0] = client_data;
211
 
 
212
 
  gnome_client_set_clone_command(client, argc, argv);
213
 
  gnome_client_set_restart_command(client, argc, argv);
214
 
 
215
 
  return TRUE;
216
 
}
217
 
 
218
 
/* Kill Session */
219
 
static gint KillSession(GnomeClient* client, gpointer client_data)
220
 
{
221
 
  gtk_main_quit();
222
 
 
223
 
  return TRUE;
224
 
}
225
 
 
226
 
static gint TimeOut(gpointer data)
227
 
{
228
 
  GripUpdate(grip_app);
229
 
 
230
 
  return TRUE;
231
 
}