[chronojump/chronojump-importer: 29/66] Shows a text box to type (this will be fixed) the path to import the session from.



commit 5d5542bdeb80db5560366d81114b7d806219b8a5
Author: Carles Pina i Estany <carles pina cat>
Date:   Tue Sep 13 09:59:10 2016 +0100

    Shows a text box to type (this will be fixed) the path to import the session from.
    
    It's the same dialogue as Load Session.

 glade/chronojump.glade |   78 ++++++++++++++++++++++++++++++++++++++++++++++--
 src/gui/chronojump.cs  |   18 +++++++++--
 src/gui/encoder.cs     |    8 -----
 src/gui/session.cs     |   28 +++++++++++++----
 src/sqlite/main.cs     |   24 +++++++++++++-
 src/sqlite/session.cs  |   10 ++++--
 6 files changed, 140 insertions(+), 26 deletions(-)
---
diff --git a/glade/chronojump.glade b/glade/chronojump.glade
index df06b60..737c385 100644
--- a/glade/chronojump.glade
+++ b/glade/chronojump.glade
@@ -17963,6 +17963,9 @@ Concentric</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
@@ -22778,6 +22781,9 @@ by you</property>
                         <child>
                           <placeholder/>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                     </child>
                   </widget>
@@ -24074,6 +24080,9 @@ by you</property>
                         <child>
                           <placeholder/>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                     </child>
                   </widget>
@@ -25862,6 +25871,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>
@@ -26707,6 +26719,9 @@ by you</property>
             <child>
               <placeholder/>
             </child>
+            <child>
+              <placeholder/>
+            </child>
           </widget>
           <packing>
             <property name="expand">True</property>
@@ -40011,6 +40026,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>
@@ -43158,6 +43191,18 @@ To differentiate between male and female, use the values 1/0, or m/f, or M/F on
                     <child>
                       <placeholder/>
                     </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
                   </widget>
                 </child>
               </widget>
@@ -44287,9 +44332,6 @@ To differentiate between male and female, use the values 1/0, or m/f, or M/F on
                                       <placeholder/>
                                     </child>
                                     <child>
-                                      <placeholder/>
-                                    </child>
-                                    <child>
                                       <widget class="GtkLabel" id="label218">
                                         <property name="visible">True</property>
                                         <property name="can_focus">False</property>
@@ -45585,6 +45627,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>
@@ -50464,6 +50509,9 @@ Other</property>
                         <child>
                           <placeholder/>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                       <packing>
                         <property name="left_attach">2</property>
@@ -51424,6 +51472,9 @@ Other</property>
                     <child>
                       <placeholder/>
                     </child>
+                    <child>
+                      <placeholder/>
+                    </child>
                   </widget>
                 </child>
               </widget>
@@ -52399,6 +52450,9 @@ Other</property>
                     <child>
                       <placeholder/>
                     </child>
+                    <child>
+                      <placeholder/>
+                    </child>
                   </widget>
                 </child>
               </widget>
@@ -58751,6 +58805,24 @@ suitable for agility tests and RSA)</property>
             <property name="position">2</property>
           </packing>
         </child>
+        <child>
+          <widget class="GtkEntry" id="entry_path">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="invisible_char">●</property>
+            <property name="invisible_char_set">True</property>
+            <property name="primary_icon_activatable">False</property>
+            <property name="secondary_icon_activatable">False</property>
+            <property name="primary_icon_sensitive">True</property>
+            <property name="secondary_icon_sensitive">True</property>
+            <signal name="changed" handler="on_entry_path_changed" swapped="no"/>
+          </widget>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">3</property>
+          </packing>
+        </child>
       </widget>
     </child>
   </widget>
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index 96f70f5..fd8b211 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -2598,14 +2598,26 @@ public partial class ChronoJumpWindow
                        }
                }
        }
-       
+
+       private void on_button_encoder_import_chronojump_session(object o, EventArgs args)
+       {
+               sessionLoadWin = SessionLoadWindow.Show (app1, SessionLoadWindow.WindowType.IMPORT_SESSION);
+               sessionLoadWin.Button_accept.Clicked += new EventHandler(on_load_session_accepted_to_import);
+       }
+
+       //from import session
+       private void on_load_session_accepted_to_import(object o, EventArgs args)
+       {
+               // TODO
+       }
+
        private void on_open_activate (object o, EventArgs args) 
        {
                LogB.Information("open session");
-               sessionLoadWin = SessionLoadWindow.Show(app1);
+               sessionLoadWin = SessionLoadWindow.Show(app1, SessionLoadWindow.WindowType.LOAD_SESSION);
                sessionLoadWin.Button_accept.Clicked += new EventHandler(on_load_session_accepted_from_open);
        }
-       
+
        //from open session
        private void on_load_session_accepted_from_open (object o, EventArgs args) 
        {
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index f2b38ea..0c8b041 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -1413,14 +1413,6 @@ public partial class ChronoJumpWindow
                checkFile(Constants.EncoderCheckFileOp.CAPTURE_EXPORT_ALL);
        }
 
-       void on_button_encoder_import_chronojump_session(object o, EventArgs args)
-       {
-               // TODO: show dialog Load Session
-               // TODO: and the user will select a database (needs a button + FileDialog to select the 
database)
-               // TODO: the sessions of the database will be displayed
-               // TODO: and one of them will be imported
-       }
-
        /*
         * encoder session overview
         */
diff --git a/src/gui/session.cs b/src/gui/session.cs
index c586484..88305b5 100644
--- a/src/gui/session.cs
+++ b/src/gui/session.cs
@@ -646,7 +646,12 @@ public class SessionAddEditWindow {
 
 
 public class SessionLoadWindow {
-       
+
+       public enum WindowType
+       {
+               LOAD_SESSION,
+               IMPORT_SESSION
+       };
        [Widget] Gtk.Window session_load;
        
        private TreeStore store;
@@ -656,20 +661,24 @@ public class SessionLoadWindow {
        [Widget] Gtk.Entry entry_search_filter;
        [Widget] Gtk.CheckButton checkbutton_show_data_jump_run;
        [Widget] Gtk.CheckButton checkbutton_show_data_encoder;
+       [Widget] Gtk.Entry entry_path;
 
        static SessionLoadWindow SessionLoadWindowBox;
        Gtk.Window parent;
        
        private Session currentSession;
        private SqliteSessionSwitcher sqliteSession;
+       private WindowType type;
 
-       SessionLoadWindow (Gtk.Window parent, SqliteSessionSwitcher sqliteSession) {
-               this.sqliteSession = sqliteSession;
+       SessionLoadWindow (Gtk.Window parent, WindowType type) {
+               this.type = type;
                Glade.XML gladeXML;
                gladeXML = Glade.XML.FromAssembly (Util.GetGladePath() + "chronojump.glade", "session_load", 
null);
                gladeXML.Autoconnect(this);
                this.parent = parent;
-               
+
+               entry_path.Visible = (type == WindowType.IMPORT_SESSION);
+
                //put an icon to window
                UtilGtk.IconWindow(session_load);
                
@@ -721,10 +730,10 @@ public class SessionLoadWindow {
        }
 
        
-       static public SessionLoadWindow Show (Gtk.Window parent)
+       static public SessionLoadWindow Show (Gtk.Window parent, WindowType type)
        {
                if (SessionLoadWindowBox == null) {
-                       SessionLoadWindowBox = new SessionLoadWindow (parent, new SqliteSessionSwitcher(""));
+                       SessionLoadWindowBox = new SessionLoadWindow (parent, type);
                }
                SessionLoadWindowBox.session_load.Show ();
                
@@ -766,6 +775,9 @@ public class SessionLoadWindow {
        protected void on_entry_search_filter_changed (object o, EventArgs args) {
                recreateTreeView("changed search filter");
        }
+       protected void on_entry_path_changed(object o, EventArgs args) {
+               recreateTreeView ("entry path changed");
+       }
        void on_checkbutton_show_data_jump_run_toggled (object o, EventArgs args) {
                recreateTreeView("jump run " + checkbutton_show_data_jump_run.Active.ToString());
        }
@@ -798,8 +810,10 @@ public class SessionLoadWindow {
                string filterName = "";
                if(entry_search_filter.Text.ToString().Length > 0) 
                        filterName = entry_search_filter.Text.ToString();
+
+               SqliteSessionSwitcher sessionSwitcher = new SqliteSessionSwitcher (entry_path.Text.ToString 
());
                
-               string [] mySessions = SqliteSession.SelectAllSessions(filterName); //returns a string of 
values separated by ':'
+               string [] mySessions = sessionSwitcher.SelectAllSessions(filterName); //returns a string of 
values separated by ':'
                foreach (string session in mySessions) {
                        string [] myStringFull = session.Split(new char[] {':'});
                
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index 8e54170..b4e8442 100644
--- a/src/sqlite/main.cs
+++ b/src/sqlite/main.cs
@@ -30,12 +30,32 @@ using Mono.Unix;
 class SqliteGeneral
 {
        private SqliteConnection dbcon;
-
+       private bool isOpened;
        public SqliteGeneral(string databasePath)
        {
+               isOpened = false;
+
+               if (!File.Exists (databasePath)) {
+                       return;
+               }
                dbcon = new SqliteConnection ();
                string connectionString = "version = 3; Data source = " + databasePath;
-               dbcon.Open();
+               dbcon.ConnectionString = connectionString;
+               try {
+                       dbcon.Open();
+                       isOpened = true;
+               }
+               catch {
+
+               }
+       }
+
+       public bool IsOpened
+       {
+               get
+               {
+                       return isOpened;
+               }
        }
 
        public SqliteCommand command()
diff --git a/src/sqlite/session.cs b/src/sqlite/session.cs
index 2ea866c..7bcb5e7 100644
--- a/src/sqlite/session.cs
+++ b/src/sqlite/session.cs
@@ -43,9 +43,13 @@ public class SqliteSessionSwitcher
                else
                {
                        SqliteGeneral sqliteGeneral = new SqliteGeneral(databasePath);
+                       if (!sqliteGeneral.IsOpened) {
+                               List<string> emptyResult = new List<string> ();
+                               return emptyResult.ToArray ();
+                       }
                        SqliteCommand dbcommand = sqliteGeneral.command();
 
-                       dbcommand.CommandText = "SELECT uniqueID, name, place, data, comment FROM Sessions";
+                       dbcommand.CommandText = "SELECT uniqueID, name, place, date, comments FROM Session";
 
                        SqliteDataReader reader = dbcommand.ExecuteReader ();
 
@@ -55,7 +59,7 @@ public class SqliteSessionSwitcher
                        // 1:SIMULATED::11/09/2016:--Undefined::Undefined:Use this session to simulate 
tests.:0:0:0:0:0:0:0:0:0 ; 0:0 ; 0
                        while (reader.Read())
                        {
-                               string row = string.Format 
("{0}:{1}::{2}--Undefined::Undefined:{3}:0:0:0:0:0:0:0:0:0 ; 0:0 ; 0", reader ["uniqueID"], reader ["name"], 
reader ["data"], reader ["comment"]);
+                               string row = string.Format 
("{0}:{1}::{2}--Undefined::Undefined:{3}:0:0:0:0:0:0:0:0:0 ; 0:0 ; 0", reader ["uniqueID"], reader ["name"], 
reader ["date"], reader ["comments"]);
                                result.Add(row);
                        }
                        return result.ToArray();
@@ -73,7 +77,7 @@ public class SqliteSessionSwitcher
                        SqliteGeneral sqliteGeneral = new SqliteGeneral(databasePath);
                        SqliteCommand dbcommand = sqliteGeneral.command();
 
-                       dbcommand.CommandText = "SELECT * FROM Sessions WHERE uniqueID == @myUniqueID";
+                       dbcommand.CommandText = "SELECT * FROM Session WHERE uniqueID == @myUniqueID";
                        dbcommand.Parameters.Add (new SqliteParameter ("@myUniqueID", myUniqueID));
 
                        SqliteDataReader reader = dbcommand.ExecuteReader ();


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