2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $TOG: DtPrtProps.C /main/4 1998/07/24 16:14:02 mgreess $ */
25 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
26 * (c) Copyright 1993, 1994 International Business Machines Corp. *
27 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
28 * (c) Copyright 1993, 1994 Novell, Inc. *
31 #include "DtPrtProps.h"
32 #include "DtFindSet.h"
34 #include "DtPrinterIcon.h"
36 #include "Container.h"
42 #include "Dt/Action.h"
44 #include "dtprintinfomsg.h"
47 #include <unistd.h> // This is for the getpid function
48 #include <stdlib.h> // This is for the getenv function
50 DtPrtProps::DtPrtProps(DtMainW *parent, char *name, DtPrinterIcon *_printer)
51 : Dialog(parent, name)
55 _iconFile = STRDUP(printer->IconFile());
57 _has_been_posted = false;
59 int i, captionWidth = 0, width, columns = 0;
60 int n_attributes = printer->QueueObj()->NumAttributes();
61 Attribute **attributes = printer->QueueObj()->Attributes();
62 if ((width = StringWidth(MESSAGE(IconLabelL))) > captionWidth)
64 if ((width = StringWidth(MESSAGE(IconGroupTitleL))) > captionWidth)
66 if ((width = StringWidth(MESSAGE(DescriptionL))) > captionWidth)
68 if ((width = strlen(printer->Name())) > columns)
70 for (i = 0; i < n_attributes; i++)
72 if ((width = StringWidth(attributes[i]->DisplayName)) > captionWidth)
74 if ((width = strlen(attributes[i]->DisplayValue)) > columns)
78 icon_prompt = new Prompt(this, MESSAGE(IconLabelL), true, STRING_PROMPT,
79 (char *)printer->Name(), NULL,
80 NULL, true, columns, 1, captionWidth + 8);
81 icon_prompt->AttachLeft();
82 icon_prompt->AttachRight();
83 icon_prompt->AttachTop(5);
85 Container *form = new Container(this, "form", FORM);
86 icon_group = new Group(form, NULL, FORM_BOX);
87 LabelObj *label = new LabelObj(form, MESSAGE(IconGroupTitleL),
90 label->AttachBottom();
92 label->Width(captionWidth + 8);
93 icon_group->AttachTop();
94 icon_group->AttachBottom();
95 icon_group->AttachRight();
96 icon_group->AttachLeft(label);
98 // Creation of Large Icon
99 largeIcon = new IconObj(icon_group, NULL, printer->IconFile());
100 largeIcon->IconView(VERY_LARGE_ICON);
101 largeIcon->AttachLeft(10);
102 largeIcon->AttachTop(10);
103 largeIcon->AttachBottom(10);
105 // Creation of Medium Icon
106 mediumIcon = new IconObj(icon_group, NULL, printer->IconFile());
107 mediumIcon->IconView(MEDIUM_ICON);
108 mediumIcon->AttachLeft(largeIcon, 10);
109 mediumIcon->AttachBottom(10);
111 // Creation of Small Icon
112 smallIcon = new IconObj(icon_group, NULL, printer->IconFile());
113 smallIcon->IconView(SMALL_ICON);
114 smallIcon->AttachLeft(mediumIcon, 10);
115 smallIcon->AttachBottom(10);
117 // Creation of Find Set Button
118 find_set = new Button(icon_group, MESSAGE(FindSetL), PUSH_BUTTON, FindSetCB,
121 find_set->AttachRight(10);
122 find_set->AttachLeft(smallIcon, 10);
123 find_set->AttachBottom(10);
127 form->AttachTop(icon_prompt, 5);
129 Container *rc = new Container(this, "rc", VERTICAL_ROW_COLUMN);
130 for (i = 0; i < n_attributes; i++)
132 new Prompt(rc, attributes[i]->DisplayName, false, STRING_PROMPT,
133 attributes[i]->DisplayValue, NULL,
134 NULL, true, columns, 1, captionWidth + 8);
135 if (mainw->PrinterAppMode() != CONFIG_PRINTERS)
139 value = _printer->PrintQueueUp() ? MESSAGE(UpL) : MESSAGE(DownL);
142 value = _printer->PrintDeviceUp(i - 1) ? MESSAGE(UpL) :
145 value = _printer->PrintDeviceUp() ? MESSAGE(UpL) : MESSAGE(DownL);
147 new Prompt(rc, MESSAGE(PrinterStatusL), false, STRING_PROMPT,
148 value, NULL, NULL, true, columns, 1, captionWidth + 8);
156 Sep *sep = new Sep(this);
159 sep->AttachBottom(rc, 5);
161 description = new Prompt(this, MESSAGE(DescriptionL), false,
162 MULTI_LINE_STRING_PROMPT, printer->Description(),
163 NULL, NULL, true, columns, 3, captionWidth + 8);
164 description->AttachLeft();
165 description->AttachRight();
166 description->AttachTop(form, 5);
167 description->AttachBottom(sep, 5);
169 ok = new Button(this, MESSAGE(OKL), PUSH_BUTTON, OkCB, this);
170 cancel = new Button(this, MESSAGE(CancelL), PUSH_BUTTON, CancelCB, this);
171 help = new Button(this, MESSAGE(HelpL), PUSH_BUTTON, HelpCB, this);
173 CancelButton(cancel);
176 DtPrtProps::~DtPrtProps()
181 boolean DtPrtProps::SetVisiblity(boolean flag)
183 Dialog::SetVisiblity(flag);
184 if (_has_been_posted == false)
186 _has_been_posted = true;
187 find_set->Height(find_set->Height() + 6);
194 void DtPrtProps::Reset()
196 if (strcmp(printer->IconFile(), _iconFile))
197 SetActionIcons(printer->IconFile());
198 icon_prompt->Value((char *)printer->Name());
199 description->Value(printer->Description());
202 void DtPrtProps::Apply()
206 char *iconName = (char *)IconLabel();
207 char *iconFile = (char *)IconFileName();
209 if (!iconName || *iconName == '\0')
210 iconName = (char *)printer->Name();
211 if (!iconFile || *iconFile == '\0')
212 iconFile = (char *)PRINTER_ICON_FILE;
214 if (!strcmp(iconName, printer->Name()) &&
215 !strcmp(iconFile, printer->IconFile()))
217 // return since nothing changed
221 char *save_msg = strdup(mainw->status_line->Name());
222 mainw->WorkingCursor(true);
223 mainw->status_line->Name(MESSAGE(UpdatingActionsL));
225 buf_len = strlen(printer->QueueObj()->Name()) +
226 (2 * strlen(printer->HomeDir())) + 50;
229 buf = new char [buf_len];
230 FILE *fp_src, *fp_dest;
231 char *filename = printer->CreateActionFile();
232 sprintf(buf, "%s.%ld", filename, (long)getpid());
233 if (fp_dest = fopen(buf, "w"))
235 if (fp_src = fopen(filename, "r"))
237 while (fgets(buf, buf_len, fp_src))
239 if (strstr(buf, "LABEL"))
240 fprintf(fp_dest, " LABEL %s\n",
242 else if (strstr(buf, "ICON"))
243 fprintf(fp_dest, " ICON %s\n",
246 fprintf(fp_dest, "%s", buf);
252 sprintf(buf, "%s.%ld", filename, (long)getpid());
253 rename(buf, filename);
254 DtActionInvoke(((AnyUI *)mainw->Parent())->BaseWidget(), "ReloadActions",
255 NULL, 0, NULL, NULL, NULL, True, NULL, NULL);
257 mainw->WorkingCursor(false);
258 mainw->status_line->Name(save_msg);
261 void DtPrtProps::CloseCB()
267 void DtPrtProps::OkCB(void *data)
269 DtPrtProps *obj = (DtPrtProps *) data;
275 void DtPrtProps::ApplyCB(void *data)
277 DtPrtProps *obj = (DtPrtProps *) data;
281 void DtPrtProps::CancelCB(void *data)
283 DtPrtProps *obj = (DtPrtProps *) data;
289 void DtPrtProps::ResetCB(void *data)
291 DtPrtProps *obj = (DtPrtProps *) data;
296 void DtPrtProps::HelpCB(void *data)
298 DtPrtProps *obj = (DtPrtProps *) data;
299 obj->HandleHelpRequest();
302 boolean DtPrtProps::HandleHelpRequest()
304 mainw->DisplayHelp((char *)PROPS_PRINTER_ID);
308 void DtPrtProps::SetActionIcons(const char *icon)
311 _iconFile = STRDUP(icon);
312 largeIcon->IconFile((char*)icon);
313 mediumIcon->IconFile((char*)icon);
314 smallIcon->IconFile((char*)icon);
317 void DtPrtProps::CallerCB(BaseUI *caller, char *iconFile)
319 DtPrtProps *obj = (DtPrtProps *)caller;
320 delete obj->_iconFile;
321 obj->_iconFile = STRDUP(iconFile);
322 obj->smallIcon->IconFile(iconFile);
323 obj->mediumIcon->IconFile(iconFile);
324 obj->largeIcon->IconFile(iconFile);
327 void DtPrtProps::FindSetCB(void *data)
329 DtPrtProps *obj = (DtPrtProps *)data;
330 if (!obj->mainw->findSetD)
332 char *name = new char [strlen(obj->mainw->Name()) +
333 strlen(MESSAGE(FindSetTitleL))];
334 sprintf(name, MESSAGE(FindSetTitleL), obj->mainw->Name());
335 obj->mainw->findSetD = new DtFindSet(obj->mainw, name,
336 &DtPrtProps::CallerCB);
339 obj->mainw->findSetD->Caller(obj);
340 obj->mainw->findSetD->Visible(true);