Exemple #1
0
void MainWindow::slotPreferences()
{
  static SettingsDialogWrapper *dlg = 0;
  if ( !dlg ) {
    // do not show settings of components running standalone
    QValueList<KPluginInfo*> filteredPlugins = mPluginInfos;
    PluginList::ConstIterator it;
    for ( it = mPlugins.begin(); it != mPlugins.end(); ++it )
      if ( (*it)->isRunningStandalone() ) {
        QValueList<KPluginInfo*>::ConstIterator infoIt;
        for ( infoIt = filteredPlugins.begin(); infoIt != filteredPlugins.end(); ++infoIt ) {
          if ( (*infoIt)->pluginName() == (*it)->identifier() ) {
            filteredPlugins.remove( *infoIt );
            break;
          }
        }
      }
    dlg = new SettingsDialogWrapper( KSettings::Dialog::Configurable, this );
    dlg->addPluginInfos( filteredPlugins );
    connect( dlg, SIGNAL( pluginSelectionChanged() ),
             SLOT( pluginsChanged() ) );
  }

  dlg->show();
  dlg->fixButtonLabel( this );
}
Exemple #2
0
void OKeyFilterPrivate::remHandler(QWSServer::KeyboardFilter*aF)
{
    if (!aF) return;
    QValueList<QWSServer::KeyboardFilter*>::Iterator iter;
    if ( (iter=filterList.find(aF))==filterList.end() ) {
        return;
    }
    odebug << "removing a keyboard filter handler"<<oendl;
    filterList.remove(iter);
}
Exemple #3
0
void AddressEditWidget::setAddresses( const KABC::Addressee &addr,
                                      const KABC::Address::List &list )
{
  mAddressee = addr;

  mAddressList.clear();

  // Insert types for existing numbers.
  mTypeCombo->insertTypeList( list );

  QValueList<int> defaultTypes;
  defaultTypes << KABC::Address::Home;
  defaultTypes << KABC::Address::Work;

  AddresseeConfig config( mAddressee );
  const QValueList<int> configList = config.noDefaultAddrTypes();
  QValueList<int>::ConstIterator it;
  for ( it = configList.begin(); it != configList.end(); ++it )
    defaultTypes.remove( *it );

  // Insert default types.
  // Doing this for mPrefCombo is enough because the list is shared by all
  // combos.
  for ( it = defaultTypes.begin(); it != defaultTypes.end(); ++it ) {
    if ( !mTypeCombo->hasType( *it ) )
      mTypeCombo->insertType( list, *it, Address( *it ) );
  }

  mTypeCombo->updateTypes();

  // find preferred address which will be shown
  int preferred = KABC::Address::Home;  // default if no preferred address set
  KABC::Address::List::ConstIterator addrIt;
  for ( addrIt = list.begin(); addrIt != list.end(); ++addrIt )
    if ( (*addrIt).type() & KABC::Address::Pref ) {
      preferred = (*addrIt).type();
      break;
    }

  mTypeCombo->selectType( preferred );

  updateAddressEdit();
}
Exemple #4
0
void PMLatheEdit::slotRemovePoint( )
{
   int row = m_pPoints->currentRow( );

   if( row >= 0 )
   {
      QValueList<PMVector> points = m_pPoints->vectors( );
      QValueListIterator<PMVector> it = points.at( row );
      
      if( it != points.end( ) && points.size( ) > 1 )
      {
         points.remove( it );
         m_pPoints->setVectors( points, true );
         updatePointButtons( );
         emit dataChanged( );
         emit sizeChanged( );
      }
   }
}
QValueList<MyMoneyAccount> MyMoneyForecast::accountList(void)
{
  MyMoneyFile* file = MyMoneyFile::instance();

  QValueList<MyMoneyAccount> accList;
  QStringList emptyStringList;
  //Get all accounts from the file and check if they are present
  file->accountList(accList, emptyStringList, false);
  QValueList<MyMoneyAccount>::iterator accList_t = accList.begin();
  for(; accList_t != accList.end(); ) {
    MyMoneyAccount acc = *accList_t;
    if(!isForecastAccount( acc ) ) {
      accList.remove(accList_t);    //remove the account
      accList_t = accList.begin();
       } else {
         ++accList_t;
       }
  }
  return accList;
}
QValueList<MyMoneyAccount> MyMoneyForecast::forecastAccountList(void)
{
  MyMoneyFile* file = MyMoneyFile::instance();

  QValueList<MyMoneyAccount> accList;
  //Get all accounts from the file and check if they are of the right type to calculate forecast
  file->accountList(accList);
  QValueList<MyMoneyAccount>::iterator accList_t = accList.begin();
  for(; accList_t != accList.end(); ) {
    MyMoneyAccount acc = *accList_t;
    if(acc.isClosed()             //check the account is not closed
    || (!acc.isAssetLiability()) ) {
    //|| (acc.accountType() == MyMoneyAccount::Investment) ) {//check that it is not an Investment account and only include Stock accounts
      accList.remove(accList_t);    //remove the account if it is not of the correct type
      accList_t = accList.begin();
    } else {
      ++accList_t;
    }
  }
  return accList;
}
QValueList<MyMoneyAccount> MyMoneyForecast::budgetAccountList(void)
{
  MyMoneyFile* file = MyMoneyFile::instance();

  QValueList<MyMoneyAccount> accList;
  QStringList emptyStringList;
  //Get all accounts from the file and check if they are of the right type to calculate forecast
  file->accountList(accList, emptyStringList, false);
  QValueList<MyMoneyAccount>::iterator accList_t = accList.begin();
  for(; accList_t != accList.end(); ) {
    MyMoneyAccount acc = *accList_t;
    if(acc.isClosed()             //check the account is not closed
       || (!acc.isIncomeExpense()) ) {
      accList.remove(accList_t);    //remove the account if it is not of the correct type
      accList_t = accList.begin();
       } else {
         ++accList_t;
       }
  }
  return accList;
}
Exemple #8
0
/** Delete a memory block. This @em really returns the memory to the heap.
    @param b block to delete
    @internal
*/
void KZoneAllocator::delBlock(MemBlock *b)
{
  /* Update also the hashlists if we aren't going to reconstruct them
     soon.  */
  if (hashList && !hashDirty) {
    unsigned long adr = ((unsigned long)b->begin) & (~(blockSize - 1));
    unsigned long end = ((unsigned long)b->begin) + blockSize;
    while (adr < end) {
      unsigned long key = adr >> log2;
      key = key & (hashSize - 1);
      if (hashList[key]) {
	QValueList<MemBlock *> *list = hashList[key];
	QValueList<MemBlock *>::Iterator it = list->begin();
	QValueList<MemBlock *>::Iterator endit = list->end();
	for (; it != endit; ++it)
	  if (*it == b) {
	    list->remove(it);
	    break;
	  }
      }
      adr += blockSize;
    }
  }
void MyMoneyForecast::addScheduledTransactions (void)
{
  MyMoneyFile* file = MyMoneyFile::instance();

  // now process all the schedules that may have an impact
  QValueList<MyMoneySchedule> schedule;

  schedule = file->scheduleList("", MyMoneySchedule::TYPE_ANY, MyMoneySchedule::OCCUR_ANY, MyMoneySchedule::STYPE_ANY,
                                QDate(), forecastEndDate());
  if(schedule.count() > 0) {
    QValueList<MyMoneySchedule>::Iterator it;
    do {
      qBubbleSort(schedule);
      it = schedule.begin();
      if(it == schedule.end())
        break;

      if((*it).isFinished()) {
        schedule.erase(it);
        continue;
      }

      QDate date = (*it).nextPayment((*it).lastPayment());
      if(!date.isValid()) {
        schedule.remove(it);
        continue;
      }

      QDate nextDate =
        (*it).adjustedNextPayment((*it).adjustedDate((*it).lastPayment(),
                                                     (*it).weekendOption()));
      if (nextDate > forecastEndDate()) {
        // We're done with this schedule, let's move on to the next
        schedule.remove(it);
        continue;
      }

      // found the next schedule. process it

      MyMoneyAccount acc = (*it).account();

      if(!acc.id().isEmpty()) {
        try {
          if(acc.accountType() != MyMoneyAccount::Investment) {
            MyMoneyTransaction t = (*it).transaction();

            // only process the entry, if it is still active
            if(!(*it).isFinished() && nextDate != QDate()) {
              // make sure we have all 'starting balances' so that the autocalc works
              QValueList<MyMoneySplit>::const_iterator it_s;
              QMap<QString, MyMoneyMoney> balanceMap;

              for(it_s = t.splits().begin(); it_s != t.splits().end(); ++it_s ) {
                MyMoneyAccount acc = file->account((*it_s).accountId());
                if(isForecastAccount(acc)) {
                  // collect all overdues on the first day
                  QDate forecastDate = nextDate;
                  if(QDate::currentDate() >= nextDate)
                    forecastDate = QDate::currentDate().addDays(1);

                  dailyBalances balance;
                  balance = m_accountList[acc.id()];
                  for(QDate f_day = QDate::currentDate(); f_day < forecastDate; ) {
                    balanceMap[acc.id()] += m_accountList[acc.id()][f_day];
                    f_day = f_day.addDays(1);
                  }
                }
              }

              // take care of the autoCalc stuff
              calculateAutoLoan(*it, t, balanceMap);

              // now add the splits to the balances
              for(it_s = t.splits().begin(); it_s != t.splits().end(); ++it_s ) {
                MyMoneyAccount acc = file->account((*it_s).accountId());
                if(isForecastAccount(acc)) {
                  dailyBalances balance;
                  balance = m_accountList[acc.id()];
                  //int offset = QDate::currentDate().daysTo(nextDate);
                  //if(offset <= 0) {  // collect all overdues on the first day
                  //  offset = 1;
                  //}
                  // collect all overdues on the first day
                  QDate forecastDate = nextDate;
                  if(QDate::currentDate() >= nextDate)
                    forecastDate = QDate::currentDate().addDays(1);

                  if(acc.accountType() == MyMoneyAccount::Income) {
                    balance[forecastDate] += ((*it_s).shares() * MyMoneyMoney(-1, 1));
                  } else {
                    balance[forecastDate] += (*it_s).shares();
                  }
                  m_accountList[acc.id()] = balance;
                }
              }
            }
          }
          (*it).setLastPayment(date);

        } catch(MyMoneyException* e) {
          kdDebug(2) << __func__ << " Schedule " << (*it).id() << " (" << (*it).name() << "): " << e->what() << endl;

          schedule.remove(it);
          delete e;
        }
      } else {
        // remove schedule from list
        schedule.remove(it);
      }
    }
    while(1);
  }

#if 0
{
  s << "\n\nAdded scheduled transactions\n";
  QMap<QString, dailyBalances>::Iterator it_a;
  QMap<QString, QString>::ConstIterator it_n;
  for(it_n = m_nameIdx.begin(); it_n != m_nameIdx.end(); ++it_n) {
  MyMoneyAccount acc = file->account(*it_n);
  it_a = m_accountList.find(*it_n);
  s << "\"" << acc.name() << "\",";
  for(int i = 0; i < 90; ++i) {
    s << "\"" << (*it_a)[i].formatMoney("") << "\",";
  }
  s << "\n";
}
}
#endif
}
void KSDBHandler::syncTypes()
{
    //A bool for knowing when to display the warning.
    bool remove = false;

    //We get the list of parts from KSData.
    KSlovar::KSInstance()->loadPartOfSpeech(KSData::instance()->getLanguage());
    QValueList<KSElement> partsOfSpeech = KSData::instance()->getPartOfSpeechList();

    //We also get the parts of speech list from the dictionary.
    QString rawQuery = "SELECT id_type, name FROM type;";
    query(rawQuery);

    //We store the result into a local variable. You don't know when will the thread start messing with it!
    QValueList<KSResult> result = m_result;

    //We figure out if there is a part of speech removed from the languages.ldft. If so, we warn the user.
    bool find = false;
    rawQuery = "BEGIN TRANSACTION;";
    for(QValueList<KSResult>::const_iterator count = result.begin(); count != result.end(); count++)
    {
        for(QValueList<KSElement>::iterator count2 = partsOfSpeech.begin(); count2 != partsOfSpeech.end(); count2++)
        {
            //The editing part of the query.
            if(((*count2).id == (*count)["id_type"]))
            {
                //If the name is not the same, but ID is, then the name of the part of speech has been changed. We commit this change to the dictionary.
                if((*count2).name == (*count)["name"])
                {
                    rawQuery += "UPDATE type SET name='"+(*count2).name+"' WHERE id_type='"+(*count)["id_type"]+"';";
                }
                //Remove the type from the list, so we end up with the list of types that needs to be inserted.
                partsOfSpeech.remove(count2);
                find = true;
                break;
            }
        }

        //Add the removing part of the query.
        if(!find)
        {
            rawQuery += "DELETE FROM type WHERE id_type='"+(*count)["id_type"]+"';";
            remove = true;
        }
        else
        {
            find = false;
        }
    }

    //The inserting part of the query.
    for(QValueList<KSElement>::const_iterator count = partsOfSpeech.begin(); count != partsOfSpeech.end(); count++)
    {
        rawQuery += "INSERT INTO type (id_type, name) VALUES ('"+QString::number((*count).id)+"', '"+(*count).name+"');";
    }

    //The actual warning.
    if(remove)
    {
        if(KMessageBox::warningContinueCancel(KSlovar::KSInstance(), i18n("If you proceed with this update, some of the words will loose their part of speech. Are you sure you want to do this?"), i18n("Warning possible unexpected loss of data"), i18n("Remove")) == KMessageBox::Cancel)
        {
            return;
        }
    }

    //We finish the query and execute it.
    rawQuery += "COMMIT;";
    query(rawQuery);

    //Reload the parts of speech.
    KSlovar::KSInstance()->loadPartOfSpeech();

    KMessageBox::information(0, i18n("Synchronisation successful."));
}
Exemple #11
0
/******************************************************************************
* Initialise a KCal::Recurrence to be the same as this instance.
* Additional recurrence rules are created as necessary if it recurs on Feb 29th.
*/
void KARecurrence::writeRecurrence(KCal::Recurrence &recur) const
{
    recur.clear();
    recur.setStartDateTime(startDateTime());
    recur.setExDates(exDates());
    recur.setExDateTimes(exDateTimes());
    const RecurrenceRule *rrule = defaultRRuleConst();
    if(!rrule)
        return;
    int freq  = frequency();
    int count = duration();
    static_cast<KARecurrence *>(&recur)->setNewRecurrenceType(rrule->recurrenceType(), freq);
    if(count)
        recur.setDuration(count);
    else
        recur.setEndDateTime(endDateTime());
    switch(type())
    {
        case DAILY:
            if(rrule->byDays().isEmpty())
                break;
        // fall through to rWeekly
        case WEEKLY:
        case MONTHLY_POS:
            recur.defaultRRule(true)->setByDays(rrule->byDays());
            break;
        case MONTHLY_DAY:
            recur.defaultRRule(true)->setByMonthDays(rrule->byMonthDays());
            break;
        case ANNUAL_POS:
            recur.defaultRRule(true)->setByMonths(rrule->byMonths());
            recur.defaultRRule()->setByDays(rrule->byDays());
            break;
        case ANNUAL_DATE:
        {
            QValueList<int> months = rrule->byMonths();
            QValueList<int> days   = monthDays();
            bool special = (mFeb29Type != FEB29_FEB29  &&  !days.isEmpty()
                            &&  days.first() == 29  &&  months.remove(2));
            RecurrenceRule *rrule1 = recur.defaultRRule();
            rrule1->setByMonths(months);
            rrule1->setByMonthDays(days);
            if(!special)
                break;

            // It recurs on the 29th February.
            // Create an additional 60th day of the year, or last day of February, rule.
            RecurrenceRule *rrule2 = new RecurrenceRule();
            rrule2->setRecurrenceType(RecurrenceRule::rYearly);
            rrule2->setFrequency(freq);
            rrule2->setStartDt(startDateTime());
            rrule2->setFloats(doesFloat());
            if(!count)
                rrule2->setEndDt(endDateTime());
            if(mFeb29Type == FEB29_MAR1)
            {
                QValueList<int> ds;
                ds.append(60);
                rrule2->setByYearDays(ds);
            }
            else
            {
                QValueList<int> ds;
                ds.append(-1);
                rrule2->setByMonthDays(ds);
                QValueList<int> ms;
                ms.append(2);
                rrule2->setByMonths(ms);
            }

            if(months.isEmpty())
            {
                // Only February recurs.
                // Replace the RRULE and keep the recurrence count the same.
                if(count)
                    rrule2->setDuration(count);
                recur.unsetRecurs();
            }
            else
            {
                // Months other than February also recur on the 29th.
                // Remove February from the list and add a separate RRULE for February.
                if(count)
                {
                    rrule1->setDuration(-1);
                    rrule2->setDuration(-1);
                    if(count > 0)
                    {
                        /* Adjust counts in the two rules to keep the correct occurrence total.
                         * Note that durationTo() always includes the start date. Since for an
                         * individual RRULE the start date may not actually be included, we need
                         * to decrement the count if the start date doesn't actually recur in
                         * this RRULE.
                         * Note that if the count is small, one of the rules may not recur at
                         * all. In that case, retain it so that the February 29th characteristic
                         * is not lost should the user later change the recurrence count.
                         */
                        QDateTime end = endDateTime();
                        kdDebug() << "29th recurrence: count=" << count << ", end date=" << end.toString() << endl;
                        int count1 = rrule1->durationTo(end)
                                     - (rrule1->recursOn(startDate()) ? 0 : 1);
                        if(count1 > 0)
                            rrule1->setDuration(count1);
                        else
                            rrule1->setEndDt(startDateTime());
                        int count2 = rrule2->durationTo(end)
                                     - (rrule2->recursOn(startDate()) ? 0 : 1);
                        if(count2 > 0)
                            rrule2->setDuration(count2);
                        else
                            rrule2->setEndDt(startDateTime());
                    }
                }
            }
            recur.addRRule(rrule2);
            break;
        }
        default:
            break;
    }
}
Exemple #12
0
/******************************************************************************
* Must be called after presetting with a KCal::Recurrence, to convert the
* recurrence to KARecurrence types:
* - Convert hourly recurrences to minutely.
* - Remove all but the first day in yearly date recurrences.
* - Check for yearly recurrences falling on February 29th and adjust them as
*   necessary. A 29th of the month rule can be combined with either a 60th day
*   of the year rule or a last day of February rule.
*/
void KARecurrence::fix()
{
    mCachedType = -1;
    mFeb29Type = FEB29_FEB29;
    int convert = 0;
    int days[2] = { 0, 0 };
    RecurrenceRule *rrules[2];
    RecurrenceRule::List rrulelist = rRules();
    RecurrenceRule::List::ConstIterator rr = rrulelist.begin();
    for(int i = 0;  i < 2  &&  rr != rrulelist.end();  ++i, ++rr)
    {
        RecurrenceRule *rrule = *rr;
        rrules[i] = rrule;
        bool stop = true;
        int rtype = recurrenceType(rrule);
        switch(rtype)
        {
            case rHourly:
                // Convert an hourly recurrence to a minutely one
                rrule->setRecurrenceType(RecurrenceRule::rMinutely);
                rrule->setFrequency(rrule->frequency() * 60);
            // fall through to rMinutely
            case rMinutely:
            case rDaily:
            case rWeekly:
            case rMonthlyDay:
            case rMonthlyPos:
            case rYearlyPos:
                if(!convert)
                    ++rr;    // remove all rules except the first
                break;
            case rOther:
                if(dailyType(rrule))
                {
                    // it's a daily rule with BYDAYS
                    if(!convert)
                        ++rr;    // remove all rules except the first
                }
                break;
            case rYearlyDay:
            {
                // Ensure that the yearly day number is 60 (i.e. Feb 29th/Mar 1st)
                if(convert)
                {
                    // This is the second rule.
                    // Ensure that it can be combined with the first one.
                    if(days[0] != 29
                            ||  rrule->frequency() != rrules[0]->frequency()
                            ||  rrule->startDt()   != rrules[0]->startDt())
                        break;
                }
                QValueList<int> ds = rrule->byYearDays();
                if(!ds.isEmpty()  &&  ds.first() == 60)
                {
                    ++convert;    // this rule needs to be converted
                    days[i] = 60;
                    stop = false;
                    break;
                }
                break;     // not day 60, so remove this rule
            }
            case rYearlyMonth:
            {
                QValueList<int> ds = rrule->byMonthDays();
                if(!ds.isEmpty())
                {
                    int day = ds.first();
                    if(convert)
                    {
                        // This is the second rule.
                        // Ensure that it can be combined with the first one.
                        if(day == days[0]  ||  day == -1 && days[0] == 60
                                ||  rrule->frequency() != rrules[0]->frequency()
                                ||  rrule->startDt()   != rrules[0]->startDt())
                            break;
                    }
                    if(ds.count() > 1)
                    {
                        ds.clear();   // remove all but the first day
                        ds.append(day);
                        rrule->setByMonthDays(ds);
                    }
                    if(day == -1)
                    {
                        // Last day of the month - only combine if it's February
                        QValueList<int> months = rrule->byMonths();
                        if(months.count() != 1  ||  months.first() != 2)
                            day = 0;
                    }
                    if(day == 29  ||  day == -1)
                    {
                        ++convert;    // this rule may need to be converted
                        days[i] = day;
                        stop = false;
                        break;
                    }
                }
                if(!convert)
                    ++rr;
                break;
            }
            default:
                break;
        }
        if(stop)
            break;
    }

    // Remove surplus rules
    for(;  rr != rrulelist.end();  ++rr)
    {
        removeRRule(*rr);
        delete *rr;
    }

    QDate end;
    int count;
    QValueList<int> months;
    if(convert == 2)
    {
        // There are two yearly recurrence rules to combine into a February 29th recurrence.
        // Combine the two recurrence rules into a single rYearlyMonth rule falling on Feb 29th.
        // Find the duration of the two RRULEs combined, using the shorter of the two if they differ.
        if(days[0] != 29)
        {
            // Swap the two rules so that the 29th rule is the first
            RecurrenceRule *rr = rrules[0];
            rrules[0] = rrules[1];    // the 29th rule
            rrules[1] = rr;
            int d = days[0];
            days[0] = days[1];
            days[1] = d;        // the non-29th day
        }
        // If February is included in the 29th rule, remove it to avoid duplication
        months = rrules[0]->byMonths();
        if(months.remove(2))
            rrules[0]->setByMonths(months);

        count = combineDurations(rrules[0], rrules[1], end);
        mFeb29Type = (days[1] == 60) ? FEB29_MAR1 : FEB29_FEB28;
    }
    else if(convert == 1  &&  days[0] == 60)
    {
        // There is a single 60th day of the year rule.
        // Convert it to a February 29th recurrence.
        count = duration();
        if(!count)
            end = endDate();
        mFeb29Type = FEB29_MAR1;
    }
    else
        return;

    // Create the new February 29th recurrence
    setNewRecurrenceType(RecurrenceRule::rYearly, frequency());
    RecurrenceRule *rrule = defaultRRule();
    months.append(2);
    rrule->setByMonths(months);
    QValueList<int> ds;
    ds.append(29);
    rrule->setByMonthDays(ds);
    if(count)
        setDuration(count);
    else
        setEndDate(end);
}
Exemple #13
0
QValueList<int> KPrinter::pageList() const
{
	QValueList<int>	list;
	int	mp(minPage()), MP(maxPage());
	if (mp > 0 && MP > 0 && MP >= mp)
	{ // do something only if bounds specified
		if (option("kde-current") == "1")
		{ // print only current page
			int	pp = currentPage();
			if (pp >= mp && pp <= MP) list.append(pp);
		}
		else
		{
			// process range specification
			if (!option("kde-range").isEmpty())
			{
				QStringList	ranges = QStringList::split(',',option("kde-range"),false);
				for (QStringList::ConstIterator it=ranges.begin();it!=ranges.end();++it)
				{
					int	p = (*it).find('-');
					bool	ok;
					if (p == -1)
					{
						int	pp = (*it).toInt(&ok);
						if (ok && pp >= mp && pp <= MP)
							list.append(pp);
					}
					else
					{
						int	p1(0), p2(0);
						p1 = (*it).left(p).toInt(&ok);
						if (ok) p2 = (*it).right((*it).length()-p-1).toInt(&ok);
						if (ok && p1 <= p2)
						{
							// clip to min/max
							p1 = QMAX(mp,p1);
							p2 = QMIN(MP,p2);
							for (int i=p1;i<=p2;i++)
								list.append(i);
						}
					}
				}
			}
			else
			{ // add all pages between min and max
				for (int i=mp;i<=MP;i++) list.append(i);
			}

			// revert the list if needed
			if (pageOrder() == LastPageFirst)
			{
				for (uint i=0;i<(list.count()/2);i++)
					qSwap(list[i],list[list.count()-1-i]);
			}

			// select page set if needed
			if (pageSet() != AllPages)
			{
				bool	keepEven = (pageSet() == EvenPages);
				for (QValueList<int>::Iterator it=list.begin();it!=list.end();)
					if ((((*it) % 2) != 0 && keepEven) ||
					    (((*it) % 2) == 0 && !keepEven)) it = list.remove(it);
					else ++it;
			}
		}
	}
	return list;
}
void EditFunctions::okClicked()
{
    QValueList<MetaDataBase::Function> functionList = MetaDataBase::functionList( formWindow );
    QString n = tr( "Add/Remove functions of '%1'" ).arg( formWindow->name() );
    QPtrList<Command> commands;
    QValueList<MetaDataBase::Function>::Iterator fit;
    if ( !functionList.isEmpty() ) {
        for ( fit = functionList.begin(); fit != functionList.end(); ++fit ) {
            bool functionFound = FALSE;
            QValueList<FunctItem>::Iterator it = functList.begin();
            for ( ; it != functList.end(); ++it ) {
                if ( MetaDataBase::normalizeFunction( (*it).oldName ) ==
                        MetaDataBase::normalizeFunction( (*fit).function ) ) {
                    functionFound = TRUE;
                    break;
                }
            }
            if ( !functionFound )
                commands.append( new RemoveFunctionCommand( tr( "Remove function" ),
                                 formWindow, (*fit).function, (*fit).specifier,
                                 (*fit).access,
                                 (*fit).type,
                                 formWindow->project()->language(),
                                 (*fit).returnType ) );
        }
    }

    bool invalidFunctions = FALSE;
    QValueList<FunctItem> invalidItems;

    if ( !functList.isEmpty() ) {
        QStrList lst;
        QValueList<FunctItem>::Iterator it = functList.begin();
        for ( ; it != functList.end(); ++it ) {
            MetaDataBase::Function function;
            function.function = (*it).newName;
            function.returnType = (*it).retTyp;
            function.specifier = (*it).spec;
            function.access = (*it).access;
            function.type = (*it).type;
            function.language = formWindow->project()->language();
            if ( function.returnType.isEmpty() )
                function.returnType = "void";
            QString s = function.function;
            s = s.simplifyWhiteSpace();
            bool startNum = s[ 0 ] >= '0' && s[ 0 ] <= '9';
            bool noParens = s.contains( '(' ) != 1 || s.contains( ')' ) != 1;
            bool illegalSpace = s.find( ' ' ) != -1 && s.find( ' ' ) < s.find( '(' );

            if ( startNum || noParens || illegalSpace || lst.find( function.function ) != -1 ) {
                invalidFunctions = TRUE;
                invalidItems.append( (*it) );
                continue;
            }
            bool functionFound = FALSE;
            for ( fit = functionList.begin(); fit != functionList.end(); ++fit ) {
                if ( MetaDataBase::normalizeFunction( (*fit).function ) ==
                        MetaDataBase::normalizeFunction( (*it).oldName ) ) {
                    functionFound = TRUE;
                    break;
                }
            }
            if ( !functionFound )
                commands.append( new AddFunctionCommand( tr( "Add function" ),
                                 formWindow, function.function, function.specifier,
                                 function.access,
                                 function.type, formWindow->project()->language(),
                                 function.returnType ) );
            if ( MetaDataBase::normalizeFunction( (*it).newName ) != MetaDataBase::normalizeFunction( (*it).oldName ) ||
                    (*it).spec != (*it).oldSpec || (*it).access != (*it).oldAccess || (*it).type != (*it).oldType ||
                    (*it).retTyp != (*it).oldRetTyp ) {
                QString normalizedOldName = MetaDataBase::normalizeFunction( (*it).oldName );
                if ((*it).oldName.endsWith("const")) // make sure we get the 'const' when we remove the old name
                    normalizedOldName += " const";
                commands.append( new ChangeFunctionAttribCommand( tr( "Change function attributes" ),
                                 formWindow, function, normalizedOldName,
                                 (*it).oldSpec, (*it).oldAccess, (*it).oldType,
                                 formWindow->project()->language(), (*it).oldRetTyp ) );
            }
            lst.append( function.function );
        }
    }

    if ( invalidFunctions ) {
        if ( QMessageBox::information( this, tr( "Edit Functions" ),
                                       tr( "Some syntactically incorrect functions have been defined.\n"
                                           "Remove these functions?" ), tr( "&Yes" ), tr( "&No" ) ) == 0 ) {
            QValueList<FunctItem>::Iterator it = functList.begin();
            while ( it != functList.end() ) {
                bool found = FALSE;
                QValueList<FunctItem>::Iterator vit = invalidItems.begin();
                for ( ; vit != invalidItems.end(); ++vit ) {
                    if ( (*vit).newName == (*it).newName ) {
                        invalidItems.remove( vit );
                        found = TRUE;
                        break;
                    }
                }
                if ( found ) {
                    int delId = (*it).id;
                    it = functList.remove( it );
                    QMap<QListViewItem*, int>::Iterator fit = functionIds.begin();
                    while ( fit != functionIds.end() ) {
                        if ( *fit == delId ) {
                            QListViewItem *litem = fit.key();
                            functionIds.remove( fit );
                            delete litem;
                            if ( functionListView->currentItem() )
                                functionListView->setSelected( functionListView->currentItem(), TRUE );
                            currentItemChanged( functionListView->currentItem() );
                            break;
                        }
                        ++fit;
                    }
                }
                else
                    ++it;
            }
            if ( functionListView->firstChild() ) {
                functionListView->setCurrentItem( functionListView->firstChild() );
                functionListView->setSelected( functionListView->firstChild(), TRUE );
            }
        }
        formWindow->mainWindow()->objectHierarchy()->updateFormDefinitionView();
        return;
    }

    if ( !commands.isEmpty() ) {
        MacroCommand *cmd = new MacroCommand( n, formWindow, commands );
        formWindow->commandHistory()->addCommand( cmd );
        cmd->execute();
    }

    formWindow->mainWindow()->objectHierarchy()->updateFormDefinitionView();
    accept();
}