-
Notifications
You must be signed in to change notification settings - Fork 32
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
86cb68e
4ed0a40
e21db5f
edab81b
35395ec
4051807
a722274
2e1971f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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" | ||
} |
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())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you need this timer? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, in .qbs file I limit plugin to Unity only. |
||
|
||
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())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You want to run this method infinitive times? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) |
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 */ | ||
|
There was a problem hiding this comment.
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?