Qtopia library API Documentation

categorymenu.cpp

00001 /**********************************************************************
00002 ** Copyright (C) 2001 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 Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 
00021 #include "categorymenu.h"
00022 #include "backend/categories.h"
00023 #include "categoryselect.h"
00024 #include <qstring.h>
00025 #include <qmap.h>
00026 
00056 CategoryMenu::CategoryMenu( const QString &n, bool ig = TRUE,
00057     QWidget *parent, const char *name ) :
00058     QPopupMenu(parent, name),
00059     appName(n),
00060     includeGlobal(ig)
00061 {
00062     currentMid = 1;
00063     reload();
00064     connect(this, SIGNAL(activated(int)), this, SLOT(mapMenuId(int)));
00065 }
00066 
00070 CategoryMenu::~CategoryMenu( )
00071 {
00072 }
00073 
00077 void CategoryMenu::reload()
00078 {
00079     clear();
00080     Categories c;
00081 
00082     c.load(categoryFileName());
00083 
00084     QStringList sl = c.labels(appName, includeGlobal);
00085     int mid = 1;
00086 
00087     insertItem(tr("All"), mid);
00088     mid++;
00089     insertItem(tr("Unfiled"), mid);
00090     mid++;
00091 
00092     for (QStringList::Iterator it = sl.begin();
00093         it != sl.end(); ++it ) {
00094     int cid = c.id(appName, *it);
00095     insertItem(*it, mid);
00096     menuToId.insert(mid, cid);
00097     idToMenu.insert(cid, mid);
00098     mid++;
00099     }
00100 
00101     setItemChecked(currentMid, TRUE );
00102 }
00103 
00107 void CategoryMenu::mapMenuId(int id)
00108 {
00109     if (id == currentMid)
00110     return;
00111     setItemChecked( currentMid, FALSE );
00112     setItemChecked( id, TRUE );
00113     currentMid = id;
00114 
00115     emit categoryChange();
00116 }
00117 
00123 bool CategoryMenu::isSelected(const QArray<int> &cUids) const
00124 {
00125     if (currentMid == 1)
00126     return TRUE;
00127 
00128     if (currentMid == 2 && cUids.count() == 0)
00129     return TRUE;
00130 
00131     if (cUids.contains(menuToId[currentMid]))
00132     return TRUE;
00133 
00134     return FALSE;
00135 }
00136 
00140 void CategoryMenu::setCurrentCategory( int newCatUid )
00141 {
00142     if (!idToMenu.contains(newCatUid))
00143     return;
00144 
00145     mapMenuId(idToMenu[newCatUid]);
00146 }
00147 
00151 void CategoryMenu::setCurrentCategoryAll( )
00152 {
00153     mapMenuId(1);
00154 }
00155 
00159 void CategoryMenu::setCurrentCategoryUnfiled( )
00160 {
00161     mapMenuId(2);
00162 }
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