jobitem.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., 51 Franklin Street, Fifth Floor,
00017  *  Boston, MA 02110-1301, USA.
00018  **/
00019 
00020 #include "jobitem.h"
00021 #include "kmjob.h"
00022 
00023 #include <kiconloader.h>
00024 
00025 JobItem::JobItem(QListView *parent, KMJob *job)
00026 : QListViewItem(parent)
00027 {
00028     m_job = new KMJob;
00029     init(job);
00030 }
00031 
00032 JobItem::~JobItem()
00033 {
00034     delete m_job;
00035 }
00036 
00037 void JobItem::init(KMJob *job)
00038 {
00039     m_job->copy(job ? *job : KMJob());
00040 
00041     setPixmap(0,SmallIcon(m_job->pixmap()));
00042     setText(0,QString::number(m_job->id()));
00043     //setText(6,m_job->printer());
00044     setText(2,m_job->name());
00045     setText(1,m_job->owner());
00046     setText(3,m_job->stateString());
00047     setText(4,QString::number(m_job->size()));
00048     setText(5,QString::number(m_job->processedPages()));
00049     m_ID = m_job->id();
00050     m_uri = m_job->uri();
00051 
00052     // additional attributes
00053     for (int i=0; i<m_job->attributeCount(); i++)
00054         setText(6+i, m_job->attribute(i));
00055 
00056     widthChanged();
00057 }
00058 
00059 int JobItem::compare(QListViewItem *item, int col, bool asc) const
00060 {
00061     switch (col)
00062     {
00063         case 0:
00064         case 4:
00065         case 5:
00066             {
00067                 int i1(this->text(col).toInt()), i2(item->text(col).toInt());
00068                 return (i1 < i2 ? -1 : (i1 > i2 ? 1 : 0));
00069                 break;
00070             }
00071         default:
00072             return QListViewItem::compare(item, col, asc);
00073     }
00074 }
KDE Home | KDE Accessibility Home | Description of Access Keys