aboutsummaryrefslogtreecommitdiffstats
path: root/capplet/anjal-settings-main.c
blob: 081424e3dd3dc30a9daedbbfbe96afc3cf6fcbb3 (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
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */

/*
 * This program 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 of the License, or (at your option) version 3.
 *
 * 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with the program; if not, see <http://www.gnu.org/licenses/>
 *
 *
 * Authors:
 *      Srinivasa Ragavan <sragavan@novell.com>
 *
 * Copyright (C) 2009 Intel Corporation (www.intel.com)
 *
 */

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

#include <sys/types.h>
#include <sys/stat.h>
#include <locale.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>

#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include <libedataserverui/e-passwords.h>
#include <libemail-utils/mail-mt.h>
#include "settings/mail-capplet-shell.h"
#include <libedataserver/e-categories.h>
#include "e-util/e-plugin.h"
#include "e-util/e-plugin-ui.h"
#include "shell/es-event.h"
#include "shell/e-shell-meego.h"
#include "e-util/e-import.h"

#ifdef G_OS_WIN32
#define WIN32_LEAN_AND_MEAN
#ifdef DATADIR
#undef DATADIR
#endif
#define _WIN32_WINNT 0x0601
#include <windows.h>
#include <conio.h>
#include <io.h>
#ifndef PROCESS_DEP_ENABLE
#define PROCESS_DEP_ENABLE 0x00000001
#endif
#ifndef PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION
#define PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION 0x00000002
#endif
#endif

guint32 socket_id = 0;
GtkWidget *main_window;
static gchar **remaining_args;

static void
categories_icon_theme_hack (void)
{
    GtkIconTheme *icon_theme;
    const gchar *category_name;
    const gchar *filename;
    gchar *dirname;

    /* XXX Allow the category icons to be referenced as named
     *     icons, since GtkAction does not support GdkPixbufs. */

    /* Get the icon file for some default category.  Doesn't matter
     * which, so long as it has an icon.  We're just interested in
     * the directory components. */
    category_name = _("Birthday");
    filename = e_categories_get_icon_file_for (category_name);
    g_return_if_fail (filename != NULL && *filename != '\0');

    /* Extract the directory components. */
    dirname = g_path_get_dirname (filename);

    /* Add it to the icon theme's search path.  This relies on
     * GtkIconTheme's legacy feature of using image files found
     * directly in the search path. */
    icon_theme = gtk_icon_theme_get_default ();
    gtk_icon_theme_append_search_path (icon_theme, dirname);

    g_free (dirname);
}

static EShell *
create_default_shell (void)
{
    main_window = mail_capplet_shell_new (socket_id, FALSE, TRUE);
    if (!socket_id)
        gtk_widget_show (main_window);

    return e_shell_get_default();
}

gint
main (gint argc,
      gchar *argv[])
{
    GError *error = NULL;
    EShell *shell;

#ifdef G_OS_WIN32
    /* Reduce risks */
    {
        typedef BOOL (WINAPI *t_SetDllDirectoryA) (LPCSTR lpPathName);
        t_SetDllDirectoryA p_SetDllDirectoryA;

        p_SetDllDirectoryA = GetProcAddress (GetModuleHandle ("kernel32.dll"), "SetDllDirectoryA");
        if (p_SetDllDirectoryA)
            (*p_SetDllDirectoryA) ("");
    }
#ifndef _WIN64
    {
        typedef BOOL (WINAPI *t_SetProcessDEPPolicy) (DWORD dwFlags);
        t_SetProcessDEPPolicy p_SetProcessDEPPolicy;

        p_SetProcessDEPPolicy = GetProcAddress (GetModuleHandle ("kernel32.dll"), "SetProcessDEPPolicy");
        if (p_SetProcessDEPPolicy)
            (*p_SetProcessDEPPolicy) (PROCESS_DEP_ENABLE | PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION);
    }
#endif

    if (fileno (stdout) != -1 && _get_osfhandle (fileno (stdout)) != -1) {
        /* stdout is fine, presumably redirected to a file or pipe */
    } else {
        typedef BOOL (* WINAPI AttachConsole_t) (DWORD);

        AttachConsole_t p_AttachConsole =
            (AttachConsole_t) GetProcAddress (GetModuleHandle ("kernel32.dll"), "AttachConsole");

        if (p_AttachConsole && p_AttachConsole (ATTACH_PARENT_PROCESS)) {
            freopen ("CONOUT$", "w", stdout);
            dup2 (fileno (stdout), 1);
            freopen ("CONOUT$", "w", stderr);
            dup2 (fileno (stderr), 2);
        }
    }
#endif

    static GOptionEntry entries[] = {
        { "socket",
          's',
          G_OPTION_FLAG_IN_MAIN,
          G_OPTION_ARG_INT,
          &socket_id,
          /* TRANSLATORS: don't translate the terms in brackets */
          N_("ID of the socket to embed in"),
          N_("socket") },
        { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &remaining_args, NULL, NULL },
        { NULL, 0, 0, 0, NULL, NULL, NULL }
    };

#ifdef ENABLE_NLS
    bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
    textdomain (GETTEXT_PACKAGE);
#endif

    setlocale (LC_ALL, NULL);

    if (!gtk_init_with_args (&argc, &argv, NULL, entries, NULL, &error))
        g_error ("%s", error->message);

    e_passwords_init ();
    categories_icon_theme_hack ();

    shell = create_default_shell ();
    e_shell_load_modules (shell);

    /* Register built-in plugin hook types. */
    es_event_hook_get_type ();
    e_import_hook_get_type ();
    e_plugin_ui_hook_get_type ();

    /* All EPlugin and EPluginHook subclasses should be
     * registered in GType now, so load plugins now. */
    e_plugin_load_plugins ();

    gtk_main ();

    return 0;
}