From d1b9bae155425c2d500b136111cc4f2f28fc0c16 Mon Sep 17 00:00:00 2001 From: Mavridis Philippe Date: Sun, 12 Dec 2021 16:24:28 +0200 Subject: KMix: system tray icon enhancements * XDG-compliant icon names with volume level specification (low, medium, high) Low-Medium threshold: 33% Medium-High threshold: 67% * Improved built-in icon theme with distinct volume levels (according to above) * Choice between classic KMix icon theme, imrpoved KMix icon theme and system theme. * New KMixDockWidget::getAvgVolume() method Gets average volume in %. Code actually comes from KMixDockWidget::setVolumeTip(), but was put into a separate method to be reused for determination of icon according to the volume level (cherry picked from commit 3168c39ef1e445db1a6e22a7ba63e8cb4714e6e8) --- kmix/kmixdockwidget.cpp | 97 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 88 insertions(+), 9 deletions(-) (limited to 'kmix/kmixdockwidget.cpp') diff --git a/kmix/kmixdockwidget.cpp b/kmix/kmixdockwidget.cpp index 574a996c..fba30421 100644 --- a/kmix/kmixdockwidget.cpp +++ b/kmix/kmixdockwidget.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -47,6 +48,7 @@ #include "mixer.h" #include "mixdevicewidget.h" #include "kmixdockwidget.h" +#include "kmixsettings.h" #include "viewdockareapopup.h" KMixDockWidget::KMixDockWidget( Mixer *mixer, TQWidget *parent, const char *name, bool volumePopup, bool dockIconMuting ) @@ -72,6 +74,9 @@ KMixDockWidget::KMixDockWidget( Mixer *mixer, TQWidget *parent, const char *name createActions(); createMasterVolWidget(); connect(this, TQ_SIGNAL(quitSelected()), kapp, TQ_SLOT(quitExtended())); + + TDEGlobal::dirs()->addResourceDir("icons_crystal", locate("appdata", "pics/crystal/")); + TDEGlobal::dirs()->addResourceDir("icons_oldcrystal", locate("appdata", "pics/oldcrystal/")); } KMixDockWidget::~KMixDockWidget() @@ -254,6 +259,20 @@ void KMixDockWidget::handleNewMaster(bool defaultMaster, int soundcard_id, const } +long +KMixDockWidget::getAvgVolume() +{ + MixDevice *md = 0; + if ( _dockAreaPopup != 0 ) { + md = _dockAreaPopup->dockDevice(); + } + + if ( md == 0 || md->maxVolume() == 0 ) + return -1; + + return (md->getVolume().getAvgVolume(Volume::MMAIN)*100 )/( md->maxVolume() ); +} + void KMixDockWidget::setVolumeTip() { @@ -261,6 +280,7 @@ KMixDockWidget::setVolumeTip() if ( _dockAreaPopup != 0 ) { md = _dockAreaPopup->dockDevice(); } + TQString tip = ""; int newToolTipValue = 0; @@ -271,10 +291,7 @@ KMixDockWidget::setVolumeTip() } else { - long val = -1; - if ( md->maxVolume() != 0 ) { - val = (md->getVolume().getAvgVolume(Volume::MMAIN)*100 )/( md->maxVolume() ); - } + long val = getAvgVolume(); newToolTipValue = val + 10000*md->isMuted(); if ( _oldToolTipValue != newToolTipValue ) { tip = i18n( "Volume at %1%" ).arg( val ); @@ -316,7 +333,13 @@ KMixDockWidget::updatePixmap(bool force) } else { - newPixmapType = 'd'; + long avgVol = getAvgVolume(); + if ( avgVol <= 33 ) + newPixmapType = 'L'; + else if ( avgVol <= 67 ) + newPixmapType = 'M'; + else + newPixmapType = 'H'; } if (( newPixmapType != _oldPixmapType ) || (force == true)) { @@ -325,12 +348,23 @@ KMixDockWidget::updatePixmap(bool force) TQPixmap origpixmap; TQPixmap scaledpixmap; TQImage newIcon; + + TQStringList fallback; switch ( newPixmapType ) { - case 'e': origpixmap = isShown() ? loadSizedIcon( "kmixdocked_error", width() ) : loadIcon( "kmixdocked_error"); break; - case 'm': origpixmap = isShown() ? loadSizedIcon( "kmixdocked_mute" , width() ) : loadIcon( "kmixdocked_mute"); break; - case 'd': origpixmap = isShown() ? loadSizedIcon( "kmixdocked" , width() ) : loadIcon( "kmixdocked "); break; + case 'm': fallback << "audio-volume-muted" << "kmixdocked_mute"; break; + case 'L': fallback << "audio-volume-low" << "kmixdocked"; break; + case 'M': fallback << "audio-volume-medium" << "kmixdocked"; break; + case 'H': fallback << "audio-volume-high" << "kmixdocked"; break; } - newIcon = origpixmap; + + TQString icon = getIconPath(fallback); + if (icon.isNull()) + { + icon = getIconPath("audio-volume-error"); + } + + origpixmap = isShown() ? loadSizedIcon(icon, width()) : loadIcon(icon); + newIcon = origpixmap; if (isShown()) { newIcon = newIcon.smoothScale(width(), height()); } @@ -341,6 +375,51 @@ KMixDockWidget::updatePixmap(bool force) } } +TQString KMixDockWidget::getIconPath(TQStringList fallback) +{ + auto iconTheme = KMixSettings::iconTheme(); + + TQCString iconThemeName; + if (iconTheme != KMixSettings::EnumIconTheme::System) + { + switch (iconTheme) + { + case KMixSettings::EnumIconTheme::OldCrystal: + iconThemeName = "oldcrystal"; + break; + + default: + case KMixSettings::EnumIconTheme::Crystal: + iconThemeName = "crystal"; + break; + } + } + + for (TQStringList::iterator it = fallback.begin(); it != fallback.end(); ++it) + { + if (iconTheme == KMixSettings::EnumIconTheme::System) + { + TQString iconPath = kapp->iconLoader()->iconPath((*it), TDEIcon::Panel, true); + if (!iconPath.isNull()) + { + return iconPath; + } + } + + else + { + TQCString type = "icons_" + iconThemeName; + + TQString iconPath = TDEGlobal::dirs()->findResource(type, TQString("%1.png").arg(*it)); + if (!iconPath.isNull()) return iconPath; + + iconPath = TDEGlobal::dirs()->findResource(type, TQString("%1.svg").arg(*it)); + if (!iconPath.isNull()) return iconPath; + } + } + return TQString::null; +} + void KMixDockWidget::resizeEvent ( TQResizeEvent * ) { updatePixmap(true); -- cgit v1.2.1