File: rbgnome-url.c

package info (click to toggle)
ruby-gnome2 0.15.0-1.1etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 7,704 kB
  • ctags: 8,558
  • sloc: ansic: 69,912; ruby: 19,511; makefile: 97; xml: 35; sql: 13
file content (80 lines) | stat: -rw-r--r-- 2,424 bytes parent folder | download | duplicates (3)
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
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
/* $Id: rbgnome-url.c,v 1.6 2005/09/24 18:02:43 mutoh Exp $ */

/* Gnome::URL module for Ruby/Gnome
 * Copyright (C) 2002-2005 Ruby-GNOME2 Project Team
 * Copyright (C) 2001      Neil Conway <neilconway@rogers.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "rbgnome.h"

static VALUE
url_show(argc, argv, self)
    int argc;
    VALUE *argv;
    VALUE self;
{
  VALUE url, env;

    GError *error = NULL;
    gboolean result;

    rb_scan_args(argc, argv, "11", &url, &env);

    if (NIL_P(env)){
        result = gnome_url_show((const char*)RVAL2CSTR(url), &error);
    } else {
#if GNOME_CHECK_VERSION(2,6,0)
      int i, genc;
      char** genvp;
      
      Check_Type(env, T_ARRAY);
      genc = RARRAY(env)->len;

      genvp = ALLOCA_N(gchar*, genc + 1);
      
      for (i = 0; i < genc; i++) {
        if (TYPE(RARRAY(env)->ptr[i]) == T_STRING) {
          genvp[i] = RVAL2CSTR(RARRAY(env)->ptr[i]);
        }
        else {
          genvp[i] = "";
        }
        genvp[genc] = (gchar*)NULL;
      }
      result = gnome_url_show_with_env((const char*)RVAL2CSTR(url), genvp, &error);
#else
      rb_warn("Ignored 5th argument under this environment. Because it has been supported since GNOME-2.6.");
      result = gnome_url_show((const char*)RVAL2CSTR(url), &error);
#endif      
    }
    if (!result)
        RAISE_GERROR(error);
    return self;
}

void
Init_gnome_url(mGnome)
     VALUE mGnome;
{
    VALUE mGnomeURL = rb_define_module_under(mGnome, "URL");
    rb_define_module_function(mGnomeURL, "show", url_show, -1);

    G_DEF_ERROR(GNOME_URL_ERROR, "URLError", mGnome, rb_eRuntimeError,
                GNOME_TYPE_URL_ERROR);

}