/** * main * @argc: number of arguments * @argv: arguments * * Description: * main * * Returns: * exit code **/ int main (int argc, char *argv[]) { GtkWidget *errordialog; GtkWidget *vbox, *menubar, *toolbar, *statusbar, *gridframe; GtkUIManager *ui_manager; GOptionContext *context; struct timeval tv; gint i; gchar *config; gboolean retval; GError *error = NULL; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); games_scores_startup (); gettimeofday (&tv, NULL); srand (tv.tv_usec); context = g_option_context_new (NULL); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE); retval = g_option_context_parse (context, &argc, &argv, &error); g_option_context_free (context); if (!retval) { g_print ("%s", error->message); g_error_free (error); exit (1); } g_set_application_name (_("Robots")); highscores = games_scores_new ("gnobots2", scorecats, G_N_ELEMENTS (scorecats), NULL, NULL, 0 /* default category */, GAMES_SCORES_STYLE_PLAIN_DESCENDING); settings = g_settings_new ("org.gnome.gnobots2"); gtk_window_set_default_icon_name ("gnobots2"); app = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (app), _("Robots")); g_signal_connect (GTK_WINDOW (app), "configure-event", G_CALLBACK (window_configure_event_cb), NULL); g_signal_connect (GTK_WINDOW (app), "window-state-event", G_CALLBACK (window_state_event_cb), NULL); gtk_window_set_default_size (GTK_WINDOW (app), g_settings_get_int (settings, "window-width"), g_settings_get_int (settings, "window-height")); if (g_settings_get_boolean (settings, "window-is-fullscreen")) gtk_window_fullscreen (GTK_WINDOW (app)); if (g_settings_get_boolean (settings, "window-is-maximized")) gtk_window_maximize (GTK_WINDOW (app)); g_signal_connect (G_OBJECT (app), "delete_event", G_CALLBACK (quit_game), NULL); statusbar = gnobots_statusbar_new (); ui_manager = gtk_ui_manager_new (); games_stock_prepare_for_statusbar_tooltips (ui_manager, statusbar); create_game_menus (ui_manager); gtk_window_add_accel_group (GTK_WINDOW (app), gtk_ui_manager_get_accel_group (ui_manager)); menubar = gtk_ui_manager_get_widget (ui_manager, "/MainMenu"); toolbar = gtk_ui_manager_get_widget (ui_manager, "/Toolbar"); gtk_style_context_add_class (gtk_widget_get_style_context (toolbar), GTK_STYLE_CLASS_PRIMARY_TOOLBAR); make_cursors (); game_area = gtk_drawing_area_new (); gtk_widget_add_events (game_area, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK); g_signal_connect (G_OBJECT (game_area), "button-press-event", G_CALLBACK (mouse_cb), NULL); g_signal_connect (G_OBJECT (game_area), "motion-notify-event", G_CALLBACK (move_cb), NULL); g_signal_connect (G_OBJECT (game_area), "configure-event", G_CALLBACK (resize_cb), NULL); g_signal_connect (G_OBJECT (game_area), "draw", G_CALLBACK (draw_cb), NULL); gridframe = games_grid_frame_new (GAME_WIDTH, GAME_HEIGHT); gtk_container_add (GTK_CONTAINER (gridframe), game_area); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_box_pack_start (GTK_BOX (vbox), menubar, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), gridframe, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (vbox), statusbar, FALSE, FALSE, 0); gtk_container_add (GTK_CONTAINER (app), vbox); gtk_widget_set_size_request (GTK_WIDGET (game_area), MINIMUM_TILE_WIDTH * GAME_WIDTH, MINIMUM_TILE_HEIGHT * GAME_HEIGHT); /* Set the window position if it was set by the session manager */ if (session_xpos >= 0 && session_ypos >= 0) { gtk_window_move (GTK_WINDOW (app), session_xpos, session_ypos); } gtk_widget_show_all (app); if (!load_game_configs ()) { /* Oops, no configs, we probably haven't been installed properly. */ errordialog = gtk_message_dialog_new_with_markup (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "<b>%s</b>\n\n%s", _("No game data could be found."), _ ("The program Robots was unable to find any valid game configuration files. Please check that the program is installed correctly.")); gtk_window_set_resizable (GTK_WINDOW (errordialog), FALSE); gtk_dialog_run (GTK_DIALOG (errordialog)); exit (1); } load_properties (); if (!load_game_graphics ()) { /* Oops, no graphics, we probably haven't been installed properly. */ errordialog = gtk_message_dialog_new_with_markup (GTK_WINDOW (app), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "<b>%s</b>\n\n%s", _ ("Some graphics files are missing or corrupt."), _ ("The program Robots was unable to load all the necessary graphics files. Please check that the program is installed correctly.")); gtk_dialog_run (GTK_DIALOG (errordialog)); exit (1); } connect_toolbar_toggle (toolbar); init_sound (); init_game (); if (cmdline_scenario) { set_game_graphics (cmdline_scenario); } if (cmdline_config) { for (i = 0; i < num_game_configs (); ++i) { config = game_config_name (i); if (!strcmp (cmdline_config, config)) { properties_set_config (i); g_free (config); break; } g_free (config); } } gtk_main (); g_settings_sync(); return 0; }
static gint reset_run (void) { GError *error = NULL; if (hard_reset && soft_reset) { g_printerr ("%s\n", _("You can not use the --hard and --soft arguments together")); return EXIT_FAILURE; } /* KILL processes first... */ if (hard_reset || soft_reset) { tracker_process_stop (TRACKER_PROCESS_TYPE_NONE, TRACKER_PROCESS_TYPE_ALL); } if (hard_reset || soft_reset) { guint log_handler_id; #ifndef DISABLE_JOURNAL gchar *rotate_to; TrackerDBConfig *db_config; gsize chunk_size; gint chunk_size_mb; #endif /* DISABLE_JOURNAL */ /* Set log handler for library messages */ log_handler_id = g_log_set_handler (NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL, log_handler, NULL); g_log_set_default_handler (log_handler, NULL); #ifndef DISABLE_JOURNAL db_config = tracker_db_config_new (); chunk_size_mb = tracker_db_config_get_journal_chunk_size (db_config); chunk_size = (gsize) ((gsize) chunk_size_mb * (gsize) 1024 * (gsize) 1024); rotate_to = tracker_db_config_get_journal_rotate_destination (db_config); /* This call is needed to set the journal's filename */ tracker_db_journal_set_rotating ((chunk_size_mb != -1), chunk_size, rotate_to); g_free (rotate_to); g_object_unref (db_config); #endif /* DISABLE_JOURNAL */ /* Clean up (select_cache_size and update_cache_size don't matter here) */ if (!tracker_db_manager_init (TRACKER_DB_MANAGER_REMOVE_ALL, NULL, FALSE, FALSE, 100, 100, NULL, NULL, NULL, &error)) { g_message ("Error initializing database: %s", error->message); g_free (error); return EXIT_FAILURE; } #ifndef DISABLE_JOURNAL tracker_db_journal_init (NULL, FALSE, NULL); #endif /* DISABLE_JOURNAL */ tracker_db_manager_remove_all (hard_reset); tracker_db_manager_shutdown (); #ifndef DISABLE_JOURNAL tracker_db_journal_shutdown (NULL); #endif /* DISABLE_JOURNAL */ /* Unset log handler */ g_log_remove_handler (NULL, log_handler_id); if (!remove_config) { return EXIT_SUCCESS; } } if (remove_config) { GFile *file; const gchar *home_conf_dir; gchar *path; GSList *all, *l; /* Check the default XDG_DATA_HOME location */ home_conf_dir = g_getenv ("XDG_CONFIG_HOME"); if (home_conf_dir && tracker_path_has_write_access_or_was_created (home_conf_dir)) { path = g_build_path (G_DIR_SEPARATOR_S, home_conf_dir, "tracker", NULL); } else { home_conf_dir = g_getenv ("HOME"); if (!home_conf_dir || !tracker_path_has_write_access_or_was_created (home_conf_dir)) { home_conf_dir = g_get_home_dir (); } path = g_build_path (G_DIR_SEPARATOR_S, home_conf_dir, ".config", "tracker", NULL); } file = g_file_new_for_path (path); g_free (path); g_print ("%s\n", _("Removing configuration files…")); directory_foreach (file, ".cfg", (GFunc) delete_file, NULL); g_object_unref (file); g_print ("%s\n", _("Resetting existing configuration…")); all = tracker_gsettings_get_all (NULL); if (!all) { return EXIT_FAILURE; } for (l = all; l; l = l->next) { ComponentGSettings *c = l->data; gchar **keys, **p; if (!c) { continue; } g_print (" %s\n", c->name); keys = g_settings_list_keys (c->settings); for (p = keys; p && *p; p++) { g_print (" %s\n", *p); g_settings_reset (c->settings, *p); } if (keys) { g_strfreev (keys); } g_settings_apply (c->settings); } g_settings_sync (); tracker_gsettings_free (all); return EXIT_SUCCESS; } /* All known options have their own exit points */ g_warn_if_reached (); return EXIT_FAILURE; }
void go_conf_sync (GOConfNode *node) { g_settings_sync (); }
static void pocketvox_setup_save_and_quit(PocketvoxSetup *setup, gpointer data) { gboolean addModule; setup->priv = G_TYPE_INSTANCE_GET_PRIVATE (setup, TYPE_POCKETVOX_SETUP, PocketvoxSetupPrivate); PocketvoxSetupPrivate *priv = setup->priv; GVariantBuilder *builder; GVariant *value; GList* infos = g_hash_table_get_values(priv->apps); GList* iter = NULL; GList* tmp = NULL; builder = g_variant_builder_new(G_VARIANT_TYPE("a(ssb)")); for(iter = infos; iter; iter = iter->next) { ModuleInfos *info = (ModuleInfos *)iter->data; const gchar *id = gtk_entry_get_text(GTK_ENTRY(info->entry_id)); const gchar *dict = gtk_entry_get_text(GTK_ENTRY(info->entry_path)); gboolean isapp = gtk_switch_get_active(GTK_SWITCH(info->sw)); //by default each module should be added addModule = TRUE; //check if we have a valid module if( id == NULL || !g_strcmp0(id, "") == TRUE || dict == NULL || !g_strcmp0(dict, "") == TRUE) { g_warning("PocketvoxSetup: an invalid module couldn't be added to your configuration"); addModule = FALSE; } //check if we already find this one if(addModule == TRUE) { addModule = addModule & (NULL == g_list_find_custom(tmp, id, pocketvox_module_check)); if(addModule == FALSE) { g_warning("PocketvoxSetup: 2 modules cannot have the same ID"); } } //add the new module to the GVariant if(addModule == TRUE) { g_variant_builder_add(builder, "(ssb)", id, dict, isapp); tmp = g_list_append(tmp, g_strdup(id)); } } value = g_variant_new("a(ssb)", builder); g_variant_builder_unref(builder); g_settings_set_value(priv->settings, "list-apps", value); g_settings_sync(); g_list_free(infos); for(iter=tmp; iter; iter=iter->next) { g_free((gchar *)iter->data); } g_list_free(tmp); g_hash_table_destroy(priv->apps); gtk_main_quit(); }
static void main_prog (void *closure, int argc, char *argv[]) { AppData data; GOptionContext *option_context; GError *error = NULL; gboolean retval; memset (&data, 0, sizeof (AppData)); option_context = g_option_context_new (NULL); g_option_context_set_translation_domain (option_context, GETTEXT_PACKAGE); add_main_options (option_context, &data); ar_sound_enable (FALSE); g_option_context_add_group (option_context, gtk_get_option_group (TRUE)); #ifdef HAVE_CLUTTER g_option_context_add_group (option_context, cogl_get_option_group ()); g_option_context_add_group (option_context, clutter_get_option_group_without_init ()); g_option_context_add_group (option_context, gtk_clutter_get_option_group ()); #endif /* HAVE_CLUTTER */ retval = g_option_context_parse (option_context, &argc, &argv, &error); g_option_context_free (option_context); if (!retval) { g_printerr ("%s\n", error->message); g_error_free (error); goto cleanup; } g_set_application_name (data.freecell ? _("FreeCell Solitaire") : _("AisleRiot")); aisleriot_conf_init (); /* If we are asked for a specific game, check that it is valid. */ if (!data.freecell && data.variation != NULL) { char *game_module = NULL; if (data.variation[0] != '\0') { game_module = ar_filename_to_game_module (data.variation); } g_free (data.variation); data.variation = game_module; } if (!data.freecell && !data.variation) { char *pref; pref = ar_conf_get_string_with_default (NULL, aisleriot_conf_get_key (CONF_VARIATION), DEFAULT_VARIATION); data.variation = ar_filename_to_game_module (pref); g_free (pref); } g_assert (data.variation != NULL || data.freecell); ar_stock_init (); gtk_window_set_default_icon_name (data.freecell ? "gnome-freecell" : "gnome-aisleriot"); data.window = AISLERIOT_WINDOW (aisleriot_window_new (data.freecell)); g_signal_connect (data.window, "destroy", G_CALLBACK (gtk_main_quit), NULL); if (data.freecell) { aisleriot_window_set_game_module (data.window, FREECELL_VARIATION, NULL); } else { aisleriot_window_set_game_module (data.window, data.variation, NULL); } gtk_window_present (GTK_WINDOW (data.window)); gtk_main (); aisleriot_conf_shutdown (); cleanup: g_free (data.variation); g_settings_sync (); ar_runtime_shutdown (); }