0
|
1 // Filename : myframe.cpp
|
|
2 // Last Change: 20-Oct-2012.
|
|
3 //
|
|
4
|
|
5 #include "main.h"
|
|
6 #include "myframe.h"
|
|
7 #include "about.h"
|
|
8
|
|
9 // resources
|
|
10 #if !defined(__WXMSW__) && !defined(__WXPM__)
|
|
11 #include "sample.xpm"
|
|
12 #endif
|
|
13
|
|
14 MyFrame::MyFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style )
|
|
15 : wxFrame( parent, id, title, pos, size, style )
|
|
16 {
|
|
17 this->SetSizeHints( wxDefaultSize, wxDefaultSize );
|
|
18 this->SetBackgroundColour( wxColour(wxT("WHEAT")) );
|
|
19 // set the frame icon
|
|
20 SetIcon(wxICON(sample));
|
|
21
|
|
22 // メニューバー Menu
|
|
23 m_menubar = new wxMenuBar();
|
|
24 m_menuFile = new wxMenu();
|
|
25
|
|
26 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 );
|
|
28
|
1
|
29 m_menubar->Append( m_menuFile, wxT("File(&F)") );
|
0
|
30
|
|
31 this->SetMenuBar( m_menubar );
|
|
32
|
|
33 //
|
1
|
34 wxFlexGridSizer* fgSizer = new wxFlexGridSizer( 0, 4, 0, 0 );
|
0
|
35 fgSizer->SetFlexibleDirection( wxBOTH );
|
|
36 fgSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
|
|
37
|
|
38 m_staticText1 = new wxStaticText( this, wxID_ANY, wxT("Folder"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
39 fgSizer->Add( m_staticText1, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 );
|
|
40
|
|
41 m_dirPickerWatch = new wxDirPickerCtrl( this, ID_WATCHDIR, wxEmptyString, wxT("Select a folder"), wxDefaultPosition, wxDefaultSize, wxDIRP_DEFAULT_STYLE );
|
|
42 fgSizer->Add( m_dirPickerWatch, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
|
43
|
|
44 m_staticText2 = new wxStaticText( this, wxID_ANY, wxT("Filename"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
45 fgSizer->Add( m_staticText2, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 );
|
|
46
|
|
47 m_textCtrlFile = new wxTextCtrl( this, ID_FILENAME, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
|
|
48 fgSizer->Add( m_textCtrlFile, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 );
|
|
49
|
|
50 m_staticText3 = new wxStaticText( this, wxID_ANY, wxT("Command"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
51 fgSizer->Add( m_staticText3, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 );
|
|
52
|
|
53 m_textCtrlCommand = new wxTextCtrl( this, ID_COMMAND, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
|
|
54 fgSizer->Add( m_textCtrlCommand, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 );
|
|
55
|
1
|
56 m_staticText4 = new wxStaticText( this, wxID_ANY, wxT("wait [sec]"), wxDefaultPosition, wxDefaultSize, 0 );
|
0
|
57 fgSizer->Add( m_staticText4, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 );
|
1
|
58
|
|
59 m_textCtrlWait = new wxTextCtrl( this, ID_WAIT, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
|
|
60 fgSizer->Add( m_textCtrlWait, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 );
|
|
61
|
|
62 m_staticText5 = new wxStaticText( this, wxID_ANY, wxT("MoveTo"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
63 fgSizer->Add( m_staticText5, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 );
|
0
|
64
|
|
65 m_dirPickerMove = new wxDirPickerCtrl( this, ID_MOVEDIR, wxEmptyString, wxT("Select a folder"), wxDefaultPosition, wxDefaultSize, wxDIRP_DEFAULT_STYLE );
|
|
66 fgSizer->Add( m_dirPickerMove, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
|
67
|
1
|
68 m_staticText6 = new wxStaticText( this, wxID_ANY, wxT("copy"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
69 fgSizer->Add( m_staticText6, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 );
|
|
70
|
|
71 m_checkBoxCopy = new wxCheckBox( this, ID_COPY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
|
|
72 fgSizer->Add( m_checkBoxCopy, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
|
73
|
|
74 m_staticTextDummy1 = new wxStaticText( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
|
|
75 fgSizer->Add( m_staticTextDummy1, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 );
|
|
76
|
|
77 m_staticTextDummy2 = new wxStaticText( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
|
|
78 fgSizer->Add( m_staticTextDummy2, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 );
|
|
79
|
|
80 m_staticTextDummy3 = new wxStaticText( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
|
|
81 fgSizer->Add( m_staticTextDummy3, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 );
|
0
|
82
|
|
83 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 );
|
|
85
|
|
86 this->SetSizer( fgSizer );
|
|
87 this->Layout();
|
|
88
|
|
89 this->Centre( wxBOTH );
|
|
90
|
1
|
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\\" ) );
|
0
|
95 m_textCtrlFile->SetValue( wxT("test.file") );
|
|
96 }
|
|
97
|
|
98 MyFrame::~MyFrame()
|
|
99 {
|
|
100 delete m_watcher;
|
|
101 }
|
|
102
|
|
103 // Event Table
|
|
104 BEGIN_EVENT_TABLE( MyFrame, wxFrame )
|
|
105 EVT_SIZE( MyFrame::OnWinSize )
|
|
106 EVT_MOVE( MyFrame::OnWinMove )
|
|
107 EVT_MENU( ID_MNABOUT, MyFrame::OnAbout )
|
|
108 //EVT_MENU( wxID_EXIT, MyFrame::OnQuit )
|
|
109 EVT_TOGGLEBUTTON( ID_TOGGLEWATCH, MyFrame::OnWatch )
|
|
110 EVT_CLOSE( MyFrame::SaveConfig )
|
|
111 END_EVENT_TABLE()
|
|
112
|
|
113 // Event Handlers & Functions
|
|
114 /* フォルダ監視開始/停止スイッチ */
|
|
115 void MyFrame::OnWatch( wxCommandEvent& WXUNUSED(event) )
|
|
116 {
|
|
117 Connect( wxEVT_FSWATCHER, wxFileSystemWatcherEventHandler( MyFrame::OnFileSystemEvent ) );
|
|
118
|
|
119 static bool enabled = false;
|
|
120 enabled = !enabled;
|
|
121
|
|
122 if ( enabled ) {
|
|
123 m_toggleBtn->SetLabelText( wxT("Stop Watching") );
|
|
124 m_watcher = new wxFileSystemWatcher();
|
|
125 m_watcher->SetOwner( this );
|
|
126
|
|
127 m_watcher->Add( m_dirPickerWatch->GetPath(), wxFSW_EVENT_CREATE );
|
|
128 }
|
|
129 else {
|
|
130 m_toggleBtn->SetLabelText( wxT("Start Watching") );
|
|
131 wxDELETE( m_watcher );
|
|
132 }
|
|
133 }
|
|
134
|
|
135 /* フォルダ監視 */
|
|
136 void MyFrame::OnFileSystemEvent( wxFileSystemWatcherEvent& event )
|
|
137 {
|
1
|
138 wxMilliSleep( 1500 );
|
|
139
|
0
|
140 wxString watchdir = m_dirPickerWatch->GetPath();
|
|
141 wxString filename = m_textCtrlFile->GetValue();
|
|
142 wxString command = m_textCtrlCommand->GetValue();
|
|
143 wxString movedir = m_dirPickerMove->GetPath();
|
|
144
|
|
145 wxString from;
|
|
146 wxString to;
|
|
147
|
|
148 wxString file;
|
|
149 wxDir dir( watchdir );
|
|
150 bool cont = dir.GetFirst( &file, filename, wxDIR_FILES );
|
|
151 while ( cont ) {
|
|
152
|
|
153 if ( !command.IsEmpty() ) {
|
1
|
154 wxSleep( 2 );
|
0
|
155 wxExecute( command );
|
|
156 }
|
|
157
|
|
158 if ( !movedir.IsEmpty() ) {
|
|
159 from = watchdir + wxFILE_SEP_PATH + filename;
|
|
160 wxFileName f( from );
|
|
161 wxDateTime now = wxDateTime::Now();
|
|
162 to = movedir + wxFILE_SEP_PATH + f.GetName() + wxT("_") + now.Format(wxT("%Y%m%d%H%M%S")) + wxT(".") + f.GetExt();
|
1
|
163 if ( m_checkBoxCopy->IsChecked() ) {
|
|
164 wxCopyFile( from, to, false );
|
|
165 }
|
|
166 else {
|
|
167 wxRenameFile( from, to, false );
|
|
168 }
|
0
|
169 }
|
|
170
|
|
171 cont = dir.GetNext( &file );
|
|
172 }
|
|
173 }
|
|
174
|
|
175 /* サイズ変更 */
|
|
176 void MyFrame::OnWinSize( wxSizeEvent& event )
|
|
177 {
|
|
178 this->Refresh( true, NULL );
|
|
179 TellLocation();
|
|
180 event.Skip();
|
|
181 }
|
|
182 /* ウィンドウ移動 */
|
|
183 void MyFrame::OnWinMove( wxMoveEvent& WXUNUSED(event) )
|
|
184 {
|
|
185 TellLocation();
|
|
186 return;
|
|
187 }
|
|
188 /* ウィンドウ位置とサイズを表示 */
|
|
189 void MyFrame::TellLocation( void )
|
|
190 {
|
|
191 wxRect r = this->GetRect();
|
|
192 int x = r.GetX();
|
|
193 int y = r.GetY();
|
|
194 int w = r.GetWidth();
|
|
195 int h = r.GetHeight();
|
|
196 //SetStatusText( wxString::Format(wxT("(%d,%d) %dx%d"),x,y,w,h), 3 );
|
|
197 }
|
|
198 /* 終了 */
|
|
199 void MyFrame::OnQuit( wxCommandEvent& WXUNUSED(event) )
|
|
200 {
|
|
201 Close(true);
|
|
202 }
|
|
203 /* 設定を保存 */
|
|
204 void MyFrame::SaveConfig( wxCloseEvent& WXUNUSED(event) )
|
|
205 {
|
|
206 if ( !IsIconized() && !IsMaximized() ) {
|
|
207 wxGetApp().rect = this->GetRect();
|
|
208 }
|
|
209 Destroy();
|
|
210 }
|
|
211 /* アバウトダイアログ */
|
|
212 void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) )
|
|
213 {
|
|
214 AboutDialog* aboutDlg = new AboutDialog( this, wxID_ANY, wxT("About this Software"), wxDefaultPosition, wxSize(320,280), wxDEFAULT_DIALOG_STYLE|wxSTAY_ON_TOP );
|
|
215 aboutDlg->ShowModal();
|
|
216 }
|
|
217
|