Commit 3f775aed authored by Nikita Sirgienko's avatar Nikita Sirgienko

Improve logic of handling missing or disabled backends

parent faa0d99c
......@@ -286,34 +286,37 @@ void CantorShell::addWorksheet(const QString& backendName)
KPluginFactory* factory = KPluginLoader(QLatin1String("libcantorpart")).factory();
if (factory)
{
// now that the Part is loaded, we cast it to a Part to get
// our hands on it
KParts::ReadWritePart* part = factory->create<KParts::ReadWritePart>(m_tabWidget, QVariantList()<<backendName);
Cantor::Backend* backend = Cantor::Backend::getBackend(backendName);
if (part)
if (backend)
{
//determine backend
Cantor::Backend* backend = Cantor::Backend::getBackend(backendName);
// if backend not found, part is invalid, so delete it
if (backend)
if (backend->isEnabled() || backendName == QLatin1String("null"))
{
connect(part, SIGNAL(setCaption(QString,QIcon)), this, SLOT(setTabCaption(QString,QIcon)));
m_parts.append(part);
int tab = m_tabWidget->addTab(part->widget(), QIcon::fromTheme(backend->icon()), i18n("Session %1", sessionCount++));
m_tabWidget->setCurrentIndex(tab);
// Setting focus on worksheet view, because Qt clear focus of added widget inside addTab
// This fix https://bugs.kde.org/show_bug.cgi?id=395976
part->widget()->findChild<QGraphicsView*>()->setFocus();
// now that the Part is loaded, we cast it to a Part to get our hands on it
KParts::ReadWritePart* part = factory->create<KParts::ReadWritePart>(m_tabWidget, QVariantList()<<backendName);
if (part)
{
connect(part, SIGNAL(setCaption(QString,QIcon)), this, SLOT(setTabCaption(QString,QIcon)));
m_parts.append(part);
int tab = m_tabWidget->addTab(part->widget(), QIcon::fromTheme(backend->icon()), i18n("Session %1", sessionCount++));
m_tabWidget->setCurrentIndex(tab);
// Setting focus on worksheet view, because Qt clear focus of added widget inside addTab
// This fix https://bugs.kde.org/show_bug.cgi?id=395976
part->widget()->findChild<QGraphicsView*>()->setFocus();
}
else
{
qDebug()<<"error creating part ";
}
}
else
delete part;
{
KMessageBox::error(this, i18n("%1 backend installed, but innactive. Please check installation and Cantor settings", backendName), i18n("Cantor"));
}
}
else
{
qDebug()<<"error creating part ";
}
KMessageBox::error(this, i18n("Backend %1 is not installed", backendName), i18n("Cantor"));
}
else
{
......
......@@ -136,22 +136,6 @@ CantorPart::CantorPart( QWidget *parentWidget, QObject *parent, const QVariantLi
}
Cantor::Backend* b=Cantor::Backend::getBackend(backendName);
if(!b)
{
KMessageBox::error(parentWidget, i18n("Backend %1 is not installed", backendName), i18n("Error - Cantor"));
setWidget(new QWidget(parentWidget));
return;
}
if (b && !b->isEnabled() && backendName != QLatin1String("null"))
{
KMessageBox::information(parentWidget, i18n("There are some problems with the %1 backend,\n"\
"please check your configuration or install the needed packages.\n"
"You will only be able to view this worksheet.", backendName), i18n("Cantor"));
setWidget(new QWidget(parentWidget));
return;
}
qDebug()<<"Backend "<<b->name()<<" offers extensions: "<<b->extensions();
......
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