Exemple #1
0
Palapeli::TriggerListView::TriggerListView(const QMap<QByteArray, Palapeli::Interactor*>& interactors, Palapeli::InteractorType interactorType, QWidget* parent)
	: KCategorizedView(parent)
	, m_categoryDrawer(new KCategoryDrawer)
	, m_baseModel(new QStandardItemModel(this))
	, m_proxyModel(new Palapeli::TriggerListProxyModel(this))
	, m_delegate(new Palapeli::TriggerListDelegate(this))
{
	//fill base model with interactors
	QMap<QByteArray, Palapeli::Interactor*>::const_iterator it1 = interactors.begin(), it2 = interactors.end();
	for (; it1 != it2; ++it1)
	{
		//filter interactor
		Palapeli::Interactor* interactor = it1.value();
		if (interactor->interactorType() != interactorType)
			continue;
		//create item for interactor
		QStandardItem* item = new QStandardItem;
		item->setData(interactor->description(), Qt::DisplayRole);
		item->setData(interactor->icon(), Qt::DecorationRole);
		item->setData(interactorType, Palapeli::InteractorTypeRole);
		item->setData(it1.key(), Palapeli::InteractorRole);
		item->setData(qVariantFromValue(Palapeli::Trigger()), Palapeli::TriggerRole);
		item->setData(categoryToString(interactor->category()), KCategorizedSortFilterProxyModel::CategoryDisplayRole);
		item->setData(interactor->category(), KCategorizedSortFilterProxyModel::CategorySortRole);
		m_baseModel->appendRow(item);
	}
	//setup model/view
	m_proxyModel->setSourceModel(m_baseModel);
	setModel(m_proxyModel);
	setItemDelegate(m_delegate);
	connect(m_delegate, SIGNAL(triggerChanged()), SIGNAL(associationsChanged()));
// 	setCategoryDrawer(m_categoryDrawer); //FIXME: Why do I crash?
}
Exemple #2
0
void Logger::trace(int category, const UTF8String& sMsg)
{
    boost::mutex::scoped_lock Lock(log_Mutex);
    if (category & m_Flags) {
        struct tm* pTime;
#ifdef _WIN32
        __int64 now;
        _time64(&now);
        pTime = _localtime64(&now);
        DWORD tms = timeGetTime();
        unsigned millis = unsigned(tms % 1000);
#else
        struct timeval time;
        gettimeofday(&time, NULL);
        pTime = localtime(&time.tv_sec);
        unsigned millis = time.tv_usec/1000;
#endif
        char timeString[256];
        strftime(timeString, sizeof(timeString), "%y-%m-%d %H:%M:%S", pTime);
        cerr << "[" << timeString << "." << 
            setw(3) << setfill('0') << millis << setw(0) << "] ";
        cerr << categoryToString(category) << ": ";
        cerr << sMsg << endl;
        cerr.flush();
    }
}
QString SimpleLoggerRoutingInfo::getLevelsAsString() const
{
  QString s = "";
  QMapIterator<MessageCategory, int> i(*m_levels);
  while (i.hasNext())
  {
      i.next();
      if (s.length() > 0)
      {
        s = s + QString("|%1:%2").arg(categoryToString(i.key(), 1)).arg(i.value());
      }
      else
      {
        s = QString("%1:%2").arg(categoryToString(i.key(), 1)).arg(i.value());
      }
  }
  return s;
}
QString SimpleLoggerRoutingInfo::formatMessage(const QString& message, const QString& location, const QDateTime dateTime, MessageCategory category, int) const
{
  QString s;
  for (int i=0; i<m_format.length(); ++i)
  {
    const QPair<MessageComponent, QString>& pair(m_format[i]);
    switch(pair.first)
    {
    case MessageDateTime:
      if (pair.second.length() == 0)
      {
        s.append(dateTime.toString(Qt::ISODate));
      }
      else
      {
        s.append(dateTime.toString(pair.second));
      }
      break;
    case MessageType:
      s.append(categoryToString(category, pair.second.length()));
      break;
    case MessageText:
      s.append(message);
      break;
    case MessageLocation:
      // The file macro used to get the location sometimes contains path information.
      // This is related to the target build directory, so if the object files are not
      // in the same directory as the source files, a path like "../LinkBackAPD/helper.cpp" is used.
      // The following code checks for this and removes the path information.
      if (location.contains('/'))
      {
        s.append(location.right(location.length() - location.lastIndexOf('/') - 1));
      }
      else if (location.contains('\\'))
      {
        s.append(location.right(location.length() - location.lastIndexOf('\\') - 1));
      }
      else
      {
        s.append(location);
      }
      break;
    case ConstantText:
      s.append(pair.second);
      break;
    default:
      // TODO: Error handling
      break;
    }
  }
  return s;
}
void AdDisplayMenu::print() {
	//first line, only borderChar
	for (unsigned int i = 0; i < width; i++)
		cout << borderChar;

	cout << endl;

	//includes top margin with is a line full of spaces, with borderChar on either side
	for (unsigned int i = 0; i < topMargin; i++)
		emptyLine();

	cout << borderChar << " ";
	string adType;
	if (ad->getType() == 'P')
		adType = "Purchase";
	else
		adType = "Sale";
	adType += " Ad";

	cout << adType << string(width - 3 - adType.length(), ' ') << borderChar << endl;
	emptyLine();

	//display title
	string title = ad->getTitle();
	cout << borderChar << " Title: " << title
			<< string(width - 2 - 8 - title.length(), ' ') << borderChar << endl;

	//a white line between title and description
	emptyLine();

	cout << borderChar << " Category: " << categoryToString(ad->getCategory())
			<< string(
					width - 2 - 11
							- categoryToString(ad->getCategory()).length(), ' ')
			<< borderChar << endl;

	emptyLine();

	//used to add menu options correctly
	string description = ad->getDescription();

	cout << borderChar << " Description: " << description
			<< string(width - 2 - 14 - description.length(), ' ') << borderChar
			<< endl;

	if(ad->getType() == 'S'){
		emptyLine();
		Sale* sale = static_cast<Sale*> (ad);
		string cond = conditionToString(sale->getCondition());
		cout << borderChar << " Product Condition: " << cond << string(width-2-20- cond.length(), ' ') << borderChar << endl;
	}


	//a white line between description and contacts
	emptyLine();

	cout << borderChar << " Creation Date: " << ad->getCreationDate()
			<< string(width - 2 - 16 - ad->getCreationDate().length(), ' ')
			<< borderChar << endl;

	bool showEmail = ad->getOwner()->getShowEmail();
	bool showName = ad->getOwner()->getShowName();
	bool showPhoneNumber = ad->getOwner()->getShowPhoneNumber();

	if (showEmail || showName || showPhoneNumber) {
		if (showEmail) {
			string email = ad->getOwner()->getEmail();
			cout << borderChar << " Email: " << email
					<< string(width - 2 - 8 - email.length(), ' ') << borderChar
					<< endl;
		}

		if (showName) {
			string name = ad->getOwner()->getName();
			cout << borderChar << " Name: " << name
					<< string(width - 2 - 7 - name.length(), ' ') << borderChar
					<< endl;
		}

		if (showPhoneNumber) {
			string phoneNumber = ad->getOwner()->getPhoneNumber();
			cout << borderChar << " Phone Number: " << phoneNumber
					<< string(width - 2 - 15 - phoneNumber.length(), ' ')
					<< borderChar << endl;
		}
		emptyLine();
	}
	stringstream ss;
	ss << ad->getViews();
	cout << borderChar << " Views: " << ss.str()
			<< string(width - 2 - 8 - ss.str().length(), ' ') << borderChar
			<< endl;
	emptyLine();

	ss.str("");
	ss << ad->getPrice() << "  ";
	if (!ad->isPriceNegotiable())
		ss << "Non-";
	ss << "Negotiable";
	cout << borderChar << " Price: " << ss.str()
			<< string(width - 2 - 8 - ss.str().length(), ' ') << borderChar
			<< endl;
	emptyLine();

	unsigned int i = 1;
	if (data->getSignedInUser() == ad->getOwner()) {
		string editTitle = "1 - Edit title";
		cout << borderChar << " " << editTitle
				<< string(width - 3 - editTitle.length(), ' ') << borderChar
				<< endl;
		string editDescription = "2 - Edit description";
		cout << borderChar << " " << editDescription
				<< string(width - 3 - editDescription.length(), ' ')
				<< borderChar << endl;
		string editCategory = "3 - Edit category";
		cout << borderChar << " " << editCategory
				<< string(width - 3 - editCategory.length(), ' ') << borderChar
				<< endl;
		string editPrice = "4 - Edit price";
		cout << borderChar << " " << editPrice
				<< string(width - 3 - editPrice.length(), ' ') << borderChar
				<< endl;
		string removeAd = "5 - Remove advertisement";
		cout << borderChar << " " << removeAd
				<< string(width - 3 - removeAd.length(), ' ') << borderChar
				<< endl;
		i = 6;
	} else {
		string imInterested = " 1 - I'm interested";
		i = 2;
		cout << borderChar << imInterested
				<< string(width - imInterested.length() - 2, ' ') << borderChar
				<< endl;
	}
	ss.str("");
	ss << " " << i << " - Exit";
	cout << borderChar << ss.str() << string(width - ss.str().length() - 2, ' ')
			<< borderChar << endl;

	emptyLine();

	//last line
	for (unsigned int i = 0; i < width; i++)
		cout << borderChar;

	cout << endl;
}
QXmlStreamWriter& SimpleLoggerRoutingInfo::write(QXmlStreamWriter& writer) const
{
  writer.writeStartElement("SimpleLoggerRoutingInfo");

  if (m_name.length() > 0)
  {
    XMLUtility::writeElement(writer, "Name", m_name);
  }
  XMLUtility::writeElement(writer, "Enabled", XMLUtility::booleanToString(m_enabled));

  if (m_levels != nullptr && m_levels->size() > 0)
  {
    QMap<MessageCategory, int>::const_iterator i;
    for (i = m_levels->begin(); i != m_levels->end(); ++i)
    {
      XMLUtility::writeElementAttribute(writer, "Level", QString::number(i.value()), "MessageCategory", categoryToString(i.key(), -1));
    }
  }

  if (m_routing != nullptr && m_routing->size() > 0)
  {
    QMap<MessageRouting, bool>::const_iterator i;
    for (i = m_routing->begin(); i != m_routing->end(); ++i)
    {
      XMLUtility::writeElementAttribute(writer, "Routing", XMLUtility::booleanToString(i.value()), "MessageRouting", routingToString(i.key(), -1));
    }
  }

  if (m_locationRegExp != nullptr)
  {
    XMLUtility::write(writer, *m_locationRegExp, "LocationRegEx");
  }

  if (m_messageRegExp != nullptr)
  {
    XMLUtility::write(writer, *m_messageRegExp, "MessageRegEx");
  }

  if (m_format.size() > 0)
  {
    for (int i=0; i<m_format.size(); ++i)
    {
      const QPair<MessageComponent, QString>& comp = m_format.at(i);
      XMLUtility::writeElementAttribute(writer, "Format", comp.second, "MessageComponent", componentToString(comp.first, comp.second.length()));
    }
  }

  writer.writeEndElement();
  return writer;
}