aboutsummaryrefslogtreecommitdiffstats
path: root/src/ephy-automation.c
blob: 529b1854e3ad7350e88a6c1af752448cd6a94e5d (plain) (blame)
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/*
 *  Copyright (C) 2000, 2001, 2002 Marco Pesenti Gritti
 *
 *  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, 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.
 *
 *  $Id$
 */

#include "ephy-automation.h"
#include "ephy-shell.h"
#include "EphyAutomation.h"
#include "ephy-embed.h"
#include "ephy-window.h"
#include "session.h"

#include <string.h>
#include <bonobo/bonobo-generic-factory.h>
#include <bonobo/bonobo-main.h>
#include <bonobo/bonobo-context.h>

static void
impl_ephy_automation_add_bookmark (PortableServer_Servant _servant,
                   const CORBA_char * url,
                   CORBA_Environment * ev);
static void
impl_ephy_automation_quit (PortableServer_Servant _servant,
                           const CORBA_boolean disableServer,
                           CORBA_Environment * ev);
static void
impl_ephy_automation_load_session (PortableServer_Servant _servant,
                   const CORBA_char * filename,
                   CORBA_Environment * ev);
static void
ephy_automation_class_init (EphyAutomationClass *klass);
static void
ephy_automation_init (EphyAutomation *a);
static void
ephy_automation_object_finalize (GObject *object);
static BonoboObject *
ephy_automation_factory (BonoboGenericFactory *this_factory,
             const char *iid,
             gpointer user_data);

static GObjectClass *ephy_automation_parent_class;

#define EPHY_FACTORY_OAFIID "OAFIID:GNOME_Epiphany_Automation_Factory"

static BonoboObject *
ephy_automation_factory (BonoboGenericFactory *this_factory,
             const char *iid,
             gpointer user_data)
{
        EphyAutomation *a;

        a  = g_object_new (EPHY_TYPE_AUTOMATION, NULL);

        return BONOBO_OBJECT(a);
}

BonoboObject *
ephy_automation_new (void)
{
    BonoboGenericFactory   *factory;

    factory = bonobo_generic_factory_new (EPHY_FACTORY_OAFIID,
                          ephy_automation_factory,
                          NULL);

    g_return_val_if_fail (factory != NULL, NULL);

    return BONOBO_OBJECT (factory);
}

static void
impl_ephy_automation_loadurl (PortableServer_Servant _servant,
                  const CORBA_char * url,
                  const CORBA_boolean fullscreen,
                  const CORBA_boolean open_in_existing_tab,
                  const CORBA_boolean open_in_new_window,
                  const CORBA_boolean open_in_new_tab,
                  const CORBA_boolean raise,
                              CORBA_Environment * ev)
{
    EphyNewTabFlags flags = 0;
    EphyWindow *window;
    Session *session;

    session = EPHY_SESSION (ephy_shell_get_session (ephy_shell));

    /* no window open, let's try to autoresume */
    if (session_get_windows (session) == NULL)
    {
        gboolean res;
        res = session_autoresume (session);
        /* no need to open the homepage,
         * we did already open session windows */
        if (res && *url == '\0') return;
    }

    window = ephy_shell_get_active_window (ephy_shell);

    if (open_in_existing_tab && window != NULL)
    {
        ephy_window_load_url (window, url);
        return;
    }

    if (*url == '\0')
    {
        flags |= EPHY_NEW_TAB_HOME_PAGE;
    }
    else
    {
        flags |= EPHY_NEW_TAB_OPEN_PAGE;
    }

    if (open_in_new_tab)
    {
        flags |= EPHY_NEW_TAB_IN_EXISTING_WINDOW;
    }
    else
    {
        flags |= EPHY_NEW_TAB_IN_NEW_WINDOW;
    }

    if (fullscreen)
    {
        flags |= EPHY_NEW_TAB_FULLSCREEN_MODE;
    }

    ephy_shell_new_tab (ephy_shell, window, NULL, url,
                flags);
}

static void
impl_ephy_automation_add_bookmark (PortableServer_Servant _servant,
                   const CORBA_char * url,
                   CORBA_Environment * ev)
{
}

static void
impl_ephy_automation_quit (PortableServer_Servant _servant,
                           const CORBA_boolean disableServer,
                           CORBA_Environment * ev)
{
    Session *session;

    session = EPHY_SESSION (ephy_shell_get_session (ephy_shell));

    session_close (session);
}

static void
impl_ephy_automation_load_session (PortableServer_Servant _servant,
                   const CORBA_char * filename,
                   CORBA_Environment * ev)
{
    Session *session;

    session = EPHY_SESSION (ephy_shell_get_session (ephy_shell));
    session_load (session, filename);
}

static void
impl_ephy_automation_open_bookmarks_editor (PortableServer_Servant _servant,
                        CORBA_Environment * ev)
{
    ephy_shell_show_bookmarks_editor (ephy_shell, NULL);
}

static void
ephy_automation_class_init (EphyAutomationClass *klass)
{
        GObjectClass *object_class = (GObjectClass *) klass;
        POA_GNOME_EphyAutomation__epv *epv = &klass->epv;

        ephy_automation_parent_class = g_type_class_peek_parent (klass);

        object_class->finalize = ephy_automation_object_finalize;

        /* connect implementation callbacks */
        epv->loadurl = impl_ephy_automation_loadurl;
    epv->addBookmark = impl_ephy_automation_add_bookmark;
    epv->quit = impl_ephy_automation_quit;
    epv->loadSession = impl_ephy_automation_load_session;
    epv->openBookmarksEditor = impl_ephy_automation_open_bookmarks_editor;
}

static void
ephy_automation_init (EphyAutomation *c)
{
}

static void
ephy_automation_object_finalize (GObject *object)
{
        EphyAutomation *a = EPHY_AUTOMATION (object);

        ephy_automation_parent_class->finalize (G_OBJECT (a));
}

BONOBO_TYPE_FUNC_FULL (
        EphyAutomation,
        GNOME_EphyAutomation,
        BONOBO_TYPE_OBJECT,
        ephy_automation);