46
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "cxecameradevicedesktop.h"
|
|
19 |
|
|
20 |
#include <QTimer>
|
|
21 |
#include <QDir>
|
|
22 |
#include "cxutils.h"
|
|
23 |
|
|
24 |
|
|
25 |
/*!
|
|
26 |
* Constructor
|
|
27 |
*/
|
|
28 |
CxeCameraDeviceDesktop::CxeCameraDeviceDesktop() :
|
|
29 |
mSwitchPictureTimer(0),
|
|
30 |
mPictureIndex(0)
|
|
31 |
{
|
|
32 |
CX_DEBUG_ENTER_FUNCTION();
|
|
33 |
loadPictures();
|
|
34 |
setupTimer();
|
|
35 |
CX_DEBUG_EXIT_FUNCTION();
|
|
36 |
}
|
|
37 |
|
|
38 |
/*!
|
|
39 |
* Destructor
|
|
40 |
*/
|
|
41 |
CxeCameraDeviceDesktop::~CxeCameraDeviceDesktop()
|
|
42 |
{
|
|
43 |
CX_DEBUG_ENTER_FUNCTION();
|
|
44 |
mSwitchPictureTimer->stop();
|
|
45 |
delete mSwitchPictureTimer;
|
|
46 |
CX_DEBUG_EXIT_FUNCTION();
|
|
47 |
}
|
|
48 |
|
|
49 |
/*!
|
|
50 |
* Start the camera device
|
|
51 |
*/
|
|
52 |
void CxeCameraDeviceDesktop::start()
|
|
53 |
{
|
|
54 |
CX_DEBUG_ENTER_FUNCTION();
|
|
55 |
if (!mSwitchPictureTimer->isActive()) {
|
|
56 |
mSwitchPictureTimer->start();
|
|
57 |
CX_DEBUG_EXIT_FUNCTION();
|
|
58 |
}
|
|
59 |
}
|
|
60 |
|
|
61 |
/*!
|
|
62 |
* Stop the camera device
|
|
63 |
*/
|
|
64 |
void CxeCameraDeviceDesktop::stop()
|
|
65 |
{
|
|
66 |
CX_DEBUG_ENTER_FUNCTION();
|
|
67 |
mSwitchPictureTimer->stop();
|
|
68 |
CX_DEBUG_EXIT_FUNCTION();
|
|
69 |
}
|
|
70 |
|
|
71 |
/*!
|
|
72 |
* Get current picture
|
|
73 |
* @ Return current picture
|
|
74 |
*/
|
|
75 |
const QPixmap &CxeCameraDeviceDesktop::currentSnaphot()
|
|
76 |
{
|
|
77 |
return mPictureList.at(mPictureIndex);
|
|
78 |
}
|
|
79 |
|
|
80 |
/*!
|
|
81 |
* Handle timeout
|
|
82 |
*/
|
|
83 |
void CxeCameraDeviceDesktop::handleTimeout()
|
|
84 |
{
|
|
85 |
CX_DEBUG_ENTER_FUNCTION();
|
|
86 |
mPictureIndex++;
|
|
87 |
|
|
88 |
if (mPictureIndex >= mPictureList.count()) {
|
|
89 |
mPictureIndex = 0;
|
|
90 |
}
|
|
91 |
|
|
92 |
emit imageChanged(mPictureList.at(mPictureIndex));
|
|
93 |
CX_DEBUG_EXIT_FUNCTION();
|
|
94 |
}
|
|
95 |
|
|
96 |
/*!
|
|
97 |
* Load pictures
|
|
98 |
*/
|
|
99 |
void CxeCameraDeviceDesktop::loadPictures()
|
|
100 |
{
|
|
101 |
CX_DEBUG_ENTER_FUNCTION();
|
|
102 |
QDir currentDir(".","*.jpg");
|
55
|
103 |
CX_DEBUG(("Searching images from %s", qPrintable(currentDir.absolutePath())));
|
|
104 |
CX_DEBUG(("Number of images found %d", currentDir.count()));
|
46
|
105 |
|
|
106 |
if (!currentDir.count()) {
|
|
107 |
mPictureList.append(QPixmap(360, 640));
|
|
108 |
return;
|
|
109 |
}
|
|
110 |
|
|
111 |
foreach (QString entry, currentDir.entryList()){
|
|
112 |
mPictureList.append(QPixmap(entry).scaledToHeight(360));
|
|
113 |
}
|
|
114 |
CX_DEBUG_EXIT_FUNCTION();
|
|
115 |
}
|
|
116 |
|
|
117 |
/*!
|
|
118 |
* Create timer
|
|
119 |
*/
|
|
120 |
void CxeCameraDeviceDesktop::setupTimer()
|
|
121 |
{
|
|
122 |
CX_DEBUG_ENTER_FUNCTION();
|
|
123 |
mSwitchPictureTimer = new QTimer(this);
|
|
124 |
mSwitchPictureTimer->setInterval(500);
|
|
125 |
mSwitchPictureTimer->setSingleShot(false);
|
|
126 |
connect(mSwitchPictureTimer, SIGNAL(timeout()), this, SLOT(handleTimeout()));
|
|
127 |
CX_DEBUG_EXIT_FUNCTION();
|
|
128 |
}
|