File: notifyosd.cpp

package info (click to toggle)
vdr-plugin-fritzbox 1.5.3-7.1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 788 kB
  • sloc: cpp: 4,829; makefile: 94; sh: 15
file content (168 lines) | stat: -rw-r--r-- 6,141 bytes parent folder | download | duplicates (3)
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
 /*
 * Fritz!Box plugin for VDR
 *
 * Copyright (C) 2007-2012 Joachim Wilke <vdr@joachim-wilke.de>
 *
 * 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 <vdr/osd.h>
#include <vdr/status.h>
#include "liblog++/Log.h"
#include "notifyosd.h"
#include "setup.h"

bool cNotifyOsd::open = false;

cNotifyOsd::cNotifyOsd(cFritzEventHandler *event) {

	font = cFont::GetFont(fontOsd);
	this->event = event;
	open = true;
	osd = NULL;

	GenerateOsdText();
	lastUpdate = time(NULL);
}

cNotifyOsd::~cNotifyOsd() {
	DBG("closing OSD");
	cStatus::MsgOsdStatusMessage(NULL);
	open = false;
	delete osd;
}

bool cNotifyOsd::GenerateOsdText() {
	std::vector<std::string> lines;
	std::vector<int> ids = event->GetPendingCallIds();
	for (std::vector<int>::iterator it = ids.begin(); it < ids.end(); it++) {
		fritz::sCallInfo callInfo = event->GetCallInfo(*it);
		if (callInfo.localNumber.length() == 0)
			continue;
		cStatus::MsgOsdStatusMessage(event->ComposeCallMessage(*it).c_str());
		event->NotificationDone(*it);
		// 0: separation betwenn multiple calls
		if (it != ids.begin())
			lines.push_back("");
		// 1: In- or Outgoing call? + [medium]
		std::string tmpLine = callInfo.isOutgoing ? tr("Outgoing call") : tr("Incoming call");
		tmpLine += " [" + callInfo.medium;
		if (callInfo.medium.find("ISDN") != std::string::npos)
			tmpLine += " " + callInfo.localNumber;
		tmpLine += "]";
		lines.push_back(tmpLine);
		// 2: remote party (only if information available)
		tmpLine = callInfo.remoteName;
		if (tmpLine.size() > 0)
			lines.push_back(tmpLine);
	}
	if (lines != this->lines) {
		DBG("showing OSD with call information, " << (int) lines.size() << " lines");
		this->lines = lines;
		return true;
	} else
		return false;
}

void cNotifyOsd::Show(void) {
	// osd parameters
	/* whole screen: (OsdLeft, OsdTop) - (OsdLeft+OsdWidth, OsdTop+OsdHeight)
	 * ------------------------------------------------------
	 * |                                                    |
	 * |                                                    |
	 * |                                                    |      border:
	 * |     -(border)-------------------------------       |  =>  (zoomed in)  noOsd
	 * |     |        ^                             |       |      ----------------------------
	 * |     |        ^ (2)                         |       |      |            ^ clrBackground
	 * |     | <(3)> Incoming call   [VoIP 0] <(3)> |       |      |            ^ (1)
	 * |     |        ^                             |       |      |    ----------------------- ...
	 * |     |        ^ (2)                         |       |      |    |       ^ clrForeground
	 * |     |      +491234567890                   |       |      |    |       ^ (1)
	 * |     |        ^                             |       |      |    |    ------------------
	 * |     |        ^ (2)                         |       |      |    |    |    clrBackground
	 * |     ----------------------------------------       |      |    |    |
	 * |                       ^                            |          ...
	 * |                       ^ (4)                        |
	 * ------------------------------------------------------
	 */
	const tColor clrBackground = clrGray50;
	const tColor clrForeground = clrWhite;
	const size_t colorDepth     = 4;
	const size_t borderWidth    = 2;  // (1)
	const size_t lineBuffer     = 10; // (2)
	const size_t cellspacing    = 20; // (3)
	const size_t verticalOffset = 40; // (4)
	const size_t numLines = lines.size();
	// osd dimensions
	unsigned int left, top, width, height;
	// determine osd width
	width = 0;
	for (size_t i=0; i < numLines; i++)
		if (font->Width(lines[i].c_str()) + 2*cellspacing > width)
			width = font->Width(lines[i].c_str()) + 2*cellspacing;
	if (width > ((unsigned int) cOsd::OsdWidth()))
		width = cOsd::OsdWidth();
	height = (font->Height() + lineBuffer) * numLines + 4*borderWidth + lineBuffer;
	// assert alignment
	while (width  % (8/colorDepth) > 0) width++;
	while (height % (8/colorDepth) > 0) height++;
	// center osd
	left = cOsd::OsdLeft() + (cOsd::OsdWidth() - width) / 2;
	top  = cOsd::OsdTop()  + cOsd::OsdHeight() - height - verticalOffset;

	// defines upper left corner of osd
	if (osd)
		delete osd;
	osd = cOsdProvider::NewOsd(left, top);
	// defines drawing area and color depth
	tArea Area = { 0, 0, width-1, height-1, colorDepth };
	osd->SetAreas(&Area, 1);
	// draw osd frame, 2px thick
	osd->DrawRectangle(0,             0,             width-1,               height-1,               clrBackground);
	osd->DrawRectangle(borderWidth,   borderWidth,   width-borderWidth-1,   height-borderWidth-1,   clrForeground);
	osd->DrawRectangle(2*borderWidth, 2*borderWidth, width-2*borderWidth-1, height-2*borderWidth-1, clrBackground);
	// draw text lines
	for (size_t i=0; i < numLines; i++)
		osd->DrawText(cellspacing, 2*borderWidth + lineBuffer + i*(font->Height() + lineBuffer),
				      lines[i].c_str(), clrForeground, clrBackground, font);
	osd->Flush();
}

eOSState cNotifyOsd::ProcessKey(eKeys Key) {
	eOSState state = cOsdObject::ProcessKey(Key);
	if (state == osUnknown)
		switch (Key) {
		case kBack:
			state = osBack;
			break;
		case kNone:
			if (time(NULL) - lastUpdate > Setup.OSDMessageTime) {
				if (event->GetPendingCallIds().size() == 0)
					state = osBack;
				else {
					if (GenerateOsdText()) {
						lastUpdate = time(NULL);
						Show();
					}
				}
			}
		default:
			break;
		}
	return state;
}