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