Skip to content

Commit 6af3be9

Browse files
TinyTrebuchettillkamppeter
authored andcommitted
added get_media_size() function to retrieve media dimensions for a given "media" option value
1 parent 612f884 commit 6af3be9

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

demo/print_frontend.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,17 @@ gpointer parse_commands(gpointer user_data)
270270
PrinterObj *p = find_PrinterObj(f, printer_id, backend_name);
271271
printf("%s\n", get_human_readable_choice_name(p, option_name, choice_name));
272272
}
273+
else if (strcmp(buf, "get-media-size") == 0)
274+
{
275+
char printer_id[100];
276+
char backend_name[100];
277+
char media[100];
278+
int width, length;
279+
scanf("%s%s%s", media, printer_id, backend_name);
280+
PrinterObj *p = find_PrinterObj(f, printer_id, backend_name);
281+
get_media_size(p, media, &width, &length);
282+
printf("%dx%d\n", width, length);
283+
}
273284
}
274285
}
275286

@@ -299,6 +310,7 @@ void display_help()
299310
printf("%s\n", "clear-setting <option name> <printer id> <backend name>");
300311
printf("%s\n", "get-human-readable-option-name <printer id> <backend name> <option name>");
301312
printf("%s\n", "get-human-readable-choice-name <printer id> <backend name> <option name> <choice name>");
313+
printf("%s\n", "get-media-size <media> <printer id> <backend name>");
302314

303315
printf("pickle-printer <printer id> <backend name>\n");
304316
}

lib/frontend_helper.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,15 @@ char *get_human_readable_choice_name(PrinterObj *p, char *option_name, char* cho
640640
}
641641
}
642642

643+
void get_media_size(PrinterObj *p, const char *media_size, int *width, int *length)
644+
{
645+
GError *error = NULL;
646+
GVariant *var;
647+
print_backend_call_get_media_size_sync(p->backend_proxy, media_size,
648+
&var, NULL, &error);
649+
g_variant_get(var, "(ii)", width, length);
650+
}
651+
643652
/**
644653
________________________________________________ Settings __________________________________________
645654
**/

lib/frontend_helper.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,15 @@ char *get_human_readable_option_name(PrinterObj *p, char *option_name);
340340
*/
341341
char *get_human_readable_choice_name(PrinterObj *p, char *option_name, char *choice_name);
342342

343+
/**
344+
* Finds the dimension for a given media-size
345+
*
346+
* @param media : name of media-size
347+
* @param width : address of width of media-size to be returned
348+
* @param length : address of length of media-size to be returned
349+
*/
350+
void get_media_size(PrinterObj *p, const char *media, int *width, int *length);
351+
343352
/************************************************************************************************/
344353
/**
345354
______________________________________ Settings __________________________________________

lib/interface/org.openprinting.Backend.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
<arg name="choice_name" direction="in" type="s"/>
3535
<arg name="human_readable_name" direction="out" type="s"/>
3636
</method>
37+
<method name="getMediaSize">
38+
<arg name="media" direction="in" type="s"/>
39+
<arg name="dimensions" direction="out" type="(ii)"/>
40+
<!-- dimension contents: width, length -->
41+
</method>
3742
<method name="isAcceptingJobs">
3843
<arg name="printer_id" direction="in" type="s"/>
3944
<arg name="is_accepting" direction="out" type="b"/>

0 commit comments

Comments
 (0)