2010-08-07 09:10:44 -04:00
|
|
|
/*
|
2012-04-27 04:50:32 -04:00
|
|
|
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 or (at your option)
|
|
|
|
* version 3 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2010-08-07 09:10:44 -04:00
|
|
|
|
|
|
|
#include "Group.h"
|
|
|
|
|
2012-05-28 14:16:49 -04:00
|
|
|
#include "core/Config.h"
|
2011-07-08 08:51:14 -04:00
|
|
|
#include "core/DatabaseIcons.h"
|
|
|
|
#include "core/Metadata.h"
|
2012-05-09 14:29:21 -04:00
|
|
|
#include "core/Tools.h"
|
2010-08-12 15:38:59 -04:00
|
|
|
|
2012-07-01 15:58:45 -04:00
|
|
|
const int Group::DefaultIconNumber = 48;
|
|
|
|
|
2010-08-13 12:08:06 -04:00
|
|
|
Group::Group()
|
2012-07-19 07:57:55 -04:00
|
|
|
: m_iconNumber(DefaultIconNumber)
|
|
|
|
, m_isExpanded(true)
|
|
|
|
, m_autoTypeEnabled(Inherit)
|
|
|
|
, m_searchingEnabled(Inherit)
|
|
|
|
, m_updateTimeinfo(true)
|
2010-08-12 15:38:59 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-08-18 10:22:48 -04:00
|
|
|
Group::~Group()
|
|
|
|
{
|
2011-07-09 15:54:01 -04:00
|
|
|
cleanupParent();
|
2012-04-21 17:31:37 -04:00
|
|
|
this->blockSignals(true);
|
2012-04-21 13:06:28 -04:00
|
|
|
if (m_db && m_parent) {
|
|
|
|
QList<Entry*> entries = m_entries;
|
|
|
|
Q_FOREACH (Entry* entry, entries) {
|
2012-04-21 17:31:37 -04:00
|
|
|
entry->blockSignals(true);
|
2012-04-21 13:06:28 -04:00
|
|
|
delete entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<Group*> children = m_children;
|
|
|
|
Q_FOREACH (Group* group, children) {
|
2012-04-21 17:31:37 -04:00
|
|
|
group->blockSignals(true);
|
2012-04-21 13:06:28 -04:00
|
|
|
delete group;
|
|
|
|
}
|
|
|
|
|
|
|
|
DeletedObject delGroup;
|
2012-05-09 14:29:21 -04:00
|
|
|
delGroup.deletionTime = Tools::currentDateTimeUtc();
|
2012-04-21 13:06:28 -04:00
|
|
|
delGroup.uuid = m_uuid;
|
|
|
|
m_db->addDeletedObject(delGroup);
|
|
|
|
}
|
2010-08-18 10:22:48 -04:00
|
|
|
}
|
|
|
|
|
2012-04-21 18:10:04 -04:00
|
|
|
template <class P, class V> bool Group::set(P& property, const V& value) {
|
2012-04-11 12:00:28 -04:00
|
|
|
if (property != value) {
|
|
|
|
property = value;
|
2012-04-18 10:58:14 -04:00
|
|
|
updateTimeinfo();
|
2012-04-11 12:00:28 -04:00
|
|
|
Q_EMIT modified();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-17 16:43:21 -04:00
|
|
|
void Group::updateTimeinfo()
|
|
|
|
{
|
|
|
|
if (m_updateTimeinfo) {
|
2012-05-09 14:29:21 -04:00
|
|
|
m_timeInfo.setLastModificationTime(Tools::currentDateTimeUtc());
|
|
|
|
m_timeInfo.setLastAccessTime(Tools::currentDateTimeUtc());
|
2012-04-17 16:43:21 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-29 18:22:07 -04:00
|
|
|
void Group::setUpdateTimeinfo(bool value)
|
|
|
|
{
|
2012-04-11 12:00:28 -04:00
|
|
|
m_updateTimeinfo = value;
|
|
|
|
}
|
|
|
|
|
2010-08-12 15:38:59 -04:00
|
|
|
Uuid Group::uuid() const
|
|
|
|
{
|
|
|
|
return m_uuid;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Group::name() const
|
|
|
|
{
|
|
|
|
return m_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Group::notes() const
|
|
|
|
{
|
|
|
|
return m_notes;
|
|
|
|
}
|
|
|
|
|
2012-01-01 15:52:54 -05:00
|
|
|
QImage Group::icon() const
|
2010-08-12 15:38:59 -04:00
|
|
|
{
|
2010-09-19 15:22:24 -04:00
|
|
|
if (m_customIcon.isNull()) {
|
2012-01-01 15:52:54 -05:00
|
|
|
return databaseIcons()->icon(m_iconNumber);
|
2010-08-24 17:12:01 -04:00
|
|
|
}
|
|
|
|
else {
|
2012-05-11 06:39:06 -04:00
|
|
|
// TODO: check if m_db is 0
|
2010-09-19 15:22:24 -04:00
|
|
|
return m_db->metadata()->customIcon(m_customIcon);
|
2010-08-24 17:12:01 -04:00
|
|
|
}
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
2012-01-01 15:52:54 -05:00
|
|
|
QPixmap Group::iconPixmap() const
|
|
|
|
{
|
|
|
|
if (m_customIcon.isNull()) {
|
|
|
|
return databaseIcons()->iconPixmap(m_iconNumber);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
QPixmap pixmap;
|
|
|
|
if (!QPixmapCache::find(m_pixmapCacheKey, &pixmap)) {
|
2012-05-11 06:39:06 -04:00
|
|
|
// TODO: check if m_db is 0
|
2012-01-01 15:52:54 -05:00
|
|
|
pixmap = QPixmap::fromImage(m_db->metadata()->customIcon(m_customIcon));
|
|
|
|
*const_cast<QPixmapCache::Key*>(&m_pixmapCacheKey) = QPixmapCache::insert(pixmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pixmap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-18 16:57:26 -04:00
|
|
|
int Group::iconNumber() const
|
|
|
|
{
|
|
|
|
return m_iconNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
Uuid Group::iconUuid() const
|
|
|
|
{
|
|
|
|
return m_customIcon;
|
|
|
|
}
|
|
|
|
|
2010-08-12 15:38:59 -04:00
|
|
|
TimeInfo Group::timeInfo() const
|
|
|
|
{
|
|
|
|
return m_timeInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Group::isExpanded() const
|
|
|
|
{
|
|
|
|
return m_isExpanded;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Group::defaultAutoTypeSequence() const
|
|
|
|
{
|
|
|
|
return m_defaultAutoTypeSequence;
|
|
|
|
}
|
|
|
|
|
2011-07-07 06:45:14 -04:00
|
|
|
Group::TriState Group::autoTypeEnabled() const
|
2010-08-19 08:03:54 -04:00
|
|
|
{
|
|
|
|
return m_autoTypeEnabled;
|
|
|
|
}
|
|
|
|
|
2012-05-13 07:33:55 -04:00
|
|
|
Group::TriState Group::searchingEnabled() const
|
2010-08-19 08:03:54 -04:00
|
|
|
{
|
|
|
|
return m_searchingEnabled;
|
|
|
|
}
|
|
|
|
|
2010-08-12 15:38:59 -04:00
|
|
|
Entry* Group::lastTopVisibleEntry() const
|
|
|
|
{
|
|
|
|
return m_lastTopVisibleEntry;
|
|
|
|
}
|
|
|
|
|
2012-05-15 13:58:10 -04:00
|
|
|
bool Group::isExpired() const
|
|
|
|
{
|
|
|
|
return m_timeInfo.expires() && m_timeInfo.expiryTime() < Tools::currentDateTimeUtc();
|
|
|
|
}
|
|
|
|
|
2010-08-12 15:38:59 -04:00
|
|
|
void Group::setUuid(const Uuid& uuid)
|
|
|
|
{
|
2012-04-11 12:00:28 -04:00
|
|
|
set(m_uuid, uuid);
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Group::setName(const QString& name)
|
|
|
|
{
|
2012-04-11 12:00:28 -04:00
|
|
|
if (set(m_name, name)) {
|
|
|
|
Q_EMIT dataChanged(this);
|
|
|
|
}
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Group::setNotes(const QString& notes)
|
|
|
|
{
|
2012-04-11 12:00:28 -04:00
|
|
|
set(m_notes, notes);
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Group::setIcon(int iconNumber)
|
|
|
|
{
|
2010-08-14 06:24:35 -04:00
|
|
|
Q_ASSERT(iconNumber >= 0);
|
|
|
|
|
2012-04-11 12:00:28 -04:00
|
|
|
if (m_iconNumber != iconNumber || !m_customIcon.isNull()) {
|
|
|
|
m_iconNumber = iconNumber;
|
|
|
|
m_customIcon = Uuid();
|
2010-08-15 09:03:47 -04:00
|
|
|
|
2012-04-11 12:00:28 -04:00
|
|
|
m_pixmapCacheKey = QPixmapCache::Key();
|
2012-01-01 15:52:54 -05:00
|
|
|
|
2012-04-18 10:58:14 -04:00
|
|
|
updateTimeinfo();
|
2012-04-11 12:00:28 -04:00
|
|
|
Q_EMIT modified();
|
|
|
|
Q_EMIT dataChanged(this);
|
|
|
|
}
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Group::setIcon(const Uuid& uuid)
|
|
|
|
{
|
2010-08-14 06:24:35 -04:00
|
|
|
Q_ASSERT(!uuid.isNull());
|
|
|
|
|
2012-04-18 11:14:51 -04:00
|
|
|
if (m_customIcon != uuid) {
|
|
|
|
m_customIcon = uuid;
|
2012-04-11 12:00:28 -04:00
|
|
|
m_iconNumber = 0;
|
2010-08-15 09:03:47 -04:00
|
|
|
|
2012-04-11 12:00:28 -04:00
|
|
|
m_pixmapCacheKey = QPixmapCache::Key();
|
2012-01-01 15:52:54 -05:00
|
|
|
|
2012-04-18 11:14:51 -04:00
|
|
|
updateTimeinfo();
|
|
|
|
Q_EMIT modified();
|
2012-04-11 12:00:28 -04:00
|
|
|
Q_EMIT dataChanged(this);
|
|
|
|
}
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Group::setTimeInfo(const TimeInfo& timeInfo)
|
|
|
|
{
|
|
|
|
m_timeInfo = timeInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Group::setExpanded(bool expanded)
|
|
|
|
{
|
2012-05-28 14:16:49 -04:00
|
|
|
if (m_isExpanded != expanded) {
|
|
|
|
m_isExpanded = expanded;
|
|
|
|
updateTimeinfo();
|
2012-05-30 05:21:42 -04:00
|
|
|
if (config()->get("ModifiedOnExpandedStateChanges").toBool()) {
|
2012-05-28 14:16:49 -04:00
|
|
|
Q_EMIT modified();
|
|
|
|
}
|
|
|
|
}
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Group::setDefaultAutoTypeSequence(const QString& sequence)
|
|
|
|
{
|
2012-04-11 12:00:28 -04:00
|
|
|
set(m_defaultAutoTypeSequence, sequence);
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
2011-07-07 06:45:14 -04:00
|
|
|
void Group::setAutoTypeEnabled(TriState enable)
|
2010-08-19 08:03:54 -04:00
|
|
|
{
|
2012-04-11 12:00:28 -04:00
|
|
|
set(m_autoTypeEnabled, enable);
|
2010-08-19 08:03:54 -04:00
|
|
|
}
|
|
|
|
|
2011-07-07 06:45:14 -04:00
|
|
|
void Group::setSearchingEnabled(TriState enable)
|
2010-08-19 08:03:54 -04:00
|
|
|
{
|
2012-04-11 12:00:28 -04:00
|
|
|
set(m_searchingEnabled, enable);
|
2010-08-19 08:03:54 -04:00
|
|
|
}
|
|
|
|
|
2010-08-12 15:38:59 -04:00
|
|
|
void Group::setLastTopVisibleEntry(Entry* entry)
|
|
|
|
{
|
2012-04-11 12:00:28 -04:00
|
|
|
set(m_lastTopVisibleEntry, entry);
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
2012-05-18 04:52:05 -04:00
|
|
|
void Group::setExpires(const bool& value)
|
|
|
|
{
|
|
|
|
if (m_timeInfo.expires() != value) {
|
|
|
|
m_timeInfo.setExpires(value);
|
|
|
|
updateTimeinfo();
|
|
|
|
Q_EMIT modified();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Group::setExpiryTime(const QDateTime& dateTime)
|
|
|
|
{
|
|
|
|
if (m_timeInfo.expiryTime() != dateTime) {
|
|
|
|
m_timeInfo.setExpiryTime(dateTime);
|
|
|
|
updateTimeinfo();
|
|
|
|
Q_EMIT modified();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-23 15:30:20 -04:00
|
|
|
Group* Group::parentGroup()
|
|
|
|
{
|
|
|
|
return m_parent;
|
|
|
|
}
|
|
|
|
|
2010-08-15 06:31:48 -04:00
|
|
|
const Group* Group::parentGroup() const
|
|
|
|
{
|
|
|
|
return m_parent;
|
|
|
|
}
|
|
|
|
|
2010-08-18 04:27:40 -04:00
|
|
|
void Group::setParent(Group* parent, int index)
|
2010-08-12 15:38:59 -04:00
|
|
|
{
|
2010-08-18 04:27:40 -04:00
|
|
|
Q_ASSERT(parent);
|
|
|
|
Q_ASSERT(index >= -1 && index <= parent->children().size());
|
2011-07-09 15:54:01 -04:00
|
|
|
// setting a new parent for root groups is not allowed
|
|
|
|
Q_ASSERT(!m_db || (m_db->rootGroup() != this));
|
2010-08-18 04:27:40 -04:00
|
|
|
|
2012-04-23 10:57:08 -04:00
|
|
|
bool moveWithinDatabase = (m_db && m_db == parent->m_db);
|
|
|
|
|
2010-08-18 04:27:40 -04:00
|
|
|
if (index == -1) {
|
|
|
|
index = parent->children().size();
|
2012-04-24 18:10:06 -04:00
|
|
|
|
|
|
|
if (parentGroup() == parent) {
|
|
|
|
index--;
|
|
|
|
}
|
2010-08-18 04:27:40 -04:00
|
|
|
}
|
|
|
|
|
2012-04-23 10:57:08 -04:00
|
|
|
if (m_parent == parent && parent->children().indexOf(this) == index) {
|
2012-04-22 06:09:12 -04:00
|
|
|
return;
|
|
|
|
}
|
2012-04-11 12:00:28 -04:00
|
|
|
|
2012-04-23 10:57:08 -04:00
|
|
|
if (!moveWithinDatabase) {
|
|
|
|
cleanupParent();
|
|
|
|
m_parent = parent;
|
2012-04-27 04:50:32 -04:00
|
|
|
if (m_db) {
|
2012-04-23 10:57:08 -04:00
|
|
|
recCreateDelObjects();
|
2012-04-27 05:22:02 -04:00
|
|
|
|
|
|
|
// copy custom icon to the new database
|
|
|
|
if (!iconUuid().isNull() && parent->m_db
|
|
|
|
&& m_db->metadata()->containsCustomIcon(iconUuid())
|
|
|
|
&& !parent->m_db->metadata()->containsCustomIcon(iconUuid())) {
|
|
|
|
parent->m_db->metadata()->addCustomIcon(iconUuid(), icon());
|
|
|
|
}
|
2012-04-27 04:50:32 -04:00
|
|
|
}
|
|
|
|
if (m_db != parent->m_db) {
|
2012-04-23 10:57:08 -04:00
|
|
|
recSetDatabase(parent->m_db);
|
|
|
|
}
|
|
|
|
QObject::setParent(parent);
|
|
|
|
Q_EMIT aboutToAdd(this, index);
|
2012-04-24 18:10:06 -04:00
|
|
|
Q_ASSERT(index <= parent->m_children.size());
|
2012-04-23 10:57:08 -04:00
|
|
|
parent->m_children.insert(index, this);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Q_EMIT aboutToMove(this, parent, index);
|
|
|
|
m_parent->m_children.removeAll(this);
|
|
|
|
m_parent = parent;
|
|
|
|
QObject::setParent(parent);
|
2012-04-24 18:10:06 -04:00
|
|
|
Q_ASSERT(index <= parent->m_children.size());
|
2012-04-23 10:57:08 -04:00
|
|
|
parent->m_children.insert(index, this);
|
2010-08-14 06:24:35 -04:00
|
|
|
}
|
2010-08-18 04:27:40 -04:00
|
|
|
|
2012-04-22 06:09:12 -04:00
|
|
|
if (m_updateTimeinfo) {
|
2012-05-09 14:29:21 -04:00
|
|
|
m_timeInfo.setLocationChanged(Tools::currentDateTimeUtc());
|
2012-04-22 06:09:12 -04:00
|
|
|
}
|
|
|
|
|
2012-04-11 12:00:28 -04:00
|
|
|
Q_EMIT modified();
|
2012-04-23 10:57:08 -04:00
|
|
|
|
|
|
|
if (!moveWithinDatabase) {
|
|
|
|
Q_EMIT added();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Q_EMIT moved();
|
|
|
|
}
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Group::setParent(Database* db)
|
|
|
|
{
|
2010-08-18 04:27:40 -04:00
|
|
|
Q_ASSERT(db);
|
2012-04-27 04:50:32 -04:00
|
|
|
Q_ASSERT(db->rootGroup() == this);
|
2010-08-18 04:27:40 -04:00
|
|
|
|
2011-07-09 15:54:01 -04:00
|
|
|
cleanupParent();
|
2010-08-18 04:27:40 -04:00
|
|
|
|
2012-06-29 08:15:16 -04:00
|
|
|
m_parent = Q_NULLPTR;
|
2010-08-14 06:24:35 -04:00
|
|
|
recSetDatabase(db);
|
|
|
|
|
2010-08-12 15:38:59 -04:00
|
|
|
QObject::setParent(db);
|
|
|
|
}
|
|
|
|
|
2012-04-21 18:29:39 -04:00
|
|
|
Database* Group::database()
|
|
|
|
{
|
|
|
|
return m_db;
|
|
|
|
}
|
|
|
|
|
2010-08-14 06:24:35 -04:00
|
|
|
const Database* Group::database() const
|
|
|
|
{
|
|
|
|
return m_db;
|
|
|
|
}
|
|
|
|
|
2010-08-15 09:03:47 -04:00
|
|
|
QList<Group*> Group::children()
|
|
|
|
{
|
|
|
|
return m_children;
|
|
|
|
}
|
|
|
|
|
2010-08-25 08:00:46 -04:00
|
|
|
const QList<Group*>& Group::children() const
|
2010-08-15 06:31:48 -04:00
|
|
|
{
|
2010-08-25 08:00:46 -04:00
|
|
|
return m_children;
|
2010-08-15 06:31:48 -04:00
|
|
|
}
|
|
|
|
|
2010-08-15 09:03:47 -04:00
|
|
|
QList<Entry*> Group::entries()
|
2010-08-12 15:38:59 -04:00
|
|
|
{
|
2010-08-15 09:03:47 -04:00
|
|
|
return m_entries;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
2010-08-25 08:00:46 -04:00
|
|
|
const QList<Entry*>& Group::entries() const
|
2010-08-15 06:31:48 -04:00
|
|
|
{
|
2010-08-25 08:00:46 -04:00
|
|
|
return m_entries;
|
2010-08-15 06:31:48 -04:00
|
|
|
}
|
|
|
|
|
2012-05-11 18:01:58 -04:00
|
|
|
QList<Entry*> Group::entriesRecursive(bool includeHistoryItems) const
|
2012-04-21 10:45:46 -04:00
|
|
|
{
|
|
|
|
QList<Entry*> entryList;
|
|
|
|
|
|
|
|
entryList.append(m_entries);
|
|
|
|
|
|
|
|
if (includeHistoryItems) {
|
|
|
|
Q_FOREACH (Entry* entry, m_entries) {
|
|
|
|
entryList.append(entry->historyItems());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_FOREACH (Group* group, m_children) {
|
|
|
|
entryList.append(group->entriesRecursive(includeHistoryItems));
|
|
|
|
}
|
|
|
|
|
|
|
|
return entryList;
|
|
|
|
}
|
|
|
|
|
2012-05-11 19:51:41 -04:00
|
|
|
QList<const Group*> Group::groupsRecursive(bool includeSelf) const
|
|
|
|
{
|
|
|
|
QList<const Group*> groupList;
|
|
|
|
if (includeSelf) {
|
|
|
|
groupList.append(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_FOREACH (Group* group, m_children) {
|
|
|
|
groupList.append(group->groupsRecursive(true));
|
|
|
|
}
|
|
|
|
|
|
|
|
return groupList;
|
|
|
|
}
|
|
|
|
|
2012-05-02 11:04:03 -04:00
|
|
|
void Group::addEntry(Entry* entry)
|
2010-08-12 15:38:59 -04:00
|
|
|
{
|
2010-08-18 10:22:48 -04:00
|
|
|
Q_ASSERT(entry);
|
2012-04-27 04:50:32 -04:00
|
|
|
Q_ASSERT(!m_entries.contains(entry));
|
2010-08-18 10:22:48 -04:00
|
|
|
|
|
|
|
Q_EMIT entryAboutToAdd(entry);
|
2010-08-14 06:24:35 -04:00
|
|
|
|
2010-08-12 15:38:59 -04:00
|
|
|
m_entries << entry;
|
2010-08-23 15:30:20 -04:00
|
|
|
connect(entry, SIGNAL(dataChanged(Entry*)), SIGNAL(entryDataChanged(Entry*)));
|
2012-04-18 09:16:38 -04:00
|
|
|
if (m_db) {
|
2012-06-24 11:53:01 -04:00
|
|
|
connect(entry, SIGNAL(modified()), m_db, SIGNAL(modifiedImmediate()));
|
2012-04-18 09:16:38 -04:00
|
|
|
}
|
2010-08-18 10:22:48 -04:00
|
|
|
|
2012-04-11 13:51:54 -04:00
|
|
|
Q_EMIT modified();
|
2010-08-18 10:22:48 -04:00
|
|
|
Q_EMIT entryAdded();
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Group::removeEntry(Entry* entry)
|
|
|
|
{
|
2012-04-27 04:50:32 -04:00
|
|
|
Q_ASSERT(m_entries.contains(entry));
|
|
|
|
|
2012-04-21 17:31:37 -04:00
|
|
|
Q_EMIT entryAboutToRemove(entry);
|
2010-08-18 10:22:48 -04:00
|
|
|
|
|
|
|
entry->disconnect(this);
|
2012-04-18 11:07:40 -04:00
|
|
|
if (m_db) {
|
|
|
|
entry->disconnect(m_db);
|
|
|
|
}
|
2010-08-12 15:38:59 -04:00
|
|
|
m_entries.removeAll(entry);
|
2012-04-21 17:31:37 -04:00
|
|
|
Q_EMIT modified();
|
|
|
|
Q_EMIT entryRemoved();
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2010-08-14 06:24:35 -04:00
|
|
|
|
|
|
|
void Group::recSetDatabase(Database* db)
|
|
|
|
{
|
2012-04-18 11:07:40 -04:00
|
|
|
if (m_db) {
|
|
|
|
disconnect(SIGNAL(dataChanged(Group*)), m_db);
|
|
|
|
disconnect(SIGNAL(aboutToRemove(Group*)), m_db);
|
|
|
|
disconnect(SIGNAL(removed()), m_db);
|
|
|
|
disconnect(SIGNAL(aboutToAdd(Group*,int)), m_db);
|
|
|
|
disconnect(SIGNAL(added()), m_db);
|
2012-04-23 10:57:08 -04:00
|
|
|
disconnect(SIGNAL(aboutToMove(Group*,Group*,int)), m_db);
|
|
|
|
disconnect(SIGNAL(moved()), m_db);
|
2012-04-18 11:07:40 -04:00
|
|
|
disconnect(SIGNAL(modified()), m_db);
|
|
|
|
}
|
2010-08-18 04:27:40 -04:00
|
|
|
|
2012-04-18 09:16:38 -04:00
|
|
|
Q_FOREACH (Entry* entry, m_entries) {
|
2012-04-18 11:07:40 -04:00
|
|
|
if (m_db) {
|
|
|
|
entry->disconnect(m_db);
|
|
|
|
}
|
2012-04-27 04:50:32 -04:00
|
|
|
if (db) {
|
2012-06-24 11:53:01 -04:00
|
|
|
connect(entry, SIGNAL(modified()), db, SIGNAL(modifiedImmediate()));
|
2012-04-27 04:50:32 -04:00
|
|
|
}
|
2012-04-18 09:16:38 -04:00
|
|
|
}
|
|
|
|
|
2012-04-27 04:50:32 -04:00
|
|
|
if (db) {
|
|
|
|
connect(this, SIGNAL(dataChanged(Group*)), db, SIGNAL(groupDataChanged(Group*)));
|
|
|
|
connect(this, SIGNAL(aboutToRemove(Group*)), db, SIGNAL(groupAboutToRemove(Group*)));
|
|
|
|
connect(this, SIGNAL(removed()), db, SIGNAL(groupRemoved()));
|
|
|
|
connect(this, SIGNAL(aboutToAdd(Group*,int)), db, SIGNAL(groupAboutToAdd(Group*,int)));
|
|
|
|
connect(this, SIGNAL(added()), db, SIGNAL(groupAdded()));
|
|
|
|
connect(this, SIGNAL(aboutToMove(Group*,Group*,int)), db, SIGNAL(groupAboutToMove(Group*,Group*,int)));
|
|
|
|
connect(this, SIGNAL(moved()), db, SIGNAL(groupMoved()));
|
2012-06-24 11:53:01 -04:00
|
|
|
connect(this, SIGNAL(modified()), db, SIGNAL(modifiedImmediate()));
|
2012-04-27 04:50:32 -04:00
|
|
|
}
|
2010-08-15 09:03:47 -04:00
|
|
|
|
2010-08-14 06:24:35 -04:00
|
|
|
m_db = db;
|
|
|
|
|
|
|
|
Q_FOREACH (Group* group, m_children) {
|
|
|
|
group->recSetDatabase(db);
|
|
|
|
}
|
|
|
|
}
|
2011-07-09 15:54:01 -04:00
|
|
|
|
|
|
|
void Group::cleanupParent()
|
|
|
|
{
|
|
|
|
if (m_parent) {
|
2012-04-21 17:31:37 -04:00
|
|
|
Q_EMIT aboutToRemove(this);
|
2011-07-09 15:54:01 -04:00
|
|
|
m_parent->m_children.removeAll(this);
|
2012-04-21 17:31:37 -04:00
|
|
|
Q_EMIT modified();
|
|
|
|
Q_EMIT removed();
|
2012-04-21 13:06:28 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Group::recCreateDelObjects()
|
|
|
|
{
|
|
|
|
if (m_db) {
|
|
|
|
Q_FOREACH (Entry* entry, m_entries) {
|
2012-04-21 18:29:39 -04:00
|
|
|
m_db->addDeletedObject(entry->uuid());
|
2012-04-21 13:06:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Q_FOREACH (Group* group, m_children) {
|
|
|
|
group->recCreateDelObjects();
|
|
|
|
}
|
2012-04-22 03:52:12 -04:00
|
|
|
m_db->addDeletedObject(m_uuid);
|
2012-04-21 13:06:28 -04:00
|
|
|
}
|
|
|
|
}
|
2012-05-12 07:22:41 -04:00
|
|
|
|
|
|
|
QList<Entry*> Group::search(const QString& searchTerm, Qt::CaseSensitivity caseSensitivity,
|
|
|
|
bool resolveInherit)
|
|
|
|
{
|
|
|
|
QList<Entry*> searchResult;
|
|
|
|
if (includeInSearch(resolveInherit)) {
|
|
|
|
Q_FOREACH (Entry* entry, m_entries) {
|
|
|
|
if (entry->match(searchTerm, caseSensitivity)) {
|
|
|
|
searchResult.append(entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Q_FOREACH (Group* group, m_children) {
|
|
|
|
searchResult.append(group->search(searchTerm, caseSensitivity, false));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return searchResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Group::includeInSearch(bool resolveInherit)
|
|
|
|
{
|
|
|
|
switch (m_searchingEnabled) {
|
|
|
|
case Inherit:
|
|
|
|
if (!m_parent) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (resolveInherit) {
|
|
|
|
return m_parent->includeInSearch(true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case Enable:
|
|
|
|
return true;
|
|
|
|
case Disable:
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
Q_ASSERT(false);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|