/* check_ascii_word: * Checks that a string is a valid variable name. */ static void check_ascii_word(char *buf, char *error) { int i; for (i=0; buf[i]; i++) { if (!iswordchar(buf[i])) break; } if (i <= 0) egg_error(error, "Missing identifier"); else if (buf[i]) egg_error(error, "Invalid character ('%c') in identifier", buf[i]); }
/** * pk_task_list_item_create: **/ static PkTaskListItem * pk_task_list_item_create (PkTaskList *tlist, const gchar *tid) { gboolean ret; GError *error = NULL; PkTaskListItem *item; g_return_val_if_fail (PK_IS_TASK_LIST (tlist), NULL); g_return_val_if_fail (tid != NULL, NULL); item = g_new0 (PkTaskListItem, 1); item->tid = g_strdup (tid); item->monitor = pk_client_new (); g_signal_connect (item->monitor, "status-changed", G_CALLBACK (pk_task_list_status_changed_cb), tlist); g_signal_connect (item->monitor, "finished", G_CALLBACK (gpk_task_list_finished_cb), tlist); g_signal_connect (item->monitor, "error-code", G_CALLBACK (gpk_task_list_error_code_cb), tlist); g_signal_connect (item->monitor, "message", G_CALLBACK (gpk_task_list_message_cb), tlist); ret = pk_client_set_tid (item->monitor, tid, &error); if (!ret) { egg_error ("could not set tid: %s", error->message); g_error_free (error); pk_task_list_item_free (item); return NULL; } pk_client_set_use_buffer (item->monitor, TRUE, NULL); pk_client_get_role (item->monitor, &item->role, &item->text, NULL); pk_client_get_status (item->monitor, &item->status, NULL); return item; }
zypp::ResPool zypp_build_local_pool () { zypp::sat::Pool pool = zypp::sat::Pool::instance (); zypp::ZYpp::Ptr zypp = get_zypp (); try { for (zypp::detail::RepositoryIterator it = pool.reposBegin (); it != pool.reposEnd (); it++){ if (! it->isSystemRepo ()) pool.reposErase(it->alias ()); } if (zypp::sat::Pool::instance().reposFind( zypp::sat::Pool::systemRepoAlias() ).solvablesEmpty ()) { // Add local resolvables zypp::Target_Ptr target = zypp->target (); target->load (); } } catch (const zypp::Exception &ex) { egg_error ("%s", ex.asUserString ().c_str ()); } return zypp->pool (); }
zypp::ResPool zypp_build_pool (gboolean include_local) { zypp::ZYpp::Ptr zypp = get_zypp (); if (include_local == TRUE) { //FIXME have to wait for fix in zypp (repeated loading of target) if (zypp::sat::Pool::instance().reposFind( zypp::sat::Pool::systemRepoAlias() ).solvablesEmpty ()) { // Add local resolvables zypp::Target_Ptr target = zypp->target (); target->load (); } } // Add resolvables from enabled repos zypp::RepoManager manager; std::list<zypp::RepoInfo> repos; try { repos = std::list<zypp::RepoInfo>(manager.repoBegin(),manager.repoEnd()); for (std::list<zypp::RepoInfo>::iterator it = repos.begin(); it != repos.end (); it++) { zypp::RepoInfo repo (*it); // skip disabled repos if (repo.enabled () == false) continue; // skip not cached repos if (manager.isCached (repo) == false) { egg_warning ("%s is not cached! Do a refresh", repo.alias ().c_str ()); continue; } //FIXME see above, skip already cached repos if (zypp::sat::Pool::instance().reposFind( repo.alias ()) == zypp::Repository::noRepository) manager.loadFromCache (repo); } } catch (const zypp::repo::RepoNoAliasException &ex) { egg_error ("Can't figure an alias to look in cache"); } catch (const zypp::repo::RepoNotCachedException &ex) { egg_error ("The repo has to be cached at first: %s", ex.asUserString ().c_str ()); } catch (const zypp::Exception &ex) { egg_error ("TODO: Handle exceptions: %s", ex.asUserString ().c_str ()); } return zypp->pool (); }
/** * mcm_calibrate_dialog_run: **/ GtkResponseType mcm_calibrate_dialog_run (McmCalibrateDialog *calibrate_dialog) { if (g_main_loop_is_running (calibrate_dialog->priv->loop)) egg_error ("you can't call this recursively"); g_main_loop_run (calibrate_dialog->priv->loop); return calibrate_dialog->priv->response; }
/* get_brace: * Reads a '{' from the input stream, giving an error if it is not found. */ static void get_brace(char *error) { char buf[256]; get_word(buf); if (strcmp(buf, "{") != 0) egg_error(error, "Missing '{'"); }
/* get_formula: * Reads a formula from the input stream, finishing when the specified * terminator character is encountered. */ static void get_formula(char *buf, int terminator, char *error) { int inspace = FALSE; int braces = 0; int i = 0; int c; for (;;) { c = egg_getc(); if ((c == terminator) && (braces <= 0)) { buf[i] = 0; return; } if (c == EOF) { egg_error(error, "Unexpected EOF"); return; } if (isspace(c)) { if ((i > 0) && (!inspace)) { buf[i++] = ' '; inspace = TRUE; } } else { buf[i++] = c; if (terminator == ')') { if (c == '(') braces++; else if (c == ')') braces--; } } if (i >= 1023) { egg_error(error, "Missing '%c'", terminator); return; } } }
/** * gpm_manager_systemd_shutdown: * * Shutdown the system using systemd-logind. * * Return value: fd, -1 on error **/ static gboolean gpm_control_systemd_shutdown (void) { GError *error = NULL; GDBusProxy *proxy; GVariant *res = NULL; egg_debug ("Requesting systemd to shutdown"); proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, "org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", NULL, &error ); //append all our arguments if (proxy == NULL) { egg_error("Error connecting to dbus - %s", error->message); g_error_free (error); return FALSE; } res = g_dbus_proxy_call_sync (proxy, "PowerOff", g_variant_new( "(b)", FALSE), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error ); if (error != NULL) { egg_error ("Error in dbus - %s", error->message); g_error_free (error); return FALSE; } g_variant_unref(res); return TRUE; }
/** * up_device_init: **/ static void up_device_init (UpDevice *device) { GError *error = NULL; device->priv = UP_DEVICE_GET_PRIVATE (device); device->priv->object_path = NULL; device->priv->system_bus_connection = NULL; device->priv->system_bus_proxy = NULL; device->priv->daemon = NULL; device->priv->native = NULL; device->priv->has_ever_refresh = FALSE; device->priv->during_coldplug = FALSE; device->priv->history = up_history_new (); device->priv->system_bus_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); if (device->priv->system_bus_connection == NULL) { egg_error ("error getting system bus: %s", error->message); g_error_free (error); } g_signal_connect (device, "notify::update-time", G_CALLBACK (up_device_perhaps_changed_cb), device); }
/** * Initialize Zypp (Factory method) */ zypp::ZYpp::Ptr get_zypp () { static gboolean initialized = FALSE; zypp::ZYpp::Ptr zypp = NULL; try { zypp = zypp::ZYppFactory::instance ().getZYpp (); // TODO: Make this threadsafe if (initialized == FALSE) { zypp::filesystem::Pathname pathname("/"); zypp->initializeTarget (pathname); initialized = TRUE; } } catch (const zypp::Exception &ex) { egg_error ("%s", ex.asUserString ().c_str ()); } return zypp; }
/** * gpm_control_suspend: **/ gboolean gpm_control_suspend (GpmControl *control, GError **error) { gboolean allowed = FALSE; gboolean ret = FALSE; gboolean do_lock; gboolean nm_sleep; EggConsoleKit *console; GpmScreensaver *screensaver; guint32 throttle_cookie = 0; #ifdef WITH_KEYRING gboolean lock_gnome_keyring; GnomeKeyringResult keyres; #endif /* WITH_KEYRING */ GError *dbus_error = NULL; GDBusProxy *proxy; GVariant *res = NULL; screensaver = gpm_screensaver_new (); if (!LOGIND_RUNNING()) { console = egg_console_kit_new (); egg_console_kit_can_suspend (console, &allowed, NULL); g_object_unref (console); if (!allowed) { egg_debug ("cannot suspend as not allowed from policy"); g_set_error_literal (error, GPM_CONTROL_ERROR, GPM_CONTROL_ERROR_GENERAL, "Cannot suspend"); goto out; } } #ifdef WITH_KEYRING /* we should perhaps lock keyrings when sleeping #375681 */ lock_gnome_keyring = g_settings_get_boolean (control->priv->settings, GPM_SETTINGS_LOCK_KEYRING_SUSPEND); if (lock_gnome_keyring) { keyres = gnome_keyring_lock_all_sync (); if (keyres != GNOME_KEYRING_RESULT_OK) egg_warning ("could not lock keyring"); } #endif /* WITH_KEYRING */ do_lock = gpm_control_get_lock_policy (control, GPM_SETTINGS_LOCK_ON_SUSPEND); if (do_lock) { throttle_cookie = gpm_screensaver_add_throttle (screensaver, "suspend"); gpm_screensaver_lock (screensaver); } nm_sleep = g_settings_get_boolean (control->priv->settings, GPM_SETTINGS_NETWORKMANAGER_SLEEP); if (nm_sleep) gpm_networkmanager_sleep (); /* Do the suspend */ egg_debug ("emitting sleep"); g_signal_emit (control, signals [SLEEP], 0, GPM_CONTROL_ACTION_SUSPEND); if (LOGIND_RUNNING()) { /* sleep via logind */ proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, "org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", NULL, &dbus_error ); if (proxy == NULL) { egg_error("Error connecting to dbus - %s", dbus_error->message); g_error_free (dbus_error); ret = FALSE; goto out; } res = g_dbus_proxy_call_sync (proxy, "Suspend", g_variant_new( "(b)",FALSE), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &dbus_error ); if (dbus_error != NULL ) { egg_debug ("Error in dbus - %s", dbus_error->message); g_error_free (dbus_error); ret = TRUE; } else { g_variant_unref(res); ret = TRUE; } g_object_unref(proxy); } else { console = egg_console_kit_new (); ret = egg_console_kit_suspend (console, error); g_object_unref (console); } egg_debug ("emitting resume"); g_signal_emit (control, signals [RESUME], 0, GPM_CONTROL_ACTION_SUSPEND); if (do_lock) { gpm_screensaver_poke (screensaver); if (throttle_cookie) gpm_screensaver_remove_throttle (screensaver, throttle_cookie); } nm_sleep = g_settings_get_boolean (control->priv->settings, GPM_SETTINGS_NETWORKMANAGER_SLEEP); if (nm_sleep) gpm_networkmanager_wake (); out: g_object_unref (screensaver); return ret; }
/* load_egg_cmd: * Reads a list of commands. */ static EGG_COMMAND *load_egg_cmd(EGG *egg, int root, char *error) { EGG_COMMAND *cmd = NULL; EGG_COMMAND *tail = NULL; EGG_TYPE *type; char buf[1024]; char buf2[256]; /* helper macro for inserting new commands into the list */ #define ADD_COMMAND(_type_) \ { \ if (tail) { \ tail->next = malloc(sizeof(EGG_COMMAND)); \ tail = tail->next; \ } \ else \ tail = cmd = malloc(sizeof(EGG_COMMAND)); \ \ tail->type = _type_; \ tail->line = egg_line; \ tail->var = NULL; \ tail->exp = NULL; \ tail->cmd = NULL; \ tail->cmd2 = NULL; \ tail->next = NULL; \ } while ((!egg_eof()) && (!error[0])) { get_word(buf); if (strcmp(buf, "}") == 0) { /* block end marker */ if (root) egg_error(error, "Unexpected '}'"); else return cmd; } else if (strcmp(buf, "if") == 0) { /* parse an if statement */ get_word(buf); if (strcmp(buf, "(") != 0) { egg_error(error, "Missing '('"); } else { get_formula(buf, ')', error); if (!error[0]) { get_brace(error); if (!error[0]) { ADD_COMMAND(EGG_COMMAND_IF); tail->exp = malloc(strlen(buf)+1); strcpy(tail->exp, buf); tail->cmd = load_egg_cmd(egg, FALSE, error); } } } } else if (strcmp(buf, "else") == 0) { /* parse an else statement */ if ((!tail) || (tail->type != EGG_COMMAND_IF) || (tail->cmd2)) { egg_error(error, "Invalid context for 'else'"); } else { get_brace(error); if (!error[0]) tail->cmd2 = load_egg_cmd(egg, FALSE, error); } } else if (strcmp(buf, "lay") == 0) { /* parse a lay statement */ ADD_COMMAND(EGG_COMMAND_LAY); get_word(buf); if (strcmp(buf, "(") == 0) { get_formula(buf, ')', error); if (!error[0]) { tail->exp = malloc(strlen(buf)+1); strcpy(tail->exp, buf); get_word(buf); } } if (!error[0]) { check_ascii_word(buf, error); if (!error[0]) { tail->var = malloc(strlen(buf)+1); strcpy(tail->var, buf); get_word(buf); if (strcmp(buf, "{") == 0) tail->cmd = load_egg_cmd(egg, FALSE, error); else if (strcmp(buf, ";") != 0) egg_error(error, "Expecting '{' or ';'"); } } } else if (strcmp(buf, "die") == 0) { /* parse a die statement */ ADD_COMMAND(EGG_COMMAND_DIE); get_word(buf); if (strcmp(buf, ";") != 0) egg_error(error, "Missing ';'"); } else if (strcmp(buf, "type") == 0) { /* parse a type definition */ if (!root) { egg_error(error, "Nested type definition"); } else { get_ascii_word(buf, error); if (!error[0]) { type = malloc(sizeof(EGG_TYPE)); type->name = malloc(strlen(buf)+1); strcpy(type->name, buf); type->cmd = NULL; type->next = NULL; get_brace(error); if (error[0]) { free(type->name); free(type); } else { type->cmd = load_egg_cmd(egg, FALSE, error); if (error[0]) { free(type->name); free(type); } else { type->next = egg->type; egg->type = type; } } } } } else if (buf[0]) { /* this must be a variable assignment */ check_ascii_word(buf, error); if (!error[0]) { get_word(buf2); if (strcmp(buf2, "=") == 0) { ADD_COMMAND(EGG_COMMAND_SET); } else if (strcmp(buf2, ":") == 0) { get_word(buf2); if (strcmp(buf2, "=") != 0) { egg_error(error, "Missing '='"); } else { ADD_COMMAND(EGG_COMMAND_INIT); } } else { egg_error(error, "F****d up syntax "); } if (!error[0]) { tail->var = malloc(strlen(buf)+1); strcpy(tail->var, buf); get_formula(buf, ';', error); if (!error[0]) { tail->exp = malloc(strlen(buf)+1); strcpy(tail->exp, buf); } } } } } if ((!error[0]) && (egg_eof()) && (!root)) egg_error(error, "Unexpected EOF"); if (error[0]) { destroy_egg_cmd(cmd); return NULL; } return cmd; }
/** * 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[]) { GMainLoop *loop; DBusGConnection *system_connection; DBusGConnection *session_connection; gboolean verbose = FALSE; gboolean version = FALSE; gboolean timed_exit = FALSE; gboolean immediate_exit = FALSE; GpmSession *session = NULL; GpmManager *manager = NULL; GError *error = NULL; GOptionContext *context; gint ret; const GOptionEntry options[] = { { "verbose", '\0', 0, G_OPTION_ARG_NONE, &verbose, N_("Show extra debugging information"), NULL }, { "version", '\0', 0, G_OPTION_ARG_NONE, &version, N_("Show version of installed program and exit"), NULL }, { "timed-exit", '\0', 0, G_OPTION_ARG_NONE, &timed_exit, N_("Exit after a small delay (for debugging)"), NULL }, { "immediate-exit", '\0', 0, G_OPTION_ARG_NONE, &immediate_exit, N_("Exit after the manager has loaded (for debugging)"), NULL }, { NULL} }; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); dbus_g_thread_init (); context = g_option_context_new (N_("MATE Power Manager")); /* TRANSLATORS: program name, a simple app to view pending updates */ g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE); g_option_context_set_translation_domain(context, GETTEXT_PACKAGE); g_option_context_set_summary (context, _("MATE Power Manager")); g_option_context_parse (context, &argc, &argv, NULL); if (version) { g_print ("Version %s\n", VERSION); goto unref_program; } dbus_g_thread_init (); gtk_init (&argc, &argv); egg_debug_init (verbose); egg_debug ("MATE %s %s", GPM_NAME, VERSION); /* check dbus connections, exit if not valid */ system_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); if (error) { egg_warning ("%s", error->message); g_error_free (error); egg_error ("This program cannot start until you start " "the dbus system service.\n" "It is <b>strongly recommended</b> you reboot " "your computer after starting this service."); } session_connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); if (error) { egg_warning ("%s", error->message); g_error_free (error); egg_error ("This program cannot start until you start the " "dbus session service.\n\n" "This is usually started automatically in X " "or mate startup when you start a new session."); } /* add application specific icons to search path */ gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), GPM_DATA G_DIR_SEPARATOR_S "icons"); loop = g_main_loop_new (NULL, FALSE); /* optionally register with the session */ session = gpm_session_new (); g_signal_connect (session, "stop", G_CALLBACK (gpm_main_stop_cb), loop); g_signal_connect (session, "query-end-session", G_CALLBACK (gpm_main_query_end_session_cb), loop); g_signal_connect (session, "end-session", G_CALLBACK (gpm_main_end_session_cb), loop); gpm_session_register_client (session, "mate-power-manager", getenv ("DESKTOP_AUTOSTART_ID")); /* create a new gui object */ manager = gpm_manager_new (); if (!gpm_object_register (session_connection, G_OBJECT (manager))) { egg_error ("%s is already running in this session.", GPM_NAME); return 0; } /* register to be a policy agent, just like kpackagekit does */ ret = dbus_bus_request_name(dbus_g_connection_get_connection(system_connection), "org.freedesktop.Policy.Power", DBUS_NAME_FLAG_REPLACE_EXISTING, NULL); switch (ret) { case DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER: egg_debug ("Successfully acquired interface org.freedesktop.Policy.Power."); break; case DBUS_REQUEST_NAME_REPLY_IN_QUEUE: egg_debug ("Queued for interface org.freedesktop.Policy.Power."); break; default: break; }; /* 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); } if (immediate_exit == FALSE) { g_main_loop_run (loop); } g_main_loop_unref (loop); g_object_unref (session); g_object_unref (manager); unref_program: g_option_context_free (context); return 0; }
/** * mcm_calibrate_dialog_init: **/ static void mcm_calibrate_dialog_init (McmCalibrateDialog *calibrate_dialog) { gint retval; GError *error = NULL; GtkWidget *widget; guint i; calibrate_dialog->priv = MCM_CALIBRATE_DIALOG_GET_PRIVATE (calibrate_dialog); calibrate_dialog->priv->device_kind = MCM_CALIBRATE_DEVICE_KIND_UNKNOWN; calibrate_dialog->priv->print_kind = MCM_CALIBRATE_PRINT_KIND_UNKNOWN; calibrate_dialog->priv->reference_kind = MCM_CALIBRATE_REFERENCE_KIND_UNKNOWN; calibrate_dialog->priv->precision = MCM_CALIBRATE_PRECISION_UNKNOWN; calibrate_dialog->priv->move_window = FALSE; calibrate_dialog->priv->loop = g_main_loop_new (NULL, FALSE); calibrate_dialog->priv->cached_dialogs = g_ptr_array_new_with_free_func ((GDestroyNotify)mcm_calibrate_dialog_dialog_free); /* get UI */ calibrate_dialog->priv->builder = gtk_builder_new (); retval = gtk_builder_add_from_file (calibrate_dialog->priv->builder, MCM_DATA "/mcm-calibrate.ui", &error); if (retval == 0) { egg_error ("failed to load ui: %s", error->message); g_error_free (error); } widget = GTK_WIDGET (gtk_builder_get_object (calibrate_dialog->priv->builder, "dialog_calibrate")); g_signal_connect (widget, "delete_event", G_CALLBACK (mcm_calibrate_dialog_delete_event_cb), calibrate_dialog); widget = GTK_WIDGET (gtk_builder_get_object (calibrate_dialog->priv->builder, "button_lcd")); g_signal_connect (widget, "clicked", G_CALLBACK (mcm_calibrate_dialog_button_clicked_lcd_cb), calibrate_dialog); widget = GTK_WIDGET (gtk_builder_get_object (calibrate_dialog->priv->builder, "button_crt")); g_signal_connect (widget, "clicked", G_CALLBACK (mcm_calibrate_dialog_button_clicked_crt_cb), calibrate_dialog); widget = GTK_WIDGET (gtk_builder_get_object (calibrate_dialog->priv->builder, "button_projector")); g_signal_connect (widget, "clicked", G_CALLBACK (mcm_calibrate_dialog_button_clicked_projector_cb), calibrate_dialog); widget = GTK_WIDGET (gtk_builder_get_object (calibrate_dialog->priv->builder, "button_cancel")); g_signal_connect (widget, "clicked", G_CALLBACK (mcm_calibrate_dialog_button_clicked_cancel_cb), calibrate_dialog); widget = GTK_WIDGET (gtk_builder_get_object (calibrate_dialog->priv->builder, "button_ok")); g_signal_connect (widget, "clicked", G_CALLBACK (mcm_calibrate_dialog_button_clicked_ok_cb), calibrate_dialog); widget = GTK_WIDGET (gtk_builder_get_object (calibrate_dialog->priv->builder, "button_print_local")); g_signal_connect (widget, "clicked", G_CALLBACK (mcm_calibrate_dialog_button_clicked_print_local_cb), calibrate_dialog); widget = GTK_WIDGET (gtk_builder_get_object (calibrate_dialog->priv->builder, "button_print_generate")); g_signal_connect (widget, "clicked", G_CALLBACK (mcm_calibrate_dialog_button_clicked_print_generate_cb), calibrate_dialog); widget = GTK_WIDGET (gtk_builder_get_object (calibrate_dialog->priv->builder, "button_print_analyze")); g_signal_connect (widget, "clicked", G_CALLBACK (mcm_calibrate_dialog_button_clicked_print_analyze_cb), calibrate_dialog); widget = GTK_WIDGET (gtk_builder_get_object (calibrate_dialog->priv->builder, "button_precision_short")); g_signal_connect (widget, "clicked", G_CALLBACK (mcm_calibrate_dialog_button_clicked_precision_short_cb), calibrate_dialog); widget = GTK_WIDGET (gtk_builder_get_object (calibrate_dialog->priv->builder, "button_precision_normal")); g_signal_connect (widget, "clicked", G_CALLBACK (mcm_calibrate_dialog_button_clicked_precision_normal_cb), calibrate_dialog); widget = GTK_WIDGET (gtk_builder_get_object (calibrate_dialog->priv->builder, "button_precision_long")); g_signal_connect (widget, "clicked", G_CALLBACK (mcm_calibrate_dialog_button_clicked_precision_long_cb), calibrate_dialog); widget = GTK_WIDGET (gtk_builder_get_object (calibrate_dialog->priv->builder, "image_target")); gtk_widget_set_size_request (widget, 200, 140); widget = GTK_WIDGET (gtk_builder_get_object (calibrate_dialog->priv->builder, "combobox_target")); mcm_calibrate_dialog_setup_combo_simple_text (widget); g_signal_connect (widget, "changed", G_CALLBACK (mcm_calibrate_dialog_reference_kind_combobox_cb), calibrate_dialog); /* add the list of charts */ for (i = 0; i < MCM_CALIBRATE_REFERENCE_KIND_UNKNOWN; i++) { gtk_combo_box_append_text (GTK_COMBO_BOX (widget), mcm_calibrate_dialog_reference_kind_to_localised_string (i)); } /* use IT8 by default */ gtk_combo_box_set_active (GTK_COMBO_BOX (widget), MCM_CALIBRATE_REFERENCE_KIND_IT8); widget = GTK_WIDGET (gtk_builder_get_object (calibrate_dialog->priv->builder, "notebook1")); gtk_notebook_set_show_tabs (GTK_NOTEBOOK (widget), FALSE); }
/** * gpm_control_hibernate: **/ gboolean gpm_control_hibernate (GpmControl *control, GError **error) { gboolean allowed; gboolean ret = FALSE; gboolean do_lock; gboolean nm_sleep; GpmScreensaver *screensaver; guint32 throttle_cookie = 0; #ifdef WITH_KEYRING gboolean lock_mate_keyring; MateKeyringResult keyres; #endif /* WITH_KEYRING */ #ifdef WITH_SYSTEMD_SLEEP GError *dbus_error = NULL; DBusGProxy *proxy; #endif screensaver = gpm_screensaver_new (); #ifndef WITH_SYSTEMD_SLEEP g_object_get (control->priv->client, "can-hibernate", &allowed, NULL); if (!allowed) { egg_debug ("cannot hibernate as not allowed from policy"); g_set_error_literal (error, GPM_CONTROL_ERROR, GPM_CONTROL_ERROR_GENERAL, "Cannot hibernate"); goto out; } #endif #ifdef WITH_KEYRING /* we should perhaps lock keyrings when sleeping #375681 */ lock_mate_keyring = g_settings_get_boolean (control->priv->settings, GPM_SETTINGS_LOCK_KEYRING_HIBERNATE); if (lock_mate_keyring) { keyres = mate_keyring_lock_all_sync (); if (keyres != MATE_KEYRING_RESULT_OK) { egg_warning ("could not lock keyring"); } } #endif /* WITH_KEYRING */ do_lock = gpm_control_get_lock_policy (control, GPM_SETTINGS_LOCK_ON_HIBERNATE); if (do_lock) { throttle_cookie = gpm_screensaver_add_throttle (screensaver, "hibernate"); gpm_screensaver_lock (screensaver); } nm_sleep = g_settings_get_boolean (control->priv->settings, GPM_SETTINGS_NETWORKMANAGER_SLEEP); if (nm_sleep) gpm_networkmanager_sleep (); egg_debug ("emitting sleep"); g_signal_emit (control, signals [SLEEP], 0, GPM_CONTROL_ACTION_HIBERNATE); #ifdef WITH_SYSTEMD_SLEEP /* sleep via logind */ proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, "org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", NULL, &dbus_error ); if (proxy == NULL) { egg_error("Error connecting to dbus - %s", dbus_error->message); g_error_free (dbus_error); return -1; } g_dbus_proxy_call_sync (proxy, "Hibernate", g_variant_new( "(b)",FALSE), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &dbus_error ); if (dbus_error != NULL ) { egg_debug ("Error in dbus - %s", dbus_error->message); g_error_free (dbus_error); ret = TRUE; } else { ret = TRUE; } #else ret = up_client_hibernate_sync (control->priv->client, NULL, error); #endif egg_debug ("emitting resume"); g_signal_emit (control, signals [RESUME], 0, GPM_CONTROL_ACTION_HIBERNATE); if (do_lock) { gpm_screensaver_poke (screensaver); if (throttle_cookie) gpm_screensaver_remove_throttle (screensaver, throttle_cookie); } nm_sleep = g_settings_get_boolean (control->priv->settings, GPM_SETTINGS_NETWORKMANAGER_SLEEP); if (nm_sleep) gpm_networkmanager_wake (); out: g_object_unref (screensaver); return ret; }
/** * mcm_profile_store_add_profiles: * * Return value: if any profile were added **/ gboolean mcm_profile_store_search_default (McmProfileStore *profile_store) { gchar *path; gboolean ret; gboolean success = FALSE; GError *error; McmProfileStorePrivate *priv = profile_store->priv; /* get OSX and Linux system-wide profiles */ ret = mcm_profile_store_search_by_path (profile_store, "/usr/share/color/icc"); if (ret) success = TRUE; ret = mcm_profile_store_search_by_path (profile_store, "/usr/local/share/color/icc"); if (ret) success = TRUE; ret = mcm_profile_store_search_by_path (profile_store, "/Library/ColorSync/Profiles/Displays"); if (ret) success = TRUE; /* get OSX and Windows system-wide profiles when using Linux */ ret = g_settings_get_boolean (priv->settings, MCM_SETTINGS_USE_PROFILES_FROM_VOLUMES); if (ret) { ret = mcm_profile_store_add_profiles_from_mounted_volumes (profile_store); if (ret) success = TRUE; } /* get Linux per-user profiles */ path = g_build_filename (g_get_user_data_dir (), "icc", NULL); ret = mcm_utils_mkdir_with_parents (path, &error); if (!ret) { egg_error ("failed to create directory on startup: %s", error->message); g_error_free (error); } else { ret = mcm_profile_store_search_by_path (profile_store, path); if (ret) success = TRUE; } g_free (path); /* get per-user profiles from obsolete location */ path = g_build_filename (g_get_home_dir (), ".color", "icc", NULL); ret = mcm_profile_store_search_by_path (profile_store, path); if (ret) success = TRUE; g_free (path); /* get OSX per-user profiles */ path = g_build_filename (g_get_home_dir (), "Library", "ColorSync", "Profiles", NULL); ret = mcm_profile_store_search_by_path (profile_store, path); if (ret) success = TRUE; g_free (path); /* get machine specific profiles */ ret = mcm_profile_store_search_by_path (profile_store, "/var/lib/color/icc"); if (ret) success = TRUE; return success; }