Mercurial > mercurial > hgweb_dw.cgi
comparison src/myframe.cpp @ 2:deaf3f2d54b2
more parameters.
| author | pyon@macmini | 
|---|---|
| date | Thu, 08 Nov 2012 20:17:12 +0900 | 
| parents | 20018a6f69a9 | 
| children | eea479fc2a28 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 1:20018a6f69a9 | 2:deaf3f2d54b2 | 
|---|---|
| 21 | 21 | 
| 22 // メニューバー Menu | 22 // メニューバー Menu | 
| 23 m_menubar = new wxMenuBar(); | 23 m_menubar = new wxMenuBar(); | 
| 24 m_menuFile = new wxMenu(); | 24 m_menuFile = new wxMenu(); | 
| 25 | 25 | 
| 26 wxMenuItem* m_menuItemSetup = new wxMenuItem( m_menuFile, ID_MNSETUP, wxString( wxT("&Setup...") ) , wxT("Setup parameters"), wxITEM_NORMAL ); | |
| 27 m_menuFile->Append( m_menuItemSetup ); | |
| 28 | |
| 29 wxMenuItem* m_menuItemSave = new wxMenuItem( m_menuFile, ID_MNSAVE, wxString( wxT("Save setting...") ) , wxT("Save parameters"), wxITEM_NORMAL ); | |
| 30 m_menuFile->Append( m_menuItemSave ); | |
| 31 | |
| 26 wxMenuItem* m_menuItemAbout = new wxMenuItem( m_menuFile, ID_MNABOUT, wxString( wxT("&About...\tF1") ) , wxT("Show about dialog"), wxITEM_NORMAL ); | 32 wxMenuItem* m_menuItemAbout = new wxMenuItem( m_menuFile, ID_MNABOUT, wxString( wxT("&About...\tF1") ) , wxT("Show about dialog"), wxITEM_NORMAL ); | 
| 27 m_menuFile->Append( m_menuItemAbout ); | 33 m_menuFile->Append( m_menuItemAbout ); | 
| 28 | 34 | 
| 29 m_menubar->Append( m_menuFile, wxT("File(&F)") ); | 35 m_menubar->Append( m_menuFile, wxT("File(&F)") ); | 
| 30 | 36 | 
| 69 fgSizer->Add( m_staticText6, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 ); | 75 fgSizer->Add( m_staticText6, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 ); | 
| 70 | 76 | 
| 71 m_checkBoxCopy = new wxCheckBox( this, ID_COPY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); | 77 m_checkBoxCopy = new wxCheckBox( this, ID_COPY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); | 
| 72 fgSizer->Add( m_checkBoxCopy, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); | 78 fgSizer->Add( m_checkBoxCopy, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); | 
| 73 | 79 | 
| 80 m_staticText7 = new wxStaticText( this, wxID_ANY, wxT("suffix"), wxDefaultPosition, wxDefaultSize, 0 ); | |
| 81 fgSizer->Add( m_staticText7, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 ); | |
| 82 | |
| 83 wxArrayString suffix; | |
| 84 suffix.Add( wxT("Date & Time") ); | |
| 85 m_comboSuffix = new wxComboBox( this, ID_SUFFIX, wxEmptyString, wxDefaultPosition, wxDefaultSize, suffix, 0 ); | |
| 86 fgSizer->Add( m_comboSuffix, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); | |
| 87 | |
| 74 m_staticTextDummy1 = new wxStaticText( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); | 88 m_staticTextDummy1 = new wxStaticText( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); | 
| 75 fgSizer->Add( m_staticTextDummy1, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 ); | 89 fgSizer->Add( m_staticTextDummy1, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 ); | 
| 76 | 90 | 
| 77 m_staticTextDummy2 = new wxStaticText( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); | 91 m_staticTextDummy2 = new wxStaticText( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); | 
| 78 fgSizer->Add( m_staticTextDummy2, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 ); | 92 fgSizer->Add( m_staticTextDummy2, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 ); | 
| 79 | 93 | 
| 94 m_staticText8 = new wxStaticText( this, wxID_ANY, wxT("Exit"), wxDefaultPosition, wxDefaultSize, 0 ); | |
| 95 fgSizer->Add( m_staticText8, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 ); | |
| 96 | |
| 97 m_checkBoxExit = new wxCheckBox( this, ID_EXIT, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); | |
| 98 fgSizer->Add( m_checkBoxExit, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); | |
| 99 | |
| 80 m_staticTextDummy3 = new wxStaticText( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); | 100 m_staticTextDummy3 = new wxStaticText( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); | 
| 81 fgSizer->Add( m_staticTextDummy3, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 ); | 101 fgSizer->Add( m_staticTextDummy3, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 ); | 
| 82 | 102 | 
| 83 m_toggleBtn = new wxToggleButton( this, ID_TOGGLEWATCH, wxT("Start Watching"), wxDefaultPosition, wxDefaultSize, 0 ); | 103 m_toggleBtn = new wxToggleButton( this, ID_TOGGLEWATCH, wxT("Start Watching"), wxDefaultPosition, wxDefaultSize, 0 ); | 
| 84 fgSizer->Add( m_toggleBtn, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 ); | 104 fgSizer->Add( m_toggleBtn, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 ); | 
| 85 | 105 | 
| 86 this->SetSizer( fgSizer ); | 106 this->SetSizer( fgSizer ); | 
| 87 this->Layout(); | 107 this->Layout(); | 
| 88 | 108 | 
| 89 this->Centre( wxBOTH ); | 109 this->Centre( wxBOTH ); | 
| 90 | |
| 91 //m_dirPickerWatch->SetPath( wxT("/Users/takayuki/wx/dw_test" ) ); | |
| 92 //m_dirPickerMove->SetPath( wxT("/Users/takayuki/wx/dw_test/log" ) ); | |
| 93 m_dirPickerWatch->SetPath( wxT("\\\\Kai-sv51\\Users\\Administrator\\Documents\\Fuji Xerox\\DocuWorks\\DWFolders\\ユーザーフォルダ" ) ); | |
| 94 m_dirPickerMove->SetPath( wxT("C:\\Users\\KAIGO\\Desktop\\dww\\" ) ); | |
| 95 m_textCtrlFile->SetValue( wxT("test.file") ); | |
| 96 } | 110 } | 
| 97 | 111 | 
| 98 MyFrame::~MyFrame() | 112 MyFrame::~MyFrame() | 
| 99 { | 113 { | 
| 100 delete m_watcher; | 114 delete m_watcher; | 
| 102 | 116 | 
| 103 // Event Table | 117 // Event Table | 
| 104 BEGIN_EVENT_TABLE( MyFrame, wxFrame ) | 118 BEGIN_EVENT_TABLE( MyFrame, wxFrame ) | 
| 105 EVT_SIZE( MyFrame::OnWinSize ) | 119 EVT_SIZE( MyFrame::OnWinSize ) | 
| 106 EVT_MOVE( MyFrame::OnWinMove ) | 120 EVT_MOVE( MyFrame::OnWinMove ) | 
| 121 EVT_MENU( ID_MNSETUP, MyFrame::OnSetup ) | |
| 122 EVT_MENU( ID_MNSAVE, MyFrame::OnSaveParams ) | |
| 107 EVT_MENU( ID_MNABOUT, MyFrame::OnAbout ) | 123 EVT_MENU( ID_MNABOUT, MyFrame::OnAbout ) | 
| 108 //EVT_MENU( wxID_EXIT, MyFrame::OnQuit ) | 124 //EVT_MENU( wxID_EXIT, MyFrame::OnQuit ) | 
| 109 EVT_TOGGLEBUTTON( ID_TOGGLEWATCH, MyFrame::OnWatch ) | 125 EVT_TOGGLEBUTTON( ID_TOGGLEWATCH, MyFrame::OnWatch ) | 
| 110 EVT_CLOSE( MyFrame::SaveConfig ) | 126 EVT_CLOSE( MyFrame::SaveConfig ) | 
| 111 END_EVENT_TABLE() | 127 END_EVENT_TABLE() | 
| 149 wxDir dir( watchdir ); | 165 wxDir dir( watchdir ); | 
| 150 bool cont = dir.GetFirst( &file, filename, wxDIR_FILES ); | 166 bool cont = dir.GetFirst( &file, filename, wxDIR_FILES ); | 
| 151 while ( cont ) { | 167 while ( cont ) { | 
| 152 | 168 | 
| 153 if ( !command.IsEmpty() ) { | 169 if ( !command.IsEmpty() ) { | 
| 170 wxExecute( command ); | |
| 154 wxSleep( 2 ); | 171 wxSleep( 2 ); | 
| 155 wxExecute( command ); | |
| 156 } | 172 } | 
| 157 | 173 | 
| 158 if ( !movedir.IsEmpty() ) { | 174 if ( !movedir.IsEmpty() ) { | 
| 159 from = watchdir + wxFILE_SEP_PATH + filename; | 175 from = watchdir + wxFILE_SEP_PATH + filename; | 
| 160 wxFileName f( from ); | 176 wxFileName f( from ); | 
| 161 wxDateTime now = wxDateTime::Now(); | 177 | 
| 162 to = movedir + wxFILE_SEP_PATH + f.GetName() + wxT("_") + now.Format(wxT("%Y%m%d%H%M%S")) + wxT(".") + f.GetExt(); | 178 // ファイル名をどうするか | 
| 163 if ( m_checkBoxCopy->IsChecked() ) { | 179 if ( m_comboSuffix->GetCurrentSelection() == 0 ) { | 
| 164 wxCopyFile( from, to, false ); | 180 wxDateTime now = wxDateTime::Now(); | 
| 181 to = movedir + wxFILE_SEP_PATH + f.GetName() + wxT("_") + now.Format(wxT("%Y%m%d%H%M%S")) + wxT(".") + f.GetExt(); | |
| 165 } | 182 } | 
| 166 else { | 183 else { | 
| 184 to = movedir + wxFILE_SEP_PATH + filename; | |
| 185 } | |
| 186 | |
| 187 // オリジナルを残すか | |
| 188 if ( m_checkBoxCopy->IsChecked() ) | |
| 189 wxCopyFile( from, to, false ); | |
| 190 else | |
| 167 wxRenameFile( from, to, false ); | 191 wxRenameFile( from, to, false ); | 
| 168 } | |
| 169 } | 192 } | 
| 170 | 193 | 
| 171 cont = dir.GetNext( &file ); | 194 cont = dir.GetNext( &file ); | 
| 172 } | 195 } | 
| 196 if ( m_checkBoxExit->IsChecked() ) Close( true ); | |
| 197 } | |
| 198 | |
| 199 /* セットアップ */ | |
| 200 void MyFrame::OnSetup( wxCommandEvent& WXUNUSED(event) ) | |
| 201 { | |
| 202 wxString dws_dir = wxGetCwd() + wxFILE_SEP_PATH + wxT("dws"); | |
| 203 wxFileDialog fd( this, wxT("Open Setup file"), dws_dir , wxEmptyString, wxT("Setup files (*.dws)|*.dws"), wxFD_OPEN|wxFD_FILE_MUST_EXIST ); | |
| 204 if ( fd.ShowModal() == wxID_CANCEL ) return; // the user changed idea... | |
| 205 | |
| 206 wxFileConfig* config = new wxFileConfig( wxT("MyApp"), wxT("T.Mutoh"), fd.GetPath(), wxEmptyString, wxCONFIG_USE_LOCAL_FILE ); | |
| 207 | |
| 208 wxString p_folder, p_filename, p_command, p_wait, p_moveto; | |
| 209 bool p_copy, p_exit; | |
| 210 long p_suffix; | |
| 211 config->SetPath( wxT("/Parameter") ); | |
| 212 config->Read( wxT("Folder"), &p_folder ); | |
| 213 config->Read( wxT("Filename"), &p_filename ); | |
| 214 config->Read( wxT("Command"), &p_command ); | |
| 215 config->Read( wxT("Wait"), &p_wait ); | |
| 216 config->Read( wxT("MoveTo"), &p_moveto ); | |
| 217 config->Read( wxT("Copy"), p_copy ); | |
| 218 config->Read( wxT("Suffix"), &p_suffix ); | |
| 219 config->Read( wxT("Exit"), p_exit ); | |
| 220 | |
| 221 m_dirPickerWatch->SetPath( p_folder ); | |
| 222 m_textCtrlFile->SetValue( p_filename ); | |
| 223 m_textCtrlCommand->SetValue( p_command ); | |
| 224 m_textCtrlWait->SetValue( p_wait ); | |
| 225 m_dirPickerMove->SetPath( p_moveto ); | |
| 226 m_checkBoxCopy->SetValue( p_copy ); | |
| 227 m_comboSuffix->SetSelection( (int)p_suffix ); | |
| 228 m_checkBoxExit->SetValue( p_exit ); | |
| 229 | |
| 230 delete config; | |
| 231 } | |
| 232 /* パラーメータを保存 */ | |
| 233 void MyFrame::OnSaveParams( wxCommandEvent& WXUNUSED(event) ) | |
| 234 { | |
| 235 wxString dws_dir = wxGetCwd() + wxFILE_SEP_PATH + wxT("dws"); | |
| 236 wxFileDialog fd( this, wxT("Save Setup file"), dws_dir , wxEmptyString, wxT("Setup files (*.dws)|*.dws"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT ); | |
| 237 if ( fd.ShowModal() == wxID_CANCEL ) return; // the user changed idea... | |
| 238 | |
| 239 wxFileConfig* config = new wxFileConfig( wxT("MyApp"), wxT("T.Mutoh"), fd.GetPath(), wxEmptyString, wxCONFIG_USE_LOCAL_FILE ); | |
| 240 | |
| 241 config->SetPath( wxT("/Parameter") ); | |
| 242 config->Write( wxT("Folder"), m_dirPickerWatch->GetPath() ); | |
| 243 config->Write( wxT("Filename"), m_textCtrlFile->GetValue() ); | |
| 244 config->Write( wxT("Command"), m_textCtrlCommand->GetValue() ); | |
| 245 config->Write( wxT("Wait"), m_textCtrlWait->GetValue() ); | |
| 246 config->Write( wxT("MoveTo"), m_dirPickerMove->GetPath() ); | |
| 247 config->Write( wxT("Copy"), m_checkBoxCopy->GetValue() ); | |
| 248 config->Write( wxT("Suffix"), m_comboSuffix->GetSelection() ); | |
| 249 config->Write( wxT("Exit"), m_checkBoxExit->GetValue() ); | |
| 250 | |
| 251 delete config; | |
| 173 } | 252 } | 
| 174 | 253 | 
| 175 /* サイズ変更 */ | 254 /* サイズ変更 */ | 
| 176 void MyFrame::OnWinSize( wxSizeEvent& event ) | 255 void MyFrame::OnWinSize( wxSizeEvent& event ) | 
| 177 { | 256 { | 
| 196 //SetStatusText( wxString::Format(wxT("(%d,%d) %dx%d"),x,y,w,h), 3 ); | 275 //SetStatusText( wxString::Format(wxT("(%d,%d) %dx%d"),x,y,w,h), 3 ); | 
| 197 } | 276 } | 
| 198 /* 終了 */ | 277 /* 終了 */ | 
| 199 void MyFrame::OnQuit( wxCommandEvent& WXUNUSED(event) ) | 278 void MyFrame::OnQuit( wxCommandEvent& WXUNUSED(event) ) | 
| 200 { | 279 { | 
| 201 Close(true); | 280 Close( true ); | 
| 202 } | 281 } | 
| 203 /* 設定を保存 */ | 282 /* 設定を保存 */ | 
| 204 void MyFrame::SaveConfig( wxCloseEvent& WXUNUSED(event) ) | 283 void MyFrame::SaveConfig( wxCloseEvent& WXUNUSED(event) ) | 
| 205 { | 284 { | 
| 206 if ( !IsIconized() && !IsMaximized() ) { | 285 if ( !IsIconized() && !IsMaximized() ) { | 
