2012-03-21 19:06:35 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* Version: MPL 1.1 / GPLv3+ / LGPLv3+
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License or as specified alternatively below. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* Major Contributor(s):
|
|
|
|
* Copyright (C) 2012 Michael Meeks <michael.meeks@suse.com> (initial developer)
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* For minor contributions see the git repository.
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 3 or later (the "GPLv3+"), or
|
|
|
|
* the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
|
|
|
|
* in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
|
|
|
|
* instead of those above.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sal/config.h"
|
2012-03-22 12:31:15 +00:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
2012-03-21 19:06:35 +00:00
|
|
|
#include "cell.hxx"
|
|
|
|
#include "docsh.hxx"
|
|
|
|
#include "docfunc.hxx"
|
2012-03-23 10:55:09 +01:00
|
|
|
#include "collab.hxx"
|
2012-03-23 16:57:09 +00:00
|
|
|
#include "contacts.hxx"
|
2012-03-23 17:54:06 +00:00
|
|
|
#include <tubes/manager.hxx>
|
2012-03-23 10:55:09 +01:00
|
|
|
#include <tubes/conference.hxx>
|
2012-03-21 19:06:35 +00:00
|
|
|
|
2012-03-22 19:44:44 +00:00
|
|
|
// new file send/recv fun ...
|
2012-03-23 11:29:48 +00:00
|
|
|
#include <com/sun/star/uno/Sequence.hxx>
|
2012-03-22 19:44:44 +00:00
|
|
|
#include <unotools/tempfile.hxx>
|
|
|
|
#include <unotools/localfilehelper.hxx>
|
|
|
|
#include <comphelper/mediadescriptor.hxx>
|
2012-03-23 16:01:00 +00:00
|
|
|
#include <comphelper/processfactory.hxx>
|
|
|
|
#include <comphelper/componentcontext.hxx>
|
2012-03-23 11:29:48 +00:00
|
|
|
#include <com/sun/star/frame/XLoadable.hpp>
|
2012-03-23 16:01:00 +00:00
|
|
|
#include <com/sun/star/frame/XComponentLoader.hpp>
|
|
|
|
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
|
2012-03-23 11:29:48 +00:00
|
|
|
#include <com/sun/star/beans/PropertyValue.hpp>
|
2012-03-22 19:44:44 +00:00
|
|
|
#include <com/sun/star/document/XDocumentRecovery.hpp>
|
2012-03-23 16:01:00 +00:00
|
|
|
#include <com/sun/star/util/XCloseable.hpp>
|
2012-03-22 19:44:44 +00:00
|
|
|
|
|
|
|
namespace css = ::com::sun::star;
|
|
|
|
|
2012-03-21 19:06:35 +00:00
|
|
|
namespace {
|
|
|
|
|
2012-03-22 17:06:27 +00:00
|
|
|
rtl::OUString cellToString( ScBaseCell *pCell )
|
|
|
|
{
|
2012-03-22 17:39:25 +00:00
|
|
|
(void)pCell; // FIXME: implement me
|
2012-03-22 17:06:27 +00:00
|
|
|
return rtl::OUString();
|
|
|
|
}
|
|
|
|
|
|
|
|
ScBaseCell *stringToCell( const rtl::OUString &rString )
|
|
|
|
{
|
2012-03-22 17:39:25 +00:00
|
|
|
(void)rString; // FIXME: implement me
|
2012-03-22 17:06:27 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-03-28 20:24:23 +02:00
|
|
|
bool isCollabMode( bool& rbMaster )
|
|
|
|
{
|
|
|
|
const char* pEnv = getenv ("LIBO_TUBES");
|
|
|
|
if (pEnv)
|
|
|
|
{
|
|
|
|
rbMaster = !strcmp( pEnv, "master");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
rbMaster = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-03-22 17:06:27 +00:00
|
|
|
|
2012-03-22 12:31:15 +00:00
|
|
|
// Ye noddy mangling - needs improvement ...
|
|
|
|
// method name ';' then arguments ; separated
|
|
|
|
class ScChangeOpWriter
|
2012-03-21 19:06:35 +00:00
|
|
|
{
|
|
|
|
rtl::OUStringBuffer aMessage;
|
2012-03-22 12:31:15 +00:00
|
|
|
void appendSeparator()
|
|
|
|
{
|
|
|
|
aMessage.append( sal_Unicode( ';' ) );
|
|
|
|
}
|
2012-03-21 19:06:35 +00:00
|
|
|
public:
|
2012-03-22 12:31:15 +00:00
|
|
|
|
|
|
|
ScChangeOpWriter( const char *pName )
|
|
|
|
{
|
|
|
|
aMessage.appendAscii( pName );
|
|
|
|
appendSeparator();
|
|
|
|
}
|
|
|
|
|
2012-03-22 17:39:25 +00:00
|
|
|
void appendString( const rtl::OUString &rStr )
|
2012-03-21 19:06:35 +00:00
|
|
|
{
|
2012-03-22 17:39:25 +00:00
|
|
|
if ( rStr.indexOf( sal_Unicode( '"' ) ) >= 0 ||
|
|
|
|
rStr.indexOf( sal_Unicode( ';' ) ) >= 0 )
|
|
|
|
{
|
|
|
|
String aQuoted( rStr );
|
2012-03-22 17:06:27 +00:00
|
|
|
ScGlobal::AddQuotes( aQuoted, sal_Unicode( '"' ) );
|
2012-03-22 17:39:25 +00:00
|
|
|
aMessage.append( aQuoted );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
aMessage.append( rStr );
|
2012-03-22 12:31:15 +00:00
|
|
|
appendSeparator();
|
2012-03-21 19:06:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void appendAddress( const ScAddress &rPos )
|
|
|
|
{
|
2012-03-22 12:31:15 +00:00
|
|
|
rtl::OUString aStr;
|
|
|
|
rPos.Format( aStr, SCA_VALID );
|
|
|
|
aMessage.append( aStr );
|
|
|
|
appendSeparator();
|
|
|
|
}
|
|
|
|
|
|
|
|
void appendInt( sal_Int32 i )
|
|
|
|
{
|
|
|
|
aMessage.append( i );
|
|
|
|
appendSeparator();
|
|
|
|
}
|
|
|
|
|
|
|
|
void appendBool( sal_Bool b )
|
|
|
|
{
|
|
|
|
aMessage.appendAscii( b ? "true" : "false" );
|
|
|
|
appendSeparator();
|
|
|
|
}
|
|
|
|
|
2012-03-22 17:06:27 +00:00
|
|
|
void appendCell( ScBaseCell *pCell )
|
|
|
|
{
|
|
|
|
appendString( cellToString( pCell ) );
|
|
|
|
}
|
|
|
|
|
2012-03-22 12:31:15 +00:00
|
|
|
rtl::OString toString()
|
|
|
|
{
|
|
|
|
return rtl::OUStringToOString( aMessage.toString(), RTL_TEXTENCODING_UTF8 );
|
2012-03-21 19:06:35 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-03-22 12:31:15 +00:00
|
|
|
struct ProtocolError {
|
|
|
|
const char *message;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ScChangeOpReader {
|
2012-03-22 17:06:27 +00:00
|
|
|
std::vector< rtl::OUString > maArgs;
|
2012-03-22 12:31:15 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2012-03-22 17:06:27 +00:00
|
|
|
ScChangeOpReader( const rtl::OUString &rString)
|
2012-03-22 12:31:15 +00:00
|
|
|
{
|
|
|
|
// will need to handle escaping etc.
|
2012-03-22 17:06:27 +00:00
|
|
|
// Surely someone else wrote this before ! [!?]
|
|
|
|
enum {
|
2012-03-22 17:39:25 +00:00
|
|
|
IN_TEXT, CHECK_QUOTE, FIND_LAST_QUOTE, SKIP_SEMI
|
|
|
|
} eState = CHECK_QUOTE;
|
2012-03-22 17:06:27 +00:00
|
|
|
|
2012-03-22 17:39:25 +00:00
|
|
|
sal_Int32 nStart = 0;
|
|
|
|
for (sal_Int32 n = 0; n < rString.getLength(); n++)
|
2012-03-22 17:06:27 +00:00
|
|
|
{
|
2012-03-22 17:39:25 +00:00
|
|
|
if (rString[n] == '\\')
|
|
|
|
{
|
|
|
|
n++; // skip next char
|
|
|
|
continue;
|
|
|
|
}
|
2012-03-22 17:06:27 +00:00
|
|
|
switch (eState) {
|
|
|
|
case CHECK_QUOTE:
|
|
|
|
if (rString[n] == '"')
|
|
|
|
{
|
2012-03-22 17:39:25 +00:00
|
|
|
nStart = n + 1;
|
|
|
|
eState = FIND_LAST_QUOTE;
|
2012-03-22 17:06:27 +00:00
|
|
|
break;
|
2012-03-22 17:39:25 +00:00
|
|
|
}
|
|
|
|
// else drop through
|
2012-03-22 17:06:27 +00:00
|
|
|
case IN_TEXT:
|
|
|
|
if (rString[n] == ';')
|
|
|
|
{
|
2012-03-22 17:39:25 +00:00
|
|
|
maArgs.push_back( rString.copy( nStart, n - nStart ) );
|
|
|
|
nStart = n + 1;
|
|
|
|
eState = CHECK_QUOTE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FIND_LAST_QUOTE:
|
|
|
|
if (rString[n] == '"')
|
|
|
|
{
|
|
|
|
maArgs.push_back( rString.copy( nStart, n - nStart ) );
|
|
|
|
eState = SKIP_SEMI;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SKIP_SEMI:
|
|
|
|
if (rString[n] == ';')
|
|
|
|
{
|
|
|
|
nStart = n + 1;
|
2012-03-22 17:06:27 +00:00
|
|
|
eState = CHECK_QUOTE;
|
2012-03-22 17:39:25 +00:00
|
|
|
}
|
2012-03-22 17:06:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( nStart < rString.getLength())
|
|
|
|
maArgs.push_back( rString.copy( nStart, rString.getLength() - nStart ) );
|
|
|
|
|
|
|
|
for (size_t i = 0; i < maArgs.size(); i++)
|
|
|
|
fprintf( stderr, "arg %d: '%s'\n", (int)i,
|
|
|
|
rtl::OUStringToOString( maArgs[i], RTL_TEXTENCODING_UTF8).getStr() );
|
2012-03-22 12:31:15 +00:00
|
|
|
}
|
|
|
|
~ScChangeOpReader() {}
|
|
|
|
|
2012-03-22 17:06:27 +00:00
|
|
|
rtl::OUString getMethod()
|
2012-03-22 12:31:15 +00:00
|
|
|
{
|
|
|
|
return maArgs[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t getArgCount() { return maArgs.size(); }
|
|
|
|
|
|
|
|
rtl::OUString getString( sal_Int32 n )
|
|
|
|
{
|
|
|
|
if (n > 0 && (size_t)n < getArgCount() )
|
2012-03-22 17:06:27 +00:00
|
|
|
{
|
|
|
|
String aUStr( maArgs[ n ] );
|
|
|
|
ScGlobal::EraseQuotes( aUStr );
|
|
|
|
return aUStr;
|
|
|
|
} else
|
2012-03-22 12:31:15 +00:00
|
|
|
return rtl::OUString();
|
|
|
|
}
|
|
|
|
|
|
|
|
ScAddress getAddress( sal_Int32 n )
|
|
|
|
{
|
|
|
|
ScAddress aAddr;
|
|
|
|
rtl::OUString aToken( getString( n ) );
|
|
|
|
aAddr.Parse( aToken );
|
|
|
|
return aAddr;
|
|
|
|
}
|
|
|
|
|
2012-03-22 17:06:27 +00:00
|
|
|
sal_Int32 getInt( sal_Int32 n )
|
|
|
|
{
|
|
|
|
return getString( n ).toInt32();
|
|
|
|
}
|
|
|
|
|
2012-03-22 12:31:15 +00:00
|
|
|
bool getBool( sal_Int32 n )
|
|
|
|
{
|
2012-03-22 17:06:27 +00:00
|
|
|
return getString( n ).equalsIgnoreAsciiCase( "true" );
|
|
|
|
}
|
|
|
|
|
|
|
|
ScBaseCell *getCell( sal_Int32 n )
|
|
|
|
{
|
|
|
|
return stringToCell( getString( n ) );
|
2012-03-22 12:31:15 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ScDocFuncRecv : public ScDocFunc
|
2012-03-21 19:06:35 +00:00
|
|
|
{
|
2012-03-22 12:31:15 +00:00
|
|
|
ScDocFunc *mpChain;
|
2012-03-23 10:55:09 +01:00
|
|
|
ScCollaboration* mpCollab;
|
2012-03-21 19:06:35 +00:00
|
|
|
public:
|
2012-03-22 12:31:15 +00:00
|
|
|
// FIXME: really ScDocFunc should be an abstract base
|
|
|
|
ScDocFuncRecv( ScDocShell& rDocSh, ScDocFunc *pChain )
|
|
|
|
: ScDocFunc( rDocSh ),
|
2012-03-23 10:55:09 +01:00
|
|
|
mpChain( pChain ),
|
|
|
|
mpCollab( NULL)
|
2012-03-21 19:06:35 +00:00
|
|
|
{
|
2012-03-22 12:31:15 +00:00
|
|
|
fprintf( stderr, "Receiver created !\n" );
|
2012-03-21 19:06:35 +00:00
|
|
|
}
|
2012-03-22 12:31:15 +00:00
|
|
|
virtual ~ScDocFuncRecv() {}
|
|
|
|
|
2012-03-23 10:55:09 +01:00
|
|
|
void SetCollaboration( ScCollaboration* pCollab )
|
|
|
|
{
|
|
|
|
mpCollab = pCollab;
|
|
|
|
}
|
|
|
|
|
2012-03-23 17:14:36 +00:00
|
|
|
void packetReceived( TeleConference* pConference, const rtl::OString & );
|
2012-03-23 17:40:21 +00:00
|
|
|
void fileReceived( rtl::OUString *rStr );
|
2012-03-23 11:29:48 +00:00
|
|
|
DECL_LINK( ReceiveFileCallback, rtl::OUString * );
|
2012-03-23 10:55:09 +01:00
|
|
|
|
2012-03-22 12:31:15 +00:00
|
|
|
void RecvMessage( const rtl::OString &rString )
|
|
|
|
{
|
|
|
|
try {
|
2012-03-22 17:06:27 +00:00
|
|
|
ScChangeOpReader aReader( rtl::OUString( rString.getStr(),
|
|
|
|
rString.getLength(),
|
|
|
|
RTL_TEXTENCODING_UTF8 ) );
|
2012-03-22 12:31:15 +00:00
|
|
|
// FIXME: have some hash to enumeration mapping here
|
|
|
|
if ( aReader.getMethod() == "setNormalString" )
|
|
|
|
mpChain->SetNormalString( aReader.getAddress( 1 ), aReader.getString( 2 ),
|
|
|
|
aReader.getBool( 3 ) );
|
2012-03-22 17:06:27 +00:00
|
|
|
else if ( aReader.getMethod() == "putCell" )
|
|
|
|
{
|
|
|
|
ScBaseCell *pNewCell = aReader.getCell( 2 );
|
|
|
|
if ( pNewCell )
|
|
|
|
mpChain->PutCell( aReader.getAddress( 1 ), pNewCell, aReader.getBool( 3 ) );
|
|
|
|
}
|
|
|
|
else if ( aReader.getMethod() == "enterListAction" )
|
|
|
|
mpChain->EnterListAction( aReader.getInt( 1 ) );
|
|
|
|
else if ( aReader.getMethod() == "endListAction" )
|
|
|
|
mpChain->EndListAction();
|
|
|
|
else if ( aReader.getMethod() == "showNote" )
|
|
|
|
mpChain->ShowNote( aReader.getAddress( 1 ), aReader.getBool( 2 ) );
|
|
|
|
else if ( aReader.getMethod() == "setNoteText" )
|
|
|
|
mpChain->SetNoteText( aReader.getAddress( 1 ), aReader.getString( 2 ),
|
|
|
|
aReader.getBool( 3 ) );
|
|
|
|
else if ( aReader.getMethod() == "renameTable" )
|
|
|
|
mpChain->RenameTable( aReader.getInt( 1 ), aReader.getString( 2 ),
|
|
|
|
aReader.getBool( 3 ), aReader.getBool( 4 ) );
|
2012-03-22 12:31:15 +00:00
|
|
|
else
|
|
|
|
fprintf( stderr, "Error: unknown message '%s' (%d)\n",
|
|
|
|
rString.getStr(), (int)aReader.getArgCount() );
|
|
|
|
} catch (const ProtocolError &e) {
|
|
|
|
fprintf( stderr, "Error: protocol twisting '%s'\n", e.message );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-03-23 17:40:21 +00:00
|
|
|
void ScDocFuncRecv::packetReceived( TeleConference*, const rtl::OString &rStr)
|
2012-03-23 10:55:09 +01:00
|
|
|
{
|
2012-03-23 17:14:36 +00:00
|
|
|
RecvMessage( rStr);
|
2012-03-23 10:55:09 +01:00
|
|
|
}
|
|
|
|
|
2012-03-23 17:40:21 +00:00
|
|
|
void ScDocFuncRecv::fileReceived( rtl::OUString *pStr )
|
2012-03-23 11:29:48 +00:00
|
|
|
{
|
|
|
|
fprintf( stderr, "incoming file '%s'\n",
|
|
|
|
rtl::OUStringToOString( *pStr, RTL_TEXTENCODING_UTF8 ).getStr() );
|
|
|
|
|
2012-03-23 16:01:00 +00:00
|
|
|
// using the frame::XLoadable interface fails with a DoubleInitializationException
|
|
|
|
/* css::uno::Sequence < css::beans::PropertyValue > aLoadArgs(5);
|
2012-03-23 11:29:48 +00:00
|
|
|
aLoadArgs[0].Name = rtl::OUString( "URL" );
|
|
|
|
aLoadArgs[0].Value <<= (*pStr);
|
|
|
|
aLoadArgs[1].Name = rtl::OUString( "FilterName" );
|
|
|
|
aLoadArgs[1].Value <<= rtl::OUString( "calc8" );
|
|
|
|
aLoadArgs[2].Name = rtl::OUString( "Referer" );
|
|
|
|
aLoadArgs[2].Value <<= rtl::OUString( "" );
|
|
|
|
// no interaction handler ?
|
|
|
|
aLoadArgs[3].Name = rtl::OUString( "MacroExecutionMode" );
|
|
|
|
aLoadArgs[3].Value <<= sal_Int32( 3 );
|
|
|
|
aLoadArgs[4].Name = rtl::OUString( "UpdateDocMode" );
|
|
|
|
aLoadArgs[4].Value <<= sal_Int32( 2 );
|
|
|
|
try
|
|
|
|
{
|
|
|
|
css::uno::Reference < css::frame::XLoadable > xLoad(
|
|
|
|
rDocShell.GetBaseModel(), css::uno::UNO_QUERY_THROW );
|
|
|
|
xLoad->load( aLoadArgs );
|
|
|
|
}
|
2012-03-23 13:13:30 +00:00
|
|
|
catch ( css::uno::Exception& e )
|
2012-03-23 16:01:00 +00:00
|
|
|
{
|
|
|
|
fprintf( stderr, "exception when loading '%s' !\n",
|
|
|
|
rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
|
|
|
|
} */
|
|
|
|
// #2 - tried out the SfxAutoReloadTimer_Impl - shove stuff at the SID_RELOAD slot ...
|
|
|
|
|
|
|
|
// #3 - can we use the framework/inc/services/frame.hxx 's "sTargetFrameName"
|
|
|
|
// magic to load into our current frame ? ... :-)
|
|
|
|
|
|
|
|
css::uno::Reference< css::lang::XMultiServiceFactory > rFactory =
|
|
|
|
::comphelper::getProcessServiceFactory();
|
|
|
|
|
|
|
|
css::uno::Sequence < css::beans::PropertyValue > args(0);
|
|
|
|
// FIXME: should this be hidden before it is synched & ready ? ...
|
|
|
|
// args[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Hidden"));
|
|
|
|
// args[0].Value <<= sal_True;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
css::uno::Reference < css::frame::XComponentLoader > xLoader(
|
|
|
|
::comphelper::getProcessServiceFactory()->createInstance(
|
|
|
|
"com.sun.star.frame.Desktop" ),
|
|
|
|
css::uno::UNO_QUERY_THROW );
|
|
|
|
css::uno::Reference < css::util::XCloseable > xDoc(
|
|
|
|
xLoader->loadComponentFromURL( *pStr, "_blank", 0, args ),
|
|
|
|
css::uno::UNO_QUERY_THROW );
|
|
|
|
}
|
|
|
|
catch ( css::uno::Exception& e )
|
2012-03-23 11:29:48 +00:00
|
|
|
{
|
2012-03-23 13:13:30 +00:00
|
|
|
fprintf( stderr, "exception when loading '%s' !\n",
|
|
|
|
rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
|
2012-03-23 11:29:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-22 12:31:15 +00:00
|
|
|
class ScDocFuncSend : public ScDocFunc
|
|
|
|
{
|
|
|
|
ScDocFuncRecv *mpChain;
|
2012-03-23 10:55:09 +01:00
|
|
|
ScCollaboration* mpCollab;
|
2012-03-22 12:31:15 +00:00
|
|
|
|
|
|
|
void SendMessage( ScChangeOpWriter &rOp )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Op: '%s'\n", rOp.toString().getStr() );
|
2012-03-23 10:55:09 +01:00
|
|
|
if (mpCollab)
|
|
|
|
mpCollab->sendPacket( rOp.toString());
|
|
|
|
else
|
|
|
|
mpChain->RecvMessage( rOp.toString() );
|
2012-03-22 12:31:15 +00:00
|
|
|
}
|
|
|
|
|
2012-03-22 19:44:44 +00:00
|
|
|
void SendFile( const rtl::OUString &rURL )
|
|
|
|
{
|
|
|
|
(void)rURL;
|
|
|
|
|
|
|
|
String aTmpPath = utl::TempFile::CreateTempName();
|
|
|
|
aTmpPath.Append( rtl::OUString( ".ods" ) );
|
|
|
|
|
|
|
|
rtl::OUString aFileURL;
|
|
|
|
::utl::LocalFileHelper::ConvertPhysicalNameToURL( aTmpPath, aFileURL );
|
|
|
|
|
|
|
|
::comphelper::MediaDescriptor aDescriptor;
|
|
|
|
// some issue with hyperlinks:
|
|
|
|
aDescriptor[::comphelper::MediaDescriptor::PROP_DOCUMENTBASEURL()] <<= ::rtl::OUString();
|
|
|
|
try {
|
|
|
|
css::uno::Reference< css::document::XDocumentRecovery > xDocRecovery(
|
|
|
|
rDocShell.GetBaseModel(), css::uno::UNO_QUERY_THROW);
|
|
|
|
|
|
|
|
xDocRecovery->storeToRecoveryFile( aFileURL, aDescriptor.getAsConstPropertyValueList() );
|
|
|
|
} catch (const css::uno::Exception &ex) {
|
|
|
|
fprintf( stderr, "exception foo !\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( stderr, "Temp file is '%s'\n",
|
|
|
|
rtl::OUStringToOString( aFileURL, RTL_TEXTENCODING_UTF8 ).getStr() );
|
2012-03-23 11:29:48 +00:00
|
|
|
|
2012-03-23 11:32:13 +00:00
|
|
|
if ( mpCollab )
|
|
|
|
mpCollab->sendFile( aFileURL );
|
2012-03-23 11:29:48 +00:00
|
|
|
}
|
2012-03-22 19:44:44 +00:00
|
|
|
|
2012-03-22 12:31:15 +00:00
|
|
|
public:
|
|
|
|
// FIXME: really ScDocFunc should be an abstract base, so
|
|
|
|
// we don't need the rDocSh hack/pointer
|
|
|
|
ScDocFuncSend( ScDocShell& rDocSh, ScDocFuncRecv *pChain )
|
|
|
|
: ScDocFunc( rDocSh ),
|
2012-03-23 10:55:09 +01:00
|
|
|
mpChain( pChain ),
|
|
|
|
mpCollab( NULL)
|
2012-03-22 12:31:15 +00:00
|
|
|
{
|
|
|
|
fprintf( stderr, "Sender created !\n" );
|
|
|
|
}
|
|
|
|
virtual ~ScDocFuncSend() {}
|
|
|
|
|
2012-03-23 10:55:09 +01:00
|
|
|
void SetCollaboration( ScCollaboration* pCollab )
|
|
|
|
{
|
|
|
|
mpCollab = pCollab;
|
|
|
|
}
|
|
|
|
|
2012-03-21 19:06:35 +00:00
|
|
|
virtual void EnterListAction( sal_uInt16 nNameResId )
|
|
|
|
{
|
|
|
|
// Want to group these operations for the other side ...
|
|
|
|
String aUndo( ScGlobal::GetRscString( nNameResId ) );
|
2012-03-22 17:06:27 +00:00
|
|
|
ScChangeOpWriter aOp( "enterListAction" );
|
|
|
|
aOp.appendInt( nNameResId ); // nasty but translate-able ...
|
|
|
|
SendMessage( aOp );
|
2012-03-21 19:06:35 +00:00
|
|
|
}
|
|
|
|
virtual void EndListAction()
|
|
|
|
{
|
2012-03-22 17:06:27 +00:00
|
|
|
ScChangeOpWriter aOp( "endListAction" );
|
|
|
|
SendMessage( aOp );
|
2012-03-21 19:06:35 +00:00
|
|
|
}
|
2012-03-22 12:31:15 +00:00
|
|
|
|
2012-03-21 19:06:35 +00:00
|
|
|
virtual sal_Bool SetNormalString( const ScAddress& rPos, const String& rText, sal_Bool bApi )
|
|
|
|
{
|
2012-03-22 12:31:15 +00:00
|
|
|
ScChangeOpWriter aOp( "setNormalString" );
|
|
|
|
aOp.appendAddress( rPos );
|
|
|
|
aOp.appendString( rText );
|
|
|
|
aOp.appendBool( bApi );
|
|
|
|
SendMessage( aOp );
|
2012-03-22 19:44:44 +00:00
|
|
|
|
|
|
|
if ( rtl::OUString( rText ) == "saveme" )
|
|
|
|
SendFile( rText );
|
|
|
|
|
2012-03-23 16:57:09 +00:00
|
|
|
if ( rtl::OUString( rText ) == "contacts" )
|
2012-03-28 20:24:23 +02:00
|
|
|
{
|
|
|
|
// For TeleManager::get() use the same master/slave mode we have
|
|
|
|
// for collaboration, if any. This is a hack anyway so don't care
|
|
|
|
// whether we really are in collab mode or not.
|
|
|
|
bool bIsMaster = false;
|
|
|
|
isCollabMode( bIsMaster );
|
|
|
|
tubes::createContacts( TeleManager::get( bIsMaster ) );
|
|
|
|
}
|
2012-03-23 16:57:09 +00:00
|
|
|
|
2012-03-22 12:31:15 +00:00
|
|
|
return true; // needs some code auditing action
|
2012-03-21 19:06:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual sal_Bool PutCell( const ScAddress& rPos, ScBaseCell* pNewCell, sal_Bool bApi )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "put cell '%p' type %d %d\n", pNewCell, pNewCell->GetCellType(), bApi );
|
2012-03-22 17:06:27 +00:00
|
|
|
ScChangeOpWriter aOp( "putCell" );
|
|
|
|
aOp.appendAddress( rPos );
|
|
|
|
aOp.appendCell( pNewCell );
|
|
|
|
aOp.appendBool( bApi );
|
|
|
|
SendMessage( aOp );
|
|
|
|
return true; // needs some code auditing action
|
2012-03-21 19:06:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual sal_Bool PutData( const ScAddress& rPos, ScEditEngineDefaulter& rEngine,
|
|
|
|
sal_Bool bInterpret, sal_Bool bApi )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "put data\n" );
|
2012-03-22 12:31:15 +00:00
|
|
|
return mpChain->PutData( rPos, rEngine, bInterpret, bApi );
|
2012-03-21 19:06:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual sal_Bool SetCellText( const ScAddress& rPos, const String& rText,
|
|
|
|
sal_Bool bInterpret, sal_Bool bEnglish, sal_Bool bApi,
|
|
|
|
const String& rFormulaNmsp,
|
|
|
|
const formula::FormulaGrammar::Grammar eGrammar )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "set cell text '%s'\n",
|
|
|
|
rtl::OUStringToOString( rText, RTL_TEXTENCODING_UTF8 ).getStr() );
|
2012-03-22 12:31:15 +00:00
|
|
|
return mpChain->SetCellText( rPos, rText, bInterpret, bEnglish, bApi, rFormulaNmsp, eGrammar );
|
2012-03-21 19:06:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool ShowNote( const ScAddress& rPos, bool bShow = true )
|
|
|
|
{
|
2012-03-22 17:06:27 +00:00
|
|
|
ScChangeOpWriter aOp( "showNote" );
|
|
|
|
aOp.appendAddress( rPos );
|
|
|
|
aOp.appendBool( bShow );
|
|
|
|
SendMessage( aOp );
|
|
|
|
return true; // needs some code auditing action
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool SetNoteText( const ScAddress& rPos, const String& rNoteText, sal_Bool bApi )
|
|
|
|
{
|
|
|
|
ScChangeOpWriter aOp( "setNoteText" );
|
|
|
|
aOp.appendAddress( rPos );
|
|
|
|
aOp.appendString( rNoteText );
|
|
|
|
aOp.appendBool( bApi );
|
|
|
|
SendMessage( aOp );
|
|
|
|
return true; // needs some code auditing action
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual sal_Bool RenameTable( SCTAB nTab, const String& rName,
|
|
|
|
sal_Bool bRecord, sal_Bool bApi )
|
|
|
|
{
|
|
|
|
ScChangeOpWriter aOp( "renameTable" );
|
|
|
|
aOp.appendInt( nTab );
|
|
|
|
aOp.appendString( rName );
|
|
|
|
aOp.appendBool( bRecord );
|
|
|
|
aOp.appendBool( bApi );
|
|
|
|
SendMessage( aOp );
|
|
|
|
return true; // needs some code auditing action
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual sal_Bool ApplyAttributes( const ScMarkData& rMark, const ScPatternAttr& rPattern,
|
|
|
|
sal_Bool bRecord, sal_Bool bApi )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Apply Attributes\n" );
|
|
|
|
return mpChain->ApplyAttributes( rMark, rPattern, bRecord, bApi );
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual sal_Bool ApplyStyle( const ScMarkData& rMark, const String& rStyleName,
|
|
|
|
sal_Bool bRecord, sal_Bool bApi )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Apply Style '%s'\n",
|
|
|
|
rtl::OUStringToOString( rStyleName, RTL_TEXTENCODING_UTF8 ).getStr() );
|
|
|
|
return mpChain->ApplyStyle( rMark, rStyleName, bRecord, bApi );
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual sal_Bool MergeCells( const ScCellMergeOption& rOption, sal_Bool bContents,
|
|
|
|
sal_Bool bRecord, sal_Bool bApi )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Merge cells\n" );
|
|
|
|
return mpChain->MergeCells( rOption, bContents, bRecord, bApi );
|
2012-03-21 19:06:35 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
SC_DLLPRIVATE ScDocFunc *ScDocShell::CreateDocFunc()
|
|
|
|
{
|
2012-03-23 10:55:09 +01:00
|
|
|
// FIXME: the chains should be auto-ptrs, so should be collab
|
2012-03-28 20:24:23 +02:00
|
|
|
bool bIsMaster = false;
|
2012-03-21 19:06:35 +00:00
|
|
|
if (getenv ("INTERCEPT"))
|
2012-03-22 12:31:15 +00:00
|
|
|
return new ScDocFuncSend( *this, new ScDocFuncRecv( *this, new ScDocFuncDirect( *this ) ) );
|
2012-03-28 20:24:23 +02:00
|
|
|
else if (isCollabMode( bIsMaster ))
|
2012-03-23 10:55:09 +01:00
|
|
|
{
|
|
|
|
ScDocFuncRecv* pReceiver = new ScDocFuncRecv( *this, new ScDocFuncDirect( *this ) );
|
|
|
|
ScDocFuncSend* pSender = new ScDocFuncSend( *this, pReceiver );
|
|
|
|
bool bOk = true;
|
2012-03-23 17:40:21 +00:00
|
|
|
ScCollaboration* pCollab = new ScCollaboration();
|
2012-03-23 16:25:34 +00:00
|
|
|
pCollab->sigPacketReceived.connect(
|
2012-03-23 17:14:36 +00:00
|
|
|
boost::bind( &ScDocFuncRecv::packetReceived, pReceiver, _1, _2 ));
|
2012-03-23 17:40:21 +00:00
|
|
|
pCollab->sigFileReceived.connect(
|
|
|
|
boost::bind( &ScDocFuncRecv::fileReceived, pReceiver, _1));
|
2012-03-26 14:22:25 +01:00
|
|
|
bOk = bOk && pCollab->initManager(!bIsMaster);
|
|
|
|
if (bIsMaster)
|
2012-03-23 14:10:36 +00:00
|
|
|
{
|
|
|
|
bOk = bOk && pCollab->initAccountContact();
|
2012-03-23 12:39:35 +01:00
|
|
|
bOk = bOk && pCollab->startCollaboration();
|
2012-03-23 14:10:36 +00:00
|
|
|
}
|
2012-03-23 10:55:09 +01:00
|
|
|
if (bOk)
|
|
|
|
{
|
|
|
|
pReceiver->SetCollaboration( pCollab);
|
|
|
|
pSender->SetCollaboration( pCollab);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Could not start collaboration.\n");
|
|
|
|
delete pCollab;
|
|
|
|
}
|
|
|
|
return pSender;
|
|
|
|
}
|
2012-03-21 19:06:35 +00:00
|
|
|
else
|
|
|
|
return new ScDocFuncDirect( *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|