[chronojump] News WIP



commit 3966b56013eb531dda9c97a40c9813a26226bf13
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Dec 21 23:08:37 2020 +0100

    News WIP

 glade/app1.glade           | 115 ++++++++++++++++++++++++++++++++++++++-------
 src/Makefile.am            |   2 +
 src/constants.cs           |   1 +
 src/gui/app1/chronojump.cs |  22 +++++++++
 src/gui/app1/menu.cs       |   6 +++
 src/gui/app1/menu_tiny.cs  |   4 ++
 src/json/json.cs           |  28 +++++++++++
 src/news.cs                |  78 ++++++++++++++++++++++++++++++
 src/sqlite/news.cs         |  81 +++++++++++++++++++++++++++++++
 9 files changed, 321 insertions(+), 16 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index 7ae2780e..cfbd42ca 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -297,6 +297,33 @@
                                         <property name="position">2</property>
                                       </packing>
                                     </child>
+                                    <child>
+                                      <widget class="GtkButton" id="button_menu_news1">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">True</property>
+                                        <property name="receives_default">True</property>
+                                        <property name="tooltip" translatable="yes">News</property>
+                                        <signal name="clicked" handler="on_button_menu_news_clicked" 
swapped="no"/>
+                                        <child>
+                                          <widget class="GtkEventBox" id="eventbox_button_menu_news1">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                            <child>
+                                              <widget class="GtkImage" id="image_menu_news1">
+                                                <property name="visible">True</property>
+                                                <property name="can_focus">False</property>
+                                                <property name="stock">gtk-missing-image</property>
+                                              </widget>
+                                            </child>
+                                          </widget>
+                                        </child>
+                                      </widget>
+                                      <packing>
+                                        <property name="expand">False</property>
+                                        <property name="fill">False</property>
+                                        <property name="position">3</property>
+                                      </packing>
+                                    </child>
                                     <child>
                                       <widget class="GtkButton" id="button_menu_exit1">
                                         <property name="visible">True</property>
@@ -322,7 +349,7 @@
                                       <packing>
                                         <property name="expand">False</property>
                                         <property name="fill">False</property>
-                                        <property name="position">3</property>
+                                        <property name="position">4</property>
                                       </packing>
                                     </child>
                                     <child>
@@ -335,7 +362,7 @@
                                       <packing>
                                         <property name="expand">False</property>
                                         <property name="fill">False</property>
-                                        <property name="position">4</property>
+                                        <property name="position">5</property>
                                       </packing>
                                     </child>
                                   </widget>
@@ -939,6 +966,56 @@
                                                             </packing>
                                                             </child>
                                                             <child>
+                                                            <widget class="GtkButton" id="button_menu_news">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">True</property>
+                                                            <property name="receives_default">True</property>
+                                                            <signal name="clicked" 
handler="on_button_menu_news_clicked" swapped="no"/>
+                                                            <child>
+                                                            <widget class="GtkEventBox" 
id="eventbox_button_menu_news">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <child>
+                                                            <widget class="GtkHBox" id="hbox297">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="spacing">4</property>
+                                                            <child>
+                                                            <widget class="GtkImage" id="image_menu_news">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property 
name="stock">gtk-missing-image</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
+                                                            <property name="position">0</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
+                                                            <widget class="GtkLabel" id="label_menu_news">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="label" 
translatable="yes">News</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">True</property>
+                                                            <property name="fill">True</property>
+                                                            <property name="position">1</property>
+                                                            </packing>
+                                                            </child>
+                                                            </widget>
+                                                            </child>
+                                                            </widget>
+                                                            </child>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
+                                                            <property name="position">3</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
                                                             <widget class="GtkButton" id="button_menu_exit">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">True</property>
@@ -986,7 +1063,7 @@
                                                             <packing>
                                                             <property name="expand">False</property>
                                                             <property name="fill">False</property>
-                                                            <property name="position">3</property>
+                                                            <property name="position">4</property>
                                                             </packing>
                                                             </child>
                                                             <child>
@@ -999,7 +1076,7 @@
                                                             <packing>
                                                             <property name="expand">False</property>
                                                             <property name="fill">False</property>
-                                                            <property name="position">4</property>
+                                                            <property name="position">5</property>
                                                             </packing>
                                                             </child>
                                                           </widget>
@@ -23494,6 +23571,9 @@ Concentric</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
@@ -28340,6 +28420,18 @@ Concentric</property>
                                                             <property name="can_focus">False</property>
                                                             <property name="spacing">6</property>
                                                             <child>
+                                                            <widget class="GtkLabel" 
id="label_video_encoder_tests_will_be_filmed">
+                                                            <property name="can_focus">False</property>
+                                                            <property name="label" translatable="yes">Tests 
will be filmed</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
+                                                            <property name="pack_type">end</property>
+                                                            <property name="position">0</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
                                                             <widget class="GtkHBox" 
id="hbox_video_encoder_capturing">
                                                             <property name="can_focus">False</property>
                                                             <property name="spacing">4</property>
@@ -28376,18 +28468,6 @@ Concentric</property>
                                                             </packing>
                                                             </child>
                                                             <child>
-                                                            <widget class="GtkLabel" 
id="label_video_encoder_tests_will_be_filmed">
-                                                            <property name="can_focus">False</property>
-                                                            <property name="label" translatable="yes">Tests 
will be filmed</property>
-                                                            </widget>
-                                                            <packing>
-                                                            <property name="expand">False</property>
-                                                            <property name="fill">False</property>
-                                                            <property name="pack_type">end</property>
-                                                            <property name="position">0</property>
-                                                            </packing>
-                                                            </child>
-                                                            <child>
                                                             <widget class="GtkHBox" 
id="hbox_video_encoder_no_capturing">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">False</property>
@@ -36622,6 +36702,9 @@ then click this button.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
diff --git a/src/Makefile.am b/src/Makefile.am
index a5c473d0..ccdce6ec 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -149,6 +149,7 @@ SOURCES = \
        sqlite/jump.cs\
        sqlite/jumpRj.cs\
        sqlite/jumpType.cs\
+       sqlite/news.cs\
        sqlite/run.cs\
        sqlite/runInterval.cs\
        sqlite/runType.cs\
@@ -212,6 +213,7 @@ SOURCES = \
        jumpsWeightFVProfile.cs\
        jumpType.cs\
        networks.cs\
+       news.cs\
        person.cs\
        personSession.cs\
        run.cs\
diff --git a/src/constants.cs b/src/constants.cs
index 01b4aa0a..7f1a63a0 100644
--- a/src/constants.cs
+++ b/src/constants.cs
@@ -154,6 +154,7 @@ public class Constants
        public const string CountryTable = "country";
        public const string ConvertTempTable = "convertTemp"; //for conversions
        public const string ChronopicRegisterTable = "chronopicRegister";
+       public const string NewsTable = "news";
 
        //tests
        public const string JumpTable = "jump";
diff --git a/src/gui/app1/chronojump.cs b/src/gui/app1/chronojump.cs
index 4065e9f2..a37b92ab 100644
--- a/src/gui/app1/chronojump.cs
+++ b/src/gui/app1/chronojump.cs
@@ -6765,6 +6765,28 @@ LogB.Debug("mc finished 5");
                }
        }
 
+       private void on_button_menu_news_clicked (object o, EventArgs args)
+       {
+               Json js = new Json();
+               bool success = js.GetNews();
+
+               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_menuitem_ping_activate (object o, EventArgs args) 
        {
diff --git a/src/gui/app1/menu.cs b/src/gui/app1/menu.cs
index caac2c16..2b25a0d3 100644
--- a/src/gui/app1/menu.cs
+++ b/src/gui/app1/menu.cs
@@ -49,9 +49,11 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.EventBox eventbox_button_menu_session_more;
        [Widget] Gtk.EventBox eventbox_button_menu_preferences;
        [Widget] Gtk.EventBox eventbox_button_menu_help;
+       [Widget] Gtk.EventBox eventbox_button_menu_news;
        [Widget] Gtk.EventBox eventbox_button_menu_exit;
        [Widget] Gtk.CheckButton check_menu_session;
        [Widget] Gtk.Button button_menu_help;
+       [Widget] Gtk.Button button_menu_news;
        [Widget] Gtk.VBox vbox_menu_session;
        [Widget] Gtk.Alignment alignment_menu_session_options;
        [Widget] Gtk.Alignment alignment_menu_person_options;
@@ -90,6 +92,7 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.Image image_menu_help_documents;
        [Widget] Gtk.Image image_menu_help_shortcuts;
        [Widget] Gtk.Image image_menu_help_about;
+       [Widget] Gtk.Image image_menu_news;
        [Widget] Gtk.Image image_menu_quit;
 
        private void initialize_menu_or_menu_tiny()
@@ -147,6 +150,7 @@ public partial class ChronoJumpWindow
                //menus
                l.Add(check_menu_session.SizeRequest().Width);
                l.Add(button_menu_help.SizeRequest().Width);
+               l.Add(button_menu_news.SizeRequest().Width);
                l.Add(button_menu_exit.SizeRequest().Width);
                l.Add(button_menu_preferences.SizeRequest().Width);
 
@@ -222,6 +226,7 @@ public partial class ChronoJumpWindow
                image_menu_help_documents.Visible = preferences.menuType != Preferences.MenuTypes.TEXT;
                image_menu_help_shortcuts.Visible = preferences.menuType != Preferences.MenuTypes.TEXT;
                image_menu_help_about.Visible = preferences.menuType != Preferences.MenuTypes.TEXT;
+               image_menu_news.Visible = preferences.menuType != Preferences.MenuTypes.TEXT;
                image_menu_quit.Visible = preferences.menuType != Preferences.MenuTypes.TEXT;
        }
 
@@ -252,6 +257,7 @@ public partial class ChronoJumpWindow
                UtilGtk.EventBoxColorBackgroundActive (eventbox_check_menu_session, UtilGtk.YELLOW, 
UtilGtk.YELLOW_LIGHT);
                UtilGtk.EventBoxColorBackgroundActive (eventbox_button_menu_preferences, UtilGtk.YELLOW, 
UtilGtk.YELLOW_LIGHT);
                UtilGtk.EventBoxColorBackgroundActive (eventbox_button_menu_help, UtilGtk.YELLOW, 
UtilGtk.YELLOW_LIGHT);
+               UtilGtk.EventBoxColorBackgroundActive (eventbox_button_menu_news, UtilGtk.YELLOW, 
UtilGtk.YELLOW_LIGHT);
                UtilGtk.EventBoxColorBackgroundActive (eventbox_button_menu_exit, UtilGtk.YELLOW, 
UtilGtk.YELLOW_LIGHT);
 
                UtilGtk.EventBoxColorBackgroundActive (eventbox_button_menu_session_new, UtilGtk.YELLOW, 
UtilGtk.YELLOW_LIGHT);
diff --git a/src/gui/app1/menu_tiny.cs b/src/gui/app1/menu_tiny.cs
index c49e30a3..1c783300 100644
--- a/src/gui/app1/menu_tiny.cs
+++ b/src/gui/app1/menu_tiny.cs
@@ -37,11 +37,13 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.EventBox eventbox_button_menu_session_load1;
        [Widget] Gtk.EventBox eventbox_button_menu_preferences1;
        [Widget] Gtk.EventBox eventbox_button_menu_help1;
+       [Widget] Gtk.EventBox eventbox_button_menu_news1;
        [Widget] Gtk.EventBox eventbox_button_menu_exit1;
        [Widget] Gtk.EventBox eventbox_button_contacts_person_change;
        [Widget] Gtk.EventBox eventbox_button_encoder_person_change;
        [Widget] Gtk.CheckButton check_menu_session1;
        [Widget] Gtk.Button button_menu_help1;
+       [Widget] Gtk.Button button_menu_news1;
        [Widget] Gtk.VBox vbox_menu_session1;
        [Widget] Gtk.Alignment alignment_menu_session_options1;
        [Widget] Gtk.Alignment alignment_menu_person_options1;
@@ -54,6 +56,7 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.Image image_session_more1;
        [Widget] Gtk.Image image_menu_preferences1;
        [Widget] Gtk.Image image_menu_help1;
+       [Widget] Gtk.Image image_menu_news1;
        [Widget] Gtk.Image image_menu_quit1;
        [Widget] Gtk.Button button_menu_guiTest1;
 
@@ -105,6 +108,7 @@ public partial class ChronoJumpWindow
                UtilGtk.EventBoxColorBackgroundActive (eventbox_check_menu_session1, UtilGtk.YELLOW, 
UtilGtk.YELLOW_LIGHT);
                UtilGtk.EventBoxColorBackgroundActive (eventbox_button_menu_preferences1, UtilGtk.YELLOW, 
UtilGtk.YELLOW_LIGHT);
                UtilGtk.EventBoxColorBackgroundActive (eventbox_button_menu_help1, UtilGtk.YELLOW, 
UtilGtk.YELLOW_LIGHT);
+               UtilGtk.EventBoxColorBackgroundActive (eventbox_button_menu_news1, UtilGtk.YELLOW, 
UtilGtk.YELLOW_LIGHT);
                UtilGtk.EventBoxColorBackgroundActive (eventbox_button_menu_exit1, UtilGtk.YELLOW, 
UtilGtk.YELLOW_LIGHT);
 
                UtilGtk.EventBoxColorBackgroundActive (eventbox_button_menu_session_new1, UtilGtk.YELLOW, 
UtilGtk.YELLOW_LIGHT);
diff --git a/src/json/json.cs b/src/json/json.cs
index 808df87e..55674939 100644
--- a/src/json/json.cs
+++ b/src/json/json.cs
@@ -184,6 +184,34 @@ public class Json
                return true;
        }
 
+       public bool GetNews()
+       {
+               // Create a request using a URL that can receive a post.
+               if (! createWebRequest(requestType.GENERIC, "/getNews"))
+                       return false;
+
+               // 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;
+               if(! getHttpWebResponse (request, out response, "Could not get last news."))
+                       return false;
+
+               string responseFromServer;
+               using (var sr = new StreamReader(response.GetResponseStream()))
+               {
+                       responseFromServer = sr.ReadToEnd();
+               }
+
+               string str = responseFromServer;
+
+               this.ResultMessage = str;
+
+               return true;
+       }
        /*
         * if software just started, ping gets stuck by network problems, and user try to exit software,
         * thread.Abort doesn't kill the thread properly
diff --git a/src/news.cs b/src/news.cs
new file mode 100644
index 00000000..03da81cf
--- /dev/null
+++ b/src/news.cs
@@ -0,0 +1,78 @@
+/*
+ * This file is part of ChronoJump
+ *
+ * ChronoJump is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or   
+ *    (at your option) any later version.
+ *    
+ * ChronoJump is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
+ *    GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ *  Copyright (C) 2020   Xavier de Blas <xaviblas gmail com>
+ */
+
+using System;
+using System.IO;               //for detect OS //TextWriter
+using System.Collections.Generic; //List<T>
+using Mono.Unix;
+
+public class News
+{
+       private int uniqueID;
+       private int code; //regular integer
+       private int category; //at the moment: 0 software, 1 products
+       private int version; //is NOT version of the software, is version of the news, because can be updated 
with new text or image. New version of the sofware will be simply a new code
+       private string versionDateTime;
+       private bool viewed;
+       private string title;
+       private string link;
+       private string description;
+
+       /* constructors */
+
+       //have a uniqueID -1 contructor, useful when set is deleted
+       public News()
+       {
+               uniqueID = -1;
+       }
+
+       //constructor
+       public News(int uniqueID, int code, int category, int version, string versionDateTime,
+                       bool viewed, string title, string link, string description)
+       {
+               this.uniqueID = uniqueID;
+               this.code = code;
+               this.category = category;
+               this.version = version;
+               this.versionDateTime = versionDateTime;
+               this.viewed = viewed;
+               this.title = title;
+               this.link = link;
+               this.description = description;
+       }
+
+       /* methods */
+
+       public int InsertSQL(bool dbconOpened)
+       {
+               return SqliteNews.Insert(dbconOpened, toSQLInsertString());
+       }
+       private string toSQLInsertString()
+       {
+               string uniqueIDStr = "NULL";
+               if(uniqueID != -1)
+                       uniqueIDStr = uniqueID.ToString();
+
+               return uniqueIDStr + ", " + code + ", " + category + ", " +
+                       version + ", \"" + versionDateTime + "\", " + Util.BoolToInt(viewed).ToString() + ", 
\"" +
+                              title + "\", \"" + link + "\", \"" + description + "\"";
+       }
+
+}
diff --git a/src/sqlite/news.cs b/src/sqlite/news.cs
new file mode 100644
index 00000000..c885ecee
--- /dev/null
+++ b/src/sqlite/news.cs
@@ -0,0 +1,81 @@
+/*
+ * This file is part of ChronoJump
+ *
+ * ChronoJump is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or   
+ *    (at your option) any later version.
+ *    
+ * ChronoJump is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
+ *    GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Copyright (C) 2020   Xavier de Blas <xaviblas gmail com> 
+ */
+
+using System;
+//using System.Data;
+using System.Collections;
+using System.Collections.Generic; //List<T>
+using Mono.Data.Sqlite;
+
+class SqliteNews : Sqlite
+{
+       private static string table = Constants.NewsTable;
+
+       public SqliteNews() {
+       }
+       
+       ~SqliteNews() {}
+       
+       /*
+        * create and initialize tables
+        */
+
+       //server table is created like this:
+       //create table news (code INT NOT NULL AUTO_INCREMENT PRIMARY KEY, category INT, version INT, 
versionDateTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP, title char(255), linkWeb char(255), linkImage char(255), 
description char(255));
+       //INSERT INTO news VALUES (NULL, 1, 0, current_timestamp(), "my title", "http://chronojump.org/test";, 
"https://chronojump.org/wp-content/uploads/2019/08/Adaptadors-scaled.jpeg";, "This is the description");
+
+
+       protected internal static void createTable ()
+       {
+               dbcmd.CommandText = 
+                       "CREATE TABLE " + table + " ( " +
+                       "uniqueID INTEGER PRIMARY KEY, " +
+                       "code INT, " +
+                       "category INT, " +
+                       "version INT, " +
+                       "versionDateTime TEXT, " +
+                       "viewed INT, " +
+                       "title TEXT, " +
+                       "link TEXT, " +
+                       "description TEXT )";
+               dbcmd.ExecuteNonQuery();
+       }
+
+       public static int Insert (bool dbconOpened, string insertString)
+       {
+               openIfNeeded(dbconOpened);
+
+               dbcmd.CommandText = "INSERT INTO " + table +
+                               " (uniqueID, code, category, version, versionDateTime, viewed, title, link, 
description)" +
+                               " VALUES (" + insertString + ")";
+               LogB.SQL(dbcmd.CommandText.ToString());
+               dbcmd.ExecuteNonQuery();
+
+               string myString = @"select last_insert_rowid()";
+               dbcmd.CommandText = myString;
+               int myLast = Convert.ToInt32(dbcmd.ExecuteScalar()); // Need to type-cast since 
`ExecuteScalar` returns an object.
+
+               closeIfNeeded(dbconOpened);
+
+               return myLast;
+       }
+
+}
+


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