2010-08-07 09:10:44 -04:00
|
|
|
/*
|
|
|
|
<one line to give the program's name and a brief idea of what it does.>
|
|
|
|
Copyright (C) <year> <name of author>
|
|
|
|
|
|
|
|
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 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
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, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Group.h"
|
|
|
|
|
2010-08-12 15:38:59 -04:00
|
|
|
#include "Database.h"
|
2010-09-19 15:22:24 -04:00
|
|
|
#include "DatabaseIcons.h"
|
|
|
|
#include "Metadata.h"
|
2010-08-12 15:38:59 -04:00
|
|
|
|
2010-08-13 12:08:06 -04:00
|
|
|
Group::Group()
|
2010-08-12 15:38:59 -04:00
|
|
|
{
|
2010-08-13 12:08:06 -04:00
|
|
|
m_parent = 0;
|
|
|
|
m_db = 0;
|
2011-06-29 10:47:05 -04:00
|
|
|
|
|
|
|
m_iconNumber = 0; // TODO change?
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
2010-08-18 10:22:48 -04:00
|
|
|
Group::~Group()
|
|
|
|
{
|
|
|
|
// TODO notify parent
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-09-19 15:22:24 -04:00
|
|
|
QIcon Group::icon() const
|
2010-08-12 15:38:59 -04:00
|
|
|
{
|
2010-09-19 15:22:24 -04:00
|
|
|
if (m_customIcon.isNull()) {
|
|
|
|
return DatabaseIcons::icon(m_iconNumber);
|
2010-08-24 17:12:01 -04:00
|
|
|
}
|
|
|
|
else {
|
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
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-08-19 08:03:54 -04:00
|
|
|
int Group::autoTypeEnabled() const
|
|
|
|
{
|
|
|
|
return m_autoTypeEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Group::searchingEnabed() const
|
|
|
|
{
|
|
|
|
return m_searchingEnabled;
|
|
|
|
}
|
|
|
|
|
2010-08-12 15:38:59 -04:00
|
|
|
Entry* Group::lastTopVisibleEntry() const
|
|
|
|
{
|
|
|
|
return m_lastTopVisibleEntry;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Group::setUuid(const Uuid& uuid)
|
|
|
|
{
|
|
|
|
m_uuid = uuid;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Group::setName(const QString& name)
|
|
|
|
{
|
|
|
|
m_name = name;
|
2010-08-15 09:03:47 -04:00
|
|
|
|
2010-08-18 04:27:40 -04:00
|
|
|
Q_EMIT dataChanged(this);
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Group::setNotes(const QString& notes)
|
|
|
|
{
|
|
|
|
m_notes = notes;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Group::setIcon(int iconNumber)
|
|
|
|
{
|
2010-08-14 06:24:35 -04:00
|
|
|
Q_ASSERT(iconNumber >= 0);
|
|
|
|
|
2010-08-12 15:38:59 -04:00
|
|
|
m_iconNumber = iconNumber;
|
|
|
|
m_customIcon = Uuid();
|
2010-08-15 09:03:47 -04:00
|
|
|
|
2010-08-18 04:27:40 -04:00
|
|
|
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());
|
|
|
|
|
2010-08-12 15:38:59 -04:00
|
|
|
m_iconNumber = 0;
|
|
|
|
m_customIcon = uuid;
|
2010-08-15 09:03:47 -04:00
|
|
|
|
2010-08-18 04:27:40 -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)
|
|
|
|
{
|
|
|
|
m_isExpanded = expanded;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Group::setDefaultAutoTypeSequence(const QString& sequence)
|
|
|
|
{
|
|
|
|
m_defaultAutoTypeSequence = sequence;
|
|
|
|
}
|
|
|
|
|
2010-08-19 08:03:54 -04:00
|
|
|
void Group::setAutoTypeEnabled(int enable)
|
|
|
|
{
|
|
|
|
Q_ASSERT(enable >= -1 && enable <= 1);
|
|
|
|
|
|
|
|
m_autoTypeEnabled = enable;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Group::setSearchingEnabled(int enable)
|
|
|
|
{
|
|
|
|
Q_ASSERT(enable >= -1 && enable <= 1);
|
|
|
|
|
|
|
|
m_searchingEnabled = enable;
|
|
|
|
}
|
|
|
|
|
2010-08-12 15:38:59 -04:00
|
|
|
void Group::setLastTopVisibleEntry(Entry* entry)
|
|
|
|
{
|
|
|
|
m_lastTopVisibleEntry = entry;
|
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
if (index == -1) {
|
|
|
|
index = parent->children().size();
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_EMIT aboutToRemove(this);
|
2010-08-13 12:08:06 -04:00
|
|
|
|
2010-08-12 15:38:59 -04:00
|
|
|
if (m_parent) {
|
|
|
|
m_parent->m_children.removeAll(this);
|
|
|
|
}
|
2010-08-13 12:08:06 -04:00
|
|
|
else if (m_db) {
|
2010-08-15 09:03:47 -04:00
|
|
|
// parent was a Database
|
2010-08-13 12:08:06 -04:00
|
|
|
m_db->setRootGroup(0);
|
|
|
|
}
|
2010-08-12 15:38:59 -04:00
|
|
|
|
2010-08-18 04:27:40 -04:00
|
|
|
Q_EMIT removed();
|
|
|
|
|
2010-08-13 12:08:06 -04:00
|
|
|
m_parent = parent;
|
2010-08-14 06:24:35 -04:00
|
|
|
|
|
|
|
if (m_db != parent->m_db) {
|
|
|
|
recSetDatabase(parent->m_db);
|
|
|
|
}
|
|
|
|
|
2010-08-12 15:38:59 -04:00
|
|
|
QObject::setParent(parent);
|
2010-08-13 12:08:06 -04:00
|
|
|
|
2010-08-18 04:27:40 -04:00
|
|
|
Q_EMIT aboutToAdd(this, index);
|
|
|
|
|
|
|
|
parent->m_children.insert(index, this);
|
|
|
|
|
|
|
|
Q_EMIT added();
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Group::setParent(Database* db)
|
|
|
|
{
|
2010-08-18 04:27:40 -04:00
|
|
|
Q_ASSERT(db);
|
|
|
|
|
|
|
|
Q_EMIT aboutToRemove(this);
|
2010-08-13 12:08:06 -04:00
|
|
|
|
|
|
|
if (m_parent) {
|
|
|
|
m_parent->m_children.removeAll(this);
|
|
|
|
}
|
|
|
|
else if (m_db) {
|
2010-08-12 15:38:59 -04:00
|
|
|
m_db->setRootGroup(0);
|
|
|
|
}
|
|
|
|
|
2010-08-18 04:27:40 -04:00
|
|
|
Q_EMIT removed();
|
|
|
|
|
2010-08-12 15:38:59 -04:00
|
|
|
m_parent = 0;
|
2010-08-14 06:24:35 -04:00
|
|
|
recSetDatabase(db);
|
|
|
|
|
2010-08-12 15:38:59 -04:00
|
|
|
QObject::setParent(db);
|
2010-08-13 12:08:06 -04:00
|
|
|
|
|
|
|
db->setRootGroup(this);
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-08-12 15:38:59 -04:00
|
|
|
void Group::addEntry(Entry *entry)
|
|
|
|
{
|
2010-08-18 10:22:48 -04:00
|
|
|
Q_ASSERT(entry);
|
|
|
|
|
|
|
|
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*)));
|
2010-08-18 10:22:48 -04:00
|
|
|
|
|
|
|
Q_EMIT entryAdded();
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Group::removeEntry(Entry* entry)
|
|
|
|
{
|
2010-08-18 10:22:48 -04:00
|
|
|
Q_EMIT entryAboutToRemove(entry);
|
|
|
|
|
|
|
|
entry->disconnect(this);
|
2010-08-12 15:38:59 -04:00
|
|
|
m_entries.removeAll(entry);
|
2010-08-18 10:22:48 -04:00
|
|
|
|
|
|
|
Q_EMIT entryRemoved();
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2010-08-14 06:24:35 -04:00
|
|
|
|
|
|
|
void Group::recSetDatabase(Database* db)
|
|
|
|
{
|
2010-08-23 15:30:20 -04:00
|
|
|
disconnect(SIGNAL(dataChanged(Group*)), m_db);
|
|
|
|
disconnect(SIGNAL(aboutToRemove(Group*)), m_db);
|
2010-08-18 04:27:40 -04:00
|
|
|
disconnect(SIGNAL(removed()), m_db);
|
2010-08-23 15:30:20 -04:00
|
|
|
disconnect(SIGNAL(aboutToAdd(Group*,int)), m_db);
|
2010-08-18 04:27:40 -04:00
|
|
|
disconnect(SIGNAL(added()), m_db);
|
|
|
|
|
2010-08-23 15:30:20 -04:00
|
|
|
connect(this, SIGNAL(dataChanged(Group*)), db, SIGNAL(groupDataChanged(Group*)));
|
|
|
|
connect(this, SIGNAL(aboutToRemove(Group*)), db, SIGNAL(groupAboutToRemove(Group*)));
|
2010-08-18 04:27:40 -04:00
|
|
|
connect(this, SIGNAL(removed()), db, SIGNAL(groupRemoved()));
|
2010-08-23 15:30:20 -04:00
|
|
|
connect(this, SIGNAL(aboutToAdd(Group*,int)), db, SIGNAL(groupAboutToAdd(Group*,int)));
|
2010-08-18 04:27:40 -04:00
|
|
|
connect(this, SIGNAL(added()), db, SIGNAL(groupAdded()));
|
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);
|
|
|
|
}
|
|
|
|
}
|