source: qutecom-coip/wengochat/WengoChat.cpp @ 125:d648f4cb122f

Last change on this file since 125:d648f4cb122f was 125:d648f4cb122f, checked in by laurent, 3 years ago

wengo => qutecom

File size: 6.6 KB
Line 
1/*
2 * QuteCom, a voice over Internet phone
3 * Copyright (C) 2010 Mbdsys
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 */
19
20#include "QuteComChat.h"
21
22#include "ChatWidget.h"
23#include "IMContactDialog.h"
24#include "LoggerWidget.h"
25#include "ManageAccount.h"
26#include "Config.h"
27#include "Widget.h"
28
29#include "ui_MainWindow.h"
30
31#include <coipmanager_threaded/TCoIpManager.h>
32#include <coipmanager_threaded/chatsessionmanager/TChatSession.h>
33#include <coipmanager_threaded/chatsessionmanager/TChatSessionManager.h>
34#include <coipmanager_threaded/connectmanager/TConnectManager.h>
35#include <coipmanager_threaded/datamanager/TUserProfileManager.h>
36#include <coipmanager_base/storage/UserProfileFileStorage.h>
37
38#include <settings/SettingsFileStorage.h>
39
40#include <util/SafeConnect.h>
41
42#include <util/Logger.h>
43#include <util/Path.h>
44#include <util/SafeDelete.h>
45#include <cutil/global.h>
46
47#include <QtGui/QtGui>
48
49QuteComChat::QuteComChat() {
50        _ui = new Ui::MainWindow();
51        _ui->setupUi(this);
52
53        _manageAccount = NULL;
54
55        initializeLogTab();
56        initializeCoIpManager();
57
58        SAFE_CONNECT(_ui->actionStart_a_chat, SIGNAL(triggered()), SLOT(startChat()));
59        SAFE_CONNECT(_ui->actionManage_account, SIGNAL(triggered()), SLOT(manageAccount()));
60}
61
62QuteComChat::~QuteComChat() {
63        Config::getInstance().set(Config::PROFILE_LAST_USED_ID_KEY,
64                _tCoIpManager->getTUserProfileManager().getCopyOfUserProfile().getUUID());
65
66        SettingsFileStorage::save(_configFilename, Config::getInstance());
67
68        OWSAFE_DELETE(_manageAccount);
69        OWSAFE_DELETE(_tCoIpManager);
70        OWSAFE_DELETE(_ui);
71}
72
73void QuteComChat::showStatusBarMessage(const std::string & message) {
74        statusBar()->showMessage(QString::fromStdString(message));
75}
76
77void QuteComChat::initializeCoIpManager() {
78        // Initializing CoIpManager
79        Config & config = Config::getInstance();
80        std::string endOfPath = "QuteCom-coip/";
81#if defined(OS_LINUX)
82        endOfPath = ".qutecom-coip/";
83#endif
84        config.set(Config::CONFIG_PATH_KEY, Path::getConfigurationDirPath() + endOfPath);
85
86        _configFilename = config.getConfigPath() + "config.xml";
87        SettingsFileStorage::load(_configFilename, config);
88
89        _tCoIpManager = new TCoIpManager(config);
90
91        SAFE_CONNECT(_tCoIpManager, SIGNAL(initialized()), SLOT(tCoIpManagerInitialized()));
92
93        _tCoIpManager->start();
94        ////
95}
96
97void QuteComChat::tCoIpManagerInitialized() {
98        // Registering to events
99        SAFE_CONNECT(&_tCoIpManager->getTUserProfileManager(),
100                SIGNAL(userProfileSetSignal(UserProfile)),
101                SLOT(userProfileSetSlot(UserProfile)));
102
103        SAFE_CONNECT(&_tCoIpManager->getTConnectManager(),
104                SIGNAL(accountConnectionStateSignal(std::string, EnumConnectionState::ConnectionState)),
105                SLOT(accountConnectionStateSlot(std::string, EnumConnectionState::ConnectionState)));
106
107        SAFE_CONNECT(&_tCoIpManager->getTConnectManager(),
108                SIGNAL(accountConnectionErrorSignal(std::string, EnumConnectionError::ConnectionError)),
109                SLOT(accountConnectionErrorSlot(std::string, EnumConnectionError::ConnectionError)));
110
111        SAFE_CONNECT(&_tCoIpManager->getTConnectManager(),
112                SIGNAL(accountConnectionProgressSignal(std::string, unsigned, unsigned, std::string)),
113                SLOT(accountConnectionProgressSlot(std::string, unsigned, unsigned, std::string)));
114
115        SAFE_CONNECT(&_tCoIpManager->getTChatSessionManager(),
116                SIGNAL(newChatSessionCreatedSignal(TChatSession *)),
117                SLOT(newChatSessionCreatedSlot(TChatSession *)));
118        ////
119
120
121        // Loading last used profile
122        Config & config = Config::getInstance();
123        UserProfile userProfile;
124        std::string lastProfile = config.getProfileLastUsedId();
125        if (!lastProfile.empty()) {
126                UserProfileFileStorage fileStorage(config.getConfigPath());
127                if (!fileStorage.load(lastProfile, userProfile) == UserProfileFileStorage::UserProfileStorageErrorNoError) {
128                        LOG_ERROR("cannot load profile");
129                }
130        }
131
132        _tCoIpManager->getTUserProfileManager().setUserProfile(userProfile);
133        ////
134}
135
136void QuteComChat::userProfileSetSlot(UserProfile userProfile) {
137        _tCoIpManager->getTConnectManager().connectAllAccounts();
138}
139
140void QuteComChat::initializeLogTab() {
141        QWidget * logTab = _ui->tabWidget->widget(0);
142        Widget::createLayout(logTab);
143        logTab->layout()->setMargin(10);
144        logTab->layout()->addWidget(new LoggerWidget(_ui->tabWidget, this));
145}
146
147void QuteComChat::manageAccount() {
148        if (!_manageAccount) {
149                _manageAccount = new ManageAccount(*_tCoIpManager, this);
150        }
151
152        _manageAccount->show();
153}
154
155void QuteComChat::startChat() {
156        IMContactDialog dialog(this);
157        if (dialog.exec()) {
158                IMContact imContact(dialog.accountType(), dialog.contactId().toStdString());
159                Contact contact;
160                contact.addIMContact(imContact);
161                TChatSession * session = _tCoIpManager->getTChatSessionManager().createTChatSession();
162                EnumSessionError::SessionError error = session->addContact(contact);
163                if (error != EnumSessionError::SessionErrorNoError) {
164                        QMessageBox::warning(this, "Session creation error",
165                                "This contact could not be added to the Session",
166                                QMessageBox::Ok, QMessageBox::NoButton);
167                        OWSAFE_DELETE(session);
168                        return;
169                }
170                addSession(session);
171        }
172}
173
174void QuteComChat::newChatSessionCreatedSlot(TChatSession * tChatSession) {
175        addSession(tChatSession);
176}
177
178void QuteComChat::accountConnectionStateSlot(std::string accountId, EnumConnectionState::ConnectionState state) {
179        showStatusBarMessage("** Account status changed: " + EnumConnectionState::toString(state));
180}
181
182void QuteComChat::accountConnectionErrorSlot(std::string accountId,
183        EnumConnectionError::ConnectionError errorCode) {
184
185        showStatusBarMessage(EnumConnectionError::toString(errorCode));
186}
187
188void QuteComChat::accountConnectionProgressSlot(std::string accountId,
189        unsigned currentStep, unsigned totalSteps, std::string infoMessage) {
190
191        showStatusBarMessage(infoMessage);
192}
193
194void QuteComChat::addSession(TChatSession * session) {
195        ChatWidget * chatTab = new ChatWidget(this, session);
196        int i = _ui->tabWidget->addTab(chatTab, "name" /*session->getName()*/);
197        _ui->tabWidget->setCurrentIndex(i);
198}
Note: See TracBrowser for help on using the repository browser.