Source

almad-gentoo / net-im / psi / files / psi-0.12.1-plugin-otr.patch

Full commit
  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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
Index: src/pluginmanager.h
===================================================================
--- src/pluginmanager.h	(Revision 1195)
+++ src/pluginmanager.h	(Arbeitskopie)
@@ -4,9 +4,12 @@
 #include <QtCore>
 #include <QList>
 #include <QMap>
+#include <QToolButton>
+#include <QAction>
 
 #include "userlist.h"
 #include "optionstree.h"
+#include "../iris/include/im.h"
 
 class PsiPlugin;
 
@@ -22,6 +25,8 @@
 
 class QPluginLoader;
 
+using namespace XMPP;
+
 class PluginManager : public QObject
 {
 	Q_OBJECT
@@ -30,9 +35,15 @@
 
 	QStringList availablePlugins();
 
+	QList<QAction*> getChatDlgMenuEntries(QWidget* parent, 
+									      PsiAccount* account, 
+	                                      const XMPP::Jid& otherjid);
+
 	void addAccount( const PsiAccount* account, XMPP::Client* client);
-	void message( PsiAccount* account, const XMPP::Jid& from, 
-	const UserListItem*, const QString& message );
+	QString incomingMessage( PsiAccount* account, const XMPP::Jid& from, QString message );
+	HTMLElement incomingMessage( PsiAccount* account, const XMPP::Jid& from, HTMLElement htmlMessage );
+	QString outgoingMessage( PsiAccount* account, const XMPP::Jid& from, QString message );
+				
 	bool loadPlugin( const QString& file );
 	void loadEnabledPlugins();
 	bool unloadPlugin( const QString& file );
@@ -41,6 +52,13 @@
 	QString shortName( const QString& plugin );
 	QWidget* getOptionsWidget( const QString& plugin );
 	bool processEvent( const PsiAccount* account, QDomElement &event );
+	void statusChanged(QString account, QString jid, QString resource, int prio, QString status, 
+			   QString text);
+	void contactOffline(QString account, QString contact);
+	void contactOnline(QString account, QString contact);
+	void login(QString jid);
+	void logout(QString jid);
+	void quitProgram();
 	
 	const QVariant getGlobalOption(const QString& option);
 	
@@ -80,6 +98,8 @@
 	void optionChanged(const QString& option);
 	void sendStanza( const PsiAccount* account, const QDomElement& stanza);
 	void sendStanza( const PsiAccount* account, const QString& stanza);
+	void sendStanza(const QString& fromJid, const QString& stanza);
+	void getHomeDir(QString&);
 };
 
 #endif
Index: src/about.ui
===================================================================
--- src/about.ui	(Revision 1195)
+++ src/about.ui	(Arbeitskopie)
@@ -101,8 +101,11 @@
          </property>
          <property name="text" >
           <string>A cross-platform Jabber client designed for the Jabber power user.&lt;br>
-&lt;br>
+	  &lt;br>
 Copyright © 2001-2008 The Psi Team.&lt;br>
+
+This version of Psi has been been patched by Timo Engel (timo-e@freenet.de)
+
 </string>
          </property>
          <property name="textFormat" >
Index: src/psiplugin.h
===================================================================
--- src/psiplugin.h	(Revision 1195)
+++ src/psiplugin.h	(Arbeitskopie)
@@ -28,7 +28,9 @@
 
 #include <QObject>
 #include <QtCore>
-#include <QDomNode>
+#include <QtXml>
+#include <QAction>
+#include <QToolButton>
 
 class PsiAccount;
 class QDomElement;
@@ -53,6 +55,7 @@
 	 * \return Plugin name
 	 */
 	virtual QString name() const = 0;
+
 	/** \brief Short name for the plugin
 	 *	This is the short name of the plugin, used for options structures. 
 	 * It must consist of only alphanumerics (no spaces or punctuation).
@@ -66,11 +69,40 @@
 	 * \return Plugin version string
 	 */
 	virtual QString version() const = 0; 
-	
-	virtual void message( const PsiAccount* account, const QString& message, const QString& fromJid, const QString& fromDisplay) 
-	{Q_UNUSED(account);Q_UNUSED(message);Q_UNUSED(fromJid);Q_UNUSED(fromDisplay);}
 
 	/**
+	 * Allows the plugin to add a entry to the chat dialog menu.
+	 */
+	virtual QAction* getChatDlgMenuEntry(QWidget* parent,
+				       	     const QString& fromJid,
+				             const QString& toJid)
+	{Q_UNUSED(parent);Q_UNUSED(fromJid);Q_UNUSED(toJid);return NULL;}
+
+	/**
+	 * process incoming message
+	 */
+	virtual QString incomingMessage( const QString& fromJid,
+			      const QString& toJid, 
+			      const QString& message) 
+	{Q_UNUSED(fromJid);Q_UNUSED(toJid);Q_UNUSED(message);return NULL;}
+
+	/**
+	 * process incoming HTML message
+	 */
+	virtual QDomElement incomingMessage( const QString& fromJid,
+			      const QString& toJid, 
+			      const QDomElement& html) 
+	{Q_UNUSED(fromJid);Q_UNUSED(toJid);Q_UNUSED(html);return QDomElement();}
+
+	/** 
+	 * process outgoing message
+	 */
+	virtual QString outgoingMessage(const QString& fromJid, 
+					const QString& toJid, 
+					const QString& message)
+	{Q_UNUSED(fromJid);Q_UNUSED(toJid);Q_UNUSED(message); return NULL;}
+
+	/**
 	 * \brief Plugin options widget
 	 * This method is called by the Psi options system to retrieve
 	 * a widget containing the options for this plugin.
@@ -81,10 +113,17 @@
 	virtual QWidget* options() {return NULL;} 
 	
 
-	virtual bool processEvent( const PsiAccount* account, QDomNode &event ) {Q_UNUSED(account);Q_UNUSED(event);return true;}
+	/**
+	 * 
+	 *
+	 */
+	virtual bool processEvent( const PsiAccount* account, QDomNode &event ) 
+	{Q_UNUSED(account);Q_UNUSED(event);return true;}
 
+
 	/**
-	 * Convenience method for plugins, allowing them to convert a QDomElement to a QString
+	 * Convenience method for plugins, allowing them to convert a QDomElement 
+	 * to a QString
 	 */
 	static QString toString(const QDomNode& xml)
 	{
@@ -93,7 +132,53 @@
 		xml.save(stream, 0);
 		return QString(*stream.string());
 	}
-	
+
+	/* initialize the plugin. called from the pluginmanager after loading */
+	virtual void init() {return;}
+
+	/* a contact has become available */
+	virtual void contactOnline(QString account, QString jid) {
+		Q_UNUSED(jid);
+		Q_UNUSED(account);
+		return;
+	}
+
+	/* a contact has become unavailable */
+	virtual void contactOffline(QString account, QString jid) {
+		Q_UNUSED(jid);
+		Q_UNUSED(account);
+		return;
+	}
+
+	/* a contact has changed its status */
+	virtual void statusChanged(QString account, QString jid, QString resource, int prio, 
+		QString status, QString text) {
+		Q_UNUSED(account);
+		Q_UNUSED(jid);
+		Q_UNUSED(resource);
+		Q_UNUSED(prio);
+		Q_UNUSED(status);
+		Q_UNUSED(text);
+		return;
+	}
+
+	/* account logged in */
+	virtual void login(QString jid) {
+		Q_UNUSED(jid);
+		return;
+	}
+
+	/* account went offline */
+	virtual void logout(QString jid) {
+		Q_UNUSED(jid);
+		return;
+	}
+
+	/* user want to exit psi */
+	virtual void quitProgram() {
+		return;
+	}
+
 signals:
 	/**
 	 *	\brief Signals that the plugin wants to send a stanza.
@@ -101,7 +186,7 @@
 	 * \param account The account name, as used by the plugin interface.
 	 * \param stanza The stanza to be sent.
 	 */
-	//void sendStanza( const PsiAccount* account, const QDomElement& stanza);
+	void sendStanza( const PsiAccount* account, const QDomElement& stanza);
 
 	/**
 	 *	\brief Signals that the plugin wants to send a stanza.
@@ -111,7 +196,14 @@
 	 */
 	void sendStanza( const PsiAccount* account, const QString& stanza);
 	
+	
 	/**
+	 * Send a stanza from the account with the jid fromJid.
+	 *
+	 */
+	void sendStanza( const QString& fromJid, const QString& stanza);
+	
+	/**
 	 * \brief Requests an item in the Psi menu for the plugin
 	 * 
 	 * \param label The text to be inserted in the menu
@@ -162,6 +254,11 @@
 	 */
 	void getGlobalOption( const QString& option, QVariant& value);
 	
+	/**
+	 * Returns the home-directory used by psi
+	 */
+	void getHomeDir(QString& dir);
+
 //protected:
 
 	
Index: src/options/opt_plugins.h
===================================================================
--- src/options/opt_plugins.h	(Revision 1195)
+++ src/options/opt_plugins.h	(Arbeitskopie)
@@ -14,8 +14,8 @@
 	~OptionsTabPlugins();
 
 	QWidget *widget();
-	void applyOptions(Options *opt);
-	void restoreOptions(const Options *opt);
+	void applyOptions();
+	void restoreOptions();
 
 private:
 	QWidget *w;
Index: src/options/opt_plugins.cpp
===================================================================
--- src/options/opt_plugins.cpp	(Revision 1195)
+++ src/options/opt_plugins.cpp	(Arbeitskopie)
@@ -53,23 +53,21 @@
 	return w;
 }
 
-void OptionsTabPlugins::applyOptions(Options *opt)
+void OptionsTabPlugins::applyOptions()
 {
 	if ( !w )
 		return;
 
 	OptPluginsUI *d = (OptPluginsUI *)w;
 	Q_UNUSED(d);
-	Q_UNUSED(opt);
 }
 
-void OptionsTabPlugins::restoreOptions(const Options *opt)
+void OptionsTabPlugins::restoreOptions()
 {
 	if ( !w )
 		return;
 
 	OptPluginsUI *d = (OptPluginsUI *)w;
-	Q_UNUSED(opt);
 	Q_UNUSED(d);
 }
 
@@ -104,6 +102,15 @@
 		.arg(PluginManager::instance()->shortName(d->cb_plugins->currentText()));
 	bool value=d->cb_loadPlugin->isChecked(); 
 	PsiOptions::instance()->setOption(option, value);
+	if ( value) {
+		PluginManager::instance()->loadEnabledPlugins();
+		pluginSelected(0);
+	}
+	else {
+		delete d->pluginOptions;
+		PluginManager::instance()->unloadPlugin( d->cb_plugins->currentText());
+		d->pluginOptions = new QLabel(tr("This plugin has no user configurable options"));
+	}
 }
 
 void OptionsTabPlugins::pluginSelected(int index)
Index: src/main.h
===================================================================
--- src/main.h	(Revision 1195)
+++ src/main.h	(Arbeitskopie)
@@ -24,6 +24,8 @@
 #include <QString>
 #include <QObject>
 
+#include "pluginmanager.h"
+
 class PsiCon;
 
 class PsiMain : public QObject
Index: src/psichatdlg.cpp
===================================================================
--- src/psichatdlg.cpp	(Revision 1195)
+++ src/psichatdlg.cpp	(Arbeitskopie)
@@ -38,6 +38,7 @@
 #include "userlist.h"
 #include "jidutil.h"
 #include "textutil.h"
+#include "pluginmanager.h"
 
 PsiChatDlg::PsiChatDlg(const Jid& jid, PsiAccount* pa, TabManager* tabManager)
 		: ChatDlg(jid, pa, tabManager)
@@ -189,6 +190,12 @@
 
 	act_compact_ = new IconAction(tr("Toggle Compact/Full size"), "psi/compact", tr("Toggle Compact/Full size"), 0, this);
 	connect(act_compact_, SIGNAL(activated()), SLOT(toggleSmallChat()));
+
+#ifdef PSI_PLUGINS
+	act_plugins_ = PluginManager::instance()->getChatDlgMenuEntries(this, 
+	                                                                account(),
+								        							jid());
+#endif
 }
 
 void PsiChatDlg::initToolBar()
@@ -207,6 +214,12 @@
 	if (account()->voiceCaller()) {
 		ui_.toolbar->addAction(act_voice_);
 	}
+#ifdef PSI_PLUGINS
+	foreach (QAction* i, act_plugins_ )
+	{
+		ui_.toolbar->addAction(i);
+	}
+#endif
 }
 
 void PsiChatDlg::contextMenuEvent(QContextMenuEvent *)
@@ -364,6 +377,13 @@
 
 	pm_settings_->addAction(act_info_);
 	pm_settings_->addAction(act_history_);
+#ifdef PSI_PLUGINS
+	foreach (QAction* a, act_plugins_)
+	{
+		pm_settings_->insertSeparator();
+		pm_settings_->addAction(a);
+	}
+#endif
 }
 
 void PsiChatDlg::updateCounter()
Index: src/psiaccount.cpp
===================================================================
--- src/psiaccount.cpp	(Revision 1195)
+++ src/psiaccount.cpp	(Arbeitskopie)
@@ -1243,6 +1243,9 @@
 // disconnect or stop reconnecting
 void PsiAccount::logout(bool fast, const Status &s)
 {
+#ifdef PSI_PLUGINS	
+	PluginManager::instance()->logout(jid().node() + "@" + jid().domain());
+#endif
 	if(!isActive())
 		return;
 
@@ -1447,6 +1450,9 @@
 
 	// ask for roster
 	d->client->rosterRequest();
+#ifdef PSI_PLUGINS
+	PluginManager::instance()->login(jid().node() + "@" + jid().domain());
+#endif
 }
 
 void PsiAccount::cs_connectionClosed()
@@ -1618,7 +1624,7 @@
 		str = tr("Broken security layer (SASL)");
 	else
 		str = tr("None");
-	//printf("str[%s], reconn=%d\n", str.latin1(), reconn);
+//printf("str[%s], reconn=%d\n", str.latin1(), reconn);
 	*_str = str;
 	*_reconn = reconn;
 }
@@ -1864,6 +1870,11 @@
 		UserResourceList::Iterator rit = u->userResourceList().find(j.resource());
 		bool found = (rit == u->userResourceList().end()) ? false: true;
 		if(!found) {
+#ifdef PSI_PLUGINS
+			PluginManager::instance()->contactOnline(
+				jid().node() + "@" + jid().domain(),
+				j.node() + "@" + j.domain());
+#endif
 			popupType = PopupOnline;
 
 			UserResource ur(r);
@@ -1949,6 +1960,15 @@
 			}
 		}
 	}
+#ifdef PSI_PLUGINS
+	PluginManager::instance()->statusChanged(
+		jid().node() + "@" + jid().domain(),
+		j.node() + "@" + j.domain(),
+		r.name(),
+		r.priority(),
+		r.status().show(),
+		r.status().status());
+#endif
 }
 
 void PsiAccount::client_resourceUnavailable(const Jid &j, const Resource &r)
@@ -2019,6 +2039,11 @@
 		PsiGrowlNotifier::instance()->popup(this, PsiPopup::AlertOffline, j, r, u);
 #endif
 	}
+#ifdef PSI_PLUGINS
+	PluginManager::instance()->contactOffline(
+		jid().node() + "@" + jid().domain(),
+		j.node() + "@" + j.domain());
+#endif
 }
 
 void PsiAccount::client_presenceError(const Jid &j, int, const QString &str)
@@ -3493,6 +3518,14 @@
 		}
 	}
 
+#ifdef PSI_PLUGINS
+        if (! nm.body().isEmpty()) {
+                nm.setBody(PluginManager::instance()->outgoingMessage(this, nm.to(), nm.body()));
+        }
+#endif
+
+
+
 	d->client->sendMessage(nm);
 
 	// only toggle if not an invite or body is not empty
@@ -3764,6 +3797,32 @@
 	//FIXME(KIS): must now cause the event to be recreated from this xml or such. Horrid. 	
 #endif
 	
+#ifdef PSI_PLUGINS
+	if(e->type() == PsiEvent::Message) {
+		MessageEvent *me = (MessageEvent *)e;
+		Message msg = me->message();
+		UserListItem *ulItem=NULL;
+		if ( !ul.isEmpty() ) {
+			ulItem=ul.first();
+		}
+		
+		if (msg.containsHTML() && ! msg.html().text().isEmpty() ) {
+			HTMLElement htmlPart = PluginManager::instance()->incomingMessage(this,
+				msg.from(),
+				msg.html());
+			msg.setHTML(htmlPart, msg.lang());
+			msg.setBody(htmlPart.text());
+		}
+        	else if (! msg.body().isEmpty()) {
+                	msg.setBody( PluginManager::instance()->incomingMessage(this, 
+							      msg.from(),
+							      msg.body()));
+        	}
+		me->setMessage(msg);
+		e = me;
+	}
+#endif
+	
 	if(d->acc.opt_log && activationType != FromXml) {
 		if(e->type() == PsiEvent::Message || e->type() == PsiEvent::Auth) {
 			// don't log private messages
@@ -3772,10 +3831,14 @@
 		}
 	}
 
+	
 	if(e->type() == PsiEvent::Message) {
+	
 		MessageEvent *me = (MessageEvent *)e;
-		const Message &m = me->message();
+		Message msg = me->message();
+		const Message &m = msg;
 
+
 		// Pass message events to chat window
 		if ((m.containsEvents() || m.chatState() != StateNone) && m.body().isEmpty()) {
 			if (PsiOptions::instance()->getOption("options.messages.send-composing-events").toBool()) {
@@ -3840,13 +3903,7 @@
 			// FIXME: handle message errors
 			//msg.text = QString(tr("<big>[Error Message]</big><br>%1").arg(plain2rich(msg.text)));
 		}
-#ifdef PSI_PLUGINS
-		UserListItem *ulItem=NULL;
-		if ( !ul.isEmpty() )
-			ulItem=ul.first();
-		PluginManager::instance()->message(this,e->from(),ulItem,((MessageEvent*)e)->message().body());
-#endif
-	}
+}
 	else if(e->type() == PsiEvent::HttpAuth) {
 		playSound(PsiOptions::instance()->getOption("options.ui.notifications.sounds.system-message").toString());
 	}
Index: src/main.cpp
===================================================================
--- src/main.cpp	(Revision 1195)
+++ src/main.cpp	(Arbeitskopie)
@@ -265,6 +265,9 @@
 
 void PsiMain::bail()
 {
+#ifdef PSI_PLUGINS
+	PluginManager::instance()->quitProgram();
+#endif
 	if(pcon) {
 		delete pcon;
 		pcon = 0;
Index: src/psichatdlg.h
===================================================================
--- src/psichatdlg.h	(Revision 1195)
+++ src/psichatdlg.h	(Arbeitskopie)
@@ -69,7 +69,9 @@
 	IconAction* act_file_;
 	IconAction* act_compact_;
 	IconAction* act_voice_;
-
+#ifdef PSI_PLUGINS
+	QList<QAction*> act_plugins_;
+#endif
 	bool smallChat_;
 	QDateTime lastMsgTime_;
 };
Index: src/pluginmanager.cpp
===================================================================
--- src/pluginmanager.cpp	(Revision 1195)
+++ src/pluginmanager.cpp	(Arbeitskopie)
@@ -7,6 +7,7 @@
 #include "userlist.h"
 #include "applicationinfo.h"
 #include "psioptions.h"
+#include "psiaccount.h"
 #include <QtCrypto>
 #include "xmpp_client.h"
 
@@ -71,6 +72,7 @@
  */
 void PluginManager::optionChanged(const QString& option)
 {
+	Q_UNUSED(option);
 	//QString("%1.%2").arg(loadOptionPrefix).arg(shortNames_[plugin]);
 }
 
@@ -164,12 +166,17 @@
 	plugins_.insert( plugin->name(), plugin );
 	
 	qDebug() << "connecting to plugin " << plugin->name();
+	connect(plugin, SIGNAL(sendStanza(const QString&, const QString&)),
+		this,   SLOT(sendStanza(const QString&, const QString&)));
 	connect( plugin, SIGNAL(sendStanza(const PsiAccount*, const QDomElement&)), this, SLOT(sendStanza(const PsiAccount*, const QDomElement&)));
 	connect( plugin, SIGNAL(sendStanza(const PsiAccount*, const QString&)), this, SLOT(sendStanza(const PsiAccount*, const QString&)));
 	connect( plugin, SIGNAL(setPluginOption( const QString&, const QVariant& )), this, SLOT( setPluginOption( const QString&, const QVariant& )));
 	connect( plugin, SIGNAL(getPluginOption( const QString&, QVariant&)), this, SLOT( getPluginOption( const QString&, QVariant&)));
 	connect( plugin, SIGNAL(setGlobalOption( const QString&, const QVariant& )), this, SLOT( setGlobalOption( const QString&, const QVariant& )));
 	connect( plugin, SIGNAL(getGlobalOption( const QString&, QVariant&)), this, SLOT( getGlobalOption( const QString&, QVariant&)));
+	connect(plugin, SIGNAL(getHomeDir(QString&)),
+		this, SLOT(getHomeDir(QString&)));
+	plugin->init();
 	return true;
 }
 
@@ -274,6 +281,9 @@
 		QDir dir(d);
 		foreach(QString file, dir.entryList()) {
 		  	file=dir.absoluteFilePath(file);
+		  	if (file.endsWith("..") || file.endsWith(".") ) {
+		  		continue;
+		  	}
 			qWarning(qPrintable(QString("Found plugin: %1").arg(file)));
 			if ( !loaders_.contains(file) ) { 
 				loadPlugin(file);
@@ -341,7 +351,8 @@
  */
 void PluginManager::getPluginOption( const QString& option, QVariant& value)
 {
-	
+	Q_UNUSED(option);
+	Q_UNUSED(value);
 }
 
 /**
@@ -373,17 +384,82 @@
 	else
 		qDebug("not valid option");
 }
-	
-void PluginManager::message(PsiAccount* account, const XMPP::Jid& from, const UserListItem* ul, const QString& message)
+
+
+
+QList<QAction*> PluginManager::getChatDlgMenuEntries(QWidget* parent, 
+                                                     PsiAccount* account,
+					           						 const XMPP::Jid& otherjid)
 {
-	QString fromString=QString("%1").arg(from.full());
+	const QString accountString = QString("%1").arg(account->jid().full());
+	const QString otherJidString = QString("%1").arg(otherjid.full());
+	QList<QAction*> res;
+ 	foreach(PsiPlugin* plugin, plugins_.values() ) 
+	{
+		QAction* m = plugin->getChatDlgMenuEntry(parent, accountString,
+											     otherJidString);
+		if (m) {
+			res.append(m);
+		}
+	}
+	return res;
+}
+
+
+
+/**
+ * incomingMessage. Function is only for non-HTML messages.
+ */
+QString PluginManager::incomingMessage(PsiAccount* account, const XMPP::Jid& from, 
+	QString message) {
+	const QString toString = QString("%1").arg(account->jid().full());
+	const QString fromString=QString("%1").arg(from.full());
+	//qDebug() << "pluginmanager: incomming message from " << fromString 
+	//	 << " to " << toString;
 	qDebug() << "message from" << fromString;
 	foreach(PsiPlugin* plugin, plugins_.values() ) {
-		plugin->message( account, message , fromString , from.full() );
+		message = plugin->incomingMessage(fromString, toString, message );
+		//qDebug() << plugin->shortName() << " returned: " << endl
+		//	<< message << "\n--\n";
 	}
+	//qDebug() << "PluginManager::incomingMessage:\n" << message << endl << "--";
+	return message;
 }
 
 /**
+ * incommingMessage with HTML content.
+ */
+HTMLElement PluginManager::incomingMessage(PsiAccount* account, const XMPP::Jid& from,
+                                           HTMLElement htmlMessage)
+{
+	const QString toString = QString("%1").arg(account->jid().full());
+	const QString fromString=QString("%1").arg(from.full());
+	//qDebug() << "pluginmanager: incomming message from " << fromString 
+	//	 << " to " << toString;
+	QDomElement body = htmlMessage.body();
+
+	//QString str;
+	//QTextStream ts( &str, IO_WriteOnly );
+	//body.save(ts, 8);
+	//qDebug() << "--\n" << str << "\n--\n\n";
+
+	foreach(PsiPlugin* plugin, plugins_.values())
+	{
+		body = plugin->incomingMessage(fromString, toString, body);
+		//qDebug() << plugin->shortName() << " returned: " << endl
+		//	<< message << "\n--\n";
+	}
+	
+	//QString str;
+	//QTextStream ts( &str, IO_WriteOnly );
+	//body.save(ts, 2);
+	//qDebug() << "pluginmanager: modified message:\n" << str << "\n--\n";
+		
+	htmlMessage.setBody(body);
+	return htmlMessage;
+}
+
+/**
  * \brief Give each plugin the opportunity to process the incoming event
  * 
  * Each plugin is passed the event in turn. Any plugin may then modify the event
@@ -429,7 +505,27 @@
 	clients_[account]->send(stanza);
 }
 
+
 /**
+ * Sends a stanza from the account spezified with fromJid.
+ *
+ */
+void PluginManager::sendStanza(const QString& fromJid, const QString& stanza) {
+	//qDebug() << "pluginmanager: sending stanza from account " << fromJid 
+	//	<< endl << stanza << "\n--";
+	QMapIterator<const PsiAccount*, XMPP::Client*> iterator(clients_);
+	while (iterator.hasNext()) {
+		iterator.next();
+		const PsiAccount* account = iterator.key();
+		if ( ! QString::compare(account->jid().full(), fromJid, Qt::CaseInsensitive)) {
+			clients_.value(account)->send(stanza);
+			break;
+		}
+	}
+}
+
+
+/**
  * Tells the plugin manager about an XMPP::Client and the owning PsiAccount
  */
 void PluginManager::addAccount( const PsiAccount* account, XMPP::Client* client)
@@ -447,6 +543,83 @@
 	return true;
 }
 
+
+/**
+ * process an outgoing message
+ */
+QString PluginManager::outgoingMessage( PsiAccount* account, const XMPP::Jid& to, QString message ) {
+	const QString toString=QString("%1").arg(to.full());
+	const QString fromString = QString("%1").arg(account->jid().full());
+	//qDebug() << "pluginmanager: outgoing message from " << fromString << " to "
+	//	<< toString;
+	foreach(PsiPlugin* plugin, plugins_.values() ) {
+		message = plugin->outgoingMessage( fromString, toString, message );
+	}
+	return message;
+
+}
+
+/**
+ * Get the home-directory used by psi.
+ */
+void PluginManager::getHomeDir(QString& dir) {
+	dir = ApplicationInfo::homeDir();
+}
+
+/**
+ * A user from the roster has changed his status.
+ */
+void PluginManager::statusChanged(QString account, QString jid, QString resource, int prio, QString status, QString text) {
+	foreach(PsiPlugin* plugin, plugins_.values() ) {
+		plugin->statusChanged(account, jid, resource, prio, status, text);
+	}
+}
+
+/**
+ * A user from the roster has gone offline
+ */
+void PluginManager::contactOffline(QString account, QString jid) {
+	foreach(PsiPlugin* plugin, plugins_.values() ) {
+		plugin->contactOffline(account, jid);
+	}
+}
+
+/**
+ * A user from the roster has become available
+ */
+void PluginManager::contactOnline(QString account, QString jid) {
+	foreach(PsiPlugin* plugin, plugins_.values() ) {
+		plugin->contactOnline(account, jid);
+	}
+}
+
+/**
+ * A local account has succsesfully logged in
+ */
+void PluginManager::login(QString jid) {
+	foreach(PsiPlugin* plugin, plugins_.values() ) {
+		plugin->login(jid);
+	}
+
+}
+
+/**
+ * Account has logged of from the server.
+ */
+void PluginManager::logout(QString jid) {
+	foreach(PsiPlugin* plugin, plugins_.values() ) {
+		plugin->logout(jid);
+	}
+
+}
+
+void PluginManager::quitProgram() {
+	foreach(PsiPlugin* plugin, plugins_.values() ) {
+		plugin->quitProgram();
+	}
+}
+
+	
 PluginManager* PluginManager::instance_ = NULL;
 const QString PluginManager::loadOptionPrefix = "plugins.auto-load";
 const QString PluginManager::pluginOptionPrefix = "plugins.options";