static void
remove_notebook (GeditMultiNotebook *mnb,
GtkWidget *notebook)
{
GtkWidget *parent;
GtkWidget *grandpa;
GList *children;
GtkWidget *new_notebook;
GList *current;
if (mnb->priv->notebooks->next == NULL)
{
g_warning ("You are trying to remove the main notebook");
return;
}
current = g_list_find (mnb->priv->notebooks,
notebook);
if (current->next != NULL)
{
new_notebook = GTK_WIDGET (current->next->data);
}
else
{
new_notebook = GTK_WIDGET (mnb->priv->notebooks->data);
}
parent = gtk_widget_get_parent (notebook);
/* Now we destroy the widget, we get the children of parent and we destroy
parent too as the parent is an useless paned. Finally we add the child
into the grand parent */
g_object_ref (notebook);
mnb->priv->removing_notebook = TRUE;
gtk_widget_destroy (notebook);
mnb->priv->notebooks = g_list_remove (mnb->priv->notebooks,
notebook);
mnb->priv->removing_notebook = FALSE;
children = gtk_container_get_children (GTK_CONTAINER (parent));
if (children->next != NULL)
{
g_warning ("The parent is not a paned");
return;
}
grandpa = gtk_widget_get_parent (parent);
g_object_ref (children->data);
gtk_container_remove (GTK_CONTAINER (parent),
GTK_WIDGET (children->data));
gtk_widget_destroy (parent);
gtk_container_add (GTK_CONTAINER (grandpa),
GTK_WIDGET (children->data));
g_object_unref (children->data);
g_list_free (children);
disconnect_notebook_signals (mnb, notebook);
g_signal_emit (G_OBJECT (mnb), signals[NOTEBOOK_REMOVED], 0, notebook);
g_object_unref (notebook);
/* Let's make the active notebook grab the focus */
gtk_widget_grab_focus (new_notebook);
}
static gboolean
gail_focus_watcher (GSignalInvocationHint *ihint,
guint n_param_values,
const GValue *param_values,
gpointer data)
{
GObject *object;
GtkWidget *widget;
GdkEvent *event;
object = g_value_get_object (param_values + 0);
g_return_val_if_fail (GTK_IS_WIDGET(object), FALSE);
event = g_value_get_boxed (param_values + 1);
widget = GTK_WIDGET (object);
if (event->type == GDK_FOCUS_CHANGE)
{
if (event->focus_change.in)
{
if (GTK_IS_WINDOW (widget))
{
GtkWindow *window;
window = GTK_WINDOW (widget);
if (window->focus_widget)
{
/*
* If we already have a potential focus widget set this
* windows's focus widget to focus_before_menu so that
* it will be reported when menu item is unset.
*/
if (next_focus_widget)
{
if (GTK_IS_MENU_ITEM (next_focus_widget) &&
!focus_before_menu)
{
void *vp_focus_before_menu = &focus_before_menu;
focus_before_menu = window->focus_widget;
g_object_add_weak_pointer (G_OBJECT (focus_before_menu), vp_focus_before_menu);
}
return TRUE;
}
widget = window->focus_widget;
}
else if (window->type == GTK_WINDOW_POPUP)
{
if (GTK_IS_BIN (widget))
{
GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
if (GTK_IS_WIDGET (child) && GTK_WIDGET_HAS_GRAB (child))
{
if (GTK_IS_MENU_SHELL (child))
{
if (GTK_MENU_SHELL (child)->active_menu_item)
{
/*
* We have a menu which has a menu item selected
* so we do not report focus on the menu.
*/
return TRUE;
}
}
widget = child;
}
}
else /* popup window has no children; this edge case occurs in some custom code (OOo for instance) */
{
return TRUE;
}
}
else /* Widget is a non-popup toplevel with no focus children;
don't emit for this case either, as it's useless */
{
return TRUE;
}
}
}
else
{
if (next_focus_widget)
{
GtkWidget *toplevel;
toplevel = gtk_widget_get_toplevel (next_focus_widget);
if (toplevel == widget)
next_focus_widget = NULL;
}
/* focus out */
widget = NULL;
}
}
else
{
if (event->type == GDK_MOTION_NOTIFY && GTK_WIDGET_HAS_FOCUS (widget))
{
if (widget == focus_widget)
{
//.........这里部分代码省略.........
//.........这里部分代码省略.........
next_color = xfce_rc_read_int_entry(settings_ro, "next_color",
next_color);
viewer_text_overlay_enabled = xfce_rc_read_bool_entry(settings_ro,
"viewer_text_overlay_enabled", viewer_text_overlay_enabled);
viewer_text_overlay_format_string = xfce_rc_read_entry(settings_ro,
"viewer_text_overlay_format_string",
viewer_text_overlay_format_string.c_str());
viewer_text_overlay_separator = xfce_rc_read_entry(settings_ro,
"viewer_text_overlay_separator", viewer_text_overlay_separator.c_str());
viewer_text_overlay_font = xfce_rc_read_entry(settings_ro,
"viewer_text_overlay_font", viewer_text_overlay_font.c_str());
viewer_text_overlay_color = xfce_rc_read_int_entry(settings_ro,
"viewer_text_overlay_color", viewer_text_overlay_color);
viewer_monitor_type_sync_enabled = xfce_rc_read_bool_entry(settings_ro,
"viewer_monitor_type_sync_enabled", viewer_monitor_type_sync_enabled);
// Enum is validated in set_viewer_text_overlay_position
CanvasView::TextOverlayPosition text_overlay_position =
static_cast<CanvasView::TextOverlayPosition>(
xfce_rc_read_int_entry(settings_ro, "viewer_text_overlay_position",
CanvasView::top_left));
set_viewer_text_overlay_position(text_overlay_position);
}
// Loading icon
try
{
icon = Gdk::Pixbuf::create_from_file(icon_path);
}
catch (...)
{
std::cerr <<
String::ucompose(_("Hardware Monitor: cannot load the icon '%1'.\n"),
icon_path);
// It's a minor problem if we can't find the icon
icon = Glib::RefPtr<Gdk::Pixbuf>();
}
// Configuring viewer type
viewer_type_listener(viewer_type);
/* Actually setting the viewer size has no effect in this function -
* seems that it needs to be done in or after the mainloop kicks off */
// Loading up monitors
/* Plugin& is initialised from non-transient address of this ('this' itself
* is an rvalue so not allowed for a reference) */
monitor_seq mon = load_monitors(settings_ro, *this);
for (monitor_iter i = mon.begin(), end = mon.end(); i != end; ++i)
add_monitor(*i);
// All settings loaded
if (settings_ro)
xfce_rc_close(settings_ro);
/* Connect plugin signals to functions - since I'm not really interested
* in the plugin but the plugin pointer, swapped results in the signal
* handler getting the plugin reference first - the plugin pointer is
* passed next, but since the handler only takes one parameter this is
* discarded
* Providing About option */
g_signal_connect_swapped(xfce_plugin, "about", G_CALLBACK(display_about),
this);
// Hooking into Properties option
g_signal_connect_swapped(xfce_plugin, "configure-plugin",
G_CALLBACK(display_preferences), this);
// Hooking into plugin destruction signal
g_signal_connect_swapped(xfce_plugin, "free-data", G_CALLBACK(plugin_free),
this);
// Hooking into save signal
g_signal_connect_swapped(xfce_plugin, "save", G_CALLBACK(save_monitors),
this);
/* Not needed as the canvas resizes on the fly
// Hooking into size changed signal
g_signal_connect(xfce_plugin, "size-changed", G_CALLBACK(size_changed),
this);
*/
// Adding configure and about to the plugin's right-click menu
xfce_panel_plugin_menu_show_configure(xfce_plugin);
xfce_panel_plugin_menu_show_about(xfce_plugin);
/* Add plugin to panel - I need to turn the Plugin (which inherits from
* Gtk::EventBox) into a GtkWidget* - to do this I get at the GObject
* pointer underneath the gtkmm layer */
gtk_container_add(GTK_CONTAINER(xfce_plugin), GTK_WIDGET(this->gobj()));
// Initialising timer to run every second (by default) to trigger main_loop
timer =
Glib::signal_timeout().connect(sigc::mem_fun(*this, &Plugin::main_loop),
update_interval);
// Initial main_loop run
main_loop();
}
void
nautilus_launch_desktop_file (GdkScreen *screen,
const char *desktop_file_uri,
const GList *parameter_uris,
GtkWindow *parent_window)
{
GError *error;
char *message, *desktop_file_path;
const GList *p;
GList *files;
int total, count;
GFile *file, *desktop_file;
GDesktopAppInfo *app_info;
GdkAppLaunchContext *context;
/* Don't allow command execution from remote locations
* to partially mitigate the security
* risk of executing arbitrary commands.
*/
desktop_file = g_file_new_for_uri (desktop_file_uri);
desktop_file_path = g_file_get_path (desktop_file);
if (!g_file_is_native (desktop_file)) {
g_free (desktop_file_path);
g_object_unref (desktop_file);
eel_show_error_dialog
(_("Sorry, but you cannot execute commands from "
"a remote site."),
_("This is disabled due to security considerations."),
parent_window);
return;
}
g_object_unref (desktop_file);
app_info = g_desktop_app_info_new_from_filename (desktop_file_path);
g_free (desktop_file_path);
if (app_info == NULL) {
eel_show_error_dialog
(_("There was an error launching the application."),
NULL,
parent_window);
return;
}
/* count the number of uris with local paths */
count = 0;
total = g_list_length ((GList *) parameter_uris);
files = NULL;
for (p = parameter_uris; p != NULL; p = p->next) {
file = g_file_new_for_uri ((const char *) p->data);
if (g_file_is_native (file)) {
count++;
}
files = g_list_prepend (files, file);
}
/* check if this app only supports local files */
if (g_app_info_supports_files (G_APP_INFO (app_info)) &&
!g_app_info_supports_uris (G_APP_INFO (app_info)) &&
parameter_uris != NULL) {
if (count == 0) {
/* all files are non-local */
eel_show_error_dialog
(_("This drop target only supports local files."),
_("To open non-local files copy them to a local folder and then"
" drop them again."),
parent_window);
g_list_free_full (files, g_object_unref);
g_object_unref (app_info);
return;
} else if (count != total) {
/* some files are non-local */
eel_show_warning_dialog
(_("This drop target only supports local files."),
_("To open non-local files copy them to a local folder and then"
" drop them again. The local files you dropped have already been opened."),
parent_window);
}
}
error = NULL;
context = gdk_display_get_app_launch_context (gtk_widget_get_display (GTK_WIDGET (parent_window)));
/* TODO: Ideally we should accept a timestamp here instead of using GDK_CURRENT_TIME */
gdk_app_launch_context_set_timestamp (context, GDK_CURRENT_TIME);
gdk_app_launch_context_set_screen (context,
gtk_window_get_screen (parent_window));
if (count == total) {
/* All files are local, so we can use g_app_info_launch () with
* the file list we constructed before.
*/
g_app_info_launch (G_APP_INFO (app_info),
files,
G_APP_LAUNCH_CONTEXT (context),
&error);
} else {
/* Some files are non local, better use g_app_info_launch_uris ().
*/
g_app_info_launch_uris (G_APP_INFO (app_info),
(GList *) parameter_uris,
//.........这里部分代码省略.........
请发表评论