2021-01-29 11:43:07 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020, KylinSoft Co., Ltd.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Authors: zhangpengfei <zhangpengfei@kylinos.cn>
|
|
|
|
* Modified by: zhangzihao <zhangzihao@kylinos.cn>
|
|
|
|
* Modified by: zhangjiaping <zhangjiaping@kylinos.cn>
|
|
|
|
*
|
|
|
|
*/
|
2020-12-21 18:50:54 +08:00
|
|
|
#ifndef FILEUTILS_H
|
|
|
|
#define FILEUTILS_H
|
|
|
|
#include <QString>
|
|
|
|
#include <QCryptographicHash>
|
2020-12-24 11:06:19 +08:00
|
|
|
#include <QIcon>
|
2020-12-26 12:45:28 +08:00
|
|
|
#include <QMap>
|
2021-03-04 14:10:00 +08:00
|
|
|
#include <QMimeDatabase>
|
|
|
|
#include <QMimeType>
|
2021-03-13 14:52:20 +08:00
|
|
|
#include <QDir>
|
2021-04-16 11:20:14 +08:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QMap>
|
|
|
|
#include <QQueue>
|
2021-05-27 21:10:11 +08:00
|
|
|
#include <QDesktopServices>
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QClipboard>
|
2021-08-06 17:45:28 +08:00
|
|
|
#include <QFontMetrics>
|
2021-08-26 11:22:10 +08:00
|
|
|
#include <QLabel>
|
2021-04-16 11:20:14 +08:00
|
|
|
|
2022-03-01 17:39:53 +08:00
|
|
|
#include <quazip5/quazipfile.h>
|
2021-04-16 11:20:14 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2022-03-01 17:39:53 +08:00
|
|
|
#include <quazip5/quazip.h>
|
2021-04-16 11:20:14 +08:00
|
|
|
#include <uchardet/uchardet.h>
|
|
|
|
//#include <poppler-qt5.h>
|
|
|
|
#include <poppler/qt5/poppler-qt5.h>
|
2021-04-15 09:19:36 +08:00
|
|
|
|
2020-12-30 14:42:04 +08:00
|
|
|
#include "libsearch_global.h"
|
2021-08-06 17:45:28 +08:00
|
|
|
#include "common.h"
|
2022-04-13 13:46:30 +08:00
|
|
|
#include <leptonica/allheaders.h>
|
|
|
|
|
2021-01-22 17:15:43 +08:00
|
|
|
//#define INITIAL_STATE 0
|
|
|
|
//#define CREATING_INDEX 1
|
|
|
|
//#define FINISH_CREATING_INDEX 2
|
2021-04-08 16:11:58 +08:00
|
|
|
#define MAX_CONTENT_LENGTH 20480000
|
2021-12-14 14:43:35 +08:00
|
|
|
namespace UkuiSearch {
|
2021-04-26 15:06:47 +08:00
|
|
|
class LIBSEARCH_EXPORT FileUtils {
|
2020-12-21 18:50:54 +08:00
|
|
|
public:
|
2021-12-17 17:39:37 +08:00
|
|
|
static QString getHtmlText(const QString &text, const QString &keyword);
|
|
|
|
static QString setAllTextBold(const QString &name);
|
2021-08-26 11:22:10 +08:00
|
|
|
static QString wrapData(QLabel *p_label, const QString &text);
|
2021-12-17 17:39:37 +08:00
|
|
|
static std::string makeDocUterm(QString path);
|
|
|
|
static QIcon getFileIcon(const QString &uri, bool checkValid = true);
|
|
|
|
static QIcon getAppIcon(const QString &path);
|
|
|
|
static QIcon getSettingIcon(const QString &setting, const bool is_white);
|
2021-11-30 17:21:06 +08:00
|
|
|
static QIcon getSettingIcon();
|
2020-12-24 11:06:19 +08:00
|
|
|
|
2021-12-17 17:39:37 +08:00
|
|
|
static QString getFileName(const QString &uri);
|
|
|
|
static QString getAppName(const QString &path);
|
|
|
|
static QString getSettingName(const QString &setting);
|
2021-07-06 16:53:32 +08:00
|
|
|
//A is or under B
|
|
|
|
static bool isOrUnder(QString pathA, QString pathB);
|
2020-12-26 12:45:28 +08:00
|
|
|
|
|
|
|
//chinese character to pinyin
|
2020-12-29 20:18:36 +08:00
|
|
|
static QMap<QString, QStringList> map_chinese2pinyin;
|
2021-12-17 17:39:37 +08:00
|
|
|
static QString find(const QString &hanzi);
|
|
|
|
static QStringList findMultiToneWords(const QString &hanzi);
|
|
|
|
static void loadHanziTable(const QString &fileName);
|
2020-12-26 12:45:28 +08:00
|
|
|
|
2020-12-29 20:18:36 +08:00
|
|
|
//parse text,docx.....
|
2021-03-04 14:10:00 +08:00
|
|
|
static QMimeType getMimetype(QString &path);
|
2021-01-12 16:07:50 +08:00
|
|
|
static void getDocxTextContent(QString &path, QString &textcontent);
|
2021-04-08 16:11:58 +08:00
|
|
|
static void getPptxTextContent(QString &path, QString &textcontent);
|
2021-04-13 14:53:55 +08:00
|
|
|
static void getXlsxTextContent(QString &path, QString &textcontent);
|
2021-04-15 09:19:36 +08:00
|
|
|
static void getPdfTextContent(QString &path, QString &textcontent);
|
2021-01-12 16:07:50 +08:00
|
|
|
static void getTxtContent(QString &path, QString &textcontent);
|
2022-05-27 16:07:09 +08:00
|
|
|
static void getUOFTextContent(QString &path, QString &textContent);
|
|
|
|
static void getUOF2TextContent(QString &path, QString &textContent);
|
2022-05-11 09:08:23 +08:00
|
|
|
static void getUOF2PPTContent(QString &path, QString &textContent);
|
2022-05-27 16:07:09 +08:00
|
|
|
static void getOFDTextContent(QString &path, QString &textContent);
|
2021-05-27 21:10:11 +08:00
|
|
|
|
2021-09-23 10:31:13 +08:00
|
|
|
static int openFile(QString &path, bool openInDir = false);
|
2021-05-27 21:10:11 +08:00
|
|
|
static bool copyPath(QString &path);
|
2021-12-17 17:39:37 +08:00
|
|
|
static QString escapeHtml(const QString &str);
|
2021-08-06 17:45:28 +08:00
|
|
|
static QString chineseSubString(const std::string &myStr,int start,int length);
|
2021-12-17 17:39:37 +08:00
|
|
|
static QIcon iconFromTheme(const QString &name, const QIcon &iconDefault);
|
2021-10-26 14:20:58 +08:00
|
|
|
static bool isOpenXMLFileEncrypted(QString &path);
|
2021-10-27 15:16:43 +08:00
|
|
|
static bool isEncrypedOrUnreadable(QString path);
|
2022-04-13 13:46:30 +08:00
|
|
|
static bool isOcrSupportSize(QString path);
|
2022-03-17 15:40:55 +08:00
|
|
|
static size_t maxIndexCount;
|
2021-11-09 10:07:41 +08:00
|
|
|
static unsigned short indexStatus;
|
2020-12-29 20:18:36 +08:00
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
enum class SearchMethod { DIRECTSEARCH = 0, INDEXSEARCH = 1};
|
2021-04-16 15:35:54 +08:00
|
|
|
static SearchMethod searchMethod;
|
2021-04-16 11:20:14 +08:00
|
|
|
|
2022-05-09 14:47:40 +08:00
|
|
|
private:
|
|
|
|
static void findNodes(const QDomElement &elem, QQueue<QString> &names, QList<QDomElement> &nodes);
|
|
|
|
static inline void findNodesByAttr(const QDomElement&, QQueue<QString>&, QList<QDomElement>&, const QString &, const QStringList&);
|
|
|
|
static inline bool findNodeText(const QDomElement &elem, QQueue<QString> &names, QString &content);
|
|
|
|
static inline void findNodeAttr(const QDomElement &elem, QQueue<QString> &names, const QString &attr, QStringList &attrs);
|
|
|
|
static void processUOFPPT(const QDomDocument &doc, QString &content);
|
2022-05-11 09:08:23 +08:00
|
|
|
static inline bool loadZipFileToDoc(QuaZip &zipFile, QDomDocument &doc, const QString &fileName);
|
2022-05-09 14:47:40 +08:00
|
|
|
|
2020-12-21 18:50:54 +08:00
|
|
|
private:
|
|
|
|
FileUtils();
|
|
|
|
};
|
|
|
|
|
2021-04-30 16:28:50 +08:00
|
|
|
}
|
|
|
|
|
2020-12-21 18:50:54 +08:00
|
|
|
#endif // FILEUTILS_H
|