]> sjero.net Git - linphone/blob - gtk/utils.c
Merge branch 'master' of git.linphone.org:linphone-private
[linphone] / gtk / utils.c
1 /*
2 linphone, gtk-glade interface.
3 Copyright (C) 2008  Simon MORLAT (simon.morlat@linphone.org)
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 */
19
20 #include "linphone.h"
21
22 static void run_gtk(){
23         while (gtk_events_pending ())
24                 gtk_main_iteration ();
25
26 }
27
28 void *linphone_gtk_wait(LinphoneCore *lc, void *ctx, LinphoneWaitingState ws, const char *purpose, float progress){
29         GtkWidget *w;
30         switch(ws){
31                 case LinphoneWaitingStart:
32                         gdk_threads_enter();
33                         w=linphone_gtk_create_window("waiting");
34                         gtk_window_set_transient_for(GTK_WINDOW(w),GTK_WINDOW(linphone_gtk_get_main_window()));
35                         gtk_window_set_position(GTK_WINDOW(w),GTK_WIN_POS_CENTER_ON_PARENT);
36                         if (purpose) {
37                                 gtk_progress_bar_set_text(
38                                         GTK_PROGRESS_BAR(linphone_gtk_get_widget(w,"progressbar")),
39                                         purpose);
40                         }
41                         gtk_widget_show(w);
42                         /*g_message("Creating waiting window");*/
43                         run_gtk();
44                         gdk_threads_leave();
45                         return w;
46                 break;
47                 case LinphoneWaitingProgress:
48                         w=(GtkWidget*)ctx;
49                         gdk_threads_enter();
50                         if (progress>=0){
51                                 gtk_progress_bar_set_fraction(
52                                         GTK_PROGRESS_BAR(linphone_gtk_get_widget(w,"progressbar")),
53                                         progress);
54                                 
55                                 
56                         }else {
57                                 gtk_progress_bar_pulse(
58                                         GTK_PROGRESS_BAR(linphone_gtk_get_widget(w,"progressbar"))
59                                 );
60                         }
61                         /*g_message("Updating progress");*/
62                         run_gtk();
63                         gdk_threads_leave();
64                         g_usleep(50000);
65                         return w;
66                 break;
67                 case LinphoneWaitingFinished:
68                         w=(GtkWidget*)ctx;
69                         gdk_threads_enter();
70                         gtk_widget_destroy(w);
71                         run_gtk();
72                         gdk_threads_leave();
73                         return NULL;
74                 break;
75         }
76         return NULL;
77 }
78
79 GdkPixbuf *_gdk_pixbuf_new_from_memory_at_scale(const void *data, gint len, gint w, gint h, gboolean preserve_ratio){
80         GInputStream *stream=g_memory_input_stream_new_from_data (data,len,NULL);
81         GError *error=NULL;
82         
83         GdkPixbuf *pbuf=gdk_pixbuf_new_from_stream_at_scale (stream,w,h,preserve_ratio,NULL,&error);
84         g_input_stream_close(stream,NULL,NULL);
85         g_object_unref(G_OBJECT(stream));
86         if (pbuf==NULL){
87                 g_warning("Could not open image from memory");
88         }
89         return pbuf;
90 }
91
92 GtkWidget * _gtk_image_new_from_memory_at_scale(const void *data, gint len, gint w, gint h, gboolean preserve_ratio){
93         GtkWidget *image;
94         GdkPixbuf *pbuf=_gdk_pixbuf_new_from_memory_at_scale(data,len,w,h,preserve_ratio);
95         if (pbuf==NULL) return NULL;
96         image=gtk_image_new_from_pixbuf(pbuf);
97         g_object_unref(G_OBJECT(pbuf));
98         return image;
99 }