Commit 4c1d8467 authored by LordTermor's avatar LordTermor
Browse files
parents f638a3f8 8ecd2c84
......@@ -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)
......@@ -25,10 +26,14 @@ add_executable(pamac-tray-plasma
pamac_tray.h
run_guard.cpp
run_guard.h
# temporary while libqpamac is tied to pamac-qt
UpdatesChecker.cpp
UpdatesChecker.h
)
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 "UpdatesChecker.h"
#include <glib.h>
namespace LibQPamac {
UpdatesChecker::UpdatesChecker(QObject *parent) : QObject(parent),
m_handle(pamac_updates_checker_new())
{
_init();
}
void UpdatesChecker::checkUpdates()
{
return pamac_updates_checker_check_updates(m_handle);
}
void UpdatesChecker::_init()
{
g_signal_connect(m_handle, "updates_available", reinterpret_cast<GCallback>(+[](PamacUpdatesChecker* checker, int updates_nb, void* selfPtr){
auto self = reinterpret_cast<UpdatesChecker*>(selfPtr);
Q_EMIT self->updatesAvailable(updates_nb);
}) ,this);
}
} // namespace LibQPamac
#pragma once
#include <QObject>
#include <pamac.h>
namespace LibQPamac {
#define LIBQPAMAC_PROPERTY_GET(type, name, method) \
Q_PROPERTY(type name READ name CONSTANT)\
inline type name() const \
{\
return type(method);\
}
class UpdatesChecker : public QObject
{
Q_OBJECT
public:
LIBQPAMAC_PROPERTY_GET(bool, noUpdateHideIcon, pamac_updates_checker_get_no_update_hide_icon(m_handle))
LIBQPAMAC_PROPERTY_GET(uint16_t, updatesNb, pamac_updates_checker_get_updates_nb(m_handle))
LIBQPAMAC_PROPERTY_GET(uint32_t, refreshPeriod, pamac_updates_checker_get_refresh_period(m_handle))
explicit UpdatesChecker(QObject *parent = nullptr);
void checkUpdates();
Q_SIGNALS:
int updatesAvailable(uint16_t updatesNb);
private:
void _init();
PamacUpdatesChecker* m_handle;
};
} // namespace LibQPamac
#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("pamac-tray-plasma");
QApplication a(argc, argv);
notify_init("Package Manager");
QApplication::setQuitOnLastWindowClosed(false);
QApplication::setApplicationName("Pamac Updates");
PamacTray tray;
tray.show();
return a.exec();
return QApplication::exec();
}
......@@ -3,39 +3,38 @@
#include <QAction>
#include <QApplication>
PamacTray::PamacTray(QObject *parent):QSystemTrayIcon(QIcon::fromTheme("pamac-tray-no-update"),parent),
m_updatesChecker(pamac_updates_checker_new())
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(pamac_updates_checker_get_updates_nb(m_updatesChecker)>0){
if(m_updatesChecker.updatesNb()>0){
execute_updater();
} else{
execute_manager();
}
});
g_signal_connect(m_updatesChecker, "updates_available", reinterpret_cast<GCallback>(+[](PamacUpdatesChecker* checker, int updates_nb, void* selfPtr){
auto self = reinterpret_cast<PamacTray*>(selfPtr);
if(updates_nb == 0){
self->setIcon(QIcon::fromTheme("pamac-tray-no-update"));
self->setToolTip(tr("Your system is up-to-date"));
self->setVisible(!pamac_updates_checker_get_no_update_hide_icon(checker));
self->close_notification();
} else{
self->show_or_update_notification(updates_nb);
}
connect(&m_updatesChecker, &LibQPamac::UpdatesChecker::updatesAvailable, [this](uint16_t updates_nb){
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());
}
}), this);
});
QTimer::singleShot(30 * 1000, this, [=](){
pamac_updates_checker_check_updates(m_updatesChecker);
QTimer::singleShot(1, this, [=](){
m_updatesChecker.checkUpdates();
});
updateCheckerTimerId = startTimer(3600*1000);
......@@ -57,7 +56,7 @@ void PamacTray::show_notification(QString info)
close_notification();
m_notification = notify_notification_new(tr("Package Manager").toUtf8(), info.toUtf8(), "system-software-install-symbolic");
m_info = info;
notify_notification_set_timeout(m_notification, NOTIFY_EXPIRES_DEFAULT);
notify_notification_add_action(m_notification, "default", tr("Details").toUtf8(),+[](NotifyNotification*, char*, void* selfPtr){
......@@ -72,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);
}
......@@ -82,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 && m_info!=info){
notify_notification_update(m_notification, tr("Package Manager").toUtf8(),
info.toUtf8(), "system-software-install-symbolic");
notify_notification_show(m_notification,nullptr);
m_info = info;
notify_notification_show(m_notification,nullptr);
}
} else{
show_notification(info);
......@@ -112,7 +112,7 @@ QMenu* PamacTray::create_menu()
action = new QAction(menu);
action->setText(tr("Quit"));
connect(action, &QAction::triggered, [](){QApplication::quit();});
connect(action, &QAction::triggered,this , &QApplication::quit);
menu->addAction(action);
return menu;
......
......@@ -2,12 +2,13 @@
#include <QSystemTrayIcon>
#include <QMenu>
#include <QTimer>
#include <pamac.h>
#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:
......@@ -15,7 +16,7 @@ public:
void timerEvent(QTimerEvent* e) override {
if (e->timerId() == updateCheckerTimerId){
pamac_updates_checker_check_updates(m_updatesChecker);
m_updatesChecker.checkUpdates();
}
}
private Q_SLOTS:
......@@ -27,10 +28,10 @@ private Q_SLOTS:
void close_notification();
private:
int updateCheckerTimerId;
PamacUpdatesChecker* m_updatesChecker = nullptr;
LibQPamac::UpdatesChecker m_updatesChecker;
NotifyNotification* m_notification = nullptr;
QMenu* create_menu();
QString m_info;
};
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