summaryrefslogtreecommitdiffstats
path: root/kopete/libkopete/tests/kopetewallettest_program.cpp
blob: f127ba26a0f4dffba88f8df79ceb7e4ab34c2c9e (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
92
93
94
95
96
/*
    Tests for the wallet manager

    Copyright (c) 2003      by Richard Smith          <[email protected]>
    Kopete    (c) 2002-2003 by the Kopete developers  <[email protected]>

    *************************************************************************
    *                                                                       *
    * This program is free software; you can redistribute it and/or modify  *
    * it under the terms of the GNU General Public License as published by  *
    * the Free Software Foundation; either version 2 of the License, or     *
    * (at your option) any later version.                                   *
    *                                                                       *
    *************************************************************************
*/

#include <tqtextstream.h>
#include <tqtimer.h>

#include <tdeaboutdata.h>
#include <tdeapplication.h>
#include <tdecmdlineargs.h>
#include <kdebug.h>
#include <tdeglobal.h>
#include <kstandarddirs.h>
#include <dcopclient.h>
#include <tdewallet.h>

#include "kopetewalletmanager.h"
#include "kopetewallettest_program.h"

static TQTextStream _out( stdout, IO_WriteOnly );

void closeWallet()
{
	Kopete::WalletManager::self()->closeWallet();
}

void delay()
{
	TQTimer::singleShot( 3000, tqApp, TQ_SLOT( quit() ) );
	tqApp->exec();
}

void openWalletAsync()
{
	WalletReciever *r = new WalletReciever;
	_out << "[ASYNC] About to open wallet, receiver: " << r << endl;
	Kopete::WalletManager::self()->openWallet( r, TQ_SLOT( gotWallet(  TDEWallet::Wallet* ) ) );
}

void WalletReciever::gotWallet( TDEWallet::Wallet *w )
{
	_out << "[ASYNC] Received wallet pointer: " << w << " for receiver: " << this << endl;
}

void WalletReciever::timer()
{
	_out << "Timer..." << endl;
}

int main( int argc, char *argv[] )
{
	TDEAboutData aboutData( "kopetewallettest", "kopetewallettest", "version" );
	TDECmdLineArgs::init( argc, argv, &aboutData );
	TDECmdLineOptions opts[] = { {"+action",0,0}, TDECmdLineLastOption };
	TDECmdLineArgs::addCmdLineOptions( opts );
	TDEApplication app( "kopetewallettest" );

	TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();

	// must register with DCOP or async callbacks will fail
	_out << "DCOP registration returned " << app.dcopClient()->registerAs(app.name()) << endl;

	for( int i = 0; i < args->count(); ++i )
	{
		TQString arg = args->arg( i );
		_out << "Processing " << arg << endl;
		if( arg == TQString::fromLatin1( "open" ) ) openWalletAsync();
		if( arg == TQString::fromLatin1( "close" ) ) closeWallet();
		if( arg == TQString::fromLatin1( "delay" ) ) delay();
		_out << "Done." << endl;
	}

	WalletReciever *r = new WalletReciever;

	TQTimer timer;
	r->connect( &timer, TQ_SIGNAL( timeout() ), TQ_SLOT( timer() ) );
	timer.start( 1000 );

	_out << "About to start 30 second event loop" << endl;
	TQTimer::singleShot( 30000, tqApp, TQ_SLOT( quit() ) );
	return tqApp->exec();
}

#include "kopetewallettest_program.moc"