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 #include <pi-appinfo.h> 00036 00037 #include <qwidget.h> 00038 #include <qcombobox.h> 00039 #include <qtextcodec.h> 00040 00041 #include <kdebug.h> 00042 00043 #include "kpilotConfig.h" 00044 #include "pilotAppCategory.h" 00045 #include "pilotComponent.moc" 00046 00047 static const char *pilotComponent_id = 00048 "$Id: pilotComponent.cc,v 1.30 2003/10/13 13:58:19 kainhofe Exp $"; 00049 00050 // This is a pilot constant and should probably be defined 00051 // in a more sensible place but I'm lazy right now. 00052 // 00053 #define MAX_CATEGORIES (15) 00054 00055 PilotComponent::PilotComponent(QWidget * parent, 00056 const char *id, 00057 const QString & path) : 00058 QWidget(parent, id), 00059 fDBPath(path), 00060 shown(false) 00061 { 00062 FUNCTIONSETUP; 00063 00064 if (parent) 00065 { 00066 resize(parent->geometry().width(), 00067 parent->geometry().height()); 00068 } 00069 00070 (void) pilotComponent_id; 00071 } 00072 00073 00074 00075 int PilotComponent::findSelectedCategory(QComboBox * fCatList, 00076 struct CategoryAppInfo *info, bool AllIsUnfiled) 00077 { 00078 FUNCTIONSETUP; 00079 00080 // Semantics of currentCatID are: 00081 // 00082 // >=0 is a specific category based on the text -> 00083 // category number mapping defined by the Pilot, 00084 // ==-1 means "All" category selected when 00085 // AllIsUnfiled is true. 00086 // == 0 == Unfiled means "All" category selected when 00087 // AllIsUnfiled is false. 00088 // 00089 // 00090 int currentCatID = 0; 00091 00092 // If a category is deleted after others have been added, none of the 00093 // category numbers are changed. So we need to find the category number 00094 // for this category (this category is represented by the selected 00095 // *text*). 00096 // 00097 // 00098 // The top entry in the list is "All", so if the top item is 00099 // selected we can indicate that we are using the "All" category. 00100 // 00101 // 00102 if (fCatList->currentItem() == 0) 00103 { 00104 currentCatID = (-1); 00105 #ifdef DEBUG 00106 DEBUGKPILOT << fname << ": Category 'All' selected.\n"; 00107 #endif 00108 } 00109 else 00110 { 00111 QString selectedCategory = 00112 fCatList->text(fCatList->currentItem()); 00113 00114 #ifdef DEBUG 00115 DEBUGKPILOT << fname 00116 << ": List item " 00117 << fCatList->currentItem() 00118 << " (of " 00119 << fCatList->count() 00120 << ") " 00121 << " selected, text=" << selectedCategory << endl; 00122 #endif 00123 00124 currentCatID = 0; 00125 while (strcmp(info->name[currentCatID], 00126 selectedCategory.latin1()) && 00127 (currentCatID < MAX_CATEGORIES)) 00128 { 00129 #ifdef DEBUG 00130 DEBUGKPILOT << fname 00131 << ": Didn't match category " 00132 << currentCatID 00133 << "=" << info->name[currentCatID] << endl; 00134 #endif 00135 00136 currentCatID++; 00137 } 00138 00139 if (!(currentCatID < MAX_CATEGORIES)) 00140 { 00141 currentCatID = 0; 00142 while (strcmp(info->name[currentCatID], 00143 selectedCategory.latin1()) && 00144 (currentCatID < MAX_CATEGORIES)) 00145 { 00146 currentCatID++; 00147 } 00148 } 00149 00150 if (!(currentCatID < MAX_CATEGORIES)) 00151 { 00152 currentCatID = 0; 00153 while (strcmp(info->name[currentCatID], 00154 selectedCategory.ascii()) && 00155 (currentCatID < MAX_CATEGORIES)) 00156 { 00157 currentCatID++; 00158 } 00159 } 00160 00161 if (!(currentCatID < MAX_CATEGORIES)) 00162 { 00163 currentCatID = 0; 00164 while ((info->name[currentCatID][0]) && 00165 (currentCatID < MAX_CATEGORIES)) 00166 { 00167 if (selectedCategory == 00168 QString::fromLatin1(info-> 00169 name[currentCatID])) 00170 { 00171 #ifdef DEBUG 00172 DEBUGKPILOT << fname 00173 << ": Matched " 00174 << currentCatID << endl; 00175 #endif 00176 00177 break; 00178 } 00179 currentCatID++; 00180 } 00181 } 00182 00183 if (currentCatID < MAX_CATEGORIES) 00184 { 00185 #ifdef DEBUG 00186 DEBUGKPILOT << fname 00187 << ": Matched category " 00188 << currentCatID 00189 << "=" << info->name[currentCatID] << endl; 00190 #endif 00191 } 00192 else 00193 { 00194 #ifdef DEBUG // necessary for Tru64 unix 00195 kdWarning() << k_funcinfo 00196 << ": Selected category didn't match " 00197 "any name!\n"; 00198 kdWarning() << k_funcinfo 00199 << ": Number of listed categories " 00200 << fCatList->count() << endl; 00201 kdWarning() << k_funcinfo 00202 << ": Selected category (" 00203 << selectedCategory 00204 << ") expands to " 00205 << qstringExpansion(selectedCategory) << endl; 00206 kdWarning() << k_funcinfo 00207 << ": Categories expand to " << endl; 00208 #endif 00209 currentCatID = 0; 00210 while ((info->name[currentCatID][0]) && 00211 (currentCatID < MAX_CATEGORIES)) 00212 { 00213 #ifdef DEBUG 00214 kdWarning() << k_funcinfo 00215 << ": Category [" 00216 << currentCatID 00217 << "] = " 00218 << charExpansion(info-> 00219 name[currentCatID]) << endl; 00220 #endif 00221 currentCatID++; 00222 } 00223 00224 currentCatID = (-1); 00225 } 00226 } 00227 00228 if ((currentCatID == -1) && AllIsUnfiled) 00229 currentCatID = 0; 00230 return currentCatID; 00231 } 00232 00233 00234 void PilotComponent::populateCategories(QComboBox * c, 00235 struct CategoryAppInfo *info) 00236 { 00237 FUNCTIONSETUP; 00238 00239 #ifdef DEBUG 00240 DEBUGKPILOT << fname 00241 << ": Combo box @" 00242 << (int) c << " and info @" << (int) info << endl; 00243 #endif 00244 00245 c->clear(); 00246 00247 if (!info) 00248 goto CategoryAll; 00249 00250 // Fill up the categories list box with 00251 // the categories defined by the user. 00252 // These presumably are in the language 00253 // the user uses, so no translation is necessary. 00254 // 00255 // 00256 for (int i = 0; i < 15; i++) 00257 { 00258 if (info->name[i][0]) 00259 { 00260 #ifdef DEBUG 00261 DEBUGKPILOT << fname 00262 << ": Adding category: " 00263 << info->name[i] 00264 << " with ID: " << (int) info->ID[i] << endl; 00265 #endif 00266 00267 c->insertItem(PilotAppCategory::codec()->toUnicode(info->name[i])); 00268 } 00269 } 00270 00271 CategoryAll: 00272 c->insertItem(i18n("All"), 0); 00273 } 00274 00275 00276 void PilotComponent::slotShowComponent() 00277 { 00278 FUNCTIONSETUP; 00279 00280 #ifdef DEBUG 00281 DEBUGKPILOT << fname << ": Showing component @" << (int) this << endl; 00282 #endif 00283 00284 emit showComponent(this); 00285 } 00286 00287 /* virtual */ bool PilotComponent::preHotSync(QString &) 00288 { 00289 FUNCTIONSETUP; 00290 00291 return true; 00292 } 00293 00294 void PilotComponent::markDBDirty(const QString db) 00295 { 00296 FUNCTIONSETUP; 00297 KPilotConfigSettings&c=KPilotConfig::getConfig(); 00298 c.setDatabaseGroup().addDirtyDatabase(db); 00299 c.sync(); 00300 } 00301 00302 void PilotComponent::showKPilotComponent( bool toShow ) 00303 { 00304 if ( toShow != shown ) 00305 { 00306 shown = toShow; 00307 if (shown) showComponent(); 00308 else hideComponent(); 00309 } 00310 }
KDE Logo
This file is part of the documentation for kpilot Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:57:49 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003