Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
System
KHelpCenter
Commits
6dbd16ec
Commit
6dbd16ec
authored
Feb 11, 2022
by
Friedrich W. H. Kossebau
Browse files
Make KHelpCenter DBusActivatable
parent
f6f4aa9e
Pipeline
#138028
passed with stage
in 47 seconds
Changes
4
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
CMakeLists.txt
View file @
6dbd16ec
...
...
@@ -26,6 +26,7 @@ include(ECMOptionalAddSubdirectory)
include
(
FeatureSummary
)
include
(
CheckIncludeFiles
)
include
(
ECMQtDeclareLoggingCategory
)
include
(
ECMGenerateDBusServiceFile
)
find_package
(
Qt5
${
QT_MIN_VERSION
}
CONFIG REQUIRED COMPONENTS
DBus
...
...
@@ -126,6 +127,12 @@ install(TARGETS khelpcenter ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
########### install files ###############
ecm_generate_dbus_service_file
(
NAME org.kde.khelpcenter
EXECUTABLE
${
KDE_INSTALL_FULL_BINDIR
}
/khelpcenter
DESTINATION
${
KDE_INSTALL_DBUSSERVICEDIR
}
)
install
(
PROGRAMS org.kde.khelpcenter.desktop DESTINATION
${
KDE_INSTALL_APPDIR
}
)
install
(
FILES khelpcenter.kcfg DESTINATION
${
KDE_INSTALL_KCFGDIR
}
)
install
(
FILES khelpcenter.desktop DESTINATION
${
KDE_INSTALL_KSERVICES5DIR
}
)
...
...
application.cpp
View file @
6dbd16ec
...
...
@@ -7,8 +7,10 @@
#include "application.h"
#include "mainwindow.h"
#include <kwindowsystem_version.h>
#include <KAboutData>
#include <KDBusService>
#include <KWindowSystem>
#include <KLocalizedString>
#include <KUrlAuthorized>
...
...
@@ -43,29 +45,66 @@ QCommandLineParser *Application::cmdParser()
return
&
mCmdParser
;
}
void
Application
::
activate
(
const
QStringList
&
args
,
const
QString
&
workingDirectory
)
void
Application
::
activate
ForStartLikeCall
(
)
{
mCmdParser
.
parse
(
args
);
QStringList
urls
=
mCmdParser
.
positionalArguments
();
if
(
!
mMainWindow
)
{
if
(
qApp
->
isSessionRestored
())
{
// The kRestoreMainWindows call will do the rest.
return
;
mMainWindow
->
show
();
#if KWINDOWSYSTEM_VERSION >= QT_VERSION_CHECK(5, 91, 0)
KWindowSystem
::
updateStartupId
(
mMainWindow
->
windowHandle
());
#else
if
(
KWindowSystem
::
isPlatformWayland
())
{
const
QString
token
=
qEnvironmentVariable
(
"XDG_ACTIVATION_TOKEN"
);
if
(
!
token
.
isEmpty
())
{
KWindowSystem
::
setCurrentXdgActivationToken
(
token
);
// no need to unset XDG_ACTIVATION_TOKEN, because
// KDBusService cares for that and we only run in its signals handlers here
}
mMainWindow
=
new
MainWindow
;
}
#endif
mMainWindow
->
raise
();
KWindowSystem
::
activateWindow
(
mMainWindow
->
winId
());
}
void
Application
::
newInstance
()
{
mMainWindow
=
new
MainWindow
;
mMainWindow
->
show
();
QUrl
url
;
const
QStringList
urls
=
mCmdParser
.
positionalArguments
()
;
if
(
!
urls
.
isEmpty
()
)
{
url
=
QUrl
::
fromUserInput
(
urls
.
at
(
0
),
workingDirectory
);
const
QUrl
url
=
QUrl
::
fromUserInput
(
urls
.
at
(
0
),
QDir
::
currentPath
());
mMainWindow
->
openUrl
(
url
);
}
}
void
Application
::
restoreInstance
()
{
mMainWindow
=
new
MainWindow
;
mMainWindow
->
restore
(
1
);
}
void
Application
::
activate
(
const
QStringList
&
arguments
,
const
QString
&
workingDirectory
)
{
if
(
!
arguments
.
isEmpty
())
{
mCmdParser
.
parse
(
arguments
);
const
QStringList
urls
=
mCmdParser
.
positionalArguments
();
if
(
!
urls
.
isEmpty
()
)
{
const
QUrl
url
=
QUrl
::
fromUserInput
(
urls
.
at
(
0
),
workingDirectory
);
mMainWindow
->
openUrl
(
url
);
}
}
mMainWindow
->
openUrl
(
url
);
activateForStartLikeCall
();
}
void
Application
::
open
(
const
QList
<
QUrl
>&
urls
)
{
if
(
!
urls
.
isEmpty
())
{
mMainWindow
->
openUrl
(
urls
.
first
()
);
}
mMainWindow
->
show
();
activateForStartLikeCall
();
}
int
main
(
int
argc
,
char
**
argv
)
...
...
@@ -95,14 +134,13 @@ int main( int argc, char **argv )
KDBusService
service
(
KDBusService
::
Unique
);
app
.
activate
(
app
.
arguments
(),
QDir
::
currentPath
());
if
(
app
.
isSessionRestored
()
&&
KMainWindow
::
canBeRestored
(
1
))
app
.
restoreInstance
();
else
app
.
newInstance
();
QObject
::
connect
(
&
service
,
&
KDBusService
::
activateRequested
,
&
app
,
&
Application
::
activate
);
if
(
app
.
isSessionRestored
()
)
{
kRestoreMainWindows
<
MainWindow
>
();
}
QObject
::
connect
(
&
service
,
&
KDBusService
::
openRequested
,
&
app
,
&
Application
::
open
);
return
app
.
exec
();
}
...
...
application.h
View file @
6dbd16ec
...
...
@@ -9,6 +9,7 @@
#include <QApplication>
#include <QCommandLineParser>
#include <QList>
#include <QUrl>
namespace
KHC
{
...
...
@@ -23,8 +24,15 @@ namespace KHC {
QCommandLineParser
*
cmdParser
();
void
newInstance
();
void
restoreInstance
();
public
Q_SLOTS
:
void
activate
(
const
QStringList
&
args
,
const
QString
&
workingDirectory
);
void
open
(
const
QList
<
QUrl
>&
urls
);
private:
void
activateForStartLikeCall
();
private:
MainWindow
*
mMainWindow
=
nullptr
;
...
...
org.kde.khelpcenter.desktop
View file @
6dbd16ec
...
...
@@ -214,5 +214,8 @@ Keywords[zh_CN]=man;info;documentation;handbook;manual;information;说明书;信
Categories=Qt;KDE;Core;
OnlyShowIn=KDE;
DBusActivatable=true
X-DBUS-StartupType=Unique
X-DBUS-ServiceName=org.kde.khelpcenter
SingleMainWindow=true
MimeType=x-scheme-handler/help;x-scheme-handler/man;x-scheme-handler/info;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment