~ubuntu-branches/debian/sid/cheese/sid

« back to all changes in this revision

Viewing changes to src/cheese-main.vala

  • Committer: Bazaar Package Importer
  • Author(s): Laurent Bigonville
  • Date: 2011-07-17 21:04:16 UTC
  • mfrom: (15.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20110717210416-nt5qi659qei7a2yy
Tags: 3.0.1-2
* debian/control.in:
  - Change gir1.2-cheese-3.0 Section to libs
  - Make library packages depend against cheese-common package
  - Make cheese package recommends against hicolor-icon-theme
  - Move gst Dependency to libcheese package
* debian/patches/0002-fix-linking.patch: Add missing library to fix linking
* debian/watch:
  - Switch to .bz2 tarballs.
  - Bump version to 3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2010 Yuvaraj Pandian T <yuvipanda@yuvi.in>
 
3
 * Copyright © 2010 daniel g. siegel <dgsiegel@gnome.org>
 
4
 * Copyright © 2008 Filippo Argiolas <filippo.argiolas@gmail.com>
 
5
 *
 
6
 * Licensed under the GNU General Public License Version 2
 
7
 *
 
8
 * This program is free software; you can redistribute it and/or modify
 
9
 * it under the terms of the GNU General Public License as published by
 
10
 * the Free Software Foundation; either version 2 of the License, or
 
11
 * (at your option) any later version.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public License
 
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
 */
 
21
 
 
22
using GLib;
 
23
using Gtk;
 
24
using Clutter;
 
25
using Gst;
 
26
 
 
27
public class Cheese.Main : Gtk.Application
 
28
{
 
29
  static bool   wide;
 
30
  static string device;
 
31
  static bool   version;
 
32
  static bool   fullscreen;
 
33
 
 
34
  static Cheese.MainWindow main_window;
 
35
 
 
36
  const OptionEntry[] options = {
 
37
    {"wide",       'w', 0, OptionArg.NONE,     ref wide,       N_("Start in wide mode"),                  null        },
 
38
    {"device",     'd', 0, OptionArg.FILENAME, ref device,     N_("Device to use as a camera"),           N_("DEVICE")},
 
39
    {"version",    'v', 0, OptionArg.NONE,     ref version,    N_("Output version information and exit"), null        },
 
40
    {"fullscreen", 'f', 0, OptionArg.NONE,     ref fullscreen, N_("Start in fullscreen mode"),            null        },
 
41
    {null}
 
42
  };
 
43
 
 
44
  public Main (string app_id, ApplicationFlags flags)
 
45
  {
 
46
    GLib.Object (application_id: app_id, flags: flags);
 
47
  }
 
48
 
 
49
  public void on_app_activate ()
 
50
  {
 
51
    if (get_windows () != null)
 
52
      main_window.present ();
 
53
    else
 
54
    {
 
55
      main_window = new Cheese.MainWindow ();
 
56
 
 
57
      Environment.set_application_name (_("Cheese"));
 
58
      Window.set_default_icon_name ("cheese");
 
59
 
 
60
      Gtk.IconTheme.get_default ().append_search_path (GLib.Path.build_filename (Config.PACKAGE_DATADIR, "icons"));
 
61
 
 
62
      main_window.setup_ui ();
 
63
 
 
64
      if (wide)
 
65
        main_window.set_startup_wide_mode ();
 
66
      if (fullscreen)
 
67
        main_window.set_startup_fullscreen_mode ();
 
68
 
 
69
      main_window.set_application (this);
 
70
      main_window.destroy.connect (Gtk.main_quit);
 
71
      main_window.show ();
 
72
      main_window.setup_camera (device);
 
73
     }
 
74
  }
 
75
 
 
76
  public override bool local_command_line ([CCode (array_null_terminated = true, array_length = false)]
 
77
                                           ref unowned string[] arguments,
 
78
                                           out int exit_status)
 
79
  {
 
80
    // Try to register.
 
81
    try
 
82
    {
 
83
      register();
 
84
    }
 
85
    catch (Error e)
 
86
    {
 
87
      stdout.printf ("Error: %s\n", e.message);
 
88
      exit_status = 1;
 
89
      return true;
 
90
    }
 
91
 
 
92
    // Workaround until bug 642885 is solved.
 
93
    unowned string[] local_args = arguments;
 
94
 
 
95
    // Check command line parameters.
 
96
    int n_args = local_args.length;
 
97
    if (n_args <= 1)
 
98
    {
 
99
      Gst.init (ref local_args);
 
100
      activate ();
 
101
      exit_status = 0;
 
102
    }
 
103
    else
 
104
    {
 
105
      // Set parser.
 
106
      try
 
107
      {
 
108
        var context = new OptionContext (_("- Take photos and videos from your webcam"));
 
109
        context.set_help_enabled (true);
 
110
        context.add_main_entries (options, null);
 
111
        context.add_group (Gtk.get_option_group (true));
 
112
        context.add_group (Clutter.get_option_group ());
 
113
        context.add_group (Gst.init_get_option_group ());
 
114
        context.parse (ref local_args);
 
115
      }
 
116
      catch (OptionError e)
 
117
      {
 
118
        stdout.printf ("%s\n", e.message);
 
119
        stdout.printf (_("Run '%s --help' to see a full list of available command line options.\n"), arguments[0]);
 
120
        exit_status = 1;
 
121
        return true;
 
122
      }
 
123
 
 
124
      if (version)
 
125
      {
 
126
        stdout.printf ("%s %s\n", Config.PACKAGE_NAME, Config.PACKAGE_VERSION);
 
127
        exit_status = 1;
 
128
        return true;
 
129
      }
 
130
 
 
131
      //Remote instance process commands locally.
 
132
      if (get_is_remote ())
 
133
      {
 
134
          stdout.printf (_("Another instance of Cheese is currently running\n"));
 
135
          exit_status = 1;
 
136
          return true;
 
137
      }
 
138
      //Primary instance.
 
139
      else
 
140
      {
 
141
        Gst.init (ref local_args);
 
142
        activate ();
 
143
        exit_status=0;
 
144
      }
 
145
    }
 
146
    return true;
 
147
  }
 
148
}
 
149
 
 
150
  public int main (string[] args)
 
151
  {
 
152
    Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.PACKAGE_LOCALEDIR);
 
153
    Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
 
154
    Intl.textdomain (Config.GETTEXT_PACKAGE);
 
155
 
 
156
    GtkClutter.init (ref args);
 
157
 
 
158
    Cheese.Main app;
 
159
    app = new Cheese.Main ("org.gnome.Cheese", ApplicationFlags.FLAGS_NONE);
 
160
 
 
161
    app.activate.connect (app.on_app_activate);
 
162
    int status = app.run (args);
 
163
 
 
164
    return status;
 
165
  }