/** * gpm_dpms_set_mode: **/ gboolean gpm_dpms_set_mode (GpmDpms *dpms, GpmDpmsMode mode, GError **error) { gboolean ret; g_return_val_if_fail (GPM_IS_DPMS (dpms), FALSE); if (mode == GPM_DPMS_MODE_UNKNOWN) { egg_debug ("mode unknown"); g_set_error (error, GPM_DPMS_ERROR, GPM_DPMS_ERROR_GENERAL, "Unknown DPMS mode"); return FALSE; } ret = gpm_dpms_x11_set_mode (dpms, mode, error); return ret; }
/** * pk_task_list_status_changed_cb: **/ static void pk_task_list_status_changed_cb (PkClient *client, PkStatusEnum status, PkTaskList *tlist) { gchar *tid; PkTaskListItem *item; g_return_if_fail (PK_IS_TASK_LIST (tlist)); tid = pk_client_get_tid (client); /* get correct item */ item = pk_task_list_find_existing_tid (tlist, tid); item->status = status; egg_debug ("emit status-changed(%s) for %s", pk_status_enum_to_text (status), tid); g_signal_emit (tlist, signals [PK_TASK_LIST_STATUS_CHANGED], 0); g_free (tid); }
static gboolean backend_get_packages_thread (PkBackend *backend) { PkBitfield filters; filters = (PkBitfield) pk_backend_get_uint (backend, "filters"); pk_backend_set_allow_cancel (backend, true); aptcc *m_apt = new aptcc(backend, _cancel); pk_backend_set_pointer(backend, "aptcc_obj", m_apt); if (m_apt->init()) { egg_debug ("Failed to create apt cache"); delete m_apt; pk_backend_finished (backend); return false; } pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY); vector<pair<pkgCache::PkgIterator, pkgCache::VerIterator> > output; output.reserve(m_apt->packageCache->HeaderP->PackageCount); for(pkgCache::PkgIterator pkg = m_apt->packageCache->PkgBegin(); !pkg.end(); ++pkg) { if (_cancel) { break; } // Ignore packages that exist only due to dependencies. if(pkg.VersionList().end() && pkg.ProvidesList().end()) continue; // Don't insert virtual packages as they don't have all kinds of info pkgCache::VerIterator ver = m_apt->find_ver(pkg); if (ver.end() == false) { output.push_back(pair<pkgCache::PkgIterator, pkgCache::VerIterator>(pkg, ver)); } } // It's faster to emmit the packages rather here than in the matching part m_apt->emit_packages(output, filters); delete m_apt; pk_backend_finished (backend); return true; }
/** * gpm_object_register: * @connection: What we want to register to * @object: The GObject we want to register * * Register org.mate.PowerManager on the session bus. * This function MUST be called before DBUS service will work. * * Return value: success **/ static gboolean gpm_object_register (DBusGConnection *connection, GObject *object) { DBusGProxy *bus_proxy = NULL; GError *error = NULL; guint request_name_result; gboolean ret; bus_proxy = dbus_g_proxy_new_for_name (connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); ret = dbus_g_proxy_call (bus_proxy, "RequestName", &error, G_TYPE_STRING, GPM_DBUS_SERVICE, G_TYPE_UINT, 0, G_TYPE_INVALID, G_TYPE_UINT, &request_name_result, G_TYPE_INVALID); if (error) { egg_debug ("ERROR: %s", error->message); g_error_free (error); } if (!ret) { /* abort as the DBUS method failed */ egg_warning ("RequestName failed!"); return FALSE; } /* free the bus_proxy */ g_object_unref (G_OBJECT (bus_proxy)); /* already running */ if (request_name_result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { return FALSE; } dbus_g_object_type_install_info (GPM_TYPE_MANAGER, &dbus_glib_gpm_manager_object_info); dbus_g_error_domain_register (GPM_MANAGER_ERROR, NULL, GPM_MANAGER_TYPE_ERROR); dbus_g_connection_register_g_object (connection, GPM_DBUS_PATH, object); return TRUE; }
/** * pk_connection_valid: * @connection: a valid #PkConnection instance * * Return value: %TRUE if packagekitd is running **/ gboolean pk_connection_valid (PkConnection *connection) { DBusError error; DBusConnection *conn; gboolean ret; g_return_val_if_fail (PK_IS_CONNECTION (connection), FALSE); /* get raw connection */ conn = dbus_g_connection_get_connection (connection->priv->connection); dbus_error_init (&error); ret = dbus_bus_name_has_owner (conn, PK_DBUS_SERVICE, &error); if (dbus_error_is_set (&error)) { egg_debug ("error: %s", error.message); dbus_error_free (&error); } return ret; }
/** * gpk_package_entry_completion_model_new: * * Creates a tree model containing completions from the system package list **/ static GtkTreeModel * gpk_package_entry_completion_model_new (void) { GPtrArray *list; guint i; PkPackage *item; GHashTable *hash; gpointer data; GtkListStore *store; GtkTreeIter iter; gchar **split; store = gtk_list_store_new (1, G_TYPE_STRING); hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); list = gpk_package_entry_completion_get_names_from_file (PK_SYSTEM_PACKAGE_LIST_FILENAME); if (list == NULL) { egg_warning ("no package list, try refreshing"); return NULL; } egg_debug ("loading %i autocomplete items", list->len); for (i=0; i<list->len; i++) { item = g_ptr_array_index (list, i); if (item == NULL || pk_package_get_id (item) == NULL) { egg_warning ("item invalid!"); break; } split = pk_package_id_split (pk_package_get_id (item)); data = g_hash_table_lookup (hash, (gpointer) split[PK_PACKAGE_ID_NAME]); if (data == NULL) { /* append just the name */ g_hash_table_insert (hash, g_strdup (split[PK_PACKAGE_ID_NAME]), GINT_TO_POINTER (1)); gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, 0, split[PK_PACKAGE_ID_NAME], -1); } g_strfreev (split); } g_hash_table_unref (hash); g_ptr_array_unref (list); return GTK_TREE_MODEL (store); }
static void up_devd_process_event (const gchar *event, gpointer user_data) { UpBackend *backend; g_return_if_fail(event != NULL); backend = UP_BACKEND(user_data); egg_debug("received devd event: '%s'", event); switch (event[0]) { case UP_DEVD_EVENT_ADD: case UP_DEVD_EVENT_REMOVE: /* Do nothing as we don't currently hotplug ACPI devices. */ return; case UP_DEVD_EVENT_NOTIFY: { gchar *system; gchar *subsystem; gchar *type; gchar *data; if (!up_devd_parse_notify (event + 1, &system, &subsystem, &type, &data)) goto malformed; up_devd_process_notify_event (backend, system, subsystem, type, data); g_free (system); g_free (subsystem); g_free (type); g_free (data); } return; case UP_DEVD_EVENT_NOMATCH: /* Do nothing. */ return; } malformed: egg_warning("malformed devd event: %s", event); }
/** * mcm_profile_store_remove_profile: **/ static gboolean mcm_profile_store_remove_profile (McmProfileStore *profile_store, McmProfile *profile) { gboolean ret; McmProfileStorePrivate *priv = profile_store->priv; /* remove from list */ ret = g_ptr_array_remove (priv->profile_array, profile); if (!ret) { egg_warning ("failed to remove %s", mcm_profile_get_filename (profile)); goto out; } /* emit a signal */ egg_debug ("emit removed (and changed): %s", mcm_profile_get_filename (profile)); g_signal_emit (profile_store, signals[SIGNAL_REMOVED], 0, profile); g_signal_emit (profile_store, signals[SIGNAL_CHANGED], 0); out: return ret; }
/** * ai_generate_create_icon_directories: **/ static gboolean ai_generate_create_icon_directories (const gchar *directory) { gboolean ret; GError *error = NULL; GFile *file; gchar *path; guint i; /* create main directory */ ret = g_file_test (directory, G_FILE_TEST_IS_DIR); if (!ret) { file = g_file_new_for_path (directory); ret = g_file_make_directory (file, NULL, &error); g_object_unref (file); if (!ret) { egg_warning ("cannot create %s: %s", directory, error->message); g_error_free (error); goto out; } } /* make sub directories */ for (i=0; icon_sizes[i] != NULL; i++) { path = g_build_filename (directory, icon_sizes[i], NULL); ret = g_file_test (path, G_FILE_TEST_IS_DIR); if (!ret) { egg_debug ("creating %s", path); file = g_file_new_for_path (path); ret = g_file_make_directory (file, NULL, &error); if (!ret) { egg_warning ("cannot create %s: %s", path, error->message); g_clear_error (&error); } g_object_unref (file); } g_free (path); } out: return ret; }
/** * up_device_perhaps_changed_cb: **/ static void up_device_perhaps_changed_cb (GObject *object, GParamSpec *pspec, UpDevice *device) { g_return_if_fail (UP_IS_DEVICE (device)); /* don't proxy during coldplug */ if (device->priv->during_coldplug) return; /* save new history */ up_history_set_state (device->priv->history, device->priv->state); up_history_set_charge_data (device->priv->history, device->priv->percentage); up_history_set_rate_data (device->priv->history, device->priv->energy_rate); up_history_set_time_full_data (device->priv->history, device->priv->time_to_full); up_history_set_time_empty_data (device->priv->history, device->priv->time_to_empty); /* The order here matters; we want Device::Changed() before * the DeviceChanged() signal on the main object */ egg_debug ("emitting changed on %s", device->priv->native_path); g_signal_emit (device, signals[SIGNAL_CHANGED], 0); }
static gboolean gpm_kbd_backlight_set (GpmKbdBacklight *backlight, guint percentage) { gint scale; guint goal; g_return_val_if_fail (GPM_IS_KBD_BACKLIGHT (backlight), FALSE); /* avoid warnings if no keyboard brightness is available */ if (backlight->priv->max_brightness < 1) return FALSE; /* if we're setting the same we are, don't bother */ //g_return_val_if_fail (backlight->priv->brightness_percent != percentage, FALSE); goal = gpm_discrete_from_percent (percentage, backlight->priv->max_brightness); scale = percentage > backlight->priv->brightness_percent ? 1 : -1; /* if percentage change too small force next value */ if (goal == backlight->priv->brightness) { goal += percentage == backlight->priv->brightness_percent ? 0 : scale; } /* step loop down by 1 for a dimming effect */ while (backlight->priv->brightness != goal) { backlight->priv->brightness += scale; backlight->priv->brightness_percent = gpm_discrete_to_percent (backlight->priv->brightness, backlight->priv->max_brightness); g_dbus_proxy_call (backlight->priv->upower_proxy, "SetBrightness", g_variant_new ("(i)", (gint) backlight->priv->brightness), G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL); } egg_debug("Set brightness to %i", backlight->priv->brightness); return TRUE; }
/** * gpk_prefs_update_freq_combo_setup: **/ static void gpk_prefs_update_freq_combo_setup (void) { guint value; gboolean is_writable; GtkWidget *widget; GConfClient *client; client = gconf_client_get_default (); widget = GTK_WIDGET (gtk_builder_get_object (builder, "combobox_check")); is_writable = gconf_client_key_is_writable (client, GPK_CONF_FREQUENCY_GET_UPDATES, NULL); value = gconf_client_get_int (client, GPK_CONF_FREQUENCY_GET_UPDATES, NULL); egg_debug ("value from gconf %i", value); g_object_unref (client); /* do we have permission to write? */ gtk_widget_set_sensitive (widget, is_writable); /* set a simple text model */ gpk_prefs_update_freq_combo_simple_text (widget); gtk_combo_box_append_text (GTK_COMBO_BOX (widget), PK_FREQ_HOURLY_TEXT); gtk_combo_box_append_text (GTK_COMBO_BOX (widget), PK_FREQ_DAILY_TEXT); gtk_combo_box_append_text (GTK_COMBO_BOX (widget), PK_FREQ_WEEKLY_TEXT); gtk_combo_box_append_text (GTK_COMBO_BOX (widget), PK_FREQ_NEVER_TEXT); /* select the correct entry */ if (value == GPK_PREFS_VALUE_HOURLY) gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0); else if (value == GPK_PREFS_VALUE_DAILY) gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 1); else if (value == GPK_PREFS_VALUE_WEEKLY) gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 2); else if (value == GPK_PREFS_VALUE_NEVER) gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 3); /* only do this after else we redraw the window */ g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (gpk_prefs_update_freq_combo_changed), NULL); }
/** * pk_task_list_print: **/ gboolean pk_task_list_print (PkTaskList *tlist) { guint i; PkTaskListItem *item; guint length; g_return_val_if_fail (PK_IS_TASK_LIST (tlist), FALSE); length = tlist->priv->task_list->len; egg_debug ("Tasks:"); if (length == 0) { g_print ("[none]...\n"); return TRUE; } for (i=0; i<length; i++) { item = g_ptr_array_index (tlist->priv->task_list, i); g_print ("%s\t%s:%s %s\n", item->tid, pk_role_enum_to_text (item->role), pk_status_enum_to_text (item->status), item->text); } return TRUE; }
/** * 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; }
/** * gpk_log_refilter **/ static void gpk_log_refilter (void) { guint i; gboolean ret; PkTransactionPast *item; GtkWidget *widget; const gchar *package; GtkTreeView *treeview; GtkTreeModel *model; /* set the new filter */ g_free (filter); widget = GTK_WIDGET (gtk_builder_get_object (builder, "entry_package")); package = gtk_entry_get_text (GTK_ENTRY(widget)); if (package != NULL && package[0] != '\0') filter = g_strdup (package); else filter = NULL; egg_debug ("len=%i", transactions->len); /* mark the items as not used */ treeview = GTK_TREE_VIEW (gtk_builder_get_object (builder, "treeview_simple")); model = gtk_tree_view_get_model (treeview); gpk_log_mark_nonactive (model); /* go through the list, adding and removing the items as required */ for (i=0; i<transactions->len; i++) { item = g_ptr_array_index (transactions, i); ret = gpk_log_filter (item); if (ret) gpk_log_add_item (item); } /* remove the items that are not used */ gpk_log_remove_nonactive (model); }
/** * gpk_prefs_upgrade_freq_combo_changed: **/ static void gpk_prefs_upgrade_freq_combo_changed (GtkWidget *widget, gpointer data) { gchar *value; guint freq = 0; GConfClient *client; client = gconf_client_get_default (); value = gtk_combo_box_get_active_text (GTK_COMBO_BOX (widget)); if (strcmp (value, PK_FREQ_DAILY_TEXT) == 0) freq = GPK_PREFS_VALUE_DAILY; else if (strcmp (value, PK_FREQ_WEEKLY_TEXT) == 0) freq = GPK_PREFS_VALUE_WEEKLY; else if (strcmp (value, PK_FREQ_NEVER_TEXT) == 0) freq = GPK_PREFS_VALUE_NEVER; else g_assert (FALSE); egg_debug ("Changing %s to %i", GPK_CONF_FREQUENCY_GET_UPGRADES, freq); gconf_client_set_int (client, GPK_CONF_FREQUENCY_GET_UPGRADES, freq, NULL); g_free (value); g_object_unref (client); }
/** * gpm_backlight_notify_system_idle_changed: **/ static gboolean gpm_backlight_notify_system_idle_changed (GpmBacklight *backlight, gboolean is_idle) { gdouble elapsed; /* no point continuing */ if (backlight->priv->system_is_idle == is_idle) { egg_debug ("state not changed"); return FALSE; } /* get elapsed time and reset timer */ elapsed = g_timer_elapsed (backlight->priv->idle_timer, NULL); g_timer_reset (backlight->priv->idle_timer); if (is_idle == FALSE) { egg_debug ("we have just been idle for %lfs", elapsed); /* The user immediatly undimmed the screen! * We should double the timeout to avoid this happening again */ if (elapsed < 10) { /* double the event time */ backlight->priv->idle_dim_timeout *= 2.0; egg_debug ("increasing idle dim time to %is", backlight->priv->idle_dim_timeout); gpm_idle_set_timeout_dim (backlight->priv->idle, backlight->priv->idle_dim_timeout); } /* We reset the dimming after 2 minutes of idle, * as the user will have changed tasks */ if (elapsed > 2*60) { /* reset back to our default dimming */ backlight->priv->idle_dim_timeout = gconf_client_get_int (backlight->priv->conf, GPM_CONF_BACKLIGHT_IDLE_DIM_TIME, NULL); egg_debug ("resetting idle dim time to %is", backlight->priv->idle_dim_timeout); gpm_idle_set_timeout_dim (backlight->priv->idle, backlight->priv->idle_dim_timeout); } } else { egg_debug ("we were active for %lfs", elapsed); } egg_debug ("changing powersave idle status to %i", is_idle); backlight->priv->system_is_idle = is_idle; return TRUE; }
/** * gpk_prefs_auto_update_combo_setup: **/ static void gpk_prefs_auto_update_combo_setup (void) { gchar *value; gboolean is_writable; GtkWidget *widget; GpkUpdateEnum update; GConfClient *client; client = gconf_client_get_default (); widget = GTK_WIDGET (gtk_builder_get_object (builder, "combobox_install")); is_writable = gconf_client_key_is_writable (client, GPK_CONF_AUTO_UPDATE, NULL); value = gconf_client_get_string (client, GPK_CONF_AUTO_UPDATE, NULL); if (value == NULL) { egg_warning ("invalid schema, please re-install"); return; } egg_debug ("value from gconf %s", value); update = gpk_update_enum_from_text (value); g_free (value); g_object_unref (client); /* do we have permission to write? */ gtk_widget_set_sensitive (widget, is_writable); /* set a simple text model */ gpk_prefs_update_freq_combo_simple_text (widget); gtk_combo_box_append_text (GTK_COMBO_BOX (widget), PK_UPDATE_ALL_TEXT); gtk_combo_box_append_text (GTK_COMBO_BOX (widget), PK_UPDATE_SECURITY_TEXT); gtk_combo_box_append_text (GTK_COMBO_BOX (widget), PK_UPDATE_NONE_TEXT); /* we can do this as it's the same order */ gtk_combo_box_set_active (GTK_COMBO_BOX (widget), update); /* only do this after else we redraw the window */ g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (gpk_prefs_update_combo_changed), NULL); }
/** * gpm_conf_gconf_key_changed_cb: * * We might have to do things when the gconf keys change; do them here. **/ static void gpm_conf_gconf_key_changed_cb (GConfClient *client, guint cnxn_id, GConfEntry *entry, GpmBacklight *backlight) { GConfValue *value; gboolean on_battery; value = gconf_entry_get_value (entry); if (value == NULL) return; /* get battery status */ g_object_get (backlight->priv->client, "on-battery", &on_battery, NULL); if (!on_battery && strcmp (entry->key, GPM_CONF_BACKLIGHT_BRIGHTNESS_AC) == 0) { backlight->priv->master_percentage = gconf_value_get_int (value); gpm_backlight_brightness_evaluate_and_set (backlight, FALSE); } else if (on_battery && strcmp (entry->key, GPM_CONF_BACKLIGHT_BRIGHTNESS_DIM_BATT) == 0) { gpm_backlight_brightness_evaluate_and_set (backlight, FALSE); } else if (strcmp (entry->key, GPM_CONF_BACKLIGHT_IDLE_DIM_AC) == 0 || strcmp (entry->key, GPM_CONF_BACKLIGHT_ENABLE) == 0 || strcmp (entry->key, GPM_CONF_TIMEOUT_SLEEP_DISPLAY_BATT) == 0 || strcmp (entry->key, GPM_CONF_BACKLIGHT_BATTERY_REDUCE) == 0 || strcmp (entry->key, GPM_CONF_BACKLIGHT_IDLE_BRIGHTNESS) == 0) { gpm_backlight_brightness_evaluate_and_set (backlight, FALSE); } else if (strcmp (entry->key, GPM_CONF_BACKLIGHT_IDLE_DIM_TIME) == 0) { backlight->priv->idle_dim_timeout = gconf_value_get_int (value); gpm_idle_set_timeout_dim (backlight->priv->idle, backlight->priv->idle_dim_timeout); } else { egg_debug ("unknown key %s", entry->key); } }
/** * gpm_applet_get_icon: * @applet: Brightness applet instance * * retrieve an icon from stock with a size adapted to panel **/ static void gpm_applet_get_icon (GpmBrightnessApplet *applet) { const gchar *icon; /* free */ if (applet->icon != NULL) { g_object_unref (applet->icon); applet->icon = NULL; } if (applet->size <= 2) { return; } /* get icon */ if (applet->proxy == NULL) { icon = GPM_BRIGHTNESS_APPLET_ICON_INVALID; } else if (applet->call_worked == FALSE) { icon = GPM_BRIGHTNESS_APPLET_ICON_DISABLED; } else { icon = GPM_BRIGHTNESS_APPLET_ICON; } applet->icon = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), icon, applet->size - 2, 0, NULL); if (applet->icon == NULL) { egg_warning ("Cannot find %s!\n", icon); } else { egg_debug ("got icon %s!\n", icon); /* update size cache */ applet->icon_height = gdk_pixbuf_get_height (applet->icon); applet->icon_width = gdk_pixbuf_get_width (applet->icon); } }
/** * gpm_backlight_brightness_evaluate_and_set: **/ static gboolean gpm_backlight_brightness_evaluate_and_set (GpmBacklight *backlight, gboolean interactive) { gfloat brightness; gfloat scale; gboolean ret; gboolean on_battery; gboolean do_laptop_lcd; gboolean enable_action; gboolean battery_reduce; gboolean hw_changed; guint value; guint old_value; if (backlight->priv->can_dim == FALSE) { egg_warning ("no dimming hardware"); return FALSE; } do_laptop_lcd = gconf_client_get_bool (backlight->priv->conf, GPM_CONF_BACKLIGHT_ENABLE, NULL); if (do_laptop_lcd == FALSE) { egg_warning ("policy is no dimming"); return FALSE; } /* get the last set brightness */ brightness = backlight->priv->master_percentage / 100.0f; egg_debug ("1. main brightness %f", brightness); /* get battery status */ g_object_get (backlight->priv->client, "on-battery", &on_battery, NULL); /* reduce if on battery power if we should */ battery_reduce = gconf_client_get_bool (backlight->priv->conf, GPM_CONF_BACKLIGHT_BATTERY_REDUCE, NULL); if (on_battery && battery_reduce) { value = gconf_client_get_int (backlight->priv->conf, GPM_CONF_BACKLIGHT_BRIGHTNESS_DIM_BATT, NULL); if (value > 100) { egg_warning ("cannot use battery brightness value %i, correcting to 50", value); value = 50; } scale = (100 - value) / 100.0f; brightness *= scale; } else { scale = 1.0f; } egg_debug ("2. battery scale %f, brightness %f", scale, brightness); /* reduce if system is momentarily idle */ if (!on_battery) enable_action = gconf_client_get_bool (backlight->priv->conf, GPM_CONF_BACKLIGHT_IDLE_DIM_AC, NULL); else enable_action = gconf_client_get_bool (backlight->priv->conf, GPM_CONF_BACKLIGHT_IDLE_DIM_BATT, NULL); if (enable_action && backlight->priv->system_is_idle) { value = gconf_client_get_int (backlight->priv->conf, GPM_CONF_BACKLIGHT_IDLE_BRIGHTNESS, NULL); if (value > 100) { egg_warning ("cannot use idle brightness value %i, correcting to 50", value); value = 50; } scale = value / 100.0f; brightness *= scale; } else { scale = 1.0f; } egg_debug ("3. idle scale %f, brightness %f", scale, brightness); /* convert to percentage */ value = (guint) ((brightness * 100.0f) + 0.5); /* only do stuff if the brightness is different */ gpm_brightness_get (backlight->priv->brightness, &old_value); if (old_value == value) { egg_debug ("values are the same, no action"); return FALSE; } /* only show dialog if interactive */ if (interactive) { gpm_backlight_dialog_init (backlight); gsd_media_keys_window_set_volume_level (GSD_MEDIA_KEYS_WINDOW (backlight->priv->popup), round (brightness)); gpm_backlight_dialog_show (backlight); } ret = gpm_brightness_set (backlight->priv->brightness, value, &hw_changed); /* we emit a signal for the brightness applet */ if (ret && hw_changed) { egg_debug ("emitting brightness-changed : %i", value); g_signal_emit (backlight, signals [BRIGHTNESS_CHANGED], 0, value); } return TRUE; }
/** * gpm_session_end_session_cb: **/ static void gpm_session_end_session_cb (DBusGProxy *proxy, guint flags, GpmSession *session) { egg_debug ("emitting ::end-session(%i)", flags); g_signal_emit (session, signals [END_SESSION], 0, flags); }
/** * 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; }
/** * gpk_log_filter: **/ static gboolean gpk_log_filter (PkTransactionPast *item) { gboolean ret = FALSE; guint i; guint length; gchar **sections; gchar **packages; gchar **split; gchar *tid; gboolean succeeded; gchar *cmdline; gchar *data; /* get data */ g_object_get (item, "tid", &tid, "succeeded", &succeeded, "cmdline", &cmdline, "data", &data, NULL); /* only show transactions that succeeded */ if (!succeeded) { egg_debug ("tid %s did not succeed, so not adding", tid); return FALSE; } if (filter == NULL) return TRUE; /* matches cmdline */ if (cmdline != NULL && g_strrstr (cmdline, filter) != NULL) ret = TRUE; /* look in all the data for the filter string */ packages = g_strsplit (data, "\n", 0); length = g_strv_length (packages); for (i=0; i<length; i++) { sections = g_strsplit (packages[i], "\t", 0); /* check if type matches filter */ if (g_strrstr (sections[0], filter) != NULL) ret = TRUE; /* check to see if package name, version or arch matches */ split = pk_package_id_split (sections[1]); if (g_strrstr (split[0], filter) != NULL) ret = TRUE; if (split[1] != NULL && g_strrstr (split[1], filter) != NULL) ret = TRUE; if (split[2] != NULL && g_strrstr (split[2], filter) != NULL) ret = TRUE; g_strfreev (split); g_strfreev (sections); /* shortcut for speed */ if (ret) break; } g_free (tid); g_free (cmdline); g_free (data); g_strfreev (packages); return ret; }
/** * gpm_session_init: * @session: This class instance **/ static void gpm_session_init (GpmSession *session) { DBusGConnection *connection; GError *error = NULL; session->priv = GPM_SESSION_GET_PRIVATE (session); session->priv->is_idle_old = FALSE; session->priv->is_idle_inhibited_old = FALSE; session->priv->is_suspend_inhibited_old = FALSE; session->priv->proxy_client_private = NULL; connection = dbus_g_bus_get (DBUS_BUS_SESSION, NULL); /* get org.mate.Session interface */ session->priv->proxy = dbus_g_proxy_new_for_name_owner (connection, GPM_SESSION_MANAGER_SERVICE, GPM_SESSION_MANAGER_PATH, GPM_SESSION_MANAGER_INTERFACE, &error); if (session->priv->proxy == NULL) { egg_warning ("DBUS error: %s", error->message); g_error_free (error); return; } /* get org.mate.Session.Presence interface */ session->priv->proxy_presence = dbus_g_proxy_new_for_name_owner (connection, GPM_SESSION_MANAGER_SERVICE, GPM_SESSION_MANAGER_PRESENCE_PATH, GPM_SESSION_MANAGER_PRESENCE_INTERFACE, &error); if (session->priv->proxy_presence == NULL) { egg_warning ("DBUS error: %s", error->message); g_error_free (error); return; } /* get properties interface */ session->priv->proxy_prop = dbus_g_proxy_new_for_name_owner (connection, GPM_SESSION_MANAGER_SERVICE, GPM_SESSION_MANAGER_PRESENCE_PATH, GPM_DBUS_PROPERTIES_INTERFACE, &error); if (session->priv->proxy_prop == NULL) { egg_warning ("DBUS error: %s", error->message); g_error_free (error); return; } /* get StatusChanged */ dbus_g_proxy_add_signal (session->priv->proxy_presence, "StatusChanged", G_TYPE_UINT, G_TYPE_INVALID); dbus_g_proxy_connect_signal (session->priv->proxy_presence, "StatusChanged", G_CALLBACK (gpm_session_presence_status_changed_cb), session, NULL); /* get InhibitorAdded */ dbus_g_proxy_add_signal (session->priv->proxy, "InhibitorAdded", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); dbus_g_proxy_connect_signal (session->priv->proxy, "InhibitorAdded", G_CALLBACK (gpm_session_inhibit_changed_cb), session, NULL); /* get InhibitorRemoved */ dbus_g_proxy_add_signal (session->priv->proxy, "InhibitorRemoved", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); dbus_g_proxy_connect_signal (session->priv->proxy, "InhibitorRemoved", G_CALLBACK (gpm_session_inhibit_changed_cb), session, NULL); /* coldplug */ session->priv->is_idle_inhibited_old = gpm_session_is_idle_inhibited (session); session->priv->is_suspend_inhibited_old = gpm_session_is_suspend_inhibited (session); session->priv->is_idle_old = gpm_session_is_idle (session); egg_debug ("idle: %i, idle_inhibited: %i, suspend_inhibited: %i", session->priv->is_idle_old, session->priv->is_idle_inhibited_old, session->priv->is_suspend_inhibited_old); }
/** * idle_changed_cb: * @idle: The idle class instance * @mode: The idle mode, e.g. GPM_IDLE_MODE_BLANK * @manager: This class instance * * This callback is called when gnome-screensaver detects that the idle state * has changed. GPM_IDLE_MODE_BLANK is when the session has become inactive, * and GPM_IDLE_MODE_SLEEP is where the session has become inactive, AND the * session timeout has elapsed for the idle action. **/ static void idle_changed_cb (GpmIdle *idle, GpmIdleMode mode, GpmBacklight *backlight) { gboolean ret; GError *error = NULL; gboolean on_battery; gchar *dpms_method; GpmDpmsMode dpms_mode; /* don't dim or undim the screen when the lid is closed */ if (gpm_button_is_lid_closed (backlight->priv->button)) return; /* don't dim or undim the screen unless we are on the active console */ if (!egg_console_kit_is_active (backlight->priv->consolekit)) { egg_debug ("ignoring as not on active console"); return; } if (mode == GPM_IDLE_MODE_NORMAL) { /* sync lcd brightness */ gpm_backlight_notify_system_idle_changed (backlight, FALSE); gpm_backlight_brightness_evaluate_and_set (backlight, FALSE); /* ensure backlight is on */ ret = gpm_dpms_set_mode (backlight->priv->dpms, GPM_DPMS_MODE_ON, &error); if (!ret) { egg_warning ("failed to turn on DPMS: %s", error->message); g_error_free (error); } } else if (mode == GPM_IDLE_MODE_DIM) { /* sync lcd brightness */ gpm_backlight_notify_system_idle_changed (backlight, TRUE); gpm_backlight_brightness_evaluate_and_set (backlight, FALSE); /* ensure backlight is on */ ret = gpm_dpms_set_mode (backlight->priv->dpms, GPM_DPMS_MODE_ON, &error); if (!ret) { egg_warning ("failed to turn on DPMS: %s", error->message); g_error_free (error); } } else if (mode == GPM_IDLE_MODE_BLANK) { /* sync lcd brightness */ gpm_backlight_notify_system_idle_changed (backlight, TRUE); gpm_backlight_brightness_evaluate_and_set (backlight, FALSE); /* get the DPMS state we're supposed to use on the power state */ g_object_get (backlight->priv->client, "on-battery", &on_battery, NULL); if (!on_battery) dpms_method = gconf_client_get_string (backlight->priv->conf, GPM_CONF_BACKLIGHT_DPMS_METHOD_AC, NULL); else dpms_method = gconf_client_get_string (backlight->priv->conf, GPM_CONF_BACKLIGHT_DPMS_METHOD_BATT, NULL); /* convert the string types to standard types */ dpms_mode = gpm_dpms_mode_from_string (dpms_method); /* check if method is valid */ if (dpms_mode == GPM_DPMS_MODE_UNKNOWN || dpms_mode == GPM_DPMS_MODE_ON) { egg_warning ("BACKLIGHT method %s unknown. Using OFF.", dpms_method); dpms_mode = GPM_DPMS_MODE_OFF; } /* turn backlight off */ ret = gpm_dpms_set_mode (backlight->priv->dpms, dpms_mode, &error); if (!ret) { egg_warning ("failed to change DPMS: %s", error->message); g_error_free (error); } g_free (dpms_method); } }
/** * 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; }
/** * 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; }
/** * 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 */ screensaver = gpm_screensaver_new (); 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; } #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); ret = up_client_hibernate_sync (control->priv->client, NULL, error); 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; }
/** * 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; }