2 Copyright (C) 2010 by Juan Carlos Torres <jucato@kdemail.net>
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of
7 the License or (at your option) version 3 or any later version
8 accepted by the membership of KDE e.V. (or its successor appro-
9 ved by the membership of KDE e.V.), which shall act as a proxy
10 defined in Section 14 of version 3 of the license.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see http://www.gnu.org/licenses/.
22 #include "mainwindow.h"
24 #include "musicplayer.h"
27 #include <QMessageBox>
30 MainWindow::MainWindow(QWidget* parent): QWidget(parent)
32 m_camera = new Camera(this);
33 m_timer = new QTimer(this);
35 //Setup the UI widgets and layout
36 m_ui = new Ui::MainWindow;
37 m_player = new MusicPlayer(this);
40 m_ui->verticalLayout->insertWidget(0, m_player, 0);
42 m_ui->frequencyLabel->setFont(QFont("Sans Serif", 48));
45 setAttribute(Qt::WA_Maemo5PortraitOrientation,true);
48 frequencyChanged(m_ui->frequencyDial->value());
49 connect(m_ui->frequencyDial, SIGNAL(valueChanged(int)), this, SLOT(frequencyChanged(int)));
50 connect(m_ui->strobeButton, SIGNAL(toggled(bool)), this, SLOT(toggleStrobe(bool)));
51 connect(m_camera, SIGNAL(shutterStateChanged(bool)), this, SLOT(toggleAppState(bool)));
52 connect(m_timer, SIGNAL(timeout()), m_camera, SLOT(strobe()));
54 // Start listening for camera shutter state changes
55 m_camera->registerDbusWatcher();
57 toggleAppState(m_camera->isShutterOpen());
60 MainWindow::~MainWindow()
66 * The user has changed the frequency, normally through the QDial.
67 * The flashing interval is computed as hertz (in milliseconds) while
68 * the actual flash LED timeout is computed as half of that (in microseconds).
70 * @param frequency Frequency in hertz
72 void MainWindow::frequencyChanged(int frequency)
74 m_ui->frequencyLabel->setText(QString("%1 bpm").arg(frequency*60));
75 m_camera->setTimeout((1000000/frequency)/2);
76 m_timer->setInterval(1000/frequency);
79 void MainWindow::toggleStrobe(bool checked)
81 int timeout = m_ui->frequencyDial->value();
84 if (m_camera->init() == -1)
86 QMessageBox::information(this, tr("Camera Unavailable"),
87 tr("Please close any application using the camera"));
88 m_ui->strobeButton->setChecked(false);
92 m_camera->setTimeout((1000000/timeout)/2);
93 m_camera->setFlashIntensity(215);
94 m_timer->start(1000/timeout);
100 m_camera->setTimeout(0);
101 m_camera->setFlashIntensity(0);
106 void MainWindow::toggleAppState(bool enable)
108 m_ui->strobeButton->setEnabled(enable);
109 m_ui->frequencyDial->setEnabled(enable);
113 QMessageBox::information(this, tr("Shutter Closed"),
114 tr("Please open the camera shutter before using"));
116 if (m_ui->strobeButton->isChecked())
118 m_ui->strobeButton->setChecked(false);