2
|
1 // Filename : delwhite.cpp
|
4
|
2 // Last Change: 05-Oct-2011.
|
2
|
3 //
|
|
4
|
|
5 #include "delwhite.h"
|
|
6
|
|
7 // constructor
|
|
8 FrameDelWhite::FrameDelWhite( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style )
|
|
9 {
|
|
10 this->SetSize( 1200, 1000 );
|
3
|
11 this->SetBackgroundColour( wxColour(wxT("WHEAT")) );
|
2
|
12
|
|
13 wxBoxSizer* bSizer;
|
|
14 bSizer = new wxBoxSizer( wxVERTICAL );
|
|
15
|
|
16 m_listCtrl = new wxListCtrl( this, ID_LSWHITE, wxDefaultPosition, wxDefaultSize, wxLC_ICON );
|
|
17 bSizer->Add( m_listCtrl, 1, wxALL|wxEXPAND, 5 );
|
3
|
18 m_imageList = new wxImageList( 63, 89 );
|
2
|
19 m_listCtrl->AssignImageList( m_imageList, wxIMAGE_LIST_NORMAL );
|
|
20
|
|
21 wxBoxSizer* bSizerBtn;
|
|
22 bSizerBtn = new wxBoxSizer( wxHORIZONTAL );
|
|
23
|
|
24 m_checkBox = new wxCheckBox( this, ID_CHECK, wxT("全ての画像を表示"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
25 bSizer->Add( m_checkBox, 0, wxALL, 5 );
|
|
26
|
|
27 m_staticText = new wxStaticText( this, wxID_ANY, wxT("白紙ファイルを選択し,「削除」ボタンを押してください.") );
|
|
28 bSizerBtn->Add( m_staticText, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
|
29
|
|
30 m_buttonDelWhite = new wxButton( this, ID_DELETE, wxT("削除"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
31 bSizerBtn->Add( m_buttonDelWhite, 0, wxALL, 5 );
|
|
32
|
|
33 m_buttonCancel = new wxButton( this, ID_CANCEL, wxT("キャンセル"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
34 bSizerBtn->Add( m_buttonCancel, 0, wxALL, 5 );
|
|
35
|
|
36 bSizer->Add( bSizerBtn, 0, wxEXPAND, 5 );
|
|
37
|
|
38 this->SetSizer( bSizer );
|
|
39 this->Layout();
|
|
40
|
|
41 this->Centre( wxBOTH );
|
|
42 }
|
|
43
|
|
44 // destructor
|
|
45 FrameDelWhite::~FrameDelWhite()
|
|
46 {
|
|
47 }
|
|
48
|
|
49 // Event Table
|
|
50 BEGIN_EVENT_TABLE( FrameDelWhite, wxFrame )
|
|
51 //EVT_LIST_ITEM_SELECTED( ID_LSTCTRL, FramePreview::ChageImage )
|
3
|
52 EVT_CHECKBOX( ID_CHECK, FrameDelWhite::UpdateList )
|
2
|
53 EVT_BUTTON( ID_DELETE, FrameDelWhite::DeleteImage )
|
3
|
54 EVT_BUTTON( ID_CANCEL, FrameDelWhite::CloseFrame )
|
2
|
55 END_EVENT_TABLE()
|
|
56
|
|
57 // Event Handlers
|
3
|
58 void FrameDelWhite::UpdateList(wxCommandEvent& WXUNUSED(event))
|
|
59 {
|
|
60 LoadImages();
|
|
61 }
|
|
62
|
2
|
63 void FrameDelWhite::DeleteImage(wxCommandEvent& WXUNUSED(event))
|
|
64 {
|
4
|
65 wxDateTime now = wxDateTime::Now();
|
|
66 wxString trash = wxGetCwd() + wxFILE_SEP_PATH + wxT("trash") + wxFILE_SEP_PATH + now.Format(wxT("%Y%m%d%H%M%S"));
|
|
67 wxMkdir( trash );
|
|
68
|
|
69 long item = -1;
|
|
70 for ( ; ; ) {
|
|
71 item = m_listCtrl->GetNextItem( item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
|
|
72 if ( item == -1 )
|
|
73 break;
|
|
74 wxString file = m_listCtrl->GetItemText( item );
|
|
75
|
|
76 wxString from = m_dir + wxFILE_SEP_PATH + file;
|
|
77 wxString to = trash + wxFILE_SEP_PATH + file;
|
|
78 wxRenameFile( from, to, false );
|
|
79 }
|
|
80 LoadImages();
|
2
|
81 return;
|
|
82 }
|
|
83
|
|
84 void FrameDelWhite::CloseFrame(wxCommandEvent& WXUNUSED(event))
|
|
85 {
|
|
86 this->Close();
|
|
87 return;
|
|
88 }
|
|
89
|
|
90 // Functions
|
|
91 void FrameDelWhite::LoadImages( void )
|
|
92 {
|
3
|
93 m_listCtrl->DeleteAllItems();
|
|
94 m_imageList->RemoveAll();
|
2
|
95 wxDir dir(m_dir);
|
|
96 wxString filename;
|
|
97 if ( !dir.IsOpened() ) return;
|
|
98
|
|
99 bool cout = dir.GetFirst( &filename, wxT("*.jpg"), wxDIR_FILES );
|
|
100
|
|
101 int i=0;
|
|
102 wxListItem item;
|
|
103 while ( cout ) {
|
|
104 wxString f = m_dir + wxFILE_SEP_PATH + filename;
|
|
105 wxFile file( f );
|
|
106 long len = file.Length();
|
3
|
107 if ( !m_checkBox->IsChecked() && len > 150000 ) {
|
2
|
108 cout = dir.GetNext( &filename );
|
|
109 continue;
|
|
110 }
|
|
111
|
|
112 item.SetId(i);
|
|
113 item.SetMask(wxLIST_MASK_STATE|wxLIST_MASK_TEXT|wxLIST_MASK_IMAGE);
|
|
114 item.SetStateMask(wxLIST_STATE_SELECTED);
|
|
115 item.SetState(wxLIST_STATE_SELECTED);
|
|
116 item.SetImage(i);
|
|
117 item.SetText(filename);
|
|
118 m_listCtrl->InsertItem( item );
|
|
119 m_listCtrl->SetItem( item );
|
|
120
|
|
121 wxImage img( f, wxBITMAP_TYPE_JPEG );
|
3
|
122 wxBitmap bmp( img.Scale( 63, 89, wxIMAGE_QUALITY_HIGH ) );
|
2
|
123 m_imageList->Add( bmp );
|
|
124 cout = dir.GetNext( &filename );
|
|
125 i++;
|
|
126 }
|
|
127
|
|
128 return;
|
|
129 }
|
|
130
|