Skip to content

Commit

Permalink
Finalise scanner-webif.c
Browse files Browse the repository at this point in the history
This commit finalises the scanner-webif.c file.
It closely follows all aspects of the printer-webif.c file, but
also follows the scan specific requirements.

This commit finalizes the implementation of the scanner web interface
functions, including the following features:

- Added `_papplScannerWebConfig()` to show and handle scanner configuration settings.
- Implemented `_papplScannerWebConfigFinalize()` to save changes to the scanner configuration.
- Developed `_papplScannerWebDefaults()` to display and update default scanning settings.

Signed-off-by: Akarshan Kapoor <data.akarshan@icloud.com>
  • Loading branch information
Kappuccino111 committed Jul 12, 2024
1 parent 8507fb9 commit 64f7aa4
Show file tree
Hide file tree
Showing 11 changed files with 847 additions and 9 deletions.
1 change: 1 addition & 0 deletions pappl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ BASEOBJS = \
scanner-accessors.o\
scanner-driver.o \
scanner-escl.o \
scanner-webif.o \
snmp.o \
subscription.o \
subscription-ipp.o \
Expand Down
1 change: 1 addition & 0 deletions pappl/client-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct _pappl_client_s // Client data
char username[256]; // Authenticated username, if any
char language[256]; // Accept-Language value, if any
pappl_printer_t *printer; // Printer, if any
pappl_scanner_t *scanner; // Scanner, if any
pappl_job_t *job; // Job, if any
pappl_loc_t *loc; // Localization, if any
int num_files; // Number of temporary files
Expand Down
124 changes: 124 additions & 0 deletions pappl/client-webif.c
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,26 @@ papplClientHTMLPrinterFooter(pappl_client_t *client) // I - Client
}


//
// 'papplClientHTMLScannerFooter()' - Show the web interface footer for scanners.
//
// This function sends the standard web interface footer for a scanner followed
// by a trailing 0-length chunk to finish the current HTTP response. Use the
// @link papplSystemSetFooterHTML@ function to add any custom HTML needed in
// the footer.
//

void
papplClientHTMLScannerFooter(pappl_client_t *client) // I - Client
{
papplClientHTMLPuts(client,
" </div>\n"
" </div>\n"
" </div>\n");
papplClientHTMLFooter(client);
}


//
// 'papplClientHTMLPrinterHeader()' - Show the web interface header and title
// for printers.
Expand Down Expand Up @@ -1015,6 +1035,110 @@ papplClientHTMLPrinterHeader(
}


//
// 'papplClientHTMLScannerHeader()' - Show the web interface header and title
// for scanners.
//
// This function sends the standard web interface header and title for a
// scanner. If the "refresh" argument is greater than zero, the page will
// automatically reload after that many seconds.
//
// If "label" and "path_or_url" are non-`NULL` strings, an additional navigation
// link is included with the title header - this is typically used for an
// action button ("Change").
//
// Use the @link papplSystemAddLink@ function to add system-wide navigation
// links to the header. Similarly, use @link papplScannerAddLink@ to add
// scanner-specific links, which will appear in the web interface scanner if
// the system is not configured to support multiple scanners
//

// TODO : papplScannerAddLink
void
papplClientHTMLScannerHeader(
pappl_client_t *client, // I - Client
pappl_scanner_t *scanner, // I - Scanner
const char *title, // I - Title
int refresh, // I - Refresh time in seconds or 0 for none
const char *label, // I - Button label or `NULL` for none
const char *path_or_url) // I - Button path or `NULL` for none
{
const char *header; // Header text

if (!papplClientRespond(client, HTTP_STATUS_OK, NULL, "text/html", 0, 0))
return;


// Multi-queue mode not required for scanners

// Single queue mode - the function will automatically add the scanner name and localize the title...
papplClientHTMLHeader(client, title, refresh);

// Generate HTML for scanners
_papplRWLockRead(scanner);
papplClientHTMLPrintf(client,
" <div class=\"header2\">\n"
" <div class=\"row\">\n"
" <div class=\"col-12 nav\"><a class=\"btn\" href=\"%s\">%s:</a>\n", scanner->uriname, scanner->name);
_papplClientHTMLPutLinks(client, scanner->links, PAPPL_LOPTIONS_NAVIGATION);
papplClientHTMLPuts(client,
" </div>\n"
" </div>\n"
" </div>\n");
_papplRWUnlock(scanner);

// Display system version if available
if (client->system->versions[0].sversion[0])
{
papplClientHTMLPrintf(client,
" <div class=\"header2\">\n"
" <div class=\"row\">\n"
" <div class=\"col-12 nav\">\n"
" Version %s\n"
" </div>\n"
" </div>\n"
" </div>\n", client->system->versions[0].sversion);
}

papplClientHTMLPuts(client, " <div class=\"content\">\n");

if ((header = papplClientGetLocString(client, client->uri)) == client->uri)
{
size_t urilen = strlen(scanner->uriname);
// Length of scanner URI name
const char *uriptr = client->uri + urilen;
// Pointer into client URI

if (strlen(client->uri) <= urilen || !strcmp(client->uri, "/") || (header = papplClientGetLocString(client, uriptr)) == uriptr)
header = NULL;
}

if (header)
{
// Show header text
papplClientHTMLPuts(client,
" <div class=\"row\">\n"
" <div class=\"col-12\">\n");
papplClientHTMLPuts(client, header);
papplClientHTMLPuts(client,
"\n"
" </div>\n"
" </div>\n");
}

if (title)
{
papplClientHTMLPrintf(client,
" <div class=\"row\">\n"
" <div class=\"col-12\">\n"
" <h1 class=\"title\">%s", papplClientGetLocString(client, title));
if (label && path_or_url)
papplClientHTMLPrintf(client, " <a class=\"btn\" href=\"%s\">%s</a>", path_or_url, papplClientGetLocString(client, label));
papplClientHTMLPuts(client, "</h1>\n");
}
}


//
// 'papplClientHTMLPrintf()' - Send formatted text to the web browser client,
// escaping as needed.
Expand Down
2 changes: 2 additions & 0 deletions pappl/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ extern bool papplClientHTMLAuthorize(pappl_client_t *client) _PAPPL_PUBLIC;
extern void papplClientHTMLEscape(pappl_client_t *client, const char *s, size_t slen) _PAPPL_PUBLIC;
extern void papplClientHTMLFooter(pappl_client_t *client) _PAPPL_PUBLIC;
extern void papplClientHTMLHeader(pappl_client_t *client, const char *title, int refresh) _PAPPL_PUBLIC;
extern void papplClientHTMLScannerHeader(pappl_client_t *client, pappl_scanner_t *scanner, const char *title, int refresh, const char *label, const char *path_or_url)_PAPPL_PUBLIC;
extern void papplClientHTMLScannerFooter(pappl_client_t *client)_PAPPL_PUBLIC;
extern void papplClientHTMLPrinterFooter(pappl_client_t *client) _PAPPL_PUBLIC;
extern void papplClientHTMLPrinterHeader(pappl_client_t *client, pappl_printer_t *printer, const char *title, int refresh, const char *label, const char *path_or_url) _PAPPL_PUBLIC;
extern void papplClientHTMLPrintf(pappl_client_t *client, const char *format, ...) _PAPPL_PUBLIC _PAPPL_FORMAT(2, 3);
Expand Down
1 change: 1 addition & 0 deletions pappl/pappl-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
# include "log-private.h"
# include "mainloop-private.h"
# include "printer-private.h"
# include "scanner-private.h"
# include "system-private.h"
#endif // !_PAPPL_PAPPL_PRIVATE_H_
14 changes: 7 additions & 7 deletions pappl/scanner-driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ papplScannerSetDriverDefaults(
scanner->driver_data.default_color_mode = data->default_color_mode;
scanner->driver_data.default_resolution = data->default_resolution;
scanner->driver_data.default_input_source = data->default_input_source;
scanner->driver_data.default_media_type = data->default_media_type;
scanner->driver_data.default_document_format = data->default_document_format;
scanner->driver_data.default_intent = data->default_intent;
scanner->driver_data.default_color_space = data->default_color_space;

scanner->config_time = time(NULL);

Expand Down Expand Up @@ -237,11 +241,7 @@ make_escl_attr(

xmlNewChild(root_node, NULL, BAD_CAST "scan:NoiseRemovalSupported", BAD_CAST (scanner->driver_data.noise_removal_supported ? "true" : "false"));

xmlNewChild(root_node, NULL, BAD_CAST "scan:SharpnessSupported", BAD_CAST (scanner->driver_data.sharpness_supported ? "true" : "false"));

char compression_factor_str[16];
snprintf(compression_factor_str, sizeof(compression_factor_str), "%d", scanner->driver_data.compression_factor_supported);
xmlNewChild(root_node, NULL, BAD_CAST "scan:CompressionFactorsSupported", BAD_CAST compression_factor_str);
xmlNewChild(root_node, NULL, BAD_CAST "scan:SharpeningSupported", BAD_CAST (scanner->driver_data.sharpening_supported ? "true" : "false"));

xmlNewChild(root_node, NULL, BAD_CAST "scan:BinaryRenderingSupported", BAD_CAST (scanner->driver_data.binary_rendering_supported ? "true" : "false"));

Expand All @@ -255,7 +255,7 @@ make_escl_attr(
}

// Converts input source to string
const char *_papplScannerInputSourceString(pappl_sc_input_source_t value)
const char *ScannerInputSourceString(pappl_sc_input_source_t value)
{
switch (value)
{
Expand All @@ -269,7 +269,7 @@ const char *_papplScannerInputSourceString(pappl_sc_input_source_t value)
}

// Converts resolution to string
const char *_papplScannerResolutionString(int resolution)
const char *ScannerResolutionString(int resolution)
{
static char res_str[32];
snprintf(res_str, sizeof(res_str), "%d DPI", resolution);
Expand Down
Loading

0 comments on commit 64f7aa4

Please sign in to comment.