File: main.c

package info (click to toggle)
coriander 1.0.1-3.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,376 kB
  • ctags: 943
  • sloc: ansic: 10,305; sh: 3,030; makefile: 131
file content (143 lines) | stat: -rw-r--r-- 4,211 bytes parent folder | download
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
/*
 *                     C  O  R  I  A  N  D  E  R
 *
 *            -- The IEEE-1394 Digital Camera controller --
 *
 * Copyright (C) 2000-2004 Damien Douxchamps  <ddouxchamps@users.sf.net>
 *               Ftp and conversions by Dan Dennedy <ddennedy@coolsite.net>
 *
 * 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.
 */

#include "coriander.h"

int
main (int argc, char *argv[])
{
  int i;
  int main_timeout;
  GtkWidget* err_window;

  main_timeout_ticker=0;
  WM_cancel_display=0;
  cameras=NULL;
  silent_ui_update=0;

#ifdef ENABLE_NLS
  bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
  textdomain (PACKAGE);
#endif
  gnome_init ("coriander", VERSION, argc, argv);

  businfo=(BusInfo_t*)malloc(sizeof(BusInfo_t));
  businfo->handles=NULL;
  businfo->port_camera_num=NULL;
  businfo->camera_nodes=NULL;
  businfo->card_found=0;

  GetXvInfo(&xvinfo);
  //fprintf(stderr,"%d %d\n", xvinfo.max_height, xvinfo.max_width);

  GetCameraNodes(businfo);

  // it seems that freeing some vars before a return() or an exit() prevent the program from exiting.
  // this only happens on some platforms, but I cleared the free() anyway.
  if (businfo->card_found==0) {
    err_window=create_no_handle_window();
    gtk_signal_connect(GTK_OBJECT(err_window), "realize",
		       GTK_SIGNAL_FUNC(window_set_icon), err_window);
    gtk_widget_show(err_window);
    gtk_main();
    free(businfo);
    return(1);
  }
  else {
    if (businfo->camera_num<1) {
    err_window=create_no_camera_window();
    gtk_signal_connect(GTK_OBJECT(err_window), "realize",
		       GTK_SIGNAL_FUNC(window_set_icon), err_window);
      gtk_widget_show(err_window);
      gtk_main();
      
      for (i=0;i<businfo->port_num;i++)
	free(businfo->camera_nodes[i]);
      free(businfo->camera_nodes);
      free(businfo->port_camera_num);
      free(businfo->handles);
      free(businfo);
      
      return(1);
    }
  }

  LoadConfigFile();

  // we have at least one camera on one interface card.
  // get camera infos and serialize the port info for each camera
  GetCamerasInfo(businfo);

  GrabSelfIds(businfo->handles, businfo->port_num);

  SetChannels();
  // current camera is the first camera:
  SetCurrentCamera(cameras->camera_info.euid_64);
  
  preferences_window= create_preferences_window();
  main_window = create_main_window();
  gtk_signal_connect(GTK_OBJECT(main_window), "realize",
		     GTK_SIGNAL_FUNC(window_set_icon), main_window);
  
  format7_tab_presence=1;
  gtk_notebook_set_homogeneous_tabs(GTK_NOTEBOOK(lookup_widget(main_window,"notebook2")),TRUE);
  gtk_notebook_set_homogeneous_tabs(GTK_NOTEBOOK(lookup_widget(main_window,"notebook5")),TRUE);

  // Setup the GUI in accordance with the camera capabilities
  GetContextStatus();
  BuildAllWindows();
  UpdateAllWindows();

  MainStatus("Welcome to Coriander...");
  gtk_widget_show (main_window); // this is the only window shown at boot-time
  
  main_timeout=gtk_timeout_add(10, (GtkFunction)main_timeout_handler, (gpointer*)businfo->port_num);

#ifdef HAVE_SDLLIB
  WatchStartThread(&watchthread_info);
#endif

  gtk_main();

  gtk_timeout_remove(main_timeout);
  
#ifdef HAVE_SDLLIB
  WatchStopThread(&watchthread_info);
#endif

  while (cameras!=NULL) {
    RemoveCamera(cameras->camera_info.euid_64);
  }
  
  for (i=0;i<businfo->port_num;i++) {
    if (businfo->handles[i]!=0)
      raw1394_destroy_handle(businfo->handles[i]);
    free(businfo->camera_nodes[i]);
  }
  
  free(businfo->camera_nodes);
  free(businfo->handles);
  free(businfo->port_camera_num);
  
  return 0;
}