From a0563ab9190fe36da6d79ce65c0dcaf518009d99 Mon Sep 17 00:00:00 2001 From: zhangjiaping Date: Tue, 13 Apr 2021 15:40:19 +0800 Subject: [PATCH] =?UTF-8?q?Fix:=20Mainwindow=20will=20not=20refresh=20some?= =?UTF-8?q?time=20theme=20changed.=20=E4=BF=AE=E5=A4=8D=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=AE=8C=E9=80=8F=E6=98=8E=E5=BA=A6=E5=90=8E=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=B8=BB=E9=A2=98=EF=BC=8C=E4=B8=BB=E7=95=8C=E9=9D=A2=E9=A2=9C?= =?UTF-8?q?=E8=89=B2=E6=9C=AA=E9=9A=8F=E4=B8=BB=E9=A2=98=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E7=9A=84Bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libsearch/global-settings.cpp | 18 ++++++++++++++---- libsearch/global-settings.h | 5 ++++- src/content-widget.cpp | 4 ++-- src/main.cpp | 6 +----- src/mainwindow.h | 10 ---------- src/search-app-thread.cpp | 2 +- src/settings-widget.cpp | 2 +- src/singleapplication/qt-local-peer.cpp | 19 +++++++++++-------- .../qt-single-application.cpp | 12 +++++++----- 9 files changed, 41 insertions(+), 37 deletions(-) diff --git a/libsearch/global-settings.cpp b/libsearch/global-settings.cpp index 7d3c6d4..a70199d 100644 --- a/libsearch/global-settings.cpp +++ b/libsearch/global-settings.cpp @@ -59,16 +59,26 @@ GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent) //if someone changes the num in mainwindow, here should be modified too m_cache.insert(TRANSPARENCY_KEY, 0.7); if (QGSettings::isSchemaInstalled(CONTROL_CENTER_PERSONALISE_GSETTINGS_ID)) { - m_gsettings = new QGSettings(CONTROL_CENTER_PERSONALISE_GSETTINGS_ID, QByteArray(), this); - connect(m_gsettings, &QGSettings::changed, this, [=](const QString& key) { + m_trans_gsettings = new QGSettings(CONTROL_CENTER_PERSONALISE_GSETTINGS_ID, QByteArray(), this); + connect(m_trans_gsettings, &QGSettings::changed, this, [=](const QString& key) { if (key == TRANSPARENCY_KEY) { m_cache.remove(TRANSPARENCY_KEY); - m_cache.insert(TRANSPARENCY_KEY, m_gsettings->get(TRANSPARENCY_KEY).toDouble()); + m_cache.insert(TRANSPARENCY_KEY, m_trans_gsettings->get(TRANSPARENCY_KEY).toDouble()); qApp->paletteChanged(qApp->palette()); } }); m_cache.remove(TRANSPARENCY_KEY); - m_cache.insert(TRANSPARENCY_KEY, m_gsettings->get(TRANSPARENCY_KEY).toDouble()); + m_cache.insert(TRANSPARENCY_KEY, m_trans_gsettings->get(TRANSPARENCY_KEY).toDouble()); + } + + if (QGSettings::isSchemaInstalled(THEME_GSETTINGS_ID)) { + m_theme_gsettings = new QGSettings(THEME_GSETTINGS_ID, QByteArray(), this); + connect(m_theme_gsettings, &QGSettings::changed, this, [=](const QString& key) { + if (key == STYLE_NAME_KEY) { + //当前主题改变时也发出paletteChanged信号,通知主界面刷新 + qApp->paletteChanged(qApp->palette()); + } + }); } } diff --git a/libsearch/global-settings.h b/libsearch/global-settings.h index 3fe4250..858185c 100644 --- a/libsearch/global-settings.h +++ b/libsearch/global-settings.h @@ -37,6 +37,8 @@ #define CONTROL_CENTER_PERSONALISE_GSETTINGS_ID "org.ukui.control-center.personalise" #define TRANSPARENCY_KEY "transparency" +#define THEME_GSETTINGS_ID "org.ukui.style" +#define STYLE_NAME_KEY "styleName" #define INDEX_DATABASE_STATE "index_database_state" #define CONTENT_INDEX_DATABASE_STATE "content_index_database_state" #define INDEX_GENERATOR_NORMAL_EXIT "index_generator_normal_exit" @@ -93,7 +95,8 @@ private: ~GlobalSettings() = default; QSettings* m_settings; - QGSettings* m_gsettings; + QGSettings* m_trans_gsettings; + QGSettings* m_theme_gsettings; QSettings *m_block_dirs_settings; QSettings *m_search_record_settings; QMap m_cache; diff --git a/src/content-widget.cpp b/src/content-widget.cpp index 9d50717..4149331 100644 --- a/src/content-widget.cpp +++ b/src/content-widget.cpp @@ -272,8 +272,8 @@ void ContentWidget::setupConnect(SearchListView * listview) { m_resultListArea->ensureVisible(pos.x(),pos.y()); }); connect(listview,&SearchListView::mousePressed,this,&ContentWidget::mousePressed); - connect(listview, SIGNAL(currentRowChanged(SearchListView *,const int&, const QString&)), this, SLOT(onListViewRowChanged(SearchListView *, const int&, const QString&))); - connect(listview, SIGNAL(onRowDoubleClicked(SearchListView *,const int&, const QString&)), this, SLOT(onListViewRowDoubleClicked(SearchListView *, const int&, const QString&))); + connect(listview, &SearchListView::currentRowChanged, this, &ContentWidget::onListViewRowChanged); + connect(listview, &SearchListView::onRowDoubleClicked, this, &ContentWidget::onListViewRowDoubleClicked); } /** diff --git a/src/main.cpp b/src/main.cpp index ad93af2..eb76c89 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -257,8 +257,6 @@ int main(int argc, char *argv[]) // hints.decorations = MWM_DECOR_BORDER; // XAtomHelper::getInstance()->setWindowMotifHint(w->winId(), hints); - //TODO - //wait Ping jiang before 2021.04.10 app.setActivationWindow(w); // Processing startup parameters @@ -269,9 +267,7 @@ int main(int argc, char *argv[]) w->show(); } - // TODO - // Wait Ping jiang before 2021.04.10 - QObject::connect(&app, SIGNAL(messageReceived(const QString&)),w, SLOT(bootOptionsFilter(const QString&))); + QObject::connect(&app, &QtSingleApplication::messageReceived, w, &MainWindow::bootOptionsFilter); // Start app search thread AppMatch::getAppMatch()->start(); diff --git a/src/mainwindow.h b/src/mainwindow.h index c9aa0e6..be2a3fe 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -74,8 +74,6 @@ public: // The position which mainwindow shows in the center of screen where the cursor in. void centerToScreen(QWidget* widget); - // TODO - // Wait Ping jiang. MotifWmHints m_hints; private: @@ -83,10 +81,6 @@ private: // MainWindow quit when focus out. bool nativeEvent(const QByteArray&, void*, long*); - // TODO - // Not use? - QFrame * m_line = nullptr; // Vertical dividing line - QFrame * m_frame = nullptr; // Main frame QFrame * m_titleFrame = nullptr; // Title bar frame QHBoxLayout * m_titleLyt = nullptr; // Title layout @@ -98,10 +92,6 @@ private: SearchBarHLayout * m_searchLayout = nullptr; // Search bar layout SeachBarWidget * m_searchWidget = nullptr; // Search bar - // TODO - // Not use? - bool m_winFlag = false; - QGSettings * m_transparency_gsettings = nullptr; double getTransparentData(); diff --git a/src/search-app-thread.cpp b/src/search-app-thread.cpp index 9068691..ffd1493 100644 --- a/src/search-app-thread.cpp +++ b/src/search-app-thread.cpp @@ -14,7 +14,7 @@ void SearchAppThread::startSearch(const QString & keyword) SearchApp *appsearch; appsearch = new SearchApp(keyword); // appsearch->setKeyword(keyword); - connect(appsearch, SIGNAL(searchResultApp(const QVector&)), this, SIGNAL(searchResultApp(const QVector&))); + connect(appsearch, &SearchApp::searchResultApp, this, &SearchAppThread::searchResultApp); m_pool.start(appsearch); } diff --git a/src/settings-widget.cpp b/src/settings-widget.cpp index c0cae6e..a0c9388 100644 --- a/src/settings-widget.cpp +++ b/src/settings-widget.cpp @@ -234,7 +234,7 @@ void SettingsWidget::setupBlackList(const QStringList& list) { FolderListItem * item = new FolderListItem(m_dirListWidget, path); m_dirListLyt->addWidget(item); item->setMaximumWidth(this->width() - 52); - connect(item, SIGNAL(onDelBtnClicked(const QString&)), this, SLOT(onBtnDelClicked(const QString&))); + connect(item, &FolderListItem::onDelBtnClicked, this, &SettingsWidget::onBtnDelClicked); m_blockdirs ++; } this->resize(); diff --git a/src/singleapplication/qt-local-peer.cpp b/src/singleapplication/qt-local-peer.cpp index 3b74d98..9670eee 100644 --- a/src/singleapplication/qt-local-peer.cpp +++ b/src/singleapplication/qt-local-peer.cpp @@ -69,10 +69,10 @@ QtLocalPeer::QtLocalPeer(QObject* parent, const QString &appId) #if defined(Q_OS_WIN) id = id.toLower(); #endif - prefix = id.section(QLatin1Char('/'), -1); + prefix = id.section(QLatin1Char('/'), -1); //完整路径按‘/’分隔后取最后一个字段 } - prefix.remove(QRegExp("[^a-zA-Z]")); - prefix.truncate(6); + prefix.remove(QRegExp("[^a-zA-Z]")); //去掉名称中的非字母 + prefix.truncate(6); //取前六位 QByteArray idc = id.toUtf8(); quint16 idNum = qChecksum(idc.constData(), idc.size()); @@ -96,7 +96,7 @@ QtLocalPeer::QtLocalPeer(QObject* parent, const QString &appId) server = new QLocalServer(this); QString lockName = QDir(QDir::tempPath()).absolutePath() + QLatin1Char('/') + socketName - + QLatin1String("-lockfile"); + + QLatin1String("-lockfile"); //tmp目录下的锁文件 lockFile.setFileName(lockName); lockFile.open(QIODevice::ReadWrite); } @@ -111,6 +111,7 @@ bool QtLocalPeer::isClient() if (!lockFile.lock(QtLP_Private::QtLockedFile::WriteLock, false)) return true; + //由于文件锁的存在,仅当本进程第一次启动时能执行到此并使server进行监听和关联槽函数 bool res = server->listen(socketName); #if defined(Q_OS_UNIX) && (QT_VERSION >= QT_VERSION_CHECK(4,5,0)) // ### Workaround @@ -121,7 +122,7 @@ bool QtLocalPeer::isClient() #endif if (!res) qWarning("QtSingleCoreApplication: listen on local socket failed, %s", qPrintable(server->errorString())); - QObject::connect(server, SIGNAL(newConnection()), SLOT(receiveConnection())); + QObject::connect(server, &QLocalServer::newConnection, this, &QtLocalPeer::receiveConnection); return false; } @@ -162,10 +163,12 @@ bool QtLocalPeer::sendMessage(const QString &message, int timeout) return res; } - +/** + * @brief QtLocalPeer::receiveConnection 当新进程启动时,会尝试连接此进程server,server接收到newConnection信号并触发此槽函数 + */ void QtLocalPeer::receiveConnection() { - QLocalSocket* socket = server->nextPendingConnection(); + QLocalSocket* socket = server->nextPendingConnection(); //获取新进程的socket if (!socket) return; @@ -202,5 +205,5 @@ void QtLocalPeer::receiveConnection() socket->waitForBytesWritten(1000); socket->waitForDisconnected(1000); // make sure client reads ack delete socket; - Q_EMIT messageReceived(message); //### (might take a long time to return) + Q_EMIT messageReceived(message); //获取新进程的启动信息并作为信号发送给前端 } diff --git a/src/singleapplication/qt-single-application.cpp b/src/singleapplication/qt-single-application.cpp index c4c401a..91b6e7f 100644 --- a/src/singleapplication/qt-single-application.cpp +++ b/src/singleapplication/qt-single-application.cpp @@ -145,7 +145,8 @@ void QtSingleApplication::sysInit(const QString &appId) { actWin = 0; peer = new QtLocalPeer(this, appId); - connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&))); +// connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&))); + connect(peer, &QtLocalPeer::messageReceived, this, &QtSingleApplication::messageReceived); } @@ -295,10 +296,11 @@ QString QtSingleApplication::id() const void QtSingleApplication::setActivationWindow(QWidget* aw, bool activateOnMessage) { actWin = aw; - if (activateOnMessage) - connect(peer, SIGNAL(messageReceived(const QString&)), this, SLOT(activateWindow())); - else - disconnect(peer, SIGNAL(messageReceived(const QString&)), this, SLOT(activateWindow())); + //目前不需要用到此处的置顶方法,故此信号槽暂时注释掉,若后续需要根据新起进程传递的信号执行部分操作时可以把这里放开 +// if (activateOnMessage) +// connect(peer, &QtLocalPeer::messageReceived, this, &QtSingleApplication::activateWindow); +// else +// disconnect(peer, &QtLocalPeer::messageReceived, this, &QtSingleApplication::activateWindow); }