~ubuntu-branches/ubuntu/feisty/photoprint/feisty

« back to all changes in this revision

Viewing changes to pp_printoutput.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Milan Zamazal
  • Date: 2006-09-29 12:18:16 UTC
  • Revision ID: james.westby@ubuntu.com-20060929121816-6t2iz9zaymixd3om
Tags: upstream-0.3.3
ImportĀ upstreamĀ versionĀ 0.3.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// FIXME - need a destructor to clean up the printer queue strings.
 
2
 
 
3
#include <iostream>
 
4
 
 
5
#include <string.h>
 
6
 
 
7
#include <gtk/gtkframe.h>
 
8
#include <gtk/gtksizegroup.h>
 
9
#include <gtk/gtklabel.h>
 
10
#include <gtk/gtkcontainer.h>
 
11
 
 
12
#include "pp_printoutput.h"
 
13
 
 
14
using namespace std;
 
15
 
 
16
enum {
 
17
        CHANGED_SIGNAL,
 
18
        LAST_SIGNAL
 
19
};
 
20
 
 
21
static guint pp_printoutput_signals[LAST_SIGNAL] = { 0 };
 
22
 
 
23
static void pp_printoutput_class_init (pp_PrintOutputClass *klass);
 
24
static void pp_printoutput_init (pp_PrintOutput *stpuicombo);
 
25
 
 
26
 
 
27
static void printersel_changed(GtkWidget *wid,gpointer *ob)
 
28
{
 
29
        cerr << "In printersel_changed()" << endl;
 
30
        pp_PrintOutput *lo=(pp_PrintOutput *)ob;
 
31
 
 
32
        const char *driver=stpui_printerselector_get_driver(STPUI_PRINTERSELECTOR(wid));
 
33
        lo->po->SetString("Driver",driver);
 
34
 
 
35
        g_signal_emit(G_OBJECT (ob),pp_printoutput_signals[CHANGED_SIGNAL], 0);
 
36
}
 
37
 
 
38
 
 
39
static void command_changed(GtkWidget *wid,gpointer *ob)
 
40
{
 
41
        cerr << "In command_changed()" << endl;
 
42
        pp_PrintOutput *lo=(pp_PrintOutput *)ob;
 
43
 
 
44
        const char *command=gtk_entry_get_text(GTK_ENTRY(wid));
 
45
        lo->po->SetString("Command",command);
 
46
}
 
47
 
 
48
 
 
49
static void pp_printoutput_queue_changed(GtkEntry *entry,gpointer *ud)
 
50
{
 
51
        cerr << "In pp_printoutput_queue_changed()" << endl;
 
52
 
 
53
        pp_PrintOutput *ob=PP_PRINTOUTPUT(ud);
 
54
        PrintOutput *po=ob->po;
 
55
 
 
56
        const char *val=gtk_entry_get_text(entry);
 
57
        if(val && strlen(val))
 
58
        {
 
59
                po->SetString("Queue",val);
 
60
                char *driver=po->GetPrinterDriver(val);
 
61
                if(driver)
 
62
                {
 
63
                        cerr << "Got driver: " << driver << " from Queue" << endl;
 
64
                        po->SetString("Driver",driver);
 
65
                        stpui_printerselector_set_driver(STPUI_PRINTERSELECTOR(ob->printersel),driver);
 
66
                        free(driver);
 
67
                }
 
68
//              char *command=po->GetPrintCommand(val);
 
69
//              if(command)
 
70
//              {
 
71
//                      po->SetString("Command",command);
 
72
//                      gtk_entry_set_text(GTK_ENTRY(ob->string),command);
 
73
//                      free(command);
 
74
//              }
 
75
                g_signal_emit(G_OBJECT (ob),pp_printoutput_signals[CHANGED_SIGNAL], 0);
 
76
        }
 
77
}
 
78
 
 
79
 
 
80
 
 
81
void pp_printoutput_refresh(pp_PrintOutput *ob)
 
82
{
 
83
        cerr << "In pp_printoutput_refresh()" << endl;
 
84
        PrintOutput *po=ob->po;
 
85
 
 
86
        char *driver=po->FindString("Driver");
 
87
        if(driver)
 
88
        {
 
89
                cerr << "Setting driver to " << driver << endl;
 
90
                stpui_printerselector_set_driver(STPUI_PRINTERSELECTOR(ob->printersel),driver);
 
91
        }
 
92
        char *command=po->FindString("Command");
 
93
        if(command)
 
94
        {
 
95
                gtk_entry_set_text(GTK_ENTRY(ob->string),command);
 
96
        }
 
97
}
 
98
 
 
99
 
 
100
GtkWidget*
 
101
pp_printoutput_new (PrintOutput *po)
 
102
{
 
103
        pp_PrintOutput *ob=PP_PRINTOUTPUT(g_object_new (pp_printoutput_get_type (), NULL));
 
104
        gtk_box_set_spacing(GTK_BOX(ob),5);
 
105
 
 
106
        ob->po=po;
 
107
 
 
108
        GtkWidget *label;
 
109
 
 
110
        GtkWidget *table=gtk_table_new(2,3,FALSE);
 
111
        gtk_container_set_border_width(GTK_CONTAINER(table),5);
 
112
        gtk_box_pack_start(GTK_BOX(ob),table,FALSE,FALSE,0);
 
113
        gtk_widget_show(table);
 
114
 
 
115
        label=gtk_label_new("Print Queue:");
 
116
        gtk_table_attach_defaults(GTK_TABLE(table),label,0,1,0,1);
 
117
        gtk_widget_show(label);
 
118
 
 
119
        ob->combo=gtk_combo_new();
 
120
        gtk_combo_set_value_in_list(GTK_COMBO(ob->combo),TRUE,FALSE);
 
121
        gtk_table_attach_defaults(GTK_TABLE(table),ob->combo,1,2,0,1);
 
122
        gtk_widget_show(ob->combo);
 
123
 
 
124
        int count,j;
 
125
 
 
126
        ob->queues=NULL;
 
127
        count=po->GetPrinterCount();
 
128
        
 
129
        for(j=0;j<count;++j)
 
130
        {
 
131
                char *queue=po->GetPrinterName(j);
 
132
                ob->queues=g_list_append(ob->queues,(void *)queue);
 
133
        }
 
134
        
 
135
        if(ob->queues)
 
136
        {
 
137
                gtk_combo_set_popdown_strings(GTK_COMBO(ob->combo),ob->queues);
 
138
                gtk_widget_set_sensitive(GTK_WIDGET(ob->combo),TRUE);
 
139
        }
 
140
        else
 
141
                gtk_widget_set_sensitive(GTK_WIDGET(ob->combo),FALSE);
 
142
 
 
143
        char *queue=po->FindString("Queue");
 
144
        if(queue && g_list_find_custom(ob->queues,queue,(GCompareFunc)strcmp))
 
145
                gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(ob->combo)->entry),queue);
 
146
 
 
147
        g_signal_connect(GTK_COMBO(ob->combo)->entry,"changed",G_CALLBACK(pp_printoutput_queue_changed),ob);
 
148
 
 
149
 
 
150
        label=gtk_label_new("Printer Model:");
 
151
        gtk_table_attach_defaults(GTK_TABLE(table),label,0,1,1,2);
 
152
        gtk_widget_show(label);
 
153
 
 
154
        ob->printersel=stpui_printerselector_new();
 
155
        gtk_table_attach_defaults(GTK_TABLE(table),ob->printersel,1,2,1,2);
 
156
        g_signal_connect(G_OBJECT(ob->printersel),"changed",G_CALLBACK(printersel_changed),ob);
 
157
 
 
158
        stpui_printerselector_set_driver(STPUI_PRINTERSELECTOR(ob->printersel),po->FindString("Driver"));
 
159
        gtk_widget_show(ob->printersel);
 
160
 
 
161
 
 
162
        label=gtk_label_new("Print command:");
 
163
        gtk_table_attach_defaults(GTK_TABLE(table),label,0,1,2,3);
 
164
        gtk_widget_show(label);
 
165
 
 
166
        ob->string=gtk_entry_new();
 
167
        gtk_table_attach_defaults(GTK_TABLE(table),ob->string,1,2,2,3);
 
168
        gtk_widget_show(ob->string);
 
169
        gtk_entry_set_text(GTK_ENTRY(ob->string),po->FindString("Command"));
 
170
        g_signal_connect(G_OBJECT(ob->string),"changed",G_CALLBACK(command_changed),ob);
 
171
        
 
172
        return(GTK_WIDGET(ob));
 
173
}
 
174
 
 
175
 
 
176
GType
 
177
pp_printoutput_get_type (void)
 
178
{
 
179
        static GType stpuic_type = 0;
 
180
 
 
181
        if (!stpuic_type)
 
182
        {
 
183
                static const GTypeInfo pp_printoutput_info =
 
184
                {
 
185
                        sizeof (pp_PrintOutputClass),
 
186
                        NULL, /* base_init */
 
187
                        NULL, /* base_finalize */
 
188
                        (GClassInitFunc) pp_printoutput_class_init,
 
189
                        NULL, /* class_finalize */
 
190
                        NULL, /* class_data */
 
191
                        sizeof (pp_PrintOutput),
 
192
                        0,
 
193
                        (GInstanceInitFunc) pp_printoutput_init,
 
194
                };
 
195
                stpuic_type = g_type_register_static (GTK_TYPE_VBOX, "pp_PrintOutput", &pp_printoutput_info, (GTypeFlags)0);
 
196
        }
 
197
        return stpuic_type;
 
198
}
 
199
 
 
200
 
 
201
static void
 
202
pp_printoutput_class_init (pp_PrintOutputClass *klass)
 
203
{
 
204
        pp_printoutput_signals[CHANGED_SIGNAL] =
 
205
        g_signal_new ("changed",
 
206
                G_TYPE_FROM_CLASS (klass),
 
207
                GSignalFlags(G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION),
 
208
                G_STRUCT_OFFSET (pp_PrintOutputClass, changed),
 
209
                NULL, NULL,
 
210
                g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
 
211
}
 
212
 
 
213
 
 
214
static void
 
215
pp_printoutput_init (pp_PrintOutput *ob)
 
216
{
 
217
        ob->po=NULL;
 
218
}