]> Creatis software - creaImageIO.git/commitdiff
Added Settings dialog, customize configuration options and the listener on an externa...
authorcaballero <caballero>
Tue, 19 May 2009 12:52:26 +0000 (12:52 +0000)
committercaballero <caballero>
Tue, 19 May 2009 12:52:26 +0000 (12:52 +0000)
25 files changed:
src2/CMakeLists.txt
src2/creaImageIOGimmick.cpp
src2/creaImageIOGimmick.h
src2/creaImageIOGimmickView.h
src2/creaImageIOListener.cpp [new file with mode: 0644]
src2/creaImageIOListener.h [new file with mode: 0644]
src2/creaImageIOSQLiteTreeHandler.cpp
src2/creaImageIOSQLiteTreeHandler.h
src2/creaImageIOSettings.cpp
src2/creaImageIOSettings.h
src2/creaImageIOSynchron.cpp
src2/creaImageIOSynchron.h
src2/creaImageIOTimestampDatabaseHandler.cpp
src2/creaImageIOTimestampDatabaseHandler.h
src2/creaImageIOTreeHandler.h
src2/creaImageIOTreeHandlerImageAdder.cpp
src2/creaImageIOTreeHandlerImageAdder.h
src2/creaImageIOWxCustomizeConfigPanel.cpp [new file with mode: 0644]
src2/creaImageIOWxCustomizeConfigPanel.h [new file with mode: 0644]
src2/creaImageIOWxGimmickView.cpp
src2/creaImageIOWxGimmickView.h
src2/creaImageIOWxListenerPanel.cpp [new file with mode: 0644]
src2/creaImageIOWxListenerPanel.h [new file with mode: 0644]
src2/creaImageIOWxTreeView.cpp
src2/creaImageIOWxTreeView.h

index 709965a91c13e77fb5df5c38cb635cc1927fdaae..e5b263ee355c69e2771ab4851b9783ed7e1d2179 100644 (file)
@@ -35,6 +35,7 @@ SET( SRCS
   creaImageIOGimmick
   creaImageIOSynchron
   creaImageIOTimestampDatabaseHandler
+  creaImageIOListener
 
   # Abstract views
   creaImageIOGimmickView
@@ -47,6 +48,8 @@ SET( SRCS
   creaImageIOWxGimmickFrame
   creaImageIOWxGimmickPanel
   creaImageIOWxGimmickTools
+  creaImageIOWxCustomizeConfigPanel
+  creaImageIOWxListenerPanel
 
   # 
   BlockScopeWxApp
index 2ed5b0c72f115c9e4bbdb593b93e67cf57220c58..3aae8a855e242c7fbc8a7f4b04bdc5531bc9df58 100644 (file)
@@ -362,6 +362,35 @@ namespace creaImageIO
     GetTreeHandler(d)->GetTree().Print();
   }
   //========================================================================
+
+  void Gimmick::GetSetting(const std::string& name, std::string& value)
+  {
+         value = mSettings->getValue(name);
+  }
+  //========================================================================
+
+  //========================================================================
+
+  void Gimmick::UpdateSetting(const std::string& name, const std::string& value)
+  {
+         mSettings->updateSetting(name,value);
+         mSettings->writeSettingsFile();
+  }
+  //========================================================================
+
+  void Gimmick::DeleteDrive(const std::string& drive)
+  {
+         for( TreeHandlerMapType::const_iterator it = mTreeHandlerMap.begin();
+           it!= mTreeHandlerMap.end(); ++it)
+          {
+                  mImageAdder.SetTreeHandler(it->second);
+                  mImageAdder.DeleteDriveFromMainDB(drive);
+          }
+         mImageAdder.SetTimestampHandler(mTimestampDatabase);
+         mImageAdder.SetSynchronizer(mSynchronizer);
+         mImageAdder.DeleteDriveFromOtherDB(drive);
+  }
+
   /////////////////////////////////////////////////////////////////////////
   // add DB from Settings file                                                                              //
   // @param : -                                                                                                                         //
index 6c3b1cc6e231754cced691044bd385d7009da19a..09423fe0c00a7e8a057170e635b2358749f5cae1 100644 (file)
@@ -96,6 +96,10 @@ namespace creaImageIO
        void RemoveFile(const std::string& d, 
                        tree::Node* filename);
 
+       ///Deletes the given drive name from the databases
+       void DeleteDrive(const std::string& drive);
+  
+
        /// Copies the files into the local directory
        void CopyFiles(const std::vector<std::string>& filenames, const std::string& d );
   
@@ -126,6 +130,12 @@ namespace creaImageIO
     const SQLiteTreeHandler* GetLocalDatabase() const 
     { return mLocalDatabase; }
 
+       ///Returns the given setting value for the given setting parameter
+       void GetSetting(const std::string& name, std::string& value);
+
+       ///Updates the settings file
+       void UpdateSetting(const std::string& name, const std::string& value);
+
        // add DB from Settings file
     void addDBSettings();
 
index c0e31d39e0d6c4f91f81906f175c7f7e79135ea8..4621dbd6a3b727b2c53b08dc1cd78115ae521d5c 100644 (file)
@@ -141,6 +141,8 @@ namespace creaImageIO
       void ConnectValidationObserver(ValidationCallbackType callback);
      //==================================================================
 
+         
+
        void modifyValidationSignal(bool ivalid);
 
     private:
diff --git a/src2/creaImageIOListener.cpp b/src2/creaImageIOListener.cpp
new file mode 100644 (file)
index 0000000..d515b31
--- /dev/null
@@ -0,0 +1,104 @@
+#include <creaImageIOListener.h>
+#include <creaImageIOSystem.h>
+#include "boost/filesystem.hpp"
+#include <boost/filesystem/operations.hpp>
+#include <boost/utility.hpp>
+
+
+namespace fs = boost::filesystem;
+using boost::filesystem::path;
+
+using namespace crea;
+
+namespace creaImageIO
+{
+  //=====================================================================
+  // CTor
+  Listener::Listener()
+  {
+    wxMutexLocker lock(mMutex);
+    GimmickDebugMessage(6,"Listener::Listener"
+                       <<std::endl);
+       mDrive="E:";
+       mMounted=false;
+       mAddFiles=false;
+       mRemoveFiles=true;
+
+  }
+  //=====================================================================
+
+  //=====================================================================
+  /// Destructor
+  Listener::~Listener()
+  {
+    wxMutexLocker lock(mMutex);
+    GimmickDebugMessage(6,"Listener::~Listener"
+                       <<std::endl);
+  }
+  //=====================================================================
+
+  void*  Listener::Entry()
+  {      
+    GimmickDebugMessage(6,"Listener::Entry()"<<std::endl);
+       while(!TestDestroy())
+         { 
+               try  
+               {
+                       fs::exists( mDrive );
+                       if(!mMounted && mAddFiles)
+                       {
+                               mMounted=true;
+                               SendSignal(mMounted);           
+                       }
+                       else if(!mMounted)
+                       {
+                               mMounted=true;
+                       }
+                       
+               }
+               catch (...)
+               {
+                       if(mMounted && mRemoveFiles)
+                       {
+                         mMounted=false;
+                         SendSignal(mMounted);
+                       }
+                       else if(mMounted)
+                       {
+                               mMounted=false;
+                       }
+               }
+
+               clock_t endwait;
+               endwait = clock () + 0.00000001 * CLOCKS_PER_SEC ;
+               while (clock() < endwait ) {}
+                       
+      }
+    return 0;
+  }
+
+  //=====================================================================
+
+  //=====================================================================
+  void Listener::OnExit()
+  {
+    GimmickDebugMessage(6,"Listener::OnExit() "<<std::endl);
+  }
+
+   //====================================================================
+  void Listener::ConnectObserver(MountingCallbackType callback)
+  {
+    mMountingSignal.connect(callback);
+  }
+
+   //======================================================================
+  void Listener::SendSignal(bool mount)
+  {
+         mMountingSignal(mount);
+  }
+
+
+
+} // EO namespace creaImageIO
+
diff --git a/src2/creaImageIOListener.h b/src2/creaImageIOListener.h
new file mode 100644 (file)
index 0000000..32b4caa
--- /dev/null
@@ -0,0 +1,66 @@
+#ifndef __creaImageIOListener_h_INCLUDED__
+#define __creaImageIOListener_h_INCLUDED__
+
+#include <creaImageIOSystem.h>
+#include <stdio.h>
+#include <time.h>
+#include <wx/thread.h>
+// Signal/slot mechanism
+#include <boost/signal.hpp>
+#include <boost/bind.hpp>
+
+namespace creaImageIO
+{
+
+  class Listener : public wxThread
+  {
+  public:
+    /// Ctors 
+    Listener();
+    /// Dtor
+    virtual ~Listener();
+       ///Thread method that is executed once create is called
+       void* Entry();
+       ///Thread method called upon exiting
+    void  OnExit();
+       ///Sets the new state of adding files
+       void SetAddFilesState(bool addFiles){wxMutexLocker lock(mMutex);mAddFiles=addFiles;}
+       ///Sets the new state of removing files
+       void SetRemoveFilesState(bool removeFiles){wxMutexLocker lock(mMutex);mRemoveFiles=removeFiles;}
+       ///Sets the new monitored drive
+       void SetMonitoredDrive(const std::string& dr){wxMutexLocker lock(mMutex);mDrive=dr;}
+       ///Puts the name of the monitored drive in the given string
+       void GetMonitoredDrive(std::string& drive){drive=mDrive;}
+
+       ///Related with signals
+       //=============================================
+    typedef boost::signal<void (bool)>  MountingSignalType;
+    typedef MountingSignalType::slot_function_type MountingCallbackType;
+    //=============================================
+
+    //==================================================================
+    void ConnectObserver(MountingCallbackType callback);
+    //==================================================================
+
+       ///Sends a boost::signal to alert that the drive has changed its state (mounted/unmounted)
+       void SendSignal(bool ivalid);
+  
+
+  private:
+    /// The mutex
+    wxMutex mMutex;
+    /// Boolean that declares if the files that are read on CD mount should be added
+    bool mAddFiles;
+       /// Boolean that declares if, on CD unmount, the files that were in the drive should be removed
+    bool mRemoveFiles;
+       ///Boolean that declares if a unit has been mounted
+       bool mMounted;
+       ///The monitored drive
+       std::string mDrive;
+       ///The validation signal
+       MountingSignalType mMountingSignal;
+  };
+
+}
+
+#endif  
index 14bb3db2476d9f31ce80372afbe1993b2b21eb3d..6d4d25b9ce249d2ce1023d33d72cba8b75feeb04 100644 (file)
@@ -149,7 +149,7 @@ namespace creaImageIO
     if (parent)
       {
        int nC = parent->RemoveChildrenFromList(node);
-       if(nC>0)
+       if(nC>0 && parent->GetLevel()>0)
        {       
                std::stringstream out;
                out <<nC;
@@ -892,6 +892,7 @@ namespace creaImageIO
        sql += " = '";
     sql += searchVal;
        sql += "'";
+       std::cout<<sql<<std::endl;
     UPDATEDB(sql);
   }
    //=====================================================================
@@ -1080,6 +1081,17 @@ namespace creaImageIO
 
   }
 
+  //=====================================================================
+  void SQLiteTreeHandler::RemoveEntries(const std::string i_table, 
+               const std::string i_attribute, 
+               const std::string i_operand, 
+               const std::string i_val)
+    {
+        std::stringstream query;
+               query<<"DELETE  FROM "<<i_table<<" WHERE "<<i_attribute<<" "<<i_operand<<" '"<<i_val<<"'";
+        UPDATEDB(query.str());
+       }
+
   /*
   //=====================================================================
   bool SQLiteTreeHandler::DBInsert(Node* alien_node,
index 1284e169edd14fc17e138f64c74b973107533ef3..d3a055e55eca70ff2d2e337f864c60b6c51dd184 100644 (file)
@@ -124,6 +124,11 @@ namespace creaImageIO
                                  const std::string& searchVal);
        //Deletes the tuple that matches the parameters given
        virtual void DeleteTuple(std::string levelDescriptor, std::string key, std::string value);
+       //Deletes the entries that match the parameters given
+       virtual void RemoveEntries(const std::string i_table, 
+               const std::string i_attribute, 
+               const std::string i_operand, 
+               const std::string i_val);
  
     //====================================================================
     
index 99cc4c526fb8ab4df14bdd3c77ad01a380bdda5e..03b4317747c56e2d16e3eeb7c254c6f6690f8cc5 100644 (file)
@@ -79,6 +79,18 @@ namespace creaImageIO
                        }
                }
        }
+
+       ////////////////////////////////////////////////////////////////////////////////////////////////
+    // Update settings in config file                                                             //
+    // @param key : Key to update                                                                 //
+    // @param value: New value to set                                                             //
+       // return : -
+    ///////////////////////////////////////////////////////////////////////////////////////////////
+       void Settings::updateSetting(const std::string& key, const std::string &val)
+       {
+               m_SettingsMap[key.c_str()] = val;
+       }
+
        ////////////////////////////////////////////////////////////////////////////////////////////////
     // add a path to a DB                                                                                    //
     // @param i_path : DB path to add                                                             //
index 44c6e8c79561385bd59552be3e98e18324205c2e..2e4eeb6aeda1a17d722de94cedf28dfa0a7bab7e 100644 (file)
@@ -21,6 +21,9 @@ namespace creaImageIO
                void addDB(const std::string &i_path);
 
                void removeDB(const std::string &i_path);
+
+               void updateSetting(const std::string& key, const std::string &val);
+       
                //write configuration file
                void writeSettingsFile();
                
index 3bd73e433107d16cfbcf2fb4be9d0375e25ab60f..74e9e98ced8fc532e9c0843a593098db249dce02 100644 (file)
@@ -146,7 +146,7 @@ namespace creaImageIO
 
     /////////////////////////////////////////////////////////////////////////////////////////////////
     // remove an entry of the DB
-    //@param i_table : table where do the remove
+    //@param i_table : table where to do the remove
     // @param i_key : the add_key reference (one entry to remove for ADD_OP table, many for IGNORED_FILES table
     //@result : -
     /////////////////////////////////////////////////////////////////////////////////////////////////
@@ -156,6 +156,24 @@ namespace creaImageIO
         UPDATESYNCDB(query);
        }
 
+       /////////////////////////////////////////////////////////////////////////////////////////////////
+    // remove several entries of the DB
+    // @param i_table : table where to do the remove
+       // @param i_attribute: attribute to match
+       // @param i_operand : operand to use
+    // @param i_val : the reference
+    //@result : -
+    /////////////////////////////////////////////////////////////////////////////////////////////////
+    void Synchronizer::RemoveEntries(const std::string i_table, 
+               const std::string i_attribute, 
+               const std::string i_operand, 
+               const std::string i_val)
+    {
+        std::stringstream query;
+               query<<"DELETE  FROM "<<i_table<<" WHERE "<<i_attribute<<" "<<i_operand<<" '"<<i_val<<"'";
+        UPDATESYNCDB(query.str());
+       }
+
     /////////////////////////////////////////////////////////////////////////////////////////////////
     // clean DataBase if an operation has no child anymore
        // @param refdb: the database segement to clean
index 7e4bc3693ccb58f150d9a44f078941fd46745ffc..11ecd1bbf15ec9dd2b3edeba2c79f8437c945bc3 100644 (file)
@@ -62,6 +62,10 @@ namespace creaImageIO
                                                        const std::string& time,
                                                        const std::string& refdb);
                          void RemoveEntry(const std::string i_table, const std::string i_key);
+                         void RemoveEntries(const std::string i_table, 
+                                                                                       const std::string i_attribute, 
+                                                                                       const std::string i_operand, 
+                                                                                       const std::string i_key);
                          void GetFileList(std::vector<AddList>& files , const std::string& refdb);
                          void GetIgnoredFiles(const std::string& key, std::vector<std::string> &ignoreList);
                          std::string GetAttribute(const std::string& attribute, 
index 35a81534baafeb0815a8ad3b10f2f28b00d30fa1..f1561110b38acab9f7606338d6bca2e78dd16fe6 100644 (file)
@@ -427,5 +427,16 @@ namespace creaImageIO
          return false;  
   }
 
+  //=====================================================================
+  void TimestampDatabaseHandler::RemoveEntries(const std::string i_table, 
+               const std::string i_attribute, 
+               const std::string i_operand, 
+               const std::string i_val)
+    {
+        std::stringstream query;
+               query<<"DELETE  FROM "<<i_table<<" WHERE "<<i_attribute<<" "<<i_operand<<" '"<<i_val<<"'";
+        UPDATETIMESTAMPDB(query.str());
+       }
+
 }// namespace creaImageIO
 
index 4727fe3fde9bc0a080428b0e665825b184d835f0..056614116d77f895ef1e95ac06bd1459193e1e3d 100644 (file)
@@ -70,6 +70,11 @@ namespace creaImageIO
        ///Checks the timestamp in the database and compares it with the given one. 
        //If there is a difference, it will return false, otherwise it will return true.
        bool CheckTimestamp(const std::string pathId, const time_t lastModif, const std::string& refdb);
+       ///Removes the entries that match the given parameters
+       void RemoveEntries(const std::string i_table, 
+               const std::string i_attribute, 
+               const std::string i_operand, 
+               const std::string i_val);
 
        //====================================================================
 
index 9b7c4db9eb8ba36b297e81e287f9e60909e2b77a..a0d3f45f7afa6cf31d1608c04a2b316282e03792 100644 (file)
@@ -136,6 +136,11 @@ namespace creaImageIO
                                  const std::string& searchVal){}
        //Deletes the tuple that matches the parameters given
        virtual void DeleteTuple(std::string levelDescriptor, std::string key, std::string value){}
+       //Deletes the entries that match the parameters given
+       virtual void RemoveEntries(const std::string i_table, 
+               const std::string i_attribute, 
+               const std::string i_operand, 
+               const std::string i_val){}
  
     //====================================================================
 
index 6fb907a2490ee2162e8b8962b5b3daaa076b1965..471c785317df2e0e0c4289d6dcdcedff6b50a5dd 100644 (file)
@@ -200,12 +200,14 @@ namespace creaImageIO
                        removedOn<<time(0);
                        mSynchronizer->InsertIgnoreFile(addKey, itr->string(),"0",removedOn.str(),mCurrentDB);
                        }
+                       
                        mProgressSignal(mProgress);
                        if (mProgress.GetStop()) 
                        {
                        //itr = end_itr;
                        break;
                        }
+                       
                }
                mTimestampHandler->SetAttribute("TopLevelNodeId",parent_id,"PATH",dirpath);
          }
@@ -444,6 +446,28 @@ namespace creaImageIO
          }
   }
   
+  //=======================================================================
+  void TreeHandlerImageAdder::FindNodePartial(tree::Node* parent, int level, const std::string& searchParam, const std::string& searchVal, tree::Node*& node)
+  {
+         if(level>1)
+         {
+                 std::vector<tree::Node*>::iterator iter;
+                 for(iter=parent->GetChildrenList().begin();iter!=parent->GetChildrenList().end() && node==0 ;++iter)
+                 {
+                         FindNodePartial(*iter,level-1,searchParam,searchVal,node);
+                 }
+         }
+         else
+         {
+                 if(parent->GetAttribute(searchParam).find(searchVal)<9000)
+                 {
+                         node=parent;
+                         return;
+                 }
+
+         }
+  }
+  
   //=======================================================================
 
   void TreeHandlerImageAdder::CopyFiles(const std::vector<std::string>& filenames, const std::string directory  )
@@ -526,5 +550,32 @@ namespace creaImageIO
 
   //=======================================================================
 
+  void TreeHandlerImageAdder::DeleteDriveFromMainDB(const std::string& drive)
+  {
+         //Delete from local database and others
+         tree::Node* node=0;
+         mTreeHandler->LoadChildren(NULL,4);
+         FindNodePartial(mTreeHandler->GetTree().GetChildrenList()[0],3,"FullFileName",drive,node);
+         while(node!=0)
+         {
+         mTreeHandler->Remove(node);
+         node=0;
+         mTreeHandler->LoadChildren(NULL,4);
+         FindNodePartial(mTreeHandler->GetTree().GetChildrenList()[0],3,"FullFileName",drive,node); 
+         }
+  }
+
+   //=======================================================================
+
+  void TreeHandlerImageAdder::DeleteDriveFromOtherDB(const std::string& drive)
+  {
+         //Delete from timestamp
+         mTimestampHandler->RemoveEntries("FILES", "PATH", "LIKE", drive+"%");
+
+         //Delete from maintenance
+         mSynchronizer->RemoveEntries("ADD_OPS", "PATH", "LIKE", drive+"%");
+         mSynchronizer->RemoveEntries("IGNORED_FILES", "PATH", "LIKE", drive+"%");
+  }
+
  
 }
index fe3c31da644ebe6f28219e1810e23df13c376915..53cff0b7b325d8ec8ac4fe1dc688014e7b4bc651 100644 (file)
@@ -130,8 +130,17 @@ namespace creaImageIO
                const std::string& searchParam, 
                const std::string& searchVal, 
                tree::Node*& node);
+
+       ///Finds the nodes that partially match the searchVal
+       void FindNodePartial(tree::Node* parent, int level, const std::string& searchParam, const std::string& searchVal, tree::Node*& node);
        ///Checks the attributes of the database against the ones in disk
        void CheckAttributes(bool repair, std::string& file, std::vector<std::string>& attsModified);
+       ///Deletes the drive with the given name (use for all databases except maintenance and timestamp)
+       void DeleteDriveFromMainDB(const std::string& drive);
+       ///Deletes the drive with the given name (use for maintenance and timestamp databases)
+       void DeleteDriveFromOtherDB(const std::string& drive);
+  
  
     //====================================================================
 
diff --git a/src2/creaImageIOWxCustomizeConfigPanel.cpp b/src2/creaImageIOWxCustomizeConfigPanel.cpp
new file mode 100644 (file)
index 0000000..8fd0e78
--- /dev/null
@@ -0,0 +1,74 @@
+#include <creaImageIOWxCustomizeConfigPanel.h>
+#include <creaImageIOSystem.h>
+
+namespace creaImageIO
+{
+  // CTor
+  WxCustomizeConfigPanel::WxCustomizeConfigPanel(wxWindow *parent, wxDialog* dial, WxGimmickView* view, const std::string& cPath, 
+               const std::string& dPath,
+               const std::string& sEvent,
+               const std::string& sFreq)
+ :   wxPanel( parent, 
+                 -1, wxDefaultPosition, 
+                 wxDefaultSize,
+                 wxRESIZE_BORDER | 
+             wxSYSTEM_MENU  |
+                 wxCLOSE_BOX |
+                 wxMAXIMIZE_BOX | 
+                 wxMINIMIZE_BOX | 
+                 wxCAPTION  
+              ),       
+                  dialog(dial),
+                  copyP (cPath), 
+                  databaseP(dPath), 
+                  syncEv(sEvent), 
+                  syncFr(sFreq),
+                  mView(view)
+  {
+    GimmickDebugMessage(1,"WxCustomizeConfigPanel::WxCustomizeConfigPanel"
+                       <<std::endl);
+       wxStaticText * cp=new wxStaticText(this,-1,_T(" Copy Path: "), wxPoint(5,10));
+    copyPath=new wxTextCtrl(this, wxID_ANY, _T(copyP), wxPoint(150,10), wxSize(250,20));
+
+       wxStaticText * dp=new wxStaticText(this,-1,_T(" Database Path: "), wxPoint(5,40));
+       dbPath=new wxTextCtrl(this, wxID_ANY, _T(databaseP), wxPoint(150,40), wxSize(250,20));
+
+       wxStaticText * se=new wxStaticText(this,-1,_T(" Synchronization Event: "), wxPoint(5,70));
+       syncEvent=new wxTextCtrl(this, wxID_ANY, _T(syncEv), wxPoint(150,70), wxSize(250,20));
+
+       wxStaticText * sf=new wxStaticText(this,-1,_T(" Synchronization Frequency: "), wxPoint(5,100));
+       syncFrequency=new wxTextCtrl(this, wxID_ANY, _T(syncFr), wxPoint(150,100), wxSize(250,20));
+
+       wxButton *save = new wxButton(this,wxID_ANY,_T("Save Changes"), wxPoint(5,130) );
+       Connect( save->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxCustomizeConfigPanel::OnSaveConfig ); 
+  
+
+    //topsizer->Add( mView,1,wxGROW,0);
+
+//    SetSizer( topsizer );     
+    Layout(); 
+  }
+
+  /// Destructor
+  WxCustomizeConfigPanel::~WxCustomizeConfigPanel()
+  {
+    GimmickDebugMessage(1,"WxCustomizeConfigPanel::~WxCustomizeConfigPanel"
+                       <<std::endl);
+  }
+
+  void WxCustomizeConfigPanel::OnSaveConfig(wxCommandEvent& event)
+  {
+         mView->OnSaveSettingsCallback(crea::wx2std(copyPath->GetValue()),
+                 crea::wx2std(dbPath->GetValue()),
+                 crea::wx2std(syncEvent->GetValue()),
+                 crea::wx2std(syncFrequency->GetValue()));
+         dialog->Destroy();
+  }
+  
+//======================================================================
+  
+//====================================================================== 
+
+} // EO namespace creaImageIO
+
+
diff --git a/src2/creaImageIOWxCustomizeConfigPanel.h b/src2/creaImageIOWxCustomizeConfigPanel.h
new file mode 100644 (file)
index 0000000..0de052a
--- /dev/null
@@ -0,0 +1,54 @@
+#ifndef __creaImageIOWxCustomizeConfigPanel_h_INCLUDED__
+#define __creaImageIOWxCustomizeConfigPanel_h_INCLUDED__
+
+#ifdef USE_WXWIDGETS
+#include <creaWx.h>
+#include <creaImageIOWxGimmickView.h>
+
+
+namespace creaImageIO
+{
+  /**
+   * \ingroup GUI
+   */
+  //=====================================================================
+ //=====================================================================
+  class WxCustomizeConfigPanel : public wxPanel
+  {
+  public:
+    WxCustomizeConfigPanel();    
+       WxCustomizeConfigPanel(wxWindow *parent, 
+               wxDialog* dial,
+               WxGimmickView* view,
+               const std::string& cPath, 
+               const std::string& dPath,
+               const std::string& sEvent,
+               const std::string& sFreq);
+    
+    ~WxCustomizeConfigPanel();
+       ///Saves the configuration
+        void OnSaveConfig(wxCommandEvent& event);
+
+  private :
+       std::string copyP;
+       std::string databaseP;
+       std::string syncEv;
+       std::string syncFr;
+    wxTextCtrl* copyPath;
+       wxTextCtrl* dbPath;
+       wxTextCtrl* syncEvent;
+       wxTextCtrl* syncFrequency;
+       wxDialog* dialog;
+       WxGimmickView* mView;
+
+
+  }; // class WxCustomizeConfigPanel
+  //=====================================================================
+
+  
+} // EO namespace creaImageIO
+
+
+#endif // USE_WIDGETS
+// EOF
+#endif  
\ No newline at end of file
index 6c84edb0baacf5343a997b9426f08dd00d20d406..fb46be65b1bfefc812697d47c05401272635b375 100644 (file)
@@ -1,6 +1,9 @@
 #include <creaImageIOWxGimmickView.h>
 #include <creaImageIOWxTreeView.h>
 #include <creaImageIOSystem.h>
+#include <creaImageIOWxCustomizeConfigPanel.h>
+#include <creaImageIOWxListenerPanel.h>
+
 using namespace crea;
 // Icons
 #include "icons/accept.xpm"
@@ -157,10 +160,14 @@ namespace creaImageIO
 
     sizer->Add( mSplitter,1,wxGROW  ,0);
 
-
+       mProgressDialog=0;
     SetSizer( sizer );     
     SetAutoLayout(true);
     Layout();
+       mListener=new Listener();
+       mListener->ConnectObserver(boost::bind( &WxGimmickView::OnDriveMount , this, _1 ) );
+       mListener->Create();
+       mListener->Run();
     
     mConstructed = true;
   }
@@ -174,6 +181,10 @@ namespace creaImageIO
        mViewer->StopPlayer();
     GimmickDebugMessage(1,"WxGimmickView::~WxGimmickView"
                        <<std::endl);
+       if(mListener->IsAlive())
+       {
+        mListener->Delete();
+       }
   }
   //======================================================================
   
@@ -673,13 +684,13 @@ namespace creaImageIO
   //=================================================
   void WxGimmickView::OnSettings(wxCommandEvent& event)
   {
-    wxDialog* dial= new wxDialog (this,-1,_T("System Settings"),wxDefaultPosition, wxSize(450,600));
+    wxDialog* dial= new wxDialog (this,-1,_T("System Settings"),wxDefaultPosition, wxSize(450,220));
     wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
     // Notebook
     wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
     
     siz->Add( nb,1,wxGROW  ,0);  
-    CreateSettingsDialog(nb);
+    CreateSettingsDialog(nb,dial);
     dial->SetSizer(siz);
     dial->ShowModal();
   }
@@ -750,22 +761,114 @@ namespace creaImageIO
   }
   //=================================================
 
-  void WxGimmickView::CreateSettingsDialog(wxNotebook* nb)
+  void WxGimmickView::CreateSettingsDialog(wxNotebook* nb, wxDialog* dial)
   {
          //First page: Customization of configurations
-         wxPanel* customConfig=new wxPanel(nb);
+         //Copy Path string
+         std::string cp;
+         mGimmick->GetSetting(SETTINGS_COPY_PATH,cp);
+         //Database Path String
+         std::string dp;
+         mGimmick->GetSetting(SETTINGS_DBPATH,dp);
+         //Syncronization Event String
+         std::string se;
+         mGimmick->GetSetting(SETTINGS_SYNC_EVENT,se);
+         //Syncronization Frequency String
+         std::string sf;
+         mGimmick->GetSetting(SETTINGS_SYNC_FREQ,sf);
+
+         WxCustomizeConfigPanel * customConfig=new WxCustomizeConfigPanel(nb,dial,this,cp,dp,se,sf);
+
          nb->AddPage( customConfig, crea::std2wx("Customize Configuration") );
+
          //Second page: Creation of Databases
          wxPanel* databaseCreation=new wxPanel(nb);
          nb->AddPage( databaseCreation, crea::std2wx("Create Database") );
+
          //Third page: CD/DVD Watch
-         wxPanel* cdWatch=new wxPanel(nb);
+         WxListenerPanel* cdWatch=new WxListenerPanel(nb,dial, this, mListener->IsPaused());
          nb->AddPage( cdWatch, crea::std2wx("CD/DVD") );
+
          //Fourth page: Selection of attributes to show (edit)
          wxPanel* attSelection=new wxPanel(nb);
          nb->AddPage( attSelection, crea::std2wx("Selection of Attributes") );
   }
 
+  //===================================================================
+  void WxGimmickView::OnSaveSettingsCallback(const std::string& copyPath,
+         const std::string& dbPath,
+         const std::string& syncEvent,
+         const std::string& syncFreq)
+  {
+         mGimmick->UpdateSetting(SETTINGS_COPY_PATH,copyPath);
+         mGimmick->UpdateSetting(SETTINGS_DBPATH,dbPath);
+         mGimmick->UpdateSetting(SETTINGS_SYNC_EVENT,syncEvent);
+         mGimmick->UpdateSetting(SETTINGS_SYNC_FREQ,syncFreq);
+  }
+
+  //===================================================================
+  void WxGimmickView::OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles)
+  {
+        mListener->SetMonitoredDrive(drive);
+        mListener->SetAddFilesState(addFiles);
+        mListener->SetRemoveFilesState(removeFiles);
+  }
+
+  //========================================================================
+
+  void WxGimmickView::OnDriveMount(bool mount)
+  {
+         GimmickMessage(1, "Gimmick::OnDriveMount"<<std::endl);
+         std::string drive;
+         mListener->GetMonitoredDrive(drive);
+         
+         if(mount)
+         {
+               mViewer->StopPlayer();
+               wxBusyCursor busy;
+               wxString title(_T("Adding drive"));
+               mProgressDialog = 
+               new wxProgressDialog(_T("Adding drive"),
+                                       _T(""),
+                                       1000,
+                                       this,
+                                       wxPD_ELAPSED_TIME |
+                                       //                             wxPD_ESTIMATED_TIME | 
+                                       //                             wxPD_REMAINING_TIME |
+                                       wxPD_CAN_ABORT );
+               mCurrentDirectory = crea::std2wx(drive);
+               mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),drive,true);
+               mProgressDialog->Pulse(_T("Updating view..."));
+               
+               UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
+               delete mProgressDialog;
+               DisplayAddSummary();
+               mViewer->StartPlayer();
+                 
+         }
+         else
+         {  
+                 mGimmick->DeleteDrive(drive);
+                 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
+         }
+        
+  }
+
+   //========================================================================
+
+  void WxGimmickView::StartListeningThread()
+  {
+         mListener->Resume();
+  }
+
+   //========================================================================
+
+  void WxGimmickView::StopListeningThread()
+  {
+         mListener->Pause();
+  }
+
+
   //=================================================
   /// AddProgress Gimmick callback
   void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
index 937442e51623d466ddd57ff521275a329441c070..cf3dd3f0a72ffb1091431a68e4fb9666c0873fcb 100644 (file)
@@ -6,6 +6,7 @@
 #include <creaImageIOGimmickView.h>
 #include <creaImageIOWxViewer.h>
 #include <creaImageIOWxGimmickTools.h>
+#include <creaImageIOListener.h>
 #include <creaWx.h>
 #include "wx/wx.h"
 //#include "bruker2dicom.h"
@@ -72,7 +73,25 @@ namespace creaImageIO
     
     ///Sends a request to read the currently selected node and the ones that surround it.
     void ReadImageThreaded(const std::vector<tree::Node*>& sel);
-    
+
+       ///Saves the settings to the file
+       void OnSaveSettingsCallback(const std::string& copyPath,
+         const std::string& dbPath,
+         const std::string& syncEvent,
+         const std::string& syncFreq);
+       
+       ///Changes listener state
+       void OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles);
+
+       ///Acts upon a drive mount
+       void OnDriveMount(bool mount);
+
+       ///Starts the listening thread on the CD/DVD drive
+       void StartListeningThread();
+
+       ///Stops the listening thread on the CD/DVD drive
+       void StopListeningThread();
+  
     
   protected:
     /// Creates the tool bar
@@ -109,6 +128,8 @@ namespace creaImageIO
     void CreateIconList();
     
     Gimmick * mGimmick;
+       
+       Listener* mListener;
     /// Callback for adding files
     void OnAddFiles(wxCommandEvent& event);
     /// Callback for adding dir
@@ -122,7 +143,8 @@ namespace creaImageIO
        /// Callback for settings edition
     void OnTools(wxCommandEvent& event);
        ///Creates the settings dialog (the pages inside and the information)
-       void CreateSettingsDialog(wxNotebook* nb);
+       void CreateSettingsDialog(wxNotebook* nb, wxDialog* dial);
+    
     /// Display a message box with the last addition statistics
     void DisplayAddSummary();
 
diff --git a/src2/creaImageIOWxListenerPanel.cpp b/src2/creaImageIOWxListenerPanel.cpp
new file mode 100644 (file)
index 0000000..f259388
--- /dev/null
@@ -0,0 +1,95 @@
+#include <creaImageIOWxListenerPanel.h>
+#include <creaImageIOSystem.h>
+
+namespace creaImageIO
+{
+  // CTor
+  WxListenerPanel::WxListenerPanel(wxWindow *parent, wxDialog* dial, WxGimmickView* view, bool stat)
+ :   wxPanel( parent, 
+                 -1, wxDefaultPosition, 
+                 wxDefaultSize,
+                 wxRESIZE_BORDER | 
+             wxSYSTEM_MENU  |
+                 wxCLOSE_BOX |
+                 wxMAXIMIZE_BOX | 
+                 wxMINIMIZE_BOX | 
+                 wxCAPTION  
+              ),       
+                  dialog(dial),
+                  mView(view)
+  {
+    GimmickDebugMessage(1,"WxListener::WxListener"
+                       <<std::endl);
+       state=stat;
+       wxStaticText * cp=new wxStaticText(this,-1,_T(" Drive to monitor: "), wxPoint(5,15));
+       const wxString choices[] = { _T("D:"), 
+               _T("E:"), 
+               _T("F:"), 
+               _T("G:") };
+       drives=new wxComboBox(this, -1,"E:",wxPoint(100, 10),wxDefaultSize,4,choices);
+
+       addCheckBox = new wxCheckBox(this, -1, _T("Automatically add images to the database when CD/DVD is mounted?"), wxPoint(5,45) );
+       addCheckBox->SetValue(true);
+       removeCheckBox = new wxCheckBox(this, -1, _T("Automatically remove images from the database when CD/DVD is unmounted?"), wxPoint(5,75) );
+       removeCheckBox->SetValue(true);
+       Connect( addCheckBox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &WxListenerPanel::OnAdd );
+       Connect( removeCheckBox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &WxListenerPanel::OnRemove );
+       std::string name;
+       if (state){name="Start Monitoring Drive";}
+       else {name="Stop Monitoring Drive";}
+       wxButton *start = new wxButton(this,wxID_ANY,_T(name), wxPoint(5,110) );
+       Connect( start->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxListenerPanel::OnChangeThreadState ); 
+
+       wxButton *save = new wxButton(this,wxID_ANY,_T("Save Changes"), wxPoint(130,110) );
+       Connect( save->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxListenerPanel::OnChangeListenState ); 
+  
+
+    //topsizer->Add( mView,1,wxGROW,0);
+
+//    SetSizer( topsizer );     
+    Layout(); 
+  }
+
+  /// Destructor
+  WxListenerPanel::~WxListenerPanel()
+  {
+    GimmickDebugMessage(1,"WxCustomizeConfigPanel::~WxCustomizeConfigPanel"
+                       <<std::endl);
+  }
+
+  void WxListenerPanel::OnAdd(wxCommandEvent& event)
+  {
+               addFiles = addCheckBox->GetValue();
+  }
+
+  void WxListenerPanel::OnRemove(wxCommandEvent& event)
+  {
+               removeFiles = removeCheckBox->GetValue();
+  }
+
+  void WxListenerPanel::OnChangeListenState(wxCommandEvent& event)
+  {
+         mView->OnListenerCallback(crea::wx2std(drives->GetValue()),addFiles, removeFiles);
+         dialog->Destroy();
+  }
+
+  void WxListenerPanel::OnChangeThreadState(wxCommandEvent& event)
+  {
+         if(state)
+         {
+               mView->StartListeningThread();
+         }
+         else
+         {
+               mView->StopListeningThread();
+         }
+         dialog->Destroy();
+  }
+  
+//======================================================================
+  
+//====================================================================== 
+
+} // EO namespace creaImageIO
+
+
diff --git a/src2/creaImageIOWxListenerPanel.h b/src2/creaImageIOWxListenerPanel.h
new file mode 100644 (file)
index 0000000..17dff79
--- /dev/null
@@ -0,0 +1,56 @@
+#ifndef __creaImageIOWxListenerPanel_h_INCLUDED__
+#define __creaImageIOWxListenerPanel_h_INCLUDED__
+
+#ifdef USE_WXWIDGETS
+#include <creaWx.h>
+#include <creaImageIOWxGimmickView.h>
+
+
+namespace creaImageIO
+{
+  /**
+   * \ingroup GUI
+   */
+  //=====================================================================
+ //=====================================================================
+  class WxListenerPanel : public wxPanel
+  {
+  public:
+    WxListenerPanel();    
+       WxListenerPanel(wxWindow *parent, 
+               wxDialog* dial,
+               WxGimmickView* view,
+               bool stat);
+    
+    ~WxListenerPanel();
+       ///Saves the configuration
+        void OnChangeListenState(wxCommandEvent& event);
+    ///Changes the thread state(start/stop)
+        void OnChangeThreadState(wxCommandEvent& event);
+       ///Changes the state of the add boolean
+        void OnAdd(wxCommandEvent& event);
+    ///Changes the state of the remove boolean
+        void OnRemove(wxCommandEvent& event);
+  
+
+  private :
+       bool addFiles;
+       bool removeFiles;
+       bool state;
+       wxCheckBox* addCheckBox;
+       wxCheckBox* removeCheckBox;
+       wxComboBox* drives;
+       wxDialog* dialog;
+       WxGimmickView* mView;
+
+
+  }; // class WxListener
+  //=====================================================================
+
+  
+} // EO namespace creaImageIO
+
+
+#endif // USE_WIDGETS
+// EOF
+#endif  
\ No newline at end of file
index a2604c779865fd34b30a5dabcddcfb3cd538c005..cf6f1eb70e93fedc1883c960ae68214183af1215 100644 (file)
@@ -226,11 +226,14 @@ namespace creaImageIO
        menuItem =new wxMenu;
        wxMenuItem* m1Item=menuItem->Append(wxID_ANY, _T("&Anonymize"));
        wxMenuItem* m2Item=menuItem->Append(wxID_ANY, _T("&Local Copy"));
+       wxMenuItem* m3Item=menuItem->Append(wxID_ANY, _T("&Edit field"));
        
        mAnonymizingID=m1Item->GetId();
        mLocalCopyID=m2Item->GetId();
+       mEditFieldID=m3Item->GetId();
        //Connect( mAnonymizingID, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(WxTreeView::OnAnonymize) );
        Connect( mLocalCopyID, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(WxTreeView::OnLocalCopy) );
+       Connect( mEditFieldID, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(WxTreeView::OnEditField) );
        
        
 #endif // wxUSE_MENUS
@@ -681,12 +684,16 @@ namespace creaImageIO
         wxPoint clientpt;
     clientpt.x = wxGetMousePosition().x - this->GetScreenPosition().x;
     clientpt.y = wxGetMousePosition().y - this->GetScreenPosition().y;
-    senderCtrl = event.GetEventObject(); 
+    senderCtrl = event.GetEventObject();
     unsigned int level = 0;
     for (level = 0; level<mLevelList.size(); ++level)
       {
                if ( GetCtrl(level) == senderCtrl ) break;
       }
+         long* ptr=0;
+         int flag=wxLIST_HITTEST_ONITEM;
+         long itemId=GetCtrl(level)->HitTest(clientpt,flag,ptr);
+         std::cout<<itemId<<std::endl;
     PopupMenu(menuItem, clientpt);
     
   }
@@ -820,6 +827,15 @@ namespace creaImageIO
        }
     
     
+  }
+  //================================================================
+
+   //================================================================
+  void WxTreeView::OnEditField(wxCommandEvent& event)
+  {
+    
+    
+    
   }
   //================================================================
 
index 9d8c34afdbc9de07c6b4f4e29c01d77420835bd3..465d704bb3fe42aaa2189eecd50f5cb089fb448a 100644 (file)
@@ -54,8 +54,11 @@ namespace creaImageIO
       ///Callback when the user need the items filtered
       void OnPopupFilter(wxCommandEvent& event);
 
-         ///Callback when the user need the items filtered
+         ///Callback when the user needs the item copied to the local disk
       void OnLocalCopy(wxCommandEvent& event);
+
+         ///Callback when the user needs to edit a field
+      void OnEditField(wxCommandEvent& event);
       
       ///Callback on mouse click
       void OnMouseClick(wxMouseEvent& event);
@@ -149,6 +152,7 @@ namespace creaImageIO
          wxMenu* menuItem;
          int mAnonymizingID;
          int mLocalCopyID;
+         int mEditFieldID;
       // If set to true then OnSelectedChanged returns immediately.
       // Used to do avoid useless process during multiple selections 
       // or sorting