gint main (gint argc, gchar **argv) { GOptionContext *context; EDBusServer *server; EDBusServerExitCode exit_code; GError *error = NULL; #ifdef G_OS_WIN32 e_util_win32_initialize (); #endif setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); /* Workaround https://bugzilla.gnome.org/show_bug.cgi?id=674885 */ g_type_ensure (G_TYPE_DBUS_CONNECTION); #if defined (ENABLE_MAINTAINER_MODE) && defined (HAVE_GTK) if (g_getenv ("EDS_TESTING") == NULL) /* This is only to load gtk-modules, like * bug-buddy's gnomesegvhandler, if possible */ gtk_init_check (&argc, &argv); #endif context = g_option_context_new (NULL); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); g_option_context_parse (context, &argc, &argv, &error); g_option_context_free (context); if (error != NULL) { g_printerr ("%s\n", error->message); exit (EXIT_FAILURE); } e_gdbus_templates_init_main_thread (); reload: server = e_data_book_factory_new (NULL, &error); if (error != NULL) { g_printerr ("%s\n", error->message); exit (EXIT_FAILURE); } g_debug ("Server is up and running..."); /* This SHOULD keep the server's use * count from ever reaching zero. */ if (opt_keep_running) e_dbus_server_hold (server); exit_code = e_dbus_server_run (server, opt_wait_for_client); g_object_unref (server); if (exit_code == E_DBUS_SERVER_EXIT_RELOAD) { g_debug ("Reloading..."); goto reload; } g_debug ("Bye."); return 0; }
gint main (gint argc, gchar **argv) { guint id; guint watched_id; ESubprocessBookFactory *subprocess_book_factory; GMainLoop *loop; GDBusObjectManagerServer *manager; GOptionContext *context; SubprocessData sd; GError *error = NULL; #ifdef G_OS_WIN32 e_util_win32_initialize (); #endif setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); /* Workaround https://bugzilla.gnome.org/show_bug.cgi?id=674885 */ g_type_ensure (G_TYPE_DBUS_CONNECTION); #if defined (ENABLE_MAINTAINER_MODE) && defined (HAVE_GTK) if (g_getenv ("EDS_TESTING") == NULL) /* This is only to load gtk-modules, like * bug-buddy's gnomesegvhandler, if possible */ gtk_init_check (&argc, &argv); #endif context = g_option_context_new (NULL); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); g_option_context_parse (context, &argc, &argv, &error); g_option_context_free (context); if (error != NULL) { g_printerr ("%s\n", error->message); exit (EXIT_FAILURE); } loop = g_main_loop_new (NULL, FALSE); manager = g_dbus_object_manager_server_new ("/org/gnome/evolution/dataserver/Subprocess/Backend"); subprocess_book_factory = e_subprocess_book_factory_new (NULL, NULL); sd.loop = loop; sd.manager = manager; sd.subprocess_book_factory = subprocess_book_factory; /* Watch the factory name and close the subprocess if the factory dies/crashes */ watched_id = g_bus_watch_name ( G_BUS_TYPE_SESSION, ADDRESS_BOOK_DBUS_SERVICE_NAME, G_BUS_NAME_WATCHER_FLAGS_NONE, NULL, (GBusNameVanishedCallback) vanished_cb, &sd, NULL); id = g_bus_own_name ( G_BUS_TYPE_SESSION, bus_name, G_BUS_NAME_OWNER_FLAGS_NONE, (GBusAcquiredCallback) on_bus_acquired, NULL, NULL, &sd, NULL); g_main_loop_run (loop); g_bus_unown_name (id); g_bus_unwatch_name (watched_id); g_clear_object (&subprocess_book_factory); g_clear_object (&manager); g_main_loop_unref (loop); return 0; }
gint main (gint argc, gchar **argv) { GTask *task; GCancellable *cancellable; gchar *file = NULL, *oper = NULL; const gchar *title = NULL; gint ii; GError *error = NULL; #ifdef G_OS_WIN32 e_util_win32_initialize (); #endif bindtextdomain (GETTEXT_PACKAGE, EVOLUTION_LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); gtk_init_with_args ( &argc, &argv, NULL, options, GETTEXT_PACKAGE, &error); if (error != NULL) { g_printerr ("%s\n", error->message); g_error_free (error); exit (EXIT_FAILURE); } if (opt_remaining != NULL) { for (ii = 0; ii < g_strv_length (opt_remaining); ii++) { if (backup_op) { title = _("Evolution Back Up"); oper = _("Backing up to the file %s"); bk_file = g_strdup ((gchar *) opt_remaining[ii]); file = bk_file; } else if (restore_op) { title = _("Evolution Restore"); oper = _("Restoring from the file %s"); res_file = g_strdup ((gchar *) opt_remaining[ii]); file = res_file; } else if (check_op) { d (g_message ("Checking %s", (gchar *) opt_remaining[ii])); chk_file = g_strdup ((gchar *) opt_remaining[ii]); } } } cancellable = g_cancellable_new (); if (gui_arg && !check_op) { GtkWidget *widget, *container; GtkWidget *action_area; GtkWidget *content_area; const gchar *txt, *txt2; gchar *str = NULL; gchar *markup; gtk_window_set_default_icon_name ("evolution"); /* Backup / Restore only can have GUI. * We should restrict the rest. */ progress_dialog = gtk_dialog_new_with_buttons ( title, NULL, GTK_DIALOG_MODAL, _("_Cancel"), GTK_RESPONSE_REJECT, NULL); gtk_container_set_border_width ( GTK_CONTAINER (progress_dialog), 12); action_area = gtk_dialog_get_action_area ( GTK_DIALOG (progress_dialog)); content_area = gtk_dialog_get_content_area ( GTK_DIALOG (progress_dialog)); /* Override GtkDialog defaults */ gtk_box_set_spacing (GTK_BOX (content_area), 12); gtk_container_set_border_width (GTK_CONTAINER (content_area), 0); gtk_box_set_spacing (GTK_BOX (action_area), 12); gtk_container_set_border_width (GTK_CONTAINER (action_area), 0); if (oper && file) str = g_strdup_printf (oper, file); container = gtk_grid_new (); gtk_grid_set_column_spacing (GTK_GRID (container), 6); gtk_grid_set_row_spacing (GTK_GRID (container), 0); gtk_widget_show (container); gtk_box_pack_start ( GTK_BOX (content_area), container, FALSE, TRUE, 0); widget = gtk_image_new_from_icon_name ( "edit-copy", GTK_ICON_SIZE_DIALOG); gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.0); gtk_widget_show (widget); gtk_grid_attach (GTK_GRID (container), widget, 0, 0, 1, 3); g_object_set ( G_OBJECT (widget), "halign", GTK_ALIGN_FILL, "valign", GTK_ALIGN_FILL, "vexpand", TRUE, NULL); if (backup_op) { txt = _("Backing up Evolution Data"); txt2 = _("Please wait while Evolution is backing up your data."); } else if (restore_op) { txt = _("Restoring Evolution Data"); txt2 = _("Please wait while Evolution is restoring your data."); } else { g_return_val_if_reached (EXIT_FAILURE); } markup = g_markup_printf_escaped ("<b><big>%s</big></b>", txt); widget = gtk_label_new (markup); gtk_label_set_line_wrap (GTK_LABEL (widget), FALSE); gtk_label_set_use_markup (GTK_LABEL (widget), TRUE); gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.0); gtk_widget_show (widget); g_free (markup); gtk_grid_attach (GTK_GRID (container), widget, 1, 0, 1, 1); g_object_set ( G_OBJECT (widget), "halign", GTK_ALIGN_FILL, "hexpand", TRUE, "valign", GTK_ALIGN_FILL, NULL); markup = g_strconcat ( txt2, " ", _("This may take a while depending " "on the amount of data in your account."), NULL); widget = gtk_label_new (markup); gtk_label_set_line_wrap (GTK_LABEL (widget), TRUE); gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5); gtk_widget_show (widget); g_free (markup); gtk_grid_attach (GTK_GRID (container), widget, 1, 1, 1, 1); g_object_set ( G_OBJECT (widget), "halign", GTK_ALIGN_FILL, "hexpand", TRUE, "valign", GTK_ALIGN_FILL, NULL); pbar = gtk_progress_bar_new (); if (str != NULL) { markup = g_markup_printf_escaped ("<i>%s</i>", str); widget = gtk_label_new (markup); gtk_label_set_use_markup (GTK_LABEL (widget), TRUE); gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5); g_free (markup); g_free (str); gtk_grid_attach (GTK_GRID (container), widget, 1, 2, 1, 1); g_object_set ( G_OBJECT (widget), "halign", GTK_ALIGN_FILL, "hexpand", TRUE, "valign", GTK_ALIGN_FILL, NULL); gtk_grid_attach (GTK_GRID (container), pbar, 1, 3, 1, 1); } else gtk_grid_attach (GTK_GRID (container), pbar, 1, 2, 1, 1); g_object_set ( G_OBJECT (pbar), "halign", GTK_ALIGN_FILL, "hexpand", TRUE, "valign", GTK_ALIGN_FILL, NULL); g_signal_connect ( progress_dialog, "response", G_CALLBACK (dlg_response), cancellable); gtk_widget_show_all (progress_dialog); } else if (check_op) { /* For sanity we don't need gui */ check (chk_file, NULL); exit (result == 0 ? 0 : 1); } if (gui_arg) { e_named_timeout_add_full ( G_PRIORITY_DEFAULT, 50, pbar_update, g_object_ref (cancellable), (GDestroyNotify) g_object_unref); } task = g_task_new (cancellable, cancellable, NULL, NULL); g_task_run_in_thread (task, start_job); g_object_unref (task); gtk_main (); g_object_unref (cancellable); e_util_cleanup_settings (); return result; }
gint main (gint argc, gchar **argv) { ActionContext actctx; GOptionContext *context; GError *error = NULL; gint current_action = ACTION_NOTHING; gint IsCSV = FALSE; gint IsVCard = FALSE; #ifdef G_OS_WIN32 e_util_win32_initialize (); #endif /*i18n-lize */ bindtextdomain (GETTEXT_PACKAGE, EVOLUTION_LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); context = g_option_context_new (NULL); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_printerr ("%s\n", error->message); g_error_free (error); exit (-1); } actctx.registry = e_source_registry_new_sync (NULL, &error); if (error != NULL) { g_printerr ("%s\n", error->message); g_error_free (error); exit (-1); } /* Parsing Parameter */ if (opt_remaining && g_strv_length (opt_remaining) > 0) opt_addressbook_source_uid = g_strdup (opt_remaining[0]); if (opt_list_folders_mode != FALSE) { current_action = ACTION_LIST_FOLDERS; if (opt_addressbook_source_uid != NULL || opt_output_format != NULL) { g_warning (_("Command line arguments error, please use --help option to see the usage.")); exit (-1); } } else { current_action = ACTION_LIST_CARDS; /* check the output format */ if (opt_output_format == NULL) { IsVCard = TRUE; } else { IsCSV = !strcmp (opt_output_format, "csv"); IsVCard = !strcmp (opt_output_format, "vcard"); if (IsCSV == FALSE && IsVCard == FALSE) { g_warning (_("Only support csv or vcard format.")); exit (-1); } } } /* do actions */ if (current_action == ACTION_LIST_FOLDERS) { actctx.action_type = current_action; if (opt_output_file == NULL) { actctx.output_file = NULL; } else { actctx.output_file = g_strdup (opt_output_file); } action_list_folders_init (&actctx); } else if (current_action == ACTION_LIST_CARDS) { actctx.action_type = current_action; if (opt_output_file == NULL) { actctx.output_file = NULL; } else { actctx.output_file = g_strdup (opt_output_file); } actctx.IsCSV = IsCSV; actctx.IsVCard = IsVCard; actctx.addressbook_source_uid = g_strdup (opt_addressbook_source_uid); action_list_cards_init (&actctx); } else { g_warning (_("Unhandled error")); exit (-1); } g_object_unref (actctx.registry); /*FIXME:should free actctx's some gchar * field, such as output_file! but since the program will end, so that will not cause mem leak. */ return 0; }