26 #if defined (HAVE_CONFIG_H)
32 #include <QDialogButtonBox>
33 #include <QDirIterator>
34 #include <QFileDialog>
36 #include <QGridLayout>
38 #include <QHeaderView>
42 #include <QPushButton>
45 #include <QTextStream>
57 :
QDialog (p), m_octave_qobj (oct_qobj)
61 setWindowTitle (tr (
"Find Files"));
62 setWindowIcon (rmgr.
icon (
"edit-find"));
64 m_dir_iterator =
nullptr;
66 m_timer =
new QTimer (
this);
67 connect (m_timer, &QTimer::timeout,
74 m_file_name_edit->setToolTip (tr (
"Enter the filename search expression"));
77 file_name_label->setBuddy (m_file_name_edit);
83 QDir::currentPath ()).toString ());
84 m_start_dir_edit->setToolTip (tr (
"Enter the start directory"));
85 start_dir_label->setBuddy (m_start_dir_edit);
87 m_browse_button =
new QPushButton (tr (
"Browse..."));
88 m_browse_button->setToolTip (tr (
"Browse for start directory"));
89 connect (m_browse_button, &QPushButton::clicked,
92 m_recurse_dirs_check =
new QCheckBox (tr (
"Search subdirectories"));
94 m_recurse_dirs_check->setToolTip (tr (
"Search recursively through directories for matching files"));
96 m_include_dirs_check =
new QCheckBox (tr (
"Include directory names"));
98 m_include_dirs_check->setToolTip (tr (
"Include matching directories in search results"));
100 m_name_case_check =
new QCheckBox (tr (
"Name case insensitive"));
102 m_name_case_check->setToolTip (tr (
"Set matching name is case insensitive"));
104 m_contains_text_check =
new QCheckBox (tr (
"Contains text:"));
105 m_contains_text_check->setToolTip (tr (
"Enter the file content search expression"));
109 m_contains_text_edit->setToolTip (tr (
"Text to match"));
112 m_content_case_check =
new QCheckBox (tr (
"Text case insensitive"));
114 m_content_case_check->setToolTip (tr (
"Set text content is case insensitive"));
119 m_file_list->setWordWrap (
false);
120 m_file_list->setModel (model);
121 m_file_list->setShowGrid (
false);
122 m_file_list->setSelectionBehavior (QAbstractItemView::SelectRows);
123 m_file_list->setSelectionMode (QAbstractItemView::SingleSelection);
124 m_file_list->setAlternatingRowColors (
true);
125 m_file_list->setToolTip (tr (
"Search results"));
126 m_file_list->setSortingEnabled (
true);
128 m_file_list->horizontalHeader ()->setSortIndicatorShown (
true);
129 m_file_list->horizontalHeader ()->setSectionsClickable (
true);
130 m_file_list->horizontalHeader ()->setStretchLastSection (
true);
132 static_cast<Qt::SortOrder
>
137 connect (m_file_list, &QTableView::doubleClicked,
140 m_status_bar =
new QStatusBar;
141 m_status_bar->showMessage (tr (
"Idle."));
144 m_find_button->setToolTip (tr (
"Start search for matching files"));
145 connect (m_find_button, &QPushButton::clicked,
149 m_stop_button->setToolTip (tr (
"Stop searching"));
150 m_stop_button->setEnabled (
false);
151 connect (m_stop_button, &QPushButton::clicked,
155 QDialogButtonBox *button_box =
new QDialogButtonBox (Qt::Vertical);
156 button_box->addButton (m_find_button, QDialogButtonBox::ActionRole);
157 button_box->addButton (m_stop_button, QDialogButtonBox::ActionRole);
160 m_close_button = button_box->addButton (QDialogButtonBox::Close);
161 connect (button_box, &QDialogButtonBox::rejected,
162 this, &find_files_dialog::close);
165 QGroupBox *name_group =
new QGroupBox (tr (
"Filename/location"));
166 QGridLayout *name_layout =
new QGridLayout;
167 name_group->setLayout (name_layout);
169 name_layout->addWidget (file_name_label, 1, 1, 1, 1);
170 name_layout->addWidget (m_file_name_edit, 1, 2, 1, -1);
172 name_layout->addWidget (start_dir_label, 2, 1);
173 name_layout->addWidget (m_start_dir_edit, 2, 2, 1, 3);
174 name_layout->addWidget (m_browse_button, 2, 5);
175 name_layout->setColumnStretch (2, 1);
177 name_layout->addWidget (m_recurse_dirs_check, 3, 1);
178 name_layout->addWidget (m_include_dirs_check, 3, 2);
179 name_layout->addWidget (m_name_case_check, 3, 3);
182 QGroupBox *content_group =
new QGroupBox (tr (
"File contents"));
183 QGridLayout *content_layout =
new QGridLayout;
184 content_group->setLayout (content_layout);
185 content_layout->addWidget (m_contains_text_check, 4, 1);
186 content_layout->addWidget (m_contains_text_edit, 4, 2, 1, 3);
187 content_layout->setColumnStretch (2, 1);
188 content_layout->addWidget (m_content_case_check, 5, 1);
190 QGridLayout *main_layout =
new QGridLayout;
191 main_layout->setSizeConstraint (QLayout::SetFixedSize);
192 main_layout->addWidget (name_group, 0, 0);
193 main_layout->addWidget (content_group, 1, 0);
194 main_layout->addWidget (button_box, 0, 1, 3, 1);
195 main_layout->addWidget (m_file_list, 2, 0);
196 main_layout->setRowStretch (2, 1);
197 main_layout->addWidget (m_status_bar, 3, 0, 1, -1);
199 setLayout (main_layout);
201 connect (
this, &find_files_dialog::finished,
218 int sort_column =
m_file_list->horizontalHeader ()->sortIndicatorSection ();
219 Qt::SortOrder sort_order
220 =
m_file_list->horizontalHeader ()->sortIndicatorOrder ();
253 QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags;
255 flags |= QDirIterator::Subdirectories;
257 QDir::Filters filters = QDir::Dirs | QDir::NoDotAndDotDot | QDir::Files;
259 filters |= QDir::CaseSensitive;
261 QStringList nameFilters;
306 QString res_str = QString (tr (
"%1 match (es)")).arg (
m->rowCount ());
318 opts = QFileDialog::DontUseNativeDialog;
321 QFileDialog::getExistingDirectory (
this, tr (
"Set search directory"),
323 QFileDialog::Option (opts));
325 if (! dir.isEmpty ())
333 QFileInfo info =
m->fileInfo (idx);
335 if (idx.column () == 1)
389 QFile file (info.absoluteFilePath ());
390 if (file.open (QIODevice::ReadOnly))
392 QTextStream
stream (&file);
398 ? Qt::CaseInsensitive
403 line =
stream.readLine ();
404 match = line.contains (match_str, cs);
406 while (! line.isNull () && match ==
false);
Base class for Octave interfaces that use Qt.
resource_manager & get_resource_manager(void)
QPushButton * m_close_button
QCheckBox * m_recurse_dirs_check
QCheckBox * m_include_dirs_check
QPushButton * m_browse_button
virtual ~find_files_dialog(void)
void set_search_dir(const QString &dir)
void item_double_clicked(const QModelIndex &)
bool is_match(const QFileInfo &info)
QCheckBox * m_contains_text_check
QLineEdit * m_contains_text_edit
void look_for_files(void)
void file_selected(const QString &fileName)
QCheckBox * m_name_case_check
QLineEdit * m_file_name_edit
void dir_selected(const QString &fileName)
QPushButton * m_find_button
QStatusBar * m_status_bar
QPushButton * m_stop_button
void browse_folders(void)
QLineEdit * m_start_dir_edit
QDirIterator * m_dir_iterator
base_qobject & m_octave_qobj
QCheckBox * m_content_case_check
gui_settings * get_settings(void) const
QIcon icon(const QString &icon_name, bool octave_only=false, const QString &icon_alt_name=QString())
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
const gui_pref ff_include_dirs("findfiles/include_dirs", QVariant(false))
const gui_pref ff_start_dir("findfiles/start_dir", QVariant(""))
const gui_pref ff_check_text("findfiles/check_text", QVariant(false))
const gui_pref ff_file_name("findfiles/file_name", QVariant("*"))
const gui_pref ff_recurse_dirs("findfiles/recurse_dirs", QVariant(false))
const gui_pref ff_content_case("findfiles/content_case", QVariant(false))
const gui_pref ff_sort_files_by_order("findfiles/sort_files_by_order", QVariant(Qt::AscendingOrder))
const gui_pref ff_column_state("findfiles/column_state", QVariant())
const gui_pref ff_sort_files_by_column("findfiles/sort_files_by_column", QVariant(0))
const gui_pref ff_name_case("findfiles/name_case", QVariant(false))
const gui_pref ff_contains_text("findfiles/contains_text", QVariant(""))
const gui_pref global_use_native_dialogs("use_native_file_dialogs", QVariant(true))