plugincombobox.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 "plugincombobox.h" 00021 #include "kmfactory.h" 00022 #include "kmmanager.h" 00023 00024 #include <tqcombobox.h> 00025 #include <tqlabel.h> 00026 #include <tqlayout.h> 00027 #include <tdelocale.h> 00028 #include <tqwhatsthis.h> 00029 00030 PluginComboBox::PluginComboBox(TQWidget *parent, const char *name) 00031 :TQWidget(parent, name) 00032 { 00033 TQString whatsThisCurrentPrintsystem = i18n(" <qt><b>Print Subsystem Selection</b>" 00034 " <p>This combo box shows (and lets you select)" 00035 " a print subsystem to be used by TDEPrint. (This print" 00036 " subsystem must, of course, be installed inside your" 00037 " Operating System.) TDEPrint usually auto-detects the" 00038 " correct print subsystem by itself upon first startup." 00039 " Most Linux distributions have \"CUPS\", the <em>Common" 00040 " UNIX Printing System</em>." 00041 " </qt>" ); 00042 00043 m_combo = new TQComboBox(this, "PluginCombo"); 00044 TQWhatsThis::add(m_combo, whatsThisCurrentPrintsystem); 00045 TQLabel *m_label = new TQLabel(i18n("Print s&ystem currently used:"), this); 00046 TQWhatsThis::add(m_label, whatsThisCurrentPrintsystem); 00047 m_label->setAlignment(AlignVCenter|AlignRight); 00048 m_label->setBuddy(m_combo); 00049 m_plugininfo = new TQLabel("Plugin information", this); 00050 TQGridLayout *l0 = new TQGridLayout(this, 2, 2, 0, 5); 00051 l0->setColStretch(0, 1); 00052 l0->addWidget(m_label, 0, 0); 00053 l0->addWidget(m_combo, 0, 1); 00054 l0->addWidget(m_plugininfo, 1, 1); 00055 00056 TQValueList<KMFactory::PluginInfo> list = KMFactory::self()->pluginList(); 00057 TQString currentPlugin = KMFactory::self()->printSystem(); 00058 for (TQValueList<KMFactory::PluginInfo>::ConstIterator it=list.begin(); it!=list.end(); ++it) 00059 { 00060 m_combo->insertItem((*it).comment); 00061 if ((*it).name == currentPlugin) 00062 m_combo->setCurrentItem(m_combo->count()-1); 00063 m_pluginlist.append((*it).name); 00064 } 00065 00066 connect(m_combo, TQT_SIGNAL(activated(int)), TQT_SLOT(slotActivated(int))); 00067 configChanged(); 00068 } 00069 00070 void PluginComboBox::slotActivated(int index) 00071 { 00072 TQString plugin = m_pluginlist[index]; 00073 if (!plugin.isEmpty()) 00074 { 00075 // the factory will notify all registered objects of the change 00076 KMFactory::self()->reload(plugin, true); 00077 } 00078 } 00079 00080 void PluginComboBox::reload() 00081 { 00082 TQString syst = KMFactory::self()->printSystem(); 00083 int index(-1); 00084 if ((index=m_pluginlist.findIndex(syst)) != -1) 00085 m_combo->setCurrentItem(index); 00086 configChanged(); 00087 } 00088 00089 void PluginComboBox::configChanged() 00090 { 00091 TQString whatsThisCurrentConnection = i18n(" <qt><b>Current Connection</b>" 00092 " <p>This line shows which CUPS server your PC is" 00093 " currently connected to for printing and retrieving" 00094 " printer info. To switch to a different CUPS server," 00095 " click \"System Options\", then select \"Cups server\"" 00096 " and fill in the required info." 00097 " </qt>" ); 00098 00099 m_plugininfo->setText(KMManager::self()->stateInformation()); 00100 TQWhatsThis::add(m_plugininfo, whatsThisCurrentConnection); 00101 00102 } 00103 00104 #include "plugincombobox.moc"