printerfilter.cpp
00001 /* 00002 * This file is part of the KDE libraries 00003 * Copyright (c) 2001 Michael Goffioul <tdeprint@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 "printerfilter.h" 00021 #include "kmprinter.h" 00022 #include "kmfactory.h" 00023 00024 #include <tdeconfig.h> 00025 #include <tdeglobal.h> 00026 #include <kdebug.h> 00027 00028 PrinterFilter::PrinterFilter(TQObject *parent, const char *name) 00029 : TQObject(parent, name) 00030 { 00031 m_locationRe.setWildcard(true); 00032 update(); 00033 } 00034 00035 PrinterFilter::~PrinterFilter() 00036 { 00037 } 00038 00039 void PrinterFilter::update() 00040 { 00041 TDEConfig *conf = KMFactory::self()->printConfig(); 00042 conf->setGroup("Filter"); 00043 m_locationRe.setPattern(conf->readEntry("LocationRe")); 00044 m_printers = conf->readListEntry("Printers"); 00045 // filter enable state is saved on a per application basis, 00046 // so this option is retrieve from the application config file 00047 conf = TDEGlobal::config(); 00048 conf->setGroup("KPrinter Settings"); 00049 m_enabled = conf->readBoolEntry("FilterEnabled", false); 00050 } 00051 00052 void PrinterFilter::setEnabled(bool on) 00053 { 00054 m_enabled = on; 00055 TDEConfig *conf = TDEGlobal::config(); 00056 conf->setGroup("KPrinter Settings"); 00057 conf->writeEntry("FilterEnabled", m_enabled); 00058 } 00059 00060 bool PrinterFilter::filter(KMPrinter *prt) 00061 { 00062 if (m_enabled) 00063 { 00064 if ((!m_locationRe.isEmpty() && m_locationRe.exactMatch(prt->location())) || 00065 m_printers.find(prt->printerName()) != m_printers.end()) 00066 return true; 00067 else 00068 return false; 00069 } 00070 return true; 00071 }