Mercurial > mercurial > hgweb_dw.cgi
comparison src/myframe.cpp @ 0:7c3921bf511e
Beta2
author | pyon@macmini |
---|---|
date | Sat, 20 Oct 2012 16:07:42 +0900 |
parents | |
children | 20018a6f69a9 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:7c3921bf511e |
---|---|
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 | |
29 m_menubar->Append( m_menuFile, wxT("ファイル(&F)") ); | |
30 | |
31 this->SetMenuBar( m_menubar ); | |
32 | |
33 // | |
34 wxFlexGridSizer* fgSizer = new wxFlexGridSizer( 0, 2, 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 | |
56 m_staticText4 = new wxStaticText( this, wxID_ANY, wxT("MoveTo"), wxDefaultPosition, wxDefaultSize, 0 ); | |
57 fgSizer->Add( m_staticText4, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 ); | |
58 | |
59 m_dirPickerMove = new wxDirPickerCtrl( this, ID_MOVEDIR, wxEmptyString, wxT("Select a folder"), wxDefaultPosition, wxDefaultSize, wxDIRP_DEFAULT_STYLE ); | |
60 fgSizer->Add( m_dirPickerMove, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); | |
61 | |
62 m_staticText5 = new wxStaticText( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); | |
63 fgSizer->Add( m_staticText5, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); | |
64 | |
65 m_toggleBtn = new wxToggleButton( this, ID_TOGGLEWATCH, wxT("Start Watching"), wxDefaultPosition, wxDefaultSize, 0 ); | |
66 fgSizer->Add( m_toggleBtn, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 ); | |
67 | |
68 this->SetSizer( fgSizer ); | |
69 this->Layout(); | |
70 | |
71 this->Centre( wxBOTH ); | |
72 | |
73 m_dirPickerWatch->SetPath( wxT("/Users/takayuki/wx/dw_test" ) ); | |
74 m_dirPickerMove->SetPath( wxT("/Users/takayuki/wx/dw_test/log" ) ); | |
75 m_textCtrlFile->SetValue( wxT("test.file") ); | |
76 } | |
77 | |
78 MyFrame::~MyFrame() | |
79 { | |
80 delete m_watcher; | |
81 } | |
82 | |
83 // Event Table | |
84 BEGIN_EVENT_TABLE( MyFrame, wxFrame ) | |
85 EVT_SIZE( MyFrame::OnWinSize ) | |
86 EVT_MOVE( MyFrame::OnWinMove ) | |
87 EVT_MENU( ID_MNABOUT, MyFrame::OnAbout ) | |
88 //EVT_MENU( wxID_EXIT, MyFrame::OnQuit ) | |
89 EVT_TOGGLEBUTTON( ID_TOGGLEWATCH, MyFrame::OnWatch ) | |
90 EVT_CLOSE( MyFrame::SaveConfig ) | |
91 END_EVENT_TABLE() | |
92 | |
93 // Event Handlers & Functions | |
94 /* フォルダ監視開始/停止スイッチ */ | |
95 void MyFrame::OnWatch( wxCommandEvent& WXUNUSED(event) ) | |
96 { | |
97 Connect( wxEVT_FSWATCHER, wxFileSystemWatcherEventHandler( MyFrame::OnFileSystemEvent ) ); | |
98 | |
99 static bool enabled = false; | |
100 enabled = !enabled; | |
101 | |
102 if ( enabled ) { | |
103 m_toggleBtn->SetLabelText( wxT("Stop Watching") ); | |
104 m_watcher = new wxFileSystemWatcher(); | |
105 m_watcher->SetOwner( this ); | |
106 | |
107 m_watcher->Add( m_dirPickerWatch->GetPath(), wxFSW_EVENT_CREATE ); | |
108 } | |
109 else { | |
110 m_toggleBtn->SetLabelText( wxT("Start Watching") ); | |
111 wxDELETE( m_watcher ); | |
112 } | |
113 } | |
114 | |
115 /* フォルダ監視 */ | |
116 void MyFrame::OnFileSystemEvent( wxFileSystemWatcherEvent& event ) | |
117 { | |
118 //wxMessageBox(wxT("")); | |
119 wxString watchdir = m_dirPickerWatch->GetPath(); | |
120 wxString filename = m_textCtrlFile->GetValue(); | |
121 wxString command = m_textCtrlCommand->GetValue(); | |
122 wxString movedir = m_dirPickerMove->GetPath(); | |
123 | |
124 wxString from; | |
125 wxString to; | |
126 | |
127 wxString file; | |
128 wxDir dir( watchdir ); | |
129 bool cont = dir.GetFirst( &file, filename, wxDIR_FILES ); | |
130 while ( cont ) { | |
131 | |
132 if ( !command.IsEmpty() ) { | |
133 wxExecute( command ); | |
134 } | |
135 | |
136 if ( !movedir.IsEmpty() ) { | |
137 from = watchdir + wxFILE_SEP_PATH + filename; | |
138 wxFileName f( from ); | |
139 wxDateTime now = wxDateTime::Now(); | |
140 to = movedir + wxFILE_SEP_PATH + f.GetName() + wxT("_") + now.Format(wxT("%Y%m%d%H%M%S")) + wxT(".") + f.GetExt(); | |
141 wxRenameFile( from, to, false ); | |
142 } | |
143 | |
144 cont = dir.GetNext( &file ); | |
145 } | |
146 } | |
147 | |
148 /* サイズ変更 */ | |
149 void MyFrame::OnWinSize( wxSizeEvent& event ) | |
150 { | |
151 this->Refresh( true, NULL ); | |
152 TellLocation(); | |
153 event.Skip(); | |
154 } | |
155 /* ウィンドウ移動 */ | |
156 void MyFrame::OnWinMove( wxMoveEvent& WXUNUSED(event) ) | |
157 { | |
158 TellLocation(); | |
159 return; | |
160 } | |
161 /* ウィンドウ位置とサイズを表示 */ | |
162 void MyFrame::TellLocation( void ) | |
163 { | |
164 wxRect r = this->GetRect(); | |
165 int x = r.GetX(); | |
166 int y = r.GetY(); | |
167 int w = r.GetWidth(); | |
168 int h = r.GetHeight(); | |
169 //SetStatusText( wxString::Format(wxT("(%d,%d) %dx%d"),x,y,w,h), 3 ); | |
170 } | |
171 /* 終了 */ | |
172 void MyFrame::OnQuit( wxCommandEvent& WXUNUSED(event) ) | |
173 { | |
174 Close(true); | |
175 } | |
176 /* 設定を保存 */ | |
177 void MyFrame::SaveConfig( wxCloseEvent& WXUNUSED(event) ) | |
178 { | |
179 if ( !IsIconized() && !IsMaximized() ) { | |
180 wxGetApp().rect = this->GetRect(); | |
181 } | |
182 Destroy(); | |
183 } | |
184 /* アバウトダイアログ */ | |
185 void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) ) | |
186 { | |
187 AboutDialog* aboutDlg = new AboutDialog( this, wxID_ANY, wxT("About this Software"), wxDefaultPosition, wxSize(320,280), wxDEFAULT_DIALOG_STYLE|wxSTAY_ON_TOP ); | |
188 aboutDlg->ShowModal(); | |
189 } | |
190 |