Fix some file header comments.
[platform/upstream/evolution-data-server.git] / services / evolution-source-registry / evolution-source-registry.c
1 /*
2  * evolution-source-registry.c
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) version 3.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with the program; if not, see <http://www.gnu.org/licenses/>
16  *
17  */
18
19 #include <config.h>
20 #include <locale.h>
21 #include <stdlib.h>
22 #include <glib/gi18n.h>
23
24 #ifdef ENABLE_MAINTAINER_MODE
25 #include <gtk/gtk.h>
26 #endif
27
28 #include <libebackend/libebackend.h>
29
30 /* Forward Declarations */
31 void evolution_source_registry_migrate_basedir (void);
32 void evolution_source_registry_migrate_sources (void);
33
34 gint
35 main (gint argc,
36       gchar **argv)
37 {
38         EDBusServer *server;
39         EDBusServerExitCode exit_code;
40         GError *error = NULL;
41
42         setlocale (LC_ALL, "");
43         bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
44         bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
45
46 #ifdef ENABLE_MAINTAINER_MODE
47         /* This is only to load gtk-modules, like
48          * bug-buddy's gnomesegvhandler, if possible */
49         gtk_init_check (&argc, &argv);
50 #else
51         g_type_init ();
52 #endif
53
54         e_gdbus_templates_init_main_thread ();
55
56 reload:
57         /* Migrate user data from ~/.evolution to XDG base directories. */
58         evolution_source_registry_migrate_basedir ();
59
60         /* Migrate ESource data from GConf XML blobs to key files.
61          * Do this AFTER XDG base directory migration since the key
62          * files are saved according to XDG base directory settings. */
63         evolution_source_registry_migrate_sources ();
64
65         server = e_source_registry_server_new ();
66
67         /* Failure here is fatal.  Don't even try to keep going. */
68         e_source_registry_server_load_all (
69                 E_SOURCE_REGISTRY_SERVER (server), &error);
70
71         if (error != NULL) {
72                 g_printerr ("%s\n", error->message);
73                 g_object_unref (server);
74                 exit (EXIT_FAILURE);
75         }
76
77         g_print ("Server is up and running...\n");
78
79         /* Keep the server from quitting on its own.
80          * We don't have a way of tracking number of
81          * active clients, so once the server is up,
82          * it's up until the session bus closes. */
83         e_dbus_server_hold (server);
84
85         exit_code = e_dbus_server_run (server, FALSE);
86
87         g_object_unref (server);
88
89         if (exit_code == E_DBUS_SERVER_EXIT_RELOAD) {
90                 const gchar *config_dir;
91                 gchar *dirname;
92
93                 g_print ("Reloading...\n");
94
95                 /* It's possible the Reload is called after restore, where
96                    the ~/.config/evolution/sources directory can be missing,
97                    thus create it, because e_server_side_source_get_user_dir()
98                    may have its static variable already set to non-NULL value.
99                 */
100                 config_dir = e_get_user_config_dir ();
101                 dirname = g_build_filename (config_dir, "sources", NULL);
102                 g_mkdir_with_parents (dirname, 0700);
103                 g_free (dirname);
104
105                 goto reload;
106         }
107
108         g_print ("Bye.\n");
109
110         return 0;
111 }