Esempio n. 1
0
DLineEdit::DLineEdit(QWidget *parent, const char *name) :
  QWidget(parent)
{
  setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
  setFocusPolicy(Qt::StrongFocus);
  setMaximumWidth(200);
  setName(name);

  QHBoxLayout *hbox = new QHBoxLayout(this);
  hbox->addWidget(&_lineedit);
  hbox->addWidget(&_calbutton);
  hbox->setSpacing(1);
  hbox->setMargin(0);

  QPixmap pixmap(":/widgets/images/calendar_24.png"); 
  _calbutton.setIconSize(QSize(24,24));
  _calbutton.setIcon(QIcon(pixmap));
  _calbutton.setFlat(true);
  _calbutton.setMaximumSize(pixmap.size());

  connect(&_calbutton,        SIGNAL(clicked()), this, SLOT(showCalendar()));
  connect(&_lineedit, SIGNAL(editingFinished()), this, SLOT(validateDate()));

  _allowNull   = FALSE;
  _parsed      = FALSE;
  _nullString  = QString::null;
  _valid       = FALSE;
}
Esempio n. 2
0
///////////////////////////////////////////////////////////////////////////////
/// @fn setToday()
/// @brief Fetches the current time of the system and parses the day and month 
///   into our MM/DD format and stores it in m_today
///////////////////////////////////////////////////////////////////////////////
void validate::setToday() {
  
  //Creates a time object
  time_t rawtime;
  
  //Creates a struct to hold our time information
  struct tm * timeinfo;

  //Gets the current time as a time_t object
  time( &rawtime );

  //returns a pointer to a tm structure with the information of the pointer 
  //passed in filled in
  timeinfo = localtime( &rawtime );

  // Sets "today" in the MM/DD format.
  // +1 to the month because it's stored as 0-11 instead of 1-12.
  string today = int_to_str(timeinfo->tm_mon + 1, 2) + "/" + int_to_str(timeinfo->tm_mday, 2);

  if( validateDate( today ) == false ) {
    
    throw Exception( 70, "The date set on your computer is invalid. Exception in (class validate, setToday()" );
  
  }
  
  m_today = today;

}
Esempio n. 3
0
//Based on program by Stanley Wong
string Date::getDayName(int dd, int mm, int yyyy)
{
	string dayName;
	if(!validateDate(dd,mm,yyyy))return dayName;
	int days = ((yyyy-1)*365 + (yyyy-1)/4 - (yyyy-1)/100 + (yyyy-1)/400) % 7;//Daycode for prev year 31st Dec
	switch(mm)
	{
		case 12:dd += 30;break;
		case 11:dd += 31;break;
		case 10:dd += 30;break;
		case 9:dd += 31;break;
		case 8:dd += 31;break;
		case 7:dd += 30;break;
		case 6:dd += 31;break;
		case 5:dd += 30;break;
		case 4:dd += 31;break;
		case 3:dd += 28;break;
		case 2:dd += 31;break;
	}
	days += dd;
	if ((!(yyyy % 4) && ((yyyy % 100) || !(yyyy % 400)))&& mm > 2)
		days++;
	days = days%7;
	switch(days)
	{
		case 0:dayName = "SUNDAY";break;
		case 1:dayName = "MONDAY";break;
		case 2:dayName = "TUESDAY";break;
		case 3:dayName = "WEDNESDAY";break;
		case 4:dayName = "THURSDAY";break;
		case 5:dayName = "FRIDAY";break;
		case 6:dayName = "SATURDAY";break;
	}
	return dayName;
}
Esempio n. 4
0
Date::Date(int yyyy,int mm,int dd)
{
	if(!validateDate(dd,mm,yyyy))throw "Invalid date";
	long g = getDays(yyyy,mm,dd);
	*this = getDateFromDays(g);
	this->nanoseconds = 0;
	this->timeZoneOffset = 0;
}
Esempio n. 5
0
Date::Date(const int& yyyy, const int& mm, const int& dd)
{
	if(!validateDate(dd,mm,yyyy))throw std::runtime_error("Invalid date");
	long g = getDays(yyyy,mm,dd);
	*this = getDateFromDays(g);
	populateDay();
	populateMonth();
	populateEpochAndTimeZone(false);
}
Esempio n. 6
0
Date::Date(int yyyy,string mmm,int dd)
{
	string mm = getMon(mmm);
	if(mm=="-1")throw "Invalid month";
	if(!validateDate(dd,CastUtil::lexical_cast<int>(mm),yyyy))throw "Invalid date";
	long g = getDays(yyyy,CastUtil::lexical_cast<long>(mm),dd);
	*this = getDateFromDays(g);
	this->nanoseconds = 0;
	this->timeZoneOffset = 0;
}
Esempio n. 7
0
int isOlder(char *dob1, char *dob2)
{
	if (validateDate(dob1) == 0)
		return -1;
	if (validateDate(dob2) == 0)
		return -1;
	if (verifyForNumbers(dob1, dob2) == -1)
		return -1;
	int k;
	k = compareAndReturnGreater(dob1, dob2, 6, 9);
	if (k != 0)
		return k;
	k = compareAndReturnGreater(dob1, dob2, 2, 4);
	if (k != 0)
		return k;
	k = compareAndReturnGreater(dob1, dob2, 0, 1);
	if (k != 0)
		return k;
	return 0;
}
Esempio n. 8
0
Date::Date(const int& yyyy, const std::string& mmm, const int& dd)
{
	std::string mm = getMon(mmm);
	if(mm=="-1")throw std::runtime_error("Invalid month");
	if(!validateDate(dd,CastUtil::lexical_cast<int>(mm),yyyy))throw std::runtime_error("Invalid date");
	long g = getDays(yyyy,CastUtil::lexical_cast<long>(mm),dd);
	*this = getDateFromDays(g);
	populateDay();
	populateMonth();
	populateEpochAndTimeZone(false);
}
Esempio n. 9
0
Date::Date(int yy,int mm,int dd,bool te)
{
	Date d;
	string syyyy = d.year.substr(0,2) + CastUtil::lexical_cast<string>(yy);
	int yyyy = CastUtil::lexical_cast<int>(syyyy);
	if(!validateDate(dd,mm,yyyy))throw "Invalid date";
	long g = getDays(yyyy,mm,dd);
	*this = getDateFromDays(g);
	this->nanoseconds = 0;
	this->timeZoneOffset = 0;
}
Esempio n. 10
0
Date::Date(const int& yy, const int& mm, const int& dd, const bool& te)
{
	Date d;
	std::string syyyy = CastUtil::lexical_cast<std::string>(d.year).substr(0,2) + CastUtil::lexical_cast<std::string>(yy);
	int yyyy = CastUtil::lexical_cast<int>(syyyy);
	if(!validateDate(dd,mm,yyyy))throw std::runtime_error("Invalid date");
	long g = getDays(yyyy,mm,dd);
	*this = getDateFromDays(g);
	populateDay();
	populateMonth();
	populateEpochAndTimeZone(false);
}
/**
 * @description Funcao responsavel por ler a data que o livro saiu da biblioteca. 
 * @param e	Parametro do tipo emprestimo que guardara temporariamente a data de saida do livro que  se deseja buscar. 
 */
void leituraDataSaida(TEmprestimo *e)
{
	int validation = -1;
	do {
		printf("Digite a data de emprestimo do livro. Ex:(dd/mm/AAAA): ");
		fflush(stdin);
		scanf("%d/%d/%d", &e->dataSaida.dia, &e->dataSaida.mes, &e->dataSaida.ano);
		validation = validateDate(e->dataEntrega.dia, e->dataEntrega.mes, e->dataEntrega.ano);
		if (validation == -1) printf("\nData Invalida! Digite novamente...\n\n");
	} while (validation == -1);

}
Esempio n. 12
0
Date::Date(int yy,string mmm,int dd,bool te)
{
	Date d;
	string syyyy = d.year.substr(0,2) + CastUtil::lexical_cast<string>(yy);
	int yyyy = CastUtil::lexical_cast<int>(syyyy);
	string mm = getMon(mmm);
	if(mm=="-1")throw "Invalid month";
	if(!validateDate(dd,CastUtil::lexical_cast<int>(mm),yyyy))throw "Invalid date";
	long g = getDays(yyyy,CastUtil::lexical_cast<long>(mm),dd);
	*this = getDateFromDays(g);
	this->nanoseconds = 0;
	this->timeZoneOffset = 0;
	setDayName();
}
bool iCalConverter::validateDT(WCHAR* dt) {
    //1997 06 30 T 23 59 60 Z
    int len = int(wcslen(dt));
    if(len != 15 && len != 16)
        return false;

    if(len == 16) {
        if(dt[15] != 'Z')
            return false;
    }

    if(dt[8] != 'T')
        return false;

    WCHAR* date;
    date = new WCHAR[9];
    wcsncpy(date, dt, 8);
    date[8] = 0;
    if(!validateDate(date)) {
        delete [] date;
        return false;
    }
    delete [] date;

    WCHAR hour[2];
    hour[0] = dt[9];
    hour[1] = dt[10];
    int h = _wtoi(hour);
    if(h < 0 || h > 23)
        return false;

    WCHAR min[2];
    min[0] = dt[11];
    min[1] = dt[12];
    int m = _wtoi(min);
    if(m < 0 || m > 59)
        return false;

    WCHAR sec[2];
    sec[0] = dt[13];
    sec[1] = dt[14];
    int s = _wtoi(sec);
    if(s < 0 || s > 59)
        return false;

    return true;

}
/**
 * @description	Funcao responsavel por ler os atributos da struct emprestimo.
 * @param e	Parametro do tipo emprestimo que ira guardar os valores digitados pelo usuario.
 */
void leituraEmprestimo(TEmprestimo *e)
{
	e->dataSaida.dia = getDay();
	e->dataSaida.mes = getMonth();
	e->dataSaida.ano = getYear();
	int validation = -1;
	do {
		printf("Digite a data de entrega do livro: ");
		scanf("%d/%d/%d", &e->dataEntrega.dia, &e->dataEntrega.mes, &e->dataEntrega.ano);
		validation = validateDate(e->dataEntrega.dia, e->dataEntrega.mes, e->dataEntrega.ano);
		if (validation == -1) printf("\nData Invalida! Digite novamente...\n\n");
	} while (validation == -1);
	printf("\nOBS: A data de devolucao sera 99/99/9999 a principio. Quando o livro for devolvido, esta assumira a data de devolucao.\n\n");
	e->dataDevolucao.dia = 99;
	e->dataDevolucao.mes = 99;
	e->dataDevolucao.ano = 9999;
}
Esempio n. 15
0
///////////////////////////////////////////////////////////////////////////////
/// @fn bool validateLeave( string startDate, string endDate, rulesSystem &rules )
/// @brief checks a leave range of dates against the rules in the passed rules
///   and then returns whether or not the range follows the rules
/// @param string startDate is the start date for the requested vacation 
/// @param string endDate is the end date for the requested vacation
/// @param rulesSystem &rules is rules system to check the dates against for
///   verification of leave time
/// @return false if the request is denied for any reason
/// @return true if the request is accepted
/// @note the parameters startDate and endDate must be in "MM/DD" where MM is 
///   the month number and DD is the day number
///////////////////////////////////////////////////////////////////////////////
bool validate::validateLeave( string uID, string request ) {

  vector<string> request_vec = parse_request(request);

  string startDate    = request_vec[1];
  string endDate      = request_vec[2];
  string requestType  = request_vec[3];

  //First make sure both the start and end dates are valid dates
  if ( validateDate( startDate ) == false ) {
    
    return false;
  
  }

  if ( validateDate( endDate ) == false ) {
    
    return false;
  
  }

  // Number of days requesting off.
  int request_days = num_days( startDate, endDate );
  int days_to_start = num_days( get_today(), startDate ) - 1;

  // TEST 0
  // If they don't have enough time available in the leave type
  // of their request, they fail.
  if (requestType == SICK_LEAVE) {

    int time_available = str_to_int( DATABASE.get_entry(uID, SICK_LEAVE_BALANCE) );

    // Not enough time.
    if (time_available < request_days) {

      return false;

    }

  } else if (requestType == VACATION_LEAVE) {

    int time_available = str_to_int( DATABASE.get_entry(uID, VACATION_LEAVE_BALANCE) );

    // Not enough time.
    if (time_available < request_days) {

      return false;

    }

  } else {

    // Not a valid leave type.
    return false;

  }

  //TEST 1
  //If the number of days notice is fewer than the rules allow, fail
  //leave time validation
  if ( ( days_to_start ) < m_rules->getDaysNotice() ) {
    
    return false;
  
  }

  //TEST 2
  //Now we're going to make sure we're not requesting too much time off in a row
  //This will just check the size of the leaveRequestDates against the rule for
  //amount of time off in a row
  if ( request_days > m_rules->getDaysConsecutive() ) {
    
    return false;
  
  }

  //TEST 3
  //And now we need to make sure that we're not going to leave the company
  //Trying to run itself with no employees left
  //This I'm not sure how we're going to implement yet, but I'll figure it out
  //I think I've got this part figured out. There's a field in the scope uID
  //in the database that is called ON_VACATION that will store a 1 or a 0
  //to represent if that user is on vacation. This item will be edited somewhere
  //that isn't here.
  //We'll just get all the entries in all scopes in that field and count the
  //number of 1s >_>

  //THIS NEEDS TO BE CHANGED TO JUST CHECK THE CURRENT DATE VS THE DATES OF
  //PEOPLE WHO ARE ON VACATION, lolk
  
  double usersOnVacation = 0;

  vector<string> users = DATABASE.get_scopes();
  vector<string> leaveRequest;

  //We'll run through each user
  for ( int x = 0; x < users.size(); x++ ) {
   
    //Gets all of the approved requests for the user
    leaveRequest = DATABASE.get_entries( users.at( x ), APPROVED_REQUESTS );

    // Hax the vector from the request list into the last
    // approved request in the list.
    leaveRequest = parse_request(leaveRequest.back());

    if (leaveRequest[0] != DEFAULT_ENTRY) {

      // Pull out the start/end of the most recent approved request.
      string request_start = leaveRequest[1];
      string request_end = leaveRequest[2];

      // Calculate the length of the request.
      int request_length = num_days(request_start, request_end);

      // And the number of days from the start of the request to today.
      int start_to_today = num_days(request_start, get_today());

      // If today is between the start and end of the request...
      if (start_to_today > 0 && start_to_today <= request_length) {

        // They're on vacation.
        usersOnVacation++;

      }

    } /* if (leave_request[0] != DEFAULT_ENTRY) */
   
  }
  
  if ( usersOnVacation >= m_rules->getMaxPeopleOff() ) {
  
    return false;
  
  }

  // Vector to store the blackout days.
  vector<string> blackout = m_rules->getBlackoutList();
  
  //TEST 4
  //And finally now we're going to make sure that we're not trying to leave on 
  //A blackout date. This should run through all of the blackoutlist for each
  //date in the request list, not efficient, but the easiest way
  for ( int j = 0; j < blackout.size(); j++ ) {

    int days_to_blackout = num_days(startDate, blackout[j]);

    //And if the date in the request list matches any in the blackout list
    //We return false because employees can't take a vacation on a 
    //blackout date
    if ( days_to_blackout > 0 &&  // A day in the past doesn't matter to us.
         days_to_blackout <= request_days ) {

      return false;

    }
    
  } //end for loop

  return true;

}
Esempio n. 16
0
/*------------------------------------------------------------------------
 * Register a new account with MXit
 *
 * @param gc		The connection object
 * @param fields	This is the fields filled-in by the user
 */
static void mxit_cb_register_ok( PurpleConnection *gc, PurpleRequestFields *fields )
{
	struct MXitSession*		session		= purple_connection_get_protocol_data( gc );
	struct MXitProfile*		profile		= session->profile;
	const char*				str;
	const char*				pin;
	const char*				err			= NULL;
	int						len;
	int						i;

	purple_debug_info( MXIT_PLUGIN_ID, "mxit_cb_register_ok\n" );

	if ( !PURPLE_CONNECTION_IS_VALID( gc ) ) {
		purple_debug_error( MXIT_PLUGIN_ID, "Unable to register; account offline.\n" );
		return;
	}

	/* nickname */
	str = purple_request_fields_get_string( fields, "nickname" );
	if ( ( !str ) || ( strlen( str ) < 3 ) ) {
		err = _( "The Display Name you entered is too short." );
		goto out;
	}
	g_strlcpy( profile->nickname, str, sizeof( profile->nickname ) );

	/* birthdate */
	str = purple_request_fields_get_string( fields, "bday" );
	if ( ( !str ) || ( strlen( str ) < 10 ) || ( !validateDate( str ) ) ) {
		err = _( "The birthday you entered is invalid. The correct format is: 'YYYY-MM-DD'." );
		goto out;
	}
	g_strlcpy( profile->birthday, str, sizeof( profile->birthday ) );

	/* gender */
	profile->male = ( purple_request_fields_get_choice( fields, "male" ) != 0 );

	/* pin */
	pin = purple_request_fields_get_string( fields, "pin" );
	if ( !pin ) {
		err = _( "The PIN you entered is invalid." );
		goto out;
	}
	len = strlen( pin );
	if ( ( len < 7 ) || ( len > 10 ) ) {
		err = _( "The PIN you entered has an invalid length [7-10]." );
		goto out;
	}
	for ( i = 0; i < len; i++ ) {
		if ( !g_ascii_isdigit( pin[i] ) ) {
			err = _( "The PIN is invalid. It should only consist of digits [0-9]." );
			goto out;
		}
	}
	str = purple_request_fields_get_string( fields, "pin2" );
	if ( ( !str ) || ( strcmp( pin, str ) != 0 ) ) {
		err = _( "The two PINs you entered do not match." );
		goto out;
	}
	g_strlcpy( profile->pin, pin, sizeof( profile->pin ) );

out:
	if ( !err ) {
		purple_account_set_password( session->acc, session->profile->pin, NULL, NULL );
		mxit_login_connect( session );
	}
	else {
		/* show error to user */
		mxit_popup( PURPLE_NOTIFY_MSG_ERROR, _( "Registration Error" ), err );
		mxit_register_view( session );
	}
}
Esempio n. 17
0
/*------------------------------------------------------------------------
 * The user has selected to change their profile.
 *
 *  @param gc		The connection object
 *  @param fields	The fields from the request pop-up
 */
static void mxit_profile_cb( PurpleConnection* gc, PurpleRequestFields* fields )
{
	struct MXitSession*		session	= purple_connection_get_protocol_data( gc );
	PurpleRequestField*		field	= NULL;
	const char*				name	= NULL;
	const char*				bday	= NULL;
	const char*				err		= NULL;
	GList*					entry	= NULL;

	purple_debug_info( MXIT_PLUGIN_ID, "mxit_profile_cb\n" );

	PURPLE_ASSERT_CONNECTION_IS_VALID(gc);

	/* validate name */
	name = purple_request_fields_get_string( fields, "name" );
	if ( ( !name ) || ( strlen( name ) < 3 ) ) {
		err = _( "The Display Name you entered is invalid." );
		goto out;
	}

	/* validate birthdate */
	bday = purple_request_fields_get_string( fields, "bday" );
	if ( ( !bday ) || ( strlen( bday ) < 10 ) || ( !validateDate( bday ) ) ) {
		err = _( "The birthday you entered is invalid. The correct format is: 'YYYY-MM-DD'." );
		goto out;
	}

out:
	if ( !err ) {
		struct MXitProfile*	profile		= session->profile;
		GString*			attributes	= g_string_sized_new( 128 );
		char				attrib[512];
		unsigned int		acount		= 0;


		/* update name */
		g_strlcpy( profile->nickname, name, sizeof( profile->nickname ) );
		g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_FULLNAME, CP_PROFILE_TYPE_UTF8, profile->nickname );
		g_string_append( attributes, attrib );
		acount++;

		/* update birthday */
		g_strlcpy( profile->birthday, bday, sizeof( profile->birthday ) );
		g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_BIRTHDATE, CP_PROFILE_TYPE_UTF8, profile->birthday );
		g_string_append( attributes, attrib );
		acount++;

		/* update gender */
		profile->male = ( purple_request_fields_get_choice( fields, "male" ) != 0 );
		g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_GENDER, CP_PROFILE_TYPE_BOOL, ( profile->male ) ? "1" : "0" );
		g_string_append( attributes, attrib );
		acount++;

		/* update title */
		name = purple_request_fields_get_string( fields, "title" );
		if ( !name )
			profile->title[0] = '\0';
		else
			g_strlcpy( profile->title, name, sizeof( profile->title ) );
		g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_TITLE, CP_PROFILE_TYPE_UTF8, profile->title );
		g_string_append( attributes, attrib );
		acount++;

		/* update firstname */
		name = purple_request_fields_get_string( fields, "firstname" );
		if ( !name )
			profile->firstname[0] = '\0';
		else
			g_strlcpy( profile->firstname, name, sizeof( profile->firstname ) );
		g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_FIRSTNAME, CP_PROFILE_TYPE_UTF8, profile->firstname );
		g_string_append( attributes, attrib );
		acount++;

		/* update lastname */
		name = purple_request_fields_get_string( fields, "lastname" );
		if ( !name )
			profile->lastname[0] = '\0';
		else
			g_strlcpy( profile->lastname, name, sizeof( profile->lastname ) );
		g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_LASTNAME, CP_PROFILE_TYPE_UTF8, profile->lastname );
		g_string_append( attributes, attrib );
		acount++;

		/* update email address */
		name = purple_request_fields_get_string( fields, "email" );
		if ( !name )
			profile->email[0] = '\0';
		else
			g_strlcpy( profile->email, name, sizeof( profile->email ) );
		g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_EMAIL, CP_PROFILE_TYPE_UTF8, profile->email );
		g_string_append( attributes, attrib );
		acount++;

		/* update mobile number */
		name = purple_request_fields_get_string( fields, "mobilenumber" );
		if ( !name )
			profile->mobilenr[0] = '\0';
		else
			g_strlcpy( profile->mobilenr, name, sizeof( profile->mobilenr ) );
		g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_MOBILENR, CP_PROFILE_TYPE_UTF8, profile->mobilenr );
		g_string_append( attributes, attrib );
		acount++;

		/* update about me */
		name = purple_request_fields_get_string( fields, "aboutme" );
		if ( !name )
			profile->aboutme[0] = '\0';
		else
			g_strlcpy( profile->aboutme, name, sizeof( profile->aboutme ) );
		g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_ABOUTME, CP_PROFILE_TYPE_UTF8, profile->aboutme );
		g_string_append( attributes, attrib );
		acount++;

		/* update where am i */
		name = purple_request_fields_get_string( fields, "whereami" );
		if ( !name )
			profile->whereami[0] = '\0';
		else
			g_strlcpy( profile->whereami, name, sizeof( profile->whereami ) );
		g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_WHEREAMI, CP_PROFILE_TYPE_UTF8, profile->whereami );
		g_string_append( attributes, attrib );
		acount++;

		/* relationship status */
		field = purple_request_fields_get_field( fields, "relationship" );
		entry = g_list_first( purple_request_field_list_get_selected( field ) );
		profile->relationship = atoi( purple_request_field_list_get_data( field, entry->data ) );
		g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%i", CP_PROFILE_RELATIONSHIP, CP_PROFILE_TYPE_SHORT, profile->relationship );
		g_string_append( attributes, attrib );
		acount++;

		/* update flags */
		field = purple_request_fields_get_field( fields, "searchable" );
		if ( purple_request_field_bool_get_value( field ) )		/* is searchable -> clear not-searchable flag */
			profile->flags &= ~CP_PROF_NOT_SEARCHABLE;
		else
			profile->flags |= CP_PROF_NOT_SEARCHABLE;
		field = purple_request_fields_get_field( fields, "suggestable" );
		if ( purple_request_field_bool_get_value( field ) )		/* is suggestable -> clear not-suggestable flag */
			profile->flags &= ~CP_PROF_NOT_SUGGESTABLE;
		else
			profile->flags |= CP_PROF_NOT_SUGGESTABLE;
		g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%" G_GINT64_FORMAT, CP_PROFILE_FLAGS, CP_PROFILE_TYPE_LONG, profile->flags);
		g_string_append( attributes, attrib );
		acount++;

		/* send the profile update to MXit */
		mxit_send_extprofile_update( session, NULL, acount, attributes->str );
		g_string_free( attributes, TRUE );
	}
	else {
		/* show error to user */
		mxit_popup( PURPLE_NOTIFY_MSG_ERROR, _( "Profile Update Error" ), err );
	}
}
bool iCalConverter::validatePropery(VProperty* vp, WString& errorDescription, long* errorCode) {

    if(!wcscmp(vp->getName(), TEXT("CLASS"))) {
        if(!wcsstr(CLASS_PROPERTY_VALUE, vp->getValue()) &&
            wcsstr(vp->getValue(),TEXT("X-")) != vp->getValue()) {
                *errorCode = ERROR_INVALID_PROPERTY_VALUE;
                errorDescription = TEXT("Property CLASS, Invalid value : ");
                errorDescription += vp->getValue();
                return false;
            }
    }
    else if(!wcscmp(vp->getName(), TEXT("CREATED"))) {
        if(!validateDT(vp->getValue())) {
            *errorCode = ERROR_INVALID_PROPERTY_VALUE;
            errorDescription = TEXT("Property CREATED, Invalid value : ");
            errorDescription += vp->getValue();
            return false;
        }
    }
    else if(!wcscmp(vp->getName(), TEXT("DESCRIPTION"))) {
        for(int i = 0; i < vp->parameterCount(); i++)
            if(!wcsstr(COMMENT_PARAM_LIST, vp->getParameter(i)) &&
                wcsstr(vp->getValue(),TEXT("X-")) != vp->getParameter(i)) {
                    *errorCode = ERROR_ILLEGAL_PARAMETER;
                    errorDescription = TEXT("Property DESCRIPTION, Invalid parameter : ");
                    errorDescription += vp->getParameter(i);
                    return false;
                }
    }
    else if(!wcscmp(vp->getName(), TEXT("DTSTART"))) {
        for(int i = 0; i < vp->parameterCount(); i++) {
            if(!wcsstr(DT_PARAM_LIST, vp->getParameter(i)) &&
                wcsstr(vp->getValue(),TEXT("X-")) != vp->getParameter(i)) {
                    *errorCode = ERROR_ILLEGAL_PARAMETER;
                    errorDescription = TEXT("Property DTSTART, Invalid parameter : ");
                    errorDescription += vp->getParameter(i);
                    return false;
                }
        }
        if(vp->containsParameter(TEXT("VALUE")) && !wcscmp(vp->getParameterValue(TEXT("VALUE")), TEXT("DATE"))) {
            if(!validateDate(vp->getValue())) {
                *errorCode = ERROR_INVALID_PROPERTY_VALUE;
                errorDescription = TEXT("Property DTSTART, Invalid value : ");
                errorDescription += vp->getValue();
                return false;
            }
        }
        else if(!validateDT(vp->getValue()) && !validateDate(vp->getValue())) {
            *errorCode = ERROR_INVALID_PROPERTY_VALUE;
            errorDescription = TEXT("Property DTSTART, Invalid value : ");
            errorDescription += vp->getValue();
            return false;
        }
    }
    else if(!wcscmp(vp->getName(), TEXT("GEO"))) {
        if(!validateGeo(vp->getValue())) {
            *errorCode = ERROR_INVALID_PROPERTY_VALUE;
            errorDescription = TEXT("Property GEO, Invalid value format : ");
            errorDescription += vp->getValue();
            return false;
        }
    }
    else if(!wcscmp(vp->getName(), TEXT("LAST-MODIFIED"))) {
        if(!validateDT(vp->getValue())) {
            *errorCode = ERROR_INVALID_PROPERTY_VALUE;
            errorDescription = TEXT("Property LAST-MODIFIED, Invalid value : ");
            errorDescription += vp->getValue();
            return false;
        }
    }
    else if(!wcscmp(vp->getName(), TEXT("LOCATION"))) {
        for(int i = 0; i < vp->parameterCount(); i++)
            if(!wcsstr(COMMENT_PARAM_LIST, vp->getParameter(i)) &&
                wcsstr(vp->getValue(),TEXT("X-")) != vp->getParameter(i)) {
                    *errorCode = ERROR_ILLEGAL_PARAMETER;
                    errorDescription = TEXT("Property LOCATION, Invalid parameter : ");
                    errorDescription += vp->getParameter(i);
                    return false;
                }
    }
    else if(!wcscmp(vp->getName(), TEXT("ORGANIZER"))) {
        for(int i = 0; i < vp->parameterCount(); i++)
            if(!wcsstr(ORGANIZER_PARAM_LIST, vp->getParameter(i)) &&
                wcsstr(vp->getValue(),TEXT("X-")) != vp->getParameter(i)) {
                    *errorCode = ERROR_ILLEGAL_PARAMETER;
                    errorDescription = TEXT("Property ORGANIZER, Invalid parameter : ");
                    errorDescription += vp->getParameter(i);
                    return false;
                }
    }
    else if(!wcscmp(vp->getName(), TEXT("PRIORITY"))) {
        if(vp->getValue()) {
            if(wcslen(vp->getValue()) > 1 || !isdigit(vp->getValue()[0])) {
                *errorCode = ERROR_INVALID_PROPERTY_VALUE;
                errorDescription = TEXT("Property PRIORITY, Invalid value : ");
                errorDescription += vp->getValue();
                return false;
            }
        }
    }
    else if(!wcscmp(vp->getName(), TEXT("DTSTAMP"))) {
        if(!validateDT(vp->getValue())) {
            *errorCode = ERROR_INVALID_PROPERTY_VALUE;
            errorDescription = TEXT("Property DTSTAMP, Invalid value : ");
            errorDescription += vp->getValue();
            return false;
        }
    }
    else if(!wcscmp(vp->getName(), TEXT("SUMMARY"))) {
        for(int i = 0; i < vp->parameterCount(); i++)
            if(!wcsstr(COMMENT_PARAM_LIST, vp->getParameter(i)) &&
                wcsstr(vp->getValue(),TEXT("X-")) != vp->getParameter(i)) {
                    *errorCode = ERROR_ILLEGAL_PARAMETER;
                    errorDescription = TEXT("Property SUMMARY, Invalid parameter : ");
                    errorDescription += vp->getParameter(i);
                    return false;
                }
    }
    else if(!wcscmp(vp->getName(), TEXT("TRANSP"))) {
        if(wcscmp(vp->getName(), TEXT("OPAQUE")) && wcscmp(vp->getName(), TEXT("TRANSPARENT"))) {
            *errorCode = ERROR_INVALID_PROPERTY_VALUE;
            errorDescription = TEXT("Property TRANSP, Invalid value : ");
            errorDescription += vp->getValue();
            return false;
        }
    }

    else if(!wcscmp(vp->getName(), TEXT("RECURRENCE-ID"))) {
        for(int i = 0; i < vp->parameterCount(); i++) {
            if(!wcsstr(DT_PARAM_LIST, vp->getParameter(i)) &&
                wcsstr(vp->getValue(),TEXT("X-")) != vp->getParameter(i) &&
                wcscmp(vp->getParameter(i), TEXT("RANGE"))) {
                    *errorCode = ERROR_ILLEGAL_PARAMETER;
                    errorDescription = TEXT("Property RECURRENCE-ID, Invalid parameter : ");
                    errorDescription += vp->getParameter(i);
                    return false;
                }
        }
        if(vp->containsParameter(TEXT("VALUE")) && !wcscmp(vp->getParameterValue(TEXT("VALUE")), TEXT("DATE"))) {
            if(!validateDate(vp->getValue())) {
                *errorCode = ERROR_INVALID_PROPERTY_VALUE;
                errorDescription = TEXT("Property RECURRENCE-ID, Invalid value : ");
                errorDescription += vp->getValue();
                return false;
            }
        }
        else if(!validateDT(vp->getValue())) {
            *errorCode = ERROR_INVALID_PROPERTY_VALUE;
            errorDescription = TEXT("Property RECURRENCE-ID, Invalid value : ");
            errorDescription += vp->getValue();
            return false;
        }
    }
    else if(!wcscmp(vp->getName(), TEXT("DTEND"))) {
        for(int i = 0; i < vp->parameterCount(); i++) {
            if(!wcsstr(DT_PARAM_LIST, vp->getParameter(i)) &&
                wcsstr(vp->getValue(),TEXT("X-")) != vp->getParameter(i)) {
                    *errorCode = ERROR_ILLEGAL_PARAMETER;
                    errorDescription = TEXT("Property DTEND, Invalid parameter: ");
                    errorDescription += vp->getParameter(i);
                    return false;
                }
        }
        if(vp->containsParameter(TEXT("VALUE")) && !wcscmp(vp->getParameterValue(TEXT("VALUE")), TEXT("DATE"))) {
            if(!validateDate(vp->getValue())) {
                *errorCode = ERROR_INVALID_PROPERTY_VALUE;
                errorDescription = TEXT("Property DTEND, Invalid value : ");
                errorDescription += vp->getValue();
                return false;
            }
        }
        else if(!validateDT(vp->getValue()) && !validateDate(vp->getValue())) {
            *errorCode = ERROR_INVALID_PROPERTY_VALUE;
            errorDescription = TEXT("Property DTEND, Invalid value : ");
            errorDescription += vp->getValue();
            return false;
        }
    }
    else if(!wcscmp(vp->getName(), TEXT("DUE"))) {
        for(int i = 0; i < vp->parameterCount(); i++) {
            if(!wcsstr(DT_PARAM_LIST, vp->getParameter(i)) &&
                wcsstr(vp->getValue(),TEXT("X-")) != vp->getParameter(i)) {
                    *errorCode = ERROR_ILLEGAL_PARAMETER;
                    errorDescription = TEXT("Property DUE, Invalid parameter : ");
                    errorDescription += vp->getParameter(i);
                    return false;
                }
        }
        if(vp->containsParameter(TEXT("VALUE")) && !wcscmp(vp->getParameterValue(TEXT("VALUE")), TEXT("DATE"))) {
            if(!validateDate(vp->getValue())) {
                *errorCode = ERROR_INVALID_PROPERTY_VALUE;
                errorDescription = TEXT("Property DUE, Invalid value : ");
                errorDescription += vp->getValue();
                return false;
            }
        }
        else if(!validateDT(vp->getValue())) {
            *errorCode = ERROR_INVALID_PROPERTY_VALUE;
            errorDescription = TEXT("Property DUE, Invalid value : ");
            errorDescription += vp->getValue();
            return false;
        }
    }
    else if(!wcscmp(vp->getName(), TEXT("COMPLETED"))) {
        if(!validateDT(vp->getValue())) {
            *errorCode = ERROR_INVALID_PROPERTY_VALUE;
            errorDescription = TEXT("Property COMPLETED, Invalid value : ");
            errorDescription += vp->getValue();
            return false;
        }
    }
    else if(!wcscmp(vp->getName(), TEXT("PERCENT-COMPLETE"))) {
        if(wcslen(vp->getValue()) > 2 ||
            (wcslen(vp->getValue()) == 1 && !isdigit(vp->getValue()[0])) ||
            (wcslen(vp->getValue()) == 2 && (!isdigit(vp->getValue()[0]) || !isdigit(vp->getValue()[1])))) {
            *errorCode = ERROR_INVALID_PROPERTY_VALUE;
            errorDescription = TEXT("Property PERCENT, Invalid value : ");
            errorDescription += vp->getValue();
            return false;
            }
    }
    else if(!wcscmp(vp->getName(), TEXT("ATTACH"))) {
        for(int i = 0; i < vp->parameterCount(); i++) {
            if(!wcsstr(ATTACH_PARAM_LIST, vp->getParameter(i)) &&
                wcsstr(vp->getValue(),TEXT("X-")) != vp->getParameter(i)) {
                    *errorCode = ERROR_ILLEGAL_PARAMETER;
                    errorDescription = TEXT("Property ATTACH, Invalid parameter : ");
                    errorDescription += vp->getParameter(i);
                    return false;
                }
            if(!wcscmp(vp->getParameter(i), TEXT("ENCODING"))
                && wcscmp(vp->getParameterValue(TEXT("ENCODING")), TEXT("BASE64"))) {
                    *errorCode = ERROR_UNSUPPORTED_ENCODING;
                    errorDescription = TEXT("Property ATTACH, unsupported encoding : ");
                    errorDescription += vp->getParameterValue(TEXT("ENCODING"));
                    return false;
                }
        }
    }
    else if(!wcscmp(vp->getName(), TEXT("ATTENDEE"))) {
        for(int i = 0; i < vp->parameterCount(); i++) {
            if(!wcsstr(ATTENDEE_PARAM_LIST, vp->getParameter(i)) &&
                wcsstr(vp->getValue(),TEXT("X-")) != vp->getParameter(i)) {
                    *errorCode = ERROR_ILLEGAL_PARAMETER;
                    errorDescription = TEXT("Property ATTENDEE, Invalid parameter : ");
                    errorDescription += vp->getParameter(i);
                    return false;
                }
        }
    }
    else if(!wcscmp(vp->getName(), TEXT("COMMENT"))) {
        for(int i = 0; i < vp->parameterCount(); i++)
            if(!wcsstr(COMMENT_PARAM_LIST, vp->getParameter(i)) &&
                wcsstr(vp->getValue(),TEXT("X-")) != vp->getParameter(i)) {
                    *errorCode = ERROR_ILLEGAL_PARAMETER;
                    errorDescription = TEXT("Property COMMENT, Invalid parameter : ");
                    errorDescription += vp->getParameter(i);
                    return false;
                }
    }
    else if(!wcscmp(vp->getName(), TEXT("CONTACT"))) {
        for(int i = 0; i < vp->parameterCount(); i++)
            if(!wcsstr(COMMENT_PARAM_LIST, vp->getParameter(i)) &&
                wcsstr(vp->getValue(),TEXT("X-")) != vp->getParameter(i)) {
                    *errorCode = ERROR_ILLEGAL_PARAMETER;
                    errorDescription = TEXT("Property CONTACT, Invalid parameter : ");
                    errorDescription += vp->getParameter(i);
                    return false;
                }
    }
    else if(!wcscmp(vp->getName(), TEXT("EXDATE"))) {
        for(int i = 0; i < vp->parameterCount(); i++) {
            if(!wcsstr(DT_PARAM_LIST, vp->getParameter(i)) &&
                wcsstr(vp->getValue(),TEXT("X-")) != vp->getParameter(i)) {
                    *errorCode = ERROR_ILLEGAL_PARAMETER;
                    errorDescription = TEXT("Property EXDATE, Invalid parameter : ");
                    errorDescription += vp->getParameter(i);
                    return false;
                }
        }
        if(vp->containsParameter(TEXT("VALUE")) && !wcscmp(vp->getParameterValue(TEXT("VALUE")), TEXT("DATE"))) {
            WCHAR seps[] = TEXT(",");
            WCHAR *token;
            token = wcstok( vp->getValue(), seps );
            while( token != NULL ) {
                if(!validateDate(token)) {
                    *errorCode = ERROR_INVALID_PROPERTY_VALUE;
                    errorDescription = TEXT("Property EXDATE, Invalid value : ");
                    errorDescription += vp->getValue();
                    return false;
                }
                token = wcstok( NULL, seps );
            }
        }
        else if(!validateDT(vp->getValue())) {
            *errorCode = ERROR_INVALID_PROPERTY_VALUE;
            errorDescription = TEXT("Property EXDATE, Invalid value : ");
            errorDescription += vp->getValue();
            return false;
        }
    }
    else if(!wcscmp(vp->getName(), TEXT("EXRULE"))) {
        if(!validateRecur(vp->getValue())) {
            *errorCode = ERROR_INVALID_PROPERTY_VALUE;
            errorDescription = TEXT("Property EXRULE, Invalid value : ");
            errorDescription += vp->getValue();
            return false;
        }
    }
    else if(!wcscmp(vp->getName(), TEXT("REQUEST-STATUS"))) {
        //statcode ";" statdesc [";" extdata]
        WCHAR* value = new WCHAR[wcslen(vp->getName())+1];
        wcscpy(value, vp->getName());
        if(!isdigit(value[0]) || value[1] != '.' || !wcschr(value, ';')) {
            *errorCode = ERROR_INVALID_PROPERTY_VALUE;
            errorDescription = TEXT("Property REQUEST-STATUS, Invalid value : ");
            errorDescription += vp->getValue();
            delete [] value;
            return false;
        }
        delete [] value;
    }
    else if(!wcscmp(vp->getName(), TEXT("RELATED-TO"))) {
        for(int i = 0; i < vp->parameterCount(); i++)
            if(wcscmp(TEXT("RELTYPE"), vp->getParameter(i)) &&
                wcsstr(vp->getValue(),TEXT("X-")) != vp->getParameter(i)) {
                    *errorCode = ERROR_ILLEGAL_PARAMETER;
                    errorDescription = TEXT("Property RELATED-TO, Invalid parameter : ");
                    errorDescription += vp->getParameter(i);
                    return false;
                }
    }
    else if(!wcscmp(vp->getName(), TEXT("RESOURCES"))) {
        for(int i = 0; i < vp->parameterCount(); i++)
            if(!wcsstr(COMMENT_PARAM_LIST, vp->getParameter(i)) &&
                wcsstr(vp->getValue(),TEXT("X-")) != vp->getParameter(i)) {
                    *errorCode = ERROR_ILLEGAL_PARAMETER;
                    errorDescription = TEXT("Property RESOURCES, Invalid parameter : ");
                    errorDescription += vp->getParameter(i);
                    return false;
                }
    }
    else if(!wcscmp(vp->getName(), TEXT("RDATE"))) {
        for(int i = 0; i < vp->parameterCount(); i++) {
            if(!wcsstr(RDATE_PARAM_LIST, vp->getParameter(i)) &&
                wcsstr(vp->getValue(),TEXT("X-")) != vp->getParameter(i)) {
                    *errorCode = ERROR_ILLEGAL_PARAMETER;
                    errorDescription = TEXT("Property RDATE, Invalid parameter : ");
                    errorDescription += vp->getParameter(i);
                    return false;
                }
        }
        if(vp->containsParameter(TEXT("VALUE")) && !wcscmp(vp->getParameterValue(TEXT("VALUE")), TEXT("DATE"))) {
            if(!validateDate(vp->getValue())) {
                *errorCode = ERROR_INVALID_PROPERTY_VALUE;
                errorDescription = TEXT("Property RDATE, Invalid value : ");
                errorDescription += vp->getValue();
                return false;
            }
        }
        else if(vp->containsParameter(TEXT("VALUE")) && !wcscmp(vp->getParameterValue(TEXT("VALUE")), TEXT("PERIOD"))) {
            WCHAR* delimiter;
            delimiter = wcschr(vp->getValue(), '/');
            if(!delimiter) {
                *errorCode = ERROR_INVALID_PROPERTY_VALUE;
                errorDescription = TEXT("Property RDATE, Invalid value : ");
                errorDescription += vp->getValue();
                return false;
            }
        }
        else if(!validateDT(vp->getValue())) {
            *errorCode = ERROR_INVALID_PROPERTY_VALUE;
            errorDescription = TEXT("Property RDATE, Invalid value : ");
            errorDescription += vp->getValue();
            return false;
        }
    }
    else if(!wcscmp(vp->getName(), TEXT("RRULE"))) {
        if(!validateRecur(vp->getValue())) {
            *errorCode = ERROR_INVALID_PROPERTY_VALUE;
            errorDescription = TEXT("Property RRULE, Invalid value : ");
            errorDescription += vp->getValue();
            return false;
        }
    }
    return true;
}
Esempio n. 19
0
void DLineEdit::parseDate()
{
  validateDate();
}
Esempio n. 20
0
/**
 * Parse a GPRMC sentence from a string
 *
 * @param s the string
 * @param len the length of the string
 * @param pack a pointer to the result structure
 * @return 1 (true) - if parsed successfully or 0 (false) otherwise.
 */
int nmea_parse_GPRMC(const char *s, const int len, nmeaGPRMC *pack) {
	int token_count;
	char time_buff[NMEA_TIMEPARSE_BUF];
	int date;
	size_t time_buff_len = 0;

	assert(s);
	assert(pack);

	nmea_trace_buff(s, len);

	/*
	 * Clear before parsing, to be able to detect absent fields
	 */
	time_buff[0] = '\0';
	date = -1;
	pack->present = 0;
	pack->utc.year = -1;
	pack->utc.mon = -1;
	pack->utc.day = -1;
	pack->utc.hour = -1;
	pack->utc.min = -1;
	pack->utc.sec = -1;
	pack->utc.hsec = -1;
	pack->status = 0;
	pack->lat = NAN;
	pack->ns = 0;
	pack->lon = NAN;
	pack->ew = 0;
	pack->speed = NAN;
	pack->track = NAN;
	pack->magvar = NAN;
	pack->magvar_ew = 0;
	pack->mode = 0;

	/* parse */
	token_count = nmea_scanf(s, len, "$GPRMC,%s,%c,%f,%c,%f,%c,%f,%f,%d,%f,%c,%c*", &time_buff[0], &pack->status,
			&pack->lat, &pack->ns, &pack->lon, &pack->ew, &pack->speed, &pack->track, &date,
			&pack->magvar, &pack->magvar_ew, &pack->mode);

	/* see that we have enough tokens */
	if ((token_count != 11) && (token_count != 12)) {
		nmea_error("GPRMC parse error: need 11 or 12 tokens, got %d in %s", token_count, s);
		return 0;
	}

	/* determine which fields are present and validate them */

	time_buff_len = strlen(&time_buff[0]);
	if (time_buff_len) {
		if (!_nmea_parse_time(&time_buff[0], time_buff_len, &pack->utc)) {
			return 0;
		}

		if (!validateTime(&pack->utc)) {
			return 0;
		}

		nmea_INFO_set_present(&pack->present, UTCTIME);
	}

	if (!pack->status) {
		pack->status = 'V';
	} else {
		pack->status = toupper(pack->status);
		if (!((pack->status == 'A') || (pack->status == 'V'))) {
			nmea_error("GPRMC parse error: invalid status (%c)", pack->status);
			return 0;
		}
	}
	if (!isnan(pack->lat) && (pack->ns)) {
		if (!validateNSEW(&pack->ns, true)) {
			return 0;
		}

		nmea_INFO_set_present(&pack->present, LAT);
	}
	if (!isnan(pack->lon) && (pack->ew)) {
		if (!validateNSEW(&pack->ew, false)) {
			return 0;
		}

		nmea_INFO_set_present(&pack->present, LON);
	}
	if (!isnan(pack->speed)) {
		nmea_INFO_set_present(&pack->present, SPEED);
	}
	if (!isnan(pack->track)) {
		nmea_INFO_set_present(&pack->present, TRACK);
	}

	if (date != -1) {
		if (!_nmea_parse_date(date, &pack->utc)) {
			return 0;
		}

		if (!validateDate(&pack->utc)) {
			return 0;
		}

		nmea_INFO_set_present(&pack->present, UTCDATE);
	}

	if (!isnan(pack->magvar) && (pack->magvar_ew)) {
		if (!validateNSEW(&pack->magvar_ew, false)) {
			return 0;
		}

		nmea_INFO_set_present(&pack->present, MAGVAR);
	}
	if (token_count == 11) {
		pack->mode = 'A';
	} else {
		if (!pack->mode) {
			pack->mode = 'N';
		} else {
			if (!validateMode(&pack->mode)) {
				return 0;
			}
		}
	}

	return 1;
}