Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
9
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Open sidebar
LordTermor
Pamac tray icon for plasma
Commits
a892398a
Commit
a892398a
authored
Sep 01, 2020
by
LordTermor
Browse files
moved from QSystemTrayIcon to KStatusNotifierItem
parent
e2369bc6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
28 deletions
+34
-28
CMakeLists.txt
CMakeLists.txt
+4
-2
main.cpp
main.cpp
+4
-4
pamac_tray.cpp
pamac_tray.cpp
+24
-21
pamac_tray.h
pamac_tray.h
+2
-1
No files found.
CMakeLists.txt
View file @
a892398a
...
...
@@ -8,10 +8,11 @@ set(CMAKE_AUTOUIC ON)
set
(
CMAKE_AUTOMOC ON
)
set
(
CMAKE_AUTORCC ON
)
set
(
CMAKE_CXX_STANDARD 1
1
)
set
(
CMAKE_CXX_STANDARD 1
7
)
set
(
CMAKE_CXX_STANDARD_REQUIRED ON
)
find_package
(
Qt5 COMPONENTS Core Widgets
)
find_package
(
KF5Notifications
)
find_package
(
PkgConfig
)
add_definitions
(
-DQT_NO_KEYWORDS
)
...
...
@@ -31,7 +32,8 @@ add_executable(pamac-tray-plasma
)
target_include_directories
(
pamac-tray-plasma PUBLIC
${
DEPS_INCLUDE_DIRS
}
)
target_link_libraries
(
pamac-tray-plasma Qt5::Core Qt5::Widgets
${
DEPS_LDFLAGS
}
)
target_link_libraries
(
pamac-tray-plasma Qt5::Core Qt5::Widgets
${
DEPS_LDFLAGS
}
KF5::Notifications
)
configure_file
(
pamac-tray-plasma.desktop.in pamac-tray-plasma.desktop
)
...
...
main.cpp
View file @
a892398a
#include <QApplication>
#include <libnotify/notify.h>
#include <pamac_tray.h>
#include <run_guard.h>
#include <libnotify/notify.h>
int
main
(
int
argc
,
char
*
argv
[])
{
RunGuard
guard
(
"org.manjaro.pamac.tray-plasma"
);
if
(
!
guard
.
tryToRun
()){
return
0
;
}
notify_init
(
"
Package Manager
"
);
notify_init
(
"
pamac-tray-plasma
"
);
QApplication
a
(
argc
,
argv
);
QApplication
::
setQuitOnLastWindowClosed
(
false
);
QApplication
::
setApplicationName
(
"pamac-tray-plasma"
);
PamacTray
tray
;
tray
.
show
();
return
QApplication
::
exec
();
}
pamac_tray.cpp
View file @
a892398a
...
...
@@ -3,14 +3,16 @@
#include <QAction>
#include <QApplication>
PamacTray
::
PamacTray
(
QObject
*
parent
)
:
QSystemTrayIcon
(
QIcon
::
fromTheme
(
"pamac-tray-no-update"
),
parent
)
PamacTray
::
PamacTray
(
QObject
*
parent
)
:
KStatusNotifierItem
(
parent
)
{
setToolTip
(
"Your system is up-to-date"
);
setToolTipTitle
(
tr
(
"Your system is up-to-date"
));
setIconByName
(
"pamac-tray-no-update"
);
setStandardActionsEnabled
(
false
);
this
->
setContextMenu
(
create_menu
());
connect
(
this
,
&
QSystemTrayIcon
::
activa
ted
,
this
,
connect
(
this
,
&
KStatusNotifierItem
::
activateReques
ted
,
this
,
[
=
](){
if
(
m_updatesChecker
.
updatesNb
()
>
0
){
execute_updater
();
...
...
@@ -20,18 +22,18 @@ PamacTray::PamacTray(QObject *parent):QSystemTrayIcon(QIcon::fromTheme("pamac-tr
});
connect
(
&
m_updatesChecker
,
&
LibQPamac
::
UpdatesChecker
::
updatesAvailable
,
[
this
](
uint16_t
updates_nb
){
if
(
updates_nb
==
0
){
setIcon
(
QIcon
::
fromThe
me
(
"pamac-tray-no-update"
)
)
;
setToolTip
(
tr
(
"Your system is up-to-date"
));
set
Visible
(
!
m_updatesChecker
.
noUpdateHideIcon
());
close_notification
();
}
else
{
show_or_update_notification
(
updates
_nb
);
}
});
QTimer
::
singleShot
(
30
*
1000
,
this
,
[
=
](){
if
(
updates_nb
==
0
){
setIcon
ByNa
me
(
"pamac-tray-no-update"
);
setToolTip
Title
(
tr
(
"Your system is up-to-date"
));
set
Status
(
m_updatesChecker
.
noUpdateHideIcon
()
?
ItemStatus
::
Passive
:
ItemStatus
::
Active
);
close_notification
();
}
else
{
show_or_update_notification
(
m_
updates
Checker
.
updatesNb
()
);
}
});
QTimer
::
singleShot
(
1
,
this
,
[
=
](){
m_updatesChecker
.
checkUpdates
();
});
updateCheckerTimerId
=
startTimer
(
3600
*
1000
);
...
...
@@ -69,9 +71,9 @@ void PamacTray::show_or_update_notification(uint updates_nb)
{
QString
info
=
tr
(
"%n available update(s)"
,
""
,
updates_nb
);
setIcon
(
QIcon
::
fromThe
me
(
"pamac-tray-update"
)
)
;
setToolTip
(
info
);
set
Visible
(
tru
e
);
setIcon
ByNa
me
(
"pamac-tray-update"
);
setToolTip
Title
(
info
);
set
Status
(
ItemStatus
::
Activ
e
);
update_notification
(
info
);
}
...
...
@@ -79,11 +81,12 @@ void PamacTray::show_or_update_notification(uint updates_nb)
void
PamacTray
::
update_notification
(
QString
info
)
{
if
(
m_notification
!=
nullptr
){
if
(
notify_notification_get_closed_reason
(
m_notification
)
==
-
1
)
if
(
notify_notification_get_closed_reason
(
m_notification
)
==
-
1
)
{
notify_notification_update
(
m_notification
,
tr
(
"Package Manager"
).
toUtf8
(),
info
.
toUtf8
(),
"system-software-install-symbolic"
);
notify_notification_show
(
m_notification
,
nullptr
);
notify_notification_show
(
m_notification
,
nullptr
);
}
}
else
{
show_notification
(
info
);
...
...
@@ -110,7 +113,7 @@ QMenu* PamacTray::create_menu()
action
=
new
QAction
(
menu
);
action
->
setText
(
tr
(
"Quit"
));
connect
(
action
,
&
QAction
::
triggered
,
this
,
[](){
QApplication
::
quit
();}
);
connect
(
action
,
&
QAction
::
triggered
,
this
,
&
QApplication
::
quit
);
menu
->
addAction
(
action
);
return
menu
;
...
...
pamac_tray.h
View file @
a892398a
...
...
@@ -5,9 +5,10 @@
#include <glib.h>
#include <QTimerEvent>
#include <UpdatesChecker.h>
#include <KStatusNotifierItem>
#include <libnotify/notification.h>
class
PamacTray
:
public
QSystemTrayIcon
class
PamacTray
:
public
KStatusNotifierItem
{
Q_OBJECT
public:
...
...
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