]> Pileus Git - ~andy/gtk/blob - modules/printbackends/cups/gtkcupsutils.h
Merge the gtk-printing branch. For more detailed ChangeLog entries, see
[~andy/gtk] / modules / printbackends / cups / gtkcupsutils.h
1 /* gtkcupsutils.h 
2  * Copyright (C) 2006 John (J5) Palmieri <johnp@redhat.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19  
20 #ifndef __GTK_CUPS_UTILS_H__
21 #define __GTK_CUPS_UTILS_H__
22
23 #include <glib.h>
24 #include <cups/cups.h>
25 #include <cups/language.h>
26 #include <cups/http.h>
27 #include <cups/ipp.h>
28
29 G_BEGIN_DECLS
30
31 typedef struct _GtkCupsRequest  GtkCupsRequest;
32 typedef struct _GtkCupsResult   GtkCupsResult;
33
34 typedef enum
35 {
36   GTK_CUPS_POST,
37   GTK_CUPS_GET
38 } GtkCupsRequestType;
39
40
41 /** 
42  * Direction we should be polling the http socket on.
43  * We are either reading or writting at each state.
44  * This makes it easy for mainloops to connect to poll.
45  */
46 typedef enum
47 {
48   GTK_CUPS_HTTP_IDLE,
49   GTK_CUPS_HTTP_READ,
50   GTK_CUPS_HTTP_WRITE
51 } GtkCupsPollState;
52
53
54 struct _GtkCupsRequest 
55 {
56   GtkCupsRequestType type;
57
58   http_t *http;
59   http_status_t last_status;
60   ipp_t *ipp_request;
61
62   gchar *server;
63   gchar *resource;
64   gint data_fd;
65   gint attempts;
66
67   GtkCupsResult *result;
68
69   gint state;
70   GtkCupsPollState poll_state;
71
72   gint own_http : 1; 
73 };
74
75 #define GTK_CUPS_REQUEST_START 0
76 #define GTK_CUPS_REQUEST_DONE 500
77
78 /* POST states */
79 enum 
80 {
81   GTK_CUPS_POST_CONNECT = GTK_CUPS_REQUEST_START,
82   GTK_CUPS_POST_SEND,
83   GTK_CUPS_POST_WRITE_REQUEST,
84   GTK_CUPS_POST_WRITE_DATA,
85   GTK_CUPS_POST_CHECK,
86   GTK_CUPS_POST_READ_RESPONSE,
87   GTK_CUPS_POST_DONE = GTK_CUPS_REQUEST_DONE
88 };
89
90 /* GET states */
91 enum
92 {
93   GTK_CUPS_GET_CONNECT = GTK_CUPS_REQUEST_START,
94   GTK_CUPS_GET_SEND,
95   GTK_CUPS_GET_CHECK,
96   GTK_CUPS_GET_READ_DATA,
97   GTK_CUPS_GET_DONE = GTK_CUPS_REQUEST_DONE
98 };
99
100 GtkCupsRequest * gtk_cups_request_new             (http_t             *connection,
101                                                    GtkCupsRequestType  req_type,
102                                                    gint                operation_id,
103                                                    gint                data_fd,
104                                                    const char         *server,
105                                                    const char         *resource);
106 void             gtk_cups_request_ipp_add_string  (GtkCupsRequest     *request,
107                                                    ipp_tag_t           group,
108                                                    ipp_tag_t           tag,
109                                                    const char         *name,
110                                                    const char         *charset,
111                                                    const char         *value);
112 gboolean         gtk_cups_request_read_write      (GtkCupsRequest     *request);
113 GtkCupsPollState gtk_cups_request_get_poll_state  (GtkCupsRequest     *request);
114 void             gtk_cups_request_free            (GtkCupsRequest     *request);
115 GtkCupsResult  * gtk_cups_request_get_result      (GtkCupsRequest     *request);
116 gboolean         gtk_cups_request_is_done         (GtkCupsRequest     *request);
117 void             gtk_cups_request_encode_option   (GtkCupsRequest     *request,
118                                                    const gchar        *option,
119                                                    const gchar        *value);
120 gboolean         gtk_cups_result_is_error         (GtkCupsResult      *result);
121 ipp_t          * gtk_cups_result_get_response     (GtkCupsResult      *result);
122 const char     * gtk_cups_result_get_error_string (GtkCupsResult      *result);
123
124 G_END_DECLS
125 #endif