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