improved the presentation of the decoded information
[zxing.git] / symbian / ZXingBarcodeReader / src / DecodingOperations.cpp
1 #include "ZXingBarcodeReaderAppView.h"\r
2 #include <e32std.h>\r
3 \r
4 #include <zxing/qrcode/QRCodeReader.h>\r
5 \r
6 #include <zxing/common/GlobalHistogramBinarizer.h>\r
7 #include <zxing/Binarizer.h>\r
8 #include <zxing/BinaryBitmap.h>\r
9 #include <CameraImage.h>\r
10 #include <string>\r
11 #include <aknmessagequerydialog.h>\r
12 #include "ZXingBarcodeReader_0xEF24C10A.rsg"\r
13 \r
14 using namespace zxing;\r
15 using namespace zxing::qrcode;\r
16 \r
17 void CZXingBarcodeReaderAppView::StartTimer()\r
18         {\r
19         const TInt tickInterval=2000000;\r
20         iPeriodic=CPeriodic::NewL(0); // neutral priority\r
21 \r
22         //CleanupStack::PushL(iPeriodic);\r
23 \r
24         iPeriodic->Start(tickInterval,tickInterval,TCallBack(&CZXingBarcodeReaderAppView::Tick, this));\r
25 \r
26 //      CleanupStack::PopAndDestroy(iPeriodic);\r
27         }\r
28 \r
29 TInt CZXingBarcodeReaderAppView::Tick(TAny* aObject)\r
30         {\r
31         // cast, and call non-static function\r
32         ((CZXingBarcodeReaderAppView*)aObject)->decodeBackbufferImage();\r
33         return 1;\r
34         }\r
35 \r
36 void CZXingBarcodeReaderAppView::decodeBackbufferImage()\r
37         {\r
38         QRCodeReader decoder;\r
39 \r
40         CameraImage image;\r
41         image.setImage(iBackBuffer);\r
42 \r
43 \r
44         Ref<Result> res;\r
45 \r
46         try\r
47                 {\r
48                 Ref<LuminanceSource> imageRef(new CameraImage(image));\r
49                 GlobalHistogramBinarizer* binz = new GlobalHistogramBinarizer(imageRef);\r
50         \r
51                 Ref<Binarizer> bz (binz);\r
52                 BinaryBitmap* bb = new BinaryBitmap(bz);\r
53         \r
54                 Ref<BinaryBitmap> ref(bb);\r
55         \r
56                 res = decoder.decode(ref);\r
57         \r
58                 string string = res->getText()->getText();\r
59                 HBufC8 *pHeap8 = HBufC8::NewMaxLC(string.size());\r
60                 pHeap8->Des().Copy((const TUint8 *)string.c_str());\r
61                 \r
62                 HBufC *pHeap16 = HBufC::NewMaxLC(pHeap8->Length());\r
63                 pHeap16->Des().Copy(*pHeap8);\r
64                 \r
65                 ShowResultL(*pHeap16);\r
66                 }\r
67         catch(zxing::Exception& e)\r
68                 {\r
69                         /*string string = "Error...retrying...";\r
70                         HBufC8 *pHeap8 = HBufC8::NewMaxLC(string.size());\r
71                         pHeap8->Des().Copy((const TUint8 *)string.c_str());\r
72                         \r
73                         HBufC *pHeap16 = HBufC::NewMaxLC(pHeap8->Length());\r
74                         pHeap16->Des().Copy(*pHeap8);\r
75                         \r
76                         ShowResultL(*pHeap16);*/\r
77                 }\r
78         }\r
79 \r
80 void CZXingBarcodeReaderAppView::ShowResultL(TDesC16& message)\r
81         {\r
82          StopTimer();\r
83             \r
84         CAknMessageQueryDialog* dlg = new (ELeave) CAknMessageQueryDialog ();\r
85         \r
86         dlg->PrepareLC(R_TEXT_QUERY_DIALOG );\r
87            \r
88         //HBufC* title = NULL;  \r
89         //title = iEikonEnv->AllocReadResourceLC ( TEXT_DIALOG_TITLE );\r
90         dlg->QueryHeading ()->SetTextL (_L("Information") );\r
91                 \r
92         dlg->SetMessageTextL ( message );\r
93         \r
94         dlg->RunLD();\r
95         \r
96         CleanupStack::PopAndDestroy();\r
97         \r
98         StartTimer();\r
99         }\r