summaryrefslogtreecommitdiffstats
path: root/kdeprint/management
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitce4a32fe52ef09d8f5ff1dd22c001110902b60a2 (patch)
tree5ac38a06f3dde268dc7927dc155896926aaf7012 /kdeprint/management
downloadtdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.tar.gz
tdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kdeprint/management')
-rw-r--r--kdeprint/management/Makefile.am52
-rw-r--r--kdeprint/management/cjanuswidget.cpp265
-rw-r--r--kdeprint/management/cjanuswidget.h64
-rw-r--r--kdeprint/management/jobitem.cpp74
-rw-r--r--kdeprint/management/jobitem.h55
-rw-r--r--kdeprint/management/kaddprinterwizard.cpp39
-rw-r--r--kdeprint/management/kdeprint_management_module.cpp56
-rw-r--r--kdeprint/management/kiconselectaction.cpp118
-rw-r--r--kdeprint/management/kiconselectaction.h49
-rw-r--r--kdeprint/management/kmconfigcommand.cpp53
-rw-r--r--kdeprint/management/kmconfigcommand.h31
-rw-r--r--kdeprint/management/kmconfigdialog.cpp89
-rw-r--r--kdeprint/management/kmconfigdialog.h43
-rw-r--r--kdeprint/management/kmconfigfilter.cpp159
-rw-r--r--kdeprint/management/kmconfigfilter.h52
-rw-r--r--kdeprint/management/kmconfigfonts.cpp182
-rw-r--r--kdeprint/management/kmconfigfonts.h54
-rw-r--r--kdeprint/management/kmconfiggeneral.cpp142
-rw-r--r--kdeprint/management/kmconfiggeneral.h50
-rw-r--r--kdeprint/management/kmconfigjobs.cpp63
-rw-r--r--kdeprint/management/kmconfigjobs.h40
-rw-r--r--kdeprint/management/kmconfigpage.cpp36
-rw-r--r--kdeprint/management/kmconfigpage.h53
-rw-r--r--kdeprint/management/kmconfigpreview.cpp74
-rw-r--r--kdeprint/management/kmconfigpreview.h41
-rw-r--r--kdeprint/management/kmdbcreator.cpp187
-rw-r--r--kdeprint/management/kmdbcreator.h58
-rw-r--r--kdeprint/management/kmdriverdb.cpp244
-rw-r--r--kdeprint/management/kmdriverdb.h67
-rw-r--r--kdeprint/management/kmdriverdbwidget.cpp273
-rw-r--r--kdeprint/management/kmdriverdbwidget.h74
-rw-r--r--kdeprint/management/kmdriverdialog.cpp55
-rw-r--r--kdeprint/management/kmdriverdialog.h44
-rw-r--r--kdeprint/management/kmiconview.cpp237
-rw-r--r--kdeprint/management/kmiconview.h78
-rw-r--r--kdeprint/management/kminfopage.cpp143
-rw-r--r--kdeprint/management/kminfopage.h42
-rw-r--r--kdeprint/management/kminstancepage.cpp276
-rw-r--r--kdeprint/management/kminstancepage.h58
-rw-r--r--kdeprint/management/kmjobviewer.cpp742
-rw-r--r--kdeprint/management/kmjobviewer.h127
-rw-r--r--kdeprint/management/kmlistview.cpp268
-rw-r--r--kdeprint/management/kmlistview.h59
-rw-r--r--kdeprint/management/kmmainview.cpp908
-rw-r--r--kdeprint/management/kmmainview.h132
-rw-r--r--kdeprint/management/kmpages.cpp74
-rw-r--r--kdeprint/management/kmpages.h44
-rw-r--r--kdeprint/management/kmprinterpage.h42
-rw-r--r--kdeprint/management/kmprinterview.cpp113
-rw-r--r--kdeprint/management/kmprinterview.h62
-rw-r--r--kdeprint/management/kmpropbackend.cpp86
-rw-r--r--kdeprint/management/kmpropbackend.h45
-rw-r--r--kdeprint/management/kmpropcontainer.cpp77
-rw-r--r--kdeprint/management/kmpropcontainer.h50
-rw-r--r--kdeprint/management/kmpropdriver.cpp83
-rw-r--r--kdeprint/management/kmpropdriver.h46
-rw-r--r--kdeprint/management/kmpropertypage.cpp94
-rw-r--r--kdeprint/management/kmpropertypage.h53
-rw-r--r--kdeprint/management/kmpropgeneral.cpp83
-rw-r--r--kdeprint/management/kmpropgeneral.h44
-rw-r--r--kdeprint/management/kmpropmembers.cpp70
-rw-r--r--kdeprint/management/kmpropmembers.h42
-rw-r--r--kdeprint/management/kmpropwidget.cpp86
-rw-r--r--kdeprint/management/kmpropwidget.h63
-rw-r--r--kdeprint/management/kmspecialprinterdlg.cpp222
-rw-r--r--kdeprint/management/kmspecialprinterdlg.h57
-rw-r--r--kdeprint/management/kmtimer.cpp96
-rw-r--r--kdeprint/management/kmtimer.h62
-rw-r--r--kdeprint/management/kmwbackend.cpp177
-rw-r--r--kdeprint/management/kmwbackend.h54
-rw-r--r--kdeprint/management/kmwclass.cpp141
-rw-r--r--kdeprint/management/kmwclass.h46
-rw-r--r--kdeprint/management/kmwdriver.cpp116
-rw-r--r--kdeprint/management/kmwdriver.h40
-rw-r--r--kdeprint/management/kmwdriverselect.cpp116
-rw-r--r--kdeprint/management/kmwdriverselect.h48
-rw-r--r--kdeprint/management/kmwdrivertest.cpp172
-rw-r--r--kdeprint/management/kmwdrivertest.h53
-rw-r--r--kdeprint/management/kmwend.cpp119
-rw-r--r--kdeprint/management/kmwend.h38
-rw-r--r--kdeprint/management/kmwfile.cpp77
-rw-r--r--kdeprint/management/kmwfile.h39
-rw-r--r--kdeprint/management/kmwinfobase.cpp90
-rw-r--r--kdeprint/management/kmwinfobase.h51
-rw-r--r--kdeprint/management/kmwinfopage.cpp48
-rw-r--r--kdeprint/management/kmwinfopage.h31
-rw-r--r--kdeprint/management/kmwizard.cpp262
-rw-r--r--kdeprint/management/kmwizard.h101
-rw-r--r--kdeprint/management/kmwizardpage.cpp48
-rw-r--r--kdeprint/management/kmwizardpage.h52
-rw-r--r--kdeprint/management/kmwlocal.cpp206
-rw-r--r--kdeprint/management/kmwlocal.h58
-rw-r--r--kdeprint/management/kmwlpd.cpp102
-rw-r--r--kdeprint/management/kmwlpd.h34
-rw-r--r--kdeprint/management/kmwname.cpp96
-rw-r--r--kdeprint/management/kmwname.h35
-rw-r--r--kdeprint/management/kmwpassword.cpp133
-rw-r--r--kdeprint/management/kmwpassword.h43
-rw-r--r--kdeprint/management/kmwsmb.cpp119
-rw-r--r--kdeprint/management/kmwsmb.h50
-rw-r--r--kdeprint/management/kmwsocket.cpp150
-rw-r--r--kdeprint/management/kmwsocket.h51
-rw-r--r--kdeprint/management/kmwsocketutil.cpp219
-rw-r--r--kdeprint/management/kmwsocketutil.h76
-rw-r--r--kdeprint/management/kxmlcommanddlg.cpp1059
-rw-r--r--kdeprint/management/kxmlcommanddlg.h127
-rw-r--r--kdeprint/management/kxmlcommandselector.cpp285
-rw-r--r--kdeprint/management/kxmlcommandselector.h68
-rw-r--r--kdeprint/management/networkscanner.cpp421
-rw-r--r--kdeprint/management/networkscanner.h95
-rw-r--r--kdeprint/management/pluginaction.cpp34
-rw-r--r--kdeprint/management/pluginaction.h42
-rw-r--r--kdeprint/management/side.pngbin0 -> 50353 bytes
-rw-r--r--kdeprint/management/sidepixmap.cpp69
-rw-r--r--kdeprint/management/sidepixmap.h42
-rw-r--r--kdeprint/management/smbview.cpp284
-rw-r--r--kdeprint/management/smbview.h67
-rw-r--r--kdeprint/management/tiledown.pngbin0 -> 323 bytes
-rw-r--r--kdeprint/management/tileup.pngbin0 -> 241 bytes
119 files changed, 13584 insertions, 0 deletions
diff --git a/kdeprint/management/Makefile.am b/kdeprint/management/Makefile.am
new file mode 100644
index 000000000..b6485fdfb
--- /dev/null
+++ b/kdeprint/management/Makefile.am
@@ -0,0 +1,52 @@
+AM_CPPFLAGS = -D_KDEPRINT_COMPILE
+
+INCLUDES= -I$(top_srcdir)/kdefx -I$(top_srcdir)/kdeprint -I$(top_builddir)/kdeprint -I$(top_srcdir)/kio -I$(top_srcdir)/kfile -I$(top_srcdir) $(all_includes)
+
+lib_LTLIBRARIES = libkdeprint_management.la
+kde_module_LTLIBRARIES = libkdeprint_management_module.la
+kdeinit_LTLIBRARIES = kaddprinterwizard.la
+bin_PROGRAMS =
+
+kaddprinterwizard_la_SOURCES = kaddprinterwizard.cpp
+kaddprinterwizard_la_LIBADD = libkdeprint_management.la
+kaddprinterwizard_la_LDFLAGS = -module -avoid-version $(all_libraries) $(KDE_RPATH)
+
+libkdeprint_management_la_SOURCES = \
+ kmdbcreator.cpp kmdriverdb.cpp kmdriverdbwidget.cpp \
+ kmiconview.cpp kminfopage.cpp kmmainview.cpp \
+ kmpages.cpp kmprinterview.cpp kmjobviewer.cpp \
+ jobitem.cpp kmpropwidget.cpp kmpropcontainer.cpp kmpropertypage.cpp \
+ kmpropgeneral.cpp cjanuswidget.cpp kmpropmembers.cpp kmpropbackend.cpp kmpropdriver.cpp \
+ kmlistview.cpp kminstancepage.cpp kmtimer.cpp \
+ kmwizard.cpp kmwizardpage.cpp kmwinfopage.cpp kmwpassword.cpp kmwsocketutil.cpp \
+ kmwbackend.cpp kmwsocket.cpp kmwdriver.cpp kmwdriverselect.cpp kmwdrivertest.cpp \
+ kmwinfobase.cpp kmwname.cpp kmwend.cpp kmwclass.cpp kmwlpd.cpp kmwfile.cpp kmdriverdialog.cpp \
+ kmwsmb.cpp smbview.cpp kmconfigdialog.cpp kmconfigpage.cpp kmconfiggeneral.cpp kmspecialprinterdlg.cpp \
+ kmwlocal.cpp kiconselectaction.cpp kmconfigpreview.cpp sidepixmap.cpp \
+ pluginaction.cpp kxmlcommanddlg.cpp kxmlcommandselector.cpp kmconfigcommand.cpp \
+ kmconfigfilter.cpp kmconfigfonts.cpp kmconfigjobs.cpp networkscanner.cpp
+libkdeprint_management_la_LDFLAGS = $(all_libraries) -version-info 6:0:2 -no-undefined
+libkdeprint_management_la_LIBADD = ../libkdeprint.la
+libkdeprint_management_la_METASOURCES = AUTO
+
+libkdeprint_management_module_la_SOURCES = kdeprint_management_module.cpp
+libkdeprint_management_module_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) -no-undefined
+libkdeprint_management_module_la_LIBADD = libkdeprint_management.la
+
+kdeprint_HEADERS = kmmainview.h kmjobviewer.h kmprinterpage.h kiconselectaction.h kmtimer.h
+kdeprintdir = $(includedir)/kdeprint
+
+noinst_HEADERS = kmdbcreator.h kmdriverdb.h kmdriverdbwidget.h kmiconview.h \
+ kminfopage.h kmmainview.h kmpages.h \
+ kmprinterpage.h kmprinterview.h kmjobviewer.h jobitem.h kmpropwidget.h kmpropcontainer.h \
+ kmpropertypage.h kmpropgeneral.h cjanuswidget.h kmpropmembers.h kmpropbackend.h kmpropdriver.h \
+ kmlistview.h kminstancepage.h kmwizard.h kmwizardpage.h kmwinfopage.h kmwpassword.h kmwsocketutil.h \
+ kmwbackend.h kmwsocket.h kmwdriver.h kmwdriverselect.h kmwdrivertest.h kmwinfobase.h kmwname.h kmwend.h \
+ kmwclass.h kmwlpd.h kmwfile.h kmdriverdialog.h kmwsmb.h smbview.h kmconfigdialog.h kmconfigpage.h \
+ kmconfiggeneral.h kmspecialprinterdlg.h kmwlocal.h kmconfigpreview.h sidepixmap.h \
+ pluginaction.h kxmlcommanddlg.h kxmlcommandselector.h kmconfigcommand.h \
+ kmconfigfilter.h kmconfigfonts.h kmconfigjobs.h networkscanner.h
+
+dataicon_DATA = tileup.png tiledown.png side.png
+dataicondir = $(kde_datadir)/kdeprint
+
diff --git a/kdeprint/management/cjanuswidget.cpp b/kdeprint/management/cjanuswidget.cpp
new file mode 100644
index 000000000..a2ea52b2e
--- /dev/null
+++ b/kdeprint/management/cjanuswidget.cpp
@@ -0,0 +1,265 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "cjanuswidget.h"
+
+#include <qwidgetstack.h>
+#include <qlabel.h>
+#include <qpainter.h>
+#include <klistbox.h>
+#include <qlayout.h>
+#include <kseparator.h>
+
+class CJanusWidget::CPage
+{
+public:
+ QWidget *m_widget;
+ QString m_text;
+ QString m_header;
+ QPixmap m_pixmap;
+ CListBoxItem *m_item;
+};
+
+//***********************************************************************************
+
+class CJanusWidget::CListBoxItem : public QListBoxItem
+{
+public:
+ CListBoxItem(QListBox *lb, QListBoxItem *after, const QPixmap& pix, const QString& text);
+ int height(const QListBox*) const;
+ int width(const QListBox*) const;
+
+protected:
+ void paint(QPainter*);
+
+private:
+ QPixmap m_pix;
+};
+
+CJanusWidget::CListBoxItem::CListBoxItem(QListBox *lb, QListBoxItem *after, const QPixmap& pix, const QString& text)
+: QListBoxItem(lb, after), m_pix(pix)
+{
+ setText(text);
+}
+
+int CJanusWidget::CListBoxItem::height(const QListBox *lb) const
+{
+ return (m_pix.height() + lb->fontMetrics().lineSpacing() + 12);
+}
+
+int CJanusWidget::CListBoxItem::width(const QListBox *lb) const
+{
+ int w = QMAX(lb->fontMetrics().width(text()),m_pix.width());
+ return (w + 10);
+}
+
+void CJanusWidget::CListBoxItem::paint(QPainter *p)
+{
+ int w1 = (listBox()->contentsWidth()-m_pix.width())/2;
+
+ p->drawPixmap(w1,5,m_pix);
+ p->drawText(0,7+m_pix.height(),listBox()->contentsWidth(),p->fontMetrics().lineSpacing(),Qt::AlignHCenter,text());
+}
+
+//***********************************************************************************
+
+class CJanusWidget::CListBox : public KListBox
+{
+public:
+ CListBox(QWidget *parent = 0, const char *name = 0);
+ ~CListBox();
+
+ void computeWidth();
+
+protected:
+ virtual bool eventFilter(QObject*, QEvent*);
+};
+
+CJanusWidget::CListBox::CListBox(QWidget *parent, const char *name)
+: KListBox(parent,name)
+{
+ verticalScrollBar()->installEventFilter(this);
+}
+
+CJanusWidget::CListBox::~CListBox()
+{
+}
+
+bool CJanusWidget::CListBox::eventFilter(QObject *o, QEvent *e)
+{
+ if (e->type() == QEvent::Show || e->type() == QEvent::Hide)
+ computeWidth();
+ return KListBox::eventFilter(o,e);
+}
+
+void CJanusWidget::CListBox::computeWidth()
+{
+ QListBoxItem *item = firstItem();
+ int w(40);
+ while (item)
+ {
+ w = QMAX(w,item->width(this));
+ item = item->next();
+ }
+ if (verticalScrollBar()->isVisible())
+ w += verticalScrollBar()->sizeHint().width();
+ w += (frameWidth()*2);
+ setFixedWidth(w);
+}
+
+//***********************************************************************************
+
+CJanusWidget::CJanusWidget(QWidget *parent, const char *name)
+: QWidget(parent,name)
+{
+ m_pages.setAutoDelete(true);
+
+ m_stack = new QWidgetStack(this);
+ m_header = new QLabel(this);
+ QFont f(m_header->font());
+ f.setBold(true);
+ m_header->setFont(f);
+
+ KSeparator* sep = new KSeparator( KSeparator::HLine, this);
+ sep->setFixedHeight(5);
+
+ m_iconlist = new CListBox(this);
+ f = m_iconlist->font();
+ f.setBold(true);
+ m_iconlist->setFont(f);
+ connect(m_iconlist,SIGNAL(selectionChanged(QListBoxItem*)),SLOT(slotSelected(QListBoxItem*)));
+
+ m_empty = new QWidget(this, "Empty");
+ m_stack->addWidget(m_empty,0);
+
+ QHBoxLayout *main_ = new QHBoxLayout(this, 0, 10);
+ QVBoxLayout *sub_ = new QVBoxLayout(0, 0, 5);
+ main_->addWidget(m_iconlist,0);
+ main_->addLayout(sub_,1);
+ sub_->addWidget(m_header,0);
+ sub_->addWidget(sep,0);
+ sub_->addWidget(m_stack,1);
+}
+
+CJanusWidget::~CJanusWidget()
+{
+}
+
+void CJanusWidget::addPage(QWidget *w, const QString& text, const QString& header, const QPixmap& pix)
+{
+ CPage *page = new CPage();
+ m_pages.append(page);
+ page->m_widget = w;
+ page->m_text = text;
+ page->m_header = header;
+ page->m_pixmap = pix;
+ page->m_item = new CListBoxItem(m_iconlist,findPrevItem(page),pix,text);
+ m_iconlist->computeWidth();
+ m_stack->addWidget(w,m_pages.count());
+
+ if (m_iconlist->count() == 1)
+ m_iconlist->setSelected(page->m_item,true);
+}
+
+void CJanusWidget::enablePage(QWidget *w)
+{
+ CPage *page = findPage(w);
+ if (page && !page->m_item)
+ {
+ page->m_item = new CListBoxItem(m_iconlist,findPrevItem(page),page->m_pixmap,page->m_text);
+ m_iconlist->computeWidth();
+ if (m_iconlist->count() == 1)
+ m_iconlist->setSelected(page->m_item,true);
+ }
+}
+
+void CJanusWidget::disablePage(QWidget *w)
+{
+ CPage *page = findPage(w);
+ if (page && page->m_item)
+ {
+ bool needReselect(m_iconlist->isSelected(page->m_item));
+ delete page->m_item;
+ page->m_item = 0;
+ m_iconlist->computeWidth();
+ if (needReselect)
+ if (m_iconlist->count() > 0)
+ m_iconlist->setSelected(m_iconlist->firstItem(),true);
+ else
+ slotSelected(0);
+ }
+}
+
+void CJanusWidget::slotSelected(QListBoxItem *item)
+{
+ CPage *page = findPage(item);
+ if (page)
+ {
+ m_stack->raiseWidget(page->m_widget);
+ m_header->setText(page->m_header);
+ }
+ else
+ {
+ m_header->setText("");
+ m_stack->raiseWidget(m_empty);
+ }
+}
+
+CJanusWidget::CPage* CJanusWidget::findPage(QWidget *w)
+{
+ QPtrListIterator<CPage> it(m_pages);
+ for (;it.current();++it)
+ if (it.current()->m_widget == w)
+ return it.current();
+ return 0;
+}
+
+CJanusWidget::CPage* CJanusWidget::findPage(QListBoxItem *i)
+{
+ QPtrListIterator<CPage> it(m_pages);
+ for (;it.current();++it)
+ if (it.current()->m_item == i)
+ return it.current();
+ return 0;
+}
+
+QListBoxItem* CJanusWidget::findPrevItem(CPage *p)
+{
+ if (m_pages.findRef(p) == -1)
+ m_pages.last();
+ else
+ m_pages.prev();
+ for (;m_pages.current();m_pages.prev())
+ if (m_pages.current()->m_item)
+ return m_pages.current()->m_item;
+ return 0;
+}
+
+void CJanusWidget::clearPages()
+{
+ QPtrListIterator<CPage> it(m_pages);
+ for (;it.current(); ++it)
+ {
+ delete it.current()->m_widget;
+ delete it.current()->m_item;
+ }
+ m_pages.clear();
+}
+
+#include "cjanuswidget.moc"
diff --git a/kdeprint/management/cjanuswidget.h b/kdeprint/management/cjanuswidget.h
new file mode 100644
index 000000000..b0d1da50f
--- /dev/null
+++ b/kdeprint/management/cjanuswidget.h
@@ -0,0 +1,64 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef CJANUSWIDGET_H
+#define CJANUSWIDGET_H
+
+#include <qwidget.h>
+#include <qpixmap.h>
+#include <qptrlist.h>
+
+class QWidgetStack;
+class QLabel;
+class QListBoxItem;
+
+class CJanusWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ CJanusWidget(QWidget *parent, const char *name);
+ ~CJanusWidget();
+
+ void addPage(QWidget *w, const QString& text, const QString& header, const QPixmap& pix);
+ void enablePage(QWidget *w);
+ void disablePage(QWidget *w);
+ void clearPages();
+
+protected slots:
+ void slotSelected(QListBoxItem*);
+
+public:
+ class CPage;
+ class CListBox;
+ class CListBoxItem;
+
+private:
+ CPage* findPage(QWidget *w);
+ CPage* findPage(QListBoxItem *i);
+ QListBoxItem* findPrevItem(CPage*);
+
+private:
+ QPtrList<CPage> m_pages;
+ CListBox *m_iconlist;
+ QLabel *m_header;
+ QWidgetStack *m_stack;
+ QWidget *m_empty;
+};
+
+#endif
diff --git a/kdeprint/management/jobitem.cpp b/kdeprint/management/jobitem.cpp
new file mode 100644
index 000000000..61a2eaf9d
--- /dev/null
+++ b/kdeprint/management/jobitem.cpp
@@ -0,0 +1,74 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "jobitem.h"
+#include "kmjob.h"
+
+#include <kiconloader.h>
+
+JobItem::JobItem(QListView *parent, KMJob *job)
+: QListViewItem(parent)
+{
+ m_job = new KMJob;
+ init(job);
+}
+
+JobItem::~JobItem()
+{
+ delete m_job;
+}
+
+void JobItem::init(KMJob *job)
+{
+ m_job->copy(job ? *job : KMJob());
+
+ setPixmap(0,SmallIcon(m_job->pixmap()));
+ setText(0,QString::number(m_job->id()));
+ //setText(6,m_job->printer());
+ setText(2,m_job->name());
+ setText(1,m_job->owner());
+ setText(3,m_job->stateString());
+ setText(4,QString::number(m_job->size()));
+ setText(5,QString::number(m_job->processedPages()));
+ m_ID = m_job->id();
+ m_uri = m_job->uri();
+
+ // additional attributes
+ for (int i=0; i<m_job->attributeCount(); i++)
+ setText(6+i, m_job->attribute(i));
+
+ widthChanged();
+}
+
+int JobItem::compare(QListViewItem *item, int col, bool asc) const
+{
+ switch (col)
+ {
+ case 0:
+ case 4:
+ case 5:
+ {
+ int i1(this->text(col).toInt()), i2(item->text(col).toInt());
+ return (i1 < i2 ? -1 : (i1 > i2 ? 1 : 0));
+ break;
+ }
+ default:
+ return QListViewItem::compare(item, col, asc);
+ }
+}
diff --git a/kdeprint/management/jobitem.h b/kdeprint/management/jobitem.h
new file mode 100644
index 000000000..fdb310b31
--- /dev/null
+++ b/kdeprint/management/jobitem.h
@@ -0,0 +1,55 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef JOBITEM_H
+#define JOBITEM_H
+
+#include <qlistview.h>
+#include "kmobject.h"
+
+class KMJob;
+
+class JobItem : public QListViewItem, public KMObject
+{
+public:
+ JobItem(QListView *parent, KMJob *job = 0);
+ ~JobItem();
+ void init(KMJob *job);
+ int compare(QListViewItem*, int, bool) const;
+
+ int jobID() const;
+ QString jobUri() const;
+ KMJob* job() const;
+
+private:
+ KMJob *m_job;
+ int m_ID;
+ QString m_uri;
+};
+
+inline int JobItem::jobID() const
+{ return m_ID; }
+
+inline KMJob* JobItem::job() const
+{ return m_job; }
+
+inline QString JobItem::jobUri() const
+{ return m_uri; }
+
+#endif
diff --git a/kdeprint/management/kaddprinterwizard.cpp b/kdeprint/management/kaddprinterwizard.cpp
new file mode 100644
index 000000000..65d355a8f
--- /dev/null
+++ b/kdeprint/management/kaddprinterwizard.cpp
@@ -0,0 +1,39 @@
+#include "kmmanager.h"
+#include <kcmdlineargs.h>
+#include <kapplication.h>
+#include <kmessagebox.h>
+#include <klocale.h>
+#include <kglobal.h>
+
+static KCmdLineOptions options[] =
+{
+ { "kdeconfig", I18N_NOOP("Configure KDE Print"), 0 },
+ { "serverconfig", I18N_NOOP("Configure print server"), 0 },
+ KCmdLineLastOption
+};
+
+extern "C" KDE_EXPORT int kdemain(int argc, char *argv[])
+{
+ KCmdLineArgs::init(argc, argv, "kaddprinterwizard",
+ I18N_NOOP("Start the add printer wizard"),
+ "0.1");
+ KCmdLineArgs::addCmdLineOptions(options);
+
+ KGlobal::locale()->setMainCatalogue("kdelibs");
+
+ KApplication app;
+ KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+ bool doConfig = args->isSet("kdeconfig");
+ bool doSrvConfig = args->isSet("serverconfig");
+
+ if (doConfig)
+ KMManager::self()->invokeOptionsDialog();
+ else if (doSrvConfig)
+ KMManager::self()->configureServer();
+ else if (KMManager::self()->addPrinterWizard() == -1)
+ {
+ KMessageBox::error(0, KMManager::self()->errorMsg().prepend("<qt>").append("</qt>"));
+ }
+
+ return 0;
+}
diff --git a/kdeprint/management/kdeprint_management_module.cpp b/kdeprint/management/kdeprint_management_module.cpp
new file mode 100644
index 000000000..276eb76f5
--- /dev/null
+++ b/kdeprint/management/kdeprint_management_module.cpp
@@ -0,0 +1,56 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ * Copyright (C) 2004 Dominique Devriese <devriese@kde.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kxmlcommandselector.h"
+#include "kmconfigdialog.h"
+#include "kmwizard.h"
+#include "kmfactory.h"
+#include "kmmanager.h"
+#include "kmprinter.h"
+#include "kmmainview.h"
+
+#include <kmessagebox.h>
+#include <kdialogbase.h>
+#include <klocale.h>
+
+extern "C"
+{
+ KDEPRINT_EXPORT int add_printer_wizard(QWidget *parent)
+ {
+ return kdeprint_management_add_printer_wizard( parent );
+ }
+
+ KDEPRINT_EXPORT bool config_dialog(QWidget *parent)
+ {
+ KMConfigDialog dlg(parent);
+ return dlg.exec();
+ }
+
+ KDEPRINT_EXPORT QString select_command( QWidget* parent )
+ {
+ KDialogBase dlg( parent, 0, true, i18n( "Select Command" ), KDialogBase::Ok|KDialogBase::Cancel );
+ KXmlCommandSelector *xmlSel = new KXmlCommandSelector( false, &dlg, "CommandSelector", &dlg );
+ dlg.setMainWidget( xmlSel );
+ if ( dlg.exec() )
+ return xmlSel->command();
+ return QString::null;
+ }
+}
+
diff --git a/kdeprint/management/kiconselectaction.cpp b/kdeprint/management/kiconselectaction.cpp
new file mode 100644
index 000000000..9939d061e
--- /dev/null
+++ b/kdeprint/management/kiconselectaction.cpp
@@ -0,0 +1,118 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kiconselectaction.h"
+
+#include <qpopupmenu.h>
+#include <kiconloader.h>
+#include <kdebug.h>
+#include <ktoolbar.h>
+#include <ktoolbarbutton.h>
+
+class KIconSelectActionPrivate
+{
+public:
+ KIconSelectActionPrivate()
+ {
+ m_menu = 0;
+ }
+ QStringList m_iconlst;
+ QPopupMenu* m_menu;
+};
+
+KIconSelectAction::KIconSelectAction(const QString& text, int accel, QObject* parent, const char* name)
+: KSelectAction(text, accel, parent, name)
+{
+ d = new KIconSelectActionPrivate;
+}
+
+KIconSelectAction::~KIconSelectAction()
+{
+ delete d;
+}
+
+void KIconSelectAction::updateIcons()
+{
+ if (d->m_menu)
+ {
+ QStringList lst = items();
+ for (uint id=0; id<lst.count(); ++id)
+ d->m_menu->changeItem(id, SmallIconSet(d->m_iconlst[id]), lst[id]);
+ }
+}
+
+void KIconSelectAction::createPopupMenu()
+{
+ if (!d->m_menu)
+ {
+ d->m_menu = popupMenu();
+ updateIcons();
+ }
+}
+
+void KIconSelectAction::setItems(const QStringList& lst, const QStringList& iconlst)
+{
+ KSelectAction::setItems(lst);
+ d->m_iconlst = iconlst;
+ updateIcons();
+}
+
+int KIconSelectAction::plug(QWidget* widget, int index)
+{
+ int value(-1);
+ if (widget->inherits("QPopupMenu"))
+ {
+ createPopupMenu();
+ value = KSelectAction::plug(widget, index);
+ }
+ else if (widget->inherits("KToolBar"))
+ {
+ KToolBar* bar = static_cast<KToolBar*>(widget);
+ int id = KAction::getToolButtonID();
+ // To have a correct layout in the toolbar, a non
+ // empty icon has to be used. Use "unknown" by default.
+ QString iconName = (currentItem() != -1 ? d->m_iconlst[currentItem()] : "unknown");
+
+ createPopupMenu();
+ bar->insertButton(iconName, id, true, plainText(), index);
+ bar->getButton(id)->setPopup(d->m_menu, true);
+ bar->setItemEnabled(id, isEnabled());
+ addContainer(bar, id);
+ connect(bar, SIGNAL(destroyed()), SLOT(slotDestroyed()));
+
+ value = containerCount()-1;
+ }
+ return value;
+}
+
+void KIconSelectAction::updateCurrentItem(int id)
+{
+ QWidget* w = container(id);
+ if (w->inherits("KToolBar"))
+ static_cast<KToolBar*>(w)->getButton(itemId(id))->setIcon(d->m_iconlst[currentItem()]);
+ else
+ KSelectAction::updateCurrentItem(id);
+}
+
+void KIconSelectAction::setCurrentItem(int index)
+{
+ KSelectAction::setCurrentItem(index);
+}
+
+#include "kiconselectaction.moc"
diff --git a/kdeprint/management/kiconselectaction.h b/kdeprint/management/kiconselectaction.h
new file mode 100644
index 000000000..0cfcdaf84
--- /dev/null
+++ b/kdeprint/management/kiconselectaction.h
@@ -0,0 +1,49 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KICONSELECTACTION_H
+#define KICONSELECTACTION_H
+
+#include <kaction.h>
+
+class KIconSelectActionPrivate;
+
+class KIconSelectAction : public KSelectAction
+{
+ Q_OBJECT
+public:
+ KIconSelectAction(const QString& text, int accel = 0, QObject* parent = 0, const char* name = 0);
+ virtual ~KIconSelectAction();
+
+ virtual int plug(QWidget* widget, int index = -1);
+
+public slots:
+ virtual void setItems(const QStringList& lst, const QStringList& iconlst);
+ virtual void setCurrentItem(int index);
+
+protected:
+ void createPopupMenu();
+ void updateIcons();
+ virtual void updateCurrentItem(int id);
+
+private:
+ KIconSelectActionPrivate* d;
+};
+
+#endif
diff --git a/kdeprint/management/kmconfigcommand.cpp b/kdeprint/management/kmconfigcommand.cpp
new file mode 100644
index 000000000..5af13e170
--- /dev/null
+++ b/kdeprint/management/kmconfigcommand.cpp
@@ -0,0 +1,53 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmconfigcommand.h"
+#include "kxmlcommandselector.h"
+
+#include <qlabel.h>
+#include <qgroupbox.h>
+#include <qlayout.h>
+
+#include <klocale.h>
+#include <kdialog.h>
+
+KMConfigCommand::KMConfigCommand(QWidget *parent, const char *name)
+: KMConfigPage(parent, name)
+{
+ setPageName(i18n("Commands"));
+ setPageHeader(i18n("Command Settings"));
+ setPagePixmap("exec");
+
+ QGroupBox *gb = new QGroupBox(0, Qt::Horizontal, i18n("Edit/Create Commands"), this);
+ QLabel *lab = new QLabel(i18n(
+ "<p>Command objects perform a conversion from input to output.<br>"
+ "They are used as the basis to build both print filters "
+ "and special printers. They are described by a command string, a "
+ "set of options, a set of requirements and associated mime types. "
+ "Here you can create new command objects and edit existing ones. All "
+ "changes will only be effective for you."), gb);
+ KXmlCommandSelector *sel = new KXmlCommandSelector(false, gb);
+
+ QVBoxLayout *l0 = new QVBoxLayout(this, 0, KDialog::spacingHint());
+ l0->addWidget(gb);
+ l0->addStretch(1);
+ QVBoxLayout *l2 = new QVBoxLayout(gb->layout(), KDialog::spacingHint());
+ l2->addWidget(lab);
+ l2->addWidget(sel);
+}
diff --git a/kdeprint/management/kmconfigcommand.h b/kdeprint/management/kmconfigcommand.h
new file mode 100644
index 000000000..17aa88042
--- /dev/null
+++ b/kdeprint/management/kmconfigcommand.h
@@ -0,0 +1,31 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMCONFIGCOMMAND_H
+#define KMCONFIGCOMMAND_H
+
+#include "kmconfigpage.h"
+
+class KMConfigCommand : public KMConfigPage
+{
+public:
+ KMConfigCommand(QWidget *parent = 0, const char *name = 0);
+};
+
+#endif
diff --git a/kdeprint/management/kmconfigdialog.cpp b/kdeprint/management/kmconfigdialog.cpp
new file mode 100644
index 000000000..b775786e8
--- /dev/null
+++ b/kdeprint/management/kmconfigdialog.cpp
@@ -0,0 +1,89 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmconfigdialog.h"
+#include "kmconfigpage.h"
+#include "kmfactory.h"
+#include "kmuimanager.h"
+
+#include "kmconfiggeneral.h"
+#include "kmconfigpreview.h"
+#include "kmconfigcommand.h"
+#include "kmconfigfilter.h"
+#include "kmconfigfonts.h"
+#include "kmconfigjobs.h"
+
+#include <qlayout.h>
+#include <klocale.h>
+#include <kiconloader.h>
+#include <kconfig.h>
+
+KMConfigDialog::KMConfigDialog(QWidget *parent, const char *name)
+: KDialogBase(IconList,i18n("KDE Print Configuration"),Ok|Cancel,Ok,parent,name,true,true)
+{
+ m_pages.setAutoDelete(false);
+ addConfigPage(new KMConfigGeneral(this));
+ addConfigPage(new KMConfigPreview(this));
+ addConfigPage(new KMConfigFonts(this));
+ addConfigPage(new KMConfigCommand(this));
+ addConfigPage(new KMConfigFilter(this));
+ addConfigPage(new KMConfigJobs(this));
+ KMFactory::self()->uiManager()->setupConfigDialog(this);
+
+ // initialize pages
+ KConfig *conf = KMFactory::self()->printConfig();
+ QPtrListIterator<KMConfigPage> it(m_pages);
+ for (;it.current();++it)
+ it.current()->loadConfig(conf);
+
+ // resize dialog
+ resize(450,400);
+}
+
+void KMConfigDialog::addConfigPage(KMConfigPage *page)
+{
+ if (page)
+ {
+ QPixmap icon = KGlobal::instance()->iconLoader()->loadIcon(
+ page->pagePixmap(),
+ KIcon::NoGroup,
+ KIcon::SizeMedium
+ );
+
+ QFrame *frame = addPage(page->pageName(),page->pageHeader(),icon);
+ page->reparent(frame,QPoint(0,0));
+ QVBoxLayout *lay = new QVBoxLayout(frame, 0, 0);
+ lay->addWidget(page);
+ m_pages.append(page);
+ }
+}
+
+void KMConfigDialog::slotOk()
+{
+ // save configuration
+ KConfig *conf = KMFactory::self()->printConfig();
+ QPtrListIterator<KMConfigPage> it(m_pages);
+ for (;it.current();++it)
+ it.current()->saveConfig(conf);
+ KMFactory::self()->saveConfig();
+
+ // close the dialog
+ KDialogBase::slotOk();
+}
+#include "kmconfigdialog.moc"
diff --git a/kdeprint/management/kmconfigdialog.h b/kdeprint/management/kmconfigdialog.h
new file mode 100644
index 000000000..977408d70
--- /dev/null
+++ b/kdeprint/management/kmconfigdialog.h
@@ -0,0 +1,43 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMCONFIGDIALOG_H
+#define KMCONFIGDIALOG_H
+
+#include <kdialogbase.h>
+#include <qptrlist.h>
+
+#include "kmconfigpage.h"
+
+class KDEPRINT_EXPORT KMConfigDialog : public KDialogBase
+{
+ Q_OBJECT
+public:
+ KMConfigDialog(QWidget *parent = 0, const char *name = 0);
+
+ void addConfigPage(KMConfigPage*);
+
+protected slots:
+ void slotOk();
+
+private:
+ QPtrList<KMConfigPage> m_pages;
+};
+
+#endif
diff --git a/kdeprint/management/kmconfigfilter.cpp b/kdeprint/management/kmconfigfilter.cpp
new file mode 100644
index 000000000..1a62112f7
--- /dev/null
+++ b/kdeprint/management/kmconfigfilter.cpp
@@ -0,0 +1,159 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmconfigfilter.h"
+#include "kmmanager.h"
+#include "kmfactory.h"
+
+#include <qgroupbox.h>
+#include <qlineedit.h>
+#include <qtoolbutton.h>
+#include <qlayout.h>
+#include <qlabel.h>
+#include <qapplication.h>
+
+#include <klocale.h>
+#include <kconfig.h>
+#include <kiconloader.h>
+#include <klistbox.h>
+#include <kdialog.h>
+
+KMConfigFilter::KMConfigFilter(QWidget *parent, const char *name)
+: KMConfigPage(parent, name)
+{
+ setPageName(i18n("Filter"));
+ setPageHeader(i18n("Printer Filtering Settings"));
+ setPagePixmap("filter");
+
+ QGroupBox *box = new QGroupBox(0, Qt::Vertical, i18n("Printer Filter"), this);
+
+ m_list1 = new KListBox(box);
+ m_list1->setSelectionMode(KListBox::Extended);
+ m_list2 = new KListBox(box);
+ m_list2->setSelectionMode(KListBox::Extended);
+ m_add = new QToolButton( box );
+ m_add->setIconSet(QApplication::reverseLayout() ? SmallIconSet( "back" ) : SmallIconSet( "forward" ));
+ m_remove = new QToolButton( box );
+ m_remove->setIconSet(QApplication::reverseLayout() ? SmallIconSet( "forward" ) : SmallIconSet( "back" ));
+ m_locationre = new QLineEdit(box);
+ QLabel *lab = new QLabel(box);
+ lab->setText(i18n("The printer filtering allows you to view only a specific set of "
+ "printers instead of all of them. This may be useful when there are a "
+ "lot of printers available but you only use a few ones. Select the "
+ "printers you want to see from the list on the left or enter a <b>Location</b> "
+ "filter (ex: Group_1*). Both are cumulative and ignored if empty."));
+ lab->setTextFormat(Qt::RichText);
+ QLabel *lab1 = new QLabel(i18n("Location filter:"), box);
+
+ QVBoxLayout *l0 = new QVBoxLayout(this, 0, KDialog::spacingHint());
+ l0->addWidget(box, 1);
+ QVBoxLayout *l1 = new QVBoxLayout(box->layout(), KDialog::spacingHint());
+ l1->addWidget(lab);
+ QGridLayout *l2 = new QGridLayout(0, 4, 3, 0, KDialog::spacingHint());
+ l1->addLayout(l2);
+ l2->setRowStretch(0, 1);
+ l2->setRowStretch(3, 1);
+ l2->setColStretch(0, 1);
+ l2->setColStretch(2, 1);
+ l2->addMultiCellWidget(m_list1, 0, 3, 0, 0);
+ l2->addMultiCellWidget(m_list2, 0, 3, 2, 2);
+ l2->addWidget(m_add, 1, 1);
+ l2->addWidget(m_remove, 2, 1);
+ QHBoxLayout *l3 = new QHBoxLayout(0, 0, KDialog::spacingHint());
+ l1->addLayout(l3, 0);
+ l3->addWidget(lab1, 0);
+ l3->addWidget(m_locationre, 1);
+
+ connect(m_add, SIGNAL(clicked()), SLOT(slotAddClicked()));
+ connect(m_remove, SIGNAL(clicked()), SLOT(slotRemoveClicked()));
+ connect(m_list1, SIGNAL(selectionChanged()), SLOT(slotSelectionChanged()));
+ connect(m_list2, SIGNAL(selectionChanged()), SLOT(slotSelectionChanged()));
+ m_add->setEnabled(false);
+ m_remove->setEnabled(false);
+}
+
+void KMConfigFilter::loadConfig(KConfig *conf)
+{
+ conf->setGroup("Filter");
+ QStringList m_plist = conf->readListEntry("Printers");
+ QPtrListIterator<KMPrinter> it(*(KMManager::self()->printerListComplete(false)));
+ for (; it.current(); ++it)
+ {
+ if (!it.current()->isSpecial() && !it.current()->isVirtual())
+ {
+ KListBox *lb = (m_plist.find(it.current()->printerName()) == m_plist.end() ? m_list1 : m_list2);
+ lb->insertItem(SmallIcon(it.current()->pixmap()), it.current()->printerName());
+ }
+ }
+ m_list1->sort();
+ m_list2->sort();
+ m_locationre->setText(conf->readEntry("LocationRe"));
+}
+
+void KMConfigFilter::saveConfig(KConfig *conf)
+{
+ conf->setGroup("Filter");
+ QStringList plist;
+ for (uint i=0; i<m_list2->count(); i++)
+ plist << m_list2->text(i);
+ conf->writeEntry("Printers", plist);
+ conf->writeEntry("LocationRe", m_locationre->text());
+}
+
+void KMConfigFilter::transfer(KListBox *from, KListBox *to)
+{
+ for (uint i=0; i<from->count();)
+ {
+ if (from->isSelected(i))
+ {
+ to->insertItem(*(from->pixmap(i)), from->text(i));
+ from->removeItem(i);
+ }
+ else
+ i++;
+ }
+ to->sort();
+}
+
+void KMConfigFilter::slotAddClicked()
+{
+ transfer(m_list1, m_list2);
+}
+
+void KMConfigFilter::slotRemoveClicked()
+{
+ transfer(m_list2, m_list1);
+}
+
+void KMConfigFilter::slotSelectionChanged()
+{
+ const KListBox *lb = static_cast<const KListBox*>(sender());
+ if (!lb)
+ return;
+ QToolButton *pb = (lb == m_list1 ? m_add : m_remove);
+ for (uint i=0; i<lb->count(); i++)
+ if (lb->isSelected(i))
+ {
+ pb->setEnabled(true);
+ return;
+ }
+ pb->setEnabled(false);
+}
+
+#include "kmconfigfilter.moc"
diff --git a/kdeprint/management/kmconfigfilter.h b/kdeprint/management/kmconfigfilter.h
new file mode 100644
index 000000000..2374f3b05
--- /dev/null
+++ b/kdeprint/management/kmconfigfilter.h
@@ -0,0 +1,52 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMCONFIGFILTER_H
+#define KMCONFIGFILTER_H
+
+#include "kmconfigpage.h"
+
+class KListBox;
+class QToolButton;
+class QLineEdit;
+
+class KMConfigFilter : public KMConfigPage
+{
+ Q_OBJECT
+public:
+ KMConfigFilter(QWidget *parent = 0, const char *name = 0);
+
+ void loadConfig(KConfig*);
+ void saveConfig(KConfig*);
+
+protected slots:
+ void slotSelectionChanged();
+ void slotAddClicked();
+ void slotRemoveClicked();
+
+protected:
+ void transfer(KListBox *from, KListBox *to);
+
+private:
+ KListBox *m_list1, *m_list2;
+ QToolButton *m_add, *m_remove;
+ QLineEdit *m_locationre;
+};
+
+#endif
diff --git a/kdeprint/management/kmconfigfonts.cpp b/kdeprint/management/kmconfigfonts.cpp
new file mode 100644
index 000000000..c7b4420cb
--- /dev/null
+++ b/kdeprint/management/kmconfigfonts.cpp
@@ -0,0 +1,182 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmconfigfonts.h"
+
+#include <qgroupbox.h>
+#include <kpushbutton.h>
+#include <qlayout.h>
+#include <qheader.h>
+#include <qlabel.h>
+#include <qcheckbox.h>
+#include <qsettings.h>
+#include <qwhatsthis.h>
+
+#include <klocale.h>
+#include <kconfig.h>
+#include <kiconloader.h>
+#include <kurlrequester.h>
+#include <kfile.h>
+#include <klistview.h>
+#include <kdialog.h>
+
+KMConfigFonts::KMConfigFonts(QWidget *parent, const char *name)
+: KMConfigPage(parent, name)
+{
+ setPageName(i18n("Fonts"));
+ setPageHeader(i18n("Font Settings"));
+ setPagePixmap("fonts");
+
+ QGroupBox *box = new QGroupBox(0, Qt::Vertical, i18n("Fonts Embedding"), this);
+ QGroupBox *box2 = new QGroupBox(0, Qt::Vertical, i18n("Fonts Path"), this);
+
+ m_embedfonts = new QCheckBox(i18n("&Embed fonts in PostScript data when printing"), box);
+ m_fontpath = new KListView(box2);
+ m_fontpath->addColumn("");
+ m_fontpath->header()->setStretchEnabled(true, 0);
+ m_fontpath->header()->hide();
+ m_fontpath->setSorting(-1);
+ m_addpath = new KURLRequester(box2);
+ m_addpath->setMode(KFile::Directory|KFile::ExistingOnly|KFile::LocalOnly);
+ m_up = new KPushButton(KGuiItem(i18n("&Up"), "up"), box2);
+ m_down = new KPushButton(KGuiItem(i18n("&Down"), "down"), box2);
+ m_add = new KPushButton(KGuiItem(i18n("&Add"), "add"), box2);
+ m_remove = new KPushButton(KGuiItem(i18n("&Remove"), "editdelete"), box2);
+ QLabel *lab0 = new QLabel(i18n("Additional director&y:"), box2);
+ lab0->setBuddy(m_addpath);
+
+ QVBoxLayout *l0 = new QVBoxLayout(box->layout(), KDialog::spacingHint());
+ l0->addWidget(m_embedfonts);
+ QVBoxLayout *l1 = new QVBoxLayout(box2->layout(), KDialog::spacingHint());
+ l1->addWidget(m_fontpath);
+ QHBoxLayout *l2 = new QHBoxLayout(0, 0, KDialog::spacingHint());
+ l1->addLayout(l2);
+ l2->addWidget(m_up);
+ l2->addWidget(m_down);
+ l2->addWidget(m_remove);
+ l1->addSpacing(10);
+ l1->addWidget(lab0);
+ l1->addWidget(m_addpath);
+ QHBoxLayout *l3 = new QHBoxLayout(0, 0, KDialog::spacingHint());
+ l1->addLayout(l3);
+ l3->addStretch(1);
+ l3->addWidget(m_add);
+ QVBoxLayout *l4 = new QVBoxLayout(this, 0, KDialog::spacingHint());
+ l4->addWidget(box);
+ l4->addWidget(box2);
+
+ QWhatsThis::add(m_embedfonts,
+ i18n("These options will automatically put fonts in the PostScript file "
+ "which are not present on the printer. Font embedding usually produces better print results "
+ "(closer to what you see on the screen), but larger print data as well."));
+ QWhatsThis::add(m_fontpath,
+ i18n("When using font embedding you can select additional directories where "
+ "KDE should search for embeddable font files. By default, the X server "
+ "font path is used, so adding those directories is not needed. The default "
+ "search path should be sufficient in most cases."));
+
+ connect(m_remove, SIGNAL(clicked()), SLOT(slotRemove()));
+ connect(m_add, SIGNAL(clicked()), SLOT(slotAdd()));
+ connect(m_up, SIGNAL(clicked()), SLOT(slotUp()));
+ connect(m_down, SIGNAL(clicked()), SLOT(slotDown()));
+ connect(m_fontpath, SIGNAL(selectionChanged()), SLOT(slotSelected()));
+ connect(m_addpath, SIGNAL(textChanged(const QString&)), SLOT(slotTextChanged(const QString&)));
+ m_add->setEnabled(false);
+ m_remove->setEnabled(false);
+ m_up->setEnabled(false);
+ m_down->setEnabled(false);
+}
+
+void KMConfigFonts::loadConfig(KConfig *)
+{
+ QSettings settings;
+ m_embedfonts->setChecked(settings.readBoolEntry("/qt/embedFonts", true));
+ QStringList paths = settings.readListEntry("/qt/fontPath", ':');
+ QListViewItem *item(0);
+ for (QStringList::ConstIterator it=paths.begin(); it!=paths.end(); ++it)
+ item = new QListViewItem(m_fontpath, item, *it);
+}
+
+void KMConfigFonts::saveConfig(KConfig *)
+{
+ QSettings settings;
+ settings.writeEntry("/qt/embedFonts", m_embedfonts->isChecked());
+ QStringList l;
+ QListViewItem *item = m_fontpath->firstChild();
+ while (item)
+ {
+ l << item->text(0);
+ item = item->nextSibling();
+ }
+ settings.writeEntry("/qt/fontPath", l, ':');
+}
+
+void KMConfigFonts::slotSelected()
+{
+ QListViewItem *item = m_fontpath->selectedItem();
+ m_remove->setEnabled(item);
+ m_up->setEnabled(item && item->itemAbove());
+ m_down->setEnabled(item && item->itemBelow());
+}
+
+void KMConfigFonts::slotAdd()
+{
+ if (m_addpath->url().isEmpty())
+ return;
+ QListViewItem *lastItem(m_fontpath->firstChild());
+ while (lastItem && lastItem->nextSibling())
+ lastItem = lastItem->nextSibling();
+ QListViewItem *item = new QListViewItem(m_fontpath, lastItem, m_addpath->url());
+ m_fontpath->setSelected(item, true);
+}
+
+void KMConfigFonts::slotRemove()
+{
+ delete m_fontpath->selectedItem();
+ if (m_fontpath->currentItem())
+ m_fontpath->setSelected(m_fontpath->currentItem(), true);
+ slotSelected();
+}
+
+void KMConfigFonts::slotUp()
+{
+ QListViewItem *citem = m_fontpath->selectedItem(), *nitem = 0;
+ if (!citem || !citem->itemAbove())
+ return;
+ nitem = new QListViewItem(m_fontpath, citem->itemAbove()->itemAbove(), citem->text(0));
+ delete citem;
+ m_fontpath->setSelected(nitem, true);
+}
+
+void KMConfigFonts::slotDown()
+{
+ QListViewItem *citem = m_fontpath->selectedItem(), *nitem = 0;
+ if (!citem || !citem->itemBelow())
+ return;
+ nitem = new QListViewItem(m_fontpath, citem->itemBelow(), citem->text(0));
+ delete citem;
+ m_fontpath->setSelected(nitem, true);
+}
+
+void KMConfigFonts::slotTextChanged(const QString& t)
+{
+ m_add->setEnabled(!t.isEmpty());
+}
+
+#include "kmconfigfonts.moc"
diff --git a/kdeprint/management/kmconfigfonts.h b/kdeprint/management/kmconfigfonts.h
new file mode 100644
index 000000000..c1c383199
--- /dev/null
+++ b/kdeprint/management/kmconfigfonts.h
@@ -0,0 +1,54 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMCONFIGFONTS_H
+#define KMCONFIGFONTS_H
+
+#include "kmconfigpage.h"
+
+class KListView;
+class KURLRequester;
+class QPushButton;
+class QCheckBox;
+
+class KMConfigFonts : public KMConfigPage
+{
+ Q_OBJECT
+public:
+ KMConfigFonts(QWidget *parent = 0, const char *name = 0);
+
+ void loadConfig(KConfig*);
+ void saveConfig(KConfig*);
+
+protected slots:
+ void slotUp();
+ void slotDown();
+ void slotRemove();
+ void slotAdd();
+ void slotSelected();
+ void slotTextChanged(const QString&);
+
+private:
+ QCheckBox *m_embedfonts;
+ KListView *m_fontpath;
+ KURLRequester *m_addpath;
+ QPushButton *m_up, *m_down, *m_add, *m_remove;
+};
+
+#endif
diff --git a/kdeprint/management/kmconfiggeneral.cpp b/kdeprint/management/kmconfiggeneral.cpp
new file mode 100644
index 000000000..65f9d2437
--- /dev/null
+++ b/kdeprint/management/kmconfiggeneral.cpp
@@ -0,0 +1,142 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmconfiggeneral.h"
+
+#include <qlayout.h>
+#include <qgroupbox.h>
+#include <qcheckbox.h>
+#include <qlabel.h>
+#include <qwhatsthis.h>
+
+#include <kpushbutton.h>
+#include <klocale.h>
+#include <kurlrequester.h>
+#include <krun.h>
+#include <kmimemagic.h>
+#include <kconfig.h>
+#include <knuminput.h>
+#include <kmessagebox.h>
+#include <kcursor.h>
+#include <klineedit.h>
+#include <kguiitem.h>
+#include <kdialog.h>
+
+KMConfigGeneral::KMConfigGeneral(QWidget *parent)
+: KMConfigPage(parent,"ConfigTimer")
+{
+ setPageName(i18n("General"));
+ setPageHeader(i18n("General Settings"));
+ setPagePixmap("fileprint");
+
+ QGroupBox *m_timerbox = new QGroupBox(0, Qt::Vertical, i18n("Refresh Interval"), this);
+ m_timer = new KIntNumInput(m_timerbox,"Timer");
+ m_timer->setRange(0,30);
+ m_timer->setSuffix( i18n( " sec" ) );
+ m_timer->setSpecialValueText(i18n("Disabled"));
+ QWhatsThis::add(m_timer, i18n("This time setting controls the refresh rate of various "
+ "<b>KDE Print</b> components like the print manager "
+ "and the job viewer."));
+
+ QGroupBox *m_testpagebox = new QGroupBox(0, Qt::Vertical, i18n("Test Page"), this);
+ m_defaulttestpage = new QCheckBox(i18n("&Specify personal test page"), m_testpagebox, "TestPageCheck");
+ m_testpage = new KURLRequester(m_testpagebox,"TestPage");
+ m_preview = new KPushButton(KGuiItem(i18n("Preview..."), "filefind"), m_testpagebox);
+ connect(m_defaulttestpage,SIGNAL(toggled(bool)),m_testpage,SLOT(setEnabled(bool)));
+ connect(m_defaulttestpage,SIGNAL(toggled(bool)),this,SLOT(setEnabledPreviewButton(bool)));
+ connect(m_preview,SIGNAL(clicked()),SLOT(slotTestPagePreview()));
+ connect(m_testpage->lineEdit(),SIGNAL(textChanged ( const QString & )),this,SLOT(testPageChanged(const QString & )));
+ m_testpage->setDisabled(true);
+ m_preview->setDisabled(true);
+ m_defaulttestpage->setCursor(KCursor::handCursor());
+
+ QGroupBox *m_statusbox = new QGroupBox(0, Qt::Vertical, i18n("Miscellaneous"), this);
+ m_statusmsg = new QCheckBox(i18n("Sho&w printing status message box"), m_statusbox);
+ m_uselast = new QCheckBox(i18n("De&faults to the last printer used in the application"), m_statusbox);
+
+ //layout
+ QVBoxLayout *lay0 = new QVBoxLayout(this, 0, KDialog::spacingHint());
+ lay0->addWidget(m_timerbox);
+ lay0->addWidget(m_testpagebox);
+ lay0->addWidget(m_statusbox);
+ lay0->addStretch(1);
+ QVBoxLayout *lay1 = new QVBoxLayout(m_timerbox->layout(),
+ KDialog::spacingHint());
+ lay1->addWidget(m_timer);
+ QVBoxLayout *lay2 = new QVBoxLayout(m_testpagebox->layout(),
+ KDialog::spacingHint());
+ QHBoxLayout *lay3 = new QHBoxLayout(0, 0, 0);
+ lay2->addWidget(m_defaulttestpage);
+ lay2->addWidget(m_testpage);
+ lay2->addLayout(lay3);
+ lay3->addStretch(1);
+ lay3->addWidget(m_preview);
+ QVBoxLayout *lay4 = new QVBoxLayout(m_statusbox->layout(),
+ KDialog::spacingHint());
+ lay4->addWidget(m_statusmsg);
+ lay4->addWidget(m_uselast);
+ m_preview->setEnabled( !m_testpage->url().isEmpty());
+}
+
+void KMConfigGeneral::testPageChanged(const QString &test )
+{
+ m_preview->setEnabled( !test.isEmpty());
+}
+
+void KMConfigGeneral::setEnabledPreviewButton(bool b)
+{
+ m_preview->setEnabled(!m_testpage->url().isEmpty() && b);
+}
+
+void KMConfigGeneral::loadConfig(KConfig *conf)
+{
+ conf->setGroup("General");
+ m_timer->setValue(conf->readNumEntry("TimerDelay",5));
+ QString tpage = conf->readPathEntry("TestPage");
+ if (!tpage.isEmpty())
+ {
+ m_defaulttestpage->setChecked(true);
+ m_testpage->setURL(tpage);
+ }
+ m_statusmsg->setChecked(conf->readBoolEntry("ShowStatusMsg", true));
+ m_uselast->setChecked(conf->readBoolEntry("UseLast", true));
+}
+
+void KMConfigGeneral::saveConfig(KConfig *conf)
+{
+ conf->setGroup("General");
+ conf->writeEntry("TimerDelay",m_timer->value());
+ conf->writePathEntry("TestPage",(m_defaulttestpage->isChecked() ? m_testpage->url() : QString::null));
+ if (m_defaulttestpage->isChecked() && KMimeMagic::self()->findFileType(m_testpage->url())->mimeType() != "application/postscript")
+ KMessageBox::sorry(this, i18n("The selected test page is not a PostScript file. You may not "
+ "be able to test your printer anymore."));
+ conf->writeEntry("ShowStatusMsg", m_statusmsg->isChecked());
+ conf->writeEntry("UseLast", m_uselast->isChecked());
+}
+
+void KMConfigGeneral::slotTestPagePreview()
+{
+ QString tpage = m_testpage->url();
+ if (tpage.isEmpty())
+ KMessageBox::error(this, i18n("Empty file name."));
+ else
+ KRun::runURL(KURL( tpage ), KMimeMagic::self()->findFileType(tpage)->mimeType());
+}
+
+#include "kmconfiggeneral.moc"
diff --git a/kdeprint/management/kmconfiggeneral.h b/kdeprint/management/kmconfiggeneral.h
new file mode 100644
index 000000000..87c10c2bf
--- /dev/null
+++ b/kdeprint/management/kmconfiggeneral.h
@@ -0,0 +1,50 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMCONFIGGENERAL_H
+#define KMCONFIGGENERAL_H
+
+#include "kmconfigpage.h"
+
+class KIntNumInput;
+class KURLRequester;
+class QCheckBox;
+class QPushButton;
+class KMConfigGeneral : public KMConfigPage
+{
+ Q_OBJECT
+public:
+ KMConfigGeneral(QWidget *parent = 0);
+
+ void loadConfig(KConfig*);
+ void saveConfig(KConfig*);
+
+protected slots:
+ void slotTestPagePreview();
+ void testPageChanged(const QString & );
+ void setEnabledPreviewButton(bool b);
+private:
+ KIntNumInput *m_timer;
+ KURLRequester *m_testpage;
+ QCheckBox *m_defaulttestpage;
+ QPushButton *m_preview;
+ QCheckBox *m_statusmsg, *m_uselast;
+};
+
+#endif
diff --git a/kdeprint/management/kmconfigjobs.cpp b/kdeprint/management/kmconfigjobs.cpp
new file mode 100644
index 000000000..31ca1ed26
--- /dev/null
+++ b/kdeprint/management/kmconfigjobs.cpp
@@ -0,0 +1,63 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmconfigjobs.h"
+
+#include <qgroupbox.h>
+#include <qlayout.h>
+
+#include <knuminput.h>
+#include <klocale.h>
+#include <kconfig.h>
+#include <kdialog.h>
+
+KMConfigJobs::KMConfigJobs(QWidget *parent, const char *name)
+: KMConfigPage(parent, name)
+{
+ setPageName(i18n("Jobs"));
+ setPageHeader(i18n("Print Job Settings"));
+ setPagePixmap("exec");
+
+ QGroupBox *box = new QGroupBox(0, Qt::Vertical, i18n("Jobs Shown"), this);
+
+ m_limit = new KIntNumInput(box);
+ m_limit->setRange(0, 9999, 1, true);
+ m_limit->setSpecialValueText(i18n("Unlimited"));
+ m_limit->setLabel(i18n("Maximum number of jobs shown:"));
+
+ QVBoxLayout *l0 = new QVBoxLayout(this, 0, KDialog::spacingHint());
+ l0->addWidget(box, 0);
+ l0->addStretch(1);
+ QVBoxLayout *l1 = new QVBoxLayout(box->layout(), KDialog::spacingHint());
+ l1->addWidget(m_limit);
+}
+
+void KMConfigJobs::loadConfig(KConfig *conf)
+{
+ conf->setGroup("Jobs");
+ m_limit->setValue(conf->readNumEntry("Limit", 0));
+}
+
+void KMConfigJobs::saveConfig(KConfig *conf)
+{
+ conf->setGroup("Jobs");
+ conf->writeEntry("Limit", m_limit->value());
+}
+
+#include "kmconfigjobs.moc"
diff --git a/kdeprint/management/kmconfigjobs.h b/kdeprint/management/kmconfigjobs.h
new file mode 100644
index 000000000..c1a301b32
--- /dev/null
+++ b/kdeprint/management/kmconfigjobs.h
@@ -0,0 +1,40 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMCONFIGJOBS_H
+#define KMCONFIGJOBS_H
+
+#include "kmconfigpage.h"
+
+class KIntNumInput;
+
+class KMConfigJobs : public KMConfigPage
+{
+ Q_OBJECT
+public:
+ KMConfigJobs(QWidget *parent = 0, const char *name = 0);
+
+ void loadConfig(KConfig*);
+ void saveConfig(KConfig*);
+
+private:
+ KIntNumInput *m_limit;
+};
+
+#endif
diff --git a/kdeprint/management/kmconfigpage.cpp b/kdeprint/management/kmconfigpage.cpp
new file mode 100644
index 000000000..afeda5f9e
--- /dev/null
+++ b/kdeprint/management/kmconfigpage.cpp
@@ -0,0 +1,36 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmconfigpage.h"
+
+KMConfigPage::KMConfigPage(QWidget *parent, const char *name)
+: QWidget(parent,name)
+{
+ m_name = "Name";
+ m_header = "Header";
+}
+
+void KMConfigPage::loadConfig(KConfig*)
+{
+}
+
+void KMConfigPage::saveConfig(KConfig*)
+{
+}
+#include "kmconfigpage.moc"
diff --git a/kdeprint/management/kmconfigpage.h b/kdeprint/management/kmconfigpage.h
new file mode 100644
index 000000000..d3db9994b
--- /dev/null
+++ b/kdeprint/management/kmconfigpage.h
@@ -0,0 +1,53 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMCONFIGPAGE_H
+#define KMCONFIGPAGE_H
+
+#include <qwidget.h>
+
+#include <kdelibs_export.h>
+
+class KConfig;
+
+class KDEPRINT_EXPORT KMConfigPage : public QWidget
+{
+ Q_OBJECT
+public:
+ KMConfigPage(QWidget *parent = 0, const char *name = 0);
+
+ virtual void loadConfig(KConfig*);
+ virtual void saveConfig(KConfig*);
+
+ QString pageName() const { return m_name; }
+ QString pageHeader() const { return m_header; }
+ QString pagePixmap() const { return m_pixmap; }
+
+protected:
+ void setPageName(const QString& s) { m_name = s; }
+ void setPageHeader(const QString& s) { m_header = s; }
+ void setPagePixmap(const QString& s) { m_pixmap = s; }
+
+protected:
+ QString m_name;
+ QString m_header;
+ QString m_pixmap;
+};
+
+#endif
diff --git a/kdeprint/management/kmconfigpreview.cpp b/kdeprint/management/kmconfigpreview.cpp
new file mode 100644
index 000000000..a3ed5581e
--- /dev/null
+++ b/kdeprint/management/kmconfigpreview.cpp
@@ -0,0 +1,74 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmconfigpreview.h"
+
+#include <qcheckbox.h>
+#include <qlayout.h>
+#include <qgroupbox.h>
+#include <qlabel.h>
+
+#include <klocale.h>
+#include <kurlrequester.h>
+#include <kconfig.h>
+#include <kdialog.h>
+
+KMConfigPreview::KMConfigPreview(QWidget *parent, const char *name)
+: KMConfigPage(parent, name)
+{
+ setPageName(i18n("Preview"));
+ setPageHeader(i18n("Preview Settings"));
+ setPagePixmap("filefind");
+
+ QGroupBox *box = new QGroupBox(0, Qt::Vertical, i18n("Preview Program"), this);
+
+ m_useext = new QCheckBox(i18n("&Use external preview program"), box);
+ m_program = new KURLRequester(box);
+ QLabel *lab = new QLabel(box);
+ lab->setText(i18n("You can use an external preview program (PS viewer) instead of the "
+ "KDE built-in preview system. Note that if the KDE default PS viewer "
+ "(KGhostView) cannot be found, KDE tries automatically to find another "
+ "external PostScript viewer"));
+ lab->setTextFormat(Qt::RichText);
+
+ QVBoxLayout *l0 = new QVBoxLayout(this, 0, KDialog::spacingHint());
+ l0->addWidget(box);
+ l0->addStretch(1);
+ QVBoxLayout *l1 = new QVBoxLayout(box->layout(), KDialog::spacingHint());
+ l1->addWidget(lab);
+ l1->addWidget(m_useext);
+ l1->addWidget(m_program);
+
+ connect(m_useext, SIGNAL(toggled(bool)), m_program, SLOT(setEnabled(bool)));
+ m_program->setEnabled(false);
+}
+
+void KMConfigPreview::loadConfig(KConfig *conf)
+{
+ conf->setGroup("General");
+ m_useext->setChecked(conf->readBoolEntry("ExternalPreview", false));
+ m_program->setURL(conf->readPathEntry("PreviewCommand", "gv"));
+}
+
+void KMConfigPreview::saveConfig(KConfig *conf)
+{
+ conf->setGroup("General");
+ conf->writeEntry("ExternalPreview", m_useext->isChecked());
+ conf->writePathEntry("PreviewCommand", m_program->url());
+}
diff --git a/kdeprint/management/kmconfigpreview.h b/kdeprint/management/kmconfigpreview.h
new file mode 100644
index 000000000..e37aa2b8f
--- /dev/null
+++ b/kdeprint/management/kmconfigpreview.h
@@ -0,0 +1,41 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMCONFIGPREVIEW_H
+#define KMCONFIGPREVIEW_H
+
+#include "kmconfigpage.h"
+
+class QCheckBox;
+class KURLRequester;
+
+class KMConfigPreview : public KMConfigPage
+{
+public:
+ KMConfigPreview(QWidget *parent = 0, const char *name = 0);
+
+ void loadConfig(KConfig*);
+ void saveConfig(KConfig*);
+
+private:
+ QCheckBox *m_useext;
+ KURLRequester *m_program;
+};
+
+#endif
diff --git a/kdeprint/management/kmdbcreator.cpp b/kdeprint/management/kmdbcreator.cpp
new file mode 100644
index 000000000..021619db9
--- /dev/null
+++ b/kdeprint/management/kmdbcreator.cpp
@@ -0,0 +1,187 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmdbcreator.h"
+#include "kmfactory.h"
+#include "kmmanager.h"
+
+#include <qprogressdialog.h>
+#include <qfileinfo.h>
+#include <qdir.h>
+#include <klocale.h>
+#include <kapplication.h>
+#include <kstandarddirs.h>
+#include <kdebug.h>
+
+KMDBCreator::KMDBCreator(QObject *parent, const char *name)
+: QObject(parent,name)
+{
+ m_dlg = 0;
+ m_status = true;
+
+ connect(&m_proc,SIGNAL(receivedStdout(KProcess*,char*,int)),SLOT(slotReceivedStdout(KProcess*,char*,int)));
+ connect(&m_proc,SIGNAL(receivedStderr(KProcess*,char*,int)),SLOT(slotReceivedStderr(KProcess*,char*,int)));
+ connect(&m_proc,SIGNAL(processExited(KProcess*)),SLOT(slotProcessExited(KProcess*)));
+}
+
+KMDBCreator::~KMDBCreator()
+{
+ if (m_proc.isRunning())
+ m_proc.kill();
+ // do not delete the progress dialog anymore: it's persistent and owned by
+ // it's parent. It will be destroyed along with its parent.
+}
+
+bool KMDBCreator::checkDriverDB(const QString& dirname, const QDateTime& d)
+{
+ // don't block GUI
+ kapp->processEvents();
+
+ // first check current directory
+ QFileInfo dfi(dirname);
+ if (dfi.lastModified() > d)
+ return false;
+
+ // then check most recent file in current directory
+ QDir dir(dirname);
+ const QFileInfoList *list = dir.entryInfoList(QDir::Files,QDir::Time);
+ if (list && list->count() > 0 && list->getFirst()->lastModified() > d)
+ return false;
+
+ // then loop into subdirs
+ QStringList slist = dir.entryList(QDir::Dirs,QDir::Time);
+ for (QStringList::ConstIterator it=slist.begin(); it!=slist.end(); ++it)
+ if ((*it) != "." && (*it) != ".." && !checkDriverDB(dir.absFilePath(*it),d))
+ return false;
+
+ // everything is OK
+ return true;
+}
+
+bool KMDBCreator::createDriverDB(const QString& dirname, const QString& filename, QWidget *parent)
+{
+ bool started(true);
+
+ // initialize status
+ m_status = false;
+ m_firstflag = true;
+
+ // start the child process
+ m_proc.clearArguments();
+ QString exestr = KMFactory::self()->manager()->driverDbCreationProgram();
+ m_proc << exestr << dirname << filename;
+ kdDebug() << "executing : " << exestr << " " << dirname << " " << filename << endl;
+ QString msg;
+ if (exestr.isEmpty())
+ msg = i18n("No executable defined for the creation of the "
+ "driver database. This operation is not implemented.");
+ else if (KStandardDirs::findExe(exestr).isEmpty())
+ msg = i18n("The executable %1 could not be found in your "
+ "PATH. Check that this program exists and is "
+ "accessible in your PATH variable.").arg(exestr);
+ else if (!m_proc.start(KProcess::NotifyOnExit, KProcess::AllOutput))
+ msg = i18n("Unable to start the creation of the driver "
+ "database. The execution of %1 failed.").arg(exestr);
+ if (!msg.isEmpty())
+ {
+ KMManager::self()->setErrorMsg(msg);
+ started = false;
+ }
+
+ // Create the dialog if the process is running and if needed
+ if (started)
+ {
+ if (!m_dlg)
+ {
+ m_dlg = new QProgressDialog(parent->topLevelWidget(),"progress-dialog",true);
+ m_dlg->setLabelText(i18n("Please wait while KDE rebuilds a driver database."));
+ m_dlg->setCaption(i18n("Driver Database"));
+ connect(m_dlg,SIGNAL(canceled()),SLOT(slotCancelled()));
+ }
+ m_dlg->setMinimumDuration(0); // always show the dialog
+ m_dlg->setProgress(0); // to force showing
+ }
+ else
+ // be sure to emit this signal otherwise the DB widget won't never be notified
+ emit dbCreated();
+
+ return started;
+}
+
+void KMDBCreator::slotReceivedStdout(KProcess*, char *buf, int len)
+{
+ // save buffer
+ QString str( QCString(buf, len) );
+
+ // get the number, cut the string at the first '\n' otherwise
+ // the toInt() will return 0. If that occurs for the first number,
+ // then the number of steps will be also 0.
+ bool ok;
+ int p = str.find('\n');
+ int n = str.mid(0, p).toInt(&ok);
+
+ // process the number received
+ if (ok && m_dlg)
+ {
+ if (m_firstflag)
+ {
+ m_dlg->setTotalSteps(n);
+ m_firstflag = false;
+ }
+ else
+ {
+ m_dlg->setProgress(n);
+ }
+ }
+}
+
+void KMDBCreator::slotReceivedStderr(KProcess*, char*, int)
+{
+ // just discard it for the moment
+}
+
+void KMDBCreator::slotProcessExited(KProcess*)
+{
+ // delete the progress dialog
+ if (m_dlg)
+ {
+ m_dlg->reset();
+ }
+
+ // set exit status
+ m_status = (m_proc.normalExit() && m_proc.exitStatus() == 0);
+ if (!m_status)
+ {
+ KMFactory::self()->manager()->setErrorMsg(i18n("Error while creating driver database: abnormal child-process termination."));
+ // remove the incomplete driver DB file so that, it will be
+ // reconstructed on next check
+ QFile::remove(m_proc.args()[2]);
+ }
+ //else
+ emit dbCreated();
+}
+
+void KMDBCreator::slotCancelled()
+{
+ if (m_proc.isRunning())
+ m_proc.kill();
+ else
+ emit dbCreated();
+}
+#include "kmdbcreator.moc"
diff --git a/kdeprint/management/kmdbcreator.h b/kdeprint/management/kmdbcreator.h
new file mode 100644
index 000000000..8af6e5bcf
--- /dev/null
+++ b/kdeprint/management/kmdbcreator.h
@@ -0,0 +1,58 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMDBCREATOR_H
+#define KMDBCREATOR_H
+
+#include <qobject.h>
+#include <qstring.h>
+#include <qdatetime.h>
+#include <kprocess.h>
+
+class QWidget;
+class QProgressDialog;
+
+class KMDBCreator : public QObject
+{
+ Q_OBJECT
+public:
+ KMDBCreator(QObject *parent = 0, const char *name = 0);
+ ~KMDBCreator();
+
+ bool checkDriverDB(const QString& dirname, const QDateTime& d);
+ bool createDriverDB(const QString& dirname, const QString& filename, QWidget *parent = 0);
+ bool status() const { return m_status; }
+
+protected slots:
+ void slotReceivedStdout(KProcess *p, char *bufm, int len);
+ void slotReceivedStderr(KProcess *p, char *bufm, int len);
+ void slotProcessExited(KProcess *p);
+ void slotCancelled();
+
+signals:
+ void dbCreated();
+
+private:
+ KProcess m_proc;
+ QProgressDialog *m_dlg;
+ bool m_status;
+ bool m_firstflag;
+};
+
+#endif
diff --git a/kdeprint/management/kmdriverdb.cpp b/kdeprint/management/kmdriverdb.cpp
new file mode 100644
index 000000000..d75588d0d
--- /dev/null
+++ b/kdeprint/management/kmdriverdb.cpp
@@ -0,0 +1,244 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmdriverdb.h"
+#include "kmdbentry.h"
+#include "kmdbcreator.h"
+#include "kmmanager.h"
+#include "kmfactory.h"
+#include <kdebug.h>
+
+#include <qfile.h>
+#include <qtextstream.h>
+#include <qfileinfo.h>
+#include <kstandarddirs.h>
+#include <kapplication.h>
+#include <kmessagebox.h>
+
+KMDriverDB* KMDriverDB::m_self = 0;
+
+KMDriverDB* KMDriverDB::self()
+{
+ if (!m_self)
+ {
+ m_self = new KMDriverDB();
+ Q_CHECK_PTR(m_self);
+ }
+ return m_self;
+}
+
+KMDriverDB::KMDriverDB(QObject *parent, const char *name)
+: QObject(parent,name)
+{
+ m_creator = new KMDBCreator(this,"db-creator");
+ connect(m_creator,SIGNAL(dbCreated()),SLOT(slotDbCreated()));
+
+ m_entries.setAutoDelete(true);
+ m_pnpentries.setAutoDelete(true);
+}
+
+KMDriverDB::~KMDriverDB()
+{
+}
+
+QString KMDriverDB::dbFile()
+{
+ // this calls insure missing directories creation
+ QString filename = locateLocal("data",QString::fromLatin1("kdeprint/printerdb_%1.txt").arg(KMFactory::self()->printSystem()));
+ return filename;
+}
+
+void KMDriverDB::init(QWidget *parent)
+{
+ QFileInfo dbfi(dbFile());
+ QString dirname = KMFactory::self()->manager()->driverDirectory();
+ QStringList dbDirs = QStringList::split(':', dirname, false);
+ bool createflag(false);
+
+ for (QStringList::ConstIterator it=dbDirs.begin(); it!=dbDirs.end() && !createflag; ++it)
+ if (!(*it).startsWith("module:") && !m_creator->checkDriverDB(*it, dbfi.lastModified()))
+ createflag = true;
+
+ if (createflag)
+ {
+ // starts DB creation and wait for creator signal
+ if (!m_creator->createDriverDB(dirname,dbfi.absFilePath(),parent))
+ KMessageBox::error(parent, KMFactory::self()->manager()->errorMsg().prepend("<qt>").append("</qt>"));
+ }
+ else if (m_entries.count() == 0)
+ {
+ // call directly the slot as the DB won't be re-created
+ // this will (re)load the driver DB
+ slotDbCreated();
+ }
+ else
+ // no need to refresh, and already loaded, just emit signal
+ emit dbLoaded(false);
+}
+
+void KMDriverDB::slotDbCreated()
+{
+ // DB should be created, check creator status
+ if (m_creator->status())
+ {
+ // OK, load DB and emit signal
+ loadDbFile();
+ emit dbLoaded(true);
+ }
+ else
+ // error while creating DB, notify the DB widget
+ emit error(KMManager::self()->errorMsg());
+ // be sure to emit this signal to notify the DB widget
+ //emit dbLoaded(true);
+}
+
+KMDBEntryList* KMDriverDB::findEntry(const QString& manu, const QString& model)
+{
+ QDict<KMDBEntryList> *models = m_entries.find(manu);
+ if (models)
+ return models->find(model);
+ return 0;
+}
+
+KMDBEntryList* KMDriverDB::findPnpEntry(const QString& manu, const QString& model)
+{
+ QDict<KMDBEntryList> *models = m_pnpentries.find(manu);
+ if (models)
+ return models->find(model);
+ return 0;
+}
+
+QDict<KMDBEntryList>* KMDriverDB::findModels(const QString& manu)
+{
+ return m_entries.find(manu);
+}
+
+void KMDriverDB::insertEntry(KMDBEntry *entry)
+{
+ // first check entry
+ if (!entry->validate())
+ {
+ kdDebug() << "Incorrect entry, skipping...(" << entry->file << ")" << endl;
+ delete entry;
+ return;
+ }
+
+ // insert it in normal entries
+ QDict<KMDBEntryList> *models = m_entries.find(entry->manufacturer);
+ if (!models)
+ {
+ models = new QDict<KMDBEntryList>(17,false);
+ models->setAutoDelete(true);
+ m_entries.insert(entry->manufacturer,models);
+ }
+ KMDBEntryList *list = models->find(entry->model);
+ if (!list)
+ {
+ list = new KMDBEntryList;
+ list->setAutoDelete(true);
+ models->insert(entry->model,list);
+ }
+ list->append(entry);
+
+ if (!entry->pnpmanufacturer.isEmpty() && !entry->pnpmodel.isEmpty())
+ {
+ // insert it in PNP entries
+ models = m_pnpentries.find(entry->manufacturer);
+ if (!models)
+ {
+ models = new QDict<KMDBEntryList>(17,false);
+ models->setAutoDelete(true);
+ m_pnpentries.insert(entry->manufacturer,models);
+ }
+ list = models->find(entry->model);
+ if (!list)
+ {
+ list = new KMDBEntryList;
+ list->setAutoDelete(true);
+ models->insert(entry->model,list);
+ }
+ list->append(entry);
+ }
+
+ // don't block GUI
+ kapp->processEvents();
+}
+
+/*
+ Driver DB file format:
+ FILE=<path>
+ MANUFACTURER=<string>
+ MODEL=<string>
+ PNPMANUFACTURER=<string>
+ PNPMODEL=<string>
+ DESCRIPTION=<string>
+*/
+
+void KMDriverDB::loadDbFile()
+{
+ // first clear everything
+ m_entries.clear();
+ m_pnpentries.clear();
+
+ QFile f(dbFile());
+ if (f.exists() && f.open(IO_ReadOnly))
+ {
+ QTextStream t(&f);
+ QString line;
+ QStringList words;
+ KMDBEntry *entry(0);
+
+ while (!t.eof())
+ {
+ line = t.readLine().stripWhiteSpace();
+ if (line.isEmpty())
+ continue;
+ int p = line.find('=');
+ if (p == -1)
+ continue;
+ words.clear();
+ words << line.left(p) << line.mid(p+1);
+ if (words[0] == "FILE")
+ {
+ if (entry) insertEntry(entry);
+ entry = new KMDBEntry;
+ entry->file = words[1];
+ }
+ else if (words[0] == "MANUFACTURER" && entry)
+ entry->manufacturer = words[1].upper();
+ else if (words[0] == "MODEL" && entry)
+ entry->model = words[1];
+ else if (words[0] == "MODELNAME" && entry)
+ entry->modelname = words[1];
+ else if (words[0] == "PNPMANUFACTURER" && entry)
+ entry->pnpmanufacturer = words[1].upper();
+ else if (words[0] == "PNPMODEL" && entry)
+ entry->pnpmodel = words[1];
+ else if (words[0] == "DESCRIPTION" && entry)
+ entry->description = words[1];
+ else if (words[0] == "RECOMMANDED" && entry && words[1].lower() == "yes")
+ entry->recommended = true;
+ else if (words[0] == "DRIVERCOMMENT" && entry)
+ entry->drivercomment = ("<qt>"+words[1].replace("&lt;", "<").replace("&gt;", ">")+"</qt>");
+ }
+ if (entry)
+ insertEntry(entry);
+ }
+}
+#include "kmdriverdb.moc"
diff --git a/kdeprint/management/kmdriverdb.h b/kdeprint/management/kmdriverdb.h
new file mode 100644
index 000000000..e0f3a7eba
--- /dev/null
+++ b/kdeprint/management/kmdriverdb.h
@@ -0,0 +1,67 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMDRIVERDB_H
+#define KMDRIVERDB_H
+
+#include <qobject.h>
+#include <qptrlist.h>
+#include <qdict.h>
+#include <qstring.h>
+
+#include "kmdbentry.h"
+
+class KMDBCreator;
+
+class KMDriverDB : public QObject
+{
+ Q_OBJECT
+public:
+ static KMDriverDB* self();
+
+ KMDriverDB(QObject *parent = 0, const char *name = 0);
+ ~KMDriverDB();
+
+ void init(QWidget *parent = 0);
+ KMDBEntryList* findEntry(const QString& manu, const QString& model);
+ KMDBEntryList* findPnpEntry(const QString& manu, const QString& model);
+ QDict<KMDBEntryList>* findModels(const QString& manu);
+ const QDict< QDict<KMDBEntryList> >& manufacturers() const { return m_entries; }
+
+protected:
+ void loadDbFile();
+ void insertEntry(KMDBEntry *entry);
+ QString dbFile();
+
+protected slots:
+ void slotDbCreated();
+
+signals:
+ void dbLoaded(bool reloaded);
+ void error(const QString&);
+
+private:
+ KMDBCreator *m_creator;
+ QDict< QDict<KMDBEntryList> > m_entries;
+ QDict< QDict<KMDBEntryList> > m_pnpentries;
+
+ static KMDriverDB *m_self;
+};
+
+#endif
diff --git a/kdeprint/management/kmdriverdbwidget.cpp b/kdeprint/management/kmdriverdbwidget.cpp
new file mode 100644
index 000000000..076b8897e
--- /dev/null
+++ b/kdeprint/management/kmdriverdbwidget.cpp
@@ -0,0 +1,273 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmdriverdbwidget.h"
+#include "kmdriverdb.h"
+#include "kmfactory.h"
+#include "kmmanager.h"
+#include "driver.h"
+
+#include <klistbox.h>
+#include <kpushbutton.h>
+#include <qcheckbox.h>
+#include <kcursor.h>
+#include <qapplication.h>
+#include <kmessagebox.h>
+#include <qlayout.h>
+#include <qlabel.h>
+#include <qstrlist.h>
+
+#include <klocale.h>
+#include <kcursor.h>
+#include <kfiledialog.h>
+#include <kguiitem.h>
+#include <kio/netaccess.h>
+
+KMDriverDbWidget::KMDriverDbWidget(QWidget *parent, const char *name)
+: QWidget(parent,name)
+{
+ m_external = QString::null;
+ m_valid = false;
+
+ // build widget
+ m_manu = new KListBox(this);
+ m_model = new KListBox(this);
+ m_postscript = new QCheckBox(i18n("&PostScript printer"),this);
+ m_raw = new QCheckBox(i18n("&Raw printer (no driver needed)"),this);
+ m_postscript->setCursor(KCursor::handCursor());
+ m_raw->setCursor(KCursor::handCursor());
+ m_other = new KPushButton(KGuiItem(i18n("&Other..."), "fileopen"), this);
+ QLabel *l1 = new QLabel(i18n("&Manufacturer:"), this);
+ QLabel *l2 = new QLabel(i18n("Mo&del:"), this);
+ l1->setBuddy(m_manu);
+ l2->setBuddy(m_model);
+
+ // build layout
+ QVBoxLayout *main_ = new QVBoxLayout(this, 0, 10);
+ QGridLayout *sub1_ = new QGridLayout(0, 2, 3, 0, 0);
+ QHBoxLayout *sub2_ = new QHBoxLayout(0, 0, 10);
+ main_->addLayout(sub1_);
+ main_->addLayout(sub2_);
+ main_->addWidget(m_raw);
+ sub1_->addWidget(l1,0,0);
+ sub1_->addWidget(l2,0,2);
+ sub1_->addWidget(m_manu,1,0);
+ sub1_->addWidget(m_model,1,2);
+ sub1_->addColSpacing(1,20);
+ sub2_->addWidget(m_postscript,1);
+ sub2_->addWidget(m_other,0);
+
+ // build connections
+ connect(KMDriverDB::self(),SIGNAL(dbLoaded(bool)),SLOT(slotDbLoaded(bool)));
+ connect(KMDriverDB::self(), SIGNAL(error(const QString&)), SLOT(slotError(const QString&)));
+ connect(m_manu,SIGNAL(highlighted(const QString&)),SLOT(slotManufacturerSelected(const QString&)));
+ connect(m_raw,SIGNAL(toggled(bool)),m_manu,SLOT(setDisabled(bool)));
+ connect(m_raw,SIGNAL(toggled(bool)),m_model,SLOT(setDisabled(bool)));
+ connect(m_raw,SIGNAL(toggled(bool)),m_other,SLOT(setDisabled(bool)));
+ connect(m_raw,SIGNAL(toggled(bool)),m_postscript,SLOT(setDisabled(bool)));
+ connect(m_postscript,SIGNAL(toggled(bool)),m_manu,SLOT(setDisabled(bool)));
+ connect(m_postscript,SIGNAL(toggled(bool)),m_model,SLOT(setDisabled(bool)));
+ connect(m_postscript,SIGNAL(toggled(bool)),m_other,SLOT(setDisabled(bool)));
+ connect(m_postscript,SIGNAL(toggled(bool)),m_raw,SLOT(setDisabled(bool)));
+ connect(m_postscript,SIGNAL(toggled(bool)),SLOT(slotPostscriptToggled(bool)));
+ connect(m_other,SIGNAL(clicked()),SLOT(slotOtherClicked()));
+}
+
+KMDriverDbWidget::~KMDriverDbWidget()
+{
+}
+
+void KMDriverDbWidget::setDriver(const QString& manu, const QString& model)
+{
+ QListBoxItem *item = m_manu->findItem(manu);
+ QString model_(model);
+ if (item)
+ {
+ m_manu->setCurrentItem(item);
+ item = m_model->findItem(model_);
+ if (!item)
+ // try by stripping the manufacturer name from
+ // the beginning of the model string. This is
+ // often the case with PPD files
+ item = m_model->findItem(model_.replace(0,manu.length()+1,QString::fromLatin1("")));
+ if (item)
+ m_model->setCurrentItem(item);
+ }
+}
+
+void KMDriverDbWidget::setHaveRaw(bool on)
+{
+ if (on)
+ m_raw->show();
+ else
+ m_raw->hide();
+}
+
+void KMDriverDbWidget::setHaveOther(bool on)
+{
+ if (on)
+ m_other->show();
+ else
+ m_other->hide();
+}
+
+QString KMDriverDbWidget::manufacturer()
+{
+ return m_manu->currentText();
+}
+
+QString KMDriverDbWidget::model()
+{
+ return m_model->currentText();
+}
+
+KMDBEntryList* KMDriverDbWidget::drivers()
+{
+ return KMDriverDB::self()->findEntry(manufacturer(),model());
+}
+
+bool KMDriverDbWidget::isRaw()
+{
+ return m_raw->isChecked();
+}
+
+void KMDriverDbWidget::init()
+{
+ if (!m_valid)
+ {
+ QApplication::setOverrideCursor(KCursor::waitCursor());
+ m_manu->clear();
+ m_model->clear();
+ m_manu->insertItem(i18n("Loading..."));
+ KMDriverDB::self()->init(this);
+ }
+}
+
+void KMDriverDbWidget::slotDbLoaded(bool reloaded)
+{
+ QApplication::restoreOverrideCursor();
+ m_valid = true;
+ if (reloaded || m_manu->count() == 0 || (m_manu->count() == 1 && m_manu->text(0) == i18n("Loading...")))
+ { // do something only if DB reloaded
+ m_manu->clear();
+ m_model->clear();
+ QDictIterator< QDict<KMDBEntryList> > it(KMDriverDB::self()->manufacturers());
+ for (;it.current();++it)
+ m_manu->insertItem(it.currentKey());
+ m_manu->sort();
+ m_manu->setCurrentItem(0);
+ }
+}
+
+void KMDriverDbWidget::slotError(const QString& msg)
+{
+ QApplication::restoreOverrideCursor();
+ m_valid = false;
+ m_manu->clear();
+ KMessageBox::error(this, "<qt>"+msg+"</qt>");
+}
+
+void KMDriverDbWidget::slotManufacturerSelected(const QString& name)
+{
+ m_model->clear();
+ QDict<KMDBEntryList> *models = KMDriverDB::self()->findModels(name);
+ if (models)
+ {
+ QStrIList ilist(true);
+ QDictIterator<KMDBEntryList> it(*models);
+ for (;it.current();++it)
+ ilist.append(it.currentKey().latin1());
+ ilist.sort();
+ m_model->insertStrList(&ilist);
+ m_model->setCurrentItem(0);
+ }
+}
+
+void KMDriverDbWidget::slotPostscriptToggled(bool on)
+{
+ if (on)
+ {
+ QListBoxItem *item = m_manu->findItem("GENERIC");
+ if (item)
+ {
+ m_manu->setCurrentItem(item);
+ item = m_model->findItem( "POSTSCRIPT PRINTER" );
+ if ( item )
+ {
+ m_model->setCurrentItem( item );
+ return;
+ }
+ }
+ KMessageBox::error(this,i18n("Unable to find the PostScript driver."));
+ m_postscript->setChecked(false);
+ }
+}
+
+void KMDriverDbWidget::slotOtherClicked()
+{
+ if (m_external.isEmpty())
+ {
+ KFileDialog dlg( QString::null, QString::null, this, 0, true );
+ KURL url;
+
+ dlg.setMode( KFile::File );
+ dlg.setCaption( i18n( "Select Driver" ) );
+ if ( dlg.exec() )
+ url = dlg.selectedURL();
+
+ if ( !url.isEmpty() )
+ {
+ QString filename;
+ if ( KIO::NetAccess::download( url, filename, this ) )
+ {
+ DrMain *driver = KMFactory::self()->manager()->loadFileDriver(filename);
+ if (driver)
+ {
+ m_external = filename;
+ disconnect(m_manu,SIGNAL(highlighted(const QString&)),this,SLOT(slotManufacturerSelected(const QString&)));
+ m_manu->clear();
+ m_model->clear();
+ QString s = driver->get("manufacturer");
+ m_manu->insertItem((s.isEmpty() ? i18n("<Unknown>") : s));
+ s = driver->get("model");
+ m_model->insertItem((s.isEmpty() ? i18n("<Unknown>") : s));
+ m_manu->setCurrentItem(0);
+ m_model->setCurrentItem(0);
+ m_other->setText(i18n("Database"));
+ m_desc = driver->get("description");
+ delete driver;
+ }
+ else
+ {
+ KIO::NetAccess::removeTempFile( filename );
+ KMessageBox::error(this,"<qt>"+i18n("Wrong driver format.")+"<p>"+KMManager::self()->errorMsg()+"</p></qt>");
+ }
+ }
+ }
+ }
+ else
+ {
+ m_external = QString::null;
+ connect(m_manu,SIGNAL(highlighted(const QString&)),this,SLOT(slotManufacturerSelected(const QString&)));
+ m_other->setText(i18n("Other"));
+ m_desc = QString::null;
+ slotDbLoaded(true);
+ }
+}
+#include "kmdriverdbwidget.moc"
diff --git a/kdeprint/management/kmdriverdbwidget.h b/kdeprint/management/kmdriverdbwidget.h
new file mode 100644
index 000000000..aa040e110
--- /dev/null
+++ b/kdeprint/management/kmdriverdbwidget.h
@@ -0,0 +1,74 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMDRIVERDBWIDGET_H
+#define KMDRIVERDBWIDGET_H
+
+#include <qwidget.h>
+#include "kmdbentry.h"
+
+class QListBox;
+class QCheckBox;
+class QPushButton;
+
+class KMDriverDbWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ KMDriverDbWidget(QWidget *parent = 0, const char *name = 0);
+ ~KMDriverDbWidget();
+
+ void init();
+ void setHaveRaw(bool on);
+ void setHaveOther(bool on);
+ void setDriver(const QString& manu, const QString& model);
+
+ QString manufacturer();
+ QString model();
+ QString description() { return m_desc; }
+ KMDBEntryList* drivers();
+ QString driverFile();
+ bool isRaw();
+ bool isExternal();
+
+protected slots:
+ void slotDbLoaded(bool reloaded);
+ void slotManufacturerSelected(const QString& name);
+ void slotPostscriptToggled(bool);
+ void slotOtherClicked();
+ void slotError(const QString&);
+
+private:
+ QListBox *m_manu;
+ QListBox *m_model;
+ QCheckBox *m_postscript;
+ QCheckBox *m_raw;
+ QPushButton *m_other;
+ QString m_external;
+ QString m_desc;
+ bool m_valid;
+};
+
+inline QString KMDriverDbWidget::driverFile()
+{ return m_external; }
+
+inline bool KMDriverDbWidget::isExternal()
+{ return !(m_external.isEmpty()); }
+
+#endif
diff --git a/kdeprint/management/kmdriverdialog.cpp b/kdeprint/management/kmdriverdialog.cpp
new file mode 100644
index 000000000..f25ba8725
--- /dev/null
+++ b/kdeprint/management/kmdriverdialog.cpp
@@ -0,0 +1,55 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmdriverdialog.h"
+#include "driverview.h"
+
+#include <klocale.h>
+#include <kmessagebox.h>
+
+KMDriverDialog::KMDriverDialog(QWidget *parent, const char *name)
+: KDialogBase(KDialogBase::Swallow,i18n("Configure"),KDialogBase::Ok|KDialogBase::Cancel,KDialogBase::Ok,parent,name,true,false)
+{
+ m_view = new DriverView(0);
+ setMainWidget(m_view);
+
+ resize(400,450);
+}
+
+KMDriverDialog::~KMDriverDialog()
+{
+}
+
+void KMDriverDialog::setDriver(DrMain *d)
+{
+ m_view->setDriver(d);
+}
+
+void KMDriverDialog::slotOk()
+{
+ if (m_view->hasConflict())
+ {
+ KMessageBox::error(this, "<qt>"+i18n("Some options are in conflict. You must resolve those conflicts "
+ "before continuing.")+"</qt>");
+ return;
+ }
+ KDialogBase::slotOk();
+}
+
+#include "kmdriverdialog.moc"
diff --git a/kdeprint/management/kmdriverdialog.h b/kdeprint/management/kmdriverdialog.h
new file mode 100644
index 000000000..b3368ae13
--- /dev/null
+++ b/kdeprint/management/kmdriverdialog.h
@@ -0,0 +1,44 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMDRIVERDIALOG_H
+#define KMDRIVERDIALOG_H
+
+#include <kdialogbase.h>
+
+class DriverView;
+class DrMain;
+
+class KMDriverDialog : public KDialogBase
+{
+ Q_OBJECT
+public:
+ KMDriverDialog(QWidget *parent = 0, const char *name = 0);
+ ~KMDriverDialog();
+
+ void setDriver(DrMain*);
+
+protected slots:
+ void slotOk();
+
+private:
+ DriverView *m_view;
+};
+
+#endif
diff --git a/kdeprint/management/kmiconview.cpp b/kdeprint/management/kmiconview.cpp
new file mode 100644
index 000000000..cabd4496a
--- /dev/null
+++ b/kdeprint/management/kmiconview.cpp
@@ -0,0 +1,237 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmiconview.h"
+#include "kmprinter.h"
+
+#include <qpainter.h>
+#include <kiconloader.h>
+#include <kdebug.h>
+
+KMIconViewItem::KMIconViewItem(QIconView *parent, KMPrinter *p)
+: QIconViewItem(parent)
+{
+ m_state = 0;
+ m_mode = parent->itemTextPos();
+ m_pixmap = QString::null;
+ m_isclass = false;
+ updatePrinter(p, m_mode);
+}
+
+void KMIconViewItem::paintItem(QPainter *p, const QColorGroup& cg)
+{
+ if (m_state != 0)
+ {
+ QFont f(p->font());
+ if (m_state & 0x1) f.setBold(true);
+ if (m_state & 0x2) f.setItalic(true);
+ p->setFont(f);
+ }
+ QIconViewItem::paintItem(p,cg);
+}
+
+void KMIconViewItem::calcRect(const QString&)
+{
+ QRect ir(rect()), pr, tr;
+
+ // pixmap rect
+ pr.setWidth(pixmap()->width());
+ pr.setHeight(pixmap()->height());
+
+ // text rect
+ QFont f(iconView()->font());
+ if (m_state & 0x1) f.setBold(true);
+ if (m_state & 0x2) f.setItalic(true);
+ QFontMetrics fm(f);
+ if (m_mode == QIconView::Bottom)
+ tr = fm.boundingRect(0, 0, iconView()->maxItemWidth(), 0xFFFFFF, AlignHCenter|AlignTop|WordBreak|BreakAnywhere, text()+"X");
+ else
+ tr = fm.boundingRect(0, 0, 0xFFFFFF, 0xFFFFFF, AlignLeft|AlignTop, text()+"X");
+
+ // item rect
+ if (m_mode == QIconView::Bottom)
+ {
+ ir.setHeight(pr.height() + tr.height() + 15);
+ ir.setWidth(QMAX(pr.width(), tr.width()) + 10);
+ pr = QRect((ir.width()-pr.width())/2, 5, pr.width(), pr.height());
+ tr = QRect((ir.width()-tr.width())/2, 10+pr.height(), tr.width(), tr.height());
+ }
+ else
+ {
+ ir.setHeight(QMAX(pr.height(), tr.height()) + 4);
+ ir.setWidth(pr.width() + tr.width() + 6);
+ pr = QRect(2, (ir.height()-pr.height())/2, pr.width(), pr.height());
+ tr = QRect(4+pr.width(), (ir.height()-tr.height())/2, tr.width(), tr.height());
+ }
+
+ // set rects
+ setItemRect(ir);
+ setTextRect(tr);
+ setPixmapRect(pr);
+}
+
+void KMIconViewItem::updatePrinter(KMPrinter *p, int mode)
+{
+ bool update(false);
+ int oldstate = m_state;
+ if (p)
+ {
+ m_state = ((p->isHardDefault() ? 0x1 : 0x0) | (p->ownSoftDefault() ? 0x2 : 0x0) | (p->isValid() ? 0x4 : 0x0));
+ update = (oldstate != m_state);
+ if (p->name() != text() || update)
+ {
+ setText(QString::null);
+ setText(p->name());
+ }
+ setKey(QString::fromLatin1("%1_%2").arg((p->isSpecial() ? "special" : (p->isClass(false) ? "class" : "printer"))).arg(p->name()));
+ m_isclass = p->isClass(false);
+ }
+ if (mode != m_mode || ((oldstate&0x4) != (m_state&0x4)) || (p && p->pixmap() != m_pixmap))
+ {
+ int iconstate = (m_state&0x4 ? (int)KIcon::DefaultState : (int)KIcon::LockOverlay);
+ if (p)
+ m_pixmap = p->pixmap();
+ m_mode = mode;
+ if (m_mode == QIconView::Bottom)
+ setPixmap(DesktopIcon(m_pixmap, 0, iconstate));
+ else
+ setPixmap(SmallIcon(m_pixmap, 0, iconstate));
+ }
+ //if (update)
+ // repaint();
+ setDiscarded(false);
+}
+
+KMIconView::KMIconView(QWidget *parent, const char *name)
+: KIconView(parent,name)
+{
+ setMode(KIconView::Select);
+ setSelectionMode(QIconView::Single);
+ setItemsMovable(false);
+ setResizeMode(QIconView::Adjust);
+
+ m_items.setAutoDelete(false);
+ setViewMode(KMIconView::Big);
+
+ connect(this,SIGNAL(contextMenuRequested(QIconViewItem*,const QPoint&)),SLOT(slotRightButtonClicked(QIconViewItem*,const QPoint&)));
+ connect(this,SIGNAL(selectionChanged()),SLOT(slotSelectionChanged()));
+}
+
+KMIconView::~KMIconView()
+{
+}
+
+KMIconViewItem* KMIconView::findItem(KMPrinter *p)
+{
+ if (p)
+ {
+ QPtrListIterator<KMIconViewItem> it(m_items);
+ for (;it.current();++it)
+ if (it.current()->text() == p->name()
+ && it.current()->isClass() == p->isClass())
+ return it.current();
+ }
+ return 0;
+}
+
+void KMIconView::setPrinterList(QPtrList<KMPrinter> *list)
+{
+ bool changed(false);
+
+ QPtrListIterator<KMIconViewItem> it(m_items);
+ for (;it.current();++it)
+ it.current()->setDiscarded(true);
+
+ if (list)
+ {
+ QPtrListIterator<KMPrinter> it(*list);
+ KMIconViewItem *item(0);
+ for (;it.current();++it)
+ {
+ // only keep real printers (no instances)
+ if (!it.current()->instanceName().isEmpty())
+ continue;
+ item = findItem(it.current());
+ if (!item)
+ {
+ item = new KMIconViewItem(this,it.current());
+ m_items.append(item);
+ changed = true;
+ }
+ else
+ item->updatePrinter(it.current(), itemTextPos());
+ }
+ }
+
+ for (uint i=0; i<m_items.count(); i++)
+ if (m_items.at(i)->isDiscarded())
+ {
+ delete m_items.take(i);
+ i--;
+ changed = true;
+ }
+
+ if (changed) sort();
+ emit selectionChanged();
+}
+
+void KMIconView::setViewMode(ViewMode m)
+{
+ m_mode = m;
+ bool big = (m == KMIconView::Big);
+ int mode = (big ? QIconView::Bottom : QIconView::Right);
+
+ QPtrListIterator<KMIconViewItem> it(m_items);
+ for (;it.current();++it)
+ it.current()->updatePrinter(0, mode);
+
+ setArrangement((big ? QIconView::LeftToRight : QIconView::TopToBottom));
+ setItemTextPos((QIconView::ItemTextPos)mode);
+ //setGridX((big ? 60 : -1));
+ setWordWrapIconText(true);
+}
+
+void KMIconView::slotRightButtonClicked(QIconViewItem *item, const QPoint& p)
+{
+ emit rightButtonClicked(item ? item->text() : QString::null, p);
+}
+
+void KMIconView::slotSelectionChanged()
+{
+ KMIconViewItem *item = static_cast<KMIconViewItem*>(currentItem());
+ emit printerSelected((item && !item->isDiscarded() && item->isSelected() ? item->text() : QString::null));
+}
+
+void KMIconView::setPrinter(const QString& prname)
+{
+ QPtrListIterator<KMIconViewItem> it(m_items);
+ for (; it.current(); ++it)
+ if (it.current()->text() == prname)
+ {
+ setSelected(it.current(), true);
+ break;
+ }
+}
+
+void KMIconView::setPrinter(KMPrinter *p)
+{
+ setPrinter(p ? p->name() : QString::null);
+}
+
+#include "kmiconview.moc"
diff --git a/kdeprint/management/kmiconview.h b/kdeprint/management/kmiconview.h
new file mode 100644
index 000000000..1cc8daa09
--- /dev/null
+++ b/kdeprint/management/kmiconview.h
@@ -0,0 +1,78 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMICONVIEW_H
+#define KMICONVIEW_H
+
+#include <kiconview.h>
+#include <qptrlist.h>
+
+#include "kmobject.h"
+
+class KMPrinter;
+
+class KMIconViewItem : public QIconViewItem, public KMObject
+{
+public:
+ KMIconViewItem(QIconView *parent, KMPrinter *p);
+ void updatePrinter(KMPrinter *printer = 0, int mode = QIconView::Bottom);
+ bool isClass() const { return m_isclass; }
+
+protected:
+ virtual void paintItem(QPainter*, const QColorGroup&);
+ virtual void calcRect(const QString& text_ = QString::null);
+
+private:
+ int m_mode;
+ QString m_pixmap;
+ char m_state;
+ bool m_isclass;
+};
+
+class KMIconView : public KIconView
+{
+ Q_OBJECT
+public:
+ enum ViewMode { Big, Small };
+
+ KMIconView(QWidget *parent = 0, const char *name = 0);
+ ~KMIconView();
+
+ void setPrinterList(QPtrList<KMPrinter> *list);
+ void setPrinter(const QString&);
+ void setPrinter(KMPrinter*);
+ void setViewMode(ViewMode);
+
+signals:
+ void rightButtonClicked(const QString&, const QPoint&);
+ void printerSelected(const QString&);
+
+protected slots:
+ void slotRightButtonClicked(QIconViewItem*, const QPoint&);
+ void slotSelectionChanged();
+
+private:
+ KMIconViewItem* findItem(KMPrinter *p);
+
+private:
+ QPtrList<KMIconViewItem> m_items;
+ ViewMode m_mode;
+};
+
+#endif
diff --git a/kdeprint/management/kminfopage.cpp b/kdeprint/management/kminfopage.cpp
new file mode 100644
index 000000000..4366265ab
--- /dev/null
+++ b/kdeprint/management/kminfopage.cpp
@@ -0,0 +1,143 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kminfopage.h"
+#include "kmprinter.h"
+
+#include <qpixmap.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <klocale.h>
+#include <kiconloader.h>
+#include <kseparator.h>
+
+KMInfoPage::KMInfoPage(QWidget *parent, const char *name)
+: QWidget(parent,name)
+{
+ m_title = new QLabel(this);
+ m_titlepixmap = new QLabel(this);
+ m_titlepixmap->setAlignment(Qt::AlignCenter);
+ KSeparator* sep = new KSeparator( KSeparator::HLine, this);
+ m_type = new QLabel(this);
+ m_description = new QLabel(this);
+ m_state = new QLabel(this);
+ m_location = new QLabel(this);
+ m_model = new QLabel(this);
+ m_uri = new QLabel(this);
+ m_device = new QLabel(this);
+ QLabel *m_loclabel = new QLabel(i18n("Physical Location", "Location:"), this);
+ m_loclabel->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
+ QLabel *m_desclabel = new QLabel(i18n("Description:"), this);
+ m_desclabel->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
+ QLabel *m_typelabel = new QLabel(i18n("Type:"), this);
+ m_typelabel->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
+ QLabel *m_statelabel = new QLabel(i18n("Status", "State:"), this);
+ m_statelabel->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
+ QLabel *m_urilabel = new QLabel(i18n("URI:"), this);
+ m_urilabel->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
+ m_devlabel = new QLabel(i18n("Device:"), this);
+ m_devlabel->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
+ QLabel *m_modellabel = new QLabel(i18n("Model:"), this);
+ m_modellabel->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
+
+ QGridLayout *lay0 = new QGridLayout(this, 11, 2, 0, 5);
+ QHBoxLayout *lay1 = new QHBoxLayout(0, 0, 10);
+ lay0->addRowSpacing(7,20);
+ lay0->setRowStretch(7,0);
+ lay0->setRowStretch(10,1);
+ lay0->setColStretch(1,1);
+ lay0->addMultiCellLayout(lay1, 0, 0, 0, 1);
+ lay0->addMultiCellWidget(sep, 1, 1, 0, 1);
+ lay0->addWidget(m_typelabel, 2, 0);
+ lay0->addWidget(m_statelabel, 3, 0);
+ lay0->addWidget(m_loclabel, 4, 0);
+ lay0->addWidget(m_desclabel, 5, 0);
+ lay0->addWidget(m_urilabel, 6, 0);
+ lay0->addWidget(m_devlabel, 8, 0);
+ lay0->addWidget(m_modellabel, 9, 0);
+ lay0->addWidget(m_type, 2, 1);
+ lay0->addWidget(m_state, 3, 1);
+ lay0->addWidget(m_location, 4, 1);
+ lay0->addWidget(m_description, 5, 1);
+ lay0->addWidget(m_uri, 6, 1);
+ lay0->addWidget(m_device, 8, 1);
+ lay0->addWidget(m_model, 9, 1);
+ lay1->addWidget(m_title, 1);
+ lay1->addWidget(m_titlepixmap, 0);
+}
+
+KMInfoPage::~KMInfoPage()
+{
+}
+
+void KMInfoPage::setPrinter(KMPrinter *p)
+{
+ // change "Device" label if it's a real class (not true for implicit classes)
+ if (p && p->isClass(false)) m_devlabel->setText(i18n("Members:"));
+ else m_devlabel->setText(i18n("Device:"));
+
+ // clear everything if p == 0
+ if (!p)
+ {
+ m_title->setText(QString::null);
+ m_titlepixmap->setPixmap(QPixmap());
+ m_type->setText(QString::null);
+ m_state->setText(QString::null);
+ m_location->setText(QString::null);
+ m_description->setText(QString::null);
+ m_uri->setText(QString::null);
+ m_device->setText(QString::null);
+ m_model->setText(QString::null);
+ }
+ else
+ {
+ m_title->setText(QString::fromLatin1("<b>%1</b>").arg(p->name()));
+ m_titlepixmap->setPixmap(SmallIcon(p->pixmap()));
+ if (p->isImplicit()) m_type->setText(i18n("Implicit class"));
+ else if (p->isClass(false))
+ if (p->isRemote()) m_type->setText(i18n("Remote class"));
+ else m_type->setText(i18n("Local class"));
+ else if (p->isPrinter())
+ if (p->isRemote()) m_type->setText(i18n("Remote printer"));
+ else m_type->setText(i18n("Local printer"));
+ else if (p->isSpecial())
+ m_type->setText(i18n("Special (pseudo) printer"));
+ else m_type->setText(i18n("Unknown class of printer", "Unknown"));
+ m_state->setText(p->stateString());
+ m_location->setText(p->location());
+ m_description->setText(p->description());
+ m_uri->setText(p->uri().prettyURL());
+ if (p->isClass(false))
+ {
+ QString s;
+ for (QStringList::ConstIterator it=p->members().begin(); it!=p->members().end(); ++it)
+ s.append(KURL(*it).prettyURL() + ", ");
+ s.truncate(s.length()-2);
+ m_device->setText(s);
+ }
+ else
+ {
+ // double decoding in case printer name contains
+ // annoying chars like '#'
+ KURL dev(p->device());
+ m_device->setText(KURL::decode_string(dev.prettyURL()));
+ }
+ m_model->setText(p->driverInfo());
+ }
+}
diff --git a/kdeprint/management/kminfopage.h b/kdeprint/management/kminfopage.h
new file mode 100644
index 000000000..a93aa1296
--- /dev/null
+++ b/kdeprint/management/kminfopage.h
@@ -0,0 +1,42 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMINFOPAGE_H
+#define KMINFOPAGE_H
+
+#include "kmprinterpage.h"
+#include <qwidget.h>
+
+class QLabel;
+
+class KMInfoPage : public QWidget, public KMPrinterPage
+{
+public:
+ KMInfoPage(QWidget *parent = 0, const char *name = 0);
+ ~KMInfoPage();
+
+ void setPrinter(KMPrinter *p);
+
+protected:
+ QLabel *m_title, *m_titlepixmap;
+ QLabel *m_location, *m_description, *m_uri, *m_model, *m_type, *m_state, *m_device;
+ QLabel *m_devlabel;
+};
+
+#endif
diff --git a/kdeprint/management/kminstancepage.cpp b/kdeprint/management/kminstancepage.cpp
new file mode 100644
index 000000000..d4bb32687
--- /dev/null
+++ b/kdeprint/management/kminstancepage.cpp
@@ -0,0 +1,276 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kminstancepage.h"
+#include "kmprinter.h"
+#include "kmfactory.h"
+#include "kmvirtualmanager.h"
+#include "kmmanager.h"
+#include "kprinterpropertydialog.h"
+#include "kprinter.h"
+#include "kmtimer.h"
+
+#include <qlayout.h>
+#include <qregexp.h>
+#include <qwhatsthis.h>
+#include <qpushbutton.h>
+#include <kmessagebox.h>
+#include <kinputdialog.h>
+#include <klistbox.h>
+#include <klocale.h>
+#include <kiconloader.h>
+#include <kstandarddirs.h>
+#include <kdebug.h>
+
+KMInstancePage::KMInstancePage(QWidget *parent, const char *name)
+: QWidget(parent,name)
+{
+ m_view = new KListBox(this);
+ m_printer = 0;
+
+ initActions();
+
+ QHBoxLayout *main_ = new QHBoxLayout(this, 0, 0);
+ main_->addWidget(m_view);
+ QVBoxLayout *sub_ = new QVBoxLayout(0, 0, 0);
+ main_->addLayout(sub_);
+ for (QValueList<QButton*>::Iterator it=m_buttons.begin(); it!=m_buttons.end(); ++it)
+ if (*it)
+ sub_->addWidget(*it);
+ else
+ sub_->addSpacing(10);
+ sub_->addStretch(1);
+
+ QWhatsThis::add(this,
+ i18n("Define/Edit here instances for the current selected "
+ "printer. An instance is a combination of a real "
+ "(physical) printer and a set of predefined options. "
+ "For a single InkJet printer, you could define different "
+ "print formats like <i>DraftQuality</i>, <i>PhotoQuality</i> "
+ "or <i>TwoSided</i>. Those instances appear as normal "
+ "printers in the print dialog and allow you to quickly "
+ "select the print format you want."));
+}
+
+KMInstancePage::~KMInstancePage()
+{
+}
+
+void KMInstancePage::addButton(const QString& txt, const QString& pixmap, const char *receiver)
+{
+ QPushButton *btn = new QPushButton(this, 0L);
+ btn->setText(txt);
+ btn->setIconSet(BarIconSet(pixmap));
+ btn->setFlat(true);
+ connect(btn, SIGNAL(clicked()), receiver);
+ m_buttons.append(btn);
+}
+
+void KMInstancePage::initActions()
+{
+ addButton(i18n("New..."), "filenew", SLOT(slotNew()));
+ addButton(i18n("Copy..."), "editcopy", SLOT(slotCopy()));
+ addButton(i18n("Remove"), "edittrash", SLOT(slotRemove()));
+ m_buttons.append(0);
+ addButton(i18n("Set as Default"), "exec", SLOT(slotDefault()));
+ addButton(i18n("Settings"), "configure", SLOT(slotSettings()));
+ m_buttons.append(0);
+ addButton(i18n("Test..."), "fileprint", SLOT(slotTest()));
+}
+
+void KMInstancePage::setPrinter(KMPrinter *p)
+{
+ QString oldText = m_view->currentText();
+
+ m_view->clear();
+ m_printer = p;
+ //bool ok = (p && !p->isSpecial());
+ bool ok = (p != 0);
+ if (ok)
+ {
+ QPtrList<KMPrinter> list;
+ KMFactory::self()->virtualManager()->virtualList(list,p->name());
+ QPtrListIterator<KMPrinter> it(list);
+ for (;it.current();++it)
+ {
+ QStringList pair = QStringList::split('/',it.current()->name(),false);
+ m_view->insertItem(SmallIcon((it.current()->isSoftDefault() ? "exec" : "fileprint")),(pair.count() > 1 ? pair[1] : i18n("(Default)")));
+ }
+ m_view->sort();
+ }
+
+ for (QValueList<QButton*>::ConstIterator it=m_buttons.begin(); it!=m_buttons.end(); ++it)
+ if (*it)
+ (*it)->setEnabled(ok);
+
+ //iif (!oldText.isEmpty())
+ //{
+ QListBoxItem *item = m_view->findItem(oldText);
+ if (!item)
+ item = m_view->findItem(i18n("(Default)"));
+ if (item)
+ m_view->setSelected(item,true);
+ //}
+}
+
+void KMInstancePage::slotNew()
+{
+ KMTimer::self()->hold();
+
+ bool ok(false);
+ QString name = KInputDialog::getText(i18n("Instance Name"),i18n("Enter name for new instance (leave untouched for default):"),
+ i18n("(Default)"),&ok,this);
+ if (ok)
+ {
+ if (name.find(QRegExp("[/\\s]")) != -1)
+ KMessageBox::error(this, i18n("Instance name must not contain any spaces or slashes."));
+ else
+ {
+ if (name == i18n("(Default)"))
+ name = QString::null;
+ KMFactory::self()->virtualManager()->create(m_printer,name);
+ setPrinter(m_printer);
+ }
+ }
+
+ KMTimer::self()->release();
+}
+
+void KMInstancePage::slotRemove()
+{
+ KMTimer::self()->hold();
+ bool reload(false);
+
+ QString src = m_view->currentText();
+ QString msg = (src != i18n("(Default)") ? i18n("Do you really want to remove instance %1?") : i18n("You can't remove the default instance. However all settings of %1 will be discarded. Continue?"));
+ if (!src.isEmpty() && KMessageBox::warningContinueCancel(this,msg.arg(src),QString::null,KStdGuiItem::del()) == KMessageBox::Continue)
+ {
+ if (src == i18n("(Default)"))
+ src = QString::null;
+ reload = KMFactory::self()->virtualManager()->isDefault(m_printer,src);
+ KMFactory::self()->virtualManager()->remove(m_printer,src);
+ setPrinter(m_printer);
+ }
+
+ KMTimer::self()->release(reload);
+}
+
+void KMInstancePage::slotCopy()
+{
+ KMTimer::self()->hold();
+
+ QString src = m_view->currentText();
+ if (!src.isEmpty())
+ {
+ bool ok(false);
+ QString name = KInputDialog::getText(i18n("Instance Name"),i18n("Enter name for new instance (leave untouched for default):"),
+ i18n("(Default)"),&ok,this);
+ if (ok)
+ {
+ if (name.find(QRegExp("[/\\s]")) != -1)
+ KMessageBox::error(this, i18n("Instance name must not contain any spaces or slashes."));
+ else
+ {
+ if (src == i18n("(Default)"))
+ src = QString::null;
+ if (name == i18n("(Default)"))
+ name = QString::null;
+ KMFactory::self()->virtualManager()->copy(m_printer,src,name);
+ setPrinter(m_printer);
+ }
+ }
+ }
+
+ KMTimer::self()->release();
+}
+
+void KMInstancePage::slotSettings()
+{
+ KMTimer::self()->hold();
+
+ QString src = m_view->currentText();
+ if (!src.isEmpty())
+ {
+ if (src == i18n("(Default)")) src = QString::null;
+ KMPrinter *pr = KMFactory::self()->virtualManager()->findInstance(m_printer,src);
+ if ( !pr )
+ KMessageBox::error( this, i18n( "Unable to find instance %1." ).arg( m_view->currentText() ) );
+ else if ( !pr->isSpecial() && !KMFactory::self()->manager()->completePrinterShort( pr ) )
+ KMessageBox::error( this, i18n( "Unable to retrieve printer information. Message from printing system: %1." ).arg( KMFactory::self()->manager()->errorMsg() ) );
+ else
+ {
+ int oldAppType = KMFactory::self()->settings()->application;
+ KMFactory::self()->settings()->application = -1;
+ KPrinterPropertyDialog::setupPrinter(pr, this);
+ KMFactory::self()->settings()->application = oldAppType;
+ if (pr->isEdited())
+ { // printer edited, need to save changes
+ pr->setDefaultOptions(pr->editedOptions());
+ pr->setEditedOptions(QMap<QString,QString>());
+ pr->setEdited(false);
+ KMFactory::self()->virtualManager()->triggerSave();
+ }
+ }
+ }
+ else
+ KMessageBox::error( this, i18n( "The instance name is empty. Please select an instance." ) );
+
+ KMTimer::self()->release();
+}
+
+void KMInstancePage::slotDefault()
+{
+ KMTimer::self()->hold();
+
+ QString src = m_view->currentText();
+ if (!src.isEmpty())
+ {
+ if (src == i18n("(Default)"))
+ src = QString::null;
+ KMFactory::self()->virtualManager()->setAsDefault(m_printer,src);
+ setPrinter(m_printer);
+ }
+
+ KMTimer::self()->release(true);
+}
+
+void KMInstancePage::slotTest()
+{
+ KMTimer::self()->hold();
+
+ QString src = m_view->currentText();
+ if (!src.isEmpty())
+ {
+ if (src == i18n("(Default)"))
+ src = QString::null;
+ KMPrinter *mpr = KMFactory::self()->virtualManager()->findInstance(m_printer,src);
+ if (!mpr)
+ KMessageBox::error(this,i18n("Internal error: printer not found."));
+ else if (KMessageBox::warningContinueCancel(this, i18n("You are about to print a test page on %1. Do you want to continue?").arg(mpr->printerName()), QString::null, i18n("Print Test Page"), "printTestPage") == KMessageBox::Continue)
+ {
+ if (!KMFactory::self()->virtualManager()->testInstance(mpr))
+ KMessageBox::error(this, i18n("Unable to send test page to %1.").arg(mpr->printerName()));
+ else
+ KMessageBox::information(this,i18n("Test page successfully sent to printer %1.").arg(mpr->printerName()));
+ }
+ }
+
+ KMTimer::self()->release(false);
+}
+#include "kminstancepage.moc"
diff --git a/kdeprint/management/kminstancepage.h b/kdeprint/management/kminstancepage.h
new file mode 100644
index 000000000..d85a4bdb9
--- /dev/null
+++ b/kdeprint/management/kminstancepage.h
@@ -0,0 +1,58 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMINSTANCEPAGE_H
+#define KMINSTANCEPAGE_H
+
+#include "kmprinterpage.h"
+#include <qvaluelist.h>
+#include <qwidget.h>
+
+class KListBox;
+class KMPrinter;
+class QButton;
+
+class KMInstancePage : public QWidget, public KMPrinterPage
+{
+ Q_OBJECT
+public:
+ KMInstancePage(QWidget *parent = 0, const char *name = 0);
+ ~KMInstancePage();
+
+ void setPrinter(KMPrinter*);
+
+protected slots:
+ void slotNew();
+ void slotCopy();
+ void slotRemove();
+ void slotDefault();
+ void slotTest();
+ void slotSettings();
+
+protected:
+ void initActions();
+ void addButton(const QString& text, const QString& pixmap, const char *receiver);
+
+private:
+ KListBox *m_view;
+ QValueList<QButton*> m_buttons;
+ KMPrinter *m_printer;
+};
+
+#endif
diff --git a/kdeprint/management/kmjobviewer.cpp b/kdeprint/management/kmjobviewer.cpp
new file mode 100644
index 000000000..bc27d0928
--- /dev/null
+++ b/kdeprint/management/kmjobviewer.cpp
@@ -0,0 +1,742 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmjobviewer.h"
+#include "kmjobmanager.h"
+#include "kmfactory.h"
+#include "kmjob.h"
+#include "kmprinter.h"
+#include "kmmanager.h"
+#include "kmuimanager.h"
+#include "jobitem.h"
+#include "kmtimer.h"
+#include "kmconfigjobs.h"
+#include "kmconfigpage.h"
+#include "kprinter.h"
+
+#include <klistview.h>
+#include <kstatusbar.h>
+#include <qpopupmenu.h>
+#include <kmessagebox.h>
+#include <klocale.h>
+#include <kpopupmenu.h>
+#include <kaction.h>
+#include <kstdaction.h>
+#include <kiconloader.h>
+#include <kapplication.h>
+#include <kcursor.h>
+#include <kmenubar.h>
+#include <kdebug.h>
+#include <kwin.h>
+#include <kio/netaccess.h>
+#include <qtimer.h>
+#include <qlayout.h>
+#include <stdlib.h>
+#include <qlineedit.h>
+#include <kdialogbase.h>
+#include <qcheckbox.h>
+#include <kurldrag.h>
+#include <kconfig.h>
+
+#undef m_manager
+#define m_manager KMFactory::self()->jobManager()
+
+class KJobListView : public KListView
+{
+public:
+ KJobListView( QWidget *parent = 0, const char *name = 0 );
+
+protected:
+ bool acceptDrag( QDropEvent* ) const;
+};
+
+KJobListView::KJobListView( QWidget *parent, const char *name )
+ : KListView( parent, name )
+{
+ setAcceptDrops( true );
+ setDropVisualizer( false );
+}
+
+bool KJobListView::acceptDrag( QDropEvent *e ) const
+{
+ if ( KURLDrag::canDecode( e ) )
+ return true;
+ else
+ return KListView::acceptDrag( e );
+}
+
+KMJobViewer::KMJobViewer(QWidget *parent, const char *name)
+: KMainWindow(parent,name)
+{
+ m_view = 0;
+ m_pop = 0;
+ m_jobs.setAutoDelete(false);
+ m_items.setAutoDelete(false);
+ m_printers.setAutoDelete(false);
+ m_type = KMJobManager::ActiveJobs;
+ m_stickybox = 0;
+ m_standalone = ( parent == NULL );
+
+ setToolBarsMovable(false);
+ init();
+
+ if (m_standalone)
+ {
+ setCaption(i18n("No Printer"));
+ KConfig *conf = KMFactory::self()->printConfig();
+ QSize defSize( 550, 250 );
+ conf->setGroup( "Jobs" );
+ resize( conf->readSizeEntry( "Size", &defSize ) );
+ }
+}
+
+KMJobViewer::~KMJobViewer()
+{
+ if (m_standalone)
+ {
+ kdDebug( 500 ) << "Destroying stand-alone job viewer window" << endl;
+ KConfig *conf = KMFactory::self()->printConfig();
+ conf->setGroup( "Jobs" );
+ conf->writeEntry( "Size", size() );
+ emit viewerDestroyed(this);
+ }
+ removeFromManager();
+}
+
+void KMJobViewer::setPrinter(KMPrinter *p)
+{
+ setPrinter((p ? p->printerName() : QString::null));
+}
+
+void KMJobViewer::setPrinter(const QString& prname)
+{
+ // We need to trigger a refresh even if the printer
+ // has not changed, some jobs may have been canceled
+ // outside kdeprint. We can't return simply if
+ // prname == m_prname.
+ if (m_prname != prname)
+ {
+ removeFromManager();
+ m_prname = prname;
+ addToManager();
+ m_view->setAcceptDrops( prname != i18n( "All Printers" ) );
+ }
+ triggerRefresh();
+}
+
+void KMJobViewer::updateCaption()
+{
+ if (!m_standalone)
+ return;
+
+ QString pixname("fileprint");
+ if (!m_prname.isEmpty())
+ {
+ setCaption(i18n("Print Jobs for %1").arg(m_prname));
+ KMPrinter *prt = KMManager::self()->findPrinter(m_prname);
+ if (prt)
+ pixname = prt->pixmap();
+ }
+ else
+ {
+ setCaption(i18n("No Printer"));
+ }
+ KWin::setIcons(winId(), DesktopIcon(pixname), SmallIcon(pixname));
+}
+
+void KMJobViewer::updateStatusBar()
+{
+ if (!m_standalone)
+ return;
+
+ int limit = m_manager->limit();
+ if (limit == 0)
+ statusBar()->changeItem(i18n("Max.: %1").arg(i18n("Unlimited")), 0);
+ else
+ statusBar()->changeItem(i18n("Max.: %1").arg(limit), 0);
+}
+
+void KMJobViewer::addToManager()
+{
+ if (m_prname == i18n("All Printers"))
+ {
+ loadPrinters();
+ QPtrListIterator<KMPrinter> it(m_printers);
+ for (; it.current(); ++it)
+ m_manager->addPrinter(it.current()->printerName(), (KMJobManager::JobType)m_type, it.current()->isSpecial());
+ }
+ else if (!m_prname.isEmpty())
+ {
+ KMPrinter *prt = KMManager::self()->findPrinter( m_prname );
+ bool isSpecial = ( prt ? prt->isSpecial() : false );
+ m_manager->addPrinter(m_prname, (KMJobManager::JobType)m_type, isSpecial);
+ }
+}
+
+void KMJobViewer::removeFromManager()
+{
+ if (m_prname == i18n("All Printers"))
+ {
+ QPtrListIterator<KMPrinter> it(m_printers);
+ for (; it.current(); ++it)
+ m_manager->removePrinter(it.current()->printerName(), (KMJobManager::JobType)m_type);
+ }
+ else if (!m_prname.isEmpty())
+ {
+ m_manager->removePrinter(m_prname, (KMJobManager::JobType)m_type);
+ }
+}
+
+void KMJobViewer::refresh(bool reload)
+{
+ m_jobs.clear();
+ QPtrListIterator<KMJob> it(m_manager->jobList(reload));
+ bool all = (m_prname == i18n("All Printers")), active = (m_type == KMJobManager::ActiveJobs);
+ for (; it.current(); ++it)
+ if ((all || it.current()->printer() == m_prname)
+ && ((it.current()->state() >= KMJob::Cancelled && !active)
+ || (it.current()->state() < KMJob::Cancelled && active))
+ && (m_username.isEmpty() || m_username == it.current()->owner()))
+ m_jobs.append(it.current());
+ updateJobs();
+
+
+ // update the caption and icon (doesn't do anything if it has a parent widget)
+ updateCaption();
+
+ updateStatusBar();
+
+ // do it last as this signal can cause this view to be destroyed. No
+ // code can be executed safely after that
+ emit jobsShown(this, (m_jobs.count() != 0));
+}
+
+void KMJobViewer::init()
+{
+ if (!m_view)
+ {
+ m_view = new KJobListView(this);
+ m_view->addColumn(i18n("Job ID"));
+ m_view->addColumn(i18n("Owner"));
+ m_view->addColumn(i18n("Name"), 150);
+ m_view->addColumn(i18n("Status", "State"));
+ m_view->addColumn(i18n("Size (KB)"));
+ m_view->addColumn(i18n("Page(s)"));
+ m_view->setColumnAlignment(5,Qt::AlignRight|Qt::AlignVCenter);
+ connect( m_view, SIGNAL( dropped( QDropEvent*, QListViewItem* ) ), SLOT( slotDropped( QDropEvent*, QListViewItem* ) ) );
+ //m_view->addColumn(i18n("Printer"));
+ //m_view->setColumnAlignment(6,Qt::AlignRight|Qt::AlignVCenter);
+ KMFactory::self()->uiManager()->setupJobViewer(m_view);
+ m_view->setFrameStyle(QFrame::WinPanel|QFrame::Sunken);
+ m_view->setLineWidth(1);
+ m_view->setSorting(0);
+ m_view->setAllColumnsShowFocus(true);
+ m_view->setSelectionMode(QListView::Extended);
+ connect(m_view,SIGNAL(selectionChanged()),SLOT(slotSelectionChanged()));
+ connect(m_view,SIGNAL(rightButtonPressed(QListViewItem*,const QPoint&,int)),SLOT(slotRightClicked(QListViewItem*,const QPoint&,int)));
+ setCentralWidget(m_view);
+ }
+
+ initActions();
+}
+
+void KMJobViewer::initActions()
+{
+ // job actions
+ KAction *hact = new KAction(i18n("&Hold"),"stop",0,this,SLOT(slotHold()),actionCollection(),"job_hold");
+ KAction *ract = new KAction(i18n("&Resume"),"run",0,this,SLOT(slotResume()),actionCollection(),"job_resume");
+ KAction *dact = new KAction(i18n("Remo&ve"),"edittrash",Qt::Key_Delete,this,SLOT(slotRemove()),actionCollection(),"job_remove");
+ KAction *sact = new KAction(i18n("Res&tart"),"redo",0,this,SLOT(slotRestart()),actionCollection(),"job_restart");
+ KActionMenu *mact = new KActionMenu(i18n("&Move to Printer"),"fileprint",actionCollection(),"job_move");
+ mact->setDelayed(false);
+ connect(mact->popupMenu(),SIGNAL(activated(int)),SLOT(slotMove(int)));
+ connect(mact->popupMenu(),SIGNAL(aboutToShow()),KMTimer::self(),SLOT(hold()));
+ connect(mact->popupMenu(),SIGNAL(aboutToHide()),KMTimer::self(),SLOT(release()));
+ connect(mact->popupMenu(),SIGNAL(aboutToShow()),SLOT(slotShowMoveMenu()));
+ KToggleAction *tact = new KToggleAction(i18n("&Toggle Completed Jobs"),"history",0,actionCollection(),"view_completed");
+ tact->setEnabled(m_manager->actions() & KMJob::ShowCompleted);
+ connect(tact,SIGNAL(toggled(bool)),SLOT(slotShowCompleted(bool)));
+ KToggleAction *uact = new KToggleAction(i18n("Show Only User Jobs"), "personal", 0, actionCollection(), "view_user_jobs");
+ uact->setCheckedState(KGuiItem(i18n("Hide Only User Jobs"),"personal"));
+ connect(uact, SIGNAL(toggled(bool)), SLOT(slotUserOnly(bool)));
+ m_userfield = new QLineEdit(0);
+ m_userfield->setText(getenv("USER"));
+ connect(m_userfield, SIGNAL(returnPressed()), SLOT(slotUserChanged()));
+ connect(uact, SIGNAL(toggled(bool)), m_userfield, SLOT(setEnabled(bool)));
+ m_userfield->setEnabled(false);
+ m_userfield->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
+ KWidgetAction *ufact = new KWidgetAction(m_userfield, i18n("User Name"), 0, 0, 0, actionCollection(), "view_username");
+
+ if (!m_pop)
+ {
+ m_pop = new QPopupMenu(this);
+ connect(m_pop,SIGNAL(aboutToShow()),KMTimer::self(),SLOT(hold()));
+ connect(m_pop,SIGNAL(aboutToHide()),KMTimer::self(),SLOT(release()));
+ hact->plug(m_pop);
+ ract->plug(m_pop);
+ m_pop->insertSeparator();
+ dact->plug(m_pop);
+ mact->plug(m_pop);
+ m_pop->insertSeparator();
+ sact->plug(m_pop);
+ }
+
+ // Filter actions
+ KActionMenu *fact = new KActionMenu(i18n("&Select Printer"), "kdeprint_printer", actionCollection(), "filter_modify");
+ fact->setDelayed(false);
+ connect(fact->popupMenu(),SIGNAL(activated(int)),SLOT(slotPrinterSelected(int)));
+ connect(fact->popupMenu(),SIGNAL(aboutToShow()),KMTimer::self(),SLOT(hold()));
+ connect(fact->popupMenu(),SIGNAL(aboutToHide()),KMTimer::self(),SLOT(release()));
+ connect(fact->popupMenu(),SIGNAL(aboutToShow()),SLOT(slotShowPrinterMenu()));
+
+ if (!m_standalone)
+ {
+ KToolBar *toolbar = toolBar();
+ hact->plug(toolbar);
+ ract->plug(toolbar);
+ toolbar->insertSeparator();
+ dact->plug(toolbar);
+ mact->plug(toolbar);
+ toolbar->insertSeparator();
+ sact->plug(toolbar);
+ toolbar->insertSeparator();
+ tact->plug(toolbar);
+ uact->plug(toolbar);
+ ufact->plug(toolbar);
+ }
+ else
+ {// stand-alone application
+ KStdAction::quit(kapp,SLOT(quit()),actionCollection());
+ KStdAction::close(this,SLOT(slotClose()),actionCollection());
+ KStdAction::preferences(this, SLOT(slotConfigure()), actionCollection());
+
+ // refresh action
+ new KAction(i18n("Refresh"),"reload",0,this,SLOT(slotRefresh()),actionCollection(),"refresh");
+
+ // create status bar
+ KStatusBar *statusbar = statusBar();
+ m_stickybox = new QCheckBox( i18n( "Keep window permanent" ), statusbar );
+ statusbar->addWidget( m_stickybox, 1, false );
+ statusbar->insertItem(" " + i18n("Max.: %1").arg(i18n("Unlimited"))+ " ", 0, 0, true);
+ statusbar->setItemFixed(0);
+ updateStatusBar();
+
+ createGUI();
+ }
+
+ loadPluginActions();
+ slotSelectionChanged();
+}
+
+void KMJobViewer::buildPrinterMenu(QPopupMenu *menu, bool use_all, bool use_specials)
+{
+ loadPrinters();
+ menu->clear();
+
+ QPtrListIterator<KMPrinter> it(m_printers);
+ int i(0);
+ if (use_all)
+ {
+ menu->insertItem(SmallIcon("fileprint"), i18n("All Printers"), i++);
+ menu->insertSeparator();
+ }
+ for (; it.current(); ++it, i++)
+ {
+ if ( !it.current()->instanceName().isEmpty() ||
+ ( it.current()->isSpecial() && !use_specials ) )
+ continue;
+ menu->insertItem(SmallIcon(it.current()->pixmap()), it.current()->printerName(), i);
+ }
+}
+
+void KMJobViewer::slotShowMoveMenu()
+{
+ QPopupMenu *menu = static_cast<KActionMenu*>(actionCollection()->action("job_move"))->popupMenu();
+ buildPrinterMenu(menu, false, false);
+}
+
+void KMJobViewer::slotShowPrinterMenu()
+{
+ QPopupMenu *menu = static_cast<KActionMenu*>(actionCollection()->action("filter_modify"))->popupMenu();
+ buildPrinterMenu(menu, true, true);
+}
+
+void KMJobViewer::updateJobs()
+{
+ QPtrListIterator<JobItem> jit(m_items);
+ for (;jit.current();++jit)
+ jit.current()->setDiscarded(true);
+
+ QPtrListIterator<KMJob> it(m_jobs);
+ for (;it.current();++it)
+ {
+ KMJob *j(it.current());
+ JobItem *item = findItem(j->uri());
+ if (item)
+ {
+ item->setDiscarded(false);
+ item->init(j);
+ }
+ else
+ m_items.append(new JobItem(m_view,j));
+ }
+
+ for (uint i=0; i<m_items.count(); i++)
+ if (m_items.at(i)->isDiscarded())
+ {
+ delete m_items.take(i);
+ i--;
+ }
+
+ slotSelectionChanged();
+}
+
+JobItem* KMJobViewer::findItem(const QString& uri)
+{
+ QPtrListIterator<JobItem> it(m_items);
+ for (;it.current();++it)
+ if (it.current()->jobUri() == uri) return it.current();
+ return 0;
+}
+
+void KMJobViewer::slotSelectionChanged()
+{
+ int acts = m_manager->actions();
+ int state(-1);
+ int thread(0);
+ bool completed(true), remote(false);
+
+ QPtrListIterator<JobItem> it(m_items);
+ QPtrList<KMJob> joblist;
+
+ joblist.setAutoDelete(false);
+ for (;it.current();++it)
+ {
+ if (it.current()->isSelected())
+ {
+ // check if threaded job. "thread" value will be:
+ // 0 -> no jobs
+ // 1 -> only thread jobs
+ // 2 -> only system jobs
+ // 3 -> thread and system jobs
+ if (it.current()->job()->type() == KMJob::Threaded) thread |= 0x1;
+ else thread |= 0x2;
+
+ if (state == -1) state = it.current()->job()->state();
+ else if (state != 0 && state != it.current()->job()->state()) state = 0;
+
+ completed = (completed && it.current()->job()->isCompleted());
+ joblist.append(it.current()->job());
+ if (it.current()->job()->isRemote())
+ remote = true;
+ }
+ }
+ if (thread != 2)
+ joblist.clear();
+
+ actionCollection()->action("job_remove")->setEnabled((thread == 1) || (/*!remote &&*/ !completed && (state >= 0) && (acts & KMJob::Remove)));
+ actionCollection()->action("job_hold")->setEnabled(/*!remote &&*/ !completed && (thread == 2) && (state > 0) && (state != KMJob::Held) && (acts & KMJob::Hold));
+ actionCollection()->action("job_resume")->setEnabled(/*!remote &&*/ !completed && (thread == 2) && (state > 0) && (state == KMJob::Held) && (acts & KMJob::Resume));
+ actionCollection()->action("job_move")->setEnabled(!remote && !completed && (thread == 2) && (state >= 0) && (acts & KMJob::Move));
+ actionCollection()->action("job_restart")->setEnabled(!remote && (thread == 2) && (state >= 0) && (completed) && (acts & KMJob::Restart));
+
+ m_manager->validatePluginActions(actionCollection(), joblist);
+}
+
+void KMJobViewer::jobSelection(QPtrList<KMJob>& l)
+{
+ l.setAutoDelete(false);
+ QPtrListIterator<JobItem> it(m_items);
+ for (;it.current();++it)
+ if (it.current()->isSelected())
+ l.append(it.current()->job());
+}
+
+void KMJobViewer::send(int cmd, const QString& name, const QString& arg)
+{
+ KMTimer::self()->hold();
+
+ QPtrList<KMJob> l;
+ jobSelection(l);
+ if (!m_manager->sendCommand(l,cmd,arg))
+ {
+ KMessageBox::error(this,"<qt>"+i18n("Unable to perform action \"%1\" on selected jobs. Error received from manager:").arg(name)+"<p>"+KMManager::self()->errorMsg()+"</p></qt>");
+ // error reported, clean it
+ KMManager::self()->setErrorMsg(QString::null);
+ }
+
+ triggerRefresh();
+
+ KMTimer::self()->release();
+}
+
+void KMJobViewer::slotHold()
+{
+ send(KMJob::Hold,i18n("Hold"));
+}
+
+void KMJobViewer::slotResume()
+{
+ send(KMJob::Resume,i18n("Resume"));
+}
+
+void KMJobViewer::slotRemove()
+{
+ send(KMJob::Remove,i18n("Remove"));
+}
+
+void KMJobViewer::slotRestart()
+{
+ send(KMJob::Restart,i18n("Restart"));
+}
+
+void KMJobViewer::slotMove(int prID)
+{
+ if (prID >= 0 && prID < (int)(m_printers.count()))
+ {
+ KMPrinter *p = m_printers.at(prID);
+ send(KMJob::Move,i18n("Move to %1").arg(p->printerName()),p->printerName());
+ }
+}
+
+void KMJobViewer::slotRightClicked(QListViewItem*,const QPoint& p,int)
+{
+ if (m_pop) m_pop->popup(p);
+}
+
+void KMJobViewer::loadPrinters()
+{
+ m_printers.clear();
+
+ // retrieve printer list without reloading it (faster)
+ QPtrListIterator<KMPrinter> it(*(KMFactory::self()->manager()->printerList(false)));
+ for (;it.current();++it)
+ {
+ // keep only real printers (no instance, no implicit) and special printers
+ if ((it.current()->isPrinter() || it.current()->isClass(false) ||
+ ( it.current()->isSpecial() && it.current()->isValid() ) )
+ && (it.current()->name() == it.current()->printerName()))
+ m_printers.append(it.current());
+ }
+}
+
+void KMJobViewer::slotPrinterSelected(int prID)
+{
+ if (prID >= 0 && prID < (int)(m_printers.count()+1))
+ {
+ QString prname = (prID == 0 ? i18n("All Printers") : m_printers.at(prID-1)->printerName());
+ emit printerChanged(this, prname);
+ }
+}
+
+void KMJobViewer::slotRefresh()
+{
+ triggerRefresh();
+}
+
+void KMJobViewer::triggerRefresh()
+{
+ // parent widget -> embedded in KControl and needs
+ // to update itself. Otherwise, it's standalone
+ // kjobviewer and we need to synchronize all possible
+ // opened windows -> do the job on higher level.
+ if (!m_standalone)
+ refresh(true);
+ else
+ emit refreshClicked();
+}
+
+void KMJobViewer::slotShowCompleted(bool on)
+{
+ removeFromManager();
+ m_type = (on ? KMJobManager::CompletedJobs : KMJobManager::ActiveJobs);
+ addToManager();
+ triggerRefresh();
+}
+
+void KMJobViewer::slotClose()
+{
+ delete this;
+}
+
+void KMJobViewer::loadPluginActions()
+{
+ int mpopindex(7), toolbarindex(!m_standalone?7:8), menuindex(7);
+ QMenuData *menu(0);
+
+ if (m_standalone)
+ {
+ // standalone window, insert actions into main menubar
+ KAction *act = actionCollection()->action("job_restart");
+ for (int i=0;i<act->containerCount();i++)
+ {
+ if (menuBar()->findItem(act->itemId(i), &menu))
+ {
+ menuindex = mpopindex = menu->indexOf(act->itemId(i))+1;
+ break;
+ }
+ }
+ }
+
+ QValueList<KAction*> acts = m_manager->createPluginActions(actionCollection());
+ for (QValueListIterator<KAction*> it=acts.begin(); it!=acts.end(); ++it)
+ {
+ // connect the action to this
+ connect((*it), SIGNAL(activated(int)), SLOT(pluginActionActivated(int)));
+
+ // should add it to the toolbar and menubar
+ (*it)->plug(toolBar(), toolbarindex++);
+ if (m_pop)
+ (*it)->plug(m_pop, mpopindex++);
+ if (menu)
+ (*it)->plug(static_cast<QPopupMenu*>(menu), menuindex++);
+ }
+}
+
+void KMJobViewer::removePluginActions()
+{
+ QValueList<KAction*> acts = actionCollection()->actions("plugin");
+ for (QValueListIterator<KAction*> it=acts.begin(); it!=acts.end(); ++it)
+ {
+ (*it)->unplugAll();
+ delete (*it);
+ }
+}
+
+/*
+void KMJobViewer::aboutToReload()
+{
+ if (m_view)
+ {
+ m_view->clear();
+ m_items.clear();
+ }
+ m_jobs.clear();
+}
+*/
+
+void KMJobViewer::reload()
+{
+ removePluginActions();
+ loadPluginActions();
+ // re-add the current printer to the job manager: the job
+ // manager has been destroyed, so the new one doesn't know
+ // which printer it has to list
+ addToManager();
+ // no refresh needed: view has been cleared before reloading
+ // and the actual refresh will be triggered either by the KControl
+ // module, or by KJobViewerApp using timer.
+
+ // reload the columns needed: remove the old one
+ for (int c=m_view->columns()-1; c>5; c--)
+ m_view->removeColumn(c);
+ KMFactory::self()->uiManager()->setupJobViewer(m_view);
+
+ // update the "History" action state
+ actionCollection()->action("view_completed")->setEnabled(m_manager->actions() & KMJob::ShowCompleted);
+ static_cast<KToggleAction*>(actionCollection()->action("view_completed"))->setChecked(false);
+}
+
+void KMJobViewer::closeEvent(QCloseEvent *e)
+{
+ if (m_standalone && !kapp->sessionSaving())
+ {
+ hide();
+ e->ignore();
+ }
+ else
+ e->accept();
+}
+
+void KMJobViewer::pluginActionActivated(int ID)
+{
+ KMTimer::self()->hold();
+
+ QPtrList<KMJob> joblist;
+ jobSelection(joblist);
+ if (!m_manager->doPluginAction(ID, joblist))
+ KMessageBox::error(this, "<qt>"+i18n("Operation failed.")+"<p>"+KMManager::self()->errorMsg()+"</p></qt>");
+
+ triggerRefresh();
+ KMTimer::self()->release();
+}
+
+void KMJobViewer::slotUserOnly(bool on)
+{
+ m_username = (on ? m_userfield->text() : QString::null);
+ refresh(false);
+}
+
+void KMJobViewer::slotUserChanged()
+{
+ if (m_userfield->isEnabled())
+ {
+ m_username = m_userfield->text();
+ refresh(false);
+ }
+}
+
+void KMJobViewer::slotConfigure()
+{
+ KMTimer::self()->hold();
+
+ KDialogBase dlg(this, 0, true, i18n("Print Job Settings"), KDialogBase::Ok|KDialogBase::Cancel);
+ KMConfigJobs *w = new KMConfigJobs(&dlg);
+ dlg.setMainWidget(w);
+ dlg.resize(300, 10);
+ KConfig *conf = KMFactory::self()->printConfig();
+ w->loadConfig(conf);
+ if (dlg.exec())
+ {
+ w->saveConfig(conf);
+ updateStatusBar();
+ refresh(true);
+ }
+
+ KMTimer::self()->release();
+}
+
+bool KMJobViewer::isSticky() const
+{
+ return ( m_stickybox ? m_stickybox->isChecked() : false );
+}
+
+void KMJobViewer::slotDropped( QDropEvent *e, QListViewItem* )
+{
+ QStringList files;
+ QString target;
+
+ KURL::List uris;
+ KURLDrag::decode( e, uris );
+ for ( KURL::List::ConstIterator it = uris.begin();
+ it != uris.end(); ++it)
+ {
+ if ( KIO::NetAccess::download( *it, target, 0 ) )
+ files << target;
+ }
+
+ if ( files.count() > 0 )
+ {
+ KPrinter prt;
+ if ( prt.autoConfigure( m_prname, this ) )
+ prt.printFiles( files, false, false );
+ }
+}
+
+#include "kmjobviewer.moc"
diff --git a/kdeprint/management/kmjobviewer.h b/kdeprint/management/kmjobviewer.h
new file mode 100644
index 000000000..69a3f27d6
--- /dev/null
+++ b/kdeprint/management/kmjobviewer.h
@@ -0,0 +1,127 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMJOBVIEWER_H
+#define KMJOBVIEWER_H
+
+#if !defined( _KDEPRINT_COMPILE ) && defined( __GNUC__ )
+#warning internal header, do not use except if you are a KDEPrint developer
+#endif
+
+#include <kmainwindow.h>
+#include "kmprinterpage.h"
+#include "kpreloadobject.h"
+
+class KMJobManager;
+class KMJob;
+class KListView;
+class JobItem;
+class QPopupMenu;
+class QListViewItem;
+class KMPrinter;
+class QTimer;
+class QLineEdit;
+class QCheckBox;
+
+/**
+ * @internal
+ * This class is internal to KDEPrint and is not intended to be
+ * used outside it. Please do not make use of this header, except
+ * if you're a KDEPrint developer. The API might change in the
+ * future and binary compatibility might be broken.
+ */
+class KDEPRINT_EXPORT KMJobViewer : public KMainWindow, public KMPrinterPage, public KPReloadObject
+{
+ Q_OBJECT
+public:
+ KMJobViewer(QWidget *parent = 0, const char *name = 0);
+ ~KMJobViewer();
+
+ void setPrinter(const QString& prname);
+ void setPrinter(KMPrinter *p);
+ void refresh(bool reload = false);
+ QString printer() const;
+ bool isSticky() const;
+
+signals:
+ void jobsShown(KMJobViewer*, bool hasJobs);
+ void refreshClicked();
+ void printerChanged(KMJobViewer*, const QString& prname);
+ void viewerDestroyed(KMJobViewer*);
+
+public slots:
+ void pluginActionActivated(int);
+
+protected slots:
+ void slotSelectionChanged();
+ void slotHold();
+ void slotResume();
+ void slotRemove();
+ void slotRestart();
+ void slotRightClicked(QListViewItem*,const QPoint&,int);
+ void slotMove(int prID);
+ void slotPrinterSelected(int);
+ void slotShowCompleted(bool);
+ void slotRefresh();
+ void slotClose();
+ void slotShowMoveMenu();
+ void slotShowPrinterMenu();
+ void slotUserOnly(bool);
+ void slotUserChanged();
+ void slotConfigure();
+ void slotDropped( QDropEvent*, QListViewItem* );
+
+protected:
+ void init();
+ void updateJobs();
+ void initActions();
+ JobItem* findItem(const QString& uri);
+ void jobSelection(QPtrList<KMJob>& l);
+ void send(int cmd, const QString& name, const QString& arg = QString::null);
+ void loadPrinters();
+ void loadPluginActions();
+ void removePluginActions();
+ void reload();
+ //void aboutToReload();
+ void closeEvent(QCloseEvent*);
+ void triggerRefresh();
+ void addToManager();
+ void removeFromManager();
+ void buildPrinterMenu(QPopupMenu *menu, bool use_all = false, bool use_specials = false);
+ void updateCaption();
+ void updateStatusBar();
+
+private:
+ KListView *m_view;
+ QPtrList<KMJob> m_jobs;
+ QPtrList<JobItem> m_items;
+ QPopupMenu *m_pop;
+ QPtrList<KMPrinter> m_printers;
+ QString m_prname;
+ int m_type;
+ QString m_username;
+ QLineEdit *m_userfield;
+ QCheckBox *m_stickybox;
+ bool m_standalone;
+};
+
+inline QString KMJobViewer::printer() const
+{ return m_prname; }
+
+#endif
diff --git a/kdeprint/management/kmlistview.cpp b/kdeprint/management/kmlistview.cpp
new file mode 100644
index 000000000..cbb1ca088
--- /dev/null
+++ b/kdeprint/management/kmlistview.cpp
@@ -0,0 +1,268 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmlistview.h"
+#include "kmprinter.h"
+#include "kmobject.h"
+
+#include <qheader.h>
+#include <qpainter.h>
+#include <klocale.h>
+#include <kiconloader.h>
+#include <kcursor.h>
+
+class KMListViewItem : public QListViewItem, public KMObject
+{
+public:
+ KMListViewItem(QListView *parent, const QString& txt);
+ KMListViewItem(QListViewItem *parent, const QString& txt);
+ KMListViewItem(QListViewItem *parent, KMPrinter *p);
+
+ virtual void paintCell(QPainter*, const QColorGroup&, int, int, int);
+ void updatePrinter(KMPrinter *p);
+ bool isClass() const { return m_isclass; }
+
+protected:
+ void init(KMPrinter *p = 0);
+
+private:
+ int m_state;
+ bool m_isclass;
+};
+
+KMListViewItem::KMListViewItem(QListView *parent, const QString& txt)
+: QListViewItem(parent,txt)
+{
+ init();
+}
+
+KMListViewItem::KMListViewItem(QListViewItem *parent, const QString& txt)
+: QListViewItem(parent,txt)
+{
+ init();
+}
+
+KMListViewItem::KMListViewItem(QListViewItem *parent, KMPrinter *p)
+: QListViewItem(parent)
+{
+ init(p);
+}
+
+void KMListViewItem::init(KMPrinter *p)
+{
+ m_state = 0;
+ if (p)
+ updatePrinter(p);
+ setSelectable(depth() == 2);
+}
+
+void KMListViewItem::updatePrinter(KMPrinter *p)
+{
+ bool update(false);
+ if (p)
+ {
+ int oldstate = m_state;
+ int st(p->isValid() ? (int)KIcon::DefaultState : (int)KIcon::LockOverlay);
+ m_state = ((p->isHardDefault() ? 0x1 : 0x0) | (p->ownSoftDefault() ? 0x2 : 0x0) | (p->isValid() ? 0x4 : 0x0));
+ update = (oldstate != m_state);
+ QString name = (p->isVirtual() ? p->instanceName() : p->name());
+ if (name != text(0))
+ setText(0, name);
+ setPixmap(0, SmallIcon(p->pixmap(), 0, st));
+ m_isclass = p->isClass();
+ }
+ setDiscarded(false);
+ if (update)
+ repaint();
+}
+
+void KMListViewItem::paintCell(QPainter *p, const QColorGroup& cg, int c, int w, int a)
+{
+ if (m_state != 0)
+ {
+ QFont f(p->font());
+ if (m_state & 0x1) f.setBold(true);
+ if (m_state & 0x2) f.setItalic(true);
+ p->setFont(f);
+ }
+ QListViewItem::paintCell(p,cg,c,w,a);
+}
+
+//************************************************************************************************
+
+KMListView::KMListView(QWidget *parent, const char *name)
+: QListView(parent,name)
+{
+ m_items.setAutoDelete(false);
+
+ addColumn("");
+ header()->hide();
+ setFrameStyle(QFrame::WinPanel|QFrame::Sunken);
+ setLineWidth(1);
+ setSorting(0);
+
+ connect(this,SIGNAL(contextMenuRequested(QListViewItem*,const QPoint&,int)),SLOT(slotRightButtonClicked(QListViewItem*,const QPoint&,int)));
+ connect(this,SIGNAL(selectionChanged()),SLOT(slotSelectionChanged()));
+ connect(this,SIGNAL(onItem(QListViewItem*)),SLOT(slotOnItem(QListViewItem*)));
+ connect(this,SIGNAL(onViewport()),SLOT(slotOnViewport()));
+
+ m_root = new KMListViewItem(this,i18n("Print System"));
+ m_root->setPixmap(0,SmallIcon("kdeprint_printer"));
+ m_root->setOpen(true);
+ m_classes = new KMListViewItem(m_root,i18n("Classes"));
+ m_classes->setPixmap(0,SmallIcon("package"));
+ m_classes->setOpen(true);
+ m_printers = new KMListViewItem(m_root,i18n("Printers"));
+ m_printers->setPixmap(0,SmallIcon("package"));
+ m_printers->setOpen(true);
+ m_specials = new KMListViewItem(m_root,i18n("Specials"));
+ m_specials->setPixmap(0,SmallIcon("package"));
+ m_specials->setOpen(true);
+
+ sort();
+}
+
+KMListView::~KMListView()
+{
+}
+
+void KMListView::slotRightButtonClicked(QListViewItem *item, const QPoint& p, int)
+{
+ emit rightButtonClicked(item && item->depth() == 2 ? item->text(0) : QString::null, p);
+}
+
+KMListViewItem* KMListView::findItem(KMPrinter *p)
+{
+ if (p)
+ {
+ QPtrListIterator<KMListViewItem> it(m_items);
+ bool isVirtual(p->isVirtual()), isClass(p->isClass());
+ for (;it.current();++it)
+ if (isVirtual)
+ {
+ if (it.current()->depth() == 3 && it.current()->text(0) == p->instanceName()
+ && it.current()->parent()->text(0) == p->printerName())
+ return it.current();
+ }
+ else
+ {
+ if (it.current()->isClass() == isClass && it.current()->text(0) == p->name())
+ return it.current();
+ }
+ }
+ return 0;
+}
+
+KMListViewItem* KMListView::findItem(const QString& prname)
+{
+ QPtrListIterator<KMListViewItem> it(m_items);
+ for (; it.current(); ++it)
+ if (it.current()->depth() == 2 && it.current()->text(0) == prname)
+ return it.current();
+ return 0;
+}
+
+void KMListView::setPrinterList(QPtrList<KMPrinter> *list)
+{
+ bool changed(false);
+
+ QPtrListIterator<KMListViewItem> it(m_items);
+ for (;it.current();++it)
+ it.current()->setDiscarded(true);
+
+ if (list)
+ {
+ QPtrListIterator<KMPrinter> it(*list);
+ KMListViewItem *item (0);
+ for (;it.current();++it)
+ {
+ item = findItem(it.current());
+ if (!item)
+ {
+ if (it.current()->isVirtual())
+ {
+ KMListViewItem *pItem = findItem(it.current()->printerName());
+ if (!pItem)
+ continue;
+ item = new KMListViewItem(pItem, it.current());
+ pItem->setOpen(true);
+ }
+ else
+ item = new KMListViewItem((it.current()->isSpecial() ? m_specials : (it.current()->isClass(false) ? m_classes : m_printers)),it.current());
+ m_items.append(item);
+ changed = true;
+ }
+ else
+ item->updatePrinter(it.current());
+ }
+ }
+
+ QPtrList<KMListViewItem> deleteList;
+ deleteList.setAutoDelete(true);
+ for (uint i=0; i<m_items.count(); i++)
+ if (m_items.at(i)->isDiscarded())
+ {
+ // instance items are put in front of the list
+ // so that they are destroyed first
+ KMListViewItem *item = m_items.take(i);
+ if (item->depth() == 2)
+ deleteList.append(item);
+ else
+ deleteList.prepend(item);
+ i--;
+ changed = true;
+ }
+ deleteList.clear();
+
+ if (changed) sort();
+ emit selectionChanged();
+}
+
+void KMListView::slotSelectionChanged()
+{
+ KMListViewItem *item = static_cast<KMListViewItem*>(currentItem());
+ emit printerSelected((item && !item->isDiscarded() && item->depth() == 2 ? item->text(0) : QString::null));
+}
+
+void KMListView::setPrinter(const QString& prname)
+{
+ QPtrListIterator<KMListViewItem> it(m_items);
+ for (;it.current();++it)
+ if (it.current()->text(0) == prname)
+ {
+ setSelected(it.current(),true);
+ break;
+ }
+}
+
+void KMListView::setPrinter(KMPrinter *p)
+{
+ setPrinter(p ? p->name() : QString::null);
+}
+
+void KMListView::slotOnItem(QListViewItem *)
+{
+ setCursor(KCursor::handCursor());
+}
+
+void KMListView::slotOnViewport()
+{
+ setCursor(KCursor::arrowCursor());
+}
+#include "kmlistview.moc"
diff --git a/kdeprint/management/kmlistview.h b/kdeprint/management/kmlistview.h
new file mode 100644
index 000000000..9e5ce6651
--- /dev/null
+++ b/kdeprint/management/kmlistview.h
@@ -0,0 +1,59 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMLISTVIEW_H
+#define KMLISTVIEW_H
+
+#include <qlistview.h>
+#include <qptrlist.h>
+
+class KMListViewItem;
+class KMPrinter;
+
+class KMListView : public QListView
+{
+ Q_OBJECT
+public:
+ KMListView(QWidget *parent = 0, const char *name = 0);
+ ~KMListView();
+
+ void setPrinterList(QPtrList<KMPrinter> *list);
+ void setPrinter(const QString&);
+ void setPrinter(KMPrinter*);
+
+signals:
+ void rightButtonClicked(const QString&, const QPoint&);
+ void printerSelected(const QString&);
+
+protected slots:
+ void slotRightButtonClicked(QListViewItem*, const QPoint&, int);
+ void slotSelectionChanged();
+ void slotOnItem(QListViewItem*);
+ void slotOnViewport();
+
+protected:
+ KMListViewItem* findItem(KMPrinter*);
+ KMListViewItem* findItem(const QString&);
+
+private:
+ QPtrList<KMListViewItem> m_items;
+ KMListViewItem *m_root, *m_classes, *m_printers, *m_specials;
+};
+
+#endif
diff --git a/kdeprint/management/kmmainview.cpp b/kdeprint/management/kmmainview.cpp
new file mode 100644
index 000000000..c506725af
--- /dev/null
+++ b/kdeprint/management/kmmainview.cpp
@@ -0,0 +1,908 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmmainview.h"
+#include "kmtimer.h"
+#include "kmprinterview.h"
+#include "kmpages.h"
+#include "kmmanager.h"
+#include "kmuimanager.h"
+#include "kmfactory.h"
+#include "kmvirtualmanager.h"
+#include "kmprinter.h"
+#include "driver.h"
+#include "kmdriverdialog.h"
+#include "kmwizard.h"
+#include "kmconfigdialog.h"
+#include "kmspecialprinterdlg.h"
+#include "plugincombobox.h"
+#include "kiconselectaction.h"
+#include "messagewindow.h"
+
+#include <qdockarea.h>
+#include <kmenubar.h>
+#include <qtimer.h>
+#include <qcombobox.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qpopupmenu.h>
+#include <kmessagebox.h>
+#include <kaction.h>
+#include <klocale.h>
+#include <kconfig.h>
+#include <ktoolbar.h>
+#include <ktoolbarbutton.h>
+#include <kdebug.h>
+#include <kpopupmenu.h>
+#include <klibloader.h>
+#include <kdialogbase.h>
+#include <ksimpleconfig.h>
+#include <kstandarddirs.h>
+#include <kapplication.h>
+
+#undef m_manager
+#define m_manager KMFactory::self()->manager()
+
+int kdeprint_management_add_printer_wizard( QWidget* parent )
+{
+ KMWizard dlg(parent);
+ int flag(0);
+ if (dlg.exec())
+ {
+ flag = 1;
+ // check if the printer already exists, and ask confirmation if needed.
+ if (KMFactory::self()->manager()->findPrinter(dlg.printer()->name()) != 0)
+ if (KMessageBox::warningContinueCancel(parent,i18n("The printer %1 already exists. Continuing will overwrite existing printer. Do you want to continue?").arg(dlg.printer()->name())) == KMessageBox::Cancel)
+ flag = 0;
+ // try to add printer only if flag is true.
+ if (flag && !KMFactory::self()->manager()->createPrinter(dlg.printer()))
+ flag = -1;
+ }
+ return flag;
+}
+
+KMMainView::KMMainView(QWidget *parent, const char *name, KActionCollection *coll)
+: QWidget(parent, name)
+{
+ m_current = 0;
+ m_first = true;
+
+ // create widgets
+ m_printerview = new KMPrinterView(this, "PrinterView");
+ m_printerpages = new KMPages(this, "PrinterPages");
+ m_pop = new QPopupMenu(this);
+ m_toolbar = new KToolBar(this, "ToolBar");
+ m_toolbar->setMovingEnabled(false);
+ m_plugin = new PluginComboBox(this, "Plugin");
+ /*
+ m_menubar = new KMenuBar( this );
+ static_cast<KMenuBar*>( m_menubar )->setTopLevelMenu( false );
+ */
+ m_menubar = new KToolBar( this, "MenuBar", false, false );
+ m_menubar->setIconText( KToolBar::IconTextRight );
+ m_menubar->setMovingEnabled( false );
+
+ // layout
+ QVBoxLayout *m_layout = new QVBoxLayout(this, 0, 0);
+ m_layout->addWidget(m_toolbar);
+ m_layout->addWidget( m_menubar );
+ m_boxlayout = new QBoxLayout(QBoxLayout::TopToBottom, 0, 0);
+ m_layout->addLayout(m_boxlayout);
+ m_boxlayout->addWidget(m_printerview);
+ m_boxlayout->addWidget(m_printerpages);
+ m_layout->addSpacing(5);
+ m_layout->addWidget(m_plugin, 0);
+
+ // connections
+ connect(KMTimer::self(),SIGNAL(timeout()),SLOT(slotTimer()));
+ connect(m_printerview,SIGNAL(printerSelected(const QString&)),SLOT(slotPrinterSelected(const QString&)));
+ connect(m_printerview,SIGNAL(rightButtonClicked(const QString&,const QPoint&)),SLOT(slotRightButtonClicked(const QString&,const QPoint&)));
+ connect(m_pop,SIGNAL(aboutToShow()),KMTimer::self(),SLOT(hold()));
+ connect(m_pop,SIGNAL(aboutToHide()),KMTimer::self(),SLOT(release()));
+ connect( m_manager, SIGNAL( updatePossible( bool ) ), SLOT( slotUpdatePossible( bool ) ) );
+
+ // actions
+ if (coll)
+ m_actions = coll;
+ else
+ m_actions = new KActionCollection(this);
+ initActions();
+
+ // first update
+ restoreSettings();
+ loadParameters();
+
+ // delay first update until KMManager is ready
+ reset( i18n( "Initializing manager..." ), true, true );
+}
+
+KMMainView::~KMMainView()
+{
+ saveSettings();
+ //KMFactory::release();
+}
+
+void KMMainView::loadParameters()
+{
+}
+
+void KMMainView::restoreSettings()
+{
+ KConfig *conf = KMFactory::self()->printConfig();
+ conf->setGroup("General");
+ setViewType((KMPrinterView::ViewType)conf->readNumEntry("ViewType",KMPrinterView::Icons));
+ setOrientation(conf->readNumEntry("Orientation", Qt::Vertical));
+ bool view = conf->readBoolEntry("ViewToolBar",false);
+ slotToggleToolBar(view);
+ ((KToggleAction*)m_actions->action("view_toolbar"))->setChecked(view);
+ view = conf->readBoolEntry( "ViewMenuBar", true );
+ slotToggleMenuBar( view );
+ static_cast<KToggleAction*>( m_actions->action( "view_menubar" ) )->setChecked( view );
+ view = conf->readBoolEntry("ViewPrinterInfos",true);
+ slotShowPrinterInfos(view);
+ ((KToggleAction*)m_actions->action("view_printerinfos"))->setChecked(view);
+}
+
+void KMMainView::saveSettings()
+{
+ KConfig *conf = KMFactory::self()->printConfig();
+ conf->setGroup("General");
+ conf->writeEntry("ViewType",(int)m_printerview->viewType());
+ conf->writeEntry("Orientation",(int)orientation());
+ conf->writeEntry("ViewToolBar",((KToggleAction*)m_actions->action("view_toolbar"))->isChecked());
+ conf->writeEntry("ViewMenuBar",static_cast<KToggleAction*>( m_actions->action("view_menubar") )->isChecked());
+ conf->writeEntry("ViewPrinterInfos",((KToggleAction*)m_actions->action("view_printerinfos"))->isChecked());
+ conf->sync();
+}
+
+void KMMainView::initActions()
+{
+ KIconSelectAction *vact = new KIconSelectAction(i18n("&View"),0,m_actions,"view_change");
+ QStringList iconlst;
+ iconlst << "view_icon" << "view_detailed" << "view_tree";
+ vact->setItems(QStringList::split(',',i18n("&Icons,&List,&Tree"),false), iconlst);
+ vact->setCurrentItem(0);
+ connect(vact,SIGNAL(activated(int)),SLOT(slotChangeView(int)));
+
+ KActionMenu *stateAct = new KActionMenu(i18n("Start/Stop Printer"), "kdeprint_printstate", m_actions, "printer_state_change");
+ stateAct->setDelayed(false);
+ stateAct->insert(new KAction(i18n("&Start Printer"),"kdeprint_enableprinter",0,this,SLOT(slotChangePrinterState()),m_actions,"printer_start"));
+ stateAct->insert(new KAction(i18n("Sto&p Printer"),"kdeprint_stopprinter",0,this,SLOT(slotChangePrinterState()),m_actions,"printer_stop"));
+
+ stateAct = new KActionMenu(i18n("Enable/Disable Job Spooling"), "kdeprint_queuestate", m_actions, "printer_spool_change");
+ stateAct->setDelayed(false);
+ stateAct->insert(new KAction(i18n("&Enable Job Spooling"),"kdeprint_enableprinter",0,this,SLOT(slotChangePrinterState()),m_actions,"printer_enable"));
+ stateAct->insert(new KAction(i18n("&Disable Job Spooling"),"kdeprint_stopprinter",0,this,SLOT(slotChangePrinterState()),m_actions,"printer_disable"));
+
+ new KAction(i18n("&Remove"),"edittrash",0,this,SLOT(slotRemove()),m_actions,"printer_remove");
+ new KAction(i18n("&Configure..."),"configure",0,this,SLOT(slotConfigure()),m_actions,"printer_configure");
+ new KAction(i18n("Add &Printer/Class..."),"kdeprint_addprinter",0,this,SLOT(slotAdd()),m_actions,"printer_add");
+ new KAction(i18n("Add &Special (pseudo) Printer..."),"kdeprint_addpseudo",0,this,SLOT(slotAddSpecial()),m_actions,"printer_add_special");
+ new KAction(i18n("Set as &Local Default"),"kdeprint_defaulthard",0,this,SLOT(slotHardDefault()),m_actions,"printer_hard_default");
+ new KAction(i18n("Set as &User Default"),"kdeprint_defaultsoft",0,this,SLOT(slotSoftDefault()),m_actions,"printer_soft_default");
+ new KAction(i18n("&Test Printer..."),"kdeprint_testprinter",0,this,SLOT(slotTest()),m_actions,"printer_test");
+ new KAction(i18n("Configure &Manager..."),"kdeprint_configmgr",0,this,SLOT(slotManagerConfigure()),m_actions,"manager_configure");
+ new KAction(i18n("Initialize Manager/&View"),"reload",0,this,SLOT(slotInit()),m_actions,"view_refresh");
+
+ KIconSelectAction *dact = new KIconSelectAction(i18n("&Orientation"),0,m_actions,"orientation_change");
+ iconlst.clear();
+ iconlst << "view_top_bottom" << "view_left_right";
+ dact->setItems(QStringList::split(',',i18n("&Vertical,&Horizontal"),false), iconlst);
+ dact->setCurrentItem(0);
+ connect(dact,SIGNAL(activated(int)),SLOT(slotChangeDirection(int)));
+
+ new KAction(i18n("R&estart Server"),"kdeprint_restartsrv",0,this,SLOT(slotServerRestart()),m_actions,"server_restart");
+ new KAction(i18n("Configure &Server..."),"kdeprint_configsrv",0,this,SLOT(slotServerConfigure()),m_actions,"server_configure");
+
+ KToggleAction *tact = new KToggleAction(i18n("Show &Toolbar"),0,m_actions,"view_toolbar");
+ tact->setCheckedState(i18n("Hide &Toolbar"));
+ connect(tact,SIGNAL(toggled(bool)),SLOT(slotToggleToolBar(bool)));
+ tact = new KToggleAction( i18n( "Show Me&nu Toolbar" ), 0, m_actions, "view_menubar" );
+ tact->setCheckedState(i18n("Hide Me&nu Toolbar"));
+ connect( tact, SIGNAL( toggled( bool ) ), SLOT( slotToggleMenuBar( bool ) ) );
+ tact = new KToggleAction(i18n("Show Pr&inter Details"),"kdeprint_printer_infos", 0,m_actions,"view_printerinfos");
+ tact->setCheckedState(KGuiItem(i18n("Hide Pr&inter Details"),"kdeprint_printer_infos"));
+ tact->setChecked(true);
+ connect(tact,SIGNAL(toggled(bool)),SLOT(slotShowPrinterInfos(bool)));
+
+ tact = new KToggleAction(i18n("Toggle Printer &Filtering"), "filter", 0, m_actions, "view_pfilter");
+ tact->setChecked(KMManager::self()->isFilterEnabled());
+ connect(tact, SIGNAL(toggled(bool)), SLOT(slotToggleFilter(bool)));
+
+ new KAction( i18n( "%1 &Handbook" ).arg( "KDEPrint" ), "contents", 0, this, SLOT( slotHelp() ), m_actions, "invoke_help" );
+ new KAction( i18n( "%1 &Web Site" ).arg( "KDEPrint" ), "network", 0, this, SLOT( slotHelp() ), m_actions, "invoke_web" );
+
+ KActionMenu *mact = new KActionMenu(i18n("Pri&nter Tools"), "package_utilities", m_actions, "printer_tool");
+ mact->setDelayed(false);
+ connect(mact->popupMenu(), SIGNAL(activated(int)), SLOT(slotToolSelected(int)));
+ QStringList files = KGlobal::dirs()->findAllResources("data", "kdeprint/tools/*.desktop");
+ for (QStringList::ConstIterator it=files.begin(); it!=files.end(); ++it)
+ {
+ KSimpleConfig conf(*it);
+ conf.setGroup("Desktop Entry");
+ mact->popupMenu()->insertItem(conf.readEntry("Name", "Unnamed"), mact->popupMenu()->count());
+ m_toollist << conf.readEntry("X-KDE-Library");
+ }
+
+ // add actions to the toolbar
+ m_actions->action("printer_add")->plug(m_toolbar);
+ m_actions->action("printer_add_special")->plug(m_toolbar);
+ m_toolbar->insertLineSeparator();
+ m_actions->action("printer_state_change")->plug(m_toolbar);
+ m_actions->action("printer_spool_change")->plug(m_toolbar);
+ m_toolbar->insertSeparator();
+ m_actions->action("printer_hard_default")->plug(m_toolbar);
+ m_actions->action("printer_soft_default")->plug(m_toolbar);
+ m_actions->action("printer_remove")->plug(m_toolbar);
+ m_toolbar->insertSeparator();
+ m_actions->action("printer_configure")->plug(m_toolbar);
+ m_actions->action("printer_test")->plug(m_toolbar);
+ m_actions->action("printer_tool")->plug(m_toolbar);
+ m_pactionsindex = m_toolbar->insertSeparator();
+ m_toolbar->insertLineSeparator();
+ m_actions->action("server_restart")->plug(m_toolbar);
+ m_actions->action("server_configure")->plug(m_toolbar);
+ m_toolbar->insertLineSeparator();
+ m_actions->action("manager_configure")->plug(m_toolbar);
+ m_actions->action("view_refresh")->plug(m_toolbar);
+ m_toolbar->insertLineSeparator();
+ m_actions->action("view_printerinfos")->plug(m_toolbar);
+ m_actions->action("view_change")->plug(m_toolbar);
+ m_actions->action("orientation_change")->plug(m_toolbar);
+ m_actions->action("view_pfilter")->plug(m_toolbar);
+
+ // add actions to the menu bar
+ QPopupMenu *menu = new QPopupMenu( this );
+ m_actions->action( "printer_add" )->plug( menu );
+ m_actions->action( "printer_add_special" )->plug( menu );
+ //m_menubar->insertItem( i18n( "Add" ), menu );
+ m_menubar->insertButton( "wizard", 0, true, i18n( "Add" ) );
+ m_menubar->getButton( 0 )->setPopup( menu, true );
+ menu = new QPopupMenu( this );
+ m_actions->action("printer_state_change")->plug( menu );
+ m_actions->action("printer_spool_change")->plug( menu );
+ menu->insertSeparator();
+ m_actions->action("printer_hard_default")->plug( menu );
+ m_actions->action("printer_soft_default")->plug( menu );
+ m_actions->action("printer_remove")->plug( menu );
+ menu->insertSeparator();
+ m_actions->action("printer_configure")->plug( menu );
+ m_actions->action("printer_test")->plug( menu );
+ m_actions->action("printer_tool")->plug( menu );
+ menu->insertSeparator();
+ //m_menubar->insertItem( i18n( "Printer" ), menu );
+ m_menubar->insertButton( "printer1", 1, true, i18n( "Printer" ) );
+ m_menubar->getButton( 1 )->setPopup( menu, true );
+ menu = new QPopupMenu( this );
+ m_actions->action("server_restart")->plug( menu );
+ m_actions->action("server_configure")->plug( menu );
+ //m_menubar->insertItem( i18n( "Server" ), menu );
+ m_menubar->insertButton( "misc", 2, true, i18n( "Print Server" ) );
+ m_menubar->getButton( 2 )->setPopup( menu, true );
+ menu = new QPopupMenu( this );
+ m_actions->action("manager_configure")->plug( menu );
+ m_actions->action("view_refresh")->plug( menu );
+ //m_menubar->insertItem( i18n( "Manager" ), menu );
+ m_menubar->insertButton( "kdeprint_configmgr", 3, true, i18n( "Print Manager" ) );
+ m_menubar->getButton( 3 )->setPopup( menu, true );
+ menu = new QPopupMenu( this );
+ m_actions->action("view_printerinfos")->plug( menu );
+ m_actions->action("view_change")->plug( menu );
+ m_actions->action("orientation_change")->plug( menu );
+ m_actions->action( "view_toolbar" )->plug ( menu );
+ m_actions->action( "view_menubar" )->plug ( menu );
+ menu->insertSeparator();
+ m_actions->action("view_pfilter")->plug( menu );
+ //m_menubar->insertItem( i18n( "View" ), menu );
+ m_menubar->insertButton( "view_remove", 4, true, i18n( "View" ) );
+ m_menubar->getButton( 4 )->setPopup( menu, true );
+ //m_menubar->setMinimumHeight( m_menubar->heightForWidth( 1000 ) );
+ menu = new QPopupMenu( this );
+ m_actions->action( "invoke_help" )->plug( menu );
+ m_actions->action( "invoke_web" )->plug( menu );
+ m_menubar->insertButton( "help", 5, true, i18n( "Documentation" ) );
+ m_menubar->getButton( 5 )->setPopup( menu, true );
+
+ loadPluginActions();
+ slotPrinterSelected(QString::null);
+}
+
+void KMMainView::slotRefresh()
+{
+ // TODO: remove me
+}
+
+void KMMainView::slotTimer()
+{
+ kdDebug() << "KMMainView::slotTimer" << endl;
+ QPtrList<KMPrinter> *printerlist = m_manager->printerList();
+ bool ok = m_manager->errorMsg().isEmpty();
+ m_printerview->setPrinterList(printerlist);
+ if ( m_first )
+ {
+ if ( !ok )
+ showErrorMsg(i18n("An error occurred while retrieving the printer list."));
+ else
+ {
+ /* try to select the most appropriate printer:
+ * - soft default owner printer
+ * - hard default printer
+ * - first printer
+ */
+ QPtrListIterator<KMPrinter> it( *printerlist );
+ KMPrinter *p1 = 0, *p2 = 0, *p3 = 0;
+ while ( it.current() )
+ {
+ if ( !it.current()->isVirtual() )
+ {
+ if ( it.current()->ownSoftDefault() )
+ {
+ p1 = it.current();
+ break;
+ }
+ else if ( it.current()->isHardDefault() )
+ p2 = it.current();
+ else if ( !p3 )
+ p3 = it.current();
+ }
+ ++it;
+ }
+ if ( p1 || p2 || p3 )
+ m_printerview->setPrinter( p1 ? p1 : ( p2 ? p2 : p3 ) );
+ }
+ m_first = false;
+ }
+}
+
+void KMMainView::slotPrinterSelected(const QString& prname)
+{
+ KMPrinter *p = KMManager::self()->findPrinter(prname);
+ m_current = p;
+ if (p && !p->isSpecial())
+ KMFactory::self()->manager()->completePrinter(p);
+ m_printerpages->setPrinter(p);
+
+ // update actions state (only if toolbar enabled, workaround for toolbar
+ // problem).
+ //if (m_toolbar->isEnabled())
+ //{
+ int mask = (m_manager->hasManagement() ? m_manager->printerOperationMask() : 0);
+ bool sp = !(p && p->isSpecial());
+ m_actions->action("printer_remove")->setEnabled(!sp || ((mask & KMManager::PrinterRemoval) && p && p->isLocal() && !p->isImplicit()));
+ m_actions->action("printer_configure")->setEnabled(!sp || ((mask & KMManager::PrinterConfigure) && p && !p->isClass(true) /*&& p->isLocal()*/));
+ m_actions->action("printer_hard_default")->setEnabled((sp && (mask & KMManager::PrinterDefault) && p && !p->isClass(true) && !p->isHardDefault() && p->isLocal()));
+ m_actions->action("printer_soft_default")->setEnabled((p && !p->isSoftDefault()));
+ m_actions->action("printer_test")->setEnabled((sp && (mask & KMManager::PrinterTesting) && p && !p->isClass(true)));
+ bool stmask = (sp && (mask & KMManager::PrinterEnabling) && p);
+ m_actions->action("printer_state_change")->setEnabled(stmask && p->isLocal());
+ m_actions->action("printer_spool_change")->setEnabled(stmask);
+ m_actions->action("printer_start")->setEnabled((stmask && p->state() == KMPrinter::Stopped));
+ m_actions->action("printer_stop")->setEnabled((stmask && p->state() != KMPrinter::Stopped));
+ m_actions->action("printer_enable")->setEnabled((stmask && !p->acceptJobs()));
+ m_actions->action("printer_disable")->setEnabled((stmask && p->acceptJobs()));
+
+ m_actions->action("printer_add")->setEnabled((mask & KMManager::PrinterCreation));
+ mask = m_manager->serverOperationMask();
+ m_actions->action("server_restart")->setEnabled((mask & KMManager::ServerRestarting));
+ m_actions->action("server_configure")->setEnabled((mask & KMManager::ServerConfigure));
+
+ KMFactory::self()->manager()->validatePluginActions(m_actions, p);
+ //}
+ m_actions->action("printer_tool")->setEnabled(p && !p->isClass(true) && !p->isRemote() && !p->isSpecial());
+}
+
+void KMMainView::setViewType(int ID)
+{
+ ((KSelectAction*)m_actions->action("view_change"))->setCurrentItem(ID);
+ slotChangeView(ID);
+}
+
+int KMMainView::viewType() const
+{ return m_printerview->viewType(); }
+
+void KMMainView::slotChangeView(int ID)
+{
+ kdDebug() << "KMMainView::slotChangeView" << endl;
+ if (ID >= KMPrinterView::Icons && ID <= KMPrinterView::Tree)
+ m_printerview->setViewType((KMPrinterView::ViewType)ID);
+}
+
+void KMMainView::slotRightButtonClicked(const QString& prname, const QPoint& p)
+{
+ KMPrinter *printer = KMManager::self()->findPrinter(prname);
+ // construct popup menu
+ m_pop->clear();
+ if (printer)
+ {
+ m_current = printer;
+ if (!printer->isSpecial())
+ {
+ if (printer->isLocal())
+ m_actions->action((printer->state() == KMPrinter::Stopped ? "printer_start" : "printer_stop"))->plug(m_pop);
+ m_actions->action((printer->acceptJobs() ? "printer_disable" : "printer_enable"))->plug(m_pop);
+ m_pop->insertSeparator();
+ }
+ if (!printer->isSoftDefault()) m_actions->action("printer_soft_default")->plug(m_pop);
+ if (printer->isLocal() && !printer->isImplicit())
+ {
+ if (!printer->isHardDefault()) m_actions->action("printer_hard_default")->plug(m_pop);
+ m_actions->action("printer_remove")->plug(m_pop);
+ m_pop->insertSeparator();
+ if (!printer->isClass(true))
+ {
+ m_actions->action("printer_configure")->plug(m_pop);
+ m_actions->action("printer_test")->plug(m_pop);
+ m_actions->action("printer_tool")->plug(m_pop);
+ m_pop->insertSeparator();
+ }
+ }
+ else
+ {
+ if (!printer->isClass(true))
+ {
+ m_actions->action("printer_configure")->plug(m_pop);
+ m_actions->action("printer_test")->plug(m_pop);
+ }
+ m_pop->insertSeparator();
+ }
+ if (!printer->isSpecial())
+ {
+ QValueList<KAction*> pactions = m_actions->actions("plugin");
+ for (QValueList<KAction*>::Iterator it=pactions.begin(); it!=pactions.end(); ++it)
+ (*it)->plug(m_pop);
+ if (pactions.count() > 0)
+ m_pop->insertSeparator();
+ }
+ }
+ else
+ {
+ m_actions->action("printer_add")->plug(m_pop);
+ m_actions->action("printer_add_special")->plug(m_pop);
+ m_pop->insertSeparator();
+ m_actions->action("server_restart")->plug(m_pop);
+ m_actions->action("server_configure")->plug(m_pop);
+ m_pop->insertSeparator();
+ m_actions->action("manager_configure")->plug(m_pop);
+ m_actions->action("view_refresh")->plug(m_pop);
+ m_pop->insertSeparator();
+ }
+ m_actions->action("view_printerinfos")->plug(m_pop);
+ m_actions->action("view_change")->plug(m_pop);
+ m_actions->action("orientation_change")->plug(m_pop);
+ m_actions->action("view_toolbar")->plug(m_pop);
+ m_actions->action("view_menubar")->plug(m_pop);
+ m_pop->insertSeparator();
+ m_actions->action("view_pfilter")->plug(m_pop);
+
+ // pop the menu
+ m_pop->popup(p);
+}
+
+void KMMainView::slotChangePrinterState()
+{
+ QString opname = sender()->name();
+ if (m_current && opname.startsWith("printer_"))
+ {
+ opname = opname.mid(8);
+ KMTimer::self()->hold();
+ bool result(false);
+ if (opname == "enable")
+ result = m_manager->enablePrinter(m_current, true);
+ else if (opname == "disable")
+ result = m_manager->enablePrinter(m_current, false);
+ else if (opname == "start")
+ result = m_manager->startPrinter(m_current, true);
+ else if (opname == "stop")
+ result = m_manager->startPrinter(m_current, false);
+ if (!result)
+ showErrorMsg(i18n("Unable to modify the state of printer %1.").arg(m_current->printerName()));
+ KMTimer::self()->release(result);
+ }
+}
+
+void KMMainView::slotRemove()
+{
+ if (m_current)
+ {
+ KMTimer::self()->hold();
+ bool result(false);
+ if (KMessageBox::warningYesNo(this,i18n("Do you really want to remove %1?").arg(m_current->printerName())) == KMessageBox::Yes)
+ if (m_current->isSpecial())
+ {
+ if (!(result=m_manager->removeSpecialPrinter(m_current)))
+ showErrorMsg(i18n("Unable to remove special printer %1.").arg(m_current->printerName()));
+ }
+ else if (!(result=m_manager->removePrinter(m_current)))
+ showErrorMsg(i18n("Unable to remove printer %1.").arg(m_current->printerName()));
+ KMTimer::self()->release(result);
+ }
+}
+
+void KMMainView::slotConfigure()
+{
+ if (m_current)
+ {
+ KMTimer::self()->hold();
+ bool needRefresh(false);
+ if (m_current->isSpecial())
+ {
+ KMSpecialPrinterDlg dlg(this);
+ dlg.setPrinter(m_current);
+ if (dlg.exec())
+ {
+ KMPrinter *prt = dlg.printer();
+ if (prt->name() != m_current->name())
+ m_manager->removeSpecialPrinter(m_current);
+ m_manager->createSpecialPrinter(prt);
+ needRefresh = true;
+ }
+ }
+ else
+ {
+ DrMain *driver = m_manager->loadPrinterDriver(m_current, true);
+ if (driver)
+ {
+ KMDriverDialog dlg(this);
+ dlg.setCaption(i18n("Configure %1").arg(m_current->printerName()));
+ dlg.setDriver(driver);
+ // disable OK button for remote printer (read-only dialog)
+ if (m_current->isRemote())
+ dlg.enableButtonOK(false);
+ if (dlg.exec())
+ if (!m_manager->savePrinterDriver(m_current,driver))
+ showErrorMsg(i18n("Unable to modify settings of printer %1.").arg(m_current->printerName()));
+ delete driver;
+ }
+ else
+ showErrorMsg(i18n("Unable to load a valid driver for printer %1.").arg(m_current->printerName()));
+ }
+ KMTimer::self()->release(needRefresh);
+ }
+}
+
+void KMMainView::slotAdd()
+{
+ KMTimer::self()->hold();
+
+ int result(0);
+ if ((result=kdeprint_management_add_printer_wizard(this)) == -1)
+ showErrorMsg(i18n("Unable to create printer."));
+
+ KMTimer::self()->release((result == 1));
+}
+
+void KMMainView::slotHardDefault()
+{
+ if (m_current)
+ {
+ KMTimer::self()->hold();
+ bool result = m_manager->setDefaultPrinter(m_current);
+ if (!result)
+ showErrorMsg(i18n("Unable to define printer %1 as default.").arg(m_current->printerName()));
+ KMTimer::self()->release(result);
+ }
+}
+
+void KMMainView::slotSoftDefault()
+{
+ if (m_current)
+ {
+ KMTimer::self()->hold();
+ KMFactory::self()->virtualManager()->setAsDefault(m_current,QString::null);
+ KMTimer::self()->release(true);
+ }
+}
+
+void KMMainView::setOrientation(int o)
+{
+ int ID = (o == Qt::Horizontal ? 1 : 0);
+ ((KSelectAction*)m_actions->action("orientation_change"))->setCurrentItem(ID);
+ slotChangeDirection(ID);
+}
+
+int KMMainView::orientation() const
+{ return (m_boxlayout->direction() == QBoxLayout::LeftToRight ? Qt::Horizontal : Qt::Vertical); }
+
+void KMMainView::slotChangeDirection(int d)
+{
+ m_boxlayout->setDirection(d == 1 ? QBoxLayout::LeftToRight : QBoxLayout::TopToBottom);
+}
+
+void KMMainView::slotTest()
+{
+ if (m_current)
+ {
+ KMTimer::self()->hold();
+ if (KMessageBox::warningContinueCancel(this, i18n("You are about to print a test page on %1. Do you want to continue?").arg(m_current->printerName()), QString::null, i18n("Print Test Page"), "printTestPage") == KMessageBox::Continue)
+ {
+ if (KMFactory::self()->manager()->testPrinter(m_current))
+ KMessageBox::information(this,i18n("Test page successfully sent to printer %1.").arg(m_current->printerName()));
+ else
+ showErrorMsg(i18n("Unable to test printer %1.").arg(m_current->printerName()));
+ }
+ KMTimer::self()->release(true);
+ }
+}
+
+void KMMainView::showErrorMsg(const QString& msg, bool usemgr)
+{
+ QString s(msg);
+ if (usemgr)
+ {
+ s.prepend("<p>");
+ s.append(" ");
+ s += i18n("Error message received from manager:</p><p>%1</p>");
+ if (m_manager->errorMsg().isEmpty())
+ s = s.arg(i18n("Internal error (no error message)."));
+ else
+ s = s.arg(m_manager->errorMsg());
+ // clean up error message
+ m_manager->setErrorMsg(QString::null);
+ }
+ s.prepend("<qt>").append("</qt>");
+ KMTimer::self()->hold();
+ KMessageBox::error(this,s);
+ KMTimer::self()->release();
+}
+
+void KMMainView::slotServerRestart()
+{
+ KMTimer::self()->hold();
+ bool result = m_manager->restartServer();
+ if (!result)
+ {
+ showErrorMsg(i18n("Unable to restart print server."));
+ KMTimer::self()->release( false );
+ }
+ else
+ {
+ reset( i18n( "Restarting server..." ), false, false );
+ }
+}
+
+void KMMainView::slotServerConfigure()
+{
+ KMTimer::self()->hold();
+ bool result = m_manager->configureServer(this);
+ if (!result)
+ {
+ showErrorMsg(i18n("Unable to configure print server."));
+ KMTimer::self()->release( false );
+ }
+ else
+ {
+ reset( i18n( "Configuring server..." ), false, false );
+ }
+}
+
+void KMMainView::slotToggleToolBar(bool on)
+{
+ if (on) m_toolbar->show();
+ else m_toolbar->hide();
+}
+
+void KMMainView::slotToggleMenuBar( bool on )
+{
+ if ( on )
+ m_menubar->show();
+ else
+ m_menubar->hide();
+}
+
+void KMMainView::slotManagerConfigure()
+{
+ KMTimer::self()->hold();
+ KMConfigDialog dlg(this,"ConfigDialog");
+ if ( dlg.exec() )
+ {
+ loadParameters();
+ }
+ /* when "OK":
+ * => the config file is saved
+ * => triggering a DCOP signal
+ * => configChanged() called
+ * hence no need to refresh, just release the timer
+ */
+ KMTimer::self()->release( false );
+}
+
+void KMMainView::slotAddSpecial()
+{
+ KMTimer::self()->hold();
+ KMSpecialPrinterDlg dlg(this);
+ if (dlg.exec())
+ {
+ KMPrinter *prt = dlg.printer();
+ m_manager->createSpecialPrinter(prt);
+ }
+ KMTimer::self()->release(true);
+}
+
+void KMMainView::slotShowPrinterInfos(bool on)
+{
+ if (on)
+ m_printerpages->show();
+ else
+ m_printerpages->hide();
+ m_actions->action("orientation_change")->setEnabled(on);
+}
+
+void KMMainView::enableToolbar(bool on)
+{
+ KToggleAction *act = (KToggleAction*)m_actions->action("view_toolbar");
+ m_toolbar->setEnabled(on);
+ act->setEnabled(on);
+ if (on && act->isChecked())
+ m_toolbar->show();
+ else
+ m_toolbar->hide();
+}
+
+KAction* KMMainView::action(const char *name)
+{
+ return m_actions->action(name);
+}
+
+/*
+void KMMainView::aboutToReload()
+{
+ m_printerview->setPrinterList(0);
+}
+*/
+
+void KMMainView::reload()
+{
+ removePluginActions();
+ loadPluginActions();
+
+ // redo the connection as the old manager object has been removed
+ connect( m_manager, SIGNAL( updatePossible( bool ) ), SLOT( slotUpdatePossible( bool ) ) );
+
+ // We must delay the refresh such that all objects has been
+ // correctly reloaded (otherwise, crash in KMJobViewer).
+ reset( i18n( "Initializing manager..." ), true, true );
+}
+
+void KMMainView::showPrinterInfos(bool on)
+{
+ static_cast<KToggleAction*>(m_actions->action("view_printerinfos"))->setChecked(on);
+ slotShowPrinterInfos(on);
+}
+
+bool KMMainView::printerInfosShown() const
+{
+ return (static_cast<KToggleAction*>(m_actions->action("view_printerinfos"))->isChecked());
+}
+
+void KMMainView::loadPluginActions()
+{
+ KMFactory::self()->manager()->createPluginActions(m_actions);
+ QValueList<KAction*> pactions = m_actions->actions("plugin");
+ int index = m_pactionsindex;
+ //QPopupMenu *menu = m_menubar->findItem( m_menubar->idAt( 1 ) )->popup();
+ QPopupMenu *menu = m_menubar->getButton( 1 )->popup();
+ for (QValueList<KAction*>::Iterator it=pactions.begin(); it!=pactions.end(); ++it)
+ {
+ (*it)->plug(m_toolbar, index++);
+ ( *it )->plug( menu );
+ }
+}
+
+void KMMainView::removePluginActions()
+{
+ QValueList<KAction*> pactions = m_actions->actions("plugin");
+ for (QValueList<KAction*>::Iterator it=pactions.begin(); it!=pactions.end(); ++it)
+ {
+ (*it)->unplugAll();
+ delete (*it);
+ }
+}
+
+void KMMainView::slotToolSelected(int ID)
+{
+ KMTimer::self()->hold();
+
+ QString libname = m_toollist[ID];
+ libname.prepend("kdeprint_tool_");
+ if (m_current && !m_current->device().isEmpty() && !libname.isEmpty())
+ {
+ KLibFactory *factory = KLibLoader::self()->factory(libname.local8Bit());
+ if (factory)
+ {
+ QStringList args;
+ args << m_current->device() << m_current->printerName();
+ KDialogBase *dlg = static_cast<KDialogBase*>(factory->create(this, "Tool", 0, args));
+ if (dlg)
+ dlg->exec();
+ delete dlg;
+ }
+ }
+ else
+ KMessageBox::error(this,
+ i18n("Unable to start printer tool. Possible reasons are: "
+ "no printer selected, the selected printer doesn't have "
+ "any local device defined (printer port), or the tool library "
+ "could not be found."));
+
+ KMTimer::self()->release();
+}
+
+void KMMainView::slotToggleFilter(bool on)
+{
+ KMTimer::self()->hold();
+ KMManager::self()->enableFilter(on);
+ KMTimer::self()->release(true);
+}
+
+void KMMainView::configChanged()
+{
+ reset( i18n( "Initializing manager..." ), false, true );
+}
+
+void KMMainView::slotUpdatePossible( bool flag )
+{
+ destroyMessageWindow();
+ if ( !flag )
+ showErrorMsg( i18n( "Unable to retrieve the printer list." ) );
+ KMTimer::self()->release( true );
+}
+
+void KMMainView::createMessageWindow( const QString& txt, int delay )
+{
+ destroyMessageWindow();
+ MessageWindow::add( m_printerview, txt, delay );
+}
+
+void KMMainView::destroyMessageWindow()
+{
+ MessageWindow::remove( m_printerview );
+}
+
+void KMMainView::slotInit()
+{
+ reset( i18n( "Initializing manager..." ), true, true );
+}
+
+void KMMainView::reset( const QString& msg, bool useDelay, bool holdTimer )
+{
+ if ( holdTimer )
+ KMTimer::self()->hold();
+ m_printerview->setPrinterList( 0 );
+ if ( !msg.isEmpty() )
+ createMessageWindow( msg, ( useDelay ? 500 : 0 ) );
+ m_first = true;
+ m_manager->checkUpdatePossible();
+}
+
+void KMMainView::slotHelp()
+{
+ QString s = sender()->name();
+ if ( s == "invoke_help" )
+ kapp->invokeHelp( QString::null, "kdeprint" );
+ else if ( s == "invoke_web" )
+ {
+ QStringList args;
+ args << "exec" << "http://printing.kde.org";
+ kapp->kdeinitExec( "kfmclient", args );
+ }
+ else
+ kdDebug( 500 ) << "Unknown help invokator: " << s << endl;
+}
+
+#include "kmmainview.moc"
diff --git a/kdeprint/management/kmmainview.h b/kdeprint/management/kmmainview.h
new file mode 100644
index 000000000..150ee9129
--- /dev/null
+++ b/kdeprint/management/kmmainview.h
@@ -0,0 +1,132 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMMAINVIEW_H
+#define KMMAINVIEW_H
+
+#if !defined( _KDEPRINT_COMPILE ) && defined( __GNUC__ )
+#warning internal header, do not use except if you are a KDEPrint developer
+#endif
+
+#include <qwidget.h>
+#include <kdeprint/kpreloadobject.h>
+#include <kmainwindow.h>
+
+class KMManager;
+class KMPrinterView;
+class KMPrinter;
+class KMPages;
+class KActionCollection;
+class QPopupMenu;
+class QTimer;
+class QSplitter;
+class KToolBar;
+class KAction;
+class PluginComboBox;
+class QBoxLayout;
+class MessageWindow;
+class QMenuBar;
+
+/**
+ * @internal
+ * This class is internal to KDEPrint and is not intended to be
+ * used outside it. Please do not make use of this header, except
+ * if you're a KDEPrint developer. The API might change in the
+ * future and binary compatibility might be broken.
+ */
+class KDEPRINT_EXPORT KMMainView : public QWidget, public KPReloadObject
+{
+ Q_OBJECT
+public:
+ KMMainView(QWidget *parent = 0, const char *name = 0, KActionCollection *coll = 0);
+ ~KMMainView();
+
+ void setOrientation(int);
+ int orientation() const;
+ void setViewType(int);
+ int viewType() const;
+ void enableToolbar(bool on = true);
+ KAction* action(const char *name);
+ void showPrinterInfos(bool on);
+ bool printerInfosShown() const;
+
+public slots:
+ void slotTimer();
+ void slotShowPrinterInfos(bool);
+ void slotChangePrinterState();
+ void slotRemove();
+ void slotConfigure();
+ void slotAdd();
+ void slotHardDefault();
+ void slotSoftDefault();
+ void slotTest();
+ void slotServerRestart();
+ void slotServerConfigure();
+ void slotManagerConfigure();
+ void slotAddSpecial();
+ void slotRefresh();
+ void slotToolSelected(int);
+ void slotToggleFilter(bool);
+ void slotHelp();
+
+protected slots:
+ void slotPrinterSelected(const QString&);
+ void slotRightButtonClicked(const QString&, const QPoint&);
+ void slotToggleToolBar(bool);
+ void slotToggleMenuBar(bool);
+ void slotChangeView(int);
+ void slotChangeDirection(int);
+ void slotUpdatePossible( bool );
+ void slotInit();
+
+protected:
+ void initActions();
+ void showErrorMsg(const QString& msg, bool usemgr = true);
+ void restoreSettings();
+ void saveSettings();
+ void loadParameters();
+ void reload();
+ void configChanged();
+ //void aboutToReload();
+ void loadPluginActions();
+ void removePluginActions();
+ void createMessageWindow( const QString&, int delay = 500 );
+ void destroyMessageWindow();
+ void reset( const QString& msg = QString::null, bool useDelay = true, bool holdTimer = true );
+
+private:
+ KMPrinterView *m_printerview;
+ KMPages *m_printerpages;
+ QPopupMenu *m_pop;
+ KActionCollection *m_actions;
+ KMPrinter *m_current;
+ KToolBar *m_toolbar;
+ PluginComboBox *m_plugin;
+ int m_pactionsindex;
+ QStringList m_toollist;
+ bool m_first;
+ QBoxLayout *m_boxlayout;
+ class KMainWindowPrivate;
+ KMainWindowPrivate *d;
+ KToolBar *m_menubar;
+};
+
+KDEPRINT_EXPORT int kdeprint_management_add_printer_wizard( QWidget* parent );
+
+#endif
diff --git a/kdeprint/management/kmpages.cpp b/kdeprint/management/kmpages.cpp
new file mode 100644
index 000000000..9387b33a0
--- /dev/null
+++ b/kdeprint/management/kmpages.cpp
@@ -0,0 +1,74 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmpages.h"
+#include "kminfopage.h"
+#include "kmjobviewer.h"
+#include "kmpropertypage.h"
+#include "kminstancepage.h"
+
+#include <klocale.h>
+#include <kiconloader.h>
+#include <kdialog.h>
+
+KMPages::KMPages(QWidget *parent, const char *name)
+: QTabWidget(parent,name)
+{
+ m_pages.setAutoDelete(false);
+ initialize();
+}
+
+KMPages::~KMPages()
+{
+}
+
+void KMPages::setPrinter(KMPrinter *p)
+{
+ QPtrListIterator<KMPrinterPage> it(m_pages);
+ for (int i=0;it.current();++it,i++)
+ it.current()->setPrinter(p);
+}
+
+void KMPages::initialize()
+{
+ setMargin(KDialog::marginHint());
+
+ // Info page
+ KMInfoPage *infopage = new KMInfoPage(this, "InfoPage");
+ addTab(infopage, SmallIcon("help"), i18n("Information"));
+ m_pages.append(infopage);
+
+ // Job page
+ KMJobViewer *jobviewer = new KMJobViewer(this, "JobViewer");
+ addTab(jobviewer, SmallIcon("folder"), i18n("Jobs"));
+ m_pages.append(jobviewer);
+
+ // Property page
+ KMPropertyPage *proppage = new KMPropertyPage(this, "Property");
+ addTab(proppage, SmallIcon("configure"), i18n("Properties"));
+ m_pages.append(proppage);
+
+ // Instance page
+ KMInstancePage *instpage = new KMInstancePage(this, "Instance");
+ addTab(instpage, SmallIcon("fileprint"), i18n("Instances"));
+ m_pages.append(instpage);
+
+ // initialize pages
+ setPrinter(0);
+}
diff --git a/kdeprint/management/kmpages.h b/kdeprint/management/kmpages.h
new file mode 100644
index 000000000..5af1da108
--- /dev/null
+++ b/kdeprint/management/kmpages.h
@@ -0,0 +1,44 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMPAGES_H
+#define KMPAGES_H
+
+#include <qtabwidget.h>
+#include <qptrlist.h>
+
+class KMPrinter;
+class KMPrinterPage;
+
+class KMPages : public QTabWidget
+{
+public:
+ KMPages(QWidget *parent = 0, const char *name = 0);
+ ~KMPages();
+
+ void setPrinter(KMPrinter *p);
+
+protected:
+ void initialize();
+
+private:
+ QPtrList<KMPrinterPage> m_pages;
+};
+
+#endif
diff --git a/kdeprint/management/kmprinterpage.h b/kdeprint/management/kmprinterpage.h
new file mode 100644
index 000000000..cfce97ec7
--- /dev/null
+++ b/kdeprint/management/kmprinterpage.h
@@ -0,0 +1,42 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMPRINTERPAGE_H
+#define KMPRINTERPAGE_H
+
+#if !defined( _KDEPRINT_COMPILE ) && defined( __GNUC__ )
+#warning internal header, do not use except if you are a KDEPrint developer
+#endif
+
+class KMPrinter;
+
+/**
+ * @internal
+ * This class is internal to KDEPrint and is not intended to be
+ * used outside it. Please do not make use of this header, except
+ * if you're a KDEPrint developer. The API might change in the
+ * future and binary compatibility might be broken.
+ */
+class KMPrinterPage
+{
+public:
+ virtual void setPrinter(KMPrinter*) = 0;
+};
+
+#endif
diff --git a/kdeprint/management/kmprinterview.cpp b/kdeprint/management/kmprinterview.cpp
new file mode 100644
index 000000000..89549ed94
--- /dev/null
+++ b/kdeprint/management/kmprinterview.cpp
@@ -0,0 +1,113 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmprinterview.h"
+#include "kmprinter.h"
+#include "kmiconview.h"
+#include "kmlistview.h"
+#include "kmtimer.h"
+#include "kmmanager.h"
+
+#include <qlayout.h>
+#include <qpopupmenu.h>
+#include <kaction.h>
+#include <klocale.h>
+
+KMPrinterView::KMPrinterView(QWidget *parent, const char *name)
+: QWidgetStack(parent,name), m_type(KMPrinterView::Icons)
+{
+ m_iconview = new KMIconView(this);
+ addWidget(m_iconview,0);
+ m_listview = new KMListView(this);
+ addWidget(m_listview,1);
+ m_current = QString::null;
+ m_listset = false;
+
+ connect(m_iconview,SIGNAL(rightButtonClicked(const QString&,const QPoint&)),SIGNAL(rightButtonClicked(const QString&,const QPoint&)));
+ connect(m_listview,SIGNAL(rightButtonClicked(const QString&,const QPoint&)),SIGNAL(rightButtonClicked(const QString&,const QPoint&)));
+ connect(m_iconview,SIGNAL(printerSelected(const QString&)),SIGNAL(printerSelected(const QString&)));
+ connect(m_listview,SIGNAL(printerSelected(const QString&)),SIGNAL(printerSelected(const QString&)));
+ connect(m_iconview,SIGNAL(printerSelected(const QString&)),SLOT(slotPrinterSelected(const QString&)));
+ connect(m_listview,SIGNAL(printerSelected(const QString&)),SLOT(slotPrinterSelected(const QString&)));
+
+ setViewType(m_type);
+ setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
+}
+
+KMPrinterView::~KMPrinterView()
+{
+}
+
+void KMPrinterView::setPrinterList(QPtrList<KMPrinter> *list)
+{
+ if (m_type != KMPrinterView::Tree || list == 0)
+ m_iconview->setPrinterList(list);
+ if (m_type == KMPrinterView::Tree || list == 0)
+ m_listview->setPrinterList(list);
+ m_listset = ( list != 0 );
+}
+
+void KMPrinterView::setPrinter( KMPrinter *p )
+{
+ if ( m_type == KMPrinterView::Tree )
+ m_listview->setPrinter( p );
+ else
+ m_iconview->setPrinter( p );
+}
+
+void KMPrinterView::setViewType(ViewType t)
+{
+ m_type = t;
+ switch (m_type)
+ {
+ case KMPrinterView::Icons:
+ m_iconview->setViewMode(KMIconView::Big);
+ break;
+ case KMPrinterView::List:
+ m_iconview->setViewMode(KMIconView::Small);
+ break;
+ default:
+ break;
+ }
+ QString oldcurrent = m_current;
+ if ( m_listset )
+ setPrinterList(KMManager::self()->printerList(false));
+ if (m_type == KMPrinterView::Tree)
+ {
+ raiseWidget(m_listview);
+ m_listview->setPrinter(oldcurrent);
+ }
+ else
+ {
+ raiseWidget(m_iconview);
+ m_iconview->setPrinter(oldcurrent);
+ }
+}
+
+void KMPrinterView::slotPrinterSelected(const QString& p)
+{
+ m_current = p;
+}
+
+QSize KMPrinterView::minimumSizeHint() const
+{
+ return QWidgetStack::minimumSizeHint();
+}
+
+#include "kmprinterview.moc"
diff --git a/kdeprint/management/kmprinterview.h b/kdeprint/management/kmprinterview.h
new file mode 100644
index 000000000..394ff7f19
--- /dev/null
+++ b/kdeprint/management/kmprinterview.h
@@ -0,0 +1,62 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMPRINTERVIEW_H
+#define KMPRINTERVIEW_H
+
+#include <qwidgetstack.h>
+#include <qptrlist.h>
+
+class KMIconView;
+class KMListView;
+class KMPrinter;
+class QIconViewItem;
+
+class KMPrinterView : public QWidgetStack
+{
+ Q_OBJECT
+public:
+ enum ViewType { Icons = 0, List, Tree };
+
+ KMPrinterView(QWidget *parent = 0, const char *name = 0);
+ ~KMPrinterView();
+
+ void setPrinterList(QPtrList<KMPrinter> *list);
+ void setPrinter( KMPrinter* );
+ void setViewType(ViewType t);
+ ViewType viewType() const { return m_type; }
+
+ QSize minimumSizeHint() const;
+
+signals:
+ void printerSelected(const QString&);
+ void rightButtonClicked(const QString&, const QPoint&);
+
+protected slots:
+ void slotPrinterSelected(const QString&);
+
+private:
+ KMIconView *m_iconview;
+ KMListView *m_listview;
+ ViewType m_type;
+ QString m_current;
+ bool m_listset;
+};
+
+#endif
diff --git a/kdeprint/management/kmpropbackend.cpp b/kdeprint/management/kmpropbackend.cpp
new file mode 100644
index 000000000..bf92e7fdc
--- /dev/null
+++ b/kdeprint/management/kmpropbackend.cpp
@@ -0,0 +1,86 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmpropbackend.h"
+#include "kmprinter.h"
+#include "kmwizard.h"
+
+#include <qlabel.h>
+#include <qlayout.h>
+#include <klocale.h>
+
+KMPropBackend::KMPropBackend(QWidget *parent, const char *name)
+: KMPropWidget(parent,name)
+{
+ m_uri = new QLabel("",this);
+ m_type = new QLabel("",this);
+
+ QLabel *l1 = new QLabel(i18n("Printer type:"), this);
+ QLabel *l2 = new QLabel(i18n("URI:"), this);
+
+ // layout
+ QGridLayout *main_ = new QGridLayout(this, 3, 2, 10, 7);
+ main_->setColStretch(0,0);
+ main_->setColStretch(1,1);
+ main_->setRowStretch(2,1);
+ main_->addWidget(l1,0,0);
+ main_->addWidget(l2,1,0);
+ main_->addWidget(m_type,0,1);
+ main_->addWidget(m_uri,1,1);
+
+ m_pixmap = "connect_established";
+ m_title = i18n("Interface");
+ m_header = i18n("Interface Settings");
+}
+
+KMPropBackend::~KMPropBackend()
+{
+}
+
+void KMPropBackend::setPrinter(KMPrinter *p)
+{
+ if (p && p->isPrinter())
+ {
+ m_uri->setText(KURL(p->device()).prettyURL());
+ QString prot = p->deviceProtocol();
+ if (prot == "ipp" || prot == "http") m_type->setText(i18n("IPP Printer"));
+ else if (prot == "usb") m_type->setText(i18n("Local USB Printer"));
+ else if (prot == "parallel") m_type->setText(i18n("Local Parallel Printer"));
+ else if (prot == "serial") m_type->setText(i18n("Local Serial Printer"));
+ else if (prot == "socket") m_type->setText(i18n("Network Printer (socket)"));
+ else if (prot == "smb") m_type->setText(i18n("SMB printers (Windows)"));
+ else if (prot == "lpd") m_type->setText(i18n("Remote LPD queue"));
+ else if (prot == "file") m_type->setText(i18n("File printer"));
+ else if (prot == "fax") m_type->setText(i18n("Serial Fax/Modem printer"));
+ else m_type->setText(i18n("Unknown Protocol", "Unknown"));
+ emit enable(true);
+ emit enableChange(p->isLocal());
+ }
+ else
+ {
+ emit enable(false);
+ m_type->setText("");
+ m_uri->setText("");
+ }
+}
+
+void KMPropBackend::configureWizard(KMWizard *w)
+{
+ w->configure(KMWizard::Backend,KMWizard::Driver,false);
+}
diff --git a/kdeprint/management/kmpropbackend.h b/kdeprint/management/kmpropbackend.h
new file mode 100644
index 000000000..fb8c299d8
--- /dev/null
+++ b/kdeprint/management/kmpropbackend.h
@@ -0,0 +1,45 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMPROPBACKEND_H
+#define KMPROPBACKEND_H
+
+#include "kmpropwidget.h"
+
+#include <kdelibs_export.h>
+
+class QLabel;
+
+class KDEPRINT_EXPORT KMPropBackend : public KMPropWidget
+{
+public:
+ KMPropBackend(QWidget *parent = 0, const char *name = 0);
+ ~KMPropBackend();
+
+ void setPrinter(KMPrinter*);
+
+protected:
+ void configureWizard(KMWizard*);
+
+private:
+ QLabel *m_type;
+ QLabel *m_uri;
+};
+
+#endif
diff --git a/kdeprint/management/kmpropcontainer.cpp b/kdeprint/management/kmpropcontainer.cpp
new file mode 100644
index 000000000..cc55aa901
--- /dev/null
+++ b/kdeprint/management/kmpropcontainer.cpp
@@ -0,0 +1,77 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmpropcontainer.h"
+#include "kmpropwidget.h"
+
+#include <kpushbutton.h>
+#include <qlayout.h>
+#include <klocale.h>
+#include <kseparator.h>
+#include <kguiitem.h>
+
+KMPropContainer::KMPropContainer(QWidget *parent, const char *name)
+: QWidget(parent,name)
+{
+ KSeparator* sep = new KSeparator( KSeparator::HLine, this);
+ sep->setFixedHeight(5);
+
+ m_button = new KPushButton(KGuiItem(i18n("Change..."), "edit"), this);
+ m_widget = 0;
+
+ QVBoxLayout *main_ = new QVBoxLayout(this, 0, 10);
+ QHBoxLayout *btn_ = new QHBoxLayout(0, 0, 0);
+ main_->addWidget(sep,0);
+ main_->addLayout(btn_,0);
+ btn_->addStretch(1);
+ btn_->addWidget(m_button);
+}
+
+KMPropContainer::~KMPropContainer()
+{
+}
+
+void KMPropContainer::setWidget(KMPropWidget *w)
+{
+ if (!m_widget)
+ {
+ m_widget = w;
+ m_widget->reparent(this,QPoint(0,0));
+ connect(m_button,SIGNAL(clicked()),m_widget,SLOT(slotChange()));
+ connect(m_widget,SIGNAL(enable(bool)),SIGNAL(enable(bool)));
+ connect(m_widget,SIGNAL(enableChange(bool)),SLOT(slotEnableChange(bool)));
+ QVBoxLayout *lay = dynamic_cast<QVBoxLayout*>(layout());
+ if (lay)
+ {
+ lay->insertWidget(0,m_widget,1);
+ }
+ }
+}
+
+void KMPropContainer::setPrinter(KMPrinter *p)
+{
+ if (m_widget)
+ m_widget->setPrinterBase(p);
+}
+
+void KMPropContainer::slotEnableChange(bool on)
+{
+ m_button->setEnabled(on && (m_widget ? m_widget->canChange() : true));
+}
+#include "kmpropcontainer.moc"
diff --git a/kdeprint/management/kmpropcontainer.h b/kdeprint/management/kmpropcontainer.h
new file mode 100644
index 000000000..95d7cb57a
--- /dev/null
+++ b/kdeprint/management/kmpropcontainer.h
@@ -0,0 +1,50 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMPROPCONTAINER_H
+#define KMPROPCONTAINER_H
+
+#include <qwidget.h>
+
+class KMPropWidget;
+class QPushButton;
+class KMPrinter;
+
+class KMPropContainer : public QWidget
+{
+ Q_OBJECT
+public:
+ KMPropContainer(QWidget *parent = 0, const char *name = 0);
+ ~KMPropContainer();
+
+ void setWidget(KMPropWidget*);
+ void setPrinter(KMPrinter*);
+
+signals:
+ void enable(bool);
+
+protected slots:
+ void slotEnableChange(bool);
+
+private:
+ KMPropWidget *m_widget;
+ QPushButton *m_button;
+};
+
+#endif
diff --git a/kdeprint/management/kmpropdriver.cpp b/kdeprint/management/kmpropdriver.cpp
new file mode 100644
index 000000000..8298ee8a8
--- /dev/null
+++ b/kdeprint/management/kmpropdriver.cpp
@@ -0,0 +1,83 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmpropdriver.h"
+#include "kmprinter.h"
+#include "kmwizard.h"
+
+#include <qlabel.h>
+#include <qlayout.h>
+#include <klocale.h>
+
+KMPropDriver::KMPropDriver(QWidget *parent, const char *name)
+: KMPropWidget(parent,name)
+{
+ m_manufacturer = new QLabel("",this);
+ m_model = new QLabel("",this);
+ m_driverinfo = new QLabel("",this);
+ m_driverinfo->setTextFormat(Qt::RichText);
+
+ QLabel *l1 = new QLabel(i18n("Manufacturer:"), this);
+ QLabel *l2 = new QLabel(i18n("Printer model:"), this);
+ QLabel *l3 = new QLabel(i18n("Driver info:"), this);
+
+ // layout
+ QGridLayout *main_ = new QGridLayout(this, 4, 2, 10, 7);
+ main_->setColStretch(0,0);
+ main_->setColStretch(1,1);
+ main_->setRowStretch(3,1);
+ main_->addWidget(l1,0,0);
+ main_->addWidget(l2,1,0);
+ main_->addWidget(l3,2,0,Qt::AlignTop|Qt::AlignLeft);
+ main_->addWidget(m_manufacturer,0,1);
+ main_->addWidget(m_model,1,1);
+ main_->addWidget(m_driverinfo,2,1);
+
+ m_pixmap = "gear";
+ m_title = i18n("Driver");
+ m_header = i18n("Driver Settings");
+}
+
+KMPropDriver::~KMPropDriver()
+{
+}
+
+void KMPropDriver::setPrinter(KMPrinter *p)
+{
+ if (p && p->isPrinter())
+ {
+ m_manufacturer->setText(p->manufacturer());
+ m_model->setText(p->model());
+ m_driverinfo->setText(p->driverInfo());
+ emit enable(true);
+ emit enableChange(p->isLocal());
+ }
+ else
+ {
+ emit enable(false);
+ m_manufacturer->setText("");
+ m_model->setText("");
+ m_driverinfo->setText("");
+ }
+}
+
+void KMPropDriver::configureWizard(KMWizard *w)
+{
+ w->configure(KMWizard::Driver,KMWizard::DriverTest,true);
+}
diff --git a/kdeprint/management/kmpropdriver.h b/kdeprint/management/kmpropdriver.h
new file mode 100644
index 000000000..9c07fe727
--- /dev/null
+++ b/kdeprint/management/kmpropdriver.h
@@ -0,0 +1,46 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMPROPDRIVER_H
+#define KMPROPDRIVER_H
+
+#include "kmpropwidget.h"
+
+#include <kdelibs_export.h>
+
+class QLabel;
+
+class KDEPRINT_EXPORT KMPropDriver : public KMPropWidget
+{
+public:
+ KMPropDriver(QWidget *parent = 0, const char *name = 0);
+ ~KMPropDriver();
+
+ void setPrinter(KMPrinter*);
+
+protected:
+ void configureWizard(KMWizard*);
+
+private:
+ QLabel *m_manufacturer;
+ QLabel *m_model;
+ QLabel *m_driverinfo;
+};
+
+#endif
diff --git a/kdeprint/management/kmpropertypage.cpp b/kdeprint/management/kmpropertypage.cpp
new file mode 100644
index 000000000..aa8f61663
--- /dev/null
+++ b/kdeprint/management/kmpropertypage.cpp
@@ -0,0 +1,94 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmpropertypage.h"
+#include "kmpropwidget.h"
+#include "kmpropcontainer.h"
+#include "kmprinter.h"
+#include "kmfactory.h"
+#include "kmuimanager.h"
+
+#include "kmpropgeneral.h"
+
+#include <qvbox.h>
+#include <kiconloader.h>
+
+KMPropertyPage::KMPropertyPage(QWidget *parent, const char *name)
+: CJanusWidget(parent,name)
+{
+ m_widgets.setAutoDelete(false);
+
+ initialize();
+}
+
+KMPropertyPage::~KMPropertyPage()
+{
+}
+
+void KMPropertyPage::setPrinter(KMPrinter *p)
+{
+ QPtrListIterator<KMPropWidget> it(m_widgets);
+ for (;it.current();++it)
+ it.current()->setPrinterBase(p);
+}
+
+void KMPropertyPage::addPropPage(KMPropWidget *w)
+{
+ if (w)
+ {
+ m_widgets.append(w);
+ KMPropContainer *ctn = new KMPropContainer(this,"Container");
+ ctn->setWidget(w);
+ connect(ctn,SIGNAL(enable(bool)),SLOT(slotEnable(bool)));
+
+ QPixmap icon = KGlobal::instance()->iconLoader()->loadIcon(
+ w->pixmap(),
+ KIcon::NoGroup,
+ KIcon::SizeMedium
+ );
+ addPage(ctn,w->title(),w->header(),icon);
+ }
+}
+
+void KMPropertyPage::slotEnable(bool on)
+{
+ QWidget *w = (QWidget*)(sender());
+ if (on)
+ enablePage(w);
+ else
+ disablePage(w);
+}
+
+void KMPropertyPage::initialize()
+{
+ // add General page
+ addPropPage(new KMPropGeneral(this, "General"));
+ // add plugin specific pages
+ KMFactory::self()->uiManager()->setupPropertyPages(this);
+}
+
+void KMPropertyPage::reload()
+{
+ clearPages();
+ m_widgets.clear();
+ initialize();
+ setPrinter(0);
+}
+
+#include "kmpropertypage.moc"
diff --git a/kdeprint/management/kmpropertypage.h b/kdeprint/management/kmpropertypage.h
new file mode 100644
index 000000000..7f2f1c074
--- /dev/null
+++ b/kdeprint/management/kmpropertypage.h
@@ -0,0 +1,53 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMPROPERTYPAGE_H
+#define KMPROPERTYPAGE_H
+
+#include "cjanuswidget.h"
+#include "kmprinterpage.h"
+#include <kdeprint/kpreloadobject.h>
+#include <kdelibs_export.h>
+#include <qptrlist.h>
+
+class KMPropWidget;
+class KMPrinter;
+
+class KDEPRINT_EXPORT KMPropertyPage : public CJanusWidget, public KMPrinterPage, public KPReloadObject
+{
+ Q_OBJECT
+public:
+ KMPropertyPage(QWidget *parent = 0, const char *name = 0);
+ ~KMPropertyPage();
+
+ void addPropPage(KMPropWidget*);
+ void setPrinter(KMPrinter*);
+
+protected slots:
+ void slotEnable(bool);
+ void initialize();
+
+protected:
+ void reload();
+
+private:
+ QPtrList<KMPropWidget> m_widgets;
+};
+
+#endif
diff --git a/kdeprint/management/kmpropgeneral.cpp b/kdeprint/management/kmpropgeneral.cpp
new file mode 100644
index 000000000..cea16bd5d
--- /dev/null
+++ b/kdeprint/management/kmpropgeneral.cpp
@@ -0,0 +1,83 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmpropgeneral.h"
+#include "kmprinter.h"
+#include "kmwizard.h"
+#include "kmfactory.h"
+#include "kmmanager.h"
+
+#include <qlabel.h>
+#include <qlayout.h>
+#include <klocale.h>
+
+KMPropGeneral::KMPropGeneral(QWidget *parent, const char *name)
+: KMPropWidget(parent,name)
+{
+ m_name = new QLabel("",this);
+ m_location = new QLabel("",this);
+ m_description = new QLabel("",this);
+
+ QLabel *l1 = new QLabel(i18n("Printer name:"), this);
+ QLabel *l2 = new QLabel(i18n("Physical Location", "Location:"), this);
+ QLabel *l3 = new QLabel(i18n("Description:"), this);
+
+ // layout
+ QGridLayout *main_ = new QGridLayout(this, 4, 2, 10, 7);
+ main_->setColStretch(0,0);
+ main_->setColStretch(1,1);
+ main_->setRowStretch(3,1);
+ main_->addWidget(l1,0,0);
+ main_->addWidget(l2,1,0);
+ main_->addWidget(l3,2,0);
+ main_->addWidget(m_name,0,1);
+ main_->addWidget(m_location,1,1);
+ main_->addWidget(m_description,2,1);
+
+ m_pixmap = "contents";
+ m_title = i18n("General");
+ m_header = i18n("General Settings");
+}
+
+KMPropGeneral::~KMPropGeneral()
+{
+}
+
+void KMPropGeneral::setPrinter(KMPrinter *p)
+{
+ if (p)
+ {
+ m_name->setText(p->name());
+ m_location->setText(p->location());
+ m_description->setText(p->description());
+ emit enableChange(!(p->isSpecial() || p->isRemote() || p->isImplicit()));
+ }
+ else
+ {
+ emit enableChange(false);
+ m_name->setText("");
+ m_location->setText("");
+ m_description->setText("");
+ }
+}
+
+void KMPropGeneral::configureWizard(KMWizard *w)
+{
+ w->configure(KMWizard::Name,KMWizard::Name,true);
+}
diff --git a/kdeprint/management/kmpropgeneral.h b/kdeprint/management/kmpropgeneral.h
new file mode 100644
index 000000000..4fad67996
--- /dev/null
+++ b/kdeprint/management/kmpropgeneral.h
@@ -0,0 +1,44 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMPROPGENERAL_H
+#define KMPROPGENERAL_H
+
+#include "kmpropwidget.h"
+
+class QLabel;
+
+class KMPropGeneral : public KMPropWidget
+{
+public:
+ KMPropGeneral(QWidget *parent = 0, const char *name = 0);
+ ~KMPropGeneral();
+
+ void setPrinter(KMPrinter*);
+
+protected:
+ void configureWizard(KMWizard*);
+
+private:
+ QLabel *m_name;
+ QLabel *m_location;
+ QLabel *m_description;
+};
+
+#endif
diff --git a/kdeprint/management/kmpropmembers.cpp b/kdeprint/management/kmpropmembers.cpp
new file mode 100644
index 000000000..958ee763b
--- /dev/null
+++ b/kdeprint/management/kmpropmembers.cpp
@@ -0,0 +1,70 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmpropmembers.h"
+#include "kmprinter.h"
+#include "kmwizard.h"
+
+#include <qtextview.h>
+#include <qlayout.h>
+#include <klocale.h>
+
+KMPropMembers::KMPropMembers(QWidget *parent, const char *name)
+: KMPropWidget(parent,name)
+{
+ m_members = new QTextView(this);
+ m_members->setPaper(colorGroup().background());
+ m_members->setFrameStyle(QFrame::NoFrame);
+
+ QVBoxLayout *main_ = new QVBoxLayout(this, 10, 0);
+ main_->addWidget(m_members);
+
+ m_pixmap = "kdeprint_printer_class";
+ m_title = i18n("Members");
+ m_header = i18n("Class Members");
+}
+
+KMPropMembers::~KMPropMembers()
+{
+}
+
+void KMPropMembers::setPrinter(KMPrinter *p)
+{
+ if (p && ((p->isClass(false) && p->isLocal()) || p->isImplicit()))
+ {
+ QStringList l = p->members();
+ QString txt("<ul>");
+ for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it)
+ txt.append("<li>" + (*it) + "</li>");
+ txt.append("</ul>");
+ m_members->setText(txt);
+ emit enable(true);
+ emit enableChange(!p->isImplicit());
+ }
+ else
+ {
+ emit enable(false);
+ m_members->setText("");
+ }
+}
+
+void KMPropMembers::configureWizard(KMWizard *w)
+{
+ w->configure(KMWizard::Class,KMWizard::Class,true);
+}
diff --git a/kdeprint/management/kmpropmembers.h b/kdeprint/management/kmpropmembers.h
new file mode 100644
index 000000000..67f519dc7
--- /dev/null
+++ b/kdeprint/management/kmpropmembers.h
@@ -0,0 +1,42 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMPROPMEMBERS_H
+#define KMPROPMEMBERS_H
+
+#include "kmpropwidget.h"
+
+class QTextView;
+
+class KDEPRINT_EXPORT KMPropMembers : public KMPropWidget
+{
+public:
+ KMPropMembers(QWidget *parent = 0, const char *name = 0);
+ ~KMPropMembers();
+
+ void setPrinter(KMPrinter*);
+
+protected:
+ void configureWizard(KMWizard*);
+
+private:
+ QTextView *m_members;
+};
+
+#endif
diff --git a/kdeprint/management/kmpropwidget.cpp b/kdeprint/management/kmpropwidget.cpp
new file mode 100644
index 000000000..aa93f6a5f
--- /dev/null
+++ b/kdeprint/management/kmpropwidget.cpp
@@ -0,0 +1,86 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmpropwidget.h"
+#include "kmwizard.h"
+#include "kmfactory.h"
+#include "kmmanager.h"
+#include "kmtimer.h"
+
+#include <kmessagebox.h>
+#include <klocale.h>
+
+KMPropWidget::KMPropWidget(QWidget *parent, const char *name)
+: QWidget(parent,name)
+{
+ m_pixmap = "folder";
+ m_title = m_header = "Title";
+ m_printer = 0;
+ m_canchange = ((KMFactory::self()->manager()->printerOperationMask() & KMManager::PrinterCreation) && KMFactory::self()->manager()->hasManagement());
+
+ connect(this,SIGNAL(enable(bool)),this,SIGNAL(enableChange(bool)));
+}
+
+KMPropWidget::~KMPropWidget()
+{
+}
+
+void KMPropWidget::slotChange()
+{
+ KMTimer::self()->hold();
+ int value = requestChange();
+ if (value == -1)
+ {
+ KMessageBox::error(this, i18n("<qt>Unable to change printer properties. Error received from manager:<p>%1</p></qt>").arg(KMManager::self()->errorMsg()));
+ KMManager::self()->setErrorMsg(QString::null);
+ }
+ KMTimer::self()->release((value == 1));
+}
+
+void KMPropWidget::setPrinterBase(KMPrinter *p)
+{
+ m_printer = p;
+ setPrinter(p);
+}
+
+void KMPropWidget::setPrinter(KMPrinter*)
+{
+}
+
+void KMPropWidget::configureWizard(KMWizard*)
+{
+}
+
+// return status:
+// -1 : error
+// 0 : nothing to be done (canceled)
+// 1 : success
+int KMPropWidget::requestChange()
+{
+ if (m_printer)
+ {
+ KMWizard dlg(this);
+ configureWizard(&dlg);
+ dlg.setPrinter(m_printer);
+ if (dlg.exec())
+ return (KMFactory::self()->manager()->modifyPrinter(m_printer,dlg.printer()) ? 1 : -1);
+ }
+ return 0;
+}
+#include "kmpropwidget.moc"
diff --git a/kdeprint/management/kmpropwidget.h b/kdeprint/management/kmpropwidget.h
new file mode 100644
index 000000000..43d84d410
--- /dev/null
+++ b/kdeprint/management/kmpropwidget.h
@@ -0,0 +1,63 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMPROPWIDGET_H
+#define KMPROPWIDGET_H
+
+#include <qwidget.h>
+
+#include <kdelibs_export.h>
+
+class KMPrinter;
+class KMWizard;
+
+class KDEPRINT_EXPORT KMPropWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ KMPropWidget(QWidget *parent = 0, const char *name = 0);
+ virtual ~KMPropWidget();
+
+ virtual void setPrinter(KMPrinter*);
+ void setPrinterBase(KMPrinter*);
+ QString pixmap() const { return m_pixmap; }
+ QString title() const { return m_title; }
+ QString header() const { return m_header; }
+ bool canChange() const { return m_canchange; }
+
+signals:
+ void enable(bool);
+ void enableChange(bool);
+
+public slots:
+ void slotChange();
+
+protected:
+ virtual int requestChange();
+ virtual void configureWizard(KMWizard*);
+
+protected:
+ QString m_pixmap;
+ QString m_title;
+ QString m_header;
+ KMPrinter *m_printer;
+ bool m_canchange;
+};
+
+#endif
diff --git a/kdeprint/management/kmspecialprinterdlg.cpp b/kdeprint/management/kmspecialprinterdlg.cpp
new file mode 100644
index 000000000..31728249f
--- /dev/null
+++ b/kdeprint/management/kmspecialprinterdlg.cpp
@@ -0,0 +1,222 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmspecialprinterdlg.h"
+#include "kmprinter.h"
+#include "kdeprintcheck.h"
+#include "kmfactory.h"
+#include "kmspecialmanager.h"
+#include "kxmlcommandselector.h"
+#include "kxmlcommand.h"
+#include "driver.h"
+
+#include <qpushbutton.h>
+#include <qlineedit.h>
+#include <qcheckbox.h>
+#include <qcombobox.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qwhatsthis.h>
+#include <qgroupbox.h>
+#include <klocale.h>
+#include <kmessagebox.h>
+#include <kicondialog.h>
+#include <kfiledialog.h>
+#include <kseparator.h>
+
+KMSpecialPrinterDlg::KMSpecialPrinterDlg(QWidget *parent, const char *name)
+: KDialogBase(parent, name, true, QString::null, Ok|Cancel, Ok)
+{
+ setCaption(i18n("Add Special Printer"));
+
+ QWidget *dummy = new QWidget(this);
+ setMainWidget(dummy);
+
+ // widget creation
+ m_name = new QLineEdit(dummy);
+ connect(m_name, SIGNAL(textChanged ( const QString & )),this,SLOT(slotTextChanged(const QString & )));
+ m_description = new QLineEdit(dummy);
+ m_location = new QLineEdit(dummy);
+ QLabel *m_namelabel = new QLabel(i18n("&Name:"), dummy);
+ QLabel *m_desclabel = new QLabel(i18n("&Description:"), dummy);
+ QLabel *m_loclabel = new QLabel(i18n("&Location:"), dummy);
+ m_namelabel->setBuddy(m_name);
+ m_desclabel->setBuddy(m_description);
+ m_loclabel->setBuddy(m_location);
+
+ KSeparator* sep = new KSeparator( KSeparator::HLine, dummy);
+
+ sep->setFixedHeight(10);
+ QGroupBox *m_gb = new QGroupBox(1, Qt::Horizontal, i18n("Command &Settings"), dummy);
+ m_command = new KXmlCommandSelector(true, m_gb, "CommandSelector", this);
+
+ QGroupBox *m_outfile_gb = new QGroupBox( 0, Qt::Horizontal, i18n( "Outp&ut File" ), dummy );
+
+ m_usefile = new QCheckBox( i18n("&Enable output file"), m_outfile_gb);
+
+ m_mimetype = new QComboBox(m_outfile_gb);
+ KMimeType::List list = KMimeType::allMimeTypes();
+ for (QValueList<KMimeType::Ptr>::ConstIterator it=list.begin(); it!=list.end(); ++it)
+ {
+ QString mimetype = (*it)->name();
+ m_mimelist << mimetype;
+ }
+ m_mimelist.sort();
+ m_mimetype->insertStringList(m_mimelist);
+
+ QLabel *m_mimetypelabel = new QLabel(i18n("&Format:"), m_outfile_gb);
+ m_mimetypelabel->setBuddy (m_mimetype);
+
+ m_extension = new QLineEdit(m_outfile_gb);
+
+ QLabel *m_extensionlabel = new QLabel(i18n("Filename e&xtension:"), m_outfile_gb);
+ m_extensionlabel->setBuddy(m_extension);
+
+ m_icon = new KIconButton(dummy);
+ m_icon->setIcon("fileprint");
+ m_icon->setFixedSize(QSize(48,48));
+
+ connect( m_usefile, SIGNAL( toggled( bool ) ), m_mimetype, SLOT( setEnabled( bool ) ) );
+ connect( m_usefile, SIGNAL( toggled( bool ) ), m_extension, SLOT( setEnabled( bool ) ) );
+ connect( m_usefile, SIGNAL( toggled( bool ) ), m_mimetypelabel, SLOT( setEnabled( bool ) ) );
+ connect( m_usefile, SIGNAL( toggled( bool ) ), m_extensionlabel, SLOT( setEnabled( bool ) ) );
+ m_mimetypelabel->setEnabled( false );
+ m_mimetype->setEnabled( false );
+ m_extensionlabel->setEnabled( false );
+ m_extension->setEnabled( false );
+
+ QWhatsThis::add(m_usefile,
+ i18n("<p>The command will use an output file. If checked, make sure the "
+ "command contains an output tag.</p>"));
+ QWhatsThis::add(m_command,
+ i18n("<p>The command to execute when printing on this special printer. Either enter "
+ "the command to execute directly, or associate/create a command object with/for "
+ "this special printer. The command object is the preferred method as it provides "
+ "support for advanced settings like mime type checking, configurable options and "
+ "requirement list (the plain command is only provided for backward compatibility). "
+ "When using a plain command, the following tags are recognized:</p>"
+ "<ul><li><b>%in</b>: the input file (required).</li>"
+ "<li><b>%out</b>: the output file (required if using an output file).</li>"
+ "<li><b>%psl</b>: the paper size in lower case.</li>"
+ "<li><b>%psu</b>: the paper size with the first letter in upper case.</li></ul>"));
+ QString mimetypeWhatsThis = i18n("<p>The default mimetype for the output file (e.g. application/postscript).</p>");
+ QWhatsThis::add(m_mimetypelabel, mimetypeWhatsThis);
+ QWhatsThis::add(m_mimetype, mimetypeWhatsThis);
+ QString extensionWhatsThis = i18n("<p>The default extension for the output file (e.g. ps, pdf, ps.gz).</p>");
+ QWhatsThis::add(m_extensionlabel, extensionWhatsThis);
+ QWhatsThis::add(m_extension, extensionWhatsThis);
+
+ // layout creation
+ QVBoxLayout *l0 = new QVBoxLayout(dummy, 0, 10);
+ QGridLayout *l1 = new QGridLayout(0, 3, 3, 0, 5);
+ l0->addLayout(l1);
+ l1->setColStretch(2,1);
+ l1->addColSpacing(0,60);
+ l1->addMultiCellWidget(m_icon, 0, 2, 0, 0, Qt::AlignCenter);
+ l1->addWidget(m_namelabel, 0, 1);
+ l1->addWidget(m_desclabel, 1, 1);
+ l1->addWidget(m_loclabel, 2, 1);
+ l1->addWidget(m_name, 0, 2);
+ l1->addWidget(m_description, 1, 2);
+ l1->addWidget(m_location, 2, 2);
+ l0->addWidget(sep);
+ l0->addWidget(m_gb);
+ l0->addWidget(m_outfile_gb);
+ QGridLayout *l6 = new QGridLayout(m_outfile_gb->layout(), 3, 2, 10);
+ l6->addMultiCellWidget( m_usefile, 0, 0, 0, 1 );
+ l6->addWidget(m_mimetypelabel, 1, 0);
+ l6->addWidget(m_mimetype, 1, 1);
+ l6->addWidget(m_extensionlabel, 2, 0);
+ l6->addWidget(m_extension, 2, 1);
+
+ enableButton(Ok, !m_name->text().isEmpty());
+
+ // resize dialog
+ resize(400,100);
+}
+
+void KMSpecialPrinterDlg::slotTextChanged(const QString & )
+{
+ enableButton(Ok, !m_name->text().isEmpty());
+}
+
+void KMSpecialPrinterDlg::slotOk()
+{
+ if (!checkSettings())
+ return;
+ KDialogBase::slotOk();
+}
+
+bool KMSpecialPrinterDlg::checkSettings()
+{
+ QString msg;
+ if (m_name->text().isEmpty())
+ msg = i18n("You must provide a non-empty name.");
+ else
+ KXmlCommandManager::self()->checkCommand(m_command->command(),
+ KXmlCommandManager::Basic,
+ (m_usefile->isChecked() ? KXmlCommandManager::Basic : KXmlCommandManager::None),
+ &msg);
+
+ if (!msg.isEmpty())
+ KMessageBox::error(this, i18n("Invalid settings. %1.").arg(msg));
+
+ return (msg.isEmpty());
+}
+
+void KMSpecialPrinterDlg::setPrinter(KMPrinter *printer)
+{
+ if (printer && printer->isSpecial())
+ {
+ m_command->setCommand(printer->option("kde-special-command"));
+ m_usefile->setChecked(printer->option("kde-special-file") == "1");
+ int index = m_mimelist.findIndex(printer->option("kde-special-mimetype"));
+ m_mimetype->setCurrentItem(index == -1 ? 0 : index);
+ m_extension->setText(printer->option("kde-special-extension"));
+ m_name->setText(printer->name());
+ m_description->setText(printer->description());
+ m_location->setText(printer->location());
+ m_icon->setIcon(printer->pixmap());
+
+ setCaption(i18n("Configuring %1").arg(printer->name()));
+ }
+}
+
+KMPrinter* KMSpecialPrinterDlg::printer()
+{
+ KMPrinter *printer = new KMPrinter();
+ printer->setName(m_name->text());
+ printer->setPrinterName(m_name->text());
+ printer->setPixmap(m_icon->icon());
+ printer->setDescription(m_description->text());
+ printer->setLocation(m_location->text());
+ printer->setOption("kde-special-command",m_command->command());
+ printer->setOption("kde-special-file",(m_usefile->isChecked() ? "1" : "0"));
+ if (m_usefile->isChecked ())
+ {
+ if (m_mimetype->currentText() != "all/all")
+ printer->setOption("kde-special-mimetype", m_mimetype->currentText());
+ printer->setOption("kde-special-extension",m_extension->text());
+ }
+ printer->setType(KMPrinter::Special);
+ printer->setState(KMPrinter::Idle);
+ return printer;
+}
+
+#include "kmspecialprinterdlg.moc"
diff --git a/kdeprint/management/kmspecialprinterdlg.h b/kdeprint/management/kmspecialprinterdlg.h
new file mode 100644
index 000000000..2cba217c4
--- /dev/null
+++ b/kdeprint/management/kmspecialprinterdlg.h
@@ -0,0 +1,57 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMSPECIALPRINTERDLG_H
+#define KMSPECIALPRINTERDLG_H
+
+#include <kdialogbase.h>
+
+class KMPrinter;
+class QLineEdit;
+class QCheckBox;
+class QComboBox;
+class KIconButton;
+class KXmlCommandSelector;
+
+class KMSpecialPrinterDlg : public KDialogBase
+{
+ Q_OBJECT
+public:
+ KMSpecialPrinterDlg(QWidget *parent = 0, const char *name = 0);
+
+ void setPrinter(KMPrinter*);
+ KMPrinter* printer();
+
+protected:
+ bool checkSettings();
+
+protected slots:
+ void slotOk();
+ void slotTextChanged(const QString &);
+
+private:
+ QLineEdit *m_name, *m_description, *m_location, *m_extension;
+ QComboBox *m_mimetype;
+ QCheckBox *m_usefile;
+ QStringList m_mimelist;
+ KIconButton *m_icon;
+ KXmlCommandSelector *m_command;
+};
+
+#endif
diff --git a/kdeprint/management/kmtimer.cpp b/kdeprint/management/kmtimer.cpp
new file mode 100644
index 000000000..ae8725848
--- /dev/null
+++ b/kdeprint/management/kmtimer.cpp
@@ -0,0 +1,96 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmtimer.h"
+#include "kmfactory.h"
+
+#include <kconfig.h>
+
+KMTimer* KMTimer::m_self = 0;
+
+KMTimer* KMTimer::self()
+{
+ if (!m_self)
+ {
+ m_self = new KMTimer(KMFactory::self(), "InternalTimer");
+ Q_CHECK_PTR(m_self);
+ }
+ return m_self;
+}
+
+KMTimer::KMTimer(QObject *parent, const char *name)
+: QTimer(parent, name), m_count(0)
+{
+ connect(this, SIGNAL(timeout()), SLOT(slotTimeout()));
+}
+
+KMTimer::~KMTimer()
+{
+ m_self = 0;
+}
+
+void KMTimer::hold()
+{
+ if ((m_count++) == 0)
+ stop();
+}
+
+void KMTimer::release()
+{
+ releaseTimer(false);
+}
+
+void KMTimer::release(bool do_emit)
+{
+ releaseTimer(do_emit);
+}
+
+void KMTimer::releaseTimer(bool do_emit)
+{
+ m_count = QMAX(0, m_count-1);
+ if (m_count == 0)
+ {
+ if (do_emit)
+ emit timeout();
+ startTimer();
+ }
+}
+
+void KMTimer::delay(int t)
+{
+ startTimer(t);
+}
+
+void KMTimer::slotTimeout()
+{
+ startTimer();
+}
+
+void KMTimer::startTimer(int t)
+{
+ if (t == -1)
+ {
+ KConfig *conf = KMFactory::self()->printConfig();
+ conf->setGroup("General");
+ t = conf->readNumEntry("TimerDelay", 5) * 1000;
+ }
+ start(t, true);
+}
+
+#include "kmtimer.moc"
diff --git a/kdeprint/management/kmtimer.h b/kdeprint/management/kmtimer.h
new file mode 100644
index 000000000..b4ac49a56
--- /dev/null
+++ b/kdeprint/management/kmtimer.h
@@ -0,0 +1,62 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMTIMER_H
+#define KMTIMER_H
+
+#if !defined( _KDEPRINT_COMPILE ) && defined( __GNUC__ )
+#warning internal header, do not use except if you are a KDEPrint developer
+#endif
+
+#include <qtimer.h>
+#include <kdelibs_export.h>
+
+/**
+ * @internal
+ * This class is internal to KDEPrint and is not intended to be
+ * used outside it. Please do not make use of this header, except
+ * if you're a KDEPrint developer. The API might change in the
+ * future and binary compatibility might be broken.
+ */
+class KDEPRINT_EXPORT KMTimer : public QTimer
+{
+ Q_OBJECT
+public:
+ void delay(int t);
+ ~KMTimer();
+
+public slots:
+ void hold();
+ void release();
+ void release(bool do_emit);
+
+ static KMTimer* self();
+
+private slots:
+ void slotTimeout();
+
+private:
+ static KMTimer *m_self;
+ int m_count;
+ KMTimer(QObject *parent = 0, const char *name = 0);
+ void releaseTimer(bool do_emit = false);
+ void startTimer(int delay = -1);
+};
+
+#endif
diff --git a/kdeprint/management/kmwbackend.cpp b/kdeprint/management/kmwbackend.cpp
new file mode 100644
index 000000000..32f95949d
--- /dev/null
+++ b/kdeprint/management/kmwbackend.cpp
@@ -0,0 +1,177 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmwbackend.h"
+#include "kmwizard.h"
+#include "kmprinter.h"
+
+#include <qlayout.h>
+#include <qregexp.h>
+#include <qbuttongroup.h>
+#include <qradiobutton.h>
+#include <qwhatsthis.h>
+
+#include <kcursor.h>
+#include <klocale.h>
+#include <kseparator.h>
+#include <kdialog.h>
+#include <kdebug.h>
+
+class KRadioButton : public QRadioButton
+{
+public:
+ KRadioButton(const QString& txt, QWidget *parent = 0, const char *name = 0);
+};
+
+KRadioButton::KRadioButton(const QString& txt, QWidget *parent, const char *name)
+: QRadioButton(txt,parent,name)
+{
+ setCursor(KCursor::handCursor());
+}
+
+//********************************************************************************************************
+
+KMWBackend::KMWBackend(QWidget *parent, const char *name)
+: KMWizardPage(parent,name)
+{
+ m_ID = KMWizard::Backend;
+ m_title = i18n("Backend Selection");
+
+ m_buttons = new QButtonGroup(this);
+ m_buttons->hide();
+
+ m_layout = new QVBoxLayout(this, 0, KDialog::spacingHint());
+ m_layout->addStretch(1);
+ m_count = 0;
+}
+
+bool KMWBackend::isValid(QString& msg)
+{
+ if (!m_buttons->selected())
+ {
+ msg = i18n("You must select a backend.");
+ return false;
+ }
+ return true;
+}
+
+void KMWBackend::initPrinter(KMPrinter *p)
+{
+ QString s = p->option("kde-backend");
+ int ID(-1);
+
+ if (!s.isEmpty())
+ ID = s.toInt();
+ else
+ {
+ s = p->deviceProtocol();
+ // extract protocol
+ if (s == "parallel" || s == "serial" || s == "usb") ID = KMWizard::Local;
+ else if (s == "smb") ID = KMWizard::SMB;
+ else if (s == "ipp" || s == "http") ID = KMWizard::IPP;
+ else if (s == "lpd") ID = KMWizard::LPD;
+ else if (s == "socket") ID = KMWizard::TCP;
+ else if (s == "file") ID = KMWizard::File;
+ else if (p->members().count() > 0) ID = KMWizard::Class;
+ }
+
+ if (m_buttons->find(ID))
+ m_buttons->setButton(ID);
+}
+
+void KMWBackend::updatePrinter(KMPrinter *p)
+{
+ int ID = m_buttons->id(m_buttons->selected());
+ if (ID == KMWizard::Class) p->setType(KMPrinter::Class);
+ else p->setType(KMPrinter::Printer);
+ p->setOption("kde-backend",QString::number(ID));
+ QString s = m_buttons->selected()->text();
+ s.replace(QRegExp("&(?=\\w)"), QString::fromLatin1(""));
+ p->setOption("kde-backend-description",s);
+ setNextPage((m_map.contains(ID) ? m_map[ID] : KMWizard::Error));
+}
+
+void KMWBackend::addBackend( int ID, bool on, int nextpage )
+{
+ switch ( ID )
+ {
+ case KMWizard::Local:
+ addBackend( ID, i18n("&Local printer (parallel, serial, USB)"), on,
+ i18n( "<qt><p>Locally-connected printer</p>"
+ "<p>Use this for a printer connected "
+ "to the computer via a parallel, serial or USB port.</p></qt>" ),
+ nextpage );
+ break;
+ case KMWizard::SMB:
+ addBackend( ID, i18n("&SMB shared printer (Windows)"), on,
+ i18n( "<qt><p>Shared Windows printer</p>"
+ "<p>Use this for a printer installed "
+ "on a Windows server and shared on the network using the SMB "
+ "protocol (samba).</p></qt>" ),
+ nextpage );
+ break;
+ case KMWizard::LPD:
+ addBackend( ID, i18n("&Remote LPD queue"), on,
+ i18n( "<qt><p>Print queue on a remote LPD server</p>"
+ "<p>Use this for a print queue "
+ "existing on a remote machine running a LPD print server.</p></qt>" ),
+ nextpage );
+ break;
+ case KMWizard::TCP:
+ addBackend( ID, i18n("Ne&twork printer (TCP)"), on,
+ i18n( "<qt><p>Network TCP printer</p>"
+ "<p>Use this for a network-enabled printer "
+ "using TCP (usually on port 9100) as communication protocol. Most "
+ "network printers can use this mode.</p></qt>" ),
+ nextpage );
+ break;
+ case -1:
+ addBackend( ID, QString::null, on, QString::null, nextpage );
+ break;
+ default:
+ kdError( 500 ) << "Non standard wizard page ID: " << ID << endl;
+ }
+}
+
+void KMWBackend::addBackend(int ID, const QString& txt, bool on, const QString& whatsThis, int nextpage)
+{
+ if (ID == -1)
+ {
+ KSeparator* sep = new KSeparator( KSeparator::HLine, this);
+ m_layout->insertWidget(m_count, sep);
+ }
+ else
+ {
+ KRadioButton *btn = new KRadioButton(txt, this);
+ btn->setEnabled(on);
+ if ( !whatsThis.isEmpty() )
+ QWhatsThis::add( btn, whatsThis );
+ m_buttons->insert(btn, ID);
+ m_map[ID] = (nextpage == -1 ? ID : nextpage); // use nextpage if specified, default to ID
+ m_layout->insertWidget(m_count, btn);
+ }
+ m_count++;
+}
+
+void KMWBackend::enableBackend(int ID, bool on)
+{
+ QButton *btn = m_buttons->find(ID);
+ if (btn)
+ btn->setEnabled(on);
+}
diff --git a/kdeprint/management/kmwbackend.h b/kdeprint/management/kmwbackend.h
new file mode 100644
index 000000000..654ec3337
--- /dev/null
+++ b/kdeprint/management/kmwbackend.h
@@ -0,0 +1,54 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMWBACKEND_H
+#define KMWBACKEND_H
+
+#include "kmwizardpage.h"
+#include <kdelibs_export.h>
+#include <qmap.h>
+
+class QButtonGroup;
+class QVBoxLayout;
+
+class KDEPRINT_EXPORT KMWBackend : public KMWizardPage
+{
+public:
+ KMWBackend(QWidget *parent = 0, const char *name = 0);
+
+ bool isValid(QString&);
+ void initPrinter(KMPrinter*);
+ void updatePrinter(KMPrinter*);
+
+ void addBackend(int ID, const QString& txt, bool on = true, const QString& whatsThis = QString::null, int nextpage = -1);
+ void addBackend(int ID = -1, bool on = true, int nextpage = -1);
+ void enableBackend(int ID, bool on = true);
+
+private:
+ QButtonGroup *m_buttons;
+ QVBoxLayout *m_layout;
+ // keep a map between button ID and the real next page to switch to. This enables
+ // to have different backends switching to the same page (like backends requiring
+ // a password). If the next page is not given when adding the backend, the ID is
+ // used by default.
+ QMap<int,int> m_map;
+ int m_count;
+};
+
+#endif
diff --git a/kdeprint/management/kmwclass.cpp b/kdeprint/management/kmwclass.cpp
new file mode 100644
index 000000000..6d80a6ff3
--- /dev/null
+++ b/kdeprint/management/kmwclass.cpp
@@ -0,0 +1,141 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmwclass.h"
+#include "kmwizard.h"
+#include "kmfactory.h"
+#include "kmmanager.h"
+#include "kmprinter.h"
+
+#include <qlayout.h>
+#include <qlabel.h>
+#include <qtoolbutton.h>
+#include <klistbox.h>
+#include <klocale.h>
+#include <kiconloader.h>
+
+KMWClass::KMWClass(QWidget *parent, const char *name)
+: KMWizardPage(parent,name)
+{
+ m_ID = KMWizard::Class;
+ m_title = i18n("Class Composition");
+ m_nextpage = KMWizard::Name;
+
+ m_list1 = new KListBox(this);
+ m_list1->setSelectionMode(QListBox::Extended);
+ m_list2 = new KListBox(this);
+ m_list2->setSelectionMode(QListBox::Extended);
+
+ QToolButton *add = new QToolButton(this);
+ QToolButton *remove = new QToolButton(this);
+ add->setIconSet(BarIcon("forward"));
+ remove->setIconSet(BarIcon("back"));
+ connect(add,SIGNAL(clicked()),SLOT(slotAdd()));
+ connect(remove,SIGNAL(clicked()),SLOT(slotRemove()));
+
+ QLabel *l1 = new QLabel(i18n("Available printers:"), this);
+ QLabel *l2 = new QLabel(i18n("Class printers:"), this);
+
+ QHBoxLayout *lay1 = new QHBoxLayout(this, 0, 15);
+ QVBoxLayout *lay2 = new QVBoxLayout(0, 0, 20);
+ QVBoxLayout *lay3 = new QVBoxLayout(0, 0, 0), *lay4 = new QVBoxLayout(0, 0, 0);
+ lay1->addLayout(lay3, 1);
+ lay1->addLayout(lay2, 0);
+ lay1->addLayout(lay4, 1);
+ lay3->addWidget(l1, 0);
+ lay3->addWidget(m_list1, 1);
+ lay2->addStretch(1);
+ lay2->addWidget(add, 0);
+ lay2->addWidget(remove, 0);
+ lay2->addStretch(1);
+ lay4->addWidget(l2, 0);
+ lay4->addWidget(m_list2, 1);
+}
+
+KMWClass::~KMWClass()
+{
+}
+
+bool KMWClass::isValid(QString& msg)
+{
+ if (m_list2->count() == 0)
+ {
+ msg = i18n("You must select at least one printer.");
+ return false;
+ }
+ return true;
+}
+
+void KMWClass::initPrinter(KMPrinter *p)
+{
+ QStringList members = p->members();
+ KMManager *mgr = KMFactory::self()->manager();
+
+ // first load available printers
+ QPtrList<KMPrinter> *list = mgr->printerList(false);
+ m_list1->clear();
+ if (list)
+ {
+ QPtrListIterator<KMPrinter> it(*list);
+ for (;it.current();++it)
+ if (it.current()->instanceName().isEmpty() && !it.current()->isClass(true) && !it.current()->isSpecial() && !members.contains(it.current()->name()))
+ m_list1->insertItem(SmallIcon(it.current()->pixmap()), it.current()->name());
+ m_list1->sort();
+ }
+
+ // set class printers
+ m_list2->clear();
+ for (QStringList::ConstIterator it=members.begin(); it!=members.end(); ++it)
+ {
+ KMPrinter *pr = mgr->findPrinter(*it);
+ if (pr) m_list2->insertItem(SmallIcon(pr->pixmap()), *it);
+ }
+ m_list2->sort();
+}
+
+void KMWClass::updatePrinter(KMPrinter *p)
+{
+ QStringList members;
+ for (uint i=0; i<m_list2->count(); i++)
+ members.append(m_list2->item(i)->text());
+ p->setMembers(members);
+}
+
+void KMWClass::slotAdd()
+{
+ for (uint i=0;i<m_list1->count();i++)
+ if (m_list1->isSelected(i))
+ {
+ m_list2->insertItem(*(m_list1->pixmap(i)), m_list1->text(i));
+ m_list1->removeItem(i--);
+ }
+ m_list2->sort();
+}
+
+void KMWClass::slotRemove()
+{
+ for (uint i=0;i<m_list2->count();i++)
+ if (m_list2->isSelected(i))
+ {
+ m_list1->insertItem(*(m_list2->pixmap(i)), m_list2->text(i));
+ m_list2->removeItem(i--);
+ }
+ m_list1->sort();
+}
+#include "kmwclass.moc"
diff --git a/kdeprint/management/kmwclass.h b/kdeprint/management/kmwclass.h
new file mode 100644
index 000000000..4a4475b7d
--- /dev/null
+++ b/kdeprint/management/kmwclass.h
@@ -0,0 +1,46 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMWCLASS_H
+#define KMWCLASS_H
+
+#include "kmwizardpage.h"
+
+class KListBox;
+
+class KMWClass : public KMWizardPage
+{
+ Q_OBJECT
+public:
+ KMWClass(QWidget *parent = 0, const char *name = 0);
+ ~KMWClass();
+
+ bool isValid(QString&);
+ void initPrinter(KMPrinter*);
+ void updatePrinter(KMPrinter*);
+
+protected slots:
+ void slotAdd();
+ void slotRemove();
+
+private:
+ KListBox *m_list1, *m_list2;
+};
+
+#endif
diff --git a/kdeprint/management/kmwdriver.cpp b/kdeprint/management/kmwdriver.cpp
new file mode 100644
index 000000000..66ab87d20
--- /dev/null
+++ b/kdeprint/management/kmwdriver.cpp
@@ -0,0 +1,116 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmwdriver.h"
+#include "kmwizard.h"
+#include "kmprinter.h"
+#include "kmdriverdbwidget.h"
+#include "kmdriverdb.h"
+
+#include <qlayout.h>
+#include <klocale.h>
+
+KMWDriver::KMWDriver(QWidget *parent, const char *name)
+: KMWizardPage(parent,name)
+{
+ m_ID = KMWizard::Driver;
+ m_title = i18n("Printer Model Selection");
+ m_nextpage = KMWizard::DriverTest;
+
+ m_widget = new KMDriverDbWidget(this);
+
+ QVBoxLayout *lay1 = new QVBoxLayout(this, 0, 0);
+ lay1->addWidget(m_widget);
+}
+
+void KMWDriver::initPrinter(KMPrinter *p)
+{
+ m_widget->init();
+ if (p)
+ {
+ QString autoDetect = p->option( "kde-autodetect" );
+ if ( !autoDetect.isEmpty() )
+ {
+ // use auto-detection info instead: split the string
+ // into make/model pair at the first space character
+ int p = autoDetect.find( ' ' );
+ if ( p != -1 )
+ {
+ QString manu = autoDetect.left( p ), model = autoDetect.mid( p+1 );
+ KMDBEntryList *l = KMDriverDB::self()->findPnpEntry( manu, model );
+ if ( l && l->count() > 0 )
+ {
+ m_widget->setDriver( l->getFirst()->manufacturer, l->getFirst()->model );
+ return;
+ }
+ }
+ }
+ m_widget->setDriver(p->manufacturer(),p->model());
+ }
+}
+
+void KMWDriver::updatePrinter(KMPrinter *p)
+{
+ if (p)
+ {
+ p->setManufacturer(QString::null);
+ p->setModel(QString::null);
+ p->setDbEntry(0);
+ p->setDriverInfo(QString::null);
+ p->setOption("kde-driver",QString::null);
+ setNextPage(KMWizard::DriverTest);
+ if (m_widget->isRaw())
+ {
+ p->setDriverInfo(i18n("Raw printer"));
+ p->setOption("kde-driver","raw");
+ }
+ else
+ {
+ p->setManufacturer(m_widget->manufacturer());
+ p->setModel(m_widget->model());
+ if (m_widget->isExternal())
+ {
+ p->setDriverInfo(m_widget->description());
+ p->setOption("kde-driver",m_widget->driverFile());
+ }
+ else
+ {
+ KMDBEntryList *drvs = m_widget->drivers();
+ if (drvs->count() == 1)
+ {
+ p->setDbEntry(drvs->getFirst());
+ p->setDriverInfo(drvs->getFirst()->description);
+ }
+ else
+ setNextPage(KMWizard::DriverSelect);
+ }
+ }
+ }
+}
+
+bool KMWDriver::isValid(QString& msg)
+{
+ if (m_widget->isRaw() || m_widget->isExternal() || m_widget->drivers())
+ return true;
+ else
+ {
+ msg = i18n("Internal error: unable to locate the driver.");
+ return false;
+ }
+}
diff --git a/kdeprint/management/kmwdriver.h b/kdeprint/management/kmwdriver.h
new file mode 100644
index 000000000..0961f7a81
--- /dev/null
+++ b/kdeprint/management/kmwdriver.h
@@ -0,0 +1,40 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMWDRIVER_H
+#define KMWDRIVER_H
+
+#include "kmwizardpage.h"
+
+class KMDriverDbWidget;
+
+class KMWDriver : public KMWizardPage
+{
+public:
+ KMWDriver(QWidget *parent = 0, const char *name = 0);
+
+ bool isValid(QString&);
+ void updatePrinter(KMPrinter*);
+ void initPrinter(KMPrinter*);
+
+private:
+ KMDriverDbWidget *m_widget;
+};
+
+#endif
diff --git a/kdeprint/management/kmwdriverselect.cpp b/kdeprint/management/kmwdriverselect.cpp
new file mode 100644
index 000000000..ed97b967c
--- /dev/null
+++ b/kdeprint/management/kmwdriverselect.cpp
@@ -0,0 +1,116 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmwdriverselect.h"
+#include "kmwizard.h"
+#include "kmprinter.h"
+#include "kmdbentry.h"
+#include "kmdriverdb.h"
+
+#include <qlabel.h>
+#include <qlayout.h>
+#include <kpushbutton.h>
+#include <klistbox.h>
+#include <klocale.h>
+#include <kmessagebox.h>
+
+KMWDriverSelect::KMWDriverSelect(QWidget *parent, const char *name)
+: KMWizardPage(parent,name)
+{
+ m_ID = KMWizard::DriverSelect;
+ m_title = i18n("Driver Selection");
+ m_nextpage = KMWizard::DriverTest;
+ m_entries = NULL;
+
+ m_list = new KListBox(this);
+ QLabel *l1 = new QLabel(this);
+ l1->setText(i18n("<p>Several drivers have been detected for this model. Select the driver "
+ "you want to use. You will have the opportunity to test it as well as to "
+ "change it if necessary.</p>"));
+ m_drivercomment = new KPushButton(i18n("Driver Information"), this);
+ connect(m_drivercomment, SIGNAL(clicked()), SLOT(slotDriverComment()));
+
+ QVBoxLayout *main_ = new QVBoxLayout(this, 0, 10);
+ main_->addWidget(l1,0);
+ main_->addWidget(m_list,1);
+ QHBoxLayout *lay0 = new QHBoxLayout(0, 0, 0);
+ main_->addLayout(lay0,0);
+ lay0->addStretch(1);
+ lay0->addWidget(m_drivercomment);
+}
+
+bool KMWDriverSelect::isValid(QString& msg)
+{
+ if (m_list->currentItem() == -1)
+ {
+ msg = i18n("You must select a driver.");
+ return false;
+ }
+ return true;
+}
+
+void KMWDriverSelect::initPrinter(KMPrinter *p)
+{
+ m_entries = KMDriverDB::self()->findEntry(p->manufacturer(),p->model());
+ m_list->clear();
+ if (m_entries)
+ {
+ KMDBEntryListIterator it(*m_entries);
+ int recomm(0);
+ for (;it.current();++it)
+ {
+ QString s(it.current()->description);
+ if (it.current()->recommended)
+ {
+ recomm = m_list->count();
+ s.append(i18n(" [recommended]"));
+ }
+ m_list->insertItem(s);
+ }
+ if (m_entries->count() > 0)
+ m_list->setSelected(recomm, true);
+ }
+}
+
+void KMWDriverSelect::updatePrinter(KMPrinter *p)
+{
+ int index = m_list->currentItem();
+ if (m_entries && index >= 0 && index < (int)(m_entries->count()))
+ {
+ KMDBEntry *entry = m_entries->at(index);
+ p->setDbEntry(entry);
+ p->setDriverInfo(entry->description);
+ }
+ else
+ {
+ p->setDbEntry(0);
+ p->setDriverInfo(QString::null);
+ }
+}
+
+void KMWDriverSelect::slotDriverComment()
+{
+ int index = m_list->currentItem();
+ if (m_entries && index >=0 && index < (int)(m_entries->count()) && !m_entries->at(index)->drivercomment.isEmpty())
+ KMessageBox::information(this, m_entries->at(index)->drivercomment, QString::null, QString::null, KMessageBox::AllowLink);
+ else
+ KMessageBox::error(this, i18n("No information about the selected driver."));
+}
+
+#include "kmwdriverselect.moc"
diff --git a/kdeprint/management/kmwdriverselect.h b/kdeprint/management/kmwdriverselect.h
new file mode 100644
index 000000000..bf00f2e46
--- /dev/null
+++ b/kdeprint/management/kmwdriverselect.h
@@ -0,0 +1,48 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMWDRIVERSELECT_H
+#define KMWDRIVERSELECT_H
+
+#include "kmwizardpage.h"
+#include "kmdbentry.h"
+
+class KListBox;
+class QPushButton;
+
+class KMWDriverSelect : public KMWizardPage
+{
+ Q_OBJECT
+public:
+ KMWDriverSelect(QWidget *parent = 0, const char *name = 0);
+
+ bool isValid(QString&);
+ void initPrinter(KMPrinter*);
+ void updatePrinter(KMPrinter*);
+
+protected slots:
+ void slotDriverComment();
+
+private:
+ KListBox *m_list;
+ KMDBEntryList *m_entries;
+ QPushButton *m_drivercomment;
+};
+
+#endif
diff --git a/kdeprint/management/kmwdrivertest.cpp b/kdeprint/management/kmwdrivertest.cpp
new file mode 100644
index 000000000..5075e2204
--- /dev/null
+++ b/kdeprint/management/kmwdrivertest.cpp
@@ -0,0 +1,172 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmwdrivertest.h"
+#include "kmprinter.h"
+#include "kmwizard.h"
+#include "driver.h"
+#include "kmfactory.h"
+#include "kmmanager.h"
+#include "kmdriverdialog.h"
+
+#include <qlabel.h>
+#include <kpushbutton.h>
+#include <qlayout.h>
+#include <klocale.h>
+#include <kapplication.h>
+#include <kmessagebox.h>
+#include <kguiitem.h>
+#include <kio/netaccess.h>
+
+KMWDriverTest::KMWDriverTest(QWidget *parent, const char *name)
+: KMWizardPage(parent,name)
+{
+ m_ID = KMWizard::DriverTest;
+ m_title = i18n("Printer Test");
+ m_nextpage = KMWizard::Name;
+ m_needsinitonback = true;
+ m_driver = 0;
+ m_printer = 0;
+
+ m_manufacturer = new QLabel(this);
+ m_model = new QLabel(this);
+ m_driverinfo = new QLabel(this);
+ m_driverinfo->setTextFormat(Qt::RichText);
+ QLabel *l1 = new QLabel(i18n("<b>Manufacturer:</b>"), this);
+ QLabel *l2 = new QLabel(i18n("<b>Model:</b>"), this);
+ QLabel *l3 = new QLabel(i18n("<b>Description:</b>"), this);
+
+ m_test = new KPushButton(KGuiItem(i18n("&Test"), "kdeprint_testprinter"), this);
+ m_settings = new KPushButton(KGuiItem(i18n("&Settings"), "configure"), this);
+
+ QLabel *l0 = new QLabel(this);
+ l0->setText(i18n("<p>Now you can test the printer before finishing installation. "
+ "Use the <b>Settings</b> button to configure the printer driver and "
+ "the <b>Test</b> button to test your configuration. Use the <b>Back</b> "
+ "button to change the driver (your current configuration will be discarded).</p>"));
+
+ QVBoxLayout *lay1 = new QVBoxLayout(this, 0, 15);
+ QGridLayout *lay2 = new QGridLayout(0, 3, 3, 0, 0);
+ QHBoxLayout *lay3 = new QHBoxLayout(0, 0, 10);
+ lay1->addWidget(l0,0);
+ lay1->addLayout(lay2,0);
+ lay1->addLayout(lay3,0);
+ lay1->addStretch(1);
+ lay2->setColStretch(2,1);
+ lay2->addColSpacing(1,10);
+ lay2->addWidget(l1,0,0);
+ lay2->addWidget(l2,1,0);
+ lay2->addWidget(l3,2,0,Qt::AlignLeft|Qt::AlignTop);
+ lay2->addWidget(m_manufacturer,0,2);
+ lay2->addWidget(m_model,1,2);
+ lay2->addWidget(m_driverinfo,2,2);
+ lay3->addWidget(m_test,0);
+ lay3->addWidget(m_settings,0);
+ lay3->addStretch(1);
+
+ connect(m_test,SIGNAL(clicked()),SLOT(slotTest()));
+ connect(m_settings,SIGNAL(clicked()),SLOT(slotSettings()));
+}
+
+KMWDriverTest::~KMWDriverTest()
+{
+ delete m_driver;
+}
+
+void KMWDriverTest::initPrinter(KMPrinter *p)
+{
+ m_manufacturer->setText(p->manufacturer());
+ m_model->setText(p->model());
+ m_driverinfo->setText(p->driverInfo());
+ m_printer = p;
+
+ delete m_driver;
+ m_driver = 0;
+
+ QString drfile = p->option("kde-driver");
+ bool checkDriver(true);
+ if (!drfile.isEmpty() && drfile != "raw")
+ {
+ m_driver = KMFactory::self()->manager()->loadFileDriver(drfile);
+ /* remove the temp file if it has been downloaded */
+ KIO::NetAccess::removeTempFile( drfile );
+ }
+ else if (p->dbEntry() != NULL)
+ m_driver = KMFactory::self()->manager()->loadDbDriver(p->dbEntry());
+ else
+ checkDriver = false;
+
+ if (checkDriver && !m_driver)
+ {
+ KMessageBox::error(this, i18n("<qt>Unable to load the requested driver:<p>%1</p></qt>").arg(KMManager::self()->errorMsg()));
+ KMManager::self()->setErrorMsg(QString::null);
+ }
+ m_settings->setEnabled((m_driver != 0));
+}
+
+void KMWDriverTest::updatePrinter(KMPrinter *p)
+{
+ // Give the DrMain structure to the driver and don't care about it anymore.
+ // It will be destroyed either when giving another structure, or when the
+ // printer object will be destroyed.
+ p->setDriver(m_driver);
+ m_driver = 0;
+}
+
+void KMWDriverTest::slotTest()
+{
+ if (!m_printer) return;
+
+ QString name = "tmpprinter_"+KApplication::randomString(8);
+ // save printer name (can be non empty when modifying a printer)
+ QString oldname = m_printer->name();
+
+ m_printer->setName(name);
+ m_printer->setPrinterName(name);
+ m_printer->setDriver(m_driver);
+ if (KMFactory::self()->manager()->createPrinter(m_printer))
+ {
+ if (KMFactory::self()->manager()->testPrinter(m_printer))
+ KMessageBox::information(this,"<qt>"+i18n("Test page successfully sent to printer. Wait until printing is complete, then click the OK button."));
+ else
+ KMessageBox::error(this,"<qt>"+i18n("Unable to test printer: ")+KMFactory::self()->manager()->errorMsg()+"</qt>");
+ if (!KMFactory::self()->manager()->removePrinter(m_printer))
+ KMessageBox::error(this,i18n("Unable to remove temporary printer."));
+ }
+ else
+ KMessageBox::error(this,i18n("Unable to create temporary printer."));
+
+ // restoring old name
+ m_printer->setName(oldname);
+ m_printer->setPrinterName(oldname);
+
+ m_driver = m_printer->takeDriver();
+}
+
+void KMWDriverTest::slotSettings()
+{
+ if (m_driver)
+ {
+ KMDriverDialog dlg(this);
+ dlg.setDriver(m_driver);
+ dlg.showButtonCancel(false); // only OK button
+ dlg.exec();
+ }
+}
+#include "kmwdrivertest.moc"
diff --git a/kdeprint/management/kmwdrivertest.h b/kdeprint/management/kmwdrivertest.h
new file mode 100644
index 000000000..8433687dd
--- /dev/null
+++ b/kdeprint/management/kmwdrivertest.h
@@ -0,0 +1,53 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMWDRIVERTEST_H
+#define KMWDRIVERTEST_H
+
+#include "kmwizardpage.h"
+
+class QLabel;
+class QPushButton;
+class DrMain;
+
+class KMWDriverTest : public KMWizardPage
+{
+ Q_OBJECT
+public:
+ KMWDriverTest(QWidget *parent = 0, const char *name = 0);
+ ~KMWDriverTest();
+
+ void initPrinter(KMPrinter*);
+ void updatePrinter(KMPrinter*);
+
+protected slots:
+ void slotTest();
+ void slotSettings();
+
+private:
+ QLabel *m_manufacturer;
+ QLabel *m_model;
+ QLabel *m_driverinfo;
+ QPushButton *m_test;
+ QPushButton *m_settings;
+ DrMain *m_driver;
+ KMPrinter *m_printer;
+};
+
+#endif
diff --git a/kdeprint/management/kmwend.cpp b/kdeprint/management/kmwend.cpp
new file mode 100644
index 000000000..7386ba7f0
--- /dev/null
+++ b/kdeprint/management/kmwend.cpp
@@ -0,0 +1,119 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmwend.h"
+#include "kmprinter.h"
+#include "kmwizard.h"
+#include "util.h"
+
+#include <qtextview.h>
+#include <klocale.h>
+#include <qlayout.h>
+
+KMWEnd::KMWEnd(QWidget *parent, const char *name)
+: KMWizardPage(parent,name)
+{
+ m_ID = KMWizard::End;
+ m_title = i18n("Confirmation");
+ m_nextpage = KMWizard::Error;
+
+ m_view = new QTextView(this);
+
+ QVBoxLayout *lay = new QVBoxLayout(this, 0, 0);
+ lay->addWidget(m_view,1);
+}
+
+void KMWEnd::initPrinter(KMPrinter *p)
+{
+ QString txt;
+ QString s(QString::fromLatin1("<li><u>%1</u>: %2</li>"));
+ int ID = p->option("kde-backend").toInt();
+
+ // general information
+ txt.append(QString::fromLatin1("<b>%1</b><ul type=circle>").arg(i18n("General")));
+ txt.append(s.arg(i18n("Type")).arg(p->option("kde-backend-description")));
+ txt.append(s.arg(i18n("Name")).arg(p->name()));
+ txt.append(s.arg(i18n("Location")).arg(p->location()));
+ txt.append(s.arg(i18n("Description")).arg(p->description()));
+ txt.append("</ul><br>");
+
+ if (ID == KMWizard::Class)
+ {
+ // class members
+ txt.append(QString::fromLatin1("<b>%1</b><ul type=circle>").arg(i18n("Members")));
+ QStringList m(p->members());
+ QString s1(QString::fromLatin1("<li>%1</li>"));
+ for (QStringList::ConstIterator it=m.begin(); it!=m.end(); ++it)
+ txt.append(s1.arg(*it));
+ txt.append("</ul><br>");
+ }
+ else
+ {
+ // backend information
+ txt.append(QString::fromLatin1("<b>%1</b><ul type=circle>").arg(i18n("Backend")));
+ KURL url ( p->device() );
+ switch (ID)
+ {
+ case KMWizard::Local:
+ txt.append(s.arg(i18n("Device")).arg(url.path()));
+ break;
+ case KMWizard::TCP:
+ txt.append(s.arg(i18n("Printer IP")).arg(url.host()));
+ txt.append(s.arg(i18n("Port")).arg(url.port()));
+ break;
+ case KMWizard::LPD:
+ txt.append(s.arg(i18n("Host")).arg(url.host()));
+ txt.append(s.arg(i18n("Queue")).arg(url.path().right(url.path().length()-1)));
+ break;
+ case KMWizard::File:
+ txt.append(s.arg(i18n("File")).arg(url.path()));
+ break;
+ case KMWizard::IPP:
+ txt.append(s.arg(i18n("Host")).arg(url.host()));
+ txt.append(s.arg(i18n("Port")).arg(url.port()));
+ txt.append(s.arg(i18n("Printer")).arg(url.path().right(url.path().length()-1)));
+ if (url.hasUser()) txt.append(s.arg(i18n("Account")).arg(url.user()));
+ break;
+ default:
+ // double decoding in case the printer name contains chars like '#' that are
+ // not decoded by "prettyURL".
+ txt.append(s.arg(i18n("URI")).arg(KURL( p->device()).prettyURL()));
+ break;
+ }
+ txt.append("</ul><br>");
+
+ if (p->option("kde-driver") == "raw" || p->driver())
+ {
+ // driver information
+ txt.append(QString::fromLatin1("<b>%1</b><ul type=circle>").arg(i18n("Driver")));
+ if (p->option("kde-driver") == "raw")
+ txt.append(s.arg(i18n("Type")).arg(i18n("Raw printer")));
+ else
+ {
+ txt.append(s.arg(i18n("Type")).arg((p->dbEntry() ? i18n("DB driver") : i18n("External driver"))));
+ txt.append(s.arg(i18n("Manufacturer")).arg(p->manufacturer()));
+ txt.append(s.arg(i18n("Model")).arg(p->model()));
+ txt.append(s.arg(i18n("Description")).arg(p->driverInfo()));
+ }
+ txt.append("</ul><br>");
+ }
+ }
+
+ m_view->setText(txt);
+}
diff --git a/kdeprint/management/kmwend.h b/kdeprint/management/kmwend.h
new file mode 100644
index 000000000..4682d831e
--- /dev/null
+++ b/kdeprint/management/kmwend.h
@@ -0,0 +1,38 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMWEND_H
+#define KMWEND_H
+
+#include "kmwizardpage.h"
+
+class QTextView;
+
+class KMWEnd : public KMWizardPage
+{
+public:
+ KMWEnd(QWidget *parent = 0, const char *name = 0);
+
+ void initPrinter(KMPrinter*);
+
+private:
+ QTextView *m_view;
+};
+
+#endif
diff --git a/kdeprint/management/kmwfile.cpp b/kdeprint/management/kmwfile.cpp
new file mode 100644
index 000000000..497b03f27
--- /dev/null
+++ b/kdeprint/management/kmwfile.cpp
@@ -0,0 +1,77 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmwfile.h"
+#include "kmwizard.h"
+#include "kmprinter.h"
+
+#include <qlabel.h>
+#include <qlayout.h>
+
+#include <kurlrequester.h>
+#include <klocale.h>
+#include <kfiledialog.h>
+
+KMWFile::KMWFile(QWidget *parent, const char *name)
+: KMWizardPage(parent,name)
+{
+ m_ID = KMWizard::File;
+ m_title = i18n("File Selection");
+ m_nextpage = KMWizard::Driver;
+
+ m_url = new KURLRequester(this);
+ m_url->setMode((KFile::Mode)(KFile::File|KFile::LocalOnly));
+ QLabel *l1 = new QLabel(this);
+ l1->setText(i18n("<p>The printing will be redirected to a file. Enter here the path "
+ "of the file you want to use for redirection. Use an absolute path or "
+ "the browse button for graphical selection.</p>"));
+ QLabel *l2 = new QLabel(i18n("Print to file:"), this);
+
+ QVBoxLayout *lay1 = new QVBoxLayout(this, 0, 30);
+ QVBoxLayout *lay2 = new QVBoxLayout(0, 0, 5);
+ lay1->addWidget(l1);
+ lay1->addLayout(lay2);
+ lay1->addStretch(1);
+ lay2->addWidget(l2);
+ lay2->addWidget(m_url);
+}
+
+bool KMWFile::isValid(QString& msg)
+{
+ QFileInfo fi(m_url->url());
+ if (fi.fileName().isEmpty())
+ {
+ msg = i18n("Empty file name.");
+ return false;
+ }
+
+ if (!fi.dir().exists())
+ {
+ msg = i18n("Directory does not exist.");
+ return false;
+ }
+
+ return true;
+}
+
+void KMWFile::updatePrinter(KMPrinter *p)
+{
+ QString dev = QString::fromLatin1("file:%1").arg(m_url->url());
+ p->setDevice(dev);
+}
diff --git a/kdeprint/management/kmwfile.h b/kdeprint/management/kmwfile.h
new file mode 100644
index 000000000..7bcd779ed
--- /dev/null
+++ b/kdeprint/management/kmwfile.h
@@ -0,0 +1,39 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMWFILE_H
+#define KMWFILE_H
+
+#include "kmwizardpage.h"
+
+class KURLRequester;
+
+class KMWFile : public KMWizardPage
+{
+public:
+ KMWFile(QWidget *parent = 0, const char *name = 0);
+
+ bool isValid(QString&);
+ void updatePrinter(KMPrinter*);
+
+private:
+ KURLRequester *m_url;
+};
+
+#endif
diff --git a/kdeprint/management/kmwinfobase.cpp b/kdeprint/management/kmwinfobase.cpp
new file mode 100644
index 000000000..e58e452bb
--- /dev/null
+++ b/kdeprint/management/kmwinfobase.cpp
@@ -0,0 +1,90 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmwinfobase.h"
+
+#include <qlabel.h>
+#include <qlineedit.h>
+#include <qlayout.h>
+
+KMWInfoBase::KMWInfoBase(int n, QWidget *parent, const char *name)
+: KMWizardPage(parent,name)
+{
+ m_labels.setAutoDelete(false);
+ m_edits.setAutoDelete(false);
+
+ m_nlines = n;
+ QGridLayout *lay1 = new QGridLayout(this, m_nlines+3, 2, 0, 10);
+ lay1->addRowSpacing(1,10);
+ lay1->setRowStretch(m_nlines+2,1);
+ lay1->setColStretch(1,1);
+
+ m_info = new QLabel(this);
+ m_info->setTextFormat(Qt::RichText);
+ lay1->addMultiCellWidget(m_info,0,0,0,1);
+
+ for (int i=0;i<m_nlines;i++)
+ {
+ m_labels.append(new QLabel(this));
+ m_edits.append(new QLineEdit(this));
+ lay1->addWidget(m_labels.last(),i+2,0);
+ lay1->addWidget(m_edits.last(),i+2,1);
+ }
+}
+
+void KMWInfoBase::setInfo(const QString& s)
+{
+ m_info->setText(s);
+}
+
+void KMWInfoBase::setLabel(int i, const QString& s)
+{
+ if (i >= 0 && i < m_nlines)
+ m_labels.at(i)->setText(s);
+}
+
+void KMWInfoBase::setText(int i, const QString& s)
+{
+ if (i >= 0 && i < m_nlines)
+ m_edits.at(i)->setText(s);
+}
+
+QString KMWInfoBase::text(int i)
+{
+ if (i >= 0 && i < m_nlines)
+ return m_edits.at(i)->text();
+ return QString::null;
+}
+
+void KMWInfoBase::setCurrent(int i)
+{
+ if (i >= 0 && i < m_nlines)
+ {
+ m_edits.at(i)->selectAll();
+ m_edits.at(i)->setFocus();
+ }
+}
+
+QLineEdit* KMWInfoBase::lineEdit( int i )
+{
+ if ( i >= 0 && i < m_nlines )
+ return m_edits.at( i );
+ else
+ return NULL;
+}
diff --git a/kdeprint/management/kmwinfobase.h b/kdeprint/management/kmwinfobase.h
new file mode 100644
index 000000000..77f9e976a
--- /dev/null
+++ b/kdeprint/management/kmwinfobase.h
@@ -0,0 +1,51 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMWINFOBASE_H
+#define KMWINFOBASE_H
+
+#include "kmwizardpage.h"
+#include <qptrlist.h>
+
+class QLabel;
+class QLineEdit;
+
+class KDEPRINT_EXPORT KMWInfoBase : public KMWizardPage
+{
+public:
+ KMWInfoBase(int n = 1, QWidget *parent = 0, const char *name = 0);
+
+ void setInfo(const QString&);
+ void setLabel(int, const QString&);
+ void setText(int, const QString&);
+ void setCurrent(int);
+
+ QString text(int);
+
+protected:
+ QLineEdit* lineEdit( int );
+
+private:
+ QPtrList<QLabel> m_labels;
+ QPtrList<QLineEdit> m_edits;
+ QLabel *m_info;
+ int m_nlines;
+};
+
+#endif
diff --git a/kdeprint/management/kmwinfopage.cpp b/kdeprint/management/kmwinfopage.cpp
new file mode 100644
index 000000000..43e830a20
--- /dev/null
+++ b/kdeprint/management/kmwinfopage.cpp
@@ -0,0 +1,48 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmwinfopage.h"
+#include "kmwizard.h"
+
+#include <qlabel.h>
+#include <qlayout.h>
+#include <klocale.h>
+#include <kactivelabel.h>
+
+KMWInfoPage::KMWInfoPage(QWidget *parent, const char *name)
+: KMWizardPage(parent,name)
+{
+ m_ID = KMWizard::Start;
+ m_title = i18n("Introduction");
+ m_nextpage = KMWizard::Backend;
+
+ //QLabel *m_label = new QLabel(this);
+ KActiveLabel *m_label = new KActiveLabel(this);
+ m_label->setText(i18n("<p>Welcome,</p><br>"
+ "<p>This wizard will help to install a new printer on your computer. "
+ "It will guide you through the various steps of the process of installing "
+ "and configuring a printer for your printing system. At each step, you "
+ "can always go back using the <b>Back</b> button.</p><br>"
+ "<p>We hope you'll enjoy this tool!</p><br>"
+ "<p align=right><a href=\"http://printing.kde.org\"><i>"
+ "The KDE printing team</i></a>.</p>"));
+
+ QVBoxLayout *main_ = new QVBoxLayout(this, 0, 0);
+ main_->addWidget(m_label);
+}
diff --git a/kdeprint/management/kmwinfopage.h b/kdeprint/management/kmwinfopage.h
new file mode 100644
index 000000000..76719e0ff
--- /dev/null
+++ b/kdeprint/management/kmwinfopage.h
@@ -0,0 +1,31 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMWINFOPAGE_H
+#define KMWINFOPAGE_H
+
+#include "kmwizardpage.h"
+
+class KMWInfoPage : public KMWizardPage
+{
+public:
+ KMWInfoPage(QWidget *parent = 0, const char *name = 0);
+};
+
+#endif
diff --git a/kdeprint/management/kmwizard.cpp b/kdeprint/management/kmwizard.cpp
new file mode 100644
index 000000000..d44ac87e8
--- /dev/null
+++ b/kdeprint/management/kmwizard.cpp
@@ -0,0 +1,262 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmwizard.h"
+#include "kmwizardpage.h"
+#include "kmprinter.h"
+#include "kmfactory.h"
+#include "kmuimanager.h"
+
+#include <kpushbutton.h>
+#include <qlabel.h>
+#include <qwidgetstack.h>
+#include <kmessagebox.h>
+#include <qlayout.h>
+#include <klocale.h>
+#include <kdebug.h>
+#include <kseparator.h>
+#include <kapplication.h>
+#include <kstdguiitem.h>
+
+#include "kmwinfopage.h"
+#include "kmwpassword.h"
+#include "kmwbackend.h"
+#include "kmwsocket.h"
+#include "kmwdriver.h"
+#include "kmwdriverselect.h"
+#include "kmwdrivertest.h"
+#include "kmwname.h"
+#include "kmwend.h"
+#include "kmwclass.h"
+#include "kmwlpd.h"
+#include "kmwfile.h"
+#include "kmwsmb.h"
+#include "kmwlocal.h"
+#include "sidepixmap.h"
+
+KMWizard::KMWizard(QWidget *parent, const char *name)
+: QDialog(parent,name,true)
+{
+ m_start = KMWizard::Start;
+ m_end = KMWizard::End;
+ m_inclusive = true;
+ m_printer = new KMPrinter();
+
+ m_pagepool.setAutoDelete(false);
+
+ m_stack = new QWidgetStack(this);
+ m_next = new KPushButton(i18n("&Next >"), this);
+ m_next->setDefault(true);
+ m_prev = new KPushButton(i18n("< &Back"), this);
+ QPushButton *m_cancel = new KPushButton(KStdGuiItem::cancel(), this);
+ m_title = new QLabel(this);
+ QFont f(m_title->font());
+ f.setBold(true);
+ m_title->setFont(f);
+ KSeparator* sep = new KSeparator( KSeparator::HLine, this);
+ sep->setFixedHeight(5);
+ KSeparator* sep2 = new KSeparator( KSeparator::HLine, this);
+ QPushButton *m_help = new KPushButton(KStdGuiItem::help(), this);
+
+ connect(m_cancel,SIGNAL(clicked()),SLOT(reject()));
+ connect(m_next,SIGNAL(clicked()),SLOT(slotNext()));
+ connect(m_prev,SIGNAL(clicked()),SLOT(slotPrev()));
+ connect(m_help, SIGNAL(clicked()), SLOT(slotHelp()));
+
+ m_side = new SidePixmap(this);
+ if (!m_side->isValid())
+ {
+ delete m_side;
+ m_side = 0;
+ }
+
+ // layout
+ QVBoxLayout *main0_ = new QVBoxLayout(this, 10, 10);
+ QVBoxLayout *main_ = new QVBoxLayout(0, 0, 0);
+ QHBoxLayout *main1_ = new QHBoxLayout(0, 0, 10);
+ QHBoxLayout *btn_ = new QHBoxLayout(0, 0, 10);
+ main0_->addLayout(main1_);
+ if (m_side)
+ main1_->addWidget(m_side);
+ main1_->addLayout(main_);
+ main_->addWidget(m_title);
+ main_->addWidget(sep);
+ main_->addSpacing(10);
+ main_->addWidget(m_stack,1);
+ main0_->addWidget(sep2);
+ main0_->addLayout(btn_);
+ btn_->addWidget(m_help);
+ btn_->addStretch(1);
+ btn_->addWidget(m_prev);
+ btn_->addWidget(m_next);
+ btn_->addWidget(m_cancel);
+
+ // create standard pages
+ addPage(new KMWInfoPage(this));
+ m_backend = new KMWBackend(this);
+ addPage(m_backend);
+ addPage(new KMWPassword(this));
+ addPage(new KMWSocket(this));
+ addPage(new KMWDriver(this));
+ addPage(new KMWDriverSelect(this));
+ addPage(new KMWDriverTest(this));
+ addPage(new KMWName(this));
+ addPage(new KMWEnd(this));
+ addPage(new KMWClass(this));
+ addPage(new KMWLpd(this));
+ addPage(new KMWFile(this));
+ addPage(new KMWSmb(this));
+ addPage(new KMWLocal(this));
+
+ // add other pages
+ KMFactory::self()->uiManager()->setupWizard(this);
+
+ setCurrentPage(m_start,false);
+ setCaption(i18n("Add Printer Wizard"));
+ resize(400,350);
+}
+
+KMWizard::~KMWizard()
+{
+ delete m_printer;
+}
+
+void KMWizard::addPage(KMWizardPage *page)
+{
+ m_stack->addWidget(page,page->id());
+ m_pagepool.insert(page->id(),page);
+}
+
+void KMWizard::setPrinter(KMPrinter *p)
+{
+ if (p)
+ {
+ m_printer->copy(*p);
+ KMWizardPage *page = (KMWizardPage*)m_stack->visibleWidget();
+ if (page)
+ page->initPrinter(m_printer);
+ }
+}
+
+void KMWizard::configure(int start, int end, bool inclusive)
+{
+ m_start = start;
+ m_end = end;
+ m_inclusive = inclusive;
+ m_pagestack.clear();
+
+ // disable class if not starting from beginning
+ m_backend->enableBackend(KMWizard::Class,(m_start == KMWizard::Start));
+ setCaption((m_start == KMWizard::Start ? i18n("Add Printer Wizard") : i18n("Modify Printer")));
+
+ if (m_side)
+ {
+ if (start == KMWizard::Start && end == KMWizard::End)
+ m_side->show();
+ else
+ m_side->hide();
+ }
+
+ setCurrentPage(m_start,false);
+}
+
+void KMWizard::setNextPage(int page, int next)
+{
+ KMWizardPage *p = m_pagepool.find(page);
+ if (p)
+ p->setNextPage(next);
+}
+
+void KMWizard::setCurrentPage(int ID, bool back)
+{
+ KMWizardPage *page = m_pagepool.find(ID);
+ if (!page)
+ {
+ KMessageBox::error(this,i18n("Unable to find the requested page."),i18n("Add Printer Wizard"));
+ return;
+ }
+
+ // add current page to stack (only if going backward)
+ if (!back) m_pagestack.push(ID);
+
+ // raise page + initialize
+ m_stack->raiseWidget(page);
+ m_title->setText(page->title());
+ if (!back || page->needsInitOnBack()) page->initPrinter(m_printer);
+
+ // update buttons
+ if (ID == m_start) m_prev->setEnabled(false);
+ else m_prev->setEnabled(true);
+ if ((m_inclusive && ID == m_end) || (!m_inclusive && page->nextPage() == m_end))
+ m_next->setText(i18n("&Finish"));
+ else
+ m_next->setText(i18n("&Next >"));
+}
+
+void KMWizard::slotPrev()
+{
+ // current page is on top of stack -> pop it and retrieve new top of stack
+ m_pagestack.pop();
+ int ID = m_pagestack.top();
+ setCurrentPage(ID,true);
+}
+
+void KMWizard::slotNext()
+{
+ KMWizardPage *page = (KMWizardPage*)m_stack->visibleWidget();
+ if (page)
+ {
+ QString msg;
+ if (!page->isValid(msg))
+ {
+ if (!msg.isEmpty())
+ KMessageBox::error(this,msg.prepend("<qt>").append("</qt>"),page->title());
+ }
+ else
+ {
+ page->updatePrinter(m_printer);
+ if (m_next->text() == i18n("&Finish"))
+ accept();
+ else
+ {
+ int ID = page->nextPage();
+ setCurrentPage(ID,false);
+ }
+ }
+ }
+}
+
+void KMWizard::slotHelp()
+{
+ kapp->invokeHelp(QString::null, "kdeprint");
+}
+
+void KMWizard::enableWizard()
+{
+ m_next->setEnabled( true );
+ m_prev->setEnabled( m_pagestack.top() != m_start );
+}
+
+void KMWizard::disableWizard()
+{
+ m_next->setEnabled( false );
+ m_prev->setEnabled( false );
+}
+
+#include "kmwizard.moc"
diff --git a/kdeprint/management/kmwizard.h b/kdeprint/management/kmwizard.h
new file mode 100644
index 000000000..4a52628fb
--- /dev/null
+++ b/kdeprint/management/kmwizard.h
@@ -0,0 +1,101 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMWIZARD_H
+#define KMWIZARD_H
+
+#include <qdialog.h>
+#include <qintdict.h>
+#include <qvaluestack.h>
+
+#include <kdelibs_export.h>
+
+class QWidgetStack;
+class QLabel;
+class QPushButton;
+class KMWizardPage;
+class KMPrinter;
+class KMWBackend;
+class SidePixmap;
+
+class KDEPRINT_EXPORT KMWizard : public QDialog
+{
+ Q_OBJECT
+public:
+ enum PageType {
+ Start = 0,
+ End,
+ Error,
+ Backend,
+ Driver,
+ File,
+ SMB,
+ TCP,
+ Local,
+ LPD,
+ IPP,
+ IPPSelect,
+ Class,
+ Password,
+ DriverTest,
+ DriverSelect,
+ Name,
+ Banners,
+ Custom = 100
+ };
+
+ KMWizard(QWidget *parent = 0, const char *name = 0);
+ ~KMWizard();
+
+ void configure(int start, int end, bool inclusive = true);
+ void setCurrentPage(int ID, bool back = false);
+ void setPrinter(KMPrinter*);
+ KMPrinter* printer() { return m_printer; }
+ void addPage(KMWizardPage*);
+ KMWBackend* backendPage() { return m_backend; }
+ void setNextPage(int page, int next);
+
+public slots:
+ void enableWizard();
+ void disableWizard();
+
+protected slots:
+ void slotNext();
+ void slotPrev();
+ void slotHelp();
+
+private:
+ QIntDict<KMWizardPage> m_pagepool;
+ QValueStack<int> m_pagestack;
+
+ QWidgetStack *m_stack;
+ QLabel *m_title;
+ QPushButton *m_next, *m_prev;
+ int m_start, m_end;
+ bool m_inclusive;
+ KMPrinter *m_printer;
+
+ // backend page
+ KMWBackend *m_backend;
+
+ // side pixmap
+ SidePixmap *m_side;
+};
+
+#endif
diff --git a/kdeprint/management/kmwizardpage.cpp b/kdeprint/management/kmwizardpage.cpp
new file mode 100644
index 000000000..fe872161e
--- /dev/null
+++ b/kdeprint/management/kmwizardpage.cpp
@@ -0,0 +1,48 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmwizardpage.h"
+#include "kmwizard.h"
+
+KMWizardPage::KMWizardPage(QWidget *parent, const char *name)
+: QWidget(parent,name)
+{
+ m_ID = KMWizard::Error;
+ m_title = "KMWizardPage";
+ m_nextpage = KMWizard::Error;
+ m_needsinitonback = false;
+}
+
+KMWizardPage::~KMWizardPage()
+{
+}
+
+bool KMWizardPage::isValid(QString&)
+{
+ return true;
+}
+
+void KMWizardPage::initPrinter(KMPrinter*)
+{
+}
+
+void KMWizardPage::updatePrinter(KMPrinter*)
+{
+}
+#include "kmwizardpage.moc"
diff --git a/kdeprint/management/kmwizardpage.h b/kdeprint/management/kmwizardpage.h
new file mode 100644
index 000000000..d0846b57f
--- /dev/null
+++ b/kdeprint/management/kmwizardpage.h
@@ -0,0 +1,52 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMWIZARDPAGE_H
+#define KMWIZARDPAGE_H
+
+#include <qwidget.h>
+
+#include <kdelibs_export.h>
+
+class KMPrinter;
+
+class KDEPRINT_EXPORT KMWizardPage : public QWidget
+{
+ Q_OBJECT
+public:
+ KMWizardPage(QWidget *parent = 0, const char *name = 0);
+ virtual ~KMWizardPage();
+
+ int id() const { return m_ID; }
+ const QString& title() const { return m_title; }
+ int nextPage() const { return m_nextpage; }
+ void setNextPage(int p) { m_nextpage = p; }
+ virtual bool isValid(QString&);
+ virtual void initPrinter(KMPrinter*);
+ virtual void updatePrinter(KMPrinter*);
+ bool needsInitOnBack() { return m_needsinitonback; }
+
+protected:
+ QString m_title;
+ int m_ID;
+ int m_nextpage;
+ bool m_needsinitonback;
+};
+
+#endif
diff --git a/kdeprint/management/kmwlocal.cpp b/kdeprint/management/kmwlocal.cpp
new file mode 100644
index 000000000..10657f246
--- /dev/null
+++ b/kdeprint/management/kmwlocal.cpp
@@ -0,0 +1,206 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmwlocal.h"
+#include "kmwizard.h"
+#include "kmprinter.h"
+#include "kmfactory.h"
+#include "kmmanager.h"
+
+#include <klocale.h>
+#include <qlayout.h>
+#include <qlineedit.h>
+#include <qlabel.h>
+#include <qheader.h>
+#include <klistview.h>
+#include <kmessagebox.h>
+#include <kiconloader.h>
+
+KMWLocal::KMWLocal(QWidget *parent, const char *name)
+: KMWizardPage(parent,name)
+{
+ m_title = i18n("Local Port Selection");
+ m_ID = KMWizard::Local;
+ m_nextpage = KMWizard::Driver;
+ m_initialized = false;
+ m_block = false;
+
+ m_ports = new KListView(this);
+ m_ports->setFrameStyle(QFrame::WinPanel|QFrame::Sunken);
+ m_ports->setLineWidth(1);
+ m_ports->header()->hide();
+ m_ports->addColumn("");
+ m_ports->setSorting(-1);
+ QListViewItem *root = new QListViewItem(m_ports, i18n("Local System"));
+ root->setPixmap(0, SmallIcon("kdeprint_computer"));
+ root->setOpen(true);
+ connect(m_ports, SIGNAL(selectionChanged(QListViewItem*)), SLOT(slotPortSelected(QListViewItem*)));
+ QLabel *l1 = new QLabel(i18n("URI:"), this);
+ m_localuri = new QLineEdit(this);
+ connect( m_localuri, SIGNAL( textChanged( const QString& ) ), SLOT( slotTextChanged( const QString& ) ) );
+ m_parents[0] = new QListViewItem(root, i18n("Parallel"));
+ m_parents[1] = new QListViewItem(root, m_parents[0], i18n("Serial"));
+ m_parents[2] = new QListViewItem(root, m_parents[1], i18n("USB"));
+ m_parents[3] = new QListViewItem(root, m_parents[2], i18n("Others"));
+ for (int i=0;i<4;i++)
+ m_parents[i]->setPixmap(0, SmallIcon("input_devices_settings"));
+ QLabel *l2 = new QLabel(i18n("<p>Select a valid detected port, or enter directly the corresponding URI in the bottom edit field.</p>"), this);
+
+ QVBoxLayout *lay0 = new QVBoxLayout(this, 0, 10);
+ QHBoxLayout *lay1 = new QHBoxLayout(0, 0, 10);
+ lay0->addWidget(l2, 0);
+ lay0->addWidget(m_ports, 1);
+ lay0->addLayout(lay1, 0);
+ lay1->addWidget(l1, 0);
+ lay1->addWidget(m_localuri, 1);
+}
+
+bool KMWLocal::isValid(QString& msg)
+{
+ if (m_localuri->text().isEmpty())
+ {
+ msg = i18n("The URI is empty","Empty URI.");
+ return false;
+ }
+ else if (m_uris.findIndex(m_localuri->text()) == -1)
+ {
+ if (KMessageBox::warningContinueCancel(this, i18n("The local URI doesn't correspond to a detected port. Continue?")) == KMessageBox::Cancel)
+ {
+ msg = i18n("Select a valid port.");
+ return false;
+ }
+ }
+ return true;
+}
+
+void KMWLocal::slotPortSelected(QListViewItem *item)
+{
+ if ( m_block )
+ return;
+
+ QString uri;
+ if (!item || item->depth() <= 1 || item->depth() > 3)
+ uri = QString::null;
+ else if (item->depth() == 3)
+ uri = item->parent()->text( 1 );
+ else
+ uri = item->text( 1 );
+ m_block = true;
+ m_localuri->setText( uri );
+ m_block = false;
+}
+
+void KMWLocal::updatePrinter(KMPrinter *printer)
+{
+ QListViewItem *item = m_ports->selectedItem();
+ if ( item && item->depth() == 3 )
+ printer->setOption( "kde-autodetect", item->text( 0 ) );
+ printer->setDevice(m_localuri->text());
+}
+
+void KMWLocal::initPrinter(KMPrinter *printer)
+{
+ if (!m_initialized)
+ initialize();
+
+ if (printer)
+ {
+ m_localuri->setText(printer->device());
+ }
+}
+
+QListViewItem* KMWLocal::lookForItem( const QString& uri )
+{
+ for ( int i=0; i<4; i++ )
+ {
+ QListViewItem *item = m_parents[ i ]->firstChild();
+ while ( item )
+ if ( item->text( 1 ) == uri )
+ if ( item->firstChild() )
+ return item->firstChild();
+ else
+ return item;
+ else
+ item = item->nextSibling();
+ }
+ return 0;
+}
+
+void KMWLocal::slotTextChanged( const QString& txt )
+{
+ if ( m_block )
+ return;
+
+ QListViewItem *item = lookForItem( txt );
+ if ( item )
+ {
+ m_block = true;
+ m_ports->setSelected( item, true );
+ m_block = false;
+ }
+ else
+ m_ports->clearSelection();
+}
+
+void KMWLocal::initialize()
+{
+ QStringList list = KMFactory::self()->manager()->detectLocalPrinters();
+ if (list.isEmpty() || (list.count() % 4) != 0)
+ {
+ KMessageBox::error(this, i18n("Unable to detect local ports."));
+ return;
+ }
+ QListViewItem *last[4] = {0, 0, 0, 0};
+ for (QStringList::Iterator it=list.begin(); it!=list.end(); ++it)
+ {
+ QString cl = *it;
+ ++it;
+
+ QString uri = *it;
+ int p = uri.find( ':' );
+ QString desc = *(++it), prot = ( p != -1 ? uri.left( p ) : QString::null );
+ QString printer = *(++it);
+ int index(-1);
+ if (desc.isEmpty())
+ desc = uri;
+ if (prot == "parallel" || prot == "file")
+ index = 0;
+ else if (prot == "serial")
+ index = 1;
+ else if (prot == "usb")
+ index = 2;
+ else if (cl == "direct")
+ index = 3;
+ else
+ continue;
+ last[index] = new QListViewItem(m_parents[index], last[index], desc, uri);
+ last[index]->setPixmap(0, SmallIcon("blockdevice"));
+ m_parents[index]->setOpen(true);
+ m_uris << uri;
+ if (!printer.isEmpty())
+ {
+ QListViewItem *pItem = new QListViewItem(last[index], printer);
+ last[index]->setOpen(true);
+ pItem->setPixmap(0, SmallIcon("kdeprint_printer"));
+ }
+ }
+ m_initialized = true;
+}
+
+#include "kmwlocal.moc"
diff --git a/kdeprint/management/kmwlocal.h b/kdeprint/management/kmwlocal.h
new file mode 100644
index 000000000..5f99c32e0
--- /dev/null
+++ b/kdeprint/management/kmwlocal.h
@@ -0,0 +1,58 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMWLOCAL_H
+#define KMWLOCAL_H
+
+#include "kmwizardpage.h"
+
+#include <qstringlist.h>
+
+class QLineEdit;
+class KListView;
+class QListViewItem;
+
+class KMWLocal : public KMWizardPage
+{
+ Q_OBJECT
+public:
+ KMWLocal(QWidget *parent = 0, const char *name = 0);
+
+ bool isValid(QString&);
+ void updatePrinter(KMPrinter*);
+ void initPrinter(KMPrinter*);
+
+protected slots:
+ void slotPortSelected(QListViewItem*);
+ void slotTextChanged( const QString& );
+
+protected:
+ void initialize();
+ QListViewItem* lookForItem( const QString& );
+
+protected:
+ KListView *m_ports;
+ QLineEdit *m_localuri;
+ QStringList m_uris;
+ QListViewItem *m_parents[4];
+ bool m_initialized;
+ bool m_block;
+};
+
+#endif
diff --git a/kdeprint/management/kmwlpd.cpp b/kdeprint/management/kmwlpd.cpp
new file mode 100644
index 000000000..fdb762e7d
--- /dev/null
+++ b/kdeprint/management/kmwlpd.cpp
@@ -0,0 +1,102 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include <config.h>
+#include "kmwlpd.h"
+#include "kmwizard.h"
+#include "kmprinter.h"
+
+#include <kurl.h>
+#include <klocale.h>
+#include <qlabel.h>
+#include <kdebug.h>
+#include <qlineedit.h>
+#include <kmessagebox.h>
+#include <kextsock.h>
+
+static bool checkLpdQueue(const char *host, const char *queue);
+
+//********************************************************************************************************
+
+KMWLpd::KMWLpd(QWidget *parent, const char *name)
+: KMWInfoBase(2,parent,name)
+{
+ m_ID = KMWizard::LPD;
+ m_title = i18n("LPD Queue Information");
+ m_nextpage = KMWizard::Driver;
+
+ setInfo(i18n("<p>Enter the information concerning the remote LPD queue; "
+ "this wizard will check it before continuing.</p>"));
+ setLabel(0,i18n("Host:"));
+ setLabel(1,i18n("Queue:"));
+}
+
+bool KMWLpd::isValid(QString& msg)
+{
+ if (text(0).isEmpty() || text(1).isEmpty())
+ {
+ msg = i18n("Some information is missing.");
+ return false;
+ }
+
+ // check LPD queue
+ if (!checkLpdQueue(text(0).latin1(),text(1).latin1()))
+ {
+ if (KMessageBox::warningContinueCancel(this, i18n("Cannot find queue %1 on server %2; do you want to continue anyway?").arg(text(1)).arg(text(0))) == KMessageBox::Cancel)
+ return false;
+ }
+ return true;
+}
+
+void KMWLpd::updatePrinter(KMPrinter *p)
+{
+ QString dev = QString::fromLatin1("lpd://%1/%2").arg(text(0)).arg(text(1));
+ p->setDevice(dev);
+}
+
+//*******************************************************************************************************
+
+bool checkLpdQueue(const char *host, const char *queue)
+{
+ KExtendedSocket sock(host, "printer", KExtendedSocket::streamSocket);
+ sock.setBlockingMode(true);
+ if (sock.connect() != 0)
+ return false;
+
+ char res[64] = {0};
+ snprintf(res,64,"%c%s\n",(char)4,queue);
+ if (sock.writeBlock(res, strlen(res)) != (Q_LONG)(strlen(res)))
+ return false;
+
+ char buf[1024] = {0};
+ int n, tot(1);
+ while ((n = sock.readBlock(res, 63)) > 0)
+ {
+ res[n] = 0;
+ tot += n;
+ if (tot >= 1024)
+ break;
+ else
+ strcat(buf, res);
+ }
+ sock.close();
+ if (strlen(buf) == 0 || strstr(buf, "unknown printer") != NULL)
+ return false;
+ return true;
+}
diff --git a/kdeprint/management/kmwlpd.h b/kdeprint/management/kmwlpd.h
new file mode 100644
index 000000000..bd4b636f8
--- /dev/null
+++ b/kdeprint/management/kmwlpd.h
@@ -0,0 +1,34 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMWLPD_H
+#define KMWLPD_H
+
+#include "kmwinfobase.h"
+
+class KMWLpd : public KMWInfoBase
+{
+public:
+ KMWLpd(QWidget *parent = 0, const char *name = 0);
+
+ bool isValid(QString&);
+ void updatePrinter(KMPrinter*);
+};
+
+#endif
diff --git a/kdeprint/management/kmwname.cpp b/kdeprint/management/kmwname.cpp
new file mode 100644
index 000000000..0cfbfbea9
--- /dev/null
+++ b/kdeprint/management/kmwname.cpp
@@ -0,0 +1,96 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmwname.h"
+#include "kmwizard.h"
+#include "kmprinter.h"
+
+#include <qlabel.h>
+#include <qlineedit.h>
+#include <klocale.h>
+#include <kmessagebox.h>
+#include <qregexp.h>
+
+KMWName::KMWName(QWidget *parent, const char *name)
+: KMWInfoBase(3,parent,name)
+{
+ m_ID = KMWizard::Name;
+ m_title = i18n("General Information");
+ m_nextpage = KMWizard::End;
+
+ setInfo(i18n("<p>Enter the information concerning your printer or class. <b>Name</b> is mandatory, "
+ "<b>Location</b> and <b>Description</b> are not (they may even not be used on some systems).</p>"));
+ setLabel(0,i18n("Name:"));
+ setLabel(1,i18n("Location:"));
+ setLabel(2,i18n("Description:"));
+}
+
+bool KMWName::isValid(QString& msg)
+{
+ if (text(0).isEmpty())
+ {
+ msg = i18n("You must supply at least a name.");
+ return false;
+ }
+ else if (text(0).find(QRegExp("\\s")) != -1)
+ {
+ QString conv = text(0);
+ conv.replace(QRegExp("\\s"), "");
+ int result = KMessageBox::warningYesNoCancel(this,
+ i18n("It is usually not a good idea to include spaces "
+ "in printer name: it may prevent your printer from "
+ "working correctly. The wizard can strip all spaces "
+ "from the string you entered, resulting in %1; "
+ "what do you want to do?").arg(conv),
+ QString::null,
+ i18n("Strip"), i18n("Keep"));
+ switch (result)
+ {
+ case KMessageBox::Yes:
+ setText(0, conv);
+ case KMessageBox::No:
+ return true;
+ default:
+ return false;
+ }
+ }
+ return true;
+}
+
+void KMWName::initPrinter(KMPrinter *p)
+{
+ setText(0,p->printerName());
+ setText(1,p->location());
+ setText(2,p->description());
+ if (text(2).isEmpty())
+ if (p->option("kde-driver") == "raw")
+ setText(2,i18n("Raw printer"));
+ else
+ setText(2,p->manufacturer() + " " + p->model());
+
+ setCurrent(0);
+}
+
+void KMWName::updatePrinter(KMPrinter *p)
+{
+ p->setPrinterName(text(0));
+ p->setName(text(0));
+ p->setLocation(text(1));
+ p->setDescription(text(2));
+}
diff --git a/kdeprint/management/kmwname.h b/kdeprint/management/kmwname.h
new file mode 100644
index 000000000..245b2c985
--- /dev/null
+++ b/kdeprint/management/kmwname.h
@@ -0,0 +1,35 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMWNAME_H
+#define KMWNAME_H
+
+#include "kmwinfobase.h"
+
+class KMWName : public KMWInfoBase
+{
+public:
+ KMWName(QWidget *parent = 0, const char *name = 0);
+
+ bool isValid(QString&);
+ void initPrinter(KMPrinter*);
+ void updatePrinter(KMPrinter*);
+};
+
+#endif
diff --git a/kdeprint/management/kmwpassword.cpp b/kdeprint/management/kmwpassword.cpp
new file mode 100644
index 000000000..1b67ac6be
--- /dev/null
+++ b/kdeprint/management/kmwpassword.cpp
@@ -0,0 +1,133 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmwpassword.h"
+#include "kmwizard.h"
+#include "kmprinter.h"
+
+#include <qlabel.h>
+#include <qlineedit.h>
+#include <qvbuttongroup.h>
+#include <qradiobutton.h>
+#include <qlayout.h>
+#include <klocale.h>
+#include <kcursor.h>
+
+#include <stdlib.h>
+
+KMWPassword::KMWPassword(QWidget *parent, const char *name)
+: KMWizardPage(parent,name)
+{
+ m_title = i18n("User Identification");
+ m_ID = KMWizard::Password;
+ m_nextpage = KMWizard::SMB;
+
+ // create widgets
+ QLabel *infotext_ = new QLabel(this);
+ infotext_->setText(i18n("<p>This backend may require a login/password to work properly. "
+ "Select the type of access to use and fill in the login and password entries if needed.</p>"));
+ m_login = new QLineEdit(this);
+ m_login->setText(QString::fromLocal8Bit(getenv("USER")));
+ m_password = new QLineEdit(this);
+ m_password->setEchoMode(QLineEdit::Password);
+ QLabel *loginlabel_ = new QLabel(i18n("&Login:"),this);
+ QLabel *passwdlabel_ = new QLabel(i18n("&Password:"),this);
+ m_btngroup = new QVButtonGroup( this );
+ m_btngroup->setFrameStyle( QFrame::NoFrame );
+ QRadioButton *btn1 = new QRadioButton( i18n( "&Anonymous (no login/password)" ), m_btngroup );
+ QRadioButton *btn2 = new QRadioButton( i18n( "&Guest account (login=\"guest\")" ), m_btngroup );
+ QRadioButton *btn3 = new QRadioButton( i18n( "Nor&mal account" ), m_btngroup );
+ btn1->setCursor( KCursor::handCursor() );
+ btn2->setCursor( KCursor::handCursor() );
+ btn3->setCursor( KCursor::handCursor() );
+ m_btngroup->setButton( 0 );
+
+ loginlabel_->setBuddy(m_login);
+ passwdlabel_->setBuddy(m_password);
+
+ m_login->setEnabled(false);
+ m_password->setEnabled(false);
+ connect(btn3,SIGNAL(toggled(bool)),m_login,SLOT(setEnabled(bool)));
+ connect(btn3,SIGNAL(toggled(bool)),m_password,SLOT(setEnabled(bool)));
+
+ // layout
+ QVBoxLayout *main_ = new QVBoxLayout( this, 0, 0 );
+ main_->addWidget( infotext_ );
+ main_->addSpacing( 10 );
+ main_->addWidget( m_btngroup );
+ QGridLayout *l1 = new QGridLayout( 0, 2, 3 );
+ main_->addLayout( l1 );
+ main_->addStretch( 1 );
+ l1->setColSpacing( 0, 35 );
+ l1->setColStretch( 2, 1 );
+ l1->addWidget( loginlabel_, 0, 1 );
+ l1->addWidget( passwdlabel_, 1, 1 );
+ l1->addWidget( m_login, 0, 2 );
+ l1->addWidget( m_password, 1, 2 );
+}
+
+bool KMWPassword::isValid(QString& msg)
+{
+ if ( !m_btngroup->selected() )
+ msg = i18n( "Select one option" );
+ else if (m_btngroup->selectedId() == 2 && m_login->text().isEmpty())
+ msg = i18n("User name is empty.");
+ else
+ return true;
+ return false;
+}
+
+void KMWPassword::initPrinter( KMPrinter* p )
+{
+ /* guest account only for SMB backend */
+ if ( p->option( "kde-backend" ).toInt() != KMWizard::SMB )
+ {
+ int ID = m_btngroup->selectedId();
+ m_btngroup->find( 1 )->hide();
+ if ( ID == 1 )
+ m_btngroup->setButton( 0 );
+ }
+ else
+ m_btngroup->find( 1 )->show();
+}
+
+void KMWPassword::updatePrinter(KMPrinter *p)
+{
+ QString s = p->option("kde-backend");
+ if (!s.isEmpty())
+ setNextPage(s.toInt());
+ else
+ setNextPage(KMWizard::Error);
+ switch ( m_btngroup->selectedId() )
+ {
+ case 0:
+ p->setOption( "kde-login", QString::null );
+ p->setOption( "kde-password", QString::null );
+ break;
+ case 1:
+ p->setOption( "kde-login", QString::fromLatin1( "guest" ) );
+ p->setOption( "kde-password", QString::null );
+ break;
+ case 2:
+ p->setOption( "kde-login", m_login->text() );
+ p->setOption( "kde-password", m_password->text() );
+ break;
+ }
+}
+
diff --git a/kdeprint/management/kmwpassword.h b/kdeprint/management/kmwpassword.h
new file mode 100644
index 000000000..9941376f6
--- /dev/null
+++ b/kdeprint/management/kmwpassword.h
@@ -0,0 +1,43 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMWPASSWORD_H
+#define KMWPASSWORD_H
+
+#include "kmwizardpage.h"
+
+class QLineEdit;
+class QButtonGroup;
+
+class KMWPassword : public KMWizardPage
+{
+public:
+ KMWPassword(QWidget *parent = 0, const char *name = 0);
+
+ bool isValid(QString&);
+ void initPrinter( KMPrinter* );
+ void updatePrinter(KMPrinter*);
+
+private:
+ QLineEdit *m_login;
+ QLineEdit *m_password;
+ QButtonGroup *m_btngroup;
+};
+
+#endif
diff --git a/kdeprint/management/kmwsmb.cpp b/kdeprint/management/kmwsmb.cpp
new file mode 100644
index 000000000..bd1372c42
--- /dev/null
+++ b/kdeprint/management/kmwsmb.cpp
@@ -0,0 +1,119 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmwsmb.h"
+#include "kmwizard.h"
+#include "smbview.h"
+#include "kmprinter.h"
+#include "util.h"
+
+#include <klocale.h>
+#include <kpushbutton.h>
+#include <qlayout.h>
+#include <qlineedit.h>
+#include <qlabel.h>
+
+KMWSmb::KMWSmb(QWidget *parent, const char *name)
+: KMWizardPage(parent,name)
+{
+ m_title = i18n("SMB Printer Settings");
+ m_ID = KMWizard::SMB;
+ m_nextpage = KMWizard::Driver;
+
+ m_view = new SmbView(this,"SmbView");
+ m_loginlabel = new QLabel( this );
+ QPushButton *m_scan = new KPushButton(KGuiItem(i18n("Scan"), "viewmag"), this);
+ QPushButton *m_abort = new KPushButton(KGuiItem(i18n("Abort"), "stop"), this);
+ m_abort->setEnabled(false);
+ QLabel *m_worklabel = new QLabel(i18n("Workgroup:"), this);
+ QLabel *m_serverlabel = new QLabel(i18n("Server:"), this);
+ QLabel *m_printerlabel = new QLabel(i18n("Printer:"), this);
+ m_work = new QLineEdit(this);
+ m_server = new QLineEdit(this);
+ m_printer = new QLineEdit(this);
+
+ QVBoxLayout *lay0 = new QVBoxLayout(this, 0, 10);
+ QGridLayout *lay1 = new QGridLayout(0, 3, 2, 0, 10);
+ QHBoxLayout *lay3 = new QHBoxLayout(0, 0, 10);
+ lay0->addLayout(lay1,0);
+ lay0->addWidget(m_view,1);
+ lay0->addLayout(lay3,0);
+ lay0->addSpacing(10);
+ lay1->setColStretch(1,1);
+ lay1->addWidget(m_worklabel,0,0);
+ lay1->addWidget(m_serverlabel,1,0);
+ lay1->addWidget(m_printerlabel,2,0);
+ lay1->addWidget(m_work,0,1);
+ lay1->addWidget(m_server,1,1);
+ lay1->addWidget(m_printer,2,1);
+ lay3->addWidget( m_loginlabel );
+ lay3->addStretch(1);
+ lay3->addWidget(m_scan);
+ lay3->addWidget(m_abort);
+
+ connect(m_scan,SIGNAL(clicked()),SLOT(slotScan()));
+ connect(m_abort,SIGNAL(clicked()),SLOT(slotAbort()));
+ connect(m_view,SIGNAL(printerSelected(const QString&,const QString&,const QString&)),SLOT(slotPrinterSelected(const QString&,const QString&,const QString&)));
+ connect(m_view,SIGNAL(running(bool)),m_abort,SLOT(setEnabled(bool)));
+}
+
+bool KMWSmb::isValid(QString& msg)
+{
+ if (m_server->text().isEmpty())
+ msg = i18n("Empty server name.");
+ else if (m_printer->text().isEmpty())
+ msg = i18n("Empty printer name.");
+ else
+ return true;
+ return false;
+}
+
+void KMWSmb::updatePrinter(KMPrinter *printer)
+{
+ QString uri = buildSmbURI( m_work->text(), m_server->text(), m_printer->text(), printer->option( "kde-login" ), printer->option( "kde-password" ) );
+ printer->setDevice( uri );
+}
+
+void KMWSmb::initPrinter(KMPrinter *printer)
+{
+ if (printer)
+ {
+ QString login = printer->option( "kde-login" );
+ m_view->setLoginInfos(login,printer->option("kde-password"));
+ m_loginlabel->setText( i18n( "Login: %1" ).arg( login.isEmpty() ? i18n( "<anonymous>" ) : login ) );
+ }
+}
+
+void KMWSmb::slotScan()
+{
+ m_view->init();
+}
+
+void KMWSmb::slotAbort()
+{
+ m_view->abort();
+}
+
+void KMWSmb::slotPrinterSelected(const QString& work, const QString& server, const QString& printer)
+{
+ m_work->setText(work);
+ m_server->setText(server);
+ m_printer->setText(printer);
+}
+#include "kmwsmb.moc"
diff --git a/kdeprint/management/kmwsmb.h b/kdeprint/management/kmwsmb.h
new file mode 100644
index 000000000..e76668f74
--- /dev/null
+++ b/kdeprint/management/kmwsmb.h
@@ -0,0 +1,50 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMWSMB_H
+#define KMWSMB_H
+
+#include "kmwizardpage.h"
+
+class SmbView;
+class QLineEdit;
+class QLabel;
+
+class KMWSmb : public KMWizardPage
+{
+ Q_OBJECT
+public:
+ KMWSmb(QWidget *parent = 0, const char *name = 0);
+
+ bool isValid(QString&);
+ void updatePrinter(KMPrinter*);
+ void initPrinter(KMPrinter*);
+
+protected slots:
+ void slotScan();
+ void slotAbort();
+ void slotPrinterSelected(const QString& work, const QString& server, const QString& printer);
+
+protected:
+ SmbView *m_view;
+ QLineEdit *m_work, *m_server, *m_printer;
+ QLabel *m_loginlabel;
+};
+
+#endif
diff --git a/kdeprint/management/kmwsocket.cpp b/kdeprint/management/kmwsocket.cpp
new file mode 100644
index 000000000..9c44aef25
--- /dev/null
+++ b/kdeprint/management/kmwsocket.cpp
@@ -0,0 +1,150 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmwsocket.h"
+#include "networkscanner.h"
+#include "kmwizard.h"
+#include "kmprinter.h"
+
+#include <klistview.h>
+#include <qheader.h>
+#include <qlineedit.h>
+#include <qlabel.h>
+#include <kmessagebox.h>
+#include <qlayout.h>
+#include <klocale.h>
+#include <kiconloader.h>
+#include <kseparator.h>
+
+KMWSocket::KMWSocket(QWidget *parent, const char *name)
+: KMWizardPage(parent,name)
+{
+ m_title = i18n("Network Printer Information");
+ m_ID = KMWizard::TCP;
+ m_nextpage = KMWizard::Driver;
+
+ m_list = new KListView(this);
+ m_list->addColumn("");
+ m_list->header()->hide();
+ m_list->setFrameStyle(QFrame::WinPanel|QFrame::Sunken);
+ m_list->setLineWidth(1);
+
+ QLabel *l1 = new QLabel(i18n("&Printer address:"),this);
+ QLabel *l2 = new QLabel(i18n("P&ort:"),this);
+
+ m_printer = new QLineEdit(this);
+ m_port = new QLineEdit(this);
+
+ l1->setBuddy(m_printer);
+ l2->setBuddy(m_port);
+
+ m_scanner = new NetworkScanner( 9100, this );
+
+ KSeparator* sep = new KSeparator( KSeparator::HLine, this);
+ sep->setFixedHeight(40);
+
+ connect(m_list,SIGNAL(selectionChanged(QListViewItem*)),SLOT(slotPrinterSelected(QListViewItem*)));
+ connect( m_scanner, SIGNAL( scanStarted() ), SLOT( slotScanStarted() ) );
+ connect( m_scanner, SIGNAL( scanFinished() ), SLOT( slotScanFinished() ) );
+ connect( m_scanner, SIGNAL( scanStarted() ), parent, SLOT( disableWizard() ) );
+ connect( m_scanner, SIGNAL( scanFinished() ), parent, SLOT( enableWizard() ) );
+
+ // layout
+ QHBoxLayout *lay3 = new QHBoxLayout(this, 0, 10);
+ QVBoxLayout *lay2 = new QVBoxLayout(0, 0, 0);
+
+ lay3->addWidget(m_list,1);
+ lay3->addLayout(lay2,1);
+ lay2->addWidget(l1);
+ lay2->addWidget(m_printer);
+ lay2->addSpacing(10);
+ lay2->addWidget(l2);
+ lay2->addWidget(m_port);
+ lay2->addWidget(sep);
+ lay2->addWidget( m_scanner );
+ lay2->addStretch(1);
+}
+
+KMWSocket::~KMWSocket()
+{
+}
+
+void KMWSocket::updatePrinter(KMPrinter *p)
+{
+ QString dev = QString::fromLatin1("socket://%1:%2").arg(m_printer->text()).arg(m_port->text());
+ p->setDevice(dev);
+}
+
+bool KMWSocket::isValid(QString& msg)
+{
+ if (m_printer->text().isEmpty())
+ {
+ msg = i18n("You must enter a printer address.");
+ return false;
+ }
+ QString port(m_port->text());
+ int p(9100);
+ if (!port.isEmpty())
+ {
+ bool ok;
+ p = port.toInt(&ok);
+ if (!ok)
+ {
+ msg = i18n("Wrong port number.");
+ return false;
+ }
+ }
+
+ if (!m_scanner->checkPrinter(m_printer->text(),p))
+ {
+ msg = i18n("No printer found at this address/port.");
+ return false;
+ }
+ return true;
+}
+
+void KMWSocket::slotScanStarted()
+{
+ m_list->clear();
+}
+
+void KMWSocket::slotScanFinished()
+{
+ const QPtrList<NetworkScanner::SocketInfo> *list = m_scanner->printerList();
+ QPtrListIterator<NetworkScanner::SocketInfo> it(*list);
+ for (;it.current();++it)
+ {
+ QString name;
+ if (it.current()->Name.isEmpty())
+ name = i18n("Unknown host - 1 is the IP", "<Unknown> (%1)").arg(it.current()->IP);
+ else
+ name = it.current()->Name;
+ QListViewItem *item = new QListViewItem(m_list,name,it.current()->IP,QString::number(it.current()->Port));
+ item->setPixmap(0,SmallIcon("kdeprint_printer"));
+ }
+}
+
+void KMWSocket::slotPrinterSelected(QListViewItem *item)
+{
+ if (!item) return;
+ m_printer->setText(item->text(1));
+ m_port->setText(item->text(2));
+}
+
+#include "kmwsocket.moc"
diff --git a/kdeprint/management/kmwsocket.h b/kdeprint/management/kmwsocket.h
new file mode 100644
index 000000000..f7aeb7157
--- /dev/null
+++ b/kdeprint/management/kmwsocket.h
@@ -0,0 +1,51 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMWSOCKET_H
+#define KMWSOCKET_H
+
+#include "kmwizardpage.h"
+
+class KListView;
+class QListViewItem;
+class QLineEdit;
+class NetworkScanner;
+
+class KMWSocket : public KMWizardPage
+{
+ Q_OBJECT
+public:
+ KMWSocket(QWidget *parent = 0, const char *name = 0);
+ ~KMWSocket();
+
+ bool isValid(QString&);
+ void updatePrinter(KMPrinter*);
+
+protected slots:
+ void slotPrinterSelected(QListViewItem*);
+ void slotScanStarted();
+ void slotScanFinished();
+
+private:
+ KListView *m_list;
+ NetworkScanner *m_scanner;
+ QLineEdit *m_printer, *m_port;
+};
+
+#endif
diff --git a/kdeprint/management/kmwsocketutil.cpp b/kdeprint/management/kmwsocketutil.cpp
new file mode 100644
index 000000000..f0a6b3bba
--- /dev/null
+++ b/kdeprint/management/kmwsocketutil.cpp
@@ -0,0 +1,219 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include <config.h>
+
+#include "kmwsocketutil.h"
+
+#include <qprogressbar.h>
+#include <qlineedit.h>
+#include <qlabel.h>
+#include <qcombobox.h>
+#include <qpushbutton.h>
+#include <kmessagebox.h>
+#include <qlayout.h>
+#include <qregexp.h>
+#include <knumvalidator.h>
+
+#include <kapplication.h>
+#include <klocale.h>
+#include <kextsock.h>
+#include <kdebug.h>
+
+#include <unistd.h>
+
+QString localRootIP();
+
+//----------------------------------------------------------------------------------------
+
+SocketConfig::SocketConfig(KMWSocketUtil *util, QWidget *parent, const char *name)
+: KDialogBase(parent, name, true, QString::null, Ok|Cancel, Ok, true)
+{
+ QWidget *dummy = new QWidget(this);
+ setMainWidget(dummy);
+ KIntValidator *val = new KIntValidator( this );
+ QLabel *masklabel = new QLabel(i18n("&Subnetwork:"),dummy);
+ QLabel *portlabel = new QLabel(i18n("&Port:"),dummy);
+ QLabel *toutlabel = new QLabel(i18n("&Timeout (ms):"),dummy);
+ QLineEdit *mm = new QLineEdit(dummy);
+ mm->setText(QString::fromLatin1(".[0-255]"));
+ mm->setReadOnly(true);
+ mm->setFixedWidth(fontMetrics().width(mm->text())+10);
+
+ mask_ = new QLineEdit(dummy);
+ mask_->setAlignment(Qt::AlignRight);
+ port_ = new QComboBox(true,dummy);
+ if ( port_->lineEdit() )
+ port_->lineEdit()->setValidator( val );
+ tout_ = new QLineEdit(dummy);
+ tout_->setValidator( val );
+
+ masklabel->setBuddy(mask_);
+ portlabel->setBuddy(port_);
+ toutlabel->setBuddy(tout_);
+
+ mask_->setText(util->root_);
+ port_->insertItem("631");
+ port_->insertItem("9100");
+ port_->insertItem("9101");
+ port_->insertItem("9102");
+ port_->setEditText(QString::number(util->port_));
+ tout_->setText(QString::number(util->timeout_));
+
+ QGridLayout *main_ = new QGridLayout(dummy, 3, 2, 0, 10);
+ QHBoxLayout *lay1 = new QHBoxLayout(0, 0, 5);
+ main_->addWidget(masklabel, 0, 0);
+ main_->addWidget(portlabel, 1, 0);
+ main_->addWidget(toutlabel, 2, 0);
+ main_->addLayout(lay1, 0, 1);
+ main_->addWidget(port_, 1, 1);
+ main_->addWidget(tout_, 2, 1);
+ lay1->addWidget(mask_,1);
+ lay1->addWidget(mm,0);
+
+ resize(250,130);
+ setCaption(i18n("Scan Configuration"));
+}
+
+SocketConfig::~SocketConfig()
+{
+}
+
+void SocketConfig::slotOk()
+{
+ QString msg;
+ QRegExp re("(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})");
+ if (!re.exactMatch(mask_->text()))
+ msg = i18n("Wrong subnetwork specification.");
+ else
+ {
+ for (int i=1; i<=3; i++)
+ if (re.cap(i).toInt() >= 255)
+ {
+ msg = i18n("Wrong subnetwork specification.");
+ break;
+ }
+ }
+
+ bool ok(false);
+ int v = tout_->text().toInt(&ok);
+ if (!ok || v <= 0)
+ msg = i18n("Wrong timeout specification.");
+ v = port_->currentText().toInt(&ok);
+ if (!ok || v <= 0)
+ msg = i18n("Wrong port specification.");
+ if (!msg.isEmpty())
+ {
+ KMessageBox::error(this,msg);
+ return;
+ }
+
+ KDialogBase::slotOk();
+}
+
+//----------------------------------------------------------------------------------------
+
+KMWSocketUtil::KMWSocketUtil()
+{
+ printerlist_.setAutoDelete(true);
+ root_ = localRootIP();
+ port_ = 9100;
+ timeout_ = 50;
+}
+
+bool KMWSocketUtil::checkPrinter(const QString& IPstr, int port, QString* hostname)
+{
+ KExtendedSocket sock(IPstr, port, KExtendedSocket::inetSocket|KExtendedSocket::streamSocket);
+ bool result(false);
+ sock.setTimeout(0, timeout_ * 1000);
+ if (sock.connect() == 0)
+ {
+ if (hostname)
+ {
+ QString portname;
+ KExtendedSocket::resolve((KSocketAddress*)(sock.peerAddress()), *hostname, portname);
+ }
+ result = true;
+ }
+ sock.close();
+ return result;
+}
+
+bool KMWSocketUtil::scanNetwork(QProgressBar *bar)
+{
+ printerlist_.setAutoDelete(true);
+ printerlist_.clear();
+ int n(256);
+ if (bar)
+ bar->setTotalSteps(n);
+ for (int i=0; i<n; i++)
+ {
+ QString IPstr = root_ + "." + QString::number(i);
+ QString hostname;
+ if (checkPrinter(IPstr, port_, &hostname))
+ { // we found a printer at this address, create SocketInfo entry in printer list
+ SocketInfo *info = new SocketInfo;
+ info->IP = IPstr;
+ info->Port = port_;
+ info->Name = hostname;
+ printerlist_.append(info);
+ }
+ if (bar)
+ {
+ bar->setProgress(i);
+ kapp->flushX();
+ }
+ }
+ return true;
+}
+
+void KMWSocketUtil::configureScan(QWidget *parent)
+{
+ SocketConfig *dlg = new SocketConfig(this,parent);
+ if (dlg->exec())
+ {
+ root_ = dlg->mask_->text();
+ port_ = dlg->port_->currentText().toInt();
+ timeout_ = dlg->tout_->text().toInt();
+ }
+ delete dlg;
+}
+
+//----------------------------------------------------------------------------------------
+
+QString localRootIP()
+{
+ char buf[256];
+ buf[0] = '\0';
+ if (!gethostname(buf, sizeof(buf)))
+ buf[sizeof(buf)-1] = '\0';
+ QPtrList<KAddressInfo> infos = KExtendedSocket::lookup(buf, QString::null);
+ infos.setAutoDelete(true);
+ if (infos.count() > 0)
+ {
+ QString IPstr = infos.first()->address()->nodeName();
+ int p = IPstr.findRev('.');
+ IPstr.truncate(p);
+ return IPstr;
+ }
+ return QString::null;
+}
+
+#include "kmwsocketutil.moc"
diff --git a/kdeprint/management/kmwsocketutil.h b/kdeprint/management/kmwsocketutil.h
new file mode 100644
index 000000000..fa1942ef5
--- /dev/null
+++ b/kdeprint/management/kmwsocketutil.h
@@ -0,0 +1,76 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMWSOCKETUTIL_H
+#define KMWSOCKETUTIL_H
+
+#include <qstring.h>
+#include <qptrlist.h>
+#include <kdialogbase.h>
+
+struct SocketInfo
+{
+ QString IP;
+ QString Name;
+ int Port;
+};
+
+class QProgressBar;
+class QLineEdit;
+class QComboBox;
+class KMWSocketUtil;
+
+class SocketConfig : public KDialogBase
+{
+ friend class KMWSocketUtil;
+ Q_OBJECT
+public:
+ SocketConfig(KMWSocketUtil *util, QWidget *parent = 0, const char *name = 0);
+ ~SocketConfig();
+
+protected slots:
+ void slotOk();
+
+private:
+ QLineEdit *mask_, *tout_;
+ QComboBox *port_;
+};
+
+class KMWSocketUtil
+{
+ friend class SocketConfig;
+
+public:
+ KMWSocketUtil();
+
+ bool checkPrinter(const QString& host, int port, QString* hostname = 0);
+
+ const QPtrList<SocketInfo>* printerList() { return &printerlist_; }
+ bool scanNetwork(QProgressBar *bar = 0);
+ void configureScan(QWidget *parent = 0);
+ void setDefaultPort(int p) { port_ = p; }
+
+private:
+ QPtrList<SocketInfo> printerlist_;
+ QString root_;
+ int port_;
+ int timeout_; // in milliseconds
+};
+
+#endif
diff --git a/kdeprint/management/kxmlcommanddlg.cpp b/kdeprint/management/kxmlcommanddlg.cpp
new file mode 100644
index 000000000..b9610ad13
--- /dev/null
+++ b/kdeprint/management/kxmlcommanddlg.cpp
@@ -0,0 +1,1059 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kxmlcommanddlg.h"
+#include "driver.h"
+#include "kxmlcommand.h"
+
+#include <qlayout.h>
+#include <qheader.h>
+#include <qlabel.h>
+#include <qlineedit.h>
+#include <qcombobox.h>
+#include <qgroupbox.h>
+#include <qwidgetstack.h>
+#include <qtoolbutton.h>
+#include <kpushbutton.h>
+#include <qtooltip.h>
+#include <qcheckbox.h>
+#include <ktextedit.h>
+#include <qregexp.h>
+#include <qwhatsthis.h>
+#include <qapplication.h>
+
+#include <klistview.h>
+#include <klocale.h>
+#include <kiconloader.h>
+#include <kdialogbase.h>
+#include <kseparator.h>
+#include <klistbox.h>
+#include <kmimetype.h>
+#include <kmessagebox.h>
+#include <kapplication.h>
+#include <kdebug.h>
+#include <kguiitem.h>
+
+QString generateId(const QMap<QString, DrBase*>& map)
+{
+ int index(-1);
+ while (map.contains(QString::fromLatin1("item%1").arg(++index))) ;
+ return QString::fromLatin1("item%1").arg(index);
+}
+
+QListViewItem* findPrev(QListViewItem *item)
+{
+ QListViewItem *prev = item->itemAbove();
+ while (prev && prev->depth() > item->depth())
+ prev = prev->itemAbove();
+ if (prev && prev->depth() == item->depth())
+ return prev;
+ else
+ return 0;
+}
+
+QListViewItem* findNext(QListViewItem *item)
+{
+ QListViewItem *next = item->itemBelow();
+ while (next && next->depth() > item->depth())
+ next = next->itemBelow();
+ if (next && next->depth() == item->depth())
+ return next;
+ else
+ return 0;
+}
+
+KXmlCommandAdvancedDlg::KXmlCommandAdvancedDlg(QWidget *parent, const char *name)
+: QWidget(parent, name)
+{
+ m_xmlcmd = 0;
+
+ m_command = new QLineEdit(this);
+ m_view = new KListView(this);
+ m_view->addColumn("");
+ m_view->header()->hide();
+ m_view->setSorting(-1);
+ m_apply = new QToolButton(this);
+ m_apply->setIconSet( QApplication::reverseLayout()? SmallIconSet( "forward" ) : SmallIconSet("back"));
+ m_addgrp = new QToolButton(this);
+ m_addgrp->setIconSet(SmallIconSet("folder"));
+ m_addopt = new QToolButton(this);
+ m_addopt->setIconSet(SmallIconSet("document"));
+ m_delopt = new QToolButton(this);
+ m_delopt->setIconSet(SmallIconSet("editdelete"));
+ m_up = new QToolButton(this);
+ m_up->setIconSet(SmallIconSet("up"));
+ m_down = new QToolButton(this);
+ m_down->setIconSet(SmallIconSet("down"));
+ m_dummy = new QWidget(this);
+ m_desc = new QLineEdit(m_dummy);
+ m_name = new QLineEdit(m_dummy);
+ m_type = new QComboBox(m_dummy);
+ m_type->insertItem(i18n("String"));
+ m_type->insertItem(i18n("Integer"));
+ m_type->insertItem(i18n("Float"));
+ m_type->insertItem(i18n("List"));
+ m_type->insertItem(i18n("Boolean"));
+ m_format = new QLineEdit(m_dummy);
+ m_default = new QLineEdit(m_dummy);
+ QLabel *m_namelab = new QLabel(i18n("&Name:"), m_dummy);
+ QLabel *m_desclab = new QLabel(i18n("&Description:"), m_dummy);
+ QLabel *m_formatlab = new QLabel(i18n("&Format:"), m_dummy);
+ QLabel *m_typelab = new QLabel(i18n("&Type:"), m_dummy);
+ QLabel *m_defaultlab = new QLabel(i18n("Default &value:"), m_dummy);
+ QLabel *m_commandlab = new QLabel(i18n("Co&mmand:"), this);
+ m_namelab->setBuddy(m_name);
+ m_desclab->setBuddy(m_desc);
+ m_formatlab->setBuddy(m_format);
+ m_typelab->setBuddy(m_type);
+ m_defaultlab->setBuddy(m_default);
+ m_commandlab->setBuddy(m_command);
+ m_persistent = new QCheckBox( i18n( "&Persistent option" ), m_dummy );
+
+ QGroupBox *gb = new QGroupBox(0, Qt::Horizontal, i18n("Va&lues"), m_dummy);
+ m_stack = new QWidgetStack(gb);
+ QWidget *w1 = new QWidget(m_stack), *w2 = new QWidget(m_stack), *w3 = new QWidget(m_stack);
+ m_stack->addWidget(w1, 1);
+ m_stack->addWidget(w2, 2);
+ m_stack->addWidget(w3, 3);
+ m_edit1 = new QLineEdit(w1);
+ m_edit2 = new QLineEdit(w1);
+ QLabel *m_editlab1 = new QLabel(i18n("Minimum v&alue:"), w1);
+ QLabel *m_editlab2 = new QLabel(i18n("Ma&ximum value:"), w1);
+ m_editlab1->setBuddy(m_edit1);
+ m_editlab2->setBuddy(m_edit2);
+ m_values = new KListView(w2);
+ m_values->addColumn(i18n("Name"));
+ m_values->addColumn(i18n("Description"));
+ m_values->setAllColumnsShowFocus(true);
+ m_values->setSorting(-1);
+ m_values->setMaximumHeight(110);
+ m_addval = new QToolButton(w2);
+ m_addval->setIconSet(SmallIconSet("editcopy"));
+ m_delval = new QToolButton(w2);
+ m_delval->setIconSet(SmallIconSet("editdelete"));
+ QToolTip::add(m_addval, i18n("Add value"));
+ QToolTip::add(m_delval, i18n("Delete value"));
+
+ QToolTip::add(m_apply, i18n("Apply changes"));
+ QToolTip::add(m_addgrp, i18n("Add group"));
+ QToolTip::add(m_addopt, i18n("Add option"));
+ QToolTip::add(m_delopt, i18n("Delete item"));
+ QToolTip::add(m_up, i18n("Move up"));
+ QToolTip::add(m_down, i18n("Move down"));
+
+ KSeparator *sep1 = new KSeparator(KSeparator::HLine, m_dummy);
+
+ QGroupBox *gb_input = new QGroupBox(0, Qt::Horizontal, i18n("&Input From"), this);
+ QGroupBox *gb_output = new QGroupBox(0, Qt::Horizontal, i18n("O&utput To"), this);
+ QLabel *m_inputfilelab = new QLabel(i18n("File:"), gb_input);
+ QLabel *m_inputpipelab = new QLabel(i18n("Pipe:"), gb_input);
+ QLabel *m_outputfilelab = new QLabel(i18n("File:"), gb_output);
+ QLabel *m_outputpipelab = new QLabel(i18n("Pipe:"), gb_output);
+ m_inputfile = new QLineEdit(gb_input);
+ m_inputpipe = new QLineEdit(gb_input);
+ m_outputfile = new QLineEdit(gb_output);
+ m_outputpipe = new QLineEdit(gb_output);
+
+ m_comment = new KTextEdit( this );
+ m_comment->setTextFormat(Qt::RichText );
+ m_comment->setReadOnly(true);
+ QLabel *m_commentlab = new QLabel( i18n( "Comment:" ), this );
+
+ QVBoxLayout *l2 = new QVBoxLayout(this, 0, KDialog::spacingHint());
+ QHBoxLayout *l3 = new QHBoxLayout(0, 0, KDialog::spacingHint());
+ QVBoxLayout *l7 = new QVBoxLayout(0, 0, 0);
+ l2->addLayout(l3, 0);
+ l3->addWidget(m_commandlab);
+ l3->addWidget(m_command);
+ QHBoxLayout *l0 = new QHBoxLayout(0, 0, KDialog::spacingHint());
+ QGridLayout *l10 = new QGridLayout(0, 2, 2, 0, KDialog::spacingHint());
+ l2->addLayout(l0, 1);
+ l0->addLayout(l10);
+ l10->addMultiCellWidget(m_view, 0, 0, 0, 1);
+ l10->addWidget(gb_input, 1, 0);
+ l10->addWidget(gb_output, 1, 1);
+ l10->setRowStretch(0, 1);
+ l0->addLayout(l7);
+ l7->addWidget(m_apply);
+ l7->addSpacing(5);
+ l7->addWidget(m_addgrp);
+ l7->addWidget(m_addopt);
+ l7->addWidget(m_delopt);
+ l7->addSpacing(5);
+ l7->addWidget(m_up);
+ l7->addWidget(m_down);
+ l7->addStretch(1);
+ l0->addWidget(m_dummy, 1);
+ QGridLayout *l1 = new QGridLayout(m_dummy, 9, 2, 0, KDialog::spacingHint());
+ l1->addWidget(m_desclab, 0, 0, Qt::AlignRight|Qt::AlignVCenter);
+ l1->addWidget(m_desc, 0, 1);
+ l1->addMultiCellWidget(sep1, 1, 1, 0, 1);
+ l1->addWidget(m_namelab, 2, 0, Qt::AlignRight|Qt::AlignVCenter);
+ l1->addWidget(m_name, 2, 1);
+ l1->addWidget(m_typelab, 3, 0, Qt::AlignRight|Qt::AlignVCenter);
+ l1->addWidget(m_type, 3, 1);
+ l1->addWidget(m_formatlab, 4, 0, Qt::AlignRight|Qt::AlignVCenter);
+ l1->addWidget(m_format, 4, 1);
+ l1->addWidget(m_defaultlab, 5, 0, Qt::AlignRight|Qt::AlignVCenter);
+ l1->addWidget(m_default, 5, 1);
+ l1->addWidget( m_persistent, 6, 1 );
+ l1->addMultiCellWidget(gb, 7, 7, 0, 1);
+ l1->setRowStretch(8, 1);
+
+ QHBoxLayout *l4 = new QHBoxLayout(w2, 0, KDialog::spacingHint());
+ l4->addWidget(m_values);
+ QVBoxLayout *l6 = new QVBoxLayout(0, 0, 0);
+ l4->addLayout(l6);
+ l6->addWidget(m_addval);
+ l6->addWidget(m_delval);
+ l6->addStretch(1);
+ QGridLayout *l5 = new QGridLayout(w1, 3, 2, 0, KDialog::spacingHint());
+ l5->setRowStretch(2, 1);
+ l5->addWidget(m_editlab1, 0, 0, Qt::AlignRight|Qt::AlignVCenter);
+ l5->addWidget(m_editlab2, 1, 0, Qt::AlignRight|Qt::AlignVCenter);
+ l5->addWidget(m_edit1, 0, 1);
+ l5->addWidget(m_edit2, 1, 1);
+
+ QGridLayout *l8 = new QGridLayout(gb_input->layout(), 2, 2,
+ KDialog::spacingHint());
+ QGridLayout *l9 = new QGridLayout(gb_output->layout(), 2, 2,
+ KDialog::spacingHint());
+ l8->addWidget(m_inputfilelab, 0, 0);
+ l8->addWidget(m_inputpipelab, 1, 0);
+ l8->addWidget(m_inputfile, 0, 1);
+ l8->addWidget(m_inputpipe, 1, 1);
+ l9->addWidget(m_outputfilelab, 0, 0);
+ l9->addWidget(m_outputpipelab, 1, 0);
+ l9->addWidget(m_outputfile, 0, 1);
+ l9->addWidget(m_outputpipe, 1, 1);
+
+ QVBoxLayout *l11 = new QVBoxLayout(gb->layout());
+ l11->addWidget(m_stack);
+
+ QVBoxLayout *l12 = new QVBoxLayout( 0, 0, 0 );
+ l2->addSpacing( 10 );
+ l2->addLayout( l12 );
+ l12->addWidget( m_commentlab );
+ l12->addWidget( m_comment );
+
+ connect(m_view, SIGNAL(selectionChanged(QListViewItem*)), SLOT(slotSelectionChanged(QListViewItem*)));
+ connect(m_values, SIGNAL(selectionChanged(QListViewItem*)), SLOT(slotValueSelected(QListViewItem*)));
+ connect(m_type, SIGNAL(activated(int)), SLOT(slotTypeChanged(int)));
+ connect(m_addval, SIGNAL(clicked()), SLOT(slotAddValue()));
+ connect(m_delval, SIGNAL(clicked()), SLOT(slotRemoveValue()));
+ connect(m_apply, SIGNAL(clicked()), SLOT(slotApplyChanges()));
+ connect(m_addgrp, SIGNAL(clicked()), SLOT(slotAddGroup()));
+ connect(m_addopt, SIGNAL(clicked()), SLOT(slotAddOption()));
+ connect(m_delopt, SIGNAL(clicked()), SLOT(slotRemoveItem()));
+ connect(m_up, SIGNAL(clicked()), SLOT(slotMoveUp()));
+ connect(m_down, SIGNAL(clicked()), SLOT(slotMoveDown()));
+ connect(m_command, SIGNAL(textChanged(const QString&)), SLOT(slotCommandChanged(const QString&)));
+ connect(m_view, SIGNAL(itemRenamed(QListViewItem*,int)), SLOT(slotOptionRenamed(QListViewItem*,int)));
+ connect(m_desc, SIGNAL(textChanged(const QString&)), SLOT(slotChanged()));
+ connect(m_name, SIGNAL(textChanged(const QString&)), SLOT(slotChanged()));
+ connect(m_format, SIGNAL(textChanged(const QString&)), SLOT(slotChanged()));
+ connect(m_default, SIGNAL(textChanged(const QString&)), SLOT(slotChanged()));
+ connect(m_edit1, SIGNAL(textChanged(const QString&)), SLOT(slotChanged()));
+ connect(m_edit2, SIGNAL(textChanged(const QString&)), SLOT(slotChanged()));
+ connect(m_type, SIGNAL(activated(int)), SLOT(slotChanged()));
+ connect(m_addval, SIGNAL(clicked()), SLOT(slotChanged()));
+ connect(m_delval, SIGNAL(clicked()), SLOT(slotChanged()));
+ connect( m_persistent, SIGNAL( toggled(bool) ), SLOT( slotChanged() ) );
+ m_dummy->setEnabled(false);
+ viewItem(0);
+
+ /**
+ * Add some short help for the normal (non expert) user
+ */
+ QWhatsThis::add( m_name, i18n(
+ "An identification string. Use only alphanumeric characters except spaces. "
+ "The string <b>__root__</b> is reserved for internal use." ) );
+ QWhatsThis::add( m_namelab, QWhatsThis::textFor( m_name ) );
+ QWhatsThis::add( m_desc, i18n(
+ "A description string. This string is shown in the interface, and should "
+ "be explicit enough about the role of the corresponding option." ) );
+ QWhatsThis::add( m_desclab, QWhatsThis::textFor( m_desc ) );
+ QWhatsThis::add( m_type, i18n(
+ "The type of the option. This determines how the option is presented "
+ "graphically to the user." ) );
+ QWhatsThis::add( m_typelab, QWhatsThis::textFor( m_type ) );
+ QWhatsThis::add( m_format, i18n(
+ "The format of the option. This determines how the option is formatted "
+ "for inclusion in the global command line. The tag <b>%value</b> can be used "
+ "to represent the user selection. This tag will be replaced at run-time by a "
+ "string representation of the option value." ) );
+ QWhatsThis::add( m_formatlab, QWhatsThis::textFor( m_format ) );
+ QWhatsThis::add( m_default, i18n(
+ "The default value of the option. For non persistent options, nothing is "
+ "added to the command line if the option has that default value. If this "
+ "value does not correspond to the actual default value of the underlying "
+ "utility, make the option persistent to avoid unwanted effects." ) );
+ QWhatsThis::add( m_defaultlab, QWhatsThis::textFor( m_default ) );
+ QWhatsThis::add( m_persistent, i18n(
+ "Make the option persistent. A persistent option is always written to the "
+ "command line, whatever its value. This is useful when the chosen default "
+ "value does not match with the actual default value of the underlying utility." ) );
+ QWhatsThis::add( m_command, i18n(
+ "The full command line to execute the associated underlying utility. This "
+ "command line is based on a mechanism of tags that are replaced at run-time. "
+ "The supported tags are:<ul>"
+ "<li><b>%filterargs</b>: command options</li>"
+ "<li><b>%filterinput</b>: input specification</li>"
+ "<li><b>%filteroutput</b>: output specification</li>"
+ "<li><b>%psu</b>: the page size in upper case</li>"
+ "<li><b>%psl</b>: the page size in lower case</li></ul>" ) );
+ QWhatsThis::add( m_commandlab, QWhatsThis::textFor( m_command ) );
+ QWhatsThis::add( m_inputfile, i18n(
+ "Input specification when the underlying utility reads input data from a file. Use "
+ "the tag <b>%in</b> to represent the input filename." ) );
+ QWhatsThis::add( m_inputfilelab, QWhatsThis::textFor( m_inputfile ) );
+ QWhatsThis::add( m_outputfile, i18n(
+ "Output specification when the underlying utility writes output data to a file. Use "
+ "the tag <b>%out</b> to represent the output filename." ) );
+ QWhatsThis::add( m_outputfilelab, QWhatsThis::textFor( m_outputfile ) );
+ QWhatsThis::add( m_inputpipe, i18n(
+ "Input specification when the underlying utility reads input data from its "
+ "standard input." ) );
+ QWhatsThis::add( m_inputpipelab, QWhatsThis::textFor( m_inputpipe ) );
+ QWhatsThis::add( m_outputpipe, i18n(
+ "Output specification when the underlying utility writes output data to its "
+ "standard output." ) );
+ QWhatsThis::add( m_outputpipelab, QWhatsThis::textFor( m_outputpipe ) );
+ QWhatsThis::add( m_comment, i18n(
+ "A comment about the underlying utility, which can be viewed by the user "
+ "from the interface. This comment string supports basic HTML tags like "
+ "&lt;a&gt;, &lt;b&gt; or &lt;i&gt;." ) );
+ QWhatsThis::add( m_commentlab, QWhatsThis::textFor( m_comment ) );
+
+ resize(660, 200);
+}
+
+KXmlCommandAdvancedDlg::~KXmlCommandAdvancedDlg()
+{
+ if (m_opts.count() > 0)
+ {
+ kdDebug() << "KXmlCommandAdvancedDlg: " << m_opts.count() << " items remaining" << endl;
+ for (QMap<QString,DrBase*>::ConstIterator it=m_opts.begin(); it!=m_opts.end(); ++it)
+ {
+ //kdDebug() << "Item: name=" << (*it)->name() << endl;
+ delete (*it);
+ }
+ }
+}
+
+void KXmlCommandAdvancedDlg::setCommand(KXmlCommand *xmlcmd)
+{
+ m_xmlcmd = xmlcmd;
+ if (m_xmlcmd)
+ parseXmlCommand(m_xmlcmd);
+}
+
+void KXmlCommandAdvancedDlg::parseXmlCommand(KXmlCommand *xmlcmd)
+{
+ m_view->clear();
+ QListViewItem *root = new QListViewItem(m_view, xmlcmd->name(), xmlcmd->name());
+ DrMain *driver = xmlcmd->driver();
+
+ root->setPixmap(0, SmallIcon("fileprint"));
+ root->setOpen(true);
+ if (driver)
+ {
+ DrMain *clone = driver->cloneDriver();
+ if (!clone->get("text").isEmpty())
+ root->setText(0, clone->get("text"));
+ root->setText(1, "__root__");
+ clone->setName("__root__");
+ m_opts["__root__"] = clone;
+ parseGroupItem(clone, root);
+ clone->flatten();
+ }
+ m_command->setText(xmlcmd->command());
+ m_inputfile->setText(xmlcmd->io(true, false));
+ m_inputpipe->setText(xmlcmd->io(true, true));
+ m_outputfile->setText(xmlcmd->io(false, false));
+ m_outputpipe->setText(xmlcmd->io(false, true));
+ m_comment->setText( xmlcmd->comment() );
+
+ viewItem(0);
+}
+
+void KXmlCommandAdvancedDlg::parseGroupItem(DrGroup *grp, QListViewItem *parent)
+{
+ QListViewItem *item(0);
+
+ QPtrListIterator<DrGroup> git(grp->groups());
+ for (; git.current(); ++git)
+ {
+ QString namestr = git.current()->name();
+ if (namestr.isEmpty())
+ {
+ namestr = "group_"+kapp->randomString(4);
+ }
+ git.current()->setName(namestr);
+ item = new QListViewItem(parent, item, git.current()->get("text"), git.current()->name());
+ item->setPixmap(0, SmallIcon("folder"));
+ item->setOpen(true);
+ item->setRenameEnabled(0, true);
+ parseGroupItem(git.current(), item);
+ m_opts[namestr] = git.current();
+ }
+
+ QPtrListIterator<DrBase> oit(grp->options());
+ for (; oit.current(); ++oit)
+ {
+ QString namestr = oit.current()->name().mid(m_xmlcmd->name().length()+6);
+ if (namestr.isEmpty())
+ {
+ namestr = "option_"+kapp->randomString(4);
+ }
+ oit.current()->setName(namestr);
+ item = new QListViewItem(parent, item, oit.current()->get("text"), namestr);
+ item->setPixmap(0, SmallIcon("document"));
+ item->setRenameEnabled(0, true);
+ m_opts[namestr] = oit.current();
+ }
+}
+
+void KXmlCommandAdvancedDlg::slotSelectionChanged(QListViewItem *item)
+{
+ if (item && item->depth() == 0)
+ item = 0;
+ viewItem(item);
+}
+
+void KXmlCommandAdvancedDlg::viewItem(QListViewItem *item)
+{
+ m_dummy->setEnabled((item != 0));
+ m_name->setText("");
+ m_desc->setText("");
+ m_format->setText("");
+ m_default->setText("");
+ m_values->clear();
+ m_edit1->setText("");
+ m_edit2->setText("");
+ m_persistent->setChecked( false );
+ int typeId(-1);
+ if (item)
+ {
+ m_name->setText(item->text(1));
+ m_desc->setText(item->text(0));
+
+ DrBase *opt = (m_opts.contains(item->text(1)) ? m_opts[item->text(1)] : 0);
+ if (opt)
+ {
+ bool isgroup = (opt->type() < DrBase::String);
+ if (!isgroup)
+ {
+ m_type->setCurrentItem(opt->type() - DrBase::String);
+ typeId = m_type->currentItem();
+ m_format->setText(opt->get("format"));
+ m_default->setText(opt->get("default"));
+ }
+ m_type->setEnabled(!isgroup);
+ m_default->setEnabled(!isgroup);
+ m_format->setEnabled(!isgroup);
+ m_stack->setEnabled(!isgroup);
+
+ switch (opt->type())
+ {
+ case DrBase::Float:
+ case DrBase::Integer:
+ m_edit1->setText(opt->get("minval"));
+ m_edit2->setText(opt->get("maxval"));
+ break;
+ case DrBase::Boolean:
+ case DrBase::List:
+ {
+ QPtrListIterator<DrBase> it(*(static_cast<DrListOption*>(opt)->choices()));
+ QListViewItem *item(0);
+ for (; it.current(); ++it)
+ {
+ item = new QListViewItem(m_values, item, it.current()->name(), it.current()->get("text"));
+ item->setRenameEnabled(0, true);
+ item->setRenameEnabled(1, true);
+ }
+ break;
+ }
+ default:
+ break;
+ }
+
+ m_addgrp->setEnabled(isgroup);
+ m_addopt->setEnabled(isgroup);
+
+ QListViewItem *prevItem = findPrev(item), *nextItem = findNext(item);
+ DrBase *prevOpt = (prevItem && m_opts.contains(prevItem->text(1)) ? m_opts[prevItem->text(1)] : 0);
+ DrBase *nextOpt = (nextItem && m_opts.contains(nextItem->text(1)) ? m_opts[nextItem->text(1)] : 0);
+ m_up->setEnabled(prevOpt && !(prevOpt->type() < DrBase::String && opt->type() >= DrBase::String));
+ m_down->setEnabled(nextOpt && !(isgroup && nextOpt->type() >= DrBase::String));
+
+ m_persistent->setChecked( opt->get( "persistent" ) == "1" );
+ }
+
+ m_delopt->setEnabled(true);
+ m_dummy->setEnabled(opt);
+ }
+ else
+ {
+ m_delopt->setEnabled(false);
+ m_addopt->setEnabled(m_view->currentItem() && m_view->isEnabled());
+ m_addgrp->setEnabled(m_view->currentItem() && m_view->isEnabled());
+ m_up->setEnabled(false);
+ m_down->setEnabled(false);
+ }
+ slotTypeChanged(typeId);
+ m_apply->setEnabled(false);
+}
+
+void KXmlCommandAdvancedDlg::slotTypeChanged(int ID)
+{
+ int wId(3);
+ ID += DrBase::String;
+ switch (ID)
+ {
+ case DrBase::Float:
+ case DrBase::Integer:
+ wId = 1;
+ break;
+ case DrBase::Boolean:
+ case DrBase::List:
+ wId = 2;
+ slotValueSelected(m_values->currentItem());
+ break;
+ }
+ m_stack->raiseWidget(wId);
+}
+
+void KXmlCommandAdvancedDlg::slotAddValue()
+{
+ QListViewItem *item = new QListViewItem(m_values, m_values->lastItem(), i18n("Name"), i18n("Description"));
+ item->setRenameEnabled(0, true);
+ item->setRenameEnabled(1, true);
+ m_values->ensureItemVisible(item);
+ slotValueSelected(item);
+ item->startRename(0);
+}
+
+void KXmlCommandAdvancedDlg::slotRemoveValue()
+{
+ QListViewItem *item = m_values->currentItem();
+ if (item)
+ delete item;
+ slotValueSelected(m_values->currentItem());
+}
+
+void KXmlCommandAdvancedDlg::slotApplyChanges()
+{
+ QListViewItem *item = m_view->currentItem();
+ if (item)
+ {
+ if (m_name->text().isEmpty() || m_name->text() == "__root__")
+ {
+ KMessageBox::error(this, i18n("Invalid identification name. Empty strings and \"__root__\" are not allowed."));
+ return;
+ }
+
+ m_apply->setEnabled(false);
+
+ DrBase *opt = (m_opts.contains(item->text(1)) ? m_opts[item->text(1)] : 0);
+ m_opts.remove(item->text(1));
+ delete opt;
+
+ // update tree item
+ item->setText(0, m_desc->text());
+ item->setText(1, m_name->text());
+
+ // recreate option
+ if (m_type->isEnabled())
+ {
+ int type = m_type->currentItem() + DrBase::String;
+ switch (type)
+ {
+ case DrBase::Integer:
+ case DrBase::Float:
+ if (type == DrBase::Integer)
+ opt = new DrIntegerOption;
+ else
+ opt = new DrFloatOption;
+ opt->set("minval", m_edit1->text());
+ opt->set("maxval", m_edit2->text());
+ break;
+ case DrBase::List:
+ case DrBase::Boolean:
+ {
+ if (type == DrBase::List)
+ opt = new DrListOption;
+ else
+ opt = new DrBooleanOption;
+ DrListOption *lopt = static_cast<DrListOption*>(opt);
+ QListViewItem *item = m_values->firstChild();
+ while (item)
+ {
+ DrBase *choice = new DrBase;
+ choice->setName(item->text(0));
+ choice->set("text", item->text(1));
+ lopt->addChoice(choice);
+ item = item->nextSibling();
+ }
+ break;
+ }
+ case DrBase::String:
+ opt = new DrStringOption;
+ break;
+
+ }
+ opt->set("format", m_format->text());
+ opt->set("default", m_default->text());
+ opt->setValueText(opt->get("default"));
+ }
+ else
+ opt = new DrGroup;
+
+ opt->setName((m_name->text().isEmpty() ? generateId(m_opts) : m_name->text()));
+ opt->set("text", m_desc->text());
+ opt->set( "persistent", m_persistent->isChecked() ? "1" : "0" );
+
+ m_opts[opt->name()] = opt;
+ }
+}
+
+void KXmlCommandAdvancedDlg::slotChanged()
+{
+ m_apply->setEnabled(true);
+}
+
+void KXmlCommandAdvancedDlg::slotAddGroup()
+{
+ if (m_view->currentItem())
+ {
+ QString ID = generateId(m_opts);
+
+ DrGroup *grp = new DrGroup;
+ grp->setName(ID);
+ grp->set("text", i18n("New Group"));
+ m_opts[ID] = grp;
+
+ QListViewItem *item = new QListViewItem(m_view->currentItem(), i18n("New Group"), ID);
+ item->setRenameEnabled(0, true);
+ item->setPixmap(0, SmallIcon("folder"));
+ m_view->ensureItemVisible(item);
+ item->startRename(0);
+ }
+}
+
+void KXmlCommandAdvancedDlg::slotAddOption()
+{
+ if (m_view->currentItem())
+ {
+ QString ID = generateId(m_opts);
+
+ DrBase *opt = new DrStringOption;
+ opt->setName(ID);
+ opt->set("text", i18n("New Option"));
+ m_opts[ID] = opt;
+
+ QListViewItem *item = new QListViewItem(m_view->currentItem(), i18n("New Option"), ID);
+ item->setRenameEnabled(0, true);
+ item->setPixmap(0, SmallIcon("document"));
+ m_view->ensureItemVisible(item);
+ item->startRename(0);
+ }
+}
+
+void KXmlCommandAdvancedDlg::slotRemoveItem()
+{
+ QListViewItem *item = m_view->currentItem();
+ if (item)
+ {
+ QListViewItem *newCurrent(item->nextSibling());
+ if (!newCurrent)
+ newCurrent = item->parent();
+ removeItem(item);
+ delete item;
+ m_view->setSelected(newCurrent, true);
+ }
+}
+
+void KXmlCommandAdvancedDlg::removeItem(QListViewItem *item)
+{
+ delete m_opts[item->text(1)];
+ m_opts.remove(item->text(1));
+ QListViewItem *child = item->firstChild();
+ while (child && item)
+ {
+ removeItem(child);
+ if ( item )
+ item = item->nextSibling();
+ }
+}
+
+void KXmlCommandAdvancedDlg::slotMoveUp()
+{
+ QListViewItem *item = m_view->currentItem(), *prev = 0;
+ if (item && (prev=findPrev(item)))
+ {
+ QListViewItem *after(0);
+ if ((after=findPrev(prev)) != 0)
+ item->moveItem(after);
+ else
+ {
+ QListViewItem *parent = item->parent();
+ parent->takeItem(item);
+ parent->insertItem(item);
+ }
+ m_view->setSelected(item, true);
+ slotSelectionChanged(item);
+ }
+}
+
+void KXmlCommandAdvancedDlg::slotMoveDown()
+{
+ QListViewItem *item = m_view->currentItem(), *next = 0;
+ if (item && (next=findNext(item)))
+ {
+ item->moveItem(next);
+ m_view->setSelected(item, true);
+ slotSelectionChanged(item);
+ }
+}
+
+void KXmlCommandAdvancedDlg::slotCommandChanged(const QString& cmd)
+{
+ m_inputfile->parentWidget()->setEnabled(cmd.find("%filterinput") != -1);
+ m_outputfile->parentWidget()->setEnabled(cmd.find("%filteroutput") != -1);
+ m_view->setEnabled(cmd.find("%filterargs") != -1);
+ m_name->parentWidget()->setEnabled(m_view->isEnabled());
+ slotSelectionChanged((m_view->isEnabled() ? m_view->currentItem() : 0));
+ m_view->setOpen(m_view->firstChild(), m_view->isEnabled());
+}
+
+void KXmlCommandAdvancedDlg::slotValueSelected(QListViewItem *item)
+{
+ m_addval->setEnabled(m_type->currentItem() != 4 || m_values->childCount() < 2);
+ m_delval->setEnabled(item != 0);
+}
+
+void KXmlCommandAdvancedDlg::slotOptionRenamed(QListViewItem *item, int)
+{
+ if (item && m_opts.contains(item->text(1)))
+ {
+ DrBase *opt = m_opts[item->text(1)];
+ opt->set("text", item->text(0));
+ slotSelectionChanged(item);
+ }
+}
+
+void KXmlCommandAdvancedDlg::recreateGroup(QListViewItem *item, DrGroup *grp)
+{
+ if (!item)
+ return;
+
+ QListViewItem *child = item->firstChild();
+ while (child)
+ {
+ DrBase *opt = (m_opts.contains(child->text(1)) ? m_opts[child->text(1)] : 0);
+ if (opt)
+ {
+ if (opt->type() == DrBase::Group)
+ {
+ DrGroup *childGroup = static_cast<DrGroup*>(opt);
+ recreateGroup(child, childGroup);
+ grp->addGroup(childGroup);
+ }
+ else
+ {
+ opt->setName("_kde-"+m_xmlcmd->name()+"-"+opt->name());
+ grp->addOption(opt);
+ }
+ m_opts.remove(child->text(1));
+ }
+ child = child->nextSibling();
+ }
+}
+
+bool KXmlCommandAdvancedDlg::editCommand(KXmlCommand *xmlcmd, QWidget *parent)
+{
+ if (!xmlcmd)
+ return false;
+
+ KDialogBase dlg(parent, 0, true, i18n("Command Edit for %1").arg(xmlcmd->name()), KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, false);
+ KXmlCommandAdvancedDlg *xmldlg = new KXmlCommandAdvancedDlg(&dlg);
+ dlg.setMainWidget(xmldlg);
+ //dlg.enableButton(KDialogBase::Ok, false);
+ xmldlg->setCommand(xmlcmd);
+ if (dlg.exec())
+ {
+ xmlcmd->setCommand(xmldlg->m_command->text());
+ xmlcmd->setIo(xmldlg->m_inputfile->text(), true, false);
+ xmlcmd->setIo(xmldlg->m_inputpipe->text(), true, true);
+ xmlcmd->setIo(xmldlg->m_outputfile->text(), false, false);
+ xmlcmd->setIo(xmldlg->m_outputpipe->text(), false, true);
+ xmlcmd->setComment( xmldlg->m_comment->text().replace( QRegExp( "\n" ), " " ) );
+
+ // need to recreate the driver tree structure
+ DrMain *driver = (xmldlg->m_opts.contains("__root__") ? static_cast<DrMain*>(xmldlg->m_opts["__root__"]) : 0);
+ if (!driver && xmldlg->m_opts.count() > 0)
+ {
+ kdDebug() << "KXmlCommandAdvancedDlg: driver structure not found, creating one" << endl;
+ driver = new DrMain;
+ driver->setName(xmlcmd->name());
+ }
+ xmldlg->recreateGroup(xmldlg->m_view->firstChild(), driver);
+ xmldlg->m_opts.remove("__root__");
+ xmlcmd->setDriver(driver);
+
+ // remaining options will be removed in destructor
+
+ return true;
+ }
+ return false;
+}
+
+//-----------------------------------------------------------------------------------------------------
+
+KXmlCommandDlg::KXmlCommandDlg(QWidget *parent, const char *name)
+: KDialogBase(parent, name, true, QString::null, Ok|Cancel|Details, Ok, true)
+{
+ setButtonText(Details, i18n("&Mime Type Settings"));
+ m_cmd = 0;
+
+ QWidget *dummy = new QWidget(this, "TopDetail");
+ QWidget *topmain = new QWidget(this, "TopMain");
+
+ QGroupBox *m_gb1 = new QGroupBox(0, Qt::Horizontal, i18n("Supported &Input Formats"), dummy);
+ QGroupBox *m_gb2 = new QGroupBox(0, Qt::Horizontal, i18n("Requirements"), topmain);
+
+ m_description = new QLineEdit(topmain);
+ m_idname = new QLabel(topmain);
+ m_requirements = new KListView(m_gb2);
+ m_requirements->addColumn("");
+ m_requirements->header()->hide();
+ m_addreq = new QToolButton(m_gb2);
+ m_addreq->setIconSet(SmallIconSet("filenew"));
+ m_removereq = new QToolButton(m_gb2);
+ m_removereq->setIconSet(SmallIconSet("editdelete"));
+ QPushButton *m_edit = new KPushButton(KGuiItem(i18n("&Edit Command..."), "edit"), topmain);
+ m_mimetype = new QComboBox(dummy);
+ m_availablemime = new KListBox(m_gb1);
+ m_selectedmime = new KListBox(m_gb1);
+ m_addmime = new QToolButton(m_gb1);
+ m_addmime->setIconSet(QApplication::reverseLayout()? SmallIconSet("forward") : SmallIconSet("back"));
+ m_removemime = new QToolButton(m_gb1);
+ m_removemime->setIconSet(QApplication::reverseLayout()? SmallIconSet("back" ) : SmallIconSet("forward"));
+ m_gb2->setMinimumWidth(380);
+ m_gb1->setMinimumHeight(180);
+ m_requirements->setMaximumHeight(80);
+ m_removereq->setEnabled(false);
+ m_addmime->setEnabled(false);
+ m_removemime->setEnabled(false);
+
+ QLabel *m_desclab = new QLabel(i18n("&Description:"), topmain);
+ m_desclab->setBuddy(m_description);
+ QLabel *m_mimetypelab = new QLabel(i18n("Output &format:"), dummy);
+ m_mimetypelab->setBuddy(m_mimetype);
+ QLabel *m_idnamelab = new QLabel(i18n("ID name:"), topmain);
+
+ QFont f(m_idname->font());
+ f.setBold(true);
+ m_idname->setFont(f);
+
+ KSeparator *sep1 = new KSeparator(QFrame::HLine, dummy);
+
+ QVBoxLayout *l0 = new QVBoxLayout(topmain, 0, 10);
+ QGridLayout *l5 = new QGridLayout(0, 2, 2, 0, 5);
+ l0->addLayout(l5);
+ l5->addWidget(m_idnamelab, 0, 0);
+ l5->addWidget(m_idname, 0, 1);
+ l5->addWidget(m_desclab, 1, 0);
+ l5->addWidget(m_description, 1, 1);
+ l0->addWidget(m_gb2);
+ QHBoxLayout *l3 = new QHBoxLayout(0, 0, 0);
+ l0->addLayout(l3);
+ l3->addWidget(m_edit);
+ l3->addStretch(1);
+
+ QVBoxLayout *l7 = new QVBoxLayout(dummy, 0, 10);
+ QHBoxLayout *l6 = new QHBoxLayout(0, 0, 5);
+ l7->addWidget(sep1);
+ l7->addLayout(l6);
+ l6->addWidget(m_mimetypelab, 0);
+ l6->addWidget(m_mimetype, 1);
+ l7->addWidget(m_gb1);
+ QGridLayout *l2 = new QGridLayout(m_gb1->layout(), 4, 3, 10);
+ l2->addMultiCellWidget(m_availablemime, 0, 3, 2, 2);
+ l2->addMultiCellWidget(m_selectedmime, 0, 3, 0, 0);
+ l2->addWidget(m_addmime, 1, 1);
+ l2->addWidget(m_removemime, 2, 1);
+ l2->setRowStretch(0, 1);
+ l2->setRowStretch(3, 1);
+ QHBoxLayout *l4 = new QHBoxLayout(m_gb2->layout(), 10);
+ l4->addWidget(m_requirements);
+ QVBoxLayout *l8 = new QVBoxLayout(0, 0, 0);
+ l4->addLayout(l8);
+ l8->addWidget(m_addreq);
+ l8->addWidget(m_removereq);
+ l8->addStretch(1);
+
+ connect(m_addmime, SIGNAL(clicked()), SLOT(slotAddMime()));
+ connect(m_removemime, SIGNAL(clicked()), SLOT(slotRemoveMime()));
+ connect(m_edit, SIGNAL(clicked()), SLOT(slotEditCommand()));
+ connect(m_requirements, SIGNAL(selectionChanged(QListViewItem*)), SLOT(slotReqSelected(QListViewItem*)));
+ connect(m_availablemime, SIGNAL(selectionChanged(QListBoxItem*)), SLOT(slotAvailableSelected(QListBoxItem*)));
+ connect(m_selectedmime, SIGNAL(selectionChanged(QListBoxItem*)), SLOT(slotSelectedSelected(QListBoxItem*)));
+ connect(m_addreq, SIGNAL(clicked()), SLOT(slotAddReq()));
+ connect(m_removereq, SIGNAL(clicked()), SLOT(slotRemoveReq()));
+
+ KMimeType::List list = KMimeType::allMimeTypes();
+ for (QValueList<KMimeType::Ptr>::ConstIterator it=list.begin(); it!=list.end(); ++it)
+ {
+ QString mimetype = (*it)->name();
+ m_mimelist << mimetype;
+ }
+
+ m_mimelist.sort();
+ m_mimetype->insertStringList(m_mimelist);
+ m_availablemime->insertStringList(m_mimelist);
+
+ setMainWidget(topmain);
+ setDetailsWidget(dummy);
+}
+
+void KXmlCommandDlg::setCommand(KXmlCommand *xmlCmd)
+{
+ setCaption(i18n("Command Edit for %1").arg(xmlCmd->name()));
+
+ m_cmd = xmlCmd;
+ m_description->setText(i18n(xmlCmd->description().utf8()));
+ m_idname->setText(xmlCmd->name());
+
+ m_requirements->clear();
+ QStringList list = xmlCmd->requirements();
+ QListViewItem *item(0);
+ for (QStringList::ConstIterator it=list.begin(); it!=list.end(); ++it)
+ {
+ item = new QListViewItem(m_requirements, item, *it);
+ item->setRenameEnabled(0, true);
+ }
+
+ int index = m_mimelist.findIndex(xmlCmd->mimeType());
+ if (index != -1)
+ m_mimetype->setCurrentItem(index);
+ else
+ m_mimetype->setCurrentItem(0);
+
+ list = xmlCmd->inputMimeTypes();
+ m_selectedmime->clear();
+ m_availablemime->clear();
+ m_availablemime->insertStringList(m_mimelist);
+ for (QStringList::ConstIterator it=list.begin(); it!=list.end(); ++it)
+ {
+ m_selectedmime->insertItem(*it);
+ delete m_availablemime->findItem(*it, Qt::ExactMatch);
+ }
+}
+
+void KXmlCommandDlg::slotOk()
+{
+ if (m_cmd)
+ {
+ m_cmd->setMimeType((m_mimetype->currentText() == "all/all" ? QString::null : m_mimetype->currentText()));
+ m_cmd->setDescription(m_description->text());
+ QStringList l;
+ QListViewItem *item = m_requirements->firstChild();
+ while (item)
+ {
+ l << item->text(0);
+ item = item->nextSibling();
+ }
+ m_cmd->setRequirements(l);
+ l.clear();
+ for (uint i=0; i<m_selectedmime->count(); i++)
+ l << m_selectedmime->text(i);
+ m_cmd->setInputMimeTypes(l);
+ }
+ KDialogBase::slotOk();
+}
+
+bool KXmlCommandDlg::editCommand(KXmlCommand *xmlCmd, QWidget *parent)
+{
+ if (!xmlCmd)
+ return false;
+
+ KXmlCommandDlg xmldlg(parent, 0);
+ xmldlg.setCommand(xmlCmd);
+
+ return (xmldlg.exec() == Accepted);
+}
+
+void KXmlCommandDlg::slotAddMime()
+{
+ int index = m_availablemime->currentItem();
+ if (index != -1)
+ {
+ m_selectedmime->insertItem(m_availablemime->currentText());
+ m_availablemime->removeItem(index);
+ m_selectedmime->sort();
+ }
+}
+
+void KXmlCommandDlg::slotRemoveMime()
+{
+ int index = m_selectedmime->currentItem();
+ if (index != -1)
+ {
+ m_availablemime->insertItem(m_selectedmime->currentText());
+ m_selectedmime->removeItem(index);
+ m_availablemime->sort();
+ }
+}
+
+void KXmlCommandDlg::slotEditCommand()
+{
+ KXmlCommandAdvancedDlg::editCommand(m_cmd, parentWidget());
+}
+
+void KXmlCommandDlg::slotAddReq()
+{
+ QListViewItem *item = new QListViewItem(m_requirements, m_requirements->lastItem(), i18n("exec:/"));
+ item->setRenameEnabled(0, true);
+ m_requirements->ensureItemVisible(item);
+ item->startRename(0);
+}
+
+void KXmlCommandDlg::slotRemoveReq()
+{
+ delete m_requirements->currentItem();
+}
+
+void KXmlCommandDlg::slotReqSelected(QListViewItem *item)
+{
+ m_removereq->setEnabled(item);
+}
+
+void KXmlCommandDlg::slotAvailableSelected(QListBoxItem *item)
+{
+ m_addmime->setEnabled(item);
+}
+
+void KXmlCommandDlg::slotSelectedSelected(QListBoxItem *item)
+{
+ m_removemime->setEnabled(item);
+}
+
+#include "kxmlcommanddlg.moc"
diff --git a/kdeprint/management/kxmlcommanddlg.h b/kdeprint/management/kxmlcommanddlg.h
new file mode 100644
index 000000000..54bec2dfc
--- /dev/null
+++ b/kdeprint/management/kxmlcommanddlg.h
@@ -0,0 +1,127 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KXMLCOMMANDDLG_H
+#define KXMLCOMMANDDLG_H
+
+#include <qwidget.h>
+#include <qmap.h>
+#include <qstringlist.h>
+#include <kdialogbase.h>
+
+class KListView;
+class QListViewItem;
+class QLineEdit;
+class QComboBox;
+class QWidgetStack;
+class QToolButton;
+class KListBox;
+class QListBoxItem;
+class QTextEdit;
+class QCheckBox;
+
+class DrGroup;
+class DrBase;
+class KXmlCommand;
+
+class KXmlCommandAdvancedDlg : public QWidget
+{
+ Q_OBJECT
+public:
+ KXmlCommandAdvancedDlg(QWidget *parent = 0, const char *name = 0);
+ ~KXmlCommandAdvancedDlg();
+
+ void setCommand(KXmlCommand*);
+ static bool editCommand(KXmlCommand *xmlcmd, QWidget *parent = 0);
+
+protected:
+ void parseGroupItem(DrGroup*, QListViewItem*);
+ void parseXmlCommand(KXmlCommand*);
+ void viewItem(QListViewItem*);
+ void removeItem(QListViewItem*);
+ void recreateGroup(QListViewItem*, DrGroup*);
+
+protected slots:
+ void slotSelectionChanged(QListViewItem*);
+ void slotTypeChanged(int);
+ void slotAddValue();
+ void slotRemoveValue();
+ void slotApplyChanges();
+ void slotAddGroup();
+ void slotAddOption();
+ void slotRemoveItem();
+ void slotMoveUp();
+ void slotMoveDown();
+ void slotCommandChanged(const QString&);
+ void slotValueSelected(QListViewItem*);
+ void slotOptionRenamed(QListViewItem*, int);
+ void slotChanged();
+
+private:
+ KListView *m_view;
+ QLineEdit *m_name, *m_desc, *m_format, *m_default, *m_command;
+ QComboBox *m_type;
+ QWidget *m_dummy;
+ KListView *m_values;
+ QLineEdit *m_edit1, *m_edit2;
+ QWidgetStack *m_stack;
+ QToolButton *m_apply, *m_addgrp, *m_addopt, *m_delopt, *m_up, *m_down;
+ QLineEdit *m_inputfile, *m_inputpipe, *m_outputfile, *m_outputpipe;
+ QToolButton *m_addval, *m_delval;
+ QTextEdit *m_comment;
+ QCheckBox *m_persistent;
+
+ KXmlCommand *m_xmlcmd;
+ QMap<QString, DrBase*> m_opts;
+};
+
+class KXmlCommandDlg : public KDialogBase
+{
+ Q_OBJECT
+public:
+ KXmlCommandDlg(QWidget *parent = 0, const char *name = 0);
+
+ void setCommand(KXmlCommand*);
+ static bool editCommand(KXmlCommand*, QWidget *parent = 0);
+
+protected slots:
+ void slotAddMime();
+ void slotRemoveMime();
+ void slotEditCommand();
+ void slotAddReq();
+ void slotRemoveReq();
+ void slotReqSelected(QListViewItem*);
+ void slotAvailableSelected(QListBoxItem*);
+ void slotSelectedSelected(QListBoxItem*);
+ void slotOk();
+
+private:
+ QLineEdit *m_description;
+ QLabel *m_idname;
+ QComboBox *m_mimetype;
+ KListBox *m_availablemime, *m_selectedmime;
+ QToolButton *m_addmime, *m_removemime;
+ KListView *m_requirements;
+ QToolButton *m_removereq, *m_addreq;
+
+ QStringList m_mimelist;
+ KXmlCommand *m_cmd;
+};
+
+#endif
diff --git a/kdeprint/management/kxmlcommandselector.cpp b/kdeprint/management/kxmlcommandselector.cpp
new file mode 100644
index 000000000..f0363e0b6
--- /dev/null
+++ b/kdeprint/management/kxmlcommandselector.cpp
@@ -0,0 +1,285 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kxmlcommandselector.h"
+#include "kxmlcommand.h"
+#include "kxmlcommanddlg.h"
+#include "kdeprintcheck.h"
+
+#include <qcombobox.h>
+#include <kpushbutton.h>
+#include <qlabel.h>
+#include <qcheckbox.h>
+#include <qlayout.h>
+#include <qtooltip.h>
+#include <qlineedit.h>
+#include <kinputdialog.h>
+#include <klocale.h>
+#include <kiconloader.h>
+#include <kmessagebox.h>
+#include <kfiledialog.h>
+#include <kseparator.h>
+#include <kguiitem.h>
+#include <kactivelabel.h>
+#include <kdatetbl.h>
+#include <kdialogbase.h>
+
+KXmlCommandSelector::KXmlCommandSelector(bool canBeNull, QWidget *parent, const char *name, KDialogBase *dlg)
+: QWidget(parent, name)
+{
+ m_cmd = new QComboBox(this);
+ connect(m_cmd, SIGNAL(activated(int)), SLOT(slotCommandSelected(int)));
+ QPushButton *m_add = new KPushButton(this);
+ QPushButton *m_edit = new KPushButton(this);
+ m_add->setPixmap(SmallIcon("filenew"));
+ m_edit->setPixmap(SmallIcon("configure"));
+ connect(m_add, SIGNAL(clicked()), SLOT(slotAddCommand()));
+ connect(m_edit, SIGNAL(clicked()), SLOT(slotEditCommand()));
+ QToolTip::add(m_add, i18n("New command"));
+ QToolTip::add(m_edit, i18n("Edit command"));
+ m_shortinfo = new QLabel(this);
+ m_helpbtn = new KPushButton( this );
+ m_helpbtn->setIconSet( SmallIconSet( "help" ) );
+ connect( m_helpbtn, SIGNAL( clicked() ), SLOT( slotHelpCommand() ) );
+ QToolTip::add( m_helpbtn, i18n( "Information" ) );
+ m_helpbtn->setEnabled( false );
+
+ m_line = 0;
+ m_usefilter = 0;
+ QPushButton *m_browse = 0;
+
+ QVBoxLayout *l0 = new QVBoxLayout(this, 0, 10);
+
+ if (canBeNull)
+ {
+ m_line = new QLineEdit(this);
+ m_browse = new KPushButton(KGuiItem(i18n("&Browse..."), "fileopen"), this);
+ m_usefilter = new QCheckBox(i18n("Use co&mmand:"), this);
+ connect(m_browse, SIGNAL(clicked()), SLOT(slotBrowse()));
+ connect(m_usefilter, SIGNAL(toggled(bool)), m_line, SLOT(setDisabled(bool)));
+ connect(m_usefilter, SIGNAL(toggled(bool)), m_browse, SLOT(setDisabled(bool)));
+ connect(m_usefilter, SIGNAL(toggled(bool)), m_cmd, SLOT(setEnabled(bool)));
+ connect(m_usefilter, SIGNAL(toggled(bool)), m_add, SLOT(setEnabled(bool)));
+ connect(m_usefilter, SIGNAL(toggled(bool)), m_edit, SLOT(setEnabled(bool)));
+ connect(m_usefilter, SIGNAL(toggled(bool)), m_shortinfo, SLOT(setEnabled(bool)));
+ connect( m_usefilter, SIGNAL( toggled( bool ) ), SLOT( slotXmlCommandToggled( bool ) ) );
+ m_usefilter->setChecked(true);
+ m_usefilter->setChecked(false);
+ //setFocusProxy(m_line);
+ setTabOrder(m_usefilter, m_cmd);
+ setTabOrder(m_cmd, m_add);
+ setTabOrder(m_add, m_edit);
+
+ QHBoxLayout *l1 = new QHBoxLayout(0, 0, 10);
+ l0->addLayout(l1);
+ l1->addWidget(m_line);
+ l1->addWidget(m_browse);
+
+ KSeparator *sep = new KSeparator(Qt::Horizontal, this);
+ l0->addWidget(sep);
+ }
+ else
+ setFocusProxy(m_cmd);
+
+ QGridLayout *l2 = new QGridLayout(0, 2, (m_usefilter?3:2), 0, 5);
+ int c(0);
+ l0->addLayout(l2);
+ if (m_usefilter)
+ {
+ l2->addWidget(m_usefilter, 0, c++);
+ }
+ l2->addWidget(m_cmd, 0, c);
+ QHBoxLayout *l4 = new QHBoxLayout( 0, 0, 5 );
+ l2->addLayout( l4, 1, c );
+ l4->addWidget( m_helpbtn, 0 );
+ l4->addWidget( m_shortinfo, 1 );
+ QHBoxLayout *l3 = new QHBoxLayout(0, 0, 0);
+ l2->addLayout(l3, 0, c+1);
+ l3->addWidget(m_add);
+ l3->addWidget(m_edit);
+
+ if ( dlg )
+ connect( this, SIGNAL( commandValid( bool ) ), dlg, SLOT( enableButtonOK( bool ) ) );
+
+ loadCommands();
+}
+
+void KXmlCommandSelector::loadCommands()
+{
+ QString thisCmd = (m_cmd->currentItem() != -1 ? m_cmdlist[m_cmd->currentItem()] : QString::null);
+
+ m_cmd->clear();
+ m_cmdlist.clear();
+
+ QStringList list = KXmlCommandManager::self()->commandListWithDescription();
+ QStringList desclist;
+ for (QStringList::Iterator it=list.begin(); it!=list.end(); ++it)
+ {
+ m_cmdlist << (*it);
+ ++it;
+ desclist << (*it);
+ }
+ m_cmd->insertStringList(desclist);
+
+ int index = m_cmdlist.findIndex(thisCmd);
+ if (index != -1)
+ m_cmd->setCurrentItem(index);
+ if (m_cmd->currentItem() != -1 && m_cmd->isEnabled())
+ slotCommandSelected(m_cmd->currentItem());
+}
+
+QString KXmlCommandSelector::command() const
+{
+ QString cmd;
+ if (m_line && !m_usefilter->isChecked())
+ cmd = m_line->text();
+ else
+ cmd = m_cmdlist[m_cmd->currentItem()];
+ return cmd;
+}
+
+void KXmlCommandSelector::setCommand(const QString& cmd)
+{
+ int index = m_cmdlist.findIndex(cmd);
+
+ if (m_usefilter)
+ m_usefilter->setChecked(index != -1);
+ if (m_line)
+ m_line->setText((index == -1 ? cmd : QString::null));
+ if (index != -1)
+ m_cmd->setCurrentItem(index);
+ if (m_cmd->currentItem() != -1 && m_cmd->isEnabled())
+ slotCommandSelected(m_cmd->currentItem());
+}
+
+void KXmlCommandSelector::slotAddCommand()
+{
+ bool ok(false);
+ QString cmdId = KInputDialog::getText(i18n("Command Name"), i18n("Enter an identification name for the new command:"), QString::null, &ok, this);
+ if (ok)
+ {
+ bool added(true);
+
+ if (m_cmdlist.findIndex(cmdId) != -1)
+ {
+ if (KMessageBox::warningContinueCancel(
+ this,
+ i18n("A command named %1 already exists. Do you want "
+ "to continue and edit the existing one?").arg(cmdId),
+ QString::null,
+ KStdGuiItem::cont()) == KMessageBox::Cancel)
+ {
+ return;
+ }
+ else
+ added = false;
+ }
+
+ KXmlCommand *xmlCmd = KXmlCommandManager::self()->loadCommand(cmdId);
+ if (KXmlCommandDlg::editCommand(xmlCmd, this))
+ KXmlCommandManager::self()->saveCommand(xmlCmd);
+
+ if (added)
+ loadCommands();
+ }
+}
+
+void KXmlCommandSelector::slotEditCommand()
+{
+ QString xmlId = m_cmdlist[m_cmd->currentItem()];
+ KXmlCommand *xmlCmd = KXmlCommandManager::self()->loadCommand(xmlId);
+ if (xmlCmd)
+ {
+ if (KXmlCommandDlg::editCommand(xmlCmd, this))
+ {
+ // force to load the driver if not already done
+ xmlCmd->driver();
+ KXmlCommandManager::self()->saveCommand(xmlCmd);
+ }
+ m_cmd->changeItem(xmlCmd->description(), m_cmd->currentItem());
+ delete xmlCmd;
+ slotCommandSelected(m_cmd->currentItem());
+ }
+ else
+ KMessageBox::error(this, i18n("Internal error. The XML driver for the command %1 could not be found.").arg(xmlId));
+}
+
+void KXmlCommandSelector::slotBrowse()
+{
+ QString filename = KFileDialog::getOpenFileName(QString::null, QString::null, this);
+ if (!filename.isEmpty() && m_line)
+ m_line->setText(filename);
+}
+
+void KXmlCommandSelector::slotCommandSelected(int ID)
+{
+ KXmlCommand *xmlCmd = KXmlCommandManager::self()->loadCommand(m_cmdlist[ID], true);
+ if (xmlCmd)
+ {
+ QString msg;
+ if ( xmlCmd->isValid() && KdeprintChecker::check( xmlCmd->requirements() ) )
+ {
+ msg = QString::fromLocal8Bit("(ID = %1, %2 = ").arg(xmlCmd->name()).arg(i18n("output"));
+ if (KXmlCommandManager::self()->checkCommand(xmlCmd->name(), KXmlCommandManager::None, KXmlCommandManager::Basic))
+ {
+ if (xmlCmd->mimeType() == "all/all")
+ msg.append(i18n("undefined"));
+ else
+ msg.append(xmlCmd->mimeType());
+ }
+ else
+ msg.append(i18n("not allowed"));
+ msg.append(")");
+ emit commandValid( true );
+ }
+ else
+ {
+ msg = "<font color=\"red\">" + i18n( "(Unavailable: requirements not satisfied)" ) + "</font>";
+ emit commandValid( false );
+ }
+ m_shortinfo->setText(msg);
+ m_help = xmlCmd->comment();
+ m_helpbtn->setEnabled( !m_help.isEmpty() );
+ }
+ delete xmlCmd;
+}
+
+void KXmlCommandSelector::slotXmlCommandToggled( bool on )
+{
+ if ( on )
+ slotCommandSelected( m_cmd->currentItem() );
+ else
+ {
+ emit commandValid( true );
+ m_shortinfo->setText( QString::null );
+ }
+}
+
+void KXmlCommandSelector::slotHelpCommand()
+{
+ KPopupFrame *pop = new KPopupFrame( m_helpbtn );
+ KActiveLabel *lab = new KActiveLabel( m_help, pop );
+ lab->resize( lab->sizeHint() );
+ pop->setMainWidget( lab );
+ pop->exec( m_helpbtn->mapToGlobal( QPoint( m_helpbtn->width(), 0 ) ) );
+ pop->close( 0 );
+ delete pop;
+}
+
+#include "kxmlcommandselector.moc"
diff --git a/kdeprint/management/kxmlcommandselector.h b/kdeprint/management/kxmlcommandselector.h
new file mode 100644
index 000000000..b0d67284e
--- /dev/null
+++ b/kdeprint/management/kxmlcommandselector.h
@@ -0,0 +1,68 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KXMLCOMMANDSELECTOR_H
+#define KXMLCOMMANDSELECTOR_H
+
+#include <qwidget.h>
+#include <qstringlist.h>
+
+#include <kdelibs_export.h>
+
+class QComboBox;
+class QLineEdit;
+class QCheckBox;
+class QLabel;
+class QPushButton;
+class KDialogBase;
+
+class KDEPRINT_EXPORT KXmlCommandSelector : public QWidget
+{
+ Q_OBJECT
+public:
+ KXmlCommandSelector(bool canBeNull = true, QWidget *parent = 0, const char *name = 0, KDialogBase *dlg = 0);
+
+ void setCommand(const QString&);
+ QString command() const;
+
+protected:
+ void loadCommands();
+
+protected slots:
+ void slotAddCommand();
+ void slotEditCommand();
+ void slotBrowse();
+ void slotCommandSelected(int);
+ void slotHelpCommand();
+ void slotXmlCommandToggled( bool );
+
+signals:
+ void commandValid( bool );
+
+private:
+ QComboBox *m_cmd;
+ QLineEdit *m_line;
+ QCheckBox *m_usefilter;
+ QStringList m_cmdlist;
+ QLabel *m_shortinfo;
+ QPushButton *m_helpbtn;
+ QString m_help;
+};
+
+#endif
diff --git a/kdeprint/management/networkscanner.cpp b/kdeprint/management/networkscanner.cpp
new file mode 100644
index 000000000..ae99c4fa4
--- /dev/null
+++ b/kdeprint/management/networkscanner.cpp
@@ -0,0 +1,421 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001-2002 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#define USE_QSOCKET
+
+#include "networkscanner.h"
+
+#include <qprogressbar.h>
+#include <kpushbutton.h>
+#include <qlayout.h>
+#include <qtimer.h>
+#include <qlabel.h>
+#include <qcombobox.h>
+#include <qlineedit.h>
+#include <qregexp.h>
+#include <qsocket.h>
+#include <klocale.h>
+#include <kextendedsocket.h>
+#include <kmessagebox.h>
+#include <knumvalidator.h>
+#include <kdebug.h>
+#include <unistd.h>
+
+class NetworkScanner::NetworkScannerPrivate
+{
+public:
+ int port;
+ QString prefixaddress;
+ int currentaddress;
+ int timeout;
+ bool scanning;
+ QPtrList<NetworkScanner::SocketInfo> printers;
+
+ QProgressBar *bar;
+ KPushButton *scan, *settings;
+ QLabel *subnetlab;
+ QTimer *timer;
+#ifdef USE_QSOCKET
+ QSocket *socket;
+#else
+ KExtendedSocket *socket;
+#endif
+
+ NetworkScannerPrivate( int portvalue ) : port( portvalue )
+ {
+ prefixaddress = localPrefix();
+ currentaddress = 1;
+ timeout = 50;
+ scanning = false;
+ printers.setAutoDelete( true );
+ }
+ QString localPrefix();
+ QString scanString();
+};
+
+QString NetworkScanner::NetworkScannerPrivate::localPrefix()
+{
+ char buf[256];
+ buf[0] = '\0';
+ if (!gethostname(buf, sizeof(buf)))
+ buf[sizeof(buf)-1] = '\0';
+ QPtrList<KAddressInfo> infos = KExtendedSocket::lookup(buf, QString::null);
+ infos.setAutoDelete(true);
+ if (infos.count() > 0)
+ {
+ QString IPstr = infos.first()->address()->nodeName();
+ int p = IPstr.findRev('.');
+ IPstr.truncate(p);
+ return IPstr;
+ }
+ return QString::null;
+}
+
+QString NetworkScanner::NetworkScannerPrivate::scanString()
+{
+ QString s = prefixaddress + ".*";
+ if ( port != -1 )
+ s.append( ":" ).append( QString::number( port ) );
+ return s;
+}
+
+NetworkScanner::NetworkScanner( int port, QWidget *parent, const char *name )
+ : QWidget( parent, name )
+{
+ d = new NetworkScannerPrivate( port );
+ d->bar = new QProgressBar( 256, this );
+ d->settings = new KPushButton( KGuiItem( i18n( "&Settings" ), "configure" ), this );
+ d->scan = new KPushButton( KGuiItem( i18n( "Sc&an" ), "viewmag" ), this );
+ d->timer = new QTimer( this );
+#ifdef USE_QSOCKET
+ d->socket = new QSocket( this );
+#else
+ d->socket = new KExtendedSocket();
+#endif
+ QLabel *label = new QLabel( i18n( "Network scan:" ), this );
+ d->subnetlab = new QLabel( i18n( "Subnet: %1" ).arg( d->scanString() ), this );
+
+ QGridLayout *l0 = new QGridLayout( this, 4, 2, 0, 10 );
+ l0->addMultiCellWidget( label, 0, 0, 0, 1 );
+ l0->addMultiCellWidget( d->bar, 1, 1, 0, 1 );
+ l0->addMultiCellWidget( d->subnetlab, 2, 2, 0, 1 );
+ l0->addWidget( d->settings, 3, 0 );
+ l0->addWidget( d->scan, 3, 1 );
+
+ connect( d->timer, SIGNAL( timeout() ), SLOT( slotTimeout() ) );
+ connect( d->settings, SIGNAL( clicked() ), SLOT( slotSettingsClicked() ) );
+ connect( d->scan, SIGNAL( clicked() ), SLOT( slotScanClicked() ) );
+#ifdef USE_QSOCKET
+ connect( d->socket, SIGNAL( connected() ), SLOT( slotConnectionSuccess() ) );
+ connect( d->socket, SIGNAL( error( int ) ), SLOT( slotConnectionFailed( int ) ) );
+#else
+ connect( d->socket, SIGNAL( connectionSuccess() ), SLOT( slotConnectionSuccess() ) );
+ connect( d->socket, SIGNAL( connectionFailed( int ) ), SLOT( slotConnectionFailed( int ) ) );
+#endif
+}
+
+NetworkScanner::~NetworkScanner()
+{
+#ifndef USE_QSOCKET
+ delete d->socket;
+#endif
+ delete d;
+}
+
+void NetworkScanner::start()
+{
+ if ( d->scanning )
+ return;
+
+ d->printers.clear();
+ emit scanStarted();
+ d->settings->setEnabled( false );
+ d->scan->setGuiItem( KGuiItem( i18n( "&Abort" ), "stop" ) );
+ d->currentaddress = -1;
+ d->scanning = true;
+ next();
+}
+
+void NetworkScanner::slotScanClicked()
+{
+ if ( !d->scanning )
+ {
+ if ( d->localPrefix() == d->prefixaddress ||
+ KMessageBox::warningContinueCancel( this->parentWidget(),
+ i18n( "You are about to scan a subnet (%1.*) that does not "
+ "correspond to the current subnet of this computer (%2.*). Do you want "
+ "to scan the specified subnet anyway?" ).arg( d->prefixaddress ).arg( d->localPrefix() ),
+ QString::null, KGuiItem( i18n( "&Scan" ), "viewmag" ), "askForScan" ) == KMessageBox::Continue )
+ start();
+ }
+ else
+ {
+#ifdef USE_QSOCKET
+ d->socket->close();
+#else
+ d->socket->cancelAsyncConnect();
+#endif
+ finish();
+ }
+}
+
+void NetworkScanner::finish()
+{
+ if ( !d->scanning )
+ return;
+
+ d->settings->setEnabled( true );
+ d->scan->setGuiItem( KGuiItem( i18n( "Sc&an" ), "viewmag" ) );
+ d->bar->reset();
+ d->scanning = false;
+ emit scanFinished();
+}
+
+void NetworkScanner::slotSettingsClicked()
+{
+ NetworkScannerConfig dlg( this );
+ dlg.exec();
+}
+
+void NetworkScanner::slotNext()
+{
+ if ( !d->scanning )
+ return;
+
+ d->timer->stop();
+#ifdef USE_QSOCKET
+ d->socket->connectToHost( d->prefixaddress + "." + QString::number( d->currentaddress ), d->port );
+ kdDebug() << "Address: " << d->socket->peerName() << ", Port: " << d->socket->peerPort() << endl;
+#else
+ d->socket->setAddress( d->prefixaddress + "." + QString::number( d->currentaddress ), d->port );
+ d->socket->startAsyncLookup();
+ kdDebug() << "Address: " << d->socket->host() << ", Port: " << d->socket->port() << endl;
+#endif
+ d->timer->start( d->timeout, true );
+}
+
+void NetworkScanner::next()
+{
+ //kdDebug() << "Next" << endl;
+ d->currentaddress++;
+ if ( d->currentaddress >= 256 )
+ finish();
+ else
+ {
+ d->bar->setProgress( d->currentaddress );
+ QTimer::singleShot( 0, this, SLOT( slotNext() ) );
+ }
+}
+
+void NetworkScanner::slotTimeout()
+{
+ kdDebug() << "Timeout" << endl;
+ if ( !d->scanning )
+ return;
+
+#ifdef USE_QSOCKET
+ d->socket->close();
+#else
+ d->socket->cancelAsyncConnect();
+#endif
+ next();
+}
+
+void NetworkScanner::slotConnectionSuccess()
+{
+ kdDebug() << "Success" << endl;
+#ifdef USE_QSOCKET
+ KSocketAddress *addr = KExtendedSocket::peerAddress( d->socket->socket() );
+#else
+ KSocketAddress *addr = const_cast<KSocketAddress*>( d->socket->peerAddress() );
+#endif
+ kdDebug() << "Connection success: " << ( addr ? addr->pretty() : QString( "ERROR" ) ) << endl;
+ kdDebug() << "Socket: " << d->socket->socket() << endl;
+ if ( addr )
+ {
+ SocketInfo *info = new SocketInfo;
+#ifdef USE_QSOCKET
+ info->IP = d->socket->peerName();
+#else
+ info->IP = d->socket->host();
+#endif
+ info->Port = d->port;
+ QString portname;
+ KExtendedSocket::resolve( addr, info->Name, portname );
+ d->printers.append( info );
+ d->socket->close();
+ delete addr;
+ }
+ else
+ kdDebug() << "Unconnected socket, skipping" << endl;
+ next();
+}
+
+void NetworkScanner::slotConnectionFailed( int )
+{
+ kdDebug() << "Failure" << endl;
+ next();
+}
+
+const QPtrList<NetworkScanner::SocketInfo>* NetworkScanner::printerList()
+{
+ return &( d->printers );
+}
+
+int NetworkScanner::timeout() const
+{
+ return d->timeout;
+}
+
+void NetworkScanner::setTimeout( int to )
+{
+ d->timeout = to;
+}
+
+QString NetworkScanner::subnet() const
+{
+ return d->prefixaddress;
+}
+
+void NetworkScanner::setSubnet( const QString& sn )
+{
+ d->prefixaddress = sn;
+ d->subnetlab->setText( i18n( "Subnet: %1" ).arg( d->scanString() ) );
+}
+
+int NetworkScanner::port() const
+{
+ return d->port;
+}
+
+void NetworkScanner::setPort( int p )
+{
+ d->port = p;
+ d->subnetlab->setText( i18n( "Subnet: %1" ).arg( d->scanString() ) );
+}
+
+bool NetworkScanner::checkPrinter( const QString& host, int port )
+{
+ // try first to find it in the SocketInfo list
+ QPtrListIterator<NetworkScanner::SocketInfo> it( d->printers );
+ for ( ; it.current(); ++it )
+ {
+ if ( port == it.current()->Port && ( host == it.current()->IP ||
+ host == it.current()->Name ) )
+ return true;
+ }
+
+ // not found in SocketInfo list, try to establish connection
+ KExtendedSocket extsock( host, port );
+ extsock.setBlockingMode( false );
+ extsock.setTimeout( 0, d->timeout * 1000 );
+ return ( extsock.connect() == 0 );
+}
+
+NetworkScannerConfig::NetworkScannerConfig(NetworkScanner *scanner, const char *name)
+ : KDialogBase(scanner, name, true, QString::null, Ok|Cancel, Ok, true)
+{
+ scanner_ = scanner;
+ QWidget *dummy = new QWidget(this);
+ setMainWidget(dummy);
+ KIntValidator *val = new KIntValidator( this );
+ QLabel *masklabel = new QLabel(i18n("&Subnetwork:"),dummy);
+ QLabel *portlabel = new QLabel(i18n("&Port:"),dummy);
+ QLabel *toutlabel = new QLabel(i18n("&Timeout (ms):"),dummy);
+ QLineEdit *mm = new QLineEdit(dummy);
+ mm->setText(QString::fromLatin1(".[0-255]"));
+ mm->setReadOnly(true);
+ mm->setFixedWidth(fontMetrics().width(mm->text())+10);
+
+ mask_ = new QLineEdit(dummy);
+ mask_->setAlignment(Qt::AlignRight);
+ port_ = new QComboBox(true,dummy);
+ if ( port_->lineEdit() )
+ port_->lineEdit()->setValidator( val );
+ tout_ = new QLineEdit(dummy);
+ tout_->setValidator( val );
+
+ masklabel->setBuddy(mask_);
+ portlabel->setBuddy(port_);
+ toutlabel->setBuddy(tout_);
+
+ mask_->setText(scanner_->subnet());
+ port_->insertItem("631");
+ port_->insertItem("9100");
+ port_->insertItem("9101");
+ port_->insertItem("9102");
+ port_->setEditText(QString::number(scanner_->port()));
+ tout_->setText(QString::number(scanner_->timeout()));
+
+ QGridLayout *main_ = new QGridLayout(dummy, 3, 2, 0, 10);
+ QHBoxLayout *lay1 = new QHBoxLayout(0, 0, 5);
+ main_->addWidget(masklabel, 0, 0);
+ main_->addWidget(portlabel, 1, 0);
+ main_->addWidget(toutlabel, 2, 0);
+ main_->addLayout(lay1, 0, 1);
+ main_->addWidget(port_, 1, 1);
+ main_->addWidget(tout_, 2, 1);
+ lay1->addWidget(mask_,1);
+ lay1->addWidget(mm,0);
+
+ resize(250,130);
+ setCaption(i18n("Scan Configuration"));
+}
+
+NetworkScannerConfig::~NetworkScannerConfig()
+{
+}
+
+void NetworkScannerConfig::slotOk()
+{
+ QString msg;
+ QRegExp re("(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})");
+ if (!re.exactMatch(mask_->text()))
+ msg = i18n("Wrong subnetwork specification.");
+ else
+ {
+ for (int i=1; i<=3; i++)
+ if (re.cap(i).toInt() >= 255)
+ {
+ msg = i18n("Wrong subnetwork specification.");
+ break;
+ }
+ }
+
+ bool ok(false);
+ int v = tout_->text().toInt(&ok);
+ if (!ok || v <= 0)
+ msg = i18n("Wrong timeout specification.");
+ v = port_->currentText().toInt(&ok);
+ if (!ok || v <= 0)
+ msg = i18n("Wrong port specification.");
+ if (!msg.isEmpty())
+ {
+ KMessageBox::error(this,msg);
+ return;
+ }
+
+ scanner_->setTimeout( tout_->text().toInt() );
+ scanner_->setSubnet( mask_->text() );
+ scanner_->setPort( port_->currentText().toInt() );
+
+ KDialogBase::slotOk();
+}
+
+#include "networkscanner.moc"
diff --git a/kdeprint/management/networkscanner.h b/kdeprint/management/networkscanner.h
new file mode 100644
index 000000000..2877a7596
--- /dev/null
+++ b/kdeprint/management/networkscanner.h
@@ -0,0 +1,95 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001-2002 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef NETWORKSCANNER_H
+#define NETWORKSCANNER_H
+
+#include <qwidget.h>
+#include <kdialogbase.h>
+#include <qptrlist.h>
+
+
+class KDEPRINT_EXPORT NetworkScanner : public QWidget
+{
+ Q_OBJECT
+
+public:
+ NetworkScanner( int port = 9100, QWidget *parent = 0, const char *name = 0 );
+ ~NetworkScanner();
+
+ struct SocketInfo
+ {
+ QString IP;
+ QString Name;
+ int Port;
+ };
+
+ const QPtrList<NetworkScanner::SocketInfo>* printerList();
+
+ int timeout() const;
+ void setTimeout( int to );
+ QString subnet() const;
+ void setSubnet( const QString& );
+ int port() const;
+ void setPort( int );
+ bool checkPrinter( const QString&, int );
+
+signals:
+ void scanStarted();
+ void scanFinished();
+
+protected slots:
+ void slotConnectionSuccess();
+ void slotConnectionFailed( int );
+ void slotTimeout();
+ void slotScanClicked();
+ void slotSettingsClicked();
+ void slotNext();
+
+protected:
+ void next();
+ void finish();
+ void start();
+
+private:
+ class NetworkScannerPrivate;
+ NetworkScannerPrivate *d;
+};
+
+class QLineEdit;
+class QComboBox;
+
+class NetworkScannerConfig : public KDialogBase
+{
+ Q_OBJECT
+
+public:
+ NetworkScannerConfig(NetworkScanner *scanner, const char *name = 0);
+ ~NetworkScannerConfig();
+
+protected slots:
+ void slotOk();
+
+private:
+ QLineEdit *mask_, *tout_;
+ QComboBox *port_;
+ NetworkScanner *scanner_;
+};
+
+#endif
diff --git a/kdeprint/management/pluginaction.cpp b/kdeprint/management/pluginaction.cpp
new file mode 100644
index 000000000..e03f8c4da
--- /dev/null
+++ b/kdeprint/management/pluginaction.cpp
@@ -0,0 +1,34 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "pluginaction.h"
+
+// automatically connect to "pluginActionActived(int)" in the receiver.
+PluginAction::PluginAction(int ID, const QString& txt, const QString& icon, int accel, QObject *parent, const char *name)
+: KAction(txt, icon, accel, parent, name), m_id(ID)
+{
+ connect(this, SIGNAL(activated()), SLOT(slotActivated()));
+}
+
+void PluginAction::slotActivated()
+{
+ emit activated(m_id);
+}
+
+#include "pluginaction.moc"
diff --git a/kdeprint/management/pluginaction.h b/kdeprint/management/pluginaction.h
new file mode 100644
index 000000000..f0addad4b
--- /dev/null
+++ b/kdeprint/management/pluginaction.h
@@ -0,0 +1,42 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef PLUGINACTION_H
+#define PLUGINACTION_H
+
+#include <kaction.h>
+
+class KDEPRINT_EXPORT PluginAction : public KAction
+{
+ Q_OBJECT
+
+public:
+ PluginAction(int ID, const QString& txt, const QString& icon, int accel, QObject *parent = 0, const char *name = 0);
+
+signals:
+ void activated(int);
+
+protected slots:
+ void slotActivated();
+
+private:
+ int m_id;
+};
+
+#endif
diff --git a/kdeprint/management/side.png b/kdeprint/management/side.png
new file mode 100644
index 000000000..f7e978d27
--- /dev/null
+++ b/kdeprint/management/side.png
Binary files differ
diff --git a/kdeprint/management/sidepixmap.cpp b/kdeprint/management/sidepixmap.cpp
new file mode 100644
index 000000000..6469b935d
--- /dev/null
+++ b/kdeprint/management/sidepixmap.cpp
@@ -0,0 +1,69 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "sidepixmap.h"
+
+#include <qpainter.h>
+#include <kstandarddirs.h>
+
+SidePixmap::SidePixmap(QWidget *parent, const char *name)
+: QFrame(parent, name)
+{
+ setLineWidth(1);
+ setFrameStyle(QFrame::WinPanel|QFrame::Sunken);
+
+ m_side.load(locate("data", "kdeprint/side.png"));
+ m_tileup.load(locate("data", "kdeprint/tileup.png"));
+ m_tiledown.load(locate("data", "kdeprint/tiledown.png"));
+
+ setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum));
+}
+
+bool SidePixmap::isValid()
+{
+ return (!m_side.isNull() && !m_tileup.isNull() && !m_tiledown.isNull()
+ && (m_side.width() == m_tileup.width())
+ && (m_side.width() == m_tiledown.width()));
+}
+
+QSize SidePixmap::sizeHint() const
+{
+ return (QSize(m_side.width()+lineWidth(), 300+lineWidth()));
+}
+
+void SidePixmap::drawContents(QPainter *p)
+{
+ QRect r = contentsRect();
+ if (r.height() <= m_side.height())
+ {
+ // case where the main pixmap is enough, just center it
+ int yoffset = (m_side.height()-r.height())/2;
+ p->drawPixmap(r.left(), r.top(), m_side, 0, yoffset, r.width(), r.height());
+ }
+ else
+ {
+ // we need to add tiled pixmap. Make sure we have a multiple
+ // of 3 in the space above to simplifu tiling.
+ int hh = (((r.height()-m_side.height())/2)/3)*3;
+ if (hh > 0)
+ p->drawTiledPixmap(r.left(), r.top(), r.width(), hh, m_tileup);
+ p->drawPixmap(r.left(), r.top()+hh, m_side);
+ p->drawTiledPixmap(r.left(), r.top()+m_side.height()+hh, r.width(), r.height()-m_side.height()-hh, m_tiledown);
+ }
+}
diff --git a/kdeprint/management/sidepixmap.h b/kdeprint/management/sidepixmap.h
new file mode 100644
index 000000000..48bfebf47
--- /dev/null
+++ b/kdeprint/management/sidepixmap.h
@@ -0,0 +1,42 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef SIDEPIXMAP_H
+#define SIDEPIXMAP_H
+
+#include <qframe.h>
+#include <qpixmap.h>
+
+#include <kdelibs_export.h>
+
+class KDEPRINT_EXPORT SidePixmap : public QFrame
+{
+public:
+ SidePixmap(QWidget *parent = 0, const char *name = 0);
+ QSize sizeHint() const;
+ bool isValid();
+
+protected:
+ void drawContents(QPainter*);
+
+private:
+ QPixmap m_side, m_tileup, m_tiledown;
+};
+
+#endif
diff --git a/kdeprint/management/smbview.cpp b/kdeprint/management/smbview.cpp
new file mode 100644
index 000000000..79e088209
--- /dev/null
+++ b/kdeprint/management/smbview.cpp
@@ -0,0 +1,284 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "smbview.h"
+
+#include <kprocess.h>
+#include <ktempfile.h>
+#include <qheader.h>
+#include <qapplication.h>
+
+#include <kiconloader.h>
+#include <klocale.h>
+#include <kdebug.h>
+#include <kmessagebox.h>
+#include <kcursor.h>
+
+#include <qfile.h>
+#include <qtextstream.h>
+#include <cstdlib>
+
+
+//*********************************************************************************************
+
+SmbView::SmbView(QWidget *parent, const char *name)
+: KListView(parent,name)
+{
+ addColumn(i18n("Printer"));
+ addColumn(i18n("Comment"));
+ setFrameStyle(QFrame::WinPanel|QFrame::Sunken);
+ setLineWidth(1);
+ setAllColumnsShowFocus(true);
+ setRootIsDecorated(true);
+
+ m_state = Idle;
+ m_current = 0;
+ m_proc = new KProcess();
+ m_proc->setUseShell(true);
+ m_passwdFile = 0;
+ connect(m_proc,SIGNAL(processExited(KProcess*)),SLOT(slotProcessExited(KProcess*)));
+ connect(m_proc,SIGNAL(receivedStdout(KProcess*,char*,int)),SLOT(slotReceivedStdout(KProcess*,char*,int)));
+ connect(this,SIGNAL(selectionChanged(QListViewItem*)),SLOT(slotSelectionChanged(QListViewItem*)));
+}
+
+SmbView::~SmbView()
+{
+ delete m_proc;
+ delete m_passwdFile;
+}
+
+void SmbView::setLoginInfos(const QString& login, const QString& password)
+{
+ m_login = login;
+ m_password = password;
+
+ // We can't pass the password via the command line or the environment
+ // because the command line is publically accessible on most OSes and
+ // the environment is publically accessible on some OSes.
+ // Therefor we write the password to a file and pass that file to
+ // smbclient with the -A option
+ delete m_passwdFile;
+ m_passwdFile = new KTempFile;
+ m_passwdFile->setAutoDelete(true);
+
+ QTextStream *passwdFile = m_passwdFile->textStream();
+ if (!passwdFile) return; // Error
+ (*passwdFile) << "username = " << m_login << endl;
+ (*passwdFile) << "password = " << m_password << endl;
+ // (*passwdFile) << "domain = " << ???? << endl;
+
+ m_passwdFile->close();
+}
+
+void SmbView::startProcess(int state)
+{
+ m_buffer = QString::null;
+ m_state = state;
+ QApplication::setOverrideCursor(KCursor::waitCursor());
+ m_proc->start(KProcess::NotifyOnExit,KProcess::Stdout);
+ emit running(true);
+}
+
+void SmbView::endProcess()
+{
+ switch (m_state)
+ {
+ case GroupListing:
+ processGroups();
+ break;
+ case ServerListing:
+ processServers();
+ break;
+ case ShareListing:
+ processShares();
+ break;
+ default:
+ break;
+ }
+ m_state = Idle;
+ QApplication::restoreOverrideCursor();
+ emit running(false);
+ // clean up for future usage
+ m_proc->clearArguments();
+}
+
+void SmbView::slotProcessExited(KProcess*)
+{
+ endProcess();
+}
+
+void SmbView::slotReceivedStdout(KProcess*, char *buf, int len)
+{
+ m_buffer.append(QString::fromLocal8Bit(buf,len));
+}
+
+void SmbView::init()
+{
+ // Open Samba configuration file and check if a WINS server is defined
+ m_wins_server = QString::null;
+ QString wins_keyword("wins server");
+ QFile smb_conf ("/etc/samba/smb.conf");
+ if (smb_conf.exists () && smb_conf.open (IO_ReadOnly))
+ {
+ QTextStream smb_stream (&smb_conf);
+ while (!smb_stream.atEnd ())
+ {
+ QString smb_line = smb_stream.readLine ();
+ if (smb_line.contains (wins_keyword, FALSE) > 0)
+ {
+ QString key = smb_line.section ('=', 0, 0);
+ key = key.stripWhiteSpace();
+ if (key.lower() == wins_keyword)
+ {
+ continue;
+ }
+ m_wins_server = smb_line.section ('=', 1, 1);
+ // take only the first declared WINS server
+ m_wins_server = m_wins_server.section(',', 0, 0);
+ m_wins_server = m_wins_server.stripWhiteSpace ();
+ m_wins_server = m_wins_server.section(' ', 0, 0);
+ // strip any server tag (see man smb.conf(5))
+ if (m_wins_server.section(':', 1, 1) != NULL)
+ {
+ m_wins_server = m_wins_server.section(':', 1, 1);
+ }
+ break;
+ }
+ }
+ smb_conf.close ();
+ }
+ m_wins_server = m_wins_server.isEmpty ()? " " : " -U " + m_wins_server + " ";
+ QString cmd ("nmblookup" + m_wins_server +
+ "-M -- - | grep '<01>' | awk '{print $1}' | xargs nmblookup -A | grep '<1d>'");
+ *m_proc << cmd;
+ startProcess(GroupListing);
+}
+
+void SmbView::setOpen(QListViewItem *item, bool on)
+{
+ if (on && item->childCount() == 0)
+ {
+ if (item->depth() == 0)
+ { // opening group
+ m_current = item;
+ *m_proc << "nmblookup"+m_wins_server+"-M ";
+ *m_proc << KProcess::quote(item->text(0));
+ *m_proc << " -S | grep '<20>' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*<20>.*//' | xargs -Iserv_name smbclient -N -L 'serv_name' -W ";
+ *m_proc << KProcess::quote(item->text(0));
+ *m_proc << " -A ";
+ *m_proc << KProcess::quote(m_passwdFile->name());
+ startProcess(ServerListing);
+ }
+ else if (item->depth() == 1)
+ { // opening server
+ m_current = item;
+ *m_proc << "smbclient -N -L ";
+ *m_proc << KProcess::quote(item->text(0));
+ *m_proc << " -W ";
+ *m_proc << KProcess::quote(item->parent()->text(0));
+ *m_proc << " -A ";
+ *m_proc << KProcess::quote(m_passwdFile->name());
+ startProcess(ShareListing);
+ }
+ }
+ QListView::setOpen(item,on);
+}
+
+void SmbView::processGroups()
+{
+ QStringList grps = QStringList::split('\n',m_buffer,false);
+ clear();
+ for (QStringList::ConstIterator it=grps.begin(); it!=grps.end(); ++it)
+ {
+ int p = (*it).find("<1d>");
+ if (p == -1)
+ continue;
+ QListViewItem *item = new QListViewItem(this,(*it).left(p).stripWhiteSpace());
+ item->setExpandable(true);
+ item->setPixmap(0,SmallIcon("network"));
+ }
+}
+
+void SmbView::processServers()
+{
+ QStringList lines = QStringList::split('\n',m_buffer,true);
+ QString line;
+ uint index(0);
+ for (;index < lines.count();index++)
+ if (lines[index].stripWhiteSpace().startsWith("Server"))
+ break;
+ index += 2;
+ while (index < lines.count())
+ {
+ line = lines[index++].stripWhiteSpace();
+ if (line.isEmpty())
+ break;
+ QStringList words = QStringList::split(' ',line,false);
+ QListViewItem *item = new QListViewItem(m_current,words[0]);
+ item->setExpandable(true);
+ item->setPixmap(0,SmallIcon("kdeprint_computer"));
+ }
+}
+
+void SmbView::processShares()
+{
+ QStringList lines = QStringList::split('\n',m_buffer,true);
+ QString line;
+ uint index(0);
+ for (;index < lines.count();index++)
+ if (lines[index].stripWhiteSpace().startsWith("Sharename"))
+ break;
+ index += 2;
+ while (index < lines.count())
+ {
+ line = lines[index++].stripWhiteSpace();
+ if (line.isEmpty())
+ break;
+ else if ( line.startsWith( "Error returning" ) )
+ {
+ KMessageBox::error( this, line );
+ break;
+ }
+ QString typestr(line.mid(15, 10).stripWhiteSpace());
+ //QStringList words = QStringList::split(' ',line,false);
+ //if (words[1] == "Printer")
+ if (typestr == "Printer")
+ {
+ QString comm(line.mid(25).stripWhiteSpace()), sharen(line.mid(0, 15).stripWhiteSpace());
+ //for (uint i=2; i<words.count(); i++)
+ // comm += (words[i]+" ");
+ //QListViewItem *item = new QListViewItem(m_current,words[0],comm);
+ QListViewItem *item = new QListViewItem(m_current,sharen,comm);
+ item->setPixmap(0,SmallIcon("kdeprint_printer"));
+ }
+ }
+}
+
+void SmbView::slotSelectionChanged(QListViewItem *item)
+{
+ if (item && item->depth() == 2)
+ emit printerSelected(item->parent()->parent()->text(0),item->parent()->text(0),item->text(0));
+}
+
+void SmbView::abort()
+{
+ if (m_proc->isRunning())
+ m_proc->kill();
+}
+#include "smbview.moc"
diff --git a/kdeprint/management/smbview.h b/kdeprint/management/smbview.h
new file mode 100644
index 000000000..74932a964
--- /dev/null
+++ b/kdeprint/management/smbview.h
@@ -0,0 +1,67 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef SMBVIEW_H
+#define SMBVIEW_H
+
+#include <klistview.h>
+
+class KProcess;
+class KTempFile;
+
+class SmbView : public KListView
+{
+ Q_OBJECT
+public:
+ SmbView(QWidget *parent = 0, const char *name = 0);
+ ~SmbView();
+
+ void setLoginInfos(const QString& login, const QString& password);
+ void setOpen(QListViewItem*, bool);
+ void init();
+ void abort();
+
+signals:
+ void printerSelected(const QString& work, const QString& server, const QString& printer);
+ void running(bool);
+
+protected:
+ void startProcess(int);
+ void endProcess();
+ void processGroups();
+ void processServers();
+ void processShares();
+
+protected slots:
+ void slotReceivedStdout(KProcess*, char*, int);
+ void slotProcessExited(KProcess*);
+ void slotSelectionChanged(QListViewItem*);
+
+private:
+ enum State { GroupListing, ServerListing, ShareListing, Idle };
+ int m_state;
+ QListViewItem *m_current;
+ KProcess *m_proc;
+ QString m_buffer;
+ QString m_login, m_password;
+ KTempFile *m_passwdFile;
+ QString m_wins_server;
+};
+
+#endif
diff --git a/kdeprint/management/tiledown.png b/kdeprint/management/tiledown.png
new file mode 100644
index 000000000..71af44b99
--- /dev/null
+++ b/kdeprint/management/tiledown.png
Binary files differ
diff --git a/kdeprint/management/tileup.png b/kdeprint/management/tileup.png
new file mode 100644
index 000000000..cf63939a3
--- /dev/null
+++ b/kdeprint/management/tileup.png
Binary files differ