Commit 5b04cc43 authored by Rafał Malinowski's avatar Rafał Malinowski

gui: added ChatWidgetManager::openChat method

Signed-off-by: Rafał Malinowski's avatarRafał Malinowski <rafal.przemyslaw.malinowski@gmail.com>
parent 9c65b13f
......@@ -25,7 +25,6 @@
#include "accounts/account.h"
#include "gui/actions/action.h"
#include "gui/widgets/chat-widget/chat-widget-manager.h"
#include "gui/widgets/chat-widget/chat-widget.h"
#include "gui/widgets/recent-chats-menu.h"
#include "recent-chats-action.h"
......@@ -59,9 +58,7 @@ void RecentChatsAction::actionInstanceCreated(Action *action)
void RecentChatsAction::openRecentChats(QAction *action)
{
ChatWidget * const chatWidget = ChatWidgetManager::instance()->byChat(action->data().value<Chat>(), true);
if (chatWidget)
chatWidget->tryActivate();
ChatWidgetManager::instance()->openChat(action->data().value<Chat>());
}
#include "moc_recent-chats-action.cpp"
......@@ -487,9 +487,7 @@ void ChatWidgetActions::openChatActionActivated(QAction *sender, bool toggled)
if (!action)
return;
ChatWidget * const chatWidget = ChatWidgetManager::instance()->byChat(action->context()->chat(), true);
if (chatWidget)
chatWidget->tryActivate();
ChatWidgetManager::instance()->openChat(action->context()->chat());
kdebugf2();
}
......
......@@ -93,7 +93,7 @@ void ChatWidgetManager::openPersistedChatWindows()
m_chatWindowStorage.data()->ensureLoaded();
auto chats = m_chatWindowStorage.data()->loadedChats();
foreach (const auto &chat, chats)
byChat(chat, true);
m_chatWidgetRepository.data()->widgetForChat(chat);
}
void ChatWidgetManager::closeAllWindows()
......@@ -136,6 +136,15 @@ void ChatWidgetManager::chatWidgetCreated(ChatWidget *chatWidget)
}
}
void ChatWidgetManager::openChat(const Chat &chat)
{
if (!m_chatWindowRepository)
return;
auto chatWidget = m_chatWidgetRepository.data()->widgetForChat(chat);
chatWidget->tryActivate();
}
void ChatWidgetManager::closeChat(const Chat &chat)
{
ChatWidget * const chatWidget = byChat(chat, false);
......
......@@ -83,6 +83,8 @@ public:
ChatWidget * byChat(const Chat &chat, const bool create);
public slots:
void openChat(const Chat &chat);
/**
* @short Close ChatWidget for given chat.
* @param chat chat to close chat widget for
......
......@@ -34,7 +34,6 @@
#include "gui/widgets/account-buddy-list-widget.h"
#include "gui/widgets/accounts-combo-box.h"
#include "gui/widgets/chat-widget/chat-widget-manager.h"
#include "gui/widgets/chat-widget/chat-widget.h"
#include "gui/widgets/filtered-tree-view.h"
#include "gui/widgets/talkable-tree-view.h"
#include "icons/kadu-icon.h"
......@@ -277,10 +276,7 @@ void AddConferenceWindow::start()
if (!DisplayNameEdit->text().isEmpty())
chat.setDisplay(DisplayNameEdit->text());
ChatWidget * const chatWidget = ChatWidgetManager::instance()->byChat(computeChat(), true);
if (chatWidget)
chatWidget->tryActivate();
ChatWidgetManager::instance()->openChat(computeChat());
QDialog::accept();
}
......
......@@ -33,7 +33,6 @@
#include "configuration/config-file-variant-wrapper.h"
#include "gui/widgets/accounts-combo-box.h"
#include "gui/widgets/chat-widget/chat-widget-manager.h"
#include "gui/widgets/chat-widget/chat-widget.h"
#include "icons/kadu-icon.h"
#include "os/generic/window-geometry-manager.h"
#include "protocols/protocol.h"
......@@ -228,9 +227,7 @@ void AddRoomChatWindow::start()
if (!DisplayNameEdit->text().isEmpty())
chat.setDisplay(DisplayNameEdit->text());
ChatWidget * const chatWidget = ChatWidgetManager::instance()->byChat(computeChat(), true);
if (chatWidget)
chatWidget->tryActivate();
ChatWidgetManager::instance()->openChat(computeChat());
ChatDetailsRoom *details = qobject_cast<ChatDetailsRoom *>(chat.details());
Q_ASSERT(details);
......
......@@ -57,7 +57,6 @@
#include "gui/widgets/buddy-info-panel.h"
#include "gui/widgets/chat-widget/chat-widget-actions.h"
#include "gui/widgets/chat-widget/chat-widget-manager.h"
#include "gui/widgets/chat-widget/chat-widget.h"
#include "gui/widgets/recent-chats-menu.h"
#include "gui/widgets/roster-widget.h"
#include "gui/widgets/status-buttons.h"
......@@ -297,9 +296,7 @@ void KaduWindow::talkableActivatedSlot(const Talkable &talkable)
const Chat &chat = talkable.toChat();
if (chat && !chat.contacts().toBuddySet().contains(Core::instance()->myself()))
{
ChatWidget * const chatWidget = ChatWidgetManager::instance()->byChat(chat, true);
if (chatWidget)
chatWidget->tryActivate();
ChatWidgetManager::instance()->openChat(chat);
return;
}
......
......@@ -41,7 +41,6 @@
#include "configuration/xml-configuration-file.h"
#include "contacts/contact.h"
#include "gui/widgets/chat-widget/chat-widget-manager.h"
#include "gui/widgets/chat-widget/chat-widget.h"
#include "gui/widgets/filtered-tree-view.h"
#include "gui/widgets/line-edit-with-clear-button.h"
#include "misc/kadu-paths.h"
......@@ -225,10 +224,7 @@ void OpenChatWith::itemActivated(int index)
if (!chat)
return;
ChatWidget * const chatWidget = ChatWidgetManager::instance()->byChat(chat, true);
if (chatWidget)
chatWidget->tryActivate();
ChatWidgetManager::instance()->openChat(chat);
deleteLater();
}
......
......@@ -51,7 +51,6 @@
#include "core/core.h"
#include "gui/actions/base-action-context.h"
#include "gui/widgets/chat-widget/chat-widget-manager.h"
#include "gui/widgets/chat-widget/chat-widget.h"
#include "gui/widgets/toolbar.h"
#include "gui/windows/add-buddy-window.h"
#include "gui/windows/kadu-window.h"
......@@ -338,9 +337,7 @@ void SearchWindow::chatFound()
const Chat &chat = 1 == contacts.size()
? ChatTypeContact::findChat(*contacts.constBegin(), ActionCreateAndAdd)
: ChatTypeContactSet::findChat(contacts, ActionCreateAndAdd);
ChatWidget * const chatWidget = ChatWidgetManager::instance()->byChat(chat, true);
if (chatWidget)
chatWidget->tryActivate();
ChatWidgetManager::instance()->openChat(chat);
}
}
......
......@@ -24,7 +24,6 @@
#include "chat/chat.h"
#include "gui/widgets/chat-widget/chat-widget-manager.h"
#include "gui/widgets/chat-widget/chat-widget.h"
#include "chat-notification.h"
......@@ -39,9 +38,7 @@ void ChatNotification::openChat()
{
close();
ChatWidget * const chatWidget = ChatWidgetManager::instance()->byChat(chat(), true);
if (chatWidget)
chatWidget->tryActivate();
ChatWidgetManager::instance()->openChat(chat());
}
void ChatNotification::callbackAccept()
......
......@@ -43,7 +43,6 @@
#include "configuration/configuration-file.h"
#include "core/core.h"
#include "gui/widgets/chat-widget/chat-widget.h"
#include "gui/widgets/chat-widget/chat-widget-manager.h"
#include "gui/widgets/status-menu.h"
#include "gui/windows/kadu-window.h"
......@@ -400,9 +399,7 @@ void DockingManager::hideKaduWindow()
void DockingManager::openUnreadMessages()
{
const Message &message = Core::instance()->unreadMessageRepository()->unreadMessage();
ChatWidget * const chatWidget = ChatWidgetManager::instance()->byChat(message.messageChat(), true);
if (chatWidget)
chatWidget->tryActivate();
ChatWidgetManager::instance()->openChat(message.messageChat());
}
void DockingManager::trayMousePressEvent(QMouseEvent * e)
......
......@@ -32,7 +32,6 @@
#include "contacts/contact.h"
#include "core/core.h"
#include "gui/widgets/chat-widget/chat-widget-manager.h"
#include "gui/widgets/chat-widget/chat-widget.h"
#include "icons/kadu-icon.h"
#include "misc/misc.h"
#include "status/status-container.h"
......@@ -72,9 +71,7 @@ void GaduUrlHandler::openUrl(const QByteArray &url, bool disableMenu)
const Chat &chat = ChatTypeContact::findChat(contact, ActionCreateAndAdd);
if (chat)
{
ChatWidget * const chatWidget = ChatWidgetManager::instance()->byChat(chat, true);
if (chatWidget)
chatWidget->tryActivate();
ChatWidgetManager::instance()->openChat(chat);
return;
}
}
......@@ -111,9 +108,7 @@ void GaduUrlHandler::accountSelected(QAction *action)
const Contact &contact = ContactManager::instance()->byId(account, ids[1], ActionCreateAndAdd);
const Chat &chat = ChatTypeContact::findChat(contact, ActionCreateAndAdd);
ChatWidget * const chatWidget = ChatWidgetManager::instance()->byChat(chat, true);
if (chatWidget)
chatWidget->tryActivate();
ChatWidgetManager::instance()->openChat(chat);
}
#include "moc_gadu-url-handler.cpp"
......@@ -41,7 +41,6 @@
#include "contacts/contact.h"
#include "core/core.h"
#include "gui/widgets/chat-widget/chat-widget-manager.h"
#include "gui/widgets/chat-widget/chat-widget.h"
#include "gui/widgets/tool-tip-class-manager.h"
#include "message/message-manager.h"
#include "message/unread-message-repository.h"
......@@ -376,9 +375,7 @@ void HintManager::openChat(Hint *hint)
if ((hint->getNotification()->type() != "NewChat") && (hint->getNotification()->type() != "NewMessage"))
return;
ChatWidget * const chatWidget = ChatWidgetManager::instance()->byChat(hint->chat(), true);
if (chatWidget)
chatWidget->tryActivate();
ChatWidgetManager::instance()->openChat(hint->chat());
deleteHintAndUpdate(hint);
......
......@@ -34,7 +34,6 @@
#include "dom/dom-processor.h"
#include "dom/ignore-links-dom-visitor.h"
#include "gui/widgets/chat-widget/chat-widget-manager.h"
#include "gui/widgets/chat-widget/chat-widget.h"
#include "icons/kadu-icon.h"
#include "misc/misc.h"
#include "status/status-container.h"
......@@ -91,9 +90,7 @@ void JabberUrlHandler::openUrl(const QByteArray &url, bool disableMenu)
const Chat &chat = ChatTypeContact::findChat(contact, ActionCreateAndAdd);
if (chat)
{
ChatWidget * const chatWidget = ChatWidgetManager::instance()->byChat(chat, true);
if (chatWidget)
chatWidget->tryActivate();
ChatWidgetManager::instance()->openChat(chat);
return;
}
}
......@@ -130,9 +127,7 @@ void JabberUrlHandler::accountSelected(QAction *action)
const Contact &contact = ContactManager::instance()->byId(account, ids[1], ActionCreateAndAdd);
const Chat &chat = ChatTypeContact::findChat(contact, ActionCreateAndAdd);
ChatWidget * const chatWidget = ChatWidgetManager::instance()->byChat(chat, true);
if (chatWidget)
chatWidget->tryActivate();
ChatWidgetManager::instance()->openChat(chat);
}
#include "moc_jabber-url-handler.cpp"
......@@ -33,7 +33,6 @@
#include "configuration/configuration-file.h"
#include "gui/widgets/chat-widget/chat-widget-manager.h"
#include "gui/widgets/chat-widget/chat-widget.h"
#include "gui/windows/message-dialog.h"
#include "parser/parser.h"
#include "debug.h"
......@@ -134,9 +133,7 @@ void Qt4Notify::notify(Notification *notification)
void Qt4Notify::messageClicked()
{
ChatWidget * const chatWidget = ChatWidgetManager::instance()->byChat(chat, true);
if (chatWidget)
chatWidget->tryActivate();
ChatWidgetManager::instance()->openChat(chat);
}
NotifierConfigurationWidget *Qt4Notify::createConfigurationWidget(QWidget *parent)
......
......@@ -461,9 +461,7 @@ void TabWidget::openTabsList()
void TabWidget::openRecentChat(QAction *action)
{
ChatWidget * const chatWidget = ChatWidgetManager::instance()->byChat(action->data().value<Chat>(), true);
if (chatWidget)
chatWidget->tryActivate();
ChatWidgetManager::instance()->openChat(action->data().value<Chat>());
}
void TabWidget::deleteTab()
......
......@@ -581,9 +581,7 @@ bool TabsManager::detachChat(ChatWidget *chatWidget)
// omg this is bad
chat.addProperty("tabs:detached", true, CustomProperties::Storable);
ChatWidget * const detachedChatWidget = ChatWidgetManager::instance()->byChat(chat, true);
if (detachedChatWidget)
detachedChatWidget->tryActivate();
ChatWidgetManager::instance()->openChat(chat);
return true;
}
......@@ -784,10 +782,7 @@ void TabsManager::reopenClosedChat()
if (ClosedChats.isEmpty())
return;
ChatWidget * const chatWidget = ChatWidgetManager::instance()->byChat(ClosedChats.takeFirst(), true);
if (chatWidget)
chatWidget->tryActivate();
ChatWidgetManager::instance()->openChat(ClosedChats.takeFirst());
ReopenClosedTabMenuAction->setEnabled(ClosedChats.isEmpty());
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment