gaim/gaim

a91f6dfa4164
Parents de189eef5bda
Children
Added a rough whiteboard graphics 'save' button/functionality. Minor changes,
here and there.
--- a/src/gtkwhiteboard.c Fri Aug 05 20:35:59 2005 -0400
+++ b/src/gtkwhiteboard.c Wed Aug 10 17:26:27 2005 -0400
@@ -23,13 +23,15 @@
// INCLUDES ============================================================================================
+#include "blist.h"
+
#include "gtkwhiteboard.h"
// GLOBALS =============================================================================================
//GList *buttonList = NULL;
-//GdkColor DefaultColor[PALETTE_NUM_OF_COLORS];
+//GdkColor DefaultColor[PALETTE_NUM_COLORS];
static gboolean LocalShutdownRequest;
@@ -59,9 +61,10 @@
void gaim_gtk_whiteboard_create( GaimWhiteboard *wb )
{
- //int i;
//g_print( "gaim_gtk_whiteboard_create()\n" );
+ int i;
+
GtkWidget *window;
GtkWidget *drawing_area;
@@ -83,7 +86,8 @@
GtkWidget *clear_button;
GtkWidget *save_button;
- //GtkWidget *color_box[PALETTE_NUM_OF_COLORS];
+ GtkWidget *palette_color_box[PALETTE_NUM_COLORS];
+ GdkPixbuf *palette_color_area[PALETTE_NUM_COLORS];
GaimGtkWhiteboard *gtkwb = g_new0( GaimGtkWhiteboard, 1 );
gtkwb->wb = wb;
@@ -96,7 +100,14 @@
window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
gtkwb->window = window;
gtk_widget_set_name( window, wb->who );
- gtk_window_set_title( ( GtkWindow* )( window ), wb->who ); // TODO Try and use alias first
+
+ // Try and set window title as the name of the buddy, else just use their username
+ const char *window_title = gaim_contact_get_alias( gaim_buddy_get_contact( gaim_find_buddy( wb->account, wb->who ) ) );
+ if( window_title )
+ gtk_window_set_title( ( GtkWindow* )( window ), window_title );
+ else
+ gtk_window_set_title( ( GtkWindow* )( window ), wb->who );
+
gtk_window_set_resizable( ( GtkWindow* )( window ), FALSE );
g_signal_connect( G_OBJECT( window ), "destroy",
@@ -116,15 +127,20 @@
hbox_canvas_and_controls = gtk_hbox_new( FALSE, 0 );
gtk_container_add( GTK_CONTAINER( vbox_palette_above_canvas_and_controls ), hbox_canvas_and_controls );
gtk_widget_show( hbox_canvas_and_controls );
-/*
- for( i = 0; i < PALETTE_NUM_OF_COLORS; i++ )
+
+ for( i = 0; i < PALETTE_NUM_COLORS; i++ )
{
- color_box[i] = gtk_label_new( NULL );
- gtk_widget_set_size_request( color_box[i], gtkwb->width / PALETTE_NUM_OF_COLORS ,32 );
- gtk_container_add( GTK_CONTAINER( hbox_palette ), color_box[i] );
- gtk_widget_show( color_box[i] );
+ //palette_color_area[i] =
+
+ palette_color_box[i] = gtk_image_new_from_pixbuf( NULL );
+ gtk_widget_set_size_request( palette_color_box[i], gtkwb->width / PALETTE_NUM_COLORS ,32 );
+ gtk_container_add( GTK_CONTAINER( hbox_palette ), palette_color_box[i] );
+
+
+
+ gtk_widget_show( palette_color_box[i] );
}
-*/
+
// Create the drawing area
drawing_area = gtk_drawing_area_new();
gtkwb->drawing_area = drawing_area;
@@ -132,14 +148,14 @@
gtk_box_pack_start( GTK_BOX( hbox_canvas_and_controls ), drawing_area, TRUE, TRUE, 8 );
gtk_widget_show( drawing_area );
-
+
// Signals used to handle backing pixmap
g_signal_connect( G_OBJECT( drawing_area ), "expose_event",
G_CALLBACK( gaim_gtk_whiteboard_expose_event ), ( gpointer )( gtkwb ) );
g_signal_connect( G_OBJECT( drawing_area ), "configure_event",
G_CALLBACK( gaim_gtk_whiteboard_configure_event ), ( gpointer )( gtkwb ) );
-
+
// Event signals
g_signal_connect( G_OBJECT( drawing_area ), "button_press_event",
G_CALLBACK( gaim_gtk_whiteboard_brush_down ), ( gpointer )( gtkwb ) );
@@ -149,7 +165,7 @@
g_signal_connect( G_OBJECT( drawing_area ), "button_release_event",
G_CALLBACK( gaim_gtk_whiteboard_brush_up ), ( gpointer )( gtkwb ) );
-
+
gtk_widget_set_events( drawing_area, GDK_EXPOSURE_MASK |
GDK_LEAVE_NOTIFY_MASK |
GDK_BUTTON_PRESS_MASK |
@@ -177,6 +193,9 @@
gtk_box_pack_start( GTK_BOX( vbox_controls ), save_button, FALSE, FALSE, 8 );
gtk_widget_show( save_button );
+ g_signal_connect( G_OBJECT( save_button ), "clicked",
+ G_CALLBACK( gaim_gtk_whiteboard_button_save_press ), ( gpointer )( gtkwb ) );
+
// Make all this (window) visible
gtk_widget_show( window );
@@ -705,6 +724,70 @@
// ------------------------------------------------------------------------------------------------------
+void gaim_gtk_whiteboard_button_save_press( GtkWidget *widget, gpointer data )
+{
+ GaimGtkWhiteboard *gtkwb = ( GaimGtkWhiteboard* )( data );
+ GdkPixbuf *pixbuf;
+
+ GtkWidget *dialog;
+
+ dialog = gtk_file_chooser_dialog_new ("Save File",
+ &gtkwb->window,
+ GTK_FILE_CHOOSER_ACTION_SAVE,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
+ NULL );
+
+ //gtk_file_chooser_set_do_overwrite_confirmation( GTK_FILE_CHOOSER( dialog ), (gboolean)(TRUE) );
+
+// if( user_edited_a_new_document )
+ {
+// gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER( dialog ), default_folder_for_saving );
+ gtk_file_chooser_set_current_name( GTK_FILE_CHOOSER( dialog ), "whiteboard.jpg" );
+ }
+// else
+// gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog), filename_for_existing_document);
+
+ int result = gtk_dialog_run( GTK_DIALOG( dialog ) );
+
+ if( result == GTK_RESPONSE_ACCEPT )
+ {
+ char *filename;
+
+ filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER( dialog ) );
+
+ gtk_widget_destroy( dialog );
+
+ // Makes an icon from the whiteboard's canvas 'image'
+ pixbuf = gdk_pixbuf_get_from_drawable( NULL,
+ ( GdkDrawable* )( gtkwb->pixmap ),
+ gdk_drawable_get_colormap( gtkwb->pixmap ),
+ 0, 0,
+ 0, 0,
+ gtkwb->width, gtkwb->height );
+
+ if( gdk_pixbuf_save( pixbuf,
+ filename,
+ "jpeg",
+ NULL,
+ "quality",
+ "100",
+ NULL ) )
+ g_print( "File Saved...\n" );
+ else
+ g_print( "File not Saved... Error\n" );
+ }
+ else
+ if( result == GTK_RESPONSE_CANCEL )
+ {
+ gtk_widget_destroy( dialog );
+
+ g_print( "File not Saved... Canceled\n" );
+ }
+}
+
+// ------------------------------------------------------------------------------------------------------
+
void gaim_gtk_whiteboard_set_canvas_as_icon( GaimGtkWhiteboard *gtkwb )
{
GdkPixbuf *pixbuf;
@@ -715,7 +798,7 @@
gdk_drawable_get_colormap( gtkwb->pixmap ),
0, 0,
0, 0,
- gtkwb->width, gtkwb->height ); //Constants for protocol specific UI_Ops?
+ gtkwb->width, gtkwb->height );
gtk_window_set_icon( ( GtkWindow* )( gtkwb->window ), pixbuf );
}
--- a/src/gtkwhiteboard.h Fri Aug 05 20:35:59 2005 -0400
+++ b/src/gtkwhiteboard.h Wed Aug 10 17:26:27 2005 -0400
@@ -38,6 +38,8 @@
#define BRUSH_STATE_DOWN 1
#define BRUSH_STATE_MOTION 2
+#define PALETTE_NUM_COLORS 7
+
// DATATYPES ===========================================================================================
typedef struct _GaimGtkWhiteboard
{
@@ -78,6 +80,7 @@
void gaim_gtk_whiteboard_clear( GaimWhiteboard *wb );
void gaim_gtk_whiteboard_button_clear_press( GtkWidget *widget, gpointer data );
+void gaim_gtk_whiteboard_button_save_press( GtkWidget *widget, gpointer data );
void gaim_gtk_whiteboard_set_canvas_as_icon( GaimGtkWhiteboard *gtkwb );
--- a/src/protocols/yahoo/yahoo_doodle.c Fri Aug 05 20:35:59 2005 -0400
+++ b/src/protocols/yahoo/yahoo_doodle.c Wed Aug 10 17:26:27 2005 -0400
@@ -75,18 +75,16 @@
GaimCmdRet yahoo_doodle_gaim_cmd_start( GaimConversation *conv, const char *cmd, char **args, char **error, void *data )
{
+ if( *args && args[0] )
+ return( GAIM_CMD_RET_FAILED );
+
GaimAccount *account = gaim_conversation_get_account( conv );
GaimConnection *gc = gaim_account_get_connection( account );
char *to = ( char* )( gaim_conversation_get_name( conv ) );
-
- if( *args && args[0] )
- return( GAIM_CMD_RET_FAILED );
+ GaimWhiteboard *wb = gaim_whiteboard_get_session( account, to );
// NOTE Functionalize this code?
- // Only handle this if local client requested Doodle session (else local client would have sent one)
- GaimWhiteboard *wb = gaim_whiteboard_get_session( account, to );
-
if( wb == NULL )
{
// Insert this 'session' in the list. At this point, it's only a requested session.
@@ -578,7 +576,7 @@
void yahoo_doodle_start( GaimWhiteboard *wb )
{
- g_print( "yahoo_doodle_start()\n" );
+ //g_print( "yahoo_doodle_start()\n" );
doodle_session *ds = g_new0( doodle_session, 1 );
@@ -587,15 +585,13 @@
ds->brush_color = 0; // black
wb->proto_data = ds;
-
- g_print( "---wb->proto_data:%p\n", wb->proto_data );
}
// ------------------------------------------------------------------------------------------------------
void yahoo_doodle_end( GaimWhiteboard *wb )
{
- g_print( "yahoo_doodle_end()\n" );
+ //g_print( "yahoo_doodle_end()\n" );
GaimConnection *gc = gaim_account_get_connection( wb->account );
@@ -619,19 +615,14 @@
void yahoo_doodle_send_draw_list( GaimWhiteboard *wb, GList *draw_list )
{
- g_print( "yahoo_doodle_send_draw_list()\n" );
+ //g_print( "yahoo_doodle_send_draw_list()\n" );
doodle_session *ds = wb->proto_data;
- if( ds == NULL )
- g_print( "doodle_session not there?\n" );
char *message = yahoo_doodle_build_draw_string( ds, draw_list );
if( message )
- {
yahoo_doodle_command_send_draw( wb->account->gc, wb->who, message );
- }
- else
- g_print( "no message?\n" );
+
}
// ------------------------------------------------------------------------------------------------------
@@ -691,13 +682,10 @@
char *yahoo_doodle_build_draw_string( doodle_session *ds, GList *draw_list )
{
- g_print( "yahoo_doodle_build_draw_string()\n" );
+ //g_print( "yahoo_doodle_build_draw_string()\n" );
if( draw_list == NULL )
- {
- g_print( "---Oh, shit! The list is empty!?! %p\n", draw_list );
return( NULL );
- }
GList *l = draw_list;
@@ -708,13 +696,9 @@
strcpy( message, "\"" );
- g_print( "---SOOOO far!\n" );
-
sprintf( token_string, "%d,%d,", ds->brush_color, ds->brush_size );
strcat( message, token_string );
- g_print( "---Started message with: %s\n", token_string );
-
// Pray this works and pray that the list has an even number of elements
while( l )
{
@@ -731,13 +715,11 @@
l = l->next;
}
- g_print( "---Finished traversing through list\n" );
-
message[strlen( message ) - 1] = '\"';
//message[strlen( message )] = 0;
//message[511] = 0;
- g_print( "Draw Message: %s\n", message );
+ //g_print( "Draw Message: %s\n", message );
return( message );
}
--- a/src/whiteboard.c Fri Aug 05 20:35:59 2005 -0400
+++ b/src/whiteboard.c Wed Aug 10 17:26:27 2005 -0400
@@ -153,17 +153,12 @@
GList *gaim_whiteboard_draw_list_destroy( GList *draw_list )
{
- g_print( "gaim_whiteboard_draw_list_destroy()\n" );
+ //g_print( "gaim_whiteboard_draw_list_destroy()\n" );
if( draw_list == NULL )
- {
- g_print( "-1-FUCK, the list is empty: %p\n", draw_list );
return( NULL );
- }
else
{
- g_print( "-2-d_list:%p\n", draw_list );
-
// Destroy the contents of this list
int *n = NULL;
GList *l = draw_list;
@@ -172,10 +167,7 @@
n = l->data;
if( n )
- {
- g_print( "-3-n=%d\n", *n );
g_free( n );
- }
l = l->next;
}