00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kmwbanners.h"
00021 #include "kmwizard.h"
00022 #include "kmprinter.h"
00023 #include "kmfactory.h"
00024 #include "kmmanager.h"
00025
00026 #include <qcombobox.h>
00027 #include <qlabel.h>
00028 #include <qlayout.h>
00029 #include <qmap.h>
00030 #include <klocale.h>
00031
00032 QStringList defaultBanners()
00033 {
00034 QStringList bans;
00035 QPtrList<KMPrinter> *list = KMFactory::self()->manager()->printerList(false);
00036 if (list && list->count() > 0)
00037 {
00038 QPtrListIterator<KMPrinter> it(*list);
00039 for (;it.current() && !it.current()->isPrinter(); ++it) ;
00040 if (it.current() && KMFactory::self()->manager()->completePrinter(it.current()))
00041 {
00042 QString s = list->getFirst()->option("kde-banners-supported");
00043 bans = QStringList::split(',',s,false);
00044 }
00045 }
00046 if (bans.count() == 0)
00047 bans.append("none");
00048 return bans;
00049 }
00050
00051 static struct
00052 {
00053 const char *banner;
00054 const char *name;
00055 } bannermap[] =
00056 {
00057 { "none", I18N_NOOP( "No Banner" ) },
00058 { "classified", I18N_NOOP( "Classified" ) },
00059 { "confidential", I18N_NOOP( "Confidential" ) },
00060 { "secret", I18N_NOOP( "Secret" ) },
00061 { "standard", I18N_NOOP( "Standard" ) },
00062 { "topsecret", I18N_NOOP( "Top Secret" ) },
00063 { "unclassified", I18N_NOOP( "Unclassified" ) },
00064 { 0, 0 }
00065 };
00066
00067 QString mapBanner( const QString& ban )
00068 {
00069 static QMap<QString,QString> map;
00070 if ( map.size() == 0 )
00071 for ( int i=0; bannermap[ i ].banner; i++ )
00072 map[ bannermap[ i ].banner ] = bannermap[ i ].name;
00073 QMap<QString,QString>::ConstIterator it = map.find( ban );
00074 if ( it == map.end() )
00075 return ban;
00076 else
00077 return it.data();
00078 }
00079
00080
00081
00082 KMWBanners::KMWBanners(QWidget *parent, const char *name)
00083 : KMWizardPage(parent,name)
00084 {
00085 m_ID = KMWizard::Banners;
00086 m_title = i18n("Banner Selection");
00087 m_nextpage = KMWizard::Custom+3;
00088
00089 m_start = new QComboBox(this);
00090 m_end = new QComboBox(this);
00091
00092 QLabel *l1 = new QLabel(i18n("&Starting banner:"),this);
00093 QLabel *l2 = new QLabel(i18n("&Ending banner:"),this);
00094
00095 l1->setBuddy(m_start);
00096 l2->setBuddy(m_end);
00097
00098 QLabel *l0 = new QLabel(this);
00099 l0->setText(i18n("<p>Select the default banners associated with this printer. These "
00100 "banners will be inserted before and/or after each print job sent "
00101 "to the printer. If you don't want to use banners, select <b>No Banner</b>.</p>"));
00102
00103 QGridLayout *lay = new QGridLayout(this, 5, 2, 0, 10);
00104 lay->setColStretch(1,1);
00105 lay->addRowSpacing(1,20);
00106 lay->setRowStretch(4,1);
00107 lay->addMultiCellWidget(l0,0,0,0,1);
00108 lay->addWidget(l1,2,0);
00109 lay->addWidget(l2,3,0);
00110 lay->addWidget(m_start,2,1);
00111 lay->addWidget(m_end,3,1);
00112 }
00113
00114 void KMWBanners::initPrinter(KMPrinter *p)
00115 {
00116 if (p)
00117 {
00118 if (m_start->count() == 0)
00119 {
00120 m_bans = QStringList::split(',',p->option("kde-banners-supported"),false);
00121 if (m_bans.count() == 0)
00122 m_bans = defaultBanners();
00123 if (m_bans.find("none") == m_bans.end())
00124 m_bans.prepend("none");
00125 for ( QStringList::Iterator it=m_bans.begin(); it!=m_bans.end(); ++it )
00126 {
00127 m_start->insertItem( i18n( mapBanner(*it).utf8() ) );
00128 m_end->insertItem( i18n( mapBanner(*it).utf8() ) );
00129 }
00130 }
00131 QStringList l = QStringList::split(',',p->option("kde-banners"),false);
00132 while (l.count() < 2)
00133 l.append("none");
00134 m_start->setCurrentItem(m_bans.findIndex(l[0]));
00135 m_end->setCurrentItem(m_bans.findIndex(l[1]));
00136 }
00137 }
00138
00139 void KMWBanners::updatePrinter(KMPrinter *p)
00140 {
00141 if (m_start->count() > 0)
00142 {
00143 p->setOption("kde-banners",m_bans[m_start->currentItem()]+","+m_bans[m_end->currentItem()]);
00144 }
00145 }