Merge branch 'fix90875' into 'dbus-interface'

add function of calling up the mainWindow from the command line

See merge request kylin-desktop/kylin-nm!428
This commit is contained in:
w x 2021-11-29 02:36:02 +00:00
commit ae087e88d7
3 changed files with 33 additions and 42 deletions

View File

@ -85,14 +85,8 @@ int main(int argc, char *argv[])
QtSingleApplication a(id, argc, argv);
qInstallMessageHandler(messageOutput);
if (a.isRunning()) {
qInfo() << "Kylin-Network-Manager Is Already Launched, just show";
auto connection = QDBusConnection::sessionBus();
QDBusInterface iface("com.kylin.network",
"/com/kylin/network",
"com.kylin.network",
connection);
iface.call("showMainWindow");
return 0;
a.sendMessage("raise_window_noop");
return EXIT_SUCCESS;
}
QApplication::setQuitOnLastWindowClosed(false);
@ -116,6 +110,7 @@ int main(int argc, char *argv[])
}
MainWindow w;
a.setActivationWindow(&w);
w.setProperty("useStyleWindowManager", false); //禁用拖动
//设置窗口无边框,阴影
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))

View File

@ -49,6 +49,7 @@
#include <QDBusConnection>
#include <QDBusInterface>
#include <QDBusReply>
#include <QMainWindow>
#include "../mainwindow.h"
@ -142,10 +143,9 @@
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, &QtLocalPeer::messageReceived, this, &QtSingleApplication::messageReceived);
m_activateWindow = 0;
m_peer = new QtLocalPeer(this, appId);
connect(m_peer, &QtLocalPeer::messageReceived, this, &QtSingleApplication::messageReceived);
}
@ -240,7 +240,7 @@ QtSingleApplication::QtSingleApplication(Display* dpy, const QString &appId, int
*/
bool QtSingleApplication::isRunning() {
return peer->isClient();
return m_peer->isClient();
}
@ -258,7 +258,7 @@ bool QtSingleApplication::isRunning() {
\sa isRunning(), messageReceived()
*/
bool QtSingleApplication::sendMessage(const QString &message, int timeout) {
return peer->sendMessage(message, timeout);
return m_peer->sendMessage(message, timeout);
}
@ -267,7 +267,7 @@ bool QtSingleApplication::sendMessage(const QString &message, int timeout) {
identifier will be regarded as instances of the same application.
*/
QString QtSingleApplication::id() const {
return peer->applicationId();
return m_peer->applicationId();
}
@ -284,12 +284,11 @@ QString QtSingleApplication::id() const {
*/
void QtSingleApplication::setActivationWindow(QWidget* aw, bool activateOnMessage) {
actWin = aw;
//目前不需要用到此处的置顶方法,故此信号槽暂时注释掉,若后续需要根据新起进程传递的信号执行部分操作时可以把这里放开
// if (activateOnMessage)
// connect(peer, &QtLocalPeer::messageReceived, this, &QtSingleApplication::activateWindow);
// else
// disconnect(peer, &QtLocalPeer::messageReceived, this, &QtSingleApplication::activateWindow);
m_activateWindow = aw;
if (activateOnMessage)
connect(m_peer, &QtLocalPeer::messageReceived, this, &QtSingleApplication::activateWindow);
else
disconnect(m_peer, &QtLocalPeer::messageReceived, this, &QtSingleApplication::activateWindow);
}
@ -300,7 +299,7 @@ void QtSingleApplication::setActivationWindow(QWidget* aw, bool activateOnMessag
\sa setActivationWindow()
*/
QWidget* QtSingleApplication::activationWindow() const {
return actWin;
return m_activateWindow;
}
@ -319,24 +318,21 @@ QWidget* QtSingleApplication::activationWindow() const {
\sa setActivationWindow(), messageReceived(), initialize()
*/
void QtSingleApplication::activateWindow() {
//单例置顶策略由于bootOptionsFilter in mainwindow自带置顶策略故注掉此处
// if (actWin) {
// if(this->applicationState() & Qt::ApplicationInactive)
// {
// MainWindow* w=qobject_cast<MainWindow*>(actWin);
//// w->loadMainWindow();
// w->clearSearchResult();
// actWin->setWindowState(actWin->windowState() & ~Qt::WindowMinimized);
// actWin->raise();
// actWin->showNormal();
// actWin->activateWindow();
// }
// else {
// actWin->setWindowState(actWin->windowState() & Qt::WindowMinimized);
// actWin->hide();
// }
// }
if (m_activateWindow) {
if(this->applicationState() & Qt::ApplicationInactive)
{
MainWindow* w=qobject_cast<MainWindow*>(m_activateWindow);
w->showMainwindow();
m_activateWindow->setWindowState(m_activateWindow->windowState() & ~Qt::WindowMinimized);
m_activateWindow->raise();
m_activateWindow->showNormal();
m_activateWindow->activateWindow();
}
else {
m_activateWindow->setWindowState(m_activateWindow->windowState() & Qt::WindowMinimized);
m_activateWindow->hide();
}
}
}

View File

@ -102,8 +102,8 @@ Q_SIGNALS:
private:
void sysInit(const QString &appId = QString());
QtLocalPeer *peer;
QWidget *actWin;
QtLocalPeer *m_peer;
QWidget *m_activateWindow;
};
#endif // QTSINGLEAPPLICATION_H