Add system tray icon.

This commit is contained in:
zhangpengfei 2021-01-13 18:35:48 +08:00
parent b225dfa49e
commit d7ff0e2a31
6 changed files with 27 additions and 2 deletions

View File

@ -12,6 +12,7 @@
#include <QQueue> #include <QQueue>
size_t FileUtils::_max_index_count = 0; size_t FileUtils::_max_index_count = 0;
size_t FileUtils::_current_index_count = 0; size_t FileUtils::_current_index_count = 0;
unsigned short FileUtils::_index_status = INITIAL_STATE;
QMap<QString, QStringList> FileUtils::map_chinese2pinyin = QMap<QString, QStringList>(); QMap<QString, QStringList> FileUtils::map_chinese2pinyin = QMap<QString, QStringList>();
FileUtils::FileUtils() FileUtils::FileUtils()

View File

@ -6,6 +6,9 @@
#include <QIcon> #include <QIcon>
#include <QMap> #include <QMap>
#include "libsearch_global.h" #include "libsearch_global.h"
#define INITIAL_STATE 0
#define CREATING_INDEX 1
#define FINISH_CREATING_INDEX 2
class LIBSEARCH_EXPORT FileUtils class LIBSEARCH_EXPORT FileUtils
{ {
@ -31,6 +34,7 @@ public:
static void getTxtContent(QString &path, QString &textcontent); static void getTxtContent(QString &path, QString &textcontent);
static size_t _max_index_count; static size_t _max_index_count;
static size_t _current_index_count; static size_t _current_index_count;
static unsigned short _index_status;
private: private:
FileUtils(); FileUtils();

View File

@ -75,6 +75,7 @@ bool IndexGenerator::creatAllIndex(QQueue<QVector<QString> > *messageList)
//文件内容索引 //文件内容索引
bool IndexGenerator::creatAllIndex(QQueue<QString> *messageList) bool IndexGenerator::creatAllIndex(QQueue<QString> *messageList)
{ {
FileUtils::_index_status = CREATING_INDEX;
HandlePathList(messageList); HandlePathList(messageList);
try try
{ {
@ -99,6 +100,7 @@ bool IndexGenerator::creatAllIndex(QQueue<QString> *messageList)
} }
m_doc_list_content->clear(); m_doc_list_content->clear();
Q_EMIT this->transactionFinished(); Q_EMIT this->transactionFinished();
FileUtils::_index_status = FINISH_CREATING_INDEX;
return true; return true;
} }
@ -359,7 +361,9 @@ bool IndexGenerator::deleteAllIndex(QStringList *pathlist)
qDebug()<<"delete path"<<doc; qDebug()<<"delete path"<<doc;
qDebug()<<"delete md5"<<QString::fromStdString(uniqueterm); qDebug()<<"delete md5"<<QString::fromStdString(uniqueterm);
m_datebase_path->commit(); m_datebase_path->commit();
FileUtils::_current_index_count -= 1;
FileUtils::_current_index_count = m_datebase_path->get_doccount();
qDebug()<< "--delete finish--"; qDebug()<< "--delete finish--";
} }
catch(const Xapian::Error &e) catch(const Xapian::Error &e)

View File

@ -99,6 +99,20 @@ MainWindow::MainWindow(QWidget *parent) :
connect(m_search_result_thread, &SearchResult::searchResultContent, this, [ = ](QPair<QString, QStringList> pair) { connect(m_search_result_thread, &SearchResult::searchResultContent, this, [ = ](QPair<QString, QStringList> pair) {
m_contentFrame->appendSearchItem(SearchItem::SearchType::Contents, pair.first, m_searchLayout->text(), pair.second); m_contentFrame->appendSearchItem(SearchItem::SearchType::Contents, pair.first, m_searchLayout->text(), pair.second);
}); });
m_sys_tray_icon = new QSystemTrayIcon(this);
m_sys_tray_icon->setIcon(QIcon::fromTheme("system-search-symbolic"));
m_sys_tray_icon->setToolTip(tr("Global Search"));
m_sys_tray_icon->show();
connect(m_sys_tray_icon,&QSystemTrayIcon::activated,this,[=](QSystemTrayIcon::ActivationReason reason){
if(reason == QSystemTrayIcon::Trigger)
{
clearSearchResult();
this->show();
this->raise();
this->activateWindow();
}
});
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()

View File

@ -37,6 +37,7 @@
#include <QFrame> #include <QFrame>
#include <QPushButton> #include <QPushButton>
#include <QGSettings/QGSettings> #include <QGSettings/QGSettings>
#include <QSystemTrayIcon>
#include "content-widget.h" #include "content-widget.h"
#include "input-box.h" #include "input-box.h"
#include "index/index-generator.h" #include "index/index-generator.h"
@ -90,6 +91,7 @@ private:
SearchResult * m_search_result_thread = nullptr; SearchResult * m_search_result_thread = nullptr;
FileSearcher* m_searcher = nullptr; FileSearcher* m_searcher = nullptr;
QSystemTrayIcon *m_sys_tray_icon;
protected: protected:
void paintEvent(QPaintEvent *); void paintEvent(QPaintEvent *);

View File

@ -43,7 +43,7 @@ void SearchResult::run()
m_mainwindow->m_searcher->m_mutex2.unlock(); m_mainwindow->m_searcher->m_mutex2.unlock();
} }
m_mainwindow->m_searcher->m_mutex3.lock(); m_mainwindow->m_searcher->m_mutex3.lock();
if (!m_mainwindow->m_search_result_content->isEmpty()) // if (!m_mainwindow->m_search_result_content->isEmpty())
// qDebug() << m_mainwindow->m_search_result_content->head(); // qDebug() << m_mainwindow->m_search_result_content->head();
if (!m_mainwindow->m_search_result_content->isEmpty()) { if (!m_mainwindow->m_search_result_content->isEmpty()) {
Q_EMIT this->searchResultContent(m_mainwindow->m_search_result_content->dequeue()); Q_EMIT this->searchResultContent(m_mainwindow->m_search_result_content->dequeue());