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

« back to all changes in this revision

Viewing changes to src/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Taku YASUI
  • Date: 2002-04-15 12:34:02 UTC
  • Revision ID: james.westby@ubuntu.com-20020415123402-868ezmdfi1yzu1tv
Tags: upstream-3.0.0
ImportĀ upstreamĀ versionĀ 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* main.c
 
2
 *
 
3
 * Copyright (c) 1998-2002  Mike Oliphant <oliphant@gtk.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
 
 
26
#include "grip.h"
 
27
 
 
28
static gint KillSession(GnomeClient* client, gpointer client_data);
 
29
static gint SaveSession(GnomeClient *client, gint phase, 
 
30
                        GnomeSaveStyle save_style,
 
31
                        gint is_shutdown, GnomeInteractStyle interact_style,
 
32
                        gint is_fast, gpointer client_data);
 
33
static gint TimeOut(gpointer data);
 
34
 
 
35
gboolean do_debug=TRUE;
 
36
GtkWidget* grip_app;
 
37
 
 
38
/* popt table */
 
39
static char *geometry=NULL;
 
40
static char *device=NULL;
 
41
static char *scsi_device=NULL;
 
42
static int force_small=FALSE;
 
43
static int local_mode=FALSE;
 
44
static int no_redirect=FALSE;
 
45
static int verbose=FALSE;
 
46
 
 
47
struct poptOption options[] = {
 
48
  { 
 
49
    "geometry",
 
50
    '\0',
 
51
    POPT_ARG_STRING,
 
52
    &geometry,
 
53
    0,
 
54
    N_("Specify the geometry of the main window"),
 
55
    N_("GEOMETRY")
 
56
  },
 
57
  { 
 
58
    "device",
 
59
    '\0',
 
60
    POPT_ARG_STRING,
 
61
    &device,
 
62
    0,
 
63
    N_("Specify the cdrom device to use"),
 
64
    N_("DEVICE")
 
65
  },
 
66
  { 
 
67
    "scsi-device",
 
68
    '\0',
 
69
    POPT_ARG_STRING,
 
70
    &scsi_device,
 
71
    0,
 
72
    N_("Specify the generic scsi device to use"),
 
73
    N_("DEVICE")
 
74
  },
 
75
  { 
 
76
    "small",
 
77
    '\0',
 
78
    POPT_ARG_NONE,
 
79
    &force_small,
 
80
    0,
 
81
    N_("Launch in \"small\" (cd-only) mode"),
 
82
    NULL
 
83
  },
 
84
  { 
 
85
    "local",
 
86
    '\0',
 
87
    POPT_ARG_NONE,
 
88
    &local_mode,
 
89
    0,
 
90
    N_("\"Local\" mode -- do not look up disc info on the net"),
 
91
    NULL
 
92
  },
 
93
  { 
 
94
    "no-redirect",
 
95
    '\0',
 
96
    POPT_ARG_NONE,
 
97
    &no_redirect,
 
98
    0,
 
99
    N_("Do not do I/O redirection"),
 
100
    NULL
 
101
  },
 
102
  { 
 
103
    "verbose",
 
104
    '\0',
 
105
    POPT_ARG_NONE,
 
106
    &verbose,
 
107
    0,
 
108
    N_("Run in verbose (debug) mode"),
 
109
    NULL
 
110
  },
 
111
  {
 
112
    NULL,
 
113
    '\0',
 
114
    0,
 
115
    NULL,
 
116
    0,
 
117
    NULL,
 
118
    NULL
 
119
  }
 
120
};
 
121
 
 
122
void Debug(char *fmt,...)
 
123
{
 
124
  va_list args;
 
125
 
 
126
  if(do_debug) {
 
127
    va_start(args,fmt);
 
128
 
 
129
    vfprintf(stderr,fmt,args);
 
130
  }
 
131
 
 
132
  va_end(args);
 
133
}
 
134
 
 
135
int Cmain(int argc, char* argv[])
 
136
{
 
137
  poptContext pctx;
 
138
  char** args;
 
139
  GnomeClient *client;
 
140
 
 
141
  /* Unbuffer stdout */
 
142
  setvbuf(stdout, 0, _IONBF, 0);
 
143
 
 
144
  /* setup locale, i18n */
 
145
  gtk_set_locale();
 
146
  bindtextdomain(PACKAGE,GNOMELOCALEDIR);  
 
147
  textdomain(PACKAGE);
 
148
 
 
149
  gnome_init_with_popt_table(PACKAGE,VERSION,argc,argv, 
 
150
                             options,0,&pctx);  
 
151
 
 
152
  /* Parse args */
 
153
 
 
154
  args=(char **)poptGetArgs(pctx);
 
155
 
 
156
  poptFreeContext(pctx);
 
157
 
 
158
  /* Session Management */
 
159
  
 
160
  client=gnome_master_client();
 
161
  gtk_signal_connect(GTK_OBJECT(client),"save_yourself",
 
162
                     GTK_SIGNAL_FUNC(SaveSession),argv[0]);
 
163
  gtk_signal_connect(GTK_OBJECT(client),"die",
 
164
                     GTK_SIGNAL_FUNC(KillSession),NULL);
 
165
  
 
166
 
 
167
  do_debug=verbose;
 
168
 
 
169
  if(scsi_device) printf("scsi=[%s]\n",scsi_device);
 
170
 
 
171
  /* Start a new Grip app */
 
172
  grip_app=GripNew(geometry,device,scsi_device,force_small,local_mode,
 
173
                   no_redirect);
 
174
 
 
175
  gtk_widget_show(grip_app);
 
176
 
 
177
  gtk_timeout_add(1000,TimeOut,0);
 
178
 
 
179
  gtk_main();
 
180
 
 
181
  return 0;
 
182
}
 
183
 
 
184
/* Save the session */
 
185
static gint SaveSession(GnomeClient *client, gint phase,
 
186
                        GnomeSaveStyle save_style,
 
187
                        gint is_shutdown, GnomeInteractStyle interact_style,
 
188
                        gint is_fast, gpointer client_data)
 
189
{
 
190
  gchar** argv;
 
191
  guint argc;
 
192
 
 
193
  /* allocate 0-filled, so it will be NULL-terminated */
 
194
  argv = g_malloc0(sizeof(gchar*)*4);
 
195
  argc = 1;
 
196
 
 
197
  argv[0] = client_data;
 
198
 
 
199
  gnome_client_set_clone_command(client, argc, argv);
 
200
  gnome_client_set_restart_command(client, argc, argv);
 
201
 
 
202
  return TRUE;
 
203
}
 
204
 
 
205
/* Kill Session */
 
206
static gint KillSession(GnomeClient* client, gpointer client_data)
 
207
{
 
208
  gtk_main_quit();
 
209
 
 
210
  return TRUE;
 
211
}
 
212
 
 
213
static gint TimeOut(gpointer data)
 
214
{
 
215
  GripUpdate(grip_app);
 
216
 
 
217
  return TRUE;
 
218
}