Commit c7720895 authored by Rafał Malinowski's avatar Rafał Malinowski

gui: remove singleton from ChatWidgetManager

Signed-off-by: Rafał Malinowski's avatarRafał Malinowski <rafal.przemyslaw.malinowski@gmail.com>
parent cae90de9
......@@ -601,9 +601,13 @@ void Core::runServices()
CurrentChatWidgetRepository = new ChatWidgetRepository(this);
CurrentChatWidgetManager = new ChatWidgetManager(this);
CurrentChatWidgetManager->setChatWidgetFactory(CurrentChatWidgetFactory);
CurrentChatWidgetManager->setChatWidgetRepository(CurrentChatWidgetRepository);
CurrentChatWidgetMessageHandler = new ChatWidgetMessageHandler(this);
CurrentChatWidgetMessageHandler->setBuddyChatManager(BuddyChatManager::instance());
CurrentChatWidgetMessageHandler->setChatWidgetManager(ChatWidgetManager::instance());
CurrentChatWidgetMessageHandler->setChatWidgetManager(CurrentChatWidgetManager);
CurrentChatWidgetMessageHandler->setChatWidgetRepository(CurrentChatWidgetRepository);
CurrentChatWidgetMessageHandler->setMessageManager(MessageManager::instance());
CurrentChatWidgetMessageHandler->setUnreadMessageRepository(CurrentUnreadMessageRepository);
......@@ -631,10 +635,8 @@ void Core::runServices()
auto chatWindowStorageConfigurator = new ChatWindowStorageConfigurator(); // this is basically a global so we do not care about relesing it
chatWindowStorageConfigurator->setChatWindowStorage(CurrentChatWindowStorage);
ChatWidgetManager::instance()->setChatWidgetFactory(CurrentChatWidgetFactory);
ChatWidgetManager::instance()->setChatWidgetRepository(CurrentChatWidgetRepository);
CurrentChatWindowManager = new ChatWindowManager(this);
CurrentChatWindowManager->setChatWidgetManager(CurrentChatWidgetManager);
CurrentChatWindowManager->setChatWindowRepository(CurrentChatWindowRepository);
CurrentChatWindowManager->setChatWindowStorage(CurrentChatWindowStorage);
CurrentChatWindowManager->openStoredChatWindows();
......@@ -772,6 +774,11 @@ ChatWidgetActions * Core::chatWidgetActions() const
return CurrentChatWidgetActions;
}
ChatWidgetManager * Core::chatWidgetManager() const
{
return CurrentChatWidgetManager;
}
ChatWidgetFactory * Core::chatWidgetFactory() const
{
return CurrentChatWidgetFactory;
......
......@@ -60,6 +60,7 @@ class ChatWidgetActions;
class ChatWidgetContainerHandlerMapper;
class ChatWidgetContainerHandlerRepository;
class ChatWidgetFactory;
class ChatWidgetManager;
class ChatWidgetMessageHandler;
class ChatWidgetRepository;
class ChatWindowFactory;
......@@ -115,6 +116,7 @@ class KADUAPI Core : public QObject, private AccountsAwareObject, public Configu
ChatWidgetContainerHandlerMapper *CurrentChatWidgetContainerHandlerMapper;
ChatWidgetContainerHandlerRepository *CurrentChatWidgetContainerHandlerRepository;
ChatWidgetFactory *CurrentChatWidgetFactory;
ChatWidgetManager *CurrentChatWidgetManager;
ChatWidgetMessageHandler *CurrentChatWidgetMessageHandler;
ChatWidgetRepository *CurrentChatWidgetRepository;
ChatWindowFactory *CurrentChatWindowFactory;
......@@ -194,6 +196,7 @@ public:
ChatWidgetContainerHandlerMapper * chatWidgetContainerHandlerMapper() const;
ChatWidgetContainerHandlerRepository * chatWidgetContainerHandlerRepository() const;
ChatWidgetFactory * chatWidgetFactory() const;
ChatWidgetManager * chatWidgetManager() const;
ChatWidgetRepository * chatWidgetRepository() const;
ChatWindowFactory * chatWindowFactory() const;
ChatWindowManager * chatWindowManager() const;
......
......@@ -23,6 +23,7 @@
#include "accounts/account-manager.h"
#include "accounts/account.h"
#include "core/core.h"
#include "gui/actions/action.h"
#include "gui/widgets/chat-widget/chat-widget-manager.h"
#include "gui/widgets/recent-chats-menu.h"
......@@ -58,7 +59,7 @@ void RecentChatsAction::actionInstanceCreated(Action *action)
void RecentChatsAction::openRecentChats(QAction *action)
{
ChatWidgetManager::instance()->openChat(action->data().value<Chat>(), OpenChatActivation::Activate);
Core::instance()->chatWidgetManager()->openChat(action->data().value<Chat>(), OpenChatActivation::Activate);
}
#include "moc_recent-chats-action.cpp"
......@@ -487,7 +487,7 @@ void ChatWidgetActions::openChatActionActivated(QAction *sender, bool toggled)
if (!action)
return;
ChatWidgetManager::instance()->openChat(action->context()->chat(), OpenChatActivation::Activate);
Core::instance()->chatWidgetManager()->openChat(action->context()->chat(), OpenChatActivation::Activate);
kdebugf2();
}
......
......@@ -30,17 +30,8 @@
#include "gui/widgets/chat-widget/chat-widget-repository.h"
#include "gui/widgets/chat-widget/chat-widget.h"
ChatWidgetManager * ChatWidgetManager::m_instance = nullptr;
ChatWidgetManager * ChatWidgetManager::instance()
{
if (!m_instance)
m_instance = new ChatWidgetManager();
return m_instance;
}
ChatWidgetManager::ChatWidgetManager()
ChatWidgetManager::ChatWidgetManager(QObject *parent) :
QObject{parent}
{
}
......
......@@ -47,11 +47,7 @@ enum class OpenChatActivation
/**
* @class ChatWidgetManager
* @short Manager of all ChatWidget instances.
* @todo replace handleNewChatWidget with better mechanism
* @todo create some kind of per-container manager than can store its own configuration
*
* This singleton is responsible for all ChatWidget instances in Kadu.
* @short Class for opening and closing chat widgets.
*/
class KADUAPI ChatWidgetManager : public QObject
{
......@@ -59,25 +55,23 @@ class KADUAPI ChatWidgetManager : public QObject
Q_DISABLE_COPY(ChatWidgetManager)
public:
/**
* @short Returns manager's singleton instance.
* @return manager's singleton instance
*
* Returns manager's singleton instance.
*/
static ChatWidgetManager * instance();
explicit ChatWidgetManager(QObject *parent = nullptr);
virtual ~ChatWidgetManager();
void setChatWidgetRepository(ChatWidgetRepository *chatWidgetRepository);
void setChatWidgetFactory(ChatWidgetFactory *chatWidgetFactory);
public slots:
/**
* @short Open given chat.
*
* If activation is set to OpenChatActivation::Activate then newly opened
* chat will be activated.
*/
void openChat(const Chat &chat, OpenChatActivation activation);
/**
* @short Close ChatWidget for given chat.
* @param chat chat to close chat widget for
*
* This method closes ChatWidget for given chat.
* @short Close given chat.
*/
void closeChat(const Chat &chat);
......@@ -87,9 +81,6 @@ private:
QWeakPointer<ChatWidgetRepository> m_chatWidgetRepository;
QWeakPointer<ChatWidgetFactory> m_chatWidgetFactory;
ChatWidgetManager();
virtual ~ChatWidgetManager();
};
/**
......
......@@ -31,6 +31,7 @@
#include "chat/chat-manager.h"
#include "chat/type/chat-type-contact-set.h"
#include "configuration/config-file-variant-wrapper.h"
#include "core/core.h"
#include "gui/widgets/account-buddy-list-widget.h"
#include "gui/widgets/accounts-combo-box.h"
#include "gui/widgets/chat-widget/chat-widget-manager.h"
......@@ -276,7 +277,7 @@ void AddConferenceWindow::start()
if (!DisplayNameEdit->text().isEmpty())
chat.setDisplay(DisplayNameEdit->text());
ChatWidgetManager::instance()->openChat(computeChat(), OpenChatActivation::Activate);
Core::instance()->chatWidgetManager()->openChat(computeChat(), OpenChatActivation::Activate);
QDialog::accept();
}
......
......@@ -31,6 +31,7 @@
#include "chat/chat-manager.h"
#include "chat/type/chat-type-room.h"
#include "configuration/config-file-variant-wrapper.h"
#include "core/core.h"
#include "gui/widgets/accounts-combo-box.h"
#include "gui/widgets/chat-widget/chat-widget-manager.h"
#include "icons/kadu-icon.h"
......@@ -227,7 +228,7 @@ void AddRoomChatWindow::start()
if (!DisplayNameEdit->text().isEmpty())
chat.setDisplay(DisplayNameEdit->text());
ChatWidgetManager::instance()->openChat(computeChat(), OpenChatActivation::Activate);
Core::instance()->chatWidgetManager()->openChat(computeChat(), OpenChatActivation::Activate);
ChatDetailsRoom *details = qobject_cast<ChatDetailsRoom *>(chat.details());
Q_ASSERT(details);
......
......@@ -33,6 +33,10 @@ ChatWindowManager::ChatWindowManager(QObject *parent) :
ChatWindowManager::~ChatWindowManager()
{
}
void ChatWindowManager::setChatWidgetManager(ChatWidgetManager *chatWidgetManager)
{
m_chatWidgetManager = chatWidgetManager;
}
void ChatWindowManager::setChatWindowRepository(ChatWindowRepository *chatWindowRepository)
{
......@@ -51,7 +55,7 @@ void ChatWindowManager::openStoredChatWindows()
auto chats = m_chatWindowStorage.data()->loadChats();
for (const auto &chat : chats)
ChatWidgetManager::instance()->openChat(chat, OpenChatActivation::DoNotActivate);
m_chatWidgetManager.data()->openChat(chat, OpenChatActivation::DoNotActivate);
}
void ChatWindowManager::storeOpenedChatWindows()
......
......@@ -22,6 +22,7 @@
#include <QtCore/QObject>
#include <QtCore/QWeakPointer>
class ChatWidgetManager;
class ChatWindowStorage;
class ChatWindowRepository;
......@@ -33,14 +34,16 @@ public:
explicit ChatWindowManager(QObject *parent = 0);
virtual ~ChatWindowManager();
void setChatWindowStorage(ChatWindowStorage *chatWindowStorage);
void setChatWidgetManager(ChatWidgetManager *chatWidgetManager);
void setChatWindowRepository(ChatWindowRepository *chatWindowRepository);
void setChatWindowStorage(ChatWindowStorage *chatWindowStorage);
void openStoredChatWindows();
void storeOpenedChatWindows();
private:
QWeakPointer<ChatWindowStorage> m_chatWindowStorage;
QWeakPointer<ChatWidgetManager> m_chatWidgetManager;
QWeakPointer<ChatWindowRepository> m_chatWindowRepository;
QWeakPointer<ChatWindowStorage> m_chatWindowStorage;
};
......@@ -296,7 +296,7 @@ void KaduWindow::talkableActivatedSlot(const Talkable &talkable)
const Chat &chat = talkable.toChat();
if (chat && !chat.contacts().toBuddySet().contains(Core::instance()->myself()))
{
ChatWidgetManager::instance()->openChat(chat, OpenChatActivation::Activate);
Core::instance()->chatWidgetManager()->openChat(chat, OpenChatActivation::Activate);
return;
}
......
......@@ -40,6 +40,7 @@
#include "chat/type/chat-type-contact.h"
#include "configuration/xml-configuration-file.h"
#include "contacts/contact.h"
#include "core/core.h"
#include "gui/widgets/chat-widget/chat-widget-manager.h"
#include "gui/widgets/filtered-tree-view.h"
#include "gui/widgets/line-edit-with-clear-button.h"
......@@ -224,7 +225,7 @@ void OpenChatWith::itemActivated(int index)
if (!chat)
return;
ChatWidgetManager::instance()->openChat(chat, OpenChatActivation::Activate);
Core::instance()->chatWidgetManager()->openChat(chat, OpenChatActivation::Activate);
deleteLater();
}
......
......@@ -337,7 +337,7 @@ void SearchWindow::chatFound()
const Chat &chat = 1 == contacts.size()
? ChatTypeContact::findChat(*contacts.constBegin(), ActionCreateAndAdd)
: ChatTypeContactSet::findChat(contacts, ActionCreateAndAdd);
ChatWidgetManager::instance()->openChat(chat, OpenChatActivation::Activate);
Core::instance()->chatWidgetManager()->openChat(chat, OpenChatActivation::Activate);
}
}
......
......@@ -23,6 +23,7 @@
*/
#include "chat/chat.h"
#include "core/core.h"
#include "gui/widgets/chat-widget/chat-widget-manager.h"
#include "chat-notification.h"
......@@ -38,7 +39,7 @@ void ChatNotification::openChat()
{
close();
ChatWidgetManager::instance()->openChat(chat(), OpenChatActivation::Activate);
Core::instance()->chatWidgetManager()->openChat(chat(), OpenChatActivation::Activate);
}
void ChatNotification::callbackAccept()
......
......@@ -400,7 +400,7 @@ void DockingManager::hideKaduWindow()
void DockingManager::openUnreadMessages()
{
const Message &message = Core::instance()->unreadMessageRepository()->unreadMessage();
ChatWidgetManager::instance()->openChat(message.messageChat(), OpenChatActivation::Activate);
Core::instance()->chatWidgetManager()->openChat(message.messageChat(), OpenChatActivation::Activate);
}
void DockingManager::trayMousePressEvent(QMouseEvent * e)
......@@ -673,7 +673,7 @@ void DockingManager::unregisterModuleAction(QAction *action)
#ifdef Q_OS_MAC
void DockingManager::showMinimizedChats()
{
foreach (ChatWidget *chat, ChatWidgetManager::instance()->chats())
foreach (ChatWidget *chat, Core::instance()->chatWidgetManager()->chats())
chat->activate();
}
......
......@@ -71,7 +71,7 @@ void GaduUrlHandler::openUrl(const QByteArray &url, bool disableMenu)
const Chat &chat = ChatTypeContact::findChat(contact, ActionCreateAndAdd);
if (chat)
{
ChatWidgetManager::instance()->openChat(chat, OpenChatActivation::Activate);
Core::instance()->chatWidgetManager()->openChat(chat, OpenChatActivation::Activate);
return;
}
}
......@@ -108,7 +108,7 @@ void GaduUrlHandler::accountSelected(QAction *action)
const Contact &contact = ContactManager::instance()->byId(account, ids[1], ActionCreateAndAdd);
const Chat &chat = ChatTypeContact::findChat(contact, ActionCreateAndAdd);
ChatWidgetManager::instance()->openChat(chat, OpenChatActivation::Activate);
Core::instance()->chatWidgetManager()->openChat(chat, OpenChatActivation::Activate);
}
#include "moc_gadu-url-handler.cpp"
......@@ -375,7 +375,7 @@ void HintManager::openChat(Hint *hint)
if ((hint->getNotification()->type() != "NewChat") && (hint->getNotification()->type() != "NewMessage"))
return;
ChatWidgetManager::instance()->openChat(hint->chat(), OpenChatActivation::Activate);
Core::instance()->chatWidgetManager()->openChat(hint->chat(), OpenChatActivation::Activate);
deleteHintAndUpdate(hint);
......
......@@ -30,6 +30,7 @@
#include "contacts/contact-manager.h"
#include "contacts/contact-set.h"
#include "contacts/contact.h"
#include "core/core.h"
#include "dom/dom-processor-service.h"
#include "dom/dom-processor.h"
#include "dom/ignore-links-dom-visitor.h"
......@@ -90,7 +91,7 @@ void JabberUrlHandler::openUrl(const QByteArray &url, bool disableMenu)
const Chat &chat = ChatTypeContact::findChat(contact, ActionCreateAndAdd);
if (chat)
{
ChatWidgetManager::instance()->openChat(chat, OpenChatActivation::Activate);
Core::instance()->chatWidgetManager()->openChat(chat, OpenChatActivation::Activate);
return;
}
}
......@@ -127,7 +128,7 @@ void JabberUrlHandler::accountSelected(QAction *action)
const Contact &contact = ContactManager::instance()->byId(account, ids[1], ActionCreateAndAdd);
const Chat &chat = ChatTypeContact::findChat(contact, ActionCreateAndAdd);
ChatWidgetManager::instance()->openChat(chat, OpenChatActivation::Activate);
Core::instance()->chatWidgetManager()->openChat(chat, OpenChatActivation::Activate);
}
#include "moc_jabber-url-handler.cpp"
......@@ -32,6 +32,7 @@
#include "notify/notification/notification.h"
#include "configuration/configuration-file.h"
#include "core/core.h"
#include "gui/widgets/chat-widget/chat-widget-manager.h"
#include "gui/windows/message-dialog.h"
#include "parser/parser.h"
......@@ -133,7 +134,7 @@ void Qt4Notify::notify(Notification *notification)
void Qt4Notify::messageClicked()
{
ChatWidgetManager::instance()->openChat(chat, OpenChatActivation::Activate);
Core::instance()->chatWidgetManager()->openChat(chat, OpenChatActivation::Activate);
}
NotifierConfigurationWidget *Qt4Notify::createConfigurationWidget(QWidget *parent)
......
......@@ -112,7 +112,7 @@ SingleWindow::SingleWindow()
connect(m_tabs, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));
connect(m_tabs, SIGNAL(currentChanged(int)), this, SLOT(onTabChange(int)));
connect(ChatWidgetManager::instance(), SIGNAL(handleNewChatWidget(ChatWidget *,bool &)),
connect(Core::instance()->chatWidgetManager(), SIGNAL(handleNewChatWidget(ChatWidget *,bool &)),
this, SLOT(onNewChat(ChatWidget *,bool &)));
connect(kadu, SIGNAL(keyPressed(QKeyEvent *)), this, SLOT(onkaduKeyPressed(QKeyEvent *)));
......@@ -131,7 +131,7 @@ SingleWindow::~SingleWindow()
config_file.writeEntry("SingleWindow", "KaduWindowWidth", kadu->width());
disconnect(ChatWidgetManager::instance(), 0, this, 0);
disconnect(Core::instance()->chatWidgetManager(), 0, this, 0);
disconnect(m_tabs, 0, this, 0);
disconnect(kadu, 0, this, 0);
......@@ -143,7 +143,7 @@ SingleWindow::~SingleWindow()
const Chat &chat = chatWidget->chat();
m_tabs->removeTab(i);
delete chatWidget;
ChatWidgetManager::instance()->openChat(chat, OpenChatActivation::DoNotActivate);
Core::instance()->chatWidgetManager()->openChat(chat, OpenChatActivation::DoNotActivate);
}
}
......
......@@ -461,7 +461,7 @@ void TabWidget::openTabsList()
void TabWidget::openRecentChat(QAction *action)
{
ChatWidgetManager::instance()->openChat(action->data().value<Chat>(), OpenChatActivation::Activate);
Core::instance()->chatWidgetManager()->openChat(action->data().value<Chat>(), OpenChatActivation::Activate);
}
void TabWidget::deleteTab()
......
......@@ -128,7 +128,7 @@ TabsManager::~TabsManager()
->removeAction(OpenInNewTabActionDescription);
Timer.stop();
disconnect(ChatWidgetManager::instance(), 0, this, 0);
disconnect(Core::instance()->chatWidgetManager(), 0, this, 0);
if (m_chatWidgetRepository)
disconnect(m_chatWidgetRepository.data(), 0, this, 0);
......@@ -321,7 +321,7 @@ void TabsManager::onNewTab(QAction *sender, bool toggled)
else if (chat.contacts().count() == 1 || ConfigConferencesInTabs)
ForceTabs = true;
ChatWidgetManager::instance()->openChat(chat, OpenChatActivation::DoNotActivate);
Core::instance()->chatWidgetManager()->openChat(chat, OpenChatActivation::DoNotActivate);
}
kdebugf2();
......@@ -577,7 +577,7 @@ bool TabsManager::detachChat(ChatWidget *chatWidget)
// omg this is bad
chat.addProperty("tabs:detached", true, CustomProperties::Storable);
ChatWidgetManager::instance()->openChat(chat, OpenChatActivation::Activate);
Core::instance()->chatWidgetManager()->openChat(chat, OpenChatActivation::Activate);
return true;
}
......@@ -611,7 +611,7 @@ void TabsManager::load()
ForceTabs = true;
else if (element.attribute("type") == "detachedChat")
chat.addProperty("tabs:detached", true, CustomProperties::Storable);
ChatWidgetManager::instance()->openChat(chat, OpenChatActivation::DoNotActivate);
Core::instance()->chatWidgetManager()->openChat(chat, OpenChatActivation::DoNotActivate);
}
else if (element.attribute("type") == "tab")
insertTab(chatWidget);
......@@ -757,7 +757,7 @@ void TabsManager::reopenClosedChat()
if (ClosedChats.isEmpty())
return;
ChatWidgetManager::instance()->openChat(ClosedChats.takeFirst(), OpenChatActivation::Activate);
Core::instance()->chatWidgetManager()->openChat(ClosedChats.takeFirst(), OpenChatActivation::Activate);
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