Пример #1
1
static void
gm_window_init (GTypeInstance *instance,
                gpointer g_class)
{
  GmWindow *self = NULL;

  (void) g_class; /* -Wextra */

  self = GM_WINDOW (instance);
  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GM_WINDOW_TYPE, GmWindowPrivate);
  self->priv->key = g_strdup ("");
  self->priv->hide_on_esc = TRUE;
  self->priv->hide_on_delete = TRUE;

  self->priv->accel = gtk_accel_group_new ();
  gtk_window_add_accel_group (GTK_WINDOW (self), self->priv->accel);
  gtk_accel_group_connect (self->priv->accel, GDK_Escape, (GdkModifierType) 0, GTK_ACCEL_LOCKED,
                           g_cclosure_new_swap (G_CALLBACK (gtk_widget_hide), (gpointer) self, NULL));

  g_signal_connect (G_OBJECT (self), "delete_event",
		    G_CALLBACK (gm_window_delete_event), NULL);

  g_signal_connect (G_OBJECT (self), "show",
                    G_CALLBACK (gm_window_show), self);

  g_signal_connect (G_OBJECT (self), "hide",
                    G_CALLBACK (gm_window_hide), self);

  g_signal_connect (G_OBJECT (self), "configure-event",
                    G_CALLBACK (gm_window_configure_event), self);
}
Пример #2
0
GtkAccelGroup* maintainr_shell_get_shortcuts (MaintainrShell *shell)
{
	GtkAccelGroup *group;

	group = gtk_accel_group_new ();
	gtk_accel_group_connect (group, GDK_KEY_Up, GDK_CONTROL_MASK, 0, g_cclosure_new (G_CALLBACK (scroll_in_projects), shell, NULL));
	gtk_accel_group_connect (group, GDK_KEY_Down, GDK_CONTROL_MASK, 0, g_cclosure_new (G_CALLBACK (scroll_in_projects), shell, NULL));
	return group;
}
Пример #3
0
static void
build_search_entry(GitgWindow *window, GtkBuilder *builder)
{
	GtkWidget *box = GTK_WIDGET(gtk_builder_get_object(builder, "hbox_top"));
	GtkWidget *entry = sexy_icon_entry_new();
	
	GtkImage *image = GTK_IMAGE(gtk_image_new_from_stock(GTK_STOCK_FIND, GTK_ICON_SIZE_MENU));
	sexy_icon_entry_set_icon(SEXY_ICON_ENTRY(entry), SEXY_ICON_ENTRY_PRIMARY, image);
	
	gtk_tree_view_set_search_entry(window->priv->tree_view, GTK_ENTRY(entry));
	gtk_widget_show(entry);
	gtk_box_pack_end(GTK_BOX(box), entry, FALSE, FALSE, 0);
	
	GtkBuilder *b = gitg_utils_new_builder( "gitg-menus.xml");
	
	GtkUIManager *manager = GTK_UI_MANAGER(gtk_builder_get_object(b, "uiman"));
	window->priv->search_popup = GTK_WIDGET(g_object_ref(gtk_ui_manager_get_widget(manager, "/ui/search_popup")));
	
	gtk_builder_connect_signals(b, window);
	g_object_unref(b);
	
	g_signal_connect(entry, "icon-pressed", G_CALLBACK(on_search_icon_pressed), window);
	gtk_tree_view_set_search_column(window->priv->tree_view, 1);
	
	gtk_tree_view_set_search_equal_func(window->priv->tree_view, search_equal_func, window, NULL);
	
	GtkAccelGroup *group = gtk_accel_group_new();
	
	GClosure *closure = g_cclosure_new(G_CALLBACK(focus_search), entry, NULL); 
	gtk_accel_group_connect(group, GDK_f, GDK_CONTROL_MASK, 0, closure); 
	gtk_window_add_accel_group(GTK_WINDOW(window), group);
}
Пример #4
0
int
clip_GTK_ACCELGROUPCONNECT(ClipMachine * ClipMachineMemory)
{
   C_widget *caccelg = _fetch_cw_arg(ClipMachineMemory);

   guint     accel_key = _clip_parni(ClipMachineMemory, 2);

   GdkModifierType accel_mods = _clip_parni(ClipMachineMemory, 3);

   GtkAccelFlags accel_flags = _clip_parni(ClipMachineMemory, 4);

   C_object *cclosure = _fetch_cobject(ClipMachineMemory, _clip_spar(ClipMachineMemory, 5));

   GClosure *closure;

   CHECKCWID(caccelg, GTK_IS_ACCEL_GROUP);
   CHECKOPT2(1, MAP_type_of_ClipVarType, NUMERIC_type_of_ClipVarType);
   CHECKOPT(2, NUMERIC_type_of_ClipVarType);
   CHECKOPT(3, NUMERIC_type_of_ClipVarType);
   CHECKOPT(4, NUMERIC_type_of_ClipVarType);

   closure = (GClosure *) (cclosure->object);
   gtk_accel_group_connect(GTK_ACCEL_GROUP(caccelg->widget), accel_key, accel_mods, accel_flags, closure);
   return 0;
 err:
   return 1;
}
Пример #5
0
/*#
    @method connect_group
    @brief Installs an accelerator in this group.
    @param accel_key key of the accelerator
    @param accel_mods modifier combination of the accelerator
    @param accel_flags a flag mask to configure this accelerator
    @param callback a function or method to be executed upon accelerator activation

    The connect_group() method installs an accelerator in the accelerator group.
    When the accelerator group is being activated, the function (or method)
    specified by callback will be invoked if the accelerator key and modifier key
    match those specified by accel_key and accel_mods.

    The value of modifier is a combination of the GDK Modifier Constants.
    accel_flags is a combination of gtk.ACCEL_VISIBLE and gtk.ACCEL_LOCKED.

    The callback function is defined as:

    function callback(acceleratable, keyval, modifier)

    where acceleratable is the object that
    the accel_group is attached to (e.g. a gtk.Window), keyval is the accelerator
    key and modifier is the key modifier. callback returns True if the accelerator
    was handled by callback.
 */
FALCON_FUNC AccelGroup::connect_group( VMARG )
{
    Item* i_key = vm->param( 0 );
    Item* i_mods = vm->param( 1 );
    Item* i_flags = vm->param( 2 );
    Item* i_cb = vm->param( 3 );
#ifndef NO_PARAMETER_CHECK
    if ( !i_key || !i_key->isString()
        || !i_mods || !i_mods->isInteger()
        || !i_flags || !i_flags->isInteger()
        || !i_cb || !( i_cb->isCallable() || i_cb->isComposed() ) )
        throw_inv_params( "S,GdkModifierType,GtkAccelFlags,C" );
#endif
    MYSELF;
    GET_OBJ( self );
    String* chr = i_key->asString();
    guint keyval = chr->length() ? chr->getCharAt( 0 ) : 0;

    GarbageLock* lock = CoreGObject::lockItem( _obj, *i_cb );
    GClosure* cl = g_cclosure_new( G_CALLBACK( &AccelGroup::activate_cb ),
                                   (gpointer) lock,
                                   NULL );
    g_object_watch_closure( _obj, cl );

    gtk_accel_group_connect( GET_ACCELGROUP( vm->self() ),
                             keyval,
                             (GdkModifierType) i_mods->asInteger(),
                             (GtkAccelFlags) i_flags->asInteger(),
                             cl );
}
Пример #6
0
static void
gm_window_init (GmWindow* self)
{
  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GM_TYPE_WINDOW, GmWindowPrivate);
  self->priv->settings = NULL;
  self->priv->key = g_strdup ("");
  self->priv->hide_on_esc = TRUE;
  self->priv->hide_on_delete = TRUE;
  self->priv->state_restored = FALSE;

  self->priv->accel = gtk_accel_group_new ();
  gtk_window_add_accel_group (GTK_WINDOW (self), self->priv->accel);
  gtk_accel_group_connect (self->priv->accel, GDK_KEY_Escape, (GdkModifierType) 0, GTK_ACCEL_LOCKED,
                           g_cclosure_new_swap (G_CALLBACK (gtk_widget_hide), (gpointer) self, NULL));

  g_signal_connect (self, "delete-event",
		    G_CALLBACK (gm_window_delete_event_cb), NULL);

  g_signal_connect (self, "show",
                    G_CALLBACK (window_show_cb), self);

  g_signal_connect (self, "realize",
                    G_CALLBACK (window_realize_cb), self);

  g_signal_connect (self, "hide",
                    G_CALLBACK (window_hide_cb), self);

  g_signal_connect (self, "configure-event",
                    G_CALLBACK (gm_window_configure_event), self);
}
Пример #7
0
static void
gis_finished_page_constructed (GObject *object)
{
  GisFinishedPage *page = GIS_FINISHED_PAGE (object);
  GisFinishedPagePrivate *priv = gis_finished_page_get_instance_private (page);
  g_autoptr(GClosure) closure = NULL;

  G_OBJECT_CLASS (gis_finished_page_parent_class)->constructed (object);

  gis_page_set_complete (GIS_PAGE (page), TRUE);

  g_signal_connect (priv->restart_button, "clicked", G_CALLBACK (reboot_cb), page);

  priv->gedit = g_desktop_app_info_new ("org.gnome.gedit.desktop");
  if (priv->gedit != NULL)
    g_signal_connect (priv->diagnostics_label, "activate-link",
                      G_CALLBACK (diagnostics_label_activate_link_cb), page);

  /* Use Ctrl+U to write unattended config */
  priv->accel_group = gtk_accel_group_new ();
  closure = g_cclosure_new_swap (G_CALLBACK (write_unattended_config_cb), page, NULL);
  gtk_accel_group_connect (priv->accel_group, GDK_KEY_u, GDK_CONTROL_MASK, 0, closure);

  gtk_widget_show (GTK_WIDGET (page));
}
Пример #8
0
static void modulewindow_init(ModuleWindow * mw)
{
	GClosure *gclosure;
	GtkAccelGroup *accel_group;

	g_signal_connect(G_OBJECT(mw), "destroy",
			 G_CALLBACK(modulewindow_destroy_cb),
			 mw);

        gtk_window_set_default_size (GTK_WINDOW(mw), MODULEWINDOW_DEFAULT_WIDTH, MODULEWINDOW_DEFAULT_HEIGHT);

	gtk_container_border_width(GTK_CONTAINER(mw), 1);

	accel_group = gtk_accel_group_new();
	gtk_window_add_accel_group(GTK_WINDOW(mw), accel_group);

	/*
	 * close the window when Ctrl and w are pressed.
	 *      accel key combo is static. perhaps there is a better
	 *      way to do this?
	 */
	gclosure =
	    g_cclosure_new((GCallback) modulewindow_close_cb, NULL, NULL);
	gtk_accel_group_connect(accel_group, GDK_w, GDK_CONTROL_MASK, 0,
				gclosure);

	/* Set up the boxes */
	mw->mainbox = gtk_vbox_new(FALSE, 5);
	gtk_container_add(GTK_CONTAINER(mw), mw->mainbox);
	gtk_widget_show(mw->mainbox);

	mw->headbox = gtk_hbox_new(FALSE, 5);
	gtk_box_pack_start(GTK_BOX(mw->mainbox), mw->headbox, FALSE, TRUE,
			   0);
	gtk_widget_show(mw->headbox);

        /* On button */
	mw->onbutton = gtk_toggle_button_new_with_label("On");
	gtk_box_pack_start(GTK_BOX(mw->headbox), mw->onbutton, FALSE,
			   FALSE, 1);
	gtk_widget_show(mw->onbutton);

	gclosure = g_cclosure_new((GCallback) modulewindow_toggle, mw, NULL);
	gtk_accel_group_connect(accel_group, GDK_Escape, 0, 0, gclosure);

}
Пример #9
0
void snippets_accel_connect (GuSnippets* sc, guint keyval, GdkModifierType mod,
        GClosure* closure) {
    gchar* acc = NULL;
    gtk_accel_group_connect (sc->accel_group, keyval,
            gtk_accelerator_get_default_mod_mask () & mod, GTK_ACCEL_VISIBLE,
            closure);

    acc = gtk_accelerator_get_label (keyval,
            gtk_accelerator_get_default_mod_mask () & mod);
    slog (L_DEBUG, "Accelerator `%s' connected\n", acc);
    g_free (acc);
}
Пример #10
0
static void
gtk_ssh_askpass(const char *prompt)
{
	GtkWidget *window, *vbox, *label, *hbox, *ok, *cancel;
	GtkAccelGroup *accel;
	GClosure *closure;

	gtk_init(NULL, NULL);

	accel = gtk_accel_group_new();
	closure = g_cclosure_new(G_CALLBACK(on_escape_key), NULL, NULL);
	gtk_accel_group_connect(accel, GDK_KEY_Escape, 0, 0, closure);

	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_default_size(GTK_WINDOW(window), 10, 10);
	gtk_container_set_border_width(GTK_CONTAINER(window), 5);
	gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_MOUSE);
	gtk_window_add_accel_group(GTK_WINDOW(window), accel);

	vbox = gtk_vbox_new(FALSE, 4);
	label = gtk_label_new(prompt);
	entry = gtk_entry_new();
	gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE);
	hbox = gtk_hbox_new(FALSE, 5);
	ok = gtk_button_new_from_stock(GTK_STOCK_OK);
	cancel = gtk_button_new_from_stock(GTK_STOCK_CANCEL);

	gtk_box_pack_end(GTK_BOX(hbox), cancel, FALSE, FALSE, 0);
	gtk_box_pack_end(GTK_BOX(hbox), ok, FALSE, FALSE, 0);
	gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
	gtk_box_pack_start(GTK_BOX(vbox), entry, FALSE, FALSE, 0);
	gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);

	gtk_container_add(GTK_CONTAINER(window), vbox);

	gtk_widget_show_all(window);

	gtk_widget_grab_focus(window);
	gtk_widget_grab_focus(entry);
	gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE);
	gtk_widget_set_can_default(ok, TRUE);
	gtk_widget_grab_default(ok);

	g_signal_connect(G_OBJECT(window), "delete-event",
	    G_CALLBACK(on_window_delete), NULL);
	g_signal_connect(G_OBJECT(ok), "clicked",
	    G_CALLBACK(on_ok_clicked), NULL);
	g_signal_connect(G_OBJECT(cancel), "clicked",
	    G_CALLBACK(on_cancel_clicked), NULL);

	gtk_main();
}
Пример #11
0
static void _add_hotkey (const gchar *hotkey, GtkAccelGroup *accelgroup,
                GCallback callback, gpointer user_data) {
        GClosure *keycallback;
        guint accelkey;
        GdkModifierType accelmod;

        gtk_accelerator_parse (hotkey, &accelkey, &accelmod);

        keycallback = g_cclosure_new_swap (callback, user_data, NULL);

        gtk_accel_group_connect(accelgroup, accelkey, accelmod, 0, keycallback);
        g_closure_unref(keycallback);
}
Пример #12
0
GClosure* accel_group_add_accelerator(ui::AccelGroup group, Accelerator accelerator, const Callback<void()>& callback ){
	if ( accelerator.key != 0 && gtk_accelerator_valid( accelerator.key, accelerator.modifiers ) ) {
		//globalOutputStream() << "global_accel_connect: " << makeQuoted(accelerator) << "\n";
		GClosure* closure = create_cclosure( G_CALLBACK( accel_closure_callback ), callback );
		gtk_accel_group_connect( group, accelerator.key, accelerator.modifiers, GTK_ACCEL_VISIBLE, closure );
		return closure;
	}
	else
	{
		special_accelerators_add( accelerator, callback );
		return 0;
	}
}
Пример #13
0
void gtkui_page_attach_shortcut(GtkWidget *win, void (*attacher)(void))
{
   GtkAccelGroup *accel;
   GClosure *closure = NULL;
   GdkModifierType mods;
   gint keyval;

   accel = gtk_accel_group_new ();
   gtk_window_add_accel_group(GTK_WINDOW (win), accel);
   closure = g_cclosure_new(G_CALLBACK(attacher), NULL, NULL);
   gtk_accelerator_parse ("<control>D", &keyval, &mods);
   gtk_accel_group_connect(accel, keyval, mods, 0, closure);
}
Пример #14
0
static void
extract_accel_from_menu_item(GMenuModel    * model,
                             gint            item,
                             GActionMap    * action_map,
                             GtkAccelGroup * accel_group)
{
    GMenuAttributeIter *iter;
    const gchar *key;
    GVariant *value;
    const gchar *accel = NULL;
    const gchar *action = NULL;
    GVariant *target = NULL;

    iter = g_menu_model_iterate_item_attributes(model, item);
    while (g_menu_attribute_iter_get_next(iter, &key, &value)) {
        if (g_str_equal(key, "action")
            && g_variant_is_of_type(value, G_VARIANT_TYPE_STRING))
            action = g_variant_get_string(value, NULL);
        else if (g_str_equal(key, "accel")
                 && g_variant_is_of_type(value, G_VARIANT_TYPE_STRING))
            accel = g_variant_get_string(value, NULL);
        else if (g_str_equal(key, "target"))
            target = g_variant_ref(value);
        g_variant_unref(value);
    }
    g_object_unref(iter);

    if (accel && action) {
        guint accel_key;
        GdkModifierType accel_mods;
        AccelInfo *info;
        const gchar *basename;
        GClosure *closure;

        gtk_accelerator_parse(accel, &accel_key, &accel_mods);
        basename = strchr(action, '.');
        basename = basename ? basename + 1 : action;
        info = g_new(AccelInfo, 1);
        info->action = g_action_map_lookup_action(action_map, basename);
        info->parameter = target ? g_variant_ref(target) : NULL;
        closure = g_cclosure_new(G_CALLBACK(accel_activate), info,
                                 (GClosureNotify) accel_info_free);
        gtk_accel_group_connect(accel_group, accel_key, accel_mods, 0,
                                closure);
    }

    if (target)
        g_variant_unref(target);
}
Пример #15
0
GClosure* accel_group_add_accelerator(GtkAccelGroup* group, Accelerator accelerator, const Callback& callback)
{
  if(accelerator.key != 0 && gtk_accelerator_valid(accelerator.key, accelerator.modifiers))
  {
    //globalOutputStream() << "adding accelerator: " << accelerator.key << " " << accelerator.modifiers << "\n";
    GClosure* closure = create_cclosure(G_CALLBACK(accel_closure_callback), callback);
    gtk_accel_group_connect(group, accelerator.key, accelerator.modifiers, GTK_ACCEL_VISIBLE, closure);
    return closure;
  }
  else
  {
    special_accelerators_add(accelerator, callback);
    return 0;
  }
}
Пример #16
0
void install_keyboard_bindings()
{
    GtkAccelGroup *gtk_accel = gtk_accel_group_new ();
    GClosure *closure;

    // Horizontal split
    closure = g_cclosure_new(G_CALLBACK(new_view_horizontal), (gpointer)NULL, NULL);
    gtk_accel_group_connect(gtk_accel, gdk_keyval_from_name("d"), GDK_CONTROL_MASK,
        GTK_ACCEL_VISIBLE, closure);
    g_closure_unref(closure);
    
    // Vertical split
    closure = g_cclosure_new(G_CALLBACK(new_view_vertical), (gpointer)NULL, NULL);
    gtk_accel_group_connect(gtk_accel, gdk_keyval_from_name("s"), GDK_CONTROL_MASK,
        GTK_ACCEL_VISIBLE, closure);
    g_closure_unref(closure);

    closure = g_cclosure_new(G_CALLBACK(next_view), (gpointer)NULL, NULL);
    gtk_accel_group_connect(gtk_accel, gdk_keyval_from_name("w"), GDK_CONTROL_MASK,
        GTK_ACCEL_VISIBLE, closure);
    g_closure_unref(closure);
    
    gtk_window_add_accel_group (GTK_WINDOW(chrome->window), gtk_accel);
}
Пример #17
0
static void
gm_window_set_property (GObject *obj,
                        guint prop_id,
                        const GValue *value,
                        GParamSpec *spec)
{
  GmWindow *self = NULL;
  const gchar *str = NULL;

  self = GM_WINDOW (obj);
  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GM_TYPE_WINDOW, GmWindowPrivate);

  switch (prop_id) {

  case GM_WINDOW_KEY:
    if (self->priv->key)
      g_free (self->priv->key);
    str = g_value_get_string (value);
    self->priv->key = g_strdup (str ? str : "");
    if (self->priv->settings)
      g_clear_object (&self->priv->settings);
    self->priv->settings = g_settings_new (self->priv->key);
    break;

  case GM_HIDE_ON_ESC:
    self->priv->hide_on_esc = g_value_get_boolean (value);
    if (!self->priv->hide_on_esc)
      gtk_accel_group_disconnect_key (self->priv->accel, GDK_KEY_Escape, (GdkModifierType) 0);
    else
      gtk_accel_group_connect (self->priv->accel, GDK_KEY_Escape, (GdkModifierType) 0, GTK_ACCEL_LOCKED,
                               g_cclosure_new_swap (G_CALLBACK (gtk_widget_hide), (gpointer) self, NULL));
    break;

  case GM_HIDE_ON_DELETE:
    self->priv->hide_on_delete = g_value_get_boolean (value);
    break;

  case GM_STAY_ON_TOP:
    self->priv->stay_on_top = g_value_get_boolean (value);
    gtk_window_set_keep_above (GTK_WINDOW (self), self->priv->stay_on_top);
    break;

  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, spec);
    break;
  }
}
Пример #18
0
void add_shortcuts(void)
{
	long i = 0;
	guint acc_key;
	GdkModifierType mod;

	if(macros == NULL)
		return;

	while(macros[i].shortcut != NULL)
	{
		macros[i].closure = g_cclosure_new_swap(G_CALLBACK(shortcut_callback), (gpointer)i, NULL);
		gtk_accelerator_parse(macros[i].shortcut, &acc_key, &mod);
		if(acc_key != 0)
			gtk_accel_group_connect(shortcuts, acc_key, mod, GTK_ACCEL_MASK, macros[i].closure);
		i++;
	}
}
Пример #19
0
void
libbalsa_window_add_accelerator(GtkApplicationWindow * window,
                                const gchar          * accel,
                                const gchar          * action_name)
{
    GActionMap *action_map = G_ACTION_MAP(window);
    guint accel_key;
    GdkModifierType accel_mods;
    const gchar *basename;
    GAction *action;
    AccelInfo *info;
    GClosure *closure;
    GtkAccelGroup *accel_group;

    gtk_accelerator_parse(accel, &accel_key, &accel_mods);
    if (!accel_key) {
        g_print("%s: could not parse accelerator “%s”\n", __func__,
                accel);
        return;
    }

    basename = strchr(action_name, '.');
    basename = basename ? basename + 1 : action_name;
    action = g_action_map_lookup_action(action_map, basename);
    if (!action) {
        g_print("%s: could not lookup action “%s”\n", __func__,
                action_name);
        return;
    }

    info = g_new(AccelInfo, 1);
    info->action = action;
    info->parameter = NULL;
    closure = g_cclosure_new(G_CALLBACK(accel_activate), info,
                             (GClosureNotify) accel_info_free);

    accel_group = gtk_accel_group_new();
    gtk_accel_group_connect(accel_group, accel_key, accel_mods, 0,
                            closure);
    gtk_window_add_accel_group(GTK_WINDOW(window), accel_group);
}
Пример #20
0
static void ghtml_window_initialize(int width, int height, bool as_dialog, void *file) {

	ghtml_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

	GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (ghtml_window));
	GdkVisual *visual = gdk_screen_get_rgba_visual (screen);

	if (visual == NULL)
	visual = gdk_screen_get_system_visual (screen);

	gtk_widget_set_visual (ghtml_window, visual);

	g_signal_connect(ghtml_window, "destroy", G_CALLBACK(ghtml_window_destroy), NULL);

	void *ghtml_window_scrollable_content_area = gtk_scrolled_window_new(NULL, NULL);

	gtk_scrolled_window_set_policy(
		ghtml_window_scrollable_content_area, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC
	);

	if (ghtml_app_title) gtk_window_set_title(ghtml_window, ghtml_app_title);

	gtk_window_set_default_size(ghtml_window, width, height);

	ghtml_webview = WEBKIT_WEB_VIEW(webkit_web_view_new());

	gtk_container_add(ghtml_window, ghtml_window_scrollable_content_area);

	if (as_dialog) {
		gtk_window_set_type_hint((void*) ghtml_window, GDK_WINDOW_TYPE_HINT_DIALOG);
		GtkAccelGroup *gtk_accel = gtk_accel_group_new ();
		GClosure *closure;
		closure = g_cclosure_new (G_CALLBACK (ghtml_window_escaped), NULL, NULL);
		gtk_accel_group_connect (gtk_accel, gdk_keyval_from_name ("Escape"), 0, GTK_ACCEL_LOCKED, closure);
		gtk_window_add_accel_group (ghtml_window, gtk_accel);
	}

	ghtml_webview_initialize(ghtml_window_scrollable_content_area, file, true);

}
Пример #21
0
Файл: config.c Проект: 366/cterm
bool cterm_register_accel(CTerm* term, const char* keyspec, GCallback callback_func) {
    guint key;
    GdkModifierType mod;
    GClosure* closure;

    /* Empty key spec */
    if(keyspec[0] == '\0') {
        return true;
    }

    if(term->config.keys == NULL) {
        term->config.keys = gtk_accel_group_new();
    }

    gtk_accelerator_parse(keyspec, &key, &mod);
    if(key == 0 || mod == 0) {
        return false;
    }
    closure = g_cclosure_new_swap(callback_func, (gpointer)term, NULL);
    gtk_accel_group_connect(term->config.keys, key, mod, GTK_ACCEL_LOCKED, closure);
    return true;
}
Пример #22
0
void
_gtk_window_add_accelerator_for_action (GtkWindow	*window,
					GtkAccelGroup	*accel_group,
					const char	*action_name,
					const char	*accel,
					GVariant	*target)
{
	AccelData	*accel_data;
	guint		 key;
	GdkModifierType  mods;
	GClosure	*closure;

	if ((action_name == NULL) || (accel == NULL))
		return;

	if (g_str_has_prefix (action_name, "app."))
		return;

	accel_data = g_new0 (AccelData, 1);
	accel_data->window = window;
	/* remove the win. prefix from the action name */
	if (g_str_has_prefix (action_name, "win."))
		accel_data->action_name = g_strdup (action_name + strlen ("win."));
	else
		accel_data->action_name = g_strdup (action_name);
	if (target != NULL)
		accel_data->target = g_variant_ref (target);

	gtk_accelerator_parse (accel, &key, &mods);
	closure = g_cclosure_new (G_CALLBACK (window_accelerator_activated_cb),
				  accel_data,
				  accel_data_free);
	gtk_accel_group_connect (accel_group,
				 key,
				 mods,
				 0,
				 closure);
}
Пример #23
0
GtkWidget*
chat_window_new (Ekiga::ServiceCore& core)
{
  ChatWindow* self = NULL;
  GtkAccelGroup *accel = NULL;

  self = (ChatWindow*)g_object_new (CHAT_WINDOW_TYPE,
                                    "hide_on_esc", FALSE,
				    NULL);

  self->priv = new ChatWindowPrivate;

  self->priv->notification_core =
    core.get<Ekiga::NotificationCore>("notification-core");

  self->priv->notebook = gtk_notebook_new ();
  gtk_container_add (GTK_CONTAINER (self), self->priv->notebook);
  gtk_widget_show (self->priv->notebook);

  accel = gtk_accel_group_new ();
  gtk_window_add_accel_group (GTK_WINDOW (self), accel);
  gtk_accel_group_connect (accel, GDK_KEY_Escape, (GdkModifierType) 0, GTK_ACCEL_LOCKED,
                           g_cclosure_new_swap (G_CALLBACK (on_escaped), (gpointer) self, NULL));
  g_object_unref (accel);

  g_signal_connect (self, "focus-in-event",
		    G_CALLBACK (on_focus_in_event), self);
  g_signal_connect (self->priv->notebook, "switch-page",
		    G_CALLBACK (on_switch_page), self);

  boost::shared_ptr<Ekiga::ChatCore> chat_core =
    core.get<Ekiga::ChatCore> ("chat-core");
  self->priv->connections.add (chat_core->dialect_added.connect (boost::bind (&on_dialect_added, self, _1)));
  self->priv->connections.add (chat_core->questions.connect (boost::bind (&on_handle_questions, self, _1)));
  chat_core->visit_dialects (boost::bind (&on_dialect_added, self, _1));

  return (GtkWidget*)self;
}
Пример #24
0
static int
connect_accel_group (OOP accel_group,
                     guint accel_key,
                     GdkModifierType accel_mods,
                     GtkAccelFlags accel_flags,
                     OOP receiver,
                     OOP selector,
		     OOP user_data)
{
  GtkAccelGroup *cObject = _gtk_vm_proxy->OOPToCObject (accel_group);
  int n_params;
  GClosure *closure;
  OOP oop_sel_args;

  oop_sel_args = _gtk_vm_proxy->strMsgSend (selector, "numArgs", NULL);
  if (oop_sel_args == _gtk_vm_proxy->nilOOP)
    return (-3); /* Invalid selector */

  /* Check the number of arguments in the selector against the number of
     arguments in the event callback */

  /* We can return fewer arguments than are in the event, if the others aren't
     wanted, but we can't return more, and returning nilOOPs instead is not
     100% satisfactory, so fail. */
  n_params = _gtk_vm_proxy->OOPToInt (oop_sel_args);
  if (n_params > 4)
    return (-4);

  /* Receiver is assumed to be OK, no matter what it is */
  /* Parameters OK, so carry on and connect the signal */

  closure = smalltalk_closure_new (receiver, selector, NULL,
				   accel_group, n_params);
  gtk_accel_group_connect (cObject, accel_key, accel_mods, accel_flags, closure);
  return 0;
}
Пример #25
0
void build_mainwindow(void) {
    mainwindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);

    gtk_widget_set_app_paintable(mainwindow, TRUE);
    gtk_widget_set_size_request(mainwindow, conf_get_width(), conf_get_height());
    gtk_window_set_decorated(GTK_WINDOW(mainwindow), FALSE);
    gtk_window_set_skip_taskbar_hint(GTK_WINDOW(mainwindow), TRUE);
    gtk_window_set_skip_pager_hint(GTK_WINDOW(mainwindow), TRUE);
    gtk_window_set_resizable(GTK_WINDOW(mainwindow), TRUE);
    mainwindow_reset_position();

    fullscreen = FALSE;
    toggled = FALSE;
    
    GtkAccelGroup* accel_group;
    GClosure *new_tab, *delete_tab, *next_tab, *prev_tab, *delete_all,
        *maximize, *copy, *paste;

    accel_group = gtk_accel_group_new();
    gtk_window_add_accel_group(GTK_WINDOW(mainwindow), accel_group);

    maximize = g_cclosure_new_swap(G_CALLBACK(mainwindow_toggle_fullscreen),
            NULL, NULL);
    gtk_accel_group_connect(accel_group, GDK_F11, 0,
            GTK_ACCEL_VISIBLE, maximize);
    
    new_tab = g_cclosure_new_swap(G_CALLBACK(mainwindow_new_tab), 
            NULL, NULL);
    gtk_accel_group_connect(accel_group, 't', conf_get_key_mod(),
            GTK_ACCEL_VISIBLE, new_tab);

    delete_tab = g_cclosure_new_swap(G_CALLBACK(mainwindow_delete_tab), 
            NULL, NULL);
    gtk_accel_group_connect(accel_group, 'w', conf_get_key_mod(),
            GTK_ACCEL_VISIBLE, delete_tab);

    next_tab = g_cclosure_new_swap(G_CALLBACK(mainwindow_next_tab), 
            NULL, NULL);
    gtk_accel_group_connect(accel_group, GDK_Page_Down, conf_get_key_mod(),
            GTK_ACCEL_VISIBLE, next_tab);

    prev_tab = g_cclosure_new_swap(G_CALLBACK(mainwindow_prev_tab), 
            NULL, NULL);
    gtk_accel_group_connect(accel_group, GDK_Page_Up, conf_get_key_mod(),
            GTK_ACCEL_VISIBLE, prev_tab);

    delete_all = g_cclosure_new_swap(G_CALLBACK(mainwindow_destroy), 
            NULL, NULL);
    gtk_accel_group_connect(accel_group, 'q', conf_get_key_mod(),
            GTK_ACCEL_VISIBLE, delete_all);
            
    copy = g_cclosure_new_swap(G_CALLBACK(mainwindow_copy), 
            NULL, NULL);
    gtk_accel_group_connect(accel_group, 'c', conf_get_key_mod(),
            GTK_ACCEL_VISIBLE, copy);
            
    paste = g_cclosure_new_swap(G_CALLBACK(mainwindow_paste), 
            NULL, NULL);
    gtk_accel_group_connect(accel_group, 'v', conf_get_key_mod(),
            GTK_ACCEL_VISIBLE, paste);

    activetab = -1;
    tabs = g_array_new(TRUE, FALSE, sizeof(VteTerminal*));
    tabcount = 0;
    GtkVBox* mainbox = GTK_VBOX(gtk_vbox_new(FALSE, 0));
    tabbar = GTK_NOTEBOOK(gtk_notebook_new());
    g_signal_connect(G_OBJECT(tabbar), "switch-page",
            G_CALLBACK(mainwindow_switch_tab), NULL);

    if (conf_get_opacity() < 100) {
        GdkScreen *screen = gdk_screen_get_default();
        GdkColormap *colormap = gdk_screen_get_rgba_colormap(screen);
        screen_is_composited = (colormap != NULL
                && gdk_screen_is_composited(screen));

        if (screen_is_composited) {
            gtk_widget_set_colormap(GTK_WIDGET(mainwindow), colormap);
            gdk_screen_set_default_colormap(screen, colormap);
        }
    }

    gtk_box_pack_start(GTK_BOX(mainbox), GTK_WIDGET(tabbar), TRUE, TRUE, 0);

    mainwindow_create_tab();

    gtk_widget_show_all(GTK_WIDGET(mainbox));
    gtk_container_add(GTK_CONTAINER(mainwindow), GTK_WIDGET(mainbox));

    int border = conf_get_border();
    if (border == BORDER_THIN)
        gtk_container_set_border_width(GTK_CONTAINER(mainwindow), 1);
    else if (border == BORDER_THICK)
        gtk_container_set_border_width(GTK_CONTAINER(mainwindow), 5);
    if (border != BORDER_NONE)
        g_signal_connect(G_OBJECT(mainwindow), "expose-event",
                G_CALLBACK(mainwindow_expose_event), NULL);
    /*
     * g_signal_connect connects a GCallback function to a signal for a 
     * particular object.  For example, when the 'focus-out-event' signal is
     * triggered (That is, when Stjerm loses focus), the 
     * 'mainwindow_focus_out_event' function will run.
     */
    if (conf_get_auto_hide())
        g_signal_connect(G_OBJECT(mainwindow), "focus-out-event",
                G_CALLBACK(mainwindow_focus_out_event), NULL);
    g_signal_connect(G_OBJECT(mainwindow), "show", G_CALLBACK(mainwindow_show), 
            NULL);
    g_signal_connect(G_OBJECT(mainwindow), "destroy",
            G_CALLBACK(mainwindow_destroy), NULL);

    gtk_notebook_set_show_border(tabbar, FALSE);
    gtk_notebook_set_scrollable(tabbar, TRUE);
    if (conf_get_show_tab() == TABS_ONE|| conf_get_show_tab() == TABS_NEVER)
        gtk_notebook_set_show_tabs(tabbar, FALSE);
    gtk_notebook_set_tab_pos(tabbar, conf_get_tab_pos());

    XSetErrorHandler(handle_x_error);
    init_key(); // init_key and grab_key are
    grab_key(); // defined globally in stjerm.h
    g_thread_create((GThreadFunc)wait_key, NULL, FALSE, NULL);
}
Пример #26
0
/*
 * display the initial menu to setup global options
 * at startup.
 */
static void gtkui_setup(void)
{
   GtkTextIter iter;
   GtkWidget *item, *vbox, *scroll, *vpaned, *logo;
   GtkItemFactory *item_factory;
   GClosure *closure = NULL;
   GdkModifierType mods;
   gint keyval, width, height, left, top;
   char *path = NULL;

   GtkItemFactoryEntry file_menu[] = {
      { "/_File",         "<shift>F",   NULL,             0, "<Branch>", NULL },
      { "/File/_Open",    "<control>O", gtkui_file_open,  0, "<StockItem>", GTK_STOCK_OPEN },
      { "/File/_Save",    "<control>S", gtkui_file_write, 0, "<StockItem>", GTK_STOCK_SAVE },
      { "/File/sep1",     NULL,         NULL,             0, "<Separator>", NULL },
      { "/File/E_xit",    "<control>x", gtkui_exit,       0, "<StockItem>", GTK_STOCK_QUIT },
      { "/_Sniff",        "<shift>S",   NULL,             0, "<Branch>", NULL },
      { "/Sniff/Unified sniffing...",  "<shift>U", gtkui_unified_sniff, 0, "<StockItem>", GTK_STOCK_DND },
      { "/Sniff/Bridged sniffing...",  "<shift>B", gtkui_bridged_sniff, 0, "<StockItem>", GTK_STOCK_DND_MULTIPLE },
      { "/Sniff/sep2",    NULL,         NULL,             0, "<Separator>", NULL },
      { "/Sniff/Set pcap filter...",    "p",       gtkui_pcap_filter,   0, "<StockItem>", GTK_STOCK_PREFERENCES },
      { "/_Options",                    "<shift>O", NULL, 0, "<Branch>", NULL },
      { "/Options/Unoffensive", NULL, toggle_unoffensive, 0, "<ToggleItem>", NULL },
      { "/Options/Promisc mode", NULL, toggle_nopromisc,  0, "<ToggleItem>", NULL },
      { "/Options/Set netmask", "n", gtkui_set_netmask,   0, "<Item>", NULL}
#ifndef OS_WINDOWS
     ,{"/_?",          NULL,         NULL,             0, "<Branch>", NULL },
      {"/?/Contents", " ",           gtkui_help,       0, "<StockItem>", GTK_STOCK_HELP }
#endif
   };
   gint nmenu_items = sizeof (file_menu) / sizeof (file_menu[0]);

   DEBUG_MSG("gtkui_setup");

   width = gtkui_conf_get("window_width");
   height = gtkui_conf_get("window_height");
   left = gtkui_conf_get("window_left");
   top = gtkui_conf_get("window_top");

   /* create menu window */
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_window_set_title(GTK_WINDOW (window), EC_PROGRAM" "EC_VERSION);
   gtk_window_set_default_size(GTK_WINDOW (window), width, height);

   if(left > 0 || top > 0)
      gtk_window_move(GTK_WINDOW(window), left, top);

   g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtkui_exit), NULL);

   accel_group = gtk_accel_group_new ();
   item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>", accel_group);
   gtk_item_factory_create_items (item_factory, nmenu_items, file_menu, NULL);

   /* hidden shortcut to start Unified Sniffing with default interface */
   closure = g_cclosure_new(G_CALLBACK(gtkui_unified_sniff_default), NULL, NULL);
   gtk_accelerator_parse ("u", &keyval, &mods);
   gtk_accel_group_connect(accel_group, keyval, mods, 0, closure);

   vbox = gtk_vbox_new(FALSE, 0);
   gtk_container_add(GTK_CONTAINER (window), vbox);
   gtk_widget_show(vbox);

   main_menu = gtk_item_factory_get_widget (item_factory, "<main>");
   gtk_box_pack_start(GTK_BOX(vbox), main_menu, FALSE, FALSE, 0);
   gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
   gtk_widget_show(main_menu);

   if(GBL_PCAP->promisc) {
      /* setting the menu item active will toggle this setting */
      /* it will be TRUE after the menu is updated */
      GBL_PCAP->promisc = 0;
      item = gtk_item_factory_get_item(item_factory, "/Options/Promisc mode");
      gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM (item), TRUE);
   }

   if(GBL_OPTIONS->unoffensive) {
      GBL_OPTIONS->unoffensive = 0;
      item = gtk_item_factory_get_item(item_factory, "/Options/Unoffensive");
      gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM (item), TRUE);
   }

   vpaned = gtk_vpaned_new();

   /* notebook for MDI pages */
   notebook_frame = gtk_frame_new(NULL);
   gtk_frame_set_shadow_type(GTK_FRAME (notebook_frame), GTK_SHADOW_IN);
   gtk_paned_pack1(GTK_PANED(vpaned), notebook_frame, TRUE, TRUE);
   gtk_widget_show(notebook_frame);

   path = INSTALL_DATADIR "/" EC_PROGRAM "/" LOGO_FILE;
   if(g_file_test(path, G_FILE_TEST_EXISTS))
      logo = gtk_image_new_from_file(path);
   else /* if neither path is valid gtk will use a broken image icon */
      logo = gtk_image_new_from_file("./share/" LOGO_FILE);

   gtk_misc_set_alignment (GTK_MISC (logo), 0.5, 0.5);
   gtk_container_add(GTK_CONTAINER (notebook_frame), logo);
   gtk_widget_show(logo);

   /* messages */
   scroll = gtk_scrolled_window_new(NULL, NULL);
   gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scroll),
                                  GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
   gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_IN);
   gtk_paned_pack2(GTK_PANED (vpaned), scroll, FALSE, TRUE);
   gtk_widget_show(scroll);

   textview = gtk_text_view_new();
   gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW (textview), GTK_WRAP_WORD_CHAR);
   gtk_text_view_set_editable(GTK_TEXT_VIEW (textview), FALSE);
   gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW (textview), FALSE);
   gtk_widget_set_size_request(textview, -1, 140);
   gtk_container_add(GTK_CONTAINER (scroll), textview);
   gtk_widget_show(textview);

   msgbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW (textview));
   gtk_text_buffer_get_end_iter(msgbuffer, &iter);
   endmark = gtk_text_buffer_create_mark(msgbuffer, "end", &iter, FALSE);

   gtk_box_pack_end(GTK_BOX(vbox), vpaned, TRUE, TRUE, 0);
   gtk_widget_show(vpaned);

   gtk_widget_show(window);

   DEBUG_MSG("gtk_setup: end");
}
Пример #27
0
GtkWidget * yui_scudsp_new(YuiWindow * y) {
  GtkWidget * dialog;
  GClosure *closureF7;
  GtkAccelGroup *accelGroup;
  const scucodebreakpoint_struct *cbp;
  gint i;
  yui = y;

  if ( yui_scudsp ) return GTK_WIDGET(yui_scudsp);
  
  dialog = GTK_WIDGET(g_object_new(yui_scudsp_get_type(), NULL));
  yui_scudsp = YUI_SCUDSP(dialog);

  if (!( yui->state & YUI_IS_INIT )) {
    yui_window_run(yui);
    yui_window_pause(yui);
  }

  ScuDspSetBreakpointCallBack(&yui_scudsp_breakpoint_handler);

  for (i = 0; i < 23 ; i++) {
    
    GtkTreeIter iter;
    gtk_list_store_append( GTK_LIST_STORE( yui_scudsp->regListStore ), &iter );
  }	
  
  cbp = ScuDspGetBreakpointList();
  
  for (i = 0; i < MAX_BREAKPOINTS; i++) {
    
    GtkTreeIter iter;
    yui_scudsp->cbp[i] = cbp[i].addr;
    gtk_list_store_append( GTK_LIST_STORE( yui_scudsp->bpListStore ), &iter );
    if (cbp[i].addr != 0xFFFFFFFF) {
      
      gchar tempstr[20];
      sprintf(tempstr, "%08X", (int)cbp[i].addr);
      gtk_list_store_set( GTK_LIST_STORE( yui_scudsp->bpListStore ), &iter, 0, tempstr, -1 );
    } else gtk_list_store_set( GTK_LIST_STORE( yui_scudsp->bpListStore ), &iter, 0, "<empty>", -1 );
  } 

  {
    GtkWidget * but2, * but3, * but4;
    
    yui_scudsp->buttonStep = gtk_button_new_with_label( "Step [F7]" );
    gtk_box_pack_start( GTK_BOX( yui_scudsp->hbox ), yui_scudsp->buttonStep, FALSE, FALSE, 2 );
    g_signal_connect( yui_scudsp->buttonStep, "clicked", G_CALLBACK(yui_scudsp_step), yui_scudsp );
    
    but2 = gtk_button_new();
    gtk_action_connect_proxy(gtk_action_group_get_action(yui->action_group, "run"), but2);
    gtk_box_pack_start(GTK_BOX(yui_scudsp->hbox), but2, FALSE, FALSE, 2);
    
    but3 = gtk_button_new();
    gtk_action_connect_proxy(gtk_action_group_get_action(yui->action_group, "pause"), but3);
    gtk_box_pack_start(GTK_BOX(yui_scudsp->hbox), but3, FALSE, FALSE, 2);
    
    but4 = gtk_button_new_from_stock("gtk-close");
    g_signal_connect_swapped(but4, "clicked", G_CALLBACK(yui_scudsp_destroy), dialog);
    gtk_box_pack_start(GTK_BOX(yui_scudsp->hbox), but4, FALSE, FALSE, 2);
  }
  yui_scudsp->paused_handler = g_signal_connect_swapped(yui, "paused", G_CALLBACK(yui_scudsp_update), yui_scudsp);
  yui_scudsp->running_handler = g_signal_connect_swapped(yui, "running", G_CALLBACK(yui_scudsp_clear), yui_scudsp);
  accelGroup = gtk_accel_group_new ();
  closureF7 = g_cclosure_new (G_CALLBACK (yui_scudsp_step), yui_scudsp, NULL);
  gtk_accel_group_connect( accelGroup, GDK_F7, 0, 0, closureF7 );
  gtk_window_add_accel_group( GTK_WINDOW( dialog ), accelGroup );
  
  yui_scudsp_update(yui_scudsp);
  if ( yui->state & YUI_IS_RUNNING ) yui_scudsp_clear(yui_scudsp);
  
  gtk_widget_show_all(GTK_WIDGET(yui_scudsp));
  
  return dialog;
}
Пример #28
0
static void
empathy_chat_window_init (EmpathyChatWindow *window)
{
	GladeXML              *glade;
	GtkAccelGroup         *accel_group;
	GClosure              *closure;
	GtkWidget             *menu_conv;
	GtkWidget             *menu;
	gint                   i;
	GtkWidget             *chat_vbox;
	gchar                 *filename;
	EmpathyChatWindowPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (window,
		EMPATHY_TYPE_CHAT_WINDOW, EmpathyChatWindowPriv);

	window->priv = priv;
	filename = empathy_file_lookup ("empathy-chat-window.glade", "src");
	glade = empathy_glade_get_file (filename,
				       "chat_window",
				       NULL,
				       "chat_window", &priv->dialog,
				       "chat_vbox", &chat_vbox,
				       "menu_conv", &menu_conv,
				       "menu_conv_clear", &priv->menu_conv_clear,
				       "menu_conv_insert_smiley", &priv->menu_conv_insert_smiley,
				       "menu_conv_contact", &priv->menu_conv_contact,
				       "menu_conv_close", &priv->menu_conv_close,
				       "menu_edit_cut", &priv->menu_edit_cut,
				       "menu_edit_copy", &priv->menu_edit_copy,
				       "menu_edit_paste", &priv->menu_edit_paste,
				       "menu_tabs_next", &priv->menu_tabs_next,
				       "menu_tabs_prev", &priv->menu_tabs_prev,
				       "menu_tabs_left", &priv->menu_tabs_left,
				       "menu_tabs_right", &priv->menu_tabs_right,
				       "menu_tabs_detach", &priv->menu_tabs_detach,
				       "menu_help_contents", &priv->menu_help_contents,
				       "menu_help_about", &priv->menu_help_about,
				       NULL);
	g_free (filename);

	empathy_glade_connect (glade,
			      window,
			      "chat_window", "configure-event", chat_window_configure_event_cb,
			      "menu_conv", "activate", chat_window_conv_activate_cb,
			      "menu_conv_clear", "activate", chat_window_clear_activate_cb,
			      "menu_conv_close", "activate", chat_window_close_activate_cb,
			      "menu_edit", "activate", chat_window_edit_activate_cb,
			      "menu_edit_cut", "activate", chat_window_cut_activate_cb,
			      "menu_edit_copy", "activate", chat_window_copy_activate_cb,
			      "menu_edit_paste", "activate", chat_window_paste_activate_cb,
			      "menu_tabs_left", "activate", chat_window_tabs_left_activate_cb,
			      "menu_tabs_right", "activate", chat_window_tabs_right_activate_cb,
			      "menu_tabs_detach", "activate", chat_window_detach_activate_cb,
			      "menu_help_contents", "activate", chat_window_help_contents_cb,
			      "menu_help_about", "activate", chat_window_help_about_cb,
			      NULL);

	g_object_unref (glade);

	priv->notebook = gtk_notebook_new ();
 	gtk_notebook_set_group (GTK_NOTEBOOK (priv->notebook), "EmpathyChatWindow"); 
	gtk_box_pack_start (GTK_BOX (chat_vbox), priv->notebook, TRUE, TRUE, 0);
	gtk_widget_show (priv->notebook);

	/* Set up accels */
	accel_group = gtk_accel_group_new ();
	gtk_window_add_accel_group (GTK_WINDOW (priv->dialog), accel_group);

	for (i = 0; i < G_N_ELEMENTS (tab_accel_keys); i++) {
		closure =  g_cclosure_new (G_CALLBACK (chat_window_accel_cb),
					   window,
					   NULL);
		gtk_accel_group_connect (accel_group,
					 tab_accel_keys[i],
					 GDK_MOD1_MASK,
					 0,
					 closure);
	}

	g_object_unref (accel_group);

	/* Set up smiley menu */
	menu = empathy_chat_view_get_smiley_menu (
		G_CALLBACK (chat_window_insert_smiley_activate_cb),
		window);
	gtk_menu_item_set_submenu (GTK_MENU_ITEM (priv->menu_conv_insert_smiley), menu);

	/* Set up signals we can't do with glade since we may need to
	 * block/unblock them at some later stage.
	 */

	g_signal_connect (priv->dialog,
			  "delete_event",
			  G_CALLBACK (chat_window_delete_event_cb),
			  window);

	g_signal_connect_swapped (priv->menu_tabs_prev,
				  "activate",
				  G_CALLBACK (gtk_notebook_prev_page),
				  priv->notebook);
	g_signal_connect_swapped (priv->menu_tabs_next,
				  "activate",
				  G_CALLBACK (gtk_notebook_next_page),
				  priv->notebook);

	g_signal_connect (priv->dialog,
			  "focus_in_event",
			  G_CALLBACK (chat_window_focus_in_event_cb),
			  window);
	g_signal_connect_after (priv->notebook,
				"switch_page",
				G_CALLBACK (chat_window_page_switched_cb),
				window);
	g_signal_connect (priv->notebook,
			  "page_added",
			  G_CALLBACK (chat_window_page_added_cb),
			  window);
	g_signal_connect (priv->notebook,
			  "page_removed",
			  G_CALLBACK (chat_window_page_removed_cb),
			  window);

	/* Set up drag and drop */
	gtk_drag_dest_set (GTK_WIDGET (priv->notebook),
			   GTK_DEST_DEFAULT_ALL,
			   drag_types_dest,
			   G_N_ELEMENTS (drag_types_dest),
			   GDK_ACTION_MOVE);

	g_signal_connect (priv->notebook,
			  "drag-data-received",
			  G_CALLBACK (chat_window_drag_data_received),
			  window);

	chat_windows = g_list_prepend (chat_windows, window);

	/* Set up private details */
	priv->chats = NULL;
	priv->chats_new_msg = NULL;
	priv->chats_composing = NULL;
	priv->current_chat = NULL;
}
int main (int argc, char **argv)
{
    GtkBuilder *builder;
    GtkWidget *widget;
    GtkAccelGroup *ag;
    OsmGpsMap *map;
    OsmGpsMapLayer *osd;
    OsmGpsMapTrack *rightclicktrack;
    const char *repo_uri;
    char *cachedir, *cachebasedir;
    GError *error = NULL;
    GOptionContext *context;

    g_thread_init(NULL);
    gtk_init (&argc, &argv);

    context = g_option_context_new ("- Map browser");
    g_option_context_set_help_enabled(context, FALSE);
    g_option_context_add_main_entries (context, entries, NULL);

    if (!g_option_context_parse (context, &argc, &argv, &error)) {
        usage(context);
        return 1;
    }

    /* Only use the repo_uri to check if the user has supplied a
    valid map source ID */
    repo_uri = osm_gps_map_source_get_repo_uri(opt_map_provider);
    if ( repo_uri == NULL ) {
        usage(context);
        return 2;
    }

    cachebasedir = osm_gps_map_get_default_cache_directory();

    if (opt_cache_base_dir && g_file_test(opt_cache_base_dir, G_FILE_TEST_IS_DIR)) {
        cachedir = g_strdup(OSM_GPS_MAP_CACHE_AUTO);
        cachebasedir = g_strdup(opt_cache_base_dir);
    } else if (opt_friendly_cache) {
        cachedir = g_strdup(OSM_GPS_MAP_CACHE_FRIENDLY);
    } else if (opt_no_cache) {
        cachedir = g_strdup(OSM_GPS_MAP_CACHE_DISABLED);
    } else {
        cachedir = g_strdup(OSM_GPS_MAP_CACHE_AUTO);
    }

    if (opt_debug)
        gdk_window_set_debug_updates(TRUE);

    g_debug("Map Cache Dir: %s", cachedir);
    g_debug("Map Provider: %s (%d)", osm_gps_map_source_get_friendly_name(opt_map_provider), opt_map_provider);

    map = g_object_new (OSM_TYPE_GPS_MAP,
                        "map-source",opt_map_provider,
                        "tile-cache",cachedir,
                        "tile-cache-base", cachebasedir,
                        "proxy-uri",g_getenv("http_proxy"),
                        NULL);

    osd = g_object_new (OSM_TYPE_GPS_MAP_OSD,
                        "show-scale",TRUE,
                        "show-coordinates",TRUE,
                        "show-crosshair",TRUE,
                        "show-dpad",TRUE,
                        "show-zoom",TRUE,
                        "show-gps-in-dpad",TRUE,
                        "show-gps-in-zoom",FALSE,
                        "dpad-radius", 30,
                        NULL);
    osm_gps_map_layer_add(OSM_GPS_MAP(map), osd);
    g_object_unref(G_OBJECT(osd));

    //Add a second track for right clicks
    rightclicktrack = osm_gps_map_track_new();
    osm_gps_map_track_add(OSM_GPS_MAP(map), rightclicktrack);

    g_free(cachedir);
    g_free(cachebasedir);

    //Enable keyboard navigation
    osm_gps_map_set_keyboard_shortcut(map, OSM_GPS_MAP_KEY_FULLSCREEN, GDK_F11);
    osm_gps_map_set_keyboard_shortcut(map, OSM_GPS_MAP_KEY_UP, GDK_Up);
    osm_gps_map_set_keyboard_shortcut(map, OSM_GPS_MAP_KEY_DOWN, GDK_Down);
    osm_gps_map_set_keyboard_shortcut(map, OSM_GPS_MAP_KEY_LEFT, GDK_Left);
    osm_gps_map_set_keyboard_shortcut(map, OSM_GPS_MAP_KEY_RIGHT, GDK_Right);

    //Build the UI
    g_star_image = gdk_pixbuf_new_from_file_at_size ("poi.png", 24,24,NULL);

    builder = gtk_builder_new();
    gtk_builder_add_from_file (builder, "mapviewer.ui", &error);
    if (error)
        g_error ("ERROR: %s\n", error->message);

    gtk_box_pack_start (
                GTK_BOX(gtk_builder_get_object(builder, "map_box")),
                GTK_WIDGET(map), TRUE, TRUE, 0);

    //Init values
    float lw,a;
    GdkColor c;
    OsmGpsMapTrack *gpstrack = osm_gps_map_gps_get_track (map);
    g_object_get (gpstrack, "line-width", &lw, "alpha", &a, NULL);
    osm_gps_map_track_get_color(gpstrack, &c);
    gtk_adjustment_set_value (
                GTK_ADJUSTMENT(gtk_builder_get_object(builder, "gps_width_adjustment")),
                lw);
    gtk_adjustment_set_value (
                GTK_ADJUSTMENT(gtk_builder_get_object(builder, "gps_alpha_adjustment")),
                a);
    gtk_adjustment_set_value (
                GTK_ADJUSTMENT(gtk_builder_get_object(builder, "star_xalign_adjustment")),
                0.5);
    gtk_adjustment_set_value (
                GTK_ADJUSTMENT(gtk_builder_get_object(builder, "star_yalign_adjustment")),
                0.5);
    gtk_color_button_set_color (
                GTK_COLOR_BUTTON(gtk_builder_get_object(builder, "gps_colorbutton")),
                &c);

    //Connect to signals
    g_signal_connect (
                gtk_builder_get_object(builder, "zoom_in_button"), "clicked",
                G_CALLBACK (on_zoom_in_clicked_event), (gpointer) map);
    g_signal_connect (
                gtk_builder_get_object(builder, "zoom_out_button"), "clicked",
                G_CALLBACK (on_zoom_out_clicked_event), (gpointer) map);
    g_signal_connect (
                gtk_builder_get_object(builder, "home_button"), "clicked",
                G_CALLBACK (on_home_clicked_event), (gpointer) map);
    g_signal_connect (
                gtk_builder_get_object(builder, "cache_button"), "clicked",
                G_CALLBACK (on_cache_clicked_event), (gpointer) map);
    g_signal_connect (
                gtk_builder_get_object(builder, "gps_alpha_adjustment"), "value-changed",
                G_CALLBACK (on_gps_alpha_changed), (gpointer) map);
    g_signal_connect (
                gtk_builder_get_object(builder, "gps_width_adjustment"), "value-changed",
                G_CALLBACK (on_gps_width_changed), (gpointer) map);
    g_signal_connect (
                gtk_builder_get_object(builder, "star_xalign_adjustment"), "value-changed",
                G_CALLBACK (on_star_align_changed), (gpointer) "x-align");
    g_signal_connect (
                gtk_builder_get_object(builder, "star_yalign_adjustment"), "value-changed",
                G_CALLBACK (on_star_align_changed), (gpointer) "y-align");
    g_signal_connect (
                gtk_builder_get_object(builder, "gps_colorbutton"), "color-set",
                G_CALLBACK (on_gps_color_changed), (gpointer) gpstrack);
    g_signal_connect (G_OBJECT (map), "button-press-event",
                G_CALLBACK (on_button_press_event), (gpointer) rightclicktrack);
    g_signal_connect (G_OBJECT (map), "button-release-event",
                G_CALLBACK (on_button_release_event),
                (gpointer) gtk_builder_get_object(builder, "text_entry"));
    g_signal_connect (G_OBJECT (map), "notify::tiles-queued",
                G_CALLBACK (on_tiles_queued_changed),
                (gpointer) gtk_builder_get_object(builder, "cache_label"));

    widget = GTK_WIDGET(gtk_builder_get_object(builder, "window1"));
    g_signal_connect (widget, "destroy",
                      G_CALLBACK (on_close), (gpointer) map);
    //Setup accelerators.
    ag = gtk_accel_group_new();
    gtk_accel_group_connect(ag, GDK_w, GDK_CONTROL_MASK, GTK_ACCEL_MASK,
                    g_cclosure_new(gtk_main_quit, NULL, NULL));
    gtk_accel_group_connect(ag, GDK_q, GDK_CONTROL_MASK, GTK_ACCEL_MASK,
                    g_cclosure_new(gtk_main_quit, NULL, NULL));
    gtk_window_add_accel_group(GTK_WINDOW(widget), ag);

    gtk_widget_show_all (widget);

    g_log_set_handler ("OsmGpsMap", G_LOG_LEVEL_MASK, g_log_default_handler, NULL);

    osm_gps_map_set_center_and_zoom(map, 48.858387,2.346268,12);

    gtk_main ();

    return 0;
}
Пример #30
0
gint
main (gint   argc,   /* IN */
      gchar *argv[]) /* IN */
{
	gdouble dashes[] = { 1.0, 4.0 };
	UberRange cpu_range = { 0., 100., 100. };
	UberRange net_range = { 0., 512., 512. };
	UberRange ui_range = { 0., 10., 10. };
	GtkWidget *window;
	GtkWidget *cpu;
	GtkWidget *net;
	GtkWidget *line;
	GtkWidget *map;
	GtkWidget *scatter;
	GtkWidget *label;
	GtkAccelGroup *ag;
	GdkColor color;
	gint lineno;
	gint nprocs;
	gint i;
	gint mod;

	g_thread_init(NULL);
	gtk_init(&argc, &argv);
	nprocs = get_nprocs();
	/*
	 * Check for blktrace hack.
	 */
	if (argc > 1 && (g_strcmp0(argv[1], "--i-can-haz-blktrace") == 0)) {
		want_blktrace = TRUE;
	}
	/*
	 * Warm up differential samplers.
	 */
	smon_next_cpu_info();
	smon_next_cpu_freq_info();
	if (want_blktrace) {
		uber_blktrace_init();
	}
	/*
	 * Install event hook to track how many X events we are doing.
	 */
	gdk_event_handler_set(smon_gdk_event_hook, NULL, NULL);
	/*
	 * Create window and graphs.
	 */
	window = uber_window_new();
	cpu = uber_line_graph_new();
	net = uber_line_graph_new();
	line = uber_line_graph_new();
	map = uber_heat_map_new();
	scatter = uber_scatter_new();
	/*
	 * Configure CPU graph.
	 */
	uber_line_graph_set_autoscale(UBER_LINE_GRAPH(cpu), FALSE);
	uber_graph_set_format(UBER_GRAPH(cpu), UBER_GRAPH_FORMAT_PERCENT);
	uber_line_graph_set_range(UBER_LINE_GRAPH(cpu), &cpu_range);
	uber_line_graph_set_data_func(UBER_LINE_GRAPH(cpu),
	                              smon_get_cpu_info, NULL, NULL);
	for (i = 0; i < nprocs; i++) {
		mod = i % G_N_ELEMENTS(default_colors);
		gdk_color_parse(default_colors[mod], &color);
		label = uber_label_new();
		uber_label_set_color(UBER_LABEL(label), &color);
		uber_line_graph_add_line(UBER_LINE_GRAPH(cpu), &color,
		                         UBER_LABEL(label));
		cpu_info.labels[i] = label;
		/*
		 * XXX: Add the line regardless. Just dont populate it if we don't
		 *      have data.
		 */
		lineno = uber_line_graph_add_line(UBER_LINE_GRAPH(cpu), &color, NULL);
		if (smon_cpu_has_freq_scaling(i)) {
			uber_line_graph_set_line_dash(UBER_LINE_GRAPH(cpu), lineno,
			                              dashes, G_N_ELEMENTS(dashes), 0);
			uber_line_graph_set_line_alpha(UBER_LINE_GRAPH(cpu), lineno, 1.);
		}
	}
	/*
	 * Add lines for GDK/X events.
	 */
	uber_line_graph_set_range(UBER_LINE_GRAPH(line), &ui_range);
	label = uber_label_new();
	uber_label_set_text(UBER_LABEL(label), "GDK Events");
	gdk_color_parse("#729fcf", &color);
	uber_line_graph_add_line(UBER_LINE_GRAPH(line), &color, UBER_LABEL(label));
	label = uber_label_new();
	uber_label_set_text(UBER_LABEL(label), "X Events");
	gdk_color_parse("#a40000", &color);
	uber_line_graph_add_line(UBER_LINE_GRAPH(line), &color, UBER_LABEL(label));
	uber_line_graph_set_data_func(UBER_LINE_GRAPH(line),
	                              smon_get_xevent_info, NULL, NULL);
	/*
	 * Add lines for bytes in/out.
	 */
	uber_line_graph_set_range(UBER_LINE_GRAPH(net), &net_range);
	uber_line_graph_set_data_func(UBER_LINE_GRAPH(net),
	                              smon_get_net_info, NULL, NULL);
	uber_graph_set_format(UBER_GRAPH(net), UBER_GRAPH_FORMAT_DIRECT1024);
	label = uber_label_new();
	uber_label_set_text(UBER_LABEL(label), "Bytes In");
	gdk_color_parse("#a40000", &color);
	uber_line_graph_add_line(UBER_LINE_GRAPH(net), &color, UBER_LABEL(label));
	label = uber_label_new();
	uber_label_set_text(UBER_LABEL(label), "Bytes Out");
	gdk_color_parse("#4e9a06", &color);
	uber_line_graph_add_line(UBER_LINE_GRAPH(net), &color, UBER_LABEL(label));

	/*
	 * Configure heat map.
	 */
	uber_graph_set_show_ylines(UBER_GRAPH(map), FALSE);
	gdk_color_parse(default_colors[0], &color);
	uber_heat_map_set_fg_color(UBER_HEAT_MAP(map), &color);
	uber_heat_map_set_data_func(UBER_HEAT_MAP(map),
	                            (UberHeatMapFunc)dummy_scatter_func, NULL, NULL);
	uber_window_add_graph(UBER_WINDOW(window), UBER_GRAPH(map), "IO Latency");
	uber_graph_set_show_xlabels(UBER_GRAPH(map), FALSE);
	gtk_widget_show(map);

	/*
	 * Configure scatter.
	 */
	if (want_blktrace) {
		uber_graph_set_show_ylines(UBER_GRAPH(scatter), FALSE);
		gdk_color_parse(default_colors[3], &color);
		uber_scatter_set_fg_color(UBER_SCATTER(scatter), &color);
		uber_scatter_set_data_func(UBER_SCATTER(scatter),
								   (UberScatterFunc)uber_blktrace_get, NULL, NULL);
		uber_window_add_graph(UBER_WINDOW(window), UBER_GRAPH(scatter), "IOPS By Size");
		uber_graph_set_show_xlabels(UBER_GRAPH(scatter), TRUE);
		gtk_widget_show(scatter);
	}
	/*
	 * Add graphs.
	 */
	uber_window_add_graph(UBER_WINDOW(window), UBER_GRAPH(cpu), "CPU");
	uber_window_add_graph(UBER_WINDOW(window), UBER_GRAPH(net), "Network");
	uber_window_add_graph(UBER_WINDOW(window), UBER_GRAPH(line), "UI Events");
	/*
	 * Disable X tick labels by default (except last).
	 */
	uber_graph_set_show_xlabels(UBER_GRAPH(cpu), FALSE);
	uber_graph_set_show_xlabels(UBER_GRAPH(net), FALSE);
	uber_graph_set_show_xlabels(UBER_GRAPH(line), FALSE);
	/*
	 * Show widgets.
	 */
	gtk_widget_show(net);
	gtk_widget_show(line);
	gtk_widget_show(cpu);
	gtk_widget_show(window);
	/*
	 * Show cpu labels by default.
	 */
	uber_window_show_labels(UBER_WINDOW(window), UBER_GRAPH(cpu));
	/*
	 * Setup accelerators.
	 */
	ag = gtk_accel_group_new();
	gtk_accel_group_connect(ag, GDK_KEY_w, GDK_CONTROL_MASK, GTK_ACCEL_MASK,
	                        g_cclosure_new(gtk_main_quit, NULL, NULL));
	gtk_window_add_accel_group(GTK_WINDOW(window), ag);
	/*
	 * Attach signals.
	 */
	g_signal_connect(window,
	                 "delete-event",
	                 G_CALLBACK(gtk_main_quit),
	                 NULL);
	/*
	 * Start sampling thread.
	 */
	g_thread_create((GThreadFunc)sample_thread, NULL, FALSE, NULL);
	gtk_main();
	/*
	 * Cleanup after blktrace.
	 */
	if (want_blktrace) {
		uber_blktrace_shutdown();
	}
	return EXIT_SUCCESS;
}