kpilot

pilotComponent.cc

Go to the documentation of this file.
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 
00041 #include <kdebug.h>
00042 
00043 #include "kpilotConfig.h"
00044 #include "pilotRecord.h"
00045 #include "pilot.h"
00046 
00047 #include "pilotComponent.moc"
00048 
00049 PilotComponent::PilotComponent(QWidget * parent,
00050     const char *id,
00051     const QString & path) :
00052     QWidget(parent, id),
00053     fDBPath(path),
00054     shown(false)
00055 {
00056     FUNCTIONSETUP;
00057 
00058     if (parent)
00059     {
00060         resize(parent->geometry().width(),
00061             parent->geometry().height());
00062     }
00063 
00064 }
00065 
00066 
00067 
00068 int PilotComponent::findSelectedCategory(QComboBox * fCatList,
00069     struct CategoryAppInfo *info, bool AllIsUnfiled)
00070 {
00071     FUNCTIONSETUP;
00072 
00073     // Semantics of currentCatID are:
00074     //
00075     // >=0          is a specific category based on the text ->
00076     //              category number mapping defined by the Pilot,
00077     // ==-1         means "All" category selected when
00078     //              AllIsUnfiled is true.
00079     // == 0         == Unfiled means "All" category selected when
00080     //              AllIsUnfiled is false.
00081     //
00082     //
00083     int currentCatID = 0;
00084 
00085     // If a category is deleted after others have been added, none of the
00086     // category numbers are changed.  So we need to find the category number
00087     // for this category (this category is represented by the selected
00088     // *text*).
00089     //
00090     //
00091     // The top entry in the list is "All", so if the top item is
00092     // selected we can indicate that we are using the "All" category.
00093     //
00094     //
00095     if (fCatList->currentItem() == 0)
00096     {
00097         currentCatID = (-1);
00098 #ifdef DEBUG
00099         DEBUGKPILOT << fname << ": Category 'All' selected.\n";
00100 #endif
00101     }
00102     else
00103     {
00104         QString selectedCategory =
00105             fCatList->text(fCatList->currentItem());
00106         currentCatID = Pilot::findCategory(info, selectedCategory, AllIsUnfiled);
00107     }
00108 
00109     if ((currentCatID == -1) && AllIsUnfiled)
00110         currentCatID = 0;
00111     return currentCatID;
00112 }
00113 
00114 
00115 void PilotComponent::populateCategories(QComboBox * c,
00116     struct CategoryAppInfo *info)
00117 {
00118     FUNCTIONSETUP;
00119 
00120 #ifdef DEBUG
00121     DEBUGKPILOT << fname
00122         << ": Combo box @"
00123         << (long) c << " and info @" << (long) info << endl;
00124 #endif
00125 
00126     c->clear();
00127 
00128     if (!info)
00129         goto CategoryAll;
00130 
00131     // Fill up the categories list box with
00132     // the categories defined by the user.
00133     // These presumably are in the language
00134     // the user uses, so no translation is necessary.
00135     //
00136     //
00137     for (unsigned int i = 0; i < Pilot::CATEGORY_COUNT; i++)
00138     {
00139         if (info->name[i][0])
00140         {
00141 #ifdef DEBUG
00142             DEBUGKPILOT << fname
00143                 << ": Adding category: "
00144                 << info->name[i]
00145                 << " with ID: " << (int) info->ID[i] << endl;
00146 #endif
00147 
00148             c->insertItem(Pilot::fromPilot(info->name[i]));
00149         }
00150     }
00151 
00152 CategoryAll:
00153     c->insertItem(i18n("All"), 0);
00154 }
00155 
00156 
00157 void PilotComponent::slotShowComponent()
00158 {
00159     FUNCTIONSETUP;
00160 
00161 #ifdef DEBUG
00162     DEBUGKPILOT << fname << ": Showing component @" << (long) this << endl;
00163 #endif
00164 
00165     emit showComponent(this);
00166 }
00167 
00168 /* virtual */ bool PilotComponent::preHotSync(QString &)
00169 {
00170     FUNCTIONSETUP;
00171 
00172     return true;
00173 }
00174 
00175 void PilotComponent::markDBDirty(const QString db)
00176 {
00177     FUNCTIONSETUP;
00178     KPilotConfig::addDirtyDatabase(db);
00179     KPilotConfig::sync();
00180 }
00181 
00182 void PilotComponent::showKPilotComponent( bool toShow )
00183 {
00184     if ( toShow != shown )
00185     {
00186         shown = toShow;
00187         if (shown) showComponent();
00188         else hideComponent();
00189     }
00190 }