diff --git a/src/backendchoosedialog.cpp b/src/backendchoosedialog.cpp index 0fe62694..ca0f292a 100644 --- a/src/backendchoosedialog.cpp +++ b/src/backendchoosedialog.cpp @@ -1,99 +1,99 @@ /* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. --- Copyright (C) 2009 Alexander Rieder */ #include "backendchoosedialog.h" #include #include #include #include #include "lib/backend.h" #include "settings.h" const char* BackendChooseDialog::descriptionTemplate = I18N_NOOP("

%1

" \ - "
Recommended version: %4
" \ + "
Recommended version: %4

" \ "
%2

" \ "
See %3 for more information
"); BackendChooseDialog::BackendChooseDialog(QWidget* parent) : QDialog(parent) { QWidget* w=new QWidget(this); m_ui.setupUi(w); QGridLayout *layout = new QGridLayout; setLayout(layout); layout->addWidget(w); m_ui.backendList->setIconSize(QSize(KIconLoader::SizeMedium, KIconLoader::SizeMedium)); m_ui.backendList->setSortingEnabled(true); connect(m_ui.backendList, &QListWidget::currentItemChanged, this, &BackendChooseDialog::updateDescription); connect(m_ui.backendList, &QListWidget::itemDoubleClicked, this, &BackendChooseDialog::accept); m_ui.buttonBox->button(QDialogButtonBox::Ok); m_ui.buttonBox->button(QDialogButtonBox::Ok)->setIcon(QApplication::style()->standardIcon(QStyle::SP_DialogOkButton)); m_ui.buttonBox->button(QDialogButtonBox::Cancel)->setIcon(QApplication::style()->standardIcon(QStyle::SP_DialogCancelButton)); foreach(Cantor::Backend* backend, Cantor::Backend::availableBackends()) { if(!backend->isEnabled()) //don't show disabled backends continue; QListWidgetItem* item=new QListWidgetItem(m_ui.backendList); item->setText(backend->name()); item->setIcon(QIcon::fromTheme(backend->icon())); m_ui.backendList->addItem(item); if(m_ui.backendList->currentItem() == 0) m_ui.backendList->setCurrentItem(item); if(backend->name()==Settings::self()->defaultBackend()) m_ui.backendList->setCurrentItem(item); } connect(m_ui.buttonBox, &QDialogButtonBox::accepted, this, &BackendChooseDialog::accept); connect(m_ui.buttonBox, &QDialogButtonBox::rejected, this, &BackendChooseDialog::close); connect(this, &BackendChooseDialog::accepted, this, &BackendChooseDialog::onAccept); } BackendChooseDialog::~BackendChooseDialog() { } void BackendChooseDialog::onAccept() { m_backend=m_ui.backendList->currentItem()->text(); if(m_ui.makeDefault->isChecked()) { Settings::self()->setDefaultBackend(m_backend); Settings::self()->save(); } } void BackendChooseDialog::updateDescription() { Cantor::Backend* current=Cantor::Backend::createBackend( m_ui.backendList->currentItem()->text() ); - m_ui.descriptionView->setHtml(i18n(BackendChooseDialog::descriptionTemplate, current->name(), current->description(), current->url())); + m_ui.descriptionView->setHtml(i18n(BackendChooseDialog::descriptionTemplate, current->name(), current->description(), current->url(), current->version())); } QString BackendChooseDialog::backendName() { return m_backend; } diff --git a/src/backends/kalgebra/kalgebrabackend.cpp b/src/backends/kalgebra/kalgebrabackend.cpp index 6b2f1598..624d120f 100644 --- a/src/backends/kalgebra/kalgebrabackend.cpp +++ b/src/backends/kalgebra/kalgebrabackend.cpp @@ -1,74 +1,79 @@ /************************************************************************************* * Copyright (C) 2009 by Aleix Pol * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * * as published by the Free Software Foundation; either version 2 * * of the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * *************************************************************************************/ #include "kalgebrabackend.h" #include "kalgebrasession.h" #include "settings.h" #include "ui_settings.h" #include "kalgebraextensions.h" #include "cantor_macros.h" KAlgebraBackend::KAlgebraBackend( QObject* parent,const QList args ) : Cantor::Backend( parent,args ) { setObjectName(QLatin1String("kalgebrabackend")); new KAlgebraVariableManagementExtension(this); } KAlgebraBackend::~KAlgebraBackend() {} QString KAlgebraBackend::id() const { return QLatin1String("kalgebra"); } +QString KAlgebraBackend::version() const +{ + return QLatin1String("Analitza version 5.0"); +} + Cantor::Session* KAlgebraBackend::createSession() { return new KAlgebraSession(this); } Cantor::Backend::Capabilities KAlgebraBackend::capabilities() const { return Cantor::Backend::Completion | Cantor::Backend::SyntaxHighlighting | Cantor::Backend::SyntaxHelp | Cantor::Backend::VariableManagement; } QWidget* KAlgebraBackend::settingsWidget(QWidget* parent) const { QWidget* widget=new QWidget(parent); Ui::KAlgebraSettingsBase s; s.setupUi(widget); return widget; } KConfigSkeleton* KAlgebraBackend::config() const { return KAlgebraSettings::self(); } QUrl KAlgebraBackend::helpUrl() const { return QUrl(i18nc("the url to the documentation of KAlgebra, please check if there is a translated version and use the correct url", "http://docs.kde.org/stable/en/kdeedu/kalgebra/")); } K_PLUGIN_FACTORY_WITH_JSON(kalgebrabackend, "kalgebrabackend.json", registerPlugin();) #include "kalgebrabackend.moc" diff --git a/src/backends/kalgebra/kalgebrabackend.h b/src/backends/kalgebra/kalgebrabackend.h index dae1d6ac..3613d538 100644 --- a/src/backends/kalgebra/kalgebrabackend.h +++ b/src/backends/kalgebra/kalgebrabackend.h @@ -1,41 +1,42 @@ /************************************************************************************* * Copyright (C) 2009 by Aleix Pol * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * * as published by the Free Software Foundation; either version 2 * * of the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * *************************************************************************************/ #ifndef KALGEBRA_BACKEND_H #define KALGEBRA_BACKEND_H #include "backend.h" class KAlgebraBackend : public Cantor::Backend { Q_OBJECT public: explicit KAlgebraBackend( QObject* parent = 0,const QList args = QList()); ~KAlgebraBackend(); QString id() const; Cantor::Session *createSession(); Cantor::Backend::Capabilities capabilities() const; QWidget* settingsWidget(QWidget* parent) const; KConfigSkeleton* config() const; QUrl helpUrl() const; + QString version() const override; }; #endif /* _NULLBACKEND_H */ diff --git a/src/lib/backend.cpp b/src/lib/backend.cpp index 2c035413..92f1ecea 100644 --- a/src/lib/backend.cpp +++ b/src/lib/backend.cpp @@ -1,202 +1,207 @@ /* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. --- Copyright (C) 2009 Alexander Rieder */ #include "backend.h" using namespace Cantor; #include #include #include #include #include #include #include #include #include "extension.h" class Cantor::BackendPrivate { public: QString name; QString comment; QString icon; QString url; bool enabled; }; Backend::Backend(QObject* parent, const QList args) : QObject(parent), d(new BackendPrivate) { Q_UNUSED(args) d->enabled=true; } Backend::~Backend() { delete d; } QString Backend::name() const { return d->name; } QString Backend::comment() const { return d->comment; } QString Backend::description() const { return comment(); } QString Backend::icon() const { return d->icon; } +QString Backend::version() const +{ + return QLatin1String(); +} + QString Backend::url() const { return d->url; } QUrl Backend::helpUrl() const { return QUrl(); } bool Backend::isEnabled() const { return d->enabled&&requirementsFullfilled(); } void Backend::setEnabled(bool enabled) { d->enabled=enabled; } static QList backendCache; QStringList Backend::listAvailableBackends() { QList backends=availableBackends(); QStringList l; foreach(Backend* b, backends) { if(b->isEnabled()) l<name(); } return l; } QList Backend::availableBackends() { //if we already have all backends Cached, just return the cache. //otherwise create the available backends if(!backendCache.isEmpty()) { return backendCache; } QStringList pluginDirs; foreach(const QString &dir, QCoreApplication::libraryPaths()){ pluginDirs << dir + QDir::separator() + QLatin1String("cantor/backends"); } QPluginLoader loader; foreach(const QString &dir, pluginDirs){ qDebug() << "dir: " << dir; QStringList plugins; QDir pluginDir = QDir(dir); plugins = pluginDir.entryList(); foreach (const QString &plugin, plugins){ if (plugin==QLatin1String(".") || plugin==QLatin1String("..")) continue; loader.setFileName(dir + QDir::separator() + plugin); if (!loader.load()){ qDebug() << "Error while loading plugin: " << plugin; continue; } KPluginFactory* factory = KPluginLoader(loader.fileName()).factory(); Backend* backend = factory->create(); KPluginMetaData info(loader); backend->d->name=info.name(); backend->d->comment=info.description(); backend->d->icon=info.iconName(); backend->d->url=info.website(); backendCache< backends=availableBackends(); foreach(Backend* b, backends) { if(b->name().toLower()==name.toLower() || b->id().toLower()==name.toLower()) return b; } return 0; } QWidget* Backend::settingsWidget(QWidget* parent) const { Q_UNUSED(parent) return 0; } KConfigSkeleton* Backend::config() const { return 0; } QStringList Backend::extensions() const { QList extensions=findChildren(QRegExp(QLatin1String(".*Extension"))); QStringList names; foreach(Extension* e, extensions) names<objectName(); return names; } Extension* Backend::extension(const QString& name) const { return findChild(name); } bool Backend::requirementsFullfilled() const { return true; } diff --git a/src/lib/backend.h b/src/lib/backend.h index 4c9c4aca..4c881c09 100644 --- a/src/lib/backend.h +++ b/src/lib/backend.h @@ -1,211 +1,218 @@ /* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. --- Copyright (C) 2009 Alexander Rieder */ #ifndef _BACKEND_H #define _BACKEND_H #include #include #include #include #include "cantor_export.h" class KConfigSkeleton; class QWidget; /** * Namespace collecting all Classes of the Cantor Libraries */ namespace Cantor { class Session; class Extension; class BackendPrivate; /** * The Backend class provides access to information about the backend. * It provides access to what features are supported by the backend, and * a factory method to create a new Session * It needs to be subclassed by all Backends. * * @author Alexander Rieder */ class CANTOR_EXPORT Backend : public QObject, public KXMLGUIClient { Q_OBJECT public: /** * This enum is used to specify the Features, supported by a backend. */ enum Capability{ Nothing = 0x0, ///< the Backend doesn't support any of the optional features LaTexOutput = 0x1, ///< it can output results as LaTeX code InteractiveMode = 0x2, /**< it supports an interactive workflow. (It means a command can ask for additional input while running */ SyntaxHighlighting = 0x4, ///< it offers a custom Syntax Highlighter Completion = 0x8, ///< it offers completion of partially typed commands SyntaxHelp = 0x10, /**< it offers help about a commands syntax, that will be shown in a tooltip */ VariableManagement= 0x20 ///< it offers access to the variables (for variable management panel) }; Q_DECLARE_FLAGS(Capabilities, Capability) protected: /** * Create a new Backend. Normally the static createBackend factory method * should be used. * @param parent the Parent object * @param args optional arguments (not used) */ explicit Backend( QObject* parent = 0,const QList args=QList() ); /** * Destructor. Doesn't anything. */ virtual ~Backend(); public: /** * Creates a new Session. It is the way to go to create a Session, * don't call new Session on your own. * @return a new Session of this Backend, or 0 if creating failed */ virtual Session* createSession() = 0; /** * Returns list of the supported optional features * @return a list of features, containing items of the Capabiltiy enum, ORed together */ virtual Capabilities capabilities() const = 0; /** * Returns whether all of this backends requirements are fulfiled, or if some are missing. * @return @c true if all the requirements needed to use this Backend are fulfilled * @return @c false some requirements are missing. e.g. the maxima executable can not be found * @see Capablility */ virtual bool requirementsFullfilled() const; /** * Returns a unique string to identify this backend. * In contrast to name() this string isn't translated * @return string to identify backend */ virtual QString id() const = 0; //Stuff extracted from the .desktop file /** * Returns the name of the backend * @return the backends name */ QString name() const; + + /** + * Returns the recommended version of the backend supported by Cantor + * @return the recommended version of the backend + */ + virtual QString version() const; + /** * Returns a short comment about the backend. * @return comment about the backend */ QString comment() const; /** * Returns the icon to use with this backend * @return name of the icon */ QString icon() const; /** * Returns the Url of the Homepage for the Backend * @return the url */ QString url() const; /** * Returns an Url pointing to the Help of the Backend * The method should be overwritten by all Backends(who have an online help) * You should make the returned Url translateble, e.g. by doing something like: * return i18nc("the url to the documentation of KAlgebra, please check if there is a translated version and use the correct url", * "http://docs.kde.org/stable/en/kdeedu/kalgebra/"); * @return Url of the help */ virtual QUrl helpUrl() const; /** * Returns if the backend should be enabled (shown in the Backend dialog) * @return @c true, if the enabled flag is set to true, and the requirements are fulfiled * @return @c false, if the backend was purposedly disabled, or requirements are missing * @see requirementsFullfilled() */ bool isEnabled() const; /** * Enables/disables this backend * @param enabled true to enable backend false to disable */ void setEnabled(bool enabled); /** * Returns a longer description of the Backend, e.g. purpose, strengths etc. * It should help the user to decide between the different Backends * @return a description of the backend. It can contain html */ virtual QString description() const; /** * Returns a Widget for configuring this backend * @return Widget for usage in the Settings dialog */ virtual QWidget* settingsWidget(QWidget* parent) const; /** * Returns a KConfig object, containing all the settings, * the backend might need * @return a KConfigSkeleton object, for configuring this backend */ virtual KConfigSkeleton* config() const; /** * Returns a list of the names of all the Extensions supported by this backend * @return a list of the names of all the Extensions supported by this backend * @see extension(const QString& name) */ QStringList extensions() const; /** * Returns an Extension of this backend for the given name, or null * if the Backend doesn't have an extension with this name. * @return Pointer to the Extension object with the given name */ Extension * extension(const QString& name) const; /** * Returns a list of the names of all the installed and enabled backends * @return a list of the names of all the installed and enabled backends * @see isEnabled() */ static QStringList listAvailableBackends(); /** * Returns Pointers to all the installed backends * @return Pointers to all the installed backends */ static QList availableBackends(); /** * Returns the backend with the given name, or null if it isn't found * @return the backend with the given name, or null if it isn't found */ static Backend* createBackend(const QString& name); private: BackendPrivate* d; }; Q_DECLARE_OPERATORS_FOR_FLAGS(Backend::Capabilities) } #endif /* _BACKEND_H */