summaryrefslogtreecommitdiffstats
path: root/kdeprint/cups/kmwbanners.cpp
blob: c221f69d7741e4bf1b83d49dbd36c12aad745ece (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
/*
 *  This file is part of the KDE libraries
 *  Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License version 2 as published by the Free Software Foundation.
 *
 *  This library 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
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public License
 *  along with this library; see the file COPYING.LIB.  If not, write to
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301, USA.
 **/

#include "kmwbanners.h"
#include "kmwizard.h"
#include "kmprinter.h"
#include "kmfactory.h"
#include "kmmanager.h"

#include <tqcombobox.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqmap.h>
#include <klocale.h>

TQStringList defaultBanners()
{
	TQStringList	bans;
	TQPtrList<KMPrinter>	*list = KMFactory::self()->manager()->printerList(false);
	if (list && list->count() > 0)
	{
		TQPtrListIterator<KMPrinter>	it(*list);
		for (;it.current() && !it.current()->isPrinter(); ++it) ;
		if (it.current() && KMFactory::self()->manager()->completePrinter(it.current()))
		{
			TQString	s = list->getFirst()->option("kde-banners-supported");
			bans = TQStringList::split(',',s,false);
		}
	}
	if (bans.count() == 0)
		bans.append("none");
	return bans;
}

static struct
{
	const char *banner;
	const char *name;
} bannermap[] =
{
	{ "none", I18N_NOOP( "No Banner" ) },
	{ "classified", I18N_NOOP( "Classified" ) },
	{ "confidential", I18N_NOOP( "Confidential" ) },
	{ "secret", I18N_NOOP( "Secret" ) },
	{ "standard", I18N_NOOP( "Standard" ) },
	{ "topsecret", I18N_NOOP( "Top Secret" ) },
	{ "unclassified", I18N_NOOP( "Unclassified" ) },
	{ 0, 0 }
};

TQString mapBanner( const TQString& ban )
{
	static TQMap<TQString,TQString> map;
	if ( map.size() == 0 )
		for ( int i=0; bannermap[ i ].banner; i++ )
			map[ bannermap[ i ].banner ] = bannermap[ i ].name;
	TQMap<TQString,TQString>::ConstIterator it = map.find( ban );
	if ( it == map.end() )
		return ban;
	else
		return it.data();
}

//**************************************************************************************************************

KMWBanners::KMWBanners(TQWidget *parent, const char *name)
: KMWizardPage(parent,name)
{
	m_ID = KMWizard::Banners;
	m_title = i18n("Banner Selection");
	m_nextpage = KMWizard::Custom+3;

	m_start = new TQComboBox(this);
	m_end = new TQComboBox(this);

	TQLabel	*l1 = new TQLabel(i18n("&Starting banner:"),this);
	TQLabel	*l2 = new TQLabel(i18n("&Ending banner:"),this);

	l1->setBuddy(m_start);
	l2->setBuddy(m_end);

	TQLabel	*l0 = new TQLabel(this);
	l0->setText(i18n("<p>Select the default banners associated with this printer. These "
			 "banners will be inserted before and/or after each print job sent "
			 "to the printer. If you don't want to use banners, select <b>No Banner</b>.</p>"));

	TQGridLayout	*lay = new TQGridLayout(this, 5, 2, 0, 10);
	lay->setColStretch(1,1);
	lay->addRowSpacing(1,20);
	lay->setRowStretch(4,1);
	lay->addMultiCellWidget(l0,0,0,0,1);
	lay->addWidget(l1,2,0);
	lay->addWidget(l2,3,0);
	lay->addWidget(m_start,2,1);
	lay->addWidget(m_end,3,1);
}

void KMWBanners::initPrinter(KMPrinter *p)
{
	if (p)
	{
		if (m_start->count() == 0)
		{
			m_bans = TQStringList::split(',',p->option("kde-banners-supported"),false);
			if (m_bans.count() == 0)
				m_bans = defaultBanners();
			if (m_bans.find("none") == m_bans.end())
				m_bans.prepend("none");
			for ( TQStringList::Iterator it=m_bans.begin(); it!=m_bans.end(); ++it )
			{
				m_start->insertItem( i18n( mapBanner(*it).utf8() ) );
				m_end->insertItem( i18n( mapBanner(*it).utf8() ) );
			}
		}
		TQStringList	l = TQStringList::split(',',p->option("kde-banners"),false);
		while (l.count() < 2)
			l.append("none");
		m_start->setCurrentItem(m_bans.findIndex(l[0]));
		m_end->setCurrentItem(m_bans.findIndex(l[1]));
	}
}

void KMWBanners::updatePrinter(KMPrinter *p)
{
	if (m_start->count() > 0)
	{
		p->setOption("kde-banners",m_bans[m_start->currentItem()]+","+m_bans[m_end->currentItem()]);
	}
}