aboutsummaryrefslogtreecommitdiffstats
path: root/src/ephy-main.c
blob: b7d29b4afcc9fe500f04ab9382bd7a57e7d8cf5e (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
/*
 *  Copyright (C) 2000-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.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "ephy-shell.h"
#include "ephy-file-helpers.h"
#include "ephy-thread-helpers.h"
#include "ephy-state.h"
#include "ephy-debug.h"
#include "ephy-stock-icons.h"
#include "eel-gconf-extensions.h"

#include <libgnomeui/gnome-ui-init.h>
#include <gtk/gtkmain.h>
#include <gtk/gtkmessagedialog.h>
#include <libgnome/gnome-program.h>
#include <bonobo/bonobo-main.h>
#include <glib/gi18n.h>
#include <glade/glade-init.h>
#include <libgnomevfs/gnome-vfs-init.h>

static gboolean open_in_existing = FALSE;
static gboolean open_in_new_tab = FALSE;
static gboolean open_fullscreen = FALSE;
static gboolean open_as_bookmarks_editor = FALSE;
static gboolean server_mode = FALSE;

static const char *session_filename = NULL;
static const char *bookmark_url = NULL;
static const char *bookmarks_file = NULL;

static struct poptOption popt_options[] =
{
    { "new-tab", 'n', POPT_ARG_NONE, &open_in_new_tab, 0,
      N_("Open a new tab in an existing Epiphany window"),
      NULL },
    { "fullscreen", 'f', POPT_ARG_NONE, &open_fullscreen, 0,
      N_("Run Epiphany in full screen mode"),
      NULL },
    { "load-session", 'l', POPT_ARG_STRING, &session_filename, 0,
      N_("Load the given session file"),
      N_("FILE") },
    { "add-bookmark", 't', POPT_ARG_STRING, &bookmark_url,
      0, N_("Add a bookmark (don't open any window)"),
      N_("URL")},
    { "import-bookmarks", '\0', POPT_ARG_STRING, &bookmarks_file,
      0, N_("Import bookmarks from the given file"),
      N_("FILE") },
    { "bookmarks-editor", 'b', POPT_ARG_NONE, &open_as_bookmarks_editor, 0,
      N_("Launch the bookmarks editor"),
      NULL },
    { "server", 's', POPT_ARG_NONE, &server_mode, 0,
      N_("Used internally by the bonobo interface"),
      NULL },
    { NULL, 0, 0, NULL, 0, NULL, NULL }
};

static void
shell_weak_notify (gpointer data,
                   GObject *where_the_object_was)
{
    gtk_main_quit ();
}

int
main (int argc, char *argv[])
{
    poptContext context;
        GValue context_as_value = { 0 };
    GnomeProgram *program;
    EphyShellStartupFlags startup_flags;
    const char **args, *string_arg;
    gboolean new_instance;
    GError *err = NULL;

#ifdef ENABLE_NLS
    /* Initialize the i18n stuff */
    bindtextdomain(GETTEXT_PACKAGE, GNOMELOCALEDIR);
    bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
    textdomain(GETTEXT_PACKAGE);
#endif

    g_set_application_name (_("Epiphany Web Browser"));
    program = gnome_program_init (PACKAGE, VERSION,
                                      LIBGNOMEUI_MODULE, argc, argv,
                                      GNOME_PARAM_POPT_TABLE, popt_options,
                                      GNOME_PARAM_HUMAN_READABLE_NAME, _("Ephy"),
                      GNOME_PARAM_APP_DATADIR, DATADIR,
                                      NULL);

        g_object_get_property (G_OBJECT (program),
                               GNOME_PARAM_POPT_CONTEXT,
                               g_value_init (&context_as_value, G_TYPE_POINTER));
        context = g_value_get_pointer (&context_as_value);
        args = poptGetArgs (context);

    startup_flags = 0;
    string_arg = NULL;
    if (open_in_new_tab)
    {
        startup_flags |= EPHY_SHELL_STARTUP_TABS;
    }
    else if (open_fullscreen)
    {
        startup_flags |= EPHY_SHELL_STARTUP_FULLSCREEN;
    }
    else if (open_in_existing)
    {
        startup_flags |= EPHY_SHELL_STARTUP_EXISTING_WINDOW;
    }
    else if (open_as_bookmarks_editor)
    {
        startup_flags |= EPHY_SHELL_STARTUP_BOOKMARKS_EDITOR;
    }
    else if (session_filename != NULL)
    {
        startup_flags |= EPHY_SHELL_STARTUP_SESSION;
        string_arg = session_filename;
    }
    else if (bookmarks_file != NULL)
    {
        startup_flags |= EPHY_SHELL_STARTUP_IMPORT_BOOKMARKS;
        string_arg = bookmarks_file;
    }
    else if (bookmark_url != NULL)
    {
        startup_flags |= EPHY_SHELL_STARTUP_ADD_BOOKMARK;
        string_arg = bookmark_url;
    }
    else if (server_mode)
    {
        startup_flags |= EPHY_SHELL_STARTUP_SERVER;
    }

    gnome_vfs_init ();
    glade_gnome_init ();
    ephy_debug_init ();
    ephy_thread_helpers_init ();
    ephy_file_helpers_init ();
    ephy_stock_icons_init ();
    eel_gconf_monitor_add ("/apps/epiphany/general");
    bonobo_activate ();

    ephy_shell = ephy_shell_new ();
    new_instance = ephy_shell_startup (ephy_shell, startup_flags,
                       args, string_arg, &err);

    if (err != NULL)
    {
        GtkWidget *dialog;

        dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
                        GTK_BUTTONS_CLOSE, 
                        GTK_MESSAGE_ERROR, err->message);
        gtk_dialog_run (GTK_DIALOG (dialog));
    }
    else if (new_instance)
    {
        g_object_unref (ephy_shell);

        g_object_weak_ref (G_OBJECT (ephy_shell), shell_weak_notify, NULL);

        gtk_main ();
    }

    eel_gconf_monitor_remove ("/apps/epiphany/general");
    ephy_state_save ();
    ephy_file_helpers_shutdown ();
    gnome_vfs_shutdown ();
    poptFreeContext (context);

    return 0;
}