-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearchpage.cpp
More file actions
114 lines (89 loc) · 2.47 KB
/
searchpage.cpp
File metadata and controls
114 lines (89 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "searchpage.h"
SearchPage::SearchPage(QWidget* parent)
: QWidget(parent), m_boxIndx( 0 ), total(0)
{
ui.setupUi(this);
Init();
show();
}
SearchPage::~SearchPage()
{
}
void SearchPage::Init()
{
m_mainLayout = new QGridLayout( this );
this->setLayout( m_mainLayout );
m_comboBox = new QComboBox( this );
m_comboBox->setFixedWidth( 40 );
connect(m_comboBox, SIGNAL(currentIndexChanged(int)), SLOT(BoxIndxChanged(int)) );
m_mainLayout->addWidget( m_comboBox, 0, 0 );
AddDisks();
m_pushButton = new QPushButton( "Searh" );
m_pushButton->setFixedWidth( 50 );
m_mainLayout->addWidget( m_pushButton, 0, 1 );
connect( m_pushButton, SIGNAL(clicked()), SLOT(Searching()) );
m_scrollArea = new QScrollArea;
m_mainLayout->addWidget( m_scrollArea, 1, 0, 1, 5 );
m_listWidget = new QListWidget;
m_scrollArea->setWidget( m_listWidget );
m_scrollArea->setWidgetResizable( true );
m_scrollArea->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
}
void SearchPage::AddDisks()
{
char buf[26];
GetLogicalDriveStringsA( sizeof(buf), buf );
// { "Unknown" , "Invalid path", "Removable", "Fixed" , "Network drive","CD-ROM", "RAM disk" };
for (char* s = buf; *s; s += strlen(s) + 1)
{
unsigned int type = GetDriveTypeA(s);
if (type == 2 || type == 3 || type == 3 || type == 5)
m_comboBox->addItem( s );
}
}
void SearchPage::BoxIndxChanged( int indx )
{
m_boxIndx = indx;
}
void SearchPage::Searching()
{
char dir[10];
char mask[] = "*.txt";
sprintf( dir, "%s", m_comboBox->itemText( m_boxIndx ).toStdString().c_str(), dir );
FindFile( dir, mask );
}
void SearchPage::FindFile( char *path, char *mask )
{
WIN32_FIND_DATAA finddata;
HANDLE hFind;
char _path[MAX_PATH], name[MAX_PATH];
sprintf(_path, "%s\\%s", path, mask);
hFind = FindFirstFileA(_path, &finddata);
if (hFind != INVALID_HANDLE_VALUE)
{
do
{
sprintf(name, "%s\\%s", path, finddata.cFileName);
m_listWidget->addItem( QString(name) );
m_listWidget->update();
total++;
} while (FindNextFileA(hFind, &finddata));
}
FindClose(hFind);
sprintf( _path, "%s\\*", path );
hFind = FindFirstFileA(_path, &finddata);
if (hFind != INVALID_HANDLE_VALUE)
{
do
{
if (!strcmp(finddata.cFileName, "..") || !strcmp(finddata.cFileName, ".")) continue;
if ((finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
sprintf(_path, "%s\\%s", path, finddata.cFileName);
FindFile(_path, mask);
}
}
while (FindNextFileA(hFind, &finddata));
}
FindClose(hFind);
}