|
1 // paste.cpp |
|
2 // |
|
3 // Copyright (c) 2009 - 2010 Accenture. All rights reserved. |
|
4 // This component and the accompanying materials are made available |
|
5 // under the terms of the "Eclipse Public License v1.0" |
|
6 // which accompanies this distribution, and is available |
|
7 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 // |
|
9 // Initial Contributors: |
|
10 // Accenture - Initial contribution |
|
11 // |
|
12 |
|
13 #include <fshell/ioutils.h> |
|
14 #include <fshell/ltkutils.h> |
|
15 #include <e32keys.h> |
|
16 #include <txtetext.h> |
|
17 #include <baclipb.h> |
|
18 |
|
19 using namespace IoUtils; |
|
20 |
|
21 class CCmdPaste : public CCommandBase |
|
22 { |
|
23 public: |
|
24 static CCommandBase* NewLC(); |
|
25 ~CCmdPaste(); |
|
26 private: |
|
27 CCmdPaste(); |
|
28 private: // From CCommandBase. |
|
29 virtual const TDesC& Name() const; |
|
30 virtual void DoRunL(); |
|
31 virtual void ArgumentsL(RCommandArgumentList& aArguments); |
|
32 virtual void OptionsL(RCommandOptionList& aOptions); |
|
33 private: |
|
34 HBufC* iString; |
|
35 TBool iStdin; |
|
36 }; |
|
37 |
|
38 |
|
39 CCommandBase* CCmdPaste::NewLC() |
|
40 { |
|
41 CCmdPaste* self = new(ELeave) CCmdPaste(); |
|
42 CleanupStack::PushL(self); |
|
43 self->BaseConstructL(); |
|
44 return self; |
|
45 } |
|
46 |
|
47 CCmdPaste::~CCmdPaste() |
|
48 { |
|
49 delete iString; |
|
50 } |
|
51 |
|
52 CCmdPaste::CCmdPaste() |
|
53 { |
|
54 } |
|
55 |
|
56 const TDesC& CCmdPaste::Name() const |
|
57 { |
|
58 _LIT(KName, "paste"); |
|
59 return KName; |
|
60 } |
|
61 |
|
62 void CCmdPaste::DoRunL() |
|
63 { |
|
64 if (iString && iStdin) |
|
65 { |
|
66 LeaveIfErr(KErrArgument, _L("Cannot read text from both command line and stdin.")); |
|
67 } |
|
68 |
|
69 if (iString) |
|
70 { |
|
71 LtkUtils::CopyToClipboardL(*iString, &FsL()); |
|
72 } |
|
73 else if (iStdin) |
|
74 { |
|
75 // Copy to clipboard from stdin |
|
76 CTextBuffer* buffer = CTextBuffer::NewLC(0x100); |
|
77 Stdin().SetReadMode(RIoReadHandle::EOneOrMore); |
|
78 TBuf<0x100> buf; |
|
79 while (Stdin().Read(buf) == KErrNone) |
|
80 { |
|
81 buffer->AppendL(buf); |
|
82 } |
|
83 |
|
84 LtkUtils::CopyToClipboardL(buffer->Descriptor(), &FsL()); |
|
85 CleanupStack::PopAndDestroy(buffer); |
|
86 } |
|
87 |
|
88 TInt err = LtkUtils::InjectRawKeyEvent('V', EModifierCtrl, 0); // Send a CTRL-V to the frontmost app. |
|
89 LeaveIfErr(err, _L("Failed to inject ctrl-v event")); |
|
90 } |
|
91 |
|
92 void CCmdPaste::ArgumentsL(RCommandArgumentList& aArguments) |
|
93 { |
|
94 aArguments.AppendStringL(iString, _L("text")); |
|
95 } |
|
96 |
|
97 void CCmdPaste::OptionsL(RCommandOptionList& aOptions) |
|
98 { |
|
99 aOptions.AppendBoolL(iStdin, _L("stdin")); |
|
100 } |
|
101 |
|
102 |
|
103 EXE_BOILER_PLATE(CCmdPaste) |
|
104 |