summaryrefslogtreecommitdiffstats
path: root/kdeprint/management/kminfopage.cpp
blob: 4366265ab33f9ecd5bfe3ecf02160fa33f89cd18 (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
/*
 *  This file is part of the KDE libraries
 *  Copyright (c) 2001 Michael Goffioul <[email protected]>
 *
 *  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 "kminfopage.h"
#include "kmprinter.h"

#include <qpixmap.h>
#include <qlabel.h>
#include <qlayout.h>
#include <klocale.h>
#include <kiconloader.h>
#include <kseparator.h>

KMInfoPage::KMInfoPage(QWidget *parent, const char *name)
: QWidget(parent,name)
{
	m_title = new QLabel(this);
	m_titlepixmap = new QLabel(this);
	m_titlepixmap->setAlignment(Qt::AlignCenter);
        KSeparator* sep = new KSeparator( KSeparator::HLine, this);
	m_type = new QLabel(this);
	m_description = new QLabel(this);
	m_state = new QLabel(this);
	m_location = new QLabel(this);
	m_model = new QLabel(this);
	m_uri = new QLabel(this);
	m_device = new QLabel(this);
	QLabel	*m_loclabel = new QLabel(i18n("Physical Location", "Location:"), this);
	m_loclabel->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
	QLabel	*m_desclabel = new QLabel(i18n("Description:"), this);
	m_desclabel->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
	QLabel	*m_typelabel = new QLabel(i18n("Type:"), this);
	m_typelabel->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
	QLabel	*m_statelabel = new QLabel(i18n("Status", "State:"), this);
	m_statelabel->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
	QLabel	*m_urilabel = new QLabel(i18n("URI:"), this);
	m_urilabel->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
	m_devlabel = new QLabel(i18n("Device:"), this);
	m_devlabel->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
	QLabel	*m_modellabel = new QLabel(i18n("Model:"), this);
	m_modellabel->setAlignment(Qt::AlignRight|Qt::AlignVCenter);

	QGridLayout	*lay0 = new QGridLayout(this, 11, 2, 0, 5);
	QHBoxLayout	*lay1 = new QHBoxLayout(0, 0, 10);
	lay0->addRowSpacing(7,20);
	lay0->setRowStretch(7,0);
	lay0->setRowStretch(10,1);
	lay0->setColStretch(1,1);
	lay0->addMultiCellLayout(lay1, 0, 0, 0, 1);
	lay0->addMultiCellWidget(sep, 1, 1, 0, 1);
	lay0->addWidget(m_typelabel, 2, 0);
	lay0->addWidget(m_statelabel, 3, 0);
	lay0->addWidget(m_loclabel, 4, 0);
	lay0->addWidget(m_desclabel, 5, 0);
	lay0->addWidget(m_urilabel, 6, 0);
	lay0->addWidget(m_devlabel, 8, 0);
	lay0->addWidget(m_modellabel, 9, 0);
	lay0->addWidget(m_type, 2, 1);
	lay0->addWidget(m_state, 3, 1);
	lay0->addWidget(m_location, 4, 1);
	lay0->addWidget(m_description, 5, 1);
	lay0->addWidget(m_uri, 6, 1);
	lay0->addWidget(m_device, 8, 1);
	lay0->addWidget(m_model, 9, 1);
	lay1->addWidget(m_title, 1);
	lay1->addWidget(m_titlepixmap, 0);
}

KMInfoPage::~KMInfoPage()
{
}

void KMInfoPage::setPrinter(KMPrinter *p)
{
	// change "Device" label if it's a real class (not true for implicit classes)
	if (p && p->isClass(false)) m_devlabel->setText(i18n("Members:"));
	else m_devlabel->setText(i18n("Device:"));

	// clear everything if p == 0
	if (!p)
	{
		m_title->setText(QString::null);
		m_titlepixmap->setPixmap(QPixmap());
		m_type->setText(QString::null);
		m_state->setText(QString::null);
		m_location->setText(QString::null);
		m_description->setText(QString::null);
		m_uri->setText(QString::null);
		m_device->setText(QString::null);
		m_model->setText(QString::null);
	}
	else
	{
		m_title->setText(QString::fromLatin1("<b>%1</b>").arg(p->name()));
		m_titlepixmap->setPixmap(SmallIcon(p->pixmap()));
		if (p->isImplicit()) m_type->setText(i18n("Implicit class"));
		else if (p->isClass(false))
			if (p->isRemote()) m_type->setText(i18n("Remote class"));
			else m_type->setText(i18n("Local class"));
		else if (p->isPrinter())
			if (p->isRemote()) m_type->setText(i18n("Remote printer"));
			else m_type->setText(i18n("Local printer"));
		else if (p->isSpecial())
			m_type->setText(i18n("Special (pseudo) printer"));
		else m_type->setText(i18n("Unknown class of printer", "Unknown"));
		m_state->setText(p->stateString());
		m_location->setText(p->location());
		m_description->setText(p->description());
		m_uri->setText(p->uri().prettyURL());
		if (p->isClass(false))
		{
			QString	s;
			for (QStringList::ConstIterator it=p->members().begin(); it!=p->members().end(); ++it)
				s.append(KURL(*it).prettyURL() + ", ");
			s.truncate(s.length()-2);
			m_device->setText(s);
		}
		else
		{
			// double decoding in case printer name contains
			// annoying chars like '#'
                        KURL dev(p->device());
			m_device->setText(KURL::decode_string(dev.prettyURL()));
		}
		m_model->setText(p->driverInfo());
	}
}