summaryrefslogtreecommitdiffstats
path: root/kontact_plugin/basket_plugin.cpp
blob: e6cfb9f9c40792c4819d82bad6937edc3ac6f604 (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
97
98
99
100
101
102
103
104
105
106
107
/***************************************************************************
 *   Copyright (C) 2006 by Petri Damsten                                   *
 *   damu@iki.fi                                                           *
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 *   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         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
 ***************************************************************************/

#include <kgenericfactory.h>
#include <kparts/componentfactory.h>
#include <kontact/core.h>
#include <klocale.h>
#include <kcmdlineargs.h>
#include <dcopref.h>
#include "basketdcopiface_stub.h"
#include "basket_plugin.h"
#include "basket_options.h"
#include "basket_part.h"

typedef KGenericFactory<BasketPlugin, Kontact::Core> BasketPluginFactory;
K_EXPORT_COMPONENT_FACTORY( libkontact_basket,
                            BasketPluginFactory( "kontact_basketplugin" ) )

BasketPlugin::BasketPlugin( Kontact::Core *core, const char *, const TQStringList& )
  : Kontact::Plugin( core, core, "basket" )
{
	setInstance( BasketPluginFactory::instance() );
	insertNewAction(new KAction( i18n("&New Basket..."), "basket", CTRL+SHIFT+Key_B,
					this, TQT_SLOT(newBasket()), actionCollection(), "basket_new" ));

	m_uniqueAppWatcher = new Kontact::UniqueAppWatcher(
		new Kontact::UniqueAppHandlerFactory<BasketUniqueAppHandler>(), this);
}

BasketPlugin::~BasketPlugin()
{
}

KParts::ReadOnlyPart* BasketPlugin::createPart()
{
	BasketPart* part = static_cast<BasketPart*>(loadPart());
	if(!part)
		return 0;

	m_stub = new BasketDcopInterface_stub(dcopClient(), "basket", "BasketIface");
	connect(part, TQT_SIGNAL(showPart()), this, TQT_SLOT(showPart()));
	return part;
}

void BasketPlugin::newBasket()
{
	(void) part(); // ensure part is loaded
	Q_ASSERT(m_stub);
	if (m_stub) {
		kdDebug() << k_funcinfo << endl;
		m_stub->newBasket();
	}
}

void BasketPlugin::showPart()
{
	core()->selectPlugin(this);
}

#if 0
bool BasketPlugin::createDCOPInterface( const TQString& serviceType )
{
	kdDebug() << k_funcinfo << serviceType << endl;
	return false;
}
#endif
bool BasketPlugin::isRunningStandalone()
{
	return m_uniqueAppWatcher->isRunningStandalone();
}

void BasketUniqueAppHandler::loadCommandLineOptions()
{
	KCmdLineArgs::addCmdLineOptions(basket_options);
}

int BasketUniqueAppHandler::newInstance()
{
	(void)plugin()->part();
	DCOPRef kmail("basket", "BasketIface");
	DCOPReply reply = kmail.call("handleCommandLine", false);
	if (reply.isValid()) {
		bool handled = reply;
		if ( !handled )
			return Kontact::UniqueAppHandler::newInstance();
	}
	return 0;
}

#include "basket_plugin.moc"