g_io_add_watch and non-blocking io on windows

2007-07-05 Thread Alexander Semyonov
Hello! I am trying to discover how to use non-blocking io with glib on
windows. I am trying such program:

/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */

#include glib.h

#ifdef G_OS_WIN32
#include winsock2.h
#include ws2tcpip.h
#endif

gboolean
connect_cb (GIOChannel *io_channel, GIOCondition condition, gpointer data)
{
switch (condition) {
case G_IO_OUT:
g_debug (Connected.);
break;
case G_IO_ERR:
g_debug (Error!);
break;
}

return FALSE;
}

int
main (int argc, char *argv[])
{
#ifdef G_OS_WIN32
int ret;
WSADATA wsaData;
SOCKET  sd;
struct sockaddr_in target;
struct hostent*hptr;
u_long mode = 1;
GMainLoop *loop;
GIOChannel*io_channel;
GSource   *source;

ret = WSAStartup (0x0202, wsaData);
if (ret) {
g_error (WSAStaroup failed with error %d, ret);
}

sd = socket (AF_INET, SOCK_STREAM, 0);
if (sd == INVALID_SOCKET) {
g_error (socket failed with error %d, WSAGetLastError ());
}

target.sin_family = AF_INET;
target.sin_port   = htons (80);
if ( (hptr = gethostbyname (somehost.com)) == NULL) {
g_error (gethostbyname () failed with error %d\n, WSAGetLastError
());
}
memcpy ((target.sin_addr.s_addr), hptr-h_addr_list[0],
sizeof (target.sin_addr.s_addr));

if (ioctlsocket(sd, FIONBIO, mode) == SOCKET_ERROR) {
g_error(ioctlsocket() failed \n);
}

loop = g_main_loop_new (NULL, FALSE);
io_channel = g_io_channel_win32_new_socket (sd);
g_io_channel_set_encoding (io_channel, NULL, NULL);
g_io_channel_set_buffered (io_channel, FALSE);
g_io_add_watch (io_channel, G_IO_ERR | G_IO_OUT, connect_cb, NULL);

g_debug (Executing connect async...);
ret = connect (sd, (const struct sockaddr *) target, sizeof (target));
if (ret == SOCKET_ERROR) {
if (WSAGetLastError () != WSAEWOULDBLOCK)
g_error (connect () failed with error %d\n, WSAGetLastError
());
}

g_debug (Starting GMainLoop...);
g_main_loop_run (loop);

#endif

return 0;
}

/* END */

My problem is that condition parameter in callback is always G_IO_OUT even
if target host:port is unreachable. How can I discover that connect was
unsuccessfull? Thanx.

// wbr Alexander
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


GtkImage with animation: animation stops when all frames are shown

2007-06-01 Thread Alexander Semyonov
Hello. I create GtkImage with animation:

GdkPixbufSimpleAnim *anim = gdk_pixbuf_simple_anim_new (w, h, RATE);
gdk_pixbuf_simple_anim_add_frame (anim, pixbuf1);
gdk_pixbuf_simple_anim_add_frame (anim, pixbuf2);
gdk_pixbuf_simple_anim_add_frame (anim, pixbuf3);
...
GtkWidget *image = gtk_image_new_from_animation (GDK_PIXBUF_ANIMATION
(anim));

But when i display it animation stops when all animation frames are shown,
but i want to have a circular animation. It looks that I should use some
g_timeout_add (...) or anything else. Can someone help me with?
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Howto discover when GtkLabel is elipsized.

2007-05-22 Thread Alexander Semyonov
Hello. I have an elipsized GtkLabel. What I need is to correctly discover
when the ellipsis ... is displayed (I think i must discover it in some
resize or paint event). Can you help me?

Thanx.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Howto discover when GtkLabel is elipsized.

2007-05-22 Thread Alexander Semyonov
I realized that pango_layout_get_width (GTK_LABEL (label)-layout)) return
-1 when the label's text is not elipsized. I think it suffices. :)

On 5/22/07, Alexander Semyonov [EMAIL PROTECTED] wrote:

 Hello. I have an elipsized GtkLabel. What I need is to correctly discover
 when the ellipsis ... is displayed (I think i must discover it in some
 resize or paint event). Can you help me?

 Thanx.

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list