~ubuntu-branches/ubuntu/karmic/digikam/karmic-backports

« back to all changes in this revision

Viewing changes to libs/database/imagescanner.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ubuntu Archive Auto-Backport
  • Date: 2009-12-07 19:03:53 UTC
  • mfrom: (54.1.4 lucid)
  • Revision ID: james.westby@ubuntu.com-20091207190353-oara3lenjxymto3i
Tags: 2:1.0.0~rc-1ubuntu1~karmic1
Automated backport upload; no source changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include <kfilemetainfo.h>
33
33
#include <kmimetype.h>
34
34
#include <klocale.h>
 
35
#include <kdebug.h>
35
36
 
36
37
// Local includes
37
38
 
43
44
#include "imagecomments.h"
44
45
#include "imagecopyright.h"
45
46
#include "imageextendedproperties.h"
46
 
#include "debug.h"
47
47
 
48
48
namespace Digikam
49
49
{
68
68
    }
69
69
 
70
70
    QString albumRootPath = CollectionManager::instance()->albumRootPath(shortInfo.albumRootID);
71
 
    m_fileInfo = QFileInfo(DatabaseUrl::fromAlbumAndName(shortInfo.itemName,
72
 
                            shortInfo.album, albumRootPath, shortInfo.albumRootID).fileUrl().toLocalFile());
 
71
    m_fileInfo            = QFileInfo(DatabaseUrl::fromAlbumAndName(shortInfo.itemName,
 
72
                                      shortInfo.album, albumRootPath, shortInfo.albumRootID).fileUrl().toLocalFile());
73
73
}
74
74
 
75
75
void ImageScanner::setCategory(DatabaseItem::Category category)
121
121
void ImageScanner::addImage(int albumId)
122
122
{
123
123
    // there is a limit here for file size <2TB
124
 
    m_scanInfo.albumID = albumId;
125
 
    m_scanInfo.itemName = m_fileInfo.fileName();
126
 
    m_scanInfo.status = DatabaseItem::Visible;
 
124
    m_scanInfo.albumID          = albumId;
 
125
    m_scanInfo.itemName         = m_fileInfo.fileName();
 
126
    m_scanInfo.status           = DatabaseItem::Visible;
 
127
 
127
128
    // category is set by setCategory
128
129
    m_scanInfo.modificationDate = m_fileInfo.lastModified();
129
 
    int fileSize = (int)m_fileInfo.size();
 
130
    int fileSize                = (int)m_fileInfo.size();
 
131
 
130
132
    // the QByteArray is an ASCII hex string
131
 
    m_scanInfo.uniqueHash = uniqueHash();
 
133
    m_scanInfo.uniqueHash       = uniqueHash();
132
134
 
133
 
    kDebug(digiKamAreaCode) << "Adding new item" << m_fileInfo.filePath();
134
 
    m_scanInfo.id = DatabaseAccess().db()->addItem(m_scanInfo.albumID, m_scanInfo.itemName,
135
 
                                                   m_scanInfo.status, m_scanInfo.category,
136
 
                                                   m_scanInfo.modificationDate, fileSize,
137
 
                                                   m_scanInfo.uniqueHash);
 
135
    kDebug() << "Adding new item" << m_fileInfo.filePath();
 
136
    m_scanInfo.id               = DatabaseAccess().db()->addItem(m_scanInfo.albumID, m_scanInfo.itemName,
 
137
                                                                 m_scanInfo.status, m_scanInfo.category,
 
138
                                                                 m_scanInfo.modificationDate, fileSize,
 
139
                                                                 m_scanInfo.uniqueHash);
138
140
}
139
141
 
140
142
void ImageScanner::updateImage()
141
143
{
142
144
    // part from addImage()
143
145
    m_scanInfo.modificationDate = m_fileInfo.lastModified();
144
 
    int fileSize = (int)m_fileInfo.size();
145
 
    m_scanInfo.uniqueHash = uniqueHash();
 
146
    int fileSize                = (int)m_fileInfo.size();
 
147
    m_scanInfo.uniqueHash       = uniqueHash();
146
148
 
147
149
    DatabaseAccess().db()->updateItem(m_scanInfo.id, m_scanInfo.category,
148
150
                                      m_scanInfo.modificationDate, fileSize, m_scanInfo.uniqueHash);
207
209
        // Sort by priority, as implemented by custom lessThan()
208
210
        qStableSort(candidates.begin(), candidates.end(), lessThanForIdentity);
209
211
 
210
 
        kDebug(digiKamAreaCode) << "Recognized" << m_fileInfo.filePath() << "as identical to item" << candidates.first().id;
 
212
        kDebug() << "Recognized" << m_fileInfo.filePath() << "as identical to item" << candidates.first().id;
211
213
 
212
214
        // Copy attributes.
213
215
        // Todo for the future is to worry about syncing identical files.
224
226
    // some basic validity checking
225
227
    if (srcId == m_scanInfo.id)
226
228
        return false;
 
229
 
227
230
    ItemScanInfo info = access.db()->getItemScanInfo(srcId);
228
231
    if (!info.id)
229
232
        return false;
230
233
 
231
 
    kDebug(digiKamAreaCode) << "Recognized" << m_fileInfo.filePath() << "as copied from" << srcId;
 
234
    kDebug() << "Recognized" << m_fileInfo.filePath() << "as copied from" << srcId;
232
235
    access.db()->copyImageAttributes(srcId, m_scanInfo.id);
233
236
    return true;
234
237
}
290
293
 
291
294
    DatabaseAccess access;
292
295
    access.db()->changeImageInformation(m_scanInfo.id, infos,
293
 
                                                    DatabaseFields::Width
294
 
                                                    | DatabaseFields::Height
295
 
                                                    | DatabaseFields::Format
296
 
                                                    | DatabaseFields::ColorDepth
297
 
                                                    | DatabaseFields::ColorModel);
 
296
                                                    DatabaseFields::Width      |
 
297
                                                    DatabaseFields::Height     |
 
298
                                                    DatabaseFields::Format     |
 
299
                                                    DatabaseFields::ColorDepth |
 
300
                                                    DatabaseFields::ColorModel);
298
301
}
299
302
 
300
303
static MetadataFields allImageMetadataFields()
486
489
          << detectVideoFormat();
487
490
 
488
491
    DatabaseAccess().db()->addImageInformation(m_scanInfo.id, infos,
489
 
                                               DatabaseFields::Rating |
 
492
                                               DatabaseFields::Rating       |
490
493
                                               DatabaseFields::CreationDate |
491
494
                                               DatabaseFields::Format);
492
495
 
502
505
        foreach (const QString& key, keys)
503
506
        {
504
507
            KFileMetaInfoItem item = metaInfo.item(key);
505
 
            kDebug(digiKamAreaCode) << item.name() << item.value();
 
508
            kDebug() << item.name() << item.value();
506
509
        }
507
510
    }
508
511
    */
518
521
          << detectAudioFormat();
519
522
 
520
523
    DatabaseAccess().db()->addImageInformation(m_scanInfo.id, infos,
521
 
                                               DatabaseFields::Rating |
 
524
                                               DatabaseFields::Rating       |
522
525
                                               DatabaseFields::CreationDate |
523
526
                                               DatabaseFields::Format);
524
527
}
535
538
    if (m_hasMetadata)
536
539
    {
537
540
        m_img.setComments(m_metadata.getComments());
 
541
 
 
542
#if KEXIV2_VERSION >= 0x010000
 
543
        m_img.setExif(m_metadata.getExifEncoded());
 
544
#else
538
545
        m_img.setExif(m_metadata.getExif());
 
546
#endif
 
547
 
539
548
        m_img.setIptc(m_metadata.getIptc());
540
549
        m_img.setXmp(m_metadata.getXmp());
541
550
    }
596
605
                }
597
606
            }
598
607
 
599
 
            kWarning(digiKamAreaCode) << "Detecting file format failed: KMimeType for" << m_fileInfo.filePath()
600
 
                            << "is null";
 
608
            kWarning() << "Detecting file format failed: KMimeType for" << m_fileInfo.filePath()
 
609
                                      << "is null";
601
610
 
602
611
        }
603
612
    }
607
616
QString ImageScanner::detectVideoFormat()
608
617
{
609
618
    QString suffix = m_fileInfo.suffix().toUpper();
 
619
 
610
620
    if (suffix == "MPEG" || suffix == "MPG" || suffix == "MPO" || suffix == "MPE")
611
621
        return "MPEG";
612
622
    if (suffix =="ASF" || suffix == "WMV")
613
623
        return "WMV";
 
624
 
614
625
    return suffix;
615
626
}
616
627
 
805
816
    {
806
817
        DatabaseAccess access;
807
818
        imagesFields = access.db()->getImagesFields(imageid,
808
 
                                           DatabaseFields::Name |
 
819
                                           DatabaseFields::Name             |
809
820
                                           DatabaseFields::ModificationDate |
810
821
                                           DatabaseFields::FileSize);
811
822
 
812
823
        imageInformationFields = access.db()->getImageInformation(imageid,
813
 
                                           DatabaseFields::Rating |
814
 
                                           DatabaseFields::CreationDate |
 
824
                                           DatabaseFields::Rating           |
 
825
                                           DatabaseFields::CreationDate     |
815
826
                                           DatabaseFields::DigitizationDate |
816
 
                                           DatabaseFields::Orientation |
817
 
                                           DatabaseFields::Width |
818
 
                                           DatabaseFields::Height |
819
 
                                           DatabaseFields::Format |
820
 
                                           DatabaseFields::ColorDepth |
 
827
                                           DatabaseFields::Orientation      |
 
828
                                           DatabaseFields::Width            |
 
829
                                           DatabaseFields::Height           |
 
830
                                           DatabaseFields::Format           |
 
831
                                           DatabaseFields::ColorDepth       |
821
832
                                           DatabaseFields::ColorModel);
822
833
    }
823
834