summaryrefslogtreecommitdiffstats
path: root/kopete/kopete/contactlist/customnotificationprops.cpp
blob: 82851eb453fbb3c3e1348b2e9c7554efcc3b1188 (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
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
/*
    customnotificationprops.cpp

    Kopete Contactlist Custom Notifications GUI for Groups and MetaContacts

    Contains UI controller logic for managing custom notifications

    Copyright (c) 2004 Will Stephenson <lists@stevello.free-online.co.uk>
    Kopete    (c) 2002-2003 by the Kopete developers  <kopete-devel@kde.org>

    *************************************************************************
    *                                                                       *
    * 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 <tqcheckbox.h>
#include <tqcombobox.h>
#include <tqlineedit.h>

#include <kdebug.h>
#include <tdeconfig.h>
#include <kurlrequester.h>

#include "customnotifications.h"
#include "kopeteeventpresentation.h"
#include "kopetenotifyevent.h"
#include "kopetenotifydataobject.h"

#include "customnotificationprops.h"

CustomNotificationProps::CustomNotificationProps( TQWidget *parent, Kopete::NotifyDataObject* item, const char * name )
: TQObject( parent, name )
{
	m_notifyWidget = new CustomNotificationWidget( parent, "notificationWidget" );

	m_item = item;
	TQString path = "kopete/eventsrc";
	TDEConfig eventsfile( path, true, false, "data" );
	m_eventList = eventsfile.groupList();
	TQStringList contactSpecificEvents; // we are only interested in events that relate to contacts
	TQStringList::Iterator it = m_eventList.begin();
	TQStringList::Iterator end = m_eventList.end();
	for ( ; it != end; ++it )
	{
		if ( !(*it).startsWith( TQString::fromLatin1( "kopete_contact_" ) ) )
			continue;
		contactSpecificEvents.append( *it );
		TQMap<TQString, TQString> entries = eventsfile.entryMap( *it );
		eventsfile.setGroup( *it );
		TQString comment = eventsfile.readEntry( "Comment", TQString::fromLatin1( "Found nothing!" ) );
		m_notifyWidget->cmbEvents->insertItem( comment );
	}
	m_eventList = contactSpecificEvents;
	slotEventsComboChanged( m_notifyWidget->cmbEvents->currentItem() );
	// we have to do this after adding items
	connect( m_notifyWidget->cmbEvents, TQT_SIGNAL( activated( int ) ), this, TQT_SLOT( slotEventsComboChanged( int ) ) );
}

void CustomNotificationProps::slotEventsComboChanged( int itemNo )
{
	// if the combo has changed, store the previous state of the widgets
	// record the selected item so we can save it when the widget changes next
	storeCurrentCustoms();
	m_event = m_eventList[ itemNo ];
	// update the widgets for the selected item
	// get the corresponding Kopete::NotifyEvent
	Kopete::NotifyEvent *evt = m_item->notifyEvent( m_event );
	// set the widgets accordingly
	resetEventWidgets();
	if ( evt )
	{
		// sound presentation
		Kopete::EventPresentation *pres = evt->presentation( Kopete::EventPresentation::Sound );
		if ( pres )
		{
			m_notifyWidget->chkCustomSound->setChecked( pres->enabled() );
			m_notifyWidget->customSound->setURL( pres->content() );
			m_notifyWidget->chkSoundSS->setChecked( pres->singleShot() );
		}
		// message presentation
		pres = evt->presentation( Kopete::EventPresentation::Message );
		if ( pres )
		{
			m_notifyWidget->chkCustomMsg->setChecked( pres->enabled() );
			m_notifyWidget->customMsg->setText( pres->content() );
			m_notifyWidget->chkMsgSS->setChecked( pres->singleShot() );
		}
		// chat presentation
		pres = evt->presentation( Kopete::EventPresentation::Chat );
		if ( pres )
		{
			m_notifyWidget->chkCustomChat->setChecked( pres->enabled() );
			m_notifyWidget->chkChatSS->setChecked( pres->singleShot() );
		}
		m_notifyWidget->chkSuppressCommon->setChecked( evt->suppressCommon() );
	}
	//dumpData();
}


void CustomNotificationProps::dumpData()
{
	Kopete::NotifyEvent *evt = m_item->notifyEvent( m_event );
	if ( evt )
		kdDebug( 14000 ) << k_funcinfo << evt->toString() << endl;
	else 
		kdDebug( 14000 ) << k_funcinfo << " no event exists." << endl;
}

void CustomNotificationProps::resetEventWidgets()
{
	m_notifyWidget->chkCustomSound->setChecked( false );
	m_notifyWidget->customSound->clear();
	m_notifyWidget->chkSoundSS->setChecked( true );
	m_notifyWidget->chkCustomMsg->setChecked( false );
	m_notifyWidget->customMsg->clear();
	m_notifyWidget->chkMsgSS->setChecked( true );
	m_notifyWidget->chkCustomChat->setChecked( false );
	m_notifyWidget->chkChatSS->setChecked( true );
	m_notifyWidget->chkSuppressCommon->setChecked( false );
}

void CustomNotificationProps::storeCurrentCustoms()
{
	if ( !m_event.isNull() )
	{
		Kopete::NotifyEvent *evt = m_item->notifyEvent( m_event );
		if ( !evt )
		{
			evt = new Kopete::NotifyEvent( );
			// store the changed event
			m_item->setNotifyEvent( m_event, evt );
		}
		evt->setSuppressCommon( m_notifyWidget->chkSuppressCommon->isChecked() );
		// set different presentations
		Kopete::EventPresentation *eventNotify = 0;
		eventNotify = new Kopete::EventPresentation( Kopete::EventPresentation::Sound, 
				m_notifyWidget->customSound->url(),
				m_notifyWidget->chkSoundSS->isChecked(),
				m_notifyWidget->chkCustomSound->isChecked() );
		evt->setPresentation( Kopete::EventPresentation::Sound, eventNotify );
		// set message attributes
		eventNotify = new Kopete::EventPresentation( Kopete::EventPresentation::Message,
				m_notifyWidget->customMsg->text(),
				m_notifyWidget->chkMsgSS->isChecked(),
				m_notifyWidget->chkCustomMsg->isChecked() );
		evt->setPresentation( Kopete::EventPresentation::Message, eventNotify );
		// set chat attributes
		eventNotify = new Kopete::EventPresentation( Kopete::EventPresentation::Chat,
				TQString(),
				m_notifyWidget->chkChatSS->isChecked(),
				m_notifyWidget->chkCustomChat->isChecked() );
		evt->setPresentation( Kopete::EventPresentation::Chat, eventNotify );
		evt->setSuppressCommon( m_notifyWidget->chkSuppressCommon->isChecked() );
	}
}

CustomNotificationWidget* CustomNotificationProps::widget()
{
	return m_notifyWidget;
}

#include "customnotificationprops.moc"