1 /* $TOG: DtPrtProps.C /main/4 1998/07/24 16:14:02 mgreess $ */
3 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
4 * (c) Copyright 1993, 1994 International Business Machines Corp. *
5 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
6 * (c) Copyright 1993, 1994 Novell, Inc. *
9 #include "DtPrtProps.h"
10 #include "DtFindSet.h"
12 #include "DtPrinterIcon.h"
14 #include "Container.h"
20 #include "Dt/Action.h"
22 #include "dtprintinfomsg.h"
25 #include <unistd.h> // This is for the getpid function
26 #include <stdlib.h> // This is for the getenv function
28 DtPrtProps::DtPrtProps(DtMainW *parent, char *name, DtPrinterIcon *_printer)
29 : Dialog(parent, name)
33 _iconFile = STRDUP(printer->IconFile());
35 _has_been_posted = false;
37 int i, captionWidth = 0, width, columns = 0;
38 int n_attributes = printer->QueueObj()->NumAttributes();
39 Attribute **attributes = printer->QueueObj()->Attributes();
40 if ((width = StringWidth(MESSAGE(IconLabelL))) > captionWidth)
42 if ((width = StringWidth(MESSAGE(IconGroupTitleL))) > captionWidth)
44 if ((width = StringWidth(MESSAGE(DescriptionL))) > captionWidth)
46 if ((width = strlen(printer->Name())) > columns)
48 for (i = 0; i < n_attributes; i++)
50 if ((width = StringWidth(attributes[i]->DisplayName)) > captionWidth)
52 if ((width = strlen(attributes[i]->DisplayValue)) > columns)
56 icon_prompt = new Prompt(this, MESSAGE(IconLabelL), true, STRING_PROMPT,
57 (char *)printer->Name(), NULL,
58 NULL, true, columns, 1, captionWidth + 8);
59 icon_prompt->AttachLeft();
60 icon_prompt->AttachRight();
61 icon_prompt->AttachTop(5);
63 Container *form = new Container(this, "form", FORM);
64 icon_group = new Group(form, NULL, FORM_BOX);
65 LabelObj *label = new LabelObj(form, MESSAGE(IconGroupTitleL),
68 label->AttachBottom();
70 label->Width(captionWidth + 8);
71 icon_group->AttachTop();
72 icon_group->AttachBottom();
73 icon_group->AttachRight();
74 icon_group->AttachLeft(label);
76 // Creation of Large Icon
77 largeIcon = new IconObj(icon_group, NULL, printer->IconFile());
78 largeIcon->IconView(VERY_LARGE_ICON);
79 largeIcon->AttachLeft(10);
80 largeIcon->AttachTop(10);
81 largeIcon->AttachBottom(10);
83 // Creation of Medium Icon
84 mediumIcon = new IconObj(icon_group, NULL, printer->IconFile());
85 mediumIcon->IconView(MEDIUM_ICON);
86 mediumIcon->AttachLeft(largeIcon, 10);
87 mediumIcon->AttachBottom(10);
89 // Creation of Small Icon
90 smallIcon = new IconObj(icon_group, NULL, printer->IconFile());
91 smallIcon->IconView(SMALL_ICON);
92 smallIcon->AttachLeft(mediumIcon, 10);
93 smallIcon->AttachBottom(10);
95 // Creation of Find Set Button
96 find_set = new Button(icon_group, MESSAGE(FindSetL), PUSH_BUTTON, FindSetCB,
99 find_set->AttachRight(10);
100 find_set->AttachLeft(smallIcon, 10);
101 find_set->AttachBottom(10);
105 form->AttachTop(icon_prompt, 5);
107 Container *rc = new Container(this, "rc", VERTICAL_ROW_COLUMN);
108 for (i = 0; i < n_attributes; i++)
110 new Prompt(rc, attributes[i]->DisplayName, false, STRING_PROMPT,
111 attributes[i]->DisplayValue, NULL,
112 NULL, true, columns, 1, captionWidth + 8);
113 if (mainw->PrinterAppMode() != CONFIG_PRINTERS)
117 value = _printer->PrintQueueUp() ? MESSAGE(UpL) : MESSAGE(DownL);
120 value = _printer->PrintDeviceUp(i - 1) ? MESSAGE(UpL) :
123 value = _printer->PrintDeviceUp() ? MESSAGE(UpL) : MESSAGE(DownL);
125 new Prompt(rc, MESSAGE(PrinterStatusL), false, STRING_PROMPT,
126 value, NULL, NULL, true, columns, 1, captionWidth + 8);
134 Sep *sep = new Sep(this);
137 sep->AttachBottom(rc, 5);
139 description = new Prompt(this, MESSAGE(DescriptionL), false,
140 MULTI_LINE_STRING_PROMPT, printer->Description(),
141 NULL, NULL, true, columns, 3, captionWidth + 8);
142 description->AttachLeft();
143 description->AttachRight();
144 description->AttachTop(form, 5);
145 description->AttachBottom(sep, 5);
147 ok = new Button(this, MESSAGE(OKL), PUSH_BUTTON, OkCB, this);
148 cancel = new Button(this, MESSAGE(CancelL), PUSH_BUTTON, CancelCB, this);
149 help = new Button(this, MESSAGE(HelpL), PUSH_BUTTON, HelpCB, this);
151 CancelButton(cancel);
154 DtPrtProps::~DtPrtProps()
159 boolean DtPrtProps::SetVisiblity(boolean flag)
161 Dialog::SetVisiblity(flag);
162 if (_has_been_posted == false)
164 _has_been_posted = true;
165 find_set->Height(find_set->Height() + 6);
172 void DtPrtProps::Reset()
174 if (strcmp(printer->IconFile(), _iconFile))
175 SetActionIcons(printer->IconFile());
176 icon_prompt->Value((char *)printer->Name());
177 description->Value(printer->Description());
180 void DtPrtProps::Apply()
184 char *iconName = (char *)IconLabel();
185 char *iconFile = (char *)IconFileName();
187 if (!iconName || *iconName == '\0')
188 iconName = (char *)printer->Name();
189 if (!iconFile || *iconFile == '\0')
190 iconFile = (char *)PRINTER_ICON_FILE;
192 if (!strcmp(iconName, printer->Name()) &&
193 !strcmp(iconFile, printer->IconFile()))
195 // return since nothing changed
199 char *save_msg = strdup(mainw->status_line->Name());
200 mainw->WorkingCursor(true);
201 mainw->status_line->Name(MESSAGE(UpdatingActionsL));
203 buf_len = strlen(printer->QueueObj()->Name()) +
204 (2 * strlen(printer->HomeDir())) + 50;
207 buf = new char [buf_len];
208 FILE *fp_src, *fp_dest;
209 char *filename = printer->CreateActionFile();
210 sprintf(buf, "%s.%ld", filename, (long)getpid());
211 if (fp_dest = fopen(buf, "w"))
213 if (fp_src = fopen(filename, "r"))
215 while (fgets(buf, buf_len, fp_src))
217 if (strstr(buf, "LABEL"))
218 fprintf(fp_dest, " LABEL %s\n",
220 else if (strstr(buf, "ICON"))
221 fprintf(fp_dest, " ICON %s\n",
224 fprintf(fp_dest, "%s", buf);
230 sprintf(buf, "%s.%ld", filename, (long)getpid());
231 rename(buf, filename);
232 DtActionInvoke(((AnyUI *)mainw->Parent())->BaseWidget(), "ReloadActions",
233 NULL, 0, NULL, NULL, NULL, True, NULL, NULL);
235 mainw->WorkingCursor(false);
236 mainw->status_line->Name(save_msg);
239 void DtPrtProps::CloseCB()
245 void DtPrtProps::OkCB(void *data)
247 DtPrtProps *obj = (DtPrtProps *) data;
253 void DtPrtProps::ApplyCB(void *data)
255 DtPrtProps *obj = (DtPrtProps *) data;
259 void DtPrtProps::CancelCB(void *data)
261 DtPrtProps *obj = (DtPrtProps *) data;
267 void DtPrtProps::ResetCB(void *data)
269 DtPrtProps *obj = (DtPrtProps *) data;
274 void DtPrtProps::HelpCB(void *data)
276 DtPrtProps *obj = (DtPrtProps *) data;
277 obj->HandleHelpRequest();
280 boolean DtPrtProps::HandleHelpRequest()
282 mainw->DisplayHelp((char *)PROPS_PRINTER_ID);
286 void DtPrtProps::SetActionIcons(const char *icon)
289 _iconFile = STRDUP(icon);
290 largeIcon->IconFile((char*)icon);
291 mediumIcon->IconFile((char*)icon);
292 smallIcon->IconFile((char*)icon);
295 void DtPrtProps::CallerCB(BaseUI *caller, char *iconFile)
297 DtPrtProps *obj = (DtPrtProps *)caller;
298 delete obj->_iconFile;
299 obj->_iconFile = STRDUP(iconFile);
300 obj->smallIcon->IconFile(iconFile);
301 obj->mediumIcon->IconFile(iconFile);
302 obj->largeIcon->IconFile(iconFile);
305 void DtPrtProps::FindSetCB(void *data)
307 DtPrtProps *obj = (DtPrtProps *)data;
308 if (!obj->mainw->findSetD)
310 char *name = new char [strlen(obj->mainw->Name()) +
311 strlen(MESSAGE(FindSetTitleL))];
312 sprintf(name, MESSAGE(FindSetTitleL), obj->mainw->Name());
313 obj->mainw->findSetD = new DtFindSet(obj->mainw, name,
314 &DtPrtProps::CallerCB);
317 obj->mainw->findSetD->Caller(obj);
318 obj->mainw->findSetD->Visible(true);