Commit a892398a authored by LordTermor's avatar LordTermor
Browse files

moved from QSystemTrayIcon to KStatusNotifierItem

parent e2369bc6
......@@ -8,10 +8,11 @@ set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
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)
......
#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();
}
......@@ -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::activated, this,
connect(this, &KStatusNotifierItem::activateRequested, 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::fromTheme("pamac-tray-no-update"));
setToolTip(tr("Your system is up-to-date"));
setVisible(!m_updatesChecker.noUpdateHideIcon());
close_notification();
} else{
show_or_update_notification(updates_nb);
}
});
QTimer::singleShot(30*1000, this, [=](){
if(updates_nb == 0){
setIconByName("pamac-tray-no-update");
setToolTipTitle(tr("Your system is up-to-date"));
setStatus(m_updatesChecker.noUpdateHideIcon()?ItemStatus::Passive:ItemStatus::Active);
close_notification();
} else{
show_or_update_notification(m_updatesChecker.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::fromTheme("pamac-tray-update"));
setToolTip(info);
setVisible(true);
setIconByName("pamac-tray-update");
setToolTipTitle(info);
setStatus(ItemStatus::Active);
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;
......
......@@ -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:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment