[Digikam-devel] extragear/graphics/digikam/utilities/cameragui
Gilles Caulier
caulier.gilles at gmail.com
Thu Sep 6 10:58:32 BST 2007
SVN commit 708999 by cgilles:
digiKam from trunk (KDE4) : Camera GUI : new option to capture a picture from camera.
Only Gphoto2 camera drivers (PTP include) can support this feature. Of course, your camera must
be able to support capture mode. A new dialog will display in live the
lens preview from camera. When you want to take the picture, just press "Capture" button. A new
picture file will be recorded on camera media following camera settings.
This tool can be usefull if you perform nature or astro digital photography.
A screenshot of the new Camera Capture tool in action is given at this url:
http://digikam3rdparty.free.fr/Screenshots/digikamKDE4_06.png
CCMAIL: digikam-devel at kde.org
M +35 -1 cameracontroller.cpp
M +3 -0 cameracontroller.h
M +19 -1 cameraui.cpp
M +1 -0 cameraui.h
M +5 -1 cameraui.rc
M +2 -0 camerauiprivate.h
M +3 -0 dkcamera.h
M +139 -0 gpcamera.cpp
M +2 -0 gpcamera.h
M +4 -0 umscamera.h
--- trunk/extragear/graphics/digikam/utilities/cameragui/cameracontroller.cpp #708998:708999
@@ -79,7 +79,9 @@
gp_thumbnail,
gp_exif,
gp_open,
- gp_freeSpace
+ gp_freeSpace,
+ gp_preview,
+ gp_capture
};
Action action;
@@ -286,6 +288,22 @@
emit signalFreeSpace(kBSize, kBAvail);
break;
}
+ case(CameraCommand::gp_preview):
+ {
+ sendInfo(i18n("Getting preview..."));
+ QImage preview;
+ d->camera->getPreview(preview);
+ emit signalPreview(preview);
+ break;
+ }
+ case(CameraCommand::gp_capture):
+ {
+ sendInfo(i18n("Capture picture..."));
+ GPItemInfo itemInfo;
+ d->camera->capture(itemInfo);
+ emit signalUploaded(itemInfo);
+ break;
+ }
case(CameraCommand::gp_listfolders):
{
sendInfo(i18n("Listing folders..."));
@@ -858,6 +876,22 @@
addCommand(cmd);
}
+void CameraController::getPreview()
+{
+ d->canceled = false;
+ CameraCommand *cmd = new CameraCommand;
+ cmd->action = CameraCommand::gp_preview;
+ addCommand(cmd);
+}
+
+void CameraController::capture()
+{
+ d->canceled = false;
+ CameraCommand *cmd = new CameraCommand;
+ cmd->action = CameraCommand::gp_capture;
+ addCommand(cmd);
+}
+
void CameraController::upload(const QFileInfo& srcFileInfo, const QString& destFile, const QString& destFolder)
{
d->canceled = false;
--- trunk/extragear/graphics/digikam/utilities/cameragui/cameracontroller.h #708998:708999
@@ -62,6 +62,8 @@
void getThumbnail(const QString& folder, const QString& file);
void getExif(const QString& folder, const QString& file);
void getCameraInformations();
+ void getPreview();
+ void capture();
QString getCameraPath();
QString getCameraTitle();
DKCamera::CameraDriverType cameraDriverType();
@@ -81,6 +83,7 @@
void signalCameraInformations(const QString& summary, const QString& manual,
const QString& about);
void signalFreeSpace(unsigned long kBSize, unsigned long kBAvail);
+ void signalPreview(const QImage& preview);
void signalConnected(bool val);
void signalFolderList(const QStringList& folderList);
--- trunk/extragear/graphics/digikam/utilities/cameragui/cameraui.cpp #708998:708999
@@ -100,6 +100,7 @@
#include "freespacewidget.h"
#include "collectionscanner.h"
#include "collectionmanager.h"
+#include "capturedlg.h"
#include "camerafolderdialog.h"
#include "camerainfodialog.h"
#include "cameraiconview.h"
@@ -289,12 +290,18 @@
// -----------------------------------------------------------------
- d->cameraInfoAction = new KAction(KIcon("camera-photo"), i18n("Camera Information"), this);
+ d->cameraInfoAction = new KAction(KIcon("camera-photo"), i18n("Information"), this);
connect(d->cameraInfoAction, SIGNAL(triggered()), this, SLOT(slotInformations()));
actionCollection()->addAction("cameraui_camerainfo", d->cameraInfoAction);
// -----------------------------------------------------------------
+ d->cameraCaptureAction = new KAction(KIcon("camera"), i18n("Capture"), this);
+ connect(d->cameraCaptureAction, SIGNAL(triggered()), this, SLOT(slotCapture()));
+ actionCollection()->addAction("cameraui_cameracapture", d->cameraCaptureAction);
+
+ // -----------------------------------------------------------------
+
actionCollection()->addAction(KStandardAction::Close, "cameraui_close",
this, SLOT(close()));
@@ -815,6 +822,7 @@
d->selectNewItemsAction->setEnabled(true);
d->lockAction->setEnabled(true);
d->cameraInfoAction->setEnabled(true);
+ d->cameraCaptureAction->setEnabled(true);
d->anim->stop();
d->statusProgressBar->progressBarMode(StatusProgressBar::TextMode, i18n("Ready"));
@@ -854,6 +862,7 @@
d->selectNewItemsAction->setEnabled(false);
d->lockAction->setEnabled(false);
d->cameraInfoAction->setEnabled(false);
+ d->cameraCaptureAction->setEnabled(false);
}
}
@@ -969,6 +978,15 @@
d->statusProgressBar->setProgressValue(curr+1);
}
+void CameraUI::slotCapture()
+{
+ if (d->busy)
+ return;
+
+ CaptureDlg *captureDlg = new CaptureDlg(this, d->controller, d->cameraTitle);
+ captureDlg->show();
+}
+
void CameraUI::slotInformations()
{
if (d->busy)
--- trunk/extragear/graphics/digikam/utilities/cameragui/cameraui.h #708998:708999
@@ -115,6 +115,7 @@
void slotBusy(bool val);
void slotErrorMsg(const QString& msg);
void slotInformations();
+ void slotCapture();
void slotCameraInformations(const QString&, const QString&, const QString&);
void slotCameraFreeSpaceInfo(unsigned long kBSize, unsigned long kBAvail);
--- trunk/extragear/graphics/digikam/utilities/cameragui/cameraui.rc #708998:708999
@@ -1,5 +1,5 @@
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
-<gui version="12" name="cameraui" >
+<gui version="14" name="cameraui" >
<MenuBar>
@@ -7,6 +7,8 @@
<Action name="cameraui_cancelprocess" />
<Action name="cameraui_camerainfo" />
<Separator />
+ <Action name="cameraui_cameracapture" />
+ <Separator />
<Action name="cameraui_close" />
</Menu>
@@ -69,6 +71,8 @@
<Action name="cameraui_imageupload" />
<Action name="cameraui_imagelock" />
<Separator/>
+ <Action name="cameraui_cameracapture" />
+ <Separator/>
<Action name="cameraui_fullscreen" />
<Merge />
<WeakSeparator/>
--- trunk/extragear/graphics/digikam/utilities/cameragui/camerauiprivate.h #708998:708999
@@ -93,6 +93,7 @@
deleteSelectedAction = 0;
deleteAllAction = 0;
cameraInfoAction = 0;
+ cameraCaptureAction = 0;
statusProgressBar = 0;
statusNavigateBar = 0;
statusZoomBar = 0;
@@ -157,6 +158,7 @@
KAction *deleteSelectedAction;
KAction *deleteAllAction;
KAction *cameraInfoAction;
+ KAction *cameraCaptureAction;
KAction *uploadAction;
KAction *lockAction;
KAction *selectAllAction;
--- trunk/extragear/graphics/digikam/utilities/cameragui/dkcamera.h #708998:708999
@@ -67,6 +67,9 @@
virtual bool getThumbnail(const QString& folder, const QString& itemName, QImage& thumbnail) = 0;
virtual bool getExif(const QString& folder, const QString& itemName, char **edata, int& esize) = 0;
+ virtual bool getPreview(QImage& preview) = 0;
+ virtual bool capture(GPItemInfo& itemInfo) = 0;
+
virtual bool downloadItem(const QString& folder, const QString& itemName, const QString& saveFile) = 0;
virtual bool deleteItem(const QString& folder, const QString& itemName) = 0;
virtual bool uploadItem(const QString& folder, const QString& itemName, const QString& localFile,
--- trunk/extragear/graphics/digikam/utilities/cameragui/gpcamera.cpp #708998:708999
@@ -419,6 +419,145 @@
return true;
}
+bool GPCamera::getPreview(QImage& preview)
+{
+ int errorCode;
+ CameraFile *cfile;
+ const char *data;
+ unsigned long int size;
+
+ gp_file_new(&cfile);
+
+ if (m_status)
+ {
+ delete m_status;
+ m_status = 0;
+ }
+
+ m_status = new GPStatus;
+
+ errorCode = gp_camera_capture_preview(d->camera, cfile, m_status->context);
+ if (errorCode != GP_OK)
+ {
+ DDebug() << "Failed to initialize camera preview mode!" << endl;
+ printGphotoErrorDescription(errorCode);
+ gp_file_unref(cfile);
+ delete m_status;
+ m_status = 0;
+ return false;
+ }
+
+ delete m_status;
+ m_status = 0;
+
+ errorCode = gp_file_get_data_and_size(cfile, &data, &size);
+ if (errorCode != GP_OK)
+ {
+ DDebug() << "Failed to get preview from camera!" << endl;
+ printGphotoErrorDescription(errorCode);
+ gp_file_unref(cfile);
+ return false;
+ }
+
+ preview.loadFromData((const uchar*) data, (uint) size);
+
+ gp_file_unref(cfile);
+ return true;
+}
+
+bool GPCamera::capture(GPItemInfo& itemInfo)
+{
+ int errorCode;
+ CameraFilePath path;
+
+ if (m_status)
+ {
+ delete m_status;
+ m_status = 0;
+ }
+
+ m_status = new GPStatus;
+
+ errorCode = gp_camera_capture(d->camera, GP_CAPTURE_IMAGE, &path, m_status->context);
+ if (errorCode != GP_OK)
+ {
+ DDebug() << "Failed to take camera capture!" << endl;
+ printGphotoErrorDescription(errorCode);
+ delete m_status;
+ m_status = 0;
+ return false;
+ }
+
+ // Get new camera item information.
+
+ itemInfo.folder = QString(path.folder);
+ itemInfo.name = QString(path.name);
+
+ CameraFileInfo info;
+ errorCode = gp_camera_file_get_info(d->camera, QFile::encodeName(itemInfo.folder),
+ QFile::encodeName(itemInfo.name), &info,
+ m_status->context);
+ if (errorCode != GP_OK)
+ {
+ DDebug() << "Failed to get camera item information!" << endl;
+ printGphotoErrorDescription(errorCode);
+ delete m_status;
+ m_status = 0;
+ return false;
+ }
+
+ itemInfo.mtime = -1;
+ itemInfo.mime = "";
+ itemInfo.size = -1;
+ itemInfo.width = -1;
+ itemInfo.height = -1;
+ itemInfo.downloaded = GPItemInfo::DownloadUnknow;
+ itemInfo.readPermissions = -1;
+ itemInfo.writePermissions = -1;
+
+ /* The mime type returned by Gphoto2 is dummy with all RAW files.
+ if (info.file.fields & GP_FILE_INFO_TYPE)
+ itemInfo.mime = info.file.type;*/
+
+ itemInfo.mime = mimeType(itemInfo.name.section('.', -1).toLower());
+
+ if (info.file.fields & GP_FILE_INFO_MTIME)
+ itemInfo.mtime = info.file.mtime;
+
+ if (info.file.fields & GP_FILE_INFO_SIZE)
+ itemInfo.size = info.file.size;
+
+ if (info.file.fields & GP_FILE_INFO_WIDTH)
+ itemInfo.width = info.file.width;
+
+ if (info.file.fields & GP_FILE_INFO_HEIGHT)
+ itemInfo.height = info.file.height;
+
+ if (info.file.fields & GP_FILE_INFO_STATUS)
+ {
+ if (info.file.status == GP_FILE_STATUS_DOWNLOADED)
+ itemInfo.downloaded = GPItemInfo::DownloadedYes;
+ else
+ itemInfo.downloaded = GPItemInfo::DownloadedNo;
+ }
+
+ if (info.file.fields & GP_FILE_INFO_PERMISSIONS)
+ {
+ if (info.file.permissions & GP_FILE_PERM_READ)
+ itemInfo.readPermissions = 1;
+ else
+ itemInfo.readPermissions = 0;
+ if (info.file.permissions & GP_FILE_PERM_DELETE)
+ itemInfo.writePermissions = 1;
+ else
+ itemInfo.writePermissions = 0;
+ }
+
+ delete m_status;
+ m_status = 0;
+ return true;
+}
+
void GPCamera::getAllFolders(const QString& rootFolder,
QStringList& folderList)
{
--- trunk/extragear/graphics/digikam/utilities/cameragui/gpcamera.h #708998:708999
@@ -88,6 +88,8 @@
DKCamera::CameraDriverType cameraDriverType(){ return DKCamera::GPhotoDriver; };
bool getFreeSpace(unsigned long& kBSize, unsigned long& kBAvail);
+ bool getPreview(QImage& preview);
+ bool capture(GPItemInfo& itemInfo);
// Public static methods shared with Setup Camera
--- trunk/extragear/graphics/digikam/utilities/cameragui/umscamera.h #708998:708999
@@ -65,6 +65,10 @@
bool getFreeSpace(unsigned long& kBSize, unsigned long& kBAvail);
+ // Methods not supported by UMS camera.
+ bool getPreview(QImage& /*preview*/){ return false; };
+ bool capture(GPItemInfo& /*itemInfo*/){ return false; };
+
DKCamera::CameraDriverType cameraDriverType(){ return DKCamera::UMSDriver; };
private:
More information about the Digikam-devel
mailing list