File indexing completed on 2024-05-19 04:48:46
0001 /**************************************************************************************** 0002 * Copyright (c) 2004-2007 Mark Kretschmann <kretschmann@kde.org> * 0003 * Copyright (c) 2004 Frederik Holljen <fh@ez.no> * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify it under * 0006 * the terms of the GNU General Public License as published by the Free Software * 0007 * Foundation; either version 2 of the License, or (at your option) any later * 0008 * version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0011 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0012 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0013 * * 0014 * You should have received a copy of the GNU General Public License along with * 0015 * this program. If not, see <http://www.gnu.org/licenses/>. * 0016 ****************************************************************************************/ 0017 0018 #include "NotificationsConfig.h" 0019 0020 #include "amarokconfig.h" 0021 #include "configdialog/ConfigDialog.h" 0022 #include "core/support/Debug.h" 0023 #include "KNotificationBackend.h" 0024 0025 #include <KWindowSystem> 0026 0027 #include <QDesktopWidget> 0028 0029 NotificationsConfig::NotificationsConfig( Amarok2ConfigDialog* parent ) 0030 : ConfigDialogBase( parent ) 0031 , m_oldAlignment( static_cast<OSDWidget::Alignment>( AmarokConfig::osdAlignment() ) ) 0032 , m_oldYOffset( AmarokConfig::osdYOffset() ) 0033 { 0034 setupUi( this ); 0035 0036 connect( this, &NotificationsConfig::changed, 0037 parent, &Amarok2ConfigDialog::updateButtons ); 0038 0039 m_osdPreview = new OSDPreviewWidget( this ); //must be child!!! 0040 m_osdPreview->setAlignment( static_cast<OSDWidget::Alignment>( AmarokConfig::osdAlignment() ) ); 0041 m_osdPreview->setYOffset( AmarokConfig::osdYOffset() ); 0042 m_osdPreview->setFontScale( AmarokConfig::osdFontScaling() ); 0043 m_osdPreview->setTranslucent( AmarokConfig::osdUseTranslucency() ); 0044 0045 #ifdef Q_WS_MAC 0046 QCheckBox* growl = new QCheckBox( i18n( "Use Growl for notifications" ), this ); 0047 growl->setChecked( AmarokConfig::growlEnabled() ); 0048 gridLayout_5->addWidget( growl, 2, 0, 1, 1 ); 0049 connect( growl, &QCheckBox::toggled, 0050 this, &NotificationsConfig::setGrowlEnabled ); 0051 #endif 0052 0053 // Enable/disable the translucency option depending on availability of desktop compositing 0054 kcfg_OsdUseTranslucency->setEnabled( KWindowSystem::compositingActive() ); 0055 0056 connect( m_osdPreview, &OSDPreviewWidget::positionChanged, this, &NotificationsConfig::slotPositionChanged ); 0057 0058 const int numScreens = QApplication::desktop()->numScreens(); 0059 for( int i = 0; i < numScreens; i++ ) 0060 kcfg_OsdScreen->addItem( QString::number( i ) ); 0061 0062 connect( kcfg_OsdTextColor, &KColorButton::changed, 0063 m_osdPreview, &OSDPreviewWidget::setTextColor ); 0064 connect( kcfg_OsdUseCustomColors, &QGroupBox::toggled, 0065 this, &NotificationsConfig::useCustomColorsToggled ); 0066 connect( kcfg_OsdScreen, QOverload<int>::of(&KComboBox::activated), 0067 m_osdPreview, &OSDPreviewWidget::setScreen ); 0068 connect( kcfg_OsdEnabled, &QGroupBox::toggled, 0069 m_osdPreview, &OSDPreviewWidget::setVisible ); 0070 connect( kcfg_OsdUseTranslucency, &QCheckBox::toggled, 0071 m_osdPreview, &OSDPreviewWidget::setTranslucent ); 0072 connect( kcfg_OsdFontScaling, QOverload<int>::of(&QSpinBox::valueChanged), 0073 m_osdPreview, &OSDPreviewWidget::setFontScale ); 0074 0075 /* 0076 Amarok::QStringx text = i18n( 0077 "<h3>Tags Displayed in OSD</h3>" 0078 "You can use the following tokens:" 0079 "<ul>" 0080 "<li>Title - %1" 0081 "<li>Album - %2" 0082 "<li>Artist - %3" 0083 "<li>Genre - %4" 0084 "<li>Bitrate - %5" 0085 "<li>Year - %6" 0086 "<li>Track Length - %7" 0087 "<li>Track Number - %8" 0088 "<li>Filename - %9" 0089 "<li>Directory - %10" 0090 "<li>Type - %11" 0091 "<li>Comment - %12" 0092 "<li>Score - %13" 0093 "<li>Playcount - %14" 0094 "<li>Disc Number - %15" 0095 "<li>Rating - %16" 0096 "<li>Elapsed Time - %17" 0097 "</ul>" 0098 "If you surround sections of text that contain a token with curly-braces, that section will be hidden if the token is empty, for example:" 0099 "<pre>%18</pre>" 0100 "Will not show <b>Score: <i>%score</i></b> if the track has no score." ); 0101 */ 0102 } 0103 0104 NotificationsConfig::~NotificationsConfig() 0105 {} 0106 0107 0108 /////////////////////////////////////////////////////////////// 0109 // REIMPLEMENTED METHODS from ConfigDialogBase 0110 /////////////////////////////////////////////////////////////// 0111 0112 bool 0113 NotificationsConfig::hasChanged() 0114 { 0115 DEBUG_BLOCK 0116 0117 return ( m_osdPreview->alignment() != m_oldAlignment ) || ( m_osdPreview->yOffset() != m_oldYOffset ); 0118 } 0119 0120 bool 0121 NotificationsConfig::isDefault() 0122 { 0123 return false; 0124 } 0125 0126 void 0127 NotificationsConfig::updateSettings() 0128 { 0129 DEBUG_BLOCK 0130 0131 AmarokConfig::setOsdAlignment( m_osdPreview->alignment() ); 0132 AmarokConfig::setOsdYOffset( m_osdPreview->yOffset() ); 0133 AmarokConfig::setOsdUseTranslucency( kcfg_OsdUseTranslucency->isChecked() ); 0134 0135 Amarok::OSD::instance()->setEnabled( kcfg_OsdEnabled->isChecked() ); 0136 0137 Amarok::KNotificationBackend::instance()->setEnabled( kcfg_KNotifyEnabled->isChecked() ); 0138 0139 Q_EMIT settingsChanged( QString() ); 0140 } 0141 0142 0143 /////////////////////////////////////////////////////////////// 0144 // PRIVATE METHODS 0145 /////////////////////////////////////////////////////////////// 0146 0147 void 0148 NotificationsConfig::slotPositionChanged() 0149 { 0150 DEBUG_BLOCK 0151 0152 kcfg_OsdScreen->blockSignals( true ); 0153 kcfg_OsdScreen->setCurrentIndex( m_osdPreview->screen() ); 0154 kcfg_OsdScreen->blockSignals( false ); 0155 0156 // Update button states (e.g. "Apply") 0157 Q_EMIT changed(); 0158 } 0159 0160 void 0161 NotificationsConfig::hideEvent( QHideEvent* ) 0162 { 0163 m_osdPreview->hide(); 0164 } 0165 0166 void 0167 NotificationsConfig::showEvent( QShowEvent* ) 0168 { 0169 useCustomColorsToggled( kcfg_OsdUseCustomColors->isChecked() ); 0170 0171 m_osdPreview->setScreen( kcfg_OsdScreen->currentIndex() ); 0172 m_osdPreview->setVisible( kcfg_OsdEnabled->isChecked() ); 0173 } 0174 0175 void 0176 NotificationsConfig::setGrowlEnabled( bool enable ) 0177 { 0178 DEBUG_BLOCK 0179 AmarokConfig::setGrowlEnabled( enable ); 0180 } 0181 0182 void 0183 NotificationsConfig::useCustomColorsToggled( bool on ) 0184 { 0185 m_osdPreview->setUseCustomColors( on, kcfg_OsdTextColor->color() ); 0186 } 0187