Permalink
Browse files

Fix: Move all submenu to top-level menu in unity.

  • Loading branch information...
1 parent 7448c52 commit ba4369f6126a9828bb39528a43ee67ed6c1189ff @lenky0401 committed Mar 19, 2015
Showing with 52 additions and 78 deletions.
  1. +44 −63 system_tray_menu.cpp
  2. +8 −15 system_tray_menu.h
View
@@ -39,30 +39,18 @@ SystemTrayMenu::SystemTrayMenu(PanelAgent *agent)
SystemTrayMenu::~SystemTrayMenu()
{
- delete mVKListMenu;
- delete mIMListMenu;
- delete mSkinMenu;
+
}
void SystemTrayMenu::init()
{
- mVKListMenu = new QMenu(gettext("Virtual Keyboard"), this);
- mIMListMenu = new QMenu(gettext("Input Method"), this);
- mSkinMenu = new SkinMenu(gettext("Skin"), this);
- QObject::connect(mVKListMenu, SIGNAL(aboutToShow()), this,
+ QObject::connect(this, SIGNAL(aboutToShow()), this,
SLOT(triggerUpdateVKListMenu()));
- QObject::connect(mIMListMenu, SIGNAL(aboutToShow()), this,
+ QObject::connect(this, SIGNAL(aboutToShow()), this,
SLOT(triggerUpdateIMListMenu()));
- if (isUnity())
- QObject::connect(this, SIGNAL(aboutToShow()), this,
- SLOT(triggerUpdateIMListMenu()));
- else
- QObject::connect(this, SIGNAL(aboutToShow()), this,
- SLOT(triggerUpdateMainMenu()));
-
QObject::connect(this, SIGNAL(triggered(QAction*)), this,
SLOT(menuItemOnClick(QAction *)));
@@ -82,7 +70,7 @@ void SystemTrayMenu::registerProperties(const QList<KimpanelProperty> &props)
int count = 0;
mStatusMenuList.clear();
foreach(const KimpanelProperty &prop, props) {
- //qDebug() << QString("triggerUpdateMainMenu(1:%1 2:%2 3:%3 4:%4 5:%5 6:%6)").arg(prop.key)
+ //qDebug() << QString("registerProperties(1:%1 2:%2 3:%3 4:%4 5:%5 6:%6)").arg(prop.key)
// .arg(prop.label).arg(prop.icon).arg(prop.tip).arg(prop.state).arg(prop.menu);
if (count ++ < StatusMenuSkip)
continue;
@@ -100,16 +88,20 @@ void SystemTrayMenu::updateProperty(const KimpanelProperty &prop)
this->mCurtIMLabel = prop.label;
}
-void SystemTrayMenu::triggerUpdateMainMenu()
+void SystemTrayMenu::updateMainMenu()
{
MyAction *menu;
this->clear();
this->addAction(QIcon::fromTheme("help-contents"), gettext("Online &Help!"));
this->addSeparator();
- if (isUnity()) {
- appendIMListToMenu(this, mIMList);
+ bool kbd = this->doUpdateIMListMenu(mIMList);
+ this->addSeparator();
+
+ if (kbd)
+ {
+ this->doUpdateVKListMenu(mVKList);
this->addSeparator();
}
@@ -118,39 +110,27 @@ void SystemTrayMenu::triggerUpdateMainMenu()
menu->setProp(prop);
this->addAction(menu);
}
- //this->addSeparator();
-
- //this->addMenu(mVKListMenu);
- if (!isUnity())
- this->addMenu(mIMListMenu);
- //this->addMenu(mSkinMenu);
this->addSeparator();
this->addAction(QIcon::fromTheme("preferences-desktop"), gettext("ConfigureFcitx"));
this->addAction(QIcon::fromTheme("preferences-desktop"), gettext("ConfigureIMPanel"));
- //this->addAction(QIcon::fromTheme("preferences-desktop"), gettext("ConfigureIM"));
- this->addSeparator();
if (isUnity()) {
+ this->addSeparator();
this->addAction(gettext("Character Map"));
this->addAction(gettext("Keyboard Layout Chart"));
this->addAction(gettext("Text Entry Settings..."));
this->addSeparator();
}
-
- //this->addAction(QIcon::fromTheme("view-refresh"), gettext("Restart"));
- //this->addAction(QIcon::fromTheme("application-exit"), gettext("Exit"));
}
void SystemTrayMenu::triggerUpdateVKListMenu()
{
- mExecMenuType = updateVKListMenu;
mAgent->triggerProperty(QString("/Fcitx/vk"));
}
void SystemTrayMenu::triggerUpdateIMListMenu()
{
- mExecMenuType = updateIMListMenu;
mAgent->triggerProperty(QString("/Fcitx/im"));
}
@@ -159,24 +139,17 @@ void SystemTrayMenu::doUpdateVKListMenu(const QList<KimpanelProperty> &prop_list
MyAction *menu;
QList<KimpanelProperty>::const_iterator iter;
- mVKListMenu->clear();
for (iter = prop_list.begin(); iter != prop_list.end(); ++ iter) {
menu = new MyAction(QIcon::fromTheme(iter->icon), iter->label, this);
menu->setProp(*iter);
- mVKListMenu->addAction(menu);
+ this->addAction(menu);
}
}
-void SystemTrayMenu::doUpdateIMListMenu(const QList<KimpanelProperty> &prop_list)
-{
- mIMListMenu->clear();
- appendIMListToMenu(mIMListMenu, prop_list);
-}
-
-void SystemTrayMenu::appendIMListToMenu(QMenu *menu, const QList<KimpanelProperty> &prop_list)
+bool SystemTrayMenu::doUpdateIMListMenu(const QList<KimpanelProperty> &prop_list)
{
bool checked = false;
- MyAction *firstAction = NULL, *action;
+ MyAction *firstAction = NULL, *action = NULL, *actionChecked = NULL;
QList<KimpanelProperty>::const_iterator iter;
for (iter = prop_list.begin(); iter != prop_list.end(); ++ iter) {
@@ -185,47 +158,54 @@ void SystemTrayMenu::appendIMListToMenu(QMenu *menu, const QList<KimpanelPropert
else
action = new MyAction(QIcon::fromTheme(iter->icon), iter->label, this);
action->setProp(*iter);
- menu->addAction(action);
+ this->addAction(action);
if (firstAction == NULL)
firstAction = action;
action->setCheckable(true);
if (iter->label == this->mCurtIMLabel) {
checked = true;
+ actionChecked = action;
action->setChecked(true);
}
}
+
if (!checked && firstAction)
+ {
+ actionChecked = firstAction;
firstAction->setChecked(true);
+ }
+
+ if (actionChecked == NULL)
+ return false;
+ else
+ return actionChecked->icon().name() == "fcitx-kbd";
}
-void SystemTrayMenu::execMenu(const QList<KimpanelProperty> &prop_list)
+bool SystemTrayMenu::isIMList(const QString &key)
{
- QList<KimpanelProperty>::const_iterator iter;
+ return key.startsWith("/Fcitx/im");
+}
- switch (mExecMenuType) {
- case updateVKListMenu:
- doUpdateVKListMenu(prop_list);
- break;
- case updateIMListMenu:
- if (isUnity()) {
- mIMList = prop_list;
- triggerUpdateMainMenu();
- } else {
- doUpdateIMListMenu(prop_list);
- }
- break;
- //case updateThemerMenu:
- // tmpMenu = mSkinMenu;
- // break;
- default:
+bool SystemTrayMenu::isVKList(const QString &key)
+{
+ return key.startsWith("/Fcitx/vk");
+}
+
+void SystemTrayMenu::execMenu(const QList<KimpanelProperty> &prop_list)
+{
+ QList<KimpanelProperty>::const_iterator iter = prop_list.begin();
+ if (isIMList(iter->key))
+ mIMList = prop_list;
+ else if (isVKList(iter->key))
+ mVKList = prop_list;
+ else {
for (iter = prop_list.begin(); iter != prop_list.end(); ++ iter) {
qDebug() << QString("execMenuCallback(1:%1 2:%2 3:%3 4:%4 5:%5 6:%6)").arg(iter->key)
.arg(iter->label).arg(iter->icon).arg(iter->tip).arg(iter->state).arg(iter->menu);
}
- break;
}
- mExecMenuType = nullExecMenuType;
+ updateMainMenu();
}
void SystemTrayMenu::restart()
@@ -347,3 +327,4 @@ bool SystemTrayMenu::isUnity()
const char *desktop = getenv("XDG_CURRENT_DESKTOP");
return desktop && !strcmp(desktop, "Unity");
}
+
View
@@ -30,14 +30,6 @@
#include "config.h"
#include "skin/skinmenu.h"
-enum ExecMenuType
-{
- nullExecMenuType,
- updateVKListMenu,
- updateIMListMenu,
- //updateThemerMenu,
-};
-
class SystemTrayMenu : public QMenu
{
Q_OBJECT
@@ -47,8 +39,10 @@ class SystemTrayMenu : public QMenu
virtual ~SystemTrayMenu();
void init();
+private:
+ void updateMainMenu();
+
private slots:
- void triggerUpdateMainMenu();
void triggerUpdateVKListMenu();
void triggerUpdateIMListMenu();
void menuItemOnClick(QAction* action);
@@ -61,26 +55,25 @@ public slots:
void updateProperty(const KimpanelProperty &prop);
private:
+ //return True if is the fcitx-kbd checked.
+ bool doUpdateIMListMenu(const QList<KimpanelProperty> &prop_list);
void doUpdateVKListMenu(const QList<KimpanelProperty> &prop_list);
- void doUpdateIMListMenu(const QList<KimpanelProperty> &prop_list);
- void appendIMListToMenu(QMenu *menu, const QList<KimpanelProperty> &prop_list);
void startChildApp(const char *app_exe, const char * const argv[] = NULL);
public:
void restart();
private:
static bool isUnity();
+ static bool isIMList(const QString &key);
+ static bool isVKList(const QString &key);
private:
QString mCurtIMLabel;
//前两个用不到,见后端KimpanelRegisterAllStatus()函数
#define StatusMenuSkip (2)
QList<KimpanelProperty> mIMList;
+ QList<KimpanelProperty> mVKList;
QList<KimpanelProperty> mStatusMenuList;
- SkinMenu *mSkinMenu;
- QMenu *mVKListMenu;
- QMenu *mIMListMenu;
- ExecMenuType mExecMenuType;
};
#endif // __SYSTEM_TRAY_MENU_H__

0 comments on commit ba4369f

Please sign in to comment.