diff --git a/krfb/CMakeLists.txt b/krfb/CMakeLists.txt --- a/krfb/CMakeLists.txt +++ b/krfb/CMakeLists.txt @@ -68,6 +68,7 @@ ki18n_wrap_ui (krfb_SRCS ui/configtcp.ui ui/configsecurity.ui + ui/configframebuffer.ui ui/connectionwidget.ui ui/mainwidget.ui ) diff --git a/krfb/framebuffermanager.cpp b/krfb/framebuffermanager.cpp --- a/krfb/framebuffermanager.cpp +++ b/krfb/framebuffermanager.cpp @@ -71,25 +71,25 @@ i.toBack(); QSet unique; while (i.hasPrevious()) { - KPluginMetaData data = i.previous(); + const KPluginMetaData &data = i.previous(); // only load plugins once, even if found multiple times! if (unique.contains(data.name())) continue; - KPluginFactory *factory = KPluginLoader(data.fileName()).factory(); - - if (!factory) { - qDebug() << "KPluginFactory could not load the plugin:" << data.fileName(); - } else { - qDebug() << "found plugin at " << data.fileName(); - } - - FrameBufferPlugin *plugin = factory->create(this); - if (plugin) { - m_plugins.insert(data.pluginId(), plugin); - qDebug() << "Loaded plugin with name " << data.pluginId(); - } else { - qDebug() << "unable to load pluign for " << data.fileName(); - } + KPluginFactory *factory = KPluginLoader(data.fileName()).factory(); + + if (!factory) { + qDebug() << "KPluginFactory could not load the plugin:" << data.fileName(); + } else { + qDebug() << "found plugin at " << data.fileName(); + } + + FrameBufferPlugin *plugin = factory->create(this); + if (plugin) { + m_plugins.insert(data.pluginId(), plugin); + qDebug() << "Loaded plugin with name " << data.pluginId(); + } else { + qDebug() << "unable to load pluign for " << data.fileName(); + } unique.insert (data.name()); } } diff --git a/krfb/main.cpp b/krfb/main.cpp --- a/krfb/main.cpp +++ b/krfb/main.cpp @@ -56,6 +56,21 @@ return true; } + +static void checkOldX11PluginConfig() { + if (KrfbConfig::preferredFrameBufferPlugin() == QStringLiteral("x11")) { + qDebug() << "Detected deprecated configuration: preferredFrameBufferPlugin = x11"; + KConfigSkeletonItem *config_item = KrfbConfig::self()->findItem( + QStringLiteral("preferredFrameBufferPlugin")); + if (config_item) { + config_item->setProperty(QStringLiteral("xcb")); + KrfbConfig::self()->save(); + qDebug() << " Fixed preferredFrameBufferPlugin from x11 to xcb."; + } + } +} + + int main(int argc, char *argv[]) { QApplication app(argc, argv); @@ -109,6 +124,9 @@ return 1; } + // upgrade the configuration + checkOldX11PluginConfig(); + //init the core InvitationsRfbServer::init(); diff --git a/krfb/mainwindow.cpp b/krfb/mainwindow.cpp --- a/krfb/mainwindow.cpp +++ b/krfb/mainwindow.cpp @@ -13,20 +13,28 @@ #include "krfbconfig.h" #include "ui_configtcp.h" #include "ui_configsecurity.h" +#include "ui_configframebuffer.h" #include #include #include #include #include #include #include +#include +#include #include #include +#include +#include #include +#include +#include #include + class TCP: public QWidget, public Ui::TCP { public: @@ -43,6 +51,40 @@ } }; +class ConfigFramebuffer: public QWidget, public Ui::Framebuffer +{ +public: + ConfigFramebuffer(QWidget *parent = 0) : QWidget(parent) { + setupUi(this); + // hide the line edit with framebuffer string + kcfg_preferredFrameBufferPlugin->hide(); + // fill drop-down combo with a list of real existing plugins + this->fillFrameBuffersCombo(); + // initialize combo with currently configured framebuffer plugin + cb_preferredFrameBufferPlugin->setCurrentText(KrfbConfig::preferredFrameBufferPlugin()); + // connect signals between combo<->lineedit + // if we change selection in combo, lineedit is updated + QObject::connect(cb_preferredFrameBufferPlugin, &QComboBox::currentTextChanged, + kcfg_preferredFrameBufferPlugin, &QLineEdit::setText); + } + + void fillFrameBuffersCombo() { + const QVector plugins = KPluginLoader::findPlugins( + QStringLiteral("krfb"), [](const KPluginMetaData & md) { + return md.serviceTypes().contains(QStringLiteral("krfb/framebuffer")); + }); + QSet unique; + QVectorIterator i(plugins); + i.toBack(); + while (i.hasPrevious()) { + const KPluginMetaData &metadata = i.previous(); + if (unique.contains(metadata.pluginId())) continue; + cb_preferredFrameBufferPlugin->addItem(metadata.pluginId()); + unique.insert(metadata.pluginId()); + } + } +}; + MainWindow::MainWindow(QWidget *parent) : KXmlGuiWindow(parent) @@ -183,14 +225,28 @@ void MainWindow::showConfiguration() { + static QString s_prevFramebufferPlugin; + // ^^ needs to be static, because lambda will be called long time + // after showConfiguration() ends, so auto variable would go out of scope + // save previously selected framebuffer plugin config + s_prevFramebufferPlugin = KrfbConfig::preferredFrameBufferPlugin(); + if (KConfigDialog::showDialog("settings")) { return; } KConfigDialog *dialog = new KConfigDialog(this, "settings", KrfbConfig::self()); - dialog->addPage(new TCP, i18n("Network"), "network-workgroup"); + dialog->addPage(new TCP, i18n("Network"), "network-wired"); dialog->addPage(new Security, i18n("Security"), "security-high"); + dialog->addPage(new ConfigFramebuffer, i18n("Screen capture"), "video-display"); dialog->show(); + connect(dialog, &KConfigDialog::settingsChanged, [this] () { + // check if framebuffer plugin config has changed + if (s_prevFramebufferPlugin != KrfbConfig::preferredFrameBufferPlugin()) { + KMessageBox::information(this, i18n("To apply framebuffer plugin setting, " + "you need to restart the program.")); + } + }); } void MainWindow::readProperties(const KConfigGroup& group) diff --git a/krfb/ui/configframebuffer.ui b/krfb/ui/configframebuffer.ui new file mode 100644 --- /dev/null +++ b/krfb/ui/configframebuffer.ui @@ -0,0 +1,90 @@ + + + Framebuffer + + + + 0 + 0 + 418 + 186 + + + + Framebuffer + + + + + + + + Preferred frameb&uffer plugin: + + + cb_preferredFrameBufferPlugin + + + + + + + false + + + + + + + + + + + + true + + + <html><head/><body><p>When using x11, <span style=" font-weight:600;">xcb</span> plugin should be preferred, because it is more performant.<br/><span style=" font-weight:600;">qt</span> plugin is a safe fallback, if for some reason others don't work. But also it is very slow.</p></body></html> + + + Qt::RichText + + + false + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + true + + + 5 + + + Qt::NoTextInteraction + + + + + + + Qt::Vertical + + + + 20 + 63 + + + + + + + + cb_preferredFrameBufferPlugin + kcfg_preferredFrameBufferPlugin + + + +