1
////////////////////////////////////////////////////////////////////////////////
3
// This file is part of Toolkit for Conceptual Modeling (TCM).
4
// (c) copyright 1997, Vrije Universiteit Amsterdam.
5
// Author: Frank Dehne (frank@cs.vu.nl).
7
// TCM is free software; you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License as published by
9
// the Free Software Foundation; either version 2 of the License, or
10
// (at your option) any later version.
12
// TCM is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU General Public License for more details.
17
// You should have received a copy of the GNU General Public License
18
// along with TCM; if not, write to the Free Software
19
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21
////////////////////////////////////////////////////////////////////////////////
22
#include "printerqueuedialog.h"
23
#include "printeroptions.h"
24
#include "mainwindow.h"
25
#include "promptdialog.h"
26
#include "messagedialog.h"
33
PrinterQueueDialog::PrinterQueueDialog(Widget p, MainWindow *w):
35
SetAutoUnmanage(False);
37
promptDialog = new PromptDialog(mainwindow->GetWidget());
38
promptDialog->Initialize();
39
printerOptions = mainwindow->GetPrinterOptions();
41
defaultQueueCommand = "";
43
defaultRemoveCommand = "";
46
void PrinterQueueDialog::CreateWidget() {
47
// create the selection box dialog
48
Arg al[10]; int ac = 0;
49
XtSetArg(al[ac], XmNautoUnmanage, GetAutoUnmanage()); ac++;
50
XtSetArg(al[ac], XmNdefaultButtonType, XmDIALOG_APPLY_BUTTON); ac++;
51
XtSetArg(al[ac], XmNmustMatch, False); ac++;
52
SetWidget(XmCreateSelectionDialog(GetParent(), (char *)GetClassName(), al, ac));
55
void PrinterQueueDialog::Configure() {
56
SelectionDialog::Configure();
57
const char *selection =
58
"Update refreshes, Remove cancels selected item and"
59
" Dismiss deletes dialog.";
60
SetSelectionLabel(selection);
61
SetCancelButtonLabel("Dismiss");
62
SetOKButtonLabel("Update");
63
SetApplyButtonLabel("Remove");
64
SetApplyCallback(RemoveCB, this);
65
SetOKCallback(UpdateCB, this);
66
SetCancelCallback(UnmanageCB, this);
67
ManageHelpButton(False);
71
void PrinterQueueDialog::Update() {
72
mainwindow->SetCursor(MouseCursor::WATCH);
73
mainwindow->SetStatus("");
74
// Check if printer queue command exists.
75
if (!System::FileExists(queueCommand.getstr())) {
76
string txt = "The Unix program " + queueCommand +
78
(new MessageDialog(mainwindow->GetWidget(),
79
MessageDialog::ERROR))->
81
error("Error: could not open %s\n", queueCommand.getstr());
84
// establish a link to Unix printer queue with the link class.
85
// and place the strings from output into the selection box.
87
char s[MAXNAME], s2[MAXNAME];
88
if (!check(GetWidget()))
90
char command[MAXNAME];
91
string printerName = *printerOptions->GetPrinterName();
92
System::GiveFile(queueCommand.getstr(), command);
93
if (equal(command, "lpq"))
94
sprintf(s2, "-P%s", printerName.getstr());
95
else if (equal(command, "lpstat"))
96
sprintf(s2, "-o %s", printerName.getstr());
97
l.Open(queueCommand.getstr(), s2);
98
// l.Read(s); lose header line
99
// XmListDeleteAllItems(GetList());
103
// xs = CreateXmString(s);
104
// XmListAddItem(GetList(), xs, 0);
108
XtManageChild(GetWidget());
109
mainwindow->SetStatus("Update printer queue");
110
mainwindow->SetCursor(MouseCursor::LEFT_PTR);
113
void PrinterQueueDialog::Remove(const char *procstr) {
115
char rank[20], owner[64], job[20];
116
char removeProg[MAXNAME];
117
char queueProg[MAXNAME];
118
if (!System::FileExists(removeCommand.getstr())) {
119
string txt = "The Unix program " + removeCommand +
121
(new MessageDialog(mainwindow->GetWidget(),
122
MessageDialog::ERROR))->
124
error("Error: could not open %s\n", removeCommand.getstr());
127
System::GiveFile(removeCommand.getstr(), removeProg);
128
System::GiveFile(queueCommand.getstr(), queueProg);
129
// extract the job number from the line and remove that job number.
131
if (equal(queueProg, "lpq")) {
132
if (sscanf(procstr, "%s%s%s", rank, owner, job) != 3)
135
else if (equal(queueProg, "lpstat")) {
136
if (sscanf(procstr, "%*[^-]-%s%s", job, owner) != 2)
142
string printerName = *printerOptions->GetPrinterName();
143
if (equal(removeProg, "lprm")) {
144
sprintf(s, "%s -P%s %s 2>&1",
145
removeProg, printerName.getstr(), job);
147
else if (equal(removeProg, "cancel")) {
148
sprintf(s, "%s %s-%s 2>&1",
149
removeProg, printerName.getstr(), job);
152
string txt = "try to remove job '";
155
mainwindow->SetStatus(&txt);
158
mainwindow->SetStatus("nothing to be removed");
159
// make selection string empty.
164
void PrinterQueueDialog::PrinterQueueCommand() {
165
promptDialog->SetTitle("Printer queue command");
166
promptDialog->SetSelectionLabel("Printer queue command:");
167
promptDialog->SetTextString(&queueCommand);
168
promptDialog->SetOKCallback(SetPrinterQueueCommandCB, this);
169
promptDialog->SetDefaultValue(&defaultQueueCommand);
170
promptDialog->Popup();
173
void PrinterQueueDialog::PrinterRemoveCommand() {
174
promptDialog->SetTitle("Printer remove command");
175
promptDialog->SetSelectionLabel("Printer remove command:");
176
promptDialog->SetTextString(&removeCommand);
177
promptDialog->SetOKCallback(SetPrinterRemoveCommandCB, this);
178
promptDialog->SetDefaultValue(&defaultRemoveCommand);
179
promptDialog->Popup();
182
void PrinterQueueDialog::SetPrinterQueueCommand(const string *s) {
184
string txt = "printer queue command is " + queueCommand;
185
mainwindow->SetStatus(&txt);
188
void PrinterQueueDialog::SetPrinterRemoveCommand(const string *s) {
190
string txt = "printer remove command is " + removeCommand;
191
mainwindow->SetStatus(&txt);
194
void PrinterQueueDialog::RemoveCB(Widget, XtPointer client_data, XtPointer cbs){
195
XmSelectionBoxCallbackStruct *call_data =
196
(XmSelectionBoxCallbackStruct *)cbs;
197
PrinterQueueDialog *p = (PrinterQueueDialog *)client_data;
199
if (XmStringGetLtoR(call_data->value,XmFONTLIST_DEFAULT_TAG,&procstr)) {
205
void PrinterQueueDialog::UpdateCB(Widget, XtPointer client_data, XtPointer) {
206
PrinterQueueDialog *p = (PrinterQueueDialog *)client_data;
210
void PrinterQueueDialog::SetPrinterQueueCommandCB(Widget, XtPointer clientData,
212
PrinterQueueDialog *p = (PrinterQueueDialog *)clientData;
213
PromptDialog *dialog = p->GetPromptDialog();
215
dialog->GetTextString(&t);
216
p->SetPrinterQueueCommand(&t);
219
void PrinterQueueDialog::SetPrinterRemoveCommandCB(Widget,
220
XtPointer clientData, XtPointer) {
221
PrinterQueueDialog *p = (PrinterQueueDialog *)clientData;
222
PromptDialog *dialog = p->GetPromptDialog();
224
dialog->GetTextString(&t);
225
p->SetPrinterRemoveCommand(&t);