~ubuntu-branches/debian/lenny/kipi-plugins/lenny

« back to all changes in this revision

Viewing changes to kipi-plugins/acquireimages/acquireimagedialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2008-10-16 08:26:01 UTC
  • mfrom: (2.1.15 hardy)
  • Revision ID: james.westby@ubuntu.com-20081016082601-3f8ozqd96zwuuuki
Tags: 0.1.5-4
* Revert unsuccessful PicasaWebExport.patch 
  - this version suitable for inclusion in lenny
  - kipi plugins - picasa bug (Closes: #501771)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//////////////////////////////////////////////////////////////////////////////
2
 
//
3
 
//    ACQUIREIMAGEDIALOG.CPP
4
 
//
5
 
//    Copyright (C) 2003 Gilles Caulier <caulier.gilles at free.fr>
6
 
//
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.
11
 
//
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.
16
 
//
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.
20
 
//
21
 
//////////////////////////////////////////////////////////////////////////////
 
1
/* ============================================================
 
2
 *
 
3
 * This file is a part of kipi-plugins project
 
4
 * http://www.kipi-plugins.org
 
5
 *
 
6
 * Date        : 2003-10-01
 
7
 * Description : Acquire image dialog
 
8
 *
 
9
 * Copyright (C) 2003-2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
 
10
 *
 
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.
 
15
 * 
 
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.
 
20
 * 
 
21
 * ============================================================ */
22
22
 
23
23
// C Ansi includes
24
24
 
81
81
 
82
82
// Include files for libKipi.
83
83
 
84
 
#include <libkipi/version.h>
85
84
#include <libkipi/imageinfo.h>
86
85
 
87
86
// Local includes
88
87
 
 
88
#include "pluginsversion.h"
89
89
#include "acquireimagedialog.h"
 
90
#include "acquireimagedialog.moc"
90
91
 
91
92
namespace KIPIAcquireImagesPlugin
92
93
{
100
101
#define NETACCESS_WIDGET
101
102
#endif
102
103
 
103
 
//////////////////////////////////// CONSTRUCTOR ////////////////////////////////////////////
104
 
 
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 )
108
107
{
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 );
118
 
    
 
117
 
119
118
    // About data and help button.
120
 
    
121
 
    KAboutData* about = new KAboutData("kipiplugins",
122
 
                                       I18N_NOOP("Acquire images"), 
123
 
                                       kipi_version,
124
 
                                       I18N_NOOP("A Kipi plugin to acquire images"),
125
 
                                       KAboutData::License_GPL,
126
 
                                       "(c) 2003-2004, Gilles Caulier", 
127
 
                                       0,
128
 
                                       "http://extragear.kde.org/apps/kipi");
129
 
    
130
 
    about->addAuthor("Gilles Caulier", I18N_NOOP("Author and maintainer"),
131
 
                     "caulier dot gilles at free.fr");
 
119
 
 
120
    m_about = new KIPIPlugins::KPAboutData(I18N_NOOP("Acquire images"),
 
121
                                           0,
 
122
                                           KAboutData::License_GPL,
 
123
                                           I18N_NOOP("A Kipi plugin to acquire images"),
 
124
                                           "(c) 2003-2008, Gilles Caulier");
 
125
 
 
126
    m_about->addAuthor("Gilles Caulier", I18N_NOOP("Author and maintainer"),
 
127
                       "caulier dot gilles at gmail dot com");
132
128
 
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() );
138
134
}
139
135
 
140
 
 
141
 
//////////////////////////////////// DESTRUCTOR /////////////////////////////////////////////
142
 
 
143
136
AcquireImageDialog::~AcquireImageDialog()
144
137
{
 
138
    delete m_about;
145
139
}
146
140
 
147
 
 
148
 
/////////////////////////////////////////////////////////////////////////////////////////////
149
 
 
150
141
void AcquireImageDialog::slotHelp()
151
142
{
152
 
    KApplication::kApplication()->invokeHelp("acquireimages",
153
 
                                             "kipi-plugins");
 
143
    KApplication::kApplication()->invokeHelp("acquireimages", "kipi-plugins");
154
144
}    
155
145
 
156
 
 
157
 
/////////////////////////////////////////////////////////////////////////////////////////////
158
 
 
159
146
void AcquireImageDialog::readSettings(void)
160
147
{
161
148
    // Read all settings from configuration file.
173
160
    m_ImagesFilesSort = m_interface->fileExtensions();    
174
161
}
175
162
 
176
 
 
177
 
/////////////////////////////////////////////////////////////////////////////////////////////
178
 
 
179
163
void AcquireImageDialog::writeSettings(void)
180
164
{
181
165
    // Write all settings in configuration file.
189
173
    delete m_config;
190
174
}
191
175
 
192
 
 
193
 
/////////////////////////////////////////////////////////////////////////////////////////////
194
 
 
195
176
void AcquireImageDialog::setupImageOptions(void)
196
177
{
197
178
    QString whatsThis;
206
187
 
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);
212
193
 
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);
222
203
 
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);
225
206
 
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);
230
211
 
231
212
    m_preview = new QLabel( groupBox1, "preview" );
315
296
            this, SLOT(slotImageFormatChanged(const QString &)));
316
297
}
317
298
 
318
 
 
319
 
/////////////////////////////////////////////////////////////////////////////////////////////
320
 
 
321
299
void AcquireImageDialog::setupAlbumsList(void)
322
300
{
323
301
    QString whatsThis;
392
370
    slotAlbumSelected( m_uploadPath->path() );           
393
371
 }
394
372
 
395
 
 
396
 
//////////////////////////////////////// SLOTS //////////////////////////////////////////////
397
 
 
398
373
void AcquireImageDialog::slotAlbumSelected( const KURL &url )
399
374
{
400
375
    QString comments, category, date, items;
402
377
    QValueList<KIPI::ImageCollection>::Iterator albumIt;
403
378
    
404
379
    for( albumIt = albums.begin() ; albumIt != albums.end() ; ++albumIt )
405
 
       {
 
380
    {
406
381
       if ( (*albumIt).path() == url ) 
407
382
          break;
408
 
       }
 
383
    }
409
384
    
410
385
    if (albumIt != albums.end())
411
 
       { 
 
386
    { 
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());
416
 
       }
 
391
    }
417
392
        
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 ) );
422
397
}
423
398
 
424
 
 
425
 
/////////////////////////////////////////////////////////////////////////////////////////////
426
 
 
427
 
  void AcquireImageDialog::slotOk()
 
399
void AcquireImageDialog::slotOk()
428
400
{
429
401
    // PENDING( aurelien)
430
402
    // It would be nice if m_uploadPath kept its value between multiple snapshots.
446
418
 
447
419
    writeSettings();
448
420
 
449
 
    // Get all scanned image informations.
 
421
    // Get all scanned image information.
450
422
    QString imageFormat = m_imagesFormat->currentText();
451
423
    int imageCompression = m_imageCompression->value();
452
424
    QString Commentsimg = m_CommentsEdit->text();
457
429
    url.setFileName(fileName + ext);
458
430
 
459
431
    if (KIO::NetAccess::exists(url, false NETACCESS_WIDGET)) 
460
 
        {
 
432
    {
461
433
        for (int idx = 1; idx < 100 ; ++idx) 
462
 
            {
 
434
        {
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;
465
437
            
466
438
            if (!KIO::NetAccess::exists(url, false NETACCESS_WIDGET)) 
467
439
               break;
468
 
            }
469
440
        }
 
441
    }
470
442
 
471
443
    kdDebug(51001) << k_funcinfo << "Saving image as " << url.prettyURL() << endl;
472
444
 
474
446
    KTempFile tmp;
475
447
    tmp.setAutoDelete(true);
476
448
    QString imagePath;
477
 
    if (url.isLocalFile()) {
 
449
    if (url.isLocalFile()) 
 
450
    {
478
451
        imagePath=url.path();
479
 
    } else {
 
452
    } 
 
453
    else 
 
454
    {
480
455
        imagePath=tmp.name();
481
456
    }
482
457
 
483
458
    bool ok=false;
484
 
    if (imageFormat=="JPEG" || imageFormat=="PNG") {
 
459
    if (imageFormat=="JPEG" || imageFormat=="PNG") 
 
460
    {
485
461
        ok = m_qimageScanned.save(imagePath, imageFormat.latin1(), imageCompression);
486
 
    } else if (imageFormat=="TIFF") {
 
462
    }
 
463
    else if (imageFormat=="TIFF") 
 
464
    {
487
465
        ok = QImageToTiff(m_qimageScanned, imagePath);
488
 
    } else {
 
466
    }
 
467
    else 
 
468
    {
489
469
        ok =  m_qimageScanned.save(imagePath, imageFormat.latin1());
490
470
    }
491
471
 
496
476
    }
497
477
 
498
478
    // Upload the image if necessary
499
 
    if ( !url.isLocalFile()) {
500
 
        if (!KIO::NetAccess::upload(imagePath, url NETACCESS_WIDGET)) {
 
479
    if ( !url.isLocalFile()) 
 
480
    {
 
481
        if (!KIO::NetAccess::upload(imagePath, url NETACCESS_WIDGET)) 
 
482
        {
501
483
           KMessageBox::error(this, i18n("Could not upload image to \"%1\".").arg(url.prettyURL()));
502
484
           return;
503
485
        }
506
488
    // Save the comments for this image.
507
489
    QString err;
508
490
    ok = m_interface->addImage( url, err );
509
 
    if ( !ok ) {
 
491
    if ( !ok ) 
 
492
    {
510
493
        KMessageBox::error(this, i18n("<qt>Error when informing the application about the new image. "
511
494
                                  "The error was: %1</qt>" ).arg( err ) );
512
495
        return;
521
504
    delete this;
522
505
}
523
506
 
524
 
 
525
 
/////////////////////////////////////////////////////////////////////////////////////////////////////
526
 
 
527
507
void AcquireImageDialog::slotImageFormatChanged(const QString &string)
528
508
{
529
509
    if ( string == "JPEG" || string == "PNG" )
532
512
       m_imageCompression->setEnabled(false);
533
513
}
534
514
 
535
 
 
536
 
/////////////////////////////////////////////////////////////////////////////////////////////////////
537
 
 
538
515
QString AcquireImageDialog::extension(const QString& imageFormat)
539
516
{
540
517
    if (imageFormat == "PNG")
556
533
    return "";
557
534
}
558
535
 
559
 
 
560
 
/////////////////////////////////////////////////////////////////////////////////////////////////////
561
 
 
562
536
bool AcquireImageDialog::QImageToTiff(const QImage& image, const QString& dst)
563
537
{
564
538
    TIFF               *tif;
568
542
 
569
543
    tif = TIFFOpen(QFile::encodeName(dst).data(), "w");
570
544
    if ( tif )
571
 
        {
 
545
    {
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);
578
 
            {
 
552
        {
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;
585
559
 
586
560
            for (y = 0 ; y < image.height() ; ++y)
587
 
                {
 
561
            {
588
562
                dptr = data;
589
563
 
590
564
                for (x = 0 ; x < image.width() ; ++x)
591
 
                    {
 
565
                {
592
566
                    rgb = *((uint *)image.scanLine(y) + x);
593
567
                    *(dptr++) = qRed(rgb);
594
568
                    *(dptr++) = qGreen(rgb);
595
569
                    *(dptr++) = qBlue(rgb);
596
 
                    }
 
570
                }
597
571
 
598
572
                TIFFWriteScanline(tif, data, y, 0);
599
 
                }
 
573
            }
600
574
 
601
575
            delete [] data;
602
 
            }
 
576
        }
603
577
 
604
578
        TIFFClose(tif);
605
579
        return true;
606
 
        }
 
580
    }
607
581
 
608
582
    return false;
609
583
}
610
584
 
611
585
}  // NameSpace KIPIAcquireImagesPlugin
612
 
 
613
 
#include "acquireimagedialog.moc"