27 #include <QPushButton>
28 #include <QDialogButtonBox>
29 #include <QGridLayout>
34 #include <QHeaderView>
36 #include <QFileDialog>
41 #include <QDirIterator>
42 #include <QTextStream>
52 setWindowTitle (tr (
"Find Files"));
53 setWindowIcon (QIcon (
":/actions/icons/search.png"));
57 _timer =
new QTimer (
this);
62 QLabel * file_name_label =
new QLabel (tr (
"Named:"));
70 QLabel * start_dir_label =
new QLabel (tr (
"Start in:"));
74 QDir::currentPath ()).toString ());
86 tr (
"Search recursively through directories for matching files"));
92 tr (
"Include matching directories in search results"));
120 _file_list->setSelectionBehavior (QAbstractItemView::SelectRows);
121 _file_list->setSelectionMode (QAbstractItemView::SingleSelection);
123 _file_list->setToolTip (tr (
"Search results"));
125 _file_list->horizontalHeader ()->restoreState (
126 settings->value (
"findfiles/column_state").toByteArray ());
127 _file_list->horizontalHeader ()->setSortIndicatorShown (
true);
128 _file_list->horizontalHeader ()->setClickable (
true);
129 _file_list->horizontalHeader ()->setStretchLastSection (
true);
131 settings->value (
"findfiles/sort_files_by_column",0).toInt (),
132 static_cast<Qt::SortOrder
>
133 (settings->value (
"findfiles/sort_files_by_order",
134 Qt::AscendingOrder).toUInt ()));
136 connect (
_file_list, SIGNAL (doubleClicked (
const QModelIndex&)),
143 _find_button->setToolTip (tr (
"Start search for matching files"));
152 QDialogButtonBox * button_box =
new QDialogButtonBox (Qt::Vertical);
153 button_box->addButton (
_find_button, QDialogButtonBox::ActionRole);
154 button_box->addButton (
_stop_button, QDialogButtonBox::ActionRole);
157 _close_button = button_box->addButton (QDialogButtonBox::Close);
158 connect (button_box, SIGNAL (rejected ()),
159 this, SLOT (close ()));
162 QGroupBox * name_group =
new QGroupBox (tr (
"File name/location"));
163 QGridLayout * name_layout =
new QGridLayout;
164 name_group->setLayout (name_layout);
166 name_layout->addWidget (file_name_label,1,1, 1,1);
169 name_layout->addWidget (start_dir_label,2,1);
172 name_layout->setColumnStretch (2,1);
179 QGroupBox * content_group =
new QGroupBox (tr (
"File contents"));
180 QGridLayout * content_layout =
new QGridLayout;
181 content_group->setLayout (content_layout);
184 content_layout->setColumnStretch (2,1);
187 QGridLayout *main_layout =
new QGridLayout;
188 main_layout->setSizeConstraint (QLayout::SetFixedSize);
189 main_layout->addWidget (name_group, 0, 0);
190 main_layout->addWidget (content_group, 1, 0);
191 main_layout->addWidget (button_box, 0, 1,3,1);
193 main_layout->setRowStretch (2,1);
197 setLayout (main_layout);
199 connect (
this, SIGNAL (finished (
int)),
this, SLOT (
handle_done (
int)));
206 int sort_column =
_file_list->horizontalHeader ()->sortIndicatorSection ();
207 Qt::SortOrder sort_order
208 =
_file_list->horizontalHeader ()->sortIndicatorOrder ();
209 settings->setValue (
"findfiles/sort_files_by_column", sort_column);
210 settings->setValue (
"findfiles/sort_files_by_order", sort_order);
211 settings->setValue (
"findfiles/column_state",
212 _file_list->horizontalHeader ()->saveState ());
223 settings->setValue (
"findfiles/check_text",
225 settings->setValue (
"findfiles/content_case",
254 QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags;
256 flags |= QDirIterator::Subdirectories;
258 QDir::Filters filters = QDir::Dirs|QDir::NoDotAndDotDot|QDir::Files;
260 filters |= QDir::CaseSensitive;
262 QStringList nameFilters;
307 QString res_str = QString (
"%1 matches").arg (m->
rowCount ());
316 QFileDialog::getExistingDirectory (
this, tr (
"Set search directory"),
319 if (! dir.isEmpty ())
332 if (idx.column () == 1)
381 QFile file (info.absoluteFilePath ());
382 if (file.open (QIODevice::ReadOnly))
384 QTextStream stream (&file);
390 Qt::CaseInsensitive : Qt::CaseSensitive;
394 line = stream.readLine ();
395 match = line.contains (match_str, cs);
397 while (!line.isNull () && match ==
false);