GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Mon Sep 01, 2014 1:43 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: How to use g_signal_handler_find(), the function is static
PostPosted: Sat Sep 12, 2009 10:44 pm 
Offline

Joined: Sat Sep 12, 2009 10:09 pm
Posts: 4
Hello, I am new to GTK+ programming and I am coding a Pidgin plugin that would allow users to selectively lock conversation windows, so to prevent accidental clicks or maybe to keep conversation window safe for time being.

So far, I can prevent closing tabs and also have disabled the shortcut to close window. The only thing remains is I don't know how to prevent main window from closing.

This might have been possible by catching "delete-event" but as one of Pidgin developers said that my callback function wont be executed as Pidgin already have one Static function for closing windows and doing house cleaning. This function returns TRUE already, so no other callback functions can be executed. Now, as this function is static we cant call it from outside the file and also no other equivalent API is provided.

He further said that I should look into function g_signal_handler_find() which will return the signal_handle and I should block that with g_signal_handler_block().

If I understand correctly, finding out signal_handle is impossible as we don't know "signal_id" and "func" arguments as those are used in static functions by Pidgin itself. Also the last argument "data" cant be used as there are many callback functions which use same arguments ( I have checked source code of this).

How do I go on to find out the solution?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 12, 2009 11:24 pm 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hello and welcome to the GTK+ forums.

I know nothing about Pidgin's internals, so my help isn't specially targeted to this particular problem.

But I can show you how to get signal handler id using data you have.

Code:
guint  signal_id;
gulong handler_id;

signal_id = g_signal_lookup( "delete-event", GTK_TYPE_WINDOW );
handler_id = g_signal_handler_find( (gpointer)window,
                                    G_SIGNAL_MATCH_ID,
                                    signal_id,
                                    0, NULL, NULL, NULL );
Hope this helps a bit.

Tadej


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 13, 2009 5:36 am 
Offline

Joined: Sat Sep 12, 2009 10:09 pm
Posts: 4
Thanks for the example, I think I might be able to solve this. But before hat I am having problem finding the signal_id.

Code:
signal_id = g_signal_lookup( "delete_event", (PidginConversation->win)->window );
purple_debug_fatal("Testing_Plugin, "signal id = %u\n", signal_id);


Pidgin has declared following structure, PidginConversation is a points to win, win points to window id (I think I have understood it correctly), maybe could you take a look at this image? (refer the link in following post, the forum doesnt allow to post links until user has 2 posts)

Pidgin provides API for debugging, thats the second like. You might have guessed, but I wanted to make the situation crystal clear.

The debugger shows
Code:
GLib-GObject: g_signal_lookup: assertion `G_TYPE_IS_INSTANTIATABLE (itype) || G_TYPE_IS_INTERFACE (itype)' failed
Testing_Plugin: signal id = 0


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 13, 2009 5:37 am 
Offline

Joined: Sat Sep 12, 2009 10:09 pm
Posts: 4
The link to data structure : http://developer.pidgin.im/doxygen/dev/ ... ation.html


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 13, 2009 8:55 am 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hi.

g_signal_lookup doesn't take the actual object as a second parameter, it only takes object type. To transplant my sample code into your plugin, you only need to modify g_signal_handler_find function call.

Exact code would look like this:
Code:
signal_id = g_signal_lookup( "delete-event", GTK_TYPE_WINDOW );
handler_id = g_signal_handler_find( (gpointer)PidginConversation->win->window,
                                    G_SIGNAL_MATCH_ID,
                                    signal_id,
                                    0, NULL, NULL, NULL );

Tadej


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 14, 2009 1:19 am 
Offline

Joined: Sat Sep 12, 2009 10:09 pm
Posts: 4
Thank you so much tadeboro, I was able to achieve what I wanted with your precious help. Now the plugins basic functionality is in place, I will add some fancy stuff around it and release it in a week or two.

Slightly off-topic, which book you would recommend for learning GTK+?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group