-
Notifications
You must be signed in to change notification settings - Fork 30
[metamenu] Metamenu plugin simply adds a menu to QMainWindow, which inte... #327
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
base: master
Are you sure you want to change the base?
Changes from all commits
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())); | ||
|
Owner
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?
Collaborator
Author
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
Owner
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)); | ||
|
Owner
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?
Owner
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?
Collaborator
Author
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())); | ||
|
Owner
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?
Collaborator
Author
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())); | ||
|
Owner
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())); | ||
|
Owner
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); | ||
|
Owner
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 */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import QtQuick 2.3 | ||
| import org.qutim 0.4 | ||
| import org.qutim.quickchat 0.4 | ||
| import "../default" as Default | ||
|
|
||
|
|
||
| MessageBase { | ||
| id: root | ||
| height: messageItem.height | ||
|
|
||
| readonly property var message: messages[0] | ||
|
|
||
| Default.SelectableText { | ||
| id: messageItem | ||
| anchors { | ||
| top: parent.top | ||
| left: parent.left | ||
| margins: 4 | ||
| } | ||
| renderType: Text.NativeRendering | ||
| textFormat: Text.RichText | ||
| wrapMode: Text.WrapAtWordBoundaryOrAnywhere | ||
|
|
||
|
|
||
|
|
||
| readonly property string timeText: Qt.formatDateTime(message.time, '[hh:mm:ss]') | ||
| readonly property string timeColor: { | ||
| var incoming = message.incoming; | ||
| var success = messageReceipts[message.id]; | ||
| var history = message.property("history", false); | ||
| var color = undefined; | ||
| if (history) | ||
| color = "gray"; | ||
| else if (incoming || success === true) | ||
| color = "black"; | ||
| else if (success === false) | ||
| color = "red"; | ||
| else | ||
| color = "orange"; | ||
| return color; | ||
| } | ||
|
|
||
| readonly property string timeHtml: "<span style=\"color:" + timeColor + ";\">" + timeText + "</span>"; | ||
|
|
||
|
|
||
| property variant nickColorsArray: ["#4e9a06", "#f57900", "#ce5c00", "#3465a4", "#204a87", "#75507b", "#5c3566", "#c17d11", "#8f5902", "#ef2929", "#cc0000", "#a40000"] | ||
| readonly property string incomingNickColor: { | ||
| return nickColorsArray[root.session.hashOf(nick, nickColorsArray.length)]; | ||
| } | ||
| readonly property string nick: message.unitData.title | ||
| readonly property url appendNickUrl: session.appendNickUrl(nick) + "#do-not-style" | ||
| readonly property string nickHtml: { | ||
| return "<b><a href=\"" + appendNickUrl + "\"" + | ||
| " style=\"text-decoration: none; color:" + nickColor + "; font-weight:" + fontWeight + ";\">" + | ||
| session.htmlEscape(nick) + "</a></b>"; | ||
| } | ||
|
|
||
| readonly property string fontWeight: { | ||
| return message.property("mention", false) ? "bold" : "normal"; | ||
| } | ||
|
|
||
| readonly property string nickColor: message.incoming ? incomingNickColor : "#437ee0" | ||
|
|
||
| readonly property string messageFormattedHtml: "<span style=\"color:" + messageColor + "; font-weight: " + fontWeight + ";\" >" + message.formattedHtml().substr(4) + "</span>"; | ||
| readonly property string messageColor: { | ||
| return nickColor | ||
| } | ||
|
|
||
| text: timeHtml + " " + nickHtml + " " + messageFormattedHtml | ||
|
|
||
| property AnchorsHighlighter highlighter: AnchorsHighlighter { | ||
| Component.onCompleted: { | ||
| // TextEdit.textDocument is non-notifyable property | ||
| textDocument = messageItem.textDocument; | ||
| hoverColor = "#07A"; | ||
| activeColor = "#09C"; | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| } |
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?