File: mailboxmenu.cc

package info (click to toggle)
bbmail 0.8.3-7
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 784 kB
  • sloc: cpp: 7,307; sh: 3,506; makefile: 83; perl: 26
file content (137 lines) | stat: -rw-r--r-- 3,672 bytes parent folder | download | duplicates (5)
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
// mailboxmenu.cc for bbmail - an tool for display the mail in X11.
//
//  Copyright (c) 1998-2000 by John Kennis, jkennis@chello.nl
//
//  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., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// (See the included file COPYING / GPL-2.0)
//
#include "mailboxmenu.hh"

Mailboxmenu::Mailboxmenu(ToolWindow *toolwindow) :
		Basemenu(toolwindow)
{
	int i;
	bbtool=toolwindow;

	setTitleVisibility(False);
	setMovable(False);
	setHidable(False);
	setAlignment(AlignBottom);
	defaultMenu();

	word_length = new int [bbtool->getResource()->report.number_of_spoolfiles];
	for (i=0;i<bbtool->getResource()->report.number_of_spoolfiles;i++) {
		insert(&bbtool->getResource()->spoolfile[i].name);
		word_length[i]=strlen(bbtool->getResource()->spoolfile[i].name);
	}
	insert("Reconfigure");
	insert("Close");
}


Mailboxmenu::~Mailboxmenu(void)
{
	delete [] word_length;
}

void Mailboxmenu::ClearMenu()
{
	int i;

	for (i=0;i<=bbtool->getResource()->report.number_of_spoolfiles;i++)
		remove(0);
	remove(0);
	remove(0);
	delete [] word_length;
}

void Mailboxmenu::Reconfigure()
{
	int i;

	word_length = new int [bbtool->getResource()->report.number_of_spoolfiles];
	for (i=0;i<bbtool->getResource()->report.number_of_spoolfiles;i++) {
		insert(&bbtool->getResource()->spoolfile[i].name);
		word_length[i]=strlen(bbtool->getResource()->spoolfile[i].name);
	}
	insert("Reconfigure");
	insert("Close");
	Basemenu::reconfigure();
}


void Mailboxmenu::Move(int x, int y, bool withdrawn)
{
	if (!withdrawn) {
		int y_old=y;
		y= y - getHeight() -1;
		if ((x+getWidth())>bbtool->getCurrentScreenInfo()->getWidth())
			x=bbtool->getCurrentScreenInfo()->getWidth()-getWidth();
		if (y<0)
			y=y_old+bbtool->Frame().height;
		Basemenu::move(x, y);
	} else {
		x= x - getWidth() - 6;
		if (x<0)
			x=x + getWidth() + 12;
		if (y<0)
			y=0;
		if (y+getHeight()>bbtool->getCurrentScreenInfo()->getHeight())
			y=bbtool->getCurrentScreenInfo()->getHeight()-getHeight();
		Basemenu::move(x, y);
	}
}

/* quick and dirty */
void Mailboxmenu::UpdateNumbers(int newmail, int totalmail,int spoolno)
{
	char dummy[15];

	bbtool->getResource()->spoolfile[spoolno].name[word_length[spoolno]]='\0';
	sprintf(dummy," (%u/%u)",newmail,totalmail);
	strcat(bbtool->getResource()->spoolfile[spoolno].name,dummy);
	if (newmail>0)
		setHighlight(spoolno);
	Basemenu::reconfigure();
}

void Mailboxmenu::Update()
{
	wait_for_update=False;
	Basemenu::update();
}

void Mailboxmenu::itemSelected(int button, int index)
{
	if (button == 1) {
		if (index < bbtool->getResource()->report.number_of_spoolfiles) {
			system(bbtool->getResource()->spoolfile[index].runCommand);
		} else if (index == bbtool->getResource()->report.number_of_spoolfiles) {
			bbtool->reconfigure();
		} else if (index == bbtool->getResource()->report.number_of_spoolfiles+1) {
			bbtool->shutdown();
		}
		hide();
		bbtool->EnvelopePushed(False);
		bbtool->Redraw(False);
	}
}

void Mailboxmenu::show(void)
{
	XRaiseWindow(bbtool->getXDisplay(), getWindowID());
	Basemenu::show();
}