Commit e7d56107 authored by LordTermor's avatar LordTermor
Browse files

Added dependency on UpdatesChecker wrapper from libqpamac

parent abcd937f
......@@ -25,6 +25,9 @@ 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})
......
#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
......@@ -3,8 +3,7 @@
#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):QSystemTrayIcon(QIcon::fromTheme("pamac-tray-no-update"),parent)
{
......@@ -13,29 +12,27 @@ PamacTray::PamacTray(QObject *parent):QSystemTrayIcon(QIcon::fromTheme("pamac-tr
this->setContextMenu(create_menu());
connect(this, &QSystemTrayIcon::activated, 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);
connect(&m_updatesChecker, &LibQPamac::UpdatesChecker::updatesAvailable, [this](uint16_t updates_nb){
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();
setIcon(QIcon::fromTheme("pamac-tray-no-update"));
setToolTip(tr("Your system is up-to-date"));
setVisible(!m_updatesChecker.noUpdateHideIcon());
close_notification();
} else{
self->show_or_update_notification(updates_nb);
show_or_update_notification(updates_nb);
}
}), this);
});
QTimer::singleShot(30 * 1000, this, [=](){
pamac_updates_checker_check_updates(m_updatesChecker);
QTimer::singleShot(30*1000, this, [=](){
m_updatesChecker.checkUpdates();
});
updateCheckerTimerId = startTimer(3600*1000);
......@@ -113,7 +110,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,9 +2,9 @@
#include <QSystemTrayIcon>
#include <QMenu>
#include <QTimer>
#include <pamac.h>
#include <glib.h>
#include <QTimerEvent>
#include <UpdatesChecker.h>
#include <libnotify/notification.h>
class PamacTray : public QSystemTrayIcon
......@@ -15,7 +15,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,7 +27,7 @@ private Q_SLOTS:
void close_notification();
private:
int updateCheckerTimerId;
PamacUpdatesChecker* m_updatesChecker = nullptr;
LibQPamac::UpdatesChecker m_updatesChecker;
NotifyNotification* m_notification = nullptr;
QMenu* create_menu();
......
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