Skip to content

Commit

Permalink
New notification system.
Browse files Browse the repository at this point in the history
The new system uses Qt5's own libraries and works on the AppImage.

Based on this https://gist.github.com/codito/dbd64bdc8cd51c58741a59537874e0be
  • Loading branch information
son-link committed May 15, 2023
1 parent ce7a77b commit b812116
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 223 deletions.
9 changes: 3 additions & 6 deletions PQMusic/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
from PyQt5.QtGui import QIcon, QPixmap, QStandardItem
from PyQt5 import QtWidgets
from pathlib import Path
from .utils import getMetaData, openM3U, saveM3U, getTrackerTitle
from .utils import getMetaData, openM3U, saveM3U, getTrackerTitle, notify
from urllib.parse import urlparse
from os import path, access, R_OK, mkdir, environ, listdir
from .sys_notify import Notification, init
from .covers import searchTrackInfo, downCover

import magic
Expand Down Expand Up @@ -52,8 +51,6 @@ def __init__(self, parent):
self.volume = 100
self.blockCoverSearch = False

init('pqmusic')

self.player.mediaStatusChanged.connect(self.qmp_mediaStatusChanged)
self.player.metaDataChanged.connect(self.metaDataChanged)
self.player.positionChanged.connect(self.qmp_positionChanged)
Expand Down Expand Up @@ -316,13 +313,13 @@ def __getcover(data):
self.parent.tray.setToolTip(trayTooltip)

if self.parent.config['shownotify']:
n = Notification(
notify(
'PQMusic',
trayTooltip,
notifyIcon,
timeout=3000
)
n.show()


def openPlaylist(self, file=None):
""" Opens the dialog to select files to add """
Expand Down
217 changes: 0 additions & 217 deletions PQMusic/sys_notify.py

This file was deleted.

31 changes: 31 additions & 0 deletions PQMusic/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
environ,
)
from os.path import isfile
from PyQt5 import QtDBus, QtCore
import psutil

LOCKFILE = '/tmp/pqmusic.lock'
Expand Down Expand Up @@ -233,3 +234,33 @@ def getTrackerTitle(filepath, ext=None):
fil = filter(str.isprintable, title)
title = "".join(fil)
return title


def notify(title, body='', icon='', timeout=-1):
item = "org.freedesktop.Notifications"
path = "/org/freedesktop/Notifications"
interface = "org.freedesktop.Notifications"
app_name = "pqmusic"
v = QtCore.QVariant(417598) # random int to identify all notifications

if v.convert(QtCore.QVariant.UInt):
id_replace = v

actions_list = QtDBus.QDBusArgument([], QtCore.QMetaType.QStringList)
hint = {}

bus = QtDBus.QDBusConnection.sessionBus()
if not bus.isConnected():
print("Not connected to dbus!")

notify = QtDBus.QDBusInterface(item, path, interface, bus)

if notify.isValid():
x = notify.call(QtDBus.QDBus.AutoDetect, "Notify", app_name,
id_replace, icon, title, body,
actions_list, hint, timeout)
if x.errorName():
print("Failed to send notification!")
print(x.errorMessage(), x.errorName())
else:
print("Invalid dbus interface")

0 comments on commit b812116

Please sign in to comment.