[chronojump] Can read last published version using json



commit 4d0d07a0377e79074bdc4bd0865fc9d5b7013a20
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Jan 27 01:30:10 2015 +0100

    Can read last published version using json

 glade/chronojump.glade        |   72 +++++++++++++++++++++++++++++++++++++++++
 po/POTFILES.in                |    2 +-
 src/Makefile.am               |    2 +-
 src/gui/chronojump.cs         |   20 +++++++++++
 src/gui/error.cs              |   10 +++---
 src/{json_post.cs => json.cs} |   49 ++++++++++++++++++++++++---
 6 files changed, 142 insertions(+), 13 deletions(-)
---
diff --git a/glade/chronojump.glade b/glade/chronojump.glade
index 7389929..e2cecfa 100644
--- a/glade/chronojump.glade
+++ b/glade/chronojump.glade
@@ -372,6 +372,21 @@
                       </widget>
                     </child>
                     <child>
+                      <widget class="GtkSeparatorMenuItem" id="separador3">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                      </widget>
+                    </child>
+                    <child>
+                      <widget class="GtkMenuItem" id="menuitem_check_last_version">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="label" translatable="yes">Check last version</property>
+                        <property name="use_underline">True</property>
+                        <signal name="activate" handler="on_menuitem_check_last_version_activate" 
swapped="no"/>
+                      </widget>
+                    </child>
+                    <child>
                       <widget class="GtkSeparatorMenuItem" id="separator2">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
@@ -6383,6 +6398,9 @@ Second Chronopic to platforms.</property>
                                                         <child>
                                                           <placeholder/>
                                                         </child>
+                                                        <child>
+                                                          <placeholder/>
+                                                        </child>
                                                       </widget>
                                                       <packing>
                                                         <property name="expand">True</property>
@@ -7155,6 +7173,9 @@ Second Chronopic to platforms.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             </child>
                                                             <child>
@@ -8179,6 +8200,9 @@ Second Chronopic to platforms.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="position">2</property>
@@ -8844,6 +8868,9 @@ Second Chronopic to platforms.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="position">4</property>
@@ -19039,6 +19066,9 @@ by you</property>
                         <child>
                           <placeholder/>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                     </child>
                   </widget>
@@ -19612,6 +19642,9 @@ by you</property>
                         <child>
                           <placeholder/>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                     </child>
                   </widget>
@@ -20677,6 +20710,9 @@ by you</property>
               <placeholder/>
             </child>
             <child>
+              <placeholder/>
+            </child>
+            <child>
               <widget class="GtkButton" id="button_video_url">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
@@ -20799,6 +20835,9 @@ by you</property>
             <child>
               <placeholder/>
             </child>
+            <child>
+              <placeholder/>
+            </child>
           </widget>
           <packing>
             <property name="expand">True</property>
@@ -30009,6 +30048,24 @@ options</property>
                             <child>
                               <placeholder/>
                             </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
                           </widget>
                         </child>
                       </widget>
@@ -31962,6 +32019,9 @@ To differentiate between male and female, use the values 1/0, or m/f, or M/F on
                                 <child>
                                   <placeholder/>
                                 </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
                               </widget>
                             </child>
                           </widget>
@@ -32573,6 +32633,9 @@ To differentiate between male and female, use the values 1/0, or m/f, or M/F on
                         <child>
                           <placeholder/>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                     </child>
                   </widget>
@@ -35150,6 +35213,9 @@ show elevation as:</property>
                         <child>
                           <placeholder/>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                       <packing>
                         <property name="left_attach">2</property>
@@ -35387,6 +35453,9 @@ show elevation as:</property>
                     <child>
                       <placeholder/>
                     </child>
+                    <child>
+                      <placeholder/>
+                    </child>
                   </widget>
                 </child>
               </widget>
@@ -35639,6 +35708,9 @@ show elevation as:</property>
                     <child>
                       <placeholder/>
                     </child>
+                    <child>
+                      <placeholder/>
+                    </child>
                   </widget>
                 </child>
               </widget>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 5e3c562..973c010 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -20,7 +20,7 @@ src/execute/pulse.cs
 src/execute/reactionTime.cs
 src/execute/run.cs
 src/exportSession.cs
-src/json_post.cs
+src/json.cs
 src/gui/chronojump.cs
 src/gui/chronopic.cs
 src/gui/convertWeight.cs
diff --git a/src/Makefile.am b/src/Makefile.am
index 0db32cd..9a6cfb1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -121,7 +121,7 @@ SOURCES = \
        event.cs\
        eventType.cs\
        genericObjects.cs\
-       json_post.cs\
+       json.cs\
        jump.cs\
        jumpType.cs\
        person.cs\
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index c9def02..3b6653b 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -5898,6 +5898,26 @@ LogB.Debug("X");
                                "<tt><b>r</b></tt> " + Catalog.GetString("Repair selected test") + " " + 
Catalog.GetString("(if available)")
                                );
        }
+       
+       private void on_menuitem_check_last_version_activate (object o, EventArgs args) {
+               Json js = new Json();
+               bool success = js.GetLastVersion();
+
+               if(success) {
+                       LogB.Information(js.ResultMessage);
+                       new DialogMessage(
+                                       "Chronojump",
+                                       Constants.MessageTypes.INFO, 
+                                       js.ResultMessage);
+               }
+               else {
+                       LogB.Error(js.ResultMessage);
+                       new DialogMessage(
+                                       "Chronojump",
+                                       Constants.MessageTypes.WARNING, 
+                                       js.ResultMessage);
+               }
+       }
 
        private void on_about1_activate (object o, EventArgs args) {
                string translator_credits = Catalog.GetString ("translator-credits");
diff --git a/src/gui/error.cs b/src/gui/error.cs
index a006dd4..7899913 100644
--- a/src/gui/error.cs
+++ b/src/gui/error.cs
@@ -89,18 +89,18 @@ public class ErrorWindow
        }
        private void on_button_send_log_clicked (object o, EventArgs args)
        {
-               JsonPost jp = new JsonPost();
-               bool success = jp.PostCrashLog();
+               Json js = new Json();
+               bool success = js.PostCrashLog();
                
                if(success) {
                        image_send_log_yes.Show();
-                       LogB.Information(jp.ResultMessage);
+                       LogB.Information(js.ResultMessage);
                } else {
                        image_send_log_no.Show();
-                       LogB.Error(jp.ResultMessage);
+                       LogB.Error(js.ResultMessage);
                }
 
-               label_send_log_message.Text = jp.ResultMessage;
+               label_send_log_message.Text = js.ResultMessage;
        }
 
        public void Show_button_open_database_folder () {
diff --git a/src/json_post.cs b/src/json.cs
similarity index 67%
rename from src/json_post.cs
rename to src/json.cs
index 31e717a..f1dcd81 100644
--- a/src/json_post.cs
+++ b/src/json.cs
@@ -23,20 +23,21 @@ using System.Net;
 using System.Web;
 using System.IO;
 using System.Json;
+using System.Collections.Generic; //Dictionary
 using Mono.Unix;
 
-public class JsonPost
+public class Json
 {
        public string ResultMessage;
 
-       public JsonPost()
+       public Json()
        {
                ResultMessage = "";
        }
 
        public bool PostCrashLog() 
        {
-        string serverUrl = "http://api.chronojump.org:8080";;
+               string serverUrl = "http://api.chronojump.org:8080";;
                string filePath = UtilAll.GetLogFileOld();
         string email = "test test com";
 
@@ -65,8 +66,9 @@ public class JsonPost
                try {
                        dataStream = request.GetRequestStream ();
                } catch {
-                       this.ResultMessage = string.Format(Catalog.GetString("Could not send file.\nYou are 
not connected to the Internet\nor {0} server is down."), 
-                                       serverUrl);
+                       this.ResultMessage = Catalog.GetString("Could not send file.") + "\n" + 
+                               string.Format(Catalog.GetString("You are not connected to the Internet\nor 
{0} server is down."), 
+                                               serverUrl);
                        return false;
                }
 
@@ -113,5 +115,40 @@ public class JsonPost
                return System.IO.File.ReadAllBytes(filePath); 
        }
 
-       ~JsonPost() {}
+
+       public bool GetLastVersion() 
+       {
+               string serverUrl = "http://api.chronojump.org:8080";;
+
+               // Create a request using a URL that can receive a post. 
+               WebRequest request = WebRequest.Create (serverUrl + "/version");
+               
+               // Set the Method property of the request to GET.
+               request.Method = "GET";
+               
+               // Set the ContentType property of the WebRequest.
+               //request.ContentType = "application/x-www-form-urlencoded";
+               
+               HttpWebResponse response;
+               try {
+                       response = (HttpWebResponse) request.GetResponse();
+               } catch {
+                       this.ResultMessage = 
+                               Catalog.GetString("Could not get last version.") + "\n" +
+                               string.Format(Catalog.GetString("You are not connected to the Internet\nor 
{0} server is down."), 
+                               serverUrl);
+                       return false;
+               }
+
+               string responseFromServer;
+               using (var sr = new StreamReader(response.GetResponseStream()))
+               {
+                       responseFromServer = sr.ReadToEnd();
+               }
+               this.ResultMessage = "Last version published: " + responseFromServer;
+
+               return true;
+       }
+
+       ~Json() {}
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]