kpilot Library API Documentation

pilotComponent.cc

00001 /* pilotComponent.cc                    KPilot
00002 **
00003 ** Copyright (C) 1998-2001 by Dan Pilone
00004 **
00005 ** This file defines a base class for components -- internal conduits --
00006 ** in KPilot. This includes a number of general utility functions.
00007 */
00008 
00009 /*
00010 ** This program is free software; you can redistribute it and/or modify
00011 ** it under the terms of the GNU General Public License as published by
00012 ** the Free Software Foundation; either version 2 of the License, or
00013 ** (at your option) any later version.
00014 **
00015 ** This program is distributed in the hope that it will be useful,
00016 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00018 ** GNU General Public License for more details.
00019 **
00020 ** You should have received a copy of the GNU General Public License
00021 ** along with this program in a file called COPYING; if not, write to
00022 ** the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
00023 ** MA 02111-1307, USA.
00024 */
00025 
00026 /*
00027 ** Bug reports and questions can be sent to kde-pim@kde.org
00028 */
00029 
00030 
00031 #include "options.h"
00032 
00033 #include <time.h>
00034 
00035 #ifndef _PILOT_APPINFO_H_
00036 #include <pi-appinfo.h>
00037 #endif
00038 
00039 #ifndef QWIDGET_H
00040 #include <qwidget.h>
00041 #endif
00042 
00043 #ifndef QCOMBOBOX_H
00044 #include <qcombobox.h>
00045 #endif
00046 
00047 #ifndef _KDEBUG_H
00048 #include <kdebug.h>
00049 #endif
00050 
00051 #include "pilotComponent.moc"
00052 
00053 static const char *pilotComponent_id =
00054         "$Id: pilotComponent.cc,v 1.23.6.4 2003/03/12 23:31:14 adridg Exp $";
00055 
00056 // This is a pilot constant and should probably be defined
00057 // in a more sensible place but I'm lazy right now.
00058 //
00059 #define MAX_CATEGORIES  (15)
00060 
00061 PilotComponent::PilotComponent(QWidget * parent,
00062         const char *id,
00063         const QString & path) :
00064         QWidget(parent, id), 
00065         fDBPath(path)
00066 {
00067         FUNCTIONSETUP;
00068 
00069         if (parent)
00070         {
00071                 resize(parent->geometry().width(),
00072                         parent->geometry().height());
00073         }
00074 
00075         (void) pilotComponent_id;
00076 }
00077 
00078 
00079 
00080 int PilotComponent::findSelectedCategory(QComboBox * fCatList,
00081         struct CategoryAppInfo *info, bool AllIsUnfiled)
00082 {
00083         FUNCTIONSETUP;
00084 
00085         // Semantics of currentCatID are: 
00086         //
00087         // >=0          is a specific category based on the text -> 
00088         //              category number mapping defined by the Pilot, 
00089         // ==-1         means "All" category selected when 
00090         //              AllIsUnfiled is true.
00091         // == 0         == Unfiled means "All" category selected when 
00092         //              AllIsUnfiled is false.
00093         //
00094         //
00095         int currentCatID = 0;
00096 
00097         // If a category is deleted after others have been added, none of the
00098         // category numbers are changed.  So we need to find the category number
00099         // for this category (this category is represented by the selected
00100         // *text*).
00101         //
00102         //
00103         // The top entry in the list is "All", so if the top item is
00104         // selected we can indicate that we are using the "All" category.
00105         //
00106         //
00107         if (fCatList->currentItem() == 0)
00108         {
00109                 currentCatID = (-1);
00110 #ifdef DEBUG
00111                 DEBUGKPILOT << fname << ": Category 'All' selected.\n";
00112 #endif
00113         }
00114         else
00115         {
00116                 QString selectedCategory =
00117                         fCatList->text(fCatList->currentItem());
00118 
00119 #ifdef DEBUG
00120                 DEBUGKPILOT << fname
00121                         << ": List item "
00122                         << fCatList->currentItem()
00123                         << " (of "
00124                         << fCatList->count()
00125                         << ") "
00126                         << " selected, text=" << selectedCategory << endl;
00127 #endif
00128 
00129                 currentCatID = 0;
00130                 while (strcmp(info->name[currentCatID],
00131                                 selectedCategory.latin1()) &&
00132                         (currentCatID < MAX_CATEGORIES))
00133                 {
00134 #ifdef DEBUG
00135                         DEBUGKPILOT << fname
00136                                 << ": Didn't match category "
00137                                 << currentCatID
00138                                 << "=" << info->name[currentCatID] << endl;
00139 #endif
00140 
00141                         currentCatID++;
00142                 }
00143 
00144                 if (!(currentCatID < MAX_CATEGORIES))
00145                 {
00146                         currentCatID = 0;
00147                         while (strcmp(info->name[currentCatID],
00148                                         selectedCategory.latin1()) &&
00149                                 (currentCatID < MAX_CATEGORIES))
00150                         {
00151                                 currentCatID++;
00152                         }
00153                 }
00154 
00155                 if (!(currentCatID < MAX_CATEGORIES))
00156                 {
00157                         currentCatID = 0;
00158                         while (strcmp(info->name[currentCatID],
00159                                         selectedCategory.ascii()) &&
00160                                 (currentCatID < MAX_CATEGORIES))
00161                         {
00162                                 currentCatID++;
00163                         }
00164                 }
00165 
00166                 if (!(currentCatID < MAX_CATEGORIES))
00167                 {
00168                         currentCatID = 0;
00169                         while ((info->name[currentCatID][0]) &&
00170                                 (currentCatID < MAX_CATEGORIES))
00171                         {
00172                                 if (selectedCategory ==
00173                                         QString::fromLatin1(info->
00174                                                 name[currentCatID]))
00175                                 {
00176 #ifdef DEBUG
00177                                         DEBUGKPILOT << fname
00178                                                 << ": Matched "
00179                                                 << currentCatID << endl;
00180 #endif
00181 
00182                                         break;
00183                                 }
00184                                 currentCatID++;
00185                         }
00186                 }
00187 
00188                 if (currentCatID < MAX_CATEGORIES)
00189                 {
00190 #ifdef DEBUG
00191                         DEBUGKPILOT << fname
00192                                 << ": Matched category "
00193                                 << currentCatID
00194                                 << "=" << info->name[currentCatID] << endl;
00195 #endif
00196                 }
00197                 else
00198                 {
00199 #ifdef DEBUG                    // necessary for Tru64 unix
00200                         kdWarning() << k_funcinfo
00201                                 << ": Selected category didn't match "
00202                                 "any name!\n";
00203                         kdWarning() << k_funcinfo
00204                                 << ": Number of listed categories "
00205                                 << fCatList->count() << endl;
00206                         kdWarning() << k_funcinfo
00207                                 << ": Selected category ("
00208                                 << selectedCategory
00209                                 << ") expands to "
00210                                 << qstringExpansion(selectedCategory) << endl;
00211                         kdWarning() << k_funcinfo
00212                                 << ": Categories expand to " << endl;
00213 #endif
00214                         currentCatID = 0;
00215                         while ((info->name[currentCatID][0]) &&
00216                                 (currentCatID < MAX_CATEGORIES))
00217                         {
00218 #ifdef DEBUG
00219                                 kdWarning() << k_funcinfo
00220                                         << ": Category ["
00221                                         << currentCatID
00222                                         << "] = "
00223                                         << charExpansion(info->
00224                                         name[currentCatID]) << endl;
00225 #endif
00226                                 currentCatID++;
00227                         }
00228 
00229                         currentCatID = (-1);
00230                 }
00231         }
00232 
00233         if ((currentCatID == -1) && AllIsUnfiled)
00234                 currentCatID = 0;
00235         return currentCatID;
00236 }
00237 
00238 
00239 void PilotComponent::populateCategories(QComboBox * c,
00240         struct CategoryAppInfo *info)
00241 {
00242         FUNCTIONSETUP;
00243 
00244 #ifdef DEBUG
00245         DEBUGKPILOT << fname
00246                 << ": Combo box @"
00247                 << (int) c << " and info @" << (int) info << endl;
00248 #endif
00249 
00250         c->clear();
00251 
00252         if (!info)
00253                 goto CategoryAll;
00254 
00255         // Fill up the categories list box with
00256         // the categories defined by the user. 
00257         // These presumably are in the language 
00258         // the user uses, so no translation is necessary.
00259         //
00260         //
00261         for (int i = 0; i < 15; i++)
00262         {
00263                 if (info->name[i][0])
00264                 {
00265 #ifdef DEBUG
00266                         DEBUGKPILOT << fname
00267                                 << ": Adding category: "
00268                                 << info->name[i]
00269                                 << " with ID: " << (int) info->ID[i] << endl;
00270 #endif
00271 
00272                         c->insertItem(QString::fromLatin1(info->name[i]));
00273                 }
00274         }
00275 
00276 CategoryAll:
00277         c->insertItem(i18n("All"), 0);
00278 }
00279 
00280 
00281 void PilotComponent::slotShowComponent()
00282 {
00283         FUNCTIONSETUP;
00284 
00285 #ifdef DEBUG
00286         DEBUGKPILOT << fname << ": Showing component @" << (int) this << endl;
00287 #endif
00288 
00289         emit showComponent(this);
00290 }
00291 
00292 /* virtual */ bool PilotComponent::preHotSync(QString &)
00293 {
00294         FUNCTIONSETUP;
00295 
00296         return true;
00297 }
00298 
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sat Oct 18 02:47:14 2003 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001