kupdatenotifier: new app to notify for software updates

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-04-07 17:23:41 +03:00
parent 599a545c40
commit 98d4b016a7
6 changed files with 207 additions and 0 deletions

View file

@ -26,3 +26,4 @@ macro_optional_add_subdirectory (zeroconf-ioslave)
macro_optional_add_subdirectory (kdestopspy)
macro_optional_add_subdirectory (kvolume)
macro_optional_add_subdirectory (ksnapshot)
macro_optional_add_subdirectory (kupdatenotifier)

View file

@ -0,0 +1,28 @@
project(kupdatenotifier)
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
find_package(KDE4 4.21.0 REQUIRED)
include(KDE4Defaults)
include_directories(${KDE4_INCLUDES})
add_definitions(${QT_DEFINITIONS} ${KDE4_DEFINITIONS})
endif()
########### next target ###############
set(kupdatenotifier_SRCS
main.cpp
kupdatenotifier.cpp
)
add_executable(kupdatenotifier ${kupdatenotifier_SRCS})
target_link_libraries(kupdatenotifier ${KDE4_KDEUI_LIBS})
install(TARGETS kupdatenotifier ${INSTALL_TARGETS_DEFAULT_ARGS})
########### next target ###############
install(
PROGRAMS kupdatenotifier.desktop
DESTINATION ${KDE4_XDG_APPS_INSTALL_DIR}
)

View file

@ -0,0 +1,68 @@
/* This file is part of the KDE project
Copyright (C) 2022 Ivailo Monev <xakepa10@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2, as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "kupdatenotifier.h"
#include <kactioncollection.h>
#include <kcomponentdata.h>
#include <klocale.h>
#include <kglobal.h>
#include <kdebug.h>
// for reference:
// https://www.freedesktop.org/software/PackageKit/gtk-doc/PackageKit.html
#define PACKAGEKIT_SERVICE "org.freedesktop.PackageKit"
#define PACKAGEKIT_PATH "/org/freedesktop/PackageKit"
#define PACKAGEKIT_IFACE "org.freedesktop.PackageKit"
KUpdateNotifier::KUpdateNotifier(QObject* parent)
: KStatusNotifierItem(parent),
m_menu(nullptr),
m_helpmenu(nullptr),
m_interface(PACKAGEKIT_SERVICE, PACKAGEKIT_PATH, PACKAGEKIT_IFACE, QDBusConnection::systemBus(), this)
{
setTitle(i18n("Update notifier"));
setCategory(KStatusNotifierItem::SystemServices);
setIconByName("system-software-update");
setStatus(KStatusNotifierItem::Passive);
m_menu = new KMenu(associatedWidget());
setContextMenu(m_menu);
m_helpmenu = new KHelpMenu(associatedWidget(), KGlobal::mainComponent().aboutData());
m_menu->addMenu(m_helpmenu->menu());
if (m_interface.isValid()) {
connect(&m_interface, SIGNAL(UpdatesChanged()), this, SLOT(slotUpdatesChanged()));
// qDebug() << Q_FUNC_INFO << m_interface.property("NetworkState");
} else {
setOverlayIconByName("dialog-error");
showMessage(i18n("Update notifier"), i18n("PackageKit interface is not valid"), "dialog-error");
}
}
KUpdateNotifier::~KUpdateNotifier()
{
}
void KUpdateNotifier::slotUpdatesChanged()
{
// qDebug() << Q_FUNC_INFO;
setStatus(KStatusNotifierItem::NeedsAttention);
showMessage(i18n("Update notifier"), i18n("Updates available"), "vcs-update-required");
}

View file

@ -0,0 +1,9 @@
[Desktop Entry]
Name=KUpdateNotifier
GenericName=Update notifier
Comment=A panel applet for software updates notification.
Exec=kupdatenotifier --icon '%i' --caption '%c'
Icon=system-software-update
Type=Application
OnlyShowIn=KDE;
Categories=Qt;KDE;System;

View file

@ -0,0 +1,43 @@
/* This file is part of the KDE project
Copyright (C) 2022 Ivailo Monev <xakepa10@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2, as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KUPDATENOTIFIER_H
#define KUPDATENOTIFIER_H
#include <QDBusInterface>
#include <kstatusnotifieritem.h>
#include <kmenu.h>
#include <khelpmenu.h>
class KUpdateNotifier : public KStatusNotifierItem
{
Q_OBJECT
public:
KUpdateNotifier(QObject* parent = nullptr);
~KUpdateNotifier();
private Q_SLOTS:
void slotUpdatesChanged();
private:
KMenu* m_menu;
KHelpMenu* m_helpmenu;
QDBusInterface m_interface;
};
#endif // KUPDATENOTIFIER_H

58
kupdatenotifier/main.cpp Normal file
View file

@ -0,0 +1,58 @@
/* This file is part of the KDE project
Copyright (C) 2022 Ivailo Monev <xakepa10@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2, as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <kuniqueapplication.h>
#include <klocale.h>
#include <kcmdlineargs.h>
#include <kaboutdata.h>
#include <kdebug.h>
#include "kupdatenotifier.h"
int main(int argc, char** argv)
{
KAboutData aboutData(
"kupdatenotifier", 0, ki18n("KUpdateNotifier"),
"1.0.0", ki18n("A panel applet for software updates notification."),
KAboutData::License_GPL_V2,
ki18n("(c) 2022 Ivailo Monev"),
KLocalizedString(),
"http://github.com/fluxer/katana"
);
aboutData.addAuthor(
ki18n("Ivailo Monev"),
ki18n("Maintainer"),
"xakepa10@gmail.com"
);
aboutData.setProgramIconName(QLatin1String("system-software-update"));
KCmdLineArgs::init(argc, argv, &aboutData);
KUniqueApplication::addCmdLineOptions();
KUniqueApplication kupdatenotifierapp;
kupdatenotifierapp.setQuitOnLastWindowClosed(false);
if (!KUniqueApplication::start()) {
kWarning() << "kupdatenotifier is already running!";
return 0;
}
KUpdateNotifier kupdatenotifier(&kupdatenotifierapp);
return kupdatenotifierapp.exec();
}