]> Creatis software - creaImageIO.git/blobdiff - src2/creaImageIOWxGimmickView.cpp
*** empty log message ***
[creaImageIO.git] / src2 / creaImageIOWxGimmickView.cpp
index 7e79bc320c94b25983120a56ab82a33f1c660b6c..900101ad1a4cdc848fa05489766bb0d3382689ea 100644 (file)
@@ -19,7 +19,7 @@ namespace creaImageIO
   // The ids of the different tools
   enum
     {
-      TOOL_ADDFILE_ID = 1,
+      TOOL_ADDFILES_ID = 1,
       TOOL_ADDDIR_ID = 2,
       TOOL_REMOVE_ID = 3,
       TOOL_ADDDATABASE_ID = 4,
@@ -64,10 +64,18 @@ namespace creaImageIO
                               int image_type,
                               int number_of_threads)
     : wxPanel(parent,id,pos,size),
-      GimmickView(gimmick)
+      GimmickView(gimmick),
+      mProgressDialog(0)
   {
     GimmickDebugMessage(1,"WxGimmickView::WxGimmickView"
                        <<std::endl);
+    // Sets the current directory to the home dir
+    mCurrentDirectory =  std2wx(gimmick->GetHomeDirectory());
+
+     // Connect the AddProgress callback
+    gimmick->ConnectAddProgressObserver
+      ( boost::bind( &WxGimmickView::OnAddProgress , this, _1 ) );
+
     // Create the list of icons (mIcon)
     CreateIconList();
 
@@ -131,10 +139,10 @@ namespace creaImageIO
     mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize,
                             style);
 
-    mToolAddFile = mToolBar->AddTool( TOOL_ADDFILE_ID, 
+    mToolAddFile = mToolBar->AddTool( TOOL_ADDFILES_ID, 
                                      _T("Add file(s)"),
                                      mIcon->GetBitmap(Icon_page_down),
-                                     _T("Add some file(s) to database")
+                                     _T("Add one or more file to database")
                                      );
     mToolAddDir = mToolBar->AddTool( TOOL_ADDDIR_ID, 
                                      _T("Add folder"),
@@ -219,23 +227,25 @@ namespace creaImageIO
          }
       }
   }
+  //=================================================
 
 
   //=================================================
-  void WxGimmickView::OnAddFile(wxCommandEvent& event)
+  void WxGimmickView::OnAddFiles(wxCommandEvent& event)
   {
    long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
     std::string wc("*.*");
     wxFileDialog* FD = new wxFileDialog( 0, 
                                         _T("Select file"),
-                                        "",
                                         _T(""),
-                                        std2wx(wc),
+                                        _T(""),
+                                        crea::std2wx(wc),
                                         style,
                                         wxDefaultPosition);
     
     if (FD->ShowModal()==wxID_OK)
       {
+       wxBusyCursor busy;
 
        wxArrayString files;
        FD->GetPaths(files);
@@ -247,6 +257,23 @@ namespace creaImageIO
          GimmickMessage(2,"Adding File "<<files[i]<<"."<<std::endl);
        }
 
+       mProgressDialog = 
+         new wxProgressDialog(_T("Adding file(s)"),
+                              _T(""),
+                              1000,
+                              this,
+                              wxPD_ELAPSED_TIME |
+                              wxPD_ESTIMATED_TIME | 
+                              wxPD_REMAINING_TIME |
+                              wxPD_CAN_ABORT );
+
+       // TO DO : select the current tree handler
+       mGimmick->AddFiles("Local database",filenames);
+
+       mProgressDialog->Pulse(_T("Updating view..."));
+
+       UpdateTreeViewLevel("Local database",1);
+       delete mProgressDialog;
        
     /*   
        TreeItemData *data = 
@@ -276,9 +303,83 @@ namespace creaImageIO
   }
   //=================================================
 
+  //=================================================
+  void WxGimmickView::OnAddDir(wxCommandEvent& event)
+  {
+    long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
+    wxDirDialog* FD = 
+      new wxDirDialog( 0, 
+                      _T("Select directory"),
+                      mCurrentDirectory,
+                      style);
+    
+    if (FD->ShowModal()==wxID_OK)
+      {
+       
+       bool recurse = false;
+       if (wxMessageBox(_T("Recurse into sub-directories ?"),
+                        _T("Scan directory"),
+                        wxYES_NO,this ) == wxYES)
+         {
+           recurse = true;
+         }
+       
+       wxBusyCursor busy;
+       wxString title(_T("Adding directory"));
+       if (recurse) 
+         title = _T("Adding directory (recursive)");
+       mProgressDialog = 
+         new wxProgressDialog(_T("Adding directory"),
+                              _T(""),
+                              1000,
+                              this,
+                              wxPD_ELAPSED_TIME |
+                              wxPD_ESTIMATED_TIME | 
+                              wxPD_REMAINING_TIME |
+                              wxPD_CAN_ABORT );
+       std::string dirname = wx2std (FD->GetPath()) ;
+       mCurrentDirectory = FD->GetPath();  
+       
+       // TO DO : select the current tree handler
+       mGimmick->AddDir("Local database",dirname,recurse);
+       
+       mProgressDialog->Pulse(_T("Updating view..."));
+       
+       UpdateTreeViewLevel("Local database",1);
+       delete mProgressDialog;
+       
+      }
+  }
+  //=================================================
+
+  //=================================================
+  /// AddProgress Gimmick callback
+  void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
+  {
+
+    char mess[200];
+    sprintf(mess,"%i dirs - %i files - %i handled - %i added",
+          p.GetNumberScannedDirs(),
+          p.GetNumberScannedFiles(),
+          p.GetNumberHandledFiles(),
+          p.GetNumberAddedFiles());
+    std::cout << "OnAddProgress "<<mess<<std::endl;
+    wxString s(wxString::From8BitData(mess));
+    //  std::cout << "Pulse"<<std::endl;
+    if (!mProgressDialog->Pulse(s)) 
+      {
+       p.SetStop();
+      }
+    //  std::cout << "OnAddProgress ok"<<std::endl;
+  }
+  //=================================================
+
+ //=================================================
   BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
-  EVT_TOOL(TOOL_ADDFILE_ID, WxGimmickView::OnAddFile)
-  END_EVENT_TABLE()
+    EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
+    EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
+    END_EVENT_TABLE()
+  //=================================================
 
 } // EO namespace creaImageIO