Qtopia library API Documentation

categories.h

00001 /**********************************************************************
00002 ** Copyright (C) 2000 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free
00008 ** Software Foundation and appearing in the file LICENSE.GPL included
00009 ** in the packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
00012 ** THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
00013 ** PARTICULAR PURPOSE.
00014 **
00015 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00016 **
00017 ** Contact info@trolltech.com if any conditions of this licensing are
00018 ** not clear to you.
00019 **
00020 **********************************************************************/
00021 
00022 #ifndef QTPALMTOP_CATEGORIES_H
00023 #define QTPALMTOP_CATEGORIES_H
00024 
00025 #include <qstring.h>
00026 #include <qstringlist.h>
00027 #include <qmap.h>
00028 #include <qlistview.h>
00029 #include <qarray.h>
00030 #include "qpcglobal.h"
00031 #include "palmtopuidgen.h"
00032 
00033 class CategoryGroup;
00034 
00035 #if defined(QPC_TEMPLATEDLL)
00036 // MOC_SKIP_BEGIN
00037 template class QPC_EXPORT QMap<int, QString>;
00038 template class QPC_EXPORT QMap<QString, int>;
00039 template class QPC_EXPORT QMap< QString, CategoryGroup >;
00040 // MOC_SKIP_END
00041 #endif
00042 
00043 class QPC_EXPORT CategoryGroup
00044 {
00045     friend class Categories;
00046 public:
00047     CategoryGroup(): mIdLabelMap(), mLabelIdMap() { }
00048     CategoryGroup( const CategoryGroup &c ) :
00049     mIdLabelMap( c.mIdLabelMap), mLabelIdMap( c.mLabelIdMap ) { }
00050 
00051     void clear() { mIdLabelMap.clear(); mLabelIdMap.clear(); }
00052 
00053     int add( const QString &label );
00054     bool add( int uid, const QString &label );
00055 
00056     bool remove( const QString &label );
00057     bool remove( int uid );
00058 
00059     bool rename( int uid, const QString &newLabel );
00060     bool rename( const QString &oldLabel, const QString &newLabel );
00061 
00062     bool contains(int id) const;
00063     bool contains(const QString &label) const;
00064 
00068     const QString &label(int id) const;
00070     int id(const QString &label) const;
00071 
00073     QStringList labels() const;
00074 
00075     QStringList labels( const QArray<int> &catids ) const;
00076 
00077     const QMap<int, QString> &idMap() const { return mIdLabelMap; }
00078 
00079 private:
00080     void insert( int uid, const QString &label );
00081     QMap<int, QString> mIdLabelMap;
00082     QMap<QString, int> mLabelIdMap;
00083 
00084     static Qtopia::UidGen &uidGen() { return sUidGen; }
00085     static Qtopia::UidGen sUidGen;
00086 };
00087 
00088 /* Map from application name to categories */
00089 class QPC_EXPORT Categories : public QObject
00090 {
00091     Q_OBJECT
00092 public:
00093     Categories( QObject *parent=0, const char *name = 0 )
00094     : QObject( parent, name ),  mGlobalCats(), mAppCats() { }
00095     Categories( const Categories &copyFrom ) : QObject( copyFrom.parent() ),
00096     mGlobalCats( copyFrom.mGlobalCats ),
00097     mAppCats( copyFrom.mAppCats ) { }
00098     virtual ~Categories() { }
00099 
00100     Categories &operator= ( const Categories &c )
00101 { mAppCats = c.mAppCats; mGlobalCats = c.mGlobalCats; return *this; }
00102 
00103     void clear();
00104 
00109     int addCategory( const QString &appname, const QString &catname);
00114     int addCategory( const QString &appname, const QString &catname, int uid);
00118     int addGlobalCategory( const QString &catname );
00122     int addGlobalCategory( const QString &catname, int uid );
00126     bool removeCategory( const QString &appName, const QString &catName,
00127              bool checkGlobal = TRUE);
00128     bool removeCategory( const QString &appName, int uid );
00129     bool removeGlobalCategory( const QString &catName );
00130     bool removeGlobalCategory( int uid );
00131 
00132     QArray<int> ids( const QString &app, const QStringList &labels) const;
00133 
00135     int id( const QString &app, const QString &cat ) const;
00137     QString label( const QString &app, int id ) const;
00138 
00139     enum ExtraLabels { NoExtra, AllUnfiled, AllLabel, UnfiledLabel };
00150     QStringList labels( const QString &app,
00151             bool includeGlobal = TRUE,
00152             ExtraLabels extra = NoExtra ) const;
00153 
00154     QStringList labels( const QString &app,
00155             const QArray<int> &catids ) const;
00156 
00157     enum DisplaySingle { ShowMulti, ShowAll, ShowFirst };
00158 
00168     QString displaySingle( const QString &app,
00169                const QArray<int> &catids,
00170                DisplaySingle display ) const;
00171 
00172     QStringList globalCategories() const { return mGlobalCats.labels();}
00173 
00174     bool renameCategory( const QString &appname,
00175              const QString &oldName,
00176              const QString &newName );
00177     bool renameGlobalCategory( const QString &oldName,
00178                    const QString &newName );
00179 
00180     void setGlobal( const QString &appname, const QString &catname,
00181             bool value );
00182     bool isGlobal( const QString &catname ) const;
00183 
00184 
00187     bool exists( const QString &catname ) const;
00188     bool exists( const QString &appname, const QString &catname) const;
00189 
00190     bool save( const QString &fname ) const;
00191     bool load( const QString &fname );
00192 
00193     // for debugging
00194     void dump() const;
00195 
00196     const QMap<QString, CategoryGroup> &appGroupMap() const{ return mAppCats; }
00197     const CategoryGroup &globalGroup() const { return mGlobalCats; }
00198 
00199 signals:
00205     void categoryAdded( const Categories &, const QString &, int );
00211     void categoryRemoved( const Categories &, const QString &, int );
00214     void categoryRenamed( const Categories &, const QString &, int );
00215 
00216 private:
00217     CategoryGroup mGlobalCats;
00218     QMap< QString, CategoryGroup > mAppCats;
00219 };
00220 
00221 class QPC_EXPORT CheckedListView : public QListView
00222 {
00223 public:
00224     void addCheckableList( const QStringList &options );
00225     void setChecked( const QStringList &checked );
00226     QStringList checked() const;
00227 };
00228 
00229 #endif
KDE Logo
This file is part of the documentation for OPIE Version 1.5.5.
Documentation copyright © 1997-2003 the KDE developers. 2003 OPIE developers
Generated on Tue Feb 10 20:24:03 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001