Skip to content

Commit 3faed08

Browse files
committed
Save work.
1 parent 5a203f8 commit 3faed08

File tree

5 files changed

+102
-20
lines changed

5 files changed

+102
-20
lines changed

ippevetool/lib/ipptool.dart

+27-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// ipptool support function.
2+
// ipptool support functions.
33
//
44
// Copyright © 2024 by the IEEE-ISTO Printer Working Group.
55
//
@@ -13,8 +13,30 @@ import 'dart:convert';
1313
import 'package:xml/xml.dart';
1414

1515

16-
Future<XmlDocument> ipptool({required String testfile, String? datafile, Map<String, String>? vars}) async {
17-
List<String> args = [testfile]; // Command-line arguments
16+
// Get the printer attributes as Map<String,dynamic> value
17+
Future<Map<String,dynamic>> ipptoolGetAttributes({required String printerUri}) async {
18+
var process = await Process.start("ipptool", ["-j", printerUri, "get-printer-attributes.test"]);
19+
var json = "";
20+
process.stderr.pipe(stderr);
21+
await process.stdout
22+
.transform(utf8.decoder)
23+
.forEach((text) {
24+
json = json + text;
25+
});
26+
var result = process.exitCode;
27+
28+
print("result=$result\n");
29+
print("json=$json\n");
30+
31+
const JsonDecoder decoder = JsonDecoder();
32+
33+
return (decoder.convert(json)[1]);
34+
}
35+
36+
37+
// Run an ipptool test file and return the results as an XML plist file
38+
Future<XmlDocument> ipptoolRunTest({required String printerUri, required String testfile, String? datafile, Map<String, String>? vars}) async {
39+
List<String> args = [printerUri]; // Command-line arguments
1840

1941
if (datafile != null) {
2042
args.add("-f");
@@ -27,6 +49,8 @@ Future<XmlDocument> ipptool({required String testfile, String? datafile, Map<Str
2749
});
2850
}
2951

52+
args.add(testfile);
53+
3054
var process = await Process.start("ipptool", args);
3155
var plist = "";
3256
process.stderr.pipe(stderr);

ippevetool/lib/main.dart

+49-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import 'package:flutter/material.dart';
44
import 'package:flutter/services.dart';
55
import 'package:nsd/nsd.dart';
66
import 'package:url_launcher/url_launcher.dart';
7-
import 'package:xml/xml.dart';
7+
//import 'package:xml/xml.dart';
8+
import 'ipptool.dart';
89

910
void main() {
1011
runApp(const IppEveToolApp());
@@ -165,11 +166,18 @@ class _IppEveDetailsPageState extends State<IppEveDetailsPage> {
165166
],
166167
rows: _buildTxtRows(widget.printer.txt),
167168
))),
168-
]),
169-
// ListView(// IPP Attributes
170-
// children: [
171-
// ],
172-
// ),
169+
170+
// IPP Attributes
171+
const Row(children: [
172+
Text(" IPP Attributes:", textAlign: TextAlign.left, style: TextStyle(fontWeight: FontWeight.bold)),
173+
]),
174+
Expanded(child: SingleChildScrollView(child: DataTable(columns: const [
175+
DataColumn(label: SizedBox(width: 100,child: Text("Name"),)),
176+
DataColumn(label: Expanded(child: Text("Value"))),
177+
],
178+
rows: _buildAttrRows(widget.printer),
179+
))),
180+
173181
// ListView(// Print File
174182
// children: [
175183
// ],
@@ -180,6 +188,7 @@ class _IppEveDetailsPageState extends State<IppEveDetailsPage> {
180188
// ),
181189
// ],
182190
// ),
191+
]),
183192
bottomNavigationBar: BottomNavigationBar(
184193
items: const [
185194
BottomNavigationBarItem(
@@ -209,6 +218,40 @@ class _IppEveDetailsPageState extends State<IppEveDetailsPage> {
209218
);
210219
}
211220

221+
// Build a list of attribute name and value data rows
222+
List<DataRow> _buildAttrRows(Service printer) {
223+
var list = <DataRow>[ ];
224+
225+
if (printer.host != null && printer.port != null && printer.txt != null) {
226+
// Have a hostname, port, and TXT record...
227+
var rp = "/ipp/print";
228+
229+
if (printer.txt!["rp"] != null) {
230+
// Use the "rp" value from the TXT record...
231+
Uint8List rpraw = printer.txt!["rp"]!;
232+
rp = const Utf8Decoder().convert(rpraw);
233+
if (rp[0] != '/') {
234+
rp = "/$rp";
235+
}
236+
}
237+
238+
// Build the printer URI...
239+
var uri = "ipp://${printer.host}:${printer.port}$rp";
240+
241+
// Get the attributes as a JSON object
242+
ipptoolGetAttributes(printerUri: uri).then((attrs){
243+
attrs.forEach((key,value){
244+
list.add(DataRow(cells: [
245+
DataCell(Text(key)),
246+
DataCell(Expanded(child: Text(value, softWrap: true)), onTap:(){ _tapValue(context, value); }),
247+
]));
248+
});
249+
});
250+
}
251+
252+
return (list);
253+
}
254+
212255
List<DataRow> _buildTxtRows(Map<String, Uint8List?>? txt) {
213256
var list = <DataRow>[ ];
214257

ippevetool/pubspec.lock

+10-10
Original file line numberDiff line numberDiff line change
@@ -297,26 +297,26 @@ packages:
297297
dependency: "direct main"
298298
description:
299299
name: url_launcher
300-
sha256: e9aa5ea75c84cf46b3db4eea212523591211c3cf2e13099ee4ec147f54201c86
300+
sha256: d25bb0ca00432a5e1ee40e69c36c85863addf7cc45e433769d61bed3fe81fd96
301301
url: "https://pub.dev"
302302
source: hosted
303-
version: "6.2.2"
303+
version: "6.2.3"
304304
url_launcher_android:
305305
dependency: transitive
306306
description:
307307
name: url_launcher_android
308-
sha256: c0766a55ab42cefaa728cabc951e82919ab41a3a4fee0aaa96176ca82da8cc51
308+
sha256: "507dc655b1d9cb5ebc756032eb785f114e415f91557b73bf60b7e201dfedeb2f"
309309
url: "https://pub.dev"
310310
source: hosted
311-
version: "6.2.1"
311+
version: "6.2.2"
312312
url_launcher_ios:
313313
dependency: transitive
314314
description:
315315
name: url_launcher_ios
316-
sha256: "46b81e3109cbb2d6b81702ad3077540789a3e74e22795eb9f0b7d494dbaa72ea"
316+
sha256: cdb7b6da34483f9b2c9f8b2b29bc468fa7271d92e2021607ca0c4d3bcb04cdd4
317317
url: "https://pub.dev"
318318
source: hosted
319-
version: "6.2.2"
319+
version: "6.2.3"
320320
url_launcher_linux:
321321
dependency: transitive
322322
description:
@@ -337,10 +337,10 @@ packages:
337337
dependency: transitive
338338
description:
339339
name: url_launcher_platform_interface
340-
sha256: f099b552bd331eacd69affed7ff2f23bfa6b0cb825b629edf3d844375a7501ad
340+
sha256: a932c3a8082e118f80a475ce692fde89dc20fddb24c57360b96bc56f7035de1f
341341
url: "https://pub.dev"
342342
source: hosted
343-
version: "2.2.1"
343+
version: "2.3.1"
344344
url_launcher_web:
345345
dependency: transitive
346346
description:
@@ -361,10 +361,10 @@ packages:
361361
dependency: transitive
362362
description:
363363
name: uuid
364-
sha256: "22c94e5ad1e75f9934b766b53c742572ee2677c56bc871d850a57dad0f82127f"
364+
sha256: "8c951c9cb6504b2aa6b3666e6de504032d9baec24bf4cbabd3eea9edd73d4d77"
365365
url: "https://pub.dev"
366366
source: hosted
367-
version: "4.2.2"
367+
version: "4.3.2"
368368
vector_math:
369369
dependency: transitive
370370
description:

libcups

scripts/getjson.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
#
3+
# Get attributes as JSON.
4+
#
5+
# Usage:
6+
#
7+
# ./getjson.sh PRINTER-URI FILENAME.json
8+
#
9+
10+
if test $# != 2; then
11+
echo "Usage: ./getjson.sh PRINTER-URI FILENAME.json"
12+
exit 1
13+
fi
14+
15+
ipptool -j "$1" get-printer-attributes.test >"$2"

0 commit comments

Comments
 (0)