Initial import of ephy (rev# 7126) from svn
[ephy-soc.git] / src / ephy-automation.c
blobc617295c2f0e38ae7280b39e3ff53235b3b26280
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * Copyright © 2000, 2001, 2002 Marco Pesenti Gritti
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * $Id: ephy-automation.c 6952 2007-03-11 19:42:02Z chpe $
22 #include "config.h"
24 #include "ephy-automation.h"
26 #include "EphyAutomation.h"
27 #include "ephy-shell.h"
28 #include "ephy-embed.h"
29 #include "ephy-window.h"
30 #include "ephy-session.h"
31 #include "ephy-bookmarks.h"
32 #include "ephy-bookmarks-import.h"
33 #include "eel-gconf-extensions.h"
34 #include "ephy-prefs.h"
35 #include "ephy-gui.h"
37 #include <string.h>
38 #include <bonobo/bonobo-main.h>
39 #include <bonobo/bonobo-context.h>
41 static void ephy_automation_class_init (EphyAutomationClass *klass);
43 static GObjectClass *parent_class = NULL;
45 static void
46 impl_ephy_automation_loadUrlWithStartupId (PortableServer_Servant _servant,
47 const CORBA_char *url,
48 const CORBA_boolean fullscreen,
49 const CORBA_boolean open_in_existing_tab,
50 const CORBA_boolean open_in_new_tab,
51 const CORBA_unsigned_long startup_id,
52 CORBA_Environment *ev)
54 EphyNewTabFlags flags = 0;
55 EphyWindow *window;
56 EphySession *session;
57 guint32 user_time = (guint32) startup_id;
59 session = EPHY_SESSION (ephy_shell_get_session (ephy_shell));
60 g_return_if_fail (session != NULL);
62 if (eel_gconf_get_boolean (CONF_LOCKDOWN_DISABLE_ARBITRARY_URL))
64 url = "";
67 if (ephy_session_autoresume (session, user_time) && *url == '\0')
69 /* no need to open the homepage,
70 * we did already open session windows */
71 return;
74 window = ephy_session_get_active_window (session);
76 if (open_in_existing_tab && window != NULL)
78 ephy_gui_window_update_user_time (GTK_WIDGET (window),
79 user_time);
80 ephy_window_load_url (window, url);
81 return;
84 if (*url == '\0')
86 flags |= EPHY_NEW_TAB_HOME_PAGE;
88 else
90 flags |= EPHY_NEW_TAB_OPEN_PAGE;
93 if (open_in_new_tab)
95 flags |= EPHY_NEW_TAB_IN_EXISTING_WINDOW |
96 EPHY_NEW_TAB_JUMP;
98 else
100 flags |= EPHY_NEW_TAB_IN_NEW_WINDOW;
103 if (fullscreen)
105 flags |= EPHY_NEW_TAB_FULLSCREEN_MODE;
108 ephy_shell_new_tab_full (ephy_shell, window, NULL, url, flags,
109 EPHY_EMBED_CHROME_ALL, FALSE, user_time);
112 static void
113 impl_ephy_automation_loadurl (PortableServer_Servant _servant,
114 const CORBA_char *url,
115 const CORBA_boolean fullscreen,
116 const CORBA_boolean open_in_existing_tab,
117 const CORBA_boolean open_in_new_tab,
118 CORBA_Environment *ev)
120 impl_ephy_automation_loadUrlWithStartupId (_servant,
121 url,
122 fullscreen,
123 open_in_existing_tab,
124 open_in_new_tab,
125 0, /* no startup ID */
126 ev);
129 static void
130 impl_ephy_automation_addBookmark (PortableServer_Servant _servant,
131 const CORBA_char * url,
132 CORBA_Environment * ev)
134 ephy_bookmarks_add (ephy_shell_get_bookmarks (ephy_shell),
135 url /* title */, url);
138 static void
139 impl_ephy_automation_importBookmarks (PortableServer_Servant _servant,
140 const CORBA_char *filename,
141 CORBA_Environment *ev)
143 ephy_bookmarks_import (ephy_shell_get_bookmarks (ephy_shell),
144 filename);
147 static void
148 impl_ephy_automation_loadSessionWithStartupId (PortableServer_Servant _servant,
149 const CORBA_char *filename,
150 const CORBA_unsigned_long startup_id,
151 CORBA_Environment *ev)
153 EphySession *session;
154 guint32 user_time = (guint32) startup_id;
156 session = EPHY_SESSION (ephy_shell_get_session (ephy_shell));
157 ephy_session_load (session, filename, user_time);
160 static void
161 impl_ephy_automation_loadSession (PortableServer_Servant _servant,
162 const CORBA_char *filename,
163 CORBA_Environment *ev)
165 impl_ephy_automation_loadSessionWithStartupId (_servant,
166 filename,
167 0, /* no startup ID */
168 ev);
171 static void
172 impl_ephy_automation_openBookmarksEditorWithStartupId (PortableServer_Servant _servant,
173 const CORBA_unsigned_long startup_id,
174 CORBA_Environment *ev)
176 GtkWidget *editor;
177 guint32 user_time = (guint32) startup_id;
179 if (eel_gconf_get_boolean (CONF_LOCKDOWN_DISABLE_BOOKMARK_EDITING)) return;
181 editor = ephy_shell_get_bookmarks_editor (ephy_shell);
183 ephy_gui_window_update_user_time (editor, user_time);
185 gtk_window_present (GTK_WINDOW (editor));
188 static void
189 impl_ephy_automation_openBookmarksEditor (PortableServer_Servant _servant,
190 CORBA_Environment *ev)
192 impl_ephy_automation_openBookmarksEditorWithStartupId (_servant,
193 0, /* no startup ID */
194 ev);
197 static void
198 ephy_automation_init (EphyAutomation *c)
202 static void
203 ephy_automation_class_init (EphyAutomationClass *klass)
205 POA_GNOME_EphyAutomation__epv *epv = &klass->epv;
207 parent_class = g_type_class_peek_parent (klass);
209 /* connect implementation callbacks */
210 epv->loadurl = impl_ephy_automation_loadurl;
211 epv->addBookmark = impl_ephy_automation_addBookmark;
212 epv->importBookmarks = impl_ephy_automation_importBookmarks;
213 epv->loadSession = impl_ephy_automation_loadSession;
214 epv->openBookmarksEditor = impl_ephy_automation_openBookmarksEditor;
215 epv->loadUrlWithStartupId = impl_ephy_automation_loadUrlWithStartupId;
216 epv->loadSessionWithStartupId = impl_ephy_automation_loadSessionWithStartupId;
217 epv->openBookmarksEditorWithStartupId = impl_ephy_automation_openBookmarksEditorWithStartupId;
220 BONOBO_TYPE_FUNC_FULL (
221 EphyAutomation,
222 GNOME_EphyAutomation,
223 BONOBO_TYPE_OBJECT,
224 ephy_automation);