Add switch search method.
This commit is contained in:
parent
ffb51b9d17
commit
fd9a19ecae
|
@ -27,6 +27,22 @@
|
||||||
|
|
||||||
FirstIndex::FirstIndex(const QString& path) : Traverse_BFS(path)
|
FirstIndex::FirstIndex(const QString& path) : Traverse_BFS(path)
|
||||||
{
|
{
|
||||||
|
// Create a fifo at ~/.config/org.ukui/ukui-search, the fifo is used to control the order of child processes' running.
|
||||||
|
QDir fifoDir = QDir(QDir::homePath()+"/.config/org.ukui/ukui-search");
|
||||||
|
if(!fifoDir.exists())
|
||||||
|
qDebug()<<"create fifo path"<<fifoDir.mkpath(fifoDir.absolutePath());
|
||||||
|
|
||||||
|
unlink(UKUI_SEARCH_PIPE_PATH);
|
||||||
|
int retval = mkfifo(UKUI_SEARCH_PIPE_PATH, 0777);
|
||||||
|
if(retval == -1)
|
||||||
|
{
|
||||||
|
qCritical()<<"creat fifo error!!";
|
||||||
|
syslog(LOG_ERR,"creat fifo error!!\n");
|
||||||
|
assert(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
qDebug()<<"create fifo success\n";
|
||||||
|
|
||||||
QString indexDataBaseStatus = GlobalSettings::getInstance()->getValue(INDEX_DATABASE_STATE).toString();
|
QString indexDataBaseStatus = GlobalSettings::getInstance()->getValue(INDEX_DATABASE_STATE).toString();
|
||||||
QString contentIndexDataBaseStatus = GlobalSettings::getInstance()->getValue(CONTENT_INDEX_DATABASE_STATE).toString();
|
QString contentIndexDataBaseStatus = GlobalSettings::getInstance()->getValue(CONTENT_INDEX_DATABASE_STATE).toString();
|
||||||
QString inotifyIndexStatus = GlobalSettings::getInstance()->getValue(INOTIFY_NORMAL_EXIT).toString();
|
QString inotifyIndexStatus = GlobalSettings::getInstance()->getValue(INOTIFY_NORMAL_EXIT).toString();
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <sys/prctl.h>
|
#include <sys/prctl.h>
|
||||||
|
#include <syslog.h>
|
||||||
//#include <QtConcurrent>
|
//#include <QtConcurrent>
|
||||||
#include "traverse_bfs.h"
|
#include "traverse_bfs.h"
|
||||||
#include "global-settings.h"
|
#include "global-settings.h"
|
||||||
|
|
|
@ -256,8 +256,8 @@ void InotifyIndex::run(){
|
||||||
|
|
||||||
ssize_t numRead;
|
ssize_t numRead;
|
||||||
|
|
||||||
for (;;) { /* Read events forever */
|
while (!isInterruptionRequested()) {
|
||||||
read:
|
// for (;;) { /* Read events forever */
|
||||||
memset(buf, 0x00, BUF_LEN);
|
memset(buf, 0x00, BUF_LEN);
|
||||||
numRead = read(m_fd, buf, BUF_LEN);
|
numRead = read(m_fd, buf, BUF_LEN);
|
||||||
|
|
||||||
|
@ -276,14 +276,14 @@ read:
|
||||||
// qDebug() << "Read Event: " << currentPath[event->wd] << QString(event->name) << event->cookie << event->wd << event->mask;
|
// qDebug() << "Read Event: " << currentPath[event->wd] << QString(event->name) << event->cookie << event->wd << event->mask;
|
||||||
if(event->name[0] != '.'){
|
if(event->name[0] != '.'){
|
||||||
GlobalSettings::getInstance()->setValue(INOTIFY_NORMAL_EXIT, "0");
|
GlobalSettings::getInstance()->setValue(INOTIFY_NORMAL_EXIT, "0");
|
||||||
goto fork;
|
break;
|
||||||
}
|
}
|
||||||
tmp += sizeof(struct inotify_event) + event->len;
|
tmp += sizeof(struct inotify_event) + event->len;
|
||||||
|
|
||||||
}
|
}
|
||||||
goto read;
|
if (tmp >= buf + numRead) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
fork:
|
|
||||||
++FileUtils::_index_status;
|
++FileUtils::_index_status;
|
||||||
|
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
21
src/main.cpp
21
src/main.cpp
|
@ -118,6 +118,23 @@ void centerToScreen(QWidget* widget) {
|
||||||
widget->move(desk_x / 2 - x / 2 + desk_rect.left(), desk_y / 2 - y / 2 + desk_rect.top());
|
widget->move(desk_x / 2 - x / 2 + desk_rect.left(), desk_y / 2 - y / 2 + desk_rect.top());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void searchMethod(FileUtils::SearchMethod sm){
|
||||||
|
if (FileUtils::SearchMethod::INDEXSEARCH == sm || FileUtils::SearchMethod::DIRECTSEARCH == sm){
|
||||||
|
FileUtils::searchMethod = sm;
|
||||||
|
} else {
|
||||||
|
printf("enum class error!!!\n");
|
||||||
|
qWarning("enum class error!!!\n");
|
||||||
|
}
|
||||||
|
if (FileUtils::SearchMethod::INDEXSEARCH == sm) {
|
||||||
|
FirstIndex fi("/home/zhangzihao/Desktop");
|
||||||
|
fi.start();
|
||||||
|
InotifyIndex* ii = InotifyIndex::getInstance("/home");
|
||||||
|
ii->start();
|
||||||
|
} else if (FileUtils::SearchMethod::DIRECTSEARCH == sm) {
|
||||||
|
InotifyIndex::getInstance("/home")->requestInterruption();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
// Determine whether the home directory has been created, and if not, keep waiting.
|
// Determine whether the home directory has been created, and if not, keep waiting.
|
||||||
|
@ -178,7 +195,7 @@ int main(int argc, char *argv[])
|
||||||
parser.addOptions({debugOption, showsearch});
|
parser.addOptions({debugOption, showsearch});
|
||||||
parser.process(app);
|
parser.process(app);
|
||||||
}*/
|
}*/
|
||||||
|
/*
|
||||||
// Create a fifo at ~/.config/org.ukui/ukui-search, the fifo is used to control the order of child processes' running.
|
// Create a fifo at ~/.config/org.ukui/ukui-search, the fifo is used to control the order of child processes' running.
|
||||||
QDir fifoDir = QDir(QDir::homePath()+"/.config/org.ukui/ukui-search");
|
QDir fifoDir = QDir(QDir::homePath()+"/.config/org.ukui/ukui-search");
|
||||||
if(!fifoDir.exists())
|
if(!fifoDir.exists())
|
||||||
|
@ -194,7 +211,7 @@ int main(int argc, char *argv[])
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
qDebug()<<"create fifo success\n";
|
qDebug()<<"create fifo success\n";
|
||||||
|
*/
|
||||||
// Set max_user_watches to a number which is enough big.
|
// Set max_user_watches to a number which is enough big.
|
||||||
UkuiSearchQDBus usQDBus;
|
UkuiSearchQDBus usQDBus;
|
||||||
usQDBus.setInotifyMaxUserWatches();
|
usQDBus.setInotifyMaxUserWatches();
|
||||||
|
|
Loading…
Reference in New Issue