]> sjero.net Git - linphone/blob - gtk/utils.c
Aac-eld add missing header according to RFC3640 3.3.6
[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 }
100
101 void linphone_gtk_reload_sound_devices(void){
102         GtkWidget *mw=linphone_gtk_get_main_window();
103         GtkWidget *pb=(GtkWidget*)g_object_get_data(G_OBJECT(mw),"parameters");
104         linphone_core_reload_sound_devices(linphone_gtk_get_core());
105         linphone_gtk_fill_soundcards(pb);
106 }
107
108 void linphone_gtk_reload_video_devices(void){
109         GtkWidget *mw=linphone_gtk_get_main_window();
110         GtkWidget *pb=(GtkWidget*)g_object_get_data(G_OBJECT(mw),"parameters");
111         linphone_core_reload_video_devices(linphone_gtk_get_core());
112         linphone_gtk_fill_webcams(pb);
113 }
114
115 #ifdef HAVE_LIBUDEV_H
116
117 static struct udev *udevroot=NULL;
118 static struct udev_monitor *monitor=NULL;
119 static GIOChannel *monitor_channel=NULL;
120 static guint monitor_src_id;
121
122 #include <libudev.h>
123
124 static gboolean on_monitor_data(GIOChannel *chan, GIOCondition cond, void *userdata){
125         struct udev_device *dev=udev_monitor_receive_device(monitor);
126         const char *subsys=udev_device_get_subsystem(dev);
127         const char *type=udev_device_get_action(dev);
128         g_message("USB event arrived for class %s of action type %s",subsys,type);
129         if (strcmp(subsys,"sound")==0) linphone_gtk_reload_sound_devices();
130         if (strcmp(subsys,"video4linux")==0) linphone_gtk_reload_video_devices();
131         udev_device_unref(dev);
132         return TRUE;
133 }
134
135 void linphone_gtk_monitor_usb(void){
136         int fd;
137         udevroot=udev_new();
138         if (!udevroot) return;
139         monitor=udev_monitor_new_from_netlink(udevroot,"udev");
140         udev_monitor_filter_add_match_subsystem_devtype(monitor,"sound",NULL);
141         udev_monitor_filter_add_match_subsystem_devtype(monitor,"video4linux",NULL);
142         fd=udev_monitor_get_fd(monitor);
143         monitor_channel=g_io_channel_unix_new(fd);
144         monitor_src_id=g_io_add_watch(monitor_channel,G_IO_IN,on_monitor_data,NULL);
145         udev_monitor_enable_receiving(monitor);
146 }
147
148 void linphone_gtk_unmonitor_usb(void){
149         if (monitor) udev_monitor_unref(monitor);
150         if (udevroot) udev_unref(udevroot);
151         if (monitor_channel) {
152                 g_source_remove(monitor_src_id);
153                 g_io_channel_unref(monitor_channel);
154         }
155 }
156
157 #else
158
159 void linphone_gtk_monitor_usb(void){
160 }
161 void linphone_gtk_unmonitor_usb(void){
162 }
163
164 #endif
165
166