remove useless members
[makneto-zunavac1.git] / src / ui-kde / sessiontabmanager.cpp
blob9189b2dbc4d0368da8c60ba3964b7d6c93e6550f
1 /*
2 * sessiontabmanager.cpp
4 * Copyright (C) 2008 Jaroslav Reznik <rezzabuh@gmail.com>
5 */
7 #include "sessiontabmanager.h"
8 #include "sessionview.h"
9 #include "maknetohtmlbrowser.h"
11 #include "ktabbar.h"
12 #include "kiconloader.h"
15 #include <QtGui/QVBoxLayout>
16 #include <QtGui/QWidget>
17 #include <QtGui/QStackedWidget>
18 #include <QtGui/QFrame>
19 #include <QDebug>
21 //vtheman
22 #include "../backend/telepathy-client.h"
24 SessionTabManager::SessionTabManager(Makneto *makneto, QWidget *) : m_makneto(makneto) {
25 m_mainlayout = new QVBoxLayout(this);
26 m_mainlayout->setMargin(5);
27 m_mainlayout->setSpacing(5);
29 m_tab = new KTabBar(this);
30 m_tab->setHoverCloseButton(true);
32 m_widgets = new QStackedWidget();
34 m_mainlayout->addWidget(m_tab);
35 m_mainlayout->addWidget(m_widgets);
37 // connect tab bar with widgets
38 connect(m_tab, SIGNAL(currentChanged(int)), m_widgets, SLOT(setCurrentIndex(int)));
40 // Close tab on request
41 connect(m_tab, SIGNAL(closeRequest(int)), this, SLOT(closeTab(int)));
43 // TODO: and status (from contact list?)
45 // KHTMLpart widget for "Home tab"
46 MaknetoHTMLBrowser *homeTabBrowser = new MaknetoHTMLBrowser(this);
48 m_tab->addTab("Home");
49 m_widgets->addWidget(homeTabBrowser);
51 setLayout(m_mainlayout);
54 SessionTabManager::~SessionTabManager() {
61 // SessionView* SessionTabManager::newSessionTab(const QString &text, ChatType type, const QString &nick)
62 // {
63 // // There shouldn't be the same tab twice, so we won't create it
64 // SessionView *session = findSession(text);
65 // if (session)
66 // return session;
67 //
68 // // add new tab
69 // m_tab->addTab(text);
70 //
71 // // create new session view and add to widgets
72 // session = new SessionView(this, text, m_tab->count()-1, type, nick);
73 // m_widgets->addWidget(session);
74 //
75 // connect(session, SIGNAL(sendMessage(const Message &)), m_makneto->getConnection(), SLOT(sendMessage(const Message &)));
76 //
77 // return session;
78 // }
83 /**
84 * @param
85 * @return session
87 //FIXME - possibly can be left as is
89 SessionView* SessionTabManager::findSession(const QString &sessionId) {
90 SessionView *sessionView;
92 // From 1!!! First widget is home tab!
93 for (int i = 1; i < m_widgets->count(); i++) {
94 sessionView = dynamic_cast<SessionView*> (m_widgets->widget(i));
96 if (sessionView->sessionId() == sessionId)
97 return sessionView;
100 return 0;
103 //IS OK
105 void SessionTabManager::bringToFront(SessionView *session) {
106 qDebug() << "SessionTabManager: BringToFront(" << session->sessionId() << ")";
108 SessionView *sessionView;
109 for (int i = 1; i < m_widgets->count(); i++) {
110 sessionView = dynamic_cast<SessionView*> (m_widgets->widget(i));
112 if (sessionView->sessionId() == session->sessionId())
113 m_tab->setCurrentIndex(i);
117 //IS OK
119 SessionView *SessionTabManager::activeSession() {
120 return dynamic_cast<SessionView *> (m_widgets->currentWidget());
123 //IS OK
125 void SessionTabManager::closeTab(int tabIndex) {
126 qDebug() << "SessionTabManager: Close tab";
127 // If closing tab has class SessionView, closeRequest method will be called
128 if (QString(m_widgets->widget(tabIndex)->metaObject()->className()).compare("SessionView") != 0
129 || dynamic_cast<SessionView *> (m_widgets->widget(tabIndex))->closeRequest()) {
130 m_widgets->removeWidget(m_widgets->widget(tabIndex));
131 m_tab->removeTab(tabIndex);
136 SessionView* SessionTabManager::newSessionTab(MaknetoLib::Session *session)
138 // There shouldn't be the same tab twice, so we won't create it
139 SessionView *sessionView = findSession(session->getUniqueName());
140 if (sessionView)
141 return sessionView;
143 // add new tab
144 m_tab->addTab(session->getUniqueName());
145 // create new session view and add to widgets
146 sessionView = new SessionView(this, session, m_tab->count()-1);
147 m_widgets->addWidget(sessionView);
149 //most likely will be elsewhere
150 //connect(sessionView, SIGNAL(sendMessage(const Message &)), m_makneto->getConnection(), SLOT(sendMessage(const Message &)));
152 return sessionView;
156 //vtheman
157 //The following two methods request new Session from TelepathyClient, specifing the type using session flags
159 void SessionTabManager::onTextChatRequested(const QModelIndex &contactIndex) {
161 //TODO find session, if it exist do not create it and make the tab active
162 SessionView *sessionView = findSession(MaknetoBackend::TelepathyClient::Instance()->sessionIdforIndex(contactIndex));
163 if (sessionView) {
164 bringToFront(sessionView);
165 return;
167 qDebug() << "SessionTabManager: New text chat requested";
168 emit newSessionRequested(contactIndex, MaknetoBackend::Session::SessionTypeText);
171 //TODO figure out if this should be done from contactlist context menu
173 void SessionTabManager::onCallRequested(const QModelIndex &contactIndex) {
174 SessionView *sessionView = findSession(MaknetoBackend::TelepathyClient::Instance()->sessionIdforIndex(contactIndex));
175 if (sessionView) {
176 bringToFront(sessionView);
177 return;
179 qDebug() << "SessionTabManager: New audio call requested";
180 emit newSessionRequested(contactIndex, MaknetoBackend::Session::SessionTypeAudio);
183 void SessionTabManager::onNewSession(MaknetoBackend::Session* session, bool upgradeExisting, bool requested) {
184 SessionView *sessionView = findSession(session->getUniqueName());
185 if (sessionView) {
186 bringToFront(sessionView);
187 return;
189 // add new tab
190 m_tab->addTab(session->getName());
191 // create new session view and add to widgets
192 sessionView = new SessionView(this, session);
193 m_widgets->addWidget(sessionView);
194 bringToFront(sessionView);
196 qDebug() << "SessionTabManager: New session of name: " << session->getUniqueName() << " has been created.";