File indexing completed on 2024-11-17 05:01:08

0001 /*
0002     SPDX-FileCopyrightText: 2009 Wang Hoi <zealot.hoi@gmail.com>
0003     SPDX-FileCopyrightText: 2011 Weng Xuetian <wengxt@gmail.com>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 #pragma once
0008 
0009 #include "kimpanelagenttype.h"
0010 
0011 // Qt
0012 #include <QDBusConnection>
0013 #include <QDBusContext>
0014 #include <QObject>
0015 #include <QStringList>
0016 
0017 class QDBusServiceWatcher;
0018 class Impanel2Adaptor;
0019 class ImpanelAdaptor;
0020 
0021 class PanelAgent : public QObject, protected QDBusContext
0022 {
0023     Q_OBJECT
0024 
0025 public:
0026     PanelAgent(QObject *parent);
0027     ~PanelAgent() override;
0028 
0029     void configure();
0030     void created();
0031     void exit();
0032     void reloadConfig();
0033     void selectCandidate(int idx);
0034     void lookupTablePageUp();
0035     void lookupTablePageDown();
0036     void movePreeditCaret(int pos);
0037     void triggerProperty(const QString &key);
0038 
0039 public Q_SLOTS: // METHODS
0040     void UpdateLookupTable(const QStringList &labels, const QStringList &candis, const QStringList &attrlists, bool has_prev, bool has_next);
0041     void UpdatePreeditText(const QString &text, const QString &attr);
0042     void UpdateAux(const QString &text, const QString &attr);
0043     void UpdateScreen(int screen_id);
0044     void UpdateProperty(const QString &prop);
0045     void RegisterProperties(const QStringList &props);
0046     void ExecDialog(const QString &prop);
0047     void ExecMenu(const QStringList &entries);
0048     void SetSpotRect(int x, int y, int w, int h);
0049     void SetLookupTable(const QStringList &labels, const QStringList &candis, const QStringList &attrlists, bool hasPrev, bool hasNext, int cursor, int layout);
0050     void serviceUnregistered(const QString &service);
0051 
0052 Q_SIGNALS:
0053     // signals that from kimpanel
0054     void Configure();
0055     void MovePreeditCaret(int position);
0056     void SelectCandidate(int index);
0057     void LookupTablePageUp();
0058     void LookupTablePageDown();
0059     void TriggerProperty(const QString &key);
0060     void PanelCreated();
0061     void PanelCreated2();
0062     void PanelRegistered();
0063     void Exit();
0064     void ReloadConfig();
0065 
0066     // signals to inform kimpanel
0067     void enable(bool to_enable);
0068 
0069     void updatePreeditCaret(int pos);
0070     void updatePreeditText(const QString &text, const QList<TextAttribute> &attr);
0071     void updateAux(const QString &text, const QList<TextAttribute> &attr);
0072     void updateProperty(const KimpanelProperty &prop);
0073     void updateLookupTable(const KimpanelLookupTable &lookup_table);
0074     void updateLookupTableFull(const KimpanelLookupTable &lookup_table, int cursor, int layout);
0075     void updateSpotLocation(int x, int y);
0076     void updateSpotRect(int x, int y, int w, int h);
0077 
0078     void registerProperties(const QList<KimpanelProperty> &props);
0079 
0080     void execDialog(const KimpanelProperty &prop);
0081     void execMenu(const QList<KimpanelProperty> &prop_list);
0082 
0083     void showPreedit(bool to_show);
0084     void showAux(bool to_show);
0085     void showLookupTable(bool to_show);
0086     void updateLookupTableCursor(int pos);
0087 
0088 private:
0089     QString m_currentService;
0090     QStringList m_cachedProps;
0091     ImpanelAdaptor *m_adaptor;
0092     Impanel2Adaptor *m_adaptor2;
0093     QDBusServiceWatcher *m_watcher;
0094     QDBusConnection m_connection;
0095     static int m_connectionIndex;
0096 };