| 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 <coipmanager/filesessionmanager/SendFileSession.h> |
|---|
| 21 | |
|---|
| 22 | #include <coipmanager/CoIpManager.h> |
|---|
| 23 | #include <coipmanager/datamanager/UserProfileManager.h> |
|---|
| 24 | #include <coipmanager/filesessionmanager/FileSessionManager.h> |
|---|
| 25 | #include <coipmanager/filesessionmanager/ISendFileSessionPlugin.h> |
|---|
| 26 | |
|---|
| 27 | #include <util/Logger.h> |
|---|
| 28 | #include <util/SafeConnect.h> |
|---|
| 29 | #include <util/SafeDelete.h> |
|---|
| 30 | |
|---|
| 31 | SendFileSession::SendFileSession(CoIpManager & coIpManager) |
|---|
| 32 | : Session(coIpManager) { |
|---|
| 33 | _currentFileSessionPlugin = NULL; |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | SendFileSession::~SendFileSession() { |
|---|
| 37 | QMutexLocker lock(_mutex); |
|---|
| 38 | |
|---|
| 39 | OWSAFE_DELETE(_currentFileSessionPlugin); |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | void SendFileSession::start() { |
|---|
| 43 | QMutexLocker lock(_mutex); |
|---|
| 44 | |
|---|
| 45 | // Check if a FileSession is not currently running. |
|---|
| 46 | if (_currentFileSessionPlugin) { |
|---|
| 47 | LOG_ERROR("session already started"); |
|---|
| 48 | return; |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | // Check if we have files to send and contacts to send to |
|---|
| 52 | if (_file.getFilename().empty() || _contactList.empty()) { |
|---|
| 53 | moduleFinishedSignal(); |
|---|
| 54 | return; |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | //outgoing call |
|---|
| 58 | AccountList accountList = _coIpManager.getUserProfileManager().getCopyOfUserProfile().getAccountList(); |
|---|
| 59 | Account * account = AccountListHelper::getCopyOfAccount(accountList, _accountToUse); |
|---|
| 60 | if (account) { |
|---|
| 61 | IFileSessionManagerPlugin *iFileSessionManager = |
|---|
| 62 | _coIpManager.getFileSessionManager().getICoIpManagerPlugin(*account, _contactList); |
|---|
| 63 | if (iFileSessionManager) { |
|---|
| 64 | _currentFileSessionPlugin = iFileSessionManager->createISendFileSessionPlugin(); |
|---|
| 65 | |
|---|
| 66 | SAFE_CONNECT(_currentFileSessionPlugin, SIGNAL(moduleFinishedSignal()), |
|---|
| 67 | SIGNAL(moduleFinishedSignal())); |
|---|
| 68 | SAFE_CONNECT(_currentFileSessionPlugin, SIGNAL(fileTransferSignal(IFileSession::IFileSessionEvent)), |
|---|
| 69 | SLOT(fileTransferSlot(IFileSession::IFileSessionEvent))); |
|---|
| 70 | SAFE_CONNECT(_currentFileSessionPlugin, SIGNAL(fileTransferProgressionSignal(int)), |
|---|
| 71 | SLOT(fileTransferProgressionSlot(int))); |
|---|
| 72 | |
|---|
| 73 | IMContactList imContactList = iFileSessionManager->getValidIMContacts(*account, _contactList); |
|---|
| 74 | _currentFileSessionPlugin->setIMContactList(imContactList); |
|---|
| 75 | _currentFileSessionPlugin->setAccount(*account); |
|---|
| 76 | _currentFileSessionPlugin->setFile(_file); |
|---|
| 77 | |
|---|
| 78 | _currentFileSessionPlugin->start(); |
|---|
| 79 | } |
|---|
| 80 | OWSAFE_DELETE(account); |
|---|
| 81 | } else { |
|---|
| 82 | LOG_ERROR("account \"" + _accountToUse + "\" not found"); |
|---|
| 83 | } |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | void SendFileSession::pause() { |
|---|
| 87 | QMutexLocker lock(_mutex); |
|---|
| 88 | |
|---|
| 89 | if (_currentFileSessionPlugin) { |
|---|
| 90 | _currentFileSessionPlugin->pause(); |
|---|
| 91 | } else { |
|---|
| 92 | LOG_ERROR("session not started"); |
|---|
| 93 | } |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | void SendFileSession::resume() { |
|---|
| 97 | QMutexLocker lock(_mutex); |
|---|
| 98 | |
|---|
| 99 | if (_currentFileSessionPlugin) { |
|---|
| 100 | _currentFileSessionPlugin->resume(); |
|---|
| 101 | } else { |
|---|
| 102 | LOG_ERROR("session not started"); |
|---|
| 103 | } |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | void SendFileSession::stop() { |
|---|
| 107 | QMutexLocker lock(_mutex); |
|---|
| 108 | |
|---|
| 109 | if (_currentFileSessionPlugin) { |
|---|
| 110 | _currentFileSessionPlugin->stop(); |
|---|
| 111 | } else { |
|---|
| 112 | LOG_ERROR("session not started"); |
|---|
| 113 | } |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | bool SendFileSession::canCreateISession(const Account & account, const ContactList & contactList) const { |
|---|
| 117 | return (_coIpManager.getFileSessionManager().getICoIpManagerPlugin(account, contactList) != NULL); |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | void SendFileSession::fileTransferSlot(IFileSession::IFileSessionEvent event) { |
|---|
| 121 | _lastEvent = event; |
|---|
| 122 | |
|---|
| 123 | fileTransferSignal(event); |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | void SendFileSession::fileTransferProgressionSlot(int percentage) { |
|---|
| 127 | fileTransferProgressionSignal(percentage); |
|---|
| 128 | } |
|---|