Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[metamenu] Metamenu plugin simply adds a menu to QMainWindow, which inte... #327

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
5 changes: 5 additions & 0 deletions plugins/metamenu/metamenu.qbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import "../UreenPlugin.qbs" as UreenPlugin

UreenPlugin {
condition: qbs.getenv("XDG_CURRENT_DESKTOP") === "Unity"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What? So you think that it should be not possible to build this plugin at the build farm where there is no x11 oe Unity?

}
120 changes: 120 additions & 0 deletions plugins/metamenu/src/metamenu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/****************************************************************************
**
** qutIM - instant messenger
**
** Copyright © 2014 Nicolay Izoderov <[email protected]>
** Copyright © 2014 Ivan Vizir <[email protected]>
**
*****************************************************************************
**
** $QUTIM_BEGIN_LICENSE$
** 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 3 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, see http://www.gnu.org/licenses/.
** $QUTIM_END_LICENSE$
**
****************************************************************************/

#include "metamenu.h"
#include <qutim/debug.h>
#include <qutim/chatsession.h>
#include <QMenuBar>
#include <QMainWindow>
#include <QTimer>

MetamenuPlugin::MetamenuPlugin ()
{
}

void MetamenuPlugin::init ()
{
qutim_sdk_0_3::ExtensionIcon icon("info");
addAuthor(QLatin1String("nicoizo"));
setInfo(QT_TRANSLATE_NOOP("Plugin", "MetaMenu"),
QT_TRANSLATE_NOOP("Plugin", "Ubuntu metamenu integration"),
PLUGIN_VERSION(0, 0, 1, 1),
icon
);
setCapabilities(Loadable);
}

bool MetamenuPlugin::load ()
{
QTimer::singleShot(2000, this, SLOT(shot()));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need this timer?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this timer i'll get null pointer of QMenuBar, because QMainWindow needs some time to be created

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be it's better to make "chatWidgets" a Qt's property to be able to listen signals about it's changes? So you will be able to create a QMenuBar per each widget separatly with common MenuController

m_menu = new MetaMenuController(this);
return true;
}

bool MetamenuPlugin::unload ()
{
return true;
}

/*!
* \brief MetamenuPlugin::oneOfChatWindows
* \author viv
* \return QMainWindow
*/
QWidget* MetamenuPlugin::oneOfChatWindows()
{
QObject* obj = ServiceManager::getByName("ChatForm");
QWidget *widget = 0;
bool metZero = false;
QWidgetList list;
QMetaObject::invokeMethod(obj, "chatWidgets", Q_RETURN_ARG(QWidgetList, list));
if(!list.size())
return 0;
foreach (QWidget *w, list)
if (w) {
widget = w->window();
break;
} else
metZero = true;
if (metZero) // TODO: this block should dissapear sometimes as well as variables used here
qWarning() << "Zeros still appear in ChatForm's chatWidgets list.";
return widget;
}

void MetamenuPlugin::shot() {
QWidget* window = oneOfChatWindows();

if(!m_menuBar && window)
QMetaObject::invokeMethod(window, "getMenuBar", Q_RETURN_ARG(QMenuBar*, m_menuBar));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not obvious that you set result value to m_menuBar, may you introduce a temporary variable here?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I right that this change will add contact list's menu bar to chat window at every system, not only for Unity or other systems with global menu? May be you should to add an configuration for it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, in .qbs file I limit plugin to Unity only.
Okay, I will introduce temporary variable.


QMenu* mainMenu = m_menu->menu(false);

mainMenu->setTitle("&qutIM");

if(m_menuBar && !m_added) {
qDebug() << mainMenu;
m_menuBar->addMenu(mainMenu);
m_added = true;
}

if(!m_added)
QTimer::singleShot(1000, this, SLOT(shot()));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You want to run this method infinitive times?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as there is no mainwindow

else
connect(window, SIGNAL(destroyed()), this, SLOT(onDestroyed()));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if there is no window?

}

void MetamenuPlugin::onDestroyed()
{
m_added = false;
m_menuBar = 0;
delete m_menu;
m_menu = new MetaMenuController(this);
QTimer::singleShot(1000, this, SLOT(shot()));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to have single QTimer instead of a lot of singleShots, at least it will be possible to stop it in case of plugin's unload

}



QUTIM_EXPORT_PLUGIN(MetamenuPlugin)
70 changes: 70 additions & 0 deletions plugins/metamenu/src/metamenu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/****************************************************************************
**
** qutIM - instant messenger
**
** Copyright © 2014 Nicolay Izoderov <[email protected]>
**
*****************************************************************************
**
** $QUTIM_BEGIN_LICENSE$
** 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 3 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, see http://www.gnu.org/licenses/.
** $QUTIM_END_LICENSE$
**
****************************************************************************/

#ifndef METAMENU_METAMENU_H
#define METAMENU_METAMENU_H

#include <qutim/plugin.h>
#include <qutim/servicemanager.h>
#include <qutim/menucontroller.h>
#include <qutim/chatsession.h>
#include <QMenuBar>

using namespace qutim_sdk_0_3;

class MetaMenuController : public MenuController
{
Q_OBJECT
public:
MetaMenuController(QObject *parent) : MenuController(parent)
{
if (MenuController *contactList = ServiceManager::getByName<MenuController *>("ContactList"))
setMenuOwner(contactList);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if I will change ContactList's implemenation plugin? You should add binding to update menu owner.

}
};

class MetamenuPlugin : public qutim_sdk_0_3::Plugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qutim.Plugin")
Q_CLASSINFO("DebugName", "Metamenu")
Q_CLASSINFO("Uses", "ChatLayer")
public:
explicit MetamenuPlugin ();
virtual void init();
virtual bool load();
virtual bool unload();
public slots:
void shot();
void onDestroyed();
private:
QWidget* oneOfChatWindows();
QMenuBar* m_menuBar = 0;
MenuController* m_menu;
bool m_added = false;
};

#endif /* end of include guard: METAMENU_METAMENU_H */

3 changes: 2 additions & 1 deletion plugins/plugins.qbs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Project {
"qmlchat/qmlchat.qbs",
"quickcontactlist/quickcontactlist.qbs",
"indicator/indicator.qbs",
"winintegration/winintegration.qbs"
"winintegration/winintegration.qbs",
"metamenu/metamenu.qbs",
]
}