/** * egg_debug_init: * @argc: a pointer to the number of command line arguments. * @argv: a pointer to the array of command line arguments. * * Parses command line arguments. * * Return value: %TRUE if initialization succeeded, otherwise %FALSE. **/ gboolean egg_debug_init (gint *argc, gchar ***argv) { GOptionContext *context; /* already initialized */ if (_initialized) return TRUE; context = g_option_context_new (NULL); g_option_context_set_ignore_unknown_options (context, TRUE); g_option_context_add_group (context, egg_debug_get_option_group ()); g_option_context_parse (context, argc, argv, NULL); g_option_context_free (context); return TRUE; }
/** * main: **/ int main (int argc, char **argv) { guint i; guint retval = 0; GOptionContext *context; gchar **files = NULL; const GOptionEntry options[] = { { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &files, /* TRANSLATORS: command line option: a list of files to install */ _("Profiles to view"), NULL }, { NULL} }; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); gtk_init (&argc, &argv); /* TRANSLATORS: this just dumps the profile to the screen */ context = g_option_context_new (_("ICC profile dump program")); g_option_context_add_main_entries (context, options, NULL); g_option_context_add_group (context, egg_debug_get_option_group ()); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_parse (context, &argc, &argv, NULL); g_option_context_free (context); /* nothing specified */ if (files == NULL) goto out; /* show each profile */ for (i=0; files[i] != NULL; i++) mcm_dump_profile_filename (files[i]); out: g_strfreev (files); return retval; }
/** * main: **/ int main (int argc, char *argv[]) { GOptionContext *context; GConfClient *gconf_client; GtkWidget *widget; GtkTreeSelection *selection; GtkEntryCompletion *completion; UniqueApp *unique_app; gboolean ret; guint retval; guint xid = 0; GError *error = NULL; const GOptionEntry options[] = { { "filter", 'f', 0, G_OPTION_ARG_STRING, &filter, /* TRANSLATORS: preset the GtktextBox with this filter text */ N_("Set the filter to this value"), NULL }, { "parent-window", 'p', 0, G_OPTION_ARG_INT, &xid, /* TRANSLATORS: we can make this modal (stay on top of) another window */ _("Set the parent window to make this modal"), NULL }, { NULL} }; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); if (! g_thread_supported ()) g_thread_init (NULL); g_type_init (); gtk_init (&argc, &argv); context = g_option_context_new (NULL); g_option_context_set_summary (context, _("Software Log Viewer")); g_option_context_add_main_entries (context, options, NULL); g_option_context_add_group (context, egg_debug_get_option_group ()); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_parse (context, &argc, &argv, NULL); g_option_context_free (context); /* are we running privileged */ ret = gpk_check_privileged_user (_("Log viewer"), TRUE); if (!ret) return 1; /* are we already activated? */ unique_app = unique_app_new ("org.freedesktop.PackageKit.LogViewer", NULL); if (unique_app_is_running (unique_app)) { egg_debug ("You have another instance running. This program will now close"); unique_app_send_message (unique_app, UNIQUE_ACTIVATE, NULL); goto unique_out; } g_signal_connect (unique_app, "message-received", G_CALLBACK (gpk_log_message_received_cb), NULL); /* add application specific icons to search path */ gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), GPK_DATA G_DIR_SEPARATOR_S "icons"); client = pk_client_new (); g_object_set (client, "background", FALSE, NULL); /* get UI */ builder = gtk_builder_new (); retval = gtk_builder_add_from_file (builder, GPK_DATA "/gpk-log.ui", &error); if (retval == 0) { egg_warning ("failed to load ui: %s", error->message); g_error_free (error); goto out_build; } widget = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_simple")); gtk_window_set_icon_name (GTK_WINDOW (widget), GPK_ICON_SOFTWARE_LOG); /* set a size, if the screen allows */ gpk_window_set_size_request (GTK_WINDOW (widget), 900, 300); /* if command line arguments are set, then setup UI */ if (filter != NULL) { widget = GTK_WIDGET (gtk_builder_get_object (builder, "entry_package")); gtk_entry_set_text (GTK_ENTRY(widget), filter); } /* Get the main window quit */ g_signal_connect_swapped (widget, "delete_event", G_CALLBACK (gtk_main_quit), NULL); widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_close")); g_signal_connect_swapped (widget, "clicked", G_CALLBACK (gtk_main_quit), NULL); gtk_widget_grab_default (widget); widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_help")); g_signal_connect (widget, "clicked", G_CALLBACK (gpk_log_button_help_cb), NULL); widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_refresh")); g_signal_connect (widget, "clicked", G_CALLBACK (gpk_log_button_refresh_cb), NULL); gtk_widget_hide (widget); widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_filter")); g_signal_connect (widget, "clicked", G_CALLBACK (gpk_log_button_filter_cb), NULL); /* hit enter in the search box for filter */ widget = GTK_WIDGET (gtk_builder_get_object (builder, "entry_package")); g_signal_connect (widget, "activate", G_CALLBACK (gpk_log_button_filter_cb), NULL); /* autocompletion can be turned off as it's slow */ gconf_client = gconf_client_get_default (); ret = gconf_client_get_bool (gconf_client, GPK_CONF_AUTOCOMPLETE, NULL); if (ret) { /* create the completion object */ completion = gpk_package_entry_completion_new (); widget = GTK_WIDGET (gtk_builder_get_object (builder, "entry_package")); gtk_entry_set_completion (GTK_ENTRY (widget), completion); g_object_unref (completion); } else { /* use search as you type */ g_signal_connect (widget, "key-release-event", G_CALLBACK (gpk_log_entry_filter_cb), NULL); } g_object_unref (gconf_client); /* create list stores */ list_store = gtk_list_store_new (GPK_LOG_COLUMN_LAST, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN); /* create transaction_id tree view */ widget = GTK_WIDGET (gtk_builder_get_object (builder, "treeview_simple")); gtk_tree_view_set_model (GTK_TREE_VIEW (widget), GTK_TREE_MODEL (list_store)); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget)); g_signal_connect (selection, "changed", G_CALLBACK (gpk_log_treeview_clicked_cb), NULL); /* add columns to the tree view */ pk_treeview_add_general_columns (GTK_TREE_VIEW (widget)); gtk_tree_view_columns_autosize (GTK_TREE_VIEW (widget)); gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (list_store), GPK_LOG_COLUMN_TIMESPEC, GTK_SORT_DESCENDING); /* show */ widget = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_simple")); gtk_widget_show (widget); /* set the parent window if it is specified */ if (xid != 0) { egg_debug ("Setting xid %i", xid); gpk_window_set_parent_xid (GTK_WINDOW (widget), xid); } /* get the update list */ gpk_log_refresh (); gtk_main (); out_build: g_object_unref (builder); g_object_unref (list_store); g_object_unref (client); g_free (transaction_id); g_free (filter); if (transactions != NULL) g_ptr_array_unref (transactions); unique_out: g_object_unref (unique_app); return 0; }
/** * main: **/ int main (int argc, char *argv[]) { GMainLoop *loop; gboolean program_version = FALSE; GOptionContext *context; GtkWidget *widget; PkControl *control; guint retval; GError *error = NULL; const GOptionEntry options[] = { { "version", '\0', 0, G_OPTION_ARG_NONE, &program_version, _("Show the program version and exit"), NULL }, { NULL} }; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); if (! g_thread_supported ()) g_thread_init (NULL); g_type_init (); gtk_init (&argc, &argv); context = g_option_context_new (NULL); g_option_context_set_summary (context, _("PackageKit Backend Details Viewer")); g_option_context_add_main_entries (context, options, NULL); g_option_context_add_group (context, egg_debug_get_option_group ()); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_parse (context, &argc, &argv, NULL); g_option_context_free (context); if (program_version) { g_print (VERSION "\n"); return 0; } loop = g_main_loop_new (NULL, FALSE); control = pk_control_new (); /* get UI */ builder = gtk_builder_new (); retval = gtk_builder_add_from_file (builder, GPK_DATA "/gpk-backend-status.ui", &error); if (retval == 0) { egg_warning ("failed to load ui: %s", error->message); g_error_free (error); goto out; } widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_close")); g_signal_connect (widget, "clicked", G_CALLBACK (gpk_backend_status_close_cb), loop); widget = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_backend")); g_signal_connect (widget, "delete_event", G_CALLBACK (gpk_backend_status_delete_event_cb), loop); gtk_window_set_icon_name (GTK_WINDOW (widget), GPK_ICON_SOFTWARE_LOG); gtk_widget_show (GTK_WIDGET (widget)); /* get properties */ pk_control_get_properties_async (control, NULL, (GAsyncReadyCallback) gpk_backend_status_get_properties_cb, loop); /* wait for results */ g_main_loop_run (loop); out: g_object_unref (builder); g_object_unref (control); g_main_loop_unref (loop); return 0; }
/** * main: **/ int main (int argc, char *argv[]) { GOptionContext *context; guint retval = 0; GError *error = NULL; GMainLoop *loop; GtkWidget *main_window; GtkWidget *widget; UniqueApp *unique_app; guint xid = 0; McmColorimeter *colorimeter = NULL; const GOptionEntry options[] = { { "parent-window", 'p', 0, G_OPTION_ARG_INT, &xid, /* TRANSLATORS: we can make this modal (stay on top of) another window */ _("Set the parent window to make this modal"), NULL }, { NULL} }; /* setup translations */ setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); /* setup LCMS */ cmsSetLogErrorHandler (mcm_picker_error_cb); context = g_option_context_new (NULL); /* TRANSLATORS: tool that is used to pick colors */ g_option_context_set_summary (context, _("MATE Color Manager Color Picker")); g_option_context_add_group (context, egg_debug_get_option_group ()); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_add_main_entries (context, options, NULL); g_option_context_parse (context, &argc, &argv, NULL); g_option_context_free (context); /* block in a loop */ loop = g_main_loop_new (NULL, FALSE); /* are we already activated? */ unique_app = unique_app_new ("org.mate.ColorManager.Picker", NULL); if (unique_app_is_running (unique_app)) { egg_debug ("You have another instance running. This program will now close"); unique_app_send_message (unique_app, UNIQUE_ACTIVATE, NULL); goto out; } g_signal_connect (unique_app, "message-received", G_CALLBACK (mcm_picker_message_received_cb), NULL); /* get UI */ builder = gtk_builder_new (); retval = gtk_builder_add_from_file (builder, MCM_DATA "/mcm-picker.ui", &error); if (retval == 0) { egg_warning ("failed to load ui: %s", error->message); g_error_free (error); goto out; } main_window = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_picker")); gtk_window_set_icon_name (GTK_WINDOW (main_window), MCM_STOCK_ICON); g_signal_connect (main_window, "delete_event", G_CALLBACK (mcm_picker_delete_event_cb), loop); widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_close")); g_signal_connect (widget, "clicked", G_CALLBACK (mcm_picker_close_cb), loop); widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_help")); g_signal_connect (widget, "clicked", G_CALLBACK (mcm_picker_help_cb), NULL); widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_measure")); g_signal_connect (widget, "clicked", G_CALLBACK (mcm_picker_measure_cb), NULL); widget = GTK_WIDGET (gtk_builder_get_object (builder, "image_preview")); gtk_widget_set_size_request (widget, 200, 200); /* add application specific icons to search path */ gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), MCM_DATA G_DIR_SEPARATOR_S "icons"); /* use the color device */ colorimeter = mcm_colorimeter_new (); g_signal_connect (colorimeter, "changed", G_CALLBACK (mcm_picker_colorimeter_changed_cb), NULL); /* set the parent window if it is specified */ if (xid != 0) { egg_debug ("Setting xid %i", xid); mcm_window_set_parent_xid (GTK_WINDOW (main_window), xid); } /* use argyll */ calibrate = MCM_CALIBRATE (mcm_calibrate_argyll_new ()); g_signal_connect (calibrate, "notify::xyz", G_CALLBACK (mcm_picker_xyz_notify_cb), NULL); /* use an info bar if there is no device, or the wrong device */ info_bar_hardware = gtk_info_bar_new (); info_bar_hardware_label = gtk_label_new (NULL); gtk_info_bar_set_message_type (GTK_INFO_BAR(info_bar_hardware), GTK_MESSAGE_INFO); widget = gtk_info_bar_get_content_area (GTK_INFO_BAR(info_bar_hardware)); gtk_container_add (GTK_CONTAINER(widget), info_bar_hardware_label); gtk_widget_show (info_bar_hardware_label); /* add infobar to devices pane */ widget = GTK_WIDGET (gtk_builder_get_object (builder, "vbox1")); gtk_box_pack_start (GTK_BOX(widget), info_bar_hardware, FALSE, FALSE, 0); /* disable some ui if no hardware */ mcm_picker_colorimeter_setup_ui (colorimeter); /* maintain a list of profiles */ profile_store = mcm_profile_store_new (); /* default to AdobeRGB */ profile_filename = "/usr/share/color/icc/Argyll/ClayRGB1998.icm"; /* setup RGB combobox */ widget = GTK_WIDGET (gtk_builder_get_object (builder, "combobox_colorspace")); mcm_prefs_set_combo_simple_text (widget); mcm_prefs_setup_space_combobox (widget); g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (mcm_prefs_space_combo_changed_cb), NULL); /* setup results expander */ mcm_picker_refresh_results (); /* setup initial preview window */ widget = GTK_WIDGET (gtk_builder_get_object (builder, "image_preview")); gtk_image_set_from_file (GTK_IMAGE (widget), DATADIR "/icons/hicolor/64x64/apps/mate-color-manager.png"); /* wait */ gtk_widget_show (main_window); g_main_loop_run (loop); out: g_object_unref (unique_app); if (profile_store != NULL) g_object_unref (profile_store); if (colorimeter != NULL) g_object_unref (colorimeter); if (calibrate != NULL) g_object_unref (calibrate); if (builder != NULL) g_object_unref (builder); g_main_loop_unref (loop); return retval; }
/** * main: **/ int main (int argc, char *argv[]) { gboolean program_version = FALSE; GOptionContext *context; GtkWidget *main_window; GtkWidget *widget; PkControl *control; UniqueApp *unique_app; guint retval; guint xid = 0; GError *error = NULL; GMainLoop *loop; const GOptionEntry options[] = { { "version", '\0', 0, G_OPTION_ARG_NONE, &program_version, _("Show the program version and exit"), NULL }, { "parent-window", 'p', 0, G_OPTION_ARG_INT, &xid, /* TRANSLATORS: we can make this modal (stay on top of) another window */ _("Set the parent window to make this modal"), NULL }, { NULL} }; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); if (! g_thread_supported ()) g_thread_init (NULL); dbus_g_thread_init (); g_type_init (); gtk_init (&argc, &argv); context = g_option_context_new (NULL); /* TRANSLATORS: program name, an application to set per-user policy for updates */ g_option_context_set_summary(context, _("Software Update Preferences")); g_option_context_add_main_entries (context, options, NULL); g_option_context_add_group (context, egg_debug_get_option_group ()); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_parse (context, &argc, &argv, NULL); g_option_context_free (context); if (program_version) { g_print (VERSION "\n"); return 0; } /* are we already activated? */ unique_app = unique_app_new ("org.freedesktop.PackageKit.Prefs", NULL); if (unique_app_is_running (unique_app)) { egg_debug ("You have another instance running. This program will now close"); unique_app_send_message (unique_app, UNIQUE_ACTIVATE, NULL); goto unique_out; } g_signal_connect (unique_app, "message-received", G_CALLBACK (gpk_prefs_message_received_cb), NULL); /* get actions */ loop = g_main_loop_new (NULL, FALSE); control = pk_control_new (); g_signal_connect (control, "notify::network-state", G_CALLBACK (gpk_prefs_notify_network_state_cb), NULL); /* get UI */ builder = gtk_builder_new (); retval = gtk_builder_add_from_file (builder, GPK_DATA "/gpk-prefs.ui", &error); if (retval == 0) { egg_warning ("failed to load ui: %s", error->message); g_error_free (error); goto out_build; } main_window = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_prefs")); /* Hide window first so that the dialogue resizes itself without redrawing */ gtk_widget_hide (main_window); gtk_window_set_icon_name (GTK_WINDOW (main_window), GPK_ICON_SOFTWARE_UPDATE_PREFS); g_signal_connect (main_window, "delete_event", G_CALLBACK (gpk_prefs_delete_event_cb), loop); widget = GTK_WIDGET (gtk_builder_get_object (builder, "checkbutton_mobile_broadband")); gpk_prefs_notify_checkbutton_setup (widget, GPK_CONF_CONNECTION_USE_MOBILE); widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_close")); g_signal_connect (widget, "clicked", G_CALLBACK (gpk_prefs_close_cb), loop); widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_help")); g_signal_connect (widget, "clicked", G_CALLBACK (gpk_prefs_help_cb), NULL); /* update the combo boxes */ gpk_prefs_update_freq_combo_setup (); gpk_prefs_upgrade_freq_combo_setup (); gpk_prefs_auto_update_combo_setup (); gtk_widget_show (main_window); /* set the parent window if it is specified */ if (xid != 0) { egg_debug ("Setting xid %i", xid); gpk_window_set_parent_xid (GTK_WINDOW (main_window), xid); } /* get some data */ pk_control_get_properties_async (control, NULL, (GAsyncReadyCallback) gpk_prefs_get_properties_cb, loop); /* wait */ g_main_loop_run (loop); out_build: g_main_loop_unref (loop); g_object_unref (control); g_object_unref (builder); unique_out: g_object_unref (unique_app); return 0; }
/** * main: **/ int main (int argc, char **argv) { gint retval = EXIT_FAILURE; guint i; GOptionContext *context; gboolean opt_dump = FALSE; gboolean opt_wakeups = FALSE; gboolean opt_enumerate = FALSE; gboolean opt_monitor = FALSE; gchar *opt_show_info = FALSE; gboolean opt_version = FALSE; gboolean ret; GError *error = NULL; gchar *text = NULL; UpClient *client; UpDevice *device; const GOptionEntry entries[] = { { "enumerate", 'e', 0, G_OPTION_ARG_NONE, &opt_enumerate, _("Enumerate objects paths for devices"), NULL }, { "dump", 'd', 0, G_OPTION_ARG_NONE, &opt_dump, _("Dump all parameters for all objects"), NULL }, { "wakeups", 'w', 0, G_OPTION_ARG_NONE, &opt_wakeups, _("Get the wakeup data"), NULL }, { "monitor", 'm', 0, G_OPTION_ARG_NONE, &opt_monitor, _("Monitor activity from the power daemon"), NULL }, { "monitor-detail", 0, 0, G_OPTION_ARG_NONE, &opt_monitor_detail, _("Monitor with detail"), NULL }, { "show-info", 'i', 0, G_OPTION_ARG_STRING, &opt_show_info, _("Show information about object path"), NULL }, { "version", 'v', 0, G_OPTION_ARG_NONE, &opt_version, "Print version of client and daemon", NULL }, { NULL } }; g_type_init (); context = g_option_context_new ("UPower tool"); g_option_context_add_main_entries (context, entries, NULL); g_option_context_add_group (context, egg_debug_get_option_group ()); g_option_context_parse (context, &argc, &argv, NULL); g_option_context_free (context); loop = g_main_loop_new (NULL, FALSE); client = up_client_new (); if (opt_version) { gchar *daemon_version; g_object_get (client, "daemon-version", &daemon_version, NULL); g_print ("UPower client version %s\n" "UPower daemon version %s\n", PACKAGE_VERSION, daemon_version); g_free (daemon_version); retval = 0; goto out; } /* wakeups */ if (opt_wakeups) { up_tool_show_wakeups (); retval = EXIT_SUCCESS; goto out; } if (opt_enumerate || opt_dump) { GPtrArray *devices; ret = up_client_enumerate_devices_sync (client, NULL, &error); if (!ret) { egg_warning ("failed to enumerate: %s", error->message); goto out; } devices = up_client_get_devices (client); for (i=0; i < devices->len; i++) { device = (UpDevice*) g_ptr_array_index (devices, i); if (opt_enumerate) { g_print ("%s\n", up_device_get_object_path (device)); } else { g_print ("Device: %s\n", up_device_get_object_path (device)); text = up_device_to_text (device); g_print ("%s\n", text); g_free (text); } } g_ptr_array_unref (devices); if (opt_dump) { g_print ("Daemon:\n"); up_client_print (client); } retval = EXIT_SUCCESS; goto out; } if (opt_monitor || opt_monitor_detail) { ret = up_client_enumerate_devices_sync (client, NULL, &error); if (!ret) { egg_warning ("failed to enumerate: %s", error->message); goto out; } if (!up_tool_do_monitor (client)) goto out; retval = EXIT_SUCCESS; goto out; } if (opt_show_info != NULL) { device = up_device_new (); ret = up_device_set_object_path_sync (device, opt_show_info, NULL, &error); if (!ret) { g_print ("failed to set path: %s\n", error->message); g_error_free (error); } else { text = up_device_to_text (device); g_print ("%s\n", text); g_free (text); } g_object_unref (device); retval = EXIT_SUCCESS; goto out; } out: g_object_unref (client); return retval; }
/** * main: **/ int main (int argc, char *argv[]) { gboolean program_version = FALSE; gboolean timed_exit = FALSE; GpkCheckUpdate *cupdate = NULL; GpkWatch *watch = NULL; GpkFirmware *firmware = NULL; GpkHardware *hardware = NULL; GOptionContext *context; UniqueApp *unique_app; gboolean ret; const GOptionEntry options[] = { { "timed-exit", '\0', 0, G_OPTION_ARG_NONE, &timed_exit, _("Exit after a small delay"), NULL }, { "version", '\0', 0, G_OPTION_ARG_NONE, &program_version, _("Show the program version and exit"), NULL }, { NULL} }; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); if (! g_thread_supported ()) g_thread_init (NULL); g_type_init (); gtk_init (&argc, &argv); dbus_g_thread_init (); notify_init ("gpk-update-icon"); /* TRANSLATORS: program name, a session wide daemon to watch for updates and changing system state */ g_set_application_name (_("Update Applet")); context = g_option_context_new (NULL); g_option_context_set_summary (context, _("Update Applet")); g_option_context_add_main_entries (context, options, NULL); g_option_context_add_group (context, egg_debug_get_option_group ()); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_parse (context, &argc, &argv, NULL); g_option_context_free (context); if (program_version) { g_print (VERSION "\n"); return 0; } /* TRANSLATORS: title to pass to to the user if there are not enough privs */ ret = gpk_check_privileged_user (_("Update applet"), FALSE); if (!ret) { egg_warning ("Exit: gpk_check_privileged_user returned FALSE"); return 1; } /* are we already activated? */ unique_app = unique_app_new ("org.freedesktop.PackageKit.UpdateIcon", NULL); if (unique_app_is_running (unique_app)) { egg_debug ("You have another instance running. This program will now close"); unique_app_send_message (unique_app, UNIQUE_ACTIVATE, NULL); goto unique_out; } /* add application specific icons to search path */ gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), GPK_DATA G_DIR_SEPARATOR_S "icons"); /* create new objects */ cupdate = gpk_check_update_new (); watch = gpk_watch_new (); firmware = gpk_firmware_new (); hardware = gpk_hardware_new (); /* Only timeout if we have specified iton the command line */ if (timed_exit) g_timeout_add_seconds (120, (GSourceFunc) gtk_main_quit, NULL); /* wait */ gtk_main (); g_object_unref (cupdate); g_object_unref (watch); g_object_unref (firmware); g_object_unref (hardware); unique_out: g_object_unref (unique_app); return 0; }
/** * main: **/ int main (int argc, char *argv[]) { gboolean program_version = FALSE; GpkUpdateViewer *update_viewer = NULL; GOptionContext *context; UniqueApp *unique_app; gboolean ret; const GOptionEntry options[] = { { "version", '\0', 0, G_OPTION_ARG_NONE, &program_version, /* TRANSLATORS: show the program version */ _("Show the program version and exit"), NULL }, { NULL} }; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); if (! g_thread_supported ()) g_thread_init (NULL); dbus_g_thread_init (); g_type_init (); gtk_init (&argc, &argv); context = g_option_context_new (NULL); g_option_context_set_summary (context, _("Add/Remove Software")); g_option_context_add_main_entries (context, options, NULL); g_option_context_add_group (context, egg_debug_get_option_group ()); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_parse (context, &argc, &argv, NULL); g_option_context_free (context); if (program_version) { g_print (VERSION "\n"); return 0; } /* add application specific icons to search path */ gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), GPK_DATA G_DIR_SEPARATOR_S "icons"); /* TRANSLATORS: title to pass to to the user if there are not enough privs */ ret = gpk_check_privileged_user (_("Software Update Viewer"), TRUE); if (!ret) return 1; /* are we already activated? */ unique_app = unique_app_new ("org.freedesktop.PackageKit.UpdateViewer", NULL); if (unique_app_is_running (unique_app)) { egg_debug ("You have another instance running. This program will now close"); unique_app_send_message (unique_app, UNIQUE_ACTIVATE, NULL); goto unique_out; } /* create a new update_viewer object */ update_viewer = gpk_update_viewer_new (); g_signal_connect (unique_app, "message-received", G_CALLBACK (gpk_update_viewer_message_received_cb), update_viewer); g_signal_connect (update_viewer, "action-close", G_CALLBACK (gpk_update_viewer_close_cb), NULL); /* wait */ gtk_main (); g_object_unref (update_viewer); unique_out: g_object_unref (unique_app); return 0; }
/** * main: **/ int main (int argc, char **argv) { gboolean ret; const gchar *copyright; const gchar *description; GFile *destination = NULL; GFile *file = NULL; gchar **files = NULL; guint retval = 1; McmProfile *profile = NULL; McmColorspace colorspace; GError *error = NULL; GOptionContext *context; GString *string = NULL; GtkWidget *dialog; GtkResponseType response; GtkWidget *cie_widget = NULL; McmXyz *white = NULL; McmXyz *red = NULL; McmXyz *green = NULL; McmXyz *blue = NULL; const GOptionEntry options[] = { { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &files, /* TRANSLATORS: command line option: a list of catalogs to install */ _("ICC profile to install"), NULL }, { NULL} }; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); gtk_init (&argc, &argv); context = g_option_context_new ("mate-color-manager import program"); g_option_context_add_main_entries (context, options, NULL); g_option_context_add_group (context, egg_debug_get_option_group ()); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_parse (context, &argc, &argv, NULL); g_option_context_free (context); /* nothing sent */ if (files == NULL) { /* TRANSLATORS: nothing was specified on the command line */ dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("No filename specified")); gtk_window_set_icon_name (GTK_WINDOW (dialog), MCM_STOCK_ICON); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); goto out; } /* load profile */ profile = mcm_profile_default_new (); file = g_file_new_for_path (files[0]); ret = mcm_profile_parse (profile, file, &error); if (!ret) { /* TRANSLATORS: could not read file */ dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Failed to open ICC profile")); gtk_window_set_icon_name (GTK_WINDOW (dialog), MCM_STOCK_ICON); /* TRANSLATORS: parsing error */ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), _("Failed to parse file: %s"), error->message); gtk_dialog_run (GTK_DIALOG (dialog)); g_error_free (error); gtk_widget_destroy (dialog); goto out; } /* get data */ description = mcm_profile_get_description (profile); copyright = mcm_profile_get_copyright (profile); colorspace = mcm_profile_get_colorspace (profile); g_object_get (profile, "white", &white, "red", &red, "green", &green, "blue", &blue, NULL); /* use CIE widget */ cie_widget = mcm_cie_widget_new (); gtk_widget_set_size_request (cie_widget, 200, 200); g_object_set (cie_widget, "use-grid", FALSE, "use-whitepoint", FALSE, "white", white, "red", red, "green", green, "blue", blue, NULL); /* check file does't already exist */ destination = mcm_utils_get_profile_destination (file); ret = g_file_query_exists (destination, NULL); if (ret) { /* TRANSLATORS: color profile already been installed */ dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, _("ICC profile already installed")); gtk_window_set_icon_name (GTK_WINDOW (dialog), MCM_STOCK_ICON); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s\n%s", description, copyright); /* add cie widget */ mcm_import_add_cie_widget (GTK_DIALOG(dialog), cie_widget); gtk_window_set_resizable (GTK_WINDOW (dialog), TRUE); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); goto out; } /* create message */ string = g_string_new (""); if (description != NULL) { /* TRANSLATORS: message text */ g_string_append_printf (string, _("Import ICC color profile %s?"), description); } else { /* TRANSLATORS: message text */ g_string_append (string, _("Import ICC color profile?")); } /* add copyright */ if (copyright != NULL) g_string_append_printf (string, "\n%s", copyright); /* ask confirmation */ dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_CLOSE, "%s", _("Import ICC profile")); gtk_window_set_icon_name (GTK_WINDOW (dialog), MCM_STOCK_ICON); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", string->str); /* TRANSLATORS: button text */ gtk_dialog_add_button (GTK_DIALOG (dialog), _("Install"), GTK_RESPONSE_OK); /* add cie widget */ mcm_import_add_cie_widget (GTK_DIALOG(dialog), cie_widget); /* only show the cie widget if we have RGB data */ if (colorspace != MCM_COLORSPACE_RGB) gtk_widget_hide (cie_widget); gtk_window_set_resizable (GTK_WINDOW (dialog), TRUE); response = gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); /* not the correct response */ if (response != GTK_RESPONSE_OK) goto out; /* copy icc file to users profile path */ ret = mcm_utils_mkdir_and_copy (file, destination, &error); if (!ret) { /* TRANSLATORS: could not read file */ dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Failed to copy file")); gtk_window_set_icon_name (GTK_WINDOW (dialog), MCM_STOCK_ICON); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message); gtk_dialog_run (GTK_DIALOG (dialog)); g_error_free (error); gtk_widget_destroy (dialog); goto out; } /* open up the preferences */ ret = g_spawn_command_line_async (BINDIR "/mcm-prefs", &error); if (!ret) { egg_warning ("failed to spawn preferences: %s", error->message); g_error_free (error); goto out; } out: if (file != NULL) g_object_unref (file); if (white != NULL) g_object_unref (white); if (red != NULL) g_object_unref (red); if (green != NULL) g_object_unref (green); if (blue != NULL) g_object_unref (blue); if (string != NULL) g_string_free (string, TRUE); if (profile != NULL) g_object_unref (profile); if (destination != NULL) g_object_unref (destination); g_strfreev (files); return retval; }
/** * main: **/ int main (int argc, char *argv[]) { DBusGConnection *system_connection; EggDbusMonitor *monitor; gboolean ret; gboolean disable_timer = FALSE; gboolean version = FALSE; gboolean use_daemon = FALSE; gboolean timed_exit = FALSE; gboolean immediate_exit = FALSE; gboolean do_logging = FALSE; gchar *backend_name = NULL; PkEngine *engine = NULL; PkBackend *backend = NULL; PkConf *conf = NULL; PkSyslog *syslog = NULL; GError *error = NULL; GOptionContext *context; const GOptionEntry options[] = { { "backend", '\0', 0, G_OPTION_ARG_STRING, &backend_name, /* TRANSLATORS: a backend is the system package tool, e.g. yum, apt */ _("Packaging backend to use, e.g. dummy"), NULL }, { "daemonize", '\0', 0, G_OPTION_ARG_NONE, &use_daemon, /* TRANSLATORS: if we should run in the background */ _("Daemonize and detach from the terminal"), NULL }, { "disable-timer", '\0', 0, G_OPTION_ARG_NONE, &disable_timer, /* TRANSLATORS: if we should not monitor how long we are inactive for */ _("Disable the idle timer"), NULL }, { "version", '\0', 0, G_OPTION_ARG_NONE, &version, /* TRANSLATORS: show version */ _("Show version and exit"), NULL }, { "timed-exit", '\0', 0, G_OPTION_ARG_NONE, &timed_exit, /* TRANSLATORS: exit after we've started up, used for user profiling */ _("Exit after a small delay"), NULL }, { "immediate-exit", '\0', 0, G_OPTION_ARG_NONE, &immediate_exit, /* TRANSLATORS: exit straight away, used for automatic profiling */ _("Exit after the engine has loaded"), NULL }, { NULL} }; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); if (! g_thread_supported ()) g_thread_init (NULL); dbus_g_thread_init (); g_type_init (); /* TRANSLATORS: describing the service that is running */ context = g_option_context_new (_("PackageKit service")); g_option_context_add_main_entries (context, options, NULL); g_option_context_add_group (context, egg_debug_get_option_group ()); g_option_context_parse (context, &argc, &argv, NULL); g_option_context_free (context); if (version) { g_print ("Version %s\n", VERSION); goto exit_program; } /* check if an instance is already running */ monitor = egg_dbus_monitor_new (); egg_dbus_monitor_assign (monitor, EGG_DBUS_MONITOR_SYSTEM, PK_DBUS_SERVICE); ret = egg_dbus_monitor_is_connected (monitor); g_object_unref (monitor); if (ret) { g_print ("Already running service which provides %s\n", PK_DBUS_SERVICE); goto exit_program; } /* do stuff on ctrl-c */ signal (SIGINT, pk_main_sigint_handler); /* we need to daemonize before we get a system connection */ if (use_daemon && daemon (0, 0)) { g_print ("Could not daemonize: %s\n", g_strerror (errno)); goto exit_program; } /* don't let GIO start it's own session bus: http://bugzilla.gnome.org/show_bug.cgi?id=526454 */ setenv ("GIO_USE_VFS", "local", 1); /* check dbus connections, exit if not valid */ system_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); if (error) { /* TRANSLATORS: fatal error, dbus is not running */ g_print ("%s: %s\n", _("Cannot connect to the system bus"), error->message); g_error_free (error); goto exit_program; } /* we don't actually need to do this, except it rules out the * 'it works from the command line but not service activation' bugs */ #ifdef HAVE_CLEARENV clearenv (); #endif /* get values from the config file */ conf = pk_conf_new (); /* log the startup */ syslog = pk_syslog_new (); pk_syslog_add (syslog, PK_SYSLOG_TYPE_INFO, "daemon start"); /* do we log? */ do_logging = pk_conf_get_bool (conf, "TransactionLogging"); egg_debug ("Log all transactions: %i", do_logging); if (do_logging) egg_debug_set_log_filename ("/var/log/PackageKit"); /* after how long do we timeout? */ exit_idle_time = pk_conf_get_int (conf, "ShutdownTimeout"); egg_debug ("daemon shutdown set to %i seconds", exit_idle_time); if (backend_name == NULL) { backend_name = pk_conf_get_string (conf, "DefaultBackend"); egg_debug ("using default backend %s", backend_name); } /* load our chosen backend */ backend = pk_backend_new (); ret = pk_backend_set_name (backend, backend_name); g_free (backend_name); /* all okay? */ if (!ret) egg_error ("cannot continue, backend invalid"); loop = g_main_loop_new (NULL, FALSE); /* create a new engine object */ engine = pk_engine_new (); g_signal_connect (engine, "quit", G_CALLBACK (pk_main_quit_cb), loop); if (!pk_object_register (system_connection, G_OBJECT (engine), &error)) { /* TRANSLATORS: cannot register on system bus, unknown reason -- geeky error follows */ g_print ("%s %s\n", _("Error trying to start:"), error->message); g_error_free (error); goto out; } /* Only timeout and close the mainloop if we have specified it * on the command line */ if (timed_exit) g_timeout_add_seconds (20, (GSourceFunc) timed_exit_cb, loop); /* only poll every 10 seconds when we are alive */ if (exit_idle_time != 0 && !disable_timer) g_timeout_add_seconds (5, (GSourceFunc) pk_main_timeout_check_cb, engine); /* immediatly exit */ if (immediate_exit) g_timeout_add (50, (GSourceFunc) timed_exit_cb, loop); /* run until quit */ g_main_loop_run (loop); out: /* log the shutdown */ pk_syslog_add (syslog, PK_SYSLOG_TYPE_INFO, "daemon quit"); g_main_loop_unref (loop); g_object_unref (syslog); g_object_unref (conf); g_object_unref (engine); g_object_unref (backend); exit_program: return 0; }
/** * main: **/ int main (int argc, char *argv[]) { GOptionContext *context; gboolean ret; GError *error = NULL; DBusGConnection *connection; DBusGProxy *proxy = NULL; gchar **files = NULL; const GOptionEntry options[] = { { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &files, /* TRANSLATORS: command line option: a list of files to install */ _("Local files to install"), NULL }, { NULL} }; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); if (! g_thread_supported ()) g_thread_init (NULL); g_type_init (); gtk_init (&argc, &argv); /* TRANSLATORS: program name, an application to install a file that is needed by an application and is provided by packages */ g_set_application_name (_("Single File Installer")); context = g_option_context_new ("gpk-install-provide-file"); g_option_context_set_summary (context, _("Single File Installer")); g_option_context_add_main_entries (context, options, NULL); g_option_context_add_group (context, egg_debug_get_option_group ()); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_parse (context, &argc, &argv, NULL); g_option_context_free (context); /* TRANSLATORS: application name to pass to to the user if there are not enough privs */ ret = gpk_check_privileged_user (_("Single File Installer"), TRUE); if (!ret) goto out; if (files == NULL) { /* TRANSLATORS: nothing done */ gpk_error_dialog (_("Failed to install a package to provide a file"), /* TRANSLATORS: nothig was specified */ _("You need to specify a filename to install"), NULL); goto out; } /* check dbus connections, exit if not valid */ connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); if (connection == NULL) { egg_warning ("%s", error->message); goto out; } /* get a connection */ proxy = dbus_g_proxy_new_for_name (connection, "org.freedesktop.PackageKit", "/org/freedesktop/PackageKit", "org.freedesktop.PackageKit.Modify"); if (proxy == NULL) { egg_warning ("Cannot connect to session service"); goto out; } /* don't timeout, as dbus-glib sets the timeout ~25 seconds */ dbus_g_proxy_set_default_timeout (proxy, INT_MAX); /* do method */ ret = dbus_g_proxy_call (proxy, "InstallProvideFiles", &error, G_TYPE_UINT, 0, /* xid */ G_TYPE_STRV, files, /* data */ G_TYPE_STRING, "hide-finished,hide-warnings", /* interaction */ G_TYPE_INVALID, G_TYPE_INVALID); if (!ret && !gpk_ignore_session_error (error)) { /* TRANSLATORS: This is when the specified DBus method did not execute successfully */ gpk_error_dialog (_("The action could not be completed"), /* TRANSLATORS: we don't have anything more useful to translate. sorry. */ _("The request failed. More details are available in the detailed report."), error->message); egg_warning ("%s", error->message); goto out; } out: if (error != NULL) g_error_free (error); if (proxy != NULL) g_object_unref (proxy); g_strfreev (files); return !ret; }