Commit cf1305a2 authored by Tigran Gabrielyan's avatar Tigran Gabrielyan Committed by Nate Graham

Fix Default Applications KCM window size

Summary:
Config widgets were loading in when a service item was clicked.
This change loads all config widgets at the start so the window can be sized to the largest widget.

BUG: 398799
FIXED-IN: 5.16.0

Reviewers: #plasma, ngraham

Reviewed By: ngraham

Subscribers: ngraham, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D20072
parent 0bba1a43
......@@ -134,93 +134,68 @@ ComponentChooser::ComponentChooser(QWidget *parent):
cg.readEntry("Name",i18n("Unknown")));
item->setData(Qt::UserRole, (*it));
ServiceChooser->addItem(item);
loadConfigWidget((*it), cfg.group(QByteArray()).readEntry("configurationType"), item->text());
}
ServiceChooser->setFixedWidth(ServiceChooser->sizeHintForColumn(0) + 20);
ServiceChooser->sortItems();
connect(ServiceChooser,&QListWidget::currentItemChanged,this,&ComponentChooser::slotServiceSelected);
ServiceChooser->setCurrentRow(0);
slotServiceSelected(ServiceChooser->item(0));
}
void ComponentChooser::slotServiceSelected(QListWidgetItem* it) {
if (!it) return;
if (somethingChanged) {
if (KMessageBox::questionYesNo(this,i18n("<qt>You changed the default component of your choice, do want to save that change now ?</qt>"),QString(),KStandardGuiItem::save(),KStandardGuiItem::discard())==KMessageBox::Yes) save();
}
KConfig cfg(it->data(Qt::UserRole).toString(), KConfig::SimpleConfig);
ComponentDescription->setText(cfg.group(QByteArray()).readEntry("Comment",i18n("No description available")));
ComponentDescription->setMinimumSize(ComponentDescription->sizeHint());
QString cfgType=cfg.group(QByteArray()).readEntry("configurationType");
QWidget *newConfigWidget = nullptr;
if (cfgType.isEmpty() || (cfgType==QLatin1String("component")))
void ComponentChooser::loadConfigWidget(const QString &service, const QString &cfgType, const QString &name)
{
QWidget *loadedConfigWidget = nullptr;
if (cfgType.isEmpty() || (cfgType == QLatin1String("component")))
{
if (!(configWidget && qobject_cast<CfgComponent*>(configWidget)))
{
CfgComponent* cfgcomp = new CfgComponent(configContainer);
cfgcomp->ChooserDocu->setText(i18n("Choose from the list below which component should be used by default for the %1 service.", it->text()));
newConfigWidget = cfgcomp;
}
else
{
static_cast<CfgComponent*>(configWidget)->ChooserDocu->setText(i18n("Choose from the list below which component should be used by default for the %1 service.", it->text()));
}
loadedConfigWidget = new CfgComponent(configContainer);
static_cast<CfgComponent*>(loadedConfigWidget)->ChooserDocu->setText(i18n("Choose from the list below which component should be used by default for the %1 service.", name));
}
else if (cfgType==QLatin1String("internal_email"))
{
if (!(configWidget && qobject_cast<CfgEmailClient*>(configWidget)))
{
newConfigWidget = new CfgEmailClient(configContainer);
}
loadedConfigWidget = new CfgEmailClient(configContainer);
}
#ifdef Q_OS_UNIX
else if (cfgType==QLatin1String("internal_terminal"))
{
if (!(configWidget && qobject_cast<CfgTerminalEmulator*>(configWidget)))
{
newConfigWidget = new CfgTerminalEmulator(configContainer);
}
loadedConfigWidget = new CfgTerminalEmulator(configContainer);
}
#endif
else if (cfgType==QLatin1String("internal_filemanager"))
{
if (!(configWidget && qobject_cast<CfgFileManager*>(configWidget)))
{
newConfigWidget = new CfgFileManager(configContainer);
}
loadedConfigWidget = new CfgFileManager(configContainer);
}
else if (cfgType==QLatin1String("internal_browser"))
{
if (!(configWidget && qobject_cast<CfgBrowser*>(configWidget)))
{
newConfigWidget = new CfgBrowser(configContainer);
}
loadedConfigWidget = new CfgBrowser(configContainer);
}
if (loadedConfigWidget) {
configWidgetMap.insert(service, loadedConfigWidget);
configContainer->addWidget(loadedConfigWidget);
connect(loadedConfigWidget, SIGNAL(changed(bool)), this, SLOT(emitChanged(bool)));
}
}
if (newConfigWidget)
{
configContainer->addWidget(newConfigWidget);
configContainer->setCurrentWidget (newConfigWidget);
configContainer->removeWidget(configWidget);
delete configWidget;
configWidget=newConfigWidget;
connect(configWidget,SIGNAL(changed(bool)),this,SLOT(emitChanged(bool)));
configContainer->setMinimumSize(configWidget->sizeHint());
void ComponentChooser::slotServiceSelected(QListWidgetItem* it) {
if (!it) return;
if (somethingChanged) {
if (KMessageBox::questionYesNo(this,i18n("<qt>You changed the default component of your choice, do want to save that change now ?</qt>"),QString(),KStandardGuiItem::save(),KStandardGuiItem::discard())==KMessageBox::Yes) save();
}
const QString &service = it->data(Qt::UserRole).toString();
KConfig cfg(service, KConfig::SimpleConfig);
ComponentDescription->setText(cfg.group(QByteArray()).readEntry("Comment",i18n("No description available")));
ComponentDescription->setMinimumSize(ComponentDescription->sizeHint());
if (configWidget)
configWidget = configWidgetMap.value(service);
if (configWidget) {
configContainer->setCurrentWidget(configWidget);
dynamic_cast<CfgPlugin*>(configWidget)->load(&cfg);
}
emitChanged(false);
latestEditedService=it->data(Qt::UserRole).toString();
emitChanged(false);
latestEditedService = service;
}
......@@ -232,7 +207,9 @@ void ComponentChooser::emitChanged(bool val) {
ComponentChooser::~ComponentChooser()
{
delete configWidget;
for (QWidget *configWidget : configWidgetMap) {
delete configWidget;
}
}
void ComponentChooser::load() {
......
......@@ -77,6 +77,10 @@ private:
bool somethingChanged;
QWidget *configWidget;
QVBoxLayout *myLayout;
QMap<QString, QWidget*> configWidgetMap;
void loadConfigWidget(const QString &, const QString &, const QString &);
protected Q_SLOTS:
void emitChanged(bool);
void slotServiceSelected(QListWidgetItem *);
......
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