summaryrefslogtreecommitdiffstats
path: root/kalarm/kalarmd/clientinfo.cpp
blob: e8c5ea6c7304ab115665b72b34999b8ea1533e62 (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
/*
 *  clientinfo.cpp  -  client application information
 *  Program:  KAlarm's alarm daemon (kalarmd)
 *  Copyright (C) 2001, 2004 by David Jarvie <software@astrojar.org.uk>
 *
 *  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 "adcalendar.h"
#include "clientinfo.h"

TQMap<TQCString, ClientInfo*> ClientInfo::mClients;


ClientInfo::ClientInfo(const TQCString& appName, const TQString& title,
                       const TQCString& dcopObj, const TQString& calendar, bool startClient)
	: mAppName(appName),
	  mTitle(title),
	  mDcopObject(dcopObj),
	  mCalendar(new ADCalendar(calendar, appName)),
	  mStartClient(startClient)
{
	mClients[mAppName] = this;
}

ClientInfo::ClientInfo(const TQCString& appName, const TQString& title,
                       const TQCString& dcopObj, ADCalendar* calendar, bool startClient)
	: mAppName(appName),
	  mTitle(title),
	  mDcopObject(dcopObj),
	  mCalendar(calendar),
	  mStartClient(startClient)
{
	mClients[mAppName] = this;
}

ClientInfo::~ClientInfo()
{
	delete mCalendar;
	mClients.remove(mAppName);
}

/******************************************************************************
* Set a new calendar for the specified client application.
*/
ADCalendar* ClientInfo::setCalendar(const TQString& url)
{
	if (url != mCalendar->urlString())
	{
		delete mCalendar;
		mCalendar = new ADCalendar(url, mAppName);
	}
	return mCalendar;
}

/******************************************************************************
* Return the ClientInfo object for the specified client application.
*/
ClientInfo* ClientInfo::get(const TQCString& appName)
{
	if (appName.isEmpty())
		return 0;
	TQMap<TQCString, ClientInfo*>::ConstIterator it = mClients.find(appName);
	if (it == mClients.end())
		return 0;
	return it.data();
}

/******************************************************************************
* Return the ClientInfo object for client which owns the specified calendar.
*/
ClientInfo* ClientInfo::get(const ADCalendar* cal)
{
	for (ClientInfo::ConstIterator it = ClientInfo::begin();  it != ClientInfo::end();  ++it)
		if (it.data()->calendar() == cal)
			return it.data();
	return 0;
}

/******************************************************************************
* Delete all clients.
*/
void ClientInfo::clear()
{
	TQMap<TQCString, ClientInfo*>::Iterator it;
	while ((it = mClients.begin()) != mClients.end())
		delete it.data();
}

/******************************************************************************
* Delete the client with the specified name.
*/
void ClientInfo::remove(const TQCString& appName)
{
	TQMap<TQCString, ClientInfo*>::Iterator it = mClients.find(appName);
	if (it != mClients.end())
		delete it.data();
}