summaryrefslogtreecommitdiff
path: root/player/swfdec-player.c
blob: 0e3036b687fcd1cf6297bb389708a45717edd4b2 (plain)
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
/* Swfdec Player
 * Copyright (C) 2006 Benjamin Otte <otte@gnome.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., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301, USA.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdlib.h>
#include <string.h>
#include <glib/gi18n.h>
#include "swfdec-window.h"

static char *
sanitize_url (const char *s)
{
  if (strstr (s, "://")) {
    return g_strdup (s);
  } else {
    char *dir, *full;
    if (g_path_is_absolute (s))
      return g_strconcat ("file://", s, NULL);
    dir = g_get_current_dir ();
    full = g_strconcat ("file://", dir, G_DIR_SEPARATOR_S, s, NULL);
    g_free (dir);
    return full;
  }
}

int 
main (int argc, char *argv[])
{
  SwfdecWindowSettings settings = { TRUE, TRUE };
  GError *error = NULL;
  char **filenames = NULL;
  SwfdecWindow *window;
  guint i;
  char *s;

  GOptionEntry options[] = {
    { "no-sound", 'n', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &settings.sound, N_("don't play sound"), NULL },
    { "paused", 'p', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &settings.playing, N_("start player paused"), NULL },
    { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &filenames, NULL, "<FILE> [<FILE> ...]" },
    { NULL }
  };
  GOptionContext *ctx;

  g_set_application_name (_("Swfdec Flash Player"));
  ctx = g_option_context_new ("");
  g_option_context_set_translation_domain (ctx, GETTEXT_PACKAGE);
  g_option_context_add_main_entries (ctx, options, "options");
  g_option_context_add_group (ctx, gtk_get_option_group (TRUE));
  g_option_context_parse (ctx, &argc, &argv, &error);
  g_option_context_free (ctx);

  if (error) {
    g_printerr ("Error parsing command line arguments: %s\n", error->message);
    g_error_free (error);
    return EXIT_FAILURE;
  }

  swfdec_init ();

  if (filenames == NULL) {
    /* open an empty window if no args */
    window = swfdec_window_new (NULL);
    swfdec_window_set_settings (window, &settings);
  } else {
    for (i = 0; filenames[i]; i++) {
      s = sanitize_url (filenames[i]);
      window = swfdec_window_new (s);
      g_free (s);
      swfdec_window_set_settings (window, &settings);
    }
    g_strfreev (filenames);
  }

  gtk_main ();

  return EXIT_SUCCESS;
}