2 linphone, gtk-glade interface.
\r
3 Copyright (C) 2008 Simon MORLAT (simon.morlat@linphone.org)
\r
5 This program is free software; you can redistribute it and/or
\r
6 modify it under the terms of the GNU General Public License
\r
7 as published by the Free Software Foundation; either version 2
\r
8 of the License, or (at your option) any later version.
\r
10 This program is distributed in the hope that it will be useful,
\r
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 GNU General Public License for more details.
\r
15 You should have received a copy of the GNU General Public License
\r
16 along with this program; if not, write to the Free Software
\r
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
\r
20 #include "linphone.h"
\r
24 #include <wininet.h>
\r
26 static int linphone_gtk_get_new_version(const char *version_url, char *version, size_t size){
\r
27 DWORD dwDownloaded = 0;
\r
28 HINTERNET hSession = NULL, hConnect = NULL;
\r
31 hSession=InternetOpen("Linphone",INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
\r
33 if (hSession==NULL) return -1;
\r
35 hConnect=InternetOpenUrl(hSession,version_url,NULL,0,0,0);
\r
37 if (hConnect==NULL) {
\r
38 InternetCloseHandle(hSession);
\r
42 if (InternetReadFile(hConnect,version,size,&dwDownloaded) && dwDownloaded>0){
\r
43 version[dwDownloaded]='\0';
\r
44 ms_message("Got response: %s", version);
\r
45 /*check this not just html containing 404 not found*/
\r
46 if (strstr(version,"html")==0)
\r
50 // Close any open handles.
\r
51 if (hConnect) InternetCloseHandle(hConnect);
\r
52 if (hSession) InternetCloseHandle(hSession);
\r
58 static int linphone_gtk_get_new_version(const char *url, char *version, size_t size){
\r
65 static void new_version_response(GtkWidget *dialog, int response_id, gpointer download_site){
\r
66 if (response_id==GTK_RESPONSE_YES){
\r
67 linphone_gtk_open_browser((const char*)download_site);
\r
69 gtk_widget_destroy(dialog);
\r
72 static gboolean popup_new_version(const char *download_site){
\r
74 /* draw a question box. link to dialog_click callback */
\r
75 dialog = gtk_message_dialog_new (
\r
76 GTK_WINDOW(linphone_gtk_get_main_window()),
\r
77 GTK_DIALOG_DESTROY_WITH_PARENT,
\r
78 GTK_MESSAGE_QUESTION,
\r
80 _("A more recent version is availalble from %s.\nWould you like to open a browser to download it ?"),
\r
82 g_signal_connect(G_OBJECT (dialog), "response",
\r
83 G_CALLBACK (new_version_response),
\r
84 (gpointer)download_site);
\r
85 /* actually show the box */
\r
86 gtk_widget_show(dialog);
\r
90 static gboolean popup_version_ok(){
\r
91 linphone_gtk_display_something(GTK_MESSAGE_INFO,_("You are running the lastest version."));
\r
95 static int copytilldot(char *n, const char *v){
\r
97 while(*v!='\0' && *v!='.' && *v!='-' && *v!='\n' && *v!='\r' && *v!='\t'){
\r
104 if (*v!='\0') ret=ret+1;
\r
108 static int version_compare(const char *v1, const char *v2){
\r
112 if (*v1=='\0' && *v2=='\0') return 0;
\r
113 v1+=copytilldot(n1,v1);
\r
114 v2+=copytilldot(n2,v2);
\r
115 ms_message("Comparing %s <> %s",n1,n2);
\r
117 if (ret==0) return version_compare(v1,v2);
\r
121 static void *check_for_new_version(void *d){
\r
122 const char *version_url=(const char *)d;
\r
124 if (linphone_gtk_get_new_version(version_url,version,sizeof(version))==0){
\r
125 if (version_compare(version,LINPHONE_VERSION)>0){
\r
126 const char *download_site=linphone_gtk_get_ui_config("download_site",NULL);
\r
127 if (download_site) {
\r
128 gdk_threads_enter();
\r
129 g_idle_add((GSourceFunc)popup_new_version,(gpointer)download_site);
\r
130 gdk_threads_leave();
\r
133 if (linphone_gtk_get_ui_config_int("update_check_menu",0)){
\r
134 gdk_threads_enter();
\r
135 g_idle_add((GSourceFunc)popup_version_ok,NULL);
\r
136 gdk_threads_leave();
\r
143 void linphone_gtk_check_for_new_version(void){
\r
144 ortp_thread_t thread;
\r
145 static gboolean done=FALSE;
\r
146 const char *version_url;
\r
149 version_url=linphone_gtk_get_ui_config("last_version_url",NULL);
\r
150 if (version_url==NULL) return ;
\r
151 ortp_thread_create(&thread,NULL,check_for_new_version,(void*)version_url);
\r
154 /*called when the user clicks on the "Check for updates" menu item */
\r
155 void linphone_gtk_check_for_updates(void){
\r
156 linphone_gtk_check_for_new_version();
\r