| 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 "PurpleReceiveFileSession.h" |
|---|
| 21 | |
|---|
| 22 | #include <coipmanager/CoIpManager.h> |
|---|
| 23 | #include <coipmanager/datamanager/UserProfileManager.h> |
|---|
| 24 | |
|---|
| 25 | #include <util/File.h> |
|---|
| 26 | #include <util/Logger.h> |
|---|
| 27 | #include <util/SafeConnect.h> |
|---|
| 28 | |
|---|
| 29 | PurpleReceiveFileSession::PurpleReceiveFileSession(CoIpManager & coIpManager) |
|---|
| 30 | : IReceiveFileSessionPlugin(coIpManager) { |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | PurpleReceiveFileSession::PurpleReceiveFileSession(const PurpleReceiveFileSession & PurpleReceiveFileSession) |
|---|
| 34 | : IReceiveFileSessionPlugin(PurpleReceiveFileSession) { |
|---|
| 35 | |
|---|
| 36 | _fileName = PurpleReceiveFileSession._fileName; |
|---|
| 37 | _fileSize = PurpleReceiveFileSession._fileSize; |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | Identifiable * PurpleReceiveFileSession::clone() const { |
|---|
| 41 | return new PurpleReceiveFileSession(*this); |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | PurpleReceiveFileSession::~PurpleReceiveFileSession() { |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | void PurpleReceiveFileSession::start() { |
|---|
| 48 | LOG_DEBUG("starting file transfer"); |
|---|
| 49 | //Only start the file transfer if it's still not marked as cancelled and therefore can be begun. |
|---|
| 50 | if ((purple_xfer_get_status(_xfer) != PURPLE_XFER_STATUS_CANCEL_LOCAL) && |
|---|
| 51 | (purple_xfer_get_status(_xfer) != PURPLE_XFER_STATUS_CANCEL_REMOTE)) { |
|---|
| 52 | //XXX should do further error checking as done by purple_xfer_choose_file_ok_cb() in purple's ft.c |
|---|
| 53 | std::string path = _filePath + _fileName; |
|---|
| 54 | purple_xfer_request_accepted(_xfer, path.c_str()); |
|---|
| 55 | } |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | void PurpleReceiveFileSession::pause() { |
|---|
| 59 | LOG_DEBUG("pausing file transfer"); |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | void PurpleReceiveFileSession::resume() { |
|---|
| 63 | LOG_DEBUG("resuming file transfer"); |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | void PurpleReceiveFileSession::stop() { |
|---|
| 67 | |
|---|
| 68 | LOG_DEBUG("stopping file transfer"); |
|---|
| 69 | |
|---|
| 70 | purple_xfer_request_denied(_xfer); |
|---|
| 71 | |
|---|
| 72 | if ((purple_xfer_get_status(_xfer) == PURPLE_XFER_STATUS_UNKNOWN) || |
|---|
| 73 | (purple_xfer_get_status(_xfer) == PURPLE_XFER_STATUS_NOT_STARTED) || |
|---|
| 74 | (purple_xfer_get_status(_xfer) == PURPLE_XFER_STATUS_STARTED) || |
|---|
| 75 | (purple_xfer_get_status(_xfer) == PURPLE_XFER_STATUS_ACCEPTED)) { |
|---|
| 76 | purple_xfer_cancel_local(_xfer); |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | } |
|---|