Make gui plugin use qt's metadata.

This commit is contained in:
Weng Xuetian 2018-03-19 15:50:54 -07:00
parent f7616e2279
commit 6c8913c4b0
52 changed files with 87 additions and 99 deletions

View File

@ -122,7 +122,7 @@ FCITX5_QT_BEGIN_DECLARE_DBUS_TYPE(FcitxQtAddonState);
FCITX5_QT_DECLARE_FIELD(QString, uniqueName, setUniqueName);
FCITX5_QT_DECLARE_FIELD(bool, enabled, setEnabled);
FCITX5_QT_END_DECLARE_DBUS_TYPE(FcitxQtAddonState);
}
} // namespace fcitx
Q_DECLARE_METATYPE(fcitx::FcitxQtFormattedPreedit)
Q_DECLARE_METATYPE(fcitx::FcitxQtFormattedPreeditList)

View File

@ -173,6 +173,6 @@ public:
bool m_portal = false;
qulonglong m_capability = 0;
};
}
} // namespace fcitx
#endif // _DBUSADDONS_FCITXQTINPUTCONTEXTPROXY_P_H_

View File

@ -26,4 +26,4 @@ FcitxQtInputContextProxyImpl::FcitxQtInputContextProxyImpl(
parent) {}
FcitxQtInputContextProxyImpl::~FcitxQtInputContextProxyImpl() {}
}
} // namespace fcitx

View File

@ -120,6 +120,6 @@ Q_SIGNALS: // SIGNALS
void ForwardKey(uint keyval, uint state, bool type);
void UpdateFormattedPreedit(FcitxQtFormattedPreeditList str, int cursorpos);
};
}
} // namespace fcitx
#endif

View File

@ -153,4 +153,4 @@ void FcitxQtWatcher::updateAvailability() {
Q_D(FcitxQtWatcher);
setAvailability(d->m_mainPresent || d->m_portalPresent);
}
}
} // namespace fcitx

View File

@ -62,6 +62,6 @@ private:
FcitxQtWatcherPrivate *const d_ptr;
Q_DECLARE_PRIVATE(FcitxQtWatcher);
};
}
} // namespace fcitx
#endif // _DBUSADDONS_FCITXQTWATCHER_H_

View File

@ -40,6 +40,6 @@ public:
bool m_portalPresent = false;
bool m_watched = false;
};
}
} // namespace fcitx
#endif // _DBUSADDONS_FCITXQTWATCHER_P_H_

View File

@ -26,7 +26,7 @@ namespace {
bool isFcitx(const QString &key) {
return key.toLower() == "fcitx5" || key.toLower() == "fcitx";
}
}
} // namespace
QStringList QFcitxInputContextPlugin::keys() const {
return QStringList{"fcitx5", "fcitx"};
@ -62,6 +62,6 @@ QStringList QFcitxInputContextPlugin::languages(const QString &key) {
QString QFcitxInputContextPlugin::displayName(const QString &key) {
return key;
}
}
} // namespace fcitx
Q_EXPORT_PLUGIN2(QFcitxInputContextPlugin, fcitx::QFcitxInputContextPlugin)

View File

@ -41,6 +41,6 @@ public:
QString displayName(const QString &key) override;
};
}
} // namespace fcitx
#endif // MAIN_H

View File

@ -544,10 +544,11 @@ void QFcitxInputContext::createICData(QWidget *w) {
SLOT(commitString(QString)));
connect(data.proxy, SIGNAL(forwardKey(uint, uint, bool)), this,
SLOT(forwardKey(uint, uint, bool)));
connect(data.proxy, SIGNAL(updateFormattedPreedit(
FcitxQtFormattedPreeditList, int)),
this,
SLOT(updateFormattedPreedit(FcitxQtFormattedPreeditList, int)));
connect(
data.proxy,
SIGNAL(updateFormattedPreedit(FcitxQtFormattedPreeditList, int)),
this,
SLOT(updateFormattedPreedit(FcitxQtFormattedPreeditList, int)));
connect(data.proxy, SIGNAL(deleteSurroundingText(int, uint)), this,
SLOT(deleteSurroundingText(int, uint)));
}
@ -768,6 +769,6 @@ bool QFcitxInputContext::processCompose(uint keyval, uint state,
QString QFcitxInputContext::identifierName() { return "fcitx5"; }
QString QFcitxInputContext::language() { return ""; }
}
} // namespace fcitx
// kate: indent-mode cstyle; space-indent on; indent-width 0;

View File

@ -181,6 +181,6 @@ private:
private slots:
void processKeyEventFinished(QDBusPendingCallWatcher *);
};
}
} // namespace fcitx
#endif // QFCITXINPUTCONTEXT_H

View File

@ -122,7 +122,7 @@ FCITX5_QT_BEGIN_DECLARE_DBUS_TYPE(FcitxQtAddonState);
FCITX5_QT_DECLARE_FIELD(QString, uniqueName, setUniqueName);
FCITX5_QT_DECLARE_FIELD(bool, enabled, setEnabled);
FCITX5_QT_END_DECLARE_DBUS_TYPE(FcitxQtAddonState);
}
} // namespace fcitx
Q_DECLARE_METATYPE(fcitx::FcitxQtFormattedPreedit)
Q_DECLARE_METATYPE(fcitx::FcitxQtFormattedPreeditList)

View File

@ -169,6 +169,6 @@ public:
bool m_portal = false;
qulonglong m_capability = 0;
};
}
} // namespace fcitx
#endif // _DBUSADDONS_FCITXQTINPUTCONTEXTPROXY_P_H_

View File

@ -33,4 +33,4 @@ FcitxQtInputContextProxyImpl::FcitxQtInputContextProxyImpl(
parent) {}
FcitxQtInputContextProxyImpl::~FcitxQtInputContextProxyImpl() {}
}
} // namespace fcitx

View File

@ -118,6 +118,6 @@ Q_SIGNALS: // SIGNALS
void ForwardKey(uint keyval, uint state, bool type);
void UpdateFormattedPreedit(FcitxQtFormattedPreeditList str, int cursorpos);
};
}
} // namespace fcitx
#endif

View File

@ -151,4 +151,4 @@ void FcitxQtWatcher::updateAvailability() {
Q_D(FcitxQtWatcher);
setAvailability(d->m_mainPresent || d->m_portalPresent);
}
}
} // namespace fcitx

View File

@ -62,6 +62,6 @@ private:
FcitxQtWatcherPrivate *const d_ptr;
Q_DECLARE_PRIVATE(FcitxQtWatcher);
};
}
} // namespace fcitx
#endif // _DBUSADDONS_FCITXQTWATCHER_H_

View File

@ -40,6 +40,6 @@ public:
bool m_portalPresent = false;
bool m_watched = false;
};
}
} // namespace fcitx
#endif // _DBUSADDONS_FCITXQTWATCHER_P_H_

View File

@ -128,4 +128,4 @@ void MainWindow::showEvent(QShowEvent *event) {
QDialog::showEvent(event);
}
}
} // namespace fcitx

View File

@ -54,6 +54,6 @@ private:
FcitxQtControllerProxy *m_proxy;
WId wid_ = 0;
};
}
} // namespace fcitx
#endif // FCITXQT5_GUIWRAPPER_MAINWINDOW_H

View File

@ -90,4 +90,4 @@ WrapperApp::~WrapperApp() {
}
void WrapperApp::errorExit() { exit(1); }
}
} // namespace fcitx

View File

@ -40,6 +40,6 @@ private:
FcitxQtConfigUIFactory *m_factory;
MainWindow *m_mainWindow;
};
}
} // namespace fcitx
#endif // _GUIWRAPPER_WRAPPERAPP_H_

View File

@ -38,4 +38,4 @@ QFcitxPlatformInputContextPlugin::create(const QString &system,
}
return 0;
}
}
} // namespace fcitx

View File

@ -37,6 +37,6 @@ public:
QFcitxPlatformInputContext *create(const QString &system,
const QStringList &paramList);
};
}
} // namespace fcitx
#endif // MAIN_H

View File

@ -876,6 +876,6 @@ bool QFcitxPlatformInputContext::processCompose(uint keyval, uint state,
return true;
}
}
} // namespace fcitx
// kate: indent-mode cstyle; space-indent on; indent-width 0;

View File

@ -180,6 +180,6 @@ private:
private slots:
void processKeyEventFinished(QDBusPendingCallWatcher *);
};
}
} // namespace fcitx
#endif // QFCITXPLATFORMINPUTCONTEXT_H

View File

@ -32,4 +32,4 @@ BatchDialog::~BatchDialog() {}
void BatchDialog::setText(const QString &s) { plainTextEdit->setPlainText(s); }
QString BatchDialog::text() const { return plainTextEdit->toPlainText(); }
}
} // namespace fcitx

View File

@ -32,6 +32,6 @@ public:
QString text() const;
void setText(const QString &s);
};
}
} // namespace fcitx
#endif // _QUICKPHRASE_EDITOR_BATCHDIALOG_H_

View File

@ -299,4 +299,4 @@ void ListEditor::removeFileTriggered() {
loadFileList();
load();
}
}
} // namespace fcitx

View File

@ -75,6 +75,6 @@ private:
QMenu *m_operationMenu;
QString m_lastFile;
};
}
} // namespace fcitx
#endif // _QUICKPHRASE_EDITOR_EDITOR_H_

View File

@ -32,4 +32,4 @@ void EditorDialog::setValue(const QString &s) { valueLineEdit->setText(s); }
QString EditorDialog::key() const { return keyLineEdit->text(); }
QString EditorDialog::value() const { return valueLineEdit->text(); }
}
} // namespace fcitx

View File

@ -34,6 +34,6 @@ public:
void setValue(const QString &s);
void setKey(const QString &s);
};
}
} // namespace fcitx
#endif // _QUICKPHRASE_EDITOR_EDITORDIALOG_H_

View File

@ -43,6 +43,6 @@ public:
private:
QStringList m_fileList;
};
}
} // namespace fcitx
#endif // _QUICKPHRASE_EDITOR_FILELISTMODEL_H_

View File

@ -28,11 +28,3 @@ QuickPhraseEditorPlugin::create(const QString &key) {
Q_UNUSED(key);
return new fcitx::ListEditor;
}
QStringList QuickPhraseEditorPlugin::files() {
return QStringList("data/QuickPhrase.mb");
}
QString QuickPhraseEditorPlugin::name() { return "quickphrase-editor"; }
QString QuickPhraseEditorPlugin::domain() { return "fcitx"; }

View File

@ -27,10 +27,7 @@ public:
Q_PLUGIN_METADATA(IID FcitxQtConfigUIFactoryInterface_iid FILE
"quickphrase-editor.json")
explicit QuickPhraseEditorPlugin(QObject *parent = 0);
virtual QString name();
virtual QStringList files();
virtual QString domain();
virtual fcitx::FcitxQtConfigUIWidget *create(const QString &key);
fcitx::FcitxQtConfigUIWidget *create(const QString &key) override;
};
#endif // _QUICKPHRASE_EDITOR_MAIN_H_

View File

@ -260,4 +260,4 @@ void QuickPhraseModel::setNeedSave(bool needSave) {
emit needSaveChanged(m_needSave);
}
}
}
} // namespace fcitx

View File

@ -68,6 +68,6 @@ private:
QStringPairList m_list;
QFutureWatcher<QStringPairList> *m_futureWatcher;
};
}
} // namespace fcitx
#endif // _QUICKPHRASE_EDITOR_MODEL_H_

View File

@ -1,2 +1,4 @@
{
"addon": "quickphrase",
"files": ["data/QuickPhrase.mb"]
}

View File

@ -48,16 +48,23 @@ FcitxQtConfigUIFactory::~FcitxQtConfigUIFactory() {}
FcitxQtConfigUIWidget *FcitxQtConfigUIFactory::create(const QString &file) {
Q_D(FcitxQtConfigUIFactory);
if (!d->plugins.contains(file))
return 0;
auto loader = d->plugins_.value(file);
if (!loader) {
return nullptr;
}
return d->plugins[file]->create(file);
auto instance =
qobject_cast<FcitxQtConfigUIFactoryInterface *>(loader->instance());
if (!instance) {
return nullptr;
}
return instance->create(file);
}
bool FcitxQtConfigUIFactory::test(const QString &file) {
Q_D(FcitxQtConfigUIFactory);
return d->plugins.contains(file);
return d->plugins_.contains(file);
}
void FcitxQtConfigUIFactoryPrivate::scan() {
@ -81,17 +88,17 @@ void FcitxQtConfigUIFactoryPrivate::scan() {
}
QPluginLoader *loader = new QPluginLoader(filePath, this);
// qDebug() << loader->load();
// qDebug() << loader->errorString();
FcitxQtConfigUIFactoryInterface *plugin =
qobject_cast<FcitxQtConfigUIFactoryInterface *>(
loader->instance());
if (plugin) {
QStringList list = plugin->files();
Q_FOREACH (const QString &s, list) { plugins[s] = plugin; }
auto files = loader->metaData()
.value("MetaData")
.toObject()
.value("files")
.toVariant()
.toStringList();
for (const auto &file : files) {
plugins_[file] = loader;
}
} while (0);
return true;
});
}
}
} // namespace fcitx

View File

@ -63,6 +63,6 @@ private:
FcitxQtConfigUIFactoryPrivate *d_ptr;
Q_DECLARE_PRIVATE(FcitxQtConfigUIFactory);
};
}
} // namespace fcitx
#endif // _WIDGETSADDONS_FCITXQTCONFIGUIFACTORY_H_

View File

@ -21,6 +21,8 @@
#include "fcitxqtconfiguifactory.h"
#include <QObject>
#include <QPluginLoader>
#include <qpluginloader.h>
namespace fcitx {
@ -34,8 +36,8 @@ public:
private:
void scan();
QMap<QString, FcitxQtConfigUIFactoryInterface *> plugins;
QMap<QString, QPluginLoader *> plugins_;
};
}
} // namespace fcitx
#endif // _WIDGETSADDONS_FCITXQTCONFIGUIFACTORY_P_H_

View File

@ -25,4 +25,4 @@ FcitxQtConfigUIPlugin::FcitxQtConfigUIPlugin(QObject *parent)
: QObject(parent) {}
FcitxQtConfigUIPlugin::~FcitxQtConfigUIPlugin() {}
}
} // namespace fcitx

View File

@ -32,11 +32,6 @@ class FcitxQtConfigUIWidget;
* interface for qt config ui
*/
struct FCITX5QT5WIDGETSADDONS_EXPORT FcitxQtConfigUIFactoryInterface {
/**
* return the name for plugin
*/
virtual QString name() = 0;
/**
* create new widget based on key
*
@ -45,19 +40,11 @@ struct FCITX5QT5WIDGETSADDONS_EXPORT FcitxQtConfigUIFactoryInterface {
* @return plugin name
*/
virtual FcitxQtConfigUIWidget *create(const QString &key) = 0;
/**
* return a list that this plugin will handle, need to be consist with
* the file path in config file
*
* @return support file list
*/
virtual QStringList files() = 0;
};
#define FcitxQtConfigUIFactoryInterface_iid \
"org.fcitx.Fcitx.FcitxQtConfigUIFactoryInterface"
}
} // namespace fcitx
Q_DECLARE_INTERFACE(fcitx::FcitxQtConfigUIFactoryInterface,
FcitxQtConfigUIFactoryInterface_iid)
@ -75,6 +62,6 @@ public:
explicit FcitxQtConfigUIPlugin(QObject *parent = 0);
virtual ~FcitxQtConfigUIPlugin();
};
}
} // namespace fcitx
#endif // _WIDGETSADDONS_FCITXQTCONFIGUIPLUGIN_H_

View File

@ -27,4 +27,4 @@ FcitxQtConfigUIWidget::FcitxQtConfigUIWidget(QWidget *parent)
QString FcitxQtConfigUIWidget::icon() { return QLatin1String("fcitx"); }
bool FcitxQtConfigUIWidget::asyncSave() { return false; }
}
} // namespace fcitx

View File

@ -93,6 +93,6 @@ Q_SIGNALS:
**/
void saveFinished();
};
}
} // namespace fcitx
#endif // _WIDGETSADDONS_FCITXQTCONFIGUIWIDGET_H_

View File

@ -33,6 +33,6 @@ inline QString tr2fcitx(const char *message, const char *comment = nullptr) {
return QString();
}
}
}
} // namespace fcitx
#endif // _WIDGETSADDONS_FCITXQTI18NHELPER_H_

View File

@ -512,6 +512,6 @@ int FcitxQtKeySequenceWidget::keyFcitxToQt(Key key) {
return qtkey | qstate;
}
}
} // namespace fcitx
#include "moc_fcitxqtkeysequencewidget.cpp"

View File

@ -69,13 +69,13 @@ class FCITX5QT5WIDGETSADDONS_EXPORT FcitxQtKeySequenceWidget : public QWidget {
public:
/**
* Constructor.
*/
* Constructor.
*/
explicit FcitxQtKeySequenceWidget(QWidget *parent = 0);
/**
* Destructs the widget.
*/
* Destructs the widget.
*/
virtual ~FcitxQtKeySequenceWidget();
void setMultiKeyShortcutsAllowed(bool);
@ -108,6 +108,6 @@ private:
Q_DISABLE_COPY(FcitxQtKeySequenceWidget)
};
}
} // namespace fcitx
#endif // _WIDGETSADDONS_FCITXQTKEYSEQUENCEWIDGET_H_

View File

@ -62,8 +62,8 @@ public:
protected:
/**
* Reimplemented for internal reasons.
*/
* Reimplemented for internal reasons.
*/
virtual bool event(QEvent *event);
virtual void keyPressEvent(QKeyEvent *event);
virtual void keyReleaseEvent(QKeyEvent *event);
@ -71,6 +71,6 @@ protected:
private:
FcitxQtKeySequenceWidgetPrivate *const d;
};
}
} // namespace fcitx
#endif // _WIDGETSADDONS_FCITXQTKEYSEQUENCEWIDGET_P_H_

View File

@ -773,4 +773,4 @@ bool keyQtToSym(int qtcode, Qt::KeyboardModifiers mod, int &sym,
return sym >= 0;
}
}
} // namespace fcitx

View File

@ -28,6 +28,6 @@ bool keyQtToSym(int qtcode, Qt::KeyboardModifiers mod, int &sym,
bool symToKeyQt(int sym, unsigned int state, int &qtcode,
Qt::KeyboardModifiers &mod);
}
} // namespace fcitx
#endif // _WIDGETSADDONS_QTKEYTRANS_H_

View File

@ -1470,6 +1470,6 @@ QtCode2Key qtCodeToKey[] = {
{16781916, 65116}, {16781917, 65117}, {16781918, 65118}, {16781919, 65119},
{16781920, 65120}, {16781921, 65121}, {16781922, 65122},
};
}
} // namespace fcitx
#endif // _WIDGETSADDONS_QTKEYTRANSDATA_H_