# kdeprint Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# kmwclass.cpp

    00001 /*
    00002  *  This file is part of the KDE libraries
    00003  *  Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
    00004  *
    00005  *  This library is free software; you can redistribute it and/or
    00006  *  modify it under the terms of the GNU Library General Public
    00007  *  License version 2 as published by the Free Software Foundation.
    00008  *
    00009  *  This library is distributed in the hope that it will be useful,
    00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00012  *  Library General Public License for more details.
    00013  *
    00014  *  You should have received a copy of the GNU Library General Public License
    00015  *  along with this library; see the file COPYING.LIB.  If not, write to
    00016  *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00017  *  Boston, MA 02111-1307, USA.
    00018  **/
    00019
    00020 #include "kmwclass.h"
    00021 #include "kmwizard.h"
    00022 #include "kmfactory.h"
    00023 #include "kmmanager.h"
    00024 #include "kmprinter.h"
    00025
    00026 #include <qlayout.h>
    00027 #include <qlabel.h>
    00028 #include <qtoolbutton.h>
    00029 #include <klistbox.h>
    00030 #include <klocale.h>
    00031 #include <kiconloader.h>
    00032
    00033 KMWClass::KMWClass(QWidget *parent, const char *name)
    00034 : KMWizardPage(parent,name)
    00035 {
    00036     m_ID = KMWizard::Class;
    00037     m_title = i18n("Class Composition");
    00038     m_nextpage = KMWizard::Name;
    00039
    00040     m_list1 = new KListBox(this);
    00041     m_list1->setSelectionMode(QListBox::Extended);
    00042     m_list2 = new KListBox(this);
    00043     m_list2->setSelectionMode(QListBox::Extended);
    00044
    00045     QToolButton *add = new QToolButton(this);
    00046     QToolButton *remove = new QToolButton(this);
    00047     add->setIconSet(BarIcon("forward"));
    00048     remove->setIconSet(BarIcon("back"));
    00049     connect(add,SIGNAL(clicked()),SLOT(slotAdd()));
    00050     connect(remove,SIGNAL(clicked()),SLOT(slotRemove()));
    00051
    00052     QLabel  *l1 = new QLabel(i18n("Available printers:"), this);
    00053     QLabel  *l2 = new QLabel(i18n("Class printers:"), this);
    00054
    00055         QHBoxLayout *lay1 = new QHBoxLayout(this, 0, 15);
    00056         QVBoxLayout *lay2 = new QVBoxLayout(0, 0, 20);
    00057         QVBoxLayout *lay3 = new QVBoxLayout(0, 0, 0), *lay4 = new QVBoxLayout(0, 0, 0);
    00058         lay1->addLayout(lay3, 1);
    00059         lay1->addLayout(lay2, 0);
    00060     lay1->addLayout(lay4, 1);
    00061         lay3->addWidget(l1, 0);
    00062         lay3->addWidget(m_list1, 1);
    00063         lay2->addStretch(1);
    00064         lay2->addWidget(add, 0);
    00065         lay2->addWidget(remove, 0);
    00066         lay2->addStretch(1);
    00067         lay4->addWidget(l2, 0);
    00068         lay4->addWidget(m_list2, 1);
    00069 }
    00070
    00071 KMWClass::~KMWClass()
    00072 {
    00073 }
    00074
    00075 bool KMWClass::isValid(QString& msg)
    00076 {
    00077     if (m_list2->count() == 0)
    00078     {
    00079         msg = i18n("You must select at least one printer.");
    00080         return false;
    00081     }
    00082     return true;
    00083 }
    00084
    00085 void KMWClass::initPrinter(KMPrinter *p)
    00086 {
    00087     QStringList members = p->members();
    00088     KMManager   *mgr = KMFactory::self()->manager();
    00089
    00090     // first load available printers
    00091     QPtrList<KMPrinter> *list = mgr->printerList(false);
    00092     m_list1->clear();
    00093     if (list)
    00094     {
    00095         QPtrListIterator<KMPrinter> it(*list);
    00096         for (;it.current();++it)
    00097             if (it.current()->instanceName().isEmpty() && !it.current()->isClass(true) && !it.current()->isSpecial() && !members.contains(it.current()->name()))
    00098                 m_list1->insertItem(SmallIcon(it.current()->pixmap()), it.current()->name());
    00099         m_list1->sort();
    00100     }
    00101
    00102     // set class printers
    00103     m_list2->clear();
    00104     for (QStringList::ConstIterator it=members.begin(); it!=members.end(); ++it)
    00105     {
    00106         KMPrinter   *pr = mgr->findPrinter(*it);
    00107         if (pr) m_list2->insertItem(SmallIcon(pr->pixmap()), *it);
    00108     }
    00109     m_list2->sort();
    00110 }
    00111
    00112 void KMWClass::updatePrinter(KMPrinter *p)
    00113 {
    00114     QStringList members;
    00115     for (uint i=0; i<m_list2->count(); i++)
    00116         members.append(m_list2->item(i)->text());
    00117     p->setMembers(members);
    00118 }
    00119
    00120 void KMWClass::slotAdd()
    00121 {
    00122     for (uint i=0;i<m_list1->count();i++)
    00123         if (m_list1->isSelected(i))
    00124         {
    00125             m_list2->insertItem(*(m_list1->pixmap(i)), m_list1->text(i));
    00126             m_list1->removeItem(i--);
    00127         }
    00128     m_list2->sort();
    00129 }
    00130
    00131 void KMWClass::slotRemove()
    00132 {
    00133     for (uint i=0;i<m_list2->count();i++)
    00134         if (m_list2->isSelected(i))
    00135         {
    00136             m_list1->insertItem(*(m_list2->pixmap(i)), m_list2->text(i));
    00137             m_list2->removeItem(i--);
    00138         }
    00139     m_list1->sort();
    00140 }
    00141 #include "kmwclass.moc"

This file is part of the documentation for kdeprint Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:31:03 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003