20 #include "editentrydialog.h"
22 #include <tqlineedit.h>
23 #include <tqcheckbox.h>
24 #include <tqspinbox.h>
25 #include <tqcombobox.h>
28 #include <tdelistview.h>
30 #include <tqwidgetstack.h>
31 #include <tdelocale.h>
32 #include <kiconloader.h>
34 EditEntryDialog::EditEntryDialog(PrintcapEntry *entry, TQWidget *parent,
const char *name)
35 : KDialogBase(parent, name, true, TQString::null, Ok|Cancel)
37 TQWidget *w =
new TQWidget(
this);
40 TQLabel *lab0 =
new TQLabel(i18n(
"Aliases:"), w);
41 m_aliases =
new TQLineEdit(w);
42 m_view =
new TDEListView(w);
43 m_view->addColumn(
"");
44 m_view->header()->hide();
45 m_type =
new TQComboBox(w);
46 m_type->insertItem(i18n(
"String"));
47 m_type->insertItem(i18n(
"Number"));
48 m_type->insertItem(i18n(
"Boolean"));
49 m_stack =
new TQWidgetStack(w);
50 m_boolean =
new TQCheckBox(i18n(
"Enabled"), m_stack);
51 m_string =
new TQLineEdit(m_stack);
52 m_number =
new TQSpinBox(0, 9999, 1, m_stack);
53 m_stack->addWidget(m_string, 0);
54 m_stack->addWidget(m_boolean, 2);
55 m_stack->addWidget(m_number, 1);
56 m_name =
new TQLineEdit(w);
58 TQVBoxLayout *l0 =
new TQVBoxLayout(w, 0, 10);
59 TQHBoxLayout *l1 =
new TQHBoxLayout(0, 0, 10);
60 TQHBoxLayout *l2 =
new TQHBoxLayout(0, 0, 5);
63 l1->addWidget(m_aliases);
64 l0->addWidget(m_view);
66 l2->addWidget(m_name, 0);
67 l2->addWidget(m_type, 0);
68 l2->addWidget(m_stack, 1);
72 setCaption(i18n(
"Printcap Entry: %1").arg(entry->name));
73 m_fields = entry->fields;
74 m_aliases->setText(entry->aliases.join(
"|"));
75 TQListViewItem *root =
new TQListViewItem(m_view, entry->name), *item = 0;
76 root->setSelectable(
false);
78 root->setPixmap(0, SmallIcon(
"document-print"));
79 for (TQMap<TQString,Field>::ConstIterator it=m_fields.begin(); it!=m_fields.end(); ++it)
80 item =
new TQListViewItem(root, item, (*it).toString(), it.key());
84 enableButton(Ok,
false);
85 slotItemSelected(NULL);
89 connect(m_view, TQ_SIGNAL(selectionChanged(TQListViewItem*)), TQ_SLOT(slotItemSelected(TQListViewItem*)));
90 connect(m_string, TQ_SIGNAL(textChanged(
const TQString&)), TQ_SLOT(slotChanged()));
91 connect(m_boolean, TQ_SIGNAL(toggled(
bool)), TQ_SLOT(slotChanged()));
92 connect(m_number, TQ_SIGNAL(valueChanged(
int)), TQ_SLOT(slotChanged()));
93 connect(m_type, TQ_SIGNAL(activated(
int)), TQ_SLOT(slotTypeChanged(
int)));
94 connect(m_name, TQ_SIGNAL(textChanged(
const TQString&)), TQ_SLOT(slotChanged()));
99 Field EditEntryDialog::createField()
102 f.name = m_name->text();
103 f.type = (Field::Type)(m_type->currentItem());
106 case Field::String: f.value = m_string->text();
break;
107 case Field::Integer: f.value = m_number->cleanText();
break;
108 case Field::Boolean: f.value = (m_boolean->isChecked() ?
"1" :
"0");
break;
113 void EditEntryDialog::slotChanged()
115 if (!m_block && m_view->currentItem())
117 Field f = createField();
118 if (f.name != m_current)
119 m_fields.remove(m_current);
120 m_fields[f.name] = f;
121 m_view->currentItem()->setText(0, f.toString());
125 void EditEntryDialog::slotItemSelected(TQListViewItem *item)
127 m_stack->setEnabled(item);
128 m_name->setEnabled(item);
129 m_type->setEnabled(item);
133 m_current = item->text(1);
134 Field f = m_fields[m_current];
135 m_name->setText(f.name);
136 m_type->setCurrentItem(f.type);
137 slotTypeChanged(f.type);
138 m_string->setText(f.value);
139 m_number->setValue(f.value.toInt());
140 m_boolean->setChecked(f.value.toInt() == 1);
145 void EditEntryDialog::fillEntry(PrintcapEntry *entry)
147 entry->aliases = TQStringList::split(
'|', m_aliases->text(),
false);
148 entry->fields = m_fields;
151 void EditEntryDialog::slotTypeChanged(
int ID)
153 m_stack->raiseWidget(ID);
157 #include "editentrydialog.moc"