| 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 | #ifdef WIN32 |
|---|
| 23 | |
|---|
| 24 | #include <wininet.h> |
|---|
| 25 | |
|---|
| 26 | static int linphone_gtk_get_new_version(const char *version_url, char *version, size_t size){ |
|---|
| 27 | DWORD dwSize = 0; |
|---|
| 28 | DWORD dwDownloaded = 0; |
|---|
| 29 | LPSTR pszOutBuffer; |
|---|
| 30 | BOOL bResults = FALSE; |
|---|
| 31 | HINTERNET hSession = NULL, |
|---|
| 32 | hConnect = NULL; |
|---|
| 33 | int ret=-1; |
|---|
| 34 | |
|---|
| 35 | hSession=InternetOpen("Linphone",INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0); |
|---|
| 36 | |
|---|
| 37 | if (hSession==NULL) return -1; |
|---|
| 38 | |
|---|
| 39 | hConnect=InternetOpenUrl(hSession,version_url,NULL,0,0,0); |
|---|
| 40 | |
|---|
| 41 | if (hConnect==NULL) { |
|---|
| 42 | InternetCloseHandle(hSession); |
|---|
| 43 | return -1; |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | if (InternetReadFile(hConnect,version,size,&dwDownloaded)){ |
|---|
| 47 | version[dwDownloaded]=0; |
|---|
| 48 | ms_message("Got response: %s", version); |
|---|
| 49 | ret=0; |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | // Close any open handles. |
|---|
| 54 | if (hConnect) InternetCloseHandle(hConnect); |
|---|
| 55 | if (hSession) InternetCloseHandle(hSession); |
|---|
| 56 | return ret; |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | #else |
|---|
| 60 | |
|---|
| 61 | static int linphone_gtk_get_new_version(const char *url, char *version, size_t size){ |
|---|
| 62 | |
|---|
| 63 | return -1; |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | #endif |
|---|
| 67 | |
|---|
| 68 | static void new_version_response(GtkWidget *dialog, int response_id, gpointer download_site){ |
|---|
| 69 | if (response_id==GTK_RESPONSE_YES){ |
|---|
| 70 | linphone_gtk_open_browser((const char*)download_site); |
|---|
| 71 | } |
|---|
| 72 | gtk_widget_destroy(dialog); |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | static void popup_new_version(const char *download_site){ |
|---|
| 76 | GtkWidget *dialog; |
|---|
| 77 | /* draw a question box. link to dialog_click callback */ |
|---|
| 78 | dialog = gtk_message_dialog_new ( |
|---|
| 79 | NULL, |
|---|
| 80 | GTK_DIALOG_DESTROY_WITH_PARENT, |
|---|
| 81 | GTK_MESSAGE_QUESTION, |
|---|
| 82 | GTK_BUTTONS_YES_NO, |
|---|
| 83 | _("A more recent version is availalble from %s.\nWould you like to open a browser to download it ?"), |
|---|
| 84 | download_site); |
|---|
| 85 | g_signal_connect(G_OBJECT (dialog), "response", |
|---|
| 86 | G_CALLBACK (new_version_response), |
|---|
| 87 | (gpointer)download_site); |
|---|
| 88 | /* actually show the box */ |
|---|
| 89 | gtk_widget_show(dialog); |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | static int copytilldot(char *n, const char *v){ |
|---|
| 93 | int ret=0; |
|---|
| 94 | while(*v!='\0' || *v!='.' || *v!='-'){ |
|---|
| 95 | *n=*v; |
|---|
| 96 | ret++; |
|---|
| 97 | v++; |
|---|
| 98 | n++; |
|---|
| 99 | } |
|---|
| 100 | n[ret]='\0'; |
|---|
| 101 | if (*v!='\0') ret=ret+1; |
|---|
| 102 | printf("Got %s",n); |
|---|
| 103 | return ret; |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | static int version_compare(const char *v1, const char *v2){ |
|---|
| 107 | char n1[16]; |
|---|
| 108 | char n2[16]; |
|---|
| 109 | int ret; |
|---|
| 110 | v1+=copytilldot(n1,v1); |
|---|
| 111 | v2+=copytilldot(n2,v2); |
|---|
| 112 | ret=strcmp(n1,n2); |
|---|
| 113 | if (ret==0) return version_compare(v1,v2); |
|---|
| 114 | else return ret; |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | static void *check_for_new_version(void *d){ |
|---|
| 118 | const char *version_url=(const char *)d; |
|---|
| 119 | char version[256]; |
|---|
| 120 | if (linphone_gtk_get_new_version(version_url,version,sizeof(version))==0){ |
|---|
| 121 | if (version_compare(version,LINPHONE_VERSION)>0){ |
|---|
| 122 | const char *download_site=linphone_gtk_get_ui_config("download_site",NULL); |
|---|
| 123 | if (download_site) popup_new_version(download_site); |
|---|
| 124 | } |
|---|
| 125 | } |
|---|
| 126 | return NULL; |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | void linphone_gtk_check_for_new_version(void){ |
|---|
| 130 | ortp_thread_t thread; |
|---|
| 131 | static gboolean done=FALSE; |
|---|
| 132 | const char *version_url; |
|---|
| 133 | if (done) return; |
|---|
| 134 | done=TRUE; |
|---|
| 135 | version_url=linphone_gtk_get_ui_config("last_version_url",NULL); |
|---|
| 136 | if (version_url==NULL) return ; |
|---|
| 137 | ortp_thread_create(&thread,NULL,check_for_new_version,(void*)version_url); |
|---|
| 138 | } |
|---|