summaryrefslogtreecommitdiff
path: root/open-vm-tools/services/plugins/dndcp/dndGuest/guestCopyPasteDest.cc
blob: 0781c211069df318e3c9b0dcee13483347a1b1ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*********************************************************
 * Copyright (C) 2010 VMware, Inc. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation version 2.1 and no later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the Lesser GNU General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA.
 *
 *********************************************************/

/**
 * @guestCopyPasteDest.cc --
 *
 * Implementation of common layer GuestCopyPasteDest object for guest.
 */

#include "guestCopyPaste.hh"

extern "C" {
   #include <glib.h>

   #include "dndClipboard.h"
   #include "debug.h"
}


/**
 * Constructor.
 *
 * @param[in] mgr guest CP manager
 */

GuestCopyPasteDest::GuestCopyPasteDest(GuestCopyPasteMgr *mgr)
 : mMgr(mgr)
{
   ASSERT(mMgr);
}


/**
 * Got valid clipboard data from UI. Send sendClip cmd to controller.
 *
 * @param[in] clip cross-platform clipboard data.
 */

void
GuestCopyPasteDest::UISendClip(const CPClipboard *clip)
{
   ASSERT(clip);

   g_debug("%s: state is %d\n", __FUNCTION__, mMgr->GetState());
   if (mMgr->GetState() != GUEST_CP_READY) {
      /* Reset DnD for any wrong state. */
      g_debug("%s: Bad state: %d\n", __FUNCTION__, mMgr->GetState());
      goto error;
   }

   if (!mMgr->GetRpc()->DestSendClip(mMgr->GetSessionId(), mIsActive, clip)) {
      g_debug("%s: DestSendClip failed\n", __FUNCTION__);
      goto error;
   }

   return;

error:
   mMgr->ResetCopyPaste();
}


/**
 * Host is asking for clipboard data. Emit destRequestClipChanged signal.
 *
 * @param[in] isActive active or passive CopyPaste.
 */

void
GuestCopyPasteDest::OnRpcRequestClip(bool isActive)
{
   mIsActive = isActive;
   g_debug("%s: state is %d\n", __FUNCTION__, mMgr->GetState());
   mMgr->destRequestClipChanged.emit();
}