Skip to content

Commit

Permalink
Add interface method to get human readable option names
Browse files Browse the repository at this point in the history
Pull request #2
Co-authored-by: Priydarshi Singh <dryairship@gmail.com>

Print attributes/options and their choices are usually defined in a machine-readable form which is more made for easy typing in a command line, not too long, no special characters, always in English and human-readable form for GUI (print dialogs), more verbose for easier understanding, with spaces and other special characters, translated, ...

This commit adds functionality to the library to poll the human-readable strings from the backends.

Older backends without human-readable strings can still be used. In such a case it is recommended that the dialog does either its own conversion or simply shows the machine-readable string as a last mean.
  • Loading branch information
TinyTrebuchet committed Feb 10, 2022
1 parent 60a003c commit 46f8870
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
21 changes: 21 additions & 0 deletions demo/print_frontend.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,25 @@ gpointer parse_commands(gpointer user_data)
PrinterObj *p = find_PrinterObj(f, printer_id, backend_name);
pickle_printer_to_file(p, "/tmp/.printer-pickle", f);
}
else if (strcmp(buf, "get-human-readable-option-name") == 0)
{
char printer_id[100];
char backend_name[100];
char option_name[100];
scanf("%s%s%s", printer_id, backend_name, option_name);
PrinterObj *p = find_PrinterObj(f, printer_id, backend_name);
printf("%s\n", get_human_readable_option_name(p, option_name));
}
else if (strcmp(buf, "get-human-readable-choice-name") == 0)
{
char printer_id[100];
char backend_name[100];
char option_name[100];
char choice_name[100];
scanf("%s%s%s%s", printer_id, backend_name, option_name, choice_name);
PrinterObj *p = find_PrinterObj(f, printer_id, backend_name);
printf("%s\n", get_human_readable_choice_name(p, option_name, choice_name));
}
}
}

Expand Down Expand Up @@ -278,6 +297,8 @@ void display_help()
printf("%s\n", "get-current <option name> <printer id> <backend name>");
printf("%s\n", "add-setting <option name> <option value> <printer id> <backend name>");
printf("%s\n", "clear-setting <option name> <printer id> <backend name>");
printf("%s\n", "get-human-readable-option-name <printer id> <backend name> <option name>");
printf("%s\n", "get-human-readable-choice-name <printer id> <backend name> <option name> <choice name>");

printf("pickle-printer <printer id> <backend name>\n");
}
28 changes: 28 additions & 0 deletions lib/frontend_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,34 @@ PrinterObj *resurrect_printer_from_file(const char *filename)
return p;
}

char *get_human_readable_option_name(PrinterObj *p, char *option_name)
{
char *human_readable_name;
GError *error = NULL;
print_backend_call_get_human_readable_option_name_sync(p->backend_proxy, option_name,
&human_readable_name, NULL, &error);
if(error) {
DBG_LOG("Error getting human readable option name", ERR);
return option_name;
} else {
return human_readable_name;
}
}

char *get_human_readable_choice_name(PrinterObj *p, char *option_name, char* choice_name)
{
char *human_readable_name;
GError *error = NULL;
print_backend_call_get_human_readable_choice_name_sync(p->backend_proxy, option_name, choice_name,
&human_readable_name, NULL, &error);
if(error) {
DBG_LOG("Error getting human readable choice name", ERR);
return choice_name;
} else {
return human_readable_name;
}
}

/**
________________________________________________ Settings __________________________________________
**/
Expand Down
16 changes: 16 additions & 0 deletions lib/frontend_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,22 @@ void pickle_printer_to_file(PrinterObj *p, const char *filename , const Frontend
* NULL otherwise
*/
PrinterObj *resurrect_printer_from_file(const char *filename);

/**
* Finds the human readable English name of the setting.
*
* @param option_name : name of the setting
*/
char *get_human_readable_option_name(PrinterObj *p, char *option_name);

/**
* Finds the human readable English name of the choice for the given setting.
*
* @param option_name : name of the setting
* @param choice_name : value of the choice
*/
char *get_human_readable_choice_name(PrinterObj *p, char *option_name, char *choice_name);

/************************************************************************************************/
/**
______________________________________ Settings __________________________________________
Expand Down
9 changes: 9 additions & 0 deletions lib/interface/org.openprinting.Backend.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@
<arg name="printer_id" direction="in" type="s"/>
<arg name="state" direction="out" type="s"/>
</method>
<method name="getHumanReadableOptionName">
<arg name="option_name" direction="in" type="s"/>
<arg name="human_readable_name" direction="out" type="s"/>
</method>
<method name="getHumanReadableChoiceName">
<arg name="option_name" direction="in" type="s"/>
<arg name="choice_name" direction="in" type="s"/>
<arg name="human_readable_name" direction="out" type="s"/>
</method>
<method name="isAcceptingJobs">
<arg name="printer_id" direction="in" type="s"/>
<arg name="is_accepting" direction="out" type="b"/>
Expand Down

0 comments on commit 46f8870

Please sign in to comment.