2021-05-22 21:29:43 +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: zhangjiaping <zhangjiaping@kylinos.cn>
|
|
|
|
|
* Modified by: zhangpengfei <zhangpengfei@kylinos.cn>
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "mainwindow.h"
|
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QDesktopWidget>
|
|
|
|
|
#include <syslog.h>
|
|
|
|
|
#include <QPalette>
|
|
|
|
|
#include <QScreen>
|
|
|
|
|
#include <QStyleOption>
|
|
|
|
|
#include <QPixmap>
|
|
|
|
|
#include <KWindowEffects>
|
2022-06-27 09:30:22 +08:00
|
|
|
|
#include <KWindowSystem>
|
2021-08-18 14:23:14 +08:00
|
|
|
|
#include <QtX11Extras/QX11Info>
|
2023-09-19 15:40:13 +08:00
|
|
|
|
#include <gperftools/malloc_extension.h>
|
2022-06-27 09:30:22 +08:00
|
|
|
|
#include "ukuistylehelper/ukuistylehelper.h"
|
|
|
|
|
#include "windowmanager/windowmanager.h"
|
|
|
|
|
#include "global-settings.h"
|
2022-11-02 20:50:30 +08:00
|
|
|
|
#include "action-transmiter.h"
|
2023-09-01 17:30:21 +08:00
|
|
|
|
#include "icon-loader.h"
|
2021-05-22 21:29:43 +08:00
|
|
|
|
|
2021-07-21 17:01:34 +08:00
|
|
|
|
#define MAIN_MARGINS 0, 0, 0, 0
|
2021-05-22 21:29:43 +08:00
|
|
|
|
#define TITLE_MARGINS 0,0,0,0
|
2021-07-21 17:01:34 +08:00
|
|
|
|
#define WINDOW_WIDTH 700
|
|
|
|
|
#define WINDOW_HEIGHT 610
|
2021-05-22 21:29:43 +08:00
|
|
|
|
#define TITLE_HEIGHT 40
|
|
|
|
|
#define WINDOW_ICON_SIZE 24
|
|
|
|
|
#define SETTING_BTN_SIZE 30
|
2021-07-05 14:27:14 +08:00
|
|
|
|
#define SEARCH_BAR_SIZE 48
|
2021-05-22 21:29:43 +08:00
|
|
|
|
#define ASK_INDEX_TIME 5*1000
|
|
|
|
|
#define RESEARCH_TIME 10*1000
|
|
|
|
|
|
2022-11-28 18:11:55 +08:00
|
|
|
|
#define MAIN_SETTINGS QDir::homePath() + "/.config/org.ukui/ukui-search/ukui-search.conf"
|
|
|
|
|
#define ENABLE_CREATE_INDEX_ASK_DIALOG "enable_create_index_ask_dialog"
|
2023-05-31 17:59:20 +08:00
|
|
|
|
const static QString FILE_INDEX_ENABLE_KEY = "fileIndexEnable";
|
2022-11-28 18:11:55 +08:00
|
|
|
|
|
2021-12-14 14:43:35 +08:00
|
|
|
|
using namespace UkuiSearch;
|
2021-05-22 21:29:43 +08:00
|
|
|
|
extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed);
|
|
|
|
|
/**
|
|
|
|
|
* @brief MainWindow 主界面
|
|
|
|
|
* @param parent
|
|
|
|
|
*
|
|
|
|
|
* 慎用KWindowSystem::setShowingDesktop(!KWindowSystem::showingDesktop());
|
|
|
|
|
* 可能造成窗口属性的混乱
|
|
|
|
|
*/
|
|
|
|
|
MainWindow::MainWindow(QWidget *parent) :
|
|
|
|
|
QMainWindow(parent) {
|
|
|
|
|
this->setAttribute(Qt::WA_TranslucentBackground, true);
|
2021-07-21 17:01:34 +08:00
|
|
|
|
this->setWindowFlag(Qt::FramelessWindowHint);
|
2021-05-22 21:29:43 +08:00
|
|
|
|
this->setAutoFillBackground(false);
|
|
|
|
|
this->setFocusPolicy(Qt::StrongFocus);
|
|
|
|
|
this->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
|
|
|
|
this->setWindowTitle(tr("ukui-search"));
|
2022-03-23 15:44:37 +08:00
|
|
|
|
KWindowSystem::setState(this->winId(),NET::SkipTaskbar | NET::SkipPager | NET::SkipSwitcher );
|
2022-11-28 18:11:55 +08:00
|
|
|
|
initSettings();
|
2021-05-22 21:29:43 +08:00
|
|
|
|
initUi();
|
|
|
|
|
initTimer();
|
|
|
|
|
|
|
|
|
|
m_sys_tray_icon = new QSystemTrayIcon(this);
|
2023-10-10 16:16:02 +08:00
|
|
|
|
m_menu = new QMenu(this);
|
|
|
|
|
m_menu->addAction(IconLoader::loadIconQt("document-page-setup-symbolic", QIcon(":/res/icons/document-page-setup-symbolic.svg")), tr("Search Settings"), this, SLOT(openSearchSettings()));
|
|
|
|
|
m_sys_tray_icon->setContextMenu(m_menu);
|
2023-09-01 17:30:21 +08:00
|
|
|
|
m_sys_tray_icon->setIcon(IconLoader::loadIconQt("system-search-symbolic", QIcon(":/res/icons/edit-find-symbolic.svg")));
|
2021-05-22 21:29:43 +08:00
|
|
|
|
m_sys_tray_icon->setToolTip(tr("Global Search"));
|
|
|
|
|
m_sys_tray_icon->show();
|
|
|
|
|
installEventFilter(this);
|
|
|
|
|
initConnections();
|
2022-11-28 18:11:55 +08:00
|
|
|
|
|
2022-07-13 14:53:23 +08:00
|
|
|
|
// connect(KWindowSystem::self(), &KWindowSystem::activeWindowChanged, this,[&](WId activeWindowId){
|
|
|
|
|
// qDebug() << "activeWindowChanged!!!" << activeWindowId;
|
|
|
|
|
// if (activeWindowId != this->winId()) {
|
|
|
|
|
// tryHideMainwindow();
|
|
|
|
|
// }
|
|
|
|
|
// });
|
2022-01-04 16:53:52 +08:00
|
|
|
|
|
2022-09-09 11:01:13 +08:00
|
|
|
|
m_appWidgetPlugin = new AppWidgetPlugin;
|
|
|
|
|
|
2023-01-03 09:20:54 +08:00
|
|
|
|
// connect(m_appWidgetPlugin, &AppWidgetPlugin::startSearch, this, [ & ] (QString keyword){
|
|
|
|
|
// this->bootOptionsFilter("-s");
|
|
|
|
|
// this->setText(keyword);
|
|
|
|
|
// });
|
|
|
|
|
connect(m_appWidgetPlugin, &AppWidgetPlugin::start, this, [&] {
|
2022-09-09 11:01:13 +08:00
|
|
|
|
this->bootOptionsFilter("-s");
|
|
|
|
|
});
|
2022-11-02 20:50:30 +08:00
|
|
|
|
connect(ActionTransmiter::getInstance(), &ActionTransmiter::hideUIAction, this, &MainWindow::tryHideMainwindow);
|
2021-05-22 21:29:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MainWindow::~MainWindow() {
|
|
|
|
|
if(m_askDialog) {
|
|
|
|
|
delete m_askDialog;
|
|
|
|
|
m_askDialog = NULL;
|
|
|
|
|
}
|
2023-04-24 17:36:37 +08:00
|
|
|
|
// if(m_askTimer) {
|
|
|
|
|
// delete m_askTimer;
|
|
|
|
|
// m_askTimer = NULL;
|
|
|
|
|
// }
|
2022-11-28 18:11:55 +08:00
|
|
|
|
if(m_searchGsettings) {
|
|
|
|
|
delete m_searchGsettings;
|
|
|
|
|
m_searchGsettings = NULL;
|
2021-05-22 21:29:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief initUi 初始化主界面主要ui控件
|
|
|
|
|
*/
|
|
|
|
|
void MainWindow::initUi() {
|
2021-07-26 15:08:46 +08:00
|
|
|
|
this->setFixedSize(WINDOW_WIDTH, 68);
|
2021-05-22 21:29:43 +08:00
|
|
|
|
|
2021-07-26 15:08:46 +08:00
|
|
|
|
m_searchBarWidget = new SeachBarWidget(this);
|
|
|
|
|
m_searchBarWidget->move(this->rect().topLeft());
|
2021-07-23 16:10:30 +08:00
|
|
|
|
m_searchBarWidget->show();
|
2021-07-26 15:08:46 +08:00
|
|
|
|
m_searchResultPage = new SearchResultPage(this);
|
|
|
|
|
m_searchResultPage->hide();
|
2021-07-23 16:10:30 +08:00
|
|
|
|
m_searchResultPage->move(0, 58);
|
2021-09-16 14:58:07 +08:00
|
|
|
|
this->setFocusProxy(m_searchBarWidget);
|
2021-08-18 14:23:14 +08:00
|
|
|
|
|
2021-05-22 21:29:43 +08:00
|
|
|
|
//创建索引询问弹窗
|
|
|
|
|
m_askDialog = new CreateIndexAskDialog(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::initConnections()
|
|
|
|
|
{
|
|
|
|
|
connect(m_sys_tray_icon, &QSystemTrayIcon::activated, this, &MainWindow::trayIconActivatedSlot);
|
2023-03-23 10:00:43 +08:00
|
|
|
|
connect(QApplication::primaryScreen(), &QScreen::geometryChanged, this, &MainWindow::ScreenGeometryChanged);
|
2021-05-22 21:29:43 +08:00
|
|
|
|
connect(m_askDialog, &CreateIndexAskDialog::closed, this, [ = ]() {
|
|
|
|
|
m_isAskDialogVisible = false;
|
|
|
|
|
});
|
2022-11-28 18:11:55 +08:00
|
|
|
|
connect(m_askDialog, &CreateIndexAskDialog::btnClicked, this, [ = ](const bool &isCreateIndex, const bool &isAskAgain) {
|
|
|
|
|
setSearchMethodConfig(isCreateIndex, isAskAgain);
|
2021-05-22 21:29:43 +08:00
|
|
|
|
});
|
2022-03-08 14:50:48 +08:00
|
|
|
|
// connect(m_settingsBtn, &QPushButton::clicked, this, &MainWindow::settingsBtnClickedSlot);
|
2021-05-22 21:29:43 +08:00
|
|
|
|
//主题改变时,更新自定义标题栏的图标
|
2021-07-08 18:53:16 +08:00
|
|
|
|
// connect(qApp, &QApplication::paletteChanged, this, [ = ]() {
|
|
|
|
|
// m_iconLabel->setPixmap(QIcon::fromTheme("kylin-search").pixmap(QSize(WINDOW_ICON_SIZE, WINDOW_ICON_SIZE)));
|
|
|
|
|
// });
|
2021-07-23 16:10:30 +08:00
|
|
|
|
connect(m_searchBarWidget, &SeachBarWidget::requestSearchKeyword, this, &MainWindow::searchKeywordSlot);
|
2021-07-21 17:01:34 +08:00
|
|
|
|
// connect(m_stackedWidget, &StackedWidget::effectiveSearch, m_searchLayout, &SearchBarHLayout::effectiveSearchRecord);
|
2021-08-02 13:46:59 +08:00
|
|
|
|
//connect(m_searchResultPage, &SearchResultPage::resizeHeight, this, &MainWindow::resizeHeight);
|
2021-08-11 17:50:00 +08:00
|
|
|
|
connect(this,&MainWindow::setText,m_searchBarWidget,&SeachBarWidget::setText);
|
2021-05-22 21:29:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief bootOptionsFilter 过滤终端命令
|
|
|
|
|
* @param opt
|
|
|
|
|
*/
|
|
|
|
|
void MainWindow::bootOptionsFilter(QString opt) {
|
|
|
|
|
if(opt == "-s" || opt == "--show") {
|
2022-04-21 17:15:32 +08:00
|
|
|
|
if (this->isHidden()) {
|
|
|
|
|
clearSearchResult();
|
|
|
|
|
centerToScreen(this);
|
|
|
|
|
this->m_searchBarWidget->setFocus();
|
2021-09-16 14:58:07 +08:00
|
|
|
|
}
|
2023-05-31 17:59:20 +08:00
|
|
|
|
this->activateWindow();
|
2021-05-22 21:29:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief clearSearchResult 清空搜索结果
|
|
|
|
|
*/
|
|
|
|
|
void MainWindow::clearSearchResult() {
|
2021-07-23 16:10:30 +08:00
|
|
|
|
m_searchBarWidget->clear();
|
2021-07-21 17:01:34 +08:00
|
|
|
|
// m_searchLineEdit->clearFocus();
|
2021-05-22 21:29:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief MainWindow::trayIconActivatedSlot 点击任务栏图标的槽函数
|
|
|
|
|
* @param reason
|
|
|
|
|
*/
|
|
|
|
|
void MainWindow::trayIconActivatedSlot(QSystemTrayIcon::ActivationReason reason)
|
|
|
|
|
{
|
|
|
|
|
if(reason == QSystemTrayIcon::Trigger) {
|
|
|
|
|
if(!this->isVisible()) {
|
|
|
|
|
clearSearchResult();
|
|
|
|
|
centerToScreen(this);
|
2021-07-21 17:01:34 +08:00
|
|
|
|
// this->m_searchLineEdit->focusIn(); //打开主界面时输入框夺焦,可直接输入
|
2021-05-22 21:29:43 +08:00
|
|
|
|
this->raise();
|
|
|
|
|
this->activateWindow();
|
|
|
|
|
} else {
|
|
|
|
|
tryHideMainwindow();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief setSearchMethodConfig 在询问弹窗点击按钮后执行
|
|
|
|
|
* @param create_index 是否同意创建索引
|
|
|
|
|
* @param no_longer_ask 是否勾选了不再提示
|
|
|
|
|
*/
|
2022-11-28 18:11:55 +08:00
|
|
|
|
void MainWindow::setSearchMethodConfig(const bool& createIndex, const bool& noLongerAsk)
|
2021-05-22 21:29:43 +08:00
|
|
|
|
{
|
2022-11-28 18:11:55 +08:00
|
|
|
|
if(noLongerAsk) {
|
|
|
|
|
m_settings->setValue(ENABLE_CREATE_INDEX_ASK_DIALOG, false);
|
2021-05-22 21:29:43 +08:00
|
|
|
|
} else {
|
2022-11-28 18:11:55 +08:00
|
|
|
|
m_settings->setValue(ENABLE_CREATE_INDEX_ASK_DIALOG, true);
|
2021-05-22 21:29:43 +08:00
|
|
|
|
}
|
2022-11-28 18:11:55 +08:00
|
|
|
|
if(createIndex) {
|
|
|
|
|
if(m_searchGsettings && m_searchGsettings->keys().contains(FILE_INDEX_ENABLE_KEY)) {
|
|
|
|
|
m_searchGsettings->set(FILE_INDEX_ENABLE_KEY, true);
|
2021-05-22 21:29:43 +08:00
|
|
|
|
}
|
2021-11-22 16:03:31 +08:00
|
|
|
|
//创建索引十秒后重新搜索一次(如果用户十秒内没有退出搜索界面且没有重新搜索)
|
|
|
|
|
m_researchTimer->start();
|
2021-05-22 21:29:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @brief MainWindow::searchKeywordSlot 执行搜索的槽函数
|
|
|
|
|
* @param keyword 关键词
|
|
|
|
|
*/
|
|
|
|
|
void MainWindow::searchKeywordSlot(const QString &keyword)
|
|
|
|
|
{
|
2022-11-28 18:11:55 +08:00
|
|
|
|
if(keyword == "" || keyword.isEmpty()) {
|
2021-07-23 16:10:30 +08:00
|
|
|
|
// m_stackedWidget->setPage(int(StackedPage::HomePage));
|
2022-08-24 09:57:07 +08:00
|
|
|
|
QTimer::singleShot(10, this, [ = ]() {
|
|
|
|
|
m_askTimer->stop();
|
2022-11-22 10:17:36 +08:00
|
|
|
|
Q_EMIT m_searchResultPage->stopSearch();
|
2022-08-24 09:57:07 +08:00
|
|
|
|
m_searchResultPage->hide();
|
|
|
|
|
this->resizeHeight(68);
|
|
|
|
|
});
|
2021-07-26 15:08:46 +08:00
|
|
|
|
|
2021-05-22 21:29:43 +08:00
|
|
|
|
} else {
|
|
|
|
|
QTimer::singleShot(10, this, [ = ]() {
|
|
|
|
|
//允许弹窗且当前次搜索(为关闭主界面,算一次搜索过程)未询问且当前为暴力搜索
|
2022-11-28 18:11:55 +08:00
|
|
|
|
if(m_settings->value(ENABLE_CREATE_INDEX_ASK_DIALOG).toBool()
|
|
|
|
|
&& !m_currentSearchAsked
|
2023-05-31 17:59:20 +08:00
|
|
|
|
&& !m_isIndexSearch) {
|
2021-05-22 21:29:43 +08:00
|
|
|
|
m_askTimer->start();
|
2022-11-28 18:11:55 +08:00
|
|
|
|
}
|
2021-07-23 16:10:30 +08:00
|
|
|
|
Q_EMIT m_searchResultPage->startSearch(keyword);
|
2021-08-02 13:46:59 +08:00
|
|
|
|
this->resizeHeight(WINDOW_HEIGHT);
|
2021-07-26 15:08:46 +08:00
|
|
|
|
|
|
|
|
|
m_searchResultPage->move(0, 58);
|
|
|
|
|
m_searchResultPage->show();
|
2021-05-22 21:29:43 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
m_researchTimer->stop(); //如果搜索内容发生改变,则停止建索引后重新搜索的倒计时
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-26 15:08:46 +08:00
|
|
|
|
void MainWindow::resizeHeight(int height)
|
|
|
|
|
{
|
|
|
|
|
this->setFixedHeight(height);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-05 12:47:16 +08:00
|
|
|
|
void MainWindow::tryHide()
|
|
|
|
|
{
|
|
|
|
|
this->tryHideMainwindow();
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-23 10:00:43 +08:00
|
|
|
|
void MainWindow::ScreenGeometryChanged(QRect rect) {
|
2021-05-22 21:29:43 +08:00
|
|
|
|
Q_UNUSED(rect);
|
2023-03-23 10:00:43 +08:00
|
|
|
|
if(this->isVisible()) {
|
|
|
|
|
centerToScreen(this);
|
|
|
|
|
}
|
2021-05-22 21:29:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief MainWindow::centerToScreen 使窗口显示在屏幕中间
|
|
|
|
|
* @param widget
|
|
|
|
|
*/
|
|
|
|
|
void MainWindow::centerToScreen(QWidget* widget) {
|
|
|
|
|
if(!widget)
|
|
|
|
|
return;
|
2021-12-16 11:26:49 +08:00
|
|
|
|
KWindowSystem::setState(this->winId(),NET::SkipTaskbar | NET::SkipPager);
|
2023-03-23 10:00:43 +08:00
|
|
|
|
QRect desk_rect = qApp->screenAt(QCursor::pos())->geometry();
|
2021-05-22 21:29:43 +08:00
|
|
|
|
int desk_x = desk_rect.width();
|
|
|
|
|
int desk_y = desk_rect.height();
|
|
|
|
|
int x = widget->width();
|
2022-06-27 09:30:22 +08:00
|
|
|
|
widget->show();
|
|
|
|
|
kdk::WindowManager::setGeometry(this->windowHandle(),QRect(desk_x / 2 - x / 2 + desk_rect.left(),
|
2023-08-25 14:31:51 +08:00
|
|
|
|
desk_y / 6 + desk_rect.top(),
|
2022-06-27 09:30:22 +08:00
|
|
|
|
this->width(),
|
|
|
|
|
this->height()));
|
2022-07-20 14:07:04 +08:00
|
|
|
|
//设置跳过多任务视图
|
|
|
|
|
kdk::WindowManager::setSkipSwitcher(this->windowHandle(),true);
|
|
|
|
|
//设置跳过任务栏
|
|
|
|
|
kdk::WindowManager::setSkipTaskBar(this->windowHandle(),true);
|
2022-06-27 09:30:22 +08:00
|
|
|
|
// widget->move(desk_x / 2 - x / 2 + desk_rect.left(), desk_y / 3 + desk_rect.top());
|
2021-05-22 21:29:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-28 18:11:55 +08:00
|
|
|
|
void MainWindow::initSettings() {
|
2021-05-22 21:29:43 +08:00
|
|
|
|
const QByteArray id(UKUI_SEARCH_SCHEMAS);
|
|
|
|
|
if(QGSettings::isSchemaInstalled(id)) {
|
2022-11-28 18:11:55 +08:00
|
|
|
|
m_searchGsettings = new QGSettings(id);
|
2023-05-31 17:59:20 +08:00
|
|
|
|
if (m_searchGsettings->keys().contains(FILE_INDEX_ENABLE_KEY)) {
|
|
|
|
|
m_isIndexSearch = m_searchGsettings->get(FILE_INDEX_ENABLE_KEY).toBool();
|
|
|
|
|
}
|
2022-11-28 18:11:55 +08:00
|
|
|
|
connect(m_searchGsettings, &QGSettings::changed, this, [ = ](const QString & key) {
|
|
|
|
|
if(key == FILE_INDEX_ENABLE_KEY) {
|
2023-05-31 17:59:20 +08:00
|
|
|
|
m_isIndexSearch = m_searchGsettings->get(FILE_INDEX_ENABLE_KEY).toBool();
|
|
|
|
|
if(m_researchTimer->isActive() && !m_isIndexSearch) {
|
2022-11-28 18:11:55 +08:00
|
|
|
|
m_researchTimer->stop();
|
|
|
|
|
}
|
2021-05-22 21:29:43 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-11-28 18:11:55 +08:00
|
|
|
|
m_settings = new QSettings(MAIN_SETTINGS, QSettings::IniFormat, this);
|
2021-05-22 21:29:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//使用GSetting获取当前窗口应该使用的透明度
|
|
|
|
|
double MainWindow::getTransparentData() {
|
2023-05-31 17:59:20 +08:00
|
|
|
|
return GlobalSettings::getInstance().getValue(TRANSPARENCY_KEY).toDouble();
|
2021-05-22 21:29:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::initTimer() {
|
2023-04-24 17:36:37 +08:00
|
|
|
|
m_askTimer = new QTimer(this);
|
2021-05-22 21:29:43 +08:00
|
|
|
|
m_askTimer->setInterval(ASK_INDEX_TIME);
|
|
|
|
|
connect(m_askTimer, &QTimer::timeout, this, [ = ]() {
|
2023-04-24 17:36:37 +08:00
|
|
|
|
QWindow *modal = QGuiApplication::modalWindow();
|
|
|
|
|
if(modal) {
|
|
|
|
|
m_askTimer->stop();
|
|
|
|
|
connect(modal, &QWindow::visibleChanged, this, [ & ](bool visible){
|
|
|
|
|
if(!visible) {
|
|
|
|
|
m_askTimer->start();
|
|
|
|
|
}
|
|
|
|
|
}, Qt::UniqueConnection);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-05-31 17:59:20 +08:00
|
|
|
|
if(this->isVisible() && !m_isIndexSearch) {
|
2021-05-22 21:29:43 +08:00
|
|
|
|
m_isAskDialogVisible = true;
|
2022-06-27 09:30:22 +08:00
|
|
|
|
kdk::UkuiStyleHelper::self()->removeHeader(m_askDialog);
|
2021-05-22 21:29:43 +08:00
|
|
|
|
m_askDialog->show();
|
2022-07-20 14:07:04 +08:00
|
|
|
|
//设置跳过多任务视图
|
|
|
|
|
kdk::WindowManager::setSkipSwitcher(m_askDialog->windowHandle(),true);
|
|
|
|
|
//设置跳过任务栏
|
|
|
|
|
kdk::WindowManager::setSkipTaskBar(m_askDialog->windowHandle(),true);
|
2021-05-22 21:29:43 +08:00
|
|
|
|
m_currentSearchAsked = true;
|
|
|
|
|
}
|
|
|
|
|
m_askTimer->stop();
|
|
|
|
|
});
|
|
|
|
|
m_researchTimer = new QTimer;
|
|
|
|
|
m_researchTimer->setInterval(RESEARCH_TIME);
|
2021-08-06 10:54:48 +08:00
|
|
|
|
connect(m_researchTimer, &QTimer::timeout, this, [ = ]() {
|
|
|
|
|
if(this->isVisible()) {
|
|
|
|
|
m_searchBarWidget->reSearch();
|
|
|
|
|
}
|
|
|
|
|
m_researchTimer->stop();
|
|
|
|
|
});
|
|
|
|
|
connect(m_searchBarWidget, &SeachBarWidget::requestSearchKeyword, this, [ = ](QString text) {
|
|
|
|
|
if(text == "" || text.isEmpty()) {
|
|
|
|
|
m_askTimer->stop();
|
|
|
|
|
} else {
|
|
|
|
|
//允许弹窗且当前次搜索(为关闭主界面,算一次搜索过程)未询问且当前为暴力搜索
|
2023-05-31 17:59:20 +08:00
|
|
|
|
if(m_settings->value(ENABLE_CREATE_INDEX_ASK_DIALOG, true).toBool() && !m_currentSearchAsked && !m_isIndexSearch) {
|
2021-08-06 10:54:48 +08:00
|
|
|
|
m_askTimer->start();
|
2023-05-31 17:59:20 +08:00
|
|
|
|
}
|
2021-08-06 10:54:48 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
2021-05-22 21:29:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief MainWindow::tryHideMainwindow 尝试隐藏主界面并停止部分未完成的动作,重置部分状态值
|
|
|
|
|
*/
|
|
|
|
|
bool MainWindow::tryHideMainwindow()
|
|
|
|
|
{
|
2021-09-23 10:31:13 +08:00
|
|
|
|
if (!m_isAskDialogVisible && QApplication::activeModalWidget() == nullptr) {
|
2021-05-22 21:29:43 +08:00
|
|
|
|
qDebug()<<"Mainwindow will be hidden";
|
|
|
|
|
m_currentSearchAsked = false;
|
|
|
|
|
m_askTimer->stop();
|
|
|
|
|
m_researchTimer->stop();
|
2021-07-23 16:10:30 +08:00
|
|
|
|
Q_EMIT m_searchResultPage->stopSearch();
|
2023-07-07 16:19:12 +08:00
|
|
|
|
this->clearSearchResult();
|
|
|
|
|
this->hide();
|
2023-09-19 15:40:13 +08:00
|
|
|
|
if(!m_releaseFreeMemoryTimerWorking) {
|
|
|
|
|
m_releaseFreeMemoryTimerWorking = true;
|
|
|
|
|
QTimer::singleShot(2000, this, [&](){
|
|
|
|
|
if(!this->isVisible()) {
|
|
|
|
|
MallocExtension::instance()->ReleaseFreeMemory();
|
|
|
|
|
}
|
|
|
|
|
m_releaseFreeMemoryTimerWorking = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-05-22 21:29:43 +08:00
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
//有上层弹窗未关闭,不允许隐藏主界面
|
|
|
|
|
qWarning()<<"There is a dialog onside, so that mainwindow can not be hidden.";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief MainWindow::setSearchMethod 设置搜索模式
|
|
|
|
|
* @param is_index_search true为索引搜索,false为暴力搜索
|
|
|
|
|
*/
|
2022-11-28 18:11:55 +08:00
|
|
|
|
void MainWindow::setSearchMethod(const bool isIndexSearch) {
|
|
|
|
|
if(!isIndexSearch) {
|
2021-05-22 21:29:43 +08:00
|
|
|
|
m_researchTimer->stop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief MainWindow::keyPressEvent 按esc键关闭主界面
|
|
|
|
|
* @param event
|
|
|
|
|
*/
|
|
|
|
|
void MainWindow::keyPressEvent(QKeyEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (event->key() == Qt::Key_Escape) {
|
|
|
|
|
tryHideMainwindow();
|
2021-08-18 14:23:14 +08:00
|
|
|
|
} else if (event->key() == Qt::Key_Return or event->key() == Qt::Key_Enter) {
|
2021-09-13 20:12:35 +08:00
|
|
|
|
if (!m_searchResultPage->isHidden()) {
|
|
|
|
|
//显示最佳匹配中第一项的详情页,无搜索结果则调取网页搜索
|
|
|
|
|
qDebug() << "Press Enter";
|
|
|
|
|
m_searchResultPage->pressEnter();
|
|
|
|
|
}
|
2021-08-18 14:23:14 +08:00
|
|
|
|
} else if (event->key() == Qt::Key_Up) {
|
|
|
|
|
qDebug() << "Press ↑";
|
|
|
|
|
m_searchResultPage->pressUp();
|
|
|
|
|
} else if (event->key() == Qt::Key_Down) {
|
|
|
|
|
qDebug() << "Press ↓";
|
|
|
|
|
if (!m_searchResultPage->getSelectedState()) {
|
|
|
|
|
m_searchResultPage->pressEnter();
|
|
|
|
|
} else {
|
|
|
|
|
m_searchResultPage->pressDown();
|
|
|
|
|
}
|
2021-05-22 21:29:43 +08:00
|
|
|
|
}
|
|
|
|
|
return QWidget::keyPressEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-24 14:07:56 +08:00
|
|
|
|
void MainWindow::paintEvent(QPaintEvent *event)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(event)
|
2021-07-21 17:01:34 +08:00
|
|
|
|
QPainterPath path;
|
|
|
|
|
|
2022-05-19 13:47:54 +08:00
|
|
|
|
path.addRoundedRect(m_searchBarWidget->x()+10, m_searchBarWidget->y()+10, m_searchBarWidget->width()-20, m_searchBarWidget->height()-20, 12, 12);
|
|
|
|
|
path.addRoundedRect(m_searchResultPage->x()+10, m_searchResultPage->y()+10, m_searchResultPage->width()-20, m_searchResultPage->height()-20, 12, 12);
|
2021-07-23 16:10:30 +08:00
|
|
|
|
|
2021-07-21 17:01:34 +08:00
|
|
|
|
KWindowEffects::enableBlurBehind(this->winId(), true, QRegion(path.toFillPolygon().toPolygon()));
|
2021-05-22 21:29:43 +08:00
|
|
|
|
|
|
|
|
|
}
|
2022-04-21 17:15:32 +08:00
|
|
|
|
|
|
|
|
|
bool MainWindow::eventFilter(QObject *watched, QEvent *event)
|
|
|
|
|
{
|
2022-07-13 14:53:23 +08:00
|
|
|
|
if (watched == this) {
|
|
|
|
|
//失焦退出
|
|
|
|
|
if (event->type() == QEvent::ActivationChange) {
|
|
|
|
|
if (QApplication::activeWindow() != this) {
|
|
|
|
|
tryHideMainwindow();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//kwin alt+f4发出close事件, 需要在存在子窗口时屏蔽该事件
|
|
|
|
|
if (event->type() == QEvent::Close) {
|
|
|
|
|
event->ignore();
|
|
|
|
|
tryHideMainwindow();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2022-04-21 17:15:32 +08:00
|
|
|
|
}
|
2022-07-13 14:53:23 +08:00
|
|
|
|
|
2022-04-21 17:15:32 +08:00
|
|
|
|
return QObject::eventFilter(watched, event);
|
|
|
|
|
}
|
2023-10-10 16:16:02 +08:00
|
|
|
|
|
|
|
|
|
void MainWindow::openSearchSettings() {
|
|
|
|
|
bool res(false);
|
|
|
|
|
QDBusInterface* appLaunchInterface = new QDBusInterface("com.kylin.AppManager",
|
|
|
|
|
"/com/kylin/AppManager",
|
|
|
|
|
"com.kylin.AppManager",
|
|
|
|
|
QDBusConnection::sessionBus());
|
|
|
|
|
if(!appLaunchInterface->isValid()) {
|
|
|
|
|
qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message());
|
|
|
|
|
res = false;
|
|
|
|
|
} else {
|
|
|
|
|
appLaunchInterface->setTimeout(10000);
|
|
|
|
|
QDBusReply<bool> reply = appLaunchInterface->call("LaunchAppWithArguments", "ukui-control-center.desktop", QStringList() << "-m" << "search");
|
|
|
|
|
if(reply.isValid()) {
|
|
|
|
|
res = reply;
|
|
|
|
|
} else {
|
|
|
|
|
qWarning() << "SoftWareCenter dbus called failed!";
|
|
|
|
|
res = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (appLaunchInterface) {
|
|
|
|
|
delete appLaunchInterface;
|
|
|
|
|
appLaunchInterface = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!res) {
|
|
|
|
|
//打开控制面板对应页面
|
|
|
|
|
QProcess::startDetached("ukui-control-center", {"-m", "search"});
|
|
|
|
|
}
|
|
|
|
|
}
|