pilotComponent.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
00051
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
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 int currentCatID = 0;
00091
00092
00093
00094
00095
00096
00097
00098
00099
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
00251
00252
00253
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 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 }
This file is part of the documentation for kpilot Library Version 3.2.2.