Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/linksmodel.py
blob: 4318bfc5a45f02fdc5f1f1c74879877b5e69e032 (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
# Copyright (C) 2006, Red Hat, Inc.
#
# 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 St, Fifth Floor, Boston, MA  02110-1301  USA

import gobject

class Link(object):
	def __init__(self, buddy, title, url):
		self.buddy = buddy
		self.title = title
		self.url = url

class LinksModel(gobject.GObject):
	__gsignals__ = {
		'link-added':   (gobject.SIGNAL_RUN_FIRST,
						 gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])),
		'link-removed': (gobject.SIGNAL_RUN_FIRST,
						 gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])),
	}

	def __init__(self):
		gobject.GObject.__init__(self)
		self._links = {}

	def add_link(self, buddy, title, url):
		link = Link(buddy, title, url)
		self._links[(buddy.get_name(), url)] = link

		self.emit('link-added', link)

	def remove_link(self, buddy, url):
		key = (buddy.get_name(), url)
		if self._links.haskey(key):
			link = self._links[key]
			del self._links[key]
			self.emit('link-removed', link)

	def __iter__(self):
		return self._links.values().__iter__()