1
//////////////////////////////////////////////////////////////////////////////
3
// ACQUIREIMAGEDIALOG.CPP
5
// Copyright (C) 2003 Gilles Caulier <caulier.gilles at free.fr>
7
// This program is free software; you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License as published by
9
// the Free Software Foundation; either version 2 of the License, or
10
// (at your option) any later version.
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, write to the Free Software
19
// Foundation, Inc., 51 Franklin Steet, Fifth Floor, Cambridge, MA 02110-1301, USA.
21
//////////////////////////////////////////////////////////////////////////////
1
/* ============================================================
3
* This file is a part of kipi-plugins project
4
* http://www.kipi-plugins.org
7
* Description : Acquire image dialog
9
* Copyright (C) 2003-2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
11
* This program is free software; you can redistribute it
12
* and/or modify it under the terms of the GNU General
13
* Public License as published by the Free Software Foundation;
14
* either version 2, or (at your option) any later version.
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU General Public License for more details.
21
* ============================================================ */
82
82
// Include files for libKipi.
84
#include <libkipi/version.h>
85
84
#include <libkipi/imageinfo.h>
88
#include "pluginsversion.h"
89
89
#include "acquireimagedialog.h"
90
#include "acquireimagedialog.moc"
91
92
namespace KIPIAcquireImagesPlugin
100
101
#define NETACCESS_WIDGET
103
//////////////////////////////////// CONSTRUCTOR ////////////////////////////////////////////
105
104
AcquireImageDialog::AcquireImageDialog( KIPI::Interface* interface, QWidget *parent, const QImage &img)
106
105
: KDialogBase( IconList, i18n("Save Target Image Options"), Help|Ok|Cancel,
107
Ok, parent, "AcquireImageDialog", true, true ), m_interface( interface )
106
Ok, parent, "AcquireImageDialog", true, false ), m_interface( interface )
109
108
KImageIO::registerFormats();
110
109
m_qimageScanned = img;
115
114
slotImageFormatChanged(m_imagesFormat->currentText());
116
115
page_setupImageOptions->setFocus();
117
116
resize( 600, 400 );
119
118
// About data and help button.
121
KAboutData* about = new KAboutData("kipiplugins",
122
I18N_NOOP("Acquire images"),
124
I18N_NOOP("A Kipi plugin to acquire images"),
125
KAboutData::License_GPL,
126
"(c) 2003-2004, Gilles Caulier",
128
"http://extragear.kde.org/apps/kipi");
130
about->addAuthor("Gilles Caulier", I18N_NOOP("Author and maintainer"),
131
"caulier dot gilles at free.fr");
120
m_about = new KIPIPlugins::KPAboutData(I18N_NOOP("Acquire images"),
122
KAboutData::License_GPL,
123
I18N_NOOP("A Kipi plugin to acquire images"),
124
"(c) 2003-2008, Gilles Caulier");
126
m_about->addAuthor("Gilles Caulier", I18N_NOOP("Author and maintainer"),
127
"caulier dot gilles at gmail dot com");
133
129
m_helpButton = actionButton( Help );
134
KHelpMenu* helpMenu = new KHelpMenu(this, about, false);
130
KHelpMenu* helpMenu = new KHelpMenu(this, m_about, false);
135
131
helpMenu->menu()->removeItemAt(0);
136
helpMenu->menu()->insertItem(i18n("Acquire Images Handbook"), this, SLOT(slotHelp()), 0, -1, 0);
132
helpMenu->menu()->insertItem(i18n("Plugin Handbook"), this, SLOT(slotHelp()), 0, -1, 0);
137
133
m_helpButton->setPopup( helpMenu->menu() );
141
//////////////////////////////////// DESTRUCTOR /////////////////////////////////////////////
143
136
AcquireImageDialog::~AcquireImageDialog()
148
/////////////////////////////////////////////////////////////////////////////////////////////
150
141
void AcquireImageDialog::slotHelp()
152
KApplication::kApplication()->invokeHelp("acquireimages",
143
KApplication::kApplication()->invokeHelp("acquireimages", "kipi-plugins");
157
/////////////////////////////////////////////////////////////////////////////////////////////
159
146
void AcquireImageDialog::readSettings(void)
161
148
// Read all settings from configuration file.
207
188
QGroupBox * groupBox1 = new QGroupBox( page_setupImageOptions );
208
189
groupBox1->setFlat(false);
209
groupBox1->setTitle(i18n("File Name && Comments"));
210
QWhatsThis::add( groupBox1, i18n("<p>The target image preview with the file name and comments.") );
190
groupBox1->setTitle(i18n("File Name && Caption"));
191
QWhatsThis::add( groupBox1, i18n("<p>The target image preview with the file name and caption.") );
211
192
QGridLayout* grid2 = new QGridLayout( groupBox1, 3, 3 , 20, 10);
213
194
m_ImageFileName = new QLabel( i18n("File name (without suffix):"), groupBox1);
220
201
m_ImageFileName->setBuddy(m_FileName);
221
202
grid2->addMultiCellWidget(m_FileName, 1, 1, 0, 3);
223
m_ImageComments = new QLabel( i18n("Comments:"), groupBox1);
204
m_ImageComments = new QLabel( i18n("Caption:"), groupBox1);
224
205
grid2->addMultiCellWidget(m_ImageComments, 2, 2, 0, 3);
226
207
m_CommentsEdit = new QTextEdit(groupBox1);
227
208
m_CommentsEdit->setMaximumHeight( 200 );
228
QWhatsThis::add( m_CommentsEdit, i18n("<p>Enter here the target image's comments.") );
209
QWhatsThis::add( m_CommentsEdit, i18n("<p>Enter here the target image's caption.") );
229
210
grid2->addMultiCellWidget(m_CommentsEdit, 3, 3, 0, 2);
231
212
m_preview = new QLabel( groupBox1, "preview" );
392
370
slotAlbumSelected( m_uploadPath->path() );
396
//////////////////////////////////////// SLOTS //////////////////////////////////////////////
398
373
void AcquireImageDialog::slotAlbumSelected( const KURL &url )
400
375
QString comments, category, date, items;
402
377
QValueList<KIPI::ImageCollection>::Iterator albumIt;
404
379
for( albumIt = albums.begin() ; albumIt != albums.end() ; ++albumIt )
406
381
if ( (*albumIt).path() == url )
410
385
if (albumIt != albums.end())
412
387
comments = (*albumIt).comment();
413
388
category = (*albumIt).category();
414
389
date = (*albumIt).date().toString( Qt::LocalDate );
415
390
items.setNum((*albumIt).images().count());
418
m_AlbumComments->setText( i18n("Comment: %1").arg(comments) );
393
m_AlbumComments->setText( i18n("Caption: %1").arg(comments) );
419
394
m_AlbumCollection->setText( i18n("Collection: %1").arg(category) );
420
395
m_AlbumDate->setText( i18n("Date: %1").arg(date) );
421
396
m_AlbumItems->setText( i18n("Items: %1").arg( items ) );
425
/////////////////////////////////////////////////////////////////////////////////////////////
427
void AcquireImageDialog::slotOk()
399
void AcquireImageDialog::slotOk()
429
401
// PENDING( aurelien)
430
402
// It would be nice if m_uploadPath kept its value between multiple snapshots.
457
429
url.setFileName(fileName + ext);
459
431
if (KIO::NetAccess::exists(url, false NETACCESS_WIDGET))
461
433
for (int idx = 1; idx < 100 ; ++idx)
463
435
url.setFileName(QString("%1_%2%3").arg(fileName).arg(idx).arg(ext));
464
436
kdDebug(51001) << "File already exist. Try to fixed target Url to: " << url.prettyURL() << endl;
466
438
if (!KIO::NetAccess::exists(url, false NETACCESS_WIDGET))
471
443
kdDebug(51001) << k_funcinfo << "Saving image as " << url.prettyURL() << endl;
475
447
tmp.setAutoDelete(true);
476
448
QString imagePath;
477
if (url.isLocalFile()) {
449
if (url.isLocalFile())
478
451
imagePath=url.path();
480
455
imagePath=tmp.name();
484
if (imageFormat=="JPEG" || imageFormat=="PNG") {
459
if (imageFormat=="JPEG" || imageFormat=="PNG")
485
461
ok = m_qimageScanned.save(imagePath, imageFormat.latin1(), imageCompression);
486
} else if (imageFormat=="TIFF") {
463
else if (imageFormat=="TIFF")
487
465
ok = QImageToTiff(m_qimageScanned, imagePath);
489
469
ok = m_qimageScanned.save(imagePath, imageFormat.latin1());
498
478
// Upload the image if necessary
499
if ( !url.isLocalFile()) {
500
if (!KIO::NetAccess::upload(imagePath, url NETACCESS_WIDGET)) {
479
if ( !url.isLocalFile())
481
if (!KIO::NetAccess::upload(imagePath, url NETACCESS_WIDGET))
501
483
KMessageBox::error(this, i18n("Could not upload image to \"%1\".").arg(url.prettyURL()));
569
543
tif = TIFFOpen(QFile::encodeName(dst).data(), "w");
572
546
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, image.width());
573
547
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, image.height());
574
548
TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
575
549
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
576
550
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
577
551
TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_ADOBE_DEFLATE);
579
553
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3);
580
554
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
581
555
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(tif, 0));
584
558
unsigned char *dptr = 0;
586
560
for (y = 0 ; y < image.height() ; ++y)
590
564
for (x = 0 ; x < image.width() ; ++x)
592
566
rgb = *((uint *)image.scanLine(y) + x);
593
567
*(dptr++) = qRed(rgb);
594
568
*(dptr++) = qGreen(rgb);
595
569
*(dptr++) = qBlue(rgb);
598
572
TIFFWriteScanline(tif, data, y, 0);
611
585
} // NameSpace KIPIAcquireImagesPlugin
613
#include "acquireimagedialog.moc"