work-in-progress: I have no idea whats working or broken…
This commit is contained in:
parent
3df7b529c6
commit
6530affd65
18 changed files with 595 additions and 121 deletions
|
@ -34,6 +34,7 @@
|
|||
#include "image.h"
|
||||
#include "properties.h"
|
||||
#include "camera.h"
|
||||
#include "helpers.h"
|
||||
|
||||
using namespace Oi;
|
||||
|
||||
|
@ -41,40 +42,30 @@ const QString Camera::cUserAgent = "libqt-omd v0.1";
|
|||
|
||||
Camera::Camera() :
|
||||
mAddress("192.168.0.10"),
|
||||
mCamProperties(this),
|
||||
mCamMode(MODE_UNKNOWN),
|
||||
mConnectMode(CONNECT_UNKNOWN)
|
||||
{
|
||||
connect(&mNetworkManager, &QNetworkAccessManager::finished, this, &Camera::requestFinished);
|
||||
|
||||
if (isOnline())
|
||||
initialize();
|
||||
else
|
||||
qWarning() << "[libqt-omd] Camera is not online";
|
||||
}
|
||||
|
||||
void Camera::initialize()
|
||||
{
|
||||
requestConnectMode();
|
||||
requestCamInfo();
|
||||
requestCommands();
|
||||
|
||||
switchCamMode(MODE_PLAY);
|
||||
completePendingRequests();
|
||||
|
||||
requestCamInfo();
|
||||
requestCapacity();
|
||||
requestConnectMode();
|
||||
requestCommandList();
|
||||
requestImageList();
|
||||
requestImages();
|
||||
|
||||
switchCamMode(MODE_RECORD);
|
||||
completePendingRequests();
|
||||
|
||||
qDebug() << "[libqt-omd] CamModel: " << mCamModel;
|
||||
qDebug() << "[libqt-omd] UnusedCapacity: " << mUnusedCapacity;
|
||||
qDebug() << "[libqt-omd] CamMode: " << mCamMode;
|
||||
qDebug() << "[libqt-omd] ConnectMode: " << mConnectMode;
|
||||
|
||||
}
|
||||
|
||||
QUrl Camera::getUrl() const
|
||||
{
|
||||
return QUrl("http://192.168.0.10");
|
||||
requestProperties();
|
||||
completePendingRequests();
|
||||
}
|
||||
|
||||
bool Camera::isOnline()
|
||||
|
@ -97,6 +88,11 @@ QNetworkRequest Camera::makeRequest(QString cgi, QMap<QString, QString> params)
|
|||
for (QString key : params.keys())
|
||||
paramList.push_back(qMakePair(key, params[key]));
|
||||
|
||||
if (cgi == "switch_cammode") {
|
||||
QPair<QString, QString> tmp = paramList.takeFirst();
|
||||
paramList.append(tmp);
|
||||
}
|
||||
|
||||
query.setQueryItems(paramList);
|
||||
url.setQuery(query);
|
||||
|
||||
|
@ -146,7 +142,7 @@ void Camera::requestFinished(QNetworkReply *reply)
|
|||
if (contentType == "text/xml" && reply->size() > 0) {
|
||||
QDomDocument body;
|
||||
if (body.setContent(reply->readAll())) {
|
||||
qDebug() << "[libqt-omd] Content:" << body.toString();
|
||||
//qDebug() << "[libqt-omd] Content:" << body.toString();
|
||||
parseXml(cgi, body);
|
||||
}
|
||||
else
|
||||
|
@ -199,9 +195,20 @@ void Camera::powerOff() { get("exec_pwoff"); }
|
|||
void Camera::requestCamInfo() { get("get_caminfo"); }
|
||||
void Camera::requestCapacity() { get("get_unusedcapacity"); }
|
||||
void Camera::requestConnectMode() { get("get_connectmode"); }
|
||||
void Camera::requestCommandList() { get("get_commandlist"); }
|
||||
void Camera::requestCommands() { get("get_commandlist"); }
|
||||
|
||||
void Camera::requestImageList(QString dir, bool rsv) {
|
||||
void Camera::requestProperties()
|
||||
{
|
||||
QMap<QString, QString> params;
|
||||
|
||||
params["com"] = "desc";
|
||||
params["propname"] = "desclist";
|
||||
|
||||
get("get_camprop", params);
|
||||
|
||||
}
|
||||
|
||||
void Camera::requestImages(QString dir, bool rsv) {
|
||||
QMap<QString, QString> params;
|
||||
|
||||
params["DIR"] = dir.replace('/', "%2F");
|
||||
|
@ -228,13 +235,16 @@ void Camera::switchCamMode(CamMode mode)
|
|||
case MODE_PLAY:
|
||||
params["mode"] = "play";
|
||||
break;
|
||||
|
||||
case MODE_RECORD:
|
||||
params["mode"] = "rec";
|
||||
params["lvqty"] = "0640x0480"; // FIXME allow other liveViewQualities
|
||||
params["lvqty"] = "0320x0240"; // FIXME allow other liveViewQualities
|
||||
break;
|
||||
|
||||
case MODE_SHUTTER:
|
||||
params["mode"] = "shutter";
|
||||
break;
|
||||
|
||||
case MODE_UNKNOWN:
|
||||
default:
|
||||
return;
|
||||
|
@ -275,6 +285,8 @@ void Camera::parseList(QString cgi, QByteArray body)
|
|||
mImages.insert(img.path(), img);
|
||||
}
|
||||
}
|
||||
|
||||
emit imagesUpdated(mImages);
|
||||
}
|
||||
|
||||
void Camera::parseImage(QString cgi, QByteArray body)
|
||||
|
@ -313,7 +325,7 @@ void Camera::parseCapacity(QDomDocument body)
|
|||
{
|
||||
QDomElement elm = body.firstChildElement("unused");
|
||||
if (!elm.isNull()) {
|
||||
mUnusedCapacity = elm.text().toUInt();
|
||||
mUnusedCapacity = elm.text().toULong();
|
||||
|
||||
emit capacityUpdated(mUnusedCapacity);
|
||||
}
|
||||
|
@ -333,15 +345,19 @@ void Camera::parseConnectMode(QDomDocument body)
|
|||
else if (elm.text() == "shared")
|
||||
mConnectMode = CONNECT_SHARED;
|
||||
else
|
||||
qWarning() << "[libqt-omd] Warning: unknown connectMode:" << elm.text();
|
||||
}
|
||||
mConnectMode = CONNECT_UNKNOWN;
|
||||
|
||||
emit connected(mConnectMode);
|
||||
}
|
||||
}
|
||||
|
||||
void Camera::parseProperties(QDomDocument body)
|
||||
{
|
||||
Q_UNUSED(body)
|
||||
// FIXME implement
|
||||
QDomElement elm = body.firstChildElement("desclist");
|
||||
if (!elm.isNull()) {
|
||||
mCamProperties.parse(elm);
|
||||
emit propertiesUpdated(&mCamProperties);
|
||||
}
|
||||
}
|
||||
|
||||
void Camera::parseTakeMisc(QDomDocument body)
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include <QHostAddress>
|
||||
#include <QImage>
|
||||
#include <QUrl>
|
||||
#include <QDateTime>
|
||||
#include <QtXml/QDomDocument>
|
||||
#include <QNetworkAccessManager>
|
||||
|
@ -35,6 +36,7 @@
|
|||
|
||||
#include "properties.h"
|
||||
#include "image.h"
|
||||
|
||||
class QNetworkAccessManager;
|
||||
class QNetworkReply;
|
||||
class QNetworkRequest;
|
||||
|
@ -42,6 +44,7 @@ class QNetworkRequest;
|
|||
namespace Oi {
|
||||
class LiveView;
|
||||
class Camera;
|
||||
class Image;
|
||||
}
|
||||
|
||||
class Oi::Camera : public QObject
|
||||
|
@ -81,26 +84,26 @@ public:
|
|||
void requestCamInfo();
|
||||
void requestCapacity();
|
||||
void requestConnectMode();
|
||||
void requestCommandList();
|
||||
void requestImageList(QString dir = "/DCIM/100OLYMP", bool reserved = false);
|
||||
void requestCommands();
|
||||
void requestProperties();
|
||||
void requestImages(QString dir = "/DCIM/100OLYMP", bool reserved = false);
|
||||
void requestImage(QString name = QString(), QSize resolution = QSize(-1, -1));
|
||||
|
||||
/* Synchronous getters */
|
||||
QString getCamInfo();
|
||||
unsigned getCapacity();
|
||||
enum ConnectMode getConnectMode();
|
||||
void /* FIXME */ getCommandList();
|
||||
QList<QString> getImageList(bool reserved = false);
|
||||
QImage getImage(QString name = QString(), QSize resolution = QSize());
|
||||
QUrl getUrl() const;
|
||||
QString camModel() const { return mCamModel; }
|
||||
unsigned unusedCapacity() const { return mUnusedCapacity; }
|
||||
QHash<QString, Image> images() const { return mImages; }
|
||||
QImage image(QString name = QString(), QSize resolution = QSize()) const;
|
||||
QUrl url() const { return QUrl(QString("http://") + mAddress.toString()); }
|
||||
|
||||
bool isOnline();
|
||||
enum ConnectMode connectMode() const { return mConnectMode; }
|
||||
enum CamMode camMode() const { return mCamMode; }
|
||||
const Oi::Properties * properties() const { return &mCamProperties; }
|
||||
|
||||
Oi::LiveView * startLiveView(QSize resolution = QSize(640, 480), int port = 22222);
|
||||
void stopLiveView();
|
||||
|
||||
/* Cached getters */
|
||||
bool isOnline();
|
||||
enum CamMode camMode();
|
||||
|
||||
public slots:
|
||||
void initialize();
|
||||
void switchCamMode(enum CamMode mode);
|
||||
|
@ -112,8 +115,10 @@ public slots:
|
|||
|
||||
signals:
|
||||
void receivedImage(QImage);
|
||||
void capacityUpdated(long unsigned);
|
||||
void changedProperty(QString key, QString value);
|
||||
void imagesUpdated(QHash<QString, Image>);
|
||||
void capacityUpdated(unsigned long c);
|
||||
void propertyChanged(Oi::Property *prop);
|
||||
void propertiesUpdated(Oi::Properties *props);
|
||||
void changedMode(enum CamMode);
|
||||
void modelUpdated(QString);
|
||||
void poweredOff();
|
||||
|
@ -151,16 +156,18 @@ protected:
|
|||
QList<QNetworkReply *> mPendingReplies;
|
||||
QNetworkAccessManager mNetworkManager;
|
||||
|
||||
Oi::Properties mCamProperties;
|
||||
|
||||
/* Properties */
|
||||
enum CamMode mCamMode;
|
||||
enum ConnectMode mConnectMode;
|
||||
|
||||
QString mCamModel;
|
||||
long unsigned mUnusedCapacity;
|
||||
unsigned long mUnusedCapacity;
|
||||
|
||||
QDomDocument mCommandList;
|
||||
|
||||
QHash<QString, Image> mImages;
|
||||
QHash<QString, Image> mImages;
|
||||
|
||||
/* Constants */
|
||||
static const QString cUserAgent;
|
||||
|
|
|
@ -36,7 +36,6 @@ Image::Image() :
|
|||
|
||||
Image::Image(const Image &img) :
|
||||
mCam(img.mCam),
|
||||
mPixels(img.mPixels),
|
||||
mPath(img.mPath),
|
||||
mDate(img.mDate),
|
||||
mAttributes(img.mAttributes),
|
||||
|
|
|
@ -72,8 +72,6 @@ class Oi::Image : public QImage
|
|||
|
||||
Oi::Camera *mCam;
|
||||
|
||||
QMap<QSize, QImage> mPixels;
|
||||
|
||||
QString mPath;
|
||||
QDateTime mDate;
|
||||
|
||||
|
|
59
libqt-omd/imagelistmodel.cpp
Normal file
59
libqt-omd/imagelistmodel.cpp
Normal file
|
@ -0,0 +1,59 @@
|
|||
#include "imagelistmodel.h"
|
||||
#include "image.h"
|
||||
#include "camera.h"
|
||||
|
||||
using namespace Oi;
|
||||
|
||||
ImageListModel::ImageListModel(Camera *cam, QObject *parent) :
|
||||
QAbstractTableModel(parent),
|
||||
mCam(cam)
|
||||
{
|
||||
connect(cam, &Oi::Camera::imagesUpdated, this, [&](QHash<QString, Image>) {
|
||||
emit dataChanged(index(0, 0), index(rowCount()-1, columnCount()-1));
|
||||
});
|
||||
}
|
||||
|
||||
QVariant ImageListModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
|
||||
switch (section) {
|
||||
case 0: return QString(tr("Path"));
|
||||
case 1: return QString(tr("Size"));
|
||||
case 2: return QString(tr("Marked"));
|
||||
case 3: return QString(tr("Date"));
|
||||
case 4: return QString(tr("Attributes"));
|
||||
default: return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
int ImageListModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
return mCam->images().count();
|
||||
}
|
||||
|
||||
int ImageListModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
|
||||
QVariant ImageListModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
// if (!index.isValid())
|
||||
// return QVariant();
|
||||
|
||||
const Image &img = mCam->images().values().at(index.row());
|
||||
|
||||
if (role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
|
||||
switch (index.column()) {
|
||||
case 0: return img.path();
|
||||
case 1: return img.size();
|
||||
case 2: return img.marked();
|
||||
case 3: return img.dateTime().toString();
|
||||
case 4: return img.attributes();
|
||||
default: return QVariant();
|
||||
}
|
||||
}
|
33
libqt-omd/imagelistmodel.h
Normal file
33
libqt-omd/imagelistmodel.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
#ifndef IMAGETABLEMODEL_H
|
||||
#define IMAGETABLEMODEL_H
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
|
||||
namespace Oi {
|
||||
class Camera;
|
||||
class ImageListModel;
|
||||
}
|
||||
|
||||
class Oi::ImageListModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ImageListModel(Camera *cam, QObject *parent = 0);
|
||||
|
||||
// Header:
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||
|
||||
// Basic functionality:
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
protected:
|
||||
Oi::Camera *mCam;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif // IMAGELISTMODEL_H
|
|
@ -12,13 +12,15 @@ TEMPLATE = lib
|
|||
SOURCES += camera.cpp \
|
||||
liveview.cpp \
|
||||
properties.cpp \
|
||||
image.cpp
|
||||
image.cpp \
|
||||
imagelistmodel.cpp
|
||||
|
||||
HEADERS += camera.h \
|
||||
liveview.h \
|
||||
properties.h \
|
||||
image.h \
|
||||
helpers.h
|
||||
helpers.h \
|
||||
imagelistmodel.h
|
||||
|
||||
unix {
|
||||
target.path = /usr/lib
|
||||
|
|
|
@ -28,5 +28,66 @@
|
|||
using namespace Oi;
|
||||
|
||||
LiveView::LiveView(Camera *c) :
|
||||
mCam(c)
|
||||
mCam(c),
|
||||
mSocket(this)
|
||||
{ }
|
||||
|
||||
void LiveView::start()
|
||||
{
|
||||
mSocket->bind(QHostAddress::LocalHost, mPort);
|
||||
|
||||
mCam->get()
|
||||
|
||||
connect(mSocket, &QUdpSocket::readyRead, this, &LiveView::readPendingChunks);
|
||||
}
|
||||
|
||||
void LiveView::stop()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void LiveView::readPendingChunks()
|
||||
{
|
||||
while (udpSocket->hasPendingDatagrams()) {
|
||||
QByteArray datagram;
|
||||
|
||||
datagram.resize(udpSocket->pendingDatagramSize());
|
||||
|
||||
QHostAddress sender;
|
||||
quint16 senderPort;
|
||||
|
||||
mSocket->readDatagram(datagram.data(), datagram.size(), &sender, &senderPort);
|
||||
|
||||
processChunk(datagram);
|
||||
}
|
||||
}
|
||||
|
||||
void LiveView::processChunk(QByteArray chunk)
|
||||
{
|
||||
const char *data = chunk.constData();
|
||||
const char *payload = data + 12;
|
||||
|
||||
const quint16 *packetType = reinterpret_cast<const quint16 *>(data + 0);
|
||||
const quint16 *chunkNo = reinterpret_cast<const quint16 *>(data + 2);
|
||||
const quint32 *frameId = reinterpret_cast<const quint32 *>(data + 4);
|
||||
const quint32 *streamId = reinterpret_cast<const quint16 *>(data + 8);
|
||||
|
||||
qDebug() << "packetType: " << *packetType << " chunkNo: " << *chunkNo << " frameId: " << *frameId << " streamId: " << *streamId;
|
||||
|
||||
switch (*packetType) {
|
||||
case 0x9060: /* Start of Frame */
|
||||
break;
|
||||
|
||||
case 0x8060: /* Middle of Frame */
|
||||
break;
|
||||
|
||||
case 0x80e0: /* End of Frame */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void LiveView::processFrame()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,9 @@
|
|||
#ifndef LIVEVIEW_H
|
||||
#define LIVEVIEW_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QUdpSocket>
|
||||
#include <QByteArray>
|
||||
|
||||
#include "camera.h"
|
||||
|
||||
|
@ -36,19 +38,30 @@ namespace Oi {
|
|||
class LiveView;
|
||||
}
|
||||
|
||||
class Oi::LiveView
|
||||
class Oi::LiveView : QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
LiveView(Oi::Camera *c);
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
signals:
|
||||
void newFrame();
|
||||
|
||||
protected:
|
||||
void readPendingChunks();
|
||||
void processChunk(QByteArray);
|
||||
|
||||
int mPort = 48482;
|
||||
QUdpSocket mSocket;
|
||||
|
||||
Camera *mCam;
|
||||
quint32 mStreamId;
|
||||
quint32 mFrameId;
|
||||
|
||||
Oi::Camera *mCam;
|
||||
};
|
||||
|
||||
#endif // LIVEVIEW_H
|
||||
|
|
|
@ -29,24 +29,32 @@
|
|||
|
||||
using namespace Oi;
|
||||
|
||||
Properties::Properties(QDomNode desclist)
|
||||
Properties::Properties(Camera *c) :
|
||||
mCam(c)
|
||||
{ }
|
||||
|
||||
void Properties::parse(QDomNode desclist)
|
||||
{
|
||||
QDomNode desc = desclist.firstChild();
|
||||
QDomNode desc = desclist.firstChildElement("desc");
|
||||
while (!desc.isNull()) {
|
||||
Property prop(desc);
|
||||
Property prop(mCam, desc);
|
||||
|
||||
if (prop.isValid())
|
||||
mProperties[prop.mKey] = prop;
|
||||
insert(prop.mKey, prop);
|
||||
|
||||
desc = desc.nextSibling();
|
||||
desc = desc.nextSiblingElement("desc");
|
||||
}
|
||||
}
|
||||
|
||||
Property::Property(QDomNode desc)
|
||||
Property::Property(Camera *c, QDomNode desc) :
|
||||
mCam(c)
|
||||
{
|
||||
mKey = desc.firstChildElement("propname").text();
|
||||
mValue = desc.firstChildElement("value").text();
|
||||
mValid = desc.firstChildElement("enum").text().split(' ');
|
||||
|
||||
QDomElement validEnum = desc.firstChildElement("enum");
|
||||
if (!validEnum.isNull())
|
||||
mValid = validEnum.text().split(' ');
|
||||
|
||||
QString attr = desc.firstChildElement("attribute").text();
|
||||
if (attr.contains("set"))
|
||||
|
|
|
@ -23,32 +23,33 @@
|
|||
* along with libqt-omd. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef PROPERTIES_H
|
||||
#define PROPERTIES_H
|
||||
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
#include "camera.h"
|
||||
#include <QStringList>
|
||||
#include <QDomNode>
|
||||
|
||||
#include "image.h"
|
||||
|
||||
namespace Oi {
|
||||
class Camera;
|
||||
class Property;
|
||||
class Properties;
|
||||
}
|
||||
|
||||
class Oi::Properties
|
||||
class Oi::Properties :
|
||||
public QMap<QString, Oi::Property>
|
||||
{
|
||||
public:
|
||||
Properties(QDomNode desclist);
|
||||
Properties(Oi::Camera *c);
|
||||
|
||||
void parse(QDomNode desclist);
|
||||
Oi::Property& operator[](const QString &key);
|
||||
|
||||
protected:
|
||||
Oi::Camera *mCam;
|
||||
|
||||
QMap<QString, Oi::Property> mProperties;
|
||||
};
|
||||
|
||||
class Oi::Property
|
||||
|
@ -64,15 +65,20 @@ class Oi::Property
|
|||
|
||||
public:
|
||||
Property() { }
|
||||
Property(QDomElement desc);
|
||||
|
||||
Property& operator =(const QString &value);
|
||||
operator QString();
|
||||
|
||||
bool isValid(QString value = QString());
|
||||
|
||||
/* Getter */
|
||||
const QString & key() const { return mKey; }
|
||||
const QString & value() const { return mValue; }
|
||||
const QStringList & valids() const { return mValid; }
|
||||
|
||||
protected:
|
||||
Property(QDomNode desc);
|
||||
Property(Oi::Camera *c, QDomNode desc);
|
||||
|
||||
Oi::Camera *mCam;
|
||||
|
||||
QStringList mValid;
|
||||
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
#include <QMenu>
|
||||
#include <QDesktopServices>
|
||||
#include <QUrl>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "viewer.h"
|
||||
#include "mainwindow.h"
|
||||
#include "camera.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
@ -13,38 +14,25 @@ int main(int argc, char *argv[])
|
|||
QSystemTrayIcon tray(&app);
|
||||
QMenu menu;
|
||||
|
||||
Viewer viewer;
|
||||
Oi::Camera cam;
|
||||
MainWindow win(&cam);
|
||||
|
||||
/* Actions */
|
||||
QAction showLiveView("Show Live View", &tray);
|
||||
QObject::connect(&showLiveView, &QAction::triggered, [&]() {
|
||||
viewer.show();
|
||||
});
|
||||
|
||||
QAction openBrowser("Open Browser", &tray);
|
||||
QObject::connect(&openBrowser, &QAction::triggered, [&]() {
|
||||
QDesktopServices::openUrl(cam.getUrl());
|
||||
});
|
||||
|
||||
QAction openWindow("Open", &tray);
|
||||
QAction closeApp("Quit", &tray);
|
||||
QObject::connect(&closeApp, &QAction::triggered, [&]() {
|
||||
app.quit();
|
||||
});
|
||||
QAction openBrowser("Open Browser", &tray);
|
||||
|
||||
/* Camera Signals */
|
||||
QAction sizeInfo("Capacity: ?", &tray);
|
||||
QObject::connect(&cam, &Oi::Camera::capacityUpdated, [&](int cap) {
|
||||
sizeInfo.setText(QString("Capacity: %1").arg(cap));
|
||||
tray.setContextMenu(&menu);
|
||||
QObject::connect(&closeApp, &QAction::triggered, &win, &QMainWindow::close);
|
||||
QObject::connect(&openWindow, &QAction::triggered, &win, &QMainWindow::show);
|
||||
|
||||
QObject::connect(&openBrowser, &QAction::triggered, [&]() {
|
||||
QDesktopServices::openUrl(cam.url());
|
||||
});
|
||||
|
||||
/* Context Menu */
|
||||
menu.addAction(&showLiveView);
|
||||
menu.addAction(&openWindow);
|
||||
menu.addAction(&openBrowser);
|
||||
menu.addSeparator();
|
||||
menu.addAction(&sizeInfo);
|
||||
menu.addSeparator();
|
||||
menu.addAction(&closeApp);
|
||||
|
||||
QIcon icon(":/icon/libqt-omd_gray.png");
|
||||
|
@ -52,5 +40,11 @@ int main(int argc, char *argv[])
|
|||
tray.setContextMenu(&menu);
|
||||
tray.show();
|
||||
|
||||
/* Initialize camera */
|
||||
if (cam.isOnline())
|
||||
cam.initialize();
|
||||
else
|
||||
QMessageBox::critical(&win, "Error", "Failed to connect to camera!");
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
|
92
test/mainwindow.cpp
Normal file
92
test/mainwindow.cpp
Normal file
|
@ -0,0 +1,92 @@
|
|||
#include <QComboBox>
|
||||
|
||||
#include <utility>
|
||||
using std::make_pair;
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
MainWindow::MainWindow(Oi::Camera *c, QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::MainWindow),
|
||||
cam(c),
|
||||
imageListModel(c, parent)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->imgTable->setModel(&imageListModel);
|
||||
|
||||
connect(cam, &Oi::Camera::propertiesUpdated, this, &MainWindow::updateProperties);
|
||||
connect(cam, &Oi::Camera::modelUpdated, [&](QString model) {
|
||||
ui->lblModel->setText(QString("Olympus OM-D ") + model);
|
||||
});
|
||||
connect(cam, &Oi::Camera::imagesUpdated, [&](QHash<QString, Oi::Image> imgs) {
|
||||
ui->lblImages->setText(QString("%1").arg(imgs.count()));
|
||||
});
|
||||
connect(cam, &Oi::Camera::capacityUpdated, [&](unsigned long c) {
|
||||
ui->lblCapacity->setText(QString("%1 MB").arg(c / (1 << 20)));
|
||||
});
|
||||
connect(cam, &Oi::Camera::connected, [&](enum Oi::Camera::ConnectMode m) {
|
||||
QLabel *l = ui->lblConnectMode;
|
||||
switch (m) {
|
||||
case Oi::Camera::CONNECT_PRIVATE: l->setText(tr("Private")); break;
|
||||
case Oi::Camera::CONNECT_SHARED: l->setText(tr("Shared")); break;
|
||||
case Oi::Camera::CONNECT_UNKNOWN: l->setText(tr("Unknown")); break;
|
||||
}
|
||||
});
|
||||
|
||||
propInfo["touchactiveframe"] = qMakePair(tr(""), tr(""));
|
||||
propInfo["takemode"] = qMakePair(tr("Shooting Mode"), tr(""));
|
||||
propInfo["noisereduction"] = qMakePair(tr("Noise Reduction"), tr(""));
|
||||
propInfo["lowvibtime"] = qMakePair(tr(""), tr(""));
|
||||
propInfo["bulbtimelimit"] = qMakePair(tr(""), tr(""));
|
||||
propInfo["digitaltelecon"] = qMakePair(tr("Digital Tele-converter"), tr(""));
|
||||
propInfo["drivemode"] = qMakePair(tr(""), tr(""));
|
||||
propInfo["focalvalue"] = qMakePair(tr(""), tr(""));
|
||||
propInfo["expcomp"] = qMakePair(tr("Exposure Compensation"), tr(""));
|
||||
propInfo["shuttspeedvalue"] = qMakePair(tr("Shutter Speed"), tr(""));
|
||||
propInfo["isospeedvalue"] = qMakePair(tr("ISO Sensivity"), tr(""));
|
||||
propInfo["wbvalue"] = qMakePair(tr("White Balance"), tr(""));
|
||||
propInfo["artfilter"] = qMakePair(tr("Art Filter"), tr(""));
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void MainWindow::updateProperties(Oi::Properties *props)
|
||||
{
|
||||
QGroupBox *wdg = ui->grpProperties;
|
||||
|
||||
/* Create layout if non-existant */
|
||||
QFormLayout *layout = qobject_cast<QFormLayout*>(wdg->layout());
|
||||
if (!layout) {
|
||||
layout = new QFormLayout();
|
||||
wdg->setLayout(layout);
|
||||
}
|
||||
|
||||
/* Remove old properties */
|
||||
while (layout->count()) {
|
||||
QLayoutItem *item = layout->takeAt(0);
|
||||
|
||||
delete item->widget();
|
||||
delete item;
|
||||
}
|
||||
|
||||
for (Oi::Property &prop : props->values()) {
|
||||
QLabel *lbl = new QLabel(wdg);
|
||||
lbl->setText(propInfo.value(prop.key()).first);
|
||||
lbl->setToolTip(propInfo.value(prop.key()).second);
|
||||
|
||||
QComboBox *cbox = new QComboBox(wdg);
|
||||
cbox->addItems(prop.valids());
|
||||
cbox->setCurrentText(prop.value());
|
||||
|
||||
connect(cbox, &QComboBox::currentTextChanged, [&](QString value) {
|
||||
prop = value;
|
||||
});
|
||||
|
||||
layout->addRow(lbl, cbox);
|
||||
}
|
||||
}
|
32
test/mainwindow.h
Normal file
32
test/mainwindow.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
#include <image.h>
|
||||
#include <camera.h>
|
||||
#include <imagelistmodel.h>
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(Oi::Camera *c, QWidget *parent = 0);
|
||||
~MainWindow();
|
||||
|
||||
protected:
|
||||
void updateProperties(Oi::Properties *props);
|
||||
|
||||
Ui::MainWindow *ui;
|
||||
Oi::Camera *cam;
|
||||
Oi::ImageListModel imageListModel;
|
||||
|
||||
QMap<QString, QPair<QString, QString>> propInfo;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
176
test/mainwindow.ui
Normal file
176
test/mainwindow.ui
Normal file
|
@ -0,0 +1,176 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tabImages">
|
||||
<attribute name="title">
|
||||
<string>Images</string>
|
||||
</attribute>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QTableView" name="imgTable"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="imgPreview">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tabProperties">
|
||||
<attribute name="title">
|
||||
<string>Camera Properties</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="lblModelDesc">
|
||||
<property name="text">
|
||||
<string>Model</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="lblModel">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="lblCapacityDesc">
|
||||
<property name="text">
|
||||
<string>Unused Capacity</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="lblConnectModeDesc">
|
||||
<property name="text">
|
||||
<string>Connection Mode</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="lblCapacity">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLabel" name="lblConnectMode">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="lblImagesDesc">
|
||||
<property name="text">
|
||||
<string>Images</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLabel" name="lblImages">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>345</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="grpProperties">
|
||||
<property name="title">
|
||||
<string>Settings</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tabLiveView">
|
||||
<attribute name="title">
|
||||
<string>Live View</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
<property name="title">
|
||||
<string>File</string>
|
||||
</property>
|
||||
<addaction name="actionQuit"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menu">
|
||||
<property name="title">
|
||||
<string>?</string>
|
||||
</property>
|
||||
<addaction name="actionAbout"/>
|
||||
</widget>
|
||||
<addaction name="menuFile"/>
|
||||
<addaction name="menu"/>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
<action name="actionQuit">
|
||||
<property name="text">
|
||||
<string>Quit</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionAbout">
|
||||
<property name="text">
|
||||
<string>About</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -13,9 +13,10 @@ TEMPLATE = app
|
|||
|
||||
|
||||
SOURCES += main.cpp\
|
||||
viewer.cpp
|
||||
mainwindow.cpp
|
||||
|
||||
HEADERS += viewer.h
|
||||
HEADERS += \
|
||||
mainwindow.h
|
||||
|
||||
win32: CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../libqt-omd/release/ -llibqt-omd
|
||||
else:win32: CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../libqt-omd/debug/ -llibqt-omd
|
||||
|
@ -28,3 +29,6 @@ CONFIG += c++11
|
|||
|
||||
RESOURCES += \
|
||||
images.qrc
|
||||
|
||||
FORMS += \
|
||||
mainwindow.ui
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
#include "viewer.h"
|
||||
|
||||
Viewer::Viewer(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
}
|
||||
|
||||
Viewer::~Viewer()
|
||||
{
|
||||
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
#ifndef VIEWER_H
|
||||
#define VIEWER_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class Viewer : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Viewer(QWidget *parent = 0);
|
||||
~Viewer();
|
||||
};
|
||||
|
||||
#endif // VIEWER_H
|
Loading…
Add table
Reference in a new issue