• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kdeprint
 

kdeprint

editentrydialog.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 "editentrydialog.h"
00021 
00022 #include <tqlineedit.h>
00023 #include <tqcheckbox.h>
00024 #include <tqspinbox.h>
00025 #include <tqcombobox.h>
00026 #include <tqlabel.h>
00027 #include <tqheader.h>
00028 #include <klistview.h>
00029 #include <tqlayout.h>
00030 #include <tqwidgetstack.h>
00031 #include <klocale.h>
00032 #include <kiconloader.h>
00033 
00034 EditEntryDialog::EditEntryDialog(PrintcapEntry *entry, TQWidget *parent, const char *name)
00035 : KDialogBase(parent, name, true, TQString::null, Ok|Cancel)
00036 {
00037     TQWidget    *w = new TQWidget(this);
00038     setMainWidget(w);
00039 
00040     TQLabel *lab0 = new TQLabel(i18n("Aliases:"), w);
00041     m_aliases = new TQLineEdit(w);
00042     m_view = new KListView(w);
00043     m_view->addColumn("");
00044     m_view->header()->hide();
00045     m_type = new TQComboBox(w);
00046     m_type->insertItem(i18n("String"));
00047     m_type->insertItem(i18n("Number"));
00048     m_type->insertItem(i18n("Boolean"));
00049     m_stack = new TQWidgetStack(w);
00050     m_boolean = new TQCheckBox(i18n("Enabled"), m_stack);
00051     m_string = new TQLineEdit(m_stack);
00052     m_number = new TQSpinBox(0, 9999, 1, m_stack);
00053     m_stack->addWidget(m_string, 0);
00054     m_stack->addWidget(m_boolean, 2);
00055     m_stack->addWidget(m_number, 1);
00056     m_name = new TQLineEdit(w);
00057 
00058     TQVBoxLayout    *l0 = new TQVBoxLayout(w, 0, 10);
00059     TQHBoxLayout    *l1 = new TQHBoxLayout(0, 0, 10);
00060     TQHBoxLayout    *l2 = new TQHBoxLayout(0, 0, 5);
00061     l0->addLayout(l1);
00062     l1->addWidget(lab0);
00063     l1->addWidget(m_aliases);
00064     l0->addWidget(m_view);
00065     l0->addLayout(l2);
00066     l2->addWidget(m_name, 0);
00067     l2->addWidget(m_type, 0);
00068     l2->addWidget(m_stack, 1);
00069 
00070     if (entry)
00071     {
00072         setCaption(i18n("Printcap Entry: %1").arg(entry->name));
00073         m_fields = entry->fields;
00074         m_aliases->setText(entry->aliases.join("|"));
00075         TQListViewItem  *root = new TQListViewItem(m_view, entry->name), *item = 0;
00076         root->setSelectable(false);
00077         root->setOpen(true);
00078         root->setPixmap(0, SmallIcon("fileprint"));
00079         for (TQMap<TQString,Field>::ConstIterator it=m_fields.begin(); it!=m_fields.end(); ++it)
00080             item = new TQListViewItem(root, item, (*it).toString(), it.key());
00081     }
00082 
00083     m_block = true;
00084     enableButton(Ok, false);
00085     slotItemSelected(NULL);
00086     slotTypeChanged(0);
00087     m_block = false;
00088 
00089     connect(m_view, TQT_SIGNAL(selectionChanged(TQListViewItem*)), TQT_SLOT(slotItemSelected(TQListViewItem*)));
00090     connect(m_string, TQT_SIGNAL(textChanged(const TQString&)), TQT_SLOT(slotChanged()));
00091     connect(m_boolean, TQT_SIGNAL(toggled(bool)), TQT_SLOT(slotChanged()));
00092     connect(m_number, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(slotChanged()));
00093     connect(m_type, TQT_SIGNAL(activated(int)), TQT_SLOT(slotTypeChanged(int)));
00094     connect(m_name, TQT_SIGNAL(textChanged(const TQString&)), TQT_SLOT(slotChanged()));
00095 
00096     resize(500,400);
00097 }
00098 
00099 Field EditEntryDialog::createField()
00100 {
00101     Field   f;
00102     f.name = m_name->text();
00103     f.type = (Field::Type)(m_type->currentItem());
00104     switch (f.type)
00105     {
00106         case Field::String: f.value = m_string->text(); break;
00107         case Field::Integer: f.value = m_number->cleanText(); break;
00108         case Field::Boolean: f.value = (m_boolean->isChecked() ? "1" : "0"); break;
00109     }
00110     return f;
00111 }
00112 
00113 void EditEntryDialog::slotChanged()
00114 {
00115     if (!m_block && m_view->currentItem())
00116     {
00117         Field   f = createField();
00118         if (f.name != m_current)
00119             m_fields.remove(m_current);
00120         m_fields[f.name] = f;
00121         m_view->currentItem()->setText(0, f.toString());
00122     }
00123 }
00124 
00125 void EditEntryDialog::slotItemSelected(TQListViewItem *item)
00126 {
00127     m_stack->setEnabled(item);
00128     m_name->setEnabled(item);
00129     m_type->setEnabled(item);
00130     if (item)
00131     {
00132         m_block = true;
00133         m_current = item->text(1);
00134         Field   f = m_fields[m_current];
00135         m_name->setText(f.name);
00136         m_type->setCurrentItem(f.type);
00137         slotTypeChanged(f.type);
00138         m_string->setText(f.value);
00139         m_number->setValue(f.value.toInt());
00140         m_boolean->setChecked(f.value.toInt() == 1);
00141         m_block = false;
00142     }
00143 }
00144 
00145 void EditEntryDialog::fillEntry(PrintcapEntry *entry)
00146 {
00147     entry->aliases = TQStringList::split('|', m_aliases->text(), false);
00148     entry->fields = m_fields;
00149 }
00150 
00151 void EditEntryDialog::slotTypeChanged(int ID)
00152 {
00153     m_stack->raiseWidget(ID);
00154     slotChanged();
00155 }
00156 
00157 #include "editentrydialog.moc"

kdeprint

Skip menu "kdeprint"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kdeprint

Skip menu "kdeprint"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdeprint by doxygen 1.7.6.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |