kpilot/kpilot

pilotComponent.cc

00001 /* KPilot
00002 **
00003 ** Copyright (C) 1998-2001 by Dan Pilone
00004 ** Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00005 **
00006 ** This file defines a base class for components -- internal conduits --
00007 ** in KPilot. This includes a number of general utility functions.
00008 */
00009 
00010 /*
00011 ** This program is free software; you can redistribute it and/or modify
00012 ** it under the terms of the GNU General Public License as published by
00013 ** the Free Software Foundation; either version 2 of the License, or
00014 ** (at your option) any later version.
00015 **
00016 ** This program is distributed in the hope that it will be useful,
00017 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019 ** GNU General Public License for more details.
00020 **
00021 ** You should have received a copy of the GNU General Public License
00022 ** along with this program in a file called COPYING; if not, write to
00023 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00024 ** MA 02110-1301, USA.
00025 */
00026 
00027 /*
00028 ** Bug reports and questions can be sent to kde-pim@kde.org
00029 */
00030 
00031 
00032 #include "options.h"
00033 
00034 #include <time.h>
00035 
00036 #include <pi-appinfo.h>
00037 
00038 #include <qwidget.h>
00039 #include <qcombobox.h>
00040 #include <qtextcodec.h>
00041 
00042 #include <kdebug.h>
00043 
00044 #include "kpilotConfig.h"
00045 #include "pilotAppCategory.h"
00046 #include "pilotDatabase.h"
00047 
00048 #include "pilotComponent.moc"
00049 
00050 static const char *pilotComponent_id =
00051     "$Id: pilotComponent.cc 437980 2005-07-23 19:53:57Z kainhofe $";
00052 
00053 PilotComponent::PilotComponent(QWidget * parent,
00054     const char *id,
00055     const QString & path) :
00056     QWidget(parent, id),
00057     fDBPath(path),
00058     shown(false)
00059 {
00060     FUNCTIONSETUP;
00061 
00062     if (parent)
00063     {
00064         resize(parent->geometry().width(),
00065             parent->geometry().height());
00066     }
00067 
00068     (void) pilotComponent_id;
00069 }
00070 
00071 
00072 
00073 int PilotComponent::findSelectedCategory(QComboBox * fCatList,
00074     struct CategoryAppInfo *info, bool AllIsUnfiled)
00075 {
00076     FUNCTIONSETUP;
00077 
00078     // Semantics of currentCatID are:
00079     //
00080     // >=0          is a specific category based on the text ->
00081     //              category number mapping defined by the Pilot,
00082     // ==-1         means "All" category selected when
00083     //              AllIsUnfiled is true.
00084     // == 0         == Unfiled means "All" category selected when
00085     //              AllIsUnfiled is false.
00086     //
00087     //
00088     int currentCatID = 0;
00089 
00090     // If a category is deleted after others have been added, none of the
00091     // category numbers are changed.  So we need to find the category number
00092     // for this category (this category is represented by the selected
00093     // *text*).
00094     //
00095     //
00096     // The top entry in the list is "All", so if the top item is
00097     // selected we can indicate that we are using the "All" category.
00098     //
00099     //
00100     if (fCatList->currentItem() == 0)
00101     {
00102         currentCatID = (-1);
00103 #ifdef DEBUG
00104         DEBUGKPILOT << fname << ": Category 'All' selected.\n";
00105 #endif
00106     }
00107     else
00108     {
00109         QString selectedCategory =
00110             fCatList->text(fCatList->currentItem());
00111         currentCatID = PilotAppInfoBase::findCategory(selectedCategory, AllIsUnfiled, info);
00112     }
00113 
00114     if ((currentCatID == -1) && AllIsUnfiled)
00115         currentCatID = 0;
00116     return currentCatID;
00117 }
00118 
00119 
00120 void PilotComponent::populateCategories(QComboBox * c,
00121     struct CategoryAppInfo *info)
00122 {
00123     FUNCTIONSETUP;
00124 
00125 #ifdef DEBUG
00126     DEBUGKPILOT << fname
00127         << ": Combo box @"
00128         << (long) c << " and info @" << (long) info << endl;
00129 #endif
00130 
00131     c->clear();
00132 
00133     if (!info)
00134         goto CategoryAll;
00135 
00136     // Fill up the categories list box with
00137     // the categories defined by the user.
00138     // These presumably are in the language
00139     // the user uses, so no translation is necessary.
00140     //
00141     //
00142     for (int i = 0; i < PILOT_CATEGORY_MAX; i++)
00143     {
00144         if (info->name[i][0])
00145         {
00146 #ifdef DEBUG
00147             DEBUGKPILOT << fname
00148                 << ": Adding category: "
00149                 << info->name[i]
00150                 << " with ID: " << (int) info->ID[i] << endl;
00151 #endif
00152 
00153             c->insertItem(PilotAppCategory::codec()->toUnicode(info->name[i]));
00154         }
00155     }
00156 
00157 CategoryAll:
00158     c->insertItem(i18n("All"), 0);
00159 }
00160 
00161 
00162 void PilotComponent::slotShowComponent()
00163 {
00164     FUNCTIONSETUP;
00165 
00166 #ifdef DEBUG
00167     DEBUGKPILOT << fname << ": Showing component @" << (long) this << endl;
00168 #endif
00169 
00170     emit showComponent(this);
00171 }
00172 
00173 /* virtual */ bool PilotComponent::preHotSync(QString &)
00174 {
00175     FUNCTIONSETUP;
00176 
00177     return true;
00178 }
00179 
00180 void PilotComponent::markDBDirty(const QString db)
00181 {
00182     FUNCTIONSETUP;
00183     KPilotConfig::addDirtyDatabase(db);
00184     KPilotConfig::sync();
00185 }
00186 
00187 void PilotComponent::showKPilotComponent( bool toShow )
00188 {
00189     if ( toShow != shown )
00190     {
00191         shown = toShow;
00192         if (shown) showComponent();
00193         else hideComponent();
00194     }
00195 }
KDE Home | KDE Accessibility Home | Description of Access Keys