summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/backend/categories.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/library/backend/categories.cpp b/library/backend/categories.cpp
index e37b3b9..2e84089 100644
--- a/library/backend/categories.cpp
+++ b/library/backend/categories.cpp
@@ -1,404 +1,404 @@
/**********************************************************************
** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
** This file is part of the Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
-#include <qtopia/categories.h>
+#include <qtopia/private/categories.h>
#include <qtopia/stringutil.h>
#include <qfile.h>
#include <qcstring.h>
#include <qtextstream.h>
using namespace Qtopia;
/***********************************************************
*
* CategoryGroup
*
**********************************************************/
#ifdef PALMTOPCENTER
UidGen CategoryGroup::sUidGen( UidGen::PalmtopCenter );
#else
UidGen CategoryGroup::sUidGen( UidGen::Qtopia );
#endif
/*! \class CategoryGroup categories.h
\brief Helper class that is used by Categories
CategoryGroup is a group of categories that is associated with an
application or global set. Mainly it defines a map of ids to
category labels and category labels to ids. Lookups can be done with
labels or unique idenifiers.
\ingroup qtopiaemb
\ingroup qtopiadesktop
\warning Categories API will likely change between Qtopia 1.5 and Qtopia 3
\sa Categories::appGroupMap(), Categories::globalGroup()
*/
/*! Add \a label and return the UID. If failure, then 0 is returned. Note
that All and Unfiled are reserved labels.
\internal
*/
int CategoryGroup::add( const QString &label )
{
if ( label == QObject::tr("All") || label == QObject::tr("Unfiled") )
return 0;
QMap<QString,int>::Iterator findIt = mLabelIdMap.find( label );
if ( findIt != mLabelIdMap.end() )
return 0;
int newUid = uidGen().generate();
insert( newUid, label );
return newUid;
}
void CategoryGroup::insert( int uid, const QString &label )
{
uidGen().store( uid );
mIdLabelMap[uid] = label;
mLabelIdMap[label] = uid;
}
/*! \internal
*/
bool CategoryGroup::add( int uid, const QString &label )
{
if ( label == QObject::tr("All") || label == QObject::tr("Unfiled") )
return FALSE;
QMap<QString,int>::ConstIterator labelIt = mLabelIdMap.find( label );
if ( labelIt != mLabelIdMap.end() )
return FALSE;
QMap<int,QString>::ConstIterator idIt = mIdLabelMap.find( uid );
if ( idIt != mIdLabelMap.end() )
return FALSE;
insert( uid, label );
return TRUE;
}
/*! Returns TRUE if \a label was removed from the group, FALSE if not.
\internal
*/
bool CategoryGroup::remove( const QString &label )
{
QMap<QString,int>::Iterator findIt = mLabelIdMap.find( label );
if ( findIt == mLabelIdMap.end() )
return FALSE;
mIdLabelMap.remove( *findIt );
mLabelIdMap.remove( findIt );
return TRUE;
}
/*! Returns TRUE if \a uid was removed from the group, FALSE if not.
\internal
*/
bool CategoryGroup::remove( int uid )
{
QMap<int,QString>::Iterator idIt = mIdLabelMap.find( uid );
if ( idIt == mIdLabelMap.end() )
return FALSE;
mLabelIdMap.remove( *idIt );
mIdLabelMap.remove( idIt );
return TRUE;
}
/*! \internal
*/
bool CategoryGroup::rename( int uid, const QString &newLabel )
{
if ( newLabel == QObject::tr("All") || newLabel == QObject::tr("Unfiled") )
return FALSE;
QMap<int, QString>::Iterator idIt = mIdLabelMap.find( uid );
if ( idIt == mIdLabelMap.end() )
return FALSE;
mLabelIdMap.remove( *idIt );
mLabelIdMap[newLabel] = uid;
*idIt = newLabel;
return TRUE;
}
/*! \internal
*/
bool CategoryGroup::rename( const QString &oldLabel, const QString &newLabel )
{
return rename( id(oldLabel), newLabel );
}
/*! Returns TRUE if \a uid is stored in this group, FALSE if not. */
bool CategoryGroup::contains(int uid) const
{
return ( mIdLabelMap.find( uid ) != mIdLabelMap.end() );
}
/*! Returns TRUE if \a label is stored in this group, FALSE if not. */
bool CategoryGroup::contains(const QString &label) const
{
return ( mLabelIdMap.find( label ) != mLabelIdMap.end() );
}
/*! Returns label associated with the \a uid or QString::null if
not found
*/
const QString &CategoryGroup::label(int uid) const
{
QMap<int,QString>::ConstIterator idIt = mIdLabelMap.find( uid );
if ( idIt == mIdLabelMap.end() )
return QString::null;
return *idIt;
}
/*! Returns the uid associated with \a label or 0 if not found */
int CategoryGroup::id(const QString &label) const
{
QMap<QString,int>::ConstIterator labelIt = mLabelIdMap.find( label );
if ( labelIt == mLabelIdMap.end() )
return 0;
return *labelIt;
}
/*! Returns a list of all labels stored in this group. */
QStringList CategoryGroup::labels() const
{
QStringList labels;
for ( QMap<int, QString>::ConstIterator it = mIdLabelMap.begin();
it != mIdLabelMap.end(); ++it )
labels += *it;
// ### I don't think this is the place for this...
// labels.sort();
return labels;
}
/*! Returns a list of all labels associated with the \a catids */
QStringList CategoryGroup::labels(const QArray<int> &catids ) const
{
QStringList labels;
if ( catids.count() == 0 )
return labels;
for ( QMap<int, QString>::ConstIterator it = mIdLabelMap.begin();
it != mIdLabelMap.end(); ++it )
if ( catids.find( it.key() ) != -1 )
labels += *it;
return labels;
}
/***********************************************************
*
* Categories
*
**********************************************************/
/*!
\class Categories categories.h
\brief The Categories class is a database that groups categories and maps ids to names.
The Categories class is the low level Categories accessor class. To
add a category menu and filter for your application, see CategoryMenu.
The Categories class allows the developer to add, remove, and rename
categories. Categories can be created for an individual application
such as Todo List or to be used for all applications. Categories
that can be used by all applications are called global
categories. Each PalmtopRecord subclass stores categories as an
QArray<int> using PalmtopRecord::setCategories() and
PalmtopRecord::categories(). This allows each record to be assigned
to multiple categories. This also allows the user to rename a
category and for it to update automatically in all records.
This class provides several methods to convert between a category id
and it's associated string such as id(), ids(), label() and labels(). A
helper class called CategoryGroup is used to access categories of a
single application group, such as Todo List. Global categories can
also be accessed via CategoryGroup objects. See appGroupMap() and
globalGroup() for the appropriate accessor methods.
Categories are stored in an xml file in the Settings directory
(Categories.xml). A global function called categoryFileName() will
return to appropriate QString file location to be passed to load()
and save() for the master categories database.
\ingroup qtopiaemb
\ingroup qtopiadesktop
\warning Categories API will likely change between Qtopia 1.5 and Qtopia 3
\sa CategoryGroup, CategoryMenu
*/
/*!
Add the category name as long as it doesn't already exist locally or
globally. The \a uid is assigned to the category if successfully
added. Return \a uid if added, 0 if conflicts (error).
\internal
*/
int Categories::addCategory( const QString &appname,
const QString &catname,
int uid )
{
if ( mGlobalCats.contains(catname) )
return 0;
QMap< QString, CategoryGroup >::Iterator
appIt = mAppCats.find( appname );
if ( appIt == mAppCats.end() ) {
CategoryGroup newgroup;
newgroup.add( uid, catname );
mAppCats.insert( appname, newgroup );
emit categoryAdded( *this, appname, uid );
return uid;
}
CategoryGroup &cats = *appIt;
cats.add( uid, catname );
emit categoryAdded( *this, appname, uid );
return uid;
}
/*!
Add the category name as long as it doesn't already exist locally or
globally. Return UID if added, 0 if conflicts (error).
*/
int Categories::addCategory( const QString &appname,
const QString &catname )
{
if ( mGlobalCats.contains(catname) )
return 0;
QMap< QString, CategoryGroup >::Iterator
appIt = mAppCats.find( appname );
if ( appIt == mAppCats.end() ) {
CategoryGroup newgroup;
int uid = newgroup.add( catname );
mAppCats.insert( appname, newgroup );
emit categoryAdded( *this, appname, uid );
return uid;
}
CategoryGroup &cats = *appIt;
int uid = cats.add( catname );
if ( !uid )
return 0;
emit categoryAdded( *this, appname, uid );
return uid;
}
/*!
\internal
*/
int Categories::addGlobalCategory( const QString &catname, int uid )
{
mGlobalCats.add( uid, catname );
emit categoryAdded( *this, QString::null, uid );
return uid;
}
/*!
Add the global category \a catname while checking that it doesn't
already exist globally. Return UID if added, 0 if conflicts.
\sa addCategory()
*/
int Categories::addGlobalCategory( const QString &catname )
{
int uid = mGlobalCats.add( catname );
if ( !uid )
return 0;
emit categoryAdded( *this, QString::null, uid );
return uid;
}
/*!
Removes the \a catname from the application group. If it is not
found in the application group and \a checkGlobal is TRUE, then it
attempts to remove it from the global list
*/
bool Categories::removeCategory( const QString &appname,
const QString &catname,
bool checkGlobal )
{
QMap< QString, CategoryGroup >::Iterator
appIt = mAppCats.find( appname );
if ( appIt != mAppCats.end() ) {
CategoryGroup &cats = *appIt;
int uid = cats.id( catname );
if ( cats.remove( uid ) ) {
emit categoryRemoved( *this, appname, uid );
return TRUE;
}
}
if ( !checkGlobal )
return FALSE;
return removeGlobalCategory( catname );
}
/*!
Removes the \a uid from the application group \a appname. Returns TRUE
if success, FALSE if not found.
*/
bool Categories::removeCategory( const QString &appname, int uid )
{
QMap< QString, CategoryGroup >::Iterator
appIt = mAppCats.find( appname );
if ( appIt != mAppCats.end() ) {
CategoryGroup &cats = *appIt;
if ( cats.remove( uid ) ) {
emit categoryRemoved( *this, appname, uid );
return TRUE;
}
}
return FALSE;
}
/*!
Removes the global category \a catname. Returns TRUE
if success, FALSE if not found.
*/
bool Categories::removeGlobalCategory( const QString &catname )
{
int uid = mGlobalCats.id( catname );
if ( mGlobalCats.remove( uid ) ) {
emit categoryRemoved( *this, QString::null, uid );
return TRUE;
}
return FALSE;
}
/*!
Removes the global category \a uid. Returns TRUE
if success, FALSE if not found.
*/
bool Categories::removeGlobalCategory( int uid )
{
if ( mGlobalCats.remove( uid ) ) {
emit categoryRemoved( *this, QString::null, uid );
return TRUE;
}
return FALSE;
}