mirror of
https://bitbucket.org/smil3y/kde-playground.git
synced 2025-02-24 02:42:51 +00:00
kamera: format and indent
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
f81e445c07
commit
6176039dfc
2 changed files with 812 additions and 805 deletions
|
@ -62,20 +62,12 @@ extern "C"
|
|||
|
||||
#ifdef HAVE_GPHOTO2_5
|
||||
static void frontendCameraStatus(GPContext *context, const char *status, void *data);
|
||||
static unsigned int frontendProgressStart(
|
||||
GPContext *context, float totalsize, const char *status,
|
||||
void *data
|
||||
);
|
||||
static unsigned int frontendProgressStart(GPContext *context, float totalsize, const char *status, void *data);
|
||||
#else
|
||||
static void frontendCameraStatus(GPContext *context, const char *format, va_list args, void *data);
|
||||
static unsigned int frontendProgressStart(
|
||||
GPContext *context, float totalsize, const char *format,
|
||||
va_list args, void *data
|
||||
);
|
||||
static unsigned int frontendProgressStart(GPContext *context, float totalsize, const char *format, va_list args, void *data);
|
||||
#endif
|
||||
static void frontendProgressUpdate(
|
||||
GPContext *context, unsigned int id, float current, void *data
|
||||
);
|
||||
static void frontendProgressUpdate(GPContext *context, unsigned int id, float current, void *data);
|
||||
}
|
||||
|
||||
int kdemain(int argc, char **argv)
|
||||
|
@ -166,8 +158,7 @@ bool KameraProtocol::openCamera(QString &str) {
|
|||
kDebug(7123) << "KameraProtocol::openCamera at " << getpid();
|
||||
while (tries--) {
|
||||
ret = gp_camera_init(m_camera, m_context);
|
||||
if ( (ret == GP_ERROR_IO_USB_CLAIM) ||
|
||||
(ret == GP_ERROR_IO_LOCK)) {
|
||||
if (ret == GP_ERROR_IO_USB_CLAIM || ret == GP_ERROR_IO_LOCK) {
|
||||
// just create / touch if not there
|
||||
int fd = ::open(m_lockfile.toUtf8(),O_CREAT|O_WRONLY,0600);
|
||||
if (fd != -1) ::close(fd);
|
||||
|
@ -175,7 +166,9 @@ bool KameraProtocol::openCamera(QString &str) {
|
|||
kDebug(7123) << "openCamera at " << getpid() << "- busy, ret " << ret << ", trying again.";
|
||||
continue;
|
||||
}
|
||||
if (ret == GP_OK) break;
|
||||
if (ret == GP_OK) {
|
||||
break;
|
||||
}
|
||||
str = gp_result_as_string(ret);
|
||||
return false;
|
||||
}
|
||||
|
@ -193,8 +186,9 @@ void KameraProtocol::closeCamera(void)
|
|||
{
|
||||
int gpr;
|
||||
|
||||
if (!m_camera)
|
||||
if (!m_camera) {
|
||||
return;
|
||||
}
|
||||
|
||||
kDebug(7123) << "KameraProtocol::closeCamera at " << getpid();
|
||||
if ((gpr=gp_camera_exit(m_camera,m_context))!=GP_OK) {
|
||||
|
@ -215,8 +209,9 @@ static QString fix_foldername(QString ofolder) {
|
|||
while ((folder.length()>1) && (folder.right(1) == "/"))
|
||||
folder = folder.left(folder.length()-1);
|
||||
}
|
||||
if (folder.length() == 0)
|
||||
if (folder.length() == 0) {
|
||||
folder = "/";
|
||||
}
|
||||
return folder;
|
||||
}
|
||||
|
||||
|
@ -269,10 +264,11 @@ void KameraProtocol::get(const KUrl &url)
|
|||
gpr = gp_camera_file_get_info(m_camera, tocstr(fix_foldername(directory)), tocstr(file), &info, m_context);
|
||||
if (gpr != GP_OK) {
|
||||
gp_file_unref(m_file);
|
||||
if ((gpr == GP_ERROR_FILE_NOT_FOUND) || (gpr == GP_ERROR_DIRECTORY_NOT_FOUND))
|
||||
if ((gpr == GP_ERROR_FILE_NOT_FOUND) || (gpr == GP_ERROR_DIRECTORY_NOT_FOUND)) {
|
||||
error(KIO::ERR_DOES_NOT_EXIST, url.path());
|
||||
else
|
||||
} else {
|
||||
error(KIO::ERR_UNKNOWN, QString::fromLocal8Bit(gp_result_as_string(gpr)));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -280,45 +276,50 @@ void KameraProtocol::get(const KUrl &url)
|
|||
if(cameraSupportsPreview() && metaData("thumbnail") == "1") {
|
||||
kDebug(7123) << "get() retrieving the thumbnail";
|
||||
fileType = GP_FILE_TYPE_PREVIEW;
|
||||
if (info.preview.fields & GP_FILE_INFO_SIZE)
|
||||
if (info.preview.fields & GP_FILE_INFO_SIZE) {
|
||||
totalSize(info.preview.size);
|
||||
if (info.preview.fields & GP_FILE_INFO_TYPE)
|
||||
}
|
||||
if (info.preview.fields & GP_FILE_INFO_TYPE) {
|
||||
mimeType(info.preview.type);
|
||||
}
|
||||
} else {
|
||||
kDebug(7123) << "get() retrieving the full-scale photo";
|
||||
fileType = GP_FILE_TYPE_NORMAL;
|
||||
if (info.file.fields & GP_FILE_INFO_SIZE)
|
||||
if (info.file.fields & GP_FILE_INFO_SIZE) {
|
||||
totalSize(info.file.size);
|
||||
if (info.preview.fields & GP_FILE_INFO_TYPE)
|
||||
}
|
||||
if (info.preview.fields & GP_FILE_INFO_TYPE) {
|
||||
mimeType(info.file.type);
|
||||
}
|
||||
}
|
||||
|
||||
// fetch the data
|
||||
m_fileSize = 0;
|
||||
gpr = gp_camera_file_get(m_camera, tocstr(fix_foldername(directory)), tocstr(file), fileType, m_file, m_context);
|
||||
if ( (gpr == GP_ERROR_NOT_SUPPORTED) &&
|
||||
(fileType == GP_FILE_TYPE_PREVIEW)
|
||||
) {
|
||||
if (gpr == GP_ERROR_NOT_SUPPORTED && fileType == GP_FILE_TYPE_PREVIEW) {
|
||||
// If we get here, the file info command information
|
||||
// will either not be used, or still valid.
|
||||
fileType = GP_FILE_TYPE_NORMAL;
|
||||
gpr = gp_camera_file_get(m_camera, tocstr(fix_foldername(directory)), tocstr(file), fileType, m_file, m_context);
|
||||
}
|
||||
switch(gpr) {
|
||||
case GP_OK:
|
||||
case GP_OK: {
|
||||
break;
|
||||
}
|
||||
case GP_ERROR_FILE_NOT_FOUND:
|
||||
case GP_ERROR_DIRECTORY_NOT_FOUND:
|
||||
case GP_ERROR_DIRECTORY_NOT_FOUND: {
|
||||
gp_file_unref(m_file);
|
||||
m_file = NULL;
|
||||
error(KIO::ERR_DOES_NOT_EXIST, url.fileName());
|
||||
return;
|
||||
default:
|
||||
}
|
||||
default: {
|
||||
gp_file_unref(m_file);
|
||||
m_file = NULL;
|
||||
error(KIO::ERR_UNKNOWN, QString::fromLocal8Bit(gp_result_as_string(gpr)));
|
||||
return;
|
||||
}
|
||||
}
|
||||
// emit the mimetype
|
||||
// NOTE: we must first get the file, so that CameraFile->name would be set
|
||||
const char *fileMimeType;
|
||||
|
@ -342,7 +343,7 @@ void KameraProtocol::get(const KUrl &url)
|
|||
// make sure we're not sending zero-sized chunks (=EOF)
|
||||
// also make sure we send only if the progress did not send the data
|
||||
// already.
|
||||
if ((fileSize > 0) && (fileSize - m_fileSize)>0) {
|
||||
if (fileSize > 0 && (fileSize - m_fileSize) > 0) {
|
||||
unsigned long written = 0;
|
||||
QByteArray chunkDataBuffer;
|
||||
|
||||
|
@ -353,8 +354,9 @@ void KameraProtocol::get(const KUrl &url)
|
|||
while (written < fileSize-m_fileSize) {
|
||||
unsigned long towrite = 1024*1024; // 1MB
|
||||
|
||||
if (towrite > fileSize-m_fileSize-written)
|
||||
if (towrite > fileSize-m_fileSize-written) {
|
||||
towrite = fileSize-m_fileSize-written;
|
||||
}
|
||||
chunkDataBuffer = QByteArray::fromRawData(fileData + m_fileSize + written, towrite);
|
||||
processedSize(m_fileSize + written + towrite);
|
||||
data(chunkDataBuffer);
|
||||
|
@ -384,11 +386,12 @@ void KameraProtocol::stat(const KUrl &url)
|
|||
finished();
|
||||
return;
|
||||
}
|
||||
if(url.path() == "/")
|
||||
if (url.path() == "/") {
|
||||
statRoot();
|
||||
else
|
||||
} else {
|
||||
statRegular(url);
|
||||
}
|
||||
}
|
||||
|
||||
// Implements stat("/") -- which always returns the same value.
|
||||
void KameraProtocol::statRoot(void)
|
||||
|
@ -407,16 +410,14 @@ void KameraProtocol::statRoot(void)
|
|||
idletime = MAXIDLETIME;
|
||||
}
|
||||
|
||||
void KameraProtocol::split_url2camerapath(QString url,
|
||||
QString &directory,
|
||||
QString &file
|
||||
) {
|
||||
void KameraProtocol::split_url2camerapath(QString url, QString &directory, QString &file) {
|
||||
QStringList components, camarr;
|
||||
QString cam, camera, port;
|
||||
|
||||
components = url.split('/', QString::SkipEmptyParts);
|
||||
if (components.size() == 0)
|
||||
if (components.size() == 0) {
|
||||
return;
|
||||
}
|
||||
cam = path_unquote(components.takeFirst());
|
||||
if (!cam.isEmpty()) {
|
||||
camarr = cam.split('@');
|
||||
|
@ -468,10 +469,11 @@ void KameraProtocol::statRegular(const KUrl &xurl)
|
|||
|
||||
gpr = gp_camera_folder_list_folders(m_camera, tocstr(fix_foldername(directory)), dirList, m_context);
|
||||
if (gpr != GP_OK) {
|
||||
if ((gpr == GP_ERROR_FILE_NOT_FOUND) || (gpr == GP_ERROR_DIRECTORY_NOT_FOUND))
|
||||
if (gpr == GP_ERROR_FILE_NOT_FOUND || gpr == GP_ERROR_DIRECTORY_NOT_FOUND) {
|
||||
error(KIO::ERR_DOES_NOT_EXIST, xurl.path());
|
||||
else
|
||||
} else {
|
||||
error(KIO::ERR_UNKNOWN, QString::fromLocal8Bit(gp_result_as_string(gpr)));
|
||||
}
|
||||
gp_list_free(dirList);
|
||||
return;
|
||||
}
|
||||
|
@ -512,10 +514,11 @@ void KameraProtocol::statRegular(const KUrl &xurl)
|
|||
CameraFileInfo info;
|
||||
gpr = gp_camera_file_get_info(m_camera, tocstr(fix_foldername(directory)), tocstr(file), &info, m_context);
|
||||
if (gpr != GP_OK) {
|
||||
if ((gpr == GP_ERROR_FILE_NOT_FOUND) || (gpr == GP_ERROR_DIRECTORY_NOT_FOUND))
|
||||
if (gpr == GP_ERROR_FILE_NOT_FOUND || gpr == GP_ERROR_DIRECTORY_NOT_FOUND) {
|
||||
error(KIO::ERR_DOES_NOT_EXIST, xurl.path());
|
||||
else
|
||||
} else {
|
||||
error(KIO::ERR_UNKNOWN, QString::fromLocal8Bit(gp_result_as_string(gpr)));
|
||||
}
|
||||
return;
|
||||
}
|
||||
translateFileToUDS(entry, info, file);
|
||||
|
@ -562,11 +565,12 @@ void KameraProtocol::listDir(const KUrl &yurl)
|
|||
split_url2camerapath(yurl.path(), directory, file);
|
||||
|
||||
if (!file.isEmpty()) {
|
||||
if (directory == "/")
|
||||
if (directory == "/") {
|
||||
directory = "/" + file;
|
||||
else
|
||||
} else {
|
||||
directory = directory + "/" + file;
|
||||
}
|
||||
}
|
||||
|
||||
if (yurl.path() == "/") {
|
||||
KUrl xurl;
|
||||
|
@ -576,7 +580,6 @@ void KameraProtocol::listDir(const KUrl &yurl)
|
|||
QStringList::Iterator it;
|
||||
KIO::UDSEntry entry;
|
||||
|
||||
|
||||
/*
|
||||
* What we do:
|
||||
* - Autodetect cameras and remember them with their ports.
|
||||
|
@ -628,13 +631,15 @@ void KameraProtocol::listDir(const KUrl &yurl)
|
|||
gp_list_free (list);
|
||||
|
||||
/* Avoid duplicated entry, that is a camera with both port usb: and usb:001,042 entries. */
|
||||
if (ports.contains("usb:") && names.contains(ports["usb:"]) && names[ports["usb:"]] != "usb:")
|
||||
if (ports.contains("usb:") && names.contains(ports["usb:"]) && names[ports["usb:"]] != "usb:") {
|
||||
ports.remove("usb:");
|
||||
}
|
||||
|
||||
for (it = groupList.begin(); it != groupList.end(); it++) {
|
||||
QString m_cfgPath;
|
||||
if (*it == "<default>")
|
||||
if (*it == "<default>") {
|
||||
continue;
|
||||
}
|
||||
|
||||
KConfigGroup cg(m_config, *it);
|
||||
m_cfgPath = cg.readEntry("Path");
|
||||
|
@ -679,10 +684,11 @@ void KameraProtocol::listDir(const KUrl &yurl)
|
|||
KUrl rooturl(yurl);
|
||||
|
||||
kDebug(7123) << "redirecting to /";
|
||||
if (!current_camera.isEmpty() && !current_port.isEmpty())
|
||||
if (!current_camera.isEmpty() && !current_port.isEmpty()) {
|
||||
rooturl.setPath("/"+current_camera+"@"+current_port+"/");
|
||||
else
|
||||
} else {
|
||||
rooturl.setPath("/");
|
||||
}
|
||||
redirection(rooturl);
|
||||
finished();
|
||||
return;
|
||||
|
@ -703,13 +709,16 @@ void KameraProtocol::listDir(const KUrl &yurl)
|
|||
|
||||
if (!directory.compare("/")) {
|
||||
CameraText text;
|
||||
if (GP_OK == gp_camera_get_manual(m_camera, &text, m_context))
|
||||
if (GP_OK == gp_camera_get_manual(m_camera, &text, m_context)) {
|
||||
gp_list_append(specialList,"manual.txt",NULL);
|
||||
if (GP_OK == gp_camera_get_about(m_camera, &text, m_context))
|
||||
}
|
||||
if (GP_OK == gp_camera_get_about(m_camera, &text, m_context)) {
|
||||
gp_list_append(specialList,"about.txt",NULL);
|
||||
if (GP_OK == gp_camera_get_summary(m_camera, &text, m_context))
|
||||
}
|
||||
if (GP_OK == gp_camera_get_summary(m_camera, &text, m_context)) {
|
||||
gp_list_append(specialList,"summary.txt",NULL);
|
||||
}
|
||||
}
|
||||
|
||||
gpr = readCameraFolder(directory, dirList, fileList);
|
||||
if (gpr != GP_OK) {
|
||||
|
@ -774,10 +783,7 @@ void KameraProtocol::setCamera(const QString& camera, const QString& port)
|
|||
if (!camera.isEmpty() && !port.isEmpty()) {
|
||||
kDebug(7123) << "model is " << camera << ", port is " << port;
|
||||
|
||||
if ( m_camera &&
|
||||
(current_camera == camera) &&
|
||||
(current_port == port)
|
||||
) {
|
||||
if (m_camera && current_camera == camera && current_port == port) {
|
||||
kDebug(7123) << "Configuration is same, nothing to do.";
|
||||
return;
|
||||
}
|
||||
|
@ -813,8 +819,9 @@ void KameraProtocol::setCamera(const QString& camera, const QString& port)
|
|||
idx = gp_port_info_list_lookup_path(port_info_list, tocstr(port));
|
||||
|
||||
/* Handle erronously passed usb:XXX,YYY */
|
||||
if ((idx < 0) && port.startsWith("usb:"))
|
||||
if (idx < 0 && port.startsWith("usb:")) {
|
||||
idx = gp_port_info_list_lookup_path(port_info_list, "usb:");
|
||||
}
|
||||
if (idx < 0) {
|
||||
gp_port_info_list_free(port_info_list);
|
||||
kDebug(7123) << "Unable to get port info for path: " << port;
|
||||
|
@ -848,8 +855,9 @@ void KameraProtocol::setCamera(const QString& camera, const QString& port)
|
|||
|
||||
QString errstr;
|
||||
if (!openCamera(errstr)) {
|
||||
if (m_camera)
|
||||
if (m_camera) {
|
||||
gp_camera_unref(m_camera);
|
||||
}
|
||||
m_camera = NULL;
|
||||
kDebug(7123) << "Unable to init camera: " << errstr;
|
||||
error(KIO::ERR_SERVICE_NOT_AVAILABLE, errstr);
|
||||
|
@ -864,9 +872,8 @@ void KameraProtocol::reparseConfiguration(void)
|
|||
}
|
||||
|
||||
// translate a simple text to a UDS entry
|
||||
void KameraProtocol::translateTextToUDS(KIO::UDSEntry &udsEntry, const QString &fn,
|
||||
const char *text
|
||||
) {
|
||||
void KameraProtocol::translateTextToUDS(KIO::UDSEntry &udsEntry, const QString &fn, const char *text)
|
||||
{
|
||||
|
||||
udsEntry.clear();
|
||||
|
||||
|
@ -901,8 +908,9 @@ void KameraProtocol::translateFileToUDS(KIO::UDSEntry &udsEntry, const CameraFil
|
|||
udsEntry.insert(KIO::UDSEntry::UDS_MODIFICATION_TIME,time(NULL));
|
||||
}
|
||||
|
||||
if (info.file.fields & GP_FILE_INFO_TYPE)
|
||||
if (info.file.fields & GP_FILE_INFO_TYPE) {
|
||||
udsEntry.insert(KIO::UDSEntry::UDS_MIME_TYPE,QString::fromLatin1(info.file.type));
|
||||
}
|
||||
|
||||
if (info.file.fields & GP_FILE_INFO_PERMISSIONS) {
|
||||
udsEntry.insert(KIO::UDSEntry::UDS_ACCESS,((info.file.permissions & GP_FILE_PERM_READ) ? (S_IRUSR | S_IRGRP | S_IROTH) : 0));
|
||||
|
@ -946,16 +954,17 @@ int KameraProtocol::readCameraFolder(const QString &folder, CameraList *dirList,
|
|||
kDebug(7123) << "KameraProtocol::readCameraFolder(" << folder << ")";
|
||||
|
||||
int gpr;
|
||||
if((gpr = gp_camera_folder_list_folders(m_camera, tocstr(folder), dirList, m_context)) != GP_OK)
|
||||
if ((gpr = gp_camera_folder_list_folders(m_camera, tocstr(folder), dirList, m_context)) != GP_OK) {
|
||||
return gpr;
|
||||
if((gpr = gp_camera_folder_list_files(m_camera, tocstr(folder), fileList, m_context)) != GP_OK)
|
||||
}
|
||||
if ((gpr = gp_camera_folder_list_files(m_camera, tocstr(folder), fileList, m_context)) != GP_OK) {
|
||||
return gpr;
|
||||
}
|
||||
return GP_OK;
|
||||
}
|
||||
|
||||
void frontendProgressUpdate(
|
||||
GPContext * /*context*/, unsigned int /*id*/, float /*current*/, void *data
|
||||
) {
|
||||
void frontendProgressUpdate(GPContext * /*context*/, unsigned int /*id*/, float /*current*/, void *data)
|
||||
{
|
||||
KameraProtocol *object = (KameraProtocol*)data;
|
||||
|
||||
// This code will get the last chunk of data retrieved from the
|
||||
|
@ -967,8 +976,9 @@ void frontendProgressUpdate(
|
|||
|
||||
// This merely returns us a pointer to gphoto's internal data
|
||||
// buffer -- there's no expensive memcpy
|
||||
if (!object->getFile())
|
||||
if (!object->getFile()) {
|
||||
return;
|
||||
}
|
||||
gp_file_get_data_and_size(object->getFile(), &fileData, &fileSize);
|
||||
// make sure we're not sending zero-sized chunks (=EOF)
|
||||
if (fileSize > 0) {
|
||||
|
@ -983,15 +993,14 @@ void frontendProgressUpdate(
|
|||
}
|
||||
}
|
||||
|
||||
unsigned int frontendProgressStart(
|
||||
GPContext * /*context*/, float totalsize,
|
||||
unsigned int frontendProgressStart(GPContext * /*context*/, float totalsize,
|
||||
#ifdef HAVE_GPHOTO2_5
|
||||
const char *status,
|
||||
#else
|
||||
const char *format, va_list args,
|
||||
#endif
|
||||
void *data
|
||||
) {
|
||||
void *data)
|
||||
{
|
||||
KameraProtocol *object = (KameraProtocol*)data;
|
||||
#ifndef HAVE_GPHOTO2_5
|
||||
char *status;
|
||||
|
@ -1007,8 +1016,9 @@ unsigned int frontendProgressStart(
|
|||
__va_copy(xvalist, args);
|
||||
# endif
|
||||
int size=vsnprintf(NULL, 0, format, xvalist);
|
||||
if(size<=0)
|
||||
if (size<=0) {
|
||||
return GP_OK; // vsnprintf is broken, better don't do anything.
|
||||
}
|
||||
|
||||
status=new char[size+1];
|
||||
# ifdef HAVE_VA_COPY
|
||||
|
@ -1036,15 +1046,14 @@ unsigned int frontendProgressStart(
|
|||
}
|
||||
|
||||
// this callback function is activated on every status message from gphoto2
|
||||
static void frontendCameraStatus(
|
||||
GPContext * /*context*/,
|
||||
static void frontendCameraStatus(GPContext * /*context*/,
|
||||
#ifdef HAVE_GPHOTO2_5
|
||||
const char *status,
|
||||
#else
|
||||
const char *format, va_list args,
|
||||
#endif
|
||||
void *data
|
||||
) {
|
||||
void *data)
|
||||
{
|
||||
KameraProtocol *object = (KameraProtocol*)data;
|
||||
#ifndef HAVE_GPHOTO2_5
|
||||
char *status;
|
||||
|
@ -1060,8 +1069,9 @@ static void frontendCameraStatus(
|
|||
__va_copy(xvalist, args);
|
||||
# endif
|
||||
int size=vsnprintf(NULL, 0, format, xvalist);
|
||||
if(size<=0)
|
||||
if (size<=0) {
|
||||
return; // vsnprintf is broken, better don't do anything.
|
||||
}
|
||||
|
||||
status=new char[size+1];
|
||||
# ifdef HAVE_VA_COPY
|
||||
|
|
|
@ -56,10 +56,7 @@ private:
|
|||
void setCamera(const QString &cam, const QString &port);
|
||||
void reparseConfiguration(void);
|
||||
bool openCamera(QString& str);
|
||||
bool openCamera(void ) {
|
||||
QString errstr;
|
||||
return openCamera(errstr);
|
||||
}
|
||||
bool openCamera(void ) { QString errstr; return openCamera(errstr); }
|
||||
void closeCamera(void);
|
||||
|
||||
void statRoot(void);
|
||||
|
|
Loading…
Add table
Reference in a new issue