Commit 068aec9d authored by Jonathan Marten's avatar Jonathan Marten
Browse files

Use KMixToolBox::noDevicesWarningWidget() in 3 applicable dialogues

DialogAddView, DialogChooseBackends, DialogSelectMaster and KMix
(error message string only).
parent 951f5efb
......@@ -952,19 +952,6 @@ void KMixWindow::unplugged(const QString &udi)
}
/**
* Create a widget with an error message
* This widget shows an error message like "no mixers detected.
void KMixWindow::setErrorMixerWidget()
{
QString s = i18n("Please plug in your soundcard. No soundcard found. Probably you have not set it up or are missing soundcard drivers. Please check your operating system manual for installing your soundcard."); // !! better text
m_errorLabel = new QLabel( s,this );
m_errorLabel->setAlignment( Qt::AlignCenter );
m_errorLabel->setWordWrap(true);
m_errorLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
m_wsMixers->addTab( m_errorLabel, i18n("No soundcard found") );
}
*/
/**
*
......@@ -1255,12 +1242,12 @@ void KMixWindow::slotSelectMasterClose(QObject*)
void KMixWindow::slotSelectMaster()
{
Mixer *mixer = Mixer::getGlobalMasterMixer();
if (mixer != 0)
const Mixer *mixer = Mixer::getGlobalMasterMixer();
if (mixer!=nullptr)
{
if (!m_dsm)
{
m_dsm = new DialogSelectMaster(Mixer::getGlobalMasterMixer(), this);
m_dsm = new DialogSelectMaster(mixer, this);
connect(m_dsm, SIGNAL(destroyed(QObject*)), this, SLOT(slotSelectMasterClose(QObject*)));
m_dsm->setAttribute(Qt::WA_DeleteOnClose, true);
m_dsm->show();
......@@ -1270,7 +1257,7 @@ void KMixWindow::slotSelectMaster()
}
else
{
KMessageBox::error(0, i18n("No sound card is installed or currently plugged in."));
KMessageBox::error(nullptr, KMixToolBox::noDevicesWarningString());
}
}
......
......@@ -77,7 +77,7 @@ void MixSet::setName( const QString &name )
m_name = name;
}
shared_ptr<MixDevice> MixSet::get(const QString &id)
shared_ptr<MixDevice> MixSet::get(const QString &id) const
{
shared_ptr<MixDevice> mdRet;
......
......@@ -37,7 +37,7 @@ class KMIXCORE_EXPORT MixSet : public QList<shared_ptr<MixDevice> >
QString name() const { return m_name; }
void setName( const QString &name );
shared_ptr<MixDevice> get(const QString &id);
shared_ptr<MixDevice> get(const QString &id) const;
void removeById(const QString &id);
......
......@@ -30,6 +30,7 @@
#include <klocalizedstring.h>
#include "core/mixer.h"
#include "gui/kmixtoolbox.h"
static QStringList viewNames;
......@@ -37,14 +38,15 @@ static QStringList viewIds;
DialogAddView::DialogAddView(QWidget *parent, const Mixer *mixer)
: DialogBase( parent )
: DialogBase(parent)
{
// TODO 000 Adding View for MPRIS2 is broken. We need at least a dummy XML GUI Profile. Also the
// fixed list below is plain wrong. Actually we should get the Profile list from either the XML files or
// from the backend. The latter is probably easier for now.
if ( viewNames.isEmpty() )
{
// initialize static list. Later this list could be generated from the actually installed profiles
// Initialize static list.
// Maybe this list could be generated from the actually installed profiles.
viewNames.append(i18n("All controls"));
viewNames.append(i18n("Only playback controls"));
viewNames.append(i18n("Only capture controls"));
......@@ -54,21 +56,17 @@ DialogAddView::DialogAddView(QWidget *parent, const Mixer *mixer)
viewIds.append("capture");
}
setWindowTitle( i18n( "Add View" ) );
if ( Mixer::mixers().count() > 0 )
setButtons( QDialogButtonBox::Ok|QDialogButtonBox::Cancel );
else {
setButtons( QDialogButtonBox::Cancel );
}
m_listForChannelSelector = nullptr;
setWindowTitle(i18n("Add View"));
if (!Mixer::mixers().isEmpty()) setButtons(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
else setButtons(QDialogButtonBox::Cancel);
createWidgets(mixer); // for the specified 'mixer'
m_listForChannelSelector = nullptr;
createWidgets(mixer); // for the specified 'mixer'
}
/**
* Create basic widgets of the Dialog.
* Create basic widgets of the dialogue.
*/
void DialogAddView::createWidgets(const Mixer *mixer)
{
......@@ -123,9 +121,9 @@ void DialogAddView::createWidgets(const Mixer *mixer)
}
else
{
// TODO: see DialogChooseBackends::createWidgets()
QLabel *qlbl = new QLabel( i18n("No sound card is installed or currently plugged in."), mainFrame );
layout->addWidget(qlbl);
QWidget *noMixersWarning = KMixToolBox::noDevicesWarningWidget(mainFrame);
layout->addWidget(noMixersWarning);
layout->addStretch(1);
}
}
......
......@@ -27,9 +27,9 @@
#include <qlistwidget.h>
#include <klocalizedstring.h>
#include <kmessagewidget.h>
#include "core/mixer.h"
#include "gui/kmixtoolbox.h"
/**
* Creates a dialog to choose mixers from. All currently known mixers will be shown, and the given mixerID's
......@@ -60,13 +60,7 @@ void DialogChooseBackends::createWidgets(const QSet<QString> &mixerIds)
if (Mixer::mixers().isEmpty())
{
// TODO: to KMixToolbox - used here, DialogSelectMaster, DialogAddView
KMessageWidget *noMixersWarning = new KMessageWidget(i18n("No sound cards are installed or are currently available."), this);
noMixersWarning->setIcon(QIcon::fromTheme("dialog-warning"));
noMixersWarning->setMessageType(KMessageWidget::Warning);
noMixersWarning->setCloseButtonVisible(false);
noMixersWarning->setWordWrap(true);
QWidget *noMixersWarning = KMixToolBox::noDevicesWarningWidget(this);
vLayout->addWidget(noMixersWarning);
m_mixerList->setEnabled(false);
}
......
......@@ -29,34 +29,38 @@
#include <klocalizedstring.h>
#include "core/ControlManager.h"
#include "core/mixdevice.h"
#include "core/mixer.h"
#include "gui/kmixtoolbox.h"
DialogSelectMaster::DialogSelectMaster( Mixer *mixer, QWidget *parent )
: DialogBase( parent )
// TOD: Should this be incorporated into the "Configure KMix" dialogue?
DialogSelectMaster::DialogSelectMaster(const Mixer *mixer, QWidget *parent)
: DialogBase(parent)
{
setWindowTitle(i18n("Select Master Channel"));
if ( Mixer::mixers().count() > 0 )
setButtons(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
else {
setButtons(QDialogButtonBox::Cancel);
}
m_channelSelector = 0;
createWidgets(mixer); // Open with Mixer Hardware #0
if (Mixer::mixers().count()>0) setButtons(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
else setButtons(QDialogButtonBox::Cancel);
m_channelSelector = nullptr;
createWidgets(mixer); // for the specified 'mixer'
}
/**
* Create basic widgets of the Dialog.
* Create basic widgets of the dialogue.
*/
void DialogSelectMaster::createWidgets(Mixer *ptr_mixer)
void DialogSelectMaster::createWidgets(const Mixer *mixer)
{
QWidget *mainFrame = new QWidget(this);
setMainWidget(mainFrame);
QVBoxLayout *layout = new QVBoxLayout(mainFrame);
if ( Mixer::mixers().count() > 1 ) {
const QList<Mixer *> &mixers = Mixer::mixers(); // list of all mixers present
int mixerIndex = 0; // index of specified 'mixer'
if (mixers.count()>1)
{
// More than one Mixer => show Combo-Box to select Mixer
// Mixer widget line
QHBoxLayout* mixerNameLayout = new QHBoxLayout();
......@@ -73,57 +77,59 @@ void DialogSelectMaster::createWidgets(Mixer *ptr_mixer)
m_cMixer->setFixedHeight(m_cMixer->sizeHint().height());
connect( m_cMixer, SIGNAL(activated(int)), this, SLOT(createPageByID(int)) );
for( int i =0; i<Mixer::mixers().count(); i++ )
for (int i = 0; i<mixers.count(); ++i)
{
const Mixer *mixer = (Mixer::mixers())[i];
const shared_ptr<MixDevice> md = mixer->getLocalMasterMD();
const QString iconName = (md!=nullptr) ? md->iconName() : "media-playback-start";
m_cMixer->addItem(QIcon::fromTheme(iconName), mixer->readableName(), mixer->id() );
} // end for all_Mixers
// Make the current Mixer the current item in the ComboBox
int findIndex = m_cMixer->findData( ptr_mixer->id() );
if ( findIndex != -1 ) m_cMixer->setCurrentIndex( findIndex );
const Mixer *m = mixers[i];
const QString name = m->readableName();
m_cMixer->addItem(QIcon::fromTheme(m->iconName()), name);
if (name==mixer->readableName()) mixerIndex = i;
}
// Select the specified 'mixer' as the current item in the combo box.
// If it was not found by the loop above, then select the first item.
m_cMixer->setCurrentIndex(mixerIndex);
m_cMixer->setToolTip( i18n("Current mixer" ) );
mixerNameLayout->addWidget(m_cMixer, 1);
layout->addSpacing(DialogBase::verticalSpacing());
}
} // end if (more_than_1_Mixer)
if ( Mixer::mixers().count() > 0 ) {
QLabel *qlbl = new QLabel( i18n("Select the channel representing the master volume:"), mainFrame );
if (mixers.count()>0)
{
QLabel *qlbl = new QLabel(i18n("Select the channel representing the master volume:"), mainFrame);
layout->addWidget(qlbl);
createPage(ptr_mixer);
connect(this, SIGNAL(accepted()), this, SLOT(apply()));
createPage(mixer);
connect(this, &QDialog::accepted, this, &DialogSelectMaster::apply);
}
else {
// TODO: see DialogChooseBackends::createWidgets()
QLabel *qlbl = new QLabel( i18n("No sound card is installed or currently plugged in."), mainFrame );
layout->addWidget(qlbl);
else
{
QWidget *noMixersWarning = KMixToolBox::noDevicesWarningWidget(mainFrame);
layout->addWidget(noMixersWarning);
layout->addStretch(1);
}
}
/**
* Create RadioButton's for the Mixer with number 'mixerId'.
* @par mixerId The Mixer, for which the RadioButton's should be created.
* Create the channel list for the specified mixer
*
* @p mixerId the ID (index) of the mixer for which the list should be created.
*/
void DialogSelectMaster::createPageByID(int mixerId)
{
QString mixer_id = m_cMixer->itemData(mixerId).toString();
Mixer * mixer = Mixer::findMixer(mixer_id);
if ( mixer != NULL )
createPage(mixer);
const QString mixer_id = m_cMixer->itemData(mixerId).toString();
const Mixer *mixer = Mixer::findMixer(mixer_id);
if (mixer!=nullptr) createPage(mixer);
}
/**
* Create RadioButton's for the Mixer with number 'mixerId'.
* @par mixerId The Mixer, for which the RadioButton's should be created.
* Create the channel list for the specified mixer
*
* @p mixer the mixer for which the list should be created
*/
void DialogSelectMaster::createPage(Mixer* mixer)
void DialogSelectMaster::createPage(const Mixer *mixer)
{
/** --- Reset page -----------------------------------------------
* In case the user selected a new Mixer via m_cMixer, we need
* to remove the stuff created on the last call.
......@@ -131,7 +137,6 @@ void DialogSelectMaster::createPage(Mixer* mixer)
// delete the list widget.
// This should automatically remove all contained items.
delete m_channelSelector;
/** Reset page end -------------------------------------------------- */
......@@ -148,83 +153,79 @@ void DialogSelectMaster::createPage(Mixer* mixer)
m_channelSelector->setAlternatingRowColors(true);
layout->addWidget(m_channelSelector);
// shared_ptr<MixDevice> master = mixer->getLocalMasterMD();
// QString masterKey = ( master.get() != 0 ) ? master->id() : "----noMaster---"; // Use non-matching name as default
const MixSet& mixset = mixer->getMixSet();
MixSet& mset = const_cast<MixSet&>(mixset);
const MixSet &mixset = mixer->getMixSet();
const MixSet &mset = const_cast<MixSet &>(mixset);
MasterControl mc = mixer->getGlobalMasterPreferred(false);
const MasterControl mc = mixer->getGlobalMasterPreferred(false);
QString masterKey = mc.getControl();
if (!masterKey.isEmpty() && !mset.get(masterKey))
{
shared_ptr<MixDevice> master = mixer->getLocalMasterMD();
if (master.get() != 0)
masterKey = master->id();
const shared_ptr<MixDevice> master = mixer->getLocalMasterMD();
if (master.get()!=nullptr) masterKey = master->id();
}
int msetCount = 0;
for (int i = 0; i < mset.count(); ++i)
{
shared_ptr<MixDevice> md = mset[i];
if ( md->playbackVolume().hasVolume() )
++msetCount;
}
{
const shared_ptr<MixDevice> md = mset[i];
if (md->playbackVolume().hasVolume()) ++msetCount;
}
if (msetCount > 0 && !mixer->isDynamic())
{
QString mdName = i18n("Automatic (%1 recommendation)", mixer->getDriverName());
auto *item = new QListWidgetItem(QIcon::fromTheme("audio-volume-high"), mdName, m_channelSelector);
item->setData(Qt::UserRole, QString()); // ID here: see apply(), empty String => Automatic
if (masterKey.isEmpty())
m_channelSelector->setCurrentItem(item);
auto *item = new QListWidgetItem(QIcon::fromTheme("audio-volume-high"), mdName, m_channelSelector);
item->setData(Qt::UserRole, QString()); // ID here: see apply(), empty String => Automatic
if (masterKey.isEmpty()) m_channelSelector->setCurrentItem(item);
}
// Populate ListView with the MixDevice's having a playbakc volume (excludes pure capture controls and pure enum's)
// Populate the list view with the MixDevice's having a playback volume
// (excludes pure capture controls and pure enum's)
for (int i = 0; i < mset.count(); ++i)
{
shared_ptr<MixDevice> md = mset[i];
if ( md->playbackVolume().hasVolume() )
{
QString mdName = md->readableName();
auto *item = new QListWidgetItem(QIcon::fromTheme(md->iconName()), mdName, m_channelSelector);
item->setData(Qt::UserRole, md->id()); // ID here: see apply()
if ( md->id() == masterKey )
{ // select the current master
m_channelSelector->setCurrentItem(item);
const shared_ptr<MixDevice> md = mset[i];
if (md->playbackVolume().hasVolume())
{
const QString mdName = md->readableName();
auto *item = new QListWidgetItem(QIcon::fromTheme(md->iconName()), mdName, m_channelSelector);
item->setData(Qt::UserRole, md->id()); // ID here: see apply()
if (md->id() == masterKey)
{ // select the current master
m_channelSelector->setCurrentItem(item);
}
}
}
}
setButtonEnabled(QDialogButtonBox::Ok, m_channelSelector->count()>0);
setButtonEnabled(QDialogButtonBox::Ok, m_channelSelector->count()>0);
}
void DialogSelectMaster::apply()
{
Mixer *mixer = 0;
if ( Mixer::mixers().count() == 1 ) {
// only one mxier => no combo box => take first entry
mixer = (Mixer::mixers())[0];
const QList<Mixer *> &mixers = Mixer::mixers(); // list of all mixers present
Mixer *mixer = nullptr; // selected mixer found
if (mixers.count()==1)
{
// only one mixer => no combo box => take first entry
mixer = mixers.first();
}
else if ( Mixer::mixers().count() > 1 ) {
// find mixer that is currently active in the ComboBox
int idx = m_cMixer->currentIndex();
QString mixer_id = m_cMixer->itemData(idx).toString();
mixer = Mixer::findMixer(mixer_id);
else if (mixers.count()>1)
{
// use the mixer that is currently selected in the combo box
const int idx = m_cMixer->currentIndex();
if (idx!=-1) mixer = mixers.at(idx);
}
if ( mixer == 0 )
return; // User must have unplugged everything
if (mixer==nullptr) return; // user must have unplugged everything
QList<QListWidgetItem *> items = m_channelSelector->selectedItems();
if (items.count()==1)
{
QListWidgetItem *item = items.first();
QString control_id = item->data(Qt::UserRole).toString();
mixer->setLocalMasterMD( control_id );
Mixer::setGlobalMaster(mixer->id(), control_id, true);
ControlManager::instance().announce(mixer->id(), ControlManager::MasterChanged, QString("Select Master Dialog"));
}
mixer->setLocalMasterMD( control_id );
Mixer::setGlobalMaster(mixer->id(), control_id, true);
ControlManager::instance().announce(mixer->id(), ControlManager::MasterChanged, QString("Select Master Dialog"));
}
}
......@@ -34,15 +34,16 @@ class DialogSelectMaster : public DialogBase
Q_OBJECT
public:
explicit DialogSelectMaster(Mixer *mixer = nullptr, QWidget *parent = nullptr);
explicit DialogSelectMaster(const Mixer *mixer = nullptr, QWidget *parent = nullptr);
virtual ~DialogSelectMaster() = default;
public slots:
void apply();
private:
void createWidgets(Mixer*);
void createPage(Mixer*);
void createWidgets(const Mixer *mixer);
void createPage(const Mixer *mixer);
QComboBox* m_cMixer;
QListWidget *m_channelSelector;
......
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