• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

digikam

album.cpp

Go to the documentation of this file.
00001 /* ============================================================
00002  *
00003  * This file is a part of digiKam project
00004  * http://www.digikam.org
00005  *
00006  * Date        : 2004-06-15
00007  * Description : digiKam album types
00008  *
00009  * Copyright (C) 2004-2005 by Renchi Raju <renchi@pooh.tam.uiuc.edu>
00010  * Copyright (C) 2006-2009 by Gilles Caulier <caulier dot gilles at gmail dot com>
00011  *
00012  * This program is free software; you can redistribute it
00013  * and/or modify it under the terms of the GNU General
00014  * Public License as published by the Free Software Foundation;
00015  * either version 2, or (at your option)
00016  * any later version.
00017  *
00018  * This program is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * ============================================================ */
00024 
00025 
00026 #include "album.h"
00027 
00028 // KDE includes
00029 
00030 #include <klocale.h>
00031 #include <kdebug.h>
00032 
00033 // Local includes
00034 
00035 #include "albumdb.h"
00036 #include "albummanager.h"
00037 #include "collectionmanager.h"
00038 #include "databaseaccess.h"
00039 #include "databaseurl.h"
00040 
00041 namespace Digikam
00042 {
00043 
00044 Album::Album(Album::Type type, int id, bool root)
00045 {
00046     m_parent     = 0;
00047     m_next       = 0;
00048     m_prev       = 0;
00049     m_firstChild = 0;
00050     m_lastChild  = 0;
00051     m_clearing   = false;
00052     m_type       = type;
00053     m_id         = id;
00054     m_root       = root;
00055 }
00056 
00057 Album::~Album()
00058 {
00059     if (m_parent)
00060         m_parent->removeChild(this);
00061     clear();
00062     AlbumManager::internalInstance->notifyAlbumDeletion(this);
00063 }
00064 
00065 void Album::setParent(Album* parent)
00066 {
00067     if (parent)
00068     {
00069         m_parent = parent;
00070         parent->insertChild(this);
00071     }
00072 }
00073 
00074 Album* Album::parent() const
00075 {
00076     return m_parent;
00077 }
00078 
00079 Album* Album::firstChild() const
00080 {
00081     return m_firstChild;
00082 }
00083 
00084 Album* Album::lastChild() const
00085 {
00086     return m_lastChild;
00087 }
00088 
00089 Album* Album::next() const
00090 {
00091     return m_next;
00092 }
00093 
00094 Album* Album::prev() const
00095 {
00096     return m_prev;
00097 }
00098 
00099 void Album::insertChild(Album* child)
00100 {
00101     if (!child)
00102         return;
00103 
00104     if (!m_firstChild)
00105     {
00106         m_firstChild  = child;
00107         m_lastChild   = child;
00108         child->m_next = 0;
00109         child->m_prev = 0;
00110     }
00111     else
00112     {
00113         m_lastChild->m_next = child;
00114         child->m_prev       = m_lastChild;
00115         child->m_next       = 0;
00116         m_lastChild         = child;
00117     }
00118 }
00119 
00120 void Album::removeChild(Album* child)
00121 {
00122     if (!child || m_clearing)
00123         return;
00124 
00125     if (child == m_firstChild)
00126     {
00127         m_firstChild = m_firstChild->m_next;
00128         if (m_firstChild)
00129             m_firstChild->m_prev = 0;
00130         else
00131             m_firstChild = m_lastChild = 0;
00132     }
00133     else if (child == m_lastChild)
00134     {
00135         m_lastChild = m_lastChild->m_prev;
00136         if (m_lastChild)
00137             m_lastChild->m_next = 0;
00138         else
00139             m_firstChild = m_lastChild = 0;
00140     }
00141     else
00142     {
00143         Album* c = child;
00144         if (c->m_prev)
00145             c->m_prev->m_next = c->m_next;
00146         if (c->m_next)
00147             c->m_next->m_prev = c->m_prev;
00148     }
00149 }
00150 
00151 void Album::clear()
00152 {
00153     m_clearing = true;
00154 
00155     Album* child = m_firstChild;
00156     Album* nextChild;
00157     while (child)
00158     {
00159         nextChild = child->m_next;
00160         delete child;
00161         child = nextChild;
00162     }
00163 
00164     m_firstChild = 0;
00165     m_lastChild  = 0;
00166     m_clearing   = false;
00167 }
00168 
00169 int Album::globalID() const
00170 {
00171     switch (m_type)
00172     {
00173         // Use the upper bits to create unique ids.
00174         case (PHYSICAL):
00175             return m_id;
00176         case(TAG):
00177             return m_id | (1 << 28);
00178         case(DATE):
00179             return m_id | (1 << 29);
00180         case(SEARCH):
00181             return m_id | (1 << 30);
00182         default:
00183             kError() << "Unknown album type";
00184             return -1;
00185     }
00186 }
00187 
00188 int Album::id() const
00189 {
00190     return m_id;
00191 }
00192 
00193 void Album::setTitle(const QString& title)
00194 {
00195     m_title = title;
00196 }
00197 
00198 QString Album::title() const
00199 {
00200     return m_title;
00201 }
00202 
00203 Album::Type Album::type() const
00204 {
00205     return m_type;
00206 }
00207 
00208 void Album::setExtraData(const void* key, void* value)
00209 {
00210     m_extraMap.insert(key, value);
00211 }
00212 
00213 void Album::removeExtraData(const void* key)
00214 {
00215     m_extraMap.remove(key);
00216 }
00217 
00218 void* Album::extraData(const void* key) const
00219 {
00220     typedef QMap<const void*, void*> Map;
00221     Map::const_iterator it = m_extraMap.constFind(key);
00222     if (it == m_extraMap.constEnd())
00223         return 0;
00224 
00225     return it.value();
00226 }
00227 
00228 bool Album::isRoot() const
00229 {
00230     return m_root;
00231 }
00232 
00233 bool Album::isAncestorOf(Album* album) const
00234 {
00235     bool val = false;
00236     Album* a = album;
00237     while (a && !a->isRoot())
00238     {
00239         if (a == this)
00240         {
00241             val = true;
00242             break;
00243         }
00244         a = a->parent();
00245     }
00246     return val;
00247 }
00248 
00249 // ------------------------------------------------------------------------------
00250 
00251 PAlbum::PAlbum(const QString& title)
00252       : Album(Album::PHYSICAL, 0, true)
00253 {
00254     setTitle(title);
00255     m_isAlbumRootAlbum = false;
00256     m_albumRootId      = -1;
00257     m_parentPath       = '/';
00258     m_path.clear();
00259 }
00260 
00261 PAlbum::PAlbum(int albumRoot, const QString& label)
00262       : Album(Album::PHYSICAL, -1, false)
00263 {
00264     // set the id to -1 (line above). AlbumManager may change that later.
00265     setTitle(label);
00266     m_albumRootId      = albumRoot;
00267     m_isAlbumRootAlbum = true;
00268     m_parentPath       = '/';
00269     m_path.clear();
00270 }
00271 
00272 PAlbum::PAlbum(int albumRoot, const QString& parentPath, const QString& title, int id)
00273       : Album(Album::PHYSICAL, id, false)
00274 {
00275     // If path is /holidays/2007, title is only "2007", path is "/holidays"
00276     setTitle(title);
00277     m_albumRootId = albumRoot;
00278     m_isAlbumRootAlbum = false;
00279     m_parentPath  = parentPath + '/';
00280     m_path        = title;
00281     m_date        = QDate::currentDate();
00282 }
00283 
00284 PAlbum::~PAlbum()
00285 {
00286 }
00287 
00288 bool PAlbum::isAlbumRoot() const
00289 {
00290     return m_isAlbumRootAlbum;
00291 }
00292 
00293 void PAlbum::setCaption(const QString& caption)
00294 {
00295     m_caption = caption;
00296 
00297     DatabaseAccess access;
00298     access.db()->setAlbumCaption(id(), m_caption);
00299 }
00300 
00301 void PAlbum::setCategory(const QString& category)
00302 {
00303     m_category = category;
00304 
00305     DatabaseAccess access;
00306     access.db()->setAlbumCategory(id(), m_category);
00307 }
00308 
00309 void PAlbum::setDate(const QDate& date)
00310 {
00311     m_date = date;
00312 
00313     DatabaseAccess access;
00314     access.db()->setAlbumDate(id(), m_date);
00315 }
00316 
00317 QString PAlbum::albumRootPath() const
00318 {
00319     return CollectionManager::instance()->albumRootPath(m_albumRootId);
00320 }
00321 
00322 int PAlbum::albumRootId() const
00323 {
00324     return m_albumRootId;
00325 }
00326 
00327 QString PAlbum::caption() const
00328 {
00329     return m_caption;
00330 }
00331 
00332 QString PAlbum::category() const
00333 {
00334     return m_category;
00335 }
00336 
00337 QDate PAlbum::date() const
00338 {
00339     return m_date;
00340 }
00341 
00342 QString PAlbum::albumPath() const
00343 {
00344     return m_parentPath + m_path;
00345 }
00346 
00347 DatabaseUrl PAlbum::databaseUrl() const
00348 {
00349     return DatabaseUrl::fromAlbumAndName(QString(), albumPath(), albumRootPath(), m_albumRootId);
00350 }
00351 
00352 QString PAlbum::prettyUrl() const
00353 {
00354     QString u = i18n("My Albums") + albumPath();
00355     return u;
00356 }
00357 
00358 QString PAlbum::icon() const
00359 {
00360     return m_icon;
00361 }
00362 
00363 KUrl PAlbum::iconKURL() const
00364 {
00365     KUrl u;
00366     u.setPath( m_icon );
00367     return u;
00368 }
00369 
00370 KUrl PAlbum::fileUrl() const
00371 {
00372     return databaseUrl().fileUrl();
00373 }
00374 
00375 QString PAlbum::folderPath() const
00376 {
00377     return databaseUrl().fileUrl().toLocalFile();
00378 }
00379 
00380 // --------------------------------------------------------------------------
00381 
00382 TAlbum::TAlbum(const QString& title, int id, bool root)
00383       : Album(Album::TAG, id, root)
00384 {
00385     setTitle(title);
00386 }
00387 
00388 TAlbum::~TAlbum()
00389 {
00390 }
00391 
00392 QString TAlbum::tagPath(bool leadingSlash) const
00393 {
00394     if (isRoot())
00395         return leadingSlash ? "/" : "";
00396 
00397     QString u;
00398 
00399     if (parent())
00400     {
00401         u = ((TAlbum*)parent())->tagPath(leadingSlash);
00402         if (!parent()->isRoot())
00403             u += '/';
00404     }
00405 
00406     u += title();
00407 
00408     return u;
00409 }
00410 
00411 QString TAlbum::prettyUrl() const
00412 {
00413     QString u = i18n("My Tags") + tagPath(true);
00414     return u;
00415 }
00416 
00417 DatabaseUrl TAlbum::databaseUrl() const
00418 {
00419     return DatabaseUrl::fromTagIds(tagIDs());
00420 }
00421 
00422 QList<int> TAlbum::tagIDs() const
00423 {
00424     if (isRoot())
00425     {
00426         return QList<int>();
00427     }
00428     else if (parent())
00429     {
00430         return static_cast<TAlbum*>(parent())->tagIDs() << id();
00431     }
00432     else
00433     {
00434         return QList<int>() << id();
00435     }
00436 }
00437 
00438 QString TAlbum::icon() const
00439 {
00440     return m_icon;
00441 }
00442 
00443 // --------------------------------------------------------------------------
00444 
00445 int DAlbum::m_uniqueID = 0;
00446 
00447 DAlbum::DAlbum(const QDate& date, bool root, Range range)
00448       : Album(Album::DATE, root ? 0 : ++m_uniqueID, root)
00449 {
00450     m_date  = date;
00451     m_range = range;
00452 
00453     // Set the name of the date album
00454     QString dateTitle;
00455 
00456     if (m_range == Month)
00457         dateTitle = m_date.toString("MMMM yyyy");
00458     else
00459         dateTitle = m_date.toString("yyyy");
00460 
00461     setTitle(dateTitle);
00462 }
00463 
00464 DAlbum::~DAlbum()
00465 {
00466 }
00467 
00468 QDate DAlbum::date() const
00469 {
00470     return m_date;
00471 }
00472 
00473 DAlbum::Range DAlbum::range() const
00474 {
00475     return m_range;
00476 }
00477 
00478 DatabaseUrl DAlbum::databaseUrl() const
00479 {
00480     if (m_range == Month)
00481         return DatabaseUrl::fromDateForMonth(m_date);
00482 
00483     return DatabaseUrl::fromDateForYear(m_date);
00484 }
00485 
00486 // --------------------------------------------------------------------------
00487 
00488 SAlbum::SAlbum(const QString& title, int id, bool root)
00489       : Album(Album::SEARCH, id, root),
00490         m_type(DatabaseSearch::UndefinedType)
00491 {
00492     setTitle(title);
00493 }
00494 
00495 SAlbum::~SAlbum()
00496 {
00497 }
00498 
00499 void SAlbum::setSearch(DatabaseSearch::Type type, const QString& query)
00500 {
00501     m_type  = type;
00502     m_query = query;
00503 }
00504 
00505 DatabaseUrl SAlbum::databaseUrl() const
00506 {
00507     return DatabaseUrl::searchUrl(id());
00508 }
00509 
00510 QString SAlbum::query() const
00511 {
00512     return m_query;
00513 }
00514 
00515 DatabaseSearch::Type SAlbum::type() const
00516 {
00517     return m_type;
00518 }
00519 
00520 bool SAlbum::isNormalSearch() const
00521 {
00522     switch (m_type)
00523     {
00524         case DatabaseSearch::KeywordSearch:
00525         case DatabaseSearch::AdvancedSearch:
00526         case DatabaseSearch::LegacyUrlSearch:
00527             return true;
00528         default:
00529             return false;
00530     }
00531 }
00532 
00533 bool SAlbum::isAdvancedSearch() const
00534 {
00535     return m_type == DatabaseSearch::AdvancedSearch;
00536 }
00537 
00538 bool SAlbum::isKeywordSearch() const
00539 {
00540     return m_type == DatabaseSearch::KeywordSearch;
00541 }
00542 
00543 bool SAlbum::isTimelineSearch() const
00544 {
00545     return m_type == DatabaseSearch::TimeLineSearch;
00546 }
00547 
00548 bool SAlbum::isHaarSearch() const
00549 {
00550     return m_type == DatabaseSearch::HaarSearch;
00551 }
00552 
00553 bool SAlbum::isMapSearch() const
00554 {
00555     return m_type == DatabaseSearch::MapSearch;
00556 }
00557 
00558 bool SAlbum::isDuplicatesSearch() const
00559 {
00560     return m_type == DatabaseSearch::DuplicatesSearch;
00561 }
00562 
00563 // --------------------------------------------------------------------------
00564 
00565 AlbumIterator::AlbumIterator(Album *album)
00566 {
00567     m_root    = album;
00568     m_current = album ? album->firstChild() : 0;
00569 }
00570 
00571 AlbumIterator::~AlbumIterator()
00572 {
00573 }
00574 
00575 AlbumIterator& AlbumIterator::operator++()
00576 {
00577     if (!m_current)
00578         return *this;
00579 
00580     Album *album = m_current->firstChild();
00581     if ( !album )
00582     {
00583         while ( (album = m_current->next()) == 0  )
00584         {
00585             m_current = m_current->parent();
00586 
00587             if ( m_current == m_root )
00588             {
00589                 // we have reached the root.
00590                 // that means no more children
00591                 m_current = 0;
00592                 break;
00593             }
00594 
00595             if ( m_current == 0 )
00596                 break;
00597         }
00598     }
00599 
00600     m_current = album;
00601     return *this;
00602 }
00603 
00604 Album* AlbumIterator::operator*()
00605 {
00606     return m_current;
00607 }
00608 
00609 Album* AlbumIterator::current() const
00610 {
00611     return m_current;
00612 }
00613 
00614 }  // namespace Digikam

digikam

Skip menu "digikam"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • digikam
Generated for API Reference by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal